123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- namespace Score\Lib;
- use Dever;
- class Level
- {
- # 获取当前用户的等级信息
- public function get($uid, $level_type_id = 1, $prefix = 'vip')
- {
- $result = $this->config($prefix);
- $userLevel = Dever::db('score/user_level')->one(array('uid' => $uid, 'level_type_id' => $level_type_id));
-
- if ($userLevel) {
- $level = Dever::db('score/level')->one($userLevel['level_id']);
- $next_level = Dever::db('score/level')->one(array('level_type_id' => $level_type_id, 'level' => $level['level'] + 1));
- $result['current']['id'] = $level['id'];
- $result['current']['name'] = $level['name'];
- $result['current']['level'] = $level['level'];
- $result['current']['key'] .= $level['level'];
- $result['current']['status'] = $userLevel['level_status'];
- if ($next_level) {
- $result['next']['id'] = $next_level['id'];
- $result['next']['name'] = $next_level['name'];
- $result['next']['level'] = $next_level['level'];
- $result['next']['key'] .= $next_level['level'];
- }
- }
- return $result;
- }
- # 手动升级接口
- public function update($uid, $level_type_id)
- {
- $level_type = Dever::db('score/level_type')->one($level_type_id);
- if ($level_type) {
- # 将手动转为自动
- $level_type['type'] = 1;
- Dever::load('score/lib/core')->setLevel($uid, $level_type);
- }
- return true;
- }
- private function config($prefix)
- {
- $result = array
- (
- # 当前等级
- 'current' => array
- (
- # id
- 'id' => '',
- # 名称
- 'name' => '',
- # 等级数字
- 'level' => 0,
- # 唯一key
- 'key' => $prefix,
- ),
- # 下一级
- 'next' => array
- (
- # id
- 'id' => '',
- # 名称
- 'name' => '',
- # 等级数字
- 'level' => 0,
- # 唯一key
- 'key' => $prefix,
- ),
- );
- return $result;
- }
- }
|