1
This commit is contained in:
@@ -79,7 +79,7 @@ func CreateOrder(ctx *jxcontext.Context, type1, orderType int, way string, price
|
||||
return order.OrderID, errCode, err
|
||||
}
|
||||
|
||||
func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType string) (result *financial.WxPayParam, err error) {
|
||||
func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType, appId string) (result *financial.WxPayParam, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
order = &model.Order{
|
||||
@@ -109,7 +109,7 @@ func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType stri
|
||||
if userBill == nil {
|
||||
err = financial.AddUserBill(txDB, jxutils.GenBillID(), order.UserID)
|
||||
}
|
||||
err = payHandler.CreatePay(txDB)
|
||||
err = payHandler.CreatePay(txDB, appId)
|
||||
dao.Commit(db, txDB)
|
||||
globals.SugarLogger.Debugf("result : %v", utils.Format4Output(payHandler.WxPayParam, false))
|
||||
return payHandler.WxPayParam, err
|
||||
|
||||
@@ -34,28 +34,71 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func (p *PayHandler) CreatePay(txDB orm.TxOrmer) (err error) {
|
||||
func (p *PayHandler) CreatePay(txDB orm.TxOrmer, subAppID string) (err error) {
|
||||
switch p.PayType {
|
||||
case model.PayTypeTL:
|
||||
param := &tonglianpayapi.CreateUnitorderOrderParam{
|
||||
Trxamt: int(p.Order.PayPrice),
|
||||
Trxamt: p.Order.PayPrice,
|
||||
NotifyUrl: globals.TLPayNotifyURL,
|
||||
Reqsn: p.Order.OrderID,
|
||||
PayType: p.VendorPayType,
|
||||
}
|
||||
//暂时做兼容处理
|
||||
if p.VendorPayType == "JSAPI" {
|
||||
param.PayType = tonglianpayapi.PayTypeWxXcx
|
||||
}
|
||||
if p.VendorPayType == tonglianpayapi.PayTypeWxXcx {
|
||||
if authInfo, err := p.Ctx.GetV2AuthInfo(); err == nil && authInfo.GetAuthType() == weixin.AuthTypeWxApp {
|
||||
param.SubAppID = subAppID
|
||||
authInfo, err := p.Ctx.GetV2AuthInfo()
|
||||
// 微信小程序支付
|
||||
if err == nil && authInfo.GetAuthType() == weixin.AuthTypeMini && authInfo.GetAuthTypeID() == subAppID {
|
||||
param.Acct = authInfo.GetAuthID()
|
||||
}
|
||||
}
|
||||
result, err := api.TLpayAPI.CreateUnitorderOrder(param)
|
||||
if err == nil {
|
||||
var result2 tonglianpayapi.PayInfo
|
||||
json.Unmarshal([]byte(result.PayInfo), &result2)
|
||||
p.Order.PrepayID = result2.Package[strings.LastIndex(result2.Package, "=")+1 : len(result2.Package)]
|
||||
p.Order.TransactionID = result.TrxID
|
||||
_, err = dao.UpdateEntityTx(txDB, p.Order, "PrepayID", "TransactionID")
|
||||
if p.VendorPayType == tonglianpayapi.PayTypeZfbJS || p.VendorPayType == tonglianpayapi.PayTypeZfbApp {
|
||||
if authInfo, err := p.Ctx.GetV2AuthInfo(); err == nil {
|
||||
param.Acct = authInfo.GetAuthID()
|
||||
}
|
||||
if param.Acct == "" {
|
||||
return fmt.Errorf("未找到用户的认证ID!")
|
||||
}
|
||||
}
|
||||
if p.VendorPayType == tonglianpayapi.PayTypeH5 {
|
||||
param2 := &tonglianpayapi.CreateH5UnitorderOrderParam{
|
||||
Trxamt: p.Order.PayPrice,
|
||||
NotifyUrl: globals.TLPayNotifyURL,
|
||||
Body: "冲天猴",
|
||||
Charset: "UTF-8",
|
||||
}
|
||||
err = api.TLpayAPI.CreateH5UnitorderOrder(param2)
|
||||
} else {
|
||||
result, err := api.TLpayAPI.CreateUnitorderOrder(param)
|
||||
if err == nil {
|
||||
var result2 tonglianpayapi.PayInfo
|
||||
json.Unmarshal([]byte(result.PayInfo), &result2)
|
||||
p.Order.PrepayID = result2.Package[strings.LastIndex(result2.Package, "=")+1 : len(result2.Package)]
|
||||
p.Order.TransactionID = result.TrxID
|
||||
_, err = dao.UpdateEntityTx(txDB, p.Order, "PrepayID", "TransactionID")
|
||||
}
|
||||
//var result2 tonglianpayapi.PayInfo
|
||||
//json.Unmarshal([]byte(result.PayInfo), &result2)
|
||||
//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),
|
||||
//}
|
||||
}
|
||||
|
||||
// 暂时不支持微信直接支付
|
||||
case model.PayTypeWX:
|
||||
param := &wxpayapi.CreateOrderParam{
|
||||
OutTradeNo: p.Order.OrderID,
|
||||
@@ -213,16 +256,24 @@ func onTLpayFinished(call *tonglianpayapi.CallBackResult) (err error) {
|
||||
loc, _ := time.LoadLocation("Local")
|
||||
t1, _ := time.ParseInLocation("20060102150405", call.PayTime, loc)
|
||||
order.PayFinishedAt = t1
|
||||
// order.TransactionID = call.ChnlTrxID
|
||||
order.OriginalData = utils.Format4Output(call, true)
|
||||
if call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
||||
order.Status = model.OrderStatusFinished
|
||||
} else {
|
||||
order.Status = model.OrderStatusCanceled
|
||||
}
|
||||
dao.UpdateEntity(db, order)
|
||||
|
||||
if _, err := dao.UpdateEntity(db, order); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
||||
err = OnPayFinished(order)
|
||||
switch order.OrderType {
|
||||
case model.PayType4Express:
|
||||
|
||||
case model.PayType4Member, model.PayType4Recharge:
|
||||
err = OnPayFinished(order)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
globals.SugarLogger.Debugf("onTLpayFinished msg:%s, err:%v", utils.Format4Output(call, true), err)
|
||||
|
||||
@@ -36,9 +36,7 @@ type PayHandlerInterface interface {
|
||||
}
|
||||
|
||||
func OnPayFinished(order *model.Order) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
var db = dao.GetDB()
|
||||
globals.SugarLogger.Debugf("OnPayFinished begin modify account order: %v", utils.Format4Output(order, false))
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
|
||||
Reference in New Issue
Block a user