cms_model = new CmsModel;
}
public function index()
{
$page = $this->request->param('page/d', 1);
$seo = seo();
$this->assign([
'SEO' => $seo,
'page' => $page,
]);
if ($this->request->isAjax()) {
$this->success('', '', $this->fetch('/common/index_ajax'));
}
return $this->fetch('/index');
}
public function lists()
{
$cat = $this->request->param('catid/d', 0);
if (empty($cat)) {
$cat = $this->request->param('catdir/s', '');
}
$page = $this->request->param('page/d', 1);
$category = getCategory($cat);
if (empty($category)) {
throw new \think\exception\HttpException(404, '栏目不存在!');
}
$catid = $category['id'];
$setting = $category['setting'];
if ($category['type'] == 2) {
$template = $setting['category_template'] ?? 'category';
$template_list = $setting['list_template'] ?? 'list';
$template = $category['child'] ? $template : $template_list;
$seo = seo($catid, '', $setting['meta_description'], $setting['meta_keywords']);
} elseif ($category['type'] == 1) {
$template = $setting['page_template'] ?? 'page';
[$cacheKey, $cacheExpire] = Service::getCacheConfig('page-' . $catid . '-' . $this->siteLang);
$info = PageModel::getPageWithLangByCatid($catid, $this->siteLang);
if (empty($info)) {
throw new \think\exception\HttpException(404, '单页不存在!');
}
PageModel::where('id', $info['id'])->inc('hits')->save();
$keywords = $info['keywords'] ?? $setting['meta_keywords'];
$description = $info['description'] ?? $setting['meta_description'];
$seo = seo($catid, '', $description, $keywords);
$this->assign($info);
if ((int)$catid === 26 && $this->request->has('project', 'get')) {
$projectId = $this->request->param('project/d', 0);
$supportProject = [];
if ($projectId > 0) {
$supportCatIds = [5, 6, 7];
foreach ($supportCatIds as $supportCatId) {
$project = $this->cms_model->getContent(getCategory($supportCatId, 'modelid'), ['catid' => $supportCatId, 'id' => $projectId], true);
if (!empty($project)) {
$supportProject = $project;
$supportProject['source_catid'] = $supportCatId;
break;
}
}
}
if (empty($supportProject)) {
throw new \think\exception\HttpException(404, '产品不存在!');
}
$supportSections = [
'video' => ['catid' => 34, 'field' => 'url', 'projectField' => 'project_id'],
'faq' => ['catid' => 25, 'field' => 'url', 'projectField' => 'project_id'],
'guide' => ['catid' => 35, 'field' => 'url', 'projectField' => 'project_id'],
'download' => ['catid' => 40, 'field' => 'fileaddress', 'projectField' => 'project_id'],
];
foreach ($supportSections as $sectionKey => $sectionConfig) {
$sectionCatid = (int) $sectionConfig['catid'];
$sectionTabs = Db::name('cms_category')->where('parentid', $sectionCatid)->where('status', 1)->order('listorder ASC,id ASC')->select()->toArray();
$sectionMap = [];
$sectionDirect = [];
$buildProjectWhere = function ($catIds) use ($sectionConfig, $projectId) {
$catIds = array_values(array_filter(array_map('intval', (array)$catIds)));
if (empty($catIds)) {
return '';
}
$where = '`catid` in(' . implode(',', $catIds) . ') AND `status` = 1';
if (!empty($sectionConfig['projectField'])) {
$where .= " AND `{$sectionConfig['projectField']}` = {$projectId}";
}
return $where;
};
if (!empty($sectionTabs)) {
foreach ($sectionTabs as $sectionTab) {
$childTabs = Db::name('cms_category')->where('parentid', $sectionTab['id'])->where('status', 1)->order('listorder ASC,id ASC')->select()->toArray();
$tabCatIds = [$sectionTab['id']];
if (!empty($childTabs)) {
foreach ($childTabs as $childTab) {
$tabCatIds[] = (int)$childTab['id'];
}
}
$where = $buildProjectWhere($tabCatIds);
$sectionMap[$sectionTab['id']] = [];
if ($where !== '') {
$sectionMap[$sectionTab['id']] = $this->cms_model->getList(getCategory($sectionTab['id'], 'modelid'), $where, 1, '*', 'listorder ASC,id DESC', 24, false);
}
}
}
$directWhere = $buildProjectWhere([$sectionCatid]);
if ($directWhere !== '') {
$sectionDirect = $this->cms_model->getList(getCategory($sectionCatid, 'modelid'), $directWhere, 1, '*', 'listorder ASC,id DESC', 24, false);
}
$hasSectionContent = !empty($sectionDirect);
if (!$hasSectionContent && !empty($sectionMap)) {
foreach ($sectionMap as $sectionItems) {
if (!empty($sectionItems)) {
$hasSectionContent = true;
break;
}
}
}
$assignPrefix = 'support' . ucfirst($sectionKey);
$this->assign($assignPrefix . 'Tabs', $sectionTabs);
$this->assign($assignPrefix . 'Map', $sectionMap);
$this->assign($assignPrefix . 'Direct', $sectionDirect);
$this->assign($assignPrefix . 'Field', $sectionConfig['field']);
$this->assign($assignPrefix . 'HasContent', $hasSectionContent);
}
$this->assign('supportProject', $supportProject);
$this->assign('supportProjectId', $projectId);
}
}
$template = pathinfo($template, PATHINFO_FILENAME);
$top_parentid = $category['arrparentid'][0] ?? $catid;
unset($category['id']);
$this->assign([
'category' => $category,
'top_parentid' => $top_parentid,
'SEO' => $seo,
'catid' => $catid,
'page' => $page,
'modelid' => $category['modelid'],
]);
if ($this->request->isAjax()) {
$this->success('', '', $this->fetch('/common/' . $template . '_ajax'));
}
return $this->fetch('/' . $template);
}
public function shows()
{
$id = $this->request->param('id/d', 0);
$cat = $this->request->param('catid/d', 0);
if (empty($cat)) {
$cat = $this->request->param('catdir/s', '');
}
$page = $this->request->param('page/d', 1);
$page = max(1, $page);
$category = getCategory($cat);
if (empty($category)) {
throw new \think\exception\HttpException(404, '栏目不存在!');
}
$catid = $category['catid'] = $category['id'];
unset($category['id']);
$modelid = $category['modelid'];
$modelInfo = cms_cache('Model')[$modelid] ?? '';
if (empty($modelInfo)) {
throw new \think\exception\HttpException(404, '模型不存在!');
}
Db::name($modelInfo['tablename'])->where('id', $id)->setInc('hits');
[$cacheKey, $cacheExpire] = Service::getCacheConfig('show-' . $catid . '-' . $id . '-' . $this->siteLang);
$info = $this->cms_model->getContent($modelid, ['catid' => $catid, 'id' => $id], true, '*', '', $cacheKey, $cacheExpire);
if (!$info) {
throw new \think\exception\HttpException(404, '内容不存在!');
}
if ($info['status'] !== 1 && !\app\admin\library\Auth::instance()->isLogin() && $info['user_id'] !== $this->auth->id) {
throw new \think\exception\HttpException(403, '内容未审核或没有权限!');
}
$paginator = isset($info['content']) ? strpos($info['content'], '[page]') : false;
if ($paginator !== false) {
$contents = array_filter(explode('[page]', $info['content']));
$total = count($contents);
$pages = \addons\cms\paginator\Page::make([], 1, $page, $total, false, ['path' => $this->request->baseUrl()]);
if ($paginator < 7) {
$info['content'] = $contents[$page];
} else {
$info['content'] = $contents[$page - 1];
}
$this->assign('pages', $pages);
} else {
$this->assign('pages', '');
}
$setting = $category['setting'];
$template = isset($setting['show_template']) ? pathinfo($setting['show_template'], PATHINFO_FILENAME) : 'show';
$info['readpoint'] = $info['readpoint'] ?? 0;
$info['paytype'] = $info['paytype'] ?? 1;
$is_pay = 1;
$is_part_content_pay = 0;
if (isset($info['content'])) {
$info['content'] = str_replace(['###paidstart###', '###paidend###'], ['', ''], $info['content']);
}
if ($info['readpoint'] > 0) {
$is_pay = \addons\cms\model\Order::check_payment($info);
if (!$is_pay) {
if (isset($info['content'])) {
$pattern = '/(.*?)<\/paid>/is';
if (preg_match($pattern, $info['content'])) {
$info['content'] = preg_replace($pattern, "此处内容需要付费后方可阅读
", $info['content']);
$is_part_content_pay = 1;
}
}
} else {
$is_pay = 1;
}
}
$title = $info['title'] ?? ($setting['meta_title'] ?? '');
$keywords = $info['keywords'] ?? ($setting['meta_keywords'] ?? '');
$description = $info['description'] ?? ($setting['meta_description'] ?? '');
$seo = seo($catid, $title, $description, $keywords);
$top_parentid = $category['arrparentid'][0] ?? $catid;
if ($template === 'show_fqa') {
$fqaProjectId = (int) ($info['project_id'] ?? 0);
$fqaChannels = [25, 35];
$fqaSidebar = [];
foreach ($fqaChannels as $channelCatid) {
$channel = getCategory($channelCatid);
if (empty($channel)) {
continue;
}
$children = Db::name('cms_category')->where('parentid', $channelCatid)->where('status', 1)->order('listorder ASC,id ASC')->select()->toArray();
$groups = [];
if (!empty($children)) {
foreach ($children as $child) {
$where = "`catid` = {$child['id']} AND `status` = 1";
if ($fqaProjectId > 0) {
$where .= " AND `project_id` = {$fqaProjectId}";
}
$items = $this->cms_model->getList(getCategory($child['id'], 'modelid'), $where, 1, '*', 'listorder ASC,id DESC', 100, false);
if (!empty($items)) {
$groups[] = [
'title' => $child['catname'],
'items' => $items,
];
}
}
} else {
$where = "`catid` = {$channelCatid} AND `status` = 1";
if ($fqaProjectId > 0) {
$where .= " AND `project_id` = {$fqaProjectId}";
}
$items = $this->cms_model->getList(getCategory($channelCatid, 'modelid'), $where, 1, '*', 'listorder ASC,id DESC', 100, false);
if (!empty($items)) {
$groups[] = [
'title' => $channel['catname'],
'items' => $items,
];
}
}
$fqaSidebar[] = [
'title' => $channel['catname'],
'groups' => $groups,
];
}
$this->assign('fqaSidebar', $fqaSidebar);
}
$this->assign($info);
$this->assign([
'category' => $category,
'is_part_content_pay' => $is_part_content_pay,
'is_pay' => $is_pay,
'top_parentid' => $top_parentid,
'SEO' => $seo,
'catid' => $catid,
'page' => $page,
'modelid' => $modelid,
]);
return $this->fetch('/' . $template);
}
}