|
@@ -252,6 +252,7 @@ class StoreOrder extends BaseModel
|
|
|
|
|
|
/**
|
|
/**
|
|
* 生成订单
|
|
* 生成订单
|
|
|
|
+ * @param int $userConsumption
|
|
* @param $uid
|
|
* @param $uid
|
|
* @param $key
|
|
* @param $key
|
|
* @param $addressId
|
|
* @param $addressId
|
|
@@ -275,7 +276,7 @@ class StoreOrder extends BaseModel
|
|
* @throws \think\exception\DbException
|
|
* @throws \think\exception\DbException
|
|
*/
|
|
*/
|
|
|
|
|
|
- public static function cacheKeyCreateOrder($uid, $key, $addressId, $payType, $useIntegral = false, $couponId = 0, $mark = '', $combinationId = 0, $pinkId = 0, $seckill_id = 0, $bargain_id = 0, $test = false, $isChannel = 0, $shipping_type = 1, $real_name = '', $phone = '', $storeId = 0)
|
|
|
|
|
|
+ public static function cacheKeyCreateOrder($userConsumption = 0,$uid, $key, $addressId, $payType, $useIntegral = false, $couponId = 0, $mark = '', $combinationId = 0, $pinkId = 0, $seckill_id = 0, $bargain_id = 0, $test = false, $isChannel = 0, $shipping_type = 1, $real_name = '', $phone = '', $storeId = 0)
|
|
{
|
|
{
|
|
self::beginTrans();
|
|
self::beginTrans();
|
|
try {
|
|
try {
|
|
@@ -332,6 +333,11 @@ class StoreOrder extends BaseModel
|
|
if ($cateId[0] == 1){
|
|
if ($cateId[0] == 1){
|
|
$number += $cart['cart_num'];
|
|
$number += $cart['cart_num'];
|
|
}
|
|
}
|
|
|
|
+ if ($cateId[0] == 3 and $useIntegral){
|
|
|
|
+ return self::setErrorInfo('消费券商品不能使用积分抵扣', true);
|
|
|
|
+ }elseif ($cateId[0] != 3 and $userConsumption){
|
|
|
|
+ return self::setErrorInfo('普通商品不能使用消费券抵扣', true);
|
|
|
|
+ }
|
|
$gainIntegral = bcadd($gainIntegral, $cartInfoGainIntegral, 2);
|
|
$gainIntegral = bcadd($gainIntegral, $cartInfoGainIntegral, 2);
|
|
}
|
|
}
|
|
if ($shop_number < $number) return self::setErrorInfo('环球优购专区最大购买数'.$shop_number, true);
|
|
if ($shop_number < $number) return self::setErrorInfo('环球优购专区最大购买数'.$shop_number, true);
|
|
@@ -388,7 +394,8 @@ class StoreOrder extends BaseModel
|
|
|
|
|
|
//积分抵扣
|
|
//积分抵扣
|
|
$res2 = true;
|
|
$res2 = true;
|
|
- $SurplusIntegral = $userInfo['integral'];
|
|
|
|
|
|
+ $SurplusIntegral = $userInfo['integral'] + $userInfo['dynamic_integral'];
|
|
|
|
+ $SurplusConsumption = $userInfo['consumption'];
|
|
if ($payIntegral > 0) {
|
|
if ($payIntegral > 0) {
|
|
if ($userInfo['integral'] < $payIntegral) {
|
|
if ($userInfo['integral'] < $payIntegral) {
|
|
return self::setErrorInfo('积分不足', true);
|
|
return self::setErrorInfo('积分不足', true);
|
|
@@ -399,23 +406,53 @@ class StoreOrder extends BaseModel
|
|
$res2 = $res2 && false != UserBill::expend('积分商品', $uid, 'integral', 'integral_product', $payIntegral, $key, $SurplusIntegral, '购买积分商品使用' . $payIntegral . '积分');
|
|
$res2 = $res2 && false != UserBill::expend('积分商品', $uid, 'integral', 'integral_product', $payIntegral, $key, $SurplusIntegral, '购买积分商品使用' . $payIntegral . '积分');
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if ($userConsumption && $SurplusConsumption > 0){
|
|
|
|
+ if ($SurplusConsumption < $payPrice){
|
|
|
|
+ $deductionPrice = $SurplusConsumption;
|
|
|
|
+ $payPrice = bcsub($payPrice, $SurplusConsumption, 2);
|
|
|
|
+ $user_consumption = $SurplusConsumption;
|
|
|
|
+ $SurplusConsumption = 0;
|
|
|
|
+ $resc = false !== User::edit(['consumption' => 0], $userInfo['uid'], 'uid');
|
|
|
|
+ }else{
|
|
|
|
+ $deductionPrice = $payPrice;
|
|
|
|
+ $user_consumption = $payPrice;
|
|
|
|
+ $SurplusConsumption = bcsub($SurplusConsumption, $deductionPrice, 2);
|
|
|
|
+ $resc = false !== User::bcDec($userInfo['uid'], 'consumption', $deductionPrice, 'uid');
|
|
|
|
+ $payPrice = 0;
|
|
|
|
+ }
|
|
|
|
+ $resc = $resc && false != UserBill::expend('消费券抵扣', $uid, 'integral', 'deduction', $deductionPrice, $key, $SurplusConsumption, '购买商品使用' . floatval($deductionPrice) . '消费券抵扣抵扣' . floatval($deductionPrice) . '元');
|
|
|
|
+ $usedIntegral = 0;
|
|
|
|
+ if (!$resc) return self::setErrorInfo('使用消费券抵扣失败!', true);
|
|
|
|
+ }elseif (!$useIntegral && !$userConsumption){
|
|
|
|
+ $deductionPrice = 0;
|
|
|
|
+ $user_consumption = 0;
|
|
|
|
+ }
|
|
//积分抵扣
|
|
//积分抵扣
|
|
if ($useIntegral && $SurplusIntegral > 0) {
|
|
if ($useIntegral && $SurplusIntegral > 0) {
|
|
$deductionPrice = (float)bcmul($SurplusIntegral, $other['integralRatio'], 2);
|
|
$deductionPrice = (float)bcmul($SurplusIntegral, $other['integralRatio'], 2);
|
|
|
|
+ $str = '';
|
|
if ($deductionPrice < $payPrice) {
|
|
if ($deductionPrice < $payPrice) {
|
|
$payPrice = bcsub($payPrice, $deductionPrice, 2);
|
|
$payPrice = bcsub($payPrice, $deductionPrice, 2);
|
|
$usedIntegral = $SurplusIntegral;
|
|
$usedIntegral = $SurplusIntegral;
|
|
$SurplusIntegral = 0;
|
|
$SurplusIntegral = 0;
|
|
- $res2 = false !== User::edit(['integral' => 0], $userInfo['uid'], 'uid');
|
|
|
|
|
|
+ $res2 = false !== User::edit(['integral' => 0, 'dynamic_integral' => 0], $userInfo['uid'], 'uid');
|
|
} else {
|
|
} else {
|
|
$deductionPrice = $payPrice;
|
|
$deductionPrice = $payPrice;
|
|
$usedIntegral = (float)bcdiv($payPrice, $other['integralRatio'], 2);
|
|
$usedIntegral = (float)bcdiv($payPrice, $other['integralRatio'], 2);
|
|
$SurplusIntegral = bcsub($SurplusIntegral, $usedIntegral, 2);
|
|
$SurplusIntegral = bcsub($SurplusIntegral, $usedIntegral, 2);
|
|
- $res2 = false !== User::bcDec($userInfo['uid'], 'integral', $usedIntegral, 'uid');
|
|
|
|
|
|
+ if ($userInfo['integral'] < $usedIntegral){
|
|
|
|
+ $res2 = false !== User::bcDec($userInfo['uid'], 'integral', $userInfo['integral'], 'uid');
|
|
|
|
+ $res2 = $res2 && false !== User::bcDec($userInfo['uid'], 'dynamic_integral', ($usedIntegral - $userInfo['integral']), 'uid');
|
|
|
|
+ $str = '使用普通积分'.$userInfo['integral'].'和使用动态积分'.$userInfo['dynamic_integral'];
|
|
|
|
+ }else{
|
|
|
|
+ $res2 = false !== User::bcDec($userInfo['uid'], 'integral', $usedIntegral, 'uid');
|
|
|
|
+ }
|
|
|
|
+
|
|
$payPrice = 0;
|
|
$payPrice = 0;
|
|
}
|
|
}
|
|
- $res2 = $res2 && false != UserBill::expend('积分抵扣', $uid, 'integral', 'deduction', $usedIntegral, $key, $SurplusIntegral, '购买商品使用' . floatval($usedIntegral) . '积分抵扣' . floatval($deductionPrice) . '元');
|
|
|
|
- } else {
|
|
|
|
|
|
+ $res2 = $res2 && false != UserBill::expend('积分抵扣', $uid, 'integral', 'deduction', $usedIntegral, $key, $SurplusIntegral, '购买商品使用' . floatval($usedIntegral) . '积分抵扣' . floatval($deductionPrice) . '元'.$str);
|
|
|
|
+ $user_consumption = 0;
|
|
|
|
+ } elseif (!$useIntegral && !$userConsumption){
|
|
$deductionPrice = 0;
|
|
$deductionPrice = 0;
|
|
$usedIntegral = 0;
|
|
$usedIntegral = 0;
|
|
}
|
|
}
|
|
@@ -431,6 +468,7 @@ class StoreOrder extends BaseModel
|
|
'deduction_price' => $deductionPrice,
|
|
'deduction_price' => $deductionPrice,
|
|
'totalIntegral' => $payIntegral,
|
|
'totalIntegral' => $payIntegral,
|
|
'SurplusIntegral' => $SurplusIntegral,
|
|
'SurplusIntegral' => $SurplusIntegral,
|
|
|
|
+ 'SurplusConsumption' => $SurplusConsumption
|
|
];
|
|
];
|
|
}
|
|
}
|
|
$orderInfo = [
|
|
$orderInfo = [
|
|
@@ -451,6 +489,7 @@ class StoreOrder extends BaseModel
|
|
'paid' => 0,
|
|
'paid' => 0,
|
|
'pay_type' => $payType,
|
|
'pay_type' => $payType,
|
|
'use_integral' => $usedIntegral + $payIntegral,
|
|
'use_integral' => $usedIntegral + $payIntegral,
|
|
|
|
+ 'user_consumption' => $user_consumption,
|
|
'gain_integral' => $gainIntegral,
|
|
'gain_integral' => $gainIntegral,
|
|
'mark' => htmlspecialchars($mark),
|
|
'mark' => htmlspecialchars($mark),
|
|
'combination_id' => $combinationId,
|
|
'combination_id' => $combinationId,
|