Przeglądaj źródła

up - 多个节点通知

liugc 1 rok temu
rodzic
commit
415767b75d

+ 13 - 0
app/adminapi/logic/works/ServiceWorkLogic.php

@@ -366,6 +366,19 @@ class ServiceWorkLogic extends BaseLogic
             ];
             ServiceWorkLogLogic::add($work_log);
             Db::commit();
+
+
+            // 外部平台工单 - 通知外边平台
+            if($work->external_platform_id > 0){
+                event('ExternalPlatform',  [
+                    'scene' => 'service_finish',
+                    'params' => [
+                        'work_id' => $work->id,
+                    ]
+                ]);
+            }
+
+
         } catch (\Exception $e) {
             Db::rollback();
             self::setError($e->getMessage());

+ 0 - 27
app/api/controller/ServiceOrderController.php

@@ -244,33 +244,6 @@ class ServiceOrderController extends BaseApiController
         if (false === $result) {
             return $this->fail(ServiceOrderLogic::getError());
         }
-        if($result->master_worker_id!=0){
-            $workDetail = ServiceWorkAppointmentLog::where(['work_id'=>$result['id']])->order('id desc')->findOrEmpty();
-            $masterDetail = MasterWorkerLogic::detail(['id'=>$result['master_worker_id']]);
-            // 修改预约时间通知【给用户的通知】
-            $res = event('Notice',  [
-                'scene_id' => 117,
-                'params' => [
-                    'user_id' => $result['user_id'],
-                    'date' => $params['appointment_time'],
-                    'tel' => asteriskString($masterDetail['mobile']),
-                ]
-            ]);
-            // 修改预约时间通知【给工程师的通知,仅限公众号】
-            $res = event('Notice',  [
-                'scene_id' => 118,
-                'params' => [
-                    'user_id' => $result['master_worker_id'],
-                    'order_id' => $result['id'],
-                    'thing4' => $result['title'],
-                    'time5' => date('Y-m-d H:i:s',$workDetail['last_appointment_time']),
-                    'time6' => date('Y-m-d H:i:s',$workDetail['this_appointment_time']),
-                    'thing11' => (iconv_strlen($result['address'])>15)?(mb_substr($result['address'],0,15,'UTF-8').'...'):$result['address'],
-                    'phone_number8' => asteriskString($result['mobile']),
-                ]
-            ]);
-        }
-
         return $this->success('已提交改约', [], 1, 1);
     }
 

+ 29 - 0
app/api/logic/ServiceOrderLogic.php

@@ -2,6 +2,7 @@
 
 namespace app\api\logic;
 
+use app\adminapi\logic\master_worker\MasterWorkerLogic;
 use app\adminapi\service\DistributeLeafletsService;
 use app\common\enum\GoodsEnum;
 use app\common\enum\PayEnum;
@@ -965,6 +966,34 @@ class ServiceOrderLogic extends BaseLogic
             $work->save();
 
             Db::commit();
+
+            if($work->master_worker_id!=0){
+                $workDetail = ServiceWorkAppointmentLog::where(['work_id'=>$work->id])->order('id desc')->findOrEmpty();
+                $masterDetail = MasterWorkerLogic::detail(['id'=>$work->master_worker_id]);
+                // 修改预约时间通知【给用户的通知】
+                event('Notice',  [
+                    'scene_id' => 117,
+                    'params' => [
+                        'user_id' => $work->user_id,
+                        'date' => $params['appointment_time'],
+                        'tel' => asteriskString($masterDetail['mobile']),
+                    ]
+                ]);
+                // 修改预约时间通知【给工程师的通知,仅限公众号】
+                event('Notice',  [
+                    'scene_id' => 118,
+                    'params' => [
+                        'user_id' => $work->master_worker_id,
+                        'order_id' => $work->id,
+                        'thing4' => $work->title,
+                        'time5' => date('Y-m-d H:i:s',$workDetail['last_appointment_time']),
+                        'time6' => date('Y-m-d H:i:s',$workDetail['this_appointment_time']),
+                        'thing11' => addressOmit($work->address),
+                        'phone_number8' => asteriskString($work->mobile),
+                    ]
+                ]);
+            }
+
         }
         catch (\Exception $e) {
             Db::rollback();

+ 8 - 0
app/common.php

@@ -447,6 +447,14 @@ function asteriskString($str) {
         return $str;
     }
 }
