ZjServiceController.php
6.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
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
<?php
/**
* Created by PhpStorm.
* User: wz
* Date: 2018/6/29
* Time: 15:25
*/
namespace app\admin\controller;
use cmf\controller\AdminBaseController;
use Think\Db;
class ZjServiceController extends AdminBaseController
{
/**
* 后台服务列表
*/
public function index()
{
$all=Db::name('zj_service')->alias('s')->join('zj_service_type t','s.ser_type=t.id')
->field('s.id,s.ser_type,s.name,s.price_ori,s.price_new,s.describes,s.apply,s.create_time,s.update_time,s.is_dis,s.is_rec,t.name as tname');
if ($this->request->isPost()){
$arr=input('post.');
//搜索条件
if($arr['ser_type']=='0'||$arr['ser_type']=='1'||$arr['ser_type']=='2'){
$all=$all->where('ser_type',$arr['ser_type']);
}
if($arr['apply']=='0'||$arr['apply']=='1'||$arr['apply']=='2'||$arr['apply']=='3'){
$all=$all->where('apply',$arr['apply']);
}
if (is_numeric($arr['price_max'])&&is_numeric($arr['price_min'])&&$arr['price_min']<=$arr['price_max']){
$all=$all->where('price_new','>=',$arr['price_min']);
$all=$all->where('price_new','<=',$arr['price_max']);
}
}
$all=$all->order('id','asc')->paginate(10);
$ser=Db::name('zj_service_type')->select();
$this->assign('ser',$ser);
$this->assign('allser',$all);
return $this->fetch();
}
/**
*添加服务
*/
public function add()
{
$ser=Db::name('zj_service_type')->select();
$this->assign('ser',$ser);
return $this->fetch();
}
/**
*添加服务提交
*/
public function addPost()
{
if ($this->request->isPost()){
$arr=input('post.');
$name=Db::name('zj_service')->field('name')->where('name',$arr['name'])->find();
if ($name){
$this->error('服务名称已存在');
}else{
if (is_numeric($arr['price_ori'])&&is_numeric($arr['price_new'])){
if(empty($arr['content'])){
$this->error('详情不能为空');
}else{
$arr['create_time']=time();
$arr['update_time']=time();
if (Db::name('zj_service')->insert($arr)){
$this->success('添加成功',url('zj_service/index'));
}else{
$this->error('添加失败');
}
}
}else{
$this->error('价格请输入数字内容');
}
}
}
}
/**
* 编辑服务
*/
public function edit()
{
if ($this->request->param()){
$id=input('param.id');
$one=Db::name('zj_service')->where('id',$id)->find();
$ser=Db::name('zj_service_type')->select();
$this->assign('ser',$ser);
$this->assign('one',$one);
return $this->fetch();
}
}
/**
* 编辑服务提交
*/
public function editPost()
{
if ($this->request->isPost()){
$arr=input('post.');
if (is_numeric($arr['price_ori'])&&is_numeric($arr['price_new'])){
if(empty($arr['content'])){
$this->error('详情不能为空');
}else{
$arr['update_time']=time();
if (Db::name('zj_service')->where('id',$arr['id'])->update($arr)){
$this->success('修改成功',url('zj_service/index'));
}else{
$this->error('修改失败');
}
}
}else{
$this->error('价格请输入数字内容');
}
}
}
/**
* 服务发布与取消发布
*/
public function publish()
{
$param = $this->request->param();
if (isset($param['ids']) && isset($param["yes"])) {
$ids = $this->request->param('ids/a');
$yes=Db::name('zj_service')->where(['id' => ['in', $ids]])->update(['is_dis' => 1]);
$this->success("发布成功!", '');
}
if (isset($param['ids']) && isset($param["no"])) {
$ids = $this->request->param('ids/a');
$yes=Db::name('zj_service')->where(['id' => ['in', $ids]])->update(['is_dis' => 0]);
$this->success("取消发布成功!", '');
}
}
/**
* 服务推荐与取消
*/
public function recommend()
{
$param = $this->request->param();
if (isset($param['ids']) && isset($param["yes"])) {
$ids = $this->request->param('ids/a');
$yes=Db::name('zj_service')->where(['id' => ['in', $ids]])->update(['is_rec' => 1]);
$this->success("推荐成功!", '');
}
if (isset($param['ids']) && isset($param["no"])) {
$ids = $this->request->param('ids/a');
$yes=Db::name('zj_service')->where(['id' => ['in', $ids]])->update(['is_rec' => 0]);
$this->success("取消推荐成功!", '');
}
}
/**
* 服务删除
*/
public function delete()
{
$param = $this->request->param();
if (isset($param['id'])) {
$id = $this->request->param('id');
$del=Db::name('zj_service')->where('id',$id)->delete();
$this->success("删除成功!", '');
}
if (isset($param['ids'])) {
$ids = $this->request->param('ids/a');
$del=Db::name('zj_service')->where(['id' => ['in', $ids]])->delete();
$this->success("删除成功!", '');
}
}
/**
*添加服务分类
*/
public function addType()
{
if ($this->request->param()){
$name=input('param.name');
$type=Db::name('zj_service_type')->insert(['name'=>$name]);
if ($type){
$this->success('增加分类成功','');
}else{
$this->error('增加分类失败');
}
}
return $this->fetch();
}
}