API-优化每日推送接口
This commit is contained in:
@@ -173,16 +173,6 @@ class Playx extends Api
|
||||
}
|
||||
}
|
||||
|
||||
$requestId = $body['request_id'] ?? '';
|
||||
$date = $body['date'] ?? '';
|
||||
$playxUserId = strval($body['user_id'] ?? '');
|
||||
$yesterdayWinLossNet = $body['yesterday_win_loss_net'] ?? 0;
|
||||
$yesterdayTotalDeposit = $body['yesterday_total_deposit'] ?? 0;
|
||||
|
||||
if ($requestId === '' || $date === '' || $playxUserId === '') {
|
||||
return $this->error(__('Missing required fields: request_id, date, user_id'));
|
||||
}
|
||||
|
||||
$secret = config('playx.daily_push_secret', '');
|
||||
if ($secret !== '') {
|
||||
$sig = $request->header('X-Signature', '');
|
||||
@@ -198,6 +188,130 @@ class Playx extends Api
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 新版批量上报格式 =====
|
||||
// 兼容你们截图:{ report_date, member:[{member_id, login, lty_deposit, lty_withdrawal, yesterday_total_w, yesterday_total_deposit}, ...] }
|
||||
if (isset($body['report_date']) && isset($body['member']) && is_array($body['member'])) {
|
||||
$reportDate = $body['report_date'];
|
||||
$date = '';
|
||||
if (is_numeric($reportDate)) {
|
||||
$date = date('Y-m-d', intval($reportDate));
|
||||
} else {
|
||||
$date = strval($reportDate);
|
||||
}
|
||||
|
||||
$members = $body['member'];
|
||||
if ($date === '' || empty($members)) {
|
||||
return $this->error(__('Missing required fields: report_date, member'));
|
||||
}
|
||||
|
||||
$requestId = strval($body['request_id'] ?? '');
|
||||
if ($requestId === '') {
|
||||
$requestId = 'report_' . $date;
|
||||
}
|
||||
|
||||
$returnRatio = config('playx.return_ratio', 0.1);
|
||||
$unlockRatio = config('playx.unlock_ratio', 0.1);
|
||||
|
||||
$results = [];
|
||||
$allDeduped = true;
|
||||
|
||||
foreach ($members as $m) {
|
||||
$playxUserId = strval($m['member_id'] ?? '');
|
||||
if ($playxUserId === '') {
|
||||
return $this->error(__('Missing required fields: member_id'));
|
||||
}
|
||||
|
||||
$username = strval($m['login'] ?? '');
|
||||
$yesterdayWinLossNet = $m['yesterday_total_w'] ?? 0;
|
||||
$yesterdayTotalDeposit = $m['yesterday_total_deposit'] ?? 0;
|
||||
$lifetimeTotalDeposit = $m['lty_deposit'] ?? 0;
|
||||
$lifetimeTotalWithdraw = $m['lty_withdrawal'] ?? 0;
|
||||
|
||||
$exists = MallPlayxDailyPush::where('user_id', $playxUserId)->where('date', $date)->find();
|
||||
if ($exists) {
|
||||
$results[] = [
|
||||
'user_id' => $playxUserId,
|
||||
'deduped' => true,
|
||||
'accepted' => true,
|
||||
'message' => __('Duplicate input'),
|
||||
];
|
||||
continue;
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
MallPlayxDailyPush::create([
|
||||
'user_id' => $playxUserId,
|
||||
'date' => $date,
|
||||
'username' => $username,
|
||||
'yesterday_win_loss_net' => $yesterdayWinLossNet,
|
||||
'yesterday_total_deposit' => $yesterdayTotalDeposit,
|
||||
'lifetime_total_deposit' => $lifetimeTotalDeposit,
|
||||
'lifetime_total_withdraw' => $lifetimeTotalWithdraw,
|
||||
'create_time' => time(),
|
||||
]);
|
||||
|
||||
$newLocked = 0;
|
||||
if ($yesterdayWinLossNet < 0) {
|
||||
$newLocked = intval(round(abs(floatval($yesterdayWinLossNet)) * $returnRatio));
|
||||
}
|
||||
$todayLimit = intval(round(floatval($yesterdayTotalDeposit) * $unlockRatio));
|
||||
|
||||
$asset = $this->ensureAssetForPlayx($playxUserId, $username);
|
||||
if (!$asset) {
|
||||
throw new \RuntimeException(__('Failed to map playx user to mall user'));
|
||||
}
|
||||
|
||||
if ($asset->today_limit_date !== $date) {
|
||||
$asset->today_claimed = 0;
|
||||
$asset->today_limit_date = $date;
|
||||
}
|
||||
|
||||
$asset->locked_points = intval($asset->locked_points ?? 0) + $newLocked;
|
||||
$asset->today_limit = $todayLimit;
|
||||
$asset->playx_user_id = $playxUserId;
|
||||
|
||||
$uname = trim($username);
|
||||
if ($uname !== '') {
|
||||
$asset->username = $uname;
|
||||
}
|
||||
$asset->save();
|
||||
|
||||
Db::commit();
|
||||
|
||||
$results[] = [
|
||||
'user_id' => $playxUserId,
|
||||
'deduped' => false,
|
||||
'accepted' => true,
|
||||
'message' => __('Ok'),
|
||||
];
|
||||
$allDeduped = false;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return $this->success('', [
|
||||
'request_id' => $requestId,
|
||||
'accepted' => true,
|
||||
'deduped' => $allDeduped,
|
||||
'message' => $allDeduped ? __('Duplicate input') : __('Ok'),
|
||||
'results' => $results,
|
||||
]);
|
||||
}
|
||||
|
||||
// ===== 旧版单条上报格式(兼容)=====
|
||||
$requestId = $body['request_id'] ?? '';
|
||||
$date = $body['date'] ?? '';
|
||||
$playxUserId = strval($body['user_id'] ?? '');
|
||||
$yesterdayWinLossNet = $body['yesterday_win_loss_net'] ?? 0;
|
||||
$yesterdayTotalDeposit = $body['yesterday_total_deposit'] ?? 0;
|
||||
|
||||
if ($requestId === '' || $date === '' || $playxUserId === '') {
|
||||
return $this->error(__('Missing required fields: request_id, date, user_id'));
|
||||
}
|
||||
|
||||
$exists = MallPlayxDailyPush::where('user_id', $playxUserId)->where('date', $date)->find();
|
||||
if ($exists) {
|
||||
return $this->success('', [
|
||||
@@ -221,10 +335,9 @@ class Playx extends Api
|
||||
'create_time' => time(),
|
||||
]);
|
||||
|
||||
$newLocked = 0;
|
||||
$returnRatio = config('playx.return_ratio', 0.1);
|
||||
$unlockRatio = config('playx.unlock_ratio', 0.1);
|
||||
|
||||
$newLocked = 0;
|
||||
if ($yesterdayWinLossNet < 0) {
|
||||
$newLocked = intval(round(abs(floatval($yesterdayWinLossNet)) * $returnRatio));
|
||||
}
|
||||
@@ -234,14 +347,16 @@ class Playx extends Api
|
||||
if (!$asset) {
|
||||
throw new \RuntimeException(__('Failed to map playx user to mall user'));
|
||||
}
|
||||
$todayLimitDate = $date;
|
||||
if ($asset->today_limit_date !== $todayLimitDate) {
|
||||
|
||||
if ($asset->today_limit_date !== $date) {
|
||||
$asset->today_claimed = 0;
|
||||
$asset->today_limit_date = $todayLimitDate;
|
||||
$asset->today_limit_date = $date;
|
||||
}
|
||||
|
||||
$asset->locked_points = intval($asset->locked_points ?? 0) + $newLocked;
|
||||
$asset->today_limit = $todayLimit;
|
||||
$asset->playx_user_id = $playxUserId;
|
||||
|
||||
$uname = trim(strval($body['username'] ?? ''));
|
||||
if ($uname !== '') {
|
||||
$asset->username = $uname;
|
||||
|
||||
Reference in New Issue
Block a user