rai_data_summary.go 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768
  1. package statistic
  2. import (
  3. "fmt"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hz_crm_api/controllers"
  6. "hongze/hz_crm_api/models"
  7. "hongze/hz_crm_api/models/company"
  8. "hongze/hz_crm_api/models/fms"
  9. "hongze/hz_crm_api/models/statistic_report"
  10. "hongze/hz_crm_api/models/system"
  11. "hongze/hz_crm_api/services"
  12. cygxService "hongze/hz_crm_api/services/cygx"
  13. "hongze/hz_crm_api/utils"
  14. "strconv"
  15. "strings"
  16. "time"
  17. )
  18. // 权益数据汇总
  19. // StatisticRaiDataSummaryController 权益数据汇总基类
  20. type StatisticRaiDataSummaryController struct {
  21. controllers.BaseAuthController
  22. }
  23. // MergeCompanyList
  24. // @Title 权益数据汇总
  25. // @Description 权益数据汇总统计列表接口
  26. // @Param AdminId query string true "开拓组销售id,多个用英文逗号隔开,空字符串为全部"
  27. // @Param ServiceAdminId query string true "服务组销售id,多个用英文逗号隔开,空字符串为全部"
  28. // @Param StartYear query int false "开始日期(年份)"
  29. // @Param EndYear query int false "结束日期(年份)"
  30. // @Param DataType query string false "报表类型,枚举值:`季度`,`年度`,`半年度`"
  31. // @Param DevelopButton query int false "开拓组开关,枚举值:1:开启,0:关闭 ,默认关闭"
  32. // @Param ServerButton query int false "服务组开关,枚举值:1:开启,0:关闭 ,默认关闭"
  33. // @Param ContractButtonType query string false "开关类型,:`新签`,`续约`,`收入` 多个用英文逗号隔开, "
  34. // @Param IsExport query bool false "是否导出excel,默认是false"
  35. // @Success 200 {object} statistic_report.RaiDataSummaryListResp
  36. // @router /rai_data_summary/list [get]
  37. func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
  38. br := new(models.BaseResponse).Init()
  39. defer func() {
  40. this.Data["json"] = br
  41. this.ServeJSON()
  42. }()
  43. sysUser := this.SysUser
  44. if sysUser == nil {
  45. br.Msg = "请登录"
  46. br.ErrMsg = "请登录,SysUser Is Empty"
  47. br.Ret = 408
  48. return
  49. }
  50. dataType := this.GetString("DataType")
  51. adminId := this.GetString("AdminId")
  52. serviceAdminId := this.GetString("ServiceAdminId")
  53. startYear, _ := this.GetInt("StartYear")
  54. endYear, _ := this.GetInt("EndYear")
  55. developButton, _ := this.GetBool("DevelopButton")
  56. serverButton, _ := this.GetBool("ServerButton")
  57. adminIdArr := strings.Split(adminId, ",")
  58. serviceAdminIdArr := strings.Split(serviceAdminId, ",")
  59. if adminId == "" {
  60. adminIdArr = make([]string, 0)
  61. }
  62. if serviceAdminId == "" {
  63. serviceAdminIdArr = make([]string, 0)
  64. }
  65. dataTypeArr := []string{}
  66. if dataType == "季度" {
  67. dataTypeArr = []string{"Q1", "Q2", "Q3", "Q4"}
  68. } else if dataType == "半年度" {
  69. dataTypeArr = []string{"H1", "H2"}
  70. } else {
  71. dataTypeArr = []string{""}
  72. }
  73. var condition string
  74. var pars []interface{}
  75. mapsellerDevelop := make(map[int]bool) // 开拓组销售Map
  76. mapsellerService := make(map[int]bool) // 服务组销售Map
  77. var sellerIds []string
  78. var sellerServiceIds []string
  79. condition = " AND role_type_code IN ('rai_seller','rai_group') "
  80. sellerListAll, err := system.GetSysUserItemsOrderByCreated(condition, pars)
  81. if err != nil {
  82. br.Msg = "获取管理账号失败"
  83. br.ErrMsg = "获取管理账号失败,Err:" + err.Error()
  84. return
  85. }
  86. for _, v := range sellerListAll {
  87. if strings.Contains(v.RealName, "6") {
  88. mapsellerService[v.AdminId] = true
  89. sellerServiceIds = append(sellerServiceIds, strconv.Itoa(v.AdminId))
  90. } else {
  91. mapsellerDevelop[v.AdminId] = true
  92. sellerIds = append(sellerIds, strconv.Itoa(v.AdminId))
  93. }
  94. }
  95. condition = " AND role_type_code IN ('rai_seller','rai_group') AND enabled = 1 AND rai_enabled = 1 "
  96. if adminId != "" {
  97. serviceAdminId = ""
  98. condition += " AND admin_id IN (" + adminId + ") "
  99. sellerIds = make([]string, 0)
  100. }
  101. if serviceAdminId != "" {
  102. condition += " AND admin_id IN (" + serviceAdminId + ") "
  103. sellerServiceIds = make([]string, 0)
  104. }
  105. if developButton && !serverButton && adminId == "" && serviceAdminId == "" { //开拓组筛选条件
  106. condition += " AND real_name NOT LIKE '%6%' "
  107. }
  108. if !developButton && serverButton && adminId == "" && serviceAdminId == "" { //服务组筛选条件
  109. condition += " AND real_name LIKE '%6%' "
  110. }
  111. sellerList, err := system.GetSysUserItemsOrderByCreated(condition, pars)
  112. if err != nil {
  113. br.Msg = "获取管理账号失败"
  114. br.ErrMsg = "获取管理账号失败,Err:" + err.Error()
  115. return
  116. }
  117. var sellerDevelop []*system.AdminItem // 开拓组销售
  118. var sellerService []*system.AdminItem // 服务组销售
  119. var sellerDevelopIds = make(map[int]bool) // 开拓组销售的map
  120. mapsellerId := make(map[int]bool) // 权益销售map
  121. for _, v := range sellerList {
  122. if strings.Contains(v.RealName, "6") {
  123. sellerService = append(sellerService, v)
  124. } else {
  125. sellerDevelop = append(sellerDevelop, v)
  126. sellerDevelopIds[v.AdminId] = true
  127. }
  128. mapsellerId[v.AdminId] = true
  129. }
  130. //拼接起始时间查询
  131. startDate := fmt.Sprintf("%d-01-01", startYear)
  132. endDate := fmt.Sprintf("%d-12-31", endYear)
  133. //新签部分的数据
  134. var conditionRai string
  135. var parsRai []interface{}
  136. conditionRai = " AND a.product_id = 2 AND a.status = 1 AND a.start_date >= ? AND a.start_date <= ? AND a.rai_contract_type = '新签合同' "
  137. parsRai = append(parsRai, startDate, endDate)
  138. listRaiData, err := statistic_report.GetRaiDataSummaryList(conditionRai, parsRai)
  139. if err != nil {
  140. br.Msg = "获取数据信息失败"
  141. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  142. return
  143. }
  144. var companyContractIds []int
  145. for _, v := range listRaiData {
  146. companyContractIds = append(companyContractIds, v.CompanyId)
  147. }
  148. companyContractIds = append(companyContractIds, 0)
  149. //续约部分的数据
  150. var conditionInherit string
  151. var parsInherit []interface{}
  152. 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)) + `) `
  153. parsInherit = append(parsInherit, startDate, endDate, companyContractIds)
  154. listInheritData, err := statistic_report.GetRaiDataSummaryInheritList(conditionInherit, parsInherit)
  155. if err != nil {
  156. br.Msg = "获取数据信息失败"
  157. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  158. return
  159. }
  160. //确认不续约、到期合同部分的数据
  161. var conditionEnd string
  162. var parsEnd []interface{}
  163. conditionEnd = " AND a.product_id = 2 AND a.status = 1 AND a.end_date >= ? AND a.end_date <= ? AND a.end_date < ? "
  164. parsEnd = append(parsEnd, startDate, endDate, time.Now().Format(utils.FormatDate))
  165. listEndData, err := statistic_report.GetRaiDataSummaryList(conditionEnd, parsEnd)
  166. if err != nil {
  167. br.Msg = "获取数据信息失败"
  168. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  169. return
  170. }
  171. var conditionConfirm string
  172. var parsConfirm []interface{}
  173. mapNoRenewedcompanyContractIds := make(map[int]bool) //已经确定未续约的合同ID
  174. conditionConfirm = " AND company_ascribe_id != 9 "
  175. companyConfirmList, err := company.GetCompanyContractNoRenewedAscribeList(conditionConfirm, parsConfirm, 0, 0)
  176. if err != nil && err.Error() != utils.ErrNoRow() {
  177. br.Msg = "获取失败"
  178. br.ErrMsg = "获取失败,GetCompanyNoRenewedAscribeList Err:" + err.Error()
  179. return
  180. }
  181. for _, v := range companyConfirmList {
  182. mapNoRenewedcompanyContractIds[v.CompanyContractId] = true
  183. }
  184. mapAddTrialNum := make(map[string]float64) // 新增试用-(数据)
  185. mapNewContractMoney := make(map[string]float64) // 新签合同(金额)
  186. mapNewContractNum := make(map[string]int) // 新签合同(数量)
  187. mapExpiredContractMoney := make(map[string]float64) // 到期合同(金额)
  188. mapExpiredContractNum := make(map[string]int) // 到期合同(数量)
  189. mapExpiredContractCompanyNum := make(map[string]int) // 到期公司(数量)
  190. mapRenewedContractMoney := make(map[string]float64) // 续约合同(金额)
  191. mapRenewedContractNum := make(map[string]int) // 续约合同(数量)
  192. mapRenewedContractCompanyNum := make(map[string]int) // 续约公司(数量)
  193. confirmedNoRenewalContractMoney := make(map[string]float64) // 确认不续约合同(金额)
  194. confirmedNoRenewalContractNum := make(map[string]int) // 确认不续约合同(数量)
  195. confirmedNoRenewalContractCompanyNum := make(map[string]int) // 确认不续约公司(数量)
  196. mapSignedClientNum := make(map[string]int) // 签约客户(数量)
  197. mapSignedClientMoney := make(map[string]float64) // 签约客户(金额)
  198. mapInvoiceAmountMoney := make(map[string]float64) // 财务系统开票金额(金额)
  199. mapPaymentAmountMoney := make(map[string]float64) // 财务系统到款金额(金额)
  200. mapNewCustomerInvoicingMoney := make(map[string]float64) // 财务系统新客开票金额(金额)
  201. mapNewCustomerPaymentsReceivedMoney := make(map[string]float64) // 财务系统新客到款金额(金额)
  202. mapNewContractMoneyServer := make(map[string]float64) // 新签合同(金额)
  203. mapNewContractNumServer := make(map[string]int) // 新签合同(数量)
  204. mapExpiredContractMoneyServer := make(map[string]float64) // 到期合同(金额)
  205. mapExpiredContractNumServer := make(map[string]int) // 到期合同(数量)_服务组
  206. mapExpiredContractCompanyNumServer := make(map[string]int) // 到期公司(数量)_服务组
  207. mapRenewedContractMoneyServer := make(map[string]float64) // 续约合同(金额)_服务组
  208. mapRenewedContractNumServer := make(map[string]int) // 续约合同(数量)_服务组
  209. mapRenewedContractCompanyNumServer := make(map[string]int) // 续约公司(数量)_服务组
  210. confirmedNoRenewalContractMoneyServer := make(map[string]float64) // 确认不续约合同(金额)_服务组
  211. confirmedNoRenewalContractNumServer := make(map[string]int) // 确认不续约合同(数量)_服务组
  212. confirmedNoRenewalContractCompanyNumServer := make(map[string]int) // 确认不续约公司(数量)_服务组
  213. mapSignedClientNumServer := make(map[string]int) // 签约客户(数量)
  214. mapSignedClientMoneyServer := make(map[string]float64) // 签约客户(金额)
  215. var keyMap string
  216. var keyMapTtoal string
  217. var keyMapTtoalServer string
  218. var keyMapCompany string
  219. var keyMapCompanyNo string
  220. //var keyMapCompanyNoServer string
  221. var keySigned string
  222. mapCompanyData := make(map[string]bool)
  223. //新签部分的数据(开拓组)
  224. for _, v := range listRaiData {
  225. if !mapsellerDevelop[v.SellerIdInit] {
  226. continue
  227. }
  228. yearStr := getYearStar(utils.StrDateToDate(v.StartDate), dataType)
  229. keyMap = fmt.Sprint(yearStr, "_", v.SellerIdLast)
  230. keySigned = fmt.Sprint(yearStr, "_CID_", v.CompanyId, "_SID_", v.SellerIdLast)
  231. keyMapTtoal = fmt.Sprint(yearStr, "_Develop")
  232. if v.RaiContractType == "新签合同" {
  233. mapNewContractMoney[keyMap] += v.Money
  234. mapNewContractNum[keyMap]++
  235. mapNewContractMoney[keyMapTtoal] += v.Money
  236. mapNewContractNum[keyMapTtoal]++
  237. }
  238. mapSignedClientMoney[keyMap] += v.Money
  239. mapSignedClientMoney[keyMapTtoal] += v.Money
  240. if !mapCompanyData[keySigned] && v.RaiContractType == "新签合同" {
  241. mapSignedClientNum[keyMap]++
  242. mapSignedClientNum[keyMapTtoal]++
  243. mapCompanyData[keySigned] = true
  244. }
  245. }
  246. //新签部分的数据(服务组)
  247. for _, v := range listRaiData {
  248. if !mapsellerDevelop[v.ShareSellerInit] {
  249. continue
  250. }
  251. yearStr := getYearStar(utils.StrDateToDate(v.StartDate), dataType)
  252. keyMap = fmt.Sprint(yearStr, "_Server_", v.ShareSellerInit)
  253. keySigned = fmt.Sprint(yearStr, "_Server_", v.CompanyId, "_SID_", v.ShareSellerInit)
  254. keyMapTtoal = fmt.Sprint(yearStr, "_Server_")
  255. if v.RaiContractType == "新签合同" {
  256. mapNewContractMoneyServer[keyMap] += v.Money
  257. mapNewContractNumServer[keyMap]++
  258. mapNewContractMoneyServer[keyMapTtoal] += v.Money
  259. mapNewContractNumServer[keyMapTtoal]++
  260. }
  261. mapSignedClientMoneyServer[keyMap] += v.Money
  262. mapSignedClientMoneyServer[keyMapTtoal] += v.Money
  263. if !mapCompanyData[keySigned] && v.RaiContractType == "新签合同" {
  264. mapSignedClientNumServer[keyMap]++
  265. mapSignedClientNumServer[keyMapTtoal]++
  266. mapCompanyData[keySigned] = true
  267. }
  268. }
  269. //续约部分的数据(开拓组)
  270. mapKeyMapCompanyData := make(map[string]bool)
  271. for _, v := range listInheritData {
  272. if len(adminIdArr) > 0 && !utils.InArrayByStr(adminIdArr, strconv.Itoa(v.SellerIdLast)) {
  273. continue
  274. }
  275. if !mapsellerDevelop[v.SellerIdLast] {
  276. continue
  277. }
  278. yearStr := getYearStar(utils.StrDateToDate(v.InheritEndDate), dataType)
  279. keyMap = fmt.Sprint(yearStr, "_", v.SellerIdLast)
  280. keyMapCompany = fmt.Sprint(yearStr, "_", v.SellerIdLast, "_CID_", v.CompanyId)
  281. keySigned = fmt.Sprint(yearStr, "_CID_", v.CompanyId, "_SID_", v.SellerIdLast)
  282. keyMapTtoal = fmt.Sprint(yearStr, "_Develop")
  283. //续约合同 数据
  284. mapRenewedContractMoney[keyMap] += v.Money
  285. mapRenewedContractMoney[keyMapTtoal] += v.Money
  286. mapRenewedContractNum[keyMap]++
  287. mapRenewedContractNum[keyMapTtoal]++
  288. //续约公司 数据
  289. if !mapKeyMapCompanyData[keyMapCompany] {
  290. mapRenewedContractCompanyNum[keyMap]++
  291. mapRenewedContractCompanyNum[keyMapTtoal]++
  292. mapKeyMapCompanyData[keyMapCompany] = true
  293. }
  294. //签约合同 数据
  295. mapSignedClientMoney[keyMap] += v.Money
  296. mapSignedClientMoney[keyMapTtoal] += v.Money
  297. if !mapCompanyData[keySigned] {
  298. mapSignedClientNum[keyMap]++
  299. mapSignedClientNum[keyMapTtoal]++
  300. mapCompanyData[keySigned] = true
  301. }
  302. }
  303. //续约部分的数据(服务组)
  304. for _, v := range listInheritData {
  305. if len(serviceAdminIdArr) > 0 && !utils.InArrayByStr(serviceAdminIdArr, strconv.Itoa(v.ShareSellerIdLast)) {
  306. continue
  307. }
  308. if !mapsellerService[v.ShareSellerIdLast] {
  309. continue
  310. }
  311. yearStr := getYearStar(utils.StrDateToDate(v.InheritEndDate), dataType)
  312. keyMap = fmt.Sprint(yearStr, "_Server_", v.ShareSellerIdLast)
  313. keyMapCompany = fmt.Sprint(yearStr, "_Server_", v.ShareSellerIdLast, "_CID_", v.CompanyId)
  314. keySigned = fmt.Sprint(yearStr, "_Server_", v.CompanyId, "_SID_", v.ShareSellerIdLast)
  315. keyMapTtoal = fmt.Sprint(yearStr, "_Server_")
  316. //续约合同 数据
  317. mapRenewedContractMoneyServer[keyMap] += v.Money
  318. mapRenewedContractMoneyServer[keyMapTtoal] += v.Money
  319. mapRenewedContractNumServer[keyMap]++
  320. mapRenewedContractNumServer[keyMapTtoal]++
  321. //续约公司 数据
  322. if !mapKeyMapCompanyData[keyMapCompany] {
  323. mapRenewedContractCompanyNumServer[keyMap]++
  324. mapRenewedContractCompanyNumServer[keyMapTtoal]++
  325. mapKeyMapCompanyData[keyMapCompany] = true
  326. }
  327. ////签约合同 数据
  328. mapSignedClientMoneyServer[keyMap] += v.Money
  329. mapSignedClientMoneyServer[keyMapTtoal] += v.Money
  330. //if !mapCompanyData[keySigned] {
  331. // mapSignedClientNum[keyMap]++
  332. // mapSignedClientNum[keyMapTtoal]++
  333. // mapCompanyData[keySigned] = true
  334. //}
  335. }
  336. //确认不续约、到期合同部分的数据
  337. mapKeyMapCompanyEndData := make(map[string]bool)
  338. mapKeyMapCompanyNoData := make(map[string]bool)
  339. //到期部分开拓组数据
  340. for _, v := range listEndData {
  341. if len(adminIdArr) > 0 && !utils.InArrayByStr(adminIdArr, strconv.Itoa(v.SellerIdLast)) {
  342. continue
  343. }
  344. if !mapsellerDevelop[v.SellerIdLast] {
  345. continue
  346. }
  347. yearStr := getYearStar(utils.StrDateToDate(v.EndDate), dataType)
  348. keyMap = fmt.Sprint(yearStr, "_", v.SellerIdLast)
  349. keyMapCompany = fmt.Sprint(yearStr, "_", v.SellerIdLast, "_CID_", v.CompanyId)
  350. keyMapCompanyNo = fmt.Sprint(yearStr, "_", v.SellerIdLast, "_CID_NO", v.CompanyId)
  351. keyMapTtoal = fmt.Sprint(yearStr, "_Develop")
  352. //到期合同数据
  353. mapExpiredContractMoney[keyMap] += v.Money
  354. mapExpiredContractMoney[keyMapTtoal] += v.Money
  355. //一家公司同一个时间纬度,只统计一次
  356. mapExpiredContractNum[keyMap]++
  357. mapExpiredContractNum[keyMapTtoal]++
  358. //一家公司同一个时间纬度,只统计一次
  359. if !mapKeyMapCompanyEndData[keyMapCompany] {
  360. mapExpiredContractCompanyNum[keyMap]++
  361. mapExpiredContractCompanyNum[keyMapTtoal]++
  362. mapKeyMapCompanyEndData[keyMapCompany] = true
  363. }
  364. if mapNoRenewedcompanyContractIds[v.CompanyContractId] { // 确认不续约合同
  365. confirmedNoRenewalContractMoney[keyMap] += v.Money
  366. confirmedNoRenewalContractMoney[keyMapTtoal] += v.Money
  367. //一家公司同一个时间纬度,只统计一次
  368. confirmedNoRenewalContractNum[keyMap]++
  369. confirmedNoRenewalContractNum[keyMapTtoal]++
  370. if !mapKeyMapCompanyNoData[keyMapCompanyNo] {
  371. confirmedNoRenewalContractCompanyNum[keyMap]++
  372. confirmedNoRenewalContractCompanyNum[keyMapTtoal]++
  373. mapKeyMapCompanyNoData[keyMapCompanyNo] = true
  374. }
  375. }
  376. }
  377. //到期部分服务组数据
  378. for _, v := range listEndData {
  379. if len(serviceAdminIdArr) > 0 && !utils.InArrayByStr(serviceAdminIdArr, strconv.Itoa(v.ShareSellerIdLast)) {
  380. continue
  381. }
  382. if !mapsellerService[v.ShareSellerIdLast] {
  383. continue
  384. }
  385. yearStr := getYearStar(utils.StrDateToDate(v.EndDate), dataType)
  386. keyMap = fmt.Sprint(yearStr, "_Server_", v.ShareSellerIdLast)
  387. keyMapCompany = fmt.Sprint(yearStr, "_Server_", v.ShareSellerIdLast, "_CID_", v.CompanyId)
  388. keyMapCompanyNo = fmt.Sprint(yearStr, "_Server_", v.ShareSellerIdLast, "_CID_NO", v.CompanyId)
  389. keyMapTtoal = fmt.Sprint(yearStr, "_Server_")
  390. //到期合同数据
  391. mapExpiredContractMoneyServer[keyMap] += v.Money
  392. mapExpiredContractMoneyServer[keyMapTtoal] += v.Money
  393. mapExpiredContractNumServer[keyMap]++
  394. mapExpiredContractNumServer[keyMapTtoal]++
  395. //一家公司同一个时间纬度,只统计一次
  396. if !mapKeyMapCompanyEndData[keyMapCompany] {
  397. mapExpiredContractCompanyNumServer[keyMap]++
  398. mapExpiredContractCompanyNumServer[keyMapTtoal]++
  399. mapKeyMapCompanyEndData[keyMapCompany] = true
  400. }
  401. if mapNoRenewedcompanyContractIds[v.CompanyContractId] { // 确认不续约合同
  402. confirmedNoRenewalContractMoneyServer[keyMap] += v.Money
  403. confirmedNoRenewalContractMoneyServer[keyMapTtoal] += v.Money
  404. //一家公司同一个时间纬度,只统计一次
  405. confirmedNoRenewalContractNumServer[keyMap]++
  406. confirmedNoRenewalContractNumServer[keyMapTtoal]++
  407. if !mapKeyMapCompanyNoData[keyMapCompanyNo] {
  408. confirmedNoRenewalContractCompanyNumServer[keyMap]++
  409. confirmedNoRenewalContractCompanyNumServer[keyMapTtoal]++
  410. mapKeyMapCompanyNoData[keyMapCompanyNo] = true
  411. }
  412. }
  413. }
  414. listFmsData, err := fms.GetContractRegisterListByStartDate(startDate, endDate)
  415. if err != nil {
  416. br.Msg = "获取数据信息失败"
  417. br.ErrMsg = "获取财务系统数据信息失败,Err:" + err.Error()
  418. return
  419. }
  420. //开拓组财务系统数据
  421. for _, v := range listFmsData {
  422. if len(adminIdArr) > 0 && !utils.InArrayByStr(adminIdArr, strconv.Itoa(v.RaiSellerId)) {
  423. continue
  424. }
  425. //if !mapsellerDevelop[v.RaiSellerId] {
  426. // continue
  427. //}
  428. yearStr := getYearStar(v.StartDate, dataType)
  429. keyMap = fmt.Sprint(yearStr, "_", v.RaiSellerId)
  430. keyMapTtoal = fmt.Sprint(yearStr, "_Develop")
  431. mapInvoiceAmountMoney[keyMap] += v.InvoicedAmount
  432. mapPaymentAmountMoney[keyMap] += v.PaymentAmount
  433. mapInvoiceAmountMoney[keyMapTtoal] += v.InvoicedAmount
  434. mapPaymentAmountMoney[keyMapTtoal] += v.PaymentAmount
  435. if v.ContractType == 1 {
  436. mapNewCustomerInvoicingMoney[keyMap] += v.InvoicedAmount
  437. mapNewCustomerPaymentsReceivedMoney[keyMap] += v.PaymentAmount
  438. mapNewCustomerInvoicingMoney[keyMapTtoal] += v.InvoicedAmount
  439. mapNewCustomerPaymentsReceivedMoney[keyMapTtoal] += v.PaymentAmount
  440. }
  441. }
  442. //服务组财务系统数据
  443. for _, v := range listFmsData {
  444. if len(serviceAdminIdArr) > 0 && !utils.InArrayByStr(serviceAdminIdArr, strconv.Itoa(v.RaiSellerId)) {
  445. continue
  446. }
  447. if !mapsellerService[v.RaiSellerId] {
  448. continue
  449. }
  450. yearStr := getYearStar(v.StartDate, dataType)
  451. keyMap = fmt.Sprint(yearStr, "_", v.RaiSellerId)
  452. keyMapTtoal = fmt.Sprint(yearStr, "_Server_")
  453. mapInvoiceAmountMoney[keyMap] += v.InvoicedAmount
  454. mapPaymentAmountMoney[keyMap] += v.PaymentAmount
  455. mapInvoiceAmountMoney[keyMapTtoal] += v.InvoicedAmount
  456. mapPaymentAmountMoney[keyMapTtoal] += v.PaymentAmount
  457. if v.ContractType == 1 {
  458. mapNewCustomerInvoicingMoney[keyMap] += v.InvoicedAmount
  459. mapNewCustomerPaymentsReceivedMoney[keyMap] += v.PaymentAmount
  460. mapNewCustomerInvoicingMoney[keyMapTtoal] += v.InvoicedAmount
  461. mapNewCustomerPaymentsReceivedMoney[keyMapTtoal] += v.PaymentAmount
  462. }
  463. }
  464. 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') ) `
  465. var parsTry []interface{}
  466. parsTry = append(parsTry, startDate, endDate)
  467. //列表页数据
  468. tryList, err := models.GetIncrementalCompanyListByOperationRecordRai(conditionTry, parsTry, 0, 9999)
  469. if err != nil {
  470. br.Msg = "获取失败"
  471. br.ErrMsg = "获取失败,Err:" + err.Error()
  472. return
  473. }
  474. for _, v := range tryList {
  475. startDateTime := utils.StrTimeToTime(v.CreateTime)
  476. monthNum := startDateTime.Month()
  477. yearStr := strconv.Itoa(startDateTime.Year())
  478. if dataType == "季度" {
  479. if monthNum < 4 {
  480. yearStr += "Q1"
  481. } else if monthNum > 3 && monthNum < 7 {
  482. yearStr += "Q2"
  483. } else if monthNum > 6 && monthNum < 10 {
  484. yearStr += "Q3"
  485. } else if monthNum > 9 {
  486. yearStr += "Q4"
  487. }
  488. } else if dataType == "半年度" {
  489. if monthNum < 7 {
  490. yearStr += "H1"
  491. } else {
  492. yearStr += "H2"
  493. }
  494. }
  495. keyMap = fmt.Sprint(yearStr, "_", v.SysUserId)
  496. mapAddTrialNum[keyMap]++
  497. //var keyMapTtoal string
  498. sysUserId, _ := strconv.Atoi(v.SysUserId)
  499. if sellerDevelopIds[sysUserId] == true {
  500. keyMapTtoal = fmt.Sprint(yearStr, "_Develop")
  501. } else {
  502. keyMapTtoal = fmt.Sprint(yearStr, "_Server_")
  503. }
  504. mapAddTrialNum[keyMapTtoal]++
  505. }
  506. resp := new(statistic_report.RaiDataSummaryListResp)
  507. var items []*statistic_report.RaiDataSummaryResp
  508. for i := startYear; i <= endYear; i++ {
  509. //if len(dataTypeArr) > 0 {
  510. for _, Dv := range dataTypeArr {
  511. item := new(statistic_report.RaiDataSummaryResp)
  512. item.DataType = fmt.Sprint(i, Dv)
  513. keyMapTtoal = fmt.Sprint(item.DataType, "_Develop")
  514. keyMapTtoalServer = fmt.Sprint(item.DataType, "_Server_")
  515. for _, vS := range sellerDevelop {
  516. keyMap = fmt.Sprint(item.DataType, "_", vS.AdminId)
  517. sellerItem := new(statistic_report.RaiDataSummaryDetail)
  518. sellerItem.SellerId = strconv.Itoa(vS.AdminId)
  519. sellerIds = append(sellerIds, sellerItem.SellerId)
  520. sellerItem.SellerName = vS.RealName
  521. sellerItem.AddTrialCount = fmt.Sprint(mapAddTrialNum[keyMap])
  522. sellerItem.NewContractData = fmt.Sprint(utils.SubFloatToString(mapNewContractMoney[keyMap], 2), " / ", mapNewContractNum[keyMap]) // 新签合同(金额/数量)-(数据)
  523. sellerItem.ExpiredContractData = fmt.Sprint(utils.SubFloatToString(mapExpiredContractMoney[keyMap], 2), " / ", mapExpiredContractNum[keyMap]) //"到期合同(金额/数量)-(数据)"
  524. sellerItem.RenewedContractData = fmt.Sprint(utils.SubFloatToString(mapRenewedContractMoney[keyMap], 2), " / ", mapRenewedContractNum[keyMap]) // "续约合同(金额/数量)-(数据)"
  525. var renewalRateMoey string
  526. var renewalRateNum string
  527. if mapRenewedContractMoney[keyMap] == 0 || mapExpiredContractMoney[keyMap] == 0 {
  528. renewalRateMoey = "0%"
  529. } else {
  530. renewalRateMoey = utils.SubFloatToString(mapRenewedContractMoney[keyMap]/mapExpiredContractMoney[keyMap]*100, 2) + "%"
  531. }
  532. if mapRenewedContractCompanyNum[keyMap] == 0 || mapExpiredContractCompanyNum[keyMap] == 0 {
  533. renewalRateNum = "0%"
  534. } else {
  535. renewalRateNum = utils.SubFloatToString(float64(mapRenewedContractCompanyNum[keyMap])/float64(mapExpiredContractCompanyNum[keyMap])*100, 2) + "%"
  536. }
  537. sellerItem.RenewalRateData = fmt.Sprint(renewalRateMoey, " / ", renewalRateNum) //"续约率(金额/数量)-(数据)"
  538. sellerItem.ConfirmedNoRenewalContractData = fmt.Sprint(utils.SubFloatToString(confirmedNoRenewalContractMoney[keyMap], 2), " / ", confirmedNoRenewalContractNum[keyMap]) //"确认不续约合同(金额/数量)-(数据)"
  539. var confirmNonRenewalRateMoey string
  540. var confirmNonRenewalRateNum string
  541. if confirmedNoRenewalContractMoney[keyMap] == 0 || mapExpiredContractMoney[keyMap] == 0 {
  542. confirmNonRenewalRateMoey = "0%"
  543. } else {
  544. confirmNonRenewalRateMoey = utils.SubFloatToString(confirmedNoRenewalContractMoney[keyMap]/mapExpiredContractMoney[keyMap]*100, 2) + "%"
  545. }
  546. if confirmedNoRenewalContractCompanyNum[keyMap] == 0 || mapExpiredContractCompanyNum[keyMap] == 0 {
  547. confirmNonRenewalRateNum = "0%"
  548. } else {
  549. confirmNonRenewalRateNum = utils.SubFloatToString(float64(confirmedNoRenewalContractCompanyNum[keyMap])/float64(mapExpiredContractCompanyNum[keyMap])*100, 2) + "%"
  550. }
  551. sellerItem.ConfirmNonRenewalRateData = fmt.Sprint(confirmNonRenewalRateMoey, " / ", confirmNonRenewalRateNum) //确认不续约率(金额/数量)-(数据)"
  552. sellerItem.SignedClientCount = fmt.Sprint(mapSignedClientNum[keyMap]) // 签约客户数量
  553. if mapSignedClientNum[keyMap] == 0 || mapSignedClientMoney[keyMap] == 0 {
  554. sellerItem.AverageRevenueCount = "0"
  555. } else {
  556. sellerItem.AverageRevenueCount = utils.SubFloatToString(mapSignedClientMoney[keyMap]/float64(mapSignedClientNum[keyMap]), 2) //客单价
  557. }
  558. sellerItem.InvoiceAmountCount = utils.SubFloatToString(mapInvoiceAmountMoney[keyMap], 2) //"开票金额-(数据)"
  559. sellerItem.PaymentReceivedCount = utils.SubFloatToString(mapPaymentAmountMoney[keyMap], 2) //"开票金额-(数据)"
  560. if mapInvoiceAmountMoney[keyMap] == 0 || mapPaymentAmountMoney[keyMap] == 0 {
  561. sellerItem.UnpaidRatioCount = "0%"
  562. } else {
  563. sellerItem.UnpaidRatioCount = utils.SubFloatToString((mapInvoiceAmountMoney[keyMap]-mapPaymentAmountMoney[keyMap])/mapInvoiceAmountMoney[keyMap]*100, 2) + "%" //"未到款比例-(数据)"
  564. }
  565. sellerItem.NewCustomerInvoicingCount = utils.SubFloatToString(mapNewCustomerInvoicingMoney[keyMap], 2) // "新客开票-(数据)"
  566. sellerItem.NewCustomerPaymentsReceivedCount = utils.SubFloatToString(mapNewCustomerPaymentsReceivedMoney[keyMap], 2) // "新客到款-(数据)"
  567. if developButton || serverButton || adminId != "" {
  568. item.DataList = append(item.DataList, sellerItem)
  569. }
  570. }
  571. if len(sellerDevelop) > 0 {
  572. sellerItem := new(statistic_report.RaiDataSummaryDetail)
  573. sellerItem.SellerId = strings.Join(sellerIds, ",")
  574. sellerItem.SellerName = "开拓组合计"
  575. sellerItem.AddTrialCount = fmt.Sprint(mapAddTrialNum[keyMapTtoal])
  576. sellerItem.NewContractData = fmt.Sprint(utils.SubFloatToString(mapNewContractMoney[keyMapTtoal], 2), " / ", mapNewContractNum[keyMapTtoal]) // 新签合同(金额/数量)-(数据)
  577. sellerItem.ExpiredContractData = fmt.Sprint(utils.SubFloatToString(mapExpiredContractMoney[keyMapTtoal], 2), " / ", mapExpiredContractNum[keyMapTtoal]) //"到期合同(金额/数量)-(数据)"
  578. sellerItem.RenewedContractData = fmt.Sprint(utils.SubFloatToString(mapRenewedContractMoney[keyMapTtoal], 2), " / ", mapRenewedContractNum[keyMapTtoal]) // "续约合同(金额/数量)-(数据)"
  579. var renewalRateMoey string
  580. var renewalRateNum string
  581. if mapRenewedContractMoney[keyMapTtoal] == 0 || mapExpiredContractMoney[keyMapTtoal] == 0 {
  582. renewalRateMoey = "0%"
  583. } else {
  584. renewalRateMoey = utils.SubFloatToString(mapRenewedContractMoney[keyMapTtoal]/mapExpiredContractMoney[keyMapTtoal]*100, 2) + "%"
  585. }
  586. if mapRenewedContractCompanyNum[keyMapTtoal] == 0 || mapExpiredContractCompanyNum[keyMapTtoal] == 0 {
  587. renewalRateNum = "0%"
  588. } else {
  589. renewalRateNum = utils.SubFloatToString(float64(mapRenewedContractCompanyNum[keyMapTtoal])/float64(mapExpiredContractCompanyNum[keyMapTtoal])*100, 2) + "%"
  590. }
  591. sellerItem.RenewalRateData = fmt.Sprint(renewalRateMoey, " / ", renewalRateNum) //"续约率(金额/数量)-(数据)"
  592. sellerItem.ConfirmedNoRenewalContractData = fmt.Sprint(utils.SubFloatToString(confirmedNoRenewalContractMoney[keyMapTtoal], 2), " / ", confirmedNoRenewalContractNum[keyMapTtoal]) //"确认不续约合同(金额/数量)-(数据)"
  593. var confirmNonRenewalRateMoey string
  594. var confirmNonRenewalRateNum string
  595. if confirmedNoRenewalContractMoney[keyMapTtoal] == 0 || mapExpiredContractMoney[keyMapTtoal] == 0 {
  596. confirmNonRenewalRateMoey = "0%"
  597. } else {
  598. confirmNonRenewalRateMoey = utils.SubFloatToString(confirmedNoRenewalContractMoney[keyMapTtoal]/mapExpiredContractMoney[keyMapTtoal]*100, 2) + "%"
  599. }
  600. if confirmedNoRenewalContractCompanyNum[keyMapTtoal] == 0 || mapExpiredContractCompanyNum[keyMapTtoal] == 0 {
  601. confirmNonRenewalRateNum = "0%"
  602. } else {
  603. confirmNonRenewalRateNum = utils.SubFloatToString(float64(confirmedNoRenewalContractCompanyNum[keyMapTtoal])/float64(mapExpiredContractCompanyNum[keyMapTtoal])*100, 2) + "%"
  604. }
  605. sellerItem.ConfirmNonRenewalRateData = fmt.Sprint(confirmNonRenewalRateMoey, " / ", confirmNonRenewalRateNum) //确认不续约率(金额/数量)-(数据)"
  606. sellerItem.SignedClientCount = fmt.Sprint(mapSignedClientNum[keyMapTtoal]) // 签约客户数量
  607. if mapSignedClientNum[keyMapTtoal] == 0 || mapSignedClientMoney[keyMapTtoal] == 0 {
  608. sellerItem.AverageRevenueCount = "0"
  609. } else {
  610. sellerItem.AverageRevenueCount = utils.SubFloatToString(mapSignedClientMoney[keyMapTtoal]/float64(mapSignedClientNum[keyMapTtoal]), 2) //客单价
  611. }
  612. sellerItem.InvoiceAmountCount = utils.SubFloatToString(mapInvoiceAmountMoney[keyMapTtoal], 2) //"开票金额-(数据)"
  613. sellerItem.PaymentReceivedCount = utils.SubFloatToString(mapPaymentAmountMoney[keyMapTtoal], 2) //"开票金额-(数据)"
  614. if mapInvoiceAmountMoney[keyMapTtoal] == 0 || mapPaymentAmountMoney[keyMapTtoal] == 0 {
  615. sellerItem.UnpaidRatioCount = "0%"
  616. } else {
  617. sellerItem.UnpaidRatioCount = utils.SubFloatToString((mapInvoiceAmountMoney[keyMapTtoal]-mapPaymentAmountMoney[keyMapTtoal])/mapInvoiceAmountMoney[keyMapTtoal]*100, 2) + "%" //"未到款比例-(数据)"
  618. }
  619. sellerItem.NewCustomerInvoicingCount = utils.SubFloatToString(mapNewCustomerInvoicingMoney[keyMapTtoal], 2) // "新客开票-(数据)"
  620. sellerItem.NewCustomerPaymentsReceivedCount = utils.SubFloatToString(mapNewCustomerPaymentsReceivedMoney[keyMapTtoal], 2) // "新客到款-(数据)"
  621. item.DataList = append(item.DataList, sellerItem)
  622. }
  623. for _, vS := range sellerService {
  624. keyMap = fmt.Sprint(item.DataType, "_Server_", vS.AdminId)
  625. sellerItem := new(statistic_report.RaiDataSummaryDetail)
  626. sellerItem.IsServerSeller = true
  627. sellerItem.SellerId = strconv.Itoa(vS.AdminId)
  628. sellerServiceIds = append(sellerServiceIds, sellerItem.SellerId)
  629. sellerItem.SellerName = vS.RealName
  630. sellerItem.AddTrialCount = fmt.Sprint(mapAddTrialNum[keyMap])
  631. sellerItem.NewContractData = fmt.Sprint(utils.SubFloatToString(mapNewContractMoneyServer[keyMap], 2), " / ", mapNewContractNumServer[keyMap]) // 新签合同(金额/数量)-(数据)
  632. sellerItem.ExpiredContractData = fmt.Sprint(utils.SubFloatToString(mapExpiredContractMoneyServer[keyMap], 2), " / ", mapExpiredContractNumServer[keyMap]) //"到期合同(金额/数量)-(数据)"
  633. sellerItem.RenewedContractData = fmt.Sprint(utils.SubFloatToString(mapRenewedContractMoneyServer[keyMap], 2), " / ", mapRenewedContractNumServer[keyMap]) // "续约合同(金额/数量)-(数据)"
  634. var renewalRateMoey string
  635. var renewalRateNum string
  636. if mapRenewedContractMoneyServer[keyMap] == 0 || mapExpiredContractMoneyServer[keyMap] == 0 {
  637. renewalRateMoey = "0%"
  638. } else {
  639. renewalRateMoey = utils.SubFloatToString(mapRenewedContractMoneyServer[keyMap]/mapExpiredContractMoneyServer[keyMap]*100, 2) + "%"
  640. }
  641. if mapRenewedContractCompanyNumServer[keyMap] == 0 || mapExpiredContractCompanyNumServer[keyMap] == 0 {
  642. renewalRateNum = "0%"
  643. } else {
  644. renewalRateNum = utils.SubFloatToString(float64(mapRenewedContractCompanyNumServer[keyMap])/float64(mapExpiredContractCompanyNumServer[keyMap])*100, 2) + "%"
  645. }
  646. sellerItem.RenewalRateData = fmt.Sprint(renewalRateMoey, " / ", renewalRateNum) //"续约率(金额/数量)-(数据)"
  647. sellerItem.ConfirmedNoRenewalContractData = fmt.Sprint(utils.SubFloatToString(confirmedNoRenewalContractMoneyServer[keyMap], 2), " / ", confirmedNoRenewalContractNumServer[keyMap]) //"确认不续约合同(金额/数量)-(数据)"
  648. var confirmNonRenewalRateMoey string
  649. var confirmNonRenewalRateNum string
  650. if confirmedNoRenewalContractMoneyServer[keyMap] == 0 || mapExpiredContractMoneyServer[keyMap] == 0 {
  651. confirmNonRenewalRateMoey = "0%"
  652. } else {
  653. confirmNonRenewalRateMoey = utils.SubFloatToString(confirmedNoRenewalContractMoneyServer[keyMap]/mapExpiredContractMoneyServer[keyMap]*100, 2) + "%"
  654. }
  655. if confirmedNoRenewalContractCompanyNumServer[keyMap] == 0 || mapExpiredContractCompanyNumServer[keyMap] == 0 {
  656. confirmNonRenewalRateNum = "0%"
  657. } else {
  658. confirmNonRenewalRateNum = utils.SubFloatToString(float64(confirmedNoRenewalContractCompanyNumServer[keyMap])/float64(mapExpiredContractCompanyNumServer[keyMap])*100, 2) + "%"
  659. }
  660. sellerItem.ConfirmNonRenewalRateData = fmt.Sprint(confirmNonRenewalRateMoey, " / ", confirmNonRenewalRateNum) //确认不续约率(金额/数量)-(数据)"
  661. sellerItem.SignedClientCount = fmt.Sprint(mapSignedClientNumServer[keyMap]) // 签约客户数量
  662. if mapSignedClientNumServer[keyMap] == 0 || mapSignedClientMoneyServer[keyMap] == 0 {
  663. sellerItem.AverageRevenueCount = "0"
  664. } else {
  665. sellerItem.AverageRevenueCount = utils.SubFloatToString(mapSignedClientMoneyServer[keyMap]/float64(mapSignedClientNumServer[keyMap]), 2) //客单价
  666. }
  667. sellerItem.InvoiceAmountCount = utils.SubFloatToString(mapInvoiceAmountMoney[keyMap], 2) //"开票金额-(数据)"
  668. sellerItem.PaymentReceivedCount = utils.SubFloatToString(mapPaymentAmountMoney[keyMap], 2) //"开票金额-(数据)"
  669. if mapInvoiceAmountMoney[keyMap] == 0 || mapPaymentAmountMoney[keyMap] == 0 {
  670. sellerItem.UnpaidRatioCount = "0%"
  671. } else {
  672. sellerItem.UnpaidRatioCount = utils.SubFloatToString((mapInvoiceAmountMoney[keyMap]-mapPaymentAmountMoney[keyMap])/mapInvoiceAmountMoney[keyMap]*100, 2) + "%" //"未到款比例-(数据)"
  673. }
  674. sellerItem.NewCustomerInvoicingCount = utils.SubFloatToString(mapNewCustomerInvoicingMoney[keyMap], 2) // "新客开票-(数据)"
  675. sellerItem.NewCustomerPaymentsReceivedCount = utils.SubFloatToString(mapNewCustomerPaymentsReceivedMoney[keyMap], 2) // "新客到款-(数据)"
  676. if developButton || serverButton || serviceAdminId != "" {
  677. item.DataList = append(item.DataList, sellerItem)
  678. }
  679. }
  680. if len(sellerService) > 0 {
  681. sellerItem := new(statistic_report.RaiDataSummaryDetail)
  682. sellerItem.IsServerSeller = true
  683. sellerItem.SellerId = strings.Join(sellerServiceIds, ",")
  684. sellerItem.SellerName = "服务组合计"
  685. sellerItem.AddTrialCount = fmt.Sprint(mapAddTrialNum[keyMapTtoalServer])
  686. sellerItem.NewContractData = fmt.Sprint(utils.SubFloatToString(mapNewContractMoneyServer[keyMapTtoalServer], 2), " / ", mapNewContractNumServer[keyMapTtoalServer]) // 新签合同(金额/数量)-(数据)
  687. sellerItem.ExpiredContractData = fmt.Sprint(utils.SubFloatToString(mapExpiredContractMoneyServer[keyMapTtoalServer], 2), " / ", mapExpiredContractNumServer[keyMapTtoalServer]) //"到期合同(金额/数量)-(数据)"
  688. sellerItem.RenewedContractData = fmt.Sprint(utils.SubFloatToString(mapRenewedContractMoneyServer[keyMapTtoalServer], 2), " / ", mapRenewedContractNumServer[keyMapTtoalServer]) // "续约合同(金额/数量)-(数据)"
  689. var renewalRateMoey string
  690. var renewalRateNum string
  691. if mapRenewedContractMoneyServer[keyMapTtoalServer] == 0 || mapExpiredContractMoneyServer[keyMapTtoalServer] == 0 {
  692. renewalRateMoey = "0%"
  693. } else {
  694. renewalRateMoey = utils.SubFloatToString(mapRenewedContractMoneyServer[keyMapTtoalServer]/mapExpiredContractMoneyServer[keyMapTtoalServer]*100, 2) + "%"
  695. }
  696. if mapRenewedContractCompanyNumServer[keyMapTtoalServer] == 0 || mapExpiredContractCompanyNumServer[keyMapTtoalServer] == 0 {
  697. renewalRateNum = "0%"
  698. } else {
  699. renewalRateNum = utils.SubFloatToString(float64(mapRenewedContractCompanyNumServer[keyMapTtoalServer])/float64(mapExpiredContractCompanyNumServer[keyMapTtoalServer])*100, 2) + "%"
  700. }
  701. sellerItem.RenewalRateData = fmt.Sprint(renewalRateMoey, " / ", renewalRateNum) //"续约率(金额/数量)-(数据)"
  702. sellerItem.ConfirmedNoRenewalContractData = fmt.Sprint(utils.SubFloatToString(confirmedNoRenewalContractMoneyServer[keyMapTtoalServer], 2), " / ", confirmedNoRenewalContractNumServer[keyMapTtoalServer]) //"确认不续约合同(金额/数量)-(数据)"
  703. var confirmNonRenewalRateMoey string
  704. var confirmNonRenewalRateNum string
  705. if confirmedNoRenewalContractMoneyServer[keyMapTtoalServer] == 0 || mapExpiredContractMoneyServer[keyMapTtoalServer] == 0 {
  706. confirmNonRenewalRateMoey = "0%"
  707. } else {
  708. confirmNonRenewalRateMoey = utils.SubFloatToString(confirmedNoRenewalContractMoneyServer[keyMapTtoalServer]/mapExpiredContractMoneyServer[keyMapTtoalServer]*100, 2) + "%"
  709. }
  710. if confirmedNoRenewalContractCompanyNumServer[keyMapTtoalServer] == 0 || mapExpiredContractCompanyNumServer[keyMapTtoalServer] == 0 {
  711. confirmNonRenewalRateNum = "0%"
  712. } else {
  713. confirmNonRenewalRateNum = utils.SubFloatToString(float64(confirmedNoRenewalContractCompanyNumServer[keyMapTtoalServer])/float64(mapExpiredContractCompanyNumServer[keyMapTtoalServer])*100, 2) + "%"
  714. }
  715. sellerItem.ConfirmNonRenewalRateData = fmt.Sprint(confirmNonRenewalRateMoey, " / ", confirmNonRenewalRateNum) //确认不续约率(金额/数量)-(数据)"
  716. sellerItem.SignedClientCount = fmt.Sprint(mapSignedClientNumServer[keyMapTtoalServer]) // 签约客户数量
  717. if mapSignedClientNumServer[keyMapTtoalServer] == 0 || mapSignedClientMoneyServer[keyMapTtoalServer] == 0 {
  718. sellerItem.AverageRevenueCount = "0"
  719. } else {
  720. sellerItem.AverageRevenueCount = utils.SubFloatToString(mapSignedClientMoneyServer[keyMapTtoalServer]/float64(mapSignedClientNumServer[keyMapTtoalServer]), 2) //客单价
  721. }
  722. sellerItem.InvoiceAmountCount = utils.SubFloatToString(mapInvoiceAmountMoney[keyMapTtoalServer], 2) //"开票金额-(数据)"
  723. sellerItem.PaymentReceivedCount = utils.SubFloatToString(mapPaymentAmountMoney[keyMapTtoalServer], 2) //"开票金额-(数据)"
  724. if mapInvoiceAmountMoney[keyMapTtoalServer] == 0 || mapPaymentAmountMoney[keyMapTtoalServer] == 0 {
  725. sellerItem.UnpaidRatioCount = "0%"
  726. } else {
  727. sellerItem.UnpaidRatioCount = utils.SubFloatToString((mapInvoiceAmountMoney[keyMapTtoalServer]-mapPaymentAmountMoney[keyMapTtoalServer])/mapInvoiceAmountMoney[keyMapTtoalServer]*100, 2) + "%" //"未到款比例-(数据)"
  728. }
  729. sellerItem.NewCustomerInvoicingCount = utils.SubFloatToString(mapNewCustomerInvoicingMoney[keyMapTtoalServer], 2) // "新客开票-(数据)"
  730. sellerItem.NewCustomerPaymentsReceivedCount = utils.SubFloatToString(mapNewCustomerPaymentsReceivedMoney[keyMapTtoalServer], 2) // "新客到款-(数据)"
  731. item.DataList = append(item.DataList, sellerItem)
  732. }
  733. items = append(items, item)
  734. }
  735. }
  736. resp.List = items
  737. br.Ret = 200
  738. br.Success = true
  739. br.Msg = "获取成功"
  740. br.Data = resp
  741. }
  742. // MergeCompanyList
  743. // @Title 权益数据汇总弹窗详情
  744. // @Description 权益数据汇总弹窗详情接口
  745. // @Param SellerId query int true "销售ID"
  746. // @Param DataType query string false "报表类型,枚举值:`季度`,`年度`,`半年度`"
  747. // @Param PopupType query string false "弹窗数据类型,枚举值:"
  748. // @Param IsServerSeller query bool false "是否属于服务组销售"
  749. // @Param PageSize query int true "每页数据条数"
  750. // @Param CurrentIndex query int true "当前页页码,从1开始"
  751. // @Success 200 {object} statistic_report.RaiDataSummaryPopupTypeResp
  752. // @router /rai_data_summary/detail [get]
  753. func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
  754. br := new(models.BaseResponse).Init()
  755. defer func() {
  756. this.Data["json"] = br
  757. this.ServeJSON()
  758. }()
  759. sysUser := this.SysUser
  760. if sysUser == nil {
  761. br.Msg = "请登录"
  762. br.ErrMsg = "请登录,SysUser Is Empty"
  763. br.Ret = 408
  764. return
  765. }
  766. pageSize, _ := this.GetInt("PageSize")
  767. currentIndex, _ := this.GetInt("CurrentIndex")
  768. dataType := this.GetString("DataType")
  769. sellerId := this.GetString("SellerId")
  770. popupType := this.GetString("PopupType")
  771. isServerSeller, _ := this.GetBool("IsServerSeller")
  772. var startSize int
  773. if pageSize <= 0 {
  774. pageSize = utils.PageSize20
  775. }
  776. if currentIndex <= 0 {
  777. currentIndex = 1
  778. }
  779. startSize = utils.StartIndex(currentIndex, pageSize)
  780. var startDate string
  781. var endDate string
  782. year := (dataType[:4])
  783. if strings.Contains(dataType, "Q1") {
  784. startDate = year + "-01-01"
  785. endDate = year + "-03-31"
  786. } else if strings.Contains(dataType, "Q2") {
  787. startDate = year + "-04-01"
  788. endDate = year + "-06-30"
  789. } else if strings.Contains(dataType, "Q3") {
  790. startDate = year + "-07-01"
  791. endDate = year + "-09-30"
  792. } else if strings.Contains(dataType, "Q4") {
  793. startDate = year + "-10-01"
  794. endDate = year + "-12-31"
  795. } else if strings.Contains(dataType, "H1") {
  796. startDate = year + "-01-01"
  797. endDate = year + "-06-31"
  798. } else if strings.Contains(dataType, "H2") {
  799. startDate = year + "-07-01"
  800. endDate = year + "-12-31"
  801. } else {
  802. startDate = year + "-01-01"
  803. endDate = year + "-12-31"
  804. }
  805. resp := new(statistic_report.RaiDataSummaryPopupTypeResp)
  806. var listResp []*statistic_report.RaiDataSummaryDetailResp
  807. var listGroup []*models.CompanyContractGroupList
  808. var trialTotal int
  809. var condition string
  810. var pars []interface{}
  811. //新签合同的ID
  812. var companyContractIdsNew []int
  813. {
  814. var conditionNew string
  815. var parsNew []interface{}
  816. fmt.Println("sellerId", sellerId)
  817. if sellerId != "" {
  818. conditionNew += ` AND a.seller_id_last IN (` + sellerId + `) `
  819. }
  820. conditionNew += " AND a.product_id = 2 AND a.status = 1 AND a.start_date >= ? AND a.start_date <= ? AND a.rai_contract_type = '新签合同' "
  821. parsNew = append(parsNew, startDate, endDate)
  822. listNewData, err := statistic_report.GetRaiDataSummaryList(conditionNew, parsNew)
  823. if err != nil {
  824. br.Msg = "获取数据信息失败"
  825. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  826. return
  827. }
  828. for _, v := range listNewData {
  829. companyContractIdsNew = append(companyContractIdsNew, v.CompanyId)
  830. }
  831. }
  832. companyContractIdsNew = append(companyContractIdsNew, 0)
  833. lenArrCompany := len(companyContractIdsNew)
  834. switch popupType {
  835. case "新增试用":
  836. var parsTry []interface{}
  837. var conditionTry string
  838. if sellerId != "" {
  839. conditionTry += ` AND a.sys_user_id IN (` + sellerId + `) `
  840. }
  841. 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') ) `
  842. parsTry = append(parsTry, startDate, endDate)
  843. total, err := models.GetIncrementalCompanyCountByOperationRecordRai(conditionTry, parsTry)
  844. if err != nil {
  845. br.Msg = "获取失败"
  846. br.ErrMsg = "获取新增试用客户数量失败,Err:" + err.Error()
  847. return
  848. }
  849. trialTotal = total
  850. //列表页数据
  851. tryList, err := models.GetIncrementalCompanyListByOperationRecordRai(conditionTry, parsTry, startSize, pageSize)
  852. if err != nil {
  853. br.Msg = "获取失败"
  854. br.ErrMsg = "获取失败,Err:" + err.Error()
  855. return
  856. }
  857. if len(tryList) > 0 {
  858. for _, v := range tryList {
  859. item := new(statistic_report.RaiDataSummaryDetailResp)
  860. v.SellerName = v.SysRealName
  861. if v.Operation == "add" {
  862. item.AddType = "新建"
  863. } else if v.Operation == "receive" || v.Operation == "apply_receive" {
  864. item.AddType = "领取"
  865. }
  866. item.CompanyId = v.CompanyId
  867. item.CompanyName = v.CompanyName
  868. item.SellerName = v.SellerName
  869. item.CreateTime = v.CreateTime
  870. listResp = append(listResp, item)
  871. }
  872. }
  873. case "新签合同":
  874. if sellerId != "" {
  875. condition += ` AND a.seller_id_init IN (` + sellerId + `) `
  876. }
  877. condition += ` AND a.status = 1 AND a.start_date >= ? AND a.start_date <= ? AND a.product_id = 2 `
  878. pars = append(pars, startDate, endDate)
  879. condition += ` AND a.rai_contract_type = ? `
  880. pars = append(pars, "新签合同")
  881. total, err := company.GetIncrementalNewCompanyProductMergeCount(condition, pars)
  882. if err != nil && err.Error() != utils.ErrNoRow() {
  883. br.Msg = "获取失败"
  884. br.ErrMsg = "获取失败,Err:" + err.Error()
  885. return
  886. }
  887. trialTotal = total
  888. //列表页数据
  889. tmpList, err := models.GetIncrementalCompanyMergeList(condition, pars, startSize, pageSize)
  890. if err != nil {
  891. br.Msg = "获取失败"
  892. br.ErrMsg = "获取失败,Err:" + err.Error()
  893. return
  894. }
  895. if len(tmpList) > 0 {
  896. var companyContractIds []int
  897. for _, v := range tmpList {
  898. companyContractIds = append(companyContractIds, v.CompanyContractId)
  899. }
  900. //合并合同所对应的权限
  901. mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapById(companyContractIds)
  902. if err != nil {
  903. br.Msg = "获取失败"
  904. br.ErrMsg = "获取失败,Err:" + err.Error()
  905. return
  906. }
  907. for _, v := range tmpList {
  908. item := new(statistic_report.RaiDataSummaryDetailResp)
  909. item.CompanyId = v.CompanyId
  910. item.CompanyName = v.CompanyName
  911. item.SellerName = v.SellerNameInit
  912. item.StartDate = v.StartDate
  913. item.EndDate = v.EndDate
  914. item.Money = v.Money
  915. item.PermissionName = mappermissionName[v.CompanyContractId]
  916. listResp = append(listResp, item)
  917. }
  918. listGroup, err = models.GetCompanyContractGroupList(condition, pars)
  919. if err != nil {
  920. br.Msg = "获取失败"
  921. br.ErrMsg = "获取失败,Err:" + err.Error()
  922. return
  923. }
  924. }
  925. case "到期合同":
  926. if sellerId != "" {
  927. if isServerSeller {
  928. condition += ` AND a.share_seller_id_last IN (` + sellerId + `) `
  929. } else {
  930. condition += ` AND a.seller_id_last IN (` + sellerId + `) `
  931. }
  932. }
  933. condition += ` AND a.product_id = 2 AND a.status = 1 AND a.end_date >= ? AND a.end_date <= ? AND a.end_date < ? `
  934. pars = append(pars, startDate, endDate, time.Now().Format(utils.FormatDate))
  935. total, err := company.GetIncrementalNewCompanyProductMergeCount(condition, pars)
  936. if err != nil && err.Error() != utils.ErrNoRow() {
  937. br.Msg = "获取失败"
  938. br.ErrMsg = "获取失败,Err:" + err.Error()
  939. return
  940. }
  941. trialTotal = total
  942. //列表页数据
  943. tmpList, err := models.GetIncrementalCompanyMergeListEnd(condition, pars, startSize, pageSize)
  944. if err != nil {
  945. br.Msg = "获取失败"
  946. br.ErrMsg = "获取失败,Err:" + err.Error()
  947. return
  948. }
  949. if len(tmpList) > 0 {
  950. var companyContractIds []int
  951. for _, v := range tmpList {
  952. companyContractIds = append(companyContractIds, v.CompanyContractId)
  953. }
  954. //合并合同所对应的权限
  955. mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapById(companyContractIds)
  956. if err != nil {
  957. br.Msg = "获取失败"
  958. br.ErrMsg = "获取失败,Err:" + err.Error()
  959. return
  960. }
  961. for _, v := range tmpList {
  962. item := new(statistic_report.RaiDataSummaryDetailResp)
  963. item.CompanyId = v.CompanyId
  964. item.CompanyName = v.CompanyName
  965. item.SellerName = v.SellerNameLast
  966. item.StartDate = v.StartDate
  967. item.EndDate = v.EndDate
  968. item.Money = v.Money
  969. item.PermissionName = mappermissionName[v.CompanyContractId]
  970. listResp = append(listResp, item)
  971. }
  972. listGroup, err = models.GetCompanyContractGroupList(condition, pars)
  973. if err != nil {
  974. br.Msg = "获取失败"
  975. br.ErrMsg = "获取失败,Err:" + err.Error()
  976. return
  977. }
  978. }
  979. case "续约合同":
  980. if sellerId != "" {
  981. if isServerSeller {
  982. condition += ` AND a.share_seller_id_last IN (` + sellerId + `) `
  983. } else {
  984. condition += ` AND a.seller_id_last IN (` + sellerId + `) `
  985. }
  986. }
  987. 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) + `) `
  988. pars = append(pars, startDate, endDate, companyContractIdsNew)
  989. total, err := company.GetIncrementalNewCompanyProductMergeCount(condition, pars)
  990. if err != nil && err.Error() != utils.ErrNoRow() {
  991. br.Msg = "获取失败"
  992. br.ErrMsg = "获取失败,Err:" + err.Error()
  993. return
  994. }
  995. trialTotal = total
  996. //列表页数据
  997. tmpList, err := models.GetIncrementalCompanyMergeList(condition, pars, startSize, pageSize)
  998. if err != nil {
  999. br.Msg = "获取失败"
  1000. br.ErrMsg = "获取失败,Err:" + err.Error()
  1001. return
  1002. }
  1003. if len(tmpList) > 0 {
  1004. var companyContractIds []int
  1005. for _, v := range tmpList {
  1006. companyContractIds = append(companyContractIds, v.CompanyContractId)
  1007. }
  1008. //合并合同所对应的权限
  1009. mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapById(companyContractIds)
  1010. if err != nil {
  1011. br.Msg = "获取失败"
  1012. br.ErrMsg = "获取失败,Err:" + err.Error()
  1013. return
  1014. }
  1015. for _, v := range tmpList {
  1016. item := new(statistic_report.RaiDataSummaryDetailResp)
  1017. item.CompanyId = v.CompanyId
  1018. item.CompanyName = v.CompanyName
  1019. item.SellerName = v.SellerNameLast
  1020. item.StartDate = v.StartDate
  1021. item.EndDate = v.EndDate
  1022. item.Money = v.Money
  1023. item.PermissionName = mappermissionName[v.CompanyContractId]
  1024. listResp = append(listResp, item)
  1025. }
  1026. listGroup, err = models.GetCompanyContractGroupList(condition, pars)
  1027. if err != nil {
  1028. br.Msg = "获取失败"
  1029. br.ErrMsg = "获取失败,Err:" + err.Error()
  1030. return
  1031. }
  1032. }
  1033. case "续约率":
  1034. var conditionEnd string
  1035. var parsEnd []interface{}
  1036. if sellerId != "" {
  1037. condition += ` AND a.seller_id_last IN (` + sellerId + `) `
  1038. conditionEnd += ` AND a.seller_id_last IN (` + sellerId + `) `
  1039. }
  1040. 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) + `) `
  1041. pars = append(pars, startDate, endDate, companyContractIdsNew)
  1042. listRaiData, err := statistic_report.GetRaiDataSummaryList(condition, pars)
  1043. if err != nil {
  1044. br.Msg = "获取数据信息失败"
  1045. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1046. return
  1047. }
  1048. //到期合同数据
  1049. conditionEnd += ` AND a.status = 1 AND a.end_date >= ? AND a.end_date <= ? AND a.end_date < ? `
  1050. parsEnd = append(parsEnd, startDate, endDate, time.Now().Format(utils.FormatDate))
  1051. listEndData, err := statistic_report.GetRaiDataSummaryList(conditionEnd, parsEnd)
  1052. if err != nil {
  1053. br.Msg = "获取数据信息失败"
  1054. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1055. return
  1056. }
  1057. var renewedContractMoney float64 // 续约金额
  1058. var renewedContractCompany float64 // 续约客户数
  1059. maprenewedContractCompany := make(map[int]bool)
  1060. var expiredContractMoney float64 //到期金额
  1061. var expiredContractCompany float64 // 到期客户数
  1062. mapexpiredContractCompany := make(map[int]bool)
  1063. for _, v := range listRaiData {
  1064. renewedContractMoney += v.Money
  1065. if !maprenewedContractCompany[v.CompanyId] {
  1066. renewedContractCompany++
  1067. maprenewedContractCompany[v.CompanyId] = true
  1068. }
  1069. //startDateTime := utils.StrDateToDate(v.StartDate)
  1070. //if startDateTime.Before(time.Now().AddDate(0, 0, -1)) { //到期合同数据
  1071. // expiredContractMoney += v.Money
  1072. // if !mapexpiredContractCompany[v.CompanyId] {
  1073. // expiredContractCompany++
  1074. // mapexpiredContractCompany[v.CompanyId] = true
  1075. // }
  1076. //}
  1077. }
  1078. for _, v := range listEndData {
  1079. expiredContractMoney += v.Money
  1080. if !mapexpiredContractCompany[v.CompanyId] {
  1081. expiredContractCompany++
  1082. mapexpiredContractCompany[v.CompanyId] = true
  1083. }
  1084. }
  1085. item := new(statistic_report.RaiDataSummaryDetailResp)
  1086. item.TbaleNameAText = "金额续约率"
  1087. item.RenewedContractMoney = fmt.Sprint(utils.SubFloatToString(renewedContractMoney, 2))
  1088. item.ExpiredContractMoney = fmt.Sprint(utils.SubFloatToString(expiredContractMoney, 2))
  1089. if renewedContractMoney == 0 || expiredContractMoney == 0 {
  1090. item.RenewalRate = "0%"
  1091. } else {
  1092. item.RenewalRate = fmt.Sprint(utils.SubFloatToString(renewedContractMoney/expiredContractMoney*100, 2), "%")
  1093. }
  1094. listResp = append(listResp, item)
  1095. item2 := new(statistic_report.RaiDataSummaryDetailResp)
  1096. item2.TbaleNameAText = "客户续约率"
  1097. item2.RenewedContractMoney = fmt.Sprint(renewedContractCompany)
  1098. item2.ExpiredContractMoney = fmt.Sprint(expiredContractCompany)
  1099. if renewedContractCompany == 0 || expiredContractCompany == 0 {
  1100. item2.RenewalRate = "0%"
  1101. } else {
  1102. item2.RenewalRate = fmt.Sprint(utils.SubFloatToString(renewedContractCompany/expiredContractCompany*100, 2), "%")
  1103. }
  1104. listResp = append(listResp, item2)
  1105. case "确认不续约合同":
  1106. noRenewedcompanyContractIds := services.GetCompanyContractNoRenewedAscribeListArr()
  1107. condition += ` AND a.company_contract_id IN (` + utils.GetOrmInReplace(len(noRenewedcompanyContractIds)) + `) ` // 已确认
  1108. pars = append(pars, noRenewedcompanyContractIds)
  1109. if sellerId != "" {
  1110. if isServerSeller {
  1111. condition += ` AND a.share_seller_id_last IN (` + sellerId + `) `
  1112. } else {
  1113. condition += ` AND a.seller_id_last IN (` + sellerId + `) `
  1114. }
  1115. }
  1116. condition += ` AND a.product_id = 2 AND a.status = 1 AND a.end_date >= ? AND a.end_date <= ? AND a.end_date <= ? `
  1117. pars = append(pars, startDate, endDate, time.Now().Format(utils.FormatDate))
  1118. total, err := company.GetIncrementalNewCompanyProductMergeCount(condition, pars)
  1119. if err != nil && err.Error() != utils.ErrNoRow() {
  1120. br.Msg = "获取失败"
  1121. br.ErrMsg = "获取失败,Err:" + err.Error()
  1122. return
  1123. }
  1124. trialTotal = total
  1125. //列表页数据
  1126. tmpList, err := models.GetIncrementalCompanyMergeList(condition, pars, startSize, pageSize)
  1127. if err != nil {
  1128. br.Msg = "获取失败"
  1129. br.ErrMsg = "获取失败,Err:" + err.Error()
  1130. return
  1131. }
  1132. if len(tmpList) > 0 {
  1133. var companyContractIds []int
  1134. for _, v := range tmpList {
  1135. companyContractIds = append(companyContractIds, v.CompanyContractId)
  1136. }
  1137. //合并合同所对应的权限
  1138. mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapById(companyContractIds)
  1139. if err != nil {
  1140. br.Msg = "获取失败"
  1141. br.ErrMsg = "获取失败,Err:" + err.Error()
  1142. return
  1143. }
  1144. for _, v := range tmpList {
  1145. item := new(statistic_report.RaiDataSummaryDetailResp)
  1146. item.CompanyId = v.CompanyId
  1147. item.CompanyName = v.CompanyName
  1148. item.SellerName = v.SellerNameInit
  1149. item.StartDate = v.StartDate
  1150. item.EndDate = v.EndDate
  1151. item.Money = v.Money
  1152. item.PermissionName = mappermissionName[v.CompanyContractId]
  1153. listResp = append(listResp, item)
  1154. }
  1155. listGroup, err = models.GetCompanyContractGroupList(condition, pars)
  1156. if err != nil {
  1157. br.Msg = "获取失败"
  1158. br.ErrMsg = "获取失败,Err:" + err.Error()
  1159. return
  1160. }
  1161. }
  1162. case "确认不续约率":
  1163. noRenewedcompanyContractIdsMap := services.GetCompanyContractNoRenewedAscribeListMap()
  1164. var conditionEnd string
  1165. var parsEnd []interface{}
  1166. if sellerId != "" {
  1167. condition += ` AND a.seller_id_last IN (` + sellerId + `) `
  1168. conditionEnd += ` AND a.seller_id_last IN (` + sellerId + `) `
  1169. }
  1170. condition += ` AND a.product_id = 2 AND a.status = 1 AND a.end_date >= ? AND a.end_date <= ? AND a.end_date <= ? `
  1171. pars = append(pars, startDate, endDate, time.Now().Format(utils.FormatDate))
  1172. listRaiData, err := statistic_report.GetRaiDataSummaryList(condition, pars)
  1173. if err != nil {
  1174. br.Msg = "获取数据信息失败"
  1175. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1176. return
  1177. }
  1178. conditionEnd += ` AND a.product_id = 2 AND a.status = 1 AND a.end_date >= ? AND a.end_date <= ? AND a.end_date < ? `
  1179. parsEnd = append(parsEnd, startDate, endDate, time.Now().Format(utils.FormatDate))
  1180. listEndData, err := statistic_report.GetRaiDataSummaryList(conditionEnd, parsEnd)
  1181. if err != nil {
  1182. br.Msg = "获取数据信息失败"
  1183. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1184. return
  1185. }
  1186. var norenewedContractMoney float64 // 不续约金额
  1187. var norenewedContractCompany float64 // 不续约客户数
  1188. mapnorenewedContractCompany := make(map[int]bool)
  1189. var expiredContractMoney float64 //到期金额
  1190. var expiredContractCompany float64 // 到期客户数
  1191. mapexpiredContractCompany := make(map[int]bool)
  1192. for _, v := range listRaiData {
  1193. if noRenewedcompanyContractIdsMap[v.CompanyContractId] {
  1194. norenewedContractMoney += v.Money
  1195. if !mapnorenewedContractCompany[v.CompanyId] {
  1196. norenewedContractCompany++
  1197. mapnorenewedContractCompany[v.CompanyId] = true
  1198. }
  1199. }
  1200. }
  1201. for _, v := range listEndData {
  1202. expiredContractMoney += v.Money
  1203. if !mapexpiredContractCompany[v.CompanyId] {
  1204. expiredContractCompany++
  1205. mapexpiredContractCompany[v.CompanyId] = true
  1206. }
  1207. }
  1208. item := new(statistic_report.RaiDataSummaryDetailResp)
  1209. item.TbaleNameAText = "金额不续约率"
  1210. item.RenewedContractMoney = fmt.Sprint(utils.SubFloatToString(norenewedContractMoney, 2))
  1211. item.ExpiredContractMoney = fmt.Sprint(utils.SubFloatToString(expiredContractMoney, 2))
  1212. if norenewedContractMoney == 0 || expiredContractMoney == 0 {
  1213. item.RenewalRate = "0%"
  1214. } else {
  1215. item.RenewalRate = fmt.Sprint(utils.SubFloatToString(norenewedContractMoney/expiredContractMoney*100, 2), "%")
  1216. }
  1217. listResp = append(listResp, item)
  1218. item2 := new(statistic_report.RaiDataSummaryDetailResp)
  1219. item2.TbaleNameAText = "客户不续约率"
  1220. item2.RenewedContractMoney = fmt.Sprint(norenewedContractCompany)
  1221. item2.ExpiredContractMoney = fmt.Sprint(expiredContractCompany)
  1222. if norenewedContractCompany == 0 || expiredContractCompany == 0 {
  1223. item2.RenewalRate = "0%"
  1224. } else {
  1225. item2.RenewalRate = fmt.Sprint(utils.SubFloatToString(norenewedContractCompany/expiredContractCompany*100, 2), "%")
  1226. }
  1227. listResp = append(listResp, item2)
  1228. case "签约客户数量":
  1229. var conditionInherit string
  1230. var parsInherit []interface{}
  1231. if sellerId != "" {
  1232. condition += ` AND a.seller_id_last IN (` + sellerId + `) `
  1233. conditionInherit += ` AND a.seller_id_last IN (` + sellerId + `) `
  1234. }
  1235. condition += " AND a.product_id = 2 AND a.status = 1 AND a.start_date >= ? AND a.start_date <= ? AND a.rai_contract_type = '新签合同' "
  1236. pars = append(pars, startDate, endDate)
  1237. listRaiData, err := statistic_report.GetRaiDataSummaryList(condition, pars)
  1238. if err != nil {
  1239. br.Msg = "获取数据信息失败"
  1240. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1241. return
  1242. }
  1243. //续约部分的数据
  1244. 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) + `) `
  1245. parsInherit = append(parsInherit, startDate, endDate, companyContractIdsNew)
  1246. listInheritData, err := statistic_report.GetRaiDataSummaryInheritList(conditionInherit, parsInherit)
  1247. if err != nil {
  1248. br.Msg = "获取数据信息失败"
  1249. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1250. return
  1251. }
  1252. var renewedContractCompany int // 续约客户数
  1253. var renewedContract int // 续约合同数
  1254. maprenewedContractCompany := make(map[int]bool)
  1255. var newContractCompany int // 新签客户数
  1256. var newContract int // 新签合同数
  1257. mapenewContractCompany := make(map[int]bool)
  1258. for _, v := range listRaiData {
  1259. if v.RaiContractType == "新签合同" {
  1260. newContract++
  1261. if !mapenewContractCompany[v.CompanyId] {
  1262. newContractCompany++
  1263. mapenewContractCompany[v.CompanyId] = true
  1264. }
  1265. }
  1266. //else if v.RaiContractType == "续约合同" {
  1267. // renewedContract++
  1268. // if !maprenewedContractCompany[v.CompanyId] {
  1269. // renewedContractCompany++
  1270. // maprenewedContractCompany[v.CompanyId] = true
  1271. // }
  1272. //}
  1273. }
  1274. for _, v := range listInheritData {
  1275. renewedContract++
  1276. if !maprenewedContractCompany[v.CompanyId] {
  1277. renewedContractCompany++
  1278. maprenewedContractCompany[v.CompanyId] = true
  1279. }
  1280. }
  1281. item := new(statistic_report.RaiDataSummaryDetailResp)
  1282. item.RenewedContractCompany = renewedContractCompany
  1283. item.RenewedContract = renewedContract
  1284. item.NewContractCompany = newContractCompany
  1285. item.NewContract = newContract
  1286. listResp = append(listResp, item)
  1287. case "客单价":
  1288. //续约部分的数据
  1289. var conditionInherit string
  1290. var parsInherit []interface{}
  1291. if sellerId != "" {
  1292. condition += ` AND a.seller_id_last IN (` + sellerId + `) `
  1293. conditionInherit += ` AND a.seller_id_last IN (` + sellerId + `) `
  1294. }
  1295. condition += " AND a.product_id = 2 AND a.status = 1 AND a.start_date >= ? AND a.start_date <= ? AND a.rai_contract_type = '新签合同' "
  1296. pars = append(pars, startDate, endDate)
  1297. listRaiData, err := statistic_report.GetRaiDataSummaryList(condition, pars)
  1298. if err != nil {
  1299. br.Msg = "获取数据信息失败"
  1300. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1301. return
  1302. }
  1303. var ontractMoney float64 // 签约总金额
  1304. var contractNum int // 签约客户数
  1305. mapCompany := make(map[int]bool)
  1306. for _, v := range listRaiData {
  1307. if v.RaiContractType != "新签合同" {
  1308. continue
  1309. }
  1310. ontractMoney += v.Money
  1311. if !mapCompany[v.CompanyId] {
  1312. contractNum++
  1313. mapCompany[v.CompanyId] = true
  1314. }
  1315. }
  1316. 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) + `) `
  1317. parsInherit = append(parsInherit, startDate, endDate, companyContractIdsNew)
  1318. listInheritData, err := statistic_report.GetRaiDataSummaryInheritList(conditionInherit, parsInherit)
  1319. if err != nil {
  1320. br.Msg = "获取数据信息失败"
  1321. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1322. return
  1323. }
  1324. for _, v := range listInheritData {
  1325. ontractMoney += v.Money
  1326. if !mapCompany[v.CompanyId] && v.RaiContractType == "续约合同" {
  1327. contractNum++
  1328. mapCompany[v.CompanyId] = true
  1329. }
  1330. }
  1331. item := new(statistic_report.RaiDataSummaryDetailResp)
  1332. item.ContractMoney = fmt.Sprint(utils.SubFloatToString(ontractMoney, 2))
  1333. item.ContractNum = contractNum
  1334. listResp = append(listResp, item)
  1335. case "开票金额":
  1336. if sellerId != "" {
  1337. condition += ` AND a.rai_seller_id IN (` + sellerId + `) `
  1338. }
  1339. condition += " AND a.is_deleted = 0 AND a.start_date >= ? AND a.start_date <= ? AND invoiced_amount > 0 AND product_ids LIKE '%2%' "
  1340. pars = append(pars, startDate, endDate)
  1341. total, err := fms.GetContractInvoiceCount(condition, pars)
  1342. if err != nil && err.Error() != utils.ErrNoRow() {
  1343. br.Msg = "获取失败"
  1344. br.ErrMsg = "获取失败,Err:" + err.Error()
  1345. return
  1346. }
  1347. trialTotal = total
  1348. listFmsData, err := fms.GetContractRegisterList(condition, pars, startSize, pageSize)
  1349. if err != nil {
  1350. br.Msg = "获取数据信息失败"
  1351. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1352. return
  1353. }
  1354. if len(listFmsData) > 0 {
  1355. var contractRegisterId []int
  1356. for _, v := range listFmsData {
  1357. contractRegisterId = append(contractRegisterId, v.ContractRegisterId)
  1358. }
  1359. lenArr := len(contractRegisterId)
  1360. var conditionFms string
  1361. var parsFms []interface{}
  1362. conditionFms += ` AND contract_register_id IN (` + utils.GetOrmInReplace(lenArr) + `) GROUP BY contract_register_id `
  1363. parsFms = append(parsFms, contractRegisterId)
  1364. listInvoiceData, err := fms.GetContractInvoiceList(conditionFms, parsFms, 0, lenArr)
  1365. if err != nil {
  1366. br.Msg = "获取数据信息失败"
  1367. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1368. return
  1369. }
  1370. mapInvoiceTime := make(map[int]string)
  1371. for _, v := range listInvoiceData {
  1372. mapInvoiceTime[v.ContractRegisterId] = v.InvoiceTime.Format(utils.FormatDate)
  1373. }
  1374. for _, v := range listFmsData {
  1375. item := new(statistic_report.RaiDataSummaryDetailResp)
  1376. item.CompanyName = v.CompanyName
  1377. item.SellerName = v.RaiSellerName
  1378. item.ContractCode = v.ContractCode
  1379. item.InvoicedAmount = v.InvoicedAmount
  1380. item.CreateTime = mapInvoiceTime[v.ContractRegisterId]
  1381. listResp = append(listResp, item)
  1382. }
  1383. }
  1384. case "到款金额":
  1385. if sellerId != "" {
  1386. condition += ` AND a.rai_seller_id IN (` + sellerId + `) `
  1387. }
  1388. condition += " AND a.is_deleted = 0 AND a.start_date >= ? AND a.start_date <= ? AND payment_amount > 0 AND product_ids LIKE '%2%' "
  1389. pars = append(pars, startDate, endDate)
  1390. total, err := fms.GetContractInvoiceCount(condition, pars)
  1391. if err != nil && err.Error() != utils.ErrNoRow() {
  1392. br.Msg = "获取失败"
  1393. br.ErrMsg = "获取失败,Err:" + err.Error()
  1394. return
  1395. }
  1396. trialTotal = total
  1397. listFmsData, err := fms.GetContractRegisterList(condition, pars, startSize, pageSize)
  1398. if err != nil {
  1399. br.Msg = "获取数据信息失败"
  1400. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1401. return
  1402. }
  1403. if len(listFmsData) > 0 {
  1404. var contractRegisterId []int
  1405. for _, v := range listFmsData {
  1406. contractRegisterId = append(contractRegisterId, v.ContractRegisterId)
  1407. }
  1408. lenArr := len(contractRegisterId)
  1409. var conditionFms string
  1410. var parsFms []interface{}
  1411. conditionFms += ` AND contract_register_id IN (` + utils.GetOrmInReplace(lenArr) + `) GROUP BY contract_register_id `
  1412. parsFms = append(parsFms, contractRegisterId)
  1413. listInvoiceData, err := fms.GetContractInvoiceList(conditionFms, parsFms, 0, lenArr)
  1414. if err != nil {
  1415. br.Msg = "获取数据信息失败"
  1416. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1417. return
  1418. }
  1419. mapInvoiceTime := make(map[int]string)
  1420. for _, v := range listInvoiceData {
  1421. mapInvoiceTime[v.ContractRegisterId] = v.InvoiceTime.Format(utils.FormatDate)
  1422. }
  1423. for _, v := range listFmsData {
  1424. item := new(statistic_report.RaiDataSummaryDetailResp)
  1425. item.CompanyName = v.CompanyName
  1426. item.SellerName = v.RaiSellerName
  1427. item.ContractCode = v.ContractCode
  1428. item.PaymentAmount = v.PaymentAmount
  1429. item.CreateTime = v.CreateTime.Format(utils.FormatDate)
  1430. listResp = append(listResp, item)
  1431. }
  1432. }
  1433. case "未到款比例":
  1434. if sellerId != "" {
  1435. condition += ` AND a.rai_seller_id IN (` + sellerId + `) `
  1436. }
  1437. condition += " AND a.is_deleted = 0 AND a.start_date >= ? AND a.start_date <= ? AND product_ids LIKE '%2%' "
  1438. pars = append(pars, startDate, endDate)
  1439. listFmsData, err := fms.GetContractRegisterAmountList(condition, pars)
  1440. if err != nil {
  1441. br.Msg = "获取数据信息失败"
  1442. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1443. return
  1444. }
  1445. for _, v := range listFmsData {
  1446. item := new(statistic_report.RaiDataSummaryDetailResp)
  1447. item.InvoicedAmount = v.InvoicedAmount
  1448. item.PaymentAmount = v.PaymentAmount
  1449. item.NotReceivedtAmount = v.InvoicedAmount - v.PaymentAmount
  1450. item.CreateTime = v.CreateTime.Format(utils.FormatDate)
  1451. listResp = append(listResp, item)
  1452. }
  1453. case "新客开票":
  1454. if sellerId != "" {
  1455. condition += ` AND a.rai_seller_id IN (` + sellerId + `) `
  1456. }
  1457. condition += " AND a.is_deleted = 0 AND contract_type = 1 AND a.start_date >= ? AND a.start_date <= ? AND product_ids LIKE '%2%' "
  1458. pars = append(pars, startDate, endDate)
  1459. total, err := fms.GetContractInvoiceCount(condition, pars)
  1460. if err != nil && err.Error() != utils.ErrNoRow() {
  1461. br.Msg = "获取失败"
  1462. br.ErrMsg = "获取失败,Err:" + err.Error()
  1463. return
  1464. }
  1465. trialTotal = total
  1466. listFmsData, err := fms.GetContractRegisterList(condition, pars, startSize, pageSize)
  1467. if err != nil {
  1468. br.Msg = "获取数据信息失败"
  1469. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1470. return
  1471. }
  1472. if len(listFmsData) > 0 {
  1473. var contractRegisterId []int
  1474. for _, v := range listFmsData {
  1475. contractRegisterId = append(contractRegisterId, v.ContractRegisterId)
  1476. }
  1477. lenArr := len(contractRegisterId)
  1478. var conditionFms string
  1479. var parsFms []interface{}
  1480. conditionFms += ` AND contract_register_id IN (` + utils.GetOrmInReplace(lenArr) + `) GROUP BY contract_register_id `
  1481. parsFms = append(parsFms, contractRegisterId)
  1482. listInvoiceData, err := fms.GetContractInvoiceList(conditionFms, parsFms, 0, lenArr)
  1483. if err != nil {
  1484. br.Msg = "获取数据信息失败"
  1485. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1486. return
  1487. }
  1488. mapInvoiceTime := make(map[int]string)
  1489. for _, v := range listInvoiceData {
  1490. mapInvoiceTime[v.ContractRegisterId] = v.InvoiceTime.Format(utils.FormatDate)
  1491. }
  1492. for _, v := range listFmsData {
  1493. item := new(statistic_report.RaiDataSummaryDetailResp)
  1494. item.CompanyName = v.CompanyName
  1495. item.SellerName = v.RaiSellerName
  1496. item.ContractCode = v.ContractCode
  1497. item.InvoicedAmount = v.InvoicedAmount
  1498. item.CreateTime = mapInvoiceTime[v.ContractRegisterId]
  1499. listResp = append(listResp, item)
  1500. }
  1501. }
  1502. case "新客到款":
  1503. if sellerId != "" {
  1504. condition += ` AND a.rai_seller_id IN (` + sellerId + `) `
  1505. }
  1506. 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%' "
  1507. pars = append(pars, startDate, endDate)
  1508. total, err := fms.GetContractInvoiceCount(condition, pars)
  1509. if err != nil && err.Error() != utils.ErrNoRow() {
  1510. br.Msg = "获取失败"
  1511. br.ErrMsg = "获取失败,Err:" + err.Error()
  1512. return
  1513. }
  1514. trialTotal = total
  1515. listFmsData, err := fms.GetContractRegisterList(condition, pars, startSize, pageSize)
  1516. if err != nil {
  1517. br.Msg = "获取数据信息失败"
  1518. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1519. return
  1520. }
  1521. if len(listFmsData) > 0 {
  1522. var contractRegisterId []int
  1523. for _, v := range listFmsData {
  1524. contractRegisterId = append(contractRegisterId, v.ContractRegisterId)
  1525. }
  1526. lenArr := len(contractRegisterId)
  1527. var conditionFms string
  1528. var parsFms []interface{}
  1529. conditionFms += ` AND contract_register_id IN (` + utils.GetOrmInReplace(lenArr) + `) GROUP BY contract_register_id `
  1530. parsFms = append(parsFms, contractRegisterId)
  1531. listInvoiceData, err := fms.GetContractInvoiceList(conditionFms, parsFms, 0, lenArr)
  1532. if err != nil {
  1533. br.Msg = "获取数据信息失败"
  1534. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1535. return
  1536. }
  1537. mapInvoiceTime := make(map[int]string)
  1538. for _, v := range listInvoiceData {
  1539. mapInvoiceTime[v.ContractRegisterId] = v.InvoiceTime.Format(utils.FormatDate)
  1540. }
  1541. for _, v := range listFmsData {
  1542. item := new(statistic_report.RaiDataSummaryDetailResp)
  1543. item.CompanyName = v.CompanyName
  1544. item.SellerName = v.RaiSellerName
  1545. item.ContractCode = v.ContractCode
  1546. item.PaymentAmount = v.PaymentAmount
  1547. item.CreateTime = mapInvoiceTime[v.ContractRegisterId]
  1548. listResp = append(listResp, item)
  1549. }
  1550. }
  1551. }
  1552. if len(listResp) == 0 {
  1553. listResp = make([]*statistic_report.RaiDataSummaryDetailResp, 0)
  1554. }
  1555. if len(listGroup) > 0 {
  1556. for _, v := range listGroup {
  1557. if v.CompanyCount > 1 {
  1558. resp.CompanyMultiple++
  1559. }
  1560. }
  1561. resp.CompanyNum = len(listGroup)
  1562. }
  1563. resp.List = listResp
  1564. page := paging.GetPaging(currentIndex, pageSize, trialTotal)
  1565. resp.Paging = page
  1566. br.Ret = 200
  1567. br.Success = true
  1568. br.Msg = "获取成功"
  1569. br.Data = resp
  1570. }
  1571. // 时间筛选项的转换
  1572. func getYearStar(startDate time.Time, dataType string) (yearStr string) {
  1573. startDateTime := startDate
  1574. monthNum := startDateTime.Month()
  1575. yearStr = strconv.Itoa(startDateTime.Year())
  1576. if dataType == "季度" {
  1577. if monthNum < 4 {
  1578. yearStr += "Q1"
  1579. } else if monthNum > 3 && monthNum < 7 {
  1580. yearStr += "Q2"
  1581. } else if monthNum > 6 && monthNum < 10 {
  1582. yearStr += "Q3"
  1583. } else if monthNum > 9 {
  1584. yearStr += "Q4"
  1585. }
  1586. } else if dataType == "半年度" {
  1587. if monthNum < 7 {
  1588. yearStr += "H1"
  1589. } else {
  1590. yearStr += "H2"
  1591. }
  1592. }
  1593. return
  1594. }