更新每日推送数据的保存

This commit is contained in:
2026-07-22 11:00:42 +08:00
parent 140a068b88
commit b2b4fd4fbc
7 changed files with 621 additions and 61 deletions

View File

@@ -89,22 +89,15 @@ class Playx extends Api
return null;
}
private function buildTempPhone(): ?string
{
for ($i = 0; $i < 8; $i++) {
$candidate = '13' . str_pad(strval(mt_rand(0, 999999999)), 9, '0', STR_PAD_LEFT);
if (!MallUserAsset::where('phone', $candidate)->find()) {
return $candidate;
}
}
return null;
}
private function ensureAssetForPlayx(string $playxUserId, string $username): ?MallUserAsset
private function ensureAssetForPlayx(string $playxUserId, string $username, string $phone = ''): ?MallUserAsset
{
$phone = trim($phone);
$asset = MallUserAsset::where('playx_user_id', $playxUserId)->find();
if ($asset) {
if ($phone !== '' && trim(strval($asset->phone ?? '')) === '') {
$asset->phone = $phone;
$asset->save();
}
return $asset;
}
@@ -115,15 +108,14 @@ class Playx extends Api
$byName = MallUserAsset::where('username', $effectiveUsername)->find();
if ($byName) {
$byName->playx_user_id = $playxUserId;
if ($phone !== '' && trim(strval($byName->phone ?? '')) === '') {
$byName->phone = $phone;
}
$byName->save();
return $byName;
}
$phone = $this->buildTempPhone();
if ($phone === null) {
return null;
}
$pwd = hash_password(Random::build('alnum', 16));
$now = time();
@@ -151,9 +143,17 @@ class Playx extends Api
/**
* 按每日推送记录同步用户资产主信息applyAssetDelta=true 时才落资产增量。
*/
private function syncAssetByDailyPush(string $playxUserId, string $username, string $date, int $newLocked, int $todayLimit, bool $applyAssetDelta): ?MallUserAsset
private function syncAssetByDailyPush(
string $playxUserId,
string $username,
string $date,
int $newLocked,
int $todayLimit,
bool $applyAssetDelta,
string $phone = ''
): ?MallUserAsset
{
$asset = $this->ensureAssetForPlayx($playxUserId, $username);
$asset = $this->ensureAssetForPlayx($playxUserId, $username, $phone);
if (!$asset) {
return null;
}
@@ -215,7 +215,7 @@ class Playx extends Api
}
// ===== 新版批量上报格式 =====
// 兼容你们截图:{ report_date, member:[{member_id, login, lty_deposit, lty_withdrawal, yesterday_total_w, yesterday_total_deposit}, ...] }
// 当前字段为 ltv_depositltv_withdrawalyesterday_total_wl同时兼容早期错误字段名。
if (isset($body['report_date']) && isset($body['member']) && is_array($body['member'])) {
$reportDate = $body['report_date'];
$date = '';
@@ -249,10 +249,11 @@ class Playx extends Api
}
$username = strval($m['login'] ?? '');
$yesterdayWinLossNet = $m['yesterday_total_w'] ?? 0;
$phone = trim(strval($m['phone'] ?? ($m['mobile'] ?? '')));
$yesterdayWinLossNet = $m['yesterday_total_wl'] ?? ($m['yesterday_total_w'] ?? 0);
$yesterdayTotalDeposit = $m['yesterday_total_deposit'] ?? 0;
$lifetimeTotalDeposit = $m['lty_deposit'] ?? 0;
$lifetimeTotalWithdraw = $m['lty_withdrawal'] ?? 0;
$lifetimeTotalDeposit = $m['ltv_deposit'] ?? ($m['lty_deposit'] ?? 0);
$lifetimeTotalWithdraw = $m['ltv_withdrawal'] ?? ($m['lty_withdrawal'] ?? 0);
$exists = MallDailyPush::where('user_id', $playxUserId)->where('date', $date)->find();
if ($exists) {
@@ -261,7 +262,7 @@ class Playx extends Api
$newLocked = intval(round(abs(floatval($yesterdayWinLossNet)) * $returnRatio));
}
$todayLimit = intval(round(floatval($yesterdayTotalDeposit) * $unlockRatio));
$asset = $this->syncAssetByDailyPush($playxUserId, $username, $date, $newLocked, $todayLimit, false);
$asset = $this->syncAssetByDailyPush($playxUserId, $username, $date, $newLocked, $todayLimit, false, $phone);
if (!$asset) {
return $this->error(__('Failed to ensure PlayX user asset'));
}
@@ -294,7 +295,7 @@ class Playx extends Api
}
$todayLimit = intval(round(floatval($yesterdayTotalDeposit) * $unlockRatio));
$asset = $this->syncAssetByDailyPush($playxUserId, $username, $date, $newLocked, $todayLimit, true);
$asset = $this->syncAssetByDailyPush($playxUserId, $username, $date, $newLocked, $todayLimit, true, $phone);
if (!$asset) {
throw new \RuntimeException(__('Failed to ensure PlayX user asset'));
}
@@ -327,6 +328,7 @@ class Playx extends Api
$requestId = $body['request_id'] ?? '';
$date = $body['date'] ?? '';
$playxUserId = strval($body['user_id'] ?? '');
$phone = trim(strval($body['phone'] ?? ($body['mobile'] ?? '')));
$yesterdayWinLossNet = $body['yesterday_win_loss_net'] ?? 0;
$yesterdayTotalDeposit = $body['yesterday_total_deposit'] ?? 0;
@@ -344,7 +346,15 @@ class Playx extends Api
$newLocked = intval(round(abs(floatval($yesterdayWinLossNet)) * $returnRatio));
}
$todayLimit = intval(round(floatval($yesterdayTotalDeposit) * $unlockRatio));
$asset = $this->syncAssetByDailyPush($playxUserId, strval($body['username'] ?? ''), $date, $newLocked, $todayLimit, false);
$asset = $this->syncAssetByDailyPush(
$playxUserId,
strval($body['username'] ?? ''),
$date,
$newLocked,
$todayLimit,
false,
$phone
);
if (!$asset) {
return $this->error(__('Failed to ensure PlayX user asset'));
}
@@ -379,7 +389,15 @@ class Playx extends Api
}
$todayLimit = intval(round(floatval($yesterdayTotalDeposit) * $unlockRatio));
$asset = $this->syncAssetByDailyPush($playxUserId, strval($body['username'] ?? ''), $date, $newLocked, $todayLimit, true);
$asset = $this->syncAssetByDailyPush(
$playxUserId,
strval($body['username'] ?? ''),
$date,
$newLocked,
$todayLimit,
true,
$phone
);
if (!$asset) {
throw new \RuntimeException(__('Failed to ensure PlayX user asset'));
}
@@ -543,6 +561,7 @@ class Playx extends Api
$userId = strval($data['user_id']);
$username = strval($data['username'] ?? '');
$phone = trim(strval($data['phone'] ?? ($data['mobile'] ?? '')));
$expireAt = time() + intval(config('playx.session_expire_seconds', 3600));
if (!empty($data['token_expire_at'])) {
@@ -552,7 +571,7 @@ class Playx extends Api
}
}
$asset = $this->ensureAssetForPlayx($userId, $username);
$asset = $this->ensureAssetForPlayx($userId, $username, $phone);
if ($asset === null) {
return $this->error(__('Failed to ensure PlayX user asset'));
}