TaoLer/extend/taoler/com/Level.php
2020-03-30 21:11:12 +08:00

41 lines
746 B
PHP

<?php
namespace taoler\com;
use think\facade\Db;
use app\common\model\Vip;
use app\common\model\User;
class Level
{
//根据用户积分升级vip等级
public static function writeLv($uid)
{
$user = User::find($uid);
$score = $user->point;
$userLv = $user->vip;
$vipLv = self::getLevel($score);
if($vipLv>$userLv){
$result = User::update(['id'=>$uid,'vip'=>$vipLv]);
if($result){
return true;
}else{
return false;
}
}
}
//根据积分获取用户vip等级
public static function getLevel($point)
{
$vip = Db::name('user_viprule')->select();
foreach($vip as $k => $v){
$score = explode('-',$v['score']);
if($score[0] <= $point && $point <= $score[1]){
return $v['vip'];
}
}
}
}