Explorar el Código

美团对接-第三方订单

fang hace 1 año
padre
commit
2bc338aaf7

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

@@ -91,12 +91,14 @@ class MeiTuanNotifyController extends BaseApiController
 
     /**
      * 改约提交
-     * @return void
+     * @return \think\response\Json
      */
     public function changeBooking()
     {
         $order = $this->request->param();
         Log::write('改约提交:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
+        ThirdOrderLogic::updateOrderHandle($order);
+        return $this->success('改约提交成功');
     }
 
 

+ 60 - 16
app/common/logic/ThirdOrderLogic.php

@@ -14,6 +14,7 @@ use app\common\{enum\GoodsEnum,
     model\third\ThirdOrders,
     model\user\User,
     model\works\ServiceWork,
+    model\works\ServiceWorkAppointmentLog,
     model\works\ServiceWorkLog};
 use think\facade\Db;
 use app\common\model\service_area\ServiceArea;
@@ -412,25 +413,66 @@ class ThirdOrderLogic extends BaseLogic
     public static function cancelOrderHandle(array $order)
     {
         $message = json_decode($order['message'], true);
-        $thirdOrders = ThirdOrders::where('orderId',$message['orderId'])->findOrEmpty();
-        $thirdOrders->bookStatus = 3;
-        $thirdOrders->save();
         Db::startTrans();
         try {
-            // 04-11-12 不做任何限制强制取消,已支付的费用给工程师余额
-            $serviceWorkInfo = ServiceWork::find($thirdOrders->work_id);
-            if(!empty($serviceWorkInfo)){
-                ServiceWork::where('id', $thirdOrders->work_id)->update([
-                    //'work_status' => 9,
-                    'service_status' => 4,
-                    'remark' => '美团取消预约订单'
-                ]);
+            $thirdOrders = ThirdOrders::where('orderId',$message['orderId'])->findOrEmpty();
+            if(!$thirdOrders->isEmpty()){
+                $thirdOrders->bookStatus = 3;
+                $thirdOrders->save();
+                $serviceWorkInfo = ServiceWork::find($thirdOrders->work_id);
+                if(!empty($serviceWorkInfo)){
+                    $appointment_time = '2099-12-31 23:59:59';
+                    ServiceWorkAppointmentLog::create([
+                        'work_id'=>$serviceWorkInfo->id,
+                        'last_appointment_time'=>strtotime($serviceWorkInfo->appointment_time),
+                        'this_appointment_time'=>strtotime($appointment_time),
+                    ]);
+                    //修改预计完成时间
+                    if ($serviceWorkInfo->estimated_finish_time) {
+                        $serviceWorkInfo->estimated_finish_time = strtotime($appointment_time) + (strtotime($serviceWorkInfo->estimated_finish_time) - strtotime($serviceWorkInfo->appointment_time));
+                    }
+                    $serviceWorkInfo->appointment_time = strtotime($appointment_time);
+                    $serviceWorkInfo->save();
+                }
+            }
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
 
-                ServiceWorkLog::create([
-                    'work_id' => $thirdOrders->work_id,
-                    'master_worker_id' => $serviceWorkInfo['master_worker_id'],
-                    'opera_log' => "工单:{$serviceWorkInfo['work_sn']}已取消"
-                ]);
+    /**
+     * 美团改约通知
+     * @param array $order
+     * @return bool
+     */
+    public static function updateOrderHandle(array $order)
+    {
+        $message = json_decode($order['message'], true);
+        Db::startTrans();
+        try {
+            $thirdOrders = ThirdOrders::where('orderId',$message['orderId'])->findOrEmpty();
+            if(!$thirdOrders->isEmpty()){
+                $thirdOrders->bookStatus = 2;
+                $thirdOrders->save();
+                $serviceWorkInfo = ServiceWork::find($thirdOrders->work_id);
+                if(!empty($serviceWorkInfo)){
+                    $appointment_time = $message['reserveEndtime'];
+                    ServiceWorkAppointmentLog::create([
+                        'work_id'=>$serviceWorkInfo->id,
+                        'last_appointment_time'=>strtotime($serviceWorkInfo->appointment_time),
+                        'this_appointment_time'=>strtotime($appointment_time),
+                    ]);
+                    //修改预计完成时间
+                    if ($serviceWorkInfo->estimated_finish_time) {
+                        $serviceWorkInfo->estimated_finish_time = strtotime($appointment_time) + (strtotime($serviceWorkInfo->estimated_finish_time) - strtotime($serviceWorkInfo->appointment_time));
+                    }
+                    $serviceWorkInfo->appointment_time = strtotime($appointment_time);
+                    $serviceWorkInfo->save();
+                }
             }
             Db::commit();
             return true;
@@ -533,6 +575,8 @@ class ThirdOrderLogic extends BaseLogic
     {
         $third_order = ThirdOrders::where('work_id',$work_id)->findOrEmpty();
         if(!$third_order->isEmpty() && !empty($third_order['request_msg'])){
+            $third_order->bookStatus = 3;
+            $third_order->save();
             $url = 'https://api-open-cater.meituan.com/ddzh/yuding/merchantcancelorder';
             $opBizCode = !empty($third_order['request_msg'])?json_decode($third_order['request_msg'],true)['opBizCode']:'';
             $accessToken = $opBizCode == 'AE7MKOJAV67338LIC3UD0K5TGIO' ? self::shop_token2['accessToken'] : self::shop_token1['accessToken'];