UpdateMediaPushRechargeInfo.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. namespace App\Console\Commands\SmartPush;
  3. use App\Modules\MediaPush\Models\MediaPushDayStats;
  4. use App\Modules\MediaPush\Models\OrderParam;
  5. use App\Modules\PersonalOp\Models\MediaPushDetailRecord;
  6. use DB;
  7. use Illuminate\Console\Command;
  8. class UpdateMediaPushRechargeInfo extends Command
  9. {
  10. /**
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'update_media_push_recharge_info';
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = '更新个性化推送带来的充值';
  22. /**
  23. * Create a new command instance.
  24. *
  25. * @return void
  26. */
  27. public function __construct()
  28. {
  29. parent::__construct();
  30. }
  31. /**
  32. * Execute the console command.
  33. *
  34. * @return mixed
  35. */
  36. public function handle()
  37. {
  38. $this->updateOneDayRechargeInfo();
  39. $this->updateThreeDayRechargeInfo();
  40. }
  41. public function updateOneDayRechargeInfo()
  42. {
  43. $start_time = $date = date('Y-m-d H:i:s', strtotime('-1 day'));
  44. $params = ['is_one_day' => 1, 'start_time' => $start_time];
  45. $info = MediaPushDetailRecord::getUnUpdatedInfos($params);
  46. $officialChargeAmountArray = [];
  47. foreach ($info as $item) {
  48. $push_time = $item->push_time;
  49. $promotion_id = $item->promotion_id;
  50. $end_time = date('Y-m-d H:i:s', strtotime($item->push_time) + 86400);
  51. $params = ['start_time' => $push_time, 'end_time' => $end_time, 'promotion_id' => $promotion_id];;
  52. $recharge_in_one_day = OrderParam::getChargeAmount($params);
  53. $item->recharge_in_one_day = $recharge_in_one_day;
  54. $item->save();
  55. //更新dayStats表
  56. $appid = $item->appid;
  57. $date = date('Y-m-d', strtotime($item->push_time));
  58. if (isset($officialChargeAmountArray[$date][$appid])) {
  59. $officialChargeAmountArray[$date][$appid] = $officialChargeAmountArray[$date][$appid] + $recharge_in_one_day;
  60. } else {
  61. $officialChargeAmountArray[$date][$appid] = $recharge_in_one_day;
  62. }
  63. }
  64. foreach ($officialChargeAmountArray as $k => $v) {
  65. foreach ($v as $index => $value) {
  66. $date = $k;
  67. $appid = $index;
  68. $recharge_in_one_day = $value;
  69. $mediaPushDayInfo = MediaPushDayStats::getByAppidAndDate($appid, $date);
  70. if ($mediaPushDayInfo) {
  71. if (empty($mediaPushDayInfo->recharge_in_one_day)) {
  72. $mediaPushDayInfo->recharge_in_one_day = $recharge_in_one_day;
  73. } else {
  74. $mediaPushDayInfo->recharge_in_one_day += $recharge_in_one_day;
  75. }
  76. $mediaPushDayInfo->save();
  77. }
  78. }
  79. }
  80. }
  81. public function updateThreeDayRechargeInfo()
  82. {
  83. $start_time = $date = date('Y-m-d H:i:s', strtotime('-3 day'));
  84. $params = ['is_three_day' => 1, 'start_time' => $start_time];
  85. $info = MediaPushDetailRecord::getUnUpdatedInfos($params);
  86. $officialChargeAmountArray = [];
  87. foreach ($info as $item) {
  88. $push_time = $item->push_time;
  89. $promotion_id = $item->promotion_id;
  90. $end_time = date('Y-m-d H:i:s', strtotime($item->push_time) + 3 * 86400);
  91. $params = ['start_time' => $push_time, 'end_time' => $end_time, 'promotion_id' => $promotion_id];;
  92. $recharge_in_three_days = OrderParam::getChargeAmount($params);
  93. $item->recharge_in_three_days = $recharge_in_three_days;
  94. $item->save();
  95. //更新dayStats表
  96. $appid = $item->appid;
  97. $date = date('Y-m-d', strtotime($item->push_time));
  98. if (isset($officialChargeAmountArray[$date][$appid])) {
  99. $officialChargeAmountArray[$date][$appid] = $officialChargeAmountArray[$date][$appid] + $recharge_in_three_days;
  100. } else {
  101. $officialChargeAmountArray[$date][$appid] = $recharge_in_three_days;
  102. }
  103. }
  104. foreach ($officialChargeAmountArray as $k => $v) {
  105. foreach ($v as $index => $value) {
  106. $date = $k;
  107. $appid = $index;
  108. $recharge_in_three_days = $value;
  109. $mediaPushDayInfo = MediaPushDayStats::getByAppidAndDate($appid, $date);
  110. if ($mediaPushDayInfo) {
  111. if (empty($mediaPushDayInfo->recharge_in_three_days)) {
  112. $mediaPushDayInfo->recharge_in_three_days = $recharge_in_three_days;
  113. } else {
  114. $mediaPushDayInfo->recharge_in_three_days = $mediaPushDayInfo->recharge_in_three_days + $recharge_in_three_days;
  115. }
  116. $mediaPushDayInfo->save();
  117. }
  118. }
  119. }
  120. }
  121. }