xxxrrrdddd 2 years ago
parent
commit
283fe6553f
2 changed files with 12 additions and 9 deletions
  1. 2 1
      application/config.php
  2. 10 8
      extend/logicmodel/GoodsMergeLogic.php

+ 2 - 1
application/config.php

@@ -164,7 +164,8 @@ return [
         // 日志保存目录
         'path'  => LOG_PATH,
         // 日志记录级别
-        'level' => ['error'],
+        'level' => ['error','sql'],
+        'apart_level'   =>  ['error','sql'],
     ],
     // +----------------------------------------------------------------------
     // | Trace设置 开启 app_trace 后 有效

+ 10 - 8
extend/logicmodel/GoodsMergeLogic.php

@@ -57,6 +57,15 @@ class GoodsMergeLogic
         if(!$hash){
             api_error('暂无可用hash');
         }
+        $old_user_goods_ids=[];
+        foreach ($info['merge'] as $merge){
+            $userGoods=UsersGoods::canMerge($merge['source_goods_id'],$userId)
+                ->limit($merge['num'])->lock(true)->select();
+            if(count($userGoods)!=$merge['num']){
+                api_error('藏品数量不足');
+            }
+            $old_user_goods_ids=array_merge($old_user_goods_ids,array_column($userGoods,'id'));
+        }
         $goods=[];
         $goods['uid'] = $userId;
         $goods['goods_id'] = $info['id'];
@@ -65,13 +74,6 @@ class GoodsMergeLogic
         $goods['is_merge']=1;
         $userNewGoods=UsersGoods::create($goods);
         $userNewGoods->addHash($hash,-2);
-        foreach ($info['merge'] as $merge){
-            $userGoods=UsersGoods::canMerge($merge['source_goods_id'],$userId)
-                ->limit($merge['num'])->lock(true)->select();
-            if(count($userGoods)!=$merge['num']){
-                api_error('藏品数量不足');
-            }
-            UsersGoods::whereIn('id',array_column($userGoods,'id'))->update(['status'=>6,'merged_user_goods_id'=>$userNewGoods['id']]);
-        }
+        UsersGoods::whereIn('id',$old_user_goods_ids)->update(['status'=>6,'merged_user_goods_id'=>$userNewGoods['id']]);
     }
 }