user_view_history.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hz_crm_api/utils"
  5. "time"
  6. )
  7. type UserViewHistory struct {
  8. ViewHistoryId int `orm:"column(id);pk"`
  9. UserId int `description:"用户id"`
  10. Mobile string `description:"手机号"`
  11. Email string `description:"邮箱"`
  12. RealName string `description:"用户实际姓名"`
  13. CompanyName string `description:"公司名称"`
  14. ViewTitle string `description:"访问标题"`
  15. ViewPage string `description:"访问页面"`
  16. ReportChapterModule string `description:"访问核心观点或者图文逻辑"`
  17. CreatedTime string `description:"创建时间"`
  18. LastUpdatedTime time.Time `description:"访问历史类型,weekly_report 周报,pdf;默认值:weekly_report"`
  19. ResearchReportId int `description:"研报id"`
  20. ResearchReportTypeId int `description:"报告章节id,为0时表示查看目录或者首页"`
  21. }
  22. // 根据用户id字符串获取用户的浏览数
  23. type UserViewTotalSlice struct {
  24. UserId int `description:"用户id"`
  25. Total int `description:"总阅读数"`
  26. CreatedTime time.Time `description:"用户浏览时间"`
  27. }
  28. func GetCountUserViewHistoryByUserIds(userIds string) (items []*UserViewTotalSlice, err error) {
  29. o := orm.NewOrm()
  30. sql := `SELECT count(1) total,user_id,max(created_time) as created_time FROM user_view_history WHERE user_id in (` + userIds + `) group by user_id`
  31. _, err = o.Raw(sql).QueryRows(&items)
  32. return
  33. //return items2,err
  34. }
  35. // 根据用户手机号字符串获取用户的浏览数
  36. type UserViewMobileTotalSlice struct {
  37. Mobile string `description:"用户手机号"`
  38. Total int `description:"总阅读数"`
  39. CreatedTime time.Time `description:"用户浏览时间"`
  40. }
  41. func GetCountUserViewHistoryByMobiles(mobiles string) (items []*UserViewMobileTotalSlice, err error) {
  42. o := orm.NewOrm()
  43. sql := `SELECT count(1) total,mobile,max(created_time) as created_time FROM user_view_history WHERE mobile in (` + mobiles + `) group by mobile`
  44. _, err = o.Raw(sql).QueryRows(&items)
  45. return
  46. }
  47. // 根据用户id字符串获取用户的浏览数
  48. type UserViewEmailTotalSlice struct {
  49. Email string `description:"用户邮箱"`
  50. Total int `description:"总阅读数"`
  51. CreatedTime time.Time `description:"用户浏览时间"`
  52. }
  53. func GetCountUserViewHistoryByEmails(emails string) (items []*UserViewEmailTotalSlice, err error) {
  54. o := orm.NewOrm()
  55. sql := `SELECT count(1) total,email,max(created_time) as created_time FROM user_view_history WHERE email in (` + emails + `) group by email`
  56. _, err = o.Raw(sql).QueryRows(&items)
  57. return
  58. //return items2,err
  59. }
  60. func GetCountCygxArticleHistoryRecordByMobiles(mobiles string) (items []*UserViewMobileTotalSlice, err error) {
  61. o := orm.NewOrm()
  62. sql := `SELECT count(1) total,h.mobile,max(h.create_time) as created_time FROM cygx_article_history_record_all AS h INNER JOIN cygx_article AS art ON art.article_id = h.article_id WHERE h.mobile in (` + mobiles + `) AND h.is_del = 0 AND h.company_id != 16 group by h.mobile`
  63. _, err = o.Raw(sql).QueryRows(&items)
  64. return
  65. }
  66. func GetCountCygxArticleHistoryRecordByEmails(emails string) (items []*UserViewEmailTotalSlice, err error) {
  67. o := orm.NewOrm()
  68. sql := `SELECT count(1) total,h.email,max(h.create_time) as created_time FROM cygx_article_history_record_all AS h INNER JOIN cygx_article AS art ON art.article_id = h.article_id WHERE h.email in (` + emails + `) AND h.is_del = 0 AND h.company_id != 16 group by email`
  69. _, err = o.Raw(sql).QueryRows(&items)
  70. return
  71. }
  72. // CompanyLastViewSlice 根据手机号获取客户的最新浏览时间
  73. type CompanyLastViewSlice struct {
  74. CompanyId int `description:"客户id"`
  75. ViewTime time.Time `description:"用户浏览时间"`
  76. }
  77. // GetLastUserViewHistoryByCompanyIdsMobile 根据手机号获取客户的最新浏览时间
  78. func GetLastUserViewHistoryByCompanyIdsMobile(companyIds string) (items []*CompanyLastViewSlice, err error) {
  79. today := time.Now().Format(utils.FormatDate)
  80. o := orm.NewOrm()
  81. sql := `SELECT
  82. a.company_id ,max(b.created_time) view_time
  83. FROM
  84. wx_user a
  85. JOIN user_view_history b ON a.mobile = b.mobile
  86. WHERE
  87. a.company_id IN ( ` + companyIds + ` ) and b.mobile !="" and b.created_time>=? GROUP BY company_id`
  88. _, err = o.Raw(sql, today).QueryRows(&items)
  89. return
  90. }
  91. // GetLastUserViewHistoryByCompanyIdsEmail 根据邮箱获取客户的最新浏览时间
  92. func GetLastUserViewHistoryByCompanyIdsEmail(companyIds string) (items []*CompanyLastViewSlice, err error) {
  93. today := time.Now().Format(utils.FormatDate)
  94. o := orm.NewOrm()
  95. // sql := `SELECT
  96. // a.company_id ,max(b.created_time) view_time
  97. //FROM
  98. // wx_user a
  99. // JOIN user_view_history b ON a.email = b.email
  100. //WHERE a.company_id IN ( ` + companyIds + ` ) and b.email !="" and b.mobile="" and b.created_time>=? GROUP BY company_id`
  101. sql := `SELECT
  102. a.company_id ,max(b.created_time) view_time FROM wx_user a
  103. JOIN user_view_history b ON a.email = b.email
  104. WHERE b.email !="" and b.mobile="" and b.created_time>=? GROUP BY company_id`
  105. _, err = o.Raw(sql, today).QueryRows(&items)
  106. return
  107. }
  108. // GetLastAdvisoryArticleViewRecordByCompanyIdsMobile 根据手机号获取客户的最新浏览时间
  109. func GetLastAdvisoryArticleViewRecordByCompanyIdsMobile(companyIds string) (items []*CompanyLastViewSlice, err error) {
  110. today := time.Now().Format(utils.FormatDate)
  111. o := orm.NewOrm()
  112. sql := `SELECT
  113. a.company_id ,max(b.create_time) view_time
  114. FROM
  115. wx_user a
  116. JOIN advisory_user_chart_article_record b ON a.mobile = b.mobile
  117. WHERE
  118. a.company_id IN ( ` + companyIds + ` ) and b.mobile !="" and b.create_time>=? GROUP BY company_id`
  119. _, err = o.Raw(sql, today).QueryRows(&items)
  120. return
  121. }
  122. // GetLastAdvisoryArticleViewRecordByCompanyIdsEmail 根据邮箱获取客户的最新浏览时间
  123. func GetLastAdvisoryArticleViewRecordByCompanyIdsEmail(companyIds string) (items []*CompanyLastViewSlice, err error) {
  124. today := time.Now().Format(utils.FormatDate)
  125. o := orm.NewOrm()
  126. sql := `SELECT
  127. a.company_id ,max(b.create_time) view_time
  128. FROM
  129. wx_user a
  130. JOIN advisory_user_chart_article_record b ON a.email = b.email
  131. WHERE a.company_id IN ( ` + companyIds + ` ) and b.email !="" and b.mobile="" and b.create_time>=? GROUP BY company_id`
  132. _, err = o.Raw(sql, today).QueryRows(&items)
  133. return
  134. }
  135. // GetLastCygxArticleViewRecordByCompanyIdsMobile 根据手机号获取客户的最新浏览时间
  136. func GetLastCygxArticleViewRecordByCompanyIdsMobile(companyIds string) (items []*CompanyLastViewSlice, err error) {
  137. o := orm.NewOrm()
  138. //dataName := ""
  139. //if utils.RunMode == "debug" {
  140. // dataName = "test_v2_hongze_rddp"
  141. //} else {
  142. // dataName = "hongze_rddp"
  143. //}
  144. sql := `SELECT
  145. a.company_id ,max(b.create_time) view_time
  146. FROM
  147. wx_user a
  148. JOIN cygx_article_history_record_newpv b ON a.mobile = b.mobile
  149. WHERE
  150. a.company_id IN ( ` + companyIds + ` ) and b.mobile !="" GROUP BY company_id`
  151. _, err = o.Raw(sql).QueryRows(&items)
  152. return
  153. }
  154. // GetLastCygxArticleViewRecordByCompanyIdsEmail 根据邮箱获取客户的最新浏览时间
  155. func GetLastCygxArticleViewRecordByCompanyIdsEmail(companyIds string) (items []*CompanyLastViewSlice, err error) {
  156. o := orm.NewOrm()
  157. sql := `SELECT
  158. a.company_id ,max(b.create_time) view_time
  159. FROM
  160. wx_user a
  161. JOIN cygx_article_history_record_newpv b ON a.email = b.email
  162. WHERE a.company_id IN ( ` + companyIds + ` ) and b.email !="" and b.mobile="" GROUP BY company_id`
  163. _, err = o.Raw(sql).QueryRows(&items)
  164. return
  165. }
  166. // MobileOrEmailLastViewSlice 根据手机号/邮箱获取客户的最新浏览时间
  167. type MobileOrEmailLastViewSlice struct {
  168. Mobile string `description:"手机号/邮箱"`
  169. ViewTime time.Time `description:"用户浏览时间"`
  170. }
  171. // GetLastReportViewRecordByMobileList 根据手机号获取客户的最新浏览时间
  172. func GetLastReportViewRecordByMobileList(mobileList []string) (items []*MobileOrEmailLastViewSlice, err error) {
  173. num := len(mobileList)
  174. if num <= 0 {
  175. return
  176. }
  177. today := time.Now().Format(utils.FormatDate)
  178. o := orm.NewOrmUsingDB("rddp")
  179. sql := `SELECT mobile ,max(create_time) view_time FROM report_view_record
  180. WHERE mobile IN ( ` + utils.GetOrmInReplace(num) + ` ) and mobile !="" and create_time>=? GROUP BY mobile`
  181. _, err = o.Raw(sql, mobileList, today).QueryRows(&items)
  182. return
  183. }
  184. // GetLastReportViewRecordByEmailList 根据邮箱获取客户的最新浏览时间
  185. func GetLastReportViewRecordByEmailList(emailList []string) (items []*MobileOrEmailLastViewSlice, err error) {
  186. num := len(emailList)
  187. if num <= 0 {
  188. return
  189. }
  190. today := time.Now().Format(utils.FormatDate)
  191. o := orm.NewOrmUsingDB("rddp")
  192. sql := `SELECT email AS mobile ,max(create_time) view_time FROM report_view_record
  193. WHERE email IN ( ` + utils.GetOrmInReplace(num) + ` ) and email !="" and create_time>=? GROUP BY email`
  194. _, err = o.Raw(sql, emailList, today).QueryRows(&items)
  195. return
  196. }
  197. // GetLastUserViewStatisticsByCompanyIdsMobile 根据手机号获取客户的最新浏览时间
  198. func GetLastUserViewStatisticsByCompanyIdsMobile(companyIds string) (items []*CompanyLastViewSlice, err error) {
  199. today := time.Now().Format(utils.FormatDate)
  200. o := orm.NewOrm()
  201. sql := `SELECT
  202. a.company_id ,max(b.last_view_time) view_time
  203. FROM
  204. wx_user a
  205. JOIN user_view_statistics b ON a.mobile = b.mobile
  206. WHERE
  207. a.company_id IN ( ` + companyIds + ` ) and a.mobile !="" and b.mobile !="" and b.date<=? GROUP BY a.company_id`
  208. _, err = o.Raw(sql, today).QueryRows(&items)
  209. return
  210. }
  211. // GetLastUserViewStatisticsByCompanyIdsEmail 根据邮箱获取客户的最新浏览时间
  212. func GetLastUserViewStatisticsByCompanyIdsEmail(companyIds string) (items []*CompanyLastViewSlice, err error) {
  213. today := time.Now().Format(utils.FormatDate)
  214. o := orm.NewOrm()
  215. sql := `SELECT
  216. a.company_id ,max(b.last_view_time) view_time
  217. FROM
  218. wx_user a
  219. JOIN user_view_statistics b ON a.email = b.email
  220. WHERE a.company_id IN ( ` + companyIds + ` ) and a.email !="" and b.email !="" and a.mobile="" and b.mobile="" and b.date<=? GROUP BY a.company_id`
  221. _, err = o.Raw(sql, today).QueryRows(&items)
  222. return
  223. }
  224. // CompanyViewTotalSlice 获取客户的浏览次数
  225. type CompanyViewTotalSlice struct {
  226. CompanyId int `description:"客户id"`
  227. ViewTotal int `description:"用户浏览次数"`
  228. }
  229. // GetCountUserViewHistoryByCompanyIdsMobile 根据手机号获取客户的浏览次数
  230. func GetCountUserViewHistoryByCompanyIdsMobile(companyIds string) (items []*CompanyViewTotalSlice, err error) {
  231. today := time.Now().Format(utils.FormatDate) + " 00:00:00"
  232. o := orm.NewOrm()
  233. sql := `SELECT
  234. a.company_id ,count(1) view_total FROM wx_user a
  235. JOIN user_view_history b ON a.mobile = b.mobile
  236. WHERE a.company_id IN ( ` + companyIds + ` ) and b.mobile !="" and b.created_time>=? GROUP BY company_id`
  237. _, err = o.Raw(sql, today).QueryRows(&items)
  238. return
  239. }
  240. // GetCountUserViewHistoryByCompanyIdsEmail 根据邮箱获取客户的浏览次数
  241. func GetCountUserViewHistoryByCompanyIdsEmail(companyIds string) (items []*CompanyViewTotalSlice, err error) {
  242. today := time.Now().Format(utils.FormatDate) + " 00:00:00"
  243. o := orm.NewOrm()
  244. // sql := `SELECT
  245. // a.company_id ,count(1) view_total
  246. //FROM
  247. // wx_user a
  248. // JOIN user_view_history b ON a.email = b.email
  249. //WHERE a.company_id IN ( ` + companyIds + ` ) and b.email !="" and b.mobile="" and b.created_time>=? GROUP BY company_id`
  250. sql := `SELECT a.company_id ,count(1) view_total FROM wx_user a
  251. JOIN user_view_history b ON a.email = b.email
  252. WHERE b.email !="" and b.mobile="" and b.created_time>=? GROUP BY company_id`
  253. _, err = o.Raw(sql, today).QueryRows(&items)
  254. return
  255. }
  256. // GetCountAdvisoryArticleViewRecordByCompanyIdsMobile 根据手机号获取客户的浏览次数
  257. func GetCountAdvisoryArticleViewRecordByCompanyIdsMobile(companyIds string) (items []*CompanyViewTotalSlice, err error) {
  258. today := time.Now().Format(utils.FormatDate) + " 00:00:00"
  259. o := orm.NewOrm()
  260. sql := `SELECT
  261. a.company_id ,count(1) view_total
  262. FROM
  263. wx_user a
  264. JOIN advisory_user_chart_article_record b ON a.mobile = b.mobile
  265. WHERE
  266. a.company_id IN ( ` + companyIds + ` ) and b.mobile !="" and create_time>=? GROUP BY company_id`
  267. _, err = o.Raw(sql, today).QueryRows(&items)
  268. return
  269. }
  270. // GetCountAdvisoryArticleViewRecordByCompanyIdsEmail 根据邮箱获取客户的浏览次数
  271. func GetCountAdvisoryArticleViewRecordByCompanyIdsEmail(companyIds string) (items []*CompanyViewTotalSlice, err error) {
  272. today := time.Now().Format(utils.FormatDate) + " 00:00:00"
  273. o := orm.NewOrm()
  274. sql := `SELECT
  275. a.company_id ,count(1) view_total
  276. FROM
  277. wx_user a
  278. JOIN advisory_user_chart_article_record b ON a.email = b.email
  279. WHERE a.company_id IN ( ` + companyIds + ` ) and b.email !="" and b.mobile="" and create_time>=? GROUP BY company_id`
  280. _, err = o.Raw(sql, today).QueryRows(&items)
  281. return
  282. }
  283. // GetCountCygxArticleViewRecordByCompanyIdsMobile 根据手机号获取客户的浏览次数
  284. func GetCountCygxArticleViewRecordByCompanyIdsMobile(companyIds string) (items []*CompanyViewTotalSlice, err error) {
  285. o := orm.NewOrm()
  286. //dataName := ""
  287. //if utils.RunMode == "debug" {
  288. // dataName = "test_v2_hongze_rddp"
  289. //} else {
  290. // dataName = "hongze_rddp"
  291. //}
  292. sql := `SELECT
  293. a.company_id ,count(1) view_total
  294. FROM
  295. wx_user a
  296. JOIN cygx_article_history_record_newpv b ON a.mobile = b.mobile
  297. WHERE
  298. a.company_id IN ( ` + companyIds + ` ) and b.mobile !="" GROUP BY company_id`
  299. _, err = o.Raw(sql).QueryRows(&items)
  300. return
  301. }
  302. // GetCountCygxArticleViewRecordByCompanyIdsEmail 根据邮箱获取客户的浏览次数
  303. func GetCountCygxArticleViewRecordByCompanyIdsEmail(companyIds string) (items []*CompanyViewTotalSlice, err error) {
  304. o := orm.NewOrm()
  305. sql := `SELECT
  306. a.company_id ,count(1) view_total
  307. FROM
  308. wx_user a
  309. JOIN cygx_article_history_record_newpv b ON a.email = b.email
  310. WHERE a.company_id IN ( ` + companyIds + ` ) and b.email !="" and b.mobile="" GROUP BY company_id`
  311. _, err = o.Raw(sql).QueryRows(&items)
  312. return
  313. }
  314. // MobileOrEmailViewTotalSlice 获取客户的浏览次数
  315. type MobileOrEmailViewTotalSlice struct {
  316. Mobile string `description:"客户手机号/邮箱"`
  317. ViewTotal int `description:"用户浏览次数"`
  318. }
  319. // GetCountReportViewRecordByMobileList 根据手机号获取客户的浏览次数
  320. func GetCountReportViewRecordByMobileList(mobileList []string) (items []*MobileOrEmailViewTotalSlice, err error) {
  321. num := len(mobileList)
  322. if num <= 0 {
  323. return
  324. }
  325. today := time.Now().Format(utils.FormatDate) + " 00:00:00"
  326. o := orm.NewOrmUsingDB("rddp")
  327. sql := `SELECT mobile ,count(1) AS view_total FROM report_view_record
  328. WHERE mobile IN ( ` + utils.GetOrmInReplace(num) + ` ) and mobile !="" and create_time>=? GROUP BY mobile`
  329. _, err = o.Raw(sql, mobileList, today).QueryRows(&items)
  330. return
  331. }
  332. // GetCountReportViewRecordByEmailList 根据邮箱获取客户的浏览次数
  333. func GetCountReportViewRecordByEmailList(emailList []string) (items []*MobileOrEmailViewTotalSlice, err error) {
  334. num := len(emailList)
  335. if num <= 0 {
  336. return
  337. }
  338. today := time.Now().Format(utils.FormatDate) + " 00:00:00"
  339. o := orm.NewOrmUsingDB("rddp")
  340. sql := `SELECT email AS mobile ,count(1) AS view_total FROM report_view_record
  341. WHERE email IN ( ` + utils.GetOrmInReplace(num) + ` ) and email !="" and create_time>=? GROUP BY email`
  342. _, err = o.Raw(sql, emailList, today).QueryRows(&items)
  343. return
  344. }
  345. // GetUserViewStatisticsByCompanyIdsMobile 根据手机号获取客户的浏览次数
  346. func GetUserViewStatisticsByCompanyIdsMobile(companyIds string) (items []*CompanyViewTotalSlice, err error) {
  347. today := time.Now().Format(utils.FormatDate)
  348. o := orm.NewOrm()
  349. sql := `SELECT
  350. a.company_id ,sum(b.view_num) view_total
  351. FROM
  352. wx_user a
  353. JOIN user_view_statistics b ON a.mobile = b.mobile
  354. WHERE
  355. a.company_id IN ( ` + companyIds + ` ) and a.mobile !="" and b.mobile !="" and date<=? GROUP BY a.company_id`
  356. _, err = o.Raw(sql, today).QueryRows(&items)
  357. return
  358. }
  359. // GetUserViewStatisticsByCompanyIdsEmail 根据邮箱获取客户的浏览次数
  360. func GetUserViewStatisticsByCompanyIdsEmail(companyIds string) (items []*CompanyViewTotalSlice, err error) {
  361. today := time.Now().Format(utils.FormatDate)
  362. o := orm.NewOrm()
  363. sql := `SELECT
  364. a.company_id ,sum(b.view_num) view_total
  365. FROM
  366. wx_user a
  367. JOIN user_view_statistics b ON a.email = b.email
  368. WHERE a.company_id IN ( ` + companyIds + ` ) and a.email !="" and b.email !="" and a.mobile="" and b.mobile="" and date<=? GROUP BY a.company_id`
  369. _, err = o.Raw(sql, today).QueryRows(&items)
  370. return
  371. }
  372. // UserViewStatisticsInfo 根据用户手机号字符串获取用户的浏览数和最晚阅读次数
  373. type UserViewStatisticsInfo struct {
  374. Mobile string `description:"用户手机号"`
  375. Total int `description:"总阅读数"`
  376. LastViewTime time.Time `description:"用户浏览时间"`
  377. }
  378. // GetUserViewStatisticsByMobile 根据手机号获取联系人的浏览次数
  379. func GetUserViewStatisticsByMobile(mobile string) (item *UserViewStatisticsInfo, err error) {
  380. o := orm.NewOrm()
  381. sql := `SELECT mobile,sum(view_num) total,max(last_view_time) last_view_time FROM user_view_statistics WHERE mobile = ? `
  382. err = o.Raw(sql, mobile).QueryRow(&item)
  383. return
  384. }
  385. type ResearchReportViewPUV struct {
  386. ResearchReportId int
  387. Pv int
  388. Uv int
  389. }
  390. // GetPUVByResearchReportIds 通过报告IDs获取老报告PV、UV
  391. func GetPUVByResearchReportIds(reportIds string) (list []*ResearchReportViewPUV, err error) {
  392. o := orm.NewOrm()
  393. sql := `SELECT
  394. research_report_id,
  395. COUNT(1) AS pv,
  396. COUNT(DISTINCT user_id) AS uv
  397. FROM
  398. user_view_history
  399. WHERE
  400. research_report_id IN (` + reportIds + `)
  401. GROUP BY
  402. research_report_id`
  403. _, err = o.Raw(sql).QueryRows(&list)
  404. return
  405. }
  406. //`ficc_view_total` int(9) unsigned DEFAULT '0' COMMENT 'ficc报告的阅读次数',
  407. //`ficc_last_view_time` datetime DEFAULT NULL COMMENT 'ficc报告最近一次阅读时间',
  408. //`rai_view_total` int(9) unsigned DEFAULT '0' COMMENT '权益报告的阅读次数',
  409. //`rai_last_view_time` datetime DEFAULT NULL COMMENT '权益报告的最近一次阅读时间',
  410. // CompanyViewRecord 获取客户ficc和权益的浏览次数/最近浏览时间
  411. type CompanyViewRecord struct {
  412. CompanyId int `description:"客户id"`
  413. FiccViewTotal int `description:"ficc报告的阅读次数"`
  414. FiccLastViewTime time.Time `description:"ficc报告最近一次阅读时间"`
  415. RaiViewTotal int `description:"权益报告的阅读次数"`
  416. RaiLastViewTime time.Time `description:"权益报告最近一次阅读时间"`
  417. }
  418. // GetUserViewHistoryByCompanyIdList 根据company_id列表获取客户的浏览次数
  419. func GetUserViewHistoryByCompanyIdList(companyIdList []int) (items []*CompanyViewRecord, err error) {
  420. num := len(companyIdList)
  421. if num <= 0 {
  422. return
  423. }
  424. o := orm.NewOrm()
  425. sql := `SELECT
  426. a.company_id ,SUM(ficc_view_total) as ficc_view_total,max(ficc_last_view_time) as ficc_last_view_time,SUM(rai_view_total) as rai_view_total,max(rai_last_view_time) as rai_last_view_time
  427. FROM wx_user AS a WHERE a.company_id IN ( ` + utils.GetOrmInReplace(num) + ` ) GROUP BY a.company_id`
  428. _, err = o.Raw(sql, companyIdList).QueryRows(&items)
  429. return
  430. }