123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945 |
- package roadshow
- import (
- "fmt"
- "hongze/hz_crm_api/models/company"
- "hongze/hz_crm_api/models/overseas_custom"
- "hongze/hz_crm_api/models/roadshow"
- "hongze/hz_crm_api/utils"
- "time"
- )
- // GetWeekData 周度数据
- func GetWeekData(adminType, dimensionType string) (adminDataList []AdminDataMap, firstDate time.Time, err error) {
- nowWeekMonday := utils.GetNowWeekMonday() //本周周一
- //fmt.Println(nowWeekMonday)
- nowWeekSunday := nowWeekMonday.AddDate(0, 0, 7).Add(-1 * time.Second) //本周周日
- //fmt.Println(nowWeekSunday)
- //nowWeekMonday = nowWeekMonday.AddDate(0, 0, -30) //上周周一
- //nowWeekSunday = nowWeekSunday.AddDate(0, 0, -30) //上周周日
- //adminDataMap, err := getSectionData(nowWeekMonday, nowWeekSunday)
- //if err != nil {
- // fmt.Println(err)
- // return
- //}
- //fmt.Println(adminDataMap)
- lastWeekMonday := nowWeekMonday.AddDate(0, 0, -7) //上周周一
- //fmt.Println(lastWeekMonday)
- //最早的一天
- firstDate = lastWeekMonday
- lastWeekSunday := nowWeekSunday.AddDate(0, 0, -7) //上周周日
- //fmt.Println(lastWeekSunday)
- nextWeekMonday := nowWeekMonday.AddDate(0, 0, 7) //下周周一
- //fmt.Println(nextWeekMonday)
- nextWeekSunday := nowWeekSunday.AddDate(0, 0, 7) //下周周日
- //fmt.Println(nextWeekSunday)
- ch1 := make(chan AdminDataMap, 0)
- ch2 := make(chan AdminDataMap, 0)
- ch3 := make(chan AdminDataMap, 0)
- go getSectionData(lastWeekMonday, lastWeekSunday, adminType, dimensionType, ch1)
- go getSectionData(nowWeekMonday, nowWeekSunday, adminType, dimensionType, ch2)
- go getSectionData(nextWeekMonday, nextWeekSunday, adminType, dimensionType, ch3)
- var nowWeekAdminDataMap, lastWeekAdminDataMap, nextWeekAdminDataMap AdminDataMap
- lastWeekAdminDataMap = <-ch1
- close(ch1)
- nowWeekAdminDataMap = <-ch2
- close(ch2)
- nextWeekAdminDataMap = <-ch3
- close(ch3)
- adminDataList = make([]AdminDataMap, 0)
- adminDataList = append(adminDataList, lastWeekAdminDataMap, nowWeekAdminDataMap, nextWeekAdminDataMap)
- return
- }
- // GetWeekDataV2 周度数据
- func GetWeekDataV2(adminType, dimensionType string, weekNum int) (adminDataList []AdminDataMap, firstDate time.Time, err error) {
- nowWeekMonday := utils.GetNowWeekMonday() //本周周一
- //fmt.Println(nowWeekMonday)
- nowWeekSunday := nowWeekMonday.AddDate(0, 0, 7).Add(-1 * time.Second) //本周周日
- chanList := make([]chan AdminDataMap, 0)
- for i := 0; i < weekNum; i++ {
- tmpCh := make(chan AdminDataMap, 0)
- chanList = append(chanList, tmpCh)
- lastWeekMonday := nowWeekMonday.AddDate(0, 0, -7*i)
- lastWeekSunday := nowWeekSunday.AddDate(0, 0, -7*i)
- // 第一个开始日期
- firstDate = lastWeekMonday
- go getSectionData(lastWeekMonday, lastWeekSunday, adminType, dimensionType, tmpCh)
- }
- adminDataList = make([]AdminDataMap, 0)
- for _, vChan := range chanList {
- var weekAdminDataMap AdminDataMap
- weekAdminDataMap = <-vChan
- close(vChan)
- adminDataList = append(adminDataList, weekAdminDataMap)
- }
- return
- }
- // GetMonthData 月度数据
- func GetMonthData(adminType, dimensionType string) (adminDataMapList []AdminDataMap, firstDate time.Time, err error) { //三个协程返回
- nowMonthFirstDay := utils.GetNowMonthFirstDay() //本月第一天
- nowMonthLastDay := nowMonthFirstDay.AddDate(0, 1, 0).Add(-1 * time.Second) //本月最后一天
- lastMonthFirstDay1 := nowMonthFirstDay.AddDate(0, -1, 0) //上个月第一天
- lastMonthLastDay1 := lastMonthFirstDay1.AddDate(0, 1, 0).Add(-1 * time.Second) //上个月最后一天
- lastMonthFirstDay2 := nowMonthFirstDay.AddDate(0, -2, 0) //上上个月第一天
- lastMonthLastDay2 := lastMonthFirstDay2.AddDate(0, 1, 0).Add(-1 * time.Second) //上上个月最后一天
- lastMonthFirstDay3 := nowMonthFirstDay.AddDate(0, -3, 0) //上上上个月第一天
- lastMonthLastDay3 := lastMonthFirstDay3.AddDate(0, 1, 0).Add(-1 * time.Second) //上上上个月最后一天
- //最早的一天
- firstDate = lastMonthFirstDay3
- ch1 := make(chan AdminDataMap, 0)
- ch2 := make(chan AdminDataMap, 0)
- ch3 := make(chan AdminDataMap, 0)
- ch4 := make(chan AdminDataMap, 0)
- go getSectionData(nowMonthFirstDay, nowMonthLastDay, adminType, dimensionType, ch1)
- go getSectionData(lastMonthFirstDay1, lastMonthLastDay1, adminType, dimensionType, ch2)
- go getSectionData(lastMonthFirstDay2, lastMonthLastDay2, adminType, dimensionType, ch3)
- go getSectionData(lastMonthFirstDay3, lastMonthLastDay3, adminType, dimensionType, ch4)
- var nowMonthAdminDataMap, lastMonthAdminDataMap1, lastMonthAdminDataMap2, lastMonthAdminDataMap3 AdminDataMap
- nowMonthAdminDataMap = <-ch1
- close(ch1)
- lastMonthAdminDataMap1 = <-ch2
- close(ch2)
- lastMonthAdminDataMap2 = <-ch3
- close(ch3)
- lastMonthAdminDataMap3 = <-ch4
- close(ch4)
- adminDataMapList = make([]AdminDataMap, 0)
- adminDataMapList = append(adminDataMapList, nowMonthAdminDataMap, lastMonthAdminDataMap1, lastMonthAdminDataMap2, lastMonthAdminDataMap3)
- return
- }
- // GetMonthDataV2 月度数据
- func GetMonthDataV2(adminType, dimensionType string, dataNum int) (adminDataMapList []AdminDataMap, firstDate time.Time, err error) { //三个协程返回
- nowMonthFirstDay := utils.GetNowMonthFirstDay() //本月第一天
- //nowMonthLastDay := nowMonthFirstDay.AddDate(0, 1, 0).Add(-1 * time.Second) //本月最后一天
- chanList := make([]chan AdminDataMap, 0)
- for i := 0; i < dataNum; i++ {
- tmpCh := make(chan AdminDataMap, 0)
- chanList = append(chanList, tmpCh)
- lastMonthFirstDay := nowMonthFirstDay.AddDate(0, -1*i, 0) //上个月第一天
- lastMonthLastDay := nowMonthFirstDay.AddDate(0, -1*(i-1), 0).Add(-1 * time.Second) //上个月最后一天
- // 第一个开始日期
- firstDate = lastMonthFirstDay
- go getSectionData(lastMonthFirstDay, lastMonthLastDay, adminType, dimensionType, tmpCh)
- }
- adminDataMapList = make([]AdminDataMap, 0)
- for _, vChan := range chanList {
- var monthAdminDataMap AdminDataMap
- monthAdminDataMap = <-vChan
- close(vChan)
- adminDataMapList = append(adminDataMapList, monthAdminDataMap)
- }
- return
- }
- // GetTimeIntervalData 区间数据
- func GetTimeIntervalData(startDate, endDate, adminType, dimensionType string) (adminDataMapList []AdminDataMap, firstDate time.Time, err error) { //三个协程返回
- startDateTimer, _ := time.ParseInLocation(utils.FormatDate, startDate, time.Local)
- endDateTimer, _ := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
- endDateTimer = endDateTimer.AddDate(0, 0, 1).Add(-1 * time.Second) //本月最后一天
- //最早的一天
- firstDate = startDateTimer
- ch1 := make(chan AdminDataMap, 0)
- go getSectionData(startDateTimer, endDateTimer, adminType, dimensionType, ch1)
- var adminDataMap AdminDataMap
- adminDataMap = <-ch1
- close(ch1)
- adminDataMapList = make([]AdminDataMap, 0)
- adminDataMapList = append(adminDataMapList, adminDataMap)
- return
- }
- type AdminDataMap struct {
- TryOutMap map[int]int `description:"试用路演次数"`
- FormalMap map[int]int `description:"正式路演次数"`
- MeetingMap map[int]int `description:"会议次数"`
- OnlineMap map[int]int `description:"线上路演次数"`
- OfflineMap map[int]int `description:"线上路演次数"`
- StartDate string `description:"开始日期"`
- EndDate string `description:"开始日期"`
- }
- // getSectionData 获取周期数据
- func getSectionData(startDate, endDate time.Time, adminType, dimensionType string, ch chan AdminDataMap) (adminDataMap AdminDataMap, err error) {
- defer func() {
- ch <- adminDataMap
- }()
- //adminType := `seller`
- switch adminType {
- case "researcher":
- adminDataMap, err = getResearcherSectionData(startDate, endDate)
- case "seller":
- adminDataMap, err = getSellerSectionData(startDate, endDate, dimensionType)
- }
- return
- }
- // getResearcherSectionData 获取研究员周期数据
- func getResearcherSectionData(startDate, endDate time.Time) (adminDataMap AdminDataMap, err error) {
- tryOutMap := make(map[int]int)
- formalMap := make(map[int]int)
- meetingMap := make(map[int]int)
- //正式客户
- {
- var condition string
- var pars []interface{}
- condition = ` and start_date >= ? and end_date <= ? and company_status = ? `
- pars = append(pars, startDate, endDate, "正式")
- data, tmpErr := roadshow.GetGroupResearcherRecordList(condition, pars)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range data {
- formalMap[v.AdminId] = v.Num
- }
- }
- //试用客户
- {
- var condition string
- var pars []interface{}
- condition = ` and start_date >= ? and end_date <= ? and company_status = ? `
- pars = append(pars, startDate, endDate, "试用")
- data, tmpErr := roadshow.GetGroupResearcherRecordList(condition, pars)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range data {
- //fmt.Println(v)
- tryOutMap[v.AdminId] = v.Num
- }
- }
- //试用客户
- {
- var condition string
- var pars []interface{}
- condition = ` and start_date >= ? and end_date <= ? and activity_type = ? `
- pars = append(pars, startDate, endDate, "公开会议")
- data, tmpErr := roadshow.GetGroupResearcherRecordList(condition, pars)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range data {
- //fmt.Println(v)
- meetingMap[v.AdminId] = v.Num
- }
- }
- adminDataMap = AdminDataMap{
- TryOutMap: tryOutMap,
- FormalMap: formalMap,
- MeetingMap: meetingMap,
- StartDate: startDate.Format(utils.FormatDate),
- EndDate: endDate.Format(utils.FormatDate),
- }
- return
- }
- // getSellerSectionData 获取销售周期数据
- func getSellerSectionData(startDate, endDate time.Time, dimensionType string) (adminDataMap AdminDataMap, err error) {
- tryOutMap := make(map[int]int)
- formalMap := make(map[int]int)
- meetingMap := make(map[int]int)
- onlineMap := make(map[int]int)
- offlineMap := make(map[int]int)
- //fmt.Println()
- //客户状态维度
- if dimensionType == "company_status" {
- //正式客户
- {
- var condition string
- var pars []interface{}
- condition = ` and start_date >= ? and end_date <= ? and company_status = ? `
- pars = append(pars, startDate, endDate, "正式")
- data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range data {
- formalMap[v.AdminId] = v.Num
- }
- }
- //试用客户
- {
- var condition string
- var pars []interface{}
- condition = ` and start_date >= ? and end_date <= ? and company_status = ? `
- pars = append(pars, startDate, endDate, "试用")
- data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range data {
- //fmt.Println(v)
- tryOutMap[v.AdminId] = v.Num
- }
- }
- }
- //路演形式维度
- if dimensionType == "roadshow_type" {
- //线上路演
- {
- var condition string
- var pars []interface{}
- condition = ` and start_date >= ? and end_date <= ? and roadshow_type = ? `
- pars = append(pars, startDate, endDate, "线上")
- data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range data {
- //fmt.Println(v)
- onlineMap[v.AdminId] = v.Num
- }
- }
- //线下路演
- {
- var condition string
- var pars []interface{}
- condition = ` and start_date >= ? and end_date <= ? and roadshow_type = ? `
- pars = append(pars, startDate, endDate, "线下")
- data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range data {
- //fmt.Println(v)
- offlineMap[v.AdminId] = v.Num
- }
- }
- }
- //销售专项路演统计
- if dimensionType == "seller_special" {
- detail, errdetail := company.GetConfigDetailByCode("choice_researcher_adminid")
- if errdetail != nil {
- err = errdetail
- return
- }
- //正式客户
- {
- var condition string
- var pars []interface{}
- condition = ` and start_date >= ? and end_date <= ? and company_status = ? ` + ` and researcher_id IN (` + detail.ConfigValue + `) `
- pars = append(pars, startDate, endDate, "正式")
- data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range data {
- formalMap[v.AdminId] = v.Num
- }
- }
- //试用客户
- {
- var condition string
- var pars []interface{}
- condition = ` and start_date >= ? and end_date <= ? and company_status = ? ` + ` and researcher_id IN (` + detail.ConfigValue + `) `
- pars = append(pars, startDate, endDate, "试用")
- data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range data {
- //fmt.Println(v)
- tryOutMap[v.AdminId] = v.Num
- }
- }
- //公开会议
- {
- var condition string
- var pars []interface{}
- condition = ` and start_date >= ? and end_date <= ? and activity_type = ? ` + ` and researcher_id IN (` + detail.ConfigValue + `) `
- pars = append(pars, startDate, endDate, "公开会议")
- data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range data {
- //fmt.Println(v)
- meetingMap[v.AdminId] = v.Num
- }
- }
- } else {
- //公开会议
- {
- var condition string
- var pars []interface{}
- condition = ` and start_date >= ? and end_date <= ? and activity_type = ? `
- pars = append(pars, startDate, endDate, "公开会议")
- data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range data {
- //fmt.Println(v)
- meetingMap[v.AdminId] = v.Num
- }
- }
- }
- adminDataMap = AdminDataMap{
- TryOutMap: tryOutMap,
- FormalMap: formalMap,
- MeetingMap: meetingMap,
- OfflineMap: offlineMap,
- OnlineMap: onlineMap,
- StartDate: startDate.Format(utils.FormatDate),
- EndDate: endDate.Format(utils.FormatDate),
- }
- return
- }
- type OverseasAdminDataMap struct {
- TryOutMap map[int]int `description:"试用路演次数"`
- FormalMap map[int]int `description:"正式路演次数"`
- CloseMap map[int]int `description:"关闭客户次数"`
- OnlineMap map[int]int `description:"线上路演次数"`
- OfflineMap map[int]int `description:"线上路演次数"`
- StartDate string `description:"开始日期"`
- EndDate string `description:"开始日期"`
- }
- // GetOverseasWeekDataV2 周度数据
- func GetOverseasWeekDataV2(adminType, dimensionType string, weekNum int) (adminDataList []OverseasAdminDataMap, firstDate time.Time, err error) {
- nowWeekMonday := utils.GetNowWeekMonday() //本周周一
- //fmt.Println(nowWeekMonday)
- nowWeekSunday := nowWeekMonday.AddDate(0, 0, 7).Add(-1 * time.Second) //本周周日
- chanList := make([]chan OverseasAdminDataMap, 0)
- for i := 0; i < weekNum; i++ {
- tmpCh := make(chan OverseasAdminDataMap, 0)
- chanList = append(chanList, tmpCh)
- lastWeekMonday := nowWeekMonday.AddDate(0, 0, -7*i)
- lastWeekSunday := nowWeekSunday.AddDate(0, 0, -7*i)
- // 第一个开始日期
- firstDate = lastWeekMonday
- go getOverseasSectionData(lastWeekMonday, lastWeekSunday, adminType, dimensionType, tmpCh)
- }
- adminDataList = make([]OverseasAdminDataMap, 0)
- for _, vChan := range chanList {
- var weekAdminDataMap OverseasAdminDataMap
- weekAdminDataMap = <-vChan
- close(vChan)
- adminDataList = append(adminDataList, weekAdminDataMap)
- }
- return
- }
- // getOverseasSectionData 获取周期数据
- func getOverseasSectionData(startDate, endDate time.Time, adminType, dimensionType string, ch chan OverseasAdminDataMap) (adminDataMap OverseasAdminDataMap, err error) {
- defer func() {
- ch <- adminDataMap
- }()
- //adminType := `seller`
- switch adminType {
- case "researcher":
- adminDataMap, err = getOverseasResearcherSectionData(startDate, endDate)
- case "seller":
- adminDataMap, err = getOverseasSellerSectionData(startDate, endDate, dimensionType)
- }
- return
- }
- // getOverseasSellerSectionData 获取销售周期数据
- func getOverseasSellerSectionData(startDate, endDate time.Time, dimensionType string) (adminDataMap OverseasAdminDataMap, err error) {
- tryOutMap := make(map[int]int)
- formalMap := make(map[int]int)
- closeMap := make(map[int]int)
- onlineMap := make(map[int]int)
- offlineMap := make(map[int]int)
- //fmt.Println()
- //客户状态维度
- companylist, err := overseas_custom.GetOverseasCustomList("", nil)
- if err != nil {
- return
- }
- formalIdsArr := make([]int, 0)
- tryoutIdsArr := make([]int, 0)
- closeIdsArr := make([]int, 0)
- for _, v := range companylist {
- if v.OverseasStatus == "正式" {
- formalIdsArr = append(formalIdsArr, v.CompanyId)
- } else if v.OverseasStatus == "试用" {
- tryoutIdsArr = append(tryoutIdsArr, v.CompanyId)
- } else if v.OverseasStatus == "关闭" {
- closeIdsArr = append(closeIdsArr, v.CompanyId)
- }
- }
- if dimensionType == "company_status" {
- //正式客户
- {
- //var condition string
- //var pars []interface{}
- //condition = ` and start_date >= ? and end_date <= ? and company_status = ? and company_id IN (` + utils.GetOrmInReplace(len(formalIdsArr)) + `)`
- //pars = append(pars, startDate, endDate, "正式", formalIdsArr)
- data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate), "正式")
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range data {
- fmt.Println(v)
- formalMap[v.AdminId] = v.Num
- }
- }
- //试用客户
- {
- //var condition string
- //var pars []interface{}
- //condition = ` and start_date >= ? and end_date <= ? and company_status = ? and company_id IN (` + utils.GetOrmInReplace(len(tryoutIdsArr)) + `)`
- //pars = append(pars, startDate, endDate, "试用", tryoutIdsArr)
- data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate), "试用")
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range data {
- //fmt.Println(v)
- tryOutMap[v.AdminId] = v.Num
- }
- }
- //关闭客户
- {
- //var condition string
- //var pars []interface{}
- //condition = ` and start_date >= ? and end_date <= ? and company_status = ? and company_id IN (` + utils.GetOrmInReplace(len(closeIdsArr)) + `)`
- //pars = append(pars, startDate, endDate, "关闭", closeIdsArr)
- data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate), "关闭")
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range data {
- //fmt.Println(v)
- closeMap[v.AdminId] = v.Num
- }
- }
- }
- //路演形式维度
- //if dimensionType == "roadshow_type" {
- // //线上路演
- // {
- // var condition string
- // var pars []interface{}
- // condition = ` and start_date >= ? and end_date <= ? and roadshow_type = ? and company_id IN (` + utils.GetOrmInReplace(len(idsArr)) + `)`
- // pars = append(pars, startDate, endDate, "线上", idsArr)
- // data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(condition, pars)
- // if tmpErr != nil {
- // err = tmpErr
- // return
- // }
- // for _, v := range data {
- // //fmt.Println(v)
- // onlineMap[v.AdminId] = v.Num
- // }
- // }
- //
- // //线下路演
- // {
- // var condition string
- // var pars []interface{}
- // condition = ` and start_date >= ? and end_date <= ? and roadshow_type = ? and company_id IN (` + utils.GetOrmInReplace(len(idsArr)) + `)`
- // pars = append(pars, startDate, endDate, "线下", idsArr)
- // data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(condition, pars)
- // if tmpErr != nil {
- // err = tmpErr
- // return
- // }
- // for _, v := range data {
- // //fmt.Println(v)
- // offlineMap[v.AdminId] = v.Num
- // }
- // }
- //}
- ////销售专项路演统计
- //if dimensionType == "seller_special" {
- //
- // detail, errdetail := company.GetConfigDetailByCode("choice_researcher_adminid")
- // if errdetail != nil {
- // err = errdetail
- // return
- // }
- // //正式客户
- // {
- // var condition string
- // var pars []interface{}
- // condition = ` and start_date >= ? and end_date <= ? and company_status = ? ` + ` and researcher_id IN (` + detail.ConfigValue + `) `
- // pars = append(pars, startDate, endDate, "正式")
- // data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(condition, pars)
- // if tmpErr != nil {
- // err = tmpErr
- // return
- // }
- // for _, v := range data {
- // formalMap[v.AdminId] = v.Num
- // }
- // }
- //
- // //试用客户
- // {
- // var condition string
- // var pars []interface{}
- // condition = ` and start_date >= ? and end_date <= ? and company_status = ? ` + ` and researcher_id IN (` + detail.ConfigValue + `) `
- // pars = append(pars, startDate, endDate, "试用")
- // data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(condition, pars)
- //
- // if tmpErr != nil {
- // err = tmpErr
- // return
- // }
- // for _, v := range data {
- // //fmt.Println(v)
- // tryOutMap[v.AdminId] = v.Num
- // }
- // }
- //
- // //公开会议
- // {
- // var condition string
- // var pars []interface{}
- // condition = ` and start_date >= ? and end_date <= ? and activity_type = ? ` + ` and researcher_id IN (` + detail.ConfigValue + `) `
- // pars = append(pars, startDate, endDate, "公开会议")
- // data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(condition, pars)
- // if tmpErr != nil {
- // err = tmpErr
- // return
- // }
- // for _, v := range data {
- // //fmt.Println(v)
- // meetingMap[v.AdminId] = v.Num
- // }
- // }
- //} else {
- // //公开会议
- // {
- // var condition string
- // var pars []interface{}
- // condition = ` and start_date >= ? and end_date <= ? and activity_type = ? `
- // pars = append(pars, startDate, endDate, "公开会议")
- // data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(condition, pars)
- // if tmpErr != nil {
- // err = tmpErr
- // return
- // }
- // for _, v := range data {
- // //fmt.Println(v)
- // meetingMap[v.AdminId] = v.Num
- // }
- // }
- //}
- adminDataMap = OverseasAdminDataMap{
- TryOutMap: tryOutMap,
- FormalMap: formalMap,
- CloseMap: closeMap,
- OfflineMap: offlineMap,
- OnlineMap: onlineMap,
- StartDate: startDate.Format(utils.FormatDate),
- EndDate: endDate.Format(utils.FormatDate),
- }
- return
- }
- // getOverseasResearcherSectionData 获取研究员周期数据
- func getOverseasResearcherSectionData(startDate, endDate time.Time) (adminDataMap OverseasAdminDataMap, err error) {
- tryOutMap := make(map[int]int)
- formalMap := make(map[int]int)
- closemap := make(map[int]int)
- //companylist, err := overseas_custom.GetOverseasCustomList("", nil)
- //if err != nil {
- // return
- //}
- //formalIdsArr := make([]int, 0)
- //tryoutIdsArr := make([]int, 0)
- //closeIdsArr := make([]int, 0)
- //for _, v := range companylist {
- // if v.OverseasStatus == "正式" {
- // formalIdsArr = append(formalIdsArr, v.CompanyId)
- // } else if v.OverseasStatus == "试用" {
- // tryoutIdsArr = append(tryoutIdsArr, v.CompanyId)
- // } else if v.OverseasStatus == "关闭" {
- // closeIdsArr = append(closeIdsArr, v.CompanyId)
- // }
- //}
- //正式客户
- {
- //var condition string
- //var pars []interface{}
- //condition = ` and start_date >= ? and end_date <= ? and company_status = ? and company_id IN (` + utils.GetOrmInReplace(len(formalIdsArr)) + `)`
- //pars = append(pars, startDate, endDate, "正式", formalIdsArr)
- data, tmpErr := roadshow.GetOverseasGroupResearcherRecordList(startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate), "正式")
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range data {
- formalMap[v.AdminId] = v.Num
- }
- }
- //试用客户
- {
- //var condition string
- //var pars []interface{}
- //condition = ` and start_date >= ? and end_date <= ? and company_status = ? and company_id IN (` + utils.GetOrmInReplace(len(tryoutIdsArr)) + `)`
- //pars = append(pars, startDate, endDate, "试用", tryoutIdsArr)
- data, tmpErr := roadshow.GetOverseasGroupResearcherRecordList(startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate), "试用")
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range data {
- //fmt.Println(v)
- tryOutMap[v.AdminId] = v.Num
- }
- }
- //试用客户
- {
- //var condition string
- //var pars []interface{}
- //condition = ` and start_date >= ? and end_date <= ? and company_status = ? and company_id IN (` + utils.GetOrmInReplace(len(closeIdsArr)) + `)`
- //pars = append(pars, startDate, endDate, "关闭", closeIdsArr)
- data, tmpErr := roadshow.GetOverseasGroupResearcherRecordList(startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate), "关闭")
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range data {
- //fmt.Println(v)
- closemap[v.AdminId] = v.Num
- }
- }
- adminDataMap = OverseasAdminDataMap{
- TryOutMap: tryOutMap,
- FormalMap: formalMap,
- CloseMap: closemap,
- StartDate: startDate.Format(utils.FormatDate),
- EndDate: endDate.Format(utils.FormatDate),
- }
- return
- }
- // GetOverseasMonthDataV2 月度数据
- func GetOverseasMonthDataV2(adminType, dimensionType string, dataNum int) (adminDataMapList []OverseasAdminDataMap, firstDate time.Time, err error) { //三个协程返回
- nowMonthFirstDay := utils.GetNowMonthFirstDay() //本月第一天
- //nowMonthLastDay := nowMonthFirstDay.AddDate(0, 1, 0).Add(-1 * time.Second) //本月最后一天
- chanList := make([]chan OverseasAdminDataMap, 0)
- for i := 0; i < dataNum; i++ {
- tmpCh := make(chan OverseasAdminDataMap, 0)
- chanList = append(chanList, tmpCh)
- lastMonthFirstDay := nowMonthFirstDay.AddDate(0, -1*i, 0) //上个月第一天
- lastMonthLastDay := nowMonthFirstDay.AddDate(0, -1*(i-1), 0).Add(-1 * time.Second) //上个月最后一天
- // 第一个开始日期
- firstDate = lastMonthFirstDay
- go getOverseasSectionData(lastMonthFirstDay, lastMonthLastDay, adminType, dimensionType, tmpCh)
- }
- adminDataMapList = make([]OverseasAdminDataMap, 0)
- for _, vChan := range chanList {
- var monthAdminDataMap OverseasAdminDataMap
- monthAdminDataMap = <-vChan
- close(vChan)
- adminDataMapList = append(adminDataMapList, monthAdminDataMap)
- }
- return
- }
- // GetOverseasTimeIntervalData 区间数据
- func GetOverseasTimeIntervalData(startDate, endDate, adminType, dimensionType string) (adminDataMapList []OverseasAdminDataMap, firstDate time.Time, err error) { //三个协程返回
- startDateTimer, _ := time.ParseInLocation(utils.FormatDate, startDate, time.Local)
- endDateTimer, _ := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
- endDateTimer = endDateTimer.AddDate(0, 0, 1).Add(-1 * time.Second) //本月最后一天
- //最早的一天
- firstDate = startDateTimer
- ch1 := make(chan OverseasAdminDataMap, 0)
- go getOverseasSectionData(startDateTimer, endDateTimer, adminType, dimensionType, ch1)
- var adminDataMap OverseasAdminDataMap
- adminDataMap = <-ch1
- close(ch1)
- adminDataMapList = make([]OverseasAdminDataMap, 0)
- adminDataMapList = append(adminDataMapList, adminDataMap)
- return
- }
- // GetOverseasWeekData 周度数据
- func GetOverseasWeekData(adminType, dimensionType string) (adminDataList []OverseasAdminDataMap, firstDate time.Time, err error) {
- nowWeekMonday := utils.GetNowWeekMonday() //本周周一
- //fmt.Println(nowWeekMonday)
- nowWeekSunday := nowWeekMonday.AddDate(0, 0, 7).Add(-1 * time.Second) //本周周日
- //fmt.Println(nowWeekSunday)
- //nowWeekMonday = nowWeekMonday.AddDate(0, 0, -30) //上周周一
- //nowWeekSunday = nowWeekSunday.AddDate(0, 0, -30) //上周周日
- //adminDataMap, err := getSectionData(nowWeekMonday, nowWeekSunday)
- //if err != nil {
- // fmt.Println(err)
- // return
- //}
- //fmt.Println(adminDataMap)
- lastWeekMonday := nowWeekMonday.AddDate(0, 0, -7) //上周周一
- //fmt.Println(lastWeekMonday)
- //最早的一天
- firstDate = lastWeekMonday
- lastWeekSunday := nowWeekSunday.AddDate(0, 0, -7) //上周周日
- //fmt.Println(lastWeekSunday)
- nextWeekMonday := nowWeekMonday.AddDate(0, 0, 7) //下周周一
- //fmt.Println(nextWeekMonday)
- nextWeekSunday := nowWeekSunday.AddDate(0, 0, 7) //下周周日
- //fmt.Println(nextWeekSunday)
- ch1 := make(chan OverseasAdminDataMap, 0)
- ch2 := make(chan OverseasAdminDataMap, 0)
- ch3 := make(chan OverseasAdminDataMap, 0)
- go getOverseasSectionData(lastWeekMonday, lastWeekSunday, adminType, dimensionType, ch1)
- go getOverseasSectionData(nowWeekMonday, nowWeekSunday, adminType, dimensionType, ch2)
- go getOverseasSectionData(nextWeekMonday, nextWeekSunday, adminType, dimensionType, ch3)
- var nowWeekAdminDataMap, lastWeekAdminDataMap, nextWeekAdminDataMap OverseasAdminDataMap
- lastWeekAdminDataMap = <-ch1
- close(ch1)
- nowWeekAdminDataMap = <-ch2
- close(ch2)
- nextWeekAdminDataMap = <-ch3
- close(ch3)
- adminDataList = make([]OverseasAdminDataMap, 0)
- adminDataList = append(adminDataList, lastWeekAdminDataMap, nowWeekAdminDataMap, nextWeekAdminDataMap)
- return
- }
- // GetOverseasMonthData 月度数据
- func GetOverseasMonthData(adminType, dimensionType string) (adminDataMapList []OverseasAdminDataMap, firstDate time.Time, err error) { //三个协程返回
- nowMonthFirstDay := utils.GetNowMonthFirstDay() //本月第一天
- nowMonthLastDay := nowMonthFirstDay.AddDate(0, 1, 0).Add(-1 * time.Second) //本月最后一天
- lastMonthFirstDay1 := nowMonthFirstDay.AddDate(0, -1, 0) //上个月第一天
- lastMonthLastDay1 := lastMonthFirstDay1.AddDate(0, 1, 0).Add(-1 * time.Second) //上个月最后一天
- lastMonthFirstDay2 := nowMonthFirstDay.AddDate(0, -2, 0) //上上个月第一天
- lastMonthLastDay2 := lastMonthFirstDay2.AddDate(0, 1, 0).Add(-1 * time.Second) //上上个月最后一天
- lastMonthFirstDay3 := nowMonthFirstDay.AddDate(0, -3, 0) //上上上个月第一天
- lastMonthLastDay3 := lastMonthFirstDay3.AddDate(0, 1, 0).Add(-1 * time.Second) //上上上个月最后一天
- //最早的一天
- firstDate = lastMonthFirstDay3
- ch1 := make(chan OverseasAdminDataMap, 0)
- ch2 := make(chan OverseasAdminDataMap, 0)
- ch3 := make(chan OverseasAdminDataMap, 0)
- ch4 := make(chan OverseasAdminDataMap, 0)
- go getOverseasSectionData(nowMonthFirstDay, nowMonthLastDay, adminType, dimensionType, ch1)
- go getOverseasSectionData(lastMonthFirstDay1, lastMonthLastDay1, adminType, dimensionType, ch2)
- go getOverseasSectionData(lastMonthFirstDay2, lastMonthLastDay2, adminType, dimensionType, ch3)
- go getOverseasSectionData(lastMonthFirstDay3, lastMonthLastDay3, adminType, dimensionType, ch4)
- var nowMonthAdminDataMap, lastMonthAdminDataMap1, lastMonthAdminDataMap2, lastMonthAdminDataMap3 OverseasAdminDataMap
- nowMonthAdminDataMap = <-ch1
- close(ch1)
- lastMonthAdminDataMap1 = <-ch2
- close(ch2)
- lastMonthAdminDataMap2 = <-ch3
- close(ch3)
- lastMonthAdminDataMap3 = <-ch4
- close(ch4)
- adminDataMapList = make([]OverseasAdminDataMap, 0)
- adminDataMapList = append(adminDataMapList, nowMonthAdminDataMap, lastMonthAdminDataMap1, lastMonthAdminDataMap2, lastMonthAdminDataMap3)
- return
- }
|