MemberRebind.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. <?php
  2. /**
  3. * 用户换绑控制器
  4. *
  5. * Created by PhpStorm.
  6. * User: Admin
  7. * Date: 2018/5/10
  8. * Time: 10:27
  9. */
  10. namespace app\admin\controller;
  11. use think\Db;
  12. use app\common\model\Channel;
  13. use app\common\model\Game as GameModel;
  14. use app\common\model\GameInfo;
  15. use app\common\model\Logininfo;
  16. use app\common\logic\SubPackage as SubChannel;
  17. use app\common\model\AndroidSdk;
  18. use app\common\model\AutoPackage;
  19. use app\common\library\ValidateExtend;
  20. class MemberRebind extends Admin
  21. {
  22. protected $departmentModel;
  23. protected $gameModel;
  24. protected $subChannel;
  25. protected $channelModel;
  26. protected $sdkgamelistModel;
  27. protected $gameList;
  28. protected $channel;
  29. protected $gameIOS; // 特殊处理的 IOS游戏id 数组
  30. protected function _initialize()
  31. {
  32. parent::_initialize();
  33. $this->subChannel = new SubChannel;
  34. $this->channelModel = new Channel;
  35. $this->gameModel = new GameModel;
  36. $this->sdkgamelistModel = $this->cyModel('sdkgamelist');
  37. $this->gameList = $gameList = model('Common/Game')->getAllByCondition('id,name');
  38. $tmpSelfGameList = model('Common/Game')->getAllByCondition('id,name', [],'','self');
  39. $selfGameList = array();
  40. foreach ($tmpSelfGameList as $game) {
  41. $selfGameList[ $game['id']] = $game;
  42. }
  43. $this->selfGameList = $selfGameList;
  44. $this->channel = $channelList = $this->nwModel('channel')->where(['flag' => 3])->field('id,name')->select();
  45. $this->childChannel = $this->nwModel('channel')->where(['flag' => 3,'level' => 3])->field('id,name')->select();
  46. // 特殊处理的 IOS游戏id 数组
  47. $this->gameIOS = config('gameIOS');
  48. }
  49. /**
  50. * 换绑记录列表
  51. * @return mixed
  52. */
  53. public function index()
  54. {
  55. $game_id = input('game_id',0,'intval');
  56. $account = input('account','','trim');
  57. $cusername = input('cusername','','trim');
  58. $start_time = input('start_time','','trim');
  59. $end_time = input('end_time','','trim');
  60. $admin_type = input('admin_type',0,'intval');
  61. $condition = [];
  62. if(input('account')){
  63. $condition['r.username'] = $account;
  64. }
  65. if(input('game_id') <> ''){
  66. $condition['r.game_id'] = $game_id;
  67. }
  68. if(input('admin_type') <> ''){
  69. $condition['r.admin_type'] = $admin_type;
  70. }
  71. //申请开始时间和结束时间不为空时
  72. if ($start_time != '' && $end_time != '') {
  73. $condition['r.create_time'] = [
  74. ['>=', strtotime($start_time)],
  75. ['<=', strtotime($end_time . ' 23:59:59')],
  76. ];
  77. } //开始时间不为空时
  78. elseif ($start_time != '') {
  79. $condition['r.create_time'] = ['>=', strtotime($start_time)];
  80. } //结束时间不为空时
  81. elseif ($end_time != '') {
  82. $condition['r.create_time'] = ['<=', strtotime($end_time . ' 23:59:59')];
  83. }
  84. $whereRaw = '';
  85. if(input('cusername')<>''){
  86. $whereRaw .= ' r.origin_cusername="'.$cusername.'" or r.cusername="'.$cusername.'" ';
  87. }
  88. if($whereRaw){
  89. $rebindList = model('PlayerRebind')->alias('r')
  90. ->join('cy_game g', 'r.game_id = g.id', 'left')
  91. ->where($condition)
  92. ->whereRaw($whereRaw)
  93. ->field("r.id,r.userid,r.username,r.game_id,g.name as game_name,r.origin_cuserid,r.origin_cusername,r.cuserid,r.cusername,r.create_time,r.cmmt,r.admin_type,r.admin_id,r.admin_name")
  94. ->order("r.id desc")
  95. ->paginate(10, false, ['query' => $condition]);
  96. }
  97. else{
  98. $rebindList = model('PlayerRebind')->alias('r')
  99. ->join('cy_game g', 'r.game_id = g.id', 'left')
  100. ->where($condition)
  101. ->field("r.id,r.userid,r.username,r.game_id,g.name as game_name,r.origin_cuserid,r.origin_cusername,r.cuserid,r.cusername,r.create_time,r.cmmt,r.admin_type,r.admin_id,r.admin_name")
  102. ->order("r.id desc")
  103. ->paginate(10, false, ['query' => $condition]);
  104. }
  105. foreach ($rebindList as $key => $value) {
  106. $channel = get_top_second_channel_name($value['origin_cuserid']);
  107. $rebindList[$key]['origin_top_channel'] = $channel['top_name'];
  108. $cuserid_channel = get_top_second_channel_name($value['cuserid']);
  109. $rebindList[$key]['cuser_top_channel'] = $cuserid_channel['top_name'];
  110. }
  111. // 获取分页显示
  112. $page = $rebindList->render();
  113. $this->assign('game_list', $this->selfGameList);
  114. $this->assign('page', $page);
  115. $this->assign('rebindList', $rebindList);
  116. return $this->fetch();
  117. }
  118. /**
  119. * 换绑申请列表
  120. * @return mixed
  121. */
  122. public function applyList()
  123. {
  124. $game_id = input('game_id',0,'intval');
  125. $account = input('account','','trim');
  126. $cusername = input('cusername','','trim');
  127. $start_time = input('start_time','','trim');
  128. $end_time = input('end_time','','trim');
  129. $status = input('status',0,'intval');
  130. $condition = [];
  131. if(input('account')){
  132. $condition['r.username'] = $account;
  133. }
  134. if(input('game_id') <> ''){
  135. $condition['r.game_id'] = $game_id;
  136. }
  137. if(input('status') <> ''){
  138. $condition['r.status'] = $status;
  139. }
  140. //申请开始时间和结束时间不为空时
  141. if ($start_time != '' && $end_time != '') {
  142. $condition['r.create_time'] = [
  143. ['>=', strtotime($start_time)],
  144. ['<=', strtotime($end_time . ' 23:59:59')],
  145. ];
  146. } //开始时间不为空时
  147. elseif ($start_time != '') {
  148. $condition['r.create_time'] = ['>=', strtotime($start_time)];
  149. } //结束时间不为空时
  150. elseif ($end_time != '') {
  151. $condition['r.create_time'] = ['<=', strtotime($end_time . ' 23:59:59')];
  152. }
  153. $whereRaw = '';
  154. if (input('cusername') <> '') {
  155. $whereRaw .= ' r.origin_cusername="' . $cusername . '" or r.cusername="' . $cusername . '" ';
  156. }
  157. if ($whereRaw) {
  158. $rebindList = model('PlayerRebindApply')->alias('r')
  159. ->join('cy_game g', 'r.game_id = g.id', 'left')
  160. ->join('nw_subaccount s', 's.id=r.sub_id', 'left')
  161. ->where($condition)
  162. ->whereRaw($whereRaw)
  163. ->field("r.id,r.userid,r.username,r.game_id,g.name as game_name,r.origin_cuserid,r.origin_cusername,r.cuserid,r.cusername,r.create_time,r.cmmt,r.status,r.admin_id,r.admin_name,r.audit_remark,r.audit_admin_id,r.audit_admin_name,r.audit_time,r.picture1,r.picture2,r.picture3,r.oldPoint,r.deductionAmount,r.newPoint,r.getAmount,r.remark,r.playerAmount, s.sub_username")
  164. ->order("r.id desc")
  165. ->paginate(25, false, ['query' => $condition]);
  166. } else {
  167. $rebindList = model('PlayerRebindApply')->alias('r')
  168. ->join('cy_game g', 'r.game_id = g.id', 'left')
  169. ->join('nw_subaccount s', 's.id=r.sub_id', 'left')
  170. ->where($condition)
  171. ->field("r.id,r.userid,r.username,r.game_id,g.name as game_name,r.origin_cuserid,r.origin_cusername,r.cuserid,r.cusername,r.create_time,r.cmmt,r.status,r.admin_id,r.admin_name,r.audit_remark,r.audit_admin_id,r.audit_admin_name,r.audit_time,r.picture1,r.picture2,r.picture3,r.oldPoint,r.deductionAmount,r.newPoint,r.getAmount,r.remark,r.playerAmount, s.sub_username")
  172. ->order("r.id desc")
  173. ->paginate(25, false, ['query' => $condition]);
  174. }
  175. foreach ($rebindList as $key => $value) {
  176. $channel = get_top_second_channel_name($value['origin_cuserid']);
  177. $rebindList[$key]['origin_top_channel'] = $channel['top_name'];
  178. $cuserid_channel = get_top_second_channel_name($value['cuserid']);
  179. $rebindList[$key]['cuser_top_channel'] = $cuserid_channel['top_name'];
  180. }
  181. // 获取分页显示
  182. $page = $rebindList->render();
  183. $this->assign('game_list', $this->selfGameList);
  184. $this->assign('page', $page);
  185. $this->assign('rebindList', $rebindList);
  186. return $this->fetch();
  187. }
  188. //审核
  189. public function audit()
  190. {
  191. if (request()->isAjax()) {
  192. $id = input('id',0,'intval');
  193. $beizhu = input('beizhu','','trim');
  194. $status = input('status','0','intval');
  195. if(empty($id)){
  196. $this->error('ID不能为空');
  197. }
  198. if($status<>1 && $status<>2){
  199. $this->error('非法审核状态');
  200. }
  201. $rebindApplyInfo = model('PlayerRebindApply')->where(['id' => $id])->find();
  202. if (empty($rebindApplyInfo)) {
  203. $this->error('玩家换绑申请不存在');
  204. } else if ($rebindApplyInfo['status'] <> 0) {
  205. $this->error('玩家换绑申请已审核过,不能再进行审核');
  206. }
  207. if ($status == $rebindApplyInfo['status']) {
  208. $this->error('您未更改订单状态,请选择要更改的状态');
  209. }
  210. $auditData = array();
  211. $auditData['status'] = $status;
  212. $auditData['audit_time'] = NOW_TIMESTAMP;
  213. $auditData['audit_remark'] = $beizhu;
  214. $auditData['audit_admin_id'] = session('ADMIN_ID');
  215. $auditData['audit_admin_name'] = session('USERNAME');
  216. if ($status == 1) {
  217. if (!$rebindApplyInfo['cuserid']) {
  218. $this->error('换绑申请异常:要换绑的推广账号不存在');
  219. }
  220. $new_channel_info = model('Channel')->where(['id' => $rebindApplyInfo['cuserid']])->field('name,level')->find();
  221. if (empty($new_channel_info)) {
  222. $this->error('玩家换绑申请异常:要换绑的推广员账号不存在');
  223. } else if ($new_channel_info['level'] <> 3) {
  224. $this->error('玩家换绑申请异常:要换绑的推广员账号渠道层级有误,非推广员账号');
  225. }
  226. $old_channel_info = model('Channel')->where(['id' => $rebindApplyInfo['origin_cuserid']])->field('id,name,level')->find();
  227. if (!$old_channel_info) {
  228. $this->error('玩家所属原推广员账号不存在');
  229. }
  230. $channelInfo = (new Channel())->where(['id' => $rebindApplyInfo['cuserid']])->field('id,yql_id')->find();
  231. if (!$channelInfo) {
  232. $this->error('玩家切换的新渠道不存在');
  233. }
  234. $MemberChannelGameInfo = model('MemberChannelGame')->where(['member_id' => $rebindApplyInfo['userid'], 'game_id' => $rebindApplyInfo['game_id']])->find();
  235. if ($MemberChannelGameInfo) {
  236. if ($MemberChannelGameInfo['channel_id'] <> $rebindApplyInfo['origin_cuserid']) {
  237. $this->error('换绑申请异常:换绑申请中的原C账号与玩家当前所属推广员账号不一致!');
  238. }
  239. } else {
  240. $this->error('玩家尚未进入该游戏,不属于任何推广员');
  241. }
  242. }
  243. Db::startTrans();
  244. try {
  245. if ($status == 2) { //审核不通过
  246. $result = model('PlayerRebindApply')->where(['id' => $id, 'status' => array('in', [0])])->update($auditData);
  247. if ($result === false) {
  248. throw new Exception("更改玩家换绑申请状态失败");
  249. }
  250. $message = "玩家换绑审核,换绑ID:" . $rebindApplyInfo['id'] . ",审核状态:审核不通过";
  251. $this->insertLog($this->current_node, "玩家换绑审核,换绑ID:" . $rebindApplyInfo['id'] . ",审核状态:审核不通过", 24);
  252. } else if ($status == 1) { //审核通过
  253. if ($result = model('MemberChannelGame')->where(['member_id' => $rebindApplyInfo['userid'], 'game_id' => $rebindApplyInfo['game_id']])->update(['channel_id' => $rebindApplyInfo['cuserid']])) {
  254. $gamename = $rebindApplyInfo['game_name'];
  255. $message = '玩家' . $rebindApplyInfo['username'] . ',在游戏:' . $gamename . '的归属渠道由:' . $rebindApplyInfo['origin_cusername'] . ',变更为:' . $rebindApplyInfo['cusername'] . '的信息;';
  256. $this->insertLog($this->current_node, $message, 24);
  257. // 插入玩家历史记录
  258. Db::table('cy_member_history')->insert([
  259. 'userid' => $rebindApplyInfo['userid'],
  260. 'channel' => $gamename . "," . $new_channel_info['name'],
  261. 'ip' => request()->ip(),
  262. 'create_time' => time(),
  263. 'admin_id' => session('ADMIN_ID')
  264. ]);
  265. $updGameServerData = array();
  266. $updGameServerData['channel_id'] = $rebindApplyInfo['cuserid'];
  267. $updGameServerResult = model('MemberGameServer')->where(['member_id' => $rebindApplyInfo['userid'], 'game_id' => $rebindApplyInfo['game_id']])->update($updGameServerData);
  268. Db::table("cy_members")->where("id", $rebindApplyInfo['userid'])->update(
  269. [
  270. "channel_id" => $rebindApplyInfo['cuserid'],
  271. "update_time" => NOW_TIMESTAMP
  272. ]
  273. );
  274. Db::table("nw_subaccount")->where("id", $rebindApplyInfo['sub_id'])->update(
  275. [
  276. "channel_id" => $rebindApplyInfo['cuserid'],
  277. "update_time" => NOW_TIMESTAMP
  278. ]
  279. );
  280. /*
  281. $updGameServerImeilData = array();
  282. $updGameServerImeilData['channel_id'] = $rebindApplyInfo['cuserid'];
  283. $updGameServerResult = model('GameServerImeil')->where(['member_id' => $rebindApplyInfo['userid'], 'game_id' => $rebindApplyInfo['game_id']])->update($updGameServerImeilData);
  284. $updGameServerIpData = array();
  285. $updGameServerIpData['channel_id'] = $rebindApplyInfo['cuserid'];
  286. $updGameServerResult = model('GameServerIp')->where(['member_id' => $rebindApplyInfo['userid'], 'game_id' => $rebindApplyInfo['game_id']])->update($updGameServerIpData);
  287. */
  288. $rebindData = [
  289. 'userid' => $rebindApplyInfo['userid'],
  290. 'username' => $rebindApplyInfo['username'],
  291. 'game_id' => $rebindApplyInfo['game_id'],
  292. 'game_name' => $rebindApplyInfo['game_name'],
  293. 'origin_cuserid' => $rebindApplyInfo['origin_cuserid'],
  294. 'origin_cusername' => $rebindApplyInfo['origin_cusername'],
  295. 'cuserid' => $rebindApplyInfo['cuserid'],
  296. 'cusername' => $rebindApplyInfo['cusername'],
  297. 'create_time' => time(),
  298. 'cmmt' => '管理后台换绑申请审核通过',
  299. 'admin_type' => 1,
  300. 'admin_id' => session('ADMIN_ID'),
  301. 'admin_name' => session('USERNAME'),
  302. ];
  303. $insertRebindId = model('PlayerRebind')->insert($rebindData);
  304. // if($insertRebindId){
  305. // $rebindPayFromTime = strtotime(date('Y-m-d',(time()-((date('w',time())==0?7:date('w',time()))-1)*24*3600)));
  306. // $updPayData = array();
  307. // $updPayData['channel_id'] = $rebindData['cuserid'];
  308. // $updPayResult = model('Pay')->where(['userid' => $rebindData['userid'],'gameid' => $rebindData['game_id'],'channel_id' => $rebindData['origin_cuserid'],'create_time'=> ['egt', $rebindPayFromTime]])->update($updPayData);
  309. // if ($updPayResult) {
  310. // $message .= '该玩家本周后消费订单也已做换绑。';
  311. // }
  312. // }
  313. // 处理配对的 安卓/IOS/H5 端游戏(通过 nw_game_band 表查询)
  314. $bandGameIds = getBandGameId($rebindApplyInfo['game_id']);
  315. foreach ($bandGameIds as $bandGameId) {
  316. if (empty($bandGameId) || $bandGameId == $rebindApplyInfo['game_id']) {
  317. continue;
  318. }
  319. $bandGameInfo = model('Common/Game')->where(['id' => $bandGameId])->find();
  320. if ($bandGameInfo) {
  321. Db::table('cy_member_channel_game_rel')->where(['member_id' => $rebindApplyInfo['userid'], 'game_id' => $bandGameInfo['id']])->update(['channel_id' => $rebindApplyInfo['cuserid']]);
  322. $bandMessage = '玩家' . $rebindApplyInfo['username'] . ', 在配对游戏:' . $bandGameInfo['name'] . '的归属渠道由:' . $rebindApplyInfo['origin_cusername'] . ',变更为:' . $rebindApplyInfo['cusername'] . '的信息;';
  323. $this->insertLog($this->current_node, $bandMessage, 24);
  324. // 插入玩家历史记录
  325. Db::table('cy_member_history')->insert([
  326. 'userid' => $rebindApplyInfo['userid'],
  327. 'channel' => $bandGameInfo['name'] . "," . $new_channel_info['name'],
  328. 'ip' => request()->ip(),
  329. 'create_time' => time(),
  330. 'admin_id' => session('ADMIN_ID')
  331. ]);
  332. Db::table("nw_member_game_server")->where(['member_id' => $rebindApplyInfo['userid'], 'game_id' => $bandGameInfo['id']])->update(['channel_id' => $rebindApplyInfo['cuserid']]);
  333. Db::table("nw_subaccount")->where(['member_id' => $rebindApplyInfo['userid'], 'game_id' => $bandGameInfo['id']])->update(["channel_id" => $rebindApplyInfo['cuserid'], "update_time" => NOW_TIMESTAMP]);
  334. model('MemberChannelGame')->where(['member_id' => $rebindApplyInfo['userid'], 'game_id' => $bandGameId])->update(['channel_id' => $rebindApplyInfo['cuserid']]);
  335. $rebindData = [
  336. 'userid' => $rebindApplyInfo['userid'],
  337. 'username' => $rebindApplyInfo['username'],
  338. 'game_id' => $bandGameInfo['id'],
  339. 'game_name' => $bandGameInfo['name'],
  340. 'origin_cuserid' => $rebindApplyInfo['origin_cuserid'],
  341. 'origin_cusername' => $rebindApplyInfo['origin_cusername'],
  342. 'cuserid' => $rebindApplyInfo['cuserid'],
  343. 'cusername' => $rebindApplyInfo['cusername'],
  344. 'create_time' => time(),
  345. 'cmmt' => '管理后台换绑申请审核通过(配对游戏)',
  346. 'admin_type' => 1,
  347. 'admin_id' => session('ADMIN_ID'),
  348. 'admin_name' => session('USERNAME'),
  349. ];
  350. model('PlayerRebind')->insert($rebindData);
  351. $message .= $bandMessage;
  352. }
  353. }
  354. Db::commit();
  355. } else {
  356. throw new Exception("换绑申请异常:您未做任何绑定修改");
  357. }
  358. $result = model('PlayerRebindApply')->where(['id'=>$id,'status'=>array('in',[0])])->update($auditData);
  359. if ($result === false) {
  360. throw new Exception("更改玩家换绑申请状态失败");
  361. }
  362. $this->insertLog($this->current_node, "玩家换绑审核,换绑ID:".$rebindApplyInfo['id'].",审核状态:审核通过",24);
  363. }
  364. Db::commit();
  365. } catch (\Exception $e) {
  366. Db::rollback();
  367. $this->error("添加失败: " . $e->getMessage());
  368. }
  369. $this->success('审核成功; '.$message);
  370. }
  371. else{
  372. $this->error('非法请求');
  373. }
  374. }
  375. }