|
|
@@ -9,6 +9,7 @@ use app\common\model\AdminModel;
|
|
|
use app\common\model\ConfigModel;
|
|
|
use app\common\model\CreditCardConfigModel;
|
|
|
use app\common\model\CustomerModel;
|
|
|
+use app\common\model\CustomerZueCoinModel;
|
|
|
use app\common\model\OrderAnnualFeeModel;
|
|
|
use app\common\model\OrderModel;
|
|
|
use app\common\model\OrderPaymentModel;
|
|
|
@@ -36,6 +37,7 @@ class OrderService extends \app\BaseService
|
|
|
private $customerModel;
|
|
|
private $paymentChannelModel;
|
|
|
private $creditCardModel;
|
|
|
+ private $zueCoinModel;
|
|
|
|
|
|
public function __construct()
|
|
|
{
|
|
|
@@ -53,6 +55,7 @@ class OrderService extends \app\BaseService
|
|
|
$this->customerModel = new CustomerModel();
|
|
|
$this->paymentChannelModel = new PaymentChannelModel();
|
|
|
$this->creditCardModel = new CreditCardConfigModel();
|
|
|
+ $this->zueCoinModel = new CustomerZueCoinModel();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -277,6 +280,7 @@ class OrderService extends \app\BaseService
|
|
|
$item['fee'] = $channel->fee;
|
|
|
// TODO: 御龙币需求未明确
|
|
|
array_push($order_payments, $item);
|
|
|
+ $zue_coin += $channel->fee;
|
|
|
} else {
|
|
|
for ($j = 0; $j < count($channel->credit_card); $j++) {
|
|
|
$credit_card = $channel->credit_card[$j];
|
|
|
@@ -326,6 +330,51 @@ class OrderService extends \app\BaseService
|
|
|
$total_service_charge_amount = ($order->service_charge_amount + $service_charge);
|
|
|
// 总共需要收取这么多费用; (商品的价格 + 商品税费 + 年费 + 信用卡手续费) - 御龙币抵扣的费用
|
|
|
$imposed_amount = fixed2Float($order->product_amount + $order->total_sales_tax + $order->total_annual_fee + $total_service_charge_amount);
|
|
|
+
|
|
|
+
|
|
|
+ $order_use_zue_coin = $order->zue_coin;
|
|
|
+ $order_use_zue_coin_amount = $order->zue_coin_amount;
|
|
|
+
|
|
|
+ if($zue_coin > 0) {
|
|
|
+ $zue_coin_model = $this->zueCoinModel->findByCustomerId($customer->id);
|
|
|
+ if ($zue_coin > $zue_coin_model->zue_coin)
|
|
|
+ return $this->fail("当前客户御龙币账户余额:{$zue_coin_model->zue_coin}");
|
|
|
+ $zue_coin_config = $fmt_pay_channels['11'];
|
|
|
+ if(!$zue_coin_config)
|
|
|
+ return $this->fail("御龙币设置不存在!");
|
|
|
+ $zue_coin_exchange_rate = $zue_coin_config['zue_coin_exchange_rate'] ?? 0; // 兑换比例
|
|
|
+ $zue_coin_consume_rate = $zue_coin_config['zue_coin_consume_rate'] ?? 0; // 报销比例
|
|
|
+ if($zue_coin_exchange_rate == 0 || $zue_coin_consume_rate == 0) {
|
|
|
+ return $this->fail("该笔订单不支持御龙币支付");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 1.计算出该订单能使用多少御龙币
|
|
|
+ // 2.结合之前已使用的御龙币 算出还能使用多少御龙币
|
|
|
+ // 3.判断当前御龙币是否符合兑换数额
|
|
|
+ // 4.进行扣除并记录
|
|
|
+
|
|
|
+ // 总共能报销这么多钱
|
|
|
+ $total_consume_amount = fixed2Float($imposed_amount * ($zue_coin_consume_rate / 100));
|
|
|
+ // 总共能消耗这么多御龙币
|
|
|
+ $total_can_zue_coin = fixed2Float($total_consume_amount / $zue_coin_exchange_rate);
|
|
|
+ // 还能使用多少御龙币
|
|
|
+ $now_can_consume_zue_coin = $total_can_zue_coin - $order_use_zue_coin;
|
|
|
+ // 判断当前还能使用
|
|
|
+ if ($now_can_consume_zue_coin - $zue_coin < 0)
|
|
|
+ return $this->fail("
|
|
|
+ 当前已使用御龙币数额: {$order_use_zue_coin}/{$total_can_zue_coin},
|
|
|
+ 当前已兑换金额: {$order_use_zue_coin_amount}/{$total_consume_amount},
|
|
|
+ 御龙币兑换比例: {$zue_coin_exchange_rate},
|
|
|
+ 御龙币报销比例:{$zue_coin_consume_rate}
|
|
|
+ ");
|
|
|
+ // 总共使用了这么多御龙币
|
|
|
+ $order_use_zue_coin += $zue_coin;
|
|
|
+ // 总共兑换了这么多钱
|
|
|
+ $order_use_zue_coin_amount = fixed2Float($order_use_zue_coin * $zue_coin_exchange_rate);
|
|
|
+ }
|
|
|
+ // 总计费用 - 御龙币抵消费用;
|
|
|
+ $imposed_amount -= $order_use_zue_coin_amount;
|
|
|
+
|
|
|
// 总计实收金额
|
|
|
$receive_amount = fixed2Float($order->receive_amount + $total_fee);
|
|
|
if (round($receive_amount) > round($imposed_amount)) return $this->fail("实收金额大于待收金额! 应该支付 {$imposed_amount} (商品总价:{$order->product_amount} + 商品总消费税:{$order->total_sales_tax} + 第一年年费:{$order->total_annual_fee} + 信用卡总手续费:{$total_service_charge_amount})");
|
|
|
@@ -369,15 +418,19 @@ class OrderService extends \app\BaseService
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ return $this->ok(true);
|
|
|
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
$update_order = [
|
|
|
- 'rental_amount' => $imposed_amount,
|
|
|
+ 'rental_amount' => $imposed_amount + $order_use_zue_coin_amount,
|
|
|
'receivable_amount' => $imposed_amount,
|
|
|
'receive_amount' => $receive_amount,
|
|
|
'imposed_amount' => $imposed_amount - $receive_amount,
|
|
|
'service_charge_amount' => $order->service_charge_amount + $service_charge,
|
|
|
+ 'zue_coin' => $order_use_zue_coin,
|
|
|
+ 'zue_coin_amount' => $order_use_zue_coin_amount,
|
|
|
+ 'remarks' => $params['remarks']
|
|
|
];
|
|
|
if (round($receive_amount) == round($imposed_amount)) { // 支付满了
|
|
|
$update_order['type'] = 1;
|