Authored by ccbikai

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

framework @ 75bbc3b0
Subproject commit 119c247f5cf929aa1e059e40609bb16dd6b58f05
Subproject commit 75bbc3b075de19f239532f60c5995d06c5f814e2
... ...
... ... @@ -18,14 +18,15 @@ class Yohobuy
{
/* 正式环境 */
// const API_URL = 'http://api2.open.yohobuy.com/';
// const SERVICE_URL = 'http://service.api.yohobuy.com/';
// const YOHOBUY_URL = 'http://www.yohobuy.com/';
const API_URL = 'http://api2.open.yohobuy.com/';
const API_URL2 = 'http://api.open.yohobuy.com/';
const SERVICE_URL = 'http://service.api.yohobuy.com/';
const YOHOBUY_URL = 'http://www.yohobuy.com/';
/* 测试环境 */
const API_URL = 'http://test2.open.yohobuy.com/';
const SERVICE_URL = 'http://test.service.api.yohobuy.com/';
const YOHOBUY_URL = 'http://www.yohobuy.com/';
// const API_URL = 'http://test2.open.yohobuy.com/';
// const SERVICE_URL = 'http://test.service.api.yohobuy.com/';
// const YOHOBUY_URL = 'http://www.yohobuy.com/';
/**
* 私钥列表
... ...
... ... @@ -42,5 +42,6 @@ class CacheConfig
const KEY_ACTION_HOME_PREFERENTIAL = 'key_action_home_preferential';//会员特权详情
const KEY_ACTION_GUANG_PLUSTAR_DATA = 'key_action_guang_plustar_data'; // 逛PLUSTAR
const KEY_ACTION_GUANG_DETAIL_DATA = 'key_action_guang_detail_data'; // 逛内容详情
const KEY_ACTION_HOME_ORDER_ORDER = 'key_action_home_order_order';//订单列表
}
... ...
... ... @@ -19,7 +19,7 @@ class GradeData
* @param string $uid 用户id
* @return array 接口返回的会员等级数据
*/
public function getGradeData($gender,$channel, $uid) {
public function getGradeData($gender, $channel, $uid) {
$urlList = array();
//获取会员等级数据
$param = Yohobuy::param();
... ... @@ -27,8 +27,8 @@ class GradeData
$param['uid'] = $uid;
$param['method'] = 'app.Passport.vip';
$param['client_secret'] = Sign::getSign($param);
$urlList['grade'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param);
$urlList['grade'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL, $param);
//获取用户基本信息数据(用来得到username)
$param = Yohobuy::param();
$param['gender'] = $gender;
... ... @@ -36,8 +36,8 @@ class GradeData
$param['yh_channel'] = $channel;
$param['method'] = 'app.passport.profile';
$param['client_secret'] = Sign::getSign($param);
$urlList['userProfile'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param);
$urlList['userProfile'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL, $param);
return Yohobuy::getMulti($urlList);
}
... ...
... ... @@ -4,6 +4,7 @@ namespace LibModels\Wap\Home;
use Api\Yohobuy;
use Api\Sign;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
... ... @@ -18,11 +19,13 @@ use Api\Sign;
class OrderData
{
/*
* 获取订单数据
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
public function getOrderData($type,$page,$limit,$gender,$yh_channel,$uid){
* 获取订单数据
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
public function getOrderData($type, $page, $limit, $gender, $yh_channel, $uid) {
//构建必传参数
$param = Yohobuy::param();
$param['gender'] = $gender;
$param['limit'] = $limit;
... ... @@ -32,7 +35,8 @@ class OrderData
$param['uid'] = $uid;
$param['yh_channel'] = $yh_channel;
$param['client_secret'] = Sign::getSign($param);
print_r($param);
return Yohobuy::get(Yohobuy::API_URL,$param);
//调用接口获得数据
return Yohobuy::get(Yohobuy::API_URL2, $param);
}
}
... ...
... ... @@ -8,18 +8,18 @@ var page = 1,
hotnav,
listTop,
navSwiper,
notab=0,
notab = 0,
sort = '',
id = '';
function hotrank(page, sort, tabId, notab) {
console.log(sort);
$.ajax({
type: 'GET',
url: '/product/newsale/selectHotrank',
url: '/product/newsale/selectHotrank?'+sort,
dataType: 'html',
data: {
page: page,
sort: sort,
tab_id: tabId,
notab: notab
},
... ... @@ -48,8 +48,8 @@ function hotrank(page, sort, tabId, notab) {
hotnav = new Hammer($('.s-goods-nav .nav-item')[index]);
hotnav.on('tap', function(e) {
var navItme = $('.s-goods-nav .nav-item').eq(index);
id = navItme.data('id') ? navItme.data('id') : '';
sort = navItme.data('sort') ? navItme.data('sort') : '';
page = 1;
notab = 1;
hotrank(page, sort, id, notab);
... ...
... ... @@ -16,24 +16,24 @@ use Plugin\Helpers;
*/
class HomeController extends AbstractAction
{
/**
* 个人中心入口
*/
public function indexAction()
{
// 设置网站标题
public function indexAction() {
// 设置网站标题
$this->setTitle('个人中心');
$this->setNavHeader('个人中心', true, SITE_MAIN);
$this->setNavHeader('个人中心', true, SITE_MAIN);
// $uid = $this->getUid();
$uid = 967016;
$data = \Index\UserModel::getUserProfileData($uid);
$data += \Index\UserModel::getInfoNumData($uid);
// $uid = $this->getUid();
$uid = 967016;
$data = \Index\UserModel::getUserProfileData($uid);
$data += \Index\UserModel::getInfoNumData($uid);
// 优选新品数据
$channel = Helpers::getChannelByCookie();
$data['recommendForYou'] = \Index\UserModel::getPreferenceData($channel);
// print_r($data);
// 优选新品数据
$channel = Helpers::getChannelByCookie();
$data['recommendForYou'] = \Index\UserModel::getPreferenceData($channel);
// print_r($data);
$data['myIndexPage'] = true;
$data['pageFooter'] = true;
... ... @@ -41,63 +41,60 @@ class HomeController extends AbstractAction
$this->_view->display('index', $data);
}
/**
* 用户订单
*/
public function ordersAction()
{
// $uid = $this->getUid();
// $type = $this->get('type', 1);
// $orders = \Index\UserModel::getUserOrderData(967016, $type);
$order = array(
'orders' => array(
array(
'orderNum' => '408539077',
'tradingStatus' => '交易成功',
'goods' => array(
array(
'id' => 1,
'thumb' => 'http://img11.static.yhbimg.com/goodsimg/2015/11/04/05/01ce2aff32fc3c90584f516167cd526d91.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',
'name' => 'Adidas Originals ZX FLUXM22508',
'color' => '黄',
'size' => '43',
'price' => '699.00',
'count' => '2'
),
array(
'id' => 1,
'thumb' => 'http://img10.static.yhbimg.com/goodsimg/2015/11/04/05/0188f1aca49ac478a565ec029b5d2d4a6c.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',
'name' => 'B.Duck浴室玩伴mini浮水鸭',
'gift' => true,
'color' => '黄',
'size' => '43',
'price' => '0.00',
'count' => '1'
)
),
'count' => 2,
'sumCost' => '699.00',
'unpaid' => true,
)
)
);
/**
* 用户订单
*/
public function ordersAction() {
// $uid = $this->getUid();
// $type = $this->get('type', 1);
// $orders = \Index\UserModel::getUserOrderData(967016, $type);
$this->_view->display('order', array('order' => $order, 'orderPage' => true));
// print_r($orders);
}
$order = array(
'orders' => array(
array(
'orderNum' => '408539077',
'tradingStatus' => '交易成功',
'goods' => array(
array(
'id' => 1,
'thumb' => 'http://img11.static.yhbimg.com/goodsimg/2015/11/04/05/01ce2aff32fc3c90584f516167cd526d91.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',
'name' => 'Adidas Originals ZX FLUXM22508',
'color' => '黄',
'size' => '43',
'price' => '699.00',
'count' => '2'
),
array(
'id' => 1,
'thumb' => 'http://img10.static.yhbimg.com/goodsimg/2015/11/04/05/0188f1aca49ac478a565ec029b5d2d4a6c.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',
'name' => 'B.Duck浴室玩伴mini浮水鸭',
'gift' => true,
'color' => '黄',
'size' => '43',
'price' => '0.00',
'count' => '1'
)
),
'count' => 2,
'sumCost' => '699.00',
'unpaid' => true,
)
)
);
/**
* 用户收藏的商品
*/
public function favoriteAction()
{
$uid = $this->getUid();
$this->_view->display('order', array('order' => $order, 'orderPage' => true));
// print_r($orders);
}
$favProducts = \Index\UserModel::getFavProductData($uid);
/**
* 用户收藏的商品
*/
public function favoriteAction() {
$uid = $this->getUid();
$favProducts = \Index\UserModel::getFavProductData($uid);
//print_r($favProducts);
//print_r($favProducts);
$this->_view->display('favorite', array(
'favPage' => true,
... ... @@ -111,57 +108,43 @@ class HomeController extends AbstractAction
'hasFavProduct' => false,
'hasFavBrand' => false
));
}
}
/**
* 用户收藏的品牌
*/
public function favoritebrandAction()
{
$uid = $this->getUid();
$gender = Helpers::getGenderByCookie();
/**
* 用户收藏的品牌
*/
public function favoritebrandAction() {
$uid = $this->getUid();
$gender = Helpers::getGenderByCookie();
$favBrands = \Index\UserModel::getFavBrandData($uid, $gender);
$favBrands = \Index\UserModel::getFavBrandData($uid, $gender);
print_r($favBrands);
}
print_r($favBrands);
}
/**
* 个人信息
*/
public function personalDetailsAction()
{
/**
* 个人信息
*/
public function personalDetailsAction() {
$this->setTitle('个人信息');
$this->setNavHeader('个人信息', true, SITE_MAIN);
$this->setNavHeader('个人信息', true, SITE_MAIN);
// $uid = $this->getUid();
$uid = 967016;
$data = \Index\UserModel::getUserProfileData($uid);
$data['pageFooter'] = true;
// $uid = $this->getUid();
$uid = 967016;
$data = \Index\UserModel::getUserProfileData($uid);
$data['pageFooter'] = true;
$this->_view->display('personal-details', $data);
}
/**
* YOHO币
*/
public function currencyAction() {
// $uid = $this->getUid();
$this->setNavHeader('YOHO币', true, false);
}
/**
* YOHO币
*/
public function currencyAction()
{
// $uid = $this->getUid();
$this->setNavHeader('YOHO币', true, false);
$uid = 967016;
$currency = \Index\UserModel::getYohoCoinData($uid);
$this->_view->display('currency', $currency);
}
/**
* 优惠券
*/
public function couponsAction()
{
$uid = 967016;
$currency = \Index\UserModel::getYohoCoinData($uid);
$this->setTitle('优惠券');
$this->setNavHeader('优惠券', true, SITE_MAIN);
... ... @@ -176,31 +159,45 @@ class HomeController extends AbstractAction
);
$this->_view->display('coupons', $coupons);
}
/**
* 优惠券
*/
public function couponsAction() {
}
$this->setTitle('优惠券');
$this->setNavHeader('优惠券', true, SITE_MAIN);
// $uid = $this->getUid();
$uid = 8826435;
$status = $this->get('status', 0);
$coupons = array(
'couponsUrl' => \Index\UserModel::getCouponData($uid, $status),
'couponsPage' => true
);
/**
* 我的消息
*/
public function messageAction()
{
// $uid = $this->getUid();
$page = $this->get('page', 0);
$size = $this->get('size', 10);
print_r($coupons);
$this->_view->display('coupons', $coupons);
}
$uid = 967016;
$messages = \Index\UserModel::getMessageData($uid, $page, $size);
/**
* 我的消息
*/
public function messageAction() {
// $uid = $this->getUid();
$page = $this->get('page', 0);
$size = $this->get('size', 10);
print_r($messages);
$uid = 967016;
$messages = \Index\UserModel::getMessageData($uid, $page, $size);
}
print_r($messages);
}
/**
* 地址管理
*/
public function addressAction()
{
// 设置网站标题
/**
* 地址管理
*/
public function addressAction() {
// 设置网站标题
$this->setTitle('地址管理');
$this->setNavHeader('地址管理', true, SITE_MAIN);
... ... @@ -210,7 +207,7 @@ class HomeController extends AbstractAction
$address = \Index\UserModel::getAddressData($uid);
$addressList = \Index\UserModel::getAddressListData($uid);
// print_r($address);
// print_r($address);
$this->_view->display('address', array(
'addressPage' => true,
... ... @@ -218,7 +215,7 @@ class HomeController extends AbstractAction
'address' => $address,
'addressList' => $addressList
));
}
}
/**
* 修改地址或者添加新地址
... ... @@ -273,8 +270,7 @@ class HomeController extends AbstractAction
}
//在线客服
public function onlineServiceAction()
{
public function onlineServiceAction() {
// 设置网站标题
$this->setTitle('在线客服');
$this->setNavHeader('在线客服', true, SITE_MAIN);
... ... @@ -289,8 +285,7 @@ class HomeController extends AbstractAction
}
//在线客服-具体详情
public function onlineServiceDetailAction()
{
public function onlineServiceDetailAction() {
$service = array();
$cateId = $this->get('cateId', 0);
$cateName = $this->get('cateName', '');
... ... @@ -304,25 +299,23 @@ class HomeController extends AbstractAction
}
/**
* 我的逛
*/
public function myGuangAction()
{
echo 'My Guang';
}
* 我的逛
*/
public function myGuangAction() {
echo 'My Guang';
}
/**
* 意见反馈
*/
public function suggestAction()
{
$udid = $this->getUdid();
$page = $this->get('page', 1);
$limit = $this->get('limit', 30);
/**
* 意见反馈
*/
public function suggestAction() {
$udid = $this->getUdid();
$page = $this->get('page', 1);
$limit = $this->get('limit', 30);
$suggest = \Index\UserModel::getSuggestData($udid, $page, $limit);
$suggest = \Index\UserModel::getSuggestData($udid, $page, $limit);
//print_r($suggest);
//print_r($suggest);
$this->_view->display('suggest', array(
'suggestPage' => true,
'pageHeader' => array(
... ... @@ -352,133 +345,92 @@ class HomeController extends AbstractAction
'bad' => false)
)
));
}
}
/**
* 异步保存意见反馈数据
*/
public function savesuggestAction() {
if ($this->isAjax()) {
$uid = $this->getUid();
$content = $this->post('content', '');
$suggest_type = $this->get('suggest_type', 2);
/**
* 异步保存意见反馈数据
*/
public function savesuggestAction()
{
if($this->isAjax()) {
$uid = $this->getUid();
$content = $this->post('content', '');
$suggest_type = $this->get('suggest_type', 2);
$result = \Index\UserModel::saveSuggestData($uid, $content, $suggest_type);
$result = \Index\UserModel::saveSuggestData($uid, $content, $suggest_type);
$this->echoJson($result);
}
}
$this->echoJson($result);
}
/**
* 会员等级展示页
*/
public function gradeAction() {
//设置网站seo信息
$this->setTitle('会员等级');
//显示网站导航头部信息
$this->setNavHeader('会员等级');
$gender = Helpers::getGenderByCookie();
$channel = Helpers::getChannelByCookie();
$uid = $this->getUid();
$uid = '7566245'; //临时测试用
$data = GradeModel::getGrade($gender, $channel, $uid);
$data['pageFooter'] = true;
$this->_view->display('vip-grade', $data);
}
}
/**
* 会员等级展示页
*/
public function gradeAction(){
//设置网站seo信息
$this->setTitle('会员等级');
//显示网站导航头部信息
$this->setNavHeader('会员等级');
$gender = Helpers::getGenderByCookie();
$channel = Helpers::getChannelByCookie();
$uid = $this -> getUid();
$uid = '7566245';//临时测试用
$data = GradeModel::getGrade($gender,$channel,$uid);
$data['pageFooter'] = true;
$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);
$data['pageFooter'] = true;
$this -> _view -> display('privilege',$data);
}
/*
*我的订单页面
*/
public function orderAction(){
do{
//判断是不是ajax请求
// if(!$this -> isAjax()){
// break;
// }
//判断参数是否有效
$type = $this -> get('type',1);
$page = $this -> get('page',1);
$limit = $this -> get('limit',10);
$gender = Helpers::getGenderByCookie();
$yh_channel = $this -> get('yh_channel',1);
$uid = $this -> getUid();
if(!empty($type) && !is_numeric($type)){
break;
}
//$data = OrderModel::getOrder();
$data = OrderModel::getOrder($type,$page,$limit,$gender,$yh_channel,$uid);
//print_r($data);
}
while(false);
//$this -> _view -> display('order',$data);
}
/*
* 会员特权查看页
*/
/**
* 订单详情页
public function preferentialAction() {
//设置网站seo信息
$this->setTitle('会员等级');
//显示网站导航头部信息
$this->setNavHeader('会员特权详情');
$channel = Helpers::getChannelByCookie();
$uid = $this->getUid();
$data = GradeModel::getPreferential($channel, $uid);
$data['pageFooter'] = true;
$this->_view->display('privilege', $data);
}
/*
* 我的订单页面
*/
public function orderDetailAction()
{
$data = array(
'name' => '毛毛莉Lydia',
'phoneNum' => '18600001133',
'address' => '南京市建邺区嘉陵江东街18号国家广告产业园5栋17楼',
'orderStatus' => '待收货',
'orderNum' => '418358063',
'orderTime' => '2014-03-10 17:25:10',
'unreceived' => true,
'logisticsUrl' => '',
'logisticsCompany' => '顺丰',
'logisticsNum' => '51537443456',
'goods' => array(
array(
'id' => 1,
'thumb' => 'http://img11.static.yhbimg.com/goodsimg/2015/11/04/05/01ce2aff32fc3c90584f516167cd526d91.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',
'name' => 'Adidas Originals ZX FLUXM22508',
'color' => '黄',
'size' => '43',
'price' => '699.00',
'count' => '2'
),
array(
'id' => 1,
'thumb' => 'http://img10.static.yhbimg.com/goodsimg/2015/11/04/05/0188f1aca49ac478a565ec029b5d2d4a6c.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',
'name' => 'B.Duck浴室玩伴mini浮水鸭',
'gift' => true,
'color' => '黄',
'size' => '43',
'price' => '0.00',
'count' => '1'
)
),
'sumPrice' => 799,
'salePrice' => 80,
'freight' => 5,
'yohoCoin' => 5,
'price' => 719
);
$this->_view->display('order-detail', array('orderDetail' => $data, 'orderDetailPage' => true));
public function orderAction() {
//获取基本参数:type:1=>全部,2=>待付款,3=>待发货,4=>待收货,5=>待评论
$type = $this->get('type', 1);
$page = $this->get('page', 1);
$limit = $this->get('limit', 10);
$gender = Helpers::getGenderByCookie();
$yh_channel = $this->get('yh_channel', 1);
$uid = $this->getUid();
$uid = '7566245'; //测试用
//调用模型层getOrder方法获得并处理数据
$data = OrderModel::getOrder($type, $page, $limit, $gender, $yh_channel, $uid);
//渲染模板
$this->_view->display('order', array(
'order' => array(
'orders' => $data
)
));
}
/*
* 我的订单-处理ajax请求页面(切换订单状态)
*/
public function orderAjaxAction() {
//判断是不是ajax请求
if (!$this->isAjax()) {
$this->error();
}
self::orderAction();
}
}
... ...
... ... @@ -26,41 +26,41 @@ class GradeModel
}
}
//调用接口获取数据
$data = GradeData::getGradeData($gender,$channel, $uid);
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'] = $data['grade']['current_year_cost'];
//升级下一等级会员的进度;
$result['vipGrade']['percent'] = 100*(round($data['grade']['current_total_cost'] / $data['grade']['next_need_cost'], 2));
//距离升级所需消费金额
if ($data['grade']['current_vip_level'] != 3) {
$result['vipGrade']['costGap'] = $data['grade']['upgrade_need_cost'];
}
//消费总计
$result['vipGrade']['sumCost'] = $data['grade']['current_total_cost'];
//username 调用获取用户基本信息数据,获得username;
//$userProfile = GradeData::getUserProfileData($gender,$uid,$channel);
$result['vipGrade']['name'] = $data['userProfile']['username'];
//跳转url(会员特权详情)
$result['vipGrade']['allUrl'] = Helpers::url('/Home/preferential',null);
//当前vip等级享受的特权
$result['vipGrade']['privilege'] = $data['grade']['enjoy_preferential'];
$data = GradeData::getGradeData($gender, $channel, $uid);
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'] = $data['grade']['current_year_cost'];
//升级下一等级会员的进度;
$result['vipGrade']['percent'] = 100 * (round($data['grade']['current_total_cost'] / $data['grade']['next_need_cost'], 2));
//距离升级所需消费金额
if ($data['grade']['current_vip_level'] != 3) {
$result['vipGrade']['costGap'] = $data['grade']['upgrade_need_cost'];
}
//消费总计
$result['vipGrade']['sumCost'] = $data['grade']['current_total_cost'];
//username 调用获取用户基本信息数据,获得username;
//$userProfile = GradeData::getUserProfileData($gender,$uid,$channel);
$result['vipGrade']['name'] = $data['userProfile']['username'];
//跳转url(会员特权详情)
$result['vipGrade']['allUrl'] = Helpers::url('/Home/preferential', null);
//当前vip等级享受的特权
$result['vipGrade']['privilege'] = $data['grade']['enjoy_preferential'];
if (USE_CACHE) {
// 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
... ... @@ -72,7 +72,7 @@ class GradeModel
Cache::set(CacheConfig::KEY_ACTION_HOME_GRADE, $result);
}
}
return $result;
}
... ... @@ -95,7 +95,7 @@ class GradeModel
if (isset($data['code']) && $data['code'] == 200) {
$result['vipGrade']['privilege'] = $data['data'];
}
if (USE_CACHE) {
// 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
... ... @@ -107,7 +107,7 @@ class GradeModel
Cache::set(CacheConfig::KEY_ACTION_HOME_PREFERENTIAL, $result);
}
}
return $result;
}
... ...
<?php
namespace home;
use LibModels\Wap\Home\OrderData;
namespace home;
use LibModels\Wap\Home\OrderData;
use Plugin\Helpers;
use Configs\CacheConfig;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
... ... @@ -15,15 +18,104 @@
*/
class OrderModel
{
/**
* 订单相关数据处理
*/
public function getOrder($type = 1,$page = 1,$limit,$gender,$yh_channel,$uid){
$data = OrderData::getOrderData($type,$page,$limit,$gender,$yh_channel,$uid);
return $data;
public function getOrder($type = 1, $page = 1, $limit, $gender, $yh_channel, $uid) {
$result = array();
if (USE_CACHE) {
$key = CacheConfig::KEY_ACTION_HOME_ORDER_ORDER;
// 先尝试获取一级缓存(master), 有数据则直接返回.
$result = Cache::get($key, 'master');
if (!empty($result)) {
return $result;
}
}
//调用接口获得数据
$data = OrderData::getOrderData($type, $page, $limit, $gender, $yh_channel, $uid);
//检查数据返回是否正常,正常则处理数据
if ($data['code'] == 200 && isset($data['data'])) {
foreach ($data['data']['order_list'] as $key => $vo) {
//订单号,支付状态,订单商品数量,订单总价格
$result[$key]['orderNum'] = $vo['order_code'];
$result[$key]['tradingStatus'] = $vo['status_str'];
$result[$key]['count'] = count($vo['order_goods']);
$result[$key]['sumCost'] = $vo['amount'] + $vo['shipping_cost'];
//订单商品列表数据
$result[$key]['goods'] = self::formatOrderGoods($vo['order_goods']);
//订单status判断订单处于什么状态。
do {
//订单取消状态
if ($vo['is_cancel'] === 'Y') {
$result[$key]['canceled'] = true;
break;
}
//支付方式不是货到付款时,计算订单状态
if ($vo['payment_type'] != 2) {
switch ($vo['status']) {
case 0:
$result[$key]['unpaid'] = true;
break;
case 1 || 2 || 3 || 4 || 5:
$result[$key]['unreceived'] = true;
$resault[$key]['logisticsUrl'] = "暂无logisticsUrl数据";
break;
case 6:
$result[$key]['completed'] = true;
break;
default:
break;
}
} elseif ($vo['payment_type'] == 2) {
//订单为货到付款订单时,订单没有未支付状态
switch ($vo['status']) {
case 0 || 1 || 2 || 3 || 4 || 5:
$result[$key]['unreceived'] = true;
//此处备注,接口没有返回logisticsUrl数据
$resault[$key]['logisticsUrl'] = "备注:暂无logisticsUrl数据";
break;
case 6:
$result[$key]['completed'] = true;
break;
default:
break;
}
}
} while (false);
}
}
if (USE_CACHE) {
// 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
if (empty($result)) {
$result = Cache::get($key, 'slave');
}
// 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
else {
Cache::set($key, $result);
}
}
return $result;
}
//格式化订单商品
static function formatOrderGoods($orderGoods) {
$arr = array();
foreach ($orderGoods as $key => $vo) {
$arr[$key]['thumb'] = Helpers::getImageUrl($vo['goods_image'], 90, 120);
$arr[$key]['name'] = $vo['product_name'];
$arr[$key]['color'] = $vo['color_name'];
$arr[$key]['size'] = $vo['size_name'];
$arr[$key]['price'] = $vo['goods_price'];
$arr[$key]['count'] = $vo['buy_number'];
if ($vo['goods_type'] == 'gift') {
$arr[$key]['gift'] = true;
} elseif ($vo['goods_type'] == 'price_gift') {
$arr[$key]['advanceBuy'] = true;
}
}
return $arr;
}
}
... ...