You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
4.5KB

  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "time"
  6. )
  7. type crmdLead struct {
  8. ID string `json:"id,omitempty"`
  9. Name string `json:"name,omitempty"`
  10. Deleted bool `json:"deleted,omitempty"`
  11. SalutationName string `json:"salutationName,omitempty"`
  12. FirstName string `json:"firstName,omitempty"`
  13. LastName string `json:"lastName,omitempty"`
  14. Title string `json:"title,omitempty"`
  15. Status string `json:"status,omitempty"`
  16. Source string `json:"source,omitempty"`
  17. Industry string `json:"industry,omitempty"`
  18. OpportunityAmount int `json:"opportunityAmount,omitempty"`
  19. Website string `json:"website,omitempty"`
  20. AddressStreet string `json:"addressStreet,omitempty"`
  21. AddressCity string `json:"addressCity,omitempty"`
  22. AddressState string `json:"addressState,omitempty"`
  23. AddressCountry string `json:"addressCountry,omitempty"`
  24. AddressPostalCode string `json:"addresPostalCode,omitempty"`
  25. EmailAddress string `json:"emailAddress,omitempty"`
  26. PhoneNumber string `json:"phoneNumber,omitempty"`
  27. DoNotCall bool `json:"doNotCall,omitempty"`
  28. Description string `json:"description,omitempty"`
  29. CreatedAt string `json:"createdAt,omitempty"`
  30. ModifiedAt string `json:"ModifiedAt,omitempty"`
  31. AccountName string `json:"accountName,omitempty"`
  32. Password string `json:"password,omitempty"`
  33. WechatHitxyID string `json:"wechat_hitxy_id,omitempty"`
  34. Verifier []string `json:"verifier,omitempty"`
  35. OpportunityAmountCurrency string `json:"opportunityAmountCurrency,omitempty"`
  36. OpportunityAmountConverted int `json:"opportunityAmountConverted,omitempty"`
  37. EmailAddressData []struct {
  38. EmailAddress string `json:"emailAddress,omitempty"`
  39. Lower string `json:"lower,omitempty"`
  40. Primary bool `json:"primary,omitempty"`
  41. OptOut bool `json:"optOut,omitempty"`
  42. Invalid bool `json:"invalid,omitempty"`
  43. } `json:"emailAddressData,omitempty"`
  44. PhoneNumberData []struct {
  45. PhoneNumber string `json:"phoneNumber,omitempty"`
  46. Primary bool `json:"primary,omitempty"`
  47. Type string `json:"type,omitempty"`
  48. } `json:"phoneNumberData,omitempty"`
  49. CreatedByID string `json:"createdById,omitempty"`
  50. CreatedByName string `json:"createdByName,omitempty"`
  51. ModifiedByID string `json:"modifiedById,omitempty"`
  52. ModifiedByName string `json:"modifiedByName,omitempty"`
  53. AssignedUserID string `json:"assignedUserId,omitempty"`
  54. AssignedUserName string `json:"assignedUserName,omitempty"`
  55. CampaignID string `json:"campaignId,omitempty"`
  56. CreatedAccountID string `json:"createdAccountId,omitempty"`
  57. CreatedContactID string `json:"createdContactId,omitempty"`
  58. CreatedOpportunityID string `json:"createdOpportunityId,omitempty"`
  59. ForceDuplicate bool `json:"forceDuplicate,omitempty"` //when purposely creating duplicated record, we need to set this to true
  60. }
  61. type crmdSearchLead struct {
  62. Total int `json:"total"`
  63. List []crmdLead `json:"list"`
  64. }
  65. func (m *crmdLead) getCreatedAt() (r time.Time) {
  66. layout := m.getTimeLayout()
  67. r, _ = time.Parse(layout, m.CreatedAt)
  68. return
  69. }
  70. func (m *crmdLead) setCreatedAt(v time.Time) string {
  71. layout := m.getTimeLayout()
  72. m.CreatedAt = v.Format(layout)
  73. return m.CreatedAt
  74. }
  75. func (m *crmdLead) getModifiedAt() (r time.Time) {
  76. layout := m.getTimeLayout()
  77. r, _ = time.Parse(layout, m.ModifiedAt)
  78. return
  79. }
  80. func (m *crmdLead) setModifiedAt(v time.Time) string {
  81. layout := m.getTimeLayout()
  82. m.ModifiedAt = v.Format(layout)
  83. return m.ModifiedAt
  84. }
  85. func (m *crmdLead) getTimeLayout() string {
  86. return "2006-01-02 15:04:05"
  87. }
  88. func crmFindOpenID(openID string) (info crmdLead, found bool, err error) {
  89. total, list, err := crmFindEntityByAttr("Lead", "wechat_hitxy_id", openID)
  90. if err != nil {
  91. return
  92. }
  93. if total == 1 {
  94. found = true
  95. info = list.([]crmdLead)[0]
  96. return
  97. }
  98. found = false
  99. if total > 1 {
  100. msg := fmt.Sprintf("wechat_hitxy_id %s has %d record", openID, total)
  101. log.Printf(msg)
  102. }
  103. return
  104. }
  105. func crmGetLead(id string) (r crmdLead, err error) {
  106. entity, err := crmGetEntity("Lead", id)
  107. r = entity.(crmdLead)
  108. return
  109. }