浏览代码

增加工单虚拟拨号、工单配件修改

dongxiaoqin 10 月之前
父节点
当前提交
93b70e8214

+ 11 - 1
app/adminapi/logic/works/ServiceWorkLogic.php

@@ -52,6 +52,7 @@ 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;
 
 /**
  * ServiceWork逻辑
@@ -442,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;
@@ -1138,6 +1139,15 @@ class ServiceWorkLogic extends BaseLogic
                 $work->first_contact_time = time();
                 $work->save();
             }
+            $worker_mobile = $params['user_info']['mobile'];
+            $res = VirtualCallService::auth($worker_mobile, $work->mobile, 60);
+            if (isset($res['result']) && $res['result'] == '000000') {
+                return ['middleNumber' => $res['middleNumber']];
+            } else {
+                Log::info('虚拟外呼失败:'.json_encode($res));
+                throw new \Exception('虚拟外呼失败');
+            }
+
             return true;
         }
         catch  (\Exception $e) {

+ 28 - 0
app/api/controller/notify/VirtualCallController.php

@@ -0,0 +1,28 @@
+<?php
+
+namespace app\api\controller\notify;
+
+use app\api\controller\BaseApiController;
+use app\common\service\call\VirtualCallService;
+
+/**
+ * 虚拟呼叫结果回调接口
+ * Class VirtualCallController
+ * @package app\api\controller\notify
+ */
+class VirtualCallController extends BaseApiController
+{
+
+    public array $notNeedLogin = ['notify'];
+
+    public function notify()
+    {
+        $params = $this->request->param();
+        if (!empty($params['dataType']) && $params['dataType'] == 'ROBOT_TASK_STATUS_CHANGE') {
+            VirtualCallService::notify($params);
+        }
+        
+        return $this->data(['resultCode' => "200"]);
+    }
+
+}

+ 39 - 9
app/common/service/call/VirtualCallService.php

@@ -16,17 +16,47 @@ namespace app\common\service\call;
 
 class VirtualCallService
 {
+    public static $host = 'https://101.37.133.245:11008/';
+    public static $appId = '989460';
+    public static $accessToken = 'edcd07d7216446b6ae549a2e621eb42b';
+
+    public static function timestamp(){
+        $time = explode (" ", microtime () );
+        return $time[1] . "000";
+    }
+    /**
+     * @notes 鉴权
+     */
+    public static function auth($bindNumberA, $bindNumberB, $maxBindingTime = 60)
+    {
+        $timestamp = self::timestamp();
+        $sig = md5(self::$appId.self::$accessToken.$timestamp);
+        $authorization = base64_encode(self::$appId.":".$timestamp);
+        $url = self::$host . 'voice/1.0.0/middleNumberAXB/'.self::$appId.'/'.$sig;
+        $header = [
+            "Accept:application/json",
+            "Content-Type:application/json;charset=utf-8",
+            "Authorization:$authorization"
+        ];
+        $params = [
+            //"middleNumber" => "13003426180",
+            "bindNumberA" => $bindNumberA,
+            "bindNumberB" => $bindNumberB,
+            "maxBindingTime" => $maxBindingTime
+        ];
+        $params = json_encode($params);
+        $response = http_request($url, $params, $header);
+        return $response;
+    }
+
     /**
-     * @notes 设置配置值
-     * @param $type
-     * @param $name
-     * @param $value
-     * @return mixed
-     * @author 段誉
-     * @date 2021/12/27 15:00
+     * @notes 虚拟外呼回调通知
      */
-    public static function set(string $type, string $name, $value)
+    public static function notify($params)
     {
-        return '';
+        if (empty($params['appId']) || $params['appId'] != self::$appId) {
+            return ['resultCode' => "200"];
+        }
+        return ['resultCode' => "200"];
     }
 }

+ 5 - 6
app/workerapi/controller/WorksController.php

@@ -338,7 +338,7 @@ class WorksController extends BaseApiController
 
     
     /**
-     * 第一次电话联系客户
+     * 电话联系客户(虚拟拨号)
      * @return \think\response\Json
      */
     public function contactCustomer()
@@ -351,8 +351,7 @@ class WorksController extends BaseApiController
         if (false === $result) {
             return $this->fail(ServiceWorkLogic::getError());
         }
-        
-        return $this->success('成功', [], 1, 1);
+        return $this->data($result);
     }
 
     /**
@@ -435,13 +434,13 @@ class WorksController extends BaseApiController
      */
     public function selfSparePart()
     {
-        $params = (new ServiceWorkValidate())->post()->goCheck('sparepart');
+        $params = (new ServiceWorkValidate())->post()->goCheck('sparepart', [
+            'user_id' => $this->userId,
+        ]);
         $result = ServiceWorkLogic::selfSparePart($params);
         if (false === $result) {
             return $this->fail(ServiceWorkLogic::getError());
         }
         return $this->success('修改成功', [], 1, 1);
     }
-
-
 }