Authored by xuqi

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

... ... @@ -43,5 +43,8 @@ class CacheConfig
const KEY_ACTION_SEARCH_SEARCH = 'key_action_search_search'; // 搜索的数据
const KEY_ACTION_SEARCH_FILTER = 'key_action_search_filter'; // 搜索的过滤条件
const KEY_ACTION_HOME_GRADE = 'key_action_home_grade';//会员等级
const KEY_ACTION_HOME_PREFERENTIAL = 'key_action_home_preferential';//会员特权详情
}
... ...
<?php
namespace LibModels\Wap\Home;
use Api\Yohobuy;
use Api\Sign;
/*
* 个人中心-会员等级接口操作类
*/
class GradeData
{
/**
* 获取会员等级数据
* @param string $yh_channel 频道数据,1->男,2->女,3->潮童,4->创意生活,5->其他
* @param string $uid 用户id
* @return array 接口返回的会员等级数据
*/
public function getGradeData($channel, $uid) {
$param = Yohobuy::param();
$param['yh_channel'] = $channel;
$param['uid'] = $uid;
$param['method'] = 'app.Passport.vip';
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
/**
* 获取会员特权详情数据
* @param string $yh_channel 频道数据,1->男,2->女,3->潮童,4->创意生活,5->其他
* @param string $uid 用户id
* @return array 接口返回的会员特权详情数据
*/
public function getPreferentialData($channel, $uid) {
$param = Yohobuy::param();
$param['yh_channel'] = $channel;
$param['uid'] = $uid;
$param['method'] = 'app.passport.getPrivilege';
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
/**
* 获取用户基本信息数据??获取不到
*/
// public function getUserProfileData($gender, $uid, $channel) {
// $param = Yohobuy::param();
// $param['gender'] = $gender;
// $param['uid'] = $uid;
// $param['yh_channel'] = $channel;
// $param['method'] = 'app.passport.profile';
// $param['client_secret'] = Sign::getSign($param);
// var_dump(Yohobuy::post(Yohobuy::API_URL,$param));
// }
}
... ...
{{> layout/header}}
<div class="vip-grade-page yoho-page">
{{# vipGrade}}
{{> me/privilege}}
{{> me/vip-grade/privilege}}
{{/ vipGrade}}
</div>
{{> layout/footer}}
\ No newline at end of file
... ...
... ... @@ -23,9 +23,9 @@
</div>
{{/unless}}
<a class="all-privilege block">
<a class="all-privilege block" href="{{allUrl}}" >
查看全部VIP特权
<span class="iconfont">&#xe604;</span>
<span class="iconfont>&#xe604;</span>
</a>
{{/ vipGrade}}
</div>
... ...
<?php
use Action\AbstractAction;
use home\GradeModel;
use Plugin\Helpers;
/**
... ... @@ -225,5 +226,36 @@ class HomeController extends AbstractAction
}
}
/**
* 会员等级展示页
*/
public function gradeAction(){
//设置网站seo信息
$this->setTitle('会员等级');
//显示网站导航头部信息
$this->setNavHeader('会员等级');
$gender = Helpers::getGenderByCookie();
$channel = Helpers::getChannelByCookie();
$uid = $this -> getUid();
$uid = '10267443';//临时测试用
$data = GradeModel::getGrade($gender,$channel,$uid);
$this -> _view -> display('vip-grade',$data);
}
/*
*会员特权查看页
*/
public function preferentialAction(){
//设置网站seo信息
$this->setTitle('会员等级');
//显示网站导航头部信息
$this->setNavHeader('会员特权详情');
$channel = Helpers::getChannelByCookie();
$uid = $this -> getUid();
$data = GradeModel::getPreferential($channel,$uid);
$this -> _view -> display('privilege',$data);
}
}
... ...
<?php
namespace home;
use LibModels\Wap\Home\GradeData;
use Action\AbstractAction;
use Plugin\Helpers;
/**
* 会员等级相关数据处理
*/
class GradeModel
{
/*
* 获取个人中心-会员等级数据
*/
public function getGrade($gender, $channel, $uid) {
$result = array();
if (USE_CACHE) {
// 先尝试获取一级缓存(master), 有数据则直接返回.
$result = Cache::get(CacheConfig::KEY_ACTION_HOME_GRADE, 'master');
if (!empty($result)) {
return $result;
}
}
//调用接口获取数据
$data = GradeData::getGradeData($channel, $uid);
if (isset($data['code']) && $data['code'] === 200 && isset($data['data'])) {
switch (intval($data['data']['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'] = $data['data']['current_year_cost'];
//升级下一等级会员的进度;
$result['vipGrade']['percent'] = 100*(round(round($data['data']['current_total_cost'], 2) / round($data['data']['next_need_cost'], 2), 2));
//距离升级所需消费金额
if ($data['data']['current_vip_level'] != 3) {
$result['vipGrade']['costGap'] = $data['data']['upgrade_need_cost'];
}
//消费总计
$result['vipGrade']['sumCost'] = $data['data']['current_total_cost'];
//username 接口问题取不到,暂时写uid
$result['vipGrade']['name'] = $uid;
$result['vipGrade']['allUrl'] = Helpers::url('/Home/preferential',null);
}
if (USE_CACHE) {
// 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
if (empty($result)) {
$result = Cache::get(CacheConfig::KEY_ACTION_HOME_GRADE, 'slave');
}
// 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
else {
Cache::set(CacheConfig::KEY_ACTION_HOME_GRADE, $result);
}
}
return $result;
}
/*
* 获取个人中心-会员特权详情页
*/
public function getPreferential($channel, $uid) {
$result = array();
if (USE_CACHE) {
// 先尝试获取一级缓存(master), 有数据则直接返回.
$result = Cache::get(CacheConfig::KEY_ACTION_HOME_PREFERENTIAL, 'master');
if (!empty($result)) {
return $result;
}
}
//调取接口获得数据
$data = GradeData::getPreferentialData($channel, $uid);
if (isset($data['code']) && $data['code'] == 200) {
$result['vipGrade']['privilege'] = $data['data'];
}
if (USE_CACHE) {
// 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
if (empty($result)) {
$result = Cache::get(CacheConfig::KEY_ACTION_HOME_GRADE, 'slave');
}
// 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
else {
Cache::set(CacheConfig::KEY_ACTION_HOME_PREFERENTIAL, $result);
}
}
return $result;
}
}
... ...
<?php
use Action\AbstractAction;
/**
* 会员等级
*/
class GradeController extends AbstractAction{
/**
* 会员等级展示页
*/
public function indexAction(){
//$data =
echo "1";
//$data = '1';
//$this -> _view -> display('index',$data);
}
}
... ...