rai_data_summary.go 72 KB

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