model = new ContentModel; } /** * 获取事件列表 * @param $offset * @param $limit */ public function getContentList() { $data = $this->request->post(); if($this->request->isPost()){ $uid = isset($data['token'])&&!empty($data['token'])?$this->auth->id: 0; $where = json_decode(htmlspecialchars_decode($data['filter']),true); if($where){ $search['where'] = $where; $search['user_id'] = $uid; $this->setsearch($search); } $order = ''; $offset = $data['offset']; $limit = $data['limit']; $list = $this->model->getlist($where, $order, $offset, $limit,$uid); return $this->success('获取成功',$list); } return $this->error("非法请求"); } /** * 获取用户事件列表 * @param $offset * @param $limit */ public function getUserContentList(){ $data = $this->request->post(); if($this->request->isPost()&&$data['user_id']){ $where['user_id'] = $data['user_id']; $where['content_type_id'] = $data['content_type_id']; $order = ''; $offset = $data['offset']; $limit = $data['limit']; $uid = isset($data['token'])&&!empty($data['token'])?$this->auth->id: 0; $list = $this->model->getlist($where, $order, $offset, $limit,$uid); return $this->success('获取成功',$list); } return $this->error("非法请求"); } public function getJoinContentList(){ $data = $this->request->post(); if($this->request->isPost()){ //查询关联的信息id $join = Mainjoin::where(['main_id'=>$data['id']])->column('content_id'); $list = []; if(!empty($join)){ $where['id'] = $join; $order = ['readnum'=>'desc']; $offset = empty($data['offset']) ? 0 : $data['offset']; $limit = empty($data['limit']) ? 6 : $data['limit']; $uid = isset($data['token'])&&!empty($data['token'])?$this->auth->id: 0; $list = $this->model->getlist($where, $order, $offset, $limit,$uid); } return $this->success('获取成功',$list); } return $this->error("非法请求"); } /** * 发布事件接口 * @param $offset * @param $limit */ public function setContent(){ if($this->request->post()){ $data = $this->request->param(); $zhengren = $data['zhengren']?json_decode(htmlspecialchars_decode($data['zhengren']),true):''; unset($data['zhengren']); Db::startTrans(); $data['user_id'] = $this->auth->id; $data['createtime'] = date("Y-m-d H:i:s"); $data['content_tag'] = htmlspecialchars_decode($data['content_tag']); unset($data['token']); try { $cid = $this->model->insertGetId($data); if ($cid&&!empty($zhengren)) { foreach ($zhengren as $key => &$value) { $value['content_id'] = $cid; $value['createtime'] = date("Y-m-d H:i:s"); unset($value['addressArr']); unset($value['id']); } if(!Zhengren::insertAll($zhengren)) throw new Exception("发布事件失败"); } else { throw new Exception("发布事件失败"); } Db::commit(); } catch (Exception $e) { Db::rollback(); return $this->error($e->getMessage()); } $this->success('发布成功,等待审核', $data); } return $this->error("非法请求"); } //重新发起申请 public function reapply(){ $data = $this->request->post(); if($this->request->isPost()){ $id = $data['id']; $content = $this->model->get($id); if($content['status']==-1){ $content->status = 0; $content->reason = ''; $content->save(); return $this->success('重新申请成功'); }else{ return $this->error('重新申请失败'); } } } public function getContentdetail(){ if($this->request->isPost()){ $logModel = new LogModel; $id = $this->request->post('id'); $post = $this->request->post(); $data = $this->model->get($id); if(isset($post['token']) && !empty($post['token']) && $this->auth->id){ $userin = User::get($this->auth->id); $playinfo = $logModel->where('type',3)->where('content_id',$id)->where('user_id',$this->auth->id)->find(); if(empty($playinfo)){ $this->operaContentneibu(['content_id'=>$id,'type'=>3,'user_id'=>$this->auth->id]); } $order = Order::where(['content_id'=>$data['id'],'user_id'=>$this->auth->id,'status'=>1])->find(); //判断是否是云股东 if($userin['is_vip']&&$userin['vipout_time']>time()&&$userin['read_num']>0&&empty($order)){ $order['content_id'] = $data['id']; $order['user_id'] = $this->auth->id; $order['order_no'] = "YGD".Random::numeric(15); $order['money'] = 0; $order['createtime'] = date('Y-m-d H:i:s',time()); $order['paytime'] = date('Y-m-d H:i:s',time()); $order['ispay'] = 1; $order['status'] = 1; $order['paytype'] = "云股东权益"; $order['user_money'] = 0; $order['system_money'] = 0; Order::insertGetId($order); $userin->read_num = $userin['read_num']-1; $userin->save(); } } //查询发布人信息 $userinfo = User::get($data['user_id']); $data['avatar'] = empty($userinfo)?'':$userinfo['avatar']; $data['nickname'] = empty($userinfo)?'':$userinfo['nickname']; $data['is_like'] = 0; $data['is_sc'] = 0; $data['is_read'] = 0; $data['payed'] = 0; $data['is_guanzhu'] = 0; $data['content_tag'] = json_decode($data['content_tag'],true); if(isset($post['token']) && !empty($post['token']) && $this->auth->id){ $myuid = $this->auth->id; $order = Order::where(['content_id'=>$data['id'],'user_id'=>$myuid,'status'=>1])->find(); $data['payed'] = $order||$data['user_id']==$myuid?1:0; //查询当前用户是否已经关注 $playinfo = $logModel->where('type',1)->where('content_id',$data['id'])->where('user_id',$myuid)->find(); $data['is_like'] = $playinfo?1:0; $playinfo = $logModel->where('type',2)->where('content_id',$data['id'])->where('user_id',$myuid)->find(); $data['is_sc'] = $playinfo?1:0; $playinfo = $logModel->where('type',3)->where('content_id',$data['id'])->where('user_id',$myuid)->find(); $data['is_read'] = $playinfo?1:0; //当前用户是否关注该用户 $guanzhu = Friend::where(['user_id'=>$myuid,'children_id'=>$data['user_id']])->find(); $data['is_guanzhu'] = $guanzhu?1:0; } return $this->success('获取成功',$data??[]); } $this->error("非法请求"); } // 事件操作接口 public function operaContent(){ $data = $this->request->post(); if($this->request->post()){ $insert['content_id'] = $data['content_id']; $insert['type'] = $data['type']; $insert['user_id'] = $this->auth->id; DB::startTrans(); try { $logModel = new LogModel; $playinfo = $this->model->get($data['content_id']); //查询是否存在该记录 $loginfo = $logModel->where($insert)->find(); //取消操作 if(isset($data['is_del']) && $data['is_del']){ if(!$loginfo) throw new Exception("操作繁忙,请歇一会"); $loginfo->deletetime = date("Y-m-d H:i:s",time()); if(!$loginfo->save()) throw new Exception("操作繁忙,请歇一会"); //修改主表点赞喜欢数量 if($data['type']==1){ $playinfo->likenum = $playinfo->likenum - 1; }else if($data['type']==2){ $playinfo->scnum = $playinfo->scnum - 1; }else if($data['type']==3){ $playinfo->readnum = $playinfo->readnum - 1; } }else{ //点赞喜欢操作 $insert['createtime'] = date("Y-m-d H:i:s",time()); if($loginfo && !$loginfo['deletetime']) throw new Exception("操作繁忙,请歇一会"); if(!$logModel->insert($insert)) throw new Exception("操作繁忙,请歇一会"); //修改主表点赞喜欢数量 if($data['type']==1){ $playinfo->likenum = $playinfo->likenum + 1; }else if($data['type']==2){ $playinfo->scnum = $playinfo->scnum + 1; }else if($data['type']==3){ $playinfo->readnum = $playinfo->readnum + 1; } } if(!$playinfo->save()) throw new Exception("操作繁忙,请歇一会"); DB::commit(); return $this->success("成功"); } catch (Exception $e) { DB::rollback(); return $this->error($e->getMessage()); } } $this->error("非法请求"); } public function operaContentneibu($data){ if($this->request->post()){ $insert['content_id'] = $data['content_id']; $insert['type'] = $data['type']; $insert['user_id'] = $data['user_id']; DB::startTrans(); try { $logModel = new LogModel; $playinfo = $this->model->get($data['content_id']); //查询是否存在该记录 $loginfo = $logModel->where($insert)->find(); //取消操作 if(isset($data['is_del']) && $data['is_del']){ if(!$loginfo) throw new Exception("操作繁忙,请歇一会"); $loginfo->deletetime = date("Y-m-d H:i:s",time()); if(!$loginfo->save()) throw new Exception("操作繁忙,请歇一会"); //修改主表点赞喜欢数量 if($data['type']==1){ $playinfo->likenum = $playinfo->likenum - 1; }else if($data['type']==2){ $playinfo->scnum = $playinfo->scnum - 1; }else if($data['type']==3){ $playinfo->readnum = $playinfo->readnum - 1; } }else{ //点赞喜欢操作 $insert['createtime'] = date("Y-m-d H:i:s",time()); if($loginfo && !$loginfo['deletetime']) throw new Exception("操作繁忙,请歇一会"); if(!$logModel->insert($insert)) throw new Exception("操作繁忙,请歇一会"); //修改主表点赞喜欢数量 if($data['type']==1){ $playinfo->likenum = $playinfo->likenum + 1; }else if($data['type']==2){ $playinfo->scnum = $playinfo->scnum + 1; }else if($data['type']==3){ $playinfo->readnum = $playinfo->readnum + 1; } } if(!$playinfo->save()) throw new Exception("操作繁忙,请歇一会"); DB::commit(); return true; } catch (Exception $e) { DB::rollback(); return false; } } $this->error("非法请求"); } public function getContentTag(){ $tag = TagModel::field('id,title')->select(); $this->success('返回成功', $tag); } public function setpinglun(){ $data = $this->request->post(); if($this->request->post()){ $data['user_id'] = $this->auth->id; $data['createtime'] = date("Y-m-d H:i:s"); $data['content_id'] = $data['content_id']; $data['content'] = $data['content']; if(isset($data['image']) && $data['image']){ $data['image'] = $data['image']; } unset($data['id']); unset($data['token']); $result = Pinglun::create($data); if($result)return $this->success('评论成功'); return $this->error('评论失败'); } return $this->error('非法请求'); } public function getpinglun(){ $data = $this->request->post(); if($this->request->post()){ $list = Pinglun::where(['content_id'=>$data['content_id']])->order('createtime desc')->select(); return $this->success('获取成功', $list); } return $this->error('非法请求'); } public function getzhengren(){ $data = $this->request->post(); if($this->request->post()){ $list = Zhengren::where(['content_id'=>$data['content_id']])->order('createtime desc')->select(); return $this->success('获取成功', $list); } return $this->error('非法请求'); } public function setsearch($data){ //添加搜索记录 $insert['user_id'] = $data['user_id']; $insert['content'] = json_encode($data['where']); foreach ($data['where'] as $key => $value) { if(empty($value)) unset($data['where'][$key]); } $insert['title'] = implode(',',array_values($data['where'])); $insert['createtime'] = date("Y-m-d H:i:s",time()); if(!empty($insert['title'])){ if(Search::insert($insert)){ return true; }else{ return false; } } return false; } public function getsearchlist(){ //获取搜索记录 $lianxiang =[]; $data = $this->request->post(); $uid = isset($data['token'])&&!empty($data['token'])?$this->auth->id:0; $list = Search::where('user_id',$uid)->order('createtime desc')->limit(0,10)->select(); foreach($list as $key => &$val){ $val['content'] = json_decode($val['content'],true); } //查询联想内容 //查询次数多的内容 $lianxiang = Search::where('user_id',$uid)->order('createtime desc')->select(); //获取信息 $keyword = array_column($lianxiang,'title'); $keyword = array_count_values($keyword); arsort($keyword); $top_strings = array_keys($keyword); $top_strings = array_slice($top_strings, 0, 1); $returnlx = Search::where("title","like",$top_strings[0])->order('createtime desc')->limit(0,10)->select(); foreach($returnlx as $ke => &$va){ $va['content'] = json_decode($va['content'],true); } $rerurn = ['list'=>$list,'lianxiang'=>$returnlx]; return $this->success('获取成功', $rerurn); } public function delsearch(){ //获取搜索记录 $data = $this->request->post(); if($this->request->post()){ $uid = $this->auth->id; if(Search::where('user_id',$uid)->delete()){ return $this->success('已清除'); }else{ return $this->error('暂无搜索记录'); } } } public function getreadcontentlist(){ $data = $this->request->post(); if($this->request->post()){ $uid = $this->auth->id; $type = $data['type']; $logModel = new LogModel; $ids = $logModel->where('user_id',$uid)->where('type',$type)->column('content_id'); $offset = $data['offset']; $limit = $data['limit']; $order = ['createtime'=>'desc']; $where = json_decode(htmlspecialchars_decode($data['filter']),true); $where['ids'] = $ids; $list = $this->model->getlist($where, $order, $offset, $limit,$uid); return $this->success('获取成功', $list); } return $this->error('非法请求'); } }