Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
J
Jz-Php
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
PHP
Jz-Php
Commits
a70cbfe9
提交
a70cbfe9
authored
4月 26, 2020
作者:
chengye
提交者:
wangkr
4月 29, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
完成update 方法
上级
cc440ac8
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
77 行增加
和
34 行删除
+77
-34
Useage.php
application/em/controller/Useage.php
+77
-34
Useage.php.bak
application/em/controller/Useage.php.bak
+0
-0
没有找到文件。
application/em/controller/Useage.php
浏览文件 @
a70cbfe9
...
...
@@ -8,6 +8,7 @@ use app\em\model\Staff;
use
app\em\model\Station
;
use
app\em\model\UseageDetail
;
use
app\em\validate\UseageGeneralInfoValidate
;
use
think\Db
;
use
think\facade\Request
;
use
think\facade\Session
;
...
...
@@ -118,9 +119,11 @@ class Useage extends Base
}
//保存抄表单
public
function
store
(){
public
function
store
(
$useage_id
=
''
){
//获取表单数据
$data
=
Request
::
post
();
$action
=
'新增'
;
//数据验证
$validate
=
new
UseageGeneralInfoValidate
();
//根据计量模式 验证去表单数据
...
...
@@ -129,25 +132,46 @@ class Useage extends Base
}
//获取电表基本信息
$em
=
(
new
\app\em\model\Em
)
->
getEmInfoById
([
'id'
=>
$data
[
'em_id'
]],
'rule'
);
//保存抄表单
$uModel
=
new
\app\em\model\Useage
();
//生成抄表单ID
$data
[
'useage_id'
]
=
$this
->
getUId
();
$data
[
'last_sum_numb'
]
=
$data
[
'last_numb'
];
$data
[
'current_sum_numb'
]
=
$data
[
'current_numb'
];
//保存用户ID
$user
=
Session
::
get
(
'user'
);
$data
[
'uid'
]
=
$user
[
'user_id'
];
//峰谷类型
$data
[
'type'
]
=
$data
[
'pricing_type'
];
if
(
empty
(
$useage_id
))
{
$uModel
=
new
\app\em\model\Useage
();
$uModel
->
useage_id
=
$this
->
getUId
();
$user
=
Session
::
get
(
'user'
);
$uModel
->
uid
=
$user
[
'user_id'
];
$uModel
->
last_sum_numb
=
$data
[
'last_numb'
];
$uModel
->
last_date
=
$data
[
'last_date'
];
$uModel
->
em_id
=
$data
[
'em_id'
];
//峰谷类型
$uModel
->
type
=
$data
[
'pricing_type'
];
}
else
{
$this
->
checkEnd
(
$useage_id
);
$action
=
'修改'
;
$uModel
=
(
new
\app\em\model\Useage
())
->
get
([
'useage_id'
=>
$useage_id
]);
}
//更新
$uModel
->
staff_id
=
$data
[
'staff_id'
];
$uModel
->
current_date
=
$data
[
'current_date'
];
$uModel
->
current_sum_numb
=
$data
[
'current_numb'
];
$uModel
->
photo_id
=
$data
[
'photo_id'
];
//单价
$data
[
'price'
]
=
$data
[
'pricing_type'
]
==
1
?
$em
->
rule
->
pay_price
:
$data
[
'price'
];
$uModel
->
save
(
$data
);
//保存抄表记录
$uModel
->
price
=
$data
[
'pricing_type'
]
==
1
?
$em
->
rule
->
pay_price
:
$data
[
'price'
];
$uModel
->
save
();
//保存抄表记录
if
(
empty
(
$useage_id
)){
$udModel
=
new
UseageDetail
();
//抄表详情模型
$udModel
->
type
=
$data
[
'type'
]
==
1
?
5
:
6
;
$uModel
->
current_numb
=
$data
[
'current_numb'
];
$uModel
->
last_numb
=
$data
[
'last_numb'
];
}
else
{
$udModel
=
(
new
UseageDetail
())
->
get
([
'useage_id'
=>
$useage_id
]);;
//抄表详情模型
}
$udModel
->
current_numb
=
$data
[
'current_numb'
];
$udModel
->
price
=
$uModel
->
price
;
$data
[
'type'
]
=
$data
[
'type'
]
==
1
?
5
:
6
;
$udModel
=
new
UseageDetail
();
//抄表详情模型
$udModel
->
save
(
$data
);
return
json
([
'status'
=>
1
,
'message'
=>
'添加抄表记录成功'
]);
$udModel
->
save
();
return
json
([
'status'
=>
1
,
'message'
=>
$action
.
'抄表记录成功'
]);
}
/**
...
...
@@ -210,30 +234,48 @@ class Useage extends Base
$useage
->
repo_numb
=
round
(
round
(
$useage
->
current_sum_numb
-
$useage
->
last_sum_numb
,
2
)
*
$useage
->
rate
,
2
);
$this
->
assign
(
'em'
,
$em
);
$this
->
assign
(
'useage'
,
$useage
);
return
$this
->
fetch
(
'detail'
);
}
public
function
del
(){
$uid
=
Request
::
param
(
'uid'
);
$useage_id
=
Request
::
param
(
'uid'
);
$this
->
checkEnd
(
$useage_id
);
$useage
=
(
new
\app\em\model\Useage
())
->
get
([
'useage_id'
=>
$useage_id
]);
$useage_details
=
(
new
UseageDetail
())
->
select
([
'useage_id'
=>
$useage_id
]);
$useage
=
(
new
\app\em\model\Useage
())
->
get
([
'useage_id'
=>
$uid
]);
$useage_details
=
(
new
UseageDetail
())
->
select
([
'useage_id'
=>
$uid
]);
if
(
!
$useage
){
return
json
([
'status'
=>
0
,
'message'
=>
"删除异常,未找到单据编号,请联系管理员"
]);
}
if
(
$useage
->
delete
()){
if
(
!
$useage_details
->
isEmpty
()){
foreach
(
$useage_details
as
$k
=>
$v
){
unset
(
$useage_details
[
$k
]);
}
}
Db
::
startTrans
();
try
{
$useage
->
delete
();
$useage_details
->
delete
();
Db
::
commit
();
return
json
([
'status'
=>
1
,
'message'
=>
"删除单据成功"
]);
}
{
}
catch
(
\Exception
$e
)
{
// 回滚事务
Db
::
rollback
();
return
json
([
'status'
=>
0
,
'message'
=>
"删除异常,单据删除失败,请联系管理员"
]);
}
}
/**
* 判断useage_id是否是em_id的最后一条记录
* @param $useage_id
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public
function
checkEnd
(
$useage_id
){
$uModel
=
(
new
\app\em\model\Useage
())
->
get
([
'useage_id'
=>
$useage_id
]);
if
(
!
$uModel
)
return
json
([
'status'
=>
0
,
'message'
=>
"不存在的抄表单号,请联系管理员"
]);
if
(
$uModel
->
status
==
2
)
return
json
([
'status'
=>
0
,
'message'
=>
"已审核过的单据无法编辑,请联系管理员"
]);
//找出电表最后一条数据
$lastModel
=
(
new
\app\em\model\Useage
())
->
where
(
'em_id'
,
'='
,
$uModel
->
em_id
)
->
order
(
'id desc'
)
->
find
();
if
(
$lastModel
->
status
==
2
)
return
json
([
'status'
=>
0
,
'message'
=>
"单号不是最新的抄表记录且最新的抄表记录已经审核无法修改,请联系管理员"
]);
if
(
$uModel
->
id
!=
$lastModel
->
id
){
return
json
([
'status'
=>
0
,
'message'
=>
"抄表单号不是最新的抄表记录,无法修改,请联系管理员"
]);
}
}
}
\ No newline at end of file
application/em/controller/Useage.php.bak
deleted
100755 → 0
浏览文件 @
cc440ac8
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论