经常有客户反应,我这件商品利润大 想让用户多抵扣一点积分,这件商品没有利润不想让用户用积分抵扣,对于这种需求,最简单粗暴的方法就是把最高可抵扣积分数量放在商品里面来设置。
假设A商品利润空间大,我设置最高可抵扣50积分,B商品利润空间少,我设置可抵扣10积分或设置0积分不给抵扣
二开地方
代码:
/**
* 使用积分
* @param $useIntegral
* @param $userInfo
* @param $payPrice
* @param $other
* @return array
*/
public function useIntegral(bool $useIntegral, $userInfo, string $payPrice, array $other, array $cartInfo = [])
{
/** @var UserBillServices $userBillServices */
$userBillServices = app()->make(UserBillServices::class);
// 可用积分
$usable = bcsub((string)$userInfo['integral'], (string)$userBillServices->getBillSum(['uid' => $userInfo['uid'], 'is_frozen' => 1]), 0);
$SurplusIntegral = $usable;
if ($useIntegral && $userInfo['integral'] > 0 && $other['integralRatio'] > 0) {
// 获取商品最高可抵扣积分数
$integralMaxNum = 0;
foreach ($cartInfo as $val) {
$integralMaxNum = bcadd($integralMaxNum, bcmul($val['productInfo']['max_integral'], $val['cart_num']));
}
if ($integralMaxNum > 0 && $userInfo['integral'] > $integralMaxNum) {
$integral = $integralMaxNum;
} else {
$integral = $userInfo['integral'];
}
if ($integralMaxNum <= 0) {
// 给默认后台设置的抵扣积分
$integral = sys_config('integral_max_num', 200);
}
$deductionPrice = (float)bcmul((string)$integral, (string)$other['integralRatio'], 2);
if ($deductionPrice < $payPrice) {
$payPrice = bcsub((string)$payPrice, (string)$deductionPrice, 2);
$usedIntegral = $integral;
} else {
$deductionPrice = $payPrice;
$usedIntegral = (int)ceil(bcdiv((string)$payPrice, (string)$other['integralRatio'], 2));
$payPrice = 0;
}
$deductionPrice = $deductionPrice > 0 ? $deductionPrice : 0;
$usedIntegral = $usedIntegral > 0 ? $usedIntegral : 0;
$SurplusIntegral = (int)bcsub((string)$usable, $usedIntegral, 0);
} else {
$deductionPrice = 0;
$usedIntegral = 0;
}
if ($payPrice <= 0) $payPrice = 0;
return [$payPrice, $deductionPrice, $usedIntegral, $SurplusIntegral];
}
云管家网络科技有限公司专注CRMEB商城系统二次开发、分销商城系统开发、城市代理开发等多种应用场景定制开发。