|
|
@@ -6,6 +6,7 @@ use think\facade\Log;
|
|
|
use think\console\Input;
|
|
|
use think\console\Output;
|
|
|
use think\console\Command;
|
|
|
+use app\adminapi\service\WeCallService;
|
|
|
use app\common\model\works\ServiceWork;
|
|
|
use app\common\model\goods_time\GoodsTime;
|
|
|
use app\common\model\master_worker\MasterWorker;
|
|
|
@@ -26,6 +27,16 @@ class AutomaticDispatch extends Command
|
|
|
//默认服务时长 180 分钟
|
|
|
protected $defaultServiceTime = 180;
|
|
|
|
|
|
+ //外呼客户列表
|
|
|
+ protected $customerList = [];
|
|
|
+
|
|
|
+ //服务类目
|
|
|
+ protected $categoryType = [
|
|
|
+ 1 => '安装',
|
|
|
+ 2 => '维修',
|
|
|
+ 3 => '清洗',
|
|
|
+ ];
|
|
|
+
|
|
|
protected function configure()
|
|
|
{
|
|
|
$this->setName('automatic_dispatch')
|
|
|
@@ -34,7 +45,14 @@ class AutomaticDispatch extends Command
|
|
|
|
|
|
protected function execute(Input $input, Output $output)
|
|
|
{
|
|
|
- $this->autoDispatch();
|
|
|
+ //自动派单
|
|
|
+ //$this->autoDispatch();
|
|
|
+
|
|
|
+ //执行外呼任务
|
|
|
+ $h = date('H');
|
|
|
+ if ($h >= 8 && $h <= 22) {
|
|
|
+ $this->startTask();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -55,15 +73,15 @@ class AutomaticDispatch extends Command
|
|
|
->where('service_status',0)
|
|
|
->where('refund_approval',0)
|
|
|
->where('work_pay_status',1)
|
|
|
- ->where(function ($query) use ($fiveMinutesAgo) {
|
|
|
- $query->where('exec_time', 0)->whereOr('exec_time', '<', $fiveMinutesAgo);
|
|
|
- })
|
|
|
- ->where('appointment_time','between', [$startTime, $endTime])
|
|
|
- ->field('id,category_type,goods_category_id,service_area_id,lon,lat,province,city,title,appointment_time,address,mobile')
|
|
|
- ->order('create_time','asc')
|
|
|
- ->limit($size)
|
|
|
- ->select()
|
|
|
- ->toArray();
|
|
|
+ ->where(function ($query) use ($fiveMinutesAgo) {
|
|
|
+ $query->where('exec_time', 0)->whereOr('exec_time', '<', $fiveMinutesAgo);
|
|
|
+ })
|
|
|
+ ->where('appointment_time','between', [$startTime, $endTime])
|
|
|
+ ->field('id,category_type,goods_category_id,service_area_id,lon,lat,province,city,title,appointment_time,address,mobile,work_sn')
|
|
|
+ ->order('create_time','asc')
|
|
|
+ ->limit($size)
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
if (!$list) {
|
|
|
return ;
|
|
|
}
|
|
|
@@ -95,6 +113,20 @@ class AutomaticDispatch extends Command
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 执行外呼任务
|
|
|
+ */
|
|
|
+ protected function startTask() {
|
|
|
+ if ($this->customerList) {
|
|
|
+ $weCallService = new WeCallService();
|
|
|
+ $res = $weCallService->importUser($this->customerList);
|
|
|
+ if (isset($res['code']) && $res['code'] == 200) {
|
|
|
+ $res = $weCallService->startTask();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->customerList = [];
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 派单给平台工程师
|
|
|
*/
|
|
|
@@ -134,6 +166,8 @@ class AutomaticDispatch extends Command
|
|
|
'a.lat',
|
|
|
'a.worker_number',
|
|
|
'a.real_name',
|
|
|
+ 'a.mobile',
|
|
|
+ 'a.is_wecall',
|
|
|
'b.comprehensive_score',
|
|
|
'b.weight_score',
|
|
|
$real_distance
|
|
|
@@ -195,7 +229,16 @@ class AutomaticDispatch extends Command
|
|
|
if ($count == 0) {
|
|
|
$operaLog = '系统自动派单于'.date('Y-m-d H:i:s',time()).'分配了工程师'.'编号['.$worker['worker_number'].']'.$worker['real_name'];
|
|
|
$res = $this->allocateWorker($item,$worker['id'],$worker['tenant_id'],$operaLog,$estimated_finish_time);
|
|
|
- if ($res === true) {
|
|
|
+ if ($res === true && $worker['is_wecall'] == 1) {
|
|
|
+ $this->customerList[] = [
|
|
|
+ 'phone' => $worker['mobile'],
|
|
|
+ 'properties' => [
|
|
|
+ '订单号' => substr($item['work_sn'], -4),
|
|
|
+ '详细地址'=>$item['address'],
|
|
|
+ '服务类型'=> isset($this->categoryType[$item['category_type']]) ?? '',
|
|
|
+ '客户手机号'=>$item['mobile']
|
|
|
+ ]
|
|
|
+ ];
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
@@ -281,6 +324,15 @@ class AutomaticDispatch extends Command
|
|
|
if ($res === true) {
|
|
|
$updateData = $isAm == 1 ? ['am_order' => Db::raw('am_order + 1')] : ['pm_order' => Db::raw('pm_order + 1')];
|
|
|
MasterWorkerTeam::where('id',$worker['id'])->update($updateData);
|
|
|
+ $this->customerList[] = [
|
|
|
+ 'phone' => MasterWorker::where('id',$worker['master_worker_id'])->value('mobile'),
|
|
|
+ 'properties' => [
|
|
|
+ '订单号' => substr($item['work_sn'], -4),
|
|
|
+ '详细地址'=>$item['address'],
|
|
|
+ '服务类型'=> isset($this->categoryType[$item['category_type']]) ?? '',
|
|
|
+ '客户手机号'=>$item['mobile']
|
|
|
+ ]
|
|
|
+ ];
|
|
|
return true;
|
|
|
}
|
|
|
}
|