|
|
@@ -55,6 +55,8 @@ use app\common\model\master_worker\MasterWorkerRetentionMoneyLog;
|
|
|
use app\common\model\master_commission\MasterWorkerCommissionRatio;
|
|
|
use app\common\model\master_commission\MasterWorkerCommissionConfig;
|
|
|
use app\common\model\service_area\ServiceArea;
|
|
|
+use app\common\service\call\VirtualCallService;
|
|
|
+use think\facade\Cache;
|
|
|
|
|
|
/**
|
|
|
* ServiceWork逻辑
|
|
|
@@ -164,22 +166,37 @@ class ServiceWorkLogic extends BaseLogic
|
|
|
throw new Exception('请勿重复点击');
|
|
|
}
|
|
|
|
|
|
- //验证更改的预约时间必须是在领单时间内的半小内修改,否则不允许修改
|
|
|
- if(strtotime($work->appointment_time) != strtotime($params['appointment_time']) && (time()-strtotime($work->receive_time))>1800){
|
|
|
- throw new Exception('距离领单时间已超过半小时,无法修改预约时间,请联系客服');
|
|
|
+ //判断是否有待审核的预约时间修改记录
|
|
|
+ $exists = ServiceWorkAppointmentLog::where(['work_id'=>$work->id,'status'=>0])->value('id');
|
|
|
+ if ($exists){
|
|
|
+ throw new Exception('存在待审核的预约时间修改记录,无法修改');
|
|
|
}
|
|
|
|
|
|
- $work->work_status = 3;//待上门
|
|
|
- $work->appointment_time = strtotime($params['appointment_time']);
|
|
|
- $work->save();
|
|
|
+ //验证更改的预约时间必须是在领单时间内的半小内修改,否则不允许修改
|
|
|
+ // if(strtotime($work->appointment_time) != strtotime($params['appointment_time']) && (time()-strtotime($work->receive_time))>1800){
|
|
|
+ // throw new Exception('距离领单时间已超过半小时,无法修改预约时间,请联系客服');
|
|
|
+ // }
|
|
|
|
|
|
- //添加变更日志
|
|
|
- $work_log = [
|
|
|
+ //添加预约时间修改待审核记录
|
|
|
+ ServiceWorkAppointmentLog::create([
|
|
|
+ 'status'=>0,//待审核
|
|
|
'work_id'=>$work->id,
|
|
|
- 'master_worker_id'=>$work->master_worker_id,
|
|
|
- 'opera_log'=>'编号['.$params['user_info']['worker_number'].']'.$params['user_info']['real_name'].'于'.date('y-m-d H:i:s',time()).'联系了客户,确认了于'.$params['appointment_time'].$params['address'].'预约上门',
|
|
|
- ];
|
|
|
- ServiceWorkLogLogic::add($work_log);
|
|
|
+ 'worker_id'=>$params['user_id'],
|
|
|
+ 'last_appointment_time'=>strtotime($work->appointment_time),
|
|
|
+ 'this_appointment_time'=>strtotime($params['appointment_time']),
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // $work->work_status = 3;//待上门
|
|
|
+ // $work->appointment_time = strtotime($params['appointment_time']);
|
|
|
+ // $work->save();
|
|
|
+
|
|
|
+ //添加变更日志
|
|
|
+ // $work_log = [
|
|
|
+ // 'work_id'=>$work->id,
|
|
|
+ // 'master_worker_id'=>$work->master_worker_id,
|
|
|
+ // 'opera_log'=>'编号['.$params['user_info']['worker_number'].']'.$params['user_info']['real_name'].'于'.date('y-m-d H:i:s',time()).'联系了客户,确认了于'.$params['appointment_time'].$params['address'].'预约上门',
|
|
|
+ // ];
|
|
|
+ // ServiceWorkLogLogic::add($work_log);
|
|
|
Db::commit();
|
|
|
}
|
|
|
catch (\Exception $e) {
|
|
|
@@ -426,7 +443,7 @@ class ServiceWorkLogic extends BaseLogic
|
|
|
throw new Exception('请上传配件图片');
|
|
|
}
|
|
|
//修改
|
|
|
- ServiceWorkSpare::where("id",$params['id'])->where('service_worker_id', $work['id'])->update(['spare_image' => $params['spare_image']]);
|
|
|
+ ServiceWorkSpare::where("id",$params['id'])->where('service_work_id', $work['id'])->update(['spare_image' => $params['spare_image'], 'status' => 0]);
|
|
|
|
|
|
Db::commit();
|
|
|
return true;
|
|
|
@@ -717,6 +734,14 @@ class ServiceWorkLogic extends BaseLogic
|
|
|
if($result['third_type']==1){
|
|
|
$result['meituan_order'] = ThirdOrders::where(['work_id'=>$result['id']])->order('create_time desc')->findOrEmpty();
|
|
|
}
|
|
|
+ //工程师预约时间修改申请记录
|
|
|
+ if (!empty($params['user_id'])) {
|
|
|
+ $result['appointment_log'] = ServiceWorkAppointmentLog::where('work_id',$result['id'])->where('worker_id',$params['user_id'])->where('status','<>',1)->field('id,work_id,worker_id,last_appointment_time,this_appointment_time,status,create_time')->order('id desc')->findOrEmpty();
|
|
|
+ if ($result['appointment_log']){
|
|
|
+ $result['appointment_log']['last_appointment_time'] = date('Y/m/d H:i:s',$result['appointment_log']['last_appointment_time']);
|
|
|
+ $result['appointment_log']['this_appointment_time'] = date('Y/m/d H:i:s',$result['appointment_log']['this_appointment_time']);
|
|
|
+ }
|
|
|
+ }
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
@@ -1122,6 +1147,20 @@ class ServiceWorkLogic extends BaseLogic
|
|
|
$work->first_contact_time = time();
|
|
|
$work->save();
|
|
|
}
|
|
|
+
|
|
|
+ if ($middleNumber = Cache::get('WORKER_MIDDLE_NUMBER_'.$work->id)) {
|
|
|
+ return ['middleNumber' => $middleNumber];
|
|
|
+ }
|
|
|
+ $worker_mobile = $params['user_info']['mobile'];
|
|
|
+ $res = VirtualCallService::auth($worker_mobile, $work->mobile, 60);
|
|
|
+ if (isset($res['result']) && $res['result'] == '000000') {
|
|
|
+ Cache::set('WORKER_MIDDLE_NUMBER_'.$work->id, $res['middleNumber'], 60); //缓存60秒
|
|
|
+ return ['middleNumber' => $res['middleNumber']];
|
|
|
+ } else {
|
|
|
+ Log::info('虚拟外呼失败:'.json_encode($res));
|
|
|
+ throw new \Exception('虚拟外呼失败');
|
|
|
+ }
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
catch (\Exception $e) {
|
|
|
@@ -1272,7 +1311,6 @@ class ServiceWorkLogic extends BaseLogic
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 给用户发券
|
|
|
*/
|
|
|
@@ -1335,4 +1373,45 @@ class ServiceWorkLogic extends BaseLogic
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static function appointmentAudit($params): bool
|
|
|
+ {
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ $work = ServiceWork::where('id',$params['work_id'])->findOrEmpty();
|
|
|
+ if($work->isEmpty()){
|
|
|
+ throw new \Exception('工单不存在');
|
|
|
+ }
|
|
|
+ $log = ServiceWorkAppointmentLog::where('id',$params['id'])->findOrEmpty();
|
|
|
+ if($log->isEmpty()){
|
|
|
+ throw new \Exception('审核记录不存在');
|
|
|
+ }
|
|
|
+ $master = MasterWorker::where('id',$log->worker_id)->findOrEmpty();
|
|
|
+
|
|
|
+
|
|
|
+ $log->status = $params['status'];
|
|
|
+ $log->remark = $params['remark'];
|
|
|
+ $log->save();
|
|
|
+
|
|
|
+ //预约时间修改审核通过则更新工单预约时间
|
|
|
+ if ($params['status'] == 2) {
|
|
|
+ //$work->work_status = 3;//待上门
|
|
|
+ $work->appointment_time = $log->this_appointment_time;
|
|
|
+ $work->save();
|
|
|
+
|
|
|
+ //添加变更日志
|
|
|
+ $work_log = [
|
|
|
+ 'work_id'=>$work->id,
|
|
|
+ 'master_worker_id'=>$log->worker_id,
|
|
|
+ 'opera_log'=>'编号['.$master->worker_number.']'.$master->real_name.'于'.$log->create_time.'联系了客户,确认了于'.date('Y-m-d H:i:s',$log->this_appointment_time).'预约上门',
|
|
|
+ ];
|
|
|
+ ServiceWorkLogLogic::add($work_log);
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ return true;
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ self::setError('预约时间审核失败');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|