12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028 |
- 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:"线上路演次数"`
- RoadShowMap map[int]int `description:"路演总次数"`
- SalonMap 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)
- roadShowMap := make(map[int]int) // 路演总次数
- salonMap := 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
- }
- }
- //路演总次数
- {
- 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)
- roadShowMap[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)
- salonMap[v.AdminId] = v.Num
- }
- }
- adminDataMap = AdminDataMap{
- TryOutMap: tryOutMap,
- FormalMap: formalMap,
- MeetingMap: meetingMap,
- RoadShowMap: roadShowMap,
- SalonMap: salonMap,
- 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)
- roadShowMap := make(map[int]int) // 路演总次数
- salonMap := 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
- }
- }
- }
- //权益路演
- if dimensionType == "roadshow_rai" {
- //路演总次数
- {
- 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)
- roadShowMap[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.GetGroupSellerRecordList(condition, pars)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range data {
- //fmt.Println(v)
- salonMap[v.AdminId] = v.Num
- }
- }
- }
- adminDataMap = AdminDataMap{
- TryOutMap: tryOutMap,
- FormalMap: formalMap,
- MeetingMap: meetingMap,
- OfflineMap: offlineMap,
- OnlineMap: onlineMap,
- RoadShowMap: roadShowMap,
- SalonMap: salonMap,
- 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
- }
|