pay
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
package cms
|
package cms
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"git.rosy.net.cn/jx-callback/business/jxstore/financial"
|
"git.rosy.net.cn/jx-callback/business/jxstore/financial"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
"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")
|
err = dao.GetEntity(db, order, "OrderID")
|
||||||
switch payType {
|
err = financial.IPayHandler.CreatePay(order, payType, vendorPayType)
|
||||||
case model.PayTypeTL:
|
|
||||||
err = financial.Pay4OrderByTL(ctx, order, payType, vendorPayType)
|
|
||||||
default:
|
|
||||||
err = fmt.Errorf("支付方式:%d当前不支持", payType)
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package financial
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -16,6 +17,49 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
"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) {
|
func Pay4OrderByTL(ctx *jxcontext.Context, order *model.GoodsOrder, payType int, vendorPayType string) (orderPay *model.OrderPay, err error) {
|
||||||
payCreatedAt := time.Now()
|
payCreatedAt := time.Now()
|
||||||
param := &tonglianpayapi.CreateUnitorderOrderParam{
|
param := &tonglianpayapi.CreateUnitorderOrderParam{
|
||||||
|
|||||||
13
business/jxstore/financial/pay.go
Normal file
13
business/jxstore/financial/pay.go
Normal file
@@ -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)
|
||||||
|
}
|
||||||
@@ -445,12 +445,15 @@ func IsAfsOrderJXTemp(order *AfsOrder) bool {
|
|||||||
type Order struct {
|
type Order struct {
|
||||||
ModelIDCUL
|
ModelIDCUL
|
||||||
|
|
||||||
OrderID int64 `orm:"column(order_id)" json:"orderID"` //订单号
|
OrderID int64 `orm:"column(order_id)" json:"orderID"` //订单号
|
||||||
UserID string `orm:"column(user_id);size(48)" json:"userID"` //用户ID
|
UserID string `orm:"column(user_id);size(48)" json:"userID"` //用户ID
|
||||||
Type int `json:"type"` //订单类型
|
Type int `json:"type"` //订单类型
|
||||||
Status int `json:"status"` //订单状态,待支付2,已支付5,支付成功110,支付失败115
|
Status int `json:"status"` //订单状态,待支付2,已支付5,支付成功110,支付失败115
|
||||||
PayPrice int `json:"payPrice"` //支付金额
|
PayPrice int `json:"payPrice"` //支付金额
|
||||||
Comment string `orm:"size(255)" json:"comment"` //备注
|
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 {
|
func (v *Order) TableIndex() [][]string {
|
||||||
|
|||||||
Reference in New Issue
Block a user