|
@@ -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']]);
|
|
|
}
|
|
|
}
|