chore: 并入 iotlcm-admin-svr 历史到 admin-svr/(原提交 49818c6)
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
)
|
||||
|
||||
type AlipayConfig struct {
|
||||
AppId string `json:"appId" yaml:"appId"`
|
||||
PrivateKey string `json:"privateKey" yaml:"privateKey"`
|
||||
AlipayPublicKey string `json:"alipayPublicKey" yaml:"alipayPublicKey"`
|
||||
NotifyUrl string `json:"notifyUrl" yaml:"notifyUrl"`
|
||||
ReturnUrl string `json:"returnUrl" yaml:"returnUrl"`
|
||||
IsProduction bool `json:"isProduction" yaml:"isProduction"`
|
||||
}
|
||||
|
||||
type AlipayPayInput struct {
|
||||
OutTradeNo string `json:"outTradeNo" dc:"商户订单号"`
|
||||
Subject string `json:"subject" dc:"订单标题" v:"required#订单标题不能为空"`
|
||||
TotalAmount string `json:"totalAmount" dc:"支付金额(元)" v:"required#支付金额不能为空"`
|
||||
PayType string `json:"payType" dc:"支付类型:page 电脑网站支付,wap 手机网站支付" d:"page"`
|
||||
BusinessType string `json:"businessType" dc:"业务类型:balanceRecharge 余额充值"`
|
||||
}
|
||||
|
||||
type AlipayPayOutput struct {
|
||||
OutTradeNo string `json:"outTradeNo" dc:"商户订单号"`
|
||||
PayUrl string `json:"payUrl" dc:"支付链接"`
|
||||
}
|
||||
|
||||
type AlipayNotifyInput struct{}
|
||||
|
||||
type AlipayNotifyOutput struct{}
|
||||
|
||||
type AlipayReturnInput struct {
|
||||
RefundAmount string `json:"refundAmount" dc:"退款金额(元)" `
|
||||
OutTradeNo string `json:"outTradeNo" dc:"商户订单号"`
|
||||
TradeNo string `json:"tradeNo" dc:"支付宝交易号" `
|
||||
}
|
||||
|
||||
type AlipayReturnOutput struct {
|
||||
OutTradeNo string `json:"outTradeNo" dc:"商户订单号"`
|
||||
TradeNo string `json:"tradeNo" dc:"支付宝交易号"`
|
||||
TotalAmount string `json:"totalAmount" dc:"交易金额"`
|
||||
Message string `json:"message" dc:"消息"`
|
||||
}
|
||||
|
||||
type AlipayTradeQueryInput struct {
|
||||
OutTradeNo string `json:"outTradeNo" dc:"商户订单号"`
|
||||
TradeNo string `json:"tradeNo" dc:"支付宝交易号"`
|
||||
}
|
||||
|
||||
type AlipayTradeQueryOutput struct {
|
||||
OutTradeNo string `json:"outTradeNo" dc:"商户订单号"`
|
||||
TradeNo string `json:"tradeNo" dc:"支付宝交易号"`
|
||||
TradeStatus string `json:"tradeStatus" dc:"交易状态"`
|
||||
TotalAmount string `json:"totalAmount" dc:"交易金额"`
|
||||
BuyerLogonId string `json:"buyerLogonId" dc:"买家支付宝账号"`
|
||||
BuyerUserId string `json:"buyerUserId" dc:"买家支付宝用户ID"`
|
||||
BuyerOpenId string `json:"buyerOpenId" dc:"买家支付宝OpenID"`
|
||||
SendPayDate string `json:"sendPayDate" dc:"交易付款时间"`
|
||||
}
|
||||
|
||||
type AlipayRefundInput struct {
|
||||
OutRequestNo string `json:"outRequestNo" dc:"退款请求号" v:"required#退款请求号不能为空"`
|
||||
RefundReason string `json:"refundReason" dc:"退款原因"`
|
||||
OutTradeNo string `json:"outTradeNo" dc:"商户订单号"`
|
||||
TradeNo string `json:"tradeNo" dc:"支付宝交易号"`
|
||||
RefundAmount string `json:"refundAmount" dc:"退款金额(元)" v:"required#退款金额不能为空"`
|
||||
}
|
||||
|
||||
type AlipayRefundOutput struct {
|
||||
TradeNo string `json:"tradeNo" dc:"支付宝交易号"`
|
||||
OutTradeNo string `json:"outTradeNo" dc:"商户订单号"`
|
||||
BuyerLogonId string `json:"buyerLogonId" dc:"买家支付宝账号"`
|
||||
RefundFee string `json:"refundFee" dc:"退款总金额(元)"`
|
||||
}
|
||||
|
||||
var alipayRefundAmountPattern = regexp.MustCompile(`^(0|[1-9]\d{0,13})(\.\d{1,2})?$`)
|
||||
|
||||
// AlipayRefundModel is the validated data sent to the Alipay refund SDK.
|
||||
type AlipayRefundModel struct {
|
||||
OutTradeNo string
|
||||
TradeNo string
|
||||
OutRequestNo string
|
||||
RefundAmount string
|
||||
RefundReason string
|
||||
}
|
||||
|
||||
func (in *AlipayRefundInput) Normalize() (*AlipayRefundModel, error) {
|
||||
if in == nil {
|
||||
return nil, gerror.New("退款参数不能为空")
|
||||
}
|
||||
refund := &AlipayRefundModel{
|
||||
OutTradeNo: strings.TrimSpace(in.OutTradeNo),
|
||||
TradeNo: strings.TrimSpace(in.TradeNo),
|
||||
OutRequestNo: strings.TrimSpace(in.OutRequestNo),
|
||||
RefundAmount: strings.TrimSpace(in.RefundAmount),
|
||||
RefundReason: strings.TrimSpace(in.RefundReason),
|
||||
}
|
||||
if refund.OutTradeNo == "" && refund.TradeNo == "" {
|
||||
return nil, gerror.New("商户订单号和支付宝交易号不能同时为空")
|
||||
}
|
||||
if len(refund.OutTradeNo) > 64 || len(refund.TradeNo) > 64 {
|
||||
return nil, gerror.New("商户订单号或支付宝交易号长度不能超过64位")
|
||||
}
|
||||
if !alipayRefundAmountPattern.MatchString(refund.RefundAmount) || refund.RefundAmount == "0" || strings.HasPrefix(refund.RefundAmount, "0.") && strings.Trim(refund.RefundAmount, "0.") == "" {
|
||||
return nil, gerror.New("退款金额格式错误,金额必须大于0且最多两位小数")
|
||||
}
|
||||
if refund.OutRequestNo == "" {
|
||||
refund.OutRequestNo = refund.OutTradeNo
|
||||
if refund.OutRequestNo == "" {
|
||||
refund.OutRequestNo = refund.TradeNo
|
||||
}
|
||||
}
|
||||
return refund, nil
|
||||
}
|
||||
Reference in New Issue
Block a user