diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index 972be47b..b7d0076c 100644 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -35,10 +35,12 @@ class StoreOrderCreateRepository extends StoreOrderRepository { protected $store_consumption_user; protected $consumption_money; + protected $balance; public function v2CartIdByOrderInfo($user, array $cartId, array $takes = null, array $useCoupon = null, bool $useIntegral = false, int $addressId = null, $createOrder = false, $consumption_id = 0) { $uid = $user->uid; + $this->balance = 0; $userIntegral = $user->integral; $key = md5(json_encode(compact('cartId', 'takes', 'useCoupon', 'useIntegral', 'addressId'))) . $uid; app()->make(StoreCouponUserRepository::class)->failCoupon(); @@ -154,6 +156,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository if ($consumption_id > 0) { $this->store_consumption_user = Db::name('store_consumption_user')->where('coupon_user_id', $consumption_id)->where('uid', $uid)->find(); + $this->balance=$this->store_consumption_user['balance']; } // 循环计算每个店铺的订单数据 委托商品是否设置收货方式 ? foreach ($merchantCartList as &$merchantCart) { @@ -565,33 +568,33 @@ class StoreOrderCreateRepository extends StoreOrderRepository $pay_price = $org_price; } //计算总红包金额 - $a = 0; if ($consumption_id > 0) { if ($this->store_consumption_user) { if ($this->store_consumption_user['type'] == 2) { $a = bcdiv($pay_price, 6); - if ($this->store_consumption_user['balance'] > $a) { + if ($this->balance > $a) { $pay_price = bcsub($pay_price, $a, 2); $this->consumption_money = bcadd($this->consumption_money, $a); - $this->store_consumption_user['balance'] = bcsub($this->store_consumption_user['balance'], $a); + $this->balance = bcsub($this->balance, $a); } else { - $a = $this->store_consumption_user['balance']; - $pay_price = bcsub($pay_price, $this->store_consumption_user['balance'], 2); - $this->consumption_money = bcadd($this->consumption_money, $this->store_consumption_user['balance']); - $this->store_consumption_user['balance'] = 0; + $pay_price = bcsub($pay_price, $this->balance, 2); + $this->consumption_money = bcadd($this->consumption_money, $this->balance); + $this->balance = 0; } } if ($this->store_consumption_user['type'] == 1) { - if ($pay_price > $this->store_consumption_user['balance']) { - $pay_price = bcsub($pay_price, $this->store_consumption_user['balance'], 2); - $this->consumption_money = $this->store_consumption_user['balance']; - $a = $this->store_consumption_user['balance']; + if ($pay_price > $this->balance) { + $pay_price = bcsub($pay_price, $this->balance, 2); + $this->consumption_money = bcadd($this->consumption_money, $this->balance); + $this->balance=0; } else { - $this->consumption_money = $pay_price; $pay_price = 0; - $a = $this->consumption_money; + $this->consumption_money = bcadd($this->consumption_money, $pay_price); + $this->balance = $pay_price; + } } + } } @@ -611,7 +614,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository $merchantCart['order']['postage_price'] = $merchantCart['order']['postage_price']; $merchantCart['order']['procure_price'] = $merchantCart['order']['procure_price']; $merchantCart['order']['consumption_id'] = $consumption_id; - $merchantCart['order']['consumption_money'] = $a; + $merchantCart['order']['consumption_money'] = $this->balance; $order_price = bcadd($order_price, $pay_price, 2); $order_total_price = bcadd($order_total_price, $total_price, 2);