RefundController.php
6.58 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
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Model\OrderModel;
use App\Model\OrderRefundModel;
use App\Model\OrderRefundItemsModel;
use DB;
use App\Http\Page;
use App\Model\UserMainModel;
// 获取会员账号
function getAccountName($user_id)
{
if (!$user_id) return false;
$userMainModel = new UserMainModel;
$user = $userMainModel->find($user_id);
if (!$user) return false;
return $user->mobile ? $user->mobile : $user->email;
}
// 获取订单金额
function getOrderAmount($order_id)
{
if (!$order_id) return false;
$OrderModel = new OrderModel;
$order = $OrderModel->find($order_id);
if (!$order) return false;
return $order->order_amount;
}
// 获取支付名称
function getPayName($order_id)
{
$payLog = DB::connection('order')
->table('lie_pay_log')
->where(['order_id' => $order_id])
->select('pay_name')
->get();
if (!empty($payLog)) {
foreach ($payLog as $v) {
$payName[] = $v->pay_name;
}
return implode(',', $payName);
}
return false;
}
class RefundController extends Controller
{
// 页面用户、菜单信息
public function getPageInfo(Request $request)
{
$uri = '/' . $request->path();
if ($request->path() == '/') $uri = '/list';
$username = $request->user->email;
$useremail= $request->user->email;
// 菜单
$menuconfig = DB::table('config')->where('config_title', '订单系统')->first();
$menus = [];
if ($menuconfig && !($menus = json_decode($menuconfig->config_data)))
$menus = [];
$perm = new PermController;
// 用户角色
$role = $perm->getUserRole($request);
// 获取权限菜单
if ($role != 1) {
$menus = $perm->getPermMenu($menus, $request->user->userId);
}
$userPerms = $perm->getUserAllPerms($request->user->userId, $role); // 用户权限
$data = [
'header' => $request->user->header,
'uri' => $uri,
'username' => $username,
'useremail' => $useremail,
'menus' => $menus,
'userPerms' => $userPerms,
'role' => $role,
];
return $data;
}
// 联营退款列表
public function jointRefundList(Request $request)
{
$info = $this->refundList($request, 1);
return view('refundlist', $info);
}
// 自营退款列表
public function selfRefundList(Request $request)
{
$info = $this->refundList($request, 2);
return view('refundlist', $info);
}
// 退款申请列表
public function refundList(Request $request, $type)
{
$info = $this->getPageInfo($request);
$info['title'] = $type == 1 ? '联营退款申请列表' : '自营退款申请列表';
$map['order_sn'] = $request->input('order_sn', '');
$map['sku_name'] = $request->input('sku_name', '');
$map['order_payment_mode'] = $request->input('order_payment_mode', '');
$map['apply_status'] = $request->input('apply_status', '');
$map['time_start'] = $request->input('time_start', '');
$map['time_end'] = $request->input('time_end', '');
$map['order_goods_type'] = $type; // 类型
//获取订单列表
$url = Config('website.api_domain').'refund/getRefundOrderList';
$data['k1'] = time();
$data['k2'] = md5(md5($data['k1']).'fh6y5t4rr351d2c3bryi');
$data['p'] = $request->input('p', 1); // 当前页码
$data['size'] = 10; // 当前页条数
$data['map'] = $map;
$response = json_decode(curlApi($url, $data), true);
// 分页
$page = new Page($response['data']['count'], 10);
$page->setConfig('theme', '%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
$show = $page->show();
$info['condition'] = $map;
$info['list'] = $response['data']['data'];
$info['count'] = $response['data']['count'];
$info['page'] = $show;
return $info;
}
// 联营退款导出
public function refundExport(Request $request)
{
$refundModel = new OrderRefundModel();
return $refundModel->jointExport($request);
}
// 自营退款导出
public function refundSelfExport(Request $request)
{
$refundModel = new OrderRefundModel();
return $refundModel->selfExport($request);
}
// 退货详情
public function refundDetails(Request $request, $id)
{
$info = $this->getPageInfo($request);
$OrderRefundModel = new OrderRefundModel();
$info['refund'] = $OrderRefundModel->find($id);
$info['refundItems'] = $OrderRefundModel->find($id)->hasManyRefundItems;
if ($info['refund']['order_goods_type'] == 1) {
$title = '联营订单';
$refund_url = '/refund_order';
} else {
$title = '自营订单';
$refund_url = '/refund_self_order';
}
$info['title'] = '订单退货详情';
$info['paths'] = [["title" => $title, "href" => '#'], ["title" => '退款申请列表', "href" => $refund_url], ["title" => '订单退货详情', "href" => '#']];
return view('refundDetails', $info);
}
// 钱包退款
public function walletRefund(Request $request, $id)
{
// 获取退款单
// $refund = DB::connection('order')->table('lie_order_refund')->where('refund_id', $id)->first();
if (!$id) echo '未获取到退款单';
$data['refund_id'] = $id;
// $data['refund_amount'] = number_format($refund->pay_amount - $refund->price_fall, 2); // 最終退款金額
$data['pay_code'] = 'unionpay';
$url = Config('website.api_domain').'refund/recharge';
$data['k1'] = time();
$data['k2'] = md5(md5($data['k1']).'fh6y5t4rr351d2c3bryi');
$temp = curlApi($url, $data, "POST");
if (!$temp) echo '未获取到退款地址';
echo $temp;
}
// 自营取消退款申请
public function cancelSelfRefund(Request $request)
{
$refund_id = $request->input('refund_id');
$update = DB::connection('order')->table('lie_order_refund')->where('refund_id', $refund_id)->update(['status' => -1]);
if (!$update) return ['errcode' => 1, 'errmsg' => '取消申请失败'];
return ['errcode' => 0, 'errmsg' => '取消申请成功'];
}
}