IndexController.php
14.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
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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
<?php
namespace api\home\controller;
use api\portal\model\PortalPostModel;
use cmf\controller\RestUserBaseController;
use think\composer\Plugin;
use Think\Db;
use api\home\service\AnswerService;
/**
* @title 答题小程序
* @description 欢迎使用在线接口文档
*/
class IndexController extends RestUserBaseController
{
/**
* @title 判断用户是否保存手机接口
* @description 手机判断
* @author WeiQiang
* @url /home/index/userMobile
* @method POST
* @header name:XX-Token require:1 default: desc:token
* @header name:XX-Device-Type require:1 default:wxapp desc:固定参数
*
* @return type:以保存手机返回true,未保存返回false
*/
public function userMobile(){
$id = $this->getUserId();
$mobile = Db::name('user')->where('id',$id)->value('mobile');
if(empty($mobile)){
$this->success('SUCCESS',['type'=>false]);
}
$this->success('SUCCESS',['type'=>true]);
}
/**
* @title 用户保存手机接口
* @description 手机保存
* @author WeiQiang
* @url /home/index/saveMobile
* @method POST
* @header name:XX-Token require:1 default: desc:token
* @header name:XX-Device-Type require:1 default:wxapp desc:固定参数
* @param name:mobile type:string require:1 other: desc:用户手机
* @return type:保存手机成功返回true,未保存成功返回false
*/
public function saveMobile(){
$id = $this->getUserId();
$mobile = input('mobile');
if(mb_strlen($mobile,'utf8') != 11 ){
$this->error(['code'=>'40001','msg'=>'手机号码位数错误']);
}
if(Db::name('user')->where('id',$id)->update(['mobile'=>$mobile]) == true){
$this->success('SUCCESS',['type'=>true]);
}
$this->success('SUCCESS',['type'=>false]);
}
/**
* @title 优惠券展示接口
* @description 优惠券
* @author WeiQiang
* @url /home/index/coupon
* @method POST
* @header name:XX-Token require:1 default: desc:token
* @header name:XX-Device-Type require:1 default:wxapp desc:固定参数
* @return title:优惠券名称
* @return money:优惠券金额
* @return time:有效期
* @return content:优惠券信息
*/
public function coupon(){
$coupon = Db::name('coupon')->where('type',1)->where('delete_time',0)->find();
$array['title'] = $coupon['title'];
$array['money'] = $coupon['money'];
$array['time'] = date('Y-m-d',$coupon['start_time']).' 至 '.date('Y-m-d',$coupon['end_time']);
$array['content'] = $coupon['content'];
$this->success('SUCCESS',$array);
}
/**
* @title 优惠券领取结果接口
* @description 优惠券
* @author WeiQiang
* @url /home/index/couponPost
* @method POST
* @header name:XX-Token require:1 default: desc:token
* @header name:XX-Device-Type require:1 default:wxapp desc:固定参数
* @return type:领取成功返回true,返回40002为已经领取,40001数据库写入错误
* @return coupon_text:成功返回成功消息语
*/
public function couponPost(){
$user_id = $this->getUserId();
$coupon = Db::name('coupon')->where('type',1)->where('delete_time',0)->find();
$user_coupon = Db::name('user_coupon')->where('user_id',$user_id)->where('coupon_id',$coupon['id'])->count();
if($user_coupon > 0){
$this->error(['code'=>40002,'msg'=>'该优惠券一个用户仅限领取一次']);
}
if(Db::name('user_coupon')->insert([
'user_id' => $user_id,
'coupon_id' => $coupon['id'],
'create_time' => time(),
'delete_time' => 0,
'type' => 0
])
== true){
$coupon_text = Db::name('public_config')->where('id',1)->value('coupon_text');
$this->success('SUCCESS',['type'=>true,'coupon_text'=>$coupon_text]);
} else {
$this->error(['code'=>40001,'msg'=>'系统繁忙请重试']);
}
}
/**
* @title 前七题列表接口
* @description 答题
* @author WeiQiang
* @url /home/index/qualification
* @method POST
* @header name:XX-Token require:1 default: desc:token
* @header name:XX-Device-Type require:1 default:wxapp desc:固定参数
* @return list:题目列表@
* @list id:题目id title:题目 content:选错提示 type:正确选项1为是0为否 order_id:题目排序
*/
public function qualification(){
$list = Db::name('qualification')
->field('id,title,content,type ,order_id')
->where('delete_time',0)
->order('order_id')
->select();
$this->success('SUCCESS',['list'=>$list]);
}
/**
* @title 答题错误提示语
* @description 优惠券
* @author WeiQiang
* @url /home/index/qualificationPost
* @method POST
* @header name:XX-Token require:1 default: desc:token
* @header name:XX-Device-Type require:1 default:wxapp desc:固定参数
* @return qualification:提示语内容
*/
public function qualificationPost(){
$qualification = Db::name('public_config')->where('id',1)->value('qualification');
$this->success('SUCCESS',['qualification'=>$qualification]);
}
/**
* @title 后八题列表接口
* @description 答题
* @author WeiQiang
* @url /home/index/question
* @method POST
* @header name:XX-Token require:1 default: desc:token
* @header name:XX-Device-Type require:1 default:wxapp desc:固定参数
* @return list:题目列表@
* @list id:题目id title:题目 hint_type:是否有答题提示1为有0为没有 hint_text:答题提示标注 hint_title:答题提示标题 hint_content:答题提示内容 question:选项列表@ order_id:问题排序
* @question id:选项列表 title:选项内容 order_id:选项排序
*/
public function question(){
$list = Db::name('question')->where('delete_time',0)->where('parent_id',0)->order('order_id')->select();
$array = [];
foreach($list as $l){
$arr = [];
$arr['id'] = $l['id'];
$arr['title'] = $l['title'];
$arr['hint_type'] = $l['hint_type'];
$arr['hint_title'] = $l['hint_title'];
$arr['hint_content'] = $l['hint_content'];
$arr['hint_text'] = $l['hint_text'];
$arr['order_id'] = $l['order_id'];
$question = Db::name('question')
->field('id ,title ,order_id')
->where('delete_time',0)
->where('parent_id',$l['id'])
->order('order_id')
->select();
$arr['question'] = $question;
array_push($array,$arr);
}
$this->success('SUCCESS',['list'=>$array]);
}
/**
* @title 后八题答题结果接口
* @description 答题
* @author WeiQiang
* @url /home/index/questionPost
* @method POST
* @header name:XX-Token require:1 default: desc:token
* @header name:XX-Device-Type require:1 default:wxapp desc:固定参数
* @param name:questionStr type:string require:1 other:问题id-选项id,问题id-选项id desc:答题结果字符串
* @return fen:分数区间
* @return content:分数评价
* @return type:是否显示评星1为显示
* @return start:评星数量@
* @return question:题目单独评价列表@
* @start text:类型内容 num:评星数量 title:解释文字 type:1为知识产权2为科技成果转化情况3为研发组织管理水平4为财务增长情况
* @question title:题目编号 content:单独评价题目内容
* @return all_fen:总分
*/
public function questionPost(){
$question_str = input('questionStr');
//结果采集
$Answer = new AnswerService();
$array = $Answer->answer($question_str);
if($array == false){
$this->error(['code'=>40001,'msg'=>'请完成所有题目']);
}
//保存结果
$user_id = $this->getUserId();
$user_answer = Db::name('user_answer')->where('user_id',$user_id)->find();
if($user_answer){
Db::name('user_answer')
->where('user_id',$user_id)
->update(['user_id'=>$user_id,'str'=>$question_str,'create_time'=>time()]);
} else {
Db::name('user_answer')->insert(['user_id'=>$user_id,'str'=>$question_str,'create_time'=>time()]);
}
$this->success('SUCCESS',$array);
}
/**
* @title 个人资料接口
* @description 个人中心
* @author WeiQiang
* @url /home/index/MyMeans
* @method POST
* @header name:XX-Token require:1 default: desc:token
* @header name:XX-Device-Type require:1 default:wxapp desc:固定参数
* @return avatar:头像
* @return name:昵称
* @return mobile:电话
*/
public function MyMeans(){
$user_id = $this->getUserId();
$array = Db::name('user')->field('user_nickname ,avatar ,mobile')->where('id',$user_id)->find();
$array['avatar'] = cmf_get_asset_url($array['avatar']);
$this->success('SUCCESS',$array);
}
/**
* @title 个人答题结果接口
* @description 个人中心
* @author WeiQiang
* @url /home/index/MyAnswer
* @method POST
* @header name:XX-Token require:1 default: desc:token
* @header name:XX-Device-Type require:1 default:wxapp desc:固定参数
* @return answer:有结果返回true无结果返回false
* @return fen:分数区间
* @return content:分数评价
* @return type:是否显示评星1为显示
* @return start:评星数量@
* @return question:题目单独评价列表@
* @start text:类型内容 num:评星数量 title:解释文字 type:1为知识产权2为科技成果转化情况3为研发组织管理水平4为财务增长情况
* @question title:题目编号 content:单独评价题目内容
* @return all_fen:总分
*/
public function MyAnswer(){
$user_id = $this->getUserId();
$str = Db::name('user_answer')->where('user_id',$user_id)->value('str');
if(!$str){
$this->success('SUCCESS',['type'=>false]);
}
//结果采集
$Answer = new AnswerService();
$array = $Answer->answer($str);
$array['answer'] = true;
$this->success('SUCCESS',$array);
}
/**
* @title 我的优惠券接口
* @description 个人中心
* @author WeiQiang
* @url /home/index/MyCoupon
* @method POST
* @header name:XX-Token require:1 default: desc:token
* @header name:XX-Device-Type require:1 default:wxapp desc:固定参数
*@param name:type type:int require:1 other:0为未使用,1为已使用,2为已过期 desc:优惠券类型
* @return list:优惠券列表@
* @list title:优惠券名称 start_time:开始时间 end_time:结束时间 money:金额 content:简介 type:优惠券状态0待使用1已使用2已过期
*/
public function MyCoupon(){
$type = input('type');
$user_id = $this->getUserId();
$list = Db::name('user_coupon')
->alias('uc')
->field('c.money ,c.title ,c.start_time ,c.end_time ,c.content ,uc.type')
->join('coupon c','uc.coupon_id = c.id','left')
->where('uc.user_id',$user_id)
->where('uc.delete_time',0)
->order('uc.id','DESC')
->select()
->each(function ($item){
if($item['end_time'] < time()){
$item['type'] = 2;
}
$item['start_time'] = date('Y-m-d',$item['start_time']);
$item['end_time'] = date('Y-m-d',$item['end_time']);
return $item;
});
$this_list = [];
foreach ($list as $l){
if($l['type'] == $type){
$this_list[] = $l;
}
}
$this->success('SUCCESS',$this_list);
}
/**
* @title 关于我们页面接口
* @description 个人中心
* @author WeiQiang
* @url /home/index/AboutUs
* @method POST
* @header name:XX-Token require:1 default: desc:token
* @header name:XX-Device-Type require:1 default:wxapp desc:固定参数
* @return wechat_name:小程序名称
* @return thumbnail:小程序头像
* @return about:平台简介
* @return qq:qq客服
* @return mobile:客服电话
* @return email:客服邮箱
*/
public function AboutUs(){
$list = Db::name('public_config')->where('id',1)->field('wechat_name,thumbnail,about,qq,mobile,email')->find();
$list['thumbnail'] = cmf_get_asset_url($list['thumbnail']);
$this->success('SUCCESS',$list);
}
/**
* @title 意见反馈接口
* @description 个人中心
* @author WeiQiang
* @url /home/index/tick
* @method POST
* @header name:XX-Token require:1 default: desc:token
* @header name:XX-Device-Type require:1 default:wxapp desc:固定参数
* @param name:content type:string require:1 other: desc:反馈内容
* @return type:保存成功type返回1保存失败返回错误码40001
*/
public function tick(){
$content = input('content');
$user_id = $this->getUserId();
if(Db::name('tickling')->insert(['content'=>$content,'user_id'=>$user_id,'create_time'=>time(),'delete_time'=>0]) == true){
$this->success('SUCCESS',['type'=>1]);
} else {
$this->error(['code'=>40001,'msg'=>'系统繁忙']);
}
}
/**
* @title 用户协议接口
* @description 个人中心
* @author WeiQiang
* @url /home/index/category
* @method POST
* @header name:XX-Token require:1 default: desc:token
* @header name:XX-Device-Type require:1 default:wxapp desc:固定参数
* @return list:优惠券列表@
* @list title:优惠券名称 start_time:开始时间 end_time:结束时间 money:金额 content:简介 status:优惠券状态0待使用1已使用2已过期
*/
public function category(){
$PortalPost = new PortalPostModel();
$category = $PortalPost->where('id',32)->find();
$content = $category['post_content'];
$title = $category['post_title'];
$this->success('SUCCESS',['title'=>$title,'content'=>$content]);
}
}