CenterController.php
14.6 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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
<?php
/**
* Created by PhpStorm.
* User: yhbr
* Date: 2018/9/5
* Time: 10:48
*/
namespace app\user\controller;
use app\coupons\model\CouponModel;
use cmf\controller\HomeBaseController;
use Think\Db;
use app\coupons\model\DiscountCouponModel;
use app\order\model\OrderModel;
/**
* @title 个人中心模块
*/
class CenterController extends HomeBaseController
{
function _initialize()
{
if (empty(session('user.id'))) {
echo json_encode(['msg' => '登陆失败', 'code' => 40001]);
exit();
}
}
/**
* @title 个人中心首页
* @description 默认访问接口
* @author sᴏᴜʟ ᴏғ ᴄɪɴᴅᴇʀ
* @url /user/Center/index
* @method POST
*/
public function index()
{
$userInfo = Db::name('user')->field('user_nickname,avatar')->where(['id' => session('user.id')])->find();
if (request()->isPost()) {
echo json_encode(['user_info' => $userInfo, 'code' => 20000]);
exit();
} else {
return $this->fetch(':index', [
'user_info' => $userInfo
]);
}
}
/**
* @title 我的资料
* @description 默认访问接口(post方式更改用户信息需要填写参数,put模板渲染用户信息)
* @author sᴏᴜʟ ᴏғ ᴄɪɴᴅᴇʀ
* @url /user/Center/myInfo
* @method PUT
*
* @param name:realname type:char require:1 default:李涵 desc:真实姓名
* @param name:tel type:char require:1 default:15122554644 desc:手机号
* @param name:wechat type:char require:1 default:xxxxxx desc:微信号
* @param name:identity type:char require:1 default:12010319960501291X desc:身份证号
*
* @return version:版本号
* @return code:错误码
*/
public function myInfo()
{
$request = request();
if ($request->isPost()) {
$post = $request->param();
if ($post['realname'] == null) {
echo json_encode(['msg' => '请填写真实姓名', 'code' => 40000]);
exit();
}
if ($post['tel'] == null) {
echo json_encode(['msg' => '请填写手机号', 'code' => 40000]);
exit();
}
if ($post['wechat'] == null) {
echo json_encode(['msg' => '请填写微信号', 'code' => 40000]);
exit();
}
if ($post['identity'] == null) {
echo json_encode(['msg' => '请填写身份证信息', 'code' => 40000]);
exit();
}
$post['id'] = session('user.id');
if (Db::name('user')->update($post)) {
$is_perfect = Db::name('user')->where(['id' => session('user.id')])->value('is_perfect');
if ($is_perfect == 0) {
give_as_a_present(session('user.id'), '完善信息赠送');
}
Db::name('user')->update(['id' => session('user.id'), 'is_perfect' => 1]);
echo json_encode(['data' => '更改成功', 'code' => 20000]);
exit();
} else {
echo json_encode(['data' => '您未做出任何修改', 'code' => 40000]);
exit();
}
} elseif ($request->isPut()) {
$userInfo = Db::name('user')->field('avatar,user_nickname,realname,tel,wechat,identity')
->where(['id' => session('user.id')])
->find();
echo json_encode(['data' => $userInfo, 'code' => 20000]);
exit();
} else {
return $this->fetch(':edit', [
'info' => Db::name('user')->field('avatar,user_nickname,realname,tel,wechat,identity')
->where(['id' => session('user.id')])
->find()
]);
}
}
/**
* @title 我的优惠券
* @description 默认访问接口
* @author sᴏᴜʟ ᴏғ ᴄɪɴᴅᴇʀ
* @url /user/Center/discountCoupon
* @method POST
*
* @return version:版本号
* @return code:错误码
* @return id:优惠券id
* @return reduce:减
* @return discount_coupon_name:优惠券名称
* @return deadline:截止日期
*/
public function discountCoupon()
{
$request = request();
$user_id = session('user.id');
$model = new CouponModel;
$data = $model->getAllDiscountCouponByUniqueIdAndByStatus($user_id);
if ($request->isPost()) {
if (empty($data)) {
echo json_encode(['msg' => '暂无数据', 'code' => 40000]);
exit();
} else {
echo json_encode(['data' => $data, 'code' => 20000]);
exit();
}
} else {
return $this->fetch(':coupon', [
'data' => $data
]);
}
}
/**
* @title 我要充值
* @description 默认访问接口
* @author sᴏᴜʟ ᴏғ ᴄɪɴᴅᴇʀ
* @url /user/Center/charge
* @method POST
*
* @param name:is_bonus type:int require:1 default:0 desc:0普通充值1活动专享
*
* @return version:版本号
* @return code:错误码
* @return id:充值卡id
* @return denomination:面值
* @return bonus:赠送金额
*/
public function charge()
{
$is_bonus = request()->param('is_bonus');
$where['is_on_sale'] = ['eq', 1];
$is_bonus = (empty($is_bonus)) ? 0 : 1;
$where['is_bonus'] = ['eq', $is_bonus];
$field = 'id,denomination';
if ($is_bonus == 1) {
$field .= ',bonus';
}
$res = Db::name('charge')->field($field)->where($where)->select()->toArray();
if (request()->isPost()) {
echo json_encode(['data' => $res, 'code' => 20000]);
exit();
} else {
if ($is_bonus == 0) {
$view = ':charge';
} else {
$view = ':charge2';
}
return $this->fetch($view, [
'data' => $res
]);
}
}
/**
* @title 订单列表
* @description 默认访问接口
* @author sᴏᴜʟ ᴏғ ᴄɪɴᴅᴇʀ
* @url /user/Center/orderList
* @method POST
*
* @param name:status type:int require:1 default: desc:订单状态
* @param name:order_sn type:char require:1 default:201809091314 desc:订单号
* @return version:版本号
* @return code:错误码
*/
public function orderList()
{
$request = request();
$order['status'] = $request->param('status');
$order['order_sn'] = $request->param('order_sn');
$model = new OrderModel;
$list = $model->getOrderListByUserId($order['status'], $order['order_sn'], session('user.id'));
if ($request->isPost()) {
if (!empty($list)) {
echo json_encode(['order_list' => $list, 'code' => 20000]);
exit();
} else {
echo json_encode(['msg' => '暂无数据', 'code' => 40000]);
exit();
}
} else {
return $this->fetch(':order_list', [
'order_sn' => $order['order_sn'],
'status' => $order['status'],
'data' => $list
]);
}
}
/**
* @title 订单详情
* @description 默认访问接口
* @author sᴏᴜʟ ᴏғ ᴄɪɴᴅᴇʀ
* @url /user/Center/orderDetail
* @method POST
*
* @param name:oid type:int require:1 default: desc:订单id
* @return version:版本号
* @return code:错误码
*/
public function orderDetail()
{
$request = request();
//订单基本信息
$oid = $request->param('oid');
$info = Db::name('order_info')->alias('o')
->field('o.id as oid,o.order_sn,a.name,a.thumb,o.status,a.down_price,s.price')
->join('activity a', 'a.id=o.activity_id')
->join('activity_schedule s', 's.id=o.schedule_id')
->where(['o.id' => $oid])
->order('add_time DESC')
->find();
$info['status_text'] = getOrderStatusText($info['status']);
$info['count'] = Db::name('order_detail')->where(['oid' => $oid])->count();
$escort = Db::name('order_detail')->alias('d')
->field('d.id,d.status,d.reason,e.name,e.tel')
->join('escort e', 'e.id=d.escort_id')
->where(['oid' => $oid])
->select();
foreach ($escort as $k => $v) {
$v['count'] = 1;
$v['down_price'] = $info['down_price'];
$v['bar'] = $this->progressBar($v['status']);
$escort[$k] = $v;
}
$return = [
'baseInfo' => $info,
'escort' => $escort
];
if ($request->isPost()) {
echo json_encode(['data' => $return, 'code' => 20000]);
exit();
} else {
return $this->fetch(':order_detail', [
'data' => $return
]);
}
}
/**
* @title 钱包记录
* @description 默认访问接口
* @author sᴏᴜʟ ᴏғ ᴄɪɴᴅᴇʀ
* @url /user/Center/walletLog
* @method POST
*/
public function walletLog()
{
$balance = Db::name('user')->where(['id' => session('user.id')])->value('balance');
$log = Db::name('my_wallet')->field('type,cost,create_time')->where(['user_id' => session('user.id')])->order('create_time DESC')->select()->toArray();
foreach ($log as $k => $v) {
$v['create_time'] = date('Y.m.d H:i:s', $v['create_time']);
if ($v['type'] == 0) {
$v['type_text'] = '账户消费';
} elseif ($v['type'] == 1) {
$v['type_text'] = '账户充值';
} else {
$v['type_text'] = '退款订单';
}
$log[$k] = $v;
}
$return = [
'balance' => $balance,
'log' => $log
];
if (request()->isPost()) {
echo json_encode(['data' => $return, 'code' => 20000]);
exit();
} else {
return $this->fetch(':log', [
'data' => $return
]);
}
}
public function wallet()
{
return $this->fetch(':wallet', [
'balance' => Db::name('user')->where(['id' => session('user.id')])->value('balance')
]);
}
//进度条
private function progressBar($status)
{
if ($status == 2) {
$bar = '<div class="faqi_out">
<div class="circle_main active_circle">
<span class="circle">
</span>
<span class="fa">
发起退款待审核中
</span>
</div>
<div class="circle_main active_circle">
<span class="circle">
</span>
<span class="fa">
审核通过
</span>
<span class="span_line"></span>
</div>
<div class="circle_main active_circle">
<span class="circle">
</span>
<span class="fa">
已退款
</span>
<span class="span_line"></span>
</div>
</div>';
} elseif ($status == 3) {
$bar = '<div class="faqi_out">
<div class="circle_main active_circle">
<span class="circle">
</span>
<span class="fa">
发起退款待审核中
</span>
</div>
<div class="circle_main">
<span class="circle">
<i class="iconfont icon-chahao" id="icon-chahao"></i>
</span>
<span class="fa ">
审核不通过
</span>
<span class="span_line"></span>
</div>
<div class="circle_main ">
<span class="circle">
</span>
<span class="fa">
已退款
</span>
<span class="span_line"></span>
</div>
</div>';
} else {
$bar = '<div class="faqi_out">
<div class="circle_main active_circle">
<span class="circle">
</span>
<span class="fa">
发起退款待审核中
</span>
</div>
<div class="circle_main">
<span class="circle">
</span>
<span class="fa ">
</span>
<span class="span_line"></span>
</div>
<div class="circle_main ">
<span class="circle">
</span>
<span class="fa">
</span>
<span class="span_line"></span>
</div>
</div>';
}
return $bar;
}
public function refund()
{
$request = request();
if ($request->isAjax()) {
$id = $request->param('id');
$data = [
'id' => $id,
'status' => 1,
'cause' => $request->param('cause'),
];
if (Db::name('order_detail')->update($data)) {
$this->success('', '', true);
}
}
}
public function cancelOrder()
{
$request = request();
if ($request->isAjax()) {
if (Db::name('order_info')->where(['id' => $request->param('oid')])->value('status') == 1) {
$data = [
'id' => $request->param('oid'),
'status' => 7
];
if (Db::name('order_info')->update($data)) {
echo json_encode(['msg' => '已取消订单', 'code' => 20000]);
exit();
} else {
echo json_encode(['msg' => '取消失败', 'code' => 40000]);
exit();
}
} else {
echo json_encode(['msg' => '该订单禁止取消', 'code' => 40000]);
exit();
}
}
}
public function confirmOrder() {
$request = request();
if($request->isAjax()) {
if (Db::name('order_info')->where(['id' => $request->param('oid')])->value('status') == 4) {
$data = [
'id' => $request->param('oid'),
'status' => 5
];
if (Db::name('order_info')->update($data)) {
echo json_encode(['msg' => '订单已确认', 'code' => 20000]);
exit();
} else {
echo json_encode(['msg' => '确认失败', 'code' => 40000]);
exit();
}
} else {
echo json_encode(['msg' => '该订单禁止确认', 'code' => 40000]);
exit();
}
}
}
public function comment(){
$request = request();
if($request->isAjax()) {
}else {
return $this->fetch(':comment');
}
}
}