update_contact_logic.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package contact
  2. import (
  3. "context"
  4. "wechat-api/ent/contact"
  5. "wechat-api/internal/svc"
  6. "wechat-api/internal/types"
  7. "wechat-api/internal/utils/dberrorhandler"
  8. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. )
  11. type UpdateContactLogic struct {
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. logx.Logger
  15. }
  16. func NewUpdateContactLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateContactLogic {
  17. return &UpdateContactLogic{
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. Logger: logx.WithContext(ctx),
  21. }
  22. }
  23. func (l *UpdateContactLogic) UpdateContact(req *types.ContactInfo) (*types.BaseMsgResp, error) {
  24. organizationId := l.ctx.Value("organizationId").(uint64)
  25. cage := 0
  26. if req.Cage != nil && *req.Cage > 0 {
  27. cage = *req.Cage
  28. }
  29. err := l.svcCtx.DB.Contact.UpdateOneID(*req.Id).
  30. Where(contact.OrganizationID(organizationId)).
  31. SetNotNilStatus(req.Status).
  32. SetNotNilWxWxid(req.WxWxid).
  33. SetNotNilType(req.Type).
  34. SetNotNilWxid(req.Wxid).
  35. SetNotNilAccount(req.Account).
  36. SetNotNilNickname(req.Nickname).
  37. SetNotNilMarkname(req.Markname).
  38. SetNotNilHeadimg(req.Headimg).
  39. SetNotNilSex(req.Sex).
  40. SetNotNilStarrole(req.Starrole).
  41. SetNotNilDontseeit(req.Dontseeit).
  42. SetNotNilDontseeme(req.Dontseeme).
  43. SetNotNilLag(req.Lag).
  44. SetNotNilGid(req.Gid).
  45. SetNotNilGname(req.Gname).
  46. SetNotNilV3(req.V3).
  47. SetNotNilCname(req.Cname).
  48. SetNotNilCarea(req.Carea).
  49. SetNotNilCage(&cage).
  50. SetNotNilCbirthday(req.Cbirthday).
  51. SetNotNilCbirtharea(req.Cbirtharea).
  52. SetNotNilCc(req.Cc).
  53. SetNotNilPhone(req.Phone).
  54. SetNotNilCidcardNo(req.CidcardNo).
  55. SetNotNilCtitle(req.Ctitle).
  56. Exec(l.ctx)
  57. if err != nil {
  58. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  59. }
  60. return &types.BaseMsgResp{Msg: errormsg.UpdateSuccess}, nil
  61. }