News.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace app\api\controller\worker;
  3. use app\common\controller\Apiw;
  4. use think\Db;
  5. /**
  6. * 咨询
  7. */
  8. class News extends Apiw
  9. {
  10. protected $noNeedLogin = [''];
  11. protected $noNeedRight = [''];
  12. public function index()
  13. {
  14. //所有分类
  15. $typelist = Db::name('news_type')
  16. ->where('company_id',$this->auth->company_id)
  17. ->order('id' , 'asc')
  18. ->select();
  19. $this->success(1, $typelist);
  20. }
  21. //
  22. public function lists(){
  23. $type_id = input('type_id',0);
  24. $keyword = input('keyword','','trim');
  25. $where = [];
  26. if(!empty($type_id)){
  27. $where['type_id'] = $type_id;
  28. }
  29. if(!empty($keyword)){
  30. $where['title'] = ['LIKE','%'.$keyword.'%'];
  31. }
  32. $list = Db::name('news')->field('content',true)
  33. ->where('company_id',$this->auth->company_id)
  34. ->where($where)
  35. ->autopage()
  36. ->select();
  37. $list = list_domain_image($list,['image']);
  38. $this->success(1, $list);
  39. }
  40. //详情
  41. public function info(){
  42. $id = input('id',0);
  43. $info = Db::name('news')
  44. ->where('id',$id)
  45. ->find();
  46. $info = info_domain_image($info, ['image']);
  47. //收藏
  48. $info['is_collect'] = $this->is_collect($info['id'],$this->auth->id);
  49. $this->success(1, $info);
  50. }
  51. //收藏,取消收藏
  52. public function collect(){
  53. $where = [
  54. 'worker_id' => $this->auth->id,
  55. 'table' => 'news',
  56. 'table_id' => input('id',0),
  57. ];
  58. $check = Db::name('worker_collect')->where($where)->find();
  59. if($check){
  60. Db::name('worker_collect')->where($where)->delete();
  61. $this->success('已取消收藏');
  62. }else{
  63. Db::name('worker_collect')->insertGetId($where);
  64. $this->success('收藏成功');
  65. }
  66. }
  67. //动态是否收藏
  68. private function is_collect($id,$uid){
  69. $where = [
  70. 'worker_id' => $uid,
  71. 'table' => 'news',
  72. 'table_id' => $id,
  73. ];
  74. $check = Db::name('worker_collect')->where($where)->find();
  75. if($check){
  76. return 1;
  77. }else{
  78. return 0;
  79. }
  80. }
  81. }