AutoPackage.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * 定时更新游戏定时器脚本
  4. *
  5. */
  6. namespace app\crontab;
  7. set_time_limit(0);
  8. use think\console\Command;
  9. use think\console\Input;
  10. use think\console\Output;
  11. use app\common\logic\SubPackage as SubChannel;
  12. use app\common\model\Game;
  13. use app\common\model\AutoPackage as AutoPackageModel;
  14. class AutoPackage extends Command {
  15. protected $now_time; //当前时间
  16. protected $_output;
  17. protected function configure() {
  18. $this->setName('AutoPackage')->setDescription('定时更新游戏');
  19. }
  20. protected function execute(Input $input, Output $output) {
  21. ini_set('memory_limit', '1024M');
  22. $this->now_time = time();
  23. $this->_output = $output;
  24. $output->writeln(date('Y-m-d H:i:s')." AutoPackage start\r\n");
  25. $this->updateGamePackage();
  26. $output->writeln(date('Y-m-d H:i:s')." AutoPackage end\r\n");
  27. exit;
  28. }
  29. /**
  30. * 更新游戏包体处理
  31. *
  32. */
  33. private function updateGamePackage()
  34. {
  35. $gameModel = new Game;
  36. $subChannel = new SubChannel;
  37. $autoPackageModel = new AutoPackageModel;
  38. $autoPackageList = $autoPackageModel->table('nw_auto_package a,cy_game g')->field('a.*,g.pinyin')->where('a.game_id=g.id')->where(['a.status'=>0,'a.auto_update_time'=>['<=',$this->now_time]])->select();
  39. if(!empty($autoPackageList)){
  40. foreach($autoPackageList as $value){
  41. //光环加速包
  42. if($value['package_type']==1){
  43. $path = '/data/www/aoyou/download/sygameguanghuan/'.$value['pinyin'].'/';
  44. }
  45. else{
  46. $path = '/data/www/aoyou/download/sygame/'.$value['pinyin'].'/';
  47. }
  48. if($this->checkPackageFile($path,$value['file_name'])){
  49. $path_parts = pathinfo($value['file_name']);
  50. //待更新的包替换成游戏拼音包
  51. if(rename($path.$value['file_name'], $path.$value['pinyin'].".".$path_parts['extension'])){
  52. $gameData['android_sdk_id'] = $value['android_sdk_id'];
  53. //强更
  54. if($value['update_type']==1){
  55. $gameData['channel_version'] = $value['channel_version'];
  56. }
  57. //更新游戏信息
  58. $gameModel->update($gameData,['id'=>$value['game_id']]);
  59. $res = $subChannel->batchSubpackageByActiveDay($value['game_id'], $value['active_day'], $value['package_type'], $value['admin_id']);
  60. //更新定时更新游戏的记录状态
  61. $autoPackageModel->update(['status'=>1,'update_time'=>$this->now_time],['id'=>$value['id']]);
  62. $this->_output->writeln("游戏ID:".$value['game_id']."的批量分包结果:".print_r($res,true)." \r\n");
  63. }
  64. else{
  65. $autoPackageModel->update(['status'=>2,'update_time'=>$this->now_time,'result'=>'待更新的包替换成游戏拼音母包失败'],['id'=>$value['id']]);
  66. $this->_output->writeln("待更新的包替换成游戏拼音包失败: ".$value['file_name'].",定时更新游戏的记录ID:".$value['id']." \r\n");
  67. }
  68. }
  69. else{
  70. $autoPackageModel->update(['status'=>2,'update_time'=>$this->now_time,'result'=>'待更新的包不存在'],['id'=>$value['id']]);
  71. $this->_output->writeln("待更新的包不存在: ".$value['file_name'].",定时更新游戏的记录ID:".$value['id']." \r\n");
  72. }
  73. }
  74. }
  75. }
  76. /**
  77. * 获得指定时间内有流水的渠道ID
  78. *
  79. * @param $path
  80. * @param $file_name int 指定的天数
  81. *
  82. * @return boolean
  83. *
  84. */
  85. private function checkPackageFile($path,$file_name)
  86. {
  87. if (file_exists($path.$file_name)) {
  88. return true;
  89. } else {
  90. return false;
  91. }
  92. }
  93. }