69 lines
1.7 KiB
PHP
69 lines
1.7 KiB
PHP
<?php
|
||
|
||
namespace App\Models;
|
||
|
||
use Illuminate\Database\Eloquent\Model;
|
||
use EloquentFilter\Filterable;
|
||
use Slowlyo\OwlAdmin\Models\AdminUser;
|
||
use Carbon\Carbon;
|
||
|
||
class ConstFlow extends Model
|
||
{
|
||
use Filterable;
|
||
|
||
public const TYPE_IN = 1; //入住
|
||
public const TYPE_CONTINUE = 2; //续住
|
||
public const TYPE_EXIT = 3; //结算
|
||
|
||
public static function typeMap()
|
||
{
|
||
return [
|
||
self::TYPE_IN => '入住缴费',
|
||
self::TYPE_CONTINUE => '续住缴费',
|
||
self::TYPE_EXIT => '离开结算',
|
||
];
|
||
}
|
||
|
||
public static function typeMapLabel()
|
||
{
|
||
return [
|
||
self::TYPE_IN => "<span class='label label-info'>入住缴费</span>",
|
||
self::TYPE_CONTINUE => "<span class='label label-warning'>续住缴费</span>",
|
||
self::TYPE_EXIT => "<span class='label label-danger'>离开结算</span>",
|
||
'*'=>'其他:${live_in}'
|
||
];
|
||
}
|
||
|
||
protected $casts = [
|
||
'extends' => 'array',
|
||
];
|
||
|
||
protected $fillable = [
|
||
'oldman_id', 'const_type', 'money', 'extends', 'start_at', 'end_at',
|
||
'change_lv', 'old_lv', 'new_lv',
|
||
'state', 'sn', 'adminuser_id',
|
||
];
|
||
|
||
protected static function boot()
|
||
{
|
||
parent::boot();
|
||
// 监听 flow 创建事件,创建sn;
|
||
static::creating(function ($oldmen) {
|
||
$oldmen->sn = self::createSn();
|
||
});
|
||
}
|
||
|
||
public function oldman(){
|
||
return $this->belongsTo(Oldmen::class, 'oldman_id');
|
||
}
|
||
|
||
public function adminuser(){
|
||
return $this->belongsTo(AdminUser::class, 'adminuser_id');
|
||
}
|
||
|
||
private static function createSn()
|
||
{
|
||
return Carbon::now()->isoFormat('YYMMDDHHmmss').rand(1000, 9999);
|
||
}
|
||
}
|