Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

131 lignes
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. 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:"wechat_hitxy_id,omitempty"`
  36. Verifier []string `json:"verifier,omitempty"`
  37. OpportunityAmountCurrency string `json:"opportunityAmountCurrency,omitempty"`
  38. OpportunityAmountConverted int `json:"opportunityAmountConverted,omitempty"`
  39. EmailAddressData []struct {
  40. EmailAddress string `json:"emailAddress,omitempty"`
  41. Lower string `json:"lower,omitempty"`
  42. Primary bool `json:"primary,omitempty"`
  43. OptOut bool `json:"optOut,omitempty"`
  44. Invalid bool `json:"invalid,omitempty"`
  45. } `json:"emailAddressData,omitempty"`
  46. PhoneNumberData []struct {
  47. PhoneNumber string `json:"phoneNumber,omitempty"`
  48. Primary bool `json:"primary,omitempty"`
  49. Type string `json:"type,omitempty"`
  50. } `json:"phoneNumberData,omitempty"`
  51. //CreatedByID string `json:"createdById,omitempty"`
  52. //CreatedByName string `json:"createdByName,omitempty"`
  53. //ModifiedByID string `json:"modifiedById,omitempty"`
  54. //ModifiedByName string `json:"modifiedByName,omitempty"`
  55. //AssignedUserID string `json:"assignedUserId,omitempty"`
  56. //AssignedUserName string `json:"assignedUserName,omitempty"`
  57. CampaignID string `json:"campaignId,omitempty"`
  58. CreatedAccountID string `json:"createdAccountId,omitempty"`
  59. CreatedContactID string `json:"createdContactId,omitempty"`
  60. CreatedOpportunityID string `json:"createdOpportunityId,omitempty"`
  61. ForceDuplicate bool `json:"forceDuplicate,omitempty"` //when purposely creating duplicated record, we need to set this to true
  62. }
  63. type crmdSearchLead struct {
  64. Total int `json:"total"`
  65. List []crmdLead `json:"list"`
  66. }
  67. func crmFindLeadByOpenID(openID string) (info crmdLead, found bool, err error) {
  68. total, list, err := crmFindEntityByAttr("Lead", "wechat_hitxy_id", openID)
  69. if err != nil {
  70. return
  71. }
  72. if total == 1 {
  73. found = true
  74. info = list.([]crmdLead)[0]
  75. return
  76. }
  77. found = false
  78. if total > 1 {
  79. msg := fmt.Sprintf("wechat_hitxy_id %s has %d record", openID, total)
  80. log.Printf(msg)
  81. }
  82. return
  83. }
  84. func crmGetLead(id string) (r crmdLead, err error) {
  85. entity, err := crmGetEntity("Lead", id)
  86. r = entity.(crmdLead)
  87. return
  88. }
  89. func crmPatchLeadInfo(newInfo crmdLead) (updatedLead crmdLead, err error) {
  90. b, err := json.Marshal(newInfo)
  91. if err != nil {
  92. log.Printf("Failed to Patch new Info for Lead")
  93. log.Println(newInfo)
  94. return
  95. }
  96. newEntity, err := crmUpdateEntity("Lead", newInfo.ID, b)
  97. if err != nil {
  98. return
  99. }
  100. updatedLead, ok := newEntity.(crmdLead)
  101. if !ok {
  102. err = errors.New("Update Lead result in wrong entityType")
  103. }
  104. return
  105. }
  106. func crmLeadSetStatusNew(id string) {
  107. crmLeadSetStatus(id, "New")
  108. }
  109. func crmLeadSetStatusDead(id string) {
  110. crmLeadSetStatus(id, "Dead")
  111. }
  112. func crmLeadSetStatus(id string, status string) {
  113. newLead := crmdLead{}
  114. newLead.ID = id
  115. newLead.Status = status
  116. crmPatchLeadInfo(newLead)
  117. }