MatchRuleController.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. /**
  3. * 系统设置
  4. */
  5. namespace App\Http\Controllers\Admin;
  6. use App\Http\Controllers\Controller;
  7. use App\Models\ArticleType;
  8. use Illuminate\Http\Request as Req;
  9. use Request;
  10. use App\Http\Model\St_match_rule as matchRuleModel;
  11. use App\Http\Model\St_match_rule_group as matchRuleGroupModel;
  12. /**
  13. *
  14. */
  15. class MatchRuleController extends Controller
  16. {
  17. /**
  18. * 活动公告
  19. */
  20. function Index(Req $req)
  21. {
  22. $request['title'] = isset($req->title) ? trim($req->title) : null;
  23. $request['type'] = isset($req->type) ? trim($req->type) : null;
  24. $dt = \App\Lib\DataTable\DataTable::init();
  25. $dt->setDataSource('/admin/MatchRule/getMatchRule');
  26. $dt->setLang('matchRule');
  27. $dt->addColsFields('id', array('width' => 60));
  28. // $dt->addColsFields('sort', array('width' => 120));
  29. $dt->addColsFields('modular_name',array('sort' => false, 'width' => 80));
  30. $dt->addColsFields('group_name', array('templet' => '#group_name', 'sort' => false, 'width' => 120));
  31. $dt->addColsFields('atime',array('width' => 160));
  32. $dt->addColsFields('author',array('width' => 80));
  33. $dt->addColsFields('status', array('templet' => '#closeTool', 'sort' => false, 'width' => 80));
  34. $dt->enableCheckBox();
  35. $arr[] = 'view';
  36. if (checkRriv('/admin/MatchRule/Edit')) {
  37. $arr[] = 'edit';
  38. }
  39. // $dt->setToolBar($arr, array('width' => 80));
  40. return view('admin.matchRule/arictle', $dt->render($request));
  41. }
  42. /**
  43. * 获取赛事规则数据
  44. */
  45. function getMatchRule(){
  46. $limit = Request::has('limit') ? Request::get('limit') : 10;
  47. $group_name = Request::has('group_name') ? Request::get('group_name') : '';
  48. $group_id = Request::has('group_id') ? Request::get('group_id') : '';
  49. $where = array();
  50. if (!empty($group_name)) {
  51. $where[] = array('group_name', 'like', '%' . $group_name . '%');
  52. }
  53. if (!empty($group_id)) {
  54. $where[] = array('group_id', '=', $group_id);
  55. }
  56. $db = new matchRuleModel();
  57. $data = $db->getList($limit, $where);
  58. return \App\Lib\DataTable\DataTable::init()->toJson($data);
  59. }
  60. /**
  61. * 发布赛事规则
  62. */
  63. function addMatchRule(Req $req)
  64. {
  65. if (!$req->isMethod('post')) {
  66. return view('admin.matchRule/editMatchRule', ['select' => 0, "child_id" => 0]);
  67. } else {
  68. if(matchRuleModel::where('group_id', $req->type)->first()){
  69. return responseToJson(-20001);
  70. }
  71. $data['modular_name'] = $req->input('title');
  72. $data['group_id'] = $req->type;
  73. $data['group_name'] = matchRuleGroupModel::find($data['group_id'])->group_name;
  74. $data['content'] = $req->desc;
  75. $log = array(
  76. session('adminInfo.admin_name'),
  77. $data['modular_name']
  78. );
  79. $data['atime'] = date('Y-m-d H:i:s');
  80. $data['utime'] = date('Y-m-d H:i:s');
  81. $data['author'] = session('adminInfo.admin_name');
  82. $data['status'] = 1;
  83. $db = new matchRuleModel();
  84. $res = $db->addMatchRule($data);
  85. OperationLog(session('adminInfo.admin_id'), 'add_match_rule', $log);
  86. return responseToJson(1);
  87. }
  88. }
  89. /**
  90. * 编辑
  91. */
  92. function Edit(Req $req)
  93. {
  94. $id = $req->id;
  95. if (intval($id) < 1) {
  96. abort(404);
  97. }
  98. $db = new matchRuleModel;
  99. if (!$req->isMethod('post')) {
  100. $data = $db->getDmsg($id);
  101. if (!$data) {
  102. return responseToJson($data);
  103. }
  104. $select = $data["type"];
  105. $child_id = $data["child_id"];
  106. return view('admin.matchRule/editMatchRule', ['data' => $data]);
  107. } else {
  108. $data['child_id'] = $req->child_id;
  109. $data['title'] = $req->input('title');
  110. // $data['author'] = $req->input('author');
  111. $data['sort'] = $req->input('sort');
  112. $data['type'] = $req->input('type');
  113. $data['img'] = $req->input('img');
  114. $data['typebind'] = $req->input('typebind');
  115. $data['mobilecontent'] = $req->mobilecontent;
  116. $data['mobileimg'] = $req->input('mobileimg');
  117. $data['content'] = $req->desc;
  118. $res = $db->updateMsg($data, $id);
  119. $log = array(
  120. session('adminInfo.admin_name'),
  121. $data['title']
  122. );
  123. OperationLog(session('adminInfo.admin_id'), 'edit_game', $log);
  124. return responseToJson($res);
  125. }
  126. }
  127. /**
  128. * 禁用
  129. */
  130. function activeClose(Req $req)
  131. {
  132. $status = $req->has('status') ? $req->get('status') : '';
  133. $id = $req->has('id') ? $req->get('id') : '';
  134. if (empty($id)) {
  135. return responseToJson(-5030002031);
  136. }
  137. if ($status < 0) {
  138. return responseToJson(-5030002032);
  139. }
  140. $db = new matchRuleModel();
  141. $data = array(
  142. 'status' => $status,
  143. );
  144. if ($status) {
  145. $data['status'] = 1;
  146. } else {
  147. $data['status'] = 0;
  148. }
  149. $res = $db->closeGame(["id" => intval($id)], $data);
  150. return responseToJson($res);
  151. }
  152. /**
  153. * 查看
  154. */
  155. function view(Req $req)
  156. {
  157. return $this->Edit($req);
  158. }
  159. /**
  160. * 批量删除
  161. * [delete description]
  162. * @return [type] [description]
  163. */
  164. function delete(Req $req)
  165. {
  166. $id = $req->input('id');
  167. if (empty($id)) {
  168. return responseToJson(-2001);
  169. }
  170. $ids = explode(',', $id);
  171. if (!is_array($ids) && intval($ids) < 0) {
  172. return responseToJson(-2002);
  173. }
  174. if (is_array($ids) && count($ids) > 0) {
  175. foreach ($ids as $k => $v) {
  176. if (intval($v) < 1) {
  177. unset($ids[$k]);
  178. }
  179. }
  180. }
  181. $rows = matchRuleModel::whereIn('id', $ids)->delete();
  182. if (!$rows) {
  183. return responseToJson(-2003);
  184. }
  185. return responseToJson(1);
  186. }
  187. }
  188. ?>