|
@@ -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'];
|
|
|
// 判断库存
|