Jelajahi Sumber

错误原因

shish 8 bulan lalu
induk
melakukan
fdd306c634
1 mengubah file dengan 19 tambahan dan 10 penghapusan
  1. 19 10
      biz-ghs/custom/classes/CustomClass.php

+ 19 - 10
biz-ghs/custom/classes/CustomClass.php

@@ -73,18 +73,27 @@ class CustomClass extends BaseClass
 
     public static function pullOtherShopCustom($data)
     {
-        $toShopId = $data['toShopId'] ?? 0;
-        $fromShopId = $data['fromShopId'] ?? 0;
-        //指定当前环境为批发商,重要!!!
-        Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'ghs');
-        $fromCustomList = CustomClass::getAllByCondition(['ownShopId' => $fromShopId], null, '*');
-        if (!empty($fromCustomList)) {
-            foreach ($fromCustomList as $fromCustomer) {
-                $exist = CustomClass::exists(['ownShopId' => $toShopId, 'shopId' => $fromCustomer['shopId']]);
-                if (!$exist) {
-                    CustomClass::build($toShopId, $fromCustomer['shopId'], $fromCustomer['name']);
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            $toShopId = $data['toShopId'] ?? 0;
+            $fromShopId = $data['fromShopId'] ?? 0;
+            //指定当前环境为批发商,重要!!!
+            Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'ghs');
+            $fromCustomList = CustomClass::getAllByCondition(['ownShopId' => $fromShopId], null, '*');
+            if (!empty($fromCustomList)) {
+                foreach ($fromCustomList as $fromCustomer) {
+                    $exist = CustomClass::exists(['ownShopId' => $toShopId, 'shopId' => $fromCustomer['shopId']]);
+                    if (!$exist) {
+                        CustomClass::build($toShopId, $fromCustomer['shopId'], $fromCustomer['name']);
+                    }
                 }
             }
+            $transaction->commit();
+            return true;
+        } catch (\Exception $exception) {
+            $transaction->rollBack();
+            noticeUtil::push("拉取客户报报错:{$fromShopId} {$toShopId},报错内容:" . $exception->getMessage(), '15280215347');
         }
         return true;
     }