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

更新

... ... @@ -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;
}
}
... ...
... ... @@ -85,6 +85,7 @@ class Mycenter extends Api
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=id, type=int, required=true, description="点子id")
* @ApiParams (name=type, type=int, required=true, description="1=体验2=取消体验")
* @ApiReturn ({
'code':'1',
'msg':'SUCCESS'
... ... @@ -93,6 +94,7 @@ class Mycenter extends Api
public function experienceIdea()
{
$id = $this->request->post('id');
$type = $this->request->post('type');
if (!is_numeric($id)){
$this->error('id参数不合法');
}
... ... @@ -107,7 +109,7 @@ class Mycenter extends Api
$role[] = Db::name('user_role')->where('id',$v)->find();
}
}
if ($type == 1){
if(!Db::name('user_idea_record')->where('user_id',$this->auth->id)->where('idea_id',$id)->where('type',1)->value('id')){
foreach ($ideatype as $key => $value){
Db::name('user_idea_record')->insert(['user_id'=>$this->auth->id,'idea_id'=>$id,'type'=>1,'idea_type_id'=>$value,'createtime'=>time()]);
... ... @@ -116,17 +118,24 @@ class Mycenter extends Api
Db::name('user_idea_score')->insert(['user_id'=>$this->auth->id,'user_role_id'=>$value['id'],'weigh'=>$value['weigh']]);
}
}
$strcount = substr_count($idea['avatar_images'],',');
if ($strcount < 4){
if ($strcount == 0){
$data = ['avatar_images'=>$this->auth->avatar];
}else{
$data = ['avatar_images'=>$idea['avatar_images'].','.$this->auth->avatar];
}
Db::name('idea')->where('id',$id)->update($data);
}
Db::name('idea')->where('id',$id)->setInc('all_number');
Db::name('user')->where('id',$this->auth->id)->setInc('idea_number');
}elseif ($type == 2){
Db::name('user_idea_record')->where(['user_id'=>$this->auth->id,'idea_id'=>$id,'type'=>1])->delete();
foreach ($role as $key => $value){
Db::name('user_idea_score')
->where('user_id',$this->auth->id)
->where('user_role_id',$value['id'])
->limit(1)
->delete();
}
Db::name('idea')->where('id',$id)->setDec('all_number');
Db::name('user')->where('id',$this->auth->id)->setDec('idea_number');
}else{
$this->error('type参数不合法');
}
$this->success('SUCCESS');
}
... ... @@ -154,6 +163,7 @@ class Mycenter extends Api
* @ApiSummary (我的界面上半部分角色解析和数据统计)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=userid, type=int, required=false, description="请求的Token")
* @ApiReturn ({
'code':'1',
'msg':'联系客服'
... ... @@ -354,46 +364,6 @@ class Mycenter extends Api
$this->success('我的界面 下',$array);
}
protected function boxGetAccessToken()
{
$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']);
}
$urls = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token='.$wechattoken['access_token'];
$data = json_encode(['scene'=>1,'width'=>280]);
$curl = curl_init();
curl_setopt($curl,CURLOPT_URL,$urls);
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,2);
curl_setopt($curl,CURLOPT_HTTPHEADER,array('Expect:'));
curl_setopt($curl,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($curl,CURLOPT_AUTOREFERER,1);
curl_setopt($curl,CURLOPT_POST,1);
curl_setopt($curl,CURLOPT_POSTFIELDS,$data);
curl_setopt($curl,CURLOPT_TIMEOUT,30);
curl_setopt($curl,CURLOPT_HEADER,0);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
$tmpInfo = curl_exec($curl);
if (curl_errno($curl)) {
$this->error( 'Errno:'.curl_error($curl));
}
curl_close($curl);
if (!file_put_contents(ROOT_PATH.'public/qrcode.png',$tmpInfo)) {
$this->error('保存二维码失败');
}
return 1;
}
//获取用户圆形头像
protected function getAvatar($url)
{
... ...
... ... @@ -6,21 +6,11 @@ use think\Model;
class Idea extends Model
{
protected $append = [
'avatar_text'
];
public function getAvatarTextAttr($value,$data)
{
$value = isset($data['avatar_images']) && !empty($data['avatar_images']) ? explode(',',$data['avatar_images']) : [];
foreach ($value as $key => $val){
$value[$key] = cdnurl($val,true);
}
return $value;
}
protected $append = [];
public function ideaType()
{
return $this->belongsTo('IdeaType','idea_type_id','id');
}
}
\ No newline at end of file
... ...

4.3 KB | 宽: | 高:

15.8 KB | 宽: | 高:

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