|
@@ -4,7 +4,9 @@ namespace app\api\controller; |
|
@@ -4,7 +4,9 @@ namespace app\api\controller; |
4
|
|
4
|
|
5
|
use app\api\model\Idea;
|
5
|
use app\api\model\Idea;
|
6
|
use app\api\model\IdeaComment;
|
6
|
use app\api\model\IdeaComment;
|
|
|
7
|
+use app\api\model\IdeaType;
|
7
|
use app\common\controller\Api;
|
8
|
use app\common\controller\Api;
|
|
|
9
|
+use fast\Http;
|
8
|
use think\Config;
|
10
|
use think\Config;
|
9
|
use think\Db;
|
11
|
use think\Db;
|
10
|
|
12
|
|
|
@@ -72,7 +74,6 @@ class Index extends Api |
|
@@ -72,7 +74,6 @@ class Index extends Api |
72
|
* @ApiParams (name=pepole_number, type=int, required=false, description="参与人数")
|
74
|
* @ApiParams (name=pepole_number, type=int, required=false, description="参与人数")
|
73
|
* @ApiParams (name=time, type=int, required=false, description="体验时长")
|
75
|
* @ApiParams (name=time, type=int, required=false, description="体验时长")
|
74
|
* @ApiParams (name=type, type=int, required=false, description="分类id")
|
76
|
* @ApiParams (name=type, type=int, required=false, description="分类id")
|
75
|
- * @ApiParams (name=num, type=int, required=false, description="页数 默认第一页")
|
|
|
76
|
* @ApiReturn ({
|
77
|
* @ApiReturn ({
|
77
|
'code':'1',
|
78
|
'code':'1',
|
78
|
'msg':'搜索分类列表'
|
79
|
'msg':'搜索分类列表'
|
|
@@ -102,8 +103,6 @@ class Index extends Api |
|
@@ -102,8 +103,6 @@ class Index extends Api |
102
|
$time = $this->request->post('time');
|
103
|
$time = $this->request->post('time');
|
103
|
$type = $this->request->post('type');
|
104
|
$type = $this->request->post('type');
|
104
|
$text = $this->request->post('text');
|
105
|
$text = $this->request->post('text');
|
105
|
- $num = $this->request->post('num');
|
|
|
106
|
- $num = $num ? $num : 1;
|
|
|
107
|
$where = [];
|
106
|
$where = [];
|
108
|
if (is_numeric($city)) $where['idea_area_id'] = $city;
|
107
|
if (is_numeric($city)) $where['idea_area_id'] = $city;
|
109
|
if (is_numeric($weather)) $where['idea_weather_id'] = $weather;
|
108
|
if (is_numeric($weather)) $where['idea_weather_id'] = $weather;
|
|
@@ -115,13 +114,14 @@ class Index extends Api |
|
@@ -115,13 +114,14 @@ class Index extends Api |
115
|
$list = $ideaModel
|
114
|
$list = $ideaModel
|
116
|
->where($where)
|
115
|
->where($where)
|
117
|
->field('id,title')
|
116
|
->field('id,title')
|
118
|
- ->paginate(10,false,['page'=>$num]);
|
117
|
+ ->limit(20)
|
|
|
118
|
+ ->select();
|
119
|
$list = $list->toArray();
|
119
|
$list = $list->toArray();
|
120
|
- foreach ($list['data'] as $key=>$value){
|
120
|
+ foreach ($list as $key=>$value){
|
121
|
$db = Db::name('user_idea_record')->where('user_id',$this->auth->id)->where('idea_id',$value['id'])->where('type',2)->value('id');
|
121
|
$db = Db::name('user_idea_record')->where('user_id',$this->auth->id)->where('idea_id',$value['id'])->where('type',2)->value('id');
|
122
|
- $list['data'][$key]['collection_status'] = $db ? 1:0;
|
122
|
+ $list[$key]['collection_status'] = $db ? 1:0;
|
123
|
$db = Db::name('user_idea_record')->where('user_id',$this->auth->id)->where('idea_id',$value['id'])->where('type',1)->value('id');
|
123
|
$db = Db::name('user_idea_record')->where('user_id',$this->auth->id)->where('idea_id',$value['id'])->where('type',1)->value('id');
|
124
|
- $list['data'][$key]['experience_status'] = $db ? 1:0;
|
124
|
+ $list[$key]['experience_status'] = $db ? 1:0;
|
125
|
|
125
|
|
126
|
}
|
126
|
}
|
127
|
$this->success('条件搜索列表',['list'=>$list]);
|
127
|
$this->success('条件搜索列表',['list'=>$list]);
|
|
@@ -165,6 +165,7 @@ class Index extends Api |
|
@@ -165,6 +165,7 @@ class Index extends Api |
165
|
->where('id',$id)
|
165
|
->where('id',$id)
|
166
|
->find();
|
166
|
->find();
|
167
|
if (!$detail) $this->error('点子不存在');
|
167
|
if (!$detail) $this->error('点子不存在');
|
|
|
168
|
+ //统计用户每日点子浏览次数
|
168
|
$time = strtotime(date('Y-m-d'));
|
169
|
$time = strtotime(date('Y-m-d'));
|
169
|
$times = Db::name('user_everyday_times')
|
170
|
$times = Db::name('user_everyday_times')
|
170
|
->where('user_id',$this->auth->id)
|
171
|
->where('user_id',$this->auth->id)
|
|
@@ -176,17 +177,23 @@ class Index extends Api |
|
@@ -176,17 +177,23 @@ class Index extends Api |
176
|
}else{
|
177
|
}else{
|
177
|
Db::name('user_everyday_times')->insertGetId(['user_id'=>$this->auth->id,'time'=>$time,'times'=>1]);
|
178
|
Db::name('user_everyday_times')->insertGetId(['user_id'=>$this->auth->id,'time'=>$time,'times'=>1]);
|
178
|
}
|
179
|
}
|
179
|
- $detail->visible(['title','id','all_number','collection','idea_type_id','duration','mid_feel']);
|
180
|
+ $detail->visible(['title','id','ideaType','all_number','collection','idea_type_id','duration','mid_feel']);
|
180
|
$detail = $detail->toArray();
|
181
|
$detail = $detail->toArray();
|
|
|
182
|
+ //查找点子分类名称
|
181
|
$ideatype = explode(',',$detail['idea_type_id']);
|
183
|
$ideatype = explode(',',$detail['idea_type_id']);
|
182
|
foreach ($ideatype as $key => $value){
|
184
|
foreach ($ideatype as $key => $value){
|
183
|
- $detail['idea_type'][] = Db::name('idea_type')->where('id',$value)->value('name');
|
185
|
+ $detail['idea_type'][] = IdeaType::where('id',$value)->find()->visible(['name']);
|
184
|
}
|
186
|
}
|
|
|
187
|
+ //收藏状态
|
185
|
$db = Db::name('user_idea_record')->where('user_id',$this->auth->id)->where('idea_id',$id)->where('type',2)->value('id');
|
188
|
$db = Db::name('user_idea_record')->where('user_id',$this->auth->id)->where('idea_id',$id)->where('type',2)->value('id');
|
186
|
$detail['collection_status'] = $db ? 1:0;
|
189
|
$detail['collection_status'] = $db ? 1:0;
|
|
|
190
|
+ //体验状态
|
187
|
$db = Db::name('user_idea_record')->where('user_id',$this->auth->id)->where('idea_id',$id)->where('type',1)->value('id');
|
191
|
$db = Db::name('user_idea_record')->where('user_id',$this->auth->id)->where('idea_id',$id)->where('type',1)->value('id');
|
188
|
$detail['experience_status'] = $db ? 1:0;
|
192
|
$detail['experience_status'] = $db ? 1:0;
|
189
|
-
|
193
|
+ //体验过的用户头像
|
|
|
194
|
+ $db = Db::name('user_idea_record')->where('idea_id',$id)->where('type',1)->limit(50)->column('user_id');
|
|
|
195
|
+ $user = Db::name('user')->whereIn('id',$db)->field('id,avatar')->select();
|
|
|
196
|
+ $detail['user_avatars'] = $user;
|
190
|
$this->success('点子详情',['detail'=>$detail]);
|
197
|
$this->success('点子详情',['detail'=>$detail]);
|
191
|
}
|
198
|
}
|
192
|
|
199
|
|
|
@@ -381,6 +388,11 @@ class Index extends Api |
|
@@ -381,6 +388,11 @@ class Index extends Api |
381
|
if (!$validate->check($data)){
|
388
|
if (!$validate->check($data)){
|
382
|
$this->error($validate->getError());
|
389
|
$this->error($validate->getError());
|
383
|
}
|
390
|
}
|
|
|
391
|
+ $msg = $this->checkMsg($this->auth->id,$comment);
|
|
|
392
|
+ $msg = json_decode($msg,true);
|
|
|
393
|
+ if ($msg['errcode'] != 0 || $msg['result']['label'] != 100){
|
|
|
394
|
+ $this->error('您的评论违规,请修改');
|
|
|
395
|
+ }
|
384
|
if ($images){
|
396
|
if ($images){
|
385
|
$images = str_replace('"','"',$images);
|
397
|
$images = str_replace('"','"',$images);
|
386
|
$imgarr = json_decode($images,true);
|
398
|
$imgarr = json_decode($images,true);
|
|
@@ -500,4 +512,46 @@ class Index extends Api |
|
@@ -500,4 +512,46 @@ class Index extends Api |
500
|
}
|
512
|
}
|
501
|
$this->success('SUCCESS');
|
513
|
$this->success('SUCCESS');
|
502
|
}
|
514
|
}
|
|
|
515
|
+
|
|
|
516
|
+ protected function getAccessToken()
|
|
|
517
|
+ {
|
|
|
518
|
+ $url = 'https://api.weixin.qq.com/cgi-bin/token';
|
|
|
519
|
+ $appid = Config::get('site.appid');
|
|
|
520
|
+ $secret = Config::get('site.secret');
|
|
|
521
|
+ $data = [
|
|
|
522
|
+ 'grant_type' => 'client_credential',
|
|
|
523
|
+ 'appid' => $appid,
|
|
|
524
|
+ 'secret' => $secret,
|
|
|
525
|
+ ];
|
|
|
526
|
+ $wechattoken = Http::get($url, $data);
|
|
|
527
|
+ $wechattoken = json_decode($wechattoken, true);
|
|
|
528
|
+ if (isset($wechattoken['errcode'])){
|
|
|
529
|
+ $this->error($wechattoken['errmsg']);
|
|
|
530
|
+ }
|
|
|
531
|
+ return $wechattoken['access_token'];
|
|
|
532
|
+ }
|
|
|
533
|
+
|
|
|
534
|
+ protected function checkMsg($userid,$msg)
|
|
|
535
|
+ {
|
|
|
536
|
+ $access_token = $this->getAccessToken();
|
|
|
537
|
+ $openid = Db::name('third')->where('user_id',$userid)->value('openid');
|
|
|
538
|
+ $url = 'https://api.weixin.qq.com/wxa/msg_sec_check?access_token='.$access_token;
|
|
|
539
|
+ $data = [
|
|
|
540
|
+ 'version'=>2,
|
|
|
541
|
+ 'openid'=>$openid,
|
|
|
542
|
+ 'scene'=>2,
|
|
|
543
|
+ 'content'=>$msg,
|
|
|
544
|
+ ];
|
|
|
545
|
+ $data = json_encode($data);
|
|
|
546
|
+ $curl = curl_init();
|
|
|
547
|
+ curl_setopt($curl, CURLOPT_URL, $url);
|
|
|
548
|
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
|
|
|
549
|
+ curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
|
|
|
550
|
+ curl_setopt($curl, CURLOPT_POST, TRUE);
|
|
|
551
|
+ curl_setopt($curl, CURLOPT_POSTFIELDS,$data);
|
|
|
552
|
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
|
|
|
553
|
+ $output = curl_exec($curl);
|
|
|
554
|
+ curl_close($curl);
|
|
|
555
|
+ return $output;
|
|
|
556
|
+ }
|
503
|
} |
557
|
} |