company_seller.go 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858
  1. package controllers
  2. import (
  3. "eta/eta_api/models"
  4. "eta/eta_api/models/company"
  5. "eta/eta_api/models/system"
  6. "eta/eta_api/services"
  7. "eta/eta_api/utils"
  8. "fmt"
  9. "strconv"
  10. )
  11. // CompanySellerController 销售管理
  12. type CompanySellerController struct {
  13. BaseAuthController
  14. }
  15. // CheckListV2
  16. // @Title 获取组长/组员下销售(根据部门、分组)
  17. // @Description 获取组长/组员下销售(根据部门、分组)接口
  18. // @Param AllSeller query bool true "是否获取部门所有的销售信息"
  19. // @Param Status query int true "客户状态 1:流失 0:非流失"
  20. // @Param AllEnabled query bool true "是否获取包含禁用的用户"
  21. // @Success 200 {object} company.DepartmentGroupSellersResp
  22. // @router /seller/check/listV2 [get]
  23. func (this *CompanySellerController) CheckListV2() {
  24. br := new(models.BaseResponse).Init()
  25. defer func() {
  26. this.Data["json"] = br
  27. this.ServeJSON()
  28. }()
  29. sysUser := this.SysUser
  30. if sysUser == nil {
  31. br.Msg = "请登录"
  32. br.ErrMsg = "请登录,SysUser Is Empty"
  33. br.Ret = 408
  34. return
  35. }
  36. roleCodeTypeStr := ``
  37. productId := services.GetProductId(sysUser.RoleTypeCode)
  38. switch productId {
  39. case 1:
  40. roleCodeTypeStr = `"` + utils.ROLE_TYPE_CODE_FICC_SELLER + `","` + utils.ROLE_TYPE_CODE_FICC_GROUP + `","` + utils.ROLE_TYPE_CODE_FICC_TEAM + `"`
  41. case 2:
  42. roleCodeTypeStr = `"` + utils.ROLE_TYPE_CODE_RAI_SELLER + `","` + utils.ROLE_TYPE_CODE_RAI_GROUP + `"`
  43. }
  44. // ficc管理员,不要只查销售
  45. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  46. roleCodeTypeStr = ``
  47. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  48. // 权益管理员,查看所有权益的账号
  49. roleCodeTypeStr = `"` + utils.ROLE_TYPE_CODE_RAI_SELLER + `","` + utils.ROLE_TYPE_CODE_RAI_GROUP + `","` + utils.ROLE_TYPE_CODE_RAI_RESEARCHR + `","` + utils.ROLE_TYPE_CODE_RAI_ADMIN + `"`
  50. }
  51. getAllSeller, _ := this.GetBool("AllSeller", false)
  52. status, _ := this.GetInt("Status", 0)
  53. getAllEnabled, _ := this.GetBool("AllEnabled", false)
  54. enabled := 1 //默认只获取正常状态的用户
  55. if getAllEnabled { //获取所有状态的用户
  56. enabled = -1
  57. }
  58. list := make([]company.DepartmentGroupSellers, 0)
  59. if getAllSeller == false {
  60. //超管看部门、小组、销售
  61. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  62. departmentList, err := system.GetDepartmentList()
  63. if err != nil {
  64. br.Msg = "获取失败"
  65. br.ErrMsg = "获取部门失败,Err:" + err.Error()
  66. return
  67. }
  68. for _, department := range departmentList {
  69. departmentGroupSellerList := make([]company.DepartmentGroupSellers, 0)
  70. item := company.DepartmentGroupSellers{
  71. AdminId: fmt.Sprint("department_", department.DepartmentId),
  72. //AdminName string `description:"系统用户名称"`
  73. RealName: department.DepartmentName,
  74. ChildrenList: departmentGroupSellerList,
  75. }
  76. groupList, err := system.GetSysGroupByDepartmentId(department.DepartmentId)
  77. if err != nil {
  78. br.Msg = "获取失败"
  79. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  80. return
  81. }
  82. for _, group := range groupList {
  83. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  84. groupItem := company.DepartmentGroupSellers{
  85. AdminId: fmt.Sprint("group_", group.DepartmentId),
  86. //AdminName string `description:"系统用户名称"`
  87. RealName: group.GroupName,
  88. ChildrenList: groupSellerList,
  89. }
  90. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  91. if err != nil {
  92. br.Msg = "获取小组失败"
  93. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  94. return
  95. }
  96. for _, team := range teamList {
  97. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  98. teamItem := company.DepartmentGroupSellers{
  99. AdminId: fmt.Sprint("team_", team.GroupId),
  100. //AdminName string `description:"系统用户名称"`
  101. RealName: team.GroupName,
  102. ChildrenList: teamSellerList,
  103. }
  104. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  105. if err != nil {
  106. br.Msg = "获取销售失败"
  107. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  108. return
  109. }
  110. for _, seller := range sellerList {
  111. sellerItem := company.DepartmentGroupSellers{
  112. AdminId: fmt.Sprint(seller.AdminId),
  113. //AdminName string `description:"系统用户名称"`
  114. RealName: seller.RealName,
  115. Authority: seller.Authority,
  116. RoleTypeCode: seller.RoleTypeCode,
  117. }
  118. //fmt.Println("seller.RealName:", seller.RealName)
  119. teamSellerList = append(teamSellerList, sellerItem)
  120. }
  121. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  122. teamItem.ChildrenList = teamSellerList
  123. if len(teamSellerList) > 0 {
  124. groupSellerList = append(groupSellerList, teamItem)
  125. }
  126. }
  127. //分组为0的销售(直属分组)
  128. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  129. if err != nil {
  130. br.Msg = "获取销售失败"
  131. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  132. return
  133. }
  134. if len(groupTeamSellerList) > 0 {
  135. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  136. for _, seller := range groupTeamSellerList {
  137. sellerItem := company.DepartmentGroupSellers{
  138. AdminId: fmt.Sprint(seller.AdminId),
  139. //AdminName string `description:"系统用户名称"`
  140. RealName: seller.RealName,
  141. Authority: seller.Authority,
  142. RoleTypeCode: seller.RoleTypeCode,
  143. }
  144. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  145. }
  146. //排个序
  147. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  148. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  149. }
  150. //groupItem.ChildrenList = groupSellerList
  151. //if len(groupSellerList) > 0 {
  152. // list = append(list, item)
  153. //}
  154. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  155. //if err != nil {
  156. // br.Msg = "获取销售失败"
  157. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  158. // return
  159. //}
  160. //for _, seller := range sellerList {
  161. // sellerItem := company.DepartmentGroupSellers{
  162. // AdminId: fmt.Sprint(seller.AdminId),
  163. // //AdminName string `description:"系统用户名称"`
  164. // RealName: seller.RealName,
  165. // Authority: seller.Authority,
  166. // RoleTypeCode: seller.RoleTypeCode,
  167. // }
  168. // groupSellerList = append(groupSellerList, sellerItem)
  169. //}
  170. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  171. groupItem.ChildrenList = groupSellerList
  172. if len(groupSellerList) > 0 {
  173. departmentGroupSellerList = append(departmentGroupSellerList, groupItem)
  174. }
  175. }
  176. //分组为0的销售(直属部门)
  177. departmentSellerList, err := system.GetDepartmentGroupSysUserList(department.DepartmentId, 0, roleCodeTypeStr)
  178. if err != nil {
  179. br.Msg = "获取销售失败"
  180. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  181. return
  182. }
  183. if len(departmentSellerList) > 0 {
  184. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  185. for _, seller := range departmentSellerList {
  186. sellerItem := company.DepartmentGroupSellers{
  187. AdminId: fmt.Sprint(seller.AdminId),
  188. //AdminName string `description:"系统用户名称"`
  189. RealName: seller.RealName,
  190. Authority: seller.Authority,
  191. RoleTypeCode: seller.RoleTypeCode,
  192. }
  193. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  194. }
  195. //排个序
  196. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  197. departmentGroupSellerList = append(departmentGroupSellerList, tmpDepartmentGroupSellersList...)
  198. }
  199. item.ChildrenList = departmentGroupSellerList
  200. if len(departmentGroupSellerList) > 0 {
  201. list = append(list, item)
  202. }
  203. }
  204. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM || sysUser.Authority == 4 {
  205. //销售组长看销售
  206. if status == 0 {
  207. directorId := sysUser.GroupId
  208. fmt.Println("directorId:", directorId)
  209. groupList, err := system.GetSysGroupByDirectorId(directorId)
  210. if err != nil {
  211. br.Msg = "获取失败"
  212. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  213. return
  214. }
  215. for _, group := range groupList {
  216. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  217. groupItem := company.DepartmentGroupSellers{
  218. AdminId: fmt.Sprint("group_", group.DepartmentId),
  219. //AdminName string `description:"系统用户名称"`
  220. RealName: group.GroupName,
  221. ChildrenList: groupSellerList,
  222. }
  223. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  224. if err != nil {
  225. br.Msg = "获取小组失败"
  226. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  227. return
  228. }
  229. for _, team := range teamList {
  230. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  231. teamItem := company.DepartmentGroupSellers{
  232. AdminId: fmt.Sprint("team_", team.GroupId),
  233. //AdminName string `description:"系统用户名称"`
  234. RealName: team.GroupName,
  235. ChildrenList: teamSellerList,
  236. }
  237. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  238. if err != nil {
  239. br.Msg = "获取销售失败"
  240. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  241. return
  242. }
  243. for _, seller := range sellerList {
  244. sellerItem := company.DepartmentGroupSellers{
  245. AdminId: fmt.Sprint(seller.AdminId),
  246. //AdminName string `description:"系统用户名称"`
  247. RealName: seller.RealName,
  248. Authority: seller.Authority,
  249. RoleTypeCode: seller.RoleTypeCode,
  250. }
  251. //fmt.Println("seller.RealName:", seller.RealName)
  252. teamSellerList = append(teamSellerList, sellerItem)
  253. }
  254. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  255. teamItem.ChildrenList = teamSellerList
  256. if len(teamSellerList) > 0 {
  257. groupSellerList = append(groupSellerList, teamItem)
  258. }
  259. }
  260. //分组为0的销售(直属分组)
  261. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  262. if err != nil {
  263. br.Msg = "获取销售失败"
  264. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  265. return
  266. }
  267. if len(groupTeamSellerList) > 0 {
  268. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  269. for _, seller := range groupTeamSellerList {
  270. sellerItem := company.DepartmentGroupSellers{
  271. AdminId: fmt.Sprint(seller.AdminId),
  272. //AdminName string `description:"系统用户名称"`
  273. RealName: seller.RealName,
  274. Authority: seller.Authority,
  275. RoleTypeCode: seller.RoleTypeCode,
  276. }
  277. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  278. }
  279. //排个序
  280. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  281. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  282. }
  283. groupItem.ChildrenList = groupSellerList
  284. if len(groupSellerList) > 0 {
  285. list = append(list, groupItem)
  286. }
  287. }
  288. } else {
  289. departmentStr := `1,2`
  290. departmentList, err := system.GetDepartmentListByIds(departmentStr)
  291. if err != nil {
  292. br.Msg = "获取失败"
  293. br.ErrMsg = "获取部门失败,Err:" + err.Error()
  294. return
  295. }
  296. for _, department := range departmentList {
  297. departmentGroupSellerList := make([]company.DepartmentGroupSellers, 0)
  298. item := company.DepartmentGroupSellers{
  299. AdminId: fmt.Sprint("department_", department.DepartmentId),
  300. //AdminName string `description:"系统用户名称"`
  301. RealName: department.DepartmentName,
  302. ChildrenList: departmentGroupSellerList,
  303. }
  304. groupList, err := system.GetSysGroupByDepartmentId(department.DepartmentId)
  305. if err != nil {
  306. br.Msg = "获取失败"
  307. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  308. return
  309. }
  310. for _, group := range groupList {
  311. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  312. groupItem := company.DepartmentGroupSellers{
  313. AdminId: fmt.Sprint("group_", group.DepartmentId),
  314. //AdminName string `description:"系统用户名称"`
  315. RealName: group.GroupName,
  316. ChildrenList: groupSellerList,
  317. }
  318. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  319. if err != nil {
  320. br.Msg = "获取小组失败"
  321. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  322. return
  323. }
  324. for _, team := range teamList {
  325. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  326. teamItem := company.DepartmentGroupSellers{
  327. AdminId: fmt.Sprint("team_", team.GroupId),
  328. //AdminName string `description:"系统用户名称"`
  329. RealName: team.GroupName,
  330. ChildrenList: teamSellerList,
  331. }
  332. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  333. if err != nil {
  334. br.Msg = "获取销售失败"
  335. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  336. return
  337. }
  338. for _, seller := range sellerList {
  339. sellerItem := company.DepartmentGroupSellers{
  340. AdminId: fmt.Sprint(seller.AdminId),
  341. //AdminName string `description:"系统用户名称"`
  342. RealName: seller.RealName,
  343. Authority: seller.Authority,
  344. RoleTypeCode: seller.RoleTypeCode,
  345. }
  346. //fmt.Println("seller.RealName:", seller.RealName)
  347. teamSellerList = append(teamSellerList, sellerItem)
  348. }
  349. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  350. teamItem.ChildrenList = teamSellerList
  351. if len(teamSellerList) > 0 {
  352. groupSellerList = append(groupSellerList, teamItem)
  353. }
  354. }
  355. //分组为0的人,不光是销售(直属分组)
  356. groupTeamSellerList, err := system.GetGroupSysUserList(group.GroupId)
  357. if err != nil {
  358. br.Msg = "获取销售失败"
  359. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  360. return
  361. }
  362. if len(groupTeamSellerList) > 0 {
  363. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  364. for _, seller := range groupTeamSellerList {
  365. sellerItem := company.DepartmentGroupSellers{
  366. AdminId: fmt.Sprint(seller.AdminId),
  367. //AdminName string `description:"系统用户名称"`
  368. RealName: seller.RealName,
  369. Authority: seller.Authority,
  370. RoleTypeCode: seller.RoleTypeCode,
  371. }
  372. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  373. }
  374. //排个序
  375. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  376. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  377. }
  378. //groupItem.ChildrenList = groupSellerList
  379. //if len(groupSellerList) > 0 {
  380. // list = append(list, item)
  381. //}
  382. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  383. //if err != nil {
  384. // br.Msg = "获取销售失败"
  385. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  386. // return
  387. //}
  388. //for _, seller := range sellerList {
  389. // sellerItem := company.DepartmentGroupSellers{
  390. // AdminId: fmt.Sprint(seller.AdminId),
  391. // //AdminName string `description:"系统用户名称"`
  392. // RealName: seller.RealName,
  393. // Authority: seller.Authority,
  394. // RoleTypeCode: seller.RoleTypeCode,
  395. // }
  396. // groupSellerList = append(groupSellerList, sellerItem)
  397. //}
  398. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  399. groupItem.ChildrenList = groupSellerList
  400. if len(groupSellerList) > 0 {
  401. departmentGroupSellerList = append(departmentGroupSellerList, groupItem)
  402. }
  403. }
  404. //分组为0的人,不光是销售(直属部门)
  405. departmentSellerList, err := system.GetDepartmentGroupSysUserList(department.DepartmentId, 0, "")
  406. if err != nil {
  407. br.Msg = "获取销售失败"
  408. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  409. return
  410. }
  411. if len(departmentSellerList) > 0 {
  412. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  413. for _, seller := range departmentSellerList {
  414. sellerItem := company.DepartmentGroupSellers{
  415. AdminId: fmt.Sprint(seller.AdminId),
  416. //AdminName string `description:"系统用户名称"`
  417. RealName: seller.RealName,
  418. Authority: seller.Authority,
  419. RoleTypeCode: seller.RoleTypeCode,
  420. }
  421. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  422. }
  423. //排个序
  424. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  425. departmentGroupSellerList = append(departmentGroupSellerList, tmpDepartmentGroupSellersList...)
  426. }
  427. item.ChildrenList = departmentGroupSellerList
  428. if len(departmentGroupSellerList) > 0 {
  429. list = append(list, item)
  430. }
  431. }
  432. }
  433. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_COMPLIANCE || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FINANCE || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN { //合规或财务或ficc管理员
  434. departmentStr := `2,5,7` //合规
  435. switch sysUser.RoleTypeCode {
  436. case utils.ROLE_TYPE_CODE_FINANCE: //财务
  437. departmentStr = `2,5,8`
  438. case utils.ROLE_TYPE_CODE_FICC_ADMIN: //ficc管理员
  439. departmentStr = utils.GetFiccAdminDepartmentIds()
  440. }
  441. departmentList, err := system.GetDepartmentListByIds(departmentStr)
  442. if err != nil {
  443. br.Msg = "获取失败"
  444. br.ErrMsg = "获取部门失败,Err:" + err.Error()
  445. return
  446. }
  447. for _, department := range departmentList {
  448. fmt.Println(department)
  449. departmentGroupSellerList := make([]company.DepartmentGroupSellers, 0)
  450. item := company.DepartmentGroupSellers{
  451. AdminId: fmt.Sprint("department_", department.DepartmentId),
  452. //AdminName string `description:"系统用户名称"`
  453. RealName: department.DepartmentName,
  454. ChildrenList: departmentGroupSellerList,
  455. }
  456. groupList, err := system.GetSysGroupByDepartmentId(department.DepartmentId)
  457. if err != nil {
  458. br.Msg = "获取失败"
  459. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  460. return
  461. }
  462. for _, group := range groupList {
  463. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  464. groupItem := company.DepartmentGroupSellers{
  465. AdminId: fmt.Sprint("group_", group.DepartmentId),
  466. //AdminName string `description:"系统用户名称"`
  467. RealName: group.GroupName,
  468. ChildrenList: groupSellerList,
  469. }
  470. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  471. if err != nil {
  472. br.Msg = "获取小组失败"
  473. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  474. return
  475. }
  476. for _, team := range teamList {
  477. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  478. teamItem := company.DepartmentGroupSellers{
  479. AdminId: fmt.Sprint("team_", team.GroupId),
  480. //AdminName string `description:"系统用户名称"`
  481. RealName: team.GroupName,
  482. ChildrenList: teamSellerList,
  483. }
  484. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  485. if err != nil {
  486. br.Msg = "获取销售失败"
  487. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  488. return
  489. }
  490. for _, seller := range sellerList {
  491. sellerItem := company.DepartmentGroupSellers{
  492. AdminId: fmt.Sprint(seller.AdminId),
  493. //AdminName string `description:"系统用户名称"`
  494. RealName: seller.RealName,
  495. Authority: seller.Authority,
  496. RoleTypeCode: seller.RoleTypeCode,
  497. }
  498. //fmt.Println("seller.RealName:", seller.RealName)
  499. teamSellerList = append(teamSellerList, sellerItem)
  500. }
  501. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  502. teamItem.ChildrenList = teamSellerList
  503. if len(teamSellerList) > 0 {
  504. groupSellerList = append(groupSellerList, teamItem)
  505. }
  506. }
  507. //分组为0的销售(直属分组)
  508. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  509. if err != nil {
  510. br.Msg = "获取销售失败"
  511. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  512. return
  513. }
  514. if len(groupTeamSellerList) > 0 {
  515. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  516. for _, seller := range groupTeamSellerList {
  517. sellerItem := company.DepartmentGroupSellers{
  518. AdminId: fmt.Sprint(seller.AdminId),
  519. //AdminName string `description:"系统用户名称"`
  520. RealName: seller.RealName,
  521. Authority: seller.Authority,
  522. RoleTypeCode: seller.RoleTypeCode,
  523. }
  524. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  525. }
  526. //排个序
  527. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  528. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  529. }
  530. //groupItem.ChildrenList = groupSellerList
  531. //if len(groupSellerList) > 0 {
  532. // list = append(list, item)
  533. //}
  534. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  535. //if err != nil {
  536. // br.Msg = "获取销售失败"
  537. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  538. // return
  539. //}
  540. //for _, seller := range sellerList {
  541. // sellerItem := company.DepartmentGroupSellers{
  542. // AdminId: fmt.Sprint(seller.AdminId),
  543. // //AdminName string `description:"系统用户名称"`
  544. // RealName: seller.RealName,
  545. // Authority: seller.Authority,
  546. // RoleTypeCode: seller.RoleTypeCode,
  547. // }
  548. // groupSellerList = append(groupSellerList, sellerItem)
  549. //}
  550. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  551. groupItem.ChildrenList = groupSellerList
  552. if len(groupSellerList) > 0 {
  553. departmentGroupSellerList = append(departmentGroupSellerList, groupItem)
  554. }
  555. }
  556. //分组为0的销售(直属部门)
  557. departmentSellerList, err := system.GetDepartmentGroupSysUserList(department.DepartmentId, 0, roleCodeTypeStr)
  558. if err != nil {
  559. br.Msg = "获取销售失败"
  560. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  561. return
  562. }
  563. if len(departmentSellerList) > 0 {
  564. tmpDepartmentGroupSellerList := make([]company.DepartmentGroupSellers, 0)
  565. for _, seller := range departmentSellerList {
  566. sellerItem := company.DepartmentGroupSellers{
  567. AdminId: fmt.Sprint(seller.AdminId),
  568. //AdminName string `description:"系统用户名称"`
  569. RealName: seller.RealName,
  570. Authority: seller.Authority,
  571. RoleTypeCode: seller.RoleTypeCode,
  572. }
  573. tmpDepartmentGroupSellerList = append(tmpDepartmentGroupSellerList, sellerItem)
  574. }
  575. //排个序
  576. tmpDepartmentGroupSellerList = sortDepartmentGroupSellers(tmpDepartmentGroupSellerList)
  577. departmentGroupSellerList = append(departmentGroupSellerList, tmpDepartmentGroupSellerList...)
  578. }
  579. item.ChildrenList = departmentGroupSellerList
  580. if len(departmentGroupSellerList) > 0 {
  581. list = append(list, item)
  582. }
  583. }
  584. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN || sysUser.Authority == 1 {
  585. //部门管理员看小组、销售
  586. departmentId := sysUser.DepartmentId
  587. switch sysUser.RoleTypeCode {
  588. case utils.ROLE_TYPE_CODE_RAI_ADMIN: //权益管理员
  589. departmentId = 5
  590. case utils.ROLE_TYPE_CODE_FICC_ADMIN: //ficc管理员
  591. departmentId = 2
  592. }
  593. groupList, err := system.GetSysGroupByDepartmentId(departmentId)
  594. if err != nil {
  595. br.Msg = "获取失败"
  596. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  597. return
  598. }
  599. for _, group := range groupList {
  600. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  601. groupItem := company.DepartmentGroupSellers{
  602. AdminId: fmt.Sprint("group_", group.DepartmentId),
  603. //AdminName string `description:"系统用户名称"`
  604. RealName: group.GroupName,
  605. ChildrenList: groupSellerList,
  606. }
  607. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  608. if err != nil {
  609. br.Msg = "获取小组失败"
  610. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  611. return
  612. }
  613. for _, team := range teamList {
  614. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  615. teamItem := company.DepartmentGroupSellers{
  616. AdminId: fmt.Sprint("team_", team.GroupId),
  617. //AdminName string `description:"系统用户名称"`
  618. RealName: team.GroupName,
  619. ChildrenList: teamSellerList,
  620. }
  621. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  622. if err != nil {
  623. br.Msg = "获取销售失败"
  624. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  625. return
  626. }
  627. for _, seller := range sellerList {
  628. sellerItem := company.DepartmentGroupSellers{
  629. AdminId: fmt.Sprint(seller.AdminId),
  630. //AdminName string `description:"系统用户名称"`
  631. RealName: seller.RealName,
  632. Authority: seller.Authority,
  633. RoleTypeCode: seller.RoleTypeCode,
  634. }
  635. //fmt.Println("seller.RealName:", seller.RealName)
  636. teamSellerList = append(teamSellerList, sellerItem)
  637. }
  638. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  639. teamItem.ChildrenList = teamSellerList
  640. if len(teamSellerList) > 0 {
  641. groupSellerList = append(groupSellerList, teamItem)
  642. }
  643. }
  644. //分组为0的销售(直属分组)
  645. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  646. if err != nil {
  647. br.Msg = "获取销售失败"
  648. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  649. return
  650. }
  651. if len(groupTeamSellerList) > 0 {
  652. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  653. for _, seller := range groupTeamSellerList {
  654. sellerItem := company.DepartmentGroupSellers{
  655. AdminId: fmt.Sprint(seller.AdminId),
  656. //AdminName string `description:"系统用户名称"`
  657. RealName: seller.RealName,
  658. Authority: seller.Authority,
  659. RoleTypeCode: seller.RoleTypeCode,
  660. }
  661. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  662. }
  663. //排个序
  664. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  665. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  666. }
  667. //groupItem.ChildrenList = groupSellerList
  668. //if len(groupSellerList) > 0 {
  669. // list = append(list, item)
  670. //}
  671. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  672. //if err != nil {
  673. // br.Msg = "获取销售失败"
  674. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  675. // return
  676. //}
  677. //for _, seller := range sellerList {
  678. // sellerItem := company.DepartmentGroupSellers{
  679. // AdminId: fmt.Sprint(seller.AdminId),
  680. // //AdminName string `description:"系统用户名称"`
  681. // RealName: seller.RealName,
  682. // Authority: seller.Authority,
  683. // RoleTypeCode: seller.RoleTypeCode,
  684. // }
  685. // groupSellerList = append(groupSellerList, sellerItem)
  686. //}
  687. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  688. groupItem.ChildrenList = groupSellerList
  689. if len(groupSellerList) > 0 {
  690. list = append(list, groupItem)
  691. }
  692. }
  693. //分组为0的销售(直属部门)
  694. departmentSellerList, err := system.GetDepartmentGroupSysUserList(departmentId, 0, roleCodeTypeStr)
  695. if err != nil {
  696. br.Msg = "获取销售失败"
  697. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  698. return
  699. }
  700. if len(departmentSellerList) > 0 {
  701. tmpDepartmentGroupSeller := make([]company.DepartmentGroupSellers, 0)
  702. for _, seller := range departmentSellerList {
  703. sellerItem := company.DepartmentGroupSellers{
  704. AdminId: fmt.Sprint(seller.AdminId),
  705. //AdminName string `description:"系统用户名称"`
  706. RealName: seller.RealName,
  707. Authority: seller.Authority,
  708. RoleTypeCode: seller.RoleTypeCode,
  709. }
  710. tmpDepartmentGroupSeller = append(tmpDepartmentGroupSeller, sellerItem)
  711. }
  712. tmpDepartmentGroupSeller = sortDepartmentGroupSellers(tmpDepartmentGroupSeller)
  713. list = append(list, tmpDepartmentGroupSeller...)
  714. }
  715. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP || (sysUser.Authority == 2 && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_FICC_GROUP) {
  716. // 权益组长看小组
  717. if status == 0 {
  718. sellerList, err := system.GetTeamSysUserList(sysUser.GroupId, enabled)
  719. if err != nil {
  720. br.Msg = "获取销售失败"
  721. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  722. return
  723. }
  724. for _, seller := range sellerList {
  725. sellerItem := company.DepartmentGroupSellers{
  726. AdminId: fmt.Sprint(seller.AdminId),
  727. //AdminName string `description:"系统用户名称"`
  728. RealName: seller.RealName,
  729. Authority: seller.Authority,
  730. RoleTypeCode: seller.RoleTypeCode,
  731. }
  732. //fmt.Println("seller.RealName:", seller.RealName)
  733. list = append(list, sellerItem)
  734. }
  735. list = sortDepartmentGroupSellers(list)
  736. //正常来说没有所有人都应该在某个小组下,要不就是小组名为 无 的小组
  737. //分组为0的销售(直属分组)
  738. //groupTeamSellerList, err := system.GetGrooupsysUserList(sysUser.GroupId, 0, roleCodeTypeStr)
  739. //if err != nil {
  740. // br.Msg = "获取销售失败"
  741. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  742. // return
  743. //}
  744. //if len(groupTeamSellerList) > 0 {
  745. // tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  746. // for _, seller := range groupTeamSellerList {
  747. // sellerItem := company.DepartmentGroupSellers{
  748. // AdminId: fmt.Sprint(seller.AdminId),
  749. // //AdminName string `description:"系统用户名称"`
  750. // RealName: seller.RealName,
  751. // Authority: seller.Authority,
  752. // RoleTypeCode: seller.RoleTypeCode,
  753. // }
  754. // tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  755. // }
  756. // //排个序
  757. // tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  758. // list = append(list, tmpDepartmentGroupSellersList...)
  759. //}
  760. //sellerList, err := system.GetDepartmentGroupSysUserList(sysUser.DepartmentId, sysUser.GroupId, roleCodeTypeStr)
  761. //if err != nil {
  762. // br.Msg = "获取销售失败"
  763. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  764. // return
  765. //}
  766. //for _, seller := range sellerList {
  767. // sellerItem := company.DepartmentGroupSellers{
  768. // AdminId: fmt.Sprint(seller.AdminId),
  769. // //AdminName string `description:"系统用户名称"`
  770. // RealName: seller.RealName,
  771. // Authority: seller.Authority,
  772. // RoleTypeCode: seller.RoleTypeCode,
  773. // }
  774. // list = append(list, sellerItem)
  775. // list = sortDepartmentGroupSellers(list)
  776. //}
  777. } else {
  778. departmentId := 5
  779. groupList, err := system.GetSysGroupByDepartmentId(departmentId)
  780. if err != nil {
  781. br.Msg = "获取失败"
  782. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  783. return
  784. }
  785. for _, group := range groupList {
  786. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  787. groupItem := company.DepartmentGroupSellers{
  788. AdminId: fmt.Sprint("group_", group.DepartmentId),
  789. //AdminName string `description:"系统用户名称"`
  790. RealName: group.GroupName,
  791. ChildrenList: groupSellerList,
  792. }
  793. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  794. if err != nil {
  795. br.Msg = "获取小组失败"
  796. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  797. return
  798. }
  799. for _, team := range teamList {
  800. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  801. teamItem := company.DepartmentGroupSellers{
  802. AdminId: fmt.Sprint("team_", team.GroupId),
  803. //AdminName string `description:"系统用户名称"`
  804. RealName: team.GroupName,
  805. ChildrenList: teamSellerList,
  806. }
  807. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  808. if err != nil {
  809. br.Msg = "获取销售失败"
  810. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  811. return
  812. }
  813. for _, seller := range sellerList {
  814. sellerItem := company.DepartmentGroupSellers{
  815. AdminId: fmt.Sprint(seller.AdminId),
  816. //AdminName string `description:"系统用户名称"`
  817. RealName: seller.RealName,
  818. Authority: seller.Authority,
  819. RoleTypeCode: seller.RoleTypeCode,
  820. }
  821. //fmt.Println("seller.RealName:", seller.RealName)
  822. teamSellerList = append(teamSellerList, sellerItem)
  823. }
  824. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  825. teamItem.ChildrenList = teamSellerList
  826. if len(teamSellerList) > 0 {
  827. groupSellerList = append(groupSellerList, teamItem)
  828. }
  829. }
  830. //分组为0的销售(直属分组)
  831. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  832. if err != nil {
  833. br.Msg = "获取销售失败"
  834. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  835. return
  836. }
  837. if len(groupTeamSellerList) > 0 {
  838. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  839. for _, seller := range groupTeamSellerList {
  840. sellerItem := company.DepartmentGroupSellers{
  841. AdminId: fmt.Sprint(seller.AdminId),
  842. //AdminName string `description:"系统用户名称"`
  843. RealName: seller.RealName,
  844. Authority: seller.Authority,
  845. RoleTypeCode: seller.RoleTypeCode,
  846. }
  847. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  848. }
  849. //排个序
  850. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  851. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  852. }
  853. //groupItem.ChildrenList = groupSellerList
  854. //if len(groupSellerList) > 0 {
  855. // list = append(list, item)
  856. //}
  857. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  858. //if err != nil {
  859. // br.Msg = "获取销售失败"
  860. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  861. // return
  862. //}
  863. //for _, seller := range sellerList {
  864. // sellerItem := company.DepartmentGroupSellers{
  865. // AdminId: fmt.Sprint(seller.AdminId),
  866. // //AdminName string `description:"系统用户名称"`
  867. // RealName: seller.RealName,
  868. // Authority: seller.Authority,
  869. // RoleTypeCode: seller.RoleTypeCode,
  870. // }
  871. // groupSellerList = append(groupSellerList, sellerItem)
  872. //}
  873. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  874. groupItem.ChildrenList = groupSellerList
  875. if len(groupSellerList) > 0 {
  876. list = append(list, groupItem)
  877. }
  878. }
  879. //分组为0的销售(直属部门)
  880. departmentSellerList, err := system.GetDepartmentGroupSysUserList(departmentId, 0, roleCodeTypeStr)
  881. if err != nil {
  882. br.Msg = "获取销售失败"
  883. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  884. return
  885. }
  886. if len(departmentSellerList) > 0 {
  887. tmpDepartmentGroupSeller := make([]company.DepartmentGroupSellers, 0)
  888. for _, seller := range departmentSellerList {
  889. sellerItem := company.DepartmentGroupSellers{
  890. AdminId: fmt.Sprint(seller.AdminId),
  891. //AdminName string `description:"系统用户名称"`
  892. RealName: seller.RealName,
  893. Authority: seller.Authority,
  894. RoleTypeCode: seller.RoleTypeCode,
  895. }
  896. tmpDepartmentGroupSeller = append(tmpDepartmentGroupSeller, sellerItem)
  897. }
  898. tmpDepartmentGroupSeller = sortDepartmentGroupSellers(tmpDepartmentGroupSeller)
  899. list = append(list, tmpDepartmentGroupSeller...)
  900. }
  901. }
  902. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || sysUser.Authority == 2 {
  903. // 销售主管看小组
  904. if status == 0 {
  905. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  906. if err != nil {
  907. br.Msg = "获取失败"
  908. br.ErrMsg = "查询父级id异常" + err.Error()
  909. return
  910. }
  911. var realGroupId int
  912. if pid != nil && *pid > 0 {
  913. //主管角色放在了三级分组下
  914. realGroupId = *pid
  915. } else {
  916. //主管角色放在了二级分组下
  917. realGroupId = sysUser.GroupId
  918. }
  919. groupList, err := system.GetSysGroupByGroupId(realGroupId)
  920. if err != nil {
  921. br.Msg = "获取失败"
  922. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  923. return
  924. }
  925. for _, group := range groupList {
  926. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  927. //groupItem := company.DepartmentGroupSellers{
  928. // AdminId: fmt.Sprint("group_", group.DepartmentId),
  929. // //AdminName string `description:"系统用户名称"`
  930. // RealName: group.GroupName,
  931. // ChildrenList: groupSellerList,
  932. //}
  933. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  934. if err != nil {
  935. br.Msg = "获取小组失败"
  936. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  937. return
  938. }
  939. for _, team := range teamList {
  940. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  941. teamItem := company.DepartmentGroupSellers{
  942. AdminId: fmt.Sprint("team_", team.GroupId),
  943. //AdminName string `description:"系统用户名称"`
  944. RealName: team.GroupName,
  945. ChildrenList: teamSellerList,
  946. }
  947. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  948. if err != nil {
  949. br.Msg = "获取销售失败"
  950. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  951. return
  952. }
  953. for _, seller := range sellerList {
  954. sellerItem := company.DepartmentGroupSellers{
  955. AdminId: fmt.Sprint(seller.AdminId),
  956. //AdminName string `description:"系统用户名称"`
  957. RealName: seller.RealName,
  958. Authority: seller.Authority,
  959. RoleTypeCode: seller.RoleTypeCode,
  960. }
  961. //fmt.Println("seller.RealName:", seller.RealName)
  962. teamSellerList = append(teamSellerList, sellerItem)
  963. }
  964. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  965. teamItem.ChildrenList = teamSellerList
  966. if len(teamSellerList) > 0 {
  967. groupSellerList = append(groupSellerList, teamItem)
  968. }
  969. }
  970. //分组为0的销售(直属分组)
  971. groupTeamSellerList, err := system.GetGrooupsysUserList(realGroupId, roleCodeTypeStr, enabled)
  972. if err != nil {
  973. br.Msg = "获取销售失败"
  974. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  975. return
  976. }
  977. if len(groupTeamSellerList) > 0 {
  978. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  979. for _, seller := range groupTeamSellerList {
  980. sellerItem := company.DepartmentGroupSellers{
  981. AdminId: fmt.Sprint(seller.AdminId),
  982. //AdminName string `description:"系统用户名称"`
  983. RealName: seller.RealName,
  984. Authority: seller.Authority,
  985. RoleTypeCode: seller.RoleTypeCode,
  986. }
  987. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  988. }
  989. //排个序
  990. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  991. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  992. }
  993. list = groupSellerList
  994. //groupItem.ChildrenList = groupSellerList
  995. //if len(groupSellerList) > 0 {
  996. // list = append(list, item)
  997. //}
  998. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  999. //if err != nil {
  1000. // br.Msg = "获取销售失败"
  1001. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1002. // return
  1003. //}
  1004. //for _, seller := range sellerList {
  1005. // sellerItem := company.DepartmentGroupSellers{
  1006. // AdminId: fmt.Sprint(seller.AdminId),
  1007. // //AdminName string `description:"系统用户名称"`
  1008. // RealName: seller.RealName,
  1009. // Authority: seller.Authority,
  1010. // RoleTypeCode: seller.RoleTypeCode,
  1011. // }
  1012. // groupSellerList = append(groupSellerList, sellerItem)
  1013. //}
  1014. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  1015. //groupItem.ChildrenList = groupSellerList
  1016. //if len(groupSellerList) > 0 {
  1017. // list = append(list, groupItem)
  1018. //}
  1019. }
  1020. //分组为0的销售(直属二级分组)
  1021. //departmentSellerList, err := system.GetDepartmentGroupSysUserList(2, realGroupId, roleCodeTypeStr)
  1022. //if err != nil {
  1023. // br.Msg = "获取销售失败"
  1024. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1025. // return
  1026. //}
  1027. //if len(departmentSellerList) > 0 {
  1028. // tmpDepartmentGroupSeller := make([]company.DepartmentGroupSellers, 0)
  1029. // for _, seller := range departmentSellerList {
  1030. // sellerItem := company.DepartmentGroupSellers{
  1031. // AdminId: fmt.Sprint(seller.AdminId),
  1032. // //AdminName string `description:"系统用户名称"`
  1033. // RealName: seller.RealName,
  1034. // Authority: seller.Authority,
  1035. // RoleTypeCode: seller.RoleTypeCode,
  1036. // }
  1037. // tmpDepartmentGroupSeller = append(tmpDepartmentGroupSeller, sellerItem)
  1038. // }
  1039. // tmpDepartmentGroupSeller = sortDepartmentGroupSellers(tmpDepartmentGroupSeller)
  1040. // list = append(list, tmpDepartmentGroupSeller...)
  1041. //}
  1042. //pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  1043. //if err != nil {
  1044. // br.Msg = "获取失败"
  1045. // br.ErrMsg = "查询父级id异常" + err.Error()
  1046. // return
  1047. //}
  1048. //if pid != nil && *pid > 0 {
  1049. // //主管角色放在了三级分组下
  1050. // //
  1051. //
  1052. //
  1053. //} else {
  1054. // //主管角色放在了二级分组下
  1055. //
  1056. //}
  1057. //ids, err := company.GetGroupIdsByParentId(*pid)
  1058. //if err != nil {
  1059. // br.Msg = "获取失败"
  1060. // br.ErrMsg = "查询父级id异常" + err.Error()
  1061. // return
  1062. //}
  1063. //var idSlice []string
  1064. //var sid string
  1065. //for _, id := range ids {
  1066. // idSlice = append(idSlice, *id)
  1067. //}
  1068. //sid = strings.Join(idSlice, ",")
  1069. //sellerList, err := system.GetTeamSysUserListByIds(sid)
  1070. //if err != nil {
  1071. // br.Msg = "获取销售失败"
  1072. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1073. // return
  1074. //}
  1075. //for _, seller := range sellerList {
  1076. // sellerItem := company.DepartmentGroupSellers{
  1077. // AdminId: fmt.Sprint(seller.AdminId),
  1078. // //AdminName string `description:"系统用户名称"`
  1079. // RealName: seller.RealName,
  1080. // Authority: seller.Authority,
  1081. // RoleTypeCode: seller.RoleTypeCode,
  1082. // }
  1083. // fmt.Println("seller.RealName:", seller.RealName)
  1084. // list = append(list, sellerItem)
  1085. //}
  1086. //list = sortDepartmentGroupSellers(list)
  1087. //
  1088. ////分组为0的销售(直属分组)
  1089. //groupTeamSellerList, err := system.GetGrooupsysUserList(sysUser.GroupId, roleCodeTypeStr)
  1090. //if err != nil {
  1091. // br.Msg = "获取销售失败"
  1092. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1093. // return
  1094. //}
  1095. //if len(groupTeamSellerList) > 0 {
  1096. // tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  1097. // for _, seller := range groupTeamSellerList {
  1098. // sellerItem := company.DepartmentGroupSellers{
  1099. // AdminId: fmt.Sprint(seller.AdminId),
  1100. // //AdminName string `description:"系统用户名称"`
  1101. // RealName: seller.RealName,
  1102. // Authority: seller.Authority,
  1103. // RoleTypeCode: seller.RoleTypeCode,
  1104. // }
  1105. // tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  1106. // }
  1107. // //排个序
  1108. // tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  1109. // list = append(list, tmpDepartmentGroupSellersList...)
  1110. //}
  1111. //sellerList, err := system.GetDepartmentGroupSysUserList(sysUser.DepartmentId, sysUser.GroupId, roleCodeTypeStr)
  1112. //if err != nil {
  1113. // br.Msg = "获取销售失败"
  1114. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1115. // return
  1116. //}
  1117. //for _, seller := range sellerList {
  1118. // sellerItem := company.DepartmentGroupSellers{
  1119. // AdminId: fmt.Sprint(seller.AdminId),
  1120. // //AdminName string `description:"系统用户名称"`
  1121. // RealName: seller.RealName,
  1122. // Authority: seller.Authority,
  1123. // RoleTypeCode: seller.RoleTypeCode,
  1124. // }
  1125. // list = append(list, sellerItem)
  1126. // list = sortDepartmentGroupSellers(list)
  1127. //}
  1128. //正常来说没有所有人都应该在某个小组下,要不就是小组名为 无 的小组
  1129. } else {
  1130. //var departmentStr string
  1131. //if utils.RunMode == "release" {
  1132. // departmentStr = `1,2`
  1133. //} else {
  1134. // departmentStr = `1,2`
  1135. //}
  1136. departmentStr := `1,2`
  1137. departmentList, err := system.GetDepartmentListByIds(departmentStr)
  1138. if err != nil {
  1139. br.Msg = "获取失败"
  1140. br.ErrMsg = "获取部门失败,Err:" + err.Error()
  1141. return
  1142. }
  1143. for _, department := range departmentList {
  1144. departmentGroupSellerList := make([]company.DepartmentGroupSellers, 0)
  1145. item := company.DepartmentGroupSellers{
  1146. AdminId: fmt.Sprint("department_", department.DepartmentId),
  1147. //AdminName string `description:"系统用户名称"`
  1148. RealName: department.DepartmentName,
  1149. ChildrenList: departmentGroupSellerList,
  1150. }
  1151. groupList, err := system.GetSysGroupByDepartmentId(department.DepartmentId)
  1152. if err != nil {
  1153. br.Msg = "获取失败"
  1154. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  1155. return
  1156. }
  1157. for _, group := range groupList {
  1158. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  1159. groupItem := company.DepartmentGroupSellers{
  1160. AdminId: fmt.Sprint("group_", group.DepartmentId),
  1161. //AdminName string `description:"系统用户名称"`
  1162. RealName: group.GroupName,
  1163. ChildrenList: groupSellerList,
  1164. }
  1165. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  1166. if err != nil {
  1167. br.Msg = "获取小组失败"
  1168. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  1169. return
  1170. }
  1171. for _, team := range teamList {
  1172. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  1173. teamItem := company.DepartmentGroupSellers{
  1174. AdminId: fmt.Sprint("team_", team.GroupId),
  1175. //AdminName string `description:"系统用户名称"`
  1176. RealName: team.GroupName,
  1177. ChildrenList: teamSellerList,
  1178. }
  1179. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  1180. if err != nil {
  1181. br.Msg = "获取销售失败"
  1182. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1183. return
  1184. }
  1185. for _, seller := range sellerList {
  1186. sellerItem := company.DepartmentGroupSellers{
  1187. AdminId: fmt.Sprint(seller.AdminId),
  1188. //AdminName string `description:"系统用户名称"`
  1189. RealName: seller.RealName,
  1190. Authority: seller.Authority,
  1191. RoleTypeCode: seller.RoleTypeCode,
  1192. }
  1193. //fmt.Println("seller.RealName:", seller.RealName)
  1194. teamSellerList = append(teamSellerList, sellerItem)
  1195. }
  1196. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  1197. teamItem.ChildrenList = teamSellerList
  1198. if len(teamSellerList) > 0 {
  1199. groupSellerList = append(groupSellerList, teamItem)
  1200. }
  1201. }
  1202. //分组为0的人,不光是销售(直属分组)
  1203. groupTeamSellerList, err := system.GetGroupSysUserList(group.GroupId)
  1204. if err != nil {
  1205. br.Msg = "获取销售失败"
  1206. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1207. return
  1208. }
  1209. if len(groupTeamSellerList) > 0 {
  1210. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  1211. for _, seller := range groupTeamSellerList {
  1212. sellerItem := company.DepartmentGroupSellers{
  1213. AdminId: fmt.Sprint(seller.AdminId),
  1214. //AdminName string `description:"系统用户名称"`
  1215. RealName: seller.RealName,
  1216. Authority: seller.Authority,
  1217. RoleTypeCode: seller.RoleTypeCode,
  1218. }
  1219. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  1220. }
  1221. //排个序
  1222. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  1223. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  1224. }
  1225. //groupItem.ChildrenList = groupSellerList
  1226. //if len(groupSellerList) > 0 {
  1227. // list = append(list, item)
  1228. //}
  1229. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  1230. //if err != nil {
  1231. // br.Msg = "获取销售失败"
  1232. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1233. // return
  1234. //}
  1235. //for _, seller := range sellerList {
  1236. // sellerItem := company.DepartmentGroupSellers{
  1237. // AdminId: fmt.Sprint(seller.AdminId),
  1238. // //AdminName string `description:"系统用户名称"`
  1239. // RealName: seller.RealName,
  1240. // Authority: seller.Authority,
  1241. // RoleTypeCode: seller.RoleTypeCode,
  1242. // }
  1243. // groupSellerList = append(groupSellerList, sellerItem)
  1244. //}
  1245. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  1246. groupItem.ChildrenList = groupSellerList
  1247. if len(groupSellerList) > 0 {
  1248. departmentGroupSellerList = append(departmentGroupSellerList, groupItem)
  1249. }
  1250. }
  1251. //分组为0的人,不光是销售(直属部门)
  1252. departmentSellerList, err := system.GetDepartmentGroupSysUserList(department.DepartmentId, 0, "")
  1253. if err != nil {
  1254. br.Msg = "获取销售失败"
  1255. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1256. return
  1257. }
  1258. if len(departmentSellerList) > 0 {
  1259. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  1260. for _, seller := range departmentSellerList {
  1261. sellerItem := company.DepartmentGroupSellers{
  1262. AdminId: fmt.Sprint(seller.AdminId),
  1263. //AdminName string `description:"系统用户名称"`
  1264. RealName: seller.RealName,
  1265. Authority: seller.Authority,
  1266. RoleTypeCode: seller.RoleTypeCode,
  1267. }
  1268. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  1269. }
  1270. //排个序
  1271. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  1272. departmentGroupSellerList = append(departmentGroupSellerList, tmpDepartmentGroupSellersList...)
  1273. }
  1274. item.ChildrenList = departmentGroupSellerList
  1275. if len(departmentGroupSellerList) > 0 {
  1276. list = append(list, item)
  1277. }
  1278. }
  1279. }
  1280. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER && status == 1 {
  1281. //var departmentStr string
  1282. //if utils.RunMode == "release" {
  1283. // departmentStr = `1,2`
  1284. //} else {
  1285. // departmentStr = `1,2`
  1286. //}
  1287. departmentStr := `1,2`
  1288. departmentList, err := system.GetDepartmentListByIds(departmentStr)
  1289. if err != nil {
  1290. br.Msg = "获取失败"
  1291. br.ErrMsg = "获取部门失败,Err:" + err.Error()
  1292. return
  1293. }
  1294. for _, department := range departmentList {
  1295. departmentGroupSellerList := make([]company.DepartmentGroupSellers, 0)
  1296. item := company.DepartmentGroupSellers{
  1297. AdminId: fmt.Sprint("department_", department.DepartmentId),
  1298. //AdminName string `description:"系统用户名称"`
  1299. RealName: department.DepartmentName,
  1300. ChildrenList: departmentGroupSellerList,
  1301. }
  1302. groupList, err := system.GetSysGroupByDepartmentId(department.DepartmentId)
  1303. if err != nil {
  1304. br.Msg = "获取失败"
  1305. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  1306. return
  1307. }
  1308. for _, group := range groupList {
  1309. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  1310. groupItem := company.DepartmentGroupSellers{
  1311. AdminId: fmt.Sprint("group_", group.DepartmentId),
  1312. //AdminName string `description:"系统用户名称"`
  1313. RealName: group.GroupName,
  1314. ChildrenList: groupSellerList,
  1315. }
  1316. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  1317. if err != nil {
  1318. br.Msg = "获取小组失败"
  1319. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  1320. return
  1321. }
  1322. for _, team := range teamList {
  1323. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  1324. teamItem := company.DepartmentGroupSellers{
  1325. AdminId: fmt.Sprint("team_", team.GroupId),
  1326. //AdminName string `description:"系统用户名称"`
  1327. RealName: team.GroupName,
  1328. ChildrenList: teamSellerList,
  1329. }
  1330. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  1331. if err != nil {
  1332. br.Msg = "获取销售失败"
  1333. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1334. return
  1335. }
  1336. for _, seller := range sellerList {
  1337. sellerItem := company.DepartmentGroupSellers{
  1338. AdminId: fmt.Sprint(seller.AdminId),
  1339. //AdminName string `description:"系统用户名称"`
  1340. RealName: seller.RealName,
  1341. Authority: seller.Authority,
  1342. RoleTypeCode: seller.RoleTypeCode,
  1343. }
  1344. //fmt.Println("seller.RealName:", seller.RealName)
  1345. teamSellerList = append(teamSellerList, sellerItem)
  1346. }
  1347. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  1348. teamItem.ChildrenList = teamSellerList
  1349. if len(teamSellerList) > 0 {
  1350. groupSellerList = append(groupSellerList, teamItem)
  1351. }
  1352. }
  1353. //分组为0的人,不光是销售(直属分组)
  1354. groupTeamSellerList, err := system.GetGroupSysUserList(group.GroupId)
  1355. if err != nil {
  1356. br.Msg = "获取销售失败"
  1357. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1358. return
  1359. }
  1360. if len(groupTeamSellerList) > 0 {
  1361. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  1362. for _, seller := range groupTeamSellerList {
  1363. sellerItem := company.DepartmentGroupSellers{
  1364. AdminId: fmt.Sprint(seller.AdminId),
  1365. //AdminName string `description:"系统用户名称"`
  1366. RealName: seller.RealName,
  1367. Authority: seller.Authority,
  1368. RoleTypeCode: seller.RoleTypeCode,
  1369. }
  1370. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  1371. }
  1372. //排个序
  1373. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  1374. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  1375. }
  1376. //groupItem.ChildrenList = groupSellerList
  1377. //if len(groupSellerList) > 0 {
  1378. // list = append(list, item)
  1379. //}
  1380. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  1381. //if err != nil {
  1382. // br.Msg = "获取销售失败"
  1383. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1384. // return
  1385. //}
  1386. //for _, seller := range sellerList {
  1387. // sellerItem := company.DepartmentGroupSellers{
  1388. // AdminId: fmt.Sprint(seller.AdminId),
  1389. // //AdminName string `description:"系统用户名称"`
  1390. // RealName: seller.RealName,
  1391. // Authority: seller.Authority,
  1392. // RoleTypeCode: seller.RoleTypeCode,
  1393. // }
  1394. // groupSellerList = append(groupSellerList, sellerItem)
  1395. //}
  1396. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  1397. groupItem.ChildrenList = groupSellerList
  1398. if len(groupSellerList) > 0 {
  1399. departmentGroupSellerList = append(departmentGroupSellerList, groupItem)
  1400. }
  1401. }
  1402. //分组为0的人,不光是销售(直属部门)
  1403. departmentSellerList, err := system.GetDepartmentGroupSysUserList(department.DepartmentId, 0, "")
  1404. if err != nil {
  1405. br.Msg = "获取销售失败"
  1406. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1407. return
  1408. }
  1409. if len(departmentSellerList) > 0 {
  1410. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  1411. for _, seller := range departmentSellerList {
  1412. sellerItem := company.DepartmentGroupSellers{
  1413. AdminId: fmt.Sprint(seller.AdminId),
  1414. //AdminName string `description:"系统用户名称"`
  1415. RealName: seller.RealName,
  1416. Authority: seller.Authority,
  1417. RoleTypeCode: seller.RoleTypeCode,
  1418. }
  1419. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  1420. }
  1421. //排个序
  1422. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  1423. departmentGroupSellerList = append(departmentGroupSellerList, tmpDepartmentGroupSellersList...)
  1424. }
  1425. item.ChildrenList = departmentGroupSellerList
  1426. if len(departmentGroupSellerList) > 0 {
  1427. list = append(list, item)
  1428. }
  1429. }
  1430. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER && status == 1 {
  1431. // 权益销售可以看到权益销售部的所有人
  1432. departmentId := 5
  1433. groupList, err := system.GetSysGroupByDepartmentId(departmentId)
  1434. if err != nil {
  1435. br.Msg = "获取失败"
  1436. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  1437. return
  1438. }
  1439. for _, group := range groupList {
  1440. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  1441. groupItem := company.DepartmentGroupSellers{
  1442. AdminId: fmt.Sprint("group_", group.DepartmentId),
  1443. //AdminName string `description:"系统用户名称"`
  1444. RealName: group.GroupName,
  1445. ChildrenList: groupSellerList,
  1446. }
  1447. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  1448. if err != nil {
  1449. br.Msg = "获取小组失败"
  1450. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  1451. return
  1452. }
  1453. for _, team := range teamList {
  1454. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  1455. teamItem := company.DepartmentGroupSellers{
  1456. AdminId: fmt.Sprint("team_", team.GroupId),
  1457. //AdminName string `description:"系统用户名称"`
  1458. RealName: team.GroupName,
  1459. ChildrenList: teamSellerList,
  1460. }
  1461. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  1462. if err != nil {
  1463. br.Msg = "获取销售失败"
  1464. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1465. return
  1466. }
  1467. for _, seller := range sellerList {
  1468. sellerItem := company.DepartmentGroupSellers{
  1469. AdminId: fmt.Sprint(seller.AdminId),
  1470. //AdminName string `description:"系统用户名称"`
  1471. RealName: seller.RealName,
  1472. Authority: seller.Authority,
  1473. RoleTypeCode: seller.RoleTypeCode,
  1474. }
  1475. //fmt.Println("seller.RealName:", seller.RealName)
  1476. teamSellerList = append(teamSellerList, sellerItem)
  1477. }
  1478. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  1479. teamItem.ChildrenList = teamSellerList
  1480. if len(teamSellerList) > 0 {
  1481. groupSellerList = append(groupSellerList, teamItem)
  1482. }
  1483. }
  1484. //分组为0的销售(直属分组)
  1485. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  1486. if err != nil {
  1487. br.Msg = "获取销售失败"
  1488. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1489. return
  1490. }
  1491. if len(groupTeamSellerList) > 0 {
  1492. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  1493. for _, seller := range groupTeamSellerList {
  1494. sellerItem := company.DepartmentGroupSellers{
  1495. AdminId: fmt.Sprint(seller.AdminId),
  1496. //AdminName string `description:"系统用户名称"`
  1497. RealName: seller.RealName,
  1498. Authority: seller.Authority,
  1499. RoleTypeCode: seller.RoleTypeCode,
  1500. }
  1501. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  1502. }
  1503. //排个序
  1504. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  1505. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  1506. }
  1507. //groupItem.ChildrenList = groupSellerList
  1508. //if len(groupSellerList) > 0 {
  1509. // list = append(list, item)
  1510. //}
  1511. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  1512. //if err != nil {
  1513. // br.Msg = "获取销售失败"
  1514. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1515. // return
  1516. //}
  1517. //for _, seller := range sellerList {
  1518. // sellerItem := company.DepartmentGroupSellers{
  1519. // AdminId: fmt.Sprint(seller.AdminId),
  1520. // //AdminName string `description:"系统用户名称"`
  1521. // RealName: seller.RealName,
  1522. // Authority: seller.Authority,
  1523. // RoleTypeCode: seller.RoleTypeCode,
  1524. // }
  1525. // groupSellerList = append(groupSellerList, sellerItem)
  1526. //}
  1527. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  1528. groupItem.ChildrenList = groupSellerList
  1529. if len(groupSellerList) > 0 {
  1530. list = append(list, groupItem)
  1531. }
  1532. }
  1533. //分组为0的销售(直属部门)
  1534. departmentSellerList, err := system.GetDepartmentGroupSysUserList(departmentId, 0, roleCodeTypeStr)
  1535. if err != nil {
  1536. br.Msg = "获取销售失败"
  1537. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1538. return
  1539. }
  1540. if len(departmentSellerList) > 0 {
  1541. tmpDepartmentGroupSeller := make([]company.DepartmentGroupSellers, 0)
  1542. for _, seller := range departmentSellerList {
  1543. sellerItem := company.DepartmentGroupSellers{
  1544. AdminId: fmt.Sprint(seller.AdminId),
  1545. //AdminName string `description:"系统用户名称"`
  1546. RealName: seller.RealName,
  1547. Authority: seller.Authority,
  1548. RoleTypeCode: seller.RoleTypeCode,
  1549. }
  1550. tmpDepartmentGroupSeller = append(tmpDepartmentGroupSeller, sellerItem)
  1551. }
  1552. tmpDepartmentGroupSeller = sortDepartmentGroupSellers(tmpDepartmentGroupSeller)
  1553. list = append(list, tmpDepartmentGroupSeller...)
  1554. }
  1555. } else {
  1556. //看自己
  1557. sellerItem := company.DepartmentGroupSellers{
  1558. AdminId: fmt.Sprint(sysUser.AdminId),
  1559. //AdminName string `description:"系统用户名称"`
  1560. RealName: sysUser.RealName,
  1561. }
  1562. list = append(list, sellerItem)
  1563. }
  1564. } else {
  1565. departmentId := sysUser.DepartmentId
  1566. switch productId {
  1567. case 1:
  1568. departmentId = 2
  1569. case 5:
  1570. departmentId = 5
  1571. }
  1572. //查询整个部门的小组、销售
  1573. groupList, err := system.GetSysGroupByDepartmentId(departmentId)
  1574. if err != nil {
  1575. br.Msg = "获取失败"
  1576. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  1577. return
  1578. }
  1579. for _, group := range groupList {
  1580. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  1581. groupItem := company.DepartmentGroupSellers{
  1582. AdminId: fmt.Sprint("group_", group.DepartmentId),
  1583. //AdminName string `description:"系统用户名称"`
  1584. RealName: group.GroupName,
  1585. ChildrenList: groupSellerList,
  1586. }
  1587. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  1588. if err != nil {
  1589. br.Msg = "获取小组失败"
  1590. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  1591. return
  1592. }
  1593. for _, team := range teamList {
  1594. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  1595. teamItem := company.DepartmentGroupSellers{
  1596. AdminId: fmt.Sprint("team_", team.GroupId),
  1597. //AdminName string `description:"系统用户名称"`
  1598. RealName: team.GroupName,
  1599. ChildrenList: teamSellerList,
  1600. }
  1601. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  1602. if err != nil {
  1603. br.Msg = "获取销售失败"
  1604. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1605. return
  1606. }
  1607. for _, seller := range sellerList {
  1608. sellerItem := company.DepartmentGroupSellers{
  1609. AdminId: fmt.Sprint(seller.AdminId),
  1610. //AdminName string `description:"系统用户名称"`
  1611. RealName: seller.RealName,
  1612. Authority: seller.Authority,
  1613. RoleTypeCode: seller.RoleTypeCode,
  1614. }
  1615. //fmt.Println("seller.RealName:", seller.RealName)
  1616. teamSellerList = append(teamSellerList, sellerItem)
  1617. }
  1618. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  1619. teamItem.ChildrenList = teamSellerList
  1620. if len(teamSellerList) > 0 {
  1621. groupSellerList = append(groupSellerList, teamItem)
  1622. }
  1623. }
  1624. //分组为0的销售(直属分组)
  1625. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  1626. if err != nil {
  1627. br.Msg = "获取销售失败"
  1628. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1629. return
  1630. }
  1631. if len(groupTeamSellerList) > 0 {
  1632. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  1633. for _, seller := range groupTeamSellerList {
  1634. sellerItem := company.DepartmentGroupSellers{
  1635. AdminId: fmt.Sprint(seller.AdminId),
  1636. //AdminName string `description:"系统用户名称"`
  1637. RealName: seller.RealName,
  1638. Authority: seller.Authority,
  1639. RoleTypeCode: seller.RoleTypeCode,
  1640. }
  1641. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  1642. }
  1643. //排个序
  1644. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  1645. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  1646. }
  1647. groupItem.ChildrenList = groupSellerList
  1648. if len(groupSellerList) > 0 {
  1649. list = append(list, groupItem)
  1650. }
  1651. }
  1652. //分组为0的销售(直属部门)
  1653. departmentSellerList, err := system.GetDepartmentGroupSysUserList(departmentId, 0, roleCodeTypeStr)
  1654. if err != nil {
  1655. br.Msg = "获取销售失败"
  1656. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1657. return
  1658. }
  1659. if len(departmentSellerList) > 0 {
  1660. tmpDepartmentGroupSeller := make([]company.DepartmentGroupSellers, 0)
  1661. for _, seller := range departmentSellerList {
  1662. sellerItem := company.DepartmentGroupSellers{
  1663. AdminId: fmt.Sprint(seller.AdminId),
  1664. //AdminName string `description:"系统用户名称"`
  1665. RealName: seller.RealName,
  1666. Authority: seller.Authority,
  1667. RoleTypeCode: seller.RoleTypeCode,
  1668. }
  1669. tmpDepartmentGroupSeller = append(tmpDepartmentGroupSeller, sellerItem)
  1670. }
  1671. //排个序
  1672. tmpDepartmentGroupSeller = sortDepartmentGroupSellers(tmpDepartmentGroupSeller)
  1673. list = append(list, tmpDepartmentGroupSeller...)
  1674. }
  1675. }
  1676. // 海外销售部-目前无权限, 均可见
  1677. seaDepartment, e := system.GetSysDepartmentByName("海外销售部")
  1678. if e != nil && e.Error() != utils.ErrNoRow() {
  1679. br.Msg = "获取失败"
  1680. br.ErrMsg = "获取海外销售部失败, Err: " + e.Error()
  1681. return
  1682. }
  1683. if e == nil {
  1684. // 获取部门下的销售人员
  1685. seaSellers, e := system.GetDepartmentGroupSysUserList(seaDepartment.DepartmentId, 0, "")
  1686. if e != nil {
  1687. br.Msg = "获取失败"
  1688. br.ErrMsg = "获取海外销售失败, Err: " + e.Error()
  1689. return
  1690. }
  1691. // 获取分组
  1692. seaGroups, e := system.GetSysGroupListByDepartmentId(seaDepartment.DepartmentId)
  1693. if e != nil {
  1694. br.Msg = "获取失败"
  1695. br.ErrMsg = "获取海外销售部分组失败, Err: " + e.Error()
  1696. return
  1697. }
  1698. var d company.DepartmentGroupSellers
  1699. d.AdminId = fmt.Sprintf("department_%d", seaDepartment.DepartmentId)
  1700. d.RealName = seaDepartment.DepartmentName
  1701. children := make([]company.DepartmentGroupSellers, 0)
  1702. // 无分组
  1703. if len(seaGroups) == 0 {
  1704. for _, s := range seaSellers {
  1705. children = append(children, company.DepartmentGroupSellers{
  1706. AdminId: strconv.Itoa(s.AdminId),
  1707. RealName: s.RealName,
  1708. RoleTypeCode: s.RoleTypeCode,
  1709. Authority: s.Authority,
  1710. })
  1711. }
  1712. }
  1713. // 有分组
  1714. if len(seaGroups) > 0 {
  1715. // 销售map
  1716. sellerMap := make(map[int][]company.DepartmentGroupSellers)
  1717. for _, s := range seaSellers {
  1718. sellerMap[s.GroupId] = append(sellerMap[s.GroupId], company.DepartmentGroupSellers{
  1719. AdminId: strconv.Itoa(s.AdminId),
  1720. RealName: s.RealName,
  1721. RoleTypeCode: s.RoleTypeCode,
  1722. Authority: s.Authority,
  1723. })
  1724. }
  1725. // 小组map
  1726. childrenMap := make(map[int][]company.DepartmentGroupSellers)
  1727. for _, g := range seaGroups {
  1728. if g.ParentId == 0 {
  1729. continue
  1730. }
  1731. childrenMap[g.ParentId] = append(childrenMap[g.ParentId], company.DepartmentGroupSellers{
  1732. AdminId: fmt.Sprintf("team_%d", g.GroupId),
  1733. RealName: g.GroupName,
  1734. ChildrenList: sellerMap[g.GroupId],
  1735. })
  1736. }
  1737. // 大组
  1738. for _, g := range seaGroups {
  1739. if g.ParentId > 0 {
  1740. continue
  1741. }
  1742. c := childrenMap[g.GroupId]
  1743. if len(sellerMap[g.GroupId]) > 0 {
  1744. c = append(c, sellerMap[g.GroupId]...)
  1745. }
  1746. children = append(children, company.DepartmentGroupSellers{
  1747. AdminId: fmt.Sprintf("group_%d", g.GroupId),
  1748. RealName: g.GroupName,
  1749. ChildrenList: c,
  1750. })
  1751. }
  1752. }
  1753. d.ChildrenList = children
  1754. list = append(list, d)
  1755. }
  1756. br.Ret = 200
  1757. br.Success = true
  1758. br.Msg = "获取成功"
  1759. br.Data = company.DepartmentGroupSellersResp{
  1760. List: list,
  1761. }
  1762. }
  1763. // sortDepartmentGroupSellers 部门用户排序
  1764. func sortDepartmentGroupSellers(adminList []company.DepartmentGroupSellers) (list []company.DepartmentGroupSellers) {
  1765. sellerMap := make(map[int][]company.DepartmentGroupSellers)
  1766. for _, admin := range adminList {
  1767. index := 0 //0:超管,1:部门管理员,2:组长,3:普通人
  1768. switch admin.RoleTypeCode {
  1769. //case utils.ROLE_TYPE_CODE_ADMIN:
  1770. // index = 0
  1771. //case utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_RAI_ADMIN:
  1772. // index = 1
  1773. //case utils.ROLE_TYPE_CODE_FICC_GROUP, utils.ROLE_TYPE_CODE_RAI_GROUP:
  1774. // index = 2
  1775. default:
  1776. //0:无,1:部门负责人,2:小组负责人,3:超级管理员
  1777. switch admin.Authority {
  1778. //case 1:
  1779. // index = 1
  1780. case 2:
  1781. index = 2
  1782. //case 3:
  1783. // index = 0
  1784. default:
  1785. index = 3
  1786. }
  1787. }
  1788. sellerList, ok := sellerMap[index]
  1789. if !ok {
  1790. sellerList = make([]company.DepartmentGroupSellers, 0)
  1791. }
  1792. sellerList = append(sellerList, admin)
  1793. sellerMap[index] = sellerList
  1794. }
  1795. var indexList = []int{0, 1, 2, 3}
  1796. for _, index := range indexList {
  1797. sellerList, ok := sellerMap[index]
  1798. if ok {
  1799. list = append(list, sellerList...)
  1800. }
  1801. }
  1802. return
  1803. }