支付功能动态化扩展
This commit is contained in:
@@ -32,19 +32,13 @@ type tradeService struct {
|
||||
}
|
||||
|
||||
// 创建交易
|
||||
func (s *tradeService) CreateTrade(uid int32, now time.Time, data *CreateTradeData) (*CreateTradeResult, error) {
|
||||
platform := data.Platform
|
||||
method := data.Method
|
||||
tType := data.Product.GetType()
|
||||
func (s *tradeService) CreateTrade(uid int32, now time.Time, payment *CreateTradeData, product ProductInfo) (*CreateTradeResult, error) {
|
||||
platform := payment.Platform
|
||||
method := payment.Method
|
||||
tType := product.GetType()
|
||||
expire := time.Now().Add(30 * time.Minute)
|
||||
subject, err := data.Product.GetSubject()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
amount, err := data.Product.GetAmount()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
subject := product.GetSubject()
|
||||
amount := product.GetAmount()
|
||||
|
||||
// 实际支付金额,只在创建真实订单时使用
|
||||
amountReal := amount
|
||||
@@ -53,10 +47,10 @@ func (s *tradeService) CreateTrade(uid int32, now time.Time, data *CreateTradeDa
|
||||
}
|
||||
|
||||
// 附加优惠券
|
||||
if data.CouponCode != nil {
|
||||
if payment.CouponCode != nil {
|
||||
coupon, err := q.Coupon.
|
||||
Where(
|
||||
q.Coupon.Code.Eq(*data.CouponCode),
|
||||
q.Coupon.Code.Eq(*payment.CouponCode),
|
||||
q.Coupon.Status.Eq(int(m.CouponStatusUnused)),
|
||||
).
|
||||
Take()
|
||||
@@ -248,7 +242,7 @@ func (s *tradeService) CreateTrade(uid int32, now time.Time, data *CreateTradeDa
|
||||
}
|
||||
|
||||
// 缓存产品数据
|
||||
serialized, err := data.Product.Serialize()
|
||||
serialized, err := product.Serialize()
|
||||
if err != nil {
|
||||
return nil, core.NewServErr("序列化产品信息失败", err)
|
||||
}
|
||||
@@ -684,7 +678,6 @@ type CreateTradeData struct {
|
||||
Platform m.TradePlatform `json:"platform" validate:"required"`
|
||||
Method m.TradeMethod `json:"method" validate:"required"`
|
||||
CouponCode *string `json:"coupon_code"`
|
||||
Product ProductInfo
|
||||
}
|
||||
|
||||
type CreateTradeResult struct {
|
||||
@@ -717,8 +710,8 @@ type OnTradeCompletedData struct {
|
||||
|
||||
type ProductInfo interface {
|
||||
GetType() m.TradeType
|
||||
GetSubject() (string, error)
|
||||
GetAmount() (decimal.Decimal, error)
|
||||
GetSubject() string
|
||||
GetAmount() decimal.Decimal
|
||||
Serialize() (string, error)
|
||||
Deserialize(str string) error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user