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

79 lines
2.0 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 Slowlyo\OwlAdmin\Models\AdminUser;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Casts\Attribute;
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 $appends = ['idsn'];
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 idsn():Attribute
{
return Attribute::make(
get: fn($value) => str_pad($this->id, 6, '0',STR_PAD_LEFT),
);
}
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);
}
}