cygx_user.go 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190
  1. package cygx
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hz_crm_api/models/company"
  6. "strconv"
  7. "strings"
  8. "time"
  9. )
  10. type CygxCompanyUser struct {
  11. UserId int64 `orm:"column(user_id);pk"`
  12. Mobile string `description:"手机号"`
  13. Email string `description:"邮箱"`
  14. CompanyId int `description:"公司id"`
  15. CompanyName string `description:"公司名称"`
  16. RealName string `description:"姓名"`
  17. CreatedTime string `description:"创建时间"`
  18. IsMaker int `description:"是否决策人,1:是,0:否"`
  19. IsRegister bool `description:"是否注册,true:已注册,false:未注册"`
  20. Status string `description:"客户状态"`
  21. RegisterTime string `description:"注册时间"`
  22. SellerName string `description:"销售名称"`
  23. InteractionNum int `description:"互动量"`
  24. CompanyInteractionNum int `description:"企业互动量"`
  25. CompanyInteractionNumSeller int `description:"销售可见企业互动量"`
  26. Labels string `description:"标签,用英文,隔开"`
  27. ActivityLabel string `description:"活动标签,用英文,隔开"`
  28. IsShowSee bool `description:"是否展示查看"`
  29. IsShowSeeNum int `description:"是否展示查看"`
  30. HistoryNum int `description:"报告阅读"`
  31. CountNum int `description:"报告收藏"`
  32. IndustryFllowNum int `description:"产业关注"`
  33. DepartmentFollowNum int `description:"作者关注"`
  34. KeyWordNum int `description:"搜索关键词"`
  35. OnLineNum int `description:"线上互动活动"`
  36. OfficeNum int `description:"线下互动活动"`
  37. ChartNum int `description:"图表收藏数量"`
  38. TripNum int `description:"图表数量"`
  39. RoadshowVideoNum int `description:"产业视频播放量"`
  40. ActivityVideoNum int `description:"活动视频播放量"`
  41. ActivityVoiceNum int `description:"活动音频播放量"`
  42. YanxuanspecialNum int `description:"研选专栏查看数量"`
  43. PackageType int `description:"套餐类型,0:无,1:大套餐,2:小套餐"`
  44. TryStage int `description:"试用客户子标签:0全部、1未分类、2 推进、3 跟踪、4 预备"`
  45. Content string `description:"备注信息"`
  46. IsRemind bool `description:"是否添加互动提醒"`
  47. IsSubscribeCygx int `description:"是否关注了查研观向微信公众号: 0-未关注; 1-已关注"`
  48. }
  49. type CompanyUserListResp struct {
  50. Paging *paging.PagingItem
  51. List []*CygxCompanyUser
  52. }
  53. // 获取数量
  54. func GetCompanyListCount(userCondition, keyWord, kwywordcondition, condition, roleTypeCode string, pars []interface{}) (count int, err error) {
  55. o := orm.NewOrm()
  56. companyCondition := `SELECT a.company_id FROM company AS a INNER JOIN company_product AS b ON a.company_id=b.company_id WHERE a.enabled=1 `
  57. kwywordcondition = companyCondition + kwywordcondition
  58. if condition != "" {
  59. companyCondition += condition
  60. }
  61. sql := `SELECT COUNT(DISTINCT u.user_id) AS count
  62. FROM
  63. wx_user AS u
  64. INNER JOIN company AS c ON c.company_id = u.company_id
  65. INNER JOIN company_product AS cp ON cp.company_id = c.company_id
  66. INNER JOIN admin AS m ON m.admin_id = cp.seller_id
  67. INNER JOIN user_seller_relation AS sr ON sr.user_id = u.user_id
  68. WHERE u.company_id IN (` + companyCondition + `)`
  69. if userCondition != "" {
  70. sql += userCondition
  71. }
  72. if keyWord != "" {
  73. if strings.Count(roleTypeCode, "admin") > 0 {
  74. sql += ` OR ( cp.product_id = 2 AND cp.status IN ('正式','试用','冻结') AND ( u.real_name LIKE '%` + keyWord + `%' OR u.mobile LIKE '%` + keyWord + `%' OR u.email LIKE '%` + keyWord + `%' ) ` + userCondition + ` )`
  75. } else {
  76. sql += ` OR ( cp.product_id = 2 AND u.company_id IN (` + kwywordcondition + `) AND cp.status IN ('正式','试用','冻结') AND ( u.real_name LIKE '%` + keyWord + `%' OR u.mobile LIKE '%` + keyWord + `%' OR u.email LIKE '%` + keyWord + `%' ) ` + userCondition + ` )`
  77. }
  78. }
  79. err = o.Raw(sql, pars).QueryRow(&count)
  80. return
  81. }
  82. // 列表
  83. func GetCygxCompanyUserList(userCondition, keyWord, kwywordcondition, condition, roleTypeCode, sqlOrder string, pars []interface{}, startSize, pageSize int) (items []*CygxCompanyUser, err error) {
  84. o := orm.NewOrm()
  85. companyCondition := `SELECT a.company_id FROM company AS a INNER JOIN company_product AS b ON a.company_id=b.company_id WHERE a.enabled=1 `
  86. kwywordcondition = companyCondition + kwywordcondition
  87. if condition != "" {
  88. companyCondition += condition
  89. }
  90. sql := `SELECT
  91. u.user_id,
  92. u.mobile,
  93. u.email,
  94. date_format(u.register_time,'%Y-%m-%d') as register_time,
  95. u.real_name,
  96. u.is_register,
  97. u.is_maker,
  98. u.user_label as labels,
  99. u.cygx_subscribe as is_subscribe_cygx,
  100. c.company_name,
  101. c.company_id,
  102. c.interaction_num as company_interaction_num,
  103. c.interaction_num_seller as company_interaction_num_seller,
  104. cp.status,
  105. cp.try_stage,
  106. cp.package_type,
  107. m.real_name as seller_name ,
  108. ( SELECT COUNT( 1 ) FROM user_remarks AS rm WHERE rm.user_id = u.user_id ) AS is_show_see_num
  109. FROM
  110. wx_user AS u
  111. INNER JOIN company AS c ON c.company_id = u.company_id
  112. INNER JOIN company_product AS cp ON cp.company_id = c.company_id
  113. INNER JOIN admin AS m ON m.admin_id = cp.seller_id
  114. INNER JOIN user_seller_relation AS sr ON sr.user_id = u.user_id
  115. WHERE u.company_id IN (` + companyCondition + `)`
  116. if userCondition != "" {
  117. sql += userCondition
  118. }
  119. if keyWord != "" {
  120. if strings.Count(roleTypeCode, "admin") > 0 {
  121. sql += ` OR ( cp.product_id = 2 AND cp.status IN ('正式','试用','冻结') AND ( u.real_name LIKE '%` + keyWord + `%' OR u.mobile LIKE '%` + keyWord + `%' OR u.email LIKE '%` + keyWord + `%' ) ` + userCondition + ` )`
  122. } else {
  123. sql += ` OR ( cp.product_id = 2 AND u.company_id IN (` + kwywordcondition + `) AND cp.status IN ('正式','试用','冻结') AND ( u.real_name LIKE '%` + keyWord + `%' OR u.mobile LIKE '%` + keyWord + `%' OR u.email LIKE '%` + keyWord + `%' ) ` + userCondition + ` )`
  124. }
  125. }
  126. if sqlOrder != "" {
  127. sql += sqlOrder + ` LIMIT ?,? `
  128. } else {
  129. sql += ` GROUP by u.user_id ORDER BY c.created_time DESC, u.register_time DESC LIMIT ?,? `
  130. }
  131. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  132. return
  133. }
  134. type CygxCompanyUserAndSellerResp struct {
  135. UserId int `description:"用户ID"`
  136. Mobile string `description:"手机号"`
  137. Email string `description:"邮箱"`
  138. CompanyId int `description:"公司id"`
  139. CompanyName string `description:"公司名称"`
  140. RealName string `description:"姓名"`
  141. SellerName string `description:"销售名称"`
  142. }
  143. // 给所有已绑定手机号的客户(除流失)列表
  144. func GetCygxCompanyUserListByNoLoss() (items []*CygxCompanyUserAndSellerResp, err error) {
  145. o := orm.NewOrm()
  146. sql := `SELECT
  147. u.user_id,
  148. u.mobile,
  149. u.email,
  150. u.real_name,
  151. c.company_name,
  152. c.company_id,
  153. m.real_name AS seller_name
  154. FROM
  155. wx_user AS u
  156. INNER JOIN company AS c ON c.company_id = u.company_id
  157. INNER JOIN company_product AS cp ON cp.company_id = c.company_id
  158. INNER JOIN admin AS m ON m.admin_id = cp.seller_id
  159. INNER JOIN user_seller_relation AS sr ON sr.user_id = u.user_id
  160. WHERE
  161. 1 = 1
  162. AND c.enabled = 1
  163. AND cp.STATUS != '流失'
  164. AND cp.product_id = 2
  165. AND sr.product_id = 2
  166. GROUP BY
  167. u.user_id `
  168. _, err = o.Raw(sql).QueryRows(&items)
  169. return
  170. }
  171. // 对于上面的SQL的拆分优化查询速度
  172. func GetCygxCompanyUserListSplit(userIds string) (items []*CygxCompanyUser, err error) {
  173. o := orm.NewOrmUsingDB("hz_cygx")
  174. sql := `SELECT
  175. u.user_id,
  176. ( SELECT COUNT( 1 ) FROM cygx_article_history_record_all AS h INNER JOIN cygx_article as art ON art.article_id = h.article_id WHERE h.mobile = u.mobile AND h.is_del = 0 AND h.mobile <>'' ) AS history_num,
  177. ( SELECT COUNT( 1 ) FROM cygx_article_collect AS h WHERE h.user_id = u.user_id ) AS count_num,
  178. ( SELECT COUNT( 1 ) FROM cygx_chart_collect AS h WHERE h.user_id = u.user_id ) AS chart_num,
  179. ( SELECT COUNT( 1 ) FROM cygx_industry_fllow AS h WHERE h.user_id = u.user_id AND h.type = 1 ) AS industry_fllow_num,
  180. ( SELECT COUNT( 1 ) FROM cygx_article_department_follow AS h WHERE h.user_id = u.user_id AND h.type = 1 ) AS department_follow_num,
  181. ( SELECT COUNT( 1 ) FROM cygx_search_key_word AS h WHERE h.user_id = u.user_id ) AS key_word_num,
  182. ( SELECT COUNT(DISTINCT h.activity_id) FROM cygx_activity_signup_detail AS h INNER JOIN cygx_activity as a ON a.activity_id = h.activity_id INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id WHERE h.mobile = u.mobile
  183. AND t.activity_type = 1 AND h.do_fail_type = 0 ) AS on_line_num,
  184. ( SELECT COUNT( 1 ) FROM cygx_activity_signup_detail AS h INNER JOIN cygx_activity as a ON a.activity_id = h.activity_id INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id WHERE h.mobile = u.mobile
  185. AND t.activity_type = 0 AND h.do_fail_type = 0 ) AS office_num,
  186. ( SELECT COUNT( 1 ) FROM cygx_activity_special_meeting_detail AS h INNER JOIN cygx_activity_special AS a ON a.activity_id = h.activity_id WHERE h.mobile = u.mobile AND a.publish_status = 1 AND a.activity_time_end < NOW()) AS trip_num,
  187. ( SELECT COUNT( 1 ) FROM cygx_micro_roadshow_video_history AS h INNER JOIN cygx_micro_roadshow_video as v ON v.video_id = h.video_id WHERE h.mobile = u.mobile ) AS roadshow_video_num,
  188. ( SELECT COUNT( 1 ) FROM cygx_activity_video_history AS h INNER JOIN cygx_activity_video as v ON v.video_id = h.video_id WHERE h.mobile = u.mobile ) AS activity_video_num,
  189. ( SELECT COUNT( 1 ) FROM cygx_activity_voice_history AS h INNER JOIN cygx_activity_voice as v ON v.activity_voice_id = h.activity_voice_id WHERE h.mobile = u.mobile ) AS activity_voice_num,
  190. ( SELECT COUNT( 1 ) FROM cygx_yanxuan_special_record AS h INNER JOIN cygx_yanxuan_special as v ON v.id = h.yanxuan_special_id WHERE h.mobile = u.mobile ) AS yanxuanspecial_num
  191. FROM
  192. cygx_user_label AS u WHERE u.user_id IN (` + userIds + `) AND u.mobile != '' GROUP BY u.user_id `
  193. _, err = o.Raw(sql).QueryRows(&items)
  194. return
  195. }
  196. type UserRemarks struct {
  197. Id int `orm:"column(id);pk"`
  198. UserId int `description:"用户ID"`
  199. AdminId int `description:"销售/管理员ID"`
  200. Content string `description:"备注信息"`
  201. CreateTime time.Time `description:"创建时间"`
  202. }
  203. type UserRemarksResp struct {
  204. Id int `orm:"column(id);pk"`
  205. UserId int `description:"用户ID"`
  206. AdminId int `description:"销售/管理员ID"`
  207. Content string `description:"备注信息"`
  208. CreateTime string `description:"创建时间"`
  209. }
  210. type UserRemarAddReq struct {
  211. UserId int `description:"用户ID"`
  212. Content string `description:"备注信息"`
  213. SourceType int `description:"操作类型,1:对联系人单独设置,2:对机构批量设置"`
  214. DoType int `description:"操作方式,1:添加,2:取消"`
  215. }
  216. // 添加UserRemarks
  217. func AddUserRemarks(item *UserRemarks) (err error) {
  218. o := orm.NewOrm()
  219. _, err = o.Insert(item)
  220. return
  221. }
  222. // 获取备注列表
  223. func GetUserRemarksList(userId int) (items []*UserRemarksResp, err error) {
  224. o := orm.NewOrm()
  225. sql := ` SELECT * FROM user_remarks WHERE user_id=? ORDER BY create_time DESC`
  226. _, err = o.Raw(sql, userId).QueryRows(&items)
  227. return
  228. }
  229. // 获取备注列表(多用户)
  230. func GetUserRemarksListByUserIds(uids string) (items []*UserRemarksResp, err error) {
  231. o := orm.NewOrm()
  232. sql := ` SELECT * FROM user_remarks WHERE user_id IN(` + uids + `) ORDER BY create_time DESC`
  233. _, err = o.Raw(sql).QueryRows(&items)
  234. return
  235. }
  236. type UserRemarksListResp struct {
  237. List []*UserRemarksResp
  238. }
  239. // 切换列表
  240. type CygxUserTableRep struct {
  241. PermissionName string `description:"名称"`
  242. Source int `description:"类型"`
  243. TotalNum int `description:"总数"`
  244. }
  245. type CygxUserTableListRep struct {
  246. List []*CygxUserTableRep
  247. UserName string `description:"用户名称"`
  248. ComapnyName string `description:"公司名称"`
  249. Mobile string `description:"手机号"`
  250. }
  251. // @Param TryStage query int false "试用客户子标签:0全部、1未分类、2 推进、3 跟踪、4 预备"
  252. // 状态搜索列表
  253. type CygxTryStageRep struct {
  254. Name string `description:"试用客户子标签"`
  255. TryStage int `description:"试用客户子标签:0全部、1未分类、2 推进、3 跟踪、4 预备"`
  256. }
  257. type CygxUserTableStatusRep struct {
  258. List []*CygxTryStageRep
  259. Name string `description:"状态"`
  260. TryStage string `description:"状态"`
  261. }
  262. type CygxUserTableStatusListRep struct {
  263. List []*CygxUserTableStatusRep
  264. }
  265. type UserInteractionListResp struct {
  266. Paging *paging.PagingItem
  267. List []*UserInteraction
  268. MeetingNum int `description:"已到会"`
  269. NoMeetingNum int `description:"未到会"`
  270. }
  271. type UserInteraction struct {
  272. ArticleId int `description:"文章id"`
  273. ActivityId int `description:"活动ID"`
  274. ArticleType int `description:"文章类型 1:查研观向, 2:策略平台"`
  275. ArticleIdMd5 string `description:"文章MD5id"`
  276. Title string `description:"标题"`
  277. MediaTitle string `description:"音视频标题"`
  278. CategoryName string `description:"行业2"`
  279. PublishDate string `description:"发布时间"`
  280. CreateTime string `description:"创建时间"`
  281. CreateDate string `orm:"column(create_time);" description:"创建时间"`
  282. PermissionName string `orm:"column(chart_permission_name);" description:"行业"`
  283. ChartPermissionId int `description:"行业id"`
  284. IndustryName string `description:"产业名称"`
  285. SubjectNameStr string `description:"关联标的"`
  286. MatchTypeName string `description:"匹配类型"`
  287. StopTime string `description:"阅读停留时间"`
  288. NickName string `description:"作者昵称"`
  289. DepartmentId int `description:"作者ID "`
  290. KeyWord string `description:"关键词"`
  291. Source int `description:"关键词来源;1:纪要、2:图表、3:纪要/图表、4:产业资源包、5:报告、6:活动、7:搜索关键词、8:专项产业调研、9音视频播放"`
  292. ActivityName string `description:"活动名称"`
  293. ActivityType int `description:"1 线上,0、2线下"`
  294. IsMeeting int `description:"是否到会, 1是,0否"`
  295. ActivityTypeName string `description:"活动类型名称"`
  296. Label string `description:"标签"`
  297. ActivityTime string `description:"活动时间"`
  298. ActivityTimeText string `description:"活动时间"`
  299. FirstMeetingTime string `description:"首次入会时间"`
  300. LastMeetingTime string `description:"最后退出时间"`
  301. Duration string `description:"参会时长"`
  302. MeetingTypeStr string `description:"参会方式"`
  303. MeetingAuthentication string `description:"参会权鉴"`
  304. MeetingStatusStr string `description:"参会状态"`
  305. SignupType string `description:"参会方式 "`
  306. InteractionType string `description:"互动类型 "`
  307. ReminderNum int `description:"预约外呼数量 "`
  308. TitleEn string `description:"英文标题 "`
  309. PtagName string `description:"父类名称"`
  310. CtagName string `description:"子类名称"`
  311. PtagNameTwo string `description:"父类名称"`
  312. CtagNameTwo string `description:"子类名称"`
  313. CtagNamePc string `description:"Pc端所有的分类名称"`
  314. BodyHtml string `orm:"column(cover)";description:"图片链接"`
  315. HttpUrl string `orm:"column(iframe)";description:"文章链接跳转地址"`
  316. ChartId int `description:"图表id"`
  317. RealName string `description:"姓名"`
  318. CompanyName string `description:"公司名称"`
  319. CompanyId int `description:"公司ID"`
  320. SellerName string `description:"所属销售"`
  321. Mobile string `description:"手机号"`
  322. UserId int `description:"用户ID"`
  323. City string `description:"城市"`
  324. FileType string `description:"文件类型"`
  325. ListChart []*HomeChartListResp
  326. Paging *paging.PagingItem
  327. IsEnd bool `description:"是否最后一页,配合前端分页添加的参数"`
  328. CurrentIndex int `description:"当前页页码,配合前端分页添加的参数"`
  329. RegisterPlatform int `description:"来源 1小程序,2:网页 ,3:策略平台"`
  330. SourcePlatform string `description:"来源 'MOBILE:移动端小程序','PC:PC端小程序','CELUE:上海策略平台','WEB:查研观向网页版'"`
  331. TagId int
  332. TagName string // 标签名
  333. ArticleTypes string // 报告系列
  334. ActivityTypes string // 活动类型
  335. Industries string // 产业
  336. SubjectNames string // 标的
  337. SpecialType int `description:"专栏类型 1:笔记,2:观点"`
  338. }
  339. // 查研观向图表
  340. type CygxChartResp struct {
  341. Title string `description:"标题"`
  342. PublishDate string `description:"发布时间"`
  343. CreateTime string `description:"创建时间"`
  344. TitleEn string `description:"英文标题 "`
  345. PtagName string `description:"父类名称"`
  346. CtagName string `description:"子类名称"`
  347. PtagNameTwo string `description:"父类名称"`
  348. CtagNameTwo string `description:"子类名称"`
  349. CtagNamePc string `description:"Pc端所有的分类名称"`
  350. BodyHtml string `orm:"column(cover)";description:"图片链接"`
  351. HttpUrl string `orm:"column(iframe)";description:"文章链接跳转地址"`
  352. ChartId int `description:"图表id"`
  353. RealyName string `description:"姓名"`
  354. Mobile string `description:"手机号"`
  355. }
  356. // 获取阅读记录数量
  357. func GetCygxArticleHistoryCount(mobile, email, condition string) (count int, err error) {
  358. o := orm.NewOrmUsingDB("hz_cygx")
  359. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_article_history_record_all as r INNER JOIN cygx_article as art ON art.article_id = r.article_id WHERE r.mobile = '` + mobile + `' AND is_del = 0 ` + condition
  360. err = o.Raw(sqlCount).QueryRow(&count)
  361. return
  362. }
  363. // 阅读记录列表
  364. func GetCygxArticleHistoryRecordByUser(mobile, email, condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
  365. o := orm.NewOrmUsingDB("hz_cygx")
  366. sql := ` SELECT
  367. art.title,
  368. art.article_id,
  369. art.article_id_md5,
  370. art.publish_date,
  371. art.category_name,
  372. re.chart_permission_name,
  373. re.chart_permission_id,
  374. r.create_time,
  375. r.stop_time,
  376. r.source as source_platform,
  377. (
  378. SELECT
  379. GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' )
  380. FROM
  381. cygx_industrial_subject AS s
  382. WHERE
  383. s.industrial_subject_id IN ( SELECT industrial_subject_id FROM cygx_industrial_article_group_subject AS sg WHERE sg.article_id = art.article_id )
  384. ) AS subject_name_str,
  385. (
  386. SELECT
  387. GROUP_CONCAT( DISTINCT man.industry_name SEPARATOR '/' )
  388. FROM
  389. cygx_industrial_management AS man
  390. WHERE
  391. man.industrial_management_id IN ( SELECT industrial_management_id FROM cygx_industrial_article_group_management AS man_g WHERE man_g.article_id = art.article_id )
  392. ) AS industry_name
  393. FROM
  394. cygx_article_history_record_all AS r
  395. INNER JOIN cygx_article AS art ON art.article_id = r.article_id
  396. LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two
  397. LEFT JOIN cygx_industrial_article_group_management AS man ON man.article_id = art.article_id
  398. WHERE
  399. r.mobile = ? AND is_del = 0 ` + condition + ` OR ( email = ? AND email <>'' AND is_del = 0 ` + condition + ` )
  400. GROUP BY r.id ORDER BY r.create_time DESC `
  401. if startSize > 0 || pageSize > 0 {
  402. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  403. }
  404. _, err = o.Raw(sql, mobile, email).QueryRows(&items)
  405. return
  406. }
  407. // 用户阅读记录列表 2023-08-02 优化拆分
  408. func GetCygxArticleHistoryRecordByUserNew(condition string, startSize, pageSize int) (total int, items []*UserInteraction, err error) {
  409. o := orm.NewOrmUsingDB("hz_cygx")
  410. var sql string
  411. sql += `SELECT
  412. art.title,
  413. art.article_id,
  414. art.article_id_md5,
  415. art.publish_date,
  416. art.category_name,
  417. r.create_time,
  418. r.stop_time,
  419. r.source AS source_platform,
  420. '' AS register_platform,
  421. '' AS special_type
  422. FROM
  423. cygx_article_history_record_all AS r
  424. INNER JOIN cygx_article AS art ON art.article_id = r.article_id
  425. WHERE
  426. 1= 1
  427. AND is_del = 0 ` + condition
  428. sql += ` UNION ALL `
  429. sql += ` SELECT
  430. art.title,
  431. art.id AS article_id,
  432. '' AS article_id_md5,
  433. art.publish_time AS publish_date,
  434. '' AS category_name,
  435. r.create_time,
  436. r.stop_time,
  437. r.register_platform AS source_platform,
  438. r.register_platform,
  439. art.type AS special_type
  440. FROM
  441. cygx_yanxuan_special_record AS r
  442. INNER JOIN cygx_yanxuan_special AS art ON art.id = r.yanxuan_special_id
  443. WHERE 1 = 1 ` + condition
  444. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  445. err = o.Raw(totalSql).QueryRow(&total)
  446. if err != nil {
  447. return
  448. }
  449. sql += ` ORDER BY create_time DESC, article_id DESC `
  450. if startSize > 0 || pageSize > 0 {
  451. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  452. }
  453. _, err = o.Raw(sql).QueryRows(&items)
  454. return
  455. }
  456. // 收藏列表数量
  457. func GetCygxArticleCollectCount(uid int) (count int, err error) {
  458. o := orm.NewOrmUsingDB("hz_cygx")
  459. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_article_collect as r INNER JOIN cygx_article AS art ON art.article_id = r.article_id WHERE user_id = ? `
  460. err = o.Raw(sqlCount, uid).QueryRow(&count)
  461. return
  462. }
  463. // 收藏列表
  464. func GetCygxArticleCollectByUser(uid, startSize, pageSize int, condition string) (items []*UserInteraction, err error) {
  465. o := orm.NewOrmUsingDB("hz_cygx")
  466. sql := ` SELECT
  467. art.title,
  468. art.article_id,
  469. art.article_id_md5,
  470. art.publish_date,
  471. re.chart_permission_name,
  472. re.chart_permission_id,
  473. r.create_time,
  474. re.match_type_name,
  475. (
  476. SELECT
  477. GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' )
  478. FROM
  479. cygx_industrial_subject AS s
  480. WHERE
  481. s.industrial_subject_id IN ( SELECT industrial_subject_id FROM cygx_industrial_article_group_subject AS sg WHERE sg.article_id = art.article_id )
  482. ) AS subject_name_str,
  483. (
  484. SELECT
  485. GROUP_CONCAT( DISTINCT man.industry_name SEPARATOR '/' )
  486. FROM
  487. cygx_industrial_management AS man
  488. WHERE
  489. man.industrial_management_id IN ( SELECT industrial_management_id FROM cygx_industrial_article_group_management AS man_g WHERE man_g.article_id = art.article_id )
  490. ) AS industry_name
  491. FROM
  492. cygx_article_collect AS r
  493. INNER JOIN cygx_article AS art ON art.article_id = r.article_id
  494. LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two
  495. LEFT JOIN cygx_industrial_article_group_management AS man ON man.article_id = art.article_id
  496. WHERE
  497. user_id = ? ` + condition + ` GROUP BY r.article_id
  498. ORDER BY r.create_time DESC `
  499. if startSize > 0 || pageSize > 0 {
  500. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  501. }
  502. _, err = o.Raw(sql, uid).QueryRows(&items)
  503. return
  504. }
  505. // 关注作者数量
  506. func GetCygArticleDepartmentFollowCount(uid int) (count int, err error) {
  507. o := orm.NewOrmUsingDB("hz_cygx")
  508. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_article_department_follow WHERE user_id = ? AND type = 1 `
  509. err = o.Raw(sqlCount, uid).QueryRow(&count)
  510. return
  511. }
  512. // 关注作者列表
  513. func GetCygArticleDepartmentFollowByUser(uid, startSize, pageSize int) (items []*UserInteraction, err error) {
  514. o := orm.NewOrmUsingDB("hz_cygx")
  515. sql := `SELECT
  516. m.department_id,
  517. m.nick_name,
  518. f.modify_time as create_time,
  519. m.department_id,
  520. i.industry_name,
  521. a.title,
  522. a.article_id,
  523. ( SELECT GROUP_CONCAT( DISTINCT i.industry_name SEPARATOR '/' ) FROM cygx_industrial_management AS i WHERE i.industrial_management_id = mg.industrial_management_id ) AS industry_name,
  524. ( SELECT GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' ) FROM cygx_industrial_subject AS s WHERE s.industrial_management_id = i.industrial_management_id ) AS subject_name_str
  525. FROM
  526. cygx_article_department_follow AS f
  527. INNER JOIN cygx_article_department AS m ON m.department_id = f.department_id
  528. LEFT JOIN cygx_article AS a ON a.department_id = m.department_id
  529. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  530. LEFT JOIN cygx_industrial_management AS i ON i.industrial_management_id = mg.industrial_management_id
  531. WHERE f.user_id = ? AND f.type = 1 GROUP BY m.department_id
  532. ORDER BY f.create_time DESC LIMIT ?,? `
  533. _, err = o.Raw(sql, uid, startSize, pageSize).QueryRows(&items)
  534. return
  535. }
  536. // 用户搜索关键词统计
  537. func GetCygxSearchKeyWordCount(uid int) (count int, err error) {
  538. o := orm.NewOrmUsingDB("hz_cygx")
  539. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_search_key_word WHERE user_id = ? `
  540. err = o.Raw(sqlCount, uid).QueryRow(&count)
  541. return
  542. }
  543. // 用户搜索关键词列表
  544. func GetCygxSearchKeyWordByUser(uid, startSize, pageSize int) (items []*UserInteraction, err error) {
  545. o := orm.NewOrmUsingDB("hz_cygx")
  546. sql := `SELECT
  547. key_word,create_time
  548. FROM
  549. cygx_search_key_word as k
  550. WHERE user_id = ?
  551. ORDER BY k.create_time DESC LIMIT ?,? `
  552. _, err = o.Raw(sql, uid, startSize, pageSize).QueryRows(&items)
  553. return
  554. }
  555. // 用户专项产业调研统计
  556. func GetCygxActivitySpecialTripCount(condition string, pars []interface{}) (count int, err error) {
  557. o := orm.NewOrmUsingDB("hz_cygx")
  558. sqlCount := `SELECT
  559. COUNT( 1 )
  560. FROM
  561. cygx_activity_special_meeting_detail AS h
  562. INNER JOIN cygx_activity_special AS a ON a.activity_id = h.activity_id
  563. WHERE
  564. 1 = 1
  565. AND a.publish_status = 1 AND a.activity_time_end < NOW() ` + condition
  566. err = o.Raw(sqlCount, pars).QueryRow(&count)
  567. return
  568. }
  569. // 用户专项产业调研列表
  570. func GetCygxActivitySpecialTripByUser(uid, startSize, pageSize int) (items []*UserInteraction, err error) {
  571. o := orm.NewOrmUsingDB("hz_cygx")
  572. sql := `SELECT
  573. a.research_theme AS activity_name,
  574. a.chart_permission_name,
  575. a.activity_time_text_by_day AS activity_time_text,
  576. a.city,
  577. a.activity_id,
  578. a.special_type AS activity_type,
  579. h.is_meeting
  580. FROM
  581. cygx_activity_special_meeting_detail AS h
  582. INNER JOIN cygx_activity_special AS a ON a.activity_id = h.activity_id
  583. WHERE
  584. 1 = 1
  585. AND a.publish_status = 1 AND a.activity_time_end < NOW()
  586. AND h.user_id = ?
  587. ORDER BY a.activity_time DESC LIMIT ?,? `
  588. _, err = o.Raw(sql, uid, startSize, pageSize).QueryRows(&items)
  589. return
  590. }
  591. // 用户音视频浏览统计
  592. func GetCygxRoadshowCount(uid int) (count int, err error) {
  593. o := orm.NewOrmUsingDB("hz_cygx")
  594. sqlCount := `SELECT
  595. COUNT( 1 ) total
  596. FROM
  597. (
  598. SELECT
  599. ""
  600. FROM
  601. cygx_micro_roadshow_video_history AS r
  602. INNER JOIN cygx_micro_roadshow_video AS v ON r.video_id = v.video_id
  603. WHERE
  604. r.user_id = ? UNION ALL
  605. SELECT
  606. ""
  607. FROM
  608. cygx_activity_video_history AS r
  609. INNER JOIN cygx_activity_video AS v ON r.video_id = v.video_id
  610. WHERE
  611. r.user_id = ? UNION ALL
  612. SELECT
  613. ""
  614. FROM
  615. cygx_activity_voice_history AS r
  616. INNER JOIN cygx_activity_voice AS v ON r.activity_id = v.activity_id
  617. WHERE
  618. r.user_id = ?
  619. )z `
  620. err = o.Raw(sqlCount, uid, uid, uid).QueryRow(&count)
  621. return
  622. }
  623. // 用户专项产业调研列表
  624. func GetCygxRoadshowByUser(uid, startSize, pageSize int) (items []*UserInteraction, err error) {
  625. o := orm.NewOrmUsingDB("hz_cygx")
  626. sql := `SELECT
  627. v.video_name AS media_title,
  628. r.create_time,
  629. "逻辑解析" AS file_type
  630. FROM
  631. cygx_micro_roadshow_video_history AS r
  632. INNER JOIN cygx_micro_roadshow_video AS v ON r.video_id = v.video_id
  633. WHERE
  634. r.user_id = ? UNION ALL
  635. SELECT
  636. v.video_name AS media_title,
  637. r.create_time,
  638. "路演回放" AS file_type
  639. FROM
  640. cygx_activity_video_history AS r
  641. INNER JOIN cygx_activity_video AS v ON r.video_id = v.video_id
  642. WHERE
  643. r.user_id = ? UNION ALL
  644. SELECT
  645. v.voice_name AS media_title,
  646. r.create_time,
  647. "路演回放" AS file_type
  648. FROM
  649. cygx_activity_voice_history AS r
  650. INNER JOIN cygx_activity_voice AS v ON r.activity_id = v.activity_id
  651. WHERE
  652. r.user_id = ?
  653. ORDER BY create_time DESC LIMIT ?,? `
  654. _, err = o.Raw(sql, uid, uid, uid, startSize, pageSize).QueryRows(&items)
  655. return
  656. }
  657. // 线上已到会列表
  658. func GetAttendanceDetailListByUser(isMeeting int, mobile string, startSize, pageSize int) (item []*UserInteraction, err error) {
  659. o := orm.NewOrmUsingDB("hz_cygx")
  660. sql := `SELECT
  661. s.signup_type,
  662. a.activity_name,
  663. a.chart_permission_name,
  664. a.activity_type_name,
  665. a.label,
  666. a.activity_time,
  667. d.first_meeting_time,
  668. d.last_meeting_time,
  669. d.meeting_type_str,
  670. d.meeting_authentication,
  671. d.meeting_status_str,
  672. d.duration
  673. FROM
  674. cygx_activity_signup AS s
  675. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  676. INNER JOIN cygx_activity_attendance_detail AS d ON d.activity_id = s.activity_id
  677. INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
  678. WHERE
  679. 1 = 1
  680. AND s.do_fail_type = 0
  681. AND s.is_cancel = 0
  682. AND s.is_meeting = ?
  683. AND s.mobile = ?
  684. AND a.is_submit_meeting = 1
  685. AND t.activity_type = 1
  686. GROUP BY
  687. a.activity_id
  688. ORDER BY
  689. a.activity_time DESC
  690. LIMIT ?,?`
  691. _, err = o.Raw(sql, isMeeting, mobile, startSize, pageSize).QueryRows(&item)
  692. return
  693. }
  694. // 线上未来到会列表
  695. func GetAttendanceDetailListNoMeetingByUser(isMeeting int, mobile string, startSize, pageSize int) (item []*UserInteraction, err error) {
  696. o := orm.NewOrmUsingDB("hz_cygx")
  697. sql := `SELECT
  698. s.signup_type,
  699. a.activity_name,
  700. a.chart_permission_name,
  701. a.activity_type_name,
  702. a.label,
  703. a.activity_time,
  704. ( SELECT COUNT( 1 ) FROM cygx_activity_meeting_reminder AS rm WHERE rm.activity_id = s.activity_id AND rm.mobile = s.mobile ) AS reminder_num
  705. FROM
  706. cygx_activity_signup AS s
  707. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  708. INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
  709. WHERE
  710. 1 = 1
  711. AND s.do_fail_type = 0
  712. AND s.is_cancel = 0
  713. AND s.is_meeting = ?
  714. AND s.mobile = ?
  715. AND a.is_submit_meeting = 1
  716. AND t.activity_type = 1
  717. GROUP BY
  718. a.activity_id
  719. ORDER BY
  720. a.activity_time DESC
  721. LIMIT ?,?`
  722. _, err = o.Raw(sql, isMeeting, mobile, startSize, pageSize).QueryRows(&item)
  723. return
  724. }
  725. // 用户参会统计
  726. func GetAttendanceDetaiCount(mobile string, meetType, isMeeting int) (count int, err error) {
  727. o := orm.NewOrmUsingDB("hz_cygx")
  728. sqlCount := ` SELECT
  729. COUNT( DISTINCT a.activity_id ) as count
  730. FROM
  731. cygx_activity_signup AS s
  732. INNER JOIN cygx_activity as a ON a.activity_id = s.activity_id
  733. INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
  734. WHERE
  735. mobile = ?
  736. AND is_meeting =?
  737. AND s.do_fail_type = 0
  738. AND a.is_submit_meeting = 1 `
  739. if meetType == 1 {
  740. sqlCount += ` AND t.activity_type = 1 `
  741. } else {
  742. sqlCount += ` AND t.activity_type = 0 `
  743. }
  744. err = o.Raw(sqlCount, mobile, isMeeting).QueryRow(&count)
  745. return
  746. }
  747. // 线下已到会列表
  748. func GetAttendanceOfflineListByUser(isMeeting int, mobile string, startSize, pageSize int) (item []*UserInteraction, err error) {
  749. o := orm.NewOrmUsingDB("hz_cygx")
  750. sql := `SELECT
  751. a.activity_name,
  752. a.chart_permission_name,
  753. a.activity_type_name,
  754. a.label,
  755. a.activity_time
  756. FROM
  757. cygx_activity_signup AS s
  758. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  759. INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
  760. WHERE
  761. 1 = 1
  762. AND s.do_fail_type = 0
  763. AND s.is_cancel = 0
  764. AND s.is_meeting = ?
  765. AND s.mobile = ?
  766. AND a.is_submit_meeting = 1
  767. AND t.activity_type = 0
  768. GROUP BY
  769. a.activity_id
  770. ORDER BY
  771. a.activity_time DESC
  772. LIMIT ?,?`
  773. _, err = o.Raw(sql, isMeeting, mobile, startSize, pageSize).QueryRows(&item)
  774. return
  775. }
  776. // 获取用户参会记录数量
  777. func GetActivityMeetByUserCount(condition string) (count int, err error) {
  778. o := orm.NewOrmUsingDB("hz_cygx")
  779. sqlCount := ` SELECT
  780. COUNT( DISTINCT a.activity_id ) as count
  781. FROM
  782. cygx_activity_signup_detail AS s
  783. INNER JOIN cygx_activity as a ON a.activity_id = s.activity_id
  784. INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
  785. WHERE
  786. 1=1
  787. AND s.do_fail_type = 0 `
  788. if condition != "" {
  789. sqlCount += condition
  790. }
  791. err = o.Raw(sqlCount).QueryRow(&count)
  792. return
  793. }
  794. // 获取用户参会记录
  795. func GetActivityMeetByUser(condition string, startSize, pageSize int) (item []*UserInteraction, err error) {
  796. o := orm.NewOrmUsingDB("hz_cygx")
  797. sql := `SELECT
  798. t.activity_type,
  799. s.signup_type,
  800. s.is_meeting,
  801. a.activity_name,
  802. a.chart_permission_name,
  803. a.activity_type_name,
  804. a.label,
  805. a.activity_time,
  806. s.first_meeting_time,
  807. s.last_meeting_time,
  808. s.meeting_type_str,
  809. s.meeting_authentication,
  810. s.meeting_status_str,
  811. s.duration
  812. FROM
  813. cygx_activity_signup_detail AS s
  814. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  815. INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
  816. WHERE
  817. 1 = 1
  818. AND s.do_fail_type = 0 ` + condition + `
  819. GROUP BY
  820. s.activity_id,s.outbound_mobile
  821. ORDER BY
  822. a.activity_time DESC `
  823. if startSize > 0 || pageSize > 0 {
  824. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  825. }
  826. _, err = o.Raw(sql).QueryRows(&item)
  827. return
  828. }
  829. // 获取用户参会记录
  830. func GetActivitySpecialMeetByUser(condition string, startSize, pageSize int) (item []*UserInteraction, err error) {
  831. o := orm.NewOrmUsingDB("hz_cygx")
  832. sql := `SELECT
  833. a.activity_id,
  834. a.research_theme AS activity_name,
  835. a.chart_permission_name,
  836. special_type AS activity_type,
  837. a.activity_time,
  838. a.activity_time_text_by_day AS activity_time_text
  839. FROM
  840. cygx_activity_special_meeting_detail AS s
  841. INNER JOIN cygx_activity_special AS a ON a.activity_id = s.activity_id
  842. WHERE
  843. 1 = 1 ` + condition + `
  844. GROUP BY
  845. s.activity_id,
  846. s.mobile
  847. ORDER BY
  848. a.activity_time DESC `
  849. if startSize > 0 || pageSize > 0 {
  850. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  851. }
  852. _, err = o.Raw(sql).QueryRows(&item)
  853. return
  854. }
  855. type GetUserInteractionTableCountResp struct {
  856. HistoryNum int `description:"报告阅读"`
  857. CountNum int `description:"报告收藏"`
  858. IndustryFllowNum int `description:"产业关注"`
  859. DepartmentFollowNum int `description:"作者关注"`
  860. KeyWordNum int `description:"搜索关键词"`
  861. OnLineNum int `description:"线上互动活动"`
  862. OfficeNum int `description:"线下互动活动"`
  863. ActivityNum int `description:"活动数量"`
  864. ChartNum int `description:"图表数量"`
  865. TripNum int `description:"图表数量"`
  866. RoadshowVideoNum int `description:"产业视频播放量"`
  867. ActivityVideoNum int `description:"活动视频播放量"`
  868. ActivityVoiceNum int `description:"活动音频播放量"`
  869. TagNum int `description:"首页标签点击量"`
  870. YanxuanSpecialNum int `description:"研选专栏阅读数量"`
  871. }
  872. // 用户互动总数统计
  873. func GetUserInteractionTableCount(uid int) (item *GetUserInteractionTableCountResp, err error) {
  874. o := orm.NewOrmUsingDB("hz_cygx")
  875. sql := `SELECT
  876. ( SELECT COUNT( 1 ) FROM cygx_article_history_record_all AS h INNER JOIN cygx_article as art ON art.article_id = h.article_id WHERE h.user_id = ? AND h.is_del = 0 ) AS history_num,
  877. ( SELECT COUNT( 1 ) FROM cygx_article_collect AS h WHERE h.user_id = ? AND h.article_id > 0 ) AS count_num,
  878. ( SELECT COUNT( 1 ) FROM cygx_chart_collect AS h INNER JOIN cygx_chart_all AS a ON h.chart_id = a.chart_id WHERE h.user_id = ? ) AS chart_num,
  879. ( SELECT COUNT( 1 ) FROM cygx_industry_fllow AS h WHERE h.user_id = ? AND h.type = 1 ) AS industry_fllow_num,
  880. ( SELECT COUNT( 1 ) FROM cygx_article_department_follow AS h WHERE h.user_id = ? AND h.type = 1 ) AS department_follow_num,
  881. ( SELECT COUNT( 1 ) FROM cygx_search_key_word AS h WHERE h.user_id = ? ) AS key_word_num,
  882. ( SELECT COUNT( DISTINCT a.activity_id ) as count FROM cygx_activity_signup_detail AS h INNER JOIN cygx_activity as a ON a.activity_id = h.activity_id INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id WHERE h.user_id = ?
  883. AND t.activity_type=1 AND h.do_fail_type = 0 ) AS on_line_num,
  884. ( SELECT COUNT( DISTINCT a.activity_id ) as count FROM cygx_activity_signup_detail AS h INNER JOIN cygx_activity as a ON a.activity_id = h.activity_id INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id WHERE h.user_id = ?
  885. AND t.activity_type = 0 AND h.do_fail_type = 0 ) AS office_num,
  886. ( SELECT COUNT( 1 ) FROM cygx_activity_special_meeting_detail AS h INNER JOIN cygx_activity_special AS a ON a.activity_id = h.activity_id WHERE h.user_id = ? AND a.publish_status = 1 AND a.activity_time_end < NOW()) AS trip_num,
  887. ( SELECT COUNT( 1 ) FROM cygx_micro_roadshow_video_history AS h INNER JOIN cygx_micro_roadshow_video as v ON v.video_id = h.video_id WHERE h.user_id = ? ) AS roadshow_video_num,
  888. ( SELECT COUNT( 1 ) FROM cygx_activity_video_history AS h INNER JOIN cygx_activity_video as v ON v.video_id = h.video_id WHERE h.user_id = ? ) AS activity_video_num,
  889. ( SELECT COUNT( 1 ) FROM cygx_activity_voice_history AS h INNER JOIN cygx_activity_voice as v ON v.activity_id = h.activity_id WHERE h.user_id = ? ) AS activity_voice_num,
  890. ( SELECT COUNT(1) FROM cygx_tag_history as h INNER JOIN cygx_tag AS b ON h.tag_id = b.tag_id WHERE h.user_id = ? ) AS tag_num,
  891. ( SELECT COUNT(1) FROM cygx_yanxuan_special_record as h INNER JOIN cygx_yanxuan_special AS b ON h.yanxuan_special_id = b.id WHERE h.user_id = ? ) AS yanxuan_special_num
  892. FROM dual `
  893. err = o.Raw(sql, uid, uid, uid, uid, uid, uid, uid, uid, uid, uid, uid, uid, uid, uid).QueryRow(&item)
  894. return
  895. }
  896. // 根据时间获取用户互动总数统计
  897. func GetUserInteractionTableCountBytime(uid int, startDate, endDate string) (item *GetUserInteractionTableCountResp, err error) {
  898. o := orm.NewOrm()
  899. sql := `SELECT
  900. ( SELECT COUNT( 1 ) FROM cygx_article_history_record_all AS h INNER JOIN cygx_article as art ON art.article_id = h.article_id WHERE h.mobile = u.mobile AND h.is_del = 0 AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' OR ( h.email = u.email AND h.email <>'' AND h.is_del = 0 AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' ) ) AS history_num,
  901. ( SELECT COUNT( 1 ) FROM cygx_article_collect AS h WHERE h.user_id = u.user_id AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' ) AS count_num,
  902. ( SELECT COUNT( 1 ) FROM cygx_chart_collect AS h WHERE h.user_id = u.user_id AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' ) AS chart_num,
  903. ( SELECT COUNT( 1 ) FROM cygx_industry_fllow AS h WHERE h.user_id = u.user_id AND h.type = 1 AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' ) AS industry_fllow_num,
  904. ( SELECT COUNT( 1 ) FROM cygx_article_department_follow AS h WHERE h.user_id = u.user_id AND h.type = 1 AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' ) AS department_follow_num,
  905. ( SELECT COUNT( 1 ) FROM cygx_search_key_word AS h WHERE h.user_id = u.user_id AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' ) AS key_word_num,
  906. ( SELECT COUNT( DISTINCT a.activity_id ) as count FROM cygx_activity_signup AS h INNER JOIN cygx_activity as a ON a.activity_id = h.activity_id INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id WHERE h.mobile = u.mobile
  907. AND a.is_submit_meeting = 1 AND t.activity_type=1 AND h.do_fail_type = 0 AND a.activity_time BETWEEN '` + startDate + `'AND '` + endDate + `' ) AS on_line_num,
  908. ( SELECT COUNT( DISTINCT a.activity_id ) as count FROM cygx_activity_signup AS h INNER JOIN cygx_activity as a ON a.activity_id = h.activity_id INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id WHERE h.mobile = u.mobile
  909. AND a.is_submit_meeting = 1 AND t.activity_type = 0 AND h.do_fail_type = 0 AND a.activity_time BETWEEN '` + startDate + `'AND '` + endDate + `') AS office_num
  910. FROM
  911. wx_user as u
  912. WHERE
  913. u.user_id = ?`
  914. err = o.Raw(sql, uid).QueryRow(&item)
  915. return
  916. }
  917. type ArticlePvCountResp struct {
  918. ArticleId int `description:"文章ID"`
  919. Pv int `description:"Pv"`
  920. }
  921. // 阅读记录
  922. func GetArticlePvCount(mobile, email, dateTime string) (item []*ArticlePvCountResp, err error) {
  923. o := orm.NewOrmUsingDB("hz_cygx")
  924. sql := `SELECT
  925. article_id,
  926. COUNT(article_id) as pv
  927. FROM
  928. cygx_article_history_record_all as h
  929. WHERE
  930. mobile = ?
  931. AND create_time >= ?
  932. AND is_del = 0
  933. OR ( email = ? AND email <>'' AND create_time >= ? AND is_del = 0 )
  934. GROUP BY article_id `
  935. _, err = o.Raw(sql, mobile, dateTime, email, dateTime).QueryRows(&item)
  936. return
  937. }
  938. type ArticleIndustryNameResp struct {
  939. ArticleId int `description:"文章ID"`
  940. IndustryName string `description:"产业名称"`
  941. SubjectName string `description:"标的名称"`
  942. }
  943. // 产业名称
  944. func GetArticleGroupyIndustryName(articleIds string) (item []*ArticleIndustryNameResp, err error) {
  945. o := orm.NewOrmUsingDB("hz_cygx")
  946. sql := `SELECT
  947. art.article_id,
  948. (
  949. SELECT
  950. GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' )
  951. FROM
  952. cygx_industrial_subject AS s
  953. WHERE
  954. s.industrial_subject_id IN ( SELECT industrial_subject_id FROM cygx_industrial_article_group_subject AS sg WHERE sg.article_id = art.article_id )
  955. ) AS subject_name,
  956. (
  957. SELECT
  958. GROUP_CONCAT( DISTINCT man.industry_name SEPARATOR '/' )
  959. FROM
  960. cygx_industrial_management AS man
  961. WHERE
  962. man.industrial_management_id IN ( SELECT industrial_management_id FROM cygx_industrial_article_group_management AS man_g WHERE man_g.article_id = art.article_id )
  963. ) AS industry_name
  964. FROM
  965. cygx_article_history_record_all AS r
  966. INNER JOIN cygx_article AS art ON art.article_id = r.article_id
  967. LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two
  968. LEFT JOIN cygx_industrial_article_group_management AS man ON man.article_id = art.article_id
  969. WHERE
  970. art.article_id IN ( ` + articleIds + `) GROUP BY art.article_id `
  971. _, err = o.Raw(sql).QueryRows(&item)
  972. return
  973. }
  974. // 标的名称
  975. func GetArticleGroupySubjectName(articleIds string) (item []*ArticleIndustryNameResp, err error) {
  976. o := orm.NewOrmUsingDB("hz_cygx")
  977. sql := `SELECT
  978. article_id,
  979. subject_name
  980. FROM
  981. cygx_industrial_article_group_subject AS mg
  982. INNER JOIN cygx_industrial_subject AS m ON m.industrial_subject_id = mg.industrial_subject_id
  983. WHERE
  984. article_id IN ( ` + articleIds + `)`
  985. _, err = o.Raw(sql).QueryRows(&item)
  986. return
  987. }
  988. type UserLabel struct {
  989. Label string `description:"标签 多个用 , 隔开"`
  990. }
  991. type ActivityLabelCountResp struct {
  992. Label string `description:"标签"`
  993. Pv int `description:"Pv"`
  994. }
  995. // 活动标签记录(我的日程)
  996. func GetActivitySignCount(mobile, dateTime string) (item []*ActivityLabelCountResp, err error) {
  997. o := orm.NewOrmUsingDB("hz_cygx")
  998. sql := `SELECT
  999. label ,
  1000. COUNT( label ) AS pv
  1001. FROM
  1002. cygx_activity
  1003. WHERE
  1004. activity_id IN ( SELECT activity_id FROM cygx_my_schedule WHERE mobile = ? )
  1005. AND label != ''
  1006. AND activity_time >= ?
  1007. GROUP BY
  1008. label`
  1009. _, err = o.Raw(sql, mobile, dateTime).QueryRows(&item)
  1010. return
  1011. }
  1012. // 活动标签记录(会议提醒)
  1013. func GetActivityMeetingReminder(mobile, dateTime string) (item []*ActivityLabelCountResp, err error) {
  1014. o := orm.NewOrmUsingDB("hz_cygx")
  1015. sql := `SELECT
  1016. label ,
  1017. COUNT( label ) AS pv
  1018. FROM
  1019. cygx_activity
  1020. WHERE
  1021. activity_id IN ( SELECT activity_id FROM cygx_activity_meeting_reminder WHERE mobile = ? )
  1022. AND label != ''
  1023. AND activity_time >= ?
  1024. GROUP BY
  1025. label`
  1026. _, err = o.Raw(sql, mobile, dateTime).QueryRows(&item)
  1027. return
  1028. }
  1029. func GetCygxArticleCollectId(uid int, dateTime string) (articleIds string, err error) {
  1030. sql := `SELECT
  1031. GROUP_CONCAT( DISTINCT article_id SEPARATOR ',' ) AS permission
  1032. FROM
  1033. cygx_article_collect
  1034. WHERE
  1035. user_id = ?
  1036. AND create_time >= ? `
  1037. o := orm.NewOrmUsingDB("hz_cygx")
  1038. err = o.Raw(sql, uid, dateTime).QueryRow(&articleIds)
  1039. return
  1040. }
  1041. // 用户互动量
  1042. type CygxInteractionNumResp struct {
  1043. DateTime string `description:"时间"`
  1044. InteractionNum int `description:"互动量"`
  1045. }
  1046. type CygxCygxInteractionNumRespListResp struct {
  1047. List []*CygxInteractionNumResp
  1048. }
  1049. // 用户互动详情
  1050. type UserInteractionrelevantListResp struct {
  1051. IndustryName string `description:"产业名称"`
  1052. IsFllow bool `description:"是否关注"`
  1053. List []*UserInteraction
  1054. }
  1055. type EsUserInteraction struct {
  1056. Id int `description:"主键ID"`
  1057. ArticleId int `description:"文章id"`
  1058. ArticleType int `description:"文章类型 1:查研观向, 2:策略平台"`
  1059. Title string `description:"标题"`
  1060. PublishDate string `description:"发布时间"`
  1061. CreateTime string `description:"创建时间"`
  1062. StopTime string `description:"阅读停留时间"`
  1063. RealName string `description:"姓名"`
  1064. CompanyName string `description:"公司名称"`
  1065. CompanyId int `description:"公司ID"`
  1066. SellerName string `description:"所属销售"`
  1067. SellerId int `description:"所属销售ID"`
  1068. Mobile string `description:"手机号"`
  1069. Email string `description:"邮箱"`
  1070. UserId int `description:"用户ID"`
  1071. UserArticleHistoryNum int `description:"用户阅读数量"`
  1072. CompanyArticleHistoryNum int `description:"机构阅读数量"`
  1073. }
  1074. func GetCompanyIdsCondition(ondition string) (companyIds string, err error) {
  1075. sql := ondition
  1076. o := orm.NewOrm()
  1077. err = o.Raw(sql).QueryRow(&companyIds)
  1078. return
  1079. }
  1080. type InteractiveList struct {
  1081. TotalMap map[int]int
  1082. EsList []*EsUserInteraction
  1083. ActivityList []*company.CompanyReportRecordGroup
  1084. CollectList []*company.CompanyReportRecordGroup
  1085. IndustryFllowList []*company.CompanyReportRecordGroup
  1086. DepartmentFollowList []*company.CompanyReportRecordGroup
  1087. KeyWordList []*company.CompanyReportRecordGroup
  1088. Chartist []*company.CompanyReportRecordGroup
  1089. }
  1090. func GetAllOverseasRaiEmail() (emails []string, err error) {
  1091. sql := `
  1092. SELECT
  1093. *
  1094. FROM
  1095. (
  1096. SELECT
  1097. wu.email
  1098. FROM
  1099. wx_user AS wu
  1100. INNER JOIN company AS c
  1101. WHERE
  1102. wu.company_id = c.company_id
  1103. AND wu.email <> ""
  1104. AND c.region_type = "海外"
  1105. ) AS a UNION
  1106. (
  1107. SELECT
  1108. wu.email
  1109. FROM
  1110. company_product AS cp
  1111. INNER JOIN wx_user AS wu
  1112. WHERE
  1113. cp.industry_id = 10
  1114. AND cp.product_id = 2
  1115. AND wu.email <> ""
  1116. AND cp.status IN ( "正式", "试用" )
  1117. )`
  1118. o := orm.NewOrm()
  1119. _, err = o.Raw(sql).QueryRows(&emails)
  1120. return
  1121. }