From 06b6c24d7ff75a584a9c6e0b292e632293a45eea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AD=90=E9=93=AD?= Date: Mon, 11 Nov 2024 17:13:58 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=B4=E5=85=85=E7=B1=BB=E5=9E=8B=E5=95=86?= =?UTF-8?q?=E5=93=81=E5=BF=85=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/zltx_v2/internal/transform.go | 28 ++++++++------------- plugins/zltx_v2/internal/vo/account_type.go | 26 +++++++++++++++++++ 2 files changed, 36 insertions(+), 18 deletions(-) create mode 100644 plugins/zltx_v2/internal/vo/account_type.go diff --git a/plugins/zltx_v2/internal/transform.go b/plugins/zltx_v2/internal/transform.go index 96b6653..70c0770 100644 --- a/plugins/zltx_v2/internal/transform.go +++ b/plugins/zltx_v2/internal/transform.go @@ -6,7 +6,6 @@ import ( "gitee.com/chengdu_blue_brothers/openapi-go-sdk-v2/api" "gitee.com/chengdu_blue_brothers/openapi-go-sdk-v2/notify" "gitee.com/chengdu_blue_brothers/openapi-go-sdk-v2/sdk" - "plugins/utils/helper" "plugins/zltxv2/internal/vo" ) @@ -46,24 +45,17 @@ func (c *Config) client() (*sdk.Client, error) { } func (c *Config) orderReq(in *proto.OrderRequest) *api.OrderCreateReq { - accountType := int64(0) - if in.Order.Account == "" { - accountType = 0 - } else if helper.IsPhoneNumber(in.Order.Account) { - accountType = 1 - } else if helper.IsValidQQ(in.Order.Account) { - accountType = 2 - } + var accountType vo.AccountType return &api.OrderCreateReq{ - OutTradeNo: in.Order.OrderNo, // 商户侧订单号长度只能是1-64位 - ProductId: in.Product.ProductNo, // 产品编码不能为空 - Number: int(in.Order.Quantity), // 部分商品存在限购数量,具体可联系商务 - NotifyUrl: c.NotifyUrl, // 订单回调通知地址长度不能为空,且长度不能超过255 - Extends: string(in.Order.Extra), // 部分特殊商品需要,具体可联系商务 - RechargeAccount: in.Order.Account, // 账号类型:直充类型商品必传,商品为卡密类型时,则表示接收卡密的手机号 - AccountType: accountType, // 直充类型商品必传 - 1:手机号 - 2: QQ 号 - Attach: "", // 透传参数,当传了此参数时,查询和回调接口中将原样携带此参数 - UnitPrice: 0, // 交易商品单价,单位:元(最多保留4位小数) - 0或不传表示不限制 - 当此价格小于采购价时,下单失败 + OutTradeNo: in.Order.OrderNo, // 商户侧订单号长度只能是1-64位 + ProductId: in.Product.ProductNo, // 产品编码不能为空 + Number: int(in.Order.Quantity), // 部分商品存在限购数量,具体可联系商务 + NotifyUrl: c.NotifyUrl, // 订单回调通知地址长度不能为空,且长度不能超过255 + Extends: string(in.Order.Extra), // 部分特殊商品需要,具体可联系商务 + RechargeAccount: in.Order.Account, // 账号类型:直充类型商品必传,商品为卡密类型时,则表示接收卡密的手机号 + AccountType: accountType.AccountType(in.Order.Account).Value(), // 直充类型商品必传 - 1:手机号 - 2: QQ 号 + Attach: "", // 透传参数,当传了此参数时,查询和回调接口中将原样携带此参数 + UnitPrice: 0, // 交易商品单价,单位:元(最多保留4位小数) - 0或不传表示不限制 - 当此价格小于采购价时,下单失败 } } diff --git a/plugins/zltx_v2/internal/vo/account_type.go b/plugins/zltx_v2/internal/vo/account_type.go new file mode 100644 index 0000000..658363a --- /dev/null +++ b/plugins/zltx_v2/internal/vo/account_type.go @@ -0,0 +1,26 @@ +package vo + +import "plugins/utils/helper" + +type AccountType int64 + +const ( + AccountTypeDefault AccountType = iota // 充值成功 + AccountTypePhone + AccountTypeQQ +) + +func (o AccountType) AccountType(account string) AccountType { + if account == "" { + return AccountTypeDefault + } else if helper.IsPhoneNumber(account) { + return AccountTypePhone + } else if helper.IsValidQQ(account) { + return AccountTypeQQ + } + return AccountTypeDefault +} + +func (o AccountType) Value() int64 { + return int64(o) +}