Teams.php 5.0 KB
<?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_line", 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('请求方式错误');
        }
    }
}