Pages.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2021 勾股工作室
  4. * @license https://opensource.org/licenses/Apache-2.0
  5. * @link https://www.gougucms.com
  6. */
  7. declare (strict_types = 1);
  8. namespace app\home\controller;
  9. use app\home\BaseController;
  10. use app\admin\model\Pages as PagesModel;
  11. use think\facade\Db;
  12. use think\facade\View;
  13. class Pages extends BaseController
  14. {
  15. public function detail()
  16. {
  17. $param = get_params();
  18. $id = isset($param['id']) ? $param['id'] : 0;
  19. if (isset($param['s'])) {
  20. $id = Db::name('Pages')->where(['name'=>$param['s']])->value('id');
  21. if(empty($id)){
  22. throw new \think\exception\HttpException(406, '找不到相关记录');
  23. }
  24. }
  25. $detail = (new PagesModel())->getPagesById($id);
  26. if(empty($detail)){
  27. throw new \think\exception\HttpException(406, '找不到相关记录');
  28. }
  29. //轮播图
  30. if(!empty($detail['banner'])) {
  31. $detail['banner_array'] = explode(',',$detail['banner']);
  32. }
  33. //关键字
  34. $keyword_array = Db::name('PagesKeywords')
  35. ->field('i.aid,i.keywords_id,k.title')
  36. ->alias('i')
  37. ->join('keywords k', 'k.id = i.keywords_id', 'LEFT')
  38. ->order('i.create_time asc')
  39. ->where(array('i.aid' => $id, 'k.status' => 1))
  40. ->select()->toArray();
  41. $detail['keyword_ids'] = implode(",", array_column($keyword_array, 'keywords_id'));
  42. $detail['keyword_names'] = implode(',', array_column($keyword_array, 'title'));
  43. $detail['keyword_array'] = $keyword_array;
  44. PagesModel::where('id', $id)->inc('read')->update();
  45. View::assign('detail', $detail);
  46. return view($detail['template']);
  47. }
  48. }