From 7af40bdd1f2faca902ab0c894806156bc84d4114 Mon Sep 17 00:00:00 2001 From: zhenhui <1276357500@qq.com> Date: Wed, 22 Apr 2026 16:59:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=AF=8F=E6=97=A5=E6=8E=A8?= =?UTF-8?q?=E9=80=81=E5=88=9B=E5=BB=BA=EF=BC=88=E6=9B=B4=E6=96=B0=EF=BC=89?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=B5=84=E4=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/v1/Playx.php | 86 +++++++++++++++++++++------------ 1 file changed, 54 insertions(+), 32 deletions(-) diff --git a/app/api/controller/v1/Playx.php b/app/api/controller/v1/Playx.php index 672f2b3..88ad193 100644 --- a/app/api/controller/v1/Playx.php +++ b/app/api/controller/v1/Playx.php @@ -146,6 +146,36 @@ class Playx extends Api return MallUserAsset::where('id', $assetId)->find(); } + /** + * 按每日推送记录同步用户资产主信息;applyAssetDelta=true 时才落资产增量。 + */ + private function syncAssetByDailyPush(string $playxUserId, string $username, string $date, int $newLocked, int $todayLimit, bool $applyAssetDelta): ?MallUserAsset + { + $asset = $this->ensureAssetForPlayx($playxUserId, $username); + if (!$asset) { + return null; + } + + $asset->playx_user_id = $playxUserId; + $uname = trim($username); + if ($uname !== '') { + $asset->username = $uname; + } + + if ($applyAssetDelta) { + 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->save(); + + return $asset; + } + /** * Daily Push API - PlayX 调用商城接收 T+1 数据 * POST /api/v1/mall/dailyPush @@ -221,6 +251,16 @@ class Playx extends Api $exists = MallDailyPush::where('user_id', $playxUserId)->where('date', $date)->find(); if ($exists) { + $newLocked = 0; + if ($yesterdayWinLossNet < 0) { + $newLocked = intval(round(abs(floatval($yesterdayWinLossNet)) * $returnRatio)); + } + $todayLimit = intval(round(floatval($yesterdayTotalDeposit) * $unlockRatio)); + $asset = $this->syncAssetByDailyPush($playxUserId, $username, $date, $newLocked, $todayLimit, false); + if (!$asset) { + return $this->error(__('Failed to ensure PlayX user asset')); + } + $results[] = [ 'user_id' => $playxUserId, 'deduped' => true, @@ -249,26 +289,11 @@ class Playx extends Api } $todayLimit = intval(round(floatval($yesterdayTotalDeposit) * $unlockRatio)); - $asset = $this->ensureAssetForPlayx($playxUserId, $username); + $asset = $this->syncAssetByDailyPush($playxUserId, $username, $date, $newLocked, $todayLimit, true); if (!$asset) { throw new \RuntimeException(__('Failed to ensure PlayX user asset')); } - 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[] = [ @@ -306,6 +331,18 @@ class Playx extends Api $exists = MallDailyPush::where('user_id', $playxUserId)->where('date', $date)->find(); if ($exists) { + $newLocked = 0; + $returnRatio = config('playx.return_ratio', 0.1); + $unlockRatio = config('playx.unlock_ratio', 0.1); + if ($yesterdayWinLossNet < 0) { + $newLocked = intval(round(abs(floatval($yesterdayWinLossNet)) * $returnRatio)); + } + $todayLimit = intval(round(floatval($yesterdayTotalDeposit) * $unlockRatio)); + $asset = $this->syncAssetByDailyPush($playxUserId, strval($body['username'] ?? ''), $date, $newLocked, $todayLimit, false); + if (!$asset) { + return $this->error(__('Failed to ensure PlayX user asset')); + } + return $this->success('', [ 'request_id' => $requestId, 'accepted' => true, @@ -335,26 +372,11 @@ class Playx extends Api } $todayLimit = intval(round(floatval($yesterdayTotalDeposit) * $unlockRatio)); - $asset = $this->ensureAssetForPlayx($playxUserId, strval($body['username'] ?? '')); + $asset = $this->syncAssetByDailyPush($playxUserId, strval($body['username'] ?? ''), $date, $newLocked, $todayLimit, true); if (!$asset) { throw new \RuntimeException(__('Failed to ensure PlayX user asset')); } - 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(strval($body['username'] ?? '')); - if ($uname !== '') { - $asset->username = $uname; - } - $asset->save(); - Db::commit(); } catch (\Throwable $e) { Db::rollback();