setName('UserCollectUpdate') ->addOption('current_time', 'c', Option::VALUE_OPTIONAL, '时间节点:2019-08-11', null) ->addOption('type', 't', Option::VALUE_OPTIONAL, '执行类型', 0) ->setDescription('用户按月和汇总统计'); } public function execute(Input $input, Output $output) { Request::instance()->module('admin'); //初始化 if ($input->getOption('type')) { $end_time = time() - 86400; $current_time = strtotime($input->getOption('current_time')); while ($current_time < $end_time) { $this->start($current_time); $current_time += 86400; } } else { $current_time = strtotime($input->getOption('current_time')); if (!$current_time) { //默认取昨天 $current_time = time() - 86400; } $this->start($current_time); } } public function start($current_time) { $msg = 'processing:'.date('Y-m-d H:i:s', $current_time) . "\n"; echo $msg; LogService::debug($msg); UserCollectUpdateService::instance()->setCurrentTime($current_time); $types = [ UserConstants::USER_COLLECT_TYPE_MONTH, UserConstants::USER_COLLECT_TYPE_TOTAL, ]; $admin_list = UserCollectUpdateService::instance()->getAdminIdsToUpdate()->data; foreach ($types as $type) { if ($admin_list) { array_push($admin_list, 0); foreach (array_chunk($admin_list, 100) as $admin_ids) { try { $list = UserCollectUpdateService::instance()->getUserCollectData($type, $admin_ids)->data; UserCollectUpdateService::instance()->insertOrUpdateCollect($list); } catch (\Exception $e) { LogService::exception($e); } } } } } }