Refund.php
7.36 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
<?php
/**
*
* @author tongdesheng
*
*/
class YHMApi_App_V1_Refund extends YHMApi_Common {
/**
* 申请退款
* @param array $params
* @param string $fields
*/
public static function req(array $params, $fields = "*") {
if (empty($params['uid'])) {
return self::result(400, 'uid不能为空');
}
if (empty($params['order_code'])) {
return self::result(400, '订单号不能为空');
}
if (empty($params['refund_amount'])) {
return self::result(400, '申请退款金额不能为空');
}
$receive_uid = $params['uid']; //申请人
$order_code = $params['order_code']; //订单号
$refund_amount = $params['refund_amount']; //申请金额
//检测是否已经申请
$orders_status = YHMOrders_Models_Refund_Client::getByOrdercode($order_code);
//如果卖家已拒绝退款,可再申请,并返回最新的申请记录
if ($orders_status['refund_status'] == YHMConfig_Orderstatus::REFUND_BUYER_REQ) {
return self::result(500, '您已经申请过了,请等待卖家回复');
}
//订单信息
$order_info = YHMOrders_Models_Orders_Client::getOrdersInfoByOrderCode($order_code);
$refund_uid = $order_info['seller_uid']; //退款人
if ($orders_status['refund_status'] == YHMConfig_Orderstatus::REFUND_SELLER_CONFIRM) {
return self::result(500, '卖家已经同意退款');
}
$id = YHMOrders_Models_Refund_Client::setRefund($refund_uid, $receive_uid, $order_code, YHMConfig_Orderstatus::REFUND_BUYER_REQ, $refund_amount);
if ($id < 1) {
return self::result(500, '申请失败');
}
//订单信息
$order_goods_info = YHMOrders_Models_Orders_Client::getGoodsInfoByOrderCode($params['order_code']);
$order_goods = current($order_goods_info);
// $goods_info = YHMProduct_Models_Goods_Client::getOneByProductSkc($order_goods['product_skc']);
$goods_image =$order_goods['goods_images'];// YHMProduct_Models_Goodsimages_Client::getDefaultImageBySkc($order_goods['product_skc']);
//发送系统消息
$message = new YHMIm_MessagesParam_YHMOrderStatus;
$message->text = '您有一笔订单被申请退款';
$message->seller_uid = $order_info['seller_uid'];
$message->product_skc = $order_goods['product_skc'];
$message->product_name = $order_goods['goods_name'];
$message->image_url = YHMUpload_Images::template($goods_image, 'yhfair-product');
$message->sale_price = (int) $order_goods['last_price'];
$message->stock_number = $order_goods['buy_number'];
$message->size_name = !empty($order_goods['size_name']) ? $order_goods['size_name'] : '-';
$message->order_code = $params['order_code'];
$send = YHMIm_Client::yhmOrderStatus(0, $order_info['seller_uid'], $message);
//插入订单历史
YHMOrders_Models_Status_Client::setOrderstatus($order_code, YHMConfig_Orderstatus::REFUND_BUYER_REQ, $receive_uid);
return self::result(200, '申请成功', $id);
}
/**
* 买家取消申请退款
* @param array $params
* @param string $fields
*/
public static function cancel(array $params, $fields = "*") {
if (empty($params['uid'])) {
return self::result(400, 'uid不能为空');
}
if (empty($params['order_code'])) {
return self::result(400, '订单号不能为空');
}
$order_code = $params['order_code'];
//查看当前退款状态
$orders_status = YHMOrders_Models_Refund_Client::getByOrdercode($order_code);
if (empty($orders_status)) {
return self::result(400, '暂无退款申请');
}
if ($orders_status['refund_status'] == YHMConfig_Orderstatus::REFUND_BUYER_CANCEL) {
return self::result(500, '您已经取消退款');
}
if ($orders_status['refund_status'] == YHMConfig_Orderstatus::REFUND_SELLER_REJECT) {
return self::result(500, '卖家已经拒绝退款');
}
if ($orders_status['refund_status'] == YHMConfig_Orderstatus::REFUND_SELLER_CONFIRM) {
return self::result(500, '卖家已经同意退款');
}
//修改退货状态
YHMOrders_Models_Refund_Client::updateStatus($order_code, YHMConfig_Orderstatus::REFUND_BUYER_CANCEL);
//插入历史
YHMOrders_Models_Status_Client::setOrderstatus($order_code, YHMConfig_Orderstatus::REFUND_BUYER_CANCEL, $params['uid']);
return self::result(200, '取消申请退款成功');
}
/**
* 拒绝退款申请
* @param array $params
* @param string $fields
*/
public static function reject(array $params, $fields = "*") {
if (empty($params['uid'])) {
return self::result(400, 'uid不能为空');
}
if (empty($params['order_code'])) {
return self::result(400, '订单号不能为空');
}
$order_code = $params['order_code'];
$orders_status = YHMOrders_Models_Refund_Client::getByOrdercode($order_code);
if (empty($orders_status)) {
return self::result(400, '暂无退款申请');
}
if ($orders_status['refund_status'] == YHMConfig_Orderstatus::REFUND_BUYER_CANCEL) {
return self::result(500, '卖家已经取消退款!');
}
if ($orders_status['refund_status'] == YHMConfig_Orderstatus::REFUND_SELLER_REJECT) {
return self::result(500, '您已经拒绝退款');
}
//修改退款状态
YHMOrders_Models_Refund_Client::updateStatus($order_code, YHMConfig_Orderstatus::REFUND_SELLER_REJECT);
//插入历史
YHMOrders_Models_Status_Client::setOrderstatus($order_code, YHMConfig_Orderstatus::REFUND_SELLER_REJECT, $params['uid']);
return self::result(200, '拒绝退款申请成功');
}
/**
* 确认退款申请
* @param array $params
* @param string $fields
*/
public static function confirm(array $params, $fields = "*") {
if (empty($params['uid'])) {
return self::result(400, 'uid不能为空');
}
if (empty($params['order_code'])) {
return self::result(400, '订单号不能为空');
}
$order_code = $params['order_code'];
$orders_status = YHMOrders_Models_Refund_Client::getByOrdercode($order_code);
if (empty($orders_status)) {
return self::result(400, '暂无退款申请');
}
if ($orders_status['refund_status'] == YHMConfig_Orderstatus::REFUND_BUYER_CANCEL) {
return self::result(500, '卖家已经取消退款!');
}
if ($orders_status['refund_status'] == YHMConfig_Orderstatus::REFUND_SELLER_CONFIRM) {
return self::result(500, '您已确认退款');
}
YHMOrders_Models_Orders_Client::updateOrderStatus($order_code, YHMConfig_Orderstatus::REFUND_SELLER_CONFIRM);
//修改退款状态
YHMOrders_Models_Refund_Client::updateStatus($order_code, YHMConfig_Orderstatus::REFUND_SELLER_CONFIRM);
//插入历史
YHMOrders_Models_Status_Client::setOrderstatus($order_code, YHMConfig_Orderstatus::REFUND_SELLER_CONFIRM, $params['uid']);
return self::result(200, '确认退款申请成功');
}
}