diff --git a/api/proto/vas/proto/op.go b/api/proto/vas/proto/op.go index 9c8cda35..9d7cb8f1 100644 --- a/api/proto/vas/proto/op.go +++ b/api/proto/vas/proto/op.go @@ -118,3 +118,9 @@ type OpOrderListData struct { //Offset int `json:"offset"` //More int `json:"more"` } + +type WxpayCallbackManualParam struct { + OrderId string `json:"order_id"` // 我们自己服务的订单id + OutOrderId string `json:"out_order_id"` // 外部订单id,比如支付宝、微信 + CallbackPayType string `json:"callback_pay_type"` // 支付类型 +} diff --git a/app/mix/controller/init.go b/app/mix/controller/init.go index 0b663ce7..7655f0e5 100644 --- a/app/mix/controller/init.go +++ b/app/mix/controller/init.go @@ -297,6 +297,7 @@ func Init(r *gin.Engine) { opVasPayGroup.POST("order_list", middleware.JSONParamValidator(vasproto.OpOrderListReq{}), OpOrderList) opVasPayGroup.POST("refund_order", middleware.JSONParamValidator(vasproto.RefundOrderReq{}), RefundOrder) opVasPayGroup.POST("refund_coin_order", middleware.JSONParamValidator(vasproto.RefundCoinOrderReq{}), RefundCoinOrder) + opVasPayGroup.POST("wxpay_callback_manual", middleware.JSONParamValidator(vasproto.WxpayCallbackManualParam{}), WxpayCallbackManual) // 验证码 opVeriCodeGroup := r.Group("/op/veri_code", PrepareOp()) diff --git a/app/mix/controller/wxpay_callback.go b/app/mix/controller/wxpay_callback.go index d39f3cb0..4e6fca8c 100644 --- a/app/mix/controller/wxpay_callback.go +++ b/app/mix/controller/wxpay_callback.go @@ -31,3 +31,13 @@ func WxpayCallback(ctx *gin.Context) { } ctx.String(200, "success") } + +func WxpayCallbackManual(ctx *gin.Context) { + req := ctx.MustGet("client_req").(*vasproto.WxpayCallbackManualParam) + service.DefaultService.PayCallback(ctx, &vasproto.PayCallbackParamIn{ + OrderId: req.OrderId, + OutOrderId: req.OutOrderId, + CallbackPayType: vasproto.CallBackPayTypeWxpay, + }) + ctx.String(200, "success") +} diff --git a/app/mix/service/logic/vas.go b/app/mix/service/logic/vas.go index 23865c4d..b1385e3b 100644 --- a/app/mix/service/logic/vas.go +++ b/app/mix/service/logic/vas.go @@ -1257,7 +1257,6 @@ func (v *Vas) PayCallback(ctx *gin.Context, p *vasproto.PayCallbackParamIn) { switch product.Id { case dbstruct.ProductIdMembership: ch.SType = goproto.Int32(dbstruct.CHSTypeChargeMembership) - ch.Change = goproto.Int64(order.GetPayAmount()) case dbstruct.ProductIdH5ZoneMoment: ch.SType = goproto.Int32(dbstruct.CHSTypeChargeZoneMoment) ch.Change = goproto.Int64(order.GetPayAmount()) @@ -1313,7 +1312,7 @@ func (v *Vas) PayCallback(ctx *gin.Context, p *vasproto.PayCallbackParamIn) { } case product.Id == dbstruct.ProductIdMembership: // 解锁会员资格 - _, err = v.UnlockMembership(ctx, util.DerefInt64(order.Mid), product, order, wallet) + _, err = v.UnlockMembership(ctx, tx, util.DerefInt64(order.Mid), product, order, wallet) if err != nil { logger.Error("UnlockMembership fail, order: %v, err: %v", util.ToJson(order), err) return @@ -1851,7 +1850,7 @@ func (v *Vas) dealOneMembershipOrder(ctx *gin.Context, tx *sqlx.Tx, order *dbstr } // 解锁会员资格 -func (v *Vas) UnlockMembership(ctx *gin.Context, mid int64, product *dbstruct.Product, order *dbstruct.Order, wallet *dbstruct.Wallet) (orderId string, err error) { +func (v *Vas) UnlockMembership(ctx *gin.Context, tx *sqlx.Tx, mid int64, product *dbstruct.Product, order *dbstruct.Order, wallet *dbstruct.Wallet) (orderId string, err error) { var ( did = util.DerefString(order.Did) productId = product.Id @@ -1867,20 +1866,6 @@ func (v *Vas) UnlockMembership(ctx *gin.Context, mid int64, product *dbstruct.Pr return } - // 开启事务 - tx, err := v.store.VasBegin(ctx) - if err != nil { - logger.Error("vas begin fail, err: %v", err) - return - } - defer func() { - errTx := v.store.DealTxCR(tx, err) - if errTx != nil { - logger.Error("DealTxCR fail, err: %v", errTx) - return - } - }() - // 增加金币消费历史(伪记录,仅为对账平插入一条消费流水) ch := &dbstruct.ConsumeHistory{ Mid: goproto.Int64(mid), @@ -1934,8 +1919,15 @@ func (v *Vas) UnlockMembership(ctx *gin.Context, mid int64, product *dbstruct.Pr return } + // 获取空间id + zid := int64(0) + zone, _ := v.zone.GetByMid(ctx, order.GetUid()) + if zone != nil { + zid = zone.GetId() + } + // 增加空间消费 - _err := v.IncZoneConsume(ctx, tx, 0, mid, order.GetUid(), order.GetPayAmount(), orderId, order.GetProductId()) + _err := v.IncZoneConsume(ctx, tx, zid, mid, order.GetUid(), order.GetPayAmount(), orderId, order.GetProductId()) if _err != nil { logger.Error("IncZoneConsume fail, mid: %v, orderId: %v, err: %v", mid, orderId, err) }