1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069 |
- package roadshow
- import (
- "fmt"
- "github.com/beego/beego/v2/client/orm"
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hz_crm_api/models/company"
- "hongze/hz_crm_api/models/system"
- "hongze/hz_crm_api/utils"
- "strings"
- "time"
- )
- type AddActivityReq struct {
- ActivityType string `description:"活动类型"`
- RoadshowType string `description:"路演形式"`
- RoadshowPlatform string `description:"路演平台"`
- CompanyId int `description:"客户id"`
- CompanyName string `description:"客户名称"`
- Province string `description:"省"`
- ProvinceCode string `description:"省编码"`
- City string `description:"市"`
- CityCode string `description:"市编码"`
- District string `description:"区"`
- Theme string `description:"会议主题"`
- CooperationName string `description:"合作方名称"`
- ActivityCategory string `description:"活动类别"`
- ResearcherList []*CalendarResearcher
- EnglishCompany int `description:"是否为英文客户"`
- }
- type CalendarResearcher struct {
- ResearcherId int `description:"研究员id"`
- ResearcherName string `description:"研究员名称"`
- StartDate string `description:"开始日期"`
- EndDate string `description:"结束日期"`
- StartTime string `description:"开始时间"`
- EndTime string `description:"结束时间"`
- StartWeek string `description:"开始日期对应周"`
- EndWeek string `description:"结束日期对应周"`
- }
- type RsCalendar struct {
- RsCalendarId int `orm:"column(rs_calendar_id);pk"`
- SysUserId int `description:"创建人id"`
- SysUserRealName string `description:"创建人名称"`
- ActivityType string `description:"活动类型"`
- RoadshowType string `description:"路演形式"`
- RoadshowPlatform string `description:"路演平台"`
- CompanyId int `description:"客户id"`
- CompanyName string `description:"客户名称"`
- Province string `description:"省"`
- ProvinceCode string `description:"省编码"`
- City string `description:"市"`
- CityCode string `description:"市编码"`
- District string `description:"区"`
- Theme string `description:"会议主题"`
- CooperationName string `description:"合作方名称"`
- Title string `description:"展示在日历的标题"`
- Source int8 `description:"来源,0:自系统,1:上海方的"`
- CreateTime time.Time
- ModifyTime time.Time
- ActivityCategory string `description:"活动类别"`
- IsSynced int `description:"是否与上海同步 0:未同步 1:已同步"`
- UnionCode string `description:"公开会议联合编码"`
- EnglishCompany int `description:"是否为英文客户: 0-否; 1-是"`
- SellerId int `description:"销售id"`
- ShareSellerId int `description:"共享销售员id"`
- }
- type RsCalendarResearcher struct {
- RsCalendarResearcherId int `orm:"column(rs_calendar_researcher_id);pk"`
- RsCalendarId int `description:"日历活动id"`
- ResearcherId int `description:"研究员id"`
- ResearcherName string `description:"研究员名称"`
- StartDate string `description:"开始日期"`
- EndDate string `description:"结束日期"`
- StartTime string `description:"开始时间"`
- EndTime string `description:"结束时间"`
- StartWeek string `description:"开始日期对应周"`
- EndWeek string `description:"结束日期对应周"`
- CreateTime time.Time
- ModifyTime time.Time
- Status int `description:"状态:1:待接受,2:已接受,3:已拒绝,4:已删除,5:已撤回,6:已结束"`
- RefuseReason string `description:"拒绝理由"`
- RefuseTime time.Time `description:"拒绝时间"`
- DeleteReason string `description:"删除理由"`
- DeleteTime time.Time `description:"删除时间"`
- ApproveTime time.Time `description:"接受时间"`
- IsSynced int `description:"是否与上海同步 0:未同步 1:已同步"`
- ResearcherSort int `description:"研究员新增排序"`
- UnionCode string `description:"公开会议联合编码"`
- }
- func GetRsCalendarById(rsCalendarId int) (item *RsCalendar, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM rs_calendar WHERE rs_calendar_id=? `
- err = o.Raw(sql, rsCalendarId).QueryRow(&item)
- return
- }
- func GetRsCalendarResearcherById(rsCalendarResearcherId int) (item *RsCalendarResearcher, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM rs_calendar_researcher WHERE rs_calendar_researcher_id=? `
- err = o.Raw(sql, rsCalendarResearcherId).QueryRow(&item)
- return
- }
- // Update 更新路演用户信息
- func (item *RsCalendarResearcher) Update(cols []string) (err error) {
- o := orm.NewOrm()
- _, err = o.Update(item, cols...)
- return
- }
- func GetRsCalendarResearcherListById(rsCalendarId int) (item []*RsCalendarResearcher, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM rs_calendar_researcher WHERE rs_calendar_id=? `
- _, err = o.Raw(sql, rsCalendarId).QueryRows(&item)
- return
- }
- // 根据多个路演ID获取研究员信息
- func GetRsCalendarResearcherListByIds(rsCalendarIds []int) (item []*RsCalendarResearcher, err error) {
- if len(rsCalendarIds) == 0 {
- return
- }
- o := orm.NewOrm()
- sql := `SELECT * FROM rs_calendar_researcher WHERE rs_calendar_id IN (` + utils.GetOrmInReplace(len(rsCalendarIds)) + `) `
- _, err = o.Raw(sql, rsCalendarIds).QueryRows(&item)
- return
- }
- func GetRsCalendarResearcherListByCalendarResearcherId(rsCalendarResearcherId int) (item []*RsCalendarResearcher, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM rs_calendar_researcher WHERE rs_calendar_researcher_id=? `
- _, err = o.Raw(sql, rsCalendarResearcherId).QueryRows(&item)
- return
- }
- // 添加RsCalendar
- func AddRsCalendar(item *RsCalendar) (lastId int64, err error) {
- o := orm.NewOrm()
- lastId, err = o.Insert(item)
- return
- }
- // 添加RsCalendarResearcher
- func AddRsCalendarResearcher(item *RsCalendarResearcher) (lastId int64, err error) {
- o := orm.NewOrm()
- lastId, err = o.Insert(item)
- return
- }
- // 添加RsCalendarResearcher
- func AddRsCalendarResearcherFromSH(item *RsCalendarResearcher) (bool bool, id int64, err error) {
- o := orm.NewOrm()
- bool, id, err = o.ReadOrCreate(item, "rs_calendar_id")
- return
- }
- type Researcher struct {
- AdminId int `description:"研究员id"`
- RealName string `description:"研究员名称"`
- GroupId int `description:"分组id"`
- GroupName string `description:"分组名称"`
- RoleTypeCode string `description:"角色编码"`
- }
- type ResearcherIds struct {
- AdminIds string `description:"研究员id"`
- }
- type ResearcherGroup struct {
- GroupId int `description:"分组id"`
- GroupName string `description:"分组名称"`
- AdminId int `description:"研究员id"`
- RealName string `description:"研究员名称"`
- RoleTypeCode string `description:"角色编码"`
- ResearcherList []*ResearcherGroup
- }
- func GetResearcherGroup() (list []*ResearcherGroup, err error) {
- o := orm.NewOrm()
- sql := ` SELECT group_id,group_name FROM admin AS a
- WHERE a.role_type_code IN('researcher','ficc_researcher','ficc_admin')
- AND a.enabled=1
- AND a.group_id>0
- AND a.group_name<>'无'
- GROUP BY a.group_id
- ORDER BY a.group_id ASC `
- _, err = o.Raw(sql).QueryRows(&list)
- return
- }
- func GetResearcher() (list []*ResearcherGroup, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM admin AS a
- WHERE a.role_type_code IN('researcher','rai_researcher','ficc_researcher','ficc_admin')
- AND a.enabled=1 AND a.real_name<>'于菲' `
- _, err = o.Raw(sql).QueryRows(&list)
- return
- }
- func GetChoiceResearcher(adminIds string) (list []*Researcher, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM admin WHERE admin_id IN ( ` + adminIds + ` ); `
- _, err = o.Raw(sql).QueryRows(&list)
- return
- }
- // GetResearcherV2 获取研究员列表(冻结的也要)
- func GetResearcherV2() (list []*ResearcherGroup, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM admin AS a
- WHERE a.role_type_code IN('researcher','rai_researcher','ficc_researcher','ficc_admin')
- AND a.enabled=1 and admin_id !=92 `
- _, err = o.Raw(sql).QueryRows(&list)
- return
- }
- // GetSellerGroup 获取销售分组
- func GetSellerGroup() (list []*ResearcherGroup, err error) {
- o := orm.NewOrm()
- sql := ` SELECT group_id,group_name FROM admin AS a
- WHERE a.role_type_code IN('ficc_seller','ficc_group')
- AND a.enabled=1
- AND a.group_id>0
- AND a.group_name<>'无'
- GROUP BY a.group_id
- ORDER BY a.group_id ASC `
- _, err = o.Raw(sql).QueryRows(&list)
- return
- }
- // GetSellerList 获取销售列表(冻结的也要)
- func GetSellerList(roleTypeCode string, groupIds string) (list []*Researcher, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM admin AS a
- WHERE a.role_type_code IN ` + roleTypeCode + `
- AND a.enabled=1 `
- if groupIds != "" {
- sql += "and group_id in " + groupIds
- }
- _, err = o.Raw(sql).QueryRows(&list)
- return
- }
- // GetRaiSellerList 获取权益销售列表(冻结的也要)
- func GetRaiSellerList(roleTypeCode string, groupIds string) (list []*Researcher, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM admin AS a
- WHERE a.role_type_code IN ` + roleTypeCode + `
- AND a.enabled=1 `
- if groupIds != "" {
- sql += "and group_id in " + groupIds
- }
- _, err = o.Raw(sql).QueryRows(&list)
- return
- }
- type CalendarListView struct {
- RsCalendarId int `orm:"column(rs_calendar_id);pk"`
- SysUserId int `description:"创建人id"`
- SysUserRealName string `description:"创建人名称"`
- ActivityType string `description:"活动类型"`
- RoadshowType string `description:"路演形式"`
- RoadshowPlatform string `description:"路演平台"`
- CompanyId int `description:"客户id"`
- CompanyName string `description:"客户名称"`
- RsCalendarResearcherId int `description:"活动研究员id"`
- ResearcherId string `description:"研究员id"`
- ResearcherName string `description:"研究员名称"`
- StartDate string `description:"开始日期"`
- EndDate string `description:"结束日期"`
- StartTime string `description:"开始时间"`
- EndTime string `description:"结束时间"`
- StartWeek string `description:"开始日期对应周"`
- EndWeek string `description:"结束日期对应周"`
- CreateTime string
- ModifyTime string
- Status int `description:"状态:1:待接受,2:已接受,3:已拒绝,4:已删除,5:已撤回,6:已结束"`
- RefuseReason string `description:"拒绝理由"`
- RefuseTime string `description:"拒绝时间"`
- DeleteReason string `description:"删除原因"`
- Province string `description:"省"`
- ProvinceCode string `description:"省编码"`
- City string `description:"市"`
- CityCode string `description:"市编码"`
- District string `description:"区"`
- Theme string `description:"会议主题"`
- CooperationName string `description:"合作方名称"`
- ActivityCategory string `description:"活动类别"`
- Source int `description:"来源,0:自系统,1:上海方的"`
- Title string `description:"日历展示标题"`
- CompanyStatus string `description:"新增客户状态"`
- UnionCode string `description:"公开会议联合编码"`
- EnglishCompany int `description:"是否为英文客户: 0-否; 1-是"`
- EnglishCountry string `description:"英文客户-国家"`
- EnglishViewTotal int `description:"英文客户-累计点击量"`
- SubmitButton bool `description:"提交按钮是否展示"`
- ViewButton bool `description:"查看按钮是否展示"`
- EditButton bool `description:"修改按钮是否展示"`
- }
- type CalendarListResp struct {
- Paging *paging.PagingItem
- List []*CalendarListView
- }
- func GetCalendarListCount(condition string, pars []interface{}, calendarType int) (count int, err error) {
- o := orm.NewOrm()
- if calendarType == 3 || calendarType == 4 {
- sql := `SELECT COUNT(1) AS count FROM(SELECT COUNT(1) AS count
- FROM rs_calendar AS a
- INNER JOIN rs_calendar_researcher AS b ON a.rs_calendar_id=b.rs_calendar_id
- WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- sql += ` GROUP BY a.rs_calendar_id ) AS t `
- err = o.Raw(sql, pars).QueryRow(&count)
- } else {
- sql := `SELECT COUNT(1) AS count FROM rs_calendar AS a
- INNER JOIN rs_calendar_researcher AS b ON a.rs_calendar_id=b.rs_calendar_id
- WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql, pars).QueryRow(&count)
- }
- return
- }
- func GetCalendarList(condition string, pars []interface{}, startSize, pageSize, calendarType int) (list []*CalendarListView, err error) {
- o := orm.NewOrm()
- if calendarType == 3 || calendarType == 4 {
- sql := ` SELECT a.rs_calendar_id,a.activity_type,a.roadshow_type,a.activity_category,a.roadshow_platform,b.create_time,a.district,
- b.modify_time,GROUP_CONCAT(b.researcher_id ORDER BY researcher_sort ASC) AS researcher_id,GROUP_CONCAT(b.researcher_name ORDER BY researcher_sort ASC) AS researcher_name,
- b.rs_calendar_researcher_id,b.start_date,
- b.end_date,b.start_time,b.end_time,b.start_week,b.end_week,b.status,b.refuse_reason,b.refuse_time,
- b.delete_reason,a.sys_user_real_name,a.city,a.province,a.company_name,a.company_id,
- a.cooperation_name,a.theme,a.activity_category,a.english_company
- FROM rs_calendar AS a
- INNER JOIN rs_calendar_researcher AS b ON a.rs_calendar_id=b.rs_calendar_id
- WHERE 1=1
- `
- if condition != "" {
- sql += condition
- }
- if calendarType == 1 {
- sql += ` GROUP BY a.rs_calendar_id
- ORDER BY b.create_time ASC LIMIT ?,? `
- } else {
- sql += ` GROUP BY a.rs_calendar_id
- ORDER BY b.create_time DESC LIMIT ?,? `
- }
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
- } else {
- sql := `SELECT a.rs_calendar_id,a.activity_type,a.roadshow_type,a.activity_category,a.roadshow_platform,b.create_time,a.district,a.sys_user_id,
- b.modify_time,b.researcher_id,b.researcher_name,
- b.rs_calendar_researcher_id,b.start_date,
- b.end_date,b.start_time,b.end_time,b.start_week,b.end_week,b.status,b.refuse_reason,b.refuse_time,
- b.delete_reason,a.sys_user_real_name,a.city,a.province,a.company_name,a.company_id,a.cooperation_name,a.theme,a.activity_category,a.english_company
- FROM rs_calendar AS a
- INNER JOIN rs_calendar_researcher AS b ON a.rs_calendar_id=b.rs_calendar_id
- WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- if calendarType == 1 {
- sql += ` ORDER BY b.create_time ASC LIMIT ?,? `
- } else {
- //sql += ` ORDER BY b.create_time DESC LIMIT ?,? `
- sql += ` ORDER BY b.start_date DESC , b.start_time DESC LIMIT ?,? ` // 已处理申请,按照活动开始时间倒序(包括ficc的)
- }
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
- }
- return
- }
- type AcceptReq struct {
- RsCalendarId int `description:"日历活动id"`
- RsCalendarResearcherId int `description:"活动研究员id"`
- }
- type DeleteReq struct {
- RsCalendarId int `description:"日历活动id"`
- RsCalendarResearcherId int `description:"活动研究员id"`
- DeleteReason string `description:"删除原因"`
- }
- type RefuseReq struct {
- RsCalendarId int `description:"日历活动id"`
- RsCalendarResearcherId int `description:"活动研究员id"`
- RefuseReason string `description:"拒绝原因"`
- }
- // 更新
- func UpdateCalendarResearcher(where, updateParams map[string]interface{}) error {
- o := orm.NewOrm()
- ptrStructOrTableName := "rs_calendar_researcher"
- qs := o.QueryTable(ptrStructOrTableName)
- for expr, exprV := range where {
- qs = qs.Filter(expr, exprV)
- }
- _, err := qs.Update(updateParams)
- return err
- }
- // 更新
- func UpdateCalendarResearcherFromSH(item *RsCalendarResearcher) error {
- o := orm.NewOrm()
- _, err := o.Update(item, "")
- return err
- }
- type AddMattersReq struct {
- StartDate string `description:"开始日期"`
- EndDate string `description:"结束日期"`
- StartTime string `description:"开始时间"`
- EndTime string `description:"结束时间"`
- StartWeek string `description:"开始日期周"`
- EndWeek string `description:"结束日期周"`
- MatterContent string `description:"事项内容"`
- }
- type RsMatters struct {
- RsMattersId int `orm:"column(rs_matters_id);pk"`
- SysUserId int `description:"添加事项人id"`
- SysUserRealName string `description:"创建人姓名"`
- StartDate string `description:"开始日期"`
- EndDate string `description:"结束日期"`
- StartTime string `description:"开始时间"`
- EndTime string `description:"结束时间"`
- StartWeek string `description:"开始日期周"`
- EndWeek string `description:"结束日期周"`
- MatterContent string `description:"事项内容"`
- Status int8 `description:"状态:1:进行中,6:已结束"`
- CreateTime time.Time `description:"创建时间"`
- ModifyTime time.Time `description:"修改时间"`
- IsSynced int `description:"是否与上海同步 0:未同步 1:已同步"`
- EditReason string `description:"修改原因"`
- IsSeller int `description:"是否为销售事项: 0-否; 1-是"`
- }
- // 添加RsCalendarResearcher
- func AddRsMatters(item *RsMatters) (id int64, err error) {
- o := orm.NewOrm()
- id, err = o.Insert(item)
- return
- }
- type UpdateMattersReq struct {
- RsMattersId int `orm:"column(rs_matters_id);pk"`
- StartDate string `description:"开始日期"`
- EndDate string `description:"结束日期"`
- StartTime string `description:"开始时间"`
- EndTime string `description:"结束时间"`
- StartWeek string `description:"开始日期周"`
- EndWeek string `description:"结束日期周"`
- MatterContent string `description:"事项内容"`
- EditReason string `description:"修改原因"`
- }
- // 更新
- func UpdateRsMatters(where, updateParams map[string]interface{}) error {
- o := orm.NewOrm()
- ptrStructOrTableName := "rs_matters"
- qs := o.QueryTable(ptrStructOrTableName)
- for expr, exprV := range where {
- qs = qs.Filter(expr, exprV)
- }
- _, err := qs.Update(updateParams)
- return err
- }
- type DeleteMattersReq struct {
- RsMattersId int `description:"事项id"`
- }
- // 删除事项
- func DeleteRsMatters(rsMattersId int) (err error) {
- o := orm.NewOrm()
- sql := ` DELETE FROM rs_matters WHERE rs_matters_id=? `
- _, err = o.Raw(sql, rsMattersId).Exec()
- return err
- }
- type RsMattersView struct {
- RsMattersId int `orm:"column(rs_matters_id);pk"`
- SysUserId int `description:"添加事项人id"`
- SysUserRealName string `description:"创建人姓名"`
- StartDate string `description:"开始日期"`
- EndDate string `description:"结束日期"`
- StartTime string `description:"开始时间"`
- EndTime string `description:"结束时间"`
- StartWeek string `description:"开始日期周"`
- EndWeek string `description:"结束日期周"`
- MatterContent string `description:"事项内容"`
- Status int8 `description:"状态:1:进行中,6:已结束"`
- CreateTime string `description:"创建时间"`
- ModifyTime string `description:"修改时间"`
- IsSynced int `description:"是否与上海同步 0:未同步 1:已同步"`
- EditReason string `description:"修改原因"`
- ButtonAuth RsMatterButton `description:"按钮权限"`
- }
- // RsMatterButton
- type RsMatterButton struct {
- EditDisabled bool `description:"禁用编辑"`
- RemoveDisabled bool `description:"禁用删除"`
- }
- func GetCalendarDetailList(condition string, pars []interface{}) (list []*CalendarListView, err error) {
- o := orm.NewOrm()
- sql := `SELECT a.*,b.*,c.status AS company_status FROM rs_calendar AS a
- INNER JOIN rs_calendar_researcher AS b ON a.rs_calendar_id=b.rs_calendar_id
- LEFT JOIN company_product AS c ON a.company_id=c.company_id AND c.product_id=1
- WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- sql += ` ORDER BY a.create_time DESC `
- _, err = o.Raw(sql, pars).QueryRows(&list)
- return
- }
- func GetCalendarDetailListinit() (list []*CalendarListView, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- a.rs_calendar_id,
- b.researcher_name , b.start_date , b.start_time,a.company_name ,sys_user_real_name
- FROM
- rs_calendar AS a
- INNER JOIN rs_calendar_researcher AS b ON a.rs_calendar_id = b.rs_calendar_id
- WHERE
- 1 = 1
- AND a.sys_user_id IN (SELECT admin_id FROM admin WHERE role_type_code IN ('rai_group','rai_seller') and role_id NOT IN (28,69,70) AND enabled = 1 )
- AND a.rs_calendar_id NOT IN (SELECT rs_calendar_id FROM rs_calendar_meeting_user GROUP BY rs_calendar_id )
- AND a.activity_type = '路演'
- AND b.start_date >= '2024-01-01'
- AND b.end_date <='2024-10-07'
- AND a.company_name !=''
- AND b.status IN (2,6)
- ORDER BY start_date ASC ,start_time ASC `
- _, err = o.Raw(sql).QueryRows(&list)
- return
- }
- func GetRsMattersList(startDate, endDate string, researcherId int) (list []*RsMatters, err error) {
- o := orm.NewOrm()
- //sql := `SELECT * FROM rs_matters AS a WHERE a.start_date>=? AND a.end_date<=? AND sys_user_id=? `
- sql := `SELECT * FROM rs_matters AS a WHERE sys_user_id=? `
- sql += ` ORDER BY a.create_time DESC `
- //_, err = o.Raw(sql, startDate, endDate, researcherId).QueryRows(&list)
- _, err = o.Raw(sql, researcherId).QueryRows(&list)
- return
- }
- type CalendarDetailResp struct {
- CalendarList []*CalendarListView
- RsMattersList []*RsMatters
- }
- type EditActivityReq struct {
- EditType int `description:"修改方式: 1:修改,2:修改重提"`
- RsCalendarId int `description:"路演活动id"`
- RsCalendarResearcherId int `description:"活动研究员id"`
- ActivityType string `description:"活动类型"`
- RoadshowType string `description:"路演形式"`
- RoadshowPlatform string `description:"路演平台"`
- CompanyId int `description:"客户id"`
- CompanyName string `description:"客户名称"`
- Province string `description:"省"`
- ProvinceCode string `description:"省编码"`
- City string `description:"市"`
- CityCode string `description:"市编码"`
- District string `description:"区"`
- Theme string `description:"会议主题"`
- CooperationName string `description:"合作方名称"`
- ActivityCategory string `description:"活动类别"`
- ResearcherList []*CalendarResearcher
- EnglishCompany int `description:"是否为英文客户"`
- }
- // 更新活动信息
- func UpdateRsCalendar(where, updateParams map[string]interface{}) error {
- o := orm.NewOrm()
- ptrStructOrTableName := "rs_calendar"
- qs := o.QueryTable(ptrStructOrTableName)
- for expr, exprV := range where {
- qs = qs.Filter(expr, exprV)
- }
- _, err := qs.Update(updateParams)
- return err
- }
- func GetMattersListCount(condition string, pars []interface{}) (count int, err error) {
- o := orm.NewOrm()
- sql := `SELECT COUNT(1) AS count FROM rs_matters AS a
- WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql, pars).QueryRow(&count)
- return
- }
- func GetMattersList(condition string, pars []interface{}, pageLimit ...int) (list []*RsMattersView, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM rs_matters AS a
- WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- sql += ` ORDER BY a.create_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, pars, pageLimit).QueryRows(&list)
- return
- }
- type MattersListResp struct {
- Paging *paging.PagingItem
- List []*RsMattersView
- }
- // 删除
- func DeleteCalendar(rsCalendarId, rsCalendarResearcherId int) (err error) {
- o := orm.NewOrm()
- sql := ` DELETE FROM rs_calendar_researcher WHERE rs_calendar_id=? `
- _, err = o.Raw(sql, rsCalendarId).Exec()
- if err != nil {
- return err
- }
- //var count int
- //sql = ` SELECT COUNT(1) AS count FROM rs_calendar_researcher WHERE rs_calendar_id=? `
- //err = o.Raw(sql, rsCalendarId).QueryRow(&count)
- //if err != nil && err.Error() != utils.ErrNoRow() {
- // return err
- //}
- //if count <= 0 {
- // sql := ` DELETE FROM rs_calendar WHERE rs_calendar_id=? `
- // _, err = o.Raw(sql, rsCalendarId).Exec()
- // if err != nil {
- // return err
- // }
- //}
- sql = ` DELETE FROM rs_calendar WHERE rs_calendar_id=? `
- _, err = o.Raw(sql, rsCalendarId).Exec()
- return err
- }
- // 删除
- func DeleteRsCalendarResearcher(rsCalendarId int) (err error) {
- o := orm.NewOrm()
- sql := ` DELETE FROM rs_calendar_researcher WHERE rs_calendar_id=? `
- _, err = o.Raw(sql, rsCalendarId).Exec()
- return err
- }
- func CheckMattersCount(condition string, pars []interface{}) (count int, err error) {
- o := orm.NewOrm()
- sql := `SELECT COUNT(1) AS count FROM rs_matters AS a
- WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql, pars).QueryRow(&count)
- return
- }
- func CheckCalendarResearcherCount(condition string, pars []interface{}) (count int, err error) {
- o := orm.NewOrm()
- sql := `SELECT COUNT(1) AS count FROM rs_calendar_researcher AS a
- WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql, pars).QueryRow(&count)
- return
- }
- func GetResearcherFromAdmin(condition string, pars []interface{}) (lists []*system.Admin, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM admin WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- _, err = o.Raw(sql, pars).QueryRows(&lists)
- return
- }
- func GetCreditCodeFromCompany(companyId int) (creditCode string, err error) {
- o := orm.NewOrm()
- companyItem := company.Company{CompanyId: companyId}
- err = o.Read(&companyItem)
- if err != nil {
- return "", err
- }
- creditCode = companyItem.CreditCode
- return
- }
- type SHCalendar struct {
- CalendarId int `description:"日历id"`
- UserPhone string `description:"创建人手机号"`
- ResearcherPhone string `description:"研究员手机号"`
- IndustryName string `description:"行业名称"`
- CreditCode string `description:"社会信用码"`
- content string `description:"日历内容"`
- StartTime string `description:"开始时间"`
- EndTime string `description:"结束时间"`
- }
- func GetRsCalendarResearcherByRsCalendarIdAndResearcherId(rsCalendarId, researcherId int) (item *RsCalendarResearcher, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM rs_calendar_researcher WHERE rs_calendar_id=? AND researcher_id=? `
- err = o.Raw(sql, rsCalendarId, researcherId).QueryRow(&item)
- return
- }
- // GetRsCalendarResearcherListByRsCalendarId 根据路演id获取路演研究员列表
- func GetRsCalendarResearcherListByRsCalendarId(rsCalendarId int) (items []*RsCalendarResearcher, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM rs_calendar_researcher WHERE rs_calendar_id=? `
- _, err = o.Raw(sql, rsCalendarId).QueryRows(&items)
- return
- }
- func GetMattersById(rsMatters int) (item *RsMatters, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM rs_matters
- WHERE rs_matters_id=? `
- err = o.Raw(sql, rsMatters).QueryRow(&item)
- return
- }
- func GetRsCalendarResearcherExist(rsCalendarResearcherId, rsCalendarId, researcherId int) (count int, err error) {
- o := orm.NewOrm()
- sql := `SELECT COUNT(1) AS count FROM rs_calendar_researcher WHERE rs_calendar_researcher_id=? AND rs_calendar_id=? AND researcher_id=? `
- err = o.Raw(sql, rsCalendarResearcherId, rsCalendarId, researcherId).QueryRow(&count)
- return
- }
- func GetRsCalendarResearcherByCalendarId(rsCalendarId int) (item []*RsCalendarResearcher, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM rs_calendar_researcher WHERE rs_calendar_id=? `
- _, err = o.Raw(sql, rsCalendarId).QueryRows(&item)
- return
- }
- type PublicMeetingDetailResp struct {
- Group []*PublicMeetingGroup
- }
- type PublicMeetingGroup struct {
- UnionCode string
- MinTime string
- MaxTime string
- CalendarList []*CalendarListView
- }
- func GetPublicCalendarDetailList(condition string, pars []interface{}) (list []*CalendarListView, err error) {
- o := orm.NewOrm()
- sql := `SELECT a.*,b.*,c.status AS company_status FROM rs_calendar AS a
- INNER JOIN rs_calendar_researcher AS b ON a.rs_calendar_id=b.rs_calendar_id
- LEFT JOIN company_product AS c ON a.company_id=c.company_id AND c.product_id=1
- INNER JOIN admin AS d ON b.researcher_id=d.admin_id
- WHERE 1=1 AND d.enabled=1 `
- if condition != "" {
- sql += condition
- }
- sql += ` ORDER BY a.create_time DESC `
- _, err = o.Raw(sql, pars).QueryRows(&list)
- return
- }
- type AdminInfo struct {
- AdminId int
- RealName string
- }
- func GetOverseaCustomCalendarSellerList() (list []*AdminInfo, err error) {
- o := orm.NewOrm()
- sql1 := `SELECT a.sys_user_id FROM rs_calendar AS a
- INNER JOIN rs_report_record AS b ON a.rs_calendar_id=b.rs_calendar_id
- JOIN company_product AS c ON a.company_id=c.company_id AND c.product_id=1
- JOIN company AS d ON c.company_id=d.company_id
- INNER JOIN overseas_custom_seller AS f ON c.seller_id=f.seller_id
- where c.is_overseas = 0 and a.english_company= 0 AND a.source = 0 AND b.rs_calendar_researcher_status=2 AND a.sys_user_id != 0 `
- sql2 := `SELECT aa.sys_user_id FROM rs_calendar AS aa
- INNER JOIN rs_report_record AS bb ON aa.rs_calendar_id=bb.rs_calendar_id
- where aa.english_company= 1 AND aa.source = 0 AND bb.rs_calendar_researcher_status=2 AND aa.sys_user_id != 0`
- sql := `SELECT n.admin_id,n.real_name FROM (` + sql1 + ` UNION ALL ` + sql2
- sql += ` ) AS m
- JOIN admin n on m.sys_user_id=n.admin_id
- WHERE 1=1 Group by sys_user_id order by sys_user_id asc`
- _, err = o.Raw(sql).QueryRows(&list)
- return
- }
- func GetOverseaCustomCalendarResearcherList() (list []*AdminInfo, err error) {
- o := orm.NewOrm()
- sql1 := `SELECT b.researcher_id FROM rs_calendar AS a
- INNER JOIN rs_report_record AS b ON a.rs_calendar_id=b.rs_calendar_id
- JOIN company_product AS c ON a.company_id=c.company_id AND c.product_id=1
- JOIN company AS d ON c.company_id=d.company_id
- INNER JOIN overseas_custom_seller AS f ON c.seller_id=f.seller_id
- where c.is_overseas = 0 and a.english_company= 0 AND a.source = 0 AND b.rs_calendar_researcher_status=2 AND b.researcher_id != 0`
- sql2 := `SELECT bb.researcher_id FROM rs_calendar AS aa
- INNER JOIN rs_report_record AS bb ON aa.rs_calendar_id=bb.rs_calendar_id
- where aa.english_company= 1 AND aa.source = 0 AND bb.rs_calendar_researcher_status=2 AND bb.researcher_id != 0 `
- sql := `SELECT n.admin_id,n.real_name FROM (` + sql1 + ` UNION ALL ` + sql2
- sql += ` ) AS m
- JOIN admin n on m.researcher_id=n.admin_id
- WHERE 1=1 Group by researcher_id order by researcher_id asc`
- _, err = o.Raw(sql).QueryRows(&list)
- return
- }
- type OverseaCustomRecordInfoResp struct {
- Paging *paging.PagingItem
- List []*OverseaCustomRecordInfo
- }
- type OverseaCustomRecordInfo struct {
- RsCalendarId int
- CompanyId int
- Source int
- RoadshowType string
- RoadshowPlatform string
- SellerName string
- ResearcherName string
- CompanyName string
- CompanyStatus string
- StartDate string
- }
- func GetOverseaCustomCalendarList(keyword, sellerId, researcherId, startDate, endDate, companyStatus, sortField, sortDesc string, startSize, pageSize int) (total int, list []*OverseaCustomRecordInfo, err error) {
- var databaseName string
- if utils.RunMode == "debug" {
- databaseName = "test_v2_hongze_rddp"
- } else {
- databaseName = "hongze_rddp"
- }
- companyStatusList := make([]string, 0)
- if companyStatus != "" {
- companyStatusList = strings.Split(companyStatus, ",")
- }
- lenCompanyStatusList := len(companyStatusList)
- o := orm.NewOrm()
- pars := make([]interface{}, 0)
- sql1 := `SELECT d.company_name,d.overseas_status company_status,b.start_date,a.rs_calendar_id,a.roadshow_type,a.roadshow_platform,a.sys_user_real_name seller_name,b.researcher_name as base_researcher_name,2 AS source,d.company_id FROM rs_calendar AS a
- INNER JOIN rs_report_record AS b ON a.rs_calendar_id=b.rs_calendar_id
- JOIN company_product AS c ON a.company_id=c.company_id AND c.product_id=1
- JOIN company AS d ON c.company_id=d.company_id
- INNER JOIN overseas_custom_seller AS f ON c.seller_id=f.seller_id
- where c.is_overseas = 0 and a.english_company= 0 AND a.source = 0 AND b.rs_calendar_researcher_status=2 AND b.researcher_id != 0`
- if keyword != "" {
- sql1 += ` AND d.company_name like ? `
- pars = utils.GetLikeKeywordPars(pars, keyword, 1)
- }
- if sellerId != "" {
- sql1 += fmt.Sprintf(` AND a.sys_user_id in (%s) `, sellerId)
- }
- if startDate != "" {
- sql1 += ` AND b.start_date >= ? `
- pars = append(pars, startDate)
- }
- if endDate != "" {
- sql1 += ` AND b.start_date <= ? `
- pars = append(pars, endDate)
- }
- if lenCompanyStatusList > 0 {
- sql1 += ` AND d.overseas_status in (` + utils.GetOrmInReplace(lenCompanyStatusList) + ") "
- pars = append(pars, companyStatusList)
- }
- sql2 := fmt.Sprintf(`SELECT cc.company_name,cc.overseas_status company_status,bb.start_date,aa.rs_calendar_id,aa.roadshow_type,aa.roadshow_platform,aa.sys_user_real_name seller_name,bb.researcher_name as base_researcher_name,1 AS source,cc.company_id+10000000 FROM rs_calendar AS aa
- INNER JOIN rs_report_record AS bb ON aa.rs_calendar_id=bb.rs_calendar_id
- INNER JOIN %s.english_company AS cc ON aa.company_id=cc.company_id
- where aa.english_company= 1 AND aa.source = 0 AND cc.is_deleted=0 AND bb.rs_calendar_researcher_status=2 AND bb.researcher_id != 0 `, databaseName)
- if keyword != "" {
- sql2 += ` AND cc.company_name like ? `
- pars = utils.GetLikeKeywordPars(pars, keyword, 1)
- }
- if sellerId != "" {
- sql2 += fmt.Sprintf(` AND aa.sys_user_id in (%s) `, sellerId)
- }
- if startDate != "" {
- sql2 += ` AND bb.start_date >= ? `
- pars = append(pars, startDate)
- }
- if endDate != "" {
- sql2 += ` AND bb.start_date <= ? `
- pars = append(pars, endDate)
- }
- if lenCompanyStatusList > 0 {
- sql2 += ` AND cc.overseas_status in (` + utils.GetOrmInReplace(lenCompanyStatusList) + ") "
- pars = append(pars, companyStatusList)
- }
- rsCalendarIdList := make([]int, 0)
- if researcherId != `` {
- rsCalendarIdSql := fmt.Sprintf("select rs_calendar_id from rs_calendar_researcher where researcher_id in (%s) group by rs_calendar_id", researcherId)
- _, err = o.Raw(rsCalendarIdSql).QueryRows(&rsCalendarIdList)
- if err != nil {
- return
- }
- }
- rsCalendarIdNum := len(rsCalendarIdList)
- // 汇总数据
- totalSql := `SELECT COUNT(1) FROM (SELECT rs_calendar_id FROM (` + sql1 + ` UNION ALL ` + sql2
- totalSql += ` ) AS m WHERE 1=1 `
- if rsCalendarIdNum > 0 {
- totalSql += fmt.Sprintf(` AND rs_calendar_id IN (` + utils.GetOrmInReplace(rsCalendarIdNum) + `)`)
- pars = append(pars, rsCalendarIdList)
- }
- totalSql += ` Group by rs_calendar_id) fff`
- err = o.Raw(totalSql, pars).QueryRow(&total)
- if err != nil {
- return
- }
- // 列表数据
- sql := `SELECT m.*,GROUP_CONCAT(DISTINCT base_researcher_name ORDER BY rs_calendar_id ASC SEPARATOR ',') AS researcher_name FROM (` + sql1 + ` UNION ALL ` + sql2
- sql += ` ) AS m WHERE 1=1 `
- if rsCalendarIdNum > 0 {
- sql += fmt.Sprintf(` AND rs_calendar_id IN (` + utils.GetOrmInReplace(rsCalendarIdNum) + `)`)
- }
- sql += fmt.Sprintf(` Group by rs_calendar_id order by %s %s `, sortField, sortDesc)
- sql += ` LIMIT ?,? `
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
- return
- }
- func GetOverseaCustomCalendarList2(sellerId, researcherId, startDate, endDate, companyStatus string) (list []*RsReportRecordList, err error) {
- var databaseName string
- if utils.RunMode == "debug" {
- databaseName = "test_v2_hongze_rddp"
- } else {
- databaseName = "hongze_rddp"
- }
- companyStatusList := make([]string, 0)
- if companyStatus != "" {
- companyStatusList = strings.Split(companyStatus, ",")
- }
- lenCompanyStatusList := len(companyStatusList)
- o := orm.NewOrm()
- pars := make([]interface{}, 0)
- sql1 := `SELECT b.start_date,b.end_date,b.start_time,b.end_time,a.rs_calendar_id,b.seller_id,b.seller_name,b.researcher_name,b.company_name,b.company_id,d.overseas_status as company_status,b.roadshow_type,a.theme,a.roadshow_platform,a.province as province,a.city as city FROM rs_calendar AS a
- INNER JOIN rs_report_record AS b ON a.rs_calendar_id=b.rs_calendar_id
- JOIN company_product AS c ON a.company_id=c.company_id AND c.product_id=1
- JOIN company AS d ON c.company_id=d.company_id
- INNER JOIN overseas_custom_seller AS f ON c.seller_id=f.seller_id
- where c.is_overseas = 0 and a.english_company= 0 AND a.source = 0 AND b.rs_calendar_researcher_status=2 AND b.researcher_id != 0`
- if startDate != "" {
- sql1 += ` AND b.start_date >= ? `
- pars = append(pars, startDate)
- }
- if endDate != "" {
- sql1 += ` AND b.start_date <= ? `
- pars = append(pars, endDate)
- }
- if lenCompanyStatusList > 0 {
- sql1 += ` AND d.overseas_status in (` + utils.GetOrmInReplace(lenCompanyStatusList) + ") "
- pars = append(pars, companyStatusList)
- }
- if sellerId != "" {
- sql1 += fmt.Sprintf(` AND b.seller_id in (%s) `, sellerId)
- }
- if researcherId != "" {
- sql1 += fmt.Sprintf(` AND b.researcher_id in (%s) `, researcherId)
- }
- sql2 := fmt.Sprintf(`SELECT bb.start_date,bb.end_date,bb.start_time,bb.end_time,aa.rs_calendar_id,bb.seller_id,bb.seller_name,bb.researcher_name,aa.company_name,aa.company_id,cc.overseas_status as company_status,bb.roadshow_type,aa.theme,aa.roadshow_platform,aa.province as province,aa.city as city FROM rs_calendar AS aa
- INNER JOIN rs_report_record AS bb ON aa.rs_calendar_id=bb.rs_calendar_id
- INNER JOIN %s.english_company AS cc ON aa.company_id=cc.company_id
- where aa.english_company= 1 AND aa.source = 0 AND cc.is_deleted=0 AND bb.rs_calendar_researcher_status=2 AND bb.researcher_id != 0 `, databaseName)
- if startDate != "" {
- sql2 += ` AND bb.start_date >= ? `
- pars = append(pars, startDate)
- }
- if endDate != "" {
- sql2 += ` AND bb.start_date <= ? `
- pars = append(pars, endDate)
- }
- if lenCompanyStatusList > 0 {
- sql2 += ` AND cc.overseas_status in (` + utils.GetOrmInReplace(lenCompanyStatusList) + ") "
- pars = append(pars, companyStatusList)
- }
- if sellerId != "" {
- sql2 += fmt.Sprintf(` AND bb.seller_id in (%s) `, sellerId)
- }
- if researcherId != "" {
- sql2 += fmt.Sprintf(` AND bb.researcher_id in (%s) `, researcherId)
- }
- // 列表数据
- sql := `SELECT m.* FROM (` + sql1 + ` UNION ALL ` + sql2
- sql += ` ) AS m WHERE 1=1 `
- sql += ` Group by rs_calendar_id `
- _, err = o.Raw(sql, pars).QueryRows(&list)
- return
- }
- func GetRsCalendarResearcherListInit16_2() (item []*RsCalendar, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM rs_calendar WHERE activity_type = '路演' AND company_id > 0 AND sys_user_id IN (SELECT admin_id FROM admin WHERE role_type_code IN ('rai_seller','rai_group','rai_admin') ) AND seller_id = 0 `
- _, err = o.Raw(sql).QueryRows(&item)
- return
- }
- // 修改可见范围
- func UpdateRsCalendarSeller(seller_id, share_seller_id, rs_calendar_id int) (err error) {
- o := orm.NewOrm()
- sql := `UPDATE rs_calendar SET seller_id=?, share_seller_id= ? WHERE rs_calendar_id =? `
- _, err = o.Raw(sql, seller_id, share_seller_id, rs_calendar_id).Exec()
- return
- }
- func GetCalendarListInit(condition string, pars []interface{}) (list []*CalendarListView, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- *
- FROM
- rs_calendar_researcher AS r
- INNER JOIN rs_calendar AS c ON r.rs_calendar_id = c.rs_calendar_id
- WHERE
- 1 = 1
-
- AND c.activity_type = '路演'
- AND c.company_name != ''
-
- AND r.start_date >= '2024-09-01'
- AND r.start_date <= '2024-12-31'
- AND r.STATUS IN ( 2, 6 ) ` + condition + `
- ORDER BY
- r.start_date DESC,
- r.start_time DESC`
- _, err = o.Raw(sql, pars).QueryRows(&list)
- return
- }
|