Riverlist.php
5.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
namespace app\admin\controller\river;
use app\common\controller\Backend;
use fast\Tree;
use think\Db;
/**
* 河湖管理
*
* @icon fa fa-circle-o
*/
class Riverlist extends Backend
{
/**
* Riverlist模型对象
* @var \app\admin\model\river\Riverlist
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\river\Riverlist;
//分类
$catmodel = new \app\admin\model\river\Rivercat;
$tree = Tree::instance();
$tree->init(collection($catmodel->order('weigh asc,id asc')->select())->toArray(), 'pid');
$this->categorylist = $tree->getTreeList($tree->getTreeArray(0), 'name');
foreach ($this->categorylist as $k => $v) {
$categorydata[$v['id']] = $v;
}
//上级河段
$tree2 = Tree::instance();
$tree2->init(collection($this->model->order('id asc')->select())->toArray(), 'river_pid');
$plist = $tree2->getTreeList($tree2->getTreeArray(0), 'name');
foreach ($plist as $kk => $vv) {
$plistdata[$vv['id']] = $vv;
}
//部门选择
$tree3 = Tree::instance();
$departModel = new \app\admin\model\inspection\Depart();
$tree3->init(collection($departModel->order('weigh asc,id asc')->select())->toArray(), 'pid');
$departdata = ['' => ['depart_name' => '请选择部门']];
foreach ($tree3->getTreeList($tree3->getTreeArray(0), 'depart_name') as $k => $v) {
$departdata[$v['id']] = $v;
}
//var_dump($plistdata);
$this->view->assign("catList", $categorydata);
$this->view->assign("pList", $plistdata);
$this->view->assign("departList", $departdata);
}
public function import()
{
parent::import();
}
/**
* 查看
*/
public function index()
{
//当前是否为关联查询
$this->relationSearch = true;
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax()) {
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = $this->model
->with(['rivercat', 'reservoirprovince', 'reservoirstate', 'reservoircounty', 'reservoirstreet', 'reservoirvillage', 'inspectiondepart', 'inspectionstaff'])
->where($where)
->order($sort, $order)
->paginate($limit);
foreach ($list as $row) {
$row->visible(['id', 'river_code', 'name', 'cat_id', 'river_pid', 'thumbnail_images', 'start_address', 'end_address', 'banks_type', 'river_long', 'user_name', 'user_mobile', 'province_id', 'state_id', 'county_id', 'street_id', 'village_id', 'status', 'start_lat', 'start_lng', 'end_lat', 'createtime', 'end_lng', 'user_id', 'depart_id', 'staff_name']);
$row->visible(['rivercat', 'reservoirprovince', 'reservoirstate', 'reservoircounty', 'reservoirstreet', 'reservoirvillage', 'inspectiondepart', 'inspectionstaff']);
$row->getRelation('rivercat');
$row->getRelation('reservoirprovince');
$row->getRelation('reservoirstate');
$row->getRelation('reservoircounty');
$row->getRelation('reservoirstreet');
$row->getRelation('reservoirvillage');
$row->getRelation('inspectiondepart');
$row->getRelation('inspectionstaff');
}
$rows = $list->items();
$snararr = [];
foreach ($rows as $kk => $vv) {
$staffarr = explode(',', $vv['user_id']);
if (!empty($staffarr)) {
foreach ($staffarr as $n => $j) {
$sinfo = Db::name('inspection_staff')
->where(['id' => $j])
->field('id,staff_name,mobile')
->find();
$snararr[$n] = $sinfo['staff_name'];
}
$rows[$kk]['staff_name'] = implode(',', $snararr);
} else {
$rows[$kk]['staff_name'] = '';
}
}
$result = array("total" => $list->total(), "rows" => $rows);
return json($result);
}
return $this->view->fetch();
}
/**
* 指定河长
*
*/
public function setadmin()
{
if ($this->request->isAjax()) {
//保存数据处理
$river_id = $this->request->param('river_pid', 0);
$user_id = $this->request->param('user_id', 0);
//更新河长表的指定
$uprid['user_id'] = $user_id;
$uprid['updatetime'] = time();
$res = Db::name('river_list')->where(['id' => $river_id])->update($uprid);
//return Db::name('inspection_staff')->getLastSql();
if ($res != false) {
$rd['stu'] = 1;
$rd['msg'] = '操作成功!';
return $rd;
} else {
$rd['stu'] = 2;
$rd['msg'] = '操作失败,请重试!';
return $rd;
}
} else {
//加载页面
//获得河长列表
$ids = $this->request->param('rid', 0);
$row = Db::name('river_list')->where(['id' => $ids])->find();
$this->view->assign("row", $row);
return $this->view->fetch();
}
}
}