ecshop当前会员等级距离下一等级差多少积分显示

2016-09-07 22:02 来源:www.chinab4c.com 作者:ecshop专家

在ecshop上显示ecshop当前会员等级距离下一等级差多少积分,这个功能很实用。chinab4c分享给大家:

    if ($rank = get_rank_info())
    {
        $smarty->assign('rank_name', sprintf($_LANG['your_level'], $rank['rank_name']));
        if (!empty($rank['next_rank_name']))
        {
            $smarty->assign('next_rank_name', sprintf($_LANG['next_level'], $rank['next_rank'] ,$rank['next_rank_name']));
        }
    }

再增加get_rank_info 函数代码

function get_rank_info()
{
    global $db,$ecs;
 
    if (!empty($_SESSION['user_rank']))
    {
        $sql = "SELECT rank_name, special_rank FROM " . $ecs->table('user_rank') . " WHERE rank_id = '$_SESSION[user_rank]'";
        $row = $db->getRow($sql);
        if (empty($row))
        {
            return array();
        }
        $rank_name = $row['rank_name'];
        if ($row['special_rank'])
        {
            return array('rank_name'=>$rank_name);
        }
        else
        {
          //  zuimoban.com
               $user_rank = $db->getOne("SELECT pay_points  FROM " . $ecs->table('users') . " WHERE user_id = '$_SESSION[user_id]'");
 
   $sql = "SELECT rank_name,min_points FROM " . $ecs->table('user_rank') . " WHERE min_points > '$user_rank' ORDER BY min_points ASC LIMIT 1";
            $rt  = $db->getRow($sql);
            $next_rank_name = $rt['rank_name'];
            $next_rank = $rt['min_points'] - $user_rank;
            return array('rank_name'=>$rank_name,'next_rank_name'=>$next_rank_name,'next_rank'=>$next_rank);
        }
    }
    else
    {
        return array();
    }
}
 
再在语言库里增加相应的语言中文,插入到模板里next_rank_name  贴这个标签功能就实现了!(责任编辑:chinab4c)