News.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\data\controller\api;
  3. use app\data\model\DataNewsItem;
  4. use app\data\model\DataNewsXCollect;
  5. use app\data\service\NewsService;
  6. use think\admin\Controller;
  7. /**
  8. * 文章接口控制器
  9. * Class News
  10. * @package app\data\controller\api
  11. */
  12. class News extends Controller
  13. {
  14. /**
  15. * 获取文章标签列表
  16. * @throws \think\db\exception\DataNotFoundException
  17. * @throws \think\db\exception\DbException
  18. * @throws \think\db\exception\ModelNotFoundException
  19. */
  20. public function getMark()
  21. {
  22. $query = $this->_query('DataNewsMark')->like('name');
  23. $query->where(['status' => 1, 'deleted' => 0])->withoutField('sort,status,deleted');
  24. $this->success('获取文章标签', $query->order('sort desc,id desc')->page(false, false));
  25. }
  26. /**
  27. * 获取文章内容列表
  28. * @throws \think\db\exception\DataNotFoundException
  29. * @throws \think\db\exception\DbException
  30. * @throws \think\db\exception\ModelNotFoundException
  31. */
  32. public function getItem()
  33. {
  34. if ($code = input('code', '')) {
  35. DataNewsItem::mk()->where(['code' => $code])->inc('num_read')->update();
  36. if (($uuid = input('uuid', 0)) > 0) {
  37. $data = ['uuid' => $uuid, 'code' => $code, 'type' => 3, 'status' => 2];
  38. DataNewsXCollect::mk()->where($data)->delete();
  39. DataNewsXCollect::mk()->insert($data);
  40. }
  41. }
  42. $query = $this->_query(DataNewsItem::class)->like('name,mark')->equal('id,code');
  43. $query->where(['deleted' => 0, 'status' => 1])->withoutField('sort,status,deleted');
  44. $result = $query->order('sort desc,id desc')->page(true, false, false, 15);
  45. NewsService::instance()->buildData($result['list'], input('uuid', 0));
  46. $this->success('获取文章内容', $result);
  47. }
  48. /**
  49. * 获取文章评论
  50. * @throws \think\db\exception\DataNotFoundException
  51. * @throws \think\db\exception\DbException
  52. * @throws \think\db\exception\ModelNotFoundException
  53. */
  54. public function getComment()
  55. {
  56. $map = $this->_vali(['code.require' => '文章不能为空!']);
  57. $query = $this->_query(DataNewsXCollect::class)->where(['type' => 4, 'status' => 2]);
  58. $result = $query->where($map)->order('id desc')->page(true, false, false, 15);
  59. NewsService::instance()->buildListByUidAndCode($result['list']);
  60. $this->success('获取评论成功', $result);
  61. }
  62. }