Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

130 lines
4.3KB

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