@@ -63,6 +63,11 @@ class OrderCreate
|
||||
*/
|
||||
protected $coupon_id = 0;
|
||||
|
||||
/**
|
||||
* 用户选择的兑换券抵扣金额
|
||||
*/
|
||||
protected $voucher_fee = 0;
|
||||
|
||||
/**
|
||||
* 用户备注
|
||||
*/
|
||||
@@ -102,6 +107,8 @@ class OrderCreate
|
||||
'goods_old_amount' => '0', // 商品不参与活动时的总价
|
||||
'goods_amount' => '0', // 商品总价
|
||||
'coupon_discount_fee' => '0', // 优惠券优惠金额
|
||||
'voucher_fee' => '0', // 兑换券抵扣
|
||||
'voucher_available' => '0', // 当前可用兑换券
|
||||
'promo_discount_fee' => 0, // 当前促销优惠总金额 (包含满包邮的邮费)
|
||||
'total_discount_fee' => 0, // 当前订单,总优惠金额(优惠券 + 活动优惠)
|
||||
'coupon' => null, // 所使用的优惠券
|
||||
@@ -151,6 +158,7 @@ class OrderCreate
|
||||
$this->invoice_id = $params['invoice_id'] ?? 0;
|
||||
|
||||
$this->coupon_id = $params['coupon_id'] ?? 0;
|
||||
$this->voucher_fee = isset($params['voucher_fee']) ? floatval($params['voucher_fee']) : 0;
|
||||
$this->remark = $params['remark'] ?? '';
|
||||
|
||||
$this->money = (isset($params['money']) && $params['money'] > 0) ? $params['money'] : 0;
|
||||
@@ -593,6 +601,29 @@ class OrderCreate
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 兑换券抵扣:先商城券,再兑换券;不超过可用额和应付
|
||||
*/
|
||||
public function calcVoucher()
|
||||
{
|
||||
$available = 0;
|
||||
if ($this->user && $this->user->id && $this->order_type !== 'score') {
|
||||
$available = (new \addons\shopro\service\partner\VoucherService())->available($this->user->id);
|
||||
}
|
||||
$this->orderData['voucher_available'] = $available;
|
||||
$want = $this->order_type === 'score' ? 0 : max(0, round((float) $this->voucher_fee, 2));
|
||||
$apply = min($want, (float) $available, (float) $this->orderData['pay_fee']);
|
||||
$apply = $apply > 0 ? $apply : 0;
|
||||
$this->orderData['voucher_fee'] = $apply;
|
||||
if ($apply > 0) {
|
||||
$this->orderData['pay_fee'] = bcsub((string) $this->orderData['pay_fee'], (string) $apply, 2);
|
||||
$this->orderData['total_discount_fee'] = bcadd((string) $this->orderData['total_discount_fee'], (string) $apply, 2);
|
||||
if ($this->orderData['pay_fee'] < 0) {
|
||||
$this->orderData['pay_fee'] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户的优惠券列表,可用和不可用的做区分
|
||||
@@ -969,6 +1000,8 @@ class OrderCreate
|
||||
'temp_remain_pay_fee' => $temp_remain_pay_fee >= 0 ? $temp_remain_pay_fee : 0, // 临时剩余应支付金额,订单确认页面显示
|
||||
'total_discount_fee' => $this->orderData['total_discount_fee'],
|
||||
'coupon_discount_fee' => $this->orderData['coupon_discount_fee'],
|
||||
'voucher_fee' => $this->orderData['voucher_fee'],
|
||||
'voucher_available' => $this->orderData['voucher_available'],
|
||||
'promo_discount_fee' => $this->orderData['promo_discount_fee'], // 包含包邮的运费优惠
|
||||
'money' => $this->money, // 余额支付部分
|
||||
"invoice_amount" => $this->orderData[$this->invoiceConfig['amount_type']] // 可开票金额
|
||||
@@ -1042,6 +1075,7 @@ class OrderCreate
|
||||
$this->orderData['total_discount_fee'] = bcadd($this->orderData['coupon_discount_fee'], $this->orderData['promo_discount_fee'], 2);
|
||||
$this->orderData['pay_fee'] = bcsub($this->orderData['order_amount'], $this->orderData['total_discount_fee'], 2);
|
||||
$this->orderData['pay_fee'] = $this->orderData['pay_fee'] < 0 ? 0 : $this->orderData['pay_fee'];
|
||||
$this->calcVoucher();
|
||||
|
||||
return $this->calcReturn();
|
||||
}
|
||||
@@ -1074,6 +1108,12 @@ class OrderCreate
|
||||
$order = Order::with('items')->where('id', $order->id)->find();
|
||||
|
||||
$pay_money = floatval($result['money']);
|
||||
if ($order->status == Order::STATUS_UNPAID && bccomp((string) $order->pay_fee, '0', 2) === 0) {
|
||||
$order = Db::transaction(function () use ($order) {
|
||||
$payOper = new PayOper();
|
||||
return $payOper->checkAndPaid($order, 'order');
|
||||
});
|
||||
}
|
||||
if ($order->status == Order::STATUS_UNPAID && $pay_money > 0) {
|
||||
// 如果订单未支付,并且使用了余额混合支付 (支付失败,不影响订单状态)
|
||||
$order = Db::transaction(function () use ($order, $pay_money) {
|
||||
@@ -1129,6 +1169,7 @@ class OrderCreate
|
||||
}
|
||||
$ext['offline_status'] = $result['offline_status'];
|
||||
$ext['need_address'] = $result['need_address']; // 后台判断是否有 编辑收货地址按钮
|
||||
$ext['voucher_fee'] = $result['voucher_fee'] ?? 0;
|
||||
|
||||
// 发票开具状态
|
||||
$invoice_status = 0; // 没有申请
|
||||
|
||||
在新工单中引用
屏蔽一个用户