Game.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. <?php
  2. /**
  3. * 游戏管理控制器
  4. */
  5. namespace app\guildapi\controller;
  6. use app\common\model\PromotionShortLink;
  7. use think\Db;
  8. use think\Env;
  9. use think\Exception;
  10. use app\common\logic\Member as MemberService;
  11. use app\common\model\GamePoint;
  12. use GuzzleHttp\Client;
  13. use app\common\model\ServerInfo;
  14. class Game extends Guild
  15. {
  16. protected $_model;
  17. protected $_channelId;
  18. // 特殊处理的 IOS游戏id 数组
  19. protected $gameIOS;
  20. // 游戏平台
  21. protected $_platform = [
  22. 0 => '安卓',
  23. 1 => 'IOS'
  24. ];
  25. // 游戏状态
  26. protected $_status = [
  27. 0 => ['index'=>1,'value'=>'正常'],
  28. 1 => ['index'=>2,'value'=>'白名单'],
  29. // 3 => '下架',
  30. ];
  31. //新闻类型
  32. protected $_type = [
  33. 1 => '资讯',
  34. 2 => '麻花网络',
  35. 3 => '评测',
  36. 4 => '攻略',
  37. 5 => '视频',
  38. 6 => '活动',
  39. 7 => '更新',
  40. 8 => '新闻',
  41. 9 => '充值活动'
  42. ];
  43. // todo 显示的新闻类型
  44. private $_newsType
  45. = array(
  46. 6 => '活动' ,
  47. 7 => '更新' ,
  48. 8 => '新闻' ,
  49. 9 => '充值活动'
  50. );
  51. private $_newsTypeList = ['6','7','8','9'];
  52. // 游戏等级
  53. protected $gameLevel = ['S' , 'A1' , 'A2' , 'B1' , 'B2' , 'B3' , 'B4' , 'C' , 'D'];
  54. protected function _initialize()
  55. {
  56. parent::_initialize();
  57. $this->_model = model('Game');
  58. $guildInfo = session('guild_info');
  59. $this->_channelId = $guildInfo['channel_id'];
  60. $this->_level = $guildInfo['level'];
  61. $this->gameIOS = config('gameIOS');
  62. }
  63. /**
  64. * 获取游戏列表
  65. * @return [type] [description]
  66. */
  67. public function getGameList()
  68. {
  69. $page = input('page',1);
  70. $pageSize = input('pageSize',10);
  71. $where = $this->_getCondition();
  72. $games = $this->gameList();
  73. $exist_game = Db::name('cy_sdkgamelist')->where(['channel_id'=>$this->_channelId])->column('gameid');
  74. $apply_game = Db::name('nw_game_package_apply')->where(['channel_id'=>$this->_channelId,'apply_status'=>0])->column('game_id');//白名单申请列表
  75. $list = $this->_model->alias('game')
  76. ->join('cy_gameinfo info', 'game.id = info.game_id')
  77. ->join('nw_game_channel_divide devide','game.id = devide.game_id and devide.channel_id = '.$this->_channelId,'left')
  78. ->field(['game.id', 'game.name', 'info.mobileicon', 'game.type', 'game.subject', 'game.cooperation_status','info.platform','game.pinyin','ratio'])
  79. ->where($where)
  80. ->whereIn('game.id',array_column(json_decode(json_encode($games),true),'id'))
  81. ->where("game.is_default = 0 and game.cooperation_status != 3")
  82. ->where(['game.id'=>['not in',$exist_game]])
  83. ->order('game.id desc')
  84. ->paginate($pageSize,false,['page'=>$page])->toArray();
  85. if ($list['data']) {
  86. foreach ($list['data'] as $key => $value) {//在申请表的话并且状态是申请中 0 吧对应的游戏状态改成4
  87. $list['data'][$key]['cooperation_status'] = in_array($value['id'],$apply_game)?'apply':$list['data'][$key]['cooperation_status'];
  88. if(in_array($this->_channelId,[5851,3549])){
  89. if (empty($list['data'][$key]['ratio'])) {
  90. $list['data'][$key]['ratio'] = db::name('cy_game')->where(['id'=>$value['id']])->value('channel_split_ratio');
  91. }
  92. }else{
  93. $list['data'][$key]['ratio'] = "--";
  94. }
  95. }
  96. }
  97. return json(['data'=>$list,'code'=>20000,'msg'=>'获取游戏列表成功']);
  98. // switch ($this->_level) {
  99. // case '3':
  100. // $exist_game = Db::name('cy_sdkgamelist')->where(['channel_id'=>$this->_channelId])->column('gameid');
  101. // $apply_game = Db::name('nw_game_package_apply')->where(['channel_id'=>$this->_channelId,'apply_status'=>0])->column('game_id');//白名单申请列表
  102. // $list = $this->_model->alias('game')
  103. // ->join('cy_gameinfo info', 'game.id = info.game_id')
  104. // ->field(['game.id', 'game.name', 'info.mobileicon', 'game.type', 'game.subject', 'game.cooperation_status','info.platform','game.pinyin'])
  105. // ->where($where)
  106. // ->where("game.is_default = 0 and game.cooperation_status != 3")
  107. // ->where(['game.id'=>['not in',$exist_game]])
  108. // ->order('game.id desc')
  109. // ->paginate($pageSize,false,['page'=>$page])->toArray();
  110. // if ($list['data']) {
  111. // foreach ($list['data'] as $key => $value) {//在申请表的话并且状态是申请中 0 吧对应的游戏状态改成4
  112. // $list['data'][$key]['cooperation_status'] = in_array($value['id'],$apply_game)?'apply':$list['data'][$key]['cooperation_status'];
  113. // }
  114. // }
  115. // return json(['data'=>$list,'code'=>20000,'msg'=>'获取游戏列表成功']);
  116. // break;
  117. // case '1':
  118. // $list = $this->_model->alias('game')
  119. // ->join('cy_gameinfo info', 'game.id = info.game_id')
  120. // ->join('nw_game_channel_divide devide','game.id = devide.game_id and devide.channel_id = '.$this->_channelId,'left')
  121. // ->field(['game.id', 'game.name', 'info.mobileicon', 'game.type', 'game.subject', 'game.cooperation_status','info.platform','game.pinyin','ratio'])
  122. // ->where($where)
  123. // ->where("game.is_default = 0 and game.cooperation_status != 3")
  124. // ->order('game.id desc')
  125. // ->paginate($pageSize,false,['page'=>$page])->toArray();
  126. // if (!empty($list['data']) ) {
  127. // foreach ($list['data'] as $key => $value) {
  128. // if (empty($list['data'][$key]['ratio'])) {
  129. // $list['data'][$key]['ratio'] = db::name('cy_game')->where(['id'=>$value['id']])->value('channel_split_ratio');
  130. // }
  131. // }
  132. // }
  133. // return json(['data'=>$list,'code'=>20000,'msg'=>'获取游戏列表成功']);
  134. // break;
  135. // default:
  136. // $list = $this->_model->alias('game')
  137. // ->join('cy_gameinfo info', 'game.id = info.game_id')
  138. // ->field(['game.id', 'game.name', 'info.mobileicon', 'game.type', 'game.subject', 'game.cooperation_status','info.platform','game.pinyin'])
  139. // ->where($where)
  140. // ->where("game.is_default = 0 and game.cooperation_status != 3")
  141. // ->order('game.id desc')
  142. // ->paginate($pageSize,false,['page'=>$page])->toArray();
  143. // return json(['data'=>$list,'code'=>20000,'msg'=>'获取游戏列表成功']);
  144. // break;
  145. // }
  146. }
  147. /**
  148. * 获取搜索菜单列表
  149. * @param string $value [description]
  150. */
  151. public function getGameMenu()
  152. {
  153. $meue = [];
  154. $meue['game_platform'] = $this->_platform;
  155. $meue['game_status'] = $this->_status;
  156. $meue['game_type'] = $this->_getType();
  157. $meue['game_subject'] = $this->_getSubject();
  158. $meue['game_list'] = $this->gameList();
  159. return json(['data'=>$meue,'code'=>20000,'msg'=>'获取搜索菜单列表成功']);
  160. }
  161. /**
  162. * 我的游戏链接read
  163. * @param string $value [description]
  164. */
  165. public function myGameLink()
  166. {
  167. $page = input('page',1);
  168. $pageSize = input('pageSize',10);
  169. $platform = input('platform'); // 适用平台 0-安卓 1-IOS
  170. $level = input('level');//账号类型
  171. $gameName = input('gameName', '', 'trim');
  172. $accountName = input('accountName', '', 'trim');
  173. $upload_status = input('upload_status', ''); // 是否处理成功:-1=已禁用、0=待处理、1=已处理、2=待审核、3=分包中、4=分包失败
  174. $platform_type = input('platform_type', ''); // 平台类型(2=安卓、1=ios)
  175. $condition = [];
  176. $condition['game.game_kind'] = 1;
  177. if (is_numeric($platform)) {
  178. $condition['info.platform'] = (int)$platform;
  179. }
  180. if (is_numeric($upload_status)) {
  181. $condition['sdk.upload_status'] = (int)$upload_status;
  182. }
  183. if ($platform_type) {
  184. $condition['game.type'] = (int)$platform_type;
  185. }
  186. if (! empty($gameName)) {
  187. $condition['game.name'] = ['LIKE', '%' . $gameName . '%'];
  188. }
  189. if (! empty($accountName)) {
  190. $level == 2 && $condition['p_channel.name'] = ['LIKE', $accountName . '%'];
  191. $level == 3 && $condition['channel.name'] = ['LIKE', $accountName . '%'];
  192. }
  193. $account_level = Db::name('nw_channel')->where(['id' => $this->_channelId])->value('level');
  194. switch ($account_level) {
  195. case '1'://B账号
  196. $list = model('SdkGameList')->alias('sdk')
  197. ->join('cy_game game', 'game.id = sdk.gameid AND game.cooperation_status != 3 AND (game.is_default = 0)')
  198. ->join('cy_gameinfo info', 'game.id = info.game_id', 'left')
  199. ->join('nw_channel channel', 'sdk.channel_id = channel.id', 'left')
  200. ->join('nw_channel p_channel', 'channel.parent_id = p_channel.id AND p_channel.level = 2', 'left')
  201. ->join('nw_game_package_apply gpa', 'sdk.gameid = gpa.game_id AND sdk.channel_id = gpa.channel_id', 'left')
  202. ->field(
  203. [
  204. 'game.id', 'game.name', 'info.mobileicon','game.pinyin','info.platform',
  205. 'sdk.id' => 'sdk_id','sdk.filename', 'sdk.update_time', 'sdk.upload_status','sdk.package_type','sdk.channel_id','channel.name' =>'c_name','p_channel.name'=>'b_name','sdk.remark','game.pinyin'
  206. ,'gpa.apply_status', 'gpa.remark'
  207. ]
  208. )
  209. ->where(['channel.id_path' => ['LIKE', '%,' . $this->_channelId . ',%']])
  210. ->where($condition)
  211. ->order('sdk.update_time desc')
  212. ->paginate(['list_rows'=>$pageSize,'page'=>$page])->toArray();
  213. break;
  214. case '2'://B-
  215. $list = model('SdkGameList')->alias('sdk')
  216. ->join('cy_game game', 'game.id = sdk.gameid AND game.cooperation_status != 3 AND (game.is_default = 0)')
  217. ->join('cy_gameinfo info', 'game.id = info.game_id', 'left')
  218. ->join('nw_channel channel', 'sdk.channel_id = channel.id', 'left')
  219. ->join('nw_game_package_apply gpa', 'sdk.gameid = gpa.game_id AND sdk.channel_id = gpa.channel_id', 'left')
  220. ->field(
  221. [
  222. 'game.id', 'game.name', 'info.mobileicon','game.pinyin','info.platform',
  223. 'sdk.id' => 'sdk_id','sdk.filename', 'sdk.update_time', 'sdk.upload_status','sdk.package_type','sdk.channel_id','channel.name' =>'c_name','sdk.remark','game.pinyin'
  224. ,'gpa.apply_status', 'gpa.remark'
  225. ]
  226. )
  227. ->where(['channel.id_path' => ['LIKE', '%,' . $this->_channelId . ',%']])
  228. ->where($condition)
  229. ->order('sdk.update_time desc')
  230. ->paginate(['list_rows'=>$pageSize,'page'=>$page])->toArray();
  231. break;
  232. case '3'://C
  233. $list = model('SdkGameList')->alias('sdk')
  234. ->join('cy_game game', 'game.id = sdk.gameid AND game.cooperation_status != 3 AND (game.is_default = 0)')
  235. ->join('cy_gameinfo info', 'game.id = info.game_id', 'left')
  236. ->join('nw_channel channel', 'sdk.channel_id = channel.id', 'left')
  237. ->join('nw_game_package_apply gpa', 'sdk.gameid = gpa.game_id AND sdk.channel_id = gpa.channel_id', 'left')
  238. ->field(
  239. [
  240. 'game.id', 'game.name', 'info.mobileicon','game.pinyin','info.platform',
  241. 'sdk.id' => 'sdk_id','sdk.filename', 'sdk.update_time', 'sdk.upload_status','sdk.package_type','sdk.channel_id','channel.name' =>'c_name','sdk.remark','game.pinyin'
  242. ,'gpa.apply_status', 'gpa.remark'
  243. ]
  244. )
  245. ->where('channel.id = '.$this->_channelId)
  246. ->where($condition)
  247. ->order('sdk.update_time desc')
  248. ->paginate(['list_rows'=>$pageSize,'page'=>$page])->toArray();
  249. break;
  250. default:
  251. $list = [];
  252. break;
  253. }
  254. if (!isset($list['data'])) {
  255. return json(['data'=>$list,'code'=>10038,'msg'=>'暂无数据']);
  256. }
  257. foreach ($list['data'] as $key => $value) {
  258. $short_link = db('nw_promotion_short_link')->where(['game_id'=>$value['id'],'channel_id'=>$value['channel_id'],'package_type'=>$value['package_type'], 'type' => 1])->value('short_link');
  259. if (!empty($short_link)) {
  260. $share_url = T_DOMAIN.'/'.$short_link;
  261. } else {
  262. $share_url = T_DOMAIN . '/game_promotion/index/game_id/' . $value['id'] . '/channel_id/' . $value['channel_id'] . '/package_type/' . $value['package_type'];
  263. }
  264. if($value['update_time'] > 1711596600){
  265. $list['data'][$key]['down_url'] = APK_DOWN_DOMAIN_NEW . '/sygame/' . $value['pinyin'] . '/' . $value['filename'];
  266. }else{
  267. $list['data'][$key]['down_url'] = APK_DOWN_DOMAIN . '/sygame/' . $value['pinyin'] . '/' . $value['filename'];
  268. }
  269. $list['data'][$key]['share_url'] = $share_url;
  270. // if ($value['upload_status'] == 0) {
  271. // $list['data'][$key]['upload_status'] = time() - $value['update_time'] >= PACKAGE_TIME_OUT?2:0;
  272. // }
  273. $list['data'][$key]['share_all_url'] = T_DOMAIN . '/game/index.html?cid=' . base64_encode(auth_code($value['channel_id'], "ENCODE", Env::get('auth_key')));
  274. $short_page_link = db('nw_promotion_short_link')->where(['game_id' => $value['id'], 'channel_id' => $value['channel_id'], 'package_type' => $value['package_type'], 'type' => 2])->value('short_link');
  275. if (!$short_page_link) {
  276. (new PromotionShortLink())->insertData($value['id'], $value['channel_id'], $value['package_type'], 2);
  277. $short_page_link = db('nw_promotion_short_link')->where(['game_id' => $value['id'], 'channel_id' => $value['channel_id'], 'package_type' => $value['package_type'], 'type' => 2])->value('short_link');
  278. }
  279. if ($short_page_link) {
  280. $list['data'][$key]['share_all_url'] = T_DOMAIN . '/tgy/' . $short_page_link;
  281. }
  282. //审核中
  283. // if($value['apply_status'] === 0){
  284. // $list['data'][$key]['upload_status'] = 3;
  285. // }
  286. if ($value['update_time']) {
  287. $list['data'][$key]['update_time'] = date("Y-m-d H:i:s", $value['update_time']);
  288. }
  289. }
  290. return json(['data'=>$list,'code'=>20000,'msg'=>'获取游戏列表成功']);
  291. }
  292. /**
  293. * 批量注册列表
  294. * @param string $value [description]
  295. */
  296. public function myBatchLog()
  297. {
  298. $page = input('page',1);
  299. $list_rows = input('pageSize',10);
  300. $gameid = input('gameid');
  301. $status = input('status');
  302. $create_time = input('create_time');
  303. $where = [];
  304. if (! empty($gameid)) {
  305. $where['log.game_id'] = $gameid;
  306. }
  307. if (! empty($status) || $status==='0') {
  308. $where['log.status'] = $status;
  309. }
  310. if (! empty($create_time)) {
  311. $where['log.create_time'] = [['>=', strtotime($create_time .'0:0:0')],['<=', strtotime(date($create_time .'23:59:59'))]];
  312. }
  313. $list = Db::name('nw_batch_reg')
  314. ->alias('log')
  315. ->join('cy_game game', 'log.game_id = game.id')
  316. ->field('log.id as log_id,log.tal_cnt,log.status,FROM_UNIXTIME(log.create_time) as create_time,log.channel_id,log.remark,game.name')
  317. ->where($where)
  318. ->where(['channel_id'=>$this->_channelId,'game.game_kind'=>1])
  319. ->where("game.is_default = 0 and game.cooperation_status != 3")
  320. ->order('log.create_time desc')
  321. ->paginate(['list_rows'=>$list_rows,'page'=>$page])->toArray();
  322. $gameList = model('Common/Game')->getAllByCondition('id,name',['game_kind'=>1,'cooperation_status'=>['NOT IN',[0,3]]],'','self');
  323. return json(['data'=>$list,'code'=>20000,'gameList'=>$gameList,'msg'=>'获取批量注册记录成功']);
  324. }
  325. /**
  326. * 批量注册具体数据列表
  327. * @param string $value [description]
  328. */
  329. public function myBatchLogList()
  330. {
  331. $log_id = input('log_id',0);
  332. $page = input('page',1);
  333. $list_rows = input('pageSize',10);
  334. if (empty($log_id) || !isset($log_id)) {
  335. return json(['data'=>'','code'=>10023,'msg'=>'log_id参数错误']);
  336. }
  337. $list = Db::name('nw_batch_reg_log')->alias('log')
  338. ->field('log.id,log.account,log.status,log.channel_id,game.name')
  339. ->where(['log.log_id'=>$log_id,'log.channel_id'=>$this->_channelId])
  340. ->join('cy_game game', 'log.game_id = game.id')
  341. ->where("game.is_default = 0 and game.cooperation_status != 3")
  342. ->paginate(['list_rows'=>$list_rows,'page'=>$page])->toArray();
  343. return json(['data'=>$list,'code'=>20000,'msg'=>'获取批量注册详情成功']);
  344. }
  345. /**
  346. * 批量注册
  347. */
  348. public function doBatchReg()
  349. {
  350. if ($this->_level != 3) {
  351. return json(['data'=>'','code'=>10023,'msg'=>'只有推广员能增加账号!']);
  352. }
  353. $game_id = input('game_id');
  354. $str = input('account_str');
  355. if (empty($game_id) || !isset($game_id)) {
  356. return json(['data'=>'','code'=>10023,'msg'=>'game_id参数错误']);
  357. }
  358. $str = array_filter(explode(',', $str));
  359. if (count($str)>=100) {
  360. return json(['data'=>'','code'=>10025,'msg'=>'批量注册一次性最多支持100条账号注册']);//校验长度
  361. }
  362. foreach ($str as $key => $value) {
  363. //校验账号规则
  364. if (!preg_match('/^[a-zA-Z]{1}[a-zA-Z0-9]{5,19}$/i',$value)) {
  365. unset($str[$key]);
  366. }
  367. }
  368. $str = array_values($str);
  369. $where = [];
  370. // $where['gameid'] = $game_id;
  371. $where['username'] = ['in',$str];
  372. $accountList = Db::name('cy_memberstwo')->where($where)-> column('username');//取出重复的值
  373. if ($accountList) {//重复的情况下去除重复反馈给前端
  374. $str = array_diff($str, $accountList);
  375. $msg = implode(',', $accountList);
  376. return json(['data'=>implode(',', $str),'code'=>20000,'msg'=>'账号:'.$msg.'重复以去除,请确认其他账号是否继续创建','type'=>1]);//校验长度
  377. }
  378. // 判断该游戏是否处于白名单状态,若是,则判断是否有分包记录,没有的话,禁止注册关联
  379. if(!empty($game_id)) {
  380. $game_info = model('game')->where(['id' => $game_id])->find();
  381. // 处于白名单状态
  382. if(2 == $game_info['cooperation_status']) {
  383. $conditions = array();
  384. $conditions['gameid'] = $game_id;
  385. $conditions['channel_id'] = $this->_channelId;
  386. $subPackageCnt = model('SdkGameList')->where($conditions)->count();
  387. if(!$subPackageCnt){
  388. return json(['data'=>'','code'=>10023,'msg'=>'该游戏处于白名单状态,无法新增']);
  389. }
  390. }
  391. }
  392. //都符合的情况下写入数据
  393. Db::startTrans();
  394. try {
  395. //1. 添加到批次表
  396. $channelModel = Db::name('nw_batch_reg');
  397. $log_id = $channelModel->insertGetId([
  398. 'game_id' => $game_id,
  399. 'status' => 1,
  400. 'create_time' => NOW_TIMESTAMP,
  401. 'tal_cnt' => count($str),
  402. 'channel_id' => $this->_channelId
  403. ]);
  404. if (!$log_id) {
  405. return json(['data'=>'','code'=>10015,'msg'=>"添加批次信息失败"]);
  406. }
  407. $cont = [];
  408. foreach ($str as $key => $value) {
  409. $cont[$key]['game_id'] = $game_id;
  410. $cont[$key]['account'] = $value;
  411. $cont[$key]['log_id'] = $log_id;
  412. $cont[$key]['status'] = 1;
  413. $cont[$key]['channel_id'] = $this->_channelId;
  414. }
  415. $res = Db::name('nw_batch_reg_log')->insertAll($cont);
  416. if (!$res) {
  417. return json(['data'=>'','code'=>10015,'msg'=>"添加批次信息日志失败"]);
  418. }
  419. $data = [];
  420. foreach ($str as $key => $value) {
  421. $data['reg_time'] = NOW_TIMESTAMP;
  422. $data['login_time'] = NOW_TIMESTAMP;
  423. $data['ip'] = request()->ip();
  424. $data['gameid'] = $game_id;
  425. $data['username'] = $value;
  426. $data['password'] = auth_code('b123456', "ENCODE", Env::get('auth_key'));
  427. $data['channel_id'] = $this->_channelId;
  428. Db::startTrans();
  429. try {
  430. $member_id = Db::table('cy_members')->insertGetId($data);
  431. if ($member_id) {
  432. // 插入玩家历史记录
  433. Db::table('cy_member_history')->insert([
  434. 'userid' => $member_id,
  435. 'password' => auth_code('b123456', "ENCODE", Env::get('auth_key')),
  436. 'ip' => request()->ip(1),
  437. 'create_time' => NOW_TIMESTAMP
  438. ]);
  439. //插入用户扩展记录
  440. Db::table('cy_memberstwo')->insert([
  441. 'userid' => $member_id,
  442. 'username' => $data['username'],
  443. 'realname' => -1,
  444. 'idcard' => -1,
  445. 'create_time' => NOW_TIMESTAMP
  446. ]);
  447. // 登录时 绑定该游戏的归属渠道
  448. Db::table('cy_member_channel_game_rel')->insert([
  449. 'member_id' => $member_id,
  450. 'channel_id' => $data['channel_id'],
  451. 'game_id' => $data['gameid'],
  452. 'mcgr_createtime' => time(),
  453. // 'update_time' => time(),
  454. 'mcgr_ip' => request()->ip()
  455. ]);
  456. } else {
  457. throw new Exception("注册失败!");
  458. }
  459. Db::commit();
  460. } catch (Exception $e) {
  461. Db::rollback();
  462. return json(['data'=>'','code'=>10015,'msg'=>"添加失败: " . $e->getMessage()]);
  463. }
  464. }
  465. Db::commit();
  466. } catch (\Exception $e) {
  467. Db::rollback();
  468. return json(['data'=>'','code'=>10015,'msg'=>"添加失败: " . $e->getMessage()]);
  469. }
  470. return json(['data'=>'','code'=>20000,'msg'=>"注册成功"]);
  471. }
  472. /**
  473. * 已接游戏备注
  474. * @param string $value [description]
  475. * @return [type] [description]
  476. */
  477. public function toEditGameLink()
  478. {
  479. $sdk_id = input('sdk_id');
  480. $data = [];
  481. $data['remark'] = $remark = input('remark');
  482. if (empty($sdk_id)) {
  483. return json(['data'=>[],'code'=>10021,'msg'=>'sdk_id参数错误']);
  484. }
  485. $res = model('SdkGameList')->update($data, ['id'=>$sdk_id]);
  486. if ($res) {
  487. return json(['data'=>'','code'=>20000,'msg'=>'修改成功']);
  488. }else{
  489. return json(['data'=>'','code'=>10022,'msg'=>'修改失败']);
  490. }
  491. }
  492. /**
  493. * 获取游戏区服信息
  494. * @param string $value [description]
  495. * @return [type] [description]
  496. */
  497. public function getSeverList()
  498. {
  499. $gameId = input('game_id', 0, 'intval');
  500. $res = Db::name('nw_game_server')->field('servername,serverid')->where(['game_id'=>$gameId])->where(['status'=>1])->select();
  501. return json(['data'=>$res,'code'=>20000,'msg'=>'获取区服列表成功']);
  502. }
  503. // 获取游戏名称
  504. protected function _getGameName($gameId)
  505. {
  506. return model('Game')->where(['id' => $gameId])->value('name');
  507. }
  508. // 所有游戏类型
  509. protected function _getType()
  510. {
  511. return Db::table('cy_gametype')->field("id as 'index',name as 'value'")->select();
  512. }
  513. // 所有游戏题材
  514. protected function _getSubject()
  515. {
  516. return Db::table('cy_gamesubject')->field("id as 'index',name as 'value'")->select();
  517. }
  518. // 公共搜索条件
  519. protected function _getCondition($self = 'false')
  520. {
  521. $status = input('status');
  522. $platform = input('platform');
  523. $type = input('type', 0, 'intval');
  524. $subject = input('subject', 0, 'intval');
  525. $gameName = input('gameName', '', 'trim');
  526. $gameid = input('gameid');
  527. if ($self) {
  528. $package_type = input('package_type','');
  529. }
  530. $condition = [];
  531. $condition['game.game_kind'] = 1;
  532. if (! empty($gameName)) {
  533. $condition['game.name'] = ['LIKE', '%' . $gameName . '%'];
  534. }
  535. if (! empty($subject)) {
  536. $condition['game.subject'] = $subject;
  537. }
  538. if (! empty($type)) {
  539. $condition['game.type'] = $type;
  540. }
  541. if (is_numeric($status)) {
  542. $condition['game.cooperation_status'] = (int)$status;
  543. } else {
  544. $condition['game.cooperation_status'] = ['IN', [1, 2]];
  545. }
  546. if (is_numeric($platform)) {
  547. $condition['info.platform'] = (int)$platform;
  548. }
  549. //包体类型
  550. if ($package_type!='') {
  551. $condition['sdk.package_type'] = (int)$package_type;
  552. }
  553. return $condition;
  554. }
  555. /**
  556. * 获取游戏列表
  557. * @return mixed
  558. */
  559. public function gameList(){
  560. if($this->_channelLevel == 0){
  561. return model('Common/Game')->getAllByCondition('id,name',['game_kind'=>1,'cooperation_status'=>['neq',0]],'id desc','self');
  562. }else if($this->_channelLevel == 1){
  563. $channelGame = model('common/ChannelGame')->where(['channel_id'=>$this->_channelId])->column('game_id');
  564. }else {
  565. $channel = model('common/Channel')->field('id')->whereIn('id',$this->_channelIdPath)->where(['level'=>1])->find();
  566. $channelGame = model('common/ChannelGame')->where(['channel_id'=>$channel['id']])->column('game_id');
  567. }
  568. if(!$channelGame){
  569. return model('Common/Game')->where(['game_kind'=>1])
  570. ->where(['cooperation_status'=>1])->field('id,name')->select();
  571. }
  572. $where = ['cooperation_status'=>2,'id'=>['in',$channelGame]];
  573. return model('Common/Game')->where(['game_kind'=>1])
  574. ->where(['cooperation_status'=>1])->whereOr(function($query) use($where){
  575. $query->where($where);
  576. } )->field('id,name')->order('id desc')->select();
  577. // return model('Common/Game')->getAllByCondition('id,name',['game_kind'=>1,'cooperation_status'=>['neq',0],'id'=>['in',$channelGame]],'id desc','self');
  578. }
  579. /**
  580. * 获取所有游戏区服列表
  581. * @return mixed
  582. */
  583. public function gameServerList(){
  584. $page = input('page',1);
  585. $pageSize = input('pageSize',10);
  586. $game_id = input('game_id');
  587. $server_id = input('server_id');
  588. $where = [];
  589. if (!empty($game_id)) {
  590. $where['game.id'] = $game_id;
  591. }
  592. if (!empty($server_id)) {
  593. $where['server.id'] = $server_id;
  594. }
  595. $res = Db::name('cy_game')->alias('game')
  596. ->join('nw_game_server server','game.id = server.game_id')
  597. ->field(['game.id as game_id','game.name as game_name','servername','server.id as server_id'])
  598. ->where(['game_kind'=>1])
  599. ->where($where)
  600. ->where("game.is_default = 0 and game.cooperation_status != 3")
  601. ->paginate($pageSize,false,['page'=>$page])->toArray();
  602. if ($res['data']) {
  603. $rank = ($page-1)*10;
  604. foreach ($res['data'] as $key => $value) {
  605. $rank ++ ;
  606. $res['data'][$key]['rank'] = $rank;
  607. }
  608. }
  609. return json(['data'=>$res,'code'=>20000,'msg'=>'获取游戏列表成功']);
  610. }
  611. /**
  612. * 下载excel模板
  613. * @return [type] [description]
  614. */
  615. public function download()
  616. {
  617. $type = input('type',1);
  618. switch ($type) {
  619. case '1'://子会长模板
  620. return json(['data' => "https://cdn." . QM_DOMAIN_URL . "/common/excel/批量转账_子会长(模板).xlsx", 'code' => 20000, 'msg' => '下载链接']);
  621. break;
  622. case '2'://玩家模板
  623. return json(['data' => "https://cdn." . QM_DOMAIN_URL . "/common/excel/批量转账_玩家(模板).xlsx", 'code' => 20000, 'msg' => '下载链接']);
  624. break;
  625. default:
  626. return json(['data'=>'','code'=>15000,'msg'=>'参数错误']);
  627. break;
  628. }
  629. }
  630. }