فهرست منبع

预约时间修改审核

dongxiaoqin 10 ماه پیش
والد
کامیت
d321690b39

+ 10 - 1
app/adminapi/controller/works/ServiceWorkController.php

@@ -270,7 +270,16 @@ class ServiceWorkController extends BaseAdminController
         return $this->success('操作成功', [], 1, 1);
     }
 
+    public function appointmentLists()
+    {
+        return $this->dataLists(new ServiceWorkLists());
+    }
 
-
+    public function appointmentAudit()
+    {
+        $params = (new ServiceWorkValidate())->post()->goCheck('detail');
+        $result = ServiceWorkLogic::appointmentAudit($params);
+        return $this->data($result);
+    }
 
 }

+ 57 - 9
app/adminapi/logic/works/ServiceWorkLogic.php

@@ -53,6 +53,7 @@ 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逻辑
@@ -162,22 +163,37 @@ class ServiceWorkLogic extends BaseLogic
                 throw new Exception('请勿重复点击');
             }
 
+            //判断是否有待审核的预约时间修改记录
+            $exists = ServiceWorkAppointmentLog::where(['work_id'=>$work->id,'status'=>0])->value('id');
+            if ($exists){
+                throw new Exception('存在待审核的预约时间修改记录,无法修改');
+            }
+
             //验证更改的预约时间必须是在领单时间内的半小内修改,否则不允许修改
             if(strtotime($work->appointment_time) != strtotime($params['appointment_time']) && (time()-strtotime($work->receive_time))>1800){
                 throw new Exception('距离领单时间已超过半小时,无法修改预约时间,请联系客服');
             }
 
-            $work->work_status = 3;//待上门
-            $work->appointment_time = strtotime($params['appointment_time']);
-            $work->save();
+            //添加预约时间修改待审核记录
+            ServiceWorkAppointmentLog::create([
+                'status'=>0,//待审核
+                'work_id'=>$work->id,
+                '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);
+            // $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) {
@@ -1139,9 +1155,14 @@ 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));
@@ -1295,4 +1316,31 @@ class ServiceWorkLogic extends BaseLogic
             return false;
         }
     }
+
+    public static function appointmentAudit($params)
+    { 
+        Db::startTrans();
+        try {
+            $work = ServiceWork::where('id',$params['id'])->findOrEmpty();
+            if($work->isEmpty()){
+                throw new \Exception('工单不存在');
+            }
+            Db::commit();
+            $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);
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError('预约时间审核失败');
+            return false;
+        }
+    }
 }

+ 88 - 1
app/common/service/call/VirtualCallService.php

@@ -13,6 +13,7 @@
 // +----------------------------------------------------------------------
 
 namespace app\common\service\call;
+use think\facade\Cache;
 
 class VirtualCallService
 {
@@ -42,7 +43,8 @@ class VirtualCallService
             //"middleNumber" => "13003426180",
             "bindNumberA" => $bindNumberA,
             "bindNumberB" => $bindNumberB,
-            "maxBindingTime" => $maxBindingTime
+            "maxBindingTime" => $maxBindingTime,
+            "callbackUrl" => "",
         ];
         $params = json_encode($params);
         $response = http_request($url, $params, $header);
@@ -59,4 +61,89 @@ class VirtualCallService
         }
         return ['resultCode' => "200"];
     }
+
+    //////////////////优音云平台//////////////////////////
+    //外显固话
+    public static function addHiddedPhone($bindNumberA, $bindNumberB){
+        $url = 'https://xtapi.uincall.com/api/call/addHiddedPhone.action';
+        $header = [
+            "Content-Type:application/x-www-form-urlencoded;charset=UTF-8"
+        ];
+        $data = json_encode([['phone1' => $bindNumberA, 'phone2' => $bindNumberB]]);
+        //echo $data;die;
+        $params = [
+            'appver' => '1',
+            'timestamp' => date('YmdHis'),
+            'user' => '075533318487_dev',
+            'account' => '075533318487',
+            'data' => ($data),
+        ];
+        $token = self::getToken();
+        $params['secret'] = self::getSecret($params, $token);
+        $params = http_build_query($params, '=', '&');
+        $response = http_request($url, $params, $header);
+        return $response;
+    }
+
+    //外显小号
+    public static function bind($bindNumberA, $bindNumberB, $maxBindingTime = 60){
+        $url = 'https://xtapi.uincall.com/api/call/bindHiddedPhone.action';
+        $header = [
+            "Content-Type:application/x-www-form-urlencoded;charset=UTF-8"
+        ];
+        $params = [
+            'appver' => '1',
+            'timestamp' => date('YmdHis'),
+            'user' => '075533318487_dev',
+            'account' => '075533318487',
+            'callingId' => $bindNumberA,
+            'transferNum' => $bindNumberB,
+            'expiration' => $maxBindingTime,
+        ];
+        $token = self::getToken();
+        $params['secret'] = self::getSecret($params, $token);
+        $params = http_build_query($params, '=', '&');
+        $response = http_request($url, $params, $header);
+        return $response;
+    }
+
+    public static function getToken()
+    { 
+        if ($token = Cache::get('uincall_token')) {
+            return $token;
+        }
+        $url = 'https://xtapi.uincall.com/api/call/union400Login.action';
+        $header = [
+            "Content-Type:application/x-www-form-urlencoded;charset=UTF-8"
+        ];
+        $params = [
+            'appver' => '1',
+            'timestamp' => date('YmdHis'),
+            'user' => '075533318487_dev',
+        ];
+        $params['secret'] = self::getSecret($params, 'da7fd311e57a46af88eb972d47ebc954');
+        $params = http_build_query($params, '=', '&');
+        $response = http_request($url, $params, $header);
+        if (isset($response['errcode']) && $response['errcode'] == 0) {
+            $exp = strtotime($response['data']['expiredtime']) - time();
+            Cache::set('uincall_token', $response['data']['token'], $exp);
+            return $response['data']['token'];
+        }
+        return "";
+    }
+
+    public static function getSecret($params,$token)
+    {
+        //按键值名排序
+        ksort($params);
+        $str = '';
+        foreach ($params as $key => $value) {
+            if ($value !== '' && $value !== null) {
+                $str .= $key . $value;
+            }
+        }
+        $str .= $token;
+        $sign = md5($str);
+        return $sign;
+    }
 }