old-hotel-new/app/Models/HydropowerFee.php

46 lines
1.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?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);
}
}