From 0e3e21cd86cc440fe464e744224e3ded802f7672 Mon Sep 17 00:00:00 2001 From: lwl0608 Date: Sat, 15 Jun 2024 14:33:15 +0800 Subject: [PATCH] create_order_wx_pub --- app/mix/controller/init.go | 1 + app/mix/controller/vas.go | 48 +++++++++++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/app/mix/controller/init.go b/app/mix/controller/init.go index 2e84d4f9..2d76e046 100644 --- a/app/mix/controller/init.go +++ b/app/mix/controller/init.go @@ -274,6 +274,7 @@ func Init(r *gin.Engine) { vasPayGroup.POST("get_coins_product_list", middleware.JSONParamValidator(vasproto.GetCoinsProductListReq{}), GetCoinsProductList) vasPayGroup.POST("get_membership_product_list", middleware.JSONParamValidator(vasproto.GetMembershipProductListReq{}), GetMembershipProductList) vasPayGroup.POST("create_order", middleware.JSONParamValidator(vasproto.CreateOrderReq{}), middleware.JwtAuthenticator(), CreateOrder) + vasPayGroup.POST("create_order_wx_pub", middleware.JSONParamValidator(vasproto.CreateOrderReq{}), CreateOrderWxPub) vasPayGroup.POST("one_step_unlock", middleware.JSONParamValidator(vasproto.OneStepUnlockContactReq{}), OneStepUnlock) vasPayGroup.POST("consumer_fill_contact", middleware.JSONParamValidator(vasproto.ConsumerFillContactReq{}), ConsumerFillContact) vasPayGroup.POST("get_add_wechat_list", middleware.JSONParamValidator(vasproto.GetAddWechatListReq{}), GetAddWechatList) diff --git a/app/mix/controller/vas.go b/app/mix/controller/vas.go index 92069cba..683a2286 100644 --- a/app/mix/controller/vas.go +++ b/app/mix/controller/vas.go @@ -46,19 +46,45 @@ func GetMembershipProductList(ctx *gin.Context) { // 充值 创建订单 func CreateOrder(ctx *gin.Context) { req := ctx.MustGet("client_req").(*vasproto.CreateOrderReq) - switch req.From { - case dbstruct.VasCoinOrderFromWxPub: - if req.Mid1 <= 0 || len(req.PayType) <= 0 || len(req.ProductId) <= 0 { - logger.Error("CreateOrder, invalid param, req: %v", util.ToJson(req)) - ReplyErrCodeMsg(ctx, errcode.ErrCodeBadParam) - return - } - default: - if !req.IsValid() || len(req.PayType) <= 0 || len(req.ProductId) <= 0 { - logger.Error("CreateOrder, invalid param, req: %v", util.ToJson(req)) - ReplyErrCodeMsg(ctx, errcode.ErrCodeBadParam) + if !req.IsValid() || len(req.PayType) <= 0 || len(req.ProductId) <= 0 { + logger.Error("CreateOrder, invalid param, req: %v", util.ToJson(req)) + ReplyErrCodeMsg(ctx, errcode.ErrCodeBadParam) + return + } + if len(req.Model) >= 28 { + req.Model = req.Model[:28] + } + + // 检查能用金币支付的商品 + if req.PayType == vasproto.PayTypeCoin && !dbstruct.CoinPayValidProductIdMap[req.ProductId] { + ReplyErrorMsg(ctx, "商品错误") + return + } + + data, ec, err := service.DefaultService.CreateOrder(ctx, req) + if ec != errcode.ErrCodeVasSrvOk { + logger.Error("CreateOrder fail, req: %v, ec: %v", util.ToJson(req), ec) + if ec == errcode.ErrCodeVasSrvFail && err != nil { + ReplyErrorMsg(ctx, err.Error()) return } + ReplyErrCodeMsg(ctx, ec) + return + } + ReplyOk(ctx, data) +} + +func CreateOrderWxPub(ctx *gin.Context) { + req := ctx.MustGet("client_req").(*vasproto.CreateOrderReq) + if req.From != dbstruct.VasCoinOrderFromWxPub { + logger.Error("CreateOrder, invalid param, req: %v", util.ToJson(req)) + ReplyErrCodeMsg(ctx, errcode.ErrCodeBadParam) + return + } + if req.Mid1 <= 0 || len(req.PayType) <= 0 || len(req.ProductId) <= 0 { + logger.Error("CreateOrder, invalid param, req: %v", util.ToJson(req)) + ReplyErrCodeMsg(ctx, errcode.ErrCodeBadParam) + return } if len(req.Model) >= 28 { req.Model = req.Model[:28]