// Package agentrecharge 定义代理在线充值的纯业务规则。 package agentrecharge import ( "strings" "github.com/break/junhong_cmp_fiber/pkg/constants" "github.com/break/junhong_cmp_fiber/pkg/errors" ) // ValidateOnlineCreation 校验代理在线充值的角色、金额和支付方式不变量。 func ValidateOnlineCreation(userType int, amount int64, paymentMethod string) error { if userType != constants.UserTypeAgent { return errors.New(errors.CodeForbidden, "仅代理账号可以创建在线扫码充值") } if amount < constants.AgentOnlineRechargeMinAmount || amount > constants.AgentRechargeMaxAmount { return errors.New(errors.CodeInvalidParam, "在线充值金额必须在100元至100万元之间") } switch strings.TrimSpace(paymentMethod) { case constants.RechargeMethodWechat, constants.RechargeMethodAlipay: return nil default: return errors.New(errors.CodeInvalidParam, "在线充值支付方式无效") } } // CanCloseAfterPreCreateFailure 判断预下单明确失败后能否关闭充值单。 func CanCloseAfterPreCreateFailure(status int) bool { return status == constants.RechargeStatusPending }