tag.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. package services
  2. import (
  3. "errors"
  4. "hongze/hongze_clpt/models"
  5. "hongze/hongze_clpt/utils"
  6. "strconv"
  7. "strings"
  8. "time"
  9. )
  10. func AddCygxTagHistory(user *models.WxUserItem, tagId int) (err error) {
  11. if user.UserId == 0 {
  12. return
  13. }
  14. defer func() {
  15. if err != nil {
  16. go utils.SendAlarmMsg("tag点击信息记录失败"+err.Error()+"tagId"+strconv.Itoa(tagId)+"userId:"+strconv.Itoa(user.UserId), 2)
  17. }
  18. }()
  19. historyRecord := new(models.CygxTagHistory)
  20. historyRecord.UserId = user.UserId
  21. historyRecord.TagId = tagId
  22. historyRecord.CreateTime = time.Now()
  23. historyRecord.Mobile = user.Mobile
  24. historyRecord.Email = user.Email
  25. historyRecord.CompanyId = user.CompanyId
  26. historyRecord.CompanyName = user.CompanyName
  27. historyRecord.RegisterPlatform = utils.REGISTER_PLATFORM
  28. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  29. if err != nil && err.Error() != utils.ErrNoRow() {
  30. return
  31. }
  32. historyRecord.RealName = user.RealName
  33. if sellerItem != nil {
  34. historyRecord.SellerName = sellerItem.RealName
  35. }
  36. _, err = models.AddCygxTagHistory(historyRecord)
  37. return
  38. }
  39. //func init() {
  40. // conditionInit, err := GetConditionInitByTagIds("43")
  41. // fmt.Println(err)
  42. // fmt.Println()
  43. // fmt.Println(conditionInit)
  44. //}
  45. func GetConditionInitByTagIds(tagIds string) (conditionInit string, err error) {
  46. if tagIds == "" {
  47. return
  48. }
  49. var condition string
  50. var pars []interface{}
  51. var searchTag, industries, subjectNames []string
  52. tagslice := strings.Split(tagIds, ",")
  53. condition = ` AND tag_id IN (` + utils.GetOrmInReplace(len(tagslice)) + `)`
  54. pars = append(pars, tagslice)
  55. listTag, e := models.GetCygxTagListCondition(condition, pars, 0, 0)
  56. if e != nil {
  57. err = errors.New("GetActivityListByCondition, Err: " + e.Error())
  58. return
  59. }
  60. for _, tagInfo := range listTag {
  61. //ActivityTypes 与 ArticleTypes 进行合并
  62. if tagInfo.ActivityTypes != "" {
  63. sliceObj := strings.Split(tagInfo.ActivityTypes, ",")
  64. for _, v := range sliceObj {
  65. searchTag = append(searchTag, v)
  66. }
  67. }
  68. if tagInfo.ArticleTypes != "" {
  69. sliceObj := strings.Split(tagInfo.ArticleTypes, ",")
  70. for _, v := range sliceObj {
  71. searchTag = append(searchTag, v)
  72. }
  73. }
  74. if tagInfo.Industries != "" {
  75. sliceObj := strings.Split(tagInfo.Industries, ",")
  76. for _, v := range sliceObj {
  77. industries = append(industries, v)
  78. }
  79. //industries = append(industries, tagInfo.Industries)
  80. }
  81. if tagInfo.SubjectNames != "" {
  82. sliceObj := strings.Split(tagInfo.SubjectNames, ",")
  83. for _, v := range sliceObj {
  84. subjectNames = append(subjectNames, v)
  85. }
  86. //subjectNames = append(subjectNames, tagInfo.SubjectNames)
  87. }
  88. }
  89. //拼接search_tag 搜索内容
  90. if len(searchTag) > 0 {
  91. //search_tag_two 兼容报告类型一对多的这种,时间不够,产品也有可能变先这么做
  92. conditionInit += " AND ( search_tag IN ('" + strings.Join(searchTag, "','") + "') OR search_tag_two IN( '" + strings.Join(searchTag, "','") + "' ) )"
  93. }
  94. var resourceDataIds []int //cygx_resource_data 主键ID
  95. //如果产业有组合,那么就去捞产业相关的内容
  96. if len(industries) > 0 {
  97. var conditionIndustry string
  98. var parsIndustry []interface{}
  99. conditionIndustry += " AND industry_name IN ('" + strings.Join(industries, "','") + "')"
  100. listIndustry, e := models.GetTopOneMonthArtReadNumIndustryAll(conditionIndustry, parsIndustry)
  101. if e != nil {
  102. err = errors.New("GetTopOneMonthArtReadNumIndustryAll, Err: " + e.Error())
  103. return
  104. }
  105. var industrialManagementIds []int // 产业ID合集
  106. for _, v := range listIndustry {
  107. industrialManagementIds = append(industrialManagementIds, v.IndustrialManagementId)
  108. }
  109. var conditionIndustryResource string
  110. var parsIndustryResource []interface{}
  111. lenArrindustrial := len(industrialManagementIds)
  112. conditionIndustryResource = ` AND industrial_management_id IN (` + utils.GetOrmInReplace(lenArrindustrial) + `)`
  113. parsIndustryResource = append(parsIndustryResource, industrialManagementIds)
  114. if lenArrindustrial > 0 {
  115. listResourceDataIndustrial, e := models.GetCygxResourceDataIndustrialGroupManagementList(conditionIndustryResource, parsIndustryResource, 0, 0)
  116. //return
  117. if e != nil {
  118. err = errors.New("GetCygxResourceDataIndustrialGroupManagementList, Err: " + e.Error())
  119. return
  120. }
  121. for _, v := range listResourceDataIndustrial {
  122. resourceDataIds = append(resourceDataIds, v.ResourceDataId)
  123. }
  124. }
  125. }
  126. //return
  127. //如果标的有组合,那么就去捞标的相关的内容
  128. if len(subjectNames) > 0 {
  129. var conditionsubject string
  130. var parssubject []interface{}
  131. conditionsubject += " AND subject_name IN ('" + strings.Join(subjectNames, "','") + "')"
  132. listsubject, e := models.GetCygxIndustrialSubjectListCondition(conditionsubject, parssubject)
  133. if e != nil {
  134. err = errors.New("GetTopOneMonthArtReadNumIndustry, Err: " + e.Error())
  135. return
  136. }
  137. var industrialsubjectIds []int // 标的ID集合
  138. for _, v := range listsubject {
  139. industrialsubjectIds = append(industrialsubjectIds, v.IndustrialSubjectId)
  140. }
  141. var conditionsubjectResource string
  142. var parssubjectResource []interface{}
  143. lenArrsubject := len(industrialsubjectIds)
  144. conditionsubjectResource = ` AND industrial_subject_id IN (` + utils.GetOrmInReplace(lenArrsubject) + `)`
  145. parssubjectResource = append(parssubjectResource, industrialsubjectIds)
  146. if lenArrsubject > 0 {
  147. listResourceDatasubject, e := models.GetCygxResourceDataIndustrialGroupSubjectList(conditionsubjectResource, parssubjectResource, 0, 0)
  148. if e != nil {
  149. err = errors.New("GetCygxResourceDataIndustrialGroupSubjectList, Err: " + e.Error())
  150. return
  151. }
  152. for _, v := range listResourceDatasubject {
  153. resourceDataIds = append(resourceDataIds, v.ResourceDataId)
  154. }
  155. }
  156. }
  157. //拼接 cygx_resource_data 表主键查询ID
  158. if len(resourceDataIds) > 0 {
  159. var resourceDataIdStrs []string
  160. resourceDataIdMap := make(map[int]bool)
  161. for _, v := range resourceDataIds {
  162. if resourceDataIdMap[v] {
  163. continue
  164. }
  165. resourceDataIdStrs = append(resourceDataIdStrs, strconv.Itoa(v))
  166. resourceDataIdMap[v] = true
  167. }
  168. conditionInit += " AND id IN (" + strings.Join(resourceDataIdStrs, ",") + ") "
  169. }
  170. return
  171. }