企微短剧业务系统

PlayletDataRepair.php 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shensong
  5. * Date: 2023/7/7
  6. * Time: 11:01
  7. */
  8. namespace App\Console\Repair;
  9. use App\Log;
  10. use App\Models\PlayletTrendStatistics;
  11. use Illuminate\Console\Command;
  12. class PlayletDataRepair extends Command
  13. {
  14. protected $signature = 'PlayletDataRepair';
  15. protected $description = '更新短剧数据3天7天倍率';
  16. /**
  17. * Create a new command instance.
  18. *
  19. * @return void
  20. */
  21. public function __construct()
  22. {
  23. \DB::disableQueryLog();
  24. set_time_limit(0);
  25. ini_set('memory_limit', -1);
  26. parent::__construct();
  27. }
  28. public function handle()
  29. {
  30. $this->infoMessage(date('Y-m-d H:i:s') . ' 开始执行~');
  31. # 获取待处理数据
  32. $dataList = PlayletTrendStatistics::query()->where('enable', 1)
  33. ->where('ref_date', '>=', date('Y-m-d', strtotime('-30 days')))->get()->toArray();
  34. foreach($dataList as $data) {
  35. $charge_data = json_decode($data['charge_data'], 1);
  36. $item = [];
  37. $refDate = $data['ref_date'];
  38. self::dealDaysCharge($refDate, $item, $charge_data);
  39. PlayletTrendStatistics::query()->where('id', $data['id'])->update($item);
  40. }
  41. $this->infoMessage(date('Y-m-d H:i:s') . ' 结束执行~');
  42. return ;
  43. }
  44. public static function dealDaysCharge($refDate, &$item, $charge_data) {
  45. $item['day3_charge'] = 0;
  46. $item['day7_charge'] = 0;
  47. for ($i = 0; $i < 7; $i++) {
  48. if($i < 3) {
  49. $item['day3_charge'] += (!empty($charge_data[$i]['day_charge']) ? $charge_data[$i]['day_charge'] : 0);
  50. }
  51. if($i < 7) {
  52. $item['day7_charge'] += (!empty($charge_data[$i]['day_charge']) ? $charge_data[$i]['day_charge'] : 0);
  53. }
  54. }
  55. if(strtotime(date('Y-m-d')) - strtotime($refDate) < 2 * 86400) {
  56. $item['day3_charge'] = 0;
  57. $item['day7_charge'] = 0;
  58. } else if(strtotime(date('Y-m-d')) - strtotime($refDate) < 6 * 86400) {
  59. $item['day7_charge'] = 0;
  60. }
  61. }
  62. public static function infoMessage($message)
  63. {
  64. echo date('Y-m-d H:i:s') . $message .' 内存占用:'.round(memory_get_usage()/1024/1024, 2).'MB'. "\r\n";
  65. Log::logInfo(date('Y-m-d H:i:s') . ' ' .$message .' 内存占用:'.round(memory_get_usage()/1024/1024, 2).'MB', [], 'PlayletDataStatistics');
  66. }
  67. }