Authored by yangyang

更改了CacheCofig.php:增加了会员等级缓存配置代码;

更改了GradeData.php:增加了获取会员等级数据,获取会员等级详情数据;
微调privilege.phtml和vip-grade.phtml;
修改了Home.php:增加了会员等级展示页和会员特权查看页数据;
修改了Grade.php:增加了getGrade,和getPreferential;
@@ -43,5 +43,8 @@ class CacheConfig @@ -43,5 +43,8 @@ class CacheConfig
43 43
44 const KEY_ACTION_SEARCH_SEARCH = 'key_action_search_search'; // 搜索的数据 44 const KEY_ACTION_SEARCH_SEARCH = 'key_action_search_search'; // 搜索的数据
45 const KEY_ACTION_SEARCH_FILTER = 'key_action_search_filter'; // 搜索的过滤条件 45 const KEY_ACTION_SEARCH_FILTER = 'key_action_search_filter'; // 搜索的过滤条件
  46 +
  47 + const KEY_ACTION_HOME_GRADE = 'key_action_home_grade';//会员等级
  48 + const KEY_ACTION_HOME_PREFERENTIAL = 'key_action_home_preferential';//会员特权详情
46 49
47 } 50 }
1 <?php 1 <?php
2 2
3 - namespace LibModels\Wap\Home;  
4 - use Api\Yohobuy;  
5 - use Api\Sign; 3 +namespace LibModels\Wap\Home;
  4 +
  5 +use Api\Yohobuy;
  6 +use Api\Sign;
  7 +
