rai_data_summary.go 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809
  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 !mapsellerService[v.ShareSellerIdInit] {
  249. continue
  250. }
  251. yearStr := getYearStar(utils.StrDateToDate(v.StartDate), dataType)
  252. keyMap = fmt.Sprint(yearStr, "_Server_", v.ShareSellerIdInit)
  253. keySigned = fmt.Sprint(yearStr, "_Server_", v.CompanyId, "_SID_", v.ShareSellerIdInit)
  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. mapSignedClientNumServer[keyMap]++
  332. mapSignedClientNumServer[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 && adminId == "" {
  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 && serviceAdminId == "" {
  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. if isServerSeller {
  876. condition += ` AND a.share_seller_id_init IN (` + sellerId + `) `
  877. } else {
  878. condition += ` AND a.seller_id_init IN (` + sellerId + `) `
  879. }
  880. }
  881. condition += ` AND a.status = 1 AND a.start_date >= ? AND a.start_date <= ? AND a.product_id = 2 `
  882. pars = append(pars, startDate, endDate)
  883. condition += ` AND a.rai_contract_type = ? `
  884. pars = append(pars, "新签合同")
  885. total, err := company.GetIncrementalNewCompanyProductMergeCount(condition, pars)
  886. if err != nil && err.Error() != utils.ErrNoRow() {
  887. br.Msg = "获取失败"
  888. br.ErrMsg = "获取失败,Err:" + err.Error()
  889. return
  890. }
  891. trialTotal = total
  892. //列表页数据
  893. tmpList, err := models.GetIncrementalCompanyMergeList(condition, pars, startSize, pageSize)
  894. if err != nil {
  895. br.Msg = "获取失败"
  896. br.ErrMsg = "获取失败,Err:" + err.Error()
  897. return
  898. }
  899. if len(tmpList) > 0 {
  900. var companyContractIds []int
  901. for _, v := range tmpList {
  902. companyContractIds = append(companyContractIds, v.CompanyContractId)
  903. }
  904. //合并合同所对应的权限
  905. mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapById(companyContractIds)
  906. if err != nil {
  907. br.Msg = "获取失败"
  908. br.ErrMsg = "获取失败,Err:" + err.Error()
  909. return
  910. }
  911. for _, v := range tmpList {
  912. item := new(statistic_report.RaiDataSummaryDetailResp)
  913. item.CompanyId = v.CompanyId
  914. item.CompanyName = v.CompanyName
  915. if isServerSeller {
  916. item.SellerName = v.ShareSeller
  917. } else {
  918. item.SellerName = v.SellerNameInit
  919. }
  920. item.StartDate = v.StartDate
  921. item.EndDate = v.EndDate
  922. item.Money = v.Money
  923. item.PermissionName = mappermissionName[v.CompanyContractId]
  924. listResp = append(listResp, item)
  925. }
  926. listGroup, err = models.GetCompanyContractGroupList(condition, pars)
  927. if err != nil {
  928. br.Msg = "获取失败"
  929. br.ErrMsg = "获取失败,Err:" + err.Error()
  930. return
  931. }
  932. }
  933. case "到期合同":
  934. if sellerId != "" {
  935. if isServerSeller {
  936. condition += ` AND a.share_seller_id_last IN (` + sellerId + `) `
  937. } else {
  938. condition += ` AND a.seller_id_last IN (` + sellerId + `) `
  939. }
  940. }
  941. condition += ` AND a.product_id = 2 AND a.status = 1 AND a.end_date >= ? AND a.end_date <= ? AND a.end_date < ? `
  942. pars = append(pars, startDate, endDate, time.Now().Format(utils.FormatDate))
  943. total, err := company.GetIncrementalNewCompanyProductMergeCount(condition, pars)
  944. if err != nil && err.Error() != utils.ErrNoRow() {
  945. br.Msg = "获取失败"
  946. br.ErrMsg = "获取失败,Err:" + err.Error()
  947. return
  948. }
  949. trialTotal = total
  950. //列表页数据
  951. tmpList, err := models.GetIncrementalCompanyMergeListEnd(condition, pars, startSize, pageSize)
  952. if err != nil {
  953. br.Msg = "获取失败"
  954. br.ErrMsg = "获取失败,Err:" + err.Error()
  955. return
  956. }
  957. if len(tmpList) > 0 {
  958. var companyContractIds []int
  959. for _, v := range tmpList {
  960. companyContractIds = append(companyContractIds, v.CompanyContractId)
  961. }
  962. //合并合同所对应的权限
  963. mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapById(companyContractIds)
  964. if err != nil {
  965. br.Msg = "获取失败"
  966. br.ErrMsg = "获取失败,Err:" + err.Error()
  967. return
  968. }
  969. for _, v := range tmpList {
  970. item := new(statistic_report.RaiDataSummaryDetailResp)
  971. item.CompanyId = v.CompanyId
  972. item.CompanyName = v.CompanyName
  973. if isServerSeller {
  974. item.SellerName = v.ShareSellerLast
  975. } else {
  976. item.SellerName = v.SellerNameLast
  977. }
  978. item.StartDate = v.StartDate
  979. item.EndDate = v.EndDate
  980. item.Money = v.Money
  981. item.PermissionName = mappermissionName[v.CompanyContractId]
  982. listResp = append(listResp, item)
  983. }
  984. listGroup, err = models.GetCompanyContractGroupList(condition, pars)
  985. if err != nil {
  986. br.Msg = "获取失败"
  987. br.ErrMsg = "获取失败,Err:" + err.Error()
  988. return
  989. }
  990. }
  991. case "续约合同":
  992. if sellerId != "" {
  993. if isServerSeller {
  994. condition += ` AND a.share_seller_id_last IN (` + sellerId + `) `
  995. } else {
  996. condition += ` AND a.seller_id_last IN (` + sellerId + `) `
  997. }
  998. }
  999. 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) + `) `
  1000. pars = append(pars, startDate, endDate, companyContractIdsNew)
  1001. total, err := company.GetIncrementalNewCompanyProductMergeCount(condition, pars)
  1002. if err != nil && err.Error() != utils.ErrNoRow() {
  1003. br.Msg = "获取失败"
  1004. br.ErrMsg = "获取失败,Err:" + err.Error()
  1005. return
  1006. }
  1007. trialTotal = total
  1008. //列表页数据
  1009. tmpList, err := models.GetIncrementalCompanyMergeList(condition, pars, startSize, pageSize)
  1010. if err != nil {
  1011. br.Msg = "获取失败"
  1012. br.ErrMsg = "获取失败,Err:" + err.Error()
  1013. return
  1014. }
  1015. if len(tmpList) > 0 {
  1016. var companyContractIds []int
  1017. for _, v := range tmpList {
  1018. companyContractIds = append(companyContractIds, v.CompanyContractId)
  1019. }
  1020. //合并合同所对应的权限
  1021. mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapById(companyContractIds)
  1022. if err != nil {
  1023. br.Msg = "获取失败"
  1024. br.ErrMsg = "获取失败,Err:" + err.Error()
  1025. return
  1026. }
  1027. for _, v := range tmpList {
  1028. item := new(statistic_report.RaiDataSummaryDetailResp)
  1029. item.CompanyId = v.CompanyId
  1030. item.CompanyName = v.CompanyName
  1031. if isServerSeller {
  1032. item.SellerName = v.ShareSellerLast
  1033. } else {
  1034. item.SellerName = v.SellerNameLast
  1035. }
  1036. item.StartDate = v.StartDate
  1037. item.EndDate = v.EndDate
  1038. item.Money = v.Money
  1039. item.PermissionName = mappermissionName[v.CompanyContractId]
  1040. listResp = append(listResp, item)
  1041. }
  1042. listGroup, err = models.GetCompanyContractGroupList(condition, pars)
  1043. if err != nil {
  1044. br.Msg = "获取失败"
  1045. br.ErrMsg = "获取失败,Err:" + err.Error()
  1046. return
  1047. }
  1048. }
  1049. case "续约率":
  1050. var conditionEnd string
  1051. var parsEnd []interface{}
  1052. if sellerId != "" {
  1053. if isServerSeller {
  1054. condition += ` AND a.share_seller_id_last IN (` + sellerId + `) `
  1055. conditionEnd += ` AND a.share_seller_id_last IN (` + sellerId + `) `
  1056. } else {
  1057. condition += ` AND a.seller_id_last IN (` + sellerId + `) `
  1058. conditionEnd += ` AND a.seller_id_last IN (` + sellerId + `) `
  1059. }
  1060. }
  1061. 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) + `) `
  1062. pars = append(pars, startDate, endDate, companyContractIdsNew)
  1063. listRaiData, err := statistic_report.GetRaiDataSummaryList(condition, pars)
  1064. if err != nil {
  1065. br.Msg = "获取数据信息失败"
  1066. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1067. return
  1068. }
  1069. //到期合同数据
  1070. conditionEnd += ` AND a.status = 1 AND a.end_date >= ? AND a.end_date <= ? AND a.end_date < ? `
  1071. parsEnd = append(parsEnd, startDate, endDate, time.Now().Format(utils.FormatDate))
  1072. listEndData, err := statistic_report.GetRaiDataSummaryList(conditionEnd, parsEnd)
  1073. if err != nil {
  1074. br.Msg = "获取数据信息失败"
  1075. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1076. return
  1077. }
  1078. var renewedContractMoney float64 // 续约金额
  1079. var renewedContractCompany float64 // 续约客户数
  1080. maprenewedContractCompany := make(map[int]bool)
  1081. var expiredContractMoney float64 //到期金额
  1082. var expiredContractCompany float64 // 到期客户数
  1083. mapexpiredContractCompany := make(map[int]bool)
  1084. for _, v := range listRaiData {
  1085. renewedContractMoney += v.Money
  1086. if !maprenewedContractCompany[v.CompanyId] {
  1087. renewedContractCompany++
  1088. maprenewedContractCompany[v.CompanyId] = true
  1089. }
  1090. //startDateTime := utils.StrDateToDate(v.StartDate)
  1091. //if startDateTime.Before(time.Now().AddDate(0, 0, -1)) { //到期合同数据
  1092. // expiredContractMoney += v.Money
  1093. // if !mapexpiredContractCompany[v.CompanyId] {
  1094. // expiredContractCompany++
  1095. // mapexpiredContractCompany[v.CompanyId] = true
  1096. // }
  1097. //}
  1098. }
  1099. for _, v := range listEndData {
  1100. expiredContractMoney += v.Money
  1101. if !mapexpiredContractCompany[v.CompanyId] {
  1102. expiredContractCompany++
  1103. mapexpiredContractCompany[v.CompanyId] = true
  1104. }
  1105. }
  1106. item := new(statistic_report.RaiDataSummaryDetailResp)
  1107. item.TbaleNameAText = "金额续约率"
  1108. item.RenewedContractMoney = fmt.Sprint(utils.SubFloatToString(renewedContractMoney, 2))
  1109. item.ExpiredContractMoney = fmt.Sprint(utils.SubFloatToString(expiredContractMoney, 2))
  1110. if renewedContractMoney == 0 || expiredContractMoney == 0 {
  1111. item.RenewalRate = "0%"
  1112. } else {
  1113. item.RenewalRate = fmt.Sprint(utils.SubFloatToString(renewedContractMoney/expiredContractMoney*100, 2), "%")
  1114. }
  1115. listResp = append(listResp, item)
  1116. item2 := new(statistic_report.RaiDataSummaryDetailResp)
  1117. item2.TbaleNameAText = "客户续约率"
  1118. item2.RenewedContractMoney = fmt.Sprint(renewedContractCompany)
  1119. item2.ExpiredContractMoney = fmt.Sprint(expiredContractCompany)
  1120. if renewedContractCompany == 0 || expiredContractCompany == 0 {
  1121. item2.RenewalRate = "0%"
  1122. } else {
  1123. item2.RenewalRate = fmt.Sprint(utils.SubFloatToString(renewedContractCompany/expiredContractCompany*100, 2), "%")
  1124. }
  1125. listResp = append(listResp, item2)
  1126. case "确认不续约合同":
  1127. noRenewedcompanyContractIds := services.GetCompanyContractNoRenewedAscribeListArr()
  1128. condition += ` AND a.company_contract_id IN (` + utils.GetOrmInReplace(len(noRenewedcompanyContractIds)) + `) ` // 已确认
  1129. pars = append(pars, noRenewedcompanyContractIds)
  1130. if sellerId != "" {
  1131. if isServerSeller {
  1132. condition += ` AND a.share_seller_id_last IN (` + sellerId + `) `
  1133. } else {
  1134. condition += ` AND a.seller_id_last IN (` + sellerId + `) `
  1135. }
  1136. }
  1137. condition += ` AND a.product_id = 2 AND a.status = 1 AND a.end_date >= ? AND a.end_date <= ? AND a.end_date <= ? `
  1138. pars = append(pars, startDate, endDate, time.Now().Format(utils.FormatDate))
  1139. total, err := company.GetIncrementalNewCompanyProductMergeCount(condition, pars)
  1140. if err != nil && err.Error() != utils.ErrNoRow() {
  1141. br.Msg = "获取失败"
  1142. br.ErrMsg = "获取失败,Err:" + err.Error()
  1143. return
  1144. }
  1145. trialTotal = total
  1146. //列表页数据
  1147. tmpList, err := models.GetIncrementalCompanyMergeList(condition, pars, startSize, pageSize)
  1148. if err != nil {
  1149. br.Msg = "获取失败"
  1150. br.ErrMsg = "获取失败,Err:" + err.Error()
  1151. return
  1152. }
  1153. if len(tmpList) > 0 {
  1154. var companyContractIds []int
  1155. for _, v := range tmpList {
  1156. companyContractIds = append(companyContractIds, v.CompanyContractId)
  1157. }
  1158. //合并合同所对应的权限
  1159. mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapById(companyContractIds)
  1160. if err != nil {
  1161. br.Msg = "获取失败"
  1162. br.ErrMsg = "获取失败,Err:" + err.Error()
  1163. return
  1164. }
  1165. for _, v := range tmpList {
  1166. item := new(statistic_report.RaiDataSummaryDetailResp)
  1167. item.CompanyId = v.CompanyId
  1168. item.CompanyName = v.CompanyName
  1169. if isServerSeller {
  1170. item.SellerName = v.ShareSellerLast
  1171. } else {
  1172. item.SellerName = v.SellerNameLast
  1173. }
  1174. item.StartDate = v.StartDate
  1175. item.EndDate = v.EndDate
  1176. item.Money = v.Money
  1177. item.PermissionName = mappermissionName[v.CompanyContractId]
  1178. listResp = append(listResp, item)
  1179. }
  1180. listGroup, err = models.GetCompanyContractGroupList(condition, pars)
  1181. if err != nil {
  1182. br.Msg = "获取失败"
  1183. br.ErrMsg = "获取失败,Err:" + err.Error()
  1184. return
  1185. }
  1186. }
  1187. case "确认不续约率":
  1188. noRenewedcompanyContractIdsMap := services.GetCompanyContractNoRenewedAscribeListMap()
  1189. var conditionEnd string
  1190. var parsEnd []interface{}
  1191. if sellerId != "" {
  1192. if isServerSeller {
  1193. condition += ` AND a.share_seller_id_last IN (` + sellerId + `) `
  1194. conditionEnd += ` AND a.share_seller_id_last IN (` + sellerId + `) `
  1195. } else {
  1196. condition += ` AND a.seller_id_last IN (` + sellerId + `) `
  1197. conditionEnd += ` AND a.seller_id_last IN (` + sellerId + `) `
  1198. }
  1199. }
  1200. condition += ` AND a.product_id = 2 AND a.status = 1 AND a.end_date >= ? AND a.end_date <= ? AND a.end_date <= ? `
  1201. pars = append(pars, startDate, endDate, time.Now().Format(utils.FormatDate))
  1202. listRaiData, err := statistic_report.GetRaiDataSummaryList(condition, pars)
  1203. if err != nil {
  1204. br.Msg = "获取数据信息失败"
  1205. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1206. return
  1207. }
  1208. conditionEnd += ` AND a.product_id = 2 AND a.status = 1 AND a.end_date >= ? AND a.end_date <= ? AND a.end_date < ? `
  1209. parsEnd = append(parsEnd, startDate, endDate, time.Now().Format(utils.FormatDate))
  1210. listEndData, err := statistic_report.GetRaiDataSummaryList(conditionEnd, parsEnd)
  1211. if err != nil {
  1212. br.Msg = "获取数据信息失败"
  1213. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1214. return
  1215. }
  1216. var norenewedContractMoney float64 // 不续约金额
  1217. var norenewedContractCompany float64 // 不续约客户数
  1218. mapnorenewedContractCompany := make(map[int]bool)
  1219. var expiredContractMoney float64 //到期金额
  1220. var expiredContractCompany float64 // 到期客户数
  1221. mapexpiredContractCompany := make(map[int]bool)
  1222. for _, v := range listRaiData {
  1223. if noRenewedcompanyContractIdsMap[v.CompanyContractId] {
  1224. norenewedContractMoney += v.Money
  1225. if !mapnorenewedContractCompany[v.CompanyId] {
  1226. norenewedContractCompany++
  1227. mapnorenewedContractCompany[v.CompanyId] = true
  1228. }
  1229. }
  1230. }
  1231. for _, v := range listEndData {
  1232. expiredContractMoney += v.Money
  1233. if !mapexpiredContractCompany[v.CompanyId] {
  1234. expiredContractCompany++
  1235. mapexpiredContractCompany[v.CompanyId] = true
  1236. }
  1237. }
  1238. item := new(statistic_report.RaiDataSummaryDetailResp)
  1239. item.TbaleNameAText = "金额不续约率"
  1240. item.RenewedContractMoney = fmt.Sprint(utils.SubFloatToString(norenewedContractMoney, 2))
  1241. item.ExpiredContractMoney = fmt.Sprint(utils.SubFloatToString(expiredContractMoney, 2))
  1242. if norenewedContractMoney == 0 || expiredContractMoney == 0 {
  1243. item.RenewalRate = "0%"
  1244. } else {
  1245. item.RenewalRate = fmt.Sprint(utils.SubFloatToString(norenewedContractMoney/expiredContractMoney*100, 2), "%")
  1246. }
  1247. listResp = append(listResp, item)
  1248. item2 := new(statistic_report.RaiDataSummaryDetailResp)
  1249. item2.TbaleNameAText = "客户不续约率"
  1250. item2.RenewedContractMoney = fmt.Sprint(norenewedContractCompany)
  1251. item2.ExpiredContractMoney = fmt.Sprint(expiredContractCompany)
  1252. if norenewedContractCompany == 0 || expiredContractCompany == 0 {
  1253. item2.RenewalRate = "0%"
  1254. } else {
  1255. item2.RenewalRate = fmt.Sprint(utils.SubFloatToString(norenewedContractCompany/expiredContractCompany*100, 2), "%")
  1256. }
  1257. listResp = append(listResp, item2)
  1258. case "签约客户数量":
  1259. var conditionInherit string
  1260. var parsInherit []interface{}
  1261. if sellerId != "" {
  1262. if isServerSeller {
  1263. condition += ` AND a.share_seller_id_init IN (` + sellerId + `) `
  1264. conditionInherit += ` AND a.share_seller_id_init IN (` + sellerId + `) `
  1265. } else {
  1266. condition += ` AND a.seller_id_init IN (` + sellerId + `) `
  1267. conditionInherit += ` AND a.seller_id_init IN (` + sellerId + `) `
  1268. }
  1269. }
  1270. condition += " AND a.product_id = 2 AND a.status = 1 AND a.start_date >= ? AND a.start_date <= ? AND a.rai_contract_type = '新签合同' "
  1271. pars = append(pars, startDate, endDate)
  1272. listRaiData, err := statistic_report.GetRaiDataSummaryList(condition, pars)
  1273. if err != nil {
  1274. br.Msg = "获取数据信息失败"
  1275. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1276. return
  1277. }
  1278. //续约部分的数据
  1279. 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) + `) `
  1280. parsInherit = append(parsInherit, startDate, endDate, companyContractIdsNew)
  1281. listInheritData, err := statistic_report.GetRaiDataSummaryInheritList(conditionInherit, parsInherit)
  1282. if err != nil {
  1283. br.Msg = "获取数据信息失败"
  1284. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1285. return
  1286. }
  1287. var renewedContractCompany int // 续约客户数
  1288. var renewedContract int // 续约合同数
  1289. maprenewedContractCompany := make(map[int]bool)
  1290. var newContractCompany int // 新签客户数
  1291. var newContract int // 新签合同数
  1292. mapenewContractCompany := make(map[int]bool)
  1293. for _, v := range listRaiData {
  1294. if v.RaiContractType == "新签合同" {
  1295. newContract++
  1296. if !mapenewContractCompany[v.CompanyId] {
  1297. newContractCompany++
  1298. mapenewContractCompany[v.CompanyId] = true
  1299. }
  1300. }
  1301. //else if v.RaiContractType == "续约合同" {
  1302. // renewedContract++
  1303. // if !maprenewedContractCompany[v.CompanyId] {
  1304. // renewedContractCompany++
  1305. // maprenewedContractCompany[v.CompanyId] = true
  1306. // }
  1307. //}
  1308. }
  1309. for _, v := range listInheritData {
  1310. renewedContract++
  1311. if !maprenewedContractCompany[v.CompanyId] {
  1312. renewedContractCompany++
  1313. maprenewedContractCompany[v.CompanyId] = true
  1314. }
  1315. }
  1316. item := new(statistic_report.RaiDataSummaryDetailResp)
  1317. item.RenewedContractCompany = renewedContractCompany
  1318. item.RenewedContract = renewedContract
  1319. item.NewContractCompany = newContractCompany
  1320. item.NewContract = newContract
  1321. listResp = append(listResp, item)
  1322. case "客单价":
  1323. //续约部分的数据
  1324. var conditionInherit string
  1325. var parsInherit []interface{}
  1326. if sellerId != "" {
  1327. if isServerSeller {
  1328. condition += ` AND a.share_seller_id_last IN (` + sellerId + `) `
  1329. conditionInherit += ` AND a.share_seller_id_last IN (` + sellerId + `) `
  1330. } else {
  1331. condition += ` AND a.seller_id_last IN (` + sellerId + `) `
  1332. conditionInherit += ` AND a.seller_id_last IN (` + sellerId + `) `
  1333. }
  1334. }
  1335. condition += " AND a.product_id = 2 AND a.status = 1 AND a.start_date >= ? AND a.start_date <= ? AND a.rai_contract_type = '新签合同' "
  1336. pars = append(pars, startDate, endDate)
  1337. listRaiData, err := statistic_report.GetRaiDataSummaryList(condition, pars)
  1338. if err != nil {
  1339. br.Msg = "获取数据信息失败"
  1340. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1341. return
  1342. }
  1343. var ontractMoney float64 // 签约总金额
  1344. var contractNum int // 签约客户数
  1345. mapCompany := make(map[int]bool)
  1346. for _, v := range listRaiData {
  1347. if v.RaiContractType != "新签合同" {
  1348. continue
  1349. }
  1350. ontractMoney += v.Money
  1351. if !mapCompany[v.CompanyId] {
  1352. contractNum++
  1353. mapCompany[v.CompanyId] = true
  1354. }
  1355. }
  1356. 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) + `) `
  1357. parsInherit = append(parsInherit, startDate, endDate, companyContractIdsNew)
  1358. listInheritData, err := statistic_report.GetRaiDataSummaryInheritList(conditionInherit, parsInherit)
  1359. if err != nil {
  1360. br.Msg = "获取数据信息失败"
  1361. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1362. return
  1363. }
  1364. for _, v := range listInheritData {
  1365. ontractMoney += v.Money
  1366. if !mapCompany[v.CompanyId] && v.RaiContractType == "续约合同" {
  1367. contractNum++
  1368. mapCompany[v.CompanyId] = true
  1369. }
  1370. }
  1371. item := new(statistic_report.RaiDataSummaryDetailResp)
  1372. item.ContractMoney = fmt.Sprint(utils.SubFloatToString(ontractMoney, 2))
  1373. item.ContractNum = contractNum
  1374. listResp = append(listResp, item)
  1375. case "开票金额":
  1376. if sellerId != "" {
  1377. condition += ` AND a.rai_seller_id IN (` + sellerId + `) `
  1378. }
  1379. condition += " AND a.is_deleted = 0 AND a.start_date >= ? AND a.start_date <= ? AND invoiced_amount > 0 AND product_ids LIKE '%2%' "
  1380. pars = append(pars, startDate, endDate)
  1381. total, err := fms.GetContractInvoiceCount(condition, pars)
  1382. if err != nil && err.Error() != utils.ErrNoRow() {
  1383. br.Msg = "获取失败"
  1384. br.ErrMsg = "获取失败,Err:" + err.Error()
  1385. return
  1386. }
  1387. trialTotal = total
  1388. listFmsData, err := fms.GetContractRegisterList(condition, pars, startSize, pageSize)
  1389. if err != nil {
  1390. br.Msg = "获取数据信息失败"
  1391. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1392. return
  1393. }
  1394. if len(listFmsData) > 0 {
  1395. var contractRegisterId []int
  1396. for _, v := range listFmsData {
  1397. contractRegisterId = append(contractRegisterId, v.ContractRegisterId)
  1398. }
  1399. lenArr := len(contractRegisterId)
  1400. var conditionFms string
  1401. var parsFms []interface{}
  1402. conditionFms += ` AND contract_register_id IN (` + utils.GetOrmInReplace(lenArr) + `) GROUP BY contract_register_id `
  1403. parsFms = append(parsFms, contractRegisterId)
  1404. listInvoiceData, err := fms.GetContractInvoiceList(conditionFms, parsFms, 0, lenArr)
  1405. if err != nil {
  1406. br.Msg = "获取数据信息失败"
  1407. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1408. return
  1409. }
  1410. mapInvoiceTime := make(map[int]string)
  1411. for _, v := range listInvoiceData {
  1412. mapInvoiceTime[v.ContractRegisterId] = v.InvoiceTime.Format(utils.FormatDate)
  1413. }
  1414. for _, v := range listFmsData {
  1415. item := new(statistic_report.RaiDataSummaryDetailResp)
  1416. item.CompanyName = v.CompanyName
  1417. item.SellerName = v.RaiSellerName
  1418. item.ContractCode = v.ContractCode
  1419. item.InvoicedAmount = v.InvoicedAmount
  1420. item.CreateTime = mapInvoiceTime[v.ContractRegisterId]
  1421. listResp = append(listResp, item)
  1422. }
  1423. }
  1424. case "到款金额":
  1425. if sellerId != "" {
  1426. condition += ` AND a.rai_seller_id IN (` + sellerId + `) `
  1427. }
  1428. condition += " AND a.is_deleted = 0 AND a.start_date >= ? AND a.start_date <= ? AND payment_amount > 0 AND product_ids LIKE '%2%' "
  1429. pars = append(pars, startDate, endDate)
  1430. total, err := fms.GetContractInvoiceCount(condition, pars)
  1431. if err != nil && err.Error() != utils.ErrNoRow() {
  1432. br.Msg = "获取失败"
  1433. br.ErrMsg = "获取失败,Err:" + err.Error()
  1434. return
  1435. }
  1436. trialTotal = total
  1437. listFmsData, err := fms.GetContractRegisterList(condition, pars, startSize, pageSize)
  1438. if err != nil {
  1439. br.Msg = "获取数据信息失败"
  1440. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1441. return
  1442. }
  1443. if len(listFmsData) > 0 {
  1444. var contractRegisterId []int
  1445. for _, v := range listFmsData {
  1446. contractRegisterId = append(contractRegisterId, v.ContractRegisterId)
  1447. }
  1448. lenArr := len(contractRegisterId)
  1449. var conditionFms string
  1450. var parsFms []interface{}
  1451. conditionFms += ` AND contract_register_id IN (` + utils.GetOrmInReplace(lenArr) + `) GROUP BY contract_register_id `
  1452. parsFms = append(parsFms, contractRegisterId)
  1453. listInvoiceData, err := fms.GetContractInvoiceList(conditionFms, parsFms, 0, lenArr)
  1454. if err != nil {
  1455. br.Msg = "获取数据信息失败"
  1456. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1457. return
  1458. }
  1459. mapInvoiceTime := make(map[int]string)
  1460. for _, v := range listInvoiceData {
  1461. mapInvoiceTime[v.ContractRegisterId] = v.InvoiceTime.Format(utils.FormatDate)
  1462. }
  1463. for _, v := range listFmsData {
  1464. item := new(statistic_report.RaiDataSummaryDetailResp)
  1465. item.CompanyName = v.CompanyName
  1466. item.SellerName = v.RaiSellerName
  1467. item.ContractCode = v.ContractCode
  1468. item.PaymentAmount = v.PaymentAmount
  1469. item.CreateTime = v.CreateTime.Format(utils.FormatDate)
  1470. listResp = append(listResp, item)
  1471. }
  1472. }
  1473. case "未到款比例":
  1474. if sellerId != "" {
  1475. condition += ` AND a.rai_seller_id IN (` + sellerId + `) `
  1476. }
  1477. condition += " AND a.is_deleted = 0 AND a.start_date >= ? AND a.start_date <= ? AND product_ids LIKE '%2%' "
  1478. pars = append(pars, startDate, endDate)
  1479. listFmsData, err := fms.GetContractRegisterAmountList(condition, pars)
  1480. if err != nil {
  1481. br.Msg = "获取数据信息失败"
  1482. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1483. return
  1484. }
  1485. for _, v := range listFmsData {
  1486. item := new(statistic_report.RaiDataSummaryDetailResp)
  1487. item.InvoicedAmount = v.InvoicedAmount
  1488. item.PaymentAmount = v.PaymentAmount
  1489. item.NotReceivedtAmount = v.InvoicedAmount - v.PaymentAmount
  1490. item.CreateTime = v.CreateTime.Format(utils.FormatDate)
  1491. listResp = append(listResp, item)
  1492. }
  1493. case "新客开票":
  1494. if sellerId != "" {
  1495. condition += ` AND a.rai_seller_id IN (` + sellerId + `) `
  1496. }
  1497. condition += " AND a.is_deleted = 0 AND contract_type = 1 AND a.start_date >= ? AND a.start_date <= ? AND product_ids LIKE '%2%' "
  1498. pars = append(pars, startDate, endDate)
  1499. total, err := fms.GetContractInvoiceCount(condition, pars)
  1500. if err != nil && err.Error() != utils.ErrNoRow() {
  1501. br.Msg = "获取失败"
  1502. br.ErrMsg = "获取失败,Err:" + err.Error()
  1503. return
  1504. }
  1505. trialTotal = total
  1506. listFmsData, err := fms.GetContractRegisterList(condition, pars, startSize, pageSize)
  1507. if err != nil {
  1508. br.Msg = "获取数据信息失败"
  1509. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1510. return
  1511. }
  1512. if len(listFmsData) > 0 {
  1513. var contractRegisterId []int
  1514. for _, v := range listFmsData {
  1515. contractRegisterId = append(contractRegisterId, v.ContractRegisterId)
  1516. }
  1517. lenArr := len(contractRegisterId)
  1518. var conditionFms string
  1519. var parsFms []interface{}
  1520. conditionFms += ` AND contract_register_id IN (` + utils.GetOrmInReplace(lenArr) + `) GROUP BY contract_register_id `
  1521. parsFms = append(parsFms, contractRegisterId)
  1522. listInvoiceData, err := fms.GetContractInvoiceList(conditionFms, parsFms, 0, lenArr)
  1523. if err != nil {
  1524. br.Msg = "获取数据信息失败"
  1525. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1526. return
  1527. }
  1528. mapInvoiceTime := make(map[int]string)
  1529. for _, v := range listInvoiceData {
  1530. mapInvoiceTime[v.ContractRegisterId] = v.InvoiceTime.Format(utils.FormatDate)
  1531. }
  1532. for _, v := range listFmsData {
  1533. item := new(statistic_report.RaiDataSummaryDetailResp)
  1534. item.CompanyName = v.CompanyName
  1535. item.SellerName = v.RaiSellerName
  1536. item.ContractCode = v.ContractCode
  1537. item.InvoicedAmount = v.InvoicedAmount
  1538. item.CreateTime = mapInvoiceTime[v.ContractRegisterId]
  1539. listResp = append(listResp, item)
  1540. }
  1541. }
  1542. case "新客到款":
  1543. if sellerId != "" {
  1544. condition += ` AND a.rai_seller_id IN (` + sellerId + `) `
  1545. }
  1546. 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%' "
  1547. pars = append(pars, startDate, endDate)
  1548. total, err := fms.GetContractInvoiceCount(condition, pars)
  1549. if err != nil && err.Error() != utils.ErrNoRow() {
  1550. br.Msg = "获取失败"
  1551. br.ErrMsg = "获取失败,Err:" + err.Error()
  1552. return
  1553. }
  1554. trialTotal = total
  1555. listFmsData, err := fms.GetContractRegisterList(condition, pars, startSize, pageSize)
  1556. if err != nil {
  1557. br.Msg = "获取数据信息失败"
  1558. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1559. return
  1560. }
  1561. if len(listFmsData) > 0 {
  1562. var contractRegisterId []int
  1563. for _, v := range listFmsData {
  1564. contractRegisterId = append(contractRegisterId, v.ContractRegisterId)
  1565. }
  1566. lenArr := len(contractRegisterId)
  1567. var conditionFms string
  1568. var parsFms []interface{}
  1569. conditionFms += ` AND contract_register_id IN (` + utils.GetOrmInReplace(lenArr) + `) GROUP BY contract_register_id `
  1570. parsFms = append(parsFms, contractRegisterId)
  1571. listInvoiceData, err := fms.GetContractInvoiceList(conditionFms, parsFms, 0, lenArr)
  1572. if err != nil {
  1573. br.Msg = "获取数据信息失败"
  1574. br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
  1575. return
  1576. }
  1577. mapInvoiceTime := make(map[int]string)
  1578. for _, v := range listInvoiceData {
  1579. mapInvoiceTime[v.ContractRegisterId] = v.InvoiceTime.Format(utils.FormatDate)
  1580. }
  1581. for _, v := range listFmsData {
  1582. item := new(statistic_report.RaiDataSummaryDetailResp)
  1583. item.CompanyName = v.CompanyName
  1584. item.SellerName = v.RaiSellerName
  1585. item.ContractCode = v.ContractCode
  1586. item.PaymentAmount = v.PaymentAmount
  1587. item.CreateTime = mapInvoiceTime[v.ContractRegisterId]
  1588. listResp = append(listResp, item)
  1589. }
  1590. }
  1591. }
  1592. if len(listResp) == 0 {
  1593. listResp = make([]*statistic_report.RaiDataSummaryDetailResp, 0)
  1594. }
  1595. if len(listGroup) > 0 {
  1596. for _, v := range listGroup {
  1597. if v.CompanyCount > 1 {
  1598. resp.CompanyMultiple++
  1599. }
  1600. }
  1601. resp.CompanyNum = len(listGroup)
  1602. }
  1603. resp.List = listResp
  1604. page := paging.GetPaging(currentIndex, pageSize, trialTotal)
  1605. resp.Paging = page
  1606. br.Ret = 200
  1607. br.Success = true
  1608. br.Msg = "获取成功"
  1609. br.Data = resp
  1610. }
  1611. // 时间筛选项的转换
  1612. func getYearStar(startDate time.Time, dataType string) (yearStr string) {
  1613. startDateTime := startDate
  1614. monthNum := startDateTime.Month()
  1615. yearStr = strconv.Itoa(startDateTime.Year())
  1616. if dataType == "季度" {
  1617. if monthNum < 4 {
  1618. yearStr += "Q1"
  1619. } else if monthNum > 3 && monthNum < 7 {
  1620. yearStr += "Q2"
  1621. } else if monthNum > 6 && monthNum < 10 {
  1622. yearStr += "Q3"
  1623. } else if monthNum > 9 {
  1624. yearStr += "Q4"
  1625. }
  1626. } else if dataType == "半年度" {
  1627. if monthNum < 7 {
  1628. yearStr += "H1"
  1629. } else {
  1630. yearStr += "H2"
  1631. }
  1632. }
  1633. return
  1634. }