Tiktok.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * 前台注册用户管理控制器
  4. */
  5. namespace app\admin\controller;
  6. use app\common\model\Members as MembersModel;
  7. use app\common\model\MembersTwo;
  8. use think\Db;
  9. use app\common\logic\Member as MemberService;
  10. use app\common\library\MakeReport;
  11. use app\common\library\FileUpload;
  12. use think\Exception;
  13. class Tiktok extends Admin
  14. {
  15. public function __construct()
  16. {
  17. parent::__construct();
  18. $tmpSelfGameList = model('Common/Game')->alias('g')->field('g.id,g.name')
  19. ->join('cy_gameinfo cgi', 'g.id=cgi.game_id')
  20. ->where(['platform' => 0])->order('id desc')->select();
  21. $selfGameList = array();
  22. foreach ($tmpSelfGameList as $game) {
  23. $selfGameList[$game['id']] = $game;
  24. }
  25. $game_list = array(array('id' => 0, 'name' => ''));
  26. $game_list = array_merge($game_list, $selfGameList);
  27. $this->assign('game_list', $game_list);
  28. }
  29. public function index()
  30. {
  31. $game_id = input('request.game_id', 0, 'intval');
  32. $where = [];
  33. //用户ID
  34. if ($game_id) {
  35. $where['game_id'] = $game_id;
  36. }
  37. $list = model("TiktokPush")->alias('t')
  38. ->field("t.*,g.name as gameGame,c.name as channelName")
  39. ->join('cy_game g', 'g.id=t.game_id', 'left')
  40. ->join('nw_channel c', 'c.id=t.channel_id', 'left')
  41. ->where($where)
  42. ->order('t.id desc')
  43. ->paginate(10, false, ['query' => input('get.')]);
  44. $data = $list->toArray()['data'];
  45. $this->assign('list', $data);
  46. $this->assign('total', $list->total()); //总条数
  47. $this->assign('page', $list->render());
  48. return $this->fetch();
  49. }
  50. public function add()
  51. {
  52. $channel = model('channel')->where(['level' => 3, 'status' => 1])->field('id,name')->select();
  53. $this->assign('channel', $channel);
  54. return $this->fetch();
  55. }
  56. public function save()
  57. {
  58. $game_id = input('game_id', 0, 'intval');
  59. $select = input('select', '');
  60. $ids = explode(',', $select);
  61. if (!$ids) {
  62. $this->error('推广id不存在');
  63. }
  64. $channel_ids = model('TiktokPush')->where('game_id', $game_id)->whereIn('channel_id', $ids)->column('channel_id');
  65. if ($channel_ids) {
  66. $ids = array_diff($ids, $channel_ids);
  67. }
  68. if(!$ids){
  69. $this->error('推广id已存在');
  70. }
  71. $data = [];
  72. foreach ($ids as $k => $v) {
  73. $data[] =[
  74. 'game_id'=>$game_id,
  75. 'channel_id'=>$v,
  76. ];
  77. }
  78. if(model('TiktokPush')->insertAll($data)){
  79. $this->success('保存成功', 'tiktok/index');
  80. }else{
  81. $this->error('保存成功');
  82. }
  83. }
  84. // 删除
  85. public function del()
  86. {
  87. $id = $this->request->param('id',0,'intval');
  88. if (!$id){
  89. $this->error('ID不能为空');
  90. }
  91. $res = model('TiktokPush')->where('id',$id)->delete();
  92. if ($res) {
  93. $this->success('删除成功', url('index'));
  94. }
  95. $this->error('删除失败');
  96. }
  97. }