ChannelGame.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace app\admin\controller;
  3. class ChannelGame extends Admin
  4. {
  5. public function index(){
  6. $channelId = input('channel_id');
  7. $gameId = input('game_id');
  8. $where = [];
  9. if ($channelId) {
  10. $where['channel_id'] = ['in',$channelId];
  11. }
  12. if ($gameId) {
  13. $where['game_id'] = ['in',$gameId];
  14. }
  15. $list = model('common/ChannelGame')
  16. ->where($where)
  17. ->order("id DESC")
  18. ->paginate(10, false, ['query' =>input()]);
  19. // 获取分页显示
  20. $page = $list->render();
  21. $tmpGameList = model('Common/Game')->field('id,name')->order('id desc')->select();
  22. $gameList = array();
  23. foreach ($tmpGameList as $game) {
  24. $gameList[$game['id']] = $game;
  25. }
  26. $this->assign('gameArr', $tmpGameList);
  27. $this->assign('game_list', $gameList);
  28. $channels = model('common/Channel')->field('id,name')->where(['level'=>1,'status'=>1])->select();
  29. $channelList = array();
  30. foreach ($channels as $game) {
  31. $channelList[$game['id']] = $game;
  32. }
  33. $this->assign('channels', $channels);
  34. $this->assign('channelList', $channelList);
  35. $this->assign('channel_id', $channelId);
  36. $this->assign('game_id', $gameId);
  37. $this->assign("page", $page);
  38. $this->assign("list", $list);
  39. return $this->fetch();
  40. }
  41. public function add(){
  42. if ($this->request->isPost()) {
  43. $gameIds = input('game_id','');
  44. if(!$gameIds){
  45. $this->error('请选择游戏');
  46. }
  47. $channelIds = input('channel_id','');
  48. if(!$channelIds){
  49. $this->error('请选择会长');
  50. }
  51. $data = [];
  52. foreach (explode(',',$gameIds) as $k=>$v){
  53. foreach (explode(',',$channelIds) as $kk=>$vv){
  54. if (!$info = model('Common/ChannelGame')->where(['game_id'=>$v,'channel_id'=>$vv])->find()) {
  55. $data[] = [
  56. 'game_id'=>$v,
  57. 'channel_id'=>$vv,
  58. 'create_time'=>time(),
  59. ];
  60. }
  61. }
  62. }
  63. if(!$data){
  64. $this->error('无可添加记录');
  65. }
  66. if(model('common/ChannelGame')->insertAll($data)){
  67. $this->success('添加成功', url('index'));
  68. }else{
  69. $this->error('添加失败');
  70. }
  71. }
  72. $games = model('Common/Game')->getAllByCondition('id,name', ['cooperation_status' => ['neq', 3]], 'id desc', 'self');
  73. $this->assign('games', $games);
  74. $channels = model('common/Channel')->field('id,name')->where(['level'=>1,'status'=>1])->select();
  75. $this->assign('channels', $channels);
  76. return $this->fetch();
  77. }
  78. /**
  79. *删
  80. */
  81. public function delete()
  82. {
  83. $id = $this->request->param('id', '', 'intval');
  84. if (empty($id)) {
  85. $this->error('参数错误!');
  86. }
  87. $channelGameModel = model('Common/ChannelGame');
  88. if (!$info = $channelGameModel->find($id)) {
  89. $this->error('参数错误,不存在该数据');
  90. }
  91. if ($channelGameModel->where('id', '=', $id)->delete()) {
  92. $this->success('删除成功', url('index'));
  93. }
  94. $error = $channelGameModel->getError();
  95. $this->error($error ?: '删除失败');
  96. }
  97. }