WelfareVoluntarily.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\library\OneFileUpload;
  4. use app\common\logic\Member as MemberService;
  5. use think\Loader;
  6. use think\Db;
  7. class WelfareVoluntarily extends Admin
  8. {
  9. private $type = [
  10. 1 => '订单回调',
  11. 2 => '定时每1分钟',
  12. 3 => '定时每5分钟',
  13. 4 => '定时每10分钟',
  14. 5 => '定时每30分钟',
  15. 6 => '定时每1小时',
  16. 7 => '定时每日凌晨1点',
  17. 8 => '定时每日凌晨5点'
  18. ];
  19. /**
  20. *玩家福利类型列表
  21. */
  22. public function index()
  23. {
  24. $where = [];
  25. $order = 'id desc';
  26. $tmpGameList = model('Common/Game')->getAllByCondition('id,name', ['is_welfare' => 2]);
  27. $gameList = array();
  28. foreach ($tmpGameList as $game) {
  29. $gameList[$game['id']] = $game;
  30. }
  31. //查询参数
  32. $game_id = $this->request->get('game_id', '', 'trim');
  33. $welfare = model('Welfare')
  34. ->order('id desc')->column('name', 'id');
  35. $welfareModel = model('common/WelfareVoluntarily');
  36. $list = $welfareModel->where(function ($query) use ($game_id) {
  37. if (isset($game_id) && !empty($game_id)) {
  38. $query->whereRaw(sprintf('FIND_IN_SET(%s,game_id)', $game_id));
  39. }
  40. })
  41. ->order($order)
  42. ->paginate(10, false, ['query' => input('get.')])->each(function ($item, $key) use ($gameList) {
  43. $game_ids = explode(',', $item['game_id']);
  44. $tmp = [];
  45. foreach ($game_ids as $k => $v) {
  46. $tmp[] = $gameList[$v]['name'];
  47. }
  48. $item['game_name'] = implode('<br>', $tmp);
  49. return $item;
  50. });
  51. $this->assign('welfare', $welfare);
  52. $this->assign('grant_type_ids', model('Welfare')->grant_type_id);
  53. $this->assign('list', $list);
  54. $this->assign('game_list', $tmpGameList);
  55. $this->assign('page', $list->render());
  56. $this->assign('type', $this->type);
  57. return $this->fetch();
  58. }
  59. public function add()
  60. {
  61. if ($this->request->isPost()) {
  62. $data = $this->request->post();
  63. if (!$data['game_id']) {
  64. $this->error('游戏不能为空');
  65. }
  66. if (!$data['grant_type_id'] && $data['grant_type_id'] < 1) {
  67. $this->error('福利类型不能为空');
  68. }
  69. if (!isset($data['welfare_id']) && $data['welfare_id'] < 1) {
  70. $this->error('福利不能为空');
  71. }
  72. // if (!$data['condition']) {
  73. // $this->error('条件不能为空');
  74. // }
  75. unset($data['select']);
  76. $data['create_time'] = time();
  77. if (model('common/WelfareVoluntarily')->insertGetId($data)) {
  78. $this->success('添加成功', url('index'));
  79. }
  80. $this->error('添加失败');
  81. }
  82. $gameList = model('Common/Game')->getAllByCondition('id,name', ['is_welfare' => 2]);
  83. $this->assign('game_list', $gameList);
  84. $this->assign('type', $this->type);
  85. $this->assign('grant_type_ids', model('Welfare')->grant_type_id);
  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/WelfareVoluntarily');
  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. }