Orders.php
12.7 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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
<?php
use Action\WebAction;
use WebPlugin\Helpers;
use Home\UserModel;
use Home\OrderModel;
use LibModels\Web\Home\OrderData;
use Configs\ChannelConfig;
use WebPlugin\Paging;
use Shopping\CartModel;
/**
* 订单
*/
class OrdersController extends WebAction
{
/**
* 我的订单
*/
public function indexAction()
{
//判断是否登录
$uid = $this->auditJumpLogin(false, Helpers::url('/home/orders'));
//头部导航
$channel = Helpers::getChannelNameByCookie();
$this->setWebNavHeader($channel);
//面包屑-左侧导航
$path = UserModel::getCenterCrumb('订单中心');
$leftNav = UserModel::getCenterLeftNav('我的订单', $uid);
//分页
$page = $this->get('page', 1);
$type = $this->get('type', 1);
$limit = 10;
$paging = new Paging('yoho');
//订单 type-8-历史
if ($type == ChannelConfig::$historyType) {
$orders = OrderModel::getHistoryOrders($uid, $page, $limit);
}
else {
$orders = OrderModel::getOrders($uid, $page, $limit, $type, TRUE);
}
$total = isset($orders['pager']['total']) ? $orders['pager']['total'] : 0;
$pageTotal = isset($orders['pager']['pageTotal']) ? $orders['pager']['pageTotal'] : 0;
$page = isset($orders['pager']['page']) ? $orders['pager']['page'] : 0;
unset($orders['pager']);
$paging->setTotal($total)->setSize($limit)->setQuery(array('page' => $page, 'type' => $type));
//取消订单原因列表
$resons = OrderData::closeReasons();
$cancelReason = isset($resons['data']) ? $resons['data'] : '';
//数据整合
$data = array(
'path' => $path,
'userThumb' => UserModel::getUserHeadImg($uid),
'homeNav' => $leftNav,
'tabs' => OrderModel::getOrderTabs($type),
'cancelReason' => $cancelReason,
'pager' => array(
'count' => $total,
'curPage' => $page,
'totalPages' => $pageTotal,
'pagerHtml' => $paging->view(false)
)
);
//历史订单/普通订单
$orderKey = ($type == ChannelConfig::$historyType) ? 'historyOrders' : 'orders';
$data[$orderKey] = $orders;
$this->_view->display('orders', array('meOrdersPage' => true, 'meOrders' => $data));
}
/**
* 订单详情
*/
public function detailAction()
{
//判断是否登录
$uid = $this->auditJumpLogin();
//头部导航
$channel = Helpers::getChannelNameByCookie();
$this->setWebNavHeader($channel);
//面包屑-左侧导航
$path = UserModel::getCenterCrumb('订单详细', array('href' => Helpers::url('/home/orders'), 'name' => '订单中心'));
$leftNav = UserModel::getCenterLeftNav('我的订单', $uid);
$orderCode = $this->get('orderCode', '');
//兼容老网站传参方式
if (!$orderCode) {
$orderCode = $this->get('order_code', '');
}
$detail = OrderModel::getOrderDetail($uid, $orderCode);
//取消订单原因列表
$resons = OrderData::closeReasons();
$cancelReason = isset($resons['data']) ? $resons['data'] : '';
//非当前用户的订单,跳转个首
if (isset($detail['code']) && $detail['code'] == 400) {
$this->go(Helpers::url('/home'));
}
$data = array(
'path' => $path,
'userThumb' => UserModel::getUserHeadImg($uid),
'homeNav' => $leftNav
);
$packages = false;
if ($detail) {
$data += array(
'orderNum' => $detail['orderNum'],
'curStatus' => $detail['statusStr'],
'complete' => $detail['complete'],
'changeable' => $detail['changeable'],
'progress' => $detail['progress'],
'remark' => $detail['remark'],
'goods' => $detail['goods'],
'yohoCoinUrl' => $detail['yohoCoinUrl'],
'orderBalance' => isset($detail['orderBalance']) ? $detail['orderBalance'] : array(),
'operation' => $detail['operation'],
'totalYoho' => $detail['yoho_give_coin'],
'editInfo' => $detail['editInfo'],
//发票信息
'invoiceMode' => isset($detail['invoiceMode']) ? $detail['invoiceMode'] : false,
'invoiceType' => isset($detail['invoiceType']) && $detail['invoiceType'] === 2 ? '电子发票' : '纸质发票',
'pdfUrl' => isset($detail['showInvoice']) && isset($detail['pdfUrl']) && $detail['pdfUrl'] ? $detail['pdfUrl'] : '',
'title' => isset($detail['title']) ? $detail['title'] : '',
'contentValue' => isset($detail['contentValue']) ? $detail['contentValue'] : '个人',
);
if (isset($detail['noramlPayMode'])) {
$data['orderInfo'] = $detail['orderInfo'];
$data['traceOrder'] = $detail['traceOrder'];
$data['hastrace'] = $detail['hastrace'];
$data['noramlPayMode'] = $detail['noramlPayMode'];
}
else if (isset($detail['virtualPayMode'])) {
$data['virtualGoods'] = $detail['virtualGoods'];
$data['virtualPayMode'] = $detail['virtualPayMode'];
}
//JIT拆单
$packages = $detail['packages'];
}
$this->_view->display('order-detail', array('meOrdersPage' => true, 'meOrderDetail' => $data, 'packages' => $packages, 'cancelReason' => $cancelReason));
}
/**
* 二维码票
*/
public function ticketsAction()
{
//判断是否登录
$uid = $this->auditJumpLogin();
//头部导航
$channel = Helpers::getChannelNameByCookie();
$this->setWebNavHeader($channel);
//面包屑-左侧导航
$path = UserModel::getCenterCrumb('查看二维码', array('href' => Helpers::url('/home/orders'), 'name' => '订单中心'));
$leftNav = UserModel::getCenterLeftNav('我的订单', $uid);
$orderCode = $this->get('orderCode', '');
//兼容老网站传参方式
if (!$orderCode) {
$orderCode = $this->get('order_code', '');
}
$detail = OrderModel::getOrderDetail($uid, $orderCode);
//非当前用户的订单,跳转个首
if (isset($detail['code']) && $detail['code'] == 400) {
$this->go(Helpers::url('/home'));
}
if (isset($detail) && $detail) {
$tickets = OrderModel::getTicketsInfo($orderCode, $uid);
$data = array(
'path' => $path,
'userThumb' => UserModel::getUserHeadImg($uid),
'homeNav' => $leftNav,
'name' => $detail['goods'][0]['name'],
'num' => $detail['goods'][0]['num'],
'orderNum' => $detail['orderNum'],
'myOrdersUrl' => Helpers::url('/home/orders'),
'tickets' => $tickets
);
}
$this->_view->display('ticket', array('meOrderTicket' => $data));
}
/**
* 取消订单-ajax
*/
public function cancelOrderAction()
{
$data = array('code' => 400, 'message' => '', 'data' => '');
do {
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
break;
}
$uid = $this->auditJumpLogin();
$orderCode = trim($this->post('orderCode', '')); //订单编号
$reason = $this->post('reason', ''); //取消订单原因
$reasonid = $this->post('reasonId', ''); //取消原因id
$data = OrderData::cancelUserOrder($uid, $orderCode, $reason, $reasonid);
if (!isset($data['code'])) {
break;
}
}
while (false);
$this->echoJson($data);
}
/**
* 确认订单-ajax
*/
public function confirmOrderAction()
{
$data = array('code' => 400, 'message' => '', 'data' => '');
do {
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
break;
}
$uid = $this->auditJumpLogin();
$orderCode = trim($this->post('orderCode', ''));
$data = OrderData::confirmUserOrder($uid, $orderCode);
if (!isset($data['code'])) {
break;
}
}
while (false);
$this->echoJson($data);
}
/**
* 订单详情页地址修改
*/
public function modifyAddressAction()
{
$result = array('code' => 400, 'message' => '', 'data' => '');
do {
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
break;
}
// 获取相关参数
$order_code = $this->post('orderCode', ''); //订单号
$user_name = $this->post('userName', ''); //收货人
$area_code = $this->post('areaCode', ''); //区号
$address = $this->post('address', ''); //地址
$mobile = $this->post('mobile', ''); //手机号码
$phoneNum = $this->post('phoneNum', ''); //固定电话
$phoneCode = $this->post('phoneCode', ''); //电话编号
if(!empty($phoneNum)){
$phone = $phoneCode.'-'.$phoneNum;
}
if (!$order_code || !$user_name || !$area_code || !$address) {
$result = array('code' => 400, 'message' => '缺失必填项', 'data' => '');
break;
}
$uid = $this->getUid();
$result = OrderData::updateDeliveryAddress($order_code, $user_name, $area_code, $address, $mobile, $phone, $uid);
if (!isset($result['code'])) {
break;
}
}
while (false);
$this->echoJson($result);
}
/**
* 我的订单——再次购买
*/
public function reAddAction()
{
$result = array('code' => 401, 'message' => '商品加入购物车失败', 'data' => '');
do {
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
break;
}
//获取相关参数
$uid = $this->getUid(true);
$orderCode = $this->post('orderCode', '');
if (!$uid || !$orderCode) {
$result = array('code' => 400, 'message' => '缺失参数', 'data' => '');
break;
}
$reAddData = OrderData::reAddData($uid, $orderCode);
if(!isset($reAddData['code']) || $reAddData['code'] != 200){
break;
}
$result = array('code' => 200, 'message' => '商品已重新加入购物车', 'data' => $reAddData['data']);
if (!isset($result['code'])) {
break;
}
}
while (false);
$this->echoJson($result);
}
/**
* 还原订单
*/
public function restoreOrderAction()
{
$data = array('code' => 400, 'message' => '', 'data' => '');
do {
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
break;
}
$uid = $this->auditJumpLogin();
$orderCode = trim($this->post('orderCode', ''));
// $data = OrderData::confirmUserOrder($uid, $orderCode);
$data = array('code' => 400, 'message' => '订单还原成功', 'data' => '');
if (!isset($data['code'])) {
break;
}
}
while (false);
$this->echoJson($data);
}
/*
* 我的订单-删除订单
*/
public function delOrderAction()
{
$result = array('code' => 400, 'message' => '删除失败', 'data' => '');
do {
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
break;
}
//传入orderCode删除订单
$orderCode = $this->post('orderCode','');
$gender = Helpers::getGenderByCookie();
$channel = Helpers::getChannelByCookie();
$uid = $this->getUid(true);
if (!$orderCode || !$uid) {
$result = array('code' => 400, 'message' => '缺失必填项', 'data' => '');
break;
}
//调用接口删除订单,并返回订单删除状态
$result = OrderData::deleteOrderData($orderCode, $uid, $gender, $channel);
if (!isset($result['code'])) {
break;
}
}
while (false);
$this->echoJson($result);
}
}