rai_data_summary.go 62 KB

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