allocatr/application/admin/model/Worker.php
2025-04-29 14:30:47 +08:00

79 lines
1.5 KiB
PHP

<?php
namespace app\admin\model;
use traits\model\SoftDelete;
class Worker extends BaseModel
{
use SoftDelete;
// 表名
protected $name = 'worker';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'datetime';
protected $dateFormat = 'Y-m-d H:i:s';
// 定义时间戳字段名
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
protected $deleteTime = 'deletetime';
// 追加属性
protected $append = [
'status_text'
];
public function getStatusList()
{
return ['1' => __('Status 1'), '0' => __('Status 0')];
}
public function getStatusTextAttr($value, $data)
{
$value = $value ?: ($data['status'] ?? '');
$list = $this->getStatusList();
return $list[$value] ?? '';
}
public function area()
{
return $this->belongsTo('area', 'area_id', 'area_code');
}
public function area2()
{
return $this->belongsTo('area', 'area_id', 'area_code')->setEagerlyType(0);
}
public function admin()
{
return $this->belongsTo('admin', 'admin_id');
}
public function myorder(){
return $this->hasMany(OrderDispatch::class, 'worker_id');
}
// 定义通过中间表与 roles 表的一对多关系
public function items()
{
return $this->hasManyThrough(Item::class, WorkerItem::class, 'worker_id', 'item_id', 'id', 'id');
}
}