model = new \app\common\model\MallDailyPush(); } /** * 查看 * @throws Throwable */ public function index(Request $request): Response { $response = $this->initializeBackend($request); if ($response !== null) { return $response; } if ($request->get('select') || $request->post('select')) { return $this->select($request); } return $this->_index(); } /** * 按历史 mall_daily_push 记录回补用户信息 */ public function backfillUsers(Request $request): Response { $response = $this->initializeBackend($request); if ($response !== null) { return $response; } $dateFrom = trim(strval($request->post('date_from', $request->get('date_from', '')))); $dateTo = trim(strval($request->post('date_to', $request->get('date_to', '')))); $limitRaw = strval($request->post('limit', $request->get('limit', '0'))); $dryRunRaw = strval($request->post('dry_run', $request->get('dry_run', '0'))); if ($dateFrom !== '' && !$this->isValidDate($dateFrom)) { return $this->error('date_from 格式错误,需为 YYYY-MM-DD'); } if ($dateTo !== '' && !$this->isValidDate($dateTo)) { return $this->error('date_to 格式错误,需为 YYYY-MM-DD'); } if (!is_numeric($limitRaw)) { return $this->error('limit 必须是数字'); } $limit = intval($limitRaw); if ($limit < 0) { return $this->error('limit 不能小于 0'); } $dryRun = in_array(strtolower($dryRunRaw), ['1', 'true', 'yes', 'on'], true); $service = new MallDailyPushBackfill(); $result = $service->backfill( $dateFrom === '' ? null : $dateFrom, $dateTo === '' ? null : $dateTo, $limit, $dryRun ); return $this->success('', $result); } private function isValidDate(string $value): bool { $dt = \DateTime::createFromFormat('Y-m-d', $value); if (!$dt) { return false; } return $dt->format('Y-m-d') === $value; } }