CenterController.php
8.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
<?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 __construct()
{
if (empty(session('user.id'))) {
echo json_encode(['msg' => '登陆失败', 'code' => 40001]);
exit();
}
}
/**
* @title 个人中心首页
* @description 默认访问接口
* @author sᴏᴜʟ ᴏғ ᴄɪɴᴅᴇʀ
* @url /user/Center/index
* @method GET
*/
public function index()
{
$userInfo = Db::name('user')->field('user_nickname,avatar')->where(['id' => session('user.id')])->find();
echo json_encode(['user_info' => $userInfo, 'code' => 20000]);
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:int 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();
}
/**
* @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 (!empty($list)) {
echo json_encode(['order_list' => $list, 'code' => 20000]);
exit();
} else {
echo json_encode(['msg' => '暂无数据', 'code' => 40000]);
exit();
}
}
/**
* @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,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'];
$escort[$k] = $v;
}
$return = [
'baseInfo' => $info,
'escort' => $escort
];
echo json_encode(['data' => $return, 'code' => 20000]);
exit();
}
/**
* @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
];
echo json_encode(['data' => $return, 'code' => 20000]);
exit();
}
}