Browse Source

fix:save 23

jimmyyem 5 months ago
parent
commit
6793fd71b3

+ 21 - 0
desc/wechat/user.api

@@ -104,6 +104,15 @@ type (
 		Nickname *string `json:"nickname,optional"`
 	    IsVip *bool `json:"isVip,optional"`
 	}
+
+	UserVipResp {
+		BaseDataInfo
+		Data UserVip `json:"data,optional"`
+	}
+
+	UserVip {
+		IsVip *bool `json:"isVip,optional"`
+	}
 )
 
 @server(
@@ -117,6 +126,18 @@ service Wechat {
 }
 
 @server(
+	jwt: Auth
+	group: User
+	middleware: Miniprogram
+)
+
+service Wechat {
+	// Get user vip information | 获取用户VIP信息
+	@handler getApiUserVip
+	post /api/user/vip () returns (UserVipResp)
+}
+
+@server(
     jwt: Auth
 	group: User
 	middleware: Authority

+ 31 - 0
internal/handler/User/get_api_user_vip_handler.go

@@ -0,0 +1,31 @@
+package User
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/User"
+	"wechat-api/internal/svc"
+)
+
+// swagger:route post /api/user/vip User GetApiUserVip
+//
+// Get user vip information | 获取用户VIP信息
+//
+// Get user vip information | 获取用户VIP信息
+//
+// Responses:
+//  200: UserVipResp
+
+func GetApiUserVipHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		l := User.NewGetApiUserVipLogic(r.Context(), svcCtx)
+		resp, err := l.GetApiUserVip()
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 14 - 0
internal/handler/routes.go

@@ -636,6 +636,20 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 
 	server.AddRoutes(
 		rest.WithMiddlewares(
+			[]rest.Middleware{serverCtx.Miniprogram},
+			[]rest.Route{
+				{
+					Method:  http.MethodPost,
+					Path:    "/api/user/vip",
+					Handler: User.GetApiUserVipHandler(serverCtx),
+				},
+			}...,
+		),
+		rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
+	)
+
+	server.AddRoutes(
+		rest.WithMiddlewares(
 			[]rest.Middleware{serverCtx.Authority},
 			[]rest.Route{
 				{

+ 51 - 0
internal/logic/User/get_api_user_vip_logic.go

@@ -0,0 +1,51 @@
+package User
+
+import (
+	"context"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"wechat-api/ent"
+	"wechat-api/ent/wxcarduser"
+	"wechat-api/internal/utils/dberrorhandler"
+
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type GetApiUserVipLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewGetApiUserVipLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetApiUserVipLogic {
+	return &GetApiUserVipLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *GetApiUserVipLogic) GetApiUserVip() (*types.UserVipResp, error) {
+	userId := l.ctx.Value("userId").(uint64)
+
+	userInfo, err := l.svcCtx.DB.WxCardUser.Query().Where(wxcarduser.ID(userId)).First(l.ctx)
+	if err != nil {
+		if ent.IsNotFound(err) {
+			return nil, dberrorhandler.DefaultEntError(l.Logger, err, nil)
+		}
+		return nil, dberrorhandler.DefaultEntError(l.Logger, err, nil)
+	}
+
+	isVip := userInfo.IsVip > 0
+
+	return &types.UserVipResp{
+		BaseDataInfo: types.BaseDataInfo{
+			Code: 0,
+			Msg:  errormsg.Success,
+		},
+		Data: types.UserVip{
+			IsVip: &isVip,
+		},
+	}, nil
+}

+ 10 - 0
internal/types/types.go

@@ -1610,6 +1610,16 @@ type UserToken struct {
 	IsVip    *bool   `json:"isVip,optional"`
 }
 
+// swagger:model UserVipResp
+type UserVipResp struct {
+	BaseDataInfo
+	Data UserVip `json:"data,optional"`
+}
+
+type UserVip struct {
+	IsVip *bool `json:"isVip,optional"`
+}
+
 // swagger:model WxidReq
 type WxidReq struct {
 	Wxid string `json:"wxid"`