AdminLightOrderController.php
7.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
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?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 AdminLightOrderController
* @package app\portal\controller
* @adminMenuRoot(
* 'name' =>'订单管理',
* 'action' =>'default',
* 'parent' =>'',
* 'display'=> true,
* 'order' => 30,
* 'icon' =>'th',
* 'remark' =>'订单管理'
* )
*/
class AdminLightOrderController extends AdminBaseController
{
/**
* 订单列表
* @adminMenu(
* 'name' => '订单列表',
* 'parent' => 'portal/AdminLightOrder/default',
* 'display'=> true,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '订单列表',
* 'param' => ''
* )
*/
public function index()
{
//接收搜索参数
$param = $this->request->param();
//添加搜索条件
$where=[];
$user_name = empty($param['user_name']) ? '' : $param['user_name'];
if (!empty($user_name)) {
$where['u.user_name'] = ['like', "%$user_name%"];
}
$mobile=empty($param['mobile']) ? '' : $param['mobile'];
if (!empty($mobile)) {
$where['u.mobile'] = ['like', "%$mobile%"];
}
$temple=empty($param['temple']) ? '' : $param['temple'];
if (!empty($temple)) {
$where['l.temple_id'] = $temple;
}
$startTime = empty($param['start_time']) ? 0 : strtotime($param['start_time']);
$endTime = empty($param['end_time']) ? 0 : strtotime($param['end_time']);
if (!empty($startTime) && !empty($endTime)) {
$where['lo.pay_time'] = [['>= time', $startTime], ['<= time', $endTime]];
} else {
if (!empty($startTime)) {
$where['lo.pay_time'] = ['>= time', $startTime];
}
if (!empty($endTime)) {
$where['lo.pay_time'] = ['<= time', $endTime];
}
}
//所有寺庙
$temples=Db::name('temple')->select();
$this->assign('temples',$temples);
//数据提取
$data = Db::name('light_order')
->alias('lo')
->join('light l','lo.light_id=l.id')
->join('users u','lo.users_id=u.id')
->join('temple t','l.temple_id=t.id')
->join('temple_area ta','l.area_id=ta.id')
->where($where)
->field('lo.*,l.*,u.*,t.name as tname,ta.name as taname,lo.name as loname')
->order('lo.create_time','desc')
->paginate('10');
//向地址传参
$data->appends($param);
$this->assign('page',$data->render());
$this->assign('start_time', isset($param['start_time']) ? $param['start_time'] : '');
$this->assign('end_time', isset($param['end_time']) ? $param['end_time'] : '');
$this->assign('mobile', isset($param['mobile']) ? $param['mobile'] : '');
$this->assign('temple', isset($param['temple']) ? $param['temple'] : '');
$this->assign('user_name', isset($param['user_name']) ? $param['user_name'] : '');
$this->assign('list', $data);
return $this->fetch();
}
public function index2(){
$id=$this->request->param('id');
$data = Db::name('light')
->alias('l')
->join('temple t','l.temple_id=t.id')
->join('temple_area ta','l.area_id=ta.id')
->where('l.temple_id',$id)
->field('l.*,t.address,t.name as tname,ta.name as taname,ta.light,lo.name as loname')
->order('l.create_time','desc')
->paginate('10');
$this->assign('page',$data->render());
$this->assign('list',$data);
return $this->fetch();
}
/**
* 编辑订单
* @adminMenu(
* 'name' => '编辑订单',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '编辑订单',
* 'param' => ''
* )
*/
public function edit()
{
$id = $this->request->param('id');
$data = Db::name('light_order')
->alias('lo')
->join('light l','lo.light_id=l.id')
->join('users u','lo.users_id=u.id')
->join('temple t','l.temple_id=t.id')
->join('temple_area ta','l.area_id=ta.id')
->where('lo.id',$id)
->field('lo.*,l.*,u.*,t.name as tname,ta.name as taname,lo.name as loname')
->find();
$data['location']=[$data['row'],$data['column']];
$address = Db::name('temple')->field('address')->distinct('true')->select();
$this->assign('address',$address);
$temple = Db::name('temple')->where('address',$data['address'])->select();
$this->assign('temple', $temple);
$area = Db::name('temple_area')->where('temple_id', $data['temple_id'])->select();
$this->assign('area', $area);
$location=json_decode($this->getLocation($id=$data['area_id']),true);
$this->assign('location', $location);
$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('light')->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');
Db::name('light_order')->where('id', $id)->delete();
$this->success('删除成功');
}
//获取区域下所有位置
public function getLocation($id="")
{
if (empty($id)) {
$id = $this->request->param('id');
}
$data = Db::name('temple_area')->where('id', $id)->find();
$arr = [];
for ($r = 1; $r <= $data['rows']; $r++) {
for ($c = 1; $c <= $data['columns']; $c++) {
array_push($arr, [$r,$c]);
}
}
$is_set = Db::name('light_order')
->alias('lo')
->join('light l','lo.light_id=l.id')
->where(['l.area_id'=> $id,'lo.status'=>1,'lo.end_time'=>['>',time()]])->field('l.row,l.column')->select()->toArray();
foreach ($arr as $k=>$v){
foreach ($is_set as $k1=>$v1){
if (array_values($v)==array_values($v1)){
unset($arr[$k]);
// $arr = array_values($arr);
}
}
}
return json_encode($arr);
}
}