LevelSettingService.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | EasyAdmin
  4. // +----------------------------------------------------------------------
  5. // | PHP交流群: 763822524
  6. // +----------------------------------------------------------------------
  7. // | 开源协议 https://mit-license.org
  8. // +----------------------------------------------------------------------
  9. // | github开源项目:https://github.com/zhongshaofa/EasyAdmin
  10. // +----------------------------------------------------------------------
  11. namespace app\common\service;
  12. use app\common\model\LevelSettingModel;
  13. use utils\RedisCache;
  14. /**
  15. * 用户等级配置服务 by wes
  16. * Class LevelSettingService
  17. * @package app\common\service
  18. */
  19. class LevelSettingService
  20. {
  21. protected static $instance = null;
  22. protected $model = null;
  23. public function __construct()
  24. {
  25. $this->model = new LevelSettingModel();
  26. }
  27. /**
  28. * 静态化入口
  29. * @return static|null
  30. */
  31. public static function make()
  32. {
  33. if(!self::$instance){
  34. self::$instance = new static();
  35. }
  36. return self::$instance;
  37. }
  38. /**
  39. * 按类型获取列表
  40. * @param $groupKey 分组
  41. * @return array|mixed
  42. * @throws \think\db\exception\DataNotFoundException
  43. * @throws \think\db\exception\DbException
  44. * @throws \think\db\exception\ModelNotFoundException
  45. */
  46. public function getListData($display=0)
  47. {
  48. $cacheKey = "caches:levels:list_{$display}";
  49. $data = RedisCache::get($cacheKey);
  50. if($data){
  51. return $data;
  52. }
  53. $where = [];
  54. if($display){
  55. $where['display'] = $display;
  56. }
  57. $data = $this->model->where($where)->select();
  58. $data = $data? $data->toArray():[];
  59. if($data){
  60. RedisCache::set($cacheKey, $data, rand(5,10));
  61. }
  62. return $data;
  63. }
  64. }