123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560 |
- 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 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")
- dataTypeArr := []string{}
- if dataType == "季度" {
- dataTypeArr = []string{"Q1", "Q2", "Q3", "Q4"}
- } else if dataType == "半年度" {
- dataTypeArr = []string{"H1", "H2"}
- } else {
- dataTypeArr = []string{""}
- }
- condition := " AND role_type_code IN ('rai_seller','rai_group') AND enabled = 1 AND rai_enabled = 1 "
- var pars []interface{}
- if adminId != "" {
- serviceAdminId = ""
- condition += " AND admin_id IN (" + adminId + ") "
- }
- if serviceAdminId != "" {
- condition += " AND admin_id IN (" + serviceAdminId + ") "
- }
- 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
- }
- //拼接起始时间查询
- startDate := fmt.Sprintf("%d-01-01", startYear)
- endDate := fmt.Sprintf("%d-12-31", endYear)
- //新签部分的数据
- var conditionRai string
- var parsRai []interface{}
- conditionRai = " AND a.product_id = 2 AND a.status = 1 AND a.start_date >= ? AND a.start_date <= ? "
- parsRai = append(parsRai, startDate, endDate)
- listRaiData, err := statistic_report.GetRaiDataSummaryList(conditionRai, parsRai)
- if err != nil {
- br.Msg = "获取数据信息失败"
- br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
- return
- }
- //续约部分的数据
- 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 = '续约合同' "
- parsInherit = append(parsInherit, startDate, endDate)
- 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.end_date >= ? AND a.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) // 续约合同(数量)
- confirmedNoRenewalContractMoney := make(map[string]float64) // 确认不续约合同(金额)
- confirmedNoRenewalContractNum := make(map[string]int) // 确认不续约合同(数量)
- confirmedNoRenewalComapnyNum := 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) // 财务系统新客到款金额(金额)
- var keyMap string
- var keyMapTtoal string
- var keyMapTtoalServer string
- var keyMapCompany string
- var keyMapCompanyNo string
- var keySigned string
- mapCompanyData := make(map[string]bool)
- //新签部分的数据
- for _, v := range listRaiData {
- if !mapsellerId[v.SellerIdLast] {
- continue
- }
- startDateTime := utils.StrDateToDate(v.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"
- }
- }
- keyMap = fmt.Sprint(yearStr, "_", v.SellerIdLast)
- keySigned = fmt.Sprint(yearStr, "_", "_CID_", v.CompanyId, "_SID_", v.SellerIdLast)
- if sellerDevelopIds[v.SellerIdLast] == true {
- keyMapTtoal = fmt.Sprint(yearStr, "_Develop")
- } else {
- keyMapTtoal = fmt.Sprint(yearStr, "_Service")
- }
- if v.RaiContractType == "新签合同" {
- mapNewContractMoney[keyMap] += v.Money
- mapNewContractNum[keyMap]++
- mapNewContractMoney[keyMapTtoal] += v.Money
- mapNewContractNum[keyMapTtoal]++
- }
- //else if v.RaiContractType == "续约合同" {
- // mapRenewedContractMoney[keyMap] += v.Money
- // mapRenewedContractNum[keyMap]++
- //
- // mapRenewedContractMoney[keyMapTtoal] += v.Money
- // mapRenewedContractNum[keyMapTtoal]++
- //}
- //if startDateTime.Before(time.Now().AddDate(0, 0, -1)) { //到期合同数据
- // mapExpiredContractMoney[keyMap] += v.Money
- // mapExpiredContractNum[keyMap]++
- //
- // mapExpiredContractMoney[keyMapTtoal] += v.Money
- // mapExpiredContractNum[keyMapTtoal]++
- //}
- //
- //if mapNoRenewedcompanyContractIds[v.CompanyContractId] { // 确认不续约合同
- // confirmedNoRenewalContractMoney[keyMap] += v.Money
- // confirmedNoRenewalContractNum[keyMap]++
- //
- // confirmedNoRenewalContractMoney[keyMapTtoal] += v.Money
- // confirmedNoRenewalContractNum[keyMapTtoal]++
- //}
- mapSignedClientMoney[keyMap] += v.Money
- mapSignedClientMoney[keyMapTtoal] += v.Money
- if !mapCompanyData[keySigned] && v.RaiContractType == "新签合同" {
- mapSignedClientNum[keyMap]++
- mapSignedClientNum[keyMapTtoal]++
- mapCompanyData[keySigned] = true
- }
- }
- //fmt.Println(mapSignedClientNum)
- //续约部分的数据
- mapKeyMapCompanyData := make(map[string]bool)
- for _, v := range listInheritData {
- if !mapsellerId[v.SellerIdLast] {
- continue
- }
- startDateTime := utils.StrDateToDate(v.InheritEndDate)
- 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"
- }
- }
- keyMap = fmt.Sprint(yearStr, "_", v.SellerIdLast)
- keyMapCompany = fmt.Sprint(yearStr, "_", v.SellerIdLast, "_CID_", v.CompanyId)
- if sellerDevelopIds[v.SellerIdLast] == true {
- keyMapTtoal = fmt.Sprint(yearStr, "_Develop")
- } else {
- keyMapTtoal = fmt.Sprint(yearStr, "_Service")
- }
- //续约合同 数据
- mapRenewedContractMoney[keyMap] += v.Money
- mapRenewedContractMoney[keyMapTtoal] += v.Money
- //一家公司同一个时间纬度,只统计一次
- if !mapKeyMapCompanyData[keyMapCompany] {
- mapRenewedContractNum[keyMap]++
- mapRenewedContractNum[keyMapTtoal]++
- mapKeyMapCompanyData[keyMapCompany] = true
- }
- if !mapCompanyData[keySigned] && v.RaiContractType == "续约合同" {
- mapSignedClientNum[keyMap]++
- mapSignedClientNum[keyMapTtoal]++
- mapCompanyData[keySigned] = true
- }
- }
- //确认不续约、到期合同部分的数据
- mapKeyMapCompanyEndData := make(map[string]bool)
- mapKeyMapCompanyNoData := make(map[string]bool)
- for _, v := range listEndData {
- if !mapsellerId[v.SellerIdLast] {
- continue
- }
- startDateTime := utils.StrDateToDate(v.EndDate)
- 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"
- }
- }
- 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)
- if sellerDevelopIds[v.SellerIdLast] == true {
- keyMapTtoal = fmt.Sprint(yearStr, "_Develop")
- } else {
- keyMapTtoal = fmt.Sprint(yearStr, "_Service")
- }
- //到期合同数据
- mapExpiredContractMoney[keyMap] += v.Money
- mapExpiredContractMoney[keyMapTtoal] += v.Money
- //一家公司同一个时间纬度,只统计一次
- //if !mapKeyMapCompanyEndData[keyMapCompany] {
- mapExpiredContractNum[keyMap]++
- mapExpiredContractNum[keyMapTtoal]++
- //mapKeyMapCompanyEndData[keyMapCompany] = true
- //}
- //一家公司同一个时间纬度,只统计一次
- if !mapKeyMapCompanyEndData[keyMapCompany] {
- mapExpiredContractCompanyNum[keyMap]++
- mapExpiredContractCompanyNum[keyMapTtoal]++
- mapKeyMapCompanyEndData[keyMapCompany] = true
- }
- if mapNoRenewedcompanyContractIds[v.CompanyContractId] { // 确认不续约合同
- confirmedNoRenewalContractMoney[keyMap] += v.Money
- confirmedNoRenewalContractMoney[keyMapTtoal] += v.Money
- //一家公司同一个时间纬度,只统计一次
- //if !mapKeyMapCompanyNoData[keyMapCompanyNo] {
- confirmedNoRenewalContractNum[keyMap]++
- confirmedNoRenewalContractNum[keyMapTtoal]++
- //mapKeyMapCompanyNoData[keyMapCompanyNo] = true
- //}
- if !mapKeyMapCompanyNoData[keyMapCompanyNo] {
- confirmedNoRenewalComapnyNum[keyMap]++
- confirmedNoRenewalComapnyNum[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 !mapsellerId[v.RaiSellerId] {
- continue
- }
- startDateTime := v.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"
- }
- }
- keyMap = fmt.Sprint(yearStr, "_", v.RaiSellerId)
- if sellerDevelopIds[v.RaiSellerId] == true {
- keyMapTtoal = fmt.Sprint(yearStr, "_Develop")
- } else {
- keyMapTtoal = fmt.Sprint(yearStr, "_Service")
- }
- mapInvoiceAmountMoney[keyMap] += v.InvoicedAmount
- mapPaymentAmountMoney[keyMap] += v.PaymentAmount
- mapInvoiceAmountMoney[keyMapTtoal] += v.InvoicedAmount
- mapPaymentAmountMoney[keyMapTtoal] += v.PaymentAmount
- if v.ContractType == 1 {
- mapNewCustomerInvoicingMoney[keyMap] += v.InvoicedAmount
- mapNewCustomerPaymentsReceivedMoney[keyMap] += v.PaymentAmount
- mapNewCustomerInvoicingMoney[keyMapTtoal] += v.InvoicedAmount
- mapNewCustomerPaymentsReceivedMoney[keyMapTtoal] += v.PaymentAmount
- }
- }
- 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') ) `
- 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"
- }
- }
- 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, "_Service")
- }
- mapAddTrialNum[keyMapTtoal]++
- }
- fmt.Println(mapExpiredContractCompanyNum)
- fmt.Println(confirmedNoRenewalContractNum)
- resp := new(statistic_report.RaiDataSummaryListResp)
- var items []*statistic_report.RaiDataSummaryResp
- for i := startYear; i <= endYear; i++ {
- //if len(dataTypeArr) > 0 {
- for _, Dv := range dataTypeArr {
- item := new(statistic_report.RaiDataSummaryResp)
- item.DataType = fmt.Sprint(i, Dv)
- keyMapTtoal = fmt.Sprint(item.DataType, "_Develop")
- keyMapTtoalServer = fmt.Sprint(item.DataType, "_Server")
- var sellerIds []string
- var sellerServiceIds []string
- 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 mapRenewedContractNum[keyMap] == 0 || mapExpiredContractCompanyNum[keyMap] == 0 {
- renewalRateNum = "0%"
- } else {
- renewalRateNum = utils.SubFloatToString(float64(mapRenewedContractNum[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 confirmedNoRenewalComapnyNum[keyMap] == 0 || mapExpiredContractCompanyNum[keyMap] == 0 {
- confirmNonRenewalRateNum = "0%"
- } else {
- confirmNonRenewalRateNum = utils.SubFloatToString(float64(confirmedNoRenewalComapnyNum[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 {
- 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 mapRenewedContractNum[keyMapTtoal] == 0 || mapExpiredContractCompanyNum[keyMapTtoal] == 0 {
- renewalRateNum = "0%"
- } else {
- renewalRateNum = utils.SubFloatToString(float64(mapRenewedContractNum[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 confirmedNoRenewalComapnyNum[keyMapTtoal] == 0 || mapExpiredContractCompanyNum[keyMapTtoal] == 0 {
- confirmNonRenewalRateNum = "0%"
- } else {
- confirmNonRenewalRateNum = utils.SubFloatToString(float64(confirmedNoRenewalComapnyNum[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 {
- sellerItem := new(statistic_report.RaiDataSummaryDetail)
- 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(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 mapRenewedContractNum[keyMap] == 0 || mapExpiredContractCompanyNum[keyMap] == 0 {
- renewalRateNum = "0%"
- } else {
- renewalRateNum = utils.SubFloatToString(float64(mapRenewedContractNum[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 confirmedNoRenewalComapnyNum[keyMap] == 0 || mapExpiredContractCompanyNum[keyMap] == 0 {
- confirmNonRenewalRateNum = "0%"
- } else {
- confirmNonRenewalRateNum = utils.SubFloatToString(float64(confirmedNoRenewalComapnyNum[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 || serviceAdminId != "" {
- item.DataList = append(item.DataList, sellerItem)
- }
- }
- if len(sellerService) > 0 {
- sellerItem := new(statistic_report.RaiDataSummaryDetail)
- sellerItem.SellerId = strings.Join(sellerServiceIds, ",")
- sellerItem.SellerName = "服务组合计"
- sellerItem.AddTrialCount = fmt.Sprint(mapAddTrialNum[keyMapTtoalServer])
- sellerItem.NewContractData = fmt.Sprint(utils.SubFloatToString(mapNewContractMoney[keyMapTtoalServer], 2), " / ", mapNewContractNum[keyMapTtoalServer]) // 新签合同(金额/数量)-(数据)
- sellerItem.ExpiredContractData = fmt.Sprint(utils.SubFloatToString(mapExpiredContractMoney[keyMapTtoalServer], 2), " / ", mapExpiredContractNum[keyMapTtoalServer]) //"到期合同(金额/数量)-(数据)"
- sellerItem.RenewedContractData = fmt.Sprint(utils.SubFloatToString(mapRenewedContractMoney[keyMapTtoalServer], 2), " / ", mapRenewedContractNum[keyMapTtoalServer]) // "续约合同(金额/数量)-(数据)"
- var renewalRateMoey string
- var renewalRateNum string
- if mapRenewedContractMoney[keyMapTtoalServer] == 0 || mapExpiredContractMoney[keyMapTtoalServer] == 0 {
- renewalRateMoey = "0%"
- } else {
- renewalRateMoey = utils.SubFloatToString(mapRenewedContractMoney[keyMapTtoalServer]/mapExpiredContractMoney[keyMapTtoalServer]*100, 2) + "%"
- }
- if mapRenewedContractNum[keyMapTtoalServer] == 0 || mapExpiredContractCompanyNum[keyMapTtoalServer] == 0 {
- renewalRateNum = "0%"
- } else {
- renewalRateNum = utils.SubFloatToString(float64(mapRenewedContractNum[keyMapTtoalServer])/float64(mapExpiredContractCompanyNum[keyMapTtoalServer])*100, 2) + "%"
- }
- sellerItem.RenewalRateData = fmt.Sprint(renewalRateMoey, " / ", renewalRateNum) //"续约率(金额/数量)-(数据)"
- sellerItem.ConfirmedNoRenewalContractData = fmt.Sprint(utils.SubFloatToString(confirmedNoRenewalContractMoney[keyMapTtoalServer], 2), " / ", confirmedNoRenewalContractNum[keyMapTtoalServer]) //"确认不续约合同(金额/数量)-(数据)"
- var confirmNonRenewalRateMoey string
- var confirmNonRenewalRateNum string
- if confirmedNoRenewalContractMoney[keyMapTtoalServer] == 0 || mapExpiredContractMoney[keyMapTtoalServer] == 0 {
- confirmNonRenewalRateMoey = "0%"
- } else {
- confirmNonRenewalRateMoey = utils.SubFloatToString(confirmedNoRenewalContractMoney[keyMapTtoalServer]/mapExpiredContractMoney[keyMapTtoalServer]*100, 2) + "%"
- }
- if confirmedNoRenewalComapnyNum[keyMapTtoalServer] == 0 || mapExpiredContractCompanyNum[keyMapTtoalServer] == 0 {
- confirmNonRenewalRateNum = "0%"
- } else {
- confirmNonRenewalRateNum = utils.SubFloatToString(float64(confirmedNoRenewalComapnyNum[keyMapTtoalServer])/float64(mapExpiredContractCompanyNum[keyMapTtoalServer])*100, 2) + "%"
- }
- sellerItem.ConfirmNonRenewalRateData = fmt.Sprint(confirmNonRenewalRateMoey, " / ", confirmNonRenewalRateNum) //确认不续约率(金额/数量)-(数据)"
- sellerItem.SignedClientCount = fmt.Sprint(mapSignedClientNum[keyMapTtoalServer]) // 签约客户数量
- if mapSignedClientNum[keyMapTtoalServer] == 0 || mapSignedClientMoney[keyMapTtoalServer] == 0 {
- sellerItem.AverageRevenueCount = "0"
- } else {
- sellerItem.AverageRevenueCount = utils.SubFloatToString(mapSignedClientMoney[keyMapTtoalServer]/float64(mapSignedClientNum[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 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")
- 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
- 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{}
- 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.CompanyName = v.CompanyName
- item.SellerName = v.SellerName
- item.CreateTime = v.CreateTime
- listResp = append(listResp, item)
- }
- }
- case "新签合同":
- if sellerId != "" {
- condition += ` AND a.seller_id_init IN (` + sellerId + `) `
- }
- condition += ` AND a.status = 1 AND a.start_date >= ? AND a.start_date <= ? `
- 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.CompanyName = v.CompanyName
- 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 != "" {
- condition += ` AND a.seller_id_last IN (` + sellerId + `) `
- }
- condition += ` 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.CompanyName = v.CompanyName
- 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 != "" {
- condition += ` AND a.seller_id_last 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 = '续约合同' `
- pars = append(pars, startDate, endDate)
- 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.CompanyName = v.CompanyName
- 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 != "" {
- condition += ` AND a.seller_id_last 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 = '续约合同' `
- pars = append(pars, startDate, endDate)
- listRaiData, err := statistic_report.GetRaiDataSummaryList(condition, pars)
- if err != nil {
- br.Msg = "获取数据信息失败"
- br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
- return
- }
- //fmt.Println("listRaiData", len(listRaiData))
- //到期合同数据
- conditionEnd += ` AND a.status = 1 AND a.end_date >= ? AND a.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 != "" {
- 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.CompanyName = v.CompanyName
- 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 "确认不续约率":
- noRenewedcompanyContractIdsMap := services.GetCompanyContractNoRenewedAscribeListMap()
- var conditionEnd string
- var parsEnd []interface{}
- if sellerId != "" {
- condition += ` AND a.seller_id_last 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.end_date >= ? AND a.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 != "" {
- condition += ` AND a.seller_id_last 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 = '续约合同' "
- parsInherit = append(parsInherit, startDate, endDate)
- 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 "客单价":
- if sellerId != "" {
- condition += ` 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 <= ? "
- 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 {
- ontractMoney += v.Money
- if !mapCompany[v.CompanyId] {
- 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.start_date >= ? AND a.start_date <= ? AND invoiced_amount > 0 AND product_ids LIKE '%2%' "
- pars = append(pars, startDate, endDate)
- listFmsData, err := fms.GetContractRegisterList(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取数据信息失败"
- br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
- return
- }
- if len(listFmsData) > 0 {
- var contractRegisterId []int
- for _, v := range listFmsData {
- contractRegisterId = append(contractRegisterId, v.ContractRegisterId)
- }
- lenArr := len(contractRegisterId)
- var conditionFms string
- var parsFms []interface{}
- conditionFms += ` AND contract_register_id IN (` + utils.GetOrmInReplace(lenArr) + `) GROUP BY contract_register_id `
- parsFms = append(parsFms, contractRegisterId)
- listInvoiceData, err := fms.GetContractInvoiceList(conditionFms, parsFms, 0, lenArr)
- if err != nil {
- br.Msg = "获取数据信息失败"
- br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
- return
- }
- mapInvoiceTime := make(map[int]string)
- for _, v := range listInvoiceData {
- mapInvoiceTime[v.ContractRegisterId] = v.InvoiceTime.Format(utils.FormatDate)
- }
- for _, v := range listFmsData {
- item := new(statistic_report.RaiDataSummaryDetailResp)
- item.CompanyName = v.CompanyName
- item.SellerName = v.RaiSellerName
- item.ContractCode = v.ContractCode
- item.InvoicedAmount = v.InvoicedAmount
- item.CreateTime = mapInvoiceTime[v.ContractRegisterId]
- listResp = append(listResp, item)
- }
- }
- case "到款金额":
- if sellerId != "" {
- condition += ` AND a.rai_seller_id IN (` + sellerId + `) `
- }
- condition += " AND a.is_deleted = 0 AND a.start_date >= ? AND a.start_date <= ? AND payment_amount > 0 AND product_ids LIKE '%2%' "
- pars = append(pars, startDate, endDate)
- listFmsData, err := fms.GetContractRegisterList(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取数据信息失败"
- br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
- return
- }
- if len(listFmsData) > 0 {
- var contractRegisterId []int
- for _, v := range listFmsData {
- contractRegisterId = append(contractRegisterId, v.ContractRegisterId)
- }
- lenArr := len(contractRegisterId)
- var conditionFms string
- var parsFms []interface{}
- conditionFms += ` AND contract_register_id IN (` + utils.GetOrmInReplace(lenArr) + `) GROUP BY contract_register_id `
- parsFms = append(parsFms, contractRegisterId)
- listInvoiceData, err := fms.GetContractInvoiceList(conditionFms, parsFms, 0, lenArr)
- if err != nil {
- br.Msg = "获取数据信息失败"
- br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
- return
- }
- mapInvoiceTime := make(map[int]string)
- for _, v := range listInvoiceData {
- mapInvoiceTime[v.ContractRegisterId] = v.InvoiceTime.Format(utils.FormatDate)
- }
- for _, v := range listFmsData {
- item := new(statistic_report.RaiDataSummaryDetailResp)
- item.CompanyName = v.CompanyName
- item.SellerName = v.RaiSellerName
- item.ContractCode = v.ContractCode
- item.PaymentAmount = v.PaymentAmount
- item.CreateTime = v.CreateTime.Format(utils.FormatDate)
- listResp = append(listResp, item)
- }
- }
- case "未到款比例":
- if sellerId != "" {
- condition += ` AND a.rai_seller_id IN (` + sellerId + `) `
- }
- condition += " AND a.is_deleted = 0 AND a.start_date >= ? AND a.start_date <= ? AND product_ids LIKE '%2%' "
- pars = append(pars, startDate, endDate)
- listFmsData, err := fms.GetContractRegisterAmountList(condition, pars)
- if err != nil {
- br.Msg = "获取数据信息失败"
- br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
- return
- }
- for _, v := range listFmsData {
- item := new(statistic_report.RaiDataSummaryDetailResp)
- item.InvoicedAmount = v.InvoicedAmount
- item.PaymentAmount = v.PaymentAmount
- item.NotReceivedtAmount = v.InvoicedAmount - v.PaymentAmount
- item.CreateTime = v.CreateTime.Format(utils.FormatDate)
- listResp = append(listResp, item)
- }
- case "新客开票":
- if sellerId != "" {
- condition += ` AND a.rai_seller_id IN (` + sellerId + `) `
- }
- condition += " AND a.is_deleted = 0 AND contract_type = 1 AND a.start_date >= ? AND a.start_date <= ? AND product_ids LIKE '%2%' "
- pars = append(pars, startDate, endDate)
- listFmsData, err := fms.GetContractRegisterList(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取数据信息失败"
- br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
- return
- }
- if len(listFmsData) > 0 {
- var contractRegisterId []int
- for _, v := range listFmsData {
- contractRegisterId = append(contractRegisterId, v.ContractRegisterId)
- }
- lenArr := len(contractRegisterId)
- var conditionFms string
- var parsFms []interface{}
- conditionFms += ` AND contract_register_id IN (` + utils.GetOrmInReplace(lenArr) + `) GROUP BY contract_register_id `
- parsFms = append(parsFms, contractRegisterId)
- listInvoiceData, err := fms.GetContractInvoiceList(conditionFms, parsFms, 0, lenArr)
- if err != nil {
- br.Msg = "获取数据信息失败"
- br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
- return
- }
- mapInvoiceTime := make(map[int]string)
- for _, v := range listInvoiceData {
- mapInvoiceTime[v.ContractRegisterId] = v.InvoiceTime.Format(utils.FormatDate)
- }
- for _, v := range listFmsData {
- item := new(statistic_report.RaiDataSummaryDetailResp)
- item.CompanyName = v.CompanyName
- item.SellerName = v.RaiSellerName
- item.ContractCode = v.ContractCode
- item.InvoicedAmount = v.InvoicedAmount
- item.CreateTime = mapInvoiceTime[v.ContractRegisterId]
- listResp = append(listResp, item)
- }
- }
- case "新客到款":
- if sellerId != "" {
- condition += ` AND a.rai_seller_id IN (` + sellerId + `) `
- }
- condition += " AND a.is_deleted = 0 AND contract_type = 1 AND a.start_date >= ? AND a.start_date <= ? AND payment_amount > 0 AND product_ids LIKE '%2%' "
- pars = append(pars, startDate, endDate)
- listFmsData, err := fms.GetContractRegisterList(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取数据信息失败"
- br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
- return
- }
- if len(listFmsData) > 0 {
- var contractRegisterId []int
- for _, v := range listFmsData {
- contractRegisterId = append(contractRegisterId, v.ContractRegisterId)
- }
- lenArr := len(contractRegisterId)
- var conditionFms string
- var parsFms []interface{}
- conditionFms += ` AND contract_register_id IN (` + utils.GetOrmInReplace(lenArr) + `) GROUP BY contract_register_id `
- parsFms = append(parsFms, contractRegisterId)
- listInvoiceData, err := fms.GetContractInvoiceList(conditionFms, parsFms, 0, lenArr)
- if err != nil {
- br.Msg = "获取数据信息失败"
- br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
- return
- }
- mapInvoiceTime := make(map[int]string)
- for _, v := range listInvoiceData {
- mapInvoiceTime[v.ContractRegisterId] = v.InvoiceTime.Format(utils.FormatDate)
- }
- for _, v := range listFmsData {
- item := new(statistic_report.RaiDataSummaryDetailResp)
- item.CompanyName = v.CompanyName
- item.SellerName = v.RaiSellerName
- item.ContractCode = v.ContractCode
- item.PaymentAmount = v.PaymentAmount
- item.CreateTime = mapInvoiceTime[v.ContractRegisterId]
- 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
- }
|