12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781 |
- package statistic
- import (
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hz_crm_api/controllers"
- "hongze/hz_crm_api/models"
- "hongze/hz_crm_api/models/company"
- "hongze/hz_crm_api/models/fms"
- "hongze/hz_crm_api/models/statistic_report"
- "hongze/hz_crm_api/models/system"
- "hongze/hz_crm_api/services"
- cygxService "hongze/hz_crm_api/services/cygx"
- "hongze/hz_crm_api/utils"
- "strconv"
- "strings"
- "time"
- )
- // 权益数据汇总
- // StatisticRaiDataSummaryController 权益数据汇总基类
- type StatisticRaiDataSummaryController struct {
- controllers.BaseAuthController
- }
- // MergeCompanyList
- // @Title 权益数据汇总
- // @Description 权益数据汇总统计列表接口
- // @Param AdminId query string true "开拓组销售id,多个用英文逗号隔开,空字符串为全部"
- // @Param ServiceAdminId query string true "服务组销售id,多个用英文逗号隔开,空字符串为全部"
- // @Param StartYear query int false "开始日期(年份)"
- // @Param EndYear query int false "结束日期(年份)"
- // @Param DataType query string false "报表类型,枚举值:`季度`,`年度`,`半年度`"
- // @Param DevelopButton query int false "开拓组开关,枚举值:1:开启,0:关闭 ,默认关闭"
- // @Param ServerButton query int false "服务组开关,枚举值:1:开启,0:关闭 ,默认关闭"
- // @Param ContractButtonType query string false "开关类型,:`新签`,`续约`,`收入` 多个用英文逗号隔开, "
- // @Param StartDate query string false "开始时间 "
- // @Param EndDate query string false "结束时间 "
- // @Param IsExport query bool false "是否导出excel,默认是false"
- // @Success 200 {object} statistic_report.RaiDataSummaryListResp
- // @router /rai_data_summary/list [get]
- func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- dataType := this.GetString("DataType")
- adminId := this.GetString("AdminId")
- serviceAdminId := this.GetString("ServiceAdminId")
- startYear, _ := this.GetInt("StartYear")
- endYear, _ := this.GetInt("EndYear")
- developButton, _ := this.GetBool("DevelopButton")
- serverButton, _ := this.GetBool("ServerButton")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- adminIdArr := strings.Split(adminId, ",")
- serviceAdminIdArr := strings.Split(serviceAdminId, ",")
- if adminId == "" {
- adminIdArr = make([]string, 0)
- }
- if serviceAdminId == "" {
- serviceAdminIdArr = make([]string, 0)
- }
- dataTypeArr := []string{}
- if dataType == "季度" {
- dataTypeArr = []string{"Q1", "Q2", "Q3", "Q4"}
- } else if dataType == "半年度" {
- dataTypeArr = []string{"H1", "H2"}
- } else {
- dataTypeArr = []string{""}
- }
- var condition string
- var pars []interface{}
- var conditionEnSeller string // 手动禁用的销售
- conditionEnSeller = " AND real_name NOT IN ('余晔', '于卓铭', '张怡', '王芳6') "
- mapsellerDevelop := make(map[int]bool) // 开拓组销售Map
- mapsellerService := make(map[int]bool) // 服务组销售Map
- var sellerIds []string
- var sellerServiceIds []string
- condition = " AND role_type_code IN ('rai_seller','rai_group') " + conditionEnSeller
- sellerListAll, err := system.GetSysUserItemsOrderByCreated(condition, pars)
- if err != nil {
- br.Msg = "获取管理账号失败"
- br.ErrMsg = "获取管理账号失败,Err:" + err.Error()
- return
- }
- for _, v := range sellerListAll {
- if strings.Contains(v.RealName, "6") {
- mapsellerService[v.AdminId] = true
- sellerServiceIds = append(sellerServiceIds, strconv.Itoa(v.AdminId))
- } else {
- mapsellerDevelop[v.AdminId] = true
- sellerIds = append(sellerIds, strconv.Itoa(v.AdminId))
- }
- }
- condition = " AND role_type_code IN ('rai_seller','rai_group') AND enabled = 1 AND rai_enabled = 1 " + conditionEnSeller
- if adminId != "" {
- serviceAdminId = ""
- condition += " AND admin_id IN (" + adminId + ") "
- sellerIds = make([]string, 0)
- }
- if serviceAdminId != "" {
- condition += " AND admin_id IN (" + serviceAdminId + ") "
- sellerServiceIds = make([]string, 0)
- }
- if developButton && !serverButton && adminId == "" && serviceAdminId == "" { //开拓组筛选条件
- condition += " AND real_name NOT LIKE '%6%' "
- }
- if !developButton && serverButton && adminId == "" && serviceAdminId == "" { //服务组筛选条件
- condition += " AND real_name LIKE '%6%' "
- }
- sellerList, err := system.GetSysUserItemsOrderByCreated(condition, pars)
- if err != nil {
- br.Msg = "获取管理账号失败"
- br.ErrMsg = "获取管理账号失败,Err:" + err.Error()
- return
- }
- var sellerDevelop []*system.AdminItem // 开拓组销售
- var sellerService []*system.AdminItem // 服务组销售
- var sellerDevelopIds = make(map[int]bool) // 开拓组销售的map
- mapsellerId := make(map[int]bool) // 权益销售map
- for _, v := range sellerList {
- if strings.Contains(v.RealName, "6") {
- sellerService = append(sellerService, v)
- } else {
- sellerDevelop = append(sellerDevelop, v)
- sellerDevelopIds[v.AdminId] = true
- }
- mapsellerId[v.AdminId] = true
- }
- var isCustomizeDate bool // 是否有自定义的时间
- //拼接起始时间查询
- if startDate == "" {
- startDate = fmt.Sprintf("%d-01-01", startYear)
- endDate = fmt.Sprintf("%d-12-31", endYear)
- } else {
- isCustomizeDate = true
- startYear = 1
- endYear = 1
- dataTypeArr = []string{""}
- }
- //新签部分的数据
- var conditionRai string
- var parsRai []interface{}
- conditionRai = " AND a.product_id = 2 AND a.status = 1 AND a.start_date >= ? AND a.start_date <= ? AND a.rai_contract_type = '新签合同' "
- parsRai = append(parsRai, startDate, endDate)
- listRaiData, err := statistic_report.GetRaiDataSummaryList(conditionRai, parsRai)
- if err != nil {
- br.Msg = "获取数据信息失败"
- br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
- return
- }
- var companyContractIds []int
- for _, v := range listRaiData {
- companyContractIds = append(companyContractIds, v.CompanyId)
- }
- companyContractIds = append(companyContractIds, 0)
- //续约部分的数据
- var conditionInherit string
- var parsInherit []interface{}
- conditionInherit = ` AND a.product_id = 2 AND a.status = 1 AND a.inherit_end_date >= ? AND a.inherit_end_date <= ? AND a.rai_contract_type = '续约合同' AND a.company_contract_id NOT IN (` + utils.GetOrmInReplace(len(companyContractIds)) + `) `
- parsInherit = append(parsInherit, startDate, endDate, companyContractIds)
- listInheritData, err := statistic_report.GetRaiDataSummaryInheritList(conditionInherit, parsInherit)
- if err != nil {
- br.Msg = "获取数据信息失败"
- br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
- return
- }
- //确认不续约、到期合同部分的数据
- var conditionEnd string
- var parsEnd []interface{}
- conditionEnd = " AND a.product_id = 2 AND a.status = 1 AND a.due_end_date >= ? AND a.due_end_date <= ? AND a.end_date < ? "
- parsEnd = append(parsEnd, startDate, endDate, time.Now().Format(utils.FormatDate))
- listEndData, err := statistic_report.GetRaiDataSummaryList(conditionEnd, parsEnd)
- if err != nil {
- br.Msg = "获取数据信息失败"
- br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
- return
- }
- var conditionConfirm string
- var parsConfirm []interface{}
- mapNoRenewedcompanyContractIds := make(map[int]bool) //已经确定未续约的合同ID
- conditionConfirm = " AND company_ascribe_id != 9 "
- companyConfirmList, err := company.GetCompanyContractNoRenewedAscribeList(conditionConfirm, parsConfirm, 0, 0)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,GetCompanyNoRenewedAscribeList Err:" + err.Error()
- return
- }
- for _, v := range companyConfirmList {
- mapNoRenewedcompanyContractIds[v.CompanyContractId] = true
- }
- mapAddTrialNum := make(map[string]float64) // 新增试用-(数据)
- mapNewContractMoney := make(map[string]float64) // 新签合同(金额)
- mapNewContractNum := make(map[string]int) // 新签合同(数量)
- mapExpiredContractMoney := make(map[string]float64) // 到期合同(金额)
- mapExpiredContractNum := make(map[string]int) // 到期合同(数量)
- mapExpiredContractCompanyNum := make(map[string]int) // 到期公司(数量)
- mapRenewedContractMoney := make(map[string]float64) // 续约合同(金额)
- mapRenewedContractNum := make(map[string]int) // 续约合同(数量)
- mapRenewedContractCompanyNum := make(map[string]int) // 续约公司(数量)
- confirmedNoRenewalContractMoney := make(map[string]float64) // 确认不续约合同(金额)
- confirmedNoRenewalContractNum := make(map[string]int) // 确认不续约合同(数量)
- confirmedNoRenewalContractCompanyNum := make(map[string]int) // 确认不续约公司(数量)
- mapSignedClientNum := make(map[string]int) // 签约客户(数量)
- mapSignedClientMoney := make(map[string]float64) // 签约客户(金额)
- mapInvoiceAmountMoney := make(map[string]float64) // 财务系统开票金额(金额)
- mapPaymentAmountMoney := make(map[string]float64) // 财务系统到款金额(金额)
- mapNewCustomerInvoicingMoney := make(map[string]float64) // 财务系统新客开票金额(金额)
- mapNewCustomerPaymentsReceivedMoney := make(map[string]float64) // 财务系统新客到款金额(金额)
- mapNewContractMoneyServer := make(map[string]float64) // 新签合同(金额)
- mapNewContractNumServer := make(map[string]int) // 新签合同(数量)
- mapExpiredContractMoneyServer := make(map[string]float64) // 到期合同(金额)
- mapExpiredContractNumServer := make(map[string]int) // 到期合同(数量)_服务组
- mapExpiredContractCompanyNumServer := make(map[string]int) // 到期公司(数量)_服务组
- mapRenewedContractMoneyServer := make(map[string]float64) // 续约合同(金额)_服务组
- mapRenewedContractNumServer := make(map[string]int) // 续约合同(数量)_服务组
- mapRenewedContractCompanyNumServer := make(map[string]int) // 续约公司(数量)_服务组
- confirmedNoRenewalContractMoneyServer := make(map[string]float64) // 确认不续约合同(金额)_服务组
- confirmedNoRenewalContractNumServer := make(map[string]int) // 确认不续约合同(数量)_服务组
- confirmedNoRenewalContractCompanyNumServer := make(map[string]int) // 确认不续约公司(数量)_服务组
- mapSignedClientNumServer := make(map[string]int) // 签约客户(数量)
- mapSignedClientMoneyServer := make(map[string]float64) // 签约客户(金额)
- var keyMap string
- var keyMapTtoal string
- var keyMapTtoalServer string
- var keyMapCompany string
- var keyMapCompanyNo string
- //var keyMapCompanyNoServer string
- var keySigned string
- mapCompanyData := make(map[string]bool)
- //新签部分的数据(开拓组)
- for _, v := range listRaiData {
- if !mapsellerDevelop[v.SellerIdInit] {
- continue
- }
- yearStr := getYearStar(utils.StrDateToDate(v.StartDate), dataType, isCustomizeDate)
- keyMap = fmt.Sprint(yearStr, "_", v.SellerIdInit)
- keySigned = fmt.Sprint(yearStr, "_CID_", v.CompanyId, "_SID_", v.SellerIdInit)
- keyMapTtoal = fmt.Sprint(yearStr, "_Develop")
- if v.RaiContractType == "新签合同" {
- mapNewContractMoney[keyMap] += v.Money
- mapNewContractNum[keyMap]++
- mapNewContractMoney[keyMapTtoal] += v.Money
- mapNewContractNum[keyMapTtoal]++
- }
- mapSignedClientMoney[keyMap] += v.Money
- mapSignedClientMoney[keyMapTtoal] += v.Money
- if !mapCompanyData[keySigned] && v.RaiContractType == "新签合同" {
- mapSignedClientNum[keyMap]++
- mapSignedClientNum[keyMapTtoal]++
- mapCompanyData[keySigned] = true
- }
- }
- //新签部分的数据(服务组)
- for _, v := range listRaiData {
- if !mapsellerService[v.ShareSellerIdInit] {
- continue
- }
- yearStr := getYearStar(utils.StrDateToDate(v.StartDate), dataType, isCustomizeDate)
- keyMap = fmt.Sprint(yearStr, "_Server_", v.ShareSellerIdInit)
- keySigned = fmt.Sprint(yearStr, "_Server_", v.CompanyId, "_SID_", v.ShareSellerIdInit)
- keyMapTtoal = fmt.Sprint(yearStr, "_Server_")
- if v.RaiContractType == "新签合同" {
- mapNewContractMoneyServer[keyMap] += v.Money
- mapNewContractNumServer[keyMap]++
- mapNewContractMoneyServer[keyMapTtoal] += v.Money
- mapNewContractNumServer[keyMapTtoal]++
- }
- mapSignedClientMoneyServer[keyMap] += v.Money
- mapSignedClientMoneyServer[keyMapTtoal] += v.Money
- if !mapCompanyData[keySigned] && v.RaiContractType == "新签合同" {
- mapSignedClientNumServer[keyMap]++
- mapSignedClientNumServer[keyMapTtoal]++
- mapCompanyData[keySigned] = true
- }
- }
- //续约部分的数据(开拓组)
- mapKeyMapCompanyData := make(map[string]bool)
- for _, v := range listInheritData {
- if len(adminIdArr) > 0 && !utils.InArrayByStr(adminIdArr, strconv.Itoa(v.SellerIdLast)) {
- continue
- }
- if !mapsellerDevelop[v.SellerIdLast] {
- continue
- }
- yearStr := getYearStar(utils.StrDateToDate(v.InheritEndDate), dataType, isCustomizeDate)
- keyMap = fmt.Sprint(yearStr, "_", v.SellerIdLast)
- keyMapCompany = fmt.Sprint(yearStr, "_", v.SellerIdLast, "_CID_", v.CompanyId)
- keySigned = fmt.Sprint(yearStr, "_CID_", v.CompanyId, "_SID_", v.SellerIdLast)
- keyMapTtoal = fmt.Sprint(yearStr, "_Develop")
- //续约合同 数据
- mapRenewedContractMoney[keyMap] += v.Money
- mapRenewedContractMoney[keyMapTtoal] += v.Money
- mapRenewedContractNum[keyMap]++
- mapRenewedContractNum[keyMapTtoal]++
- //续约公司 数据
- if !mapKeyMapCompanyData[keyMapCompany] {
- mapRenewedContractCompanyNum[keyMap]++
- mapRenewedContractCompanyNum[keyMapTtoal]++
- mapKeyMapCompanyData[keyMapCompany] = true
- }
- //签约合同 数据
- mapSignedClientMoney[keyMap] += v.Money
- mapSignedClientMoney[keyMapTtoal] += v.Money
- if !mapCompanyData[keySigned] {
- mapSignedClientNum[keyMap]++
- mapSignedClientNum[keyMapTtoal]++
- mapCompanyData[keySigned] = true
- }
- }
- //续约部分的数据(服务组)
- for _, v := range listInheritData {
- if len(serviceAdminIdArr) > 0 && !utils.InArrayByStr(serviceAdminIdArr, strconv.Itoa(v.ShareSellerIdInit)) {
- continue
- }
- if !mapsellerService[v.ShareSellerIdInit] {
- continue
- }
- yearStr := getYearStar(utils.StrDateToDate(v.InheritEndDate), dataType, isCustomizeDate)
- keyMap = fmt.Sprint(yearStr, "_Server_", v.ShareSellerIdInit)
- keyMapCompany = fmt.Sprint(yearStr, "_Server_", v.ShareSellerIdInit, "_CID_", v.CompanyId)
- keySigned = fmt.Sprint(yearStr, "_Server_", v.CompanyId, "_SID_", v.ShareSellerIdInit)
- keyMapTtoal = fmt.Sprint(yearStr, "_Server_")
- //续约合同 数据
- mapRenewedContractMoneyServer[keyMap] += v.Money
- mapRenewedContractMoneyServer[keyMapTtoal] += v.Money
- mapRenewedContractNumServer[keyMap]++
- mapRenewedContractNumServer[keyMapTtoal]++
- //续约公司 数据
- if !mapKeyMapCompanyData[keyMapCompany] {
- mapRenewedContractCompanyNumServer[keyMap]++
- mapRenewedContractCompanyNumServer[keyMapTtoal]++
- mapKeyMapCompanyData[keyMapCompany] = true
- }
- ////签约合同 数据
- mapSignedClientMoneyServer[keyMap] += v.Money
- mapSignedClientMoneyServer[keyMapTtoal] += v.Money
- if !mapCompanyData[keySigned] {
- mapSignedClientNumServer[keyMap]++
- mapSignedClientNumServer[keyMapTtoal]++
- mapCompanyData[keySigned] = true
- }
- }
- //确认不续约、到期合同部分的数据
- mapKeyMapCompanyEndData := make(map[string]bool)
- mapKeyMapCompanyNoData := make(map[string]bool)
- //到期部分开拓组数据
- for _, v := range listEndData {
- if len(adminIdArr) > 0 && !utils.InArrayByStr(adminIdArr, strconv.Itoa(v.SellerIdLast)) {
- continue
- }
- if !mapsellerDevelop[v.SellerIdLast] {
- continue
- }
- yearStr := getYearStar(utils.StrDateToDate(v.DueEndDate), dataType, isCustomizeDate)
- keyMap = fmt.Sprint(yearStr, "_", v.SellerIdLast)
- keyMapCompany = fmt.Sprint(yearStr, "_", v.SellerIdLast, "_CID_", v.CompanyId)
- keyMapCompanyNo = fmt.Sprint(yearStr, "_", v.SellerIdLast, "_CID_NO", v.CompanyId)
- keyMapTtoal = fmt.Sprint(yearStr, "_Develop")
- //到期合同数据
- mapExpiredContractMoney[keyMap] += v.Money
- mapExpiredContractMoney[keyMapTtoal] += v.Money
- //一家公司同一个时间纬度,只统计一次
- mapExpiredContractNum[keyMap]++
- mapExpiredContractNum[keyMapTtoal]++
- //一家公司同一个时间纬度,只统计一次
- if !mapKeyMapCompanyEndData[keyMapCompany] {
- mapExpiredContractCompanyNum[keyMap]++
- mapExpiredContractCompanyNum[keyMapTtoal]++
- mapKeyMapCompanyEndData[keyMapCompany] = true
- }
- if mapNoRenewedcompanyContractIds[v.CompanyContractId] { // 确认不续约合同
- confirmedNoRenewalContractMoney[keyMap] += v.Money
- confirmedNoRenewalContractMoney[keyMapTtoal] += v.Money
- //一家公司同一个时间纬度,只统计一次
- confirmedNoRenewalContractNum[keyMap]++
- confirmedNoRenewalContractNum[keyMapTtoal]++
- if !mapKeyMapCompanyNoData[keyMapCompanyNo] {
- confirmedNoRenewalContractCompanyNum[keyMap]++
- confirmedNoRenewalContractCompanyNum[keyMapTtoal]++
- mapKeyMapCompanyNoData[keyMapCompanyNo] = true
- }
- }
- }
- //到期部分服务组数据
- for _, v := range listEndData {
- if len(serviceAdminIdArr) > 0 && !utils.InArrayByStr(serviceAdminIdArr, strconv.Itoa(v.ShareSellerIdLast)) {
- continue
- }
- if !mapsellerService[v.ShareSellerIdLast] {
- continue
- }
- yearStr := getYearStar(utils.StrDateToDate(v.DueEndDate), dataType, isCustomizeDate)
- keyMap = fmt.Sprint(yearStr, "_Server_", v.ShareSellerIdLast)
- keyMapCompany = fmt.Sprint(yearStr, "_Server_", v.ShareSellerIdLast, "_CID_", v.CompanyId)
- keyMapCompanyNo = fmt.Sprint(yearStr, "_Server_", v.ShareSellerIdLast, "_CID_NO", v.CompanyId)
- keyMapTtoal = fmt.Sprint(yearStr, "_Server_")
- //到期合同数据
- mapExpiredContractMoneyServer[keyMap] += v.Money
- mapExpiredContractMoneyServer[keyMapTtoal] += v.Money
- mapExpiredContractNumServer[keyMap]++
- mapExpiredContractNumServer[keyMapTtoal]++
- //一家公司同一个时间纬度,只统计一次
- if !mapKeyMapCompanyEndData[keyMapCompany] {
- mapExpiredContractCompanyNumServer[keyMap]++
- mapExpiredContractCompanyNumServer[keyMapTtoal]++
- mapKeyMapCompanyEndData[keyMapCompany] = true
- }
- if mapNoRenewedcompanyContractIds[v.CompanyContractId] { // 确认不续约合同
- confirmedNoRenewalContractMoneyServer[keyMap] += v.Money
- confirmedNoRenewalContractMoneyServer[keyMapTtoal] += v.Money
- //一家公司同一个时间纬度,只统计一次
- confirmedNoRenewalContractNumServer[keyMap]++
- confirmedNoRenewalContractNumServer[keyMapTtoal]++
- if !mapKeyMapCompanyNoData[keyMapCompanyNo] {
- confirmedNoRenewalContractCompanyNumServer[keyMap]++
- confirmedNoRenewalContractCompanyNumServer[keyMapTtoal]++
- mapKeyMapCompanyNoData[keyMapCompanyNo] = true
- }
- }
- }
- listFmsData, err := fms.GetContractRegisterListByStartDate(startDate, endDate)
- if err != nil {
- br.Msg = "获取数据信息失败"
- br.ErrMsg = "获取财务系统数据信息失败,Err:" + err.Error()
- return
- }
- //开拓组财务系统数据
- for _, v := range listFmsData {
- if len(adminIdArr) > 0 && !utils.InArrayByStr(adminIdArr, strconv.Itoa(v.RaiSellerId)) {
- continue
- }
- if !mapsellerDevelop[v.RaiSellerId] {
- continue
- }
- yearStr := getYearStar(utils.StrDateToDate(v.InvoiceTime), dataType, isCustomizeDate)
- keyMap = fmt.Sprint(yearStr, "_", v.RaiSellerId)
- keyMapTtoal = fmt.Sprint(yearStr, "_Develop")
- //开票记录
- if v.InvoiceType == 1 {
- mapInvoiceAmountMoney[keyMap] += v.Amount
- mapInvoiceAmountMoney[keyMapTtoal] += v.Amount
- if v.ContractType == 1 {
- mapNewCustomerInvoicingMoney[keyMap] += v.Amount
- mapNewCustomerInvoicingMoney[keyMapTtoal] += v.Amount
- }
- }
- //到款记录
- if v.InvoiceType == 2 {
- mapPaymentAmountMoney[keyMap] += v.Amount
- mapPaymentAmountMoney[keyMapTtoal] += v.Amount
- if v.ContractType == 1 {
- mapNewCustomerPaymentsReceivedMoney[keyMap] += v.Amount
- mapNewCustomerPaymentsReceivedMoney[keyMapTtoal] += v.Amount
- }
- }
- }
- //服务组财务系统数据
- for _, v := range listFmsData {
- if len(serviceAdminIdArr) > 0 && !utils.InArrayByStr(serviceAdminIdArr, strconv.Itoa(v.RaiSellerId)) {
- continue
- }
- if !mapsellerService[v.RaiSellerId] {
- continue
- }
- yearStr := getYearStar(utils.StrDateToDate(v.InvoiceTime), dataType, isCustomizeDate)
- keyMap = fmt.Sprint(yearStr, "_Server_", v.RaiSellerId)
- keyMapTtoal = fmt.Sprint(yearStr, "_Server_")
- //开票记录
- if v.InvoiceType == 1 {
- mapInvoiceAmountMoney[keyMap] += v.Amount
- mapInvoiceAmountMoney[keyMapTtoal] += v.Amount
- if v.ContractType == 1 {
- mapNewCustomerInvoicingMoney[keyMap] += v.Amount
- mapNewCustomerInvoicingMoney[keyMapTtoal] += v.Amount
- }
- }
- //到款记录
- if v.InvoiceType == 2 {
- mapPaymentAmountMoney[keyMap] += v.Amount
- mapPaymentAmountMoney[keyMapTtoal] += v.Amount
- if v.ContractType == 1 {
- mapNewCustomerPaymentsReceivedMoney[keyMap] += v.Amount
- mapNewCustomerPaymentsReceivedMoney[keyMapTtoal] += v.Amount
- }
- }
- }
- conditionTry := ` AND a.create_time >= ? AND a.create_time <= ? AND a.operation in ( "add","receive","apply_receive" ) AND a.sys_user_id IN ( SELECT admin_id FROM admin WHERE role_type_code IN ( 'rai_seller', 'rai_group' , 'rai_admin') ` + conditionEnSeller + ` ) `
- var parsTry []interface{}
- parsTry = append(parsTry, startDate, endDate)
- //列表页数据
- tryList, err := models.GetIncrementalCompanyListByOperationRecordRai(conditionTry, parsTry, 0, 9999)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- for _, v := range tryList {
- startDateTime := utils.StrTimeToTime(v.CreateTime)
- monthNum := startDateTime.Month()
- yearStr := strconv.Itoa(startDateTime.Year())
- if dataType == "季度" {
- if monthNum < 4 {
- yearStr += "Q1"
- } else if monthNum > 3 && monthNum < 7 {
- yearStr += "Q2"
- } else if monthNum > 6 && monthNum < 10 {
- yearStr += "Q3"
- } else if monthNum > 9 {
- yearStr += "Q4"
- }
- } else if dataType == "半年度" {
- if monthNum < 7 {
- yearStr += "H1"
- } else {
- yearStr += "H2"
- }
- }
- if isCustomizeDate {
- yearStr = ""
- }
- keyMap = fmt.Sprint(yearStr, "_", v.SysUserId)
- mapAddTrialNum[keyMap]++
- //var keyMapTtoal string
- sysUserId, _ := strconv.Atoi(v.SysUserId)
- if sellerDevelopIds[sysUserId] == true {
- keyMapTtoal = fmt.Sprint(yearStr, "_Develop")
- } else {
- keyMapTtoal = fmt.Sprint(yearStr, "_Server_")
- }
- mapAddTrialNum[keyMapTtoal]++
- }
- resp := new(statistic_report.RaiDataSummaryListResp)
- var items []*statistic_report.RaiDataSummaryResp
- for i := startYear; i <= endYear; i++ {
- for _, Dv := range dataTypeArr {
- item := new(statistic_report.RaiDataSummaryResp)
- if isCustomizeDate {
- item.DataType = "" //传了自定义时间之后,把key值,置空
- } else {
- item.DataType = fmt.Sprint(i, Dv)
- }
- keyMapTtoal = fmt.Sprint(item.DataType, "_Develop")
- keyMapTtoalServer = fmt.Sprint(item.DataType, "_Server_")
- for _, vS := range sellerDevelop {
- keyMap = fmt.Sprint(item.DataType, "_", vS.AdminId)
- sellerItem := new(statistic_report.RaiDataSummaryDetail)
- sellerItem.SellerId = strconv.Itoa(vS.AdminId)
- sellerIds = append(sellerIds, sellerItem.SellerId)
- sellerItem.SellerName = vS.RealName
- sellerItem.AddTrialCount = fmt.Sprint(mapAddTrialNum[keyMap])
- sellerItem.NewContractData = fmt.Sprint(utils.SubFloatToString(mapNewContractMoney[keyMap], 2), " / ", mapNewContractNum[keyMap]) // 新签合同(金额/数量)-(数据)
- sellerItem.ExpiredContractData = fmt.Sprint(utils.SubFloatToString(mapExpiredContractMoney[keyMap], 2), " / ", mapExpiredContractNum[keyMap]) //"到期合同(金额/数量)-(数据)"
- sellerItem.RenewedContractData = fmt.Sprint(utils.SubFloatToString(mapRenewedContractMoney[keyMap], 2), " / ", mapRenewedContractNum[keyMap]) // "续约合同(金额/数量)-(数据)"
- var renewalRateMoey string
- var renewalRateNum string
- if mapRenewedContractMoney[keyMap] == 0 || mapExpiredContractMoney[keyMap] == 0 {
- renewalRateMoey = "0%"
- } else {
- renewalRateMoey = utils.SubFloatToString(mapRenewedContractMoney[keyMap]/mapExpiredContractMoney[keyMap]*100, 2) + "%"
- }
- if mapRenewedContractCompanyNum[keyMap] == 0 || mapExpiredContractCompanyNum[keyMap] == 0 {
- renewalRateNum = "0%"
- } else {
- renewalRateNum = utils.SubFloatToString(float64(mapRenewedContractCompanyNum[keyMap])/float64(mapExpiredContractCompanyNum[keyMap])*100, 2) + "%"
- }
- sellerItem.RenewalRateData = fmt.Sprint(renewalRateMoey, " / ", renewalRateNum) //"续约率(金额/数量)-(数据)"
- sellerItem.ConfirmedNoRenewalContractData = fmt.Sprint(utils.SubFloatToString(confirmedNoRenewalContractMoney[keyMap], 2), " / ", confirmedNoRenewalContractNum[keyMap]) //"确认不续约合同(金额/数量)-(数据)"
- var confirmNonRenewalRateMoey string
- var confirmNonRenewalRateNum string
- if confirmedNoRenewalContractMoney[keyMap] == 0 || mapExpiredContractMoney[keyMap] == 0 {
- confirmNonRenewalRateMoey = "0%"
- } else {
- confirmNonRenewalRateMoey = utils.SubFloatToString(confirmedNoRenewalContractMoney[keyMap]/mapExpiredContractMoney[keyMap]*100, 2) + "%"
- }
- if confirmedNoRenewalContractCompanyNum[keyMap] == 0 || mapExpiredContractCompanyNum[keyMap] == 0 {
- confirmNonRenewalRateNum = "0%"
- } else {
- confirmNonRenewalRateNum = utils.SubFloatToString(float64(confirmedNoRenewalContractCompanyNum[keyMap])/float64(mapExpiredContractCompanyNum[keyMap])*100, 2) + "%"
- }
- sellerItem.ConfirmNonRenewalRateData = fmt.Sprint(confirmNonRenewalRateMoey, " / ", confirmNonRenewalRateNum) //确认不续约率(金额/数量)-(数据)"
- sellerItem.SignedClientCount = fmt.Sprint(mapSignedClientNum[keyMap]) // 签约客户数量
- if mapSignedClientNum[keyMap] == 0 || mapSignedClientMoney[keyMap] == 0 {
- sellerItem.AverageRevenueCount = "0"
- } else {
- sellerItem.AverageRevenueCount = utils.SubFloatToString(mapSignedClientMoney[keyMap]/float64(mapSignedClientNum[keyMap]), 2) //客单价
- }
- sellerItem.InvoiceAmountCount = utils.SubFloatToString(mapInvoiceAmountMoney[keyMap], 2) //"开票金额-(数据)"
- sellerItem.PaymentReceivedCount = utils.SubFloatToString(mapPaymentAmountMoney[keyMap], 2) //"开票金额-(数据)"
- if mapInvoiceAmountMoney[keyMap] == 0 || mapPaymentAmountMoney[keyMap] == 0 {
- sellerItem.UnpaidRatioCount = "0%"
- } else {
- sellerItem.UnpaidRatioCount = utils.SubFloatToString((mapInvoiceAmountMoney[keyMap]-mapPaymentAmountMoney[keyMap])/mapInvoiceAmountMoney[keyMap]*100, 2) + "%" //"未到款比例-(数据)"
- }
- sellerItem.NewCustomerInvoicingCount = utils.SubFloatToString(mapNewCustomerInvoicingMoney[keyMap], 2) // "新客开票-(数据)"
- sellerItem.NewCustomerPaymentsReceivedCount = utils.SubFloatToString(mapNewCustomerPaymentsReceivedMoney[keyMap], 2) // "新客到款-(数据)"
- if developButton || serverButton || adminId != "" {
- item.DataList = append(item.DataList, sellerItem)
- }
- }
- if len(sellerDevelop) > 0 && adminId == "" {
- sellerItem := new(statistic_report.RaiDataSummaryDetail)
- sellerItem.SellerId = strings.Join(sellerIds, ",")
- sellerItem.SellerName = "开拓组合计"
- sellerItem.AddTrialCount = fmt.Sprint(mapAddTrialNum[keyMapTtoal])
- sellerItem.NewContractData = fmt.Sprint(utils.SubFloatToString(mapNewContractMoney[keyMapTtoal], 2), " / ", mapNewContractNum[keyMapTtoal]) // 新签合同(金额/数量)-(数据)
- sellerItem.ExpiredContractData = fmt.Sprint(utils.SubFloatToString(mapExpiredContractMoney[keyMapTtoal], 2), " / ", mapExpiredContractNum[keyMapTtoal]) //"到期合同(金额/数量)-(数据)"
- sellerItem.RenewedContractData = fmt.Sprint(utils.SubFloatToString(mapRenewedContractMoney[keyMapTtoal], 2), " / ", mapRenewedContractNum[keyMapTtoal]) // "续约合同(金额/数量)-(数据)"
- var renewalRateMoey string
- var renewalRateNum string
- if mapRenewedContractMoney[keyMapTtoal] == 0 || mapExpiredContractMoney[keyMapTtoal] == 0 {
- renewalRateMoey = "0%"
- } else {
- renewalRateMoey = utils.SubFloatToString(mapRenewedContractMoney[keyMapTtoal]/mapExpiredContractMoney[keyMapTtoal]*100, 2) + "%"
- }
- if mapRenewedContractCompanyNum[keyMapTtoal] == 0 || mapExpiredContractCompanyNum[keyMapTtoal] == 0 {
- renewalRateNum = "0%"
- } else {
- renewalRateNum = utils.SubFloatToString(float64(mapRenewedContractCompanyNum[keyMapTtoal])/float64(mapExpiredContractCompanyNum[keyMapTtoal])*100, 2) + "%"
- }
- sellerItem.RenewalRateData = fmt.Sprint(renewalRateMoey, " / ", renewalRateNum) //"续约率(金额/数量)-(数据)"
- sellerItem.ConfirmedNoRenewalContractData = fmt.Sprint(utils.SubFloatToString(confirmedNoRenewalContractMoney[keyMapTtoal], 2), " / ", confirmedNoRenewalContractNum[keyMapTtoal]) //"确认不续约合同(金额/数量)-(数据)"
- var confirmNonRenewalRateMoey string
- var confirmNonRenewalRateNum string
- if confirmedNoRenewalContractMoney[keyMapTtoal] == 0 || mapExpiredContractMoney[keyMapTtoal] == 0 {
- confirmNonRenewalRateMoey = "0%"
- } else {
- confirmNonRenewalRateMoey = utils.SubFloatToString(confirmedNoRenewalContractMoney[keyMapTtoal]/mapExpiredContractMoney[keyMapTtoal]*100, 2) + "%"
- }
- if confirmedNoRenewalContractCompanyNum[keyMapTtoal] == 0 || mapExpiredContractCompanyNum[keyMapTtoal] == 0 {
- confirmNonRenewalRateNum = "0%"
- } else {
- confirmNonRenewalRateNum = utils.SubFloatToString(float64(confirmedNoRenewalContractCompanyNum[keyMapTtoal])/float64(mapExpiredContractCompanyNum[keyMapTtoal])*100, 2) + "%"
- }
- sellerItem.ConfirmNonRenewalRateData = fmt.Sprint(confirmNonRenewalRateMoey, " / ", confirmNonRenewalRateNum) //确认不续约率(金额/数量)-(数据)"
- sellerItem.SignedClientCount = fmt.Sprint(mapSignedClientNum[keyMapTtoal]) // 签约客户数量
- if mapSignedClientNum[keyMapTtoal] == 0 || mapSignedClientMoney[keyMapTtoal] == 0 {
- sellerItem.AverageRevenueCount = "0"
- } else {
- sellerItem.AverageRevenueCount = utils.SubFloatToString(mapSignedClientMoney[keyMapTtoal]/float64(mapSignedClientNum[keyMapTtoal]), 2) //客单价
- }
- sellerItem.InvoiceAmountCount = utils.SubFloatToString(mapInvoiceAmountMoney[keyMapTtoal], 2) //"开票金额-(数据)"
- sellerItem.PaymentReceivedCount = utils.SubFloatToString(mapPaymentAmountMoney[keyMapTtoal], 2) //"开票金额-(数据)"
- if mapInvoiceAmountMoney[keyMapTtoal] == 0 || mapPaymentAmountMoney[keyMapTtoal] == 0 {
- sellerItem.UnpaidRatioCount = "0%"
- } else {
- sellerItem.UnpaidRatioCount = utils.SubFloatToString((mapInvoiceAmountMoney[keyMapTtoal]-mapPaymentAmountMoney[keyMapTtoal])/mapInvoiceAmountMoney[keyMapTtoal]*100, 2) + "%" //"未到款比例-(数据)"
- }
- sellerItem.NewCustomerInvoicingCount = utils.SubFloatToString(mapNewCustomerInvoicingMoney[keyMapTtoal], 2) // "新客开票-(数据)"
- sellerItem.NewCustomerPaymentsReceivedCount = utils.SubFloatToString(mapNewCustomerPaymentsReceivedMoney[keyMapTtoal], 2) // "新客到款-(数据)"
- item.DataList = append(item.DataList, sellerItem)
- }
- for _, vS := range sellerService {
- keyMap = fmt.Sprint(item.DataType, "_Server_", vS.AdminId)
- sellerItem := new(statistic_report.RaiDataSummaryDetail)
- sellerItem.IsServerSeller = true
- sellerItem.SellerId = strconv.Itoa(vS.AdminId)
- sellerServiceIds = append(sellerServiceIds, sellerItem.SellerId)
- sellerItem.SellerName = vS.RealName
- sellerItem.AddTrialCount = fmt.Sprint(mapAddTrialNum[keyMap])
- sellerItem.NewContractData = fmt.Sprint(utils.SubFloatToString(mapNewContractMoneyServer[keyMap], 2), " / ", mapNewContractNumServer[keyMap]) // 新签合同(金额/数量)-(数据)
- sellerItem.ExpiredContractData = fmt.Sprint(utils.SubFloatToString(mapExpiredContractMoneyServer[keyMap], 2), " / ", mapExpiredContractNumServer[keyMap]) //"到期合同(金额/数量)-(数据)"
- sellerItem.RenewedContractData = fmt.Sprint(utils.SubFloatToString(mapRenewedContractMoneyServer[keyMap], 2), " / ", mapRenewedContractNumServer[keyMap]) // "续约合同(金额/数量)-(数据)"
- var renewalRateMoey string
- var renewalRateNum string
- if mapRenewedContractMoneyServer[keyMap] == 0 || mapExpiredContractMoneyServer[keyMap] == 0 {
- renewalRateMoey = "0%"
- } else {
- renewalRateMoey = utils.SubFloatToString(mapRenewedContractMoneyServer[keyMap]/mapExpiredContractMoneyServer[keyMap]*100, 2) + "%"
- }
- if mapRenewedContractCompanyNumServer[keyMap] == 0 || mapExpiredContractCompanyNumServer[keyMap] == 0 {
- renewalRateNum = "0%"
- } else {
- renewalRateNum = utils.SubFloatToString(float64(mapRenewedContractCompanyNumServer[keyMap])/float64(mapExpiredContractCompanyNumServer[keyMap])*100, 2) + "%"
- }
- sellerItem.RenewalRateData = fmt.Sprint(renewalRateMoey, " / ", renewalRateNum) //"续约率(金额/数量)-(数据)"
- sellerItem.ConfirmedNoRenewalContractData = fmt.Sprint(utils.SubFloatToString(confirmedNoRenewalContractMoneyServer[keyMap], 2), " / ", confirmedNoRenewalContractNumServer[keyMap]) //"确认不续约合同(金额/数量)-(数据)"
- var confirmNonRenewalRateMoey string
- var confirmNonRenewalRateNum string
- if confirmedNoRenewalContractMoneyServer[keyMap] == 0 || mapExpiredContractMoneyServer[keyMap] == 0 {
- confirmNonRenewalRateMoey = "0%"
- } else {
- confirmNonRenewalRateMoey = utils.SubFloatToString(confirmedNoRenewalContractMoneyServer[keyMap]/mapExpiredContractMoneyServer[keyMap]*100, 2) + "%"
- }
- if confirmedNoRenewalContractCompanyNumServer[keyMap] == 0 || mapExpiredContractCompanyNumServer[keyMap] == 0 {
- confirmNonRenewalRateNum = "0%"
- } else {
- confirmNonRenewalRateNum = utils.SubFloatToString(float64(confirmedNoRenewalContractCompanyNumServer[keyMap])/float64(mapExpiredContractCompanyNumServer[keyMap])*100, 2) + "%"
- }
- sellerItem.ConfirmNonRenewalRateData = fmt.Sprint(confirmNonRenewalRateMoey, " / ", confirmNonRenewalRateNum) //确认不续约率(金额/数量)-(数据)"
- sellerItem.SignedClientCount = fmt.Sprint(mapSignedClientNumServer[keyMap]) // 签约客户数量
- if mapSignedClientNumServer[keyMap] == 0 || mapSignedClientMoneyServer[keyMap] == 0 {
- sellerItem.AverageRevenueCount = "0"
- } else {
- sellerItem.AverageRevenueCount = utils.SubFloatToString(mapSignedClientMoneyServer[keyMap]/float64(mapSignedClientNumServer[keyMap]), 2) //客单价
- }
- sellerItem.InvoiceAmountCount = utils.SubFloatToString(mapInvoiceAmountMoney[keyMap], 2) //"开票金额-(数据)"
- sellerItem.PaymentReceivedCount = utils.SubFloatToString(mapPaymentAmountMoney[keyMap], 2) //"开票金额-(数据)"
- if mapInvoiceAmountMoney[keyMap] == 0 || mapPaymentAmountMoney[keyMap] == 0 {
- sellerItem.UnpaidRatioCount = "0%"
- } else {
- sellerItem.UnpaidRatioCount = utils.SubFloatToString((mapInvoiceAmountMoney[keyMap]-mapPaymentAmountMoney[keyMap])/mapInvoiceAmountMoney[keyMap]*100, 2) + "%" //"未到款比例-(数据)"
- }
- sellerItem.NewCustomerInvoicingCount = utils.SubFloatToString(mapNewCustomerInvoicingMoney[keyMap], 2) // "新客开票-(数据)"
- sellerItem.NewCustomerPaymentsReceivedCount = utils.SubFloatToString(mapNewCustomerPaymentsReceivedMoney[keyMap], 2) // "新客到款-(数据)"
- if developButton || serverButton || serviceAdminId != "" {
- item.DataList = append(item.DataList, sellerItem)
- }
- }
- if len(sellerService) > 0 && serviceAdminId == "" {
- sellerItem := new(statistic_report.RaiDataSummaryDetail)
- sellerItem.IsServerSeller = true
- sellerItem.SellerId = strings.Join(sellerServiceIds, ",")
- sellerItem.SellerName = "服务组合计"
- sellerItem.AddTrialCount = fmt.Sprint(mapAddTrialNum[keyMapTtoalServer])
- sellerItem.NewContractData = fmt.Sprint(utils.SubFloatToString(mapNewContractMoneyServer[keyMapTtoalServer], 2), " / ", mapNewContractNumServer[keyMapTtoalServer]) // 新签合同(金额/数量)-(数据)
- sellerItem.ExpiredContractData = fmt.Sprint(utils.SubFloatToString(mapExpiredContractMoneyServer[keyMapTtoalServer], 2), " / ", mapExpiredContractNumServer[keyMapTtoalServer]) //"到期合同(金额/数量)-(数据)"
- sellerItem.RenewedContractData = fmt.Sprint(utils.SubFloatToString(mapRenewedContractMoneyServer[keyMapTtoalServer], 2), " / ", mapRenewedContractNumServer[keyMapTtoalServer]) // "续约合同(金额/数量)-(数据)"
- var renewalRateMoey string
- var renewalRateNum string
- if mapRenewedContractMoneyServer[keyMapTtoalServer] == 0 || mapExpiredContractMoneyServer[keyMapTtoalServer] == 0 {
- renewalRateMoey = "0%"
- } else {
- renewalRateMoey = utils.SubFloatToString(mapRenewedContractMoneyServer[keyMapTtoalServer]/mapExpiredContractMoneyServer[keyMapTtoalServer]*100, 2) + "%"
- }
- if mapRenewedContractCompanyNumServer[keyMapTtoalServer] == 0 || mapExpiredContractCompanyNumServer[keyMapTtoalServer] == 0 {
- renewalRateNum = "0%"
- } else {
- renewalRateNum = utils.SubFloatToString(float64(mapRenewedContractCompanyNumServer[keyMapTtoalServer])/float64(mapExpiredContractCompanyNumServer[keyMapTtoalServer])*100, 2) + "%"
- }
- sellerItem.RenewalRateData = fmt.Sprint(renewalRateMoey, " / ", renewalRateNum) //"续约率(金额/数量)-(数据)"
- sellerItem.ConfirmedNoRenewalContractData = fmt.Sprint(utils.SubFloatToString(confirmedNoRenewalContractMoneyServer[keyMapTtoalServer], 2), " / ", confirmedNoRenewalContractNumServer[keyMapTtoalServer]) //"确认不续约合同(金额/数量)-(数据)"
- var confirmNonRenewalRateMoey string
- var confirmNonRenewalRateNum string
- if confirmedNoRenewalContractMoneyServer[keyMapTtoalServer] == 0 || mapExpiredContractMoneyServer[keyMapTtoalServer] == 0 {
- confirmNonRenewalRateMoey = "0%"
- } else {
- confirmNonRenewalRateMoey = utils.SubFloatToString(confirmedNoRenewalContractMoneyServer[keyMapTtoalServer]/mapExpiredContractMoneyServer[keyMapTtoalServer]*100, 2) + "%"
- }
- if confirmedNoRenewalContractCompanyNumServer[keyMapTtoalServer] == 0 || mapExpiredContractCompanyNumServer[keyMapTtoalServer] == 0 {
- confirmNonRenewalRateNum = "0%"
- } else {
- confirmNonRenewalRateNum = utils.SubFloatToString(float64(confirmedNoRenewalContractCompanyNumServer[keyMapTtoalServer])/float64(mapExpiredContractCompanyNumServer[keyMapTtoalServer])*100, 2) + "%"
- }
- sellerItem.ConfirmNonRenewalRateData = fmt.Sprint(confirmNonRenewalRateMoey, " / ", confirmNonRenewalRateNum) //确认不续约率(金额/数量)-(数据)"
- sellerItem.SignedClientCount = fmt.Sprint(mapSignedClientNumServer[keyMapTtoalServer]) // 签约客户数量
- if mapSignedClientNumServer[keyMapTtoalServer] == 0 || mapSignedClientMoneyServer[keyMapTtoalServer] == 0 {
- sellerItem.AverageRevenueCount = "0"
- } else {
- sellerItem.AverageRevenueCount = utils.SubFloatToString(mapSignedClientMoneyServer[keyMapTtoalServer]/float64(mapSignedClientNumServer[keyMapTtoalServer]), 2) //客单价
- }
- sellerItem.InvoiceAmountCount = utils.SubFloatToString(mapInvoiceAmountMoney[keyMapTtoalServer], 2) //"开票金额-(数据)"
- sellerItem.PaymentReceivedCount = utils.SubFloatToString(mapPaymentAmountMoney[keyMapTtoalServer], 2) //"开票金额-(数据)"
- if mapInvoiceAmountMoney[keyMapTtoalServer] == 0 || mapPaymentAmountMoney[keyMapTtoalServer] == 0 {
- sellerItem.UnpaidRatioCount = "0%"
- } else {
- sellerItem.UnpaidRatioCount = utils.SubFloatToString((mapInvoiceAmountMoney[keyMapTtoalServer]-mapPaymentAmountMoney[keyMapTtoalServer])/mapInvoiceAmountMoney[keyMapTtoalServer]*100, 2) + "%" //"未到款比例-(数据)"
- }
- sellerItem.NewCustomerInvoicingCount = utils.SubFloatToString(mapNewCustomerInvoicingMoney[keyMapTtoalServer], 2) // "新客开票-(数据)"
- sellerItem.NewCustomerPaymentsReceivedCount = utils.SubFloatToString(mapNewCustomerPaymentsReceivedMoney[keyMapTtoalServer], 2) // "新客到款-(数据)"
- item.DataList = append(item.DataList, sellerItem)
- }
- items = append(items, item)
- }
- }
- resp.List = items
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // MergeCompanyList
- // @Title 权益数据汇总弹窗详情
- // @Description 权益数据汇总弹窗详情接口
- // @Param SellerId query int true "销售ID"
- // @Param DataType query string false "报表类型,枚举值:`季度`,`年度`,`半年度`"
- // @Param PopupType query string false "弹窗数据类型,枚举值:"
- // @Param IsServerSeller query bool false "是否属于服务组销售"
- // @Param StartDate query string false "开始时间 "
- // @Param EndDate query string false "结束时间 "
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} statistic_report.RaiDataSummaryPopupTypeResp
- // @router /rai_data_summary/detail [get]
- func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- dataType := this.GetString("DataType")
- sellerId := this.GetString("SellerId")
- popupType := this.GetString("PopupType")
- isServerSeller, _ := this.GetBool("IsServerSeller")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- //var startDate string
- //var endDate string
- if startDate == "" {
- year := (dataType[:4])
- if strings.Contains(dataType, "Q1") {
- startDate = year + "-01-01"
- endDate = year + "-03-31"
- } else if strings.Contains(dataType, "Q2") {
- startDate = year + "-04-01"
- endDate = year + "-06-30"
- } else if strings.Contains(dataType, "Q3") {
- startDate = year + "-07-01"
- endDate = year + "-09-30"
- } else if strings.Contains(dataType, "Q4") {
- startDate = year + "-10-01"
- endDate = year + "-12-31"
- } else if strings.Contains(dataType, "H1") {
- startDate = year + "-01-01"
- endDate = year + "-06-31"
- } else if strings.Contains(dataType, "H2") {
- startDate = year + "-07-01"
- endDate = year + "-12-31"
- } else {
- startDate = year + "-01-01"
- endDate = year + "-12-31"
- }
- }
- resp := new(statistic_report.RaiDataSummaryPopupTypeResp)
- var listResp []*statistic_report.RaiDataSummaryDetailResp
- var listGroup []*models.CompanyContractGroupList
- var trialTotal int
- var condition string
- var pars []interface{}
- //新签合同的ID
- var companyContractIdsNew []int
- {
- var conditionNew string
- var parsNew []interface{}
- if sellerId != "" {
- conditionNew += ` AND a.seller_id_init IN (` + sellerId + `) `
- }
- conditionNew += " AND a.product_id = 2 AND a.status = 1 AND a.start_date >= ? AND a.start_date <= ? AND a.rai_contract_type = '新签合同' "
- parsNew = append(parsNew, startDate, endDate)
- listNewData, err := statistic_report.GetRaiDataSummaryList(conditionNew, parsNew)
- if err != nil {
- br.Msg = "获取数据信息失败"
- br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
- return
- }
- for _, v := range listNewData {
- companyContractIdsNew = append(companyContractIdsNew, v.CompanyId)
- }
- }
- companyContractIdsNew = append(companyContractIdsNew, 0)
- lenArrCompany := len(companyContractIdsNew)
- switch popupType {
- case "新增试用":
- var parsTry []interface{}
- var conditionTry string
- if sellerId != "" {
- conditionTry += ` AND a.sys_user_id IN (` + sellerId + `) `
- }
- conditionTry += ` AND a.create_time >= ? AND a.create_time <= ? AND a.operation in ( "add","receive","apply_receive" ) AND a.sys_user_id IN ( SELECT admin_id FROM admin WHERE role_type_code IN ( 'rai_seller', 'rai_group' , 'rai_admin') ) `
- parsTry = append(parsTry, startDate, endDate)
- total, err := models.GetIncrementalCompanyCountByOperationRecordRai(conditionTry, parsTry)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取新增试用客户数量失败,Err:" + err.Error()
- return
- }
- trialTotal = total
- //列表页数据
- tryList, err := models.GetIncrementalCompanyListByOperationRecordRai(conditionTry, parsTry, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if len(tryList) > 0 {
- for _, v := range tryList {
- item := new(statistic_report.RaiDataSummaryDetailResp)
- v.SellerName = v.SysRealName
- if v.Operation == "add" {
- item.AddType = "新建"
- } else if v.Operation == "receive" || v.Operation == "apply_receive" {
- item.AddType = "领取"
- }
- item.CompanyId = v.CompanyId
- item.CompanyName = v.CompanyName
- item.SellerName = v.SellerName
- item.CreateTime = v.CreateTime
- listResp = append(listResp, item)
- }
- }
- case "新签合同":
- if sellerId != "" {
- if isServerSeller {
- condition += ` AND a.share_seller_id_init IN (` + sellerId + `) `
- } else {
- condition += ` AND a.seller_id_init IN (` + sellerId + `) `
- }
- }
- condition += ` AND a.status = 1 AND a.start_date >= ? AND a.start_date <= ? AND a.product_id = 2 `
- pars = append(pars, startDate, endDate)
- condition += ` AND a.rai_contract_type = ? `
- pars = append(pars, "新签合同")
- total, err := company.GetIncrementalNewCompanyProductMergeCount(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- trialTotal = total
- //列表页数据
- tmpList, err := models.GetIncrementalCompanyMergeList(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if len(tmpList) > 0 {
- var companyContractIds []int
- for _, v := range tmpList {
- companyContractIds = append(companyContractIds, v.CompanyContractId)
- }
- //合并合同所对应的权限
- mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapById(companyContractIds)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- for _, v := range tmpList {
- item := new(statistic_report.RaiDataSummaryDetailResp)
- item.CompanyId = v.CompanyId
- item.CompanyName = v.CompanyName
- if isServerSeller {
- item.SellerName = v.ShareSeller
- } else {
- item.SellerName = v.SellerNameInit
- }
- item.StartDate = v.StartDate
- item.EndDate = v.EndDate
- item.Money = v.Money
- item.PermissionName = mappermissionName[v.CompanyContractId]
- listResp = append(listResp, item)
- }
- listGroup, err = models.GetCompanyContractGroupList(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- }
- case "到期合同":
- if sellerId != "" {
- if isServerSeller {
- condition += ` AND a.share_seller_id_last IN (` + sellerId + `) `
- } else {
- condition += ` AND a.seller_id_last IN (` + sellerId + `) `
- }
- }
- condition += ` AND a.product_id = 2 AND a.status = 1 AND a.due_end_date >= ? AND a.due_end_date <= ? AND a.end_date < ? `
- pars = append(pars, startDate, endDate, time.Now().Format(utils.FormatDate))
- total, err := company.GetIncrementalNewCompanyProductMergeCount(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- trialTotal = total
- //列表页数据
- tmpList, err := models.GetIncrementalCompanyMergeListEnd(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if len(tmpList) > 0 {
- var companyContractIds []int
- for _, v := range tmpList {
- companyContractIds = append(companyContractIds, v.CompanyContractId)
- }
- //合并合同所对应的权限
- mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapById(companyContractIds)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- for _, v := range tmpList {
- item := new(statistic_report.RaiDataSummaryDetailResp)
- item.CompanyId = v.CompanyId
- item.CompanyName = v.CompanyName
- if isServerSeller {
- item.SellerName = v.ShareSellerLast
- } else {
- item.SellerName = v.SellerNameLast
- }
- item.StartDate = v.StartDate
- item.EndDate = v.EndDate
- item.Money = v.Money
- item.PermissionName = mappermissionName[v.CompanyContractId]
- listResp = append(listResp, item)
- }
- listGroup, err = models.GetCompanyContractGroupList(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- }
- case "续约合同":
- if sellerId != "" {
- if isServerSeller {
- condition += ` AND a.share_seller_id_init IN (` + sellerId + `) `
- } else {
- condition += ` AND a.seller_id_init IN (` + sellerId + `) `
- }
- }
- condition += ` AND a.status = 1 AND a.inherit_end_date >= ? AND a.inherit_end_date <= ? AND a.inherit_company_contract_id > 0 AND a.rai_contract_type = '续约合同' AND a.company_contract_id NOT IN (` + utils.GetOrmInReplace(lenArrCompany) + `) `
- pars = append(pars, startDate, endDate, companyContractIdsNew)
- total, err := company.GetIncrementalNewCompanyProductMergeCount(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- trialTotal = total
- //列表页数据
- tmpList, err := models.GetIncrementalCompanyMergeList(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if len(tmpList) > 0 {
- var companyContractIds []int
- for _, v := range tmpList {
- companyContractIds = append(companyContractIds, v.CompanyContractId)
- }
- //合并合同所对应的权限
- mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapById(companyContractIds)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- for _, v := range tmpList {
- item := new(statistic_report.RaiDataSummaryDetailResp)
- item.CompanyId = v.CompanyId
- item.CompanyName = v.CompanyName
- if isServerSeller {
- item.SellerName = v.ShareSellerLast
- } else {
- item.SellerName = v.SellerNameLast
- }
- item.StartDate = v.StartDate
- item.EndDate = v.EndDate
- item.Money = v.Money
- item.PermissionName = mappermissionName[v.CompanyContractId]
- listResp = append(listResp, item)
- }
- listGroup, err = models.GetCompanyContractGroupList(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- }
- case "续约率":
- var conditionEnd string
- var parsEnd []interface{}
- if sellerId != "" {
- if isServerSeller {
- condition += ` AND a.share_seller_id_init IN (` + sellerId + `) `
- conditionEnd += ` AND a.share_seller_id_last IN (` + sellerId + `) `
- } else {
- condition += ` AND a.seller_id_init IN (` + sellerId + `) `
- conditionEnd += ` AND a.seller_id_last IN (` + sellerId + `) `
- }
- }
- condition += ` AND a.status = 1 AND a.inherit_end_date >= ? AND a.inherit_end_date <= ? AND inherit_company_contract_id > 0 AND a.rai_contract_type = '续约合同' AND a.company_contract_id NOT IN (` + utils.GetOrmInReplace(lenArrCompany) + `) `
- pars = append(pars, startDate, endDate, companyContractIdsNew)
- listRaiData, err := statistic_report.GetRaiDataSummaryList(condition, pars)
- if err != nil {
- br.Msg = "获取数据信息失败"
- br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
- return
- }
- //到期合同数据
- conditionEnd += ` AND a.status = 1 AND a.due_end_date >= ? AND a.due_end_date <= ? AND a.end_date < ? `
- parsEnd = append(parsEnd, startDate, endDate, time.Now().Format(utils.FormatDate))
- listEndData, err := statistic_report.GetRaiDataSummaryList(conditionEnd, parsEnd)
- if err != nil {
- br.Msg = "获取数据信息失败"
- br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
- return
- }
- var renewedContractMoney float64 // 续约金额
- var renewedContractCompany float64 // 续约客户数
- maprenewedContractCompany := make(map[int]bool)
- var expiredContractMoney float64 //到期金额
- var expiredContractCompany float64 // 到期客户数
- mapexpiredContractCompany := make(map[int]bool)
- for _, v := range listRaiData {
- renewedContractMoney += v.Money
- if !maprenewedContractCompany[v.CompanyId] {
- renewedContractCompany++
- maprenewedContractCompany[v.CompanyId] = true
- }
- //startDateTime := utils.StrDateToDate(v.StartDate)
- //if startDateTime.Before(time.Now().AddDate(0, 0, -1)) { //到期合同数据
- // expiredContractMoney += v.Money
- // if !mapexpiredContractCompany[v.CompanyId] {
- // expiredContractCompany++
- // mapexpiredContractCompany[v.CompanyId] = true
- // }
- //}
- }
- for _, v := range listEndData {
- expiredContractMoney += v.Money
- if !mapexpiredContractCompany[v.CompanyId] {
- expiredContractCompany++
- mapexpiredContractCompany[v.CompanyId] = true
- }
- }
- item := new(statistic_report.RaiDataSummaryDetailResp)
- item.TbaleNameAText = "金额续约率"
- item.RenewedContractMoney = fmt.Sprint(utils.SubFloatToString(renewedContractMoney, 2))
- item.ExpiredContractMoney = fmt.Sprint(utils.SubFloatToString(expiredContractMoney, 2))
- if renewedContractMoney == 0 || expiredContractMoney == 0 {
- item.RenewalRate = "0%"
- } else {
- item.RenewalRate = fmt.Sprint(utils.SubFloatToString(renewedContractMoney/expiredContractMoney*100, 2), "%")
- }
- listResp = append(listResp, item)
- item2 := new(statistic_report.RaiDataSummaryDetailResp)
- item2.TbaleNameAText = "客户续约率"
- item2.RenewedContractMoney = fmt.Sprint(renewedContractCompany)
- item2.ExpiredContractMoney = fmt.Sprint(expiredContractCompany)
- if renewedContractCompany == 0 || expiredContractCompany == 0 {
- item2.RenewalRate = "0%"
- } else {
- item2.RenewalRate = fmt.Sprint(utils.SubFloatToString(renewedContractCompany/expiredContractCompany*100, 2), "%")
- }
- listResp = append(listResp, item2)
- case "确认不续约合同":
- noRenewedcompanyContractIds := services.GetCompanyContractNoRenewedAscribeListArr()
- condition += ` AND a.company_contract_id IN (` + utils.GetOrmInReplace(len(noRenewedcompanyContractIds)) + `) ` // 已确认
- pars = append(pars, noRenewedcompanyContractIds)
- if sellerId != "" {
- if isServerSeller {
- condition += ` AND a.share_seller_id_last IN (` + sellerId + `) `
- } else {
- condition += ` AND a.seller_id_last IN (` + sellerId + `) `
- }
- }
- condition += ` AND a.product_id = 2 AND a.status = 1 AND a.end_date >= ? AND a.end_date <= ? AND a.end_date <= ? `
- pars = append(pars, startDate, endDate, time.Now().Format(utils.FormatDate))
- total, err := company.GetIncrementalNewCompanyProductMergeCount(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- trialTotal = total
- //列表页数据
- tmpList, err := models.GetIncrementalCompanyMergeList(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if len(tmpList) > 0 {
- var companyContractIds []int
- for _, v := range tmpList {
- companyContractIds = append(companyContractIds, v.CompanyContractId)
- }
- //合并合同所对应的权限
- mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapById(companyContractIds)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- for _, v := range tmpList {
- item := new(statistic_report.RaiDataSummaryDetailResp)
- item.CompanyId = v.CompanyId
- item.CompanyName = v.CompanyName
- if isServerSeller {
- item.SellerName = v.ShareSellerLast
- } else {
- item.SellerName = v.SellerNameLast
- }
- item.StartDate = v.StartDate
- item.EndDate = v.EndDate
- item.Money = v.Money
- item.PermissionName = mappermissionName[v.CompanyContractId]
- listResp = append(listResp, item)
- }
- listGroup, err = models.GetCompanyContractGroupList(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- }
- case "确认不续约率":
- noRenewedcompanyContractIdsMap := services.GetCompanyContractNoRenewedAscribeListMap()
- var conditionEnd string
- var parsEnd []interface{}
- if sellerId != "" {
- if isServerSeller {
- condition += ` AND a.share_seller_id_init IN (` + sellerId + `) `
- conditionEnd += ` AND a.share_seller_id_last IN (` + sellerId + `) `
- } else {
- condition += ` AND a.seller_id_init IN (` + sellerId + `) `
- conditionEnd += ` AND a.seller_id_last IN (` + sellerId + `) `
- }
- }
- condition += ` AND a.product_id = 2 AND a.status = 1 AND a.end_date >= ? AND a.end_date <= ? AND a.end_date <= ? `
- pars = append(pars, startDate, endDate, time.Now().Format(utils.FormatDate))
- listRaiData, err := statistic_report.GetRaiDataSummaryList(condition, pars)
- if err != nil {
- br.Msg = "获取数据信息失败"
- br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
- return
- }
- conditionEnd += ` AND a.product_id = 2 AND a.status = 1 AND a.due_end_date >= ? AND a.due_end_date <= ? AND a.end_date < ? `
- parsEnd = append(parsEnd, startDate, endDate, time.Now().Format(utils.FormatDate))
- listEndData, err := statistic_report.GetRaiDataSummaryList(conditionEnd, parsEnd)
- if err != nil {
- br.Msg = "获取数据信息失败"
- br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
- return
- }
- var norenewedContractMoney float64 // 不续约金额
- var norenewedContractCompany float64 // 不续约客户数
- mapnorenewedContractCompany := make(map[int]bool)
- var expiredContractMoney float64 //到期金额
- var expiredContractCompany float64 // 到期客户数
- mapexpiredContractCompany := make(map[int]bool)
- for _, v := range listRaiData {
- if noRenewedcompanyContractIdsMap[v.CompanyContractId] {
- norenewedContractMoney += v.Money
- if !mapnorenewedContractCompany[v.CompanyId] {
- norenewedContractCompany++
- mapnorenewedContractCompany[v.CompanyId] = true
- }
- }
- }
- for _, v := range listEndData {
- expiredContractMoney += v.Money
- if !mapexpiredContractCompany[v.CompanyId] {
- expiredContractCompany++
- mapexpiredContractCompany[v.CompanyId] = true
- }
- }
- item := new(statistic_report.RaiDataSummaryDetailResp)
- item.TbaleNameAText = "金额不续约率"
- item.RenewedContractMoney = fmt.Sprint(utils.SubFloatToString(norenewedContractMoney, 2))
- item.ExpiredContractMoney = fmt.Sprint(utils.SubFloatToString(expiredContractMoney, 2))
- if norenewedContractMoney == 0 || expiredContractMoney == 0 {
- item.RenewalRate = "0%"
- } else {
- item.RenewalRate = fmt.Sprint(utils.SubFloatToString(norenewedContractMoney/expiredContractMoney*100, 2), "%")
- }
- listResp = append(listResp, item)
- item2 := new(statistic_report.RaiDataSummaryDetailResp)
- item2.TbaleNameAText = "客户不续约率"
- item2.RenewedContractMoney = fmt.Sprint(norenewedContractCompany)
- item2.ExpiredContractMoney = fmt.Sprint(expiredContractCompany)
- if norenewedContractCompany == 0 || expiredContractCompany == 0 {
- item2.RenewalRate = "0%"
- } else {
- item2.RenewalRate = fmt.Sprint(utils.SubFloatToString(norenewedContractCompany/expiredContractCompany*100, 2), "%")
- }
- listResp = append(listResp, item2)
- case "签约客户数量":
- var conditionInherit string
- var parsInherit []interface{}
- if sellerId != "" {
- if isServerSeller {
- condition += ` AND a.share_seller_id_init IN (` + sellerId + `) `
- conditionInherit += ` AND a.share_seller_id_last IN (` + sellerId + `) `
- } else {
- condition += ` AND a.seller_id_init IN (` + sellerId + `) `
- conditionInherit += ` AND a.seller_id_last IN (` + sellerId + `) `
- }
- }
- condition += " AND a.product_id = 2 AND a.status = 1 AND a.start_date >= ? AND a.start_date <= ? AND a.rai_contract_type = '新签合同' "
- pars = append(pars, startDate, endDate)
- listRaiData, err := statistic_report.GetRaiDataSummaryList(condition, pars)
- if err != nil {
- br.Msg = "获取数据信息失败"
- br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
- return
- }
- //续约部分的数据
- conditionInherit += ` AND a.product_id = 2 AND a.status = 1 AND a.inherit_end_date >= ? AND a.inherit_end_date <= ? AND a.inherit_company_contract_id > 0 AND a.rai_contract_type = '续约合同' AND a.company_contract_id NOT IN (` + utils.GetOrmInReplace(lenArrCompany) + `) `
- parsInherit = append(parsInherit, startDate, endDate, companyContractIdsNew)
- listInheritData, err := statistic_report.GetRaiDataSummaryInheritList(conditionInherit, parsInherit)
- if err != nil {
- br.Msg = "获取数据信息失败"
- br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
- return
- }
- var renewedContractCompany int // 续约客户数
- var renewedContract int // 续约合同数
- maprenewedContractCompany := make(map[int]bool)
- var newContractCompany int // 新签客户数
- var newContract int // 新签合同数
- mapenewContractCompany := make(map[int]bool)
- for _, v := range listRaiData {
- if v.RaiContractType == "新签合同" {
- newContract++
- if !mapenewContractCompany[v.CompanyId] {
- newContractCompany++
- mapenewContractCompany[v.CompanyId] = true
- }
- }
- //else if v.RaiContractType == "续约合同" {
- // renewedContract++
- // if !maprenewedContractCompany[v.CompanyId] {
- // renewedContractCompany++
- // maprenewedContractCompany[v.CompanyId] = true
- // }
- //}
- }
- for _, v := range listInheritData {
- renewedContract++
- if !maprenewedContractCompany[v.CompanyId] {
- renewedContractCompany++
- maprenewedContractCompany[v.CompanyId] = true
- }
- }
- item := new(statistic_report.RaiDataSummaryDetailResp)
- item.RenewedContractCompany = renewedContractCompany
- item.RenewedContract = renewedContract
- item.NewContractCompany = newContractCompany
- item.NewContract = newContract
- listResp = append(listResp, item)
- case "客单价":
- //续约部分的数据
- var conditionInherit string
- var parsInherit []interface{}
- if sellerId != "" {
- if isServerSeller {
- condition += ` AND a.share_seller_id_init IN (` + sellerId + `) `
- conditionInherit += ` AND a.share_seller_id_last IN (` + sellerId + `) `
- } else {
- condition += ` AND a.seller_id_init IN (` + sellerId + `) `
- conditionInherit += ` AND a.seller_id_last IN (` + sellerId + `) `
- }
- }
- condition += " AND a.product_id = 2 AND a.status = 1 AND a.start_date >= ? AND a.start_date <= ? AND a.rai_contract_type = '新签合同' "
- pars = append(pars, startDate, endDate)
- listRaiData, err := statistic_report.GetRaiDataSummaryList(condition, pars)
- if err != nil {
- br.Msg = "获取数据信息失败"
- br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
- return
- }
- var ontractMoney float64 // 签约总金额
- var contractNum int // 签约客户数
- mapCompany := make(map[int]bool)
- for _, v := range listRaiData {
- if v.RaiContractType != "新签合同" {
- continue
- }
- ontractMoney += v.Money
- if !mapCompany[v.CompanyId] {
- contractNum++
- mapCompany[v.CompanyId] = true
- }
- }
- conditionInherit += ` AND a.product_id = 2 AND a.status = 1 AND a.inherit_end_date >= ? AND a.inherit_end_date <= ? AND a.rai_contract_type = '续约合同' AND a.company_contract_id NOT IN (` + utils.GetOrmInReplace(lenArrCompany) + `) `
- parsInherit = append(parsInherit, startDate, endDate, companyContractIdsNew)
- listInheritData, err := statistic_report.GetRaiDataSummaryInheritList(conditionInherit, parsInherit)
- if err != nil {
- br.Msg = "获取数据信息失败"
- br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
- return
- }
- for _, v := range listInheritData {
- ontractMoney += v.Money
- if !mapCompany[v.CompanyId] && v.RaiContractType == "续约合同" {
- contractNum++
- mapCompany[v.CompanyId] = true
- }
- }
- item := new(statistic_report.RaiDataSummaryDetailResp)
- item.ContractMoney = fmt.Sprint(utils.SubFloatToString(ontractMoney, 2))
- item.ContractNum = contractNum
- listResp = append(listResp, item)
- case "开票金额":
- if sellerId != "" {
- condition += ` AND a.rai_seller_id IN (` + sellerId + `) `
- }
- condition += " AND a.is_deleted = 0 AND a.invoiced_amount > 0 AND b.invoice_type = 1 AND b.invoice_time >= ? AND b.invoice_time <= ? "
- pars = append(pars, startDate, endDate)
- total, err := fms.GetContractInvoiceCount(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- trialTotal = total
- condition += " GROUP BY b.contract_invoice_id ORDER BY invoice_time DESC "
- listFmsData, err := fms.GetContractRegisterList(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取数据信息失败"
- br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
- return
- }
- if len(listFmsData) > 0 {
- for _, v := range listFmsData {
- item := new(statistic_report.RaiDataSummaryDetailResp)
- item.CompanyName = v.CompanyName
- item.SellerName = v.RaiSellerName
- item.ContractCode = v.ContractCode
- item.InvoicedAmount = v.Amount
- item.CreateTime = v.InvoiceTime
- listResp = append(listResp, item)
- }
- }
- case "到款金额":
- if sellerId != "" {
- condition += ` AND a.rai_seller_id IN (` + sellerId + `) `
- }
- condition += " AND a.is_deleted = 0 AND a.payment_amount > 0 AND b.invoice_type = 2 AND b.invoice_time >= ? AND b.invoice_time <= ? "
- pars = append(pars, startDate, endDate)
- total, err := fms.GetContractInvoiceCount(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- trialTotal = total
- condition += " GROUP BY b.contract_invoice_id ORDER BY invoice_time DESC "
- listFmsData, err := fms.GetContractRegisterList(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取数据信息失败"
- br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
- return
- }
- if len(listFmsData) > 0 {
- for _, v := range listFmsData {
- item := new(statistic_report.RaiDataSummaryDetailResp)
- item.CompanyName = v.CompanyName
- item.SellerName = v.RaiSellerName
- item.ContractCode = v.ContractCode
- item.PaymentAmount = v.Amount
- item.CreateTime = v.InvoiceTime
- listResp = append(listResp, item)
- }
- }
- case "未到款比例":
- if sellerId != "" {
- condition += ` AND a.rai_seller_id IN (` + sellerId + `) `
- }
- var condition2 string
- var pars2 []interface{}
- condition2 = condition + " AND a.is_deleted = 0 AND a.payment_amount > 0 AND b.invoice_type = 2 AND b.invoice_time >= ? AND b.invoice_time <= ? "
- pars2 = append(pars2, startDate, endDate)
- condition += " AND a.is_deleted = 0 AND a.invoiced_amount > 0 AND b.invoice_type = 1 AND b.invoice_time >= ? AND b.invoice_time <= ? "
- pars = append(pars, startDate, endDate)
- amount1, err := fms.GetContractInvoiceAmountCount(condition, pars) //开票金额总计
- if err != nil {
- br.Msg = "获取数据信息失败"
- br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
- return
- }
- amount2, err := fms.GetContractInvoiceAmountCount(condition2, pars2) //到款金额总计
- if err != nil {
- br.Msg = "获取数据信息失败"
- br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
- return
- }
- item := new(statistic_report.RaiDataSummaryDetailResp)
- item.InvoicedAmount = amount1
- item.PaymentAmount = amount2
- item.NotReceivedtAmount = amount1 - amount2
- listResp = append(listResp, item)
- case "新客开票":
- if sellerId != "" {
- condition += ` AND a.rai_seller_id IN (` + sellerId + `) `
- }
- condition += " AND a.is_deleted = 0 AND a.contract_type = 1 AND a.invoiced_amount > 0 AND b.invoice_type = 1 AND b.invoice_time >= ? AND b.invoice_time <= ? "
- pars = append(pars, startDate, endDate)
- total, err := fms.GetContractInvoiceCount(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- trialTotal = total
- condition += " GROUP BY b.contract_invoice_id ORDER BY invoice_time DESC "
- listFmsData, err := fms.GetContractRegisterList(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取数据信息失败"
- br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
- return
- }
- if len(listFmsData) > 0 {
- for _, v := range listFmsData {
- item := new(statistic_report.RaiDataSummaryDetailResp)
- item.CompanyName = v.CompanyName
- item.SellerName = v.RaiSellerName
- item.ContractCode = v.ContractCode
- item.InvoicedAmount = v.Amount
- item.CreateTime = v.InvoiceTime
- listResp = append(listResp, item)
- }
- }
- case "新客到款":
- if sellerId != "" {
- condition += ` AND a.rai_seller_id IN (` + sellerId + `) `
- }
- condition += " AND a.is_deleted = 0 AND a.contract_type = 1 AND a.payment_amount > 0 AND b.invoice_type = 2 AND b.invoice_time >= ? AND b.invoice_time <= ? "
- pars = append(pars, startDate, endDate)
- total, err := fms.GetContractInvoiceCount(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- trialTotal = total
- condition += " GROUP BY b.contract_invoice_id ORDER BY invoice_time DESC "
- listFmsData, err := fms.GetContractRegisterList(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取数据信息失败"
- br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
- return
- }
- if len(listFmsData) > 0 {
- for _, v := range listFmsData {
- item := new(statistic_report.RaiDataSummaryDetailResp)
- item.CompanyName = v.CompanyName
- item.SellerName = v.RaiSellerName
- item.ContractCode = v.ContractCode
- item.PaymentAmount = v.Amount
- item.CreateTime = v.InvoiceTime
- listResp = append(listResp, item)
- }
- }
- }
- if len(listResp) == 0 {
- listResp = make([]*statistic_report.RaiDataSummaryDetailResp, 0)
- }
- if len(listGroup) > 0 {
- for _, v := range listGroup {
- if v.CompanyCount > 1 {
- resp.CompanyMultiple++
- }
- }
- resp.CompanyNum = len(listGroup)
- }
- resp.List = listResp
- page := paging.GetPaging(currentIndex, pageSize, trialTotal)
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // 时间筛选项的转换
- func getYearStar(startDate time.Time, dataType string, isCustomizeDate bool) (yearStr string) {
- if isCustomizeDate {
- return //如果有自定的时间,就传空值
- }
- startDateTime := startDate
- monthNum := startDateTime.Month()
- yearStr = strconv.Itoa(startDateTime.Year())
- if dataType == "季度" {
- if monthNum < 4 {
- yearStr += "Q1"
- } else if monthNum > 3 && monthNum < 7 {
- yearStr += "Q2"
- } else if monthNum > 6 && monthNum < 10 {
- yearStr += "Q3"
- } else if monthNum > 9 {
- yearStr += "Q4"
- }
- } else if dataType == "半年度" {
- if monthNum < 7 {
- yearStr += "H1"
- } else {
- yearStr += "H2"
- }
- }
- return
- }
|