RefundapplyController.php
13.1 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
<?php
class Home_RefundapplyController extends QLib_Controller_Home_Action
{
public function init()
{
$this->QLayoutTitle()->headTitle('退货申请');
$this->view->uid = $this->uid = $this->helpIsLogin();
}
public function indexAction()
{
}
/**
* 去换货页面
*/
public function barterAction()
{
$this->QLayoutScript()
->offsetSetFile(30, $this->_js('user_main'))
->offsetSetFile(31, $this->_js('global'))
->offsetSetFile(32, $this->_js('formValidator'))
->offsetSetFile(33, $this->_js('formValidatorRegex'))
->offsetSetFile(34, $this->_js('refundapply'));
$this->QLayoutLink()->appendStylesheet($this->_css('formValidator'));
$productId = intval($this->helpGquery('product_id'));
$productId < 1 ? $this->helpJsRedirect('产品的ID不能为空!') : TRUE;
$order_code = $this->helpGquery('order_code');
$order_code < 1 ? $this->helpJsRedirect('订单编码不能为空!') : TRUE;
$this->view->order = $order = QModels_Orders_Client::getOrderByCode($order_code, $this->uid);
empty($order) ? $this->helpJsRedirect('很抱歉!您要换货的订单不存在') : TRUE;
($order['exchange'] == false) ? $this->helpJsRedirect('退换货商品在订单完成15天内才可以提交换货申请!') : TRUE;
$goods_id = intval($this->helpGquery('goods_id'));
$goods_id < 1 ? $this->helpJsRedirect('商品的ID不能为空!') : TRUE;
$num = intval($this->helpGquery('num'));
$num < 1 ? $this->helpJsRedirect('您的操作有误') : TRUE;
$this->view->num = $num;
$this->view->good = $good = QModels_Orders_Goods_Client::getOneGoodsById($this->uid, $goods_id, $order['id']);
$this->view->product = $product = QModels_Product_Client::getProductFullInfo($productId);
$this->view->storage = $storage = QModels_Product_Client::getStorage($productId);
empty($storage['goods']) || $storage['storage'] == 0 ? $this->helpJsRedirect('没有库存,您可以进行退货或者联系客服') : TRUE;
$this->view->size = $size = QINProduct_Models_Size_Client::getAllSizes();
}
/**
* 换货申请
*/
public function exchangeAction()
{
$orderCode = $this->helpGpost('orderCode');
empty($orderCode) ? $this->helpJsRedirect('您没有选着换的商品') : TRUE;
$goods = $this->helpGpost('goods');
empty($goods) ? $this->helpJsRedirect('您没有选着换的商品') : TRUE;
$size = $this->helpGpost('size');
empty($size) ? $this->helpJsRedirect('您没有选中商品的尺码') : TRUE;
$num = $this->helpGpost('num');
empty($num) ? $this->helpJsRedirect('您没有选中商品数量') : TRUE;
$oldnum = intval($this->helpGpost('oldnum'));
$oldnum < 1 ? $this->helpJsRedirect('您的操作有误') : TRUE;
$goods_id = intval($this->helpGpost('goods_id'));
$goods_id < 1 ? $this->helpJsRedirect('您的选着要换的商品有误') : TRUE;
$erp_sku_id = intval($this->helpGpost('erp_sku_id'));
$erp_sku_id < 1 ? $this->helpJsRedirect('您的选着要换的商品有误') : TRUE;
$orderId = intval($this->helpGpost('orderId'));
$orderId < 1 ? $this->helpJsRedirect('订单ID不能为空!') : TRUE;
$last_price = intval($this->helpGpost('last_price'));
$last_price < 1 ? $this->helpJsRedirect('您的操作有误') : TRUE;
$size_id = intval($this->helpGpost('size_id'));
$size_id < 1 ? $this->helpJsRedirect('您的操作有误') : TRUE;
$remark = $this->helpGpost('question');
empty($remark) ? $this->helpJsRedirect("问题描述不能为空!") : TRUE;
$sales_prices = $this->helpGpost('sales_prices');
$last_price = $this->helpGpost('last_price');
//判断商品数量
$countnum = 0;
foreach ($goods as $k=>$v)
{
$countnum += $num[$v];
}
$countnum > $oldnum ? $this->helpJsRedirect('您要换的商品数量不够,请重新输入!') : TRUE;
//创建数组
$exchangeList = array();
foreach ($goods as $k => $v)
{
$size[$v] < 1 ? $this->helpJsRedirect('您没有选中商品的尺码!') : TRUE;
$erp_sku = QModels_Product_Storage_Client::getOneStorage($v, $size[$v]);
$exchangeList[$k]['erp_sku_id'] = $erp_sku['erp_sku_id'];
$exchangeList[$k]['num'] = $num[$v];
}
//获得订单编码
$Order = QModels_Orders_OrdersNum_Client::getOrderCode();
$newOrderCode = $Order['order_code'];
//地址信息
$addrInfo = $this->GetParamers();
//调用接口
$erpOrder = QErp_Order_Factory::factory();
$result = $erpOrder->exchangeGoods($orderCode, $erp_sku_id, $num, $sales_prices, $last_price, $exchangeList, $newOrderCode, $addrInfo, $remark);
if(QErp_Config::$connectionFailCode != $result['code']){
$result['code'] != 200 ? $this->helpJsRedirect('很抱歉!您的商品不能换货,请与客服联系。电话:400-889-9646!') : TRUE;
}
//退商品
$goods_info = QModels_Orders_Goods_Client::getOneGoodsById($this->uid, $goods_id, $orderId);
//组织要退商品的数组
$good = array(
array(
'order_goods_id' => $goods_info['id'],
'erp_sku_id' => $goods_info['erp_sku_id'],
'num' => $countnum
)
);
//退商品
$status = QModels_Orders_Returned_Client::setReturnedGoods($orderId, $good);
$oldorder = QModels_Orders_Client::getOne($orderId);
//组织订单信息
$parameter = array(
'order_code' => $result['orderCode'],
'order_type' => 3,
'shipping_type_id' => $oldorder['shipping_type_id'],
'user_name' => $addrInfo['addressee_name'],
'mobile' => $addrInfo['mobile'],
'phone' => $addrInfo['phone'],
'area_code' => $addrInfo['area_code'],
'zip_code' => $addrInfo['zip_code'],
'amount' => '0.00',
'uid' => $this->uid,
'is_invoice' => $oldorder['is_invoice'],
'invoices_type' => $oldorder['invoices_type'],
'invoices_payable' => $oldorder['invoices_payable'],
'yoho_coin_num' => $oldorder['yoho_coin_num'],
'payment_type' => $oldorder['payment_type'],
'payment_status' => $oldorder['payment_status'],
'remark' => $oldorder['remark'],
'shipping_cost' => $oldorder['shipping_cost'],
'express_id' => $oldorder['express_id'],
'receipt_time' => $oldorder['receipt_time'],
'is_print_price' => $oldorder['is_print_price'],
'yoho_give_coin' => 0
);
//组织订单商品信息
$newgoods = array();
foreach ($goods as $k => $v)
{
$goodinfo = QModels_Goods_Client::getOneById($v);
$erp_sku = QModels_Product_Storage_Client::getOneStorage($v, $size[$v]);
$size_info = QModels_Product_Size_Client::getOneSize($size[$v]);
$newgoods[$k]['size_name'] = $size_info['size_name'];
$product_price = QModels_Product_Price_Client::getPrice($goodinfo['product_id']);
$product = QModels_Product_Client::getOneProduct($goodinfo['product_id']);
$newgoods[$k]['erp_sku_id'] = $erp_sku_id;
$newgoods[$k]['num'] = $num[$v];
$newgoods[$k]['size_id'] = $size_info['id'];
$newgoods[$k]['goods_price'] = $product_price['market_price'];
$newgoods[$k]['goods_amount'] = $product_price['sales_price'];
$newgoods[$k]['goods_id'] = $goodinfo['id'];
$newgoods[$k]['brand_id'] = $product['brand_id'];
$newgoods[$k]['product_id'] = $goodinfo['product_id'];
$newgoods[$k]['goods_type'] = 1;
$newgoods[$k]['color_id'] = $goodinfo['color_id'];
$newgoods[$k]['color_name'] = $goodinfo['color_name'];
}
$newOrderId = QModels_Orders_Client::setOrder($parameter, $newgoods);
$newOrderId < 1 ? $this->helpJsRedirect('您创建新的订单有误,请与客服联系。电话:400-889-9646!') : TRUE;
//添加换商品组织换商品的数据
$exchangeGoods = array();
foreach ($goods as $k => $v)
{
$exchangeGoods[$k]['order_goods_id'] = $v;
$erp_sku = QModels_Product_Storage_Client::getOneStorage($v, $size[$v]);
$exchangeGoods[$k]['erp_sku_id'] = $erp_sku['erp_sku_id'];
$exchangeGoods[$k]['num'] = $v['num'];
}
$status = QModels_Orders_Returned_Client::setReturnedGoods($orderId, $exchangeGoods, 2,$newOrderId);
$status == TRUE ? TRUE : $this->helpJsRedirect('添加换货商品有误,请与客服联系。电话:400-889-9646!');
//更新换货状态
$status = QModels_Orders_Client::updateExchangeStatus($orderId, $this->uid, 1);
$status == TRUE ? $this->helpRefresh('/home/orders','您的换货申请成功!') : $this->helpJsRedirect('修改订单状态失败!');
}
/**
* 得到地址信息
*/
public function GetParamers()
{
$parameter['addressee_name'] = QLib_Utils_String::String()->pregReplaceHtml($this->helpGpost('addressee_name'));
empty($parameter['addressee_name']) ? $this->helpJsRedirect('收货人姓名不能为空') : TRUE;
$parameter['address'] = QLib_Utils_String::String()->pregReplaceHtml($this->helpGpost('address'));
empty($parameter['address']) ? $this->helpJsRedirect('收货地址不能为空') : TRUE;
$parameter['area_code'] = $this->helpGpost('area_code');
$parameter['zip_code'] = QLib_Utils_String::String()->pregReplaceHtml($this->helpGpost('zip_code'));
empty($parameter['zip_code']) ? $this->helpJsRedirect('邮编不能为空') : TRUE;
$parameter['mobile'] = QLib_Utils_String::String()->pregReplaceHtml($this->helpGpost('mobile'));
$parameter['phone'] = QLib_Utils_String::String()->pregReplaceHtml($this->helpGpost('phone'));
(empty($parameter['mobile']) && empty($parameter['phone'])) ? $this->helpJsRedirect('固话和手机号至少填一项') : TRUE;
return $parameter;
}
/**
* 退货
* Enter description here ...
*/
public function refundAction()
{
$this->QLayoutScript()->offsetSetFile(30, $this->_js('refundapply'))->appendFile($this->_js('global'));
$order_code = intval($this->helpGquery('order_code'));
$order_code < 1 ? $this->helpJsRedirect('您的操作有误') : TRUE;
$this->view->order = $order = QModels_Orders_Client::getOrderByCode($order_code, $this->uid);
empty($order) ? $this->helpJsRedirect('很抱歉!您要退货的订单不存在') : TRUE;
$order['refund'] == false ? $this->helpJsRedirect('退换货商品在订单完成七天内才可以提交退货申请!') : TRUE;
$this->view->promotion = $promotion = QModels_Orders_Promotion_Client::getAllPromotionByOrder($order['id']);
$markey = 0;
foreach ($promotion as $k => $v){
$promotions = QModels_Promotion_Commodity_Client::getOneById($v['promotion_id']);
if ($promotions['favorable_type_id'] != 6){
$markey += 1;
break;
}
}
$good = array();
if ($markey < 1){
$good = QModels_Orders_Goods_Client::getOrderGoods($order['id'], $order_code);
}
$this->view->good = $good;
}
/**
* 提交退货申请
* Enter description here ...
*/
public function refundgoodsAction(){
$oldgood = $this->helpGpost('good');
$goods_ids = $this->helpGpost('goods_ids');
empty($goods_ids) && empty($oldgood) ? $this->helpJsRedirect('请选择要退货的商品') : TRUE;
$last_prices = $this->helpGpost('last_price');
empty($last_prices) && empty($oldgood) ? $this->helpJsRedirect('请选择要退货的商品') : TRUE;
$order_code = $this->helpGpost('order_code');
$nums = $this->helpGpost('num');
empty($nums) && empty($oldgood) ? $this->helpJsRedirect('请选择要退货的商品') : TRUE;
$this->view->order = $order = QModels_Orders_Client::getOrderByCode($order_code, $this->uid);
empty($order) ? $this->helpJsRedirect('很抱歉!该订单不存在,无法进行退货。') : TRUE;
if (!empty($oldgood)){
$good = QModels_Orders_Goods_Client::getOrderGoods($order['id'], $order_code);
}else{
$good =array();
foreach ($goods_ids as $k => $v){
$good[$k] = QModels_Orders_Goods_Client::getOneGoodsById($this->uid, $v, $order['id']);
}
}
$refundList =array();
foreach ($good as $k => $v){
$product_price = QModels_Product_Price_Client::getPrice($v['product_id']);
$refundList[$k]['sales_price'] = $product_price['sales_price'];
!empty($oldgood) ? $last_price = $v['goods_amount'] : $last_price = $last_prices[$v['goods_id']];
$refundList[$k]['last_price'] = $last_price;
$refundList[$k]['erp_sku_id'] = $v['erp_sku_id'];
!empty($oldgood) ? $num = $v['num'] : $num = $nums[$v['goods_id']];
$refundList[$k]['num'] = $num;
}
//调用接口
$erpOrder = QErp_Order_Factory::factory();
$result = $erpOrder->refundGoods($order['order_code'], $refundList);
(QErp_Config::$connectionFailCode == $result['code']) ? $this->helpJsRedirect('很抱歉!您的退货申请失败。请与客服联系。电话:400-889-9646.') : true;
$result['code'] != 200 ? $this->helpJsRedirect('很抱歉!您的订单为促销商品,请与客服联系。电话:400-889-9646!') : TRUE;
//添加退货商品
$exchangeGoods = array();
foreach ($good as $k=>$v)
{
$exchangeGoods[$k]['order_goods_id'] = $v['goods_id'];
$erp_sku = QModels_Product_Storage_Client::getOneStorage($v['goods_id'], $v['size_id']);
$exchangeGoods[$k]['erp_sku_id'] = $v['erp_sku_id'];
!empty($oldgood) ? $num = $v['num'] : $num = $nums[$v['goods_id']];
$exchangeGoods[$k]['num'] = $num;
}
$status = QModels_Orders_Returned_Client::setReturnedGoods($order['id'], $exchangeGoods);
$status == TRUE ? TRUE : $this->helpJsRedirect('您的退货申请失败!');
$status = QModels_Orders_Client::updateRefundStatus($order['id'], $this->uid, 1);
$status == TRUE ? $this->helpRefresh('/home/orders','您的退货申请成功!') : $this->helpJsRedirect('您的退货申请失败!');
}
}