Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
J
Jz-Php
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
PHP
Jz-Php
Commits
1accbcb3
提交
1accbcb3
authored
7月 20, 2020
作者:
chengye
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test
上级
dbaf0c2a
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
47 行增加
和
97 行删除
+47
-97
Invoice.php
application/em/controller/Invoice.php
+2
-95
Useage.php
application/em/controller/Useage.php
+1
-2
WriteOff.php
application/em/controller/WriteOff.php
+44
-0
没有找到文件。
application/em/controller/Invoice.php
浏览文件 @
1accbcb3
...
...
@@ -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
();
...
...
application/em/controller/Useage.php
浏览文件 @
1accbcb3
...
...
@@ -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'=>"已审核,并生成账单"]);
}
//获取单号
...
...
application/em/controller/WriteOff.php
浏览文件 @
1accbcb3
...
...
@@ -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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论