From a07c495fe01792b4eb9726f55d920518f33c5869 Mon Sep 17 00:00:00 2001 From: Dev Date: Wed, 23 Sep 2026 17:52:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E7=8E=B0=E9=87=91=E9=A2=9D=E9=99=90?= =?UTF-8?q?=E5=88=B6=E5=8F=8A=E6=B7=BB=E5=8A=A0=E5=85=B6=E5=AE=83=E6=8A=80?= =?UTF-8?q?=E6=9C=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/api/controller/Account.php | 10 ++- backend/application/api/controller/Common.php | 2 + .../common/service/AccountWithdrawService.php | 62 +++++++++++++++++-- .../miniapp/pages/usercenter/balance/index.js | 4 +- .../pages/usercenter/balance/index.wxml | 4 +- 5 files changed, 69 insertions(+), 13 deletions(-) diff --git a/backend/application/api/controller/Account.php b/backend/application/api/controller/Account.php index fd93fba..06d5666 100644 --- a/backend/application/api/controller/Account.php +++ b/backend/application/api/controller/Account.php @@ -67,15 +67,19 @@ class Account extends Api $user_id = $this->auth->id ?? -1; $amount = $this->request->post('amount', 0); $name = $this->request->post('name', ''); - // 验证参数 + // 验证参数(单笔 0.1~200 元,与 AccountWithdrawService 中的限制保持一致) $error = $this->validate($this->request->post(), [ 'name' => 'require', - 'amount' => 'require|number|between:1,500', + 'amount' => 'require|number|float|between:' + . AccountWithdrawService::WITHDRAW_MIN_AMOUNT . ',' + . AccountWithdrawService::WITHDRAW_MAX_AMOUNT, ], [ 'name.require' => '微信真实姓名必填', 'amount.require' => '提现金额不正确', 'amount.number' => '提现金额必须为数字', - 'amount.between' => '提现金额必须在1到500之间', + 'amount.float' => '提现金额必须为数字', + 'amount.between' => '单笔提现金额需在' . AccountWithdrawService::WITHDRAW_MIN_AMOUNT . '~' + . AccountWithdrawService::WITHDRAW_MAX_AMOUNT . '元之间', ]); if (true !== $error) { throw new \Exception($error); diff --git a/backend/application/api/controller/Common.php b/backend/application/api/controller/Common.php index 789a380..c9cd14b 100644 --- a/backend/application/api/controller/Common.php +++ b/backend/application/api/controller/Common.php @@ -169,6 +169,7 @@ class Common extends Api $code_languages = config('site.general_config_code_languages') ?? ''; $front_techs = config('site.general_config_front_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 = explode(',', $develop_types); $developTypes = []; @@ -182,6 +183,7 @@ class Common extends Api 'languageLabels' => explode(',', $code_languages), 'frontLabels' => explode(',', $front_techs), 'backendLabels' => explode(',', $back_techs), + 'otherLabels' => explode(',', $other_techs), 'developTypes' => $developTypes, ]; diff --git a/backend/application/common/service/AccountWithdrawService.php b/backend/application/common/service/AccountWithdrawService.php index 4a50920..aa20973 100644 --- a/backend/application/common/service/AccountWithdrawService.php +++ b/backend/application/common/service/AccountWithdrawService.php @@ -31,6 +31,13 @@ class AccountWithdrawService 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 = '') { - //每个自然日仅可发起一次提现申请 - $todayCount = self::$Model::where('user_id', $userId) - ->whereTime('createtime', 'today') - ->count(); - if ($todayCount >= 10) { - throw new \Exception('每个自然日仅可发起10次提现申请,请明日再试'); + //单笔金额校验(0.1~200元,最多两位小数) + $amount = self::checkWithdrawAmount($amount); + + //每个自然日次数限制(已驳回的不计入) + $todayCount = self::todayQuery($userId)->count(); + 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 diff --git a/frontend/miniapp/pages/usercenter/balance/index.js b/frontend/miniapp/pages/usercenter/balance/index.js index c514425..b3b9d7c 100644 --- a/frontend/miniapp/pages/usercenter/balance/index.js +++ b/frontend/miniapp/pages/usercenter/balance/index.js @@ -19,9 +19,9 @@ Page({ cancelBtnStyle: 'color: #ff0000; border-color: #ff0000; background-color: #fff;', // 提现规则:默认折叠,仅展示核心摘要 rulesExpanded: false, - briefRules: ['单笔 1-200 元', '每日限 10 次', '单日限额 2000 元', '1-3 个工作日到账'], + briefRules: ['单笔 0.1-200 元', '每日限 10 次', '单日限额 2000 元', '1-3 个工作日到账'], ruleList: [ - { title: '单笔额度', desc: '单笔最低 1 元,最高 200 元,以「可提现余额」为准' }, + { title: '单笔额度', desc: '单笔最低 0.1 元,最高 200 元,以「可提现余额」为准' }, { title: '提现次数', desc: '每个自然日最多可发起 10 次提现申请' }, { title: '单日限额', desc: '同一自然日累计提现金额不超过 2000 元,超出请次日再试' }, { title: '到账方式', desc: '转账至本人微信零钱,需填写与微信实名一致的姓名' }, diff --git a/frontend/miniapp/pages/usercenter/balance/index.wxml b/frontend/miniapp/pages/usercenter/balance/index.wxml index c741547..2587ea6 100644 --- a/frontend/miniapp/pages/usercenter/balance/index.wxml +++ b/frontend/miniapp/pages/usercenter/balance/index.wxml @@ -90,7 +90,7 @@ - - 单笔 1-200 元,每日最多 10 次,单日累计不超过 2000 元;到账至微信零钱,1-3 个工作日内到账 + + 单笔 0.1-200 元,每日最多 10 次,单日累计不超过 2000 元;到账至微信零钱,1-3 个工作日内到账 \ No newline at end of file