ChannelManage.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\model\Channel;
  4. use app\common\library\FileUpload;
  5. use think\Db as DB;
  6. use GuzzleHttp\Client;
  7. use GuzzleHttp\Exception\GuzzleException;
  8. use think\Exception;
  9. class ChannelManage extends Admin
  10. {
  11. protected function _initialize()
  12. {
  13. parent::_initialize();
  14. $this->gameList = $gameList = model('Common/Game')->getAllByCondition('id,name');
  15. $tmpSelfGameList = model('Common/Game')->getAllByCondition('id,name', [],'','self');
  16. $selfGameList = array();
  17. foreach ($tmpSelfGameList as $game) {
  18. $selfGameList[ $game['id']] = $game;
  19. }
  20. $this->selfGameList = $selfGameList;
  21. }
  22. /**
  23. * 礼包列表
  24. * @return mixed
  25. */
  26. public function search()
  27. {
  28. $gameList = $this->selfGameList;
  29. $this->assign('game_list', $gameList);
  30. return $this->fetch();
  31. }
  32. //渠道修改页面
  33. public function change()
  34. {
  35. $game_list = model('Common/Game')->getAllByCondition('id,name');
  36. //外部渠道列表
  37. $outer_channel_list = model('Common/Channel')->getAllByCondition('id,name',['flag'=>3]);
  38. //内外部渠道列表
  39. $channel_list = model('Common/Channel')->getAllByCondition('id,name',['flag'=>['in','2,3'],'status' => 1]);
  40. $this->assign('game_list', $this->selfGameList);
  41. $this->assign('outer_channel_list', $outer_channel_list);
  42. $this->assign('channel_list', $channel_list);
  43. return $this->fetch();
  44. }
  45. /**
  46. * 查询渠道的父级渠道
  47. */
  48. public function queryParentChannelName()
  49. {
  50. $channel = input('post.channel', 0, 'intval');
  51. if (empty($channel)) {
  52. $this->error('查询的渠道不能为空');
  53. }
  54. $channel_info = model('channel')->where(['id' => $channel])->field('id,parent_id,name')->find();
  55. //查询父渠道名称
  56. if (empty($channel_info)) {
  57. $this->error('查询的渠道无父级渠道');
  58. }
  59. $parent_channel_name = model('channel')->where(['id' => $channel_info['parent_id']])->field('name')->find();
  60. if (empty($parent_channel_name)) {
  61. $this->error('查询父级渠道名称出错');
  62. }
  63. $this->success('ok', '', $parent_channel_name['name']);
  64. }
  65. /**
  66. * 修改指定渠道的父级,同时修正它的所有下级的id_path数据
  67. * @throws \think\db\exception\DataNotFoundException
  68. * @throws \think\db\exception\ModelNotFoundException
  69. * @throws \think\exception\DbException
  70. */
  71. public function ChangeChannelRelation()
  72. {
  73. die();
  74. $channel_id = input('channel_id', 0, 'intval'); // 要修改的渠道id
  75. $new_pid = input('new_pid', 0, 'intval'); // 要挂载到哪个渠道下
  76. if (empty($channel_id) || empty($new_pid)) {
  77. $this->error('填写完整信息');
  78. }
  79. if($channel_id == config('TOP_CHANNEL_ID')) {
  80. $this->error('顶级渠道不可修改');
  81. }
  82. $current_channel = model('channel')->where(['id' => $channel_id])->field('name,id_path,parent_id')->find();
  83. if (empty($current_channel)) {
  84. $this->error('渠道id错误');
  85. }
  86. // 先查出新的父级渠道的id_path信息,不然会导致层级错乱
  87. $new_parent = model('channel')->field('flag,name,id_path,point_show,taptap,show_full_account')->where(['id' => $new_pid])->find();
  88. if (empty($new_parent)) {
  89. $this->error('新的归属渠道信息错误,查无此渠道');
  90. }
  91. elseif($new_parent['flag']==4){
  92. $this->error('新的归属渠道不能为聚合渠道');
  93. }
  94. $channelIdList = get_child_channel_arr($channel_id);
  95. if (in_array($new_pid, $channelIdList)) {
  96. $this->error('禁止将子渠道改为归属渠道');
  97. }
  98. $new_data['parent_id'] = $new_pid;
  99. $new_data['id_path'] = ($new_parent['flag']==2) ? ','.$new_pid.',' : $new_parent['id_path'] . $new_pid . ',';
  100. // 判断是否要更改 渠道推广后台【游戏点位】和【游戏推荐】和用户账号显示明密文的菜单权限
  101. $point_show = $taptap = $show_full_account = 1;
  102. if ($new_parent['point_show'] == 0){
  103. $new_data['point_show'] = 0;
  104. $point_show = 0;
  105. }
  106. if ($new_parent['taptap'] == 0){
  107. $new_data['taptap'] = 0;
  108. $taptap = 0;
  109. }
  110. if ($new_parent['show_full_account'] == 0){
  111. $new_data['show_full_account'] = 0;
  112. $show_full_account = 0;
  113. }
  114. // 启动事务
  115. Db::startTrans();
  116. $result = true;
  117. /**
  118. * 新的上级渠道的 渠道推广后台【游戏点位】和【游戏推荐】的菜单权限 为显示状态,不去改变子渠道的菜单权限
  119. 要更改的渠道的子渠道 的 渠道推广后台【游戏点位】和【游戏推荐】的菜单权限,也一起发生变化
  120. * 父级某个菜单权限关闭,则所有子渠道该菜单权限关闭
  121. * 父级某个菜单权限开启,则所有子渠道的菜单权限不发生变化
  122. */
  123. if ($new_parent['point_show'] == 0 && $new_parent['taptap'] == 0 && $new_parent['show_full_account'] == 0){
  124. $channel_ChildArr = model('Channel')->getChildIds($channel_id);
  125. $list = ['id'=>$channel_id,'point_show'=>$point_show,'taptap'=>$taptap,'show_full_account'=>$show_full_account];
  126. foreach($channel_ChildArr as $v){
  127. $list[] = ['id'=>$v,'point_show'=>$point_show,'taptap'=>$taptap,'show_full_account'=>$show_full_account];
  128. }
  129. $result = model('Channel')->saveAll($list);
  130. }
  131. else if($new_parent['point_show'] == 0 && $new_parent['taptap'] == 0){
  132. $channel_ChildArr = model('Channel')->getChildIds($channel_id);
  133. $list = ['id'=>$channel_id,'point_show'=>$point_show,'taptap'=>$taptap];
  134. foreach($channel_ChildArr as $v){
  135. $list[] = ['id'=>$v,'point_show'=>$point_show,'taptap'=>$taptap];
  136. }
  137. $result = model('Channel')->saveAll($list);
  138. }
  139. else if($new_parent['point_show'] == 0 && $new_parent['show_full_account'] == 0){
  140. $channel_ChildArr = model('Channel')->getChildIds($channel_id);
  141. $list = ['id'=>$channel_id,'point_show'=>$point_show,'show_full_account'=>$show_full_account];
  142. foreach($channel_ChildArr as $v){
  143. $list[] = ['id'=>$v,'point_show'=>$point_show,'show_full_account'=>$show_full_account];
  144. }
  145. $result = model('Channel')->saveAll($list);
  146. }
  147. else if($new_parent['taptap'] == 0 && $new_parent['show_full_account'] == 0){
  148. $channel_ChildArr = model('Channel')->getChildIds($channel_id);
  149. $list = ['id'=>$channel_id,'taptap'=>$taptap,'show_full_account'=>$show_full_account];
  150. foreach($channel_ChildArr as $v){
  151. $list[] = ['id'=>$v,'taptap'=>$taptap,'show_full_account'=>$show_full_account];
  152. }
  153. $result = model('Channel')->saveAll($list);
  154. }
  155. elseif ($new_parent['point_show'] == 0){
  156. $channel_ChildArr = model('Channel')->getChildIds($channel_id);
  157. $list = ['id'=>$channel_id,'point_show'=>$point_show];
  158. foreach($channel_ChildArr as $v){
  159. $list[] = ['id'=>$v,'point_show'=>$point_show];
  160. }
  161. $result = model('Channel')->saveAll($list);
  162. }elseif ( $new_parent['taptap'] == 0){
  163. $channel_ChildArr = model('Channel')->getChildIds($channel_id);
  164. $list = ['id'=>$channel_id,'taptap'=>$taptap];
  165. foreach($channel_ChildArr as $v){
  166. $list[] = ['id'=>$v,'taptap'=>$taptap];
  167. }
  168. $result = model('Channel')->saveAll($list);
  169. }
  170. elseif ( $new_parent['show_full_account'] == 0){
  171. $channel_ChildArr = model('Channel')->getChildIds($channel_id);
  172. $list = ['id'=>$channel_id,'show_full_account'=>$show_full_account];
  173. foreach($channel_ChildArr as $v){
  174. $list[] = ['id'=>$v,'show_full_account'=>$show_full_account];
  175. }
  176. $result = model('Channel')->saveAll($list);
  177. }
  178. /**
  179. * 改渠道下的游戏补点 :
  180. * 是否有没有配置补点:若无,渠道转移成功;若有判断是否和上级发送冲突
  181. * 1、上级配置了:失效(需要判断生效时间和失效时间)
  182. * 2、上级未配置,不动补点规则
  183. */
  184. $pointRatioModel = model("GameExtraPointRatio");
  185. $point_ratio_arr = $pointRatioModel->where(['channel_id'=>$channel_id,'status'=>['in','0,1,2,3']])->field('id,year_month,begin_time,end_time,game_extra_point_id,game_id,status')->select();
  186. $run_point = true;
  187. if (count($point_ratio_arr)){
  188. // 获取今日00:00:00 时间戳
  189. $time_line = strtotime(date('Y-m-d',time()));
  190. // 判断 新上级是否配置 补点规则
  191. foreach ($point_ratio_arr as $v){
  192. $numArr = $pointRatioModel->where(['game_id'=>$v['game_id'],'year_month'=>$v['year_month'],'channel_id'=>['in',$new_data['id_path']],'game_extra_point_id'=>$v['game_extra_point_id']])->column('channel_id');
  193. // 新上级没有配置补点
  194. if ($run_point && !count($numArr)){
  195. break;
  196. }
  197. // status= 2 or 3 (有参与结算统计), 要区分实际正在生效、实际已失效、实际还未生效
  198. // 新上级配置补点,status = 0 OR 1 , 实际还未生效: 设为 5失效
  199. if ($run_point && ( $v['status'] == 0 || $v['status'] == 1 || $v['begin_time'] >= $time_line)){
  200. $run_point = $pointRatioModel->save(['status'=>5,'update_time'=>time(),'update_user'=>mg_get_current_admin_id()],['id'=>$v['id']]);
  201. $run_point = $run_point ? true : false;
  202. }
  203. // 实际正在生效 : 有参与结算,失效实际设为 $time_line-1 status=3
  204. if ($run_point && $v['begin_time'] < $time_line && $v['end_time'] >= $time_line){
  205. $run_point = $pointRatioModel->save(['end_time'=>$time_line-1,'status'=>3,'update_time'=>time(),'update_user'=>mg_get_current_admin_id()],['id'=>$v['id']]);
  206. $run_point = $run_point ? true : false;
  207. }
  208. // 实际已失效: 不参与结算,不另作 5失效处理
  209. /*if ($v['end_time'] < $time_line){
  210. }*/
  211. if (!$run_point){
  212. break;
  213. }
  214. }
  215. }
  216. // 更新当前渠道的记录
  217. if ($channel_result = model('channel')->where(['id' => $channel_id])->update($new_data) && $result && $run_point) {
  218. $old_name = model('channel')->field('name')->where(['id' => $current_channel['parent_id']])->find();
  219. $message = '渠道:' . $current_channel['name'] . ',归属渠道由:' . $old_name['name'] . ',修改至:' . $new_parent['name'];
  220. $this->insertLog($this->current_node, $message,24);
  221. // 提交事务
  222. Db::commit();
  223. $this->success('修改成功', '', $message);
  224. }
  225. // 回滚事务
  226. Db::rollback();
  227. $this->error('修改失败');
  228. }
  229. public function getSubMember()
  230. {
  231. $data = input('post.');
  232. $info = model('MemberChannelGame')->where(['username' => $data['username']])->field('id,channel_id')->find();
  233. if (!$info) {
  234. $this->jsonResult([], '当前玩家不存在!', -100);
  235. }
  236. $info = model('Subaccount')->where(['game_id' => $data['game_id'], 'member_id' => $info['id']])->field('id,sub_username')->find();
  237. if (!$info) {
  238. $this->jsonResult([], '当前玩家没有子账户!', -100);
  239. }
  240. $this->jsonResult(['channel_id' => $info[''], 'info' => $info], 'success', 200);
  241. }
  242. /**
  243. * 修改玩家游戏绑定渠道
  244. *
  245. * @throws \think\db\exception\DataNotFoundException
  246. * @throws \think\db\exception\ModelNotFoundException
  247. * @throws \think\exception\DbException
  248. */
  249. public function changeMemberRelationChannel()
  250. {
  251. $fileUpload = new FileUpload();
  252. $data = input('post.');
  253. $username = isset($data['username']) ? $data['username'] : '';
  254. $game_id = isset($data['game_id']) ? $data['game_id'] : '';
  255. $channel_name = isset($data['channel_name']) ? $data['channel_name'] : ''; // 渠道名称
  256. $channel_id = isset($data['channel_id']) ? $data['channel_id'] : ''; // 渠道id
  257. $remark = isset($data['remark']) ? $data['remark'] : ''; // 渠道id
  258. $type = isset($data['type']) ? $data['type'] : 1; // 换绑类型
  259. $action = $data['action'];
  260. $sub_id = isset($data['sub_id']) ? $data['sub_id'] : ''; // 子账户ID
  261. // halt($file);
  262. if (empty($username) || empty($game_id)) {
  263. $this->error('请填写玩家账号');
  264. }
  265. if (empty($game_id)) {
  266. $this->error('请选择对应游戏');
  267. }
  268. $memberModel = model("Members");
  269. $member_info = $memberModel->field('id,gameid,channel_id')->where('username', $username)->find();
  270. if (empty($member_info)) {
  271. $this->error('无该玩家账号信息');
  272. }
  273. $gameAccountInfo = model('Subaccount')->where(['game_id' => $game_id, 'member_id' => $member_info['id']])->field('id,sub_username')->find();
  274. if (empty($gameAccountInfo)) {
  275. $this->error('无关联的子账户信息!');
  276. }
  277. $cid = model('MemberChannelGame')->where(['member_id' => $member_info['id'], 'game_id' => $game_id])->column('channel_id');
  278. if (empty($cid)) {
  279. $this->error('无关联的渠道信息');
  280. }
  281. $condition['id'] = $cid[0];
  282. $channel_info = [];
  283. //查询渠道名称
  284. if ($action == 'query') {
  285. $status = 2;
  286. $channel_info = model('channel')->where($condition)->field('name')->find();
  287. // 查询子账户
  288. $this->success('ok', '', ['name' => $channel_info['name'], 'sub_info' => $gameAccountInfo ?? []]);
  289. }
  290. // halt($channel_id);
  291. //修改绑定的渠道
  292. if ($action == 'change') {
  293. if (empty($channel_id)) {
  294. $this->error('请选择新的渠道');
  295. }
  296. // $data['channel_id'] = $channel_id;
  297. $new_channel_info = model('Channel')->where(['id' => $channel_id])->field('name,level')->find();
  298. if($new_channel_info['level'] <> 3){
  299. $this->error('玩家只能换绑到推广员账号');
  300. }
  301. $old_channel_info = model('Channel')->where(['name' => $channel_name])->field('id,name,level')->find();
  302. if(!$old_channel_info){
  303. $this->error('玩家所属原推广员账号不存在');
  304. }
  305. $MemberChannelGameInfo = model('MemberChannelGame')->where(['member_id' => $member_info['id'], 'game_id' => $game_id])->find();
  306. if($MemberChannelGameInfo){
  307. if($MemberChannelGameInfo['channel_id'] == $channel_id){
  308. $this->error('玩家所属原推广员账号和要换绑的推广员账号相同,您未做任何绑定修改');
  309. }
  310. }
  311. else{
  312. $this->error('玩家尚未进入该游戏,不属于任何推广员');
  313. }
  314. $rebindApplyCnt = model('PlayerRebindApply')->where(['userid' => $member_info['id'],'game_id' => $game_id,'status' => 0])->count();
  315. if($rebindApplyCnt){
  316. $this->error('玩家在该游戏已存在待审核换绑申请,不能重复提交');
  317. }
  318. switch ($type) {
  319. case '1':
  320. $old_partent = ltrim(db::name('nw_channel')->where(['id'=>$cid[0]])->value('id_path'),',');
  321. $new_partent = ltrim(db::name('nw_channel')->where(['id'=>$channel_id])->value('id_path'),',');
  322. if (substr($old_partent,0,stripos($old_partent,','))!=substr($new_partent,0,stripos($new_partent,','))) {
  323. $this->error('必须在同一个联盟下');
  324. }
  325. $file1_path = $fileUpload->set('allowExt', 'jpg,jpeg,png')->set('maxsize', 1024000 * 3)->set('dir','image/changeBindPic/')->upload(request()->file('file1'));//公会或联盟同意换绑截图或不同B账户同属于他的说明
  326. if ( !$file1_path) {
  327. $this->error('附图上传失败,' . $fileUpload->getError());
  328. }
  329. break;
  330. case '2':
  331. $file1_path = $fileUpload->set('allowExt', 'jpg,jpeg,png')->set('maxsize', 1024000 * 3)->set('dir','image/changeBindPic/')->upload(request()->file('file1'));//发链接,带时间引导图
  332. if ( !$file1_path) {
  333. $this->error('附图1上传失败,' . $fileUpload->getError());
  334. }
  335. $file2_path = $fileUpload->set('allowExt', 'jpg,jpeg,png')->set('maxsize', 1024000 * 3)->set('dir','image/changeBindPic/')->upload(request()->file('file2'));//玩家说角色名图
  336. if ( !$file2_path) {
  337. $this->error('附图2上传失败,' . $fileUpload->getError());
  338. }
  339. $file3_path = $fileUpload->set('allowExt', 'jpg,jpeg,png')->set('maxsize', 1024000 * 3)->set('dir','image/changeBindPic/')->upload(request()->file('file3'));//原公会同意截图
  340. if ( !$file3_path) {
  341. $this->error('附图3上传失败,' . $fileUpload->getError());
  342. }
  343. break;
  344. case '3':
  345. $oldPoint = isset($data['oldPoint']) ? $data['oldPoint'] : ''; // 原点位
  346. $deductionAmount = isset($data['deductionAmount']) ? $data['deductionAmount'] : ''; // 扣款
  347. $newPoint = isset($data['newPoint']) ? $data['newPoint'] : ''; // 新点位
  348. $getAmount = isset($data['getAmount']) ? $data['getAmount'] : ''; // 打款金额
  349. $playerAmount = isset($data['playerAmount']) ? $data['playerAmount'] : ''; // 玩家产生流水
  350. if ($oldPoint === '' || $newPoint === '') {
  351. $this->error('请填写点位信息');
  352. }
  353. if ($deductionAmount === '' || $getAmount === '') {
  354. $this->error('请填写金额信息');
  355. }
  356. if ($playerAmount === '') {
  357. $this->error('请填写产生流水信息');
  358. }
  359. $file1_path = $fileUpload->set('allowExt', 'jpg,jpeg,png')->set('maxsize', 1024000 * 3)->set('dir','image/changeBindPic/')->upload(request()->file('file1'));//发链接,带时间引导图
  360. if ( !$file1_path) {
  361. $this->error('附图1上传失败,' . $fileUpload->getError());
  362. }
  363. $file2_path = $fileUpload->set('allowExt', 'jpg,jpeg,png')->set('maxsize', 1024000 * 3)->set('dir','image/changeBindPic/')->upload(request()->file('file2'));//玩家说角色名图
  364. if ( !$file2_path) {
  365. $this->error('附图2上传失败,' . $fileUpload->getError());
  366. }
  367. $file3_path = $fileUpload->set('allowExt', 'jpg,jpeg,png')->set('maxsize', 1024000 * 3)->set('dir','image/changeBindPic/')->upload(request()->file('file3'));//原公会同意截图
  368. if ( !$file3_path) {
  369. $this->error('附图3上传失败,' . $fileUpload->getError());
  370. }
  371. break;
  372. case '4':
  373. // $file1_path = $fileUpload->set('allowExt', 'jpg,jpeg,png')->set('maxsize', 1024000 * 3)->set('dir','image/changeBindPic/')->upload(request()->file('file1'));//公会或联盟同意换绑截图或不同B账户同属于他的说明
  374. // if ( !$file1_path) {
  375. // $this->error('附图上传失败,' . $fileUpload->getError());
  376. // }
  377. if(empty($remark)){
  378. $this->error("手动换绑备注必填");
  379. }
  380. break;
  381. default:
  382. $this->error('请选择绑定方式');
  383. break;
  384. }
  385. Db::startTrans();
  386. try{
  387. /*
  388. if ($result = model('MemberChannelGame')->where(['member_id' => $member_info['id'], 'game_id' => $game_id])->update($data)) {
  389. $gamename = get_game_name($game_id);
  390. $message = '玩家' . $username . ',在游戏:' . $gamename . '的归属渠道由:' . $channel_name . ',变更为:' . $new_channel_info['name'] . '的信息;';
  391. $this->insertLog($this->current_node, $message,24);
  392. // 插入玩家历史记录
  393. Db::table('cy_member_history')->insert([
  394. 'userid' => $member_info['id'],
  395. 'channel' => $gamename . "," . $new_channel_info['name'],
  396. 'ip' => request()->ip(),
  397. 'create_time' => time(),
  398. 'admin_id' => session('ADMIN_ID')
  399. ]);
  400. */
  401. $gamename = get_game_name($game_id);
  402. $message = '您的申请:玩家' . $username . ',在游戏"' . $gamename . '"的归属渠道由:"' . $channel_name . '",变更为"' . $new_channel_info['name'] . '" 已成功提交,请耐心等待审核;';
  403. $rebindData = array();
  404. $rebindData['userid'] = $member_info['id'];
  405. $rebindData['username'] = $username;
  406. $rebindData['game_id'] = $game_id;
  407. $rebindData['game_name'] = $gamename;
  408. $rebindData['origin_cuserid'] = $old_channel_info['id'];
  409. $rebindData['origin_cusername'] = $channel_name;
  410. $rebindData['cuserid'] = $channel_id;
  411. $rebindData['cusername'] = $new_channel_info['name'];
  412. $rebindData['create_time'] = time();
  413. $rebindData['cmmt'] = '后台管理员申请换绑';
  414. $rebindData['status'] = 0;
  415. $rebindData['sub_id'] = $sub_id;
  416. $rebindData['admin_id'] = session('ADMIN_ID');
  417. $rebindData['admin_name'] = session('USERNAME');
  418. $rebindData['remark'] = $remark;
  419. switch ($type) {
  420. case '1':
  421. $rebindData['picture1'] = $file1_path;
  422. break;
  423. case '2':
  424. $rebindData['picture1'] = $file1_path;
  425. $rebindData['picture2'] = $file2_path;
  426. $rebindData['picture3'] = $file3_path;
  427. break;
  428. case '3':
  429. $rebindData['picture1'] = $file1_path;
  430. $rebindData['picture2'] = $file2_path;
  431. $rebindData['picture3'] = $file3_path;
  432. $rebindData['oldPoint'] = floatval($oldPoint);
  433. $rebindData['deductionAmount'] = floatval($deductionAmount);
  434. $rebindData['newPoint'] = floatval($newPoint);
  435. $rebindData['getAmount'] = floatval($getAmount);
  436. $rebindData['playerAmount'] = floatval($playerAmount);
  437. break;
  438. }
  439. $insertRebindId = model('PlayerRebindApply')->insert($rebindData);
  440. // if($insertRebindId){
  441. // $template = '有新的玩家换绑申请:管理员 "'.session('USERNAME').'" 发起玩家换绑申请,请及时安排处理,时间:'.date('Y-m-d H:i:s');
  442. // $ddurl = OPERATE_DINGDING_URL;
  443. // curlDD($template, $ddurl,true);
  444. // }
  445. /*
  446. if($insertRebindId){
  447. $rebindPayFromTime = strtotime(date('Y-m-d',(time()-((date('w',time())==0?7:date('w',time()))-1)*24*3600)));
  448. $updPayData = array();
  449. $updPayData['channel_id'] = $rebindData['cuserid'];
  450. $updPayResult = model('Pay')->where(['userid' => $rebindData['userid'],'gameid' => $rebindData['game_id'],'channel_id' => $rebindData['origin_cuserid'],'create_time'=> ['egt', $rebindPayFromTime]])->update($updPayData);
  451. if ($updPayResult) {
  452. $message .= '该玩家本周后消费订单也已做换绑。';
  453. }
  454. }
  455. */
  456. Db::commit();
  457. /*
  458. }
  459. else{
  460. throw new Exception("您未做任何绑定修改");
  461. }
  462. */
  463. } catch (\Exception $e) {
  464. // 回滚事务
  465. Db::rollback();
  466. $this->error('玩家换绑操作失败'.$e->getMessage());
  467. }
  468. $this->success($message);
  469. }
  470. }
  471. /**
  472. * 渠道查询方法
  473. */
  474. public function queryChannelList()
  475. {
  476. $username = input('post.username', '', 'trim'); // 玩家账号
  477. $game_id = input('post.game_id', 0, 'intval');
  478. $channel = input('post.channel', 0, 'trim'); // 渠道名称
  479. $channel_id = input('post.channel_id', 0, 'intval'); // 渠道id
  480. $account_type = input('post.account_type', 0, 'trim');
  481. $channel_type = input('post.channel_type', 0, 'filterAndTrimInput'); // 按渠道信息查询时,按渠道名还是按渠道id
  482. $condition = $result = [];
  483. if ('channel' == $account_type) { //直接查询渠道信息
  484. if ('name' == $channel_type) {
  485. if (empty($channel)) {
  486. $this->error('渠道名不能为空');
  487. }
  488. $condition['name'] = $channel;
  489. $info = DB::table('nw_channel')->field('id')->where($condition)->find();
  490. if (empty($info)) {
  491. $this->error('渠道名对应的渠道商不存在');
  492. }
  493. $condition['id'] = $info['id'];
  494. }
  495. if ('id' == $channel_type) {
  496. if (empty($channel_id)) {
  497. $this->error('渠道ID不能为空');
  498. }
  499. $condition['id'] = $channel_id;
  500. }
  501. $result = get_channel_arr($condition['id']);
  502. if (empty($result)) {
  503. $this->error('无相关渠道信息');
  504. }
  505. }
  506. $memberModel = model("Members");
  507. if ('player' == $account_type) { // 通过关联关系查询渠道信息
  508. if (empty($username) || empty($game_id)) {
  509. $this->error('玩家账号或者游戏id不能为空');
  510. }
  511. $member_id = $memberModel->field('id')->where('username', $username)->find();
  512. if (empty($member_id)) {
  513. $this->error('无该玩家账号信息');
  514. }
  515. $channel_id = DB::table('cy_member_channel_game_rel')->field('channel_id')->where([
  516. 'member_id' => $member_id['id'],
  517. 'game_id' => $game_id,
  518. ])->find();
  519. if (empty($channel_id) || !isset($channel_id['channel_id'])) {
  520. $this->error('无关联的渠道信息');
  521. }
  522. $result = get_channel_arr($channel_id['channel_id']);
  523. if (empty($result)) {
  524. $this->error('无相关渠道信息');
  525. }
  526. }
  527. $this->success('修改成功', '', $result);
  528. }
  529. /**
  530. * 查询下级渠道页面
  531. */
  532. public function queryChildChannel()
  533. {
  534. $channel_id = input('request.channel_id', '', 'intval');
  535. $is_down = input('request.download', '0', 'intval');
  536. $list = array();
  537. if(!empty($channel_id)){
  538. $condition = $result = [];
  539. $condition['parent_id'] = $channel_id;
  540. $list = DB::table('nw_channel')->field('id,name')->where($condition)->select();
  541. $this->assign('list', $list); //渠道列表
  542. if($is_down>0){
  543. if(!empty($list)){
  544. $title = "下级渠道列表_".date('YmdHis');
  545. $this->downloadexls($list,$title,'queryChildChannel');
  546. exit();
  547. }
  548. else{
  549. echo '<script>alert("报表暂无数据");history.back();</script>';
  550. exit();
  551. }
  552. }
  553. }
  554. $channel_list = (new Channel())->getAllByCondition('id,name',[],'name asc');
  555. $this->assign('channel_list', $channel_list); //渠道列表
  556. return $this->fetch("queryChildChannel");;
  557. }
  558. public function channelConfig() {
  559. if (request()->isPost()) {
  560. $register_period = $this->request->param('register_period', 0, 'intval');
  561. $mobile = $this->request->param('mobile', '', 'trim');
  562. $register_most = $this->request->param('register_most', 0, 'intval');
  563. $status = $this->request->param('status', 0, 'intval');
  564. // $free_channel = $this->request->param('free_channel', '', 'trim');
  565. $remark = $this->request->param('remark', '', 'filterAndTrimInput');
  566. //功能开启时必须配置正确
  567. if($status>0){
  568. if ( 0 >= $register_period) {
  569. $this->error('注册预警时间段必须配置,且必须为正整数');
  570. }
  571. if ($register_most < 0) {
  572. $this->error('注册预警个数必须配置,且必须为正整数');
  573. }
  574. if (!$mobile) {
  575. $this->error('预警手机必须配置');
  576. }
  577. }
  578. $mobileArray = explode("|",$mobile);
  579. while(list($key,$val)=@each($mobileArray)){
  580. if (trim($val)) {
  581. if(! preg_match("/^1\d{10}$/", trim($val))){
  582. $this->error('存在手机号码不正确,请确认');
  583. }
  584. else{
  585. $mobileArray[$key] = trim($val);
  586. }
  587. }
  588. else{
  589. unset($mobileArray[$key]);
  590. }
  591. }
  592. $mobileArray = array_unique($mobileArray);
  593. $mobile = implode("|",$mobileArray);
  594. // $id = $this->request->param('id', 0, 'intval');
  595. //该配置表暂时默认只有一笔记录,直接写定
  596. $id = 1;
  597. $data = [
  598. 'mobile' => $mobile,
  599. 'register_period' => $register_period,
  600. 'register_most' => $register_most,
  601. 'status' => $status,
  602. 'remark' => $remark,
  603. 'update_time' => time()
  604. ];
  605. $data['free_channel'] = implode(',', input('free_channel/a', [])) . ',';
  606. // var_dump($data);
  607. $update = model('channelConfig')->where(['id' => $id])->update($data);
  608. if ( false === $update) {
  609. $this->error('更新失败');
  610. } else {
  611. $content = '功能状态:'.$status;
  612. $content .= ",注册预警时间段:{$register_period}分钟";
  613. $content .= ",注册预警个数:{$register_most}";
  614. $content .= ",预警手机:".$mobile;
  615. $content .= ",备注:".$remark;
  616. $content .= ",白名单渠道:".$data['free_channel'];
  617. $this->insertLog($this->current_node, $content, 52);
  618. $this->success('更新成功', url('ChannelManage/channelConfig') );
  619. }
  620. } else {
  621. // $id = $this->request->param('id', 0, 'intval');
  622. //该配置表暂时默认只有一笔记录,直接写定
  623. $id = 1;
  624. if ( empty($id) ) {
  625. $this->error('参数出错');
  626. }
  627. $info = model('channelConfig')->field(['id', 'status', 'register_period', 'free_channel', 'register_most', 'mobile', 'remark'])->find($id);
  628. if ( empty($info) ) {
  629. $this->error('配置数据不存在');
  630. }
  631. $free_channel = '';
  632. $this->assign('vo', $info);
  633. $this->assign('free_channel', ltrim($info['free_channel'], ','));
  634. return $this->fetch("channelConfig");
  635. }
  636. }
  637. }