From d3b8758b67a3e6f55a25944e323bc0907cee2f37 Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Sat, 18 Nov 2023 15:36:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=8A=B5=E6=89=A3=E9=87=91=E9=A2=9D=E6=94=AF=E6=8C=81=E5=9B=BA?= =?UTF-8?q?=E5=AE=9A=E9=87=91=E9=A2=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/store/order/StoreCartDao.php | 2 +- .../order/StoreOrderCreateRepository.php | 115 +++++++++--------- .../store/product/ProductRepository.php | 6 + 3 files changed, 66 insertions(+), 57 deletions(-) diff --git a/app/common/dao/store/order/StoreCartDao.php b/app/common/dao/store/order/StoreCartDao.php index df0a8d8..ea3f64a 100644 --- a/app/common/dao/store/order/StoreCartDao.php +++ b/app/common/dao/store/order/StoreCartDao.php @@ -76,7 +76,7 @@ class StoreCartDao extends BaseDao { return StoreCart::getDb()->where('uid', $uid)->with([ 'product' => function (Relation $query) use ($address) { - $query->field('product_id,cate_id,image,store_name,is_show,status,is_del,unit_name,price,mer_status,temp_id,give_coupon_ids,is_gift_bag,is_used,product_type,old_product_id,integral_rate,delivery_way,delivery_free,type,extend,pay_limit,once_max_count,once_min_count,mer_svip_status,svip_price_type,refund_switch,integral_give_switch,integral_give_set,integral_give_type,integral_give_rate,integral_give_money'); + $query->field('product_id,cate_id,image,store_name,is_show,status,is_del,unit_name,price,mer_status,temp_id,give_coupon_ids,is_gift_bag,is_used,product_type,old_product_id,integral_rate,delivery_way,delivery_free,type,extend,pay_limit,once_max_count,once_min_count,mer_svip_status,svip_price_type,refund_switch,integral_give_switch,integral_give_set,integral_give_type,integral_give_rate,integral_give_money,integral_deduction_type,integral_deduction_money'); if ($address) { $cityIds = array_filter([$address->province_id, $address->city_id, $address->district_id, $address->street_id]); $query->with([ diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index 1027e3e..d43d461 100644 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -790,68 +790,71 @@ class StoreOrderCreateRepository extends StoreOrderRepository $integralFlag = $sysIntegralConfig['integral_status'] && $merIntegralConfig['mer_integral_status'] && $integralMoney > 0; // Log::info('积分抵扣 - 持有积分信息:'.var_export(['商户id'=>$merchantCart['mer_id'],'用户持有'=>$integralInfo],1)); - //计算积分抵扣 + // 计算积分抵扣 foreach ($merchantCart['list'] as &$cart) { - // 获取积分抵扣比例 可以使用积分抵扣商品支付金额的比例 - $integralRate = $cart['product']['integral_rate'];// 商品单独设置比例 - if ($integralRate < 0) $integralRate = $merIntegralConfig['mer_integral_rate'];// 商户统一设置比例 - else if($integralRate > 0) $integralRate = min(bcdiv($integralRate, 100, 4), 1); + // 获取商品可以抵扣的金额 + if($cart['product']['integral_rate'] == -1){ + // 统一设置 抵扣比例 + $integralRate = $merIntegralConfig['mer_integral_rate'];// 商户统一设置比例 + // 当前商品可以抵扣的金额 + $productIntegralPrice = (float)min(bcmul(bcmul($this->cartByPrice($cart), $cart['cart_num'], 2), $integralRate, 2), $cart['true_price']); + }else{ + // 商品独立设置 + if((int)$cart['product']['integral_deduction_type'] == 1) $productIntegralPrice = (float)$cart['product']['integral_deduction_money']; + else $productIntegralPrice = (float)min(bcmul(bcmul($this->cartByPrice($cart), $cart['cart_num'], 2), min(bcdiv($cart['product']['integral_rate'], 100, 4), 1), 2), $cart['true_price']); + } + // 判断:当前商品是否可以参与积分抵扣 - $isParticipation = $merchantCart['order']['true_price'] > 0 && $cart['product_type'] == 0 && $integralFlag && $integralRate > 0; + $isParticipation = $merchantCart['order']['true_price'] > 0 && $cart['product_type'] == 0 && $integralFlag && $productIntegralPrice > 0; if($isParticipation) $is_has_integral_use = 1;// 是否存在积分使用情况 只要存在一个则存在 // 只有普通商品可以抵扣 if ($isParticipation && ($integralInfo['mer_integral'] > 0 || $integralInfo['convert_integral'] > 0) && ($usePlatformIntegral || $useMerIntegral)) { - // 计算积分抵扣 - if ($integralRate > 0) { - // 当前商品可以抵扣的金额 - $productIntegralPrice = (float)min(bcmul(bcmul($this->cartByPrice($cart), $cart['cart_num'], 2), $integralRate, 2), $cart['true_price']); - // 抵扣需要的积分 - $productIntegral = (int)ceil(bcdiv($productIntegralPrice, $integralMoney, 3)); - if ($productIntegral > 0 && ($productIntegral <= $integralInfo['mer_integral'] || $productIntegral <= $integralInfo['convert_integral'])) { - // 判断:使用的积分类型 - if($useMerIntegral){ - // 使用商户积分抵扣 - $integralInfo['mer_integral'] = (float)bcsub($integralInfo['mer_integral'], $productIntegral, 2); - $integralInfo['use_integral_type'] = 'mer_integral'; - // 判断:积分不足 不使用积分抵扣 - if($integralInfo['mer_integral'] < 0) continue; - }else if($usePlatformIntegral) { - // 使用平台积分抵扣 - $integralInfo['convert_integral'] = bcsub($integralInfo['convert_integral'], $productIntegral, 2);// 减少转换后的积分 - $productIntegral = bcmul($productIntegral, $integralInfo['convert_rate'],2);// 刷新使用积分(使用平台积分,需要根据比例刷新平台积分减少数量) - $integralInfo['integral'] = bcsub($integralInfo['integral'], $productIntegral, 2);// 减少未转化的平台积分 - $integralInfo['use_integral_type'] = 'platform_integral'; - // 判断:积分不足 不使用积分抵扣 - if($integralInfo['convert_integral'] < 0) continue; - } - - - // 使用多少积分抵扣了多少金额 - $cart['integral'] = [ - 'use' => $productIntegral, - 'price' => $productIntegralPrice, - 'use_integral_type' => $integralInfo['use_integral_type'] - ]; - - // 抵扣后的处理 - $cart['true_price'] = bcsub($cart['true_price'], $cart['integral']['price'], 2); - $merchantCart['order']['true_price'] = bcsub($merchantCart['order']['true_price'], $cart['integral']['price'], 2); - - - if($integralInfo['use_integral_type'] == 'mer_integral') { - $use_mer_integral = bcadd($use_mer_integral, $productIntegral, 2);// 使用的商户积分 - $use_mer_integral_price = bcadd($use_mer_integral_price,$productIntegralPrice,2);// 使用商户积分抵扣的金额 - } - else { - $use_platform_integral = bcadd($use_platform_integral, $productIntegral, 2);;// 使用的平台积分 - $use_platform_integral_price = bcadd($use_platform_integral_price, $productIntegralPrice, 2);;// 使用平台积分抵扣的金额 - } - - - $total_integral_price = bcadd($total_integral_price, $cart['integral']['price'], 2); - $total_integral = bcadd($total_integral, $cart['integral']['use'], 2); - continue; + // 抵扣需要的积分 + $productIntegral = (int)ceil(bcdiv($productIntegralPrice, $integralMoney, 3)); + if ($productIntegral > 0 && ($productIntegral <= $integralInfo['mer_integral'] || $productIntegral <= $integralInfo['convert_integral'])) { + // 判断:使用的积分类型 + if($useMerIntegral){ + // 使用商户积分抵扣 + $integralInfo['mer_integral'] = (float)bcsub($integralInfo['mer_integral'], $productIntegral, 2); + $integralInfo['use_integral_type'] = 'mer_integral'; + // 判断:积分不足 不使用积分抵扣 + if($integralInfo['mer_integral'] < 0) continue; + }else if($usePlatformIntegral) { + // 使用平台积分抵扣 + $integralInfo['convert_integral'] = bcsub($integralInfo['convert_integral'], $productIntegral, 2);// 减少转换后的积分 + $productIntegral = bcmul($productIntegral, $integralInfo['convert_rate'],2);// 刷新使用积分(使用平台积分,需要根据比例刷新平台积分减少数量) + $integralInfo['integral'] = bcsub($integralInfo['integral'], $productIntegral, 2);// 减少未转化的平台积分 + $integralInfo['use_integral_type'] = 'platform_integral'; + // 判断:积分不足 不使用积分抵扣 + if($integralInfo['convert_integral'] < 0) continue; } + + + // 使用多少积分抵扣了多少金额 + $cart['integral'] = [ + 'use' => $productIntegral, + 'price' => $productIntegralPrice, + 'use_integral_type' => $integralInfo['use_integral_type'] + ]; + + // 抵扣后的处理 + $cart['true_price'] = bcsub($cart['true_price'], $cart['integral']['price'], 2); + $merchantCart['order']['true_price'] = bcsub($merchantCart['order']['true_price'], $cart['integral']['price'], 2); + + + if($integralInfo['use_integral_type'] == 'mer_integral') { + $use_mer_integral = bcadd($use_mer_integral, $productIntegral, 2);// 使用的商户积分 + $use_mer_integral_price = bcadd($use_mer_integral_price,$productIntegralPrice,2);// 使用商户积分抵扣的金额 + } + else { + $use_platform_integral = bcadd($use_platform_integral, $productIntegral, 2);;// 使用的平台积分 + $use_platform_integral_price = bcadd($use_platform_integral_price, $productIntegralPrice, 2);;// 使用平台积分抵扣的金额 + } + + + $total_integral_price = bcadd($total_integral_price, $cart['integral']['price'], 2); + $total_integral = bcadd($total_integral, $cart['integral']['use'], 2); + continue; } } $cart['integral'] = null; diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index a2fe929..e5fdcdf 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -72,6 +72,9 @@ class ProductRepository extends BaseRepository ['integral_give_type',0], 'integral_give_rate', 'integral_give_money', + // 积分抵扣 + ['integral_deduction_type',0], + ['integral_deduction_money',0], ]; protected $admin_filed = 'Product.product_id,Product.mer_id,brand_id,spec_type,unit_name,mer_status,rate,reply_count,store_info,cate_id,Product.image,slider_image,Product.store_name,Product.keyword,Product.sort,U.rank,Product.is_show,Product.sales,Product.price,extension_type,refusal,cost,Product.ot_price,stock,is_gift_bag,Product.care_count,Product.status,is_used,Product.create_time,Product.product_type,old_product_id,star,ficti,integral_total,integral_price_total,sys_labels,param_temp_id,mer_svip_status,svip_price,svip_price_type'; protected $filed = 'Product.product_id,Product.mer_id,brand_id,unit_name,spec_type,mer_status,rate,reply_count,store_info,cate_id,Product.image,slider_image,Product.store_name,Product.keyword,Product.sort,Product.is_show,Product.sales,Product.price,extension_type,refusal,cost,Product.ot_price,stock,is_gift_bag,Product.care_count,Product.status,is_used,Product.create_time,Product.product_type,old_product_id,integral_total,integral_price_total,mer_labels,Product.is_good,Product.is_del,type,param_temp_id,mer_svip_status,svip_price,svip_price_type'; @@ -480,6 +483,9 @@ class ProductRepository extends BaseRepository 'integral_give_type' => $data['integral_give_type'] ?? 0, 'integral_give_rate' => $data['integral_give_rate'] ?? 0, 'integral_give_money' => $data['integral_give_money'] ?? 0, + // 积分抵扣 + 'integral_deduction_type' => $data['integral_deduction_type'] ?? 0, + 'integral_deduction_money' => $data['integral_deduction_money'] ?? 0, ]; if (isset($data['extend'])) $result['extend'] = $data['extend'] ? json_encode($data['extend'], JSON_UNESCAPED_UNICODE) : '';