Topichub.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. public function __construct(){
  13. exit;//简讯用不到这个
  14. }
  15. //话题列表
  16. public function lists(){
  17. $list = Db::name('topic_hub')->where('status',1)->order('weight desc,id desc')->autopage()->select();
  18. $list = list_domain_image($list,['image']);
  19. $this->success('success',$list);
  20. }
  21. //某个话题详情
  22. public function info(){
  23. $id = input('id',0);
  24. $info = Db::name('topic_hub')->where(['status'=>1,'id'=>$id])->find();
  25. $info = info_domain_image($info,['image','bg_image']);
  26. //是否关注
  27. $is_follow = Db::name('user_follow_topic')->where(['uid'=>$this->auth->id,'topic_id'=>$id])->find();
  28. $info['is_follow'] = !empty($is_follow) ? 1 : 0;
  29. //增加话题浏览次数
  30. Db::name('topic_hub')->where(['status'=>1,'id'=>$id])->setInc('look_number');
  31. $this->success('success',$info);
  32. }
  33. //关注话题
  34. public function follow_one(){
  35. $topic_id = input('topic_id',0);
  36. if(!$topic_id){
  37. $this->error(__('Invalid parameters'));
  38. }
  39. $topic_hub = Db::name('topic_hub')->find($topic_id);
  40. if(empty($topic_hub)){
  41. $this->error('此话题不存在');
  42. }
  43. $map = [
  44. 'uid' => $this->auth->id,
  45. 'topic_id' => $topic_id,
  46. ];
  47. $check = Db::name('user_follow_topic')->where($map)->find();
  48. if($check){
  49. //取关
  50. $rs = Db::name('user_follow_topic')->where($map)->delete();
  51. $this->success('操作成功');
  52. }
  53. $id = Db::name('user_follow_topic')->insertGetId($map);
  54. $this->success('操作成功',$id);
  55. }
  56. }