cygx_user.go 59 KB

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