修复:购买商品数量不为一时,商品使用积分计算错误(始终只抵扣了一个数量的商品)
优化:购买积分商品时豆豆积分的相关处理
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\dao\store\order\StoreOrderDao;
|
||||||
use app\common\model\store\platformCommission\LegumesLog;
|
use app\common\model\store\platformCommission\LegumesLog;
|
||||||
use app\common\repositories\store\coupon\StoreCouponUserRepository;
|
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\ProductAssistSkuRepository;
|
||||||
use app\common\repositories\store\product\ProductAttrValueRepository;
|
use app\common\repositories\store\product\ProductAttrValueRepository;
|
||||||
use app\common\repositories\store\product\ProductGroupSkuRepository;
|
use app\common\repositories\store\product\ProductGroupSkuRepository;
|
||||||
|
|
@ -29,12 +30,16 @@ class PointsOrderCreateRepository
|
||||||
$address = $this->validateAddress($user,$addressId);
|
$address = $this->validateAddress($user,$addressId);
|
||||||
[$merchantCartList,$order_model,$order_extend,$order_type] = $this->validateCartList($cartId,$user,$address);
|
[$merchantCartList,$order_model,$order_extend,$order_type] = $this->validateCartList($cartId,$user,$address);
|
||||||
$successData = $this->validateMerchantList($user,$merchantCartList);
|
$successData = $this->validateMerchantList($user,$merchantCartList);
|
||||||
|
// 获取用户可用豆豆积分
|
||||||
|
$holdLegumesIntegral = app()->make(LegumesLogRepository::class)->getHoldLegumesIntegral((int)$user->uid);
|
||||||
|
|
||||||
|
|
||||||
return $successData + [
|
return $successData + [
|
||||||
'key' => $key,
|
'key' => $key,
|
||||||
'order_type' => $order_type,
|
'order_type' => $order_type,
|
||||||
'order_model' => $order_model,
|
'order_model' => $order_model,
|
||||||
'order_extend' => $order_extend,
|
'order_extend' => $order_extend,
|
||||||
'true_integral' => (int)$user->integral,
|
'true_integral' => $holdLegumesIntegral,//(int)$user->integral,// TODO:2024-1-2 可用积分由用户普通积分修改为豆豆积分
|
||||||
'address' => $address,
|
'address' => $address,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
@ -152,10 +157,8 @@ class PointsOrderCreateRepository
|
||||||
// 判断:当前商户积分是否充足
|
// 判断:当前商户积分是否充足
|
||||||
// $holdMerIntegral = app()->make(IntegralRepository::class)->getMerIntegral((int)$user->uid,(int)$merchantCart['mer_id']);// 用户持有的该商户积分总数
|
// $holdMerIntegral = app()->make(IntegralRepository::class)->getMerIntegral((int)$user->uid,(int)$merchantCart['mer_id']);// 用户持有的该商户积分总数
|
||||||
// if($holdMerIntegral < $total_integral) throw new ValidateException("积分不足,剩余{$holdMerIntegral}商户积分");
|
// if($holdMerIntegral < $total_integral) throw new ValidateException("积分不足,剩余{$holdMerIntegral}商户积分");
|
||||||
$legumesModel = (new LegumesLog())->where('uid', (int)$user->uid)->where('status', 1);
|
// 获取用户可用豆豆积分
|
||||||
$totalGetIntegral = $legumesModel->sum('get_integral');// 总获取积分
|
$hold_legumes_integral = app()->make(LegumesLogRepository::class)->getHoldLegumesIntegral((int)$user->uid);
|
||||||
$totalUseIntegral = $legumesModel->sum('use_integral');// 总已使用积分
|
|
||||||
$hold_legumes_integral = (float)sprintf("%.2f",$totalGetIntegral - $totalUseIntegral);// 持有可使用积分
|
|
||||||
if($hold_legumes_integral < $total_integral) throw new ValidateException("积分不足,剩余{$hold_legumes_integral}可用积分");
|
if($hold_legumes_integral < $total_integral) throw new ValidateException("积分不足,剩余{$hold_legumes_integral}可用积分");
|
||||||
|
|
||||||
unset($cart);
|
unset($cart);
|
||||||
|
|
@ -381,28 +384,29 @@ class PointsOrderCreateRepository
|
||||||
'product_type' => $cart['product_type']
|
'product_type' => $cart['product_type']
|
||||||
];
|
];
|
||||||
$orderProduct[] = [
|
$orderProduct[] = [
|
||||||
'order_id' => $_order->order_id,
|
'order_id' => $_order->order_id,
|
||||||
'cart_id' => $cart['cart_id'],
|
'cart_id' => $cart['cart_id'],
|
||||||
'uid' => $user->uid,
|
'uid' => $user->uid,
|
||||||
'product_id' => $cart['product_id'],
|
'product_id' => $cart['product_id'],
|
||||||
'activity_id' => $cart['source'] >= 2 ? $cart['source_id'] : $cart['product_id'],
|
'activity_id' => $cart['source'] >= 2 ? $cart['source_id'] : $cart['product_id'],
|
||||||
'total_price' => $cart['total_price'],
|
'total_price' => $cart['total_price'],
|
||||||
'product_price' => $productPrice,
|
'product_price' => $productPrice,
|
||||||
'extension_one' => 0,
|
'extension_one' => 0,
|
||||||
'extension_two' => 0,
|
'extension_two' => 0,
|
||||||
'postage_price' => 0,
|
'postage_price' => 0,
|
||||||
'svip_discount' => 0,
|
'svip_discount' => 0,
|
||||||
'cost' => $cart['cost'],
|
'cost' => $cart['cost'],
|
||||||
'coupon_price' => 0,
|
'coupon_price' => 0,
|
||||||
'platform_coupon_price' => 0,
|
'platform_coupon_price' => 0,
|
||||||
'product_sku' => $cart['productAttr']['unique'],
|
'product_sku' => $cart['productAttr']['unique'],
|
||||||
'product_num' => $cart['cart_num'],
|
'product_num' => $cart['cart_num'],
|
||||||
'refund_num' => $cart['cart_num'],
|
'refund_num' => $cart['cart_num'],
|
||||||
'integral_price' => 0,
|
'integral_price' => 0,
|
||||||
'integral' => $cart['integral'] ,
|
'integral' => $cart['integral'],
|
||||||
'integral_total' => $cart['integral'] ,
|
'integral_total' => $cart['integral'],
|
||||||
'product_type' => $cart['product_type'],
|
'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']);
|
$userMerchantRepository->getInfo($user->uid, $order['mer_id']);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
namespace app\common\repositories\store\order;
|
namespace app\common\repositories\store\order;
|
||||||
|
|
||||||
use app\common\model\store\platformCommission\LegumesLog;
|
use app\common\model\store\platformCommission\LegumesLog;
|
||||||
|
use app\common\repositories\store\platformCommission\LegumesLogRepository;
|
||||||
use app\common\repositories\system\config\ConfigValueRepository;
|
use app\common\repositories\system\config\ConfigValueRepository;
|
||||||
use app\jobs\store\platformCommission\UseLegumesIntegralJob;
|
use app\jobs\store\platformCommission\UseLegumesIntegralJob;
|
||||||
use crmeb\jobs\SendSmsJob;
|
use crmeb\jobs\SendSmsJob;
|
||||||
|
|
@ -759,10 +760,8 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||||
// 豆豆积分相关处理
|
// 豆豆积分相关处理
|
||||||
$order_use_legumes_integral = 0;// 使用的豆豆积分(总)
|
$order_use_legumes_integral = 0;// 使用的豆豆积分(总)
|
||||||
$order_use_legumes_integral_price = 0;// 使用的豆豆积分抵扣的金额
|
$order_use_legumes_integral_price = 0;// 使用的豆豆积分抵扣的金额
|
||||||
$legumesModel = (new LegumesLog())->where('uid', (int)$uid)->where('status', 1);
|
// 获取用户可用豆豆积分
|
||||||
$totalGetIntegral = $legumesModel->sum('get_integral');// 总获取积分
|
$hold_legumes_integral = app()->make(LegumesLogRepository::class)->getHoldLegumesIntegral((int)$uid);
|
||||||
$totalUseIntegral = $legumesModel->sum('use_integral');// 总已使用积分
|
|
||||||
$hold_legumes_integral = (float)sprintf("%.2f",$totalGetIntegral - $totalUseIntegral);// 持有可使用积分
|
|
||||||
|
|
||||||
foreach ($merchantCartList as &$merchantCart) {
|
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'];
|
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']);
|
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;
|
$isParticipation = $merchantCart['order']['true_price'] > 0 && $cart['product_type'] == 0 && $integralFlag && $productIntegralPrice > 0;
|
||||||
if($isParticipation) $is_has_integral_use = 1;// 是否存在积分使用情况 只要存在一个则存在
|
if($isParticipation) $is_has_integral_use = 1;// 是否存在积分使用情况 只要存在一个则存在
|
||||||
|
|
@ -1516,29 +1516,30 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
$orderProduct[] = [
|
$orderProduct[] = [
|
||||||
'order_id' => $_order->order_id,
|
'order_id' => $_order->order_id,
|
||||||
'cart_id' => $cart['cart_id'],
|
'cart_id' => $cart['cart_id'],
|
||||||
'uid' => $uid,
|
'uid' => $uid,
|
||||||
'product_id' => $cart['product_id'],
|
'product_id' => $cart['product_id'],
|
||||||
'activity_id' => $cart['source'] >= 2 ? $cart['source_id'] : $cart['product_id'],
|
'activity_id' => $cart['source'] >= 2 ? $cart['source_id'] : $cart['product_id'],
|
||||||
'total_price' => $cart['total_price'],
|
'total_price' => $cart['total_price'],
|
||||||
'product_price' => $productPrice,
|
'product_price' => $productPrice,
|
||||||
'extension_one' => $extension_one,
|
'extension_one' => $extension_one,
|
||||||
'extension_two' => $extension_two,
|
'extension_two' => $extension_two,
|
||||||
'postage_price' => $cart['postage_price'],
|
'postage_price' => $cart['postage_price'],
|
||||||
'svip_discount' => $cart['svip_discount'],
|
'svip_discount' => $cart['svip_discount'],
|
||||||
'cost' => $cart['cost'],
|
'cost' => $cart['cost'],
|
||||||
'coupon_price' => $cart['coupon_price'],
|
'coupon_price' => $cart['coupon_price'],
|
||||||
'platform_coupon_price' => $cart['platform_coupon_price'],
|
'platform_coupon_price' => $cart['platform_coupon_price'],
|
||||||
'product_sku' => $cart['productAttr']['unique'],
|
'product_sku' => $cart['productAttr']['unique'],
|
||||||
'product_num' => $cart['cart_num'],
|
'product_num' => $cart['cart_num'],
|
||||||
'refund_num' => $cart['cart_num'],
|
'refund_num' => $cart['cart_num'],
|
||||||
'integral_price' => $cart['integral']['price'] ?? 0,
|
'integral_price' => $cart['integral']['price'] ?? 0,
|
||||||
'integral' => $cart['integral'] ? bcdiv($cart['integral']['use'], $cart['cart_num'], 0) : 0,
|
'integral' => $cart['integral'] ? bcdiv($cart['integral']['use'],$cart['cart_num'],0) : 0,
|
||||||
'integral_total' => $cart['integral'] ? $cart['integral']['use'] : 0,
|
'integral_total' => $cart['integral'] ? $cart['integral']['use'] : 0,
|
||||||
'product_type' => $cart['product_type'],
|
'product_type' => $cart['product_type'],
|
||||||
'cart_info' => json_encode($order_cart),
|
'cart_info' => json_encode($order_cart),
|
||||||
'refund_switch' => $cart['refund_switch'],
|
'refund_switch' => $cart['refund_switch'],
|
||||||
|
'use_legumes_integral' => $cart['integral'] ? $cart['integral']['use'] : 0
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,18 @@ class LegumesLogRepository extends BaseRepository{
|
||||||
|
|
||||||
return $list;
|
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']);
|
$userList = app()->make(WeightValueRepository::class)->getUserHoldList($data['uid']);
|
||||||
$orderIds = StoreOrder::where('group_order_id',$data['group_order_id'])->column('order_id');// 获取订单id
|
$orderIds = StoreOrder::where('group_order_id',$data['group_order_id'])->column('order_id');// 获取订单id
|
||||||
$productList = StoreOrderProduct::whereIn('order_id',$orderIds)
|
$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()
|
->select()
|
||||||
->toArray();// 获取当前订单中所有商品
|
->toArray();// 获取当前订单中所有商品
|
||||||
$updateData = [];
|
$updateData = [];
|
||||||
|
|
|
||||||
|
|
@ -47,15 +47,11 @@ class UseLegumesIntegralJob implements JobInterface{
|
||||||
// 修改成功信息
|
// 修改成功信息
|
||||||
if($updateData){
|
if($updateData){
|
||||||
LegumesLog::batchUpdate(array_values($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'].'积分';
|
if($orderInfo['order_type'] == 20) $mark = '兑换积分商品消耗'.$orderInfo['use_legumes_integral'].'积分';
|
||||||
else $mark = '购买商品使用'.$orderInfo['use_legumes_integral'].'积分抵扣'.floatval($orderInfo['use_legumes_integral_price']).'元';
|
else $mark = '购买商品使用'.$orderInfo['use_legumes_integral'].'积分抵扣'.floatval($orderInfo['use_legumes_integral_price']).'元';
|
||||||
|
|
||||||
|
|
||||||
$bills[] = [
|
$bills[] = [
|
||||||
'uid' => $orderInfo['uid'],
|
'uid' => $orderInfo['uid'],
|
||||||
'link_id' => $orderInfo['order_id'],
|
'link_id' => $orderInfo['order_id'],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue