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

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

@@ -30,9 +30,11 @@ class DailyPush extends Backend
'date',
'username',
'yesterday_win_loss_net',
'converted_points',
'yesterday_total_deposit',
'lifetime_total_deposit',
'lifetime_total_withdraw',
'lifetime_win_loss_net',
'create_time',
];

View File

@@ -6,8 +6,10 @@ namespace app\admin\controller\mall;
use app\common\controller\Backend;
use app\common\library\MallPlayxRatios;
use app\common\library\MallPointsConversion;
use app\common\model\MallBusinessConfig;
use support\Response;
use support\think\Db;
use Webman\Http\Request;
/**
@@ -22,25 +24,15 @@ class PlayxConfig extends Backend
return $response;
}
$row = MallBusinessConfig::order('id', 'asc')->find();
if (!$row) {
$now = time();
MallBusinessConfig::create([
'return_ratio' => floatval(env('PLAYX_RETURN_RATIO', '0.1')),
'unlock_ratio' => floatval(env('PLAYX_UNLOCK_RATIO', '0.1')),
'points_to_cash_ratio' => floatval(env('PLAYX_POINTS_TO_CASH_RATIO', '0.1')),
'create_time' => $now,
'update_time' => $now,
]);
$row = MallBusinessConfig::order('id', 'asc')->find();
}
$row = MallBusinessConfig::ensureRow();
if ($row) {
MallPlayxRatios::syncFromRow($row);
}
MallPlayxRatios::syncFromRow($row);
$payload = $row->toArray();
$payload['active_mall_open_date'] = MallPointsConversion::resolveActiveMallOpenDate($row);
return $this->success('', [
'row' => $row ? $row->toArray() : [],
'row' => $payload,
'remark' => get_route_remark(),
]);
}
@@ -71,20 +63,54 @@ class PlayxConfig extends Backend
return $this->error(__('Parameter error'));
}
$dailyEnabled = !empty($data['daily_points_enabled']) ? 1 : 0;
$lifetimeEnabled = !empty($data['lifetime_points_enabled']) ? 1 : 0;
$lifetimeRatio = $data['lifetime_points_ratio'] ?? null;
if (!is_numeric($lifetimeRatio)) {
return $this->error(__('Parameter error'));
}
$lifetimeRatioF = floatval($lifetimeRatio);
if ($lifetimeRatioF < 0) {
return $this->error(__('Parameter error'));
}
$mallOpenDate = MallPointsConversion::normalizeDate($data['mall_open_date'] ?? null);
$row = MallBusinessConfig::order('id', 'asc')->find();
$now = time();
if (!$row) {
$now = time();
$effectiveOn = $mallOpenDate !== null ? MallPointsConversion::nextCalendarDate() : null;
MallBusinessConfig::create([
'return_ratio' => $returnF,
'unlock_ratio' => $unlockF,
'points_to_cash_ratio' => $cashF,
'create_time' => $now,
'update_time' => $now,
'return_ratio' => $returnF,
'unlock_ratio' => $unlockF,
'points_to_cash_ratio' => $cashF,
'daily_points_enabled' => $dailyEnabled,
'lifetime_points_enabled' => $lifetimeEnabled,
'lifetime_points_ratio' => $lifetimeRatioF,
'mall_open_date' => $mallOpenDate,
'mall_open_date_previous' => null,
'mall_open_date_effective_on' => $effectiveOn,
'create_time' => $now,
'update_time' => $now,
]);
} else {
$previousOpen = MallPointsConversion::resolveActiveMallOpenDate($row);
$currentPending = MallPointsConversion::normalizeDate($row->mall_open_date ?? null);
$openDateChanged = $mallOpenDate !== $currentPending;
$row->return_ratio = $returnF;
$row->unlock_ratio = $unlockF;
$row->points_to_cash_ratio = $cashF;
$row->daily_points_enabled = $dailyEnabled;
$row->lifetime_points_enabled = $lifetimeEnabled;
$row->lifetime_points_ratio = $lifetimeRatioF;
if ($openDateChanged) {
$row->mall_open_date_previous = $previousOpen;
$row->mall_open_date = $mallOpenDate;
$row->mall_open_date_effective_on = $mallOpenDate !== null ? MallPointsConversion::nextCalendarDate() : null;
}
$row->save();
}
@@ -95,4 +121,32 @@ class PlayxConfig extends Backend
return $this->success(__('The current page configuration item was updated successfully'));
}
/**
* 一键按最新终身总输赢与比例折算积分(重复执行会先扣旧比例再加新比例)
*/
public function calculateLifetimePoints(Request $request): Response
{
$response = $this->initializeBackend($request);
if ($response !== null) {
return $response;
}
$row = MallBusinessConfig::order('id', 'asc')->find();
if (!$row) {
return $this->error(__('Parameter error'));
}
Db::startTrans();
try {
$stats = MallPointsConversion::recalculateAllLifetimePoints($row);
Db::commit();
} catch (\Throwable $e) {
Db::rollback();
return $this->error($e->getMessage());
}
return $this->success(__('Operation completed'), $stats);
}
}

View File

@@ -42,6 +42,8 @@ class UserAsset extends Backend
'today_limit',
'today_claimed',
'today_limit_date',
'points_claim_cap',
'total_points_claimed',
'create_time',
'update_time',
];

View File

@@ -27,6 +27,7 @@ return [
'Added successfully' => 'Added successfully!',
'Deleted successfully' => 'Deleted successfully!',
'Parameter error' => 'Parameter error!',
'Lifetime points source is disabled' => 'Lifetime points source is disabled',
'File uploaded successfully' => 'File uploaded successfully',
'No files were uploaded' => 'No files were uploaded',
'The uploaded file format is not allowed' => 'The uploaded file format is no allowance.',

View File

@@ -27,6 +27,7 @@ return [
'Added successfully' => '添加成功!',
'Deleted successfully' => '删除成功!',
'Parameter error' => '参数错误!',
'Lifetime points source is disabled' => '终身总输赢积分来源未启用',
'Please use the %s field to sort before operating' => '请使用 %s 字段排序后再操作',
'File uploaded successfully' => '文件上传成功!',
'No files were uploaded' => '没有文件被上传',