提交 b34196ad authored 作者: chengye's avatar chengye

调整账号额度变化逻辑

上级 77fa9af6
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
*/ */
namespace app\api\controller\v2\common; namespace app\api\controller\v2\common;
use app\em\controller\Account;
use app\em\controller\WriteOff; use app\em\controller\WriteOff;
use app\em\model\EmAccount; use app\em\model\EmAccount;
use app\em\model\EmPayment; use app\em\model\EmPayment;
......
...@@ -93,4 +93,11 @@ class Account extends Base ...@@ -93,4 +93,11 @@ class Account extends Base
} }
return $account->save(); return $account->save();
} }
public function computerAmount($em_id,$balance){
//更新账户余额
$account = self::get(['em_id'=>$em_id]);
$account->amount += $balance;
return $account->save();
}
} }
\ No newline at end of file
...@@ -178,11 +178,12 @@ class Invoice extends Base ...@@ -178,11 +178,12 @@ class Invoice extends Base
$eiu->save(); $eiu->save();
} }
// //更新电表账户 //更新电表账户
// $useage = \app\em\model\Useage::get(['useage_id' => $uData['useage_id']]); $useage = \app\em\model\Useage::get(['useage_id' => $uData['useage_id']]);
//
// $account = new Account(); $account = new Account();
// $account->updateAmount($useage->em_id,$inv->payment_amount,0); $pay_amount = 0 - $inv->payment_amount;
$account->computerAmount($useage->em_id,$pay_amount);
return $inv; return $inv;
} }
...@@ -236,6 +237,10 @@ class Invoice extends Base ...@@ -236,6 +237,10 @@ class Invoice extends Base
$eiu->useage_id = $uData['useage_id']; $eiu->useage_id = $uData['useage_id'];
$eiu->save(); $eiu->save();
} }
$account = new Account();
$pay_amount = 0 - $inv->payment_amount;
$account->computerAmount($useage->em_id,$pay_amount);
return $inv; return $inv;
} }
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
namespace app\em\controller; namespace app\em\controller;
use app\em\model\EmAccount;
use app\em\model\EmInvoice; use app\em\model\EmInvoice;
use app\em\model\EmPayment; use app\em\model\EmPayment;
use app\em\model\EmPaymentInvoice; use app\em\model\EmPaymentInvoice;
...@@ -89,15 +88,7 @@ class WriteOff extends Controller ...@@ -89,15 +88,7 @@ class WriteOff extends Controller
->whereIn('status','3,4,5') ->whereIn('status','3,4,5')
->order('payment_id asc') ->order('payment_id asc')
->select(); ->select();
if($payments->isEmpty()) { if($payments->isEmpty()) return '没有找到可销账的缴费单!';
$account = EmAccount::get(['account_id'=>$invoice->account_id]);
$account->amount -= $invoice->payment_balance;
$account->save();
$invoice->is_pay = 1;
$invoice->save();
return '没有找到可销账的缴费单!';
}
} }
$paymentIds = []; $paymentIds = [];
foreach ($payments as $payment){ foreach ($payments as $payment){
...@@ -107,7 +98,6 @@ class WriteOff extends Controller ...@@ -107,7 +98,6 @@ class WriteOff extends Controller
'invoice_id' => $invoice->invoice_id 'invoice_id' => $invoice->invoice_id
]; ];
//销账日志 //销账日志
$logMsg = date('Y-m-d H-i-s').'paymentIds :' .implode('-',$paymentIds) .'invoiceIds :' .implode('-',$invsIds); $logMsg = date('Y-m-d H-i-s').'paymentIds :' .implode('-',$paymentIds) .'invoiceIds :' .implode('-',$invsIds);
Log::info($logMsg); Log::info($logMsg);
...@@ -137,7 +127,6 @@ class WriteOff extends Controller ...@@ -137,7 +127,6 @@ class WriteOff extends Controller
foreach ($invs as $index => $inv) { foreach ($invs as $index => $inv) {
if ($inv->payment_balance == 0) continue; if ($inv->payment_balance == 0) continue;
$dk_balance = 0;
$balanceMode = new EmPaymentInvoiceBalance(); $balanceMode = new EmPaymentInvoiceBalance();
$balanceMode->payment_id = $payment->payment_id; $balanceMode->payment_id = $payment->payment_id;
$balanceMode->invoice_id = $inv->invoice_id; $balanceMode->invoice_id = $inv->invoice_id;
...@@ -145,7 +134,7 @@ class WriteOff extends Controller ...@@ -145,7 +134,7 @@ class WriteOff extends Controller
//如果该缴费单可以完全消除当前账单额度 //如果该缴费单可以完全消除当前账单额度
if ($payment->balance >= $inv->payment_balance) { if ($payment->balance >= $inv->payment_balance) {
//单笔销账多少 //单笔销账多少
$balanceMode->balance = $dk_balance = $inv->payment_balance; $balanceMode->balance = $inv->payment_balance;
$payment->balance = $payment->balance - $inv->payment_balance; $payment->balance = $payment->balance - $inv->payment_balance;
//账单额度变化 //账单额度变化
...@@ -161,7 +150,7 @@ class WriteOff extends Controller ...@@ -161,7 +150,7 @@ class WriteOff extends Controller
$inv->payment_balance = $inv->payment_balance - $payment->balance; $inv->payment_balance = $inv->payment_balance - $payment->balance;
//缴费额度变化 //缴费额度变化
$payment->balance = 0; $payment->balance = 0;
$dk_balance = $inv->payment_balance;
} }
//更新账单状态 //更新账单状态
...@@ -180,17 +169,10 @@ class WriteOff extends Controller ...@@ -180,17 +169,10 @@ class WriteOff extends Controller
$result++; $result++;
$balanceMode->isUpdate(false)->save(); $balanceMode->isUpdate(false)->save();
if($inv->is_pay != 1) $this->computerAmount($inv->account_id,$dk_balance); // if($inv->is_pay != 1) $this->computerAmount($inv->account_id,$dk_balance);
} }
} }
$msg = $result == 0 ? '已审核,没有找到可销账的缴费单.' : '已审核,成功销账 '.$result.' 笔账单.'; $msg = $result == 0 ? '已审核,没有找到可销账的缴费单.' : '已审核,成功销账 '.$result.' 笔账单.';
return $msg; return $msg;
} }
protected function computerAmount($account_id,$balance){
//更新账户余额
$account = EmAccount::get(['account_id'=>$account_id]);
$account->amount -= $balance;
$account->save();
}
} }
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论