cygx_user.go 59 KB

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