12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241 |
- package cygx
- import (
- "fmt"
- "github.com/beego/beego/v2/client/orm"
- "hongze/hz_crm_api/models/company"
- "hongze/hz_crm_api/utils"
- "strconv"
- )
- // 用户互动总数统计
- //func GetUserInteractionTableCountByCompany(companyId int) (item *GetUserInteractionTableCountResp, err error) {
- // o := orm.NewOrm()
- // sql := `SELECT
- // ( 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,
- // ( 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,
- // ( 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,
- // ( 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,
- // ( 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,
- // ( 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,
- // ( 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
- // 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,
- // ( 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
- // AND t.activity_type = 0 AND h.do_fail_type = 0 AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS office_num
- // FROM
- // company as u
- // WHERE
- // u.company_id = ?`
- // err = o.Raw(sql, companyId).QueryRow(&item)
- // return
- //}
- // 获取阅读记录数量
- //func GetCygxArticleHistoryCountByCompany(condition string) (count int, err error) {
- // o := orm.NewOrm()
- // sqlCount := ` SELECT COUNT( 1 ) AS count
- //FROM
- // (
- // SELECT
- // COUNT( 1 )
- // FROM
- // cygx_article_history_record_all AS r
- // INNER JOIN cygx_article AS art ON art.article_id = r.article_id
- // INNER JOIN company_product AS cp ON cp.company_id = r.company_id
- // AND cp.product_id = 2
- // INNER JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
- // INNER JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
- // LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two WHERE r.is_del = 0`
- // if condition != "" {
- // sqlCount += condition
- // }
- // sqlCount += ` GROUP BY r.id ) AS count `
- // err = o.Raw(sqlCount).QueryRow(&count)
- // return
- //}
- // 阅读记录列表
- func GetCygxArticleHistoryRecordByCompany(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := ` SELECT
- art.title,
- art.article_id,
- art.article_id_md5,
- art.publish_date,
- art.category_name,
- re.chart_permission_name,
- re.chart_permission_id,
- r.create_time,
- r.mobile,
- r.user_id,
- r.real_name,
- r.source as source_platform,
- r.stop_time
- FROM
- cygx_article_history_record_all AS r
- INNER JOIN cygx_article AS art ON art.article_id = r.article_id
- LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
- LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two
- LEFT JOIN cygx_industrial_article_group_management AS man ON man.article_id = art.article_id
- WHERE
- 1=1 AND r.is_del = 0 ` + condition + ` GROUP BY r.id ORDER BY ui.article_history_num DESC , r.create_time DESC `
- if startSize > 0 || pageSize > 0 {
- sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
- }
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // 获取用户参会记录数量
- func GetActivityMeetByCompanyCount(condition string) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := `SELECT
- COUNT(*) AS count
- FROM
- cygx_activity_signup_detail AS r
- INNER JOIN cygx_activity AS a ON a.activity_id = r.activity_id
- INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
- WHERE
- 1 = 1
- AND r.do_fail_type = 0`
- if condition != "" {
- sqlCount += condition
- }
- err = o.Raw(sqlCount).QueryRow(&count)
- return
- }
- // 获取用户参会记录数量(关联用户跟销售的绑定关系跨库查询)
- func GetActivityMeetByCompanyCountWeekly(condition string) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- databaseName := utils.GetWeeklyDatabase()
- sqlCount := `SELECT
- COUNT(*) AS count
- FROM
- cygx_activity_signup_detail AS r
- INNER JOIN cygx_activity AS a ON a.activity_id = r.activity_id
- INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
- INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE 1 = 1
- AND r.do_fail_type = 0`
- sqlCount = fmt.Sprintf(sqlCount, databaseName)
- if condition != "" {
- sqlCount += condition
- }
- err = o.Raw(sqlCount).QueryRow(&count)
- return
- }
- // 获取用户参会记录
- func GetActivityMeetByCompany(condition string, startSize, pageSize int) (item []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- t.activity_type,
- r.signup_type,
- r.is_meeting,
- r.mobile,
- r.real_name,
- a.activity_name,
- a.chart_permission_name,
- a.activity_type_name,
- a.label,
- a.activity_time,
- r.first_meeting_time,
- r.last_meeting_time,
- r.meeting_type_str,
- r.meeting_authentication,
- r.meeting_status_str,
- r.duration
- FROM
- cygx_activity_signup_detail AS r
- INNER JOIN cygx_activity AS a ON a.activity_id = r.activity_id
- INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
- LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
- WHERE
- 1 = 1
- AND r.do_fail_type = 0
- ` + condition + `
- GROUP BY
- r.id
- ORDER BY
- a.activity_time DESC ,r.id DESC `
- if startSize > 0 || pageSize > 0 {
- sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
- }
- _, err = o.Raw(sql).QueryRows(&item)
- return
- }
- // 获取用户参会记录(关联用户跟销售的绑定关系跨库查询)
- func GetActivityMeetByCompanyWeekly(condition string, startSize, pageSize int) (item []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- databaseName := utils.GetWeeklyDatabase()
- sql := `SELECT
- t.activity_type,
- r.signup_type,
- r.is_meeting,
- r.mobile,
- r.real_name,
- a.activity_name,
- a.chart_permission_name,
- a.activity_type_name,
- a.label,
- a.activity_time,
- r.first_meeting_time,
- r.last_meeting_time,
- r.meeting_type_str,
- r.meeting_authentication,
- r.meeting_status_str,
- r.company_name,
- r.company_id,
- r.real_name,
- r.duration
- FROM
- cygx_activity_signup_detail AS r
- INNER JOIN cygx_activity AS a ON a.activity_id = r.activity_id
- INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
- INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE
- 1 = 1 AND r.do_fail_type = 0 `
- sql = fmt.Sprintf(sql, databaseName)
- sql += condition + ` GROUP BY r.id ORDER BY a.activity_time DESC ,r.id DESC `
- if startSize > 0 || pageSize > 0 {
- sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
- }
- _, err = o.Raw(sql).QueryRows(&item)
- return
- }
- // 收藏列表数量
- func GetCygxArticleCollectCountByCompany(condition string) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := ` SELECT COUNT(1) AS count FROM cygx_article_collect as r INNER JOIN cygx_article AS art ON art.article_id = r.article_id
- WHERE 1=1 ` + condition
- err = o.Raw(sqlCount).QueryRow(&count)
- return
- }
- // 收藏列表数量(关联用户跟销售的绑定关系跨库查询)
- func GetCygxArticleCollectCountByCompanyWeekly(condition string) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- databaseName := utils.GetWeeklyDatabase()
- 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
- INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE 1=1 `
- sqlCount = fmt.Sprintf(sqlCount, databaseName)
- if condition != "" {
- sqlCount += condition
- }
- err = o.Raw(sqlCount).QueryRow(&count)
- return
- }
- // 收藏列表
- func GetCygxArticleCollectByCompany(startSize, pageSize int, condition string) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := ` SELECT
- art.title,
- art.article_id,
- art.article_id_md5,
- art.publish_date,
- re.chart_permission_name,
- re.chart_permission_id,
- r.create_time,
- r.mobile,
- r.real_name,
- re.match_type_name,
- (
- SELECT
- GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' )
- FROM
- cygx_industrial_subject AS s
- WHERE
- s.industrial_subject_id IN ( SELECT industrial_subject_id FROM cygx_industrial_article_group_subject AS sg WHERE sg.article_id = art.article_id )
- ) AS subject_name_str,
- (
- SELECT
- GROUP_CONCAT( DISTINCT man.industry_name SEPARATOR '/' )
- FROM
- cygx_industrial_management AS man
- WHERE
- 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 )
- ) AS industry_name
- FROM
- cygx_article_collect AS r
- INNER JOIN cygx_article AS art ON art.article_id = r.article_id
- LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
- LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two
- LEFT JOIN cygx_industrial_article_group_management AS man ON man.article_id = art.article_id
- WHERE
- 1=1 ` + condition + ` GROUP BY r.id
- ORDER BY r.create_time DESC `
- if startSize > 0 || pageSize > 0 {
- sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
- }
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // 收藏列表(关联用户跟销售的绑定关系跨库查询)
- func GetCygxArticleCollectByCompanyWeekly(startSize, pageSize int, condition string) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- databaseName := utils.GetWeeklyDatabase()
- sql := ` SELECT
- art.title,
- art.article_id,
- art.report_id,
- art.article_id_md5,
- art.publish_date,
- re.chart_permission_name,
- re.chart_permission_id,
- r.create_time,
- r.mobile,
- r.real_name,
- re.match_type_name,
- r.company_name,
- r.company_id,
- (
- SELECT
- GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' )
- FROM
- cygx_industrial_subject AS s
- WHERE
- s.industrial_subject_id IN ( SELECT industrial_subject_id FROM cygx_industrial_article_group_subject AS sg WHERE sg.article_id = art.article_id )
- ) AS subject_name_str,
- (
- SELECT
- GROUP_CONCAT( DISTINCT man.industry_name SEPARATOR '/' )
- FROM
- cygx_industrial_management AS man
- WHERE
- 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 )
- ) AS industry_name
- FROM
- cygx_article_collect AS r
- INNER JOIN cygx_article AS art ON art.article_id = r.article_id
- INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two
- LEFT JOIN cygx_industrial_article_group_management AS man ON man.article_id = art.article_id
- WHERE
- 1=1 `
- sql = fmt.Sprintf(sql, databaseName)
- sql += condition + ` GROUP BY r.id ORDER BY r.create_time DESC `
- if startSize > 0 || pageSize > 0 {
- sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
- }
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // 关注产业数量
- func GetCygxIndustryFllowCountByCompany(condition string) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := ` SELECT COUNT(1) AS count FROM cygx_industry_fllow AS r
- 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
- err = o.Raw(sqlCount).QueryRow(&count)
- return
- }
- // 关注产业数量(关联用户跟销售的绑定关系跨库查询)
- func GetCygxIndustryFllowCountByCompanyWeekly(condition string) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- databaseName := utils.GetWeeklyDatabase()
- sqlCount := ` SELECT COUNT(1) AS count FROM cygx_industry_fllow AS r
- INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = r.industrial_management_id
- 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) `
- sqlCount = fmt.Sprintf(sqlCount, databaseName)
- if condition != "" {
- sqlCount += condition
- }
- err = o.Raw(sqlCount).QueryRow(&count)
- return
- }
- // 关注产业列表
- func GetCygxIndustryFllowByCompany(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- m.industry_name,
- r.mobile,
- r.real_name,
- r.modify_time as create_time,
- ( 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
- FROM
- cygx_industry_fllow AS r
- 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 + ` ORDER BY r.id DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- // 关注产业列表
- func GetCygxIndustryFllowByCompanyWeekly(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- databaseName := utils.GetWeeklyDatabase()
- sql := `SELECT
- m.industry_name,
- r.mobile,
- r.real_name,
- r.company_name,
- r.company_id,
- r.modify_time as create_time,
- ( 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
- FROM
- cygx_industry_fllow AS r
- INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = r.industrial_management_id
- 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) `
- sql = fmt.Sprintf(sql, databaseName)
- if condition != "" {
- sql += condition
- }
- sql += ` ORDER BY r.id DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- // 关注作者数量
- func GetCygArticleDepartmentFollowCountByCompany(condition string) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := ` SELECT COUNT(1) AS count FROM cygx_article_department_follow AS r
- INNER JOIN cygx_article_department AS m ON m.department_id = r.department_id WHERE type = 1 ` + condition
- err = o.Raw(sqlCount).QueryRow(&count)
- return
- }
- // 关注作者数量
- func GetCygArticleDepartmentFollowCountByCompanyWeekly(condition string) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- databaseName := utils.GetWeeklyDatabase()
- sqlCount := ` SELECT COUNT(1) AS count FROM cygx_article_department_follow AS r
- INNER JOIN cygx_article_department AS m ON m.department_id = r.department_id
- INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE type = 1 `
- sqlCount = fmt.Sprintf(sqlCount, databaseName)
- if condition != "" {
- sqlCount += condition
- }
- err = o.Raw(sqlCount).QueryRow(&count)
- return
- }
- // 关注作者列表
- func GetCygArticleDepartmentFollowByCompany(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- m.department_id,
- m.nick_name,
- r.modify_time as create_time,
- r.mobile,
- r.real_name,
- m.department_id,
- a.title,
- a.article_id,
- ( SELECT MAX( create_time ) FROM cygx_article_department_follow WHERE user_id = r.user_id ) AS max_time
- FROM
- cygx_article_department_follow AS r
- INNER JOIN cygx_article_department AS m ON m.department_id = r.department_id
- INNER JOIN cygx_article AS a ON a.department_id = m.department_id
- WHERE r.type = 1 ` + condition + ` GROUP BY r.id
- ORDER BY max_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- // 关注作者列表
- func GetCygArticleDepartmentFollowByCompanyWeekly(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- databaseName := utils.GetWeeklyDatabase()
- sql := `SELECT
- m.department_id,
- m.nick_name,
- r.modify_time as create_time,
- r.mobile,
- r.real_name,
- m.department_id,
- a.title,
- a.article_id,
- r.company_name,
- r.company_id,
- ( SELECT MAX( create_time ) FROM cygx_article_department_follow WHERE user_id = r.user_id ) AS max_time
- FROM
- cygx_article_department_follow AS r
- INNER JOIN cygx_article_department AS m ON m.department_id = r.department_id
- INNER JOIN cygx_article AS a ON a.department_id = m.department_id
- INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE r.type = 1 `
- sql = fmt.Sprintf(sql, databaseName)
- if condition != "" {
- sql += condition
- }
- sql += ` GROUP BY r.id ORDER BY max_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- // 用户搜索关键词统计
- func GetCygxSearchKeyWordCountBuCompany(condition string) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := ` SELECT COUNT(1) AS count FROM cygx_search_key_word as r WHERE 1= 1 ` + condition
- err = o.Raw(sqlCount).QueryRow(&count)
- return
- }
- // 用户搜索关键词统计
- func GetCygxSearchKeyWordCountBuCompanyWeekly(condition string) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- databaseName := utils.GetWeeklyDatabase()
- sqlCount := ` SELECT COUNT(1) AS count FROM cygx_search_key_word as r
- INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE 1= 1 `
- sqlCount = fmt.Sprintf(sqlCount, databaseName)
- if condition != "" {
- sqlCount += condition
- }
- err = o.Raw(sqlCount).QueryRow(&count)
- return
- }
- // 用户搜索关键词列表
- func GetCygxSearchKeyWordByCompany(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- r.key_word,
- r.create_time,
- r.mobile,
- r.real_name
- FROM
- cygx_search_key_word as r
- WHERE 1= 1 ` + condition + `
- ORDER BY r.create_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- // 用户搜索关键词列表
- func GetCygxSearchKeyWordByCompanyWeekly(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- databaseName := utils.GetWeeklyDatabase()
- sql := `SELECT
- r.key_word,
- r.create_time,
- r.mobile,
- r.company_name,
- r.company_id,
- r.real_name
- FROM
- cygx_search_key_word as r
- INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE 1= 1 `
- sql = fmt.Sprintf(sql, databaseName)
- if condition != "" {
- sql += condition
- }
- sql += ` ORDER BY r.create_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- // 用户专项产业调研统计
- func GetCygxActivitySpecialTripCountByCompany(condition string) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := ` SELECT
- COUNT( 1 )
- FROM
- cygx_activity_special_meeting_detail AS r
- INNER JOIN cygx_activity_special AS a ON a.activity_id = r.activity_id
- WHERE
- 1 = 1
- AND a.publish_status = 1 ` + condition
- err = o.Raw(sqlCount).QueryRow(&count)
- return
- }
- // 用户专项产业调研统计
- func GetCygxActivitySpecialTripCountByCompanyWeekly(condition string) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- databaseName := utils.GetWeeklyDatabase()
- sqlCount := ` SELECT
- COUNT( 1 )
- FROM
- cygx_activity_special_meeting_detail AS r
- INNER JOIN cygx_activity_special AS a ON a.activity_id = r.activity_id
- INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE
- 1 = 1
- AND a.publish_status = 1 `
- sqlCount = fmt.Sprintf(sqlCount, databaseName)
- if condition != "" {
- sqlCount += condition
- }
- err = o.Raw(sqlCount).QueryRow(&count)
- return
- }
- // 用户专项产业调研列表
- func CygxActivitySpecialTripByCompany(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- a.research_theme AS activity_name,
- a.chart_permission_name,
- a.activity_time_text_by_day AS activity_time_text,
- a.city,
- a.special_type AS activity_type,
- r.mobile,
- r.activity_id,
- r.real_name,
- r.is_meeting
- FROM
- cygx_activity_special_meeting_detail AS r
- INNER JOIN cygx_activity_special AS a ON a.activity_id = r.activity_id
- WHERE 1= 1 AND a.publish_status = 1 ` + condition + `
- ORDER BY r.create_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- // 用户专项产业调研列表
- func CygxActivitySpecialTripByCompanyWeekly(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- databaseName := utils.GetWeeklyDatabase()
- sql := `SELECT
- a.research_theme AS activity_name,
- a.chart_permission_name,
- a.activity_time_text_by_day AS activity_time_text,
- a.city,
- a.special_type AS activity_type,
- r.mobile,
- r.activity_id,
- r.real_name,
- r.company_name,
- r.seller_name,
- r.company_id,
- r.is_meeting
- FROM
- cygx_activity_special_trip AS r
- INNER JOIN cygx_activity_special AS a ON a.activity_id = r.activity_id
- INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE 1= 1 AND a.publish_status = 1 `
- sql = fmt.Sprintf(sql, databaseName)
- if condition != "" {
- sql += condition
- }
- sql += ` ORDER BY r.create_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- // 用户音视频浏览统计
- func GetCygxRoadshowCountByCompany(condition string) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := `SELECT
- COUNT( 1 ) total
- FROM
- (
- SELECT
- ""
- FROM
- cygx_micro_roadshow_video_history AS r
- INNER JOIN cygx_micro_roadshow_video AS v ON r.video_id = v.video_id
- WHERE 1=1 ` + condition + ` UNION ALL
- SELECT
- ""
- FROM
- cygx_activity_video_history AS r
- INNER JOIN cygx_activity_video AS v ON r.video_id = v.video_id
- WHERE 1=1 ` + condition + ` UNION ALL
- SELECT
- ""
- FROM
- cygx_activity_voice_history AS r
- INNER JOIN cygx_activity_voice AS v ON r.activity_id = v.activity_id
- WHERE 1=1 ` + condition + `)z `
- err = o.Raw(sqlCount).QueryRow(&count)
- return
- }
- // 用户音视频浏览统计
- func GetCygxRoadshowCountByCompanyWeekly(condition string) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- databaseName := utils.GetWeeklyDatabase()
- sqlCount := `SELECT
- COUNT( 1 ) total
- FROM
- (
- SELECT
- ""
- FROM
- cygx_micro_roadshow_video_history AS r
- INNER JOIN cygx_micro_roadshow_video AS v ON r.video_id = v.video_id
- INNER JOIN ` + databaseName + `.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE 1=1 ` + condition + ` UNION ALL
- SELECT
- ""
- FROM
- cygx_activity_video_history AS r
- INNER JOIN cygx_activity_video AS v ON r.video_id = v.video_id
- INNER JOIN ` + databaseName + `.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE 1=1 ` + condition + ` UNION ALL
- SELECT
- ""
- FROM
- cygx_activity_voice_history AS r
- INNER JOIN cygx_activity_voice AS v ON r.activity_id = v.activity_id
- INNER JOIN ` + databaseName + `.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE 1=1 ` + condition + `)z `
- err = o.Raw(sqlCount).QueryRow(&count)
- return
- }
- // 用户音视频浏览列表
- func GetCygxRoadshowByCompany(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- v.video_name AS media_title,
- r.create_time,
- r.real_name,
- r.mobile,
- "逻辑解析" AS file_type
- FROM
- cygx_micro_roadshow_video_history AS r
- INNER JOIN cygx_micro_roadshow_video AS v ON r.video_id = v.video_id
- WHERE 1=1 ` + condition + ` UNION ALL
- SELECT
- v.video_name AS media_title,
- r.create_time,
- r.real_name,
- r.mobile,
- "路演回放" AS file_type
- FROM
- cygx_activity_video_history AS r
- INNER JOIN cygx_activity_video AS v ON r.video_id = v.video_id
- WHERE 1=1 ` + condition + ` UNION ALL
- SELECT
- v.voice_name AS media_title,
- r.create_time,
- r.real_name,
- r.mobile,
- "路演回放" AS file_type
- FROM
- cygx_activity_voice_history AS r
- INNER JOIN cygx_activity_voice AS v ON r.activity_id = v.activity_id
- WHERE 1=1 ` + condition + `
- ORDER BY create_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- // 用户音视频浏览列表
- func GetCygxRoadshowByCompanyWeekly(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- databaseName := utils.GetWeeklyDatabase()
- sql := `SELECT
- v.video_name AS media_title,
- r.create_time,
- r.real_name,
- r.mobile,
- r.company_name,
- r.company_id,
- "逻辑解析" AS file_type
- FROM
- cygx_micro_roadshow_video_history AS r
- INNER JOIN cygx_micro_roadshow_video AS v ON r.video_id = v.video_id
- INNER JOIN ` + databaseName + `.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE 1=1 ` + condition + ` UNION ALL
- SELECT
- v.video_name AS media_title,
- r.create_time,
- r.real_name,
- r.mobile,
- r.company_name,
- r.company_id,
- "路演回放" AS file_type
- FROM
- cygx_activity_video_history AS r
- INNER JOIN cygx_activity_video AS v ON r.video_id = v.video_id
- INNER JOIN ` + databaseName + `.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE 1=1 ` + condition + ` UNION ALL
- SELECT
- v.voice_name AS media_title,
- r.create_time,
- r.real_name,
- r.mobile,
- r.company_name,
- r.company_id,
- "路演回放" AS file_type
- FROM
- cygx_activity_voice_history AS r
- INNER JOIN cygx_activity_voice AS v ON r.activity_id = v.activity_id
- INNER JOIN ` + databaseName + `.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE 1=1 ` + condition + `
- ORDER BY create_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- // 用户音视频浏览列表
- func GetCygxRoadshowByCompanyList(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- v.video_name AS media_title,
- r.create_time,
- r.real_name,
- r.mobile,
- r.company_name,
- r.company_id,
- ci.roadshow_num,
- ui.roadshow_num AS ui_roadshow_num,
- "逻辑解析" AS file_type
- FROM
- cygx_micro_roadshow_video_history AS r
- INNER JOIN cygx_micro_roadshow_video AS v ON r.video_id = v.video_id
- LEFT JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
- LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
- WHERE 1=1 ` + condition + ` UNION ALL
- SELECT
- v.video_name AS media_title,
- r.create_time,
- r.real_name,
- r.mobile,
- r.company_name,
- r.company_id,
- ci.roadshow_num,
- ui.roadshow_num AS ui_roadshow_num,
- "路演回放" AS file_type
- FROM
- cygx_activity_video_history AS r
- INNER JOIN cygx_activity_video AS v ON r.video_id = v.video_id
- LEFT JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
- LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
- WHERE 1=1 ` + condition + ` UNION ALL
- SELECT
- v.voice_name AS media_title,
- r.create_time,
- r.real_name,
- r.mobile,
- r.company_name,
- r.company_id,
- ci.roadshow_num,
- ui.roadshow_num AS ui_roadshow_num,
- "路演回放" AS file_type
- FROM
- cygx_activity_voice_history AS r
- INNER JOIN cygx_activity_voice AS v ON r.activity_id = v.activity_id
- LEFT JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
- LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
- WHERE 1=1 ` + condition + `
- ORDER BY create_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- // 根据时间获取机构互动总数统计
- func GetCompanyInteractionTableCountBytime(companyId int, startDate, endDate string) (item *GetUserInteractionTableCountResp, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- ( 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,
- ( 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,
- ( 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,
- ( 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,
- ( 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,
- ( 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,
- ( 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 = ?
- 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,
- ( 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 = ?
- 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
- FROM
- dual `
- err = o.Raw(sql, companyId, companyId, companyId, companyId, companyId, companyId, companyId, companyId).QueryRow(&item)
- return
- }
- // 机构阅读记录列表
- func GetCygxArticleHistoryRecordByCompanyList(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := ` SELECT
- art.title,
- art.article_id,
- art.article_id_md5,
- art.publish_date,
- art.category_name,
- re.chart_permission_name,
- re.chart_permission_id,
- r.create_time,
- r.mobile,
- r.user_id,
- r.company_name,
- r.company_id,
- r.real_name,
- r.stop_time,
- r.source as source_platform,
- ui.article_history_num
- FROM
- cygx_article_history_record_all AS r
- INNER JOIN cygx_article AS art ON art.article_id = r.article_id
- INNER JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
- INNER JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
- LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two
- WHERE
- 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 `
- if startSize > 0 || pageSize > 0 {
- sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
- }
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // 获取机构参会记录
- func GetActivityMeetByCompanyList(condition string, startSize, pageSize int) (item []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- t.activity_type,
- r.signup_type,
- r.is_meeting,
- r.mobile,
- r.real_name,
- a.activity_name,
- a.chart_permission_name,
- a.activity_type_name,
- a.label,
- a.activity_time,
- r.first_meeting_time,
- r.last_meeting_time,
- r.meeting_type_str,
- r.meeting_authentication,
- r.meeting_status_str,
- r.company_name,
- r.company_id,
- r.real_name,
- r.duration
- FROM
- cygx_activity_signup_detail AS r
- INNER JOIN cygx_activity AS a ON a.activity_id = r.activity_id
- INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
- WHERE
- 1 = 1
- AND r.do_fail_type = 0
- ` + condition + `
- GROUP BY
- r.id
- ORDER BY
- a.activity_time DESC,
- r.id DESC `
- if startSize > 0 || pageSize > 0 {
- sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
- }
- _, err = o.Raw(sql).QueryRows(&item)
- return
- }
- // 机构收藏列表
- func GetCygxArticleCollectByCompanyList(startSize, pageSize int, condition string) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := ` SELECT
- art.title,
- art.article_id,
- art.report_id,
- art.article_id_md5,
- art.publish_date,
- re.chart_permission_name,
- re.chart_permission_id,
- r.create_time,
- r.mobile,
- r.real_name,
- re.match_type_name,
- r.company_name,
- r.company_id,
- (
- SELECT
- GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' )
- FROM
- cygx_industrial_subject AS s
- WHERE
- s.industrial_subject_id IN ( SELECT industrial_subject_id FROM cygx_industrial_article_group_subject AS sg WHERE sg.article_id = art.article_id )
- ) AS subject_name_str,
- (
- SELECT
- GROUP_CONCAT( DISTINCT man.industry_name SEPARATOR '/' )
- FROM
- cygx_industrial_management AS man
- WHERE
- 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 )
- ) AS industry_name
- FROM
- cygx_article_collect AS r
- INNER JOIN cygx_article AS art ON art.article_id = r.article_id
- LEFT JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
- LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
- LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two
- LEFT JOIN cygx_industrial_article_group_management AS man ON man.article_id = art.article_id
- WHERE
- 1=1 ` + condition + ` GROUP BY r.id
- ORDER BY r.create_time DESC `
- if startSize > 0 || pageSize > 0 {
- sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
- }
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // 关注产业列表
- func GetCygxIndustryFllowByCompanyList(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- m.industry_name,
- r.mobile,
- r.real_name,
- r.modify_time as create_time,
- r.company_name,
- r.company_id,
- ( 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
- FROM
- cygx_industry_fllow AS r
- INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = r.industrial_management_id
- LEFT JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
- LEFT JOIN cygx_user_interaction_num as ui ON ui.user_id = r.user_id
-
- WHERE type = 1 AND r.source IN (0,1,2) ` + condition + ` ORDER BY r.create_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- // 关注作者机构列表
- func GetCygArticleDepartmentFollowByCompanyList(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- m.department_id,
- m.nick_name,
- r.modify_time as create_time,
- r.mobile,
- r.real_name,
- r.company_name,
- r.company_id,
- m.department_id,
- i.industry_name,
- a.title,
- a.article_id,
- ( SELECT MAX( create_time ) FROM cygx_article_department_follow WHERE user_id = r.user_id ) AS max_time,
- ( 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,
- ( 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
- FROM
- cygx_article_department_follow AS r
- INNER JOIN cygx_article_department AS m ON m.department_id = r.department_id
- INNER JOIN cygx_article AS a ON a.department_id = m.department_id
- LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
- LEFT JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
- LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
- LEFT JOIN cygx_industrial_management AS i ON i.industrial_management_id = mg.industrial_management_id
- WHERE r.type = 1 ` + condition + ` GROUP BY r.id
- ORDER BY max_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- // 用户搜索关键词列表
- func GetCygxSearchKeyWordByCompanyList(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- r.key_word,r.create_time,
- r.mobile,
- r.company_name,
- r.company_id,
- r.real_name
- FROM
- cygx_search_key_word as r
- LEFT JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
- LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
- WHERE 1= 1 ` + condition + `
- ORDER BY r.create_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- // 用户搜索关键词列表
- func GetCygxActivitySpecialTripByCompanyList(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- a.research_theme AS activity_name,
- a.chart_permission_name,
- a.activity_time_text_by_day AS activity_time_text,
- a.city,
- a.special_type AS activity_type,
- r.mobile,
- r.real_name,
- r.is_meeting,
- r.activity_id,
- r.company_name,
- r.seller_name,
- r.real_name
- FROM
- cygx_activity_special_trip as r
- INNER JOIN cygx_activity_special AS a ON a.activity_id = r.activity_id
- LEFT JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
- LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
- WHERE 1= 1 ` + condition + `
- ORDER BY r.create_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- type CompanyAndCount struct {
- CompanyId int
- Count int
- }
- // 获取用户参会记录数量根据公司分组
- func GetActivityMeetGroupByCompany(condition string) (list []*CompanyAndCount, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := ` SELECT
- r.company_id,COUNT(*) AS count
- FROM
- cygx_activity_signup AS r
- INNER JOIN cygx_activity AS a ON a.activity_id = r.activity_id
- INNER JOIN cygx_activity_type AS t ON t.activity_type_id = a.activity_type_id
- WHERE
- 1 = 1
- AND r.do_fail_type = 0 `
- if condition != "" {
- sqlCount += condition
- }
- sqlCount += ` GROUP BY r.company_id `
- _, err = o.Raw(sqlCount).QueryRows(&list)
- return
- }
- // 收藏列表数量根据公司分组
- func GetCygxArticleCollectCountGroupByCompany(condition string) (list []*CompanyAndCount, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := ` SELECT
- r.company_id,
- COUNT(*) AS count
- FROM
- cygx_article_collect AS r
- INNER JOIN cygx_article AS art ON art.article_id = r.article_id
- WHERE
- 1 = 1 `
- if condition != "" {
- sqlCount += condition
- }
- sqlCount += ` GROUP BY r.company_id `
- _, err = o.Raw(sqlCount).QueryRows(&list)
- return
- }
- // 关注产业数量根据公司分组
- func GetCygxIndustryFllowCountGroupByCompany(condition string) (list []*CompanyAndCount, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := ` SELECT
- r.company_id,
- COUNT(*) AS count
- FROM
- cygx_industry_fllow AS r
- INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = r.industrial_management_id
- WHERE
- type = 1 `
- if condition != "" {
- sqlCount += condition
- }
- sqlCount += ` GROUP BY r.company_id `
- _, err = o.Raw(sqlCount).QueryRows(&list)
- return
- }
- // 关注作者数量根据公司分组
- func GetCygArticleDepartmentFollowCountGroupByCompany(condition string) (list []*CompanyAndCount, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := ` SELECT
- r.company_id,
- COUNT(*) AS count
- FROM
- cygx_article_department_follow AS r
- INNER JOIN cygx_article_department AS m ON m.department_id = r.department_id
- WHERE
- type = 1 `
- if condition != "" {
- sqlCount += condition
- }
- sqlCount += ` GROUP BY r.company_id `
- _, err = o.Raw(sqlCount).QueryRows(&list)
- return
- }
- // 用户搜索关键词统计
- func GetCygxSearchKeyWordCountGroupByCompany(condition string) (list []*CompanyAndCount, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := ` SELECT
- r.company_id,
- COUNT(*) AS count
- FROM
- cygx_search_key_word AS r
- WHERE
- 1 = 1 ` + condition
- if condition != "" {
- sqlCount += condition
- }
- sqlCount += ` GROUP BY r.company_id `
- _, err = o.Raw(sqlCount).QueryRows(&list)
- return
- }
- func GetChartCountGroupByCompany(condition string) (list []*CompanyAndCount, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := ` SELECT
- r.company_id,
- COUNT(*) AS count
- FROM
- cygx_chart_collect AS r
- INNER JOIN cygx_chart_all AS a ON a.chart_id = r.chart_id
- WHERE
- 1 = 1 ` + condition
- if condition != "" {
- sqlCount += condition
- }
- sqlCount += ` GROUP BY r.company_id `
- _, err = o.Raw(sqlCount).QueryRows(&list)
- return
- }
- func GetCompanyCountGroupBySeller(condition string) (list []*company.CompanyReportRecordGroup, err error) {
- o := orm.NewOrm()
- sqlCount := ` SELECT
- seller_id AS admin_id,
- count(
- DISTINCT ( company_id )) num,
- GROUP_CONCAT( DISTINCT company_id SEPARATOR ',' ) AS company_ids
- FROM company_product
- WHERE 1=1 AND status="试用" ` + condition
- if condition != "" {
- sqlCount += condition
- }
- sqlCount += ` GROUP BY seller_id `
- _, err = o.Raw(sqlCount).QueryRows(&list)
- return
- }
- // 获取文章阅读记录根据公司分组
- func GetArticleHistoryGroupByCompany(condition string) (list []*CompanyAndCount, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := ` SELECT
- r.company_id,COUNT(*) AS count
- FROM
- cygx_article_history_record_all AS r
-
- WHERE
- 1 = 1
- AND r.is_del = 0
- AND r.company_id >0 `
- if condition != "" {
- sqlCount += condition
- }
- sqlCount += ` GROUP BY r.company_id `
- _, err = o.Raw(sqlCount).QueryRows(&list)
- return
- }
|