No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

132 líneas
4.4KB

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