CompetitionController.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Http\Request as Req;
  5. use Illuminate\Support\Facades\DB;
  6. use Request;
  7. /**
  8. *赛事场次管理
  9. */
  10. class CompetitionController extends Controller {
  11. public function Index(Req $req){
  12. $request=array();
  13. $request['match_id']=isset($req->match_id)?trim($req->match_id):null;//赛事id
  14. $request['game']=isset($req->game)?trim($req->game):null;//游戏名
  15. //开始时间
  16. $request['start_time_a']=isset($req->start_time_a)?trim($req->start_time_a):null;
  17. $request['start_time_b'] = isset($req->start_time_b) ? trim($req->start_time_b) : null;
  18. //结束时间
  19. $request['end_time_a'] = isset($req->end_time_a) ? trim($req->end_time_a) : null;
  20. $request['end_time_b'] = isset($req->end_time_b) ? trim($req->end_time_b) : null;
  21. //赛事名称
  22. $request['info_name']=isset($req->info_name )?$req->info_name :null;
  23. $request['sub_title']=isset($req->sub_title )?$req->sub_title :null;
  24. $request['info_no']=isset($req->info_no )?$req->info_no :null;
  25. //状态
  26. $request['status']=isset($req->status)?$req->status:null;
  27. $dt = \App\Lib\DataTable\DataTable::init();
  28. $dt->setDataSource('/admin/Competition/dataSource?match_id='.$request['match_id']);
  29. $dt->setLang('competition');
  30. $dt->addColsFields('game_name', array('sort' => false,'width'=>150));
  31. $dt->addColsFields('info_name', array('sort' => false,'width'=>150));
  32. $dt->addColsFields('sub_title', array('sort' => false,'width'=>150));
  33. $dt->addColsFields('info_no', array('sort' => false,'width'=>187));
  34. $dt->addColsFields('start_time', array('sort' => false,'width'=>200));
  35. $dt->addColsFields('end_time', array('sort' => false,'width'=>200));
  36. $dt->addColsFields('status', array('templet'=>'#status'));
  37. $dt->addColsFields('tools',array('templet' => '#tools'));
  38. return view('admin.competition/index', $dt->render($request));
  39. }
  40. //数据源
  41. function dataSource(Req $req){
  42. $match_id=isset($req->match_id)?intval($req->match_id):'';//赛事id
  43. $game=isset($req->game)?trim($req->game):null;//游戏名
  44. //开始时间
  45. $start_time_a=isset($req->start_time_a)?trim($req->start_time_a):null;
  46. $start_time_b = isset($req->start_time_b) ? trim($req->start_time_b) : null;
  47. //结束时间
  48. $end_time_a = isset($req->end_time_a) ? trim($req->end_time_a) : null;
  49. $end_time_b = isset($req->end_time_b) ? trim($req->end_time_b) : null;
  50. //赛事名称
  51. $info_name=isset($req->info_name)?$req->info_name:null;
  52. //场次
  53. $sub_title=isset($req->sub_title)?$req->sub_title:null;
  54. $info_no=isset($req->info_no)?trim($req->info_no):null;
  55. //状态
  56. $status =isset($req->status)?$req->status:null;
  57. //条数
  58. $list=isset($req->limit)?intval($req->limit):10;
  59. $where=array();//条件数组
  60. if(!empty($match_id)){
  61. $where[]=array('match_id','=',$match_id);
  62. }
  63. if(!empty($game)){
  64. $where[]=array('game_name','=',$game);
  65. }
  66. if(!empty($start_time_a)){
  67. $start_time_a=$start_time_a.' 00:00:00';
  68. $where[]=array('start_time','>=',$start_time_a);
  69. }
  70. if(!empty($start_time_b)){
  71. $start_time_b=$start_time_a.' 23:59:59';
  72. $where[]=array('start_time','>=',$start_time_b);
  73. }
  74. if(!empty($end_time_a)){
  75. $end_time_a=$end_time_a.' 00:00:00';
  76. $where[]=array('end_time','>=',$end_time_a);
  77. }
  78. if(!empty($end_time_b)){
  79. $end_time_b=$end_time_b.' 23:59:59';
  80. $where[]=array('start_time','>=',$end_time_b);
  81. }
  82. if(!empty($info_name)){
  83. $where[]=array('info_name','like','%'.$info_name.'%');
  84. }
  85. if(!empty($sub_title)){
  86. $where[]=array('sub_title','like','%'.$sub_title.'%');
  87. }
  88. if(!empty($status)){
  89. $where[]=array('status','=',$status);
  90. }
  91. if(!empty($info_no)){
  92. $where[]=array('info_no','=',$info_no);
  93. }
  94. $data=\App\Models\Egame::getInfoList($where,$list);
  95. return \App\Lib\DataTable\DataTable::init()->toJson($data['data'],$data['total']);
  96. }
  97. //详情查看
  98. function View(Req $req){
  99. $info_no=$req->info_no?trim($req->info_no):'';
  100. if(empty($info_no)){
  101. echo '没获取正确的区号';
  102. return -1;
  103. }
  104. $data=\App\Models\Egame::getDetail($info_no);
  105. // dump($data);
  106. return view('/admin/competition/view',['data'=>$data]);
  107. }
  108. //新增游戏期数
  109. function Add(Req $req){
  110. $match_id=$req->match_id?intval($req->match_id):'';
  111. $match_info=array();
  112. $game=$req->game?trim($req->game):'';
  113. if(empty($match_id)){
  114. $match_info=\App\Models\Egame::getNowMatch($game);
  115. if($match_info<0){
  116. echo '没有对应赛事';
  117. return -1;
  118. }
  119. $match_id=$match_info['match_id'];
  120. }
  121. if(!$req->isMethod('post')){
  122. //获取赛事信息
  123. $match_info=\App\Models\Egame_match::getInfoByID($match_id);
  124. if(!empty($game)){
  125. $match_info['game_name']=$game;
  126. }
  127. //获取赛事队伍
  128. $team_info=\App\Models\Egame_team::getMatchTeam($match_id);
  129. if($team_info<0||empty($team_info)){
  130. echo '请先添加赛事参赛队伍';
  131. return $team_info;
  132. }
  133. return view('admin.competition/add',['match'=>$match_info,'team'=>$team_info]);
  134. }else{
  135. $info_no=$req->info_no?trim($req->info_no):'';
  136. $info_name=$req->info_name?trim($req->info_name):'';
  137. $start_time=$req->start_time?$req->start_time:'';
  138. $end_time=$req->end_time?$req->end_time:'';
  139. $sub_title=$req->sub_title?trim($req->sub_title):'';
  140. $sealingplate=$req->sealingplate?trim($req->sealingplate):'';
  141. $game_name=$req->game_name?$req->game_name:'';
  142. $video_url=$req->video_url?$req->video_url:'';
  143. $team_a_identity=$req->team_a_identity?trim($req->team_a_identity):'';
  144. $team_b_identity=$req->team_b_identity?trim($req->team_b_identity):'';
  145. /****************************数据检测********************************/
  146. if(empty($info_no)){
  147. return responseToJson(-9040410422);
  148. }
  149. if(empty($info_name)){
  150. return responseToJson(-9040410522);
  151. }
  152. if(empty($start_time)){
  153. return responseToJson(-9040410622);
  154. }
  155. if(empty($end_time)){
  156. return responseToJson(-9040410722);
  157. }
  158. if(empty($sealingplate)){
  159. return responseToJson(-9040410822);
  160. }
  161. if(empty($sub_title)){
  162. return responseToJson(-9040410922);
  163. }
  164. if(empty($game_name)){
  165. return responseToJson(-9040411022);
  166. }
  167. if(empty($team_a_identity)||empty($team_b_identity)){
  168. return responseToJson(-9040411122);
  169. }
  170. if($team_a_identity==$team_b_identity){
  171. //选择了相同队伍
  172. return responseToJson(-9040411222);
  173. }
  174. //检测期号是否重复
  175. $check=\App\Models\Egame::checkNo($info_no);
  176. if($check<0){
  177. return responseToJson($check);
  178. }
  179. /***************************插入数据************************************/
  180. DB::beginTransaction();
  181. //egame
  182. $data=array(
  183. 'info_no'=>$info_no,
  184. 'info_name'=>$info_name,
  185. 'start_time'=>$start_time,
  186. 'end_time'=>$end_time,
  187. 'sub_title'=>$sub_title,
  188. 'sealingplate'=>$sealingplate,
  189. 'game_name'=>$game_name,
  190. 'match_id'=>$match_id,
  191. );
  192. $res=\App\Models\Egame::addNew($data);
  193. if($res<0){
  194. DB::rollback();
  195. return responseToJson($res);
  196. }
  197. //比赛队伍表
  198. //获取队伍信息
  199. $team_a_info=\App\Models\Egame_team::getInfoByID($team_a_identity);
  200. $team_b_info=\App\Models\Egame_team::getInfoByID($team_b_identity);
  201. $team_vs_data=array(
  202. 'team_a_code'=>'first',
  203. 'team_a_name'=>$team_a_info['team_name'],
  204. 'team_a_logo'=>$team_a_info['team_icon'],
  205. 'team_a_identity'=>$team_a_identity,
  206. 'team_b_code'=>'second',
  207. 'team_b_name'=>$team_b_info['team_name'],
  208. 'team_b_logo'=>$team_b_info['team_icon'],
  209. 'team_b_identity'=>$team_b_identity,
  210. 'info_no'=>$info_no,
  211. 'info_name'=>$info_name,
  212. 'video_url'=>$video_url
  213. );
  214. $res=\App\Models\Egame_info::addNewMatch($team_vs_data);
  215. if($res<0){
  216. DB::rollback();
  217. return responseToJson($res);
  218. }
  219. DB::commit();
  220. return responseToJson($res);
  221. }
  222. }
  223. }