Authored by yangyang

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

@@ -42,5 +42,6 @@ class CacheConfig @@ -42,5 +42,6 @@ class CacheConfig
42 const KEY_ACTION_HOME_PREFERENTIAL = 'key_action_home_preferential';//会员特权详情 42 const KEY_ACTION_HOME_PREFERENTIAL = 'key_action_home_preferential';//会员特权详情
43 const KEY_ACTION_GUANG_PLUSTAR_DATA = 'key_action_guang_plustar_data'; // 逛PLUSTAR 43 const KEY_ACTION_GUANG_PLUSTAR_DATA = 'key_action_guang_plustar_data'; // 逛PLUSTAR
44 const KEY_ACTION_GUANG_DETAIL_DATA = 'key_action_guang_detail_data'; // 逛内容详情 44 const KEY_ACTION_GUANG_DETAIL_DATA = 'key_action_guang_detail_data'; // 逛内容详情
  45 + const KEY_ACTION_HOME_ORDER_ORDER = 'key_action_home_order_order';//订单列表
45 46
46 } 47 }
@@ -25,6 +25,7 @@ class OrderData @@ -25,6 +25,7 @@ class OrderData
25 */ 25 */
26 26
27 public function getOrderData($type, $page, $limit, $gender, $yh_channel, $uid) { 27 public function getOrderData($type, $page, $limit, $gender, $yh_channel, $uid) {
  28 + //构建必传参数
28 $param = Yohobuy::param(); 29 $param = Yohobuy::param();
29 $param['gender'] = $gender; 30 $param['gender'] = $gender;
30 $param['limit'] = $limit; 31 $param['limit'] = $limit;
@@ -34,7 +35,7 @@ class OrderData @@ -34,7 +35,7 @@ class OrderData
34 $param['uid'] = $uid; 35 $param['uid'] = $uid;
35 $param['yh_channel'] = $yh_channel; 36 $param['yh_channel'] = $yh_channel;
36 $param['client_secret'] = Sign::getSign($param); 37 $param['client_secret'] = Sign::getSign($param);
37 - //print_r($param); 38 + //调用接口获得数据
38 return Yohobuy::get(Yohobuy::API_URL2, $param); 39 return Yohobuy::get(Yohobuy::API_URL2, $param);
39 } 40 }
40 41
@@ -155,16 +155,16 @@ class HomeController extends AbstractAction @@ -155,16 +155,16 @@ class HomeController extends AbstractAction
155 public function couponsAction() { 155 public function couponsAction() {
156 156
157 $this->setTitle('优惠券'); 157 $this->setTitle('优惠券');
158 - $this->setNavHeader('优惠券', true, SITE_MAIN);  
159 - // $uid = $this->getUid();  
160 - $uid = 8826435;  
161 - $status = $this->get('status', 0);  
162 - $coupons = array(  
163 - 'couponsUrl' => \Index\UserModel::getCouponData($uid, $status),  
164 - 'couponsPage' => true  
165 - );  
166 -  
167 - print_r($coupons); 158 + $this->setNavHeader('优惠券', true, SITE_MAIN);
  159 + // $uid = $this->getUid();
  160 + $uid = 8826435;
  161 + $status = $this->get('status', 0);
  162 + $coupons = array(
  163 + 'couponsUrl' => \Index\UserModel::getCouponData($uid, $status),
  164 + 'couponsPage' => true
  165 + );
  166 +
  167 + print_r($coupons);
168 $this->_view->display('coupons', $coupons); 168 $this->_view->display('coupons', $coupons);
169 } 169 }
170 170
@@ -227,8 +227,7 @@ class HomeController extends AbstractAction @@ -227,8 +227,7 @@ class HomeController extends AbstractAction
227 } 227 }
228 228
229 //在线客服 229 //在线客服
230 - public function onlineServiceAction()  
231 - { 230 + public function onlineServiceAction() {
232 // 设置网站标题 231 // 设置网站标题
233 $this->setTitle('在线客服'); 232 $this->setTitle('在线客服');
234 $this->setNavHeader('在线客服', true, SITE_MAIN); 233 $this->setNavHeader('在线客服', true, SITE_MAIN);
@@ -243,37 +242,33 @@ class HomeController extends AbstractAction @@ -243,37 +242,33 @@ class HomeController extends AbstractAction
243 } 242 }
244 243
245 //在线客服-具体详情 244 //在线客服-具体详情
246 - public function onlineServiceDetailAction()  
247 - { 245 + public function onlineServiceDetailAction() {
248 $service = array(); 246 $service = array();
249 $cateId = $this->get('cateId', 0); 247 $cateId = $this->get('cateId', 0);
250 - if ($cateId > 0)  
251 - { 248 + if ($cateId > 0) {
252 $service = home\OnlineModel::getOnlineServiceDetail($cateId); 249 $service = home\OnlineModel::getOnlineServiceDetail($cateId);
253 } 250 }
254 $this->_view->display('online_service_detail', $service); 251 $this->_view->display('online_service_detail', $service);
255 } 252 }
256 253
257 /** 254 /**
258 - * 我的逛  
259 - */  
260 - public function myGuangAction()  
261 - {  
262 - echo 'My Guang';  
263 - }  
264 -  
265 - /**  
266 - * 意见反馈  
267 - */  
268 - public function suggestAction()  
269 - {  
270 - $udid = $this->getUdid();  
271 - $page = $this->get('page', 1);  
272 - $limit = $this->get('limit', 30);  
273 -  
274 - $suggest = \Index\UserModel::getSuggestData($udid, $page, $limit);  
275 -  
276 - //print_r($suggest); 255 + * 我的逛
  256 + */
  257 + public function myGuangAction() {
  258 + echo 'My Guang';
  259 + }
  260 +
  261 + /**
  262 + * 意见反馈
  263 + */
  264 + public function suggestAction() {
  265 + $udid = $this->getUdid();
  266 + $page = $this->get('page', 1);
  267 + $limit = $this->get('limit', 30);
  268 +
  269 + $suggest = \Index\UserModel::getSuggestData($udid, $page, $limit);
  270 +
  271 + //print_r($suggest);
277 $this->_view->display('suggest', array( 272 $this->_view->display('suggest', array(
278 'suggestPage' => true, 273 'suggestPage' => true,
279 'pageHeader' => array( 274 'pageHeader' => array(
@@ -360,28 +355,35 @@ class HomeController extends AbstractAction @@ -360,28 +355,35 @@ class HomeController extends AbstractAction
360 */ 355 */
361 356
362 public function orderAction() { 357 public function orderAction() {
  358 + //获取基本参数:type:1=>全部,2=>待付款,3=>待发货,4=>待收货,5=>待评论
  359 + $type = $this->get('type', 1);
  360 + $page = $this->get('page', 1);
  361 + $limit = $this->get('limit', 10);
  362 + $gender = Helpers::getGenderByCookie();
  363 + $yh_channel = $this->get('yh_channel', 1);
  364 + $uid = $this->getUid();
  365 + $uid = '7566245'; //测试用
  366 + //调用模型层getOrder方法获得并处理数据
  367 + $data = OrderModel::getOrder($type, $page, $limit, $gender, $yh_channel, $uid);
  368 + //渲染模板
  369 + $this->_view->display('order', array(
  370 + 'order' => array(
  371 + 'orders' => $data
  372 + )
  373 + ));
  374 + }
  375 +
  376 + /*
  377 + * 我的订单-处理ajax请求页面(切换订单状态)
  378 + */
  379 +
  380 + public function orderAjaxAction() {
363 381
364 -// do {  
365 -// //判断是不是ajax请求  
366 -// if(!$this -> isAjax()){  
367 -// break;  
368 -// }  
369 - //判断参数是否有效  
370 - $type = $this->get('type', 1);  
371 - $page = $this->get('page', 1);  
372 - $limit = $this->get('limit', 10);  
373 - $gender = Helpers::getGenderByCookie();  
374 - $yh_channel = $this->get('yh_channel', 1);  
375 - //$uid = $this->getUid();  
376 - $uid = '7566245';  
377 - if (!empty($type) && !is_numeric($type)) {  
378 - break;  
379 - }  
380 - //$data = OrderModel::getOrder();  
381 - $data = OrderModel::getOrder($type, $page, $limit, $gender, $yh_channel, $uid);  
382 - print_r($data);  
383 - //} while (false);  
384 - //$this -> _view -> display('order',$data); 382 + //判断是不是ajax请求
  383 + if (!$this->isAjax()) {
  384 + $this->error();
  385 + }
  386 + self::orderAction();
385 } 387 }
386 - 388 +
387 } 389 }
@@ -3,6 +3,8 @@ @@ -3,6 +3,8 @@
3 namespace home; 3 namespace home;
4 4
5 use LibModels\Wap\Home\OrderData; 5 use LibModels\Wap\Home\OrderData;
  6 +use Plugin\Helpers;
  7 +use Configs\CacheConfig;
6 8
7 /* 9 /*
8 * To change this license header, choose License Headers in Project Properties. 10 * To change this license header, choose License Headers in Project Properties.
@@ -21,54 +23,99 @@ class OrderModel @@ -21,54 +23,99 @@ class OrderModel
21 * 订单相关数据处理 23 * 订单相关数据处理
22 */ 24 */
23 public function getOrder($type = 1, $page = 1, $limit, $gender, $yh_channel, $uid) { 25 public function getOrder($type = 1, $page = 1, $limit, $gender, $yh_channel, $uid) {
24 -  
25 - $data = OrderData::getOrderData($type, $page, $limit, $gender, $yh_channel, $uid);  
26 $result = array(); 26 $result = array();
27 - if($data['code'] == 200 && isset($data['data'])){  
28 - foreach($data['data']['order_list'] as $key => $vo){ 27 + if (USE_CACHE) {
  28 + $key = CacheConfig::KEY_ACTION_HOME_ORDER_ORDER;
  29 + // 先尝试获取一级缓存(master), 有数据则直接返回.
  30 + $result = Cache::get($key, 'master');
  31 + if (!empty($result)) {
  32 + return $result;
  33 + }
  34 + }
  35 + //调用接口获得数据
  36 + $data = OrderData::getOrderData($type, $page, $limit, $gender, $yh_channel, $uid);
  37 + //检查数据返回是否正常,正常则处理数据
  38 + if ($data['code'] == 200 && isset($data['data'])) {
  39 + foreach ($data['data']['order_list'] as $key => $vo) {
  40 + //订单号,支付状态,订单商品数量,订单总价格
29 $result[$key]['orderNum'] = $vo['order_code']; 41 $result[$key]['orderNum'] = $vo['order_code'];
30 $result[$key]['tradingStatus'] = $vo['status_str']; 42 $result[$key]['tradingStatus'] = $vo['status_str'];
31 $result[$key]['count'] = count($vo['order_goods']); 43 $result[$key]['count'] = count($vo['order_goods']);
32 $result[$key]['sumCost'] = $vo['amount'] + $vo['shipping_cost']; 44 $result[$key]['sumCost'] = $vo['amount'] + $vo['shipping_cost'];
33 - if($vo['payment_type'] != 2){  
34 - switch ($vo['status']) {  
35 - case 0:  
36 - $result[$key]['unpaid'] = true;  
37 - break;  
38 - case 1 || 2 || 3:  
39 - $result[$key]['unshipped'] = true;  
40 - break;  
41 - case 4 || 5:  
42 - $result[$key]['unreceived'] = true;  
43 - break;  
44 - case 6:  
45 - $result[$key]['completed'] = true;  
46 - break;  
47 - default:  
48 - break; 45 + //订单商品列表数据
  46 + $result[$key]['goods'] = self::formatOrderGoods($vo['order_goods']);
  47 + //订单status判断订单处于什么状态。
  48 + do {
  49 + //订单取消状态
  50 + if ($vo['is_cancel'] === 'Y') {
  51 + $result[$key]['canceled'] = true;
  52 + break;
  53 + }
  54 + //支付方式不是货到付款时,计算订单状态
  55 + if ($vo['payment_type'] != 2) {
  56 + switch ($vo['status']) {
  57 + case 0:
  58 + $result[$key]['unpaid'] = true;
  59 + break;
  60 + case 1 || 2 || 3 || 4 || 5:
  61 + $result[$key]['unreceived'] = true;
  62 + $resault[$key]['logisticsUrl'] = "暂无logisticsUrl数据";
  63 + break;
  64 + case 6:
  65 + $result[$key]['completed'] = true;
  66 + break;
  67 + default:
  68 + break;
  69 + }
  70 + } elseif ($vo['payment_type'] == 2) {
  71 + //订单为货到付款订单时,订单没有未支付状态
  72 + switch ($vo['status']) {
  73 + case 0 || 1 || 2 || 3 || 4 || 5:
  74 + $result[$key]['unreceived'] = true;
  75 + //此处备注,接口没有返回logisticsUrl数据
  76 + $resault[$key]['logisticsUrl'] = "备注:暂无logisticsUrl数据";
  77 + break;
  78 + case 6:
  79 + $result[$key]['completed'] = true;
  80 + break;
  81 + default:
  82 + break;
  83 + }
49 } 84 }
50 - }else{  
51 -// switch ($vo['status']) {  
52 -// case 0:  
53 -// $result[$key]['unpaid'] = true;  
54 -// break;  
55 -// case 1 || 2 || 3:  
56 -// $result[$key]['unshipped'] = true;  
57 -// break;  
58 -// case 4 || 5:  
59 -// $result[$key]['unreceived'] = true;  
60 -// break;  
61 -// case 6:  
62 -// $result[$key]['completed'] = true;  
63 -// break;  
64 -// default:  
65 -// break;  
66 -// } 85 + } while (false);
67 } 86 }
  87 + }
  88 +
  89 + if (USE_CACHE) {
  90 + // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
  91 + if (empty($result)) {
  92 + $result = Cache::get($key, 'slave');
  93 + }
  94 + // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
  95 + else {
  96 + Cache::set($key, $result);
  97 + }
  98 + }
  99 + return $result;
  100 + }
  101 +
  102 + //格式化订单商品
  103 + static function formatOrderGoods($orderGoods) {
  104 + $arr = array();
  105 + foreach ($orderGoods as $key => $vo) {
  106 + $arr[$key]['thumb'] = Helpers::getImageUrl($vo['goods_image'], 90, 120);
  107 + $arr[$key]['name'] = $vo['product_name'];
  108 + $arr[$key]['color'] = $vo['color_name'];
  109 + $arr[$key]['size'] = $vo['size_name'];
  110 + $arr[$key]['price'] = $vo['goods_price'];
  111 + $arr[$key]['count'] = $vo['buy_number'];
  112 + if ($vo['goods_type'] == 'gift') {
  113 + $arr[$key]['gift'] = true;
  114 + } elseif ($vo['goods_type'] == 'price_gift') {
  115 + $arr[$key]['advanceBuy'] = true;
68 } 116 }
69 } 117 }
70 - //return $result;  
71 - return $data; 118 + return $arr;
72 } 119 }
73 120
74 } 121 }