cygx_user_company.go 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241
  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 h.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 GetCygxArticleHistoryRecordByCompanyList(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
  820. o := orm.NewOrmUsingDB("hz_cygx")
  821. sql := ` SELECT
  822. art.title,
  823. art.article_id,
  824. art.article_id_md5,
  825. art.publish_date,
  826. art.category_name,
  827. re.chart_permission_name,
  828. re.chart_permission_id,
  829. r.create_time,
  830. r.mobile,
  831. r.user_id,
  832. r.company_name,
  833. r.company_id,
  834. r.real_name,
  835. r.stop_time,
  836. r.source as source_platform,
  837. ui.article_history_num
  838. FROM
  839. cygx_article_history_record_all AS r
  840. INNER JOIN cygx_article AS art ON art.article_id = r.article_id
  841. INNER JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
  842. INNER JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
  843. LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two
  844. WHERE
  845. 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 `
  846. if startSize > 0 || pageSize > 0 {
  847. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  848. }
  849. _, err = o.Raw(sql).QueryRows(&items)
  850. return
  851. }
  852. // 获取机构参会记录
  853. func GetActivityMeetByCompanyList(condition string, startSize, pageSize int) (item []*UserInteraction, err error) {
  854. o := orm.NewOrmUsingDB("hz_cygx")
  855. sql := `SELECT
  856. t.activity_type,
  857. r.signup_type,
  858. r.is_meeting,
  859. r.mobile,
  860. r.real_name,
  861. a.activity_name,
  862. a.chart_permission_name,
  863. a.activity_type_name,
  864. a.label,
  865. a.activity_time,
  866. r.first_meeting_time,
  867. r.last_meeting_time,
  868. r.meeting_type_str,
  869. r.meeting_authentication,
  870. r.meeting_status_str,
  871. r.company_name,
  872. r.company_id,
  873. r.real_name,
  874. r.duration
  875. FROM
  876. cygx_activity_signup_detail AS r
  877. INNER JOIN cygx_activity AS a ON a.activity_id = r.activity_id
  878. INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
  879. WHERE
  880. 1 = 1
  881. AND r.do_fail_type = 0
  882. ` + condition + `
  883. GROUP BY
  884. r.id
  885. ORDER BY
  886. a.activity_time DESC,
  887. r.id DESC `
  888. if startSize > 0 || pageSize > 0 {
  889. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  890. }
  891. _, err = o.Raw(sql).QueryRows(&item)
  892. return
  893. }
  894. // 机构收藏列表
  895. func GetCygxArticleCollectByCompanyList(startSize, pageSize int, condition string) (items []*UserInteraction, err error) {
  896. o := orm.NewOrmUsingDB("hz_cygx")
  897. sql := ` SELECT
  898. art.title,
  899. art.article_id,
  900. art.report_id,
  901. art.article_id_md5,
  902. art.publish_date,
  903. re.chart_permission_name,
  904. re.chart_permission_id,
  905. r.create_time,
  906. r.mobile,
  907. r.real_name,
  908. re.match_type_name,
  909. r.company_name,
  910. r.company_id,
  911. (
  912. SELECT
  913. GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' )
  914. FROM
  915. cygx_industrial_subject AS s
  916. WHERE
  917. s.industrial_subject_id IN ( SELECT industrial_subject_id FROM cygx_industrial_article_group_subject AS sg WHERE sg.article_id = art.article_id )
  918. ) AS subject_name_str,
  919. (
  920. SELECT
  921. GROUP_CONCAT( DISTINCT man.industry_name SEPARATOR '/' )
  922. FROM
  923. cygx_industrial_management AS man
  924. WHERE
  925. 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 )
  926. ) AS industry_name
  927. FROM
  928. cygx_article_collect AS r
  929. INNER JOIN cygx_article AS art ON art.article_id = r.article_id
  930. LEFT JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
  931. LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
  932. LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two
  933. LEFT JOIN cygx_industrial_article_group_management AS man ON man.article_id = art.article_id
  934. WHERE
  935. 1=1 ` + condition + ` GROUP BY r.id
  936. ORDER BY r.create_time DESC `
  937. if startSize > 0 || pageSize > 0 {
  938. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  939. }
  940. _, err = o.Raw(sql).QueryRows(&items)
  941. return
  942. }
  943. // 关注产业列表
  944. func GetCygxIndustryFllowByCompanyList(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
  945. o := orm.NewOrmUsingDB("hz_cygx")
  946. sql := `SELECT
  947. m.industry_name,
  948. r.mobile,
  949. r.real_name,
  950. r.modify_time as create_time,
  951. r.company_name,
  952. r.company_id,
  953. ( 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
  954. FROM
  955. cygx_industry_fllow AS r
  956. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = r.industrial_management_id
  957. LEFT JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
  958. LEFT JOIN cygx_user_interaction_num as ui ON ui.user_id = r.user_id
  959. WHERE type = 1 AND r.source IN (0,1,2) ` + condition + ` ORDER BY r.create_time DESC LIMIT ?,? `
  960. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  961. return
  962. }
  963. // 关注作者机构列表
  964. func GetCygArticleDepartmentFollowByCompanyList(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
  965. o := orm.NewOrmUsingDB("hz_cygx")
  966. sql := `SELECT
  967. m.department_id,
  968. m.nick_name,
  969. r.modify_time as create_time,
  970. r.mobile,
  971. r.real_name,
  972. r.company_name,
  973. r.company_id,
  974. m.department_id,
  975. i.industry_name,
  976. a.title,
  977. a.article_id,
  978. ( SELECT MAX( create_time ) FROM cygx_article_department_follow WHERE user_id = r.user_id ) AS max_time,
  979. ( 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,
  980. ( 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
  981. FROM
  982. cygx_article_department_follow AS r
  983. INNER JOIN cygx_article_department AS m ON m.department_id = r.department_id
  984. INNER JOIN cygx_article AS a ON a.department_id = m.department_id
  985. LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
  986. LEFT JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
  987. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  988. LEFT JOIN cygx_industrial_management AS i ON i.industrial_management_id = mg.industrial_management_id
  989. WHERE r.type = 1 ` + condition + ` GROUP BY r.id
  990. ORDER BY max_time DESC LIMIT ?,? `
  991. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  992. return
  993. }
  994. // 用户搜索关键词列表
  995. func GetCygxSearchKeyWordByCompanyList(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
  996. o := orm.NewOrmUsingDB("hz_cygx")
  997. sql := `SELECT
  998. r.key_word,r.create_time,
  999. r.mobile,
  1000. r.company_name,
  1001. r.company_id,
  1002. r.real_name
  1003. FROM
  1004. cygx_search_key_word as r
  1005. LEFT JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
  1006. LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
  1007. WHERE 1= 1 ` + condition + `
  1008. ORDER BY r.create_time DESC LIMIT ?,? `
  1009. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  1010. return
  1011. }
  1012. // 用户搜索关键词列表
  1013. func GetCygxActivitySpecialTripByCompanyList(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
  1014. o := orm.NewOrmUsingDB("hz_cygx")
  1015. sql := `SELECT
  1016. a.research_theme AS activity_name,
  1017. a.chart_permission_name,
  1018. a.activity_time_text_by_day AS activity_time_text,
  1019. a.city,
  1020. a.special_type AS activity_type,
  1021. r.mobile,
  1022. r.real_name,
  1023. r.is_meeting,
  1024. r.activity_id,
  1025. r.company_name,
  1026. r.seller_name,
  1027. r.real_name
  1028. FROM
  1029. cygx_activity_special_trip as r
  1030. INNER JOIN cygx_activity_special AS a ON a.activity_id = r.activity_id
  1031. LEFT JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
  1032. LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
  1033. WHERE 1= 1 ` + condition + `
  1034. ORDER BY r.create_time DESC LIMIT ?,? `
  1035. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  1036. return
  1037. }
  1038. type CompanyAndCount struct {
  1039. CompanyId int
  1040. Count int
  1041. }
  1042. // 获取用户参会记录数量根据公司分组
  1043. func GetActivityMeetGroupByCompany(condition string) (list []*CompanyAndCount, err error) {
  1044. o := orm.NewOrmUsingDB("hz_cygx")
  1045. sqlCount := ` SELECT
  1046. r.company_id,COUNT(*) AS count
  1047. FROM
  1048. cygx_activity_signup AS r
  1049. INNER JOIN cygx_activity AS a ON a.activity_id = r.activity_id
  1050. INNER JOIN cygx_activity_type AS t ON t.activity_type_id = a.activity_type_id
  1051. WHERE
  1052. 1 = 1
  1053. AND r.do_fail_type = 0 `
  1054. if condition != "" {
  1055. sqlCount += condition
  1056. }
  1057. sqlCount += ` GROUP BY r.company_id `
  1058. _, err = o.Raw(sqlCount).QueryRows(&list)
  1059. return
  1060. }
  1061. // 收藏列表数量根据公司分组
  1062. func GetCygxArticleCollectCountGroupByCompany(condition string) (list []*CompanyAndCount, err error) {
  1063. o := orm.NewOrmUsingDB("hz_cygx")
  1064. sqlCount := ` SELECT
  1065. r.company_id,
  1066. COUNT(*) AS count
  1067. FROM
  1068. cygx_article_collect AS r
  1069. INNER JOIN cygx_article AS art ON art.article_id = r.article_id
  1070. WHERE
  1071. 1 = 1 `
  1072. if condition != "" {
  1073. sqlCount += condition
  1074. }
  1075. sqlCount += ` GROUP BY r.company_id `
  1076. _, err = o.Raw(sqlCount).QueryRows(&list)
  1077. return
  1078. }
  1079. // 关注产业数量根据公司分组
  1080. func GetCygxIndustryFllowCountGroupByCompany(condition string) (list []*CompanyAndCount, err error) {
  1081. o := orm.NewOrmUsingDB("hz_cygx")
  1082. sqlCount := ` SELECT
  1083. r.company_id,
  1084. COUNT(*) AS count
  1085. FROM
  1086. cygx_industry_fllow AS r
  1087. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = r.industrial_management_id
  1088. WHERE
  1089. type = 1 `
  1090. if condition != "" {
  1091. sqlCount += condition
  1092. }
  1093. sqlCount += ` GROUP BY r.company_id `
  1094. _, err = o.Raw(sqlCount).QueryRows(&list)
  1095. return
  1096. }
  1097. // 关注作者数量根据公司分组
  1098. func GetCygArticleDepartmentFollowCountGroupByCompany(condition string) (list []*CompanyAndCount, err error) {
  1099. o := orm.NewOrmUsingDB("hz_cygx")
  1100. sqlCount := ` SELECT
  1101. r.company_id,
  1102. COUNT(*) AS count
  1103. FROM
  1104. cygx_article_department_follow AS r
  1105. INNER JOIN cygx_article_department AS m ON m.department_id = r.department_id
  1106. WHERE
  1107. type = 1 `
  1108. if condition != "" {
  1109. sqlCount += condition
  1110. }
  1111. sqlCount += ` GROUP BY r.company_id `
  1112. _, err = o.Raw(sqlCount).QueryRows(&list)
  1113. return
  1114. }
  1115. // 用户搜索关键词统计
  1116. func GetCygxSearchKeyWordCountGroupByCompany(condition string) (list []*CompanyAndCount, err error) {
  1117. o := orm.NewOrmUsingDB("hz_cygx")
  1118. sqlCount := ` SELECT
  1119. r.company_id,
  1120. COUNT(*) AS count
  1121. FROM
  1122. cygx_search_key_word AS r
  1123. WHERE
  1124. 1 = 1 ` + condition
  1125. if condition != "" {
  1126. sqlCount += condition
  1127. }
  1128. sqlCount += ` GROUP BY r.company_id `
  1129. _, err = o.Raw(sqlCount).QueryRows(&list)
  1130. return
  1131. }
  1132. func GetChartCountGroupByCompany(condition string) (list []*CompanyAndCount, err error) {
  1133. o := orm.NewOrmUsingDB("hz_cygx")
  1134. sqlCount := ` SELECT
  1135. r.company_id,
  1136. COUNT(*) AS count
  1137. FROM
  1138. cygx_chart_collect AS r
  1139. INNER JOIN cygx_chart_all AS a ON a.chart_id = r.chart_id
  1140. WHERE
  1141. 1 = 1 ` + condition
  1142. if condition != "" {
  1143. sqlCount += condition
  1144. }
  1145. sqlCount += ` GROUP BY r.company_id `
  1146. _, err = o.Raw(sqlCount).QueryRows(&list)
  1147. return
  1148. }
  1149. func GetCompanyCountGroupBySeller(condition string) (list []*company.CompanyReportRecordGroup, err error) {
  1150. o := orm.NewOrm()
  1151. sqlCount := ` SELECT
  1152. seller_id AS admin_id,
  1153. count(
  1154. DISTINCT ( company_id )) num,
  1155. GROUP_CONCAT( DISTINCT company_id SEPARATOR ',' ) AS company_ids
  1156. FROM company_product
  1157. WHERE 1=1 AND status="试用" ` + condition
  1158. if condition != "" {
  1159. sqlCount += condition
  1160. }
  1161. sqlCount += ` GROUP BY seller_id `
  1162. _, err = o.Raw(sqlCount).QueryRows(&list)
  1163. return
  1164. }
  1165. // 获取文章阅读记录根据公司分组
  1166. func GetArticleHistoryGroupByCompany(condition string) (list []*CompanyAndCount, err error) {
  1167. o := orm.NewOrmUsingDB("hz_cygx")
  1168. sqlCount := ` SELECT
  1169. r.company_id,COUNT(*) AS count
  1170. FROM
  1171. cygx_article_history_record_all AS r
  1172. WHERE
  1173. 1 = 1
  1174. AND r.is_del = 0
  1175. AND r.company_id >0 `
  1176. if condition != "" {
  1177. sqlCount += condition
  1178. }
  1179. sqlCount += ` GROUP BY r.company_id `
  1180. _, err = o.Raw(sqlCount).QueryRows(&list)
  1181. return
  1182. }