rai_data_summary.go 61 KB

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