Topichub.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 圈子中心
  7. */
  8. class Topichub extends Api
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = ['*'];
  12. //圈子广场,全部圈子
  13. public function lists(){
  14. $list = Db::name('topic_hub')->where('status',1)->order('weight desc,id desc')->autopage()->select();
  15. $list = list_domain_image($list,['image']);
  16. $this->success('success',$list);
  17. }
  18. //某个圈子详情
  19. /*public function info_old(){
  20. $id = input('id',0);
  21. $info = Db::name('topic_hub')->where(['status'=>1,'id'=>$id])->find();
  22. $info = info_domain_image($info,['image']);
  23. //圈子成员
  24. $user_list = Db::name('topic_user')->alias('tp')
  25. ->field('tp.user_id,user.avatar,user.nickname,user.gender,user.cityname,user.longitude,user.latitude')
  26. ->join('user','tp.user_id = user.id','LEFT')
  27. ->where('topic_id',$id)->autopage()->select();
  28. $user_list = list_domain_image($user_list,['avatar']);
  29. $info['userlist'] = $user_list;
  30. //我是否已加入
  31. $isjoin = Db::name('topic_user')->where(['topic_id'=>$id,'user_id'=>$this->auth->id])->find();
  32. $info['isjoin'] = $isjoin ? 1 : 0;
  33. $this->success('success',$info);
  34. }*/
  35. public function info(){
  36. $id = input('id',0);
  37. $info = Db::name('topic_hub')->where(['status'=>1,'id'=>$id])->find();
  38. $info = info_domain_image($info,['image']);
  39. $this->success('success',$info);
  40. }
  41. //加入某个圈子
  42. /*public function join_topic(){
  43. $id = input('topic_id',0);
  44. if(empty($id)){
  45. $this->error();
  46. }
  47. $check = Db::name('topic_user')->where(['user_id'=>$this->auth->id,'topic_id'=>$id])->find();
  48. if($check){
  49. $this->error('已经关注了此圈子');
  50. }
  51. $data = [
  52. 'user_id' => $this->auth->id,
  53. 'topic_id'=> $id,
  54. ];
  55. Db::startTrans();
  56. $new_id = Db::name('topic_user')->insertGetId($data);
  57. $rs = Db::name('topic_hub')->where('id',$id)->setInc('p_number');
  58. if($new_id && $rs){
  59. Db::commit();
  60. $this->success();
  61. }
  62. Db::rollback();
  63. $this->error('操作失败');
  64. }*/
  65. //退出某个圈子
  66. /*public function leave_topic(){
  67. $id = input('topic_id',0);
  68. if(empty($id)){
  69. $this->error();
  70. }
  71. $check = Db::name('topic_user')->where(['user_id'=>$this->auth->id,'topic_id'=>$id])->find();
  72. if(!$check){
  73. $this->error('没有关注此圈子');
  74. }
  75. Db::startTrans();
  76. $del = Db::name('topic_user')->where(['user_id'=>$this->auth->id,'topic_id'=>$id])->delete();
  77. $rs = Db::name('topic_hub')->where('id',$id)->setDec('p_number');
  78. if($del && $rs){
  79. Db::commit();
  80. $this->success();
  81. }
  82. Db::rollback();
  83. $this->error('操作失败');
  84. }*/
  85. //我的圈子列表
  86. /*public function my_lists(){
  87. $list = Db::name('topic_user')->alias('tu')
  88. ->field('th.*')
  89. ->join('topic_hub th','tu.topic_id = th.id','LEFT')
  90. ->where(['tu.user_id' => $this->auth->id,'th.status'=>1])->order('tu.id desc,th.weight desc,th.id desc')->autopage()->select();
  91. $list = list_domain_image($list,['image']);
  92. $this->success('success',$list);
  93. }*/
  94. //热门圈子。头部圈子N个,每个圈子拿出最热的一个(评论最多的一个)
  95. public function top_list(){
  96. $list = Db::name('topic_hub')->field('id,name')->where(['status'=>1])->order('weight desc,p_number desc,t_number desc')->autopage()->select();
  97. if(empty($list)){
  98. $this->success('success',$list);
  99. }
  100. foreach($list as $key => $val){
  101. $child = Db::name('topic_dongtai')->alias('dt')
  102. ->field('dt.id,dt.content,dt.images,user.nickname')
  103. ->join('user','dt.user_id = user.id','LEFT')
  104. ->where('dt.topic_id',$val['id'])
  105. ->order('goodnum desc')->find();
  106. $child = info_domain_image($child,['images']);
  107. if(!empty($child)){
  108. $child['images'] = explode(',',$child['images'])[0];
  109. }
  110. $list[$key]['child'] = $child;
  111. }
  112. $this->success('success',$list);
  113. }
  114. //某个圈子里的动态列表,全部,最新,最热
  115. //放到 topicdongtai.php里了
  116. //热门话题
  117. public function hottopic() {
  118. $list = Db::name('topic_hub')->field('id, name, image, t_number, icon_type')->where('status',1)->order('weight desc,id desc')->autopage()->select();
  119. $list = list_domain_image($list,['image']);
  120. if ($list) {
  121. $where['a.status'] = 0; //是否已删除:0=否,1=是
  122. $where['a.auit_status'] = 1; //审核状态:0=待审核,1=通过,2=拒绝
  123. $where['user.is_kefu'] = 0;
  124. if ($this->auth->gender == 1) { //男看女
  125. $where['user.gender'] = 0;
  126. } elseif ($this->auth->gender == 0) { //女看男
  127. $where['user.gender'] = 1;
  128. } else {
  129. $this->success('success', []);
  130. }
  131. $mt_topic_dongtai = Db::name('topic_dongtai a');
  132. foreach ($list as &$v) {
  133. $where['a.topic_id'] = $v['id'];
  134. $v['t_number'] = $mt_topic_dongtai
  135. ->join('mt_user user', 'a.user_id = user.id', 'left')
  136. ->where($where)->count('a.id');
  137. }
  138. }
  139. $this->success('success',$list);
  140. }
  141. //热门话题详情
  142. public function hottopicinfo() {
  143. $id = input('id', 0, 'intval'); //热门话题id
  144. $info = Db::name('topic_hub')->field('id, name, info, image, t_number, icon_type')->where(['status'=>1,'id'=>$id])->find();
  145. if (!$info) {
  146. $this->error('您的网络开小差了~');
  147. }
  148. $info = info_domain_image($info,['image']);
  149. if ($info) {
  150. $where['a.status'] = 0; //是否已删除:0=否,1=是
  151. $where['a.auit_status'] = 1; //审核状态:0=待审核,1=通过,2=拒绝
  152. $where['user.is_kefu'] = 0;
  153. if ($this->auth->gender == 1) { //男看女
  154. $where['user.gender'] = 0;
  155. } elseif ($this->auth->gender == 0) { //女看男
  156. $where['user.gender'] = 1;
  157. } else {
  158. $this->success('success', []);
  159. }
  160. $mt_topic_dongtai = Db::name('topic_dongtai a');
  161. $where['a.topic_id'] = $info['id'];
  162. $info['t_number'] = $mt_topic_dongtai
  163. ->join('mt_user user', 'a.user_id = user.id', 'left')
  164. ->where($where)->count('a.id');
  165. }
  166. $this->success('success',$info);
  167. }
  168. }