cygx_user.go 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310
  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. ArticleNum int // 已发布的文章数量
  340. FansNum int // 粉丝数量
  341. }
  342. // 查研观向图表
  343. type CygxChartResp struct {
  344. Title string `description:"标题"`
  345. PublishDate string `description:"发布时间"`
  346. CreateTime string `description:"创建时间"`
  347. TitleEn string `description:"英文标题 "`
  348. PtagName string `description:"父类名称"`
  349. CtagName string `description:"子类名称"`
  350. PtagNameTwo string `description:"父类名称"`
  351. CtagNameTwo string `description:"子类名称"`
  352. CtagNamePc string `description:"Pc端所有的分类名称"`
  353. BodyHtml string `orm:"column(cover)";description:"图片链接"`
  354. HttpUrl string `orm:"column(iframe)";description:"文章链接跳转地址"`
  355. ChartId int `description:"图表id"`
  356. RealyName string `description:"姓名"`
  357. Mobile string `description:"手机号"`
  358. }
  359. // 获取阅读记录数量
  360. func GetCygxArticleHistoryCount(mobile, email, condition string) (count int, err error) {
  361. o := orm.NewOrmUsingDB("hz_cygx")
  362. 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
  363. err = o.Raw(sqlCount).QueryRow(&count)
  364. return
  365. }
  366. // 阅读记录列表
  367. func GetCygxArticleHistoryRecordByUser(mobile, email, condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
  368. o := orm.NewOrmUsingDB("hz_cygx")
  369. sql := ` SELECT
  370. art.title,
  371. art.article_id,
  372. art.article_id_md5,
  373. art.publish_date,
  374. art.category_name,
  375. re.chart_permission_name,
  376. re.chart_permission_id,
  377. r.create_time,
  378. r.stop_time,
  379. r.source as source_platform,
  380. (
  381. SELECT
  382. GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' )
  383. FROM
  384. cygx_industrial_subject AS s
  385. WHERE
  386. s.industrial_subject_id IN ( SELECT industrial_subject_id FROM cygx_industrial_article_group_subject AS sg WHERE sg.article_id = art.article_id )
  387. ) AS subject_name_str,
  388. (
  389. SELECT
  390. GROUP_CONCAT( DISTINCT man.industry_name SEPARATOR '/' )
  391. FROM
  392. cygx_industrial_management AS man
  393. WHERE
  394. 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 )
  395. ) AS industry_name
  396. FROM
  397. cygx_article_history_record_all AS r
  398. INNER JOIN cygx_article AS art ON art.article_id = r.article_id
  399. LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two
  400. LEFT JOIN cygx_industrial_article_group_management AS man ON man.article_id = art.article_id
  401. WHERE
  402. r.mobile = ? AND is_del = 0 ` + condition + ` OR ( email = ? AND email <>'' AND is_del = 0 ` + condition + ` )
  403. GROUP BY r.id ORDER BY r.create_time DESC `
  404. if startSize > 0 || pageSize > 0 {
  405. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  406. }
  407. _, err = o.Raw(sql, mobile, email).QueryRows(&items)
  408. return
  409. }
  410. // 用户阅读记录列表 2023-08-02 优化拆分
  411. func GetCygxArticleHistoryRecordByUserNew(condition string, startSize, pageSize int) (total int, items []*UserInteraction, err error) {
  412. o := orm.NewOrmUsingDB("hz_cygx")
  413. var sql string
  414. sql += `SELECT
  415. art.title,
  416. art.article_id,
  417. art.article_id_md5,
  418. art.publish_date,
  419. art.category_name,
  420. r.create_time,
  421. r.stop_time,
  422. r.source AS source_platform,
  423. '' AS register_platform,
  424. '' AS special_type
  425. FROM
  426. cygx_article_history_record_all AS r
  427. INNER JOIN cygx_article AS art ON art.article_id = r.article_id
  428. WHERE
  429. 1= 1
  430. AND is_del = 0 ` + condition
  431. //sql += ` UNION ALL `
  432. //sql += ` SELECT
  433. // art.title,
  434. // art.id AS article_id,
  435. // '' AS article_id_md5,
  436. // art.publish_time AS publish_date,
  437. // '' AS category_name,
  438. // r.create_time,
  439. // r.stop_time,
  440. // r.register_platform AS source_platform,
  441. // r.register_platform,
  442. // art.type AS special_type
  443. // FROM
  444. // cygx_yanxuan_special_record AS r
  445. // INNER JOIN cygx_yanxuan_special AS art ON art.id = r.yanxuan_special_id
  446. // WHERE 1 = 1 ` + condition
  447. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  448. err = o.Raw(totalSql).QueryRow(&total)
  449. if err != nil {
  450. return
  451. }
  452. sql += ` ORDER BY create_time DESC, article_id DESC `
  453. if startSize > 0 || pageSize > 0 {
  454. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  455. }
  456. _, err = o.Raw(sql).QueryRows(&items)
  457. return
  458. }
  459. // 用户阅读记录列表
  460. func GetCygxYanxuaSspecialHistoryRecordByUser(condition string, startSize, pageSize int) (total int, items []*UserInteraction, err error) {
  461. o := orm.NewOrmUsingDB("hz_cygx")
  462. var sql string
  463. sql += ` SELECT
  464. art.title,
  465. art.id AS article_id,
  466. art.publish_time AS publish_date,
  467. r.create_time,
  468. r.stop_time,
  469. r.register_platform AS source_platform,
  470. art.type AS special_type,
  471. art.industry_tags as industry_name
  472. FROM
  473. cygx_yanxuan_special_record AS r
  474. INNER JOIN cygx_yanxuan_special AS art ON art.id = r.yanxuan_special_id
  475. WHERE 1 = 1 ` + condition
  476. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  477. err = o.Raw(totalSql).QueryRow(&total)
  478. if err != nil {
  479. return
  480. }
  481. sql += ` ORDER BY create_time DESC, article_id DESC `
  482. if startSize > 0 || pageSize > 0 {
  483. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  484. }
  485. _, err = o.Raw(sql).QueryRows(&items)
  486. return
  487. }
  488. // 用户阅读记录列表
  489. func GetCygxYanxuanSpecialCollectByUser(condition string, startSize, pageSize int) (total int, items []*UserInteraction, err error) {
  490. o := orm.NewOrmUsingDB("hz_cygx")
  491. var sql string
  492. sql += ` SELECT
  493. art.title,
  494. art.id AS article_id,
  495. art.publish_time AS publish_date,
  496. r.create_time,
  497. r.register_platform AS source_platform,
  498. art.type AS special_type,
  499. art.industry_tags as industry_name
  500. FROM
  501. cygx_yanxuan_special_collect AS r
  502. INNER JOIN cygx_yanxuan_special AS art ON art.id = r.yanxuan_special_id
  503. WHERE 1 = 1 ` + condition
  504. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  505. err = o.Raw(totalSql).QueryRow(&total)
  506. if err != nil {
  507. return
  508. }
  509. sql += ` ORDER BY create_time DESC, article_id DESC `
  510. if startSize > 0 || pageSize > 0 {
  511. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  512. }
  513. _, err = o.Raw(sql).QueryRows(&items)
  514. return
  515. }
  516. // 用户阅读记录列表
  517. func GetCygxYanxuanSpecialAuthorByUser(condition string, startSize, pageSize int) (total int, items []*UserInteraction, err error) {
  518. o := orm.NewOrmUsingDB("hz_cygx")
  519. var sql string
  520. sql += ` SELECT
  521. art.special_name as title,
  522. art.id AS department_id,
  523. art.nick_name,
  524. art.article_num,
  525. art.fans_num,
  526. art.company_id,
  527. art.company_name,
  528. art.mobile_init as mobile,
  529. r.create_time,
  530. r.register_platform AS source_platform
  531. FROM
  532. cygx_yanxuan_special_follow AS r
  533. INNER JOIN cygx_yanxuan_special_author AS art ON art.user_id = r.follow_user_id
  534. WHERE 1 = 1 ` + condition
  535. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  536. err = o.Raw(totalSql).QueryRow(&total)
  537. if err != nil {
  538. return
  539. }
  540. sql += ` ORDER BY create_time DESC, department_id DESC `
  541. if startSize > 0 || pageSize > 0 {
  542. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  543. }
  544. _, err = o.Raw(sql).QueryRows(&items)
  545. return
  546. }
  547. // 收藏列表数量
  548. func GetCygxArticleCollectCount(uid int, condition string) (count int, err error) {
  549. o := orm.NewOrmUsingDB("hz_cygx")
  550. 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
  551. err = o.Raw(sqlCount, uid).QueryRow(&count)
  552. return
  553. }
  554. // 收藏列表
  555. func GetCygxArticleCollectByUser(uid, startSize, pageSize int, condition string) (items []*UserInteraction, err error) {
  556. o := orm.NewOrmUsingDB("hz_cygx")
  557. sql := ` SELECT
  558. art.title,
  559. art.article_id,
  560. art.article_id_md5,
  561. art.publish_date,
  562. re.chart_permission_name,
  563. re.chart_permission_id,
  564. r.create_time,
  565. re.match_type_name,
  566. (
  567. SELECT
  568. GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' )
  569. FROM
  570. cygx_industrial_subject AS s
  571. WHERE
  572. s.industrial_subject_id IN ( SELECT industrial_subject_id FROM cygx_industrial_article_group_subject AS sg WHERE sg.article_id = art.article_id )
  573. ) AS subject_name_str,
  574. (
  575. SELECT
  576. GROUP_CONCAT( DISTINCT man.industry_name SEPARATOR '/' )
  577. FROM
  578. cygx_industrial_management AS man
  579. WHERE
  580. 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 )
  581. ) AS industry_name
  582. FROM
  583. cygx_article_collect AS r
  584. INNER JOIN cygx_article AS art ON art.article_id = r.article_id
  585. LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two
  586. LEFT JOIN cygx_industrial_article_group_management AS man ON man.article_id = art.article_id
  587. WHERE
  588. user_id = ? ` + condition + ` GROUP BY r.article_id
  589. ORDER BY r.create_time DESC `
  590. if startSize > 0 || pageSize > 0 {
  591. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  592. }
  593. _, err = o.Raw(sql, uid).QueryRows(&items)
  594. return
  595. }
  596. // 关注作者数量
  597. func GetCygArticleDepartmentFollowCount(uid int) (count int, err error) {
  598. o := orm.NewOrmUsingDB("hz_cygx")
  599. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_article_department_follow WHERE user_id = ? AND type = 1 `
  600. err = o.Raw(sqlCount, uid).QueryRow(&count)
  601. return
  602. }
  603. // 关注作者列表
  604. func GetCygArticleDepartmentFollowByUser(uid, startSize, pageSize int) (items []*UserInteraction, err error) {
  605. o := orm.NewOrmUsingDB("hz_cygx")
  606. sql := `SELECT
  607. m.department_id,
  608. m.nick_name,
  609. f.modify_time as create_time,
  610. m.department_id,
  611. i.industry_name,
  612. a.title,
  613. a.article_id,
  614. ( 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,
  615. ( 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
  616. FROM
  617. cygx_article_department_follow AS f
  618. INNER JOIN cygx_article_department AS m ON m.department_id = f.department_id
  619. LEFT JOIN cygx_article AS a ON a.department_id = m.department_id
  620. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  621. LEFT JOIN cygx_industrial_management AS i ON i.industrial_management_id = mg.industrial_management_id
  622. WHERE f.user_id = ? AND f.type = 1 GROUP BY m.department_id
  623. ORDER BY f.create_time DESC LIMIT ?,? `
  624. _, err = o.Raw(sql, uid, startSize, pageSize).QueryRows(&items)
  625. return
  626. }
  627. // 用户搜索关键词统计
  628. func GetCygxSearchKeyWordCount(uid int) (count int, err error) {
  629. o := orm.NewOrmUsingDB("hz_cygx")
  630. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_search_key_word WHERE user_id = ? `
  631. err = o.Raw(sqlCount, uid).QueryRow(&count)
  632. return
  633. }
  634. // 用户搜索关键词列表
  635. func GetCygxSearchKeyWordByUser(uid, startSize, pageSize int) (items []*UserInteraction, err error) {
  636. o := orm.NewOrmUsingDB("hz_cygx")
  637. sql := `SELECT
  638. key_word,create_time
  639. FROM
  640. cygx_search_key_word as k
  641. WHERE user_id = ?
  642. ORDER BY k.create_time DESC LIMIT ?,? `
  643. _, err = o.Raw(sql, uid, startSize, pageSize).QueryRows(&items)
  644. return
  645. }
  646. // 用户专项产业调研统计
  647. func GetCygxActivitySpecialTripCount(condition string, pars []interface{}) (count int, err error) {
  648. o := orm.NewOrmUsingDB("hz_cygx")
  649. sqlCount := `SELECT
  650. COUNT( 1 )
  651. FROM
  652. cygx_activity_special_meeting_detail AS h
  653. INNER JOIN cygx_activity_special AS a ON a.activity_id = h.activity_id
  654. WHERE
  655. 1 = 1
  656. AND a.publish_status = 1 AND a.activity_time_end < NOW() ` + condition
  657. err = o.Raw(sqlCount, pars).QueryRow(&count)
  658. return
  659. }
  660. // 用户专项产业调研列表
  661. func GetCygxActivitySpecialTripByUser(uid, startSize, pageSize int) (items []*UserInteraction, err error) {
  662. o := orm.NewOrmUsingDB("hz_cygx")
  663. sql := `SELECT
  664. a.research_theme AS activity_name,
  665. a.chart_permission_name,
  666. a.activity_time_text_by_day AS activity_time_text,
  667. a.city,
  668. a.activity_id,
  669. a.special_type AS activity_type,
  670. h.is_meeting
  671. FROM
  672. cygx_activity_special_meeting_detail AS h
  673. INNER JOIN cygx_activity_special AS a ON a.activity_id = h.activity_id
  674. WHERE
  675. 1 = 1
  676. AND a.publish_status = 1 AND a.activity_time_end < NOW()
  677. AND h.user_id = ?
  678. ORDER BY a.activity_time DESC LIMIT ?,? `
  679. _, err = o.Raw(sql, uid, startSize, pageSize).QueryRows(&items)
  680. return
  681. }
  682. // 用户音视频浏览统计
  683. func GetCygxRoadshowCount(uid int) (count int, err error) {
  684. o := orm.NewOrmUsingDB("hz_cygx")
  685. sqlCount := `SELECT
  686. COUNT( 1 ) total
  687. FROM
  688. (
  689. SELECT
  690. ""
  691. FROM
  692. cygx_micro_roadshow_video_history AS r
  693. INNER JOIN cygx_micro_roadshow_video AS v ON r.video_id = v.video_id
  694. WHERE
  695. r.user_id = ? UNION ALL
  696. SELECT
  697. ""
  698. FROM
  699. cygx_activity_video_history AS r
  700. INNER JOIN cygx_activity_video AS v ON r.video_id = v.video_id
  701. WHERE
  702. r.user_id = ? UNION ALL
  703. SELECT
  704. ""
  705. FROM
  706. cygx_activity_voice_history AS r
  707. INNER JOIN cygx_activity_voice AS v ON r.activity_id = v.activity_id
  708. WHERE
  709. r.user_id = ?
  710. )z `
  711. err = o.Raw(sqlCount, uid, uid, uid).QueryRow(&count)
  712. return
  713. }
  714. // 用户专项产业调研列表
  715. func GetCygxRoadshowByUser(uid, startSize, pageSize int) (items []*UserInteraction, err error) {
  716. o := orm.NewOrmUsingDB("hz_cygx")
  717. sql := `SELECT
  718. v.video_name AS media_title,
  719. r.create_time,
  720. "逻辑解析" AS file_type
  721. FROM
  722. cygx_micro_roadshow_video_history AS r
  723. INNER JOIN cygx_micro_roadshow_video AS v ON r.video_id = v.video_id
  724. WHERE
  725. r.user_id = ? UNION ALL
  726. SELECT
  727. v.video_name AS media_title,
  728. r.create_time,
  729. "路演回放" AS file_type
  730. FROM
  731. cygx_activity_video_history AS r
  732. INNER JOIN cygx_activity_video AS v ON r.video_id = v.video_id
  733. WHERE
  734. r.user_id = ? UNION ALL
  735. SELECT
  736. v.voice_name AS media_title,
  737. r.create_time,
  738. "路演回放" AS file_type
  739. FROM
  740. cygx_activity_voice_history AS r
  741. INNER JOIN cygx_activity_voice AS v ON r.activity_id = v.activity_id
  742. WHERE
  743. r.user_id = ?
  744. ORDER BY create_time DESC LIMIT ?,? `
  745. _, err = o.Raw(sql, uid, uid, uid, startSize, pageSize).QueryRows(&items)
  746. return
  747. }
  748. // 线上已到会列表
  749. func GetAttendanceDetailListByUser(isMeeting int, mobile string, startSize, pageSize int) (item []*UserInteraction, err error) {
  750. o := orm.NewOrmUsingDB("hz_cygx")
  751. sql := `SELECT
  752. s.signup_type,
  753. a.activity_name,
  754. a.chart_permission_name,
  755. a.activity_type_name,
  756. a.label,
  757. a.activity_time,
  758. d.first_meeting_time,
  759. d.last_meeting_time,
  760. d.meeting_type_str,
  761. d.meeting_authentication,
  762. d.meeting_status_str,
  763. d.duration
  764. FROM
  765. cygx_activity_signup AS s
  766. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  767. INNER JOIN cygx_activity_attendance_detail AS d ON d.activity_id = s.activity_id
  768. INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
  769. WHERE
  770. 1 = 1
  771. AND s.do_fail_type = 0
  772. AND s.is_cancel = 0
  773. AND s.is_meeting = ?
  774. AND s.mobile = ?
  775. AND a.is_submit_meeting = 1
  776. AND t.activity_type = 1
  777. GROUP BY
  778. a.activity_id
  779. ORDER BY
  780. a.activity_time DESC
  781. LIMIT ?,?`
  782. _, err = o.Raw(sql, isMeeting, mobile, startSize, pageSize).QueryRows(&item)
  783. return
  784. }
  785. // 线上未来到会列表
  786. func GetAttendanceDetailListNoMeetingByUser(isMeeting int, mobile string, startSize, pageSize int) (item []*UserInteraction, err error) {
  787. o := orm.NewOrmUsingDB("hz_cygx")
  788. sql := `SELECT
  789. s.signup_type,
  790. a.activity_name,
  791. a.chart_permission_name,
  792. a.activity_type_name,
  793. a.label,
  794. a.activity_time,
  795. ( 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
  796. FROM
  797. cygx_activity_signup AS s
  798. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  799. INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
  800. WHERE
  801. 1 = 1
  802. AND s.do_fail_type = 0
  803. AND s.is_cancel = 0
  804. AND s.is_meeting = ?
  805. AND s.mobile = ?
  806. AND a.is_submit_meeting = 1
  807. AND t.activity_type = 1
  808. GROUP BY
  809. a.activity_id
  810. ORDER BY
  811. a.activity_time DESC
  812. LIMIT ?,?`
  813. _, err = o.Raw(sql, isMeeting, mobile, startSize, pageSize).QueryRows(&item)
  814. return
  815. }
  816. // 用户参会统计
  817. func GetAttendanceDetaiCount(mobile string, meetType, isMeeting int) (count int, err error) {
  818. o := orm.NewOrmUsingDB("hz_cygx")
  819. sqlCount := ` SELECT
  820. COUNT( DISTINCT a.activity_id ) as count
  821. FROM
  822. cygx_activity_signup AS s
  823. INNER JOIN cygx_activity as a ON a.activity_id = s.activity_id
  824. INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
  825. WHERE
  826. mobile = ?
  827. AND is_meeting =?
  828. AND s.do_fail_type = 0
  829. AND a.is_submit_meeting = 1 `
  830. if meetType == 1 {
  831. sqlCount += ` AND t.activity_type = 1 `
  832. } else {
  833. sqlCount += ` AND t.activity_type = 0 `
  834. }
  835. err = o.Raw(sqlCount, mobile, isMeeting).QueryRow(&count)
  836. return
  837. }
  838. // 线下已到会列表
  839. func GetAttendanceOfflineListByUser(isMeeting int, mobile string, startSize, pageSize int) (item []*UserInteraction, err error) {
  840. o := orm.NewOrmUsingDB("hz_cygx")
  841. sql := `SELECT
  842. a.activity_name,
  843. a.chart_permission_name,
  844. a.activity_type_name,
  845. a.label,
  846. a.activity_time
  847. FROM
  848. cygx_activity_signup AS s
  849. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  850. INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
  851. WHERE
  852. 1 = 1
  853. AND s.do_fail_type = 0
  854. AND s.is_cancel = 0
  855. AND s.is_meeting = ?
  856. AND s.mobile = ?
  857. AND a.is_submit_meeting = 1
  858. AND t.activity_type = 0
  859. GROUP BY
  860. a.activity_id
  861. ORDER BY
  862. a.activity_time DESC
  863. LIMIT ?,?`
  864. _, err = o.Raw(sql, isMeeting, mobile, startSize, pageSize).QueryRows(&item)
  865. return
  866. }
  867. // 获取用户参会记录数量
  868. func GetActivityMeetByUserCount(condition string) (count int, err error) {
  869. o := orm.NewOrmUsingDB("hz_cygx")
  870. sqlCount := ` SELECT
  871. COUNT( DISTINCT a.activity_id ) as count
  872. FROM
  873. cygx_activity_signup_detail AS s
  874. INNER JOIN cygx_activity as a ON a.activity_id = s.activity_id
  875. INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
  876. WHERE
  877. 1=1
  878. AND s.do_fail_type = 0 `
  879. if condition != "" {
  880. sqlCount += condition
  881. }
  882. err = o.Raw(sqlCount).QueryRow(&count)
  883. return
  884. }
  885. // 获取用户参会记录
  886. func GetActivityMeetByUser(condition string, startSize, pageSize int) (item []*UserInteraction, err error) {
  887. o := orm.NewOrmUsingDB("hz_cygx")
  888. sql := `SELECT
  889. t.activity_type,
  890. s.signup_type,
  891. s.is_meeting,
  892. a.activity_name,
  893. a.chart_permission_name,
  894. a.activity_type_name,
  895. a.label,
  896. a.activity_time,
  897. s.first_meeting_time,
  898. s.last_meeting_time,
  899. s.meeting_type_str,
  900. s.meeting_authentication,
  901. s.meeting_status_str,
  902. s.duration
  903. FROM
  904. cygx_activity_signup_detail AS s
  905. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  906. INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
  907. WHERE
  908. 1 = 1
  909. AND s.do_fail_type = 0 ` + condition + `
  910. GROUP BY
  911. s.activity_id,s.outbound_mobile
  912. ORDER BY
  913. a.activity_time DESC `
  914. if startSize > 0 || pageSize > 0 {
  915. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  916. }
  917. _, err = o.Raw(sql).QueryRows(&item)
  918. return
  919. }
  920. // 获取用户参会记录
  921. func GetActivitySpecialMeetByUser(condition string, startSize, pageSize int) (item []*UserInteraction, err error) {
  922. o := orm.NewOrmUsingDB("hz_cygx")
  923. sql := `SELECT
  924. a.activity_id,
  925. a.research_theme AS activity_name,
  926. a.chart_permission_name,
  927. special_type AS activity_type,
  928. a.activity_time,
  929. a.activity_time_text_by_day AS activity_time_text
  930. FROM
  931. cygx_activity_special_meeting_detail AS s
  932. INNER JOIN cygx_activity_special AS a ON a.activity_id = s.activity_id
  933. WHERE
  934. 1 = 1 ` + condition + `
  935. GROUP BY
  936. s.activity_id,
  937. s.mobile
  938. ORDER BY
  939. a.activity_time DESC `
  940. if startSize > 0 || pageSize > 0 {
  941. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  942. }
  943. _, err = o.Raw(sql).QueryRows(&item)
  944. return
  945. }
  946. type GetUserInteractionTableCountResp struct {
  947. HistoryNum int `description:"报告阅读"`
  948. CountNum int `description:"报告收藏"`
  949. IndustryFllowNum int `description:"产业关注"`
  950. DepartmentFollowNum int `description:"作者关注"`
  951. KeyWordNum int `description:"搜索关键词"`
  952. OnLineNum int `description:"线上互动活动"`
  953. OfficeNum int `description:"线下互动活动"`
  954. ActivityNum int `description:"活动数量"`
  955. ChartNum int `description:"图表数量"`
  956. TripNum int `description:"图表数量"`
  957. RoadshowVideoNum int `description:"产业视频播放量"`
  958. ActivityVideoNum int `description:"活动视频播放量"`
  959. ActivityVoiceNum int `description:"活动音频播放量"`
  960. TagNum int `description:"首页标签点击量"`
  961. YanxuanSpecialNum int `description:"研选专栏阅读数量"`
  962. YanxuanSpecialCollectNum int `description:"研选专栏收藏数量"`
  963. YanxuanSpecialFollowNum int `description:"研选专栏作者关注数量"`
  964. }
  965. // 用户互动总数统计
  966. func GetUserInteractionTableCount(uid int) (item *GetUserInteractionTableCountResp, err error) {
  967. o := orm.NewOrmUsingDB("hz_cygx")
  968. sql := `SELECT
  969. ( 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,
  970. ( 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,
  971. ( 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,
  972. ( 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,
  973. ( 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,
  974. ( 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 = ?
  975. AND t.activity_type=1 AND h.do_fail_type = 0 AND a.chart_permission_id != 31 ) AS on_line_num,
  976. ( 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 = ?
  977. AND t.activity_type = 0 AND h.do_fail_type = 0 AND a.chart_permission_id != 31 ) AS office_num,
  978. ( 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,
  979. ( 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,
  980. ( 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,
  981. ( 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,
  982. ( 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
  983. FROM dual `
  984. err = o.Raw(sql, uid, uid, uid, uid, uid, uid, uid, uid, uid, uid, uid, uid).QueryRow(&item)
  985. return
  986. }
  987. // 用户互动总数统计
  988. func GetUserInteractionTableCountByYanXuan(uid int) (item *GetUserInteractionTableCountResp, err error) {
  989. o := orm.NewOrmUsingDB("hz_cygx")
  990. sql := `SELECT
  991. ( 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,
  992. ( 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,
  993. ( 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,
  994. ( SELECT COUNT( 1 ) FROM cygx_article_department_follow AS h WHERE h.user_id = ? AND h.type = 1 ) AS department_follow_num,
  995. ( 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,
  996. ( 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 = ?
  997. AND t.activity_type=1 AND h.do_fail_type = 0 AND a.chart_permission_id = 31 ) AS on_line_num,
  998. ( 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 = ?
  999. AND t.activity_type = 0 AND h.do_fail_type = 0 AND a.chart_permission_id = 31 ) AS office_num,
  1000. ( 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,
  1001. ( SELECT COUNT(1) FROM cygx_yanxuan_special_follow as h WHERE h.user_id = ? ) AS yanxuan_special_follow_num,
  1002. ( 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
  1003. FROM dual `
  1004. err = o.Raw(sql, uid, uid, uid, uid, uid, uid, uid, uid, uid, uid).QueryRow(&item)
  1005. return
  1006. }
  1007. // 根据时间获取用户互动总数统计
  1008. func GetUserInteractionTableCountBytime(uid int, startDate, endDate string) (item *GetUserInteractionTableCountResp, err error) {
  1009. o := orm.NewOrm()
  1010. sql := `SELECT
  1011. ( 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,
  1012. ( 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,
  1013. ( 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,
  1014. ( 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,
  1015. ( 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,
  1016. ( 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,
  1017. ( 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
  1018. 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,
  1019. ( 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
  1020. 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
  1021. FROM
  1022. wx_user as u
  1023. WHERE
  1024. u.user_id = ?`
  1025. err = o.Raw(sql, uid).QueryRow(&item)
  1026. return
  1027. }
  1028. type ArticlePvCountResp struct {
  1029. ArticleId int `description:"文章ID"`
  1030. Pv int `description:"Pv"`
  1031. }
  1032. // 阅读记录
  1033. func GetArticlePvCount(mobile, email, dateTime string) (item []*ArticlePvCountResp, err error) {
  1034. o := orm.NewOrmUsingDB("hz_cygx")
  1035. sql := `SELECT
  1036. article_id,
  1037. COUNT(article_id) as pv
  1038. FROM
  1039. cygx_article_history_record_all as h
  1040. WHERE
  1041. mobile = ?
  1042. AND create_time >= ?
  1043. AND is_del = 0
  1044. OR ( email = ? AND email <>'' AND create_time >= ? AND is_del = 0 )
  1045. GROUP BY article_id `
  1046. _, err = o.Raw(sql, mobile, dateTime, email, dateTime).QueryRows(&item)
  1047. return
  1048. }
  1049. type ArticleIndustryNameResp struct {
  1050. ArticleId int `description:"文章ID"`
  1051. IndustryName string `description:"产业名称"`
  1052. SubjectName string `description:"标的名称"`
  1053. }
  1054. // 产业名称
  1055. func GetArticleGroupyIndustryName(articleIds string) (item []*ArticleIndustryNameResp, err error) {
  1056. o := orm.NewOrmUsingDB("hz_cygx")
  1057. sql := `SELECT
  1058. art.article_id,
  1059. (
  1060. SELECT
  1061. GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' )
  1062. FROM
  1063. cygx_industrial_subject AS s
  1064. WHERE
  1065. s.industrial_subject_id IN ( SELECT industrial_subject_id FROM cygx_industrial_article_group_subject AS sg WHERE sg.article_id = art.article_id )
  1066. ) AS subject_name,
  1067. (
  1068. SELECT
  1069. GROUP_CONCAT( DISTINCT man.industry_name SEPARATOR '/' )
  1070. FROM
  1071. cygx_industrial_management AS man
  1072. WHERE
  1073. 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 )
  1074. ) AS industry_name
  1075. FROM
  1076. cygx_article_history_record_all AS r
  1077. INNER JOIN cygx_article AS art ON art.article_id = r.article_id
  1078. LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two
  1079. LEFT JOIN cygx_industrial_article_group_management AS man ON man.article_id = art.article_id
  1080. WHERE
  1081. art.article_id IN ( ` + articleIds + `) GROUP BY art.article_id `
  1082. _, err = o.Raw(sql).QueryRows(&item)
  1083. return
  1084. }
  1085. // 标的名称
  1086. func GetArticleGroupySubjectName(articleIds string) (item []*ArticleIndustryNameResp, err error) {
  1087. o := orm.NewOrmUsingDB("hz_cygx")
  1088. sql := `SELECT
  1089. article_id,
  1090. subject_name
  1091. FROM
  1092. cygx_industrial_article_group_subject AS mg
  1093. INNER JOIN cygx_industrial_subject AS m ON m.industrial_subject_id = mg.industrial_subject_id
  1094. WHERE
  1095. article_id IN ( ` + articleIds + `)`
  1096. _, err = o.Raw(sql).QueryRows(&item)
  1097. return
  1098. }
  1099. type UserLabel struct {
  1100. Label string `description:"标签 多个用 , 隔开"`
  1101. }
  1102. type ActivityLabelCountResp struct {
  1103. Label string `description:"标签"`
  1104. Pv int `description:"Pv"`
  1105. }
  1106. // 活动标签记录(我的日程)
  1107. func GetActivitySignCount(mobile, dateTime string) (item []*ActivityLabelCountResp, err error) {
  1108. o := orm.NewOrmUsingDB("hz_cygx")
  1109. sql := `SELECT
  1110. label ,
  1111. COUNT( label ) AS pv
  1112. FROM
  1113. cygx_activity
  1114. WHERE
  1115. activity_id IN ( SELECT activity_id FROM cygx_my_schedule WHERE mobile = ? )
  1116. AND label != ''
  1117. AND activity_time >= ?
  1118. GROUP BY
  1119. label`
  1120. _, err = o.Raw(sql, mobile, dateTime).QueryRows(&item)
  1121. return
  1122. }
  1123. // 活动标签记录(会议提醒)
  1124. func GetActivityMeetingReminder(mobile, dateTime string) (item []*ActivityLabelCountResp, err error) {
  1125. o := orm.NewOrmUsingDB("hz_cygx")
  1126. sql := `SELECT
  1127. label ,
  1128. COUNT( label ) AS pv
  1129. FROM
  1130. cygx_activity
  1131. WHERE
  1132. activity_id IN ( SELECT activity_id FROM cygx_activity_meeting_reminder WHERE mobile = ? )
  1133. AND label != ''
  1134. AND activity_time >= ?
  1135. GROUP BY
  1136. label`
  1137. _, err = o.Raw(sql, mobile, dateTime).QueryRows(&item)
  1138. return
  1139. }
  1140. func GetCygxArticleCollectId(uid int, dateTime string) (articleIds string, err error) {
  1141. sql := `SELECT
  1142. GROUP_CONCAT( DISTINCT article_id SEPARATOR ',' ) AS permission
  1143. FROM
  1144. cygx_article_collect
  1145. WHERE
  1146. user_id = ?
  1147. AND create_time >= ? `
  1148. o := orm.NewOrmUsingDB("hz_cygx")
  1149. err = o.Raw(sql, uid, dateTime).QueryRow(&articleIds)
  1150. return
  1151. }
  1152. // 用户互动量
  1153. type CygxInteractionNumResp struct {
  1154. DateTime string `description:"时间"`
  1155. InteractionNum int `description:"互动量"`
  1156. }
  1157. type CygxCygxInteractionNumRespListResp struct {
  1158. List []*CygxInteractionNumResp
  1159. }
  1160. // 用户互动详情
  1161. type UserInteractionrelevantListResp struct {
  1162. IndustryName string `description:"产业名称"`
  1163. IsFllow bool `description:"是否关注"`
  1164. List []*UserInteraction
  1165. }
  1166. type EsUserInteraction struct {
  1167. Id int `description:"主键ID"`
  1168. ArticleId int `description:"文章id"`
  1169. ArticleType int `description:"文章类型 1:查研观向, 2:策略平台"`
  1170. Title string `description:"标题"`
  1171. PublishDate string `description:"发布时间"`
  1172. CreateTime string `description:"创建时间"`
  1173. StopTime string `description:"阅读停留时间"`
  1174. RealName string `description:"姓名"`
  1175. CompanyName string `description:"公司名称"`
  1176. CompanyId int `description:"公司ID"`
  1177. SellerName string `description:"所属销售"`
  1178. SellerId int `description:"所属销售ID"`
  1179. Mobile string `description:"手机号"`
  1180. Email string `description:"邮箱"`
  1181. UserId int `description:"用户ID"`
  1182. UserArticleHistoryNum int `description:"用户阅读数量"`
  1183. CompanyArticleHistoryNum int `description:"机构阅读数量"`
  1184. }
  1185. func GetCompanyIdsCondition(ondition string) (companyIds string, err error) {
  1186. sql := ondition
  1187. o := orm.NewOrm()
  1188. err = o.Raw(sql).QueryRow(&companyIds)
  1189. return
  1190. }
  1191. type InteractiveList struct {
  1192. TotalMap map[int]int
  1193. EsList []*EsUserInteraction
  1194. ActivityList []*company.CompanyReportRecordGroup
  1195. CollectList []*company.CompanyReportRecordGroup
  1196. IndustryFllowList []*company.CompanyReportRecordGroup
  1197. DepartmentFollowList []*company.CompanyReportRecordGroup
  1198. KeyWordList []*company.CompanyReportRecordGroup
  1199. Chartist []*company.CompanyReportRecordGroup
  1200. }
  1201. func GetAllOverseasRaiEmail() (emails []string, err error) {
  1202. sql := `
  1203. SELECT
  1204. *
  1205. FROM
  1206. (
  1207. SELECT
  1208. wu.email
  1209. FROM
  1210. wx_user AS wu
  1211. INNER JOIN company AS c
  1212. WHERE
  1213. wu.company_id = c.company_id
  1214. AND wu.email <> ""
  1215. AND c.region_type = "海外"
  1216. ) AS a UNION
  1217. (
  1218. SELECT
  1219. wu.email
  1220. FROM
  1221. company_product AS cp
  1222. INNER JOIN wx_user AS wu
  1223. WHERE
  1224. cp.industry_id = 10
  1225. AND cp.product_id = 2
  1226. AND wu.email <> ""
  1227. AND cp.status IN ( "正式", "试用" )
  1228. )`
  1229. o := orm.NewOrm()
  1230. _, err = o.Raw(sql).QueryRows(&emails)
  1231. return
  1232. }