207 lines
5.3 KiB
PHP
207 lines
5.3 KiB
PHP
<?php
|
|
|
|
namespace app\admin\model;
|
|
|
|
use app\admin\library\Auth;
|
|
use think\Model;
|
|
|
|
|
|
class OrderDispatch extends Model
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
// 表名
|
|
protected $name = 'order_dispatch';
|
|
|
|
// 自动写入时间戳字段
|
|
protected $autoWriteTimestamp = 'datetime';
|
|
|
|
protected $dateFormat = 'Y-m-d H:i:s';
|
|
// 定义时间戳字段名
|
|
protected $createTime = 'create_time';
|
|
protected $updateTime = 'update_time';
|
|
protected $deleteTime = false;
|
|
|
|
// 追加属性
|
|
protected $append = [
|
|
'type_text',
|
|
'status_text',
|
|
'is_notice_text',
|
|
'offline_total_type_text'
|
|
];
|
|
|
|
const STATUS_TOGET = 0; //待接
|
|
const STATUS_GOTIT = 10; //已接
|
|
const STATUS_PLANIT = 20; //已预约
|
|
const STATUS_OVERTIME = 25; //超时(过了预约时间)
|
|
const STATUS_CLOCK = 30; //已打卡
|
|
const STATUS_FINISH = 60; //完成
|
|
const STATUS_REFUSED = -10; //拒绝
|
|
const STATUS_MOVE = -20; //中转(状态废弃)
|
|
const STATUS_CANCEL = -30; //取消
|
|
|
|
|
|
public function getTypeList()
|
|
{
|
|
return ['1' => __('Type 1')];
|
|
}
|
|
|
|
public function getStatusList()
|
|
{
|
|
return ['0' => __('Status 0'), '10' => __('Status 10'), '20' => __('Status 20'),'25' => __('Status 25'), '30' => __('Status 30'), '60' => __('Status 60'), '-10' => __('Status -10'),
|
|
// '-20' => __('Status -20'),
|
|
'-30' => __('Status -30')];
|
|
}
|
|
|
|
public function getIsNoticeList()
|
|
{
|
|
return ['0' => __('Is_notice 0'), '1' => __('Is_notice 1')];
|
|
}
|
|
|
|
public function getOfflineTotalTypeList()
|
|
{
|
|
return ['0' => __('无'), '1'=> __('师傅收'),'2' => __('公司收')];
|
|
}
|
|
|
|
|
|
public function getTypeTextAttr($value, $data)
|
|
{
|
|
$value = $value ?: ($data['type'] ?? '');
|
|
$list = $this->getTypeList();
|
|
return $list[$value] ?? '';
|
|
}
|
|
|
|
|
|
public function getStatusTextAttr($value, $data)
|
|
{
|
|
$value = $value ?: ($data['status'] ?? '');
|
|
$list = $this->getStatusList();
|
|
return $list[$value] ?? '';
|
|
}
|
|
|
|
|
|
public function getIsNoticeTextAttr($value, $data)
|
|
{
|
|
$value = $value ?: ($data['is_notice'] ?? '');
|
|
$list = $this->getIsNoticeList();
|
|
return $list[$value] ?? '';
|
|
}
|
|
|
|
public function getOfflineTotalTypeTextAttr($value,$data){
|
|
$value = $value ?: ($data['offline_total_type'] ?? '');
|
|
$list = $this->getOfflineTotalTypeList();
|
|
return $list[$value] ?? '';
|
|
}
|
|
|
|
|
|
public function deleteStatusList(){
|
|
return [
|
|
self::STATUS_TOGET,
|
|
self::STATUS_GOTIT,
|
|
self::STATUS_PLANIT,
|
|
self::STATUS_OVERTIME,
|
|
self::STATUS_CLOCK,
|
|
];
|
|
}
|
|
|
|
public function checkDelete($status){
|
|
|
|
if(in_array($status,$this->deleteStatusList())){
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
public function orderb()
|
|
{
|
|
return $this->belongsTo('Order', 'order_id', 'id', [], 'LEFT')->setEagerlyType(0);
|
|
}
|
|
|
|
|
|
public function btnActiveStatusList($btn){
|
|
|
|
$btns = [
|
|
'btn_edit' => [
|
|
self::STATUS_TOGET,
|
|
self::STATUS_GOTIT,
|
|
self::STATUS_PLANIT,
|
|
self::STATUS_OVERTIME,
|
|
self::STATUS_CLOCK,
|
|
],
|
|
'btn_cancel' => [ //取消按钮
|
|
self::STATUS_TOGET,
|
|
self::STATUS_GOTIT,
|
|
self::STATUS_PLANIT,
|
|
self::STATUS_OVERTIME,
|
|
self::STATUS_CLOCK,
|
|
],
|
|
'btn_abnormal' => [ //添加异常按钮
|
|
self::STATUS_TOGET,
|
|
self::STATUS_GOTIT,
|
|
self::STATUS_PLANIT,
|
|
self::STATUS_OVERTIME,
|
|
self::STATUS_CLOCK,
|
|
],
|
|
'btn_finished' => [
|
|
self::STATUS_TOGET,
|
|
self::STATUS_GOTIT,
|
|
self::STATUS_PLANIT,
|
|
self::STATUS_OVERTIME,
|
|
self::STATUS_CLOCK,
|
|
//self::STATUS_FINISH
|
|
],
|
|
'disabled_status' => [
|
|
self::STATUS_FINISH,
|
|
self::STATUS_CANCEL,
|
|
self::STATUS_REFUSED,
|
|
self::STATUS_MOVE
|
|
],
|
|
'btn_record' => [
|
|
self::STATUS_TOGET,
|
|
self::STATUS_GOTIT,
|
|
self::STATUS_PLANIT,
|
|
self::STATUS_OVERTIME,
|
|
self::STATUS_CLOCK,
|
|
],
|
|
];
|
|
|
|
return $btns[$btn]??[];
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* 管理员权限
|
|
* @param $query
|
|
* @param Auth $auth
|
|
* @param string $auth_admin_id
|
|
* @return mixed
|
|
*/
|
|
// public function scopeAuth($query, Auth $auth, string $admin_id_field='admin_id'){
|
|
//
|
|
// if(!$auth->isSuperAdmin()){
|
|
// $query->whereIn('fa_order_dispatch.'.$admin_id_field,[$auth->id,0]);
|
|
// }
|
|
// return $query;
|
|
// }
|
|
|
|
public function scopeDispatcherauth($query, Auth $auth, string $admin_id_field='admin_id'){
|
|
|
|
if($auth->isDispatcher()){ //是派单员
|
|
$query->where('fa_order_dispatch.'.$admin_id_field,$auth->id);
|
|
}
|
|
return $query;
|
|
}
|
|
|
|
|
|
|
|
public function lastRecord(){
|
|
return $this->hasOne(OrderDispatchRecord::class,'dispatch_id','id')->order('id','desc')->limit(1);
|
|
}
|
|
|
|
}
|