cygx_user.go 60 KB

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