ソースを参照

MtController 代码调整

shizhongqi 4 年 前
コミット
6e5368163a
2 ファイル変更21 行追加19 行削除
  1. 18 13
      app-hd/controllers/MtController.php
  2. 3 6
      common/base/models/Base.php

+ 18 - 13
app-hd/controllers/MtController.php

@@ -37,17 +37,15 @@ class MtController extends PublicController
         }
 
         $data = arrayUtil::humpUnderlineConversion($post, 1);
+        $orderId = $data['orderId'];
+        $mtOrder = MtOrderClass::getByCondition(['orderId' => $orderId]);
+        if (!empty($mtOrder)) {
+            Yii::warning('订单号已存在:' . $orderId);
+            return Json::encode(['data' => 'ok']);
+        }
+
         $mtOrder = MtOrderClass::add($data);
         return Json::encode(['data' => 'ok']);
-
-        $app = new Application($this->config);
-
-        $params = ['order_id' => '27061900338318741', 'is_mt_logistics' => 1];
-        $orderDetail = $app->order->getOrderDetail($params);
-        print_r(json_decode($orderDetail, true));
-
-        // 商品类、活动类接口支持异步队列
-        $app->goods->async()->create([]);
     }
 
     public function actionCancelOrder()
@@ -56,11 +54,18 @@ class MtController extends PublicController
         if(!empty($post)) {
             Yii::warning('cancelOrder: ' . urldecode(json_encode($post)));
         }
-        $get = Yii::$app->request->get();
-        if(!empty($get)) {
-            Yii::warning('cancelOrder: ' . json_encode($get));
-        }
 
         return Json::encode(['data' => 'ok']);
     }
+
+    public function demo() {
+        $app = new Application($this->config);
+
+        $params = ['order_id' => '27061900338318741', 'is_mt_logistics' => 1];
+        $orderDetail = $app->order->getOrderDetail($params);
+        print_r(json_decode($orderDetail, true));
+
+        // 商品类、活动类接口支持异步队列
+        $app->goods->async()->create([]);
+    }
 }

+ 3 - 6
common/base/models/Base.php

@@ -28,13 +28,10 @@ class Base extends ActiveRecord
             }
         }
 
-        if ($model->validate()) {
-            // 所有输入通过验证
-        } else {
+        if (!$model->validate()) {
             // 验证失败: $errors 是一个包含错误信息的数组
-            $errors = $model->errors;
-            \Yii::warning('model validate errors: ' . json_encode($errors));
-            util::fail('非法查询方式:' . json_encode($errors));
+            \Yii::error(static::tableName() . ' -- model validate errors: ' . json_encode($model->errors));
+            util::fail('输入数据验证失败');
         }
 
         $model->save();