SubPackage.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855
  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 app\common\model\PromotionShortLink;
  12. use app\common\model\SdkGameList;
  13. use app\common\model\Setting;
  14. use think\Db;
  15. use app\common\model\Channel;
  16. use app\common\model\Game as GameModel;
  17. use app\common\model\GameInfo;
  18. use app\common\model\Logininfo;
  19. use app\common\logic\SubPackage as SubChannel;
  20. use app\common\model\AndroidSdk;
  21. use app\common\model\AutoPackage;
  22. use app\common\library\ValidateExtend;
  23. use think\Env;
  24. class SubPackage extends Admin
  25. {
  26. protected $departmentModel;
  27. protected $gameModel;
  28. protected $subChannel;
  29. protected $channelModel;
  30. protected $sdkgamelistModel;
  31. protected $gameList;
  32. protected $channel;
  33. protected $gameIOS; // 特殊处理的 IOS游戏id 数组
  34. protected function _initialize()
  35. {
  36. parent::_initialize();
  37. $this->subChannel = new SubChannel;
  38. $this->channelModel = new Channel;
  39. $this->gameModel = new GameModel;
  40. $this->sdkgamelistModel = $this->cyModel('sdkgamelist');
  41. $this->gameList = $gameList = model('Common/Game')->getAllByCondition('id,name');
  42. $tmpSelfGameList = model('Common/Game')->getAllByCondition('id,name', [],'','self');
  43. $selfGameList = array();
  44. foreach ($tmpSelfGameList as $game) {
  45. $selfGameList[ $game['id']] = $game;
  46. }
  47. $this->selfGameList = $selfGameList;
  48. $this->channel = $channelList = $this->nwModel('channel')->where(['flag' => 3])->field('id,name')->select();
  49. // $this->childChannel = $this->nwModel('channel')->where(['flag' => 3,'level' => 3])->field('id,name')->select();
  50. // 推广部门列表:部门权限=外部部门, 层级=推广员
  51. $tmpChildChannel = $this->nwModel('channel')->where(['flag' => 3,'level' => 3])->field('id,name')->select();
  52. $childChannel = array();
  53. foreach ($tmpChildChannel as $game) {
  54. $childChannel[ $game['id']] = $game;
  55. }
  56. $this->childChannel = $childChannel;
  57. // 特殊处理的 IOS游戏id 数组
  58. $this->gameIOS = config('gameIOS');
  59. }
  60. /**
  61. * 分包列表
  62. * @return mixed
  63. */
  64. public function index()
  65. {
  66. $condition = array();
  67. $top_channel = input('top_channel');
  68. $channel_type = input('channel_type');
  69. $channelId = input('channel_id');
  70. $gameId = input('game_id');
  71. $package_type = input('package_type');
  72. $game_kind = input('game_kind');
  73. $upload_status = input('upload_status');
  74. $platform_type = input('platform_type');
  75. $page_size = input('page_size', 15);
  76. if (!empty($gameId)) {
  77. $condition['gameid'] = $gameId;
  78. }
  79. if ($package_type != '') {
  80. $condition['package_type'] = $package_type;
  81. }
  82. if ($game_kind != '') {
  83. $condition['game_kind'] = $game_kind;
  84. }
  85. if ($upload_status != '') {
  86. $condition['upload_status'] = $upload_status;
  87. }
  88. if ($platform_type != '') {
  89. $condition['game.type'] = $platform_type;
  90. }
  91. if ($channel_type != 1 && $channel_type != 2 && $channel_type) {
  92. $this->error('查询参数有误!');
  93. }
  94. if ($channel_type == 1 && !$channelId) {
  95. //$this->error('渠道id参数有误!');
  96. }
  97. if ($channel_type == 2 && !$top_channel) {
  98. //$this->error('顶级渠道参数有误!');
  99. }
  100. if (!empty($channelId) && $channel_type == 1) {
  101. $condition['channel_id'] = $channelId;
  102. }
  103. // 按顶级渠道进行检索
  104. if(!empty($top_channel) && $channel_type == 2) {
  105. // 查出该顶级渠道下的所有渠道
  106. $channel_info =$this->channelModel->where('name', $top_channel)->field('id,parent_id,id_path')->find();
  107. if(!empty($channel_info)) {
  108. // 组成id_path路径,便于查出所有下级
  109. $id_path = $channel_info['id_path'].$channel_info['id'].',';
  110. $map = array();
  111. $map['id_path'] = array('LIKE', $id_path.'%');
  112. $map['level'] = 3;
  113. $channel_list = $this->channelModel->where($map)->field('id')->select();
  114. if (!empty($channel_list)) {
  115. foreach ($channel_list as $item) {
  116. $channel_ids[] = $item['id'];
  117. }
  118. $channel_ids[] = $channel_info['id'];
  119. $condition['channel_id'] = array('IN', $channel_ids);
  120. }else {
  121. $condition['channel_id'] = array('IN', null);
  122. }
  123. }else {
  124. $condition['channel_id'] = array('IN', null);
  125. }
  126. }
  127. $conditions['game_id'] = $gameId;
  128. $conditions['channel_id'] = $channelId;
  129. $conditions['top_channel'] = $top_channel;
  130. $conditions['channel_type'] = $channel_type;
  131. $conditions['package_type'] = $package_type;
  132. $conditions['game_kind'] = $game_kind;
  133. $conditions['upload_status'] = $upload_status;
  134. $conditions['platform_type'] = $platform_type;
  135. $subPackageList = $this->sdkgamelistModel->alias('sdk')
  136. ->join('cy_game game', 'game.id = sdk.gameid')
  137. ->where($condition)
  138. ->field(['game.pinyin,game.name as game_name,game.game_kind, game.type', 'sdk.*'])
  139. ->order("update_time desc,id DESC")
  140. ->paginate($page_size, false, ['query' => $conditions]);
  141. $appList = [];
  142. if (!empty($subPackageList->items())) {
  143. foreach ($subPackageList->items() as $v) {
  144. if($v['type'] == 3){
  145. // H5
  146. $v['app_url'] = getChannelH5Url($v['filename'], $v['gameid']);
  147. }else{
  148. // 安卓/IOS
  149. $v['app_url'] = getHandleCdnGamesByIds($v['gameid']) . '/sygame/' . $v['pinyin'] . '/' . $v['filename'];
  150. }
  151. // 推广页
  152. $short_link = db('nw_promotion_short_link')->where(['game_id' => $v['gameid'], 'channel_id' => $v['channel_id'], 'package_type' => $v['package_type']])->value('short_link');
  153. if($short_link){
  154. $short_link = T_DOMAIN .'/'. $short_link;
  155. }else{
  156. $short_link = API_DOMAIN . "/game_promotion/index/game_id/{$v['gameid']}/channel_id/{$v['channel_id']}/package_type/{$v['package_type']}";
  157. }
  158. $v['short_link'] = $short_link;
  159. $appList[] = $v;
  160. }
  161. }
  162. // 获取分页显示
  163. $page = $subPackageList->render();
  164. $this->assign('channel_list', $this->childChannel);
  165. $this->assign('game_list', $this->selfGameList);
  166. $this->assign('channel_id', $channelId);
  167. $this->assign('game_id', $gameId);
  168. $this->assign('page', $page);
  169. $this->assign('sub_package', $subPackageList);
  170. $this->assign('app_list', $appList);
  171. $this->assign('gameIOS', $this->gameIOS);
  172. return $this->fetch();
  173. }
  174. /**
  175. * 新增分包
  176. * @return mixed
  177. */
  178. public function add()
  179. {
  180. if (request()->isPost()) {
  181. $gameId = input('post.gameid');
  182. $channel_id = input('post.channel_id');
  183. $data = [
  184. 'gameid' => $gameId,
  185. 'channel_id' => $channel_id,
  186. 'package_type' => input('post.package_type'),
  187. ];
  188. $result = $this->validate($data,
  189. [
  190. ['gameid', 'require|integer|gt:0', '请选择游戏|游戏ID必须为整型|游戏ID必须大于0'],
  191. ['channel_id', 'require|integer|gt:0', '请选择渠道|渠道ID必须为整型|渠道ID必须大于0'],
  192. ['package_type', 'require|integer|in:0,1', '请选择游戏包类型|游戏包类型必须为整型|游戏包类型参数错误'],
  193. ]);
  194. if (true !== $result) {
  195. $this->error($result);
  196. }
  197. $channelFrozenModel = Db::name('nw_channel_frozen');
  198. $gameFrozenModel = Db::name('nw_game_frozen');
  199. // 对3款IOS游戏进行特殊处理
  200. if(in_array($gameId,$this->gameIOS)){
  201. $data['upload_status'] = 1;
  202. // aes 加密
  203. $register_url = 'channel/register.html?k=' . aesEncode("{$channel_id}@.@{$gameId}", '3EFCB15CCC5D525B');
  204. $data['filename'] = $register_url;
  205. }else{
  206. $check = $this->sdkgamelistModel->where($data)->find();
  207. if ($check) {
  208. $this->error('新增失败,该游戏渠道分包已存在!');
  209. }
  210. }
  211. $gameInfo = $this->gameModel->where('id', $gameId)->field('channel_version,type')->find();
  212. // 启动事务
  213. Db::startTrans();
  214. try{
  215. $data['update_time'] = NOW_TIMESTAMP;
  216. $data['create_time'] = NOW_TIMESTAMP;
  217. $data['channel_version']= $gameInfo['channel_version'] ?? 0;
  218. $this->sdkgamelistModel->insertGetId($data);
  219. // ## 双端推广链接合并 ##
  220. $shortLinkModel = new PromotionShortLink();
  221. if(in_array($gameInfo['type'], [1,2])){
  222. if($gameInfo['type'] == 1){
  223. $bandId = Db::table('nw_game_band')->where(['ios_game_id' => $data['gameid']])->value('android_game_id');
  224. } else if ($gameInfo['type'] == 2){
  225. $bandId = Db::table('nw_game_band')->where(['android_game_id' => $data['gameid']])->value('ios_game_id');
  226. }
  227. if($bandShortLink = $shortLinkModel->where(['game_id'=>$bandId, 'channel_id'=>$data['channel_id'], 'package_type'=> $data['package_type'], 'type' => 1])->value('short_link')) {
  228. $shortLinkModel->insert(['game_id'=> $data['gameid'], 'channel_id'=> $data['channel_id'], 'package_type'=> $data['package_type'], 'create_time'=>time(), 'short_link'=> $bandShortLink, 'type' => 1]);
  229. }else{
  230. $shortLinkModel->insertData($data['gameid'], $data['channel_id'], $data['package_type'], 1);
  231. }
  232. }else{
  233. $shortLinkModel->insertData($data['gameid'], $data['channel_id'], $data['package_type'], 1);
  234. // $shortLinkModel->insertData($game_id,$channel_id,$apktype, 2);
  235. }
  236. //游戏冻结信息
  237. $gameFrozenInfo = $gameFrozenModel->where(['game_id'=>$gameId])->find();
  238. if($gameFrozenInfo){
  239. //无该渠道、该游戏的冻结信息时,添加
  240. if(!$channelFrozenModel->where(['game_id'=>$gameId,'channel_id'=>$channel_id])->find()){
  241. $frozenData['game_id'] = $gameId;
  242. $frozenData['channel_id'] = $channel_id;
  243. $frozenData['subpackage'] = $gameFrozenInfo['subpackage'];
  244. $frozenData['grant_money'] = $gameFrozenInfo['grant_money'];
  245. $frozenData['consume'] = $gameFrozenInfo['consume'];
  246. $frozenData['member_login'] = $gameFrozenInfo['member_login'];
  247. $frozenData['register'] = $gameFrozenInfo['register'];
  248. $frozenData['create_time'] = NOW_TIMESTAMP;
  249. $frozenData['update_time'] = NOW_TIMESTAMP;
  250. $channelFrozenModel->insert($frozenData);
  251. }
  252. }
  253. // 提交事务
  254. Db::commit();
  255. }
  256. catch (\Exception $e) {
  257. // 回滚事务
  258. Db::rollback();
  259. $this->error('新增操作失败, ' . $e->getMessage());
  260. }
  261. $this->success('新增成功', url('index'));
  262. }
  263. $this->assign('channel_list', $this->childChannel);
  264. $this->assign('game_list', $this->selfGameList);
  265. return $this->fetch();
  266. }
  267. /**
  268. * 分包
  269. */
  270. public function subPackIndex()
  271. {
  272. if (request()->isPost()) {
  273. $id = input('post.id');
  274. $gameId = input('post.gameid');
  275. $channel_id = input('post.channel_id');
  276. $msg = '成功!';
  277. $code= 200;
  278. $condition['id'] = $id;
  279. $condition['gameid'] = $gameId;
  280. $condition['channel_id']= $channel_id; // 部门ID
  281. $subPackageInfo = $this->sdkgamelistModel->where($condition)->find();
  282. if ($subPackageInfo['upload_status'] == 1) {
  283. $msg = '抱歉已经分包,请删包后再分包!';
  284. $code = 400;
  285. }
  286. if (!empty($subPackageInfo['filename'])) {
  287. $msg = '抱歉文件名已生成无法分包,请等待后端分包完成!';
  288. $code = 400;
  289. }
  290. $type = (new GameModel())->where(['id'=>$gameId])->value('type');
  291. $subPath = $this->subChannel->index($channel_id, $gameId,session_id(), $type, $subPackageInfo['package_type']);
  292. if ($subPath['code'] == 400) {
  293. $code = $subPath['code'];
  294. $msg = $subPath['msg'];
  295. }
  296. $data = [
  297. 'msg' => $msg,
  298. 'code'=> $code
  299. ];
  300. return json($data);
  301. }
  302. }
  303. /**
  304. * 删除分包
  305. */
  306. public function deletePack()
  307. {
  308. $id = input('post.id');
  309. $gameId = input('gameid');
  310. $channel_id = input('channel_id');
  311. $msg = '成功!';
  312. $code = 200;
  313. //删包功能
  314. if(empty($id)){
  315. $this->error('分包ID不能为空');
  316. }
  317. $condition['id'] = $id;
  318. $condition['gameid'] = $gameId;
  319. $condition['channel_id']= $channel_id;
  320. $subPackageInfo = $this->sdkgamelistModel->where($condition)->find();
  321. if (empty($subPackageInfo['filename'])) {
  322. $msg = '抱歉没有文件名无法删包!';
  323. $code = 400;
  324. }
  325. $subChannel = $this->subChannel;
  326. $res = $subChannel->deletePackage($channel_id, $gameId,$subPackageInfo['package_type']); //删包
  327. if ($res['msg'] != 'success') {
  328. $msg = $res['msg'];
  329. $code = 400;
  330. }
  331. $data = [
  332. 'msg' => $msg,
  333. 'code'=> $code
  334. ];
  335. return json($data);
  336. }
  337. /**
  338. * 禁用/解禁
  339. */
  340. public function handleStatus()
  341. {
  342. $input = input();
  343. $msg = '操作成功!';
  344. $code = 200;
  345. if(empty($input['id']) || !in_array($input['status'], [0, 1])){
  346. $this->error('参数有误!');
  347. }
  348. $subPackageInfo = (new SdkGameList())->where(['id' => $input['id']])->find();
  349. if (empty($subPackageInfo['filename'])) {
  350. $msg = '操作分包不存在!';
  351. $code = 400;
  352. }
  353. $res = (new SdkGameList())->save(['status' => $input['status']], ['id' => $input['id']]);
  354. if (!$res) {
  355. $msg = '操作失败!';
  356. $code = 400;
  357. }
  358. return json(['msg' => $msg, 'code'=> $code]);
  359. }
  360. /**
  361. * 批量分包
  362. */
  363. public function batchsubpackage(){
  364. if (request()->isPost()) {
  365. $ids = input('ids');
  366. $resultLog = [];
  367. $ids = explode(',', $ids);
  368. foreach ($ids as $v) {
  369. if (!$v) {
  370. $resultLog[] = ['value' => $v, 'msg' => '参数有误!', 'code' => '-1'];
  371. continue;
  372. }
  373. $info = explode('_', $v);
  374. if (!isset($info[0]) || !isset($info[1])) {
  375. $resultLog[] = ['value' => $v, 'msg' => '渠道或游戏参数有误!', 'code' => '-2'];
  376. continue;
  377. }
  378. $platform = model('game')->where(['id' => $info[0]])->value('type');
  379. $res = $this->subChannel->index($info[1], $info[0], session_id(), $platform);
  380. if ($res['code'] === 0) {
  381. $resultLog[] = ['value' => $v, 'msg' => $res['msg'], 'code' => '1'];
  382. } else {
  383. $resultLog[] = ['value' => $v, 'msg' => $res['msg'], 'code' => '-3'];
  384. }
  385. }
  386. return json([
  387. 'code' => 1,
  388. 'msg' => '操作成功!',
  389. 'data' => $resultLog
  390. ]);
  391. }else{
  392. $this->assign('game_list', $this->selfGameList);
  393. return $this->fetch();
  394. }
  395. }
  396. /**
  397. * 是否有光环加速游戏记录
  398. */
  399. public function haveSpeedGame(){
  400. if (request()->isAjax()) {
  401. $game_id = input('post.game_id', '', 'intval');
  402. if(empty($game_id)){
  403. $this->error('游戏ID不能为空');
  404. }
  405. $gameaidInfo = Db::name('cy_gameaid')->where(['gameid'=>$game_id])->find();
  406. $this->result(['haveSpeedGame'=>($gameaidInfo ? true : false)],1);
  407. }
  408. else{
  409. $this->error('非法请求');
  410. }
  411. }
  412. /**
  413. * 定时更新游戏
  414. *
  415. */
  416. public function autoPackageList()
  417. {
  418. $where = [];
  419. //游戏名称
  420. if (input('request.game_id') != '') {
  421. $where['a.game_id'] = input('request.game_id');
  422. }
  423. //对接状态
  424. if (input('request.package_type') != '') {
  425. $where['a.package_type'] = input('request.package_type');
  426. }
  427. //SDK版本号
  428. if (input('request.status') != '') {
  429. $where['a.status'] = input('request.status');
  430. }
  431. //更新时间的开始时间和结束时间不为空时
  432. if (input('request.auto_update_time_start') != '' && input('request.auto_update_time_end') != '') {
  433. $where['a.auto_update_time'] = [
  434. ['>=', strtotime(input('request.auto_update_time_start').' 00:00:00')],
  435. ['<=', strtotime(input('request.auto_update_time_end').' 23:59:59')],
  436. ];
  437. }
  438. //更新时间的开始时间不为空时
  439. elseif (input('request.auto_update_time_start') != '') {
  440. $where['a.auto_update_time'] = ['>=', strtotime(input('request.auto_update_time_start').' 00:00:00')];
  441. }
  442. //更新时间的结束时间不为空时
  443. elseif (input('request.auto_update_time_end') != '') {
  444. $where['a.auto_update_time'] = ['<=', strtotime(input('request.auto_update_time_end').' 23:59:59')];
  445. }
  446. //更新时间的开始时间和结束时间不为空时
  447. if (input('request.create_time_start') != '' && input('request.create_time_end') != '') {
  448. $where['a.create_time'] = [
  449. ['>=', strtotime(input('request.create_time_start').' 00:00:00')],
  450. ['<=', strtotime(input('request.create_time_end').' 23:59:59')],
  451. ];
  452. }
  453. //更新时间的开始时间不为空时
  454. elseif (input('request.create_time_start') != '') {
  455. $where['a.create_time'] = ['>=', strtotime(input('request.create_time_start').' 00:00:00')];
  456. }
  457. //更新时间的结束时间不为空时
  458. elseif (input('request.create_time_end') != '') {
  459. $where['a.create_time'] = ['<=', strtotime(input('request.create_time_end').' 23:59:59')];
  460. }
  461. $autoPackageModel = new AutoPackage;
  462. $list = $autoPackageModel->table('nw_auto_package a,cy_game g')->field('a.*,g.name game_name')
  463. ->where('a.game_id=g.id')->where($where)->where("g.is_default = 0")->order('a.status asc,a.create_time desc')->paginate(10, false, ['query' => input('get.')]);
  464. $tmpGameList = $this->gameModel->field('id,name')->where(['cooperation_status'=>['in','1,2'],'id'=>['not in',$this->gameIOS]])->select();
  465. $gameList = array();
  466. foreach ($tmpGameList as $game) {
  467. $gameList[ $game['id']] = $game;
  468. }
  469. $versionList = (new AndroidSdk())->column('version', 'id');
  470. $this->assign('gameList',$gameList);
  471. $this->assign('list',$list);
  472. $this->assign('versionList',$versionList);
  473. $this->assign('page',$list->render());
  474. return $this->fetch('auto_package_list');
  475. }
  476. /**
  477. * 新增定时更新游戏
  478. *
  479. */
  480. public function autoPackageNew()
  481. {
  482. if(request()->isPost()){
  483. $autoPackageModel = new AutoPackage;
  484. $validate = new ValidateExtend();
  485. $data = [
  486. 'game_id' => input('post.game_id'),
  487. 'package_type' => input('post.package_type'),
  488. 'android_sdk_id' => input('post.android_sdk_id'),
  489. 'update_type' => input('post.update_type'),
  490. 'active_day' => input('post.active_day'),
  491. 'auto_update_time' => input('post.auto_update_time'),
  492. 'file_name' => input('post.file_name'),
  493. 'remark' => input('post.remark'),
  494. 'channel_version' => input('post.channel_version'),
  495. ];
  496. $data['channel_version'] = $data['update_type']==0 ? 0 : $data['channel_version'];
  497. $result = $this->validate($data, [
  498. ['game_id', 'require|integer', '请输入游戏名称|游戏ID必须为整型'],
  499. ['package_type', 'require|in:0,1', '请选择游戏包类型|游戏包类型参数错误'],
  500. ['android_sdk_id', 'require|integer', '请选择待更新SDK版本号|待更新SDK版本号必须为整型'],
  501. ['update_type', 'require|integer', '请选择更新类型|更新类型必须为整型'],
  502. ['active_day', 'require|integer', '请选择渠道活跃天数|渠道活跃天数必须为整型'],
  503. ['auto_update_time', 'require|date', '更新时间不能为空|更新时间格式不正确'],
  504. ['file_name', 'require|max:100|regex:/^[A-Za-z0-9._-]+$/', '待更新包名不能为空|待更新包名不能超过100个字符|待更新包名只能输入字符数字._-符号'],
  505. ['remark', 'max:800', '备注不能超过800个字符'],
  506. ]);
  507. if (true !== $result) {
  508. $this->error($result);
  509. }
  510. elseif(NOW_TIMESTAMP>strtotime($data['auto_update_time']))
  511. {
  512. $this->error('更新时间需大于当前时间');
  513. }
  514. elseif(mb_substr($data['file_name'],-4,NULL,'UTF-8')!='.apk' && mb_substr($data['file_name'],-4,NULL,'UTF-8')!='.ipa'){
  515. $this->error('待更新包名文件后缀错误');
  516. }
  517. elseif(mb_substr($data['file_name'],0,-4,'UTF-8')==$this->gameModel->where(['id'=>$data['game_id']])->value('pinyin')){
  518. $this->error('待更新包名文件不能与游戏拼音相同');
  519. }
  520. elseif($data['update_type']==1){
  521. if($data['channel_version']==''){
  522. $this->error('强更版本不能为空');
  523. }
  524. elseif (!$validate->is($data['channel_version'], 'positiveInteger') ) {
  525. $this->error('强更版本必须为正整数');
  526. }
  527. }
  528. if($autoPackageModel->where(['game_id'=>$data['game_id'],'status'=>0,'package_type'=>$data['package_type']])->find()){
  529. $this->error('已存在该更新内容');
  530. }
  531. $data['auto_update_time'] = strtotime($data['auto_update_time']);
  532. $data['update_time'] = NOW_TIMESTAMP;
  533. $data['create_time'] = NOW_TIMESTAMP;
  534. $data['admin_id'] = session('ADMIN_ID');
  535. $autoPackageModel->insert($data);
  536. $this->success('定时更新游戏新增成功', 'autoPackageList');
  537. }
  538. $tmpGameList = $this->gameModel->field('id,name')->where(['cooperation_status'=>['in','1,2'],'id'=>['not in',$this->gameIOS]])->select();
  539. $gameList = array();
  540. foreach ($tmpGameList as $game) {
  541. $gameList[ $game['id']] = $game;
  542. }
  543. $this->assign('version', (new AndroidSdk())->getAllVersion());
  544. $this->assign('gameList',$gameList);
  545. return $this->fetch('auto_package_new');
  546. }
  547. /**
  548. * 编辑定时更新游戏
  549. *
  550. */
  551. public function autoPackageEdit()
  552. {
  553. $id = input('id');
  554. $autoPackageModel = new AutoPackage;
  555. if(empty($id)){
  556. $this->error('id不能为空');
  557. }
  558. $info = $autoPackageModel->where(['id'=>$id,'status'=>0])->find();
  559. if(empty($info)){
  560. $this->error('定时更新游戏记录不存在');
  561. }
  562. //表单提交
  563. if(request()->isPost()){
  564. $validate = new ValidateExtend();
  565. $data = [
  566. 'package_type' => input('post.package_type'),
  567. 'android_sdk_id' => input('post.android_sdk_id'),
  568. 'update_type' => input('post.update_type'),
  569. 'active_day' => input('post.active_day'),
  570. 'auto_update_time' => input('post.auto_update_time'),
  571. 'file_name' => input('post.file_name'),
  572. 'remark' => input('post.remark'),
  573. 'channel_version' => input('post.channel_version'),
  574. ];
  575. $data['channel_version'] = $data['update_type']==0 ? 0 : $data['channel_version'];
  576. $result = $this->validate($data, [
  577. ['package_type', 'require|in:0,1', '请选择游戏包类型|游戏包类型参数错误'],
  578. ['android_sdk_id', 'require|integer', '请选择待更新SDK版本号|待更新SDK版本号必须为整型'],
  579. ['update_type', 'require|integer', '请选择更新类型|更新类型必须为整型'],
  580. ['active_day', 'require|integer', '请选择渠道活跃天数|渠道活跃天数必须为整型'],
  581. ['auto_update_time', 'require|date', '更新时间不能为空|更新时间格式不正确'],
  582. ['file_name', 'require|max:100|regex:/^[A-Za-z0-9._-]+$/', '待更新包名不能为空|待更新包名不能超过100个字符|待更新包名只能输入字符数字._-符号'],
  583. ['remark', 'max:800', '备注不能超过800个字符'],
  584. ]);
  585. if (true !== $result) {
  586. $this->error($result);
  587. }
  588. elseif(NOW_TIMESTAMP>strtotime($data['auto_update_time']))
  589. {
  590. $this->error('更新时间需大于当前时间');
  591. }
  592. elseif(mb_substr($data['file_name'],-4,NULL,'UTF-8')!='.apk' && mb_substr($data['file_name'],-4,NULL,'UTF-8')!='.ipa'){
  593. $this->error('待更新包名文件后缀错误');
  594. }
  595. elseif(mb_substr($data['file_name'],0,-4,'UTF-8')==$this->gameModel->where(['id'=>$info['game_id']])->value('pinyin')){
  596. $this->error('待更新包名文件不能与游戏拼音相同');
  597. }
  598. elseif($data['update_type']==1){
  599. if($data['channel_version']==''){
  600. $this->error('强更版本不能为空');
  601. }
  602. elseif (!$validate->is($data['channel_version'], 'positiveInteger') ) {
  603. $this->error('强更版本必须为正整数');
  604. }
  605. }
  606. if($autoPackageModel->where(['game_id'=>$info['game_id'],'status'=>0,'package_type'=>$data['package_type'],'id'=>['<>',$id]])->find()){
  607. $this->error('已存在该更新内容');
  608. }
  609. $data['auto_update_time'] = strtotime($data['auto_update_time']);
  610. $data['update_time'] = NOW_TIMESTAMP;
  611. $data['admin_id'] = session('ADMIN_ID');
  612. if($autoPackageModel->update($data,['id'=>$id])){
  613. $this->success('定时更新游戏编辑成功', 'autoPackageList');
  614. }
  615. else{
  616. $this->error('定时更新游戏编辑失败');
  617. }
  618. }
  619. $gameaidInfo = Db::name('cy_gameaid')->where(['gameid'=>$info['game_id']])->find();
  620. $info['haveSpeedGame'] = ($gameaidInfo ? true : false);
  621. $gameInfo = $this->gameModel->field('cooperation_status,pinyin,name')->where(['id'=>$info['game_id']])->find();
  622. $gameList = $this->gameModel->field('id,name')->where(['cooperation_status'=>['in','1,2'],'id'=>['not in',$this->gameIOS]])->select();
  623. $this->assign('version', (new AndroidSdk())->getAllVersion());
  624. $this->assign('gameList',$gameList);
  625. $this->assign('info',$info);
  626. $this->assign('gameInfo',$gameInfo);
  627. return $this->fetch('auto_package_edit');
  628. }
  629. /**
  630. * 删除定时更新游戏
  631. *
  632. */
  633. public function autoPackageDelete()
  634. {
  635. $id = input('id');
  636. $autoPackageModel = new AutoPackage;
  637. if(empty($id)){
  638. $this->error('id不能为空');
  639. }
  640. if($autoPackageModel->where(['id'=>$id])->delete()){
  641. $this->success('删除成功');
  642. }
  643. else{
  644. $this->error('删除失败');
  645. }
  646. }
  647. /**
  648. * 通过ajax获取游戏信息
  649. */
  650. public function ajaxGetGameInfo()
  651. {
  652. if(request()->isAjax()){
  653. $game_id = input('post.game_id');
  654. if(empty($game_id)){
  655. $this->error('游戏ID不能为空');
  656. }
  657. $info = $this->gameModel->field('cooperation_status,pinyin,channel_version,android_sdk_id')->where(['cooperation_status'=>['in','1,2'],'id'=>$game_id])->find();
  658. $gameaidInfo = Db::name('cy_gameaid')->where(['gameid'=>$game_id])->find();
  659. $info['haveSpeedGame'] = ($gameaidInfo ? true : false);
  660. $this->result($info,1);
  661. }
  662. else{
  663. $this->error('非法请求');
  664. }
  665. }
  666. // 批量更新
  667. public function approved(){
  668. $ids = input('ids');
  669. if(!$ids){
  670. $this->error('请选择要更新的记录');
  671. }
  672. $arr = explode(',',$ids);
  673. $packagelModel = model('PackageApply');
  674. foreach ($arr as $k=>$v){
  675. $data = explode('_',$v);
  676. $cont = [];
  677. if(!(isset($data[0]) && $data[0])){
  678. $this->error('非法请求');
  679. }
  680. if(!(isset($data[1]) && $data[1])){
  681. $this->error('非法请求');
  682. }
  683. $cont['game_id'] = $data[0];
  684. $cont['channel_id'] = $data[1];
  685. $cont['create_time'] = NOW_TIMESTAMP;
  686. $cont['apply_time'] = NOW_TIMESTAMP;
  687. $cont['apply_status'] = 0;
  688. if ($packagelModel->where(['game_id'=>$data[0],'channel_id'=>$data[1]])->find()) {
  689. $packagelModel->where(['game_id'=>$data[0],'channel_id'=>$data[1]])->update($cont);
  690. $this->sdkgamelistModel->where(['gameid'=>$data[0],'channel_id'=>$data[1]])->update(['upload_status' => 2]);
  691. }
  692. }
  693. $this->success("已经提交分包任务");
  694. }
  695. }