company_seller.go 204 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531
  1. package controllers
  2. import (
  3. "fmt"
  4. "hongze/hz_crm_api/models"
  5. "hongze/hz_crm_api/models/company"
  6. "hongze/hz_crm_api/models/system"
  7. "hongze/hz_crm_api/services"
  8. "hongze/hz_crm_api/utils"
  9. "strconv"
  10. "strings"
  11. )
  12. // 销售管理
  13. type CompanySellerController struct {
  14. BaseAuthController
  15. }
  16. // @Title 获取所有销售信息
  17. // @Description 获取所有销售信息接口
  18. // @Param SellerType query int false "销售类型: 0-所有; 1-FICC; 2-权益"
  19. // @Success 200 {object} company.CompanySellerResp
  20. // @router /seller/list [get]
  21. func (this *CompanySellerController) List() {
  22. br := new(models.BaseResponse).Init()
  23. defer func() {
  24. this.Data["json"] = br
  25. this.ServeJSON()
  26. }()
  27. sysUser := this.SysUser
  28. if sysUser == nil {
  29. br.Msg = "请登录"
  30. br.ErrMsg = "请登录,SysUser Is Empty"
  31. br.Ret = 408
  32. return
  33. }
  34. sellerType, _ := this.GetInt("SellerType", 0)
  35. ficcRoles := []string{
  36. utils.ROLE_TYPE_CODE_FICC_ADMIN,
  37. utils.ROLE_TYPE_CODE_FICC_DEPARTMENT,
  38. utils.ROLE_TYPE_CODE_FICC_GROUP,
  39. utils.ROLE_TYPE_CODE_FICC_TEAM,
  40. utils.ROLE_TYPE_CODE_FICC_SELLER,
  41. }
  42. raiRoles := []string{
  43. utils.ROLE_TYPE_CODE_RAI_ADMIN,
  44. utils.ROLE_TYPE_CODE_RAI_DEPARTMENT,
  45. utils.ROLE_TYPE_CODE_RAI_GROUP,
  46. utils.ROLE_TYPE_CODE_RAI_SELLER,
  47. }
  48. otherRoles := []string{
  49. utils.ROLE_TYPE_CODE_ADMIN,
  50. utils.ROLE_TYPE_CODE_RESEARCHR,
  51. }
  52. roleCodeArr := make([]string, 0)
  53. switch sellerType {
  54. case 1:
  55. roleCodeArr = append(roleCodeArr, ficcRoles...)
  56. case 2:
  57. roleCodeArr = append(roleCodeArr, raiRoles...)
  58. default:
  59. roleCodeArr = append(roleCodeArr, ficcRoles...)
  60. roleCodeArr = append(roleCodeArr, raiRoles...)
  61. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  62. roleCodeArr = append(roleCodeArr, otherRoles...)
  63. }
  64. }
  65. resp := new(company.CompanySellerResp)
  66. //roleTypeCodeStr := `'ficc_admin','ficc_seller','rai_admin','rai_seller','ficc_group','rai_group','ficc_department','rai_department','ficc_sell_team'`
  67. //if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  68. // roleTypeCodeStr = roleTypeCodeStr + `,'researcher','admin'`
  69. //}
  70. //items, err := company.GetCompanySeller(roleTypeCodeStr)
  71. items, err := company.GetCompanySellerByRoleCodes(roleCodeArr)
  72. if err != nil {
  73. br.Msg = "获取失败"
  74. br.ErrMsg = "获取失败,Err:" + err.Error()
  75. return
  76. }
  77. resp.List = items
  78. br.Ret = 200
  79. br.Success = true
  80. br.Msg = "获取成功"
  81. br.Data = resp
  82. }
  83. // @Title 获取组长/组员下销售
  84. // @Description 获取组长/组员下销售接口
  85. // @Param AllSeller query bool true "是否获取部门所有的销售信息"
  86. // @Success 200 {object} company.CompanySellerResp
  87. // @router /seller/check/list [get]
  88. func (this *CompanySellerController) CheckList() {
  89. br := new(models.BaseResponse).Init()
  90. defer func() {
  91. this.Data["json"] = br
  92. this.ServeJSON()
  93. }()
  94. sysUser := this.SysUser
  95. if sysUser == nil {
  96. br.Msg = "请登录"
  97. br.ErrMsg = "请登录,SysUser Is Empty"
  98. br.Ret = 408
  99. return
  100. }
  101. authority := sysUser.Authority
  102. getAllSeller, _ := this.GetBool("AllSeller", false)
  103. var condition string
  104. var pars []interface{}
  105. if getAllSeller != true {
  106. if authority == 1 {
  107. condition += ` AND a.department_id=? `
  108. pars = append(pars, sysUser.DepartmentId)
  109. } else if authority == 2 {
  110. condition += ` AND a.group_id=? `
  111. pars = append(pars, sysUser.GroupId)
  112. }
  113. } else {
  114. productId := services.GetProductId(sysUser.RoleTypeCode)
  115. fmt.Println("productId:", productId)
  116. switch productId {
  117. case 1:
  118. roleTypeCodeList := []string{utils.ROLE_TYPE_CODE_FICC_SELLER, utils.ROLE_TYPE_CODE_FICC_GROUP}
  119. roleTypeCodeListStr := strings.Join(roleTypeCodeList, `","`)
  120. condition += ` AND b.role_type_code IN("` + roleTypeCodeListStr + `") `
  121. case 2:
  122. roleTypeCodeList := []string{utils.ROLE_TYPE_CODE_RAI_SELLER, utils.ROLE_TYPE_CODE_RAI_GROUP}
  123. roleTypeCodeListStr := strings.Join(roleTypeCodeList, `","`)
  124. condition += ` AND b.role_type_code IN("` + roleTypeCodeListStr + `") `
  125. }
  126. }
  127. resp := new(company.CompanySellerResp)
  128. items, err := company.GetCompanyCheckSeller(condition, pars)
  129. if err != nil {
  130. br.Msg = "获取失败"
  131. br.ErrMsg = "获取失败,Err:" + err.Error()
  132. return
  133. }
  134. if len(items) == 0 {
  135. items = make([]*company.CompanySellers, 0)
  136. }
  137. resp.List = items
  138. br.Ret = 200
  139. br.Success = true
  140. br.Msg = "获取成功"
  141. br.Data = resp
  142. }
  143. // CheckListV2
  144. // @Title 获取组长/组员下销售(根据部门、分组)
  145. // @Description 获取组长/组员下销售(根据部门、分组)接口
  146. // @Param AllSeller query bool true "是否获取部门所有的销售信息"
  147. // @Param Status query int true "客户状态 1:流失 0:非流失"
  148. // @Param AllEnabled query bool true "是否获取包含禁用的用户"
  149. // @Success 200 {object} company.DepartmentGroupSellersResp
  150. // @router /seller/check/listV2 [get]
  151. func (this *CompanySellerController) CheckListV2() {
  152. br := new(models.BaseResponse).Init()
  153. defer func() {
  154. this.Data["json"] = br
  155. this.ServeJSON()
  156. }()
  157. sysUser := this.SysUser
  158. if sysUser == nil {
  159. br.Msg = "请登录"
  160. br.ErrMsg = "请登录,SysUser Is Empty"
  161. br.Ret = 408
  162. return
  163. }
  164. roleCodeTypeStr := ``
  165. productId := services.GetProductId(sysUser.RoleTypeCode)
  166. switch productId {
  167. case 1:
  168. roleCodeTypeStr = `"` + utils.ROLE_TYPE_CODE_FICC_SELLER + `","` + utils.ROLE_TYPE_CODE_FICC_GROUP + `","` + utils.ROLE_TYPE_CODE_FICC_TEAM + `"`
  169. case 2:
  170. roleCodeTypeStr = `"` + utils.ROLE_TYPE_CODE_RAI_SELLER + `","` + utils.ROLE_TYPE_CODE_RAI_GROUP + `"`
  171. }
  172. // ficc管理员,不要只查销售
  173. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  174. roleCodeTypeStr = ``
  175. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  176. // 权益管理员,查看所有权益的账号
  177. 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 + `"`
  178. }
  179. getAllSeller, _ := this.GetBool("AllSeller", false)
  180. getAllUser, _ := this.GetBool("AllUser", false)
  181. status, _ := this.GetInt("Status", 0)
  182. getAllEnabled, _ := this.GetBool("AllEnabled", false)
  183. enabled := 1 //默认只获取正常状态的用户
  184. if getAllEnabled { //获取所有状态的用户
  185. enabled = -1
  186. }
  187. list := make([]company.DepartmentGroupSellers, 0)
  188. if getAllUser {
  189. departmentList, err := system.GetDepartmentList()
  190. if err != nil {
  191. br.Msg = "获取失败"
  192. br.ErrMsg = "获取部门失败,Err:" + err.Error()
  193. return
  194. }
  195. for _, department := range departmentList {
  196. departmentGroupSellerList := make([]company.DepartmentGroupSellers, 0)
  197. item := company.DepartmentGroupSellers{
  198. AdminId: fmt.Sprint("department_", department.DepartmentId),
  199. //AdminName string `description:"系统用户名称"`
  200. RealName: department.DepartmentName,
  201. ChildrenList: departmentGroupSellerList,
  202. }
  203. groupList, err := system.GetSysGroupByDepartmentId(department.DepartmentId)
  204. if err != nil {
  205. br.Msg = "获取失败"
  206. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  207. return
  208. }
  209. for _, group := range groupList {
  210. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  211. groupItem := company.DepartmentGroupSellers{
  212. AdminId: fmt.Sprint("group_", group.DepartmentId),
  213. //AdminName string `description:"系统用户名称"`
  214. RealName: group.GroupName,
  215. ChildrenList: groupSellerList,
  216. }
  217. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  218. if err != nil {
  219. br.Msg = "获取小组失败"
  220. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  221. return
  222. }
  223. for _, team := range teamList {
  224. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  225. teamItem := company.DepartmentGroupSellers{
  226. AdminId: fmt.Sprint("team_", team.GroupId),
  227. //AdminName string `description:"系统用户名称"`
  228. RealName: team.GroupName,
  229. ChildrenList: teamSellerList,
  230. }
  231. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  232. if err != nil {
  233. br.Msg = "获取销售失败"
  234. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  235. return
  236. }
  237. for _, seller := range sellerList {
  238. sellerItem := company.DepartmentGroupSellers{
  239. AdminId: fmt.Sprint(seller.AdminId),
  240. //AdminName string `description:"系统用户名称"`
  241. RealName: seller.RealName,
  242. Authority: seller.Authority,
  243. RoleTypeCode: seller.RoleTypeCode,
  244. }
  245. //fmt.Println("seller.RealName:", seller.RealName)
  246. teamSellerList = append(teamSellerList, sellerItem)
  247. }
  248. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  249. teamItem.ChildrenList = teamSellerList
  250. if len(teamSellerList) > 0 {
  251. groupSellerList = append(groupSellerList, teamItem)
  252. }
  253. }
  254. //分组为0的销售(直属分组)
  255. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  256. if err != nil {
  257. br.Msg = "获取销售失败"
  258. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  259. return
  260. }
  261. if len(groupTeamSellerList) > 0 {
  262. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  263. for _, seller := range groupTeamSellerList {
  264. sellerItem := company.DepartmentGroupSellers{
  265. AdminId: fmt.Sprint(seller.AdminId),
  266. //AdminName string `description:"系统用户名称"`
  267. RealName: seller.RealName,
  268. Authority: seller.Authority,
  269. RoleTypeCode: seller.RoleTypeCode,
  270. }
  271. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  272. }
  273. //排个序
  274. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  275. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  276. }
  277. //groupItem.ChildrenList = groupSellerList
  278. //if len(groupSellerList) > 0 {
  279. // list = append(list, item)
  280. //}
  281. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  282. //if err != nil {
  283. // br.Msg = "获取销售失败"
  284. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  285. // return
  286. //}
  287. //for _, seller := range sellerList {
  288. // sellerItem := company.DepartmentGroupSellers{
  289. // AdminId: fmt.Sprint(seller.AdminId),
  290. // //AdminName string `description:"系统用户名称"`
  291. // RealName: seller.RealName,
  292. // Authority: seller.Authority,
  293. // RoleTypeCode: seller.RoleTypeCode,
  294. // }
  295. // groupSellerList = append(groupSellerList, sellerItem)
  296. //}
  297. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  298. groupItem.ChildrenList = groupSellerList
  299. if len(groupSellerList) > 0 {
  300. departmentGroupSellerList = append(departmentGroupSellerList, groupItem)
  301. }
  302. }
  303. //分组为0的销售(直属部门)
  304. departmentSellerList, err := system.GetDepartmentGroupSysUserList(department.DepartmentId, 0, roleCodeTypeStr)
  305. if err != nil {
  306. br.Msg = "获取销售失败"
  307. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  308. return
  309. }
  310. if len(departmentSellerList) > 0 {
  311. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  312. for _, seller := range departmentSellerList {
  313. sellerItem := company.DepartmentGroupSellers{
  314. AdminId: fmt.Sprint(seller.AdminId),
  315. //AdminName string `description:"系统用户名称"`
  316. RealName: seller.RealName,
  317. Authority: seller.Authority,
  318. RoleTypeCode: seller.RoleTypeCode,
  319. }
  320. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  321. }
  322. //排个序
  323. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  324. departmentGroupSellerList = append(departmentGroupSellerList, tmpDepartmentGroupSellersList...)
  325. }
  326. item.ChildrenList = departmentGroupSellerList
  327. if len(departmentGroupSellerList) > 0 {
  328. list = append(list, item)
  329. }
  330. }
  331. br.Ret = 200
  332. br.Success = true
  333. br.Msg = "获取成功"
  334. br.Data = company.DepartmentGroupSellersResp{
  335. List: list,
  336. }
  337. return
  338. }
  339. if getAllSeller == false {
  340. //超管看部门、小组、销售
  341. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  342. departmentList, err := system.GetDepartmentList()
  343. if err != nil {
  344. br.Msg = "获取失败"
  345. br.ErrMsg = "获取部门失败,Err:" + err.Error()
  346. return
  347. }
  348. for _, department := range departmentList {
  349. departmentGroupSellerList := make([]company.DepartmentGroupSellers, 0)
  350. item := company.DepartmentGroupSellers{
  351. AdminId: fmt.Sprint("department_", department.DepartmentId),
  352. //AdminName string `description:"系统用户名称"`
  353. RealName: department.DepartmentName,
  354. ChildrenList: departmentGroupSellerList,
  355. }
  356. groupList, err := system.GetSysGroupByDepartmentId(department.DepartmentId)
  357. if err != nil {
  358. br.Msg = "获取失败"
  359. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  360. return
  361. }
  362. for _, group := range groupList {
  363. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  364. groupItem := company.DepartmentGroupSellers{
  365. AdminId: fmt.Sprint("group_", group.DepartmentId),
  366. //AdminName string `description:"系统用户名称"`
  367. RealName: group.GroupName,
  368. ChildrenList: groupSellerList,
  369. }
  370. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  371. if err != nil {
  372. br.Msg = "获取小组失败"
  373. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  374. return
  375. }
  376. for _, team := range teamList {
  377. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  378. teamItem := company.DepartmentGroupSellers{
  379. AdminId: fmt.Sprint("team_", team.GroupId),
  380. //AdminName string `description:"系统用户名称"`
  381. RealName: team.GroupName,
  382. ChildrenList: teamSellerList,
  383. }
  384. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  385. if err != nil {
  386. br.Msg = "获取销售失败"
  387. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  388. return
  389. }
  390. for _, seller := range sellerList {
  391. sellerItem := company.DepartmentGroupSellers{
  392. AdminId: fmt.Sprint(seller.AdminId),
  393. //AdminName string `description:"系统用户名称"`
  394. RealName: seller.RealName,
  395. Authority: seller.Authority,
  396. RoleTypeCode: seller.RoleTypeCode,
  397. }
  398. //fmt.Println("seller.RealName:", seller.RealName)
  399. teamSellerList = append(teamSellerList, sellerItem)
  400. }
  401. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  402. teamItem.ChildrenList = teamSellerList
  403. if len(teamSellerList) > 0 {
  404. groupSellerList = append(groupSellerList, teamItem)
  405. }
  406. }
  407. //分组为0的销售(直属分组)
  408. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  409. if err != nil {
  410. br.Msg = "获取销售失败"
  411. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  412. return
  413. }
  414. if len(groupTeamSellerList) > 0 {
  415. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  416. for _, seller := range groupTeamSellerList {
  417. sellerItem := company.DepartmentGroupSellers{
  418. AdminId: fmt.Sprint(seller.AdminId),
  419. //AdminName string `description:"系统用户名称"`
  420. RealName: seller.RealName,
  421. Authority: seller.Authority,
  422. RoleTypeCode: seller.RoleTypeCode,
  423. }
  424. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  425. }
  426. //排个序
  427. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  428. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  429. }
  430. //groupItem.ChildrenList = groupSellerList
  431. //if len(groupSellerList) > 0 {
  432. // list = append(list, item)
  433. //}
  434. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  435. //if err != nil {
  436. // br.Msg = "获取销售失败"
  437. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  438. // return
  439. //}
  440. //for _, seller := range sellerList {
  441. // sellerItem := company.DepartmentGroupSellers{
  442. // AdminId: fmt.Sprint(seller.AdminId),
  443. // //AdminName string `description:"系统用户名称"`
  444. // RealName: seller.RealName,
  445. // Authority: seller.Authority,
  446. // RoleTypeCode: seller.RoleTypeCode,
  447. // }
  448. // groupSellerList = append(groupSellerList, sellerItem)
  449. //}
  450. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  451. groupItem.ChildrenList = groupSellerList
  452. if len(groupSellerList) > 0 {
  453. departmentGroupSellerList = append(departmentGroupSellerList, groupItem)
  454. }
  455. }
  456. //分组为0的销售(直属部门)
  457. departmentSellerList, err := system.GetDepartmentGroupSysUserList(department.DepartmentId, 0, roleCodeTypeStr)
  458. if err != nil {
  459. br.Msg = "获取销售失败"
  460. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  461. return
  462. }
  463. if len(departmentSellerList) > 0 {
  464. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  465. for _, seller := range departmentSellerList {
  466. sellerItem := company.DepartmentGroupSellers{
  467. AdminId: fmt.Sprint(seller.AdminId),
  468. //AdminName string `description:"系统用户名称"`
  469. RealName: seller.RealName,
  470. Authority: seller.Authority,
  471. RoleTypeCode: seller.RoleTypeCode,
  472. }
  473. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  474. }
  475. //排个序
  476. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  477. departmentGroupSellerList = append(departmentGroupSellerList, tmpDepartmentGroupSellersList...)
  478. }
  479. item.ChildrenList = departmentGroupSellerList
  480. if len(departmentGroupSellerList) > 0 {
  481. list = append(list, item)
  482. }
  483. }
  484. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM || sysUser.Authority == 4 {
  485. //销售组长看销售
  486. if status == 0 {
  487. directorId := sysUser.GroupId
  488. fmt.Println("directorId:", directorId)
  489. groupList, err := system.GetSysGroupByDirectorId(directorId)
  490. if err != nil {
  491. br.Msg = "获取失败"
  492. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  493. return
  494. }
  495. for _, group := range groupList {
  496. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  497. groupItem := company.DepartmentGroupSellers{
  498. AdminId: fmt.Sprint("group_", group.DepartmentId),
  499. //AdminName string `description:"系统用户名称"`
  500. RealName: group.GroupName,
  501. ChildrenList: groupSellerList,
  502. }
  503. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  504. if err != nil {
  505. br.Msg = "获取小组失败"
  506. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  507. return
  508. }
  509. for _, team := range teamList {
  510. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  511. teamItem := company.DepartmentGroupSellers{
  512. AdminId: fmt.Sprint("team_", team.GroupId),
  513. //AdminName string `description:"系统用户名称"`
  514. RealName: team.GroupName,
  515. ChildrenList: teamSellerList,
  516. }
  517. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  518. if err != nil {
  519. br.Msg = "获取销售失败"
  520. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  521. return
  522. }
  523. for _, seller := range sellerList {
  524. sellerItem := company.DepartmentGroupSellers{
  525. AdminId: fmt.Sprint(seller.AdminId),
  526. //AdminName string `description:"系统用户名称"`
  527. RealName: seller.RealName,
  528. Authority: seller.Authority,
  529. RoleTypeCode: seller.RoleTypeCode,
  530. }
  531. //fmt.Println("seller.RealName:", seller.RealName)
  532. teamSellerList = append(teamSellerList, sellerItem)
  533. }
  534. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  535. teamItem.ChildrenList = teamSellerList
  536. if len(teamSellerList) > 0 {
  537. groupSellerList = append(groupSellerList, teamItem)
  538. }
  539. }
  540. //分组为0的销售(直属分组)
  541. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  542. if err != nil {
  543. br.Msg = "获取销售失败"
  544. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  545. return
  546. }
  547. if len(groupTeamSellerList) > 0 {
  548. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  549. for _, seller := range groupTeamSellerList {
  550. sellerItem := company.DepartmentGroupSellers{
  551. AdminId: fmt.Sprint(seller.AdminId),
  552. //AdminName string `description:"系统用户名称"`
  553. RealName: seller.RealName,
  554. Authority: seller.Authority,
  555. RoleTypeCode: seller.RoleTypeCode,
  556. }
  557. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  558. }
  559. //排个序
  560. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  561. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  562. }
  563. groupItem.ChildrenList = groupSellerList
  564. if len(groupSellerList) > 0 {
  565. list = append(list, groupItem)
  566. }
  567. }
  568. } else {
  569. departmentStr := `1,2`
  570. departmentList, err := system.GetDepartmentListByIds(departmentStr)
  571. if err != nil {
  572. br.Msg = "获取失败"
  573. br.ErrMsg = "获取部门失败,Err:" + err.Error()
  574. return
  575. }
  576. for _, department := range departmentList {
  577. departmentGroupSellerList := make([]company.DepartmentGroupSellers, 0)
  578. item := company.DepartmentGroupSellers{
  579. AdminId: fmt.Sprint("department_", department.DepartmentId),
  580. //AdminName string `description:"系统用户名称"`
  581. RealName: department.DepartmentName,
  582. ChildrenList: departmentGroupSellerList,
  583. }
  584. groupList, err := system.GetSysGroupByDepartmentId(department.DepartmentId)
  585. if err != nil {
  586. br.Msg = "获取失败"
  587. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  588. return
  589. }
  590. for _, group := range groupList {
  591. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  592. groupItem := company.DepartmentGroupSellers{
  593. AdminId: fmt.Sprint("group_", group.DepartmentId),
  594. //AdminName string `description:"系统用户名称"`
  595. RealName: group.GroupName,
  596. ChildrenList: groupSellerList,
  597. }
  598. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  599. if err != nil {
  600. br.Msg = "获取小组失败"
  601. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  602. return
  603. }
  604. for _, team := range teamList {
  605. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  606. teamItem := company.DepartmentGroupSellers{
  607. AdminId: fmt.Sprint("team_", team.GroupId),
  608. //AdminName string `description:"系统用户名称"`
  609. RealName: team.GroupName,
  610. ChildrenList: teamSellerList,
  611. }
  612. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  613. if err != nil {
  614. br.Msg = "获取销售失败"
  615. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  616. return
  617. }
  618. for _, seller := range sellerList {
  619. sellerItem := company.DepartmentGroupSellers{
  620. AdminId: fmt.Sprint(seller.AdminId),
  621. //AdminName string `description:"系统用户名称"`
  622. RealName: seller.RealName,
  623. Authority: seller.Authority,
  624. RoleTypeCode: seller.RoleTypeCode,
  625. }
  626. //fmt.Println("seller.RealName:", seller.RealName)
  627. teamSellerList = append(teamSellerList, sellerItem)
  628. }
  629. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  630. teamItem.ChildrenList = teamSellerList
  631. if len(teamSellerList) > 0 {
  632. groupSellerList = append(groupSellerList, teamItem)
  633. }
  634. }
  635. //分组为0的人,不光是销售(直属分组)
  636. groupTeamSellerList, err := system.GetGroupSysUserList(group.GroupId)
  637. if err != nil {
  638. br.Msg = "获取销售失败"
  639. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  640. return
  641. }
  642. if len(groupTeamSellerList) > 0 {
  643. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  644. for _, seller := range groupTeamSellerList {
  645. sellerItem := company.DepartmentGroupSellers{
  646. AdminId: fmt.Sprint(seller.AdminId),
  647. //AdminName string `description:"系统用户名称"`
  648. RealName: seller.RealName,
  649. Authority: seller.Authority,
  650. RoleTypeCode: seller.RoleTypeCode,
  651. }
  652. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  653. }
  654. //排个序
  655. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  656. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  657. }
  658. //groupItem.ChildrenList = groupSellerList
  659. //if len(groupSellerList) > 0 {
  660. // list = append(list, item)
  661. //}
  662. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  663. //if err != nil {
  664. // br.Msg = "获取销售失败"
  665. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  666. // return
  667. //}
  668. //for _, seller := range sellerList {
  669. // sellerItem := company.DepartmentGroupSellers{
  670. // AdminId: fmt.Sprint(seller.AdminId),
  671. // //AdminName string `description:"系统用户名称"`
  672. // RealName: seller.RealName,
  673. // Authority: seller.Authority,
  674. // RoleTypeCode: seller.RoleTypeCode,
  675. // }
  676. // groupSellerList = append(groupSellerList, sellerItem)
  677. //}
  678. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  679. groupItem.ChildrenList = groupSellerList
  680. if len(groupSellerList) > 0 {
  681. departmentGroupSellerList = append(departmentGroupSellerList, groupItem)
  682. }
  683. }
  684. //分组为0的人,不光是销售(直属部门)
  685. departmentSellerList, err := system.GetDepartmentGroupSysUserList(department.DepartmentId, 0, "")
  686. if err != nil {
  687. br.Msg = "获取销售失败"
  688. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  689. return
  690. }
  691. if len(departmentSellerList) > 0 {
  692. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  693. for _, seller := range departmentSellerList {
  694. sellerItem := company.DepartmentGroupSellers{
  695. AdminId: fmt.Sprint(seller.AdminId),
  696. //AdminName string `description:"系统用户名称"`
  697. RealName: seller.RealName,
  698. Authority: seller.Authority,
  699. RoleTypeCode: seller.RoleTypeCode,
  700. }
  701. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  702. }
  703. //排个序
  704. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  705. departmentGroupSellerList = append(departmentGroupSellerList, tmpDepartmentGroupSellersList...)
  706. }
  707. item.ChildrenList = departmentGroupSellerList
  708. if len(departmentGroupSellerList) > 0 {
  709. list = append(list, item)
  710. }
  711. }
  712. }
  713. } 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管理员
  714. departmentStr := `2,5,7` //合规
  715. switch sysUser.RoleTypeCode {
  716. case utils.ROLE_TYPE_CODE_FINANCE: //财务
  717. departmentStr = `2,5,8`
  718. case utils.ROLE_TYPE_CODE_FICC_ADMIN: //ficc管理员
  719. departmentStr = utils.GetFiccAdminDepartmentIds()
  720. }
  721. departmentList, err := system.GetDepartmentListByIds(departmentStr)
  722. if err != nil {
  723. br.Msg = "获取失败"
  724. br.ErrMsg = "获取部门失败,Err:" + err.Error()
  725. return
  726. }
  727. for _, department := range departmentList {
  728. fmt.Println(department)
  729. departmentGroupSellerList := make([]company.DepartmentGroupSellers, 0)
  730. item := company.DepartmentGroupSellers{
  731. AdminId: fmt.Sprint("department_", department.DepartmentId),
  732. //AdminName string `description:"系统用户名称"`
  733. RealName: department.DepartmentName,
  734. ChildrenList: departmentGroupSellerList,
  735. }
  736. groupList, err := system.GetSysGroupByDepartmentId(department.DepartmentId)
  737. if err != nil {
  738. br.Msg = "获取失败"
  739. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  740. return
  741. }
  742. for _, group := range groupList {
  743. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  744. groupItem := company.DepartmentGroupSellers{
  745. AdminId: fmt.Sprint("group_", group.DepartmentId),
  746. //AdminName string `description:"系统用户名称"`
  747. RealName: group.GroupName,
  748. ChildrenList: groupSellerList,
  749. }
  750. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  751. if err != nil {
  752. br.Msg = "获取小组失败"
  753. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  754. return
  755. }
  756. for _, team := range teamList {
  757. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  758. teamItem := company.DepartmentGroupSellers{
  759. AdminId: fmt.Sprint("team_", team.GroupId),
  760. //AdminName string `description:"系统用户名称"`
  761. RealName: team.GroupName,
  762. ChildrenList: teamSellerList,
  763. }
  764. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  765. if err != nil {
  766. br.Msg = "获取销售失败"
  767. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  768. return
  769. }
  770. for _, seller := range sellerList {
  771. sellerItem := company.DepartmentGroupSellers{
  772. AdminId: fmt.Sprint(seller.AdminId),
  773. //AdminName string `description:"系统用户名称"`
  774. RealName: seller.RealName,
  775. Authority: seller.Authority,
  776. RoleTypeCode: seller.RoleTypeCode,
  777. }
  778. //fmt.Println("seller.RealName:", seller.RealName)
  779. teamSellerList = append(teamSellerList, sellerItem)
  780. }
  781. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  782. teamItem.ChildrenList = teamSellerList
  783. if len(teamSellerList) > 0 {
  784. groupSellerList = append(groupSellerList, teamItem)
  785. }
  786. }
  787. //分组为0的销售(直属分组)
  788. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  789. if err != nil {
  790. br.Msg = "获取销售失败"
  791. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  792. return
  793. }
  794. if len(groupTeamSellerList) > 0 {
  795. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  796. for _, seller := range groupTeamSellerList {
  797. sellerItem := company.DepartmentGroupSellers{
  798. AdminId: fmt.Sprint(seller.AdminId),
  799. //AdminName string `description:"系统用户名称"`
  800. RealName: seller.RealName,
  801. Authority: seller.Authority,
  802. RoleTypeCode: seller.RoleTypeCode,
  803. }
  804. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  805. }
  806. //排个序
  807. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  808. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  809. }
  810. //groupItem.ChildrenList = groupSellerList
  811. //if len(groupSellerList) > 0 {
  812. // list = append(list, item)
  813. //}
  814. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  815. //if err != nil {
  816. // br.Msg = "获取销售失败"
  817. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  818. // return
  819. //}
  820. //for _, seller := range sellerList {
  821. // sellerItem := company.DepartmentGroupSellers{
  822. // AdminId: fmt.Sprint(seller.AdminId),
  823. // //AdminName string `description:"系统用户名称"`
  824. // RealName: seller.RealName,
  825. // Authority: seller.Authority,
  826. // RoleTypeCode: seller.RoleTypeCode,
  827. // }
  828. // groupSellerList = append(groupSellerList, sellerItem)
  829. //}
  830. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  831. groupItem.ChildrenList = groupSellerList
  832. if len(groupSellerList) > 0 {
  833. departmentGroupSellerList = append(departmentGroupSellerList, groupItem)
  834. }
  835. }
  836. //分组为0的销售(直属部门)
  837. departmentSellerList, err := system.GetDepartmentGroupSysUserList(department.DepartmentId, 0, roleCodeTypeStr)
  838. if err != nil {
  839. br.Msg = "获取销售失败"
  840. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  841. return
  842. }
  843. if len(departmentSellerList) > 0 {
  844. tmpDepartmentGroupSellerList := make([]company.DepartmentGroupSellers, 0)
  845. for _, seller := range departmentSellerList {
  846. sellerItem := company.DepartmentGroupSellers{
  847. AdminId: fmt.Sprint(seller.AdminId),
  848. //AdminName string `description:"系统用户名称"`
  849. RealName: seller.RealName,
  850. Authority: seller.Authority,
  851. RoleTypeCode: seller.RoleTypeCode,
  852. }
  853. tmpDepartmentGroupSellerList = append(tmpDepartmentGroupSellerList, sellerItem)
  854. }
  855. //排个序
  856. tmpDepartmentGroupSellerList = sortDepartmentGroupSellers(tmpDepartmentGroupSellerList)
  857. departmentGroupSellerList = append(departmentGroupSellerList, tmpDepartmentGroupSellerList...)
  858. }
  859. item.ChildrenList = departmentGroupSellerList
  860. if len(departmentGroupSellerList) > 0 {
  861. list = append(list, item)
  862. }
  863. }
  864. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN || sysUser.Authority == 1 {
  865. //部门管理员看小组、销售
  866. departmentId := sysUser.DepartmentId
  867. switch sysUser.RoleTypeCode {
  868. case utils.ROLE_TYPE_CODE_RAI_ADMIN: //权益管理员
  869. departmentId = 5
  870. case utils.ROLE_TYPE_CODE_FICC_ADMIN: //ficc管理员
  871. departmentId = 2
  872. }
  873. groupList, err := system.GetSysGroupByDepartmentId(departmentId)
  874. if err != nil {
  875. br.Msg = "获取失败"
  876. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  877. return
  878. }
  879. for _, group := range groupList {
  880. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  881. groupItem := company.DepartmentGroupSellers{
  882. AdminId: fmt.Sprint("group_", group.DepartmentId),
  883. //AdminName string `description:"系统用户名称"`
  884. RealName: group.GroupName,
  885. ChildrenList: groupSellerList,
  886. }
  887. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  888. if err != nil {
  889. br.Msg = "获取小组失败"
  890. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  891. return
  892. }
  893. for _, team := range teamList {
  894. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  895. teamItem := company.DepartmentGroupSellers{
  896. AdminId: fmt.Sprint("team_", team.GroupId),
  897. //AdminName string `description:"系统用户名称"`
  898. RealName: team.GroupName,
  899. ChildrenList: teamSellerList,
  900. }
  901. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  902. if err != nil {
  903. br.Msg = "获取销售失败"
  904. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  905. return
  906. }
  907. for _, seller := range sellerList {
  908. sellerItem := company.DepartmentGroupSellers{
  909. AdminId: fmt.Sprint(seller.AdminId),
  910. //AdminName string `description:"系统用户名称"`
  911. RealName: seller.RealName,
  912. Authority: seller.Authority,
  913. RoleTypeCode: seller.RoleTypeCode,
  914. }
  915. //fmt.Println("seller.RealName:", seller.RealName)
  916. teamSellerList = append(teamSellerList, sellerItem)
  917. }
  918. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  919. teamItem.ChildrenList = teamSellerList
  920. if len(teamSellerList) > 0 {
  921. groupSellerList = append(groupSellerList, teamItem)
  922. }
  923. }
  924. //分组为0的销售(直属分组)
  925. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  926. if err != nil {
  927. br.Msg = "获取销售失败"
  928. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  929. return
  930. }
  931. if len(groupTeamSellerList) > 0 {
  932. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  933. for _, seller := range groupTeamSellerList {
  934. sellerItem := company.DepartmentGroupSellers{
  935. AdminId: fmt.Sprint(seller.AdminId),
  936. //AdminName string `description:"系统用户名称"`
  937. RealName: seller.RealName,
  938. Authority: seller.Authority,
  939. RoleTypeCode: seller.RoleTypeCode,
  940. }
  941. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  942. }
  943. //排个序
  944. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  945. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  946. }
  947. //groupItem.ChildrenList = groupSellerList
  948. //if len(groupSellerList) > 0 {
  949. // list = append(list, item)
  950. //}
  951. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  952. //if err != nil {
  953. // br.Msg = "获取销售失败"
  954. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  955. // return
  956. //}
  957. //for _, seller := range sellerList {
  958. // sellerItem := company.DepartmentGroupSellers{
  959. // AdminId: fmt.Sprint(seller.AdminId),
  960. // //AdminName string `description:"系统用户名称"`
  961. // RealName: seller.RealName,
  962. // Authority: seller.Authority,
  963. // RoleTypeCode: seller.RoleTypeCode,
  964. // }
  965. // groupSellerList = append(groupSellerList, sellerItem)
  966. //}
  967. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  968. groupItem.ChildrenList = groupSellerList
  969. if len(groupSellerList) > 0 {
  970. list = append(list, groupItem)
  971. }
  972. }
  973. //分组为0的销售(直属部门)
  974. departmentSellerList, err := system.GetDepartmentGroupSysUserList(departmentId, 0, roleCodeTypeStr)
  975. if err != nil {
  976. br.Msg = "获取销售失败"
  977. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  978. return
  979. }
  980. if len(departmentSellerList) > 0 {
  981. tmpDepartmentGroupSeller := make([]company.DepartmentGroupSellers, 0)
  982. for _, seller := range departmentSellerList {
  983. sellerItem := company.DepartmentGroupSellers{
  984. AdminId: fmt.Sprint(seller.AdminId),
  985. //AdminName string `description:"系统用户名称"`
  986. RealName: seller.RealName,
  987. Authority: seller.Authority,
  988. RoleTypeCode: seller.RoleTypeCode,
  989. }
  990. tmpDepartmentGroupSeller = append(tmpDepartmentGroupSeller, sellerItem)
  991. }
  992. tmpDepartmentGroupSeller = sortDepartmentGroupSellers(tmpDepartmentGroupSeller)
  993. list = append(list, tmpDepartmentGroupSeller...)
  994. }
  995. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP || (sysUser.Authority == 2 && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_FICC_GROUP) {
  996. // 权益组长看小组
  997. if status == 0 {
  998. sellerList, err := system.GetTeamSysUserList(sysUser.GroupId, enabled)
  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. //fmt.Println("seller.RealName:", seller.RealName)
  1013. list = append(list, sellerItem)
  1014. }
  1015. list = sortDepartmentGroupSellers(list)
  1016. //正常来说没有所有人都应该在某个小组下,要不就是小组名为 无 的小组
  1017. //分组为0的销售(直属分组)
  1018. //groupTeamSellerList, err := system.GetGrooupsysUserList(sysUser.GroupId, 0, roleCodeTypeStr)
  1019. //if err != nil {
  1020. // br.Msg = "获取销售失败"
  1021. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1022. // return
  1023. //}
  1024. //if len(groupTeamSellerList) > 0 {
  1025. // tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  1026. // for _, seller := range groupTeamSellerList {
  1027. // sellerItem := company.DepartmentGroupSellers{
  1028. // AdminId: fmt.Sprint(seller.AdminId),
  1029. // //AdminName string `description:"系统用户名称"`
  1030. // RealName: seller.RealName,
  1031. // Authority: seller.Authority,
  1032. // RoleTypeCode: seller.RoleTypeCode,
  1033. // }
  1034. // tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  1035. // }
  1036. // //排个序
  1037. // tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  1038. // list = append(list, tmpDepartmentGroupSellersList...)
  1039. //}
  1040. //sellerList, err := system.GetDepartmentGroupSysUserList(sysUser.DepartmentId, sysUser.GroupId, roleCodeTypeStr)
  1041. //if err != nil {
  1042. // br.Msg = "获取销售失败"
  1043. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1044. // return
  1045. //}
  1046. //for _, seller := range sellerList {
  1047. // sellerItem := company.DepartmentGroupSellers{
  1048. // AdminId: fmt.Sprint(seller.AdminId),
  1049. // //AdminName string `description:"系统用户名称"`
  1050. // RealName: seller.RealName,
  1051. // Authority: seller.Authority,
  1052. // RoleTypeCode: seller.RoleTypeCode,
  1053. // }
  1054. // list = append(list, sellerItem)
  1055. // list = sortDepartmentGroupSellers(list)
  1056. //}
  1057. } else {
  1058. departmentId := 5
  1059. groupList, err := system.GetSysGroupByDepartmentId(departmentId)
  1060. if err != nil {
  1061. br.Msg = "获取失败"
  1062. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  1063. return
  1064. }
  1065. for _, group := range groupList {
  1066. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  1067. groupItem := company.DepartmentGroupSellers{
  1068. AdminId: fmt.Sprint("group_", group.DepartmentId),
  1069. //AdminName string `description:"系统用户名称"`
  1070. RealName: group.GroupName,
  1071. ChildrenList: groupSellerList,
  1072. }
  1073. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  1074. if err != nil {
  1075. br.Msg = "获取小组失败"
  1076. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  1077. return
  1078. }
  1079. for _, team := range teamList {
  1080. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  1081. teamItem := company.DepartmentGroupSellers{
  1082. AdminId: fmt.Sprint("team_", team.GroupId),
  1083. //AdminName string `description:"系统用户名称"`
  1084. RealName: team.GroupName,
  1085. ChildrenList: teamSellerList,
  1086. }
  1087. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  1088. if err != nil {
  1089. br.Msg = "获取销售失败"
  1090. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1091. return
  1092. }
  1093. for _, seller := range sellerList {
  1094. sellerItem := company.DepartmentGroupSellers{
  1095. AdminId: fmt.Sprint(seller.AdminId),
  1096. //AdminName string `description:"系统用户名称"`
  1097. RealName: seller.RealName,
  1098. Authority: seller.Authority,
  1099. RoleTypeCode: seller.RoleTypeCode,
  1100. }
  1101. //fmt.Println("seller.RealName:", seller.RealName)
  1102. teamSellerList = append(teamSellerList, sellerItem)
  1103. }
  1104. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  1105. teamItem.ChildrenList = teamSellerList
  1106. if len(teamSellerList) > 0 {
  1107. groupSellerList = append(groupSellerList, teamItem)
  1108. }
  1109. }
  1110. //分组为0的销售(直属分组)
  1111. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  1112. if err != nil {
  1113. br.Msg = "获取销售失败"
  1114. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1115. return
  1116. }
  1117. if len(groupTeamSellerList) > 0 {
  1118. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  1119. for _, seller := range groupTeamSellerList {
  1120. sellerItem := company.DepartmentGroupSellers{
  1121. AdminId: fmt.Sprint(seller.AdminId),
  1122. //AdminName string `description:"系统用户名称"`
  1123. RealName: seller.RealName,
  1124. Authority: seller.Authority,
  1125. RoleTypeCode: seller.RoleTypeCode,
  1126. }
  1127. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  1128. }
  1129. //排个序
  1130. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  1131. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  1132. }
  1133. //groupItem.ChildrenList = groupSellerList
  1134. //if len(groupSellerList) > 0 {
  1135. // list = append(list, item)
  1136. //}
  1137. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  1138. //if err != nil {
  1139. // br.Msg = "获取销售失败"
  1140. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1141. // return
  1142. //}
  1143. //for _, seller := range sellerList {
  1144. // sellerItem := company.DepartmentGroupSellers{
  1145. // AdminId: fmt.Sprint(seller.AdminId),
  1146. // //AdminName string `description:"系统用户名称"`
  1147. // RealName: seller.RealName,
  1148. // Authority: seller.Authority,
  1149. // RoleTypeCode: seller.RoleTypeCode,
  1150. // }
  1151. // groupSellerList = append(groupSellerList, sellerItem)
  1152. //}
  1153. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  1154. groupItem.ChildrenList = groupSellerList
  1155. if len(groupSellerList) > 0 {
  1156. list = append(list, groupItem)
  1157. }
  1158. }
  1159. //分组为0的销售(直属部门)
  1160. departmentSellerList, err := system.GetDepartmentGroupSysUserList(departmentId, 0, roleCodeTypeStr)
  1161. if err != nil {
  1162. br.Msg = "获取销售失败"
  1163. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1164. return
  1165. }
  1166. if len(departmentSellerList) > 0 {
  1167. tmpDepartmentGroupSeller := make([]company.DepartmentGroupSellers, 0)
  1168. for _, seller := range departmentSellerList {
  1169. sellerItem := company.DepartmentGroupSellers{
  1170. AdminId: fmt.Sprint(seller.AdminId),
  1171. //AdminName string `description:"系统用户名称"`
  1172. RealName: seller.RealName,
  1173. Authority: seller.Authority,
  1174. RoleTypeCode: seller.RoleTypeCode,
  1175. }
  1176. tmpDepartmentGroupSeller = append(tmpDepartmentGroupSeller, sellerItem)
  1177. }
  1178. tmpDepartmentGroupSeller = sortDepartmentGroupSellers(tmpDepartmentGroupSeller)
  1179. list = append(list, tmpDepartmentGroupSeller...)
  1180. }
  1181. }
  1182. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || sysUser.Authority == 2 {
  1183. // 销售主管看小组
  1184. if status == 0 {
  1185. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  1186. if err != nil {
  1187. br.Msg = "获取失败"
  1188. br.ErrMsg = "查询父级id异常" + err.Error()
  1189. return
  1190. }
  1191. var realGroupId int
  1192. if pid != nil && *pid > 0 {
  1193. //主管角色放在了三级分组下
  1194. realGroupId = *pid
  1195. } else {
  1196. //主管角色放在了二级分组下
  1197. realGroupId = sysUser.GroupId
  1198. }
  1199. groupList, err := system.GetSysGroupByGroupId(realGroupId)
  1200. if err != nil {
  1201. br.Msg = "获取失败"
  1202. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  1203. return
  1204. }
  1205. for _, group := range groupList {
  1206. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  1207. //groupItem := company.DepartmentGroupSellers{
  1208. // AdminId: fmt.Sprint("group_", group.DepartmentId),
  1209. // //AdminName string `description:"系统用户名称"`
  1210. // RealName: group.GroupName,
  1211. // ChildrenList: groupSellerList,
  1212. //}
  1213. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  1214. if err != nil {
  1215. br.Msg = "获取小组失败"
  1216. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  1217. return
  1218. }
  1219. for _, team := range teamList {
  1220. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  1221. teamItem := company.DepartmentGroupSellers{
  1222. AdminId: fmt.Sprint("team_", team.GroupId),
  1223. //AdminName string `description:"系统用户名称"`
  1224. RealName: team.GroupName,
  1225. ChildrenList: teamSellerList,
  1226. }
  1227. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  1228. if err != nil {
  1229. br.Msg = "获取销售失败"
  1230. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1231. return
  1232. }
  1233. for _, seller := range sellerList {
  1234. sellerItem := company.DepartmentGroupSellers{
  1235. AdminId: fmt.Sprint(seller.AdminId),
  1236. //AdminName string `description:"系统用户名称"`
  1237. RealName: seller.RealName,
  1238. Authority: seller.Authority,
  1239. RoleTypeCode: seller.RoleTypeCode,
  1240. }
  1241. //fmt.Println("seller.RealName:", seller.RealName)
  1242. teamSellerList = append(teamSellerList, sellerItem)
  1243. }
  1244. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  1245. teamItem.ChildrenList = teamSellerList
  1246. if len(teamSellerList) > 0 {
  1247. groupSellerList = append(groupSellerList, teamItem)
  1248. }
  1249. }
  1250. //分组为0的销售(直属分组)
  1251. groupTeamSellerList, err := system.GetGrooupsysUserList(realGroupId, roleCodeTypeStr, enabled)
  1252. if err != nil {
  1253. br.Msg = "获取销售失败"
  1254. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1255. return
  1256. }
  1257. if len(groupTeamSellerList) > 0 {
  1258. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  1259. for _, seller := range groupTeamSellerList {
  1260. sellerItem := company.DepartmentGroupSellers{
  1261. AdminId: fmt.Sprint(seller.AdminId),
  1262. //AdminName string `description:"系统用户名称"`
  1263. RealName: seller.RealName,
  1264. Authority: seller.Authority,
  1265. RoleTypeCode: seller.RoleTypeCode,
  1266. }
  1267. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  1268. }
  1269. //排个序
  1270. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  1271. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  1272. }
  1273. list = groupSellerList
  1274. //groupItem.ChildrenList = groupSellerList
  1275. //if len(groupSellerList) > 0 {
  1276. // list = append(list, item)
  1277. //}
  1278. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  1279. //if err != nil {
  1280. // br.Msg = "获取销售失败"
  1281. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1282. // return
  1283. //}
  1284. //for _, seller := range sellerList {
  1285. // sellerItem := company.DepartmentGroupSellers{
  1286. // AdminId: fmt.Sprint(seller.AdminId),
  1287. // //AdminName string `description:"系统用户名称"`
  1288. // RealName: seller.RealName,
  1289. // Authority: seller.Authority,
  1290. // RoleTypeCode: seller.RoleTypeCode,
  1291. // }
  1292. // groupSellerList = append(groupSellerList, sellerItem)
  1293. //}
  1294. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  1295. //groupItem.ChildrenList = groupSellerList
  1296. //if len(groupSellerList) > 0 {
  1297. // list = append(list, groupItem)
  1298. //}
  1299. }
  1300. //分组为0的销售(直属二级分组)
  1301. //departmentSellerList, err := system.GetDepartmentGroupSysUserList(2, realGroupId, roleCodeTypeStr)
  1302. //if err != nil {
  1303. // br.Msg = "获取销售失败"
  1304. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1305. // return
  1306. //}
  1307. //if len(departmentSellerList) > 0 {
  1308. // tmpDepartmentGroupSeller := make([]company.DepartmentGroupSellers, 0)
  1309. // for _, seller := range departmentSellerList {
  1310. // sellerItem := company.DepartmentGroupSellers{
  1311. // AdminId: fmt.Sprint(seller.AdminId),
  1312. // //AdminName string `description:"系统用户名称"`
  1313. // RealName: seller.RealName,
  1314. // Authority: seller.Authority,
  1315. // RoleTypeCode: seller.RoleTypeCode,
  1316. // }
  1317. // tmpDepartmentGroupSeller = append(tmpDepartmentGroupSeller, sellerItem)
  1318. // }
  1319. // tmpDepartmentGroupSeller = sortDepartmentGroupSellers(tmpDepartmentGroupSeller)
  1320. // list = append(list, tmpDepartmentGroupSeller...)
  1321. //}
  1322. //pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  1323. //if err != nil {
  1324. // br.Msg = "获取失败"
  1325. // br.ErrMsg = "查询父级id异常" + err.Error()
  1326. // return
  1327. //}
  1328. //if pid != nil && *pid > 0 {
  1329. // //主管角色放在了三级分组下
  1330. // //
  1331. //
  1332. //
  1333. //} else {
  1334. // //主管角色放在了二级分组下
  1335. //
  1336. //}
  1337. //ids, err := company.GetGroupIdsByParentId(*pid)
  1338. //if err != nil {
  1339. // br.Msg = "获取失败"
  1340. // br.ErrMsg = "查询父级id异常" + err.Error()
  1341. // return
  1342. //}
  1343. //var idSlice []string
  1344. //var sid string
  1345. //for _, id := range ids {
  1346. // idSlice = append(idSlice, *id)
  1347. //}
  1348. //sid = strings.Join(idSlice, ",")
  1349. //sellerList, err := system.GetTeamSysUserListByIds(sid)
  1350. //if err != nil {
  1351. // br.Msg = "获取销售失败"
  1352. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1353. // return
  1354. //}
  1355. //for _, seller := range sellerList {
  1356. // sellerItem := company.DepartmentGroupSellers{
  1357. // AdminId: fmt.Sprint(seller.AdminId),
  1358. // //AdminName string `description:"系统用户名称"`
  1359. // RealName: seller.RealName,
  1360. // Authority: seller.Authority,
  1361. // RoleTypeCode: seller.RoleTypeCode,
  1362. // }
  1363. // fmt.Println("seller.RealName:", seller.RealName)
  1364. // list = append(list, sellerItem)
  1365. //}
  1366. //list = sortDepartmentGroupSellers(list)
  1367. //
  1368. ////分组为0的销售(直属分组)
  1369. //groupTeamSellerList, err := system.GetGrooupsysUserList(sysUser.GroupId, roleCodeTypeStr)
  1370. //if err != nil {
  1371. // br.Msg = "获取销售失败"
  1372. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1373. // return
  1374. //}
  1375. //if len(groupTeamSellerList) > 0 {
  1376. // tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  1377. // for _, seller := range groupTeamSellerList {
  1378. // sellerItem := company.DepartmentGroupSellers{
  1379. // AdminId: fmt.Sprint(seller.AdminId),
  1380. // //AdminName string `description:"系统用户名称"`
  1381. // RealName: seller.RealName,
  1382. // Authority: seller.Authority,
  1383. // RoleTypeCode: seller.RoleTypeCode,
  1384. // }
  1385. // tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  1386. // }
  1387. // //排个序
  1388. // tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  1389. // list = append(list, tmpDepartmentGroupSellersList...)
  1390. //}
  1391. //sellerList, err := system.GetDepartmentGroupSysUserList(sysUser.DepartmentId, sysUser.GroupId, roleCodeTypeStr)
  1392. //if err != nil {
  1393. // br.Msg = "获取销售失败"
  1394. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1395. // return
  1396. //}
  1397. //for _, seller := range sellerList {
  1398. // sellerItem := company.DepartmentGroupSellers{
  1399. // AdminId: fmt.Sprint(seller.AdminId),
  1400. // //AdminName string `description:"系统用户名称"`
  1401. // RealName: seller.RealName,
  1402. // Authority: seller.Authority,
  1403. // RoleTypeCode: seller.RoleTypeCode,
  1404. // }
  1405. // list = append(list, sellerItem)
  1406. // list = sortDepartmentGroupSellers(list)
  1407. //}
  1408. //正常来说没有所有人都应该在某个小组下,要不就是小组名为 无 的小组
  1409. } else {
  1410. //var departmentStr string
  1411. //if utils.RunMode == "release" {
  1412. // departmentStr = `1,2`
  1413. //} else {
  1414. // departmentStr = `1,2`
  1415. //}
  1416. departmentStr := `1,2`
  1417. departmentList, err := system.GetDepartmentListByIds(departmentStr)
  1418. if err != nil {
  1419. br.Msg = "获取失败"
  1420. br.ErrMsg = "获取部门失败,Err:" + err.Error()
  1421. return
  1422. }
  1423. for _, department := range departmentList {
  1424. departmentGroupSellerList := make([]company.DepartmentGroupSellers, 0)
  1425. item := company.DepartmentGroupSellers{
  1426. AdminId: fmt.Sprint("department_", department.DepartmentId),
  1427. //AdminName string `description:"系统用户名称"`
  1428. RealName: department.DepartmentName,
  1429. ChildrenList: departmentGroupSellerList,
  1430. }
  1431. groupList, err := system.GetSysGroupByDepartmentId(department.DepartmentId)
  1432. if err != nil {
  1433. br.Msg = "获取失败"
  1434. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  1435. return
  1436. }
  1437. for _, group := range groupList {
  1438. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  1439. groupItem := company.DepartmentGroupSellers{
  1440. AdminId: fmt.Sprint("group_", group.DepartmentId),
  1441. //AdminName string `description:"系统用户名称"`
  1442. RealName: group.GroupName,
  1443. ChildrenList: groupSellerList,
  1444. }
  1445. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  1446. if err != nil {
  1447. br.Msg = "获取小组失败"
  1448. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  1449. return
  1450. }
  1451. for _, team := range teamList {
  1452. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  1453. teamItem := company.DepartmentGroupSellers{
  1454. AdminId: fmt.Sprint("team_", team.GroupId),
  1455. //AdminName string `description:"系统用户名称"`
  1456. RealName: team.GroupName,
  1457. ChildrenList: teamSellerList,
  1458. }
  1459. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  1460. if err != nil {
  1461. br.Msg = "获取销售失败"
  1462. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1463. return
  1464. }
  1465. for _, seller := range sellerList {
  1466. sellerItem := company.DepartmentGroupSellers{
  1467. AdminId: fmt.Sprint(seller.AdminId),
  1468. //AdminName string `description:"系统用户名称"`
  1469. RealName: seller.RealName,
  1470. Authority: seller.Authority,
  1471. RoleTypeCode: seller.RoleTypeCode,
  1472. }
  1473. //fmt.Println("seller.RealName:", seller.RealName)
  1474. teamSellerList = append(teamSellerList, sellerItem)
  1475. }
  1476. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  1477. teamItem.ChildrenList = teamSellerList
  1478. if len(teamSellerList) > 0 {
  1479. groupSellerList = append(groupSellerList, teamItem)
  1480. }
  1481. }
  1482. //分组为0的人,不光是销售(直属分组)
  1483. groupTeamSellerList, err := system.GetGroupSysUserList(group.GroupId)
  1484. if err != nil {
  1485. br.Msg = "获取销售失败"
  1486. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1487. return
  1488. }
  1489. if len(groupTeamSellerList) > 0 {
  1490. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  1491. for _, seller := range groupTeamSellerList {
  1492. sellerItem := company.DepartmentGroupSellers{
  1493. AdminId: fmt.Sprint(seller.AdminId),
  1494. //AdminName string `description:"系统用户名称"`
  1495. RealName: seller.RealName,
  1496. Authority: seller.Authority,
  1497. RoleTypeCode: seller.RoleTypeCode,
  1498. }
  1499. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  1500. }
  1501. //排个序
  1502. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  1503. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  1504. }
  1505. //groupItem.ChildrenList = groupSellerList
  1506. //if len(groupSellerList) > 0 {
  1507. // list = append(list, item)
  1508. //}
  1509. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  1510. //if err != nil {
  1511. // br.Msg = "获取销售失败"
  1512. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1513. // return
  1514. //}
  1515. //for _, seller := range sellerList {
  1516. // sellerItem := company.DepartmentGroupSellers{
  1517. // AdminId: fmt.Sprint(seller.AdminId),
  1518. // //AdminName string `description:"系统用户名称"`
  1519. // RealName: seller.RealName,
  1520. // Authority: seller.Authority,
  1521. // RoleTypeCode: seller.RoleTypeCode,
  1522. // }
  1523. // groupSellerList = append(groupSellerList, sellerItem)
  1524. //}
  1525. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  1526. groupItem.ChildrenList = groupSellerList
  1527. if len(groupSellerList) > 0 {
  1528. departmentGroupSellerList = append(departmentGroupSellerList, groupItem)
  1529. }
  1530. }
  1531. //分组为0的人,不光是销售(直属部门)
  1532. departmentSellerList, err := system.GetDepartmentGroupSysUserList(department.DepartmentId, 0, "")
  1533. if err != nil {
  1534. br.Msg = "获取销售失败"
  1535. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1536. return
  1537. }
  1538. if len(departmentSellerList) > 0 {
  1539. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  1540. for _, seller := range departmentSellerList {
  1541. sellerItem := company.DepartmentGroupSellers{
  1542. AdminId: fmt.Sprint(seller.AdminId),
  1543. //AdminName string `description:"系统用户名称"`
  1544. RealName: seller.RealName,
  1545. Authority: seller.Authority,
  1546. RoleTypeCode: seller.RoleTypeCode,
  1547. }
  1548. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  1549. }
  1550. //排个序
  1551. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  1552. departmentGroupSellerList = append(departmentGroupSellerList, tmpDepartmentGroupSellersList...)
  1553. }
  1554. item.ChildrenList = departmentGroupSellerList
  1555. if len(departmentGroupSellerList) > 0 {
  1556. list = append(list, item)
  1557. }
  1558. }
  1559. }
  1560. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER && status == 1 {
  1561. //var departmentStr string
  1562. //if utils.RunMode == "release" {
  1563. // departmentStr = `1,2`
  1564. //} else {
  1565. // departmentStr = `1,2`
  1566. //}
  1567. departmentStr := `1,2`
  1568. departmentList, err := system.GetDepartmentListByIds(departmentStr)
  1569. if err != nil {
  1570. br.Msg = "获取失败"
  1571. br.ErrMsg = "获取部门失败,Err:" + err.Error()
  1572. return
  1573. }
  1574. for _, department := range departmentList {
  1575. departmentGroupSellerList := make([]company.DepartmentGroupSellers, 0)
  1576. item := company.DepartmentGroupSellers{
  1577. AdminId: fmt.Sprint("department_", department.DepartmentId),
  1578. //AdminName string `description:"系统用户名称"`
  1579. RealName: department.DepartmentName,
  1580. ChildrenList: departmentGroupSellerList,
  1581. }
  1582. groupList, err := system.GetSysGroupByDepartmentId(department.DepartmentId)
  1583. if err != nil {
  1584. br.Msg = "获取失败"
  1585. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  1586. return
  1587. }
  1588. for _, group := range groupList {
  1589. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  1590. groupItem := company.DepartmentGroupSellers{
  1591. AdminId: fmt.Sprint("group_", group.DepartmentId),
  1592. //AdminName string `description:"系统用户名称"`
  1593. RealName: group.GroupName,
  1594. ChildrenList: groupSellerList,
  1595. }
  1596. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  1597. if err != nil {
  1598. br.Msg = "获取小组失败"
  1599. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  1600. return
  1601. }
  1602. for _, team := range teamList {
  1603. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  1604. teamItem := company.DepartmentGroupSellers{
  1605. AdminId: fmt.Sprint("team_", team.GroupId),
  1606. //AdminName string `description:"系统用户名称"`
  1607. RealName: team.GroupName,
  1608. ChildrenList: teamSellerList,
  1609. }
  1610. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  1611. if err != nil {
  1612. br.Msg = "获取销售失败"
  1613. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1614. return
  1615. }
  1616. for _, seller := range sellerList {
  1617. sellerItem := company.DepartmentGroupSellers{
  1618. AdminId: fmt.Sprint(seller.AdminId),
  1619. //AdminName string `description:"系统用户名称"`
  1620. RealName: seller.RealName,
  1621. Authority: seller.Authority,
  1622. RoleTypeCode: seller.RoleTypeCode,
  1623. }
  1624. //fmt.Println("seller.RealName:", seller.RealName)
  1625. teamSellerList = append(teamSellerList, sellerItem)
  1626. }
  1627. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  1628. teamItem.ChildrenList = teamSellerList
  1629. if len(teamSellerList) > 0 {
  1630. groupSellerList = append(groupSellerList, teamItem)
  1631. }
  1632. }
  1633. //分组为0的人,不光是销售(直属分组)
  1634. groupTeamSellerList, err := system.GetGroupSysUserList(group.GroupId)
  1635. if err != nil {
  1636. br.Msg = "获取销售失败"
  1637. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1638. return
  1639. }
  1640. if len(groupTeamSellerList) > 0 {
  1641. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  1642. for _, seller := range groupTeamSellerList {
  1643. sellerItem := company.DepartmentGroupSellers{
  1644. AdminId: fmt.Sprint(seller.AdminId),
  1645. //AdminName string `description:"系统用户名称"`
  1646. RealName: seller.RealName,
  1647. Authority: seller.Authority,
  1648. RoleTypeCode: seller.RoleTypeCode,
  1649. }
  1650. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  1651. }
  1652. //排个序
  1653. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  1654. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  1655. }
  1656. //groupItem.ChildrenList = groupSellerList
  1657. //if len(groupSellerList) > 0 {
  1658. // list = append(list, item)
  1659. //}
  1660. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  1661. //if err != nil {
  1662. // br.Msg = "获取销售失败"
  1663. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1664. // return
  1665. //}
  1666. //for _, seller := range sellerList {
  1667. // sellerItem := company.DepartmentGroupSellers{
  1668. // AdminId: fmt.Sprint(seller.AdminId),
  1669. // //AdminName string `description:"系统用户名称"`
  1670. // RealName: seller.RealName,
  1671. // Authority: seller.Authority,
  1672. // RoleTypeCode: seller.RoleTypeCode,
  1673. // }
  1674. // groupSellerList = append(groupSellerList, sellerItem)
  1675. //}
  1676. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  1677. groupItem.ChildrenList = groupSellerList
  1678. if len(groupSellerList) > 0 {
  1679. departmentGroupSellerList = append(departmentGroupSellerList, groupItem)
  1680. }
  1681. }
  1682. //分组为0的人,不光是销售(直属部门)
  1683. departmentSellerList, err := system.GetDepartmentGroupSysUserList(department.DepartmentId, 0, "")
  1684. if err != nil {
  1685. br.Msg = "获取销售失败"
  1686. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1687. return
  1688. }
  1689. if len(departmentSellerList) > 0 {
  1690. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  1691. for _, seller := range departmentSellerList {
  1692. sellerItem := company.DepartmentGroupSellers{
  1693. AdminId: fmt.Sprint(seller.AdminId),
  1694. //AdminName string `description:"系统用户名称"`
  1695. RealName: seller.RealName,
  1696. Authority: seller.Authority,
  1697. RoleTypeCode: seller.RoleTypeCode,
  1698. }
  1699. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  1700. }
  1701. //排个序
  1702. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  1703. departmentGroupSellerList = append(departmentGroupSellerList, tmpDepartmentGroupSellersList...)
  1704. }
  1705. item.ChildrenList = departmentGroupSellerList
  1706. if len(departmentGroupSellerList) > 0 {
  1707. list = append(list, item)
  1708. }
  1709. }
  1710. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER && status == 1 {
  1711. // 权益销售可以看到权益销售部的所有人
  1712. departmentId := 5
  1713. groupList, err := system.GetSysGroupByDepartmentId(departmentId)
  1714. if err != nil {
  1715. br.Msg = "获取失败"
  1716. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  1717. return
  1718. }
  1719. for _, group := range groupList {
  1720. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  1721. groupItem := company.DepartmentGroupSellers{
  1722. AdminId: fmt.Sprint("group_", group.DepartmentId),
  1723. //AdminName string `description:"系统用户名称"`
  1724. RealName: group.GroupName,
  1725. ChildrenList: groupSellerList,
  1726. }
  1727. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  1728. if err != nil {
  1729. br.Msg = "获取小组失败"
  1730. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  1731. return
  1732. }
  1733. for _, team := range teamList {
  1734. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  1735. teamItem := company.DepartmentGroupSellers{
  1736. AdminId: fmt.Sprint("team_", team.GroupId),
  1737. //AdminName string `description:"系统用户名称"`
  1738. RealName: team.GroupName,
  1739. ChildrenList: teamSellerList,
  1740. }
  1741. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  1742. if err != nil {
  1743. br.Msg = "获取销售失败"
  1744. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1745. return
  1746. }
  1747. for _, seller := range sellerList {
  1748. sellerItem := company.DepartmentGroupSellers{
  1749. AdminId: fmt.Sprint(seller.AdminId),
  1750. //AdminName string `description:"系统用户名称"`
  1751. RealName: seller.RealName,
  1752. Authority: seller.Authority,
  1753. RoleTypeCode: seller.RoleTypeCode,
  1754. }
  1755. //fmt.Println("seller.RealName:", seller.RealName)
  1756. teamSellerList = append(teamSellerList, sellerItem)
  1757. }
  1758. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  1759. teamItem.ChildrenList = teamSellerList
  1760. if len(teamSellerList) > 0 {
  1761. groupSellerList = append(groupSellerList, teamItem)
  1762. }
  1763. }
  1764. //分组为0的销售(直属分组)
  1765. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  1766. if err != nil {
  1767. br.Msg = "获取销售失败"
  1768. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1769. return
  1770. }
  1771. if len(groupTeamSellerList) > 0 {
  1772. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  1773. for _, seller := range groupTeamSellerList {
  1774. sellerItem := company.DepartmentGroupSellers{
  1775. AdminId: fmt.Sprint(seller.AdminId),
  1776. //AdminName string `description:"系统用户名称"`
  1777. RealName: seller.RealName,
  1778. Authority: seller.Authority,
  1779. RoleTypeCode: seller.RoleTypeCode,
  1780. }
  1781. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  1782. }
  1783. //排个序
  1784. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  1785. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  1786. }
  1787. //groupItem.ChildrenList = groupSellerList
  1788. //if len(groupSellerList) > 0 {
  1789. // list = append(list, item)
  1790. //}
  1791. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  1792. //if err != nil {
  1793. // br.Msg = "获取销售失败"
  1794. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1795. // return
  1796. //}
  1797. //for _, seller := range sellerList {
  1798. // sellerItem := company.DepartmentGroupSellers{
  1799. // AdminId: fmt.Sprint(seller.AdminId),
  1800. // //AdminName string `description:"系统用户名称"`
  1801. // RealName: seller.RealName,
  1802. // Authority: seller.Authority,
  1803. // RoleTypeCode: seller.RoleTypeCode,
  1804. // }
  1805. // groupSellerList = append(groupSellerList, sellerItem)
  1806. //}
  1807. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  1808. groupItem.ChildrenList = groupSellerList
  1809. if len(groupSellerList) > 0 {
  1810. list = append(list, groupItem)
  1811. }
  1812. }
  1813. //分组为0的销售(直属部门)
  1814. departmentSellerList, err := system.GetDepartmentGroupSysUserList(departmentId, 0, roleCodeTypeStr)
  1815. if err != nil {
  1816. br.Msg = "获取销售失败"
  1817. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1818. return
  1819. }
  1820. if len(departmentSellerList) > 0 {
  1821. tmpDepartmentGroupSeller := make([]company.DepartmentGroupSellers, 0)
  1822. for _, seller := range departmentSellerList {
  1823. sellerItem := company.DepartmentGroupSellers{
  1824. AdminId: fmt.Sprint(seller.AdminId),
  1825. //AdminName string `description:"系统用户名称"`
  1826. RealName: seller.RealName,
  1827. Authority: seller.Authority,
  1828. RoleTypeCode: seller.RoleTypeCode,
  1829. }
  1830. tmpDepartmentGroupSeller = append(tmpDepartmentGroupSeller, sellerItem)
  1831. }
  1832. tmpDepartmentGroupSeller = sortDepartmentGroupSellers(tmpDepartmentGroupSeller)
  1833. list = append(list, tmpDepartmentGroupSeller...)
  1834. }
  1835. } else {
  1836. //看自己
  1837. sellerItem := company.DepartmentGroupSellers{
  1838. AdminId: fmt.Sprint(sysUser.AdminId),
  1839. //AdminName string `description:"系统用户名称"`
  1840. RealName: sysUser.RealName,
  1841. }
  1842. list = append(list, sellerItem)
  1843. }
  1844. } else {
  1845. departmentId := sysUser.DepartmentId
  1846. switch productId {
  1847. case 1:
  1848. departmentId = 2
  1849. case 5:
  1850. departmentId = 5
  1851. }
  1852. //查询整个部门的小组、销售
  1853. groupList, err := system.GetSysGroupByDepartmentId(departmentId)
  1854. if err != nil {
  1855. br.Msg = "获取失败"
  1856. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  1857. return
  1858. }
  1859. for _, group := range groupList {
  1860. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  1861. groupItem := company.DepartmentGroupSellers{
  1862. AdminId: fmt.Sprint("group_", group.DepartmentId),
  1863. //AdminName string `description:"系统用户名称"`
  1864. RealName: group.GroupName,
  1865. ChildrenList: groupSellerList,
  1866. }
  1867. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  1868. if err != nil {
  1869. br.Msg = "获取小组失败"
  1870. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  1871. return
  1872. }
  1873. for _, team := range teamList {
  1874. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  1875. teamItem := company.DepartmentGroupSellers{
  1876. AdminId: fmt.Sprint("team_", team.GroupId),
  1877. //AdminName string `description:"系统用户名称"`
  1878. RealName: team.GroupName,
  1879. ChildrenList: teamSellerList,
  1880. }
  1881. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  1882. if err != nil {
  1883. br.Msg = "获取销售失败"
  1884. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1885. return
  1886. }
  1887. for _, seller := range sellerList {
  1888. sellerItem := company.DepartmentGroupSellers{
  1889. AdminId: fmt.Sprint(seller.AdminId),
  1890. //AdminName string `description:"系统用户名称"`
  1891. RealName: seller.RealName,
  1892. Authority: seller.Authority,
  1893. RoleTypeCode: seller.RoleTypeCode,
  1894. }
  1895. //fmt.Println("seller.RealName:", seller.RealName)
  1896. teamSellerList = append(teamSellerList, sellerItem)
  1897. }
  1898. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  1899. teamItem.ChildrenList = teamSellerList
  1900. if len(teamSellerList) > 0 {
  1901. groupSellerList = append(groupSellerList, teamItem)
  1902. }
  1903. }
  1904. //分组为0的销售(直属分组)
  1905. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  1906. if err != nil {
  1907. br.Msg = "获取销售失败"
  1908. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1909. return
  1910. }
  1911. if len(groupTeamSellerList) > 0 {
  1912. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  1913. for _, seller := range groupTeamSellerList {
  1914. sellerItem := company.DepartmentGroupSellers{
  1915. AdminId: fmt.Sprint(seller.AdminId),
  1916. //AdminName string `description:"系统用户名称"`
  1917. RealName: seller.RealName,
  1918. Authority: seller.Authority,
  1919. RoleTypeCode: seller.RoleTypeCode,
  1920. }
  1921. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  1922. }
  1923. //排个序
  1924. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  1925. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  1926. }
  1927. groupItem.ChildrenList = groupSellerList
  1928. if len(groupSellerList) > 0 {
  1929. list = append(list, groupItem)
  1930. }
  1931. }
  1932. //分组为0的销售(直属部门)
  1933. departmentSellerList, err := system.GetDepartmentGroupSysUserList(departmentId, 0, roleCodeTypeStr)
  1934. if err != nil {
  1935. br.Msg = "获取销售失败"
  1936. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  1937. return
  1938. }
  1939. if len(departmentSellerList) > 0 {
  1940. tmpDepartmentGroupSeller := make([]company.DepartmentGroupSellers, 0)
  1941. for _, seller := range departmentSellerList {
  1942. sellerItem := company.DepartmentGroupSellers{
  1943. AdminId: fmt.Sprint(seller.AdminId),
  1944. //AdminName string `description:"系统用户名称"`
  1945. RealName: seller.RealName,
  1946. Authority: seller.Authority,
  1947. RoleTypeCode: seller.RoleTypeCode,
  1948. }
  1949. tmpDepartmentGroupSeller = append(tmpDepartmentGroupSeller, sellerItem)
  1950. }
  1951. //排个序
  1952. tmpDepartmentGroupSeller = sortDepartmentGroupSellers(tmpDepartmentGroupSeller)
  1953. list = append(list, tmpDepartmentGroupSeller...)
  1954. }
  1955. }
  1956. // 海外销售部-目前无权限, 均可见
  1957. seaDepartment, e := system.GetSysDepartmentByName("海外销售部")
  1958. if e != nil && e.Error() != utils.ErrNoRow() {
  1959. br.Msg = "获取失败"
  1960. br.ErrMsg = "获取海外销售部失败, Err: " + e.Error()
  1961. return
  1962. }
  1963. if e == nil {
  1964. // 获取部门下的销售人员
  1965. seaSellers, e := system.GetDepartmentGroupSysUserList(seaDepartment.DepartmentId, 0, "")
  1966. if e != nil {
  1967. br.Msg = "获取失败"
  1968. br.ErrMsg = "获取海外销售失败, Err: " + e.Error()
  1969. return
  1970. }
  1971. // 获取分组
  1972. seaGroups, e := system.GetSysGroupListByDepartmentId(seaDepartment.DepartmentId)
  1973. if e != nil {
  1974. br.Msg = "获取失败"
  1975. br.ErrMsg = "获取海外销售部分组失败, Err: " + e.Error()
  1976. return
  1977. }
  1978. var d company.DepartmentGroupSellers
  1979. d.AdminId = fmt.Sprintf("department_%d", seaDepartment.DepartmentId)
  1980. d.RealName = seaDepartment.DepartmentName
  1981. children := make([]company.DepartmentGroupSellers, 0)
  1982. // 无分组
  1983. if len(seaGroups) == 0 {
  1984. for _, s := range seaSellers {
  1985. children = append(children, company.DepartmentGroupSellers{
  1986. AdminId: strconv.Itoa(s.AdminId),
  1987. RealName: s.RealName,
  1988. RoleTypeCode: s.RoleTypeCode,
  1989. Authority: s.Authority,
  1990. })
  1991. }
  1992. }
  1993. // 有分组
  1994. if len(seaGroups) > 0 {
  1995. // 销售map
  1996. sellerMap := make(map[int][]company.DepartmentGroupSellers)
  1997. for _, s := range seaSellers {
  1998. sellerMap[s.GroupId] = append(sellerMap[s.GroupId], company.DepartmentGroupSellers{
  1999. AdminId: strconv.Itoa(s.AdminId),
  2000. RealName: s.RealName,
  2001. RoleTypeCode: s.RoleTypeCode,
  2002. Authority: s.Authority,
  2003. })
  2004. }
  2005. // 小组map
  2006. childrenMap := make(map[int][]company.DepartmentGroupSellers)
  2007. for _, g := range seaGroups {
  2008. if g.ParentId == 0 {
  2009. continue
  2010. }
  2011. childrenMap[g.ParentId] = append(childrenMap[g.ParentId], company.DepartmentGroupSellers{
  2012. AdminId: fmt.Sprintf("team_%d", g.GroupId),
  2013. RealName: g.GroupName,
  2014. ChildrenList: sellerMap[g.GroupId],
  2015. })
  2016. }
  2017. // 大组
  2018. for _, g := range seaGroups {
  2019. if g.ParentId > 0 {
  2020. continue
  2021. }
  2022. c := childrenMap[g.GroupId]
  2023. if len(sellerMap[g.GroupId]) > 0 {
  2024. c = append(c, sellerMap[g.GroupId]...)
  2025. }
  2026. children = append(children, company.DepartmentGroupSellers{
  2027. AdminId: fmt.Sprintf("group_%d", g.GroupId),
  2028. RealName: g.GroupName,
  2029. ChildrenList: c,
  2030. })
  2031. }
  2032. }
  2033. d.ChildrenList = children
  2034. list = append(list, d)
  2035. }
  2036. br.Ret = 200
  2037. br.Success = true
  2038. br.Msg = "获取成功"
  2039. br.Data = company.DepartmentGroupSellersResp{
  2040. List: list,
  2041. }
  2042. }
  2043. // sortDepartmentGroupSellers 部门用户排序
  2044. func sortDepartmentGroupSellers(adminList []company.DepartmentGroupSellers) (list []company.DepartmentGroupSellers) {
  2045. sellerMap := make(map[int][]company.DepartmentGroupSellers)
  2046. for _, admin := range adminList {
  2047. index := 0 //0:超管,1:部门管理员,2:组长,3:普通人
  2048. switch admin.RoleTypeCode {
  2049. //case utils.ROLE_TYPE_CODE_ADMIN:
  2050. // index = 0
  2051. //case utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_RAI_ADMIN:
  2052. // index = 1
  2053. //case utils.ROLE_TYPE_CODE_FICC_GROUP, utils.ROLE_TYPE_CODE_RAI_GROUP:
  2054. // index = 2
  2055. default:
  2056. //0:无,1:部门负责人,2:小组负责人,3:超级管理员
  2057. switch admin.Authority {
  2058. //case 1:
  2059. // index = 1
  2060. case 2:
  2061. index = 2
  2062. //case 3:
  2063. // index = 0
  2064. default:
  2065. index = 3
  2066. }
  2067. }
  2068. sellerList, ok := sellerMap[index]
  2069. if !ok {
  2070. sellerList = make([]company.DepartmentGroupSellers, 0)
  2071. }
  2072. sellerList = append(sellerList, admin)
  2073. sellerMap[index] = sellerList
  2074. }
  2075. var indexList = []int{0, 1, 2, 3}
  2076. for _, index := range indexList {
  2077. sellerList, ok := sellerMap[index]
  2078. if ok {
  2079. list = append(list, sellerList...)
  2080. }
  2081. }
  2082. return
  2083. }
  2084. // CheckListForLose
  2085. // @Title 获取销售查看流失客户时的筛选框
  2086. // @Description 获取销售查看流失客户时的筛选框 接口
  2087. // @Success 200 {object} company.DepartmentGroupSellersResp
  2088. // @router /seller/checkListForLose [get]
  2089. func (this *CompanySellerController) CheckListForLose() {
  2090. br := new(models.BaseResponse).Init()
  2091. defer func() {
  2092. this.Data["json"] = br
  2093. this.ServeJSON()
  2094. }()
  2095. sysUser := this.SysUser
  2096. if sysUser == nil {
  2097. br.Msg = "请登录"
  2098. br.ErrMsg = "请登录,SysUser Is Empty"
  2099. br.Ret = 408
  2100. return
  2101. }
  2102. roleCodeTypeStr := ``
  2103. //productId := services.GetProductId(sysUser.RoleTypeCode)
  2104. //switch productId {
  2105. //case 1:
  2106. // roleCodeTypeStr = `"` + utils.ROLE_TYPE_CODE_FICC_SELLER + `","` + utils.ROLE_TYPE_CODE_FICC_GROUP + `","` + utils.ROLE_TYPE_CODE_FICC_TEAM + `"`
  2107. //case 2:
  2108. // roleCodeTypeStr = `"` + utils.ROLE_TYPE_CODE_RAI_SELLER + `","` + utils.ROLE_TYPE_CODE_RAI_GROUP + `"`
  2109. //}
  2110. list := make([]company.DepartmentGroupSellers, 0)
  2111. // ficc销售,组长,主管 可以看到ficc研究部和ficc销售部的所有人
  2112. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  2113. //var departmentStr string
  2114. //if utils.RunMode == "release" {
  2115. // departmentStr = `1,2`
  2116. //} else {
  2117. // departmentStr = `1,2`
  2118. //}
  2119. departmentStr := `1,2`
  2120. departmentList, err := system.GetDepartmentListByIds(departmentStr)
  2121. if err != nil {
  2122. br.Msg = "获取失败"
  2123. br.ErrMsg = "获取部门失败,Err:" + err.Error()
  2124. return
  2125. }
  2126. for _, department := range departmentList {
  2127. departmentGroupSellerList := make([]company.DepartmentGroupSellers, 0)
  2128. item := company.DepartmentGroupSellers{
  2129. AdminId: fmt.Sprint("department_", department.DepartmentId),
  2130. //AdminName string `description:"系统用户名称"`
  2131. RealName: department.DepartmentName,
  2132. ChildrenList: departmentGroupSellerList,
  2133. }
  2134. groupList, err := system.GetSysGroupByDepartmentId(department.DepartmentId)
  2135. if err != nil {
  2136. br.Msg = "获取失败"
  2137. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  2138. return
  2139. }
  2140. for _, group := range groupList {
  2141. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  2142. groupItem := company.DepartmentGroupSellers{
  2143. AdminId: fmt.Sprint("group_", group.DepartmentId),
  2144. //AdminName string `description:"系统用户名称"`
  2145. RealName: group.GroupName,
  2146. ChildrenList: groupSellerList,
  2147. }
  2148. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  2149. if err != nil {
  2150. br.Msg = "获取小组失败"
  2151. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  2152. return
  2153. }
  2154. for _, team := range teamList {
  2155. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  2156. teamItem := company.DepartmentGroupSellers{
  2157. AdminId: fmt.Sprint("team_", team.GroupId),
  2158. //AdminName string `description:"系统用户名称"`
  2159. RealName: team.GroupName,
  2160. ChildrenList: teamSellerList,
  2161. }
  2162. sellerList, err := system.GetTeamSysUserList(team.GroupId, 1)
  2163. if err != nil {
  2164. br.Msg = "获取销售失败"
  2165. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  2166. return
  2167. }
  2168. for _, seller := range sellerList {
  2169. sellerItem := company.DepartmentGroupSellers{
  2170. AdminId: fmt.Sprint(seller.AdminId),
  2171. //AdminName string `description:"系统用户名称"`
  2172. RealName: seller.RealName,
  2173. Authority: seller.Authority,
  2174. RoleTypeCode: seller.RoleTypeCode,
  2175. }
  2176. //fmt.Println("seller.RealName:", seller.RealName)
  2177. teamSellerList = append(teamSellerList, sellerItem)
  2178. }
  2179. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  2180. teamItem.ChildrenList = teamSellerList
  2181. if len(teamSellerList) > 0 {
  2182. groupSellerList = append(groupSellerList, teamItem)
  2183. }
  2184. }
  2185. //分组为0的销售(直属分组)
  2186. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, 1)
  2187. if err != nil {
  2188. br.Msg = "获取销售失败"
  2189. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  2190. return
  2191. }
  2192. if len(groupTeamSellerList) > 0 {
  2193. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  2194. for _, seller := range groupTeamSellerList {
  2195. sellerItem := company.DepartmentGroupSellers{
  2196. AdminId: fmt.Sprint(seller.AdminId),
  2197. //AdminName string `description:"系统用户名称"`
  2198. RealName: seller.RealName,
  2199. Authority: seller.Authority,
  2200. RoleTypeCode: seller.RoleTypeCode,
  2201. }
  2202. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  2203. }
  2204. //排个序
  2205. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  2206. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  2207. }
  2208. //groupItem.ChildrenList = groupSellerList
  2209. //if len(groupSellerList) > 0 {
  2210. // list = append(list, item)
  2211. //}
  2212. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  2213. //if err != nil {
  2214. // br.Msg = "获取销售失败"
  2215. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  2216. // return
  2217. //}
  2218. //for _, seller := range sellerList {
  2219. // sellerItem := company.DepartmentGroupSellers{
  2220. // AdminId: fmt.Sprint(seller.AdminId),
  2221. // //AdminName string `description:"系统用户名称"`
  2222. // RealName: seller.RealName,
  2223. // Authority: seller.Authority,
  2224. // RoleTypeCode: seller.RoleTypeCode,
  2225. // }
  2226. // groupSellerList = append(groupSellerList, sellerItem)
  2227. //}
  2228. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  2229. groupItem.ChildrenList = groupSellerList
  2230. if len(groupSellerList) > 0 {
  2231. departmentGroupSellerList = append(departmentGroupSellerList, groupItem)
  2232. }
  2233. }
  2234. //分组为0的销售(直属部门)
  2235. departmentSellerList, err := system.GetDepartmentGroupSysUserList(department.DepartmentId, 0, roleCodeTypeStr)
  2236. if err != nil {
  2237. br.Msg = "获取销售失败"
  2238. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  2239. return
  2240. }
  2241. if len(departmentSellerList) > 0 {
  2242. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  2243. for _, seller := range departmentSellerList {
  2244. sellerItem := company.DepartmentGroupSellers{
  2245. AdminId: fmt.Sprint(seller.AdminId),
  2246. //AdminName string `description:"系统用户名称"`
  2247. RealName: seller.RealName,
  2248. Authority: seller.Authority,
  2249. RoleTypeCode: seller.RoleTypeCode,
  2250. }
  2251. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  2252. }
  2253. //排个序
  2254. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  2255. departmentGroupSellerList = append(departmentGroupSellerList, tmpDepartmentGroupSellersList...)
  2256. }
  2257. item.ChildrenList = departmentGroupSellerList
  2258. if len(departmentGroupSellerList) > 0 {
  2259. list = append(list, item)
  2260. }
  2261. }
  2262. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  2263. // 权益销售可以看到权益销售部的所有人
  2264. departmentId := 5
  2265. groupList, err := system.GetSysGroupByDepartmentId(departmentId)
  2266. if err != nil {
  2267. br.Msg = "获取失败"
  2268. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  2269. return
  2270. }
  2271. for _, group := range groupList {
  2272. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  2273. groupItem := company.DepartmentGroupSellers{
  2274. AdminId: fmt.Sprint("group_", group.DepartmentId),
  2275. //AdminName string `description:"系统用户名称"`
  2276. RealName: group.GroupName,
  2277. ChildrenList: groupSellerList,
  2278. }
  2279. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  2280. if err != nil {
  2281. br.Msg = "获取小组失败"
  2282. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  2283. return
  2284. }
  2285. for _, team := range teamList {
  2286. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  2287. teamItem := company.DepartmentGroupSellers{
  2288. AdminId: fmt.Sprint("team_", team.GroupId),
  2289. //AdminName string `description:"系统用户名称"`
  2290. RealName: team.GroupName,
  2291. ChildrenList: teamSellerList,
  2292. }
  2293. sellerList, err := system.GetTeamSysUserList(team.GroupId, 1)
  2294. if err != nil {
  2295. br.Msg = "获取销售失败"
  2296. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  2297. return
  2298. }
  2299. for _, seller := range sellerList {
  2300. sellerItem := company.DepartmentGroupSellers{
  2301. AdminId: fmt.Sprint(seller.AdminId),
  2302. //AdminName string `description:"系统用户名称"`
  2303. RealName: seller.RealName,
  2304. Authority: seller.Authority,
  2305. RoleTypeCode: seller.RoleTypeCode,
  2306. }
  2307. //fmt.Println("seller.RealName:", seller.RealName)
  2308. teamSellerList = append(teamSellerList, sellerItem)
  2309. }
  2310. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  2311. teamItem.ChildrenList = teamSellerList
  2312. if len(teamSellerList) > 0 {
  2313. groupSellerList = append(groupSellerList, teamItem)
  2314. }
  2315. }
  2316. //分组为0的销售(直属分组)
  2317. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, 1)
  2318. if err != nil {
  2319. br.Msg = "获取销售失败"
  2320. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  2321. return
  2322. }
  2323. if len(groupTeamSellerList) > 0 {
  2324. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  2325. for _, seller := range groupTeamSellerList {
  2326. sellerItem := company.DepartmentGroupSellers{
  2327. AdminId: fmt.Sprint(seller.AdminId),
  2328. //AdminName string `description:"系统用户名称"`
  2329. RealName: seller.RealName,
  2330. Authority: seller.Authority,
  2331. RoleTypeCode: seller.RoleTypeCode,
  2332. }
  2333. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  2334. }
  2335. //排个序
  2336. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  2337. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  2338. }
  2339. //groupItem.ChildrenList = groupSellerList
  2340. //if len(groupSellerList) > 0 {
  2341. // list = append(list, item)
  2342. //}
  2343. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  2344. //if err != nil {
  2345. // br.Msg = "获取销售失败"
  2346. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  2347. // return
  2348. //}
  2349. //for _, seller := range sellerList {
  2350. // sellerItem := company.DepartmentGroupSellers{
  2351. // AdminId: fmt.Sprint(seller.AdminId),
  2352. // //AdminName string `description:"系统用户名称"`
  2353. // RealName: seller.RealName,
  2354. // Authority: seller.Authority,
  2355. // RoleTypeCode: seller.RoleTypeCode,
  2356. // }
  2357. // groupSellerList = append(groupSellerList, sellerItem)
  2358. //}
  2359. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  2360. groupItem.ChildrenList = groupSellerList
  2361. if len(groupSellerList) > 0 {
  2362. list = append(list, groupItem)
  2363. }
  2364. }
  2365. //分组为0的销售(直属部门)
  2366. departmentSellerList, err := system.GetDepartmentGroupSysUserList(departmentId, 0, roleCodeTypeStr)
  2367. if err != nil {
  2368. br.Msg = "获取销售失败"
  2369. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  2370. return
  2371. }
  2372. if len(departmentSellerList) > 0 {
  2373. tmpDepartmentGroupSeller := make([]company.DepartmentGroupSellers, 0)
  2374. for _, seller := range departmentSellerList {
  2375. sellerItem := company.DepartmentGroupSellers{
  2376. AdminId: fmt.Sprint(seller.AdminId),
  2377. //AdminName string `description:"系统用户名称"`
  2378. RealName: seller.RealName,
  2379. Authority: seller.Authority,
  2380. RoleTypeCode: seller.RoleTypeCode,
  2381. }
  2382. tmpDepartmentGroupSeller = append(tmpDepartmentGroupSeller, sellerItem)
  2383. }
  2384. tmpDepartmentGroupSeller = sortDepartmentGroupSellers(tmpDepartmentGroupSeller)
  2385. list = append(list, tmpDepartmentGroupSeller...)
  2386. }
  2387. }
  2388. br.Ret = 200
  2389. br.Success = true
  2390. br.Msg = "获取成功"
  2391. br.Data = company.DepartmentGroupSellersResp{
  2392. List: list,
  2393. }
  2394. }
  2395. // ShareSellerList
  2396. // @Title 获取共享客户销售列表
  2397. // @Description 获取共享客户销售列表 接口
  2398. // @Success 200 {object} company.DepartmentGroupSellersResp
  2399. // @router /seller/share/list [get]
  2400. func (this *CompanySellerController) ShareSellerList() {
  2401. br := new(models.BaseResponse).Init()
  2402. defer func() {
  2403. this.Data["json"] = br
  2404. this.ServeJSON()
  2405. }()
  2406. sysUser := this.SysUser
  2407. if sysUser == nil {
  2408. br.Msg = "请登录"
  2409. br.ErrMsg = "请登录,SysUser Is Empty"
  2410. br.Ret = 408
  2411. return
  2412. }
  2413. resp := make([]company.DepartmentGroupSellers, 0)
  2414. productId := services.GetProductId(sysUser.RoleTypeCode)
  2415. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  2416. // 权益管理员,查看所有权益的账号
  2417. 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 + `"`
  2418. departmentId := 5
  2419. enabled := 1
  2420. groupList, err := system.GetSysGroupByDepartmentId(departmentId)
  2421. if err != nil {
  2422. br.Msg = "获取失败"
  2423. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  2424. return
  2425. }
  2426. for _, group := range groupList {
  2427. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  2428. groupItem := company.DepartmentGroupSellers{
  2429. AdminId: fmt.Sprint("group_", group.DepartmentId),
  2430. //AdminName string `description:"系统用户名称"`
  2431. RealName: group.GroupName,
  2432. ChildrenList: groupSellerList,
  2433. }
  2434. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  2435. if err != nil {
  2436. br.Msg = "获取小组失败"
  2437. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  2438. return
  2439. }
  2440. for _, team := range teamList {
  2441. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  2442. teamItem := company.DepartmentGroupSellers{
  2443. AdminId: fmt.Sprint("team_", team.GroupId),
  2444. //AdminName string `description:"系统用户名称"`
  2445. RealName: team.GroupName,
  2446. ChildrenList: teamSellerList,
  2447. }
  2448. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  2449. if err != nil {
  2450. br.Msg = "获取销售失败"
  2451. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  2452. return
  2453. }
  2454. for _, seller := range sellerList {
  2455. sellerItem := company.DepartmentGroupSellers{
  2456. AdminId: fmt.Sprint(seller.AdminId),
  2457. //AdminName string `description:"系统用户名称"`
  2458. RealName: seller.RealName,
  2459. Authority: seller.Authority,
  2460. RoleTypeCode: seller.RoleTypeCode,
  2461. }
  2462. //fmt.Println("seller.RealName:", seller.RealName)
  2463. teamSellerList = append(teamSellerList, sellerItem)
  2464. }
  2465. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  2466. teamItem.ChildrenList = teamSellerList
  2467. if len(teamSellerList) > 0 {
  2468. groupSellerList = append(groupSellerList, teamItem)
  2469. }
  2470. }
  2471. //分组为0的销售(直属分组)
  2472. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  2473. if err != nil {
  2474. br.Msg = "获取销售失败"
  2475. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  2476. return
  2477. }
  2478. if len(groupTeamSellerList) > 0 {
  2479. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  2480. for _, seller := range groupTeamSellerList {
  2481. sellerItem := company.DepartmentGroupSellers{
  2482. AdminId: fmt.Sprint(seller.AdminId),
  2483. //AdminName string `description:"系统用户名称"`
  2484. RealName: seller.RealName,
  2485. Authority: seller.Authority,
  2486. RoleTypeCode: seller.RoleTypeCode,
  2487. }
  2488. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  2489. }
  2490. //排个序
  2491. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  2492. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  2493. }
  2494. groupItem.ChildrenList = groupSellerList
  2495. if len(groupSellerList) > 0 {
  2496. resp = append(resp, groupItem)
  2497. }
  2498. }
  2499. //分组为0的销售(直属部门)
  2500. departmentSellerList, err := system.GetDepartmentGroupSysUserList(departmentId, 0, roleCodeTypeStr)
  2501. if err != nil {
  2502. br.Msg = "获取销售失败"
  2503. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  2504. return
  2505. }
  2506. if len(departmentSellerList) > 0 {
  2507. tmpDepartmentGroupSeller := make([]company.DepartmentGroupSellers, 0)
  2508. for _, seller := range departmentSellerList {
  2509. sellerItem := company.DepartmentGroupSellers{
  2510. AdminId: fmt.Sprint(seller.AdminId),
  2511. //AdminName string `description:"系统用户名称"`
  2512. RealName: seller.RealName,
  2513. Authority: seller.Authority,
  2514. RoleTypeCode: seller.RoleTypeCode,
  2515. }
  2516. tmpDepartmentGroupSeller = append(tmpDepartmentGroupSeller, sellerItem)
  2517. }
  2518. tmpDepartmentGroupSeller = sortDepartmentGroupSellers(tmpDepartmentGroupSeller)
  2519. resp = append(resp, tmpDepartmentGroupSeller...)
  2520. }
  2521. } else if productId == utils.COMPANY_PRODUCT_FICC_ID {
  2522. groupId := 0
  2523. if utils.RunMode == "release" {
  2524. groupId = 37
  2525. } else {
  2526. groupId = 61
  2527. }
  2528. subAdmins, err := system.GetAdminByGroupId(groupId)
  2529. if err != nil && err.Error() != utils.ErrNoRow() {
  2530. br.Msg = "获取销售失败"
  2531. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  2532. return
  2533. }
  2534. for _, seller := range subAdmins {
  2535. sellerItem := company.DepartmentGroupSellers{
  2536. AdminId: fmt.Sprint(seller.AdminId),
  2537. //AdminName string `description:"系统用户名称"`
  2538. RealName: seller.RealName,
  2539. Authority: seller.Authority,
  2540. RoleTypeCode: seller.RoleTypeCode,
  2541. }
  2542. resp = append(resp, sellerItem)
  2543. }
  2544. } else {
  2545. enabled := 1
  2546. roleCodeTypeStr := ""
  2547. departmentList, err := system.GetDepartmentList()
  2548. if err != nil {
  2549. br.Msg = "获取失败"
  2550. br.ErrMsg = "获取部门失败,Err:" + err.Error()
  2551. return
  2552. }
  2553. for _, department := range departmentList {
  2554. departmentGroupSellerList := make([]company.DepartmentGroupSellers, 0)
  2555. item := company.DepartmentGroupSellers{
  2556. AdminId: fmt.Sprint("department_", department.DepartmentId),
  2557. //AdminName string `description:"系统用户名称"`
  2558. RealName: department.DepartmentName,
  2559. ChildrenList: departmentGroupSellerList,
  2560. }
  2561. groupList, err := system.GetSysGroupByDepartmentId(department.DepartmentId)
  2562. if err != nil {
  2563. br.Msg = "获取失败"
  2564. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  2565. return
  2566. }
  2567. for _, group := range groupList {
  2568. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  2569. groupItem := company.DepartmentGroupSellers{
  2570. AdminId: fmt.Sprint("group_", group.DepartmentId),
  2571. //AdminName string `description:"系统用户名称"`
  2572. RealName: group.GroupName,
  2573. ChildrenList: groupSellerList,
  2574. }
  2575. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  2576. if err != nil {
  2577. br.Msg = "获取小组失败"
  2578. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  2579. return
  2580. }
  2581. for _, team := range teamList {
  2582. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  2583. teamItem := company.DepartmentGroupSellers{
  2584. AdminId: fmt.Sprint("team_", team.GroupId),
  2585. //AdminName string `description:"系统用户名称"`
  2586. RealName: team.GroupName,
  2587. ChildrenList: teamSellerList,
  2588. }
  2589. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  2590. if err != nil {
  2591. br.Msg = "获取销售失败"
  2592. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  2593. return
  2594. }
  2595. for _, seller := range sellerList {
  2596. sellerItem := company.DepartmentGroupSellers{
  2597. AdminId: fmt.Sprint(seller.AdminId),
  2598. //AdminName string `description:"系统用户名称"`
  2599. RealName: seller.RealName,
  2600. Authority: seller.Authority,
  2601. RoleTypeCode: seller.RoleTypeCode,
  2602. }
  2603. //fmt.Println("seller.RealName:", seller.RealName)
  2604. teamSellerList = append(teamSellerList, sellerItem)
  2605. }
  2606. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  2607. teamItem.ChildrenList = teamSellerList
  2608. if len(teamSellerList) > 0 {
  2609. groupSellerList = append(groupSellerList, teamItem)
  2610. }
  2611. }
  2612. //分组为0的销售(直属分组)
  2613. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  2614. if err != nil {
  2615. br.Msg = "获取销售失败"
  2616. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  2617. return
  2618. }
  2619. if len(groupTeamSellerList) > 0 {
  2620. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  2621. for _, seller := range groupTeamSellerList {
  2622. sellerItem := company.DepartmentGroupSellers{
  2623. AdminId: fmt.Sprint(seller.AdminId),
  2624. //AdminName string `description:"系统用户名称"`
  2625. RealName: seller.RealName,
  2626. Authority: seller.Authority,
  2627. RoleTypeCode: seller.RoleTypeCode,
  2628. }
  2629. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  2630. }
  2631. //排个序
  2632. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  2633. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  2634. }
  2635. groupItem.ChildrenList = groupSellerList
  2636. if len(groupSellerList) > 0 {
  2637. departmentGroupSellerList = append(departmentGroupSellerList, groupItem)
  2638. }
  2639. }
  2640. //分组为0的销售(直属部门)
  2641. departmentSellerList, err := system.GetDepartmentGroupSysUserList(department.DepartmentId, 0, roleCodeTypeStr)
  2642. if err != nil {
  2643. br.Msg = "获取销售失败"
  2644. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  2645. return
  2646. }
  2647. if len(departmentSellerList) > 0 {
  2648. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  2649. for _, seller := range departmentSellerList {
  2650. sellerItem := company.DepartmentGroupSellers{
  2651. AdminId: fmt.Sprint(seller.AdminId),
  2652. //AdminName string `description:"系统用户名称"`
  2653. RealName: seller.RealName,
  2654. Authority: seller.Authority,
  2655. RoleTypeCode: seller.RoleTypeCode,
  2656. }
  2657. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  2658. }
  2659. //排个序
  2660. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  2661. departmentGroupSellerList = append(departmentGroupSellerList, tmpDepartmentGroupSellersList...)
  2662. }
  2663. item.ChildrenList = departmentGroupSellerList
  2664. if len(departmentGroupSellerList) > 0 {
  2665. resp = append(resp, item)
  2666. }
  2667. }
  2668. }
  2669. br.Ret = 200
  2670. br.Success = true
  2671. br.Msg = "获取成功"
  2672. br.Data = resp
  2673. }
  2674. // RoadshowFiccList
  2675. // @Title 路演FICC销售列表
  2676. // @Description 路演FICC销售列表
  2677. // @Success 200 {object} system.RoadshowGroupResp
  2678. // @router /seller/roadshow_ficc/list [get]
  2679. func (this *CompanySellerController) RoadshowFiccList() {
  2680. br := new(models.BaseResponse).Init()
  2681. defer func() {
  2682. if br.ErrMsg == "" {
  2683. br.IsSendEmail = false
  2684. }
  2685. this.Data["json"] = br
  2686. this.ServeJSON()
  2687. }()
  2688. sysUser := this.SysUser
  2689. if sysUser == nil {
  2690. br.Msg = "请登录"
  2691. br.ErrMsg = "请登录,SysUser Is Empty"
  2692. br.Ret = 408
  2693. return
  2694. }
  2695. resp := new(system.RoadshowGroupResp)
  2696. productId := services.GetProductId(sysUser.RoleTypeCode)
  2697. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  2698. br.Ret = 200
  2699. br.Success = true
  2700. br.Msg = "获取成功"
  2701. br.Data = resp
  2702. return
  2703. }
  2704. // 分组
  2705. departmentId := 2
  2706. groups, e := system.GetGroupByDepartmentId(departmentId)
  2707. if e != nil {
  2708. br.Msg = "获取失败"
  2709. br.ErrMsg = "获取FICC分组失败, Err: " + e.Error()
  2710. return
  2711. }
  2712. teamGroupId := make(map[int]int, 0) // 小组ID对应的大组ID
  2713. var list []system.RoadshowGroups
  2714. for _, g := range groups {
  2715. if g.ParentId > 0 {
  2716. teamGroupId[g.GroupId] = g.ParentId
  2717. continue
  2718. }
  2719. // 大组
  2720. list = append(list, system.RoadshowGroups{
  2721. GroupId: g.GroupId,
  2722. GroupName: g.GroupName,
  2723. })
  2724. }
  2725. // 销售
  2726. roleArr := []string{
  2727. utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_FICC_DEPARTMENT, utils.ROLE_TYPE_CODE_FICC_GROUP,
  2728. utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_FICC_SELLER,
  2729. }
  2730. cond := fmt.Sprintf(` AND role_type_code IN (%s) AND enabled = 1`, utils.GetOrmInReplace(len(roleArr)))
  2731. pars := make([]interface{}, 0)
  2732. pars = append(pars, roleArr)
  2733. sellers, e := system.GetSysUserItemsOrderByCreated(cond, pars)
  2734. if e != nil {
  2735. br.Msg = "获取失败"
  2736. br.ErrMsg = "获取FICC销售失败, Err: " + e.Error()
  2737. return
  2738. }
  2739. groupIdChild := make(map[int][]system.RoadshowGroupSellers) // 大组ID对应的销售
  2740. for _, s := range sellers {
  2741. var seller system.RoadshowGroupSellers
  2742. seller.AdminId = s.AdminId
  2743. seller.AdminName = s.RealName
  2744. gid := teamGroupId[s.GroupId]
  2745. if gid > 0 {
  2746. // 小组
  2747. seller.GroupId = gid
  2748. seller.TeamId = s.GroupId
  2749. } else {
  2750. // 大组
  2751. seller.GroupId = s.GroupId
  2752. }
  2753. groupIdChild[seller.GroupId] = append(groupIdChild[seller.GroupId], seller)
  2754. }
  2755. // 根据当前角色过滤可选项
  2756. for _, v := range list {
  2757. // 如果是销售、组长、主管, 那么过滤掉自己大组外的其他组
  2758. 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 {
  2759. if sysUser.GroupId != v.GroupId && teamGroupId[sysUser.GroupId] != v.GroupId {
  2760. continue
  2761. }
  2762. }
  2763. child := groupIdChild[v.GroupId]
  2764. // 如果是小组长, 那么只能看到自己小组的信息
  2765. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM {
  2766. var team []system.RoadshowGroupSellers
  2767. for _, c := range child {
  2768. if c.TeamId == sysUser.GroupId {
  2769. team = append(team, c)
  2770. }
  2771. }
  2772. v.Child = team
  2773. resp.List = append(resp.List, v)
  2774. continue
  2775. }
  2776. // 如果是普通销售, 那么只能看到分组中的自己
  2777. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER {
  2778. var self []system.RoadshowGroupSellers
  2779. for _, c := range child {
  2780. if c.AdminId == sysUser.AdminId {
  2781. self = append(self, c)
  2782. break
  2783. }
  2784. }
  2785. v.Child = self
  2786. resp.List = append(resp.List, v)
  2787. continue
  2788. }
  2789. // 非以上两种情况, 可见该大组所有销售
  2790. v.Child = child
  2791. resp.List = append(resp.List, v)
  2792. }
  2793. br.Ret = 200
  2794. br.Success = true
  2795. br.Msg = "获取成功"
  2796. br.Data = resp
  2797. }
  2798. // CheckListV2
  2799. // @Title 获取组长/组员下销售(根据部门、分组)
  2800. // @Description 获取组长/组员下销售(根据部门、分组)接口
  2801. // @Param AllSeller query bool true "是否获取部门所有的销售信息"
  2802. // @Param Status query int true "客户状态 1:流失 0:非流失"
  2803. // @Param AllEnabled query bool true "是否获取包含禁用的用户"
  2804. // @Success 200 {object} company.DepartmentGroupSellersResp
  2805. // @router /seller/check/list_rai [get]
  2806. func (this *CompanySellerController) CheckListRai() {
  2807. br := new(models.BaseResponse).Init()
  2808. defer func() {
  2809. this.Data["json"] = br
  2810. this.ServeJSON()
  2811. }()
  2812. sysUser := this.SysUser
  2813. if sysUser == nil {
  2814. br.Msg = "请登录"
  2815. br.ErrMsg = "请登录,SysUser Is Empty"
  2816. br.Ret = 408
  2817. return
  2818. }
  2819. roleCodeTypeStr := ``
  2820. productId := utils.COMPANY_PRODUCT_RAI_ID
  2821. //roleCodeTypeStr = `"` + utils.ROLE_TYPE_CODE_RAI_SELLER + `","` + utils.ROLE_TYPE_CODE_RAI_GROUP + `"`
  2822. //if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  2823. // 权益管理员,查看所有权益的账号
  2824. 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 + `"`
  2825. //}
  2826. getAllSeller, _ := this.GetBool("AllSeller", false)
  2827. status, _ := this.GetInt("Status", 0)
  2828. getAllEnabled, _ := this.GetBool("AllEnabled", false)
  2829. enabled := 1 //默认只获取正常状态的用户
  2830. if getAllEnabled { //获取所有状态的用户
  2831. enabled = -1
  2832. }
  2833. list := make([]company.DepartmentGroupSellers, 0)
  2834. if getAllSeller == false {
  2835. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN || sysUser.Authority == 1 || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  2836. //部门管理员看小组、销售
  2837. departmentId := sysUser.DepartmentId
  2838. switch sysUser.RoleTypeCode {
  2839. case utils.ROLE_TYPE_CODE_ADMIN: //管理员
  2840. departmentId = 5
  2841. case utils.ROLE_TYPE_CODE_RAI_ADMIN: //权益管理员
  2842. departmentId = 5
  2843. case utils.ROLE_TYPE_CODE_FICC_ADMIN: //ficc管理员
  2844. departmentId = 2
  2845. }
  2846. groupList, err := system.GetSysGroupByDepartmentId(departmentId)
  2847. if err != nil {
  2848. br.Msg = "获取失败"
  2849. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  2850. return
  2851. }
  2852. for _, group := range groupList {
  2853. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  2854. groupItem := company.DepartmentGroupSellers{
  2855. AdminId: fmt.Sprint("group_", group.DepartmentId),
  2856. //AdminName string `description:"系统用户名称"`
  2857. RealName: group.GroupName,
  2858. ChildrenList: groupSellerList,
  2859. }
  2860. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  2861. if err != nil {
  2862. br.Msg = "获取小组失败"
  2863. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  2864. return
  2865. }
  2866. for _, team := range teamList {
  2867. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  2868. teamItem := company.DepartmentGroupSellers{
  2869. AdminId: fmt.Sprint("team_", team.GroupId),
  2870. //AdminName string `description:"系统用户名称"`
  2871. RealName: team.GroupName,
  2872. ChildrenList: teamSellerList,
  2873. }
  2874. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  2875. if err != nil {
  2876. br.Msg = "获取销售失败"
  2877. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  2878. return
  2879. }
  2880. for _, seller := range sellerList {
  2881. sellerItem := company.DepartmentGroupSellers{
  2882. AdminId: fmt.Sprint(seller.AdminId),
  2883. //AdminName string `description:"系统用户名称"`
  2884. RealName: seller.RealName,
  2885. Authority: seller.Authority,
  2886. RoleTypeCode: seller.RoleTypeCode,
  2887. }
  2888. //fmt.Println("seller.RealName:", seller.RealName)
  2889. teamSellerList = append(teamSellerList, sellerItem)
  2890. }
  2891. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  2892. teamItem.ChildrenList = teamSellerList
  2893. if len(teamSellerList) > 0 {
  2894. groupSellerList = append(groupSellerList, teamItem)
  2895. }
  2896. }
  2897. //分组为0的销售(直属分组)
  2898. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  2899. if err != nil {
  2900. br.Msg = "获取销售失败"
  2901. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  2902. return
  2903. }
  2904. if len(groupTeamSellerList) > 0 {
  2905. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  2906. for _, seller := range groupTeamSellerList {
  2907. sellerItem := company.DepartmentGroupSellers{
  2908. AdminId: fmt.Sprint(seller.AdminId),
  2909. //AdminName string `description:"系统用户名称"`
  2910. RealName: seller.RealName,
  2911. Authority: seller.Authority,
  2912. RoleTypeCode: seller.RoleTypeCode,
  2913. }
  2914. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  2915. }
  2916. //排个序
  2917. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  2918. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  2919. }
  2920. groupItem.ChildrenList = groupSellerList
  2921. if len(groupSellerList) > 0 {
  2922. list = append(list, groupItem)
  2923. }
  2924. }
  2925. //分组为0的销售(直属部门)
  2926. departmentSellerList, err := system.GetDepartmentGroupSysUserList(departmentId, 0, roleCodeTypeStr)
  2927. if err != nil {
  2928. br.Msg = "获取销售失败"
  2929. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  2930. return
  2931. }
  2932. if len(departmentSellerList) > 0 {
  2933. tmpDepartmentGroupSeller := make([]company.DepartmentGroupSellers, 0)
  2934. for _, seller := range departmentSellerList {
  2935. sellerItem := company.DepartmentGroupSellers{
  2936. AdminId: fmt.Sprint(seller.AdminId),
  2937. //AdminName string `description:"系统用户名称"`
  2938. RealName: seller.RealName,
  2939. Authority: seller.Authority,
  2940. RoleTypeCode: seller.RoleTypeCode,
  2941. }
  2942. tmpDepartmentGroupSeller = append(tmpDepartmentGroupSeller, sellerItem)
  2943. }
  2944. tmpDepartmentGroupSeller = sortDepartmentGroupSellers(tmpDepartmentGroupSeller)
  2945. list = append(list, tmpDepartmentGroupSeller...)
  2946. }
  2947. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP || (sysUser.Authority == 2 && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_FICC_GROUP) {
  2948. // 权益组长看小组
  2949. if status == 0 {
  2950. sellerList, err := system.GetTeamSysUserList(sysUser.GroupId, enabled)
  2951. if err != nil {
  2952. br.Msg = "获取销售失败"
  2953. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  2954. return
  2955. }
  2956. for _, seller := range sellerList {
  2957. sellerItem := company.DepartmentGroupSellers{
  2958. AdminId: fmt.Sprint(seller.AdminId),
  2959. //AdminName string `description:"系统用户名称"`
  2960. RealName: seller.RealName,
  2961. Authority: seller.Authority,
  2962. RoleTypeCode: seller.RoleTypeCode,
  2963. }
  2964. //fmt.Println("seller.RealName:", seller.RealName)
  2965. list = append(list, sellerItem)
  2966. }
  2967. list = sortDepartmentGroupSellers(list)
  2968. //正常来说没有所有人都应该在某个小组下,要不就是小组名为 无 的小组
  2969. //分组为0的销售(直属分组)
  2970. //groupTeamSellerList, err := system.GetGrooupsysUserList(sysUser.GroupId, 0, roleCodeTypeStr)
  2971. //if err != nil {
  2972. // br.Msg = "获取销售失败"
  2973. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  2974. // return
  2975. //}
  2976. //if len(groupTeamSellerList) > 0 {
  2977. // tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  2978. // for _, seller := range groupTeamSellerList {
  2979. // sellerItem := company.DepartmentGroupSellers{
  2980. // AdminId: fmt.Sprint(seller.AdminId),
  2981. // //AdminName string `description:"系统用户名称"`
  2982. // RealName: seller.RealName,
  2983. // Authority: seller.Authority,
  2984. // RoleTypeCode: seller.RoleTypeCode,
  2985. // }
  2986. // tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  2987. // }
  2988. // //排个序
  2989. // tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  2990. // list = append(list, tmpDepartmentGroupSellersList...)
  2991. //}
  2992. //sellerList, err := system.GetDepartmentGroupSysUserList(sysUser.DepartmentId, sysUser.GroupId, roleCodeTypeStr)
  2993. //if err != nil {
  2994. // br.Msg = "获取销售失败"
  2995. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  2996. // return
  2997. //}
  2998. //for _, seller := range sellerList {
  2999. // sellerItem := company.DepartmentGroupSellers{
  3000. // AdminId: fmt.Sprint(seller.AdminId),
  3001. // //AdminName string `description:"系统用户名称"`
  3002. // RealName: seller.RealName,
  3003. // Authority: seller.Authority,
  3004. // RoleTypeCode: seller.RoleTypeCode,
  3005. // }
  3006. // list = append(list, sellerItem)
  3007. // list = sortDepartmentGroupSellers(list)
  3008. //}
  3009. } else {
  3010. departmentId := 5
  3011. groupList, err := system.GetSysGroupByDepartmentId(departmentId)
  3012. if err != nil {
  3013. br.Msg = "获取失败"
  3014. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  3015. return
  3016. }
  3017. for _, group := range groupList {
  3018. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  3019. groupItem := company.DepartmentGroupSellers{
  3020. AdminId: fmt.Sprint("group_", group.DepartmentId),
  3021. //AdminName string `description:"系统用户名称"`
  3022. RealName: group.GroupName,
  3023. ChildrenList: groupSellerList,
  3024. }
  3025. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  3026. if err != nil {
  3027. br.Msg = "获取小组失败"
  3028. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  3029. return
  3030. }
  3031. for _, team := range teamList {
  3032. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  3033. teamItem := company.DepartmentGroupSellers{
  3034. AdminId: fmt.Sprint("team_", team.GroupId),
  3035. //AdminName string `description:"系统用户名称"`
  3036. RealName: team.GroupName,
  3037. ChildrenList: teamSellerList,
  3038. }
  3039. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  3040. if err != nil {
  3041. br.Msg = "获取销售失败"
  3042. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  3043. return
  3044. }
  3045. for _, seller := range sellerList {
  3046. sellerItem := company.DepartmentGroupSellers{
  3047. AdminId: fmt.Sprint(seller.AdminId),
  3048. //AdminName string `description:"系统用户名称"`
  3049. RealName: seller.RealName,
  3050. Authority: seller.Authority,
  3051. RoleTypeCode: seller.RoleTypeCode,
  3052. }
  3053. //fmt.Println("seller.RealName:", seller.RealName)
  3054. teamSellerList = append(teamSellerList, sellerItem)
  3055. }
  3056. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  3057. teamItem.ChildrenList = teamSellerList
  3058. if len(teamSellerList) > 0 {
  3059. groupSellerList = append(groupSellerList, teamItem)
  3060. }
  3061. }
  3062. //分组为0的销售(直属分组)
  3063. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  3064. if err != nil {
  3065. br.Msg = "获取销售失败"
  3066. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  3067. return
  3068. }
  3069. if len(groupTeamSellerList) > 0 {
  3070. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  3071. for _, seller := range groupTeamSellerList {
  3072. sellerItem := company.DepartmentGroupSellers{
  3073. AdminId: fmt.Sprint(seller.AdminId),
  3074. //AdminName string `description:"系统用户名称"`
  3075. RealName: seller.RealName,
  3076. Authority: seller.Authority,
  3077. RoleTypeCode: seller.RoleTypeCode,
  3078. }
  3079. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  3080. }
  3081. //排个序
  3082. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  3083. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  3084. }
  3085. //groupItem.ChildrenList = groupSellerList
  3086. //if len(groupSellerList) > 0 {
  3087. // list = append(list, item)
  3088. //}
  3089. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  3090. //if err != nil {
  3091. // br.Msg = "获取销售失败"
  3092. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  3093. // return
  3094. //}
  3095. //for _, seller := range sellerList {
  3096. // sellerItem := company.DepartmentGroupSellers{
  3097. // AdminId: fmt.Sprint(seller.AdminId),
  3098. // //AdminName string `description:"系统用户名称"`
  3099. // RealName: seller.RealName,
  3100. // Authority: seller.Authority,
  3101. // RoleTypeCode: seller.RoleTypeCode,
  3102. // }
  3103. // groupSellerList = append(groupSellerList, sellerItem)
  3104. //}
  3105. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  3106. groupItem.ChildrenList = groupSellerList
  3107. if len(groupSellerList) > 0 {
  3108. list = append(list, groupItem)
  3109. }
  3110. }
  3111. //分组为0的销售(直属部门)
  3112. departmentSellerList, err := system.GetDepartmentGroupSysUserList(departmentId, 0, roleCodeTypeStr)
  3113. if err != nil {
  3114. br.Msg = "获取销售失败"
  3115. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  3116. return
  3117. }
  3118. if len(departmentSellerList) > 0 {
  3119. tmpDepartmentGroupSeller := make([]company.DepartmentGroupSellers, 0)
  3120. for _, seller := range departmentSellerList {
  3121. sellerItem := company.DepartmentGroupSellers{
  3122. AdminId: fmt.Sprint(seller.AdminId),
  3123. //AdminName string `description:"系统用户名称"`
  3124. RealName: seller.RealName,
  3125. Authority: seller.Authority,
  3126. RoleTypeCode: seller.RoleTypeCode,
  3127. }
  3128. tmpDepartmentGroupSeller = append(tmpDepartmentGroupSeller, sellerItem)
  3129. }
  3130. tmpDepartmentGroupSeller = sortDepartmentGroupSellers(tmpDepartmentGroupSeller)
  3131. list = append(list, tmpDepartmentGroupSeller...)
  3132. }
  3133. }
  3134. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || sysUser.Authority == 2 {
  3135. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER && status == 1 {
  3136. //var departmentStr string
  3137. //if utils.RunMode == "release" {
  3138. // departmentStr = `1,2`
  3139. //} else {
  3140. // departmentStr = `1,2`
  3141. //}
  3142. departmentStr := `1,2`
  3143. departmentList, err := system.GetDepartmentListByIds(departmentStr)
  3144. if err != nil {
  3145. br.Msg = "获取失败"
  3146. br.ErrMsg = "获取部门失败,Err:" + err.Error()
  3147. return
  3148. }
  3149. for _, department := range departmentList {
  3150. departmentGroupSellerList := make([]company.DepartmentGroupSellers, 0)
  3151. item := company.DepartmentGroupSellers{
  3152. AdminId: fmt.Sprint("department_", department.DepartmentId),
  3153. //AdminName string `description:"系统用户名称"`
  3154. RealName: department.DepartmentName,
  3155. ChildrenList: departmentGroupSellerList,
  3156. }
  3157. groupList, err := system.GetSysGroupByDepartmentId(department.DepartmentId)
  3158. if err != nil {
  3159. br.Msg = "获取失败"
  3160. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  3161. return
  3162. }
  3163. for _, group := range groupList {
  3164. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  3165. groupItem := company.DepartmentGroupSellers{
  3166. AdminId: fmt.Sprint("group_", group.DepartmentId),
  3167. //AdminName string `description:"系统用户名称"`
  3168. RealName: group.GroupName,
  3169. ChildrenList: groupSellerList,
  3170. }
  3171. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  3172. if err != nil {
  3173. br.Msg = "获取小组失败"
  3174. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  3175. return
  3176. }
  3177. for _, team := range teamList {
  3178. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  3179. teamItem := company.DepartmentGroupSellers{
  3180. AdminId: fmt.Sprint("team_", team.GroupId),
  3181. //AdminName string `description:"系统用户名称"`
  3182. RealName: team.GroupName,
  3183. ChildrenList: teamSellerList,
  3184. }
  3185. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  3186. if err != nil {
  3187. br.Msg = "获取销售失败"
  3188. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  3189. return
  3190. }
  3191. for _, seller := range sellerList {
  3192. sellerItem := company.DepartmentGroupSellers{
  3193. AdminId: fmt.Sprint(seller.AdminId),
  3194. //AdminName string `description:"系统用户名称"`
  3195. RealName: seller.RealName,
  3196. Authority: seller.Authority,
  3197. RoleTypeCode: seller.RoleTypeCode,
  3198. }
  3199. //fmt.Println("seller.RealName:", seller.RealName)
  3200. teamSellerList = append(teamSellerList, sellerItem)
  3201. }
  3202. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  3203. teamItem.ChildrenList = teamSellerList
  3204. if len(teamSellerList) > 0 {
  3205. groupSellerList = append(groupSellerList, teamItem)
  3206. }
  3207. }
  3208. //分组为0的人,不光是销售(直属分组)
  3209. groupTeamSellerList, err := system.GetGroupSysUserList(group.GroupId)
  3210. if err != nil {
  3211. br.Msg = "获取销售失败"
  3212. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  3213. return
  3214. }
  3215. if len(groupTeamSellerList) > 0 {
  3216. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  3217. for _, seller := range groupTeamSellerList {
  3218. sellerItem := company.DepartmentGroupSellers{
  3219. AdminId: fmt.Sprint(seller.AdminId),
  3220. //AdminName string `description:"系统用户名称"`
  3221. RealName: seller.RealName,
  3222. Authority: seller.Authority,
  3223. RoleTypeCode: seller.RoleTypeCode,
  3224. }
  3225. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  3226. }
  3227. //排个序
  3228. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  3229. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  3230. }
  3231. //groupItem.ChildrenList = groupSellerList
  3232. //if len(groupSellerList) > 0 {
  3233. // list = append(list, item)
  3234. //}
  3235. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  3236. //if err != nil {
  3237. // br.Msg = "获取销售失败"
  3238. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  3239. // return
  3240. //}
  3241. //for _, seller := range sellerList {
  3242. // sellerItem := company.DepartmentGroupSellers{
  3243. // AdminId: fmt.Sprint(seller.AdminId),
  3244. // //AdminName string `description:"系统用户名称"`
  3245. // RealName: seller.RealName,
  3246. // Authority: seller.Authority,
  3247. // RoleTypeCode: seller.RoleTypeCode,
  3248. // }
  3249. // groupSellerList = append(groupSellerList, sellerItem)
  3250. //}
  3251. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  3252. groupItem.ChildrenList = groupSellerList
  3253. if len(groupSellerList) > 0 {
  3254. departmentGroupSellerList = append(departmentGroupSellerList, groupItem)
  3255. }
  3256. }
  3257. //分组为0的人,不光是销售(直属部门)
  3258. departmentSellerList, err := system.GetDepartmentGroupSysUserList(department.DepartmentId, 0, "")
  3259. if err != nil {
  3260. br.Msg = "获取销售失败"
  3261. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  3262. return
  3263. }
  3264. if len(departmentSellerList) > 0 {
  3265. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  3266. for _, seller := range departmentSellerList {
  3267. sellerItem := company.DepartmentGroupSellers{
  3268. AdminId: fmt.Sprint(seller.AdminId),
  3269. //AdminName string `description:"系统用户名称"`
  3270. RealName: seller.RealName,
  3271. Authority: seller.Authority,
  3272. RoleTypeCode: seller.RoleTypeCode,
  3273. }
  3274. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  3275. }
  3276. //排个序
  3277. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  3278. departmentGroupSellerList = append(departmentGroupSellerList, tmpDepartmentGroupSellersList...)
  3279. }
  3280. item.ChildrenList = departmentGroupSellerList
  3281. if len(departmentGroupSellerList) > 0 {
  3282. list = append(list, item)
  3283. }
  3284. }
  3285. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER && status == 1 {
  3286. // 权益销售可以看到权益销售部的所有人
  3287. departmentId := 5
  3288. groupList, err := system.GetSysGroupByDepartmentId(departmentId)
  3289. if err != nil {
  3290. br.Msg = "获取失败"
  3291. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  3292. return
  3293. }
  3294. for _, group := range groupList {
  3295. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  3296. groupItem := company.DepartmentGroupSellers{
  3297. AdminId: fmt.Sprint("group_", group.DepartmentId),
  3298. //AdminName string `description:"系统用户名称"`
  3299. RealName: group.GroupName,
  3300. ChildrenList: groupSellerList,
  3301. }
  3302. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  3303. if err != nil {
  3304. br.Msg = "获取小组失败"
  3305. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  3306. return
  3307. }
  3308. for _, team := range teamList {
  3309. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  3310. teamItem := company.DepartmentGroupSellers{
  3311. AdminId: fmt.Sprint("team_", team.GroupId),
  3312. //AdminName string `description:"系统用户名称"`
  3313. RealName: team.GroupName,
  3314. ChildrenList: teamSellerList,
  3315. }
  3316. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  3317. if err != nil {
  3318. br.Msg = "获取销售失败"
  3319. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  3320. return
  3321. }
  3322. for _, seller := range sellerList {
  3323. sellerItem := company.DepartmentGroupSellers{
  3324. AdminId: fmt.Sprint(seller.AdminId),
  3325. //AdminName string `description:"系统用户名称"`
  3326. RealName: seller.RealName,
  3327. Authority: seller.Authority,
  3328. RoleTypeCode: seller.RoleTypeCode,
  3329. }
  3330. //fmt.Println("seller.RealName:", seller.RealName)
  3331. teamSellerList = append(teamSellerList, sellerItem)
  3332. }
  3333. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  3334. teamItem.ChildrenList = teamSellerList
  3335. if len(teamSellerList) > 0 {
  3336. groupSellerList = append(groupSellerList, teamItem)
  3337. }
  3338. }
  3339. //分组为0的销售(直属分组)
  3340. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  3341. if err != nil {
  3342. br.Msg = "获取销售失败"
  3343. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  3344. return
  3345. }
  3346. if len(groupTeamSellerList) > 0 {
  3347. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  3348. for _, seller := range groupTeamSellerList {
  3349. sellerItem := company.DepartmentGroupSellers{
  3350. AdminId: fmt.Sprint(seller.AdminId),
  3351. //AdminName string `description:"系统用户名称"`
  3352. RealName: seller.RealName,
  3353. Authority: seller.Authority,
  3354. RoleTypeCode: seller.RoleTypeCode,
  3355. }
  3356. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  3357. }
  3358. //排个序
  3359. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  3360. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  3361. }
  3362. //groupItem.ChildrenList = groupSellerList
  3363. //if len(groupSellerList) > 0 {
  3364. // list = append(list, item)
  3365. //}
  3366. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  3367. //if err != nil {
  3368. // br.Msg = "获取销售失败"
  3369. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  3370. // return
  3371. //}
  3372. //for _, seller := range sellerList {
  3373. // sellerItem := company.DepartmentGroupSellers{
  3374. // AdminId: fmt.Sprint(seller.AdminId),
  3375. // //AdminName string `description:"系统用户名称"`
  3376. // RealName: seller.RealName,
  3377. // Authority: seller.Authority,
  3378. // RoleTypeCode: seller.RoleTypeCode,
  3379. // }
  3380. // groupSellerList = append(groupSellerList, sellerItem)
  3381. //}
  3382. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  3383. groupItem.ChildrenList = groupSellerList
  3384. if len(groupSellerList) > 0 {
  3385. list = append(list, groupItem)
  3386. }
  3387. }
  3388. //分组为0的销售(直属部门)
  3389. departmentSellerList, err := system.GetDepartmentGroupSysUserList(departmentId, 0, roleCodeTypeStr)
  3390. if err != nil {
  3391. br.Msg = "获取销售失败"
  3392. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  3393. return
  3394. }
  3395. if len(departmentSellerList) > 0 {
  3396. tmpDepartmentGroupSeller := make([]company.DepartmentGroupSellers, 0)
  3397. for _, seller := range departmentSellerList {
  3398. sellerItem := company.DepartmentGroupSellers{
  3399. AdminId: fmt.Sprint(seller.AdminId),
  3400. //AdminName string `description:"系统用户名称"`
  3401. RealName: seller.RealName,
  3402. Authority: seller.Authority,
  3403. RoleTypeCode: seller.RoleTypeCode,
  3404. }
  3405. tmpDepartmentGroupSeller = append(tmpDepartmentGroupSeller, sellerItem)
  3406. }
  3407. tmpDepartmentGroupSeller = sortDepartmentGroupSellers(tmpDepartmentGroupSeller)
  3408. list = append(list, tmpDepartmentGroupSeller...)
  3409. }
  3410. } else {
  3411. //看自己
  3412. sellerItem := company.DepartmentGroupSellers{
  3413. AdminId: fmt.Sprint(sysUser.AdminId),
  3414. //AdminName string `description:"系统用户名称"`
  3415. RealName: sysUser.RealName,
  3416. }
  3417. list = append(list, sellerItem)
  3418. }
  3419. } else {
  3420. departmentId := sysUser.DepartmentId
  3421. switch productId {
  3422. case 1:
  3423. departmentId = 2
  3424. case 5:
  3425. departmentId = 5
  3426. }
  3427. //查询整个部门的小组、销售
  3428. groupList, err := system.GetSysGroupByDepartmentId(departmentId)
  3429. if err != nil {
  3430. br.Msg = "获取失败"
  3431. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  3432. return
  3433. }
  3434. for _, group := range groupList {
  3435. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  3436. groupItem := company.DepartmentGroupSellers{
  3437. AdminId: fmt.Sprint("group_", group.DepartmentId),
  3438. //AdminName string `description:"系统用户名称"`
  3439. RealName: group.GroupName,
  3440. ChildrenList: groupSellerList,
  3441. }
  3442. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  3443. if err != nil {
  3444. br.Msg = "获取小组失败"
  3445. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  3446. return
  3447. }
  3448. for _, team := range teamList {
  3449. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  3450. teamItem := company.DepartmentGroupSellers{
  3451. AdminId: fmt.Sprint("team_", team.GroupId),
  3452. //AdminName string `description:"系统用户名称"`
  3453. RealName: team.GroupName,
  3454. ChildrenList: teamSellerList,
  3455. }
  3456. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  3457. if err != nil {
  3458. br.Msg = "获取销售失败"
  3459. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  3460. return
  3461. }
  3462. for _, seller := range sellerList {
  3463. sellerItem := company.DepartmentGroupSellers{
  3464. AdminId: fmt.Sprint(seller.AdminId),
  3465. //AdminName string `description:"系统用户名称"`
  3466. RealName: seller.RealName,
  3467. Authority: seller.Authority,
  3468. RoleTypeCode: seller.RoleTypeCode,
  3469. }
  3470. //fmt.Println("seller.RealName:", seller.RealName)
  3471. teamSellerList = append(teamSellerList, sellerItem)
  3472. }
  3473. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  3474. teamItem.ChildrenList = teamSellerList
  3475. if len(teamSellerList) > 0 {
  3476. groupSellerList = append(groupSellerList, teamItem)
  3477. }
  3478. }
  3479. //分组为0的销售(直属分组)
  3480. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  3481. if err != nil {
  3482. br.Msg = "获取销售失败"
  3483. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  3484. return
  3485. }
  3486. if len(groupTeamSellerList) > 0 {
  3487. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  3488. for _, seller := range groupTeamSellerList {
  3489. sellerItem := company.DepartmentGroupSellers{
  3490. AdminId: fmt.Sprint(seller.AdminId),
  3491. //AdminName string `description:"系统用户名称"`
  3492. RealName: seller.RealName,
  3493. Authority: seller.Authority,
  3494. RoleTypeCode: seller.RoleTypeCode,
  3495. }
  3496. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  3497. }
  3498. //排个序
  3499. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  3500. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  3501. }
  3502. groupItem.ChildrenList = groupSellerList
  3503. if len(groupSellerList) > 0 {
  3504. list = append(list, groupItem)
  3505. }
  3506. }
  3507. //分组为0的销售(直属部门)
  3508. departmentSellerList, err := system.GetDepartmentGroupSysUserList(departmentId, 0, roleCodeTypeStr)
  3509. if err != nil {
  3510. br.Msg = "获取销售失败"
  3511. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  3512. return
  3513. }
  3514. if len(departmentSellerList) > 0 {
  3515. tmpDepartmentGroupSeller := make([]company.DepartmentGroupSellers, 0)
  3516. for _, seller := range departmentSellerList {
  3517. sellerItem := company.DepartmentGroupSellers{
  3518. AdminId: fmt.Sprint(seller.AdminId),
  3519. //AdminName string `description:"系统用户名称"`
  3520. RealName: seller.RealName,
  3521. Authority: seller.Authority,
  3522. RoleTypeCode: seller.RoleTypeCode,
  3523. }
  3524. tmpDepartmentGroupSeller = append(tmpDepartmentGroupSeller, sellerItem)
  3525. }
  3526. //排个序
  3527. tmpDepartmentGroupSeller = sortDepartmentGroupSellers(tmpDepartmentGroupSeller)
  3528. list = append(list, tmpDepartmentGroupSeller...)
  3529. }
  3530. }
  3531. // 海外销售部-目前无权限, 均可见
  3532. seaDepartment, e := system.GetSysDepartmentByName("海外销售部")
  3533. if e != nil && e.Error() != utils.ErrNoRow() {
  3534. br.Msg = "获取失败"
  3535. br.ErrMsg = "获取海外销售部失败, Err: " + e.Error()
  3536. return
  3537. }
  3538. if e == nil {
  3539. // 获取部门下的销售人员
  3540. seaSellers, e := system.GetDepartmentGroupSysUserList(seaDepartment.DepartmentId, 0, "")
  3541. if e != nil {
  3542. br.Msg = "获取失败"
  3543. br.ErrMsg = "获取海外销售失败, Err: " + e.Error()
  3544. return
  3545. }
  3546. // 获取分组
  3547. seaGroups, e := system.GetSysGroupListByDepartmentId(seaDepartment.DepartmentId)
  3548. if e != nil {
  3549. br.Msg = "获取失败"
  3550. br.ErrMsg = "获取海外销售部分组失败, Err: " + e.Error()
  3551. return
  3552. }
  3553. var d company.DepartmentGroupSellers
  3554. d.AdminId = fmt.Sprintf("department_%d", seaDepartment.DepartmentId)
  3555. d.RealName = seaDepartment.DepartmentName
  3556. children := make([]company.DepartmentGroupSellers, 0)
  3557. // 无分组
  3558. if len(seaGroups) == 0 {
  3559. for _, s := range seaSellers {
  3560. children = append(children, company.DepartmentGroupSellers{
  3561. AdminId: strconv.Itoa(s.AdminId),
  3562. RealName: s.RealName,
  3563. RoleTypeCode: s.RoleTypeCode,
  3564. Authority: s.Authority,
  3565. })
  3566. }
  3567. }
  3568. // 有分组
  3569. if len(seaGroups) > 0 {
  3570. // 销售map
  3571. sellerMap := make(map[int][]company.DepartmentGroupSellers)
  3572. for _, s := range seaSellers {
  3573. sellerMap[s.GroupId] = append(sellerMap[s.GroupId], company.DepartmentGroupSellers{
  3574. AdminId: strconv.Itoa(s.AdminId),
  3575. RealName: s.RealName,
  3576. RoleTypeCode: s.RoleTypeCode,
  3577. Authority: s.Authority,
  3578. })
  3579. }
  3580. // 小组map
  3581. childrenMap := make(map[int][]company.DepartmentGroupSellers)
  3582. for _, g := range seaGroups {
  3583. if g.ParentId == 0 {
  3584. continue
  3585. }
  3586. childrenMap[g.ParentId] = append(childrenMap[g.ParentId], company.DepartmentGroupSellers{
  3587. AdminId: fmt.Sprintf("team_%d", g.GroupId),
  3588. RealName: g.GroupName,
  3589. ChildrenList: sellerMap[g.GroupId],
  3590. })
  3591. }
  3592. // 大组
  3593. for _, g := range seaGroups {
  3594. if g.ParentId > 0 {
  3595. continue
  3596. }
  3597. c := childrenMap[g.GroupId]
  3598. if len(sellerMap[g.GroupId]) > 0 {
  3599. c = append(c, sellerMap[g.GroupId]...)
  3600. }
  3601. children = append(children, company.DepartmentGroupSellers{
  3602. AdminId: fmt.Sprintf("group_%d", g.GroupId),
  3603. RealName: g.GroupName,
  3604. ChildrenList: c,
  3605. })
  3606. }
  3607. }
  3608. d.ChildrenList = children
  3609. list = append(list, d)
  3610. }
  3611. br.Ret = 200
  3612. br.Success = true
  3613. br.Msg = "获取成功"
  3614. br.Data = company.DepartmentGroupSellersResp{
  3615. List: list,
  3616. }
  3617. }
  3618. // ShareCheckList2
  3619. // @Title 获取组长/组员下销售(根据部门、分组)
  3620. // @Description 获取组长/组员下销售(根据部门、分组)接口
  3621. // @Param AllSeller query bool true "是否获取部门所有的销售信息"
  3622. // @Param Status query int true "客户状态 1:流失 0:非流失"
  3623. // @Param AllEnabled query bool true "是否获取包含禁用的用户"
  3624. // @Success 200 {object} company.DepartmentGroupSellersResp
  3625. // @router /seller/check/Sharelist2 [get]
  3626. func (this *CompanySellerController) ShareCheckList2() {
  3627. br := new(models.BaseResponse).Init()
  3628. defer func() {
  3629. this.Data["json"] = br
  3630. this.ServeJSON()
  3631. }()
  3632. sysUser := this.SysUser
  3633. if sysUser == nil {
  3634. br.Msg = "请登录"
  3635. br.ErrMsg = "请登录,SysUser Is Empty"
  3636. br.Ret = 408
  3637. return
  3638. }
  3639. roleCodeTypeStr := ``
  3640. productId := services.GetProductId(sysUser.RoleTypeCode)
  3641. switch productId {
  3642. case 1:
  3643. roleCodeTypeStr = `"` + utils.ROLE_TYPE_CODE_FICC_SELLER + `","` + utils.ROLE_TYPE_CODE_FICC_GROUP + `","` + utils.ROLE_TYPE_CODE_FICC_TEAM + `"`
  3644. case 2:
  3645. roleCodeTypeStr = `"` + utils.ROLE_TYPE_CODE_RAI_SELLER + `","` + utils.ROLE_TYPE_CODE_RAI_GROUP + `"`
  3646. }
  3647. // ficc管理员,不要只查销售
  3648. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  3649. roleCodeTypeStr = ``
  3650. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  3651. // 权益管理员,查看所有权益的账号
  3652. 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 + `"`
  3653. }
  3654. status, _ := this.GetInt("Status", 0)
  3655. getAllEnabled, _ := this.GetBool("AllEnabled", false)
  3656. enabled := 1 //默认只获取正常状态的用户
  3657. if getAllEnabled { //获取所有状态的用户
  3658. enabled = -1
  3659. }
  3660. resp := make([]company.DepartmentGroupSellers, 0)
  3661. list := make([]company.DepartmentGroupSellers, 0)
  3662. if productId != 2 {
  3663. //超管看部门、小组、销售
  3664. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3665. departmentList, err := system.GetDepartmentList()
  3666. if err != nil {
  3667. br.Msg = "获取失败"
  3668. br.ErrMsg = "获取部门失败,Err:" + err.Error()
  3669. return
  3670. }
  3671. for _, department := range departmentList {
  3672. departmentGroupSellerList := make([]company.DepartmentGroupSellers, 0)
  3673. item := company.DepartmentGroupSellers{
  3674. AdminId: fmt.Sprint("department_", department.DepartmentId),
  3675. //AdminName string `description:"系统用户名称"`
  3676. RealName: department.DepartmentName,
  3677. ChildrenList: departmentGroupSellerList,
  3678. }
  3679. groupList, err := system.GetSysGroupByDepartmentId(department.DepartmentId)
  3680. if err != nil {
  3681. br.Msg = "获取失败"
  3682. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  3683. return
  3684. }
  3685. for _, group := range groupList {
  3686. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  3687. groupItem := company.DepartmentGroupSellers{
  3688. AdminId: fmt.Sprint("group_", group.DepartmentId),
  3689. //AdminName string `description:"系统用户名称"`
  3690. RealName: group.GroupName,
  3691. ChildrenList: groupSellerList,
  3692. }
  3693. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  3694. if err != nil {
  3695. br.Msg = "获取小组失败"
  3696. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  3697. return
  3698. }
  3699. for _, team := range teamList {
  3700. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  3701. teamItem := company.DepartmentGroupSellers{
  3702. AdminId: fmt.Sprint("team_", team.GroupId),
  3703. //AdminName string `description:"系统用户名称"`
  3704. RealName: team.GroupName,
  3705. ChildrenList: teamSellerList,
  3706. }
  3707. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  3708. if err != nil {
  3709. br.Msg = "获取销售失败"
  3710. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  3711. return
  3712. }
  3713. for _, seller := range sellerList {
  3714. sellerItem := company.DepartmentGroupSellers{
  3715. AdminId: fmt.Sprint(seller.AdminId),
  3716. //AdminName string `description:"系统用户名称"`
  3717. RealName: seller.RealName,
  3718. Authority: seller.Authority,
  3719. RoleTypeCode: seller.RoleTypeCode,
  3720. }
  3721. //fmt.Println("seller.RealName:", seller.RealName)
  3722. teamSellerList = append(teamSellerList, sellerItem)
  3723. }
  3724. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  3725. teamItem.ChildrenList = teamSellerList
  3726. if len(teamSellerList) > 0 {
  3727. groupSellerList = append(groupSellerList, teamItem)
  3728. }
  3729. }
  3730. //分组为0的销售(直属分组)
  3731. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  3732. if err != nil {
  3733. br.Msg = "获取销售失败"
  3734. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  3735. return
  3736. }
  3737. if len(groupTeamSellerList) > 0 {
  3738. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  3739. for _, seller := range groupTeamSellerList {
  3740. sellerItem := company.DepartmentGroupSellers{
  3741. AdminId: fmt.Sprint(seller.AdminId),
  3742. //AdminName string `description:"系统用户名称"`
  3743. RealName: seller.RealName,
  3744. Authority: seller.Authority,
  3745. RoleTypeCode: seller.RoleTypeCode,
  3746. }
  3747. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  3748. }
  3749. //排个序
  3750. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  3751. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  3752. }
  3753. //groupItem.ChildrenList = groupSellerList
  3754. //if len(groupSellerList) > 0 {
  3755. // list = append(list, item)
  3756. //}
  3757. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  3758. //if err != nil {
  3759. // br.Msg = "获取销售失败"
  3760. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  3761. // return
  3762. //}
  3763. //for _, seller := range sellerList {
  3764. // sellerItem := company.DepartmentGroupSellers{
  3765. // AdminId: fmt.Sprint(seller.AdminId),
  3766. // //AdminName string `description:"系统用户名称"`
  3767. // RealName: seller.RealName,
  3768. // Authority: seller.Authority,
  3769. // RoleTypeCode: seller.RoleTypeCode,
  3770. // }
  3771. // groupSellerList = append(groupSellerList, sellerItem)
  3772. //}
  3773. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  3774. groupItem.ChildrenList = groupSellerList
  3775. if len(groupSellerList) > 0 {
  3776. departmentGroupSellerList = append(departmentGroupSellerList, groupItem)
  3777. }
  3778. }
  3779. //分组为0的销售(直属部门)
  3780. departmentSellerList, err := system.GetDepartmentGroupSysUserList(department.DepartmentId, 0, roleCodeTypeStr)
  3781. if err != nil {
  3782. br.Msg = "获取销售失败"
  3783. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  3784. return
  3785. }
  3786. if len(departmentSellerList) > 0 {
  3787. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  3788. for _, seller := range departmentSellerList {
  3789. sellerItem := company.DepartmentGroupSellers{
  3790. AdminId: fmt.Sprint(seller.AdminId),
  3791. //AdminName string `description:"系统用户名称"`
  3792. RealName: seller.RealName,
  3793. Authority: seller.Authority,
  3794. RoleTypeCode: seller.RoleTypeCode,
  3795. }
  3796. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  3797. }
  3798. //排个序
  3799. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  3800. departmentGroupSellerList = append(departmentGroupSellerList, tmpDepartmentGroupSellersList...)
  3801. }
  3802. item.ChildrenList = departmentGroupSellerList
  3803. if len(departmentGroupSellerList) > 0 {
  3804. list = append(list, item)
  3805. }
  3806. }
  3807. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM || sysUser.Authority == 4 {
  3808. //销售组长看销售
  3809. if status == 0 {
  3810. directorId := sysUser.GroupId
  3811. fmt.Println("directorId:", directorId)
  3812. groupList, err := system.GetSysGroupByDirectorId(directorId)
  3813. if err != nil {
  3814. br.Msg = "获取失败"
  3815. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  3816. return
  3817. }
  3818. for _, group := range groupList {
  3819. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  3820. groupItem := company.DepartmentGroupSellers{
  3821. AdminId: fmt.Sprint("group_", group.DepartmentId),
  3822. //AdminName string `description:"系统用户名称"`
  3823. RealName: group.GroupName,
  3824. ChildrenList: groupSellerList,
  3825. }
  3826. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  3827. if err != nil {
  3828. br.Msg = "获取小组失败"
  3829. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  3830. return
  3831. }
  3832. for _, team := range teamList {
  3833. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  3834. teamItem := company.DepartmentGroupSellers{
  3835. AdminId: fmt.Sprint("team_", team.GroupId),
  3836. //AdminName string `description:"系统用户名称"`
  3837. RealName: team.GroupName,
  3838. ChildrenList: teamSellerList,
  3839. }
  3840. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  3841. if err != nil {
  3842. br.Msg = "获取销售失败"
  3843. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  3844. return
  3845. }
  3846. for _, seller := range sellerList {
  3847. sellerItem := company.DepartmentGroupSellers{
  3848. AdminId: fmt.Sprint(seller.AdminId),
  3849. //AdminName string `description:"系统用户名称"`
  3850. RealName: seller.RealName,
  3851. Authority: seller.Authority,
  3852. RoleTypeCode: seller.RoleTypeCode,
  3853. }
  3854. //fmt.Println("seller.RealName:", seller.RealName)
  3855. teamSellerList = append(teamSellerList, sellerItem)
  3856. }
  3857. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  3858. teamItem.ChildrenList = teamSellerList
  3859. if len(teamSellerList) > 0 {
  3860. groupSellerList = append(groupSellerList, teamItem)
  3861. }
  3862. }
  3863. //分组为0的销售(直属分组)
  3864. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  3865. if err != nil {
  3866. br.Msg = "获取销售失败"
  3867. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  3868. return
  3869. }
  3870. if len(groupTeamSellerList) > 0 {
  3871. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  3872. for _, seller := range groupTeamSellerList {
  3873. sellerItem := company.DepartmentGroupSellers{
  3874. AdminId: fmt.Sprint(seller.AdminId),
  3875. //AdminName string `description:"系统用户名称"`
  3876. RealName: seller.RealName,
  3877. Authority: seller.Authority,
  3878. RoleTypeCode: seller.RoleTypeCode,
  3879. }
  3880. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  3881. }
  3882. //排个序
  3883. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  3884. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  3885. }
  3886. groupItem.ChildrenList = groupSellerList
  3887. if len(groupSellerList) > 0 {
  3888. list = append(list, groupItem)
  3889. }
  3890. }
  3891. } else {
  3892. departmentStr := `1,2`
  3893. departmentList, err := system.GetDepartmentListByIds(departmentStr)
  3894. if err != nil {
  3895. br.Msg = "获取失败"
  3896. br.ErrMsg = "获取部门失败,Err:" + err.Error()
  3897. return
  3898. }
  3899. for _, department := range departmentList {
  3900. departmentGroupSellerList := make([]company.DepartmentGroupSellers, 0)
  3901. item := company.DepartmentGroupSellers{
  3902. AdminId: fmt.Sprint("department_", department.DepartmentId),
  3903. //AdminName string `description:"系统用户名称"`
  3904. RealName: department.DepartmentName,
  3905. ChildrenList: departmentGroupSellerList,
  3906. }
  3907. groupList, err := system.GetSysGroupByDepartmentId(department.DepartmentId)
  3908. if err != nil {
  3909. br.Msg = "获取失败"
  3910. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  3911. return
  3912. }
  3913. for _, group := range groupList {
  3914. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  3915. groupItem := company.DepartmentGroupSellers{
  3916. AdminId: fmt.Sprint("group_", group.DepartmentId),
  3917. //AdminName string `description:"系统用户名称"`
  3918. RealName: group.GroupName,
  3919. ChildrenList: groupSellerList,
  3920. }
  3921. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  3922. if err != nil {
  3923. br.Msg = "获取小组失败"
  3924. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  3925. return
  3926. }
  3927. for _, team := range teamList {
  3928. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  3929. teamItem := company.DepartmentGroupSellers{
  3930. AdminId: fmt.Sprint("team_", team.GroupId),
  3931. //AdminName string `description:"系统用户名称"`
  3932. RealName: team.GroupName,
  3933. ChildrenList: teamSellerList,
  3934. }
  3935. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  3936. if err != nil {
  3937. br.Msg = "获取销售失败"
  3938. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  3939. return
  3940. }
  3941. for _, seller := range sellerList {
  3942. sellerItem := company.DepartmentGroupSellers{
  3943. AdminId: fmt.Sprint(seller.AdminId),
  3944. //AdminName string `description:"系统用户名称"`
  3945. RealName: seller.RealName,
  3946. Authority: seller.Authority,
  3947. RoleTypeCode: seller.RoleTypeCode,
  3948. }
  3949. //fmt.Println("seller.RealName:", seller.RealName)
  3950. teamSellerList = append(teamSellerList, sellerItem)
  3951. }
  3952. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  3953. teamItem.ChildrenList = teamSellerList
  3954. if len(teamSellerList) > 0 {
  3955. groupSellerList = append(groupSellerList, teamItem)
  3956. }
  3957. }
  3958. //分组为0的人,不光是销售(直属分组)
  3959. groupTeamSellerList, err := system.GetGroupSysUserList(group.GroupId)
  3960. if err != nil {
  3961. br.Msg = "获取销售失败"
  3962. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  3963. return
  3964. }
  3965. if len(groupTeamSellerList) > 0 {
  3966. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  3967. for _, seller := range groupTeamSellerList {
  3968. sellerItem := company.DepartmentGroupSellers{
  3969. AdminId: fmt.Sprint(seller.AdminId),
  3970. //AdminName string `description:"系统用户名称"`
  3971. RealName: seller.RealName,
  3972. Authority: seller.Authority,
  3973. RoleTypeCode: seller.RoleTypeCode,
  3974. }
  3975. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  3976. }
  3977. //排个序
  3978. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  3979. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  3980. }
  3981. //groupItem.ChildrenList = groupSellerList
  3982. //if len(groupSellerList) > 0 {
  3983. // list = append(list, item)
  3984. //}
  3985. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  3986. //if err != nil {
  3987. // br.Msg = "获取销售失败"
  3988. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  3989. // return
  3990. //}
  3991. //for _, seller := range sellerList {
  3992. // sellerItem := company.DepartmentGroupSellers{
  3993. // AdminId: fmt.Sprint(seller.AdminId),
  3994. // //AdminName string `description:"系统用户名称"`
  3995. // RealName: seller.RealName,
  3996. // Authority: seller.Authority,
  3997. // RoleTypeCode: seller.RoleTypeCode,
  3998. // }
  3999. // groupSellerList = append(groupSellerList, sellerItem)
  4000. //}
  4001. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  4002. groupItem.ChildrenList = groupSellerList
  4003. if len(groupSellerList) > 0 {
  4004. departmentGroupSellerList = append(departmentGroupSellerList, groupItem)
  4005. }
  4006. }
  4007. //分组为0的人,不光是销售(直属部门)
  4008. departmentSellerList, err := system.GetDepartmentGroupSysUserList(department.DepartmentId, 0, "")
  4009. if err != nil {
  4010. br.Msg = "获取销售失败"
  4011. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  4012. return
  4013. }
  4014. if len(departmentSellerList) > 0 {
  4015. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  4016. for _, seller := range departmentSellerList {
  4017. sellerItem := company.DepartmentGroupSellers{
  4018. AdminId: fmt.Sprint(seller.AdminId),
  4019. //AdminName string `description:"系统用户名称"`
  4020. RealName: seller.RealName,
  4021. Authority: seller.Authority,
  4022. RoleTypeCode: seller.RoleTypeCode,
  4023. }
  4024. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  4025. }
  4026. //排个序
  4027. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  4028. departmentGroupSellerList = append(departmentGroupSellerList, tmpDepartmentGroupSellersList...)
  4029. }
  4030. item.ChildrenList = departmentGroupSellerList
  4031. if len(departmentGroupSellerList) > 0 {
  4032. list = append(list, item)
  4033. }
  4034. }
  4035. }
  4036. } 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管理员
  4037. departmentStr := `2,5,7` //合规
  4038. switch sysUser.RoleTypeCode {
  4039. case utils.ROLE_TYPE_CODE_FINANCE: //财务
  4040. departmentStr = `2,5,8`
  4041. case utils.ROLE_TYPE_CODE_FICC_ADMIN: //ficc管理员
  4042. departmentStr = utils.GetFiccAdminDepartmentIds()
  4043. }
  4044. departmentList, err := system.GetDepartmentListByIds(departmentStr)
  4045. if err != nil {
  4046. br.Msg = "获取失败"
  4047. br.ErrMsg = "获取部门失败,Err:" + err.Error()
  4048. return
  4049. }
  4050. for _, department := range departmentList {
  4051. fmt.Println(department)
  4052. departmentGroupSellerList := make([]company.DepartmentGroupSellers, 0)
  4053. item := company.DepartmentGroupSellers{
  4054. AdminId: fmt.Sprint("department_", department.DepartmentId),
  4055. //AdminName string `description:"系统用户名称"`
  4056. RealName: department.DepartmentName,
  4057. ChildrenList: departmentGroupSellerList,
  4058. }
  4059. groupList, err := system.GetSysGroupByDepartmentId(department.DepartmentId)
  4060. if err != nil {
  4061. br.Msg = "获取失败"
  4062. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  4063. return
  4064. }
  4065. for _, group := range groupList {
  4066. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  4067. groupItem := company.DepartmentGroupSellers{
  4068. AdminId: fmt.Sprint("group_", group.DepartmentId),
  4069. //AdminName string `description:"系统用户名称"`
  4070. RealName: group.GroupName,
  4071. ChildrenList: groupSellerList,
  4072. }
  4073. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  4074. if err != nil {
  4075. br.Msg = "获取小组失败"
  4076. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  4077. return
  4078. }
  4079. for _, team := range teamList {
  4080. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  4081. teamItem := company.DepartmentGroupSellers{
  4082. AdminId: fmt.Sprint("team_", team.GroupId),
  4083. //AdminName string `description:"系统用户名称"`
  4084. RealName: team.GroupName,
  4085. ChildrenList: teamSellerList,
  4086. }
  4087. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  4088. if err != nil {
  4089. br.Msg = "获取销售失败"
  4090. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  4091. return
  4092. }
  4093. for _, seller := range sellerList {
  4094. sellerItem := company.DepartmentGroupSellers{
  4095. AdminId: fmt.Sprint(seller.AdminId),
  4096. //AdminName string `description:"系统用户名称"`
  4097. RealName: seller.RealName,
  4098. Authority: seller.Authority,
  4099. RoleTypeCode: seller.RoleTypeCode,
  4100. }
  4101. //fmt.Println("seller.RealName:", seller.RealName)
  4102. teamSellerList = append(teamSellerList, sellerItem)
  4103. }
  4104. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  4105. teamItem.ChildrenList = teamSellerList
  4106. if len(teamSellerList) > 0 {
  4107. groupSellerList = append(groupSellerList, teamItem)
  4108. }
  4109. }
  4110. //分组为0的销售(直属分组)
  4111. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  4112. if err != nil {
  4113. br.Msg = "获取销售失败"
  4114. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  4115. return
  4116. }
  4117. if len(groupTeamSellerList) > 0 {
  4118. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  4119. for _, seller := range groupTeamSellerList {
  4120. sellerItem := company.DepartmentGroupSellers{
  4121. AdminId: fmt.Sprint(seller.AdminId),
  4122. //AdminName string `description:"系统用户名称"`
  4123. RealName: seller.RealName,
  4124. Authority: seller.Authority,
  4125. RoleTypeCode: seller.RoleTypeCode,
  4126. }
  4127. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  4128. }
  4129. //排个序
  4130. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  4131. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  4132. }
  4133. //groupItem.ChildrenList = groupSellerList
  4134. //if len(groupSellerList) > 0 {
  4135. // list = append(list, item)
  4136. //}
  4137. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  4138. //if err != nil {
  4139. // br.Msg = "获取销售失败"
  4140. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  4141. // return
  4142. //}
  4143. //for _, seller := range sellerList {
  4144. // sellerItem := company.DepartmentGroupSellers{
  4145. // AdminId: fmt.Sprint(seller.AdminId),
  4146. // //AdminName string `description:"系统用户名称"`
  4147. // RealName: seller.RealName,
  4148. // Authority: seller.Authority,
  4149. // RoleTypeCode: seller.RoleTypeCode,
  4150. // }
  4151. // groupSellerList = append(groupSellerList, sellerItem)
  4152. //}
  4153. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  4154. groupItem.ChildrenList = groupSellerList
  4155. if len(groupSellerList) > 0 {
  4156. departmentGroupSellerList = append(departmentGroupSellerList, groupItem)
  4157. }
  4158. }
  4159. //分组为0的销售(直属部门)
  4160. departmentSellerList, err := system.GetDepartmentGroupSysUserList(department.DepartmentId, 0, roleCodeTypeStr)
  4161. if err != nil {
  4162. br.Msg = "获取销售失败"
  4163. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  4164. return
  4165. }
  4166. if len(departmentSellerList) > 0 {
  4167. tmpDepartmentGroupSellerList := make([]company.DepartmentGroupSellers, 0)
  4168. for _, seller := range departmentSellerList {
  4169. sellerItem := company.DepartmentGroupSellers{
  4170. AdminId: fmt.Sprint(seller.AdminId),
  4171. //AdminName string `description:"系统用户名称"`
  4172. RealName: seller.RealName,
  4173. Authority: seller.Authority,
  4174. RoleTypeCode: seller.RoleTypeCode,
  4175. }
  4176. tmpDepartmentGroupSellerList = append(tmpDepartmentGroupSellerList, sellerItem)
  4177. }
  4178. //排个序
  4179. tmpDepartmentGroupSellerList = sortDepartmentGroupSellers(tmpDepartmentGroupSellerList)
  4180. departmentGroupSellerList = append(departmentGroupSellerList, tmpDepartmentGroupSellerList...)
  4181. }
  4182. item.ChildrenList = departmentGroupSellerList
  4183. if len(departmentGroupSellerList) > 0 {
  4184. list = append(list, item)
  4185. }
  4186. }
  4187. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN || sysUser.Authority == 1 {
  4188. //部门管理员看小组、销售
  4189. departmentId := sysUser.DepartmentId
  4190. switch sysUser.RoleTypeCode {
  4191. case utils.ROLE_TYPE_CODE_RAI_ADMIN: //权益管理员
  4192. departmentId = 5
  4193. case utils.ROLE_TYPE_CODE_FICC_ADMIN: //ficc管理员
  4194. departmentId = 2
  4195. }
  4196. groupList, err := system.GetSysGroupByDepartmentId(departmentId)
  4197. if err != nil {
  4198. br.Msg = "获取失败"
  4199. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  4200. return
  4201. }
  4202. for _, group := range groupList {
  4203. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  4204. groupItem := company.DepartmentGroupSellers{
  4205. AdminId: fmt.Sprint("group_", group.DepartmentId),
  4206. //AdminName string `description:"系统用户名称"`
  4207. RealName: group.GroupName,
  4208. ChildrenList: groupSellerList,
  4209. }
  4210. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  4211. if err != nil {
  4212. br.Msg = "获取小组失败"
  4213. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  4214. return
  4215. }
  4216. for _, team := range teamList {
  4217. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  4218. teamItem := company.DepartmentGroupSellers{
  4219. AdminId: fmt.Sprint("team_", team.GroupId),
  4220. //AdminName string `description:"系统用户名称"`
  4221. RealName: team.GroupName,
  4222. ChildrenList: teamSellerList,
  4223. }
  4224. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  4225. if err != nil {
  4226. br.Msg = "获取销售失败"
  4227. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  4228. return
  4229. }
  4230. for _, seller := range sellerList {
  4231. sellerItem := company.DepartmentGroupSellers{
  4232. AdminId: fmt.Sprint(seller.AdminId),
  4233. //AdminName string `description:"系统用户名称"`
  4234. RealName: seller.RealName,
  4235. Authority: seller.Authority,
  4236. RoleTypeCode: seller.RoleTypeCode,
  4237. }
  4238. //fmt.Println("seller.RealName:", seller.RealName)
  4239. teamSellerList = append(teamSellerList, sellerItem)
  4240. }
  4241. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  4242. teamItem.ChildrenList = teamSellerList
  4243. if len(teamSellerList) > 0 {
  4244. groupSellerList = append(groupSellerList, teamItem)
  4245. }
  4246. }
  4247. //分组为0的销售(直属分组)
  4248. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  4249. if err != nil {
  4250. br.Msg = "获取销售失败"
  4251. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  4252. return
  4253. }
  4254. if len(groupTeamSellerList) > 0 {
  4255. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  4256. for _, seller := range groupTeamSellerList {
  4257. sellerItem := company.DepartmentGroupSellers{
  4258. AdminId: fmt.Sprint(seller.AdminId),
  4259. //AdminName string `description:"系统用户名称"`
  4260. RealName: seller.RealName,
  4261. Authority: seller.Authority,
  4262. RoleTypeCode: seller.RoleTypeCode,
  4263. }
  4264. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  4265. }
  4266. //排个序
  4267. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  4268. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  4269. }
  4270. //groupItem.ChildrenList = groupSellerList
  4271. //if len(groupSellerList) > 0 {
  4272. // list = append(list, item)
  4273. //}
  4274. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  4275. //if err != nil {
  4276. // br.Msg = "获取销售失败"
  4277. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  4278. // return
  4279. //}
  4280. //for _, seller := range sellerList {
  4281. // sellerItem := company.DepartmentGroupSellers{
  4282. // AdminId: fmt.Sprint(seller.AdminId),
  4283. // //AdminName string `description:"系统用户名称"`
  4284. // RealName: seller.RealName,
  4285. // Authority: seller.Authority,
  4286. // RoleTypeCode: seller.RoleTypeCode,
  4287. // }
  4288. // groupSellerList = append(groupSellerList, sellerItem)
  4289. //}
  4290. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  4291. groupItem.ChildrenList = groupSellerList
  4292. if len(groupSellerList) > 0 {
  4293. list = append(list, groupItem)
  4294. }
  4295. }
  4296. //分组为0的销售(直属部门)
  4297. departmentSellerList, err := system.GetDepartmentGroupSysUserList(departmentId, 0, roleCodeTypeStr)
  4298. if err != nil {
  4299. br.Msg = "获取销售失败"
  4300. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  4301. return
  4302. }
  4303. if len(departmentSellerList) > 0 {
  4304. tmpDepartmentGroupSeller := make([]company.DepartmentGroupSellers, 0)
  4305. for _, seller := range departmentSellerList {
  4306. sellerItem := company.DepartmentGroupSellers{
  4307. AdminId: fmt.Sprint(seller.AdminId),
  4308. //AdminName string `description:"系统用户名称"`
  4309. RealName: seller.RealName,
  4310. Authority: seller.Authority,
  4311. RoleTypeCode: seller.RoleTypeCode,
  4312. }
  4313. tmpDepartmentGroupSeller = append(tmpDepartmentGroupSeller, sellerItem)
  4314. }
  4315. tmpDepartmentGroupSeller = sortDepartmentGroupSellers(tmpDepartmentGroupSeller)
  4316. list = append(list, tmpDepartmentGroupSeller...)
  4317. }
  4318. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP || (sysUser.Authority == 2 && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_FICC_GROUP) {
  4319. // 权益组长看小组
  4320. if status == 0 {
  4321. sellerList, err := system.GetTeamSysUserList(sysUser.GroupId, enabled)
  4322. if err != nil {
  4323. br.Msg = "获取销售失败"
  4324. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  4325. return
  4326. }
  4327. for _, seller := range sellerList {
  4328. sellerItem := company.DepartmentGroupSellers{
  4329. AdminId: fmt.Sprint(seller.AdminId),
  4330. //AdminName string `description:"系统用户名称"`
  4331. RealName: seller.RealName,
  4332. Authority: seller.Authority,
  4333. RoleTypeCode: seller.RoleTypeCode,
  4334. }
  4335. //fmt.Println("seller.RealName:", seller.RealName)
  4336. list = append(list, sellerItem)
  4337. }
  4338. list = sortDepartmentGroupSellers(list)
  4339. //正常来说没有所有人都应该在某个小组下,要不就是小组名为 无 的小组
  4340. //分组为0的销售(直属分组)
  4341. //groupTeamSellerList, err := system.GetGrooupsysUserList(sysUser.GroupId, 0, roleCodeTypeStr)
  4342. //if err != nil {
  4343. // br.Msg = "获取销售失败"
  4344. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  4345. // return
  4346. //}
  4347. //if len(groupTeamSellerList) > 0 {
  4348. // tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  4349. // for _, seller := range groupTeamSellerList {
  4350. // sellerItem := company.DepartmentGroupSellers{
  4351. // AdminId: fmt.Sprint(seller.AdminId),
  4352. // //AdminName string `description:"系统用户名称"`
  4353. // RealName: seller.RealName,
  4354. // Authority: seller.Authority,
  4355. // RoleTypeCode: seller.RoleTypeCode,
  4356. // }
  4357. // tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  4358. // }
  4359. // //排个序
  4360. // tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  4361. // list = append(list, tmpDepartmentGroupSellersList...)
  4362. //}
  4363. //sellerList, err := system.GetDepartmentGroupSysUserList(sysUser.DepartmentId, sysUser.GroupId, roleCodeTypeStr)
  4364. //if err != nil {
  4365. // br.Msg = "获取销售失败"
  4366. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  4367. // return
  4368. //}
  4369. //for _, seller := range sellerList {
  4370. // sellerItem := company.DepartmentGroupSellers{
  4371. // AdminId: fmt.Sprint(seller.AdminId),
  4372. // //AdminName string `description:"系统用户名称"`
  4373. // RealName: seller.RealName,
  4374. // Authority: seller.Authority,
  4375. // RoleTypeCode: seller.RoleTypeCode,
  4376. // }
  4377. // list = append(list, sellerItem)
  4378. // list = sortDepartmentGroupSellers(list)
  4379. //}
  4380. } else {
  4381. departmentId := 5
  4382. groupList, err := system.GetSysGroupByDepartmentId(departmentId)
  4383. if err != nil {
  4384. br.Msg = "获取失败"
  4385. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  4386. return
  4387. }
  4388. for _, group := range groupList {
  4389. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  4390. groupItem := company.DepartmentGroupSellers{
  4391. AdminId: fmt.Sprint("group_", group.DepartmentId),
  4392. //AdminName string `description:"系统用户名称"`
  4393. RealName: group.GroupName,
  4394. ChildrenList: groupSellerList,
  4395. }
  4396. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  4397. if err != nil {
  4398. br.Msg = "获取小组失败"
  4399. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  4400. return
  4401. }
  4402. for _, team := range teamList {
  4403. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  4404. teamItem := company.DepartmentGroupSellers{
  4405. AdminId: fmt.Sprint("team_", team.GroupId),
  4406. //AdminName string `description:"系统用户名称"`
  4407. RealName: team.GroupName,
  4408. ChildrenList: teamSellerList,
  4409. }
  4410. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  4411. if err != nil {
  4412. br.Msg = "获取销售失败"
  4413. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  4414. return
  4415. }
  4416. for _, seller := range sellerList {
  4417. sellerItem := company.DepartmentGroupSellers{
  4418. AdminId: fmt.Sprint(seller.AdminId),
  4419. //AdminName string `description:"系统用户名称"`
  4420. RealName: seller.RealName,
  4421. Authority: seller.Authority,
  4422. RoleTypeCode: seller.RoleTypeCode,
  4423. }
  4424. //fmt.Println("seller.RealName:", seller.RealName)
  4425. teamSellerList = append(teamSellerList, sellerItem)
  4426. }
  4427. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  4428. teamItem.ChildrenList = teamSellerList
  4429. if len(teamSellerList) > 0 {
  4430. groupSellerList = append(groupSellerList, teamItem)
  4431. }
  4432. }
  4433. //分组为0的销售(直属分组)
  4434. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  4435. if err != nil {
  4436. br.Msg = "获取销售失败"
  4437. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  4438. return
  4439. }
  4440. if len(groupTeamSellerList) > 0 {
  4441. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  4442. for _, seller := range groupTeamSellerList {
  4443. sellerItem := company.DepartmentGroupSellers{
  4444. AdminId: fmt.Sprint(seller.AdminId),
  4445. //AdminName string `description:"系统用户名称"`
  4446. RealName: seller.RealName,
  4447. Authority: seller.Authority,
  4448. RoleTypeCode: seller.RoleTypeCode,
  4449. }
  4450. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  4451. }
  4452. //排个序
  4453. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  4454. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  4455. }
  4456. //groupItem.ChildrenList = groupSellerList
  4457. //if len(groupSellerList) > 0 {
  4458. // list = append(list, item)
  4459. //}
  4460. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  4461. //if err != nil {
  4462. // br.Msg = "获取销售失败"
  4463. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  4464. // return
  4465. //}
  4466. //for _, seller := range sellerList {
  4467. // sellerItem := company.DepartmentGroupSellers{
  4468. // AdminId: fmt.Sprint(seller.AdminId),
  4469. // //AdminName string `description:"系统用户名称"`
  4470. // RealName: seller.RealName,
  4471. // Authority: seller.Authority,
  4472. // RoleTypeCode: seller.RoleTypeCode,
  4473. // }
  4474. // groupSellerList = append(groupSellerList, sellerItem)
  4475. //}
  4476. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  4477. groupItem.ChildrenList = groupSellerList
  4478. if len(groupSellerList) > 0 {
  4479. list = append(list, groupItem)
  4480. }
  4481. }
  4482. //分组为0的销售(直属部门)
  4483. departmentSellerList, err := system.GetDepartmentGroupSysUserList(departmentId, 0, roleCodeTypeStr)
  4484. if err != nil {
  4485. br.Msg = "获取销售失败"
  4486. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  4487. return
  4488. }
  4489. if len(departmentSellerList) > 0 {
  4490. tmpDepartmentGroupSeller := make([]company.DepartmentGroupSellers, 0)
  4491. for _, seller := range departmentSellerList {
  4492. sellerItem := company.DepartmentGroupSellers{
  4493. AdminId: fmt.Sprint(seller.AdminId),
  4494. //AdminName string `description:"系统用户名称"`
  4495. RealName: seller.RealName,
  4496. Authority: seller.Authority,
  4497. RoleTypeCode: seller.RoleTypeCode,
  4498. }
  4499. tmpDepartmentGroupSeller = append(tmpDepartmentGroupSeller, sellerItem)
  4500. }
  4501. tmpDepartmentGroupSeller = sortDepartmentGroupSellers(tmpDepartmentGroupSeller)
  4502. list = append(list, tmpDepartmentGroupSeller...)
  4503. }
  4504. }
  4505. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || sysUser.Authority == 2 {
  4506. // 销售主管看小组
  4507. if status == 0 {
  4508. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  4509. if err != nil {
  4510. br.Msg = "获取失败"
  4511. br.ErrMsg = "查询父级id异常" + err.Error()
  4512. return
  4513. }
  4514. var realGroupId int
  4515. if pid != nil && *pid > 0 {
  4516. //主管角色放在了三级分组下
  4517. realGroupId = *pid
  4518. } else {
  4519. //主管角色放在了二级分组下
  4520. realGroupId = sysUser.GroupId
  4521. }
  4522. groupList, err := system.GetSysGroupByGroupId(realGroupId)
  4523. if err != nil {
  4524. br.Msg = "获取失败"
  4525. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  4526. return
  4527. }
  4528. for _, group := range groupList {
  4529. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  4530. //groupItem := company.DepartmentGroupSellers{
  4531. // AdminId: fmt.Sprint("group_", group.DepartmentId),
  4532. // //AdminName string `description:"系统用户名称"`
  4533. // RealName: group.GroupName,
  4534. // ChildrenList: groupSellerList,
  4535. //}
  4536. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  4537. if err != nil {
  4538. br.Msg = "获取小组失败"
  4539. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  4540. return
  4541. }
  4542. for _, team := range teamList {
  4543. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  4544. teamItem := company.DepartmentGroupSellers{
  4545. AdminId: fmt.Sprint("team_", team.GroupId),
  4546. //AdminName string `description:"系统用户名称"`
  4547. RealName: team.GroupName,
  4548. ChildrenList: teamSellerList,
  4549. }
  4550. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  4551. if err != nil {
  4552. br.Msg = "获取销售失败"
  4553. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  4554. return
  4555. }
  4556. for _, seller := range sellerList {
  4557. sellerItem := company.DepartmentGroupSellers{
  4558. AdminId: fmt.Sprint(seller.AdminId),
  4559. //AdminName string `description:"系统用户名称"`
  4560. RealName: seller.RealName,
  4561. Authority: seller.Authority,
  4562. RoleTypeCode: seller.RoleTypeCode,
  4563. }
  4564. //fmt.Println("seller.RealName:", seller.RealName)
  4565. teamSellerList = append(teamSellerList, sellerItem)
  4566. }
  4567. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  4568. teamItem.ChildrenList = teamSellerList
  4569. if len(teamSellerList) > 0 {
  4570. groupSellerList = append(groupSellerList, teamItem)
  4571. }
  4572. }
  4573. //分组为0的销售(直属分组)
  4574. groupTeamSellerList, err := system.GetGrooupsysUserList(realGroupId, roleCodeTypeStr, enabled)
  4575. if err != nil {
  4576. br.Msg = "获取销售失败"
  4577. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  4578. return
  4579. }
  4580. if len(groupTeamSellerList) > 0 {
  4581. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  4582. for _, seller := range groupTeamSellerList {
  4583. sellerItem := company.DepartmentGroupSellers{
  4584. AdminId: fmt.Sprint(seller.AdminId),
  4585. //AdminName string `description:"系统用户名称"`
  4586. RealName: seller.RealName,
  4587. Authority: seller.Authority,
  4588. RoleTypeCode: seller.RoleTypeCode,
  4589. }
  4590. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  4591. }
  4592. //排个序
  4593. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  4594. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  4595. }
  4596. list = groupSellerList
  4597. //groupItem.ChildrenList = groupSellerList
  4598. //if len(groupSellerList) > 0 {
  4599. // list = append(list, item)
  4600. //}
  4601. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  4602. //if err != nil {
  4603. // br.Msg = "获取销售失败"
  4604. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  4605. // return
  4606. //}
  4607. //for _, seller := range sellerList {
  4608. // sellerItem := company.DepartmentGroupSellers{
  4609. // AdminId: fmt.Sprint(seller.AdminId),
  4610. // //AdminName string `description:"系统用户名称"`
  4611. // RealName: seller.RealName,
  4612. // Authority: seller.Authority,
  4613. // RoleTypeCode: seller.RoleTypeCode,
  4614. // }
  4615. // groupSellerList = append(groupSellerList, sellerItem)
  4616. //}
  4617. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  4618. //groupItem.ChildrenList = groupSellerList
  4619. //if len(groupSellerList) > 0 {
  4620. // list = append(list, groupItem)
  4621. //}
  4622. }
  4623. //分组为0的销售(直属二级分组)
  4624. //departmentSellerList, err := system.GetDepartmentGroupSysUserList(2, realGroupId, roleCodeTypeStr)
  4625. //if err != nil {
  4626. // br.Msg = "获取销售失败"
  4627. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  4628. // return
  4629. //}
  4630. //if len(departmentSellerList) > 0 {
  4631. // tmpDepartmentGroupSeller := make([]company.DepartmentGroupSellers, 0)
  4632. // for _, seller := range departmentSellerList {
  4633. // sellerItem := company.DepartmentGroupSellers{
  4634. // AdminId: fmt.Sprint(seller.AdminId),
  4635. // //AdminName string `description:"系统用户名称"`
  4636. // RealName: seller.RealName,
  4637. // Authority: seller.Authority,
  4638. // RoleTypeCode: seller.RoleTypeCode,
  4639. // }
  4640. // tmpDepartmentGroupSeller = append(tmpDepartmentGroupSeller, sellerItem)
  4641. // }
  4642. // tmpDepartmentGroupSeller = sortDepartmentGroupSellers(tmpDepartmentGroupSeller)
  4643. // list = append(list, tmpDepartmentGroupSeller...)
  4644. //}
  4645. //pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  4646. //if err != nil {
  4647. // br.Msg = "获取失败"
  4648. // br.ErrMsg = "查询父级id异常" + err.Error()
  4649. // return
  4650. //}
  4651. //if pid != nil && *pid > 0 {
  4652. // //主管角色放在了三级分组下
  4653. // //
  4654. //
  4655. //
  4656. //} else {
  4657. // //主管角色放在了二级分组下
  4658. //
  4659. //}
  4660. //ids, err := company.GetGroupIdsByParentId(*pid)
  4661. //if err != nil {
  4662. // br.Msg = "获取失败"
  4663. // br.ErrMsg = "查询父级id异常" + err.Error()
  4664. // return
  4665. //}
  4666. //var idSlice []string
  4667. //var sid string
  4668. //for _, id := range ids {
  4669. // idSlice = append(idSlice, *id)
  4670. //}
  4671. //sid = strings.Join(idSlice, ",")
  4672. //sellerList, err := system.GetTeamSysUserListByIds(sid)
  4673. //if err != nil {
  4674. // br.Msg = "获取销售失败"
  4675. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  4676. // return
  4677. //}
  4678. //for _, seller := range sellerList {
  4679. // sellerItem := company.DepartmentGroupSellers{
  4680. // AdminId: fmt.Sprint(seller.AdminId),
  4681. // //AdminName string `description:"系统用户名称"`
  4682. // RealName: seller.RealName,
  4683. // Authority: seller.Authority,
  4684. // RoleTypeCode: seller.RoleTypeCode,
  4685. // }
  4686. // fmt.Println("seller.RealName:", seller.RealName)
  4687. // list = append(list, sellerItem)
  4688. //}
  4689. //list = sortDepartmentGroupSellers(list)
  4690. //
  4691. ////分组为0的销售(直属分组)
  4692. //groupTeamSellerList, err := system.GetGrooupsysUserList(sysUser.GroupId, roleCodeTypeStr)
  4693. //if err != nil {
  4694. // br.Msg = "获取销售失败"
  4695. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  4696. // return
  4697. //}
  4698. //if len(groupTeamSellerList) > 0 {
  4699. // tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  4700. // for _, seller := range groupTeamSellerList {
  4701. // sellerItem := company.DepartmentGroupSellers{
  4702. // AdminId: fmt.Sprint(seller.AdminId),
  4703. // //AdminName string `description:"系统用户名称"`
  4704. // RealName: seller.RealName,
  4705. // Authority: seller.Authority,
  4706. // RoleTypeCode: seller.RoleTypeCode,
  4707. // }
  4708. // tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  4709. // }
  4710. // //排个序
  4711. // tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  4712. // list = append(list, tmpDepartmentGroupSellersList...)
  4713. //}
  4714. //sellerList, err := system.GetDepartmentGroupSysUserList(sysUser.DepartmentId, sysUser.GroupId, roleCodeTypeStr)
  4715. //if err != nil {
  4716. // br.Msg = "获取销售失败"
  4717. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  4718. // return
  4719. //}
  4720. //for _, seller := range sellerList {
  4721. // sellerItem := company.DepartmentGroupSellers{
  4722. // AdminId: fmt.Sprint(seller.AdminId),
  4723. // //AdminName string `description:"系统用户名称"`
  4724. // RealName: seller.RealName,
  4725. // Authority: seller.Authority,
  4726. // RoleTypeCode: seller.RoleTypeCode,
  4727. // }
  4728. // list = append(list, sellerItem)
  4729. // list = sortDepartmentGroupSellers(list)
  4730. //}
  4731. //正常来说没有所有人都应该在某个小组下,要不就是小组名为 无 的小组
  4732. } else {
  4733. //var departmentStr string
  4734. //if utils.RunMode == "release" {
  4735. // departmentStr = `1,2`
  4736. //} else {
  4737. // departmentStr = `1,2`
  4738. //}
  4739. departmentStr := `1,2`
  4740. departmentList, err := system.GetDepartmentListByIds(departmentStr)
  4741. if err != nil {
  4742. br.Msg = "获取失败"
  4743. br.ErrMsg = "获取部门失败,Err:" + err.Error()
  4744. return
  4745. }
  4746. for _, department := range departmentList {
  4747. departmentGroupSellerList := make([]company.DepartmentGroupSellers, 0)
  4748. item := company.DepartmentGroupSellers{
  4749. AdminId: fmt.Sprint("department_", department.DepartmentId),
  4750. //AdminName string `description:"系统用户名称"`
  4751. RealName: department.DepartmentName,
  4752. ChildrenList: departmentGroupSellerList,
  4753. }
  4754. groupList, err := system.GetSysGroupByDepartmentId(department.DepartmentId)
  4755. if err != nil {
  4756. br.Msg = "获取失败"
  4757. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  4758. return
  4759. }
  4760. for _, group := range groupList {
  4761. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  4762. groupItem := company.DepartmentGroupSellers{
  4763. AdminId: fmt.Sprint("group_", group.DepartmentId),
  4764. //AdminName string `description:"系统用户名称"`
  4765. RealName: group.GroupName,
  4766. ChildrenList: groupSellerList,
  4767. }
  4768. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  4769. if err != nil {
  4770. br.Msg = "获取小组失败"
  4771. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  4772. return
  4773. }
  4774. for _, team := range teamList {
  4775. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  4776. teamItem := company.DepartmentGroupSellers{
  4777. AdminId: fmt.Sprint("team_", team.GroupId),
  4778. //AdminName string `description:"系统用户名称"`
  4779. RealName: team.GroupName,
  4780. ChildrenList: teamSellerList,
  4781. }
  4782. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  4783. if err != nil {
  4784. br.Msg = "获取销售失败"
  4785. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  4786. return
  4787. }
  4788. for _, seller := range sellerList {
  4789. sellerItem := company.DepartmentGroupSellers{
  4790. AdminId: fmt.Sprint(seller.AdminId),
  4791. //AdminName string `description:"系统用户名称"`
  4792. RealName: seller.RealName,
  4793. Authority: seller.Authority,
  4794. RoleTypeCode: seller.RoleTypeCode,
  4795. }
  4796. //fmt.Println("seller.RealName:", seller.RealName)
  4797. teamSellerList = append(teamSellerList, sellerItem)
  4798. }
  4799. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  4800. teamItem.ChildrenList = teamSellerList
  4801. if len(teamSellerList) > 0 {
  4802. groupSellerList = append(groupSellerList, teamItem)
  4803. }
  4804. }
  4805. //分组为0的人,不光是销售(直属分组)
  4806. groupTeamSellerList, err := system.GetGroupSysUserList(group.GroupId)
  4807. if err != nil {
  4808. br.Msg = "获取销售失败"
  4809. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  4810. return
  4811. }
  4812. if len(groupTeamSellerList) > 0 {
  4813. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  4814. for _, seller := range groupTeamSellerList {
  4815. sellerItem := company.DepartmentGroupSellers{
  4816. AdminId: fmt.Sprint(seller.AdminId),
  4817. //AdminName string `description:"系统用户名称"`
  4818. RealName: seller.RealName,
  4819. Authority: seller.Authority,
  4820. RoleTypeCode: seller.RoleTypeCode,
  4821. }
  4822. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  4823. }
  4824. //排个序
  4825. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  4826. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  4827. }
  4828. //groupItem.ChildrenList = groupSellerList
  4829. //if len(groupSellerList) > 0 {
  4830. // list = append(list, item)
  4831. //}
  4832. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  4833. //if err != nil {
  4834. // br.Msg = "获取销售失败"
  4835. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  4836. // return
  4837. //}
  4838. //for _, seller := range sellerList {
  4839. // sellerItem := company.DepartmentGroupSellers{
  4840. // AdminId: fmt.Sprint(seller.AdminId),
  4841. // //AdminName string `description:"系统用户名称"`
  4842. // RealName: seller.RealName,
  4843. // Authority: seller.Authority,
  4844. // RoleTypeCode: seller.RoleTypeCode,
  4845. // }
  4846. // groupSellerList = append(groupSellerList, sellerItem)
  4847. //}
  4848. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  4849. groupItem.ChildrenList = groupSellerList
  4850. if len(groupSellerList) > 0 {
  4851. departmentGroupSellerList = append(departmentGroupSellerList, groupItem)
  4852. }
  4853. }
  4854. //分组为0的人,不光是销售(直属部门)
  4855. departmentSellerList, err := system.GetDepartmentGroupSysUserList(department.DepartmentId, 0, "")
  4856. if err != nil {
  4857. br.Msg = "获取销售失败"
  4858. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  4859. return
  4860. }
  4861. if len(departmentSellerList) > 0 {
  4862. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  4863. for _, seller := range departmentSellerList {
  4864. sellerItem := company.DepartmentGroupSellers{
  4865. AdminId: fmt.Sprint(seller.AdminId),
  4866. //AdminName string `description:"系统用户名称"`
  4867. RealName: seller.RealName,
  4868. Authority: seller.Authority,
  4869. RoleTypeCode: seller.RoleTypeCode,
  4870. }
  4871. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  4872. }
  4873. //排个序
  4874. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  4875. departmentGroupSellerList = append(departmentGroupSellerList, tmpDepartmentGroupSellersList...)
  4876. }
  4877. item.ChildrenList = departmentGroupSellerList
  4878. if len(departmentGroupSellerList) > 0 {
  4879. list = append(list, item)
  4880. }
  4881. }
  4882. }
  4883. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER && status == 1 {
  4884. //var departmentStr string
  4885. //if utils.RunMode == "release" {
  4886. // departmentStr = `1,2`
  4887. //} else {
  4888. // departmentStr = `1,2`
  4889. //}
  4890. departmentStr := `1,2`
  4891. departmentList, err := system.GetDepartmentListByIds(departmentStr)
  4892. if err != nil {
  4893. br.Msg = "获取失败"
  4894. br.ErrMsg = "获取部门失败,Err:" + err.Error()
  4895. return
  4896. }
  4897. for _, department := range departmentList {
  4898. departmentGroupSellerList := make([]company.DepartmentGroupSellers, 0)
  4899. item := company.DepartmentGroupSellers{
  4900. AdminId: fmt.Sprint("department_", department.DepartmentId),
  4901. //AdminName string `description:"系统用户名称"`
  4902. RealName: department.DepartmentName,
  4903. ChildrenList: departmentGroupSellerList,
  4904. }
  4905. groupList, err := system.GetSysGroupByDepartmentId(department.DepartmentId)
  4906. if err != nil {
  4907. br.Msg = "获取失败"
  4908. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  4909. return
  4910. }
  4911. for _, group := range groupList {
  4912. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  4913. groupItem := company.DepartmentGroupSellers{
  4914. AdminId: fmt.Sprint("group_", group.DepartmentId),
  4915. //AdminName string `description:"系统用户名称"`
  4916. RealName: group.GroupName,
  4917. ChildrenList: groupSellerList,
  4918. }
  4919. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  4920. if err != nil {
  4921. br.Msg = "获取小组失败"
  4922. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  4923. return
  4924. }
  4925. for _, team := range teamList {
  4926. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  4927. teamItem := company.DepartmentGroupSellers{
  4928. AdminId: fmt.Sprint("team_", team.GroupId),
  4929. //AdminName string `description:"系统用户名称"`
  4930. RealName: team.GroupName,
  4931. ChildrenList: teamSellerList,
  4932. }
  4933. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  4934. if err != nil {
  4935. br.Msg = "获取销售失败"
  4936. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  4937. return
  4938. }
  4939. for _, seller := range sellerList {
  4940. sellerItem := company.DepartmentGroupSellers{
  4941. AdminId: fmt.Sprint(seller.AdminId),
  4942. //AdminName string `description:"系统用户名称"`
  4943. RealName: seller.RealName,
  4944. Authority: seller.Authority,
  4945. RoleTypeCode: seller.RoleTypeCode,
  4946. }
  4947. //fmt.Println("seller.RealName:", seller.RealName)
  4948. teamSellerList = append(teamSellerList, sellerItem)
  4949. }
  4950. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  4951. teamItem.ChildrenList = teamSellerList
  4952. if len(teamSellerList) > 0 {
  4953. groupSellerList = append(groupSellerList, teamItem)
  4954. }
  4955. }
  4956. //分组为0的人,不光是销售(直属分组)
  4957. groupTeamSellerList, err := system.GetGroupSysUserList(group.GroupId)
  4958. if err != nil {
  4959. br.Msg = "获取销售失败"
  4960. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  4961. return
  4962. }
  4963. if len(groupTeamSellerList) > 0 {
  4964. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  4965. for _, seller := range groupTeamSellerList {
  4966. sellerItem := company.DepartmentGroupSellers{
  4967. AdminId: fmt.Sprint(seller.AdminId),
  4968. //AdminName string `description:"系统用户名称"`
  4969. RealName: seller.RealName,
  4970. Authority: seller.Authority,
  4971. RoleTypeCode: seller.RoleTypeCode,
  4972. }
  4973. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  4974. }
  4975. //排个序
  4976. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  4977. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  4978. }
  4979. //groupItem.ChildrenList = groupSellerList
  4980. //if len(groupSellerList) > 0 {
  4981. // list = append(list, item)
  4982. //}
  4983. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  4984. //if err != nil {
  4985. // br.Msg = "获取销售失败"
  4986. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  4987. // return
  4988. //}
  4989. //for _, seller := range sellerList {
  4990. // sellerItem := company.DepartmentGroupSellers{
  4991. // AdminId: fmt.Sprint(seller.AdminId),
  4992. // //AdminName string `description:"系统用户名称"`
  4993. // RealName: seller.RealName,
  4994. // Authority: seller.Authority,
  4995. // RoleTypeCode: seller.RoleTypeCode,
  4996. // }
  4997. // groupSellerList = append(groupSellerList, sellerItem)
  4998. //}
  4999. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  5000. groupItem.ChildrenList = groupSellerList
  5001. if len(groupSellerList) > 0 {
  5002. departmentGroupSellerList = append(departmentGroupSellerList, groupItem)
  5003. }
  5004. }
  5005. //分组为0的人,不光是销售(直属部门)
  5006. departmentSellerList, err := system.GetDepartmentGroupSysUserList(department.DepartmentId, 0, "")
  5007. if err != nil {
  5008. br.Msg = "获取销售失败"
  5009. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  5010. return
  5011. }
  5012. if len(departmentSellerList) > 0 {
  5013. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  5014. for _, seller := range departmentSellerList {
  5015. sellerItem := company.DepartmentGroupSellers{
  5016. AdminId: fmt.Sprint(seller.AdminId),
  5017. //AdminName string `description:"系统用户名称"`
  5018. RealName: seller.RealName,
  5019. Authority: seller.Authority,
  5020. RoleTypeCode: seller.RoleTypeCode,
  5021. }
  5022. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  5023. }
  5024. //排个序
  5025. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  5026. departmentGroupSellerList = append(departmentGroupSellerList, tmpDepartmentGroupSellersList...)
  5027. }
  5028. item.ChildrenList = departmentGroupSellerList
  5029. if len(departmentGroupSellerList) > 0 {
  5030. list = append(list, item)
  5031. }
  5032. }
  5033. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER && status == 1 {
  5034. // 权益销售可以看到权益销售部的所有人
  5035. departmentId := 5
  5036. groupList, err := system.GetSysGroupByDepartmentId(departmentId)
  5037. if err != nil {
  5038. br.Msg = "获取失败"
  5039. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  5040. return
  5041. }
  5042. for _, group := range groupList {
  5043. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  5044. groupItem := company.DepartmentGroupSellers{
  5045. AdminId: fmt.Sprint("group_", group.DepartmentId),
  5046. //AdminName string `description:"系统用户名称"`
  5047. RealName: group.GroupName,
  5048. ChildrenList: groupSellerList,
  5049. }
  5050. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  5051. if err != nil {
  5052. br.Msg = "获取小组失败"
  5053. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  5054. return
  5055. }
  5056. for _, team := range teamList {
  5057. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  5058. teamItem := company.DepartmentGroupSellers{
  5059. AdminId: fmt.Sprint("team_", team.GroupId),
  5060. //AdminName string `description:"系统用户名称"`
  5061. RealName: team.GroupName,
  5062. ChildrenList: teamSellerList,
  5063. }
  5064. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  5065. if err != nil {
  5066. br.Msg = "获取销售失败"
  5067. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  5068. return
  5069. }
  5070. for _, seller := range sellerList {
  5071. sellerItem := company.DepartmentGroupSellers{
  5072. AdminId: fmt.Sprint(seller.AdminId),
  5073. //AdminName string `description:"系统用户名称"`
  5074. RealName: seller.RealName,
  5075. Authority: seller.Authority,
  5076. RoleTypeCode: seller.RoleTypeCode,
  5077. }
  5078. //fmt.Println("seller.RealName:", seller.RealName)
  5079. teamSellerList = append(teamSellerList, sellerItem)
  5080. }
  5081. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  5082. teamItem.ChildrenList = teamSellerList
  5083. if len(teamSellerList) > 0 {
  5084. groupSellerList = append(groupSellerList, teamItem)
  5085. }
  5086. }
  5087. //分组为0的销售(直属分组)
  5088. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  5089. if err != nil {
  5090. br.Msg = "获取销售失败"
  5091. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  5092. return
  5093. }
  5094. if len(groupTeamSellerList) > 0 {
  5095. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  5096. for _, seller := range groupTeamSellerList {
  5097. sellerItem := company.DepartmentGroupSellers{
  5098. AdminId: fmt.Sprint(seller.AdminId),
  5099. //AdminName string `description:"系统用户名称"`
  5100. RealName: seller.RealName,
  5101. Authority: seller.Authority,
  5102. RoleTypeCode: seller.RoleTypeCode,
  5103. }
  5104. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  5105. }
  5106. //排个序
  5107. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  5108. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  5109. }
  5110. //groupItem.ChildrenList = groupSellerList
  5111. //if len(groupSellerList) > 0 {
  5112. // list = append(list, item)
  5113. //}
  5114. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  5115. //if err != nil {
  5116. // br.Msg = "获取销售失败"
  5117. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  5118. // return
  5119. //}
  5120. //for _, seller := range sellerList {
  5121. // sellerItem := company.DepartmentGroupSellers{
  5122. // AdminId: fmt.Sprint(seller.AdminId),
  5123. // //AdminName string `description:"系统用户名称"`
  5124. // RealName: seller.RealName,
  5125. // Authority: seller.Authority,
  5126. // RoleTypeCode: seller.RoleTypeCode,
  5127. // }
  5128. // groupSellerList = append(groupSellerList, sellerItem)
  5129. //}
  5130. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  5131. groupItem.ChildrenList = groupSellerList
  5132. if len(groupSellerList) > 0 {
  5133. list = append(list, groupItem)
  5134. }
  5135. }
  5136. //分组为0的销售(直属部门)
  5137. departmentSellerList, err := system.GetDepartmentGroupSysUserList(departmentId, 0, roleCodeTypeStr)
  5138. if err != nil {
  5139. br.Msg = "获取销售失败"
  5140. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  5141. return
  5142. }
  5143. if len(departmentSellerList) > 0 {
  5144. tmpDepartmentGroupSeller := make([]company.DepartmentGroupSellers, 0)
  5145. for _, seller := range departmentSellerList {
  5146. sellerItem := company.DepartmentGroupSellers{
  5147. AdminId: fmt.Sprint(seller.AdminId),
  5148. //AdminName string `description:"系统用户名称"`
  5149. RealName: seller.RealName,
  5150. Authority: seller.Authority,
  5151. RoleTypeCode: seller.RoleTypeCode,
  5152. }
  5153. tmpDepartmentGroupSeller = append(tmpDepartmentGroupSeller, sellerItem)
  5154. }
  5155. tmpDepartmentGroupSeller = sortDepartmentGroupSellers(tmpDepartmentGroupSeller)
  5156. list = append(list, tmpDepartmentGroupSeller...)
  5157. }
  5158. } else {
  5159. //看自己
  5160. sellerItem := company.DepartmentGroupSellers{
  5161. AdminId: fmt.Sprint(sysUser.AdminId),
  5162. //AdminName string `description:"系统用户名称"`
  5163. RealName: sysUser.RealName,
  5164. }
  5165. list = append(list, sellerItem)
  5166. }
  5167. } else {
  5168. // 权益管理员,查看所有权益的账号
  5169. 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 + `"`
  5170. departmentId := 5
  5171. enabled := 1
  5172. groupList, err := system.GetSysGroupByDepartmentId(departmentId)
  5173. if err != nil {
  5174. br.Msg = "获取失败"
  5175. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  5176. return
  5177. }
  5178. for _, group := range groupList {
  5179. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  5180. groupItem := company.DepartmentGroupSellers{
  5181. AdminId: fmt.Sprint("group_", group.DepartmentId),
  5182. //AdminName string `description:"系统用户名称"`
  5183. RealName: group.GroupName,
  5184. ChildrenList: groupSellerList,
  5185. }
  5186. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  5187. if err != nil {
  5188. br.Msg = "获取小组失败"
  5189. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  5190. return
  5191. }
  5192. for _, team := range teamList {
  5193. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  5194. teamItem := company.DepartmentGroupSellers{
  5195. AdminId: fmt.Sprint("team_", team.GroupId),
  5196. //AdminName string `description:"系统用户名称"`
  5197. RealName: team.GroupName,
  5198. ChildrenList: teamSellerList,
  5199. }
  5200. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  5201. if err != nil {
  5202. br.Msg = "获取销售失败"
  5203. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  5204. return
  5205. }
  5206. for _, seller := range sellerList {
  5207. sellerItem := company.DepartmentGroupSellers{
  5208. AdminId: fmt.Sprint(seller.AdminId),
  5209. //AdminName string `description:"系统用户名称"`
  5210. RealName: seller.RealName,
  5211. Authority: seller.Authority,
  5212. RoleTypeCode: seller.RoleTypeCode,
  5213. }
  5214. //fmt.Println("seller.RealName:", seller.RealName)
  5215. teamSellerList = append(teamSellerList, sellerItem)
  5216. }
  5217. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  5218. teamItem.ChildrenList = teamSellerList
  5219. if len(teamSellerList) > 0 {
  5220. groupSellerList = append(groupSellerList, teamItem)
  5221. }
  5222. }
  5223. //分组为0的销售(直属分组)
  5224. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  5225. if err != nil {
  5226. br.Msg = "获取销售失败"
  5227. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  5228. return
  5229. }
  5230. if len(groupTeamSellerList) > 0 {
  5231. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  5232. for _, seller := range groupTeamSellerList {
  5233. sellerItem := company.DepartmentGroupSellers{
  5234. AdminId: fmt.Sprint(seller.AdminId),
  5235. //AdminName string `description:"系统用户名称"`
  5236. RealName: seller.RealName,
  5237. Authority: seller.Authority,
  5238. RoleTypeCode: seller.RoleTypeCode,
  5239. }
  5240. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  5241. }
  5242. //排个序
  5243. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  5244. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  5245. }
  5246. groupItem.ChildrenList = groupSellerList
  5247. if len(groupSellerList) > 0 {
  5248. resp = append(resp, groupItem)
  5249. }
  5250. }
  5251. //分组为0的销售(直属部门)
  5252. departmentSellerList, err := system.GetDepartmentGroupSysUserList(departmentId, 0, roleCodeTypeStr)
  5253. if err != nil {
  5254. br.Msg = "获取销售失败"
  5255. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  5256. return
  5257. }
  5258. if len(departmentSellerList) > 0 {
  5259. tmpDepartmentGroupSeller := make([]company.DepartmentGroupSellers, 0)
  5260. for _, seller := range departmentSellerList {
  5261. sellerItem := company.DepartmentGroupSellers{
  5262. AdminId: fmt.Sprint(seller.AdminId),
  5263. //AdminName string `description:"系统用户名称"`
  5264. RealName: seller.RealName,
  5265. Authority: seller.Authority,
  5266. RoleTypeCode: seller.RoleTypeCode,
  5267. }
  5268. tmpDepartmentGroupSeller = append(tmpDepartmentGroupSeller, sellerItem)
  5269. }
  5270. tmpDepartmentGroupSeller = sortDepartmentGroupSellers(tmpDepartmentGroupSeller)
  5271. resp = append(resp, tmpDepartmentGroupSeller...)
  5272. }
  5273. list = resp
  5274. }
  5275. br.Ret = 200
  5276. br.Success = true
  5277. br.Msg = "获取成功"
  5278. br.Data = company.DepartmentGroupSellersResp{
  5279. List: list,
  5280. }
  5281. }
  5282. // RaiServeSellerList
  5283. // @Title 获取权益服务组销售列表
  5284. // @Description 获取权益服务组销售列表 接口
  5285. // @Success 200 {object} company.DepartmentGroupSellersResp
  5286. // @router /seller/rai_serve/list [get]
  5287. func (this *CompanySellerController) RaiServeSellerList() {
  5288. br := new(models.BaseResponse).Init()
  5289. defer func() {
  5290. this.Data["json"] = br
  5291. this.ServeJSON()
  5292. }()
  5293. sysUser := this.SysUser
  5294. if sysUser == nil {
  5295. br.Msg = "请登录"
  5296. br.ErrMsg = "请登录,SysUser Is Empty"
  5297. br.Ret = 408
  5298. return
  5299. }
  5300. resp := make([]company.DepartmentGroupSellers, 0)
  5301. groupIds := []int{}
  5302. if utils.RunMode == "release" {
  5303. groupIds = []int{68, 72}
  5304. } else {
  5305. groupIds = []int{132, 134}
  5306. }
  5307. groupNameList, err := system.GetSysGroupByGroupIds(groupIds)
  5308. if err != nil {
  5309. br.Msg = "获取销售失败"
  5310. br.ErrMsg = "获取组别信息失败,Err:" + err.Error()
  5311. return
  5312. }
  5313. for _, group := range groupNameList {
  5314. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  5315. groupItem := company.DepartmentGroupSellers{
  5316. AdminId: fmt.Sprint("group_", group.DepartmentId),
  5317. //AdminName string `description:"系统用户名称"`
  5318. RealName: group.GroupName,
  5319. ChildrenList: groupSellerList,
  5320. }
  5321. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  5322. sellerList, err := system.GetAdminByGroupId(group.GroupId)
  5323. if err != nil && err.Error() != utils.ErrNoRow() {
  5324. br.Msg = "获取销售失败"
  5325. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  5326. return
  5327. }
  5328. for _, seller := range sellerList {
  5329. sellerItem := company.DepartmentGroupSellers{
  5330. AdminId: fmt.Sprint(seller.AdminId),
  5331. //AdminName string `description:"系统用户名称"`
  5332. RealName: seller.RealName,
  5333. Authority: seller.Authority,
  5334. RoleTypeCode: seller.RoleTypeCode,
  5335. }
  5336. teamSellerList = append(teamSellerList, sellerItem)
  5337. }
  5338. groupItem.ChildrenList = teamSellerList
  5339. if len(teamSellerList) > 0 {
  5340. groupSellerList = append(groupSellerList, groupItem)
  5341. }
  5342. if len(groupSellerList) > 0 {
  5343. resp = append(resp, groupItem)
  5344. }
  5345. }
  5346. br.Ret = 200
  5347. br.Success = true
  5348. br.Msg = "获取成功"
  5349. br.Data = resp
  5350. }