company.go 319 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "github.com/tealeg/xlsx"
  7. "hongze/hz_crm_api/cache"
  8. "hongze/hz_crm_api/models"
  9. "hongze/hz_crm_api/models/advisory"
  10. "hongze/hz_crm_api/models/company"
  11. "hongze/hz_crm_api/models/company_report_permission_log"
  12. "hongze/hz_crm_api/models/company_todo"
  13. "hongze/hz_crm_api/models/company_user"
  14. "hongze/hz_crm_api/models/cygx"
  15. "hongze/hz_crm_api/models/response"
  16. statisticModels "hongze/hz_crm_api/models/statistic_report"
  17. "hongze/hz_crm_api/models/system"
  18. "hongze/hz_crm_api/services"
  19. "hongze/hz_crm_api/services/alarm_msg"
  20. cygxService "hongze/hz_crm_api/services/cygx"
  21. "hongze/hz_crm_api/services/statistic_report"
  22. "hongze/hz_crm_api/utils"
  23. "os"
  24. "path/filepath"
  25. "strconv"
  26. "strings"
  27. "time"
  28. )
  29. // 客户管理
  30. type CompanyController struct {
  31. BaseAuthController
  32. }
  33. // @Title 客户检索列表
  34. // @Description 客户检索列表接口
  35. // @Param KeyWord query string true "搜索关键词"
  36. // @Param PageSize query int true "每页数据条数"
  37. // @Param CurrentIndex query int true "当前页页码,从1开始"
  38. // @Success 200 {object} company.CompanySearchListResp
  39. // @router /search/list [get]
  40. func (this *CompanyController) SearchList() {
  41. br := new(models.BaseResponse).Init()
  42. defer func() {
  43. this.Data["json"] = br
  44. this.ServeJSON()
  45. }()
  46. sysUser := this.SysUser
  47. if sysUser == nil {
  48. br.Msg = "请登录"
  49. br.ErrMsg = "请登录,SysUser Is Empty"
  50. br.Ret = 408
  51. return
  52. }
  53. pageSize, _ := this.GetInt("PageSize")
  54. currentIndex, _ := this.GetInt("CurrentIndex")
  55. var startSize int
  56. if pageSize <= 0 {
  57. pageSize = utils.PageSize20
  58. }
  59. if currentIndex <= 0 {
  60. currentIndex = 1
  61. }
  62. startSize = paging.StartIndex(currentIndex, pageSize)
  63. roleTypeCode := sysUser.RoleTypeCode
  64. keyWord := this.GetString("KeyWord")
  65. keyWord = strings.Trim(keyWord, " ")
  66. keyWord = strings.Replace(keyWord, "'", "", -1)
  67. resp := new(company.CompanySearchListResp)
  68. var condition string
  69. var pars []interface{}
  70. //需要忽略的关键字
  71. ignoreStrs := []string{"", "有限", "投资", "资本", "管理", "贸易", "资产", "公司", "股份", "集团", "有限公司"}
  72. if strings.Contains(strings.Join(ignoreStrs, ","), keyWord) {
  73. list := make([]*company.CompanySearchItem, 0)
  74. resp.List = list
  75. br.Ret = 200
  76. br.Success = true
  77. br.Msg = "获取成功"
  78. br.Data = resp
  79. return
  80. }
  81. //正常筛选逻辑
  82. companyIdStr, err := company.GetCompanyIdByKeyWordAll(keyWord)
  83. if err != nil {
  84. br.Msg = "获取失败"
  85. br.ErrMsg = "获取失败,Err:" + err.Error()
  86. return
  87. }
  88. companyIdStr = strings.Trim(companyIdStr, ",")
  89. if companyIdStr != "" {
  90. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  91. } else {
  92. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.credit_code LIKE '%` + keyWord + `%')`
  93. //pars = append(pars, keyWord)
  94. //pars = append(pars, keyWord)
  95. }
  96. total, err := company.GetCompanySearchCount(condition, pars)
  97. if err != nil {
  98. br.Msg = "获取失败"
  99. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  100. return
  101. }
  102. list, err := company.GetCompanySearchList(condition, pars, startSize, pageSize)
  103. if err != nil && err.Error() != utils.ErrNoRow() {
  104. br.Msg = "获取失败"
  105. br.ErrMsg = "获取失败,Err:" + err.Error()
  106. return
  107. }
  108. // 查询当前销售是否有领取客户的权限
  109. receiveEnabled, _ := services.CheckCompanyReceiveButton(sysUser.AdminId)
  110. // 白嫖客户标记
  111. scroungeList, err := company.GetScroungeCompany()
  112. if err != nil {
  113. br.Msg = "获取失败"
  114. br.ErrMsg = "获取白嫖客户信息失败,Err:" + err.Error()
  115. return
  116. }
  117. scroungeMap := make(map[int]int)
  118. for _, v := range scroungeList {
  119. scroungeMap[v.CompanyId] = 1
  120. }
  121. /*
  122. 时长根据客户状态定义,
  123. 若为冻结客户或者流失客户,则展示冻结时长或流失时长;
  124. 若为正式或试用客户,展示到期时长;
  125. */
  126. lenList := len(list)
  127. for i := 0; i < lenList; i++ {
  128. duration := ""
  129. item := list[i]
  130. itemStatus := item.Status
  131. //白嫖客户标记
  132. if _, ok := scroungeMap[item.CompanyId]; ok {
  133. item.IsScrounge = 1
  134. }
  135. if !strings.Contains(item.Status, "/") {
  136. if item.Status == utils.COMPANY_STATUS_FREEZE {
  137. if item.FreezeEndDate != "" {
  138. freeZeTime, _ := time.Parse(utils.FormatDate, item.FreezeEndDate)
  139. freeZeTime = freeZeTime.AddDate(0, 0, 1)
  140. sub := freeZeTime.Sub(time.Now())
  141. if sub < 0 {
  142. sub = 0
  143. }
  144. duration = fmt.Sprintf("%v", int(sub.Hours()/24))
  145. }
  146. } else if item.Status == utils.COMPANY_STATUS_LOSE {
  147. if item.LossTime != "" {
  148. lossTime, err := time.Parse(utils.FormatDateTime, item.LossTime)
  149. if err != nil {
  150. fmt.Println("err:" + err.Error())
  151. }
  152. lossTime = lossTime.AddDate(0, 0, 1)
  153. sub := time.Now().Sub(lossTime)
  154. if sub < 0 {
  155. sub = 0
  156. }
  157. duration = fmt.Sprintf("%v", int(sub.Hours()/24))
  158. }
  159. } else if item.Status == utils.COMPANY_STATUS_FORMAL ||
  160. item.Status == utils.COMPANY_STATUS_TRY_OUT {
  161. if item.EndDate != "" {
  162. endDate, _ := time.Parse(utils.FormatDate, item.EndDate)
  163. endDate = endDate.AddDate(0, 0, 1)
  164. sub := endDate.Sub(time.Now())
  165. if sub < 0 {
  166. sub = 0
  167. }
  168. duration = fmt.Sprintf("%v", int(sub.Hours()/24))
  169. }
  170. } else if item.Status == utils.COMPANY_STATUS_TRY_OUT {
  171. duration = "永续"
  172. } else {
  173. duration = "-"
  174. }
  175. } else {
  176. statusArr := strings.Split(item.Status, "/")
  177. //freezeArr := strings.Split(item.FreezeTime, "/") //0:ficc,1:权益
  178. freezeArr := strings.Split(item.FreezeEndDate, "/") //冻结结束日期:0:ficc,1:权益
  179. lossArr := strings.Split(item.LossTime, "/") //0:ficc,1:权益
  180. endDateArr := strings.Split(item.EndDate, "/")
  181. var ficcFreeze, tryFreeze string
  182. var ficcLoss, tryLoss string
  183. var ficcEndDate, tryEndDate string
  184. ficcStatus := statusArr[0]
  185. tryOutStatus := statusArr[1]
  186. //if len(freezeArr) > 1 {
  187. // ficcFreeze = freezeArr[0]
  188. // tryFreeze = freezeArr[1]
  189. //}
  190. //if len(lossArr) > 1 {
  191. // ficcLoss = lossArr[0]
  192. // tryLoss = lossArr[1]
  193. //}
  194. //结束日期
  195. if len(endDateArr) > 1 {
  196. ficcEndDate = endDateArr[0]
  197. tryEndDate = endDateArr[1]
  198. }
  199. //冻结
  200. if ficcStatus == utils.COMPANY_STATUS_FREEZE && len(freezeArr) > 0 {
  201. //ficc
  202. ficcFreeze = freezeArr[0]
  203. }
  204. if tryOutStatus == utils.COMPANY_STATUS_FREEZE && len(freezeArr) > 0 {
  205. //权益
  206. if len(freezeArr) == 1 {
  207. tryFreeze = freezeArr[0]
  208. } else {
  209. tryFreeze = freezeArr[1]
  210. }
  211. }
  212. //流失
  213. if ficcStatus == utils.COMPANY_STATUS_LOSE && len(lossArr) > 0 {
  214. //ficc
  215. ficcLoss = lossArr[0]
  216. }
  217. if tryOutStatus == utils.COMPANY_STATUS_LOSE && len(lossArr) > 0 {
  218. //权益
  219. if len(lossArr) == 1 {
  220. tryLoss = lossArr[0]
  221. } else {
  222. tryLoss = lossArr[1]
  223. }
  224. }
  225. //ficc的判断
  226. switch ficcStatus {
  227. case utils.COMPANY_STATUS_FREEZE: //冻结
  228. if ficcFreeze != "" {
  229. ficcFreeZeTime, _ := time.Parse(utils.FormatDate, ficcFreeze)
  230. ficcFreeZeTime = ficcFreeZeTime.AddDate(0, 0, 1)
  231. sub := ficcFreeZeTime.Sub(time.Now())
  232. if sub < 0 {
  233. sub = 0
  234. }
  235. duration = fmt.Sprintf("%v", int(sub.Hours()/24))
  236. }
  237. case utils.COMPANY_STATUS_LOSE: //流失
  238. if ficcLoss != "" {
  239. ficcLossTime, _ := time.Parse(utils.FormatDateTime, ficcLoss)
  240. ficcLossTime = ficcLossTime.AddDate(0, 0, 1)
  241. sub := time.Now().Sub(ficcLossTime)
  242. if sub < 0 {
  243. sub = 0
  244. }
  245. duration = fmt.Sprintf("%v", int(sub.Hours()/24))
  246. }
  247. case utils.COMPANY_STATUS_FORMAL, utils.COMPANY_STATUS_TRY_OUT:
  248. if ficcEndDate != "" {
  249. ficcEndDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
  250. ficcEndDateTime = ficcEndDateTime.AddDate(0, 0, 1)
  251. sub := ficcEndDateTime.Sub(time.Now())
  252. if sub < 0 {
  253. sub = 0
  254. }
  255. duration = fmt.Sprintf("%v", int(sub.Hours()/24))
  256. }
  257. case utils.COMPANY_STATUS_FOREVER:
  258. duration = "永续"
  259. case utils.COMPANY_STATUS_CLOSE:
  260. duration = "-"
  261. }
  262. //权益的判断
  263. switch tryOutStatus {
  264. case utils.COMPANY_STATUS_FREEZE: //冻结
  265. if tryFreeze != "" {
  266. tryOutFreeZeTime, _ := time.Parse(utils.FormatDate, tryFreeze)
  267. tryOutFreeZeTime = tryOutFreeZeTime.AddDate(0, 0, 1)
  268. sub := tryOutFreeZeTime.Sub(time.Now())
  269. if sub < 0 {
  270. sub = 0
  271. }
  272. if duration != "" {
  273. duration = duration + "/" + fmt.Sprintf("%v", int(sub.Hours()/24))
  274. }
  275. }
  276. case utils.COMPANY_STATUS_LOSE: //流失
  277. if tryLoss != "" {
  278. tryOutLossTime, _ := time.Parse(utils.FormatDateTime, tryLoss)
  279. tryOutLossTime = tryOutLossTime.AddDate(0, 0, 1)
  280. sub := time.Now().Sub(tryOutLossTime)
  281. if sub < 0 {
  282. sub = 0
  283. }
  284. if duration != "" {
  285. duration = duration + "/" + fmt.Sprintf("%v", int(sub.Hours()/24))
  286. }
  287. }
  288. case utils.COMPANY_STATUS_FORMAL, utils.COMPANY_STATUS_TRY_OUT:
  289. if tryEndDate != "" {
  290. tryEndDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
  291. tryEndDateTime = tryEndDateTime.AddDate(0, 0, 1)
  292. sub := tryEndDateTime.Sub(time.Now())
  293. if sub < 0 {
  294. sub = 0
  295. }
  296. if duration != "" {
  297. duration = duration + "/" + fmt.Sprintf("%v", int(sub.Hours()/24))
  298. }
  299. }
  300. case utils.COMPANY_STATUS_FOREVER:
  301. if duration != "" {
  302. duration = duration + "/" + "永续"
  303. }
  304. case utils.COMPANY_STATUS_CLOSE:
  305. duration = "-"
  306. }
  307. //list[i].ApproveStatus = ""
  308. }
  309. approveStatusMap := make(map[int]string)
  310. if item.ProductId == 1 {
  311. approveStatusMap[1] = item.ApproveStatus
  312. } else if item.ProductId == 2 {
  313. approveStatusMap[2] = item.ApproveStatus
  314. }
  315. if strings.Contains(item.ApproveStatus, "/") {
  316. approveStatusSlice := strings.Split(item.ApproveStatus, "/")
  317. approveStatusMap[1] = approveStatusSlice[0]
  318. approveStatusMap[2] = approveStatusSlice[1]
  319. } else {
  320. approveStatusMap[1] = item.ApproveStatus
  321. approveStatusMap[2] = item.ApproveStatus
  322. }
  323. productIdMap := make(map[int]int)
  324. if strings.Contains(item.ProductIds, "/") {
  325. productIdSlice := strings.Split(item.ProductIds, "/")
  326. productIdMap[1], _ = strconv.Atoi(productIdSlice[0])
  327. productIdMap[2], _ = strconv.Atoi(productIdSlice[1])
  328. }
  329. if strings.Contains(item.ApproveStatus, "/") {
  330. approveStatusSlice := strings.Split(item.ApproveStatus, "/")
  331. approveStatusMap[1] = approveStatusSlice[0]
  332. approveStatusMap[2] = approveStatusSlice[1]
  333. for k, v := range productIdMap {
  334. approveStatusMap[v] = approveStatusSlice[k-1]
  335. }
  336. } else {
  337. for _, v := range productIdMap {
  338. approveStatusMap[v] = item.ApproveStatus
  339. }
  340. }
  341. sysProductId := services.GetProductId(sysUser.RoleTypeCode)
  342. if sysProductId > 0 {
  343. list[i].ApproveStatus = approveStatusMap[sysProductId]
  344. }
  345. list[i].Duration = duration
  346. //按钮显示控制
  347. /*btnItem := services.GetCompanySearchPermissionButton(roleTypeCode, itemStatus, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId)
  348. list[i].BtnItem = &btnItem*/
  349. btnItem := new(company.ButtonPermission)
  350. if item.CompanyId != 1 {
  351. *btnItem = services.GetCompanyPermissionButton(roleTypeCode, itemStatus, item.SellerIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, -1, item.ShareSellerIds)
  352. //根据销售"领取客户"的权限对部分按钮做限制
  353. btnItem = services.GetCompanyPermissionButtonByReceiveEnabled(btnItem, receiveEnabled)
  354. }
  355. if list[i].IsShare == 1 && btnItem.BtnModifySeller == true && roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  356. //如果已经是共享客户了,取消共享按钮全都显示,和修改销售权限一样
  357. btnItem.BtnShare = true
  358. }
  359. // 客户搜索页不要共享客户按钮
  360. btnItem.BtnShare = false
  361. //如果是权益客户,操作者又是权益管理员,那么就对他进行展示研选详情按钮
  362. if strings.Contains(item.CompanyType, utils.COMPANY_CLASSIFY_RAI) && sysUser.RoleName == utils.ROLE_TYPE_RAI_PRODUCT {
  363. btnItem.IsResearchShow = true
  364. }
  365. list[i].BtnItem = btnItem
  366. // 签约未签约按钮回显展示
  367. btnCompanyStatusItem := new(company.CompanyStatusButton)
  368. btnCompanyStatusItem = services.GetLsitCompanyStatusButton(list[i].CompanyType, list[i].Status, list[i].SigningStatus)
  369. list[i].CompanyStatusButton = btnCompanyStatusItem
  370. }
  371. for _, v := range list {
  372. v.Status = strings.Replace(v.Status, utils.COMPANY_STATUS_FOREVER, utils.COMPANY_STATUS_X_CLASS_TRY_OUT, -1) // 永续客户类型,映射成 X类试用
  373. v.Duration = strings.Replace(v.Duration, utils.COMPANY_STATUS_FOREVER, utils.COMPANY_STATUS_X_CLASS_TRY_OUT, -1) // 永续客户类型,映射成 X类试用
  374. }
  375. if list == nil {
  376. list = make([]*company.CompanySearchItem, 0)
  377. }
  378. resp.List = list
  379. page := paging.GetPaging(currentIndex, pageSize, total)
  380. resp.Paging = page
  381. br.Ret = 200
  382. br.Success = true
  383. br.Msg = "获取成功"
  384. br.Data = resp
  385. }
  386. // List
  387. // @Title 客户列表
  388. // @Description 客户列表接口
  389. // @Param PageSize query int true "每页数据条数"
  390. // @Param CurrentIndex query int true "当前页页码,从1开始"
  391. // @Param Status query string true "状态:'试用','永续','冻结','流失','正式'"
  392. // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
  393. // @Param IndustryId query int true "行业id,0为全部"
  394. // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
  395. // @Param ChartPermissionIds query string false "阅读权限品种ID,多个用英文逗号分开,空字符串为全部"
  396. // @Param ContractPermissionIds query string false "已购品种ID,多个用英文逗号分开,空字符串为全部"
  397. // @Param StartDate query string true "开始时间"
  398. // @Param EndDate query string true "结束时间"
  399. // @Param CreateStartDate query string true "创建开始时间"
  400. // @Param CreateEndDate query string true "创建结束时间"
  401. // @Param KeyWord query string true "搜索关键词"
  402. // @Param Address query string true "地址 , 多个用英文逗号分开 "
  403. // @Param Province query string true "省 , 多个用英文逗号分开 "
  404. // @Param City query string true "市 , 多个用英文逗号分开 "
  405. // @Param PackageType query int true "套餐类型,0:无,1:大套餐,2:小套餐"
  406. // @Param TodoStatus query string true "任务处理状态;枚举值:'无任务','未完成','已完成'"
  407. // @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:'viewTotal':总阅读次数 、 'viewTime':阅读时间 、 'roadShowTotal':累计路演次数 、`expireDay:到期时间` 、 `createTime:创建时间` 、 'formalTime': 转正时间 、 'freezeTime':冻结时间 、'lossTime':流失时间 、'tryStage':试用标签 、'deadline':距离未完成的任务的截止日期的天数、'tryOutDay':试用天数"
  408. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  409. // @Param SortByTodo query bool true "是否根据待办排序,true或false"
  410. // @Param TryStage query int false "试用客户子标签:0全部、1未分类、2 推进、3 跟踪、4 预备"
  411. // @Param IncludeShare query bool true "是否包含共享客户: true-包含; false-不包含"
  412. // @Param IsSigning query int true "是否签约过: -1-默认全部; 0-否; 1-是"
  413. // @Success 200 {object} company.CompanyListResp
  414. // @router /list [get]
  415. func (this *CompanyController) List() {
  416. br := new(models.BaseResponse).Init()
  417. defer func() {
  418. this.Data["json"] = br
  419. this.ServeJSON()
  420. }()
  421. sysUser := this.SysUser
  422. if sysUser == nil {
  423. br.Msg = "请登录"
  424. br.ErrMsg = "请登录,SysUser Is Empty"
  425. br.Ret = 408
  426. return
  427. }
  428. roleTypeCode := sysUser.RoleTypeCode
  429. pageSize, _ := this.GetInt("PageSize")
  430. currentIndex, _ := this.GetInt("CurrentIndex")
  431. status := this.GetString("Status")
  432. companyType := this.GetString("CompanyType")
  433. industryId, _ := this.GetInt("IndustryId")
  434. adminId := this.GetString("AdminId")
  435. chartPermissionIds := this.GetString("ChartPermissionIds")
  436. contractPermissionIds := this.GetString("ContractPermissionIds")
  437. startDate := this.GetString("StartDate")
  438. endDate := this.GetString("EndDate")
  439. createStartDate := this.GetString("CreateStartDate")
  440. createEndDate := this.GetString("CreateEndDate")
  441. keyWord := this.GetString("KeyWord")
  442. address := this.GetString("Address")
  443. province := this.GetString("Province")
  444. city := this.GetString("City")
  445. regionType := this.GetString("RegionType")
  446. keyWord = strings.Trim(keyWord, " ")
  447. keyWord = strings.Replace(keyWord, "'", "", -1)
  448. todoStatus := this.GetString("TodoStatus") //任务状态
  449. tryStage, _ := this.GetInt("TryStage") //试用客户标签
  450. includeShare, _ := this.GetBool("IncludeShare") // 是否包含试用客户
  451. isSigning, _ := this.GetInt("IsSigning", -1)
  452. // 套餐类型
  453. packageType, _ := this.GetInt("PackageType")
  454. //排序参数
  455. sortParam := this.GetString("SortParam")
  456. sortType := this.GetString("SortType")
  457. sortByTodo, _ := this.GetBool("SortByTodo")
  458. productId := services.GetProductId(roleTypeCode)
  459. var total int
  460. page := paging.GetPaging(currentIndex, pageSize, total)
  461. resp := new(company.CompanyListResp)
  462. statusItems := make([]*company.CompanyStatus, 0)
  463. // 永续客户类型,映射成 X类试用
  464. if status == utils.COMPANY_STATUS_X_CLASS_TRY_OUT {
  465. status = utils.COMPANY_STATUS_FOREVER
  466. }
  467. var statusArr []string
  468. // 对权益用户隐藏关闭
  469. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  470. statusArr = []string{"全部", "试用", "正式", "冻结", "流失", utils.COMPANY_STATUS_X_CLASS_TRY_OUT}
  471. } else {
  472. statusArr = []string{"全部", "试用", "正式", "冻结", "流失", utils.COMPANY_STATUS_CLOSE, utils.COMPANY_STATUS_X_CLASS_TRY_OUT}
  473. }
  474. //var statusArr = [...]string{"全部", "试用-活跃", "试用-非活跃", "正式", "冻结", "流失", "永续"}
  475. var startSize int
  476. if pageSize <= 0 {
  477. pageSize = utils.PageSize20
  478. }
  479. if currentIndex <= 0 {
  480. currentIndex = 1
  481. }
  482. startSize = paging.StartIndex(currentIndex, pageSize)
  483. var condition string
  484. var pars []interface{}
  485. //流失
  486. var lossCondition string
  487. var lossPars []interface{}
  488. //状态分类查询条件
  489. var permissionCondition string
  490. var permissionPars []interface{}
  491. if companyType != "" {
  492. condition += ` AND b.product_name=? `
  493. pars = append(pars, companyType)
  494. }
  495. if industryId > 0 {
  496. condition += ` AND b.industry_id=? `
  497. pars = append(pars, industryId)
  498. }
  499. if adminId != "" {
  500. condition += ` AND b.seller_id IN (` + adminId + `) `
  501. }
  502. if startDate != "" {
  503. condition += ` AND b.start_date>=? `
  504. pars = append(pars, startDate)
  505. }
  506. if endDate != "" {
  507. condition += ` AND b.end_date<=? `
  508. pars = append(pars, endDate)
  509. }
  510. if createStartDate != "" {
  511. condition += ` AND a.created_time>=? `
  512. pars = append(pars, createStartDate)
  513. }
  514. if createEndDate != "" {
  515. condition += ` AND a.created_time<=? `
  516. pars = append(pars, createEndDate)
  517. }
  518. if address != "" {
  519. var addressSql string
  520. slice := strings.Split(address, ",")
  521. for _, v := range slice {
  522. addressSql += "'" + v + "'" + ","
  523. }
  524. addressSql = strings.TrimRight(addressSql, ",")
  525. condition += ` AND a.address IN (` + addressSql + `) `
  526. }
  527. if province != "" {
  528. var provinceSql string
  529. slice := strings.Split(province, ",")
  530. for _, v := range slice {
  531. provinceSql += "'" + v + "'" + ","
  532. }
  533. provinceSql = strings.TrimRight(provinceSql, ",")
  534. condition += ` AND a.province IN (` + provinceSql + `) `
  535. }
  536. if city != "" {
  537. var citySql string
  538. slice := strings.Split(city, ",")
  539. for _, v := range slice {
  540. citySql += "'" + v + "'" + ","
  541. }
  542. citySql = strings.TrimRight(citySql, ",")
  543. condition += ` AND a.city IN (` + citySql + `) `
  544. }
  545. if regionType != "" {
  546. condition += ` AND a.region_type =? `
  547. pars = append(pars, regionType)
  548. }
  549. //是否签约过
  550. if isSigning == 0 || isSigning == 1 {
  551. condition += ` AND b.is_signing = ? `
  552. pars = append(pars, isSigning)
  553. }
  554. if keyWord != "" {
  555. companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
  556. if err != nil {
  557. br.Msg = "获取客户信息失败"
  558. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  559. return
  560. }
  561. if companyIdStr != "" {
  562. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.credit_code LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  563. } else {
  564. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.credit_code LIKE '%` + keyWord + `%' ) `
  565. }
  566. }
  567. //任务状态
  568. if todoStatus != "" {
  569. condition += ` AND b.todo_status =? `
  570. pars = append(pars, todoStatus)
  571. }
  572. // 阅读权限/已购品种筛选
  573. cond, emp, e := services.FilterReadAndContractAuth(chartPermissionIds, contractPermissionIds, condition)
  574. if e != nil {
  575. br.Msg = "获取失败"
  576. br.ErrMsg = "FilterReadAndContractAuth err: " + e.Error()
  577. return
  578. }
  579. if emp {
  580. for _, v := range statusArr {
  581. statusCount := new(company.CompanyStatus)
  582. if v == "全部" {
  583. statusCount.Status = "全部"
  584. statusCount.Count = 0
  585. } else {
  586. statusCount.Status = v
  587. statusCount.Count = 0
  588. }
  589. statusItems = append(statusItems, statusCount)
  590. }
  591. items := make([]*company.CompanyListItem, 0)
  592. resp.List = items
  593. resp.Paging = page
  594. resp.StatusCount = statusItems
  595. br.Msg = "获取成功"
  596. br.Ret = 200
  597. br.Data = resp
  598. return
  599. }
  600. condition = cond
  601. //套餐类型
  602. if packageType > 0 {
  603. condition += ` AND b.package_type=? `
  604. pars = append(pars, packageType)
  605. }
  606. lossCondition = condition
  607. lossPars = pars
  608. permissionCondition = condition
  609. permissionPars = pars
  610. //流失客户统计
  611. lossCondition += ` AND status='流失' `
  612. //权限控制
  613. {
  614. //如果不是超级管理员或者财务
  615. if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && roleTypeCode != utils.ROLE_TYPE_CODE_FINANCE {
  616. //如果是部门管理员
  617. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  618. condition += ` AND b.product_id=? `
  619. pars = append(pars, productId)
  620. lossCondition += ` AND b.product_id=? `
  621. lossPars = append(lossPars, productId)
  622. permissionCondition += ` AND b.product_id=? `
  623. permissionPars = append(permissionPars, productId)
  624. //}
  625. //else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DIRECTOR {
  626. // condition += ` AND b.product_id=? `
  627. // pars = append(pars, productId)
  628. //
  629. // lossCondition += ` AND b.product_id=? `
  630. // lossPars = append(lossPars, productId)
  631. //
  632. // permissionCondition += ` AND b.product_id=? `
  633. // permissionPars = append(permissionPars, productId)
  634. } else {
  635. condition += ` AND b.product_id=? `
  636. pars = append(pars, productId)
  637. lossCondition += ` AND b.product_id=? `
  638. lossPars = append(lossPars, productId)
  639. permissionCondition += ` AND b.product_id=? `
  640. permissionPars = append(permissionPars, productId)
  641. if status == "全部" {
  642. ////如果是筛选了流失客户状态
  643. if sysUser.Authority <= 0 {
  644. condition += ` AND (b.seller_id=? OR status='流失' OR (b.share_seller_id = ? AND b.is_share = 1)) `
  645. pars = append(pars, sysUser.AdminId, sysUser.AdminId)
  646. permissionCondition += ` AND (b.seller_id=? OR status='流失' OR (b.share_seller_id = ? AND b.is_share = 1)) `
  647. permissionPars = append(permissionPars, sysUser.AdminId, sysUser.AdminId)
  648. } else {
  649. if sysUser.Authority == 1 {
  650. condition += ` AND (b.department_id=? OR status='流失')`
  651. pars = append(pars, sysUser.DepartmentId)
  652. permissionCondition += ` AND b.department_id=? `
  653. permissionPars = append(permissionPars, sysUser.DepartmentId)
  654. }
  655. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  656. if status != utils.COMPANY_STATUS_LOSE {
  657. condition += ` AND (b.group_id=? OR status='流失') `
  658. pars = append(pars, sysUser.GroupId)
  659. }
  660. permissionCondition += ` AND b.group_id=? `
  661. permissionPars = append(permissionPars, sysUser.GroupId)
  662. }
  663. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  664. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  665. if err != nil {
  666. br.Msg = "获取失败"
  667. br.ErrMsg = "查询父级id异常" + err.Error()
  668. return
  669. }
  670. var ids []*string
  671. if pid != nil {
  672. if *pid != 0 {
  673. //销售主管放在三级列表中
  674. ids, err = company.GetGroupIdsByParentId(*pid)
  675. if err != nil {
  676. fmt.Println(err.Error())
  677. }
  678. } else {
  679. //销售主管放在二级列表中
  680. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  681. if err != nil {
  682. fmt.Println(err.Error())
  683. }
  684. }
  685. }
  686. var idSlice []string
  687. var sid string
  688. for _, id := range ids {
  689. idSlice = append(idSlice, *id)
  690. }
  691. //加入父级groupId
  692. if *pid > 0 {
  693. idSlice = append(idSlice, strconv.Itoa(*pid))
  694. } else {
  695. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  696. }
  697. sid = strings.Join(idSlice, ",")
  698. if len(sid) > 0 {
  699. if status != utils.COMPANY_STATUS_LOSE {
  700. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  701. //pars = append(pars, sysUser.GroupId)
  702. }
  703. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  704. } else {
  705. if status != utils.COMPANY_STATUS_LOSE {
  706. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  707. //pars = append(pars, sysUser.GroupId)
  708. }
  709. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  710. }
  711. //permissionPars = append(permissionPars, sysUser.GroupId)
  712. }
  713. if sysUser.Authority == 4 {
  714. //pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  715. //if err != nil {
  716. // br.Msg = "获取失败"
  717. // br.ErrMsg = "查询父级id异常" + err.Error()
  718. // return
  719. //}
  720. //ids,err := company.GetGroupIdsByParentId(*pid)
  721. //if err != nil {
  722. // br.Msg = "获取失败"
  723. // br.ErrMsg = "查询父级id异常" + err.Error()
  724. // return
  725. //}
  726. //var idSlice []string
  727. //var sid string
  728. //for _, id := range ids {
  729. // idSlice = append(idSlice, *id)
  730. //}
  731. //sid = strings.Join(idSlice,",")
  732. if status != utils.COMPANY_STATUS_LOSE {
  733. condition += ` AND (b.group_id =? OR status='流失') `
  734. pars = append(pars, sysUser.GroupId)
  735. }
  736. permissionCondition += ` AND b.group_id=? `
  737. permissionPars = append(permissionPars, sysUser.GroupId)
  738. }
  739. }
  740. } else {
  741. //如果没有筛选了流失客户状态,那么需要加客户归属条件加入到查询中去
  742. if sysUser.Authority <= 0 {
  743. if status != utils.COMPANY_STATUS_LOSE {
  744. //condition += ` AND b.seller_id=? `
  745. //pars = append(pars, sysUser.AdminId)
  746. // 是否包含共享客户(新增合同时, 关键词搜索客户为true)
  747. if includeShare {
  748. condition += ` AND (b.seller_id = ? OR (b.share_seller_id = ? AND b.is_share = 1)) `
  749. pars = append(pars, sysUser.AdminId, sysUser.AdminId)
  750. } else {
  751. condition += ` AND b.seller_id = ? `
  752. pars = append(pars, sysUser.AdminId)
  753. }
  754. }
  755. permissionCondition += ` AND (b.seller_id=? OR (b.share_seller_id = ? AND b.is_share = 1)) `
  756. permissionPars = append(permissionPars, sysUser.AdminId, sysUser.AdminId)
  757. } else {
  758. if sysUser.Authority == 1 {
  759. if status != utils.COMPANY_STATUS_LOSE {
  760. condition += ` AND b.department_id=?`
  761. pars = append(pars, sysUser.DepartmentId)
  762. }
  763. permissionCondition += ` AND b.department_id=? `
  764. permissionPars = append(permissionPars, sysUser.DepartmentId)
  765. }
  766. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  767. if status != utils.COMPANY_STATUS_LOSE {
  768. condition += ` AND b.group_id=? `
  769. pars = append(pars, sysUser.GroupId)
  770. }
  771. permissionCondition += ` AND b.group_id=? `
  772. permissionPars = append(permissionPars, sysUser.GroupId)
  773. }
  774. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  775. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  776. if err != nil {
  777. br.Msg = "获取失败"
  778. br.ErrMsg = "查询父级id异常" + err.Error()
  779. return
  780. }
  781. var ids []*string
  782. if pid != nil {
  783. if *pid != 0 {
  784. //销售主管放在三级列表中
  785. ids, err = company.GetGroupIdsByParentId(*pid)
  786. if err != nil {
  787. fmt.Println(err.Error())
  788. }
  789. } else {
  790. //销售主管放在二级列表中
  791. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  792. if err != nil {
  793. fmt.Println(err.Error())
  794. }
  795. }
  796. }
  797. var idSlice []string
  798. var sid string
  799. for _, id := range ids {
  800. idSlice = append(idSlice, *id)
  801. }
  802. //加入父级groupId
  803. if *pid > 0 {
  804. idSlice = append(idSlice, strconv.Itoa(*pid))
  805. } else {
  806. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  807. }
  808. sid = strings.Join(idSlice, ",")
  809. if len(sid) > 0 {
  810. if status != utils.COMPANY_STATUS_LOSE {
  811. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  812. //pars = append(pars, sysUser.GroupId)
  813. }
  814. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  815. } else {
  816. if status != utils.COMPANY_STATUS_LOSE {
  817. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  818. //pars = append(pars, sysUser.GroupId)
  819. }
  820. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  821. }
  822. }
  823. if sysUser.Authority == 4 {
  824. if status != utils.COMPANY_STATUS_LOSE {
  825. condition += ` AND b.group_id =? `
  826. pars = append(pars, sysUser.GroupId)
  827. }
  828. permissionCondition += ` AND b.group_id=? `
  829. permissionPars = append(permissionPars, sysUser.GroupId)
  830. }
  831. }
  832. }
  833. }
  834. }
  835. }
  836. //状态控制
  837. if status != "" && status != "全部" {
  838. //switch status {
  839. //case "试用-活跃":
  840. // condition += ` AND b.status="试用" and b.view_total>= ? `
  841. // pars = append(pars, statistic_report.ActiveViewNum)
  842. //case "试用-非活跃":
  843. // condition += ` AND b.status="试用" and b.view_total < ? `
  844. // pars = append(pars, statistic_report.ActiveViewNum)
  845. //default:
  846. // condition += ` AND b.status=? `
  847. // pars = append(pars, status)
  848. //}
  849. condition += ` AND b.status=? `
  850. pars = append(pars, status)
  851. // 试用客户标签
  852. if status == "试用" && tryStage > 0 {
  853. condition += ` AND b.try_stage=? `
  854. pars = append(pars, tryStage)
  855. }
  856. }
  857. total, err := company.GetCompanyListCount(condition, pars)
  858. if err != nil {
  859. br.Msg = "获取失败"
  860. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  861. return
  862. }
  863. //
  864. sortStr := ``
  865. if !sortByTodo {
  866. if sortParam != "" && sortType != "" {
  867. if sortParam == "expireDay" {
  868. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  869. if sortType == "asc" {
  870. sortStr = " ORDER BY min_end_date"
  871. } else {
  872. sortStr = " ORDER BY max_end_date"
  873. }
  874. } else {
  875. sortStr = " ORDER BY b.end_date "
  876. }
  877. } else if sortParam == "createTime" {
  878. sortStr = " ORDER BY a.created_time "
  879. } else if sortParam == "viewTotal" {
  880. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  881. sortStr = " ORDER BY all_view_total"
  882. } else {
  883. sortStr = " ORDER BY b.view_total "
  884. }
  885. } else if sortParam == "viewTime" {
  886. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  887. if sortType == "asc" {
  888. sortStr = " ORDER BY min_last_view_time"
  889. } else {
  890. sortStr = " ORDER BY max_last_view_time"
  891. }
  892. } else {
  893. sortStr = " ORDER BY b.last_view_time "
  894. }
  895. } else if sortParam == "roadShowTotal" {
  896. sortStr = " ORDER BY b.road_show_total "
  897. } else if sortParam == "formalTime" {
  898. sortStr = " ORDER BY b.formal_time "
  899. } else if sortParam == "freezeTime" {
  900. sortStr = " ORDER BY b.freeze_time "
  901. } else if sortParam == "lossTime" {
  902. sortStr = " ORDER BY b.loss_time "
  903. } else if sortParam == "todoCreateTime" {
  904. sortStr = " ORDER BY b.todo_create_time "
  905. } else if sortParam == "todoApproveTime" {
  906. sortStr = " ORDER BY b.todo_approve_time "
  907. } else if sortParam == "tryStage" && status == "试用" {
  908. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  909. sortStr = " ORDER BY sort_try_stage asc, all_view_total desc, a.created_time desc"
  910. } else {
  911. sortStr = " ORDER BY sort_try_stage asc, b.view_total desc, a.created_time desc"
  912. }
  913. } else if sortParam == "deadline" {
  914. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  915. sortStr = " ORDER BY sort_todo_end_time asc, all_view_total desc, a.created_time desc"
  916. } else {
  917. sortStr = " ORDER BY sort_todo_end_time asc, b.view_total desc, a.created_time desc"
  918. }
  919. } else if sortParam == "tryOutDay" {
  920. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  921. sortStr = " ORDER BY all_try_out_day_total "
  922. } else {
  923. sortStr = " ORDER BY b.try_out_day_total "
  924. }
  925. } else if sortParam == "closeTime" {
  926. sortStr = " ORDER BY b.close_time "
  927. } else {
  928. br.Msg = "获取失败"
  929. br.ErrMsg = "排序字段传入数据异常:" + sortParam
  930. return
  931. }
  932. if sortParam != "tryStage" && sortParam != "deadline" {
  933. if sortType == "asc" {
  934. sortStr += " ASC "
  935. } else if sortType == "desc" {
  936. sortStr += " DESC "
  937. } else {
  938. br.Msg = "获取失败"
  939. br.ErrMsg = "排序类型传入数据异常:" + sortType
  940. return
  941. }
  942. }
  943. } else {
  944. //2、客户列表选择“全部”时,支持按照“状态和阅读数”对“全部”分类下所有客户列表进行升降序排列;选择“正式”时按照“转正时间”、选择“冻结”时按照“冻结时间”、选择“流失”时按照“流失时间”、选择“永续”时按照“创建时间”;
  945. if status == "全部" {
  946. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  947. sortStr = " ORDER BY sort_status asc, all_view_total desc, a.created_time "
  948. } else {
  949. sortStr = " ORDER BY sort_status asc, b.view_total desc, a.created_time "
  950. }
  951. } else if status == "永续" {
  952. sortStr = " ORDER BY a.created_time "
  953. } else if status == "正式" {
  954. // 正式客户默认按照周阅读活跃ASC, 同为不活跃则按照转正时间DESC
  955. sortStr = " ORDER BY week_view_active ASC, b.formal_time "
  956. //sortStr = " ORDER BY b.formal_time "
  957. } else if status == "冻结" {
  958. sortStr = " ORDER BY b.freeze_time "
  959. } else if status == "流失" {
  960. sortStr = " ORDER BY b.loss_time "
  961. } else if status == "试用" {
  962. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  963. sortStr = " ORDER BY all_view_total desc, a.created_time "
  964. } else {
  965. sortStr = " ORDER BY b.view_total desc, a.created_time "
  966. }
  967. } else if status == utils.COMPANY_STATUS_CLOSE {
  968. // 关闭客户按照关闭时间DESC
  969. sortStr = " ORDER BY b.close_time "
  970. }
  971. sortStr += " DESC "
  972. }
  973. } else {
  974. sortStr = " ORDER BY FIELD (todo_status,'未完成','已完成','无任务'), todo_modify_time DESC "
  975. }
  976. //任务状态
  977. if todoStatus != "" {
  978. //排序,筛选出的未完成、已完成客户列表排序分别按照 最近一个任务的创建时间、最近一个任务的审核时间排序;
  979. switch todoStatus {
  980. case "未完成":
  981. if sortStr != "" {
  982. sortStr += " ,b.todo_create_time desc "
  983. } else {
  984. sortStr = " ORDER BY b.todo_create_time desc "
  985. }
  986. case "已完成":
  987. if sortStr != "" {
  988. sortStr += " ,b.todo_approve_time desc "
  989. } else {
  990. sortStr = " ORDER BY b.todo_approve_time desc "
  991. }
  992. }
  993. }
  994. list, err := company.GetCompanyList(condition, status, sortStr, pars, startSize, pageSize)
  995. if err != nil {
  996. br.Msg = "获取失败"
  997. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  998. return
  999. }
  1000. //企业用户数组切片
  1001. companyIdSlice := make([]string, 0)
  1002. companyIds := make([]int, 0)
  1003. for _, v := range list {
  1004. companyIdSlice = append(companyIdSlice, strconv.Itoa(v.CompanyId))
  1005. companyIds = append(companyIds, v.CompanyId)
  1006. }
  1007. //企业用户产品开通数
  1008. companyIdStr := strings.Join(companyIdSlice, ",")
  1009. companyProductTotalList, _ := company.GetCountProductByCompanyIds(companyIdStr)
  1010. companyProductTotalMap := make(map[int]*company.CompanyProductTotalSlice)
  1011. for _, companyProductTotal := range companyProductTotalList {
  1012. companyProductTotalMap[companyProductTotal.CompanyId] = companyProductTotal
  1013. }
  1014. lenList := len(list)
  1015. //companyFiccViewTimeMap := make(map[int]time.Time)
  1016. //companyRaiViewTimeMap := make(map[int]time.Time)
  1017. //companyFiccViewTotal := make(map[int]int)
  1018. //companyRaiViewTotal := make(map[int]int)
  1019. //获取最近阅读时间 和 累计阅读次数
  1020. //if lenList > 0 {
  1021. // //ficc 或者 全品种
  1022. // if productId == 1 || productId == 0 {
  1023. // companyFiccViewTimeMap, err = services.GetFiccLastUserViewHistoryByCompanyIds(companyIdStr)
  1024. // if err != nil {
  1025. // br.Msg = "获取失败"
  1026. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1027. // return
  1028. // }
  1029. // }
  1030. //
  1031. // if productId == 2 || productId == 0 {
  1032. // companyRaiViewTimeMap, err = services.GetRaiLastUserViewHistoryByCompanyIds(companyIdStr)
  1033. // if err != nil {
  1034. // br.Msg = "获取失败"
  1035. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1036. // return
  1037. // }
  1038. // }
  1039. //
  1040. // companyFiccViewTotal, err = services.GetFiccCountUserViewHistoryByCompanyIds(companyIdStr)
  1041. // if err != nil {
  1042. // br.Msg = "获取失败"
  1043. // br.ErrMsg = "获取ficc阅读数据失败,Err:" + err.Error()
  1044. // return
  1045. // }
  1046. // companyRaiViewTotal, err = services.GetRaiCountUserViewHistoryByCompanyIds(companyIdStr)
  1047. // if err != nil {
  1048. // br.Msg = "获取失败"
  1049. // br.ErrMsg = "获取权益阅读数据失败,Err:" + err.Error()
  1050. // return
  1051. // }
  1052. //}
  1053. // 客户产品详细信息
  1054. companyProductMap := make(map[string]*company.CompanyProduct)
  1055. var companyProductCondition string
  1056. var companyProductPars []interface{}
  1057. switch companyType {
  1058. case "ficc":
  1059. companyProductCondition += ` AND product_id=? `
  1060. companyProductPars = append(companyProductPars, 1)
  1061. case "权益":
  1062. companyProductCondition += ` AND product_id=? `
  1063. companyProductPars = append(companyProductPars, 2)
  1064. default:
  1065. }
  1066. companyProductList, err := company.GetCompanyProductsByCompanyIds(companyIdStr, companyProductCondition, companyProductPars)
  1067. if err != nil {
  1068. br.Msg = "获取失败"
  1069. br.ErrMsg = "获取客户产品数据失败,Err:" + err.Error()
  1070. return
  1071. }
  1072. for _, companyProduct := range companyProductList {
  1073. key := fmt.Sprint(companyProduct.CompanyId, "_", companyProduct.ProductId)
  1074. companyProductMap[key] = companyProduct
  1075. }
  1076. //任务待办
  1077. companyTodoMap := make(map[string]*company_todo.CompanyTodo)
  1078. {
  1079. var companyTodoCondition string
  1080. var companyTodoPars []interface{}
  1081. switch companyType {
  1082. case "ficc":
  1083. companyTodoCondition += ` AND product_id=? `
  1084. companyTodoPars = append(companyTodoPars, 1)
  1085. case "权益":
  1086. companyTodoCondition += ` AND product_id=? `
  1087. companyTodoPars = append(companyTodoPars, 2)
  1088. default:
  1089. }
  1090. companyTodoList, err := company_todo.GetDoingCompanyTodoByCompanyIds(companyIdStr, companyTodoCondition, companyTodoPars)
  1091. if err != nil {
  1092. br.Msg = "获取失败"
  1093. br.ErrMsg = "获取客户产品数据失败,Err:" + err.Error()
  1094. return
  1095. }
  1096. for _, companyTodo := range companyTodoList {
  1097. key := fmt.Sprint(companyTodo.CompanyId)
  1098. companyTodoMap[key] = companyTodo
  1099. }
  1100. }
  1101. // 查询是否有服务记录
  1102. btnServiceRecordMap := make(map[int]bool)
  1103. if len(companyIds) > 0 {
  1104. serRecOB := new(company.CompanyServiceRecord)
  1105. serRecCond := ` AND company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `) AND company_type = ? `
  1106. serRecPars := make([]interface{}, 0)
  1107. serRecPars = append(serRecPars, companyIds, 2)
  1108. serRecs, e := serRecOB.GetItemsByCondition(serRecCond, serRecPars, []string{"company_service_record_id", "company_id"}, "")
  1109. if e != nil {
  1110. br.Msg = "获取失败"
  1111. br.ErrMsg = "获取客户服务记录失败, Err: " + e.Error()
  1112. return
  1113. }
  1114. for _, s := range serRecs {
  1115. btnServiceRecordMap[s.CompanyId] = true
  1116. }
  1117. }
  1118. // 查询当前销售是否有领取客户的权限
  1119. receiveEnabled, _ := services.CheckCompanyReceiveButton(sysUser.AdminId)
  1120. for i := 0; i < lenList; i++ {
  1121. item := list[i]
  1122. //校验该客户是否存在多个产品,如果是,那么代表是共享客户
  1123. if companyProductTotal, ok := companyProductTotalMap[int(item.CompanyId)]; ok {
  1124. if companyProductTotal.Total > 1 {
  1125. list[i].IsShared = true
  1126. }
  1127. }
  1128. var expireDay string
  1129. itemStatus := item.Status
  1130. item.Status = strings.Replace(item.Status, utils.COMPANY_STATUS_FOREVER, utils.COMPANY_STATUS_X_CLASS_TRY_OUT, -1) // 永续客户类型,映射成 X类试用
  1131. if itemStatus != "" {
  1132. if !strings.Contains(item.Status, "/") {
  1133. if itemStatus == utils.COMPANY_STATUS_FOREVER { //永续
  1134. expireDay = "-"
  1135. } else if itemStatus == utils.COMPANY_STATUS_TRY_OUT || itemStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  1136. if item.StartDate != "" && item.EndDate != "" {
  1137. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  1138. endDateTime = endDateTime.AddDate(0, 0, 1)
  1139. sub := endDateTime.Sub(time.Now())
  1140. if sub < 0 {
  1141. sub = 0
  1142. }
  1143. expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  1144. } else {
  1145. expireDay = "-"
  1146. }
  1147. } else if itemStatus == utils.COMPANY_STATUS_LOSE {
  1148. expireDay = "-"
  1149. } else if itemStatus == utils.COMPANY_STATUS_FREEZE {
  1150. if item.StartDate != "" && item.EndDate != "" {
  1151. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  1152. endDateTime = endDateTime.AddDate(0, 0, 0)
  1153. sub := endDateTime.Sub(time.Now())
  1154. if sub < 0 {
  1155. sub = 0
  1156. }
  1157. expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  1158. } else {
  1159. expireDay = "-"
  1160. }
  1161. } else {
  1162. expireDay = "-"
  1163. }
  1164. } else {
  1165. tmpStatusArr := strings.Split(item.Status, "/")
  1166. ficcStatus := tmpStatusArr[0]
  1167. raiStatus := tmpStatusArr[1]
  1168. var ficcEndDate, tryEndDate string
  1169. var ficcExpireDay, tryExpireDay string
  1170. if item.EndDate != "" {
  1171. endDateArr := strings.Split(item.EndDate, "/")
  1172. if len(endDateArr) == 1 {
  1173. ficcEndDate = endDateArr[0]
  1174. } else if len(endDateArr) > 1 {
  1175. ficcEndDate = endDateArr[0]
  1176. tryEndDate = endDateArr[1]
  1177. }
  1178. if ficcStatus == utils.COMPANY_STATUS_FOREVER { //永续
  1179. ficcExpireDay = "-"
  1180. } else if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  1181. if ficcEndDate != "" {
  1182. endDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
  1183. endDateTime = endDateTime.AddDate(0, 0, 1)
  1184. sub := endDateTime.Sub(time.Now())
  1185. if sub < 0 {
  1186. sub = 0
  1187. }
  1188. ficcExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  1189. } else {
  1190. ficcExpireDay = "-"
  1191. }
  1192. } else if ficcStatus == utils.COMPANY_STATUS_LOSE { //流失
  1193. ficcExpireDay = "-"
  1194. } else if ficcStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  1195. if item.StartDate != "" && item.EndDate != "" {
  1196. endDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
  1197. endDateTime = endDateTime.AddDate(0, 0, 0)
  1198. sub := endDateTime.Sub(time.Now())
  1199. if sub < 0 {
  1200. sub = 0
  1201. }
  1202. ficcExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  1203. } else {
  1204. ficcExpireDay = "-"
  1205. }
  1206. } else {
  1207. ficcExpireDay = "-"
  1208. }
  1209. if raiStatus == utils.COMPANY_STATUS_FOREVER { //永续
  1210. tryExpireDay = "-"
  1211. } else if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  1212. if tryEndDate != "" {
  1213. endDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
  1214. endDateTime = endDateTime.AddDate(0, 0, 1)
  1215. sub := endDateTime.Sub(time.Now())
  1216. if sub < 0 {
  1217. sub = 0
  1218. }
  1219. tryExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  1220. } else {
  1221. tryExpireDay = "-"
  1222. }
  1223. } else if raiStatus == utils.COMPANY_STATUS_LOSE { //流失
  1224. tryExpireDay = "-"
  1225. } else if raiStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  1226. if item.StartDate != "" && item.EndDate != "" {
  1227. endDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
  1228. endDateTime = endDateTime.AddDate(0, 0, 0)
  1229. sub := endDateTime.Sub(time.Now())
  1230. if sub < 0 {
  1231. sub = 0
  1232. }
  1233. tryExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  1234. } else {
  1235. tryExpireDay = "-"
  1236. }
  1237. } else {
  1238. tryExpireDay = "-"
  1239. }
  1240. }
  1241. expireDay = ficcExpireDay + "/" + tryExpireDay
  1242. }
  1243. }
  1244. list[i].ExpireDay = expireDay
  1245. //按钮显示控制
  1246. btnItem := new(company.ButtonPermission)
  1247. if item.CompanyId != 1 {
  1248. *btnItem = services.GetCompanyPermissionButton(roleTypeCode, itemStatus, item.SellerIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, -1, item.ShareSellerIds)
  1249. //根据销售"领取客户"的权限对部分按钮做限制
  1250. btnItem = services.GetCompanyPermissionButtonByReceiveEnabled(btnItem, receiveEnabled)
  1251. }
  1252. if list[i].IsShare == 1 && btnItem.BtnModifySeller == true && roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  1253. //如果已经是共享客户了,取消共享按钮全都显示,和修改销售权限一样
  1254. btnItem.BtnShare = true
  1255. }
  1256. if list[i].Status == utils.COMPANY_STATUS_FREEZE && list[i].CompanyType == utils.COMPANY_CLASSIFY_RAI && btnItem.BtnModifySeller == true && roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  1257. //权益冻结客户,也可以设置共享。冻结客户操作栏,增加设置共享按钮,可见权限不变(仅对权益管理员开放)
  1258. btnItem.BtnShare = true
  1259. }
  1260. list[i].BtnItem = btnItem
  1261. if item.FreezeStartDate != "" && item.FreezeEndDate != "" && item.Status == utils.COMPANY_STATUS_FREEZE {
  1262. freezeEndDate, _ := time.Parse(utils.FormatDate, item.FreezeEndDate)
  1263. if time.Now().Before(freezeEndDate) {
  1264. expireDays := freezeEndDate.Sub(time.Now()).Hours() / 24
  1265. list[i].FreezeExpireDays = int(expireDays) + 1
  1266. }
  1267. }
  1268. btnItem.BtnServiceRecord = btnServiceRecordMap[list[i].CompanyId]
  1269. // 签约未签约按钮回显展示
  1270. btnCompanyStatusItem := new(company.CompanyStatusButton)
  1271. btnCompanyStatusItem = services.GetLsitCompanyStatusButton(list[i].CompanyType, list[i].Status, list[i].SigningStatus)
  1272. list[i].CompanyStatusButton = btnCompanyStatusItem
  1273. //productIdArr := strings.Split(item.ProductIds, "/")
  1274. //// 套餐类型
  1275. //packageTypeArr := strings.Split(item.PackageTypes, "/")
  1276. //viewTotalArr := strings.Split(item.ViewTotals, "/") //总阅读次数
  1277. //lastViewTimeArr := strings.Split(item.LastViewTimes, "/") //最近阅读时间
  1278. //if len(productIdArr) > 1 {
  1279. // if len(packageTypeArr) == 1 {
  1280. // item.PackageTypes = item.PackageTypes + "/" + item.PackageTypes
  1281. // packageTypeArr = strings.Split(item.PackageTypes, "/")
  1282. // }
  1283. // //阅读次数
  1284. // if len(viewTotalArr) == 1 {
  1285. // item.ViewTotals = item.ViewTotals + "/" + item.ViewTotals
  1286. // viewTotalArr = strings.Split(item.ViewTotals, "/") //总阅读次数
  1287. // }
  1288. //
  1289. // if len(lastViewTimeArr) == 1 {
  1290. // item.LastViewTimes = item.LastViewTimes + "/" + item.LastViewTimes
  1291. // lastViewTimeArr = strings.Split(item.LastViewTimes, "/") //最近阅读时间
  1292. // }
  1293. //}
  1294. //for i, tmpProductId := range productIdArr {
  1295. // packageTypeInt, _ := strconv.Atoi(packageTypeArr[i])
  1296. // viewTotalInt, _ := strconv.Atoi(viewTotalArr[i])
  1297. // lastViewTime := lastViewTimeArr[i]
  1298. // //ficc
  1299. // if tmpProductId == "1" {
  1300. // //套餐类型
  1301. // item.FiccPackageType = packageTypeInt
  1302. //
  1303. // //总阅读次数
  1304. // item.FiccView = viewTotalInt
  1305. //
  1306. // //最近一次阅读时间
  1307. // item.FiccLastViewTime = lastViewTime
  1308. // }
  1309. // //权益
  1310. // if tmpProductId == "2" {
  1311. // //总阅读次数
  1312. // item.RaiView = viewTotalInt
  1313. //
  1314. // //最近一次阅读时间
  1315. // item.RaiLastViewTime = lastViewTime
  1316. // }
  1317. //}
  1318. ficcKey := fmt.Sprint(item.CompanyId, "_", 1)
  1319. //ficc
  1320. if tmpCompanyProduct, ok := companyProductMap[ficcKey]; ok {
  1321. //套餐类型
  1322. item.FiccPackageType = tmpCompanyProduct.PackageType
  1323. //总试用天数
  1324. item.FiccTryOutDay = tmpCompanyProduct.TryOutDayTotal
  1325. //总阅读次数
  1326. item.FiccView = tmpCompanyProduct.ViewTotal
  1327. if !tmpCompanyProduct.LastViewTime.IsZero() {
  1328. //最近一次阅读时间
  1329. item.FiccLastViewTime = tmpCompanyProduct.LastViewTime.Format(utils.FormatDateTime)
  1330. }
  1331. }
  1332. //权益
  1333. raiKey := fmt.Sprint(item.CompanyId, "_", 2)
  1334. if tmpCompanyProduct, ok := companyProductMap[raiKey]; ok {
  1335. //总阅读次数
  1336. item.RaiView = tmpCompanyProduct.ViewTotal
  1337. //总试用天数
  1338. item.RaiTryOutDay = tmpCompanyProduct.TryOutDayTotal
  1339. if !tmpCompanyProduct.LastViewTime.IsZero() {
  1340. //最近一次阅读时间
  1341. item.RaiLastViewTime = tmpCompanyProduct.LastViewTime.Format(utils.FormatDateTime)
  1342. }
  1343. }
  1344. //最近阅读时间
  1345. //if viewTime, ok := companyFiccViewTimeMap[item.CompanyId]; ok {
  1346. // item.FiccLastViewTime = viewTime.Format(utils.FormatDateTime)
  1347. //}
  1348. //
  1349. //if viewTime, ok := companyRaiViewTimeMap[item.CompanyId]; ok {
  1350. // item.RaiLastViewTime = viewTime.Format(utils.FormatDateTime)
  1351. //}
  1352. // 试用客户子标签
  1353. if strings.Contains(item.Status, "试用") {
  1354. statusSlice := strings.Split(item.Status, "/")
  1355. stageItemSlice := strings.Split(item.TryStageStr, "/")
  1356. productIdSlice := strings.Split(item.ProductIds, "/")
  1357. for sk, sv := range statusSlice {
  1358. if sv != "试用" {
  1359. continue
  1360. }
  1361. tryItem := new(company.TryStageSliceItem)
  1362. if len(productIdSlice) < (sk+1) || len(stageItemSlice) < (sk+1) {
  1363. continue
  1364. }
  1365. key := fmt.Sprint(item.CompanyId, "_", productIdSlice[sk])
  1366. if pro, ok := companyProductMap[key]; ok {
  1367. tryItem.ProductId, _ = strconv.Atoi(productIdSlice[sk])
  1368. if pro.SellerId == sysUser.AdminId { //产品销售ID和登录ID相等
  1369. tryItem.HasPermission = true
  1370. }
  1371. tryItem.TryStage, _ = strconv.Atoi(stageItemSlice[sk])
  1372. list[i].TryStageSlice = append(list[i].TryStageSlice, tryItem)
  1373. }
  1374. }
  1375. }
  1376. // To-Do任务状态为未完成的对应任务的截止日期-当前日期;
  1377. if strings.Contains(item.TodoStatuss, "未完成") {
  1378. if strings.Contains(item.TodoEndTimeStr, "/") {
  1379. edtSlice := strings.Split(item.TodoEndTimeStr, "/")
  1380. item.TodoEndTime, _ = time.ParseInLocation(utils.FormatDateTime, edtSlice[0], time.Local)
  1381. } else {
  1382. item.TodoEndTime, _ = time.ParseInLocation(utils.FormatDateTime, item.TodoEndTimeStr, time.Local)
  1383. }
  1384. tmpEndTime := item.TodoEndTime.Format(utils.FormatDate)
  1385. if tmpEndTime == "0001-01-01" {
  1386. tmpEndTime = ""
  1387. }
  1388. if tmpEndTime != "" {
  1389. dlTime1 := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 0, 0, 0, 0, time.Local)
  1390. dlTime2 := time.Date(item.TodoEndTime.Year(), item.TodoEndTime.Month(), item.TodoEndTime.Day(), 0, 0, 0, 0, time.Local)
  1391. dldays := int(dlTime2.Sub(dlTime1).Hours() / 24)
  1392. list[i].Deadline = strconv.Itoa(dldays)
  1393. }
  1394. }
  1395. }
  1396. statusCount, err := company.GetCompanyStatusCount(permissionCondition, permissionPars)
  1397. if err != nil {
  1398. br.Msg = "获取失败"
  1399. br.ErrMsg = "获取状态数量失败,Err:" + err.Error()
  1400. return
  1401. }
  1402. statusMap := make(map[string]int, 0)
  1403. var totalCount int
  1404. for _, sv := range statusCount {
  1405. sv.Status = strings.Replace(sv.Status, utils.COMPANY_STATUS_FOREVER, utils.COMPANY_STATUS_X_CLASS_TRY_OUT, -1) // 永续客户类型,映射成 X类试用
  1406. totalCount = totalCount + sv.Count
  1407. statusMap[sv.Status] = sv.Count
  1408. }
  1409. // 统计试用客户的子标签数量,只在试用状态页面统计
  1410. var tryStageCountResp []*company.CompanyTryStageCount
  1411. if status == "试用" {
  1412. tryStageCount, err := company.GetCompanyTryStageCount(permissionCondition, permissionPars)
  1413. if err != nil {
  1414. br.Msg = "获取失败"
  1415. br.ErrMsg = "获取试用状态标签数量失败,Err:" + err.Error()
  1416. return
  1417. }
  1418. tryStageMap := make(map[int]int)
  1419. for _, v := range tryStageCount {
  1420. tryStageMap[0] += v.Count
  1421. tryStageMap[v.TryStage] = v.Count
  1422. }
  1423. tryStageAllMap := map[int]string{
  1424. 0: "全部",
  1425. 2: "推进",
  1426. 3: "跟踪",
  1427. 4: "预备",
  1428. 1: "未分类",
  1429. }
  1430. for k, v := range tryStageAllMap {
  1431. item := new(company.CompanyTryStageCount)
  1432. item.TryStageStr = v
  1433. item.TryStage = k
  1434. if count, ok := tryStageMap[k]; ok {
  1435. item.Count = count
  1436. }
  1437. tryStageCountResp = append(tryStageCountResp, item)
  1438. }
  1439. }
  1440. //
  1441. ////试用-活跃
  1442. //{
  1443. // tmpPermissionCondition := permissionCondition
  1444. // tmpPermissionPars := permissionPars
  1445. // tmpPermissionCondition += ` and b.view_total>=? `
  1446. // tmpPermissionPars = append(tmpPermissionPars, statistic_report.ActiveViewNum)
  1447. //
  1448. // tryOutActiveCount, err := company.GetCompanyTryOutStatusCount(tmpPermissionCondition, tmpPermissionPars)
  1449. // if err != nil {
  1450. // br.Msg = "获取失败"
  1451. // br.ErrMsg = "获取状态数量失败,Err:" + err.Error()
  1452. // return
  1453. // }
  1454. // statusMap["试用-活跃"] = tryOutActiveCount.Count
  1455. //}
  1456. //
  1457. ////试用-非活跃
  1458. //{
  1459. // tmpPermissionCondition := permissionCondition
  1460. // tmpPermissionPars := permissionPars
  1461. // tmpPermissionCondition += ` and b.view_total <? `
  1462. // tmpPermissionPars = append(tmpPermissionPars, statistic_report.ActiveViewNum)
  1463. //
  1464. // tryOutActiveCount, err := company.GetCompanyTryOutStatusCount(tmpPermissionCondition, tmpPermissionPars)
  1465. // if err != nil {
  1466. // br.Msg = "获取失败"
  1467. // br.ErrMsg = "获取状态数量失败,Err:" + err.Error()
  1468. // return
  1469. // }
  1470. // statusMap["试用-非活跃"] = tryOutActiveCount.Count
  1471. //}
  1472. lossItem, err := company.GetCompanyStatusLoseCount(lossCondition, lossPars)
  1473. if err != nil {
  1474. br.Msg = "获取失败"
  1475. br.ErrMsg = "获取流失状态数量失败,Err:" + err.Error()
  1476. return
  1477. }
  1478. totalCount = totalCount + lossItem.Count
  1479. for _, v := range statusArr {
  1480. s := new(company.CompanyStatus)
  1481. if v == "全部" {
  1482. s.Status = "全部"
  1483. s.Count = totalCount
  1484. } else if v == utils.COMPANY_STATUS_LOSE {
  1485. s.Status = v
  1486. s.Count = lossItem.Count
  1487. } else {
  1488. s.Status = v
  1489. if val, ok := statusMap[v]; ok {
  1490. s.Count = val
  1491. }
  1492. }
  1493. statusItems = append(statusItems, s)
  1494. }
  1495. sysUserList, err := system.GetAdminList()
  1496. if err != nil {
  1497. br.Msg = "获取失败"
  1498. br.ErrMsg = "获取admin列表失败, Err:" + err.Error()
  1499. return
  1500. }
  1501. adminMap := make(map[int]*system.Admin, 0)
  1502. for _, v := range sysUserList {
  1503. adminMap[v.AdminId] = v
  1504. }
  1505. companyLists := make([]*company.CompanyListItem, 0)
  1506. //查询阅读次数
  1507. if list == nil {
  1508. companyLists = make([]*company.CompanyListItem, 0)
  1509. } else {
  1510. for _, v := range list {
  1511. //viewTotal:=GetviewTotal(v.CompanyId)
  1512. //活跃(客户状态)
  1513. //if v.IsShare != 1 {
  1514. // if v.BtnItem.BtnModifySeller == true {
  1515. // v.BtnItem.BtnModifySeller = false
  1516. // }
  1517. //}
  1518. //productIdSlice := strings.Split(v.ProductIds, "/")
  1519. //statusSlice := strings.Split(v.Status, "/")
  1520. //for productIndex, tmpProductId := range productIdSlice {
  1521. // tmpStatusIndex := 0
  1522. // if len(statusSlice) > 1 {
  1523. // tmpStatusIndex = productIndex
  1524. // }
  1525. // tmpProductStatus := statusSlice[tmpStatusIndex]
  1526. // if strings.Contains(tmpProductStatus, "试用") {
  1527. // activeType := "非活跃"
  1528. // viewNum := v.FiccView
  1529. // if tmpProductId == "2" {
  1530. // viewNum = v.RaiView
  1531. // }
  1532. // if viewNum >= statistic_report.ActiveViewNum {
  1533. // activeType = "活跃"
  1534. // }
  1535. // statusSlice[tmpStatusIndex] = fmt.Sprint(tmpProductStatus, "(", activeType, ")")
  1536. //
  1537. // tmpStatus = strings.Join(statusSlice, "/")
  1538. // }
  1539. //}
  1540. //ficcViewTotal, ok := companyFiccViewTotal[v.CompanyId]
  1541. //if !ok {
  1542. // ficcViewTotal = 0
  1543. //}
  1544. //raiViewTotal, ok := companyRaiViewTotal[v.CompanyId]
  1545. //if !ok {
  1546. // raiViewTotal = 0
  1547. //}
  1548. // 是否存在进行中的任务
  1549. var todoStatus bool
  1550. if _, ok := companyTodoMap[fmt.Sprint(v.CompanyId)]; ok {
  1551. todoStatus = true
  1552. }
  1553. //是否支持确认完成待办任务
  1554. var canConfirm bool
  1555. var hiddenConfirm bool //是否隐藏确定完成按钮
  1556. var hiddenCreate bool //是否隐藏新增/编辑按钮
  1557. hiddenConfirm = true
  1558. hiddenCreate = true
  1559. for _, vProductId := range []int{1, 2} {
  1560. ficcKey := fmt.Sprint(v.CompanyId, "_", vProductId)
  1561. //ficc
  1562. if tmpCompanyProduct, ok := companyProductMap[ficcKey]; ok {
  1563. if tmpCompanyProduct.Status != utils.COMPANY_STATUS_LOSE && tmpCompanyProduct.Status != utils.COMPANY_STATUS_CLOSE { //非流失或关闭
  1564. hiddenCreate = false
  1565. switch this.SysUser.RoleTypeCode {
  1566. case utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_RAI_ADMIN, utils.ROLE_TYPE_CODE_FICC_GROUP, utils.ROLE_TYPE_CODE_RAI_GROUP:
  1567. //部门管理员、ficc主管、权益组长
  1568. hiddenConfirm = false //不展示
  1569. if todoStatus { //有任务,需要展示
  1570. canConfirm = true
  1571. }
  1572. case utils.ROLE_TYPE_CODE_FICC_TEAM: //ficc组长
  1573. if todoStatus { //有任务,需要展示
  1574. canConfirm = true
  1575. }
  1576. if v.SellerId != this.SysUser.AdminId { //不是自己的客户
  1577. hiddenConfirm = false //展示
  1578. }
  1579. case utils.ROLE_TYPE_CODE_RAI_SELLER: //权益销售
  1580. if v.SellerId == this.SysUser.AdminId { //是自己的客户
  1581. has := services.CheckRaiApprovePermission(sysUser.AdminId) //这些个权益销售是有权限的
  1582. if has {
  1583. if todoStatus { //有任务,需要展示
  1584. canConfirm = true
  1585. }
  1586. hiddenConfirm = false //展示
  1587. }
  1588. }
  1589. }
  1590. }
  1591. }
  1592. }
  1593. todoButtonColor := `green`
  1594. //'无任务','未完成','已完成'
  1595. if strings.Contains(v.TodoStatuss, "未完成") {
  1596. todoButtonColor = "red"
  1597. } else if strings.Contains(v.TodoStatuss, "已完成") {
  1598. todoButtonColor = "green"
  1599. } else if strings.Contains(v.TodoStatuss, "无任务") {
  1600. todoButtonColor = "gray"
  1601. }
  1602. //永续客户X类试用客户出参转换
  1603. v.StatusStr = strings.Replace(v.StatusStr, utils.COMPANY_STATUS_FOREVER, utils.COMPANY_STATUS_X_CLASS_TRY_OUT, -1)
  1604. if !utils.InArrayByStr([]string{"正式", "试用", "永续", "X类试用"}, v.Status) { //不是这几种状态不做标红处理
  1605. v.IsUserMaker = 0
  1606. }
  1607. //解决共享客户正式筛选下是否标红的问题
  1608. if v.WeekViewActive == 0 && v.IsUserMaker == 1 {
  1609. v.WeekViewActive = 1
  1610. }
  1611. companyList := &company.CompanyListItem{
  1612. CompanyId: v.CompanyId,
  1613. CompanyName: v.CompanyName,
  1614. CreditCode: v.CreditCode,
  1615. CompanyCode: v.CompanyCode,
  1616. StartDate: v.StartDate,
  1617. EndDate: v.EndDate,
  1618. LoseReason: v.LoseReason,
  1619. RenewalReason: v.RenewalReason,
  1620. FreezeReason: v.FreezeReason,
  1621. LossTime: v.LossTime,
  1622. Status: v.StatusStr,
  1623. CompanyType: v.CompanyType,
  1624. ApproveStatus: v.ApproveStatus,
  1625. SellerName: v.SellerName,
  1626. SellerId: v.SellerId,
  1627. SellerIds: v.SellerIds,
  1628. ExpireDay: v.ExpireDay,
  1629. FreezeTime: v.FreezeTime,
  1630. GroupId: v.GroupId,
  1631. GroupIds: v.GroupIds,
  1632. DepartmentId: v.DepartmentId,
  1633. IndustryName: v.IndustryName,
  1634. IsSuspend: v.IsSuspend,
  1635. CreatedTime: v.CreatedTime,
  1636. Source: v.Source,
  1637. Province: v.Province,
  1638. City: v.City,
  1639. Address: v.Address,
  1640. Reasons: v.Reasons,
  1641. FreezeStartDate: v.FreezeStartDate,
  1642. FreezeEndDate: v.FreezeEndDate,
  1643. FreezeExpireDays: v.FreezeExpireDays,
  1644. BtnItem: v.BtnItem,
  1645. ProductId: v.ProductId,
  1646. FormalTime: v.FormalTime,
  1647. IsShared: v.IsShared,
  1648. RegionType: v.RegionType,
  1649. FiccPackageType: v.FiccPackageType,
  1650. FiccLastViewTime: v.FiccLastViewTime,
  1651. RaiLastViewTime: v.RaiLastViewTime,
  1652. //FiccView: viewTotal[0],
  1653. //RaiView: viewTotal[1],
  1654. //FiccView: ficcViewTotal,
  1655. //RaiView: raiViewTotal,
  1656. FiccView: v.FiccView,
  1657. RaiView: v.RaiView,
  1658. FiccTryOutDay: v.FiccTryOutDay,
  1659. RaiTryOutDay: v.RaiTryOutDay,
  1660. AllViewTotal: v.AllViewTotal,
  1661. RoadShowTotal: v.RoadShowTotal,
  1662. TodoStatus: todoStatus,
  1663. CanConfirm: canConfirm,
  1664. HiddenConfirm: hiddenConfirm,
  1665. HiddenCreate: hiddenCreate,
  1666. TodoButtonColor: todoButtonColor,
  1667. TryStageSlice: v.TryStageSlice,
  1668. Deadline: v.Deadline,
  1669. WeekViewActive: v.WeekViewActive,
  1670. IsShare: v.IsShare,
  1671. CloseTime: v.CloseTime,
  1672. CloseReason: v.CloseReason,
  1673. IsSigning: v.IsSigning,
  1674. CompanyStatusButton: v.CompanyStatusButton,
  1675. ShareSellerId: v.ShareSellerId,
  1676. ShareSellerIds: v.ShareSellerIds,
  1677. IsUserMaker: v.IsUserMaker,
  1678. }
  1679. if v.ShareSellerIds != "" {
  1680. shareSellerIds := strings.Split(v.ShareSellerIds, ",")
  1681. for _, idStr := range shareSellerIds {
  1682. shareSellerId, e := strconv.Atoi(idStr)
  1683. if e != nil {
  1684. err = e
  1685. return
  1686. }
  1687. shareSeller := adminMap[shareSellerId]
  1688. if shareSeller != nil {
  1689. companyList.ShareSeller += shareSeller.RealName + "(" + shareSeller.GroupName + ")" + "/"
  1690. }
  1691. }
  1692. companyList.ShareSeller = strings.TrimRight(companyList.ShareSeller, "/")
  1693. }
  1694. companyLists = append(companyLists, companyList)
  1695. }
  1696. }
  1697. if companyLists == nil {
  1698. companyLists = make([]*company.CompanyListItem, 0)
  1699. }
  1700. // 白嫖客户标记
  1701. scroungeList, err := company.GetScroungeCompany()
  1702. if err != nil {
  1703. br.Msg = "获取失败"
  1704. br.ErrMsg = "获取白嫖客户信息失败,Err:" + err.Error()
  1705. return
  1706. }
  1707. scroungeMap := make(map[int]int)
  1708. for _, v := range scroungeList {
  1709. scroungeMap[v.CompanyId] = 1
  1710. }
  1711. for i, v := range companyLists {
  1712. if _, ok := scroungeMap[v.CompanyId]; ok {
  1713. companyLists[i].IsScrounge = 1
  1714. }
  1715. }
  1716. page = paging.GetPaging(currentIndex, pageSize, total)
  1717. resp.List = companyLists
  1718. resp.StatusCount = statusItems
  1719. resp.TryStageCount = tryStageCountResp
  1720. resp.Paging = page
  1721. resp.AddCompanyBtn = receiveEnabled
  1722. br.Ret = 200
  1723. br.Success = true
  1724. br.Msg = "获取成功"
  1725. br.Data = resp
  1726. }
  1727. //func (this *CompanyController) ListOld() {
  1728. // br := new(models.BaseResponse).Init()
  1729. // defer func() {
  1730. // this.Data["json"] = br
  1731. // this.ServeJSON()
  1732. // }()
  1733. // sysUser := this.SysUser
  1734. // if sysUser == nil {
  1735. // br.Msg = "请登录"
  1736. // br.ErrMsg = "请登录,SysUser Is Empty"
  1737. // br.Ret = 408
  1738. // return
  1739. // }
  1740. // roleTypeCode := sysUser.RoleTypeCode
  1741. //
  1742. // pageSize, _ := this.GetInt("PageSize")
  1743. // currentIndex, _ := this.GetInt("CurrentIndex")
  1744. // status := this.GetString("Status")
  1745. // companyType := this.GetString("CompanyType")
  1746. // industryId, _ := this.GetInt("IndustryId")
  1747. // adminId := this.GetString("AdminId")
  1748. //
  1749. // chartPermissionIds := this.GetString("ChartPermissionIds")
  1750. // startDate := this.GetString("StartDate")
  1751. // endDate := this.GetString("EndDate")
  1752. // createStartDate := this.GetString("CreateStartDate")
  1753. // createEndDate := this.GetString("CreateEndDate")
  1754. // keyWord := this.GetString("KeyWord")
  1755. // keyWord = strings.Trim(keyWord, " ")
  1756. // keyWord = strings.Replace(keyWord, "'", "", -1)
  1757. //
  1758. // //排序参数
  1759. // sortParam := this.GetString("SortParam")
  1760. // sortType := this.GetString("SortType")
  1761. //
  1762. // var total int
  1763. // page := paging.GetPaging(currentIndex, pageSize, total)
  1764. // resp := new(company.CompanyListResp)
  1765. // statusItems := make([]*company.CompanyStatus, 0)
  1766. // var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}
  1767. //
  1768. // var startSize int
  1769. // if pageSize <= 0 {
  1770. // pageSize = utils.PageSize20
  1771. // }
  1772. // if currentIndex <= 0 {
  1773. // currentIndex = 1
  1774. // }
  1775. // startSize = paging.StartIndex(currentIndex, pageSize)
  1776. // var condition string
  1777. // var pars []interface{}
  1778. //
  1779. // //流失
  1780. // var lossCondition string
  1781. // var lossPars []interface{}
  1782. // //冻结
  1783. // var freezeCondition string
  1784. // var freezePars []interface{}
  1785. //
  1786. // //永续
  1787. // var forverCondition string
  1788. // var forverPars []interface{}
  1789. //
  1790. // var permissionCondition string
  1791. // var permissionPars []interface{}
  1792. //
  1793. // if status != "" && status != "全部" {
  1794. // condition += ` AND b.status=? `
  1795. // pars = append(pars, status)
  1796. //
  1797. // //permissionCondition += ` AND b.status=? `
  1798. // //permissionPars = append(permissionPars, status)
  1799. // }
  1800. // if companyType != "" {
  1801. // condition += ` AND b.product_name=? `
  1802. // pars = append(pars, companyType)
  1803. //
  1804. // lossCondition += ` AND b.product_name=? `
  1805. // lossPars = append(lossPars, companyType)
  1806. //
  1807. // freezeCondition += ` AND b.product_name=? `
  1808. // freezePars = append(freezePars, companyType)
  1809. //
  1810. // forverCondition += ` AND b.product_name=? `
  1811. // forverPars = append(forverPars, companyType)
  1812. //
  1813. // permissionCondition += ` AND b.product_name=? `
  1814. // permissionPars = append(permissionPars, companyType)
  1815. // }
  1816. //
  1817. // if industryId > 0 {
  1818. // condition += ` AND b.industry_id=? `
  1819. // pars = append(pars, industryId)
  1820. //
  1821. // lossCondition += ` AND b.industry_id=? `
  1822. // lossPars = append(lossPars, industryId)
  1823. //
  1824. // freezeCondition += ` AND b.industry_id=? `
  1825. // freezePars = append(freezePars, industryId)
  1826. //
  1827. // forverCondition += ` AND b.industry_id=? `
  1828. // forverPars = append(forverPars, industryId)
  1829. //
  1830. // permissionCondition += ` AND b.industry_id=? `
  1831. // permissionPars = append(permissionPars, industryId)
  1832. // }
  1833. //
  1834. // if adminId != "" {
  1835. // condition += ` AND b.seller_id IN (` + adminId + `) `
  1836. //
  1837. // lossCondition += ` AND b.seller_id IN (` + adminId + `) `
  1838. //
  1839. // freezeCondition += ` AND b.seller_id IN (` + adminId + `) `
  1840. //
  1841. // forverCondition += ` AND b.seller_id IN (` + adminId + `) `
  1842. //
  1843. // permissionCondition += ` AND b.seller_id IN (` + adminId + `) `
  1844. // }
  1845. //
  1846. // if startDate != "" {
  1847. // condition += ` AND b.start_date>=? `
  1848. // pars = append(pars, startDate)
  1849. //
  1850. // lossCondition += ` AND b.start_date>=? `
  1851. // lossPars = append(lossPars, startDate)
  1852. //
  1853. // freezeCondition += ` AND b.start_date>=? `
  1854. // freezePars = append(freezePars, startDate)
  1855. //
  1856. // forverCondition += ` AND b.start_date>=? `
  1857. // forverPars = append(forverPars, startDate)
  1858. //
  1859. // permissionCondition += ` AND b.start_date>=? `
  1860. // permissionPars = append(permissionPars, startDate)
  1861. // }
  1862. //
  1863. // if endDate != "" {
  1864. // condition += ` AND b.end_date<=? `
  1865. // pars = append(pars, endDate)
  1866. //
  1867. // lossCondition += ` AND b.end_date<=? `
  1868. // lossPars = append(lossPars, endDate)
  1869. //
  1870. // freezeCondition += ` AND b.end_date<=? `
  1871. // freezePars = append(freezePars, endDate)
  1872. //
  1873. // forverCondition += ` AND b.end_date<=? `
  1874. // forverPars = append(forverPars, endDate)
  1875. //
  1876. // permissionCondition += ` AND b.end_date<=? `
  1877. // permissionPars = append(permissionPars, endDate)
  1878. // }
  1879. //
  1880. // if createStartDate != "" {
  1881. // condition += ` AND a.created_time>=? `
  1882. // pars = append(pars, createStartDate)
  1883. //
  1884. // lossCondition += ` AND a.created_time>=? `
  1885. // lossPars = append(lossPars, createStartDate)
  1886. //
  1887. // freezeCondition += ` AND a.created_time>=? `
  1888. // freezePars = append(freezePars, createStartDate)
  1889. //
  1890. // forverCondition += ` AND a.created_time>=? `
  1891. // forverPars = append(forverPars, createStartDate)
  1892. //
  1893. // permissionCondition += ` AND a.created_time>=? `
  1894. // permissionPars = append(permissionPars, createStartDate)
  1895. // }
  1896. //
  1897. // if createEndDate != "" {
  1898. // condition += ` AND a.created_time<=? `
  1899. // pars = append(pars, createEndDate)
  1900. //
  1901. // lossCondition += ` AND a.created_time<=? `
  1902. // lossPars = append(lossPars, createEndDate)
  1903. //
  1904. // freezeCondition += ` AND a.created_time<=? `
  1905. // freezePars = append(freezePars, createEndDate)
  1906. //
  1907. // forverCondition += ` AND a.created_time<=? `
  1908. // forverPars = append(forverPars, createEndDate)
  1909. //
  1910. // permissionCondition += ` AND a.created_time<=? `
  1911. // permissionPars = append(permissionPars, createEndDate)
  1912. // }
  1913. //
  1914. // if keyWord != "" {
  1915. // companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
  1916. // if err != nil {
  1917. // br.Msg = "获取客户信息失败"
  1918. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1919. // return
  1920. // }
  1921. // if companyIdStr != "" {
  1922. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  1923. // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  1924. // freezeCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  1925. // forverCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  1926. //
  1927. // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  1928. // } else {
  1929. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  1930. // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  1931. // freezeCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  1932. // forverCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  1933. //
  1934. // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  1935. // }
  1936. // }
  1937. // if chartPermissionIds != "" && chartPermissionIds != "1" {
  1938. // //chartPermissionArr := strings.Split(chartPermissionIds, ",")
  1939. // //chartPermissionCount := len(chartPermissionArr)
  1940. // companyIdStr, err := company.GetCompanyListCompanyIdByPermissionIdStr(chartPermissionIds)
  1941. // if err != nil {
  1942. // br.Msg = "获取失败"
  1943. // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
  1944. // return
  1945. // }
  1946. // //var companyIdArr []string
  1947. // //for _, v := range companyIdList {
  1948. // // companyIdArr = append(companyIdArr, strconv.Itoa(v.CompanyId))
  1949. // //}
  1950. // //companyIdStr := strings.Join(companyIdArr, ",")
  1951. // if companyIdStr != "" {
  1952. // condition += ` AND a.company_id IN (` + companyIdStr + `) `
  1953. // lossCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  1954. // freezeCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  1955. // forverCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  1956. // permissionCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  1957. // } else {
  1958. // for _, v := range statusArr {
  1959. // statusCount := new(company.CompanyStatus)
  1960. // if v == "全部" {
  1961. // statusCount.Status = "全部"
  1962. // statusCount.Count = 0
  1963. // } else {
  1964. // statusCount.Status = v
  1965. // statusCount.Count = 0
  1966. // }
  1967. // statusItems = append(statusItems, statusCount)
  1968. // }
  1969. // items := make([]*company.CompanyListItem, 0)
  1970. // resp.List = items
  1971. // resp.Paging = page
  1972. // resp.StatusCount = statusItems
  1973. // br.Msg = "获取成功"
  1974. // br.Ret = 200
  1975. // br.Data = resp
  1976. // return
  1977. // }
  1978. // }
  1979. // //权限控制
  1980. // {
  1981. // fmt.Println(roleTypeCode)
  1982. // if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  1983. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  1984. // condition += ` AND b.product_id=? `
  1985. // pars = append(pars, 1)
  1986. //
  1987. // permissionCondition += ` AND b.product_id=? `
  1988. // permissionPars = append(permissionPars, 1)
  1989. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  1990. // condition += ` AND b.product_id=? `
  1991. // pars = append(pars, 2)
  1992. //
  1993. // permissionCondition += ` AND b.product_id=? `
  1994. // permissionPars = append(permissionPars, 2)
  1995. // } else {
  1996. // if sysUser.Authority <= 0 {
  1997. // if status == utils.COMPANY_STATUS_TRY_OUT || status == utils.COMPANY_STATUS_FORMAL || status == "全部" {
  1998. // if status == "全部" {
  1999. // condition += ` AND (b.seller_id=? OR status='流失' OR status='永续') `
  2000. // pars = append(pars, sysUser.AdminId)
  2001. // } else {
  2002. // condition += ` AND b.seller_id=? `
  2003. // pars = append(pars, sysUser.AdminId)
  2004. // }
  2005. // }
  2006. // permissionCondition += ` AND b.seller_id=? `
  2007. // permissionPars = append(permissionPars, sysUser.AdminId)
  2008. // } else {
  2009. // if sysUser.Authority == 1 {
  2010. // if status == utils.COMPANY_STATUS_TRY_OUT || status == utils.COMPANY_STATUS_FORMAL || status == "全部" {
  2011. // condition += ` AND b.department_id=? `
  2012. // pars = append(pars, sysUser.DepartmentId)
  2013. //
  2014. // permissionCondition += ` AND b.department_id=? `
  2015. // permissionPars = append(permissionPars, sysUser.DepartmentId)
  2016. // } else {
  2017. // permissionCondition += ` AND b.department_id=? `
  2018. // permissionPars = append(permissionPars, sysUser.DepartmentId)
  2019. // }
  2020. // }
  2021. //
  2022. // if sysUser.Authority == 2 {
  2023. // if status == utils.COMPANY_STATUS_TRY_OUT || status == utils.COMPANY_STATUS_FORMAL || status == "全部" {
  2024. // condition += ` AND b.group_id=? `
  2025. // pars = append(pars, sysUser.GroupId)
  2026. //
  2027. // permissionCondition += ` AND b.group_id=? `
  2028. // permissionPars = append(permissionPars, sysUser.GroupId)
  2029. // } else {
  2030. // permissionCondition += ` AND b.group_id=? `
  2031. // permissionPars = append(permissionPars, sysUser.GroupId)
  2032. // }
  2033. // }
  2034. // }
  2035. // }
  2036. // }
  2037. //
  2038. // //if status == utils.COMPANY_STATUS_FREEZE {
  2039. // // condition += ` AND b.seller_id=? `
  2040. // // pars = append(pars, sysUser.AdminId)
  2041. // //
  2042. // // //permissionCondition += ` AND b.seller_id=? `
  2043. // // //permissionPars = append(permissionPars, sysUser.AdminId)
  2044. // //}
  2045. // //if status == "全部" || status == utils.COMPANY_STATUS_FREEZE {
  2046. // // freezeCondition += ` AND b.seller_id=? `
  2047. // // freezePars = append(freezePars, sysUser.AdminId)
  2048. // //}
  2049. // if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  2050. // //freezeCondition += ` AND b.seller_id=? `
  2051. // //freezePars = append(freezePars, sysUser.AdminId)
  2052. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  2053. // permissionCondition += ` AND b.product_id=? `
  2054. // permissionPars = append(permissionPars, 1)
  2055. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  2056. // permissionCondition += ` AND b.product_id=? `
  2057. // permissionPars = append(permissionPars, 2)
  2058. // } else {
  2059. // if status == utils.COMPANY_STATUS_FREEZE {
  2060. // condition += ` AND b.seller_id=? `
  2061. // pars = append(pars, sysUser.AdminId)
  2062. // }
  2063. //
  2064. // freezeCondition += ` AND b.seller_id=? `
  2065. // freezePars = append(freezePars, sysUser.AdminId)
  2066. // }
  2067. // }
  2068. //
  2069. // total, err := company.GetCompanyListCount(condition, pars)
  2070. // if err != nil {
  2071. // br.Msg = "获取失败"
  2072. // br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  2073. // return
  2074. // }
  2075. //
  2076. // sortStr := ``
  2077. // if sortParam != "" && sortType != "" {
  2078. // if sortParam == "endDate" {
  2079. // sortStr = " ORDER BY b.end_date "
  2080. // } else if sortParam == "createTime" {
  2081. // sortStr = " ORDER BY a.created_time "
  2082. // } else {
  2083. // br.Msg = "获取失败"
  2084. // br.ErrMsg = "排序字段传入数据异常:" + sortParam
  2085. // return
  2086. // }
  2087. //
  2088. // if sortType == "asc" {
  2089. // sortStr += " ASC "
  2090. // } else if sortType == "desc" {
  2091. // sortStr += " DESC "
  2092. // } else {
  2093. // br.Msg = "获取失败"
  2094. // br.ErrMsg = "排序类型传入数据异常:" + sortType
  2095. // return
  2096. // }
  2097. // }
  2098. //
  2099. // list, err := company.GetCompanyList(condition, status, sortStr, pars, startSize, pageSize)
  2100. // if err != nil {
  2101. // br.Msg = "获取失败"
  2102. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  2103. // return
  2104. // }
  2105. //
  2106. //
  2107. // //企业用户数组切片
  2108. // companyIdSlice := make([]string, 0)
  2109. // for _, v := range list {
  2110. // companyIdSlice = append(companyIdSlice, strconv.Itoa(v.CompanyId))
  2111. // }
  2112. //
  2113. // //企业用户产品开通数
  2114. // companyIdStr := strings.Join(companyIdSlice, ",")
  2115. // companyProductTotalList, _ := company.GetCountProductByCompanyIds(companyIdStr)
  2116. // companyProductTotalMap := make(map[int]*company.CompanyProductTotalSlice)
  2117. // for _, companyProductTotal := range companyProductTotalList {
  2118. // companyProductTotalMap[companyProductTotal.CompanyId] = companyProductTotal
  2119. // }
  2120. // lenList := len(list)
  2121. // for i := 0; i < lenList; i++ {
  2122. // item := list[i]
  2123. //
  2124. // //校验该客户是否存在多个产品,如果是,那么代表是共享客户
  2125. // if companyProductTotal, ok := companyProductTotalMap[int(item.CompanyId)]; ok {
  2126. // if companyProductTotal.Total > 1 {
  2127. // list[i].IsShared = true
  2128. // }
  2129. // }
  2130. //
  2131. // var expireDay string
  2132. // itemStatus := item.Status
  2133. // if itemStatus != "" {
  2134. // if !strings.Contains(item.Status, "/") {
  2135. // if itemStatus == utils.COMPANY_STATUS_FOREVER { //永续
  2136. // expireDay = "-"
  2137. // } else if itemStatus == utils.COMPANY_STATUS_TRY_OUT || itemStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  2138. // if item.StartDate != "" && item.EndDate != "" {
  2139. // endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  2140. // endDateTime = endDateTime.AddDate(0, 0, 1)
  2141. // sub := endDateTime.Sub(time.Now())
  2142. // if sub < 0 {
  2143. // sub = 0
  2144. // }
  2145. // expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2146. // } else {
  2147. // expireDay = "-"
  2148. // }
  2149. // } else if itemStatus == utils.COMPANY_STATUS_LOSE {
  2150. // expireDay = "-"
  2151. // } else if itemStatus == utils.COMPANY_STATUS_FREEZE {
  2152. // if item.StartDate != "" && item.EndDate != "" {
  2153. // endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  2154. // endDateTime = endDateTime.AddDate(0, 0, 0)
  2155. // sub := endDateTime.Sub(time.Now())
  2156. // if sub < 0 {
  2157. // sub = 0
  2158. // }
  2159. // expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2160. // } else {
  2161. // expireDay = "-"
  2162. // }
  2163. // } else {
  2164. // expireDay = "-"
  2165. // }
  2166. // } else {
  2167. // statusArr := strings.Split(item.Status, "/")
  2168. // ficcStatus := statusArr[0]
  2169. // raiStatus := statusArr[1]
  2170. // var ficcEndDate, tryEndDate string
  2171. // var ficcExpireDay, tryExpireDay string
  2172. // if item.EndDate != "" {
  2173. // endDateArr := strings.Split(item.EndDate, "/")
  2174. // if len(endDateArr) == 1 {
  2175. // ficcEndDate = endDateArr[0]
  2176. // } else if len(endDateArr) > 1 {
  2177. // ficcEndDate = endDateArr[0]
  2178. // tryEndDate = endDateArr[1]
  2179. // }
  2180. // if ficcStatus == utils.COMPANY_STATUS_FOREVER { //永续
  2181. // ficcExpireDay = "-"
  2182. // } else if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  2183. // if ficcEndDate != "" {
  2184. // endDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
  2185. // endDateTime = endDateTime.AddDate(0, 0, 1)
  2186. // sub := endDateTime.Sub(time.Now())
  2187. // if sub < 0 {
  2188. // sub = 0
  2189. // }
  2190. // ficcExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2191. // } else {
  2192. // ficcExpireDay = "-"
  2193. // }
  2194. // } else if ficcStatus == utils.COMPANY_STATUS_LOSE { //流失
  2195. // ficcExpireDay = "-"
  2196. // } else if ficcStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  2197. // if item.StartDate != "" && item.EndDate != "" {
  2198. // endDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
  2199. // endDateTime = endDateTime.AddDate(0, 0, 0)
  2200. // sub := endDateTime.Sub(time.Now())
  2201. // if sub < 0 {
  2202. // sub = 0
  2203. // }
  2204. // ficcExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2205. // } else {
  2206. // ficcExpireDay = "-"
  2207. // }
  2208. // } else {
  2209. // ficcExpireDay = "-"
  2210. // }
  2211. //
  2212. // if raiStatus == utils.COMPANY_STATUS_FOREVER { //永续
  2213. // tryExpireDay = "-"
  2214. // } else if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  2215. // if tryEndDate != "" {
  2216. // endDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
  2217. // endDateTime = endDateTime.AddDate(0, 0, 1)
  2218. // sub := endDateTime.Sub(time.Now())
  2219. // if sub < 0 {
  2220. // sub = 0
  2221. // }
  2222. // tryExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2223. // } else {
  2224. // tryExpireDay = "-"
  2225. // }
  2226. // } else if raiStatus == utils.COMPANY_STATUS_LOSE { //流失
  2227. // tryExpireDay = "-"
  2228. // } else if raiStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  2229. // if item.StartDate != "" && item.EndDate != "" {
  2230. // endDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
  2231. // endDateTime = endDateTime.AddDate(0, 0, 0)
  2232. // sub := endDateTime.Sub(time.Now())
  2233. // if sub < 0 {
  2234. // sub = 0
  2235. // }
  2236. // tryExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2237. // } else {
  2238. // tryExpireDay = "-"
  2239. // }
  2240. // } else {
  2241. // tryExpireDay = "-"
  2242. // }
  2243. // }
  2244. // expireDay = ficcExpireDay + "/" + tryExpireDay
  2245. // }
  2246. // }
  2247. // list[i].ExpireDay = expireDay
  2248. //
  2249. // //按钮显示控制
  2250. // btnItem := new(company.ButtonPermission)
  2251. // if item.CompanyId != 1 {
  2252. // *btnItem = services.GetCompanyPermissionButton(roleTypeCode, itemStatus, item.GroupIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId)
  2253. // }
  2254. // list[i].BtnItem = btnItem
  2255. // if item.FreezeStartDate != "" && item.FreezeEndDate != "" && item.Status == utils.COMPANY_STATUS_FREEZE {
  2256. // freezeEndDate, _ := time.Parse(utils.FormatDate, item.FreezeEndDate)
  2257. // if time.Now().Before(freezeEndDate) {
  2258. // expireDays := freezeEndDate.Sub(time.Now()).Hours() / 24
  2259. // list[i].FreezeExpireDays = int(expireDays) + 1
  2260. // }
  2261. // }
  2262. // }
  2263. //
  2264. // statusCount, err := company.GetCompanyStatusCount(permissionCondition, permissionPars)
  2265. // if err != nil {
  2266. // br.Msg = "获取失败"
  2267. // br.ErrMsg = "获取状态数量失败,Err:" + err.Error()
  2268. // return
  2269. // }
  2270. //
  2271. // statusMap := make(map[string]int, 0)
  2272. // var totalCount int
  2273. // for _, sv := range statusCount {
  2274. // totalCount = totalCount + sv.Count
  2275. // statusMap[sv.Status] = sv.Count
  2276. // }
  2277. //
  2278. // lossItem, err := company.GetCompanyStatusLoseCount(lossCondition, lossPars)
  2279. // if err != nil {
  2280. // br.Msg = "获取失败"
  2281. // br.ErrMsg = "获取流失状态数量失败,Err:" + err.Error()
  2282. // return
  2283. // }
  2284. // totalCount = totalCount + lossItem.Count
  2285. //
  2286. // freezeItem, err := company.GetCompanyStatusFreezeCount(freezeCondition, freezePars)
  2287. // if err != nil {
  2288. // br.Msg = "获取失败"
  2289. // br.ErrMsg = "获取冻结状态数量失败,Err:" + err.Error()
  2290. // return
  2291. // }
  2292. // statusMap["冻结"] = freezeItem.Count
  2293. // totalCount = totalCount + freezeItem.Count
  2294. //
  2295. // forverItem, err := company.GetCompanyStatusForverCount(forverCondition, forverPars)
  2296. // if err != nil {
  2297. // br.Msg = "获取失败"
  2298. // br.ErrMsg = "获取永续状态数量失败,Err:" + err.Error()
  2299. // return
  2300. // }
  2301. // totalCount = totalCount + forverItem.Count
  2302. //
  2303. // for _, v := range statusArr {
  2304. // statusCount := new(company.CompanyStatus)
  2305. // if v == "全部" {
  2306. // statusCount.Status = "全部"
  2307. // statusCount.Count = totalCount
  2308. // } else if v == utils.COMPANY_STATUS_LOSE {
  2309. // statusCount.Status = v
  2310. // statusCount.Count = lossItem.Count
  2311. // } else if v == utils.COMPANY_STATUS_FOREVER {
  2312. // statusCount.Status = v
  2313. // statusCount.Count = forverItem.Count
  2314. // //} else if v == utils.COMPANY_STATUS_FREEZE {
  2315. // // statusCount.Status = v
  2316. // // statusCount.Count = freezeItem.Count
  2317. // //}
  2318. // } else {
  2319. // statusCount.Status = v
  2320. // if val, ok := statusMap[v]; ok {
  2321. // statusCount.Count = val
  2322. // }
  2323. // }
  2324. // statusItems = append(statusItems, statusCount)
  2325. // }
  2326. //
  2327. // companyLists := make([]*company.CompanyListItem, 0)
  2328. // //查询阅读次数
  2329. // if list == nil {
  2330. // companyLists = make([]*company.CompanyListItem, 0)
  2331. // } else {
  2332. // for _, v := range list {
  2333. // viewTotal := GetviewTotal(v.CompanyId)
  2334. // companyList := &company.CompanyListItem{
  2335. // CompanyId: v.CompanyId,
  2336. // CompanyName: v.CompanyName,
  2337. // CreditCode: v.CreditCode,
  2338. // CompanyCode: v.CompanyCode,
  2339. // StartDate: v.StartDate,
  2340. // EndDate: v.EndDate,
  2341. // LoseReason: v.LoseReason,
  2342. // RenewalReason: v.RenewalReason,
  2343. // FreezeReason: v.FreezeReason,
  2344. // LossTime: v.LossTime,
  2345. // Status: v.Status,
  2346. // CompanyType: v.CompanyType,
  2347. // ApproveStatus: v.ApproveStatus,
  2348. // SellerName: v.SellerName,
  2349. // SellerId: v.SellerId,
  2350. // SellerIds: v.SellerIds,
  2351. // ExpireDay: v.ExpireDay,
  2352. // FreezeTime: v.FreezeTime,
  2353. // GroupId: v.GroupId,
  2354. // GroupIds: v.GroupIds,
  2355. // DepartmentId: v.DepartmentId,
  2356. // IndustryName: v.IndustryName,
  2357. // IsSuspend: v.IsSuspend,
  2358. // CreatedTime: v.CreatedTime,
  2359. // Source: v.Source,
  2360. // Province: v.Province,
  2361. // City: v.City,
  2362. // Address: v.Address,
  2363. // Reasons: v.Reasons,
  2364. // FreezeStartDate: v.FreezeStartDate,
  2365. // FreezeEndDate: v.FreezeEndDate,
  2366. // FreezeExpireDays: v.FreezeExpireDays,
  2367. // BtnItem: v.BtnItem,
  2368. // ProductId: v.ProductId,
  2369. // FormalTime: v.FormalTime,
  2370. // IsShared: v.IsShared,
  2371. // RegionType: v.RegionType,
  2372. // FiccView: viewTotal[0],
  2373. // RaiView: viewTotal[1],
  2374. // }
  2375. // companyLists = append(companyLists, companyList)
  2376. // }
  2377. // }
  2378. // if companyLists == nil {
  2379. // companyLists = make([]*company.CompanyListItem, 0)
  2380. // }
  2381. // page = paging.GetPaging(currentIndex, pageSize, total)
  2382. // resp.List = companyLists
  2383. // resp.StatusCount = statusItems
  2384. // resp.Paging = page
  2385. // br.Ret = 200
  2386. // br.Success = true
  2387. // br.Msg = "获取成功"
  2388. // br.Data = resp
  2389. //}
  2390. func GetviewTotal(companyId int) (view []int) {
  2391. list, err := company.GetCompanyUserListById(companyId)
  2392. if err != nil {
  2393. fmt.Println("GetCompanyUserList err:", err.Error())
  2394. return
  2395. }
  2396. //获取企业客户信息
  2397. companyInfo, err := company.GetCompanyById(companyId)
  2398. if err != nil {
  2399. fmt.Println("GetCompanyById err:", err.Error())
  2400. return
  2401. }
  2402. var ficcViewTotal, cygxViewTotal int
  2403. lenList := len(list)
  2404. if lenList > 0 {
  2405. userIdSlice := make([]string, 0)
  2406. mobilesSlice := make([]string, 0)
  2407. emailsSlice := make([]string, 0)
  2408. for _, v := range list {
  2409. userIdSlice = append(userIdSlice, strconv.Itoa(int(v.UserId)))
  2410. if v.Mobile != "" {
  2411. mobilesSlice = append(mobilesSlice, v.Mobile)
  2412. } else if v.Email != "" {
  2413. emailsSlice = append(emailsSlice, v.Email)
  2414. }
  2415. }
  2416. //用户浏览数据
  2417. mobileStr := strings.Join(mobilesSlice, "','")
  2418. mobileStr = "'" + mobileStr + "'"
  2419. emailStr := strings.Join(emailsSlice, "','")
  2420. emailStr = "'" + emailStr + "'"
  2421. //报告统计删除晨报部分统计加入每日资讯 2021-4-9
  2422. //手机号
  2423. userViewMobileTotalMap := make(map[string]*models.UserViewMobileTotalSlice)
  2424. userReportViewMobileTotalMap := make(map[string]*models.ReportViewMobileRecord)
  2425. userAdvisoryViewMobileTotalMap := make(map[string]*advisory.UserViewMobileTotalSlice)
  2426. userCygxArticleHistoryRecordViewMobileTotalMap := make(map[string]*models.UserViewMobileTotalSlice)
  2427. if len(mobilesSlice) > 0 {
  2428. //权益数据
  2429. rightsItems, err := company.GetRightsReportListByMobile(mobileStr)
  2430. if err != nil {
  2431. fmt.Println("GetRightsReportListByMobile err:", err.Error())
  2432. return
  2433. }
  2434. cygxViewTotal = len(rightsItems)
  2435. //FICC数据
  2436. ficcItems, err := company.GetFiccReportListByMobile(mobileStr)
  2437. if err != nil {
  2438. fmt.Println("GetFiccReportListByMobile err:", err.Error())
  2439. return
  2440. }
  2441. ficcViewTotal = len(ficcItems)
  2442. }
  2443. //邮箱
  2444. userViewEmailTotalMap := make(map[string]*models.UserViewEmailTotalSlice)
  2445. userReportViewEmailTotalMap := make(map[string]*models.ReportViewEmailRecord)
  2446. userAdvisoryViewEmailTotalMap := make(map[string]*advisory.UserViewEmailTotalSlice)
  2447. userCygxViewEmailTotalMap := make(map[string]*models.UserViewEmailTotalSlice)
  2448. if len(emailsSlice) > 0 {
  2449. //FICC数据
  2450. ficcItems, err := company.GetFiccReportListByEmail(emailStr)
  2451. if err != nil {
  2452. fmt.Println("GetFiccReportListByEmail err:", err.Error())
  2453. return
  2454. }
  2455. ficcViewTotal += len(ficcItems)
  2456. //权益数据
  2457. rightsItems, err := company.GetRightsReportListByEmail(emailStr)
  2458. if err != nil {
  2459. fmt.Println("GetViewReportListByMobile err:", err.Error())
  2460. return
  2461. }
  2462. cygxViewTotal += len(rightsItems)
  2463. }
  2464. for i := 0; i < lenList; i++ {
  2465. item := list[i]
  2466. //企业名称
  2467. list[i].CompanyName = companyInfo.CompanyName
  2468. //手机号用户累计浏览次数
  2469. if userView, ok := userViewMobileTotalMap[item.Mobile]; ok {
  2470. list[i].ViewTotal += userView.Total
  2471. }
  2472. //邮箱用户累计浏览次数
  2473. if userView, ok := userViewEmailTotalMap[item.Email]; ok {
  2474. //总共浏览的报表数据需要调整为(手机号用户浏览晨报数+邮箱号用户浏览晨报数)
  2475. list[i].ViewTotal += userView.Total
  2476. }
  2477. if item.OpenId != "" {
  2478. list[i].IsRegister = true
  2479. } else {
  2480. if item.RegisterPlatform == 2 {
  2481. if item.Mobile != "" || item.Email != "" {
  2482. list[i].IsRegister = true
  2483. }
  2484. } else if item.RegisterTime != "" {
  2485. list[i].IsRegister = true
  2486. } else {
  2487. list[i].IsRegister = false
  2488. }
  2489. }
  2490. //如果存在手机号用户日评数据,那么需要做处理
  2491. if reportView, ok := userReportViewMobileTotalMap[item.Mobile]; ok {
  2492. //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
  2493. if reportView.LastViewTime.After(list[i].LastViewTime) {
  2494. list[i].LastViewTime = reportView.LastViewTime
  2495. list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
  2496. }
  2497. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
  2498. list[i].ViewTotal += reportView.ViewTotal
  2499. }
  2500. //如果存在手机号用户日评数据,那么需要做处理
  2501. if reportView, ok := userReportViewEmailTotalMap[item.Email]; ok {
  2502. //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
  2503. if reportView.LastViewTime.After(list[i].LastViewTime) {
  2504. list[i].LastViewTime = reportView.LastViewTime
  2505. list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
  2506. }
  2507. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
  2508. list[i].ViewTotal += reportView.ViewTotal
  2509. }
  2510. //如果存在手机号用户每日资讯,那么需要做处理
  2511. if advisoryView, ok := userAdvisoryViewMobileTotalMap[item.Mobile]; ok {
  2512. //fmt.Println("蝴蝶眨几次眼睛")
  2513. //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  2514. if advisoryView.CreatedTime.After(list[i].LastViewTime) {
  2515. list[i].LastViewTime = advisoryView.CreatedTime
  2516. list[i].LastViewTimeStr = advisoryView.CreatedTime.Format(utils.FormatDateTime)
  2517. }
  2518. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数)
  2519. list[i].ViewTotal += advisoryView.Total
  2520. }
  2521. //如果存在邮箱号用户每日资讯,那么需要做处理
  2522. if advisoryView, ok := userAdvisoryViewEmailTotalMap[item.Email]; ok {
  2523. //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  2524. if advisoryView.CreatedTime.After(list[i].LastViewTime) {
  2525. list[i].LastViewTime = advisoryView.CreatedTime
  2526. list[i].LastViewTimeStr = advisoryView.CreatedTime.Format(utils.FormatDateTime)
  2527. }
  2528. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数)
  2529. list[i].ViewTotal += advisoryView.Total
  2530. }
  2531. ficcViewTotal += list[i].ViewTotal
  2532. //如果存在手机号用户查研观向,那么需要做处理
  2533. if cygxView, ok := userCygxArticleHistoryRecordViewMobileTotalMap[item.Mobile]; ok {
  2534. //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  2535. if cygxView.CreatedTime.After(list[i].LastViewTime) {
  2536. list[i].LastViewTime = cygxView.CreatedTime
  2537. list[i].LastViewTimeStr = cygxView.CreatedTime.Format(utils.FormatDateTime)
  2538. }
  2539. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数+查研观向)
  2540. cygxViewTotal += cygxView.Total
  2541. list[i].ViewTotal += cygxView.Total
  2542. }
  2543. //如果存在邮箱号用户查研观向,那么需要做处理
  2544. if cygxView, ok := userCygxViewEmailTotalMap[item.Email]; ok {
  2545. //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  2546. if cygxView.CreatedTime.After(list[i].LastViewTime) {
  2547. list[i].LastViewTime = cygxView.CreatedTime
  2548. list[i].LastViewTimeStr = cygxView.CreatedTime.Format(utils.FormatDateTime)
  2549. }
  2550. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数+查研观向)
  2551. cygxViewTotal += cygxView.Total
  2552. //list[i].ViewTotal += cygxView.Total
  2553. }
  2554. /*if reportView, ok := userReportViewTotalMap[int(item.UserId)]; ok {
  2555. //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
  2556. if reportView.LastViewTime.After(list[i].LastViewTime) {
  2557. list[i].LastViewTime = reportView.LastViewTime
  2558. list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
  2559. }
  2560. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
  2561. list[i].ViewTotal += reportView.ViewTotal
  2562. }*/
  2563. }
  2564. }
  2565. view = append(view, ficcViewTotal)
  2566. view = append(view, cygxViewTotal)
  2567. return
  2568. }
  2569. // @Title 新增客户
  2570. // @Description 新增客户接口
  2571. // @Param request body company.CompanyAddReq true "type json string"
  2572. // @Success 200 {object} company.CompanyAddResp
  2573. // @router /add [post]
  2574. func (this *CompanyController) Add() {
  2575. br := new(models.BaseResponse).Init()
  2576. defer func() {
  2577. this.Data["json"] = br
  2578. this.ServeJSON()
  2579. }()
  2580. sysUser := this.SysUser
  2581. if sysUser == nil {
  2582. br.Msg = "请登录"
  2583. br.ErrMsg = "请登录,SysUser Is Empty"
  2584. br.Ret = 408
  2585. return
  2586. }
  2587. roleTypeCode := sysUser.RoleTypeCode
  2588. var req company.CompanyAddReq
  2589. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2590. if err != nil {
  2591. br.Msg = "参数解析异常!"
  2592. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2593. return
  2594. }
  2595. if req.CompanyName == "" {
  2596. br.Msg = "请填写客户名称"
  2597. return
  2598. }
  2599. if req.CreditCode == "" {
  2600. br.Msg = "请填写社会统一信用码"
  2601. return
  2602. }
  2603. if req.Status == "" {
  2604. br.Msg = "客户状态不可为空"
  2605. return
  2606. }
  2607. //移除空格
  2608. req.CreditCode = utils.TrimStr(req.CreditCode)
  2609. var startDateTime, endDateTime time.Time
  2610. if req.Status == utils.COMPANY_STATUS_TRY_OUT {
  2611. startDateTime = time.Now()
  2612. endDateTime = time.Now().AddDate(0, 2, 0)
  2613. } else if req.Status == utils.COMPANY_STATUS_FOREVER {
  2614. startDateTime = time.Now()
  2615. endDateTime = time.Now().AddDate(100, 0, 0)
  2616. } else {
  2617. br.Msg = "无效的客户状态,请重新选择"
  2618. return
  2619. }
  2620. var startDate, endDate string
  2621. startDate = startDateTime.Format(utils.FormatDate)
  2622. endDate = endDateTime.Format(utils.FormatDate)
  2623. if req.CompanyType == "" {
  2624. br.Msg = "请选择客户类型"
  2625. return
  2626. }
  2627. var productId int
  2628. var productName string
  2629. if req.CompanyType == utils.COMPANY_PRODUCT_FICC_NAME {
  2630. productId = utils.COMPANY_PRODUCT_FICC_ID
  2631. productName = utils.COMPANY_PRODUCT_FICC_NAME
  2632. } else if req.CompanyType == utils.COMPANY_PRODUCT_RAI_NAME {
  2633. productId = utils.COMPANY_PRODUCT_RAI_ID
  2634. productName = utils.COMPANY_PRODUCT_RAI_NAME
  2635. } else {
  2636. br.Msg = "无效的客户类型,请重新选择"
  2637. return
  2638. }
  2639. if req.IndustryId <= 0 {
  2640. br.Msg = "请选择行业"
  2641. return
  2642. }
  2643. if req.SellsId <= 0 {
  2644. br.Msg = "请选择所属销售"
  2645. return
  2646. }
  2647. //if req.Reasons == "" {
  2648. // br.Msg = "请填写新增理由"
  2649. // return
  2650. //}
  2651. if req.PermissionIds == "" {
  2652. br.Msg = "请选择权限"
  2653. return
  2654. } else {
  2655. permissionStr, err := company.GetPermissionIdById(req.PermissionIds)
  2656. if err != nil {
  2657. br.Msg = "获取信息失败"
  2658. br.ErrMsg = "获取主观客观权限信息失败,Err:" + err.Error()
  2659. return
  2660. }
  2661. req.PermissionIds = permissionStr
  2662. }
  2663. industry, err := company.GetCompanyIndustryById(req.IndustryId)
  2664. if err != nil {
  2665. br.Msg = "获取行业信息失败"
  2666. br.ErrMsg = "获取行业信息失败,Err:" + err.Error()
  2667. return
  2668. }
  2669. if industry == nil {
  2670. br.Msg = "行业信息不存在"
  2671. return
  2672. }
  2673. //判断客户是否已经存在
  2674. companyNameIsExist, err := company.GetCompanyCountByCompanyName(req.CompanyName)
  2675. if err != nil {
  2676. br.Msg = "判断客户是否存在失败"
  2677. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  2678. return
  2679. }
  2680. if companyNameIsExist > 0 {
  2681. br.Msg = "客户已存在,请重新输入客户名称"
  2682. return
  2683. }
  2684. //判断客户是否已经存在
  2685. companyCreditCodeIsExist, err := company.GetCompanyCountByCreditCode(req.CreditCode)
  2686. if err != nil {
  2687. br.Msg = "判断客户是否存在失败"
  2688. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  2689. return
  2690. }
  2691. if companyCreditCodeIsExist > 0 {
  2692. br.Msg = "客户已存在,统一社会信用代码"
  2693. return
  2694. }
  2695. seller, err := system.GetSysAdminById(req.SellsId)
  2696. if err != nil {
  2697. br.Msg = "获取销售信息失败"
  2698. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  2699. return
  2700. }
  2701. tryOutCount, err := company.GetCompanyTryOutCount(utils.COMPANY_STATUS_TRY_OUT, seller.AdminId)
  2702. if err != nil {
  2703. br.Msg = "判断试用客户量失败"
  2704. br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  2705. return
  2706. }
  2707. /*
  2708. ROLE_TYPE_CODE_ADMIN = "admin" //管理员
  2709. ROLE_TYPE_CODE_FICC_ADMIN = "ficc_admin" //ficc管理员
  2710. ROLE_TYPE_CODE_FICC_SELLER = "ficc_seller" //ficc销售
  2711. ROLE_TYPE_CODE_RAI_ADMIN = "rai_admin" //权益管理员
  2712. ROLE_TYPE_CODE_RAI_SELLER = "rai_seller" //权益销售
  2713. ROLE_TYPE_CODE_FICC_GROUP = "ficc_group" //ficc组长
  2714. ROLE_TYPE_CODE_RAI_GROUP = "rai_group" //ficc组长
  2715. ROLE_TYPE_CODE_FICC_DEPARTMENT = "ficc_department" //ficc部门经理
  2716. ROLE_TYPE_CODE_RAI_DEPARTMENT = "rai_department" //权益部门经理
  2717. ROLE_TYPE_CODE_FICC_RESEARCHR = "ficc_researcher" //ficc研究员
  2718. ROLE_TYPE_CODE_RAI_RESEARCHR = "rai_researcher" //权益研究员
  2719. */
  2720. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
  2721. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  2722. if tryOutCount >= utils.COMPANY_STATUS_TRY_OUT_COUNT {
  2723. br.Msg = "您的试用客户总数,已超过上限,不可继续新增"
  2724. return
  2725. }
  2726. }
  2727. //// 每个权益销售手中的试用客户最多30个
  2728. //if productId == utils.COMPANY_PRODUCT_RAI_ID && tryOutCount >= utils.COMPANY_STATUS_TRY_OUT_COUNT_RAI {
  2729. // br.Msg = "您的试用客户总数,已超过上限,不可继续新增"
  2730. // return
  2731. //}
  2732. //如果是权益客户,在选择非研选行业试用时,需要判断当前有多少非研选的试用客户(试用状态,且行业是非研选)
  2733. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  2734. permissionArr := strings.Split(req.PermissionIds, ",")
  2735. //如果所选行业不属于研选订阅跟研选扣点包,那就是非研选试用客户
  2736. var isNoResearch bool
  2737. for _, v := range permissionArr {
  2738. if v != strconv.Itoa(utils.CHART_PERMISSION_ID_YANXUAN) && v != strconv.Itoa(utils.YAN_XUAN_KOU_DIAN_BAO_ID) {
  2739. isNoResearch = true
  2740. continue
  2741. }
  2742. }
  2743. if isNoResearch {
  2744. tryOutCountRai, err := company.GetRaiCompanyTryOutCountNoResearch(seller.AdminId)
  2745. if err != nil {
  2746. br.Msg = "判断试用客户量失败"
  2747. br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  2748. return
  2749. }
  2750. if tryOutCountRai >= utils.COMPANY_STATUS_TRY_OUT_COUNT_RAI {
  2751. br.Msg = "非研选试用客户最多40家"
  2752. return
  2753. }
  2754. }
  2755. }
  2756. if seller == nil {
  2757. br.Msg = "所属销售不存在"
  2758. return
  2759. }
  2760. companyCode, err := company.GetCompanyCode()
  2761. if err != nil {
  2762. br.Msg = "获取客户编码信息失败"
  2763. br.ErrMsg = "获取客户编码信息失败,Err:" + err.Error()
  2764. return
  2765. }
  2766. item := new(company.Company)
  2767. item.CompanyName = req.CompanyName
  2768. item.CreditCode = req.CreditCode
  2769. item.CompanyCode = companyCode
  2770. item.Province = req.Province
  2771. item.City = req.City
  2772. item.Address = req.Province + req.City
  2773. item.StartDate = time.Now().Format(utils.FormatDate)
  2774. if req.Status == utils.COMPANY_STATUS_FOREVER {
  2775. item.EndDate = time.Now().AddDate(100, 0, 0).Format(utils.FormatDate)
  2776. item.CompanyType = 5
  2777. }
  2778. if req.Status == utils.COMPANY_STATUS_TRY_OUT {
  2779. item.EndDate = time.Now().AddDate(0, 2, 0).Format(utils.FormatDate)
  2780. item.CompanyType = 2
  2781. }
  2782. item.FirstStartDate = item.StartDate
  2783. item.FirstEndDate = item.EndDate
  2784. item.CreatedTime = time.Now()
  2785. item.LastUpdatedTime = time.Now()
  2786. item.Enabled = 1
  2787. item.RegionType = req.RegionType
  2788. item.Remark = req.Reasons
  2789. item.Nation = req.Nation
  2790. item.OverseasStatus = "试用"
  2791. item.ResetBtn = 1
  2792. companyId, err := company.AddCompany(item)
  2793. if err != nil {
  2794. br.Msg = "新增失败"
  2795. br.ErrMsg = "新增失败,err:" + err.Error()
  2796. return
  2797. }
  2798. item.CompanyId = int(companyId)
  2799. //生成第三方code编号
  2800. item.OpenCompanyCode = services.GenerateOpenCompanyCode(int(companyId))
  2801. item.Update([]string{"OpenCompanyCode"})
  2802. if req.UserId > 0 {
  2803. //修改联系人
  2804. err = company.ModifyCompanyUserCompanyId(req.UserId, int(companyId))
  2805. if err != nil {
  2806. br.Msg = "新增失败"
  2807. br.ErrMsg = "新增失败,ModifyCompanyUserCompanyId err:" + err.Error()
  2808. return
  2809. }
  2810. //获取联系人详情
  2811. userInfo, err := models.GetWxUserByUserId(req.UserId)
  2812. if err != nil {
  2813. br.Msg = "获取联系人异常!"
  2814. br.ErrMsg = "获取联系人异常,Err:" + err.Error()
  2815. return
  2816. }
  2817. //添加该联系人 与 当前销售的关系
  2818. models.AddUserSellerRelation(int64(req.UserId), int(companyId), seller.AdminId, productId, seller.RealName, userInfo.Mobile, userInfo.Email)
  2819. }
  2820. companyProduct := new(company.CompanyProduct)
  2821. companyProduct.CompanyId = int(companyId)
  2822. companyProduct.ProductId = productId
  2823. companyProduct.ProductName = productName
  2824. companyProduct.CompanyName = req.CompanyName
  2825. companyProduct.Source = req.Source
  2826. companyProduct.Reasons = req.Reasons
  2827. companyProduct.Status = req.Status
  2828. companyProduct.StartDate = startDate
  2829. companyProduct.EndDate = endDate
  2830. companyProduct.IndustryId = req.IndustryId
  2831. companyProduct.IndustryName = industry.IndustryName
  2832. companyProduct.SellerId = seller.AdminId
  2833. companyProduct.SellerName = seller.RealName
  2834. companyProduct.GroupId = seller.GroupId
  2835. companyProduct.DepartmentId = seller.DepartmentId
  2836. companyProduct.IsSuspend = 0
  2837. companyProduct.CreateTime = time.Now()
  2838. companyProduct.ModifyTime = time.Now()
  2839. companyProduct.CompanyType = req.CompanyType
  2840. companyProduct.Scale = req.Scale
  2841. companyProduct.OpenCode = services.GenerateOpenCompanyProductCode(int(companyId), productId)
  2842. companyProduct.TodoStatus = "无任务"
  2843. companyProduct.TryStage = 1
  2844. companyProduct.OverseasLabel = 1
  2845. if seller.Mobile == "13065778668" {
  2846. if req.RegionType == "海外" {
  2847. companyProduct.IsOverseas = 0
  2848. } else {
  2849. companyProduct.IsOverseas = 1
  2850. }
  2851. }
  2852. if productId == utils.COMPANY_PRODUCT_RAI_ID && req.Status == utils.COMPANY_STATUS_FOREVER { // 权益的永续客户给一个状态初始化的记录
  2853. companyProduct.InitStatus = req.Status
  2854. }
  2855. companyProduct.SellerIdInit = seller.AdminId
  2856. companyProduct.SellerNameInit = seller.RealName
  2857. companyProductId, err := company.AddCompanyProduct(companyProduct)
  2858. if err != nil {
  2859. br.Msg = "新增失败"
  2860. br.ErrMsg = "新增客户产品失败,err:" + err.Error()
  2861. return
  2862. }
  2863. companyReportPermissionList, err := services.AddCompanyPermission(int(companyId), seller.AdminId, productId, productName, seller.RealName, req.PermissionIds, startDate, endDate)
  2864. if err != nil {
  2865. br.Msg = "新增失败"
  2866. br.ErrMsg = "新增客户设置权限失败,err:" + err.Error()
  2867. return
  2868. }
  2869. {
  2870. record := new(company.CompanyOperationRecord)
  2871. record.CompanyId = int(companyId)
  2872. record.CompanyName = req.CompanyName
  2873. record.SellerId = seller.AdminId
  2874. record.SysUserId = seller.AdminId
  2875. record.SysRealName = seller.RealName
  2876. record.Remark = "新增客户"
  2877. record.Operation = "add"
  2878. record.CreateTime = time.Now()
  2879. record.ProductId = productId
  2880. record.ProductName = productName
  2881. record.Status = req.Status
  2882. _, err = company.AddCompanyOperationRecord(record)
  2883. if err != nil {
  2884. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  2885. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  2886. }
  2887. }
  2888. //新增客户日志
  2889. {
  2890. companyLog := new(company.CompanyLog)
  2891. companyLog.CompanyId = int(companyId)
  2892. companyLog.CompanyName = req.CompanyName
  2893. companyLog.CreditCode = req.CreditCode
  2894. companyLog.CompanyCode = companyCode
  2895. companyLog.Sort = item.Sort
  2896. companyLog.IsFeeCustomer = item.IsFeeCustomer
  2897. companyLog.Country = item.Country
  2898. companyLog.Address = item.Address
  2899. companyLog.City = item.City
  2900. companyLog.Province = item.Province
  2901. companyLog.Enabled = item.Enabled
  2902. companyLog.CreatedTime = item.CreatedTime
  2903. companyLog.LastUpdatedTime = item.LastUpdatedTime
  2904. companyLog.Seller = item.Seller
  2905. companyLog.SellsId = item.SellsId
  2906. companyLog.CompanyBelong = item.CompanyBelong
  2907. companyLog.StartDate = item.StartDate
  2908. companyLog.EndDate = item.EndDate
  2909. companyLog.FirstStartDate = item.FirstStartDate
  2910. companyLog.FirstEndDate = item.FirstEndDate
  2911. companyLog.DateType = item.DateType
  2912. companyLog.AdminId = this.SysUser.AdminId
  2913. companyLog.LogType = "add"
  2914. companyLog.LogCreateTime = time.Now()
  2915. go company.AddCompanyLog(companyLog)
  2916. }
  2917. //新增客户产品日志
  2918. {
  2919. productLog := new(company.CompanyProductLog)
  2920. productLog.CompanyProductId = int(companyProductId)
  2921. productLog.CompanyId = companyProduct.CompanyId
  2922. productLog.ProductId = companyProduct.ProductId
  2923. productLog.ProductName = companyProduct.ProductName
  2924. productLog.CompanyName = companyProduct.CompanyName
  2925. productLog.CompanyName = companyProduct.CompanyName
  2926. productLog.Source = companyProduct.Source
  2927. productLog.Reasons = companyProduct.Reasons
  2928. productLog.Status = companyProduct.Status
  2929. productLog.IndustryId = companyProduct.IndustryId
  2930. productLog.IndustryName = companyProduct.IndustryName
  2931. productLog.SellerId = companyProduct.SellerId
  2932. productLog.SellerName = companyProduct.SellerName
  2933. productLog.GroupId = companyProduct.GroupId
  2934. productLog.DepartmentId = companyProduct.DepartmentId
  2935. productLog.IsSuspend = companyProduct.IsSuspend
  2936. productLog.SuspendTime = companyProduct.SuspendTime
  2937. productLog.ApproveStatus = companyProduct.ApproveStatus
  2938. productLog.FreezeTime = companyProduct.FreezeTime
  2939. productLog.Remark = companyProduct.Remark
  2940. productLog.StartDate = companyProduct.StartDate
  2941. productLog.EndDate = companyProduct.EndDate
  2942. productLog.CreateTime = companyProduct.CreateTime
  2943. productLog.ModifyTime = companyProduct.ModifyTime
  2944. productLog.LoseReason = companyProduct.LoseReason
  2945. productLog.LossTime = companyProduct.LossTime
  2946. productLog.LogType = "add"
  2947. productLog.LogCreateTime = time.Now()
  2948. productLog.AdminId = this.SysUser.AdminId
  2949. productLog.Scale = companyProduct.Scale
  2950. go company.AddCompanyProductLog(productLog)
  2951. }
  2952. //新增客户产品状态变更日志
  2953. {
  2954. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  2955. Id: 0,
  2956. CompanyId: companyProduct.CompanyId,
  2957. ProductId: companyProduct.ProductId,
  2958. Status: "试用",
  2959. Source: "add",
  2960. SellerId: companyProduct.SellerId,
  2961. SellerName: companyProduct.SellerName,
  2962. StartDate: startDateTime,
  2963. EndDate: endDateTime,
  2964. RealEndDate: startDateTime,
  2965. CreateTime: time.Now(),
  2966. }
  2967. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  2968. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  2969. Id: 0,
  2970. CompanyId: companyProduct.CompanyId,
  2971. ProductId: companyProduct.ProductId,
  2972. Source: "add",
  2973. SellerId: companyProduct.SellerId,
  2974. SellerName: companyProduct.SellerName,
  2975. StartDate: startDateTime,
  2976. EndDate: endDateTime,
  2977. RealEndDate: startDateTime,
  2978. IsStop: 0,
  2979. CreateTime: time.Now(),
  2980. }
  2981. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  2982. }
  2983. resp := new(company.CompanyAddResp)
  2984. resp.CompanyId = int(companyId)
  2985. br.Ret = 200
  2986. br.Success = true
  2987. br.Msg = "新增成功"
  2988. br.Data = resp
  2989. }
  2990. // Detail
  2991. // @Title 获取客户详情
  2992. // @Description 获取客户详情接口
  2993. // @Param CompanyId query int true "客户id"
  2994. // @Success 200 {object} company.CompanyDetailResp
  2995. // @router /detail [get]
  2996. func (this *CompanyController) Detail() {
  2997. br := new(models.BaseResponse).Init()
  2998. defer func() {
  2999. this.Data["json"] = br
  3000. this.ServeJSON()
  3001. }()
  3002. sysUser := this.SysUser
  3003. if sysUser == nil {
  3004. br.Msg = "请登录"
  3005. br.ErrMsg = "请登录,SysUser Is Empty"
  3006. br.Ret = 408
  3007. return
  3008. }
  3009. companyId, _ := this.GetInt("CompanyId")
  3010. if companyId <= 0 {
  3011. br.Msg = "参数错误"
  3012. br.ErrMsg = "客户参数小于等于0"
  3013. return
  3014. }
  3015. // CRM8.8-是否为编辑页的客户详情
  3016. isEdit, _ := this.GetBool("IsEdit")
  3017. productId := services.GetProductId(sysUser.RoleTypeCode)
  3018. item, err := company.GetCompanyDetailById(companyId)
  3019. if err != nil {
  3020. br.Msg = "获取信息失败"
  3021. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  3022. return
  3023. }
  3024. shareSellerId := 0
  3025. shareGroupId := 0
  3026. var productItem *company.CompanyProduct
  3027. if productId > 0 {
  3028. var e error
  3029. productItem, e = company.GetCompanyProductByCompanyIdAndProductId(companyId, productId)
  3030. if e != nil && e.Error() != utils.ErrNoRow() {
  3031. br.Msg = "客户信息有误"
  3032. br.ErrMsg = "获取客户信息失败, Err: " + e.Error()
  3033. return
  3034. }
  3035. if productItem != nil {
  3036. shareSellerId = productItem.ShareSellerId
  3037. shareGroupId = productItem.ShareGroupId
  3038. }
  3039. }
  3040. var productName string
  3041. if productId == 1 {
  3042. productName = utils.COMPANY_PRODUCT_FICC_NAME
  3043. } else if productId == 2 {
  3044. productName = utils.COMPANY_PRODUCT_RAI_NAME
  3045. } else {
  3046. productName = "admin"
  3047. }
  3048. resp := new(company.CompanyDetailResp)
  3049. resp.ProductName = productName
  3050. //获取客户产品
  3051. productList, err := company.GetCompanyProductsByCompanyId(companyId)
  3052. if err != nil {
  3053. br.Msg = "获取信息失败"
  3054. br.ErrMsg = "获取产品信息失败,Err:" + err.Error()
  3055. return
  3056. }
  3057. roleTypeCode := sysUser.RoleTypeCode
  3058. itemLen := len(productList)
  3059. btnDetailItem := new(company.ButtonDetailPermission)
  3060. // 客户权限校验
  3061. {
  3062. // 如果不是超管、ficc管理员、权益管理员,那么需要额外校验下权限
  3063. if !utils.InArrayByStr([]string{utils.ROLE_TYPE_CODE_ADMIN, utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_RAI_ADMIN}, sysUser.RoleTypeCode) {
  3064. var isOk bool //是否有权限
  3065. var companyHasProduct bool // 客户当前是否有该产品权限
  3066. for _, productInfo := range productList {
  3067. // 只校验拥有的品种权限:ficc或者权益
  3068. if productInfo.ProductId == productId {
  3069. companyHasProduct = true
  3070. // 自己的客户有权限看
  3071. if productInfo.SellerId == sysUser.AdminId {
  3072. isOk = true
  3073. break
  3074. }
  3075. // 流失客户都有权限看
  3076. if productInfo.Status == utils.COMPANY_STATUS_LOSE || productInfo.Status == utils.COMPANY_STATUS_CLOSE {
  3077. isOk = true
  3078. break
  3079. }
  3080. // 分享的客户 也有权限
  3081. if productItem.IsShare == 1 && productItem.ShareSellerId == sysUser.AdminId {
  3082. isOk = true
  3083. break
  3084. }
  3085. // 分享的客户的组长 也有权限
  3086. if productItem.IsShare == 1 && productItem.ShareGroupId == sysUser.GroupId {
  3087. isOk = true
  3088. break
  3089. }
  3090. // 如果是组长,且该客户属于本组客户
  3091. if sysUser.Authority == 4 && productInfo.GroupId > 0 && productInfo.GroupId == sysUser.GroupId && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM {
  3092. isOk = true
  3093. break
  3094. }
  3095. // 如果是ficc主管或者权益主管
  3096. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  3097. // 获取顶级分组Id
  3098. var sysUserGroupPid, productGroupPid int
  3099. // 当前账号的顶级分组id
  3100. {
  3101. sysUserGroupIdpid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  3102. if err != nil && err.Error() != utils.NotEmpty() {
  3103. break
  3104. }
  3105. if sysUserGroupIdpid == nil || *sysUserGroupIdpid == 0 {
  3106. sysUserGroupPid = sysUser.GroupId
  3107. } else {
  3108. sysUserGroupPid = *sysUserGroupIdpid
  3109. }
  3110. }
  3111. // 当前客户的顶级分组id
  3112. {
  3113. groupIdpid, err := company.GetParentIdFromGroup(productInfo.GroupId)
  3114. if err != nil && err.Error() != utils.NotEmpty() {
  3115. break
  3116. }
  3117. if groupIdpid == nil || *groupIdpid == 0 {
  3118. productGroupPid = productInfo.GroupId
  3119. } else {
  3120. productGroupPid = *groupIdpid
  3121. }
  3122. }
  3123. // 如果客户的顶级分组和当前账号分组id一致
  3124. if sysUserGroupPid == productGroupPid {
  3125. isOk = true
  3126. break
  3127. }
  3128. }
  3129. }
  3130. }
  3131. // 客户当前是否有该产品的权限,如果没有的话,说明是在领取客户,允许访问
  3132. if !companyHasProduct {
  3133. isOk = true
  3134. }
  3135. if !isOk {
  3136. br.Msg = "无访问权限"
  3137. return
  3138. }
  3139. }
  3140. }
  3141. //产品权限map
  3142. statusMap := make(map[int]string)
  3143. for i := 0; i < itemLen; i++ {
  3144. item := productList[i]
  3145. //添加产品权限map
  3146. statusMap[item.ProductId] = item.Status
  3147. if i == 0 {
  3148. if item.ProductId == 1 {
  3149. resp.CreateAuth = 1
  3150. } else {
  3151. resp.CreateAuth = 2
  3152. }
  3153. }
  3154. if item.ProductId == 1 {
  3155. if strings.Contains(sysUser.RoleTypeCode, "ficc") {
  3156. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  3157. btnDetailItem.BtnHistoryList = true
  3158. } else {
  3159. if item.SellerId == sysUser.AdminId || shareSellerId == sysUser.AdminId || shareGroupId == sysUser.GroupId {
  3160. btnDetailItem.BtnHistoryList = true
  3161. }
  3162. if sysUser.Authority > 0 {
  3163. if item.GroupId == sysUser.GroupId {
  3164. btnDetailItem.BtnHistoryList = true
  3165. }
  3166. if item.DepartmentId == sysUser.DepartmentId {
  3167. btnDetailItem.BtnHistoryList = true
  3168. }
  3169. }
  3170. }
  3171. }
  3172. // 编辑回显
  3173. allPermissions, e := company.GetPermissionLookItemsByProductId(utils.COMPANY_PRODUCT_FICC_ID)
  3174. if e != nil {
  3175. br.Msg = "获取失败"
  3176. br.ErrMsg = "获取权限信息失败,Err:" + e.Error()
  3177. return
  3178. }
  3179. permissionMap := make(map[int][]*company.PermissionLookItem, 0)
  3180. permissionCheckMap := make(map[int][]int, 0)
  3181. for _, v := range allPermissions {
  3182. if v.ParentId > 0 {
  3183. permissionMap[v.ParentId] = append(permissionMap[v.ParentId], v)
  3184. if v.IsPublic == 1 {
  3185. permissionCheckMap[v.ParentId] = append(permissionCheckMap[v.ParentId], v.ChartPermissionId)
  3186. }
  3187. }
  3188. }
  3189. for _, v := range allPermissions {
  3190. if v.ParentId == 0 {
  3191. checkList := make([]int, 0)
  3192. plist := new(company.PermissionLookList)
  3193. plist.Items = make([]*company.PermissionLookItem, 0)
  3194. plist.ItemsType = make([]*company.PermissionSetItemType, 0)
  3195. items, ok := permissionMap[v.ChartPermissionId]
  3196. if ok {
  3197. for itemK, n := range items {
  3198. permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  3199. if err != nil && err.Error() != utils.ErrNoRow() {
  3200. br.Msg = "获取失败"
  3201. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3202. return
  3203. }
  3204. if permission != nil && permission.ChartPermissionId > 0 {
  3205. checkList = append(checkList, n.ChartPermissionId)
  3206. items[itemK].StartDate = permission.StartDate
  3207. items[itemK].EndDate = permission.EndDate
  3208. items[itemK].Status = permission.Status
  3209. endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
  3210. endDateTime = endDateTime.AddDate(0, 0, 1)
  3211. sub := endDateTime.Sub(time.Now())
  3212. if sub < 0 {
  3213. sub = 0
  3214. }
  3215. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  3216. items[itemK].ExpireDay = expireDay
  3217. }
  3218. }
  3219. plist.Items = items
  3220. }
  3221. plist.ClassifyName = v.PermissionName
  3222. plist.CheckList = checkList
  3223. item.PermissionList = append(item.PermissionList, plist)
  3224. }
  3225. }
  3226. resp.FiccItem = item
  3227. if resp.FiccItem.Status == utils.COMPANY_STATUS_FOREVER {
  3228. resp.FiccItem.Status = utils.COMPANY_STATUS_X_CLASS_TRY_OUT
  3229. }
  3230. if (roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  3231. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT) &&
  3232. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3233. resp.IsButtonShow = 1
  3234. }
  3235. } else {
  3236. if strings.Contains(sysUser.RoleTypeCode, "rai") {
  3237. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  3238. btnDetailItem.BtnHistoryList = true
  3239. } else {
  3240. if item.SellerId == sysUser.AdminId || item.ShareSellerId == sysUser.AdminId || shareGroupId == sysUser.GroupId {
  3241. btnDetailItem.BtnHistoryList = true
  3242. }
  3243. if sysUser.Authority > 0 {
  3244. if item.GroupId == sysUser.GroupId {
  3245. btnDetailItem.BtnHistoryList = true
  3246. }
  3247. if item.DepartmentId == sysUser.DepartmentId {
  3248. btnDetailItem.BtnHistoryList = true
  3249. }
  3250. }
  3251. }
  3252. }
  3253. // CRM8.8-权益权限列表调用较多、统一进行调整
  3254. plist, e := services.RaiCompanyPermissionAndCheckList(companyId, isEdit, []string{"调研"})
  3255. if e != nil {
  3256. br.Msg = "获取客户权益权限列表信息失败"
  3257. br.ErrMsg = "获取客户权益权限列表信息失败,Err:" + e.Error()
  3258. return
  3259. }
  3260. // cygx8.2专项产业调研展示
  3261. item.SpecialSurplus, err = cygxService.GetSpecialSurplusByCompanyNew(companyId)
  3262. if err != nil {
  3263. br.Msg = "获取失败"
  3264. br.ErrMsg = "获取专项调研信息失败,Err:" + err.Error()
  3265. return
  3266. }
  3267. //研选服务点数
  3268. item.Points = cygxService.GetCygxActivityPointsCompanyByCompanyId(companyId)
  3269. item.PermissionList = append(item.PermissionList, plist)
  3270. resp.RaiItem = item
  3271. if resp.RaiItem.Status == utils.COMPANY_STATUS_FOREVER {
  3272. resp.RaiItem.Status = utils.COMPANY_STATUS_X_CLASS_TRY_OUT
  3273. }
  3274. if (roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  3275. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  3276. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT) &&
  3277. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3278. resp.IsButtonShow = 1
  3279. }
  3280. }
  3281. btnItem := services.GetCompanyPermissionButton(roleTypeCode, item.Status, strconv.Itoa(item.SellerId), strconv.Itoa(item.GroupId), item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, shareSellerId, "")
  3282. //if itemLen > 1 {
  3283. // btnDetailItem.BtnEdit = false
  3284. // btnDetailItem.BtnDelete = false
  3285. //} else {
  3286. // btnDetailItem.BtnEdit = btnItem.BtnEdit
  3287. // btnDetailItem.BtnDelete = btnItem.BtnDelete
  3288. //}
  3289. switch item.ProductId {
  3290. case 1:
  3291. btnDetailItem.FiccEdit = btnItem.BtnEdit
  3292. btnDetailItem.FiccDelete = btnItem.BtnDelete
  3293. case 2:
  3294. btnDetailItem.RaiEdit = btnItem.BtnEdit
  3295. btnDetailItem.RaiDelete = btnItem.BtnDelete
  3296. }
  3297. if !btnDetailItem.BtnEdit {
  3298. btnDetailItem.BtnEdit = btnItem.BtnEdit
  3299. }
  3300. if !btnDetailItem.BtnDelete {
  3301. btnDetailItem.BtnDelete = btnItem.BtnDelete
  3302. }
  3303. //联系人操作权限
  3304. if resp.IsContractButtonShow == false {
  3305. resp.IsContractButtonShow = services.CheckCompanyUserButton(sysUser.RoleTypeCode, item.SellerId, sysUser.AdminId, item.ProductId, shareSellerId, item.Status)
  3306. }
  3307. //校验当前操作员是否具给联系人开通个人研选的权限
  3308. if resp.IsUserYanXuanButtonShow == false {
  3309. resp.IsUserYanXuanButtonShow, err = services.CheckCompanyUserYanXuanButton(sysUser.RoleTypeCode, sysUser.Mobile)
  3310. if err != nil {
  3311. br.Msg = "获取失败"
  3312. br.ErrMsg = "获取专项调研信息失败,Err:" + err.Error()
  3313. return
  3314. }
  3315. }
  3316. }
  3317. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  3318. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  3319. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  3320. resp.IsButtonShow = 1
  3321. btnDetailItem.BtnHistoryList = true
  3322. }
  3323. //ficc权限
  3324. if ficcStatus, ok := statusMap[1]; ok {
  3325. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT {
  3326. if raiStatus, ok := statusMap[2]; ok {
  3327. //另一个权限也是 试用 、冻结、流失
  3328. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3329. //那么超管、部门管理员、销售可以编辑
  3330. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3331. btnDetailItem.BaseInfoEdit = true
  3332. }
  3333. }
  3334. //权益是永续时,超管可编辑基础信息
  3335. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3336. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3337. btnDetailItem.BaseInfoEdit = true
  3338. }
  3339. }
  3340. } else {
  3341. //权限未开,有编辑基础信息权限
  3342. btnDetailItem.BaseInfoEdit = true
  3343. }
  3344. }
  3345. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3346. if raiStatus, ok := statusMap[2]; ok {
  3347. //另一个权限也是 永续 、冻结、流失
  3348. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FOREVER || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3349. //超管可编辑基础信息
  3350. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3351. btnDetailItem.BaseInfoEdit = true
  3352. }
  3353. }
  3354. } else {
  3355. //权限未开,有编辑基础信息权限
  3356. btnDetailItem.BaseInfoEdit = true
  3357. }
  3358. }
  3359. }
  3360. //权益销售
  3361. if raiStatus, ok := statusMap[2]; ok {
  3362. if raiStatus == utils.COMPANY_STATUS_TRY_OUT {
  3363. if ficcStatus, ok := statusMap[1]; ok {
  3364. //另一个权限也是 试用 、冻结、流失
  3365. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3366. //那么超管、部门管理员、销售可以编辑
  3367. if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3368. btnDetailItem.BaseInfoEdit = true
  3369. }
  3370. }
  3371. //ficc是永续时,超管可编辑基础信息
  3372. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3373. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3374. btnDetailItem.BaseInfoEdit = true
  3375. }
  3376. }
  3377. } else {
  3378. //权限未开,有编辑基础信息权限
  3379. btnDetailItem.BaseInfoEdit = true
  3380. }
  3381. }
  3382. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3383. if ficcStatus, ok := statusMap[1]; ok {
  3384. //另一个权限也是 试用、永续 、冻结、流失
  3385. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FOREVER || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3386. //超管可编辑基础信息
  3387. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3388. btnDetailItem.BaseInfoEdit = true
  3389. }
  3390. }
  3391. } else {
  3392. //权限未开,有编辑基础信息权限
  3393. btnDetailItem.BaseInfoEdit = true
  3394. }
  3395. }
  3396. }
  3397. // 白嫖客户标记
  3398. scroungeList, err := company.GetScroungeCompany()
  3399. if err != nil {
  3400. br.Msg = "获取失败"
  3401. br.ErrMsg = "获取白嫖客户信息失败,Err:" + err.Error()
  3402. return
  3403. }
  3404. scroungeMap := make(map[int]int)
  3405. for _, v := range scroungeList {
  3406. scroungeMap[v.CompanyId] = 1
  3407. }
  3408. if _, ok := scroungeMap[item.CompanyId]; ok {
  3409. item.IsScrounge = 1
  3410. }
  3411. resp.Item = item
  3412. resp.BtnItem = btnDetailItem
  3413. br.Ret = 200
  3414. br.Success = true
  3415. br.Msg = "获取成功"
  3416. br.Data = resp
  3417. }
  3418. // DetailByCreditCode
  3419. // @Title 根据社会信用码获取客户详情
  3420. // @Description 根据社会信用码获取客户详情接口
  3421. // @Param CreditCode query string true "客户社会信用码"
  3422. // @Success 200 {object} company.CompanyDetailResp
  3423. // @router /detail_by_credit_code [get]
  3424. func (this *CompanyController) DetailByCreditCode() {
  3425. br := new(models.BaseResponse).Init()
  3426. defer func() {
  3427. this.Data["json"] = br
  3428. this.ServeJSON()
  3429. }()
  3430. sysUser := this.SysUser
  3431. if sysUser == nil {
  3432. br.Msg = "请登录"
  3433. br.ErrMsg = "请登录,SysUser Is Empty"
  3434. br.Ret = 408
  3435. return
  3436. }
  3437. resp := new(company.CompanyDetailResp)
  3438. creditCode := this.GetString("CreditCode")
  3439. if creditCode == "" {
  3440. br.Msg = "参数错误"
  3441. br.ErrMsg = "社会信用码必传"
  3442. return
  3443. }
  3444. item, err := company.GetCompanyDetailByCreditCode(creditCode)
  3445. if err != nil {
  3446. br.Ret = 200
  3447. br.Success = true
  3448. br.Msg = "获取成功"
  3449. br.Data = resp
  3450. return
  3451. }
  3452. companyId := item.CompanyId
  3453. var productName string
  3454. productId := services.GetProductId(sysUser.RoleTypeCode)
  3455. if productId == 1 {
  3456. productName = utils.COMPANY_PRODUCT_FICC_NAME
  3457. } else if productId == 2 {
  3458. productName = utils.COMPANY_PRODUCT_RAI_NAME
  3459. } else {
  3460. productName = "admin"
  3461. }
  3462. resp.ProductName = productName
  3463. //获取客户产品
  3464. productList, err := company.GetCompanyProductsByCompanyId(companyId)
  3465. if err != nil {
  3466. br.Msg = "获取信息失败"
  3467. br.ErrMsg = "获取产品信息失败,Err:" + err.Error()
  3468. return
  3469. }
  3470. roleTypeCode := sysUser.RoleTypeCode
  3471. itemLen := len(productList)
  3472. btnDetailItem := new(company.ButtonDetailPermission)
  3473. //产品权限map
  3474. statusMap := make(map[int]string)
  3475. for i := 0; i < itemLen; i++ {
  3476. item := productList[i]
  3477. //添加产品权限map
  3478. statusMap[item.ProductId] = item.Status
  3479. if i == 0 {
  3480. if item.ProductId == 1 {
  3481. resp.CreateAuth = 1
  3482. } else {
  3483. resp.CreateAuth = 2
  3484. }
  3485. }
  3486. if item.ProductId == 1 {
  3487. if strings.Contains(sysUser.RoleTypeCode, "ficc") {
  3488. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  3489. btnDetailItem.BtnHistoryList = true
  3490. } else {
  3491. if item.SellerId == sysUser.AdminId {
  3492. btnDetailItem.BtnHistoryList = true
  3493. }
  3494. if sysUser.Authority > 0 {
  3495. if item.GroupId == sysUser.GroupId {
  3496. btnDetailItem.BtnHistoryList = true
  3497. }
  3498. if item.DepartmentId == sysUser.DepartmentId {
  3499. btnDetailItem.BtnHistoryList = true
  3500. }
  3501. }
  3502. }
  3503. }
  3504. //子权限切片集合
  3505. allFiccPermissions, permissionMap, e := services.GetBasePermissionLookItem(utils.COMPANY_PRODUCT_FICC_ID)
  3506. if e != nil {
  3507. br.Msg = "查询基础权限失败"
  3508. br.ErrMsg = "查询基础权限失败,Err:" + e.Error()
  3509. return
  3510. }
  3511. //遍历获取
  3512. for _, v := range allFiccPermissions {
  3513. if v.ParentId == 0 {
  3514. checkList := make([]int, 0)
  3515. plist := new(company.PermissionLookList)
  3516. plist.Items = make([]*company.PermissionLookItem, 0)
  3517. items, ok1 := permissionMap[v.ChartPermissionId]
  3518. if ok1 {
  3519. for itemK, n := range items {
  3520. permission, e := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  3521. if e != nil && e.Error() != utils.ErrNoRow() {
  3522. br.Msg = "获取失败"
  3523. br.ErrMsg = "获取权限信息失败,Err:" + e.Error()
  3524. return
  3525. }
  3526. if permission != nil && permission.ChartPermissionId > 0 {
  3527. checkList = append(checkList, n.ChartPermissionId)
  3528. items[itemK].StartDate = permission.StartDate
  3529. items[itemK].EndDate = permission.EndDate
  3530. items[itemK].Status = permission.Status
  3531. endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
  3532. endDateTime = endDateTime.AddDate(0, 0, 1)
  3533. sub := endDateTime.Sub(time.Now())
  3534. if sub < 0 {
  3535. sub = 0
  3536. }
  3537. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  3538. items[itemK].ExpireDay = expireDay
  3539. }
  3540. }
  3541. plist.Items = items
  3542. }
  3543. plist.ClassifyName = v.PermissionName
  3544. plist.CheckList = checkList
  3545. item.PermissionList = append(item.PermissionList, plist)
  3546. }
  3547. }
  3548. resp.FiccItem = item
  3549. if (roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  3550. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT) &&
  3551. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3552. resp.IsButtonShow = 1
  3553. }
  3554. } else {
  3555. if strings.Contains(sysUser.RoleTypeCode, "rai") {
  3556. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  3557. btnDetailItem.BtnHistoryList = true
  3558. } else {
  3559. if item.SellerId == sysUser.AdminId {
  3560. btnDetailItem.BtnHistoryList = true
  3561. }
  3562. if sysUser.Authority > 0 {
  3563. if item.GroupId == sysUser.GroupId {
  3564. btnDetailItem.BtnHistoryList = true
  3565. }
  3566. if item.DepartmentId == sysUser.DepartmentId {
  3567. btnDetailItem.BtnHistoryList = true
  3568. }
  3569. }
  3570. }
  3571. }
  3572. classifyName := "权益"
  3573. checkList := make([]int, 0)
  3574. plist := new(company.PermissionLookList)
  3575. items, err := company.GetPermissionLookItems(item.ProductId, classifyName)
  3576. if err != nil {
  3577. br.Msg = "获取失败"
  3578. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3579. return
  3580. }
  3581. for itemK, n := range items {
  3582. permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  3583. if err != nil && err.Error() != utils.ErrNoRow() {
  3584. br.Msg = "获取失败"
  3585. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3586. return
  3587. }
  3588. if permission != nil && permission.ChartPermissionId > 0 {
  3589. checkList = append(checkList, n.ChartPermissionId)
  3590. items[itemK].StartDate = permission.StartDate
  3591. items[itemK].EndDate = permission.EndDate
  3592. items[itemK].Status = permission.Status
  3593. endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
  3594. endDateTime = endDateTime.AddDate(0, 0, 1)
  3595. sub := endDateTime.Sub(time.Now())
  3596. if sub < 0 {
  3597. sub = 0
  3598. }
  3599. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  3600. items[itemK].ExpireDay = expireDay
  3601. }
  3602. //count, err := company.GetCompanyPermissionCheck(companyId, n.ChartPermissionId)
  3603. //if err != nil {
  3604. // br.Msg = "获取失败"
  3605. // br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3606. // return
  3607. //}
  3608. //if count > 0 {
  3609. // checkList = append(checkList, n.ChartPermissionId)
  3610. //}
  3611. }
  3612. item.SpecialSurplus, err = cygxService.GetSpecialSurplusByCompanyNew(companyId)
  3613. if err != nil {
  3614. br.Msg = "获取失败"
  3615. br.ErrMsg = "获取专项调研信息失败,Err:" + err.Error()
  3616. return
  3617. }
  3618. plist.Items = items
  3619. plist.ClassifyName = classifyName
  3620. plist.CheckList = checkList
  3621. item.PermissionList = append(item.PermissionList, plist)
  3622. resp.RaiItem = item
  3623. if (roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  3624. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  3625. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT) &&
  3626. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3627. resp.IsButtonShow = 1
  3628. }
  3629. }
  3630. btnItem := services.GetCompanyPermissionButton(roleTypeCode, item.Status, strconv.Itoa(item.SellerId), strconv.Itoa(item.GroupId),
  3631. item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, item.ShareSellerId, "")
  3632. //if itemLen > 1 {
  3633. // btnDetailItem.BtnEdit = false
  3634. // btnDetailItem.BtnDelete = false
  3635. //} else {
  3636. // btnDetailItem.BtnEdit = btnItem.BtnEdit
  3637. // btnDetailItem.BtnDelete = btnItem.BtnDelete
  3638. //}
  3639. switch item.ProductId {
  3640. case 1:
  3641. btnDetailItem.FiccEdit = btnItem.BtnEdit
  3642. btnDetailItem.FiccDelete = btnItem.BtnDelete
  3643. case 2:
  3644. btnDetailItem.RaiEdit = btnItem.BtnEdit
  3645. btnDetailItem.RaiDelete = btnItem.BtnDelete
  3646. }
  3647. if !btnDetailItem.BtnEdit {
  3648. btnDetailItem.BtnEdit = btnItem.BtnEdit
  3649. }
  3650. if !btnDetailItem.BtnDelete {
  3651. btnDetailItem.BtnDelete = btnItem.BtnDelete
  3652. }
  3653. //联系人操作权限
  3654. if resp.IsContractButtonShow == false {
  3655. resp.IsContractButtonShow = services.CheckCompanyUserButton(sysUser.RoleTypeCode, item.SellerId, sysUser.AdminId, item.ProductId, item.ShareSellerId, item.Status)
  3656. }
  3657. }
  3658. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  3659. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  3660. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  3661. resp.IsButtonShow = 1
  3662. btnDetailItem.BtnHistoryList = true
  3663. }
  3664. //ficc权限
  3665. if ficcStatus, ok := statusMap[1]; ok {
  3666. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT {
  3667. if raiStatus, ok := statusMap[2]; ok {
  3668. //另一个权限也是 试用 、冻结、流失
  3669. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3670. //那么超管、部门管理员、销售可以编辑
  3671. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3672. btnDetailItem.BaseInfoEdit = true
  3673. }
  3674. }
  3675. //权益是永续时,超管可编辑基础信息
  3676. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3677. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3678. btnDetailItem.BaseInfoEdit = true
  3679. }
  3680. }
  3681. } else {
  3682. //权限未开,有编辑基础信息权限
  3683. btnDetailItem.BaseInfoEdit = true
  3684. }
  3685. }
  3686. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3687. if raiStatus, ok := statusMap[2]; ok {
  3688. //另一个权限也是 永续 、冻结、流失
  3689. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FOREVER || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3690. //超管可编辑基础信息
  3691. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3692. btnDetailItem.BaseInfoEdit = true
  3693. }
  3694. }
  3695. } else {
  3696. //权限未开,有编辑基础信息权限
  3697. btnDetailItem.BaseInfoEdit = true
  3698. }
  3699. }
  3700. }
  3701. //权益销售
  3702. if raiStatus, ok := statusMap[2]; ok {
  3703. if raiStatus == utils.COMPANY_STATUS_TRY_OUT {
  3704. if ficcStatus, ok := statusMap[1]; ok {
  3705. //另一个权限也是 试用 、冻结、流失
  3706. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3707. //那么超管、部门管理员、销售可以编辑
  3708. if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3709. btnDetailItem.BaseInfoEdit = true
  3710. }
  3711. }
  3712. //ficc是永续时,超管可编辑基础信息
  3713. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3714. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3715. btnDetailItem.BaseInfoEdit = true
  3716. }
  3717. }
  3718. } else {
  3719. //权限未开,有编辑基础信息权限
  3720. btnDetailItem.BaseInfoEdit = true
  3721. }
  3722. }
  3723. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3724. if ficcStatus, ok := statusMap[1]; ok {
  3725. //另一个权限也是 试用、永续 、冻结、流失
  3726. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FOREVER || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3727. //超管可编辑基础信息
  3728. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3729. btnDetailItem.BaseInfoEdit = true
  3730. }
  3731. }
  3732. } else {
  3733. //权限未开,有编辑基础信息权限
  3734. btnDetailItem.BaseInfoEdit = true
  3735. }
  3736. }
  3737. }
  3738. resp.Item = item
  3739. resp.BtnItem = btnDetailItem
  3740. br.Ret = 200
  3741. br.Success = true
  3742. br.Msg = "获取成功"
  3743. br.Data = resp
  3744. }
  3745. // @Title 编辑客户
  3746. // @Description 编辑客户接口
  3747. // @Param request body company.CompanyEditReq true "type json string"
  3748. // @Success Ret=200 保存成功
  3749. // @router /edit [post]
  3750. func (this *CompanyController) Edit() {
  3751. br := new(models.BaseResponse).Init()
  3752. defer func() {
  3753. this.Data["json"] = br
  3754. this.ServeJSON()
  3755. }()
  3756. sysUser := this.SysUser
  3757. if sysUser == nil {
  3758. br.Msg = "请登录"
  3759. br.ErrMsg = "请登录,SysUser Is Empty"
  3760. br.Ret = 408
  3761. return
  3762. }
  3763. //roleTypeCode := sysUser.RoleTypeCode
  3764. var req company.CompanyEditReq
  3765. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3766. if err != nil {
  3767. br.Msg = "参数解析异常!"
  3768. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3769. return
  3770. }
  3771. if req.CompanyId <= 0 {
  3772. br.Msg = "参数异常!"
  3773. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  3774. return
  3775. }
  3776. if req.CompanyName == "" {
  3777. br.Msg = "请填写客户名称"
  3778. return
  3779. }
  3780. if req.CreditCode == "" {
  3781. br.Msg = "请填写社会统一信用码"
  3782. return
  3783. }
  3784. //移除空格
  3785. req.CreditCode = utils.TrimStr(req.CreditCode)
  3786. productId := services.GetProductId(sysUser.RoleTypeCode) //产品权限id
  3787. for _, v := range req.Products {
  3788. //X类试用,转为永续
  3789. if v.Status == utils.COMPANY_STATUS_X_CLASS_TRY_OUT {
  3790. v.Status = utils.COMPANY_STATUS_FOREVER
  3791. }
  3792. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  3793. //查询客户的产品权限
  3794. companyReportPermissionListOld, err := company.GetCompanyReportPermission(req.CompanyId, productId)
  3795. if err != nil {
  3796. br.Msg = "查询客户的产品权限异常"
  3797. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  3798. return
  3799. }
  3800. permissionArr := strings.Split(v.PermissionIds, ",")
  3801. //如果所选行业不属于研选订阅跟研选扣点包,那就是非研选试用客户
  3802. var isNoResearch bool
  3803. for _, v := range permissionArr {
  3804. if v != strconv.Itoa(utils.CHART_PERMISSION_ID_YANXUAN) && v != strconv.Itoa(utils.YAN_XUAN_KOU_DIAN_BAO_ID) {
  3805. isNoResearch = true
  3806. continue
  3807. }
  3808. }
  3809. if isNoResearch && len(companyReportPermissionListOld) != len(permissionArr) {
  3810. tryOutCountRai, err := company.GetRaiCompanyTryOutCountNoResearch(sysUser.AdminId)
  3811. if err != nil {
  3812. br.Msg = "判断试用客户量失败"
  3813. br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  3814. return
  3815. }
  3816. if tryOutCountRai >= utils.COMPANY_STATUS_TRY_OUT_COUNT_RAI {
  3817. br.Msg = "非研选试用客户最多40家"
  3818. return
  3819. }
  3820. }
  3821. }
  3822. if v.IndustryId <= 0 {
  3823. br.Msg = "请选择行业"
  3824. br.IsSendEmail = false
  3825. return
  3826. }
  3827. //获取客户产品信息
  3828. productItem, err := company.GetCompanyProductById(v.CompanyProductId)
  3829. if err != nil {
  3830. br.Msg = "数据获取失败!"
  3831. br.ErrMsg = "数据获取失败,Err:" + err.Error()
  3832. return
  3833. }
  3834. if productItem == nil {
  3835. br.Msg = "客户信息不存在!"
  3836. return
  3837. }
  3838. // 如果本身是有权限归属的,同时传入的参数不是当前账号权限的,那么过滤该次循环,进入下次循环
  3839. if productId > 0 && productItem.ProductId != productId {
  3840. continue
  3841. }
  3842. if v.Status == "" {
  3843. br.Msg = "客户状态不可为空"
  3844. return
  3845. }
  3846. //if v.Reasons == "" {
  3847. // br.Msg = "请填写新增理由"
  3848. // return
  3849. //}
  3850. if v.PermissionIds == "" {
  3851. br.Msg = "请选择权限"
  3852. return
  3853. }
  3854. var startDate, endDate string
  3855. startDate = productItem.StartDate
  3856. endDate = productItem.EndDate
  3857. if startDate == "" || endDate == "" {
  3858. br.Msg = "数据错误"
  3859. br.Msg = "数据错误,开始或结束日期为空:startDate:" + startDate + "endDate:" + endDate
  3860. return
  3861. }
  3862. //判断客户是否已经存在
  3863. companyNameIsExist, err := company.GetCompanyCountByCompanyNameAndCompanyId(req.CompanyId, req.CompanyName)
  3864. if err != nil {
  3865. br.Msg = "判断客户是否存在失败"
  3866. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  3867. return
  3868. }
  3869. if companyNameIsExist > 0 {
  3870. br.Msg = "客户已存在,请重新输入客户名称"
  3871. return
  3872. }
  3873. //判断客户是否已经存在
  3874. companyCreditCodeIsExist, err := company.GetCompanyCountByCreditCodeAndCompanyId(req.CompanyId, req.CreditCode)
  3875. if err != nil {
  3876. br.Msg = "判断客户是否存在失败"
  3877. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  3878. return
  3879. }
  3880. if companyCreditCodeIsExist > 0 {
  3881. br.Msg = "客户已存在,请重新输入统一社会信用代码"
  3882. return
  3883. }
  3884. seller, err := system.GetSysAdminById(v.SellsId)
  3885. if err != nil {
  3886. br.Msg = "获取销售信息失败"
  3887. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  3888. return
  3889. }
  3890. if seller == nil {
  3891. br.Msg = "所属销售不存在"
  3892. return
  3893. }
  3894. //tryOutCount, err := company.GetCompanyTryOutCount(utils.COMPANY_STATUS_TRY_OUT, seller.AdminId)
  3895. //if err != nil {
  3896. // br.Msg = "判断试用客户量失败"
  3897. // br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  3898. // return
  3899. //}
  3900. //if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
  3901. // roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  3902. // if tryOutCount >= utils.COMPANY_STATUS_TRY_OUT_COUNT && v.SellsId == sysUser.AdminId {
  3903. // br.Msg = "您的试用客户总数,已超过上限,不可继续新增"
  3904. // return
  3905. // }
  3906. //}
  3907. industry, err := company.GetCompanyIndustryById(v.IndustryId)
  3908. if err != nil {
  3909. br.Msg = "获取行业信息失败"
  3910. br.ErrMsg = "获取行业信息失败,Err:" + err.Error()
  3911. return
  3912. }
  3913. companyProduct := new(company.CompanyProduct)
  3914. companyProduct.ProductId = productItem.ProductId
  3915. companyProduct.CompanyId = req.CompanyId
  3916. companyProduct.CompanyName = req.CompanyName
  3917. companyProduct.Source = v.Source
  3918. companyProduct.Reasons = v.Reasons
  3919. companyProduct.Status = v.Status
  3920. companyProduct.StartDate = startDate
  3921. companyProduct.EndDate = endDate
  3922. companyProduct.IndustryId = v.IndustryId
  3923. companyProduct.IndustryName = industry.IndustryName
  3924. companyProduct.SellerId = seller.AdminId
  3925. companyProduct.SellerName = seller.RealName
  3926. companyProduct.GroupId = seller.GroupId
  3927. companyProduct.DepartmentId = seller.DepartmentId
  3928. companyProduct.IsSuspend = 0
  3929. companyProduct.ModifyTime = time.Now()
  3930. companyProduct.CompanyProductId = v.CompanyProductId
  3931. companyProduct.Scale = v.Scale
  3932. err = company.ModifyCompanyProduct(companyProduct)
  3933. if err != nil {
  3934. br.Msg = "修改客户信息失败"
  3935. br.ErrMsg = "修改客户产品信息失败,Err:" + err.Error()
  3936. return
  3937. }
  3938. // CRM8.8-下面的需求取消, 编辑的时候根据选择开通对应权限
  3939. // 如果是权益客户,编辑的时候开通主观客观权限
  3940. //if v.CompanyType == utils.COMPANY_CLASSIFY_RAI {
  3941. // permissionStr, err := company.GetPermissionIdById(v.PermissionIds)
  3942. // if err != nil {
  3943. // br.Msg = "修改失败"
  3944. // br.ErrMsg = "获取主观客观权限信息失败,Err:" + err.Error()
  3945. // return
  3946. // }
  3947. // v.PermissionIds = permissionStr
  3948. //}
  3949. //处理权限
  3950. companyReportPermissionList, err := services.AddCompanyPermission(req.CompanyId, seller.AdminId, productItem.ProductId, productItem.ProductName, seller.RealName, v.PermissionIds, startDate, endDate)
  3951. if err != nil {
  3952. br.Msg = "修改失败"
  3953. br.ErrMsg = "新增客户设置权限失败,err:" + err.Error()
  3954. return
  3955. }
  3956. //新增操作记录
  3957. {
  3958. record := new(company.CompanyOperationRecord)
  3959. record.CompanyId = req.CompanyId
  3960. record.CompanyName = req.CompanyName
  3961. record.SellerId = companyProduct.SellerId
  3962. record.SysUserId = this.SysUser.AdminId
  3963. record.SysRealName = this.SysUser.RealName
  3964. record.Remark = "编辑客户"
  3965. record.Operation = "edit"
  3966. record.CreateTime = time.Now()
  3967. record.ProductId = productItem.ProductId
  3968. record.ProductName = productItem.ProductName
  3969. record.Status = productItem.Status
  3970. _, err = company.AddCompanyOperationRecord(record)
  3971. if err != nil {
  3972. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  3973. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  3974. }
  3975. }
  3976. //新增客户产品日志
  3977. {
  3978. productLog := new(company.CompanyProductLog)
  3979. productLog.CompanyProductId = v.CompanyProductId
  3980. productLog.CompanyId = companyProduct.CompanyId
  3981. productLog.ProductId = companyProduct.ProductId
  3982. productLog.ProductName = companyProduct.ProductName
  3983. productLog.CompanyName = companyProduct.CompanyName
  3984. productLog.CompanyName = companyProduct.CompanyName
  3985. productLog.Source = companyProduct.Source
  3986. productLog.Reasons = companyProduct.Reasons
  3987. productLog.Status = companyProduct.Status
  3988. productLog.IndustryId = companyProduct.IndustryId
  3989. productLog.IndustryName = companyProduct.IndustryName
  3990. productLog.SellerId = companyProduct.SellerId
  3991. productLog.SellerName = companyProduct.SellerName
  3992. productLog.GroupId = companyProduct.GroupId
  3993. productLog.DepartmentId = companyProduct.DepartmentId
  3994. productLog.IsSuspend = companyProduct.IsSuspend
  3995. productLog.SuspendTime = companyProduct.SuspendTime
  3996. productLog.ApproveStatus = companyProduct.ApproveStatus
  3997. productLog.FreezeTime = companyProduct.FreezeTime
  3998. productLog.Remark = companyProduct.Remark
  3999. productLog.StartDate = companyProduct.StartDate
  4000. productLog.EndDate = companyProduct.EndDate
  4001. productLog.CreateTime = companyProduct.CreateTime
  4002. productLog.ModifyTime = companyProduct.ModifyTime
  4003. productLog.LoseReason = companyProduct.LoseReason
  4004. productLog.LossTime = companyProduct.LossTime
  4005. productLog.LogType = "modify"
  4006. productLog.LogCreateTime = time.Now()
  4007. productLog.AdminId = this.SysUser.AdminId
  4008. productLog.Scale = companyProduct.Scale
  4009. go company.AddCompanyProductLog(productLog)
  4010. }
  4011. //新增客户产品状态变更日志
  4012. {
  4013. startDateTime, _ := time.ParseInLocation(utils.FormatDate, startDate, time.Local)
  4014. endDateTime, _ := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
  4015. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  4016. Id: 0,
  4017. CompanyId: req.CompanyId,
  4018. ProductId: productId,
  4019. Status: "试用",
  4020. Source: "edit",
  4021. SellerId: seller.AdminId,
  4022. SellerName: seller.RealName,
  4023. StartDate: startDateTime,
  4024. EndDate: endDateTime,
  4025. RealEndDate: startDateTime,
  4026. CreateTime: time.Now(),
  4027. }
  4028. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  4029. // 添加试用记录
  4030. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  4031. Id: 0,
  4032. CompanyId: req.CompanyId,
  4033. ProductId: productId,
  4034. Source: "edit",
  4035. SellerId: seller.AdminId,
  4036. SellerName: seller.RealName,
  4037. StartDate: startDateTime,
  4038. EndDate: endDateTime,
  4039. RealEndDate: startDateTime,
  4040. IsStop: 0,
  4041. CreateTime: time.Now(),
  4042. }
  4043. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  4044. }
  4045. }
  4046. companyItem := new(company.Company)
  4047. companyItem.CompanyId = req.CompanyId
  4048. companyItem.CompanyName = req.CompanyName
  4049. companyItem.CreditCode = req.CreditCode
  4050. companyItem.Province = req.Province
  4051. companyItem.City = req.City
  4052. companyItem.Address = req.Province + req.City
  4053. companyItem.LastUpdatedTime = time.Now()
  4054. companyItem.Enabled = 1
  4055. companyItem.Nation = req.Nation
  4056. err = company.ModifyCompany(companyItem)
  4057. if err != nil {
  4058. br.Msg = "修改客户信息失败"
  4059. br.ErrMsg = "修改客户信息失败,Err:" + err.Error()
  4060. return
  4061. }
  4062. //新增客户日志
  4063. {
  4064. companyLog := new(company.CompanyLog)
  4065. companyLog.CompanyId = req.CompanyId
  4066. companyLog.CompanyName = req.CompanyName
  4067. companyLog.CreditCode = req.CreditCode
  4068. companyLog.Address = companyItem.Address
  4069. companyLog.City = companyItem.City
  4070. companyLog.Province = companyItem.Province
  4071. companyLog.LastUpdatedTime = companyItem.LastUpdatedTime
  4072. companyLog.AdminId = this.SysUser.AdminId
  4073. companyLog.LogType = "modify"
  4074. companyLog.LogCreateTime = time.Now()
  4075. go company.AddCompanyLog(companyLog)
  4076. }
  4077. br.Ret = 200
  4078. br.Success = true
  4079. br.Msg = "保存成功"
  4080. }
  4081. // @Title 编辑补充客户信息接口
  4082. // @Description 编辑补充客户信息接口
  4083. // @Param request body company.CompanyInfoEditReq true "type json string"
  4084. // @Success Ret=200 保存成功
  4085. // @router /company_info/edit [post]
  4086. func (this *CompanyController) EditCompanyInfo() {
  4087. br := new(models.BaseResponse).Init()
  4088. defer func() {
  4089. this.Data["json"] = br
  4090. this.ServeJSON()
  4091. }()
  4092. sysUser := this.SysUser
  4093. if sysUser == nil {
  4094. br.Msg = "请登录"
  4095. br.ErrMsg = "请登录,SysUser Is Empty"
  4096. br.Ret = 408
  4097. return
  4098. }
  4099. var req company.CompanyInfoEditReq
  4100. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4101. if err != nil {
  4102. br.Msg = "参数解析异常!"
  4103. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4104. return
  4105. }
  4106. if req.CompanyId <= 0 {
  4107. br.Msg = "参数异常!"
  4108. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  4109. return
  4110. }
  4111. if req.CompanyName == "" {
  4112. br.Msg = "请填写客户名称"
  4113. return
  4114. }
  4115. if req.CreditCode == "" {
  4116. br.Msg = "请填写社会统一信用码"
  4117. return
  4118. }
  4119. //if req.Province == "" {
  4120. // br.Msg = "请选择省份"
  4121. // return
  4122. //}
  4123. //if req.City == "" {
  4124. // br.Msg = "请选择市区"
  4125. // return
  4126. //}
  4127. //if req.IndustryId <= 0 {
  4128. // br.Msg = "请选择所属行业"
  4129. // return
  4130. //}
  4131. //if req.IndustryName == "" {
  4132. // br.Msg = "请选择所属行业"
  4133. // return
  4134. //}
  4135. //if req.Source == "" {
  4136. // br.Msg = "请选择来源"
  4137. // return
  4138. //}
  4139. //移除空格
  4140. req.CreditCode = utils.TrimStr(req.CreditCode)
  4141. //获取产品权限
  4142. productId := services.GetProductId(sysUser.RoleTypeCode)
  4143. if productId <= 0 {
  4144. br.Msg = "当前账号不允许修改客户信息"
  4145. return
  4146. }
  4147. companyNameIsExist, err := company.GetCompanyCountByCompanyNameAndCompanyId(req.CompanyId, req.CompanyName)
  4148. if err != nil {
  4149. br.Msg = "判断客户是否存在失败"
  4150. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  4151. return
  4152. }
  4153. if companyNameIsExist > 0 {
  4154. br.Msg = "客户已存在,请重新输入客户名称"
  4155. return
  4156. }
  4157. //判断客户是否已经存在
  4158. companyCreditCodeIsExist, err := company.GetCompanyCountByCreditCodeAndCompanyId(req.CompanyId, req.CreditCode)
  4159. if err != nil {
  4160. br.Msg = "判断客户是否存在失败"
  4161. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  4162. return
  4163. }
  4164. if companyCreditCodeIsExist > 0 {
  4165. br.Msg = "客户已存在,统一社会信用代码"
  4166. return
  4167. }
  4168. //查询该客户
  4169. companyItem, err := company.GetCompanyById(req.CompanyId)
  4170. if err != nil {
  4171. br.Msg = "查找客户失败"
  4172. br.ErrMsg = "查找客户失败,Err:" + err.Error()
  4173. return
  4174. }
  4175. //待更新字段
  4176. updateCol := make([]string, 0)
  4177. companyItem.CompanyName = req.CompanyName
  4178. companyItem.CreditCode = req.CreditCode
  4179. companyItem.Enabled = 1
  4180. companyItem.LastUpdatedTime = time.Now()
  4181. updateCol = append(updateCol, "CompanyName", "CreditCode", "Enabled", "LastUpdatedTime")
  4182. if req.Province != "" && req.City != "" {
  4183. companyItem.Province = req.Province
  4184. companyItem.City = req.City
  4185. companyItem.Address = req.Province + req.City
  4186. updateCol = append(updateCol, "Province", "City", "Address")
  4187. }
  4188. err = companyItem.Update(updateCol)
  4189. if err != nil {
  4190. br.Msg = "修改客户信息失败"
  4191. br.ErrMsg = "修改客户信息失败,Err:" + err.Error()
  4192. return
  4193. }
  4194. //查询并更新客户产品信息
  4195. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  4196. if err != nil {
  4197. if err.Error() != utils.ErrNoRow() {
  4198. br.Msg = "查询客户产品信息失败"
  4199. br.ErrMsg = "查询客户产品信息失败,Err:" + err.Error()
  4200. return
  4201. }
  4202. } else {
  4203. if companyProduct != nil {
  4204. //客户产品待更新字段
  4205. updateCompanyProductCol := make([]string, 0)
  4206. //产品信息(来源、行业)
  4207. if req.IndustryId != 0 && req.IndustryId != companyProduct.IndustryId {
  4208. companyProduct.IndustryId = req.IndustryId
  4209. companyProduct.IndustryName = req.IndustryName
  4210. updateCompanyProductCol = append(updateCompanyProductCol, "IndustryId", "IndustryName")
  4211. }
  4212. if req.Source != "" && req.Source != companyProduct.Source {
  4213. companyProduct.Source = req.Source
  4214. updateCompanyProductCol = append(updateCompanyProductCol, "Source")
  4215. }
  4216. //更新客户产品信息
  4217. if len(updateCompanyProductCol) > 0 {
  4218. err = companyProduct.Update(updateCompanyProductCol)
  4219. if err != nil {
  4220. br.Msg = "修改客户信息失败"
  4221. br.ErrMsg = "修改客户信息失败,Err:" + err.Error()
  4222. return
  4223. }
  4224. }
  4225. }
  4226. }
  4227. //新增客户日志
  4228. {
  4229. companyLog := new(company.CompanyLog)
  4230. companyLog.CompanyId = req.CompanyId
  4231. companyLog.CompanyName = req.CompanyName
  4232. companyLog.CreditCode = req.CreditCode
  4233. companyLog.Address = companyItem.Address
  4234. companyLog.City = companyItem.City
  4235. companyLog.Province = companyItem.Province
  4236. companyLog.LastUpdatedTime = companyItem.LastUpdatedTime
  4237. companyLog.AdminId = this.SysUser.AdminId
  4238. companyLog.LogType = "modify"
  4239. companyLog.LogCreateTime = time.Now()
  4240. go company.AddCompanyLog(companyLog)
  4241. }
  4242. br.Ret = 200
  4243. br.Success = true
  4244. br.Msg = "保存成功"
  4245. }
  4246. // @Title 客户模糊检索(新增/编辑客户页面试用)
  4247. // @Description 客户模糊检索接口(新增/编辑客户页面试用)
  4248. // @Param KeyWord query string true "搜索关键词"
  4249. // @Success 200 {object} company.CompanyFuzzySearchReq
  4250. // @router /fuzzy/search [get]
  4251. func (this *CompanyController) FuzzySearch() {
  4252. br := new(models.BaseResponse).Init()
  4253. defer func() {
  4254. this.Data["json"] = br
  4255. this.ServeJSON()
  4256. }()
  4257. keyWord := this.GetString("KeyWord")
  4258. list, err := company.GetCompanyFuzzySearch(keyWord)
  4259. if err != nil {
  4260. br.Msg = "获取信息失败"
  4261. br.ErrMsg = "获取信息失败,err:" + err.Error()
  4262. return
  4263. }
  4264. resp := new(company.CompanyFuzzySearchReq)
  4265. resp.List = list
  4266. br.Ret = 200
  4267. br.Success = true
  4268. br.Msg = "获取成功"
  4269. br.Data = resp
  4270. }
  4271. // @Title 删除客户
  4272. // @Description 删除客户接口
  4273. // @Param request body company.DeletePptReq true "type json string"
  4274. // @Success Ret=200 保存成功
  4275. // @router /delete [post]
  4276. func (this *CompanyController) Delete() {
  4277. br := new(models.BaseResponse).Init()
  4278. defer func() {
  4279. this.Data["json"] = br
  4280. this.ServeJSON()
  4281. }()
  4282. sysUser := this.SysUser
  4283. if sysUser == nil {
  4284. br.Msg = "请登录"
  4285. br.ErrMsg = "请登录,SysUser Is Empty"
  4286. br.Ret = 408
  4287. return
  4288. }
  4289. var req company.DeletePptReq
  4290. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4291. if err != nil {
  4292. br.Msg = "参数解析异常!"
  4293. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4294. return
  4295. }
  4296. if req.CompanyId <= 0 {
  4297. br.Msg = "参数错误"
  4298. br.ErrMsg = "客户ID小于等于0"
  4299. return
  4300. }
  4301. roleTypeCode := this.SysUser.RoleTypeCode
  4302. productId := services.GetProductId(roleTypeCode)
  4303. productItems, err := company.GetCompanyProductsByCompanyId(req.CompanyId)
  4304. if err != nil {
  4305. br.Msg = "删除失败"
  4306. br.ErrMsg = "获取客户产品信息失败,Err:" + err.Error()
  4307. return
  4308. }
  4309. // 备份信息
  4310. companyDeleteBakInfo := services.CompanyDeleteBakInfo{
  4311. CompanyId: req.CompanyId,
  4312. CompanyName: "",
  4313. CompanyInfo: &company.Company{},
  4314. CompanyProductInfo: make([]*company.CompanyProduct, 0),
  4315. CompanyPermissionInfo: make([]*company.CompanyReportPermission, 0),
  4316. UserSellerRelationInfo: make([]*models.UserSellerRelation, 0),
  4317. UserRecordInfo: make([]*models.UserRecord, 0),
  4318. UserInfo: make([]*models.WxUser, 0),
  4319. CompanyChartPermissionInfo: make([]*company_user.ChartClassifyPermission, 0),
  4320. OpUserId: this.SysUser.AdminId,
  4321. OpUserName: this.SysUser.RealName,
  4322. }
  4323. if productId == 0 {
  4324. for _, v := range productItems {
  4325. //永续,试用,流失,关闭
  4326. if v.Status != utils.COMPANY_STATUS_FOREVER && v.Status != utils.COMPANY_STATUS_TRY_OUT && v.Status != utils.COMPANY_STATUS_LOSE && v.Status != utils.COMPANY_STATUS_CLOSE {
  4327. br.Msg = "该客户" + v.ProductName + "属性为" + v.Status + ",暂不可删除"
  4328. br.ErrMsg = "该客户" + v.ProductName + "属性为" + v.Status + ",暂不可删除"
  4329. return
  4330. }
  4331. companyProductList, companyReportPermissionList, err := company.DeleteCompanyProductById(v.CompanyId, v.ProductId, v.CompanyProductId)
  4332. if err != nil {
  4333. br.Msg = "删除失败"
  4334. br.ErrMsg = "删除失败,Err:" + err.Error()
  4335. return
  4336. }
  4337. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductList...)
  4338. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissionList...)
  4339. //新增操作记录
  4340. {
  4341. record := new(company.CompanyOperationRecord)
  4342. record.CompanyId = req.CompanyId
  4343. record.CompanyName = v.CompanyName
  4344. record.SellerId = v.SellerId
  4345. record.SysUserId = this.SysUser.AdminId
  4346. record.SysRealName = this.SysUser.RealName
  4347. record.Remark = "删除客户"
  4348. record.Operation = "delete"
  4349. record.CreateTime = time.Now()
  4350. record.ProductId = v.ProductId
  4351. record.ProductName = v.ProductName
  4352. _, err = company.AddCompanyOperationRecord(record)
  4353. if err != nil {
  4354. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  4355. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  4356. }
  4357. }
  4358. //删除对应产品的联系人
  4359. userSellerRelationList, userRecordList, wxUserList, chartClassifyPermission, _ := services.DeleteCompanyWxUserByProductId(v.CompanyId, v.ProductId)
  4360. //备份信息
  4361. {
  4362. if companyProductList != nil {
  4363. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductList...)
  4364. }
  4365. if companyReportPermissionList != nil {
  4366. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissionList...)
  4367. }
  4368. if userSellerRelationList != nil {
  4369. companyDeleteBakInfo.UserSellerRelationInfo = append(companyDeleteBakInfo.UserSellerRelationInfo, userSellerRelationList...)
  4370. }
  4371. if userRecordList != nil {
  4372. companyDeleteBakInfo.UserRecordInfo = append(companyDeleteBakInfo.UserRecordInfo, userRecordList...)
  4373. }
  4374. if wxUserList != nil {
  4375. companyDeleteBakInfo.UserInfo = append(companyDeleteBakInfo.UserInfo, wxUserList...)
  4376. }
  4377. if chartClassifyPermission != nil {
  4378. companyDeleteBakInfo.CompanyChartPermissionInfo = append(companyDeleteBakInfo.CompanyChartPermissionInfo, chartClassifyPermission...)
  4379. }
  4380. companyDeleteBakInfo.CompanyName = v.CompanyName
  4381. }
  4382. }
  4383. } else {
  4384. productObj, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  4385. if err != nil {
  4386. br.ErrMsg = "获取客户产品信息失败,Err:" + err.Error()
  4387. br.Msg = "删除失败"
  4388. return
  4389. }
  4390. //永续,试用,流失,关闭
  4391. if productObj.Status != utils.COMPANY_STATUS_FOREVER && productObj.Status != utils.COMPANY_STATUS_TRY_OUT && productObj.Status != utils.COMPANY_STATUS_LOSE && productObj.Status != utils.COMPANY_STATUS_CLOSE {
  4392. br.Msg = "该客户" + productObj.ProductName + "属性为" + productObj.Status + ",暂不可删除"
  4393. br.ErrMsg = "该客户" + productObj.ProductName + "属性为" + productObj.Status + ",暂不可删除"
  4394. return
  4395. }
  4396. companyProductList, companyReportPermissionList, err := company.DeleteCompanyProductById(productObj.CompanyId, productObj.ProductId, productObj.CompanyProductId)
  4397. if err != nil {
  4398. br.Msg = "删除失败"
  4399. br.ErrMsg = "删除失败,Err:" + err.Error()
  4400. return
  4401. }
  4402. //新增操作记录
  4403. {
  4404. record := new(company.CompanyOperationRecord)
  4405. record.CompanyId = req.CompanyId
  4406. record.CompanyName = productObj.CompanyName
  4407. record.SellerId = productObj.SellerId
  4408. record.SysUserId = this.SysUser.AdminId
  4409. record.SysRealName = this.SysUser.RealName
  4410. record.Remark = "删除客户"
  4411. record.Operation = "delete"
  4412. record.CreateTime = time.Now()
  4413. record.ProductId = productObj.ProductId
  4414. record.ProductName = productObj.ProductName
  4415. _, err = company.AddCompanyOperationRecord(record)
  4416. if err != nil {
  4417. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  4418. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  4419. }
  4420. }
  4421. //删除对应产品的联系人
  4422. userSellerRelationList, userRecordList, wxUserList, chartClassifyPermission, _ := services.DeleteCompanyWxUserByProductId(productObj.CompanyId, productId)
  4423. //备份信息
  4424. {
  4425. if companyProductList != nil {
  4426. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductList...)
  4427. }
  4428. if companyReportPermissionList != nil {
  4429. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissionList...)
  4430. }
  4431. if userSellerRelationList != nil {
  4432. companyDeleteBakInfo.UserSellerRelationInfo = append(companyDeleteBakInfo.UserSellerRelationInfo, userSellerRelationList...)
  4433. }
  4434. if userRecordList != nil {
  4435. companyDeleteBakInfo.UserRecordInfo = append(companyDeleteBakInfo.UserRecordInfo, userRecordList...)
  4436. }
  4437. if wxUserList != nil {
  4438. companyDeleteBakInfo.UserInfo = append(companyDeleteBakInfo.UserInfo, wxUserList...)
  4439. }
  4440. if chartClassifyPermission != nil {
  4441. companyDeleteBakInfo.CompanyChartPermissionInfo = append(companyDeleteBakInfo.CompanyChartPermissionInfo, chartClassifyPermission...)
  4442. }
  4443. companyDeleteBakInfo.CompanyName = productObj.CompanyName
  4444. }
  4445. }
  4446. productItemsNew, err := company.GetCompanyProductsByCompanyId(req.CompanyId)
  4447. if err != nil {
  4448. br.Msg = "删除失败"
  4449. br.ErrMsg = "获取客户产品信息失败,Err:" + err.Error()
  4450. return
  4451. }
  4452. if len(productItemsNew) == 0 {
  4453. //删除之前查询的数据信息
  4454. {
  4455. companyProductLists, companyReportPermissions, wxUsers, userSellerRelations, companyContracts, companyContractPermissions, companyInfo, _ := services.GetBeforeDeleteCompanyInfo(req.CompanyId)
  4456. //companyDeleteBakInfo
  4457. if companyProductLists != nil {
  4458. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductLists...)
  4459. }
  4460. if companyReportPermissions != nil {
  4461. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissions...)
  4462. }
  4463. if wxUsers != nil {
  4464. companyDeleteBakInfo.UserInfo = append(companyDeleteBakInfo.UserInfo, wxUsers...)
  4465. }
  4466. if userSellerRelations != nil {
  4467. companyDeleteBakInfo.UserSellerRelationInfo = append(companyDeleteBakInfo.UserSellerRelationInfo, userSellerRelations...)
  4468. }
  4469. if companyContracts != nil {
  4470. companyDeleteBakInfo.CompanyContract = append(companyDeleteBakInfo.CompanyContract, companyContracts...)
  4471. }
  4472. if companyContractPermissions != nil {
  4473. companyDeleteBakInfo.CompanyContractPermission = append(companyDeleteBakInfo.CompanyContractPermission, companyContractPermissions...)
  4474. }
  4475. if companyInfo != nil {
  4476. companyDeleteBakInfo.CompanyName = companyInfo.CompanyName
  4477. companyDeleteBakInfo.CompanyInfo = companyInfo
  4478. }
  4479. }
  4480. err = company.DeleteCompanyById(req.CompanyId)
  4481. if err != nil {
  4482. br.Msg = "删除失败"
  4483. br.ErrMsg = "删除失败,Err:" + err.Error()
  4484. return
  4485. }
  4486. for _, v := range productItems {
  4487. //新增操作记录
  4488. {
  4489. record := new(company.CompanyOperationRecord)
  4490. record.CompanyId = req.CompanyId
  4491. record.CompanyName = v.CompanyName
  4492. record.SellerId = v.SellerId
  4493. record.SysUserId = this.SysUser.AdminId
  4494. record.SysRealName = this.SysUser.RealName
  4495. record.Remark = "删除客户"
  4496. record.Operation = "delete"
  4497. record.CreateTime = time.Now()
  4498. record.ProductId = v.ProductId
  4499. record.ProductName = v.ProductName
  4500. _, err = company.AddCompanyOperationRecord(record)
  4501. if err != nil {
  4502. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  4503. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  4504. }
  4505. }
  4506. }
  4507. }
  4508. //数据备份入库
  4509. {
  4510. companyInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyInfo)
  4511. companyProductInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyProductInfo)
  4512. companyPermissionInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyPermissionInfo)
  4513. userSellerRelationInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.UserSellerRelationInfo)
  4514. userRecordInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.UserRecordInfo)
  4515. userInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.UserInfo)
  4516. companyChartPermissionInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyChartPermissionInfo)
  4517. companyContractByte, _ := json.Marshal(companyDeleteBakInfo.CompanyContract)
  4518. companyContractPermissionJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyContractPermission)
  4519. companyDeleteBak := &company.CompanyDeleteBak{
  4520. //DeleteBakId: 0,
  4521. CompanyId: companyDeleteBakInfo.CompanyId,
  4522. CompanyName: companyDeleteBakInfo.CompanyName,
  4523. CompanyInfo: string(companyInfoJsonByte),
  4524. CompanyProductInfo: string(companyProductInfoJsonByte),
  4525. CompanyPermissionInfo: string(companyPermissionInfoJsonByte),
  4526. UserSellerRelationInfo: string(userSellerRelationInfoJsonByte),
  4527. UserRecordInfo: string(userRecordInfoJsonByte),
  4528. UserInfo: string(userInfoJsonByte),
  4529. CompanyChartPermissionInfo: string(companyChartPermissionInfoJsonByte),
  4530. CompanyContractInfo: string(companyContractByte),
  4531. CompanyContractPermissionInfo: string(companyContractPermissionJsonByte),
  4532. OpUserId: this.SysUser.AdminId,
  4533. OpUserName: this.SysUser.RealName,
  4534. CreateTime: time.Now(),
  4535. }
  4536. _ = company.AddCompanyDeleteBak(companyDeleteBak)
  4537. }
  4538. br.Ret = 200
  4539. br.Success = true
  4540. br.Msg = "删除成功"
  4541. }
  4542. // @Title 领取客户列表
  4543. // @Description 领取客户列表接口
  4544. // @Param PageSize query int true "每页数据条数"
  4545. // @Param CurrentIndex query int true "当前页页码,从1开始"
  4546. // @Param StartDate query string true "开始时间"
  4547. // @Param EndDate query string true "结束时间"
  4548. // @Param KeyWord query string true "搜索关键词"
  4549. // @Success 200 {object} company.CompanyReceiveListResp
  4550. // @router /receive/list [get]
  4551. func (this *CompanyController) ReceiveList() {
  4552. br := new(models.BaseResponse).Init()
  4553. defer func() {
  4554. this.Data["json"] = br
  4555. this.ServeJSON()
  4556. }()
  4557. sysUser := this.SysUser
  4558. if sysUser == nil {
  4559. br.Msg = "请登录"
  4560. br.ErrMsg = "请登录,SysUser Is Empty"
  4561. br.Ret = 408
  4562. return
  4563. }
  4564. var productId, recevieProductId int
  4565. roleTypeCode := sysUser.RoleTypeCode
  4566. productId = services.GetProductId(roleTypeCode)
  4567. if productId == 1 {
  4568. recevieProductId = 2
  4569. } else if productId == 2 {
  4570. recevieProductId = 1
  4571. }
  4572. if productId == 0 {
  4573. br.Msg = "参数错误"
  4574. br.ErrMsg = "客户类型为:" + roleTypeCode
  4575. return
  4576. }
  4577. pageSize, _ := this.GetInt("PageSize")
  4578. currentIndex, _ := this.GetInt("CurrentIndex")
  4579. adminId := this.GetString("AdminId")
  4580. startDate := this.GetString("StartDate")
  4581. endDate := this.GetString("EndDate")
  4582. keyWord := this.GetString("KeyWord")
  4583. var startSize int
  4584. if pageSize <= 0 {
  4585. pageSize = utils.PageSize20
  4586. }
  4587. if currentIndex <= 0 {
  4588. currentIndex = 1
  4589. }
  4590. startSize = paging.StartIndex(currentIndex, pageSize)
  4591. var condition string
  4592. var pars []interface{}
  4593. if adminId != "" {
  4594. condition += ` AND c.seller_id IN (` + adminId + `) `
  4595. }
  4596. if startDate != "" {
  4597. condition += ` AND c.start_date>=? `
  4598. pars = append(pars, startDate)
  4599. }
  4600. if endDate != "" {
  4601. condition += ` AND c.end_date>=? `
  4602. pars = append(pars, endDate)
  4603. }
  4604. if keyWord != "" {
  4605. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR b.mobile LIKE '%` + keyWord + `%' OR b.email LIKE '%` + keyWord + `%') `
  4606. }
  4607. total, err := company.GetCompanyReceiveListCount(condition, pars, productId, recevieProductId)
  4608. if err != nil {
  4609. br.Msg = "获取失败"
  4610. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  4611. return
  4612. }
  4613. list, err := company.GetCompanyReceiveList(condition, pars, productId, recevieProductId, startSize, pageSize)
  4614. if err != nil {
  4615. br.Msg = "获取失败"
  4616. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  4617. return
  4618. }
  4619. lenList := len(list)
  4620. for i := 0; i < lenList; i++ {
  4621. item := list[i]
  4622. var expireDay string
  4623. if item.Status != "" {
  4624. status := item.Status
  4625. if item.EndDate != "" {
  4626. if status == utils.COMPANY_STATUS_FOREVER { //永续
  4627. expireDay = "-"
  4628. } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用/正式
  4629. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  4630. sub := endDateTime.Sub(time.Now())
  4631. expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  4632. } else if status == utils.COMPANY_STATUS_LOSE { //流失
  4633. expireDay = "-"
  4634. } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  4635. if item.StartDate != "" && item.EndDate != "" {
  4636. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  4637. sub := endDateTime.Sub(time.Now())
  4638. expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  4639. } else {
  4640. expireDay = "-"
  4641. }
  4642. } else {
  4643. expireDay = "-"
  4644. }
  4645. }
  4646. }
  4647. list[i].ExpireDay = expireDay
  4648. }
  4649. page := paging.GetPaging(currentIndex, pageSize, total)
  4650. resp := new(company.CompanyReceiveListResp)
  4651. resp.List = list
  4652. resp.Paging = page
  4653. br.Ret = 200
  4654. br.Success = true
  4655. br.Msg = "获取成功"
  4656. br.Data = resp
  4657. }
  4658. // @Title 领取客户
  4659. // @Description 领取客户接口
  4660. // @Param request body company.CompanyReceiveReq true "type json string"
  4661. // @Success Ret=200 领取成功
  4662. // @router /receive [post]
  4663. func (this *CompanyController) Receive() {
  4664. br := new(models.BaseResponse).Init()
  4665. defer func() {
  4666. this.Data["json"] = br
  4667. this.ServeJSON()
  4668. }()
  4669. sysUser := this.SysUser
  4670. if sysUser == nil {
  4671. br.Msg = "请登录"
  4672. br.ErrMsg = "请登录,SysUser Is Empty"
  4673. br.Ret = 408
  4674. return
  4675. }
  4676. var req company.CompanyReceiveReq
  4677. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4678. if err != nil {
  4679. br.Msg = "参数解析异常!"
  4680. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4681. return
  4682. }
  4683. if req.CompanyId <= 0 {
  4684. br.Msg = "参数异常!"
  4685. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  4686. return
  4687. }
  4688. //权益主观客观权限一块开
  4689. if req.PermissionIds != "" {
  4690. permissionStr, err := company.GetPermissionIdById(req.PermissionIds)
  4691. if err != nil {
  4692. br.Msg = "获取信息失败"
  4693. br.ErrMsg = "获取主观客观权限信息失败,Err:" + err.Error()
  4694. return
  4695. }
  4696. req.PermissionIds = permissionStr
  4697. }
  4698. roleTypeCode := sysUser.RoleTypeCode
  4699. productId := services.GetProductId(roleTypeCode)
  4700. if productId == 0 {
  4701. br.Msg = "参数错误"
  4702. br.ErrMsg = "客户类型为:" + roleTypeCode
  4703. return
  4704. }
  4705. sellsId := 0
  4706. if req.SellsId <= 0 {
  4707. sellsId = sysUser.AdminId
  4708. } else {
  4709. sellsId = req.SellsId
  4710. }
  4711. seller, err := system.GetSysAdminById(sellsId)
  4712. if err != nil {
  4713. br.Msg = "获取销售信息失败"
  4714. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  4715. return
  4716. }
  4717. companyDetail, err := company.GetCompanyDetailById(req.CompanyId)
  4718. if err != nil {
  4719. br.Msg = "获取客户信息失败"
  4720. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  4721. return
  4722. }
  4723. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  4724. if err != nil && err.Error() != utils.ErrNoRow() {
  4725. br.Msg = "获取客户信息失败"
  4726. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  4727. return
  4728. }
  4729. productName := ""
  4730. var status string
  4731. if productId == 1 {
  4732. productName = utils.COMPANY_PRODUCT_FICC_NAME
  4733. } else {
  4734. productName = utils.COMPANY_PRODUCT_RAI_NAME
  4735. }
  4736. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  4737. //查询客户的产品权限
  4738. companyReportPermissionListOld, err := company.GetCompanyReportPermission(req.CompanyId, productId)
  4739. if err != nil {
  4740. br.Msg = "查询客户的产品权限异常"
  4741. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  4742. return
  4743. }
  4744. var isNoResearch bool
  4745. for _, v := range companyReportPermissionListOld {
  4746. if v.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN && v.ChartPermissionId != utils.YAN_XUAN_KOU_DIAN_BAO_ID {
  4747. isNoResearch = true
  4748. continue
  4749. }
  4750. }
  4751. //如果所选行业不属于研选订阅跟研选扣点包,那就是非研选试用客户
  4752. if isNoResearch {
  4753. tryOutCountRai, err := company.GetRaiCompanyTryOutCountNoResearch(req.SellsId)
  4754. if err != nil {
  4755. br.Msg = "判断试用客户量失败"
  4756. br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  4757. return
  4758. }
  4759. if tryOutCountRai >= utils.COMPANY_STATUS_TRY_OUT_COUNT_RAI {
  4760. br.Msg = "非研选试用客户最多40家"
  4761. return
  4762. }
  4763. }
  4764. }
  4765. if cp != nil {
  4766. if cp.Status != utils.COMPANY_STATUS_LOSE {
  4767. br.Msg = "客户状态为:" + cp.Status + ";不可领取"
  4768. br.ErrMsg = "客户状态为:" + cp.Status + ";不可领取"
  4769. return
  4770. }
  4771. if cp.SellerId == sysUser.AdminId {
  4772. br.Msg = "已为自己客户,不可重复领取"
  4773. br.ErrMsg = "已为自己客户,不可领取:company_id:" + strconv.Itoa(cp.CompanyId)
  4774. return
  4775. }
  4776. //转移 销售
  4777. companyReportPermissionList, startDate, endDate, err := company.MoveSeller(req.CompanyId, productId, seller.AdminId, seller.GroupId, seller.DepartmentId, seller.RealName)
  4778. if err != nil {
  4779. br.Msg = "领取失败"
  4780. br.ErrMsg = "领取失败,Err:" + err.Error()
  4781. return
  4782. }
  4783. //新增客户产品状态变更日志
  4784. {
  4785. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  4786. Id: 0,
  4787. CompanyId: req.CompanyId,
  4788. ProductId: productId,
  4789. Status: "试用",
  4790. Source: "receive",
  4791. SellerId: seller.AdminId,
  4792. SellerName: seller.RealName,
  4793. StartDate: startDate,
  4794. EndDate: endDate,
  4795. RealEndDate: startDate,
  4796. CreateTime: time.Now(),
  4797. }
  4798. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  4799. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  4800. Id: 0,
  4801. CompanyId: req.CompanyId,
  4802. ProductId: productId,
  4803. Source: "receive",
  4804. SellerId: seller.AdminId,
  4805. SellerName: seller.RealName,
  4806. StartDate: startDate,
  4807. EndDate: endDate,
  4808. RealEndDate: startDate,
  4809. IsStop: 0,
  4810. CreateTime: time.Now(),
  4811. }
  4812. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  4813. }
  4814. //流失转试用,企业下面的用户自动添加产业关注
  4815. //{
  4816. // go cygxService.AddUserFllowCompanyLossToTryOut(req.CompanyId)
  4817. //}
  4818. } else {
  4819. //跨部门领取
  4820. var startDateTime, endDateTime time.Time
  4821. if req.Status == utils.COMPANY_STATUS_TRY_OUT {
  4822. startDateTime = time.Now()
  4823. endDateTime = time.Now().AddDate(0, 2, 0)
  4824. } else if req.Status == utils.COMPANY_STATUS_FOREVER {
  4825. startDateTime = time.Now()
  4826. endDateTime = time.Now().AddDate(100, 0, 0)
  4827. } else {
  4828. br.Msg = "无效的客户状态,请重新选择"
  4829. return
  4830. }
  4831. var startDate, endDate string
  4832. startDate = startDateTime.Format(utils.FormatDate)
  4833. endDate = endDateTime.Format(utils.FormatDate)
  4834. if req.PermissionIds == "" {
  4835. br.Msg = "请选择权限!"
  4836. return
  4837. }
  4838. industry, err := company.GetCompanyIndustryById(req.IndustryId)
  4839. if err != nil {
  4840. br.Msg = "获取行业信息失败"
  4841. br.ErrMsg = "获取行业信息失败,Err:" + err.Error()
  4842. return
  4843. }
  4844. if industry == nil {
  4845. br.Msg = "行业信息不存在"
  4846. return
  4847. }
  4848. status = req.Status
  4849. companyProduct := new(company.CompanyProduct)
  4850. companyProduct.CompanyId = req.CompanyId
  4851. companyProduct.ProductId = productId
  4852. companyProduct.ProductName = productName
  4853. companyProduct.CompanyName = companyDetail.CompanyName
  4854. companyProduct.Source = req.Source
  4855. companyProduct.Reasons = req.Reasons
  4856. companyProduct.Status = status
  4857. companyProduct.StartDate = startDate
  4858. companyProduct.EndDate = endDate
  4859. companyProduct.IndustryId = req.IndustryId
  4860. companyProduct.IndustryName = industry.IndustryName
  4861. companyProduct.SellerId = seller.AdminId
  4862. companyProduct.SellerName = seller.RealName
  4863. companyProduct.GroupId = seller.GroupId
  4864. companyProduct.DepartmentId = seller.DepartmentId
  4865. companyProduct.IsSuspend = 0
  4866. companyProduct.CreateTime = time.Now()
  4867. companyProduct.ModifyTime = time.Now()
  4868. companyProduct.CompanyType = req.CompanyType
  4869. companyProduct.OpenCode = services.GenerateOpenCompanyProductCode(req.CompanyId, productId)
  4870. companyProduct.TodoStatus = "无任务"
  4871. companyProduct.TryStage = 1
  4872. companyProduct.SellerIdInit = seller.AdminId
  4873. companyProduct.SellerNameInit = seller.RealName
  4874. _, err = company.AddCompanyProduct(companyProduct)
  4875. if err != nil {
  4876. br.Msg = "新增失败"
  4877. br.ErrMsg = "新增客户产品失败,err:" + err.Error()
  4878. return
  4879. }
  4880. companyReportPermissionList, err := services.AddCompanyPermission(req.CompanyId, seller.AdminId, productId, productName, seller.RealName, req.PermissionIds, startDate, endDate)
  4881. if err != nil {
  4882. br.Msg = "新增失败"
  4883. br.ErrMsg = "新增客户设置权限失败,err:" + err.Error()
  4884. return
  4885. }
  4886. //新增客户产品日志
  4887. {
  4888. go services.AddCompanyProductLog(companyProduct, this.SysUser.AdminId, "add")
  4889. }
  4890. //新增客户产品状态变更日志
  4891. {
  4892. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  4893. Id: 0,
  4894. CompanyId: companyProduct.CompanyId,
  4895. ProductId: companyProduct.ProductId,
  4896. Status: "试用",
  4897. SellerId: seller.AdminId,
  4898. SellerName: seller.RealName,
  4899. Source: "add",
  4900. StartDate: startDateTime,
  4901. EndDate: endDateTime,
  4902. RealEndDate: startDateTime,
  4903. CreateTime: time.Now(),
  4904. }
  4905. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  4906. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  4907. Id: 0,
  4908. CompanyId: companyProduct.CompanyId,
  4909. ProductId: companyProduct.ProductId,
  4910. SellerId: seller.AdminId,
  4911. SellerName: seller.RealName,
  4912. Source: "add",
  4913. StartDate: startDateTime,
  4914. EndDate: endDateTime,
  4915. RealEndDate: startDateTime,
  4916. IsStop: 0,
  4917. CreateTime: time.Now(),
  4918. }
  4919. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  4920. }
  4921. //查询当前客户的所有产品的列表数据,并找出非当前产品的销售去发送模板消息
  4922. companyProductList, err := company.GetCompanyProductsByCompanyId(req.CompanyId)
  4923. for _, companyProduct := range companyProductList {
  4924. //如果是当前领取的产品,那么就退出当前循环,进入下一循环
  4925. if companyProduct.ProductId == productId {
  4926. continue
  4927. }
  4928. //查询其他部门销售的信息
  4929. admin, tmpErr := system.GetSysAdminById(companyProduct.SellerId)
  4930. if tmpErr != nil {
  4931. continue
  4932. }
  4933. //发送模板消息给另一个部门的销售
  4934. go services.SendCompanyReceiveWxTemplateMsg(companyDetail.CompanyName, productName, sysUser.RealName, admin.Mobile)
  4935. }
  4936. }
  4937. //新增操作记录
  4938. {
  4939. remark := "领取客户"
  4940. operation := "receive"
  4941. services.AddCompanyOperationRecord(req.CompanyId, seller.AdminId, sysUser.AdminId, productId, sysUser.AdminId, companyDetail.CompanyName,
  4942. productName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", status)
  4943. }
  4944. br.Ret = 200
  4945. br.Success = true
  4946. br.Msg = "领取成功"
  4947. }
  4948. // @Title 移动销售
  4949. // @Description 移动销售接口
  4950. // @Param request body company.MoveSellerReq true "type json string"
  4951. // @Success Ret=200 移动成功
  4952. // @router /move/seller [post]
  4953. func (this *CompanyController) MoveSeller() {
  4954. br := new(models.BaseResponse).Init()
  4955. defer func() {
  4956. this.Data["json"] = br
  4957. this.ServeJSON()
  4958. }()
  4959. sysUser := this.SysUser
  4960. if sysUser == nil {
  4961. br.Msg = "请登录"
  4962. br.ErrMsg = "请登录,SysUser Is Empty"
  4963. br.Ret = 408
  4964. return
  4965. }
  4966. var req company.MoveSellerReq
  4967. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4968. if err != nil {
  4969. br.Msg = "参数解析异常!"
  4970. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4971. return
  4972. }
  4973. if req.CompanyId <= 0 {
  4974. br.Msg = "参数异常!"
  4975. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  4976. return
  4977. }
  4978. if req.SellsId <= 0 {
  4979. br.Msg = "参数异常!"
  4980. br.ErrMsg = "SellsId:" + strconv.Itoa(req.SellsId)
  4981. return
  4982. }
  4983. seller, err := system.GetSysAdminById(req.SellsId)
  4984. if err != nil {
  4985. br.Msg = "获取销售信息失败"
  4986. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  4987. return
  4988. }
  4989. roleTypeCode := sysUser.RoleTypeCode
  4990. productId := services.GetProductId(roleTypeCode)
  4991. if productId == 0 {
  4992. if req.CompanyType == utils.COMPANY_CLASSIFY_FICC {
  4993. productId = 1
  4994. } else if req.CompanyType == utils.COMPANY_CLASSIFY_RAI {
  4995. productId = 2
  4996. }
  4997. }
  4998. if productId == 0 {
  4999. br.Msg = "无效的客户类型"
  5000. br.ErrMsg = "无效的客户类型"
  5001. return
  5002. }
  5003. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  5004. //查询客户的产品权限
  5005. companyReportPermissionListOld, err := company.GetCompanyReportPermission(req.CompanyId, productId)
  5006. if err != nil {
  5007. br.Msg = "查询客户的产品权限异常"
  5008. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  5009. return
  5010. }
  5011. var isNoResearch bool
  5012. for _, v := range companyReportPermissionListOld {
  5013. if v.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN && v.ChartPermissionId != utils.YAN_XUAN_KOU_DIAN_BAO_ID {
  5014. isNoResearch = true
  5015. continue
  5016. }
  5017. }
  5018. //如果所选行业不属于研选订阅跟研选扣点包,那就是非研选试用客户
  5019. if isNoResearch {
  5020. tryOutCountRai, err := company.GetRaiCompanyTryOutCountNoResearch(req.SellsId)
  5021. if err != nil {
  5022. br.Msg = "判断试用客户量失败"
  5023. br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  5024. return
  5025. }
  5026. if tryOutCountRai >= utils.COMPANY_STATUS_TRY_OUT_COUNT_RAI {
  5027. br.Msg = seller.RealName + "的非研选试用客户已超过40家"
  5028. return
  5029. }
  5030. }
  5031. }
  5032. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  5033. if err != nil && err.Error() != utils.ErrNoRow() {
  5034. if err.Error() == utils.ErrNoRow() {
  5035. br.Msg = "客户信息不存在"
  5036. br.ErrMsg = "客户信息不存在,Err:" + err.Error()
  5037. return
  5038. }
  5039. br.Msg = "获取客户信息失败"
  5040. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  5041. return
  5042. }
  5043. if cp == nil {
  5044. br.Msg = "客户信息不存在,请刷新页面"
  5045. br.ErrMsg = "客户信息不存在"
  5046. return
  5047. }
  5048. err = company.MoveCompanySeller(req.CompanyId, productId, req.SellsId, seller.GroupId, seller.DepartmentId, seller.RealName)
  5049. if err != nil {
  5050. br.Msg = "移动失败"
  5051. br.ErrMsg = "移动失败,Err:" + err.Error()
  5052. return
  5053. }
  5054. //新增操作记录
  5055. {
  5056. remark := "移动到:" + seller.RealName
  5057. operation := "move_seller"
  5058. services.AddCompanyOperationRecord(req.CompanyId, seller.AdminId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
  5059. cp.ProductName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
  5060. }
  5061. //变更销售员与联系人关系
  5062. _ = models.UpdateUserSellerRelationByCompanyId(req.CompanyId, productId, seller.AdminId, seller.RealName)
  5063. br.Ret = 200
  5064. br.Success = true
  5065. br.Msg = "移动成功"
  5066. }
  5067. // @Title 修改试用客户标签
  5068. // @Description 修改试用客户标签接口
  5069. // @Param request body company.UpdateTryStageReq true "type json string"
  5070. // @Success Ret=200 设置成功
  5071. // @router /update/tryStage [post]
  5072. func (this *CompanyController) UpdateTryStage() {
  5073. br := new(models.BaseResponse).Init()
  5074. defer func() {
  5075. this.Data["json"] = br
  5076. this.ServeJSON()
  5077. }()
  5078. sysUser := this.SysUser
  5079. if sysUser == nil {
  5080. br.Msg = "请登录"
  5081. br.ErrMsg = "请登录,SysUser Is Empty"
  5082. br.Ret = 408
  5083. return
  5084. }
  5085. var req company.UpdateTryStageReq
  5086. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5087. if err != nil {
  5088. br.Msg = "参数解析异常!"
  5089. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5090. return
  5091. }
  5092. if req.CompanyId <= 0 {
  5093. br.Msg = "参数异常!"
  5094. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  5095. return
  5096. }
  5097. if req.ProductId <= 0 {
  5098. br.Msg = "参数异常!"
  5099. br.ErrMsg = "ProductId:" + strconv.Itoa(req.ProductId)
  5100. return
  5101. }
  5102. if req.TryStage <= 0 {
  5103. br.Msg = "参数异常!"
  5104. br.ErrMsg = "TryStage:" + strconv.Itoa(req.TryStage)
  5105. return
  5106. }
  5107. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  5108. if err != nil && err.Error() != utils.ErrNoRow() {
  5109. if err.Error() == utils.ErrNoRow() {
  5110. br.Msg = "客户信息不存在"
  5111. br.ErrMsg = "客户信息不存在,Err:" + err.Error()
  5112. return
  5113. }
  5114. br.Msg = "获取客户信息失败"
  5115. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  5116. return
  5117. }
  5118. fmt.Println(cp)
  5119. if cp == nil {
  5120. br.Msg = "客户信息不存在,请刷新页面"
  5121. br.ErrMsg = "客户信息不存在"
  5122. return
  5123. }
  5124. if cp.Status != "试用" {
  5125. br.Msg = "客户不是试用状态,不允许修改"
  5126. br.ErrMsg = "客户不是试用状态,不允许修改"
  5127. return
  5128. }
  5129. if cp.SellerId != sysUser.AdminId {
  5130. br.Msg = "无修改权限"
  5131. br.ErrMsg = "无修改权限"
  5132. return
  5133. }
  5134. if cp.TryStage == req.TryStage {
  5135. br.Msg = "与原标签一致,无需修改"
  5136. br.ErrMsg = "与原标签一致,无需修改"
  5137. return
  5138. }
  5139. err = company.UpdateCompanyTryStage(req.CompanyId, req.ProductId, req.TryStage)
  5140. if err != nil {
  5141. br.Msg = "设置失败"
  5142. br.ErrMsg = "设置失败,Err:" + err.Error()
  5143. return
  5144. }
  5145. //新增操作记录
  5146. {
  5147. stage := ""
  5148. tryStageAllMap := map[int]string{
  5149. 1: "未分类",
  5150. 2: "推进",
  5151. 3: "跟踪",
  5152. 4: "预备",
  5153. }
  5154. if v, ok := tryStageAllMap[req.TryStage]; ok {
  5155. stage = v
  5156. }
  5157. remark := "修改试用客户子标签:" + stage
  5158. operation := "UpdateTryStage"
  5159. services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  5160. cp.ProductName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
  5161. }
  5162. br.Ret = 200
  5163. br.Success = true
  5164. br.Msg = "设置成功"
  5165. }
  5166. // @Title 暂停/启用
  5167. // @Description 暂停/启用接口
  5168. // @Param request body company.SuspendReq true "type json string"
  5169. // @Success Ret=200 移动成功
  5170. // @router /suspend [post]
  5171. func (this *CompanyController) Suspend() {
  5172. br := new(models.BaseResponse).Init()
  5173. defer func() {
  5174. this.Data["json"] = br
  5175. this.ServeJSON()
  5176. }()
  5177. sysUser := this.SysUser
  5178. if sysUser == nil {
  5179. br.Msg = "请登录"
  5180. br.ErrMsg = "请登录,SysUser Is Empty"
  5181. br.Ret = 408
  5182. return
  5183. }
  5184. var req company.SuspendReq
  5185. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5186. if err != nil {
  5187. br.Msg = "参数解析异常!"
  5188. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5189. return
  5190. }
  5191. if req.CompanyId <= 0 {
  5192. br.Msg = "参数异常!"
  5193. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  5194. return
  5195. }
  5196. roleTypeCode := sysUser.RoleTypeCode
  5197. productId := services.GetProductId(roleTypeCode)
  5198. if productId == 0 {
  5199. br.Msg = "参数错误"
  5200. br.ErrMsg = "角色类型为:" + roleTypeCode
  5201. return
  5202. }
  5203. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  5204. if err != nil {
  5205. br.Msg = "获取数据异常!"
  5206. br.ErrMsg = "获取数据异常:" + err.Error()
  5207. return
  5208. }
  5209. suspendStatus := ""
  5210. suspend := 0
  5211. if cp.IsSuspend == 1 {
  5212. suspendStatus = "启用"
  5213. suspend = 0
  5214. } else {
  5215. suspendStatus = "暂停"
  5216. suspend = 1
  5217. }
  5218. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  5219. br.Msg = "客户状态为:" + cp.Status + ",不允许进行" + suspendStatus + "操作"
  5220. br.ErrMsg = "客户状态为:" + cp.Status + ",不允许进行" + suspendStatus + "操作"
  5221. return
  5222. }
  5223. err = company.SuspendCompanyProductById(req.CompanyId, productId, suspend)
  5224. if err != nil {
  5225. br.Msg = suspendStatus + "失败"
  5226. br.ErrMsg = suspendStatus + "失败 Err:" + err.Error()
  5227. return
  5228. }
  5229. //新增操作记录
  5230. {
  5231. remark := suspendStatus
  5232. operation := "is_suspend"
  5233. services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
  5234. cp.ProductName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
  5235. }
  5236. br.Ret = 200
  5237. br.Success = true
  5238. br.Msg = suspendStatus + "成功"
  5239. }
  5240. // @Title 检测客户名称或社会信用码
  5241. // @Description 检测客户名称或社会信用码接口(新增/编辑客户页面使用)
  5242. // @Param CompanyName query string true "客户名称"
  5243. // @Param CreditCode query string true "社会统一信用码"
  5244. // @Success 200 {object} company.CheckCompanyInfoResp
  5245. // @router /check/companyInfo [get]
  5246. func (this *CompanyController) CheckCompanyInfo() {
  5247. br := new(models.BaseResponse).Init()
  5248. defer func() {
  5249. this.Data["json"] = br
  5250. this.ServeJSON()
  5251. }()
  5252. sysUser := this.SysUser
  5253. if sysUser == nil {
  5254. br.Msg = "请登录"
  5255. br.ErrMsg = "请登录,SysUser Is Empty"
  5256. br.Ret = 408
  5257. return
  5258. }
  5259. roleTypeCode := sysUser.RoleTypeCode
  5260. productId := services.GetProductId(roleTypeCode)
  5261. companyName := this.GetString("CompanyName")
  5262. creditCode := this.GetString("CreditCode")
  5263. var status, comanyId int
  5264. var productName string
  5265. if productId == 0 {
  5266. productId = 1
  5267. checkProductId := 2
  5268. if companyName != "" {
  5269. nameItem, err := company.CheckCompanyProductByName(companyName, productId)
  5270. if err != nil && err.Error() != utils.ErrNoRow() {
  5271. br.Msg = "校验客户名称是否存在失败"
  5272. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
  5273. return
  5274. }
  5275. if nameItem != nil && nameItem.CompanyId > 0 {
  5276. br.Msg = "客户名称已存在,请重新填写"
  5277. br.ErrMsg = "客户名称已存在,请重新填写"
  5278. br.Ret = 405
  5279. return
  5280. }
  5281. nameCheckItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
  5282. if err != nil && err.Error() != utils.ErrNoRow() {
  5283. br.Msg = "校验客户名称是否存在失败"
  5284. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5285. return
  5286. }
  5287. if nameCheckItem != nil && nameCheckItem.CompanyId > 0 {
  5288. status = 1
  5289. productName = nameCheckItem.ProductName
  5290. comanyId = nameCheckItem.CompanyId
  5291. goto Loop
  5292. }
  5293. }
  5294. if creditCode != "" {
  5295. codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
  5296. if err != nil && err.Error() != utils.ErrNoRow() {
  5297. br.Msg = "校验社会信用码是否存在失败"
  5298. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
  5299. return
  5300. }
  5301. if codeItem != nil && codeItem.CompanyId > 0 {
  5302. br.Msg = "社会信用码已存在,请重新填写"
  5303. br.ErrMsg = "社会信用码已存在,请重新填写"
  5304. br.Ret = 405
  5305. return
  5306. }
  5307. codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
  5308. if err != nil && err.Error() != utils.ErrNoRow() {
  5309. br.Msg = "校验社会信用码是否存在失败"
  5310. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5311. return
  5312. }
  5313. if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
  5314. status = 1
  5315. productName = codeCheckItem.ProductName
  5316. comanyId = codeCheckItem.CompanyId
  5317. goto Loop
  5318. }
  5319. }
  5320. productId = 2
  5321. checkProductId = 1
  5322. if companyName != "" {
  5323. nameItem, err := company.CheckCompanyProductByName(companyName, productId)
  5324. if err != nil && err.Error() != utils.ErrNoRow() {
  5325. br.Msg = "校验客户名称是否存在失败"
  5326. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
  5327. return
  5328. }
  5329. if nameItem != nil && nameItem.CompanyId > 0 {
  5330. br.Msg = "客户名称已存在,请重新填写"
  5331. br.ErrMsg = "客户名称已存在,请重新填写"
  5332. br.Ret = 405
  5333. return
  5334. }
  5335. nameCheckItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
  5336. if err != nil && err.Error() != utils.ErrNoRow() {
  5337. br.Msg = "校验客户名称是否存在失败"
  5338. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5339. return
  5340. }
  5341. if nameCheckItem != nil && nameCheckItem.CompanyId > 0 {
  5342. status = 1
  5343. productName = nameCheckItem.ProductName
  5344. comanyId = nameCheckItem.CompanyId
  5345. goto Loop
  5346. }
  5347. }
  5348. if creditCode != "" {
  5349. codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
  5350. if err != nil && err.Error() != utils.ErrNoRow() {
  5351. br.Msg = "校验社会信用码是否存在失败"
  5352. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
  5353. return
  5354. }
  5355. if codeItem != nil && codeItem.CompanyId > 0 {
  5356. br.Msg = "社会信用码已存在,请重新填写"
  5357. br.ErrMsg = "社会信用码已存在,请重新填写"
  5358. br.Ret = 405
  5359. return
  5360. }
  5361. codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
  5362. if err != nil && err.Error() != utils.ErrNoRow() {
  5363. br.Msg = "校验社会信用码是否存在失败"
  5364. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5365. return
  5366. }
  5367. if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
  5368. status = 1
  5369. productName = codeCheckItem.ProductName
  5370. comanyId = codeCheckItem.CompanyId
  5371. goto Loop
  5372. }
  5373. }
  5374. } else {
  5375. checkProductId := 0
  5376. if productId == 1 {
  5377. checkProductId = 2
  5378. } else if productId == 2 {
  5379. checkProductId = 1
  5380. }
  5381. if companyName != "" {
  5382. nameItem, err := company.CheckCompanyProductByName(companyName, productId)
  5383. if err != nil && err.Error() != utils.ErrNoRow() {
  5384. br.Msg = "校验客户名称是否存在失败"
  5385. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
  5386. return
  5387. }
  5388. if nameItem != nil && nameItem.ProductName != "" {
  5389. br.Msg = "客户名称已存在,请重新填写"
  5390. br.ErrMsg = "客户名称已存在,请重新填写"
  5391. br.Ret = 405
  5392. return
  5393. }
  5394. nameCheckoutItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
  5395. if err != nil && err.Error() != utils.ErrNoRow() {
  5396. br.Msg = "校验客户名称是否存在失败"
  5397. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5398. return
  5399. }
  5400. if nameCheckoutItem != nil && nameCheckoutItem.CompanyId > 0 {
  5401. status = 1
  5402. productName = nameCheckoutItem.ProductName
  5403. comanyId = nameCheckoutItem.CompanyId
  5404. goto Loop
  5405. }
  5406. }
  5407. if creditCode != "" {
  5408. codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
  5409. if err != nil && err.Error() != utils.ErrNoRow() {
  5410. br.Msg = "校验社会信用码是否存在失败"
  5411. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
  5412. return
  5413. }
  5414. if codeItem != nil && codeItem.CompanyId > 0 {
  5415. br.Msg = "社会信用码已存在,请重新填写"
  5416. br.ErrMsg = "社会信用码已存在,请重新填写"
  5417. br.Ret = 405
  5418. return
  5419. }
  5420. codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
  5421. if err != nil && err.Error() != utils.ErrNoRow() {
  5422. br.Msg = "校验社会信用码是否存在失败"
  5423. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5424. return
  5425. }
  5426. if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
  5427. status = 1
  5428. productName = codeCheckItem.ProductName
  5429. comanyId = codeCheckItem.CompanyId
  5430. goto Loop
  5431. }
  5432. }
  5433. }
  5434. Loop:
  5435. resp := new(company.CheckCompanyInfoResp)
  5436. resp.Status = status
  5437. resp.ProductName = productName
  5438. resp.CompanyId = comanyId
  5439. br.Ret = 200
  5440. br.Success = true
  5441. br.Msg = "获取成功"
  5442. br.Data = resp
  5443. }
  5444. // @Title 客户导出
  5445. // @Description 客户导出接口
  5446. // @Param Status query string true "状态:'试用','永续','冻结','流失','正式'"
  5447. // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
  5448. // @Param IndustryId query int true "行业id,0为全部"
  5449. // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
  5450. // @Param ChartPermissionIds query string false "阅读权限品种ID,多个用英文逗号分开,空字符串为全部"
  5451. // @Param ContractPermissionIds query string false "已购品种ID,多个用英文逗号分开,空字符串为全部"
  5452. // @Param StartDate query string true "开始时间"
  5453. // @Param EndDate query string true "结束时间"
  5454. // @Param CreateStartDate query string true "创建开始时间"
  5455. // @Param CreateEndDate query string true "创建结束时间"
  5456. // @Param KeyWord query string true "搜索关键词"
  5457. // @Param Address query string true "地址 , 多个用英文逗号分开 "
  5458. // @Param Province query string true "省 , 多个用英文逗号分开 "
  5459. // @Param City query string true "市 , 多个用英文逗号分开 "
  5460. // @Param PackageType query int true "套餐类型,0:无,1:大套餐,2:小套餐"
  5461. // @Success 200 {object} company.CompanyListResp
  5462. // @router /export [get]
  5463. func (this *CompanyController) Export() {
  5464. br := new(models.BaseResponse).Init()
  5465. defer func() {
  5466. this.Data["json"] = br
  5467. this.ServeJSON()
  5468. }()
  5469. sysUser := this.SysUser
  5470. if sysUser == nil {
  5471. br.Msg = "请登录"
  5472. br.ErrMsg = "请登录,SysUser Is Empty"
  5473. br.Ret = 408
  5474. return
  5475. }
  5476. roleTypeCode := sysUser.RoleTypeCode
  5477. status := this.GetString("Status")
  5478. companyType := this.GetString("CompanyType")
  5479. industryId, _ := this.GetInt("IndustryId")
  5480. adminId := this.GetString("AdminId")
  5481. chartPermissionIds := this.GetString("ChartPermissionIds")
  5482. contractPermissionIds := this.GetString("ContractPermissionIds")
  5483. startDate := this.GetString("StartDate")
  5484. endDate := this.GetString("EndDate")
  5485. createStartDate := this.GetString("CreateStartDate")
  5486. createEndDate := this.GetString("CreateEndDate")
  5487. keyWord := this.GetString("KeyWord")
  5488. keyWord = strings.Trim(keyWord, " ")
  5489. address := this.GetString("Address")
  5490. province := this.GetString("Province")
  5491. city := this.GetString("City")
  5492. // 套餐类型
  5493. packageType, _ := this.GetInt("PackageType")
  5494. resp := new(company.CompanyListResp)
  5495. statusItems := make([]*company.CompanyStatus, 0)
  5496. var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}
  5497. var condition string
  5498. var pars []interface{}
  5499. //状态分类查询条件
  5500. var permissionCondition string
  5501. var permissionPars []interface{}
  5502. if companyType != "" {
  5503. condition += ` AND b.product_name=? `
  5504. pars = append(pars, companyType)
  5505. }
  5506. if industryId > 0 {
  5507. condition += ` AND b.industry_id=? `
  5508. pars = append(pars, industryId)
  5509. }
  5510. if adminId != "" {
  5511. condition += ` AND b.seller_id IN (` + adminId + `) `
  5512. }
  5513. if startDate != "" {
  5514. condition += ` AND b.start_date>=? `
  5515. pars = append(pars, startDate)
  5516. }
  5517. if endDate != "" {
  5518. condition += ` AND b.end_date<=? `
  5519. pars = append(pars, endDate)
  5520. }
  5521. if createStartDate != "" {
  5522. condition += ` AND a.created_time>=? `
  5523. pars = append(pars, createStartDate)
  5524. }
  5525. if createEndDate != "" {
  5526. condition += ` AND a.created_time<=? `
  5527. pars = append(pars, createEndDate)
  5528. }
  5529. if address != "" {
  5530. var addressSql string
  5531. slice := strings.Split(address, ",")
  5532. for _, v := range slice {
  5533. addressSql += "'" + v + "'" + ","
  5534. }
  5535. addressSql = strings.TrimRight(addressSql, ",")
  5536. condition += ` AND a.address IN (` + addressSql + `) `
  5537. }
  5538. if province != "" {
  5539. var provinceSql string
  5540. slice := strings.Split(province, ",")
  5541. for _, v := range slice {
  5542. provinceSql += "'" + v + "'" + ","
  5543. }
  5544. provinceSql = strings.TrimRight(provinceSql, ",")
  5545. condition += ` AND a.province IN (` + provinceSql + `) `
  5546. }
  5547. if city != "" {
  5548. var citySql string
  5549. slice := strings.Split(city, ",")
  5550. for _, v := range slice {
  5551. citySql += "'" + v + "'" + ","
  5552. }
  5553. citySql = strings.TrimRight(citySql, ",")
  5554. condition += ` AND a.city IN (` + citySql + `) `
  5555. }
  5556. if keyWord != "" {
  5557. companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
  5558. if err != nil {
  5559. br.Msg = "获取客户信息失败"
  5560. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  5561. return
  5562. }
  5563. if companyIdStr != "" {
  5564. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  5565. } else {
  5566. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  5567. }
  5568. }
  5569. //if chartPermissionIds != "" && chartPermissionIds != "1" {
  5570. // companyIdStr, err := company.GetCompanyListCompanyIdByPermissionIdStr(chartPermissionIds)
  5571. // if err != nil {
  5572. // br.Msg = "获取失败"
  5573. // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
  5574. // return
  5575. // }
  5576. // if companyIdStr != "" {
  5577. // condition += ` AND a.company_id IN (` + companyIdStr + `) `
  5578. // } else {
  5579. // for _, v := range statusArr {
  5580. // statusCount := new(company.CompanyStatus)
  5581. // if v == "全部" {
  5582. // statusCount.Status = "全部"
  5583. // statusCount.Count = 0
  5584. // } else {
  5585. // statusCount.Status = v
  5586. // statusCount.Count = 0
  5587. // }
  5588. // statusItems = append(statusItems, statusCount)
  5589. // }
  5590. // items := make([]*company.CompanyListItem, 0)
  5591. // resp.List = items
  5592. // resp.StatusCount = statusItems
  5593. // br.Msg = "获取成功"
  5594. // br.Ret = 200
  5595. // br.Data = resp
  5596. // return
  5597. // }
  5598. //}
  5599. // 阅读权限/已购品种筛选
  5600. cond, emp, e := services.FilterReadAndContractAuth(chartPermissionIds, contractPermissionIds, condition)
  5601. if e != nil {
  5602. br.Msg = "获取失败"
  5603. br.ErrMsg = "FilterReadAndContractAuth err: " + e.Error()
  5604. return
  5605. }
  5606. if emp {
  5607. for _, v := range statusArr {
  5608. statusCount := new(company.CompanyStatus)
  5609. if v == "全部" {
  5610. statusCount.Status = "全部"
  5611. statusCount.Count = 0
  5612. } else {
  5613. statusCount.Status = v
  5614. statusCount.Count = 0
  5615. }
  5616. statusItems = append(statusItems, statusCount)
  5617. }
  5618. items := make([]*company.CompanyListItem, 0)
  5619. resp.List = items
  5620. resp.StatusCount = statusItems
  5621. br.Msg = "获取成功"
  5622. br.Ret = 200
  5623. br.Data = resp
  5624. return
  5625. }
  5626. condition = cond
  5627. //套餐类型
  5628. if packageType > 0 {
  5629. condition += ` AND b.package_type=? `
  5630. pars = append(pars, packageType)
  5631. }
  5632. permissionCondition = condition
  5633. permissionPars = pars
  5634. productId := services.GetProductId(roleTypeCode)
  5635. //权限控制
  5636. {
  5637. //如果不是超级管理员
  5638. if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  5639. //如果是部门管理员
  5640. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  5641. condition += ` AND b.product_id=? `
  5642. pars = append(pars, productId)
  5643. permissionCondition += ` AND b.product_id=? `
  5644. permissionPars = append(permissionPars, productId)
  5645. } else {
  5646. condition += ` AND b.product_id=? `
  5647. pars = append(pars, productId)
  5648. permissionCondition += ` AND b.product_id=? `
  5649. permissionPars = append(permissionPars, productId)
  5650. if status == "全部" {
  5651. ////如果是筛选了流失客户状态
  5652. if sysUser.Authority <= 0 {
  5653. condition += ` AND (b.seller_id=? OR status='流失') `
  5654. pars = append(pars, sysUser.AdminId)
  5655. permissionCondition += ` AND b.seller_id=? `
  5656. permissionPars = append(permissionPars, sysUser.AdminId)
  5657. } else {
  5658. if sysUser.Authority == 1 {
  5659. condition += ` AND (b.department_id=? OR status='流失')`
  5660. pars = append(pars, sysUser.DepartmentId)
  5661. permissionCondition += ` AND b.department_id=? `
  5662. permissionPars = append(permissionPars, sysUser.DepartmentId)
  5663. }
  5664. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  5665. if status != utils.COMPANY_STATUS_LOSE {
  5666. condition += ` AND (b.group_id=? OR status='流失') `
  5667. pars = append(pars, sysUser.GroupId)
  5668. }
  5669. permissionCondition += ` AND b.group_id=? `
  5670. permissionPars = append(permissionPars, sysUser.GroupId)
  5671. }
  5672. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  5673. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  5674. if err != nil {
  5675. br.Msg = "获取失败"
  5676. br.ErrMsg = "查询父级id异常" + err.Error()
  5677. return
  5678. }
  5679. var ids []*string
  5680. if pid != nil && *pid != 0 {
  5681. ids, err = company.GetGroupIdsByParentId(*pid)
  5682. if err != nil {
  5683. fmt.Println(err.Error())
  5684. }
  5685. } else {
  5686. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  5687. if err != nil {
  5688. fmt.Println(err.Error())
  5689. }
  5690. }
  5691. var idSlice []string
  5692. var sid string
  5693. for _, id := range ids {
  5694. idSlice = append(idSlice, *id)
  5695. }
  5696. //加入父级groupId
  5697. if *pid > 0 {
  5698. idSlice = append(idSlice, strconv.Itoa(*pid))
  5699. } else {
  5700. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  5701. }
  5702. sid = strings.Join(idSlice, ",")
  5703. if len(sid) > 0 {
  5704. if status != utils.COMPANY_STATUS_LOSE {
  5705. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  5706. //pars = append(pars, sysUser.GroupId)
  5707. }
  5708. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  5709. } else {
  5710. if status != utils.COMPANY_STATUS_LOSE {
  5711. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  5712. //pars = append(pars, sysUser.GroupId)
  5713. }
  5714. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  5715. }
  5716. }
  5717. }
  5718. } else {
  5719. ////如果没有筛选了流失客户状态
  5720. if sysUser.Authority <= 0 {
  5721. condition += ` AND b.seller_id=? `
  5722. pars = append(pars, sysUser.AdminId)
  5723. permissionCondition += ` AND b.seller_id=? `
  5724. permissionPars = append(permissionPars, sysUser.AdminId)
  5725. } else {
  5726. if sysUser.Authority == 1 {
  5727. condition += ` AND b.department_id=?`
  5728. pars = append(pars, sysUser.DepartmentId)
  5729. permissionCondition += ` AND b.department_id=? `
  5730. permissionPars = append(permissionPars, sysUser.DepartmentId)
  5731. }
  5732. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  5733. if status != utils.COMPANY_STATUS_LOSE {
  5734. condition += ` AND b.group_id=? `
  5735. pars = append(pars, sysUser.GroupId)
  5736. }
  5737. permissionCondition += ` AND b.group_id=? `
  5738. permissionPars = append(permissionPars, sysUser.GroupId)
  5739. }
  5740. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  5741. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  5742. if err != nil {
  5743. br.Msg = "获取失败"
  5744. br.ErrMsg = "查询父级id异常" + err.Error()
  5745. return
  5746. }
  5747. var ids []*string
  5748. if pid != nil && *pid != 0 {
  5749. ids, err = company.GetGroupIdsByParentId(*pid)
  5750. if err != nil {
  5751. fmt.Println(err.Error())
  5752. }
  5753. } else {
  5754. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  5755. if err != nil {
  5756. fmt.Println(err.Error())
  5757. }
  5758. }
  5759. var idSlice []string
  5760. var sid string
  5761. for _, id := range ids {
  5762. idSlice = append(idSlice, *id)
  5763. }
  5764. //加入父级groupId
  5765. if *pid > 0 {
  5766. idSlice = append(idSlice, strconv.Itoa(*pid))
  5767. } else {
  5768. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  5769. }
  5770. sid = strings.Join(idSlice, ",")
  5771. if len(sid) > 0 {
  5772. if status != utils.COMPANY_STATUS_LOSE {
  5773. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  5774. //pars = append(pars, sysUser.GroupId)
  5775. }
  5776. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  5777. } else {
  5778. if status != utils.COMPANY_STATUS_LOSE {
  5779. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  5780. //pars = append(pars, sysUser.GroupId)
  5781. }
  5782. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  5783. }
  5784. }
  5785. if sysUser.Authority == 4 {
  5786. if status != utils.COMPANY_STATUS_LOSE {
  5787. condition += ` AND b.group_id =? `
  5788. pars = append(pars, sysUser.GroupId)
  5789. }
  5790. permissionCondition += ` AND b.group_id=? `
  5791. permissionPars = append(permissionPars, sysUser.GroupId)
  5792. }
  5793. }
  5794. }
  5795. }
  5796. }
  5797. }
  5798. //状态控制
  5799. if status != "" && status != "全部" && status != utils.COMPANY_STATUS_LOSE {
  5800. condition += ` AND b.status=? `
  5801. pars = append(pars, status)
  5802. }
  5803. dir, err := os.Executable()
  5804. exPath := filepath.Dir(dir)
  5805. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  5806. xlsxFile := xlsx.NewFile()
  5807. if err != nil {
  5808. br.Msg = "生成文件失败"
  5809. br.ErrMsg = "生成文件失败"
  5810. return
  5811. }
  5812. style := xlsx.NewStyle()
  5813. alignment := xlsx.Alignment{
  5814. Horizontal: "center",
  5815. Vertical: "center",
  5816. WrapText: true,
  5817. }
  5818. style.Alignment = alignment
  5819. style.ApplyAlignment = true
  5820. sheel, err := xlsxFile.AddSheet("客户数据")
  5821. if err != nil {
  5822. br.Msg = "新增Sheet失败"
  5823. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  5824. return
  5825. }
  5826. titleArr := []string{"客户名称", "客户地址", "客户类型", "所属行业", "所属销售", "客户状态", "服务期限", "到期天数", "创建时间", "权限详情"}
  5827. titleLen := len(titleArr)
  5828. titleRow := sheel.AddRow()
  5829. remarkRow := sheel.AddRow() // 备注行
  5830. // 填充空白至Z列
  5831. emptyColNum := 0
  5832. for i := 0; i < 26; i++ {
  5833. remarkRow.AddCell().SetValue("")
  5834. if i >= titleLen {
  5835. emptyColNum += 1
  5836. titleRow.AddCell().SetValue("")
  5837. continue
  5838. }
  5839. titleRow.AddCell().SetValue(titleArr[i])
  5840. }
  5841. // AA列开始为品种权限
  5842. ficcPermissions := make([]int, 0) // 用于后续判断试用暂停客户是否需要暂停这部分权限
  5843. raiPermissions := make([]int, 0)
  5844. permissions, e := models.GetChartPermissionList()
  5845. if e != nil {
  5846. br.Msg = "获取失败"
  5847. br.ErrMsg = "获取品种数据失败,Err:" + err.Error()
  5848. return
  5849. }
  5850. raiArr := []string{"医药", "消费", "科技", "智造"}
  5851. for _, p := range permissions {
  5852. if p.ProductId == 1 {
  5853. ficcPermissions = append(ficcPermissions, p.ChartPermissionId)
  5854. }
  5855. if p.ProductId == 2 {
  5856. raiPermissions = append(raiPermissions, p.ChartPermissionId)
  5857. }
  5858. if utils.InArrayByStr(raiArr, p.PermissionName) {
  5859. titleRow.AddCell().SetValue(p.Remark)
  5860. continue
  5861. }
  5862. titleRow.AddCell().SetValue(p.PermissionName)
  5863. }
  5864. // 第二行, 在品种权限开始列加一行标红备注
  5865. styleRed := xlsx.NewStyle()
  5866. styleRed.Font.Color = "ff0000"
  5867. remarkCell := remarkRow.AddCell()
  5868. remarkCell.SetStyle(styleRed)
  5869. remarkCell.SetString(`第一位数字表示是否已购买该品种,1表示已购,0表示未购;第二位数字表示是否有阅读权限,1表示有权限,0表示没有`)
  5870. list, err := company.GetCompanyListExport(condition, pars)
  5871. if err != nil {
  5872. br.Msg = "获取失败"
  5873. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  5874. return
  5875. }
  5876. companyIds := make([]int, 0)
  5877. for _, c := range list {
  5878. companyIds = append(companyIds, c.CompanyId)
  5879. }
  5880. // 获取客户对应的阅读和合同权限集合
  5881. contractPermissionMap := make(map[int][]int)
  5882. contractPermissions, e := company.GetContractPermissionIdsByCompanyIds(companyIds)
  5883. if e != nil {
  5884. br.Msg = "获取失败"
  5885. br.ErrMsg = "获取已购权限失败, Err: " + e.Error()
  5886. return
  5887. }
  5888. for _, p := range contractPermissions {
  5889. ids := make([]int, 0)
  5890. if p.ChartPermissionIds != "" {
  5891. idArr := strings.Split(p.ChartPermissionIds, ",")
  5892. for _, i := range idArr {
  5893. id, _ := strconv.Atoi(i)
  5894. ids = append(ids, id)
  5895. }
  5896. }
  5897. contractPermissionMap[p.CompanyId] = ids
  5898. }
  5899. reportPermissionMap := make(map[int][]int)
  5900. reportPermissions, e := company.GetReportPermissionIdsByCompanyIds(companyIds)
  5901. if e != nil {
  5902. br.Msg = "获取失败"
  5903. br.ErrMsg = "获取阅读权限失败, Err: " + e.Error()
  5904. return
  5905. }
  5906. for _, p := range reportPermissions {
  5907. ids := make([]int, 0)
  5908. if p.ChartPermissionIds != "" {
  5909. idArr := strings.Split(p.ChartPermissionIds, ",")
  5910. for _, i := range idArr {
  5911. id, _ := strconv.Atoi(i)
  5912. ids = append(ids, id)
  5913. }
  5914. }
  5915. reportPermissionMap[p.CompanyId] = ids
  5916. }
  5917. cpMap := make(map[int][]*company.ExportCompanyProduct)
  5918. permissionMap := make(map[string]string)
  5919. for _, v := range list {
  5920. cpList := make([]*company.ExportCompanyProduct, 1)
  5921. if cps, ok := cpMap[v.CompanyId]; ok {
  5922. cpList = cps
  5923. } else {
  5924. companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  5925. if err != nil {
  5926. br.Msg = "导出失败"
  5927. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  5928. return
  5929. }
  5930. cpMap[v.CompanyId] = companyProduct
  5931. cpList = companyProduct
  5932. }
  5933. var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, expireDay string
  5934. isFiccSuspend := 0
  5935. isRaiSuspend := 0
  5936. for ck, cv := range cpList {
  5937. companyName = cv.CompanyName
  5938. if ck >= 1 {
  5939. companyType = companyType + "/" + cv.ProductName
  5940. status = status + "/" + cv.Status
  5941. } else {
  5942. companyType = cv.ProductName
  5943. status = cv.Status
  5944. }
  5945. if cv.ProductId == 1 {
  5946. industryName = "ficc:" + cv.IndustryName
  5947. sellerName = "ficc:" + cv.SellerName
  5948. startDateStr := cv.StartDate.Format("2006/01/02")
  5949. endDateStr := cv.EndDate.Format("2006/01/02")
  5950. timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  5951. createTime = "ficc:" + cv.CreateTime
  5952. source = "ficc:" + cv.Source
  5953. sub := cv.EndDate.Sub(time.Now())
  5954. if sub < 0 {
  5955. sub = 0
  5956. }
  5957. expireDay = "ficc:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  5958. permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  5959. permissionStr = "ficc:"
  5960. if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  5961. permissionStr += newPermissionStr
  5962. } else {
  5963. getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  5964. if err != nil {
  5965. br.Msg = "导出失败"
  5966. br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  5967. return
  5968. }
  5969. permissionMap[permissionKey] = getPermissionStr
  5970. permissionStr += getPermissionStr
  5971. }
  5972. isFiccSuspend = cv.IsSuspend
  5973. } else {
  5974. industryName = industryName + "\n" + "权益:" + cv.IndustryName
  5975. sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  5976. startDateStr := cv.StartDate.Format("2006/01/02")
  5977. endDateStr := cv.EndDate.Format("2006/01/02")
  5978. timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  5979. createTime = createTime + "\n" + "权益:" + cv.CreateTime
  5980. source = source + "\n" + "权益:" + cv.Source
  5981. sub := cv.EndDate.Sub(time.Now())
  5982. if sub < 0 {
  5983. sub = 0
  5984. }
  5985. expireDay = "\n" + "权益:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  5986. permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  5987. if permissionStr != "" {
  5988. permissionStr = permissionStr + "\n" + "权益:"
  5989. } else {
  5990. permissionStr = "权益:"
  5991. }
  5992. if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  5993. permissionStr += newPermissionStr
  5994. } else {
  5995. getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  5996. if err != nil {
  5997. br.Msg = "导出失败"
  5998. br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  5999. return
  6000. }
  6001. permissionMap[permissionKey] = getPermissionStr
  6002. permissionStr += getPermissionStr
  6003. }
  6004. isRaiSuspend = cv.IsSuspend
  6005. }
  6006. }
  6007. dataRow := sheel.AddRow()
  6008. dataRow.SetHeight(20)
  6009. dataRow.AddCell().SetString(companyName)
  6010. dataRow.AddCell().SetString(v.Address)
  6011. dataRow.AddCell().SetString(companyType)
  6012. dataRow.AddCell().SetString(v.IndustryName)
  6013. dataRow.AddCell().SetString(v.SellerName)
  6014. dataRow.AddCell().SetString(v.Status)
  6015. dataRow.AddCell().SetString(timeLimt)
  6016. dataRow.AddCell().SetString(expireDay)
  6017. dataRow.AddCell().SetString(v.CreatedTime)
  6018. //dataRow.AddCell().SetString(v.Source)
  6019. dataRow.AddCell().SetString(permissionStr)
  6020. // 填充空白至Z列, AA列开始为权限
  6021. for i := 0; i < emptyColNum; i++ {
  6022. dataRow.AddCell().SetString("")
  6023. }
  6024. cpIds := contractPermissionMap[v.CompanyId]
  6025. rpIds := reportPermissionMap[v.CompanyId]
  6026. for _, p := range permissions {
  6027. // 数字含义:11-表示已购且有阅读权限, 01-表示未购买但有阅读权限
  6028. first := 0
  6029. if utils.InArrayByInt(cpIds, p.ChartPermissionId) {
  6030. first = 1
  6031. }
  6032. second := 0
  6033. if utils.InArrayByInt(rpIds, p.ChartPermissionId) {
  6034. second = 1
  6035. // 如果客户是试用暂停, 即使有这部分权限, 也标记为0
  6036. if isFiccSuspend == 1 && utils.InArrayByInt(ficcPermissions, p.ChartPermissionId) {
  6037. second = 0
  6038. }
  6039. if isRaiSuspend == 1 && utils.InArrayByInt(raiPermissions, p.ChartPermissionId) {
  6040. second = 0
  6041. }
  6042. }
  6043. dataRow.AddCell().SetString(fmt.Sprintf("%d%d", first, second))
  6044. }
  6045. }
  6046. err = xlsxFile.Save(downLoadnFilePath)
  6047. if err != nil {
  6048. br.Msg = "保存文件失败"
  6049. br.ErrMsg = "保存文件失败"
  6050. return
  6051. }
  6052. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  6053. downloadFileName := "客户列表_" + randStr + ".xlsx"
  6054. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  6055. defer func() {
  6056. os.Remove(downLoadnFilePath)
  6057. }()
  6058. br.Ret = 200
  6059. br.Success = true
  6060. br.Msg = "导出成功"
  6061. }
  6062. //func (this *CompanyController) ExportOld() {
  6063. // br := new(models.BaseResponse).Init()
  6064. // defer func() {
  6065. // this.Data["json"] = br
  6066. // this.ServeJSON()
  6067. // }()
  6068. // sysUser := this.SysUser
  6069. // if sysUser == nil {
  6070. // br.Msg = "请登录"
  6071. // br.ErrMsg = "请登录,SysUser Is Empty"
  6072. // br.Ret = 408
  6073. // return
  6074. // }
  6075. // roleTypeCode := sysUser.RoleTypeCode
  6076. //
  6077. // status := this.GetString("Status")
  6078. // companyType := this.GetString("CompanyType")
  6079. // industryId, _ := this.GetInt("IndustryId")
  6080. // adminId := this.GetString("AdminId")
  6081. //
  6082. // chartPermissionIds := this.GetString("ChartPermissionIds")
  6083. // startDate := this.GetString("StartDate")
  6084. // endDate := this.GetString("EndDate")
  6085. // createStartDate := this.GetString("CreateStartDate")
  6086. // createEndDate := this.GetString("CreateEndDate")
  6087. // keyWord := this.GetString("KeyWord")
  6088. // keyWord = strings.Trim(keyWord, " ")
  6089. //
  6090. // resp := new(company.CompanyListResp)
  6091. // statusItems := make([]*company.CompanyStatus, 0)
  6092. // var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}
  6093. //
  6094. // var condition string
  6095. // var pars []interface{}
  6096. //
  6097. // var lossCondition string
  6098. // var lossPars []interface{}
  6099. //
  6100. // var permissionCondition string
  6101. // var permissionPars []interface{}
  6102. //
  6103. // if status != "" && status != "全部" {
  6104. // condition += ` AND b.status=? `
  6105. // pars = append(pars, status)
  6106. //
  6107. // //permissionCondition += ` AND b.status=? `
  6108. // //permissionPars = append(permissionPars, status)
  6109. // }
  6110. // if companyType != "" {
  6111. // condition += ` AND b.product_name=? `
  6112. // pars = append(pars, companyType)
  6113. //
  6114. // lossCondition += ` AND b.product_name=? `
  6115. // lossPars = append(lossPars, companyType)
  6116. //
  6117. // permissionCondition += ` AND b.product_name=? `
  6118. // permissionPars = append(permissionPars, companyType)
  6119. // }
  6120. //
  6121. // if industryId > 0 {
  6122. // condition += ` AND b.industry_id=? `
  6123. // pars = append(pars, industryId)
  6124. //
  6125. // lossCondition += ` AND b.industry_id=? `
  6126. // lossPars = append(lossPars, industryId)
  6127. //
  6128. // permissionCondition += ` AND b.industry_id=? `
  6129. // permissionPars = append(permissionPars, industryId)
  6130. // }
  6131. //
  6132. // if adminId != "" {
  6133. // condition += ` AND b.seller_id IN (` + adminId + `) `
  6134. //
  6135. // lossCondition += ` AND b.seller_id IN (` + adminId + `) `
  6136. //
  6137. // permissionCondition += ` AND b.seller_id IN (` + adminId + `) `
  6138. // }
  6139. //
  6140. // if startDate != "" {
  6141. // condition += ` AND b.start_date>=? `
  6142. // pars = append(pars, startDate)
  6143. //
  6144. // lossCondition += ` AND b.start_date>=? `
  6145. // lossPars = append(lossPars, startDate)
  6146. //
  6147. // permissionCondition += ` AND b.start_date>=? `
  6148. // permissionPars = append(permissionPars, startDate)
  6149. // }
  6150. //
  6151. // if endDate != "" {
  6152. // condition += ` AND b.end_date<=? `
  6153. // pars = append(pars, endDate)
  6154. //
  6155. // lossCondition += ` AND b.end_date<=? `
  6156. // lossPars = append(lossPars, endDate)
  6157. //
  6158. // permissionCondition += ` AND b.end_date<=? `
  6159. // permissionPars = append(permissionPars, endDate)
  6160. // }
  6161. //
  6162. // if createStartDate != "" {
  6163. // condition += ` AND a.created_time>=? `
  6164. // pars = append(pars, createStartDate)
  6165. //
  6166. // lossCondition += ` AND a.created_time>=? `
  6167. // lossPars = append(lossPars, createStartDate)
  6168. //
  6169. // permissionCondition += ` AND a.created_time>=? `
  6170. // permissionPars = append(permissionPars, createStartDate)
  6171. // }
  6172. //
  6173. // if createEndDate != "" {
  6174. // condition += ` AND a.created_time<=? `
  6175. // pars = append(pars, createEndDate)
  6176. //
  6177. // lossCondition += ` AND a.created_time<=? `
  6178. // lossPars = append(lossPars, createEndDate)
  6179. //
  6180. // permissionCondition += ` AND a.created_time<=? `
  6181. // permissionPars = append(permissionPars, createEndDate)
  6182. // }
  6183. //
  6184. // if keyWord != "" {
  6185. // companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
  6186. // if err != nil {
  6187. // return
  6188. // }
  6189. // if companyIdStr != "" {
  6190. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  6191. // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  6192. //
  6193. // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  6194. // } else {
  6195. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  6196. // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  6197. //
  6198. // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  6199. // }
  6200. // }
  6201. //
  6202. // if chartPermissionIds != "" && chartPermissionIds != "1" {
  6203. // //chartPermissionArr := strings.Split(chartPermissionIds, ",")
  6204. // //chartPermissionCount := len(chartPermissionArr)
  6205. // companyIdStr, err := company.GetCompanyListCompanyIdByPermissionIdStr(chartPermissionIds)
  6206. // if err != nil {
  6207. // br.Msg = "获取失败"
  6208. // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
  6209. // return
  6210. // }
  6211. // //var companyIdArr []string
  6212. // //for _, v := range companyIdList {
  6213. // // companyIdArr = append(companyIdArr, strconv.Itoa(v.CompanyId))
  6214. // //}
  6215. // //companyIdStr := strings.Join(companyIdArr, ",")
  6216. //
  6217. // if companyIdStr != "" {
  6218. // condition += ` AND a.company_id IN (` + companyIdStr + `) `
  6219. // lossCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  6220. // permissionCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  6221. // } else {
  6222. // for _, v := range statusArr {
  6223. // statusCount := new(company.CompanyStatus)
  6224. // if v == "全部" {
  6225. // statusCount.Status = "全部"
  6226. // statusCount.Count = 0
  6227. // } else {
  6228. // statusCount.Status = v
  6229. // statusCount.Count = 0
  6230. // }
  6231. // statusItems = append(statusItems, statusCount)
  6232. // }
  6233. // items := make([]*company.CompanyListItem, 0)
  6234. // resp.List = items
  6235. // resp.StatusCount = statusItems
  6236. // br.Msg = "获取成功"
  6237. // br.Ret = 200
  6238. // br.Data = resp
  6239. // return
  6240. // }
  6241. // }
  6242. //
  6243. // //权限控制
  6244. // {
  6245. // if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  6246. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  6247. // condition += ` AND b.product_id=? `
  6248. // pars = append(pars, 1)
  6249. //
  6250. // permissionCondition += ` AND b.product_id=? `
  6251. // permissionPars = append(permissionPars, 1)
  6252. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  6253. // condition += ` AND b.product_id=? `
  6254. // pars = append(pars, 2)
  6255. //
  6256. // permissionCondition += ` AND b.product_id=? `
  6257. // permissionPars = append(permissionPars, 2)
  6258. // } else {
  6259. // if sysUser.Authority <= 0 {
  6260. // if status != utils.COMPANY_STATUS_LOSE {
  6261. // condition += ` AND b.seller_id=? `
  6262. // pars = append(pars, sysUser.AdminId)
  6263. // }
  6264. //
  6265. // permissionCondition += ` AND b.seller_id=? `
  6266. // permissionPars = append(permissionPars, sysUser.AdminId)
  6267. // } else {
  6268. // if sysUser.Authority == 1 {
  6269. // if status != utils.COMPANY_STATUS_LOSE {
  6270. // condition += ` AND b.department_id=? `
  6271. // pars = append(pars, sysUser.DepartmentId)
  6272. // }
  6273. // permissionCondition += ` AND b.department_id=? `
  6274. // permissionPars = append(permissionPars, sysUser.DepartmentId)
  6275. // }
  6276. //
  6277. // if sysUser.Authority == 2 {
  6278. // if status != utils.COMPANY_STATUS_LOSE {
  6279. // condition += ` AND b.group_id=? `
  6280. // pars = append(pars, sysUser.GroupId)
  6281. // }
  6282. // permissionCondition += ` AND b.group_id=? `
  6283. // permissionPars = append(permissionPars, sysUser.GroupId)
  6284. // }
  6285. // }
  6286. // }
  6287. // }
  6288. // }
  6289. //
  6290. // dir, err := os.Executable()
  6291. // exPath := filepath.Dir(dir)
  6292. // downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  6293. // xlsxFile := xlsx.NewFile()
  6294. // if err != nil {
  6295. // br.Msg = "生成文件失败"
  6296. // br.ErrMsg = "生成文件失败"
  6297. // return
  6298. // }
  6299. // style := xlsx.NewStyle()
  6300. // alignment := xlsx.Alignment{
  6301. // Horizontal: "center",
  6302. // Vertical: "center",
  6303. // WrapText: true,
  6304. // }
  6305. //
  6306. // style.Alignment = alignment
  6307. // style.ApplyAlignment = true
  6308. //
  6309. // sheel, err := xlsxFile.AddSheet("客户数据")
  6310. // if err != nil {
  6311. // br.Msg = "新增Sheet失败"
  6312. // br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  6313. // return
  6314. // }
  6315. // titleRow := sheel.AddRow()
  6316. // titleRow.AddCell().SetValue("客户名称")
  6317. // titleRow.AddCell().SetValue("客户类型")
  6318. // titleRow.AddCell().SetValue("所属行业")
  6319. // titleRow.AddCell().SetValue("所属销售")
  6320. // titleRow.AddCell().SetValue("客户状态")
  6321. // titleRow.AddCell().SetValue("服务期限")
  6322. // titleRow.AddCell().SetValue("到期天数")
  6323. // titleRow.AddCell().SetValue("创建时间")
  6324. // titleRow.AddCell().SetValue("客户来源")
  6325. // titleRow.AddCell().SetValue("阅读权限")
  6326. //
  6327. // list, err := company.GetCompanyListExport(condition, pars)
  6328. // if err != nil {
  6329. // br.Msg = "获取失败"
  6330. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  6331. // return
  6332. // }
  6333. // cpMap := make(map[int][]*company.ExportCompanyProduct)
  6334. // permissionMap := make(map[string]string)
  6335. // for _, v := range list {
  6336. // cpList := make([]*company.ExportCompanyProduct, 1)
  6337. // if cps, ok := cpMap[v.CompanyId]; ok {
  6338. // cpList = cps
  6339. // } else {
  6340. // companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  6341. // if err != nil {
  6342. // br.Msg = "导出失败"
  6343. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  6344. // return
  6345. // }
  6346. // cpMap[v.CompanyId] = companyProduct
  6347. // cpList = companyProduct
  6348. // }
  6349. // var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, expireDay string
  6350. //
  6351. // for ck, cv := range cpList {
  6352. // companyName = cv.CompanyName
  6353. // if ck >= 1 {
  6354. // companyType = companyType + "/" + cv.ProductName
  6355. // status = status + "/" + cv.Status
  6356. // } else {
  6357. // companyType = cv.ProductName
  6358. // status = cv.Status
  6359. // }
  6360. // if cv.ProductId == 1 {
  6361. // industryName = "ficc:" + cv.IndustryName
  6362. // sellerName = "ficc:" + cv.SellerName
  6363. // startDateStr := cv.StartDate.Format("2006/01/02")
  6364. // endDateStr := cv.EndDate.Format("2006/01/02")
  6365. // timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  6366. // createTime = "ficc:" + cv.CreateTime
  6367. // source = "ficc:" + cv.Source
  6368. // sub := cv.EndDate.Sub(time.Now())
  6369. // if sub < 0 {
  6370. // sub = 0
  6371. // }
  6372. // expireDay = "ficc:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  6373. //
  6374. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6375. //
  6376. // permissionStr = "ficc:"
  6377. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6378. // permissionStr += newPermissionStr
  6379. // } else {
  6380. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6381. // if err != nil {
  6382. // br.Msg = "导出失败"
  6383. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6384. // return
  6385. // }
  6386. // permissionMap[permissionKey] = getPermissionStr
  6387. // permissionStr += getPermissionStr
  6388. // }
  6389. // } else {
  6390. // industryName = industryName + "\n" + "权益:" + cv.IndustryName
  6391. // sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  6392. // startDateStr := cv.StartDate.Format("2006/01/02")
  6393. // endDateStr := cv.EndDate.Format("2006/01/02")
  6394. //
  6395. // timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  6396. // createTime = createTime + "\n" + "权益:" + cv.CreateTime
  6397. // source = source + "\n" + "权益:" + cv.Source
  6398. //
  6399. // sub := cv.EndDate.Sub(time.Now())
  6400. // if sub < 0 {
  6401. // sub = 0
  6402. // }
  6403. // expireDay = "\n" + "权益:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  6404. //
  6405. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6406. // if permissionStr != "" {
  6407. // permissionStr = permissionStr + "\n" + "权益:"
  6408. // } else {
  6409. // permissionStr = "权益:"
  6410. // }
  6411. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6412. // permissionStr += newPermissionStr
  6413. // } else {
  6414. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6415. // if err != nil {
  6416. // br.Msg = "导出失败"
  6417. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6418. // return
  6419. // }
  6420. // permissionMap[permissionKey] = getPermissionStr
  6421. // permissionStr += getPermissionStr
  6422. // }
  6423. // }
  6424. // }
  6425. //
  6426. // dataRow := sheel.AddRow()
  6427. // dataRow.SetHeight(20)
  6428. // dataRow.AddCell().SetString(companyName)
  6429. // dataRow.AddCell().SetString(companyType)
  6430. // dataRow.AddCell().SetString(v.IndustryName)
  6431. // dataRow.AddCell().SetString(v.SellerName)
  6432. // dataRow.AddCell().SetString(v.Status)
  6433. // dataRow.AddCell().SetString(timeLimt)
  6434. // dataRow.AddCell().SetString(expireDay)
  6435. // dataRow.AddCell().SetString(v.CreatedTime)
  6436. // dataRow.AddCell().SetString(v.Source)
  6437. // dataRow.AddCell().SetString(permissionStr)
  6438. // }
  6439. // err = xlsxFile.Save(downLoadnFilePath)
  6440. // if err != nil {
  6441. // br.Msg = "保存文件失败"
  6442. // br.ErrMsg = "保存文件失败"
  6443. // return
  6444. // }
  6445. // randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  6446. // downloadFileName := "客户列表_" + randStr + ".xlsx"
  6447. // this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  6448. // defer func() {
  6449. // os.Remove(downLoadnFilePath)
  6450. // }()
  6451. // br.Ret = 200
  6452. // br.Success = true
  6453. // br.Msg = "导出成功"
  6454. //}
  6455. // @Title 导出
  6456. // @Description 导出接口
  6457. // @Param Status query string true "状态:”试用','永续','冻结','流失','正式'"
  6458. // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
  6459. // @Param IndustryId query int true "行业id,0为全部"
  6460. // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
  6461. // @Param ChartPermissionIds query string false "阅读权限品种ID,多个用英文逗号分开,空字符串为全部"
  6462. // @Param ContractPermissionIds query string false "已购品种ID,多个用英文逗号分开,空字符串为全部"
  6463. // @Param StartDate query string true "开始时间"
  6464. // @Param EndDate query string true "结束时间"
  6465. // @Param KeyWord query string true "搜索关键词"
  6466. // @Param Address query string true "地址 , 多个用英文逗号分开 "
  6467. // @Param Province query string true "省 , 多个用英文逗号分开 "
  6468. // @Param City query string true "市 , 多个用英文逗号分开 "
  6469. // @Param PackageType query int true "套餐类型,0:无,1:大套餐,2:小套餐"
  6470. // @Success Ret=200 移动成功
  6471. // @router /user/export [get]
  6472. func (this *CompanyController) CompanyUserExport() {
  6473. br := new(models.BaseResponse).Init()
  6474. defer func() {
  6475. this.Data["json"] = br
  6476. this.ServeJSON()
  6477. }()
  6478. sysUser := this.SysUser
  6479. if sysUser == nil {
  6480. br.Msg = "请登录"
  6481. br.ErrMsg = "请登录,SysUser Is Empty"
  6482. br.Ret = 408
  6483. return
  6484. }
  6485. roleTypeCode := sysUser.RoleTypeCode
  6486. status := this.GetString("Status")
  6487. companyType := this.GetString("CompanyType")
  6488. industryId, _ := this.GetInt("IndustryId")
  6489. adminId := this.GetString("AdminId")
  6490. chartPermissionIds := this.GetString("ChartPermissionIds")
  6491. contractPermissionIds := this.GetString("ContractPermissionIds")
  6492. startDate := this.GetString("StartDate")
  6493. endDate := this.GetString("EndDate")
  6494. createStartDate := this.GetString("CreateStartDate")
  6495. createEndDate := this.GetString("CreateEndDate")
  6496. keyWord := this.GetString("KeyWord")
  6497. address := this.GetString("Address")
  6498. province := this.GetString("Province")
  6499. city := this.GetString("City")
  6500. // 套餐类型
  6501. packageType, _ := this.GetInt("PackageType")
  6502. var condition string
  6503. var pars []interface{}
  6504. if status != "" && status != "全部" {
  6505. condition += ` AND b.status=? `
  6506. pars = append(pars, status)
  6507. }
  6508. if companyType != "" {
  6509. condition += ` AND b.product_name=? `
  6510. pars = append(pars, companyType)
  6511. }
  6512. if industryId > 0 {
  6513. condition += ` AND b.industry_id=? `
  6514. pars = append(pars, industryId)
  6515. }
  6516. if adminId != "" {
  6517. condition += ` AND b.seller_id IN (` + adminId + `) `
  6518. }
  6519. if startDate != "" {
  6520. condition += ` AND b.start_date>=? `
  6521. pars = append(pars, startDate)
  6522. }
  6523. if endDate != "" {
  6524. condition += ` AND b.end_date<=? `
  6525. pars = append(pars, endDate)
  6526. }
  6527. if createStartDate != "" {
  6528. condition += ` AND a.created_time>=? `
  6529. pars = append(pars, createStartDate)
  6530. }
  6531. if createEndDate != "" {
  6532. condition += ` AND a.created_time<=? `
  6533. pars = append(pars, createEndDate)
  6534. }
  6535. if keyWord != "" {
  6536. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR c.mobile LIKE '%` + keyWord + `%' OR c.email LIKE '%` + keyWord + `%') `
  6537. }
  6538. // 阅读权限/已购品种筛选
  6539. cond, emp, e := services.FilterReadAndContractAuth(chartPermissionIds, contractPermissionIds, condition)
  6540. if e != nil {
  6541. br.Msg = "获取失败"
  6542. br.ErrMsg = "FilterReadAndContractAuth err: " + e.Error()
  6543. return
  6544. }
  6545. if emp {
  6546. condition += ` AND 1 = 2`
  6547. } else {
  6548. condition = cond
  6549. }
  6550. if address != "" {
  6551. var addressSql string
  6552. slice := strings.Split(address, ",")
  6553. for _, v := range slice {
  6554. addressSql += "'" + v + "'" + ","
  6555. }
  6556. addressSql = strings.TrimRight(addressSql, ",")
  6557. condition += ` AND a.address IN (` + addressSql + `) `
  6558. }
  6559. if province != "" {
  6560. var provinceSql string
  6561. slice := strings.Split(province, ",")
  6562. for _, v := range slice {
  6563. provinceSql += "'" + v + "'" + ","
  6564. }
  6565. provinceSql = strings.TrimRight(provinceSql, ",")
  6566. condition += ` AND a.province IN (` + provinceSql + `) `
  6567. }
  6568. if city != "" {
  6569. var citySql string
  6570. slice := strings.Split(city, ",")
  6571. for _, v := range slice {
  6572. citySql += "'" + v + "'" + ","
  6573. }
  6574. citySql = strings.TrimRight(citySql, ",")
  6575. condition += ` AND a.city IN (` + citySql + `) `
  6576. }
  6577. //套餐类型
  6578. if packageType > 0 {
  6579. condition += ` AND b.package_type=? `
  6580. pars = append(pars, packageType)
  6581. }
  6582. //权限控制
  6583. {
  6584. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  6585. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  6586. if status != utils.COMPANY_STATUS_LOSE && status != utils.COMPANY_STATUS_FOREVER {
  6587. condition += ` AND b.seller_id=? `
  6588. pars = append(pars, sysUser.AdminId)
  6589. }
  6590. }
  6591. if sysUser.Authority == 1 {
  6592. condition += ` AND b.department_id=? `
  6593. pars = append(pars, sysUser.DepartmentId)
  6594. }
  6595. if sysUser.Authority == 2 {
  6596. condition += ` AND b.group_id=? `
  6597. pars = append(pars, sysUser.GroupId)
  6598. }
  6599. }
  6600. var statusCond string
  6601. var statusPars []interface{}
  6602. // 根据当前用户角色
  6603. productId := services.GetProductId(roleTypeCode)
  6604. if productId > 0 {
  6605. condition += ` AND b.product_id = ? `
  6606. pars = append(pars, productId)
  6607. statusCond += ` AND b.product_id = ? `
  6608. statusPars = append(statusPars, productId)
  6609. }
  6610. companyIds, err := company.GetExportCompanyIds(condition, pars)
  6611. if err != nil {
  6612. br.Msg = "导出失败"
  6613. br.ErrMsg = "导出失败,Err:" + err.Error()
  6614. return
  6615. }
  6616. dir, err := os.Executable()
  6617. exPath := filepath.Dir(dir)
  6618. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  6619. xlsxFile := xlsx.NewFile()
  6620. if err != nil {
  6621. br.Msg = "生成文件失败"
  6622. br.ErrMsg = "生成文件失败"
  6623. return
  6624. }
  6625. style := xlsx.NewStyle()
  6626. alignment := xlsx.Alignment{
  6627. Horizontal: "center",
  6628. Vertical: "center",
  6629. WrapText: true,
  6630. }
  6631. style.Alignment = alignment
  6632. style.ApplyAlignment = true
  6633. sheel, err := xlsxFile.AddSheet("联系人数据")
  6634. if err != nil {
  6635. br.Msg = "新增Sheet失败"
  6636. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  6637. return
  6638. }
  6639. sheel.SetColWidth(7, 7, 10)
  6640. sheel.SetColWidth(8, 10, 16)
  6641. sheel.SetColWidth(9, 11, 20)
  6642. sheel.SetColWidth(12, 12, 35)
  6643. sheel.SetColWidth(13, 13, 15)
  6644. sheel.SetColWidth(14, 14, 80)
  6645. titleRow := sheel.AddRow()
  6646. titleRow.AddCell().SetValue("联系人")
  6647. titleRow.AddCell().SetValue("是否关注公众号")
  6648. titleRow.AddCell().SetValue("手机号")
  6649. titleRow.AddCell().SetValue("邮箱")
  6650. //titleRow.AddCell().SetValue("职位")
  6651. titleRow.AddCell().SetValue("是否决策人")
  6652. //titleRow.AddCell().SetValue("客户部门")
  6653. titleRow.AddCell().SetValue("客户名称")
  6654. titleRow.AddCell().SetValue("客户状态")
  6655. //titleRow.AddCell().SetValue("社会信用码")
  6656. //titleRow.AddCell().SetValue("所属区域")
  6657. //titleRow.AddCell().SetValue("客户类型")
  6658. //industryCell := titleRow.AddCell()
  6659. //industryCell.SetStyle(style)
  6660. //industryCell.Value = "所属行业"
  6661. //
  6662. //sellerCell := titleRow.AddCell()
  6663. //sellerCell.SetStyle(style)
  6664. //sellerCell.Value = "所属销售"
  6665. //
  6666. //statusCell := titleRow.AddCell()
  6667. //statusCell.SetStyle(style)
  6668. //statusCell.Value = "客户状态"
  6669. //
  6670. //timeLimtCell := titleRow.AddCell()
  6671. //timeLimtCell.SetStyle(style)
  6672. //timeLimtCell.Value = "服务期限"
  6673. //
  6674. //createTimeCell := titleRow.AddCell()
  6675. //createTimeCell.SetStyle(style)
  6676. //createTimeCell.Value = "创建时间"
  6677. //
  6678. //sourceCell := titleRow.AddCell()
  6679. //sourceCell.SetStyle(style)
  6680. //sourceCell.Value = "客户来源"
  6681. //permissionStyle := xlsx.NewStyle()
  6682. //permissionAlignment := xlsx.Alignment{
  6683. // Horizontal: "center",
  6684. // Vertical: "center",
  6685. // WrapText: true,
  6686. //}
  6687. //
  6688. //permissionStyle.Alignment = permissionAlignment
  6689. //permissionStyle.ApplyAlignment = true
  6690. //permissionCell := titleRow.AddCell()
  6691. //permissionCell.SetStyle(permissionStyle)
  6692. //permissionCell.Value = "阅读权限"
  6693. users := make([]*company.ExportUser, 0)
  6694. if companyIds != "" {
  6695. companyIds = strings.Trim(companyIds, ",")
  6696. if productId > 0 {
  6697. users, err = company.GetExportUserByProductId(companyIds, productId)
  6698. if err != nil {
  6699. br.Msg = "导出失败"
  6700. br.ErrMsg = "获取联系人信息失败,Err:" + err.Error()
  6701. return
  6702. }
  6703. } else {
  6704. users, err = company.GetExportUser(companyIds)
  6705. if err != nil {
  6706. br.Msg = "导出失败"
  6707. br.ErrMsg = "获取联系人信息失败,Err:" + err.Error()
  6708. return
  6709. }
  6710. }
  6711. // 获取客户状态
  6712. companyIntIds := make([]int, 0)
  6713. companyIdArr := strings.Split(companyIds, ",")
  6714. for _, c := range companyIdArr {
  6715. id, e := strconv.Atoi(c)
  6716. if e != nil {
  6717. br.Msg = "导出失败"
  6718. br.ErrMsg = "客户ID有误"
  6719. return
  6720. }
  6721. companyIntIds = append(companyIntIds, id)
  6722. }
  6723. if len(companyIntIds) > 0 {
  6724. statusCond += fmt.Sprintf(` AND a.company_id IN (%s) `, utils.GetOrmInReplace(len(companyIntIds)))
  6725. statusPars = append(statusPars, companyIntIds)
  6726. }
  6727. statusMap := make(map[int]string)
  6728. nameMap := make(map[int]string)
  6729. companyStatusList, e := company.GetExportUserCompanyStatus(statusCond, statusPars)
  6730. if e != nil {
  6731. br.Msg = "导出失败"
  6732. br.ErrMsg = "获取客户状态失败, Err: " + e.Error()
  6733. return
  6734. }
  6735. for _, s := range companyStatusList {
  6736. statusMap[s.CompanyId] = s.CompanyStatus
  6737. nameMap[s.CompanyId] = s.CompanyName
  6738. }
  6739. //cpMap := make(map[int][]*company.ExportCompanyProduct)
  6740. //permissionMap := make(map[string]string)
  6741. for _, v := range users {
  6742. dataRow := sheel.AddRow()
  6743. dataRow.SetHeight(20)
  6744. dataRow.AddCell().SetString(v.RealName)
  6745. if v.IsSubscribe == 1 {
  6746. dataRow.AddCell().SetString("是") // 是否关注公众号
  6747. } else {
  6748. dataRow.AddCell().SetString("")
  6749. }
  6750. dataRow.AddCell().SetString(v.Mobile)
  6751. dataRow.AddCell().SetString(v.Email)
  6752. //dataRow.AddCell().SetString(v.Position)
  6753. if v.IsMaker == 1 {
  6754. dataRow.AddCell().SetString("是")
  6755. } else {
  6756. dataRow.AddCell().SetString("否")
  6757. }
  6758. //dataRow.AddCell().SetString(v.DepartmentName)
  6759. //cpList := make([]*company.ExportCompanyProduct, 1)
  6760. //if cps, ok := cpMap[v.CompanyId]; ok {
  6761. // cpList = cps
  6762. //} else {
  6763. // companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  6764. // if err != nil {
  6765. // br.Msg = "导出失败"
  6766. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  6767. // return
  6768. // }
  6769. // cpMap[v.CompanyId] = companyProduct
  6770. // cpList = companyProduct
  6771. //}
  6772. //productList, err := company.GetExportCompanyProduct(v.CompanyId)
  6773. //if err!=nil {
  6774. // fmt.Println("导出失败,Err:"+err.Error())
  6775. // return
  6776. //}
  6777. //var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, creditCode, regionType string
  6778. //for ck, cv := range cpList {
  6779. // companyName = cv.CompanyName
  6780. // creditCode = cv.CreditCode
  6781. // regionType = cv.RegionType
  6782. // if ck >= 1 {
  6783. // companyType = companyType + "/" + cv.ProductName
  6784. // status = status + "/" + cv.Status
  6785. // } else {
  6786. // companyType = cv.ProductName
  6787. // status = cv.Status
  6788. // }
  6789. // if cv.ProductId == 1 {
  6790. // industryName = "ficc:" + cv.IndustryName
  6791. // sellerName = "ficc:" + cv.SellerName
  6792. // startDateStr := cv.StartDate.Format("2006/01/02")
  6793. // endDateStr := cv.EndDate.Format("2006/01/02")
  6794. // if startDateStr != "0001/01/01" {
  6795. // timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  6796. // } else {
  6797. // timeLimt = ""
  6798. // }
  6799. // createTime = "ficc:" + cv.CreateTime
  6800. // source = "ficc:" + cv.Source
  6801. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6802. //
  6803. // permissionStr = "ficc:"
  6804. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6805. // permissionStr += newPermissionStr
  6806. // } else {
  6807. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6808. // if err != nil {
  6809. // br.Msg = "导出失败"
  6810. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6811. // return
  6812. // }
  6813. // permissionMap[permissionKey] = getPermissionStr
  6814. // permissionStr += getPermissionStr
  6815. // }
  6816. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  6817. // permissionStr = ""
  6818. // }
  6819. // } else {
  6820. // industryName = industryName + "\n" + "权益:" + cv.IndustryName
  6821. // sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  6822. // startDateStr := cv.StartDate.Format("2006/01/02")
  6823. // endDateStr := cv.EndDate.Format("2006/01/02")
  6824. //
  6825. // if startDateStr != "0001/01/01" {
  6826. // timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  6827. // } else {
  6828. // timeLimt = timeLimt + ""
  6829. // }
  6830. // createTime = createTime + "\n" + "权益:" + cv.CreateTime
  6831. // source = source + "\n" + "权益:" + cv.Source
  6832. //
  6833. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6834. // if permissionStr != "" {
  6835. // permissionStr = permissionStr + "\n" + "权益:"
  6836. // } else {
  6837. // permissionStr = "权益:"
  6838. // }
  6839. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6840. // permissionStr += newPermissionStr
  6841. // } else {
  6842. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6843. // if err != nil {
  6844. // br.Msg = "导出失败"
  6845. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6846. // return
  6847. // }
  6848. // permissionMap[permissionKey] = getPermissionStr
  6849. // permissionStr += getPermissionStr
  6850. // }
  6851. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  6852. // permissionStr = permissionStr + ""
  6853. // }
  6854. // }
  6855. //}
  6856. // 2023-0420这是谁写的循环查,顺手优化了一下,手动狗头-_-~
  6857. //companyInfo, err := company.GetCompanyById(v.CompanyId)
  6858. //if err != nil {
  6859. // br.Msg = "导出失败"
  6860. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  6861. // return
  6862. //}
  6863. dataRow.AddCell().SetString(nameMap[v.CompanyId])
  6864. dataRow.AddCell().SetString(statusMap[v.CompanyId]) // 客户状态
  6865. //dataRow.AddCell().SetString(creditCode)
  6866. //dataRow.AddCell().SetString(regionType)
  6867. //
  6868. //dataRow.AddCell().SetString(companyType)
  6869. //industryValueCell := dataRow.AddCell()
  6870. //industryValueCell.SetStyle(style)
  6871. //industryValueCell.SetString(industryName)
  6872. //
  6873. //sellerValueCell := dataRow.AddCell()
  6874. //sellerValueCell.SetStyle(style)
  6875. //sellerValueCell.SetString(sellerName)
  6876. //
  6877. //statusValueCell := dataRow.AddCell()
  6878. //statusValueCell.SetStyle(style)
  6879. //statusValueCell.SetValue(status)
  6880. //
  6881. //timeLimitValueCell := dataRow.AddCell()
  6882. //timeLimitValueCell.SetStyle(style)
  6883. //timeLimitValueCell.SetValue(timeLimt)
  6884. //
  6885. //createTimeValueCell := dataRow.AddCell()
  6886. //createTimeValueCell.SetStyle(style)
  6887. //createTimeValueCell.SetValue(createTime)
  6888. //
  6889. //sourceValueCell := dataRow.AddCell()
  6890. //sourceValueCell.SetStyle(style)
  6891. //sourceValueCell.SetValue(source)
  6892. //
  6893. //permissionStrValueCell := dataRow.AddCell()
  6894. //permissionStrValueCell.SetStyle(style)
  6895. //permissionStrValueCell.SetValue(permissionStr)
  6896. }
  6897. }
  6898. err = xlsxFile.Save(downLoadnFilePath)
  6899. if err != nil {
  6900. br.Msg = "保存文件失败"
  6901. br.ErrMsg = "保存文件失败"
  6902. return
  6903. }
  6904. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  6905. downloadFileName := "联系人列表" + randStr + ".xlsx"
  6906. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  6907. defer func() {
  6908. os.Remove(downLoadnFilePath)
  6909. }()
  6910. br.Ret = 200
  6911. br.Success = true
  6912. br.Msg = "导出成功"
  6913. }
  6914. //func (this *CompanyController) CompanyUserExportOld() {
  6915. // br := new(models.BaseResponse).Init()
  6916. // defer func() {
  6917. // this.Data["json"] = br
  6918. // this.ServeJSON()
  6919. // }()
  6920. // sysUser := this.SysUser
  6921. // if sysUser == nil {
  6922. // br.Msg = "请登录"
  6923. // br.ErrMsg = "请登录,SysUser Is Empty"
  6924. // br.Ret = 408
  6925. // return
  6926. // }
  6927. // roleTypeCode := sysUser.RoleTypeCode
  6928. // status := this.GetString("Status")
  6929. // companyType := this.GetString("CompanyType")
  6930. // industryId, _ := this.GetInt("IndustryId")
  6931. // adminId := this.GetString("AdminId")
  6932. //
  6933. // chartPermissionIds := this.GetString("ChartPermissionIds")
  6934. // startDate := this.GetString("StartDate")
  6935. // endDate := this.GetString("EndDate")
  6936. // keyWord := this.GetString("KeyWord")
  6937. //
  6938. // var condition string
  6939. // var pars []interface{}
  6940. //
  6941. // if status != "" && status != "全部" {
  6942. // condition += ` AND b.status=? `
  6943. // pars = append(pars, status)
  6944. // }
  6945. // if companyType != "" {
  6946. // condition += ` AND b.product_name=? `
  6947. // pars = append(pars, companyType)
  6948. // }
  6949. //
  6950. // if industryId > 0 {
  6951. // condition += ` AND b.industry_id=? `
  6952. // pars = append(pars, industryId)
  6953. // }
  6954. //
  6955. // if adminId != "" {
  6956. // condition += ` AND b.seller_id IN (` + adminId + `) `
  6957. // }
  6958. //
  6959. // if startDate != "" {
  6960. // condition += ` AND b.start_date>=? `
  6961. // pars = append(pars, startDate)
  6962. // }
  6963. //
  6964. // if endDate != "" {
  6965. // condition += ` AND b.end_date>=? `
  6966. // pars = append(pars, endDate)
  6967. // }
  6968. //
  6969. // if keyWord != "" {
  6970. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR c.mobile LIKE '%` + keyWord + `%' OR c.email LIKE '%` + keyWord + `%') `
  6971. // }
  6972. //
  6973. // if chartPermissionIds != "" {
  6974. // companyIdStr, err := company.GetCompanyIdStr(chartPermissionIds)
  6975. // if err != nil {
  6976. // br.Msg = "获取失败"
  6977. // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
  6978. // return
  6979. // }
  6980. // if companyIdStr != "" {
  6981. // condition += ` AND a.company_id IN (` + companyIdStr + `) `
  6982. // }
  6983. // }
  6984. //
  6985. // //权限控制
  6986. // {
  6987. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  6988. // roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  6989. // if status != utils.COMPANY_STATUS_LOSE && status != utils.COMPANY_STATUS_FOREVER {
  6990. // condition += ` AND b.seller_id=? `
  6991. // pars = append(pars, sysUser.AdminId)
  6992. // }
  6993. // }
  6994. // if sysUser.Authority == 1 {
  6995. // condition += ` AND b.department_id=? `
  6996. // pars = append(pars, sysUser.DepartmentId)
  6997. // }
  6998. //
  6999. // if sysUser.Authority == 2 {
  7000. // condition += ` AND b.group_id=? `
  7001. // pars = append(pars, sysUser.GroupId)
  7002. // }
  7003. // }
  7004. // companyIds, err := company.GetExportCompanyIds(condition, pars)
  7005. // if err != nil {
  7006. // br.Msg = "导出失败"
  7007. // br.ErrMsg = "导出失败,Err:" + err.Error()
  7008. // return
  7009. // }
  7010. //
  7011. // dir, err := os.Executable()
  7012. // exPath := filepath.Dir(dir)
  7013. //
  7014. // downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  7015. // xlsxFile := xlsx.NewFile()
  7016. // if err != nil {
  7017. // br.Msg = "生成文件失败"
  7018. // br.ErrMsg = "生成文件失败"
  7019. // return
  7020. // }
  7021. // style := xlsx.NewStyle()
  7022. // alignment := xlsx.Alignment{
  7023. // Horizontal: "center",
  7024. // Vertical: "center",
  7025. // WrapText: true,
  7026. // }
  7027. //
  7028. // style.Alignment = alignment
  7029. // style.ApplyAlignment = true
  7030. //
  7031. // sheel, err := xlsxFile.AddSheet("联系人数据")
  7032. // if err != nil {
  7033. // br.Msg = "新增Sheet失败"
  7034. // br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  7035. // return
  7036. // }
  7037. //
  7038. // sheel.SetColWidth(7, 7, 10)
  7039. // sheel.SetColWidth(8, 10, 16)
  7040. // sheel.SetColWidth(9, 11, 20)
  7041. // sheel.SetColWidth(12, 12, 35)
  7042. // sheel.SetColWidth(13, 13, 15)
  7043. // sheel.SetColWidth(14, 14, 80)
  7044. // titleRow := sheel.AddRow()
  7045. // titleRow.AddCell().SetValue("联系人")
  7046. // titleRow.AddCell().SetValue("手机号")
  7047. // titleRow.AddCell().SetValue("邮箱")
  7048. // titleRow.AddCell().SetValue("职位")
  7049. // titleRow.AddCell().SetValue("是否决策人")
  7050. // titleRow.AddCell().SetValue("客户部门")
  7051. // titleRow.AddCell().SetValue("客户名称")
  7052. // titleRow.AddCell().SetValue("社会信用码")
  7053. // titleRow.AddCell().SetValue("所属区域")
  7054. // titleRow.AddCell().SetValue("客户类型")
  7055. //
  7056. // industryCell := titleRow.AddCell()
  7057. // industryCell.SetStyle(style)
  7058. // industryCell.Value = "所属行业"
  7059. //
  7060. // sellerCell := titleRow.AddCell()
  7061. // sellerCell.SetStyle(style)
  7062. // sellerCell.Value = "所属销售"
  7063. //
  7064. // statusCell := titleRow.AddCell()
  7065. // statusCell.SetStyle(style)
  7066. // statusCell.Value = "客户状态"
  7067. //
  7068. // timeLimtCell := titleRow.AddCell()
  7069. // timeLimtCell.SetStyle(style)
  7070. // timeLimtCell.Value = "服务期限"
  7071. //
  7072. // createTimeCell := titleRow.AddCell()
  7073. // createTimeCell.SetStyle(style)
  7074. // createTimeCell.Value = "创建时间"
  7075. //
  7076. // sourceCell := titleRow.AddCell()
  7077. // sourceCell.SetStyle(style)
  7078. // sourceCell.Value = "客户来源"
  7079. //
  7080. // permissionStyle := xlsx.NewStyle()
  7081. // permissionAlignment := xlsx.Alignment{
  7082. // Horizontal: "center",
  7083. // Vertical: "center",
  7084. // WrapText: true,
  7085. // }
  7086. //
  7087. // permissionStyle.Alignment = permissionAlignment
  7088. // permissionStyle.ApplyAlignment = true
  7089. //
  7090. // permissionCell := titleRow.AddCell()
  7091. // permissionCell.SetStyle(permissionStyle)
  7092. // permissionCell.Value = "阅读权限"
  7093. //
  7094. // if companyIds != "" {
  7095. // companyIds = strings.Trim(companyIds, ",")
  7096. // users, err := company.GetExportUser(companyIds)
  7097. // if err != nil {
  7098. // br.Msg = "导出失败"
  7099. // br.ErrMsg = "获取联系人信息失败,Err:" + err.Error()
  7100. // return
  7101. // }
  7102. // cpMap := make(map[int][]*company.ExportCompanyProduct)
  7103. // permissionMap := make(map[string]string)
  7104. // for _, v := range users {
  7105. // dataRow := sheel.AddRow()
  7106. // dataRow.SetHeight(20)
  7107. // dataRow.AddCell().SetString(v.RealName)
  7108. // dataRow.AddCell().SetString(v.Mobile)
  7109. // dataRow.AddCell().SetString(v.Email)
  7110. // dataRow.AddCell().SetString(v.Position)
  7111. // if v.IsMaker == 1 {
  7112. // dataRow.AddCell().SetString("是")
  7113. // } else {
  7114. // dataRow.AddCell().SetString("否")
  7115. // }
  7116. // dataRow.AddCell().SetString(v.DepartmentName)
  7117. // cpList := make([]*company.ExportCompanyProduct, 1)
  7118. // if cps, ok := cpMap[v.CompanyId]; ok {
  7119. // cpList = cps
  7120. // } else {
  7121. // companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  7122. // if err != nil {
  7123. // br.Msg = "导出失败"
  7124. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  7125. // return
  7126. // }
  7127. // cpMap[v.CompanyId] = companyProduct
  7128. // cpList = companyProduct
  7129. // }
  7130. // //productList, err := company.GetExportCompanyProduct(v.CompanyId)
  7131. // //if err!=nil {
  7132. // // fmt.Println("导出失败,Err:"+err.Error())
  7133. // // return
  7134. // //}
  7135. // var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, creditCode, regionType string
  7136. //
  7137. // for ck, cv := range cpList {
  7138. // companyName = cv.CompanyName
  7139. // creditCode = cv.CreditCode
  7140. // regionType = cv.RegionType
  7141. // if ck >= 1 {
  7142. // companyType = companyType + "/" + cv.ProductName
  7143. // status = status + "/" + cv.Status
  7144. // } else {
  7145. // companyType = cv.ProductName
  7146. // status = cv.Status
  7147. // }
  7148. // if cv.ProductId == 1 {
  7149. // industryName = "ficc:" + cv.IndustryName
  7150. // sellerName = "ficc:" + cv.SellerName
  7151. // startDateStr := cv.StartDate.Format("2006/01/02")
  7152. // endDateStr := cv.EndDate.Format("2006/01/02")
  7153. // if startDateStr != "0001/01/01" {
  7154. // timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  7155. // } else {
  7156. // timeLimt = ""
  7157. // }
  7158. // createTime = "ficc:" + cv.CreateTime
  7159. // source = "ficc:" + cv.Source
  7160. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  7161. //
  7162. // permissionStr = "ficc:"
  7163. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  7164. // permissionStr += newPermissionStr
  7165. // } else {
  7166. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  7167. // if err != nil {
  7168. // br.Msg = "导出失败"
  7169. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  7170. // return
  7171. // }
  7172. // permissionMap[permissionKey] = getPermissionStr
  7173. // permissionStr += getPermissionStr
  7174. // }
  7175. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  7176. // permissionStr = ""
  7177. // }
  7178. // } else {
  7179. // industryName = industryName + "\n" + "权益:" + cv.IndustryName
  7180. // sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  7181. // startDateStr := cv.StartDate.Format("2006/01/02")
  7182. // endDateStr := cv.EndDate.Format("2006/01/02")
  7183. //
  7184. // if startDateStr != "0001/01/01" {
  7185. // timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  7186. // } else {
  7187. // timeLimt = timeLimt + ""
  7188. // }
  7189. // createTime = createTime + "\n" + "权益:" + cv.CreateTime
  7190. // source = source + "\n" + "权益:" + cv.Source
  7191. //
  7192. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  7193. // if permissionStr != "" {
  7194. // permissionStr = permissionStr + "\n" + "权益:"
  7195. // } else {
  7196. // permissionStr = "权益:"
  7197. // }
  7198. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  7199. // permissionStr += newPermissionStr
  7200. // } else {
  7201. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  7202. // if err != nil {
  7203. // br.Msg = "导出失败"
  7204. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  7205. // return
  7206. // }
  7207. // permissionMap[permissionKey] = getPermissionStr
  7208. // permissionStr += getPermissionStr
  7209. // }
  7210. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  7211. // permissionStr = permissionStr + ""
  7212. // }
  7213. // }
  7214. // }
  7215. // dataRow.AddCell().SetString(companyName)
  7216. // dataRow.AddCell().SetString(creditCode)
  7217. // dataRow.AddCell().SetString(regionType)
  7218. //
  7219. // dataRow.AddCell().SetString(companyType)
  7220. // industryValueCell := dataRow.AddCell()
  7221. // industryValueCell.SetStyle(style)
  7222. // industryValueCell.SetString(industryName)
  7223. //
  7224. // sellerValueCell := dataRow.AddCell()
  7225. // sellerValueCell.SetStyle(style)
  7226. // sellerValueCell.SetString(sellerName)
  7227. //
  7228. // statusValueCell := dataRow.AddCell()
  7229. // statusValueCell.SetStyle(style)
  7230. // statusValueCell.SetValue(status)
  7231. //
  7232. // timeLimitValueCell := dataRow.AddCell()
  7233. // timeLimitValueCell.SetStyle(style)
  7234. // timeLimitValueCell.SetValue(timeLimt)
  7235. //
  7236. // createTimeValueCell := dataRow.AddCell()
  7237. // createTimeValueCell.SetStyle(style)
  7238. // createTimeValueCell.SetValue(createTime)
  7239. //
  7240. // sourceValueCell := dataRow.AddCell()
  7241. // sourceValueCell.SetStyle(style)
  7242. // sourceValueCell.SetValue(source)
  7243. //
  7244. // permissionStrValueCell := dataRow.AddCell()
  7245. // permissionStrValueCell.SetStyle(style)
  7246. // permissionStrValueCell.SetValue(permissionStr)
  7247. // }
  7248. // }
  7249. // err = xlsxFile.Save(downLoadnFilePath)
  7250. // if err != nil {
  7251. // br.Msg = "保存文件失败"
  7252. // br.ErrMsg = "保存文件失败"
  7253. // return
  7254. // }
  7255. // randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  7256. // downloadFileName := "联系人列表" + randStr + ".xlsx"
  7257. // this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  7258. // defer func() {
  7259. // os.Remove(downLoadnFilePath)
  7260. // }()
  7261. // br.Ret = 200
  7262. // br.Success = true
  7263. // br.Msg = "导出成功"
  7264. //}
  7265. // @Title 冻结客户
  7266. // @Description 冻结客户接口
  7267. // @Param request body company.CompanyFreezeReq true "type json string"
  7268. // @Success Ret=200 冻结成功
  7269. // @router /freeze [post]
  7270. func (this *CompanyController) Freeze() {
  7271. br := new(models.BaseResponse).Init()
  7272. defer func() {
  7273. this.Data["json"] = br
  7274. this.ServeJSON()
  7275. }()
  7276. sysUser := this.SysUser
  7277. if sysUser == nil {
  7278. br.Msg = "请登录"
  7279. br.ErrMsg = "请登录,SysUser Is Empty"
  7280. br.Ret = 408
  7281. return
  7282. }
  7283. var req company.CompanyFreezeReq
  7284. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  7285. if err != nil {
  7286. br.Msg = "参数解析异常!"
  7287. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  7288. return
  7289. }
  7290. if req.CompanyId <= 0 {
  7291. br.Msg = "参数错误!"
  7292. br.ErrMsg = "客户id小于等于0"
  7293. return
  7294. }
  7295. productId := 0
  7296. productName := ""
  7297. if req.CompanyType == utils.COMPANY_CLASSIFY_FICC {
  7298. productId = 1
  7299. productName = "ficc"
  7300. } else if req.CompanyType == utils.COMPANY_CLASSIFY_RAI {
  7301. productId = 2
  7302. productName = "权益"
  7303. } else {
  7304. productId = 3
  7305. productName = "佣金客户"
  7306. }
  7307. if req.CompanyId <= 0 {
  7308. br.Msg = "参数异常!"
  7309. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  7310. return
  7311. }
  7312. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  7313. if err != nil {
  7314. br.Msg = "查询该客户产品异常!"
  7315. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  7316. return
  7317. }
  7318. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  7319. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  7320. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  7321. return
  7322. }
  7323. //查询客户的产品权限
  7324. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, productId)
  7325. if err != nil {
  7326. br.Msg = "查询客户的产品权限异常"
  7327. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  7328. return
  7329. }
  7330. err = company.CompanyFreeze(req.CompanyId, productId, req.Remark)
  7331. if err != nil {
  7332. br.Msg = "冻结失败!"
  7333. br.ErrMsg = "冻结失败,Err:" + err.Error()
  7334. return
  7335. }
  7336. //新增操作记录
  7337. {
  7338. approveContent := req.Remark
  7339. remark := "冻结客户"
  7340. operation := "freeze"
  7341. services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
  7342. productName, sysUser.RealName, remark, operation, approveContent, sysUser.RealName, "", "冻结")
  7343. //新增产品权限冻结操作日志
  7344. for _, companyReportPermission := range companyReportPermissionList {
  7345. record := company_report_permission_log.CompanyReportPermissionLog{
  7346. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  7347. CompanyId: companyReportPermission.CompanyId,
  7348. ProductId: productId,
  7349. ProductName: companyReportPermission.ProductName,
  7350. SysUserId: sysUser.AdminId,
  7351. SysUserName: sysUser.RealName,
  7352. Remark: "冻结客户",
  7353. Operation: "freeze",
  7354. Status: companyReportPermission.Status,
  7355. CreateTime: time.Now(),
  7356. }
  7357. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  7358. }
  7359. }
  7360. br.Ret = 200
  7361. br.Success = true
  7362. br.Msg = "领取成功"
  7363. }
  7364. // @Title 获取客户权限
  7365. // @Description 获取客户权限接口
  7366. // @Param CompanyId query int true "用户id"
  7367. // @Success 200 {object} company.CompanyPermissionResp
  7368. // @router /getCompanyPermission [get]
  7369. func (this *CompanyController) PermissionList() {
  7370. br := new(models.BaseResponse).Init()
  7371. defer func() {
  7372. this.Data["json"] = br
  7373. this.ServeJSON()
  7374. }()
  7375. sysUser := this.SysUser
  7376. if sysUser == nil {
  7377. br.Msg = "请登录"
  7378. br.ErrMsg = "请登录,SysUser Is Empty"
  7379. br.Ret = 408
  7380. return
  7381. }
  7382. companyId, _ := this.GetInt("CompanyId")
  7383. if companyId <= 0 {
  7384. br.Msg = "参数错误"
  7385. br.ErrMsg = "客户参数小于等于0"
  7386. return
  7387. }
  7388. //返回基础参数
  7389. resp := new(company.CompanyPermissionResp)
  7390. //客户类型map
  7391. classifyMap := make(map[string]int)
  7392. classifyMap["ficc"] = 1
  7393. classifyMap["权益"] = 2
  7394. roleTypeCode := sysUser.RoleTypeCode
  7395. var companySlice []string
  7396. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  7397. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  7398. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  7399. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
  7400. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM ||
  7401. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
  7402. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_RESEARCHR {
  7403. companySlice = append(companySlice, "ficc")
  7404. } else if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  7405. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN ||
  7406. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  7407. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  7408. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT ||
  7409. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_RESEARCHR {
  7410. companySlice = append(companySlice, "权益")
  7411. }
  7412. for _, companyType := range companySlice {
  7413. //子权限切片集合
  7414. //var permissionClassifyArr []string
  7415. var permissionProductId int
  7416. if companyType == "ficc" {
  7417. permissionProductId = utils.COMPANY_PRODUCT_FICC_ID
  7418. } else {
  7419. permissionProductId = utils.COMPANY_PRODUCT_RAI_ID
  7420. }
  7421. //子权限切片集合
  7422. permissionClassifyArr, err := models.GetPermissionFirstByProductId(permissionProductId)
  7423. if err != nil {
  7424. br.Msg = "获取失败"
  7425. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  7426. return
  7427. }
  7428. //遍历获取
  7429. for _, v := range permissionClassifyArr {
  7430. checkList := make([]int, 0)
  7431. plist := new(company.PermissionLookList)
  7432. plist.Items = make([]*company.PermissionLookItem, 0)
  7433. items, err := company.GetPermissionLookItemsByParentId(classifyMap[companyType], v.ChartPermissionId)
  7434. if err != nil {
  7435. br.Msg = "获取失败"
  7436. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  7437. return
  7438. }
  7439. mapPermissionCheck := make(map[string]int)
  7440. for i, n := range items {
  7441. item := items[i]
  7442. count, err := company.GetCompanyPermissionCheck(companyId, n.ChartPermissionId)
  7443. if err != nil {
  7444. br.Msg = "获取失败"
  7445. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  7446. return
  7447. }
  7448. //合并主观客观勾选的权限
  7449. if count > 0 && mapPermissionCheck[n.PermissionName] == 0 {
  7450. checkList = append(checkList, n.ChartPermissionId)
  7451. mapPermissionCheck[n.PermissionName] = n.ChartPermissionId
  7452. }
  7453. permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  7454. if err != nil && err.Error() != utils.ErrNoRow() {
  7455. br.Msg = "获取失败"
  7456. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  7457. return
  7458. }
  7459. if permission != nil && permission.ChartPermissionId > 0 {
  7460. items[i].StartDate = permission.StartDate
  7461. items[i].EndDate = permission.EndDate
  7462. items[i].Status = permission.Status
  7463. //判断主观、客观
  7464. if items[i].PermissionType == 1 {
  7465. items[i].PermissionTypeName = "主观"
  7466. } else if items[i].PermissionType == 2 {
  7467. items[i].PermissionTypeName = "客观"
  7468. }
  7469. }
  7470. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  7471. endDateTime = endDateTime.AddDate(0, 0, 1)
  7472. sub := endDateTime.Sub(time.Now())
  7473. if sub < 0 {
  7474. sub = 0
  7475. }
  7476. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  7477. items[i].ExpireDay = expireDay
  7478. items[i].ClassifyName = v.PermissionName
  7479. //if n.PermissionType == 1 {
  7480. // items[i].PermissionTypeName = "主观"
  7481. //} else if n.PermissionType == 2 {
  7482. // items[i].PermissionTypeName = "客观"
  7483. //}
  7484. }
  7485. //合并主观客观
  7486. mapPermissionName := make(map[string]int)
  7487. for _, v := range items {
  7488. if mapPermissionName[v.PermissionName] == 0 {
  7489. //plist.Items = append(plist.Items, v)
  7490. //mapPermissionName[v.PermissionName] = v.ChartPermissionId
  7491. // CRM8.8-只有客观的时候回显
  7492. if mapPermissionCheck[v.PermissionName] == 0 || (mapPermissionCheck[v.PermissionName] > 0 && v.ChartPermissionId == mapPermissionCheck[v.PermissionName]) {
  7493. plist.Items = append(plist.Items, v)
  7494. mapPermissionName[v.PermissionName] = v.ChartPermissionId
  7495. }
  7496. }
  7497. }
  7498. plist.ClassifyName = v.PermissionName
  7499. plist.CheckList = checkList
  7500. if companyType == "ficc" {
  7501. resp.FiccPermissionList = append(resp.FiccPermissionList, plist)
  7502. } else {
  7503. resp.PermissionList = append(resp.PermissionList, plist)
  7504. }
  7505. }
  7506. }
  7507. br.Ret = 200
  7508. br.Success = true
  7509. br.Msg = "获取成功"
  7510. br.Data = resp
  7511. }
  7512. // @Title 获取客户来源列表
  7513. // @Description 获取客户来源列表
  7514. // @Success 200 {object} models.CompanySourceListResp
  7515. // @router /getCompanySourceList [get]
  7516. func (this *CompanyController) CompanySourceList() {
  7517. br := new(models.BaseResponse).Init()
  7518. defer func() {
  7519. this.Data["json"] = br
  7520. this.ServeJSON()
  7521. }()
  7522. sysUser := this.SysUser
  7523. if sysUser == nil {
  7524. br.Msg = "请登录"
  7525. br.ErrMsg = "请登录,SysUser Is Empty"
  7526. br.Ret = 408
  7527. return
  7528. }
  7529. list, err := models.GetAllCompanySourceList()
  7530. if err != nil {
  7531. br.Msg = "查询失败"
  7532. br.ErrMsg = "查询异常:" + err.Error()
  7533. return
  7534. }
  7535. br.Ret = 200
  7536. br.Success = true
  7537. br.Msg = "获取成功"
  7538. br.Data = models.CompanySourceListResp{
  7539. List: list,
  7540. }
  7541. }
  7542. // @Title 获取客户的合同列表
  7543. // @Description 获取客户合同列表接口
  7544. // @Param CompanyId query int true "用户id"
  7545. // @Param CompanyType query string false "用户类型:可取范围:ficc,权益"
  7546. // @Param Status query int true "合同审核结果,枚举值:`0`,`1`; 0:待审核,1:审核通过"
  7547. // @Success 200 {object} company.CompanyPermissionResp
  7548. // @router /getCompanyContract [get]
  7549. func (this *CompanyController) ContractList() {
  7550. br := new(models.BaseResponse).Init()
  7551. defer func() {
  7552. this.Data["json"] = br
  7553. this.ServeJSON()
  7554. }()
  7555. sysUser := this.SysUser
  7556. if sysUser == nil {
  7557. br.Msg = "请登录"
  7558. br.ErrMsg = "请登录,SysUser Is Empty"
  7559. br.Ret = 408
  7560. return
  7561. }
  7562. companyId, _ := this.GetInt("CompanyId")
  7563. if companyId <= 0 {
  7564. br.Msg = "参数错误"
  7565. br.ErrMsg = "客户参数小于等于0"
  7566. return
  7567. }
  7568. //合同状态
  7569. status, _ := this.GetInt("Status")
  7570. //产品类型
  7571. companyType := this.GetString("CompanyType")
  7572. var condition string
  7573. var pars []interface{}
  7574. //产品类型
  7575. if companyType == "" {
  7576. productId := services.GetProductId(sysUser.RoleTypeCode)
  7577. if productId != 0 {
  7578. condition += " AND product_id = ?"
  7579. pars = append(pars, productId)
  7580. }
  7581. } else {
  7582. if companyType == "ficc" {
  7583. condition += " AND product_id = ?"
  7584. pars = append(pars, 1)
  7585. } else {
  7586. condition += " AND product_id = ?"
  7587. pars = append(pars, 2)
  7588. }
  7589. }
  7590. if status != 0 {
  7591. condition += " AND status = ?"
  7592. pars = append(pars, status)
  7593. }
  7594. list, err := company.GetCompanyContractListByCompanyId(companyId, condition, pars)
  7595. if err != nil {
  7596. br.Msg = "查询失败"
  7597. br.ErrMsg = "查询异常:" + err.Error()
  7598. return
  7599. }
  7600. br.Ret = 200
  7601. br.Success = true
  7602. br.Msg = "获取成功"
  7603. br.Data = list
  7604. }
  7605. // @Title 获取客户所属销售
  7606. // @Description 根据客户id获取客户所属销售
  7607. // @Param CompanyId query int true "客户id"
  7608. // @Success 200 {object} response.CompanySellerListResp
  7609. // @router /getCompanySellerList [get]
  7610. func (this *CompanyUserController) GetCompanySellerList() {
  7611. br := new(models.BaseResponse).Init()
  7612. defer func() {
  7613. this.Data["json"] = br
  7614. this.ServeJSON()
  7615. }()
  7616. sysUser := this.SysUser
  7617. if sysUser == nil {
  7618. br.Msg = "请登录"
  7619. br.ErrMsg = "请登录,SysUser Is Empty"
  7620. br.Ret = 408
  7621. return
  7622. }
  7623. companyId, _ := this.GetInt("CompanyId")
  7624. //item := make([]*company.CompanyItem, 0)
  7625. list, err := company.GetCompanySellerByCompanyId(companyId)
  7626. if err != nil && err.Error() != utils.ErrNoRow() {
  7627. br.Msg = "获取失败"
  7628. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  7629. return
  7630. }
  7631. resp := response.CompanySellerListResp{
  7632. List: list,
  7633. }
  7634. //resp.List = list
  7635. br.Ret = 200
  7636. br.Success = true
  7637. br.Msg = "获取成功"
  7638. br.Data = resp
  7639. }
  7640. // GetTryOutCompanyList
  7641. // @Title 获取销售今日待办数据
  7642. // @Description 获取销售今日待办接口
  7643. // @Param CompanyName query string false "客户名称"
  7644. // @Param ReasonStatus query int false "续约情况说明状态:-1:未填写,0:全部,1:已填写"
  7645. // @Param PageSize query int true "每页数据条数"
  7646. // @Param CurrentIndex query int true "当前页页码,从1开始"
  7647. // @Success 200 {object} response.TryOutCompanyListResp
  7648. // @router /getTryOutCompanyList [get]
  7649. func (this *CompanyController) GetTryOutCompanyList() {
  7650. br := new(models.BaseResponse).Init()
  7651. defer func() {
  7652. this.Data["json"] = br
  7653. this.ServeJSON()
  7654. }()
  7655. sysUser := this.SysUser
  7656. if sysUser == nil {
  7657. br.Msg = "请登录"
  7658. br.ErrMsg = "请登录,SysUser Is Empty"
  7659. br.Ret = 408
  7660. return
  7661. }
  7662. companyName := this.GetString("CompanyName")
  7663. reasonStatus, _ := this.GetInt("ReasonStatus", 0)
  7664. pageSize, _ := this.GetInt("PageSize")
  7665. currentIndex, _ := this.GetInt("CurrentIndex")
  7666. productId := services.GetProductId(sysUser.RoleTypeCode)
  7667. var startSize int
  7668. if pageSize <= 0 {
  7669. pageSize = utils.PageSize20
  7670. }
  7671. if currentIndex <= 0 {
  7672. currentIndex = 1
  7673. }
  7674. startSize = paging.StartIndex(currentIndex, pageSize)
  7675. var condition string
  7676. var pars []interface{}
  7677. //sellerId, productId int, tryOutTime time.Time, tryOutReason string
  7678. var tryOutTime, lastDescriptionTime time.Time
  7679. if productId == 1 {
  7680. //ficc
  7681. interval := cache.GetIntervalFromCrmConfig("try_out_time_intervals")
  7682. tryOutTime = time.Now().AddDate(0, 0, -interval)
  7683. interval = cache.GetIntervalFromCrmConfig("last_description_time_intervals")
  7684. lastDescriptionTime = time.Now().AddDate(0, 0, -interval)
  7685. } else {
  7686. //权益
  7687. interval := cache.GetIntervalFromCrmConfig("rai_try_out_time_intervals")
  7688. tryOutTime = time.Now().AddDate(0, 0, -interval)
  7689. interval = cache.GetIntervalFromCrmConfig("rai_last_description_time_intervals")
  7690. lastDescriptionTime = time.Now().AddDate(0, 0, -interval)
  7691. }
  7692. if productId > 0 {
  7693. condition += ` and product_id=? `
  7694. pars = append(pars, productId)
  7695. }
  7696. //客户名称模糊搜索
  7697. if companyName != "" {
  7698. condition += ` and b.company_name like "%` + companyName + `%" `
  7699. }
  7700. //续约情况说明(-1:未填写,0:全部,1:已填写)
  7701. switch reasonStatus {
  7702. case -1:
  7703. condition += ` and seller_id=? and try_out_time <=? and (last_description_time <=? OR last_description_time IS NULL) and (renewal_intention is NULL or renewal_reason is NULL or renewal_intention = 0) and (freeze_time='' OR freeze_time IS NULL) `
  7704. pars = append(pars, sysUser.AdminId, tryOutTime, lastDescriptionTime)
  7705. case 1:
  7706. condition += ` and seller_id=? and try_out_time <= ? and (renewal_intention is NULL or renewal_reason is NULL or renewal_intention = 0) and (freeze_time='' OR freeze_time IS NULL) `
  7707. pars = append(pars, sysUser.AdminId, tryOutTime)
  7708. default:
  7709. condition += ` and seller_id=? and (try_out_time <= ? or last_description_time <= ?) and (renewal_intention is NULL or renewal_reason is NULL or renewal_intention = 0) and (freeze_time='' OR freeze_time IS NULL) `
  7710. pars = append(pars, sysUser.AdminId, tryOutTime, lastDescriptionTime)
  7711. }
  7712. total := 0
  7713. list := make([]*company.TryOutCompanyList, 0)
  7714. ignoreStrs := []string{utils.ROLE_TYPE_CODE_FICC_SELLER, utils.ROLE_TYPE_CODE_RAI_SELLER, utils.ROLE_TYPE_CODE_FICC_GROUP, utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_RAI_GROUP}
  7715. if strings.Contains(strings.Join(ignoreStrs, ","), sysUser.RoleTypeCode) {
  7716. //排除已经签署续约合同的
  7717. notSql := ``
  7718. if productId > 0 {
  7719. notSql = fmt.Sprint(` and product_id = `, productId)
  7720. }
  7721. condition += `and a.company_id not in (select company_id from company_contract where contract_type ="续约合同" and start_date >now() and status = 1 ` + notSql + `) `
  7722. tmpTotal, err := company.GetTryOutCompanyCount(condition, pars)
  7723. if err != nil {
  7724. br.Msg = "获取失败"
  7725. br.ErrMsg = "获取总数失败失败,Err:" + err.Error()
  7726. return
  7727. }
  7728. tmpList, err := company.GetTryOutCompanyList(condition, pars, startSize, pageSize)
  7729. if err != nil {
  7730. br.Msg = "获取失败"
  7731. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  7732. return
  7733. }
  7734. total = tmpTotal
  7735. list = tmpList
  7736. }
  7737. if len(list) > 0 {
  7738. for k, item := range list {
  7739. endTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  7740. endTime = endTime.AddDate(0, 0, 1)
  7741. sub := endTime.Sub(time.Now())
  7742. if sub < 0 {
  7743. sub = 0
  7744. }
  7745. list[k].ExpireDays = int(sub.Hours() / 24)
  7746. }
  7747. }
  7748. page := paging.GetPaging(currentIndex, pageSize, total)
  7749. resp := response.TryOutCompanyListResp{
  7750. List: list,
  7751. Paging: page,
  7752. }
  7753. br.Ret = 200
  7754. br.Success = true
  7755. br.Msg = "获取成功"
  7756. br.Data = resp
  7757. }
  7758. // EditTryOutCompanyReason
  7759. // @Title 编辑续约说明情况
  7760. // @Description 编辑续约说明情况接口
  7761. // @Param request body company.RenewalReasonReq true "type json string"
  7762. // @Success 200 编辑成功
  7763. // @router /editTryOutCompanyReason [post]
  7764. func (this *CompanyController) EditTryOutCompanyReason() {
  7765. br := new(models.BaseResponse).Init()
  7766. defer func() {
  7767. this.Data["json"] = br
  7768. this.ServeJSON()
  7769. }()
  7770. sysUser := this.SysUser
  7771. if sysUser == nil {
  7772. br.Msg = "请登录"
  7773. br.ErrMsg = "请登录,SysUser Is Empty"
  7774. br.Ret = 408
  7775. return
  7776. }
  7777. var req company.RenewalReasonReq
  7778. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  7779. if err != nil {
  7780. br.Msg = "参数解析异常!"
  7781. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  7782. return
  7783. }
  7784. if req.CompanyId <= 0 {
  7785. br.Msg = "参数缺失"
  7786. br.ErrMsg = "参数缺失,客户编号未传!"
  7787. return
  7788. }
  7789. if req.ProductId <= 0 {
  7790. br.Msg = "参数缺失"
  7791. br.ErrMsg = "参数缺失,产品编号未传!"
  7792. return
  7793. }
  7794. if req.Remark == "" {
  7795. br.Msg = "参数缺失"
  7796. br.ErrMsg = "参数缺失,续约情况说明未传!"
  7797. return
  7798. }
  7799. /*if req.RenewalTodo == "" && req.Renew == 0 {
  7800. br.Msg = "参数缺失"
  7801. br.ErrMsg = "参数缺失,待办事项说明未传!"
  7802. return
  7803. }*/
  7804. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  7805. if err != nil {
  7806. br.Msg = "查询客户异常"
  7807. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  7808. return
  7809. }
  7810. if companyProduct.SellerId != sysUser.AdminId {
  7811. br.Msg = "客户异常,没有该客户的操作权限"
  7812. br.ErrMsg = "客户异常,没有该客户的操作权限"
  7813. return
  7814. }
  7815. renewalReason := company.CompanyRenewalReason{
  7816. CompanyRenewalReasonId: 0,
  7817. CompanyId: companyProduct.CompanyId,
  7818. ProductId: companyProduct.ProductId,
  7819. ProductName: companyProduct.ProductName,
  7820. CompanyName: companyProduct.CompanyName,
  7821. TryOutTime: companyProduct.TryOutTime,
  7822. RenewalReason: req.Remark,
  7823. RenewalTodo: req.RenewalTodo,
  7824. LastDescriptionTime: companyProduct.LastDescriptionTime,
  7825. EndDays: companyProduct.ContractEndDate,
  7826. ExpirationTimeExceeded: 0,
  7827. RenewalIntention: req.Renew,
  7828. CreateTime: time.Now(),
  7829. }
  7830. endTime, err := company.GetTryOutTimeFromOperationRecord(renewalReason.CompanyId)
  7831. if err != nil {
  7832. br.Msg = "查询该客户转试用时间异常!"
  7833. br.ErrMsg = "查询该客户转试用时间异常,err:" + err.Error()
  7834. return
  7835. }
  7836. endDateTime, err := time.Parse(utils.FormatDateTime, *endTime)
  7837. if err != nil {
  7838. br.Msg = "时间格式化异常!"
  7839. br.ErrMsg = "时间格式化异常,err:" + err.Error()
  7840. return
  7841. }
  7842. endDate := endDateTime.Format(utils.FormatDate)
  7843. endDateTime, _ = time.Parse(utils.FormatDate, endDate)
  7844. sub := time.Now().Sub(endDateTime)
  7845. renewalReason.ExpirationTimeExceeded = int(sub.Hours() / 24)
  7846. var newId int64
  7847. newId, err = company.AddRenewalReason(&renewalReason)
  7848. if err != nil {
  7849. br.Msg = "新增续约情况说明操作异常!"
  7850. br.ErrMsg = "新增续约情况说明操作异常,err:" + err.Error()
  7851. return
  7852. }
  7853. companyProduct.RenewalIntention = req.Renew
  7854. err = company.EditTryOutCompanyReason(companyProduct, req.Remark, req.RenewalTodo)
  7855. if err != nil {
  7856. br.Msg = "更新客户未续约异常!"
  7857. br.ErrMsg = "更新客户未续约异常,err:" + err.Error()
  7858. return
  7859. }
  7860. if req.Renew == 1 {
  7861. productName := ""
  7862. if req.ProductId == 1 {
  7863. productName = "ficc"
  7864. } else if req.ProductId == 2 {
  7865. productName = "权益"
  7866. } else {
  7867. productName = "佣金客户"
  7868. }
  7869. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  7870. if err != nil {
  7871. br.Msg = "查询该客户产品异常!"
  7872. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  7873. return
  7874. }
  7875. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  7876. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  7877. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  7878. return
  7879. }
  7880. //查询客户的产品权限
  7881. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, req.ProductId)
  7882. if err != nil {
  7883. br.Msg = "查询客户的产品权限异常"
  7884. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  7885. return
  7886. }
  7887. err = company.CompanyFreeze(req.CompanyId, req.ProductId, req.Remark)
  7888. if err != nil {
  7889. br.Msg = "冻结失败!"
  7890. br.ErrMsg = "冻结失败,Err:" + err.Error()
  7891. return
  7892. }
  7893. //新增操作记录
  7894. go func() {
  7895. time.Sleep(time.Second)
  7896. approveContent := req.Remark
  7897. remark := "冻结客户"
  7898. operation := "freeze"
  7899. _ = services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  7900. productName, "超级管理员", remark, operation, approveContent, sysUser.RealName, "", "冻结")
  7901. //新增产品权限冻结操作日志
  7902. for _, companyReportPermission := range companyReportPermissionList {
  7903. record := company_report_permission_log.CompanyReportPermissionLog{
  7904. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  7905. CompanyId: companyReportPermission.CompanyId,
  7906. ProductId: req.ProductId,
  7907. ProductName: companyReportPermission.ProductName,
  7908. SysUserId: sysUser.AdminId,
  7909. SysUserName: "超级管理员",
  7910. Remark: "冻结客户",
  7911. Operation: "freeze",
  7912. Status: companyReportPermission.Status,
  7913. CreateTime: time.Now(),
  7914. }
  7915. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  7916. }
  7917. }()
  7918. }
  7919. approveContent := req.Remark
  7920. approveContentExtra := req.RenewalTodo
  7921. remark := "新增续约说明"
  7922. operation := "edit_renewal_reason"
  7923. _ = services.AddCompanyOperationRecordMore(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  7924. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, approveContentExtra, sysUser.RealName, "", companyProduct.Status)
  7925. items, err := company.ReadCompanyOperationRecord(req.CompanyId)
  7926. if err != nil {
  7927. br.Msg = "编辑失败"
  7928. br.ErrMsg = "编辑失败,Err:" + err.Error()
  7929. return
  7930. }
  7931. if len(items) > 0 {
  7932. record := new(company.CompanyOperationRecord)
  7933. record.Id = items[0].Id
  7934. record.ApproveContent = req.Remark
  7935. record.ApproveContentExtra = req.RenewalTodo
  7936. _, err = company.UpdateCompanyOperationRecord(record)
  7937. if err != nil {
  7938. br.Msg = "编辑失败"
  7939. br.ErrMsg = "编辑失败,Err:" + err.Error()
  7940. return
  7941. }
  7942. } else {
  7943. br.Msg = "编辑失败"
  7944. br.ErrMsg = "编辑失败,未查询到转试用记录"
  7945. return
  7946. }
  7947. if req.ProductId == utils.COMPANY_PRODUCT_RAI_ID {
  7948. //权益客户新增历史备注总表
  7949. itemRecord := new(company.CompanyHistoryRemark)
  7950. itemRecord.CompanyId = req.CompanyId
  7951. itemRecord.Content = req.Remark
  7952. itemRecord.SysAdminId = sysUser.AdminId
  7953. itemRecord.SysAdminName = sysUser.RealName
  7954. itemRecord.CreateTime = time.Now().Local()
  7955. itemRecord.ModifyTime = time.Now().Local()
  7956. itemRecord.ShowTime = time.Now().Local()
  7957. itemRecord.ProductId = 2
  7958. itemRecord.TableName = "company_renewal_reason"
  7959. itemRecord.TableId = int(newId)
  7960. go services.AddCompanyHistoryRemark(itemRecord)
  7961. }
  7962. br.Ret = 200
  7963. br.Success = true
  7964. br.Msg = "编辑成功"
  7965. }
  7966. // AddTryOutCompanyReason
  7967. // @Title 新增续约说明情况
  7968. // @Description 新增续约说明情况接口
  7969. // @Param request body company.RenewalReasonReq true "type json string"
  7970. // @Success 200 编辑成功
  7971. // @router /addTryOutCompanyReason [post]
  7972. func (this *CompanyController) AddTryOutCompanyReason() {
  7973. br := new(models.BaseResponse).Init()
  7974. defer func() {
  7975. this.Data["json"] = br
  7976. this.ServeJSON()
  7977. }()
  7978. sysUser := this.SysUser
  7979. if sysUser == nil {
  7980. br.Msg = "请登录"
  7981. br.ErrMsg = "请登录,SysUser Is Empty"
  7982. br.Ret = 408
  7983. return
  7984. }
  7985. var req company.RenewalReasonReq
  7986. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  7987. if err != nil {
  7988. br.Msg = "参数解析异常!"
  7989. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  7990. return
  7991. }
  7992. if req.CompanyId <= 0 {
  7993. br.Msg = "参数缺失"
  7994. br.ErrMsg = "参数缺失,客户编号未传!"
  7995. return
  7996. }
  7997. if req.ProductId <= 0 {
  7998. br.Msg = "参数缺失"
  7999. br.ErrMsg = "参数缺失,产品编号未传!"
  8000. return
  8001. }
  8002. if req.Remark == "" {
  8003. br.Msg = "参数缺失"
  8004. br.ErrMsg = "参数缺失,续约情况说明未传!"
  8005. return
  8006. }
  8007. if req.RenewalTodo == "" && req.Renew == 0 {
  8008. br.Msg = "参数缺失"
  8009. br.ErrMsg = "参数缺失,待办事项说明未传!"
  8010. return
  8011. }
  8012. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  8013. if err != nil {
  8014. br.Msg = "查询客户异常"
  8015. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  8016. return
  8017. }
  8018. if companyProduct.SellerId != sysUser.AdminId {
  8019. br.Msg = "客户异常,没有该客户的操作权限"
  8020. br.ErrMsg = "客户异常,没有该客户的操作权限"
  8021. return
  8022. }
  8023. renewalReason := company.CompanyRenewalReason{
  8024. CompanyRenewalReasonId: 0,
  8025. CompanyId: companyProduct.CompanyId,
  8026. ProductId: companyProduct.ProductId,
  8027. ProductName: companyProduct.ProductName,
  8028. CompanyName: companyProduct.CompanyName,
  8029. TryOutTime: companyProduct.TryOutTime,
  8030. RenewalReason: req.Remark,
  8031. RenewalTodo: req.RenewalTodo,
  8032. LastDescriptionTime: companyProduct.LastDescriptionTime,
  8033. EndDays: companyProduct.ContractEndDate,
  8034. ExpirationTimeExceeded: 0,
  8035. RenewalIntention: req.Renew,
  8036. CreateTime: time.Now(),
  8037. }
  8038. endTime, err := company.GetTryOutTimeFromOperationRecord(renewalReason.CompanyId)
  8039. if err != nil {
  8040. br.Msg = "查询该客户转试用时间异常!"
  8041. br.ErrMsg = "查询该客户转试用时间异常,err:" + err.Error()
  8042. return
  8043. }
  8044. endDateTime, err := time.Parse(utils.FormatDateTime, *endTime)
  8045. if err != nil {
  8046. br.Msg = "时间格式化异常!"
  8047. br.ErrMsg = "时间格式化异常,err:" + err.Error()
  8048. return
  8049. }
  8050. endDate := endDateTime.Format(utils.FormatDate)
  8051. endDateTime, _ = time.Parse(utils.FormatDate, endDate)
  8052. sub := time.Now().Sub(endDateTime)
  8053. renewalReason.ExpirationTimeExceeded = int(sub.Hours() / 24)
  8054. var newId int64
  8055. newId, err = company.AddRenewalReason(&renewalReason)
  8056. if err != nil {
  8057. br.Msg = "新增续约情况说明操作异常!"
  8058. br.ErrMsg = "新增续约情况说明操作异常,err:" + err.Error()
  8059. return
  8060. }
  8061. companyProduct.RenewalIntention = req.Renew
  8062. err = company.EditTryOutCompanyReason(companyProduct, req.Remark, req.RenewalTodo)
  8063. if err != nil {
  8064. br.Msg = "更新客户续约情况说明异常!"
  8065. br.ErrMsg = "更新客户续约情况说明异常,err:" + err.Error()
  8066. return
  8067. }
  8068. if req.Renew == 1 {
  8069. productName := ""
  8070. if req.ProductId == 1 {
  8071. productName = "ficc"
  8072. } else if req.ProductId == 2 {
  8073. productName = "权益"
  8074. } else {
  8075. productName = "佣金客户"
  8076. }
  8077. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  8078. if err != nil {
  8079. br.Msg = "查询该客户产品异常!"
  8080. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  8081. return
  8082. }
  8083. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  8084. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  8085. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  8086. return
  8087. }
  8088. //查询客户的产品权限
  8089. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, req.ProductId)
  8090. if err != nil {
  8091. br.Msg = "查询客户的产品权限异常"
  8092. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  8093. return
  8094. }
  8095. err = company.CompanyFreeze(req.CompanyId, req.ProductId, req.Remark)
  8096. if err != nil {
  8097. br.Msg = "冻结失败!"
  8098. br.ErrMsg = "冻结失败,Err:" + err.Error()
  8099. return
  8100. }
  8101. //新增操作记录
  8102. go func() {
  8103. time.Sleep(time.Second)
  8104. approveContent := req.Remark
  8105. remark := "冻结客户"
  8106. operation := "freeze"
  8107. _ = services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  8108. productName, "超级管理员", remark, operation, approveContent, sysUser.RealName, "", "冻结")
  8109. //新增产品权限冻结操作日志
  8110. for _, companyReportPermission := range companyReportPermissionList {
  8111. record := company_report_permission_log.CompanyReportPermissionLog{
  8112. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  8113. CompanyId: companyReportPermission.CompanyId,
  8114. ProductId: req.ProductId,
  8115. ProductName: companyReportPermission.ProductName,
  8116. SysUserId: sysUser.AdminId,
  8117. SysUserName: "超级管理员",
  8118. Remark: "冻结客户",
  8119. Operation: "freeze",
  8120. Status: companyReportPermission.Status,
  8121. CreateTime: time.Now(),
  8122. }
  8123. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  8124. }
  8125. }()
  8126. }
  8127. {
  8128. approveContent := req.Remark
  8129. approveContentExtra := req.RenewalTodo
  8130. remark := "新增续约说明"
  8131. operation := "add_renewal_reason"
  8132. _ = services.AddCompanyOperationRecordMore(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  8133. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, approveContentExtra, sysUser.RealName, "", companyProduct.Status)
  8134. }
  8135. if req.ProductId == utils.COMPANY_PRODUCT_RAI_ID {
  8136. //权益客户新增历史备注总表
  8137. itemRecord := new(company.CompanyHistoryRemark)
  8138. itemRecord.CompanyId = req.CompanyId
  8139. itemRecord.Content = req.Remark
  8140. itemRecord.SysAdminId = sysUser.AdminId
  8141. itemRecord.SysAdminName = sysUser.RealName
  8142. itemRecord.CreateTime = time.Now().Local()
  8143. itemRecord.ModifyTime = time.Now().Local()
  8144. itemRecord.ShowTime = time.Now().Local()
  8145. itemRecord.ProductId = 2
  8146. itemRecord.TableName = "company_renewal_reason"
  8147. itemRecord.TableId = int(newId)
  8148. go services.AddCompanyHistoryRemark(itemRecord)
  8149. }
  8150. br.Ret = 200
  8151. br.Success = true
  8152. br.Msg = "编辑成功"
  8153. }
  8154. // RenewReasonList 客户未续约说明历史列表
  8155. // @Title 客户未续约说明历史列表
  8156. // @Description 客户未续约说明历史列表
  8157. // @Param CompanyId query string true "客户id"
  8158. // @Param ProductId query string true "产品id"
  8159. // @Success 200 {object} response.RenewReasonItemResp
  8160. // @router /renewReasonList [get]
  8161. func (this *CompanyController) RenewReasonList() {
  8162. br := new(models.BaseResponse).Init()
  8163. defer func() {
  8164. this.Data["json"] = br
  8165. this.ServeJSON()
  8166. }()
  8167. sysUser := this.SysUser
  8168. if sysUser == nil {
  8169. br.Msg = "请登录"
  8170. br.ErrMsg = "请登录,SysUser Is Empty"
  8171. br.Ret = 408
  8172. return
  8173. }
  8174. CompanyId := this.GetString("CompanyId")
  8175. ProductId := this.GetString("ProductId")
  8176. if CompanyId == "" {
  8177. br.Msg = "请输入客户ID"
  8178. return
  8179. }
  8180. if ProductId != "1" && ProductId != "2" {
  8181. br.Msg = "请输入正确的产品ID"
  8182. return
  8183. }
  8184. renewalReason, err := models.GetMoreRenewalReason(CompanyId, ProductId)
  8185. if err != nil {
  8186. br.Msg = "获取失败"
  8187. br.ErrMsg = "获取失败,Err:" + err.Error()
  8188. return
  8189. }
  8190. resp := make([]response.RenewReasonItemResp, len(renewalReason))
  8191. for i, reason := range renewalReason {
  8192. createDate := reason.CreateTime.Format("2006.01.02 15:04:05")
  8193. resp[i].RenewalReason = reason.RenewalReason
  8194. resp[i].RenewalTodo = reason.RenewalTodo
  8195. resp[i].CreateTime = createDate
  8196. }
  8197. br.Ret = 200
  8198. br.Success = true
  8199. br.Msg = "获取成功"
  8200. br.Data = resp
  8201. }
  8202. // AddRenewalReason
  8203. // @Title 转试用按钮新增续约说明情况
  8204. // @Description 转试用按钮新增续约说明情况
  8205. // @Param request body company.TryOutReq true "type json string"
  8206. // @Success 200 编辑成功
  8207. // @router /addRenewalReason [post]
  8208. func (this *CompanyController) AddRenewalReason() {
  8209. br := new(models.BaseResponse).Init()
  8210. defer func() {
  8211. this.Data["json"] = br
  8212. this.ServeJSON()
  8213. }()
  8214. sysUser := this.SysUser
  8215. if sysUser == nil {
  8216. br.Msg = "请登录"
  8217. br.ErrMsg = "请登录,SysUser Is Empty"
  8218. br.Ret = 408
  8219. return
  8220. }
  8221. var req company.TryOutReq
  8222. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  8223. if err != nil {
  8224. br.Msg = "参数解析异常!"
  8225. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  8226. return
  8227. }
  8228. if req.CompanyId <= 0 {
  8229. br.Msg = "参数缺失"
  8230. br.ErrMsg = "参数缺失,客户编号未传!"
  8231. return
  8232. }
  8233. if req.ProductId <= 0 {
  8234. br.Msg = "参数缺失"
  8235. br.ErrMsg = "参数缺失,产品编号未传!"
  8236. return
  8237. }
  8238. if req.OperationId <= 0 {
  8239. br.Msg = "参数缺失"
  8240. br.ErrMsg = "参数缺失,操作记录表编号未传!"
  8241. return
  8242. }
  8243. if req.Remark == "" {
  8244. br.Msg = "参数缺失"
  8245. br.ErrMsg = "参数缺失,续约情况说明未传!"
  8246. return
  8247. }
  8248. if req.RenewalTodo == "" && req.Renew == 0 {
  8249. br.Msg = "参数缺失"
  8250. br.ErrMsg = "参数缺失,待办事项说明未传!"
  8251. return
  8252. }
  8253. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  8254. if err != nil {
  8255. br.Msg = "查询客户异常"
  8256. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  8257. return
  8258. }
  8259. if companyProduct.SellerId != sysUser.AdminId {
  8260. br.Msg = "客户异常,没有该客户的操作权限"
  8261. br.ErrMsg = "客户异常,没有该客户的操作权限"
  8262. return
  8263. }
  8264. renewalReason := company.CompanyRenewalReason{
  8265. CompanyRenewalReasonId: 0,
  8266. CompanyId: companyProduct.CompanyId,
  8267. ProductId: companyProduct.ProductId,
  8268. ProductName: companyProduct.ProductName,
  8269. CompanyName: companyProduct.CompanyName,
  8270. TryOutTime: companyProduct.TryOutTime,
  8271. RenewalReason: req.Remark,
  8272. RenewalTodo: req.RenewalTodo,
  8273. LastDescriptionTime: companyProduct.LastDescriptionTime,
  8274. EndDays: companyProduct.ContractEndDate,
  8275. ExpirationTimeExceeded: 0,
  8276. RenewalIntention: req.Renew,
  8277. CreateTime: time.Now(),
  8278. }
  8279. endTime, err := company.GetTryOutTimeFromOperationRecord(renewalReason.CompanyId)
  8280. if err != nil {
  8281. br.Msg = "查询该客户转试用时间异常!"
  8282. br.ErrMsg = "查询该客户转试用时间异常,err:" + err.Error()
  8283. return
  8284. }
  8285. endDateTime, err := time.Parse(utils.FormatDateTime, *endTime)
  8286. if err != nil {
  8287. br.Msg = "时间格式化异常!"
  8288. br.ErrMsg = "时间格式化异常,err:" + err.Error()
  8289. return
  8290. }
  8291. endDate := endDateTime.Format(utils.FormatDate)
  8292. endDateTime, _ = time.Parse(utils.FormatDate, endDate)
  8293. sub := time.Now().Sub(endDateTime)
  8294. renewalReason.ExpirationTimeExceeded = int(sub.Hours() / 24)
  8295. var newId int64
  8296. newId, err = company.AddRenewalReason(&renewalReason)
  8297. if err != nil {
  8298. br.Msg = "新增续约情况说明操作异常!"
  8299. br.ErrMsg = "新增续约情况说明操作异常,err:" + err.Error()
  8300. return
  8301. }
  8302. companyProduct.RenewalIntention = req.Renew
  8303. err = company.EditTryOutCompanyReason(companyProduct, req.Remark, req.RenewalTodo)
  8304. if err != nil {
  8305. br.Msg = "更新客户续约情况说明异常!"
  8306. br.ErrMsg = "更新客户续约情况说明异常,err:" + err.Error()
  8307. return
  8308. }
  8309. if req.Renew == 1 {
  8310. productName := ""
  8311. if req.ProductId == 1 {
  8312. productName = "ficc"
  8313. } else if req.ProductId == 2 {
  8314. productName = "权益"
  8315. } else {
  8316. productName = "佣金客户"
  8317. }
  8318. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  8319. if err != nil {
  8320. br.Msg = "查询该客户产品异常!"
  8321. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  8322. return
  8323. }
  8324. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  8325. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  8326. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  8327. return
  8328. }
  8329. //查询客户的产品权限
  8330. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, req.ProductId)
  8331. if err != nil {
  8332. br.Msg = "查询客户的产品权限异常"
  8333. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  8334. return
  8335. }
  8336. err = company.CompanyFreeze(req.CompanyId, req.ProductId, req.Remark)
  8337. if err != nil {
  8338. br.Msg = "冻结失败!"
  8339. br.ErrMsg = "冻结失败,Err:" + err.Error()
  8340. return
  8341. }
  8342. //新增操作记录
  8343. go func() {
  8344. time.Sleep(time.Second)
  8345. approveContent := req.Remark
  8346. remark := "冻结客户"
  8347. operation := "freeze"
  8348. _ = services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  8349. productName, "超级管理员", remark, operation, approveContent, sysUser.RealName, "", "冻结")
  8350. //新增产品权限冻结操作日志
  8351. for _, companyReportPermission := range companyReportPermissionList {
  8352. record := company_report_permission_log.CompanyReportPermissionLog{
  8353. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  8354. CompanyId: companyReportPermission.CompanyId,
  8355. ProductId: req.ProductId,
  8356. ProductName: companyReportPermission.ProductName,
  8357. SysUserId: sysUser.AdminId,
  8358. SysUserName: "超级管理员",
  8359. Remark: "冻结客户",
  8360. Operation: "freeze",
  8361. Status: companyReportPermission.Status,
  8362. CreateTime: time.Now(),
  8363. }
  8364. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  8365. }
  8366. }()
  8367. }
  8368. {
  8369. approveContent := req.Remark
  8370. approveContentExtra := req.RenewalTodo
  8371. remark := "新增续约说明"
  8372. operation := "add_try_out_reason"
  8373. _ = services.AddCompanyOperationRecordMore(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  8374. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, approveContentExtra, sysUser.RealName, "", companyProduct.Status)
  8375. record := new(company.CompanyOperationRecord)
  8376. record.Id = req.OperationId
  8377. record.ApproveContent = req.Remark
  8378. record.ApproveContentExtra = req.RenewalTodo
  8379. _, err = company.UpdateCompanyOperationRecord(record)
  8380. if err != nil {
  8381. br.Msg = "编辑失败"
  8382. br.ErrMsg = "编辑失败,Err:" + err.Error()
  8383. return
  8384. }
  8385. }
  8386. if req.ProductId == utils.COMPANY_PRODUCT_RAI_ID {
  8387. //权益客户新增历史备注总表
  8388. itemRecord := new(company.CompanyHistoryRemark)
  8389. itemRecord.CompanyId = req.CompanyId
  8390. itemRecord.Content = req.Remark
  8391. itemRecord.SysAdminId = sysUser.AdminId
  8392. itemRecord.SysAdminName = sysUser.RealName
  8393. itemRecord.CreateTime = time.Now().Local()
  8394. itemRecord.ModifyTime = time.Now().Local()
  8395. itemRecord.ShowTime = time.Now().Local()
  8396. itemRecord.ProductId = 2
  8397. itemRecord.TableName = "company_renewal_reason"
  8398. itemRecord.TableId = int(newId)
  8399. go services.AddCompanyHistoryRemark(itemRecord)
  8400. }
  8401. br.Ret = 200
  8402. br.Success = true
  8403. br.Msg = "编辑成功"
  8404. }
  8405. // AddRemark
  8406. // @Title 新增备注
  8407. // @Description 新增备注
  8408. // @Param request body company.RemarkReq true "type json string"
  8409. // @Success 200 编辑成功
  8410. // @router /remark/add [post]
  8411. func (this *CompanyController) AddRemark() {
  8412. br := new(models.BaseResponse).Init()
  8413. defer func() {
  8414. this.Data["json"] = br
  8415. this.ServeJSON()
  8416. }()
  8417. sysUser := this.SysUser
  8418. if sysUser == nil {
  8419. br.Msg = "请登录"
  8420. br.ErrMsg = "请登录,SysUser Is Empty"
  8421. br.Ret = 408
  8422. return
  8423. }
  8424. var req company.RemarkReq
  8425. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  8426. if err != nil {
  8427. br.Msg = "参数解析异常!"
  8428. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  8429. return
  8430. }
  8431. if req.CompanyId <= 0 {
  8432. br.Msg = "参数缺失"
  8433. br.ErrMsg = "参数缺失,客户编号未传!"
  8434. return
  8435. }
  8436. if req.Remark == "" {
  8437. br.Msg = "参数缺失"
  8438. br.ErrMsg = "参数缺失,备注说明未传!"
  8439. return
  8440. }
  8441. var productId int
  8442. //var productName string
  8443. 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 {
  8444. productId = 1
  8445. //productName = "ficc"
  8446. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT {
  8447. productId = 2
  8448. //productName = "权益"
  8449. } else {
  8450. br.Msg = "角色类型错误"
  8451. br.ErrMsg = "角色类型错误,该角色不能添加备注!"
  8452. return
  8453. }
  8454. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  8455. if err != nil {
  8456. br.Msg = "查询客户异常"
  8457. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  8458. }
  8459. if companyProduct.SellerId != sysUser.AdminId {
  8460. br.Msg = "客户异常,没有该客户的操作权限"
  8461. br.ErrMsg = "客户异常,没有该客户的操作权限"
  8462. return
  8463. }
  8464. remark := company.CompanyProductRemark{
  8465. CompanyId: companyProduct.CompanyId,
  8466. ProductId: companyProduct.ProductId,
  8467. ProductName: companyProduct.ProductName,
  8468. Remark: req.Remark,
  8469. CreateTime: time.Now(),
  8470. SysUserId: sysUser.AdminId,
  8471. SysRealName: sysUser.RealName,
  8472. }
  8473. var newId int64
  8474. newId, err = company.AddCompanyRemark(&remark)
  8475. {
  8476. approveContent := req.Remark
  8477. remark := "新增备注"
  8478. operation := "add_remark"
  8479. services.AddCompanyOperationRecord(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  8480. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, sysUser.RealName, "", companyProduct.Status)
  8481. }
  8482. if err != nil {
  8483. br.Msg = "编辑失败"
  8484. br.ErrMsg = "编辑失败,Err:" + err.Error()
  8485. }
  8486. //如果是权益的写入历史备注表
  8487. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  8488. //权益客户新增历史备注总表
  8489. itemRecord := new(company.CompanyHistoryRemark)
  8490. itemRecord.CompanyId = req.CompanyId
  8491. itemRecord.Content = req.Remark
  8492. itemRecord.SysAdminId = sysUser.AdminId
  8493. itemRecord.SysAdminName = sysUser.RealName
  8494. itemRecord.CreateTime = time.Now().Local()
  8495. itemRecord.ModifyTime = time.Now().Local()
  8496. itemRecord.ShowTime = time.Now().Local()
  8497. itemRecord.ProductId = 2
  8498. itemRecord.TableName = "company_product_remark"
  8499. itemRecord.TableId = int(newId)
  8500. go services.AddCompanyHistoryRemark(itemRecord)
  8501. }
  8502. br.Ret = 200
  8503. br.Success = true
  8504. br.Msg = "编辑成功"
  8505. }
  8506. // RemarkList 备注列表
  8507. // @Title 备注列表
  8508. // @Description 备注列表
  8509. // @Param CompanyId query string true "客户id"
  8510. // @Success 200 {object} company.RemarkResp
  8511. // @router /remark [get]
  8512. func (this *CompanyController) RemarkList() {
  8513. br := new(models.BaseResponse).Init()
  8514. defer func() {
  8515. this.Data["json"] = br
  8516. this.ServeJSON()
  8517. }()
  8518. sysUser := this.SysUser
  8519. if sysUser == nil {
  8520. br.Msg = "请登录"
  8521. br.ErrMsg = "请登录,SysUser Is Empty"
  8522. br.Ret = 408
  8523. return
  8524. }
  8525. companyId := this.GetString("CompanyId")
  8526. var remarkList []*company.CompanyProductRemark
  8527. var err error
  8528. groupFicc := []string{
  8529. utils.ROLE_TYPE_CODE_FICC_SELLER, utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_FICC_GROUP,
  8530. utils.ROLE_TYPE_CODE_FICC_DEPARTMENT, utils.ROLE_TYPE_CODE_FICC_ADMIN,
  8531. }
  8532. groupRai := []string{
  8533. utils.ROLE_TYPE_CODE_RAI_SELLER, utils.ROLE_TYPE_CODE_RAI_GROUP, utils.ROLE_TYPE_CODE_RAI_GROUP,
  8534. utils.ROLE_TYPE_CODE_RAI_DEPARTMENT, utils.ROLE_TYPE_CODE_RAI_ADMIN,
  8535. }
  8536. if utils.InArrayByStr(groupFicc, sysUser.RoleTypeCode) {
  8537. remarkList, err = company.GetRemarkList(companyId, "1")
  8538. if err != nil {
  8539. br.Msg = "获取失败"
  8540. br.ErrMsg = "获取失败,Err:" + err.Error()
  8541. return
  8542. }
  8543. }
  8544. if utils.InArrayByStr(groupRai, sysUser.RoleTypeCode) {
  8545. remarkList, err = company.GetRemarkList(companyId, "2")
  8546. if err != nil {
  8547. br.Msg = "获取失败"
  8548. br.ErrMsg = "获取失败,Err:" + err.Error()
  8549. return
  8550. }
  8551. }
  8552. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  8553. remarkList, err = company.GetRemarkListByCompanyId(companyId)
  8554. if err != nil {
  8555. br.Msg = "获取失败"
  8556. br.ErrMsg = "获取失败,Err:" + err.Error()
  8557. return
  8558. }
  8559. }
  8560. resp := make([]company.RemarkResp, len(remarkList))
  8561. for i, remark := range remarkList {
  8562. createDate := remark.CreateTime.Format(utils.FormatDateTime)
  8563. resp[i].RemarkId = remark.CompanyProductRemarkId
  8564. resp[i].Remark = remark.Remark
  8565. resp[i].ProductName = remark.ProductName
  8566. resp[i].CreateTime = createDate
  8567. // 仅自己添加的可删除
  8568. if remark.SysUserId == sysUser.AdminId {
  8569. resp[i].ButtonDel = true
  8570. }
  8571. }
  8572. br.Ret = 200
  8573. br.Success = true
  8574. br.Msg = "获取成功"
  8575. br.Data = resp
  8576. }
  8577. // RoadShowList 客户列表的路演详情列表
  8578. // @Title 路演详情列表
  8579. // @Description 路演详情列表
  8580. // @Param CompanyId query string true "客户id"
  8581. // @Success 200 {object} company.RoadShowListResp
  8582. // @router /roadShowList [get]
  8583. func (this *CompanyController) RoadShowList() {
  8584. br := new(models.BaseResponse).Init()
  8585. defer func() {
  8586. this.Data["json"] = br
  8587. this.ServeJSON()
  8588. }()
  8589. sysUser := this.SysUser
  8590. if sysUser == nil {
  8591. br.Msg = "请登录"
  8592. br.ErrMsg = "请登录,SysUser Is Empty"
  8593. br.Ret = 408
  8594. return
  8595. }
  8596. companyId := this.GetString("CompanyId")
  8597. companyIdInt, _ := strconv.Atoi(companyId)
  8598. if companyIdInt <= 0 {
  8599. br.Msg = "参数错误"
  8600. return
  8601. }
  8602. var englishCompany int
  8603. if companyIdInt > utils.EnCompanyIdStep {
  8604. companyIdInt = companyIdInt - utils.EnCompanyIdStep
  8605. englishCompany = 1
  8606. }
  8607. var err error
  8608. roadShowList, err := company.GetRoadShowList(companyIdInt, englishCompany)
  8609. if err != nil {
  8610. br.Msg = "获取失败"
  8611. br.ErrMsg = "获取失败,Err:" + err.Error()
  8612. return
  8613. }
  8614. //calendarIdSlice := make([]string, 0)
  8615. //for _, v := range roadShowList {
  8616. // calendarIdSlice = append(calendarIdSlice, strconv.Itoa(v.RsCalendarId))
  8617. //}
  8618. //calendarIdStr := strings.Join(calendarIdSlice, ",")
  8619. //researcherList, _ := company.GetRoadShowResearchers(calendarIdStr)
  8620. //roadShowTotalMap := make(map[int]int)
  8621. //for _, roadShowTotal := range researcherList {
  8622. // roadShowTotalMap[roadShowTotal.CompanyId] = roadShowTotal.Total
  8623. //}
  8624. resp := make([]company.RoadShowListResp, len(roadShowList))
  8625. for i, calendar := range roadShowList {
  8626. resp[i].SysUserRealName = calendar.SysUserRealName
  8627. resp[i].RoadshowType = calendar.RoadshowType
  8628. //线上为平台,线下为省市
  8629. if calendar.RoadshowType == "线上" {
  8630. resp[i].RoadshowPlatform = calendar.RoadshowPlatform
  8631. } else {
  8632. resp[i].RoadshowPlatform = calendar.Province + calendar.City
  8633. }
  8634. researchers, err := company.GetRoadShowResearchers(calendar.RsCalendarId)
  8635. if err != nil && err.Error() != utils.ErrNoRow() {
  8636. br.Msg = "获取研究员信息失败"
  8637. br.ErrMsg = "获取研究员信息失败,Err:" + err.Error()
  8638. return
  8639. }
  8640. var researcherList []string
  8641. for _, researcher := range researchers {
  8642. researcherList = append(researcherList, *researcher)
  8643. }
  8644. researcher := strings.Join(researcherList, ",")
  8645. resp[i].Researchers = researcher
  8646. resp[i].RoadShowTime = calendar.EndDate.Format("2006.01.02")
  8647. }
  8648. br.Ret = 200
  8649. br.Success = true
  8650. br.Msg = "获取成功"
  8651. br.Data = resp
  8652. }
  8653. // CustomerAreaStatistics
  8654. // @Title 客户区域统计
  8655. // @Description 获取客户区域统计接口
  8656. // @Param Date query string true "日期"
  8657. // @Param ProductId query Int true "产品Id"
  8658. // @Success 200 {object} statistic_report.CompanyRenewRecordResp
  8659. // @router /customerAreaStatistics [get]
  8660. func (this *CompanyController) CustomerAreaStatistics() {
  8661. br := new(models.BaseResponse).Init()
  8662. defer func() {
  8663. this.Data["json"] = br
  8664. this.ServeJSON()
  8665. }()
  8666. sysUser := this.SysUser
  8667. if sysUser == nil {
  8668. br.Msg = "请登录"
  8669. br.ErrMsg = "请登录,SysUser Is Empty"
  8670. br.Ret = 408
  8671. return
  8672. }
  8673. date := this.GetString("Date")
  8674. productId, _ := this.GetInt("ProductId", 1)
  8675. //获取列表
  8676. companyAreaDataMapList, _, err := statistic_report.GetAreaDateData(date, productId)
  8677. if err != nil {
  8678. br.Msg = "数据异常"
  8679. br.ErrMsg = "数据异常,Err:" + err.Error()
  8680. return
  8681. }
  8682. //获取省市数据
  8683. areaMap := make(map[string]string)
  8684. provinceMap := make(map[string][]string, 0)
  8685. list, err := statisticModels.GetAllCompanyArea()
  8686. for _, item := range list {
  8687. areaMap[item.City] = item.Province
  8688. }
  8689. for c, p := range areaMap {
  8690. citySlice := make([]string, 0)
  8691. citySlice = provinceMap[p]
  8692. citySlice = append(citySlice, c)
  8693. provinceMap[p] = citySlice
  8694. }
  8695. //数据处理
  8696. groupReportRecordList := make([]statistic_report.GroupCityRecord, 0)
  8697. resp := statistic_report.CustomerAreaStatisticsResp{
  8698. List: groupReportRecordList,
  8699. IsAdmin: false,
  8700. }
  8701. //除ficc管理员和超管之外的角色进入此页面时,正式客户数量>0时可点击,点击查看正式客户列表详情;
  8702. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  8703. resp.IsAdmin = true
  8704. }
  8705. startDateIndexList := make(map[int]string) //开始时间间隔map
  8706. endDateIndexList := make(map[int]string) //结束时间间隔map
  8707. tmpAllTryOutNumMap := make(map[int]int)
  8708. tmpAllFormalNumMap := make(map[int]int)
  8709. tmpAllActiveNumMap := make(map[int]int)
  8710. tmpAllAllActiveNumMap := make(map[int]int)
  8711. tmpAllNoIncrementalActiveNumMap := make(map[int]int)
  8712. tmpAllTryStagePushMap := make(map[int]int)
  8713. tmpAllTryStageFollowMap := make(map[int]int)
  8714. tmpAllTryStageReadyMap := make(map[int]int)
  8715. tmpAllTryStageInitMap := make(map[int]int)
  8716. for province, cityList := range provinceMap {
  8717. tmpGroupCityReportRecord := make([]statistic_report.CityRecord, 0)
  8718. tmpGroupCompanyReportRecordNumList := make([]statistic_report.CompanyAreaNum, 0)
  8719. tmpGroupTryOutNumMap := make(map[int]int)
  8720. tmpGroupFormalNumMap := make(map[int]int)
  8721. tmpGroupFormalCompanyIdsMap := make(map[int]string) //正式客户id
  8722. tmpGroupActiveNumMap := make(map[int]int)
  8723. tmpGroupAllActiveNumMap := make(map[int]int)
  8724. tmpGroupNoIncrementalActiveNumMap := make(map[int]int)
  8725. // 其他类型客户ID
  8726. tmpGroupTryOutCompanyIdsMap := make(map[int]string) //试用客户ID
  8727. tmpGroupPushCompanyIdsMap := make(map[int]string) //试用(推进)客户ID
  8728. tmpGroupFollowCompanyIdsMap := make(map[int]string) //试用(跟踪)客户ID
  8729. tmpGroupReadyCompanyIdsMap := make(map[int]string) //试用(预备)客户ID
  8730. tmpGroupInitCompanyIdsMap := make(map[int]string) //试用(未分类)客户ID
  8731. tmpGroupTryStagePushMap := make(map[int]int)
  8732. tmpGroupTryStageFollowMap := make(map[int]int)
  8733. tmpGroupTryStageReadyMap := make(map[int]int)
  8734. tmpGroupTryStageInitMap := make(map[int]int)
  8735. for _, city := range cityList {
  8736. //城市数据
  8737. //每个城市的数据
  8738. tmpCompanyReportRecordNumList := make([]statistic_report.CompanyAreaNum, 0)
  8739. for index, adminData := range companyAreaDataMapList {
  8740. startDateIndexList[index] = adminData.StartDate
  8741. endDateIndexList[index] = adminData.EndDate
  8742. var tmpTryOutNum, tmpFormalNum, tmpActiveStatus, tmpAllActiveStatus, tmpNoIncrementalActiveStatus int
  8743. var tmpTryStagePushNum, tmpTryStageFollowNum, tmpTryStageReadyNum, tmpTryStageInitNum int
  8744. var tmpFormalCompanyIds string //正式客户id集合
  8745. var tmpTryOutCompanyIds string //试用客户ID集合
  8746. var tmpPushCompanyIds string //试用(推进)客户ID集合
  8747. var tmpFollowCompanyIds string //试用(跟踪)客户ID集合
  8748. var tmpReadyCompanyIds string //试用(预备)客户ID集合
  8749. var tmpInitCompanyIds string //试用(未分类)客户ID集合
  8750. if num, ok := adminData.TryOutMap[city]; ok {
  8751. tmpTryOutNum = num
  8752. }
  8753. if num, ok := adminData.FormalMap[city]; ok {
  8754. tmpFormalNum = num
  8755. }
  8756. if companyIds, ok := adminData.FormalIdMap[city]; ok {
  8757. tmpFormalCompanyIds = companyIds
  8758. }
  8759. if companyIds, ok := adminData.TryOutIdMap[city]; ok {
  8760. tmpTryOutCompanyIds = companyIds
  8761. }
  8762. if companyIds, ok := adminData.TryStagePushIdsMap[city]; ok {
  8763. tmpPushCompanyIds = companyIds
  8764. }
  8765. if companyIds, ok := adminData.TryStageFollowIdsMap[city]; ok {
  8766. tmpFollowCompanyIds = companyIds
  8767. }
  8768. if companyIds, ok := adminData.TryStageReadyIdsMap[city]; ok {
  8769. tmpReadyCompanyIds = companyIds
  8770. }
  8771. if companyIds, ok := adminData.TryStageInitIdsMap[city]; ok {
  8772. tmpInitCompanyIds = companyIds
  8773. }
  8774. if num, ok := adminData.ActiveMap[city]; ok {
  8775. tmpActiveStatus = num
  8776. }
  8777. if num, ok := adminData.AllActiveMap[city]; ok {
  8778. tmpAllActiveStatus = num
  8779. }
  8780. if num, ok := adminData.NoIncrementalActiveMap[city]; ok {
  8781. tmpNoIncrementalActiveStatus = num
  8782. }
  8783. // 每个用户的试用标签统计 推进-跟踪-预备-未分类
  8784. if num, ok := adminData.TryStagePushNum[city]; ok {
  8785. tmpTryStagePushNum = num
  8786. }
  8787. if num, ok := adminData.TryStageFollowNum[city]; ok {
  8788. tmpTryStageFollowNum = num
  8789. }
  8790. if num, ok := adminData.TryStageReadyNum[city]; ok {
  8791. tmpTryStageReadyNum = num
  8792. }
  8793. if num, ok := adminData.TryStageInitNum[city]; ok {
  8794. tmpTryStageInitNum = num
  8795. }
  8796. tmpAdminRsReportRecordNum := statistic_report.CompanyAreaNum{
  8797. TryOutNum: tmpTryOutNum,
  8798. FormalNum: tmpFormalNum,
  8799. FormalIds: tmpFormalCompanyIds,
  8800. ActiveNum: tmpActiveStatus,
  8801. AllActiveNum: tmpAllActiveStatus,
  8802. NoIncrementalActiveNum: tmpNoIncrementalActiveStatus,
  8803. StartDate: adminData.StartDate,
  8804. EndDate: adminData.EndDate,
  8805. TryStagePushNum: tmpTryStagePushNum,
  8806. TryStageFollowNum: tmpTryStageFollowNum,
  8807. TryStageReadyNum: tmpTryStageReadyNum,
  8808. TryStageInitNum: tmpTryStageInitNum,
  8809. TotalNum: tmpTryOutNum + tmpFormalNum,
  8810. }
  8811. tmpCompanyReportRecordNumList = append(tmpCompanyReportRecordNumList, tmpAdminRsReportRecordNum)
  8812. //组内数据汇总
  8813. tmpGroupTryOutNumMap[index] += tmpTryOutNum
  8814. tmpGroupFormalNumMap[index] += tmpFormalNum
  8815. // 正式客户id
  8816. if tmpFormalCompanyIds != `` {
  8817. tmpGroupFormalCompanyIds, ok := tmpGroupFormalCompanyIdsMap[index]
  8818. if ok {
  8819. tmpGroupFormalCompanyIdsMap[index] = tmpGroupFormalCompanyIds + "," + tmpFormalCompanyIds
  8820. } else {
  8821. tmpGroupFormalCompanyIdsMap[index] = tmpFormalCompanyIds
  8822. }
  8823. }
  8824. tmpGroupActiveNumMap[index] += tmpActiveStatus
  8825. tmpGroupAllActiveNumMap[index] += tmpActiveStatus
  8826. tmpGroupNoIncrementalActiveNumMap[index] += tmpActiveStatus
  8827. tmpGroupTryStagePushMap[index] += tmpTryStagePushNum
  8828. tmpGroupTryStageFollowMap[index] += tmpTryStageFollowNum
  8829. tmpGroupTryStageReadyMap[index] += tmpTryStageReadyNum
  8830. tmpGroupTryStageInitMap[index] += tmpTryStageInitNum
  8831. // 其他客户IDs
  8832. if tmpTryOutCompanyIds != `` {
  8833. a, ok := tmpGroupTryOutCompanyIdsMap[index]
  8834. if ok {
  8835. tmpGroupTryOutCompanyIdsMap[index] = a + "," + tmpTryOutCompanyIds
  8836. } else {
  8837. tmpGroupTryOutCompanyIdsMap[index] = tmpTryOutCompanyIds
  8838. }
  8839. }
  8840. if tmpPushCompanyIds != `` {
  8841. a, ok := tmpGroupPushCompanyIdsMap[index]
  8842. if ok {
  8843. tmpGroupPushCompanyIdsMap[index] = a + "," + tmpPushCompanyIds
  8844. } else {
  8845. tmpGroupPushCompanyIdsMap[index] = tmpPushCompanyIds
  8846. }
  8847. }
  8848. if tmpFollowCompanyIds != `` {
  8849. a, ok := tmpGroupFollowCompanyIdsMap[index]
  8850. if ok {
  8851. tmpGroupFollowCompanyIdsMap[index] = a + "," + tmpFollowCompanyIds
  8852. } else {
  8853. tmpGroupFollowCompanyIdsMap[index] = tmpFollowCompanyIds
  8854. }
  8855. }
  8856. if tmpReadyCompanyIds != `` {
  8857. a, ok := tmpGroupReadyCompanyIdsMap[index]
  8858. if ok {
  8859. tmpGroupReadyCompanyIdsMap[index] = a + "," + tmpReadyCompanyIds
  8860. } else {
  8861. tmpGroupReadyCompanyIdsMap[index] = tmpReadyCompanyIds
  8862. }
  8863. }
  8864. if tmpInitCompanyIds != `` {
  8865. a, ok := tmpGroupInitCompanyIdsMap[index]
  8866. if ok {
  8867. tmpGroupInitCompanyIdsMap[index] = a + "," + tmpInitCompanyIds
  8868. } else {
  8869. tmpGroupInitCompanyIdsMap[index] = tmpInitCompanyIds
  8870. }
  8871. }
  8872. //总数据汇总
  8873. tmpAllTryOutNumMap[index] += tmpTryOutNum
  8874. tmpAllFormalNumMap[index] += tmpFormalNum
  8875. tmpAllActiveNumMap[index] += tmpActiveStatus
  8876. tmpAllAllActiveNumMap[index] += tmpAllActiveStatus
  8877. tmpAllNoIncrementalActiveNumMap[index] += tmpNoIncrementalActiveStatus
  8878. // 总数据试用标签数据汇总
  8879. tmpAllTryStagePushMap[index] += tmpTryStagePushNum
  8880. tmpAllTryStageFollowMap[index] += tmpTryStageFollowNum
  8881. tmpAllTryStageReadyMap[index] += tmpTryStageReadyNum
  8882. tmpAllTryStageInitMap[index] += tmpTryStageInitNum
  8883. }
  8884. tmpAdminReportRecord := statistic_report.CityRecord{
  8885. Name: city,
  8886. CompanyAreaNumNumList: tmpCompanyReportRecordNumList,
  8887. }
  8888. tmpGroupCityReportRecord = append(tmpGroupCityReportRecord, tmpAdminReportRecord)
  8889. }
  8890. for i := 0; i < len(tmpGroupActiveNumMap); i++ {
  8891. tmpGroupCompanyReportRecordNum := statistic_report.CompanyAreaNum{
  8892. TryOutNum: tmpGroupTryOutNumMap[i],
  8893. FormalNum: tmpGroupFormalNumMap[i],
  8894. FormalIds: tmpGroupFormalCompanyIdsMap[i],
  8895. ActiveNum: tmpGroupActiveNumMap[i],
  8896. AllActiveNum: tmpGroupAllActiveNumMap[i],
  8897. NoIncrementalActiveNum: tmpGroupNoIncrementalActiveNumMap[i],
  8898. StartDate: startDateIndexList[i],
  8899. EndDate: endDateIndexList[i],
  8900. TryStagePushNum: tmpGroupTryStagePushMap[i],
  8901. TryStageFollowNum: tmpGroupTryStageFollowMap[i],
  8902. TryStageReadyNum: tmpGroupTryStageReadyMap[i],
  8903. TryStageInitNum: tmpGroupTryStageInitMap[i],
  8904. TotalNum: tmpGroupTryOutNumMap[i] + tmpGroupFormalNumMap[i],
  8905. TryOutIds: tmpGroupTryOutCompanyIdsMap[i],
  8906. TryStagePushIds: tmpGroupPushCompanyIdsMap[i],
  8907. TryStageFollowIds: tmpGroupFollowCompanyIdsMap[i],
  8908. TryStageReadyIds: tmpGroupReadyCompanyIdsMap[i],
  8909. TryStageInitIds: tmpGroupInitCompanyIdsMap[i],
  8910. }
  8911. tmpGroupCompanyReportRecordNumList = append(tmpGroupCompanyReportRecordNumList, tmpGroupCompanyReportRecordNum)
  8912. }
  8913. groupReportRecord := statistic_report.GroupCityRecord{
  8914. Item: tmpGroupCityReportRecord,
  8915. Name: province,
  8916. CompanyAreaNumNumList: tmpGroupCompanyReportRecordNumList,
  8917. }
  8918. groupReportRecordList = append(groupReportRecordList, groupReportRecord)
  8919. }
  8920. resp.List = groupReportRecordList
  8921. br.Ret = 200
  8922. br.Success = true
  8923. br.Msg = "获取成功"
  8924. br.Data = resp
  8925. }
  8926. // CompanyTryOutDayList
  8927. // @Title 客户累计试用详情接口
  8928. // @Description 客户累计试用详情接口
  8929. // @Param CompanyId query int true "客户id"
  8930. // @Param ProductId query int true "产品id"
  8931. // @Success 200 {object} company.CompanyTryOutDayListResp
  8932. // @router /company/tryOutDayList [get]
  8933. func (this *CompanyTodoController) CompanyTryOutDayList() {
  8934. br := new(models.BaseResponse).Init()
  8935. defer func() {
  8936. this.Data["json"] = br
  8937. this.ServeJSON()
  8938. }()
  8939. companyId, _ := this.GetInt("CompanyId")
  8940. if companyId <= 0 {
  8941. br.Msg = "请选择客户"
  8942. return
  8943. }
  8944. productId, _ := this.GetInt("ProductId")
  8945. if productId <= 0 {
  8946. br.Msg = "请选择类型"
  8947. return
  8948. }
  8949. pageSize, _ := this.GetInt("PageSize")
  8950. currentIndex, _ := this.GetInt("CurrentIndex")
  8951. var startSize int
  8952. if pageSize <= 0 {
  8953. pageSize = utils.PageSize20
  8954. }
  8955. if currentIndex <= 0 {
  8956. currentIndex = 1
  8957. }
  8958. startSize = paging.StartIndex(currentIndex, pageSize)
  8959. // 获取任务信息
  8960. total, err := company.GetCompanyProductTryOutUpdateLogTotal(companyId, productId)
  8961. if err != nil {
  8962. br.Msg = "获取任务信息失败"
  8963. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  8964. return
  8965. }
  8966. // 获取任务信息
  8967. list, err := company.GetCompanyProductTryOutUpdateLogList(companyId, productId, startSize, pageSize)
  8968. if err != nil {
  8969. br.Msg = "获取任务信息失败"
  8970. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  8971. return
  8972. }
  8973. //var list []*company_todo.CompanyTodoListItem
  8974. //for _, v := range todos {
  8975. // temp := &company_todo.CompanyTodoListItem{
  8976. // CompanyTodo: v,
  8977. // }
  8978. // temp.EndTimeStr = temp.EndTime.Format(utils.FormatDate)
  8979. // if temp.EndTimeStr == "0001-01-01" {
  8980. // temp.EndTimeStr = ""
  8981. // }
  8982. // list = append(list, temp)
  8983. //}
  8984. if len(list) <= 0 {
  8985. list = make([]*company.CompanyProductTryOutUpdateLog, 0)
  8986. }
  8987. page := paging.GetPaging(currentIndex, pageSize, total)
  8988. resp := company.CompanyTryOutDayListResp{
  8989. Paging: page,
  8990. List: list,
  8991. }
  8992. br.Ret = 200
  8993. br.Success = true
  8994. br.Msg = "获取成功"
  8995. br.Data = resp
  8996. }
  8997. // @Title 获取流水信息接口
  8998. // @Description 获取流水信息接口
  8999. // @Param CompanyId query int true "客户id"
  9000. // @Success 200 {object} company.CygxActivityPointsBillListResp
  9001. // @router /company/activity/points/bill [get]
  9002. func (this *CompanyTodoController) CompanyActivityPointsBill() {
  9003. br := new(models.BaseResponse).Init()
  9004. defer func() {
  9005. this.Data["json"] = br
  9006. this.ServeJSON()
  9007. }()
  9008. companyId, _ := this.GetInt("CompanyId")
  9009. if companyId <= 0 {
  9010. br.Msg = "请选择客户"
  9011. return
  9012. }
  9013. // 获取流水信息
  9014. list, err := cygx.CygxActivityPointsBillByCompanyId(companyId)
  9015. if err != nil {
  9016. br.Msg = "获取任务信息失败"
  9017. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  9018. return
  9019. }
  9020. if len(list) <= 0 {
  9021. list = make([]*cygx.CygxActivityPointsBillResp, 0)
  9022. }
  9023. resp := cygx.CygxActivityPointsBillListResp{
  9024. List: list,
  9025. }
  9026. br.Ret = 200
  9027. br.Success = true
  9028. br.Msg = "获取成功"
  9029. br.Data = resp
  9030. }
  9031. // DelRemark
  9032. // @Title 删除备注
  9033. // @Description 删除备注
  9034. // @Param request body company.RemarkDelReq true "type json string"
  9035. // @Success 200 操作成功
  9036. // @router /remark/del [post]
  9037. func (this *CompanyController) DelRemark() {
  9038. br := new(models.BaseResponse).Init()
  9039. defer func() {
  9040. if br.ErrMsg == "" {
  9041. br.IsSendEmail = false
  9042. }
  9043. this.Data["json"] = br
  9044. this.ServeJSON()
  9045. }()
  9046. sysUser := this.SysUser
  9047. if sysUser == nil {
  9048. br.Msg = "请登录"
  9049. br.ErrMsg = "请登录,SysUser Is Empty"
  9050. br.Ret = 408
  9051. return
  9052. }
  9053. var req company.RemarkDelReq
  9054. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  9055. if err != nil {
  9056. br.Msg = "参数解析异常!"
  9057. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  9058. return
  9059. }
  9060. if req.RemarkId <= 0 {
  9061. br.Msg = "参数有误"
  9062. br.ErrMsg = "参数有误, 备注ID有误"
  9063. return
  9064. }
  9065. item, e := company.GetCompanyRemarkById(req.RemarkId)
  9066. if e != nil {
  9067. if e.Error() == utils.ErrNoRow() {
  9068. br.Msg = "备注已被删除, 请刷新页面"
  9069. return
  9070. }
  9071. br.Msg = "备注信息有误"
  9072. br.ErrMsg = "获取客户备注失败, Err: " + e.Error()
  9073. return
  9074. }
  9075. if item.SysUserId != sysUser.AdminId {
  9076. br.Msg = "仅备注添加人可删除"
  9077. return
  9078. }
  9079. product, e := company.GetCompanyProductByCompanyIdAndProductId(item.CompanyId, item.ProductId)
  9080. if e != nil {
  9081. br.Msg = "操作失败"
  9082. br.ErrMsg = "获取客户产品信息失败, Err: " + e.Error()
  9083. return
  9084. }
  9085. if e := company.DelCompanyRemark(req.RemarkId); e != nil {
  9086. br.Msg = "操作失败"
  9087. br.ErrMsg = "删除客户备注失败, Err: " + e.Error()
  9088. return
  9089. }
  9090. content := fmt.Sprintf("%s%s", "删除备注: ", item.Remark)
  9091. _ = services.AddCompanyOperationRecord(product.CompanyId, product.SellerId, sysUser.AdminId, product.ProductId, sysUser.AdminId, product.CompanyName, product.ProductName, sysUser.RealName, "删除备注", "del_remark", content, sysUser.RealName, "", product.Status)
  9092. if item.ProductId == utils.COMPANY_PRODUCT_RAI_ID {
  9093. go services.DelCompanyHistoryRemark("company_product_remark", req.RemarkId) // 删除
  9094. }
  9095. br.Ret = 200
  9096. br.Success = true
  9097. br.Msg = "操作成功"
  9098. }
  9099. // @Title 获取流水信息接口
  9100. // @Description 获取流水信息接口
  9101. // @Param CompanyId query int true "客户id"
  9102. // @Success 200 {object} company.CygxActivityPointsBillListResp
  9103. // @router /company/activity/special/points/bill [get]
  9104. func (this *CompanyTodoController) CompanyActivitySpecialPointsBill() {
  9105. br := new(models.BaseResponse).Init()
  9106. defer func() {
  9107. this.Data["json"] = br
  9108. this.ServeJSON()
  9109. }()
  9110. companyId, _ := this.GetInt("CompanyId")
  9111. if companyId <= 0 {
  9112. br.Msg = "请选择客户"
  9113. return
  9114. }
  9115. // 获取流水信息
  9116. var condition string
  9117. var pars []interface{}
  9118. condition += ` AND company_id = ? `
  9119. pars = append(pars, companyId)
  9120. //查询当年的数据
  9121. //condition += ` AND b.create_time >= ? `
  9122. //pars = append(pars, time.Now().Format(utils.FormatYearDate)+"-01-01")
  9123. list, err := cygx.GetCygxActivitySpecialTripBillDetailListAll(condition, pars)
  9124. if err != nil {
  9125. br.Msg = "获取任务信息失败"
  9126. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  9127. return
  9128. }
  9129. //userType, tripRemaining, mapChartName, err := cygxService.GetChartPermissionSpecialSurplusByCompany(companyId)
  9130. //if err != nil {
  9131. // br.Msg = "获取专项调研剩余次数失败"
  9132. // br.ErrMsg = "获取专项调研剩余次数失败,err:" + err.Error()
  9133. // return
  9134. //}
  9135. //chartMap := map[int]string{utils.YI_YAO_ID: utils.YI_YAO_NAME, utils.XIAO_FEI_ID: utils.XIAO_FEI_NAME, utils.KE_JI_ID: utils.KE_JI_NAME, utils.ZHI_ZAO_ID: utils.ZHI_ZAO_NAME}
  9136. resp := new(cygx.CygxActivitySpecialPointsBillResp)
  9137. //lastTripRemaining := 0
  9138. for _, v := range list {
  9139. item := cygx.CygxActivitySpecialPointsBillRespItem{
  9140. Id: v.Id,
  9141. CreateTime: v.CreateTime.Format(utils.FormatDateTime),
  9142. CompanyId: v.CompanyId,
  9143. CompanyName: v.CompanyName,
  9144. RealName: v.RealName,
  9145. BillDetailed: v.BillDetailed,
  9146. ActivityName: v.ResearchTheme,
  9147. ChartPermissionId: v.ChartPermissionId,
  9148. ChartPermissionName: v.ChartPermissionName,
  9149. Total: v.Total,
  9150. }
  9151. if v.ActivityId == 0 {
  9152. item.Content = v.Content
  9153. } else {
  9154. if v.DoType == 1 && v.Way != 4 && v.Way != 3 {
  9155. item.Content = item.ActivityName + "--报名"
  9156. } else if v.DoType == 2 && v.Way != 4 && v.Way != 3 {
  9157. item.Content = item.ActivityName + "--取消报名"
  9158. } else if v.Way == 4 {
  9159. item.Content = item.ActivityName + "--活动取消"
  9160. }
  9161. }
  9162. //if userType == 2 {
  9163. // if i== 0 {
  9164. // item.Total += strconv.Itoa(tripRemaining) + "次"
  9165. // } else {
  9166. // item.Total += strconv.Itoa(tripRemaining-list[i-1].BillDetailed) + "次"
  9167. // }
  9168. // //if v.BillDetailed < 4 {
  9169. // // item.Total += strconv.Itoa(lastTripRemaining-list[i-1].BillDetailed) + "次"
  9170. // //} else {
  9171. // // item.Total += strconv.Itoa(lastTripRemaining) + "次"
  9172. // //}
  9173. //} else {
  9174. // for k, num := range mapChartName {
  9175. // if i== 0 {
  9176. // item.Total += k + strconv.Itoa(num) + "次+"
  9177. // } else {
  9178. // if list[i-1].ActivityId == 0 {
  9179. // item.Total += k + strconv.Itoa(num) + "次+"
  9180. // } else {
  9181. // item.Total += k + strconv.Itoa(num-list[i-1].BillDetailed) + "次+"
  9182. // }
  9183. // }
  9184. // //if num > 0 {
  9185. // // if i== 0{
  9186. // // item.Total += k + strconv.Itoa(num) + "次+"
  9187. // // } else {
  9188. // // item.Total += k + strconv.Itoa(num-v.BillDetailed) + "次+"
  9189. // // }
  9190. // //}
  9191. // }
  9192. // item.Total = strings.TrimRight(item.Total, "+")
  9193. //}
  9194. resp.List = append(resp.List, &item)
  9195. }
  9196. br.Ret = 200
  9197. br.Success = true
  9198. br.Msg = "获取成功"
  9199. br.Data = resp
  9200. }