diff --git a/app/mix/controller/init.go b/app/mix/controller/init.go index 4f222cbf..78f99063 100644 --- a/app/mix/controller/init.go +++ b/app/mix/controller/init.go @@ -71,6 +71,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{}), middleware.JwtAuthenticator(), OneStepUnlock) vasPayGroup.POST("consumer_fill_contact", middleware.JSONParamValidator(vasproto.ConsumerFillContactReq{}), middleware.JwtAuthenticator(), ConsumerFillContact) vasPayGroup.POST("get_add_wechat_list", middleware.JSONParamValidator(vasproto.GetAddWechatListReq{}), middleware.JwtAuthenticator(), 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]