From 20cda2be44650e742ea7864ea7e53b6db13854bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Fri, 19 May 2023 18:26:23 +0800 Subject: [PATCH] 1 --- business/auth2/authprovider/weixin/weixin.go | 13 +++++++++++++ business/partner/purchase/jx/localjx/order.go | 14 +++++++------- .../partner/purchase/jx/localjx/tonglianpay.go | 10 +++++++++- controllers/jx_order2.go | 3 ++- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/business/auth2/authprovider/weixin/weixin.go b/business/auth2/authprovider/weixin/weixin.go index d554b8726..1295f2341 100644 --- a/business/auth2/authprovider/weixin/weixin.go +++ b/business/auth2/authprovider/weixin/weixin.go @@ -122,3 +122,16 @@ func (a *Auther) getAPI() *weixinapi.API { func (a *Auther) GetUserType() (userType int8) { return model.UserTypeStoreBoss } + +func GetAPI(authType string) *weixinapi.API { + if authType == AuthTypeWeixin { + return api.WeixinPageAPI + } + if authType == AuthTypeWxApp { + return api.WeixinApp + } + if authType == AuthTypeWxAppCaishi { + return api.WeixinApp2 + } + return api.WeixinAPI +} diff --git a/business/partner/purchase/jx/localjx/order.go b/business/partner/purchase/jx/localjx/order.go index 475c1d10b..4cc2b2d39 100644 --- a/business/partner/purchase/jx/localjx/order.go +++ b/business/partner/purchase/jx/localjx/order.go @@ -324,7 +324,7 @@ func Pay4Order(ctx *jxcontext.Context, orderID int64, payType int, vendorPayType //if subAppID == tiktok.TiktokAppId || subAppID == tiktok.TiktokJXDJAppID { // subAppID = model.JXC4AppId // 京西商城 //} - if orderPay, err = pay4OrderByTL(ctx, order, payType, vendorPayType, subAppID); err == nil && orderPay != nil { + if orderPay, err = pay4OrderByTL(ctx, order, payType, vendorPayType, subAppID, ""); err == nil && orderPay != nil { dao.WrapAddIDCULDEntity(orderPay, ctx.GetUserName()) err = dao.CreateEntity(dao.GetDB(), orderPay) } @@ -351,7 +351,7 @@ func Pay4Order(ctx *jxcontext.Context, orderID int64, payType int, vendorPayType ActualPayPrice: priceDefendOrders[0].ActualPayPrice, VendorID: model.VendorIDJX, } - if orderPay, err = pay4OrderByTL(ctx, order2, payType, vendorPayType, subAppID); err == nil && orderPay != nil { + if orderPay, err = pay4OrderByTL(ctx, order2, payType, vendorPayType, subAppID, ""); err == nil && orderPay != nil { dao.WrapAddIDCULDEntity(orderPay, ctx.GetUserName()) err = dao.CreateEntity(dao.GetDB(), orderPay) } @@ -359,7 +359,7 @@ func Pay4Order(ctx *jxcontext.Context, orderID int64, payType int, vendorPayType return orderPay, err } -func Pay4User(ctx *jxcontext.Context, thingID int, vendorOrderID string, payType int, vendorPayType, subAppID string) (orderPay *model.OrderPay, err error) { +func Pay4User(ctx *jxcontext.Context, thingID int, vendorOrderID string, payType int, vendorPayType, subAppID, code string) (orderPay *model.OrderPay, err error) { var ( db = dao.GetDB() order *model.GoodsOrder @@ -383,7 +383,7 @@ func Pay4User(ctx *jxcontext.Context, thingID int, vendorOrderID string, payType ActualPayPrice: int64(discountCard.Price), VendorID: model.VendorIDJX, } - if orderPay, err = pay4OrderByTL(ctx, order, payType, vendorPayType, subAppID); err == nil && orderPay != nil { + if orderPay, err = pay4OrderByTL(ctx, order, payType, vendorPayType, subAppID, code); err == nil && orderPay != nil { dao.WrapAddIDCULDEntity(orderPay, ctx.GetUserName()) err = dao.CreateEntity(dao.GetDB(), orderPay) } @@ -416,7 +416,7 @@ func Pay4User(ctx *jxcontext.Context, thingID int, vendorOrderID string, payType ActualPayPrice: int64(storeOrder.ActualPayPrice), VendorID: model.VendorIDJX, } - if orderPay, err = pay4OrderByTL(ctx, order, payType, vendorPayType, subAppID); err == nil && orderPay != nil { + if orderPay, err = pay4OrderByTL(ctx, order, payType, vendorPayType, subAppID, code); err == nil && orderPay != nil { dao.WrapAddIDCULDEntity(orderPay, ctx.GetUserName()) err = dao.CreateEntity(dao.GetDB(), orderPay) } @@ -431,7 +431,7 @@ func Pay4User(ctx *jxcontext.Context, thingID int, vendorOrderID string, payType ActualPayPrice: int64(brandOrder.ActualPayPrice), VendorID: model.VendorIDJX, } - if orderPay, err = pay4OrderByTL(ctx, order, payType, vendorPayType, subAppID); err == nil && orderPay != nil { + if orderPay, err = pay4OrderByTL(ctx, order, payType, vendorPayType, subAppID, code); err == nil && orderPay != nil { dao.WrapAddIDCULDEntity(orderPay, ctx.GetUserName()) err = dao.CreateEntity(dao.GetDB(), orderPay) } @@ -841,7 +841,7 @@ func generateOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, addressID int64 if jxOrder.OrderType != model.OrderTypeMatter || (jxOrder.OrderType == model.OrderTypeMatter && fromStoreID == -1) { outJxOrder.Skus = append(outJxOrder.Skus, jxSku) outJxOrder.OrderPrice += int64(jxSku.Count) * jxSku.SalePrice - } else { //以下else为物料订单袋子金额和数量处理 + } else { //以下else为物料订单袋子金额和数量处理 if !result.Flag { //只要flag是false就按原价申请,是true再按订单量 outJxOrder.Skus = append(outJxOrder.Skus, jxSku) outJxOrder.OrderPrice += int64(jxSku.Count) * jxSku.SalePrice diff --git a/business/partner/purchase/jx/localjx/tonglianpay.go b/business/partner/purchase/jx/localjx/tonglianpay.go index 3e69fe493..ba1896650 100644 --- a/business/partner/purchase/jx/localjx/tonglianpay.go +++ b/business/partner/purchase/jx/localjx/tonglianpay.go @@ -19,7 +19,7 @@ import ( "git.rosy.net.cn/jx-callback/globals/api" ) -func pay4OrderByTL(ctx *jxcontext.Context, order *model.GoodsOrder, payType int, vendorPayType, subAppID string) (orderPay *model.OrderPay, err error) { +func pay4OrderByTL(ctx *jxcontext.Context, order *model.GoodsOrder, payType int, vendorPayType, subAppID, code string) (orderPay *model.OrderPay, err error) { // if order.FromStoreID != 0 { // result, _ := orderman.GetMatterStoreOrderCount(nil, order.FromStoreID) // if !result.Flag { @@ -45,6 +45,14 @@ func pay4OrderByTL(ctx *jxcontext.Context, order *model.GoodsOrder, payType int, if err == nil && authInfo.GetAuthType() == weixin.AuthTypeMini && authInfo.GetAuthTypeID() == subAppID { param.Acct = authInfo.GetAuthID() } + if code != "" { + appAuth := strings.Split(code, "_") + sessionInfo, err := weixin.GetAPI(appAuth[0]).SNSCode2Session(appAuth[1]) + if err != nil { + return nil, err + } + param.Acct = sessionInfo.OpenID + } } if vendorPayType == tonglianpayapi.PayTypeZfbJS || vendorPayType == tonglianpayapi.PayTypeZfbApp { if authInfo, err := ctx.GetV2AuthInfo(); err == nil { diff --git a/controllers/jx_order2.go b/controllers/jx_order2.go index b8f1220c1..b3a6c9c7e 100644 --- a/controllers/jx_order2.go +++ b/controllers/jx_order2.go @@ -123,12 +123,13 @@ func (c *JxOrderController) Pay4StoreMyselfDeliverOrder() { // @Param vendorOrderID formData string false "订单ID" // @Param payType formData int true "支付类型" // @Param vendorPayType formData string true "平台支付类型" +// @Param code formData string false "app吊起微信支付时,需要code获取openID" // @Success 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult // @router /Pay4User [post] func (c *JxOrderController) Pay4User() { c.callPay4User(func(params *tJxorderPay4UserParams) (retVal interface{}, errCode string, err error) { - retVal, err = localjx.Pay4User(params.Ctx, params.ThingID, params.VendorOrderID, params.PayType, params.VendorPayType, params.SubAppID) + retVal, err = localjx.Pay4User(params.Ctx, params.ThingID, params.VendorOrderID, params.PayType, params.VendorPayType, params.SubAppID, params.Code) return retVal, "", err }) }