create_contact_logic.go 1.7 KB

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