This commit is contained in:
苏尹岚
2020-10-14 15:25:26 +08:00
parent 3fa46c9afd
commit cbe94c7916
4 changed files with 67 additions and 14 deletions

View File

@@ -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
}

View File

@@ -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{

View 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)
}

View File

@@ -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 {