优化每日推送创建(更新)用户资产
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user