Match.php
6.2 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
namespace app\index\controller\match;
use app\common\controller\Frontend;
use app\common\model\Member;
use app\school\model\match\MatchItems;
use app\index\model\MatchTagLog;
use app\school\model\review\Review;
use app\school\model\review\ReviewScore;
use app\common\model\match\MatchItemPrize;
use think\Collection;
use think\Db;
use think\Request;
class Match extends Frontend
{
protected $noNeedLogin = '*';
protected $noNeedRight = '*';
protected $layout = 'default';
public function _initialize()
{
parent::_initialize(); // TODO: Change the autogenerated stub
$this->assign('index','index');
}
public function index()
{
$type = request()->param('type');
$uid = $this->auth->id;
$memberModel = new Member();
$query = $memberModel->alias('m')
->field('i.*,m.is_captain,mt.match_title,mt.match_starttime,mt.match_endtime,mp.name')
->join('match_items i','m.item_id = i.id','inner')
->join('match mt','i.match_id = mt.id','left')
->join('match_type mp','i.match_type = mp.id','left');
if($type == 'ing') {
$query->where('mt.match_starttime','<=',time())->where('mt.match_endtime','>=',time());
}else if($type == 'ed'){
$query->where('mt.match_endtime','<',time());
}
$items = $query->where(['m.member_id' => $uid,'m.member_type' => Member::STUDENT,'m.member_source' => Member::MATCH])
->where(['i.school_id' => $this->school_id])
->order('i.createtime','desc')
->paginate(2, false, [
'query' => Request::instance()->param(),//不丢失已存在的url参数
]);
$countQuery = $memberModel->alias('m')
->field('i.*,m.is_captain,mt.match_title,mt.match_starttime,mt.match_endtime,mp.name')
->join('match_items i','m.item_id = i.id','inner')
->join('match mt','i.match_id = mt.id','left')
->join('match_type mp','i.match_type = mp.id','left');
if($type == 'ing') {
$countQuery->where('mt.match_starttime','<=',time())->where('mt.match_endtime','>=',time());
}else if($type == 'ed'){
$countQuery->where('mt.match_endtime','<',time());
}
$countQuery->where(['m.member_id' => $uid,'m.member_type' => Member::STUDENT,'m.member_source' => Member::MATCH])
->where(['i.school_id' => $this->school_id]);
$itemsCount = $countQuery->count();
/* $itemsModel = new MatchItems();
$query = $itemsModel->alias('i')
->field('i.*,m.match_title,mt.name,m.match_starttime,m.match_endtime')
->join('match m','m.id=i.match_id','left')
->join('match_type mt','mt.id=i.match_type','left');
if($type == 'ing') {
$query->where('m.match_starttime','<=',time())->where('m.match_endtime','>=',time());
}else if($type == 'ed'){
$query->where('m.match_endtime','<',time());
}
$items= $query ->where('i.user_id',$uid)
->where("i.school_id",$this->school_id)
->order('i.createtime','desc')
->paginate(2, false, [
'query' => Request::instance()->param(),//不丢失已存在的url参数
]);
$countQuery = $itemsModel->alias('i')
->field('i.id')
->join('match m','m.id=i.match_id','left')
->where(['i.user_id' => $uid,'i.school_id' => $this->school_id]);
if($type == 'ing') {
$countQuery->where('m.match_starttime','<=',time())->where('m.match_endtime','>=',time());
}else if($type == 'ed'){
$countQuery->where('m.match_endtime','<',time());
}
$itemsCount = $countQuery->count();*/
if($items) {
foreach ($items as &$val) {
$top = [];
$medium = [];
$down = [];
$info = Db::name('match_tag_log')->alias('l')
->field('l.createtime,m.tag_name,l.id')
->join('match_tags m','l.match_tag_id = m.id','left')
->where(['l.match_items_id' => $val['id']])
->order('l.createtime','desc')
->limit(9)
->select();
if($info) {
$info = sortArrByManyField($info,'createtime',SORT_ASC);
}
if($info) {
foreach ($info as $key => $tag) {
if($key <= 3) {
$top[] = $tag;
}else if ($key > 4) {
$down[] = $tag;
}else {
$medium[] = $tag;
}
}
}
$val['top'] = $top;
$val['medium'] = $medium;
$val['down'] = $down;
}
}
$this->assign('_list',$items);
$this->assignconfig('type',$type);
$this->assign('_count',$itemsCount);
return $this->view->fetch();
}
public function getRemark()
{
$id = request()->param('id');
$list = [];
$reviewModel = new Review();
$info = Db::name('match_tag_log')->where(['id' => $id])->find();
$review = $reviewModel->where('find_in_set(:id,match_tags_id)',['id'=>$info['match_tag_id']])->find();
if($review) {
$model = new ReviewScore;
$list = $model
->alias('s')
->field('s.remark,s.score_total,e.nickname')
->join('project_experts e','s.judge_id = e.id','left')
->where(['s.match_items_id' => $info['match_items_id'],'review_id' => $review['id']])
->select();
}
$this->assign('list',$list);
$this->assign('login','');
return $this->view->fetch();
}
public function prize_view($item_id)
{
$model = new MatchItemPrize();
$info = $model->where(['match_items_id' => $item_id])->find();
$this->assign('prize_type',$model->getPrizeType());
$this->assign('login','');
$this->assign('row',$info);
return $this->view->fetch();
}
}