cygx_user.go 61 KB

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