Ver código fonte

【Mod】优化起购限购逻辑

liuxiangxin 4 meses atrás
pai
commit
c71c89318a
1 arquivos alterados com 12 adições e 12 exclusões
  1. 12 12
      app/Http/Controllers/Api/Orders.php

+ 12 - 12
app/Http/Controllers/Api/Orders.php

@@ -118,6 +118,18 @@ class Orders extends Api{
 					if( in_array($value['name'],$productInfo['tag_exclude']) )  return json_send(['code'=>'error','msg'=>'不在 '.$productInfo['product_name'].' 可参与范围','data'=>['error'=>'用户在标签排除范围']]);
 				}
 			}
+			// 如果产品限购
+			if( $productInfo['quota'] )	{
+				// 是否在限购时间,当前时间大于开始时间,并且小于结束时间
+				if( $productInfo['quota_start'] <= $time && $time <= $productInfo['quota_end'] ){
+					// 通过时间查询商品的购买总数
+					$total 				= $OrdersProduct->query()->whereIn('status',[0,1,2,3,8,9])->where([['custom_uid','=',$uid],['is_rebate','=',0],['product_id','=',$productInfo['id']],['insert_time','>=',$productInfo['quota_start']],['insert_time','<=',$productInfo['quota_end']]])->sum('buy_num');
+					// 判断限购数量
+					$total	 			= $buyNum[$buyInfo['product_id']] + $total;
+					// 如果超过数量
+					if( $total > $productInfo['quota'] ) return json_send(['code'=>'error','msg'=>'限购'.$productInfo['quota'].'套-'.$productInfo['product_name'],'data'=>['error'=>'已超限=>'.($total - $productInfo['quota'])]]);
+				}
+			}
 			// 如果存在SKU
 			if( $buyInfo['product_skuid'] ) {
 				// 判断SKU信息存不存在
@@ -161,18 +173,6 @@ class Orders extends Api{
 					return json_send(['code'=>'error','msg'=>'最少购买'.$productInfo['min_quota'].'套-'.$productInfo['product_name'],'data'=>['error'=>'最少购买'.$productInfo['min_quota'].'套-'.$productInfo['product_name']]]);
 				}
 			}
-			// 如果产品限购
-			if( $productInfo['quota'] )	{
-				// 是否在限购时间,当前时间大于开始时间,并且小于结束时间
-				if( $productInfo['quota_start'] <= $time && $time <= $productInfo['quota_end'] ){
-					// 通过时间查询商品的购买总数
-					$total 				= $OrdersProduct->query()->whereIn('status',[0,1,2,3,8,9])->where([['custom_uid','=',$uid],['is_rebate','=',0],['product_id','=',$productInfo['id']],['insert_time','>=',$productInfo['quota_start']],['insert_time','<=',$productInfo['quota_end']]])->sum('buy_num');
-					// 判断限购数量
-					$total	 			= $buyNum[$buyInfo['product_id']] + $total;
-					// 如果超过数量
-					if( $total > $productInfo['quota'] ) return json_send(['code'=>'error','msg'=>'限购'.$productInfo['quota'].'套-'.$productInfo['product_name'],'data'=>['error'=>'已超限=>'.($total - $productInfo['quota'])]]);
-				}
-			}
 			// 需要扣除的库存
 			$productList[$buyInfo['product_id']]['decr'] = empty($productList[$buyInfo['product_id']]['decr']) ? $buyInfo['buy_num'] : $productList[$buyInfo['product_id']]['decr'] + $buyInfo['buy_num'];
 			// 判断库存