Article.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\wap\controller;
  12. use app\wap\model\article\Article as ArticleModel;
  13. use app\wap\model\wap\ArticleCategory;
  14. use app\wap\model\wap\Search;
  15. use basic\WapBasic;
  16. use service\JsonService;
  17. use service\UtilService;
  18. use think\Db;
  19. use think\Url;
  20. use service\GroupDataService;
  21. /**
  22. * 新闻控制器
  23. * Class Article
  24. * @package app\wap\controller
  25. */
  26. class Article extends AuthController
  27. {
  28. /**
  29. * 白名单
  30. */
  31. public static function WhiteList()
  32. {
  33. return [
  34. 'get_unifiend_list',
  35. 'news_bulletin',
  36. 'unified_list',
  37. 'news_list',
  38. 'articleDetails',
  39. 'details',
  40. 'news_detail',
  41. 'getArticleCate'
  42. ];
  43. }
  44. /**新闻列表
  45. * @return mixed
  46. * @throws \think\db\exception\DataNotFoundException
  47. * @throws \think\db\exception\ModelNotFoundException
  48. * @throws \think\exception\DbException
  49. */
  50. public function unified_list()
  51. {
  52. $title = '新闻列表';
  53. $category = ArticleCategory::where(['status' => 1, 'is_del' => 0])->order('sort DESC,add_time DESC')->select();
  54. $category = count($category) > 0 ? $category->toArray() : [];
  55. $this->assign([
  56. 'title' => $title,
  57. 'category' => json_encode($category),
  58. ]);
  59. return $this->fetch();
  60. }
  61. /**新闻分类列表
  62. * @throws \think\db\exception\DataNotFoundException
  63. * @throws \think\db\exception\ModelNotFoundException
  64. * @throws \think\exception\DbException
  65. */
  66. public function getArticleCate()
  67. {
  68. $category = ArticleCategory::where(['status' => 1, 'is_del' => 0])->order('sort DESC,add_time DESC')->select();
  69. $category = count($category) > 0 ? $category->toArray() : [];
  70. return JsonService::successful($category);
  71. }
  72. /**
  73. *新闻列表
  74. */
  75. public function get_unifiend_list()
  76. {
  77. $where = UtilService::getMore([
  78. ['page', 1],
  79. ['limit', 10],
  80. ['cid', 0],
  81. ]);
  82. return JsonService::successful(ArticleModel::getUnifiendList($where));
  83. }
  84. /**
  85. * 首页新闻简报
  86. */
  87. public function news_bulletin()
  88. {
  89. $news_bulletin = GroupDataService::getData('news_bulletin');
  90. return JsonService::successful($news_bulletin);
  91. }
  92. /**
  93. * 资讯详情
  94. */
  95. public function details($id = 0)
  96. {
  97. $this->assign('id', $id);
  98. return $this->fetch('news_detail');
  99. }
  100. /**
  101. * 新闻详情
  102. */
  103. public function articleDetails($id = 0)
  104. {
  105. $article = ArticleModel::where(['id' => $id, 'is_show' => 1])->find();
  106. if (!$article) return JsonService::fail('您查看的文章不存在');
  107. $content = Db::name('articleContent')->where('nid', $article["id"])->value('content');
  108. $article["content"] = htmlspecialchars_decode($content);
  109. //增加浏览次数
  110. $article["visit"] = $article["visit"] + 1;
  111. $article["add_time"] = date('Y-m-d', $article["add_time"]);
  112. ArticleModel::where('id', $id)->update(["visit" => $article["visit"]]);
  113. return JsonService::successful($article);
  114. }
  115. /**
  116. * 新闻
  117. */
  118. public function news_list()
  119. {
  120. return $this->fetch();
  121. }
  122. /**
  123. * 资讯详情
  124. */
  125. public function news_detail($id = 0)
  126. {
  127. $this->assign('id', $id);
  128. return $this->fetch();
  129. }
  130. }