LevelSettingService.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace app\common\service;
  3. use app\common\model\LevelSettingModel;
  4. use utils\RedisCache;
  5. /**
  6. * 用户等级配置服务 by wes
  7. * Class LevelSettingService
  8. * @package app\common\service
  9. */
  10. class LevelSettingService
  11. {
  12. protected static $instance = null;
  13. protected $model = null;
  14. public function __construct()
  15. {
  16. $this->model = new LevelSettingModel();
  17. }
  18. /**
  19. * 静态化入口
  20. * @return static|null
  21. */
  22. public static function make()
  23. {
  24. if(!self::$instance){
  25. self::$instance = new static();
  26. }
  27. return self::$instance;
  28. }
  29. /**
  30. * 按类型获取列表
  31. * @param $display
  32. * @return array|mixed
  33. * @throws \think\db\exception\DataNotFoundException
  34. * @throws \think\db\exception\DbException
  35. * @throws \think\db\exception\ModelNotFoundException
  36. */
  37. public function getListData($display=0)
  38. {
  39. $cacheKey = "caches:levels:list_{$display}";
  40. $data = RedisCache::get($cacheKey);
  41. if($data){
  42. return $data;
  43. }
  44. $where = [];
  45. if($display){
  46. $where['display'] = $display;
  47. }
  48. $data = $this->model->where($where)->select();
  49. $data = $data? $data->toArray():[];
  50. if($data){
  51. RedisCache::set($cacheKey, $data, rand(5,10));
  52. }
  53. return $data;
  54. }
  55. /**
  56. * 按类型获取列表
  57. * @param $level 等级
  58. * @param $type 升级方式:1-自动,2-手动
  59. * @return array|mixed
  60. * @throws \think\db\exception\DataNotFoundException
  61. * @throws \think\db\exception\DbException
  62. * @throws \think\db\exception\ModelNotFoundException
  63. */
  64. public function getConfigData($level=0, $type=0)
  65. {
  66. $cacheKey = "caches:temp:levels:config_{$level}_{$type}";
  67. $data = RedisCache::get($cacheKey);
  68. if($data){
  69. return $data;
  70. }
  71. $where = [];
  72. if($level){
  73. $where['level'] = $level;
  74. }
  75. if($type){
  76. $where['type'] = $type;
  77. }
  78. $data = $this->model->where($where)->column('level,total_money,dynamic_scale,zt_money,zt_num,team_num,zt_level','level');
  79. if($data){
  80. RedisCache::set($cacheKey, $data, 3600);
  81. }
  82. return $data;
  83. }
  84. }