123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- package wxcarduser
- import (
- "context"
- "github.com/suyuan32/simple-admin-common/msg/errormsg"
- "github.com/zeromicro/go-zero/core/errorx"
- "wechat-api/ent"
- "wechat-api/ent/wxcarduser"
- "wechat-api/internal/svc"
- "wechat-api/internal/types"
- "wechat-api/internal/utils/dberrorhandler"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type UpdateApiWxCardUserLogic struct {
- logx.Logger
- ctx context.Context
- svcCtx *svc.ServiceContext
- }
- func NewUpdateApiWxCardUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateApiWxCardUserLogic {
- return &UpdateApiWxCardUserLogic{
- Logger: logx.WithContext(ctx),
- ctx: ctx,
- svcCtx: svcCtx}
- }
- func (l *UpdateApiWxCardUserLogic) UpdateApiWxCardUser(req *types.WxCardUserInfo) (*types.BaseMsgResp, error) {
- userId := uint64(1) //l.ctx.Value("userId").(uint64)
- var nickname, avatar string
- if req.Nickname != nil && *req.Nickname != "" {
- nickname = *req.Nickname
- }
- if req.Avatar != nil && *req.Avatar != "" {
- avatar = *req.Avatar
- }
- if nickname == "" && avatar == "" {
- return nil, errorx.NewInvalidArgumentError("参数错误")
- }
- wxCardUser, err := l.svcCtx.DB.WxCardUser.Query().Where(wxcarduser.ID(userId)).Only(l.ctx)
- if err != nil && !ent.IsNotFound(err) {
- return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
- }
- if wxCardUser != nil {
- query := l.svcCtx.DB.WxCardUser.UpdateOneID(userId)
- if nickname != "" {
- query = query.SetNickname(nickname)
- }
- if avatar != "" {
- query = query.SetAvatar(avatar)
- }
- _, err = query.Save(l.ctx)
- if err != nil {
- return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
- }
- }
- return &types.BaseMsgResp{
- Code: 0,
- Msg: errormsg.Success,
- }, nil
- }
|