| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace app\common\service;
- use app\common\model\LevelSettingModel;
- use utils\RedisCache;
- /**
- * 用户等级配置服务 by wes
- * Class LevelSettingService
- * @package app\common\service
- */
- class LevelSettingService
- {
- protected static $instance = null;
- protected $model = null;
- public function __construct()
- {
- $this->model = new LevelSettingModel();
- }
- /**
- * 静态化入口
- * @return static|null
- */
- public static function make()
- {
- if(!self::$instance){
- self::$instance = new static();
- }
- return self::$instance;
- }
- /**
- * 按类型获取列表
- * @param $display
- * @return array|mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getListData($display=0)
- {
- $cacheKey = "caches:levels:list_{$display}";
- $data = RedisCache::get($cacheKey);
- if($data){
- return $data;
- }
- $where = [];
- if($display){
- $where['display'] = $display;
- }
- $data = $this->model->where($where)->select();
- $data = $data? $data->toArray():[];
- if($data){
- RedisCache::set($cacheKey, $data, rand(5,10));
- }
- return $data;
- }
- /**
- * 按类型获取列表
- * @param $level 等级
- * @param $type 升级方式:1-自动,2-手动
- * @return array|mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getConfigData($level=0, $type=0)
- {
- $cacheKey = "caches:temp:levels:config_{$level}_{$type}";
- $data = RedisCache::get($cacheKey);
- if($data){
- return $data;
- }
- $where = [];
- if($level){
- $where['level'] = $level;
- }
- if($type){
- $where['type'] = $type;
- }
- $data = $this->model->where($where)->column('level,total_money,dynamic_scale,zt_money,zt_num,team_num,zt_level','level');
- if($data){
- RedisCache::set($cacheKey, $data, 3600);
- }
- return $data;
- }
- }
|