修复:购买商品数量不为一时,商品使用积分计算错误(始终只抵扣了一个数量的商品)
优化:购买积分商品时豆豆积分的相关处理
This commit is contained in:
parent
f84a99c958
commit
a5b1657c67
|
|
@ -5,6 +5,7 @@ namespace app\common\repositories\store\order;
|
|||
use app\common\dao\store\order\StoreOrderDao;
|
||||
use app\common\model\store\platformCommission\LegumesLog;
|
||||
use app\common\repositories\store\coupon\StoreCouponUserRepository;
|
||||
use app\common\repositories\store\platformCommission\LegumesLogRepository;
|
||||
use app\common\repositories\store\product\ProductAssistSkuRepository;
|
||||
use app\common\repositories\store\product\ProductAttrValueRepository;
|
||||
use app\common\repositories\store\product\ProductGroupSkuRepository;
|
||||
|
|
@ -29,12 +30,16 @@ class PointsOrderCreateRepository
|
|||
$address = $this->validateAddress($user,$addressId);
|
||||
[$merchantCartList,$order_model,$order_extend,$order_type] = $this->validateCartList($cartId,$user,$address);
|
||||
$successData = $this->validateMerchantList($user,$merchantCartList);
|
||||
// 获取用户可用豆豆积分
|
||||
$holdLegumesIntegral = app()->make(LegumesLogRepository::class)->getHoldLegumesIntegral((int)$user->uid);
|
||||
|
||||
|
||||
return $successData + [
|
||||
'key' => $key,
|
||||
'order_type' => $order_type,
|
||||
'order_model' => $order_model,
|
||||
'order_extend' => $order_extend,
|
||||
'true_integral' => (int)$user->integral,
|
||||
'true_integral' => $holdLegumesIntegral,//(int)$user->integral,// TODO:2024-1-2 可用积分由用户普通积分修改为豆豆积分
|
||||
'address' => $address,
|
||||
];
|
||||
}
|
||||
|
|
@ -152,10 +157,8 @@ class PointsOrderCreateRepository
|
|||
// 判断:当前商户积分是否充足
|
||||
// $holdMerIntegral = app()->make(IntegralRepository::class)->getMerIntegral((int)$user->uid,(int)$merchantCart['mer_id']);// 用户持有的该商户积分总数
|
||||
// if($holdMerIntegral < $total_integral) throw new ValidateException("积分不足,剩余{$holdMerIntegral}商户积分");
|
||||
$legumesModel = (new LegumesLog())->where('uid', (int)$user->uid)->where('status', 1);
|
||||
$totalGetIntegral = $legumesModel->sum('get_integral');// 总获取积分
|
||||
$totalUseIntegral = $legumesModel->sum('use_integral');// 总已使用积分
|
||||
$hold_legumes_integral = (float)sprintf("%.2f",$totalGetIntegral - $totalUseIntegral);// 持有可使用积分
|
||||
// 获取用户可用豆豆积分
|
||||
$hold_legumes_integral = app()->make(LegumesLogRepository::class)->getHoldLegumesIntegral((int)$user->uid);
|
||||
if($hold_legumes_integral < $total_integral) throw new ValidateException("积分不足,剩余{$hold_legumes_integral}可用积分");
|
||||
|
||||
unset($cart);
|
||||
|
|
@ -402,7 +405,8 @@ class PointsOrderCreateRepository
|
|||
'integral' => $cart['integral'],
|
||||
'integral_total' => $cart['integral'],
|
||||
'product_type' => $cart['product_type'],
|
||||
'cart_info' => json_encode($order_cart)
|
||||
'cart_info' => json_encode($order_cart),
|
||||
'use_legumes_integral' => $cart['integral'],
|
||||
];
|
||||
}
|
||||
$userMerchantRepository->getInfo($user->uid, $order['mer_id']);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace app\common\repositories\store\order;
|
||||
|
||||
use app\common\model\store\platformCommission\LegumesLog;
|
||||
use app\common\repositories\store\platformCommission\LegumesLogRepository;
|
||||
use app\common\repositories\system\config\ConfigValueRepository;
|
||||
use app\jobs\store\platformCommission\UseLegumesIntegralJob;
|
||||
use crmeb\jobs\SendSmsJob;
|
||||
|
|
@ -759,10 +760,8 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
|||
// 豆豆积分相关处理
|
||||
$order_use_legumes_integral = 0;// 使用的豆豆积分(总)
|
||||
$order_use_legumes_integral_price = 0;// 使用的豆豆积分抵扣的金额
|
||||
$legumesModel = (new LegumesLog())->where('uid', (int)$uid)->where('status', 1);
|
||||
$totalGetIntegral = $legumesModel->sum('get_integral');// 总获取积分
|
||||
$totalUseIntegral = $legumesModel->sum('use_integral');// 总已使用积分
|
||||
$hold_legumes_integral = (float)sprintf("%.2f",$totalGetIntegral - $totalUseIntegral);// 持有可使用积分
|
||||
// 获取用户可用豆豆积分
|
||||
$hold_legumes_integral = app()->make(LegumesLogRepository::class)->getHoldLegumesIntegral((int)$uid);
|
||||
|
||||
foreach ($merchantCartList as &$merchantCart) {
|
||||
// 获取用户在当前店铺的积分 || 平台积分
|
||||
|
|
@ -819,7 +818,8 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
|||
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']);
|
||||
}
|
||||
|
||||
// 实际抵扣金额 * 购买数量
|
||||
$productIntegralPrice = bcmul($productIntegralPrice, $cart['cart_num'], 2);
|
||||
// 判断:当前商品是否可以参与积分抵扣
|
||||
$isParticipation = $merchantCart['order']['true_price'] > 0 && $cart['product_type'] == 0 && $integralFlag && $productIntegralPrice > 0;
|
||||
if($isParticipation) $is_has_integral_use = 1;// 是否存在积分使用情况 只要存在一个则存在
|
||||
|
|
@ -1539,6 +1539,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
|||
'product_type' => $cart['product_type'],
|
||||
'cart_info' => json_encode($order_cart),
|
||||
'refund_switch' => $cart['refund_switch'],
|
||||
'use_legumes_integral' => $cart['integral'] ? $cart['integral']['use'] : 0
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -79,6 +79,18 @@ class LegumesLogRepository extends BaseRepository{
|
|||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Common: 获取用户可用积分
|
||||
* Author: wu-hui
|
||||
* Time: 2024/01/02 9:57
|
||||
* @param $uid
|
||||
* @return float
|
||||
*/
|
||||
public function getHoldLegumesIntegral($uid):float{
|
||||
$legumesModel = $this->dao->getSearch([])->where('uid', (int)$uid)->where('status', 1);
|
||||
$totalGetIntegral = $legumesModel->sum('get_integral');// 总有效积分
|
||||
$totalUseIntegral = $legumesModel->sum('use_integral');// 总已使用积分
|
||||
return (float)sprintf("%.2f",$totalGetIntegral - $totalUseIntegral);// 持有可使用积分
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class GiveWeightValueJob implements JobInterface{
|
|||
$userList = app()->make(WeightValueRepository::class)->getUserHoldList($data['uid']);
|
||||
$orderIds = StoreOrder::where('group_order_id',$data['group_order_id'])->column('order_id');// 获取订单id
|
||||
$productList = StoreOrderProduct::whereIn('order_id',$orderIds)
|
||||
->field('order_product_id,order_id,product_id,(product_price + integral + integral_price) as product_price')
|
||||
->field('order_product_id,order_id,product_id,(product_price + use_legumes_integral) as product_price')
|
||||
->select()
|
||||
->toArray();// 获取当前订单中所有商品
|
||||
$updateData = [];
|
||||
|
|
|
|||
|
|
@ -47,15 +47,11 @@ class UseLegumesIntegralJob implements JobInterface{
|
|||
// 修改成功信息
|
||||
if($updateData){
|
||||
LegumesLog::batchUpdate(array_values($updateData));
|
||||
// 获取用户可用豆豆积分
|
||||
$hold_legumes_integral = app()->make(LegumesLogRepository::class)->getHoldLegumesIntegral((int)$orderInfo['uid']);
|
||||
// 添加用户账单信息变更记录
|
||||
$legumesModel = (new LegumesLog())->where('uid', (int)$orderInfo['uid'])->where('status', 1);
|
||||
$totalGetIntegral = $legumesModel->sum('get_integral');// 总获取积分
|
||||
$totalUseIntegral = $legumesModel->sum('use_integral');// 总已使用积分
|
||||
$hold_legumes_integral = (float)sprintf("%.2f",$totalGetIntegral - $totalUseIntegral);// 持有可使用积分
|
||||
if($orderInfo['order_type'] == 20) $mark = '兑换积分商品消耗'.$orderInfo['use_legumes_integral'].'积分';
|
||||
else $mark = '购买商品使用'.$orderInfo['use_legumes_integral'].'积分抵扣'.floatval($orderInfo['use_legumes_integral_price']).'元';
|
||||
|
||||
|
||||
$bills[] = [
|
||||
'uid' => $orderInfo['uid'],
|
||||
'link_id' => $orderInfo['order_id'],
|
||||
|
|
|
|||
Loading…
Reference in New Issue