|
|
@@ -22,6 +22,8 @@ class ManualAuditService
|
|
|
public const PLATFORM_WAGER_TYPE = '人工充值';
|
|
|
/** 按平台倍数计打码量的全部类型:“其他”与人工充值同样按倍数,但不触发充值钩子(不参与任何活动) */
|
|
|
public const PLATFORM_WAGER_TYPES = ['人工充值', '其他'];
|
|
|
+ public const CREDIT_WAGER_MULTIPLE_TYPES = ['注册赠送', '优惠活动', '神秘彩金'];
|
|
|
+ public const WAGER_MULTIPLE_PATTERN = '/\A[0-9]+\z/';
|
|
|
public const STATUS_FAILED = ManualAuditRecord::STATUS_FAILED;
|
|
|
public const STATUS_SUCCESS = ManualAuditRecord::STATUS_SUCCESS;
|
|
|
|
|
|
@@ -60,9 +62,9 @@ class ManualAuditService
|
|
|
['label' => '失败', 'value' => self::STATUS_FAILED],
|
|
|
['label' => '成功', 'value' => self::STATUS_SUCCESS],
|
|
|
],
|
|
|
- // 人工充值、其他按平台提现打码倍数自动增减打码量,其余类型需填写 wager_amount
|
|
|
'platform_wager_type' => self::PLATFORM_WAGER_TYPE,
|
|
|
'platform_wager_types' => self::PLATFORM_WAGER_TYPES,
|
|
|
+ 'credit_wager_multiple_types' => self::CREDIT_WAGER_MULTIPLE_TYPES,
|
|
|
'withdraw_wager_multiple' => WageringService::multiple(),
|
|
|
],
|
|
|
];
|
|
|
@@ -105,7 +107,8 @@ class ManualAuditService
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param string|null $wagerAmount 非“人工充值”类型时填写的打码量(为空视为0,可直接提现)
|
|
|
+ * @param string|null $wagerAmount 旧版固定打码量,仅用于识别历史请求重试
|
|
|
+ * @param string|null $wagerMultiple 指定赠送类型上分使用的非负整数倍数
|
|
|
*/
|
|
|
public static function credit(
|
|
|
string $requestId,
|
|
|
@@ -114,9 +117,10 @@ class ManualAuditService
|
|
|
string $amount,
|
|
|
string $changeType,
|
|
|
string $remark,
|
|
|
- ?string $wagerAmount = null
|
|
|
+ ?string $wagerAmount = null,
|
|
|
+ ?string $wagerMultiple = null
|
|
|
): array {
|
|
|
- return self::adjust($requestId, $adminId, $memberId, $amount, $changeType, $remark, false, null, $wagerAmount);
|
|
|
+ return self::adjust($requestId, $adminId, $memberId, $amount, $changeType, $remark, false, null, $wagerAmount, $wagerMultiple);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -148,8 +152,33 @@ class ManualAuditService
|
|
|
* 本次上下分对打码量的有符号调整。上分“人工充值”由充值钩子自动按平台倍数增加,这里只返回展示值。
|
|
|
* @return array{0:string,1:bool} [有符号打码量, 是否需要在此处手动写入]
|
|
|
*/
|
|
|
- public static function wagerDelta(bool $isDebit, string $amount, string $changeType, ?string $rechargeType, ?string $wagerAmount): array
|
|
|
- {
|
|
|
+ public static function wagerDelta(
|
|
|
+ bool $isDebit,
|
|
|
+ string $amount,
|
|
|
+ string $changeType,
|
|
|
+ ?string $rechargeType,
|
|
|
+ ?string $wagerAmount,
|
|
|
+ ?string $wagerMultiple = null
|
|
|
+ ): array {
|
|
|
+ if (!$isDebit && in_array($changeType, self::CREDIT_WAGER_MULTIPLE_TYPES, true)) {
|
|
|
+ if ($wagerAmount !== null) {
|
|
|
+ throw new Exception('请使用 wager_multiple 提交打码量倍数', HttpStatus::CUSTOM_ERROR);
|
|
|
+ }
|
|
|
+ $multiple = $wagerMultiple ?? '0';
|
|
|
+ if (!preg_match(self::WAGER_MULTIPLE_PATTERN, $multiple)) {
|
|
|
+ throw new Exception('打码量倍数必须为非负整数', HttpStatus::CUSTOM_ERROR);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ $delta = bcmul($amount, $multiple, 10);
|
|
|
+ } catch (\ValueError) {
|
|
|
+ throw new Exception('充值金额格式不正确', HttpStatus::CUSTOM_ERROR);
|
|
|
+ }
|
|
|
+ if (bccomp($delta, '100000000000000000000', 10) >= 0) {
|
|
|
+ throw new Exception('计算后的打码量超出范围', HttpStatus::CUSTOM_ERROR);
|
|
|
+ }
|
|
|
+ return [$delta, true];
|
|
|
+ }
|
|
|
+
|
|
|
// 仅自填分支解析 wager_amount:按平台倍数的类型忽略该值;校验器的 numeric 会放行 "1e2" 等 bcmath 不接受的写法
|
|
|
$custom = static function () use ($wagerAmount): string {
|
|
|
try {
|
|
|
@@ -178,14 +207,19 @@ class ManualAuditService
|
|
|
string $remark,
|
|
|
bool $isDebit,
|
|
|
?string $rechargeType = null,
|
|
|
- ?string $wagerAmount = null
|
|
|
+ ?string $wagerAmount = null,
|
|
|
+ ?string $wagerMultiple = null
|
|
|
): array {
|
|
|
$signedAmount = bcadd($amount, '0', 10);
|
|
|
if ($isDebit) {
|
|
|
$signedAmount = bcmul($signedAmount, '-1', 10);
|
|
|
}
|
|
|
$transactionType = $isDebit ? 'debit' : 'credit';
|
|
|
- [$wagerDelta, $writeWager] = self::wagerDelta($isDebit, $amount, $changeType, $rechargeType, $wagerAmount);
|
|
|
+ $wagerParameters = $rechargeType === null && $wagerAmount === null ? null
|
|
|
+ : ['recharge_type' => $rechargeType, 'wager_amount' => $wagerAmount === null ? null : bcadd($wagerAmount, '0', 10)];
|
|
|
+ if ($wagerMultiple !== null && in_array($changeType, self::CREDIT_WAGER_MULTIPLE_TYPES, true)) {
|
|
|
+ $wagerParameters['wager_multiple'] = $wagerMultiple;
|
|
|
+ }
|
|
|
$requestHash = self::requestHash(
|
|
|
$adminId,
|
|
|
$memberId,
|
|
|
@@ -194,8 +228,7 @@ class ManualAuditService
|
|
|
$changeType,
|
|
|
$remark,
|
|
|
// 只摘要请求原始参数,平台倍数调整后同一 request_id 重试仍能识别为同一请求
|
|
|
- $rechargeType === null && $wagerAmount === null ? null
|
|
|
- : ['recharge_type' => $rechargeType, 'wager_amount' => $wagerAmount === null ? null : bcadd($wagerAmount, '0', 10)]
|
|
|
+ $wagerParameters
|
|
|
);
|
|
|
|
|
|
$existing = ManualAuditRecord::where('request_id', $requestId)->first();
|
|
|
@@ -204,6 +237,8 @@ class ManualAuditService
|
|
|
return self::format($existing, self::accounts([$memberId]));
|
|
|
}
|
|
|
|
|
|
+ [$wagerDelta, $writeWager] = self::wagerDelta($isDebit, $amount, $changeType, $rechargeType, $wagerAmount, $wagerMultiple);
|
|
|
+
|
|
|
$created = false;
|
|
|
try {
|
|
|
$audit = DB::transaction(function () use (
|