Welfare.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <?php
  2. /**
  3. * 前台注册用户管理控制器
  4. */
  5. namespace app\guildapi\controller;
  6. use app\common\model\Channel;
  7. use app\service\WelfareService;
  8. use think\Db;
  9. use think\Exception;
  10. use app\common\logic\Member as MemberService;
  11. use app\common\library\MakeReport;
  12. class Welfare extends Guild
  13. {
  14. protected $channelList = [];
  15. protected function _initialize()
  16. {
  17. parent::_initialize();
  18. if (!is_array($this->channelIds)) {
  19. $this->channelList = (new Channel())->channelListById($this->channelIds);
  20. } else {
  21. $this->channelList = (new Channel())->channelList($this->_channelIdPath);
  22. }
  23. }
  24. public function welfareGrantList()
  25. {
  26. // $checkResult = $this->validate($this->input, 'Welfare.enterGameWelfare');
  27. //
  28. // if (true !== $checkResult) {
  29. // $this->jsonResult('', 20013, $checkResult);
  30. // }
  31. $data = $this->input;
  32. $welfareService = new WelfareService();
  33. if (!is_array($this->channelIds)) {
  34. $channelIds = [$this->channelIds];
  35. } else {
  36. $channelIds = $this->channelIds;
  37. }
  38. $result = $welfareService->welfareGrantList($data, $channelIds, $this->channelList);
  39. if ($result['code'] == 20000) {
  40. $this->jsonResult(['data' => $result['data']], 20000, '获取列表成功');
  41. } else {
  42. $this->jsonResult([], 20013, $result['msg']);
  43. }
  44. }
  45. public function getGameWelfareList()
  46. {
  47. if (!isset($this->input['grant_type_id'])) {
  48. $this->jsonResult([], 20013, '类型错误');
  49. }
  50. switch ($this->input['grant_type_id']) {
  51. case 1:
  52. $checkResult = $this->validate($this->input, 'Welfare.enterGameWelfare');
  53. break;
  54. case 2:
  55. $checkResult = $this->validate($this->input, 'Welfare.everydayWelfare');
  56. break;
  57. case 3:
  58. $checkResult = $this->validate($this->input, 'Welfare.singleWelfare');
  59. break;
  60. case 4:
  61. $checkResult = $this->validate($this->input, 'Welfare.grandWelfare');
  62. break;
  63. case 5:
  64. $checkResult = $this->validate($this->input, 'Welfare.singleGrandWelfare');
  65. break;
  66. case 6:
  67. $checkResult = $this->validate($this->input, 'Welfare.sevenDayWelfare');
  68. break;
  69. case 7:
  70. $checkResult = $this->validate($this->input, 'Welfare.initialWelfare');
  71. break;
  72. case 8:
  73. $checkResult = $this->validate($this->input, 'Welfare.monthWelfare');
  74. break;
  75. case 9:
  76. $checkResult = $this->validate($this->input, 'Welfare.weekWelfare');
  77. break;
  78. default:
  79. $this->jsonResult([], 20013, '类型错误');
  80. }
  81. if (true !== $checkResult) {
  82. $this->jsonResult('', 20013, $checkResult);
  83. }
  84. $data = $this->input;
  85. $welfareService = new WelfareService();
  86. if (!is_array($this->channelIds)) {
  87. $channelIds = [$this->channelIds];
  88. } else {
  89. $channelIds = $this->channelIds;
  90. }
  91. $result = $welfareService->wefare($data['grant_type_id'], $data['game_id'], $channelIds, $this->channelList, $data['page'], $data['pageSize'], $data, false);
  92. if ($result['code'] == 20000) {
  93. $this->jsonResult(['data' => $result['data'],'a'=>$this->channelIds,'b'=>$this->_channelIdPath], 20000, '获取列表成功');
  94. } else {
  95. $this->jsonResult([], 20013, $result['msg']);
  96. }
  97. }
  98. public function applyWelfare()
  99. {
  100. if (!isset($this->input['grant_type_id'])) {
  101. $this->jsonResult([], 20013, '类型错误');
  102. }
  103. switch ($this->input['grant_type_id']) {
  104. case 1:
  105. $checkResult = $this->validate($this->input, 'Welfare.applyEnterGameWelfare');
  106. break;
  107. case 2:
  108. $checkResult = $this->validate($this->input, 'Welfare.applyEverydayWelfare');
  109. break;
  110. case 3:
  111. $checkResult = $this->validate($this->input, 'Welfare.applySingleWelfare');
  112. break;
  113. case 4:
  114. $checkResult = $this->validate($this->input, 'Welfare.applyGrandWelfare');
  115. break;
  116. case 5:
  117. $checkResult = $this->validate($this->input, 'Welfare.applySingleGrandWelfare');
  118. break;
  119. case 6:
  120. $checkResult = $this->validate($this->input, 'Welfare.applySevenDayWelfare');
  121. break;
  122. case 7:
  123. $checkResult = $this->validate($this->input, 'Welfare.applyInitialWelfare');
  124. break;
  125. case 8:
  126. $checkResult = $this->validate($this->input, 'Welfare.applyMonthWelfare');
  127. break;
  128. case 9:
  129. $checkResult = $this->validate($this->input, 'Welfare.applyWeekWelfare');
  130. break;
  131. default:
  132. $this->jsonResult([], 20013, '类型错误');
  133. }
  134. if (true !== $checkResult) {
  135. $this->jsonResult('', 20013, $checkResult);
  136. }
  137. $data = $this->input;
  138. $page = isset($data['page']) ? $data['page'] : 1;
  139. $pageSize = isset($data['pageSize']) ? $data['pageSize'] : 10;
  140. $welfareService = new WelfareService();
  141. if (!is_array($this->channelIds)) {
  142. $channelIds = [$this->channelIds];
  143. } else {
  144. $channelIds = $this->channelIds;
  145. }
  146. $result = $welfareService->wefare($data['grant_type_id'], $data['game_id'],$channelIds, $this->channelList, $page, $pageSize, $data, true);
  147. if ($result['code'] == 20000) {
  148. $this->jsonResult([], 20000, '申请成功');
  149. } else {
  150. $this->jsonResult([], 20013, $result['msg']);
  151. }
  152. }
  153. public function getGameServer()
  154. {
  155. $game_id = $this->input('game_id', 0);
  156. if (!$game_id) {
  157. $this->jsonResult('', 20013, '请先选择游戏');
  158. }
  159. $list = model('GameServer')->where(['game_id' => $game_id])->field('id,servername as value,create_time')->order('id desc')->select();
  160. if ($this->input('grant_type_id') == 6) {
  161. foreach ($list as $k => $v) {
  162. $list[$k]['value'] = $v['value'] . ' (开服时间:' . date('Y-m-d', $v['create_time']) . ')';
  163. }
  164. }
  165. $this->jsonResult(['data' => $list], 20000, '获取列表成功');
  166. }
  167. public function getChannelList()
  168. {
  169. $this->jsonResult(['data' => $this->channelList], 20000, '获取列表成功');
  170. }
  171. public function getWelfareGameList()
  172. {
  173. if($this->_channelLevel == 0){
  174. $meue['game_list'] = model('Common/Game')->getAllByCondition('id,name', ['game_kind' => 1, 'cooperation_status' => ['neq', 0], 'is_welfare' => 2], 'id desc', 'self');
  175. }else if($this->_channelLevel == 1){
  176. $channelGame = model('common/ChannelGame')->where(['channel_id'=>$this->_channelId])->column('game_id');
  177. }else {
  178. $channel = model('common/Channel')->field('id')->whereIn('id',$this->_channelIdPath)->where(['level'=>1])->find();
  179. $channelGame = model('common/ChannelGame')->where(['channel_id'=>$channel['id']])->column('game_id');
  180. }
  181. if(!$channelGame){
  182. $meue['game_list'] = model('Common/Game')->where(['game_kind'=>1, 'is_welfare' => 2])
  183. ->whereOr(['cooperation_status'=>1, 'is_welfare' => 2])->field('id,name')->select();
  184. }
  185. $where = ['cooperation_status'=>2,'id'=>['in',$channelGame], 'is_welfare' => 2];
  186. $meue['game_list'] = model('Common/Game')->where(['game_kind'=>1, 'is_welfare' => 2])
  187. ->where(['cooperation_status'=>1])->whereOr(function($query) use($where){
  188. $query->where($where);
  189. } )->field('id,name')->order('id desc')->select();
  190. $this->jsonResult($meue, 20000, '获取搜索菜单列表成功');
  191. }
  192. public function getWelfareList()
  193. {
  194. $game_id = $this->input('game_id', 0);
  195. $grant_type_id = $this->input('grant_type_id', 0);
  196. $is_show = $this->input('is_show', 0);
  197. if ($list = model('Welfare')
  198. ->where(function ($query) use ($grant_type_id,$is_show) {
  199. if ($grant_type_id > 0) {
  200. $query->where('grant_type_id', $grant_type_id);
  201. }
  202. if($is_show == 0){
  203. $query->where('is_show',1);
  204. }
  205. })
  206. ->whereRaw(sprintf('FIND_IN_SET(%s,game_id)', $game_id))->field('id,name as value')->select()) {
  207. $this->jsonResult($list, 20000, '获取列表成功');
  208. } else {
  209. $this->jsonResult([], 20013, '暂未配置福利');
  210. }
  211. }
  212. public function getWelfareGrantData()
  213. {
  214. $welfare_grant_id = $this->input('welfare_grant_id', 0);
  215. $pageSize = $this->input('pageSize', 10);
  216. $page = $this->input('page', 1);
  217. $status = $this->input('status', 0);
  218. $where = [];
  219. if ($status > 0) {
  220. $where['a.status'] = $status;
  221. }
  222. if ($list = model('welfareGrantData')
  223. ->alias('a')
  224. ->join('cy_welfare_resources b', 'a.welfare_resources_id=b.id')
  225. ->where('welfare_grant_id', $welfare_grant_id)
  226. ->where($where)
  227. ->order('grant_date asc,grant_time desc')
  228. ->field('a.*,b.type_id,b.name')->paginate(['list_rows' => $pageSize, 'page' => $page])
  229. ->toArray()) {
  230. foreach ($list['data'] as $k => $v) {
  231. $list['data'][$k]['type_name'] = $v['type_id'] == 1 ? '接口发放' : '兑换码发放';
  232. $list['data'][$k]['status_str'] = $v['status'] == 1 ? '未发放' : '已发放';
  233. }
  234. $this->jsonResult($list, 20000, '获取列表成功');
  235. } else {
  236. $this->jsonResult([], 20013, '暂未配置福利');
  237. }
  238. }
  239. }