Business.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Loader;
  4. use think\Db;
  5. class Business extends Admin
  6. {
  7. protected $gameList;
  8. public function _initialize()
  9. {
  10. parent::_initialize(); // TODO: Change the autogenerated stub
  11. }
  12. public function index(){
  13. $where = [];
  14. $order = 'id desc';
  15. $adminList = model('common/Admin')->alias('a')->join('nw_admin_role_user b','a.id=b.user_id')->field('a.id,a.username')->where(['b.role_id'=>['in',[12,17,18]]])->order('a.id desc')->column('a.username','a.id');
  16. $channelList = model('common/Channel')->where(['level'=>0])->order('id desc')->column('name','id');
  17. $business = model('common/Business');
  18. $list = $business
  19. ->order($order)
  20. ->paginate(10, false, ['query' => input('get.')])->each(function($item,$key) use ($channelList){
  21. $channel = explode(',',$item['channel_ids']);
  22. $tmp = [];
  23. foreach ($channel as $k=>$v){
  24. $tmp[] = $channelList[$v];
  25. }
  26. $item['channel'] = implode(',',$tmp);
  27. return $item;
  28. });
  29. $this->assign('adminList', $adminList);
  30. $this->assign('list', $list);
  31. $this->assign('page', $list->render());
  32. return $this->fetch();
  33. }
  34. public function add(){
  35. if ($this->request->isPost()) {
  36. $data = $this->request->post();
  37. if(!$data['select']){
  38. $this->error('请选择游戏');
  39. }
  40. if(model('common/Business')->where(['admin_id'=>$data['admin_id']])->find()){
  41. $this->error('用户已存在');
  42. }
  43. $data['channel_ids'] = $data['select'];
  44. unset($data['select']);
  45. $data['update_time'] = $data['create_time'] = time();
  46. $m = model('common/Business')->insertGetId($data);
  47. if (!empty($m)) {
  48. $this->success('添加成功', url('index'));
  49. }
  50. $this->error('添加失败');
  51. }
  52. $adminList = model('common/Admin')->alias('a')->join('nw_admin_role_user b','a.id=b.user_id')->where(['b.role_id'=>['in',[12,17,18]],'a.status'=>1])->field('a.id,a.username')->order('a.id desc')->select();
  53. $channelList = model('common/Channel')->where(['level'=>0,'status'=>1])->field('id,name')->order('id desc')->select();
  54. $this->assign('admin_list', $adminList);
  55. $this->assign('channel_list', $channelList);
  56. return $this->fetch();
  57. }
  58. public function edit(){
  59. $id = $this->request->param('id', '', 'intval');
  60. if (!$data = model('common/Business')->find($id)) {
  61. $this->error('参数错误,不存在该数据');
  62. }
  63. if ($this->request->isPost()) {
  64. if(model('common/Business')->where('admin_id','=',$data['admin_id'])->where('admin_id','<>',$data['admin_id'])->find()){
  65. $this->error('用户已存在');
  66. }
  67. $data = $this->request->post();
  68. if(!$data['select']){
  69. $this->error('请选择游戏');
  70. }
  71. $data['channel_ids'] = $data['select'];
  72. unset($data['select']);
  73. $data['update_time'] = $data['create_time'] = time();
  74. if (model('common/Business')->where(['id' => $id])->update($data)) {
  75. $this->success('修改成功', url('index'));
  76. } else {
  77. $this->error(model('common/Business')->getError() ?: '修改失败');
  78. }
  79. $this->error('修改失败');
  80. }
  81. $this->assign('data', $data);
  82. $adminList = model('common/Admin')->alias('a')->join('nw_admin_role_user b','a.id=b.user_id')->where(['b.role_id'=>['in',[12,17,18]],'a.status'=>1])->field('a.id,a.username')->order('a.id desc')->select();
  83. $channelList = model('common/Channel')->where(['level'=>0,'status'=>1])->field('id,name')->order('id desc')->select();
  84. $this->assign('admin_list', $adminList);
  85. $this->assign('channel_list', $channelList);
  86. return $this->fetch();
  87. }
  88. /**
  89. *删
  90. */
  91. public function delete()
  92. {
  93. $id = $this->request->param('id', '', 'intval');
  94. if (empty($id)) {
  95. $this->error('参数错误!');
  96. }
  97. $appModel =model('common/Business');
  98. if (!$appModel->find($id)) {
  99. $this->error('参数错误,不存在该数据');
  100. }
  101. if ($appModel->where('id', '=', $id)->delete()) {
  102. $this->success('删除成功', url('index'));
  103. }
  104. $error = $appModel->getError();
  105. $this->error($error ?: '删除失败');
  106. }
  107. }