51 lines
1.1 KiB
PHP
Executable File
51 lines
1.1 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Model;
|
|
|
|
use App\Model\Traits\ScopeTrait;
|
|
use App\Model\Traits\TableFieldTrait;
|
|
use App\Model\Traits\TableTrait;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class BaseModel extends Model
|
|
{
|
|
use SoftDeletes;
|
|
use TableFieldTrait;
|
|
use TableTrait;
|
|
use ScopeTrait;
|
|
|
|
|
|
/**
|
|
* 雪花算法,唯一编码
|
|
* @param string $prefix
|
|
* @return string
|
|
*/
|
|
public static function snowflake($prefix = 'R')
|
|
{
|
|
$unique = uniqid(mt_rand(100000, 999999), true);
|
|
|
|
return sprintf('%s%s%d',$prefix, date('Ymd'), crc32($unique));
|
|
}
|
|
|
|
/**
|
|
* 删除含有_last后缀的字段
|
|
* @param BaseModel $model
|
|
*/
|
|
public static function unsetLastSuffixField(BaseModel $model) {
|
|
$attrs = $model->getAttributes();
|
|
foreach ($attrs as $field => $val) {
|
|
if (str_ends_with($field, '_last')) {
|
|
unset($model->{$field});
|
|
}
|
|
}
|
|
}
|
|
|
|
//修改日期时间格式
|
|
protected function serializeDate(\DateTimeInterface $date)
|
|
{
|
|
return $date->format('Y-m-d H:i:s');
|
|
}
|
|
|
|
}
|