123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- /**
- * Created by PhpStorm.
- * User: shensong
- * Date: 2023/7/7
- * Time: 11:01
- */
- namespace App\Console\Repair;
- use App\Log;
- use App\Models\PlayletTrendStatistics;
- use Illuminate\Console\Command;
- class PlayletDataRepair extends Command
- {
- protected $signature = 'PlayletDataRepair';
- protected $description = '更新短剧数据3天7天倍率';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- \DB::disableQueryLog();
- set_time_limit(0);
- ini_set('memory_limit', -1);
- parent::__construct();
- }
- public function handle()
- {
- $this->infoMessage(date('Y-m-d H:i:s') . ' 开始执行~');
- # 获取待处理数据
- $dataList = PlayletTrendStatistics::query()->where('enable', 1)
- ->where('ref_date', '>=', date('Y-m-d', strtotime('-30 days')))->get()->toArray();
- foreach($dataList as $data) {
- $charge_data = json_decode($data['charge_data'], 1);
- $item = [];
- $refDate = $data['ref_date'];
- self::dealDaysCharge($refDate, $item, $charge_data);
- PlayletTrendStatistics::query()->where('id', $data['id'])->update($item);
- }
- $this->infoMessage(date('Y-m-d H:i:s') . ' 结束执行~');
- return ;
- }
- public static function dealDaysCharge($refDate, &$item, $charge_data) {
- $item['day3_charge'] = 0;
- $item['day7_charge'] = 0;
- for ($i = 0; $i < 7; $i++) {
- if($i < 3) {
- $item['day3_charge'] += (!empty($charge_data[$i]['day_charge']) ? $charge_data[$i]['day_charge'] : 0);
- }
- if($i < 7) {
- $item['day7_charge'] += (!empty($charge_data[$i]['day_charge']) ? $charge_data[$i]['day_charge'] : 0);
- }
- }
- if(strtotime(date('Y-m-d')) - strtotime($refDate) < 2 * 86400) {
- $item['day3_charge'] = 0;
- $item['day7_charge'] = 0;
- } else if(strtotime(date('Y-m-d')) - strtotime($refDate) < 6 * 86400) {
- $item['day7_charge'] = 0;
- }
- }
- public static function infoMessage($message)
- {
- echo date('Y-m-d H:i:s') . $message .' 内存占用:'.round(memory_get_usage()/1024/1024, 2).'MB'. "\r\n";
- Log::logInfo(date('Y-m-d H:i:s') . ' ' .$message .' 内存占用:'.round(memory_get_usage()/1024/1024, 2).'MB', [], 'PlayletDataStatistics');
- }
- }
|