get_api_user_vip_logic.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package User
  2. import (
  3. "context"
  4. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  5. "wechat-api/ent"
  6. "wechat-api/ent/wxcarduser"
  7. "wechat-api/internal/utils/dberrorhandler"
  8. "wechat-api/internal/svc"
  9. "wechat-api/internal/types"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. )
  12. type GetApiUserVipLogic struct {
  13. logx.Logger
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. }
  17. func NewGetApiUserVipLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetApiUserVipLogic {
  18. return &GetApiUserVipLogic{
  19. Logger: logx.WithContext(ctx),
  20. ctx: ctx,
  21. svcCtx: svcCtx}
  22. }
  23. func (l *GetApiUserVipLogic) GetApiUserVip() (*types.UserVipResp, error) {
  24. userId := l.ctx.Value("userId").(uint64)
  25. userInfo, err := l.svcCtx.DB.WxCardUser.Query().Where(wxcarduser.ID(userId)).First(l.ctx)
  26. if err != nil {
  27. if ent.IsNotFound(err) {
  28. return nil, dberrorhandler.DefaultEntError(l.Logger, err, nil)
  29. }
  30. return nil, dberrorhandler.DefaultEntError(l.Logger, err, nil)
  31. }
  32. isVip := userInfo.IsVip > 0
  33. return &types.UserVipResp{
  34. BaseDataInfo: types.BaseDataInfo{
  35. Code: 0,
  36. Msg: errormsg.Success,
  37. },
  38. Data: types.UserVip{
  39. IsVip: &isVip,
  40. },
  41. }, nil
  42. }