get_api_user_vip_logic.go 1.2 KB

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