wesmiler hace 2 años
padre
commit
1e00742116
Se han modificado 1 ficheros con 10 adiciones y 3 borrados
  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();
             }
+
         }