rai_company_user_bill.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. package services
  2. import (
  3. "context"
  4. "errors"
  5. "fmt"
  6. "hongze/hongze_cygx/models"
  7. "hongze/hongze_cygx/models/company"
  8. "hongze/hongze_cygx/models/rai_serve"
  9. "hongze/hongze_cygx/models/roadshow"
  10. "hongze/hongze_cygx/utils"
  11. "strings"
  12. "time"
  13. )
  14. //func init() {
  15. // UpdateCygxRaiCompanyUserBill()
  16. //}
  17. // 权益正式,试用客户近四周互动记录
  18. func UpdateCygxRaiCompanyUserBillDate(cont context.Context) (err error) {
  19. //func UpdateCygxRaiCompanyUserBillDate() (err error) {
  20. defer func() {
  21. if err != nil {
  22. fmt.Println(err)
  23. go utils.SendAlarmMsg(fmt.Sprint("定时任务处理权权益正式,试用客户近四周互动记录 失败 UpdateCygxRaiCompanyUserBillDate ,err:", err.Error()), 2)
  24. }
  25. }()
  26. err = UpdateCygxRaiCompanyUserBill() // 处理共享机构信息
  27. if err != nil {
  28. return
  29. }
  30. err = UpdateCompanyProductIsUserMaker() // 处理个人流水记录
  31. if err != nil {
  32. return
  33. }
  34. return
  35. }
  36. // 批量更新权益正式,试用客户近四周互动记录
  37. func UpdateCygxRaiCompanyUserBill() (err error) {
  38. defer func() {
  39. if err != nil {
  40. fmt.Println(err)
  41. go utils.SendAlarmMsg("批量更新权益正式,试用客户近四周互动记录 失败: UpdateCygxRaiCompanyUserBill Err"+err.Error(), 2)
  42. }
  43. }()
  44. var delBillIds []int
  45. var startWeekDate = time.Now().AddDate(0, 0, -28).Format(utils.FormatDate) + " 23:59:59"
  46. fmt.Println("UpdateCygxRaiCompanyUserBill start")
  47. companyList, e := company.GetRaiCompanyProductCompanyids()
  48. if e != nil {
  49. err = errors.New("GetCygxRaiServeCompanyAllList, Err: " + e.Error())
  50. return
  51. }
  52. var companyIds []int
  53. var items []*rai_serve.CygxRaiCompanyUserBill
  54. for _, v := range companyList {
  55. companyIds = append(companyIds, v.CompanyId)
  56. }
  57. lencompanyId := len(companyIds)
  58. listisMakeruser, e := models.GetWxUserisMakerByCompanyIds(companyIds)
  59. if e != nil {
  60. err = errors.New("GetWxUserisMakerByCompanyIds, Err: " + e.Error())
  61. return
  62. }
  63. mapUserMaker := make(map[int]bool)
  64. mapUserMobileUserId := make(map[string]int)
  65. for _, v := range listisMakeruser {
  66. mapUserMaker[v.UserId] = true
  67. mapUserMobileUserId[v.Mobile] = v.UserId
  68. }
  69. var condition string
  70. var pars []interface{}
  71. condition = " AND art.company_id IN (" + utils.GetOrmInReplace(lencompanyId) + ") AND art.create_time > ? "
  72. pars = append(pars, companyIds, startWeekDate)
  73. fmt.Println("startWeekDate", startWeekDate)
  74. //研选专栏阅读记录内容
  75. {
  76. listYanxuanSpecialRecord, e := models.GetCygxYanxuanSpecialRecordRespListAll(condition+" GROUP BY user_id, yanxuan_special_id ORDER BY create_time ASC ", pars)
  77. if e != nil {
  78. err = errors.New("GetCygxYanxuanSpecialRecordRespListAll, Err: " + e.Error())
  79. return
  80. }
  81. var yanxuanspecialIds []int
  82. for _, v := range listYanxuanSpecialRecord {
  83. yanxuanspecialIds = append(yanxuanspecialIds, v.YanxuanSpecialId)
  84. }
  85. yanxuanspecialIds = append(yanxuanspecialIds, 0)
  86. var conditionYanxuanSpecial string
  87. var parsYanxuanSpecial []interface{}
  88. conditionYanxuanSpecial += ` AND id IN (` + utils.GetOrmInReplace(len(yanxuanspecialIds)) + `) `
  89. parsYanxuanSpecial = append(parsYanxuanSpecial, yanxuanspecialIds)
  90. listYanxuanSpecial, e := models.GetYanxuanSpecialListBycondition(conditionYanxuanSpecial, parsYanxuanSpecial, 0, len(yanxuanspecialIds))
  91. if e != nil && e.Error() != utils.ErrNoRow() {
  92. err = errors.New("GetYanxuanSpecialListBycondition, Err: " + e.Error())
  93. return
  94. }
  95. mapYanxuanSpecialTitle := make(map[int]string)
  96. for _, v := range listYanxuanSpecial {
  97. mapYanxuanSpecialTitle[v.Id] = v.Title
  98. }
  99. //研选阅读明细
  100. var conditionBill string
  101. var parsBill []interface{}
  102. conditionBill = " AND source = 'yanxuanspecial' AND company_id IN (" + utils.GetOrmInReplace(lencompanyId) + ") AND view_time > ? "
  103. parsBill = append(parsBill, companyIds, startWeekDate)
  104. listBillByYanxuanspecial, e := rai_serve.GetCygxRaiCompanyUserBillListAll(conditionBill, parsBill)
  105. if e != nil {
  106. err = errors.New("GetCygxRaiCompanyUserBillListAll, Err: " + e.Error())
  107. return
  108. }
  109. mapYanxuanspecialBill := make(map[string]bool)
  110. for _, v := range listBillByYanxuanspecial {
  111. mapYanxuanspecialBill[fmt.Sprint("UID_", v.UserId, "SID_", v.SourceId)] = true
  112. }
  113. for _, v := range listYanxuanSpecialRecord {
  114. if mapYanxuanspecialBill[fmt.Sprint("UID_", v.UserId, "SID_", v.YanxuanSpecialId)] { // 如果内容存在就不插入
  115. continue
  116. }
  117. item := new(rai_serve.CygxRaiCompanyUserBill)
  118. item.Content = mapYanxuanSpecialTitle[v.YanxuanSpecialId]
  119. item.ServeTypeId = 5
  120. item.ServeTypeName = "阅读uv"
  121. item.UserId = v.UserId
  122. item.Mobile = v.Mobile
  123. item.Email = v.Email
  124. item.CompanyId = v.CompanyId
  125. item.CompanyName = v.CompanyName
  126. item.RealName = v.RealName
  127. item.RegisterPlatform = v.RegisterPlatform
  128. item.ServeCount = 0.5
  129. if mapUserMaker[v.UserId] {
  130. item.IsKp = 1
  131. item.ServeCount = item.ServeCount * 3
  132. }
  133. item.SourceId = v.YanxuanSpecialId
  134. item.Source = utils.CYGX_OBJ_YANXUANSPECIAL
  135. item.CreateTime = time.Now()
  136. item.ViewTime = v.CreateTime
  137. item.WeekStartDate, item.WeekEndDate = utils.GetMondayAndSundayByTimeString(item.ViewTime)
  138. items = append(items, item)
  139. }
  140. }
  141. //研选专栏阅读记录内容end
  142. //文章阅读记录内容
  143. {
  144. listArticleRecord, e := models.GetCygxArticleHistoryRecordAllListNoLimit(condition+" GROUP BY art.user_id, art.article_id ORDER BY art.create_time ASC ", pars)
  145. if e != nil {
  146. err = errors.New("GetCygxArticleHistoryRecordAllListNoLimit, Err: " + e.Error())
  147. return
  148. }
  149. //文章阅读明细
  150. var conditionBill string
  151. var parsBill []interface{}
  152. conditionBill = " AND source = 'article' AND company_id IN (" + utils.GetOrmInReplace(lencompanyId) + ") AND view_time > ? "
  153. parsBill = append(parsBill, companyIds, startWeekDate)
  154. listBillByArticle, e := rai_serve.GetCygxRaiCompanyUserBillListAll(conditionBill, parsBill)
  155. if e != nil {
  156. err = errors.New("GetCygxRaiServeBillListAll, Err: " + e.Error())
  157. return
  158. }
  159. mapArticleBill := make(map[string]bool)
  160. for _, v := range listBillByArticle {
  161. mapArticleBill[fmt.Sprint("UID_", v.UserId, "SID_", v.SourceId)] = true
  162. }
  163. //部分数据来源没有存用户姓名,重新查一下
  164. var userIds []int
  165. for _, v := range listArticleRecord {
  166. userIds = append(userIds, v.UserId)
  167. }
  168. ListUser, e := models.GetWxUserListByUserIdsArr(userIds)
  169. if e != nil {
  170. err = errors.New("GetWxUserListByUserIdsArr, Err: " + e.Error())
  171. return
  172. }
  173. mapUserName := make(map[int]string)
  174. for _, v := range ListUser {
  175. mapUserName[v.UserId] = v.RealName
  176. }
  177. for _, v := range listArticleRecord {
  178. if mapArticleBill[fmt.Sprint("UID_", v.UserId, "SID_", v.ArticleId)] { // 如果内容存在就不插入
  179. continue
  180. }
  181. item := new(rai_serve.CygxRaiCompanyUserBill)
  182. item.Content = v.Title
  183. item.ServeTypeId = 5
  184. item.ServeTypeName = "阅读uv"
  185. item.UserId = v.UserId
  186. item.Mobile = v.Mobile
  187. item.Email = v.Email
  188. item.CompanyId = v.CompanyId
  189. item.CompanyName = v.CompanyName
  190. item.RealName = mapUserName[v.UserId]
  191. item.RegisterPlatform = v.RegisterPlatform
  192. item.ServeCount = 0.5
  193. if mapUserMaker[v.UserId] {
  194. item.IsKp = 1
  195. item.ServeCount = item.ServeCount * 3
  196. }
  197. item.SourceId = v.ArticleId
  198. item.Source = utils.CYGX_OBJ_ARTICLE
  199. item.CreateTime = time.Now()
  200. item.ViewTime = v.CreateTime
  201. item.WeekStartDate, item.WeekEndDate = utils.GetMondayAndSundayByTimeString(item.ViewTime)
  202. if strings.Contains(v.CategoryName, "固收") {
  203. item.ChartPermissionName = utils.GU_SHOU_NAME
  204. item.ChartPermissionId = utils.GU_SHOU_ID_CHART
  205. }
  206. if strings.Contains(v.CategoryName, "策略") {
  207. item.ChartPermissionName = utils.CE_LUE_NAME
  208. item.ChartPermissionId = utils.CE_LUE_ID
  209. }
  210. items = append(items, item)
  211. }
  212. }
  213. //文章阅读记录内容 end
  214. //活动记录内容
  215. {
  216. condition = " AND art.company_id IN (" + utils.GetOrmInReplace(lencompanyId) + ") AND a.activity_time > ? "
  217. signUpDetailList, e := models.GetSignupDetailBySignupjoinactivity(condition+" ORDER BY a.activity_time ASC ", pars)
  218. if e != nil {
  219. err = errors.New("GetSignupDetailBySignupjoinactivity, Err: " + e.Error())
  220. return
  221. }
  222. //文章阅读明细
  223. var conditionBill string
  224. var parsBill []interface{}
  225. conditionBill = " AND source = 'activity' AND company_id IN (" + utils.GetOrmInReplace(lencompanyId) + ") AND view_time > ? "
  226. parsBill = append(parsBill, companyIds, startWeekDate)
  227. listBillByActivity, e := rai_serve.GetCygxRaiCompanyUserBillListAll(conditionBill, parsBill)
  228. if e != nil {
  229. err = errors.New("GetCygxRaiCompanyUserBillListAll, Err: " + e.Error())
  230. return
  231. }
  232. mapActivityeBill := make(map[string]bool)
  233. for _, v := range listBillByActivity {
  234. mapActivityeBill[fmt.Sprint("UID_", v.UserId, "SID_", v.SourceId)] = true
  235. }
  236. mapArticleBillDel := make(map[string]bool)
  237. for _, v := range signUpDetailList {
  238. mapArticleBillDel[fmt.Sprint("UID_", v.UserId, "SID_", v.ActivityId)] = true
  239. }
  240. mapDelActivityBillDel := make(map[string]bool)
  241. for _, v := range signUpDetailList {
  242. mapDelActivityBillDel[fmt.Sprint("UID_", v.UserId, "SID_", v.ActivityId)] = true
  243. }
  244. for _, v := range listBillByActivity {
  245. if !mapDelActivityBillDel[fmt.Sprint("UID_", v.UserId, "SID_", v.SourceId)] { // 如果内容存在就插入删除ID中
  246. delBillIds = append(delBillIds, v.BillId)
  247. }
  248. }
  249. for _, v := range signUpDetailList {
  250. if mapActivityeBill[fmt.Sprint("UID_", v.UserId, "SID_", v.ActivityId)] { // 如果内容存在就不插入
  251. continue
  252. }
  253. item := new(rai_serve.CygxRaiCompanyUserBill)
  254. item.Content = v.ActivityName
  255. if v.ActivityType == 1 {
  256. item.ServeTypeId = 1
  257. item.ServeTypeName = "线上活动"
  258. } else {
  259. item.ServeTypeId = 2
  260. item.ServeTypeName = "线下活动"
  261. }
  262. if v.UserId == 0 && v.Mobile != "" {
  263. v.UserId = mapUserMobileUserId[v.Mobile] // 空降的部分联系人 userid 为0这里做一下修复
  264. }
  265. item.UserId = v.UserId
  266. item.Mobile = v.Mobile
  267. item.Email = v.Email
  268. item.CompanyId = v.CompanyId
  269. item.CompanyName = v.CompanyName
  270. item.RealName = v.RealName
  271. //item.RegisterPlatform = v.RegisterPlatform
  272. item.ServeCount = 1
  273. if mapUserMaker[v.UserId] {
  274. item.IsKp = 1
  275. item.ServeCount = item.ServeCount * 3
  276. }
  277. item.SourceId = v.ActivityId
  278. item.Source = utils.CYGX_OBJ_ACTIVITY
  279. item.CreateTime = time.Now()
  280. item.ViewTime = v.ActivityTime
  281. item.ChartPermissionName = v.ChartPermissionName
  282. item.ChartPermissionId = v.ChartPermissionId
  283. item.WeekStartDate, item.WeekEndDate = utils.GetMondayAndSundayByTimeString(item.ViewTime)
  284. items = append(items, item)
  285. }
  286. }
  287. //活动记录内容 end
  288. //专项调研活动记录内容
  289. {
  290. condition = " AND art.company_id IN (" + utils.GetOrmInReplace(lencompanyId) + ") AND a.activity_time > ? "
  291. activitySpecialList, e := models.GetCygxActivitySpecialMeetingDetailList(condition+" ORDER BY a.activity_time ASC ", pars)
  292. if e != nil {
  293. err = errors.New("GetCygxActivitySpecialMeetingDetailList, Err: " + e.Error())
  294. return
  295. }
  296. //专项调研活动明细
  297. var conditionBill string
  298. var parsBill []interface{}
  299. conditionBill = " AND source = 'activityspecial' AND company_id IN (" + utils.GetOrmInReplace(lencompanyId) + ") AND view_time > ? "
  300. parsBill = append(parsBill, companyIds, startWeekDate)
  301. listBillByActivitySpecial, e := rai_serve.GetCygxRaiCompanyUserBillListAll(conditionBill, parsBill)
  302. if e != nil {
  303. err = errors.New("GetCygxRaiCompanyUserBillListAll, Err: " + e.Error())
  304. return
  305. }
  306. mapActivitySpecial := make(map[string]bool)
  307. for _, v := range listBillByActivitySpecial {
  308. mapActivitySpecial[fmt.Sprint("UID_", v.UserId, "SID_", v.SourceId)] = true
  309. }
  310. mapDelActivitySpecial := make(map[string]bool)
  311. for _, v := range activitySpecialList {
  312. mapDelActivitySpecial[fmt.Sprint("UID_", v.UserId, "SID_", v.ActivityId)] = true
  313. }
  314. for _, v := range listBillByActivitySpecial {
  315. if !mapDelActivitySpecial[fmt.Sprint("UID_", v.UserId, "SID_", v.SourceId)] { // 如果内容存在就插入删除ID中
  316. delBillIds = append(delBillIds, v.BillId)
  317. }
  318. }
  319. for _, v := range activitySpecialList {
  320. if mapActivitySpecial[fmt.Sprint("UID_", v.UserId, "SID_", v.ActivityId)] { // 如果内容存在就不插入
  321. continue
  322. }
  323. item := new(rai_serve.CygxRaiCompanyUserBill)
  324. item.Content = v.ResearchTheme
  325. item.ServeTypeId = 3
  326. item.ServeTypeName = "专项调研"
  327. item.UserId = v.UserId
  328. item.Mobile = v.Mobile
  329. item.Email = v.Email
  330. item.CompanyId = v.CompanyId
  331. item.CompanyName = v.CompanyName
  332. item.RealName = v.RealName
  333. //item.RegisterPlatform = v.RegisterPlatform
  334. item.ServeCount = 1
  335. if mapUserMaker[v.UserId] {
  336. item.IsKp = 1
  337. item.ServeCount = item.ServeCount * 3
  338. }
  339. item.SourceId = v.ActivityId
  340. item.Source = utils.CYGX_OBJ_ACTIVITYSPECIAL
  341. item.CreateTime = time.Now()
  342. item.ViewTime = v.ActivityTime
  343. item.ChartPermissionName = v.ChartPermissionName
  344. item.ChartPermissionId = v.ChartPermissionId
  345. item.WeekStartDate, item.WeekEndDate = utils.GetMondayAndSundayByTimeString(item.ViewTime)
  346. items = append(items, item)
  347. }
  348. }
  349. //专项调研活动记录内容 end
  350. //1v1路演
  351. {
  352. condition = " AND art.company_id IN (" + utils.GetOrmInReplace(lencompanyId) + ") AND rs.start_date > ? "
  353. calendarMeetingUserList, e := roadshow.GetRsCalendarMeetingUserList(condition+" ORDER BY rs.start_date ASC ", pars)
  354. if e != nil {
  355. err = errors.New("GetRsCalendarMeetingUserList, Err: " + e.Error())
  356. return
  357. }
  358. var rsCalendarIds []int
  359. for _, v := range calendarMeetingUserList {
  360. rsCalendarIds = append(rsCalendarIds, v.RsCalendarId)
  361. }
  362. //获取研究员信息
  363. researchers, e := roadshow.GetRsCalendarResearcherListByIds(rsCalendarIds)
  364. if e != nil {
  365. err = errors.New("GetRsCalendarResearcherListByIds, Err: " + e.Error())
  366. return
  367. }
  368. mapResearcherName := make(map[int][]string)
  369. for _, v := range researchers {
  370. mapResearcherName[v.RsCalendarId] = append(mapResearcherName[v.RsCalendarId], v.ResearcherName)
  371. }
  372. listEmail, e := models.GetAskEmail()
  373. if e != nil {
  374. err = errors.New("GetAskEmail, Err: " + e.Error())
  375. return
  376. }
  377. var ceLueResearcherName []string
  378. var guShouResearcherName []string
  379. for _, v := range listEmail {
  380. if v.ChartPermissionName == utils.CE_LUE_NAME {
  381. ceLueResearcherName = append(ceLueResearcherName, v.Name)
  382. }
  383. if v.ChartPermissionName == utils.GU_SHOU_NAME {
  384. guShouResearcherName = append(guShouResearcherName, v.Name)
  385. }
  386. }
  387. //专项调研活动明细
  388. var conditionBill string
  389. var parsBill []interface{}
  390. conditionBill = " AND source = 'rscalendar' AND company_id IN (" + utils.GetOrmInReplace(lencompanyId) + ") AND view_time > ? "
  391. parsBill = append(parsBill, companyIds, startWeekDate)
  392. listBillByRscalendar, e := rai_serve.GetCygxRaiCompanyUserBillListAll(conditionBill, parsBill)
  393. if e != nil {
  394. err = errors.New("GetCygxRaiCompanyUserBillListAll, Err: " + e.Error())
  395. return
  396. }
  397. mapRscalendarBill := make(map[string]bool)
  398. for _, v := range listBillByRscalendar {
  399. mapRscalendarBill[fmt.Sprint("UID_", v.UserId, "SID_", v.SourceId)] = true
  400. }
  401. mapDelRscalendarBill := make(map[string]bool)
  402. for _, v := range calendarMeetingUserList {
  403. mapDelRscalendarBill[fmt.Sprint("UID_", v.UserId, "SID_", v.RsCalendarId)] = true
  404. }
  405. for _, v := range listBillByRscalendar {
  406. if !mapDelRscalendarBill[fmt.Sprint("UID_", v.UserId, "SID_", v.SourceId)] { // 如果内容存在就插入删除ID中
  407. delBillIds = append(delBillIds, v.BillId)
  408. }
  409. }
  410. for _, v := range calendarMeetingUserList {
  411. if mapRscalendarBill[fmt.Sprint("UID_", v.UserId, "SID_", v.RsCalendarId)] { // 如果内容存在就不插入
  412. continue
  413. }
  414. item := new(rai_serve.CygxRaiCompanyUserBill)
  415. item.Content = strings.Join(mapResearcherName[v.RsCalendarId], ",")
  416. item.ServeTypeId = 4
  417. item.ServeTypeName = "一对一路演"
  418. item.UserId = v.UserId
  419. item.Mobile = v.Mobile
  420. item.Email = v.Email
  421. item.CompanyId = v.CompanyId
  422. item.CompanyName = v.CompanyName
  423. item.RealName = v.RealName
  424. //item.RegisterPlatform = v.RegisterPlatform
  425. item.ServeCount = 1.5
  426. if mapUserMaker[v.UserId] {
  427. item.IsKp = 1
  428. item.ServeCount = item.ServeCount * 3
  429. }
  430. item.SourceId = v.RsCalendarId
  431. item.Source = utils.CYGX_OBJ_RS_CALENDAR
  432. item.CreateTime = time.Now()
  433. item.ViewTime = v.StartDate + " " + v.StartTime
  434. item.WeekStartDate, item.WeekEndDate = utils.GetMondayAndSundayByTimeString(item.ViewTime)
  435. if utils.InArrayByStr(guShouResearcherName, item.Content) {
  436. item.ChartPermissionName = utils.GU_SHOU_NAME
  437. item.ChartPermissionId = utils.GU_SHOU_ID_CHART
  438. }
  439. if utils.InArrayByStr(ceLueResearcherName, item.Content) {
  440. item.ChartPermissionName = utils.CE_LUE_NAME
  441. item.ChartPermissionId = utils.CE_LUE_ID
  442. }
  443. items = append(items, item)
  444. }
  445. }
  446. //1v1路演 end
  447. //交流反馈
  448. {
  449. condition = " AND company_id IN (" + utils.GetOrmInReplace(lencompanyId) + ") AND create_time > ? "
  450. userFeedbackList, e := rai_serve.GetCygxUserFeedbackList(condition+" ORDER BY user_feedback_id ASC ", pars)
  451. if e != nil {
  452. err = errors.New("GetCygxUserFeedbackList, Err: " + e.Error())
  453. return
  454. }
  455. //交流反馈明细
  456. var conditionBill string
  457. var parsBill []interface{}
  458. conditionBill = " AND source = 'userfeedback' AND company_id IN (" + utils.GetOrmInReplace(lencompanyId) + ") AND view_time > ? "
  459. parsBill = append(parsBill, companyIds, startWeekDate)
  460. listBillByuserFeedback, e := rai_serve.GetCygxRaiCompanyUserBillListAll(conditionBill, parsBill)
  461. if e != nil {
  462. err = errors.New("GetCygxRaiServeBillListAll, Err: " + e.Error())
  463. return
  464. }
  465. mapRscalendarBill := make(map[string]bool)
  466. for _, v := range listBillByuserFeedback {
  467. mapRscalendarBill[fmt.Sprint("UID_", v.UserId, "SID_", v.SourceId)] = true
  468. }
  469. mapDelRscalendarBill := make(map[string]bool)
  470. for _, v := range userFeedbackList {
  471. mapDelRscalendarBill[fmt.Sprint("UID_", v.UserId, "SID_", v.UserFeedbackId)] = true
  472. }
  473. for _, v := range listBillByuserFeedback {
  474. if !mapDelRscalendarBill[fmt.Sprint("UID_", v.UserId, "SID_", v.SourceId)] { // 如果内容存在就插入删除ID中
  475. delBillIds = append(delBillIds, v.BillId)
  476. }
  477. }
  478. for _, v := range userFeedbackList {
  479. if mapRscalendarBill[fmt.Sprint("UID_", v.UserId, "SID_", v.UserFeedbackId)] { // 如果内容存在就不插入
  480. continue
  481. }
  482. item := new(rai_serve.CygxRaiCompanyUserBill)
  483. item.Content = v.Content
  484. item.ServeTypeId = 6
  485. item.ServeTypeName = "交流反馈"
  486. item.UserId = v.UserId
  487. item.Mobile = v.Mobile
  488. item.Email = v.Email
  489. item.CompanyId = v.CompanyId
  490. item.CompanyName = v.CompanyName
  491. item.RealName = v.RealName
  492. item.ServeCount = 1
  493. if mapUserMaker[v.UserId] {
  494. item.IsKp = 1
  495. item.ServeCount = item.ServeCount * 3
  496. }
  497. item.SourceId = v.UserFeedbackId
  498. item.Source = utils.CYGX_OBJ_USER_FEEDBACK
  499. item.CreateTime = time.Now()
  500. item.ViewTime = v.CreateTime
  501. item.WeekStartDate, item.WeekEndDate = utils.GetMondayAndSundayByTimeString(item.ViewTime)
  502. items = append(items, item)
  503. }
  504. }
  505. //交流反馈 end
  506. //fmt.Println("items", len(items))
  507. //return
  508. if len(items) > 0 {
  509. var itemsAdd []*rai_serve.CygxRaiCompanyUserBill
  510. for k, v := range items {
  511. itemsAdd = append(itemsAdd, v)
  512. if len(itemsAdd)%2000 == 0 {
  513. fmt.Println(k)
  514. e = rai_serve.AddCygxRaiCompanyUserBilllMulti(itemsAdd)
  515. if e != nil {
  516. err = errors.New("AddCygxRaiServeBillMulti, Err: " + e.Error())
  517. return
  518. }
  519. itemsAdd = make([]*rai_serve.CygxRaiCompanyUserBill, 0)
  520. }
  521. }
  522. e = rai_serve.AddCygxRaiCompanyUserBilllMulti(itemsAdd)
  523. if e != nil {
  524. err = errors.New("AddCygxRaiCompanyUserBilllMulti, Err: " + e.Error())
  525. return
  526. }
  527. }
  528. fmt.Println("delBillIds", (delBillIds))
  529. fmt.Println("UpdateCygxRaiCompanyUserBill end")
  530. return
  531. }
  532. // 更新权益客户最近四周是否有决策人互动记录
  533. func UpdateCompanyProductIsUserMaker() (err error) {
  534. defer func() {
  535. if err != nil {
  536. fmt.Println(err)
  537. go utils.SendAlarmMsg("更新权益客户最近四周是否有决策人互动记录 失败: UpdateCompanyProductIsUserMaker Err"+err.Error(), 2)
  538. }
  539. }()
  540. fmt.Println(" UpdateCompanyProductIsUserMaker start")
  541. now := time.Now()
  542. weeks := 3
  543. monday := now.AddDate(0, 0, -int(now.Weekday()-time.Monday)-weeks*7)
  544. startDate := monday.Format(utils.FormatDate)
  545. var condition string
  546. var pars []interface{}
  547. condition = ` AND week_start_date >= ? AND is_kp = 1 GROUP BY company_id `
  548. pars = append(pars, startDate)
  549. //获取近四周之内含有KP的公司
  550. listKpCompanyId, e := rai_serve.GetCygxRaiCompanyUserBillListAll(condition, pars)
  551. if e != nil {
  552. err = errors.New("GetCygxRaiCompanyUserBillListAll, Err: " + e.Error())
  553. return
  554. }
  555. var companyIds []int
  556. for _, v := range listKpCompanyId {
  557. companyIds = append(companyIds, v.CompanyId)
  558. }
  559. companyIds = append(companyIds, 0)
  560. //if len(companyIds) == 0 {
  561. // return
  562. //}
  563. //fmt.Println(len(companyIds))
  564. e = company.UpdateRaiCompanyProductIsUserMakerByCompanyids(companyIds)
  565. if e != nil {
  566. err = errors.New("UpdateRaiCompanyProductIsUserMakerByCompanyids, Err: " + e.Error())
  567. return
  568. }
  569. fmt.Println(" UpdateCompanyProductIsUserMaker end")
  570. return
  571. }