162 lines
4.3 KiB
PHP
162 lines
4.3 KiB
PHP
<?php
|
|
|
|
namespace app\admin\model;
|
|
|
|
use think\Model;
|
|
use traits\model\SoftDelete;
|
|
|
|
|
|
class Order extends Model
|
|
{
|
|
|
|
|
|
use SoftDelete;
|
|
|
|
|
|
// 表名
|
|
protected $name = 'order';
|
|
|
|
// 自动写入时间戳字段
|
|
protected $autoWriteTimestamp = 'datetime';
|
|
|
|
protected $dateFormat = 'Y-m-d H:i:s';
|
|
// 定义时间戳字段名
|
|
protected $createTime = 'create_time';
|
|
protected $updateTime = 'update_time';
|
|
protected $deleteTime = 'delete_time';
|
|
|
|
// 追加属性
|
|
protected $append = [
|
|
'status_text',
|
|
'collect_text',
|
|
'dispatch_type_text'
|
|
];
|
|
|
|
|
|
const TAB_DISPATCH = 'dispatch'; //派单
|
|
|
|
const TAB_PENDING = 'pending'; //跟进中
|
|
|
|
const TAB_SETTING = 'setting'; //跟进中
|
|
|
|
const TAB_AUDIT = 'audit'; //审核
|
|
|
|
const TAB_REVIEW = 'review'; //回访
|
|
|
|
const STATUS_DRAFT = 0; //草稿
|
|
const STATUS_DISPATCHING = 10; //待派单
|
|
const STATUS_DISPATCHED = 20; //已派单
|
|
//const STATUS_ING = 30; //进行中
|
|
const STATUS_CHECKING = 40; //待派单
|
|
const STATUS_AUDITING = 50; //审核中
|
|
const STATUS_FINISHED = 60; //已完成
|
|
const STATUS_CANCEL = -10; //取消
|
|
|
|
|
|
|
|
|
|
public function getStatusList()
|
|
{
|
|
return ['0' => __('Status 0'),'10' => __('Status 10'), '20' => __('Status 20'),
|
|
//'30' => __('Status 30'),
|
|
'40' => __('Status 40'), '50' => __('Status 50'), '60' => __('Status 60'), '-10' => __('Status -10')];
|
|
}
|
|
|
|
|
|
public function getDispatchTypeList()
|
|
{
|
|
return ['10' => __('Dispatch_type 10'), '11' => __('Dispatch_type 11'), '20' => __('Dispatch_type 20')];
|
|
}
|
|
|
|
|
|
public function getAuditStatusList()
|
|
{
|
|
return [self::STATUS_AUDITING => __('Status 50'), self::STATUS_FINISHED => __('Status 60'), ];
|
|
}
|
|
|
|
|
|
public function getStatusTextAttr($value, $data)
|
|
{
|
|
$value = $value ?: ($data['status'] ?? '');
|
|
$list = $this->getStatusList();
|
|
return $list[$value] ?? '';
|
|
}
|
|
|
|
|
|
public function getCollectTextAttr($value, $data)
|
|
{
|
|
$value = $value ?: ($data['collect'] ?? '');
|
|
//$list = $this->getCollectList();
|
|
return $list[$value] ?? '';
|
|
}
|
|
|
|
|
|
public function getDispatchTypeTextAttr($value, $data)
|
|
{
|
|
$value = $value ?: ($data['dispatch_type'] ?? '');
|
|
$list = $this->getDispatchTypeList();
|
|
return $list[$value] ?? '';
|
|
}
|
|
|
|
|
|
protected function scopeTab($query, $tab=null)
|
|
{
|
|
$status = $this->tabStatus($tab);
|
|
if(!empty($status)){
|
|
$query->whereIn('fa_order.status', $status);
|
|
}
|
|
return $query;
|
|
}
|
|
|
|
public function tabStatus($tab){
|
|
$tabStatus = [
|
|
self::TAB_DISPATCH => [
|
|
self::STATUS_DISPATCHING,
|
|
self::STATUS_DISPATCHED,
|
|
self::STATUS_CANCEL
|
|
], //派单管理状态
|
|
self::TAB_PENDING => [
|
|
self::STATUS_DISPATCHED,
|
|
//self::STATUS_ING,
|
|
self::STATUS_CHECKING,
|
|
], //订单跟进状态
|
|
self::TAB_AUDIT => [
|
|
self::STATUS_AUDITING,
|
|
self::STATUS_FINISHED
|
|
], //待审核
|
|
self::TAB_REVIEW => [
|
|
self::STATUS_FINISHED
|
|
],
|
|
self::TAB_SETTING => [
|
|
self::STATUS_CHECKING
|
|
],
|
|
];
|
|
return $tabStatus[$tab] ?? [];
|
|
}
|
|
|
|
|
|
public function incomeBtnStatus(){
|
|
return array_merge($this->tabStatus(self::TAB_PENDING),[self::STATUS_AUDITING]);
|
|
}
|
|
|
|
public function user(){
|
|
return $this->belongsTo(Admin::class,'admin_id',);
|
|
}
|
|
|
|
public function area(){
|
|
return $this->belongsTo(Area::class,'area_id','area_code');
|
|
}
|
|
public function phone(){
|
|
return $this->belongsTo(Phones::class,'work_tel_id',);
|
|
}
|
|
|
|
public function auditadmin(){
|
|
return $this->belongsTo(Admin::class,'audit_admin_id',);
|
|
}
|
|
|
|
public function dispatch()
|
|
{
|
|
return $this->hasOne(OrderDispatch::class, 'id', 'order_id', [], 'LEFT')->setEagerlyType(0)->where('fa_order_dispatch.status',OrderDispatch::STATUS_FINISH);
|
|
}
|
|
}
|