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