添加:酒道馆商品兑换下单流程
This commit is contained in:
parent
7bbf063c8c
commit
f2700ff5a0
|
|
@ -68,6 +68,7 @@ class StoreCartDao extends BaseDao
|
|||
public function getAll(int $uid)
|
||||
{
|
||||
$query = ($this->getModel())::where(['uid' => $uid, 'is_del' => 0, 'is_new' => 0, 'is_pay' => 0])
|
||||
->where('product_type','<>', 36)
|
||||
->with([
|
||||
'product' => function ($query) {
|
||||
$query->field('product_id,image,store_name,is_show,status,is_del,unit_name,price,mer_status,is_used,product_type,once_max_count,once_min_count,pay_limit,mer_svip_status,svip_price_type');
|
||||
|
|
@ -174,7 +175,9 @@ class StoreCartDao extends BaseDao
|
|||
*/
|
||||
public function getCartCount(int $uid)
|
||||
{
|
||||
$data = ($this->getModel()::getDB())->where(['uid' => $uid, 'is_del' => 0, 'is_new' => 0, 'is_pay' => 0])->field('SUM(cart_num) as count')->select();
|
||||
$data = ($this->getModel()::getDB())->where(['uid' => $uid, 'is_del' => 0, 'is_new' => 0, 'is_pay' => 0])
|
||||
->where('product_type','<>', 36)
|
||||
->field('SUM(cart_num) as count')->select();
|
||||
$data[0]['count'] = $data[0]['count'] ? $data[0]['count'] : 0;
|
||||
return $data;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
namespace app\common\repositories\store\order;
|
||||
|
||||
use app\common\model\user\ExchangeIntegralRecord;
|
||||
use app\common\model\user\ExchangeQuotaRecord;
|
||||
use app\common\model\user\User;
|
||||
use app\common\repositories\system\config\ConfigValueRepository;
|
||||
use crmeb\jobs\SendSmsJob;
|
||||
use crmeb\services\SwooleTaskService;
|
||||
|
|
@ -20,7 +23,8 @@ use app\common\repositories\store\product\{
|
|||
ProductRepository,
|
||||
StoreDiscountRepository
|
||||
};
|
||||
use app\common\repositories\user\{IntegralRepository,
|
||||
use app\common\repositories\user\{ExchangeQuotaRepository,
|
||||
IntegralRepository,
|
||||
MemberinterestsRepository,
|
||||
UserAddressRepository,
|
||||
UserBillRepository,
|
||||
|
|
@ -37,7 +41,9 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
|
|||
public function v2CartIdByOrderInfo($user,array $cartId,array $takes = NULL,array $useCoupon = NULL,bool $useIntegral = FALSE,int $addressId = NULL,array $withGoods = [],$createOrder = FALSE){
|
||||
$uid = $user->uid;
|
||||
$userIntegral = $user->integral;
|
||||
$exchangeIntegral = $user->exchange_integral ?? 0;// 持有可用酒水卡积分
|
||||
$isWithGoods = $withGoods['is_with_goods'] ?? 0;// 0=用户购物,1=酒道馆进货
|
||||
$diffRate = 30;// 酒道馆商品 补差价比例 这里暂时默认固定为30%
|
||||
$key = md5(json_encode(compact('cartId','takes','useCoupon','useIntegral','addressId'))).$uid;
|
||||
//去掉过期的优惠券信息
|
||||
app()->make(StoreCouponUserRepository::class)->failCoupon();
|
||||
|
|
@ -89,7 +95,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
|
|||
}
|
||||
}
|
||||
if($cart['product_type'] > 0) $order_type = $cart['product_type'];
|
||||
if($cart['product_type'] != 35){
|
||||
if(!in_array($cart['product_type'],[35, 36])){
|
||||
if($cart['product_type'] > 0 && (($cart['product_type'] != 10 && count($merchantCart['list']) != 1) || count($merchantCartList) != 1)){
|
||||
throw new ValidateException('活动商品必须单独购买');
|
||||
}
|
||||
|
|
@ -716,6 +722,13 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
|
|||
$order_total_integral_price = 0;
|
||||
$order_total_give_integral = 0;
|
||||
$allow_no_address = TRUE;
|
||||
|
||||
$orderTotalWineIntegral = 0;// 订单总使用的酒水卡积分
|
||||
$orderTotalWineIntegralPrice = 0;// 订单总使用酒水卡积分抵扣的金额
|
||||
$orderTotalWineDiffMoney = 0;// 订单总差价
|
||||
$orderTotalWineDiffMoneyPrice = 0;// 订单总补差价支付金额
|
||||
|
||||
|
||||
foreach($merchantCartList as &$merchantCart){
|
||||
$merchantCart['take'] = [
|
||||
'mer_integral_rate' => 0,
|
||||
|
|
@ -732,6 +745,13 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
|
|||
$total_integral_price = 0;
|
||||
$merIntegralFlag = $merIntegralFlag || ((bool)$merIntegralConfig['mer_integral_status']);
|
||||
$integralFlag = $useIntegral && $sysIntegralConfig['integral_status'] && $sysIntegralConfig['integral_money'] > 0 && $merIntegralConfig['mer_integral_status'];
|
||||
|
||||
|
||||
$orderWineIntegral = 0;// 当前订单使用的酒水卡积分
|
||||
$orderWineIntegralPrice = 0;// 当前订单使用就是快积分抵扣的金额
|
||||
$orderWineDiffMoney = 0;// 当前订单差价
|
||||
$orderWineDiffMoneyPrice = 0;// 当前订单补差价支付金额
|
||||
|
||||
//计算积分抵扣
|
||||
foreach($merchantCart['list'] as &$cart){
|
||||
//只有普通商品可以抵扣
|
||||
|
|
@ -773,10 +793,50 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
|
|||
}
|
||||
}
|
||||
$cart['integral'] = NULL;
|
||||
// 兑换酒道馆商品时 酒水卡积分抵扣处理
|
||||
if($cart['product_type'] == 36){
|
||||
// 当前商品消耗积分 如果持有酒水卡积分大于等于支付金额,使用支付金额;小于支付金额,使用酒水卡积分
|
||||
$deductionAmount = (float)$exchangeIntegral >= (float)$cart['true_price'] ? (float)$cart['true_price'] : (float)$exchangeIntegral;// 实际抵扣金额
|
||||
$exchangeIntegral = bcsub((float)$exchangeIntegral,(float)$deductionAmount,2);// 剩余酒水卡积分
|
||||
$cart['exchange_integral'] = $deductionAmount;
|
||||
$cart['exchange_integral_price'] = $deductionAmount;
|
||||
// 订单总支付金额 先减去酒水卡积分抵扣金额
|
||||
$merchantCart['order']['true_price'] = bcsub($merchantCart['order']['true_price'],$deductionAmount,2);
|
||||
// 当前商品剩余应支付金额 进行补差价计算
|
||||
$cartTruePrice = bcsub($cart['true_price'],$deductionAmount,2);
|
||||
if($cartTruePrice > 0){
|
||||
// 未完全抵扣 需要补差价
|
||||
$diffMoney = sprintf("%.2f", $cartTruePrice * $diffRate / 100);// 实际支付差价
|
||||
|
||||
$orderWineDiffMoney = bcadd($orderWineDiffMoney,$cartTruePrice,2);// 剩余差价
|
||||
$orderWineDiffMoneyPrice = bcadd($orderWineDiffMoneyPrice,$diffMoney,2);// 实际支付差价金额
|
||||
$cart['wine_diff_money'] = $cartTruePrice;
|
||||
$cart['wine_diff_money_price'] = $diffMoney;
|
||||
|
||||
// 修改商品支付金额
|
||||
$merchantCart['order']['true_price'] = bcsub($merchantCart['order']['true_price'], bcsub($cartTruePrice,$diffMoney,2),2);
|
||||
$cartTruePrice = $diffMoney;
|
||||
}
|
||||
|
||||
$cart['true_price'] = $cartTruePrice;
|
||||
// 当前订单使用的酒水卡积分和抵扣金额
|
||||
$orderWineIntegral = bcadd($orderWineIntegral,$deductionAmount,2);
|
||||
$orderWineIntegralPrice = bcadd($orderWineIntegralPrice,$deductionAmount,2);
|
||||
}
|
||||
}
|
||||
unset($cart);
|
||||
$order_total_integral = bcadd($order_total_integral,$total_integral,0);
|
||||
$order_total_integral_price = bcadd($order_total_integral_price,$total_integral_price,2);
|
||||
|
||||
|
||||
// 订单总使用的酒水卡积分 & 总抵扣的金额
|
||||
$orderTotalWineIntegral = bcadd($orderTotalWineIntegral,$orderWineIntegral,2);
|
||||
$orderTotalWineIntegralPrice = bcadd($orderTotalWineIntegralPrice,$orderWineIntegralPrice,2);
|
||||
|
||||
$orderTotalWineDiffMoney = bcadd($orderTotalWineDiffMoney,$orderWineDiffMoney,2);
|
||||
$orderTotalWineDiffMoneyPrice = bcadd($orderTotalWineDiffMoneyPrice,$orderWineDiffMoneyPrice,2);
|
||||
|
||||
|
||||
$_pay_price = $merchantCart['order']['true_price'];
|
||||
$valid_total_price = $merchantCart['order']['valid_total_price'];
|
||||
$total_price = $merchantCart['order']['total_price'];
|
||||
|
|
@ -816,6 +876,12 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
|
|||
$merchantCart['order']['total_give_integral'] = $total_give_integral;
|
||||
$merchantCart['order']['total_integral_price'] = $total_integral_price;
|
||||
$merchantCart['order']['total_integral'] = $total_integral;
|
||||
// 酒水卡积分抵扣情况
|
||||
$merchantCart['order']['exchange_integral_price'] = $orderWineIntegralPrice;
|
||||
$merchantCart['order']['exchange_integral'] = $orderWineIntegral;
|
||||
$merchantCart['order']['wine_diff_money'] = $orderWineDiffMoney;
|
||||
$merchantCart['order']['wine_diff_money_price'] = $orderWineDiffMoneyPrice;
|
||||
|
||||
$merchantCart['order']['org_price'] = $org_price;
|
||||
$merchantCart['order']['pay_price'] = $pay_price;
|
||||
$merchantCart['order']['coupon_price'] = $coupon_price;
|
||||
|
|
@ -839,11 +905,46 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
|
|||
$order = $merchantCartList;
|
||||
$total_price = $order_total_price;
|
||||
$openIntegral = $merIntegralFlag && !$order_type && $sysIntegralConfig['integral_status'] && $sysIntegralConfig['integral_money'] > 0;
|
||||
$total_coupon = bcadd($order_svip_discount,bcadd(bcadd($total_platform_coupon_price,$order_coupon_price,2),$order_total_integral_price,2),2);
|
||||
|
||||
|
||||
$integralDeductionAmount = bcadd($order_total_integral_price,$orderTotalWineIntegralPrice,2);
|
||||
$total_coupon = bcadd($order_svip_discount,bcadd(bcadd($total_platform_coupon_price,$order_coupon_price,2),$integralDeductionAmount,2),2);
|
||||
|
||||
|
||||
$with_goods_mer_id = $withGoods['with_goods_mer_id'] ?? 0;
|
||||
$data = compact(
|
||||
'with_goods_mer_id',
|
||||
'order_type',
|
||||
'order_model',
|
||||
'order_extend',
|
||||
'order_total_postage',
|
||||
'order_price',
|
||||
'total_price',
|
||||
'platformCoupon',
|
||||
'enabledPlatformCoupon',
|
||||
'usePlatformCouponId',
|
||||
'order_total_integral',
|
||||
'order_total_integral_price',
|
||||
|
||||
$data = compact('with_goods_mer_id','order_type','order_model','order_extend','order_total_postage','order_price','total_price','platformCoupon','enabledPlatformCoupon','usePlatformCouponId','order_total_integral','order_total_integral_price','order_total_give_integral','order_svip_discount','total_platform_coupon_price','total_coupon','order_coupon_price','status','address','openIntegral','useIntegral','key','order_refund_switch','order') + [
|
||||
|
||||
'orderTotalWineIntegral',
|
||||
'orderTotalWineIntegralPrice',
|
||||
'orderTotalWineDiffMoney',
|
||||
'orderTotalWineDiffMoneyPrice',
|
||||
|
||||
|
||||
'order_total_give_integral',
|
||||
'order_svip_discount',
|
||||
'total_platform_coupon_price',
|
||||
'total_coupon',
|
||||
'order_coupon_price',
|
||||
'status',
|
||||
'address',
|
||||
'openIntegral',
|
||||
'useIntegral',
|
||||
'key',
|
||||
'order_refund_switch',
|
||||
'order') + [
|
||||
'allow_address' => !$allow_no_address,
|
||||
'order_delivery_status' => $orderDeliveryStatus
|
||||
];
|
||||
|
|
@ -883,7 +984,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
|
|||
$extend = [];
|
||||
}
|
||||
$orderType = $orderInfo['order_type'];
|
||||
if($orderType != 35){
|
||||
if(!in_array($orderType,[35, 36])){
|
||||
if($orderType && (count($orderInfo['order']) > 1 || ($orderType != 10 && count($orderInfo['order'][0]['list']) > 1))){
|
||||
throw new ValidateException('活动商品请单独购买');
|
||||
}
|
||||
|
|
@ -1056,7 +1157,13 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
|
|||
'pay_type' => $pay_type,
|
||||
'refund_switch' => $merchantCart['order']['order_refund_switch'],
|
||||
'with_goods_mer_id' => $orderInfo['with_goods_mer_id'] ?? 0,
|
||||
// 酒水卡积分抵扣相关
|
||||
'exchange_integral_price' => $merchantCart['order']['exchange_integral_price'] ?? 0,
|
||||
'exchange_integral' => $merchantCart['order']['exchange_integral'] ?? 0,
|
||||
'wine_diff_money' => $merchantCart['order']['wine_diff_money'] ?? 0,
|
||||
'wine_diff_money_price' => $merchantCart['order']['wine_diff_money_price'] ?? 0,
|
||||
];
|
||||
|
||||
$allUseCoupon = array_merge($allUseCoupon,$merchantCart['order']['useCouponIds']);
|
||||
$orderList[] = $_order;
|
||||
$totalPostage = bcadd($totalPostage,$_order['total_postage'],2);
|
||||
|
|
@ -1085,7 +1192,13 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
|
|||
'give_integral' => $orderInfo['order_total_give_integral'],
|
||||
'activity_type' => $orderInfo['order_type'],
|
||||
'with_goods_mer_id' => $orderInfo['with_goods_mer_id'] ?? 0,
|
||||
// 酒水卡积分相关
|
||||
'exchange_integral_price' => $orderInfo['orderTotalWineIntegralPrice'] ?? 0,
|
||||
'exchange_integral' => $orderInfo['orderTotalWineIntegral'] ?? 0,
|
||||
'wine_diff_money' => $orderInfo['orderTotalWineDiffMoney'] ?? 0,
|
||||
'wine_diff_money_price' => $orderInfo['orderTotalWineDiffMoneyPrice'] ?? 0,
|
||||
];
|
||||
|
||||
event('order.create.before',compact('groupOrder','orderList'));
|
||||
$group = Db::transaction(function() use ($ex,$user,$topUid,$spreadUid,$uid,$receipt_data,$cartIds,$allUseCoupon,$groupOrder,$orderList,$orderInfo){
|
||||
$storeGroupOrderRepository = app()->make(StoreGroupOrderRepository::class);
|
||||
|
|
@ -1176,6 +1289,51 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
|
|||
]);
|
||||
$user->save();
|
||||
}
|
||||
// 用户兑换酒道馆商品相关操作
|
||||
if($groupOrder['activity_type'] == 36){
|
||||
// 减少酒水卡积分
|
||||
if($groupOrder['exchange_integral'] > 0){
|
||||
$userInfo = User::where('uid',$user['uid'])->findOrEmpty();
|
||||
$integralChangeFront = (float)$userInfo->exchange_integral;
|
||||
$userInfo->exchange_integral -= (float)$groupOrder['exchange_integral'];
|
||||
$userInfo->exchange_integral = $userInfo->exchange_integral > 0 ? $userInfo->exchange_integral : 0;
|
||||
$userInfo->save();
|
||||
ExchangeIntegralRecord::insert([
|
||||
'uid' => $user['uid'],
|
||||
'product_id' => 0,
|
||||
'order_id' => 0,
|
||||
'order_product_id' => 0,
|
||||
'change_type' => 0,
|
||||
'change_quantity' => (float)$groupOrder['exchange_integral'],
|
||||
'change_front' => $integralChangeFront,
|
||||
'change_after' => (float)$userInfo->exchange_integral,
|
||||
'remark' => "兑换消费",
|
||||
]);
|
||||
}
|
||||
// 变更额度
|
||||
$userHoldInfo = app()->make(ExchangeQuotaRepository::class)
|
||||
->searchModel(['uid'=>$user['uid'],'quota_type'=>1])
|
||||
->findOrEmpty();
|
||||
$changeFront = (float)$userHoldInfo->surplus_quota;
|
||||
$userHoldInfo->use_quota += (float)$groupOrder['total_price'];
|
||||
$userHoldInfo->surplus_quota -= (float)$groupOrder['total_price'];
|
||||
$userHoldInfo->save();
|
||||
ExchangeQuotaRecord::insert([
|
||||
'uid' => $user['uid'],
|
||||
'product_id' => 0,
|
||||
'order_id' => 0,
|
||||
'order_product_id' => 0,
|
||||
'change_type' => 0,
|
||||
'change_quantity' => (float)$groupOrder['total_price'],
|
||||
'change_front' => $changeFront,
|
||||
'change_after' => (float)$userHoldInfo->surplus_quota,
|
||||
'remark' => "兑换消费",
|
||||
'source' => 2,
|
||||
'quota_type' => 1,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
foreach($orderList as $k => $order){
|
||||
$orderList[$k]['group_order_id'] = $groupOrder->group_order_id;
|
||||
}
|
||||
|
|
@ -1217,8 +1375,8 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
|
|||
'nickname' => $user->nickname,
|
||||
'user_type' => $storeOrderStatusRepository::U_TYPE_USER,
|
||||
];
|
||||
foreach($cartInfo['list'] as $cart){
|
||||
|
||||
foreach($cartInfo['list'] as $cart){
|
||||
$productPrice = $cart['true_price'];
|
||||
$extension_one = $cart['extension_one'];
|
||||
$extension_two = $cart['extension_two'];
|
||||
|
|
@ -1297,6 +1455,11 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
|
|||
'product_type' => $cart['product_type'],
|
||||
'cart_info' => json_encode($order_cart),
|
||||
'refund_switch' => $cart['refund_switch'],
|
||||
// 酒水卡积分
|
||||
'exchange_integral' => $cart['exchange_integral'] ?? 0,
|
||||
'exchange_integral_price' => $cart['exchange_integral_price'] ?? 0,
|
||||
'wine_diff_money' => $cart['wine_diff_money'] ?? 0,
|
||||
'wine_diff_money_price' => $cart['wine_diff_money_price'] ?? 0,
|
||||
];
|
||||
}
|
||||
$userMerchantRepository->getInfo($uid,$order['mer_id']);
|
||||
|
|
@ -1309,6 +1472,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
|
|||
->make(UserBillRepository::class)
|
||||
->insertAll($bills);
|
||||
}
|
||||
|
||||
$storeOrderStatusRepository->batchCreateLog($orderStatus);
|
||||
$storeOrderProductRepository->insertAll($orderProduct);
|
||||
event('order.create',compact('groupOrder'));
|
||||
|
|
@ -1333,7 +1497,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
|
|||
}
|
||||
|
||||
/****** 兼容平台积分和商户积分的版本 ************************************/
|
||||
/* public function v2CartIdByOrderInfo($user, array $cartId, array $takes = null, array $useCoupon = null, bool $usePlatformIntegral = false, bool $useMerIntegral = false, int $addressId = null, $createOrder = false)
|
||||
/*public function v2CartIdByOrderInfo($user, array $cartId, array $takes = null, array $useCoupon = null, bool $usePlatformIntegral = false, bool $useMerIntegral = false, int $addressId = null, $createOrder = false)
|
||||
{
|
||||
$uid = $user->uid;
|
||||
// $userIntegral = $user->integral;
|
||||
|
|
@ -2303,7 +2467,8 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
|
|||
Cache::set('order_create_cache' . $uid . '_' . $key, $data, 600);
|
||||
return $data;
|
||||
}
|
||||
public function v2CreateOrder($key, int $pay_type, $user, array $cartId, array $extend, array $mark, array $receipt_data, array $takes = null, array $useCoupon = null, int $addressId = null, array $post)
|
||||
*/
|
||||
/*public function v2CreateOrder($key, int $pay_type, $user, array $cartId, array $extend, array $mark, array $receipt_data, array $takes = null, array $useCoupon = null, int $addressId = null, array $post)
|
||||
{
|
||||
$uid = $user->uid;
|
||||
$orderInfo = Cache::get('order_create_cache' . $uid . '_' . $key);
|
||||
|
|
|
|||
Loading…
Reference in New Issue