规范气站与配送点提现渠道
This commit is contained in:
11
backend/api/internal/logic/common/withdrawal_channel.go
Normal file
11
backend/api/internal/logic/common/withdrawal_channel.go
Normal file
@@ -0,0 +1,11 @@
|
||||
// Package common 提供跨管理端复用的提现渠道约束。
|
||||
// 版本:v1.0.0
|
||||
package common
|
||||
|
||||
// OrganizationWithdrawalChannelBank 是当前组织钱包唯一开放的提现渠道。
|
||||
const OrganizationWithdrawalChannelBank = "bank"
|
||||
|
||||
// IsSupportedOrganizationWithdrawalChannel 判断气站或配送点提交的渠道是否已开放。
|
||||
func IsSupportedOrganizationWithdrawalChannel(channel string) bool {
|
||||
return channel == OrganizationWithdrawalChannelBank
|
||||
}
|
||||
15
backend/api/internal/logic/common/withdrawal_channel_test.go
Normal file
15
backend/api/internal/logic/common/withdrawal_channel_test.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package common
|
||||
|
||||
import "testing"
|
||||
|
||||
// TestIsSupportedOrganizationWithdrawalChannel 验证组织端只开放银行卡提现。
|
||||
func TestIsSupportedOrganizationWithdrawalChannel(t *testing.T) {
|
||||
if !IsSupportedOrganizationWithdrawalChannel("bank") {
|
||||
t.Fatal("银行卡提现渠道应当可用")
|
||||
}
|
||||
for _, channel := range []string{"alipay", "wechat", "", " bank "} {
|
||||
if IsSupportedOrganizationWithdrawalChannel(channel) {
|
||||
t.Fatalf("未开放的提现渠道不应通过校验:%q", channel)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -206,7 +206,8 @@ func CreateApplyCash(ctx *gin.Context) {
|
||||
Channel string `json:"channel" binding:"required,max=32"`
|
||||
Remark string `json:"remark" binding:"max=2000"`
|
||||
}
|
||||
if err := ctx.ShouldBindJSON(&request); err != nil || request.Amount <= 0 || strings.TrimSpace(request.RequestNo) == "" {
|
||||
if err := ctx.ShouldBindJSON(&request); err != nil || request.Amount <= 0 || strings.TrimSpace(request.RequestNo) == "" ||
|
||||
!common.IsSupportedOrganizationWithdrawalChannel(request.Channel) {
|
||||
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -133,7 +133,8 @@ func CreateWalletApplyCash(ctx *gin.Context) {
|
||||
Remark string `json:"remark" binding:"max=2000"`
|
||||
}
|
||||
if err := ctx.ShouldBindJSON(&request); err != nil || request.Amount <= 0 ||
|
||||
strings.TrimSpace(request.RequestNo) == "" {
|
||||
strings.TrimSpace(request.RequestNo) == "" ||
|
||||
!common.IsSupportedOrganizationWithdrawalChannel(request.Channel) {
|
||||
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user