Authored by yangyang

修改了订单控制器,完成了订单列表功能。修改页面OrderData.php;Order.php;Home.php

... ... @@ -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';//订单列表
}
... ...
... ... @@ -25,6 +25,7 @@ class OrderData
*/
public function getOrderData($type, $page, $limit, $gender, $yh_channel, $uid) {
//构建必传参数
$param = Yohobuy::param();
$param['gender'] = $gender;
$param['limit'] = $limit;
... ... @@ -34,7 +35,7 @@ class OrderData
$param['uid'] = $uid;
$param['yh_channel'] = $yh_channel;
$param['client_secret'] = Sign::getSign($param);
//print_r($param);
//调用接口获得数据
return Yohobuy::get(Yohobuy::API_URL2, $param);
}
... ...
... ... @@ -227,8 +227,7 @@ class HomeController extends AbstractAction
}
//在线客服
public function onlineServiceAction()
{
public function onlineServiceAction() {
// 设置网站标题
$this->setTitle('在线客服');
$this->setNavHeader('在线客服', true, SITE_MAIN);
... ... @@ -243,12 +242,10 @@ class HomeController extends AbstractAction
}
//在线客服-具体详情
public function onlineServiceDetailAction()
{
public function onlineServiceDetailAction() {
$service = array();
$cateId = $this->get('cateId', 0);
if ($cateId > 0)
{
if ($cateId > 0) {
$service = home\OnlineModel::getOnlineServiceDetail($cateId);
}
$this->_view->display('online_service_detail', $service);
... ... @@ -257,16 +254,14 @@ class HomeController extends AbstractAction
/**
* 我的逛
*/
public function myGuangAction()
{
public function myGuangAction() {
echo 'My Guang';
}
/**
* 意见反馈
*/
public function suggestAction()
{
public function suggestAction() {
$udid = $this->getUdid();
$page = $this->get('page', 1);
$limit = $this->get('limit', 30);
... ... @@ -360,28 +355,35 @@ class HomeController extends AbstractAction
*/
public function orderAction() {
// do {
// //判断是不是ajax请求
// if(!$this -> isAjax()){
// break;
// }
//判断参数是否有效
//获取基本参数: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';
if (!empty($type) && !is_numeric($type)) {
break;
}
//$data = OrderModel::getOrder();
$uid = $this->getUid();
$uid = '7566245'; //测试用
//调用模型层getOrder方法获得并处理数据
$data = OrderModel::getOrder($type, $page, $limit, $gender, $yh_channel, $uid);
print_r($data);
//} while (false);
//$this -> _view -> display('order',$data);
//渲染模板
$this->_view->display('order', array(
'order' => array(
'orders' => $data
)
));
}
/*
* 我的订单-处理ajax请求页面(切换订单状态)
*/
public function orderAjaxAction() {
//判断是不是ajax请求
if (!$this->isAjax()) {
$this->error();
}
self::orderAction();
}
}
... ...
... ... @@ -3,6 +3,8 @@
namespace home;
use LibModels\Wap\Home\OrderData;
use Plugin\Helpers;
use Configs\CacheConfig;
/*
* To change this license header, choose License Headers in Project Properties.
... ... @@ -21,25 +23,57 @@ class OrderModel
* 订单相关数据处理
*/
public function getOrder($type = 1, $page = 1, $limit, $gender, $yh_channel, $uid) {
$data = OrderData::getOrderData($type, $page, $limit, $gender, $yh_channel, $uid);
$result = array();
if($data['code'] == 200 && isset($data['data'])){
foreach($data['data']['order_list'] as $key => $vo){
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'];
if($vo['payment_type'] != 2){
//订单商品列表数据
$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:
$result[$key]['unshipped'] = true;
case 1 || 2 || 3 || 4 || 5:
$result[$key]['unreceived'] = true;
$resault[$key]['logisticsUrl'] = "暂无logisticsUrl数据";
break;
case 6:
$result[$key]['completed'] = true;
break;
case 4 || 5:
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;
... ... @@ -47,28 +81,41 @@ class OrderModel
default:
break;
}
}else{
// switch ($vo['status']) {
// case 0:
// $result[$key]['unpaid'] = true;
// break;
// case 1 || 2 || 3:
// $result[$key]['unshipped'] = true;
// break;
// case 4 || 5:
// $result[$key]['unreceived'] = true;
// 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 $result;
return $data;
return $arr;
}
}
... ...