123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545 |
- <?php
- // +----------------------------------------------------------------------
- // | ThinkAdmin
- // +----------------------------------------------------------------------
- // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
- // +----------------------------------------------------------------------
- // | 官方网站: http://demo.thinkadmin.top
- // +----------------------------------------------------------------------
- // | 开源协议 ( https://mit-license.org )
- // +----------------------------------------------------------------------
- // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
- // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
- // +----------------------------------------------------------------------
- namespace app\api\controller;
- use app\api\controller\Base;
- use think\Db;
- use think\Model;
- /**
- * @title 咨询管理
- * @controller Consult
- * @group member
- */
- class Consult extends Base
- {
- function initialize(){
- $this->check_login();
- }
- /**
- * @title 发布咨询
- * @desc 发布咨询
- * @author QGF
- * @url /api/Consult/add_consult
- * @method GET
- * @tag 发布咨询
- * @header name:Authorization require:1 desc:Token
- * @param name:content type:string require:1 default:-- desc:要咨询的问题
- */
- public function add_consult(){
- $uid = $this->uid;
- $content = input('content');
- if(empty($content)){
- $this->error('参数错误');
- }
- $data = array(
- 'user_id' => $uid,
- 'type' => 1
- );
- Db::name('store_consult')->insert($data);
- $consult_id = Db::name('store_consult')->getLastInsID();
- Db::name('store_consult')->where('id',$consult_id)->update(array('root_comment_id'=>$consult_id));
- $this->success('发布成功');
- }
- /**
- * @title 论坛列表
- * @desc 论坛列表
- * @author QGF
- * @url /api/Forum/forum_list
- * @method GET
- * @tag 论坛列表
- * @header name:Authorization require:1 desc:Token
- * @param name:page type:int require:0 default:1 desc:页数(默认为1)
- * @param name:page_size type:int require:0 default:10 desc:每页数量(默认为10)
- * @param name:keyword type:string require:0 default:-- desc:搜索的关键词(PC端)
- * @return name:user_id type:int default:-- desc:内容提供者(发布者)ID
- * @return name:title type:string default:-- desc:论坛标题
- * @return name:images type:array default:-- desc:论坛图片(数组)
- * @return name:create_at type:string default:-- desc:发布时间
- * @return name:is_like type:int default:-- desc:是否点赞(0:未点赞,1:已点赞)
- * @return name:is_attention type:int default:-- desc:是否关注(0:未关注,1:已关注)
- * @return name:user_name type:string default:-- desc:内容提供者名称
- * @return name:user_headimg type:string default:-- desc:内容提供者头像
- * @return name:ID type:int default:-- desc:论坛ID
- */
- public function forum_list(){
- $uid = $this->uid;
- $page = input('page',1);
- $pageSize = input('page_size',10);
- $keyword = input('keyword');
- if($keyword){
- $where = "title like '%".$keyword."%'";
- }else{
- $where = "id > 0";
- }
- $list = Db::name('store_forum')->field('id,user_id,title,images,create_at')->where('is_deleted',0)->where('user_id','<>',$uid)->where($where)->group('user_id')->page($page,$pageSize)->order('id','desc')->select();
- if($list){
- foreach ($list as &$value){
- $like_id = Db::name('store_forum_like')->where('forum_id',$value['id'])->where('user_id',$uid)->where('status',1)->value('id');
- $value['is_like'] = $like_id?1:0;
- $attention_id = Db::name('store_forum_attention')->where('user_id',$uid)->where('from_user_id',$value['user_id'])->where('status',1)->value('id');
- $value['is_attention'] = $attention_id?1:0;
- $forum_member_info = Db::name('store_member')->field('name,headimg')->where('id',$value['user_id'])->find();
- $value['images'] = image_path($value['images']);
- $value['user_name'] = $forum_member_info['name'];
- $value['user_headimg'] = $forum_member_info['headimg'];
- $value['ID'] = $value['id'];
- unset($value['id']);
- }
- }
- $this->success('获取成功',$list);
- }
- /**
- * @title 论坛管理(内容提供者)
- * @desc 论坛管理(内容提供者)
- * @author QGF
- * @url /api/Forum/forum_manage
- * @method GET
- * @tag 论坛管理(内容提供者)
- * @header name:Authorization require:1 desc:Token
- * @param name:page type:int require:0 default:1 desc:页数(默认为1)
- * @param name:page_size type:int require:0 default:10 desc:每页数量(默认为10)
- * @return name:title type:string default:-- desc:论坛标题
- * @return name:images type:array default:-- desc:论坛图片(数组)
- * @return name:create_at type:string default:-- desc:发布时间
- * @return name:user_name type:string default:-- desc:内容提供者名称
- * @return name:user_headimg type:string default:-- desc:内容提供者头像
- */
- public function forum_manage(){
- $uid = $this->uid;
- $member_info = Db::name('store_member')->field('current_type')->where('id',$uid)->find();
- if($member_info['current_type'] != 2){
- $this->error('请切换至内容提供者');
- }
- $page = input('page',1);
- $pageSize = input('page_size',10);
- $list = Db::name('store_forum')->field('id,user_id,title,images,create_at')->where('is_deleted',0)->where('user_id',$uid)->page($page,$pageSize)->order('id','desc')->select();
- if($list){
- foreach ($list as &$value){
- $value['ID'] = $value['id'];
- $forum_member_info = Db::name('store_member')->field('name,headimg')->where('id',$value['user_id'])->find();
- $value['images'] = image_path($value['images']);
- $value['user_name'] = $forum_member_info['name'];
- $value['user_headimg'] = $forum_member_info['headimg'];
- unset($value['user_id']);
- unset($value['id']);
- }
- }
- $this->success('获取成功',$list);
- }
- /**
- * @title 删除论坛(內容提供者)
- * @desc 删除论坛
- * @author QGF
- * @url /api/Forum/deleted_forum
- * @method GET
- * @tag 删除论坛
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int require:1 default:-- desc:论坛ID
- */
- public function deleted_forum(){
- $uid = $this->uid;
- $id = input('id');
- if(empty($id)){
- $this->error('参数错误');
- }
- $member_info = Db::name('store_member')->field('current_type')->where('id',$uid)->find();
- if($member_info['current_type'] != 2){
- $this->error('请切换至内容提供者');
- }
- $forum_info = Db::name('store_forum')->field('id')->where('id',$id)->where('user_id',$uid)->where('is_deleted',0)->find();
- if(empty($forum_info)){
- $this->error('论坛信息有误');
- }
- Db::name('store_forum')->where('id',$id)->update(array('is_deleted'=>1));
- $this->success('删除成功');
- }
- /**
- * @title 论坛详情
- * @desc 论坛详情
- * @author QGF
- * @url /api/Forum/forum_detail
- * @method GET
- * @tag 论坛详情
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int require:1 default:-- desc:论坛ID
- * @return name:user_id type:int default:-- desc:内容提供者(发布者)ID
- * @return name:title type:string default:-- desc:论坛标题
- * @return name:images type:array default:-- desc:论坛图片(数组)
- * @return name:video type:string default:-- desc:视频地址(没有返回null)
- * @return name:create_at type:string default:-- desc:发布时间
- * @return name:is_like type:int default:-- desc:是否点赞(0:未点赞,1:已点赞)
- * @return name:is_attention type:int default:-- desc:是否关注(0:未关注,1:已关注)
- * @return name:user_name type:string default:-- desc:内容提供者名称
- * @return name:user_headimg type:string default:-- desc:内容提供者头像
- * @return name:ID type:int default:-- desc:论坛ID
- */
- public function forum_detail(){
- $uid = $this->uid;
- $id = input('id');
- if(empty($id)){
- $this->error('参数错误');
- }
- $forum_info = Db::name('store_forum')->field('id,user_id,title,images,video,create_at')->where('id',$id)->where('is_deleted',0)->find();
- if(empty($forum_info)){
- $this->error('论坛信息有误');
- }
- $like_id = Db::name('store_forum_like')->where('forum_id',$id)->where('user_id',$uid)->where('status',1)->value('id');
- $forum_info['is_like'] = $like_id?1:0;
- $attention_id = Db::name('store_forum_attention')->where('user_id',$uid)->where('from_user_id',$forum_info['user_id'])->where('status',1)->value('id');
- $forum_info['is_attention'] = $attention_id?1:0;
- $forum_member_info = Db::name('store_member')->field('name,headimg')->where('id',$forum_info['user_id'])->find();
- $forum_info['images'] = image_path($forum_info['images']);
- $forum_info['user_name'] = $forum_member_info['name'];
- $forum_info['user_headimg'] = $forum_member_info['headimg'];
- $forum_info['ID'] = $forum_info['id'];
- unset($forum_info['id']);
- $this->success('获取成功',$forum_info);
- }
- /**
- * @title 点赞/取消点赞
- * @desc 点赞/取消点赞
- * @author QGF
- * @url /api/Forum/forum_like
- * @method GET
- * @tag 点赞/取消点赞
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int require:1 default:-- desc:论坛ID
- * @param name:type type:int require:1 default:-- desc:类型(0:取消点赞,1:点赞)
- */
- public function forum_like(){
- $uid = $this->uid;
- $id = input('id');
- $type = input('type');
- if(empty($id) || !isset($type)){
- $this->error('参数错误');
- }
- $store_forum = Db::name('store_forum')->field('user_id')->where('id',$id)->where('status',1)->where('is_deleted',0)->find();
- if(empty($store_forum)){
- $this->error('动态信息有误');
- }
- $user_id = $store_forum['user_id'];
- if($uid == $user_id){
- $this->error('不能操作自己');
- }
- $like = Db::name('store_forum_like')->where('user_id',$uid)->where('forum_id',$id)->where('user_id',$uid)->find();
- if($type == 0){ //取消关注
- if(empty($like['status'])){
- $this->error('没点赞无需取消');
- }
- Db::name('store_forum_like')->where('user_id',$uid)->where('forum_id',$id)->update(array('status'=>0));
- }else{
- if(!empty($like['status'])){
- $this->error('已点赞无需继续点赞');
- }
- if($like['id']){
- Db::name('store_forum_like')->where('user_id',$uid)->where('forum_id',$id)->update(array('status'=>1));
- }else{
- $data = array(
- 'user_id' => $uid,
- 'from_user_id' => $user_id,
- 'forum_id' => $id,
- 'status' => 1
- );
- Db::name('store_forum_like')->insert($data);
- }
- }
- $this->success('操作成功');
- }
- /**
- * @title 关注/取消关注
- * @desc 关注/取消关注
- * @author QGF
- * @url /api/Forum/forum_attention
- * @method GET
- * @tag 关注/取消关注
- * @header name:Authorization require:1 desc:Token
- * @param name:user_id type:int require:1 default:-- desc:被关注/取消关注的用户ID
- * @param name:type type:int require:1 default:-- desc:类型(0:取消关注,1:关注)
- */
- public function forum_attention(){
- $uid = $this->uid;
- $user_id = input('user_id');
- $type = input('type');
- if(empty($user_id) || !isset($type)){
- $this->error('参数错误');
- }
- if($uid == $user_id){
- $this->error('不能操作自己');
- }
- $attention = Db::name('store_forum_attention')->where('user_id',$uid)->where('from_user_id',$user_id)->find();
- if($type == 0){ //取消关注
- if(empty($attention['status'])){
- $this->error('没关注无需取消');
- }
- Db::name('store_forum_attention')->where('user_id',$uid)->where('from_user_id',$user_id)->update(array('status'=>0));
- }else{
- if(!empty($attention['status'])){
- $this->error('已关注无需继续关注');
- }
- if($attention['id']){
- Db::name('store_forum_attention')->where('user_id',$uid)->where('from_user_id',$user_id)->update(array('status'=>1));
- }else{
- $data = array(
- 'user_id' => $uid,
- 'from_user_id' => $user_id,
- 'status' => 1
- );
- Db::name('store_forum_attention')->insert($data);
- }
- }
- $this->success('操作成功');
- }
- /**
- * @title 发表评论
- * @desc 发表评论
- * @author QGF
- * @url /api/Forum/forum_comment
- * @method GET
- * @tag 发表评论
- * @header name:Authorization require:1 desc:Token
- * @param name:forum_id type:int require:1 default:-- desc:论坛ID
- * @param name:content type:string require:1 default:-- desc:评论内容
- */
- public function forum_comment(){
- $uid = $this->uid;
- $forum_id = input('forum_id');
- $content = input('content');
- if(empty($forum_id) || empty($content)){
- $this->error('参数错误');
- }
- $store_forum = Db::name('store_forum')->field('user_id')->where('id',$forum_id)->where('status',1)->where('is_deleted',0)->find();
- if(empty($store_forum)){
- $this->error('动态信息有误');
- }
- $user_id = $store_forum['user_id']; //论坛作者的会员ID
- if($uid == $user_id){
- $this->error('不能操作自己');
- }
- $comment_info = Db::name('store_forum_comment')->field('id')->where('user_id',$uid)->where('forum_id',$forum_id)->where('type',1)->find();
- if(!empty($comment_info)){
- $this->error('已评论过该动态');
- }
- $comment_data = array(
- 'user_id' => $uid,
- 'from_user_id' => $user_id,
- 'forum_id' => $forum_id,
- 'content' => $content,
- 'type' => 1
- );
- Db::name('store_forum_comment')->insert($comment_data);
- $comment_id = Db::name('store_forum_comment')->getLastInsID();
- Db::name('store_forum_comment')->where('id',$comment_id)->update(array('root_comment_id'=>$comment_id));
- $this->success('评论成功');
- }
- /**
- * @title 回复评论(留言)
- * @desc 回复评论(留言)
- * @author QGF
- * @url /api/Forum/reply_comment
- * @method GET
- * @tag 回复评论(留言)
- * @header name:Authorization require:1 desc:Token
- * @param name:comment_id type:int require:1 default:-- desc:要留言的评论ID
- * @param name:content type:string require:1 default:-- desc:留言内容
- */
- public function reply_comment(){
- $uid = $this->uid;
- $comment_id = input('comment_id');//要回复的评论ID
- $content = input('content');//回复评论的内容
- if(empty($content) || empty($comment_id)){
- $this->error('参数错误');
- }
- $comment = Db::name('store_forum_comment')->field('forum_id,user_id,root_comment_id')->where('id',$comment_id)->find();
- if(empty($comment)){
- $this->error('要回复的评论不存在');
- }
- if($comment['user_id'] == $uid){
- $this->error('不能回复自己的评论');
- }
- //判断要是否回复过次评论了
- $reply_comment = Db::name('store_forum_comment')->field('id')->where('user_id',$uid)->where('type',2)->where('comment_id',$comment_id)->find();
- if(!empty($reply_comment)){
- $this->error('已回复过此评论');
- }
- $root_comment_id = $comment['root_comment_id']?$comment['root_comment_id']:$comment_id;
- $comment_data = array(
- 'forum_id' => $comment['forum_id'],
- 'user_id' => $uid,
- 'from_user_id' => $comment['user_id'],
- 'content' => $content,
- 'comment_id' => $comment_id,
- 'root_comment_id' => $root_comment_id,
- 'type' => 2
- );
- Db::name('store_forum_comment')->insert($comment_data);
- $this->success('留言成功');
- }
- /**
- * @title 评论列表
- * @desc 评论列表
- * @author QGF
- * @url /api/Forum/comment_list
- * @method GET
- * @tag 评论列表
- * @header name:Authorization require:1 desc:Token
- * @param name:page type:int require:0 default:1 desc:页数(默认为1)
- * @param name:page_size type:int require:0 default:10 desc:每页数量(默认为10)
- * @param name:forum_id type:int require:1 default:-- desc:论坛ID
- * @return name:comment_num type:int default:-- desc:评论数量
- * @return name:comment_list type:array default:-- desc:content:评论内容,create_time:评论时间,headimg:评论者头像,name:评论者名称,reply_comment:留言的内容列表(content:留言内容,create_time:留言时间,to_user_name:回复的人员名称,user_name:留言者名称,user_headimg:留言者头像),ID:评论ID
- */
- public function comment_list(){
- $forum_id = input('forum_id');
- $page = input('page',1);
- $pageSize = input('page_size',10);
- if(empty($forum_id)){
- $this->error('参数错误');
- }
- //评论列表
- $comment_list = Db::name('store_forum_comment')->alias("c")
- ->join('store_member m', 'c.user_id = m.id')
- ->field('c.id,c.content,c.create_time,c.root_comment_id,m.headimg,m.name')
- ->where('forum_id',$forum_id)->where('c.type',1)
- ->page($page,$pageSize)
- ->order('c.id desc')
- ->select();
- if(empty($comment_list)){
- $this->success('暂无评论',array());
- }
- foreach ($comment_list as &$value){
- //查看回复评论
- $value['reply_comment'] = Db::name('store_forum_comment')->field('user_id,content,comment_id,create_time')->where('root_comment_id',$value['root_comment_id'])->where('type',2)->select();
- if($value['reply_comment']){
- foreach ($value['reply_comment'] as &$v){
- $to_user_id = Db::name('store_forum_comment')->where('id',$v['comment_id'])->value('user_id');
- $v['to_user_name'] = Db::name('store_member')->where('id',$to_user_id)->value('name');
- $user_info = Db::name('store_member')->field('name,headimg')->where('id',$v['user_id'])->find();
- $v['user_name'] = $user_info['name'];
- $v['user_headimg'] = $user_info['headimg'];
- unset($v['comment_id']);
- unset($v['user_id']);
- }
- }
- $value['ID'] = $value['id'];
- unset($value['id']);
- unset($value['root_comment_id']);
- }
- $data = array(
- 'comment_num' => Db::name('store_forum_comment')->where('forum_id',$forum_id)->where('type',1)->count('id'),
- 'comment_list' => $comment_list
- );
- $this->success('获取成功',$data);
- }
- /**
- * @title 论坛发布者详情(用户端)
- * @desc 论坛发布者详情(用户端)
- * @author QGF
- * @url /api/Forum/forum_master
- * @method GET
- * @tag 论坛发布者详情(用户端)
- * @header name:Authorization require:1 desc:Token
- * @param name:user_id type:int require:1 default:-- desc:论坛发布者ID
- * @return name:headimg type:string default:-- desc:发布者头像
- * @return name:name type:string default:-- desc:发布者名称
- * @return name:is_like type:int default:-- desc:是否点赞(0:未点赞,1:已点赞)
- * @return name:is_attention type:int default:-- desc:是否关注(0:未关注,1:已关注)
- * @return name:forum_list type:array default:-- desc:user_id:发布者ID,title:论坛标题,images:评论图片(数组),create_at:发布时间,is_like:是否点赞(0:未点赞,1:已点赞),user_name:发布者名称,user_headimg:发布者头像,ID:论坛ID
- */
- public function forum_master(){
- $uid = $this->uid;
- $user_id = input('user_id');
- if(empty($user_id)){
- $this->error('参数错误');
- }
- if($uid == $user_id){
- $this->error('不能操作自己');
- }
- //查看是否已关注
- $is_attention = Db::name('store_forum_attention')->where('user_id',$uid)->where('from_user_id',$user_id)->where('status',1)->count();
- //关注数量
- $attention_num = Db::name('store_forum_attention')->where('from_user_id',$user_id)->where('status',1)->count();
- //点赞数量
- $like_num = Db::name('store_forum_like')->where('from_user_id',$user_id)->where('status',1)->count();
- //动态列表
- $field = 'id,user_id,title,images,create_at';
- $forum_list = Db::name('store_forum')->field($field)->where('user_id',$user_id)->where('status',1)->where('is_deleted',0)->order('id desc')->select();
- $member = Db::name('store_member')->field('headimg,name')->where('id',$user_id)->find();
- $name = $member['name'];
- $headimg = $member['headimg'];
- foreach ($forum_list as &$value){
- $like_id = Db::name('store_forum_like')->where('forum_id',$value['id'])->where('user_id',$uid)->where('status',1)->value('id');
- $value['is_like'] = $like_id?1:0;
- $value['images'] = image_path($value['images']);
- $value['user_name'] = $name;
- $value['user_headimg'] = $headimg;
- $value['ID'] = $value['id'];
- unset($value['id']);
- }
- $data = array(
- 'headimg' => $headimg,
- 'name' => $name,
- 'is_attention' => $is_attention,
- 'attention_num' => $attention_num,
- 'like_num' => $like_num,
- 'forum_list' => $forum_list
- );
- $this->success('获取成功',$data);
- }
- /**
- * @title 我的关注
- * @desc 我的关注
- * @author QGF
- * @url /api/Forum/my_attention
- * @method GET
- * @tag 我的关注
- * @header name:Authorization require:1 desc:Token
- * @param name:page type:int require:0 default:1 desc:页数(默认为1)
- * @param name:page_size type:int require:0 default:10 desc:每页数量(默认为10)
- * @param name:keyword type:string require:0 default:-- desc:搜索的关键词(PC端)
- * @return name:user_id type:int default:-- desc:内容提供者(发布者)ID
- * @return name:title type:string default:-- desc:论坛标题
- * @return name:images type:array default:-- desc:论坛图片(数组)
- * @return name:create_at type:string default:-- desc:发布时间
- * @return name:is_like type:int default:-- desc:是否点赞(0:未点赞,1:已点赞)
- * @return name:is_attention type:int default:-- desc:是否关注(0:未关注,1:已关注)
- * @return name:user_name type:string default:-- desc:内容提供者名称
- * @return name:user_headimg type:string default:-- desc:内容提供者头像
- * @return name:ID type:int default:-- desc:论坛ID
- */
- public function my_attention(){
- $uid = $this->uid;
- $page = input('page',1);
- $pageSize = input('page_size',10);
- $user_id_arr = Db::name('store_forum_attention')->where('user_id',$uid)->where('status',1)->column('from_user_id');
- $list = Db::name('store_forum')->field('id,user_id,title,images,create_at')->where('is_deleted',0)->where('user_id','in',$user_id_arr)->group('user_id')->page($page,$pageSize)->order('id','desc')->select();
- if($list){
- foreach ($list as &$value){
- $like_id = Db::name('store_forum_like')->where('forum_id',$value['id'])->where('user_id',$uid)->where('status',1)->value('id');
- $value['is_like'] = $like_id?1:0;
- $attention_id = Db::name('store_forum_attention')->where('user_id',$uid)->where('from_user_id',$value['user_id'])->where('status',1)->value('id');
- $value['is_attention'] = $attention_id?1:0;
- $forum_member_info = Db::name('store_member')->field('name,headimg')->where('id',$value['user_id'])->find();
- $value['images'] = image_path($value['images']);
- $value['user_name'] = $forum_member_info['name'];
- $value['user_headimg'] = $forum_member_info['headimg'];
- $value['ID'] = $value['id'];
- unset($value['id']);
- }
- }
- $this->success('获取成功',$list);
- }
- }
|