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