wangtengyu
2018-12-07 f459412e0dac4ed94106da043b4c6f8576bfe496
commit | author | age
e2b48d 1 <?php
B 2
3 /**
4  * 获取会员等级信息信息
5 */
6     require('includes/safety_mysql.php');
7     define('IN_ECS', true);
8     require('includes/init.php');
9     $user=$_POST['user_rank'];
10     $row = $db -> getRow("SELECT * FROM ".$ecs->table('users')." WHERE `user_id`='$user'");
11     $result=array();
12     
13     $result['code']=1;
14
15     /*获取该会员等级信息*/
16     $rank_points = $row['rank_points'];
17     $sql = "SELECT rank_name,rank_id, special_rank FROM " . $ecs->table('user_rank') . " WHERE max_points > '$rank_points' ORDER BY max_points ASC LIMIT 1";
18     $rank = $db->getRow($sql);
19     if(!empty($rank))
20     {
21         $rank_name = $rank['rank_name'];
22         $rank_id = $rank['rank_id'];
23         
24         $sql = "SELECT rank_name,min_points FROM " . $ecs->table('user_rank') . " WHERE min_points > '$rank_points' ORDER BY min_points ASC LIMIT 1";
25         $rt  = $db->getRow($sql);
26         
27         $next_rank_name = $rt['rank_name'];
28         $next_rank = $rt['min_points'] - $rank_points;
29         
30         $result['rank'] = array('rank_name'=>$rank_name,'rank_id'=>$rank_id,'next_rank_name'=>'积分达到'.$next_rank_name,'next_rank'=>'还差'.$next_rank);
31     }else
32     {
33         $sql = "SELECT rank_name,rank_id, special_rank FROM " . $ecs->table('user_rank') . " ORDER BY rank_id DESC LIMIT 1";
34         $rank = $db->getRow($sql);
35         $rank_name = $rank['rank_name'];
36         $rank_id = $rank['rank_id'];
37         $result['rank'] = array('rank_name'=>$rank_name,'rank_id'=>$rank_id,'next_rank_name'=>'已经是最高等级了','next_rank'=>'没有下一级别了');
38     }
39     
40     
41     
42     print_r(json_encode($result));
43
44 ?>
45