|
@@ -7,6 +7,8 @@ use app\common\library\Ems; |
|
@@ -7,6 +7,8 @@ use app\common\library\Ems; |
7
|
use app\common\library\Sms;
|
7
|
use app\common\library\Sms;
|
8
|
use fast\Random;
|
8
|
use fast\Random;
|
9
|
use think\Validate;
|
9
|
use think\Validate;
|
|
|
10
|
+use think\Cache;
|
|
|
11
|
+use app\api\model\HouseJoin;
|
10
|
|
12
|
|
11
|
/**
|
13
|
/**
|
12
|
* 会员接口
|
14
|
* 会员接口
|
|
@@ -83,24 +85,22 @@ class User extends Api |
|
@@ -83,24 +85,22 @@ class User extends Api |
83
|
* @ApiReturn ({
|
85
|
* @ApiReturn ({
|
84
|
"code": 1,
|
86
|
"code": 1,
|
85
|
"msg": "成功",
|
87
|
"msg": "成功",
|
86
|
- "time": "1598664523",
|
88
|
+ "time": "1598667600",
|
87
|
"data": {
|
89
|
"data": {
|
88
|
- "user": {
|
|
|
89
|
- "id": 2, //用户ID
|
|
|
90
|
- "username": "何先生", //用户名
|
|
|
91
|
- "nickname": "何先生", //昵称
|
|
|
92
|
- "avatar": "http://cloud.caiyunpan.brotop.cn/assets/img/avatar.png", //头像
|
|
|
93
|
- "money": "0.00", //钱包余额
|
|
|
94
|
- "house_id": 17, //当前小区ID
|
|
|
95
|
- "id_num": "100001", //ID
|
|
|
96
|
- "url": "/u/2",
|
|
|
97
|
- "today_money": 10, //今日收益
|
|
|
98
|
- "total_money": 10 //总收益
|
|
|
99
|
- },
|
|
|
100
|
- "house": { //当前小区信息
|
90
|
+ "id": 2, //用户ID
|
|
|
91
|
+ "username": "何先生", //用户名
|
|
|
92
|
+ "nickname": "何先生", //昵称
|
|
|
93
|
+ "avatar": "http://cloud.caiyunpan.brotop.cn/assets/img/avatar.png", //头像
|
|
|
94
|
+ "money": "0.00", //余额
|
|
|
95
|
+ "id_num": "100001", //ID
|
|
|
96
|
+ "url": "/u/2",
|
|
|
97
|
+ "house": { //小区信息
|
101
|
"id": 17, //小区ID
|
98
|
"id": 17, //小区ID
|
102
|
"name": "碧海花园小区" //小区名称
|
99
|
"name": "碧海花园小区" //小区名称
|
103
|
- }
|
100
|
+ },
|
|
|
101
|
+ "today_money": 10, //今日收益
|
|
|
102
|
+ "total_money": 10, //总收益
|
|
|
103
|
+ "message_num": 0 //未读消息数量
|
104
|
}
|
104
|
}
|
105
|
})
|
105
|
})
|
106
|
*/
|
106
|
*/
|
|
@@ -108,29 +108,98 @@ class User extends Api |
|
@@ -108,29 +108,98 @@ class User extends Api |
108
|
{
|
108
|
{
|
109
|
$user = $this->auth->getUser();
|
109
|
$user = $this->auth->getUser();
|
110
|
$store_inform_log = new \app\api\model\StoreInformLog;
|
110
|
$store_inform_log = new \app\api\model\StoreInformLog;
|
111
|
- // 今日收益
|
|
|
112
|
- $user['today_money'] = $store_inform_log
|
|
|
113
|
- ->where('user_id',$this->auth->id)
|
|
|
114
|
- ->whereTime('createtime', 'today')
|
|
|
115
|
- ->sum('money');
|
|
|
116
|
- // 总收益
|
|
|
117
|
- $user['total_money'] = $store_inform_log
|
|
|
118
|
- ->where('user_id',$this->auth->id)
|
|
|
119
|
- ->sum('money');
|
111
|
+ $data = [
|
|
|
112
|
+ // 当前小区信息
|
|
|
113
|
+ 'house' => \app\api\model\House::get($user['house_id'])
|
|
|
114
|
+ ->visible(['id','name'])->toArray(),
|
|
|
115
|
+ // 今日收益
|
|
|
116
|
+ 'today_money' => $store_inform_log
|
|
|
117
|
+ ->where('user_id',$this->auth->id)
|
|
|
118
|
+ ->whereTime('createtime', 'today')
|
|
|
119
|
+ ->sum('money'),
|
|
|
120
|
+ // 总收益
|
|
|
121
|
+ 'total_money' => $store_inform_log
|
|
|
122
|
+ ->where('user_id',$this->auth->id)
|
|
|
123
|
+ ->sum('money'),
|
|
|
124
|
+ // 未读消息数量
|
|
|
125
|
+ 'message_num' => \app\api\model\Message::where('to_user_id',$user['id'])
|
|
|
126
|
+ ->where('is_read',2)
|
|
|
127
|
+ ->count()
|
|
|
128
|
+ ];
|
120
|
$user = $user->visible([
|
129
|
$user = $user->visible([
|
121
|
'id',
|
130
|
'id',
|
122
|
'username',
|
131
|
'username',
|
123
|
'nickname',
|
132
|
'nickname',
|
124
|
'avatar',
|
133
|
'avatar',
|
125
|
'id_num',
|
134
|
'id_num',
|
126
|
- 'house_id',
|
|
|
127
|
'money'
|
135
|
'money'
|
128
|
- ])->append([
|
|
|
129
|
- 'today_money',
|
|
|
130
|
- 'total_money'
|
|
|
131
|
- ]);
|
|
|
132
|
- $house = \app\api\model\House::get($user['house_id'])->visible(['id','name']);
|
|
|
133
|
- $this->success('成功', compact('user','house'));
|
136
|
+ ])->toArray();
|
|
|
137
|
+ $this->success('成功', array_merge($user,$data));
|
|
|
138
|
+ }
|
|
|
139
|
+
|
|
|
140
|
+ /**
|
|
|
141
|
+ * @ApiTitle (个人中心-我的活动)
|
|
|
142
|
+ * @ApiSummary (个人中心-我的活动)
|
|
|
143
|
+ * @ApiMethod (POST)
|
|
|
144
|
+ * @ApiRoute (/api/user/activity)
|
|
|
145
|
+ * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
146
|
+ * @ApiReturn ({
|
|
|
147
|
+ "code": 1,
|
|
|
148
|
+ "msg": "成功",
|
|
|
149
|
+ "time": "1598673648",
|
|
|
150
|
+ "data": [{
|
|
|
151
|
+ "id": 20, //活动报名ID
|
|
|
152
|
+ "title": "澳大利亚政府这人品:我只要不承认,就不是针对中国", //活动标题
|
|
|
153
|
+ "content": "", //活动内容
|
|
|
154
|
+ "activity_time": "2020-08-28-2020-08-28" //活动时间
|
|
|
155
|
+ }]
|
|
|
156
|
+ })
|
|
|
157
|
+ */
|
|
|
158
|
+ public function activity()
|
|
|
159
|
+ {
|
|
|
160
|
+ $list = HouseJoin::where('user_id',$this->auth->id)
|
|
|
161
|
+ ->where('join_status','1')
|
|
|
162
|
+ ->field('id,title,content,start_time,end_time')
|
|
|
163
|
+ ->select();
|
|
|
164
|
+ foreach ($list as &$v) {
|
|
|
165
|
+ // 活动日期
|
|
|
166
|
+ $v['activity_time'] = date('Y-m-d',$v['start_time']).'-'.date('Y-m-d',$v['end_time']);
|
|
|
167
|
+ unset($v['start_time'],$v['end_time']);
|
|
|
168
|
+ }
|
|
|
169
|
+ $this->success('成功', $list);
|
|
|
170
|
+ }
|
|
|
171
|
+
|
|
|
172
|
+ /**
|
|
|
173
|
+ * @ApiTitle (个人中心-我的活动-详情)
|
|
|
174
|
+ * @ApiSummary (个人中心-我的活动-详情)
|
|
|
175
|
+ * @ApiMethod (POST)
|
|
|
176
|
+ * @ApiRoute (/api/user/activityInfo)
|
|
|
177
|
+ * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
178
|
+ * @ApiParams (name="house_join_id", type="string", required=true, description="报名ID")
|
|
|
179
|
+
|
|
|
180
|
+ * @ApiReturn ({
|
|
|
181
|
+ "code": 1,
|
|
|
182
|
+ "msg": "成功",
|
|
|
183
|
+ "time": "1598673648",
|
|
|
184
|
+ "data": [{
|
|
|
185
|
+ "id": 20, //报名ID
|
|
|
186
|
+ "title": "澳大利亚政府这人品:我只要不承认,就不是针对中国", //活动标题
|
|
|
187
|
+ "content": "", //活动内容
|
|
|
188
|
+ "activity_time": "2020-08-28-2020-08-28" //活动时间
|
|
|
189
|
+ }]
|
|
|
190
|
+ })
|
|
|
191
|
+ */
|
|
|
192
|
+ public function activityInfo()
|
|
|
193
|
+ {
|
|
|
194
|
+ $house_join_id = $this->request->param('house_join_id');
|
|
|
195
|
+ empty($house_join_id) && $this->error('请传入必填参数');
|
|
|
196
|
+ $info = HouseJoin::get(['user_id'=>$this->auth->id,'id'=>$house_join_id]);
|
|
|
197
|
+ empty($info) && $this->error('活动信息不存在');
|
|
|
198
|
+ $info['activity_time'] = date('Y-m-d',$info['start_time']).'-'.date('Y-m-d',$info['end_time']);
|
|
|
199
|
+ $info = $info->visible([
|
|
|
200
|
+ 'title',
|
|
|
201
|
+ ]);
|
|
|
202
|
+ $this->success('成功', $info);
|
134
|
}
|
203
|
}
|
135
|
|
204
|
|
136
|
/**
|
205
|
/**
|
|
@@ -246,14 +315,12 @@ class User extends Api |
|
@@ -246,14 +315,12 @@ class User extends Api |
246
|
* @param string $avatar 头像地址
|
315
|
* @param string $avatar 头像地址
|
247
|
* @param string $username 用户名
|
316
|
* @param string $username 用户名
|
248
|
* @param string $nickname 昵称
|
317
|
* @param string $nickname 昵称
|
249
|
- * @param string $bio 个人简介
|
|
|
250
|
*/
|
318
|
*/
|
251
|
public function profile()
|
319
|
public function profile()
|
252
|
{
|
320
|
{
|
253
|
$user = $this->auth->getUser();
|
321
|
$user = $this->auth->getUser();
|
254
|
$username = $this->request->request('username');
|
322
|
$username = $this->request->request('username');
|
255
|
$nickname = $this->request->request('nickname');
|
323
|
$nickname = $this->request->request('nickname');
|
256
|
- $bio = $this->request->request('bio');
|
|
|
257
|
$avatar = $this->request->request('avatar', '', 'trim,strip_tags,htmlspecialchars');
|
324
|
$avatar = $this->request->request('avatar', '', 'trim,strip_tags,htmlspecialchars');
|
258
|
if ($username) {
|
325
|
if ($username) {
|
259
|
$exists = \app\common\model\User::where('username', $username)->where('id', '<>', $this->auth->id)->find();
|
326
|
$exists = \app\common\model\User::where('username', $username)->where('id', '<>', $this->auth->id)->find();
|
|
@@ -263,7 +330,6 @@ class User extends Api |
|
@@ -263,7 +330,6 @@ class User extends Api |
263
|
$user->username = $username;
|
330
|
$user->username = $username;
|
264
|
}
|
331
|
}
|
265
|
$user->nickname = $nickname;
|
332
|
$user->nickname = $nickname;
|
266
|
- $user->bio = $bio;
|
|
|
267
|
$user->avatar = $avatar;
|
333
|
$user->avatar = $avatar;
|
268
|
$user->save();
|
334
|
$user->save();
|
269
|
$this->success();
|
335
|
$this->success();
|
|
@@ -323,8 +389,8 @@ class User extends Api |
|
@@ -323,8 +389,8 @@ class User extends Api |
323
|
if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $user->id)->find()) {
|
389
|
if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $user->id)->find()) {
|
324
|
$this->error(__('Mobile already exists'));
|
390
|
$this->error(__('Mobile already exists'));
|
325
|
}
|
391
|
}
|
326
|
- $result = Sms::check($mobile, $captcha, 'changemobile');
|
|
|
327
|
- if (!$result) {
|
392
|
+ $code = Cache::get($mobile);
|
|
|
393
|
+ if ($code != $captcha) {
|
328
|
$this->error(__('Captcha is incorrect'));
|
394
|
$this->error(__('Captcha is incorrect'));
|
329
|
}
|
395
|
}
|
330
|
$verification = $user->verification;
|
396
|
$verification = $user->verification;
|
|
@@ -333,7 +399,7 @@ class User extends Api |
|
@@ -333,7 +399,7 @@ class User extends Api |
333
|
$user->mobile = $mobile;
|
399
|
$user->mobile = $mobile;
|
334
|
$user->save();
|
400
|
$user->save();
|
335
|
|
401
|
|
336
|
- Sms::flush($mobile, 'changemobile');
|
402
|
+ Cache::rm($mobile);
|
337
|
$this->success();
|
403
|
$this->success();
|
338
|
}
|
404
|
}
|
339
|
|
405
|
|