提交 497f8467 authored 作者: chengye's avatar chengye

完成抄表的驳回,修改操作

上级 14f65b58
......@@ -119,11 +119,35 @@ class Useage extends Base
return $this->fetch('default');
}
public function update(){
$useage_id = Request::param('useage_id');
$uModel = (new \app\em\model\Useage())->with('photo')->get(['useage_id'=>$useage_id]);
$em = (new \app\em\model\Em)->getEmUseageInfoById($uModel->em_id,false);
//基站信息
$station_info = Station::getBaseInfoById($em->station_id);
$this->assign('station',$station_info);
//当前用户
$user = Session::get('user');
$this->assign('uid',$user['user_id']);
//员工列表
$this->assign('staffs',(new Staff())->getStaffs($user['is_admin'],'','useage'));
$this->assign('em',$em);
$step = 1000000;
$uModel->repo_numb = ((int)($uModel->current_sum_numb * $step) - (int)($uModel->last_sum_numb * $step)) / $step;
$this->assign('useage',$uModel);
return $this->fetch('update');
}
//保存抄表单
public function store($useage_id = ''){
public function store(){
//获取表单数据
$data = Request::post();
$useage_id = isset($data['useage_id']) ? $data['useage_id'] : '';
$action = '新增';
//数据验证
$validate = new UseageGeneralInfoValidate();
......@@ -149,6 +173,7 @@ class Useage extends Base
$this->checkEnd($useage_id);
$action = '修改';
$uModel = (new \app\em\model\Useage())->get(['useage_id' => $useage_id]);
$uModel->status = 1;
}
//更新
$uModel->staff_id = $data['staff_id'];
......@@ -162,13 +187,14 @@ class Useage extends Base
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'];
$udModel->useage_id = $uModel->useage_id;
$udModel->type = $data['pricing_type'] == 1 ? 5 : 6;
$udModel->current_numb = $uModel->current_sum_numb;
$udModel->last_numb = $uModel->last_sum_numb;
} else {
$udModel = (new UseageDetail())->get(['useage_id' => $useage_id]);; //抄表详情模型
$udModel = (new UseageDetail())->get(['useage_id' => $useage_id]); //抄表详情模型
}
$udModel->current_numb = $data['current_numb'];
$udModel->current_numb = $uModel->current_sum_numb;
$udModel->price = $uModel->price;
$udModel->save();
......@@ -188,6 +214,8 @@ class Useage extends Base
$checkType = Request::param('checkType');
$this->verify($useage_id,$checkType); //1是通过 2是驳回
if($checkType == 2) {
$res = $this->checkEnd($useage_id);
if($res !== true) return $res;
$useage->status = 3; //3代表被驳回
$useage->save();
return json(['status'=>1,'message'=>'单据已经驳回']);
......@@ -249,15 +277,20 @@ class Useage extends Base
public function del(){
$useage_id = Request::param('uid');
$this->checkEnd($useage_id);
$res = $this->checkEnd($useage_id);
if($res !== true) return $res;
$useage = (new \app\em\model\Useage())->get(['useage_id'=>$useage_id]);
$useage_details = (new UseageDetail())->select(['useage_id'=>$useage_id]);
Db::startTrans();
try{
$useage->delete();
$useage_details->delete();
if(!empty($useage_details)){
foreach ($useage_details as $u){
$u->delete();
}
}
Db::commit();
return json(['status'=>1,'message'=>"删除单据成功"]);
} catch (\Exception $e) {
......@@ -278,15 +311,16 @@ class Useage extends Base
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'=>"已审核过的单据无法编辑,请联系管理员"]);
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($lastModel->status == 2) return json(['status'=>0,'message'=>"单号不是最新的抄表记录且最新的抄表记录已经审核无法操作,请联系管理员"]);
if($uModel->id != $lastModel->id){
return json(['status'=>0,'message'=>"抄表单号不是最新的抄表记录,无法修改,请联系管理员"]);
return json(['status'=>0,'message'=>"抄表单号不是最新的抄表记录无法操作,请联系管理员"]);
}
return true;
}
......
......@@ -53,8 +53,13 @@ class Useage extends Base
foreach ($data as $k => $v){
$data[$k]['repo_numb'] = round(round($v['current_sum_numb'] - $v['last_sum_numb'],2)*$v['rate'],2);
if($v['status'] == 3){
$info = (new EmCheckBill())->field('info')->get(['mode_id'=>$v['useage_id']]);
$data[$k]['info'] = $info['info'];
}
}
return $data;
return $data;
}
public function getCopyListCount($map){
$data = self::alias('ue')
......
......@@ -30,7 +30,7 @@ class UseageGeneralInfoValidate extends Validate
];
protected $scene = [
's1' => 'em_id,last_numb,last_date,current_numb,current_date,photo_id,staff_id',
's1' => 'em_id,last_numb,last_date,current_numb,current_date,photo_id,staff_id,price',
's2' => 'em_id,last_numb,last_date,current_numb,current_date,photo_id,staff_id,price',
];
......
......@@ -205,7 +205,7 @@
</div>
{if $detail == false}
<div class="layui-form-item layui-col-md-offset4">
<a href="/em" class="layui-btn">
<a href="/useage/" class="layui-btn">
返回
</a>
<button class="layui-btn" lay-filter="save" lay-submit="">
......
......@@ -217,13 +217,6 @@
{block name="js"}
<script>
//限制输入长度
function sliceDom(dom,len){
if(dom.value.length>len)
return dom.value = dom.value.slice(0,len)
}
//初始化Layui控件
layui.use(['form', 'layer', 'laydate', 'upload'],
function () {
......@@ -251,11 +244,11 @@
dataType: "json",
success: function (data) {
if (data.status == 1) {
layer.msg(data.message,{icon: 6,time: 2000},function(){
layer.msg(data.message,{icon: 6,time: 3000},function(){
window.location.href='/useage';
})
} else {
layer.msg(data.message || data.msg,{icon: 5,time: 1000 })
layer.msg(data.message || data.msg,{icon: 5,time: 3000 })
window.location.href='/useage';
}
}
......@@ -272,7 +265,7 @@
layer.open({
type: 1,
title:'填写驳回理由',
content: '<div class="layui-form-item><div class="layui-input-block" style="padding:15px;"><textarea placeholder="驳回理由" class="layui-textarea" id="refuseInfo" name="refuseInfo"></textarea></div>',
content: '<div class="layui-form-item"><div style="padding:15px;"><textarea placeholder="驳回理由" class="layui-textarea" id="refuseInfo" name="refuseInfo"></textarea></div>',
btn:"提交",
yes: function(){
$data.field.checkType = 2;
......@@ -284,12 +277,11 @@
dataType: "json",
success: function (data) {
if (data.status == 1) {
layer.msg(data.message,{icon: 6,time: 2000},function(){
layer.msg(data.message,{icon: 6,time: 4000},function(){
window.location.href='/useage';
})
} else {
layer.msg(data.message || data.msg,{icon: 5,time: 1000 })
window.location.href='/useage';
layer.msg(data.message || data.msg,{icon: 5,time: 5000 })
}
}
});
......
......@@ -95,18 +95,19 @@
{{# if(d.status == 2){ }}
<span class="layui-bg-blue">已审核</span>
{{# } }}
{{# if(d.status == 3) { }}
<span class="layui-bg-orange" title="{{ d.info.info }}">被驳回</span>
{{# if(d.status == 3){ }}
<span class="layui-bg-orange" title="{{ d.info }}">被驳回</span>
{{# } }}
{{# if(d.status < 2) { }}
<span class="layui-bg-green" title="{{ d.info.info }}">未审核</span>
{{# if(d.status < 2){ }}
<span class="layui-bg-green">未审核</span>
{{# } }}
</script>
{if $admin == true}
<script type="text/html" id="barDemo">
{{# if(d.status == 1 || d.status == 3){ }}
<a title="删除" class="layui-btn layui-btn-sm layui-bg-green" lay-event="update">编辑</a>
<a title="编辑" class="layui-btn layui-btn-sm layui-bg-green" href="/useage_update/{{d.useage_id}}">编辑</a>
<a title="删除" class="layui-btn layui-btn-sm layui-btn-danger" lay-event="del">删除</a>
{{# } }}
</script>
......@@ -138,13 +139,13 @@
dataType: "json",
success: function (data) {
if(data.status == 1){
layer.msg(data.message,{icon: 6,time: 2000},function(){
layer.msg(data.message,{icon: 6,time: 4000},function(){
obj.del();
layer.close(index);
location.reload()
})
} else {
layer.msg(data.message,{icon: 5,time: 1000 })
layer.msg(data.message,{icon: 5,time: 5000 })
}
}
});
......
差异被折叠。
......@@ -147,7 +147,7 @@ Route::get('useage/:useage_id','em/useage/detail');
Route::get('useage_add/:id','em/useage/create');
Route::post('useage_add','em/useage/store');
Route::post('useage_del','em/useage/del');
Route::post('useage_update','em/useage/update');
Route::get('useage_update/:useage_id','em/useage/update');
Route::post('upFile','em/UploadFile/upFile');
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论