Index.php 10.9 KB
<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * @ApiTitle    (首页)
     * @ApiSummary  (首页)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Index/Index)
     * @ApiParams   (name="base_id", type="integer", required=true, description="基地ID")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    "data": {
    "BaseContent": "<p>北京佛山基地北京佛山基地北京佛山基地北京佛山基地</p>",  //基地简介
    "BaseWind": {  //基地风采
    "PlaneArray": [  //飞机
    {
    "id": 3,
    "title": "阿波罗三号"
    },
    {
    "id": 2,
    "title": "阿波罗二号"
    },
    {
    "id": 1,
    "title": "阿波罗一号"
    }
    ],
    "Teacher": [ //教练
    {
    "avatar": "http://www.airplane.net//uploads/20210406/6dd2dd5c0cd227b94c7b56a349cb5780.png",
    "name": "凤雏",
    "age": 100,
    "content": "<p>凤雏凤雏凤雏凤雏</p>"
    },
    {
    "avatar": "http://www.airplane.net//uploads/20210406/6dd2dd5c0cd227b94c7b56a349cb5780.png",
    "name": "王多余",
    "age": 10,
    "content": "<p>王多余王多余</p>"
    }
    ]
    },
    "StudentWind": {  //学员风采
    "Student": [  //毕业榜
    {
    "avatar": "http://www.airplane.net//uploads/20210406/6dd2dd5c0cd227b94c7b56a349cb5780.png",
    "name": "凤雏",
    "title": "2021-05期"
    },
    {
    "avatar": "http://www.airplane.net//uploads/20210406/6dd2dd5c0cd227b94c7b56a349cb5780.png",
    "name": "王多余",
    "title": "2021-04期"
    }
    ],
    "StudentImage": [  //学员学飞照片
    {
    "id": 1,
    "image": "http://www.airplane.net//uploads/20210406/6dd2dd5c0cd227b94c7b56a349cb5780.png"
    },
    {
    "id": 2,
    "image": "http://www.airplane.net//uploads/20210406/6dd2dd5c0cd227b94c7b56a349cb5780.png"
    },
    {
    "id": 3,
    "image": "http://www.airplane.net//uploads/20210406/6dd2dd5c0cd227b94c7b56a349cb5780.png"
    }
    ]
    }
    }
    })
     */
    public function Index()
    {
        $Params = $this->request->param();
        $PlaneArray = [];
        $Teacher = [];
        $Student = [];
        $StudentImage = [];
        $PlaneArray = Db::name('plane')->order('id desc')->where('base_id', $Params['base_id'])->field('id,title')->select();
        $Teacher = Db::name('teacher')->order('weigh desc')->where('base_id', $Params['base_id'])->field('id,avatar,name,teacher_age,con')->select();
        $Student = Db::name('student')->alias('s')->where('s.status', 1)->where('base_id', $Params['base_id'])->order('s.weigh desc')->join('cycle c', 'c.id=s.cycle_id')->field('s.avatar,s.name,c.title')->select();
        $StudentImage = Db::name('student_image')->where('base_id', $Params['base_id'])->select();
        if (!empty($Teacher)) foreach ($Teacher as $k => $v) {
            $Teacher[$k]['avatar'] = cdnurl($v['avatar']);
        }
        if (!empty($Student)) foreach ($Student as $k => $v) {
            $Student[$k]['avatar'] = cdnurl($v['avatar']);
        }
        if (!empty($StudentImage)) foreach ($StudentImage as $k => $v) {
            $StudentImage[$k]['image'] = cdnurl($v['image']);
        }
        $data = [
            'BaseContent' => Db::name('base')->where('id', $Params['base_id'])->value('content'),
            /*基地风采*/
            'BaseWind' => [
                /*飞机*/
                'PlaneArray' => $PlaneArray,
                /*教练榜*/
                'Teacher' => $Teacher
            ],
            /*学员风采*/
            'StudentWind' => [
                /*毕业榜*/
                'Student' => $Student,
                /*学员照片*/
                'StudentImage' => $StudentImage
            ]
        ];
        $this->success('成功', $data);
    }

    /**
     * @ApiTitle    (基地简介)
     * @ApiSummary  (基地简介)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Index/BaseContent)
     * @ApiParams   (name="base_id", type="integer", required=true, description="基地ID")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    "data": "<p>北京佛山基地北京佛山基地北京佛山基地北京佛山基地</p>"
    })
     */
    public function BaseContent()
    {
        $Params = $this->request->param();
        $this->success('成功', Db::name('base')->where('id', $Params['base_id'])->value('content'));
    }

    /**
     * @ApiTitle    (飞机详情)
     * @ApiSummary  (飞机详情)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Index/PlaneContent)
     * @ApiParams   (name="plane_id", type="integer", required=true, description="飞机ID")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    "data": {
    "id": 1,
    "title": "阿波罗一号",
    "content": "<p>阿波罗一号阿波罗一号阿波罗一号阿波罗一号阿波罗一号</p>"
    }
    })
     */
    public function PlaneContent()
    {
        $Params = $this->request->param();
        $this->success('成功', Db::name('plane')->where('id', $Params['plane_id'])->field('id,title,content')->find());
    }


    /**
     * @ApiTitle    (教练详情)
     * @ApiSummary  (教练详情)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Index/TeacherContent)
     * @ApiParams   (name="teacher_id", type="integer", required=true, description="教练id")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    "data": {
    "id": 1,
    "avatar": "http://www.airplane.net//uploads/20210406/6dd2dd5c0cd227b94c7b56a349cb5780.png",
    "name": "王多余",
    "sex": "男",
    "age": 10,
    "teacher_age": 2, //教龄
    "content": "<p>王多余王多余</p>"
    }
    })
     */
    public function TeacherContent()
    {
        $Params = $this->request->param();
        $Teacher = Db::name('teacher')->where('id', $Params['teacher_id'])->field('id,avatar,name,sex,age,teacher_age,content')->find();
        if (empty($Teacher)) $this->error('教练不存在', 0);
        $Teacher['avatar'] = cdnurl($Teacher['avatar']);
        $Teacher['sex'] = ($Teacher['sex'] == 1) ? '男' : '女';
        $this->success('成功', $Teacher);
    }


    /**
     * @ApiTitle    (毕业周期列表)
     * @ApiSummary  (毕业周期列表)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Index/CycleList)
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    "data": [
    {
    "id": 1,
    "title": "2021-04期"
    },
    {
    "id": 2,
    "title": "2021-05期"
    }
    ]
    })
     */
    public function CycleList()
    {
        $Cycle = [];
        $Cycle = Db::name('cycle')->select();
        $this->success('成功', $Cycle);
    }


    /**
     * @ApiTitle    (毕业榜)
     * @ApiSummary  (毕业榜)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Index/StudentList)
     * @ApiParams   (name="base_id", type="integer", required=true, description="基地ID")
     * @ApiParams   (name="cycle_id", type="integer", required=true, description="学期ID")
     * @ApiParams   (name="pages", type="integer", required=true, description="pages")
     * @ApiParams   (name="rows", type="integer", required=true, description="rows")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    "data": {
    "Count": 2,
    "List": [
    {
    "avatar": "http://www.airplane.net//uploads/20210406/6dd2dd5c0cd227b94c7b56a349cb5780.png",
    "name": "大聪明",
    "content": "<p>大聪明大聪明大聪明大聪明</p>",
    "title": "2021-05期"
    },
    {
    "avatar": "http://www.airplane.net//uploads/20210406/6dd2dd5c0cd227b94c7b56a349cb5780.png",
    "name": "卧龙",
    "content": "<p>卧龙卧龙卧龙卧龙卧龙</p>",
    "title": "2021-04期"
    }
    ]
    }
    })
     */
    public function StudentList()
    {
        $Params = $this->request->param();
        $Student = [];
        $Student = Db::name('student')->alias('s')->where('base_id', $Params['base_id'])->where('cycle_id', $Params['cycle_id'])->page($Params['pages'], $Params['rows'])->order('s.weigh desc')->join('cycle c', 'c.id=s.cycle_id')->field('s.id,s.avatar,s.name,s.con,c.title')->select();
        if (!empty($Student)) foreach ($Student as $k => $v) {
            $Student[$k]['avatar'] = cdnurl($v['avatar']);
        }
        $data = [
            'Count' => count(Db::name('student')->alias('s')->where('base_id', $Params['base_id'])->where('cycle_id', $Params['cycle_id'])->order('s.weigh desc')->join('cycle c', 'c.id=s.cycle_id')->field('s.id,s.avatar,s.name,s.con,c.title')->select()),
            'List' => $Student
        ];
        $this->success('成功', $data);
    }


    /**
     * @ApiTitle    (学员详情)
     * @ApiSummary  (学员详情)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Index/StudenContent)
     * @ApiParams   (name="student_id", type="integer", required=true, description="学员ID")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    "data": {
    "id": 1,
    "avatar": "http://www.airplane.net//uploads/20210406/6dd2dd5c0cd227b94c7b56a349cb5780.png",
    "name": "王多余",
    "sex": "男",
    "age": 40,
    "cycle": "2021-04期",
    "content": "<p>王多余王多余王多余</p>"
    }
    })
     */
    public function StudenContent()
    {
        $Params = $this->request->param();
        $Student = Db::name('student')->where('id', $Params['student_id'])->field('id,avatar,name,sex,age,cycle_id as cycle,content')->find();
        if (empty($Student)) $this->error('学员不存在', 0);
        $Student['avatar'] = cdnurl($Student['avatar']);
        $Student['sex'] = ($Student['sex'] == 1) ? '男' : '女';
        $Student['cycle'] = Db::name('cycle')->where('id', $Student['cycle'])->value('title');
        $this->success('成功', $Student);
    }
}