GameRestrict.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <?php
  2. /**
  3. * 游戏管理控制器
  4. */
  5. namespace app\admin\controller;
  6. use app\common\library\FileUpload;
  7. use app\common\library\MakeReport;
  8. use app\common\model\Game as GameModel;
  9. use app\common\model\GameInfo;
  10. use app\common\model\GameRestrict as GameRestrictModel;
  11. use Overtrue\Pinyin\Pinyin;
  12. use think\Db;
  13. use think\Exception;
  14. class GameRestrict extends Admin
  15. {
  16. protected $gameModel;
  17. /**
  18. * 不进行父类的登录验证,所以增加构造方法重写了父类的初始化方法
  19. */
  20. protected function _initialize()
  21. {
  22. parent::_initialize();
  23. $this->gameModel = new GameModel;
  24. $this->gameList = $gameList = model('Common/Game')->getAllByCondition('id,name');
  25. $tmpSelfGameList = model('Common/Game')->getAllByCondition('id,name', [],'','self');
  26. $selfGameList = array();
  27. foreach ($tmpSelfGameList as $game) {
  28. $selfGameList[ $game['id']] = $game;
  29. }
  30. $this->selfGameList = $selfGameList;
  31. }
  32. /**
  33. * 未成年限制列表
  34. */
  35. public function index()
  36. {
  37. $restrict = new GameRestrictModel;
  38. $where = [];
  39. //游戏名称
  40. if (input('request.game_id') != '') {
  41. $where['n.game_id'] = input('request.game_id', '', 'trim');
  42. }
  43. //标题
  44. if (input('request.restrict_type') != '') {
  45. $where['n.restrict_type'] = input('request.restrict_type', '', 'trim');
  46. }
  47. //冻结类型
  48. if(input('request.restrict_type') == 'realname'){
  49. if (input('request.realname_restrict_status') != '') {
  50. $where['n.restrict_status'] = input('request.realname_restrict_status', '', 'trim');
  51. }
  52. }
  53. else if(input('request.restrict_type') == 'preventhook'){
  54. if (input('request.preventhook_restrict_status') != '') {
  55. $where['n.restrict_status'] = input('request.preventhook_restrict_status', '', 'trim');
  56. }
  57. }
  58. else{
  59. if (input('request.restrict_status') != '') {
  60. $where['n.restrict_status'] = input('request.restrict_status', '', 'trim');
  61. }
  62. }
  63. $start = $this->request->param('start');
  64. $end = $this->request->param('end');
  65. //开始时间和结束时间不为空时
  66. if ($start != '' && $end != '') {
  67. $where['n.create_time'] = [
  68. ['>=', strtotime($start)],
  69. ['<=', strtotime($end . ' 23:59:59')],
  70. ];
  71. } //开始时间不为空时
  72. elseif ($start != '') {
  73. $where['n.create_time'] = ['>=', strtotime($start)];
  74. } //结束时间不为空时
  75. elseif ($end != '') {
  76. $where['n.create_time'] = ['<=', strtotime($end . ' 23:59:59')];
  77. } else {
  78. /*
  79. $start = date('Y-m-d', time());
  80. $end = date('Y-m-d', time());
  81. $where['n.create_time'] = [
  82. ['>=', strtotime($start)],
  83. ['<=', strtotime($end . ' 23:59:59')],
  84. ];
  85. */
  86. }
  87. //查询参数
  88. $param = input('get.');
  89. $restrict = $restrict->alias('n')->field('n.*,g.name game_name,adm.username add_user_name,adm2.username update_user_name')->join('cy_game g', 'g.id=n.game_id', 'left')->join('cy_admin adm', 'n.add_user_id=adm.id', 'left')->join('cy_admin adm2', 'n.update_user_id=adm2.id', 'left')
  90. ->where($where)->order('n.create_time desc')
  91. ->paginate(10, false, array('query' => $param));
  92. // echo $restrict->getLastSql()."----getLastSql------<Br>";
  93. $this->assign('restrict', $restrict);
  94. $this->assign('page', $restrict->render());
  95. $gameList = $this->selfGameList;
  96. $gameList[0] = array('id'=>0,'name'=>'所有游戏');
  97. $this->assign('gameList',$gameList);
  98. return $this->fetch();
  99. }
  100. /**
  101. * 删除
  102. *
  103. */
  104. public function delete()
  105. {
  106. $id = input('id', 0, 'intval');
  107. if (empty($id)) $this->error('删除记录的ID不能为空');
  108. $restrict = new GameRestrictModel;
  109. if ($restrict->where(['id' => $id])->delete()) {
  110. $this->success('删除成功');
  111. } else {
  112. $this->error('删除失败');
  113. }
  114. }
  115. /**
  116. * 新增
  117. */
  118. public function add()
  119. {
  120. if (request()->isPost()) {
  121. $restrict = new GameRestrictModel;
  122. $data = [
  123. 'game_id' => input('post.game_id', '', 'trim'),
  124. 'restrict_type' => input('post.restrict_type','','trim'),
  125. 'restrict_status' => input('post.restrict_status','','intval'),
  126. ];
  127. if($data['restrict_type'] == 'realname'){
  128. $data['restrict_status'] = input('post.realname_restrict_status','', 'intval');
  129. }
  130. else{
  131. $data['restrict_status'] = input('post.preventhook_restrict_status','', 'intval');
  132. }
  133. $result = $this->validate($data, [
  134. ['game_id', 'require|integer', '请选择游戏|游戏ID必须为整型'],
  135. ['restrict_type', 'require', '请选择限制类型'],
  136. ['restrict_status', 'require', '请选择限制状态'],
  137. ]);
  138. if (true !== $result) {
  139. $this->error($result);
  140. }
  141. //检查是否已存在记录
  142. $condis = array();
  143. $condis['game_id'] = intval($data['game_id']);
  144. $condis['restrict_type'] = $data['restrict_type'];
  145. $restrictInfo = $restrict->where($condis)->find();
  146. if(!empty($restrictInfo)){
  147. $this->error('已添加过该游戏限制类型!');
  148. }
  149. $data['create_time'] = time();
  150. $data['add_user_id'] = session('ADMIN_ID');
  151. $data['update_time'] = time();
  152. $data['update_user_id'] = session('ADMIN_ID');
  153. if ($restrict->insert($data)) $this->success('新增成功', 'GameRestrict/index'); else
  154. $this->error('新增失败');
  155. }
  156. $game_list = array(array('id'=>0,'name'=>'所有游戏'));
  157. $game_list = array_merge($game_list,$this->selfGameList);
  158. $this->assign('game_list', $game_list);
  159. return $this->fetch();
  160. }
  161. /**
  162. * 编辑
  163. */
  164. public function edit()
  165. {
  166. $id = input('id', 0, 'intval');
  167. $restrictModel = new GameRestrictModel;
  168. if (empty($id)) $this->error('游戏冻结的ID不能为空');
  169. $restrictInfo = $restrictModel->where(['id' => $id])->find();
  170. if (empty($restrictInfo)) $this->error('记录不存在');
  171. if (request()->isPost()) {
  172. $restrict = new GameRestrictModel;
  173. $data = [
  174. 'game_id' => input('post.game_id', '', 'intval'),
  175. 'restrict_type' => input('post.restrict_type'),
  176. 'restrict_status' => input('post.restrict_status','', 'intval'),
  177. ];
  178. if($data['restrict_type'] == 'realname'){
  179. $data['restrict_status'] = input('post.realname_restrict_status','', 'intval');
  180. }
  181. else{
  182. $data['restrict_status'] = input('post.preventhook_restrict_status','', 'intval');
  183. }
  184. $result = $this->validate($data, [
  185. ['game_id', 'require|integer', '请选择游戏|游戏ID必须为整型'],
  186. ['restrict_type', 'require', '请选择限制类型'],
  187. ['restrict_status', 'require', '请选择限制状态'],
  188. ]);
  189. $data['update_time'] = time();
  190. $data['update_user_id'] = session('ADMIN_ID');
  191. if (true !== $result) {
  192. $this->error($result);
  193. }
  194. //检查是否已存在记录
  195. $condis = array();
  196. $condis['game_id'] = intval($data['game_id']);
  197. $condis['restrict_type'] = $data['restrict_type'];
  198. $condis['id'] = array('neq',$id);
  199. $restrictInfo = model('GameRestrict')->where($condis)->find();
  200. if(!empty($restrictInfo)){
  201. $this->error('已存在该游戏限制类型!');
  202. }
  203. if ($restrictModel->update($data, ['id' => $id])) {
  204. $this->success('编辑成功', 'GameRestrict/index');
  205. } else
  206. $this->error('编辑失败');
  207. }
  208. $game_list = array(array('id'=>0,'name'=>'所有游戏'));
  209. $game_list = array_merge($game_list,$this->selfGameList);
  210. $this->assign('game_list', $game_list);
  211. $this->assign('data', $restrictInfo);
  212. return $this->fetch();
  213. }
  214. /**
  215. * 防沉迷规则说明
  216. */
  217. public function restrictExplain(){
  218. if($this->request->isGet()){
  219. $info = model('Setting')->where(['name'=>'GAME_RESTRICT_EXPLAIN'])->field('value')->find()['value'];
  220. $this->assign('info',$info);
  221. return $this->fetch('restrictExplain');
  222. }
  223. if ($this->request->isPost()){
  224. $content = input('post.content');
  225. // 写入配置表
  226. model('Setting')->save(['value'=>$content],['name'=>'GAME_RESTRICT_EXPLAIN']);
  227. $this->success('设置成功','restrictExplain');
  228. }
  229. }
  230. }