common.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. // 这是home公共文件
  8. //读取导航列表,用于前台
  9. function get_navs($name)
  10. {
  11. if (!get_cache('homeNav' . $name)) {
  12. $nav_id = \think\facade\Db::name('Nav')->where(['name' => $name, 'status' => 1])->value('id');
  13. if (empty($nav_id)) {
  14. return '';
  15. }
  16. $list = \think\facade\Db::name('NavInfo')->where(['nav_id' => $nav_id, 'status' => 1])->order('sort asc')->select()->toArray();
  17. $nav = list_to_tree($list);
  18. \think\facade\Cache::tag('homeNav')->set('homeNav' . $name, $nav);
  19. }
  20. $navs = get_cache('homeNav' . $name);
  21. return $navs;
  22. }
  23. //读取指定文章的详情
  24. function get_article_detail($id)
  25. {
  26. $article = \think\facade\Db::name('article')->where(['id' => $id])->find();
  27. if (empty($article)) {
  28. return false;
  29. }
  30. $keywrod_array = \think\facade\Db::name('ArticleKeywords')
  31. ->field('i.aid,i.keywords_id,k.title')
  32. ->alias('i')
  33. ->join('keywords k', 'k.id = i.keywords_id', 'LEFT')
  34. ->order('i.create_time asc')
  35. ->where(array('i.aid' => $id, 'k.status' => 1))
  36. ->select()->toArray();
  37. $article['keyword_ids'] = implode(",", array_column($keywrod_array, 'keywords_id'));
  38. $article['keyword_names'] = implode(',', array_column($keywrod_array, 'title'));
  39. return $article;
  40. }