AdminTempleAreaController.php
5.9 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author:kane < chengjin005@163.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;
use cmf\controller\AdminBaseController;
use think\Db;
class AdminTempleAreaController extends AdminBaseController
{
/**
* 寺庙区域
* @adminMenu(
* 'name' => '寺庙区域',
* 'parent' => 'portal/AdminTemple/default',
* 'display'=> true,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '寺庙区域',
* 'param' => ''
* )
*/
public function index()
{
//接收搜索参数
$param = $this->request->param();
//添加搜索条件
$where=[];
if (cmf_get_current_admin_id()!=1){
$where['t.user_id']=cmf_get_current_admin_id();
};
$keyword = empty($param['keyword']) ? '' : $param['keyword'];
if (!empty($keyword)) {
$where['ta.name'] = ['like', "%$keyword%"];
}
$temple=empty($param['temple']) ? '' : $param['temple'];
if (!empty($temple)) {
$where['ta.temple_id'] = $temple;
}
$data = Db::name('temple_area')
->alias('ta')
->join('temple t','ta.temple_id=t.id')
->where($where)
->field('ta.*,t.name as tname')
->order('ta.create_time','desc')
->paginate('10');
$data->appends($param);
$temple_choose=Db::name('temple')->select();
$this->assign('page',$data->render());
$this->assign('keyword', isset($param['keyword']) ? $param['keyword'] : '');
$this->assign('temple', isset($param['temple']) ? $param['temple'] : '');
$this->assign('temple_choose',$temple_choose);
$this->assign('list', $data);
return $this->fetch();
}
/**
* 添加地区
* @adminMenu(
* 'name' => '添加地区',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '添加地区',
* 'param' => ''
* )
*/
public function add()
{
$where=[];
if (cmf_get_current_admin_id()!=1){
$where['user_id']=cmf_get_current_admin_id();
};
$temple=Db::name('temple')->where($where)->select();
$this->assign('temple',$temple);
return $this->fetch();
}
/**
* 添加地区提交
* @adminMenu(
* 'name' => '添加地区提交',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '添加地区提交',
* 'param' => ''
* )
*/
public function addPost()
{
$param = $this->request->param();
$param['create_time'] = time();
$re = Db::name('temple_area')->insert($param);
if ($re) {
$this->success('添加成功', 'AdminTempleArea/index');
} else {
$this->error('添加失败', 'AdminTempleArea/index');
}
}
/**
* 编辑地区
* @adminMenu(
* 'name' => '编辑地区',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '编辑地区',
* 'param' => ''
* )
*/
public function edit()
{
$id = $this->request->param('id');
$data = Db::name('temple_area')
// ->alias('t')
// ->join('user u','t.user_id=u.id')
->where('id', $id)
// ->field('t.*,u.user_login')
->find();
$where=[];
if (cmf_get_current_admin_id()!=1){
$where['user_id']=cmf_get_current_admin_id();
};
$temple=Db::name('temple')->where($where)->select();
$this->assign('temple',$temple);
$this->assign('list', $data);
return $this->fetch();
}
/**
* 编辑地区提交
* @adminMenu(
* 'name' => '编辑地区提交',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '编辑地区提交',
* 'param' => ''
* )
*/
public function editPost()
{
$param = $this->request->param();
$param['create_time'] = time();
Db::name('temple_area')->where('id', $param['id'])->update($param);
$this->success('编辑成功');
}
/**
* 删除地区
* @adminMenu(
* 'name' => '删除地区',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '删除地区',
* 'param' => ''
* )
*/
public function delete()
{
$id = $this->request->param('id');
$re=Db::name('light_order')
->alias('lo')
->join('light l','lo.light_id=l.id')
->where(['l.area_id'=>$id,'lo.end_time'=>['>',time()]])
->find();
if ($re){
$this->error('该区域下有进行中的订单,不允许删除');
}
Db::name('temple_area')->where('id', $id)->delete();
$this->success('删除成功');
}
}