Grade.php
4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
namespace Home;
use Configs\CacheConfig;
use LibModels\Wap\Home\GradeData;
use Plugin\Cache;
use Plugin\Helpers;
/**
* 会员等级相关数据处理
*/
class GradeModel
{
/*
* 获取个人中心-会员等级数据
*/
public static function getGrade($channel, $uid)
{
$result = array();
if (USE_CACHE) {
$key = CacheConfig::KEY_ACTION_HOME_GRADE . strval($uid);
// 先尝试获取一级缓存(master), 有数据则直接返回.
$result = Cache::get($key, 'master');
if (!empty($result)) {
return $result;
}
}
//调用接口获取数据
$data = GradeData::getGradeData($channel, $uid);
if (!empty($data['grade'])) {
switch (intval($data['grade']['current_vip_level'])) {
case 0://普通会员
$result['vipGrade']['vip0'] = true;
break;
case 1://银卡会员
$result['vipGrade']['vip1'] = true;
break;
case 2://金卡会员
$result['vipGrade']['vip2'] = true;
break;
case 3://白金会员
$result['vipGrade']['vip3'] = true;
break;
}
//今年总消费
$result['vipGrade']['costOfThisYear'] = sprintf("%.2f", $data['grade']['current_year_cost']);
//升级下一等级会员的进度;
if ($data['grade']['next_need_cost'] == 0) {
//当vip等级升至顶级时,进度条满格
$result['vipGrade']['percent'] = 100;
} else {
$result['vipGrade']['percent'] = 100 * (round($data['grade']['current_year_cost'] / $data['grade']['next_need_cost'], 2));
}
//距离升级所需消费金额
if ($data['grade']['current_vip_level'] != 3) {
$result['vipGrade']['costGap'] = sprintf("%.2f", $data['grade']['upgrade_need_cost']);
}
//消费总计
$result['vipGrade']['sumCost'] = sprintf("%.2f", $data['grade']['current_total_cost']);
//username 调用获取用户基本信息数据,获得nikename昵称;
$result['vipGrade']['name'] = !empty($data['userProfile']) ? $data['userProfile']['nickname'] : '';
//跳转url(会员特权详情)
$allUrl = Helpers::url('/home/preferential', null);
$result['vipGrade']['allUrl'] = strtr($allUrl, array('http://' => '//'));
//当前vip等级享受的特权
foreach ($data['grade']['enjoy_preferential'] as &$value) {
$value['pic'] = strtr($value['pic'], array('http://' => '//'));
}
$result['vipGrade']['privilege'] = $data['grade']['enjoy_preferential'];
}
if (USE_CACHE) {
// 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
if (empty($result)) {
$result = Cache::get($key, 'slave');
}
// 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
else {
Cache::set($key, $result);
}
}
return $result;
}
/*
* 获取个人中心-会员特权详情页
*/
public static function getPreferential($channel, $uid)
{
$result = array();
if (USE_CACHE) {
$key = CacheConfig::KEY_ACTION_HOME_PREFERENTIAL . strval($uid);
// 先尝试获取一级缓存(master), 有数据则直接返回.
$result = Cache::get($key, 'master');
if (!empty($result)) {
return $result;
}
}
//调取接口获得数据
$data = GradeData::getPreferentialData($channel, $uid);
if (isset($data['code']) && $data['code'] == 200) {
foreach ($data['data'] as &$value) {
$value['pic'] = strtr($value['pic'], array('http://' => '//'));
}
$result['vipGrade']['privilege'] = $data['data'];
}
if (USE_CACHE) {
// 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
if (empty($result)) {
$result = Cache::get($key, 'slave');
}
// 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
else {
Cache::set($key, $result);
}
}
return $result;
}
}