Order.php
9.59 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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<?php
namespace Home;
use LibModels\Wap\Home\OrderData;
use Plugin\Helpers;
/**
* Description of Order
*
*/
class OrderModel
{
const CODE_PAYMENT = '04cf5abaa7c20178325a07c4a833782c'; //支付订单资源码
const CODE_STROLL = 'a7989369aa86681c678bc40f171b8f1d'; //随便逛逛url地址资源码
/**
* 订单相关数据处理
*
* payment_type:
'1' => array(//在线支付
0 => '待付款',
1 => '已付款',
2 => '已付款',
3 => '已付款',
4 => '已发货',
5 => '已发货',
6 => '交易成功'
),
'2' => array(//货到付款
0 => '备货中',
1 => '已付款',
2 => '已付款',
3 => '已付款',
4 => '已发货',
5 => '已发货',
6 => '交易成功'
),
'3' => array(//现金支付
0 => '待付款',
1 => '已付款',
2 => '已付款',
3 => '已付款',
4 => '已发货',
5 => '已发货',
6 => '交易成功'
),
'4' => array(//抵消支付
0 => '待付款',
1 => '已付款',
2 => '已付款',
3 => '已付款',
4 => '已发货',
5 => '已发货',
6 => '交易成功'
)
*/
public static function getOrder($type, $page, $limit, $gender, $yh_channel, $uid)
{
$result = array();
//调用接口获得数据
$data = OrderData::getOrderData($type, $page, $limit, $gender, $yh_channel, $uid);
// 判断是否还有数据, 没有数据则返回空
if (isset($data['data']['page_total']) && $page > $data['data']['page_total']) {
return $result;
}
//检查数据返回是否正常,正常则处理数据
if (!empty($data['data']['order_list'])) {
$count = 0;
foreach ($data['data']['order_list'] as $key => $vo) {
// 订单件数清零
$count = 0;
//根据订单status判断订单处于什么状态。
$result[$key] = self::getOrderStatus($vo);
//订单号,支付状态,订单商品数量,订单总价格
$result[$key]['orderNum'] = $vo['order_code'];
$result[$key]['orderStatus'] = $vo['status_str'];
$result[$key]['sumCost'] = $vo['amount'];
//类内调用格式化订单商品数据方法
$result[$key]['goods'] = Helpers::formatOrderGoods($vo['order_goods'], $count);
$result[$key]['detailUrl'] = Helpers::url('/home/orders/detail', array('order_code' => $vo['order_code'], 't' => time()));
$result[$key]['count'] = $count;
}
}
return $result;
}
/**
* 查看物流
*
* @param int $orderCode 订单编号
* @param int $uid 用户ID
* @return array
*/
public static function Logistics($orderCode, $uid)
{
$result = array();
if (isset($orderCode) && is_numeric($uid)) {
$logistics = OrderData::LogisticsData($orderCode, $uid);
if (!empty($logistics['data'])) {
$result['logisticUrl'] = $logistics['data']['url'];
$result['logisticImg'] = $logistics['data']['logo'];
$result['logisticCompany'] = $logistics['data']['caption'];
$result['logisticNumber'] = $logistics['data']['express_number'];
$build = array();
foreach ($logistics['data']['express_detail'] as $value) {
$build['status'] = $value['accept_address'];
$build['date'] = $value['acceptTime'];
$result['logisticDetail'][] = $build;
}
}
}
return $result;
}
/**
* 获取订单详情信息
*
* @param string $orderCode 订单号
* @param int $uid 用户ID
* @param string $sessionKey 用户的会话
* @return array
*/
public static function orderDetail($orderCode, $uid, $sessionKey)
{
$result = array();
if (is_numeric($orderCode) && is_numeric($uid) && is_string($sessionKey)) {
$orderDetail = OrderData::viewOrderData($orderCode, $uid, $sessionKey);
if (isset($orderDetail['data']['order_code'])) {
$count = 0;
$result = self::getOrderStatus($orderDetail['data'], true); // 订单状态
$result['name'] = $orderDetail['data']['user_name'];
$result['phoneNum'] = $orderDetail['data']['mobile'];
$result['address'] = $orderDetail['data']['area'] . $orderDetail['data']['address'];
$result['orderStatus'] = $orderDetail['data']['status_str'];
$result['orderNum'] = $orderDetail['data']['order_code'];
$result['orderTime'] = date('Y-m-d H:i:s', $orderDetail['data']['create_time']);
$result['goods'] = Helpers::formatOrderGoods($orderDetail['data']['order_goods'], $count, true);
$result['sumPrice'] = $orderDetail['data']['goods_total_amount']; // 商品总金额
$result['salePrice'] = $orderDetail['data']['promotion_amount']; // 活动金额
$result['freight'] = $orderDetail['data']['shipping_cost']; // 运费
$result['coupon'] = $orderDetail['data']['coupons_amount']; // 优惠券
$result['yohoCoin'] = $orderDetail['data']['yoho_coin_num']; // YOHO币
$result['price'] = $orderDetail['data']['amount']; // 实付金额
}
}
return $result;
}
/**
* 根据type值设置nav属性
*/
public static function getNavs($type)
{
$navType = array(1 => '全部', 2 => '待付款', 3 => '待发货', 4 => '待收货');
$nav = array();
foreach ($navType as $key => $value) {
$act = false;
if ($type == $key) {
$act = true;
}
$nav[] = array(
'name' => $value,
'typeId' => $key,
'active' => $act,
'url' => Helpers::url('/home/orders', array('type' => $key))
);
}
return $nav;
}
/**
* 获取订单状态
*
* @param array $order 订单
* @param bool $showLogistics 控制是否显示物流信息
* @return array
*/
private static function getOrderStatus($order, $showLogistics = false)
{
$result = array();
//根据订单status判断订单处于什么状态。
do {
//订单取消状态 = Y 时,跳出判断订单状态循环,并设置订单状态为已取消。
if ($order['is_cancel'] === 'Y') {
$result['canceled'] = true;
break;
}
// 先判断订单付款方式,根据不同的付款方式计算订单状态。(注:货到付款没有待付款状态)
// 支付方式为非货到付款时,计算订单状态。
if ($order['payment_type'] != 2) {
switch ($order['status']) {
case 0: // 待付款
$result['unpaid'] = true;
$result['payUrl'] = Helpers::url('/home/pay', array('order_code' => $order['order_code']));
break;
//未发货&未收货 状态,统一合并到待收货状态。
case 1:
case 2:
case 3:
//已付款状态不给查看物流URL
$result['unreceived'] = true;
break;
case 4:
case 5:
//已发货状态,给查看物流URL
$result['unreceived'] = true;
$result['logisticsUrl'] = Helpers::url('/home/logistic', array('order_code' => $order['order_code']));
if ($showLogistics) {
$result['logisticsCompany'] = $order['caption'];
$result['logisticsNum'] = $order['express_number'];
}
break;
case 6:
$result['completed'] = true;
break;
default:
break;
}
break;
}
// 订单为货到付款订单时,计算订单状态。(货到付款没有待付款状态)
switch ($order['status']) {
case 0: // 备货中
$result['unpaid'] = true;
break;
case 1:
case 2:
case 3:
//备货中、已付款状态不给查看物流链接
$result['unreceived'] = true;
break;
case 4:
case 5:
//待收货状态,给查看物流url
$result['unreceived'] = true;
$result['logisticsUrl'] = Helpers::url('/home/logistic', array('order_code' => $order['order_code']));
if ($showLogistics) {
$result['logisticsCompany'] = isset($order['caption']) ? $order['caption'] : '';
$result['logisticsNum'] = isset($order['express_number']) ? $order['express_number'] : '';
}
break;
case 6:
$result['completed'] = true;
break;
default:
break;
}
} while (false);
return $result;
}
}