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

test

上级 54ecc0ac
...@@ -46,7 +46,7 @@ class Payment ...@@ -46,7 +46,7 @@ class Payment
$payment->status = $status; $payment->status = $status;
$payment->pay_date = time(); $payment->pay_date = time();
$payment->save(); $payment->save();
$res = (new WriteOff())->writeOffFromPayment($payment->account_id, $payment->payment_id); $res = (new WriteOff())->writeOffFromPayment($payment->payment_id);
Log::record(date('Y-m-d H:i:s').' OA单号:'.$numb . $res); Log::record(date('Y-m-d H:i:s').' OA单号:'.$numb . $res);
} }
......
...@@ -19,8 +19,9 @@ class WriteOff extends Controller ...@@ -19,8 +19,9 @@ class WriteOff extends Controller
//获取缴费单对象 //获取缴费单对象
$payment = EmPayment::where('payment_id','=',$payment_id)->find(); $payment = EmPayment::where('payment_id','=',$payment_id)->find();
$invModel = new EmInvoice();
//获取关联的账单对象 //获取关联的账单对象
$invs = (new EmInvoice())->alias('a')->field('a.invoice_id') $invs = $invModel->alias('a')->field('a.invoice_id')
->join(['em_payment_invoice'=>'b'],'b.invoice_id = a.invoice_id') ->join(['em_payment_invoice'=>'b'],'b.invoice_id = a.invoice_id')
->where('b.payment_id','=',$payment_id) ->where('b.payment_id','=',$payment_id)
->where('a.payment_balance','neq',0) ->where('a.payment_balance','neq',0)
...@@ -28,19 +29,19 @@ class WriteOff extends Controller ...@@ -28,19 +29,19 @@ class WriteOff extends Controller
->select(); ->select();
$invsArr = []; $invsArr = [];
$payments_balance = 0;
//如果存在账单关联对象 //如果存在账单关联对象
if(!$invs->isEmpty()){ if(!$invs->isEmpty()){
foreach ($invs as $inv){ foreach ($invs as $inv){
$invsArr[] = $inv->invoice_id; $invsArr[] = $inv->invoice_id;
} }
}
//查询可消的额度 //查询可消的额度
$payments_balance = (new EmInvoice)->where('invoice_id','in',$invsArr)->sum('payment_balance'); $payments_balance = $invModel->where('invoice_id','in',$invsArr)->sum('payment_balance');
}
//如果可以完全销账 则继续销账 //如果可以完全销账 则继续销账
if($payment->balance > $payments_balance){ if($payment->balance > $payments_balance){
$invs = (new EmInvoice())->field('invoice_id') $invs = $invModel->field('invoice_id')
->where('account_id','=',$payment->account_id) ->where('account_id','=',$payment->account_id)
->where('payment_balance','neq',0) ->where('payment_balance','neq',0)
->whereNotIn('invoice_id',$invsArr) ->whereNotIn('invoice_id',$invsArr)
...@@ -53,9 +54,7 @@ class WriteOff extends Controller ...@@ -53,9 +54,7 @@ class WriteOff extends Controller
} }
} }
$paymentIds[] = $payment->payment_id; $paymentIds[] = $payment->payment_id;
//处理账户金额 //处理账户金额
return $this->writeOff($paymentIds,$invsArr); return $this->writeOff($paymentIds,$invsArr);
} }
...@@ -171,13 +170,17 @@ class WriteOff extends Controller ...@@ -171,13 +170,17 @@ class WriteOff extends Controller
unset($payments[$key]); unset($payments[$key]);
$balanceMode->isUpdate(false)->save(); $balanceMode->isUpdate(false)->save();
//更新账户余额 $this->computerAmount($inv->account_id,$balanceMode->balance);
$account = EmAccount::get(['account_id'=>$inv->account_id]);
$account->amount -= $balanceMode->balance;
$account->save();
} }
} }
$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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论