6 /* 8 /*
7 - *个人中心-会员等级接口操作类 9 + * 个人中心-会员等级接口操作类
8 */ 10 */
9 -  
10 -class GradeData {  
11 - 11 +
  12 +class GradeData
  13 +{
  14 +
12 /** 15 /**
13 - * 获取会员等级展示数据  
14 - */  
15 - public function getGradeData($channel,$uid){  
16 - 16 + * 获取会员等级数据
  17 + * @param string $yh_channel 频道数据,1->男,2->女,3->潮童,4->创意生活,5->其他
  18 + * @param string $uid 用户id
  19 + * @return array 接口返回的会员等级数据
  20 + */
  21 + public function getGradeData($channel, $uid) {
  22 +
17 $param = Yohobuy::param(); 23 $param = Yohobuy::param();
18 $param['yh_channel'] = $channel; 24 $param['yh_channel'] = $channel;
19 $param['uid'] = $uid; 25 $param['uid'] = $uid;
20 $param['method'] = 'app.Passport.vip'; 26 $param['method'] = 'app.Passport.vip';
21 $param['client_secret'] = Sign::getSign($param); 27 $param['client_secret'] = Sign::getSign($param);
22 - return Yohobuy::get(Yohobuy::API_URL,$param); 28 + return Yohobuy::get(Yohobuy::API_URL, $param);
23 } 29 }
  30 +
24 /** 31 /**
25 - * 获取会员特权查看页面数据  
26 - */  
27 - public function getPreferentialData($channel,$uid){ 32 + * 获取会员特权详情数据
  33 + * @param string $yh_channel 频道数据,1->男,2->女,3->潮童,4->创意生活,5->其他
  34 + * @param string $uid 用户id
  35 + * @return array 接口返回的会员特权详情数据
  36 + */
  37 + public function getPreferentialData($channel, $uid) {
  38 +
28 $param = Yohobuy::param(); 39 $param = Yohobuy::param();
29 $param['yh_channel'] = $channel; 40 $param['yh_channel'] = $channel;
30 $param['uid'] = $uid; 41 $param['uid'] = $uid;
31 - $param['method'] = 'app.passport.getPrivilege'; 42 + $param['method'] = 'app.passport.getPrivilege';
32 $param['client_secret'] = Sign::getSign($param); 43 $param['client_secret'] = Sign::getSign($param);
33 - //print_r($param);  
34 - //print_r(Yohobuy::get('http://api.open.yohobuy.com',$param));  
35 - return Yohobuy::get(Yohobuy::API_URL,$param);  
36 - }  
37 -  
38 - /**  
39 - * 获取用户基本信息数据  
40 - */  
41 - public function getUserProfileData($gender,$uid,$channel){  
42 - $param = Yohobuy::param();  
43 - $param['gender'] = $gender;  
44 - $param['uid'] = $uid;  
45 - $param['yh_channel'] = $channel;  
46 - $param['method'] = 'app.passport.profile';  
47 - $param['client_secret'] = Sign::getSign($param);  
48 -  
49 - var_dump(Yohobuy::get(Yohobuy::API_URL,$param)); 44 + return Yohobuy::get(Yohobuy::API_URL, $param);
50 } 45 }
  46 +
  47 + /**
  48 + * 获取用户基本信息数据??获取不到
  49 + */
  50 +// public function getUserProfileData($gender, $uid, $channel) {
  51 +// $param = Yohobuy::param();
  52 +// $param['gender'] = $gender;
  53 +// $param['uid'] = $uid;
  54 +// $param['yh_channel'] = $channel;
  55 +// $param['method'] = 'app.passport.profile';
  56 +// $param['client_secret'] = Sign::getSign($param);
  57 +// var_dump(Yohobuy::post(Yohobuy::API_URL,$param));
  58 +// }
  59 +
51 } 60 }
1 {{> layout/header}} 1 {{> layout/header}}
2 <div class="vip-grade-page yoho-page"> 2 <div class="vip-grade-page yoho-page">
3 {{# vipGrade}} 3 {{# vipGrade}}
4 - {{> me/privilege}} 4 + {{> me/vip-grade/privilege}}
5 {{/ vipGrade}} 5 {{/ vipGrade}}
6 </div> 6 </div>
7 {{> layout/footer}} 7 {{> layout/footer}}
@@ -23,9 +23,9 @@ @@ -23,9 +23,9 @@
23 </div> 23 </div>
24 {{/unless}} 24 {{/unless}}
25 25
26 - <a class="all-privilege block"> 26 + <a class="all-privilege block" href="{{allUrl}}" >
27 查看全部VIP特权 27 查看全部VIP特权
28 - <span class="iconfont">&#xe604;</span> 28 + <span class="iconfont>&#xe604;</span>
29 </a> 29 </a>
30 {{/ vipGrade}} 30 {{/ vipGrade}}
31 </div> 31 </div>
@@ -187,24 +187,31 @@ class HomeController extends AbstractAction @@ -187,24 +187,31 @@ class HomeController extends AbstractAction
187 * 会员等级展示页 187 * 会员等级展示页
188 */ 188 */
189 public function gradeAction(){ 189 public function gradeAction(){
  190 + //设置网站seo信息
  191 + $this->setTitle('会员等级');
  192 + //显示网站导航头部信息
  193 + $this->setNavHeader('会员等级');
  194 +
190 $gender = Helpers::getGenderByCookie(); 195 $gender = Helpers::getGenderByCookie();
191 $channel = Helpers::getChannelByCookie(); 196 $channel = Helpers::getChannelByCookie();
192 $uid = $this -> getUid(); 197 $uid = $this -> getUid();
193 - $uid = '10267443'; 198 + $uid = '10267443';//临时测试用
194 $data = GradeModel::getGrade($gender,$channel,$uid); 199 $data = GradeModel::getGrade($gender,$channel,$uid);
195 -  
196 $this -> _view -> display('vip-grade',$data); 200 $this -> _view -> display('vip-grade',$data);
197 } 201 }
198 /* 202 /*
199 *会员特权查看页 203 *会员特权查看页
200 */ 204 */
201 public function preferentialAction(){ 205 public function preferentialAction(){
202 - $channel = Helpers::getChannelByCookie();  
203 - $uid = $this -> getUid(); 206 + //设置网站seo信息
  207 + $this->setTitle('会员等级');
  208 + //显示网站导航头部信息
  209 + $this->setNavHeader('会员特权详情');
204 210
  211 + $channel = Helpers::getChannelByCookie();
  212 + $uid = $this -> getUid();
205 $data = GradeModel::getPreferential($channel,$uid); 213 $data = GradeModel::getPreferential($channel,$uid);
206 - //print_r($data);  
207 - //$this -> _view -> display('index',$data); 214 + $this -> _view -> display('privilege',$data);
208 } 215 }
209 216
210 } 217 }
1 <?php 1 <?php
  2 +
2 namespace home; 3 namespace home;
3 4
4 use LibModels\Wap\Home\GradeData; 5 use LibModels\Wap\Home\GradeData;
  6 +use Action\AbstractAction;
  7 +use Plugin\Helpers;
  8 +
