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'); } }