company_seller.go 80 KB

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