作者 董瑞恩
1 个管道 的构建 通过 耗费 0 秒

interface

... ... @@ -29,99 +29,30 @@ use think\Db;
class AdminFaultController extends AdminBaseController{
public function index(){
$param=$this->request->param();
$where=array();
if (!empty($param['fault_type'])){
$where['fault_type']=$param['fault_type'];
}
$data=Db::name('fault')
->alias('a')
->field('a.*,b.serial_number,b.hospital')
$Order=new OrderModel();
$data=$Order->alias('a')
->field('a.*,count(a.eq_name) as num,sum(a.time) as sumTime')
->join('equipment b','a.eq_name=b.name')
->where($where)
->order('a.state','ase')
->order('a.create_time','desc')
->paginate(10);
->group('a.eq_name')
->order('start_time','desc')
->paginate(10)->each(function ($item){
$item['average']=round($item['sumTime']/$item['num']);
//计费故障次数
$item['fault_time']=Db::name('fault')->where(['eq_name'=>$item['eq_name'],'fault_type'=>1])->count();
//锁故障次数
$item['fault_lock']=Db::name('fault')->where(['eq_name'=>$item['eq_name'],'fault_type'=>5])->count();
//床故障次数
$item['fault_bed']=Db::name('fault')->where(['eq_name'=>$item['eq_name'],'fault_type'=>['in',[2,3,4]]])->count();
//其他故障次数
$item['fault_other']=Db::name('fault')->where(['eq_name'=>$item['eq_name'],'fault_type'=>6])->count();
//故障总数
$item['fault']=Db::name('fault')->where(['eq_name'=>$item['eq_name']])->count();
return $item;
});
$this->assign('data',$data);
$this->assign('fault_type', isset($param['fault_type']) ? $param['fault_type'] : '');
return $this->fetch();
}
//保修
public function warranty(){
$id=$this->request->param('id');
$fault=Db::name('fault')->where('id',$id)->find();
try{
Db::startTrans();
Db::name('equipment')->where('name',$fault['eq_name'])->update(['state'=>2]);
Db::name('fault')->where('id',$id)->update(['state'=>2]);
}catch (\Exception $exception){
Db::rollback();
$this->error('错误:'.$exception->getMessage());
}
Db::commit();
$this->success('处理完成');
}
//恢复设备
public function reply(){
$id=$this->request->param('id');
$fault=Db::name('fault')->where('id',$id)->find();
try{
Db::startTrans();
Db::name('equipment')->where('name',$fault['eq_name'])->update(['state'=>1]);
Db::name('fault')->where('id',$id)->update(['state'=>3]);
}catch (\Exception $exception){
Db::rollback();
$this->error('错误:'.$exception->getMessage());
}
Db::commit();
$this->success('处理完成');
}
//结束计费
public function bill_error(){
$id=$this->request->param('id');
$fault=Db::name('fault')->where('id',$id)->find();
$order=Db::name('order')->where(['users_id'=>$fault['users_id'],'state'=>1])->find();
if (empty($order)){
$this->error('没有未完成订单');
}else{
$time=ceil(($fault['create_time']-$order['start_time'])/3600);
$getPrice=new OrderController();
$price=$getPrice->getPrice($fault['users_id'],$order['start_time'],$fault['create_time']);
$data=[
'end_time'=>$fault['create_time'],
'time'=>$time,
'price'=>$price,
'state'=>2
];
try{
Db::startTrans();
Db::name('users')->where('id',$fault['users_id'])->update(['is_use'=>0]);
Db::name('equipment')->where('name',$fault['eq_name'])->update(['use'=>0]);
Db::name('order')->where('id',$order['id'])->update($data);
Db::name('fault')->where('id',$id)->update(['state'=>3]);
}catch (\Exception $exception){
Db::rollback();
$this->error('错误:'.$exception->getMessage());
}
Db::commit();
$this->success('处理完成');
}
}
... ...
... ... @@ -3,119 +3,59 @@
<body>
<div class="wrap js-check-wrap">
<ul class="nav nav-tabs">
<li class="active"><a href="javascript:;">故障列表</a></li>
<li class="active"><a href="javascript:;">整体统计</a></li>
</ul>
<form class="well form-inline margin-top-20" method="post" action="{:url('AdminFault/index')}">
故障分类:
<select class="form-control" name="fault_type" style="width: 140px;">
分类:
<select class="form-control" name="category" style="width: 140px;">
<option value='0'>全部</option>
<option value='1' <if condition="$fault_type eq 1">selected </if>>计费</option>
<option value='2' <if condition="$fault_type eq 2">selected </if>>床体</option>
<option value='3' <if condition="$fault_type eq 3">selected </if>>床锁</option>
<option value='4' <if condition="$fault_type eq 4">selected </if>>其他</option>
{$category_tree|default=''}
</select> &nbsp;&nbsp;
时间:
<input type="text" class="form-control js-bootstrap-datetime" name="start_time"
value="{$start_time|default=''}"
style="width: 140px;" autocomplete="off">-
<input type="text" class="form-control js-bootstrap-datetime" name="end_time"
value="{$end_time|default=''}"
style="width: 140px;" autocomplete="off"> &nbsp; &nbsp;
关键字:
<input type="text" class="form-control" name="keyword" style="width: 200px;"
value="{$keyword|default=''}" placeholder="请输入关键字...">
<input type="submit" class="btn btn-primary" value="搜索"/>
<a class="btn btn-danger" href="{:url('AdminFault/index')}">清空</a>
</form>
<form class="js-ajax-form" action="" method="post">
<div class="table-actions">
<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"
data-action="{:url('AdminFault/publish',array('yes'=>1))}" data-subcheck="true">批量新增
</button>
</div>
<table class="table table-hover table-bordered table-list">
<thead>
<tr>
<th width="15">
<label>
<input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
</label>
</th>
<th width="50">ID</th>
<th>设备名称</th>
<th>设备锁编号</th>
<th>所在医院</th>
<th>故障类型</th>
<th>故障描述</th>
<th>故障状态</th>
<th>图片</th>
<th width="150">操作</th>
<th width="80">用户ID</th>
<th>使用总时长</th>
<th>使用次数</th>
<th>平均每次使用时长</th>
<th>计费故障次数</th>
<th>锁故障次数</th>
<th>床故障次数</th>
<th>其他故障</th>
<th>故障总数</th>
</tr>
</thead>
<foreach name="data" item="vo">
<tr>
<td>
<input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]"
value="{$vo.id}" title="ID:{$vo.id}">
</td>
<td><b>{$vo.id}</b></td>
<td>{$vo.eq_name}</td>
<td>{$vo.serial_number}</td>
<td>{$vo.hospital}</td>
<td>
<switch name="$vo.fault_type">
<case value="1">计费</case>
<case value="2">床体</case>
<case value="3">床锁</case>
<case value="4">其他</case>
</switch>
</td>
<td>{$vo.fault_describe}</td>
<td>
<switch name="$vo.state">
<case value="1"><span class="label label-danger">未处理</span></case>
<case value="2"><span class="label label-warning">处理中</span></case>
<case value="3"><span class="label label-success">已处理</span></case>
</switch>
</td>
<td>
<img style="width: 50px;height: 50px" src="{:cmf_get_image_preview_url($vo.img)}">
<!--<a href="{:url('AdminFault/edit',array('id'=>$vo['id']))}">查看图片</a>-->
</td>
<td>
<a href="{:url('AdminFault/warranty',array('id'=>$vo['id']))}" class="js-ajax-delete">保修</a><br/>
<a href="{:url('AdminFault/reply',array('id'=>$vo['id']))}" class="js-ajax-delete">保修完成</a><br/>
<a href="{:url('AdminFault/bill_error',array('id'=>$vo['id']))}" class="js-ajax-delete">终止订单计费</a><br/>
</td>
<td>{$vo.users_id}</td>
<td>{$vo.sumTime}小时</td>
<td>{$vo.num}次</td>
<td>{$vo.average}小时</td>
<td>{$vo.fault_time|default='0'}</td>
<td>{$vo.fault_lock|default='0'}</td>
<td>{$vo.fault_bed|default='0'}</td>
<td>{$vo.fault_other|default='0'}</td>
<td>{$vo.fault|default='0'}</td>
</tr>
</foreach>
</table>
<!--<div class="table-actions">-->
<!--<notempty name="category">-->
<!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->
<!--data-action="{:url('AdminArticle/listOrder')}">{:lang('SORT')}-->
<!--</button>-->
<!--</notempty>-->
<!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->
<!--data-action="{:url('AdminArticle/publish',array('yes'=>1))}" data-subcheck="true">发布-->
<!--</button>-->
<!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->
<!--data-action="{:url('AdminArticle/publish',array('no'=>1))}" data-subcheck="true">取消发布-->
<!--</button>-->
<!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->
<!--data-action="{:url('AdminArticle/top',array('yes'=>1))}" data-subcheck="true">置顶-->
<!--</button>-->
<!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->
<!--data-action="{:url('AdminArticle/top',array('no'=>1))}" data-subcheck="true">取消置顶-->
<!--</button>-->
<!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->
<!--data-action="{:url('AdminArticle/recommend',array('yes'=>1))}" data-subcheck="true">推荐-->
<!--</button>-->
<!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->
<!--data-action="{:url('AdminArticle/recommend',array('no'=>1))}" data-subcheck="true">取消推荐-->
<!--</button>-->
<!--&lt;!&ndash;-->
<!--<notempty name="category">-->
<!--<button class="btn btn-primary btn-sm js-articles-move" type="button">批量移动</button>-->
<!--</notempty>-->
<!--<button class="btn btn-primary btn-sm js-articles-copy" type="button">批量复制</button>-->
<!--&ndash;&gt;-->
<!--<button class="btn btn-danger btn-sm js-ajax-submit" type="submit"-->
<!--data-action="{:url('AdminArticle/delete')}" data-subcheck="true" data-msg="您确定删除吗?">-->
<!--{:lang('DELETE')}-->
<!--</button>-->
<!--</div>-->
<ul class="pagination">{$page|default=''}</ul>
<ul style="text-align: center">{$data->render()}</ul>
</form>
</div>
<script src="__STATIC__/js/admin.js"></script>
... ...
... ... @@ -5,7 +5,7 @@
<ul class="nav nav-tabs">
<li class="active"><a href="javascript:;">故障列表</a></li>
</ul>
<form class="well form-inline margin-top-20" method="post" action="{:url('AdminFaultAuditController/index')}">
<form class="well form-inline margin-top-20" method="post" action="{:url('AdminFaultAudit/index')}">
故障分类:
<select class="form-control" name="fault_type" style="width: 140px;">
<option value='0'>全部</option>
... ... @@ -15,14 +15,9 @@
<option value='4' <if condition="$fault_type eq 4">selected </if>>其他</option>
</select> &nbsp;&nbsp;
<input type="submit" class="btn btn-primary" value="搜索"/>
<a class="btn btn-danger" href="{:url('AdminFaultAuditController/index')}">清空</a>
<a class="btn btn-danger" href="{:url('AdminFaultAudit/index')}">清空</a>
</form>
<form class="js-ajax-form" action="" method="post">
<div class="table-actions">
<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"
data-action="{:url('AdminFaultAuditController/publish',array('yes'=>1))}" data-subcheck="true">批量新增
</button>
</div>
<table class="table table-hover table-bordered table-list">
<thead>
<tr>
... ... @@ -73,9 +68,9 @@
<!--<a href="{:url('AdminFault/edit',array('id'=>$vo['id']))}">查看图片</a>-->
</td>
<td>
<a href="{:url('AdminFaultAuditController/warranty',array('id'=>$vo['id']))}" class="js-ajax-delete">保修</a><br/>
<a href="{:url('AdminFaultAuditController/reply',array('id'=>$vo['id']))}" class="js-ajax-delete">保修完成</a><br/>
<a href="{:url('AdminFaultAuditController/bill_error',array('id'=>$vo['id']))}" class="js-ajax-delete">终止订单计费</a><br/>
<a href="{:url('AdminFaultAudit/warranty',array('id'=>$vo['id']))}" class="js-ajax-delete">保修</a><br/>
<a href="{:url('AdminFaultAudit/reply',array('id'=>$vo['id']))}" class="js-ajax-delete">保修完成</a><br/>
<a href="{:url('AdminFaultAudit/bill_error',array('id'=>$vo['id']))}" class="js-ajax-delete">终止订单计费</a><br/>
</td>
</tr>
</foreach>
... ...