Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
J
Jz-Php
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
PHP
Jz-Php
Commits
84357953
提交
84357953
authored
1月 14, 2020
作者:
chengye
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test
上级
a6849155
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
140 行增加
和
557 行删除
+140
-557
workspace.xml
.idea/workspace.xml
+136
-14
Invoice.php
application/em/controller/Invoice.php
+1
-11
EmInvoice.php
application/em/model/EmInvoice.php
+3
-1
Invoice.php
application/em/view/invoice/Invoice.php
+0
-531
没有找到文件。
.idea/workspace.xml
浏览文件 @
84357953
...
...
@@ -2,7 +2,9 @@
<project
version=
"4"
>
<component
name=
"ChangeListManager"
>
<list
default=
"true"
id=
"f51c1393-9404-4c81-be85-d91ed40531b3"
name=
"默认更改列表"
comment=
""
>
<change
beforePath=
"$PROJECT_DIR$/application/em/controller/Invoice.php"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/application/em/controller/Invoice.php"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/application/em/model/EmInvoice.php"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/application/em/model/EmInvoice.php"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/application/em/view/invoice/Invoice.php"
beforeDir=
"false"
/>
</list>
<option
name=
"EXCLUDED_CONVERTED_TO_IGNORED"
value=
"true"
/>
<option
name=
"SHOW_DIALOG"
value=
"false"
/>
...
...
@@ -24,11 +26,50 @@
</provider>
</entry>
</file>
<file
pinned=
"false"
current-in-tab=
"
tru
e"
>
<file
pinned=
"false"
current-in-tab=
"
fals
e"
>
<entry
file=
"file://$PROJECT_DIR$/application/em/model/EmInvoice.php"
>
<provider
selected=
"true"
editor-type-id=
"text-editor"
>
<state
relative-caret-position=
"337"
>
<caret
line=
"65"
column=
"18"
selection-start-line=
"65"
selection-start-column=
"18"
selection-end-line=
"65"
selection-end-column=
"18"
/>
<state
relative-caret-position=
"244"
>
<caret
line=
"56"
column=
"3"
selection-start-line=
"56"
selection-start-column=
"3"
selection-end-line=
"67"
selection-end-column=
"21"
/>
</state>
</provider>
</entry>
</file>
<file
pinned=
"false"
current-in-tab=
"false"
>
<entry
file=
"file://$PROJECT_DIR$/thinkphp/library/think/db/Query.php"
>
<provider
selected=
"true"
editor-type-id=
"text-editor"
>
<state
relative-caret-position=
"495"
>
<caret
line=
"655"
column=
"45"
selection-start-line=
"655"
selection-start-column=
"40"
selection-end-line=
"655"
selection-end-column=
"45"
/>
</state>
</provider>
</entry>
</file>
<file
pinned=
"false"
current-in-tab=
"false"
>
<entry
file=
"file://$PROJECT_DIR$/application/em/view/invoice/index.html"
>
<provider
selected=
"true"
editor-type-id=
"text-editor"
>
<state
relative-caret-position=
"208"
>
<caret
line=
"42"
column=
"92"
selection-start-line=
"42"
selection-start-column=
"84"
selection-end-line=
"42"
selection-end-column=
"92"
/>
<folding>
<element
signature=
"n#style#0;n#input#0;n#div#1;n#form#0;n#div#0;n#div#0;n#div#0;n#div#0;n#div#0;n#!!top"
expanded=
"true"
/>
</folding>
</state>
</provider>
</entry>
</file>
<file
pinned=
"false"
current-in-tab=
"false"
>
<entry
file=
"file://$PROJECT_DIR$/route/admin.php"
>
<provider
selected=
"true"
editor-type-id=
"text-editor"
>
<state
relative-caret-position=
"291"
>
<caret
line=
"149"
column=
"32"
selection-start-line=
"149"
selection-start-column=
"25"
selection-end-line=
"149"
selection-end-column=
"32"
/>
</state>
</provider>
</entry>
</file>
<file
pinned=
"false"
current-in-tab=
"true"
>
<entry
file=
"file://$PROJECT_DIR$/application/em/controller/Invoice.php"
>
<provider
selected=
"true"
editor-type-id=
"text-editor"
>
<state
relative-caret-position=
"310"
>
<caret
line=
"67"
column=
"52"
selection-start-line=
"67"
selection-start-column=
"52"
selection-end-line=
"67"
selection-end-column=
"52"
/>
</state>
</provider>
</entry>
...
...
@@ -57,6 +98,7 @@
<findStrings>
<find>
last_date
</find>
<find>
$sm
</find>
<find>
/invoice
</find>
</findStrings>
</component>
<component
name=
"Git.Settings"
>
...
...
@@ -68,6 +110,7 @@
<option
value=
"$PROJECT_DIR$/application/em/view/useage/special.html"
/>
<option
value=
"$PROJECT_DIR$/.gitignore"
/>
<option
value=
"$PROJECT_DIR$/application/em/model/EmInvoice.php"
/>
<option
value=
"$PROJECT_DIR$/application/em/controller/Invoice.php"
/>
</list>
</option>
</component>
...
...
@@ -83,18 +126,66 @@
</include_path>
</component>
<component
name=
"ProjectFrameBounds"
extendedState=
"6"
>
<option
name=
"x"
value=
"
170
"
/>
<option
name=
"y"
value=
"
91
"
/>
<option
name=
"x"
value=
"
2227
"
/>
<option
name=
"y"
value=
"
188
"
/>
<option
name=
"width"
value=
"1026"
/>
<option
name=
"height"
value=
"546"
/>
</component>
<component
name=
"ProjectView"
>
<navigator
proportions=
""
version=
"1"
>
<navigator
currentView=
"Scope"
currentSubView=
"Scope 'Project Files'; set:Project Files; class com.intellij.psi.search.scope.ProjectFilesScope"
proportions=
""
version=
"1"
>
<foldersAlwaysOnTop
value=
"true"
/>
</navigator>
<panes>
<pane
id=
"ProjectPane"
/>
<pane
id=
"Scope"
/>
<pane
id=
"Scope"
>
<subPane
subId=
"Scope 'Project Files'; set:Project Files; class com.intellij.psi.search.scope.ProjectFilesScope"
>
<expand>
<path>
<item
name=
"Jz-Php"
type=
"3d21c010:ScopeViewTreeModel$ProjectNode"
/>
<item
name=
"E:\master\Jz-Php"
type=
"442cc68d:ScopeViewTreeModel$RootNode"
/>
</path>
<path>
<item
name=
"Jz-Php"
type=
"3d21c010:ScopeViewTreeModel$ProjectNode"
/>
<item
name=
"E:\master\Jz-Php"
type=
"442cc68d:ScopeViewTreeModel$RootNode"
/>
<item
name=
"application"
type=
"9f88c78c:ScopeViewTreeModel$FileNode"
/>
</path>
<path>
<item
name=
"Jz-Php"
type=
"3d21c010:ScopeViewTreeModel$ProjectNode"
/>
<item
name=
"E:\master\Jz-Php"
type=
"442cc68d:ScopeViewTreeModel$RootNode"
/>
<item
name=
"application"
type=
"9f88c78c:ScopeViewTreeModel$FileNode"
/>
<item
name=
"em"
type=
"9f88c78c:ScopeViewTreeModel$FileNode"
/>
</path>
<path>
<item
name=
"Jz-Php"
type=
"3d21c010:ScopeViewTreeModel$ProjectNode"
/>
<item
name=
"E:\master\Jz-Php"
type=
"442cc68d:ScopeViewTreeModel$RootNode"
/>
<item
name=
"application"
type=
"9f88c78c:ScopeViewTreeModel$FileNode"
/>
<item
name=
"em"
type=
"9f88c78c:ScopeViewTreeModel$FileNode"
/>
<item
name=
"controller"
type=
"9f88c78c:ScopeViewTreeModel$FileNode"
/>
</path>
<path>
<item
name=
"Jz-Php"
type=
"3d21c010:ScopeViewTreeModel$ProjectNode"
/>
<item
name=
"E:\master\Jz-Php"
type=
"442cc68d:ScopeViewTreeModel$RootNode"
/>
<item
name=
"application"
type=
"9f88c78c:ScopeViewTreeModel$FileNode"
/>
<item
name=
"em"
type=
"9f88c78c:ScopeViewTreeModel$FileNode"
/>
<item
name=
"view"
type=
"9f88c78c:ScopeViewTreeModel$FileNode"
/>
</path>
<path>
<item
name=
"Jz-Php"
type=
"3d21c010:ScopeViewTreeModel$ProjectNode"
/>
<item
name=
"E:\master\Jz-Php"
type=
"442cc68d:ScopeViewTreeModel$RootNode"
/>
<item
name=
"application"
type=
"9f88c78c:ScopeViewTreeModel$FileNode"
/>
<item
name=
"em"
type=
"9f88c78c:ScopeViewTreeModel$FileNode"
/>
<item
name=
"view"
type=
"9f88c78c:ScopeViewTreeModel$FileNode"
/>
<item
name=
"invoice"
type=
"9f88c78c:ScopeViewTreeModel$FileNode"
/>
</path>
<path>
<item
name=
"Jz-Php"
type=
"3d21c010:ScopeViewTreeModel$ProjectNode"
/>
<item
name=
"E:\master\Jz-Php"
type=
"442cc68d:ScopeViewTreeModel$RootNode"
/>
<item
name=
"route"
type=
"9f88c78c:ScopeViewTreeModel$FileNode"
/>
</path>
</expand>
<select
/>
</subPane>
</pane>
</panes>
</component>
<component
name=
"PropertiesComponent"
>
...
...
@@ -130,18 +221,18 @@
<workItem
from=
"1578817951649"
duration=
"618000"
/>
<workItem
from=
"1578900535997"
duration=
"5097000"
/>
<workItem
from=
"1578907167448"
duration=
"144000"
/>
<workItem
from=
"1578972376079"
duration=
"
1216
000"
/>
<workItem
from=
"1578972376079"
duration=
"
3459
000"
/>
</task>
<servers
/>
</component>
<component
name=
"TimeTrackingManager"
>
<option
name=
"totallyTimeSpent"
value=
"
7163
000"
/>
<option
name=
"totallyTimeSpent"
value=
"
9406
000"
/>
</component>
<component
name=
"ToolWindowManager"
>
<frame
x=
"
-8"
y=
"-8"
width=
"1382"
height=
"744
"
extended-state=
"6"
/>
<frame
x=
"
1358"
y=
"-125"
width=
"1936"
height=
"1056
"
extended-state=
"6"
/>
<editor
active=
"true"
/>
<layout>
<window_info
content_ui=
"combo"
id=
"Project"
order=
"0"
visible=
"true"
weight=
"0.260574
"
/>
<window_info
active=
"true"
content_ui=
"combo"
id=
"Project"
order=
"0"
visible=
"true"
weight=
"0.1512247
"
/>
<window_info
id=
"Structure"
order=
"1"
side_tool=
"true"
weight=
"0.25"
/>
<window_info
id=
"Favorites"
order=
"2"
side_tool=
"true"
/>
<window_info
anchor=
"bottom"
id=
"Message"
order=
"0"
/>
...
...
@@ -154,7 +245,7 @@
<window_info
anchor=
"bottom"
id=
"Docker"
order=
"7"
show_stripe_button=
"false"
/>
<window_info
anchor=
"bottom"
id=
"Database Changes"
order=
"8"
/>
<window_info
anchor=
"bottom"
id=
"Version Control"
order=
"9"
/>
<window_info
a
ctive=
"true"
anchor=
"bottom"
id=
"Terminal"
order=
"10"
visible=
"true"
weight=
"0.20888157
"
/>
<window_info
a
nchor=
"bottom"
id=
"Terminal"
order=
"10"
visible=
"true"
weight=
"0.051086955
"
/>
<window_info
anchor=
"bottom"
id=
"Event Log"
order=
"11"
side_tool=
"true"
/>
<window_info
anchor=
"right"
id=
"Commander"
internal_type=
"SLIDING"
order=
"0"
type=
"SLIDING"
weight=
"0.4"
/>
<window_info
anchor=
"right"
id=
"Ant Build"
order=
"1"
weight=
"0.25"
/>
...
...
@@ -375,10 +466,41 @@
</state>
</provider>
</entry>
<entry
file=
"file://$PROJECT_DIR$/application/em/view/invoice/index.html"
>
<provider
selected=
"true"
editor-type-id=
"text-editor"
>
<state
relative-caret-position=
"208"
>
<caret
line=
"42"
column=
"92"
selection-start-line=
"42"
selection-start-column=
"84"
selection-end-line=
"42"
selection-end-column=
"92"
/>
<folding>
<element
signature=
"n#style#0;n#input#0;n#div#1;n#form#0;n#div#0;n#div#0;n#div#0;n#div#0;n#div#0;n#!!top"
expanded=
"true"
/>
</folding>
</state>
</provider>
</entry>
<entry
file=
"file://$PROJECT_DIR$/route/admin.php"
>
<provider
selected=
"true"
editor-type-id=
"text-editor"
>
<state
relative-caret-position=
"291"
>
<caret
line=
"149"
column=
"32"
selection-start-line=
"149"
selection-start-column=
"25"
selection-end-line=
"149"
selection-end-column=
"32"
/>
</state>
</provider>
</entry>
<entry
file=
"file://$PROJECT_DIR$/thinkphp/library/think/db/Query.php"
>
<provider
selected=
"true"
editor-type-id=
"text-editor"
>
<state
relative-caret-position=
"495"
>
<caret
line=
"655"
column=
"45"
selection-start-line=
"655"
selection-start-column=
"40"
selection-end-line=
"655"
selection-end-column=
"45"
/>
</state>
</provider>
</entry>
<entry
file=
"file://$PROJECT_DIR$/application/em/model/EmInvoice.php"
>
<provider
selected=
"true"
editor-type-id=
"text-editor"
>
<state
relative-caret-position=
"337"
>
<caret
line=
"65"
column=
"18"
selection-start-line=
"65"
selection-start-column=
"18"
selection-end-line=
"65"
selection-end-column=
"18"
/>
<state
relative-caret-position=
"244"
>
<caret
line=
"56"
column=
"3"
selection-start-line=
"56"
selection-start-column=
"3"
selection-end-line=
"67"
selection-end-column=
"21"
/>
</state>
</provider>
</entry>
<entry
file=
"file://$PROJECT_DIR$/application/em/controller/Invoice.php"
>
<provider
selected=
"true"
editor-type-id=
"text-editor"
>
<state
relative-caret-position=
"310"
>
<caret
line=
"67"
column=
"52"
selection-start-line=
"67"
selection-start-column=
"52"
selection-end-line=
"67"
selection-end-column=
"52"
/>
</state>
</provider>
</entry>
...
...
application/em/controller/Invoice.php
浏览文件 @
84357953
...
...
@@ -65,21 +65,11 @@ class Invoice extends Base
}
$InvoiceCount
=
(
new
EmInvoice
)
->
getInvoiceCount
(
$map
);
if
(
Request
::
param
(
'page'
)){
return
[
'code'
=>
0
,
'msg'
=>
''
,
'count'
=>
$InvoiceCount
,
'data'
=>
$data
];
return
[
'code'
=>
0
,
'msg'
=>
''
,
'count'
=>
100
,
'data'
=>
$data
];
}
return
$this
->
fetch
();
// $data = (new EmInvoice)->getList();
//
// $page = $data->render();
//
// $this->assign('data',$data);
// $this->assign('page',$page);
// return $this->fetch();
}
//查看账单信息
...
...
application/em/model/EmInvoice.php
浏览文件 @
84357953
...
...
@@ -57,13 +57,15 @@ class EmInvoice extends Base
public
function
getInvoiceCount
(
$map
){
$data
=
self
::
alias
(
'inv'
)
->
field
(
'inv.*'
)
->
field
(
'station.station_name'
)
->
field
(
'em.em_numb'
)
->
leftJoin
([
'em_invoice_useage'
=>
'eiu'
],
'eiu.invoice_id=inv.invoice_id'
)
->
leftJoin
([
'em_useage'
=>
'eu'
],
'eu.useage_id = eiu.useage_id'
)
->
leftJoin
([
'em'
],
'em.id=eu.em_id'
)
->
leftJoin
([
'station_info'
=>
'station'
],
'station.station_id=em.station_id'
)
->
where
(
$map
)
->
count
();
return
100
;
return
$data
;
}
//通过invoice_id查询列表数据
public
function
getListByInvIds
(
$ids
){
...
...
application/em/view/invoice/Invoice.php
deleted
100755 → 0
浏览文件 @
a6849155
<?php
/**
* v2 账单模块
*/
namespace
app\em\controller
;
use
app\admin\controller\Base
;
use
app\em\model\EmInvoice
;
use
app\em\model\EmInvoiceHistory
;
use
app\em\model\EmInvoiceUseage
;
use
app\em\model\EmPayment
;
use
app\em\model\EmPaymentHistory
;
use
app\em\model\EmPaymentInvoice
;
use
app\em\model\EmPaymentInvoiceBalance
;
use
app\em\model\EmSettle
;
use
app\em\model\EmSettleInvoice
;
use
app\em\model\EmSettleInvoiceBalance
;
use
app\em\model\UseageDetail
;
use
think\facade\Request
;
class
Invoice
extends
Base
{
//账单列表
public
function
index
(){
$data
=
(
new
EmInvoice
)
->
getList
();
$page
=
$data
->
render
();
$this
->
assign
(
'data'
,
$data
);
$this
->
assign
(
'page'
,
$page
);
return
$this
->
fetch
();
}
//查看账单信息
public
function
detail
(){
$inv_id
=
Request
::
param
(
'id'
);
$invInfo
=
(
new
EmInvoice
)
->
getInvoiceDetail
(
$inv_id
);
$this
->
assign
(
'inv'
,
$invInfo
);
return
$this
->
fetch
();
}
//创建一个账单
public
function
createInvoice
(
$useage_id
){
$um
=
(
new
\app\em\model\Useage
)
->
getEmInfoByUseageId
(
$useage_id
)
->
toArray
();
return
$this
->
create
(
$um
);
}
//创建账单
public
function
create
(
$um
){
/// 如果是普通表 则
if
(
$um
[
'pricing_type'
]
==
1
){
return
$this
->
createInvoiceStdType
(
$um
);
}
else
if
(
$um
[
'pricing_type'
]
==
2
){
return
$this
->
createInvoiceSpecialType
(
$um
);
}
}
/**
* 生成账单号
* @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
private
function
getInvoiceId
(){
$inv
=
EmInvoice
::
field
(
'id'
)
->
order
(
'id desc,create_time desc'
)
->
find
();
if
(
!
$inv
)
$id
=
1
;
else
$id
=
$inv
->
id
+
1
;
return
"ZD"
.
date
(
'Ymd'
)
.
zero
(
$id
);
}
//普通读表生成账单
public
function
createInvoiceStdType
(
$uData
){
$inv
=
new
EmInvoice
();
$inv
->
type
=
4
;
$inv
->
rate
=
$uData
[
'rate'
];
$inv
->
repo_numb
=
(
$uData
[
'current_sum_numb'
]
-
$uData
[
'last_sum_numb'
])
*
$uData
[
'rate'
];
$inv
->
payment_amount
=
$inv
->
payment_balance
=
$inv
->
repo_numb
*
$uData
[
'pay_price'
];
//结算信息
$inv
->
settle_amount
=
$inv
->
settle_balance
=
$inv
->
repo_numb
*
$uData
[
'settle_price'
];
$inv
->
status
=
'000'
;
$inv
->
invoice_id
=
$this
->
getInvoiceId
();
//获取账户ID
$inv
->
account_id
=
(
new
Account
())
->
getAccountId
(
$uData
[
'em_id'
]);
//保存 并且更新抄表单与账单关联表
if
(
$inv
->
save
()){
$eiu
=
new
EmInvoiceUseage
();
$eiu
->
invoice_id
=
$inv
->
invoice_id
;
$eiu
->
useage_id
=
$uData
[
'useage_id'
];
$eiu
->
save
();
}
//更新电表账户
$useage
=
\app\em\model\Useage
::
get
([
'useage_id'
=>
$uData
[
'useage_id'
]]);
$account
=
new
Account
();
$account
->
updateAmount
(
$useage
->
em_id
,
$inv
->
payment_amount
,
0
);
return
$inv
;
}
//峰谷表生成账单
public
function
createInvoiceSpecialType
(
$uData
){
$inv
=
new
EmInvoice
();
$inv
->
type
=
1
;
$inv
->
rate
=
$uData
[
'rate'
];
//获取峰谷表抄表明细
$uds
=
UseageDetail
::
where
([
'useage_id'
=>
$uData
[
'useage_id'
]])
->
select
()
->
toArray
();
//计算总价信息
//需要计算4个属性 各分段上一次 档次 repo amount
$last_numb
=
0
;
$curr_numb
=
0
;
$amount
=
0
;
$repo_numb
=
0
;
foreach
(
$uds
as
$v
){
$last_numb
+=
$v
[
'last_numb'
];
$curr_numb
+=
$v
[
'current_numb'
];
$amount
+=
(
int
)(
$v
[
'current_numb'
]
-
$v
[
'last_numb'
])
*
$v
[
'price'
];
$repo_numb
+=
(
int
)(
$v
[
'current_numb'
]
-
$v
[
'last_numb'
]);
}
//曝移动电量
$inv
->
repo_numb
=
(
$curr_numb
-
$last_numb
)
*
$uData
[
'rate'
];
//缴费信息
$inv
->
payment_amount
=
$inv
->
payment_balance
=
$amount
*
$uData
[
'rate'
];
//结算信息
$inv
->
settle_amount
=
$inv
->
settle_balance
=
$repo_numb
*
$uData
[
'settle_price'
];
$inv
->
status
=
'000'
;
$inv
->
invoice_id
=
$this
->
getInvoiceId
();
$inv
->
account_id
=
(
new
Account
())
->
getAccountId
(
$uData
[
'em_id'
]);
//更新抄表单的status
$useage
=
\app\em\model\Useage
::
get
([
'useage_id'
=>
$uData
[
'useage_id'
]]);
$useage
->
status
=
2
;
$useage
->
save
();
$inv
->
cert_id
=
$useage
->
photo_id
;
//保存 并且更新抄表单与账单关联表
if
(
$inv
->
save
()){
$eiu
=
new
EmInvoiceUseage
();
$eiu
->
invoice_id
=
$inv
->
invoice_id
;
$eiu
->
useage_id
=
$uData
[
'useage_id'
];
$eiu
->
save
();
}
return
$inv
;
}
public
function
updatePayment
(){
$data
=
Request
::
param
();
$inv
=
EmInvoice
::
get
([
'id'
=>
$data
[
'id'
]]);
if
(
!
$inv
)
return
json
([
'status'
=>
0
,
'message'
=>
'不存在抄表单ID,无法更新缴费金额'
]);
if
(
$data
[
'amount'
]
>
0
&&
$inv
->
is_add_condition
!=
1
){
$inv
->
payment_amount
=
$data
[
'amount'
];
$inv
->
payment_balance
=
$data
[
'amount'
];
$inv
->
is_add_condition
=
1
;
}
if
(
$inv
->
save
()){
return
json
([
'status'
=>
1
,
'message'
=>
'缴费金额已经更新'
]);
}
}
//账单合并列表
public
function
mergeList
(){
$ids
=
Request
::
param
(
'ids'
);
$idsArr
=
[];
if
(
!
empty
(
$ids
)){
$idsArr
=
explode
(
'_'
,
$ids
);
}
$data
=
(
new
EmInvoice
)
->
getListByInvIds
(
$idsArr
);
$payment_amount
=
0
;
$settle_amount
=
0
;
foreach
(
$data
as
$v
){
$payment_amount
+=
$v
->
payment_amount
;
$settle_amount
+=
$v
->
settle_amount
;
}
$this
->
assign
(
'data'
,
$data
);
$this
->
assign
(
'payment_amount'
,
$payment_amount
);
$this
->
assign
(
'settle_amount'
,
$settle_amount
);
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
){
$paymentIdsArr
=
[];
//获取账单对象
$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()) return '账单未缴费';
//如果没有找到挂起的账单,则找相同账户下的缴费单
$associate
=
false
;
if
(
$payments
->
isEmpty
()){
$payments
=
(
new
EmPayment
())
->
field
(
'payment_id'
)
->
where
(
'account_id'
,
'='
,
$account_id
)
->
where
(
'balance'
,
'gt'
,
0
)
->
order
(
'id asc,create_time asc'
)
->
select
();
if
(
$payments
->
isEmpty
())
return
'账单未缴费'
;
else
$associate
=
true
;
}
//$paymentIdsArr = $payments->toArray();
foreach
(
$payments
as
$p
){
$paymentIdsArr
[]
=
$p
[
'payment_id'
];
}
//查询可消的额度
$payments_balance
=
(
new
EmPayment
)
->
where
(
'payment_id'
,
'in'
,
$paymentIdsArr
)
->
sum
(
'balance'
);
//如果该账单可以完全被缴费单销账
if
(
$payments_balance
<
$invoice
->
payment_balance
){
$payments
=
EmPayment
::
field
(
'payment_id'
)
->
where
(
'account_id'
,
'='
,
$account_id
)
->
where
(
'balance'
,
'neq'
,
0
)
->
order
(
'payment_id asc'
)
->
select
();
if
(
!
$payments
->
isEmpty
())
foreach
(
$payments
as
$payment
){
$paymentIdsArr
[]
=
$payment
->
payment_id
;
}
}
$paymentIds
=
$paymentIdsArr
;
$invsIds
[]
=
$invoice
->
invoice_id
;
//开始销账
return
$this
->
writeOff
(
$paymentIds
,
$invsIds
,
$associate
);
}
//从缴费单消账单
public
function
writeOffFromPayment
(
$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
())
{
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
,
true
);
}
public
function
writeOffFromSettle
(
$account_id
,
$settle_id
){
//获取缴费单对象
$settle
=
EmSettle
::
where
(
'settle_id'
,
'='
,
$settle_id
)
->
find
();
//获取关联的账单对象
$invs
=
(
new
EmInvoice
())
->
alias
(
'ei'
)
->
field
(
'ei.invoice_id'
)
->
leftJoin
([
'em_settle_invoice'
=>
'esi'
],
'esi.invoice_id = ei.invoice_id'
)
->
where
(
'esi.settle_id'
,
'='
,
$settle_id
)
->
where
(
'ei.settle_balance'
,
'neq'
,
0
)
->
order
(
'ei.invoice_id asc'
)
->
select
();
$invsArr
=
[];
if
(
!
$invs
->
isEmpty
())
{
foreach
(
$invs
as
$inv
){
$invsArr
[]
=
$inv
->
invoice_id
;
}
}
//查询可消的额度
$settles_balance
=
(
new
EmInvoice
)
->
where
(
'invoice_id'
,
'in'
,
$invsArr
)
->
sum
(
'settle_balance'
);
//如果可以完全销账 则继续销账
if
(
$settle
->
balance
>
$settles_balance
){
$invs
=
(
new
EmInvoice
())
->
field
(
'invoice_id'
)
->
where
(
'account_id'
,
'='
,
$account_id
)
->
where
(
'settle_balance'
,
'neq'
,
0
)
->
order
(
'invoice_id asc'
)
->
select
();
if
(
!
$invs
->
isEmpty
())
{
foreach
(
$invs
as
$inv
){
$invsArr
[]
=
$inv
->
invoice_id
;
}
}
}
$settleIds
[]
=
$settle
->
settle_id
;
//处理账户金额
return
$this
->
writeOffSettle
(
$settleIds
,
$invsArr
);
}
/**
* 销账逻辑,并选择是否构建关联关系
* @param $paymentIds
* @param $invoiceIds
* @param bool $associate
* @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
private
function
writeOff
(
$paymentIds
,
$invoiceIds
,
$associate
=
false
){
//获取可销账缴费单
$payments
=
EmPayment
::
where
(
'payment_id'
,
'in'
,
$paymentIds
)
->
select
();
//获取可销账账单
$invs
=
EmInvoice
::
where
(
'invoice_id'
,
'in'
,
$invoiceIds
)
->
select
();
$result
=
0
;
foreach
(
$payments
as
$key
=>
$payment
){
if
(
$payment
->
balance
==
0
)
continue
;
foreach
(
$invs
as
$index
=>
$inv
)
{
$balanceMode
=
new
EmPaymentInvoiceBalance
();
$balanceMode
->
payment_id
=
$payment
->
payment_id
;
if
(
$inv
->
payment_balance
==
0
)
continue
;
$balanceMode
->
invoice_id
=
$inv
->
invoice_id
;
//如果该缴费单可以完全消除当前账单额度
if
(
$payment
->
balance
>=
$inv
->
payment_balance
)
{
//单笔销账多少
$balanceMode
->
balance
=
$inv
->
payment_balance
;
//缴费额度变化
if
((
$payment
->
balance
-
$inv
->
payment_balance
)
==
0
){
$payment
->
status
=
2
;
}
else
{
$payment
->
status
=
1
;
//缴费部分销账
}
$payment
->
balance
=
$payment
->
balance
-
$inv
->
payment_balance
;
//账单额度变化
$inv
->
payment_balance
=
0
;
//更新账户status 首字母 = 2
$inv
->
status
=
setInvoiceStatus
(
$inv
->
status
,
2
);
}
else
{
//单笔销账多少
$balanceMode
->
balance
=
$payment
->
balance
;
//账单额度变化
$inv
->
status
=
setInvoiceStatus
(
$inv
->
status
,
1
);
$inv
->
payment_balance
=
$inv
->
payment_balance
-
$payment
->
balance
;
//缴费额度变化
$payment
->
balance
=
0
;
$payment
->
status
=
2
;
//缴费已经完全销账
}
//关联关系
if
(
$associate
==
true
){
$model
=
new
EmPaymentInvoice
();
$data
[
'payment_id'
]
=
$payment
->
payment_id
;
$data
[
'invoice_id'
]
=
$inv
->
invoice_id
;
$mod
=
$model
->
where
(
$data
)
->
find
();
if
(
!
$mod
){
$model
->
payment_id
=
$payment
->
payment_id
;
$model
->
invoice_id
=
$inv
->
invoice_id
;
$model
->
save
();
}
}
$result
++
;
//更新账单状态
$inv
->
save
();
//todo::history; 保存历史记录
$invData
=
$inv
->
toArray
();
$invData
[
'id'
]
=
null
;
$invData
[
'create_time'
]
=
strtotime
(
$invData
[
'create_time'
]);
$invData
[
'update_time'
]
=
strtotime
(
$invData
[
'update_time'
]);
//EmInvoiceHistory::create($invData);
unset
(
$invs
[
$index
]);
//从结果集中去掉无效的数据
//更新状态
$payment
->
save
();
//todo::history;保存历史记录
$payData
=
$payment
->
toArray
();
$payData
[
'id'
]
=
null
;
$payData
[
'create_time'
]
=
strtotime
(
$payData
[
'create_time'
]);
$payData
[
'update_time'
]
=
strtotime
(
$payData
[
'update_time'
]);
$payData
[
'pay_date'
]
=
strtotime
(
$payData
[
'pay_date'
]);
//EmPaymentHistory::create($payData);
unset
(
$payments
[
$key
]);
$balanceMode
->
isUpdate
(
false
)
->
save
();
}
}
$msg
=
$result
==
0
?
'已审核,没有可销账的账单.'
:
'已审核,成功销账 '
.
$result
.
' 笔账单.'
;
return
$msg
;
}
private
function
writeOffSettle
(
$settleIds
,
$invoiceIds
,
$associate
=
false
){
//获取可销账结算单
$settles
=
EmSettle
::
where
(
'settle_id'
,
'in'
,
$settleIds
)
->
select
();
//获取可销账账单
$invs
=
EmInvoice
::
where
(
'invoice_id'
,
'in'
,
$invoiceIds
)
->
select
();
$result
=
0
;
foreach
(
$settles
as
$key
=>
$settle
){
if
(
$settle
->
balance
==
0
)
continue
;
foreach
(
$invs
as
$index
=>
$inv
)
{
$balanceMode
=
new
EmSettleInvoiceBalance
();
$balanceMode
->
settle_id
=
$settle
->
settle_id
;
if
(
$inv
->
settle_balance
==
0
)
continue
;
$balanceMode
->
invoice_id
=
$inv
->
invoice_id
;
//如果该结算单可以完全消除当前账单额度
if
(
$settle
->
balance
>=
$inv
->
settle_balance
)
{
//单笔销账多少
$balanceMode
->
balance
=
$inv
->
settle_balance
;
//结算额度变化
if
((
$settle
->
balance
-
$inv
->
settle_balance
)
==
0
){
$settle
->
status
=
2
;
}
else
{
$settle
->
status
=
1
;
//结算部分销账
}
$settle
->
balance
=
$settle
->
balance
-
$inv
->
settle_balance
;
//账单额度变化
$inv
->
settle_balance
=
0
;
//更新账户status 首字母 = 2
$inv
->
status
=
setInvoiceStatus
(
$inv
->
status
,
2
,
1
);
}
else
{
//单笔销账多少
$balanceMode
->
balance
=
$settle
->
balance
;
//账单额度变化
$inv
->
status
=
setInvoiceStatus
(
$inv
->
status
,
1
,
1
);
$inv
->
settle_balance
=
$inv
->
settle_balance
-
$settle
->
balance
;
//结算额度变化
$settle
->
balance
=
0
;
$settle
->
status
=
2
;
//结算已经完全销账
}
if
(
$associate
==
true
){
$model
=
new
EmSettleInvoice
();
$model
->
settle_id
=
$settle
->
settle_id
;
$model
->
invoice_id
=
$inv
->
invoice_id
;
$model
->
save
();
}
$result
++
;
//更新账单状态
$inv
->
save
();
//todo::history; 保存历史记录
$invData
=
$inv
->
toArray
();
$invData
[
'id'
]
=
null
;
$invData
[
'create_time'
]
=
strtotime
(
$invData
[
'create_time'
]);
$invData
[
'update_time'
]
=
strtotime
(
$invData
[
'update_time'
]);
//EmInvoiceHistory::create($invData);
unset
(
$invs
[
$index
]);
//从结果集中去掉无效的数据
//更新状态
$settle
->
save
();
//todo::history;保存历史记录
$payData
=
$settle
->
toArray
();
$payData
[
'id'
]
=
null
;
$payData
[
'create_time'
]
=
strtotime
(
$payData
[
'create_time'
]);
$payData
[
'update_time'
]
=
strtotime
(
$payData
[
'update_time'
]);
$payData
[
'settle_date'
]
=
strtotime
(
$payData
[
'settle_date'
]);
//EmSettleHistory::create($payData);
unset
(
$settles
[
$key
]);
$balanceMode
->
isUpdate
(
false
)
->
save
();
}
}
$msg
=
$result
==
0
?
'没有结算成功'
:
'成功结算: '
.
$result
.
'笔'
;
return
$msg
;
}
}
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论