diff --git a/business/jxstore/cms/order.go b/business/jxstore/cms/order.go index 6f3965ee2..b1ef27c56 100644 --- a/business/jxstore/cms/order.go +++ b/business/jxstore/cms/order.go @@ -1,8 +1,6 @@ package cms import ( - "fmt" - "git.rosy.net.cn/jx-callback/business/jxstore/financial" "git.rosy.net.cn/jx-callback/business/jxutils" @@ -51,11 +49,6 @@ func Pay(ctx *jxcontext.Context, orderID, payType int, vendorPayType string) (er } ) err = dao.GetEntity(db, order, "OrderID") - switch payType { - case model.PayTypeTL: - err = financial.Pay4OrderByTL(ctx, order, payType, vendorPayType) - default: - err = fmt.Errorf("支付方式:%d当前不支持", payType) - } + err = financial.IPayHandler.CreatePay(order, payType, vendorPayType) return err } diff --git a/business/jxstore/financial/financial.go b/business/jxstore/financial/financial.go index 60679579e..73c480e4c 100644 --- a/business/jxstore/financial/financial.go +++ b/business/jxstore/financial/financial.go @@ -2,6 +2,7 @@ package financial import ( "encoding/json" + "fmt" "strings" "time" @@ -16,6 +17,49 @@ import ( "git.rosy.net.cn/jx-callback/globals/api" ) +var ( + IPayHandler PayHandlerInterface +) + +func (p *PayHandler) CreatePay(order *model.Order, payType int, vendorPayType string) (err error) { + switch payType { + case model.PayTypeTL: + param := &tonglianpayapi.CreateUnitorderOrderParam{ + Trxamt: int(order.PayPrice), + NotifyUrl: globals.TLPayNotifyURL, + Reqsn: utils.Int64ToStr(order.OrderID), + PayType: vendorPayType, + } + if vendorPayType == tonglianpayapi.PayTypeWxXcx { + if authInfo, err := ctx.GetV2AuthInfo(); err == nil && authInfo.GetAuthType() == weixin.AuthTypeMini { + param.Acct = authInfo.GetAuthID() + } + } + result, err := api.TLpayAPI.CreateUnitorderOrder(param) + if err == nil { + var result2 tonglianpayapi.PayInfo + json.Unmarshal([]byte(result.PayInfo), &result2) + order.PrepayID = result2.Package[strings.LastIndex(result2.Package, "=")+1 : len(result2.Package)] + orderPay = &model.OrderPay{ + PayOrderID: param.Reqsn, + PayType: payType, + VendorPayType: vendorPayType, + TransactionID: result.TrxID, + VendorOrderID: order.VendorOrderID, + VendorID: order.VendorID, + Status: 0, + PayCreatedAt: payCreatedAt, + PrepayID: prePayID, + CodeURL: utils.LimitUTF8StringLen(result.PayInfo, 3200), + TotalFee: int(order.ActualPayPrice), + } + } + default: + err = fmt.Errorf("支付方式:%d当前不支持", payType) + } + return err +} + func Pay4OrderByTL(ctx *jxcontext.Context, order *model.GoodsOrder, payType int, vendorPayType string) (orderPay *model.OrderPay, err error) { payCreatedAt := time.Now() param := &tonglianpayapi.CreateUnitorderOrderParam{ diff --git a/business/jxstore/financial/pay.go b/business/jxstore/financial/pay.go new file mode 100644 index 000000000..6f82107b6 --- /dev/null +++ b/business/jxstore/financial/pay.go @@ -0,0 +1,13 @@ +package financial + +import ( + "git.rosy.net.cn/jx-callback/business/model" +) + +type PayHandler struct { + PayType int `json:"-"` //支付方式 +} + +type PayHandlerInterface interface { + CreatePay(order *model.Order, payType int, vendorPayType string) (err error) +} diff --git a/business/model/order.go b/business/model/order.go index c1cf33aa2..974d908f8 100644 --- a/business/model/order.go +++ b/business/model/order.go @@ -445,12 +445,15 @@ func IsAfsOrderJXTemp(order *AfsOrder) bool { type Order struct { ModelIDCUL - OrderID int64 `orm:"column(order_id)" json:"orderID"` //订单号 - UserID string `orm:"column(user_id);size(48)" json:"userID"` //用户ID - Type int `json:"type"` //订单类型 - Status int `json:"status"` //订单状态,待支付2,已支付5,支付成功110,支付失败115 - PayPrice int `json:"payPrice"` //支付金额 - Comment string `orm:"size(255)" json:"comment"` //备注 + OrderID int64 `orm:"column(order_id)" json:"orderID"` //订单号 + UserID string `orm:"column(user_id);size(48)" json:"userID"` //用户ID + Type int `json:"type"` //订单类型 + Status int `json:"status"` //订单状态,待支付2,已支付5,支付成功110,支付失败115 + PayPrice int `json:"payPrice"` //支付金额 + TransactionID string `orm:"column(transaction_id);size(48)" json:"transactionID"` // 支付成功后,支付方生成的事务ID + PayFinishedAt *time.Time `orm:"type(datetime);null" json:"payFinishedAt"` + PrepayID string `orm:"column(prepay_id);size(48)" json:"prepayID"` // 下单后,支付前,支付方生成的事务ID + Comment string `orm:"size(255)" json:"comment"` //备注 } func (v *Order) TableIndex() [][]string {