...
|
...
|
@@ -4,7 +4,9 @@ namespace app\api\controller; |
|
|
|
|
|
use app\api\model\Idea;
|
|
|
use app\api\model\IdeaComment;
|
|
|
use app\api\model\IdeaType;
|
|
|
use app\common\controller\Api;
|
|
|
use fast\Http;
|
|
|
use think\Config;
|
|
|
use think\Db;
|
|
|
|
...
|
...
|
@@ -72,7 +74,6 @@ class Index extends Api |
|
|
* @ApiParams (name=pepole_number, type=int, required=false, description="参与人数")
|
|
|
* @ApiParams (name=time, type=int, required=false, description="体验时长")
|
|
|
* @ApiParams (name=type, type=int, required=false, description="分类id")
|
|
|
* @ApiParams (name=num, type=int, required=false, description="页数 默认第一页")
|
|
|
* @ApiReturn ({
|
|
|
'code':'1',
|
|
|
'msg':'搜索分类列表'
|
...
|
...
|
@@ -102,8 +103,6 @@ class Index extends Api |
|
|
$time = $this->request->post('time');
|
|
|
$type = $this->request->post('type');
|
|
|
$text = $this->request->post('text');
|
|
|
$num = $this->request->post('num');
|
|
|
$num = $num ? $num : 1;
|
|
|
$where = [];
|
|
|
if (is_numeric($city)) $where['idea_area_id'] = $city;
|
|
|
if (is_numeric($weather)) $where['idea_weather_id'] = $weather;
|
...
|
...
|
@@ -115,13 +114,14 @@ class Index extends Api |
|
|
$list = $ideaModel
|
|
|
->where($where)
|
|
|
->field('id,title')
|
|
|
->paginate(10,false,['page'=>$num]);
|
|
|
->limit(20)
|
|
|
->select();
|
|
|
$list = $list->toArray();
|
|
|
foreach ($list['data'] as $key=>$value){
|
|
|
foreach ($list as $key=>$value){
|
|
|
$db = Db::name('user_idea_record')->where('user_id',$this->auth->id)->where('idea_id',$value['id'])->where('type',2)->value('id');
|
|
|
$list['data'][$key]['collection_status'] = $db ? 1:0;
|
|
|
$list[$key]['collection_status'] = $db ? 1:0;
|
|
|
$db = Db::name('user_idea_record')->where('user_id',$this->auth->id)->where('idea_id',$value['id'])->where('type',1)->value('id');
|
|
|
$list['data'][$key]['experience_status'] = $db ? 1:0;
|
|
|
$list[$key]['experience_status'] = $db ? 1:0;
|
|
|
|
|
|
}
|
|
|
$this->success('条件搜索列表',['list'=>$list]);
|
...
|
...
|
@@ -165,6 +165,7 @@ class Index extends Api |
|
|
->where('id',$id)
|
|
|
->find();
|
|
|
if (!$detail) $this->error('点子不存在');
|
|
|
//统计用户每日点子浏览次数
|
|
|
$time = strtotime(date('Y-m-d'));
|
|
|
$times = Db::name('user_everyday_times')
|
|
|
->where('user_id',$this->auth->id)
|
...
|
...
|
@@ -176,17 +177,23 @@ class Index extends Api |
|
|
}else{
|
|
|
Db::name('user_everyday_times')->insertGetId(['user_id'=>$this->auth->id,'time'=>$time,'times'=>1]);
|
|
|
}
|
|
|
$detail->visible(['title','id','all_number','collection','idea_type_id','duration','mid_feel']);
|
|
|
$detail->visible(['title','id','ideaType','all_number','collection','idea_type_id','duration','mid_feel']);
|
|
|
$detail = $detail->toArray();
|
|
|
//查找点子分类名称
|
|
|
$ideatype = explode(',',$detail['idea_type_id']);
|
|
|
foreach ($ideatype as $key => $value){
|
|
|
$detail['idea_type'][] = Db::name('idea_type')->where('id',$value)->value('name');
|
|
|
$detail['idea_type'][] = IdeaType::where('id',$value)->find()->visible(['name']);
|
|
|
}
|
|
|
//收藏状态
|
|
|
$db = Db::name('user_idea_record')->where('user_id',$this->auth->id)->where('idea_id',$id)->where('type',2)->value('id');
|
|
|
$detail['collection_status'] = $db ? 1:0;
|
|
|
//体验状态
|
|
|
$db = Db::name('user_idea_record')->where('user_id',$this->auth->id)->where('idea_id',$id)->where('type',1)->value('id');
|
|
|
$detail['experience_status'] = $db ? 1:0;
|
|
|
|
|
|
//体验过的用户头像
|
|
|
$db = Db::name('user_idea_record')->where('idea_id',$id)->where('type',1)->limit(50)->column('user_id');
|
|
|
$user = Db::name('user')->whereIn('id',$db)->field('id,avatar')->select();
|
|
|
$detail['user_avatars'] = $user;
|
|
|
$this->success('点子详情',['detail'=>$detail]);
|
|
|
}
|
|
|
|
...
|
...
|
@@ -381,6 +388,11 @@ class Index extends Api |
|
|
if (!$validate->check($data)){
|
|
|
$this->error($validate->getError());
|
|
|
}
|
|
|
$msg = $this->checkMsg($this->auth->id,$comment);
|
|
|
$msg = json_decode($msg,true);
|
|
|
if ($msg['errcode'] != 0 || $msg['result']['label'] != 100){
|
|
|
$this->error('您的评论违规,请修改');
|
|
|
}
|
|
|
if ($images){
|
|
|
$images = str_replace('"','"',$images);
|
|
|
$imgarr = json_decode($images,true);
|
...
|
...
|
@@ -500,4 +512,46 @@ class Index extends Api |
|
|
}
|
|
|
$this->success('SUCCESS');
|
|
|
}
|
|
|
|
|
|
protected function getAccessToken()
|
|
|
{
|
|
|
$url = 'https://api.weixin.qq.com/cgi-bin/token';
|
|
|
$appid = Config::get('site.appid');
|
|
|
$secret = Config::get('site.secret');
|
|
|
$data = [
|
|
|
'grant_type' => 'client_credential',
|
|
|
'appid' => $appid,
|
|
|
'secret' => $secret,
|
|
|
];
|
|
|
$wechattoken = Http::get($url, $data);
|
|
|
$wechattoken = json_decode($wechattoken, true);
|
|
|
if (isset($wechattoken['errcode'])){
|
|
|
$this->error($wechattoken['errmsg']);
|
|
|
}
|
|
|
return $wechattoken['access_token'];
|
|
|
}
|
|
|
|
|
|
protected function checkMsg($userid,$msg)
|
|
|
{
|
|
|
$access_token = $this->getAccessToken();
|
|
|
$openid = Db::name('third')->where('user_id',$userid)->value('openid');
|
|
|
$url = 'https://api.weixin.qq.com/wxa/msg_sec_check?access_token='.$access_token;
|
|
|
$data = [
|
|
|
'version'=>2,
|
|
|
'openid'=>$openid,
|
|
|
'scene'=>2,
|
|
|
'content'=>$msg,
|
|
|
];
|
|
|
$data = json_encode($data);
|
|
|
$curl = curl_init();
|
|
|
curl_setopt($curl, CURLOPT_URL, $url);
|
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
|
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
|
|
|
curl_setopt($curl, CURLOPT_POST, TRUE);
|
|
|
curl_setopt($curl, CURLOPT_POSTFIELDS,$data);
|
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
|
|
|
$output = curl_exec($curl);
|
|
|
curl_close($curl);
|
|
|
return $output;
|
|
|
}
|
|
|
} |
...
|
...
|
|