add check

This commit is contained in:
lwl0608 2023-12-29 21:30:59 +08:00
parent 1277bbafc9
commit 5d8fda536a
5 changed files with 58 additions and 1 deletions

View File

@ -44,3 +44,13 @@ func (p *BaseRequest) GetBaseRequest() BaseRequest {
}
return BaseRequest{}
}
func (p *BaseRequest) IsValid() bool {
if p.Mid <= 0 {
return false
}
if len(p.Did) <= 0 {
return false
}
return true
}

View File

@ -13,6 +13,7 @@ var ErrCodeMsgMap = map[ErrCode]string{
ErrCodeSelfOnlyOperation: "权限不足:该操作仅可对当前登录用户执行",
ErrCodeRolePrivilegesNotEnough: "权限不足:当前用户角色禁止执行该操作",
ErrCodeOpRoleOnlyOperation: "权限不足: 后台系统仅允许超级管理员和运营操作",
ErrCodeBadParam: "参数错误",
ErrCodeProductSrvFail: "商品服务错误",
ErrCodeProductNotExist: "商品不存在",
@ -139,6 +140,7 @@ const (
ErrCodeSelfOnlyOperation ErrCode = -20 // 权限不足:该操作仅可对当前登录用户执行
ErrCodeRolePrivilegesNotEnough ErrCode = -21 // 权限不足: 当前用户角色禁止执行该操作
ErrCodeOpRoleOnlyOperation ErrCode = -22 // 权限不足: 后台系统仅允许超级管理员和运营操作
ErrCodeBadParam ErrCode = -30 // 参数错误
// Product: 1xxx
ErrCodeProductSrvOk ErrCode = ErrCodeOk

View File

@ -173,7 +173,7 @@ func Init(r *gin.Engine) {
// 支付相关
vasPayGroup := r.Group("/api/vas", PrepareToC())
vasPayGroup.POST("get_coins_product_list", middleware.JSONParamValidator(vasproto.GetCoinsProductListReq{}), GetCoinsProductList)
vasPayGroup.POST("create_order", middleware.JSONParamValidator(vasproto.CreateOrderReq{}), CreateOrder)
vasPayGroup.POST("create_order", middleware.JSONParamValidator(vasproto.CreateOrderReq{}), middleware.JwtAuthenticator(), CreateOrder)
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)
@ -190,6 +190,7 @@ func Init(r *gin.Engine) {
opVasPayGroup := r.Group("/op/vas", PrepareOp())
opVasPayGroup.POST("create_order", middleware.JSONParamValidator(vasproto.OpCreateOrderReq{}), OpCreateOrder)
opVasPayGroup.POST("order_list")
// 验证码
opVeriCodeGroup := r.Group("/op/veri_code", PrepareOp())

View File

@ -27,7 +27,13 @@ func GetCoinsProductList(ctx *gin.Context) {
// 充值 创建订单
func CreateOrder(ctx *gin.Context) {
defer logger.Recover()
req := ctx.MustGet("client_req").(*vasproto.CreateOrderReq)
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
}
data, ec := service.DefaultService.CreateOrder(ctx, req)
if ec != errcode.ErrCodeVasSrvOk {
logger.Error("CreateOrder fail, req: %v, ec: %v", util.ToJson(req), ec)
@ -59,6 +65,11 @@ func OpCreateOrder(ctx *gin.Context) {
func OneStepUnlock(ctx *gin.Context) {
defer logger.Recover()
req := ctx.MustGet("client_req").(*vasproto.OneStepUnlockContactReq)
if !req.IsValid() || req.Uid <= 0 || len(req.ContactProductId) <= 0 {
logger.Error("OneStepUnlock, invalid param, req: %v", util.ToJson(req))
ReplyErrCodeMsg(ctx, errcode.ErrCodeBadParam)
return
}
data, ec := service.DefaultService.OneStepUnlockContact(ctx, req)
if ec != errcode.ErrCodeVasSrvOk {
logger.Error("GetAddWechatList fail, req: %v, ec: %v", util.ToJson(req), ec)
@ -70,7 +81,13 @@ func OneStepUnlock(ctx *gin.Context) {
// 填写地址
func ConsumerFillContact(ctx *gin.Context) {
defer logger.Recover()
req := ctx.MustGet("client_req").(*vasproto.ConsumerFillContactReq)
if !req.IsValid() || len(req.OrderId) <= 0 {
logger.Error("ConsumerFillContact, invalid param, req: %v", util.ToJson(req))
ReplyErrCodeMsg(ctx, errcode.ErrCodeBadParam)
return
}
ec := service.DefaultService.ConsumerFillContact(ctx, req)
if ec != errcode.ErrCodeVasSrvOk {
logger.Error("ConsumerFillContact fail, req: %v, ec: %v", util.ToJson(req), ec)
@ -82,7 +99,13 @@ func ConsumerFillContact(ctx *gin.Context) {
// 待添加微信列表
func GetAddWechatList(ctx *gin.Context) {
defer logger.Recover()
req := ctx.MustGet("client_req").(*vasproto.GetAddWechatListReq)
if !req.IsValid() {
logger.Error("GetAddWechatList, invalid param, req: %v", util.ToJson(req))
ReplyErrCodeMsg(ctx, errcode.ErrCodeBadParam)
return
}
data, ec := service.DefaultService.GetAddWechatList(ctx, req)
if ec != errcode.ErrCodeVasSrvOk {
logger.Error("GetAddWechatList fail, req: %v, ec: %v", util.ToJson(req), ec)
@ -94,7 +117,13 @@ func GetAddWechatList(ctx *gin.Context) {
// 完成添加微信
func ConfirmAddWechat(ctx *gin.Context) {
defer logger.Recover()
req := ctx.MustGet("client_req").(*vasproto.ConfirmAddWechatReq)
if !req.IsValid() {
logger.Error("ConfirmAddWechat, invalid param, req: %v", util.ToJson(req))
ReplyErrCodeMsg(ctx, errcode.ErrCodeBadParam)
return
}
data, ec := service.DefaultService.ConfirmAddWechat(ctx, req)
if ec != errcode.ErrCodeVasSrvOk {
logger.Error("ConfirmAddWechat fail, req: %v, ec: %v", util.ToJson(req), ec)
@ -106,7 +135,13 @@ func ConfirmAddWechat(ctx *gin.Context) {
// 已解锁微信列表
func GetUnlockWechatList(ctx *gin.Context) {
defer logger.Recover()
req := ctx.MustGet("client_req").(*vasproto.GetUnlockWechatListReq)
if !req.IsValid() {
logger.Error("GetUnlockWechatList, invalid param, req: %v", util.ToJson(req))
ReplyErrCodeMsg(ctx, errcode.ErrCodeBadParam)
return
}
data, ec := service.DefaultService.GetUnlockWechatList(ctx, req)
if ec != errcode.ErrCodeVasSrvOk {
logger.Error("GetUnlockWechatList fail, req: %v, ec: %v", util.ToJson(req), ec)
@ -118,7 +153,13 @@ func GetUnlockWechatList(ctx *gin.Context) {
// 明细
func GetCHList(ctx *gin.Context) {
defer logger.Recover()
req := ctx.MustGet("client_req").(*vasproto.GetCHListReq)
if !req.IsValid() {
logger.Error("GetCHList, invalid param, req: %v", util.ToJson(req))
ReplyErrCodeMsg(ctx, errcode.ErrCodeBadParam)
return
}
data, ec := service.DefaultService.GetCHList(ctx, req)
if ec != errcode.ErrCodeVasSrvOk {
logger.Error("GetCHList fail, req: %v, ec: %v", util.ToJson(req), ec)

View File

@ -1373,6 +1373,9 @@ func (v *Vas) H5DirectUnlockWechat(ctx *gin.Context, req *vasproto.H5DirectUnloc
logger.Error("OneStepUnlockContact fail, req: %v, err: %v", util.ToJson(req), err)
return
}
data = &vasproto.H5DirectUnlockWechatData{
CoinEnough: 1,
}
return
}