rai_data_summary.go 61 KB

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