作者 李忠强
1 个管道 的构建 通过 耗费 4 秒

更新

@@ -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 }
@@ -85,6 +85,7 @@ class Mycenter extends Api @@ -85,6 +85,7 @@ class Mycenter extends Api
85 * @ApiMethod (POST) 85 * @ApiMethod (POST)
86 * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") 86 * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
87 * @ApiParams (name=id, type=int, required=true, description="点子id") 87 * @ApiParams (name=id, type=int, required=true, description="点子id")
  88 + * @ApiParams (name=type, type=int, required=true, description="1=体验2=取消体验")
88 * @ApiReturn ({ 89 * @ApiReturn ({
89 'code':'1', 90 'code':'1',
90 'msg':'SUCCESS' 91 'msg':'SUCCESS'
@@ -93,6 +94,7 @@ class Mycenter extends Api @@ -93,6 +94,7 @@ class Mycenter extends Api
93 public function experienceIdea() 94 public function experienceIdea()
94 { 95 {
95 $id = $this->request->post('id'); 96 $id = $this->request->post('id');
  97 + $type = $this->request->post('type');
96 if (!is_numeric($id)){ 98 if (!is_numeric($id)){
97 $this->error('id参数不合法'); 99 $this->error('id参数不合法');
98 } 100 }
@@ -107,26 +109,33 @@ class Mycenter extends Api @@ -107,26 +109,33 @@ class Mycenter extends Api
107 $role[] = Db::name('user_role')->where('id',$v)->find(); 109 $role[] = Db::name('user_role')->where('id',$v)->find();
108 } 110 }
109 } 111 }
110 -  
111 - if(!Db::name('user_idea_record')->where('user_id',$this->auth->id)->where('idea_id',$id)->where('type',1)->value('id')){  
112 - foreach ($ideatype as $key => $value){  
113 - Db::name('user_idea_record')->insert(['user_id'=>$this->auth->id,'idea_id'=>$id,'type'=>1,'idea_type_id'=>$value,'createtime'=>time()]); 112 + if ($type == 1){
  113 + if(!Db::name('user_idea_record')->where('user_id',$this->auth->id)->where('idea_id',$id)->where('type',1)->value('id')){
  114 + foreach ($ideatype as $key => $value){
  115 + Db::name('user_idea_record')->insert(['user_id'=>$this->auth->id,'idea_id'=>$id,'type'=>1,'idea_type_id'=>$value,'createtime'=>time()]);
  116 + }
  117 + foreach ($role as $key => $value){
  118 + Db::name('user_idea_score')->insert(['user_id'=>$this->auth->id,'user_role_id'=>$value['id'],'weigh'=>$value['weigh']]);
  119 + }
114 } 120 }
  121 + Db::name('idea')->where('id',$id)->setInc('all_number');
  122 + Db::name('user')->where('id',$this->auth->id)->setInc('idea_number');
  123 + }elseif ($type == 2){
  124 + Db::name('user_idea_record')->where(['user_id'=>$this->auth->id,'idea_id'=>$id,'type'=>1])->delete();
115 foreach ($role as $key => $value){ 125 foreach ($role as $key => $value){
116 - Db::name('user_idea_score')->insert(['user_id'=>$this->auth->id,'user_role_id'=>$value['id'],'weigh'=>$value['weigh']]); 126 + Db::name('user_idea_score')
  127 + ->where('user_id',$this->auth->id)
  128 + ->where('user_role_id',$value['id'])
  129 + ->limit(1)
  130 + ->delete();
117 } 131 }
  132 + Db::name('idea')->where('id',$id)->setDec('all_number');
  133 + Db::name('user')->where('id',$this->auth->id)->setDec('idea_number');
  134 + }else{
  135 + $this->error('type参数不合法');
118 } 136 }
119 - $strcount = substr_count($idea['avatar_images'],',');  
120 - if ($strcount < 4){  
121 - if ($strcount == 0){  
122 - $data = ['avatar_images'=>$this->auth->avatar];  
123 - }else{  
124 - $data = ['avatar_images'=>$idea['avatar_images'].','.$this->auth->avatar];  
125 - }  
126 - Db::name('idea')->where('id',$id)->update($data);  
127 - }  
128 - Db::name('idea')->where('id',$id)->setInc('all_number');  
129 - Db::name('user')->where('id',$this->auth->id)->setInc('idea_number'); 137 +
  138 +
130 $this->success('SUCCESS'); 139 $this->success('SUCCESS');
131 } 140 }
132 141
@@ -154,6 +163,7 @@ class Mycenter extends Api @@ -154,6 +163,7 @@ class Mycenter extends Api
154 * @ApiSummary (我的界面上半部分角色解析和数据统计) 163 * @ApiSummary (我的界面上半部分角色解析和数据统计)
155 * @ApiMethod (POST) 164 * @ApiMethod (POST)
156 * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") 165 * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  166 + * @ApiParams (name=userid, type=int, required=false, description="请求的Token")
157 * @ApiReturn ({ 167 * @ApiReturn ({
158 'code':'1', 168 'code':'1',
159 'msg':'联系客服' 169 'msg':'联系客服'
@@ -354,46 +364,6 @@ class Mycenter extends Api @@ -354,46 +364,6 @@ class Mycenter extends Api
354 $this->success('我的界面 下',$array); 364 $this->success('我的界面 下',$array);
355 } 365 }
356 366
357 - protected function boxGetAccessToken()  
358 - {  
359 - $url = 'https://api.weixin.qq.com/cgi-bin/token';  
360 - $appid = Config::get('site.appid');  
361 - $secret = Config::get('site.secret');  
362 - $data = [  
363 - 'grant_type' => 'client_credential',  
364 - 'appid' => $appid,  
365 - 'secret' => $secret,  
366 - ];  
367 - $wechattoken = Http::get($url, $data);  
368 - $wechattoken = json_decode($wechattoken, true);  
369 - if (isset($wechattoken['errcode'])){  
370 - $this->error($wechattoken['errmsg']);  
371 - }  
372 - $urls = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token='.$wechattoken['access_token'];  
373 - $data = json_encode(['scene'=>1,'width'=>280]);  
374 - $curl = curl_init();  
375 - curl_setopt($curl,CURLOPT_URL,$urls);  
376 - curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,0);  
377 - curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,2);  
378 - curl_setopt($curl,CURLOPT_HTTPHEADER,array('Expect:'));  
379 - curl_setopt($curl,CURLOPT_FOLLOWLOCATION,1);  
380 - curl_setopt($curl,CURLOPT_AUTOREFERER,1);  
381 - curl_setopt($curl,CURLOPT_POST,1);  
382 - curl_setopt($curl,CURLOPT_POSTFIELDS,$data);  
383 - curl_setopt($curl,CURLOPT_TIMEOUT,30);  
384 - curl_setopt($curl,CURLOPT_HEADER,0);  
385 - curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);  
386 - $tmpInfo = curl_exec($curl);  
387 - if (curl_errno($curl)) {  
388 - $this->error( 'Errno:'.curl_error($curl));  
389 - }  
390 - curl_close($curl);  
391 - if (!file_put_contents(ROOT_PATH.'public/qrcode.png',$tmpInfo)) {  
392 - $this->error('保存二维码失败');  
393 - }  
394 - return 1;  
395 - }  
396 -  
397 //获取用户圆形头像 367 //获取用户圆形头像
398 protected function getAvatar($url) 368 protected function getAvatar($url)
399 { 369 {
@@ -6,21 +6,11 @@ use think\Model; @@ -6,21 +6,11 @@ use think\Model;
6 6
7 class Idea extends Model 7 class Idea extends Model
8 { 8 {
9 - protected $append = [  
10 - 'avatar_text'  
11 - ];  
12 -  
13 - public function getAvatarTextAttr($value,$data)  
14 - {  
15 - $value = isset($data['avatar_images']) && !empty($data['avatar_images']) ? explode(',',$data['avatar_images']) : [];  
16 - foreach ($value as $key => $val){  
17 - $value[$key] = cdnurl($val,true);  
18 - }  
19 - return $value;  
20 - } 9 + protected $append = [];
21 10
22 public function ideaType() 11 public function ideaType()
23 { 12 {
24 return $this->belongsTo('IdeaType','idea_type_id','id'); 13 return $this->belongsTo('IdeaType','idea_type_id','id');
25 } 14 }
  15 +
26 } 16 }

4.3 KB | 宽: | 高:

15.8 KB | 宽: | 高:

  • 两方对比
  • 交换覆盖
  • 透明覆盖