Warning.php
5.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
namespace app\api\controller\inspection;
use app\common\controller\Api;
use think\Db;
/**
* 员工接口
*/
class Warning extends Api
{
// 无需登录的接口,*表示全部
// protected $noNeedLogin = ['*'];
// 无需鉴权的接口,*表示全部
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize(); // TODO: Change the autogenerated stub
$this->model = new \app\admin\model\inspection\Warning();
}
public function add()
{
if ($this->request->isPost()) {
$params = $this->request->post();
if(!$params['title']){
$this->error('隐患标题为空');
}
if(!$params['message']){
$this->error('隐患内容为空');
}
$row = Db::name('inspection_staff')
->alias('staff')
->join('inspection_area area','area.reservoir_id=staff.reservoir_id','LEFT')
->field('staff.id as staff_id,area.id as area_id')
->where('staff.user_id',$this->auth->id)
->find();
if (!$row) {
$this->error('员工信息不存在');
}
$params['staff_id'] = $row['staff_id'] ;
$params['area_id'] = $row['area_id'] ;
$params['cover_images'] = implode(",",$this->request->post("cover_images/a"));
$params['createtime'] = time();
$result = $this->model->allowField(true)->save($params);
if (!$result) {
$this->error('网络繁忙');
}
$this->success('提交成功',$params);
}
}
public function getInfo($id){
$info = Db::name('inspection_warning')
->field('id,title,message,status,cover_images,FROM_UNIXTIME(createtime,"%Y-%m-%d %H:%i") as createtime')
->where('id',$id)
->find();
$reply = Db::name('inspection_warning_reply')
->alias('r')
->join('inspection_staff s','s.id = r.staffid','LEFT')
->where('wid',$id)
->field('FROM_UNIXTIME(r.createtime,"%Y-%m-%d %H:%i:%s") as createtime,r.reply,s.staff_name,r.status')
->select();
$info['list'] = $reply;
if($info['cover_images']){
$cover_images = explode(',',$info['cover_images']);
if(!empty($cover_images)){
foreach ($cover_images as $k=>$v){
if (substr($v, 0, 4) != 'http') {
$cover_images[$k] = 'https://qiniu.ynzhsk.cn' .$v;
}
}
}
$info['cover_images'] = $cover_images;
}
$this->success('',$info);
}
public function getList(){
$map = [];
if(input('post.status')){
$map['status'] = input('post.status');
}
if(input('post.ismine')){
$staff_id = Db::name('inspection_staff')->where('user_id',$this->auth->id)->value('id');
if(!$staff_id){
$this->error('员工信息不存在');
}
$map['w.staff_id'] =['=',$staff_id];
}
if(input('post.time')){
$createtime = strtotime(input('post.time'));
$createtimeend = strtotime(input('post.time').' 23:59:59');
$map['w.createtime'] = ['between',[$createtime,$createtimeend]];
}
$page = input('post.page')?input('post.page'):1;
$list = Db::name('inspection_warning')
->alias('w')
->join('inspection_area a','w.area_id = a.id',"LEFT")
->field('w.createtime,w.id,a.area_name,w.status,w.message,w.title,w.cover_images')
->where($map)
->order('w.createtime desc')
// ->page($page,10)
->select();
foreach ($list as $k => &$v){
$v['count'] = $this->getReply($v['id']);
$v['createtime'] = date('Y-m-d H:i',$v['createtime']);
if($v['cover_images']){
$cover_images = explode(',',$v['cover_images'])[0];
if (substr($cover_images, 0, 4) != 'http') {
$cover_images = 'https://qiniu.ynzhsk.cn' .$cover_images;
}
$v['cover_images'] = $cover_images;
}
}
$this->success('',$list);
}
//获取隐患回复数量
//$wid 隐患id
public function getReply($wid){
$count = Db::name('inspection_warning_reply')->where('wid',$wid)->count();
return $count;
}
//隐患回复
//隐患id
public function reply($id){
if(!input('post.reply')){
$this->error('回复内容不能为空');
}
$status = Db::name('inspection_warning_reply')->where('wid',$id)->where('status','2')->find();
if($status){
$this->error('该隐患已解决');
}
$status = Db::name('inspection_warning_reply')->where('wid',$id)->where('status','3')->find();
if($status){
$this->error('该隐患已回复');
}
$info = Db::name('inspection_warning_reply')->where('wid',$id)->where('status','0')->find();
unset($info['id']);
$info['wid'] = $id;
$info['staffid'] = Db::name('inspection_staff')->where('user_id',$this->auth->id)->value('id');
$info['status'] = '3';
$info['createtime'] = time();
$info['reply'] = input('post.reply');
Db::name('inspection_warning_reply')->insert($info);
$this->success('回复成功');
}
}