rai_data_summary.go 56 KB

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