PageRepository.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2018/11/12
  6. * Time: 10:58
  7. */
  8. namespace App\Repositories;
  9. use App\Models\Page;
  10. use Illuminate\Support\Facades\Cache;
  11. use Prettus\Repository\Eloquent\BaseRepository;
  12. /**
  13. * Class PageRepositoryEloquent.
  14. *
  15. * @package namespace App\Repositories;
  16. */
  17. class PageRepository extends BaseRepository
  18. {
  19. /**
  20. * Specify Model class name
  21. *
  22. * @return string
  23. */
  24. public function model()
  25. {
  26. return Page::class;
  27. }
  28. public static function pageCache()
  29. {
  30. /* if (!config('aix.system.site_safety.subsite.close_subsite')) {
  31. $where['subsite_id'] = Cache::get('subsite_id');
  32. }
  33. $cache = '_'.Cache::get('subsite_id');*/
  34. $cache = '';
  35. //$where['type'] = 'Home';
  36. $where = array();
  37. if (null === $pageList = Cache::get('Home_page_list'.$cache)) {
  38. $pages = Page::select('alias', 'id', 'pname', 'route', 'rewrite', 'url', 'tag', 'caching')->where($where)->get();
  39. foreach ($pages as $key => $val) {
  40. $pageList[$val->alias] = $val;
  41. $pageList[$val->alias]->lower_route = strtolower($val->route);
  42. }
  43. Cache::forever('Home_page_list'.$cache, $pageList);
  44. }
  45. return $pageList;
  46. }
  47. public function getPage()
  48. {
  49. /*if (Cache::has('subsite_id')) {
  50. $subsite_id = Cache::get('subsite_id');
  51. $cache = '_'.$subsite_id;
  52. } else {
  53. $subsite_id = 0;
  54. $cache = '_';
  55. }*/
  56. $cache = '_';
  57. $page_seo = Cache::get('Home_page_seo_list'.$cache);
  58. if ($page_seo === null) {
  59. $page_seo = $this->pageSeoCache(/*$subsite_id*/);
  60. Cache::forever('Home_page_seo_list'.$cache, $page_seo);
  61. }
  62. return $page_seo;
  63. }
  64. public function pageSeoCache(/*$subsite_id*/)
  65. {
  66. $where = array();
  67. /*if ($subsite_id !== false) {
  68. $where['subsite_id'] = $subsite_id;
  69. }*/
  70. $pageList = $this->model->where($where)->get()->toArray();
  71. $page = array();
  72. if ($pageList) {
  73. foreach ($pageList as $key => $val) {
  74. if ($val['route']) {
  75. $page[strtolower($val['route'])] = array('title'=>$val['title'],'keywords'=>$val['keywords'],'description'=>$val['description']);
  76. }
  77. }
  78. }
  79. return $page;
  80. }
  81. }