AdminFreightController.php
8.2 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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <bronet@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;
use app\portal\model\AddRentModel;
use app\portal\model\ChangeRentModel;
use app\portal\model\ConditionModel;
use app\portal\model\FreightModel;
use app\portal\model\VehicleModel;
use cmf\controller\AdminBaseController;
use app\portal\model\PortalPostModel;
use app\portal\service\PostService;
use app\portal\model\PortalCategoryModel;
use think\Db;
use app\admin\model\ThemeModel;
use think\Loader;
/**
* Class AdminFreightController
* @package app\portal\controller
* @adminMenuRoot(
* 'name' =>'运费管理',
* 'action' =>'default',
* 'parent' =>'',
* 'display'=> true,
* 'order' => 30,
* 'icon' =>'th',
* 'remark' =>'运费管理'
* )
*/
class AdminFreightController extends AdminBaseController
{
/**
* 运费列表
* @adminMenu(
* 'name' => '运费列表',
* 'parent' => 'portal/AdminFreight/default',
* 'display'=> true,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '运费列表',
* 'param' => ''
* )
*/
public function index()
{
$data = $this->request->param();
$final = $this->adminIndex($data);
$where_freight = $final['where_arr'];
$page_arr['page_arr'] = $final['page_arr'];
if(!empty($data['keyword'])){
$page_arr['keyword'] = $data['keyword'];
$where_freight['address_name'] = array('like','%'.$data['keyword'].'%');
$this->assign('keyword', $data['keyword']);
}
$model = new FreightModel();
$where_freight['status'] = array('neq',9);
$freight = $model->where($where_freight)->paginate(10,false,['query'=>$page_arr]);
$page = $freight->render();
$this->assign('page',$page);
$this->assign('list',$freight);
return $this->fetch();
}
/**
* 添加运费
* @adminMenu(
* 'name' => '添加运费',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '添加运费',
* 'param' => ''
* )
*/
public function add()
{
$data = $this->request->param();
if($this->request->isPost()){
// 判空
if(empty($data['city_name'])){
$this->apiResponse('0','城市不能为空');
}
if(empty($data['min_weight'])){
$this->apiResponse('0','最小重量不能为空');
}
if(empty($data['max_weight'])){
$this->apiResponse('0','最大重量不能为空');
}
if(empty($data['money'])){
$this->apiResponse('0','运费金额不能为空');
}
$model = new FreightModel();
// 查询是否已配置
$where_isset['max_weight'] = array('elt',$data['max_weight']);
$where_isset['min_weight'] = array('egt',$data['min_weight']);
$isSet_arr = $model->where($where_isset)->select()->toArray();
$city_arr = explode(',',$data['city_id']);
$isset_num = 0;
if($city_arr){
if($isSet_arr){
foreach ($isSet_arr as $issetk=>$issetv){
foreach ($city_arr as $k=>$v){
if(strpos($issetv['address_id'],$v)){
$isset_num += 1;
}else{
$isset_num += 0;
}
}
}
}
}
if($isset_num > 0){
$this->apiResponse('0','运费配置重复');
}
$add = $data;
$add['address_id'] = $data['city_id'];
$add['address_name'] = $data['city_name'];
unset($add['city_id']);
unset($add['city_name']);
$res = $model->save($add);
if($res){
$this->apiResponse('1','成功');
}else{
$this->apiResponse('0','失败');
}
}else{
return $this->fetch();
}
}
/**
* 查看运费
* @adminMenu(
* 'name' => '查看运费',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '查看运费',
* 'param' => ''
* )
*/
public function view(){
$data = $this->request->param();
$where_freight['id'] = $data['id'];
$where_freight['status'] = array('neq',9);
$freight = Db::name('Freight')->where($where_freight)->find();
$this->assign('list',$freight);
return $this->fetch('edit');
}
/**
* 修改运费
* @adminMenu(
* 'name' => '修改运费',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '修改运费',
* 'param' => ''
* )
*/
public function edit(){
$data = $this->request->param();
if($this->request->isPost()){
// 判空
if(empty($data['city_name'])){
$this->apiResponse('0','城市不能为空');
}
if(empty($data['min_weight'])){
$this->apiResponse('0','最小重量不能为空');
}
if(empty($data['max_weight'])){
$this->apiResponse('0','最大重量不能为空');
}
if(empty($data['money'])){
$this->apiResponse('0','运费金额不能为空');
}
$model = new FreightModel();
// 查询是否已配置
$where_isset['max_weight'] = array('elt',$data['max_weight']);
$where_isset['min_weight'] = array('egt',$data['min_weight']);
$isSet_arr = $model->where($where_isset)->select()->toArray();
$city_arr = explode(',',$data['city_id']);
$isset_num = 0;
if($city_arr){
if($isSet_arr){
foreach ($isSet_arr as $issetk=>$issetv){
foreach ($city_arr as $k=>$v){
if($issetv['id'] != $data['id']){
if(strpos($issetv['address_id'],$v)){
$isset_num += 1;
}else{
$isset_num += 0;
}
}
}
}
}
}
if($isset_num > 0){
$this->apiResponse('0','运费配置重复');
}
$add = $data;
$add['address_id'] = $data['city_id'];
$add['address_name'] = $data['city_name'];
unset($add['city_id']);
unset($add['city_name']);
$res = $model->isUpdate(true)->save($add);
if($res){
$this->apiResponse('1','成功');
}else{
$this->apiResponse('0','失败');
}
}
}
/**
* 删除运费
* @adminMenu(
* 'name' => '删除运费',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '删除运费',
* 'param' => ''
* )
*/
public function del()
{
$model = new FreightModel();
$this->adminDel($model);
}
}