MatchRuleController.php 6.1 KB

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