+// 详细地址裁剪省略
+function addressOmit($address) {
+    if (iconv_strlen($address)>15) {
+        return (mb_substr($address,0,15,'UTF-8').'...');
+    } else {
+        return $address;
+    }
+}
 
 function getPostageRegion($ids = []) {
     $id_str = '';

+ 22 - 1
app/common/controller/InternalApiController.php

@@ -14,7 +14,7 @@ use think\facade\Log;
 
 class InternalApiController extends BaseLikeAdminController
 {
-    public array $notNeedLogin = ['confirmServiceFinish','paymentSuccessful','cancelOrder'];
+    public array $notNeedLogin = ['changeAppointment','confirmServiceFinish','paymentSuccessful','cancelOrder'];
 
     private function checkSign(){
         $params = $this->request->param();
@@ -27,6 +27,27 @@ class InternalApiController extends BaseLikeAdminController
         return false;
     }
 
+    public function changeAppointment()
+    {
+        try {
+            $params = $this->request->param();
+            if(!$this->checkSign()) throw new \Exception('签名错误',404);
+            //sn appointment_time
+            if(!isset($params['appointment_time']) || empty($params['appointment_time'])){
+                throw new \Exception('预约时间不能为空',404);
+            }
+            if(!isset($params['sn']) || empty($params['sn'])){
+                throw new \Exception('订单号不能为空',404);
+            }
+            $result = ServiceOrderLogic::approvalChangeAppointment($params);
+            if (false === $result) {
+                throw new \Exception(ServiceOrderLogic::getError(),404);
+            }
+            return $this->success('内部重新预约完成', [], 0, 1);
+        }catch(\Exception $e){
+            return $this->fail($e->getMessage(),[],$e->getCode());
+        }
+    }
 
     public function confirmServiceFinish()
     {

+ 37 - 1
app/common/logic/ExternalPlatformLogic.php

@@ -22,6 +22,9 @@ class ExternalPlatformLogic  extends BaseLogic
                 case 'confirm_price':
                     self::confirmPrice($params['params']);
                     break;
+                case 'service_finish':
+                    self::serviceFinish($params['params']);
+                    break;
                 default:
                     throw new \Exception('场景不存在');
             }
@@ -34,7 +37,7 @@ class ExternalPlatformLogic  extends BaseLogic
     }
 
 
-
+    // 工程师报价通知
     private static function confirmPrice($params)
     {
         try {
@@ -75,6 +78,39 @@ class ExternalPlatformLogic  extends BaseLogic
             throw new \Exception($e->getMessage());
         }
     }
+    // 工程师服务完成通知
+    private static function serviceFinish($params)
+    {
+        try {
+
+            $work = ServiceWork::where(['id'=>$params['work_id']])->findOrEmpty();
+            if($work->isEmpty()){
+                throw new \Exception('工单不存在');
+            }
+            if($work->external_platform_id > 0){
+                $externalPlatform = ExternalPlatform::find($work->external_platform_id);
+
+                $data = [
+                    'timestamp'=>time(),
+                    'scene'=>'service_finish',
+                    'version'=>'1',
+                    'notice_data'=>json_encode([
+                        'work_sn'=>$work->work_sn
+                    ],JSON_UNESCAPED_UNICODE)
+                ];
+                $data['sign'] = ExternalPlatform::getSign($externalPlatform['appkey'],$data);
+                $res = http_request($externalPlatform['send_url'],http_build_query($data));
+                Log::info('ExternalPlatform-serviceFinish:'
+                    .'url:'.$externalPlatform['send_url']
+                    .'|data:'.json_encode($data,JSON_UNESCAPED_UNICODE)
+                    .'|res:'.json_encode([$res],JSON_UNESCAPED_UNICODE)
+                );
+            }
+            return true;
+        } catch (\Exception $e) {
+            throw new \Exception($e->getMessage());
+        }
+    }
 
 
 }