CenterController.php
4.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
<?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;
/**
* @title 个人中心模块
*/
class CenterController extends HomeBaseController
{
function __construct()
{
session('user.id', 2);
if (empty(session('user.id'))) {
echo json_encode(['msg' => '登陆失败', 'code' => 40001]);
exit();
}
}
/**
* @title 我的资料
* @description 默认访问接口(post方式更改用户信息需要填写参数,post以外是模板渲染用户信息)
* @author sᴏᴜʟ ᴏғ ᴄɪɴᴅᴇʀ
* @url /user/Center/myInfo
* @method GET
*
* @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)) {
echo json_encode(['data' => '更改成功', 'code' => 20000]);
exit();
} else {
echo json_encode(['data' => '您为做出任何修改', 'code' => 40000]);
exit();
}
} else {
$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();
}
}
/**
* @title 我的优惠券
* @description 默认访问接口
* @author sᴏᴜʟ ᴏғ ᴄɪɴᴅᴇʀ
* @url /user/Center/discountCoupon
* @method POST
*
* @param name:status type:char require:1 default:1 desc:1未使用2已使用3已过期
*
* @return version:版本号
* @return code:错误码
* @return id:优惠券id
* @return reduce:减
* @return discount_coupon_name:优惠券名称
* @return deadline:截止日期
*/
public function discountCoupon()
{
$request = request();
if ($request->isPost()) {
$post = $request->param();
$user_id = session('user.id');
$model = new CouponModel;
$data = $model->getAllDiscountCouponByUniqueIdAndByStatus($post['status'], $user_id);
if (empty($data)) {
echo json_encode(['msg' => '暂无数据', 'code' => 40000]);
exit();
} else {
echo json_encode(['data' => $data, 'code' => 20000]);
exit();
}
}
}
/**
* @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();
echo json_encode(['data' => $res, 'code' => 20000]);
exit();
}
}