Match.php 2.9 KB
<?php


namespace app\teacher\controller;


use app\common\controller\TeacherBase;
use app\common\model\Member;
use think\Db;

class Match extends TeacherBase
{
    public function _initialize()
    {
        return parent::_initialize(); // TODO: Change the autogenerated stub
    }

    /**
     * @return string|\think\response\Json
     * @throws \think\Exception
     * 科技竞赛视图
     */
    public function index(){
        return $this->view->fetch();
    }
//{field: 'state', title:'序号', checkbox: true, },
//{field: 'match_title', title: '比赛名称', operate: false},
//{field: 'project_name', title: '项目名称', operate: false},
//{field: 'username', title: '姓名', operate: false},
//{field: 'student_no', title: '学号', operate: false},
//{field: 'mobile', title: '手机号', operate: false},
//{field: 'win_level', title: '获奖等级', operate: false},
//{field: 'createtime', title: '报名时间', operate: false}
    /**
     * @return array
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * 获取指导教师的科技竞赛
     */
    public function  getMatch(){
        $param = $this->request->param();

        $teacher = $this->auth;
        // dump($teacher);die;

        $list = (new Member())->alias('m')
            -> field('i.id,i.project_name,i.createtime,mh.match_title,u.username,u.mobile,u.student_no,p.prize_type')
            -> join('match_items i','m.item_id = i.id','left')
            -> join('match mh','i.match_id = mh.id','left')
            -> join('user u','u.id = i.user_id','left')
            -> join('match_item_prize p','p.match_items_id = i.id','left')
            -> where(['m.member_id' => $teacher['id'],'m.member_type' => Member::TEACHER,'m.member_source' => Member::MATCH])
            -> select();
        $total = (new Member())->alias('m')
            -> field('i.id')
            -> join('match_items i','m.member_id = i.id','left')
            -> where(['m.member_id' => $teacher['id'],'m.member_type' => Member::TEACHER,'m.member_source' => Member::MATCH])
            -> count();
        foreach ($list as $k => &$va){
            switch ($va['prize_type']){
                case null:
                    $va['prize_type'] = '--';
                    break;
                case 1:
                    $va['prize_type'] = '一等奖';
                    break;
                case 2:
                    $va['prize_type'] = '二等奖';
                    break;
                case 3:
                    $va['prize_type'] = '三等奖';
                    break;
            }
            $va['createtime'] = date('Y-m-d H:i:s',$va['createtime']);
        }
        $res = [
            "rows"   => $list,
            "total" => $total
        ];
        return $res;
    }


}