提交 1accbcb3 authored 作者: chengye's avatar chengye

test

上级 dbaf0c2a
......@@ -285,106 +285,13 @@ class Invoice extends Base
return $this->fetch('merge_list');
}
/**
* 账单触发销账,invoice_id 1:n payment_id
* @param $account_id
* @param $invoice_id
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @return mixed
*/
public function writeOffFromInvoice($invoice_id,$account_id){
//获取账单对象
$invoice = EmInvoice::field('id,invoice_id,payment_amount,payment_balance')
->where('invoice_id','=',$invoice_id)->find();
//查询关系表中与当前invoice_id相关联的payment_id
$model = new EmPaymentInvoice;
$payments = $model->alias('epi')->field('epi.payment_id')
->leftJoin(['em_payment'=>'ep'],'epi.payment_id = ep.payment_id')
->leftJoin(['em_payment_invoice_balance'=>'epib'],'epib.invoice_id=epi.invoice_id')
->where('epib.balance','>',0)
->where('epi.invoice_id','=',$invoice_id)->select();
//如果没有找到记录 证明并没有形成对应关系
if($payments->isEmpty()){
//查询是否有未缴费的缴费单存在
$payments = EmPayment::field('payment_id')->where('account_id','=',$account_id)
->where('balance','>',0)
->whereIn('status','3,4,5,6,8')
->order('payment_id asc')
->select();
if($payments->isEmpty()) {
return '没有销账的缴费单!';
}
}
$paymentIds = [];
foreach ($payments as $payment){
$paymentIds[] = $payment->payment_id;
}
$invsIds = [
'invoice_id' => $invoice->invoice_id
];
//开始销账
return $this->writeOff($paymentIds,$invsIds);
}
//从缴费单消账单
public function writeOffFromPayment($account_id,$payment_id){
Log::info('触发销账:'.$account_id.' | '.$payment_id);
//获取缴费单对象
$payment = EmPayment::where('payment_id','=',$payment_id)->find();
//获取关联的账单对象
$invs = (new EmInvoice())->alias('ei')->field('ei.invoice_id')
->leftJoin(['em_payment_invoice'=>'epi'],'epi.invoice_id = ei.invoice_id')
->where('epi.payment_id','=',$payment_id)
->where('ei.payment_balance','neq',0)
->order('ei.invoice_id asc')
->select();
$invsArr = [];
//更新缴费单状态
if($invs->isEmpty()){
$payment->status = 4;
$payment->save();
return '审核成功';
} else {
foreach ($invs as $inv){
$invsArr[] = $inv->invoice_id;
}
}
//查询可消的额度
$payments_balance = (new EmInvoice)->where('invoice_id','in',$invsArr)->sum('payment_balance');
//如果可以完全销账 则继续销账
if($payment->balance > $payments_balance){
$invs = (new EmInvoice())->field('invoice_id')
->where('account_id','=',$account_id)
->where('payment_balance','neq',0)
->order('invoice_id asc')
->select();
if(!$invs->isEmpty()) {
foreach ($invs as $inv){
$invsArr[] = $inv->invoice_id;
}
}
}
$paymentIds[] = $payment->payment_id;
//处理账户金额
return $this->writeOff($paymentIds,$invsArr);
}
/**
* @param $account_id
* @param $invoiceIds
* @param $paymentIds
* @return mixed
*/
/*
private function writeOff($paymentIds,$invoiceIds){
//获取可销账缴费单
......@@ -451,7 +358,7 @@ class Invoice extends Base
$msg = $result == 0 ? '已审核,没有可销账的账单.' : '已审核,成功销账 '.$result.' 笔账单.';
return $msg;
}
*/
public function writeOffFromSettle($account_id,$settle_id){
//获取缴费单对象
$settle = EmSettle::where('settle_id','=',$settle_id)->find();
......
......@@ -232,9 +232,8 @@ class Useage extends Base
$useage->save();
//触发销账逻辑
$result = (new Invoice())->writeOffFromInvoice($inv->invoice_id,$inv->account_id);
$result = (new WriteOff())->writeOffFromInvoice($inv->invoice_id);
return json(['status'=>1,'message'=>"已审核,并生成账单,$result"]);
//return json(['status'=>1,'message'=>"已审核,并生成账单"]);
}
//获取单号
......
......@@ -60,6 +60,50 @@ class WriteOff extends Controller
return $this->writeOff($paymentIds,$invsArr);
}
/**
* 账单触发销账,invoice_id 1:n payment_id
* @param $account_id
* @param $invoice_id
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @return mixed
*/
public function writeOffFromInvoice($invoice_id){
//获取账单对象
$invoice = EmInvoice::field('id,invoice_id,payment_amount,payment_balance')
->where('invoice_id','=',$invoice_id)->find();
//查询关系表中与当前invoice_id相关联的payment_id
$model = new EmPaymentInvoice;
$payments = $model->alias('epi')->field('epi.payment_id')
->leftJoin(['em_payment'=>'ep'],'epi.payment_id = ep.payment_id')
->leftJoin(['em_payment_invoice_balance'=>'epib'],'epib.invoice_id=epi.invoice_id')
->where('epib.balance','>',0)
->where('epi.invoice_id','=',$invoice_id)->select();
//如果没有找到记录 证明并没有形成对应关系
if($payments->isEmpty()){
//查询是否有未缴费的缴费单存在
$payments = EmPayment::field('payment_id')->where('account_id','=',$invoice->account_id)
->where('balance','>',0)
->whereIn('status','3,4,5,6,8')
->order('payment_id asc')
->select();
if($payments->isEmpty()) {
return '没有销账的缴费单!';
}
}
$paymentIds = [];
foreach ($payments as $payment){
$paymentIds[] = $payment->payment_id;
}
$invsIds = [
'invoice_id' => $invoice->invoice_id
];
//开始销账
return $this->writeOff($paymentIds,$invsIds);
}
/**
* @param $account_id
* @param $invoiceIds
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论