提现金额限制及添加其它技术

This commit is contained in:
Dev
2026-09-23 17:52:36 +08:00
parent eb5acfc466
commit a07c495fe0
5 changed files with 69 additions and 13 deletions
@@ -67,15 +67,19 @@ class Account extends Api
$user_id = $this->auth->id ?? -1; $user_id = $this->auth->id ?? -1;
$amount = $this->request->post('amount', 0); $amount = $this->request->post('amount', 0);
$name = $this->request->post('name', ''); $name = $this->request->post('name', '');
// 验证参数 // 验证参数(单笔 0.1~200 元,与 AccountWithdrawService 中的限制保持一致)
$error = $this->validate($this->request->post(), [ $error = $this->validate($this->request->post(), [
'name' => 'require', 'name' => 'require',
'amount' => 'require|number|between:1,500', 'amount' => 'require|number|float|between:'
. AccountWithdrawService::WITHDRAW_MIN_AMOUNT . ','
. AccountWithdrawService::WITHDRAW_MAX_AMOUNT,
], [ ], [
'name.require' => '微信真实姓名必填', 'name.require' => '微信真实姓名必填',
'amount.require' => '提现金额不正确', 'amount.require' => '提现金额不正确',
'amount.number' => '提现金额必须为数字', 'amount.number' => '提现金额必须为数字',
'amount.between' => '提现金额必须在1到500之间', 'amount.float' => '提现金额必须为数字',
'amount.between' => '单笔提现金额需在' . AccountWithdrawService::WITHDRAW_MIN_AMOUNT . '~'
. AccountWithdrawService::WITHDRAW_MAX_AMOUNT . '元之间',
]); ]);
if (true !== $error) { if (true !== $error) {
throw new \Exception($error); throw new \Exception($error);
@@ -169,6 +169,7 @@ class Common extends Api
$code_languages = config('site.general_config_code_languages') ?? ''; $code_languages = config('site.general_config_code_languages') ?? '';
$front_techs = config('site.general_config_front_techs') ?? ''; $front_techs = config('site.general_config_front_techs') ?? '';
$back_techs = config('site.general_config_back_techs') ?? ''; $back_techs = config('site.general_config_back_techs') ?? '';
$other_techs = config('site.general_config_other_techs') ?? '';
$develop_types = config('site.general_config_develop_types') ?? ''; $develop_types = config('site.general_config_develop_types') ?? '';
$develop_types = explode(',', $develop_types); $develop_types = explode(',', $develop_types);
$developTypes = []; $developTypes = [];
@@ -182,6 +183,7 @@ class Common extends Api
'languageLabels' => explode(',', $code_languages), 'languageLabels' => explode(',', $code_languages),
'frontLabels' => explode(',', $front_techs), 'frontLabels' => explode(',', $front_techs),
'backendLabels' => explode(',', $back_techs), 'backendLabels' => explode(',', $back_techs),
'otherLabels' => explode(',', $other_techs),
'developTypes' => $developTypes, 'developTypes' => $developTypes,
]; ];
@@ -31,6 +31,13 @@ class AccountWithdrawService
CommonService::FAILED => '审核驳回', CommonService::FAILED => '审核驳回',
]; ];
//提现限制(与小程序端展示的「提现规则」保持一致)
const WITHDRAW_MIN_AMOUNT = 0.1; //单笔最低(元)
const WITHDRAW_MAX_AMOUNT = 200; //单笔最高(元)
const WITHDRAW_DAY_MAX_COUNT = 10; //每个自然日最多申请次数
const WITHDRAW_DAY_MAX_AMOUNT = 2000; //每个自然日累计提现上限(元)
const WITHDRAW_AMOUNT_SCALE = 2; //金额小数位数
/** /**
* 用户申请提现 * 用户申请提现
@@ -42,12 +49,20 @@ class AccountWithdrawService
*/ */
public static function applyWithdraw($userId, $amount, string $name = '') public static function applyWithdraw($userId, $amount, string $name = '')
{ {
//每个自然日仅可发起一次提现申请 //单笔金额校验(0.1~200元,最多两位小数)
$todayCount = self::$Model::where('user_id', $userId) $amount = self::checkWithdrawAmount($amount);
->whereTime('createtime', 'today')
->count(); //每个自然日次数限制(已驳回的不计入)
if ($todayCount >= 10) { $todayCount = self::todayQuery($userId)->count();
throw new \Exception('每个自然日仅可发起10次提现申请,请明日再试'); if ($todayCount >= self::WITHDRAW_DAY_MAX_COUNT) {
throw new \Exception('每个自然日最多可发起' . self::WITHDRAW_DAY_MAX_COUNT . '次提现申请,请明日再试');
}
//每个自然日累计金额限制(已驳回的不计入)
$todayAmount = (float)self::todayQuery($userId)->sum('amount');
if ($todayAmount + $amount > self::WITHDRAW_DAY_MAX_AMOUNT) {
throw new \Exception('每个自然日累计提现金额不超过' . self::WITHDRAW_DAY_MAX_AMOUNT
. '元,今日已申请' . sprintf('%.2f', $todayAmount) . '元,请明日再试');
} }
//开启事务 抛出异常时自动回滚 //开启事务 抛出异常时自动回滚
@@ -79,6 +94,41 @@ class AccountWithdrawService
}); });
} }
/**
* 单笔提现金额校验
* @param int|float|string $amount
* @return float 校验通过返回规范化后的金额(保留2位小数)
* @throws \Exception
*/
public static function checkWithdrawAmount($amount): float
{
if (!is_numeric($amount)) {
throw new \Exception('提现金额必须为数字');
}
$amount = floatval($amount);
if ($amount < self::WITHDRAW_MIN_AMOUNT || $amount > self::WITHDRAW_MAX_AMOUNT) {
throw new \Exception('单笔提现金额需在' . self::WITHDRAW_MIN_AMOUNT . '~'
. self::WITHDRAW_MAX_AMOUNT . '元之间');
}
if (round($amount, self::WITHDRAW_AMOUNT_SCALE) != $amount) {
throw new \Exception('提现金额最多保留' . self::WITHDRAW_AMOUNT_SCALE . '位小数');
}
return round($amount, self::WITHDRAW_AMOUNT_SCALE);
}
/**
* 当日提现查询对象(已驳回的不计入次数与累计金额)
* @param int $userId
* @return \think\db\Query
*/
private static function todayQuery($userId)
{
return self::$Model::where('user_id', $userId)
->whereTime('createtime', 'today')
->where('status', '<>', CommonService::FAILED);
}
/** /**
* 审核提现 * 审核提现
* @param $withdraw_record_id int 提现申请id * @param $withdraw_record_id int 提现申请id
@@ -19,9 +19,9 @@ Page({
cancelBtnStyle: 'color: #ff0000; border-color: #ff0000; background-color: #fff;', cancelBtnStyle: 'color: #ff0000; border-color: #ff0000; background-color: #fff;',
// 提现规则:默认折叠,仅展示核心摘要 // 提现规则:默认折叠,仅展示核心摘要
rulesExpanded: false, rulesExpanded: false,
briefRules: ['单笔 1-200 元', '每日限 10 次', '单日限额 2000 元', '1-3 个工作日到账'], briefRules: ['单笔 0.1-200 元', '每日限 10 次', '单日限额 2000 元', '1-3 个工作日到账'],
ruleList: [ ruleList: [
{ title: '单笔额度', desc: '单笔最低 1 元,最高 200 元,以「可提现余额」为准' }, { title: '单笔额度', desc: '单笔最低 0.1 元,最高 200 元,以「可提现余额」为准' },
{ title: '提现次数', desc: '每个自然日最多可发起 10 次提现申请' }, { title: '提现次数', desc: '每个自然日最多可发起 10 次提现申请' },
{ title: '单日限额', desc: '同一自然日累计提现金额不超过 2000 元,超出请次日再试' }, { title: '单日限额', desc: '同一自然日累计提现金额不超过 2000 元,超出请次日再试' },
{ title: '到账方式', desc: '转账至本人微信零钱,需填写与微信实名一致的姓名' }, { title: '到账方式', desc: '转账至本人微信零钱,需填写与微信实名一致的姓名' },
@@ -90,7 +90,7 @@
<t-dialog visible="{{showWithdrawDialog}}" title="提现" confirmBtn="确认" cancelBtn="取消" cancel-style="{{ cancelBtnStyle }}" bind:confirm="onConfirmWithdraw" bind:cancel="onCancelWithdraw" content="请填写该微信账号的真实姓名,用于安全校验"> <t-dialog visible="{{showWithdrawDialog}}" title="提现" confirmBtn="确认" cancelBtn="取消" cancel-style="{{ cancelBtnStyle }}" bind:confirm="onConfirmWithdraw" bind:cancel="onCancelWithdraw" content="请填写该微信账号的真实姓名,用于安全校验">
<view class="dialog-content" slot="content"> <view class="dialog-content" slot="content">
<t-input label="真实姓名" placeholder="请输入姓名" value="{{withdrawName}}" bindchange="onWithdrawNameInput" /> <t-input label="真实姓名" placeholder="请输入姓名" value="{{withdrawName}}" bindchange="onWithdrawNameInput" />
<t-input label="提现金额" placeholder="请输入提现金额" type="number" value="{{withdrawAmount}}" bindchange="onWithdrawAmountInput" /> <t-input label="提现金额" placeholder="请输入提现金额" type="digit" value="{{withdrawAmount}}" bindchange="onWithdrawAmountInput" />
<view class="dialog-tips">单笔 1-200 元,每日最多 10 次,单日累计不超过 2000 元;到账至微信零钱,1-3 个工作日内到账</view> <view class="dialog-tips">单笔 0.1-200 元,每日最多 10 次,单日累计不超过 2000 元;到账至微信零钱,1-3 个工作日内到账</view>
</view> </view>
</t-dialog> </t-dialog>