getDateTime(); $time = $datetime->copy()->subMonths(self::INTERVAL_MONTH); $this->info('自动激活脚本'); $simArray = sprintf("SELECT sim FROM virtual_order_cards WHERE created_at >= '%s' AND created_at <= '%s' AND service_start_at IS NULL ORDER BY created_at DESC", $time->copy()->startOfMonth(), $time->copy()->endOfMonth()); $updateSql = "UPDATE cards SET virtual_activated_at='%s' WHERE sim IN (%s) AND virtual_activated_at IS NULL"; DB::statement(sprintf($updateSql, $datetime->startOfMonth(), $simArray)); $fixSql = "SELECT fix_timelines(ARRAY(%s))"; DB::statement(sprintf($fixSql, $simArray)); app(CardRepository::class)->forgetCached(); app(OrderCardPartitionRepository::class)->forgetCached(); $this->info('自动激活脚本执行完毕'); } protected function getDateTime() { if ($month = $this->argument('month')) { if (!preg_match('/\d{4}-\d{1,2}/', $month)) { throw new \App\Exceptions\InvalidArgumentException('请输入正确的年月 #示例: 2018-10'); } return Carbon::parse($month)->startOfMonth(); } return Carbon::now()->startOfMonth(); } protected function getArguments() { return [ ['month', InputArgument::OPTIONAL, '要同步的数据月份,默认上个月 #示例: 2018-10'], ]; } }