wesmiler 2 лет назад
Родитель
Сommit
1e00742116
1 измененных файлов с 10 добавлено и 3 удалено
  1. 10 3
      app/Services/Api/GoodsService.php

+ 10 - 3
app/Services/Api/GoodsService.php

@@ -332,11 +332,18 @@ class GoodsService extends BaseService
         if ($goods) {
             RedisService::set($cacheKey . '_page', $page, rand(300, 600));
             RedisService::set($cacheKey, $goods, rand(5, 10));
-            $this->model->insertAll($goods);
+            DB::beginTransaction();
+            try {
+                $this->model->insertAll($goods);
+                if($skus){
+                    GoodsSkuModel::insert($skus);
+                }
 
-            if($skus){
-                GoodsSkuModel::insert($skus);
+                DB::commit();
+            }catch (\Exception $exception){
+                DB::rollBack();
             }
+
         }