ArticleService.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的多应用管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\service\api\article;
  12. use app\model\article\Article;
  13. use core\base\BaseApiService;
  14. /**
  15. * 文章服务层
  16. * Class ArticleService
  17. * @package app\service\api\article
  18. */
  19. class ArticleService extends BaseApiService
  20. {
  21. public function __construct()
  22. {
  23. parent::__construct();
  24. $this->model = new Article();
  25. }
  26. /**
  27. * 获取文章列表
  28. * @param array $where
  29. * @return array
  30. */
  31. public function getPage(array $where = [])
  32. {
  33. $where[] = [ 'site_id', '=', $this->site_id ];
  34. $field = 'id, category_id, site_id, title, intro, summary, image, author, content, visit, visit_virtual, is_show, sort, create_time, update_time';
  35. $order = 'sort desc,create_time desc';
  36. $search_model = $this->model->where([ [ 'site_id', '=', $this->site_id ], [ 'is_show', '=', 1 ] ])->withSearch([ 'title', 'category_id' ], $where)->with('articleCategory')->field($field)->order($order)->append([ 'image_thumb_mid' ]);
  37. return $this->pageQuery($search_model);
  38. }
  39. /**
  40. * 文章列表
  41. * @param array $where
  42. * @param int $limit
  43. * @return array
  44. */
  45. public function getAll(array $where = [], int $limit = 0)
  46. {
  47. $where[] = [ 'site_id', '=', $this->site_id ];
  48. $field = 'id, category_id, site_id, title, intro, summary, image, author, content, visit, visit_virtual, is_show, sort, create_time, update_time';
  49. $order = 'sort desc,create_time desc';
  50. return $this->model->where([ [ 'site_id', '=', $this->site_id ], [ 'is_show', '=', 1 ] ])->withSearch([ 'title', 'category_id', 'ids' ], $where)->limit($limit)->with('articleCategory')->field($field)->append([ 'image_thumb_mid' ])->order($order)->select()->toArray();
  51. }
  52. /**
  53. * 文章热门资讯
  54. * @param int $limit
  55. * @return array
  56. */
  57. public function getHot(int $limit = 0)
  58. {
  59. $field = 'id, title, image, create_time';
  60. $order = 'sort desc,create_time desc, visit desc';
  61. return $this->model->where([ [ 'site_id', '=', $this->site_id ], [ 'is_show', '=', 1 ] ])->limit($limit)->field($field)->order($order)->select()->toArray();
  62. }
  63. /**
  64. * 获取文章信息
  65. * @param int $id
  66. * @return array
  67. */
  68. public function getInfo(int $id)
  69. {
  70. $field = 'id, category_id, site_id, title, intro, summary, image, author, content, visit, visit_virtual, is_show, sort, create_time, update_time';
  71. return $this->model->with('articleCategory')->field($field)->where([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ])->append([ 'image_thumb_big' ])->findOrEmpty()->toArray();
  72. }
  73. /**
  74. * 增加文章访问量
  75. * @param int $id
  76. * @return mixed
  77. */
  78. public function incVisit(int $id)
  79. {
  80. return $this->model->where([ 'id' => $id ])->setInc('visit');
  81. }
  82. }