activity.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. package yb
  2. import (
  3. "fmt"
  4. "hongze/hongze_open_api/models/tables/company"
  5. "hongze/hongze_open_api/models/tables/company_product"
  6. "hongze/hongze_open_api/models/tables/qs_event"
  7. "hongze/hongze_open_api/models/tables/qs_event_user"
  8. "hongze/hongze_open_api/models/tables/user_view_statistics"
  9. "hongze/hongze_open_api/models/tables/wx_user"
  10. "hongze/hongze_open_api/services/alarm_msg"
  11. "hongze/hongze_open_api/services/quanshi"
  12. "hongze/hongze_open_api/utils"
  13. "strings"
  14. "time"
  15. )
  16. // SyncUser 用户同步
  17. func SyncUser(qsEventId int) (err error) {
  18. errMsgList := make([]string, 0)
  19. defer func() {
  20. if err != nil {
  21. errMsgList = append(errMsgList, err.Error())
  22. }
  23. if len(errMsgList) > 0 {
  24. //for _, v := range errMsgList {
  25. // fmt.Println(v)
  26. //}
  27. go alarm_msg.SendAlarmMsg("同步全时会议参会人员数据失败:"+strings.Join(errMsgList, "/n"), 3)
  28. }
  29. }()
  30. qsEventInfo, err := qs_event.GetQsEventByQsEventId(qsEventId)
  31. if err != nil {
  32. return
  33. }
  34. //if qsEventInfo.IsSync == 1 {
  35. // return
  36. //}
  37. //获取全时的参会人员信息
  38. qsData, err := quanshi.QsEventReportSummary(qsEventId)
  39. if err != nil {
  40. fmt.Println(err)
  41. return
  42. }
  43. companyProductMap := make(map[string]*company_product.CompanyProduct)
  44. companyMap := make(map[string]*company.Company)
  45. people := 0 //参与人数
  46. productIdList := []int{1, 2} //ficc和权益
  47. companyIdProductIdMap := make(map[int]int) //客户与产品的id map
  48. if qsData.Summary != nil {
  49. for _, v := range qsData.Summary {
  50. if v.Mobile == "" { //如果手机号为空,那么就不处理了,进入下一个循环
  51. continue
  52. }
  53. tmpQsEventUser, tmpErr := qs_event_user.GetQsEventUserByQsId(qsEventInfo.QsId, v.Mobile)
  54. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  55. errMsgList = append(errMsgList, fmt.Sprintf("路演id:%d,用户手机号:%s,会议用户入库失败,err:%s", qsEventInfo.QsId, v.Mobile, err.Error()))
  56. continue
  57. }
  58. // 如果已经有数据了,那么不需要再处理了
  59. if tmpQsEventUser != nil {
  60. continue
  61. }
  62. people++
  63. mobile := v.Mobile
  64. trimMobile := mobile
  65. countryCode := "86"
  66. var companyProductInfo *company_product.CompanyProduct
  67. var companyInfo *company.Company
  68. var wxUserInfo *wx_user.WxUser
  69. if mobile != "" {
  70. trimMobileSlice := strings.Split(v.Mobile, "-")
  71. lenTrimMobileSlice := len(trimMobileSlice)
  72. if lenTrimMobileSlice > 1 {
  73. trimMobile = trimMobileSlice[1]
  74. countryCode = strings.Replace(trimMobileSlice[0], "+", "", -1)
  75. }
  76. wxUserInfo, _ = wx_user.GetWxUserByMobileCountryCode(trimMobile, countryCode)
  77. if wxUserInfo != nil && wxUserInfo.CompanyId != 1 {
  78. //获取客户产品信息
  79. productId, ok := companyIdProductIdMap[wxUserInfo.CompanyId]
  80. if ok { //已经查询过
  81. if productId > 0 {
  82. // 获取客户产品信息
  83. key := fmt.Sprint(wxUserInfo.CompanyId, "_", productId)
  84. if tmpCompanyProductInfo, ok := companyProductMap[key]; ok {
  85. companyProductInfo = tmpCompanyProductInfo
  86. }
  87. }
  88. } else {
  89. for _, productId := range productIdList {
  90. key := fmt.Sprint(wxUserInfo.CompanyId, "_", productId)
  91. companyProductInfo, _ = company_product.GetCompanyProductByCompanyIdAndProductId(wxUserInfo.CompanyId, productId)
  92. if companyProductInfo != nil {
  93. companyProductMap[key] = companyProductInfo
  94. companyIdProductIdMap[wxUserInfo.CompanyId] = productId
  95. //退出产品查询
  96. break
  97. }
  98. }
  99. if companyProductInfo == nil {
  100. companyIdProductIdMap[wxUserInfo.CompanyId] = 0
  101. }
  102. }
  103. // 获取客户信息
  104. key := fmt.Sprint(wxUserInfo.CompanyId)
  105. if tmpCompanyInfo, ok := companyMap[key]; ok {
  106. companyInfo = tmpCompanyInfo
  107. } else {
  108. companyInfo, _ = company.GetCompanyById(wxUserInfo.CompanyId)
  109. if companyInfo != nil {
  110. companyMap[key] = companyInfo
  111. }
  112. }
  113. }
  114. }
  115. name := ``
  116. if v.Mobile != v.Name {
  117. name = v.Name
  118. }
  119. qsEventUserInfo := &qs_event_user.QsEventUser{
  120. QsId: qsEventInfo.QsId,
  121. UserId: 0,
  122. Mobile: v.Mobile,
  123. Email: v.Email,
  124. Name: name,
  125. //RegisterTime: time.Time{},
  126. ViewTotal: 0,
  127. //LastViewTime: time.Time{},
  128. CompanyId: 0,
  129. ProductId: 0,
  130. CompanyName: "",
  131. Status: "",
  132. SellerId: 0,
  133. SellerName: "",
  134. CompanyViewTotal: 0,
  135. CompanyRoadTotal: 0,
  136. CreateTime: time.Now(),
  137. }
  138. //这个时候是系统用户了,美滋滋
  139. if companyProductInfo != nil {
  140. qsEventUserInfo.RegisterTime = wxUserInfo.RegisterTime
  141. userViewStatisticsInfo, _ := user_view_statistics.GetUserViewStatisticsByMobile(trimMobile) //用户阅读信息
  142. if userViewStatisticsInfo != nil {
  143. qsEventUserInfo.ViewTotal = userViewStatisticsInfo.Total
  144. qsEventUserInfo.LastViewTime = userViewStatisticsInfo.LastViewTime
  145. }
  146. qsEventUserInfo.UserId = int(wxUserInfo.UserId)
  147. qsEventUserInfo.Name = wxUserInfo.RealName
  148. qsEventUserInfo.CompanyId = companyProductInfo.CompanyId
  149. qsEventUserInfo.ProductId = companyProductInfo.ProductId
  150. qsEventUserInfo.CompanyName = companyInfo.CompanyName
  151. qsEventUserInfo.Status = companyProductInfo.Status
  152. qsEventUserInfo.SellerId = companyProductInfo.SellerId
  153. qsEventUserInfo.SellerName = companyProductInfo.SellerName
  154. qsEventUserInfo.CompanyViewTotal = companyProductInfo.ViewTotal
  155. qsEventUserInfo.CompanyRoadTotal = companyProductInfo.RoadShowTotal
  156. }
  157. _ = qs_event_user.AddQsEventUser(qsEventUserInfo)
  158. }
  159. }
  160. qsEventInfo.IsSync = 1
  161. qsEventInfo.QsStatus = 2
  162. qsEventInfo.People = qsEventInfo.People + people
  163. err = qsEventInfo.Update([]string{"IsSync", "QsStatus", "People"})
  164. return
  165. }
  166. // SyncVideo 录音同步
  167. func SyncVideo(qsEventId int, videoUrl string) (err error) {
  168. qsEventInfo, err := qs_event.GetQsEventByQsEventId(qsEventId)
  169. if err != nil {
  170. return
  171. }
  172. qsEventInfo.VideoUrl = videoUrl
  173. err = qsEventInfo.Update([]string{"VideoUrl"})
  174. return
  175. }