46 lines
1.1 KiB
PHP
46 lines
1.1 KiB
PHP
<?php
|
||
|
||
namespace App\Models;
|
||
|
||
use Illuminate\Database\Eloquent\Model;
|
||
use EloquentFilter\Filterable;
|
||
use Carbon\Carbon;
|
||
use Slowlyo\OwlAdmin\OwlAdmin;
|
||
use Slowlyo\OwlAdmin\Models\AdminUser;
|
||
|
||
class HydropowerFee extends Model
|
||
{
|
||
use Filterable;
|
||
|
||
protected $fillable = [
|
||
'oldman_id', 'money', 'extends', 'start_at', 'end_at', 'sn', 'adminuser_id',
|
||
];
|
||
|
||
public function oldman(){
|
||
return $this->belongsTo(Oldmen::class, 'oldman_id');
|
||
}
|
||
|
||
public function adminuser(){
|
||
return $this->belongsTo(AdminUser::class, 'adminuser_id');
|
||
}
|
||
|
||
protected static function boot()
|
||
{
|
||
parent::boot();
|
||
// 监听 flow 创建事件,创建sn;
|
||
static::creating(function ($hydropowerFee) {
|
||
if(empty($hydropowerFee->sn)){
|
||
$hydropowerFee->sn = self::createSn();
|
||
}
|
||
if(empty($hydropowerFee->adminuser_id)){
|
||
$hydropowerFee->adminuser_id = OwlAdmin::user()->id;
|
||
}
|
||
});
|
||
}
|
||
|
||
private static function createSn()
|
||
{
|
||
return Carbon::now()->isoFormat('YYMMDDHHmmss').rand(1000, 9999);
|
||
}
|
||
}
|