Order.php
7.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<?php
namespace Home;
use LibModels\Wap\Home\OrderData;
use Plugin\Helpers;
use Plugin\Cache;
use Configs\CacheConfig;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of Order
*
*/
class OrderModel
{
/* 频道选择页取背景图片的位置码 */
const CODE_PAYMENT = '04cf5abaa7c20178325a07c4a833782c'; //支付订单资源码
const CODE_STROLL = 'a7989369aa86681c678bc40f171b8f1d'; //随便逛逛url地址资源码
/**
* 订单相关数据处理
*/
static function getOrder($type, $page, $limit, $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, $uid);
//检查数据返回是否正常,正常则处理数据
if (!empty($data[0])) {
$result = array();
foreach ($data as $key => $vo) {
if (empty($vo['ordersGoodsList'])) {
break;
}
$result[$key]['goods'] = self::formatOrderGoods($vo['ordersGoodsList']);
$result[$key]['detailUrl'] = '???';
$result[$key]['orderNum'] = $vo['orderCode'];
$result[$key]['count'] = count($vo['ordersGoodsList']);
$result[$key]['sumCost'] = $vo['goodsTotalAmount'];
do {
if ($vo['isCancel'] === 'Y') {
$result[$key]['canceled'] = true;
$result[$key]['orderStatus'] = '已取消';
break;
}
switch ($vo['status']) {
case 0:
$result[$key]['unpaid'] = true;
$result[$key]['orderStatus'] = '未付款';
break;
//未发货&未收货 状态,统一合并到待收货状态。
case 1:
$result[$key]['orderStatus'] = '已付款';
$result[$key]['unreceived'] = true;
break;
case 2:
$result[$key]['orderStatus'] = '备货中';
$result[$key]['unreceived'] = true;
break;
case 3:
$result[$key]['orderStatus'] = '配货中';
$result[$key]['unreceived'] = true;
break;
case 4:
$result[$key]['orderStatus'] = '已发货';
$result[$key]['logisticsUrl'] = "暂无logisticsUrl数据";
$result[$key]['unreceived'] = true;
break;
case 5:
$result[$key]['orderStatus'] = '运输中';
$result[$key]['logisticsUrl'] = "暂无logisticsUrl数据";
$result[$key]['unreceived'] = true;
break;
case 6:
$result[$key]['orderStatus'] = '交易成功';
$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($ordersGoodsList) {
$arr = array();
foreach ($ordersGoodsList as $key => $vo) {
$arr[$key]['thumb'] = Helpers::getImageUrl($vo['goodsImg'][0]['imageUrl'], 90, 120);
$arr[$key]['name'] = $vo['productName'];
$arr[$key]['color'] = $vo['colorName'];
$arr[$key]['size'] = $vo['sizeName'];
$arr[$key]['price'] = $vo['goodsPrice'];
$arr[$key]['count'] = $vo['num'];
//gift=>是否赠品,advanceBuy=>是否加价购;
switch ($vo['goodsType']) {
case 1://普通商品
break;
case 2://商品的赠品
$arr[$key]['gift'] = true;
break;
case 3://订单的赠品
$arr[$key]['gift'] = true;
break;
case 4://商品满足条件加钱送
$arr[$key]['advanceBuy'] = true;
break;
case 5://订单满足条件价钱送
$arr[$key]['advanceBuy'] = true;
break;
default:
break;
}
}
return $arr;
}
//根据type值设置nav属性
static function getNavs($type) {
$nav = array(
array(
'name' => '全部',
'typeId' => '1',
'url' => '/home/order?type=1'
),
array(
'name' => '待付款',
'typeId' => '2',
'url' => '/home/order?type=2'
),
array(
'name' => '待发货',
'typeId' => '3',
'url' => '/home/order?type=3'
),
array(
'name' => '待收货',
'typeId' => '4',
'url' => '/home/order?type=4'
)
);
foreach ($nav as $key => $vo) {
switch ($type) {
case 1:
if ($vo['typeId'] == 1) {
$nav[$key]['active'] = true;
}
break;
case 2:
if ($vo['typeId'] == 2) {
$nav[$key]['active'] = true;
}
break;
case 3:
if ($vo['typeId'] == 3) {
$nav[$key]['active'] = true;
}
break;
case 4:
if ($vo['typeId'] == 4) {
$nav[$key]['active'] = true;
}
break;
default:
break;
}
}
return $nav;
}
//获得支付链接
static function payment($gender, $yh_channel) {
$code = self::CODE_PAYMENT;
$data = OrderData::paymentData($gender, $yh_channel, $code);
}
//查看物流
// static function Logistics(){
// OrderData::LogisticsData();
// }
//随便逛逛url获取
static function stroll($gender, $yh_channel) {
//获取随便逛逛url资源码
$code = self::CODE_STROLL;
//调用接口获得数据
$data = OrderData::strollData($gender, $yh_channel, $code);
//检查数据返回是否正常,正常则处理数据
if ($data['code'] == 200) {
$strollUrl = $data['data'][0]['data'][0]['url'];
}
return $strollUrl;
}
}