|
|
@@ -240,11 +240,28 @@ class CustomClass extends BaseClass
|
|
|
];
|
|
|
BalanceChangeClass::add($change, true);
|
|
|
|
|
|
- $giveAmount = bcsub($amount, $hd->balancePay, 2);//这个方法不能移到下面
|
|
|
- if ($hd->balancePay > $amount) {
|
|
|
+
|
|
|
+ if ($hd->balancePay >= $amount) {
|
|
|
+ //如果充值金额大于等于订单欠款金额,则用全部充值金额消单,还是正数
|
|
|
+
|
|
|
$payAmount = $amount;
|
|
|
+ $mustUseGiveAmount = 0;
|
|
|
} else {
|
|
|
- $payAmount = $hd->balancePay;
|
|
|
+ //如果充值金额小于订单欠款金额,则用全部充值金额消单,同时赠送金额加上,够抵,则还是正数,不够抵,则是负数
|
|
|
+
|
|
|
+ if ($hd->balanceGive <= 0) {
|
|
|
+ //没有赠送金额,则用充值金额来消全部的欠款金额,不够则变成负数
|
|
|
+ $payAmount = $amount;
|
|
|
+ } else {
|
|
|
+ $currentAdd = bcadd($hd->balancePay, $hd->balanceGive, 2);
|
|
|
+ if ($currentAdd >= $amount) {
|
|
|
+ $payAmount = $hd->balancePay;
|
|
|
+ $mustUseGiveAmount = bcsub($currentAdd, $payAmount, 2);
|
|
|
+ } else {
|
|
|
+ $mustUseGiveAmount = $hd->balanceGive;
|
|
|
+ $payAmount = bcsub($amount, $mustUseGiveAmount, 2);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/************************* 充值余额 *****************************/
|
|
|
@@ -292,14 +309,15 @@ class CustomClass extends BaseClass
|
|
|
BalancePayChangeClass::add($payChange, true);
|
|
|
|
|
|
/***************************** 赠送余额 ******************************/
|
|
|
- if ($giveAmount > 0) {
|
|
|
- $customBalanceGive = bcsub($custom->balanceGive, $giveAmount, 2);
|
|
|
+ //应用掉的赠送金额
|
|
|
+ if ($mustUseGiveAmount > 0) {
|
|
|
+ $customBalanceGive = bcsub($custom->balanceGive, $mustUseGiveAmount, 2);
|
|
|
if ($customBalanceGive < 0) {
|
|
|
- util::fail('余额异常哈,请联系管理员,编号' . $hdId);
|
|
|
+ util::fail('余额异常哈,请联系管理员,编号' . $hdId . ' ' . $custom->balanceGive);
|
|
|
}
|
|
|
$custom->balanceGive = $customBalanceGive;
|
|
|
$custom->save();
|
|
|
- $hdBalanceGive = bcsub($hd->balanceGive, $giveAmount, 2);
|
|
|
+ $hdBalanceGive = bcsub($hd->balanceGive, $mustUseGiveAmount, 2);
|
|
|
$hd->balanceGive = $hdBalanceGive;
|
|
|
$hd->save();
|
|
|
if (floatval($customBalanceGive) != floatval($hdBalanceGive)) {
|
|
|
@@ -322,7 +340,7 @@ class CustomClass extends BaseClass
|
|
|
'relateId' => $relateId,
|
|
|
'onlinePay' => $onlinePay,
|
|
|
'capitalType' => $capitalType,
|
|
|
- 'amount' => $giveAmount,
|
|
|
+ 'amount' => $mustUseGiveAmount,
|
|
|
'balance' => $customBalanceGive,
|
|
|
'io' => 0,
|
|
|
'side' => $side,
|