作者 何书鹏
1 个管道 的构建 通过 耗费 1 秒

个人中心-我的活动

@@ -284,7 +284,6 @@ class House extends Api @@ -284,7 +284,6 @@ class House extends Api
284 */ 284 */
285 public function house_list() 285 public function house_list()
286 { 286 {
287 - $qiniu = get_addon_config('qiniu')['cdnurl'];  
288 $user_id = $this->auth->id; 287 $user_id = $this->auth->id;
289 $area = $this->request->param('area'); 288 $area = $this->request->param('area');
290 $keyword = $this->request->param('keyword'); 289 $keyword = $this->request->param('keyword');
@@ -259,7 +259,6 @@ class HouseBoard extends Api @@ -259,7 +259,6 @@ class HouseBoard extends Api
259 "msg": "成功", 259 "msg": "成功",
260 "time": "1571492001", 260 "time": "1571492001",
261 "data": { 261 "data": {
262 - "id"://id  
263 "user_id"://用户id 262 "user_id"://用户id
264 "avatar"://管理员头像 263 "avatar"://管理员头像
265 "nickname"://昵称 264 "nickname"://昵称
@@ -279,7 +278,7 @@ class HouseBoard extends Api @@ -279,7 +278,7 @@ class HouseBoard extends Api
279 ->alias('a') 278 ->alias('a')
280 ->join('user b','a.user_id = b.id') 279 ->join('user b','a.user_id = b.id')
281 ->where('a.house_id',$house_id) 280 ->where('a.house_id',$house_id)
282 - ->field('a.id,a.user_id,b.avatar,b.nickname') 281 + ->field('a.user_id,b.avatar,b.nickname')
283 ->order('a.is_direct') 282 ->order('a.is_direct')
284 ->select(); 283 ->select();
285 foreach ($data as &$v){ 284 foreach ($data as &$v){
@@ -330,7 +329,6 @@ class HouseBoard extends Api @@ -330,7 +329,6 @@ class HouseBoard extends Api
330 */ 329 */
331 public function chat_record() 330 public function chat_record()
332 { 331 {
333 - $qiniu = get_addon_config('qiniu')['cdnurl'];  
334 $user_id = $this->auth->id; //当前登录用户id 332 $user_id = $this->auth->id; //当前登录用户id
335 $house_id = $this->request->param('house_id'); //社区id 333 $house_id = $this->request->param('house_id'); //社区id
336 $wuye_user_id = $this->request->param('user_id'); //物业用户id 334 $wuye_user_id = $this->request->param('user_id'); //物业用户id
@@ -352,7 +350,7 @@ class HouseBoard extends Api @@ -352,7 +350,7 @@ class HouseBoard extends Api
352 foreach ($data as &$v){ 350 foreach ($data as &$v){
353 $v['is_right'] = 1; 351 $v['is_right'] = 1;
354 if($v['type'] == 2){ 352 if($v['type'] == 2){
355 - $v['image'] = $qiniu.$v['image']; 353 + $v['image'] = cdnurl($v['image'],true);
356 } 354 }
357 } 355 }
358 $arr = Db::name('message') 356 $arr = Db::name('message')
@@ -364,7 +362,7 @@ class HouseBoard extends Api @@ -364,7 +362,7 @@ class HouseBoard extends Api
364 foreach ($arr as &$v){ 362 foreach ($arr as &$v){
365 $v['is_right'] = 2; 363 $v['is_right'] = 2;
366 if($v['type'] == 2){ 364 if($v['type'] == 2){
367 - $v['image'] = $qiniu.$v['image']; 365 + $v['image'] = cdnurl($v['image'],true);
368 } 366 }
369 } 367 }
370 368
@@ -395,7 +393,7 @@ class HouseBoard extends Api @@ -395,7 +393,7 @@ class HouseBoard extends Api
395 { 393 {
396 "id": // 活动id 394 "id": // 活动id
397 "title": // 活动标题 395 "title": // 活动标题
398 - "spec_type": // 活动规格:0=无规格(免费),1=单规格,2=多规格 396 + "spec_type": // 活动规格:0=无规格,免费,1=单规格,2=多规格
399 "content": // 活动描述 397 "content": // 活动描述
400 "activity_time": 活动日期 398 "activity_time": 活动日期
401 "price": // 报名费用 399 "price": // 报名费用
@@ -431,7 +429,7 @@ class HouseBoard extends Api @@ -431,7 +429,7 @@ class HouseBoard extends Api
431 "data": { 429 "data": {
432 "id": // 活动id 430 "id": // 活动id
433 "title": // 活动标题 431 "title": // 活动标题
434 - "spec_type": // 活动规格:0=无规格(免费),1=单规格,2=多规格 432 + "spec_type": // 活动规格:0=无规格,免费,1=单规格,2=多规格
435 "content": // 活动描述 433 "content": // 活动描述
436 "activity_time": 活动日期 434 "activity_time": 活动日期
437 "price": // 报名费用 435 "price": // 报名费用
@@ -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
  1 +<?php
  2 +
  3 +
  4 +namespace app\api\model;
  5 +
  6 +
  7 +class HouseJoin extends Base
  8 +{
  9 +
  10 +}
  1 +<?php
  2 +
  3 +
  4 +namespace app\api\model;
  5 +
  6 +
  7 +class Message extends Base
  8 +{
  9 +
  10 +}