Browse Source

状态管理

shish 10 months ago
parent
commit
ae1f019ec6
1 changed files with 11 additions and 21 deletions
  1. 11 21
      app-ghs/controllers/IntraCityController.php

+ 11 - 21
app-ghs/controllers/IntraCityController.php

@@ -672,7 +672,6 @@ class IntraCityController extends BaseController
         if (empty($callbackData)) {
             $postStr = file_get_contents('php://input');
             $callbackData = json_decode($postStr, true);
-
             if (empty($callbackData)) {
                 util::fail('回调请求的数据为空');
             }
@@ -698,15 +697,12 @@ class IntraCityController extends BaseController
                 Yii::error('订单不存在. store_order_id: ' . $storeOrderId . ',wx_store_id: ' . $wxStoreId);
                 return $this->asJson(['return_code' => 1, 'return_msg' => '系统错误']);
             }
-            // 从 $storeOrderId 提取 orderId
-            $arr = explode('_', $storeOrderId);
-            $orderId = intval($arr[0]);
-            if ($orderId == 0) {
-                Yii::error('订单号为0.  store_order_id: ' . $storeOrderId . ',wx_store_id: ' . $wxStoreId);
-                return $this->asJson(['return_code' => 1, 'return_msg' => '系统错误']);
+            $orderId = $eo->orderId ?? 0;
+            if (empty($orderId)) {
+                return $this->asJson(['return_code' => 1, 'return_msg' => '系统错误2']);
             }
-
-            $tx = Yii::$app->db->beginTransaction(); // ====================== 开启事务
+            // ====================== 开启事务
+            $tx = Yii::$app->db->beginTransaction();
             $msg = ''; // 发通知的内容(默认为空,根据情况生成。没有内容则不会发通知)
             $orderStatus = intval($callbackData['order_status']);
             switch ($orderStatus) {
@@ -780,23 +776,17 @@ class IntraCityController extends BaseController
                     $msg = '订单配送异常,订单编号 ';
                     break;
             }
-
-            if ($msg != '') { // $msg 不为空,则发通知
+            $eo->save();
+            // ====================== 事务提交
+            $tx->commit();
+            if (!empty($msg)) {
                 $order = OrderClass::getById($orderId, true, 'id, shopId, customName, sendNum');
                 $shop = ShopClass::getById($order->shopId, true, 'id, ptStyle, mainId');
                 $result = $msg . $order->sendNum;
                 WxMessageClass::expressErrorInform($shop, $order->customName, $orderId, $result);
             }
-            $re = $eo->save();
-            if (!$re) {
-                noticeUtil::push('同城配送回调更新订单状态失败. store_order_id:' . $storeOrderId . ',wx_store_id:' . $wxStoreId . ',status:' . $eo->status);
-                Yii::error('更新订单状态失败. store_order_id:' . $storeOrderId . ',wx_store_id:' . $wxStoreId . ',status:' . $eo->status);
-                $tx->rollBack();  // ====================== 事务回滚
-                return $this->asJson(['return_code' => 1, 'return_msg' => '系统错误']);
-            }
-
-            $tx->commit();  // ====================== 事务提交
-            return $this->asJson(['return_code' => 0, 'return_msg' => 'OK']); // 成功状态的返回数据
+            // 成功状态的返回数据
+            return $this->asJson(['return_code' => 0, 'return_msg' => 'OK']);
         } catch (\Exception $e) {
             Yii::error('同城配送回调处理异常:' . $e->getMessage());
             return $this->asJson(['return_code' => 1, 'return_msg' => '系统错误']);