Building.php
3.4 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
<?php
namespace app\school\controller\project_appointment;
use app\common\controller\DoubleBase;
use think\Db;
use think\Exception;
use think\exception\PDOException;
use think\exception\ValidateException;
use app\school\model\project_appointment\Building as BuildingModel;
/**
* 楼栋管理
*/
class Building extends DoubleBase
{
protected $noNeedRight = ['*'];
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new BuildingModel();
}
/**
* 楼栋index
* @return array|\think\response\Json
* @author cdd
*/
public function index()
{
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax()) {
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = $this->model
->where($where)
->order('createtime', $order)
->paginate($limit);
$result = array("total" => $list->total(), "rows" => $list->items());
return json($result);
}
return $this->view->fetch();
}
/**
* 添加
*/
public function add()
{
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
if ($params) {
$params = $this->preExcludeFields($params);
if($this->model->where(['building_no' => $params['building_no']])->find()) {
$this->error('该楼宇编号已经存在');
}
$params['school_id'] = SCHOOL_ID;
Db::startTrans();
try {
$result = $this->model->allowField(true)->save($params);
Db::commit();
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
$this->success();
}
$this->error(__('Parameter %s can not be empty', ''));
}
return $this->view->fetch();
}
/**
* 编辑
*/
public function edit($ids = null)
{
if(empty($ids)){
$ids = $this->request->param('id');
}
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
if ($params) {
$params = $this->preExcludeFields($params);
$params['school_id'] = SCHOOL_ID;
if($this->model->where(['building_no' => $params['building_no']])->where('id','neq',$row['id'])->find()) {
$this->error('该楼宇编号已经存在');
}
$result = false;
Db::startTrans();
try {
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
$this->success();
}
$this->error(__('Parameter %s can not be empty', ''));
}
$this->view->assign("row", $row); //选中的数据
$this->assignconfig('id',$ids);
return $this->view->fetch();
}
}