Compare commits
5 Commits
Iteration/
...
adcd4f5e9d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
adcd4f5e9d | ||
|
|
76f7d47167 | ||
|
|
e9d8c95b44 | ||
|
|
7ca79ebf28 | ||
|
|
1ffc923b94 |
@@ -41,9 +41,13 @@ func (s *RefundOffsetService) ApplyInTx(ctx context.Context, tx *gorm.DB, source
|
||||
if s == nil || tx == nil || s.audit == nil {
|
||||
return errors.New(errors.CodeInternalError, "员工代收款退款冲销能力未配置")
|
||||
}
|
||||
if source.RefundID == 0 || source.OrderID == 0 || source.RefundAmount <= 0 {
|
||||
if source.RefundID == 0 || source.OrderID == 0 || source.RefundAmount < 0 {
|
||||
return errors.New(errors.CodeInvalidParam, "员工代收款退款冲销参数无效")
|
||||
}
|
||||
// 0 元退款只作废权益、不退钱:不冲减、不关闭账单、不写冲销记录,也不能让退款事务失败。
|
||||
if source.RefundAmount == 0 {
|
||||
return nil
|
||||
}
|
||||
var bill model.EmployeeCollectionBill
|
||||
if err := tx.WithContext(ctx).Clauses(clause.Locking{Strength: "UPDATE"}).
|
||||
Where("source_key = ?", employeecollectiondomain.OrderSourceKey(source.OrderID)).
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/hex"
|
||||
stdErrors "errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -332,6 +333,7 @@ func RequiredSceneFields(businessType string) []RequiredSceneField {
|
||||
}
|
||||
|
||||
// RequiredRefundFields 返回退款提交固定与条件必需字段;快照方式编码缺失或未知时由表单构建拒绝。
|
||||
// 客户收款信息退款要求客户收款信息与凭证必须映射并提交;0 元退款不退钱,两者不强制。
|
||||
func RequiredRefundFields(snapshot map[string]any) []RequiredSceneField {
|
||||
methodCode, ok := snapshot[constants.ApprovalFieldRefundMethodCode].(string)
|
||||
methodCode = strings.TrimSpace(methodCode)
|
||||
@@ -339,12 +341,22 @@ func RequiredRefundFields(snapshot map[string]any) []RequiredSceneField {
|
||||
return []RequiredSceneField{{Code: constants.ApprovalFieldRefundMethodCode, Name: "退款方式编码"}}
|
||||
}
|
||||
result := []RequiredSceneField{{Code: constants.ApprovalFieldRefundMethod, Name: "退款方式", RequiredMapping: true}}
|
||||
if methodCode == constants.RefundMethodCustomerAccount {
|
||||
if methodCode == constants.RefundMethodCustomerAccount && !isZeroAmountRefund(snapshot) {
|
||||
result = append(result, RequiredSceneField{Code: constants.ApprovalFieldCustomerAccountInfo, Name: "客户收款信息"}, RequiredSceneField{Code: constants.ApprovalFieldCustomerVoucherKey, Name: "客户收款凭证"})
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// isZeroAmountRefund 判断快照中的申请退款金额是否为 0;金额缺失或无法解析时按非 0 处理,保持强制校验。
|
||||
func isZeroAmountRefund(snapshot map[string]any) bool {
|
||||
raw, ok := snapshot[constants.ApprovalFieldRequestedRefundAmount].(string)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
amount, err := strconv.ParseFloat(strings.TrimSpace(raw), 64)
|
||||
return err == nil && amount == 0
|
||||
}
|
||||
|
||||
// approvalBusinessTypes 返回全部已登记审批业务场景,供只读字段汇总复用。
|
||||
func approvalBusinessTypes() []string {
|
||||
return []string{
|
||||
|
||||
@@ -38,6 +38,10 @@ func (h *DeviceHandler) List(c *fiber.Ctx) error {
|
||||
// ListDeviceTypes 查询设备类型选项。
|
||||
// GET /api/admin/devices/types
|
||||
func (h *DeviceHandler) ListDeviceTypes(c *fiber.Ctx) error {
|
||||
userType := middleware.GetUserTypeFromContext(c.UserContext())
|
||||
if userType != constants.UserTypeSuperAdmin && userType != constants.UserTypePlatform {
|
||||
return errors.New(errors.CodeForbidden, constants.PlatformManagementForbiddenMessage)
|
||||
}
|
||||
result, err := h.service.ListDeviceTypes(c.UserContext())
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -101,7 +101,7 @@ func buildApprovalForm(ctx context.Context, businessType string, applicationID,
|
||||
attachmentCount := 0
|
||||
for _, mapping := range mappings {
|
||||
raw, exists := lookupSnapshotValue(snapshot, mapping.BusinessField)
|
||||
if !exists || raw == nil || isEmptyFileValue(mapping, raw) {
|
||||
if !exists || raw == nil || isEmptyFileValue(mapping, raw) || isEmptyCustomerAccountInfo(mapping, raw) {
|
||||
if requiredControls[mapping.ControlID] {
|
||||
return approvalFormBuildResult{}, errors.New(errors.CodeInvalidStatus, "审批业务快照缺少模板必填字段: "+mapping.BusinessField)
|
||||
}
|
||||
@@ -142,6 +142,15 @@ func isEmptyFileValue(mapping dto.WeComControlMappingItem, raw any) bool {
|
||||
}
|
||||
}
|
||||
|
||||
// isEmptyCustomerAccountInfo 判断客户收款信息是否为空文本;只有 0 元退款可能为空,按未填写处理,由模板必填规则决定是否拦截。
|
||||
func isEmptyCustomerAccountInfo(mapping dto.WeComControlMappingItem, raw any) bool {
|
||||
if strings.TrimSpace(mapping.BusinessField) != constants.ApprovalFieldCustomerAccountInfo {
|
||||
return false
|
||||
}
|
||||
value, ok := raw.(string)
|
||||
return ok && strings.TrimSpace(value) == ""
|
||||
}
|
||||
|
||||
// lookupSnapshotValue 支持用点分路径读取嵌套业务快照,避免模板映射绑定具体 DTO。
|
||||
func lookupSnapshotValue(snapshot map[string]any, path string) (any, bool) {
|
||||
segments := strings.Split(strings.TrimSpace(path), ".")
|
||||
|
||||
@@ -6,7 +6,7 @@ type CreateRefundRequest struct {
|
||||
ActualReceivedAmount *int64 `json:"actual_received_amount" validate:"omitempty" description:"已废弃:实收金额由系统从原成功支付记录或订单实际收款派生并冻结,提交人填写无效"`
|
||||
Method string `json:"method" validate:"required,oneof=original_route customer_account asset_wallet agent_wallet" required:"true" description:"退款方式 (original_route:原路退款, customer_account:客户收款信息退款, asset_wallet:退回资产钱包, agent_wallet:退回代理主钱包)"`
|
||||
CustomerAccountInfo string `json:"customer_account_info" validate:"omitempty,max=1000" maxLength:"1000" description:"客户收款信息,仅客户收款信息退款方式必填,不得复用公司线下收款方式字典"`
|
||||
RequestedRefundAmount int64 `json:"requested_refund_amount" validate:"required,min=1" required:"true" minimum:"1" description:"申请退款金额(分)"`
|
||||
RequestedRefundAmount int64 `json:"requested_refund_amount" validate:"min=0" required:"true" minimum:"0" description:"申请退款金额(分),0 ~ 冻结实收金额;0 元退款表示作废权益不退钱,仅限客户收款信息方式(钱包支付订单不支持),此时客户收款信息可不填但凭证必传"`
|
||||
RefundVoucherKey []string `json:"refund_voucher_key" validate:"omitempty,max=5,dive,max=500" maxItems:"5" description:"退款凭证对象存储file_key列表(最多5个,仅客户收款信息退款方式必填,通过/storage/upload-url上传图片后获得)"`
|
||||
RefundReason string `json:"refund_reason" validate:"required,max=1000" required:"true" maxLength:"1000" description:"退款原因(必填,去除首尾空白后不得为空)"`
|
||||
// Remark 是申请人备注,随本次提交冻结进当次审批尝试快照;与审批备注(详情响应中的 remark)语义不同。
|
||||
@@ -32,7 +32,7 @@ type ResubmitRefundRequest struct {
|
||||
ActualReceivedAmount *int64 `json:"actual_received_amount" validate:"omitempty,min=1" minimum:"1" description:"已废弃:实收金额由系统从原成功支付记录或订单实际收款派生并冻结,提交人填写无效"`
|
||||
Method *string `json:"method" validate:"omitempty,oneof=original_route customer_account asset_wallet agent_wallet" description:"退款方式 (original_route:原路退款, customer_account:客户收款信息退款, asset_wallet:退回资产钱包, agent_wallet:退回代理主钱包),不填沿用原有方式"`
|
||||
CustomerAccountInfo *string `json:"customer_account_info" validate:"omitempty,max=1000" maxLength:"1000" description:"客户收款信息,仅客户收款信息退款方式必填,不得复用公司线下收款方式字典"`
|
||||
RequestedRefundAmount *int64 `json:"requested_refund_amount" validate:"omitempty,min=1" minimum:"1" description:"申请退款金额(分)"`
|
||||
RequestedRefundAmount *int64 `json:"requested_refund_amount" validate:"omitempty,min=0" minimum:"0" description:"申请退款金额(分),不填沿用原金额;0 元退款规则同创建:仅限客户收款信息方式(钱包支付订单不支持),客户收款信息可不填但凭证必传"`
|
||||
RefundVoucherKey *[]string `json:"refund_voucher_key" validate:"omitempty,max=5,dive,max=500" maxItems:"5" description:"退款凭证对象存储file_key列表(重新提交时可替换;客户收款信息退款方式必填,最多5个)"`
|
||||
RefundReason *string `json:"refund_reason" validate:"omitempty,max=1000" maxLength:"1000" description:"退款原因(不填沿用原有原因;重提时去除首尾空白后不得为空)"`
|
||||
// Remark 是本次重提的申请人备注,随本次尝试冻结;不填沿用该退款单最近一次尝试的备注。
|
||||
|
||||
@@ -6,24 +6,15 @@ import (
|
||||
"github.com/break/junhong_cmp_fiber/internal/gateway"
|
||||
"github.com/break/junhong_cmp_fiber/internal/handler/admin"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/middleware"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/openapi"
|
||||
)
|
||||
|
||||
func registerDeviceRoutes(router fiber.Router, handler *admin.DeviceHandler, importHandler *admin.DeviceImportHandler, doc *openapi.Generator, basePath string) {
|
||||
devices := router.Group("/devices")
|
||||
groupPath := basePath + "/devices"
|
||||
platformDevices := router.Group("/devices", func(c *fiber.Ctx) error {
|
||||
userType := middleware.GetUserTypeFromContext(c.UserContext())
|
||||
if userType != constants.UserTypeSuperAdmin && userType != constants.UserTypePlatform {
|
||||
return errors.New(errors.CodeForbidden, constants.PlatformManagementForbiddenMessage)
|
||||
}
|
||||
return c.Next()
|
||||
})
|
||||
|
||||
Register(platformDevices, doc, groupPath, "GET", "/types", handler.ListDeviceTypes, RouteSpec{
|
||||
// 仅平台可用的判断放在 ListDeviceTypes 内部:Fiber 的 Group 带处理函数会注册为整个 /devices 前缀的中间件,会拦住代理与企业账号的所有设备接口。
|
||||
Register(devices, doc, groupPath, "GET", "/types", handler.ListDeviceTypes, RouteSpec{
|
||||
Summary: "查询设备类型选项",
|
||||
Description: "仅超级管理员与平台账号可访问。返回未删除设备中去重、去除首尾空白且按升序排列的非空设备类型字符串。",
|
||||
Tags: []string{"设备管理"},
|
||||
|
||||
38
internal/service/iot_card/stop_resume_polling_guard.go
Normal file
38
internal/service/iot_card/stop_resume_polling_guard.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package iot_card
|
||||
|
||||
import (
|
||||
"context"
|
||||
stderrors "errors"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
||||
)
|
||||
|
||||
// pollingDisabled 判断卡是否退出本系统自动停复机:卡级关闭轮询,或卡绑定的设备关闭轮询。
|
||||
// 关闭轮询的卡/设备已交由其他卡管管理,本系统任何入口都不得再对其自动停机或复机。
|
||||
// 查询失败时返回错误,由调用方放弃本次停复机,避免在状态不明时误操作。
|
||||
func (s *StopResumeService) pollingDisabled(ctx context.Context, card *model.IotCard) (bool, error) {
|
||||
if !card.EnablePolling {
|
||||
return true, nil
|
||||
}
|
||||
if s.db == nil {
|
||||
return false, nil
|
||||
}
|
||||
deviceID, bound, err := s.getCardDeviceID(ctx, card)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(errors.CodeDatabaseError, err, "查询卡绑定设备失败")
|
||||
}
|
||||
if !bound {
|
||||
return false, nil
|
||||
}
|
||||
var device model.Device
|
||||
if err := s.db.WithContext(ctx).Select("id", "enable_polling").First(&device, deviceID).Error; err != nil {
|
||||
if stderrors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return false, nil
|
||||
}
|
||||
return false, errors.Wrap(errors.CodeDatabaseError, err, "查询设备轮询状态失败")
|
||||
}
|
||||
return !device.EnablePolling, nil
|
||||
}
|
||||
45
internal/service/iot_card/stop_resume_polling_guard_test.go
Normal file
45
internal/service/iot_card/stop_resume_polling_guard_test.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package iot_card
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
||||
)
|
||||
|
||||
// 关闭轮询的卡已交由其他卡管:无论在线还是停机,EvaluateAndAct 都必须直接返回,
|
||||
// 不得进入停机原因判断或复机流程(服务未注入任何 store/网关,进入后续流程会直接 panic)。
|
||||
func TestEvaluateAndAct_CardPollingDisabledSkipsStopResume(t *testing.T) {
|
||||
svc := &StopResumeService{logger: zap.NewNop()}
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
card *model.IotCard
|
||||
}{
|
||||
{
|
||||
name: "在线卡无套餐不停机",
|
||||
card: &model.IotCard{NetworkStatus: constants.NetworkStatusOnline, EnablePolling: false, IsStandalone: false},
|
||||
},
|
||||
{
|
||||
name: "轮询原因停机的卡不复机",
|
||||
card: &model.IotCard{NetworkStatus: constants.NetworkStatusOffline, StopReason: constants.StopReasonNoPackage, EnablePolling: false},
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if err := svc.EvaluateAndAct(context.Background(), tc.card); err != nil {
|
||||
t.Fatalf("期望直接返回 nil,实际 %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvaluateAndAct_NilCard(t *testing.T) {
|
||||
svc := &StopResumeService{logger: zap.NewNop()}
|
||||
if err := svc.EvaluateAndAct(context.Background(), nil); err != nil {
|
||||
t.Fatalf("期望 nil,实际 %v", err)
|
||||
}
|
||||
}
|
||||
@@ -108,7 +108,19 @@ func (s *StopResumeService) SetPollingCallback(callback PollingCallback) {
|
||||
// EvaluateAndAct 停复机统一入口
|
||||
// 根据卡的当前网络状态,自动判断并执行停机或复机操作
|
||||
// 设备/单卡维度通过 card.IsStandalone 推导(false 则为设备维度,停/复机覆盖设备下所有卡)
|
||||
// 卡或其绑定设备关闭轮询时直接返回,不停机也不复机。
|
||||
func (s *StopResumeService) EvaluateAndAct(ctx context.Context, card *model.IotCard) error {
|
||||
if card == nil {
|
||||
return nil
|
||||
}
|
||||
disabled, err := s.pollingDisabled(ctx, card)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if disabled {
|
||||
s.logger.Debug("卡或绑定设备已关闭轮询,跳过自动停复机", zap.Uint("card_id", card.ID))
|
||||
return nil
|
||||
}
|
||||
switch card.NetworkStatus {
|
||||
case constants.NetworkStatusOnline:
|
||||
// 卡在线,检查是否需要停机
|
||||
|
||||
@@ -63,6 +63,15 @@ func (s *Service) clawbackCommission(ctx context.Context, refundID uint) error {
|
||||
if refund.Method == constants.RefundMethodOriginalRoute && refund.ChannelRefundStatus != constants.RefundChannelStatusSucceeded {
|
||||
return errors.New(errors.CodeServiceUnavailable, "原路退款渠道结果尚未明确成功,暂不生成佣金回溯")
|
||||
}
|
||||
// 0 元退款只作废权益、不退钱,佣金不处理:与订单佣金是否已终态无关,直接闭合为无需回溯,
|
||||
// 不能落到下方「成功金额非正」的可恢复失败而反复重试。原路退款的成功金额由渠道决定,不走这里。
|
||||
if isZeroAmountRefund(&refund) {
|
||||
return s.settleClawback(ctx, &refund, constants.AuditActionRefundClawbackNotRequired,
|
||||
"0 元退款无需回溯佣金", clawbackEventID(refund.ID, "clawback-not-required"),
|
||||
map[string]any{
|
||||
"order_id": refund.OrderID, "zero_amount_refund": true, "clawback_required": false,
|
||||
})
|
||||
}
|
||||
|
||||
// 订单佣金未终态时等待:此时「无已发放佣金」只代表尚未计算完成或尚待人工修正,
|
||||
// 提前判定为无需回溯会让后续入账的佣金永久失去回溯机会,违反「MUST NOT 提前判定为无需回溯」。
|
||||
@@ -171,6 +180,12 @@ func (s *Service) clawbackCommission(ctx context.Context, refundID uint) error {
|
||||
return s.applyClawback(ctx, &refund, allocations)
|
||||
}
|
||||
|
||||
// isZeroAmountRefund 判定已通过的退款是否为 0 元退款:非原路方式(含方式为空的存量申请)且审批退款金额为 0。
|
||||
func isZeroAmountRefund(refund *model.RefundRequest) bool {
|
||||
return refund.Method != constants.RefundMethodOriginalRoute &&
|
||||
refund.ApprovedRefundAmount != nil && *refund.ApprovedRefundAmount == 0
|
||||
}
|
||||
|
||||
// clawbackEventID 生成回溯审计事件的稳定键,重复执行返回同一事件,审计写入因此天然幂等。
|
||||
func clawbackEventID(refundID uint, suffix string) string {
|
||||
return "refund:" + strconv.FormatUint(uint64(refundID), 10) + ":" + suffix
|
||||
|
||||
@@ -36,7 +36,8 @@ type refundMethodDecision struct {
|
||||
// decideRefundMethods 派生权威实收金额并按来源实际支付方式生成可选退款方式。
|
||||
//
|
||||
// 派生来源:线上支付取该订单原成功支付记录金额;资产钱包、代理主钱包与后台线下套餐订单
|
||||
// 取订单实际收款或实际扣款金额。无法确定或金额非正时拒绝,绝不允许提交人以自填金额替代。
|
||||
// 取订单实际收款或实际扣款金额。无法确定或金额非正时拒绝,绝不允许提交人以自填金额替代;
|
||||
// 唯一例外是后台线下订单实收为 0(如迁移订单),冻结实收取 0,只能申请 0 元退款。
|
||||
func (s *Service) decideRefundMethods(ctx context.Context, order *model.Order) (*refundMethodDecision, error) {
|
||||
if order == nil || order.ID == 0 {
|
||||
return nil, errors.New(errors.CodeInvalidParam, "退款来源订单无效")
|
||||
@@ -44,7 +45,8 @@ func (s *Service) decideRefundMethods(ctx context.Context, order *model.Order) (
|
||||
|
||||
decision := &refundMethodDecision{}
|
||||
switch order.PaymentMethod {
|
||||
case model.PaymentMethodWechat, model.PaymentMethodAlipay:
|
||||
// 富友是微信支付的上游通道,套餐订单回调写入 fuiou,按线上支付处理。
|
||||
case model.PaymentMethodWechat, model.PaymentMethodAlipay, model.ProviderTypeFuiou:
|
||||
payment, err := s.loadPaidPackagePayment(ctx, order.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -81,7 +83,7 @@ func (s *Service) decideRefundMethods(ctx context.Context, order *model.Order) (
|
||||
return nil, errors.New(errors.CodeInvalidParam, "钱包支付订单的买家类型不支持退款")
|
||||
}
|
||||
case model.PaymentMethodOffline:
|
||||
amount, err := orderActualPaidAmount(order)
|
||||
amount, err := offlineActualPaidAmount(order)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -103,6 +105,14 @@ func orderActualPaidAmount(order *model.Order) (int64, error) {
|
||||
return *order.ActualPaidAmount, nil
|
||||
}
|
||||
|
||||
// offlineActualPaidAmount 取后台线下订单的实际收款金额:允许为 0(只能申请 0 元退款),缺失或为负时拒绝。
|
||||
func offlineActualPaidAmount(order *model.Order) (int64, error) {
|
||||
if order.ActualPaidAmount == nil || *order.ActualPaidAmount < 0 {
|
||||
return 0, errors.New(errors.CodeInvalidParam, "订单实际收款金额缺失或为负,无法确定权威实收金额")
|
||||
}
|
||||
return *order.ActualPaidAmount, nil
|
||||
}
|
||||
|
||||
// loadPaidPackagePayment 读取该订单原成功的线上支付记录。
|
||||
func (s *Service) loadPaidPackagePayment(ctx context.Context, orderID uint) (*model.Payment, error) {
|
||||
var payment model.Payment
|
||||
@@ -219,12 +229,13 @@ func validateRefundMethod(decision *refundMethodDecision, method string) error {
|
||||
}
|
||||
|
||||
// validateCustomerAccountMaterial 校验客户收款信息方式的材料完整性。
|
||||
// 客户收款信息与至少一个客户凭证附件必须同时存在;不得复用公司员工收款方式字典。
|
||||
func validateCustomerAccountMaterial(method, customerAccountInfo string, voucherKeys []string) error {
|
||||
// 正数退款时客户收款信息与至少一个客户凭证附件必须同时存在;0 元退款不退钱,客户收款信息可为空,
|
||||
// 但仍须至少一个客户凭证附件。不得复用公司员工收款方式字典。
|
||||
func validateCustomerAccountMaterial(method string, amount int64, customerAccountInfo string, voucherKeys []string) error {
|
||||
if method != constants.RefundMethodCustomerAccount {
|
||||
return nil
|
||||
}
|
||||
if strings.TrimSpace(customerAccountInfo) == "" {
|
||||
if amount > 0 && strings.TrimSpace(customerAccountInfo) == "" {
|
||||
return errors.New(errors.CodeInvalidParam, "客户收款信息退款必须填写客户收款信息")
|
||||
}
|
||||
hasVoucher := false
|
||||
@@ -240,13 +251,13 @@ func validateCustomerAccountMaterial(method, customerAccountInfo string, voucher
|
||||
return nil
|
||||
}
|
||||
|
||||
// validateFrozenRefundAmount 校验退款金额为正分且不超过冻结实收金额。
|
||||
// validateFrozenRefundAmount 校验退款金额不为负且不超过冻结实收金额;0 元退款表示作废权益、不退钱。
|
||||
func validateFrozenRefundAmount(amount, frozenActualReceivedAmount int64) error {
|
||||
if amount <= 0 {
|
||||
return errors.New(errors.CodeInvalidParam, "退款金额必须为正分")
|
||||
if amount < 0 {
|
||||
return errors.New(errors.CodeInvalidParam, "退款金额不能为负")
|
||||
}
|
||||
if frozenActualReceivedAmount <= 0 {
|
||||
return errors.New(errors.CodeInvalidParam, "冻结实收金额缺失或非正,无法受理退款申请")
|
||||
if frozenActualReceivedAmount < 0 {
|
||||
return errors.New(errors.CodeInvalidParam, "冻结实收金额为负,无法受理退款申请")
|
||||
}
|
||||
if amount > frozenActualReceivedAmount {
|
||||
return errors.New(errors.CodeInvalidParam, "退款金额不能超过冻结实收金额")
|
||||
@@ -254,6 +265,15 @@ func validateFrozenRefundAmount(amount, frozenActualReceivedAmount int64) error
|
||||
return nil
|
||||
}
|
||||
|
||||
// validateZeroAmountMethod 校验 0 元退款只能选客户收款信息方式:原路退款与退回原钱包都要动钱。
|
||||
// 钱包支付订单的方式矩阵不含客户收款信息,因此本校验同时保证钱包订单不能申请 0 元退款。
|
||||
func validateZeroAmountMethod(amount int64, method string) error {
|
||||
if amount == 0 && strings.TrimSpace(method) != constants.RefundMethodCustomerAccount {
|
||||
return errors.New(errors.CodeInvalidParam, "0 元退款仅支持客户收款信息方式")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// buildChannelRefundRequestNo 仅在原路退款方式下按冻结商户派生本次尝试的渠道退款请求号。
|
||||
// 请求号由收口审批申请用例冻结到不可变尝试记录上,同一尝试的渠道重试复用它作为幂等标识,
|
||||
// 重提生成新值;非原路方式返回空串。
|
||||
|
||||
@@ -175,11 +175,14 @@ func (s *Service) Create(ctx context.Context, req *dto.CreateRefundRequest) (*dt
|
||||
if err := validateFrozenRefundAmount(req.RequestedRefundAmount, decision.FrozenActualReceivedAmount); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := validateZeroAmountMethod(req.RequestedRefundAmount, req.Method); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
refundVoucherKey, err := normalizeRefundVoucherKey(req.RefundVoucherKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := validateCustomerAccountMaterial(req.Method, req.CustomerAccountInfo, refundVoucherKey); err != nil {
|
||||
if err := validateCustomerAccountMaterial(req.Method, req.RequestedRefundAmount, req.CustomerAccountInfo, refundVoucherKey); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -860,6 +863,10 @@ func (s *Service) Resubmit(ctx context.Context, id uint, req *dto.ResubmitRefund
|
||||
s.recordRefundFailure(ctx, constants.AuditActionRefundResubmitted, "重新提交退款申请失败", refund, order, err)
|
||||
return err
|
||||
}
|
||||
if err := validateZeroAmountMethod(requestedRefundAmount, method); err != nil {
|
||||
s.recordRefundFailure(ctx, constants.AuditActionRefundResubmitted, "重新提交退款申请失败", refund, order, err)
|
||||
return err
|
||||
}
|
||||
refundVoucherKey := refund.RefundVoucherKey
|
||||
if req.RefundVoucherKey != nil {
|
||||
normalized, normErr := normalizeRefundVoucherKey(*req.RefundVoucherKey)
|
||||
@@ -884,7 +891,7 @@ func (s *Service) Resubmit(ctx context.Context, id uint, req *dto.ResubmitRefund
|
||||
if req.CustomerAccountInfo != nil {
|
||||
customerAccountInfo = *req.CustomerAccountInfo
|
||||
}
|
||||
if err := validateCustomerAccountMaterial(method, customerAccountInfo, refundVoucherKey); err != nil {
|
||||
if err := validateCustomerAccountMaterial(method, requestedRefundAmount, customerAccountInfo, refundVoucherKey); err != nil {
|
||||
s.recordRefundFailure(ctx, constants.AuditActionRefundResubmitted, "重新提交退款申请失败", refund, nil, err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ func (s *Service) SendCode(ctx context.Context, phone string) error {
|
||||
|
||||
// 构造短信内容
|
||||
cfg := config.Get()
|
||||
content := fmt.Sprintf("您的验证码是%s,%d分钟内有效", code, int(constants.VerificationCodeExpiration.Minutes()))
|
||||
content := fmt.Sprintf("您的验证码是%s,请在%d分钟内输入验证。如非本人操作,请忽略本短信。", code, int(constants.VerificationCodeExpiration.Minutes()))
|
||||
|
||||
// 发送短信
|
||||
_, err = s.smsClient.SendMessage(ctx, content, []string{phone})
|
||||
|
||||
Reference in New Issue
Block a user