Raingauge.php
3.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
<?php
namespace app\equipment\controller;
use app\common\controller\Frontend;
class Raingauge extends Frontend
{
protected $noNeedLogin = [];
protected $noNeedRight = '*';
protected $layout = '';
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\reservoir\Equipment;
}
public function list1()
{
$list = $this->model
->alias('e')
->join('reservoir_list r','r.id=e.reservoir_id','LEFT')
->field('e.*,r.name as reservoir,case e.type when 1 then "水位计" when 2 then "渗流计" when 3 then "渗压计" when 4 then "GNSS" else "雨量计" end as typename')
->where('e.type','5')
->order('id desc')
->paginate(10,'',['query'=>$this->request->param()]);
$this->view->assign(['list'=>$list,'reservoir_list' => \think\Db::name('reservoir_list')->field('id,name')->where('county_id',1)->select()]);
return $this->view->fetch();
}
public function add()
{
if($this->request->isPost()){
$params = $this->request->post('row/a');
if($params){
if (!$params['deviceId']) {
$this->error('设备全局id为空');
}
if($this->model->get(['deviceId'=>$params['deviceId']])){
$this->error('设备全局id已存在');
}
if (!$params['deviceId']) {
$this->error('设备全局id为空');
}
if (!$params['apiKey']) {
$this->error('设备apiKey为空');
}
if (!$params['name']) {
$this->error('设备名称为空');
}
$params['createtime'] = time();
$result = $this->model->allowField(true)->save($params);
if(!$result){
$this->error('网络繁忙');
}
$this->success('添加成功');
}
}
}
public function edit($ids=null)
{
$row = $this->model->get($ids);
if (!$row) {
$this->error('数据不存在');
}
if ($this->request->isPost()) {
$params = $this->request->post('row/a');
if (!$params['deviceId']) {
$this->error('设备全局id为空');
}
if($this->model->where('id','<>',$ids)->where('deviceId',$params['deviceId'])->value('id') ){
$this->error('设备全局id已存在');
}
if (!$params['deviceId']) {
$this->error('设备全局id为空');
}
if (!$params['apiKey']) {
$this->error('设备apiKey为空');
}
if($this->model->where('id','<>',$ids)->where('apiKey',$params['apiKey'])->value('id') ){
$this->error('设备apiKey已存在');
}
if (!$params['name']) {
$this->error('设备名称为空');
}
$result = $row->allowField(true)->save($params);
if (!$result) {
$this->error('网络繁忙');
}
$this->success('更新成功');
}
return json(['code'=>1,'data'=>$row]);
}
public function del($ids=null)
{
$m = $this->model->get($ids);
$res = $m->delete(true);
if(!$res){
$this->error('网络繁忙');
}
$this->success('删除成功');
}
}