Reservoir.php
4.7 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
<?php
namespace app\api\controller\reservoir;
use app\common\controller\Api;
use think\Request;
use think\Db;
/**
* Class Waterlevel
* @package app\api\controller
*/
class Reservoir extends Api
{
protected $model = '';
protected $noNeedLogin = ['getCountyUnder','getallreservoir', 'reser_xy', 'getInfo', 'getCountyInfo', 'getSkAttr'];
protected $noNeedRight = '*';
public function _initialize()
{
parent::_initialize(); // TODO: Change the autogenerated stub
$this->model = new \app\admin\model\reservoir\Reservoirlist;
}
public function reser_xy()
{
$list = Db::name('reservoir_list')->field('id,name')->select();
$rlist = [];
$timelist = [];
$xy = [];
foreach ($list as $key => $item) {
$rlist[] = $item['name'];
$dis = Db::name('reservoir_dam_displacement')->where('reservoir_id', $item['id'])->field('horizontal,vertical,from_unixtime(createtime,"%Y-%m-%d") as crts')->order('id desc')->find();
if ($dis) {
$timelist[] = $dis['crts'];
$xy[] = [$dis['horizontal'], $dis['horizontal'], $dis['vertical']];
} else {
$timelist[] = date('Y-m-d');
$xy[] = [0, 0, 0];
}
}
$this->success('', ['rlist' => $rlist, 'tlist' => $timelist, 'xy' => $xy]);
}
/**
* 获取水库信息
* Class Reservoir
* @package app\api\controller\reservoir
*/
public function getInfo()
{
$id = input('get.id');
// $this->reservoir_auth('reservoir',$id);
$info = $this->model->with(['bsin'])->where('wrp_reservoir_list.id', $id)->find();
$this->success('获取成功', $info);
}
/**
* 获取水库容量
* $id 水库id
*/
public function getUnder($id)
{
$under = $this->model->where('id', $id)->value('under');
$this->success('', $under);
}
/**
* 根据县市获取水库信息
* Class Reservoir
* @package app\api\controller\reservoir
*/
public function getCountyInfo()
{
//$this->reservoir_auth('county',$id);
$list = $this->model->select();
$ids = [];
foreach ($list as $k => $v) {
//处理图片
$list[$k]['thumbnail_images'] = setQiniuFileUrl($v['thumbnail_images']);
$ids[] = $v->id;
}
$bsin = new \app\admin\model\wrp\rsr\Bsin;
$prsc = $bsin->where('RESERVOIR_ID', 'in', $ids)->field('PRSC')->select();
$prscarr = ['1' => ['count' => 0, 'name' => '大(1)型'], '2' => ['count' => 0, 'name' => '大(2)型'], '3' => ['count' => 0, 'name' => '中型'], '4' => ['count' => 0, 'name' => '小(1)型'], '5' => ['count' => 0, 'name' => '小(2)型']];
foreach ($prsc as $k => $v) {
$prscarr[$v->PRSC]['count']++;
}
$res['list'] = $list;
$res['prsc'] = $prscarr;
$this->success('获取成功', $res);
}
/**
* 获取所有水库信息
* Class Reservoir
* @package app\api\controller\reservoir
*/
public function getallreservoir()
{
//$this->reservoir_auth('county',$id);
$list = $this->model->select();
$ids = [];
foreach ($list as $k => $v) {
//处理图片
$list[$k]['thumbnail_images'] = setQiniuFileUrl($v['thumbnail_images']);
$ids[] = $v->id;
}
$this->success('获取成功', $list);
}
/**
* 获取县市水库总容量
* $id 县市id
*/
public function getCountyUnder($id)
{
$reservoirids = Db::name('reservoir_list')->where('county_id', $id)->field('id')->select();
$ids = [];
foreach ($reservoirids as $k => $v) {
$ids[] = $v['id'];
}
$under = $this->model->where('id', 'in', $ids)->value('SUM(under)');
$this->success('', $under);
}
/**
* 5. 获取某个水库的当日水位、雨量、库容量最新数据
*/
public function getSkAttr($id)
{
$data["water_value"] = 0;//水位
$data["rain_value"] = 0;//雨量
$data["capacityof_value"] = 0;//库容
if ($id) {
$data["water_value"] = Db::name("reservoir_rain_water_level")->where("reservoir_id", $id)->order("createtime desc")->value("water_level");
$data["rain_value"] = Db::name("reservoir_rain_rainfall")->where("reservoir_id", $id)->order("createtime desc")->value("total_rainfall");
$data["capacityof_value"] = Db::name("warterdata_capacityof")->where(["reservoir_id" => $id, "warterdata" => $data["water_value"]])->value("CapacityOf");
}
$this->success("数据获取成功", $data);
}
}