ソースを参照

美团对接-取消订单预约

fang 1 年間 前
コミット
97cb7dd4d8

+ 8 - 1
app/api/controller/notify/MeiTuanNotifyController.php

@@ -55,11 +55,18 @@ class MeiTuanNotifyController extends BaseApiController
     //到店综合
     /**
      * 取消预订
-     * @return void
+     * @return \think\response\Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
      */
     public function cancellation()
     {
         Log::write('取消预订:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
+        $order = $this->request->param();
+        $order = json_decode('{"opBizCode":"AE7MKOJAV67338LIC3UD0K5TGIO","msgType":"5810001","developerId":"114657","businessId":"58","sign":"82db3112e2603fc65c9165c8c6f63ef2ff9d8f70","msgId":"4531348325686354394","message":"{\"cancelType\":\"1\",\"orderId\":\"61702316\",\"auditChannel\":\"2\",\"type\":\"2\"}","timestamp":"1741940681"}',true);
+        ThirdOrderLogic::cancelOrderHandle($order);
+        return $this->success('取消预订成功');
     }
 
     /**

+ 38 - 1
app/common/logic/ThirdOrderLogic.php

@@ -13,7 +13,8 @@ use app\common\{enum\GoodsEnum,
     model\third\ThirdGoods,
     model\third\ThirdOrders,
     model\user\User,
-    model\works\ServiceWork};
+    model\works\ServiceWork,
+    model\works\ServiceWorkLog};
 use think\facade\Db;
 use app\common\model\service_area\ServiceArea;
 
@@ -399,4 +400,40 @@ class ThirdOrderLogic extends BaseLogic
         return http_request($url,http_build_query($data));
     }
 
+    /**
+     * 取消预订
+     * @param array
+     * $order
+     * @return bool
+     */
+    public static function cancelOrderHandle(array $order)
+    {
+        $message = json_decode($order['message'], true);
+        $thirdOrders = ThirdOrders::where('orderId',$message['orderId'])->findOrEmpty();
+        Db::startTrans();
+        try {
+            // 04-11-12 不做任何限制强制取消,已支付的费用给工程师余额
+            $serviceWorkInfo = ServiceWork::find($thirdOrders->work_id);
+
+            ServiceWork::where('id', $thirdOrders->work_id)->update([
+                //'work_status' => 9,
+                'service_status' => 4,
+                'remark' => '美团取消预约订单'
+            ]);
+
+            ServiceWorkLog::create([
+                'work_id' => $thirdOrders->work_id,
+                'master_worker_id' => $serviceWorkInfo['master_worker_id'],
+                'opera_log' => "工单:{$serviceWorkInfo['work_sn']}已取消"
+            ]);
+
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
 }