Ver código fonte

【Mod】优化产品限购以及起购限制提示

liuxiangxin 4 meses atrás
pai
commit
8e4a1a05e5

+ 6 - 6
app/Http/Controllers/Admin/Product.php

@@ -244,9 +244,9 @@ class Product extends Auth{
 					// SKU限购,所以限购时间也必须填
 					if( $value['quota'] && ( !$data['quota_start'] || !$data['quota_end'] )) return json_send(['code'=>'error','msg'=>'SKU限购时,请填限购时间','data'=>['error'=>'SKU限购时,请填限购时间']]);
 					// 限购提示
-					if( $value['min_quota'] && $value['min_quota'] > $value['quota'] ) 	return json_send(['code'=>'error','msg'=>$attrNames.'起购数量请勿大于限购数量','data'=>['error'=>$attrNames.'起购数量请勿大于限购数量']]);
+					if( $value['min_quota'] > $value['quota'] ) 	return json_send(['code'=>'error','msg'=>$attrNames.'起购数量请勿大于限购数量','data'=>['error'=>$attrNames.'起购数量请勿大于限购数量']]);
 					// 提示起购数量异常,如果总起购数量小于SKU起购数量,提示
-					if( $data['min_quota'] && $value['min_quota'] < $data['min_quota'] ) return json_send(['code'=>'error','msg'=>'SKU的起购数量不能小于总起购数量','data'=>['error'=>'SKU的起购数量不能小于总起购数量']]);
+					if( $value['min_quota'] && $value['min_quota'] < $data['min_quota'] ) return json_send(['code'=>'error','msg'=>'SKU的起购数量不能小于总起购数量','data'=>['error'=>'SKU的起购数量不能小于总起购数量']]);
 				}
 				// 限购数量
 				$quota 				= array_sum(array_column($skuList,'quota'));
@@ -465,9 +465,9 @@ class Product extends Auth{
 					// SKU限购,所以限购时间也必须填
 					if( $value['quota'] && ( !$data['quota_start'] || !$data['quota_end'] )) 	return json_send(['code'=>'error','msg'=>'SKU限购时,请填限购时间','data'=>['error'=>'SKU限购时,请填限购时间']]);
 					// 限购提示
-					if( $value['min_quota'] && $value['min_quota'] > $value['quota'] ) 	return json_send(['code'=>'error','msg'=>$attrNames.'起购数量请勿大于限购数量','data'=>['error'=>$attrNames.'起购数量请勿大于限购数量']]);
+					if( $value['min_quota'] > $value['quota'] ) 	return json_send(['code'=>'error','msg'=>$attrNames.'起购数量请勿大于限购数量','data'=>['error'=>$attrNames.'起购数量请勿大于限购数量']]);
 					// 提示起购数量异常,如果总起购数量小于SKU起购数量,提示
-					if( $data['min_quota'] && $value['min_quota'] < $data['min_quota'] ) 	return json_send(['code'=>'error','msg'=>'SKU的起购数量不能小于总起购数量','data'=>['error'=>'SKU的起购数量不能小于总起购数量']]);
+					if( $value['min_quota'] && $value['min_quota'] < $data['min_quota'] ) 	return json_send(['code'=>'error','msg'=>'SKU的起购数量不能小于总起购数量','data'=>['error'=>'SKU的起购数量不能小于总起购数量']]);
 				}
 				// 限购数量
 				$quota 				= array_sum(array_column($skuList,'quota'));
@@ -717,9 +717,9 @@ class Product extends Auth{
 					// SKU限购,所以限购时间也必须填
 					if( $value['quota'] && ( !$data['quota_start'] || !$data['quota_end'] )) 	return json_send(['code'=>'error','msg'=>'SKU限购时,请填限购时间','data'=>['error'=>'SKU限购时,请填限购时间']]);
 					// 限购提示
-					if( $value['min_quota'] && $value['min_quota'] > $value['quota'] ) 	return json_send(['code'=>'error','msg'=>$attrNames.'起购数量请勿大于限购数量','data'=>['error'=>$attrNames.'起购数量请勿大于限购数量']]);
+					if( $value['min_quota'] > $value['quota'] ) 	return json_send(['code'=>'error','msg'=>$attrNames.'起购数量请勿大于限购数量','data'=>['error'=>$attrNames.'起购数量请勿大于限购数量']]);
 					// 提示起购数量异常,如果总起购数量小于SKU起购数量,提示
-					if( $data['min_quota'] && $value['min_quota'] < $data['min_quota'] ) 	return json_send(['code'=>'error','msg'=>'SKU的起购数量不能小于总起购数量','data'=>['error'=>'SKU的起购数量不能小于总起购数量']]);
+					if( $value['min_quota'] && $value['min_quota'] < $data['min_quota'] ) 	return json_send(['code'=>'error','msg'=>'SKU的起购数量不能小于总起购数量','data'=>['error'=>'SKU的起购数量不能小于总起购数量']]);
 				}
 				// 限购数量
 				$quota 				= array_sum(array_column($skuList,'quota'));

+ 23 - 21
app/Http/Controllers/Api/Orders.php

@@ -118,26 +118,6 @@ 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['min_quota'] )	{
-				// 如果购买数量小于最低起购数量
-				if( $buyNum[$buyInfo['product_id']] < $productInfo['min_quota'] ){
-					// 如果超过数量
-					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'])]]);
-				}
-			}
 			// 如果存在SKU
 			if( $buyInfo['product_skuid'] ) {
 				// 判断SKU信息存不存在
@@ -166,11 +146,33 @@ class Orders extends Api{
 						if( $total > $skuInfo['quota'] ) return json_send(['code'=>'error','msg'=>'限购'.$skuInfo['quota'].'套-'.$productInfo['product_name'].'【'.$skuInfo['sku_attr_names'].'】','data'=>['error'=>'已超限=>'.($total - $skuInfo['quota'])]]);
 					}
 				}
+				// 删除起购字段,避免影响后续产品最低起购的判定
+				unset($skuInfo['min_quota']);
 				// 如果SKU存在,合并产品信息
-				$productInfo			= array_merge($productInfo,$skusList[$buyInfo['product_skuid']]);
+				$productInfo			= array_merge($productInfo,$skuInfo);
 				// 需要扣除的库存
 				$skusList[$buyInfo['product_skuid']]['decr'] = empty($skusList[$buyInfo['product_skuid']]['decr']) ? $buyInfo['buy_num'] : $skusList[$buyInfo['product_skuid']]['decr'] + $buyInfo['buy_num'];
 			}
+			// 如果产品有最低起购
+			if( $productInfo['min_quota'] )	{
+				// 如果购买数量小于最低起购数量
+				if( $buyNum[$buyInfo['product_id']] < $productInfo['min_quota'] ){
+					// 如果超过数量
+					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'];
 			// 判断库存