Authored by xuqi

Merge branch 'develop' of http://git.dev.yoho.cn/web/yohobuy into develop

@@ -44,4 +44,7 @@ class CacheConfig @@ -44,4 +44,7 @@ class CacheConfig
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 46
  47 + const KEY_ACTION_HOME_GRADE = 'key_action_home_grade';//会员等级
  48 + const KEY_ACTION_HOME_PREFERENTIAL = 'key_action_home_preferential';//会员特权详情
  49 +
47 } 50 }
  1 +<?php
  2 +
  3 +namespace LibModels\Wap\Home;
  4 +
  5 +use Api\Yohobuy;
  6 +use Api\Sign;
  7 +
  8 +/*
  9 + * 个人中心-会员等级接口操作类
  10 + */
  11 +
  12 +class GradeData
  13 +{
  14 +
  15 + /**
  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 +
  23 + $param = Yohobuy::param();
  24 + $param['yh_channel'] = $channel;
  25 + $param['uid'] = $uid;
  26 + $param['method'] = 'app.Passport.vip';
  27 + $param['client_secret'] = Sign::getSign($param);
  28 + return Yohobuy::get(Yohobuy::API_URL, $param);
  29 + }
  30 +
  31 + /**
  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 +
  39 + $param = Yohobuy::param();
  40 + $param['yh_channel'] = $channel;
  41 + $param['uid'] = $uid;
  42 + $param['method'] = 'app.passport.getPrivilege';
  43 + $param['client_secret'] = Sign::getSign($param);
  44 + return Yohobuy::get(Yohobuy::API_URL, $param);
  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 +
  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>
1 <?php 1 <?php
2 2
3 use Action\AbstractAction; 3 use Action\AbstractAction;
  4 +use home\GradeModel;
4 use Plugin\Helpers; 5 use Plugin\Helpers;
5 6
6 /** 7 /**
@@ -226,4 +227,35 @@ class HomeController extends AbstractAction @@ -226,4 +227,35 @@ class HomeController extends AbstractAction
226 227
227 } 228 }
228 229
  230 + /**
  231 + * 会员等级展示页
  232 + */
  233 + public function gradeAction(){
  234 + //设置网站seo信息
  235 + $this->setTitle('会员等级');
  236 + //显示网站导航头部信息
  237 + $this->setNavHeader('会员等级');
  238 +
  239 + $gender = Helpers::getGenderByCookie();
  240 + $channel = Helpers::getChannelByCookie();
  241 + $uid = $this -> getUid();
  242 + $uid = '10267443';//临时测试用
  243 + $data = GradeModel::getGrade($gender,$channel,$uid);
  244 + $this -> _view -> display('vip-grade',$data);
  245 + }
  246 + /*
  247 + *会员特权查看页
  248 + */
  249 + public function preferentialAction(){
  250 + //设置网站seo信息
  251 + $this->setTitle('会员等级');
  252 + //显示网站导航头部信息
  253 + $this->setNavHeader('会员特权详情');
  254 +
  255 + $channel = Helpers::getChannelByCookie();
  256 + $uid = $this -> getUid();
  257 + $data = GradeModel::getPreferential($channel,$uid);
  258 + $this -> _view -> display('privilege',$data);
  259 + }
  260 +
229 } 261 }
  1 +<?php
  2 +
  3 +namespace home;
  4 +
  5 +use LibModels\Wap\Home\GradeData;
  6 +use Action\AbstractAction;
  7 +use Plugin\Helpers;
  8 +
  9 +/**
  10 + * 会员等级相关数据处理
  11 + */
  12 +class GradeModel
  13 +{
  14 + /*
  15 + * 获取个人中心-会员等级数据
  16 + */
  17 +
  18 + public function getGrade($gender, $channel, $uid) {
  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 + }
  28 + //调用接口获取数据
  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'])) {
  32 + case 0://普通会员
  33 + $result['vipGrade']['vip0'] = true;
  34 + break;
  35 + case 1://银卡会员
  36 + $result['vipGrade']['vip1'] = true;
  37 + break;
  38 + case 2://金卡会员
  39 + $result['vipGrade']['vip2'] = true;
  40 + break;
  41 + case 3://白金会员
  42 + $result['vipGrade']['vip3'] = true;
  43 + break;
  44 + }
  45 + //今年总消费
  46 + $result['vipGrade']['costOfThisYear'] = $data['data']['current_year_cost'];
  47 + //升级下一等级会员的进度;
  48 + $result['vipGrade']['percent'] = 100*(round(round($data['data']['current_total_cost'], 2) / round($data['data']['next_need_cost'], 2), 2));
  49 + //距离升级所需消费金额
  50 + if ($data['data']['current_vip_level'] != 3) {
  51 + $result['vipGrade']['costGap'] = $data['data']['upgrade_need_cost'];
  52 + }
  53 + //消费总计
  54 + $result['vipGrade']['sumCost'] = $data['data']['current_total_cost'];
  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 + }
  69 + }
  70 +
  71 + return $result;
  72 + }
  73 +
  74 + /*
  75 + * 获取个人中心-会员特权详情页
  76 + */
  77 +
  78 + public function getPreferential($channel, $uid) {
  79 + $result = array();
  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 + }
  104 + }
  105 +
  106 + return $result;
  107 + }
  108 +
  109 +}
  1 +<?php
  2 +
  3 +use Action\AbstractAction;
  4 +
  5 +/**
  6 + * 会员等级
  7 + */
  8 +class GradeController extends AbstractAction{
  9 +
  10 + /**
  11 + * 会员等级展示页
  12 + */
  13 + public function indexAction(){
  14 + //$data =
  15 + echo "1";
  16 + //$data = '1';
  17 + //$this -> _view -> display('index',$data);
  18 + }
  19 +}