wesmiler 2 anni fa
parent
commit
1e00742116
1 ha cambiato i file con 10 aggiunte e 3 eliminazioni
  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();
             }
+
         }