SoccerLeagueController.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 App\Lib\Settlement\SettlementWinFail;
  7. use App\Models;
  8. use Request;
  9. /**
  10. *
  11. */
  12. class SoccerLeagueController extends Controller {
  13. public function index(Req $req) {
  14. //$request['name_chinese'] = isset($req->name_chinese) ? trim($req->name_chinese) : '-1';
  15. $request['name_chinese'] = isset($req->name_chinese) ? trim($req->name_chinese) : '';
  16. $request['area_id'] = isset($req->area_id) ? trim($req->area_id) : '';
  17. $request['country_id'] = isset($req->country_id) ? trim($req->country_id) : '';
  18. $request['id'] = isset($req->id) ? trim($req->id) : '';
  19. $request['status'] = isset($req->status) ? trim($req->status) : '0';
  20. $request['sureblurs'] = isset($req->sureblurs) ? $req->sureblurs : 'on';
  21. $data = \App\Models\SoccerLeague::select('id','lg_id','name_chinese')->get();
  22. $area = \App\Models\StAreaCountry::where('pid',0)->get();
  23. $country = \App\Models\StAreaCountry::where('pid','!=',0)->get();
  24. $request['league'] = $data;
  25. $request['area'] = $area;
  26. $request['country'] = $country;
  27. $dt = \App\Lib\DataTable\DataTable::init();
  28. $dt->setDataSource('/admin/SoccerLeague/info');
  29. $dt->setLang('sportsbase');
  30. $dt->addColsFields('id', array('templet' => '#userdetail', 'sort' => true, 'width' => 120));
  31. $dt->addColsFields('name_chinese', array('templet' => '#userdetail', 'sort' => false, 'width' => 200));
  32. $dt->addColsFields('area', array('sort' => false, 'width' => 180));
  33. $dt->addColsFields('country', array('sort' => true, 'width' => 180));
  34. $dt->addColsFields('league_status', array('templet' => '#userdetail', 'sort' => false, 'width' => 90));
  35. $dt->addColsFields('utime', array('templet' => '#userdetail', 'sort' => false, 'width' => 160));
  36. if (checkRriv('/admin/SoccerLeague/edit')) {
  37. $arr[] = 'edit';
  38. }
  39. $dt->setToolBar($arr, array('width' => 140));
  40. $dt->enableCheckBox();
  41. return view('sports/soccer_league', $dt->render($request));
  42. }
  43. function info(Req $req) {
  44. $page = Request::has('page') ? Request::get('page') : '';
  45. $list = Request::has('limit') ? Request::get('limit') : 10;
  46. $name_chinese = Request::has('name_chinese') ? Request::get('name_chinese') : '';
  47. $area_id = Request::has('area_id') ? Request::get('area_id') : '';
  48. $country_id = Request::has('country_id') ? Request::get('country_id') : '';
  49. $status = Request::has('status') ? Request::get('status') : '';
  50. $sureblur = Request::has('sureblurs') ? Request::get('sureblurs') : 'off';
  51. $where = array();
  52. if (!empty($name_chinese)) {
  53. if (empty($sureblur) || $sureblur == 'off') {
  54. $where[] = array('st_zq_league.name_chinese', 'like', '%' . $name_chinese . '%');
  55. }else{
  56. $where[] = array('st_zq_league.name_chinese', '=', $name_chinese);
  57. }
  58. }
  59. // if ($name_chinese != -1) {
  60. // $where[] = array('st_zq_league.name_chinese', '=', $name_chinese);
  61. // }
  62. if(!empty($area_id)){
  63. $where[] = array('st_zq_league.area_id', '=', $area_id);
  64. }
  65. if(!empty($country_id)){
  66. $where[] = array('st_zq_league.country_id', '=', $country_id);
  67. }
  68. if($status != 0){
  69. $where[] = array('st_zq_league.status', '=', $status);
  70. }
  71. $newapp = new \App\Models\SoccerLeague();
  72. $data = $newapp->getinfo($list, $page, $where);
  73. return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total']);
  74. }
  75. /**
  76. *获取地区
  77. */
  78. function getarea() {
  79. $area = \App\Models\StAreaCountry::where('pid',0)->get();
  80. return $area;
  81. }
  82. /**
  83. *获取该地区的所有国家
  84. */
  85. function getcountry() {
  86. $pid = $_GET["id"];
  87. $country = \App\Models\StAreaCountry::where('pid',$pid)->get();
  88. return json_encode($country);
  89. }
  90. /**
  91. *添加联赛
  92. */
  93. function add(Req $req) {
  94. if (!$req->isMethod('post')) {
  95. $areas = $this->getarea();
  96. if (!$areas) {
  97. return -2;
  98. }
  99. $data['area'] = $areas;
  100. return view('sports.soccer_league_form', $data);
  101. } else {
  102. $model = new \App\Models\SoccerLeague();
  103. $model->name_chinese = $req->input('name_chinese');
  104. $model->country_id = $req->input('country_id');
  105. $model->area_id = $req->input('area_id');
  106. $model->status = $req->input('status');
  107. $model->lg_id = time();
  108. $model->utime = date('Y-m-d H:i:s',time());
  109. $model->source = 'user-defined';
  110. $db = new \App\Models\Stzqlocalleague();
  111. $db->source = 'user-defined';
  112. $db->lg_id = $model->lg_id;
  113. $model->save();
  114. $db->save();
  115. return responseToJson(1);
  116. }
  117. }
  118. function view(Req $req) {
  119. return $this->edit($req);
  120. }
  121. /**
  122. *修改联赛信息(地区,国家)
  123. */
  124. function edit(Req $req) {
  125. $id = $req->id;
  126. if (intval($id) < 1) {
  127. return -1;
  128. }
  129. if (!$req->isMethod('post')) {
  130. $areas = $this->getarea();
  131. if (!$areas) {
  132. return -2;
  133. }
  134. $data = \App\Models\SoccerLeague::where('id',$id)->first();
  135. $areaname = \App\Models\StAreaCountry::where('id',$data->area_id)->first();
  136. $countryname = \App\Models\StAreaCountry::where('id',$data->country_id)->first();
  137. if(!empty($areaname)){
  138. $data->area = $areaname->name;
  139. }
  140. if(!empty($countryname)){
  141. $data->country = $countryname->name;
  142. }
  143. $data = $data->toArray();
  144. $data['area'] = $areas;
  145. return view('sports.soccer_league_form', $data);
  146. } else {
  147. $model = new \App\Models\SoccerLeague();
  148. $model->id = $req->input('id');
  149. $model = $model::find($model->id);
  150. if(!empty($req->input('country_id'))){
  151. $model->country_id = $req->input('country_id');
  152. }else{
  153. $model->country_id = 0;
  154. }
  155. if(!empty($req->input('area_id'))){
  156. $model->area_id = $req->input('area_id');
  157. }else{
  158. $model->area_id = 0;
  159. }
  160. $model->status = $req->input('status');
  161. $model->utime = date('Y-m-d H:i:s',time());
  162. $model->save();
  163. return responseToJson(1);
  164. }
  165. }
  166. /**
  167. *删除联赛
  168. */
  169. public function delete(Req $req) {
  170. $id = $req->input('id');
  171. if (empty($id)) {
  172. return responseToJson(-2001); //id???????
  173. }
  174. $ids = explode(',', $id);
  175. if (!is_array($ids) && intval($ids) < 0) {
  176. return responseToJson(-2002); //id????
  177. }
  178. $id = array();
  179. $localleague = \App\Models\Stzqlocalleague::get();
  180. if (is_array($ids) && count($ids) > 0) {
  181. foreach ($ids as $k => $v) {
  182. if (intval($v) < 1) {
  183. unset($ids[$k]);
  184. }
  185. $league = \App\Models\SoccerLeague::where('id',$v)->first();
  186. for($i=0;$i<count($localleague);$i++){
  187. if($localleague[$i]->lg_id == $league->lg_id){
  188. $id[] = $localleague[$i]->id;
  189. }
  190. }
  191. }
  192. }
  193. $rows = \App\Models\SoccerLeague::whereIn('id', $ids)->delete();
  194. if (!$rows) {
  195. return responseToJson(-2003); //id????
  196. }
  197. if(count($id)>0) {
  198. $row = \App\Models\Stzqlocalleague::whereIn('id', $id)->delete();
  199. if (!$row) {
  200. return responseToJson(-2003); //id????
  201. }
  202. }
  203. return responseToJson(1, trans('menu.delete_success')); //id????
  204. }
  205. }