Topichub.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. //全部话题,和下面hottopic重复了,就t_number是全部的,不分性别
  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. //没用到,和下面的hottopicinfo重复了
  19. /*public function info(){
  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. $this->success('success',$info);
  24. }*/
  25. //热门话题
  26. public function hottopic() {
  27. $list = Db::name('topic_hub')->field('id, name, image, t_number, icon_type')->where('status',1)->order('weight desc,id desc')->autopage()->select();
  28. $list = list_domain_image($list,['image']);
  29. if ($list) {
  30. $where['a.status'] = 0; //是否已删除:0=否,1=是
  31. $where['a.auit_status'] = 1; //审核状态:0=待审核,1=通过,2=拒绝
  32. $where['user.is_kefu'] = 0;
  33. if ($this->auth->gender == 1) { //男看女
  34. $where['user.gender'] = 0;
  35. } elseif ($this->auth->gender == 0) { //女看男
  36. $where['user.gender'] = 1;
  37. } else {
  38. $this->success('success', []);
  39. }
  40. $mt_topic_dongtai = Db::name('topic_dongtai a');
  41. foreach ($list as &$v) {
  42. $where['a.topic_id'] = $v['id'];
  43. $v['t_number'] = $mt_topic_dongtai
  44. ->join('mt_user user', 'a.user_id = user.id', 'left')
  45. ->where($where)->count('a.id');
  46. }
  47. }
  48. $this->success('success',$list);
  49. }
  50. //热门话题详情
  51. public function hottopicinfo() {
  52. $id = input('id', 0, 'intval'); //热门话题id
  53. $info = Db::name('topic_hub')->field('id, name, info, image, t_number, icon_type')->where(['status'=>1,'id'=>$id])->find();
  54. if (!$info) {
  55. $this->error('您的网络开小差了~');
  56. }
  57. $info = info_domain_image($info,['image']);
  58. if ($info) {
  59. $where['a.status'] = 0; //是否已删除:0=否,1=是
  60. $where['a.auit_status'] = 1; //审核状态:0=待审核,1=通过,2=拒绝
  61. $where['user.is_kefu'] = 0;
  62. if ($this->auth->gender == 1) { //男看女
  63. $where['user.gender'] = 0;
  64. } elseif ($this->auth->gender == 0) { //女看男
  65. $where['user.gender'] = 1;
  66. } else {
  67. $this->success('success', []);
  68. }
  69. $mt_topic_dongtai = Db::name('topic_dongtai a');
  70. $where['a.topic_id'] = $info['id'];
  71. $info['t_number'] = $mt_topic_dongtai
  72. ->join('mt_user user', 'a.user_id = user.id', 'left')
  73. ->where($where)->count('a.id');
  74. }
  75. $this->success('success',$info);
  76. }
  77. }