Teams.php
5.0 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
<?php
namespace app\api\controller;
use app\common\controller\Api;
use think\Db;
use think\Validate;
/**
* 我的团队接口**
*/
class Teams extends Api
{
protected $noNeedLogin = [];
protected $noNeedRight = '*';
protected $user_id = '';//token存贮user_id
public function _initialize()
{
parent::_initialize();
$this->user_id = $this->auth->getUserId();
}
/**
* @ApiTitle (我的团队列表)
* @ApiSummary (我的团队列表)
* @ApiMethod (GET)
* @ApiRoute (/api/teams/myTeam)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="page", type="integer", required=true, description="分页页码")
* @ApiReturn ({
"code": 1,
"msg": "成功",
"time": "1553829068",
"data": [
{
"uid": 1,//uid
"username": "admin",//用户名
"avatar": "/uploads/20190318/c7eab178376c71ae1892cd23a1fb5779.jpg",//头像
"createtime": "2019-03-29",//加入时间
"score_sum": "100"//总积分
},
{
"uid": 2,
"username": "test",
"avatar": "/uploads/20190318/4d82786ab0f7866110519f221cbf29a6.jpg",
"createtime": "2019-03-29",
"score_sum": "50"
}
]
})
*/
public function myTeam(){
if($this->request->isGet()){
$page = $this->request->get('page');//分页页码
$limit = config('site.page_limit');//分页限制数量
$rule = config('site.gift_pages');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['page'=>$page])) {
$this->error($validate->getError());
}
$data = Db::table('gc_off_line')
->alias('l')
->join('gc_user u','off_uid = u.id','LEFT')
->where(['l.uid'=>$this->user_id,'u.status'=>'normal'])
->page($page,$limit)
->field('u.id uid,u.username,u.avatar,l.createtime,sum(l.s_score) as score_sum')
->group('l.off_uid')
->select();
foreach($data as &$value){
$value['createtime'] = date('Y-m-d',$value['createtime']);
}
$this->success('成功', $data);
}else{
$this->error('请求方式错误');
}
}
/**
* @ApiTitle (我的团队积分明细)
* @ApiSummary (我的团队积分明细)
* @ApiMethod (GET)
* @ApiRoute (/api/teams/teamDetail)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="off_uid", type="integer", required=true, description="下线用户uid")
* @ApiParams (name="page", type="integer", required=true, description="分页页码")
* @ApiReturn ({
"code": 1,
"msg": "成功",
"time": "1553830349",
"data": [
{
"uid": 1,//下线uid
"username": "admin",//用户名
"avatar": "/uploads/20190318/c7eab178376c71ae1892cd23a1fb5779.jpg",//头像
"type": 0,//类型 0:提交预约单 1:购买
"createtime": "2019-03-29",//加入时间
"score": 50//积分
},
{
"uid": 1,
"username": "admin",
"avatar": "/uploads/20190318/c7eab178376c71ae1892cd23a1fb5779.jpg",
"type": 0,
"createtime": "2019-03-29",
"score": 50
}
]
})
*/
public function teamDetail(){
if($this->request->isGet()){
$off_uid = $this->request->get('off_uid');//下线用户id
$page = $this->request->get('page');//分页页码
$limit = config('site.page_limit');//分页限制数量
$rule = config('site.user_id');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['page'=>$page,'off_uid'=>$off_uid])) {
$this->error($validate->getError());
}
$data = Db::table('gc_off_line')
->alias('l')
->join('gc_user u','off_uid = u.id','LEFT')
->where(['l.off_uid'=>$off_uid,'uid'=>$this->user_id,'u.status'=>'normal'])
->page($page,$limit)
->field('u.id uid,u.username,u.avatar,l.type,l.createtime,l.s_score score')
->select();
foreach($data as &$value){
$value['createtime'] = date('Y-m-d',$value['createtime']);
}
$this->success('成功',$data);
}else{
$this->error('请求方式错误');
}
}
}