cygx_user_company.go 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263
  1. package cygx
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "hongze/hz_crm_api/models/company"
  6. "hongze/hz_crm_api/utils"
  7. "strconv"
  8. )
  9. // 用户互动总数统计
  10. //func GetUserInteractionTableCountByCompany(companyId int) (item *GetUserInteractionTableCountResp, err error) {
  11. // o := orm.NewOrm()
  12. // sql := `SELECT
  13. // ( 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.company_id = u.company_id AND h.is_del = 0 AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS history_num,
  14. // ( SELECT COUNT( 1 ) FROM cygx_article_collect AS h WHERE h.company_id = u.company_id AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS count_num,
  15. // ( SELECT COUNT( 1 ) FROM cygx_chart_collect AS h INNER JOIN cygx_chart AS a ON h.chart_id = a.chart_id WHERE h.company_id = u.company_id AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS chart_num,
  16. // ( SELECT COUNT( 1 ) FROM cygx_industry_fllow AS h WHERE h.company_id = u.company_id AND h.type = 1 AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS industry_fllow_num,
  17. // ( SELECT COUNT( 1 ) FROM cygx_article_department_follow AS h WHERE h.company_id = u.company_id AND h.type = 1 AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS department_follow_num,
  18. // ( SELECT COUNT( 1 ) FROM cygx_search_key_word AS h WHERE h.company_id = u.company_id AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS key_word_num,
  19. // ( SELECT COUNT(1 ) 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 INNER JOIN wx_user as wu ON wu.user_id = h.user_id WHERE h.company_id = u.company_id
  20. // AND t.activity_type=1 AND h.do_fail_type = 0 AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS on_line_num,
  21. // ( SELECT COUNT( 1 ) 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 INNER JOIN wx_user as wu ON wu.user_id = h.user_id WHERE h.company_id = u.company_id
  22. // AND t.activity_type = 0 AND h.do_fail_type = 0 AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS office_num
  23. // FROM
  24. // company as u
  25. // WHERE
  26. // u.company_id = ?`
  27. // err = o.Raw(sql, companyId).QueryRow(&item)
  28. // return
  29. //}
  30. // 获取阅读记录数量
  31. //func GetCygxArticleHistoryCountByCompany(condition string) (count int, err error) {
  32. // o := orm.NewOrm()
  33. // sqlCount := ` SELECT COUNT( 1 ) AS count
  34. //FROM
  35. // (
  36. // SELECT
  37. // COUNT( 1 )
  38. // FROM
  39. // cygx_article_history_record_all AS r
  40. // INNER JOIN cygx_article AS art ON art.article_id = r.article_id
  41. // INNER JOIN company_product AS cp ON cp.company_id = r.company_id
  42. // AND cp.product_id = 2
  43. // INNER JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
  44. // INNER JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
  45. // LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two WHERE r.is_del = 0`
  46. // if condition != "" {
  47. // sqlCount += condition
  48. // }
  49. // sqlCount += ` GROUP BY r.id ) AS count `
  50. // err = o.Raw(sqlCount).QueryRow(&count)
  51. // return
  52. //}
  53. // 阅读记录列表
  54. func GetCygxArticleHistoryRecordByCompany(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
  55. o := orm.NewOrmUsingDB("hz_cygx")
  56. sql := ` SELECT
  57. art.title,
  58. art.article_id,
  59. art.article_id_md5,
  60. art.publish_date,
  61. art.category_name,
  62. re.chart_permission_name,
  63. re.chart_permission_id,
  64. r.create_time,
  65. r.mobile,
  66. r.user_id,
  67. r.real_name,
  68. r.source as source_platform,
  69. r.stop_time
  70. FROM
  71. cygx_article_history_record_all AS r
  72. INNER JOIN cygx_article AS art ON art.article_id = r.article_id
  73. LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
  74. LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two
  75. LEFT JOIN cygx_industrial_article_group_management AS man ON man.article_id = art.article_id
  76. WHERE
  77. 1=1 AND r.is_del = 0 ` + condition + ` GROUP BY r.id ORDER BY ui.article_history_num DESC , r.create_time DESC `
  78. if startSize > 0 || pageSize > 0 {
  79. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  80. }
  81. _, err = o.Raw(sql).QueryRows(&items)
  82. return
  83. }
  84. // 获取用户参会记录数量
  85. func GetActivityMeetByCompanyCount(condition string) (count int, err error) {
  86. o := orm.NewOrmUsingDB("hz_cygx")
  87. sqlCount := `SELECT
  88. COUNT(*) AS count
  89. FROM
  90. cygx_activity_signup_detail AS r
  91. INNER JOIN cygx_activity AS a ON a.activity_id = r.activity_id
  92. INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
  93. WHERE
  94. 1 = 1
  95. AND r.do_fail_type = 0`
  96. if condition != "" {
  97. sqlCount += condition
  98. }
  99. err = o.Raw(sqlCount).QueryRow(&count)
  100. return
  101. }
  102. // 获取用户参会记录数量(关联用户跟销售的绑定关系跨库查询)
  103. func GetActivityMeetByCompanyCountWeekly(condition string) (count int, err error) {
  104. o := orm.NewOrmUsingDB("hz_cygx")
  105. databaseName := utils.GetWeeklyDatabase()
  106. sqlCount := `SELECT
  107. COUNT(*) AS count
  108. FROM
  109. cygx_activity_signup_detail AS r
  110. INNER JOIN cygx_activity AS a ON a.activity_id = r.activity_id
  111. INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
  112. INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
  113. WHERE 1 = 1
  114. AND r.do_fail_type = 0`
  115. sqlCount = fmt.Sprintf(sqlCount, databaseName)
  116. if condition != "" {
  117. sqlCount += condition
  118. }
  119. err = o.Raw(sqlCount).QueryRow(&count)
  120. return
  121. }
  122. // 获取用户参会记录
  123. func GetActivityMeetByCompany(condition string, startSize, pageSize int) (item []*UserInteraction, err error) {
  124. o := orm.NewOrmUsingDB("hz_cygx")
  125. sql := `SELECT
  126. t.activity_type,
  127. r.signup_type,
  128. r.is_meeting,
  129. r.mobile,
  130. r.real_name,
  131. a.activity_name,
  132. a.chart_permission_name,
  133. a.activity_type_name,
  134. a.label,
  135. a.activity_time,
  136. r.first_meeting_time,
  137. r.last_meeting_time,
  138. r.meeting_type_str,
  139. r.meeting_authentication,
  140. r.meeting_status_str,
  141. r.duration
  142. FROM
  143. cygx_activity_signup_detail AS r
  144. INNER JOIN cygx_activity AS a ON a.activity_id = r.activity_id
  145. INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
  146. LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
  147. WHERE
  148. 1 = 1
  149. AND r.do_fail_type = 0
  150. ` + condition + `
  151. GROUP BY
  152. r.id
  153. ORDER BY
  154. a.activity_time DESC ,r.id DESC `
  155. if startSize > 0 || pageSize > 0 {
  156. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  157. }
  158. _, err = o.Raw(sql).QueryRows(&item)
  159. return
  160. }
  161. // 获取用户参会记录(关联用户跟销售的绑定关系跨库查询)
  162. func GetActivityMeetByCompanyWeekly(condition string, startSize, pageSize int) (item []*UserInteraction, err error) {
  163. o := orm.NewOrmUsingDB("hz_cygx")
  164. databaseName := utils.GetWeeklyDatabase()
  165. sql := `SELECT
  166. t.activity_type,
  167. r.signup_type,
  168. r.is_meeting,
  169. r.mobile,
  170. r.real_name,
  171. a.activity_name,
  172. a.chart_permission_name,
  173. a.activity_type_name,
  174. a.label,
  175. a.activity_time,
  176. r.first_meeting_time,
  177. r.last_meeting_time,
  178. r.meeting_type_str,
  179. r.meeting_authentication,
  180. r.meeting_status_str,
  181. r.company_name,
  182. r.company_id,
  183. r.real_name,
  184. r.duration
  185. FROM
  186. cygx_activity_signup_detail AS r
  187. INNER JOIN cygx_activity AS a ON a.activity_id = r.activity_id
  188. INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
  189. INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
  190. WHERE
  191. 1 = 1 AND r.do_fail_type = 0 `
  192. sql = fmt.Sprintf(sql, databaseName)
  193. sql += condition + ` GROUP BY r.id ORDER BY a.activity_time DESC ,r.id DESC `
  194. if startSize > 0 || pageSize > 0 {
  195. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  196. }
  197. _, err = o.Raw(sql).QueryRows(&item)
  198. return
  199. }
  200. // 收藏列表数量
  201. func GetCygxArticleCollectCountByCompany(condition string) (count int, err error) {
  202. o := orm.NewOrmUsingDB("hz_cygx")
  203. 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
  204. WHERE 1=1 ` + condition
  205. err = o.Raw(sqlCount).QueryRow(&count)
  206. return
  207. }
  208. // 收藏列表数量(关联用户跟销售的绑定关系跨库查询)
  209. func GetCygxArticleCollectCountByCompanyWeekly(condition string) (count int, err error) {
  210. o := orm.NewOrmUsingDB("hz_cygx")
  211. databaseName := utils.GetWeeklyDatabase()
  212. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_article_collect as r
  213. INNER JOIN cygx_article AS art ON art.article_id = r.article_id
  214. INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
  215. WHERE 1=1 `
  216. sqlCount = fmt.Sprintf(sqlCount, databaseName)
  217. if condition != "" {
  218. sqlCount += condition
  219. }
  220. err = o.Raw(sqlCount).QueryRow(&count)
  221. return
  222. }
  223. // 收藏列表
  224. func GetCygxArticleCollectByCompany(startSize, pageSize int, condition string) (items []*UserInteraction, err error) {
  225. o := orm.NewOrmUsingDB("hz_cygx")
  226. sql := ` SELECT
  227. art.title,
  228. art.article_id,
  229. art.article_id_md5,
  230. art.publish_date,
  231. re.chart_permission_name,
  232. re.chart_permission_id,
  233. r.create_time,
  234. r.mobile,
  235. r.real_name,
  236. re.match_type_name,
  237. (
  238. SELECT
  239. GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' )
  240. FROM
  241. cygx_industrial_subject AS s
  242. WHERE
  243. s.industrial_subject_id IN ( SELECT industrial_subject_id FROM cygx_industrial_article_group_subject AS sg WHERE sg.article_id = art.article_id )
  244. ) AS subject_name_str,
  245. (
  246. SELECT
  247. GROUP_CONCAT( DISTINCT man.industry_name SEPARATOR '/' )
  248. FROM
  249. cygx_industrial_management AS man
  250. WHERE
  251. 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 )
  252. ) AS industry_name
  253. FROM
  254. cygx_article_collect AS r
  255. INNER JOIN cygx_article AS art ON art.article_id = r.article_id
  256. LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
  257. LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two
  258. LEFT JOIN cygx_industrial_article_group_management AS man ON man.article_id = art.article_id
  259. WHERE
  260. 1=1 ` + condition + ` GROUP BY r.id
  261. ORDER BY r.create_time DESC `
  262. if startSize > 0 || pageSize > 0 {
  263. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  264. }
  265. _, err = o.Raw(sql).QueryRows(&items)
  266. return
  267. }
  268. // 收藏列表(关联用户跟销售的绑定关系跨库查询)
  269. func GetCygxArticleCollectByCompanyWeekly(startSize, pageSize int, condition string) (items []*UserInteraction, err error) {
  270. o := orm.NewOrmUsingDB("hz_cygx")
  271. databaseName := utils.GetWeeklyDatabase()
  272. sql := ` SELECT
  273. art.title,
  274. art.article_id,
  275. art.report_id,
  276. art.article_id_md5,
  277. art.publish_date,
  278. re.chart_permission_name,
  279. re.chart_permission_id,
  280. r.create_time,
  281. r.mobile,
  282. r.real_name,
  283. re.match_type_name,
  284. r.company_name,
  285. r.company_id,
  286. (
  287. SELECT
  288. GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' )
  289. FROM
  290. cygx_industrial_subject AS s
  291. WHERE
  292. s.industrial_subject_id IN ( SELECT industrial_subject_id FROM cygx_industrial_article_group_subject AS sg WHERE sg.article_id = art.article_id )
  293. ) AS subject_name_str,
  294. (
  295. SELECT
  296. GROUP_CONCAT( DISTINCT man.industry_name SEPARATOR '/' )
  297. FROM
  298. cygx_industrial_management AS man
  299. WHERE
  300. 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 )
  301. ) AS industry_name
  302. FROM
  303. cygx_article_collect AS r
  304. INNER JOIN cygx_article AS art ON art.article_id = r.article_id
  305. INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
  306. LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two
  307. LEFT JOIN cygx_industrial_article_group_management AS man ON man.article_id = art.article_id
  308. WHERE
  309. 1=1 `
  310. sql = fmt.Sprintf(sql, databaseName)
  311. sql += condition + ` GROUP BY r.id ORDER BY r.create_time DESC `
  312. if startSize > 0 || pageSize > 0 {
  313. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  314. }
  315. _, err = o.Raw(sql).QueryRows(&items)
  316. return
  317. }
  318. // 关注产业数量
  319. func GetCygxIndustryFllowCountByCompany(condition string) (count int, err error) {
  320. o := orm.NewOrmUsingDB("hz_cygx")
  321. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_industry_fllow AS r
  322. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = r.industrial_management_id WHERE type = 1 AND r.source IN (0,1,2) ` + condition
  323. err = o.Raw(sqlCount).QueryRow(&count)
  324. return
  325. }
  326. // 关注产业数量(关联用户跟销售的绑定关系跨库查询)
  327. func GetCygxIndustryFllowCountByCompanyWeekly(condition string) (count int, err error) {
  328. o := orm.NewOrmUsingDB("hz_cygx")
  329. databaseName := utils.GetWeeklyDatabase()
  330. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_industry_fllow AS r
  331. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = r.industrial_management_id
  332. INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2 WHERE type = 1 AND r.source IN (0,1,2) `
  333. sqlCount = fmt.Sprintf(sqlCount, databaseName)
  334. if condition != "" {
  335. sqlCount += condition
  336. }
  337. err = o.Raw(sqlCount).QueryRow(&count)
  338. return
  339. }
  340. // 关注产业列表
  341. func GetCygxIndustryFllowByCompany(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
  342. o := orm.NewOrmUsingDB("hz_cygx")
  343. sql := `SELECT
  344. m.industry_name,
  345. r.mobile,
  346. r.real_name,
  347. r.modify_time as create_time,
  348. ( SELECT GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' ) FROM cygx_industrial_subject AS s WHERE s.industrial_management_id = m.industrial_management_id ) AS subject_name_str
  349. FROM
  350. cygx_industry_fllow AS r
  351. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = r.industrial_management_id
  352. WHERE type = 1 AND r.source IN (0,1,2) ` + condition + ` ORDER BY r.id DESC LIMIT ?,? `
  353. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  354. return
  355. }
  356. // 关注产业列表
  357. func GetCygxIndustryFllowByCompanyWeekly(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
  358. o := orm.NewOrmUsingDB("hz_cygx")
  359. databaseName := utils.GetWeeklyDatabase()
  360. sql := `SELECT
  361. m.industry_name,
  362. r.mobile,
  363. r.real_name,
  364. r.company_name,
  365. r.company_id,
  366. r.modify_time as create_time,
  367. ( SELECT GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' ) FROM cygx_industrial_subject AS s WHERE s.industrial_management_id = m.industrial_management_id ) AS subject_name_str
  368. FROM
  369. cygx_industry_fllow AS r
  370. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = r.industrial_management_id
  371. INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
  372. WHERE type = 1 AND r.source IN (0,1,2) `
  373. sql = fmt.Sprintf(sql, databaseName)
  374. if condition != "" {
  375. sql += condition
  376. }
  377. sql += ` ORDER BY r.id DESC LIMIT ?,? `
  378. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  379. return
  380. }
  381. // 关注作者数量
  382. func GetCygArticleDepartmentFollowCountByCompany(condition string) (count int, err error) {
  383. o := orm.NewOrmUsingDB("hz_cygx")
  384. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_article_department_follow AS r
  385. INNER JOIN cygx_article_department AS m ON m.department_id = r.department_id WHERE type = 1 ` + condition
  386. err = o.Raw(sqlCount).QueryRow(&count)
  387. return
  388. }
  389. // 关注作者数量
  390. func GetCygArticleDepartmentFollowCountByCompanyWeekly(condition string) (count int, err error) {
  391. o := orm.NewOrmUsingDB("hz_cygx")
  392. databaseName := utils.GetWeeklyDatabase()
  393. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_article_department_follow AS r
  394. INNER JOIN cygx_article_department AS m ON m.department_id = r.department_id
  395. INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
  396. WHERE type = 1 `
  397. sqlCount = fmt.Sprintf(sqlCount, databaseName)
  398. if condition != "" {
  399. sqlCount += condition
  400. }
  401. err = o.Raw(sqlCount).QueryRow(&count)
  402. return
  403. }
  404. // 关注作者列表
  405. func GetCygArticleDepartmentFollowByCompany(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
  406. o := orm.NewOrmUsingDB("hz_cygx")
  407. sql := `SELECT
  408. m.department_id,
  409. m.nick_name,
  410. r.modify_time as create_time,
  411. r.mobile,
  412. r.real_name,
  413. m.department_id,
  414. a.title,
  415. a.article_id,
  416. ( SELECT MAX( create_time ) FROM cygx_article_department_follow WHERE user_id = r.user_id ) AS max_time
  417. FROM
  418. cygx_article_department_follow AS r
  419. INNER JOIN cygx_article_department AS m ON m.department_id = r.department_id
  420. INNER JOIN cygx_article AS a ON a.department_id = m.department_id
  421. WHERE r.type = 1 ` + condition + ` GROUP BY r.id
  422. ORDER BY max_time DESC LIMIT ?,? `
  423. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  424. return
  425. }
  426. // 关注作者列表
  427. func GetCygArticleDepartmentFollowByCompanyWeekly(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
  428. o := orm.NewOrmUsingDB("hz_cygx")
  429. databaseName := utils.GetWeeklyDatabase()
  430. sql := `SELECT
  431. m.department_id,
  432. m.nick_name,
  433. r.modify_time as create_time,
  434. r.mobile,
  435. r.real_name,
  436. m.department_id,
  437. a.title,
  438. a.article_id,
  439. r.company_name,
  440. r.company_id,
  441. ( SELECT MAX( create_time ) FROM cygx_article_department_follow WHERE user_id = r.user_id ) AS max_time
  442. FROM
  443. cygx_article_department_follow AS r
  444. INNER JOIN cygx_article_department AS m ON m.department_id = r.department_id
  445. INNER JOIN cygx_article AS a ON a.department_id = m.department_id
  446. INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
  447. WHERE r.type = 1 `
  448. sql = fmt.Sprintf(sql, databaseName)
  449. if condition != "" {
  450. sql += condition
  451. }
  452. sql += ` GROUP BY r.id ORDER BY max_time DESC LIMIT ?,? `
  453. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  454. return
  455. }
  456. // 用户搜索关键词统计
  457. func GetCygxSearchKeyWordCountBuCompany(condition string) (count int, err error) {
  458. o := orm.NewOrmUsingDB("hz_cygx")
  459. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_search_key_word as r WHERE 1= 1 ` + condition
  460. err = o.Raw(sqlCount).QueryRow(&count)
  461. return
  462. }
  463. // 用户搜索关键词统计
  464. func GetCygxSearchKeyWordCountBuCompanyWeekly(condition string) (count int, err error) {
  465. o := orm.NewOrmUsingDB("hz_cygx")
  466. databaseName := utils.GetWeeklyDatabase()
  467. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_search_key_word as r
  468. INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
  469. WHERE 1= 1 `
  470. sqlCount = fmt.Sprintf(sqlCount, databaseName)
  471. if condition != "" {
  472. sqlCount += condition
  473. }
  474. err = o.Raw(sqlCount).QueryRow(&count)
  475. return
  476. }
  477. // 用户搜索关键词列表
  478. func GetCygxSearchKeyWordByCompany(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
  479. o := orm.NewOrmUsingDB("hz_cygx")
  480. sql := `SELECT
  481. r.key_word,
  482. r.create_time,
  483. r.mobile,
  484. r.real_name
  485. FROM
  486. cygx_search_key_word as r
  487. WHERE 1= 1 ` + condition + `
  488. ORDER BY r.create_time DESC LIMIT ?,? `
  489. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  490. return
  491. }
  492. // 用户搜索关键词列表
  493. func GetCygxSearchKeyWordByCompanyWeekly(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
  494. o := orm.NewOrmUsingDB("hz_cygx")
  495. databaseName := utils.GetWeeklyDatabase()
  496. sql := `SELECT
  497. r.key_word,
  498. r.create_time,
  499. r.mobile,
  500. r.company_name,
  501. r.company_id,
  502. r.real_name
  503. FROM
  504. cygx_search_key_word as r
  505. INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
  506. WHERE 1= 1 `
  507. sql = fmt.Sprintf(sql, databaseName)
  508. if condition != "" {
  509. sql += condition
  510. }
  511. sql += ` ORDER BY r.create_time DESC LIMIT ?,? `
  512. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  513. return
  514. }
  515. // 用户专项产业调研统计
  516. func GetCygxActivitySpecialTripCountByCompany(condition string) (count int, err error) {
  517. o := orm.NewOrmUsingDB("hz_cygx")
  518. sqlCount := ` SELECT
  519. COUNT( 1 )
  520. FROM
  521. cygx_activity_special_meeting_detail AS r
  522. INNER JOIN cygx_activity_special AS a ON a.activity_id = r.activity_id
  523. WHERE
  524. 1 = 1
  525. AND a.publish_status = 1 ` + condition
  526. err = o.Raw(sqlCount).QueryRow(&count)
  527. return
  528. }
  529. // 用户专项产业调研统计
  530. func GetCygxActivitySpecialTripCountByCompanyWeekly(condition string) (count int, err error) {
  531. o := orm.NewOrmUsingDB("hz_cygx")
  532. databaseName := utils.GetWeeklyDatabase()
  533. sqlCount := ` SELECT
  534. COUNT( 1 )
  535. FROM
  536. cygx_activity_special_meeting_detail AS r
  537. INNER JOIN cygx_activity_special AS a ON a.activity_id = r.activity_id
  538. INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
  539. WHERE
  540. 1 = 1
  541. AND a.publish_status = 1 `
  542. sqlCount = fmt.Sprintf(sqlCount, databaseName)
  543. if condition != "" {
  544. sqlCount += condition
  545. }
  546. err = o.Raw(sqlCount).QueryRow(&count)
  547. return
  548. }
  549. // 用户专项产业调研列表
  550. func CygxActivitySpecialTripByCompany(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
  551. o := orm.NewOrmUsingDB("hz_cygx")
  552. sql := `SELECT
  553. a.research_theme AS activity_name,
  554. a.chart_permission_name,
  555. a.activity_time_text_by_day AS activity_time_text,
  556. a.city,
  557. a.special_type AS activity_type,
  558. r.mobile,
  559. r.activity_id,
  560. r.real_name,
  561. r.is_meeting
  562. FROM
  563. cygx_activity_special_meeting_detail AS r
  564. INNER JOIN cygx_activity_special AS a ON a.activity_id = r.activity_id
  565. WHERE 1= 1 AND a.publish_status = 1 ` + condition + `
  566. ORDER BY r.create_time DESC LIMIT ?,? `
  567. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  568. return
  569. }
  570. // 用户专项产业调研列表
  571. func CygxActivitySpecialTripByCompanyWeekly(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
  572. o := orm.NewOrmUsingDB("hz_cygx")
  573. databaseName := utils.GetWeeklyDatabase()
  574. sql := `SELECT
  575. a.research_theme AS activity_name,
  576. a.chart_permission_name,
  577. a.activity_time_text_by_day AS activity_time_text,
  578. a.city,
  579. a.special_type AS activity_type,
  580. r.mobile,
  581. r.activity_id,
  582. r.real_name,
  583. r.company_name,
  584. r.seller_name,
  585. r.company_id,
  586. r.is_meeting
  587. FROM
  588. cygx_activity_special_trip AS r
  589. INNER JOIN cygx_activity_special AS a ON a.activity_id = r.activity_id
  590. INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
  591. WHERE 1= 1 AND a.publish_status = 1 `
  592. sql = fmt.Sprintf(sql, databaseName)
  593. if condition != "" {
  594. sql += condition
  595. }
  596. sql += ` ORDER BY r.create_time DESC LIMIT ?,? `
  597. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  598. return
  599. }
  600. // 用户音视频浏览统计
  601. func GetCygxRoadshowCountByCompany(condition string) (count int, err error) {
  602. o := orm.NewOrmUsingDB("hz_cygx")
  603. sqlCount := `SELECT
  604. COUNT( 1 ) total
  605. FROM
  606. (
  607. SELECT
  608. ""
  609. FROM
  610. cygx_micro_roadshow_video_history AS r
  611. INNER JOIN cygx_micro_roadshow_video AS v ON r.video_id = v.video_id
  612. WHERE 1=1 ` + condition + ` UNION ALL
  613. SELECT
  614. ""
  615. FROM
  616. cygx_activity_video_history AS r
  617. INNER JOIN cygx_activity_video AS v ON r.video_id = v.video_id
  618. WHERE 1=1 ` + condition + ` UNION ALL
  619. SELECT
  620. ""
  621. FROM
  622. cygx_activity_voice_history AS r
  623. INNER JOIN cygx_activity_voice AS v ON r.activity_id = v.activity_id
  624. WHERE 1=1 ` + condition + `)z `
  625. err = o.Raw(sqlCount).QueryRow(&count)
  626. return
  627. }
  628. // 用户音视频浏览统计
  629. func GetCygxRoadshowCountByCompanyWeekly(condition string) (count int, err error) {
  630. o := orm.NewOrmUsingDB("hz_cygx")
  631. databaseName := utils.GetWeeklyDatabase()
  632. sqlCount := `SELECT
  633. COUNT( 1 ) total
  634. FROM
  635. (
  636. SELECT
  637. ""
  638. FROM
  639. cygx_micro_roadshow_video_history AS r
  640. INNER JOIN cygx_micro_roadshow_video AS v ON r.video_id = v.video_id
  641. INNER JOIN ` + databaseName + `.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
  642. WHERE 1=1 ` + condition + ` UNION ALL
  643. SELECT
  644. ""
  645. FROM
  646. cygx_activity_video_history AS r
  647. INNER JOIN cygx_activity_video AS v ON r.video_id = v.video_id
  648. INNER JOIN ` + databaseName + `.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
  649. WHERE 1=1 ` + condition + ` UNION ALL
  650. SELECT
  651. ""
  652. FROM
  653. cygx_activity_voice_history AS r
  654. INNER JOIN cygx_activity_voice AS v ON r.activity_id = v.activity_id
  655. INNER JOIN ` + databaseName + `.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
  656. WHERE 1=1 ` + condition + `)z `
  657. err = o.Raw(sqlCount).QueryRow(&count)
  658. return
  659. }
  660. // 用户音视频浏览列表
  661. func GetCygxRoadshowByCompany(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
  662. o := orm.NewOrmUsingDB("hz_cygx")
  663. sql := `SELECT
  664. v.video_name AS media_title,
  665. r.create_time,
  666. r.real_name,
  667. r.mobile,
  668. "逻辑解析" AS file_type
  669. FROM
  670. cygx_micro_roadshow_video_history AS r
  671. INNER JOIN cygx_micro_roadshow_video AS v ON r.video_id = v.video_id
  672. WHERE 1=1 ` + condition + ` UNION ALL
  673. SELECT
  674. v.video_name AS media_title,
  675. r.create_time,
  676. r.real_name,
  677. r.mobile,
  678. "路演回放" AS file_type
  679. FROM
  680. cygx_activity_video_history AS r
  681. INNER JOIN cygx_activity_video AS v ON r.video_id = v.video_id
  682. WHERE 1=1 ` + condition + ` UNION ALL
  683. SELECT
  684. v.voice_name AS media_title,
  685. r.create_time,
  686. r.real_name,
  687. r.mobile,
  688. "路演回放" AS file_type
  689. FROM
  690. cygx_activity_voice_history AS r
  691. INNER JOIN cygx_activity_voice AS v ON r.activity_id = v.activity_id
  692. WHERE 1=1 ` + condition + `
  693. ORDER BY create_time DESC LIMIT ?,? `
  694. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  695. return
  696. }
  697. // 用户音视频浏览列表
  698. func GetCygxRoadshowByCompanyWeekly(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
  699. o := orm.NewOrmUsingDB("hz_cygx")
  700. databaseName := utils.GetWeeklyDatabase()
  701. sql := `SELECT
  702. v.video_name AS media_title,
  703. r.create_time,
  704. r.real_name,
  705. r.mobile,
  706. r.company_name,
  707. r.company_id,
  708. "逻辑解析" AS file_type
  709. FROM
  710. cygx_micro_roadshow_video_history AS r
  711. INNER JOIN cygx_micro_roadshow_video AS v ON r.video_id = v.video_id
  712. INNER JOIN ` + databaseName + `.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
  713. WHERE 1=1 ` + condition + ` UNION ALL
  714. SELECT
  715. v.video_name AS media_title,
  716. r.create_time,
  717. r.real_name,
  718. r.mobile,
  719. r.company_name,
  720. r.company_id,
  721. "路演回放" AS file_type
  722. FROM
  723. cygx_activity_video_history AS r
  724. INNER JOIN cygx_activity_video AS v ON r.video_id = v.video_id
  725. INNER JOIN ` + databaseName + `.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
  726. WHERE 1=1 ` + condition + ` UNION ALL
  727. SELECT
  728. v.voice_name AS media_title,
  729. r.create_time,
  730. r.real_name,
  731. r.mobile,
  732. r.company_name,
  733. r.company_id,
  734. "路演回放" AS file_type
  735. FROM
  736. cygx_activity_voice_history AS r
  737. INNER JOIN cygx_activity_voice AS v ON r.activity_id = v.activity_id
  738. INNER JOIN ` + databaseName + `.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
  739. WHERE 1=1 ` + condition + `
  740. ORDER BY create_time DESC LIMIT ?,? `
  741. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  742. return
  743. }
  744. // 用户音视频浏览列表
  745. func GetCygxRoadshowByCompanyList(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
  746. o := orm.NewOrmUsingDB("hz_cygx")
  747. sql := `SELECT
  748. v.video_name AS media_title,
  749. r.create_time,
  750. r.real_name,
  751. r.mobile,
  752. r.company_name,
  753. r.company_id,
  754. ci.roadshow_num,
  755. ui.roadshow_num AS ui_roadshow_num,
  756. "逻辑解析" AS file_type
  757. FROM
  758. cygx_micro_roadshow_video_history AS r
  759. INNER JOIN cygx_micro_roadshow_video AS v ON r.video_id = v.video_id
  760. LEFT JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
  761. LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
  762. WHERE 1=1 ` + condition + ` UNION ALL
  763. SELECT
  764. v.video_name AS media_title,
  765. r.create_time,
  766. r.real_name,
  767. r.mobile,
  768. r.company_name,
  769. r.company_id,
  770. ci.roadshow_num,
  771. ui.roadshow_num AS ui_roadshow_num,
  772. "路演回放" AS file_type
  773. FROM
  774. cygx_activity_video_history AS r
  775. INNER JOIN cygx_activity_video AS v ON r.video_id = v.video_id
  776. LEFT JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
  777. LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
  778. WHERE 1=1 ` + condition + ` UNION ALL
  779. SELECT
  780. v.voice_name AS media_title,
  781. r.create_time,
  782. r.real_name,
  783. r.mobile,
  784. r.company_name,
  785. r.company_id,
  786. ci.roadshow_num,
  787. ui.roadshow_num AS ui_roadshow_num,
  788. "路演回放" AS file_type
  789. FROM
  790. cygx_activity_voice_history AS r
  791. INNER JOIN cygx_activity_voice AS v ON r.activity_id = v.activity_id
  792. LEFT JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
  793. LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
  794. WHERE 1=1 ` + condition + `
  795. ORDER BY create_time DESC LIMIT ?,? `
  796. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  797. return
  798. }
  799. // 根据时间获取机构互动总数统计
  800. func GetCompanyInteractionTableCountBytime(companyId int, startDate, endDate string) (item *GetUserInteractionTableCountResp, err error) {
  801. o := orm.NewOrmUsingDB("hz_cygx")
  802. sql := `SELECT
  803. ( 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.company_id = ? AND h.is_del = 0 AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS history_num,
  804. ( SELECT COUNT( 1 ) FROM cygx_article_collect AS h WHERE h.company_id = ? AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS count_num,
  805. ( SELECT COUNT( 1 ) FROM cygx_chart_collect AS h WHERE h.company_id = ? AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS chart_num,
  806. ( SELECT COUNT( 1 ) FROM cygx_industry_fllow AS h WHERE h.company_id = ? AND h.type = 1 AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS industry_fllow_num,
  807. ( SELECT COUNT( 1 ) FROM cygx_article_department_follow AS h WHERE h.company_id = ? AND h.type = 1 AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS department_follow_num,
  808. ( SELECT COUNT( 1 ) FROM cygx_search_key_word AS h WHERE h.company_id = ? AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS key_word_num,
  809. ( 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.company_id = ?
  810. AND t.activity_type=1 AND h.do_fail_type = 0 AND a.activity_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS on_line_num,
  811. ( 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.company_id = ?
  812. AND t.activity_type = 0 AND h.do_fail_type = 0 AND a.activity_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS office_num
  813. FROM
  814. dual `
  815. err = o.Raw(sql, companyId, companyId, companyId, companyId, companyId, companyId, companyId, companyId).QueryRow(&item)
  816. return
  817. }
  818. // 根据时间获取机构互动总数统计
  819. func GetCompanyInteractionTableCountBytimeold(companyId int, startDate, endDate string) (item *GetUserInteractionTableCountResp, err error) {
  820. o := orm.NewOrm()
  821. sql := `SELECT
  822. ( 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.company_id = u.company_id AND h.is_del = 0 AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS history_num,
  823. ( SELECT COUNT( 1 ) FROM cygx_article_collect AS h WHERE h.company_id = u.company_id AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS count_num,
  824. ( SELECT COUNT( 1 ) FROM cygx_chart_collect AS h WHERE h.company_id = u.company_id AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS chart_num,
  825. ( SELECT COUNT( 1 ) FROM cygx_industry_fllow AS h WHERE h.company_id = u.company_id AND h.type = 1 AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS industry_fllow_num,
  826. ( SELECT COUNT( 1 ) FROM cygx_article_department_follow AS h WHERE h.company_id = u.company_id AND h.type = 1 AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS department_follow_num,
  827. ( SELECT COUNT( 1 ) FROM cygx_search_key_word AS h WHERE h.company_id = u.company_id AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS key_word_num,
  828. ( 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.company_id = u.company_id
  829. AND t.activity_type=1 AND h.do_fail_type = 0 AND a.activity_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS on_line_num,
  830. ( 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.company_id = u.company_id
  831. AND t.activity_type = 0 AND h.do_fail_type = 0 AND a.activity_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS office_num
  832. FROM
  833. company as u
  834. WHERE
  835. u.company_id = ?`
  836. err = o.Raw(sql, companyId).QueryRow(&item)
  837. return
  838. }
  839. // 机构阅读记录列表
  840. func GetCygxArticleHistoryRecordByCompanyList(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
  841. o := orm.NewOrmUsingDB("hz_cygx")
  842. sql := ` SELECT
  843. art.title,
  844. art.article_id,
  845. art.article_id_md5,
  846. art.publish_date,
  847. art.category_name,
  848. re.chart_permission_name,
  849. re.chart_permission_id,
  850. r.create_time,
  851. r.mobile,
  852. r.user_id,
  853. r.company_name,
  854. r.company_id,
  855. r.real_name,
  856. r.stop_time,
  857. r.source as source_platform,
  858. ui.article_history_num
  859. FROM
  860. cygx_article_history_record_all AS r
  861. INNER JOIN cygx_article AS art ON art.article_id = r.article_id
  862. INNER JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
  863. INNER JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
  864. LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two
  865. WHERE
  866. 1=1 AND r.is_del = 0 ` + condition + ` GROUP BY r.id ORDER BY ci.article_history_num DESC ,ui.article_history_num DESC , r.create_time DESC `
  867. if startSize > 0 || pageSize > 0 {
  868. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  869. }
  870. _, err = o.Raw(sql).QueryRows(&items)
  871. return
  872. }
  873. // 获取机构参会记录
  874. func GetActivityMeetByCompanyList(condition string, startSize, pageSize int) (item []*UserInteraction, err error) {
  875. o := orm.NewOrmUsingDB("hz_cygx")
  876. sql := `SELECT
  877. t.activity_type,
  878. r.signup_type,
  879. r.is_meeting,
  880. r.mobile,
  881. r.real_name,
  882. a.activity_name,
  883. a.chart_permission_name,
  884. a.activity_type_name,
  885. a.label,
  886. a.activity_time,
  887. r.first_meeting_time,
  888. r.last_meeting_time,
  889. r.meeting_type_str,
  890. r.meeting_authentication,
  891. r.meeting_status_str,
  892. r.company_name,
  893. r.company_id,
  894. r.real_name,
  895. r.duration
  896. FROM
  897. cygx_activity_signup_detail AS r
  898. INNER JOIN cygx_activity AS a ON a.activity_id = r.activity_id
  899. INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
  900. WHERE
  901. 1 = 1
  902. AND r.do_fail_type = 0
  903. ` + condition + `
  904. GROUP BY
  905. r.id
  906. ORDER BY
  907. a.activity_time DESC,
  908. r.id DESC `
  909. if startSize > 0 || pageSize > 0 {
  910. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  911. }
  912. _, err = o.Raw(sql).QueryRows(&item)
  913. return
  914. }
  915. // 机构收藏列表
  916. func GetCygxArticleCollectByCompanyList(startSize, pageSize int, condition string) (items []*UserInteraction, err error) {
  917. o := orm.NewOrmUsingDB("hz_cygx")
  918. sql := ` SELECT
  919. art.title,
  920. art.article_id,
  921. art.report_id,
  922. art.article_id_md5,
  923. art.publish_date,
  924. re.chart_permission_name,
  925. re.chart_permission_id,
  926. r.create_time,
  927. r.mobile,
  928. r.real_name,
  929. re.match_type_name,
  930. r.company_name,
  931. r.company_id,
  932. (
  933. SELECT
  934. GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' )
  935. FROM
  936. cygx_industrial_subject AS s
  937. WHERE
  938. s.industrial_subject_id IN ( SELECT industrial_subject_id FROM cygx_industrial_article_group_subject AS sg WHERE sg.article_id = art.article_id )
  939. ) AS subject_name_str,
  940. (
  941. SELECT
  942. GROUP_CONCAT( DISTINCT man.industry_name SEPARATOR '/' )
  943. FROM
  944. cygx_industrial_management AS man
  945. WHERE
  946. 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 )
  947. ) AS industry_name
  948. FROM
  949. cygx_article_collect AS r
  950. INNER JOIN cygx_article AS art ON art.article_id = r.article_id
  951. LEFT JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
  952. LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
  953. LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two
  954. LEFT JOIN cygx_industrial_article_group_management AS man ON man.article_id = art.article_id
  955. WHERE
  956. 1=1 ` + condition + ` GROUP BY r.id
  957. ORDER BY r.create_time DESC `
  958. if startSize > 0 || pageSize > 0 {
  959. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  960. }
  961. _, err = o.Raw(sql).QueryRows(&items)
  962. return
  963. }
  964. // 关注产业列表
  965. func GetCygxIndustryFllowByCompanyList(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
  966. o := orm.NewOrmUsingDB("hz_cygx")
  967. sql := `SELECT
  968. m.industry_name,
  969. r.mobile,
  970. r.real_name,
  971. r.modify_time as create_time,
  972. r.company_name,
  973. r.company_id,
  974. ( SELECT GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' ) FROM cygx_industrial_subject AS s WHERE s.industrial_management_id = m.industrial_management_id ) AS subject_name_str
  975. FROM
  976. cygx_industry_fllow AS r
  977. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = r.industrial_management_id
  978. LEFT JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
  979. LEFT JOIN cygx_user_interaction_num as ui ON ui.user_id = r.user_id
  980. WHERE type = 1 AND r.source IN (0,1,2) ` + condition + ` ORDER BY r.create_time DESC LIMIT ?,? `
  981. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  982. return
  983. }
  984. // 关注作者机构列表
  985. func GetCygArticleDepartmentFollowByCompanyList(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
  986. o := orm.NewOrmUsingDB("hz_cygx")
  987. sql := `SELECT
  988. m.department_id,
  989. m.nick_name,
  990. r.modify_time as create_time,
  991. r.mobile,
  992. r.real_name,
  993. r.company_name,
  994. r.company_id,
  995. m.department_id,
  996. i.industry_name,
  997. a.title,
  998. a.article_id,
  999. ( SELECT MAX( create_time ) FROM cygx_article_department_follow WHERE user_id = r.user_id ) AS max_time,
  1000. ( 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,
  1001. ( 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
  1002. FROM
  1003. cygx_article_department_follow AS r
  1004. INNER JOIN cygx_article_department AS m ON m.department_id = r.department_id
  1005. INNER JOIN cygx_article AS a ON a.department_id = m.department_id
  1006. LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
  1007. LEFT JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
  1008. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  1009. LEFT JOIN cygx_industrial_management AS i ON i.industrial_management_id = mg.industrial_management_id
  1010. WHERE r.type = 1 ` + condition + ` GROUP BY r.id
  1011. ORDER BY max_time DESC LIMIT ?,? `
  1012. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  1013. return
  1014. }
  1015. // 用户搜索关键词列表
  1016. func GetCygxSearchKeyWordByCompanyList(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
  1017. o := orm.NewOrmUsingDB("hz_cygx")
  1018. sql := `SELECT
  1019. r.key_word,r.create_time,
  1020. r.mobile,
  1021. r.company_name,
  1022. r.company_id,
  1023. r.real_name
  1024. FROM
  1025. cygx_search_key_word as r
  1026. LEFT JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
  1027. LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
  1028. WHERE 1= 1 ` + condition + `
  1029. ORDER BY r.create_time DESC LIMIT ?,? `
  1030. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  1031. return
  1032. }
  1033. // 用户搜索关键词列表
  1034. func GetCygxActivitySpecialTripByCompanyList(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
  1035. o := orm.NewOrmUsingDB("hz_cygx")
  1036. sql := `SELECT
  1037. a.research_theme AS activity_name,
  1038. a.chart_permission_name,
  1039. a.activity_time_text_by_day AS activity_time_text,
  1040. a.city,
  1041. a.special_type AS activity_type,
  1042. r.mobile,
  1043. r.real_name,
  1044. r.is_meeting,
  1045. r.activity_id,
  1046. r.company_name,
  1047. r.seller_name,
  1048. r.real_name
  1049. FROM
  1050. cygx_activity_special_trip as r
  1051. INNER JOIN cygx_activity_special AS a ON a.activity_id = r.activity_id
  1052. LEFT JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
  1053. LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
  1054. WHERE 1= 1 ` + condition + `
  1055. ORDER BY r.create_time DESC LIMIT ?,? `
  1056. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  1057. return
  1058. }
  1059. type CompanyAndCount struct {
  1060. CompanyId int
  1061. Count int
  1062. }
  1063. // 获取用户参会记录数量根据公司分组
  1064. func GetActivityMeetGroupByCompany(condition string) (list []*CompanyAndCount, err error) {
  1065. o := orm.NewOrmUsingDB("hz_cygx")
  1066. sqlCount := ` SELECT
  1067. r.company_id,COUNT(*) AS count
  1068. FROM
  1069. cygx_activity_signup AS r
  1070. INNER JOIN cygx_activity AS a ON a.activity_id = r.activity_id
  1071. INNER JOIN cygx_activity_type AS t ON t.activity_type_id = a.activity_type_id
  1072. WHERE
  1073. 1 = 1
  1074. AND r.do_fail_type = 0 `
  1075. if condition != "" {
  1076. sqlCount += condition
  1077. }
  1078. sqlCount += ` GROUP BY r.company_id `
  1079. _, err = o.Raw(sqlCount).QueryRows(&list)
  1080. return
  1081. }
  1082. // 收藏列表数量根据公司分组
  1083. func GetCygxArticleCollectCountGroupByCompany(condition string) (list []*CompanyAndCount, err error) {
  1084. o := orm.NewOrmUsingDB("hz_cygx")
  1085. sqlCount := ` SELECT
  1086. r.company_id,
  1087. COUNT(*) AS count
  1088. FROM
  1089. cygx_article_collect AS r
  1090. INNER JOIN cygx_article AS art ON art.article_id = r.article_id
  1091. WHERE
  1092. 1 = 1 `
  1093. if condition != "" {
  1094. sqlCount += condition
  1095. }
  1096. sqlCount += ` GROUP BY r.company_id `
  1097. _, err = o.Raw(sqlCount).QueryRows(&list)
  1098. return
  1099. }
  1100. // 关注产业数量根据公司分组
  1101. func GetCygxIndustryFllowCountGroupByCompany(condition string) (list []*CompanyAndCount, err error) {
  1102. o := orm.NewOrmUsingDB("hz_cygx")
  1103. sqlCount := ` SELECT
  1104. r.company_id,
  1105. COUNT(*) AS count
  1106. FROM
  1107. cygx_industry_fllow AS r
  1108. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = r.industrial_management_id
  1109. WHERE
  1110. type = 1 `
  1111. if condition != "" {
  1112. sqlCount += condition
  1113. }
  1114. sqlCount += ` GROUP BY r.company_id `
  1115. _, err = o.Raw(sqlCount).QueryRows(&list)
  1116. return
  1117. }
  1118. // 关注作者数量根据公司分组
  1119. func GetCygArticleDepartmentFollowCountGroupByCompany(condition string) (list []*CompanyAndCount, err error) {
  1120. o := orm.NewOrmUsingDB("hz_cygx")
  1121. sqlCount := ` SELECT
  1122. r.company_id,
  1123. COUNT(*) AS count
  1124. FROM
  1125. cygx_article_department_follow AS r
  1126. INNER JOIN cygx_article_department AS m ON m.department_id = r.department_id
  1127. WHERE
  1128. type = 1 `
  1129. if condition != "" {
  1130. sqlCount += condition
  1131. }
  1132. sqlCount += ` GROUP BY r.company_id `
  1133. _, err = o.Raw(sqlCount).QueryRows(&list)
  1134. return
  1135. }
  1136. // 用户搜索关键词统计
  1137. func GetCygxSearchKeyWordCountGroupByCompany(condition string) (list []*CompanyAndCount, err error) {
  1138. o := orm.NewOrmUsingDB("hz_cygx")
  1139. sqlCount := ` SELECT
  1140. r.company_id,
  1141. COUNT(*) AS count
  1142. FROM
  1143. cygx_search_key_word AS r
  1144. WHERE
  1145. 1 = 1 ` + condition
  1146. if condition != "" {
  1147. sqlCount += condition
  1148. }
  1149. sqlCount += ` GROUP BY r.company_id `
  1150. _, err = o.Raw(sqlCount).QueryRows(&list)
  1151. return
  1152. }
  1153. func GetChartCountGroupByCompany(condition string) (list []*CompanyAndCount, err error) {
  1154. o := orm.NewOrmUsingDB("hz_cygx")
  1155. sqlCount := ` SELECT
  1156. r.company_id,
  1157. COUNT(*) AS count
  1158. FROM
  1159. cygx_chart_collect AS r
  1160. INNER JOIN cygx_chart_all AS a ON a.chart_id = r.chart_id
  1161. WHERE
  1162. 1 = 1 ` + condition
  1163. if condition != "" {
  1164. sqlCount += condition
  1165. }
  1166. sqlCount += ` GROUP BY r.company_id `
  1167. _, err = o.Raw(sqlCount).QueryRows(&list)
  1168. return
  1169. }
  1170. func GetCompanyCountGroupBySeller(condition string) (list []*company.CompanyReportRecordGroup, err error) {
  1171. o := orm.NewOrm()
  1172. sqlCount := ` SELECT
  1173. seller_id AS admin_id,
  1174. count(
  1175. DISTINCT ( company_id )) num,
  1176. GROUP_CONCAT( DISTINCT company_id SEPARATOR ',' ) AS company_ids
  1177. FROM company_product
  1178. WHERE 1=1 AND status="试用" ` + condition
  1179. if condition != "" {
  1180. sqlCount += condition
  1181. }
  1182. sqlCount += ` GROUP BY seller_id `
  1183. _, err = o.Raw(sqlCount).QueryRows(&list)
  1184. return
  1185. }
  1186. // 获取文章阅读记录根据公司分组
  1187. func GetArticleHistoryGroupByCompany(condition string) (list []*CompanyAndCount, err error) {
  1188. o := orm.NewOrmUsingDB("hz_cygx")
  1189. sqlCount := ` SELECT
  1190. r.company_id,COUNT(*) AS count
  1191. FROM
  1192. cygx_article_history_record_all AS r
  1193. WHERE
  1194. 1 = 1
  1195. AND r.is_del = 0
  1196. AND r.company_id >0 `
  1197. if condition != "" {
  1198. sqlCount += condition
  1199. }
  1200. sqlCount += ` GROUP BY r.company_id `
  1201. _, err = o.Raw(sqlCount).QueryRows(&list)
  1202. return
  1203. }