Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. <?php
  2. /**
  3. * バッチ
  4. * 開発:env APPLICATION_ENV=devel3004 sudo php batch.php [provider_id]
  5. * 本番:env APPLICATION_ENV=production sudo php batch.php [provider_id]
  6. *
  7. */
  8. // プラットフォームを設定
  9. //$provider_id = $argv[1];
  10.  
  11. ini_set( "memory_limit", "-1" );
  12. defined( 'APPLICATION_ENV' )
  13. || define( 'APPLICATION_ENV', ( getenv( 'APPLICATION_ENV' ) ? getenv( 'APPLICATION_ENV' ) : 'devel' ) );
  14. define( 'PROVIDER_ID', 'gree' );
  15.  
  16. $sy_home = getenv( 'SYNPHONIE_HOME' ) ? getenv( 'SYNPHONIE_HOME' ) : '/home/sy';
  17. require_once $sy_home . '/bin/drpr/autoload.php';
  18. if ( APPLICATION_ENV == 'devel' ) {
  19. S::setLogLevel('debug');
  20. } else {
  21. S::setLogLevel('info');
  22. }
  23. S::setLogDir( '/logs/' . APP_NAME . '/' . PROVIDER_ID . '/zend' );
  24.  
  25. $db = new Synphonie_Framework_Model_Db();
  26.  
  27.  
  28. $csv_file = isset($argv[1]) ? $argv[1] : 'drpr20190312.csv';
  29. $dryrun_mode = isset( $argv[ 2 ] ) ? $argv[2] : 0;
  30.  
  31. if(!file_exists($csv_file)) die($csv_file.' is not exists');
  32.  
  33. $path_info = pathinfo( __FILE__ );
  34. $log_file = realpath( dirname( __FILE__ ) ) . '/' . $path_info['filename'] . '.log';
  35. $fp_log = fopen( $log_file, "a");
  36.  
  37. $f = file($csv_file);
  38. $header = true;
  39. $result = array();
  40. foreach($f as $v){
  41. if ($header) {
  42. $header = false;
  43. continue;
  44. }
  45. if(trim($v)){
  46. list($pf, $ins_date, $uid, $card_id, $level, $bexp, $aexp) = $separate = explode(',',trim($v));
  47. $ins_date = substr($ins_date, 1, -5);
  48. $pf = str_replace('"', '', $pf);
  49. $uid = str_replace('"', '', $uid);
  50. $card_id = str_replace('"', '', $card_id);
  51.  
  52. $material_ids = array();
  53. for ($i = 7; $i <= count($separate) - 1; $i++) {
  54. $material_id = $separate[$i];
  55. $material_id = str_replace('"', '', $material_id);
  56. $material_id = str_replace('[', '', $material_id);
  57. $material_id = str_replace(']', '', $material_id);
  58. $material_ids[] = $material_id;
  59. }
  60. $base_card = new App_Master_Card($card_id, $level, $bexp);
  61.  
  62. $material_cards = null;
  63. foreach ($material_ids as $material_id) {
  64. $material_cards[] = App_Master_Card::getInstance($material_id);
  65. }
  66. $cost = 0;
  67. foreach ($material_cards as $material_card) {
  68. $add_cost = ($bexp * 10) + ($material_card->getExp() * 15);
  69. if (strtotime($ins_date) >= strtotime('2019-03-11 16:00:00')) {
  70. $add_cost = floor( $add_cost * App_Enhancement::ENHANCEMENT_COST_RATE );
  71. }
  72. $cost += $add_cost;
  73. }
  74.  
  75.  
  76. if (isset($result[$pf][$uid])) {
  77. $result[$pf][$uid] = array(
  78. 'cost' => $result[$pf][$uid]['cost'] + $cost,
  79. 'mate' => array_merge($result[$pf][$uid]['mate'], $material_ids),
  80. );
  81. } else {
  82. $result[$pf][$uid] = array(
  83. 'cost' => $cost,
  84. 'mate' => $material_ids,
  85. );
  86. }
  87. }
  88. }
  89. foreach ($result as $pf => $pf_list) {
  90. foreach ($pf_list as $uid => $value) {
  91. echo $pf . 'tab' . $uid . 'tab' . $value['cost'] . 'tab' . json_encode($value['mate']) . PHP_EOL;
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement