statistic_company_todo.go 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432
  1. package controllers
  2. import (
  3. "hongze/hz_crm_api/models"
  4. "hongze/hz_crm_api/models/roadshow"
  5. "hongze/hz_crm_api/models/system"
  6. "hongze/hz_crm_api/services"
  7. "hongze/hz_crm_api/services/statistic_report"
  8. "hongze/hz_crm_api/utils"
  9. "strconv"
  10. "strings"
  11. "time"
  12. )
  13. // TodoCompanyReport
  14. // @Title 销售Todo任务统计统计数据
  15. // @Description 获取增销售Todo任务统计统计数据接口
  16. // @Param ProductId query string true "销售类型,ficc销售:1;权益销售:2"
  17. // @Param DataType query string true "枚举值:week、month、time_interval"
  18. // @Param StartDate query string true "开始日期,格式:2022-04-06"
  19. // @Param EndDate query string true "结束日期,格式:2022-04-06"
  20. // @Success 200 {object} statistic_report.companyTodoReportRecordResp
  21. // @router /report/seller_company_todo [get]
  22. func (this *StatisticReportController) TodoCompanyReport() {
  23. br := new(models.BaseResponse).Init()
  24. defer func() {
  25. this.Data["json"] = br
  26. this.ServeJSON()
  27. }()
  28. sysUser := this.SysUser
  29. if sysUser == nil {
  30. br.Msg = "请登录"
  31. br.ErrMsg = "请登录,SysUser Is Empty"
  32. br.Ret = 408
  33. return
  34. }
  35. productId, _ := this.GetInt("ProductId")
  36. dataType := this.GetString("DataType")
  37. startDate := this.GetString("StartDate")
  38. endDate := this.GetString("EndDate")
  39. //数据处理
  40. groupTodoReportRecordList := make([]statistic_report.GroupTodoReportRecord, 0)
  41. allCompanyTodoReportRecordNum := make([]statistic_report.CompanyTodoReportRecordNum, 0)
  42. //返回参
  43. companyTodoReportRecordResp := statistic_report.CompanyTodoReportRecordResp{
  44. List: groupTodoReportRecordList,
  45. CompanyTodoReportRecordNumList: allCompanyTodoReportRecordNum,
  46. }
  47. groupId := -1
  48. dataNum := 6 //目前设置管理员可见页面为6周,销售主管和销售组长可见页面为七周
  49. switch sysUser.RoleTypeCode {
  50. case utils.ROLE_TYPE_CODE_ADMIN:
  51. case utils.ROLE_TYPE_CODE_FICC_ADMIN: //ficc管理员
  52. productId = 1
  53. case utils.ROLE_TYPE_CODE_RAI_ADMIN: //权益管理员
  54. productId = 2
  55. case utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_FICC_SELLER, utils.ROLE_TYPE_CODE_FICC_GROUP:
  56. productId = 1
  57. groupId = sysUser.GroupId
  58. //dataNum = 7
  59. case utils.ROLE_TYPE_CODE_RAI_SELLER, utils.ROLE_TYPE_CODE_RAI_GROUP:
  60. productId = 2
  61. groupId = sysUser.GroupId
  62. //dataNum = 7
  63. default:
  64. br.Ret = 200
  65. br.Success = true
  66. br.Msg = "获取成功"
  67. br.Data = companyTodoReportRecordResp
  68. return
  69. }
  70. if productId <= 0 {
  71. br.Msg = "请选择销售类型"
  72. return
  73. }
  74. if productId != 1 && productId != 2 {
  75. br.Ret = 200
  76. br.Success = true
  77. br.Msg = "获取成功"
  78. br.Data = companyTodoReportRecordResp
  79. return
  80. }
  81. nowWeekMonday := utils.GetNowWeekMonday() //本周周一
  82. firstDate := nowWeekMonday.AddDate(0, 0, -7) //上周周一
  83. var group []services.AdminGroup
  84. groupMap := make(map[int][]*roadshow.Researcher)
  85. var sellerIds string
  86. group, groupMap, sellerIds, brMsg, brErrMsg := getTodoCompanySallers(productId, groupId, sysUser, firstDate)
  87. if brMsg != "" {
  88. br.Msg = brMsg
  89. br.ErrMsg = brErrMsg
  90. return
  91. }
  92. if sellerIds == "" {
  93. br.Ret = 200
  94. br.Success = true
  95. br.Msg = "获取成功"
  96. br.Data = companyTodoReportRecordResp
  97. return
  98. }
  99. sellerIds = strings.Trim(sellerIds, ",")
  100. sellerIds = "(" + sellerIds + ")"
  101. var companyReportDataMapList []statistic_report.CompanyTodoReportDataMap
  102. var err error
  103. //获取列表
  104. switch dataType {
  105. case "week":
  106. companyReportDataMapList, err = statistic_report.GetCompanyTodoWeekDataByWeekNumV2(productId, nowWeekMonday, sellerIds, dataNum)
  107. if err != nil {
  108. br.Msg = "数据异常"
  109. br.ErrMsg = "数据异常,Err:" + err.Error()
  110. return
  111. }
  112. case "month":
  113. nowMonthFirstDay := utils.GetNowMonthFirstDay() //本月第一天
  114. companyReportDataMapList, err = statistic_report.GetCompanyTodoMonthDataByNum(productId, nowMonthFirstDay, sellerIds, dataNum)
  115. if err != nil {
  116. br.Msg = "数据异常"
  117. br.ErrMsg = "数据异常,Err:" + err.Error()
  118. return
  119. }
  120. case "time_interval":
  121. if startDate == `` || endDate == `` {
  122. br.Msg = "开始日期或结束日期不能为空"
  123. br.ErrMsg = "开始日期或结束日期不能为空,Err:" + err.Error()
  124. return
  125. }
  126. companyReportDataMapList, err = statistic_report.GetCompanyTodoTimeIntervalDataByNum(productId, startDate, endDate, sellerIds)
  127. if err != nil {
  128. br.Msg = "数据异常"
  129. br.ErrMsg = "数据异常,Err:" + err.Error()
  130. return
  131. }
  132. default:
  133. br.Ret = 200
  134. br.Success = true
  135. br.Msg = "获取成功"
  136. br.Data = companyTodoReportRecordResp
  137. return
  138. }
  139. // 统计截止日期小于等于当前时间的未完成的任务数
  140. doingExpiredDataMapList, doingExpiredIdDataMapList, err := statistic_report.GetDoingTodoExpiredNum(productId, sellerIds)
  141. if err != nil {
  142. br.Msg = "数据异常"
  143. br.ErrMsg = "数据异常,Err:" + err.Error()
  144. return
  145. }
  146. // 统计截止日期小于等于当前时间的已完成的任务数
  147. finishDataMapList, finishIdDataMapList, err := statistic_report.GetFinishTodoNum(productId, sellerIds)
  148. if err != nil {
  149. br.Msg = "数据异常"
  150. br.ErrMsg = "数据异常,Err:" + err.Error()
  151. return
  152. }
  153. // 进行中且未到截止日期的To Do任务统计的任务数
  154. doingDataMapList, doingIdDataMapList, err := statistic_report.GetDoingTodoNum(productId, sellerIds)
  155. if err != nil {
  156. br.Msg = "数据异常"
  157. br.ErrMsg = "数据异常,Err:" + err.Error()
  158. return
  159. }
  160. adminCompanyIdsMap, err := statistic_report.GetTryStatusCompanyBySellerIds(productId, sellerIds)
  161. startDateIndexList := make(map[int]string) //开始时间间隔map
  162. endDateIndexList := make(map[int]string) //结束时间间隔map
  163. //客户数汇总
  164. tmpAllAddMap := make(map[int]int)
  165. tmpAllApproveMap := make(map[int]int)
  166. //id集合汇总
  167. tmpAllDoingExpired := 0 //任务未完成数量(基于分组id)
  168. tmpAllFinish := 0 //任务已完成数量(基于分组id)
  169. tmpAllDoing := 0 //任务进行中数量(基于分组id)
  170. for _, v := range group {
  171. v.ResearcherList = groupMap[v.GroupId]
  172. tmpGroupAdminTodoReportRecord := make([]statistic_report.AdminTodoReportRecord, 0)
  173. tmpGroupCompanyTodoReportRecordNumList := make([]statistic_report.CompanyTodoReportRecordNum, 0)
  174. //数量统计
  175. tmpGroupAddMap := make(map[int]int)
  176. tmpGroupApproveMap := make(map[int]int)
  177. //数量统计(基于分组id)
  178. tmpGroupDoingExpiredMap := make(map[int]int)
  179. tmpGroupFinishMap := make(map[int]int)
  180. tmpGroupDoingMap := make(map[int]int)
  181. //id集合(不区分客户状态)
  182. tmpGroupAddIdSliceMap := make(map[int][]string)
  183. tmpGroupApproveIdSliceMap := make(map[int][]string)
  184. //id集合 string类型(不区分客户状态)
  185. tmpGroupAddIdMap := make(map[int]string)
  186. tmpGroupApproveIdMap := make(map[int]string)
  187. //id集合(基于分组id)
  188. tmpGroupDoingExpiredIdMap := make(map[int]string)
  189. tmpGroupFinishIdMap := make(map[int]string)
  190. tmpGroupDoingIdMap := make(map[int]string)
  191. for _, researcher := range groupMap[v.GroupId] {
  192. //每个区间的数据
  193. tmpCompanyTodoReportRecordNumList := make([]statistic_report.CompanyTodoReportRecordNum, 0)
  194. // 未完成任务统计
  195. tmpDoingExpiredNum := 0
  196. tmpDoingExpiredCompanyIds := ""
  197. {
  198. if num, ok := doingExpiredDataMapList[researcher.AdminId]; ok {
  199. tmpDoingExpiredNum = num
  200. if tmpCompanyIds, ok2 := doingExpiredIdDataMapList[researcher.AdminId]; ok2 {
  201. tmpDoingExpiredCompanyIds = tmpCompanyIds
  202. }
  203. }
  204. tmpGroupDoingExpiredMap[v.GroupId] += tmpDoingExpiredNum
  205. tmpAllDoingExpired += tmpDoingExpiredNum
  206. if tmpDoingExpiredCompanyIds != "" {
  207. if tmpGroupDoingExpiredIdMap[v.GroupId] != "" {
  208. tmpGroupDoingExpiredIdMap[v.GroupId] += "," + tmpDoingExpiredCompanyIds
  209. } else {
  210. tmpGroupDoingExpiredIdMap[v.GroupId] += tmpDoingExpiredCompanyIds
  211. }
  212. }
  213. }
  214. // 已完成任务统计
  215. tmpFinishNum := 0
  216. tmpFinishCompanyIds := ""
  217. {
  218. if finishNum, ok := finishDataMapList[researcher.AdminId]; ok {
  219. tmpFinishNum = finishNum
  220. if tmpCompanyIds, ok2 := finishIdDataMapList[researcher.AdminId]; ok2 {
  221. tmpFinishCompanyIds = tmpCompanyIds
  222. }
  223. }
  224. tmpGroupFinishMap[v.GroupId] += tmpFinishNum
  225. tmpAllFinish += tmpFinishNum
  226. if tmpFinishCompanyIds != "" {
  227. if tmpGroupFinishIdMap[v.GroupId] != "" {
  228. tmpGroupFinishIdMap[v.GroupId] += "," + tmpFinishCompanyIds
  229. } else {
  230. tmpGroupFinishIdMap[v.GroupId] += tmpFinishCompanyIds
  231. }
  232. }
  233. }
  234. // 进行中任务统计
  235. tmpDoingNum := 0
  236. tmpDoingCompanyIds := ""
  237. {
  238. if doingNum, ok := doingDataMapList[researcher.AdminId]; ok {
  239. tmpDoingNum = doingNum
  240. if tmpCompanyIds, ok2 := doingIdDataMapList[researcher.AdminId]; ok2 {
  241. tmpDoingCompanyIds = tmpCompanyIds
  242. }
  243. }
  244. tmpGroupDoingMap[v.GroupId] += tmpDoingNum
  245. tmpAllDoing += tmpDoingNum
  246. if tmpDoingCompanyIds != "" {
  247. if tmpGroupDoingIdMap[v.GroupId] != "" {
  248. tmpGroupDoingIdMap[v.GroupId] += "," + tmpDoingCompanyIds
  249. } else {
  250. tmpGroupDoingIdMap[v.GroupId] += tmpDoingCompanyIds
  251. }
  252. }
  253. }
  254. // 销售相关的试用客户ID
  255. tmpAdminCompanyIds := ""
  256. if ids, ok := adminCompanyIdsMap[researcher.AdminId]; ok {
  257. tmpAdminCompanyIds = ids
  258. }
  259. for index, adminData := range companyReportDataMapList {
  260. startDateIndexList[index] = adminData.StartDate
  261. endDateIndexList[index] = adminData.EndDate
  262. var tmpAddNum, tmpApproveNum int
  263. var tmpAddIdSlice, tmpApproveIdSlice []string
  264. var tmpAddId, tmpApproveId string
  265. tmpStat := adminData.Stat
  266. //试用数据
  267. if num, ok := tmpStat.AddMap[researcher.AdminId]; ok {
  268. tmpAddNum = num
  269. tmpAddIdSlice = append(tmpAddIdSlice, tmpStat.AddIdMap[researcher.AdminId])
  270. }
  271. if num, ok := tmpStat.ApproveMap[researcher.AdminId]; ok {
  272. tmpApproveNum = num
  273. tmpApproveIdSlice = append(tmpApproveIdSlice, tmpStat.ApproveIdMap[researcher.AdminId])
  274. }
  275. tmpAddId = strings.Join(tmpAddIdSlice, ",")
  276. tmpApproveId = strings.Join(tmpApproveIdSlice, ",")
  277. tmpAdminRsReportRecordNum := statistic_report.CompanyTodoReportRecordNum{
  278. AddMap: tmpAddNum,
  279. AddIdMap: tmpAddId,
  280. ApproveMap: tmpApproveNum,
  281. ApproveIdMap: tmpApproveId,
  282. StartDate: adminData.StartDate,
  283. EndDate: adminData.EndDate,
  284. }
  285. tmpCompanyTodoReportRecordNumList = append(tmpCompanyTodoReportRecordNumList, tmpAdminRsReportRecordNum)
  286. //组内数据汇总
  287. if _, ok := tmpGroupAddMap[index]; !ok {
  288. tmpGroupAddMap[index] = 0
  289. }
  290. if _, ok := tmpGroupApproveMap[index]; !ok {
  291. tmpGroupApproveMap[index] = 0
  292. }
  293. tmpGroupAddMap[index] += tmpAddNum
  294. tmpGroupApproveMap[index] += tmpApproveNum
  295. //组内数据汇总
  296. if tmpAddId != "" {
  297. tmpGroupAddIdSliceMap[index] = append(tmpGroupAddIdSliceMap[index], tmpAddId)
  298. }
  299. if tmpApproveId != "" {
  300. tmpGroupApproveIdSliceMap[index] = append(tmpGroupApproveIdSliceMap[index], tmpApproveId)
  301. }
  302. //总数据汇总
  303. if _, ok := tmpAllAddMap[index]; !ok {
  304. tmpAllAddMap[index] = 0
  305. }
  306. if _, ok := tmpAllApproveMap[index]; !ok {
  307. tmpAllApproveMap[index] = 0
  308. }
  309. tmpAllAddMap[index] += tmpAddNum
  310. tmpAllApproveMap[index] += tmpApproveNum
  311. }
  312. tmpAdminTodoReportRecord := statistic_report.AdminTodoReportRecord{
  313. Name: researcher.RealName,
  314. AdminId: researcher.AdminId,
  315. CompanyTodoReportRecordNumList: tmpCompanyTodoReportRecordNumList,
  316. DoingExpiredNum: tmpDoingExpiredNum,
  317. DoingExpiredCompanyIds: tmpDoingExpiredCompanyIds,
  318. FinishNum: tmpFinishNum,
  319. FinishCompanyIds: tmpFinishCompanyIds,
  320. DoingNum: tmpDoingNum,
  321. DoingCompanyIds: tmpDoingCompanyIds,
  322. AdminCompanyIds: tmpAdminCompanyIds,
  323. }
  324. tmpGroupAdminTodoReportRecord = append(tmpGroupAdminTodoReportRecord, tmpAdminTodoReportRecord)
  325. }
  326. for i := 0; i < len(tmpGroupAddMap); i++ {
  327. //id集合(不区分客户状态)
  328. tmpGroupAddIdMap[i] = strings.Join(tmpGroupAddIdSliceMap[i], ",")
  329. tmpGroupApproveIdMap[i] = strings.Join(tmpGroupApproveIdSliceMap[i], ",")
  330. //tmpAddIdMap := append(AddIdMap)
  331. tmpGroupCompanyTodoReportRecordNum := statistic_report.CompanyTodoReportRecordNum{
  332. AddMap: tmpGroupAddMap[i],
  333. AddIdMap: tmpGroupAddIdMap[i],
  334. ApproveMap: tmpGroupApproveMap[i],
  335. ApproveIdMap: tmpGroupApproveIdMap[i],
  336. StartDate: startDateIndexList[i],
  337. EndDate: endDateIndexList[i],
  338. }
  339. tmpGroupCompanyTodoReportRecordNumList = append(tmpGroupCompanyTodoReportRecordNumList, tmpGroupCompanyTodoReportRecordNum)
  340. }
  341. groupTodoReportRecord := statistic_report.GroupTodoReportRecord{
  342. Item: tmpGroupAdminTodoReportRecord,
  343. Name: v.GroupName,
  344. GroupId: v.GroupId,
  345. CompanyTodoReportRecordNumList: tmpGroupCompanyTodoReportRecordNumList,
  346. DoingExpiredGroupNum: tmpGroupDoingExpiredMap[v.GroupId],
  347. DoingExpiredGroupCompanyIds: tmpGroupDoingExpiredIdMap[v.GroupId],
  348. FinishNum: tmpGroupFinishMap[v.GroupId],
  349. FinishCompanyIds: tmpGroupFinishIdMap[v.GroupId],
  350. DoingNum: tmpGroupDoingMap[v.GroupId],
  351. DoingCompanyIds: tmpGroupDoingIdMap[v.GroupId],
  352. }
  353. groupTodoReportRecordList = append(groupTodoReportRecordList, groupTodoReportRecord)
  354. }
  355. //总体汇总数据
  356. for i := 0; i < len(tmpAllApproveMap); i++ {
  357. tmpGroupCompanyTodoReportRecordNum := statistic_report.CompanyTodoReportRecordNum{
  358. AddMap: tmpAllAddMap[i],
  359. //AddIdMap: tmpAllTryOutAddIdMap[i],
  360. ApproveMap: tmpAllApproveMap[i],
  361. //ApproveIdMap: tmpAllTryOutApproveIdMap[i],
  362. StartDate: startDateIndexList[i],
  363. EndDate: endDateIndexList[i],
  364. }
  365. allCompanyTodoReportRecordNum = append(allCompanyTodoReportRecordNum, tmpGroupCompanyTodoReportRecordNum)
  366. }
  367. companyTodoReportRecordResp.CompanyTodoReportRecordNumList = allCompanyTodoReportRecordNum
  368. companyTodoReportRecordResp.List = groupTodoReportRecordList
  369. companyTodoReportRecordResp.DoingExpiredAllNum = tmpAllDoingExpired
  370. companyTodoReportRecordResp.FinishAllNum = tmpAllFinish
  371. companyTodoReportRecordResp.DoingAllNum = tmpAllDoing
  372. br.Ret = 200
  373. br.Success = true
  374. br.Msg = "获取成功"
  375. br.Data = companyTodoReportRecordResp
  376. }
  377. func (this *StatisticReportController) TodoCompanyReportBak20220610174656() {
  378. br := new(models.BaseResponse).Init()
  379. defer func() {
  380. this.Data["json"] = br
  381. this.ServeJSON()
  382. }()
  383. sysUser := this.SysUser
  384. if sysUser == nil {
  385. br.Msg = "请登录"
  386. br.ErrMsg = "请登录,SysUser Is Empty"
  387. br.Ret = 408
  388. return
  389. }
  390. productId, _ := this.GetInt("ProductId")
  391. dataType := this.GetString("DataType")
  392. //startDate := this.GetString("StartDate")
  393. //endDate := this.GetString("EndDate")
  394. //数据处理
  395. groupTodoReportRecordList := make([]statistic_report.GroupTodoReportRecord, 0)
  396. allCompanyTodoReportRecordNum := make([]statistic_report.CompanyTodoReportRecordNum, 0)
  397. //返回参
  398. companyTodoReportRecordResp := statistic_report.CompanyTodoReportRecordResp{
  399. List: groupTodoReportRecordList,
  400. CompanyTodoReportRecordNumList: allCompanyTodoReportRecordNum,
  401. }
  402. groupId := -1
  403. weekNum := 6 //目前设置管理员可见页面为6周,销售主管和销售组长可见页面为七周
  404. switch sysUser.RoleTypeCode {
  405. case utils.ROLE_TYPE_CODE_ADMIN:
  406. case utils.ROLE_TYPE_CODE_FICC_ADMIN: //ficc管理员
  407. productId = 1
  408. case utils.ROLE_TYPE_CODE_RAI_ADMIN: //权益管理员
  409. productId = 2
  410. case utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_FICC_SELLER, utils.ROLE_TYPE_CODE_FICC_GROUP:
  411. productId = 1
  412. groupId = sysUser.GroupId
  413. weekNum = 7
  414. case utils.ROLE_TYPE_CODE_RAI_SELLER, utils.ROLE_TYPE_CODE_RAI_GROUP:
  415. productId = 2
  416. groupId = sysUser.GroupId
  417. weekNum = 7
  418. default:
  419. br.Ret = 200
  420. br.Success = true
  421. br.Msg = "获取成功"
  422. br.Data = companyTodoReportRecordResp
  423. return
  424. }
  425. if productId <= 0 {
  426. br.Msg = "请选择销售类型"
  427. return
  428. }
  429. if productId != 1 && productId != 2 {
  430. br.Ret = 200
  431. br.Success = true
  432. br.Msg = "获取成功"
  433. br.Data = companyTodoReportRecordResp
  434. return
  435. }
  436. nowWeekMonday := utils.GetNowWeekMonday() //本周周一
  437. firstDate := nowWeekMonday.AddDate(0, 0, -7) //上周周一
  438. var group []services.AdminGroup
  439. groupMap := make(map[int][]*roadshow.Researcher)
  440. var sellerIds string
  441. group, groupMap, sellerIds, brMsg, brErrMsg := getTodoCompanySallers(productId, groupId, sysUser, firstDate)
  442. if brMsg != "" {
  443. br.Msg = brMsg
  444. br.ErrMsg = brErrMsg
  445. return
  446. }
  447. if sellerIds == "" {
  448. br.Ret = 200
  449. br.Success = true
  450. br.Msg = "获取成功"
  451. br.Data = companyTodoReportRecordResp
  452. return
  453. }
  454. sellerIds = strings.Trim(sellerIds, ",")
  455. sellerIds = "(" + sellerIds + ")"
  456. var companyReportDataMapList []statistic_report.CompanyTodoReportDataMap
  457. var err error
  458. //获取列表
  459. switch dataType {
  460. case "week":
  461. companyReportDataMapList, err = statistic_report.GetCompanyTodoWeekDataByWeekNum(productId, nowWeekMonday, sellerIds, weekNum)
  462. if err != nil {
  463. br.Msg = "数据异常"
  464. br.ErrMsg = "数据异常,Err:" + err.Error()
  465. return
  466. }
  467. default:
  468. br.Ret = 200
  469. br.Success = true
  470. br.Msg = "获取成功"
  471. br.Data = companyTodoReportRecordResp
  472. return
  473. }
  474. // 统计截止日期小于等于当前时间的未完成的任务数
  475. doingExpiredDataMapList, doingExpiredIdDataMapList, err := statistic_report.GetDoingTodoExpiredNum(productId, sellerIds)
  476. if err != nil {
  477. br.Msg = "数据异常"
  478. br.ErrMsg = "数据异常,Err:" + err.Error()
  479. return
  480. }
  481. // 统计截止日期小于等于当前时间的已完成的任务数
  482. finishDataMapList, finishIdDataMapList, err := statistic_report.GetFinishTodoNum(productId, sellerIds)
  483. if err != nil {
  484. br.Msg = "数据异常"
  485. br.ErrMsg = "数据异常,Err:" + err.Error()
  486. return
  487. }
  488. adminCompanyIdsMap, err := statistic_report.GetTryStatusCompanyBySellerIds(productId, sellerIds)
  489. startDateIndexList := make(map[int]string) //开始时间间隔map
  490. endDateIndexList := make(map[int]string) //结束时间间隔map
  491. //客户数汇总
  492. tmpAllTryOutAddMap := make(map[int]int)
  493. tmpAllTryOutApproveMap := make(map[int]int)
  494. tmpAllFormalAddMap := make(map[int]int)
  495. tmpAllFormalApproveMap := make(map[int]int)
  496. //id集合汇总
  497. tmpAllTryOutAddIdMap := make(map[int]string)
  498. tmpAllTryOutApproveIdMap := make(map[int]string)
  499. tmpAllFormalAddIdMap := make(map[int]string)
  500. tmpAllFormalApproveIdMap := make(map[int]string)
  501. tmpAllDoingExpired := 0 //任务未完成数量(基于分组id)
  502. tmpAllFinish := 0 //任务已完成数量(基于分组id)
  503. for _, v := range group {
  504. v.ResearcherList = groupMap[v.GroupId]
  505. tmpGroupAdminTodoReportRecord := make([]statistic_report.AdminTodoReportRecord, 0)
  506. tmpGroupCompanyTodoReportRecordNumList := make([]statistic_report.CompanyTodoReportRecordNum, 0)
  507. //数量统计
  508. tmpGroupTryOutAddMap := make(map[int]int)
  509. tmpGroupTryOutApproveMap := make(map[int]int)
  510. tmpGroupFormalAddMap := make(map[int]int)
  511. tmpGroupFormalApproveMap := make(map[int]int)
  512. //数量统计(基于分组id)
  513. tmpGroupDoingExpiredMap := make(map[int]int)
  514. tmpGroupFinishMap := make(map[int]int)
  515. //id集合
  516. tmpGroupTryOutAddIdSliceMap := make(map[int][]string)
  517. tmpGroupTryOutApproveIdSliceMap := make(map[int][]string)
  518. tmpGroupFormalAddIdSliceMap := make(map[int][]string)
  519. tmpGroupFormalApproveIdSliceMap := make(map[int][]string)
  520. //id集合(不区分客户状态)
  521. tmpGroupAddIdSliceMap := make(map[int][]string)
  522. tmpGroupApproveIdSliceMap := make(map[int][]string)
  523. //id集合 string类型
  524. tmpGroupTryOutAddIdMap := make(map[int]string)
  525. tmpGroupTryOutApproveIdMap := make(map[int]string)
  526. tmpGroupFormalAddIdMap := make(map[int]string)
  527. tmpGroupFormalApproveIdMap := make(map[int]string)
  528. //id集合 string类型(不区分客户状态)
  529. tmpGroupAddIdMap := make(map[int]string)
  530. tmpGroupApproveIdMap := make(map[int]string)
  531. //id集合(基于分组id)
  532. tmpGroupDoingExpiredIdMap := make(map[int]string)
  533. tmpGroupFinishIdMap := make(map[int]string)
  534. for _, researcher := range groupMap[v.GroupId] {
  535. //每个区间的数据
  536. tmpCompanyTodoReportRecordNumList := make([]statistic_report.CompanyTodoReportRecordNum, 0)
  537. tmpDoingExpiredNum := 0
  538. tmpDoingExpiredCompanyIds := ""
  539. tmpAdminCompanyIds := ""
  540. // 未完成任务统计
  541. if num, ok := doingExpiredDataMapList[researcher.AdminId]; ok {
  542. tmpDoingExpiredNum = num
  543. if tmpCompanyIds, ok2 := doingExpiredIdDataMapList[researcher.AdminId]; ok2 {
  544. tmpDoingExpiredCompanyIds = tmpCompanyIds
  545. }
  546. }
  547. tmpGroupDoingExpiredMap[v.GroupId] += tmpDoingExpiredNum
  548. tmpAllDoingExpired += tmpDoingExpiredNum
  549. if tmpDoingExpiredCompanyIds != "" {
  550. if tmpGroupDoingExpiredIdMap[v.GroupId] != "" {
  551. tmpGroupDoingExpiredIdMap[v.GroupId] += "," + tmpDoingExpiredCompanyIds
  552. } else {
  553. tmpGroupDoingExpiredIdMap[v.GroupId] += tmpDoingExpiredCompanyIds
  554. }
  555. }
  556. // 已完成任务统计
  557. tmpFinishNum := 0
  558. tmpFinishCompanyIds := ""
  559. if finishNum, ok := finishDataMapList[researcher.AdminId]; ok {
  560. tmpFinishNum = finishNum
  561. if tmpCompanyIds, ok2 := finishIdDataMapList[researcher.AdminId]; ok2 {
  562. tmpFinishCompanyIds = tmpCompanyIds
  563. }
  564. }
  565. tmpGroupFinishMap[v.GroupId] += tmpFinishNum
  566. tmpAllFinish += tmpFinishNum
  567. if tmpFinishCompanyIds != "" {
  568. if tmpGroupFinishIdMap[v.GroupId] != "" {
  569. tmpGroupFinishIdMap[v.GroupId] += "," + tmpFinishCompanyIds
  570. } else {
  571. tmpGroupFinishIdMap[v.GroupId] += tmpFinishCompanyIds
  572. }
  573. }
  574. // 销售相关的试用客户ID
  575. if ids, ok := adminCompanyIdsMap[researcher.AdminId]; ok {
  576. tmpAdminCompanyIds = ids
  577. }
  578. for index, adminData := range companyReportDataMapList {
  579. startDateIndexList[index] = adminData.StartDate
  580. endDateIndexList[index] = adminData.EndDate
  581. var tmpTryOutAddNum, tmpTryOutApproveNum, tmpFormalAddNum, tmpFormalApproveNum int
  582. //var tmpTryOutAddIds, tmpTryOutApproveIds, tmpFormalAddIds string
  583. var tmpTryOutAddIdSlice, tmpTryOutApproveIdSlice, tmpFormalAddIdSlice, tmpFormalApproveIdSlice, tmpAddIdSlice, tmpApproveIdSlice []string
  584. var tmpTryOutAddId, tmpTryOutApproveId, tmpFormalAddId, tmpFormalApproveId, tmpAddId, tmpApproveId string
  585. tmpTryOutData := adminData.TryOut
  586. tmpFormalData := adminData.Formal
  587. //试用数据
  588. if num, ok := tmpTryOutData.AddMap[researcher.AdminId]; ok {
  589. tmpTryOutAddNum = num
  590. tmpTryOutAddIdSlice = append(tmpTryOutAddIdSlice, tmpTryOutData.AddIdMap[researcher.AdminId])
  591. tmpAddIdSlice = append(tmpAddIdSlice, tmpTryOutData.AddIdMap[researcher.AdminId])
  592. }
  593. if num, ok := tmpTryOutData.ApproveMap[researcher.AdminId]; ok {
  594. tmpTryOutApproveNum = num
  595. tmpTryOutApproveIdSlice = append(tmpTryOutApproveIdSlice, tmpTryOutData.ApproveIdMap[researcher.AdminId])
  596. tmpApproveIdSlice = append(tmpApproveIdSlice, tmpTryOutData.ApproveIdMap[researcher.AdminId])
  597. }
  598. if num, ok := tmpFormalData.AddMap[researcher.AdminId]; ok {
  599. tmpFormalAddNum = num
  600. tmpFormalAddIdSlice = append(tmpFormalAddIdSlice, tmpFormalData.AddIdMap[researcher.AdminId])
  601. tmpAddIdSlice = append(tmpAddIdSlice, tmpFormalData.AddIdMap[researcher.AdminId])
  602. }
  603. if num, ok := tmpFormalData.ApproveMap[researcher.AdminId]; ok {
  604. tmpFormalApproveNum = num
  605. tmpFormalApproveIdSlice = append(tmpFormalApproveIdSlice, tmpFormalData.ApproveIdMap[researcher.AdminId])
  606. tmpApproveIdSlice = append(tmpApproveIdSlice, tmpFormalData.ApproveIdMap[researcher.AdminId])
  607. }
  608. tmpTryOutAddId = strings.Join(tmpTryOutAddIdSlice, ",")
  609. tmpTryOutApproveId = strings.Join(tmpTryOutApproveIdSlice, ",")
  610. tmpFormalAddId = strings.Join(tmpFormalAddIdSlice, ",")
  611. tmpAddId = strings.Join(tmpAddIdSlice, ",")
  612. tmpApproveId = strings.Join(tmpApproveIdSlice, ",")
  613. tmpAdminRsReportRecordNum := statistic_report.CompanyTodoReportRecordNum{
  614. TryOutAddMap: tmpTryOutAddNum,
  615. TryOutAddIdMap: tmpTryOutAddId,
  616. TryOutApproveMap: tmpTryOutApproveNum,
  617. TryOutApproveIdMap: tmpTryOutApproveId,
  618. FormalAddMap: tmpFormalAddNum,
  619. FormalAddIdMap: tmpFormalAddId,
  620. FormalApproveMap: tmpFormalApproveNum,
  621. FormalApproveIdMap: tmpFormalApproveId,
  622. AddMap: tmpTryOutAddNum + tmpFormalAddNum,
  623. AddIdMap: tmpAddId,
  624. ApproveMap: tmpTryOutApproveNum + tmpFormalApproveNum,
  625. ApproveIdMap: tmpApproveId,
  626. StartDate: adminData.StartDate,
  627. EndDate: adminData.EndDate,
  628. }
  629. tmpCompanyTodoReportRecordNumList = append(tmpCompanyTodoReportRecordNumList, tmpAdminRsReportRecordNum)
  630. //组内数据汇总
  631. if _, ok := tmpGroupTryOutAddMap[index]; !ok {
  632. tmpGroupTryOutAddMap[index] = 0
  633. }
  634. if _, ok := tmpGroupTryOutApproveMap[index]; !ok {
  635. tmpGroupTryOutApproveMap[index] = 0
  636. }
  637. if _, ok := tmpGroupFormalAddMap[index]; !ok {
  638. tmpGroupFormalAddMap[index] = 0
  639. }
  640. if _, ok := tmpGroupFormalApproveMap[index]; !ok {
  641. tmpGroupFormalApproveMap[index] = 0
  642. }
  643. tmpGroupTryOutAddMap[index] += tmpTryOutAddNum
  644. tmpGroupTryOutApproveMap[index] += tmpTryOutApproveNum
  645. tmpGroupFormalAddMap[index] += tmpFormalAddNum
  646. tmpGroupFormalApproveMap[index] += tmpFormalApproveNum
  647. //组内数据汇总
  648. if _, ok := tmpGroupTryOutAddIdMap[index]; !ok {
  649. tmpGroupTryOutAddIdMap[index] = ""
  650. }
  651. if _, ok := tmpGroupTryOutApproveIdMap[index]; !ok {
  652. tmpGroupTryOutApproveIdMap[index] = ""
  653. }
  654. if _, ok := tmpGroupFormalAddIdMap[index]; !ok {
  655. tmpGroupFormalAddIdMap[index] = ""
  656. }
  657. if tmpTryOutAddId != "" {
  658. tmpGroupTryOutAddIdSliceMap[index] = append(tmpGroupTryOutAddIdSliceMap[index], tmpTryOutAddId)
  659. tmpGroupAddIdSliceMap[index] = append(tmpGroupAddIdSliceMap[index], tmpTryOutAddId)
  660. }
  661. if tmpTryOutApproveId != "" {
  662. tmpGroupTryOutApproveIdSliceMap[index] = append(tmpGroupTryOutApproveIdSliceMap[index], tmpTryOutApproveId)
  663. tmpGroupApproveIdSliceMap[index] = append(tmpGroupApproveIdSliceMap[index], tmpTryOutApproveId)
  664. }
  665. if tmpFormalAddId != "" {
  666. tmpGroupFormalAddIdSliceMap[index] = append(tmpGroupFormalAddIdSliceMap[index], tmpFormalAddId)
  667. tmpGroupAddIdSliceMap[index] = append(tmpGroupAddIdSliceMap[index], tmpFormalAddId)
  668. }
  669. if tmpFormalApproveId != "" {
  670. tmpGroupFormalApproveIdSliceMap[index] = append(tmpGroupFormalApproveIdSliceMap[index], tmpFormalApproveId)
  671. tmpGroupApproveIdSliceMap[index] = append(tmpGroupApproveIdSliceMap[index], tmpFormalApproveId)
  672. }
  673. //总数据汇总
  674. if _, ok := tmpAllTryOutAddMap[index]; !ok {
  675. tmpAllTryOutAddMap[index] = 0
  676. }
  677. if _, ok := tmpAllTryOutApproveMap[index]; !ok {
  678. tmpAllTryOutApproveMap[index] = 0
  679. }
  680. if _, ok := tmpAllFormalAddMap[index]; !ok {
  681. tmpAllFormalAddMap[index] = 0
  682. }
  683. if _, ok := tmpAllFormalApproveMap[index]; !ok {
  684. tmpAllFormalApproveMap[index] = 0
  685. }
  686. tmpAllTryOutAddMap[index] += tmpTryOutAddNum
  687. tmpAllTryOutApproveMap[index] += tmpTryOutApproveNum
  688. tmpAllFormalAddMap[index] += tmpFormalAddNum
  689. tmpAllFormalApproveMap[index] += tmpFormalApproveNum
  690. }
  691. tmpAdminTodoReportRecord := statistic_report.AdminTodoReportRecord{
  692. Name: researcher.RealName,
  693. AdminId: researcher.AdminId,
  694. CompanyTodoReportRecordNumList: tmpCompanyTodoReportRecordNumList,
  695. DoingExpiredNum: tmpDoingExpiredNum,
  696. DoingExpiredCompanyIds: tmpDoingExpiredCompanyIds,
  697. FinishNum: tmpFinishNum,
  698. FinishCompanyIds: tmpFinishCompanyIds,
  699. AdminCompanyIds: tmpAdminCompanyIds,
  700. }
  701. tmpGroupAdminTodoReportRecord = append(tmpGroupAdminTodoReportRecord, tmpAdminTodoReportRecord)
  702. }
  703. for i := 0; i < len(tmpGroupFormalAddMap); i++ {
  704. tmpGroupTryOutAddIdMap[i] = strings.Join(tmpGroupTryOutAddIdSliceMap[i], ",")
  705. tmpGroupTryOutApproveIdMap[i] = strings.Join(tmpGroupTryOutApproveIdSliceMap[i], ",")
  706. tmpGroupFormalAddIdMap[i] = strings.Join(tmpGroupFormalAddIdSliceMap[i], ",")
  707. tmpGroupFormalApproveIdMap[i] = strings.Join(tmpGroupFormalApproveIdSliceMap[i], ",")
  708. //id集合(不区分客户状态)
  709. tmpGroupAddIdMap[i] = strings.Join(tmpGroupAddIdSliceMap[i], ",")
  710. tmpGroupApproveIdMap[i] = strings.Join(tmpGroupApproveIdSliceMap[i], ",")
  711. //tmpAddIdMap := append(AddIdMap)
  712. tmpGroupCompanyTodoReportRecordNum := statistic_report.CompanyTodoReportRecordNum{
  713. TryOutAddMap: tmpGroupTryOutAddMap[i],
  714. TryOutAddIdMap: tmpGroupTryOutAddIdMap[i],
  715. TryOutApproveMap: tmpGroupTryOutApproveMap[i],
  716. TryOutApproveIdMap: tmpGroupTryOutApproveIdMap[i],
  717. FormalAddMap: tmpGroupFormalAddMap[i],
  718. FormalAddIdMap: tmpGroupFormalAddIdMap[i],
  719. FormalApproveMap: tmpGroupFormalApproveMap[i],
  720. FormalApproveIdMap: tmpGroupFormalApproveIdMap[i],
  721. AddMap: tmpGroupTryOutAddMap[i] + tmpGroupFormalAddMap[i],
  722. AddIdMap: tmpGroupAddIdMap[i],
  723. ApproveMap: tmpGroupTryOutApproveMap[i] + tmpGroupFormalApproveMap[i],
  724. ApproveIdMap: tmpGroupApproveIdMap[i],
  725. StartDate: startDateIndexList[i],
  726. EndDate: endDateIndexList[i],
  727. }
  728. tmpGroupCompanyTodoReportRecordNumList = append(tmpGroupCompanyTodoReportRecordNumList, tmpGroupCompanyTodoReportRecordNum)
  729. }
  730. groupTodoReportRecord := statistic_report.GroupTodoReportRecord{
  731. Item: tmpGroupAdminTodoReportRecord,
  732. Name: v.GroupName,
  733. GroupId: v.GroupId,
  734. CompanyTodoReportRecordNumList: tmpGroupCompanyTodoReportRecordNumList,
  735. DoingExpiredGroupNum: tmpGroupDoingExpiredMap[v.GroupId],
  736. DoingExpiredGroupCompanyIds: tmpGroupDoingExpiredIdMap[v.GroupId],
  737. FinishNum: tmpGroupFinishMap[v.GroupId],
  738. FinishCompanyIds: tmpGroupFinishIdMap[v.GroupId],
  739. }
  740. groupTodoReportRecordList = append(groupTodoReportRecordList, groupTodoReportRecord)
  741. }
  742. //总体汇总数据
  743. for i := 0; i < len(tmpAllTryOutApproveMap); i++ {
  744. tmpGroupCompanyTodoReportRecordNum := statistic_report.CompanyTodoReportRecordNum{
  745. TryOutAddMap: tmpAllTryOutAddMap[i],
  746. TryOutAddIdMap: tmpAllTryOutAddIdMap[i],
  747. TryOutApproveMap: tmpAllTryOutApproveMap[i],
  748. TryOutApproveIdMap: tmpAllTryOutApproveIdMap[i],
  749. FormalAddMap: tmpAllFormalAddMap[i],
  750. FormalAddIdMap: tmpAllFormalAddIdMap[i],
  751. FormalApproveMap: tmpAllFormalApproveMap[i],
  752. FormalApproveIdMap: tmpAllFormalApproveIdMap[i],
  753. AddMap: tmpAllTryOutAddMap[i] + tmpAllFormalAddMap[i],
  754. //AddIdMap: tmpAllTryOutAddIdMap[i],
  755. ApproveMap: tmpAllTryOutApproveMap[i] + tmpAllFormalApproveMap[i],
  756. //ApproveIdMap: tmpAllTryOutApproveIdMap[i],
  757. StartDate: startDateIndexList[i],
  758. EndDate: endDateIndexList[i],
  759. }
  760. allCompanyTodoReportRecordNum = append(allCompanyTodoReportRecordNum, tmpGroupCompanyTodoReportRecordNum)
  761. }
  762. companyTodoReportRecordResp.CompanyTodoReportRecordNumList = allCompanyTodoReportRecordNum
  763. companyTodoReportRecordResp.List = groupTodoReportRecordList
  764. companyTodoReportRecordResp.DoingExpiredAllNum = tmpAllDoingExpired
  765. companyTodoReportRecordResp.FinishAllNum = tmpAllFinish
  766. br.Ret = 200
  767. br.Success = true
  768. br.Msg = "获取成功"
  769. br.Data = companyTodoReportRecordResp
  770. }
  771. func (this *StatisticReportController) TodoCompanyReportBak() {
  772. br := new(models.BaseResponse).Init()
  773. defer func() {
  774. this.Data["json"] = br
  775. this.ServeJSON()
  776. }()
  777. sysUser := this.SysUser
  778. if sysUser == nil {
  779. br.Msg = "请登录"
  780. br.ErrMsg = "请登录,SysUser Is Empty"
  781. br.Ret = 408
  782. return
  783. }
  784. productId, _ := this.GetInt("ProductId")
  785. dataType := this.GetString("DataType")
  786. //startDate := this.GetString("StartDate")
  787. //endDate := this.GetString("EndDate")
  788. //数据处理
  789. groupTodoReportRecordList := make([]statistic_report.GroupTodoReportRecord, 0)
  790. allCompanyTodoReportRecordNum := make([]statistic_report.CompanyTodoReportRecordNum, 0)
  791. //返回参
  792. companyTodoReportRecordResp := statistic_report.CompanyTodoReportRecordResp{
  793. List: groupTodoReportRecordList,
  794. CompanyTodoReportRecordNumList: allCompanyTodoReportRecordNum,
  795. }
  796. groupId := -1
  797. switch sysUser.RoleTypeCode {
  798. case utils.ROLE_TYPE_CODE_ADMIN:
  799. case utils.ROLE_TYPE_CODE_FICC_ADMIN: //ficc管理员
  800. productId = 1
  801. case utils.ROLE_TYPE_CODE_RAI_ADMIN: //权益管理员
  802. productId = 2
  803. case utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_FICC_SELLER, utils.ROLE_TYPE_CODE_FICC_GROUP:
  804. productId = 1
  805. groupId = sysUser.GroupId
  806. case utils.ROLE_TYPE_CODE_RAI_SELLER, utils.ROLE_TYPE_CODE_RAI_GROUP:
  807. productId = 2
  808. groupId = sysUser.GroupId
  809. default:
  810. br.Ret = 200
  811. br.Success = true
  812. br.Msg = "获取成功"
  813. br.Data = companyTodoReportRecordResp
  814. return
  815. }
  816. if productId <= 0 {
  817. br.Msg = "请选择销售类型"
  818. return
  819. }
  820. if productId != 1 && productId != 2 {
  821. br.Ret = 200
  822. br.Success = true
  823. br.Msg = "获取成功"
  824. br.Data = companyTodoReportRecordResp
  825. return
  826. }
  827. nowWeekMonday := utils.GetNowWeekMonday() //本周周一
  828. firstDate := nowWeekMonday.AddDate(0, 0, -7) //上周周一
  829. var group []services.AdminGroup
  830. groupMap := make(map[int][]*roadshow.Researcher)
  831. var sellerIds string
  832. group, groupMap, sellerIds, brMsg, brErrMsg := getTodoCompanySallers(productId, groupId, sysUser, firstDate)
  833. if brMsg != "" {
  834. br.Msg = brMsg
  835. br.ErrMsg = brErrMsg
  836. return
  837. }
  838. if sellerIds == "" {
  839. br.Ret = 200
  840. br.Success = true
  841. br.Msg = "获取成功"
  842. br.Data = companyTodoReportRecordResp
  843. return
  844. }
  845. sellerIds = strings.Trim(sellerIds, ",")
  846. sellerIds = "(" + sellerIds + ")"
  847. var companyReportDataMapList []statistic_report.CompanyTodoReportDataMap
  848. var err error
  849. //获取列表
  850. switch dataType {
  851. case "week":
  852. companyReportDataMapList, err = statistic_report.GetCompanyTodoWeekData(productId, nowWeekMonday, sellerIds)
  853. if err != nil {
  854. br.Msg = "数据异常"
  855. br.ErrMsg = "数据异常,Err:" + err.Error()
  856. return
  857. }
  858. default:
  859. br.Ret = 200
  860. br.Success = true
  861. br.Msg = "获取成功"
  862. br.Data = companyTodoReportRecordResp
  863. return
  864. }
  865. // 统计截止日期小于等于当前时间的未完成的任务数
  866. doingExpiredDataMapList, doingExpiredIdDataMapList, err := statistic_report.GetDoingTodoExpiredNum(productId, sellerIds)
  867. if err != nil {
  868. br.Msg = "数据异常"
  869. br.ErrMsg = "数据异常,Err:" + err.Error()
  870. return
  871. }
  872. // 统计截止日期小于等于当前时间的未完成的任务数
  873. finishDataMapList, finishIdDataMapList, err := statistic_report.GetFinishTodoNum(productId, sellerIds)
  874. if err != nil {
  875. br.Msg = "数据异常"
  876. br.ErrMsg = "数据异常,Err:" + err.Error()
  877. return
  878. }
  879. adminCompanyIdsMap, err := statistic_report.GetTryStatusCompanyBySellerIds(productId, sellerIds)
  880. startDateIndexList := make(map[int]string) //开始时间间隔map
  881. endDateIndexList := make(map[int]string) //结束时间间隔map
  882. //客户数汇总
  883. tmpAllTryOutAddMap := make(map[int]int)
  884. tmpAllTryOutApproveMap := make(map[int]int)
  885. tmpAllFormalAddMap := make(map[int]int)
  886. tmpAllFormalApproveMap := make(map[int]int)
  887. //id集合汇总
  888. tmpAllTryOutAddIdMap := make(map[int]string)
  889. tmpAllTryOutApproveIdMap := make(map[int]string)
  890. tmpAllFormalAddIdMap := make(map[int]string)
  891. tmpAllFormalApproveIdMap := make(map[int]string)
  892. tmpAllDoingExpired := 0
  893. tmpAllFinish := 0
  894. for _, v := range group {
  895. v.ResearcherList = groupMap[v.GroupId]
  896. tmpGroupAdminTodoReportRecord := make([]statistic_report.AdminTodoReportRecord, 0)
  897. tmpGroupCompanyTodoReportRecordNumList := make([]statistic_report.CompanyTodoReportRecordNum, 0)
  898. //数量统计
  899. tmpGroupTryOutAddMap := make(map[int]int)
  900. tmpGroupTryOutApproveMap := make(map[int]int)
  901. tmpGroupFormalAddMap := make(map[int]int)
  902. tmpGroupFormalApproveMap := make(map[int]int)
  903. tmpGroupDoingExpiredMap := make(map[int]int)
  904. tmpGroupFinishMap := make(map[int]int)
  905. //id集合
  906. tmpGroupTryOutAddIdSliceMap := make(map[int][]string)
  907. tmpGroupTryOutApproveIdSliceMap := make(map[int][]string)
  908. tmpGroupFormalAddIdSliceMap := make(map[int][]string)
  909. tmpGroupFormalApproveIdSliceMap := make(map[int][]string)
  910. //id集合
  911. tmpGroupTryOutAddIdMap := make(map[int]string)
  912. tmpGroupTryOutApproveIdMap := make(map[int]string)
  913. tmpGroupFormalAddIdMap := make(map[int]string)
  914. tmpGroupFormalApproveIdMap := make(map[int]string)
  915. tmpGroupDoingExpiredIdMap := make(map[int]string)
  916. tmpGroupFinishIdMap := make(map[int]string)
  917. for _, researcher := range groupMap[v.GroupId] {
  918. //每个区间的数据
  919. tmpCompanyTodoReportRecordNumList := make([]statistic_report.CompanyTodoReportRecordNum, 0)
  920. tmpDoingExpiredNum := 0
  921. tmpDoingExpiredCompanyIds := ""
  922. tmpAdminCompanyIds := ""
  923. // 未完成任务统计
  924. if num, ok := doingExpiredDataMapList[researcher.AdminId]; ok {
  925. tmpDoingExpiredNum = num
  926. if tmpCompanyIds, ok2 := doingExpiredIdDataMapList[researcher.AdminId]; ok2 {
  927. tmpDoingExpiredCompanyIds = tmpCompanyIds
  928. }
  929. }
  930. tmpGroupDoingExpiredMap[v.GroupId] += tmpDoingExpiredNum
  931. tmpAllDoingExpired += tmpDoingExpiredNum
  932. if tmpDoingExpiredCompanyIds != "" {
  933. if tmpGroupDoingExpiredIdMap[v.GroupId] != "" {
  934. tmpGroupDoingExpiredIdMap[v.GroupId] += "," + tmpDoingExpiredCompanyIds
  935. } else {
  936. tmpGroupDoingExpiredIdMap[v.GroupId] += tmpDoingExpiredCompanyIds
  937. }
  938. }
  939. // 已完成任务统计
  940. tmpFinishNum := 0
  941. tmpFinishCompanyIds := ""
  942. if finishNum, ok := finishDataMapList[researcher.AdminId]; ok {
  943. tmpFinishNum = finishNum
  944. if tmpCompanyIds, ok2 := finishIdDataMapList[researcher.AdminId]; ok2 {
  945. tmpFinishCompanyIds = tmpCompanyIds
  946. }
  947. }
  948. tmpGroupFinishMap[v.GroupId] += tmpFinishNum
  949. tmpAllFinish += tmpFinishNum
  950. if tmpFinishCompanyIds != "" {
  951. if tmpGroupFinishIdMap[v.GroupId] != "" {
  952. tmpGroupFinishIdMap[v.GroupId] += "," + tmpFinishCompanyIds
  953. } else {
  954. tmpGroupFinishIdMap[v.GroupId] += tmpFinishCompanyIds
  955. }
  956. }
  957. // 销售相关的试用客户ID
  958. if ids, ok := adminCompanyIdsMap[researcher.AdminId]; ok {
  959. tmpAdminCompanyIds = ids
  960. }
  961. for index, adminData := range companyReportDataMapList {
  962. startDateIndexList[index] = adminData.StartDate
  963. endDateIndexList[index] = adminData.EndDate
  964. var tmpTryOutAddNum, tmpTryOutApproveNum, tmpFormalAddNum, tmpFormalApproveNum int
  965. //var tmpTryOutAddIds, tmpTryOutApproveIds, tmpFormalAddIds string
  966. var tmpTryOutAddIdSlice, tmpTryOutApproveIdSlice, tmpFormalAddIdSlice, tmpFormalApproveIdSlice []string
  967. var tmpTryOutAddId, tmpTryOutApproveId, tmpFormalAddId, tmpFormalApproveId string
  968. tmpTryOutData := adminData.TryOut
  969. tmpFormalData := adminData.Formal
  970. //试用数据
  971. if num, ok := tmpTryOutData.AddMap[researcher.AdminId]; ok {
  972. tmpTryOutAddNum = num
  973. tmpTryOutAddIdSlice = append(tmpTryOutAddIdSlice, tmpTryOutData.AddIdMap[researcher.AdminId])
  974. tmpTryOutAddId = strings.Join(tmpTryOutAddIdSlice, ",")
  975. }
  976. if num, ok := tmpTryOutData.ApproveMap[researcher.AdminId]; ok {
  977. tmpTryOutApproveNum = num
  978. tmpTryOutApproveIdSlice = append(tmpTryOutApproveIdSlice, tmpTryOutData.ApproveIdMap[researcher.AdminId])
  979. tmpTryOutApproveId = strings.Join(tmpTryOutApproveIdSlice, ",")
  980. }
  981. if num, ok := tmpFormalData.AddMap[researcher.AdminId]; ok {
  982. tmpFormalAddNum = num
  983. tmpFormalAddIdSlice = append(tmpFormalAddIdSlice, tmpFormalData.AddIdMap[researcher.AdminId])
  984. tmpFormalAddId = strings.Join(tmpFormalAddIdSlice, ",")
  985. }
  986. if num, ok := tmpFormalData.ApproveMap[researcher.AdminId]; ok {
  987. tmpFormalApproveNum = num
  988. tmpFormalApproveIdSlice = append(tmpFormalApproveIdSlice, tmpFormalData.ApproveIdMap[researcher.AdminId])
  989. tmpFormalApproveId = strings.Join(tmpFormalApproveIdSlice, ",")
  990. }
  991. tmpAdminRsReportRecordNum := statistic_report.CompanyTodoReportRecordNum{
  992. TryOutAddMap: tmpTryOutAddNum,
  993. TryOutAddIdMap: tmpTryOutAddId,
  994. TryOutApproveMap: tmpTryOutApproveNum,
  995. TryOutApproveIdMap: tmpTryOutApproveId,
  996. FormalAddMap: tmpFormalAddNum,
  997. FormalAddIdMap: tmpFormalAddId,
  998. FormalApproveMap: tmpFormalApproveNum,
  999. FormalApproveIdMap: tmpFormalApproveId,
  1000. StartDate: adminData.StartDate,
  1001. EndDate: adminData.EndDate,
  1002. }
  1003. tmpCompanyTodoReportRecordNumList = append(tmpCompanyTodoReportRecordNumList, tmpAdminRsReportRecordNum)
  1004. //组内数据汇总
  1005. if _, ok := tmpGroupTryOutAddMap[index]; !ok {
  1006. tmpGroupTryOutAddMap[index] = 0
  1007. }
  1008. if _, ok := tmpGroupTryOutApproveMap[index]; !ok {
  1009. tmpGroupTryOutApproveMap[index] = 0
  1010. }
  1011. if _, ok := tmpGroupFormalAddMap[index]; !ok {
  1012. tmpGroupFormalAddMap[index] = 0
  1013. }
  1014. if _, ok := tmpGroupFormalApproveMap[index]; !ok {
  1015. tmpGroupFormalApproveMap[index] = 0
  1016. }
  1017. tmpGroupTryOutAddMap[index] += tmpTryOutAddNum
  1018. tmpGroupTryOutApproveMap[index] += tmpTryOutApproveNum
  1019. tmpGroupFormalAddMap[index] += tmpFormalAddNum
  1020. tmpGroupFormalApproveMap[index] += tmpFormalApproveNum
  1021. //组内数据汇总
  1022. if _, ok := tmpGroupTryOutAddIdMap[index]; !ok {
  1023. tmpGroupTryOutAddIdMap[index] = ""
  1024. }
  1025. if _, ok := tmpGroupTryOutApproveIdMap[index]; !ok {
  1026. tmpGroupTryOutApproveIdMap[index] = ""
  1027. }
  1028. if _, ok := tmpGroupFormalAddIdMap[index]; !ok {
  1029. tmpGroupFormalAddIdMap[index] = ""
  1030. }
  1031. if tmpTryOutAddId != "" {
  1032. tmpGroupTryOutAddIdSliceMap[index] = append(tmpGroupTryOutAddIdSliceMap[index], tmpTryOutAddId)
  1033. }
  1034. if tmpTryOutApproveId != "" {
  1035. tmpGroupTryOutApproveIdSliceMap[index] = append(tmpGroupTryOutApproveIdSliceMap[index], tmpTryOutApproveId)
  1036. }
  1037. if tmpFormalAddId != "" {
  1038. tmpGroupFormalAddIdSliceMap[index] = append(tmpGroupFormalAddIdSliceMap[index], tmpFormalAddId)
  1039. }
  1040. if tmpFormalApproveId != "" {
  1041. tmpGroupFormalApproveIdSliceMap[index] = append(tmpGroupFormalApproveIdSliceMap[index], tmpFormalApproveId)
  1042. }
  1043. //总数据汇总
  1044. if _, ok := tmpAllTryOutAddMap[index]; !ok {
  1045. tmpAllTryOutAddMap[index] = 0
  1046. }
  1047. if _, ok := tmpAllTryOutApproveMap[index]; !ok {
  1048. tmpAllTryOutApproveMap[index] = 0
  1049. }
  1050. if _, ok := tmpAllFormalAddMap[index]; !ok {
  1051. tmpAllFormalAddMap[index] = 0
  1052. }
  1053. if _, ok := tmpAllFormalApproveMap[index]; !ok {
  1054. tmpAllFormalApproveMap[index] = 0
  1055. }
  1056. tmpAllTryOutAddMap[index] += tmpTryOutAddNum
  1057. tmpAllTryOutApproveMap[index] += tmpTryOutApproveNum
  1058. tmpAllFormalAddMap[index] += tmpFormalAddNum
  1059. tmpAllFormalApproveMap[index] += tmpFormalApproveNum
  1060. }
  1061. tmpAdminTodoReportRecord := statistic_report.AdminTodoReportRecord{
  1062. Name: researcher.RealName,
  1063. AdminId: researcher.AdminId,
  1064. CompanyTodoReportRecordNumList: tmpCompanyTodoReportRecordNumList,
  1065. DoingExpiredNum: tmpDoingExpiredNum,
  1066. DoingExpiredCompanyIds: tmpDoingExpiredCompanyIds,
  1067. FinishNum: tmpFinishNum,
  1068. FinishCompanyIds: tmpFinishCompanyIds,
  1069. AdminCompanyIds: tmpAdminCompanyIds,
  1070. }
  1071. tmpGroupAdminTodoReportRecord = append(tmpGroupAdminTodoReportRecord, tmpAdminTodoReportRecord)
  1072. }
  1073. for i := 0; i < len(tmpGroupFormalAddMap); i++ {
  1074. tmpGroupTryOutAddIdMap[i] = strings.Join(tmpGroupTryOutAddIdSliceMap[i], ",")
  1075. tmpGroupTryOutApproveIdMap[i] = strings.Join(tmpGroupTryOutApproveIdSliceMap[i], ",")
  1076. tmpGroupFormalAddIdMap[i] = strings.Join(tmpGroupFormalAddIdSliceMap[i], ",")
  1077. tmpGroupFormalApproveIdMap[i] = strings.Join(tmpGroupFormalApproveIdSliceMap[i], ",")
  1078. tmpGroupCompanyTodoReportRecordNum := statistic_report.CompanyTodoReportRecordNum{
  1079. TryOutAddMap: tmpGroupTryOutAddMap[i],
  1080. TryOutAddIdMap: tmpGroupTryOutAddIdMap[i],
  1081. TryOutApproveMap: tmpGroupTryOutApproveMap[i],
  1082. TryOutApproveIdMap: tmpGroupTryOutApproveIdMap[i],
  1083. FormalAddMap: tmpGroupFormalAddMap[i],
  1084. FormalAddIdMap: tmpGroupFormalAddIdMap[i],
  1085. FormalApproveMap: tmpGroupFormalApproveMap[i],
  1086. FormalApproveIdMap: tmpGroupFormalApproveIdMap[i],
  1087. StartDate: startDateIndexList[i],
  1088. EndDate: endDateIndexList[i],
  1089. }
  1090. tmpGroupCompanyTodoReportRecordNumList = append(tmpGroupCompanyTodoReportRecordNumList, tmpGroupCompanyTodoReportRecordNum)
  1091. }
  1092. groupTodoReportRecord := statistic_report.GroupTodoReportRecord{
  1093. Item: tmpGroupAdminTodoReportRecord,
  1094. Name: v.GroupName,
  1095. GroupId: v.GroupId,
  1096. CompanyTodoReportRecordNumList: tmpGroupCompanyTodoReportRecordNumList,
  1097. DoingExpiredGroupNum: tmpGroupDoingExpiredMap[v.GroupId],
  1098. DoingExpiredGroupCompanyIds: tmpGroupDoingExpiredIdMap[v.GroupId],
  1099. }
  1100. groupTodoReportRecordList = append(groupTodoReportRecordList, groupTodoReportRecord)
  1101. }
  1102. //总体汇总数据
  1103. for i := 0; i < len(tmpAllTryOutApproveMap); i++ {
  1104. tmpGroupCompanyTodoReportRecordNum := statistic_report.CompanyTodoReportRecordNum{
  1105. TryOutAddMap: tmpAllTryOutAddMap[i],
  1106. TryOutAddIdMap: tmpAllTryOutAddIdMap[i],
  1107. TryOutApproveMap: tmpAllTryOutApproveMap[i],
  1108. TryOutApproveIdMap: tmpAllTryOutApproveIdMap[i],
  1109. FormalAddMap: tmpAllFormalAddMap[i],
  1110. FormalAddIdMap: tmpAllFormalAddIdMap[i],
  1111. FormalApproveMap: tmpAllFormalApproveMap[i],
  1112. FormalApproveIdMap: tmpAllFormalApproveIdMap[i],
  1113. StartDate: startDateIndexList[i],
  1114. EndDate: endDateIndexList[i],
  1115. }
  1116. allCompanyTodoReportRecordNum = append(allCompanyTodoReportRecordNum, tmpGroupCompanyTodoReportRecordNum)
  1117. }
  1118. companyTodoReportRecordResp.CompanyTodoReportRecordNumList = allCompanyTodoReportRecordNum
  1119. companyTodoReportRecordResp.List = groupTodoReportRecordList
  1120. companyTodoReportRecordResp.DoingExpiredAllNum = tmpAllDoingExpired
  1121. companyTodoReportRecordResp.FinishAllNum = tmpAllFinish
  1122. br.Ret = 200
  1123. br.Success = true
  1124. br.Msg = "获取成功"
  1125. br.Data = companyTodoReportRecordResp
  1126. }
  1127. // 获取销售to-do统计的销售员
  1128. func getTodoCompanySallers(productId int, groupId int, sysUser *system.Admin, firstDate time.Time) (group []services.AdminGroup, groupMap map[int][]*roadshow.Researcher, sellerIds string, brMsg, brErrMsg string) {
  1129. var groupIdRelationMap map[int]int
  1130. var researcherList []*roadshow.Researcher
  1131. var err error
  1132. groupMap = make(map[int][]*roadshow.Researcher)
  1133. //获取销售人员分组数据
  1134. if productId == 1 { //ficc
  1135. if groupId > 0 { //ficc 只查某个组相关的销售
  1136. findItem := &roadshow.Researcher{
  1137. AdminId: sysUser.AdminId,
  1138. RealName: sysUser.RealName,
  1139. GroupId: sysUser.GroupId,
  1140. GroupName: sysUser.GroupName,
  1141. RoleTypeCode: sysUser.RoleTypeCode,
  1142. }
  1143. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER { //销售,只查自己的客户
  1144. var findItems []*roadshow.Researcher
  1145. findItems = append(findItems, findItem)
  1146. groupMap[sysUser.GroupId] = findItems
  1147. sellerIds = strconv.Itoa(sysUser.AdminId)
  1148. //处理group
  1149. adminGroup := services.AdminGroup{
  1150. GroupId: sysUser.GroupId,
  1151. GroupName: sysUser.GroupName,
  1152. ResearcherList: findItems,
  1153. }
  1154. group = append(group, adminGroup)
  1155. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM { //销售组长只查本组员和本人
  1156. roleTypeCode := "('ficc_seller')"
  1157. groupIds := "(" + strconv.Itoa(groupId) + ")"
  1158. researcherList, err = roadshow.GetSellerList(roleTypeCode, groupIds)
  1159. if err != nil {
  1160. brMsg = "获取销售失败!"
  1161. brErrMsg = "获取销售失败!Err:" + err.Error()
  1162. return
  1163. }
  1164. researcherList = append(researcherList, findItem)
  1165. for _, v := range researcherList {
  1166. sellerIds += "," + strconv.Itoa(v.AdminId)
  1167. }
  1168. groupMap[sysUser.GroupId] = researcherList
  1169. //处理group
  1170. adminGroup := services.AdminGroup{
  1171. GroupId: sysUser.GroupId,
  1172. GroupName: sysUser.GroupName,
  1173. ResearcherList: researcherList,
  1174. }
  1175. group = append(group, adminGroup)
  1176. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP { //如果主管在三级小组里,查找到归属的二级分组
  1177. groupIds := ""
  1178. groupIdsSlice, err := services.GetFiccSystemGroupIdsByGroupId(sysUser.GroupId)
  1179. if err != nil {
  1180. brMsg = "获取销售失败!"
  1181. brErrMsg = "获取销售失败!Err:" + err.Error()
  1182. return
  1183. }
  1184. for _, v := range groupIdsSlice {
  1185. groupIds += "," + strconv.Itoa(v)
  1186. }
  1187. groupIds = strings.Trim(groupIds, ",")
  1188. groupIds = "(" + groupIds + ")"
  1189. roleTypeCode := "('ficc_seller','ficc_team')"
  1190. researcherList, err = roadshow.GetSellerList(roleTypeCode, groupIds)
  1191. if err != nil {
  1192. brMsg = "获取销售失败!"
  1193. brErrMsg = "获取销售失败!Err:" + err.Error()
  1194. return
  1195. }
  1196. researcherList = append(researcherList, findItem)
  1197. for _, v := range researcherList {
  1198. sellerIds += "," + strconv.Itoa(v.AdminId)
  1199. }
  1200. groupMap[sysUser.GroupId] = researcherList
  1201. //处理group
  1202. adminGroup := services.AdminGroup{
  1203. GroupId: sysUser.GroupId,
  1204. GroupName: sysUser.GroupName,
  1205. ResearcherList: researcherList,
  1206. }
  1207. group = append(group, adminGroup)
  1208. }
  1209. } else {
  1210. group, groupIdRelationMap, err = services.GetFiccSystemGroup()
  1211. if err != nil {
  1212. brMsg = "获取信息失败!"
  1213. brErrMsg = "获取分组信息失败!Err:" + err.Error()
  1214. return
  1215. }
  1216. researcherList, err = services.GetFiccSeller(firstDate, groupIdRelationMap)
  1217. for _, v := range researcherList {
  1218. if v.RoleTypeCode == "ficc_admin" {
  1219. findItems := groupMap[1]
  1220. findItems = append(findItems, v)
  1221. groupMap[1] = findItems
  1222. } else {
  1223. if findItems, ok := groupMap[v.GroupId]; ok {
  1224. findItems = append(findItems, v)
  1225. groupMap[v.GroupId] = findItems
  1226. } else {
  1227. findItems = append(findItems, v)
  1228. groupMap[v.GroupId] = findItems
  1229. }
  1230. }
  1231. sellerIds += "," + strconv.Itoa(v.AdminId)
  1232. }
  1233. }
  1234. } else if productId == 2 { //权益
  1235. if groupId > 0 {
  1236. findItem := &roadshow.Researcher{
  1237. AdminId: sysUser.AdminId,
  1238. RealName: sysUser.RealName,
  1239. GroupId: sysUser.GroupId,
  1240. GroupName: sysUser.GroupName,
  1241. RoleTypeCode: sysUser.RoleTypeCode,
  1242. }
  1243. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER { //销售,只查自己的客户
  1244. var findItems []*roadshow.Researcher
  1245. findItems = append(findItems, findItem)
  1246. groupMap[sysUser.GroupId] = findItems
  1247. sellerIds = strconv.Itoa(sysUser.AdminId)
  1248. //处理group
  1249. adminGroup := services.AdminGroup{
  1250. GroupId: sysUser.GroupId,
  1251. GroupName: sysUser.GroupName,
  1252. ResearcherList: findItems,
  1253. }
  1254. group = append(group, adminGroup)
  1255. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  1256. roleTypeCode := "('rai_seller')"
  1257. groupIds := "(" + strconv.Itoa(groupId) + ")"
  1258. researcherList, err = roadshow.GetRaiSellerList(roleTypeCode, groupIds)
  1259. if err != nil {
  1260. brMsg = "获取销售失败!"
  1261. brErrMsg = "获取销售失败!Err:" + err.Error()
  1262. return
  1263. }
  1264. researcherList = append(researcherList, findItem)
  1265. for _, v := range researcherList {
  1266. sellerIds += "," + strconv.Itoa(v.AdminId)
  1267. }
  1268. groupMap[sysUser.GroupId] = researcherList
  1269. //处理group
  1270. adminGroup := services.AdminGroup{
  1271. GroupId: sysUser.GroupId,
  1272. GroupName: sysUser.GroupName,
  1273. ResearcherList: researcherList,
  1274. }
  1275. group = append(group, adminGroup)
  1276. }
  1277. } else {
  1278. group, groupIdRelationMap, err = services.GetRaiSystemGroup()
  1279. if err != nil {
  1280. brMsg = "获取信息失败!"
  1281. brErrMsg = "获取分组信息失败!Err:" + err.Error()
  1282. return
  1283. }
  1284. researcherList, err = services.GetRaiSeller(groupIdRelationMap)
  1285. for _, v := range researcherList {
  1286. if v.RoleTypeCode == "rai_admin" {
  1287. findItems := groupMap[1]
  1288. findItems = append(findItems, v)
  1289. groupMap[1] = findItems
  1290. } else {
  1291. if findItems, ok := groupMap[v.GroupId]; ok {
  1292. findItems = append(findItems, v)
  1293. groupMap[v.GroupId] = findItems
  1294. } else {
  1295. findItems = append(findItems, v)
  1296. groupMap[v.GroupId] = findItems
  1297. }
  1298. }
  1299. sellerIds += "," + strconv.Itoa(v.AdminId)
  1300. }
  1301. }
  1302. }
  1303. return
  1304. }