Special.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace addons\cms\controller;
  3. use addons\cms\library\Service;
  4. use addons\cms\model\Fields;
  5. use addons\cms\model\Special as SpecialModel;
  6. use think\Config;
  7. use think\Exception;
  8. /**
  9. * 专题控制器
  10. * Class Special
  11. * @package addons\cms\controller
  12. */
  13. class Special extends Base
  14. {
  15. /**
  16. * 专题页面
  17. * @return string
  18. * @throws Exception
  19. * @throws \think\exception\DbException
  20. */
  21. public function index()
  22. {
  23. $config = get_addon_config('cms');
  24. $diyname = $this->request->param('diyname');
  25. if ($diyname && !is_numeric($diyname)) {
  26. $special = SpecialModel::getByDiyname($diyname);
  27. } else {
  28. $id = $diyname ? $diyname : $this->request->param('id', '');
  29. $special = SpecialModel::get($id);
  30. }
  31. if (!$special || $special['status'] == 'hidden') {
  32. $this->error(__('No specified special found'));
  33. }
  34. $special->setInc("views", 1);
  35. $fieldsContentList = Fields::getFieldsContentList('special');
  36. Service::appendTextAttr($fieldsContentList, $special);
  37. $archivesList = \addons\cms\model\Archives::with(['channel'])
  38. ->where(function ($query) use ($special) {
  39. $query->whereRaw("(`special_ids`!='' AND FIND_IN_SET('{$special->id}', `special_ids`))");
  40. if ($special['tag_ids']) {
  41. $query->whereOr('id', 'in', function ($query) use ($special) {
  42. return $query->name("cms_taggable")->where("tag_id", 'in', $special['tag_ids'])->field("archives_id");
  43. });
  44. }
  45. })
  46. ->where('status', 'normal')
  47. ->whereNull('deletetime')
  48. ->order('weigh DESC,id DESC')
  49. ->paginate(10, $config['pagemode'] == 'simple', ['type' => '\\addons\\cms\\library\\Bootstrap']);
  50. $this->view->assign("archivesList", $archivesList);
  51. $this->view->assign("__PAGELIST__", $archivesList);
  52. $this->view->assign("__SPECIAL__", $special);
  53. //设置TKD
  54. Config::set('cms.title', isset($special['seotitle']) && $special['seotitle'] ? $special['seotitle'] : $special['title']);
  55. Config::set('cms.keywords', $special['keywords']);
  56. Config::set('cms.description', $special['description']);
  57. $special['template'] = $special['template'] ? $special['template'] : 'special.html';
  58. $template = preg_replace('/\.html$/', '', $special['template']);
  59. if ($this->request->isAjax()) {
  60. $this->success("", "", $this->view->fetch('common/special_list'));
  61. }
  62. return $this->view->fetch('/' . $template);
  63. }
  64. }