Choose.php
7.1 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
<?php
namespace app\api\controller;
use app\api\model\ChoosePage;
use app\api\model\Exhibition;
use app\api\model\Video;
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();
$page = $this->request->param('page');
$limit = Config::get('paginate.index_rows');
$data = $model->selectPageData([],$page,$limit,$this->lang);
$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('验证码不正确');
}
}
}