CenterController.php
13.0 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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
<?php
namespace app\user\controller;
use cmf\controller\HomeBaseController;
use think\Db;
use app\order\model\OrderModel;
class CenterController extends HomeBaseController
{
/**
* 个人中心首页
*/
public function index()
{
$userInfo = Db::name('user')->field('user_nickname,avatar,balance')->where(['id' => session('user.id')])->find();
return $this->fetch('index', [
'data' => $userInfo
]);
}
/**
* 个人信息
*/
public function userInfo()
{
$userInfo = Db::name('user')->field('user_nickname,avatar,sex,mobile')->where(['id' => session('user.id')])->find();
return $this->fetch('info', [
'data' => $userInfo
]);
}
public function editName()
{
$request = request();
if ($request->isAjax()) {
if (Db::name('user')->update(['id' => session('user.id'), 'user_nickname' => $request->param('user_nickname')])) {
$this->success('编辑成功', url('user/Center/userInfo'));
}
} else {
return $this->fetch('edit_name', [
'nickname' => Db::name('user')->where(['id' => session('user.id')])->value('user_nickname')
]);
}
}
public function editPhone()
{
return $this->fetch('edit_phone');
}
public function editPhone2()
{
return $this->fetch('edit_phone2');
}
public function aboutUs()
{
$request = request();
if ($request->isAjax()) {
$data = [
'uid' => session('user.id'),
'content' => $request->param('content'),
'create_time' => time()
];
if (Db::name('zj_msg')->insert($data)) {
$this->success('感谢您的反馈', url('user/Center/userInfo'));
}
} else {
return $this->fetch('about_us', [
'data' => html_entity_decode(Db::name('zj_system')->value('about')),
'mobile' => Db::name('zj_system')->value('mobile')
]);
}
}
/**
* 地址管理
*/
public function addressManage()
{
$address = Db::name('zj_user_place')
->field('id,name,province,city,county,mobile,is_sta,place')
->where(['uid' => session('user.id')])
->select()
->toArray();
return $this->fetch('address_manage', [
'data' => $address
]);
}
public function addAddress()
{
$request = request();
if ($request->isAjax()) {
$post = $request->param();
$code = $post['code'];
$label = $post['label'];
$arr1 = explode(',', $code);
$post['province_id'] = $arr1[0];
$post['city_id'] = $arr1[1];
$post['county_id'] = $arr1[2];
$arr2 = explode(' ', $label);
$post['province'] = $arr2[0];
$post['city'] = $arr2[1];
$post['county'] = $arr2[2];
unset($post['code']);
unset($post['label']);
$post['uid'] = session('user.id');
if (Db::name('zj_user_place')->insert($post)) {
$this->success('', url('user/Center/addressManage'), true);
}
} else {
return $this->fetch('add_address');
}
}
public function delAddress()
{
if (Db::name('zj_user_place')->delete(request()->param('id'))) {
$this->success('', '', true);
}
}
public function editAddress()
{
$request = request();
if ($request->isAjax()) {
$post = $request->param();
$code = $post['code'];
$label = $post['label'];
$arr1 = explode(',', $code);
$post['province_id'] = $arr1[0];
$post['city_id'] = $arr1[1];
$post['county_id'] = $arr1[2];
$arr2 = explode(' ', $label);
$post['province'] = $arr2[0];
$post['city'] = $arr2[1];
$post['county'] = $arr2[2];
unset($post['code']);
unset($post['label']);
$post['uid'] = session('user.id');
if (Db::name('zj_user_place')->update($post)) {
$this->success('', url('user/Center/addressManage'), true);
}
} else {
return $this->fetch('edit_address', [
'data' => Db::name('zj_user_place')
->field('id,name,mobile,place,province_id,city_id,county_id,province,city,county')
->where(['id' => $request->param('id')])
->find()
]);
}
}
public function setDefault()
{
Db::name('zj_user_place')->where(['uid' => session('user.id')])->update(['is_sta' => 1]);
Db::name('zj_user_place')->where(['id' => request()->param('id')])->update(['is_sta' => request()->param('is_sta')]);
}
public function myBalance()
{
return $this->fetch('my_balance', [
'balance' => Db::name('user')->where(['id' => session('user.id')])->value('balance')
]);
}
public function upload()
{
upload();
}
public function upload2()
{
$this->success('', '', upload2());
}
public function orderList()
{
$order = new OrderModel;
require_once EXTEND_PATH . '/WeChatCommon.php';
$wx = new \WeChatCommon();
$data = $order->getAllOrders();
return $this->fetch('order_list', [
'data' => $data,
'js_sdk' => $wx->js_sdk()
]);
}
public function evaluate()
{
$request = request();
$oid = $request->param('oid');
if ($request->isAjax()) {
Db::startTrans();
if (Db::name('zj_order')->where(['id' => $oid])->value('is_evaluate') == 0) {
$res = Db::name('zj_order_goods')->field('gid')->where(['oid' => $oid])->select();
$data = [];
foreach ($res as $key => $item) {
$data[$key] = [
'oid' => $oid,
'gid' => $item['gid'],
'uid' => session('user.id'),
'is_sta' => 1,
'is_shove' => 1,
'create_time' => time(),
'rank' => $request->param('rank'),
'more' => substr($request->param('more'), 0, strlen($request->param('more')) - 1),
'content' => $request->param('content')
];
}
if (Db::name('zj_evaluate')->insertAll($data)) {
//变为已评价
$evaluate = [
'id' => $oid,
'is_evaluate' => 1
];
if (Db::name('zj_order')->update($evaluate)) {
Db::commit();
$this->success('感谢您的支持!', url('user/Center/orderList'), true);
} else {
Db::rollback();
$this->success('评价失败', '', false);
}
}
} else {
Db::rollback();
$this->success('您已评价过此订单啦', '', false);
}
} else {
return $this->fetch('', [
'oid' => $oid
]);
}
}
public function cancelOrder()
{
$request = request();
if ($request->isAjax()) {
$oid = $request->param('oid');
//如果是组合支付,需要吧之前支付的积分一并返还
$info = Db::name('zj_order')->field('pay_type,whole_num')->where(['id' => $oid])->find();
Db::startTrans();
if (Db::name('zj_order')->where(['id' => $oid])->value('step') == 1) {
if (Db::name('zj_order')->delete($oid)) {
if (Db::name('zj_order_goods')->where(['oid' => $oid])->delete()) {
if ($info['pay_type'] == 2) {
Db::name('user')->where(['id' => session('user.id')])->setInc('balance', $info['whole_num']);
}
Db::commit();
$this->success('订单已取消', '', true);
} else {
Db::rollback();
$this->success('取消失败', '', false);
}
} else {
Db::rollback();
$this->success('取消失败', '', false);
}
} else {
$this->success('该订单禁止取消', '', false);
}
}
}
//填写退货申请
public function refund()
{
$request = request();
$oid = $request->param('oid');
if ($request->isAjax()) {
$data = [
'id' => $request->param('oid'),
'cause' => $request->param('cause'),
'step' => 6
];
if (Db::name('zj_order')->update($data)) {
$this->success('请等待审核', url('user/Center/orderList'), true);
} else {
$this->success('提交失败', '', false);
}
} else {
$order_sn = Db::name('zj_order')->where(['id' => $oid])->value('order_num');
$list = Db::name('zj_order_goods')->alias('o')
->field('g.name,g.intro,o.price,g.thumb,o.num')
->join('zj_goods g', 'g.id=o.gid')
->where(['o.oid' => $oid])
->select();
foreach ($list as $k => $v) {
$v['thumb'] = cmf_get_image_url($v['thumb']);
$list[$k] = $v;
}
return $this->fetch('refund', [
'order_sn' => $order_sn,
'list' => $list,
'oid' => $oid
]);
}
}
//填写退款申请
public function refundPay()
{
$request = request();
$oid = $request->param('oid');
if ($request->isAjax()) {
$data = [
'id' => $request->param('oid'),
'company' => $request->param('company'),
'com_order' => $request->param('com_order'),
'step' => 8
];
if (Db::name('zj_order')->update($data)) {
$this->success('请等待审核', url('user/Center/orderList'), true);
} else {
$this->success('提交失败', '', false);
}
} else {
$order = Db::name('zj_order')->field('order_num,cause')->where(['id' => $oid])->find();
$list = Db::name('zj_order_goods')->alias('o')
->field('g.name,g.intro,o.price,g.thumb,o.num')
->join('zj_goods g', 'g.id=o.gid')
->where(['o.oid' => $oid])
->select();
foreach ($list as $k => $v) {
$v['thumb'] = cmf_get_image_url($v['thumb']);
$list[$k] = $v;
}
return $this->fetch('refund_pay', [
'order_sn' => $order['order_num'],
'cause' => $order['cause'],
'list' => $list,
'oid' => $oid
]);
}
}
//物流跟踪
public function tracking()
{
$oid = request()->param('oid');
$info = Db::name('zj_order')->alias('o')
->field('k.code,o.order_num,o.kd_num,k.name')
->join('zj_kd k', 'o.kid=k.id')
->where(['o.id' => $oid])
->find();
require EXTEND_PATH . '/KdApiSubscribeDemo.php';
$requestData = [
"OrderCode" => $info['order_num'],
"ShipperCode" => $info['code'],
"LogisticCode" => $info['kd_num']
];
$logisticResult = json_decode(orderTracesSubByJson(json_encode($requestData)), true);
return $this->fetch('', [
'kd_name' => $info['name'],
'tracking' => $logisticResult
]);
}
//确认收货
public function confirm()
{
$request = request();
if ($request->isAjax()) {
$data = [
'id' => $request->param('oid'),
'step' => 5,
'end_time' => time()
];
if (Db::name('zj_order')->update($data)) {
$this->success('', '', true);
}
}
}
public function integralLog()
{
$type = request()->param('type');
if ($type == 1) {
$title = '积分获取记录';
$where['type'] = ['in', "1,3"];
} else {
$title = '积分使用记录';
$where['type'] = ['in', "2,4"];
}
$where['uid'] = ['eq', session('user.id')];
$log = Db::name('zj_integral_log')->where($where)->order('create_time DESC')->select();
return $this->fetch('integral_log', [
'log' => $log,
'title' => $title
]);
}
}