优化每日推送创建(更新)用户资产
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace app\admin\controller\mall;
|
||||
|
||||
use Throwable;
|
||||
use app\common\library\MallDailyPushBackfill;
|
||||
use app\common\controller\Backend;
|
||||
use support\Response;
|
||||
use Webman\Http\Request;
|
||||
@@ -57,5 +58,55 @@ class DailyPush extends Backend
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user