5 /** 9 /**
6 - *会员等级相关数据处理 10 + * 会员等级相关数据处理
7 */ 11 */
8 -class GradeModel { 12 +class GradeModel
  13 +{
9 /* 14 /*
10 * 获取个人中心-会员等级数据 15 * 获取个人中心-会员等级数据
11 */ 16 */
12 - public function getGrade($gender,$channel,$uid){ 17 +
  18 + public function getGrade($gender, $channel, $uid) {
13 $result = array(); 19 $result = array();
  20 +
  21 + if (USE_CACHE) {
  22 + // 先尝试获取一级缓存(master), 有数据则直接返回.
  23 + $result = Cache::get(CacheConfig::KEY_ACTION_HOME_GRADE, 'master');
  24 + if (!empty($result)) {
  25 + return $result;
  26 + }
  27 + }
14 //调用接口获取数据 28 //调用接口获取数据
15 - $data = GradeData::getGradeData($channel,$uid);  
16 - if(isset($data['code']) && $data['code'] === 200 &&isset($data['data'])){  
17 - switch(intval($data['data']['current_vip_level'])){ 29 + $data = GradeData::getGradeData($channel, $uid);
  30 + if (isset($data['code']) && $data['code'] === 200 && isset($data['data'])) {
  31 + switch (intval($data['data']['current_vip_level'])) {
18 case 0://普通会员 32 case 0://普通会员
19 $result['vipGrade']['vip0'] = true; 33 $result['vipGrade']['vip0'] = true;
20 break; 34 break;
@@ -26,37 +40,70 @@ class GradeModel { @@ -26,37 +40,70 @@ class GradeModel {
26 break; 40 break;
27 case 3://白金会员 41 case 3://白金会员
28 $result['vipGrade']['vip3'] = true; 42 $result['vipGrade']['vip3'] = true;
29 - break; 43 + break;
30 } 44 }
31 //今年总消费 45 //今年总消费
32 $result['vipGrade']['costOfThisYear'] = $data['data']['current_year_cost']; 46 $result['vipGrade']['costOfThisYear'] = $data['data']['current_year_cost'];
33 //升级下一等级会员的进度; 47 //升级下一等级会员的进度;
34 - $result['vipGrade']['percent'] = round(round($data['data']['current_total_cost'],2)/round($data['data']['next_need_cost'],2),2); 48 + $result['vipGrade']['percent'] = 100*(round(round($data['data']['current_total_cost'], 2) / round($data['data']['next_need_cost'], 2), 2));
35 //距离升级所需消费金额 49 //距离升级所需消费金额
36 - if($data['data']['current_vip_level'] != 3){ 50 + if ($data['data']['current_vip_level'] != 3) {
37 $result['vipGrade']['costGap'] = $data['data']['upgrade_need_cost']; 51 $result['vipGrade']['costGap'] = $data['data']['upgrade_need_cost'];
38 } 52 }
39 //消费总计 53 //消费总计
40 $result['vipGrade']['sumCost'] = $data['data']['current_total_cost']; 54 $result['vipGrade']['sumCost'] = $data['data']['current_total_cost'];
41 - //username  
42 - //$result['vipGrade']['username'] = GradeData::getUserProfileData($gender,$uid,$channel);  
43 - $result['vipGrade']['name'] = 'yangyang';  
44 - //print_r($result);  
45 -  
46 - return $result; 55 + //username 接口问题取不到,暂时写uid
  56 + $result['vipGrade']['name'] = $uid;
  57 + $result['vipGrade']['allUrl'] = Helpers::url('/Home/preferential',null);
  58 + }
  59 +
  60 + if (USE_CACHE) {
  61 + // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
  62 + if (empty($result)) {
  63 + $result = Cache::get(CacheConfig::KEY_ACTION_HOME_GRADE, 'slave');
  64 + }
  65 + // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
  66 + else {
  67 + Cache::set(CacheConfig::KEY_ACTION_HOME_GRADE, $result);
  68 + }
47 } 69 }
48 70
49 - return false; 71 + return $result;
50 } 72 }
51 - /* 73 +
  74 + /*
52 * 获取个人中心-会员特权详情页 75 * 获取个人中心-会员特权详情页
53 */ 76 */
54 - public function getPreferential($channel,$uid){ 77 +
  78 + public function getPreferential($channel, $uid) {
55 $result = array(); 79 $result = array();
56 - $data = GradeData::getPreferentialData($channel,$uid);  
57 - if(isset($data['code']) && $data['code'] == 200){  
58 - //$data['data'] 80 +
  81 + if (USE_CACHE) {
  82 + // 先尝试获取一级缓存(master), 有数据则直接返回.
  83 + $result = Cache::get(CacheConfig::KEY_ACTION_HOME_PREFERENTIAL, 'master');
  84 + if (!empty($result)) {
  85 + return $result;
  86 + }
  87 + }
  88 + //调取接口获得数据
  89 + $data = GradeData::getPreferentialData($channel, $uid);
  90 + if (isset($data['code']) && $data['code'] == 200) {
  91 + $result['vipGrade']['privilege'] = $data['data'];
  92 + }
  93 +
  94 +
  95 + if (USE_CACHE) {
  96 + // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
  97 + if (empty($result)) {
  98 + $result = Cache::get(CacheConfig::KEY_ACTION_HOME_GRADE, 'slave');
  99 + }
  100 + // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
  101 + else {
  102 + Cache::set(CacheConfig::KEY_ACTION_HOME_PREFERENTIAL, $result);
  103 + }
59 } 104 }
60 - return $data; 105 +
  106 + return $result;
61 } 107 }
  108 +
62 } 109 }