Match.php
2.9 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
<?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;
}
}