优化每日推送和积分转化逻辑

This commit is contained in:
2026-07-24 11:12:29 +08:00
parent b2b4fd4fbc
commit 4bad91b8a3
29 changed files with 661 additions and 102 deletions

View File

@@ -15,6 +15,7 @@ use app\common\model\MallSession;
use app\common\model\MallOrder;
use app\common\model\MallUserAsset;
use app\common\library\MallPlayxRatios;
use app\common\library\MallPointsConversion;
use app\common\library\MallDailyPushRawLogger;
use app\common\model\MallAddress;
use support\think\Db;
@@ -143,11 +144,19 @@ class Playx extends Api
/**
* 按每日推送记录同步用户资产主信息applyAssetDelta=true 时才落资产增量。
*/
/**
* @return array<string, mixed>
*/
private function getPointsConversionConfig(): array
{
return MallPointsConversion::configForConversion();
}
private function syncAssetByDailyPush(
string $playxUserId,
string $username,
string $date,
int $newLocked,
int $convertedPoints,
int $todayLimit,
bool $applyAssetDelta,
string $phone = ''
@@ -169,7 +178,9 @@ class Playx extends Api
$asset->today_claimed = 0;
$asset->today_limit_date = $date;
}
$asset->locked_points = intval($asset->locked_points ?? 0) + $newLocked;
if ($convertedPoints !== 0) {
MallPointsConversion::applyDailyConversionDelta($asset, $convertedPoints);
}
$asset->today_limit = $todayLimit;
}
@@ -235,9 +246,8 @@ class Playx extends Api
$requestId = 'report_' . $date;
}
$ratios = MallPlayxRatios::get();
$returnRatio = $ratios['return_ratio'];
$unlockRatio = $ratios['unlock_ratio'];
$pointsConfig = $this->getPointsConversionConfig();
$unlockRatio = floatval($pointsConfig['unlock_ratio'] ?? 0);
$results = [];
$allDeduped = true;
@@ -254,15 +264,13 @@ class Playx extends Api
$yesterdayTotalDeposit = $m['yesterday_total_deposit'] ?? 0;
$lifetimeTotalDeposit = $m['ltv_deposit'] ?? ($m['lty_deposit'] ?? 0);
$lifetimeTotalWithdraw = $m['ltv_withdrawal'] ?? ($m['lty_withdrawal'] ?? 0);
$lifetimeWinLossNet = MallPointsConversion::parseLifetimeWinLossFromMember($m);
$exists = MallDailyPush::where('user_id', $playxUserId)->where('date', $date)->find();
if ($exists) {
$newLocked = 0;
if ($yesterdayWinLossNet < 0) {
$newLocked = intval(round(abs(floatval($yesterdayWinLossNet)) * $returnRatio));
}
$convertedPoints = MallPointsConversion::dailyConvertedPoints($date, floatval($yesterdayWinLossNet), $pointsConfig);
$todayLimit = intval(round(floatval($yesterdayTotalDeposit) * $unlockRatio));
$asset = $this->syncAssetByDailyPush($playxUserId, $username, $date, $newLocked, $todayLimit, false, $phone);
$asset = $this->syncAssetByDailyPush($playxUserId, $username, $date, $convertedPoints, $todayLimit, false, $phone);
if (!$asset) {
return $this->error(__('Failed to ensure PlayX user asset'));
}
@@ -278,7 +286,7 @@ class Playx extends Api
Db::startTrans();
try {
MallDailyPush::create([
$pushData = [
'user_id' => $playxUserId,
'date' => $date,
'username' => $username,
@@ -287,15 +295,17 @@ class Playx extends Api
'lifetime_total_deposit' => $lifetimeTotalDeposit,
'lifetime_total_withdraw' => $lifetimeTotalWithdraw,
'create_time' => time(),
]);
$newLocked = 0;
if ($yesterdayWinLossNet < 0) {
$newLocked = intval(round(abs(floatval($yesterdayWinLossNet)) * $returnRatio));
];
$convertedPoints = MallPointsConversion::dailyConvertedPoints($date, floatval($yesterdayWinLossNet), $pointsConfig);
$pushData['converted_points'] = $convertedPoints;
if ($lifetimeWinLossNet !== null) {
$pushData['lifetime_win_loss_net'] = $lifetimeWinLossNet;
}
MallDailyPush::create($pushData);
$todayLimit = intval(round(floatval($yesterdayTotalDeposit) * $unlockRatio));
$asset = $this->syncAssetByDailyPush($playxUserId, $username, $date, $newLocked, $todayLimit, true, $phone);
$asset = $this->syncAssetByDailyPush($playxUserId, $username, $date, $convertedPoints, $todayLimit, true, $phone);
if (!$asset) {
throw new \RuntimeException(__('Failed to ensure PlayX user asset'));
}
@@ -338,19 +348,15 @@ class Playx extends Api
$exists = MallDailyPush::where('user_id', $playxUserId)->where('date', $date)->find();
if ($exists) {
$newLocked = 0;
$ratios = MallPlayxRatios::get();
$returnRatio = $ratios['return_ratio'];
$unlockRatio = $ratios['unlock_ratio'];
if ($yesterdayWinLossNet < 0) {
$newLocked = intval(round(abs(floatval($yesterdayWinLossNet)) * $returnRatio));
}
$pointsConfig = $this->getPointsConversionConfig();
$unlockRatio = floatval($pointsConfig['unlock_ratio'] ?? 0);
$convertedPoints = MallPointsConversion::dailyConvertedPoints($date, floatval($yesterdayWinLossNet), $pointsConfig);
$todayLimit = intval(round(floatval($yesterdayTotalDeposit) * $unlockRatio));
$asset = $this->syncAssetByDailyPush(
$playxUserId,
strval($body['username'] ?? ''),
$date,
$newLocked,
$convertedPoints,
$todayLimit,
false,
$phone
@@ -369,7 +375,12 @@ class Playx extends Api
Db::startTrans();
try {
MallDailyPush::create([
$pointsConfig = $this->getPointsConversionConfig();
$lifetimeWinLossNet = null;
if (isset($body['lifetime_win_loss_net']) && is_numeric($body['lifetime_win_loss_net'])) {
$lifetimeWinLossNet = floatval($body['lifetime_win_loss_net']);
}
$pushData = [
'user_id' => $playxUserId,
'date' => $date,
'username' => $body['username'] ?? '',
@@ -378,22 +389,22 @@ class Playx extends Api
'lifetime_total_deposit' => $body['lifetime_total_deposit'] ?? 0,
'lifetime_total_withdraw' => $body['lifetime_total_withdraw'] ?? 0,
'create_time' => time(),
]);
$newLocked = 0;
$ratios = MallPlayxRatios::get();
$returnRatio = $ratios['return_ratio'];
$unlockRatio = $ratios['unlock_ratio'];
if ($yesterdayWinLossNet < 0) {
$newLocked = intval(round(abs(floatval($yesterdayWinLossNet)) * $returnRatio));
];
$convertedPoints = MallPointsConversion::dailyConvertedPoints($date, floatval($yesterdayWinLossNet), $pointsConfig);
$pushData['converted_points'] = $convertedPoints;
if ($lifetimeWinLossNet !== null) {
$pushData['lifetime_win_loss_net'] = $lifetimeWinLossNet;
}
MallDailyPush::create($pushData);
$unlockRatio = floatval($pointsConfig['unlock_ratio'] ?? 0);
$todayLimit = intval(round(floatval($yesterdayTotalDeposit) * $unlockRatio));
$asset = $this->syncAssetByDailyPush(
$playxUserId,
strval($body['username'] ?? ''),
$date,
$newLocked,
$convertedPoints,
$todayLimit,
true,
$phone
@@ -744,11 +755,12 @@ class Playx extends Api
}
$remain = $asset->today_limit - $asset->today_claimed;
if ($asset->locked_points <= 0 || $remain <= 0) {
$lifetimeRemain = MallPointsConversion::remainingClaimable($asset);
if ($asset->locked_points <= 0 || $remain <= 0 || $lifetimeRemain <= 0) {
return $this->error(__('No points to claim or limit reached'));
}
$canClaim = min($asset->locked_points, $remain);
$canClaim = min($asset->locked_points, $remain, $lifetimeRemain);
Db::startTrans();
try {
@@ -762,6 +774,7 @@ class Playx extends Api
$asset->locked_points -= $canClaim;
$asset->available_points += $canClaim;
$asset->today_claimed += $canClaim;
$asset->total_points_claimed = max(0, intval($asset->total_points_claimed ?? 0) + $canClaim);
$asset->save();
Db::commit();