Choose.php
11.8 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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
<?php
namespace app\api\controller;
use app\api\model\ChoosePage;
use app\api\model\Exhibition;
use app\api\model\Menu;
use app\api\model\MenuLikeLog;
use app\api\model\Video;
use app\api\model\VideoLikeLog;
use app\common\controller\Api;
use think\Db;
use think\Validate;
use think\Config;
/**
* 选购助手接口
*/
class Choose extends Api
{
protected function _initialize()
{
parent::_initialize();
}
/**
* @ApiTitle (获取选购助手列表)
* @ApiSummary (获取选购助手列表)
* @ApiMethod (POST)
* @ApiRoute (/api/choose/getChooseList)
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587518501",
"data": [
{
"id": 1,
"title": "公司介绍", 标题
"image": "http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png", 图片
},
{
"id": 2,
"title": "展会活动",
"image": "http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png",
}}
}
})
*/
public function getChooseList()
{
$model = new ChoosePage();
$data = $model->selectData([], $this->lang);
$this->success('SUCCESS', $data);
}
/**
* @ApiTitle (获取选购助手图文详情)
* @ApiSummary (获取选购助手图文详情)
* @ApiMethod (POST)
* @ApiRoute (/api/choose/getChooseInfo)
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiParams (name=choose_id, type=string, required=true, description="选购助手id")
* @ApiReturn({
})
*/
public function getChooseInfo()
{
$model = new ChoosePage();
$choose_id = $this->request->param('choose_id');
if (!$choose_id) $this->error('缺少参数 choose_id!');
if ($this->lang == 'ch') $field = 'id,ch_title title,ch_content content,image,phone,wechat,activitytime';
else $field = 'id,en_title title,en_content content,image,phone,wechat,activitytime';
$data = $model->where(['id' => $choose_id])->field($field)->find();
$this->success('SUCCESS', $data);
}
/**
* @ApiTitle (获取选购助手短视频列表)
* @ApiSummary (获取选购助手短视频列表)
* @ApiMethod (POST)
* @ApiRoute (/api/choose/getChooseVideo)
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiParams (name=page, type=string, required=true, description="页数")
* @ApiReturn({
})
*/
public function getChooseVideo()
{
$model = new Video();
$videoLogModel = new VideoLikeLog();
$page = $this->request->param('page');
$limit = Config::get('paginate.index_rows');
$data = $model->selectPageData([], $page, $limit, $this->lang);
foreach ($data['list'] as $k => $v) {
if ($this->user['id']) {
$data['list'][$k]['like_status'] = $videoLogModel->where(['user_id' => $this->user['id'], 'video_id' => $v['id']])->count();
} else {
$data['list'][$k]['like_status'] = 0;
}
}
$this->success('SUCCESS', $data);
}
/**
* @ApiTitle (获取选购助手短视频点赞/取消点赞)
* @ApiSummary (获取选购助手短视频点赞/取消点赞)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiParams (name=video_id, type=string, required=true, description="视频id")
* @ApiReturn({
})
*/
public
function addVideoLikeLog()
{
$model = new Video();
$videoLogModel = new VideoLikeLog();
$userId = $this->getUserId();
$videoId = $this->request->param('video_id');
if (!$videoId) $this->error('缺少参数 video_id!');
$data = [
'user_id' => $userId,
'video_id' => $videoId
];
$last = $videoLogModel->where($data)->count();
if ($last) {
$videoLogModel->where($data)->delete();
$model->where('id', $videoId)->setDec('like_num', 1);
$this->success('取消点赞');
} else {
$videoLogModel->save($data);
$model->where('id', $videoId)->setInc('like_num', 1);
$this->success('点赞成功');
}
}
/**
* @ApiTitle (获取选购助手食谱列表)
* @ApiSummary (获取选购助手食谱列表)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiParams (name=page, type=string, required=true, description="页数")
* @ApiReturn({
})
*/
public function getChooseMenu()
{
$model = new Menu();
$menuLogModel = new MenuLikeLog();
$page = $this->request->param('page');
$limit = Config::get('paginate.index_rows');
$data = $model->selectPageData([], $page, $limit, $this->lang);
foreach ($data['list'] as $k => $v) {
if ($this->user['id']) {
$data['list'][$k]['like_status'] = $menuLogModel->where(['user_id' => $this->user['id'], 'menu_id' => $v['id']])->count();
} else {
$data['list'][$k]['like_status'] = 0;
}
}
$this->success('SUCCESS', $data);
}
/**
* @ApiTitle (获取选购助手食谱点赞/取消点赞)
* @ApiSummary (获取选购助手食谱点赞/取消点赞)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiParams (name=menu_id, type=string, required=true, description="食谱id")
* @ApiReturn({
})
*/
public
function addMenuLikeLog()
{
$model = new Menu();
$menuLogModel = new MenuLikeLog();
$userId = $this->getUserId();
$menuId = $this->request->param('menu_id');
if (!$menuId) $this->error('缺少参数 menu_id!');
$data = [
'user_id' => $userId,
'menu_id' => $menuId
];
$last = $menuLogModel->where($data)->count();
if ($last) {
$menuLogModel->where($data)->delete();
$model->where('id', $menuId)->setDec('like_num', 1);
$this->success('取消点赞');
} else {
$menuLogModel->save($data);
$model->where('id', $menuId)->setInc('like_num', 1);
$this->success('点赞成功');
}
}
/**
* @ApiTitle (获取选购助手食谱详情)
* @ApiSummary (获取选购助手食谱详情)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiParams (name=menu_id, type=string, required=true, description="食谱id")
* @ApiReturn({
})
*/
public function getChooseMenuInfo()
{
$model = new Menu();
$menuLogModel = new MenuLikeLog();
$menuId = $this->request->param('menu_id');
if (!$menuId) $this->error('缺少参数 menu_id!');
$data = $model->findData(['id'=>$menuId],$this->lang);
if ($this->user['id']) {
$data['like_status'] = $menuLogModel->where(['user_id' => $this->user['id'], 'menu_id' => $menuId])->count();
} else {
$data['like_status'] = 0;
}
$this->success('SUCCESS', $data);
}
/**
* @ApiTitle (添加展会预约(个人预约))
* @ApiSummary (添加展会预约(个人预约))
* @ApiMethod (POST)
* @ApiRoute (/api/choose/addExhibitionType1)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=name, type=string, required=true, description="姓名")
* @ApiParams (name=phone, type=string, required=true, description="手机号")
* @ApiParams (name=code, type=string, required=true, description="验证码")
* @ApiParams (name=sex, type=string, required=true, description="性别:1=男,2=女")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587472510",
"data":
]
}
})
*/
public
function addExhibitionType1()
{
$model = new Exhibition();
$userId = $this->getUserId();
$data = $this->request->param();
$data['user_id'] = $userId;
$data['status'] = 1; //个人预约
$validate = new Validate([
'name' => 'require',
'phone' => ['^1\d{10}$', 'require'],
'sex' => 'require',
'code' => 'require',
]);
$validate->message([
'name' => '缺少参数 name!',
'phone.require' => '缺少参数 phone!',
'sex' => '缺少参数 sex!',
'phone' => '手机号格式错误',
'code' => '缺少参数 code!',
]);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$smsModel = new \app\common\model\Sms();
$last = $smsModel->where(['mobile' => $data['phone'], 'code' => $data['code']])->find();
if ($last) {
if ($last['createtime'] + 600 < time()) $this->error('验证码已失效');
unset($data['code']);
$data = $model->save($data);
$this->success('SUCCESS', $data);
} else {
$this->error('验证码不正确');
}
}
/**
* @ApiTitle (添加展会预约(商家预约))
* @ApiSummary (添加展会预约(商家预约))
* @ApiMethod (POST)
* @ApiRoute (/api/choose/addExhibitionType2)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=name, type=string, required=true, description="姓名")
* @ApiParams (name=phone, type=string, required=true, description="手机号")
* @ApiParams (name=code, type=string, required=true, description="验证码")
* @ApiParams (name=sex, type=string, required=true, description="性别:1=男,2=女")
* @ApiParams (name=store_type, type=string, required=true, description="商家类型:1=公司,2=餐厅")
* @ApiParams (name=num, type=string, required=true, description="参展人数")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587472510",
"data":
})
*/
public
function addExhibitionType2()
{
$model = new Exhibition();
$userId = $this->getUserId();
$data = $this->request->param();
$data['user_id'] = $userId;
$data['status'] = 2; //商家预约
$validate = new Validate([
'name' => 'require',
'phone' => ['^1\d{10}$', 'require'],
'sex' => 'require',
'store_type' => 'require',
'num' => 'require',
'code' => 'require',
]);
$validate->message([
'name' => '缺少参数 name!',
'phone.require' => '缺少参数 phone!',
'phone' => '手机号格式错误',
'sex' => '缺少参数 sex!',
'store_type' => '缺少参数 store_type!',
'num' => '缺少参数 num!',
'code' => '缺少参数 code!',
]);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$smsModel = new \app\common\model\Sms();
$last = $smsModel->where(['mobile' => $data['phone'], 'code' => $data['code']])->find();
if ($last) {
if ($last['createtime'] + 600 < time()) $this->error('验证码已失效');
unset($data['code']);
$data = $model->save($data);
$this->success('SUCCESS', $data);
} else {
$this->error('验证码不正确');
}
}
}