Article.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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. /**
  21. * 文章分类控制器
  22. * Class Article
  23. * @package app\wap\controller
  24. */
  25. class Article extends AuthController
  26. {
  27. /**
  28. * 白名单
  29. */
  30. public static function WhiteList()
  31. {
  32. return [
  33. 'get_unifiend_list',
  34. 'index',
  35. 'unified_list',
  36. 'visit',
  37. 'details',
  38. ];
  39. }
  40. public function index($cid = '')
  41. {
  42. $title = '新闻列表';
  43. if ($cid) {
  44. $cateInfo = ArticleCategory::where('status', 1)->where('is_del', 0)->where('id', $cid)->find()->toArray();
  45. if (!$cateInfo) return $this->failed('文章分类不存在!', Url::build('article/unified_list'));
  46. $title = $cateInfo['title'];
  47. }
  48. $this->assign(compact('title', 'cid'));
  49. return $this->fetch();
  50. }
  51. public function unified_list()
  52. {
  53. $title = '新闻列表';
  54. $category=ArticleCategory::where('status', 1)->where('is_del', 0)->order('sort DESC,add_time DESC')->select();
  55. $category=count($category)>0 ? $category->toArray() : [];
  56. $this->assign([
  57. 'title'=>$title,
  58. 'category' => json_encode($category),
  59. ]);
  60. return $this->fetch();
  61. }
  62. public function get_unifiend_list(){
  63. $where = UtilService::getMore([
  64. ['page', 1],
  65. ['limit', 10],
  66. ['cid', 0],
  67. ]);
  68. return JsonService::successful(ArticleModel::getUnifiendList($where));
  69. }
  70. public function video_school()
  71. {
  72. return $this->fetch();
  73. }
  74. public function guide()
  75. {
  76. return $this->fetch();
  77. }
  78. public function visit($id = '')
  79. {
  80. $content = ArticleModel::where(['id' => $id, 'hide' => 0,'is_show'=>1])->find();
  81. if (!$content) return $this->failed('此文章已经不存在!', Url::build('article/unified_list'));
  82. $content["content"] = Db::name('articleContent')->where('nid', $content["id"])->value('content');
  83. //增加浏览次数
  84. $content["visit"] = $content["visit"] + 1;
  85. ArticleModel::where('id', $id)->update(["visit" => $content["visit"]]);
  86. $this->assign(compact('content'));
  87. $this->assign([
  88. 'uid'=>$this->uid,
  89. 'title' => $content->title,
  90. 'image' => $content->image_input,
  91. 'synopsis' => $content->synopsis,
  92. 'content' => htmlspecialchars_decode($content->content)
  93. ]);
  94. return $this->fetch('details');
  95. }
  96. public function details($id = '')
  97. {
  98. $article = ArticleModel::where(['id'=>$id,'is_show'=>1])->find();
  99. if (!$article) $this->failed('您查看的文章不存在', Url::build('article/unified_list'));
  100. $article["content"] = Db::name('articleContent')->where('nid', $article["id"])->value('content');
  101. //增加浏览次数
  102. $article["visit"] = $article["visit"] + 1;
  103. ArticleModel::where('id', $id)->update(["visit" => $article["visit"]]);
  104. $this->assign([
  105. 'uid'=>$this->uid,
  106. 'title' => $article->title,
  107. 'image' => $article->image_input,
  108. 'synopsis' => $article->synopsis,
  109. 'content' => htmlspecialchars_decode($article->content)
  110. ]);
  111. return $this->fetch();
  112. }
  113. }