Authored by yangyang

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

更改了GradeData.php:增加了获取会员等级数据,获取会员等级详情数据;
微调privilege.phtml和vip-grade.phtml;
修改了Home.php:增加了会员等级展示页和会员特权查看页数据;
修改了Grade.php:增加了getGrade,和getPreferential;
... ... @@ -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;
namespace LibModels\Wap\Home;
use Api\Yohobuy;
use Api\Sign;
/*
*个人中心-会员等级接口操作类
* 个人中心-会员等级接口操作类
*/
class GradeData {
class GradeData
{
/**
* 获取会员等级展示数据
*/
public function getGradeData($channel,$uid){
* 获取会员等级数据
* @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);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
/**
* 获取会员特权查看页面数据
*/
public function getPreferentialData($channel,$uid){
* 获取会员特权详情数据
* @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['method'] = 'app.passport.getPrivilege';
$param['client_secret'] = Sign::getSign($param);
//print_r($param);
//print_r(Yohobuy::get('http://api.open.yohobuy.com',$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::get(Yohobuy::API_URL,$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>
... ...
... ... @@ -187,24 +187,31 @@ class HomeController extends AbstractAction
* 会员等级展示页
*/
public function gradeAction(){
//设置网站seo信息
$this->setTitle('会员等级');
//显示网站导航头部信息
$this->setNavHeader('会员等级');
$gender = Helpers::getGenderByCookie();
$channel = Helpers::getChannelByCookie();
$uid = $this -> getUid();
$uid = '10267443';
$uid = '10267443';//临时测试用
$data = GradeModel::getGrade($gender,$channel,$uid);
$this -> _view -> display('vip-grade',$data);
}
/*
*会员特权查看页
*/
public function preferentialAction(){
$channel = Helpers::getChannelByCookie();
$uid = $this -> getUid();
//设置网站seo信息
$this->setTitle('会员等级');
//显示网站导航头部信息
$this->setNavHeader('会员特权详情');
$channel = Helpers::getChannelByCookie();
$uid = $this -> getUid();
$data = GradeModel::getPreferential($channel,$uid);
//print_r($data);
//$this -> _view -> display('index',$data);
$this -> _view -> display('privilege',$data);
}
}
... ...
<?php
namespace home;
use LibModels\Wap\Home\GradeData;
use Action\AbstractAction;
use Plugin\Helpers;
/**
*会员等级相关数据处理
* 会员等级相关数据处理
*/
class GradeModel {
class GradeModel
{
/*
* 获取个人中心-会员等级数据
*/
public function getGrade($gender,$channel,$uid){
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'])){
$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;
... ... @@ -26,37 +40,70 @@ class GradeModel {
break;
case 3://白金会员
$result['vipGrade']['vip3'] = true;
break;
break;
}
//今年总消费
$result['vipGrade']['costOfThisYear'] = $data['data']['current_year_cost'];
//升级下一等级会员的进度;
$result['vipGrade']['percent'] = round(round($data['data']['current_total_cost'],2)/round($data['data']['next_need_cost'],2),2);
$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){
if ($data['data']['current_vip_level'] != 3) {
$result['vipGrade']['costGap'] = $data['data']['upgrade_need_cost'];
}
//消费总计
$result['vipGrade']['sumCost'] = $data['data']['current_total_cost'];
//username
//$result['vipGrade']['username'] = GradeData::getUserProfileData($gender,$uid,$channel);
$result['vipGrade']['name'] = 'yangyang';
//print_r($result);
return $result;
//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 false;
return $result;
}
/*
/*
* 获取个人中心-会员特权详情页
*/
public function getPreferential($channel,$uid){
public function getPreferential($channel, $uid) {
$result = array();
$data = GradeData::getPreferentialData($channel,$uid);
if(isset($data['code']) && $data['code'] == 200){
//$data['data']
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 $data;
return $result;
}
}
... ...