company_seller.go 277 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488
  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. }
  5351. // CheckListV2
  5352. // @Title 获取组长/组员下销售(根据部门、分组)-开票到款统计用 有特殊处理
  5353. // @Description 获取组长/组员下销售(根据部门、分组)接口
  5354. // @Param AllSeller query bool true "是否获取部门所有的销售信息"
  5355. // @Param Status query int true "客户状态 1:流失 0:非流失"
  5356. // @Param AllEnabled query bool true "是否获取包含禁用的用户"
  5357. // @Success 200 {object} company.DepartmentGroupSellersResp
  5358. // @router /seller/check/invoice_payment/list [get]
  5359. func (this *CompanySellerController) InvoicePaymentCheckList() {
  5360. br := new(models.BaseResponse).Init()
  5361. defer func() {
  5362. this.Data["json"] = br
  5363. this.ServeJSON()
  5364. }()
  5365. sysUser := this.SysUser
  5366. if sysUser == nil {
  5367. br.Msg = "请登录"
  5368. br.ErrMsg = "请登录,SysUser Is Empty"
  5369. br.Ret = 408
  5370. return
  5371. }
  5372. roleCodeTypeStr := ``
  5373. productId := services.GetProductId(sysUser.RoleTypeCode)
  5374. switch productId {
  5375. case 1:
  5376. roleCodeTypeStr = `"` + utils.ROLE_TYPE_CODE_FICC_SELLER + `","` + utils.ROLE_TYPE_CODE_FICC_GROUP + `","` + utils.ROLE_TYPE_CODE_FICC_TEAM + `"`
  5377. case 2:
  5378. roleCodeTypeStr = `"` + utils.ROLE_TYPE_CODE_RAI_SELLER + `","` + utils.ROLE_TYPE_CODE_RAI_GROUP + `"`
  5379. }
  5380. // ficc管理员,不要只查销售
  5381. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  5382. roleCodeTypeStr = ``
  5383. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  5384. // 权益管理员,查看所有权益的账号
  5385. 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 + `"`
  5386. }
  5387. getAllSeller, _ := this.GetBool("AllSeller", false)
  5388. getAllUser, _ := this.GetBool("AllUser", false)
  5389. status, _ := this.GetInt("Status", 0)
  5390. //getAllEnabled, _ := this.GetBool("AllEnabled", false)
  5391. enabled := -1 //默认只获取正常状态的用户
  5392. //if getAllEnabled { //获取所有状态的用户
  5393. // enabled = -1
  5394. //}
  5395. list := make([]company.DepartmentGroupSellers, 0)
  5396. if getAllUser {
  5397. departmentList, err := system.GetDepartmentList()
  5398. if err != nil {
  5399. br.Msg = "获取失败"
  5400. br.ErrMsg = "获取部门失败,Err:" + err.Error()
  5401. return
  5402. }
  5403. for _, department := range departmentList {
  5404. departmentGroupSellerList := make([]company.DepartmentGroupSellers, 0)
  5405. item := company.DepartmentGroupSellers{
  5406. AdminId: fmt.Sprint("department_", department.DepartmentId),
  5407. //AdminName string `description:"系统用户名称"`
  5408. RealName: department.DepartmentName,
  5409. ChildrenList: departmentGroupSellerList,
  5410. }
  5411. groupList, err := system.GetSysGroupByDepartmentId(department.DepartmentId)
  5412. if err != nil {
  5413. br.Msg = "获取失败"
  5414. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  5415. return
  5416. }
  5417. for _, group := range groupList {
  5418. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  5419. groupItem := company.DepartmentGroupSellers{
  5420. AdminId: fmt.Sprint("group_", group.DepartmentId),
  5421. //AdminName string `description:"系统用户名称"`
  5422. RealName: group.GroupName,
  5423. ChildrenList: groupSellerList,
  5424. }
  5425. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  5426. if err != nil {
  5427. br.Msg = "获取小组失败"
  5428. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  5429. return
  5430. }
  5431. for _, team := range teamList {
  5432. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  5433. teamItem := company.DepartmentGroupSellers{
  5434. AdminId: fmt.Sprint("team_", team.GroupId),
  5435. //AdminName string `description:"系统用户名称"`
  5436. RealName: team.GroupName,
  5437. ChildrenList: teamSellerList,
  5438. }
  5439. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  5440. if err != nil {
  5441. br.Msg = "获取销售失败"
  5442. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  5443. return
  5444. }
  5445. for _, seller := range sellerList {
  5446. sellerItem := company.DepartmentGroupSellers{
  5447. AdminId: fmt.Sprint(seller.AdminId),
  5448. //AdminName string `description:"系统用户名称"`
  5449. RealName: seller.RealName,
  5450. Authority: seller.Authority,
  5451. RoleTypeCode: seller.RoleTypeCode,
  5452. }
  5453. //fmt.Println("seller.RealName:", seller.RealName)
  5454. teamSellerList = append(teamSellerList, sellerItem)
  5455. }
  5456. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  5457. teamItem.ChildrenList = teamSellerList
  5458. if len(teamSellerList) > 0 {
  5459. groupSellerList = append(groupSellerList, teamItem)
  5460. }
  5461. }
  5462. //分组为0的销售(直属分组)
  5463. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  5464. if err != nil {
  5465. br.Msg = "获取销售失败"
  5466. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  5467. return
  5468. }
  5469. if len(groupTeamSellerList) > 0 {
  5470. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  5471. for _, seller := range groupTeamSellerList {
  5472. sellerItem := company.DepartmentGroupSellers{
  5473. AdminId: fmt.Sprint(seller.AdminId),
  5474. //AdminName string `description:"系统用户名称"`
  5475. RealName: seller.RealName,
  5476. Authority: seller.Authority,
  5477. RoleTypeCode: seller.RoleTypeCode,
  5478. }
  5479. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  5480. }
  5481. //排个序
  5482. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  5483. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  5484. }
  5485. //groupItem.ChildrenList = groupSellerList
  5486. //if len(groupSellerList) > 0 {
  5487. // list = append(list, item)
  5488. //}
  5489. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  5490. //if err != nil {
  5491. // br.Msg = "获取销售失败"
  5492. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  5493. // return
  5494. //}
  5495. //for _, seller := range sellerList {
  5496. // sellerItem := company.DepartmentGroupSellers{
  5497. // AdminId: fmt.Sprint(seller.AdminId),
  5498. // //AdminName string `description:"系统用户名称"`
  5499. // RealName: seller.RealName,
  5500. // Authority: seller.Authority,
  5501. // RoleTypeCode: seller.RoleTypeCode,
  5502. // }
  5503. // groupSellerList = append(groupSellerList, sellerItem)
  5504. //}
  5505. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  5506. groupItem.ChildrenList = groupSellerList
  5507. if len(groupSellerList) > 0 {
  5508. departmentGroupSellerList = append(departmentGroupSellerList, groupItem)
  5509. }
  5510. }
  5511. //分组为0的销售(直属部门)
  5512. departmentSellerList, err := system.GetDepartmentGroupSysUserList(department.DepartmentId, 0, roleCodeTypeStr)
  5513. if err != nil {
  5514. br.Msg = "获取销售失败"
  5515. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  5516. return
  5517. }
  5518. if len(departmentSellerList) > 0 {
  5519. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  5520. for _, seller := range departmentSellerList {
  5521. sellerItem := company.DepartmentGroupSellers{
  5522. AdminId: fmt.Sprint(seller.AdminId),
  5523. //AdminName string `description:"系统用户名称"`
  5524. RealName: seller.RealName,
  5525. Authority: seller.Authority,
  5526. RoleTypeCode: seller.RoleTypeCode,
  5527. }
  5528. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  5529. }
  5530. //排个序
  5531. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  5532. departmentGroupSellerList = append(departmentGroupSellerList, tmpDepartmentGroupSellersList...)
  5533. }
  5534. item.ChildrenList = departmentGroupSellerList
  5535. if len(departmentGroupSellerList) > 0 {
  5536. list = append(list, item)
  5537. }
  5538. }
  5539. br.Ret = 200
  5540. br.Success = true
  5541. br.Msg = "获取成功"
  5542. br.Data = company.DepartmentGroupSellersResp{
  5543. List: list,
  5544. }
  5545. return
  5546. }
  5547. if getAllSeller == false {
  5548. //超管看部门、小组、销售
  5549. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  5550. departmentList, err := system.GetDepartmentList()
  5551. if err != nil {
  5552. br.Msg = "获取失败"
  5553. br.ErrMsg = "获取部门失败,Err:" + err.Error()
  5554. return
  5555. }
  5556. for _, department := range departmentList {
  5557. departmentGroupSellerList := make([]company.DepartmentGroupSellers, 0)
  5558. item := company.DepartmentGroupSellers{
  5559. AdminId: fmt.Sprint("department_", department.DepartmentId),
  5560. //AdminName string `description:"系统用户名称"`
  5561. RealName: department.DepartmentName,
  5562. ChildrenList: departmentGroupSellerList,
  5563. }
  5564. groupList, err := system.GetSysGroupByDepartmentId(department.DepartmentId)
  5565. if err != nil {
  5566. br.Msg = "获取失败"
  5567. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  5568. return
  5569. }
  5570. for _, group := range groupList {
  5571. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  5572. groupItem := company.DepartmentGroupSellers{
  5573. AdminId: fmt.Sprint("group_", group.DepartmentId),
  5574. //AdminName string `description:"系统用户名称"`
  5575. RealName: group.GroupName,
  5576. ChildrenList: groupSellerList,
  5577. }
  5578. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  5579. if err != nil {
  5580. br.Msg = "获取小组失败"
  5581. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  5582. return
  5583. }
  5584. for _, team := range teamList {
  5585. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  5586. teamItem := company.DepartmentGroupSellers{
  5587. AdminId: fmt.Sprint("team_", team.GroupId),
  5588. //AdminName string `description:"系统用户名称"`
  5589. RealName: team.GroupName,
  5590. ChildrenList: teamSellerList,
  5591. }
  5592. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  5593. if err != nil {
  5594. br.Msg = "获取销售失败"
  5595. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  5596. return
  5597. }
  5598. for _, seller := range sellerList {
  5599. sellerItem := company.DepartmentGroupSellers{
  5600. AdminId: fmt.Sprint(seller.AdminId),
  5601. //AdminName string `description:"系统用户名称"`
  5602. RealName: seller.RealName,
  5603. Authority: seller.Authority,
  5604. RoleTypeCode: seller.RoleTypeCode,
  5605. }
  5606. //fmt.Println("seller.RealName:", seller.RealName)
  5607. teamSellerList = append(teamSellerList, sellerItem)
  5608. }
  5609. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  5610. teamItem.ChildrenList = teamSellerList
  5611. if len(teamSellerList) > 0 {
  5612. groupSellerList = append(groupSellerList, teamItem)
  5613. }
  5614. }
  5615. //分组为0的销售(直属分组)
  5616. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  5617. if err != nil {
  5618. br.Msg = "获取销售失败"
  5619. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  5620. return
  5621. }
  5622. if len(groupTeamSellerList) > 0 {
  5623. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  5624. for _, seller := range groupTeamSellerList {
  5625. sellerItem := company.DepartmentGroupSellers{
  5626. AdminId: fmt.Sprint(seller.AdminId),
  5627. //AdminName string `description:"系统用户名称"`
  5628. RealName: seller.RealName,
  5629. Authority: seller.Authority,
  5630. RoleTypeCode: seller.RoleTypeCode,
  5631. }
  5632. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  5633. }
  5634. //排个序
  5635. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  5636. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  5637. }
  5638. //groupItem.ChildrenList = groupSellerList
  5639. //if len(groupSellerList) > 0 {
  5640. // list = append(list, item)
  5641. //}
  5642. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  5643. //if err != nil {
  5644. // br.Msg = "获取销售失败"
  5645. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  5646. // return
  5647. //}
  5648. //for _, seller := range sellerList {
  5649. // sellerItem := company.DepartmentGroupSellers{
  5650. // AdminId: fmt.Sprint(seller.AdminId),
  5651. // //AdminName string `description:"系统用户名称"`
  5652. // RealName: seller.RealName,
  5653. // Authority: seller.Authority,
  5654. // RoleTypeCode: seller.RoleTypeCode,
  5655. // }
  5656. // groupSellerList = append(groupSellerList, sellerItem)
  5657. //}
  5658. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  5659. groupItem.ChildrenList = groupSellerList
  5660. if len(groupSellerList) > 0 {
  5661. departmentGroupSellerList = append(departmentGroupSellerList, groupItem)
  5662. }
  5663. }
  5664. //分组为0的销售(直属部门)
  5665. departmentSellerList, err := system.GetDepartmentGroupSysUserList(department.DepartmentId, 0, roleCodeTypeStr)
  5666. if err != nil {
  5667. br.Msg = "获取销售失败"
  5668. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  5669. return
  5670. }
  5671. if len(departmentSellerList) > 0 {
  5672. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  5673. for _, seller := range departmentSellerList {
  5674. sellerItem := company.DepartmentGroupSellers{
  5675. AdminId: fmt.Sprint(seller.AdminId),
  5676. //AdminName string `description:"系统用户名称"`
  5677. RealName: seller.RealName,
  5678. Authority: seller.Authority,
  5679. RoleTypeCode: seller.RoleTypeCode,
  5680. }
  5681. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  5682. }
  5683. //排个序
  5684. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  5685. departmentGroupSellerList = append(departmentGroupSellerList, tmpDepartmentGroupSellersList...)
  5686. }
  5687. item.ChildrenList = departmentGroupSellerList
  5688. if len(departmentGroupSellerList) > 0 {
  5689. list = append(list, item)
  5690. }
  5691. }
  5692. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM || sysUser.Authority == 4 {
  5693. //销售组长看销售
  5694. if status == 0 {
  5695. directorId := sysUser.GroupId
  5696. fmt.Println("directorId:", directorId)
  5697. groupList, err := system.GetSysGroupByDirectorId(directorId)
  5698. if err != nil {
  5699. br.Msg = "获取失败"
  5700. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  5701. return
  5702. }
  5703. for _, group := range groupList {
  5704. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  5705. groupItem := company.DepartmentGroupSellers{
  5706. AdminId: fmt.Sprint("group_", group.DepartmentId),
  5707. //AdminName string `description:"系统用户名称"`
  5708. RealName: group.GroupName,
  5709. ChildrenList: groupSellerList,
  5710. }
  5711. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  5712. if err != nil {
  5713. br.Msg = "获取小组失败"
  5714. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  5715. return
  5716. }
  5717. for _, team := range teamList {
  5718. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  5719. teamItem := company.DepartmentGroupSellers{
  5720. AdminId: fmt.Sprint("team_", team.GroupId),
  5721. //AdminName string `description:"系统用户名称"`
  5722. RealName: team.GroupName,
  5723. ChildrenList: teamSellerList,
  5724. }
  5725. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  5726. if err != nil {
  5727. br.Msg = "获取销售失败"
  5728. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  5729. return
  5730. }
  5731. for _, seller := range sellerList {
  5732. sellerItem := company.DepartmentGroupSellers{
  5733. AdminId: fmt.Sprint(seller.AdminId),
  5734. //AdminName string `description:"系统用户名称"`
  5735. RealName: seller.RealName,
  5736. Authority: seller.Authority,
  5737. RoleTypeCode: seller.RoleTypeCode,
  5738. }
  5739. //fmt.Println("seller.RealName:", seller.RealName)
  5740. teamSellerList = append(teamSellerList, sellerItem)
  5741. }
  5742. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  5743. teamItem.ChildrenList = teamSellerList
  5744. if len(teamSellerList) > 0 {
  5745. groupSellerList = append(groupSellerList, teamItem)
  5746. }
  5747. }
  5748. //分组为0的销售(直属分组)
  5749. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  5750. if err != nil {
  5751. br.Msg = "获取销售失败"
  5752. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  5753. return
  5754. }
  5755. if len(groupTeamSellerList) > 0 {
  5756. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  5757. for _, seller := range groupTeamSellerList {
  5758. sellerItem := company.DepartmentGroupSellers{
  5759. AdminId: fmt.Sprint(seller.AdminId),
  5760. //AdminName string `description:"系统用户名称"`
  5761. RealName: seller.RealName,
  5762. Authority: seller.Authority,
  5763. RoleTypeCode: seller.RoleTypeCode,
  5764. }
  5765. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  5766. }
  5767. //排个序
  5768. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  5769. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  5770. }
  5771. groupItem.ChildrenList = groupSellerList
  5772. if len(groupSellerList) > 0 {
  5773. list = append(list, groupItem)
  5774. }
  5775. }
  5776. } else {
  5777. departmentStr := `1,2`
  5778. departmentList, err := system.GetDepartmentListByIds(departmentStr)
  5779. if err != nil {
  5780. br.Msg = "获取失败"
  5781. br.ErrMsg = "获取部门失败,Err:" + err.Error()
  5782. return
  5783. }
  5784. for _, department := range departmentList {
  5785. departmentGroupSellerList := make([]company.DepartmentGroupSellers, 0)
  5786. item := company.DepartmentGroupSellers{
  5787. AdminId: fmt.Sprint("department_", department.DepartmentId),
  5788. //AdminName string `description:"系统用户名称"`
  5789. RealName: department.DepartmentName,
  5790. ChildrenList: departmentGroupSellerList,
  5791. }
  5792. groupList, err := system.GetSysGroupByDepartmentId(department.DepartmentId)
  5793. if err != nil {
  5794. br.Msg = "获取失败"
  5795. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  5796. return
  5797. }
  5798. for _, group := range groupList {
  5799. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  5800. groupItem := company.DepartmentGroupSellers{
  5801. AdminId: fmt.Sprint("group_", group.DepartmentId),
  5802. //AdminName string `description:"系统用户名称"`
  5803. RealName: group.GroupName,
  5804. ChildrenList: groupSellerList,
  5805. }
  5806. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  5807. if err != nil {
  5808. br.Msg = "获取小组失败"
  5809. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  5810. return
  5811. }
  5812. for _, team := range teamList {
  5813. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  5814. teamItem := company.DepartmentGroupSellers{
  5815. AdminId: fmt.Sprint("team_", team.GroupId),
  5816. //AdminName string `description:"系统用户名称"`
  5817. RealName: team.GroupName,
  5818. ChildrenList: teamSellerList,
  5819. }
  5820. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  5821. if err != nil {
  5822. br.Msg = "获取销售失败"
  5823. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  5824. return
  5825. }
  5826. for _, seller := range sellerList {
  5827. sellerItem := company.DepartmentGroupSellers{
  5828. AdminId: fmt.Sprint(seller.AdminId),
  5829. //AdminName string `description:"系统用户名称"`
  5830. RealName: seller.RealName,
  5831. Authority: seller.Authority,
  5832. RoleTypeCode: seller.RoleTypeCode,
  5833. }
  5834. //fmt.Println("seller.RealName:", seller.RealName)
  5835. teamSellerList = append(teamSellerList, sellerItem)
  5836. }
  5837. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  5838. teamItem.ChildrenList = teamSellerList
  5839. if len(teamSellerList) > 0 {
  5840. groupSellerList = append(groupSellerList, teamItem)
  5841. }
  5842. }
  5843. //分组为0的人,不光是销售(直属分组)
  5844. groupTeamSellerList, err := system.GetGroupSysUserList(group.GroupId)
  5845. if err != nil {
  5846. br.Msg = "获取销售失败"
  5847. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  5848. return
  5849. }
  5850. if len(groupTeamSellerList) > 0 {
  5851. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  5852. for _, seller := range groupTeamSellerList {
  5853. sellerItem := company.DepartmentGroupSellers{
  5854. AdminId: fmt.Sprint(seller.AdminId),
  5855. //AdminName string `description:"系统用户名称"`
  5856. RealName: seller.RealName,
  5857. Authority: seller.Authority,
  5858. RoleTypeCode: seller.RoleTypeCode,
  5859. }
  5860. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  5861. }
  5862. //排个序
  5863. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  5864. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  5865. }
  5866. //groupItem.ChildrenList = groupSellerList
  5867. //if len(groupSellerList) > 0 {
  5868. // list = append(list, item)
  5869. //}
  5870. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  5871. //if err != nil {
  5872. // br.Msg = "获取销售失败"
  5873. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  5874. // return
  5875. //}
  5876. //for _, seller := range sellerList {
  5877. // sellerItem := company.DepartmentGroupSellers{
  5878. // AdminId: fmt.Sprint(seller.AdminId),
  5879. // //AdminName string `description:"系统用户名称"`
  5880. // RealName: seller.RealName,
  5881. // Authority: seller.Authority,
  5882. // RoleTypeCode: seller.RoleTypeCode,
  5883. // }
  5884. // groupSellerList = append(groupSellerList, sellerItem)
  5885. //}
  5886. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  5887. groupItem.ChildrenList = groupSellerList
  5888. if len(groupSellerList) > 0 {
  5889. departmentGroupSellerList = append(departmentGroupSellerList, groupItem)
  5890. }
  5891. }
  5892. //分组为0的人,不光是销售(直属部门)
  5893. departmentSellerList, err := system.GetDepartmentGroupSysUserList(department.DepartmentId, 0, "")
  5894. if err != nil {
  5895. br.Msg = "获取销售失败"
  5896. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  5897. return
  5898. }
  5899. if len(departmentSellerList) > 0 {
  5900. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  5901. for _, seller := range departmentSellerList {
  5902. sellerItem := company.DepartmentGroupSellers{
  5903. AdminId: fmt.Sprint(seller.AdminId),
  5904. //AdminName string `description:"系统用户名称"`
  5905. RealName: seller.RealName,
  5906. Authority: seller.Authority,
  5907. RoleTypeCode: seller.RoleTypeCode,
  5908. }
  5909. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  5910. }
  5911. //排个序
  5912. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  5913. departmentGroupSellerList = append(departmentGroupSellerList, tmpDepartmentGroupSellersList...)
  5914. }
  5915. item.ChildrenList = departmentGroupSellerList
  5916. if len(departmentGroupSellerList) > 0 {
  5917. list = append(list, item)
  5918. }
  5919. }
  5920. }
  5921. } 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管理员
  5922. departmentStr := `2,5,7` //合规
  5923. switch sysUser.RoleTypeCode {
  5924. case utils.ROLE_TYPE_CODE_FINANCE: //财务
  5925. departmentStr = `2,5,8`
  5926. case utils.ROLE_TYPE_CODE_FICC_ADMIN: //ficc管理员
  5927. departmentStr = utils.GetFiccAdminDepartmentIds()
  5928. }
  5929. departmentList, err := system.GetDepartmentListByIds(departmentStr)
  5930. if err != nil {
  5931. br.Msg = "获取失败"
  5932. br.ErrMsg = "获取部门失败,Err:" + err.Error()
  5933. return
  5934. }
  5935. for _, department := range departmentList {
  5936. fmt.Println(department)
  5937. departmentGroupSellerList := make([]company.DepartmentGroupSellers, 0)
  5938. item := company.DepartmentGroupSellers{
  5939. AdminId: fmt.Sprint("department_", department.DepartmentId),
  5940. //AdminName string `description:"系统用户名称"`
  5941. RealName: department.DepartmentName,
  5942. ChildrenList: departmentGroupSellerList,
  5943. }
  5944. groupList, err := system.GetSysGroupByDepartmentId(department.DepartmentId)
  5945. if err != nil {
  5946. br.Msg = "获取失败"
  5947. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  5948. return
  5949. }
  5950. for _, group := range groupList {
  5951. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  5952. groupItem := company.DepartmentGroupSellers{
  5953. AdminId: fmt.Sprint("group_", group.DepartmentId),
  5954. //AdminName string `description:"系统用户名称"`
  5955. RealName: group.GroupName,
  5956. ChildrenList: groupSellerList,
  5957. }
  5958. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  5959. if err != nil {
  5960. br.Msg = "获取小组失败"
  5961. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  5962. return
  5963. }
  5964. for _, team := range teamList {
  5965. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  5966. teamItem := company.DepartmentGroupSellers{
  5967. AdminId: fmt.Sprint("team_", team.GroupId),
  5968. //AdminName string `description:"系统用户名称"`
  5969. RealName: team.GroupName,
  5970. ChildrenList: teamSellerList,
  5971. }
  5972. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  5973. if err != nil {
  5974. br.Msg = "获取销售失败"
  5975. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  5976. return
  5977. }
  5978. for _, seller := range sellerList {
  5979. sellerItem := company.DepartmentGroupSellers{
  5980. AdminId: fmt.Sprint(seller.AdminId),
  5981. //AdminName string `description:"系统用户名称"`
  5982. RealName: seller.RealName,
  5983. Authority: seller.Authority,
  5984. RoleTypeCode: seller.RoleTypeCode,
  5985. }
  5986. //fmt.Println("seller.RealName:", seller.RealName)
  5987. teamSellerList = append(teamSellerList, sellerItem)
  5988. }
  5989. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  5990. teamItem.ChildrenList = teamSellerList
  5991. if len(teamSellerList) > 0 {
  5992. groupSellerList = append(groupSellerList, teamItem)
  5993. }
  5994. }
  5995. //分组为0的销售(直属分组)
  5996. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  5997. if err != nil {
  5998. br.Msg = "获取销售失败"
  5999. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  6000. return
  6001. }
  6002. if len(groupTeamSellerList) > 0 {
  6003. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  6004. for _, seller := range groupTeamSellerList {
  6005. sellerItem := company.DepartmentGroupSellers{
  6006. AdminId: fmt.Sprint(seller.AdminId),
  6007. //AdminName string `description:"系统用户名称"`
  6008. RealName: seller.RealName,
  6009. Authority: seller.Authority,
  6010. RoleTypeCode: seller.RoleTypeCode,
  6011. }
  6012. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  6013. }
  6014. //排个序
  6015. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  6016. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  6017. }
  6018. //groupItem.ChildrenList = groupSellerList
  6019. //if len(groupSellerList) > 0 {
  6020. // list = append(list, item)
  6021. //}
  6022. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  6023. //if err != nil {
  6024. // br.Msg = "获取销售失败"
  6025. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  6026. // return
  6027. //}
  6028. //for _, seller := range sellerList {
  6029. // sellerItem := company.DepartmentGroupSellers{
  6030. // AdminId: fmt.Sprint(seller.AdminId),
  6031. // //AdminName string `description:"系统用户名称"`
  6032. // RealName: seller.RealName,
  6033. // Authority: seller.Authority,
  6034. // RoleTypeCode: seller.RoleTypeCode,
  6035. // }
  6036. // groupSellerList = append(groupSellerList, sellerItem)
  6037. //}
  6038. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  6039. groupItem.ChildrenList = groupSellerList
  6040. if len(groupSellerList) > 0 {
  6041. departmentGroupSellerList = append(departmentGroupSellerList, groupItem)
  6042. }
  6043. }
  6044. //分组为0的销售(直属部门)
  6045. departmentSellerList, err := system.GetDepartmentGroupSysUserList(department.DepartmentId, 0, roleCodeTypeStr)
  6046. if err != nil {
  6047. br.Msg = "获取销售失败"
  6048. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  6049. return
  6050. }
  6051. if len(departmentSellerList) > 0 {
  6052. tmpDepartmentGroupSellerList := make([]company.DepartmentGroupSellers, 0)
  6053. for _, seller := range departmentSellerList {
  6054. sellerItem := company.DepartmentGroupSellers{
  6055. AdminId: fmt.Sprint(seller.AdminId),
  6056. //AdminName string `description:"系统用户名称"`
  6057. RealName: seller.RealName,
  6058. Authority: seller.Authority,
  6059. RoleTypeCode: seller.RoleTypeCode,
  6060. }
  6061. tmpDepartmentGroupSellerList = append(tmpDepartmentGroupSellerList, sellerItem)
  6062. }
  6063. //排个序
  6064. tmpDepartmentGroupSellerList = sortDepartmentGroupSellers(tmpDepartmentGroupSellerList)
  6065. departmentGroupSellerList = append(departmentGroupSellerList, tmpDepartmentGroupSellerList...)
  6066. }
  6067. item.ChildrenList = departmentGroupSellerList
  6068. if len(departmentGroupSellerList) > 0 {
  6069. list = append(list, item)
  6070. }
  6071. }
  6072. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN || sysUser.Authority == 1 {
  6073. //部门管理员看小组、销售
  6074. departmentId := sysUser.DepartmentId
  6075. switch sysUser.RoleTypeCode {
  6076. case utils.ROLE_TYPE_CODE_RAI_ADMIN: //权益管理员
  6077. departmentId = 5
  6078. case utils.ROLE_TYPE_CODE_FICC_ADMIN: //ficc管理员
  6079. departmentId = 2
  6080. }
  6081. groupList, err := system.GetSysGroupByDepartmentId(departmentId)
  6082. if err != nil {
  6083. br.Msg = "获取失败"
  6084. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  6085. return
  6086. }
  6087. for _, group := range groupList {
  6088. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  6089. groupItem := company.DepartmentGroupSellers{
  6090. AdminId: fmt.Sprint("group_", group.DepartmentId),
  6091. //AdminName string `description:"系统用户名称"`
  6092. RealName: group.GroupName,
  6093. ChildrenList: groupSellerList,
  6094. }
  6095. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  6096. if err != nil {
  6097. br.Msg = "获取小组失败"
  6098. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  6099. return
  6100. }
  6101. for _, team := range teamList {
  6102. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  6103. teamItem := company.DepartmentGroupSellers{
  6104. AdminId: fmt.Sprint("team_", team.GroupId),
  6105. //AdminName string `description:"系统用户名称"`
  6106. RealName: team.GroupName,
  6107. ChildrenList: teamSellerList,
  6108. }
  6109. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  6110. if err != nil {
  6111. br.Msg = "获取销售失败"
  6112. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  6113. return
  6114. }
  6115. for _, seller := range sellerList {
  6116. sellerItem := company.DepartmentGroupSellers{
  6117. AdminId: fmt.Sprint(seller.AdminId),
  6118. //AdminName string `description:"系统用户名称"`
  6119. RealName: seller.RealName,
  6120. Authority: seller.Authority,
  6121. RoleTypeCode: seller.RoleTypeCode,
  6122. }
  6123. //fmt.Println("seller.RealName:", seller.RealName)
  6124. teamSellerList = append(teamSellerList, sellerItem)
  6125. }
  6126. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  6127. teamItem.ChildrenList = teamSellerList
  6128. if len(teamSellerList) > 0 {
  6129. groupSellerList = append(groupSellerList, teamItem)
  6130. }
  6131. }
  6132. //分组为0的销售(直属分组)
  6133. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  6134. if err != nil {
  6135. br.Msg = "获取销售失败"
  6136. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  6137. return
  6138. }
  6139. if len(groupTeamSellerList) > 0 {
  6140. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  6141. for _, seller := range groupTeamSellerList {
  6142. sellerItem := company.DepartmentGroupSellers{
  6143. AdminId: fmt.Sprint(seller.AdminId),
  6144. //AdminName string `description:"系统用户名称"`
  6145. RealName: seller.RealName,
  6146. Authority: seller.Authority,
  6147. RoleTypeCode: seller.RoleTypeCode,
  6148. }
  6149. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  6150. }
  6151. //排个序
  6152. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  6153. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  6154. }
  6155. //groupItem.ChildrenList = groupSellerList
  6156. //if len(groupSellerList) > 0 {
  6157. // list = append(list, item)
  6158. //}
  6159. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  6160. //if err != nil {
  6161. // br.Msg = "获取销售失败"
  6162. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  6163. // return
  6164. //}
  6165. //for _, seller := range sellerList {
  6166. // sellerItem := company.DepartmentGroupSellers{
  6167. // AdminId: fmt.Sprint(seller.AdminId),
  6168. // //AdminName string `description:"系统用户名称"`
  6169. // RealName: seller.RealName,
  6170. // Authority: seller.Authority,
  6171. // RoleTypeCode: seller.RoleTypeCode,
  6172. // }
  6173. // groupSellerList = append(groupSellerList, sellerItem)
  6174. //}
  6175. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  6176. groupItem.ChildrenList = groupSellerList
  6177. if len(groupSellerList) > 0 {
  6178. list = append(list, groupItem)
  6179. }
  6180. }
  6181. //分组为0的销售(直属部门)
  6182. departmentSellerList, err := system.GetDepartmentGroupSysUserList(departmentId, 0, roleCodeTypeStr)
  6183. if err != nil {
  6184. br.Msg = "获取销售失败"
  6185. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  6186. return
  6187. }
  6188. if len(departmentSellerList) > 0 {
  6189. tmpDepartmentGroupSeller := make([]company.DepartmentGroupSellers, 0)
  6190. for _, seller := range departmentSellerList {
  6191. sellerItem := company.DepartmentGroupSellers{
  6192. AdminId: fmt.Sprint(seller.AdminId),
  6193. //AdminName string `description:"系统用户名称"`
  6194. RealName: seller.RealName,
  6195. Authority: seller.Authority,
  6196. RoleTypeCode: seller.RoleTypeCode,
  6197. }
  6198. tmpDepartmentGroupSeller = append(tmpDepartmentGroupSeller, sellerItem)
  6199. }
  6200. tmpDepartmentGroupSeller = sortDepartmentGroupSellers(tmpDepartmentGroupSeller)
  6201. list = append(list, tmpDepartmentGroupSeller...)
  6202. }
  6203. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP || (sysUser.Authority == 2 && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_FICC_GROUP) {
  6204. // 权益组长看小组
  6205. if status == 0 {
  6206. sellerList, err := system.GetTeamSysUserList(sysUser.GroupId, enabled)
  6207. if err != nil {
  6208. br.Msg = "获取销售失败"
  6209. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  6210. return
  6211. }
  6212. for _, seller := range sellerList {
  6213. sellerItem := company.DepartmentGroupSellers{
  6214. AdminId: fmt.Sprint(seller.AdminId),
  6215. //AdminName string `description:"系统用户名称"`
  6216. RealName: seller.RealName,
  6217. Authority: seller.Authority,
  6218. RoleTypeCode: seller.RoleTypeCode,
  6219. }
  6220. //fmt.Println("seller.RealName:", seller.RealName)
  6221. list = append(list, sellerItem)
  6222. }
  6223. list = sortDepartmentGroupSellers(list)
  6224. //正常来说没有所有人都应该在某个小组下,要不就是小组名为 无 的小组
  6225. //分组为0的销售(直属分组)
  6226. //groupTeamSellerList, err := system.GetGrooupsysUserList(sysUser.GroupId, 0, roleCodeTypeStr)
  6227. //if err != nil {
  6228. // br.Msg = "获取销售失败"
  6229. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  6230. // return
  6231. //}
  6232. //if len(groupTeamSellerList) > 0 {
  6233. // tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  6234. // for _, seller := range groupTeamSellerList {
  6235. // sellerItem := company.DepartmentGroupSellers{
  6236. // AdminId: fmt.Sprint(seller.AdminId),
  6237. // //AdminName string `description:"系统用户名称"`
  6238. // RealName: seller.RealName,
  6239. // Authority: seller.Authority,
  6240. // RoleTypeCode: seller.RoleTypeCode,
  6241. // }
  6242. // tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  6243. // }
  6244. // //排个序
  6245. // tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  6246. // list = append(list, tmpDepartmentGroupSellersList...)
  6247. //}
  6248. //sellerList, err := system.GetDepartmentGroupSysUserList(sysUser.DepartmentId, sysUser.GroupId, roleCodeTypeStr)
  6249. //if err != nil {
  6250. // br.Msg = "获取销售失败"
  6251. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  6252. // return
  6253. //}
  6254. //for _, seller := range sellerList {
  6255. // sellerItem := company.DepartmentGroupSellers{
  6256. // AdminId: fmt.Sprint(seller.AdminId),
  6257. // //AdminName string `description:"系统用户名称"`
  6258. // RealName: seller.RealName,
  6259. // Authority: seller.Authority,
  6260. // RoleTypeCode: seller.RoleTypeCode,
  6261. // }
  6262. // list = append(list, sellerItem)
  6263. // list = sortDepartmentGroupSellers(list)
  6264. //}
  6265. } else {
  6266. departmentId := 5
  6267. groupList, err := system.GetSysGroupByDepartmentId(departmentId)
  6268. if err != nil {
  6269. br.Msg = "获取失败"
  6270. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  6271. return
  6272. }
  6273. for _, group := range groupList {
  6274. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  6275. groupItem := company.DepartmentGroupSellers{
  6276. AdminId: fmt.Sprint("group_", group.DepartmentId),
  6277. //AdminName string `description:"系统用户名称"`
  6278. RealName: group.GroupName,
  6279. ChildrenList: groupSellerList,
  6280. }
  6281. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  6282. if err != nil {
  6283. br.Msg = "获取小组失败"
  6284. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  6285. return
  6286. }
  6287. for _, team := range teamList {
  6288. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  6289. teamItem := company.DepartmentGroupSellers{
  6290. AdminId: fmt.Sprint("team_", team.GroupId),
  6291. //AdminName string `description:"系统用户名称"`
  6292. RealName: team.GroupName,
  6293. ChildrenList: teamSellerList,
  6294. }
  6295. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  6296. if err != nil {
  6297. br.Msg = "获取销售失败"
  6298. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  6299. return
  6300. }
  6301. for _, seller := range sellerList {
  6302. sellerItem := company.DepartmentGroupSellers{
  6303. AdminId: fmt.Sprint(seller.AdminId),
  6304. //AdminName string `description:"系统用户名称"`
  6305. RealName: seller.RealName,
  6306. Authority: seller.Authority,
  6307. RoleTypeCode: seller.RoleTypeCode,
  6308. }
  6309. //fmt.Println("seller.RealName:", seller.RealName)
  6310. teamSellerList = append(teamSellerList, sellerItem)
  6311. }
  6312. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  6313. teamItem.ChildrenList = teamSellerList
  6314. if len(teamSellerList) > 0 {
  6315. groupSellerList = append(groupSellerList, teamItem)
  6316. }
  6317. }
  6318. //分组为0的销售(直属分组)
  6319. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  6320. if err != nil {
  6321. br.Msg = "获取销售失败"
  6322. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  6323. return
  6324. }
  6325. if len(groupTeamSellerList) > 0 {
  6326. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  6327. for _, seller := range groupTeamSellerList {
  6328. sellerItem := company.DepartmentGroupSellers{
  6329. AdminId: fmt.Sprint(seller.AdminId),
  6330. //AdminName string `description:"系统用户名称"`
  6331. RealName: seller.RealName,
  6332. Authority: seller.Authority,
  6333. RoleTypeCode: seller.RoleTypeCode,
  6334. }
  6335. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  6336. }
  6337. //排个序
  6338. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  6339. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  6340. }
  6341. //groupItem.ChildrenList = groupSellerList
  6342. //if len(groupSellerList) > 0 {
  6343. // list = append(list, item)
  6344. //}
  6345. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  6346. //if err != nil {
  6347. // br.Msg = "获取销售失败"
  6348. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  6349. // return
  6350. //}
  6351. //for _, seller := range sellerList {
  6352. // sellerItem := company.DepartmentGroupSellers{
  6353. // AdminId: fmt.Sprint(seller.AdminId),
  6354. // //AdminName string `description:"系统用户名称"`
  6355. // RealName: seller.RealName,
  6356. // Authority: seller.Authority,
  6357. // RoleTypeCode: seller.RoleTypeCode,
  6358. // }
  6359. // groupSellerList = append(groupSellerList, sellerItem)
  6360. //}
  6361. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  6362. groupItem.ChildrenList = groupSellerList
  6363. if len(groupSellerList) > 0 {
  6364. list = append(list, groupItem)
  6365. }
  6366. }
  6367. //分组为0的销售(直属部门)
  6368. departmentSellerList, err := system.GetDepartmentGroupSysUserList(departmentId, 0, roleCodeTypeStr)
  6369. if err != nil {
  6370. br.Msg = "获取销售失败"
  6371. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  6372. return
  6373. }
  6374. if len(departmentSellerList) > 0 {
  6375. tmpDepartmentGroupSeller := make([]company.DepartmentGroupSellers, 0)
  6376. for _, seller := range departmentSellerList {
  6377. sellerItem := company.DepartmentGroupSellers{
  6378. AdminId: fmt.Sprint(seller.AdminId),
  6379. //AdminName string `description:"系统用户名称"`
  6380. RealName: seller.RealName,
  6381. Authority: seller.Authority,
  6382. RoleTypeCode: seller.RoleTypeCode,
  6383. }
  6384. tmpDepartmentGroupSeller = append(tmpDepartmentGroupSeller, sellerItem)
  6385. }
  6386. tmpDepartmentGroupSeller = sortDepartmentGroupSellers(tmpDepartmentGroupSeller)
  6387. list = append(list, tmpDepartmentGroupSeller...)
  6388. }
  6389. }
  6390. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || sysUser.Authority == 2 {
  6391. // 销售主管看小组
  6392. if status == 0 {
  6393. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  6394. if err != nil {
  6395. br.Msg = "获取失败"
  6396. br.ErrMsg = "查询父级id异常" + err.Error()
  6397. return
  6398. }
  6399. var realGroupId int
  6400. if pid != nil && *pid > 0 {
  6401. //主管角色放在了三级分组下
  6402. realGroupId = *pid
  6403. } else {
  6404. //主管角色放在了二级分组下
  6405. realGroupId = sysUser.GroupId
  6406. }
  6407. groupList, err := system.GetSysGroupByGroupId(realGroupId)
  6408. if err != nil {
  6409. br.Msg = "获取失败"
  6410. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  6411. return
  6412. }
  6413. for _, group := range groupList {
  6414. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  6415. //groupItem := company.DepartmentGroupSellers{
  6416. // AdminId: fmt.Sprint("group_", group.DepartmentId),
  6417. // //AdminName string `description:"系统用户名称"`
  6418. // RealName: group.GroupName,
  6419. // ChildrenList: groupSellerList,
  6420. //}
  6421. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  6422. if err != nil {
  6423. br.Msg = "获取小组失败"
  6424. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  6425. return
  6426. }
  6427. for _, team := range teamList {
  6428. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  6429. teamItem := company.DepartmentGroupSellers{
  6430. AdminId: fmt.Sprint("team_", team.GroupId),
  6431. //AdminName string `description:"系统用户名称"`
  6432. RealName: team.GroupName,
  6433. ChildrenList: teamSellerList,
  6434. }
  6435. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  6436. if err != nil {
  6437. br.Msg = "获取销售失败"
  6438. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  6439. return
  6440. }
  6441. for _, seller := range sellerList {
  6442. sellerItem := company.DepartmentGroupSellers{
  6443. AdminId: fmt.Sprint(seller.AdminId),
  6444. //AdminName string `description:"系统用户名称"`
  6445. RealName: seller.RealName,
  6446. Authority: seller.Authority,
  6447. RoleTypeCode: seller.RoleTypeCode,
  6448. }
  6449. //fmt.Println("seller.RealName:", seller.RealName)
  6450. teamSellerList = append(teamSellerList, sellerItem)
  6451. }
  6452. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  6453. teamItem.ChildrenList = teamSellerList
  6454. if len(teamSellerList) > 0 {
  6455. groupSellerList = append(groupSellerList, teamItem)
  6456. }
  6457. }
  6458. //分组为0的销售(直属分组)
  6459. groupTeamSellerList, err := system.GetGrooupsysUserList(realGroupId, roleCodeTypeStr, enabled)
  6460. if err != nil {
  6461. br.Msg = "获取销售失败"
  6462. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  6463. return
  6464. }
  6465. if len(groupTeamSellerList) > 0 {
  6466. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  6467. for _, seller := range groupTeamSellerList {
  6468. sellerItem := company.DepartmentGroupSellers{
  6469. AdminId: fmt.Sprint(seller.AdminId),
  6470. //AdminName string `description:"系统用户名称"`
  6471. RealName: seller.RealName,
  6472. Authority: seller.Authority,
  6473. RoleTypeCode: seller.RoleTypeCode,
  6474. }
  6475. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  6476. }
  6477. //排个序
  6478. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  6479. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  6480. }
  6481. list = groupSellerList
  6482. //groupItem.ChildrenList = groupSellerList
  6483. //if len(groupSellerList) > 0 {
  6484. // list = append(list, item)
  6485. //}
  6486. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  6487. //if err != nil {
  6488. // br.Msg = "获取销售失败"
  6489. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  6490. // return
  6491. //}
  6492. //for _, seller := range sellerList {
  6493. // sellerItem := company.DepartmentGroupSellers{
  6494. // AdminId: fmt.Sprint(seller.AdminId),
  6495. // //AdminName string `description:"系统用户名称"`
  6496. // RealName: seller.RealName,
  6497. // Authority: seller.Authority,
  6498. // RoleTypeCode: seller.RoleTypeCode,
  6499. // }
  6500. // groupSellerList = append(groupSellerList, sellerItem)
  6501. //}
  6502. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  6503. //groupItem.ChildrenList = groupSellerList
  6504. //if len(groupSellerList) > 0 {
  6505. // list = append(list, groupItem)
  6506. //}
  6507. }
  6508. //分组为0的销售(直属二级分组)
  6509. //departmentSellerList, err := system.GetDepartmentGroupSysUserList(2, realGroupId, roleCodeTypeStr)
  6510. //if err != nil {
  6511. // br.Msg = "获取销售失败"
  6512. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  6513. // return
  6514. //}
  6515. //if len(departmentSellerList) > 0 {
  6516. // tmpDepartmentGroupSeller := make([]company.DepartmentGroupSellers, 0)
  6517. // for _, seller := range departmentSellerList {
  6518. // sellerItem := company.DepartmentGroupSellers{
  6519. // AdminId: fmt.Sprint(seller.AdminId),
  6520. // //AdminName string `description:"系统用户名称"`
  6521. // RealName: seller.RealName,
  6522. // Authority: seller.Authority,
  6523. // RoleTypeCode: seller.RoleTypeCode,
  6524. // }
  6525. // tmpDepartmentGroupSeller = append(tmpDepartmentGroupSeller, sellerItem)
  6526. // }
  6527. // tmpDepartmentGroupSeller = sortDepartmentGroupSellers(tmpDepartmentGroupSeller)
  6528. // list = append(list, tmpDepartmentGroupSeller...)
  6529. //}
  6530. //pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  6531. //if err != nil {
  6532. // br.Msg = "获取失败"
  6533. // br.ErrMsg = "查询父级id异常" + err.Error()
  6534. // return
  6535. //}
  6536. //if pid != nil && *pid > 0 {
  6537. // //主管角色放在了三级分组下
  6538. // //
  6539. //
  6540. //
  6541. //} else {
  6542. // //主管角色放在了二级分组下
  6543. //
  6544. //}
  6545. //ids, err := company.GetGroupIdsByParentId(*pid)
  6546. //if err != nil {
  6547. // br.Msg = "获取失败"
  6548. // br.ErrMsg = "查询父级id异常" + err.Error()
  6549. // return
  6550. //}
  6551. //var idSlice []string
  6552. //var sid string
  6553. //for _, id := range ids {
  6554. // idSlice = append(idSlice, *id)
  6555. //}
  6556. //sid = strings.Join(idSlice, ",")
  6557. //sellerList, err := system.GetTeamSysUserListByIds(sid)
  6558. //if err != nil {
  6559. // br.Msg = "获取销售失败"
  6560. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  6561. // return
  6562. //}
  6563. //for _, seller := range sellerList {
  6564. // sellerItem := company.DepartmentGroupSellers{
  6565. // AdminId: fmt.Sprint(seller.AdminId),
  6566. // //AdminName string `description:"系统用户名称"`
  6567. // RealName: seller.RealName,
  6568. // Authority: seller.Authority,
  6569. // RoleTypeCode: seller.RoleTypeCode,
  6570. // }
  6571. // fmt.Println("seller.RealName:", seller.RealName)
  6572. // list = append(list, sellerItem)
  6573. //}
  6574. //list = sortDepartmentGroupSellers(list)
  6575. //
  6576. ////分组为0的销售(直属分组)
  6577. //groupTeamSellerList, err := system.GetGrooupsysUserList(sysUser.GroupId, roleCodeTypeStr)
  6578. //if err != nil {
  6579. // br.Msg = "获取销售失败"
  6580. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  6581. // return
  6582. //}
  6583. //if len(groupTeamSellerList) > 0 {
  6584. // tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  6585. // for _, seller := range groupTeamSellerList {
  6586. // sellerItem := company.DepartmentGroupSellers{
  6587. // AdminId: fmt.Sprint(seller.AdminId),
  6588. // //AdminName string `description:"系统用户名称"`
  6589. // RealName: seller.RealName,
  6590. // Authority: seller.Authority,
  6591. // RoleTypeCode: seller.RoleTypeCode,
  6592. // }
  6593. // tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  6594. // }
  6595. // //排个序
  6596. // tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  6597. // list = append(list, tmpDepartmentGroupSellersList...)
  6598. //}
  6599. //sellerList, err := system.GetDepartmentGroupSysUserList(sysUser.DepartmentId, sysUser.GroupId, roleCodeTypeStr)
  6600. //if err != nil {
  6601. // br.Msg = "获取销售失败"
  6602. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  6603. // return
  6604. //}
  6605. //for _, seller := range sellerList {
  6606. // sellerItem := company.DepartmentGroupSellers{
  6607. // AdminId: fmt.Sprint(seller.AdminId),
  6608. // //AdminName string `description:"系统用户名称"`
  6609. // RealName: seller.RealName,
  6610. // Authority: seller.Authority,
  6611. // RoleTypeCode: seller.RoleTypeCode,
  6612. // }
  6613. // list = append(list, sellerItem)
  6614. // list = sortDepartmentGroupSellers(list)
  6615. //}
  6616. //正常来说没有所有人都应该在某个小组下,要不就是小组名为 无 的小组
  6617. } else {
  6618. //var departmentStr string
  6619. //if utils.RunMode == "release" {
  6620. // departmentStr = `1,2`
  6621. //} else {
  6622. // departmentStr = `1,2`
  6623. //}
  6624. departmentStr := `1,2`
  6625. departmentList, err := system.GetDepartmentListByIds(departmentStr)
  6626. if err != nil {
  6627. br.Msg = "获取失败"
  6628. br.ErrMsg = "获取部门失败,Err:" + err.Error()
  6629. return
  6630. }
  6631. for _, department := range departmentList {
  6632. departmentGroupSellerList := make([]company.DepartmentGroupSellers, 0)
  6633. item := company.DepartmentGroupSellers{
  6634. AdminId: fmt.Sprint("department_", department.DepartmentId),
  6635. //AdminName string `description:"系统用户名称"`
  6636. RealName: department.DepartmentName,
  6637. ChildrenList: departmentGroupSellerList,
  6638. }
  6639. groupList, err := system.GetSysGroupByDepartmentId(department.DepartmentId)
  6640. if err != nil {
  6641. br.Msg = "获取失败"
  6642. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  6643. return
  6644. }
  6645. for _, group := range groupList {
  6646. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  6647. groupItem := company.DepartmentGroupSellers{
  6648. AdminId: fmt.Sprint("group_", group.DepartmentId),
  6649. //AdminName string `description:"系统用户名称"`
  6650. RealName: group.GroupName,
  6651. ChildrenList: groupSellerList,
  6652. }
  6653. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  6654. if err != nil {
  6655. br.Msg = "获取小组失败"
  6656. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  6657. return
  6658. }
  6659. for _, team := range teamList {
  6660. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  6661. teamItem := company.DepartmentGroupSellers{
  6662. AdminId: fmt.Sprint("team_", team.GroupId),
  6663. //AdminName string `description:"系统用户名称"`
  6664. RealName: team.GroupName,
  6665. ChildrenList: teamSellerList,
  6666. }
  6667. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  6668. if err != nil {
  6669. br.Msg = "获取销售失败"
  6670. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  6671. return
  6672. }
  6673. for _, seller := range sellerList {
  6674. sellerItem := company.DepartmentGroupSellers{
  6675. AdminId: fmt.Sprint(seller.AdminId),
  6676. //AdminName string `description:"系统用户名称"`
  6677. RealName: seller.RealName,
  6678. Authority: seller.Authority,
  6679. RoleTypeCode: seller.RoleTypeCode,
  6680. }
  6681. //fmt.Println("seller.RealName:", seller.RealName)
  6682. teamSellerList = append(teamSellerList, sellerItem)
  6683. }
  6684. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  6685. teamItem.ChildrenList = teamSellerList
  6686. if len(teamSellerList) > 0 {
  6687. groupSellerList = append(groupSellerList, teamItem)
  6688. }
  6689. }
  6690. //分组为0的人,不光是销售(直属分组)
  6691. groupTeamSellerList, err := system.GetGroupSysUserList(group.GroupId)
  6692. if err != nil {
  6693. br.Msg = "获取销售失败"
  6694. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  6695. return
  6696. }
  6697. if len(groupTeamSellerList) > 0 {
  6698. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  6699. for _, seller := range groupTeamSellerList {
  6700. sellerItem := company.DepartmentGroupSellers{
  6701. AdminId: fmt.Sprint(seller.AdminId),
  6702. //AdminName string `description:"系统用户名称"`
  6703. RealName: seller.RealName,
  6704. Authority: seller.Authority,
  6705. RoleTypeCode: seller.RoleTypeCode,
  6706. }
  6707. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  6708. }
  6709. //排个序
  6710. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  6711. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  6712. }
  6713. //groupItem.ChildrenList = groupSellerList
  6714. //if len(groupSellerList) > 0 {
  6715. // list = append(list, item)
  6716. //}
  6717. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  6718. //if err != nil {
  6719. // br.Msg = "获取销售失败"
  6720. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  6721. // return
  6722. //}
  6723. //for _, seller := range sellerList {
  6724. // sellerItem := company.DepartmentGroupSellers{
  6725. // AdminId: fmt.Sprint(seller.AdminId),
  6726. // //AdminName string `description:"系统用户名称"`
  6727. // RealName: seller.RealName,
  6728. // Authority: seller.Authority,
  6729. // RoleTypeCode: seller.RoleTypeCode,
  6730. // }
  6731. // groupSellerList = append(groupSellerList, sellerItem)
  6732. //}
  6733. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  6734. groupItem.ChildrenList = groupSellerList
  6735. if len(groupSellerList) > 0 {
  6736. departmentGroupSellerList = append(departmentGroupSellerList, groupItem)
  6737. }
  6738. }
  6739. //分组为0的人,不光是销售(直属部门)
  6740. departmentSellerList, err := system.GetDepartmentGroupSysUserList(department.DepartmentId, 0, "")
  6741. if err != nil {
  6742. br.Msg = "获取销售失败"
  6743. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  6744. return
  6745. }
  6746. if len(departmentSellerList) > 0 {
  6747. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  6748. for _, seller := range departmentSellerList {
  6749. sellerItem := company.DepartmentGroupSellers{
  6750. AdminId: fmt.Sprint(seller.AdminId),
  6751. //AdminName string `description:"系统用户名称"`
  6752. RealName: seller.RealName,
  6753. Authority: seller.Authority,
  6754. RoleTypeCode: seller.RoleTypeCode,
  6755. }
  6756. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  6757. }
  6758. //排个序
  6759. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  6760. departmentGroupSellerList = append(departmentGroupSellerList, tmpDepartmentGroupSellersList...)
  6761. }
  6762. item.ChildrenList = departmentGroupSellerList
  6763. if len(departmentGroupSellerList) > 0 {
  6764. list = append(list, item)
  6765. }
  6766. }
  6767. }
  6768. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER && status == 1 {
  6769. //var departmentStr string
  6770. //if utils.RunMode == "release" {
  6771. // departmentStr = `1,2`
  6772. //} else {
  6773. // departmentStr = `1,2`
  6774. //}
  6775. departmentStr := `1,2`
  6776. departmentList, err := system.GetDepartmentListByIds(departmentStr)
  6777. if err != nil {
  6778. br.Msg = "获取失败"
  6779. br.ErrMsg = "获取部门失败,Err:" + err.Error()
  6780. return
  6781. }
  6782. for _, department := range departmentList {
  6783. departmentGroupSellerList := make([]company.DepartmentGroupSellers, 0)
  6784. item := company.DepartmentGroupSellers{
  6785. AdminId: fmt.Sprint("department_", department.DepartmentId),
  6786. //AdminName string `description:"系统用户名称"`
  6787. RealName: department.DepartmentName,
  6788. ChildrenList: departmentGroupSellerList,
  6789. }
  6790. groupList, err := system.GetSysGroupByDepartmentId(department.DepartmentId)
  6791. if err != nil {
  6792. br.Msg = "获取失败"
  6793. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  6794. return
  6795. }
  6796. for _, group := range groupList {
  6797. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  6798. groupItem := company.DepartmentGroupSellers{
  6799. AdminId: fmt.Sprint("group_", group.DepartmentId),
  6800. //AdminName string `description:"系统用户名称"`
  6801. RealName: group.GroupName,
  6802. ChildrenList: groupSellerList,
  6803. }
  6804. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  6805. if err != nil {
  6806. br.Msg = "获取小组失败"
  6807. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  6808. return
  6809. }
  6810. for _, team := range teamList {
  6811. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  6812. teamItem := company.DepartmentGroupSellers{
  6813. AdminId: fmt.Sprint("team_", team.GroupId),
  6814. //AdminName string `description:"系统用户名称"`
  6815. RealName: team.GroupName,
  6816. ChildrenList: teamSellerList,
  6817. }
  6818. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  6819. if err != nil {
  6820. br.Msg = "获取销售失败"
  6821. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  6822. return
  6823. }
  6824. for _, seller := range sellerList {
  6825. sellerItem := company.DepartmentGroupSellers{
  6826. AdminId: fmt.Sprint(seller.AdminId),
  6827. //AdminName string `description:"系统用户名称"`
  6828. RealName: seller.RealName,
  6829. Authority: seller.Authority,
  6830. RoleTypeCode: seller.RoleTypeCode,
  6831. }
  6832. //fmt.Println("seller.RealName:", seller.RealName)
  6833. teamSellerList = append(teamSellerList, sellerItem)
  6834. }
  6835. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  6836. teamItem.ChildrenList = teamSellerList
  6837. if len(teamSellerList) > 0 {
  6838. groupSellerList = append(groupSellerList, teamItem)
  6839. }
  6840. }
  6841. //分组为0的人,不光是销售(直属分组)
  6842. groupTeamSellerList, err := system.GetGroupSysUserList(group.GroupId)
  6843. if err != nil {
  6844. br.Msg = "获取销售失败"
  6845. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  6846. return
  6847. }
  6848. if len(groupTeamSellerList) > 0 {
  6849. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  6850. for _, seller := range groupTeamSellerList {
  6851. sellerItem := company.DepartmentGroupSellers{
  6852. AdminId: fmt.Sprint(seller.AdminId),
  6853. //AdminName string `description:"系统用户名称"`
  6854. RealName: seller.RealName,
  6855. Authority: seller.Authority,
  6856. RoleTypeCode: seller.RoleTypeCode,
  6857. }
  6858. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  6859. }
  6860. //排个序
  6861. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  6862. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  6863. }
  6864. //groupItem.ChildrenList = groupSellerList
  6865. //if len(groupSellerList) > 0 {
  6866. // list = append(list, item)
  6867. //}
  6868. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  6869. //if err != nil {
  6870. // br.Msg = "获取销售失败"
  6871. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  6872. // return
  6873. //}
  6874. //for _, seller := range sellerList {
  6875. // sellerItem := company.DepartmentGroupSellers{
  6876. // AdminId: fmt.Sprint(seller.AdminId),
  6877. // //AdminName string `description:"系统用户名称"`
  6878. // RealName: seller.RealName,
  6879. // Authority: seller.Authority,
  6880. // RoleTypeCode: seller.RoleTypeCode,
  6881. // }
  6882. // groupSellerList = append(groupSellerList, sellerItem)
  6883. //}
  6884. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  6885. groupItem.ChildrenList = groupSellerList
  6886. if len(groupSellerList) > 0 {
  6887. departmentGroupSellerList = append(departmentGroupSellerList, groupItem)
  6888. }
  6889. }
  6890. //分组为0的人,不光是销售(直属部门)
  6891. departmentSellerList, err := system.GetDepartmentGroupSysUserList(department.DepartmentId, 0, "")
  6892. if err != nil {
  6893. br.Msg = "获取销售失败"
  6894. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  6895. return
  6896. }
  6897. if len(departmentSellerList) > 0 {
  6898. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  6899. for _, seller := range departmentSellerList {
  6900. sellerItem := company.DepartmentGroupSellers{
  6901. AdminId: fmt.Sprint(seller.AdminId),
  6902. //AdminName string `description:"系统用户名称"`
  6903. RealName: seller.RealName,
  6904. Authority: seller.Authority,
  6905. RoleTypeCode: seller.RoleTypeCode,
  6906. }
  6907. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  6908. }
  6909. //排个序
  6910. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  6911. departmentGroupSellerList = append(departmentGroupSellerList, tmpDepartmentGroupSellersList...)
  6912. }
  6913. item.ChildrenList = departmentGroupSellerList
  6914. if len(departmentGroupSellerList) > 0 {
  6915. list = append(list, item)
  6916. }
  6917. }
  6918. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER && status == 1 {
  6919. // 权益销售可以看到权益销售部的所有人
  6920. departmentId := 5
  6921. groupList, err := system.GetSysGroupByDepartmentId(departmentId)
  6922. if err != nil {
  6923. br.Msg = "获取失败"
  6924. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  6925. return
  6926. }
  6927. for _, group := range groupList {
  6928. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  6929. groupItem := company.DepartmentGroupSellers{
  6930. AdminId: fmt.Sprint("group_", group.DepartmentId),
  6931. //AdminName string `description:"系统用户名称"`
  6932. RealName: group.GroupName,
  6933. ChildrenList: groupSellerList,
  6934. }
  6935. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  6936. if err != nil {
  6937. br.Msg = "获取小组失败"
  6938. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  6939. return
  6940. }
  6941. for _, team := range teamList {
  6942. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  6943. teamItem := company.DepartmentGroupSellers{
  6944. AdminId: fmt.Sprint("team_", team.GroupId),
  6945. //AdminName string `description:"系统用户名称"`
  6946. RealName: team.GroupName,
  6947. ChildrenList: teamSellerList,
  6948. }
  6949. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  6950. if err != nil {
  6951. br.Msg = "获取销售失败"
  6952. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  6953. return
  6954. }
  6955. for _, seller := range sellerList {
  6956. sellerItem := company.DepartmentGroupSellers{
  6957. AdminId: fmt.Sprint(seller.AdminId),
  6958. //AdminName string `description:"系统用户名称"`
  6959. RealName: seller.RealName,
  6960. Authority: seller.Authority,
  6961. RoleTypeCode: seller.RoleTypeCode,
  6962. }
  6963. //fmt.Println("seller.RealName:", seller.RealName)
  6964. teamSellerList = append(teamSellerList, sellerItem)
  6965. }
  6966. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  6967. teamItem.ChildrenList = teamSellerList
  6968. if len(teamSellerList) > 0 {
  6969. groupSellerList = append(groupSellerList, teamItem)
  6970. }
  6971. }
  6972. //分组为0的销售(直属分组)
  6973. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  6974. if err != nil {
  6975. br.Msg = "获取销售失败"
  6976. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  6977. return
  6978. }
  6979. if len(groupTeamSellerList) > 0 {
  6980. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  6981. for _, seller := range groupTeamSellerList {
  6982. sellerItem := company.DepartmentGroupSellers{
  6983. AdminId: fmt.Sprint(seller.AdminId),
  6984. //AdminName string `description:"系统用户名称"`
  6985. RealName: seller.RealName,
  6986. Authority: seller.Authority,
  6987. RoleTypeCode: seller.RoleTypeCode,
  6988. }
  6989. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  6990. }
  6991. //排个序
  6992. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  6993. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  6994. }
  6995. //groupItem.ChildrenList = groupSellerList
  6996. //if len(groupSellerList) > 0 {
  6997. // list = append(list, item)
  6998. //}
  6999. //sellerList, err := system.GetGroupSysUserList(group.DepartmentId)
  7000. //if err != nil {
  7001. // br.Msg = "获取销售失败"
  7002. // br.ErrMsg = "获取销售失败,Err:" + err.Error()
  7003. // return
  7004. //}
  7005. //for _, seller := range sellerList {
  7006. // sellerItem := company.DepartmentGroupSellers{
  7007. // AdminId: fmt.Sprint(seller.AdminId),
  7008. // //AdminName string `description:"系统用户名称"`
  7009. // RealName: seller.RealName,
  7010. // Authority: seller.Authority,
  7011. // RoleTypeCode: seller.RoleTypeCode,
  7012. // }
  7013. // groupSellerList = append(groupSellerList, sellerItem)
  7014. //}
  7015. //groupSellerList = sortDepartmentGroupSellers(groupSellerList)
  7016. groupItem.ChildrenList = groupSellerList
  7017. if len(groupSellerList) > 0 {
  7018. list = append(list, groupItem)
  7019. }
  7020. }
  7021. //分组为0的销售(直属部门)
  7022. departmentSellerList, err := system.GetDepartmentGroupSysUserList(departmentId, 0, roleCodeTypeStr)
  7023. if err != nil {
  7024. br.Msg = "获取销售失败"
  7025. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  7026. return
  7027. }
  7028. if len(departmentSellerList) > 0 {
  7029. tmpDepartmentGroupSeller := make([]company.DepartmentGroupSellers, 0)
  7030. for _, seller := range departmentSellerList {
  7031. sellerItem := company.DepartmentGroupSellers{
  7032. AdminId: fmt.Sprint(seller.AdminId),
  7033. //AdminName string `description:"系统用户名称"`
  7034. RealName: seller.RealName,
  7035. Authority: seller.Authority,
  7036. RoleTypeCode: seller.RoleTypeCode,
  7037. }
  7038. tmpDepartmentGroupSeller = append(tmpDepartmentGroupSeller, sellerItem)
  7039. }
  7040. tmpDepartmentGroupSeller = sortDepartmentGroupSellers(tmpDepartmentGroupSeller)
  7041. list = append(list, tmpDepartmentGroupSeller...)
  7042. }
  7043. } else {
  7044. //看自己
  7045. sellerItem := company.DepartmentGroupSellers{
  7046. AdminId: fmt.Sprint(sysUser.AdminId),
  7047. //AdminName string `description:"系统用户名称"`
  7048. RealName: sysUser.RealName,
  7049. }
  7050. list = append(list, sellerItem)
  7051. }
  7052. } else {
  7053. departmentId := sysUser.DepartmentId
  7054. switch productId {
  7055. case 1:
  7056. departmentId = 2
  7057. case 5:
  7058. departmentId = 5
  7059. }
  7060. //查询整个部门的小组、销售
  7061. groupList, err := system.GetSysGroupByDepartmentId(departmentId)
  7062. if err != nil {
  7063. br.Msg = "获取失败"
  7064. br.ErrMsg = "获取分组失败,Err:" + err.Error()
  7065. return
  7066. }
  7067. for _, group := range groupList {
  7068. groupSellerList := make([]company.DepartmentGroupSellers, 0)
  7069. groupItem := company.DepartmentGroupSellers{
  7070. AdminId: fmt.Sprint("group_", group.DepartmentId),
  7071. //AdminName string `description:"系统用户名称"`
  7072. RealName: group.GroupName,
  7073. ChildrenList: groupSellerList,
  7074. }
  7075. teamList, err := system.GetSysTeamByDepartmentId(group.GroupId)
  7076. if err != nil {
  7077. br.Msg = "获取小组失败"
  7078. br.ErrMsg = "获取小组失败,Err:" + err.Error()
  7079. return
  7080. }
  7081. for _, team := range teamList {
  7082. teamSellerList := make([]company.DepartmentGroupSellers, 0)
  7083. teamItem := company.DepartmentGroupSellers{
  7084. AdminId: fmt.Sprint("team_", team.GroupId),
  7085. //AdminName string `description:"系统用户名称"`
  7086. RealName: team.GroupName,
  7087. ChildrenList: teamSellerList,
  7088. }
  7089. sellerList, err := system.GetTeamSysUserList(team.GroupId, enabled)
  7090. if err != nil {
  7091. br.Msg = "获取销售失败"
  7092. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  7093. return
  7094. }
  7095. for _, seller := range sellerList {
  7096. sellerItem := company.DepartmentGroupSellers{
  7097. AdminId: fmt.Sprint(seller.AdminId),
  7098. //AdminName string `description:"系统用户名称"`
  7099. RealName: seller.RealName,
  7100. Authority: seller.Authority,
  7101. RoleTypeCode: seller.RoleTypeCode,
  7102. }
  7103. //fmt.Println("seller.RealName:", seller.RealName)
  7104. teamSellerList = append(teamSellerList, sellerItem)
  7105. }
  7106. teamSellerList = sortDepartmentGroupSellers(teamSellerList)
  7107. teamItem.ChildrenList = teamSellerList
  7108. if len(teamSellerList) > 0 {
  7109. groupSellerList = append(groupSellerList, teamItem)
  7110. }
  7111. }
  7112. //分组为0的销售(直属分组)
  7113. groupTeamSellerList, err := system.GetGrooupsysUserList(group.GroupId, roleCodeTypeStr, enabled)
  7114. if err != nil {
  7115. br.Msg = "获取销售失败"
  7116. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  7117. return
  7118. }
  7119. if len(groupTeamSellerList) > 0 {
  7120. tmpDepartmentGroupSellersList := make([]company.DepartmentGroupSellers, 0)
  7121. for _, seller := range groupTeamSellerList {
  7122. sellerItem := company.DepartmentGroupSellers{
  7123. AdminId: fmt.Sprint(seller.AdminId),
  7124. //AdminName string `description:"系统用户名称"`
  7125. RealName: seller.RealName,
  7126. Authority: seller.Authority,
  7127. RoleTypeCode: seller.RoleTypeCode,
  7128. }
  7129. tmpDepartmentGroupSellersList = append(tmpDepartmentGroupSellersList, sellerItem)
  7130. }
  7131. //排个序
  7132. tmpDepartmentGroupSellersList = sortDepartmentGroupSellers(tmpDepartmentGroupSellersList)
  7133. groupSellerList = append(groupSellerList, tmpDepartmentGroupSellersList...)
  7134. }
  7135. groupItem.ChildrenList = groupSellerList
  7136. if len(groupSellerList) > 0 {
  7137. list = append(list, groupItem)
  7138. }
  7139. }
  7140. //分组为0的销售(直属部门)
  7141. departmentSellerList, err := system.GetDepartmentGroupSysUserList(departmentId, 0, roleCodeTypeStr)
  7142. if err != nil {
  7143. br.Msg = "获取销售失败"
  7144. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  7145. return
  7146. }
  7147. if len(departmentSellerList) > 0 {
  7148. tmpDepartmentGroupSeller := make([]company.DepartmentGroupSellers, 0)
  7149. for _, seller := range departmentSellerList {
  7150. sellerItem := company.DepartmentGroupSellers{
  7151. AdminId: fmt.Sprint(seller.AdminId),
  7152. //AdminName string `description:"系统用户名称"`
  7153. RealName: seller.RealName,
  7154. Authority: seller.Authority,
  7155. RoleTypeCode: seller.RoleTypeCode,
  7156. }
  7157. tmpDepartmentGroupSeller = append(tmpDepartmentGroupSeller, sellerItem)
  7158. }
  7159. //排个序
  7160. tmpDepartmentGroupSeller = sortDepartmentGroupSellers(tmpDepartmentGroupSeller)
  7161. list = append(list, tmpDepartmentGroupSeller...)
  7162. }
  7163. }
  7164. //// 海外销售部-目前无权限, 均可见
  7165. //seaDepartment, e := system.GetSysDepartmentByName("海外销售部")
  7166. //if e != nil && e.Error() != utils.ErrNoRow() {
  7167. // br.Msg = "获取失败"
  7168. // br.ErrMsg = "获取海外销售部失败, Err: " + e.Error()
  7169. // return
  7170. //}
  7171. //if e == nil {
  7172. // // 获取部门下的销售人员
  7173. // seaSellers, e := system.GetDepartmentGroupSysUserList(seaDepartment.DepartmentId, 0, "")
  7174. // if e != nil {
  7175. // br.Msg = "获取失败"
  7176. // br.ErrMsg = "获取海外销售失败, Err: " + e.Error()
  7177. // return
  7178. // }
  7179. // // 获取分组
  7180. // seaGroups, e := system.GetSysGroupListByDepartmentId(seaDepartment.DepartmentId)
  7181. // if e != nil {
  7182. // br.Msg = "获取失败"
  7183. // br.ErrMsg = "获取海外销售部分组失败, Err: " + e.Error()
  7184. // return
  7185. // }
  7186. //
  7187. // var d company.DepartmentGroupSellers
  7188. // d.AdminId = fmt.Sprintf("department_%d", seaDepartment.DepartmentId)
  7189. // d.RealName = seaDepartment.DepartmentName
  7190. // children := make([]company.DepartmentGroupSellers, 0)
  7191. // // 无分组
  7192. // if len(seaGroups) == 0 {
  7193. // for _, s := range seaSellers {
  7194. // children = append(children, company.DepartmentGroupSellers{
  7195. // AdminId: strconv.Itoa(s.AdminId),
  7196. // RealName: s.RealName,
  7197. // RoleTypeCode: s.RoleTypeCode,
  7198. // Authority: s.Authority,
  7199. // })
  7200. // }
  7201. // }
  7202. // // 有分组
  7203. // if len(seaGroups) > 0 {
  7204. // // 销售map
  7205. // sellerMap := make(map[int][]company.DepartmentGroupSellers)
  7206. // for _, s := range seaSellers {
  7207. // sellerMap[s.GroupId] = append(sellerMap[s.GroupId], company.DepartmentGroupSellers{
  7208. // AdminId: strconv.Itoa(s.AdminId),
  7209. // RealName: s.RealName,
  7210. // RoleTypeCode: s.RoleTypeCode,
  7211. // Authority: s.Authority,
  7212. // })
  7213. // }
  7214. // // 小组map
  7215. // childrenMap := make(map[int][]company.DepartmentGroupSellers)
  7216. // for _, g := range seaGroups {
  7217. // if g.ParentId == 0 {
  7218. // continue
  7219. // }
  7220. // childrenMap[g.ParentId] = append(childrenMap[g.ParentId], company.DepartmentGroupSellers{
  7221. // AdminId: fmt.Sprintf("team_%d", g.GroupId),
  7222. // RealName: g.GroupName,
  7223. // ChildrenList: sellerMap[g.GroupId],
  7224. // })
  7225. // }
  7226. // // 大组
  7227. // for _, g := range seaGroups {
  7228. // if g.ParentId > 0 {
  7229. // continue
  7230. // }
  7231. // c := childrenMap[g.GroupId]
  7232. // if len(sellerMap[g.GroupId]) > 0 {
  7233. // c = append(c, sellerMap[g.GroupId]...)
  7234. // }
  7235. // children = append(children, company.DepartmentGroupSellers{
  7236. // AdminId: fmt.Sprintf("group_%d", g.GroupId),
  7237. // RealName: g.GroupName,
  7238. // ChildrenList: c,
  7239. // })
  7240. // }
  7241. // }
  7242. // d.ChildrenList = children
  7243. // list = append(list, d)
  7244. //}
  7245. br.Ret = 200
  7246. br.Success = true
  7247. br.Msg = "获取成功"
  7248. br.Data = company.DepartmentGroupSellersResp{
  7249. List: list,
  7250. }
  7251. }