company.go 297 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093
  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. 时长根据客户状态定义,
  112. 若为冻结客户或者流失客户,则展示冻结时长或流失时长;
  113. 若为正式或试用客户,展示到期时长;
  114. */
  115. lenList := len(list)
  116. for i := 0; i < lenList; i++ {
  117. duration := ""
  118. item := list[i]
  119. itemStatus := item.Status
  120. if !strings.Contains(item.Status, "/") {
  121. if item.Status == utils.COMPANY_STATUS_FREEZE {
  122. if item.FreezeEndDate != "" {
  123. freeZeTime, _ := time.Parse(utils.FormatDate, item.FreezeEndDate)
  124. freeZeTime = freeZeTime.AddDate(0, 0, 1)
  125. sub := freeZeTime.Sub(time.Now())
  126. if sub < 0 {
  127. sub = 0
  128. }
  129. duration = fmt.Sprintf("%v", int(sub.Hours()/24))
  130. }
  131. } else if item.Status == utils.COMPANY_STATUS_LOSE {
  132. if item.LossTime != "" {
  133. lossTime, err := time.Parse(utils.FormatDateTime, item.LossTime)
  134. if err != nil {
  135. fmt.Println("err:" + err.Error())
  136. }
  137. lossTime = lossTime.AddDate(0, 0, 1)
  138. sub := time.Now().Sub(lossTime)
  139. if sub < 0 {
  140. sub = 0
  141. }
  142. duration = fmt.Sprintf("%v", int(sub.Hours()/24))
  143. }
  144. } else if item.Status == utils.COMPANY_STATUS_FORMAL ||
  145. item.Status == utils.COMPANY_STATUS_TRY_OUT {
  146. if item.EndDate != "" {
  147. endDate, _ := time.Parse(utils.FormatDate, item.EndDate)
  148. endDate = endDate.AddDate(0, 0, 1)
  149. sub := endDate.Sub(time.Now())
  150. if sub < 0 {
  151. sub = 0
  152. }
  153. duration = fmt.Sprintf("%v", int(sub.Hours()/24))
  154. }
  155. } else if item.Status == utils.COMPANY_STATUS_TRY_OUT {
  156. duration = "永续"
  157. } else {
  158. duration = "-"
  159. }
  160. } else {
  161. statusArr := strings.Split(item.Status, "/")
  162. //freezeArr := strings.Split(item.FreezeTime, "/") //0:ficc,1:权益
  163. freezeArr := strings.Split(item.FreezeEndDate, "/") //冻结结束日期:0:ficc,1:权益
  164. lossArr := strings.Split(item.LossTime, "/") //0:ficc,1:权益
  165. endDateArr := strings.Split(item.EndDate, "/")
  166. var ficcFreeze, tryFreeze string
  167. var ficcLoss, tryLoss string
  168. var ficcEndDate, tryEndDate string
  169. ficcStatus := statusArr[0]
  170. tryOutStatus := statusArr[1]
  171. //if len(freezeArr) > 1 {
  172. // ficcFreeze = freezeArr[0]
  173. // tryFreeze = freezeArr[1]
  174. //}
  175. //if len(lossArr) > 1 {
  176. // ficcLoss = lossArr[0]
  177. // tryLoss = lossArr[1]
  178. //}
  179. //结束日期
  180. if len(endDateArr) > 1 {
  181. ficcEndDate = endDateArr[0]
  182. tryEndDate = endDateArr[1]
  183. }
  184. //冻结
  185. if ficcStatus == utils.COMPANY_STATUS_FREEZE && len(freezeArr) > 0 {
  186. //ficc
  187. ficcFreeze = freezeArr[0]
  188. }
  189. if tryOutStatus == utils.COMPANY_STATUS_FREEZE && len(freezeArr) > 0 {
  190. //权益
  191. if len(freezeArr) == 1 {
  192. tryFreeze = freezeArr[0]
  193. } else {
  194. tryFreeze = freezeArr[1]
  195. }
  196. }
  197. //流失
  198. if ficcStatus == utils.COMPANY_STATUS_LOSE && len(lossArr) > 0 {
  199. //ficc
  200. ficcLoss = lossArr[0]
  201. }
  202. if tryOutStatus == utils.COMPANY_STATUS_LOSE && len(lossArr) > 0 {
  203. //权益
  204. if len(lossArr) == 1 {
  205. tryLoss = lossArr[0]
  206. } else {
  207. tryLoss = lossArr[1]
  208. }
  209. }
  210. //ficc的判断
  211. switch ficcStatus {
  212. case utils.COMPANY_STATUS_FREEZE: //冻结
  213. if ficcFreeze != "" {
  214. ficcFreeZeTime, _ := time.Parse(utils.FormatDate, ficcFreeze)
  215. ficcFreeZeTime = ficcFreeZeTime.AddDate(0, 0, 1)
  216. sub := ficcFreeZeTime.Sub(time.Now())
  217. if sub < 0 {
  218. sub = 0
  219. }
  220. duration = fmt.Sprintf("%v", int(sub.Hours()/24))
  221. }
  222. case utils.COMPANY_STATUS_LOSE: //流失
  223. if ficcLoss != "" {
  224. ficcLossTime, _ := time.Parse(utils.FormatDateTime, ficcLoss)
  225. ficcLossTime = ficcLossTime.AddDate(0, 0, 1)
  226. sub := time.Now().Sub(ficcLossTime)
  227. if sub < 0 {
  228. sub = 0
  229. }
  230. duration = fmt.Sprintf("%v", int(sub.Hours()/24))
  231. }
  232. case utils.COMPANY_STATUS_FORMAL, utils.COMPANY_STATUS_TRY_OUT:
  233. if ficcEndDate != "" {
  234. ficcEndDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
  235. ficcEndDateTime = ficcEndDateTime.AddDate(0, 0, 1)
  236. sub := ficcEndDateTime.Sub(time.Now())
  237. if sub < 0 {
  238. sub = 0
  239. }
  240. duration = fmt.Sprintf("%v", int(sub.Hours()/24))
  241. }
  242. case utils.COMPANY_STATUS_FOREVER:
  243. duration = "永续"
  244. case utils.COMPANY_STATUS_CLOSE:
  245. duration = "-"
  246. }
  247. //权益的判断
  248. switch tryOutStatus {
  249. case utils.COMPANY_STATUS_FREEZE: //冻结
  250. if tryFreeze != "" {
  251. tryOutFreeZeTime, _ := time.Parse(utils.FormatDate, tryFreeze)
  252. tryOutFreeZeTime = tryOutFreeZeTime.AddDate(0, 0, 1)
  253. sub := tryOutFreeZeTime.Sub(time.Now())
  254. if sub < 0 {
  255. sub = 0
  256. }
  257. if duration != "" {
  258. duration = duration + "/" + fmt.Sprintf("%v", int(sub.Hours()/24))
  259. }
  260. }
  261. case utils.COMPANY_STATUS_LOSE: //流失
  262. if tryLoss != "" {
  263. tryOutLossTime, _ := time.Parse(utils.FormatDateTime, tryLoss)
  264. tryOutLossTime = tryOutLossTime.AddDate(0, 0, 1)
  265. sub := time.Now().Sub(tryOutLossTime)
  266. if sub < 0 {
  267. sub = 0
  268. }
  269. if duration != "" {
  270. duration = duration + "/" + fmt.Sprintf("%v", int(sub.Hours()/24))
  271. }
  272. }
  273. case utils.COMPANY_STATUS_FORMAL, utils.COMPANY_STATUS_TRY_OUT:
  274. if tryEndDate != "" {
  275. tryEndDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
  276. tryEndDateTime = tryEndDateTime.AddDate(0, 0, 1)
  277. sub := tryEndDateTime.Sub(time.Now())
  278. if sub < 0 {
  279. sub = 0
  280. }
  281. if duration != "" {
  282. duration = duration + "/" + fmt.Sprintf("%v", int(sub.Hours()/24))
  283. }
  284. }
  285. case utils.COMPANY_STATUS_FOREVER:
  286. if duration != "" {
  287. duration = duration + "/" + "永续"
  288. }
  289. case utils.COMPANY_STATUS_CLOSE:
  290. duration = "-"
  291. }
  292. //list[i].ApproveStatus = ""
  293. }
  294. approveStatusMap := make(map[int]string)
  295. if item.ProductId == 1 {
  296. approveStatusMap[1] = item.ApproveStatus
  297. } else if item.ProductId == 2 {
  298. approveStatusMap[2] = item.ApproveStatus
  299. }
  300. if strings.Contains(item.ApproveStatus, "/") {
  301. approveStatusSlice := strings.Split(item.ApproveStatus, "/")
  302. approveStatusMap[1] = approveStatusSlice[0]
  303. approveStatusMap[2] = approveStatusSlice[1]
  304. } else {
  305. approveStatusMap[1] = item.ApproveStatus
  306. approveStatusMap[2] = item.ApproveStatus
  307. }
  308. productIdMap := make(map[int]int)
  309. if strings.Contains(item.ProductIds, "/") {
  310. productIdSlice := strings.Split(item.ProductIds, "/")
  311. productIdMap[1], _ = strconv.Atoi(productIdSlice[0])
  312. productIdMap[2], _ = strconv.Atoi(productIdSlice[1])
  313. }
  314. if strings.Contains(item.ApproveStatus, "/") {
  315. approveStatusSlice := strings.Split(item.ApproveStatus, "/")
  316. approveStatusMap[1] = approveStatusSlice[0]
  317. approveStatusMap[2] = approveStatusSlice[1]
  318. for k, v := range productIdMap {
  319. approveStatusMap[v] = approveStatusSlice[k-1]
  320. }
  321. } else {
  322. for _, v := range productIdMap {
  323. approveStatusMap[v] = item.ApproveStatus
  324. }
  325. }
  326. sysProductId := services.GetProductId(sysUser.RoleTypeCode)
  327. if sysProductId > 0 {
  328. list[i].ApproveStatus = approveStatusMap[sysProductId]
  329. }
  330. //如果是权益客户,操作者又是权益管理员,那么就对他进行展示研选详情按钮
  331. if strings.Contains(item.CompanyType, utils.COMPANY_CLASSIFY_RAI) && sysUser.RoleName == utils.ROLE_TYPE_RAI_PRODUCT {
  332. list[i].IsResearchShow = 1
  333. }
  334. list[i].Duration = duration
  335. //按钮显示控制
  336. /*btnItem := services.GetCompanySearchPermissionButton(roleTypeCode, itemStatus, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId)
  337. list[i].BtnItem = &btnItem*/
  338. btnItem := new(company.ButtonPermission)
  339. if item.CompanyId != 1 {
  340. *btnItem = services.GetCompanyPermissionButton(roleTypeCode, itemStatus, item.SellerIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, item.ShareSellerId)
  341. //根据销售"领取客户"的权限对部分按钮做限制
  342. btnItem = services.GetCompanyPermissionButtonByReceiveEnabled(btnItem, receiveEnabled)
  343. }
  344. list[i].BtnItem = btnItem
  345. }
  346. if list == nil {
  347. list = make([]*company.CompanySearchItem, 0)
  348. }
  349. resp.List = list
  350. page := paging.GetPaging(currentIndex, pageSize, total)
  351. resp.Paging = page
  352. br.Ret = 200
  353. br.Success = true
  354. br.Msg = "获取成功"
  355. br.Data = resp
  356. }
  357. // List
  358. // @Title 客户列表
  359. // @Description 客户列表接口
  360. // @Param PageSize query int true "每页数据条数"
  361. // @Param CurrentIndex query int true "当前页页码,从1开始"
  362. // @Param Status query string true "状态:'试用','永续','冻结','流失','正式'"
  363. // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
  364. // @Param IndustryId query int true "行业id,0为全部"
  365. // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
  366. // @Param ChartPermissionIds query string false "阅读权限品种ID,多个用英文逗号分开,空字符串为全部"
  367. // @Param ContractPermissionIds query string false "已购品种ID,多个用英文逗号分开,空字符串为全部"
  368. // @Param StartDate query string true "开始时间"
  369. // @Param EndDate query string true "结束时间"
  370. // @Param CreateStartDate query string true "创建开始时间"
  371. // @Param CreateEndDate query string true "创建结束时间"
  372. // @Param KeyWord query string true "搜索关键词"
  373. // @Param Address query string true "地址 , 多个用英文逗号分开 "
  374. // @Param Province query string true "省 , 多个用英文逗号分开 "
  375. // @Param City query string true "市 , 多个用英文逗号分开 "
  376. // @Param PackageType query int true "套餐类型,0:无,1:大套餐,2:小套餐"
  377. // @Param TodoStatus query string true "任务处理状态;枚举值:'无任务','未完成','已完成'"
  378. // @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:'viewTotal':总阅读次数 、 'viewTime':阅读时间 、 'roadShowTotal':累计路演次数 、`expireDay:到期时间` 、 `createTime:创建时间` 、 'formalTime': 转正时间 、 'freezeTime':冻结时间 、'lossTime':流失时间 、'tryStage':试用标签 、'deadline':距离未完成的任务的截止日期的天数、'tryOutDay':试用天数"
  379. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  380. // @Param SortByTodo query bool true "是否根据待办排序,true或false"
  381. // @Param TryStage query int false "试用客户子标签:0全部、1未分类、2 推进、3 跟踪、4 预备"
  382. // @Success 200 {object} company.CompanyListResp
  383. // @router /list [get]
  384. func (this *CompanyController) List() {
  385. br := new(models.BaseResponse).Init()
  386. defer func() {
  387. this.Data["json"] = br
  388. this.ServeJSON()
  389. }()
  390. sysUser := this.SysUser
  391. if sysUser == nil {
  392. br.Msg = "请登录"
  393. br.ErrMsg = "请登录,SysUser Is Empty"
  394. br.Ret = 408
  395. return
  396. }
  397. roleTypeCode := sysUser.RoleTypeCode
  398. pageSize, _ := this.GetInt("PageSize")
  399. currentIndex, _ := this.GetInt("CurrentIndex")
  400. status := this.GetString("Status")
  401. companyType := this.GetString("CompanyType")
  402. industryId, _ := this.GetInt("IndustryId")
  403. adminId := this.GetString("AdminId")
  404. chartPermissionIds := this.GetString("ChartPermissionIds")
  405. contractPermissionIds := this.GetString("ContractPermissionIds")
  406. startDate := this.GetString("StartDate")
  407. endDate := this.GetString("EndDate")
  408. createStartDate := this.GetString("CreateStartDate")
  409. createEndDate := this.GetString("CreateEndDate")
  410. keyWord := this.GetString("KeyWord")
  411. address := this.GetString("Address")
  412. province := this.GetString("Province")
  413. city := this.GetString("City")
  414. keyWord = strings.Trim(keyWord, " ")
  415. keyWord = strings.Replace(keyWord, "'", "", -1)
  416. todoStatus := this.GetString("TodoStatus") //任务状态
  417. tryStage, _ := this.GetInt("TryStage") //试用客户标签
  418. // 套餐类型
  419. packageType, _ := this.GetInt("PackageType")
  420. //排序参数
  421. sortParam := this.GetString("SortParam")
  422. sortType := this.GetString("SortType")
  423. sortByTodo, _ := this.GetBool("SortByTodo")
  424. productId := services.GetProductId(roleTypeCode)
  425. var total int
  426. page := paging.GetPaging(currentIndex, pageSize, total)
  427. resp := new(company.CompanyListResp)
  428. statusItems := make([]*company.CompanyStatus, 0)
  429. var statusArr []string
  430. // 对权益用户隐藏关闭
  431. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  432. statusArr = []string{"全部", "试用", "正式", "冻结", "流失", "永续"}
  433. } else {
  434. statusArr = []string{"全部", "试用", "正式", "冻结", "流失", utils.COMPANY_STATUS_CLOSE, "永续"}
  435. }
  436. //var statusArr = [...]string{"全部", "试用-活跃", "试用-非活跃", "正式", "冻结", "流失", "永续"}
  437. var startSize int
  438. if pageSize <= 0 {
  439. pageSize = utils.PageSize20
  440. }
  441. if currentIndex <= 0 {
  442. currentIndex = 1
  443. }
  444. startSize = paging.StartIndex(currentIndex, pageSize)
  445. var condition string
  446. var pars []interface{}
  447. //流失
  448. var lossCondition string
  449. var lossPars []interface{}
  450. //状态分类查询条件
  451. var permissionCondition string
  452. var permissionPars []interface{}
  453. if companyType != "" {
  454. condition += ` AND b.product_name=? `
  455. pars = append(pars, companyType)
  456. }
  457. if industryId > 0 {
  458. condition += ` AND b.industry_id=? `
  459. pars = append(pars, industryId)
  460. }
  461. if adminId != "" {
  462. condition += ` AND b.seller_id IN (` + adminId + `) `
  463. }
  464. if startDate != "" {
  465. condition += ` AND b.start_date>=? `
  466. pars = append(pars, startDate)
  467. }
  468. if endDate != "" {
  469. condition += ` AND b.end_date<=? `
  470. pars = append(pars, endDate)
  471. }
  472. if createStartDate != "" {
  473. condition += ` AND a.created_time>=? `
  474. pars = append(pars, createStartDate)
  475. }
  476. if createEndDate != "" {
  477. condition += ` AND a.created_time<=? `
  478. pars = append(pars, createEndDate)
  479. }
  480. if address != "" {
  481. var addressSql string
  482. slice := strings.Split(address, ",")
  483. for _, v := range slice {
  484. addressSql += "'" + v + "'" + ","
  485. }
  486. addressSql = strings.TrimRight(addressSql, ",")
  487. condition += ` AND a.address IN (` + addressSql + `) `
  488. }
  489. if province != "" {
  490. var provinceSql string
  491. slice := strings.Split(province, ",")
  492. for _, v := range slice {
  493. provinceSql += "'" + v + "'" + ","
  494. }
  495. provinceSql = strings.TrimRight(provinceSql, ",")
  496. condition += ` AND a.province IN (` + provinceSql + `) `
  497. }
  498. if city != "" {
  499. var citySql string
  500. slice := strings.Split(city, ",")
  501. for _, v := range slice {
  502. citySql += "'" + v + "'" + ","
  503. }
  504. citySql = strings.TrimRight(citySql, ",")
  505. condition += ` AND a.city IN (` + citySql + `) `
  506. }
  507. if keyWord != "" {
  508. companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
  509. if err != nil {
  510. br.Msg = "获取客户信息失败"
  511. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  512. return
  513. }
  514. if companyIdStr != "" {
  515. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.credit_code LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  516. } else {
  517. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.credit_code LIKE '%` + keyWord + `%' ) `
  518. }
  519. }
  520. //任务状态
  521. if todoStatus != "" {
  522. condition += ` AND b.todo_status =? `
  523. pars = append(pars, todoStatus)
  524. }
  525. // 阅读权限/已购品种筛选
  526. cond, emp, e := services.FilterReadAndContractAuth(chartPermissionIds, contractPermissionIds, condition)
  527. if e != nil {
  528. br.Msg = "获取失败"
  529. br.ErrMsg = "FilterReadAndContractAuth err: " + e.Error()
  530. return
  531. }
  532. if emp {
  533. for _, v := range statusArr {
  534. statusCount := new(company.CompanyStatus)
  535. if v == "全部" {
  536. statusCount.Status = "全部"
  537. statusCount.Count = 0
  538. } else {
  539. statusCount.Status = v
  540. statusCount.Count = 0
  541. }
  542. statusItems = append(statusItems, statusCount)
  543. }
  544. items := make([]*company.CompanyListItem, 0)
  545. resp.List = items
  546. resp.Paging = page
  547. resp.StatusCount = statusItems
  548. br.Msg = "获取成功"
  549. br.Ret = 200
  550. br.Data = resp
  551. return
  552. }
  553. condition = cond
  554. //套餐类型
  555. if packageType > 0 {
  556. condition += ` AND b.package_type=? `
  557. pars = append(pars, packageType)
  558. }
  559. lossCondition = condition
  560. lossPars = pars
  561. permissionCondition = condition
  562. permissionPars = pars
  563. //流失客户统计
  564. lossCondition += ` AND status='流失' `
  565. //权限控制
  566. {
  567. //如果不是超级管理员或者财务
  568. if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && roleTypeCode != utils.ROLE_TYPE_CODE_FINANCE {
  569. //如果是部门管理员
  570. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  571. condition += ` AND b.product_id=? `
  572. pars = append(pars, productId)
  573. lossCondition += ` AND b.product_id=? `
  574. lossPars = append(lossPars, productId)
  575. permissionCondition += ` AND b.product_id=? `
  576. permissionPars = append(permissionPars, productId)
  577. //}
  578. //else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DIRECTOR {
  579. // condition += ` AND b.product_id=? `
  580. // pars = append(pars, productId)
  581. //
  582. // lossCondition += ` AND b.product_id=? `
  583. // lossPars = append(lossPars, productId)
  584. //
  585. // permissionCondition += ` AND b.product_id=? `
  586. // permissionPars = append(permissionPars, productId)
  587. } else {
  588. condition += ` AND b.product_id=? `
  589. pars = append(pars, productId)
  590. lossCondition += ` AND b.product_id=? `
  591. lossPars = append(lossPars, productId)
  592. permissionCondition += ` AND b.product_id=? `
  593. permissionPars = append(permissionPars, productId)
  594. if status == "全部" {
  595. ////如果是筛选了流失客户状态
  596. if sysUser.Authority <= 0 {
  597. condition += ` AND (b.seller_id=? OR status='流失') `
  598. pars = append(pars, sysUser.AdminId)
  599. permissionCondition += ` AND b.seller_id=? `
  600. permissionPars = append(permissionPars, sysUser.AdminId)
  601. } else {
  602. if sysUser.Authority == 1 {
  603. condition += ` AND (b.department_id=? OR status='流失')`
  604. pars = append(pars, sysUser.DepartmentId)
  605. permissionCondition += ` AND b.department_id=? `
  606. permissionPars = append(permissionPars, sysUser.DepartmentId)
  607. }
  608. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  609. if status != utils.COMPANY_STATUS_LOSE {
  610. condition += ` AND (b.group_id=? OR status='流失') `
  611. pars = append(pars, sysUser.GroupId)
  612. }
  613. permissionCondition += ` AND b.group_id=? `
  614. permissionPars = append(permissionPars, sysUser.GroupId)
  615. }
  616. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  617. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  618. if err != nil {
  619. br.Msg = "获取失败"
  620. br.ErrMsg = "查询父级id异常" + err.Error()
  621. return
  622. }
  623. var ids []*string
  624. if pid != nil {
  625. if *pid != 0 {
  626. //销售主管放在三级列表中
  627. ids, err = company.GetGroupIdsByParentId(*pid)
  628. if err != nil {
  629. fmt.Println(err.Error())
  630. }
  631. } else {
  632. //销售主管放在二级列表中
  633. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  634. if err != nil {
  635. fmt.Println(err.Error())
  636. }
  637. }
  638. }
  639. var idSlice []string
  640. var sid string
  641. for _, id := range ids {
  642. idSlice = append(idSlice, *id)
  643. }
  644. //加入父级groupId
  645. if *pid > 0 {
  646. idSlice = append(idSlice, strconv.Itoa(*pid))
  647. } else {
  648. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  649. }
  650. sid = strings.Join(idSlice, ",")
  651. if len(sid) > 0 {
  652. if status != utils.COMPANY_STATUS_LOSE {
  653. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  654. //pars = append(pars, sysUser.GroupId)
  655. }
  656. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  657. } else {
  658. if status != utils.COMPANY_STATUS_LOSE {
  659. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  660. //pars = append(pars, sysUser.GroupId)
  661. }
  662. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  663. }
  664. //permissionPars = append(permissionPars, sysUser.GroupId)
  665. }
  666. if sysUser.Authority == 4 {
  667. //pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  668. //if err != nil {
  669. // br.Msg = "获取失败"
  670. // br.ErrMsg = "查询父级id异常" + err.Error()
  671. // return
  672. //}
  673. //ids,err := company.GetGroupIdsByParentId(*pid)
  674. //if err != nil {
  675. // br.Msg = "获取失败"
  676. // br.ErrMsg = "查询父级id异常" + err.Error()
  677. // return
  678. //}
  679. //var idSlice []string
  680. //var sid string
  681. //for _, id := range ids {
  682. // idSlice = append(idSlice, *id)
  683. //}
  684. //sid = strings.Join(idSlice,",")
  685. if status != utils.COMPANY_STATUS_LOSE {
  686. condition += ` AND (b.group_id =? OR status='流失') `
  687. pars = append(pars, sysUser.GroupId)
  688. }
  689. permissionCondition += ` AND b.group_id=? `
  690. permissionPars = append(permissionPars, sysUser.GroupId)
  691. }
  692. }
  693. } else {
  694. //如果没有筛选了流失客户状态,那么需要加客户归属条件加入到查询中去
  695. if sysUser.Authority <= 0 {
  696. if status != utils.COMPANY_STATUS_LOSE {
  697. condition += ` AND b.seller_id=? `
  698. pars = append(pars, sysUser.AdminId)
  699. }
  700. permissionCondition += ` AND b.seller_id=? `
  701. permissionPars = append(permissionPars, sysUser.AdminId)
  702. } else {
  703. if sysUser.Authority == 1 {
  704. if status != utils.COMPANY_STATUS_LOSE {
  705. condition += ` AND b.department_id=?`
  706. pars = append(pars, sysUser.DepartmentId)
  707. }
  708. permissionCondition += ` AND b.department_id=? `
  709. permissionPars = append(permissionPars, sysUser.DepartmentId)
  710. }
  711. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  712. if status != utils.COMPANY_STATUS_LOSE {
  713. condition += ` AND b.group_id=? `
  714. pars = append(pars, sysUser.GroupId)
  715. }
  716. permissionCondition += ` AND b.group_id=? `
  717. permissionPars = append(permissionPars, sysUser.GroupId)
  718. }
  719. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  720. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  721. if err != nil {
  722. br.Msg = "获取失败"
  723. br.ErrMsg = "查询父级id异常" + err.Error()
  724. return
  725. }
  726. var ids []*string
  727. if pid != nil {
  728. if *pid != 0 {
  729. //销售主管放在三级列表中
  730. ids, err = company.GetGroupIdsByParentId(*pid)
  731. if err != nil {
  732. fmt.Println(err.Error())
  733. }
  734. } else {
  735. //销售主管放在二级列表中
  736. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  737. if err != nil {
  738. fmt.Println(err.Error())
  739. }
  740. }
  741. }
  742. var idSlice []string
  743. var sid string
  744. for _, id := range ids {
  745. idSlice = append(idSlice, *id)
  746. }
  747. //加入父级groupId
  748. if *pid > 0 {
  749. idSlice = append(idSlice, strconv.Itoa(*pid))
  750. } else {
  751. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  752. }
  753. sid = strings.Join(idSlice, ",")
  754. if len(sid) > 0 {
  755. if status != utils.COMPANY_STATUS_LOSE {
  756. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  757. //pars = append(pars, sysUser.GroupId)
  758. }
  759. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  760. } else {
  761. if status != utils.COMPANY_STATUS_LOSE {
  762. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  763. //pars = append(pars, sysUser.GroupId)
  764. }
  765. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  766. }
  767. }
  768. if sysUser.Authority == 4 {
  769. if status != utils.COMPANY_STATUS_LOSE {
  770. condition += ` AND b.group_id =? `
  771. pars = append(pars, sysUser.GroupId)
  772. }
  773. permissionCondition += ` AND b.group_id=? `
  774. permissionPars = append(permissionPars, sysUser.GroupId)
  775. }
  776. }
  777. }
  778. }
  779. }
  780. }
  781. //状态控制
  782. if status != "" && status != "全部" {
  783. //switch status {
  784. //case "试用-活跃":
  785. // condition += ` AND b.status="试用" and b.view_total>= ? `
  786. // pars = append(pars, statistic_report.ActiveViewNum)
  787. //case "试用-非活跃":
  788. // condition += ` AND b.status="试用" and b.view_total < ? `
  789. // pars = append(pars, statistic_report.ActiveViewNum)
  790. //default:
  791. // condition += ` AND b.status=? `
  792. // pars = append(pars, status)
  793. //}
  794. condition += ` AND b.status=? `
  795. pars = append(pars, status)
  796. // 试用客户标签
  797. if status == "试用" && tryStage > 0 {
  798. condition += ` AND b.try_stage=? `
  799. pars = append(pars, tryStage)
  800. }
  801. }
  802. total, err := company.GetCompanyListCount(condition, pars)
  803. if err != nil {
  804. br.Msg = "获取失败"
  805. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  806. return
  807. }
  808. //
  809. sortStr := ``
  810. if !sortByTodo {
  811. if sortParam != "" && sortType != "" {
  812. if sortParam == "expireDay" {
  813. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  814. if sortType == "asc" {
  815. sortStr = " ORDER BY min_end_date"
  816. } else {
  817. sortStr = " ORDER BY max_end_date"
  818. }
  819. } else {
  820. sortStr = " ORDER BY b.end_date "
  821. }
  822. } else if sortParam == "createTime" {
  823. sortStr = " ORDER BY a.created_time "
  824. } else if sortParam == "viewTotal" {
  825. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  826. sortStr = " ORDER BY all_view_total"
  827. } else {
  828. sortStr = " ORDER BY b.view_total "
  829. }
  830. } else if sortParam == "viewTime" {
  831. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  832. if sortType == "asc" {
  833. sortStr = " ORDER BY min_last_view_time"
  834. } else {
  835. sortStr = " ORDER BY max_last_view_time"
  836. }
  837. } else {
  838. sortStr = " ORDER BY b.last_view_time "
  839. }
  840. } else if sortParam == "roadShowTotal" {
  841. sortStr = " ORDER BY b.road_show_total "
  842. } else if sortParam == "formalTime" {
  843. sortStr = " ORDER BY b.formal_time "
  844. } else if sortParam == "freezeTime" {
  845. sortStr = " ORDER BY b.freeze_time "
  846. } else if sortParam == "lossTime" {
  847. sortStr = " ORDER BY b.loss_time "
  848. } else if sortParam == "todoCreateTime" {
  849. sortStr = " ORDER BY b.todo_create_time "
  850. } else if sortParam == "todoApproveTime" {
  851. sortStr = " ORDER BY b.todo_approve_time "
  852. } else if sortParam == "tryStage" && status == "试用" {
  853. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  854. sortStr = " ORDER BY sort_try_stage asc, all_view_total desc, a.created_time desc"
  855. } else {
  856. sortStr = " ORDER BY sort_try_stage asc, b.view_total desc, a.created_time desc"
  857. }
  858. } else if sortParam == "deadline" {
  859. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  860. sortStr = " ORDER BY sort_todo_end_time asc, all_view_total desc, a.created_time desc"
  861. } else {
  862. sortStr = " ORDER BY sort_todo_end_time asc, b.view_total desc, a.created_time desc"
  863. }
  864. } else if sortParam == "tryOutDay" {
  865. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  866. sortStr = " ORDER BY all_try_out_day_total "
  867. } else {
  868. sortStr = " ORDER BY b.try_out_day_total "
  869. }
  870. } else {
  871. br.Msg = "获取失败"
  872. br.ErrMsg = "排序字段传入数据异常:" + sortParam
  873. return
  874. }
  875. if sortParam != "tryStage" && sortParam != "deadline" {
  876. if sortType == "asc" {
  877. sortStr += " ASC "
  878. } else if sortType == "desc" {
  879. sortStr += " DESC "
  880. } else {
  881. br.Msg = "获取失败"
  882. br.ErrMsg = "排序类型传入数据异常:" + sortType
  883. return
  884. }
  885. }
  886. } else {
  887. //2、客户列表选择“全部”时,支持按照“状态和阅读数”对“全部”分类下所有客户列表进行升降序排列;选择“正式”时按照“转正时间”、选择“冻结”时按照“冻结时间”、选择“流失”时按照“流失时间”、选择“永续”时按照“创建时间”;
  888. if status == "全部" {
  889. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  890. sortStr = " ORDER BY sort_status asc, all_view_total desc, a.created_time "
  891. } else {
  892. sortStr = " ORDER BY sort_status asc, b.view_total desc, a.created_time "
  893. }
  894. } else if status == "永续" {
  895. sortStr = " ORDER BY a.created_time "
  896. } else if status == "正式" {
  897. // 正式客户默认按照周阅读活跃ASC, 同为不活跃则按照转正时间DESC
  898. sortStr = " ORDER BY week_view_active ASC, b.formal_time "
  899. //sortStr = " ORDER BY b.formal_time "
  900. } else if status == "冻结" {
  901. sortStr = " ORDER BY b.freeze_time "
  902. } else if status == "流失" {
  903. sortStr = " ORDER BY b.loss_time "
  904. } else if status == "试用" {
  905. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  906. sortStr = " ORDER BY all_view_total desc, a.created_time "
  907. } else {
  908. sortStr = " ORDER BY b.view_total desc, a.created_time "
  909. }
  910. } else if status == utils.COMPANY_STATUS_CLOSE {
  911. // 关闭客户按照关闭时间DESC
  912. sortStr = " ORDER BY b.close_time "
  913. }
  914. sortStr += " DESC "
  915. }
  916. } else {
  917. sortStr = " ORDER BY FIELD (todo_status,'未完成','已完成','无任务'), todo_modify_time DESC "
  918. }
  919. //任务状态
  920. if todoStatus != "" {
  921. //排序,筛选出的未完成、已完成客户列表排序分别按照 最近一个任务的创建时间、最近一个任务的审核时间排序;
  922. switch todoStatus {
  923. case "未完成":
  924. if sortStr != "" {
  925. sortStr += " ,b.todo_create_time desc "
  926. } else {
  927. sortStr = " ORDER BY b.todo_create_time desc "
  928. }
  929. case "已完成":
  930. if sortStr != "" {
  931. sortStr += " ,b.todo_approve_time desc "
  932. } else {
  933. sortStr = " ORDER BY b.todo_approve_time desc "
  934. }
  935. }
  936. }
  937. list, err := company.GetCompanyList(condition, status, sortStr, pars, startSize, pageSize)
  938. if err != nil {
  939. br.Msg = "获取失败"
  940. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  941. return
  942. }
  943. //企业用户数组切片
  944. companyIdSlice := make([]string, 0)
  945. companyIds := make([]int, 0)
  946. for _, v := range list {
  947. companyIdSlice = append(companyIdSlice, strconv.Itoa(v.CompanyId))
  948. companyIds = append(companyIds, v.CompanyId)
  949. }
  950. //企业用户产品开通数
  951. companyIdStr := strings.Join(companyIdSlice, ",")
  952. companyProductTotalList, _ := company.GetCountProductByCompanyIds(companyIdStr)
  953. companyProductTotalMap := make(map[int]*company.CompanyProductTotalSlice)
  954. for _, companyProductTotal := range companyProductTotalList {
  955. companyProductTotalMap[companyProductTotal.CompanyId] = companyProductTotal
  956. }
  957. lenList := len(list)
  958. //companyFiccViewTimeMap := make(map[int]time.Time)
  959. //companyRaiViewTimeMap := make(map[int]time.Time)
  960. //companyFiccViewTotal := make(map[int]int)
  961. //companyRaiViewTotal := make(map[int]int)
  962. //获取最近阅读时间 和 累计阅读次数
  963. //if lenList > 0 {
  964. // //ficc 或者 全品种
  965. // if productId == 1 || productId == 0 {
  966. // companyFiccViewTimeMap, err = services.GetFiccLastUserViewHistoryByCompanyIds(companyIdStr)
  967. // if err != nil {
  968. // br.Msg = "获取失败"
  969. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  970. // return
  971. // }
  972. // }
  973. //
  974. // if productId == 2 || productId == 0 {
  975. // companyRaiViewTimeMap, err = services.GetRaiLastUserViewHistoryByCompanyIds(companyIdStr)
  976. // if err != nil {
  977. // br.Msg = "获取失败"
  978. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  979. // return
  980. // }
  981. // }
  982. //
  983. // companyFiccViewTotal, err = services.GetFiccCountUserViewHistoryByCompanyIds(companyIdStr)
  984. // if err != nil {
  985. // br.Msg = "获取失败"
  986. // br.ErrMsg = "获取ficc阅读数据失败,Err:" + err.Error()
  987. // return
  988. // }
  989. // companyRaiViewTotal, err = services.GetRaiCountUserViewHistoryByCompanyIds(companyIdStr)
  990. // if err != nil {
  991. // br.Msg = "获取失败"
  992. // br.ErrMsg = "获取权益阅读数据失败,Err:" + err.Error()
  993. // return
  994. // }
  995. //}
  996. // 客户产品详细信息
  997. companyProductMap := make(map[string]*company.CompanyProduct)
  998. var companyProductCondition string
  999. var companyProductPars []interface{}
  1000. switch companyType {
  1001. case "ficc":
  1002. companyProductCondition += ` AND product_id=? `
  1003. companyProductPars = append(companyProductPars, 1)
  1004. case "权益":
  1005. companyProductCondition += ` AND product_id=? `
  1006. companyProductPars = append(companyProductPars, 2)
  1007. default:
  1008. }
  1009. companyProductList, err := company.GetCompanyProductsByCompanyIds(companyIdStr, companyProductCondition, companyProductPars)
  1010. if err != nil {
  1011. br.Msg = "获取失败"
  1012. br.ErrMsg = "获取客户产品数据失败,Err:" + err.Error()
  1013. return
  1014. }
  1015. for _, companyProduct := range companyProductList {
  1016. key := fmt.Sprint(companyProduct.CompanyId, "_", companyProduct.ProductId)
  1017. companyProductMap[key] = companyProduct
  1018. }
  1019. //任务待办
  1020. companyTodoMap := make(map[string]*company_todo.CompanyTodo)
  1021. {
  1022. var companyTodoCondition string
  1023. var companyTodoPars []interface{}
  1024. switch companyType {
  1025. case "ficc":
  1026. companyTodoCondition += ` AND product_id=? `
  1027. companyTodoPars = append(companyTodoPars, 1)
  1028. case "权益":
  1029. companyTodoCondition += ` AND product_id=? `
  1030. companyTodoPars = append(companyTodoPars, 2)
  1031. default:
  1032. }
  1033. companyTodoList, err := company_todo.GetDoingCompanyTodoByCompanyIds(companyIdStr, companyTodoCondition, companyTodoPars)
  1034. if err != nil {
  1035. br.Msg = "获取失败"
  1036. br.ErrMsg = "获取客户产品数据失败,Err:" + err.Error()
  1037. return
  1038. }
  1039. for _, companyTodo := range companyTodoList {
  1040. key := fmt.Sprint(companyTodo.CompanyId)
  1041. companyTodoMap[key] = companyTodo
  1042. }
  1043. }
  1044. // 查询是否有服务记录
  1045. btnServiceRecordMap := make(map[int]bool)
  1046. if len(companyIds) > 0 {
  1047. serRecOB := new(company.CompanyServiceRecord)
  1048. serRecCond := ` AND company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `)`
  1049. serRecPars := make([]interface{}, 0)
  1050. serRecPars = append(serRecPars, companyIds)
  1051. serRecs, e := serRecOB.GetItemsByCondition(serRecCond, serRecPars, []string{"company_service_record_id", "company_id"}, "")
  1052. if e != nil {
  1053. br.Msg = "获取失败"
  1054. br.ErrMsg = "获取客户服务记录失败, Err: " + e.Error()
  1055. return
  1056. }
  1057. for _, s := range serRecs {
  1058. btnServiceRecordMap[s.CompanyId] = true
  1059. }
  1060. }
  1061. // 查询当前销售是否有领取客户的权限
  1062. receiveEnabled, _ := services.CheckCompanyReceiveButton(sysUser.AdminId)
  1063. for i := 0; i < lenList; i++ {
  1064. item := list[i]
  1065. //校验该客户是否存在多个产品,如果是,那么代表是共享客户
  1066. if companyProductTotal, ok := companyProductTotalMap[int(item.CompanyId)]; ok {
  1067. if companyProductTotal.Total > 1 {
  1068. list[i].IsShared = true
  1069. }
  1070. }
  1071. var expireDay string
  1072. itemStatus := item.Status
  1073. if itemStatus != "" {
  1074. if !strings.Contains(item.Status, "/") {
  1075. if itemStatus == utils.COMPANY_STATUS_FOREVER { //永续
  1076. expireDay = "-"
  1077. } else if itemStatus == utils.COMPANY_STATUS_TRY_OUT || itemStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  1078. if item.StartDate != "" && item.EndDate != "" {
  1079. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  1080. endDateTime = endDateTime.AddDate(0, 0, 1)
  1081. sub := endDateTime.Sub(time.Now())
  1082. if sub < 0 {
  1083. sub = 0
  1084. }
  1085. expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  1086. } else {
  1087. expireDay = "-"
  1088. }
  1089. } else if itemStatus == utils.COMPANY_STATUS_LOSE {
  1090. expireDay = "-"
  1091. } else if itemStatus == utils.COMPANY_STATUS_FREEZE {
  1092. if item.StartDate != "" && item.EndDate != "" {
  1093. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  1094. endDateTime = endDateTime.AddDate(0, 0, 0)
  1095. sub := endDateTime.Sub(time.Now())
  1096. if sub < 0 {
  1097. sub = 0
  1098. }
  1099. expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  1100. } else {
  1101. expireDay = "-"
  1102. }
  1103. } else {
  1104. expireDay = "-"
  1105. }
  1106. } else {
  1107. tmpStatusArr := strings.Split(item.Status, "/")
  1108. ficcStatus := tmpStatusArr[0]
  1109. raiStatus := tmpStatusArr[1]
  1110. var ficcEndDate, tryEndDate string
  1111. var ficcExpireDay, tryExpireDay string
  1112. if item.EndDate != "" {
  1113. endDateArr := strings.Split(item.EndDate, "/")
  1114. if len(endDateArr) == 1 {
  1115. ficcEndDate = endDateArr[0]
  1116. } else if len(endDateArr) > 1 {
  1117. ficcEndDate = endDateArr[0]
  1118. tryEndDate = endDateArr[1]
  1119. }
  1120. if ficcStatus == utils.COMPANY_STATUS_FOREVER { //永续
  1121. ficcExpireDay = "-"
  1122. } else if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  1123. if ficcEndDate != "" {
  1124. endDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
  1125. endDateTime = endDateTime.AddDate(0, 0, 1)
  1126. sub := endDateTime.Sub(time.Now())
  1127. if sub < 0 {
  1128. sub = 0
  1129. }
  1130. ficcExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  1131. } else {
  1132. ficcExpireDay = "-"
  1133. }
  1134. } else if ficcStatus == utils.COMPANY_STATUS_LOSE { //流失
  1135. ficcExpireDay = "-"
  1136. } else if ficcStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  1137. if item.StartDate != "" && item.EndDate != "" {
  1138. endDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
  1139. endDateTime = endDateTime.AddDate(0, 0, 0)
  1140. sub := endDateTime.Sub(time.Now())
  1141. if sub < 0 {
  1142. sub = 0
  1143. }
  1144. ficcExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  1145. } else {
  1146. ficcExpireDay = "-"
  1147. }
  1148. } else {
  1149. ficcExpireDay = "-"
  1150. }
  1151. if raiStatus == utils.COMPANY_STATUS_FOREVER { //永续
  1152. tryExpireDay = "-"
  1153. } else if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  1154. if tryEndDate != "" {
  1155. endDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
  1156. endDateTime = endDateTime.AddDate(0, 0, 1)
  1157. sub := endDateTime.Sub(time.Now())
  1158. if sub < 0 {
  1159. sub = 0
  1160. }
  1161. tryExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  1162. } else {
  1163. tryExpireDay = "-"
  1164. }
  1165. } else if raiStatus == utils.COMPANY_STATUS_LOSE { //流失
  1166. tryExpireDay = "-"
  1167. } else if raiStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  1168. if item.StartDate != "" && item.EndDate != "" {
  1169. endDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
  1170. endDateTime = endDateTime.AddDate(0, 0, 0)
  1171. sub := endDateTime.Sub(time.Now())
  1172. if sub < 0 {
  1173. sub = 0
  1174. }
  1175. tryExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  1176. } else {
  1177. tryExpireDay = "-"
  1178. }
  1179. } else {
  1180. tryExpireDay = "-"
  1181. }
  1182. }
  1183. expireDay = ficcExpireDay + "/" + tryExpireDay
  1184. }
  1185. }
  1186. list[i].ExpireDay = expireDay
  1187. //按钮显示控制
  1188. btnItem := new(company.ButtonPermission)
  1189. if item.CompanyId != 1 {
  1190. *btnItem = services.GetCompanyPermissionButton(roleTypeCode, itemStatus, item.GroupIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, item.ShareSellerId)
  1191. //根据销售"领取客户"的权限对部分按钮做限制
  1192. btnItem = services.GetCompanyPermissionButtonByReceiveEnabled(btnItem, receiveEnabled)
  1193. }
  1194. if list[i].IsShare == 1 && btnItem.BtnModifySeller == true {
  1195. //如果已经是共享客户了,取消共享按钮全都显示,和修改销售权限一样
  1196. btnItem.BtnShare = true
  1197. }
  1198. list[i].BtnItem = btnItem
  1199. if item.FreezeStartDate != "" && item.FreezeEndDate != "" && item.Status == utils.COMPANY_STATUS_FREEZE {
  1200. freezeEndDate, _ := time.Parse(utils.FormatDate, item.FreezeEndDate)
  1201. if time.Now().Before(freezeEndDate) {
  1202. expireDays := freezeEndDate.Sub(time.Now()).Hours() / 24
  1203. list[i].FreezeExpireDays = int(expireDays) + 1
  1204. }
  1205. }
  1206. btnItem.BtnServiceRecord = btnServiceRecordMap[list[i].CompanyId]
  1207. //productIdArr := strings.Split(item.ProductIds, "/")
  1208. //// 套餐类型
  1209. //packageTypeArr := strings.Split(item.PackageTypes, "/")
  1210. //viewTotalArr := strings.Split(item.ViewTotals, "/") //总阅读次数
  1211. //lastViewTimeArr := strings.Split(item.LastViewTimes, "/") //最近阅读时间
  1212. //if len(productIdArr) > 1 {
  1213. // if len(packageTypeArr) == 1 {
  1214. // item.PackageTypes = item.PackageTypes + "/" + item.PackageTypes
  1215. // packageTypeArr = strings.Split(item.PackageTypes, "/")
  1216. // }
  1217. // //阅读次数
  1218. // if len(viewTotalArr) == 1 {
  1219. // item.ViewTotals = item.ViewTotals + "/" + item.ViewTotals
  1220. // viewTotalArr = strings.Split(item.ViewTotals, "/") //总阅读次数
  1221. // }
  1222. //
  1223. // if len(lastViewTimeArr) == 1 {
  1224. // item.LastViewTimes = item.LastViewTimes + "/" + item.LastViewTimes
  1225. // lastViewTimeArr = strings.Split(item.LastViewTimes, "/") //最近阅读时间
  1226. // }
  1227. //}
  1228. //for i, tmpProductId := range productIdArr {
  1229. // packageTypeInt, _ := strconv.Atoi(packageTypeArr[i])
  1230. // viewTotalInt, _ := strconv.Atoi(viewTotalArr[i])
  1231. // lastViewTime := lastViewTimeArr[i]
  1232. // //ficc
  1233. // if tmpProductId == "1" {
  1234. // //套餐类型
  1235. // item.FiccPackageType = packageTypeInt
  1236. //
  1237. // //总阅读次数
  1238. // item.FiccView = viewTotalInt
  1239. //
  1240. // //最近一次阅读时间
  1241. // item.FiccLastViewTime = lastViewTime
  1242. // }
  1243. // //权益
  1244. // if tmpProductId == "2" {
  1245. // //总阅读次数
  1246. // item.RaiView = viewTotalInt
  1247. //
  1248. // //最近一次阅读时间
  1249. // item.RaiLastViewTime = lastViewTime
  1250. // }
  1251. //}
  1252. ficcKey := fmt.Sprint(item.CompanyId, "_", 1)
  1253. //ficc
  1254. if tmpCompanyProduct, ok := companyProductMap[ficcKey]; ok {
  1255. //套餐类型
  1256. item.FiccPackageType = tmpCompanyProduct.PackageType
  1257. //总试用天数
  1258. item.FiccTryOutDay = tmpCompanyProduct.TryOutDayTotal
  1259. //总阅读次数
  1260. item.FiccView = tmpCompanyProduct.ViewTotal
  1261. if !tmpCompanyProduct.LastViewTime.IsZero() {
  1262. //最近一次阅读时间
  1263. item.FiccLastViewTime = tmpCompanyProduct.LastViewTime.Format(utils.FormatDateTime)
  1264. }
  1265. }
  1266. //权益
  1267. raiKey := fmt.Sprint(item.CompanyId, "_", 2)
  1268. if tmpCompanyProduct, ok := companyProductMap[raiKey]; ok {
  1269. //总阅读次数
  1270. item.RaiView = tmpCompanyProduct.ViewTotal
  1271. //总试用天数
  1272. item.RaiTryOutDay = tmpCompanyProduct.TryOutDayTotal
  1273. if !tmpCompanyProduct.LastViewTime.IsZero() {
  1274. //最近一次阅读时间
  1275. item.RaiLastViewTime = tmpCompanyProduct.LastViewTime.Format(utils.FormatDateTime)
  1276. }
  1277. }
  1278. //最近阅读时间
  1279. //if viewTime, ok := companyFiccViewTimeMap[item.CompanyId]; ok {
  1280. // item.FiccLastViewTime = viewTime.Format(utils.FormatDateTime)
  1281. //}
  1282. //
  1283. //if viewTime, ok := companyRaiViewTimeMap[item.CompanyId]; ok {
  1284. // item.RaiLastViewTime = viewTime.Format(utils.FormatDateTime)
  1285. //}
  1286. // 试用客户子标签
  1287. if strings.Contains(item.Status, "试用") {
  1288. statusSlice := strings.Split(item.Status, "/")
  1289. stageItemSlice := strings.Split(item.TryStageStr, "/")
  1290. productIdSlice := strings.Split(item.ProductIds, "/")
  1291. for sk, sv := range statusSlice {
  1292. if sv != "试用" {
  1293. continue
  1294. }
  1295. tryItem := new(company.TryStageSliceItem)
  1296. if len(productIdSlice) < (sk+1) || len(stageItemSlice) < (sk+1) {
  1297. continue
  1298. }
  1299. key := fmt.Sprint(item.CompanyId, "_", productIdSlice[sk])
  1300. if pro, ok := companyProductMap[key]; ok {
  1301. tryItem.ProductId, _ = strconv.Atoi(productIdSlice[sk])
  1302. if pro.SellerId == sysUser.AdminId { //产品销售ID和登录ID相等
  1303. tryItem.HasPermission = true
  1304. }
  1305. tryItem.TryStage, _ = strconv.Atoi(stageItemSlice[sk])
  1306. list[i].TryStageSlice = append(list[i].TryStageSlice, tryItem)
  1307. }
  1308. }
  1309. }
  1310. // To-Do任务状态为未完成的对应任务的截止日期-当前日期;
  1311. if strings.Contains(item.TodoStatuss, "未完成") {
  1312. if strings.Contains(item.TodoEndTimeStr, "/") {
  1313. edtSlice := strings.Split(item.TodoEndTimeStr, "/")
  1314. item.TodoEndTime, _ = time.ParseInLocation(utils.FormatDateTime, edtSlice[0], time.Local)
  1315. } else {
  1316. item.TodoEndTime, _ = time.ParseInLocation(utils.FormatDateTime, item.TodoEndTimeStr, time.Local)
  1317. }
  1318. tmpEndTime := item.TodoEndTime.Format(utils.FormatDate)
  1319. if tmpEndTime == "0001-01-01" {
  1320. tmpEndTime = ""
  1321. }
  1322. if tmpEndTime != "" {
  1323. dlTime1 := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 0, 0, 0, 0, time.Local)
  1324. dlTime2 := time.Date(item.TodoEndTime.Year(), item.TodoEndTime.Month(), item.TodoEndTime.Day(), 0, 0, 0, 0, time.Local)
  1325. dldays := int(dlTime2.Sub(dlTime1).Hours() / 24)
  1326. list[i].Deadline = strconv.Itoa(dldays)
  1327. }
  1328. }
  1329. }
  1330. statusCount, err := company.GetCompanyStatusCount(permissionCondition, permissionPars)
  1331. if err != nil {
  1332. br.Msg = "获取失败"
  1333. br.ErrMsg = "获取状态数量失败,Err:" + err.Error()
  1334. return
  1335. }
  1336. statusMap := make(map[string]int, 0)
  1337. var totalCount int
  1338. for _, sv := range statusCount {
  1339. totalCount = totalCount + sv.Count
  1340. statusMap[sv.Status] = sv.Count
  1341. }
  1342. // 统计试用客户的子标签数量,只在试用状态页面统计
  1343. var tryStageCountResp []*company.CompanyTryStageCount
  1344. if status == "试用" {
  1345. tryStageCount, err := company.GetCompanyTryStageCount(permissionCondition, permissionPars)
  1346. if err != nil {
  1347. br.Msg = "获取失败"
  1348. br.ErrMsg = "获取试用状态标签数量失败,Err:" + err.Error()
  1349. return
  1350. }
  1351. tryStageMap := make(map[int]int)
  1352. for _, v := range tryStageCount {
  1353. tryStageMap[0] += v.Count
  1354. tryStageMap[v.TryStage] = v.Count
  1355. }
  1356. tryStageAllMap := map[int]string{
  1357. 0: "全部",
  1358. 2: "推进",
  1359. 3: "跟踪",
  1360. 4: "预备",
  1361. 1: "未分类",
  1362. }
  1363. for k, v := range tryStageAllMap {
  1364. item := new(company.CompanyTryStageCount)
  1365. item.TryStageStr = v
  1366. item.TryStage = k
  1367. if count, ok := tryStageMap[k]; ok {
  1368. item.Count = count
  1369. }
  1370. tryStageCountResp = append(tryStageCountResp, item)
  1371. }
  1372. }
  1373. //
  1374. ////试用-活跃
  1375. //{
  1376. // tmpPermissionCondition := permissionCondition
  1377. // tmpPermissionPars := permissionPars
  1378. // tmpPermissionCondition += ` and b.view_total>=? `
  1379. // tmpPermissionPars = append(tmpPermissionPars, statistic_report.ActiveViewNum)
  1380. //
  1381. // tryOutActiveCount, err := company.GetCompanyTryOutStatusCount(tmpPermissionCondition, tmpPermissionPars)
  1382. // if err != nil {
  1383. // br.Msg = "获取失败"
  1384. // br.ErrMsg = "获取状态数量失败,Err:" + err.Error()
  1385. // return
  1386. // }
  1387. // statusMap["试用-活跃"] = tryOutActiveCount.Count
  1388. //}
  1389. //
  1390. ////试用-非活跃
  1391. //{
  1392. // tmpPermissionCondition := permissionCondition
  1393. // tmpPermissionPars := permissionPars
  1394. // tmpPermissionCondition += ` and b.view_total <? `
  1395. // tmpPermissionPars = append(tmpPermissionPars, statistic_report.ActiveViewNum)
  1396. //
  1397. // tryOutActiveCount, err := company.GetCompanyTryOutStatusCount(tmpPermissionCondition, tmpPermissionPars)
  1398. // if err != nil {
  1399. // br.Msg = "获取失败"
  1400. // br.ErrMsg = "获取状态数量失败,Err:" + err.Error()
  1401. // return
  1402. // }
  1403. // statusMap["试用-非活跃"] = tryOutActiveCount.Count
  1404. //}
  1405. lossItem, err := company.GetCompanyStatusLoseCount(lossCondition, lossPars)
  1406. if err != nil {
  1407. br.Msg = "获取失败"
  1408. br.ErrMsg = "获取流失状态数量失败,Err:" + err.Error()
  1409. return
  1410. }
  1411. totalCount = totalCount + lossItem.Count
  1412. for _, v := range statusArr {
  1413. s := new(company.CompanyStatus)
  1414. if v == "全部" {
  1415. s.Status = "全部"
  1416. s.Count = totalCount
  1417. } else if v == utils.COMPANY_STATUS_LOSE {
  1418. s.Status = v
  1419. s.Count = lossItem.Count
  1420. } else {
  1421. s.Status = v
  1422. if val, ok := statusMap[v]; ok {
  1423. s.Count = val
  1424. }
  1425. }
  1426. statusItems = append(statusItems, s)
  1427. }
  1428. companyLists := make([]*company.CompanyListItem, 0)
  1429. //查询阅读次数
  1430. if list == nil {
  1431. companyLists = make([]*company.CompanyListItem, 0)
  1432. } else {
  1433. for _, v := range list {
  1434. //viewTotal:=GetviewTotal(v.CompanyId)
  1435. //活跃(客户状态)
  1436. tmpStatus := v.Status
  1437. if v.IsShare == 1 {
  1438. tmpStatus = v.Status + "(共享)"
  1439. }
  1440. //productIdSlice := strings.Split(v.ProductIds, "/")
  1441. //statusSlice := strings.Split(v.Status, "/")
  1442. //for productIndex, tmpProductId := range productIdSlice {
  1443. // tmpStatusIndex := 0
  1444. // if len(statusSlice) > 1 {
  1445. // tmpStatusIndex = productIndex
  1446. // }
  1447. // tmpProductStatus := statusSlice[tmpStatusIndex]
  1448. // if strings.Contains(tmpProductStatus, "试用") {
  1449. // activeType := "非活跃"
  1450. // viewNum := v.FiccView
  1451. // if tmpProductId == "2" {
  1452. // viewNum = v.RaiView
  1453. // }
  1454. // if viewNum >= statistic_report.ActiveViewNum {
  1455. // activeType = "活跃"
  1456. // }
  1457. // statusSlice[tmpStatusIndex] = fmt.Sprint(tmpProductStatus, "(", activeType, ")")
  1458. //
  1459. // tmpStatus = strings.Join(statusSlice, "/")
  1460. // }
  1461. //}
  1462. //ficcViewTotal, ok := companyFiccViewTotal[v.CompanyId]
  1463. //if !ok {
  1464. // ficcViewTotal = 0
  1465. //}
  1466. //raiViewTotal, ok := companyRaiViewTotal[v.CompanyId]
  1467. //if !ok {
  1468. // raiViewTotal = 0
  1469. //}
  1470. // 是否存在进行中的任务
  1471. var todoStatus bool
  1472. if _, ok := companyTodoMap[fmt.Sprint(v.CompanyId)]; ok {
  1473. todoStatus = true
  1474. }
  1475. //是否支持确认完成待办任务
  1476. var canConfirm bool
  1477. var hiddenConfirm bool //是否隐藏确定完成按钮
  1478. var hiddenCreate bool //是否隐藏新增/编辑按钮
  1479. hiddenConfirm = true
  1480. hiddenCreate = true
  1481. for _, vProductId := range []int{1, 2} {
  1482. ficcKey := fmt.Sprint(v.CompanyId, "_", vProductId)
  1483. //ficc
  1484. if tmpCompanyProduct, ok := companyProductMap[ficcKey]; ok {
  1485. if tmpCompanyProduct.Status != utils.COMPANY_STATUS_LOSE && tmpCompanyProduct.Status != utils.COMPANY_STATUS_CLOSE { //非流失或关闭
  1486. hiddenCreate = false
  1487. switch this.SysUser.RoleTypeCode {
  1488. 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:
  1489. //部门管理员、ficc主管、权益组长
  1490. hiddenConfirm = false //不展示
  1491. if todoStatus { //有任务,需要展示
  1492. canConfirm = true
  1493. }
  1494. case utils.ROLE_TYPE_CODE_FICC_TEAM: //ficc组长
  1495. if todoStatus { //有任务,需要展示
  1496. canConfirm = true
  1497. }
  1498. if v.SellerId != this.SysUser.AdminId { //不是自己的客户
  1499. hiddenConfirm = false //展示
  1500. }
  1501. case utils.ROLE_TYPE_CODE_RAI_SELLER: //权益销售
  1502. if v.SellerId == this.SysUser.AdminId { //是自己的客户
  1503. has := services.CheckRaiApprovePermission(sysUser.AdminId) //这些个权益销售是有权限的
  1504. if has {
  1505. if todoStatus { //有任务,需要展示
  1506. canConfirm = true
  1507. }
  1508. hiddenConfirm = false //展示
  1509. }
  1510. }
  1511. }
  1512. }
  1513. }
  1514. }
  1515. todoButtonColor := `green`
  1516. //'无任务','未完成','已完成'
  1517. if strings.Contains(v.TodoStatuss, "未完成") {
  1518. todoButtonColor = "red"
  1519. } else if strings.Contains(v.TodoStatuss, "已完成") {
  1520. todoButtonColor = "green"
  1521. } else if strings.Contains(v.TodoStatuss, "无任务") {
  1522. todoButtonColor = "gray"
  1523. }
  1524. //if str
  1525. companyList := &company.CompanyListItem{
  1526. CompanyId: v.CompanyId,
  1527. CompanyName: v.CompanyName,
  1528. CreditCode: v.CreditCode,
  1529. CompanyCode: v.CompanyCode,
  1530. StartDate: v.StartDate,
  1531. EndDate: v.EndDate,
  1532. LoseReason: v.LoseReason,
  1533. RenewalReason: v.RenewalReason,
  1534. FreezeReason: v.FreezeReason,
  1535. LossTime: v.LossTime,
  1536. Status: tmpStatus,
  1537. CompanyType: v.CompanyType,
  1538. ApproveStatus: v.ApproveStatus,
  1539. SellerName: v.SellerName,
  1540. SellerId: v.SellerId,
  1541. SellerIds: v.SellerIds,
  1542. ExpireDay: v.ExpireDay,
  1543. FreezeTime: v.FreezeTime,
  1544. GroupId: v.GroupId,
  1545. GroupIds: v.GroupIds,
  1546. DepartmentId: v.DepartmentId,
  1547. IndustryName: v.IndustryName,
  1548. IsSuspend: v.IsSuspend,
  1549. CreatedTime: v.CreatedTime,
  1550. Source: v.Source,
  1551. Province: v.Province,
  1552. City: v.City,
  1553. Address: v.Address,
  1554. Reasons: v.Reasons,
  1555. FreezeStartDate: v.FreezeStartDate,
  1556. FreezeEndDate: v.FreezeEndDate,
  1557. FreezeExpireDays: v.FreezeExpireDays,
  1558. BtnItem: v.BtnItem,
  1559. ProductId: v.ProductId,
  1560. FormalTime: v.FormalTime,
  1561. IsShared: v.IsShared,
  1562. RegionType: v.RegionType,
  1563. FiccPackageType: v.FiccPackageType,
  1564. FiccLastViewTime: v.FiccLastViewTime,
  1565. RaiLastViewTime: v.RaiLastViewTime,
  1566. //FiccView: viewTotal[0],
  1567. //RaiView: viewTotal[1],
  1568. //FiccView: ficcViewTotal,
  1569. //RaiView: raiViewTotal,
  1570. FiccView: v.FiccView,
  1571. RaiView: v.RaiView,
  1572. FiccTryOutDay: v.FiccTryOutDay,
  1573. RaiTryOutDay: v.RaiTryOutDay,
  1574. AllViewTotal: v.AllViewTotal,
  1575. RoadShowTotal: v.RoadShowTotal,
  1576. TodoStatus: todoStatus,
  1577. CanConfirm: canConfirm,
  1578. HiddenConfirm: hiddenConfirm,
  1579. HiddenCreate: hiddenCreate,
  1580. TodoButtonColor: todoButtonColor,
  1581. TryStageSlice: v.TryStageSlice,
  1582. Deadline: v.Deadline,
  1583. WeekViewActive: v.WeekViewActive,
  1584. IsShare: v.IsShare,
  1585. CloseTime: v.CloseTime,
  1586. CloseReason: v.CloseReason,
  1587. }
  1588. companyLists = append(companyLists, companyList)
  1589. }
  1590. }
  1591. if companyLists == nil {
  1592. companyLists = make([]*company.CompanyListItem, 0)
  1593. }
  1594. page = paging.GetPaging(currentIndex, pageSize, total)
  1595. resp.List = companyLists
  1596. resp.StatusCount = statusItems
  1597. resp.TryStageCount = tryStageCountResp
  1598. resp.Paging = page
  1599. resp.AddCompanyBtn = receiveEnabled
  1600. br.Ret = 200
  1601. br.Success = true
  1602. br.Msg = "获取成功"
  1603. br.Data = resp
  1604. }
  1605. //func (this *CompanyController) ListOld() {
  1606. // br := new(models.BaseResponse).Init()
  1607. // defer func() {
  1608. // this.Data["json"] = br
  1609. // this.ServeJSON()
  1610. // }()
  1611. // sysUser := this.SysUser
  1612. // if sysUser == nil {
  1613. // br.Msg = "请登录"
  1614. // br.ErrMsg = "请登录,SysUser Is Empty"
  1615. // br.Ret = 408
  1616. // return
  1617. // }
  1618. // roleTypeCode := sysUser.RoleTypeCode
  1619. //
  1620. // pageSize, _ := this.GetInt("PageSize")
  1621. // currentIndex, _ := this.GetInt("CurrentIndex")
  1622. // status := this.GetString("Status")
  1623. // companyType := this.GetString("CompanyType")
  1624. // industryId, _ := this.GetInt("IndustryId")
  1625. // adminId := this.GetString("AdminId")
  1626. //
  1627. // chartPermissionIds := this.GetString("ChartPermissionIds")
  1628. // startDate := this.GetString("StartDate")
  1629. // endDate := this.GetString("EndDate")
  1630. // createStartDate := this.GetString("CreateStartDate")
  1631. // createEndDate := this.GetString("CreateEndDate")
  1632. // keyWord := this.GetString("KeyWord")
  1633. // keyWord = strings.Trim(keyWord, " ")
  1634. // keyWord = strings.Replace(keyWord, "'", "", -1)
  1635. //
  1636. // //排序参数
  1637. // sortParam := this.GetString("SortParam")
  1638. // sortType := this.GetString("SortType")
  1639. //
  1640. // var total int
  1641. // page := paging.GetPaging(currentIndex, pageSize, total)
  1642. // resp := new(company.CompanyListResp)
  1643. // statusItems := make([]*company.CompanyStatus, 0)
  1644. // var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}
  1645. //
  1646. // var startSize int
  1647. // if pageSize <= 0 {
  1648. // pageSize = utils.PageSize20
  1649. // }
  1650. // if currentIndex <= 0 {
  1651. // currentIndex = 1
  1652. // }
  1653. // startSize = paging.StartIndex(currentIndex, pageSize)
  1654. // var condition string
  1655. // var pars []interface{}
  1656. //
  1657. // //流失
  1658. // var lossCondition string
  1659. // var lossPars []interface{}
  1660. // //冻结
  1661. // var freezeCondition string
  1662. // var freezePars []interface{}
  1663. //
  1664. // //永续
  1665. // var forverCondition string
  1666. // var forverPars []interface{}
  1667. //
  1668. // var permissionCondition string
  1669. // var permissionPars []interface{}
  1670. //
  1671. // if status != "" && status != "全部" {
  1672. // condition += ` AND b.status=? `
  1673. // pars = append(pars, status)
  1674. //
  1675. // //permissionCondition += ` AND b.status=? `
  1676. // //permissionPars = append(permissionPars, status)
  1677. // }
  1678. // if companyType != "" {
  1679. // condition += ` AND b.product_name=? `
  1680. // pars = append(pars, companyType)
  1681. //
  1682. // lossCondition += ` AND b.product_name=? `
  1683. // lossPars = append(lossPars, companyType)
  1684. //
  1685. // freezeCondition += ` AND b.product_name=? `
  1686. // freezePars = append(freezePars, companyType)
  1687. //
  1688. // forverCondition += ` AND b.product_name=? `
  1689. // forverPars = append(forverPars, companyType)
  1690. //
  1691. // permissionCondition += ` AND b.product_name=? `
  1692. // permissionPars = append(permissionPars, companyType)
  1693. // }
  1694. //
  1695. // if industryId > 0 {
  1696. // condition += ` AND b.industry_id=? `
  1697. // pars = append(pars, industryId)
  1698. //
  1699. // lossCondition += ` AND b.industry_id=? `
  1700. // lossPars = append(lossPars, industryId)
  1701. //
  1702. // freezeCondition += ` AND b.industry_id=? `
  1703. // freezePars = append(freezePars, industryId)
  1704. //
  1705. // forverCondition += ` AND b.industry_id=? `
  1706. // forverPars = append(forverPars, industryId)
  1707. //
  1708. // permissionCondition += ` AND b.industry_id=? `
  1709. // permissionPars = append(permissionPars, industryId)
  1710. // }
  1711. //
  1712. // if adminId != "" {
  1713. // condition += ` AND b.seller_id IN (` + adminId + `) `
  1714. //
  1715. // lossCondition += ` AND b.seller_id IN (` + adminId + `) `
  1716. //
  1717. // freezeCondition += ` AND b.seller_id IN (` + adminId + `) `
  1718. //
  1719. // forverCondition += ` AND b.seller_id IN (` + adminId + `) `
  1720. //
  1721. // permissionCondition += ` AND b.seller_id IN (` + adminId + `) `
  1722. // }
  1723. //
  1724. // if startDate != "" {
  1725. // condition += ` AND b.start_date>=? `
  1726. // pars = append(pars, startDate)
  1727. //
  1728. // lossCondition += ` AND b.start_date>=? `
  1729. // lossPars = append(lossPars, startDate)
  1730. //
  1731. // freezeCondition += ` AND b.start_date>=? `
  1732. // freezePars = append(freezePars, startDate)
  1733. //
  1734. // forverCondition += ` AND b.start_date>=? `
  1735. // forverPars = append(forverPars, startDate)
  1736. //
  1737. // permissionCondition += ` AND b.start_date>=? `
  1738. // permissionPars = append(permissionPars, startDate)
  1739. // }
  1740. //
  1741. // if endDate != "" {
  1742. // condition += ` AND b.end_date<=? `
  1743. // pars = append(pars, endDate)
  1744. //
  1745. // lossCondition += ` AND b.end_date<=? `
  1746. // lossPars = append(lossPars, endDate)
  1747. //
  1748. // freezeCondition += ` AND b.end_date<=? `
  1749. // freezePars = append(freezePars, endDate)
  1750. //
  1751. // forverCondition += ` AND b.end_date<=? `
  1752. // forverPars = append(forverPars, endDate)
  1753. //
  1754. // permissionCondition += ` AND b.end_date<=? `
  1755. // permissionPars = append(permissionPars, endDate)
  1756. // }
  1757. //
  1758. // if createStartDate != "" {
  1759. // condition += ` AND a.created_time>=? `
  1760. // pars = append(pars, createStartDate)
  1761. //
  1762. // lossCondition += ` AND a.created_time>=? `
  1763. // lossPars = append(lossPars, createStartDate)
  1764. //
  1765. // freezeCondition += ` AND a.created_time>=? `
  1766. // freezePars = append(freezePars, createStartDate)
  1767. //
  1768. // forverCondition += ` AND a.created_time>=? `
  1769. // forverPars = append(forverPars, createStartDate)
  1770. //
  1771. // permissionCondition += ` AND a.created_time>=? `
  1772. // permissionPars = append(permissionPars, createStartDate)
  1773. // }
  1774. //
  1775. // if createEndDate != "" {
  1776. // condition += ` AND a.created_time<=? `
  1777. // pars = append(pars, createEndDate)
  1778. //
  1779. // lossCondition += ` AND a.created_time<=? `
  1780. // lossPars = append(lossPars, createEndDate)
  1781. //
  1782. // freezeCondition += ` AND a.created_time<=? `
  1783. // freezePars = append(freezePars, createEndDate)
  1784. //
  1785. // forverCondition += ` AND a.created_time<=? `
  1786. // forverPars = append(forverPars, createEndDate)
  1787. //
  1788. // permissionCondition += ` AND a.created_time<=? `
  1789. // permissionPars = append(permissionPars, createEndDate)
  1790. // }
  1791. //
  1792. // if keyWord != "" {
  1793. // companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
  1794. // if err != nil {
  1795. // br.Msg = "获取客户信息失败"
  1796. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1797. // return
  1798. // }
  1799. // if companyIdStr != "" {
  1800. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  1801. // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  1802. // freezeCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  1803. // forverCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  1804. //
  1805. // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  1806. // } else {
  1807. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  1808. // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  1809. // freezeCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  1810. // forverCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  1811. //
  1812. // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  1813. // }
  1814. // }
  1815. // if chartPermissionIds != "" && chartPermissionIds != "1" {
  1816. // //chartPermissionArr := strings.Split(chartPermissionIds, ",")
  1817. // //chartPermissionCount := len(chartPermissionArr)
  1818. // companyIdStr, err := company.GetCompanyListCompanyIdByPermissionIdStr(chartPermissionIds)
  1819. // if err != nil {
  1820. // br.Msg = "获取失败"
  1821. // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
  1822. // return
  1823. // }
  1824. // //var companyIdArr []string
  1825. // //for _, v := range companyIdList {
  1826. // // companyIdArr = append(companyIdArr, strconv.Itoa(v.CompanyId))
  1827. // //}
  1828. // //companyIdStr := strings.Join(companyIdArr, ",")
  1829. // if companyIdStr != "" {
  1830. // condition += ` AND a.company_id IN (` + companyIdStr + `) `
  1831. // lossCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  1832. // freezeCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  1833. // forverCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  1834. // permissionCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  1835. // } else {
  1836. // for _, v := range statusArr {
  1837. // statusCount := new(company.CompanyStatus)
  1838. // if v == "全部" {
  1839. // statusCount.Status = "全部"
  1840. // statusCount.Count = 0
  1841. // } else {
  1842. // statusCount.Status = v
  1843. // statusCount.Count = 0
  1844. // }
  1845. // statusItems = append(statusItems, statusCount)
  1846. // }
  1847. // items := make([]*company.CompanyListItem, 0)
  1848. // resp.List = items
  1849. // resp.Paging = page
  1850. // resp.StatusCount = statusItems
  1851. // br.Msg = "获取成功"
  1852. // br.Ret = 200
  1853. // br.Data = resp
  1854. // return
  1855. // }
  1856. // }
  1857. // //权限控制
  1858. // {
  1859. // fmt.Println(roleTypeCode)
  1860. // if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  1861. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  1862. // condition += ` AND b.product_id=? `
  1863. // pars = append(pars, 1)
  1864. //
  1865. // permissionCondition += ` AND b.product_id=? `
  1866. // permissionPars = append(permissionPars, 1)
  1867. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  1868. // condition += ` AND b.product_id=? `
  1869. // pars = append(pars, 2)
  1870. //
  1871. // permissionCondition += ` AND b.product_id=? `
  1872. // permissionPars = append(permissionPars, 2)
  1873. // } else {
  1874. // if sysUser.Authority <= 0 {
  1875. // if status == utils.COMPANY_STATUS_TRY_OUT || status == utils.COMPANY_STATUS_FORMAL || status == "全部" {
  1876. // if status == "全部" {
  1877. // condition += ` AND (b.seller_id=? OR status='流失' OR status='永续') `
  1878. // pars = append(pars, sysUser.AdminId)
  1879. // } else {
  1880. // condition += ` AND b.seller_id=? `
  1881. // pars = append(pars, sysUser.AdminId)
  1882. // }
  1883. // }
  1884. // permissionCondition += ` AND b.seller_id=? `
  1885. // permissionPars = append(permissionPars, sysUser.AdminId)
  1886. // } else {
  1887. // if sysUser.Authority == 1 {
  1888. // if status == utils.COMPANY_STATUS_TRY_OUT || status == utils.COMPANY_STATUS_FORMAL || status == "全部" {
  1889. // condition += ` AND b.department_id=? `
  1890. // pars = append(pars, sysUser.DepartmentId)
  1891. //
  1892. // permissionCondition += ` AND b.department_id=? `
  1893. // permissionPars = append(permissionPars, sysUser.DepartmentId)
  1894. // } else {
  1895. // permissionCondition += ` AND b.department_id=? `
  1896. // permissionPars = append(permissionPars, sysUser.DepartmentId)
  1897. // }
  1898. // }
  1899. //
  1900. // if sysUser.Authority == 2 {
  1901. // if status == utils.COMPANY_STATUS_TRY_OUT || status == utils.COMPANY_STATUS_FORMAL || status == "全部" {
  1902. // condition += ` AND b.group_id=? `
  1903. // pars = append(pars, sysUser.GroupId)
  1904. //
  1905. // permissionCondition += ` AND b.group_id=? `
  1906. // permissionPars = append(permissionPars, sysUser.GroupId)
  1907. // } else {
  1908. // permissionCondition += ` AND b.group_id=? `
  1909. // permissionPars = append(permissionPars, sysUser.GroupId)
  1910. // }
  1911. // }
  1912. // }
  1913. // }
  1914. // }
  1915. //
  1916. // //if status == utils.COMPANY_STATUS_FREEZE {
  1917. // // condition += ` AND b.seller_id=? `
  1918. // // pars = append(pars, sysUser.AdminId)
  1919. // //
  1920. // // //permissionCondition += ` AND b.seller_id=? `
  1921. // // //permissionPars = append(permissionPars, sysUser.AdminId)
  1922. // //}
  1923. // //if status == "全部" || status == utils.COMPANY_STATUS_FREEZE {
  1924. // // freezeCondition += ` AND b.seller_id=? `
  1925. // // freezePars = append(freezePars, sysUser.AdminId)
  1926. // //}
  1927. // if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  1928. // //freezeCondition += ` AND b.seller_id=? `
  1929. // //freezePars = append(freezePars, sysUser.AdminId)
  1930. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  1931. // permissionCondition += ` AND b.product_id=? `
  1932. // permissionPars = append(permissionPars, 1)
  1933. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  1934. // permissionCondition += ` AND b.product_id=? `
  1935. // permissionPars = append(permissionPars, 2)
  1936. // } else {
  1937. // if status == utils.COMPANY_STATUS_FREEZE {
  1938. // condition += ` AND b.seller_id=? `
  1939. // pars = append(pars, sysUser.AdminId)
  1940. // }
  1941. //
  1942. // freezeCondition += ` AND b.seller_id=? `
  1943. // freezePars = append(freezePars, sysUser.AdminId)
  1944. // }
  1945. // }
  1946. //
  1947. // total, err := company.GetCompanyListCount(condition, pars)
  1948. // if err != nil {
  1949. // br.Msg = "获取失败"
  1950. // br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  1951. // return
  1952. // }
  1953. //
  1954. // sortStr := ``
  1955. // if sortParam != "" && sortType != "" {
  1956. // if sortParam == "endDate" {
  1957. // sortStr = " ORDER BY b.end_date "
  1958. // } else if sortParam == "createTime" {
  1959. // sortStr = " ORDER BY a.created_time "
  1960. // } else {
  1961. // br.Msg = "获取失败"
  1962. // br.ErrMsg = "排序字段传入数据异常:" + sortParam
  1963. // return
  1964. // }
  1965. //
  1966. // if sortType == "asc" {
  1967. // sortStr += " ASC "
  1968. // } else if sortType == "desc" {
  1969. // sortStr += " DESC "
  1970. // } else {
  1971. // br.Msg = "获取失败"
  1972. // br.ErrMsg = "排序类型传入数据异常:" + sortType
  1973. // return
  1974. // }
  1975. // }
  1976. //
  1977. // list, err := company.GetCompanyList(condition, status, sortStr, pars, startSize, pageSize)
  1978. // if err != nil {
  1979. // br.Msg = "获取失败"
  1980. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1981. // return
  1982. // }
  1983. //
  1984. //
  1985. // //企业用户数组切片
  1986. // companyIdSlice := make([]string, 0)
  1987. // for _, v := range list {
  1988. // companyIdSlice = append(companyIdSlice, strconv.Itoa(v.CompanyId))
  1989. // }
  1990. //
  1991. // //企业用户产品开通数
  1992. // companyIdStr := strings.Join(companyIdSlice, ",")
  1993. // companyProductTotalList, _ := company.GetCountProductByCompanyIds(companyIdStr)
  1994. // companyProductTotalMap := make(map[int]*company.CompanyProductTotalSlice)
  1995. // for _, companyProductTotal := range companyProductTotalList {
  1996. // companyProductTotalMap[companyProductTotal.CompanyId] = companyProductTotal
  1997. // }
  1998. // lenList := len(list)
  1999. // for i := 0; i < lenList; i++ {
  2000. // item := list[i]
  2001. //
  2002. // //校验该客户是否存在多个产品,如果是,那么代表是共享客户
  2003. // if companyProductTotal, ok := companyProductTotalMap[int(item.CompanyId)]; ok {
  2004. // if companyProductTotal.Total > 1 {
  2005. // list[i].IsShared = true
  2006. // }
  2007. // }
  2008. //
  2009. // var expireDay string
  2010. // itemStatus := item.Status
  2011. // if itemStatus != "" {
  2012. // if !strings.Contains(item.Status, "/") {
  2013. // if itemStatus == utils.COMPANY_STATUS_FOREVER { //永续
  2014. // expireDay = "-"
  2015. // } else if itemStatus == utils.COMPANY_STATUS_TRY_OUT || itemStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  2016. // if item.StartDate != "" && item.EndDate != "" {
  2017. // endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  2018. // endDateTime = endDateTime.AddDate(0, 0, 1)
  2019. // sub := endDateTime.Sub(time.Now())
  2020. // if sub < 0 {
  2021. // sub = 0
  2022. // }
  2023. // expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2024. // } else {
  2025. // expireDay = "-"
  2026. // }
  2027. // } else if itemStatus == utils.COMPANY_STATUS_LOSE {
  2028. // expireDay = "-"
  2029. // } else if itemStatus == utils.COMPANY_STATUS_FREEZE {
  2030. // if item.StartDate != "" && item.EndDate != "" {
  2031. // endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  2032. // endDateTime = endDateTime.AddDate(0, 0, 0)
  2033. // sub := endDateTime.Sub(time.Now())
  2034. // if sub < 0 {
  2035. // sub = 0
  2036. // }
  2037. // expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2038. // } else {
  2039. // expireDay = "-"
  2040. // }
  2041. // } else {
  2042. // expireDay = "-"
  2043. // }
  2044. // } else {
  2045. // statusArr := strings.Split(item.Status, "/")
  2046. // ficcStatus := statusArr[0]
  2047. // raiStatus := statusArr[1]
  2048. // var ficcEndDate, tryEndDate string
  2049. // var ficcExpireDay, tryExpireDay string
  2050. // if item.EndDate != "" {
  2051. // endDateArr := strings.Split(item.EndDate, "/")
  2052. // if len(endDateArr) == 1 {
  2053. // ficcEndDate = endDateArr[0]
  2054. // } else if len(endDateArr) > 1 {
  2055. // ficcEndDate = endDateArr[0]
  2056. // tryEndDate = endDateArr[1]
  2057. // }
  2058. // if ficcStatus == utils.COMPANY_STATUS_FOREVER { //永续
  2059. // ficcExpireDay = "-"
  2060. // } else if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  2061. // if ficcEndDate != "" {
  2062. // endDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
  2063. // endDateTime = endDateTime.AddDate(0, 0, 1)
  2064. // sub := endDateTime.Sub(time.Now())
  2065. // if sub < 0 {
  2066. // sub = 0
  2067. // }
  2068. // ficcExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2069. // } else {
  2070. // ficcExpireDay = "-"
  2071. // }
  2072. // } else if ficcStatus == utils.COMPANY_STATUS_LOSE { //流失
  2073. // ficcExpireDay = "-"
  2074. // } else if ficcStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  2075. // if item.StartDate != "" && item.EndDate != "" {
  2076. // endDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
  2077. // endDateTime = endDateTime.AddDate(0, 0, 0)
  2078. // sub := endDateTime.Sub(time.Now())
  2079. // if sub < 0 {
  2080. // sub = 0
  2081. // }
  2082. // ficcExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2083. // } else {
  2084. // ficcExpireDay = "-"
  2085. // }
  2086. // } else {
  2087. // ficcExpireDay = "-"
  2088. // }
  2089. //
  2090. // if raiStatus == utils.COMPANY_STATUS_FOREVER { //永续
  2091. // tryExpireDay = "-"
  2092. // } else if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  2093. // if tryEndDate != "" {
  2094. // endDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
  2095. // endDateTime = endDateTime.AddDate(0, 0, 1)
  2096. // sub := endDateTime.Sub(time.Now())
  2097. // if sub < 0 {
  2098. // sub = 0
  2099. // }
  2100. // tryExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2101. // } else {
  2102. // tryExpireDay = "-"
  2103. // }
  2104. // } else if raiStatus == utils.COMPANY_STATUS_LOSE { //流失
  2105. // tryExpireDay = "-"
  2106. // } else if raiStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  2107. // if item.StartDate != "" && item.EndDate != "" {
  2108. // endDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
  2109. // endDateTime = endDateTime.AddDate(0, 0, 0)
  2110. // sub := endDateTime.Sub(time.Now())
  2111. // if sub < 0 {
  2112. // sub = 0
  2113. // }
  2114. // tryExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2115. // } else {
  2116. // tryExpireDay = "-"
  2117. // }
  2118. // } else {
  2119. // tryExpireDay = "-"
  2120. // }
  2121. // }
  2122. // expireDay = ficcExpireDay + "/" + tryExpireDay
  2123. // }
  2124. // }
  2125. // list[i].ExpireDay = expireDay
  2126. //
  2127. // //按钮显示控制
  2128. // btnItem := new(company.ButtonPermission)
  2129. // if item.CompanyId != 1 {
  2130. // *btnItem = services.GetCompanyPermissionButton(roleTypeCode, itemStatus, item.GroupIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId)
  2131. // }
  2132. // list[i].BtnItem = btnItem
  2133. // if item.FreezeStartDate != "" && item.FreezeEndDate != "" && item.Status == utils.COMPANY_STATUS_FREEZE {
  2134. // freezeEndDate, _ := time.Parse(utils.FormatDate, item.FreezeEndDate)
  2135. // if time.Now().Before(freezeEndDate) {
  2136. // expireDays := freezeEndDate.Sub(time.Now()).Hours() / 24
  2137. // list[i].FreezeExpireDays = int(expireDays) + 1
  2138. // }
  2139. // }
  2140. // }
  2141. //
  2142. // statusCount, err := company.GetCompanyStatusCount(permissionCondition, permissionPars)
  2143. // if err != nil {
  2144. // br.Msg = "获取失败"
  2145. // br.ErrMsg = "获取状态数量失败,Err:" + err.Error()
  2146. // return
  2147. // }
  2148. //
  2149. // statusMap := make(map[string]int, 0)
  2150. // var totalCount int
  2151. // for _, sv := range statusCount {
  2152. // totalCount = totalCount + sv.Count
  2153. // statusMap[sv.Status] = sv.Count
  2154. // }
  2155. //
  2156. // lossItem, err := company.GetCompanyStatusLoseCount(lossCondition, lossPars)
  2157. // if err != nil {
  2158. // br.Msg = "获取失败"
  2159. // br.ErrMsg = "获取流失状态数量失败,Err:" + err.Error()
  2160. // return
  2161. // }
  2162. // totalCount = totalCount + lossItem.Count
  2163. //
  2164. // freezeItem, err := company.GetCompanyStatusFreezeCount(freezeCondition, freezePars)
  2165. // if err != nil {
  2166. // br.Msg = "获取失败"
  2167. // br.ErrMsg = "获取冻结状态数量失败,Err:" + err.Error()
  2168. // return
  2169. // }
  2170. // statusMap["冻结"] = freezeItem.Count
  2171. // totalCount = totalCount + freezeItem.Count
  2172. //
  2173. // forverItem, err := company.GetCompanyStatusForverCount(forverCondition, forverPars)
  2174. // if err != nil {
  2175. // br.Msg = "获取失败"
  2176. // br.ErrMsg = "获取永续状态数量失败,Err:" + err.Error()
  2177. // return
  2178. // }
  2179. // totalCount = totalCount + forverItem.Count
  2180. //
  2181. // for _, v := range statusArr {
  2182. // statusCount := new(company.CompanyStatus)
  2183. // if v == "全部" {
  2184. // statusCount.Status = "全部"
  2185. // statusCount.Count = totalCount
  2186. // } else if v == utils.COMPANY_STATUS_LOSE {
  2187. // statusCount.Status = v
  2188. // statusCount.Count = lossItem.Count
  2189. // } else if v == utils.COMPANY_STATUS_FOREVER {
  2190. // statusCount.Status = v
  2191. // statusCount.Count = forverItem.Count
  2192. // //} else if v == utils.COMPANY_STATUS_FREEZE {
  2193. // // statusCount.Status = v
  2194. // // statusCount.Count = freezeItem.Count
  2195. // //}
  2196. // } else {
  2197. // statusCount.Status = v
  2198. // if val, ok := statusMap[v]; ok {
  2199. // statusCount.Count = val
  2200. // }
  2201. // }
  2202. // statusItems = append(statusItems, statusCount)
  2203. // }
  2204. //
  2205. // companyLists := make([]*company.CompanyListItem, 0)
  2206. // //查询阅读次数
  2207. // if list == nil {
  2208. // companyLists = make([]*company.CompanyListItem, 0)
  2209. // } else {
  2210. // for _, v := range list {
  2211. // viewTotal := GetviewTotal(v.CompanyId)
  2212. // companyList := &company.CompanyListItem{
  2213. // CompanyId: v.CompanyId,
  2214. // CompanyName: v.CompanyName,
  2215. // CreditCode: v.CreditCode,
  2216. // CompanyCode: v.CompanyCode,
  2217. // StartDate: v.StartDate,
  2218. // EndDate: v.EndDate,
  2219. // LoseReason: v.LoseReason,
  2220. // RenewalReason: v.RenewalReason,
  2221. // FreezeReason: v.FreezeReason,
  2222. // LossTime: v.LossTime,
  2223. // Status: v.Status,
  2224. // CompanyType: v.CompanyType,
  2225. // ApproveStatus: v.ApproveStatus,
  2226. // SellerName: v.SellerName,
  2227. // SellerId: v.SellerId,
  2228. // SellerIds: v.SellerIds,
  2229. // ExpireDay: v.ExpireDay,
  2230. // FreezeTime: v.FreezeTime,
  2231. // GroupId: v.GroupId,
  2232. // GroupIds: v.GroupIds,
  2233. // DepartmentId: v.DepartmentId,
  2234. // IndustryName: v.IndustryName,
  2235. // IsSuspend: v.IsSuspend,
  2236. // CreatedTime: v.CreatedTime,
  2237. // Source: v.Source,
  2238. // Province: v.Province,
  2239. // City: v.City,
  2240. // Address: v.Address,
  2241. // Reasons: v.Reasons,
  2242. // FreezeStartDate: v.FreezeStartDate,
  2243. // FreezeEndDate: v.FreezeEndDate,
  2244. // FreezeExpireDays: v.FreezeExpireDays,
  2245. // BtnItem: v.BtnItem,
  2246. // ProductId: v.ProductId,
  2247. // FormalTime: v.FormalTime,
  2248. // IsShared: v.IsShared,
  2249. // RegionType: v.RegionType,
  2250. // FiccView: viewTotal[0],
  2251. // RaiView: viewTotal[1],
  2252. // }
  2253. // companyLists = append(companyLists, companyList)
  2254. // }
  2255. // }
  2256. // if companyLists == nil {
  2257. // companyLists = make([]*company.CompanyListItem, 0)
  2258. // }
  2259. // page = paging.GetPaging(currentIndex, pageSize, total)
  2260. // resp.List = companyLists
  2261. // resp.StatusCount = statusItems
  2262. // resp.Paging = page
  2263. // br.Ret = 200
  2264. // br.Success = true
  2265. // br.Msg = "获取成功"
  2266. // br.Data = resp
  2267. //}
  2268. func GetviewTotal(companyId int) (view []int) {
  2269. list, err := company.GetCompanyUserListById(companyId)
  2270. if err != nil {
  2271. fmt.Println("GetCompanyUserList err:", err.Error())
  2272. return
  2273. }
  2274. //获取企业客户信息
  2275. companyInfo, err := company.GetCompanyById(companyId)
  2276. if err != nil {
  2277. fmt.Println("GetCompanyById err:", err.Error())
  2278. return
  2279. }
  2280. var ficcViewTotal, cygxViewTotal int
  2281. lenList := len(list)
  2282. if lenList > 0 {
  2283. userIdSlice := make([]string, 0)
  2284. mobilesSlice := make([]string, 0)
  2285. emailsSlice := make([]string, 0)
  2286. for _, v := range list {
  2287. userIdSlice = append(userIdSlice, strconv.Itoa(int(v.UserId)))
  2288. if v.Mobile != "" {
  2289. mobilesSlice = append(mobilesSlice, v.Mobile)
  2290. } else if v.Email != "" {
  2291. emailsSlice = append(emailsSlice, v.Email)
  2292. }
  2293. }
  2294. //用户浏览数据
  2295. mobileStr := strings.Join(mobilesSlice, "','")
  2296. mobileStr = "'" + mobileStr + "'"
  2297. emailStr := strings.Join(emailsSlice, "','")
  2298. emailStr = "'" + emailStr + "'"
  2299. //报告统计删除晨报部分统计加入每日资讯 2021-4-9
  2300. //手机号
  2301. userViewMobileTotalMap := make(map[string]*models.UserViewMobileTotalSlice)
  2302. userReportViewMobileTotalMap := make(map[string]*models.ReportViewMobileRecord)
  2303. userAdvisoryViewMobileTotalMap := make(map[string]*advisory.UserViewMobileTotalSlice)
  2304. userCygxArticleHistoryRecordViewMobileTotalMap := make(map[string]*models.UserViewMobileTotalSlice)
  2305. if len(mobilesSlice) > 0 {
  2306. //权益数据
  2307. rightsItems, err := company.GetRightsReportListByMobile(mobileStr)
  2308. if err != nil {
  2309. fmt.Println("GetRightsReportListByMobile err:", err.Error())
  2310. return
  2311. }
  2312. cygxViewTotal = len(rightsItems)
  2313. //FICC数据
  2314. ficcItems, err := company.GetFiccReportListByMobile(mobileStr)
  2315. if err != nil {
  2316. fmt.Println("GetFiccReportListByMobile err:", err.Error())
  2317. return
  2318. }
  2319. ficcViewTotal = len(ficcItems)
  2320. }
  2321. //邮箱
  2322. userViewEmailTotalMap := make(map[string]*models.UserViewEmailTotalSlice)
  2323. userReportViewEmailTotalMap := make(map[string]*models.ReportViewEmailRecord)
  2324. userAdvisoryViewEmailTotalMap := make(map[string]*advisory.UserViewEmailTotalSlice)
  2325. userCygxViewEmailTotalMap := make(map[string]*models.UserViewEmailTotalSlice)
  2326. if len(emailsSlice) > 0 {
  2327. //FICC数据
  2328. ficcItems, err := company.GetFiccReportListByEmail(emailStr)
  2329. if err != nil {
  2330. fmt.Println("GetFiccReportListByEmail err:", err.Error())
  2331. return
  2332. }
  2333. ficcViewTotal += len(ficcItems)
  2334. //权益数据
  2335. rightsItems, err := company.GetRightsReportListByEmail(emailStr)
  2336. if err != nil {
  2337. fmt.Println("GetViewReportListByMobile err:", err.Error())
  2338. return
  2339. }
  2340. cygxViewTotal += len(rightsItems)
  2341. }
  2342. for i := 0; i < lenList; i++ {
  2343. item := list[i]
  2344. //企业名称
  2345. list[i].CompanyName = companyInfo.CompanyName
  2346. //手机号用户累计浏览次数
  2347. if userView, ok := userViewMobileTotalMap[item.Mobile]; ok {
  2348. list[i].ViewTotal += userView.Total
  2349. }
  2350. //邮箱用户累计浏览次数
  2351. if userView, ok := userViewEmailTotalMap[item.Email]; ok {
  2352. //总共浏览的报表数据需要调整为(手机号用户浏览晨报数+邮箱号用户浏览晨报数)
  2353. list[i].ViewTotal += userView.Total
  2354. }
  2355. if item.OpenId != "" {
  2356. list[i].IsRegister = true
  2357. } else {
  2358. if item.RegisterPlatform == 2 {
  2359. if item.Mobile != "" || item.Email != "" {
  2360. list[i].IsRegister = true
  2361. }
  2362. } else if item.RegisterTime != "" {
  2363. list[i].IsRegister = true
  2364. } else {
  2365. list[i].IsRegister = false
  2366. }
  2367. }
  2368. //如果存在手机号用户日评数据,那么需要做处理
  2369. if reportView, ok := userReportViewMobileTotalMap[item.Mobile]; ok {
  2370. //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
  2371. if reportView.LastViewTime.After(list[i].LastViewTime) {
  2372. list[i].LastViewTime = reportView.LastViewTime
  2373. list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
  2374. }
  2375. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
  2376. list[i].ViewTotal += reportView.ViewTotal
  2377. }
  2378. //如果存在手机号用户日评数据,那么需要做处理
  2379. if reportView, ok := userReportViewEmailTotalMap[item.Email]; ok {
  2380. //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
  2381. if reportView.LastViewTime.After(list[i].LastViewTime) {
  2382. list[i].LastViewTime = reportView.LastViewTime
  2383. list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
  2384. }
  2385. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
  2386. list[i].ViewTotal += reportView.ViewTotal
  2387. }
  2388. //如果存在手机号用户每日资讯,那么需要做处理
  2389. if advisoryView, ok := userAdvisoryViewMobileTotalMap[item.Mobile]; ok {
  2390. //fmt.Println("蝴蝶眨几次眼睛")
  2391. //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  2392. if advisoryView.CreatedTime.After(list[i].LastViewTime) {
  2393. list[i].LastViewTime = advisoryView.CreatedTime
  2394. list[i].LastViewTimeStr = advisoryView.CreatedTime.Format(utils.FormatDateTime)
  2395. }
  2396. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数)
  2397. list[i].ViewTotal += advisoryView.Total
  2398. }
  2399. //如果存在邮箱号用户每日资讯,那么需要做处理
  2400. if advisoryView, ok := userAdvisoryViewEmailTotalMap[item.Email]; ok {
  2401. //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  2402. if advisoryView.CreatedTime.After(list[i].LastViewTime) {
  2403. list[i].LastViewTime = advisoryView.CreatedTime
  2404. list[i].LastViewTimeStr = advisoryView.CreatedTime.Format(utils.FormatDateTime)
  2405. }
  2406. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数)
  2407. list[i].ViewTotal += advisoryView.Total
  2408. }
  2409. ficcViewTotal += list[i].ViewTotal
  2410. //如果存在手机号用户查研观向,那么需要做处理
  2411. if cygxView, ok := userCygxArticleHistoryRecordViewMobileTotalMap[item.Mobile]; ok {
  2412. //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  2413. if cygxView.CreatedTime.After(list[i].LastViewTime) {
  2414. list[i].LastViewTime = cygxView.CreatedTime
  2415. list[i].LastViewTimeStr = cygxView.CreatedTime.Format(utils.FormatDateTime)
  2416. }
  2417. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数+查研观向)
  2418. cygxViewTotal += cygxView.Total
  2419. list[i].ViewTotal += cygxView.Total
  2420. }
  2421. //如果存在邮箱号用户查研观向,那么需要做处理
  2422. if cygxView, ok := userCygxViewEmailTotalMap[item.Email]; ok {
  2423. //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  2424. if cygxView.CreatedTime.After(list[i].LastViewTime) {
  2425. list[i].LastViewTime = cygxView.CreatedTime
  2426. list[i].LastViewTimeStr = cygxView.CreatedTime.Format(utils.FormatDateTime)
  2427. }
  2428. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数+查研观向)
  2429. cygxViewTotal += cygxView.Total
  2430. //list[i].ViewTotal += cygxView.Total
  2431. }
  2432. /*if reportView, ok := userReportViewTotalMap[int(item.UserId)]; ok {
  2433. //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
  2434. if reportView.LastViewTime.After(list[i].LastViewTime) {
  2435. list[i].LastViewTime = reportView.LastViewTime
  2436. list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
  2437. }
  2438. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
  2439. list[i].ViewTotal += reportView.ViewTotal
  2440. }*/
  2441. }
  2442. }
  2443. view = append(view, ficcViewTotal)
  2444. view = append(view, cygxViewTotal)
  2445. return
  2446. }
  2447. // @Title 新增客户
  2448. // @Description 新增客户接口
  2449. // @Param request body company.CompanyAddReq true "type json string"
  2450. // @Success 200 {object} company.CompanyAddResp
  2451. // @router /add [post]
  2452. func (this *CompanyController) Add() {
  2453. br := new(models.BaseResponse).Init()
  2454. defer func() {
  2455. this.Data["json"] = br
  2456. this.ServeJSON()
  2457. }()
  2458. sysUser := this.SysUser
  2459. if sysUser == nil {
  2460. br.Msg = "请登录"
  2461. br.ErrMsg = "请登录,SysUser Is Empty"
  2462. br.Ret = 408
  2463. return
  2464. }
  2465. roleTypeCode := sysUser.RoleTypeCode
  2466. var req company.CompanyAddReq
  2467. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2468. if err != nil {
  2469. br.Msg = "参数解析异常!"
  2470. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2471. return
  2472. }
  2473. if req.CompanyName == "" {
  2474. br.Msg = "请填写客户名称"
  2475. return
  2476. }
  2477. if req.CreditCode == "" {
  2478. br.Msg = "请填写社会统一信用码"
  2479. return
  2480. }
  2481. if req.Status == "" {
  2482. br.Msg = "客户状态不可为空"
  2483. return
  2484. }
  2485. //移除空格
  2486. req.CreditCode = utils.TrimStr(req.CreditCode)
  2487. var startDateTime, endDateTime time.Time
  2488. if req.Status == utils.COMPANY_STATUS_TRY_OUT {
  2489. startDateTime = time.Now()
  2490. endDateTime = time.Now().AddDate(0, 2, 0)
  2491. } else if req.Status == utils.COMPANY_STATUS_FOREVER {
  2492. startDateTime = time.Now()
  2493. endDateTime = time.Now().AddDate(100, 0, 0)
  2494. } else {
  2495. br.Msg = "无效的客户状态,请重新选择"
  2496. return
  2497. }
  2498. var startDate, endDate string
  2499. startDate = startDateTime.Format(utils.FormatDate)
  2500. endDate = endDateTime.Format(utils.FormatDate)
  2501. if req.CompanyType == "" {
  2502. br.Msg = "请选择客户类型"
  2503. return
  2504. }
  2505. var productId int
  2506. var productName string
  2507. if req.CompanyType == utils.COMPANY_PRODUCT_FICC_NAME {
  2508. productId = utils.COMPANY_PRODUCT_FICC_ID
  2509. productName = utils.COMPANY_PRODUCT_FICC_NAME
  2510. } else if req.CompanyType == utils.COMPANY_PRODUCT_RAI_NAME {
  2511. productId = utils.COMPANY_PRODUCT_RAI_ID
  2512. productName = utils.COMPANY_PRODUCT_RAI_NAME
  2513. } else {
  2514. br.Msg = "无效的客户类型,请重新选择"
  2515. return
  2516. }
  2517. if req.IndustryId <= 0 {
  2518. br.Msg = "请选择行业"
  2519. return
  2520. }
  2521. if req.SellsId <= 0 {
  2522. br.Msg = "请选择所属销售"
  2523. return
  2524. }
  2525. //if req.Reasons == "" {
  2526. // br.Msg = "请填写新增理由"
  2527. // return
  2528. //}
  2529. if req.PermissionIds == "" {
  2530. br.Msg = "请选择权限"
  2531. return
  2532. } else {
  2533. permissionStr, err := company.GetPermissionIdById(req.PermissionIds)
  2534. if err != nil {
  2535. br.Msg = "获取信息失败"
  2536. br.ErrMsg = "获取主观客观权限信息失败,Err:" + err.Error()
  2537. return
  2538. }
  2539. req.PermissionIds = permissionStr
  2540. }
  2541. industry, err := company.GetCompanyIndustryById(req.IndustryId)
  2542. if err != nil {
  2543. br.Msg = "获取行业信息失败"
  2544. br.ErrMsg = "获取行业信息失败,Err:" + err.Error()
  2545. return
  2546. }
  2547. if industry == nil {
  2548. br.Msg = "行业信息不存在"
  2549. return
  2550. }
  2551. //判断客户是否已经存在
  2552. companyNameIsExist, err := company.GetCompanyCountByCompanyName(req.CompanyName)
  2553. if err != nil {
  2554. br.Msg = "判断客户是否存在失败"
  2555. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  2556. return
  2557. }
  2558. if companyNameIsExist > 0 {
  2559. br.Msg = "客户已存在,请重新输入客户名称"
  2560. return
  2561. }
  2562. //判断客户是否已经存在
  2563. companyCreditCodeIsExist, err := company.GetCompanyCountByCreditCode(req.CreditCode)
  2564. if err != nil {
  2565. br.Msg = "判断客户是否存在失败"
  2566. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  2567. return
  2568. }
  2569. if companyCreditCodeIsExist > 0 {
  2570. br.Msg = "客户已存在,统一社会信用代码"
  2571. return
  2572. }
  2573. seller, err := system.GetSysAdminById(req.SellsId)
  2574. if err != nil {
  2575. br.Msg = "获取销售信息失败"
  2576. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  2577. return
  2578. }
  2579. tryOutCount, err := company.GetCompanyTryOutCount(utils.COMPANY_STATUS_TRY_OUT, seller.AdminId)
  2580. if err != nil {
  2581. br.Msg = "判断试用客户量失败"
  2582. br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  2583. return
  2584. }
  2585. /*
  2586. ROLE_TYPE_CODE_ADMIN = "admin" //管理员
  2587. ROLE_TYPE_CODE_FICC_ADMIN = "ficc_admin" //ficc管理员
  2588. ROLE_TYPE_CODE_FICC_SELLER = "ficc_seller" //ficc销售
  2589. ROLE_TYPE_CODE_RAI_ADMIN = "rai_admin" //权益管理员
  2590. ROLE_TYPE_CODE_RAI_SELLER = "rai_seller" //权益销售
  2591. ROLE_TYPE_CODE_FICC_GROUP = "ficc_group" //ficc组长
  2592. ROLE_TYPE_CODE_RAI_GROUP = "rai_group" //ficc组长
  2593. ROLE_TYPE_CODE_FICC_DEPARTMENT = "ficc_department" //ficc部门经理
  2594. ROLE_TYPE_CODE_RAI_DEPARTMENT = "rai_department" //权益部门经理
  2595. ROLE_TYPE_CODE_FICC_RESEARCHR = "ficc_researcher" //ficc研究员
  2596. ROLE_TYPE_CODE_RAI_RESEARCHR = "rai_researcher" //权益研究员
  2597. */
  2598. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
  2599. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  2600. if tryOutCount >= utils.COMPANY_STATUS_TRY_OUT_COUNT {
  2601. br.Msg = "您的试用客户总数,已超过上限,不可继续新增"
  2602. return
  2603. }
  2604. }
  2605. if seller == nil {
  2606. br.Msg = "所属销售不存在"
  2607. return
  2608. }
  2609. companyCode, err := company.GetCompanyCode()
  2610. if err != nil {
  2611. br.Msg = "获取客户编码信息失败"
  2612. br.ErrMsg = "获取客户编码信息失败,Err:" + err.Error()
  2613. return
  2614. }
  2615. item := new(company.Company)
  2616. item.CompanyName = req.CompanyName
  2617. item.CreditCode = req.CreditCode
  2618. item.CompanyCode = companyCode
  2619. item.Province = req.Province
  2620. item.City = req.City
  2621. item.Address = req.Province + req.City
  2622. item.StartDate = time.Now().Format(utils.FormatDate)
  2623. if req.Status == utils.COMPANY_STATUS_FOREVER {
  2624. item.EndDate = time.Now().AddDate(100, 0, 0).Format(utils.FormatDate)
  2625. item.CompanyType = 5
  2626. }
  2627. if req.Status == utils.COMPANY_STATUS_TRY_OUT {
  2628. item.EndDate = time.Now().AddDate(0, 2, 0).Format(utils.FormatDate)
  2629. item.CompanyType = 2
  2630. }
  2631. item.FirstStartDate = item.StartDate
  2632. item.FirstEndDate = item.EndDate
  2633. item.CreatedTime = time.Now()
  2634. item.LastUpdatedTime = time.Now()
  2635. item.Enabled = 1
  2636. item.RegionType = req.RegionType
  2637. item.Remark = req.Reasons
  2638. companyId, err := company.AddCompany(item)
  2639. if err != nil {
  2640. br.Msg = "新增失败"
  2641. br.ErrMsg = "新增失败,err:" + err.Error()
  2642. return
  2643. }
  2644. item.CompanyId = int(companyId)
  2645. //生成第三方code编号
  2646. item.OpenCompanyCode = services.GenerateOpenCompanyCode(int(companyId))
  2647. item.Update([]string{"OpenCompanyCode"})
  2648. if req.UserId > 0 {
  2649. //修改联系人
  2650. err = company.ModifyCompanyUserCompanyId(req.UserId, int(companyId))
  2651. if err != nil {
  2652. br.Msg = "新增失败"
  2653. br.ErrMsg = "新增失败,ModifyCompanyUserCompanyId err:" + err.Error()
  2654. return
  2655. }
  2656. //添加该联系人 与 当前销售的关系
  2657. models.AddUserSellerRelation(int64(req.UserId), int(companyId), seller.AdminId, productId, seller.RealName, "", "")
  2658. }
  2659. companyProduct := new(company.CompanyProduct)
  2660. companyProduct.CompanyId = int(companyId)
  2661. companyProduct.ProductId = productId
  2662. companyProduct.ProductName = productName
  2663. companyProduct.CompanyName = req.CompanyName
  2664. companyProduct.Source = req.Source
  2665. companyProduct.Reasons = req.Reasons
  2666. companyProduct.Status = req.Status
  2667. companyProduct.StartDate = startDate
  2668. companyProduct.EndDate = endDate
  2669. companyProduct.IndustryId = req.IndustryId
  2670. companyProduct.IndustryName = industry.IndustryName
  2671. companyProduct.SellerId = seller.AdminId
  2672. companyProduct.SellerName = seller.RealName
  2673. companyProduct.GroupId = seller.GroupId
  2674. companyProduct.DepartmentId = seller.DepartmentId
  2675. companyProduct.IsSuspend = 0
  2676. companyProduct.CreateTime = time.Now()
  2677. companyProduct.ModifyTime = time.Now()
  2678. companyProduct.CompanyType = req.CompanyType
  2679. companyProduct.Scale = req.Scale
  2680. companyProduct.OpenCode = services.GenerateOpenCompanyProductCode(int(companyId), productId)
  2681. companyProduct.TodoStatus = "无任务"
  2682. companyProduct.TryStage = 1
  2683. companyProductId, err := company.AddCompanyProduct(companyProduct)
  2684. if err != nil {
  2685. br.Msg = "新增失败"
  2686. br.ErrMsg = "新增客户产品失败,err:" + err.Error()
  2687. return
  2688. }
  2689. companyReportPermissionList, err := services.AddCompanyPermission(int(companyId), seller.AdminId, productId, productName, seller.RealName, req.PermissionIds, startDate, endDate)
  2690. if err != nil {
  2691. br.Msg = "新增失败"
  2692. br.ErrMsg = "新增客户设置权限失败,err:" + err.Error()
  2693. return
  2694. }
  2695. {
  2696. record := new(company.CompanyOperationRecord)
  2697. record.CompanyId = int(companyId)
  2698. record.CompanyName = req.CompanyName
  2699. record.SellerId = seller.AdminId
  2700. record.SysUserId = seller.AdminId
  2701. record.SysRealName = seller.RealName
  2702. record.Remark = "新增客户"
  2703. record.Operation = "add"
  2704. record.CreateTime = time.Now()
  2705. record.ProductId = productId
  2706. record.ProductName = productName
  2707. record.Status = req.Status
  2708. _, err = company.AddCompanyOperationRecord(record)
  2709. if err != nil {
  2710. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  2711. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  2712. }
  2713. }
  2714. //新增客户日志
  2715. {
  2716. companyLog := new(company.CompanyLog)
  2717. companyLog.CompanyId = int(companyId)
  2718. companyLog.CompanyName = req.CompanyName
  2719. companyLog.CreditCode = req.CreditCode
  2720. companyLog.CompanyCode = companyCode
  2721. companyLog.Sort = item.Sort
  2722. companyLog.IsFeeCustomer = item.IsFeeCustomer
  2723. companyLog.Country = item.Country
  2724. companyLog.Address = item.Address
  2725. companyLog.City = item.City
  2726. companyLog.Province = item.Province
  2727. companyLog.Enabled = item.Enabled
  2728. companyLog.CreatedTime = item.CreatedTime
  2729. companyLog.LastUpdatedTime = item.LastUpdatedTime
  2730. companyLog.Seller = item.Seller
  2731. companyLog.SellsId = item.SellsId
  2732. companyLog.CompanyBelong = item.CompanyBelong
  2733. companyLog.StartDate = item.StartDate
  2734. companyLog.EndDate = item.EndDate
  2735. companyLog.FirstStartDate = item.FirstStartDate
  2736. companyLog.FirstEndDate = item.FirstEndDate
  2737. companyLog.DateType = item.DateType
  2738. companyLog.AdminId = this.SysUser.AdminId
  2739. companyLog.LogType = "add"
  2740. companyLog.LogCreateTime = time.Now()
  2741. go company.AddCompanyLog(companyLog)
  2742. }
  2743. //新增客户产品日志
  2744. {
  2745. productLog := new(company.CompanyProductLog)
  2746. productLog.CompanyProductId = int(companyProductId)
  2747. productLog.CompanyId = companyProduct.CompanyId
  2748. productLog.ProductId = companyProduct.ProductId
  2749. productLog.ProductName = companyProduct.ProductName
  2750. productLog.CompanyName = companyProduct.CompanyName
  2751. productLog.CompanyName = companyProduct.CompanyName
  2752. productLog.Source = companyProduct.Source
  2753. productLog.Reasons = companyProduct.Reasons
  2754. productLog.Status = companyProduct.Status
  2755. productLog.IndustryId = companyProduct.IndustryId
  2756. productLog.IndustryName = companyProduct.IndustryName
  2757. productLog.SellerId = companyProduct.SellerId
  2758. productLog.SellerName = companyProduct.SellerName
  2759. productLog.GroupId = companyProduct.GroupId
  2760. productLog.DepartmentId = companyProduct.DepartmentId
  2761. productLog.IsSuspend = companyProduct.IsSuspend
  2762. productLog.SuspendTime = companyProduct.SuspendTime
  2763. productLog.ApproveStatus = companyProduct.ApproveStatus
  2764. productLog.FreezeTime = companyProduct.FreezeTime
  2765. productLog.Remark = companyProduct.Remark
  2766. productLog.StartDate = companyProduct.StartDate
  2767. productLog.EndDate = companyProduct.EndDate
  2768. productLog.CreateTime = companyProduct.CreateTime
  2769. productLog.ModifyTime = companyProduct.ModifyTime
  2770. productLog.LoseReason = companyProduct.LoseReason
  2771. productLog.LossTime = companyProduct.LossTime
  2772. productLog.LogType = "add"
  2773. productLog.LogCreateTime = time.Now()
  2774. productLog.AdminId = this.SysUser.AdminId
  2775. productLog.Scale = companyProduct.Scale
  2776. go company.AddCompanyProductLog(productLog)
  2777. }
  2778. //新增客户产品状态变更日志
  2779. {
  2780. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  2781. Id: 0,
  2782. CompanyId: companyProduct.CompanyId,
  2783. ProductId: companyProduct.ProductId,
  2784. Status: "试用",
  2785. Source: "add",
  2786. SellerId: companyProduct.SellerId,
  2787. SellerName: companyProduct.SellerName,
  2788. StartDate: startDateTime,
  2789. EndDate: endDateTime,
  2790. RealEndDate: startDateTime,
  2791. CreateTime: time.Now(),
  2792. }
  2793. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  2794. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  2795. Id: 0,
  2796. CompanyId: companyProduct.CompanyId,
  2797. ProductId: companyProduct.ProductId,
  2798. Source: "add",
  2799. SellerId: companyProduct.SellerId,
  2800. SellerName: companyProduct.SellerName,
  2801. StartDate: startDateTime,
  2802. EndDate: endDateTime,
  2803. RealEndDate: startDateTime,
  2804. IsStop: 0,
  2805. CreateTime: time.Now(),
  2806. }
  2807. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  2808. }
  2809. resp := new(company.CompanyAddResp)
  2810. resp.CompanyId = int(companyId)
  2811. br.Ret = 200
  2812. br.Success = true
  2813. br.Msg = "新增成功"
  2814. br.Data = resp
  2815. }
  2816. // Detail
  2817. // @Title 获取客户详情
  2818. // @Description 获取客户详情接口
  2819. // @Param CompanyId query int true "客户id"
  2820. // @Success 200 {object} company.CompanyDetailResp
  2821. // @router /detail [get]
  2822. func (this *CompanyController) Detail() {
  2823. br := new(models.BaseResponse).Init()
  2824. defer func() {
  2825. this.Data["json"] = br
  2826. this.ServeJSON()
  2827. }()
  2828. sysUser := this.SysUser
  2829. if sysUser == nil {
  2830. br.Msg = "请登录"
  2831. br.ErrMsg = "请登录,SysUser Is Empty"
  2832. br.Ret = 408
  2833. return
  2834. }
  2835. companyId, _ := this.GetInt("CompanyId")
  2836. if companyId <= 0 {
  2837. br.Msg = "参数错误"
  2838. br.ErrMsg = "客户参数小于等于0"
  2839. return
  2840. }
  2841. // CRM8.8-是否为编辑页的客户详情
  2842. isEdit, _ := this.GetBool("IsEdit")
  2843. item, err := company.GetCompanyDetailById(companyId)
  2844. if err != nil {
  2845. br.Msg = "获取信息失败"
  2846. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  2847. return
  2848. }
  2849. shareSellerId := item.ShareSellerId
  2850. var productName string
  2851. productId := services.GetProductId(sysUser.RoleTypeCode)
  2852. if productId == 1 {
  2853. productName = utils.COMPANY_PRODUCT_FICC_NAME
  2854. } else if productId == 2 {
  2855. productName = utils.COMPANY_PRODUCT_RAI_NAME
  2856. } else {
  2857. productName = "admin"
  2858. }
  2859. resp := new(company.CompanyDetailResp)
  2860. resp.ProductName = productName
  2861. //获取客户产品
  2862. productList, err := company.GetCompanyProductsByCompanyId(companyId)
  2863. if err != nil {
  2864. br.Msg = "获取信息失败"
  2865. br.ErrMsg = "获取产品信息失败,Err:" + err.Error()
  2866. return
  2867. }
  2868. roleTypeCode := sysUser.RoleTypeCode
  2869. itemLen := len(productList)
  2870. btnDetailItem := new(company.ButtonDetailPermission)
  2871. // 客户权限校验
  2872. {
  2873. // 如果不是超管、ficc管理员、权益管理员,那么需要额外校验下权限
  2874. if !utils.InArrayByStr([]string{utils.ROLE_TYPE_CODE_ADMIN, utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_RAI_ADMIN}, sysUser.RoleTypeCode) {
  2875. var isOk bool //是否有权限
  2876. var companyHasProduct bool // 客户当前是否有该产品权限
  2877. for _, productInfo := range productList {
  2878. // 只校验拥有的品种权限:ficc或者权益
  2879. if productInfo.ProductId == productId {
  2880. companyHasProduct = true
  2881. // 自己的客户有权限看
  2882. if productInfo.SellerId == sysUser.AdminId {
  2883. isOk = true
  2884. break
  2885. }
  2886. // 流失客户都有权限看
  2887. if productInfo.Status == utils.COMPANY_STATUS_LOSE || productInfo.Status == utils.COMPANY_STATUS_CLOSE {
  2888. isOk = true
  2889. break
  2890. }
  2891. // 分享的客户 也有权限
  2892. if item.IsShare == 1 && item.ShareSellerId == sysUser.AdminId {
  2893. isOk = true
  2894. break
  2895. }
  2896. // 如果是组长,且该客户属于本组客户
  2897. if sysUser.Authority == 4 && productInfo.GroupId > 0 && productInfo.GroupId == sysUser.GroupId && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM {
  2898. isOk = true
  2899. break
  2900. }
  2901. // 如果是ficc主管或者权益主管
  2902. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  2903. // 获取顶级分组Id
  2904. var sysUserGroupPid, productGroupPid int
  2905. // 当前账号的顶级分组id
  2906. {
  2907. sysUserGroupIdpid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  2908. if err != nil && err.Error() != utils.NotEmpty() {
  2909. break
  2910. }
  2911. if sysUserGroupIdpid == nil || *sysUserGroupIdpid == 0 {
  2912. sysUserGroupPid = sysUser.GroupId
  2913. } else {
  2914. sysUserGroupPid = *sysUserGroupIdpid
  2915. }
  2916. }
  2917. // 当前客户的顶级分组id
  2918. {
  2919. groupIdpid, err := company.GetParentIdFromGroup(productInfo.GroupId)
  2920. if err != nil && err.Error() != utils.NotEmpty() {
  2921. break
  2922. }
  2923. if groupIdpid == nil || *groupIdpid == 0 {
  2924. productGroupPid = productInfo.GroupId
  2925. } else {
  2926. productGroupPid = *groupIdpid
  2927. }
  2928. }
  2929. // 如果客户的顶级分组和当前账号分组id一致
  2930. if sysUserGroupPid == productGroupPid {
  2931. isOk = true
  2932. break
  2933. }
  2934. }
  2935. }
  2936. }
  2937. // 客户当前是否有该产品的权限,如果没有的话,说明是在领取客户,允许访问
  2938. if !companyHasProduct {
  2939. isOk = true
  2940. }
  2941. if !isOk {
  2942. br.Msg = "无访问权限"
  2943. return
  2944. }
  2945. }
  2946. }
  2947. //产品权限map
  2948. statusMap := make(map[int]string)
  2949. for i := 0; i < itemLen; i++ {
  2950. item := productList[i]
  2951. //添加产品权限map
  2952. statusMap[item.ProductId] = item.Status
  2953. if i == 0 {
  2954. if item.ProductId == 1 {
  2955. resp.CreateAuth = 1
  2956. } else {
  2957. resp.CreateAuth = 2
  2958. }
  2959. }
  2960. if item.ProductId == 1 {
  2961. if strings.Contains(sysUser.RoleTypeCode, "ficc") {
  2962. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  2963. btnDetailItem.BtnHistoryList = true
  2964. } else {
  2965. if item.SellerId == sysUser.AdminId || shareSellerId == sysUser.AdminId {
  2966. btnDetailItem.BtnHistoryList = true
  2967. }
  2968. if sysUser.Authority > 0 {
  2969. if item.GroupId == sysUser.GroupId {
  2970. btnDetailItem.BtnHistoryList = true
  2971. }
  2972. if item.DepartmentId == sysUser.DepartmentId {
  2973. btnDetailItem.BtnHistoryList = true
  2974. }
  2975. }
  2976. }
  2977. }
  2978. for _, v := range utils.PermissionFiccClassifyArr {
  2979. checkList := make([]int, 0)
  2980. plist := new(company.PermissionLookList)
  2981. items, err := company.GetPermissionLookItems(item.ProductId, v)
  2982. if err != nil {
  2983. br.Msg = "获取失败"
  2984. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  2985. return
  2986. }
  2987. for itemK, n := range items {
  2988. permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  2989. if err != nil && err.Error() != utils.ErrNoRow() {
  2990. br.Msg = "获取失败"
  2991. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  2992. return
  2993. }
  2994. if permission != nil && permission.ChartPermissionId > 0 {
  2995. checkList = append(checkList, n.ChartPermissionId)
  2996. items[itemK].StartDate = permission.StartDate
  2997. items[itemK].EndDate = permission.EndDate
  2998. items[itemK].Status = permission.Status
  2999. endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
  3000. endDateTime = endDateTime.AddDate(0, 0, 1)
  3001. sub := endDateTime.Sub(time.Now())
  3002. if sub < 0 {
  3003. sub = 0
  3004. }
  3005. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  3006. items[itemK].ExpireDay = expireDay
  3007. }
  3008. //count, err := company.GetCompanyPermissionCheck(companyId, n.ChartPermissionId)
  3009. //if err != nil {
  3010. // br.Msg = "获取失败"
  3011. // br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3012. // return
  3013. //}
  3014. //if count > 0 {
  3015. // checkList = append(checkList, n.ChartPermissionId)
  3016. //}
  3017. }
  3018. plist.Items = items
  3019. plist.ClassifyName = v
  3020. plist.CheckList = checkList
  3021. item.PermissionList = append(item.PermissionList, plist)
  3022. }
  3023. resp.FiccItem = item
  3024. if (roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  3025. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT) &&
  3026. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3027. resp.IsButtonShow = 1
  3028. }
  3029. } else {
  3030. if strings.Contains(sysUser.RoleTypeCode, "rai") {
  3031. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  3032. btnDetailItem.BtnHistoryList = true
  3033. } else {
  3034. if item.SellerId == sysUser.AdminId {
  3035. btnDetailItem.BtnHistoryList = true
  3036. }
  3037. if sysUser.Authority > 0 {
  3038. if item.GroupId == sysUser.GroupId {
  3039. btnDetailItem.BtnHistoryList = true
  3040. }
  3041. if item.DepartmentId == sysUser.DepartmentId {
  3042. btnDetailItem.BtnHistoryList = true
  3043. }
  3044. }
  3045. }
  3046. }
  3047. // CRM8.8-权益权限列表调用较多、统一进行调整
  3048. plist, e := services.RaiCompanyPermissionAndCheckList(companyId, isEdit)
  3049. if e != nil {
  3050. br.Msg = "获取客户权益权限列表信息失败"
  3051. br.ErrMsg = "获取客户权益权限列表信息失败,Err:" + e.Error()
  3052. return
  3053. }
  3054. // cygx8.2专项产业调研展示
  3055. item.SpecialSurplus, err = cygxService.GetSpecialSurplusByCompany(companyId)
  3056. if err != nil {
  3057. br.Msg = "获取失败"
  3058. br.ErrMsg = "获取专项调研信息失败,Err:" + err.Error()
  3059. return
  3060. }
  3061. //研选服务点数
  3062. item.Points = cygxService.GetCygxActivityPointsCompanyByCompanyId(companyId)
  3063. item.PermissionList = append(item.PermissionList, plist)
  3064. resp.RaiItem = item
  3065. if (roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  3066. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  3067. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT) &&
  3068. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3069. resp.IsButtonShow = 1
  3070. }
  3071. }
  3072. 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)
  3073. //if itemLen > 1 {
  3074. // btnDetailItem.BtnEdit = false
  3075. // btnDetailItem.BtnDelete = false
  3076. //} else {
  3077. // btnDetailItem.BtnEdit = btnItem.BtnEdit
  3078. // btnDetailItem.BtnDelete = btnItem.BtnDelete
  3079. //}
  3080. switch item.ProductId {
  3081. case 1:
  3082. btnDetailItem.FiccEdit = btnItem.BtnEdit
  3083. btnDetailItem.FiccDelete = btnItem.BtnDelete
  3084. case 2:
  3085. btnDetailItem.RaiEdit = btnItem.BtnEdit
  3086. btnDetailItem.RaiDelete = btnItem.BtnDelete
  3087. }
  3088. if !btnDetailItem.BtnEdit {
  3089. btnDetailItem.BtnEdit = btnItem.BtnEdit
  3090. }
  3091. if !btnDetailItem.BtnDelete {
  3092. btnDetailItem.BtnDelete = btnItem.BtnDelete
  3093. }
  3094. //联系人操作权限
  3095. if resp.IsContractButtonShow == false {
  3096. resp.IsContractButtonShow = services.CheckCompanyUserButton(sysUser.RoleTypeCode, item.SellerId, sysUser.AdminId, item.ProductId, shareSellerId, item.Status)
  3097. }
  3098. }
  3099. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  3100. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  3101. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  3102. resp.IsButtonShow = 1
  3103. btnDetailItem.BtnHistoryList = true
  3104. }
  3105. //ficc权限
  3106. if ficcStatus, ok := statusMap[1]; ok {
  3107. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT {
  3108. if raiStatus, ok := statusMap[2]; ok {
  3109. //另一个权限也是 试用 、冻结、流失
  3110. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3111. //那么超管、部门管理员、销售可以编辑
  3112. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3113. btnDetailItem.BaseInfoEdit = true
  3114. }
  3115. }
  3116. //权益是永续时,超管可编辑基础信息
  3117. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3118. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3119. btnDetailItem.BaseInfoEdit = true
  3120. }
  3121. }
  3122. } else {
  3123. //权限未开,有编辑基础信息权限
  3124. btnDetailItem.BaseInfoEdit = true
  3125. }
  3126. }
  3127. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3128. if raiStatus, ok := statusMap[2]; ok {
  3129. //另一个权限也是 永续 、冻结、流失
  3130. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FOREVER || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3131. //超管可编辑基础信息
  3132. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3133. btnDetailItem.BaseInfoEdit = true
  3134. }
  3135. }
  3136. } else {
  3137. //权限未开,有编辑基础信息权限
  3138. btnDetailItem.BaseInfoEdit = true
  3139. }
  3140. }
  3141. }
  3142. //权益销售
  3143. if raiStatus, ok := statusMap[2]; ok {
  3144. if raiStatus == utils.COMPANY_STATUS_TRY_OUT {
  3145. if ficcStatus, ok := statusMap[1]; ok {
  3146. //另一个权限也是 试用 、冻结、流失
  3147. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3148. //那么超管、部门管理员、销售可以编辑
  3149. if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3150. btnDetailItem.BaseInfoEdit = true
  3151. }
  3152. }
  3153. //ficc是永续时,超管可编辑基础信息
  3154. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3155. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3156. btnDetailItem.BaseInfoEdit = true
  3157. }
  3158. }
  3159. } else {
  3160. //权限未开,有编辑基础信息权限
  3161. btnDetailItem.BaseInfoEdit = true
  3162. }
  3163. }
  3164. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3165. if ficcStatus, ok := statusMap[1]; ok {
  3166. //另一个权限也是 试用、永续 、冻结、流失
  3167. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FOREVER || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3168. //超管可编辑基础信息
  3169. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3170. btnDetailItem.BaseInfoEdit = true
  3171. }
  3172. }
  3173. } else {
  3174. //权限未开,有编辑基础信息权限
  3175. btnDetailItem.BaseInfoEdit = true
  3176. }
  3177. }
  3178. }
  3179. resp.Item = item
  3180. resp.BtnItem = btnDetailItem
  3181. br.Ret = 200
  3182. br.Success = true
  3183. br.Msg = "获取成功"
  3184. br.Data = resp
  3185. }
  3186. // DetailByCreditCode
  3187. // @Title 根据社会信用码获取客户详情
  3188. // @Description 根据社会信用码获取客户详情接口
  3189. // @Param CreditCode query string true "客户社会信用码"
  3190. // @Success 200 {object} company.CompanyDetailResp
  3191. // @router /detail_by_credit_code [get]
  3192. func (this *CompanyController) DetailByCreditCode() {
  3193. br := new(models.BaseResponse).Init()
  3194. defer func() {
  3195. this.Data["json"] = br
  3196. this.ServeJSON()
  3197. }()
  3198. sysUser := this.SysUser
  3199. if sysUser == nil {
  3200. br.Msg = "请登录"
  3201. br.ErrMsg = "请登录,SysUser Is Empty"
  3202. br.Ret = 408
  3203. return
  3204. }
  3205. resp := new(company.CompanyDetailResp)
  3206. creditCode := this.GetString("CreditCode")
  3207. if creditCode == "" {
  3208. br.Msg = "参数错误"
  3209. br.ErrMsg = "社会信用码必传"
  3210. return
  3211. }
  3212. item, err := company.GetCompanyDetailByCreditCode(creditCode)
  3213. if err != nil {
  3214. br.Ret = 200
  3215. br.Success = true
  3216. br.Msg = "获取成功"
  3217. br.Data = resp
  3218. return
  3219. }
  3220. shareSellerId := item.ShareSellerId
  3221. companyId := item.CompanyId
  3222. var productName string
  3223. productId := services.GetProductId(sysUser.RoleTypeCode)
  3224. if productId == 1 {
  3225. productName = utils.COMPANY_PRODUCT_FICC_NAME
  3226. } else if productId == 2 {
  3227. productName = utils.COMPANY_PRODUCT_RAI_NAME
  3228. } else {
  3229. productName = "admin"
  3230. }
  3231. resp.ProductName = productName
  3232. //获取客户产品
  3233. productList, err := company.GetCompanyProductsByCompanyId(companyId)
  3234. if err != nil {
  3235. br.Msg = "获取信息失败"
  3236. br.ErrMsg = "获取产品信息失败,Err:" + err.Error()
  3237. return
  3238. }
  3239. roleTypeCode := sysUser.RoleTypeCode
  3240. itemLen := len(productList)
  3241. btnDetailItem := new(company.ButtonDetailPermission)
  3242. //产品权限map
  3243. statusMap := make(map[int]string)
  3244. for i := 0; i < itemLen; i++ {
  3245. item := productList[i]
  3246. //添加产品权限map
  3247. statusMap[item.ProductId] = item.Status
  3248. if i == 0 {
  3249. if item.ProductId == 1 {
  3250. resp.CreateAuth = 1
  3251. } else {
  3252. resp.CreateAuth = 2
  3253. }
  3254. }
  3255. if item.ProductId == 1 {
  3256. if strings.Contains(sysUser.RoleTypeCode, "ficc") {
  3257. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  3258. btnDetailItem.BtnHistoryList = true
  3259. } else {
  3260. if item.SellerId == sysUser.AdminId {
  3261. btnDetailItem.BtnHistoryList = true
  3262. }
  3263. if sysUser.Authority > 0 {
  3264. if item.GroupId == sysUser.GroupId {
  3265. btnDetailItem.BtnHistoryList = true
  3266. }
  3267. if item.DepartmentId == sysUser.DepartmentId {
  3268. btnDetailItem.BtnHistoryList = true
  3269. }
  3270. }
  3271. }
  3272. }
  3273. for _, v := range utils.PermissionFiccClassifyArr {
  3274. checkList := make([]int, 0)
  3275. plist := new(company.PermissionLookList)
  3276. items, err := company.GetPermissionLookItems(item.ProductId, v)
  3277. if err != nil {
  3278. br.Msg = "获取失败"
  3279. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3280. return
  3281. }
  3282. for itemK, n := range items {
  3283. permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  3284. if err != nil && err.Error() != utils.ErrNoRow() {
  3285. br.Msg = "获取失败"
  3286. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3287. return
  3288. }
  3289. if permission != nil && permission.ChartPermissionId > 0 {
  3290. checkList = append(checkList, n.ChartPermissionId)
  3291. items[itemK].StartDate = permission.StartDate
  3292. items[itemK].EndDate = permission.EndDate
  3293. items[itemK].Status = permission.Status
  3294. endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
  3295. endDateTime = endDateTime.AddDate(0, 0, 1)
  3296. sub := endDateTime.Sub(time.Now())
  3297. if sub < 0 {
  3298. sub = 0
  3299. }
  3300. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  3301. items[itemK].ExpireDay = expireDay
  3302. }
  3303. //count, err := company.GetCompanyPermissionCheck(companyId, n.ChartPermissionId)
  3304. //if err != nil {
  3305. // br.Msg = "获取失败"
  3306. // br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3307. // return
  3308. //}
  3309. //if count > 0 {
  3310. // checkList = append(checkList, n.ChartPermissionId)
  3311. //}
  3312. }
  3313. plist.Items = items
  3314. plist.ClassifyName = v
  3315. plist.CheckList = checkList
  3316. item.PermissionList = append(item.PermissionList, plist)
  3317. }
  3318. resp.FiccItem = item
  3319. if (roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  3320. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT) &&
  3321. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3322. resp.IsButtonShow = 1
  3323. }
  3324. } else {
  3325. if strings.Contains(sysUser.RoleTypeCode, "rai") {
  3326. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  3327. btnDetailItem.BtnHistoryList = true
  3328. } else {
  3329. if item.SellerId == sysUser.AdminId {
  3330. btnDetailItem.BtnHistoryList = true
  3331. }
  3332. if sysUser.Authority > 0 {
  3333. if item.GroupId == sysUser.GroupId {
  3334. btnDetailItem.BtnHistoryList = true
  3335. }
  3336. if item.DepartmentId == sysUser.DepartmentId {
  3337. btnDetailItem.BtnHistoryList = true
  3338. }
  3339. }
  3340. }
  3341. }
  3342. classifyName := "权益"
  3343. checkList := make([]int, 0)
  3344. plist := new(company.PermissionLookList)
  3345. items, err := company.GetPermissionLookItems(item.ProductId, classifyName)
  3346. if err != nil {
  3347. br.Msg = "获取失败"
  3348. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3349. return
  3350. }
  3351. for itemK, n := range items {
  3352. permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  3353. if err != nil && err.Error() != utils.ErrNoRow() {
  3354. br.Msg = "获取失败"
  3355. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3356. return
  3357. }
  3358. if permission != nil && permission.ChartPermissionId > 0 {
  3359. checkList = append(checkList, n.ChartPermissionId)
  3360. items[itemK].StartDate = permission.StartDate
  3361. items[itemK].EndDate = permission.EndDate
  3362. items[itemK].Status = permission.Status
  3363. endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
  3364. endDateTime = endDateTime.AddDate(0, 0, 1)
  3365. sub := endDateTime.Sub(time.Now())
  3366. if sub < 0 {
  3367. sub = 0
  3368. }
  3369. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  3370. items[itemK].ExpireDay = expireDay
  3371. }
  3372. //count, err := company.GetCompanyPermissionCheck(companyId, n.ChartPermissionId)
  3373. //if err != nil {
  3374. // br.Msg = "获取失败"
  3375. // br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3376. // return
  3377. //}
  3378. //if count > 0 {
  3379. // checkList = append(checkList, n.ChartPermissionId)
  3380. //}
  3381. }
  3382. item.SpecialSurplus, err = cygxService.GetSpecialSurplusByCompany(companyId)
  3383. if err != nil {
  3384. br.Msg = "获取失败"
  3385. br.ErrMsg = "获取专项调研信息失败,Err:" + err.Error()
  3386. return
  3387. }
  3388. plist.Items = items
  3389. plist.ClassifyName = classifyName
  3390. plist.CheckList = checkList
  3391. item.PermissionList = append(item.PermissionList, plist)
  3392. resp.RaiItem = item
  3393. if (roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  3394. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  3395. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT) &&
  3396. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3397. resp.IsButtonShow = 1
  3398. }
  3399. }
  3400. 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)
  3401. //if itemLen > 1 {
  3402. // btnDetailItem.BtnEdit = false
  3403. // btnDetailItem.BtnDelete = false
  3404. //} else {
  3405. // btnDetailItem.BtnEdit = btnItem.BtnEdit
  3406. // btnDetailItem.BtnDelete = btnItem.BtnDelete
  3407. //}
  3408. switch item.ProductId {
  3409. case 1:
  3410. btnDetailItem.FiccEdit = btnItem.BtnEdit
  3411. btnDetailItem.FiccDelete = btnItem.BtnDelete
  3412. case 2:
  3413. btnDetailItem.RaiEdit = btnItem.BtnEdit
  3414. btnDetailItem.RaiDelete = btnItem.BtnDelete
  3415. }
  3416. if !btnDetailItem.BtnEdit {
  3417. btnDetailItem.BtnEdit = btnItem.BtnEdit
  3418. }
  3419. if !btnDetailItem.BtnDelete {
  3420. btnDetailItem.BtnDelete = btnItem.BtnDelete
  3421. }
  3422. //联系人操作权限
  3423. if resp.IsContractButtonShow == false {
  3424. resp.IsContractButtonShow = services.CheckCompanyUserButton(sysUser.RoleTypeCode, item.SellerId, sysUser.AdminId, item.ProductId, shareSellerId, item.Status)
  3425. }
  3426. }
  3427. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  3428. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  3429. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  3430. resp.IsButtonShow = 1
  3431. btnDetailItem.BtnHistoryList = true
  3432. }
  3433. //ficc权限
  3434. if ficcStatus, ok := statusMap[1]; ok {
  3435. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT {
  3436. if raiStatus, ok := statusMap[2]; ok {
  3437. //另一个权限也是 试用 、冻结、流失
  3438. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3439. //那么超管、部门管理员、销售可以编辑
  3440. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3441. btnDetailItem.BaseInfoEdit = true
  3442. }
  3443. }
  3444. //权益是永续时,超管可编辑基础信息
  3445. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3446. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3447. btnDetailItem.BaseInfoEdit = true
  3448. }
  3449. }
  3450. } else {
  3451. //权限未开,有编辑基础信息权限
  3452. btnDetailItem.BaseInfoEdit = true
  3453. }
  3454. }
  3455. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3456. if raiStatus, ok := statusMap[2]; ok {
  3457. //另一个权限也是 永续 、冻结、流失
  3458. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FOREVER || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3459. //超管可编辑基础信息
  3460. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3461. btnDetailItem.BaseInfoEdit = true
  3462. }
  3463. }
  3464. } else {
  3465. //权限未开,有编辑基础信息权限
  3466. btnDetailItem.BaseInfoEdit = true
  3467. }
  3468. }
  3469. }
  3470. //权益销售
  3471. if raiStatus, ok := statusMap[2]; ok {
  3472. if raiStatus == utils.COMPANY_STATUS_TRY_OUT {
  3473. if ficcStatus, ok := statusMap[1]; ok {
  3474. //另一个权限也是 试用 、冻结、流失
  3475. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3476. //那么超管、部门管理员、销售可以编辑
  3477. if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3478. btnDetailItem.BaseInfoEdit = true
  3479. }
  3480. }
  3481. //ficc是永续时,超管可编辑基础信息
  3482. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3483. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3484. btnDetailItem.BaseInfoEdit = true
  3485. }
  3486. }
  3487. } else {
  3488. //权限未开,有编辑基础信息权限
  3489. btnDetailItem.BaseInfoEdit = true
  3490. }
  3491. }
  3492. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3493. if ficcStatus, ok := statusMap[1]; ok {
  3494. //另一个权限也是 试用、永续 、冻结、流失
  3495. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FOREVER || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3496. //超管可编辑基础信息
  3497. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3498. btnDetailItem.BaseInfoEdit = true
  3499. }
  3500. }
  3501. } else {
  3502. //权限未开,有编辑基础信息权限
  3503. btnDetailItem.BaseInfoEdit = true
  3504. }
  3505. }
  3506. }
  3507. resp.Item = item
  3508. resp.BtnItem = btnDetailItem
  3509. br.Ret = 200
  3510. br.Success = true
  3511. br.Msg = "获取成功"
  3512. br.Data = resp
  3513. }
  3514. // @Title 编辑客户
  3515. // @Description 编辑客户接口
  3516. // @Param request body company.CompanyEditReq true "type json string"
  3517. // @Success Ret=200 保存成功
  3518. // @router /edit [post]
  3519. func (this *CompanyController) Edit() {
  3520. br := new(models.BaseResponse).Init()
  3521. defer func() {
  3522. this.Data["json"] = br
  3523. this.ServeJSON()
  3524. }()
  3525. sysUser := this.SysUser
  3526. if sysUser == nil {
  3527. br.Msg = "请登录"
  3528. br.ErrMsg = "请登录,SysUser Is Empty"
  3529. br.Ret = 408
  3530. return
  3531. }
  3532. //roleTypeCode := sysUser.RoleTypeCode
  3533. var req company.CompanyEditReq
  3534. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3535. if err != nil {
  3536. br.Msg = "参数解析异常!"
  3537. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3538. return
  3539. }
  3540. if req.CompanyId <= 0 {
  3541. br.Msg = "参数异常!"
  3542. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  3543. return
  3544. }
  3545. if req.CompanyName == "" {
  3546. br.Msg = "请填写客户名称"
  3547. return
  3548. }
  3549. if req.CreditCode == "" {
  3550. br.Msg = "请填写社会统一信用码"
  3551. return
  3552. }
  3553. //移除空格
  3554. req.CreditCode = utils.TrimStr(req.CreditCode)
  3555. productId := services.GetProductId(sysUser.RoleTypeCode) //产品权限id
  3556. for _, v := range req.Products {
  3557. if v.IndustryId <= 0 {
  3558. br.Msg = "请选择行业"
  3559. br.IsSendEmail = false
  3560. return
  3561. }
  3562. //获取客户产品信息
  3563. productItem, err := company.GetCompanyProductById(v.CompanyProductId)
  3564. if err != nil {
  3565. br.Msg = "数据获取失败!"
  3566. br.ErrMsg = "数据获取失败,Err:" + err.Error()
  3567. return
  3568. }
  3569. if productItem == nil {
  3570. br.Msg = "客户信息不存在!"
  3571. return
  3572. }
  3573. // 如果本身是有权限归属的,同时传入的参数不是当前账号权限的,那么过滤该次循环,进入下次循环
  3574. if productId > 0 && productItem.ProductId != productId {
  3575. continue
  3576. }
  3577. if v.Status == "" {
  3578. br.Msg = "客户状态不可为空"
  3579. return
  3580. }
  3581. //if v.Reasons == "" {
  3582. // br.Msg = "请填写新增理由"
  3583. // return
  3584. //}
  3585. if v.PermissionIds == "" {
  3586. br.Msg = "请选择权限"
  3587. return
  3588. }
  3589. var startDate, endDate string
  3590. startDate = productItem.StartDate
  3591. endDate = productItem.EndDate
  3592. if startDate == "" || endDate == "" {
  3593. br.Msg = "数据错误"
  3594. br.Msg = "数据错误,开始或结束日期为空:startDate:" + startDate + "endDate:" + endDate
  3595. return
  3596. }
  3597. //判断客户是否已经存在
  3598. companyNameIsExist, err := company.GetCompanyCountByCompanyNameAndCompanyId(req.CompanyId, req.CompanyName)
  3599. if err != nil {
  3600. br.Msg = "判断客户是否存在失败"
  3601. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  3602. return
  3603. }
  3604. if companyNameIsExist > 0 {
  3605. br.Msg = "客户已存在,请重新输入客户名称"
  3606. return
  3607. }
  3608. //判断客户是否已经存在
  3609. companyCreditCodeIsExist, err := company.GetCompanyCountByCreditCodeAndCompanyId(req.CompanyId, req.CreditCode)
  3610. if err != nil {
  3611. br.Msg = "判断客户是否存在失败"
  3612. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  3613. return
  3614. }
  3615. if companyCreditCodeIsExist > 0 {
  3616. br.Msg = "客户已存在,请重新输入统一社会信用代码"
  3617. return
  3618. }
  3619. seller, err := system.GetSysAdminById(v.SellsId)
  3620. if err != nil {
  3621. br.Msg = "获取销售信息失败"
  3622. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  3623. return
  3624. }
  3625. if seller == nil {
  3626. br.Msg = "所属销售不存在"
  3627. return
  3628. }
  3629. //tryOutCount, err := company.GetCompanyTryOutCount(utils.COMPANY_STATUS_TRY_OUT, seller.AdminId)
  3630. //if err != nil {
  3631. // br.Msg = "判断试用客户量失败"
  3632. // br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  3633. // return
  3634. //}
  3635. //if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
  3636. // roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  3637. // if tryOutCount >= utils.COMPANY_STATUS_TRY_OUT_COUNT && v.SellsId == sysUser.AdminId {
  3638. // br.Msg = "您的试用客户总数,已超过上限,不可继续新增"
  3639. // return
  3640. // }
  3641. //}
  3642. industry, err := company.GetCompanyIndustryById(v.IndustryId)
  3643. if err != nil {
  3644. br.Msg = "获取行业信息失败"
  3645. br.ErrMsg = "获取行业信息失败,Err:" + err.Error()
  3646. return
  3647. }
  3648. companyProduct := new(company.CompanyProduct)
  3649. companyProduct.ProductId = productItem.ProductId
  3650. companyProduct.CompanyId = req.CompanyId
  3651. companyProduct.CompanyName = req.CompanyName
  3652. companyProduct.Source = v.Source
  3653. companyProduct.Reasons = v.Reasons
  3654. companyProduct.Status = v.Status
  3655. companyProduct.StartDate = startDate
  3656. companyProduct.EndDate = endDate
  3657. companyProduct.IndustryId = v.IndustryId
  3658. companyProduct.IndustryName = industry.IndustryName
  3659. companyProduct.SellerId = seller.AdminId
  3660. companyProduct.SellerName = seller.RealName
  3661. companyProduct.GroupId = seller.GroupId
  3662. companyProduct.DepartmentId = seller.DepartmentId
  3663. companyProduct.IsSuspend = 0
  3664. companyProduct.ModifyTime = time.Now()
  3665. companyProduct.CompanyProductId = v.CompanyProductId
  3666. companyProduct.Scale = v.Scale
  3667. err = company.ModifyCompanyProduct(companyProduct)
  3668. if err != nil {
  3669. br.Msg = "修改客户信息失败"
  3670. br.ErrMsg = "修改客户产品信息失败,Err:" + err.Error()
  3671. return
  3672. }
  3673. // CRM8.8-下面的需求取消, 编辑的时候根据选择开通对应权限
  3674. // 如果是权益客户,编辑的时候开通主观客观权限
  3675. //if v.CompanyType == utils.COMPANY_CLASSIFY_RAI {
  3676. // permissionStr, err := company.GetPermissionIdById(v.PermissionIds)
  3677. // if err != nil {
  3678. // br.Msg = "修改失败"
  3679. // br.ErrMsg = "获取主观客观权限信息失败,Err:" + err.Error()
  3680. // return
  3681. // }
  3682. // v.PermissionIds = permissionStr
  3683. //}
  3684. //处理权限
  3685. companyReportPermissionList, err := services.AddCompanyPermission(req.CompanyId, seller.AdminId, productItem.ProductId, productItem.ProductName, seller.RealName, v.PermissionIds, startDate, endDate)
  3686. if err != nil {
  3687. br.Msg = "修改失败"
  3688. br.ErrMsg = "新增客户设置权限失败,err:" + err.Error()
  3689. return
  3690. }
  3691. //新增操作记录
  3692. {
  3693. record := new(company.CompanyOperationRecord)
  3694. record.CompanyId = req.CompanyId
  3695. record.CompanyName = req.CompanyName
  3696. record.SellerId = companyProduct.SellerId
  3697. record.SysUserId = this.SysUser.AdminId
  3698. record.SysRealName = this.SysUser.RealName
  3699. record.Remark = "编辑客户"
  3700. record.Operation = "edit"
  3701. record.CreateTime = time.Now()
  3702. record.ProductId = productItem.ProductId
  3703. record.ProductName = productItem.ProductName
  3704. record.Status = productItem.Status
  3705. _, err = company.AddCompanyOperationRecord(record)
  3706. if err != nil {
  3707. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  3708. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  3709. }
  3710. }
  3711. //新增客户产品日志
  3712. {
  3713. productLog := new(company.CompanyProductLog)
  3714. productLog.CompanyProductId = v.CompanyProductId
  3715. productLog.CompanyId = companyProduct.CompanyId
  3716. productLog.ProductId = companyProduct.ProductId
  3717. productLog.ProductName = companyProduct.ProductName
  3718. productLog.CompanyName = companyProduct.CompanyName
  3719. productLog.CompanyName = companyProduct.CompanyName
  3720. productLog.Source = companyProduct.Source
  3721. productLog.Reasons = companyProduct.Reasons
  3722. productLog.Status = companyProduct.Status
  3723. productLog.IndustryId = companyProduct.IndustryId
  3724. productLog.IndustryName = companyProduct.IndustryName
  3725. productLog.SellerId = companyProduct.SellerId
  3726. productLog.SellerName = companyProduct.SellerName
  3727. productLog.GroupId = companyProduct.GroupId
  3728. productLog.DepartmentId = companyProduct.DepartmentId
  3729. productLog.IsSuspend = companyProduct.IsSuspend
  3730. productLog.SuspendTime = companyProduct.SuspendTime
  3731. productLog.ApproveStatus = companyProduct.ApproveStatus
  3732. productLog.FreezeTime = companyProduct.FreezeTime
  3733. productLog.Remark = companyProduct.Remark
  3734. productLog.StartDate = companyProduct.StartDate
  3735. productLog.EndDate = companyProduct.EndDate
  3736. productLog.CreateTime = companyProduct.CreateTime
  3737. productLog.ModifyTime = companyProduct.ModifyTime
  3738. productLog.LoseReason = companyProduct.LoseReason
  3739. productLog.LossTime = companyProduct.LossTime
  3740. productLog.LogType = "modify"
  3741. productLog.LogCreateTime = time.Now()
  3742. productLog.AdminId = this.SysUser.AdminId
  3743. productLog.Scale = companyProduct.Scale
  3744. go company.AddCompanyProductLog(productLog)
  3745. }
  3746. //新增客户产品状态变更日志
  3747. {
  3748. startDateTime, _ := time.ParseInLocation(utils.FormatDate, startDate, time.Local)
  3749. endDateTime, _ := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
  3750. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  3751. Id: 0,
  3752. CompanyId: req.CompanyId,
  3753. ProductId: productId,
  3754. Status: "试用",
  3755. Source: "edit",
  3756. SellerId: seller.AdminId,
  3757. SellerName: seller.RealName,
  3758. StartDate: startDateTime,
  3759. EndDate: endDateTime,
  3760. RealEndDate: startDateTime,
  3761. CreateTime: time.Now(),
  3762. }
  3763. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  3764. // 添加试用记录
  3765. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  3766. Id: 0,
  3767. CompanyId: req.CompanyId,
  3768. ProductId: productId,
  3769. Source: "edit",
  3770. SellerId: seller.AdminId,
  3771. SellerName: seller.RealName,
  3772. StartDate: startDateTime,
  3773. EndDate: endDateTime,
  3774. RealEndDate: startDateTime,
  3775. IsStop: 0,
  3776. CreateTime: time.Now(),
  3777. }
  3778. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  3779. }
  3780. }
  3781. companyItem := new(company.Company)
  3782. companyItem.CompanyId = req.CompanyId
  3783. companyItem.CompanyName = req.CompanyName
  3784. companyItem.CreditCode = req.CreditCode
  3785. companyItem.Province = req.Province
  3786. companyItem.City = req.City
  3787. companyItem.Address = req.Province + req.City
  3788. companyItem.LastUpdatedTime = time.Now()
  3789. companyItem.Enabled = 1
  3790. err = company.ModifyCompany(companyItem)
  3791. if err != nil {
  3792. br.Msg = "修改客户信息失败"
  3793. br.ErrMsg = "修改客户信息失败,Err:" + err.Error()
  3794. return
  3795. }
  3796. //新增客户日志
  3797. {
  3798. companyLog := new(company.CompanyLog)
  3799. companyLog.CompanyId = req.CompanyId
  3800. companyLog.CompanyName = req.CompanyName
  3801. companyLog.CreditCode = req.CreditCode
  3802. companyLog.Address = companyItem.Address
  3803. companyLog.City = companyItem.City
  3804. companyLog.Province = companyItem.Province
  3805. companyLog.LastUpdatedTime = companyItem.LastUpdatedTime
  3806. companyLog.AdminId = this.SysUser.AdminId
  3807. companyLog.LogType = "modify"
  3808. companyLog.LogCreateTime = time.Now()
  3809. go company.AddCompanyLog(companyLog)
  3810. }
  3811. br.Ret = 200
  3812. br.Success = true
  3813. br.Msg = "保存成功"
  3814. }
  3815. // @Title 编辑补充客户信息接口
  3816. // @Description 编辑补充客户信息接口
  3817. // @Param request body company.CompanyInfoEditReq true "type json string"
  3818. // @Success Ret=200 保存成功
  3819. // @router /company_info/edit [post]
  3820. func (this *CompanyController) EditCompanyInfo() {
  3821. br := new(models.BaseResponse).Init()
  3822. defer func() {
  3823. this.Data["json"] = br
  3824. this.ServeJSON()
  3825. }()
  3826. sysUser := this.SysUser
  3827. if sysUser == nil {
  3828. br.Msg = "请登录"
  3829. br.ErrMsg = "请登录,SysUser Is Empty"
  3830. br.Ret = 408
  3831. return
  3832. }
  3833. var req company.CompanyInfoEditReq
  3834. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3835. if err != nil {
  3836. br.Msg = "参数解析异常!"
  3837. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3838. return
  3839. }
  3840. if req.CompanyId <= 0 {
  3841. br.Msg = "参数异常!"
  3842. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  3843. return
  3844. }
  3845. if req.CompanyName == "" {
  3846. br.Msg = "请填写客户名称"
  3847. return
  3848. }
  3849. if req.CreditCode == "" {
  3850. br.Msg = "请填写社会统一信用码"
  3851. return
  3852. }
  3853. //if req.Province == "" {
  3854. // br.Msg = "请选择省份"
  3855. // return
  3856. //}
  3857. //if req.City == "" {
  3858. // br.Msg = "请选择市区"
  3859. // return
  3860. //}
  3861. //if req.IndustryId <= 0 {
  3862. // br.Msg = "请选择所属行业"
  3863. // return
  3864. //}
  3865. //if req.IndustryName == "" {
  3866. // br.Msg = "请选择所属行业"
  3867. // return
  3868. //}
  3869. //if req.Source == "" {
  3870. // br.Msg = "请选择来源"
  3871. // return
  3872. //}
  3873. //移除空格
  3874. req.CreditCode = utils.TrimStr(req.CreditCode)
  3875. //获取产品权限
  3876. productId := services.GetProductId(sysUser.RoleTypeCode)
  3877. if productId <= 0 {
  3878. br.Msg = "当前账号不允许修改客户信息"
  3879. return
  3880. }
  3881. companyNameIsExist, err := company.GetCompanyCountByCompanyNameAndCompanyId(req.CompanyId, req.CompanyName)
  3882. if err != nil {
  3883. br.Msg = "判断客户是否存在失败"
  3884. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  3885. return
  3886. }
  3887. if companyNameIsExist > 0 {
  3888. br.Msg = "客户已存在,请重新输入客户名称"
  3889. return
  3890. }
  3891. //判断客户是否已经存在
  3892. companyCreditCodeIsExist, err := company.GetCompanyCountByCreditCodeAndCompanyId(req.CompanyId, req.CreditCode)
  3893. if err != nil {
  3894. br.Msg = "判断客户是否存在失败"
  3895. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  3896. return
  3897. }
  3898. if companyCreditCodeIsExist > 0 {
  3899. br.Msg = "客户已存在,统一社会信用代码"
  3900. return
  3901. }
  3902. //查询该客户
  3903. companyItem, err := company.GetCompanyById(req.CompanyId)
  3904. if err != nil {
  3905. br.Msg = "查找客户失败"
  3906. br.ErrMsg = "查找客户失败,Err:" + err.Error()
  3907. return
  3908. }
  3909. //待更新字段
  3910. updateCol := make([]string, 0)
  3911. companyItem.CompanyName = req.CompanyName
  3912. companyItem.CreditCode = req.CreditCode
  3913. companyItem.Enabled = 1
  3914. companyItem.LastUpdatedTime = time.Now()
  3915. updateCol = append(updateCol, "CompanyName", "CreditCode", "Enabled", "LastUpdatedTime")
  3916. if req.Province != "" && req.City != "" {
  3917. companyItem.Province = req.Province
  3918. companyItem.City = req.City
  3919. companyItem.Address = req.Province + req.City
  3920. updateCol = append(updateCol, "Province", "City", "Address")
  3921. }
  3922. err = companyItem.Update(updateCol)
  3923. if err != nil {
  3924. br.Msg = "修改客户信息失败"
  3925. br.ErrMsg = "修改客户信息失败,Err:" + err.Error()
  3926. return
  3927. }
  3928. //查询并更新客户产品信息
  3929. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  3930. if err != nil {
  3931. if err.Error() != utils.ErrNoRow() {
  3932. br.Msg = "查询客户产品信息失败"
  3933. br.ErrMsg = "查询客户产品信息失败,Err:" + err.Error()
  3934. return
  3935. }
  3936. } else {
  3937. if companyProduct != nil {
  3938. //客户产品待更新字段
  3939. updateCompanyProductCol := make([]string, 0)
  3940. //产品信息(来源、行业)
  3941. if req.IndustryId != 0 && req.IndustryId != companyProduct.IndustryId {
  3942. companyProduct.IndustryId = req.IndustryId
  3943. companyProduct.IndustryName = req.IndustryName
  3944. updateCompanyProductCol = append(updateCompanyProductCol, "IndustryId", "IndustryName")
  3945. }
  3946. if req.Source != "" && req.Source != companyProduct.Source {
  3947. companyProduct.Source = req.Source
  3948. updateCompanyProductCol = append(updateCompanyProductCol, "Source")
  3949. }
  3950. //更新客户产品信息
  3951. if len(updateCompanyProductCol) > 0 {
  3952. err = companyProduct.Update(updateCompanyProductCol)
  3953. if err != nil {
  3954. br.Msg = "修改客户信息失败"
  3955. br.ErrMsg = "修改客户信息失败,Err:" + err.Error()
  3956. return
  3957. }
  3958. }
  3959. }
  3960. }
  3961. //新增客户日志
  3962. {
  3963. companyLog := new(company.CompanyLog)
  3964. companyLog.CompanyId = req.CompanyId
  3965. companyLog.CompanyName = req.CompanyName
  3966. companyLog.CreditCode = req.CreditCode
  3967. companyLog.Address = companyItem.Address
  3968. companyLog.City = companyItem.City
  3969. companyLog.Province = companyItem.Province
  3970. companyLog.LastUpdatedTime = companyItem.LastUpdatedTime
  3971. companyLog.AdminId = this.SysUser.AdminId
  3972. companyLog.LogType = "modify"
  3973. companyLog.LogCreateTime = time.Now()
  3974. go company.AddCompanyLog(companyLog)
  3975. }
  3976. br.Ret = 200
  3977. br.Success = true
  3978. br.Msg = "保存成功"
  3979. }
  3980. // @Title 客户模糊检索(新增/编辑客户页面试用)
  3981. // @Description 客户模糊检索接口(新增/编辑客户页面试用)
  3982. // @Param KeyWord query string true "搜索关键词"
  3983. // @Success 200 {object} company.CompanyFuzzySearchReq
  3984. // @router /fuzzy/search [get]
  3985. func (this *CompanyController) FuzzySearch() {
  3986. br := new(models.BaseResponse).Init()
  3987. defer func() {
  3988. this.Data["json"] = br
  3989. this.ServeJSON()
  3990. }()
  3991. keyWord := this.GetString("KeyWord")
  3992. list, err := company.GetCompanyFuzzySearch(keyWord)
  3993. if err != nil {
  3994. br.Msg = "获取信息失败"
  3995. br.ErrMsg = "获取信息失败,err:" + err.Error()
  3996. return
  3997. }
  3998. resp := new(company.CompanyFuzzySearchReq)
  3999. resp.List = list
  4000. br.Ret = 200
  4001. br.Success = true
  4002. br.Msg = "获取成功"
  4003. br.Data = resp
  4004. }
  4005. // @Title 删除客户
  4006. // @Description 删除客户接口
  4007. // @Param request body company.DeletePptReq true "type json string"
  4008. // @Success Ret=200 保存成功
  4009. // @router /delete [post]
  4010. func (this *CompanyController) Delete() {
  4011. br := new(models.BaseResponse).Init()
  4012. defer func() {
  4013. this.Data["json"] = br
  4014. this.ServeJSON()
  4015. }()
  4016. sysUser := this.SysUser
  4017. if sysUser == nil {
  4018. br.Msg = "请登录"
  4019. br.ErrMsg = "请登录,SysUser Is Empty"
  4020. br.Ret = 408
  4021. return
  4022. }
  4023. var req company.DeletePptReq
  4024. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4025. if err != nil {
  4026. br.Msg = "参数解析异常!"
  4027. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4028. return
  4029. }
  4030. if req.CompanyId <= 0 {
  4031. br.Msg = "参数错误"
  4032. br.ErrMsg = "客户ID小于等于0"
  4033. return
  4034. }
  4035. roleTypeCode := this.SysUser.RoleTypeCode
  4036. productId := services.GetProductId(roleTypeCode)
  4037. productItems, err := company.GetCompanyProductsByCompanyId(req.CompanyId)
  4038. if err != nil {
  4039. br.Msg = "删除失败"
  4040. br.ErrMsg = "获取客户产品信息失败,Err:" + err.Error()
  4041. return
  4042. }
  4043. // 备份信息
  4044. companyDeleteBakInfo := services.CompanyDeleteBakInfo{
  4045. CompanyId: req.CompanyId,
  4046. CompanyName: "",
  4047. CompanyInfo: &company.Company{},
  4048. CompanyProductInfo: make([]*company.CompanyProduct, 0),
  4049. CompanyPermissionInfo: make([]*company.CompanyReportPermission, 0),
  4050. UserSellerRelationInfo: make([]*models.UserSellerRelation, 0),
  4051. UserRecordInfo: make([]*models.UserRecord, 0),
  4052. UserInfo: make([]*models.WxUser, 0),
  4053. CompanyChartPermissionInfo: make([]*company_user.ChartClassifyPermission, 0),
  4054. OpUserId: this.SysUser.AdminId,
  4055. OpUserName: this.SysUser.RealName,
  4056. }
  4057. if productId == 0 {
  4058. for _, v := range productItems {
  4059. //永续,试用,流失,关闭
  4060. 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 {
  4061. br.Msg = "该客户" + v.ProductName + "属性为" + v.Status + ",暂不可删除"
  4062. br.ErrMsg = "该客户" + v.ProductName + "属性为" + v.Status + ",暂不可删除"
  4063. return
  4064. }
  4065. companyProductList, companyReportPermissionList, err := company.DeleteCompanyProductById(v.CompanyId, v.ProductId, v.CompanyProductId)
  4066. if err != nil {
  4067. br.Msg = "删除失败"
  4068. br.ErrMsg = "删除失败,Err:" + err.Error()
  4069. return
  4070. }
  4071. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductList...)
  4072. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissionList...)
  4073. //新增操作记录
  4074. {
  4075. record := new(company.CompanyOperationRecord)
  4076. record.CompanyId = req.CompanyId
  4077. record.CompanyName = v.CompanyName
  4078. record.SellerId = v.SellerId
  4079. record.SysUserId = this.SysUser.AdminId
  4080. record.SysRealName = this.SysUser.RealName
  4081. record.Remark = "删除客户"
  4082. record.Operation = "delete"
  4083. record.CreateTime = time.Now()
  4084. record.ProductId = v.ProductId
  4085. record.ProductName = v.ProductName
  4086. _, err = company.AddCompanyOperationRecord(record)
  4087. if err != nil {
  4088. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  4089. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  4090. }
  4091. }
  4092. //删除对应产品的联系人
  4093. userSellerRelationList, userRecordList, wxUserList, chartClassifyPermission, _ := services.DeleteCompanyWxUserByProductId(v.CompanyId, v.ProductId)
  4094. //备份信息
  4095. {
  4096. if companyProductList != nil {
  4097. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductList...)
  4098. }
  4099. if companyReportPermissionList != nil {
  4100. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissionList...)
  4101. }
  4102. if userSellerRelationList != nil {
  4103. companyDeleteBakInfo.UserSellerRelationInfo = append(companyDeleteBakInfo.UserSellerRelationInfo, userSellerRelationList...)
  4104. }
  4105. if userRecordList != nil {
  4106. companyDeleteBakInfo.UserRecordInfo = append(companyDeleteBakInfo.UserRecordInfo, userRecordList...)
  4107. }
  4108. if wxUserList != nil {
  4109. companyDeleteBakInfo.UserInfo = append(companyDeleteBakInfo.UserInfo, wxUserList...)
  4110. }
  4111. if chartClassifyPermission != nil {
  4112. companyDeleteBakInfo.CompanyChartPermissionInfo = append(companyDeleteBakInfo.CompanyChartPermissionInfo, chartClassifyPermission...)
  4113. }
  4114. companyDeleteBakInfo.CompanyName = v.CompanyName
  4115. }
  4116. }
  4117. } else {
  4118. productObj, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  4119. if err != nil {
  4120. br.ErrMsg = "获取客户产品信息失败,Err:" + err.Error()
  4121. br.Msg = "删除失败"
  4122. return
  4123. }
  4124. //永续,试用,流失,关闭
  4125. 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 {
  4126. br.Msg = "该客户" + productObj.ProductName + "属性为" + productObj.Status + ",暂不可删除"
  4127. br.ErrMsg = "该客户" + productObj.ProductName + "属性为" + productObj.Status + ",暂不可删除"
  4128. return
  4129. }
  4130. companyProductList, companyReportPermissionList, err := company.DeleteCompanyProductById(productObj.CompanyId, productObj.ProductId, productObj.CompanyProductId)
  4131. if err != nil {
  4132. br.Msg = "删除失败"
  4133. br.ErrMsg = "删除失败,Err:" + err.Error()
  4134. return
  4135. }
  4136. //新增操作记录
  4137. {
  4138. record := new(company.CompanyOperationRecord)
  4139. record.CompanyId = req.CompanyId
  4140. record.CompanyName = productObj.CompanyName
  4141. record.SellerId = productObj.SellerId
  4142. record.SysUserId = this.SysUser.AdminId
  4143. record.SysRealName = this.SysUser.RealName
  4144. record.Remark = "删除客户"
  4145. record.Operation = "delete"
  4146. record.CreateTime = time.Now()
  4147. record.ProductId = productObj.ProductId
  4148. record.ProductName = productObj.ProductName
  4149. _, err = company.AddCompanyOperationRecord(record)
  4150. if err != nil {
  4151. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  4152. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  4153. }
  4154. }
  4155. //删除对应产品的联系人
  4156. userSellerRelationList, userRecordList, wxUserList, chartClassifyPermission, _ := services.DeleteCompanyWxUserByProductId(productObj.CompanyId, productId)
  4157. //备份信息
  4158. {
  4159. if companyProductList != nil {
  4160. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductList...)
  4161. }
  4162. if companyReportPermissionList != nil {
  4163. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissionList...)
  4164. }
  4165. if userSellerRelationList != nil {
  4166. companyDeleteBakInfo.UserSellerRelationInfo = append(companyDeleteBakInfo.UserSellerRelationInfo, userSellerRelationList...)
  4167. }
  4168. if userRecordList != nil {
  4169. companyDeleteBakInfo.UserRecordInfo = append(companyDeleteBakInfo.UserRecordInfo, userRecordList...)
  4170. }
  4171. if wxUserList != nil {
  4172. companyDeleteBakInfo.UserInfo = append(companyDeleteBakInfo.UserInfo, wxUserList...)
  4173. }
  4174. if chartClassifyPermission != nil {
  4175. companyDeleteBakInfo.CompanyChartPermissionInfo = append(companyDeleteBakInfo.CompanyChartPermissionInfo, chartClassifyPermission...)
  4176. }
  4177. companyDeleteBakInfo.CompanyName = productObj.CompanyName
  4178. }
  4179. }
  4180. productItemsNew, err := company.GetCompanyProductsByCompanyId(req.CompanyId)
  4181. if err != nil {
  4182. br.Msg = "删除失败"
  4183. br.ErrMsg = "获取客户产品信息失败,Err:" + err.Error()
  4184. return
  4185. }
  4186. if len(productItemsNew) == 0 {
  4187. //删除之前查询的数据信息
  4188. {
  4189. companyProductLists, companyReportPermissions, wxUsers, userSellerRelations, companyContracts, companyContractPermissions, companyInfo, _ := services.GetBeforeDeleteCompanyInfo(req.CompanyId)
  4190. //companyDeleteBakInfo
  4191. if companyProductLists != nil {
  4192. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductLists...)
  4193. }
  4194. if companyReportPermissions != nil {
  4195. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissions...)
  4196. }
  4197. if wxUsers != nil {
  4198. companyDeleteBakInfo.UserInfo = append(companyDeleteBakInfo.UserInfo, wxUsers...)
  4199. }
  4200. if userSellerRelations != nil {
  4201. companyDeleteBakInfo.UserSellerRelationInfo = append(companyDeleteBakInfo.UserSellerRelationInfo, userSellerRelations...)
  4202. }
  4203. if companyContracts != nil {
  4204. companyDeleteBakInfo.CompanyContract = append(companyDeleteBakInfo.CompanyContract, companyContracts...)
  4205. }
  4206. if companyContractPermissions != nil {
  4207. companyDeleteBakInfo.CompanyContractPermission = append(companyDeleteBakInfo.CompanyContractPermission, companyContractPermissions...)
  4208. }
  4209. if companyInfo != nil {
  4210. companyDeleteBakInfo.CompanyName = companyInfo.CompanyName
  4211. companyDeleteBakInfo.CompanyInfo = companyInfo
  4212. }
  4213. }
  4214. err = company.DeleteCompanyById(req.CompanyId)
  4215. if err != nil {
  4216. br.Msg = "删除失败"
  4217. br.ErrMsg = "删除失败,Err:" + err.Error()
  4218. return
  4219. }
  4220. for _, v := range productItems {
  4221. //新增操作记录
  4222. {
  4223. record := new(company.CompanyOperationRecord)
  4224. record.CompanyId = req.CompanyId
  4225. record.CompanyName = v.CompanyName
  4226. record.SellerId = v.SellerId
  4227. record.SysUserId = this.SysUser.AdminId
  4228. record.SysRealName = this.SysUser.RealName
  4229. record.Remark = "删除客户"
  4230. record.Operation = "delete"
  4231. record.CreateTime = time.Now()
  4232. record.ProductId = v.ProductId
  4233. record.ProductName = v.ProductName
  4234. _, err = company.AddCompanyOperationRecord(record)
  4235. if err != nil {
  4236. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  4237. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  4238. }
  4239. }
  4240. }
  4241. }
  4242. //数据备份入库
  4243. {
  4244. companyInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyInfo)
  4245. companyProductInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyProductInfo)
  4246. companyPermissionInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyPermissionInfo)
  4247. userSellerRelationInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.UserSellerRelationInfo)
  4248. userRecordInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.UserRecordInfo)
  4249. userInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.UserInfo)
  4250. companyChartPermissionInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyChartPermissionInfo)
  4251. companyContractByte, _ := json.Marshal(companyDeleteBakInfo.CompanyContract)
  4252. companyContractPermissionJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyContractPermission)
  4253. companyDeleteBak := &company.CompanyDeleteBak{
  4254. //DeleteBakId: 0,
  4255. CompanyId: companyDeleteBakInfo.CompanyId,
  4256. CompanyName: companyDeleteBakInfo.CompanyName,
  4257. CompanyInfo: string(companyInfoJsonByte),
  4258. CompanyProductInfo: string(companyProductInfoJsonByte),
  4259. CompanyPermissionInfo: string(companyPermissionInfoJsonByte),
  4260. UserSellerRelationInfo: string(userSellerRelationInfoJsonByte),
  4261. UserRecordInfo: string(userRecordInfoJsonByte),
  4262. UserInfo: string(userInfoJsonByte),
  4263. CompanyChartPermissionInfo: string(companyChartPermissionInfoJsonByte),
  4264. CompanyContractInfo: string(companyContractByte),
  4265. CompanyContractPermissionInfo: string(companyContractPermissionJsonByte),
  4266. OpUserId: this.SysUser.AdminId,
  4267. OpUserName: this.SysUser.RealName,
  4268. CreateTime: time.Now(),
  4269. }
  4270. _ = company.AddCompanyDeleteBak(companyDeleteBak)
  4271. }
  4272. br.Ret = 200
  4273. br.Success = true
  4274. br.Msg = "删除成功"
  4275. }
  4276. // @Title 领取客户列表
  4277. // @Description 领取客户列表接口
  4278. // @Param PageSize query int true "每页数据条数"
  4279. // @Param CurrentIndex query int true "当前页页码,从1开始"
  4280. // @Param StartDate query string true "开始时间"
  4281. // @Param EndDate query string true "结束时间"
  4282. // @Param KeyWord query string true "搜索关键词"
  4283. // @Success 200 {object} company.CompanyReceiveListResp
  4284. // @router /receive/list [get]
  4285. func (this *CompanyController) ReceiveList() {
  4286. br := new(models.BaseResponse).Init()
  4287. defer func() {
  4288. this.Data["json"] = br
  4289. this.ServeJSON()
  4290. }()
  4291. sysUser := this.SysUser
  4292. if sysUser == nil {
  4293. br.Msg = "请登录"
  4294. br.ErrMsg = "请登录,SysUser Is Empty"
  4295. br.Ret = 408
  4296. return
  4297. }
  4298. var productId, recevieProductId int
  4299. roleTypeCode := sysUser.RoleTypeCode
  4300. productId = services.GetProductId(roleTypeCode)
  4301. if productId == 1 {
  4302. recevieProductId = 2
  4303. } else if productId == 2 {
  4304. recevieProductId = 1
  4305. }
  4306. if productId == 0 {
  4307. br.Msg = "参数错误"
  4308. br.ErrMsg = "客户类型为:" + roleTypeCode
  4309. return
  4310. }
  4311. pageSize, _ := this.GetInt("PageSize")
  4312. currentIndex, _ := this.GetInt("CurrentIndex")
  4313. adminId := this.GetString("AdminId")
  4314. startDate := this.GetString("StartDate")
  4315. endDate := this.GetString("EndDate")
  4316. keyWord := this.GetString("KeyWord")
  4317. var startSize int
  4318. if pageSize <= 0 {
  4319. pageSize = utils.PageSize20
  4320. }
  4321. if currentIndex <= 0 {
  4322. currentIndex = 1
  4323. }
  4324. startSize = paging.StartIndex(currentIndex, pageSize)
  4325. var condition string
  4326. var pars []interface{}
  4327. if adminId != "" {
  4328. condition += ` AND c.seller_id IN (` + adminId + `) `
  4329. }
  4330. if startDate != "" {
  4331. condition += ` AND c.start_date>=? `
  4332. pars = append(pars, startDate)
  4333. }
  4334. if endDate != "" {
  4335. condition += ` AND c.end_date>=? `
  4336. pars = append(pars, endDate)
  4337. }
  4338. if keyWord != "" {
  4339. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR b.mobile LIKE '%` + keyWord + `%' OR b.email LIKE '%` + keyWord + `%') `
  4340. }
  4341. total, err := company.GetCompanyReceiveListCount(condition, pars, productId, recevieProductId)
  4342. if err != nil {
  4343. br.Msg = "获取失败"
  4344. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  4345. return
  4346. }
  4347. list, err := company.GetCompanyReceiveList(condition, pars, productId, recevieProductId, startSize, pageSize)
  4348. if err != nil {
  4349. br.Msg = "获取失败"
  4350. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  4351. return
  4352. }
  4353. lenList := len(list)
  4354. for i := 0; i < lenList; i++ {
  4355. item := list[i]
  4356. var expireDay string
  4357. if item.Status != "" {
  4358. status := item.Status
  4359. if item.EndDate != "" {
  4360. if status == utils.COMPANY_STATUS_FOREVER { //永续
  4361. expireDay = "-"
  4362. } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用/正式
  4363. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  4364. sub := endDateTime.Sub(time.Now())
  4365. expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  4366. } else if status == utils.COMPANY_STATUS_LOSE { //流失
  4367. expireDay = "-"
  4368. } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  4369. if item.StartDate != "" && item.EndDate != "" {
  4370. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  4371. sub := endDateTime.Sub(time.Now())
  4372. expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  4373. } else {
  4374. expireDay = "-"
  4375. }
  4376. } else {
  4377. expireDay = "-"
  4378. }
  4379. }
  4380. }
  4381. list[i].ExpireDay = expireDay
  4382. }
  4383. page := paging.GetPaging(currentIndex, pageSize, total)
  4384. resp := new(company.CompanyReceiveListResp)
  4385. resp.List = list
  4386. resp.Paging = page
  4387. br.Ret = 200
  4388. br.Success = true
  4389. br.Msg = "获取成功"
  4390. br.Data = resp
  4391. }
  4392. // @Title 领取客户
  4393. // @Description 领取客户接口
  4394. // @Param request body company.CompanyReceiveReq true "type json string"
  4395. // @Success Ret=200 领取成功
  4396. // @router /receive [post]
  4397. func (this *CompanyController) Receive() {
  4398. br := new(models.BaseResponse).Init()
  4399. defer func() {
  4400. this.Data["json"] = br
  4401. this.ServeJSON()
  4402. }()
  4403. sysUser := this.SysUser
  4404. if sysUser == nil {
  4405. br.Msg = "请登录"
  4406. br.ErrMsg = "请登录,SysUser Is Empty"
  4407. br.Ret = 408
  4408. return
  4409. }
  4410. var req company.CompanyReceiveReq
  4411. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4412. if err != nil {
  4413. br.Msg = "参数解析异常!"
  4414. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4415. return
  4416. }
  4417. if req.CompanyId <= 0 {
  4418. br.Msg = "参数异常!"
  4419. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  4420. return
  4421. }
  4422. //权益主观客观权限一块开
  4423. if req.PermissionIds != "" {
  4424. permissionStr, err := company.GetPermissionIdById(req.PermissionIds)
  4425. if err != nil {
  4426. br.Msg = "获取信息失败"
  4427. br.ErrMsg = "获取主观客观权限信息失败,Err:" + err.Error()
  4428. return
  4429. }
  4430. req.PermissionIds = permissionStr
  4431. }
  4432. roleTypeCode := sysUser.RoleTypeCode
  4433. productId := services.GetProductId(roleTypeCode)
  4434. if productId == 0 {
  4435. br.Msg = "参数错误"
  4436. br.ErrMsg = "客户类型为:" + roleTypeCode
  4437. return
  4438. }
  4439. sellsId := 0
  4440. if req.SellsId <= 0 {
  4441. sellsId = sysUser.AdminId
  4442. } else {
  4443. sellsId = req.SellsId
  4444. }
  4445. seller, err := system.GetSysAdminById(sellsId)
  4446. if err != nil {
  4447. br.Msg = "获取销售信息失败"
  4448. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  4449. return
  4450. }
  4451. companyDetail, err := company.GetCompanyDetailById(req.CompanyId)
  4452. if err != nil {
  4453. br.Msg = "获取客户信息失败"
  4454. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  4455. return
  4456. }
  4457. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  4458. if err != nil && err.Error() != utils.ErrNoRow() {
  4459. br.Msg = "获取客户信息失败"
  4460. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  4461. return
  4462. }
  4463. productName := ""
  4464. var status string
  4465. if productId == 1 {
  4466. productName = utils.COMPANY_PRODUCT_FICC_NAME
  4467. } else {
  4468. productName = utils.COMPANY_PRODUCT_RAI_NAME
  4469. }
  4470. if cp != nil {
  4471. if cp.Status != utils.COMPANY_STATUS_LOSE {
  4472. br.Msg = "客户状态为:" + cp.Status + ";不可领取"
  4473. br.ErrMsg = "客户状态为:" + cp.Status + ";不可领取"
  4474. return
  4475. }
  4476. if cp.SellerId == sysUser.AdminId {
  4477. br.Msg = "已为自己客户,不可重复领取"
  4478. br.ErrMsg = "已为自己客户,不可领取:company_id:" + strconv.Itoa(cp.CompanyId)
  4479. return
  4480. }
  4481. //转移 销售
  4482. companyReportPermissionList, startDate, endDate, err := company.MoveSeller(req.CompanyId, productId, seller.AdminId, seller.GroupId, seller.DepartmentId, seller.RealName)
  4483. if err != nil {
  4484. br.Msg = "领取失败"
  4485. br.ErrMsg = "领取失败,Err:" + err.Error()
  4486. return
  4487. }
  4488. //新增客户产品状态变更日志
  4489. {
  4490. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  4491. Id: 0,
  4492. CompanyId: req.CompanyId,
  4493. ProductId: productId,
  4494. Status: "试用",
  4495. Source: "receive",
  4496. SellerId: seller.AdminId,
  4497. SellerName: seller.RealName,
  4498. StartDate: startDate,
  4499. EndDate: endDate,
  4500. RealEndDate: startDate,
  4501. CreateTime: time.Now(),
  4502. }
  4503. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  4504. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  4505. Id: 0,
  4506. CompanyId: req.CompanyId,
  4507. ProductId: productId,
  4508. Source: "receive",
  4509. SellerId: seller.AdminId,
  4510. SellerName: seller.RealName,
  4511. StartDate: startDate,
  4512. EndDate: endDate,
  4513. RealEndDate: startDate,
  4514. IsStop: 0,
  4515. CreateTime: time.Now(),
  4516. }
  4517. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  4518. }
  4519. } else {
  4520. //跨部门领取
  4521. var startDateTime, endDateTime time.Time
  4522. if req.Status == utils.COMPANY_STATUS_TRY_OUT {
  4523. startDateTime = time.Now()
  4524. endDateTime = time.Now().AddDate(0, 2, 0)
  4525. } else if req.Status == utils.COMPANY_STATUS_FOREVER {
  4526. startDateTime = time.Now()
  4527. endDateTime = time.Now().AddDate(100, 0, 0)
  4528. } else {
  4529. br.Msg = "无效的客户状态,请重新选择"
  4530. return
  4531. }
  4532. var startDate, endDate string
  4533. startDate = startDateTime.Format(utils.FormatDate)
  4534. endDate = endDateTime.Format(utils.FormatDate)
  4535. if req.PermissionIds == "" {
  4536. br.Msg = "请选择权限!"
  4537. return
  4538. }
  4539. industry, err := company.GetCompanyIndustryById(req.IndustryId)
  4540. if err != nil {
  4541. br.Msg = "获取行业信息失败"
  4542. br.ErrMsg = "获取行业信息失败,Err:" + err.Error()
  4543. return
  4544. }
  4545. if industry == nil {
  4546. br.Msg = "行业信息不存在"
  4547. return
  4548. }
  4549. status = req.Status
  4550. companyProduct := new(company.CompanyProduct)
  4551. companyProduct.CompanyId = req.CompanyId
  4552. companyProduct.ProductId = productId
  4553. companyProduct.ProductName = productName
  4554. companyProduct.CompanyName = companyDetail.CompanyName
  4555. companyProduct.Source = req.Source
  4556. companyProduct.Reasons = req.Reasons
  4557. companyProduct.Status = status
  4558. companyProduct.StartDate = startDate
  4559. companyProduct.EndDate = endDate
  4560. companyProduct.IndustryId = req.IndustryId
  4561. companyProduct.IndustryName = industry.IndustryName
  4562. companyProduct.SellerId = seller.AdminId
  4563. companyProduct.SellerName = seller.RealName
  4564. companyProduct.GroupId = seller.GroupId
  4565. companyProduct.DepartmentId = seller.DepartmentId
  4566. companyProduct.IsSuspend = 0
  4567. companyProduct.CreateTime = time.Now()
  4568. companyProduct.ModifyTime = time.Now()
  4569. companyProduct.CompanyType = req.CompanyType
  4570. companyProduct.OpenCode = services.GenerateOpenCompanyProductCode(req.CompanyId, productId)
  4571. companyProduct.TodoStatus = "无任务"
  4572. companyProduct.TryStage = 1
  4573. _, err = company.AddCompanyProduct(companyProduct)
  4574. if err != nil {
  4575. br.Msg = "新增失败"
  4576. br.ErrMsg = "新增客户产品失败,err:" + err.Error()
  4577. return
  4578. }
  4579. companyReportPermissionList, err := services.AddCompanyPermission(req.CompanyId, seller.AdminId, productId, productName, seller.RealName, req.PermissionIds, startDate, endDate)
  4580. if err != nil {
  4581. br.Msg = "新增失败"
  4582. br.ErrMsg = "新增客户设置权限失败,err:" + err.Error()
  4583. return
  4584. }
  4585. //新增客户产品日志
  4586. {
  4587. go services.AddCompanyProductLog(companyProduct, this.SysUser.AdminId, "add")
  4588. }
  4589. //新增客户产品状态变更日志
  4590. {
  4591. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  4592. Id: 0,
  4593. CompanyId: companyProduct.CompanyId,
  4594. ProductId: companyProduct.ProductId,
  4595. Status: "试用",
  4596. SellerId: seller.AdminId,
  4597. SellerName: seller.RealName,
  4598. Source: "add",
  4599. StartDate: startDateTime,
  4600. EndDate: endDateTime,
  4601. RealEndDate: startDateTime,
  4602. CreateTime: time.Now(),
  4603. }
  4604. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  4605. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  4606. Id: 0,
  4607. CompanyId: companyProduct.CompanyId,
  4608. ProductId: companyProduct.ProductId,
  4609. SellerId: seller.AdminId,
  4610. SellerName: seller.RealName,
  4611. Source: "add",
  4612. StartDate: startDateTime,
  4613. EndDate: endDateTime,
  4614. RealEndDate: startDateTime,
  4615. IsStop: 0,
  4616. CreateTime: time.Now(),
  4617. }
  4618. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  4619. }
  4620. //查询当前客户的所有产品的列表数据,并找出非当前产品的销售去发送模板消息
  4621. companyProductList, err := company.GetCompanyProductsByCompanyId(req.CompanyId)
  4622. for _, companyProduct := range companyProductList {
  4623. //如果是当前领取的产品,那么就退出当前循环,进入下一循环
  4624. if companyProduct.ProductId == productId {
  4625. continue
  4626. }
  4627. //查询其他部门销售的信息
  4628. admin, tmpErr := system.GetSysAdminById(companyProduct.SellerId)
  4629. if tmpErr != nil {
  4630. continue
  4631. }
  4632. //发送模板消息给另一个部门的销售
  4633. go services.SendCompanyReceiveWxTemplateMsg(companyDetail.CompanyName, productName, sysUser.RealName, admin.Mobile)
  4634. }
  4635. }
  4636. //新增操作记录
  4637. {
  4638. remark := "领取客户"
  4639. operation := "receive"
  4640. services.AddCompanyOperationRecord(req.CompanyId, seller.AdminId, sysUser.AdminId, productId, sysUser.AdminId, companyDetail.CompanyName,
  4641. productName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", status)
  4642. }
  4643. br.Ret = 200
  4644. br.Success = true
  4645. br.Msg = "领取成功"
  4646. }
  4647. // @Title 移动销售
  4648. // @Description 移动销售接口
  4649. // @Param request body company.MoveSellerReq true "type json string"
  4650. // @Success Ret=200 移动成功
  4651. // @router /move/seller [post]
  4652. func (this *CompanyController) MoveSeller() {
  4653. br := new(models.BaseResponse).Init()
  4654. defer func() {
  4655. this.Data["json"] = br
  4656. this.ServeJSON()
  4657. }()
  4658. sysUser := this.SysUser
  4659. if sysUser == nil {
  4660. br.Msg = "请登录"
  4661. br.ErrMsg = "请登录,SysUser Is Empty"
  4662. br.Ret = 408
  4663. return
  4664. }
  4665. var req company.MoveSellerReq
  4666. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4667. if err != nil {
  4668. br.Msg = "参数解析异常!"
  4669. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4670. return
  4671. }
  4672. if req.CompanyId <= 0 {
  4673. br.Msg = "参数异常!"
  4674. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  4675. return
  4676. }
  4677. if req.SellsId <= 0 {
  4678. br.Msg = "参数异常!"
  4679. br.ErrMsg = "SellsId:" + strconv.Itoa(req.SellsId)
  4680. return
  4681. }
  4682. seller, err := system.GetSysAdminById(req.SellsId)
  4683. if err != nil {
  4684. br.Msg = "获取销售信息失败"
  4685. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  4686. return
  4687. }
  4688. roleTypeCode := sysUser.RoleTypeCode
  4689. productId := services.GetProductId(roleTypeCode)
  4690. if productId == 0 {
  4691. if req.CompanyType == utils.COMPANY_CLASSIFY_FICC {
  4692. productId = 1
  4693. } else if req.CompanyType == utils.COMPANY_CLASSIFY_RAI {
  4694. productId = 2
  4695. }
  4696. }
  4697. if productId == 0 {
  4698. br.Msg = "无效的客户类型"
  4699. br.ErrMsg = "无效的客户类型"
  4700. return
  4701. }
  4702. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  4703. if err != nil && err.Error() != utils.ErrNoRow() {
  4704. if err.Error() == utils.ErrNoRow() {
  4705. br.Msg = "客户信息不存在"
  4706. br.ErrMsg = "客户信息不存在,Err:" + err.Error()
  4707. return
  4708. }
  4709. br.Msg = "获取客户信息失败"
  4710. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  4711. return
  4712. }
  4713. fmt.Println(cp)
  4714. if cp == nil {
  4715. br.Msg = "客户信息不存在,请刷新页面"
  4716. br.ErrMsg = "客户信息不存在"
  4717. return
  4718. }
  4719. err = company.MoveCompanySeller(req.CompanyId, productId, req.SellsId, seller.GroupId, seller.DepartmentId, seller.RealName)
  4720. if err != nil {
  4721. br.Msg = "移动失败"
  4722. br.ErrMsg = "移动失败,Err:" + err.Error()
  4723. return
  4724. }
  4725. //新增操作记录
  4726. {
  4727. remark := "移动到:" + seller.RealName
  4728. operation := "move_seller"
  4729. services.AddCompanyOperationRecord(req.CompanyId, seller.AdminId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
  4730. cp.ProductName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
  4731. }
  4732. //变更销售员与联系人关系
  4733. _ = models.UpdateUserSellerRelationByCompanyId(req.CompanyId, productId, seller.AdminId, seller.RealName)
  4734. br.Ret = 200
  4735. br.Success = true
  4736. br.Msg = "移动成功"
  4737. }
  4738. // @Title 修改试用客户标签
  4739. // @Description 修改试用客户标签接口
  4740. // @Param request body company.UpdateTryStageReq true "type json string"
  4741. // @Success Ret=200 设置成功
  4742. // @router /update/tryStage [post]
  4743. func (this *CompanyController) UpdateTryStage() {
  4744. br := new(models.BaseResponse).Init()
  4745. defer func() {
  4746. this.Data["json"] = br
  4747. this.ServeJSON()
  4748. }()
  4749. sysUser := this.SysUser
  4750. if sysUser == nil {
  4751. br.Msg = "请登录"
  4752. br.ErrMsg = "请登录,SysUser Is Empty"
  4753. br.Ret = 408
  4754. return
  4755. }
  4756. var req company.UpdateTryStageReq
  4757. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4758. if err != nil {
  4759. br.Msg = "参数解析异常!"
  4760. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4761. return
  4762. }
  4763. if req.CompanyId <= 0 {
  4764. br.Msg = "参数异常!"
  4765. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  4766. return
  4767. }
  4768. if req.ProductId <= 0 {
  4769. br.Msg = "参数异常!"
  4770. br.ErrMsg = "ProductId:" + strconv.Itoa(req.ProductId)
  4771. return
  4772. }
  4773. if req.TryStage <= 0 {
  4774. br.Msg = "参数异常!"
  4775. br.ErrMsg = "TryStage:" + strconv.Itoa(req.TryStage)
  4776. return
  4777. }
  4778. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  4779. if err != nil && err.Error() != utils.ErrNoRow() {
  4780. if err.Error() == utils.ErrNoRow() {
  4781. br.Msg = "客户信息不存在"
  4782. br.ErrMsg = "客户信息不存在,Err:" + err.Error()
  4783. return
  4784. }
  4785. br.Msg = "获取客户信息失败"
  4786. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  4787. return
  4788. }
  4789. fmt.Println(cp)
  4790. if cp == nil {
  4791. br.Msg = "客户信息不存在,请刷新页面"
  4792. br.ErrMsg = "客户信息不存在"
  4793. return
  4794. }
  4795. if cp.Status != "试用" {
  4796. br.Msg = "客户不是试用状态,不允许修改"
  4797. br.ErrMsg = "客户不是试用状态,不允许修改"
  4798. return
  4799. }
  4800. if cp.SellerId != sysUser.AdminId {
  4801. br.Msg = "无修改权限"
  4802. br.ErrMsg = "无修改权限"
  4803. return
  4804. }
  4805. if cp.TryStage == req.TryStage {
  4806. br.Msg = "与原标签一致,无需修改"
  4807. br.ErrMsg = "与原标签一致,无需修改"
  4808. return
  4809. }
  4810. err = company.UpdateCompanyTryStage(req.CompanyId, req.ProductId, req.TryStage)
  4811. if err != nil {
  4812. br.Msg = "设置失败"
  4813. br.ErrMsg = "设置失败,Err:" + err.Error()
  4814. return
  4815. }
  4816. //新增操作记录
  4817. {
  4818. stage := ""
  4819. tryStageAllMap := map[int]string{
  4820. 1: "未分类",
  4821. 2: "推进",
  4822. 3: "跟踪",
  4823. 4: "预备",
  4824. }
  4825. if v, ok := tryStageAllMap[req.TryStage]; ok {
  4826. stage = v
  4827. }
  4828. remark := "修改试用客户子标签:" + stage
  4829. operation := "UpdateTryStage"
  4830. services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  4831. cp.ProductName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
  4832. }
  4833. br.Ret = 200
  4834. br.Success = true
  4835. br.Msg = "设置成功"
  4836. }
  4837. // @Title 暂停/启用
  4838. // @Description 暂停/启用接口
  4839. // @Param request body company.SuspendReq true "type json string"
  4840. // @Success Ret=200 移动成功
  4841. // @router /suspend [post]
  4842. func (this *CompanyController) Suspend() {
  4843. br := new(models.BaseResponse).Init()
  4844. defer func() {
  4845. this.Data["json"] = br
  4846. this.ServeJSON()
  4847. }()
  4848. sysUser := this.SysUser
  4849. if sysUser == nil {
  4850. br.Msg = "请登录"
  4851. br.ErrMsg = "请登录,SysUser Is Empty"
  4852. br.Ret = 408
  4853. return
  4854. }
  4855. var req company.SuspendReq
  4856. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4857. if err != nil {
  4858. br.Msg = "参数解析异常!"
  4859. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4860. return
  4861. }
  4862. if req.CompanyId <= 0 {
  4863. br.Msg = "参数异常!"
  4864. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  4865. return
  4866. }
  4867. roleTypeCode := sysUser.RoleTypeCode
  4868. productId := services.GetProductId(roleTypeCode)
  4869. if productId == 0 {
  4870. br.Msg = "参数错误"
  4871. br.ErrMsg = "角色类型为:" + roleTypeCode
  4872. return
  4873. }
  4874. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  4875. if err != nil {
  4876. br.Msg = "获取数据异常!"
  4877. br.ErrMsg = "获取数据异常:" + err.Error()
  4878. return
  4879. }
  4880. suspendStatus := ""
  4881. suspend := 0
  4882. if cp.IsSuspend == 1 {
  4883. suspendStatus = "启用"
  4884. suspend = 0
  4885. } else {
  4886. suspendStatus = "暂停"
  4887. suspend = 1
  4888. }
  4889. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  4890. br.Msg = "客户状态为:" + cp.Status + ",不允许进行" + suspendStatus + "操作"
  4891. br.ErrMsg = "客户状态为:" + cp.Status + ",不允许进行" + suspendStatus + "操作"
  4892. return
  4893. }
  4894. err = company.SuspendCompanyProductById(req.CompanyId, productId, suspend)
  4895. if err != nil {
  4896. br.Msg = suspendStatus + "失败"
  4897. br.ErrMsg = suspendStatus + "失败 Err:" + err.Error()
  4898. return
  4899. }
  4900. //新增操作记录
  4901. {
  4902. remark := suspendStatus
  4903. operation := "is_suspend"
  4904. services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
  4905. cp.ProductName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
  4906. }
  4907. br.Ret = 200
  4908. br.Success = true
  4909. br.Msg = suspendStatus + "成功"
  4910. }
  4911. // @Title 检测客户名称或社会信用码
  4912. // @Description 检测客户名称或社会信用码接口(新增/编辑客户页面使用)
  4913. // @Param CompanyName query string true "客户名称"
  4914. // @Param CreditCode query string true "社会统一信用码"
  4915. // @Success 200 {object} company.CheckCompanyInfoResp
  4916. // @router /check/companyInfo [get]
  4917. func (this *CompanyController) CheckCompanyInfo() {
  4918. br := new(models.BaseResponse).Init()
  4919. defer func() {
  4920. this.Data["json"] = br
  4921. this.ServeJSON()
  4922. }()
  4923. sysUser := this.SysUser
  4924. if sysUser == nil {
  4925. br.Msg = "请登录"
  4926. br.ErrMsg = "请登录,SysUser Is Empty"
  4927. br.Ret = 408
  4928. return
  4929. }
  4930. roleTypeCode := sysUser.RoleTypeCode
  4931. productId := services.GetProductId(roleTypeCode)
  4932. companyName := this.GetString("CompanyName")
  4933. creditCode := this.GetString("CreditCode")
  4934. var status, comanyId int
  4935. var productName string
  4936. if productId == 0 {
  4937. productId = 1
  4938. checkProductId := 2
  4939. if companyName != "" {
  4940. nameItem, err := company.CheckCompanyProductByName(companyName, productId)
  4941. if err != nil && err.Error() != utils.ErrNoRow() {
  4942. br.Msg = "校验客户名称是否存在失败"
  4943. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
  4944. return
  4945. }
  4946. if nameItem != nil && nameItem.CompanyId > 0 {
  4947. br.Msg = "客户名称已存在,请重新填写"
  4948. br.ErrMsg = "客户名称已存在,请重新填写"
  4949. br.Ret = 405
  4950. return
  4951. }
  4952. nameCheckItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
  4953. if err != nil && err.Error() != utils.ErrNoRow() {
  4954. br.Msg = "校验客户名称是否存在失败"
  4955. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  4956. return
  4957. }
  4958. if nameCheckItem != nil && nameCheckItem.CompanyId > 0 {
  4959. status = 1
  4960. productName = nameCheckItem.ProductName
  4961. comanyId = nameCheckItem.CompanyId
  4962. goto Loop
  4963. }
  4964. }
  4965. if creditCode != "" {
  4966. codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
  4967. if err != nil && err.Error() != utils.ErrNoRow() {
  4968. br.Msg = "校验社会信用码是否存在失败"
  4969. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
  4970. return
  4971. }
  4972. if codeItem != nil && codeItem.CompanyId > 0 {
  4973. br.Msg = "社会信用码已存在,请重新填写"
  4974. br.ErrMsg = "社会信用码已存在,请重新填写"
  4975. br.Ret = 405
  4976. return
  4977. }
  4978. codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
  4979. if err != nil && err.Error() != utils.ErrNoRow() {
  4980. br.Msg = "校验社会信用码是否存在失败"
  4981. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  4982. return
  4983. }
  4984. if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
  4985. status = 1
  4986. productName = codeCheckItem.ProductName
  4987. comanyId = codeCheckItem.CompanyId
  4988. goto Loop
  4989. }
  4990. }
  4991. productId = 2
  4992. checkProductId = 1
  4993. if companyName != "" {
  4994. nameItem, err := company.CheckCompanyProductByName(companyName, productId)
  4995. if err != nil && err.Error() != utils.ErrNoRow() {
  4996. br.Msg = "校验客户名称是否存在失败"
  4997. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
  4998. return
  4999. }
  5000. if nameItem != nil && nameItem.CompanyId > 0 {
  5001. br.Msg = "客户名称已存在,请重新填写"
  5002. br.ErrMsg = "客户名称已存在,请重新填写"
  5003. br.Ret = 405
  5004. return
  5005. }
  5006. nameCheckItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
  5007. if err != nil && err.Error() != utils.ErrNoRow() {
  5008. br.Msg = "校验客户名称是否存在失败"
  5009. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5010. return
  5011. }
  5012. if nameCheckItem != nil && nameCheckItem.CompanyId > 0 {
  5013. status = 1
  5014. productName = nameCheckItem.ProductName
  5015. comanyId = nameCheckItem.CompanyId
  5016. goto Loop
  5017. }
  5018. }
  5019. if creditCode != "" {
  5020. codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
  5021. if err != nil && err.Error() != utils.ErrNoRow() {
  5022. br.Msg = "校验社会信用码是否存在失败"
  5023. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
  5024. return
  5025. }
  5026. if codeItem != nil && codeItem.CompanyId > 0 {
  5027. br.Msg = "社会信用码已存在,请重新填写"
  5028. br.ErrMsg = "社会信用码已存在,请重新填写"
  5029. br.Ret = 405
  5030. return
  5031. }
  5032. codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
  5033. if err != nil && err.Error() != utils.ErrNoRow() {
  5034. br.Msg = "校验社会信用码是否存在失败"
  5035. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5036. return
  5037. }
  5038. if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
  5039. status = 1
  5040. productName = codeCheckItem.ProductName
  5041. comanyId = codeCheckItem.CompanyId
  5042. goto Loop
  5043. }
  5044. }
  5045. } else {
  5046. checkProductId := 0
  5047. if productId == 1 {
  5048. checkProductId = 2
  5049. } else if productId == 2 {
  5050. checkProductId = 1
  5051. }
  5052. if companyName != "" {
  5053. nameItem, err := company.CheckCompanyProductByName(companyName, productId)
  5054. if err != nil && err.Error() != utils.ErrNoRow() {
  5055. br.Msg = "校验客户名称是否存在失败"
  5056. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
  5057. return
  5058. }
  5059. if nameItem != nil && nameItem.ProductName != "" {
  5060. br.Msg = "客户名称已存在,请重新填写"
  5061. br.ErrMsg = "客户名称已存在,请重新填写"
  5062. br.Ret = 405
  5063. return
  5064. }
  5065. nameCheckoutItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
  5066. if err != nil && err.Error() != utils.ErrNoRow() {
  5067. br.Msg = "校验客户名称是否存在失败"
  5068. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5069. return
  5070. }
  5071. if nameCheckoutItem != nil && nameCheckoutItem.CompanyId > 0 {
  5072. status = 1
  5073. productName = nameCheckoutItem.ProductName
  5074. comanyId = nameCheckoutItem.CompanyId
  5075. goto Loop
  5076. }
  5077. }
  5078. if creditCode != "" {
  5079. codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
  5080. if err != nil && err.Error() != utils.ErrNoRow() {
  5081. br.Msg = "校验社会信用码是否存在失败"
  5082. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
  5083. return
  5084. }
  5085. if codeItem != nil && codeItem.CompanyId > 0 {
  5086. br.Msg = "社会信用码已存在,请重新填写"
  5087. br.ErrMsg = "社会信用码已存在,请重新填写"
  5088. br.Ret = 405
  5089. return
  5090. }
  5091. codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
  5092. if err != nil && err.Error() != utils.ErrNoRow() {
  5093. br.Msg = "校验社会信用码是否存在失败"
  5094. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5095. return
  5096. }
  5097. if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
  5098. status = 1
  5099. productName = codeCheckItem.ProductName
  5100. comanyId = codeCheckItem.CompanyId
  5101. goto Loop
  5102. }
  5103. }
  5104. }
  5105. Loop:
  5106. resp := new(company.CheckCompanyInfoResp)
  5107. resp.Status = status
  5108. resp.ProductName = productName
  5109. resp.CompanyId = comanyId
  5110. br.Ret = 200
  5111. br.Success = true
  5112. br.Msg = "获取成功"
  5113. br.Data = resp
  5114. }
  5115. // @Title 客户导出
  5116. // @Description 客户导出接口
  5117. // @Param Status query string true "状态:'试用','永续','冻结','流失','正式'"
  5118. // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
  5119. // @Param IndustryId query int true "行业id,0为全部"
  5120. // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
  5121. // @Param ChartPermissionIds query string false "阅读权限品种ID,多个用英文逗号分开,空字符串为全部"
  5122. // @Param ContractPermissionIds query string false "已购品种ID,多个用英文逗号分开,空字符串为全部"
  5123. // @Param StartDate query string true "开始时间"
  5124. // @Param EndDate query string true "结束时间"
  5125. // @Param CreateStartDate query string true "创建开始时间"
  5126. // @Param CreateEndDate query string true "创建结束时间"
  5127. // @Param KeyWord query string true "搜索关键词"
  5128. // @Param Address query string true "地址 , 多个用英文逗号分开 "
  5129. // @Param Province query string true "省 , 多个用英文逗号分开 "
  5130. // @Param City query string true "市 , 多个用英文逗号分开 "
  5131. // @Param PackageType query int true "套餐类型,0:无,1:大套餐,2:小套餐"
  5132. // @Success 200 {object} company.CompanyListResp
  5133. // @router /export [get]
  5134. func (this *CompanyController) Export() {
  5135. br := new(models.BaseResponse).Init()
  5136. defer func() {
  5137. this.Data["json"] = br
  5138. this.ServeJSON()
  5139. }()
  5140. sysUser := this.SysUser
  5141. if sysUser == nil {
  5142. br.Msg = "请登录"
  5143. br.ErrMsg = "请登录,SysUser Is Empty"
  5144. br.Ret = 408
  5145. return
  5146. }
  5147. roleTypeCode := sysUser.RoleTypeCode
  5148. status := this.GetString("Status")
  5149. companyType := this.GetString("CompanyType")
  5150. industryId, _ := this.GetInt("IndustryId")
  5151. adminId := this.GetString("AdminId")
  5152. chartPermissionIds := this.GetString("ChartPermissionIds")
  5153. contractPermissionIds := this.GetString("ContractPermissionIds")
  5154. startDate := this.GetString("StartDate")
  5155. endDate := this.GetString("EndDate")
  5156. createStartDate := this.GetString("CreateStartDate")
  5157. createEndDate := this.GetString("CreateEndDate")
  5158. keyWord := this.GetString("KeyWord")
  5159. keyWord = strings.Trim(keyWord, " ")
  5160. address := this.GetString("Address")
  5161. province := this.GetString("Province")
  5162. city := this.GetString("City")
  5163. // 套餐类型
  5164. packageType, _ := this.GetInt("PackageType")
  5165. resp := new(company.CompanyListResp)
  5166. statusItems := make([]*company.CompanyStatus, 0)
  5167. var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}
  5168. var condition string
  5169. var pars []interface{}
  5170. //状态分类查询条件
  5171. var permissionCondition string
  5172. var permissionPars []interface{}
  5173. if companyType != "" {
  5174. condition += ` AND b.product_name=? `
  5175. pars = append(pars, companyType)
  5176. }
  5177. if industryId > 0 {
  5178. condition += ` AND b.industry_id=? `
  5179. pars = append(pars, industryId)
  5180. }
  5181. if adminId != "" {
  5182. condition += ` AND b.seller_id IN (` + adminId + `) `
  5183. }
  5184. if startDate != "" {
  5185. condition += ` AND b.start_date>=? `
  5186. pars = append(pars, startDate)
  5187. }
  5188. if endDate != "" {
  5189. condition += ` AND b.end_date<=? `
  5190. pars = append(pars, endDate)
  5191. }
  5192. if createStartDate != "" {
  5193. condition += ` AND a.created_time>=? `
  5194. pars = append(pars, createStartDate)
  5195. }
  5196. if createEndDate != "" {
  5197. condition += ` AND a.created_time<=? `
  5198. pars = append(pars, createEndDate)
  5199. }
  5200. if address != "" {
  5201. var addressSql string
  5202. slice := strings.Split(address, ",")
  5203. for _, v := range slice {
  5204. addressSql += "'" + v + "'" + ","
  5205. }
  5206. addressSql = strings.TrimRight(addressSql, ",")
  5207. condition += ` AND a.address IN (` + addressSql + `) `
  5208. }
  5209. if province != "" {
  5210. var provinceSql string
  5211. slice := strings.Split(province, ",")
  5212. for _, v := range slice {
  5213. provinceSql += "'" + v + "'" + ","
  5214. }
  5215. provinceSql = strings.TrimRight(provinceSql, ",")
  5216. condition += ` AND a.province IN (` + provinceSql + `) `
  5217. }
  5218. if city != "" {
  5219. var citySql string
  5220. slice := strings.Split(city, ",")
  5221. for _, v := range slice {
  5222. citySql += "'" + v + "'" + ","
  5223. }
  5224. citySql = strings.TrimRight(citySql, ",")
  5225. condition += ` AND a.city IN (` + citySql + `) `
  5226. }
  5227. if keyWord != "" {
  5228. companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
  5229. if err != nil {
  5230. br.Msg = "获取客户信息失败"
  5231. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  5232. return
  5233. }
  5234. if companyIdStr != "" {
  5235. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  5236. } else {
  5237. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  5238. }
  5239. }
  5240. //if chartPermissionIds != "" && chartPermissionIds != "1" {
  5241. // companyIdStr, err := company.GetCompanyListCompanyIdByPermissionIdStr(chartPermissionIds)
  5242. // if err != nil {
  5243. // br.Msg = "获取失败"
  5244. // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
  5245. // return
  5246. // }
  5247. // if companyIdStr != "" {
  5248. // condition += ` AND a.company_id IN (` + companyIdStr + `) `
  5249. // } else {
  5250. // for _, v := range statusArr {
  5251. // statusCount := new(company.CompanyStatus)
  5252. // if v == "全部" {
  5253. // statusCount.Status = "全部"
  5254. // statusCount.Count = 0
  5255. // } else {
  5256. // statusCount.Status = v
  5257. // statusCount.Count = 0
  5258. // }
  5259. // statusItems = append(statusItems, statusCount)
  5260. // }
  5261. // items := make([]*company.CompanyListItem, 0)
  5262. // resp.List = items
  5263. // resp.StatusCount = statusItems
  5264. // br.Msg = "获取成功"
  5265. // br.Ret = 200
  5266. // br.Data = resp
  5267. // return
  5268. // }
  5269. //}
  5270. // 阅读权限/已购品种筛选
  5271. cond, emp, e := services.FilterReadAndContractAuth(chartPermissionIds, contractPermissionIds, condition)
  5272. if e != nil {
  5273. br.Msg = "获取失败"
  5274. br.ErrMsg = "FilterReadAndContractAuth err: " + e.Error()
  5275. return
  5276. }
  5277. if emp {
  5278. for _, v := range statusArr {
  5279. statusCount := new(company.CompanyStatus)
  5280. if v == "全部" {
  5281. statusCount.Status = "全部"
  5282. statusCount.Count = 0
  5283. } else {
  5284. statusCount.Status = v
  5285. statusCount.Count = 0
  5286. }
  5287. statusItems = append(statusItems, statusCount)
  5288. }
  5289. items := make([]*company.CompanyListItem, 0)
  5290. resp.List = items
  5291. resp.StatusCount = statusItems
  5292. br.Msg = "获取成功"
  5293. br.Ret = 200
  5294. br.Data = resp
  5295. return
  5296. }
  5297. condition = cond
  5298. //套餐类型
  5299. if packageType > 0 {
  5300. condition += ` AND b.package_type=? `
  5301. pars = append(pars, packageType)
  5302. }
  5303. permissionCondition = condition
  5304. permissionPars = pars
  5305. productId := services.GetProductId(roleTypeCode)
  5306. //权限控制
  5307. {
  5308. //如果不是超级管理员
  5309. if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  5310. //如果是部门管理员
  5311. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  5312. condition += ` AND b.product_id=? `
  5313. pars = append(pars, productId)
  5314. permissionCondition += ` AND b.product_id=? `
  5315. permissionPars = append(permissionPars, productId)
  5316. } else {
  5317. condition += ` AND b.product_id=? `
  5318. pars = append(pars, productId)
  5319. permissionCondition += ` AND b.product_id=? `
  5320. permissionPars = append(permissionPars, productId)
  5321. if status == "全部" {
  5322. ////如果是筛选了流失客户状态
  5323. if sysUser.Authority <= 0 {
  5324. condition += ` AND (b.seller_id=? OR status='流失') `
  5325. pars = append(pars, sysUser.AdminId)
  5326. permissionCondition += ` AND b.seller_id=? `
  5327. permissionPars = append(permissionPars, sysUser.AdminId)
  5328. } else {
  5329. if sysUser.Authority == 1 {
  5330. condition += ` AND (b.department_id=? OR status='流失')`
  5331. pars = append(pars, sysUser.DepartmentId)
  5332. permissionCondition += ` AND b.department_id=? `
  5333. permissionPars = append(permissionPars, sysUser.DepartmentId)
  5334. }
  5335. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  5336. if status != utils.COMPANY_STATUS_LOSE {
  5337. condition += ` AND (b.group_id=? OR status='流失') `
  5338. pars = append(pars, sysUser.GroupId)
  5339. }
  5340. permissionCondition += ` AND b.group_id=? `
  5341. permissionPars = append(permissionPars, sysUser.GroupId)
  5342. }
  5343. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  5344. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  5345. if err != nil {
  5346. br.Msg = "获取失败"
  5347. br.ErrMsg = "查询父级id异常" + err.Error()
  5348. return
  5349. }
  5350. var ids []*string
  5351. if pid != nil && *pid != 0 {
  5352. ids, err = company.GetGroupIdsByParentId(*pid)
  5353. if err != nil {
  5354. fmt.Println(err.Error())
  5355. }
  5356. } else {
  5357. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  5358. if err != nil {
  5359. fmt.Println(err.Error())
  5360. }
  5361. }
  5362. var idSlice []string
  5363. var sid string
  5364. for _, id := range ids {
  5365. idSlice = append(idSlice, *id)
  5366. }
  5367. //加入父级groupId
  5368. if *pid > 0 {
  5369. idSlice = append(idSlice, strconv.Itoa(*pid))
  5370. } else {
  5371. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  5372. }
  5373. sid = strings.Join(idSlice, ",")
  5374. if len(sid) > 0 {
  5375. if status != utils.COMPANY_STATUS_LOSE {
  5376. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  5377. //pars = append(pars, sysUser.GroupId)
  5378. }
  5379. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  5380. } else {
  5381. if status != utils.COMPANY_STATUS_LOSE {
  5382. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  5383. //pars = append(pars, sysUser.GroupId)
  5384. }
  5385. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  5386. }
  5387. }
  5388. }
  5389. } else {
  5390. ////如果没有筛选了流失客户状态
  5391. if sysUser.Authority <= 0 {
  5392. condition += ` AND b.seller_id=? `
  5393. pars = append(pars, sysUser.AdminId)
  5394. permissionCondition += ` AND b.seller_id=? `
  5395. permissionPars = append(permissionPars, sysUser.AdminId)
  5396. } else {
  5397. if sysUser.Authority == 1 {
  5398. condition += ` AND b.department_id=?`
  5399. pars = append(pars, sysUser.DepartmentId)
  5400. permissionCondition += ` AND b.department_id=? `
  5401. permissionPars = append(permissionPars, sysUser.DepartmentId)
  5402. }
  5403. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  5404. if status != utils.COMPANY_STATUS_LOSE {
  5405. condition += ` AND b.group_id=? `
  5406. pars = append(pars, sysUser.GroupId)
  5407. }
  5408. permissionCondition += ` AND b.group_id=? `
  5409. permissionPars = append(permissionPars, sysUser.GroupId)
  5410. }
  5411. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  5412. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  5413. if err != nil {
  5414. br.Msg = "获取失败"
  5415. br.ErrMsg = "查询父级id异常" + err.Error()
  5416. return
  5417. }
  5418. var ids []*string
  5419. if pid != nil && *pid != 0 {
  5420. ids, err = company.GetGroupIdsByParentId(*pid)
  5421. if err != nil {
  5422. fmt.Println(err.Error())
  5423. }
  5424. } else {
  5425. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  5426. if err != nil {
  5427. fmt.Println(err.Error())
  5428. }
  5429. }
  5430. var idSlice []string
  5431. var sid string
  5432. for _, id := range ids {
  5433. idSlice = append(idSlice, *id)
  5434. }
  5435. //加入父级groupId
  5436. if *pid > 0 {
  5437. idSlice = append(idSlice, strconv.Itoa(*pid))
  5438. } else {
  5439. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  5440. }
  5441. sid = strings.Join(idSlice, ",")
  5442. if len(sid) > 0 {
  5443. if status != utils.COMPANY_STATUS_LOSE {
  5444. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  5445. //pars = append(pars, sysUser.GroupId)
  5446. }
  5447. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  5448. } else {
  5449. if status != utils.COMPANY_STATUS_LOSE {
  5450. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  5451. //pars = append(pars, sysUser.GroupId)
  5452. }
  5453. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  5454. }
  5455. }
  5456. if sysUser.Authority == 4 {
  5457. if status != utils.COMPANY_STATUS_LOSE {
  5458. condition += ` AND b.group_id =? `
  5459. pars = append(pars, sysUser.GroupId)
  5460. }
  5461. permissionCondition += ` AND b.group_id=? `
  5462. permissionPars = append(permissionPars, sysUser.GroupId)
  5463. }
  5464. }
  5465. }
  5466. }
  5467. }
  5468. }
  5469. //状态控制
  5470. if status != "" && status != "全部" && status != utils.COMPANY_STATUS_LOSE {
  5471. condition += ` AND b.status=? `
  5472. pars = append(pars, status)
  5473. }
  5474. dir, err := os.Executable()
  5475. exPath := filepath.Dir(dir)
  5476. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  5477. xlsxFile := xlsx.NewFile()
  5478. if err != nil {
  5479. br.Msg = "生成文件失败"
  5480. br.ErrMsg = "生成文件失败"
  5481. return
  5482. }
  5483. style := xlsx.NewStyle()
  5484. alignment := xlsx.Alignment{
  5485. Horizontal: "center",
  5486. Vertical: "center",
  5487. WrapText: true,
  5488. }
  5489. style.Alignment = alignment
  5490. style.ApplyAlignment = true
  5491. sheel, err := xlsxFile.AddSheet("客户数据")
  5492. if err != nil {
  5493. br.Msg = "新增Sheet失败"
  5494. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  5495. return
  5496. }
  5497. titleArr := []string{"客户名称", "客户地址", "客户类型", "所属行业", "所属销售", "客户状态", "服务期限", "到期天数", "创建时间", "权限详情"}
  5498. titleLen := len(titleArr)
  5499. titleRow := sheel.AddRow()
  5500. remarkRow := sheel.AddRow() // 备注行
  5501. // 填充空白至Z列
  5502. emptyColNum := 0
  5503. for i := 0; i < 26; i++ {
  5504. remarkRow.AddCell().SetValue("")
  5505. if i >= titleLen {
  5506. emptyColNum += 1
  5507. titleRow.AddCell().SetValue("")
  5508. continue
  5509. }
  5510. titleRow.AddCell().SetValue(titleArr[i])
  5511. }
  5512. // AA列开始为品种权限
  5513. ficcPermissions := make([]int, 0) // 用于后续判断试用暂停客户是否需要暂停这部分权限
  5514. raiPermissions := make([]int, 0)
  5515. permissions, e := models.GetChartPermissionList()
  5516. if e != nil {
  5517. br.Msg = "获取失败"
  5518. br.ErrMsg = "获取品种数据失败,Err:" + err.Error()
  5519. return
  5520. }
  5521. raiArr := []string{"医药", "消费", "科技", "智造"}
  5522. for _, p := range permissions {
  5523. if p.ProductId == 1 {
  5524. ficcPermissions = append(ficcPermissions, p.ChartPermissionId)
  5525. }
  5526. if p.ProductId == 2 {
  5527. raiPermissions = append(raiPermissions, p.ChartPermissionId)
  5528. }
  5529. if utils.InArrayByStr(raiArr, p.PermissionName) {
  5530. titleRow.AddCell().SetValue(p.Remark)
  5531. continue
  5532. }
  5533. titleRow.AddCell().SetValue(p.PermissionName)
  5534. }
  5535. // 第二行, 在品种权限开始列加一行标红备注
  5536. styleRed := xlsx.NewStyle()
  5537. styleRed.Font.Color = "ff0000"
  5538. remarkCell := remarkRow.AddCell()
  5539. remarkCell.SetStyle(styleRed)
  5540. remarkCell.SetString(`第一位数字表示是否已购买该品种,1表示已购,0表示未购;第二位数字表示是否有阅读权限,1表示有权限,0表示没有`)
  5541. list, err := company.GetCompanyListExport(condition, pars)
  5542. if err != nil {
  5543. br.Msg = "获取失败"
  5544. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  5545. return
  5546. }
  5547. companyIds := make([]int, 0)
  5548. for _, c := range list {
  5549. companyIds = append(companyIds, c.CompanyId)
  5550. }
  5551. // 获取客户对应的阅读和合同权限集合
  5552. contractPermissionMap := make(map[int][]int)
  5553. contractPermissions, e := company.GetContractPermissionIdsByCompanyIds(companyIds)
  5554. if e != nil {
  5555. br.Msg = "获取失败"
  5556. br.ErrMsg = "获取已购权限失败, Err: " + e.Error()
  5557. return
  5558. }
  5559. for _, p := range contractPermissions {
  5560. ids := make([]int, 0)
  5561. if p.ChartPermissionIds != "" {
  5562. idArr := strings.Split(p.ChartPermissionIds, ",")
  5563. for _, i := range idArr {
  5564. id, _ := strconv.Atoi(i)
  5565. ids = append(ids, id)
  5566. }
  5567. }
  5568. contractPermissionMap[p.CompanyId] = ids
  5569. }
  5570. reportPermissionMap := make(map[int][]int)
  5571. reportPermissions, e := company.GetReportPermissionIdsByCompanyIds(companyIds)
  5572. if e != nil {
  5573. br.Msg = "获取失败"
  5574. br.ErrMsg = "获取阅读权限失败, Err: " + e.Error()
  5575. return
  5576. }
  5577. for _, p := range reportPermissions {
  5578. ids := make([]int, 0)
  5579. if p.ChartPermissionIds != "" {
  5580. idArr := strings.Split(p.ChartPermissionIds, ",")
  5581. for _, i := range idArr {
  5582. id, _ := strconv.Atoi(i)
  5583. ids = append(ids, id)
  5584. }
  5585. }
  5586. reportPermissionMap[p.CompanyId] = ids
  5587. }
  5588. cpMap := make(map[int][]*company.ExportCompanyProduct)
  5589. permissionMap := make(map[string]string)
  5590. for _, v := range list {
  5591. cpList := make([]*company.ExportCompanyProduct, 1)
  5592. if cps, ok := cpMap[v.CompanyId]; ok {
  5593. cpList = cps
  5594. } else {
  5595. companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  5596. if err != nil {
  5597. br.Msg = "导出失败"
  5598. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  5599. return
  5600. }
  5601. cpMap[v.CompanyId] = companyProduct
  5602. cpList = companyProduct
  5603. }
  5604. var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, expireDay string
  5605. isFiccSuspend := 0
  5606. isRaiSuspend := 0
  5607. for ck, cv := range cpList {
  5608. companyName = cv.CompanyName
  5609. if ck >= 1 {
  5610. companyType = companyType + "/" + cv.ProductName
  5611. status = status + "/" + cv.Status
  5612. } else {
  5613. companyType = cv.ProductName
  5614. status = cv.Status
  5615. }
  5616. if cv.ProductId == 1 {
  5617. industryName = "ficc:" + cv.IndustryName
  5618. sellerName = "ficc:" + cv.SellerName
  5619. startDateStr := cv.StartDate.Format("2006/01/02")
  5620. endDateStr := cv.EndDate.Format("2006/01/02")
  5621. timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  5622. createTime = "ficc:" + cv.CreateTime
  5623. source = "ficc:" + cv.Source
  5624. sub := cv.EndDate.Sub(time.Now())
  5625. if sub < 0 {
  5626. sub = 0
  5627. }
  5628. expireDay = "ficc:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  5629. permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  5630. permissionStr = "ficc:"
  5631. if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  5632. permissionStr += newPermissionStr
  5633. } else {
  5634. getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  5635. if err != nil {
  5636. br.Msg = "导出失败"
  5637. br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  5638. return
  5639. }
  5640. permissionMap[permissionKey] = getPermissionStr
  5641. permissionStr += getPermissionStr
  5642. }
  5643. isFiccSuspend = cv.IsSuspend
  5644. } else {
  5645. industryName = industryName + "\n" + "权益:" + cv.IndustryName
  5646. sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  5647. startDateStr := cv.StartDate.Format("2006/01/02")
  5648. endDateStr := cv.EndDate.Format("2006/01/02")
  5649. timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  5650. createTime = createTime + "\n" + "权益:" + cv.CreateTime
  5651. source = source + "\n" + "权益:" + cv.Source
  5652. sub := cv.EndDate.Sub(time.Now())
  5653. if sub < 0 {
  5654. sub = 0
  5655. }
  5656. expireDay = "\n" + "权益:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  5657. permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  5658. if permissionStr != "" {
  5659. permissionStr = permissionStr + "\n" + "权益:"
  5660. } else {
  5661. permissionStr = "权益:"
  5662. }
  5663. if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  5664. permissionStr += newPermissionStr
  5665. } else {
  5666. getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  5667. if err != nil {
  5668. br.Msg = "导出失败"
  5669. br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  5670. return
  5671. }
  5672. permissionMap[permissionKey] = getPermissionStr
  5673. permissionStr += getPermissionStr
  5674. }
  5675. isRaiSuspend = cv.IsSuspend
  5676. }
  5677. }
  5678. dataRow := sheel.AddRow()
  5679. dataRow.SetHeight(20)
  5680. dataRow.AddCell().SetString(companyName)
  5681. dataRow.AddCell().SetString(v.Address)
  5682. dataRow.AddCell().SetString(companyType)
  5683. dataRow.AddCell().SetString(v.IndustryName)
  5684. dataRow.AddCell().SetString(v.SellerName)
  5685. dataRow.AddCell().SetString(v.Status)
  5686. dataRow.AddCell().SetString(timeLimt)
  5687. dataRow.AddCell().SetString(expireDay)
  5688. dataRow.AddCell().SetString(v.CreatedTime)
  5689. //dataRow.AddCell().SetString(v.Source)
  5690. dataRow.AddCell().SetString(permissionStr)
  5691. // 填充空白至Z列, AA列开始为权限
  5692. for i := 0; i < emptyColNum; i++ {
  5693. dataRow.AddCell().SetString("")
  5694. }
  5695. cpIds := contractPermissionMap[v.CompanyId]
  5696. rpIds := reportPermissionMap[v.CompanyId]
  5697. for _, p := range permissions {
  5698. // 数字含义:11-表示已购且有阅读权限, 01-表示未购买但有阅读权限
  5699. first := 0
  5700. if utils.InArrayByInt(cpIds, p.ChartPermissionId) {
  5701. first = 1
  5702. }
  5703. second := 0
  5704. if utils.InArrayByInt(rpIds, p.ChartPermissionId) {
  5705. second = 1
  5706. // 如果客户是试用暂停, 即使有这部分权限, 也标记为0
  5707. if isFiccSuspend == 1 && utils.InArrayByInt(ficcPermissions, p.ChartPermissionId) {
  5708. second = 0
  5709. }
  5710. if isRaiSuspend == 1 && utils.InArrayByInt(raiPermissions, p.ChartPermissionId) {
  5711. second = 0
  5712. }
  5713. }
  5714. dataRow.AddCell().SetString(fmt.Sprintf("%d%d", first, second))
  5715. }
  5716. }
  5717. err = xlsxFile.Save(downLoadnFilePath)
  5718. if err != nil {
  5719. br.Msg = "保存文件失败"
  5720. br.ErrMsg = "保存文件失败"
  5721. return
  5722. }
  5723. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  5724. downloadFileName := "客户列表_" + randStr + ".xlsx"
  5725. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  5726. defer func() {
  5727. os.Remove(downLoadnFilePath)
  5728. }()
  5729. br.Ret = 200
  5730. br.Success = true
  5731. br.Msg = "导出成功"
  5732. }
  5733. //func (this *CompanyController) ExportOld() {
  5734. // br := new(models.BaseResponse).Init()
  5735. // defer func() {
  5736. // this.Data["json"] = br
  5737. // this.ServeJSON()
  5738. // }()
  5739. // sysUser := this.SysUser
  5740. // if sysUser == nil {
  5741. // br.Msg = "请登录"
  5742. // br.ErrMsg = "请登录,SysUser Is Empty"
  5743. // br.Ret = 408
  5744. // return
  5745. // }
  5746. // roleTypeCode := sysUser.RoleTypeCode
  5747. //
  5748. // status := this.GetString("Status")
  5749. // companyType := this.GetString("CompanyType")
  5750. // industryId, _ := this.GetInt("IndustryId")
  5751. // adminId := this.GetString("AdminId")
  5752. //
  5753. // chartPermissionIds := this.GetString("ChartPermissionIds")
  5754. // startDate := this.GetString("StartDate")
  5755. // endDate := this.GetString("EndDate")
  5756. // createStartDate := this.GetString("CreateStartDate")
  5757. // createEndDate := this.GetString("CreateEndDate")
  5758. // keyWord := this.GetString("KeyWord")
  5759. // keyWord = strings.Trim(keyWord, " ")
  5760. //
  5761. // resp := new(company.CompanyListResp)
  5762. // statusItems := make([]*company.CompanyStatus, 0)
  5763. // var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}
  5764. //
  5765. // var condition string
  5766. // var pars []interface{}
  5767. //
  5768. // var lossCondition string
  5769. // var lossPars []interface{}
  5770. //
  5771. // var permissionCondition string
  5772. // var permissionPars []interface{}
  5773. //
  5774. // if status != "" && status != "全部" {
  5775. // condition += ` AND b.status=? `
  5776. // pars = append(pars, status)
  5777. //
  5778. // //permissionCondition += ` AND b.status=? `
  5779. // //permissionPars = append(permissionPars, status)
  5780. // }
  5781. // if companyType != "" {
  5782. // condition += ` AND b.product_name=? `
  5783. // pars = append(pars, companyType)
  5784. //
  5785. // lossCondition += ` AND b.product_name=? `
  5786. // lossPars = append(lossPars, companyType)
  5787. //
  5788. // permissionCondition += ` AND b.product_name=? `
  5789. // permissionPars = append(permissionPars, companyType)
  5790. // }
  5791. //
  5792. // if industryId > 0 {
  5793. // condition += ` AND b.industry_id=? `
  5794. // pars = append(pars, industryId)
  5795. //
  5796. // lossCondition += ` AND b.industry_id=? `
  5797. // lossPars = append(lossPars, industryId)
  5798. //
  5799. // permissionCondition += ` AND b.industry_id=? `
  5800. // permissionPars = append(permissionPars, industryId)
  5801. // }
  5802. //
  5803. // if adminId != "" {
  5804. // condition += ` AND b.seller_id IN (` + adminId + `) `
  5805. //
  5806. // lossCondition += ` AND b.seller_id IN (` + adminId + `) `
  5807. //
  5808. // permissionCondition += ` AND b.seller_id IN (` + adminId + `) `
  5809. // }
  5810. //
  5811. // if startDate != "" {
  5812. // condition += ` AND b.start_date>=? `
  5813. // pars = append(pars, startDate)
  5814. //
  5815. // lossCondition += ` AND b.start_date>=? `
  5816. // lossPars = append(lossPars, startDate)
  5817. //
  5818. // permissionCondition += ` AND b.start_date>=? `
  5819. // permissionPars = append(permissionPars, startDate)
  5820. // }
  5821. //
  5822. // if endDate != "" {
  5823. // condition += ` AND b.end_date<=? `
  5824. // pars = append(pars, endDate)
  5825. //
  5826. // lossCondition += ` AND b.end_date<=? `
  5827. // lossPars = append(lossPars, endDate)
  5828. //
  5829. // permissionCondition += ` AND b.end_date<=? `
  5830. // permissionPars = append(permissionPars, endDate)
  5831. // }
  5832. //
  5833. // if createStartDate != "" {
  5834. // condition += ` AND a.created_time>=? `
  5835. // pars = append(pars, createStartDate)
  5836. //
  5837. // lossCondition += ` AND a.created_time>=? `
  5838. // lossPars = append(lossPars, createStartDate)
  5839. //
  5840. // permissionCondition += ` AND a.created_time>=? `
  5841. // permissionPars = append(permissionPars, createStartDate)
  5842. // }
  5843. //
  5844. // if createEndDate != "" {
  5845. // condition += ` AND a.created_time<=? `
  5846. // pars = append(pars, createEndDate)
  5847. //
  5848. // lossCondition += ` AND a.created_time<=? `
  5849. // lossPars = append(lossPars, createEndDate)
  5850. //
  5851. // permissionCondition += ` AND a.created_time<=? `
  5852. // permissionPars = append(permissionPars, createEndDate)
  5853. // }
  5854. //
  5855. // if keyWord != "" {
  5856. // companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
  5857. // if err != nil {
  5858. // return
  5859. // }
  5860. // if companyIdStr != "" {
  5861. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  5862. // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  5863. //
  5864. // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  5865. // } else {
  5866. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  5867. // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  5868. //
  5869. // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  5870. // }
  5871. // }
  5872. //
  5873. // if chartPermissionIds != "" && chartPermissionIds != "1" {
  5874. // //chartPermissionArr := strings.Split(chartPermissionIds, ",")
  5875. // //chartPermissionCount := len(chartPermissionArr)
  5876. // companyIdStr, err := company.GetCompanyListCompanyIdByPermissionIdStr(chartPermissionIds)
  5877. // if err != nil {
  5878. // br.Msg = "获取失败"
  5879. // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
  5880. // return
  5881. // }
  5882. // //var companyIdArr []string
  5883. // //for _, v := range companyIdList {
  5884. // // companyIdArr = append(companyIdArr, strconv.Itoa(v.CompanyId))
  5885. // //}
  5886. // //companyIdStr := strings.Join(companyIdArr, ",")
  5887. //
  5888. // if companyIdStr != "" {
  5889. // condition += ` AND a.company_id IN (` + companyIdStr + `) `
  5890. // lossCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  5891. // permissionCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  5892. // } else {
  5893. // for _, v := range statusArr {
  5894. // statusCount := new(company.CompanyStatus)
  5895. // if v == "全部" {
  5896. // statusCount.Status = "全部"
  5897. // statusCount.Count = 0
  5898. // } else {
  5899. // statusCount.Status = v
  5900. // statusCount.Count = 0
  5901. // }
  5902. // statusItems = append(statusItems, statusCount)
  5903. // }
  5904. // items := make([]*company.CompanyListItem, 0)
  5905. // resp.List = items
  5906. // resp.StatusCount = statusItems
  5907. // br.Msg = "获取成功"
  5908. // br.Ret = 200
  5909. // br.Data = resp
  5910. // return
  5911. // }
  5912. // }
  5913. //
  5914. // //权限控制
  5915. // {
  5916. // if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  5917. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  5918. // condition += ` AND b.product_id=? `
  5919. // pars = append(pars, 1)
  5920. //
  5921. // permissionCondition += ` AND b.product_id=? `
  5922. // permissionPars = append(permissionPars, 1)
  5923. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  5924. // condition += ` AND b.product_id=? `
  5925. // pars = append(pars, 2)
  5926. //
  5927. // permissionCondition += ` AND b.product_id=? `
  5928. // permissionPars = append(permissionPars, 2)
  5929. // } else {
  5930. // if sysUser.Authority <= 0 {
  5931. // if status != utils.COMPANY_STATUS_LOSE {
  5932. // condition += ` AND b.seller_id=? `
  5933. // pars = append(pars, sysUser.AdminId)
  5934. // }
  5935. //
  5936. // permissionCondition += ` AND b.seller_id=? `
  5937. // permissionPars = append(permissionPars, sysUser.AdminId)
  5938. // } else {
  5939. // if sysUser.Authority == 1 {
  5940. // if status != utils.COMPANY_STATUS_LOSE {
  5941. // condition += ` AND b.department_id=? `
  5942. // pars = append(pars, sysUser.DepartmentId)
  5943. // }
  5944. // permissionCondition += ` AND b.department_id=? `
  5945. // permissionPars = append(permissionPars, sysUser.DepartmentId)
  5946. // }
  5947. //
  5948. // if sysUser.Authority == 2 {
  5949. // if status != utils.COMPANY_STATUS_LOSE {
  5950. // condition += ` AND b.group_id=? `
  5951. // pars = append(pars, sysUser.GroupId)
  5952. // }
  5953. // permissionCondition += ` AND b.group_id=? `
  5954. // permissionPars = append(permissionPars, sysUser.GroupId)
  5955. // }
  5956. // }
  5957. // }
  5958. // }
  5959. // }
  5960. //
  5961. // dir, err := os.Executable()
  5962. // exPath := filepath.Dir(dir)
  5963. // downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  5964. // xlsxFile := xlsx.NewFile()
  5965. // if err != nil {
  5966. // br.Msg = "生成文件失败"
  5967. // br.ErrMsg = "生成文件失败"
  5968. // return
  5969. // }
  5970. // style := xlsx.NewStyle()
  5971. // alignment := xlsx.Alignment{
  5972. // Horizontal: "center",
  5973. // Vertical: "center",
  5974. // WrapText: true,
  5975. // }
  5976. //
  5977. // style.Alignment = alignment
  5978. // style.ApplyAlignment = true
  5979. //
  5980. // sheel, err := xlsxFile.AddSheet("客户数据")
  5981. // if err != nil {
  5982. // br.Msg = "新增Sheet失败"
  5983. // br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  5984. // return
  5985. // }
  5986. // titleRow := sheel.AddRow()
  5987. // titleRow.AddCell().SetValue("客户名称")
  5988. // titleRow.AddCell().SetValue("客户类型")
  5989. // titleRow.AddCell().SetValue("所属行业")
  5990. // titleRow.AddCell().SetValue("所属销售")
  5991. // titleRow.AddCell().SetValue("客户状态")
  5992. // titleRow.AddCell().SetValue("服务期限")
  5993. // titleRow.AddCell().SetValue("到期天数")
  5994. // titleRow.AddCell().SetValue("创建时间")
  5995. // titleRow.AddCell().SetValue("客户来源")
  5996. // titleRow.AddCell().SetValue("阅读权限")
  5997. //
  5998. // list, err := company.GetCompanyListExport(condition, pars)
  5999. // if err != nil {
  6000. // br.Msg = "获取失败"
  6001. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  6002. // return
  6003. // }
  6004. // cpMap := make(map[int][]*company.ExportCompanyProduct)
  6005. // permissionMap := make(map[string]string)
  6006. // for _, v := range list {
  6007. // cpList := make([]*company.ExportCompanyProduct, 1)
  6008. // if cps, ok := cpMap[v.CompanyId]; ok {
  6009. // cpList = cps
  6010. // } else {
  6011. // companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  6012. // if err != nil {
  6013. // br.Msg = "导出失败"
  6014. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  6015. // return
  6016. // }
  6017. // cpMap[v.CompanyId] = companyProduct
  6018. // cpList = companyProduct
  6019. // }
  6020. // var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, expireDay string
  6021. //
  6022. // for ck, cv := range cpList {
  6023. // companyName = cv.CompanyName
  6024. // if ck >= 1 {
  6025. // companyType = companyType + "/" + cv.ProductName
  6026. // status = status + "/" + cv.Status
  6027. // } else {
  6028. // companyType = cv.ProductName
  6029. // status = cv.Status
  6030. // }
  6031. // if cv.ProductId == 1 {
  6032. // industryName = "ficc:" + cv.IndustryName
  6033. // sellerName = "ficc:" + cv.SellerName
  6034. // startDateStr := cv.StartDate.Format("2006/01/02")
  6035. // endDateStr := cv.EndDate.Format("2006/01/02")
  6036. // timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  6037. // createTime = "ficc:" + cv.CreateTime
  6038. // source = "ficc:" + cv.Source
  6039. // sub := cv.EndDate.Sub(time.Now())
  6040. // if sub < 0 {
  6041. // sub = 0
  6042. // }
  6043. // expireDay = "ficc:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  6044. //
  6045. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6046. //
  6047. // permissionStr = "ficc:"
  6048. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6049. // permissionStr += newPermissionStr
  6050. // } else {
  6051. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6052. // if err != nil {
  6053. // br.Msg = "导出失败"
  6054. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6055. // return
  6056. // }
  6057. // permissionMap[permissionKey] = getPermissionStr
  6058. // permissionStr += getPermissionStr
  6059. // }
  6060. // } else {
  6061. // industryName = industryName + "\n" + "权益:" + cv.IndustryName
  6062. // sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  6063. // startDateStr := cv.StartDate.Format("2006/01/02")
  6064. // endDateStr := cv.EndDate.Format("2006/01/02")
  6065. //
  6066. // timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  6067. // createTime = createTime + "\n" + "权益:" + cv.CreateTime
  6068. // source = source + "\n" + "权益:" + cv.Source
  6069. //
  6070. // sub := cv.EndDate.Sub(time.Now())
  6071. // if sub < 0 {
  6072. // sub = 0
  6073. // }
  6074. // expireDay = "\n" + "权益:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  6075. //
  6076. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6077. // if permissionStr != "" {
  6078. // permissionStr = permissionStr + "\n" + "权益:"
  6079. // } else {
  6080. // permissionStr = "权益:"
  6081. // }
  6082. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6083. // permissionStr += newPermissionStr
  6084. // } else {
  6085. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6086. // if err != nil {
  6087. // br.Msg = "导出失败"
  6088. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6089. // return
  6090. // }
  6091. // permissionMap[permissionKey] = getPermissionStr
  6092. // permissionStr += getPermissionStr
  6093. // }
  6094. // }
  6095. // }
  6096. //
  6097. // dataRow := sheel.AddRow()
  6098. // dataRow.SetHeight(20)
  6099. // dataRow.AddCell().SetString(companyName)
  6100. // dataRow.AddCell().SetString(companyType)
  6101. // dataRow.AddCell().SetString(v.IndustryName)
  6102. // dataRow.AddCell().SetString(v.SellerName)
  6103. // dataRow.AddCell().SetString(v.Status)
  6104. // dataRow.AddCell().SetString(timeLimt)
  6105. // dataRow.AddCell().SetString(expireDay)
  6106. // dataRow.AddCell().SetString(v.CreatedTime)
  6107. // dataRow.AddCell().SetString(v.Source)
  6108. // dataRow.AddCell().SetString(permissionStr)
  6109. // }
  6110. // err = xlsxFile.Save(downLoadnFilePath)
  6111. // if err != nil {
  6112. // br.Msg = "保存文件失败"
  6113. // br.ErrMsg = "保存文件失败"
  6114. // return
  6115. // }
  6116. // randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  6117. // downloadFileName := "客户列表_" + randStr + ".xlsx"
  6118. // this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  6119. // defer func() {
  6120. // os.Remove(downLoadnFilePath)
  6121. // }()
  6122. // br.Ret = 200
  6123. // br.Success = true
  6124. // br.Msg = "导出成功"
  6125. //}
  6126. // @Title 导出
  6127. // @Description 导出接口
  6128. // @Param Status query string true "状态:”试用','永续','冻结','流失','正式'"
  6129. // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
  6130. // @Param IndustryId query int true "行业id,0为全部"
  6131. // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
  6132. // @Param ChartPermissionIds query string false "阅读权限品种ID,多个用英文逗号分开,空字符串为全部"
  6133. // @Param ContractPermissionIds query string false "已购品种ID,多个用英文逗号分开,空字符串为全部"
  6134. // @Param StartDate query string true "开始时间"
  6135. // @Param EndDate query string true "结束时间"
  6136. // @Param KeyWord query string true "搜索关键词"
  6137. // @Param Address query string true "地址 , 多个用英文逗号分开 "
  6138. // @Param Province query string true "省 , 多个用英文逗号分开 "
  6139. // @Param City query string true "市 , 多个用英文逗号分开 "
  6140. // @Param PackageType query int true "套餐类型,0:无,1:大套餐,2:小套餐"
  6141. // @Success Ret=200 移动成功
  6142. // @router /user/export [get]
  6143. func (this *CompanyController) CompanyUserExport() {
  6144. br := new(models.BaseResponse).Init()
  6145. defer func() {
  6146. this.Data["json"] = br
  6147. this.ServeJSON()
  6148. }()
  6149. sysUser := this.SysUser
  6150. if sysUser == nil {
  6151. br.Msg = "请登录"
  6152. br.ErrMsg = "请登录,SysUser Is Empty"
  6153. br.Ret = 408
  6154. return
  6155. }
  6156. roleTypeCode := sysUser.RoleTypeCode
  6157. status := this.GetString("Status")
  6158. companyType := this.GetString("CompanyType")
  6159. industryId, _ := this.GetInt("IndustryId")
  6160. adminId := this.GetString("AdminId")
  6161. chartPermissionIds := this.GetString("ChartPermissionIds")
  6162. contractPermissionIds := this.GetString("ContractPermissionIds")
  6163. startDate := this.GetString("StartDate")
  6164. endDate := this.GetString("EndDate")
  6165. createStartDate := this.GetString("CreateStartDate")
  6166. createEndDate := this.GetString("CreateEndDate")
  6167. keyWord := this.GetString("KeyWord")
  6168. address := this.GetString("Address")
  6169. province := this.GetString("Province")
  6170. city := this.GetString("City")
  6171. // 套餐类型
  6172. packageType, _ := this.GetInt("PackageType")
  6173. var condition string
  6174. var pars []interface{}
  6175. if status != "" && status != "全部" {
  6176. condition += ` AND b.status=? `
  6177. pars = append(pars, status)
  6178. }
  6179. if companyType != "" {
  6180. condition += ` AND b.product_name=? `
  6181. pars = append(pars, companyType)
  6182. }
  6183. if industryId > 0 {
  6184. condition += ` AND b.industry_id=? `
  6185. pars = append(pars, industryId)
  6186. }
  6187. if adminId != "" {
  6188. condition += ` AND b.seller_id IN (` + adminId + `) `
  6189. }
  6190. if startDate != "" {
  6191. condition += ` AND b.start_date>=? `
  6192. pars = append(pars, startDate)
  6193. }
  6194. if endDate != "" {
  6195. condition += ` AND b.end_date<=? `
  6196. pars = append(pars, endDate)
  6197. }
  6198. if createStartDate != "" {
  6199. condition += ` AND a.created_time>=? `
  6200. pars = append(pars, createStartDate)
  6201. }
  6202. if createEndDate != "" {
  6203. condition += ` AND a.created_time<=? `
  6204. pars = append(pars, createEndDate)
  6205. }
  6206. if keyWord != "" {
  6207. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR c.mobile LIKE '%` + keyWord + `%' OR c.email LIKE '%` + keyWord + `%') `
  6208. }
  6209. // 阅读权限/已购品种筛选
  6210. cond, emp, e := services.FilterReadAndContractAuth(chartPermissionIds, contractPermissionIds, condition)
  6211. if e != nil {
  6212. br.Msg = "获取失败"
  6213. br.ErrMsg = "FilterReadAndContractAuth err: " + e.Error()
  6214. return
  6215. }
  6216. if emp {
  6217. condition += ` AND 1 = 2`
  6218. } else {
  6219. condition = cond
  6220. }
  6221. if address != "" {
  6222. var addressSql string
  6223. slice := strings.Split(address, ",")
  6224. for _, v := range slice {
  6225. addressSql += "'" + v + "'" + ","
  6226. }
  6227. addressSql = strings.TrimRight(addressSql, ",")
  6228. condition += ` AND a.address IN (` + addressSql + `) `
  6229. }
  6230. if province != "" {
  6231. var provinceSql string
  6232. slice := strings.Split(province, ",")
  6233. for _, v := range slice {
  6234. provinceSql += "'" + v + "'" + ","
  6235. }
  6236. provinceSql = strings.TrimRight(provinceSql, ",")
  6237. condition += ` AND a.province IN (` + provinceSql + `) `
  6238. }
  6239. if city != "" {
  6240. var citySql string
  6241. slice := strings.Split(city, ",")
  6242. for _, v := range slice {
  6243. citySql += "'" + v + "'" + ","
  6244. }
  6245. citySql = strings.TrimRight(citySql, ",")
  6246. condition += ` AND a.city IN (` + citySql + `) `
  6247. }
  6248. //套餐类型
  6249. if packageType > 0 {
  6250. condition += ` AND b.package_type=? `
  6251. pars = append(pars, packageType)
  6252. }
  6253. //权限控制
  6254. {
  6255. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  6256. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  6257. if status != utils.COMPANY_STATUS_LOSE && status != utils.COMPANY_STATUS_FOREVER {
  6258. condition += ` AND b.seller_id=? `
  6259. pars = append(pars, sysUser.AdminId)
  6260. }
  6261. }
  6262. if sysUser.Authority == 1 {
  6263. condition += ` AND b.department_id=? `
  6264. pars = append(pars, sysUser.DepartmentId)
  6265. }
  6266. if sysUser.Authority == 2 {
  6267. condition += ` AND b.group_id=? `
  6268. pars = append(pars, sysUser.GroupId)
  6269. }
  6270. }
  6271. var statusCond string
  6272. var statusPars []interface{}
  6273. // 根据当前用户角色
  6274. productId := services.GetProductId(roleTypeCode)
  6275. if productId > 0 {
  6276. condition += ` AND b.product_id = ? `
  6277. pars = append(pars, productId)
  6278. statusCond += ` AND b.product_id = ? `
  6279. statusPars = append(statusPars, productId)
  6280. }
  6281. companyIds, err := company.GetExportCompanyIds(condition, pars)
  6282. if err != nil {
  6283. br.Msg = "导出失败"
  6284. br.ErrMsg = "导出失败,Err:" + err.Error()
  6285. return
  6286. }
  6287. dir, err := os.Executable()
  6288. exPath := filepath.Dir(dir)
  6289. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  6290. xlsxFile := xlsx.NewFile()
  6291. if err != nil {
  6292. br.Msg = "生成文件失败"
  6293. br.ErrMsg = "生成文件失败"
  6294. return
  6295. }
  6296. style := xlsx.NewStyle()
  6297. alignment := xlsx.Alignment{
  6298. Horizontal: "center",
  6299. Vertical: "center",
  6300. WrapText: true,
  6301. }
  6302. style.Alignment = alignment
  6303. style.ApplyAlignment = true
  6304. sheel, err := xlsxFile.AddSheet("联系人数据")
  6305. if err != nil {
  6306. br.Msg = "新增Sheet失败"
  6307. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  6308. return
  6309. }
  6310. sheel.SetColWidth(7, 7, 10)
  6311. sheel.SetColWidth(8, 10, 16)
  6312. sheel.SetColWidth(9, 11, 20)
  6313. sheel.SetColWidth(12, 12, 35)
  6314. sheel.SetColWidth(13, 13, 15)
  6315. sheel.SetColWidth(14, 14, 80)
  6316. titleRow := sheel.AddRow()
  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. //titleRow.AddCell().SetValue("社会信用码")
  6327. //titleRow.AddCell().SetValue("所属区域")
  6328. //titleRow.AddCell().SetValue("客户类型")
  6329. //industryCell := titleRow.AddCell()
  6330. //industryCell.SetStyle(style)
  6331. //industryCell.Value = "所属行业"
  6332. //
  6333. //sellerCell := titleRow.AddCell()
  6334. //sellerCell.SetStyle(style)
  6335. //sellerCell.Value = "所属销售"
  6336. //
  6337. //statusCell := titleRow.AddCell()
  6338. //statusCell.SetStyle(style)
  6339. //statusCell.Value = "客户状态"
  6340. //
  6341. //timeLimtCell := titleRow.AddCell()
  6342. //timeLimtCell.SetStyle(style)
  6343. //timeLimtCell.Value = "服务期限"
  6344. //
  6345. //createTimeCell := titleRow.AddCell()
  6346. //createTimeCell.SetStyle(style)
  6347. //createTimeCell.Value = "创建时间"
  6348. //
  6349. //sourceCell := titleRow.AddCell()
  6350. //sourceCell.SetStyle(style)
  6351. //sourceCell.Value = "客户来源"
  6352. //permissionStyle := xlsx.NewStyle()
  6353. //permissionAlignment := xlsx.Alignment{
  6354. // Horizontal: "center",
  6355. // Vertical: "center",
  6356. // WrapText: true,
  6357. //}
  6358. //
  6359. //permissionStyle.Alignment = permissionAlignment
  6360. //permissionStyle.ApplyAlignment = true
  6361. //permissionCell := titleRow.AddCell()
  6362. //permissionCell.SetStyle(permissionStyle)
  6363. //permissionCell.Value = "阅读权限"
  6364. users := make([]*company.ExportUser, 0)
  6365. if companyIds != "" {
  6366. companyIds = strings.Trim(companyIds, ",")
  6367. if productId > 0 {
  6368. users, err = company.GetExportUserByProductId(companyIds, productId)
  6369. if err != nil {
  6370. br.Msg = "导出失败"
  6371. br.ErrMsg = "获取联系人信息失败,Err:" + err.Error()
  6372. return
  6373. }
  6374. } else {
  6375. users, err = company.GetExportUser(companyIds)
  6376. if err != nil {
  6377. br.Msg = "导出失败"
  6378. br.ErrMsg = "获取联系人信息失败,Err:" + err.Error()
  6379. return
  6380. }
  6381. }
  6382. // 获取客户状态
  6383. companyIntIds := make([]int, 0)
  6384. companyIdArr := strings.Split(companyIds, ",")
  6385. for _, c := range companyIdArr {
  6386. id, e := strconv.Atoi(c)
  6387. if e != nil {
  6388. br.Msg = "导出失败"
  6389. br.ErrMsg = "客户ID有误"
  6390. return
  6391. }
  6392. companyIntIds = append(companyIntIds, id)
  6393. }
  6394. if len(companyIntIds) > 0 {
  6395. statusCond += fmt.Sprintf(` AND a.company_id IN (%s) `, utils.GetOrmInReplace(len(companyIntIds)))
  6396. statusPars = append(statusPars, companyIntIds)
  6397. }
  6398. statusMap := make(map[int]string)
  6399. nameMap := make(map[int]string)
  6400. companyStatusList, e := company.GetExportUserCompanyStatus(statusCond, statusPars)
  6401. if e != nil {
  6402. br.Msg = "导出失败"
  6403. br.ErrMsg = "获取客户状态失败, Err: " + e.Error()
  6404. return
  6405. }
  6406. for _, s := range companyStatusList {
  6407. statusMap[s.CompanyId] = s.CompanyStatus
  6408. nameMap[s.CompanyId] = s.CompanyName
  6409. }
  6410. //cpMap := make(map[int][]*company.ExportCompanyProduct)
  6411. //permissionMap := make(map[string]string)
  6412. for _, v := range users {
  6413. dataRow := sheel.AddRow()
  6414. dataRow.SetHeight(20)
  6415. dataRow.AddCell().SetString(v.RealName)
  6416. if v.IsSubscribe == 1 {
  6417. dataRow.AddCell().SetString("是") // 是否关注公众号
  6418. } else {
  6419. dataRow.AddCell().SetString("")
  6420. }
  6421. dataRow.AddCell().SetString(v.Mobile)
  6422. dataRow.AddCell().SetString(v.Email)
  6423. //dataRow.AddCell().SetString(v.Position)
  6424. if v.IsMaker == 1 {
  6425. dataRow.AddCell().SetString("是")
  6426. } else {
  6427. dataRow.AddCell().SetString("否")
  6428. }
  6429. //dataRow.AddCell().SetString(v.DepartmentName)
  6430. //cpList := make([]*company.ExportCompanyProduct, 1)
  6431. //if cps, ok := cpMap[v.CompanyId]; ok {
  6432. // cpList = cps
  6433. //} else {
  6434. // companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  6435. // if err != nil {
  6436. // br.Msg = "导出失败"
  6437. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  6438. // return
  6439. // }
  6440. // cpMap[v.CompanyId] = companyProduct
  6441. // cpList = companyProduct
  6442. //}
  6443. //productList, err := company.GetExportCompanyProduct(v.CompanyId)
  6444. //if err!=nil {
  6445. // fmt.Println("导出失败,Err:"+err.Error())
  6446. // return
  6447. //}
  6448. //var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, creditCode, regionType string
  6449. //for ck, cv := range cpList {
  6450. // companyName = cv.CompanyName
  6451. // creditCode = cv.CreditCode
  6452. // regionType = cv.RegionType
  6453. // if ck >= 1 {
  6454. // companyType = companyType + "/" + cv.ProductName
  6455. // status = status + "/" + cv.Status
  6456. // } else {
  6457. // companyType = cv.ProductName
  6458. // status = cv.Status
  6459. // }
  6460. // if cv.ProductId == 1 {
  6461. // industryName = "ficc:" + cv.IndustryName
  6462. // sellerName = "ficc:" + cv.SellerName
  6463. // startDateStr := cv.StartDate.Format("2006/01/02")
  6464. // endDateStr := cv.EndDate.Format("2006/01/02")
  6465. // if startDateStr != "0001/01/01" {
  6466. // timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  6467. // } else {
  6468. // timeLimt = ""
  6469. // }
  6470. // createTime = "ficc:" + cv.CreateTime
  6471. // source = "ficc:" + cv.Source
  6472. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6473. //
  6474. // permissionStr = "ficc:"
  6475. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6476. // permissionStr += newPermissionStr
  6477. // } else {
  6478. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6479. // if err != nil {
  6480. // br.Msg = "导出失败"
  6481. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6482. // return
  6483. // }
  6484. // permissionMap[permissionKey] = getPermissionStr
  6485. // permissionStr += getPermissionStr
  6486. // }
  6487. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  6488. // permissionStr = ""
  6489. // }
  6490. // } else {
  6491. // industryName = industryName + "\n" + "权益:" + cv.IndustryName
  6492. // sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  6493. // startDateStr := cv.StartDate.Format("2006/01/02")
  6494. // endDateStr := cv.EndDate.Format("2006/01/02")
  6495. //
  6496. // if startDateStr != "0001/01/01" {
  6497. // timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  6498. // } else {
  6499. // timeLimt = timeLimt + ""
  6500. // }
  6501. // createTime = createTime + "\n" + "权益:" + cv.CreateTime
  6502. // source = source + "\n" + "权益:" + cv.Source
  6503. //
  6504. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6505. // if permissionStr != "" {
  6506. // permissionStr = permissionStr + "\n" + "权益:"
  6507. // } else {
  6508. // permissionStr = "权益:"
  6509. // }
  6510. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6511. // permissionStr += newPermissionStr
  6512. // } else {
  6513. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6514. // if err != nil {
  6515. // br.Msg = "导出失败"
  6516. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6517. // return
  6518. // }
  6519. // permissionMap[permissionKey] = getPermissionStr
  6520. // permissionStr += getPermissionStr
  6521. // }
  6522. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  6523. // permissionStr = permissionStr + ""
  6524. // }
  6525. // }
  6526. //}
  6527. // 2023-0420这是谁写的循环查,顺手优化了一下,手动狗头-_-~
  6528. //companyInfo, err := company.GetCompanyById(v.CompanyId)
  6529. //if err != nil {
  6530. // br.Msg = "导出失败"
  6531. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  6532. // return
  6533. //}
  6534. dataRow.AddCell().SetString(nameMap[v.CompanyId])
  6535. dataRow.AddCell().SetString(statusMap[v.CompanyId]) // 客户状态
  6536. //dataRow.AddCell().SetString(creditCode)
  6537. //dataRow.AddCell().SetString(regionType)
  6538. //
  6539. //dataRow.AddCell().SetString(companyType)
  6540. //industryValueCell := dataRow.AddCell()
  6541. //industryValueCell.SetStyle(style)
  6542. //industryValueCell.SetString(industryName)
  6543. //
  6544. //sellerValueCell := dataRow.AddCell()
  6545. //sellerValueCell.SetStyle(style)
  6546. //sellerValueCell.SetString(sellerName)
  6547. //
  6548. //statusValueCell := dataRow.AddCell()
  6549. //statusValueCell.SetStyle(style)
  6550. //statusValueCell.SetValue(status)
  6551. //
  6552. //timeLimitValueCell := dataRow.AddCell()
  6553. //timeLimitValueCell.SetStyle(style)
  6554. //timeLimitValueCell.SetValue(timeLimt)
  6555. //
  6556. //createTimeValueCell := dataRow.AddCell()
  6557. //createTimeValueCell.SetStyle(style)
  6558. //createTimeValueCell.SetValue(createTime)
  6559. //
  6560. //sourceValueCell := dataRow.AddCell()
  6561. //sourceValueCell.SetStyle(style)
  6562. //sourceValueCell.SetValue(source)
  6563. //
  6564. //permissionStrValueCell := dataRow.AddCell()
  6565. //permissionStrValueCell.SetStyle(style)
  6566. //permissionStrValueCell.SetValue(permissionStr)
  6567. }
  6568. }
  6569. err = xlsxFile.Save(downLoadnFilePath)
  6570. if err != nil {
  6571. br.Msg = "保存文件失败"
  6572. br.ErrMsg = "保存文件失败"
  6573. return
  6574. }
  6575. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  6576. downloadFileName := "联系人列表" + randStr + ".xlsx"
  6577. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  6578. defer func() {
  6579. os.Remove(downLoadnFilePath)
  6580. }()
  6581. br.Ret = 200
  6582. br.Success = true
  6583. br.Msg = "导出成功"
  6584. }
  6585. //func (this *CompanyController) CompanyUserExportOld() {
  6586. // br := new(models.BaseResponse).Init()
  6587. // defer func() {
  6588. // this.Data["json"] = br
  6589. // this.ServeJSON()
  6590. // }()
  6591. // sysUser := this.SysUser
  6592. // if sysUser == nil {
  6593. // br.Msg = "请登录"
  6594. // br.ErrMsg = "请登录,SysUser Is Empty"
  6595. // br.Ret = 408
  6596. // return
  6597. // }
  6598. // roleTypeCode := sysUser.RoleTypeCode
  6599. // status := this.GetString("Status")
  6600. // companyType := this.GetString("CompanyType")
  6601. // industryId, _ := this.GetInt("IndustryId")
  6602. // adminId := this.GetString("AdminId")
  6603. //
  6604. // chartPermissionIds := this.GetString("ChartPermissionIds")
  6605. // startDate := this.GetString("StartDate")
  6606. // endDate := this.GetString("EndDate")
  6607. // keyWord := this.GetString("KeyWord")
  6608. //
  6609. // var condition string
  6610. // var pars []interface{}
  6611. //
  6612. // if status != "" && status != "全部" {
  6613. // condition += ` AND b.status=? `
  6614. // pars = append(pars, status)
  6615. // }
  6616. // if companyType != "" {
  6617. // condition += ` AND b.product_name=? `
  6618. // pars = append(pars, companyType)
  6619. // }
  6620. //
  6621. // if industryId > 0 {
  6622. // condition += ` AND b.industry_id=? `
  6623. // pars = append(pars, industryId)
  6624. // }
  6625. //
  6626. // if adminId != "" {
  6627. // condition += ` AND b.seller_id IN (` + adminId + `) `
  6628. // }
  6629. //
  6630. // if startDate != "" {
  6631. // condition += ` AND b.start_date>=? `
  6632. // pars = append(pars, startDate)
  6633. // }
  6634. //
  6635. // if endDate != "" {
  6636. // condition += ` AND b.end_date>=? `
  6637. // pars = append(pars, endDate)
  6638. // }
  6639. //
  6640. // if keyWord != "" {
  6641. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR c.mobile LIKE '%` + keyWord + `%' OR c.email LIKE '%` + keyWord + `%') `
  6642. // }
  6643. //
  6644. // if chartPermissionIds != "" {
  6645. // companyIdStr, err := company.GetCompanyIdStr(chartPermissionIds)
  6646. // if err != nil {
  6647. // br.Msg = "获取失败"
  6648. // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
  6649. // return
  6650. // }
  6651. // if companyIdStr != "" {
  6652. // condition += ` AND a.company_id IN (` + companyIdStr + `) `
  6653. // }
  6654. // }
  6655. //
  6656. // //权限控制
  6657. // {
  6658. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  6659. // roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  6660. // if status != utils.COMPANY_STATUS_LOSE && status != utils.COMPANY_STATUS_FOREVER {
  6661. // condition += ` AND b.seller_id=? `
  6662. // pars = append(pars, sysUser.AdminId)
  6663. // }
  6664. // }
  6665. // if sysUser.Authority == 1 {
  6666. // condition += ` AND b.department_id=? `
  6667. // pars = append(pars, sysUser.DepartmentId)
  6668. // }
  6669. //
  6670. // if sysUser.Authority == 2 {
  6671. // condition += ` AND b.group_id=? `
  6672. // pars = append(pars, sysUser.GroupId)
  6673. // }
  6674. // }
  6675. // companyIds, err := company.GetExportCompanyIds(condition, pars)
  6676. // if err != nil {
  6677. // br.Msg = "导出失败"
  6678. // br.ErrMsg = "导出失败,Err:" + err.Error()
  6679. // return
  6680. // }
  6681. //
  6682. // dir, err := os.Executable()
  6683. // exPath := filepath.Dir(dir)
  6684. //
  6685. // downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  6686. // xlsxFile := xlsx.NewFile()
  6687. // if err != nil {
  6688. // br.Msg = "生成文件失败"
  6689. // br.ErrMsg = "生成文件失败"
  6690. // return
  6691. // }
  6692. // style := xlsx.NewStyle()
  6693. // alignment := xlsx.Alignment{
  6694. // Horizontal: "center",
  6695. // Vertical: "center",
  6696. // WrapText: true,
  6697. // }
  6698. //
  6699. // style.Alignment = alignment
  6700. // style.ApplyAlignment = true
  6701. //
  6702. // sheel, err := xlsxFile.AddSheet("联系人数据")
  6703. // if err != nil {
  6704. // br.Msg = "新增Sheet失败"
  6705. // br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  6706. // return
  6707. // }
  6708. //
  6709. // sheel.SetColWidth(7, 7, 10)
  6710. // sheel.SetColWidth(8, 10, 16)
  6711. // sheel.SetColWidth(9, 11, 20)
  6712. // sheel.SetColWidth(12, 12, 35)
  6713. // sheel.SetColWidth(13, 13, 15)
  6714. // sheel.SetColWidth(14, 14, 80)
  6715. // titleRow := sheel.AddRow()
  6716. // titleRow.AddCell().SetValue("联系人")
  6717. // titleRow.AddCell().SetValue("手机号")
  6718. // titleRow.AddCell().SetValue("邮箱")
  6719. // titleRow.AddCell().SetValue("职位")
  6720. // titleRow.AddCell().SetValue("是否决策人")
  6721. // titleRow.AddCell().SetValue("客户部门")
  6722. // titleRow.AddCell().SetValue("客户名称")
  6723. // titleRow.AddCell().SetValue("社会信用码")
  6724. // titleRow.AddCell().SetValue("所属区域")
  6725. // titleRow.AddCell().SetValue("客户类型")
  6726. //
  6727. // industryCell := titleRow.AddCell()
  6728. // industryCell.SetStyle(style)
  6729. // industryCell.Value = "所属行业"
  6730. //
  6731. // sellerCell := titleRow.AddCell()
  6732. // sellerCell.SetStyle(style)
  6733. // sellerCell.Value = "所属销售"
  6734. //
  6735. // statusCell := titleRow.AddCell()
  6736. // statusCell.SetStyle(style)
  6737. // statusCell.Value = "客户状态"
  6738. //
  6739. // timeLimtCell := titleRow.AddCell()
  6740. // timeLimtCell.SetStyle(style)
  6741. // timeLimtCell.Value = "服务期限"
  6742. //
  6743. // createTimeCell := titleRow.AddCell()
  6744. // createTimeCell.SetStyle(style)
  6745. // createTimeCell.Value = "创建时间"
  6746. //
  6747. // sourceCell := titleRow.AddCell()
  6748. // sourceCell.SetStyle(style)
  6749. // sourceCell.Value = "客户来源"
  6750. //
  6751. // permissionStyle := xlsx.NewStyle()
  6752. // permissionAlignment := xlsx.Alignment{
  6753. // Horizontal: "center",
  6754. // Vertical: "center",
  6755. // WrapText: true,
  6756. // }
  6757. //
  6758. // permissionStyle.Alignment = permissionAlignment
  6759. // permissionStyle.ApplyAlignment = true
  6760. //
  6761. // permissionCell := titleRow.AddCell()
  6762. // permissionCell.SetStyle(permissionStyle)
  6763. // permissionCell.Value = "阅读权限"
  6764. //
  6765. // if companyIds != "" {
  6766. // companyIds = strings.Trim(companyIds, ",")
  6767. // users, err := company.GetExportUser(companyIds)
  6768. // if err != nil {
  6769. // br.Msg = "导出失败"
  6770. // br.ErrMsg = "获取联系人信息失败,Err:" + err.Error()
  6771. // return
  6772. // }
  6773. // cpMap := make(map[int][]*company.ExportCompanyProduct)
  6774. // permissionMap := make(map[string]string)
  6775. // for _, v := range users {
  6776. // dataRow := sheel.AddRow()
  6777. // dataRow.SetHeight(20)
  6778. // dataRow.AddCell().SetString(v.RealName)
  6779. // dataRow.AddCell().SetString(v.Mobile)
  6780. // dataRow.AddCell().SetString(v.Email)
  6781. // dataRow.AddCell().SetString(v.Position)
  6782. // if v.IsMaker == 1 {
  6783. // dataRow.AddCell().SetString("是")
  6784. // } else {
  6785. // dataRow.AddCell().SetString("否")
  6786. // }
  6787. // dataRow.AddCell().SetString(v.DepartmentName)
  6788. // cpList := make([]*company.ExportCompanyProduct, 1)
  6789. // if cps, ok := cpMap[v.CompanyId]; ok {
  6790. // cpList = cps
  6791. // } else {
  6792. // companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  6793. // if err != nil {
  6794. // br.Msg = "导出失败"
  6795. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  6796. // return
  6797. // }
  6798. // cpMap[v.CompanyId] = companyProduct
  6799. // cpList = companyProduct
  6800. // }
  6801. // //productList, err := company.GetExportCompanyProduct(v.CompanyId)
  6802. // //if err!=nil {
  6803. // // fmt.Println("导出失败,Err:"+err.Error())
  6804. // // return
  6805. // //}
  6806. // var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, creditCode, regionType string
  6807. //
  6808. // for ck, cv := range cpList {
  6809. // companyName = cv.CompanyName
  6810. // creditCode = cv.CreditCode
  6811. // regionType = cv.RegionType
  6812. // if ck >= 1 {
  6813. // companyType = companyType + "/" + cv.ProductName
  6814. // status = status + "/" + cv.Status
  6815. // } else {
  6816. // companyType = cv.ProductName
  6817. // status = cv.Status
  6818. // }
  6819. // if cv.ProductId == 1 {
  6820. // industryName = "ficc:" + cv.IndustryName
  6821. // sellerName = "ficc:" + cv.SellerName
  6822. // startDateStr := cv.StartDate.Format("2006/01/02")
  6823. // endDateStr := cv.EndDate.Format("2006/01/02")
  6824. // if startDateStr != "0001/01/01" {
  6825. // timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  6826. // } else {
  6827. // timeLimt = ""
  6828. // }
  6829. // createTime = "ficc:" + cv.CreateTime
  6830. // source = "ficc:" + cv.Source
  6831. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6832. //
  6833. // permissionStr = "ficc:"
  6834. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6835. // permissionStr += newPermissionStr
  6836. // } else {
  6837. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6838. // if err != nil {
  6839. // br.Msg = "导出失败"
  6840. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6841. // return
  6842. // }
  6843. // permissionMap[permissionKey] = getPermissionStr
  6844. // permissionStr += getPermissionStr
  6845. // }
  6846. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  6847. // permissionStr = ""
  6848. // }
  6849. // } else {
  6850. // industryName = industryName + "\n" + "权益:" + cv.IndustryName
  6851. // sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  6852. // startDateStr := cv.StartDate.Format("2006/01/02")
  6853. // endDateStr := cv.EndDate.Format("2006/01/02")
  6854. //
  6855. // if startDateStr != "0001/01/01" {
  6856. // timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  6857. // } else {
  6858. // timeLimt = timeLimt + ""
  6859. // }
  6860. // createTime = createTime + "\n" + "权益:" + cv.CreateTime
  6861. // source = source + "\n" + "权益:" + cv.Source
  6862. //
  6863. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6864. // if permissionStr != "" {
  6865. // permissionStr = permissionStr + "\n" + "权益:"
  6866. // } else {
  6867. // permissionStr = "权益:"
  6868. // }
  6869. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6870. // permissionStr += newPermissionStr
  6871. // } else {
  6872. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6873. // if err != nil {
  6874. // br.Msg = "导出失败"
  6875. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6876. // return
  6877. // }
  6878. // permissionMap[permissionKey] = getPermissionStr
  6879. // permissionStr += getPermissionStr
  6880. // }
  6881. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  6882. // permissionStr = permissionStr + ""
  6883. // }
  6884. // }
  6885. // }
  6886. // dataRow.AddCell().SetString(companyName)
  6887. // dataRow.AddCell().SetString(creditCode)
  6888. // dataRow.AddCell().SetString(regionType)
  6889. //
  6890. // dataRow.AddCell().SetString(companyType)
  6891. // industryValueCell := dataRow.AddCell()
  6892. // industryValueCell.SetStyle(style)
  6893. // industryValueCell.SetString(industryName)
  6894. //
  6895. // sellerValueCell := dataRow.AddCell()
  6896. // sellerValueCell.SetStyle(style)
  6897. // sellerValueCell.SetString(sellerName)
  6898. //
  6899. // statusValueCell := dataRow.AddCell()
  6900. // statusValueCell.SetStyle(style)
  6901. // statusValueCell.SetValue(status)
  6902. //
  6903. // timeLimitValueCell := dataRow.AddCell()
  6904. // timeLimitValueCell.SetStyle(style)
  6905. // timeLimitValueCell.SetValue(timeLimt)
  6906. //
  6907. // createTimeValueCell := dataRow.AddCell()
  6908. // createTimeValueCell.SetStyle(style)
  6909. // createTimeValueCell.SetValue(createTime)
  6910. //
  6911. // sourceValueCell := dataRow.AddCell()
  6912. // sourceValueCell.SetStyle(style)
  6913. // sourceValueCell.SetValue(source)
  6914. //
  6915. // permissionStrValueCell := dataRow.AddCell()
  6916. // permissionStrValueCell.SetStyle(style)
  6917. // permissionStrValueCell.SetValue(permissionStr)
  6918. // }
  6919. // }
  6920. // err = xlsxFile.Save(downLoadnFilePath)
  6921. // if err != nil {
  6922. // br.Msg = "保存文件失败"
  6923. // br.ErrMsg = "保存文件失败"
  6924. // return
  6925. // }
  6926. // randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  6927. // downloadFileName := "联系人列表" + randStr + ".xlsx"
  6928. // this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  6929. // defer func() {
  6930. // os.Remove(downLoadnFilePath)
  6931. // }()
  6932. // br.Ret = 200
  6933. // br.Success = true
  6934. // br.Msg = "导出成功"
  6935. //}
  6936. // @Title 冻结客户
  6937. // @Description 冻结客户接口
  6938. // @Param request body company.CompanyFreezeReq true "type json string"
  6939. // @Success Ret=200 冻结成功
  6940. // @router /freeze [post]
  6941. func (this *CompanyController) Freeze() {
  6942. br := new(models.BaseResponse).Init()
  6943. defer func() {
  6944. this.Data["json"] = br
  6945. this.ServeJSON()
  6946. }()
  6947. sysUser := this.SysUser
  6948. if sysUser == nil {
  6949. br.Msg = "请登录"
  6950. br.ErrMsg = "请登录,SysUser Is Empty"
  6951. br.Ret = 408
  6952. return
  6953. }
  6954. var req company.CompanyFreezeReq
  6955. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  6956. if err != nil {
  6957. br.Msg = "参数解析异常!"
  6958. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  6959. return
  6960. }
  6961. if req.CompanyId <= 0 {
  6962. br.Msg = "参数错误!"
  6963. br.ErrMsg = "客户id小于等于0"
  6964. return
  6965. }
  6966. productId := 0
  6967. productName := ""
  6968. if req.CompanyType == utils.COMPANY_CLASSIFY_FICC {
  6969. productId = 1
  6970. productName = "ficc"
  6971. } else if req.CompanyType == utils.COMPANY_CLASSIFY_RAI {
  6972. productId = 2
  6973. productName = "权益"
  6974. } else {
  6975. productId = 3
  6976. productName = "佣金客户"
  6977. }
  6978. if req.CompanyId <= 0 {
  6979. br.Msg = "参数异常!"
  6980. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  6981. return
  6982. }
  6983. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  6984. if err != nil {
  6985. br.Msg = "查询该客户产品异常!"
  6986. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  6987. return
  6988. }
  6989. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  6990. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  6991. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  6992. return
  6993. }
  6994. //查询客户的产品权限
  6995. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, productId)
  6996. if err != nil {
  6997. br.Msg = "查询客户的产品权限异常"
  6998. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  6999. return
  7000. }
  7001. err = company.CompanyFreeze(req.CompanyId, productId, req.Remark)
  7002. if err != nil {
  7003. br.Msg = "冻结失败!"
  7004. br.ErrMsg = "冻结失败,Err:" + err.Error()
  7005. return
  7006. }
  7007. //新增操作记录
  7008. {
  7009. approveContent := req.Remark
  7010. remark := "冻结客户"
  7011. operation := "freeze"
  7012. services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
  7013. productName, sysUser.RealName, remark, operation, approveContent, sysUser.RealName, "", "冻结")
  7014. //新增产品权限冻结操作日志
  7015. for _, companyReportPermission := range companyReportPermissionList {
  7016. record := company_report_permission_log.CompanyReportPermissionLog{
  7017. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  7018. CompanyId: companyReportPermission.CompanyId,
  7019. ProductId: productId,
  7020. ProductName: companyReportPermission.ProductName,
  7021. SysUserId: sysUser.AdminId,
  7022. SysUserName: sysUser.RealName,
  7023. Remark: "冻结客户",
  7024. Operation: "freeze",
  7025. Status: companyReportPermission.Status,
  7026. CreateTime: time.Now(),
  7027. }
  7028. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  7029. }
  7030. }
  7031. br.Ret = 200
  7032. br.Success = true
  7033. br.Msg = "领取成功"
  7034. }
  7035. // @Title 获取客户权限
  7036. // @Description 获取客户权限接口
  7037. // @Param CompanyId query int true "用户id"
  7038. // @Success 200 {object} company.CompanyPermissionResp
  7039. // @router /getCompanyPermission [get]
  7040. func (this *CompanyController) PermissionList() {
  7041. br := new(models.BaseResponse).Init()
  7042. defer func() {
  7043. this.Data["json"] = br
  7044. this.ServeJSON()
  7045. }()
  7046. sysUser := this.SysUser
  7047. if sysUser == nil {
  7048. br.Msg = "请登录"
  7049. br.ErrMsg = "请登录,SysUser Is Empty"
  7050. br.Ret = 408
  7051. return
  7052. }
  7053. companyId, _ := this.GetInt("CompanyId")
  7054. if companyId <= 0 {
  7055. br.Msg = "参数错误"
  7056. br.ErrMsg = "客户参数小于等于0"
  7057. return
  7058. }
  7059. //返回基础参数
  7060. resp := new(company.CompanyPermissionResp)
  7061. //客户类型map
  7062. classifyMap := make(map[string]int)
  7063. classifyMap["ficc"] = 1
  7064. classifyMap["权益"] = 2
  7065. roleTypeCode := sysUser.RoleTypeCode
  7066. var companySlice []string
  7067. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  7068. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  7069. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  7070. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
  7071. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM ||
  7072. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
  7073. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_RESEARCHR {
  7074. companySlice = append(companySlice, "ficc")
  7075. } else if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  7076. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN ||
  7077. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  7078. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  7079. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT ||
  7080. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_RESEARCHR {
  7081. companySlice = append(companySlice, "权益")
  7082. }
  7083. for _, companyType := range companySlice {
  7084. //子权限切片集合
  7085. var permissionClassifyArr []string
  7086. if companyType == "ficc" {
  7087. for _, v := range utils.PermissionFiccClassifyArr {
  7088. permissionClassifyArr = append(permissionClassifyArr, v)
  7089. }
  7090. } else {
  7091. permissionClassifyArr = append(permissionClassifyArr, "权益")
  7092. }
  7093. //遍历获取
  7094. for _, v := range permissionClassifyArr {
  7095. checkList := make([]int, 0)
  7096. plist := new(company.PermissionLookList)
  7097. items, err := company.GetPermissionLookItems(classifyMap[companyType], v)
  7098. if err != nil {
  7099. br.Msg = "获取失败"
  7100. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  7101. return
  7102. }
  7103. mapPermissionCheck := make(map[string]int)
  7104. for i, n := range items {
  7105. item := items[i]
  7106. count, err := company.GetCompanyPermissionCheck(companyId, n.ChartPermissionId)
  7107. if err != nil {
  7108. br.Msg = "获取失败"
  7109. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  7110. return
  7111. }
  7112. //合并主观客观勾选的权限
  7113. if count > 0 && mapPermissionCheck[n.PermissionName] == 0 {
  7114. checkList = append(checkList, n.ChartPermissionId)
  7115. mapPermissionCheck[n.PermissionName] = n.ChartPermissionId
  7116. }
  7117. permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  7118. if err != nil && err.Error() != utils.ErrNoRow() {
  7119. br.Msg = "获取失败"
  7120. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  7121. return
  7122. }
  7123. if permission != nil && permission.ChartPermissionId > 0 {
  7124. items[i].StartDate = permission.StartDate
  7125. items[i].EndDate = permission.EndDate
  7126. items[i].Status = permission.Status
  7127. //判断主观、客观
  7128. if items[i].PermissionType == 1 {
  7129. items[i].PermissionTypeName = "主观"
  7130. } else if items[i].PermissionType == 2 {
  7131. items[i].PermissionTypeName = "客观"
  7132. }
  7133. }
  7134. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  7135. endDateTime = endDateTime.AddDate(0, 0, 1)
  7136. sub := endDateTime.Sub(time.Now())
  7137. if sub < 0 {
  7138. sub = 0
  7139. }
  7140. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  7141. items[i].ExpireDay = expireDay
  7142. items[i].ClassifyName = v
  7143. //if n.PermissionType == 1 {
  7144. // items[i].PermissionTypeName = "主观"
  7145. //} else if n.PermissionType == 2 {
  7146. // items[i].PermissionTypeName = "客观"
  7147. //}
  7148. }
  7149. //合并主观客观
  7150. mapPermissionName := make(map[string]int)
  7151. for _, v := range items {
  7152. if mapPermissionName[v.PermissionName] == 0 {
  7153. //plist.Items = append(plist.Items, v)
  7154. //mapPermissionName[v.PermissionName] = v.ChartPermissionId
  7155. // CRM8.8-只有客观的时候回显
  7156. if mapPermissionCheck[v.PermissionName] == 0 || (mapPermissionCheck[v.PermissionName] > 0 && v.ChartPermissionId == mapPermissionCheck[v.PermissionName]) {
  7157. plist.Items = append(plist.Items, v)
  7158. mapPermissionName[v.PermissionName] = v.ChartPermissionId
  7159. }
  7160. }
  7161. }
  7162. plist.ClassifyName = v
  7163. plist.CheckList = checkList
  7164. if companyType == "ficc" {
  7165. resp.FiccPermissionList = append(resp.FiccPermissionList, plist)
  7166. } else {
  7167. resp.PermissionList = append(resp.PermissionList, plist)
  7168. }
  7169. }
  7170. }
  7171. br.Ret = 200
  7172. br.Success = true
  7173. br.Msg = "获取成功"
  7174. br.Data = resp
  7175. }
  7176. // @Title 获取客户来源列表
  7177. // @Description 获取客户来源列表
  7178. // @Success 200 {object} models.CompanySourceListResp
  7179. // @router /getCompanySourceList [get]
  7180. func (this *CompanyController) CompanySourceList() {
  7181. br := new(models.BaseResponse).Init()
  7182. defer func() {
  7183. this.Data["json"] = br
  7184. this.ServeJSON()
  7185. }()
  7186. sysUser := this.SysUser
  7187. if sysUser == nil {
  7188. br.Msg = "请登录"
  7189. br.ErrMsg = "请登录,SysUser Is Empty"
  7190. br.Ret = 408
  7191. return
  7192. }
  7193. list, err := models.GetAllCompanySourceList()
  7194. if err != nil {
  7195. br.Msg = "查询失败"
  7196. br.ErrMsg = "查询异常:" + err.Error()
  7197. return
  7198. }
  7199. br.Ret = 200
  7200. br.Success = true
  7201. br.Msg = "获取成功"
  7202. br.Data = models.CompanySourceListResp{
  7203. List: list,
  7204. }
  7205. }
  7206. // @Title 获取客户的合同列表
  7207. // @Description 获取客户合同列表接口
  7208. // @Param CompanyId query int true "用户id"
  7209. // @Param CompanyType query string false "用户类型:可取范围:ficc,权益"
  7210. // @Param Status query int true "合同审核结果,枚举值:`0`,`1`; 0:待审核,1:审核通过"
  7211. // @Success 200 {object} company.CompanyPermissionResp
  7212. // @router /getCompanyContract [get]
  7213. func (this *CompanyController) ContractList() {
  7214. br := new(models.BaseResponse).Init()
  7215. defer func() {
  7216. this.Data["json"] = br
  7217. this.ServeJSON()
  7218. }()
  7219. sysUser := this.SysUser
  7220. if sysUser == nil {
  7221. br.Msg = "请登录"
  7222. br.ErrMsg = "请登录,SysUser Is Empty"
  7223. br.Ret = 408
  7224. return
  7225. }
  7226. companyId, _ := this.GetInt("CompanyId")
  7227. if companyId <= 0 {
  7228. br.Msg = "参数错误"
  7229. br.ErrMsg = "客户参数小于等于0"
  7230. return
  7231. }
  7232. //合同状态
  7233. status, _ := this.GetInt("Status")
  7234. //产品类型
  7235. companyType := this.GetString("CompanyType")
  7236. var condition string
  7237. var pars []interface{}
  7238. //产品类型
  7239. if companyType == "" {
  7240. productId := services.GetProductId(sysUser.RoleTypeCode)
  7241. if productId != 0 {
  7242. condition += " AND product_id = ?"
  7243. pars = append(pars, productId)
  7244. }
  7245. } else {
  7246. if companyType == "ficc" {
  7247. condition += " AND product_id = ?"
  7248. pars = append(pars, 1)
  7249. } else {
  7250. condition += " AND product_id = ?"
  7251. pars = append(pars, 2)
  7252. }
  7253. }
  7254. if status != 0 {
  7255. condition += " AND status = ?"
  7256. pars = append(pars, status)
  7257. }
  7258. list, err := company.GetCompanyContractListByCompanyId(companyId, condition, pars)
  7259. if err != nil {
  7260. br.Msg = "查询失败"
  7261. br.ErrMsg = "查询异常:" + err.Error()
  7262. return
  7263. }
  7264. br.Ret = 200
  7265. br.Success = true
  7266. br.Msg = "获取成功"
  7267. br.Data = list
  7268. }
  7269. // @Title 获取客户所属销售
  7270. // @Description 根据客户id获取客户所属销售
  7271. // @Param CompanyId query int true "客户id"
  7272. // @Success 200 {object} response.CompanySellerListResp
  7273. // @router /getCompanySellerList [get]
  7274. func (this *CompanyUserController) GetCompanySellerList() {
  7275. br := new(models.BaseResponse).Init()
  7276. defer func() {
  7277. this.Data["json"] = br
  7278. this.ServeJSON()
  7279. }()
  7280. sysUser := this.SysUser
  7281. if sysUser == nil {
  7282. br.Msg = "请登录"
  7283. br.ErrMsg = "请登录,SysUser Is Empty"
  7284. br.Ret = 408
  7285. return
  7286. }
  7287. companyId, _ := this.GetInt("CompanyId")
  7288. //item := make([]*company.CompanyItem, 0)
  7289. list, err := company.GetCompanySellerByCompanyId(companyId)
  7290. if err != nil && err.Error() != utils.ErrNoRow() {
  7291. br.Msg = "获取失败"
  7292. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  7293. return
  7294. }
  7295. resp := response.CompanySellerListResp{
  7296. List: list,
  7297. }
  7298. //resp.List = list
  7299. br.Ret = 200
  7300. br.Success = true
  7301. br.Msg = "获取成功"
  7302. br.Data = resp
  7303. }
  7304. // GetTryOutCompanyList
  7305. // @Title 获取销售今日待办数据
  7306. // @Description 获取销售今日待办接口
  7307. // @Param CompanyName query string false "客户名称"
  7308. // @Param ReasonStatus query int false "续约情况说明状态:-1:未填写,0:全部,1:已填写"
  7309. // @Param PageSize query int true "每页数据条数"
  7310. // @Param CurrentIndex query int true "当前页页码,从1开始"
  7311. // @Success 200 {object} response.TryOutCompanyListResp
  7312. // @router /getTryOutCompanyList [get]
  7313. func (this *CompanyController) GetTryOutCompanyList() {
  7314. br := new(models.BaseResponse).Init()
  7315. defer func() {
  7316. this.Data["json"] = br
  7317. this.ServeJSON()
  7318. }()
  7319. sysUser := this.SysUser
  7320. if sysUser == nil {
  7321. br.Msg = "请登录"
  7322. br.ErrMsg = "请登录,SysUser Is Empty"
  7323. br.Ret = 408
  7324. return
  7325. }
  7326. companyName := this.GetString("CompanyName")
  7327. reasonStatus, _ := this.GetInt("ReasonStatus", 0)
  7328. pageSize, _ := this.GetInt("PageSize")
  7329. currentIndex, _ := this.GetInt("CurrentIndex")
  7330. productId := services.GetProductId(sysUser.RoleTypeCode)
  7331. var startSize int
  7332. if pageSize <= 0 {
  7333. pageSize = utils.PageSize20
  7334. }
  7335. if currentIndex <= 0 {
  7336. currentIndex = 1
  7337. }
  7338. startSize = paging.StartIndex(currentIndex, pageSize)
  7339. var condition string
  7340. var pars []interface{}
  7341. //sellerId, productId int, tryOutTime time.Time, tryOutReason string
  7342. var tryOutTime, lastDescriptionTime time.Time
  7343. if productId == 1 {
  7344. //ficc
  7345. interval := cache.GetIntervalFromCrmConfig("try_out_time_intervals")
  7346. tryOutTime = time.Now().AddDate(0, 0, -interval)
  7347. interval = cache.GetIntervalFromCrmConfig("last_description_time_intervals")
  7348. lastDescriptionTime = time.Now().AddDate(0, 0, -interval)
  7349. } else {
  7350. //权益
  7351. interval := cache.GetIntervalFromCrmConfig("rai_try_out_time_intervals")
  7352. tryOutTime = time.Now().AddDate(0, 0, -interval)
  7353. interval = cache.GetIntervalFromCrmConfig("rai_last_description_time_intervals")
  7354. lastDescriptionTime = time.Now().AddDate(0, 0, -interval)
  7355. }
  7356. if productId > 0 {
  7357. condition += ` and product_id=? `
  7358. pars = append(pars, productId)
  7359. }
  7360. //客户名称模糊搜索
  7361. if companyName != "" {
  7362. condition += ` and b.company_name like "%` + companyName + `%" `
  7363. }
  7364. //续约情况说明(-1:未填写,0:全部,1:已填写)
  7365. switch reasonStatus {
  7366. case -1:
  7367. 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) `
  7368. pars = append(pars, sysUser.AdminId, tryOutTime, lastDescriptionTime)
  7369. case 1:
  7370. 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) `
  7371. pars = append(pars, sysUser.AdminId, tryOutTime)
  7372. default:
  7373. 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) `
  7374. pars = append(pars, sysUser.AdminId, tryOutTime, lastDescriptionTime)
  7375. }
  7376. total := 0
  7377. list := make([]*company.TryOutCompanyList, 0)
  7378. 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}
  7379. if strings.Contains(strings.Join(ignoreStrs, ","), sysUser.RoleTypeCode) {
  7380. //排除已经签署续约合同的
  7381. notSql := ``
  7382. if productId > 0 {
  7383. notSql = fmt.Sprint(` and product_id = `, productId)
  7384. }
  7385. condition += `and a.company_id not in (select company_id from company_contract where contract_type ="续约合同" and start_date >now() and status = 1 ` + notSql + `) `
  7386. tmpTotal, err := company.GetTryOutCompanyCount(condition, pars)
  7387. if err != nil {
  7388. br.Msg = "获取失败"
  7389. br.ErrMsg = "获取总数失败失败,Err:" + err.Error()
  7390. return
  7391. }
  7392. tmpList, err := company.GetTryOutCompanyList(condition, pars, startSize, pageSize)
  7393. if err != nil {
  7394. br.Msg = "获取失败"
  7395. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  7396. return
  7397. }
  7398. total = tmpTotal
  7399. list = tmpList
  7400. }
  7401. if len(list) > 0 {
  7402. for k, item := range list {
  7403. endTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  7404. endTime = endTime.AddDate(0, 0, 1)
  7405. sub := endTime.Sub(time.Now())
  7406. if sub < 0 {
  7407. sub = 0
  7408. }
  7409. list[k].ExpireDays = int(sub.Hours() / 24)
  7410. }
  7411. }
  7412. page := paging.GetPaging(currentIndex, pageSize, total)
  7413. resp := response.TryOutCompanyListResp{
  7414. List: list,
  7415. Paging: page,
  7416. }
  7417. br.Ret = 200
  7418. br.Success = true
  7419. br.Msg = "获取成功"
  7420. br.Data = resp
  7421. }
  7422. // EditTryOutCompanyReason
  7423. // @Title 编辑续约说明情况
  7424. // @Description 编辑续约说明情况接口
  7425. // @Param request body company.RenewalReasonReq true "type json string"
  7426. // @Success 200 编辑成功
  7427. // @router /editTryOutCompanyReason [post]
  7428. func (this *CompanyController) EditTryOutCompanyReason() {
  7429. br := new(models.BaseResponse).Init()
  7430. defer func() {
  7431. this.Data["json"] = br
  7432. this.ServeJSON()
  7433. }()
  7434. sysUser := this.SysUser
  7435. if sysUser == nil {
  7436. br.Msg = "请登录"
  7437. br.ErrMsg = "请登录,SysUser Is Empty"
  7438. br.Ret = 408
  7439. return
  7440. }
  7441. var req company.RenewalReasonReq
  7442. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  7443. if err != nil {
  7444. br.Msg = "参数解析异常!"
  7445. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  7446. return
  7447. }
  7448. if req.CompanyId <= 0 {
  7449. br.Msg = "参数缺失"
  7450. br.ErrMsg = "参数缺失,客户编号未传!"
  7451. return
  7452. }
  7453. if req.ProductId <= 0 {
  7454. br.Msg = "参数缺失"
  7455. br.ErrMsg = "参数缺失,产品编号未传!"
  7456. return
  7457. }
  7458. if req.Remark == "" {
  7459. br.Msg = "参数缺失"
  7460. br.ErrMsg = "参数缺失,续约情况说明未传!"
  7461. return
  7462. }
  7463. /*if req.RenewalTodo == "" && req.Renew == 0 {
  7464. br.Msg = "参数缺失"
  7465. br.ErrMsg = "参数缺失,待办事项说明未传!"
  7466. return
  7467. }*/
  7468. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  7469. if err != nil {
  7470. br.Msg = "查询客户异常"
  7471. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  7472. return
  7473. }
  7474. if companyProduct.SellerId != sysUser.AdminId {
  7475. br.Msg = "客户异常,没有该客户的操作权限"
  7476. br.ErrMsg = "客户异常,没有该客户的操作权限"
  7477. return
  7478. }
  7479. renewalReason := company.CompanyRenewalReason{
  7480. CompanyRenewalReasonId: 0,
  7481. CompanyId: companyProduct.CompanyId,
  7482. ProductId: companyProduct.ProductId,
  7483. ProductName: companyProduct.ProductName,
  7484. CompanyName: companyProduct.CompanyName,
  7485. TryOutTime: companyProduct.TryOutTime,
  7486. RenewalReason: req.Remark,
  7487. RenewalTodo: req.RenewalTodo,
  7488. LastDescriptionTime: companyProduct.LastDescriptionTime,
  7489. EndDays: companyProduct.ContractEndDate,
  7490. ExpirationTimeExceeded: 0,
  7491. RenewalIntention: req.Renew,
  7492. CreateTime: time.Now(),
  7493. }
  7494. endTime, err := company.GetTryOutTimeFromOperationRecord(renewalReason.CompanyId)
  7495. if err != nil {
  7496. br.Msg = "查询该客户转试用时间异常!"
  7497. br.ErrMsg = "查询该客户转试用时间异常,err:" + err.Error()
  7498. return
  7499. }
  7500. endDateTime, err := time.Parse(utils.FormatDateTime, *endTime)
  7501. if err != nil {
  7502. br.Msg = "时间格式化异常!"
  7503. br.ErrMsg = "时间格式化异常,err:" + err.Error()
  7504. return
  7505. }
  7506. endDate := endDateTime.Format(utils.FormatDate)
  7507. endDateTime, _ = time.Parse(utils.FormatDate, endDate)
  7508. sub := time.Now().Sub(endDateTime)
  7509. renewalReason.ExpirationTimeExceeded = int(sub.Hours() / 24)
  7510. err = company.AddRenewalReason(&renewalReason)
  7511. if err != nil {
  7512. br.Msg = "新增续约情况说明操作异常!"
  7513. br.ErrMsg = "新增续约情况说明操作异常,err:" + err.Error()
  7514. return
  7515. }
  7516. companyProduct.RenewalIntention = req.Renew
  7517. err = company.EditTryOutCompanyReason(companyProduct, req.Remark, req.RenewalTodo)
  7518. if err != nil {
  7519. br.Msg = "更新客户未续约异常!"
  7520. br.ErrMsg = "更新客户未续约异常,err:" + err.Error()
  7521. return
  7522. }
  7523. if req.Renew == 1 {
  7524. productName := ""
  7525. if req.ProductId == 1 {
  7526. productName = "ficc"
  7527. } else if req.ProductId == 2 {
  7528. productName = "权益"
  7529. } else {
  7530. productName = "佣金客户"
  7531. }
  7532. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  7533. if err != nil {
  7534. br.Msg = "查询该客户产品异常!"
  7535. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  7536. return
  7537. }
  7538. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  7539. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  7540. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  7541. return
  7542. }
  7543. //查询客户的产品权限
  7544. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, req.ProductId)
  7545. if err != nil {
  7546. br.Msg = "查询客户的产品权限异常"
  7547. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  7548. return
  7549. }
  7550. err = company.CompanyFreeze(req.CompanyId, req.ProductId, req.Remark)
  7551. if err != nil {
  7552. br.Msg = "冻结失败!"
  7553. br.ErrMsg = "冻结失败,Err:" + err.Error()
  7554. return
  7555. }
  7556. //新增操作记录
  7557. go func() {
  7558. time.Sleep(time.Second)
  7559. approveContent := req.Remark
  7560. remark := "冻结客户"
  7561. operation := "freeze"
  7562. _ = services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  7563. productName, "超级管理员", remark, operation, approveContent, sysUser.RealName, "", "冻结")
  7564. //新增产品权限冻结操作日志
  7565. for _, companyReportPermission := range companyReportPermissionList {
  7566. record := company_report_permission_log.CompanyReportPermissionLog{
  7567. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  7568. CompanyId: companyReportPermission.CompanyId,
  7569. ProductId: req.ProductId,
  7570. ProductName: companyReportPermission.ProductName,
  7571. SysUserId: sysUser.AdminId,
  7572. SysUserName: "超级管理员",
  7573. Remark: "冻结客户",
  7574. Operation: "freeze",
  7575. Status: companyReportPermission.Status,
  7576. CreateTime: time.Now(),
  7577. }
  7578. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  7579. }
  7580. }()
  7581. }
  7582. approveContent := req.Remark
  7583. approveContentExtra := req.RenewalTodo
  7584. remark := "新增续约说明"
  7585. operation := "edit_renewal_reason"
  7586. _ = services.AddCompanyOperationRecordMore(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  7587. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, approveContentExtra, sysUser.RealName, "", companyProduct.Status)
  7588. items, err := company.ReadCompanyOperationRecord(req.CompanyId)
  7589. if err != nil {
  7590. br.Msg = "编辑失败"
  7591. br.ErrMsg = "编辑失败,Err:" + err.Error()
  7592. return
  7593. }
  7594. if len(items) > 0 {
  7595. record := new(company.CompanyOperationRecord)
  7596. record.Id = items[0].Id
  7597. record.ApproveContent = req.Remark
  7598. record.ApproveContentExtra = req.RenewalTodo
  7599. _, err = company.UpdateCompanyOperationRecord(record)
  7600. if err != nil {
  7601. br.Msg = "编辑失败"
  7602. br.ErrMsg = "编辑失败,Err:" + err.Error()
  7603. return
  7604. }
  7605. } else {
  7606. br.Msg = "编辑失败"
  7607. br.ErrMsg = "编辑失败,未查询到转试用记录"
  7608. return
  7609. }
  7610. br.Ret = 200
  7611. br.Success = true
  7612. br.Msg = "编辑成功"
  7613. }
  7614. // AddTryOutCompanyReason
  7615. // @Title 新增续约说明情况
  7616. // @Description 新增续约说明情况接口
  7617. // @Param request body company.RenewalReasonReq true "type json string"
  7618. // @Success 200 编辑成功
  7619. // @router /addTryOutCompanyReason [post]
  7620. func (this *CompanyController) AddTryOutCompanyReason() {
  7621. br := new(models.BaseResponse).Init()
  7622. defer func() {
  7623. this.Data["json"] = br
  7624. this.ServeJSON()
  7625. }()
  7626. sysUser := this.SysUser
  7627. if sysUser == nil {
  7628. br.Msg = "请登录"
  7629. br.ErrMsg = "请登录,SysUser Is Empty"
  7630. br.Ret = 408
  7631. return
  7632. }
  7633. var req company.RenewalReasonReq
  7634. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  7635. if err != nil {
  7636. br.Msg = "参数解析异常!"
  7637. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  7638. return
  7639. }
  7640. if req.CompanyId <= 0 {
  7641. br.Msg = "参数缺失"
  7642. br.ErrMsg = "参数缺失,客户编号未传!"
  7643. return
  7644. }
  7645. if req.ProductId <= 0 {
  7646. br.Msg = "参数缺失"
  7647. br.ErrMsg = "参数缺失,产品编号未传!"
  7648. return
  7649. }
  7650. if req.Remark == "" {
  7651. br.Msg = "参数缺失"
  7652. br.ErrMsg = "参数缺失,续约情况说明未传!"
  7653. return
  7654. }
  7655. if req.RenewalTodo == "" && req.Renew == 0 {
  7656. br.Msg = "参数缺失"
  7657. br.ErrMsg = "参数缺失,待办事项说明未传!"
  7658. return
  7659. }
  7660. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  7661. if err != nil {
  7662. br.Msg = "查询客户异常"
  7663. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  7664. return
  7665. }
  7666. if companyProduct.SellerId != sysUser.AdminId {
  7667. br.Msg = "客户异常,没有该客户的操作权限"
  7668. br.ErrMsg = "客户异常,没有该客户的操作权限"
  7669. return
  7670. }
  7671. renewalReason := company.CompanyRenewalReason{
  7672. CompanyRenewalReasonId: 0,
  7673. CompanyId: companyProduct.CompanyId,
  7674. ProductId: companyProduct.ProductId,
  7675. ProductName: companyProduct.ProductName,
  7676. CompanyName: companyProduct.CompanyName,
  7677. TryOutTime: companyProduct.TryOutTime,
  7678. RenewalReason: req.Remark,
  7679. RenewalTodo: req.RenewalTodo,
  7680. LastDescriptionTime: companyProduct.LastDescriptionTime,
  7681. EndDays: companyProduct.ContractEndDate,
  7682. ExpirationTimeExceeded: 0,
  7683. RenewalIntention: req.Renew,
  7684. CreateTime: time.Now(),
  7685. }
  7686. endTime, err := company.GetTryOutTimeFromOperationRecord(renewalReason.CompanyId)
  7687. if err != nil {
  7688. br.Msg = "查询该客户转试用时间异常!"
  7689. br.ErrMsg = "查询该客户转试用时间异常,err:" + err.Error()
  7690. return
  7691. }
  7692. endDateTime, err := time.Parse(utils.FormatDateTime, *endTime)
  7693. if err != nil {
  7694. br.Msg = "时间格式化异常!"
  7695. br.ErrMsg = "时间格式化异常,err:" + err.Error()
  7696. return
  7697. }
  7698. endDate := endDateTime.Format(utils.FormatDate)
  7699. endDateTime, _ = time.Parse(utils.FormatDate, endDate)
  7700. sub := time.Now().Sub(endDateTime)
  7701. renewalReason.ExpirationTimeExceeded = int(sub.Hours() / 24)
  7702. err = company.AddRenewalReason(&renewalReason)
  7703. if err != nil {
  7704. br.Msg = "新增续约情况说明操作异常!"
  7705. br.ErrMsg = "新增续约情况说明操作异常,err:" + err.Error()
  7706. return
  7707. }
  7708. companyProduct.RenewalIntention = req.Renew
  7709. err = company.EditTryOutCompanyReason(companyProduct, req.Remark, req.RenewalTodo)
  7710. if err != nil {
  7711. br.Msg = "更新客户续约情况说明异常!"
  7712. br.ErrMsg = "更新客户续约情况说明异常,err:" + err.Error()
  7713. return
  7714. }
  7715. if req.Renew == 1 {
  7716. productName := ""
  7717. if req.ProductId == 1 {
  7718. productName = "ficc"
  7719. } else if req.ProductId == 2 {
  7720. productName = "权益"
  7721. } else {
  7722. productName = "佣金客户"
  7723. }
  7724. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  7725. if err != nil {
  7726. br.Msg = "查询该客户产品异常!"
  7727. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  7728. return
  7729. }
  7730. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  7731. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  7732. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  7733. return
  7734. }
  7735. //查询客户的产品权限
  7736. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, req.ProductId)
  7737. if err != nil {
  7738. br.Msg = "查询客户的产品权限异常"
  7739. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  7740. return
  7741. }
  7742. err = company.CompanyFreeze(req.CompanyId, req.ProductId, req.Remark)
  7743. if err != nil {
  7744. br.Msg = "冻结失败!"
  7745. br.ErrMsg = "冻结失败,Err:" + err.Error()
  7746. return
  7747. }
  7748. //新增操作记录
  7749. go func() {
  7750. time.Sleep(time.Second)
  7751. approveContent := req.Remark
  7752. remark := "冻结客户"
  7753. operation := "freeze"
  7754. _ = services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  7755. productName, "超级管理员", remark, operation, approveContent, sysUser.RealName, "", "冻结")
  7756. //新增产品权限冻结操作日志
  7757. for _, companyReportPermission := range companyReportPermissionList {
  7758. record := company_report_permission_log.CompanyReportPermissionLog{
  7759. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  7760. CompanyId: companyReportPermission.CompanyId,
  7761. ProductId: req.ProductId,
  7762. ProductName: companyReportPermission.ProductName,
  7763. SysUserId: sysUser.AdminId,
  7764. SysUserName: "超级管理员",
  7765. Remark: "冻结客户",
  7766. Operation: "freeze",
  7767. Status: companyReportPermission.Status,
  7768. CreateTime: time.Now(),
  7769. }
  7770. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  7771. }
  7772. }()
  7773. }
  7774. {
  7775. approveContent := req.Remark
  7776. approveContentExtra := req.RenewalTodo
  7777. remark := "新增续约说明"
  7778. operation := "add_renewal_reason"
  7779. _ = services.AddCompanyOperationRecordMore(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  7780. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, approveContentExtra, sysUser.RealName, "", companyProduct.Status)
  7781. }
  7782. br.Ret = 200
  7783. br.Success = true
  7784. br.Msg = "编辑成功"
  7785. }
  7786. // RenewReasonList 客户未续约说明历史列表
  7787. // @Title 客户未续约说明历史列表
  7788. // @Description 客户未续约说明历史列表
  7789. // @Param CompanyId query string true "客户id"
  7790. // @Param ProductId query string true "产品id"
  7791. // @Success 200 {object} response.RenewReasonItemResp
  7792. // @router /renewReasonList [get]
  7793. func (this *CompanyController) RenewReasonList() {
  7794. br := new(models.BaseResponse).Init()
  7795. defer func() {
  7796. this.Data["json"] = br
  7797. this.ServeJSON()
  7798. }()
  7799. sysUser := this.SysUser
  7800. if sysUser == nil {
  7801. br.Msg = "请登录"
  7802. br.ErrMsg = "请登录,SysUser Is Empty"
  7803. br.Ret = 408
  7804. return
  7805. }
  7806. CompanyId := this.GetString("CompanyId")
  7807. ProductId := this.GetString("ProductId")
  7808. if CompanyId == "" {
  7809. br.Msg = "请输入客户ID"
  7810. return
  7811. }
  7812. if ProductId != "1" && ProductId != "2" {
  7813. br.Msg = "请输入正确的产品ID"
  7814. return
  7815. }
  7816. renewalReason, err := models.GetMoreRenewalReason(CompanyId, ProductId)
  7817. if err != nil {
  7818. br.Msg = "获取失败"
  7819. br.ErrMsg = "获取失败,Err:" + err.Error()
  7820. return
  7821. }
  7822. resp := make([]response.RenewReasonItemResp, len(renewalReason))
  7823. for i, reason := range renewalReason {
  7824. createDate := reason.CreateTime.Format("2006.01.02 15:04:05")
  7825. resp[i].RenewalReason = reason.RenewalReason
  7826. resp[i].RenewalTodo = reason.RenewalTodo
  7827. resp[i].CreateTime = createDate
  7828. }
  7829. br.Ret = 200
  7830. br.Success = true
  7831. br.Msg = "获取成功"
  7832. br.Data = resp
  7833. }
  7834. // AddRenewalReason
  7835. // @Title 转试用按钮新增续约说明情况
  7836. // @Description 转试用按钮新增续约说明情况
  7837. // @Param request body company.TryOutReq true "type json string"
  7838. // @Success 200 编辑成功
  7839. // @router /addRenewalReason [post]
  7840. func (this *CompanyController) AddRenewalReason() {
  7841. br := new(models.BaseResponse).Init()
  7842. defer func() {
  7843. this.Data["json"] = br
  7844. this.ServeJSON()
  7845. }()
  7846. sysUser := this.SysUser
  7847. if sysUser == nil {
  7848. br.Msg = "请登录"
  7849. br.ErrMsg = "请登录,SysUser Is Empty"
  7850. br.Ret = 408
  7851. return
  7852. }
  7853. var req company.TryOutReq
  7854. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  7855. if err != nil {
  7856. br.Msg = "参数解析异常!"
  7857. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  7858. return
  7859. }
  7860. if req.CompanyId <= 0 {
  7861. br.Msg = "参数缺失"
  7862. br.ErrMsg = "参数缺失,客户编号未传!"
  7863. return
  7864. }
  7865. if req.ProductId <= 0 {
  7866. br.Msg = "参数缺失"
  7867. br.ErrMsg = "参数缺失,产品编号未传!"
  7868. return
  7869. }
  7870. if req.OperationId <= 0 {
  7871. br.Msg = "参数缺失"
  7872. br.ErrMsg = "参数缺失,操作记录表编号未传!"
  7873. return
  7874. }
  7875. if req.Remark == "" {
  7876. br.Msg = "参数缺失"
  7877. br.ErrMsg = "参数缺失,续约情况说明未传!"
  7878. return
  7879. }
  7880. if req.RenewalTodo == "" && req.Renew == 0 {
  7881. br.Msg = "参数缺失"
  7882. br.ErrMsg = "参数缺失,待办事项说明未传!"
  7883. return
  7884. }
  7885. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  7886. if err != nil {
  7887. br.Msg = "查询客户异常"
  7888. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  7889. return
  7890. }
  7891. if companyProduct.SellerId != sysUser.AdminId {
  7892. br.Msg = "客户异常,没有该客户的操作权限"
  7893. br.ErrMsg = "客户异常,没有该客户的操作权限"
  7894. return
  7895. }
  7896. renewalReason := company.CompanyRenewalReason{
  7897. CompanyRenewalReasonId: 0,
  7898. CompanyId: companyProduct.CompanyId,
  7899. ProductId: companyProduct.ProductId,
  7900. ProductName: companyProduct.ProductName,
  7901. CompanyName: companyProduct.CompanyName,
  7902. TryOutTime: companyProduct.TryOutTime,
  7903. RenewalReason: req.Remark,
  7904. RenewalTodo: req.RenewalTodo,
  7905. LastDescriptionTime: companyProduct.LastDescriptionTime,
  7906. EndDays: companyProduct.ContractEndDate,
  7907. ExpirationTimeExceeded: 0,
  7908. RenewalIntention: req.Renew,
  7909. CreateTime: time.Now(),
  7910. }
  7911. endTime, err := company.GetTryOutTimeFromOperationRecord(renewalReason.CompanyId)
  7912. if err != nil {
  7913. br.Msg = "查询该客户转试用时间异常!"
  7914. br.ErrMsg = "查询该客户转试用时间异常,err:" + err.Error()
  7915. return
  7916. }
  7917. endDateTime, err := time.Parse(utils.FormatDateTime, *endTime)
  7918. if err != nil {
  7919. br.Msg = "时间格式化异常!"
  7920. br.ErrMsg = "时间格式化异常,err:" + err.Error()
  7921. return
  7922. }
  7923. endDate := endDateTime.Format(utils.FormatDate)
  7924. endDateTime, _ = time.Parse(utils.FormatDate, endDate)
  7925. sub := time.Now().Sub(endDateTime)
  7926. renewalReason.ExpirationTimeExceeded = int(sub.Hours() / 24)
  7927. err = company.AddRenewalReason(&renewalReason)
  7928. if err != nil {
  7929. br.Msg = "新增续约情况说明操作异常!"
  7930. br.ErrMsg = "新增续约情况说明操作异常,err:" + err.Error()
  7931. return
  7932. }
  7933. companyProduct.RenewalIntention = req.Renew
  7934. err = company.EditTryOutCompanyReason(companyProduct, req.Remark, req.RenewalTodo)
  7935. if err != nil {
  7936. br.Msg = "更新客户续约情况说明异常!"
  7937. br.ErrMsg = "更新客户续约情况说明异常,err:" + err.Error()
  7938. return
  7939. }
  7940. if req.Renew == 1 {
  7941. productName := ""
  7942. if req.ProductId == 1 {
  7943. productName = "ficc"
  7944. } else if req.ProductId == 2 {
  7945. productName = "权益"
  7946. } else {
  7947. productName = "佣金客户"
  7948. }
  7949. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  7950. if err != nil {
  7951. br.Msg = "查询该客户产品异常!"
  7952. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  7953. return
  7954. }
  7955. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  7956. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  7957. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  7958. return
  7959. }
  7960. //查询客户的产品权限
  7961. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, req.ProductId)
  7962. if err != nil {
  7963. br.Msg = "查询客户的产品权限异常"
  7964. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  7965. return
  7966. }
  7967. err = company.CompanyFreeze(req.CompanyId, req.ProductId, req.Remark)
  7968. if err != nil {
  7969. br.Msg = "冻结失败!"
  7970. br.ErrMsg = "冻结失败,Err:" + err.Error()
  7971. return
  7972. }
  7973. //新增操作记录
  7974. go func() {
  7975. time.Sleep(time.Second)
  7976. approveContent := req.Remark
  7977. remark := "冻结客户"
  7978. operation := "freeze"
  7979. _ = services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  7980. productName, "超级管理员", remark, operation, approveContent, sysUser.RealName, "", "冻结")
  7981. //新增产品权限冻结操作日志
  7982. for _, companyReportPermission := range companyReportPermissionList {
  7983. record := company_report_permission_log.CompanyReportPermissionLog{
  7984. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  7985. CompanyId: companyReportPermission.CompanyId,
  7986. ProductId: req.ProductId,
  7987. ProductName: companyReportPermission.ProductName,
  7988. SysUserId: sysUser.AdminId,
  7989. SysUserName: "超级管理员",
  7990. Remark: "冻结客户",
  7991. Operation: "freeze",
  7992. Status: companyReportPermission.Status,
  7993. CreateTime: time.Now(),
  7994. }
  7995. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  7996. }
  7997. }()
  7998. }
  7999. {
  8000. approveContent := req.Remark
  8001. approveContentExtra := req.RenewalTodo
  8002. remark := "新增续约说明"
  8003. operation := "add_try_out_reason"
  8004. _ = services.AddCompanyOperationRecordMore(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  8005. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, approveContentExtra, sysUser.RealName, "", companyProduct.Status)
  8006. record := new(company.CompanyOperationRecord)
  8007. record.Id = req.OperationId
  8008. record.ApproveContent = req.Remark
  8009. record.ApproveContentExtra = req.RenewalTodo
  8010. _, err = company.UpdateCompanyOperationRecord(record)
  8011. if err != nil {
  8012. br.Msg = "编辑失败"
  8013. br.ErrMsg = "编辑失败,Err:" + err.Error()
  8014. return
  8015. }
  8016. }
  8017. br.Ret = 200
  8018. br.Success = true
  8019. br.Msg = "编辑成功"
  8020. }
  8021. // AddRemark
  8022. // @Title 新增备注
  8023. // @Description 新增备注
  8024. // @Param request body company.RemarkReq true "type json string"
  8025. // @Success 200 编辑成功
  8026. // @router /remark/add [post]
  8027. func (this *CompanyController) AddRemark() {
  8028. br := new(models.BaseResponse).Init()
  8029. defer func() {
  8030. this.Data["json"] = br
  8031. this.ServeJSON()
  8032. }()
  8033. sysUser := this.SysUser
  8034. if sysUser == nil {
  8035. br.Msg = "请登录"
  8036. br.ErrMsg = "请登录,SysUser Is Empty"
  8037. br.Ret = 408
  8038. return
  8039. }
  8040. var req company.RemarkReq
  8041. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  8042. if err != nil {
  8043. br.Msg = "参数解析异常!"
  8044. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  8045. return
  8046. }
  8047. if req.CompanyId <= 0 {
  8048. br.Msg = "参数缺失"
  8049. br.ErrMsg = "参数缺失,客户编号未传!"
  8050. return
  8051. }
  8052. if req.Remark == "" {
  8053. br.Msg = "参数缺失"
  8054. br.ErrMsg = "参数缺失,备注说明未传!"
  8055. return
  8056. }
  8057. var productId int
  8058. //var productName string
  8059. 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 {
  8060. productId = 1
  8061. //productName = "ficc"
  8062. } 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 {
  8063. productId = 2
  8064. //productName = "权益"
  8065. } else {
  8066. br.Msg = "角色类型错误"
  8067. br.ErrMsg = "角色类型错误,该角色不能添加备注!"
  8068. return
  8069. }
  8070. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  8071. if err != nil {
  8072. br.Msg = "查询客户异常"
  8073. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  8074. }
  8075. if companyProduct.SellerId != sysUser.AdminId {
  8076. br.Msg = "客户异常,没有该客户的操作权限"
  8077. br.ErrMsg = "客户异常,没有该客户的操作权限"
  8078. return
  8079. }
  8080. remark := company.CompanyProductRemark{
  8081. CompanyProductRemakrId: 0,
  8082. CompanyId: companyProduct.CompanyId,
  8083. ProductId: companyProduct.ProductId,
  8084. ProductName: companyProduct.ProductName,
  8085. Remark: req.Remark,
  8086. CreateTime: time.Now(),
  8087. }
  8088. err = company.AddCompanyRemark(&remark)
  8089. {
  8090. approveContent := req.Remark
  8091. remark := "新增备注"
  8092. operation := "add_remark"
  8093. services.AddCompanyOperationRecord(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  8094. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, sysUser.RealName, "", companyProduct.Status)
  8095. }
  8096. if err != nil {
  8097. br.Msg = "编辑失败"
  8098. br.ErrMsg = "编辑失败,Err:" + err.Error()
  8099. }
  8100. br.Ret = 200
  8101. br.Success = true
  8102. br.Msg = "编辑成功"
  8103. }
  8104. // RemarkList 备注列表
  8105. // @Title 备注列表
  8106. // @Description 备注列表
  8107. // @Param CompanyId query string true "客户id"
  8108. // @Success 200 {object} company.RemarkResp
  8109. // @router /remark [get]
  8110. func (this *CompanyController) RemarkList() {
  8111. br := new(models.BaseResponse).Init()
  8112. defer func() {
  8113. this.Data["json"] = br
  8114. this.ServeJSON()
  8115. }()
  8116. sysUser := this.SysUser
  8117. if sysUser == nil {
  8118. br.Msg = "请登录"
  8119. br.ErrMsg = "请登录,SysUser Is Empty"
  8120. br.Ret = 408
  8121. return
  8122. }
  8123. companyId := this.GetString("CompanyId")
  8124. var remarkList []*company.CompanyProductRemark
  8125. var err error
  8126. groupFicc := []string{
  8127. utils.ROLE_TYPE_CODE_FICC_SELLER, utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_FICC_GROUP,
  8128. utils.ROLE_TYPE_CODE_FICC_DEPARTMENT, utils.ROLE_TYPE_CODE_FICC_ADMIN,
  8129. }
  8130. groupRai := []string{
  8131. utils.ROLE_TYPE_CODE_RAI_SELLER, utils.ROLE_TYPE_CODE_RAI_GROUP, utils.ROLE_TYPE_CODE_RAI_GROUP,
  8132. utils.ROLE_TYPE_CODE_RAI_DEPARTMENT, utils.ROLE_TYPE_CODE_RAI_ADMIN,
  8133. }
  8134. if utils.InArrayByStr(groupFicc, sysUser.RoleTypeCode) {
  8135. remarkList, err = company.GetRemarkList(companyId, "1")
  8136. if err != nil {
  8137. br.Msg = "获取失败"
  8138. br.ErrMsg = "获取失败,Err:" + err.Error()
  8139. return
  8140. }
  8141. }
  8142. if utils.InArrayByStr(groupRai, sysUser.RoleTypeCode) {
  8143. remarkList, err = company.GetRemarkList(companyId, "2")
  8144. if err != nil {
  8145. br.Msg = "获取失败"
  8146. br.ErrMsg = "获取失败,Err:" + err.Error()
  8147. return
  8148. }
  8149. }
  8150. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  8151. remarkList, err = company.GetRemarkListByCompanyId(companyId)
  8152. if err != nil {
  8153. br.Msg = "获取失败"
  8154. br.ErrMsg = "获取失败,Err:" + err.Error()
  8155. return
  8156. }
  8157. }
  8158. resp := make([]company.RemarkResp, len(remarkList))
  8159. for i, remark := range remarkList {
  8160. createDate := remark.CreateTime.Format(utils.FormatDateTime)
  8161. resp[i].Remark = remark.Remark
  8162. resp[i].ProductName = remark.ProductName
  8163. resp[i].CreateTime = createDate
  8164. }
  8165. br.Ret = 200
  8166. br.Success = true
  8167. br.Msg = "获取成功"
  8168. br.Data = resp
  8169. }
  8170. // RoadShowList 客户列表的路演详情列表
  8171. // @Title 路演详情列表
  8172. // @Description 路演详情列表
  8173. // @Param CompanyId query string true "客户id"
  8174. // @Success 200 {object} company.RoadShowListResp
  8175. // @router /roadShowList [get]
  8176. func (this *CompanyController) RoadShowList() {
  8177. br := new(models.BaseResponse).Init()
  8178. defer func() {
  8179. this.Data["json"] = br
  8180. this.ServeJSON()
  8181. }()
  8182. sysUser := this.SysUser
  8183. if sysUser == nil {
  8184. br.Msg = "请登录"
  8185. br.ErrMsg = "请登录,SysUser Is Empty"
  8186. br.Ret = 408
  8187. return
  8188. }
  8189. companyId := this.GetString("CompanyId")
  8190. var err error
  8191. roadShowList, err := company.GetRoadShowList(companyId)
  8192. if err != nil {
  8193. br.Msg = "获取失败"
  8194. br.ErrMsg = "获取失败,Err:" + err.Error()
  8195. return
  8196. }
  8197. //calendarIdSlice := make([]string, 0)
  8198. //for _, v := range roadShowList {
  8199. // calendarIdSlice = append(calendarIdSlice, strconv.Itoa(v.RsCalendarId))
  8200. //}
  8201. //calendarIdStr := strings.Join(calendarIdSlice, ",")
  8202. //researcherList, _ := company.GetRoadShowResearchers(calendarIdStr)
  8203. //roadShowTotalMap := make(map[int]int)
  8204. //for _, roadShowTotal := range researcherList {
  8205. // roadShowTotalMap[roadShowTotal.CompanyId] = roadShowTotal.Total
  8206. //}
  8207. resp := make([]company.RoadShowListResp, len(roadShowList))
  8208. for i, calendar := range roadShowList {
  8209. resp[i].SysUserRealName = calendar.SysUserRealName
  8210. resp[i].RoadshowType = calendar.RoadshowType
  8211. //线上为平台,线下为省市
  8212. if calendar.RoadshowType == "线上" {
  8213. resp[i].RoadshowPlatform = calendar.RoadshowPlatform
  8214. } else {
  8215. resp[i].RoadshowPlatform = calendar.Province + calendar.City
  8216. }
  8217. researchers, err := company.GetRoadShowResearchers(calendar.RsCalendarId)
  8218. if err != nil && err.Error() != utils.ErrNoRow() {
  8219. br.Msg = "获取研究员信息失败"
  8220. br.ErrMsg = "获取研究员信息失败,Err:" + err.Error()
  8221. return
  8222. }
  8223. var researcherList []string
  8224. for _, researcher := range researchers {
  8225. researcherList = append(researcherList, *researcher)
  8226. }
  8227. researcher := strings.Join(researcherList, ",")
  8228. resp[i].Researchers = researcher
  8229. resp[i].RoadShowTime = calendar.EndDate.Format("2006.01.02")
  8230. }
  8231. br.Ret = 200
  8232. br.Success = true
  8233. br.Msg = "获取成功"
  8234. br.Data = resp
  8235. }
  8236. // CustomerAreaStatistics
  8237. // @Title 客户区域统计
  8238. // @Description 获取客户区域统计接口
  8239. // @Param Date query string true "日期"
  8240. // @Param ProductId query Int true "产品Id"
  8241. // @Success 200 {object} statistic_report.CompanyRenewRecordResp
  8242. // @router /customerAreaStatistics [get]
  8243. func (this *CompanyController) CustomerAreaStatistics() {
  8244. br := new(models.BaseResponse).Init()
  8245. defer func() {
  8246. this.Data["json"] = br
  8247. this.ServeJSON()
  8248. }()
  8249. sysUser := this.SysUser
  8250. if sysUser == nil {
  8251. br.Msg = "请登录"
  8252. br.ErrMsg = "请登录,SysUser Is Empty"
  8253. br.Ret = 408
  8254. return
  8255. }
  8256. date := this.GetString("Date")
  8257. productId, _ := this.GetInt("ProductId", 1)
  8258. //获取列表
  8259. companyAreaDataMapList, _, err := statistic_report.GetAreaDateData(date, productId)
  8260. if err != nil {
  8261. br.Msg = "数据异常"
  8262. br.ErrMsg = "数据异常,Err:" + err.Error()
  8263. return
  8264. }
  8265. //获取省市数据
  8266. areaMap := make(map[string]string)
  8267. provinceMap := make(map[string][]string, 0)
  8268. list, err := statisticModels.GetAllCompanyArea()
  8269. for _, item := range list {
  8270. areaMap[item.City] = item.Province
  8271. }
  8272. for c, p := range areaMap {
  8273. citySlice := make([]string, 0)
  8274. citySlice = provinceMap[p]
  8275. citySlice = append(citySlice, c)
  8276. provinceMap[p] = citySlice
  8277. }
  8278. //数据处理
  8279. groupReportRecordList := make([]statistic_report.GroupCityRecord, 0)
  8280. resp := statistic_report.CustomerAreaStatisticsResp{
  8281. List: groupReportRecordList,
  8282. IsAdmin: false,
  8283. }
  8284. //除ficc管理员和超管之外的角色进入此页面时,正式客户数量>0时可点击,点击查看正式客户列表详情;
  8285. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  8286. resp.IsAdmin = true
  8287. }
  8288. startDateIndexList := make(map[int]string) //开始时间间隔map
  8289. endDateIndexList := make(map[int]string) //结束时间间隔map
  8290. tmpAllTryOutNumMap := make(map[int]int)
  8291. tmpAllFormalNumMap := make(map[int]int)
  8292. tmpAllActiveNumMap := make(map[int]int)
  8293. tmpAllAllActiveNumMap := make(map[int]int)
  8294. tmpAllNoIncrementalActiveNumMap := make(map[int]int)
  8295. tmpAllTryStagePushMap := make(map[int]int)
  8296. tmpAllTryStageFollowMap := make(map[int]int)
  8297. tmpAllTryStageReadyMap := make(map[int]int)
  8298. tmpAllTryStageInitMap := make(map[int]int)
  8299. for province, cityList := range provinceMap {
  8300. tmpGroupCityReportRecord := make([]statistic_report.CityRecord, 0)
  8301. tmpGroupCompanyReportRecordNumList := make([]statistic_report.CompanyAreaNum, 0)
  8302. tmpGroupTryOutNumMap := make(map[int]int)
  8303. tmpGroupFormalNumMap := make(map[int]int)
  8304. tmpGroupFormalCompanyIdsMap := make(map[int]string) //正式客户id
  8305. tmpGroupActiveNumMap := make(map[int]int)
  8306. tmpGroupAllActiveNumMap := make(map[int]int)
  8307. tmpGroupNoIncrementalActiveNumMap := make(map[int]int)
  8308. // 其他类型客户ID
  8309. tmpGroupTryOutCompanyIdsMap := make(map[int]string) //试用客户ID
  8310. tmpGroupPushCompanyIdsMap := make(map[int]string) //试用(推进)客户ID
  8311. tmpGroupFollowCompanyIdsMap := make(map[int]string) //试用(跟踪)客户ID
  8312. tmpGroupReadyCompanyIdsMap := make(map[int]string) //试用(预备)客户ID
  8313. tmpGroupInitCompanyIdsMap := make(map[int]string) //试用(未分类)客户ID
  8314. tmpGroupTryStagePushMap := make(map[int]int)
  8315. tmpGroupTryStageFollowMap := make(map[int]int)
  8316. tmpGroupTryStageReadyMap := make(map[int]int)
  8317. tmpGroupTryStageInitMap := make(map[int]int)
  8318. for _, city := range cityList {
  8319. //城市数据
  8320. //每个城市的数据
  8321. tmpCompanyReportRecordNumList := make([]statistic_report.CompanyAreaNum, 0)
  8322. for index, adminData := range companyAreaDataMapList {
  8323. startDateIndexList[index] = adminData.StartDate
  8324. endDateIndexList[index] = adminData.EndDate
  8325. var tmpTryOutNum, tmpFormalNum, tmpActiveStatus, tmpAllActiveStatus, tmpNoIncrementalActiveStatus int
  8326. var tmpTryStagePushNum, tmpTryStageFollowNum, tmpTryStageReadyNum, tmpTryStageInitNum int
  8327. var tmpFormalCompanyIds string //正式客户id集合
  8328. var tmpTryOutCompanyIds string //试用客户ID集合
  8329. var tmpPushCompanyIds string //试用(推进)客户ID集合
  8330. var tmpFollowCompanyIds string //试用(跟踪)客户ID集合
  8331. var tmpReadyCompanyIds string //试用(预备)客户ID集合
  8332. var tmpInitCompanyIds string //试用(未分类)客户ID集合
  8333. if num, ok := adminData.TryOutMap[city]; ok {
  8334. tmpTryOutNum = num
  8335. }
  8336. if num, ok := adminData.FormalMap[city]; ok {
  8337. tmpFormalNum = num
  8338. }
  8339. if companyIds, ok := adminData.FormalIdMap[city]; ok {
  8340. tmpFormalCompanyIds = companyIds
  8341. }
  8342. if companyIds, ok := adminData.TryOutIdMap[city]; ok {
  8343. tmpTryOutCompanyIds = companyIds
  8344. }
  8345. if companyIds, ok := adminData.TryStagePushIdsMap[city]; ok {
  8346. tmpPushCompanyIds = companyIds
  8347. }
  8348. if companyIds, ok := adminData.TryStageFollowIdsMap[city]; ok {
  8349. tmpFollowCompanyIds = companyIds
  8350. }
  8351. if companyIds, ok := adminData.TryStageReadyIdsMap[city]; ok {
  8352. tmpReadyCompanyIds = companyIds
  8353. }
  8354. if companyIds, ok := adminData.TryStageInitIdsMap[city]; ok {
  8355. tmpInitCompanyIds = companyIds
  8356. }
  8357. if num, ok := adminData.ActiveMap[city]; ok {
  8358. tmpActiveStatus = num
  8359. }
  8360. if num, ok := adminData.AllActiveMap[city]; ok {
  8361. tmpAllActiveStatus = num
  8362. }
  8363. if num, ok := adminData.NoIncrementalActiveMap[city]; ok {
  8364. tmpNoIncrementalActiveStatus = num
  8365. }
  8366. // 每个用户的试用标签统计 推进-跟踪-预备-未分类
  8367. if num, ok := adminData.TryStagePushNum[city]; ok {
  8368. tmpTryStagePushNum = num
  8369. }
  8370. if num, ok := adminData.TryStageFollowNum[city]; ok {
  8371. tmpTryStageFollowNum = num
  8372. }
  8373. if num, ok := adminData.TryStageReadyNum[city]; ok {
  8374. tmpTryStageReadyNum = num
  8375. }
  8376. if num, ok := adminData.TryStageInitNum[city]; ok {
  8377. tmpTryStageInitNum = num
  8378. }
  8379. tmpAdminRsReportRecordNum := statistic_report.CompanyAreaNum{
  8380. TryOutNum: tmpTryOutNum,
  8381. FormalNum: tmpFormalNum,
  8382. FormalIds: tmpFormalCompanyIds,
  8383. ActiveNum: tmpActiveStatus,
  8384. AllActiveNum: tmpAllActiveStatus,
  8385. NoIncrementalActiveNum: tmpNoIncrementalActiveStatus,
  8386. StartDate: adminData.StartDate,
  8387. EndDate: adminData.EndDate,
  8388. TryStagePushNum: tmpTryStagePushNum,
  8389. TryStageFollowNum: tmpTryStageFollowNum,
  8390. TryStageReadyNum: tmpTryStageReadyNum,
  8391. TryStageInitNum: tmpTryStageInitNum,
  8392. TotalNum: tmpTryOutNum + tmpFormalNum,
  8393. }
  8394. tmpCompanyReportRecordNumList = append(tmpCompanyReportRecordNumList, tmpAdminRsReportRecordNum)
  8395. //组内数据汇总
  8396. tmpGroupTryOutNumMap[index] += tmpTryOutNum
  8397. tmpGroupFormalNumMap[index] += tmpFormalNum
  8398. // 正式客户id
  8399. if tmpFormalCompanyIds != `` {
  8400. tmpGroupFormalCompanyIds, ok := tmpGroupFormalCompanyIdsMap[index]
  8401. if ok {
  8402. tmpGroupFormalCompanyIdsMap[index] = tmpGroupFormalCompanyIds + "," + tmpFormalCompanyIds
  8403. } else {
  8404. tmpGroupFormalCompanyIdsMap[index] = tmpFormalCompanyIds
  8405. }
  8406. }
  8407. tmpGroupActiveNumMap[index] += tmpActiveStatus
  8408. tmpGroupAllActiveNumMap[index] += tmpActiveStatus
  8409. tmpGroupNoIncrementalActiveNumMap[index] += tmpActiveStatus
  8410. tmpGroupTryStagePushMap[index] += tmpTryStagePushNum
  8411. tmpGroupTryStageFollowMap[index] += tmpTryStageFollowNum
  8412. tmpGroupTryStageReadyMap[index] += tmpTryStageReadyNum
  8413. tmpGroupTryStageInitMap[index] += tmpTryStageInitNum
  8414. // 其他客户IDs
  8415. if tmpTryOutCompanyIds != `` {
  8416. a, ok := tmpGroupTryOutCompanyIdsMap[index]
  8417. if ok {
  8418. tmpGroupTryOutCompanyIdsMap[index] = a + "," + tmpTryOutCompanyIds
  8419. } else {
  8420. tmpGroupTryOutCompanyIdsMap[index] = tmpTryOutCompanyIds
  8421. }
  8422. }
  8423. if tmpPushCompanyIds != `` {
  8424. a, ok := tmpGroupPushCompanyIdsMap[index]
  8425. if ok {
  8426. tmpGroupPushCompanyIdsMap[index] = a + "," + tmpPushCompanyIds
  8427. } else {
  8428. tmpGroupPushCompanyIdsMap[index] = tmpPushCompanyIds
  8429. }
  8430. }
  8431. if tmpFollowCompanyIds != `` {
  8432. a, ok := tmpGroupFollowCompanyIdsMap[index]
  8433. if ok {
  8434. tmpGroupFollowCompanyIdsMap[index] = a + "," + tmpFollowCompanyIds
  8435. } else {
  8436. tmpGroupFollowCompanyIdsMap[index] = tmpFollowCompanyIds
  8437. }
  8438. }
  8439. if tmpReadyCompanyIds != `` {
  8440. a, ok := tmpGroupReadyCompanyIdsMap[index]
  8441. if ok {
  8442. tmpGroupReadyCompanyIdsMap[index] = a + "," + tmpReadyCompanyIds
  8443. } else {
  8444. tmpGroupReadyCompanyIdsMap[index] = tmpReadyCompanyIds
  8445. }
  8446. }
  8447. if tmpInitCompanyIds != `` {
  8448. a, ok := tmpGroupInitCompanyIdsMap[index]
  8449. if ok {
  8450. tmpGroupInitCompanyIdsMap[index] = a + "," + tmpInitCompanyIds
  8451. } else {
  8452. tmpGroupInitCompanyIdsMap[index] = tmpInitCompanyIds
  8453. }
  8454. }
  8455. //总数据汇总
  8456. tmpAllTryOutNumMap[index] += tmpTryOutNum
  8457. tmpAllFormalNumMap[index] += tmpFormalNum
  8458. tmpAllActiveNumMap[index] += tmpActiveStatus
  8459. tmpAllAllActiveNumMap[index] += tmpAllActiveStatus
  8460. tmpAllNoIncrementalActiveNumMap[index] += tmpNoIncrementalActiveStatus
  8461. // 总数据试用标签数据汇总
  8462. tmpAllTryStagePushMap[index] += tmpTryStagePushNum
  8463. tmpAllTryStageFollowMap[index] += tmpTryStageFollowNum
  8464. tmpAllTryStageReadyMap[index] += tmpTryStageReadyNum
  8465. tmpAllTryStageInitMap[index] += tmpTryStageInitNum
  8466. }
  8467. tmpAdminReportRecord := statistic_report.CityRecord{
  8468. Name: city,
  8469. CompanyAreaNumNumList: tmpCompanyReportRecordNumList,
  8470. }
  8471. tmpGroupCityReportRecord = append(tmpGroupCityReportRecord, tmpAdminReportRecord)
  8472. }
  8473. for i := 0; i < len(tmpGroupActiveNumMap); i++ {
  8474. tmpGroupCompanyReportRecordNum := statistic_report.CompanyAreaNum{
  8475. TryOutNum: tmpGroupTryOutNumMap[i],
  8476. FormalNum: tmpGroupFormalNumMap[i],
  8477. FormalIds: tmpGroupFormalCompanyIdsMap[i],
  8478. ActiveNum: tmpGroupActiveNumMap[i],
  8479. AllActiveNum: tmpGroupAllActiveNumMap[i],
  8480. NoIncrementalActiveNum: tmpGroupNoIncrementalActiveNumMap[i],
  8481. StartDate: startDateIndexList[i],
  8482. EndDate: endDateIndexList[i],
  8483. TryStagePushNum: tmpGroupTryStagePushMap[i],
  8484. TryStageFollowNum: tmpGroupTryStageFollowMap[i],
  8485. TryStageReadyNum: tmpGroupTryStageReadyMap[i],
  8486. TryStageInitNum: tmpGroupTryStageInitMap[i],
  8487. TotalNum: tmpGroupTryOutNumMap[i] + tmpGroupFormalNumMap[i],
  8488. TryOutIds: tmpGroupTryOutCompanyIdsMap[i],
  8489. TryStagePushIds: tmpGroupPushCompanyIdsMap[i],
  8490. TryStageFollowIds: tmpGroupFollowCompanyIdsMap[i],
  8491. TryStageReadyIds: tmpGroupReadyCompanyIdsMap[i],
  8492. TryStageInitIds: tmpGroupInitCompanyIdsMap[i],
  8493. }
  8494. tmpGroupCompanyReportRecordNumList = append(tmpGroupCompanyReportRecordNumList, tmpGroupCompanyReportRecordNum)
  8495. }
  8496. groupReportRecord := statistic_report.GroupCityRecord{
  8497. Item: tmpGroupCityReportRecord,
  8498. Name: province,
  8499. CompanyAreaNumNumList: tmpGroupCompanyReportRecordNumList,
  8500. }
  8501. groupReportRecordList = append(groupReportRecordList, groupReportRecord)
  8502. }
  8503. resp.List = groupReportRecordList
  8504. br.Ret = 200
  8505. br.Success = true
  8506. br.Msg = "获取成功"
  8507. br.Data = resp
  8508. }
  8509. // CompanyTryOutDayList
  8510. // @Title 客户累计试用详情接口
  8511. // @Description 客户累计试用详情接口
  8512. // @Param CompanyId query int true "客户id"
  8513. // @Param ProductId query int true "产品id"
  8514. // @Success 200 {object} company.CompanyTryOutDayListResp
  8515. // @router /company/tryOutDayList [get]
  8516. func (this *CompanyTodoController) CompanyTryOutDayList() {
  8517. br := new(models.BaseResponse).Init()
  8518. defer func() {
  8519. this.Data["json"] = br
  8520. this.ServeJSON()
  8521. }()
  8522. companyId, _ := this.GetInt("CompanyId")
  8523. if companyId <= 0 {
  8524. br.Msg = "请选择客户"
  8525. return
  8526. }
  8527. productId, _ := this.GetInt("ProductId")
  8528. if productId <= 0 {
  8529. br.Msg = "请选择类型"
  8530. return
  8531. }
  8532. pageSize, _ := this.GetInt("PageSize")
  8533. currentIndex, _ := this.GetInt("CurrentIndex")
  8534. var startSize int
  8535. if pageSize <= 0 {
  8536. pageSize = utils.PageSize20
  8537. }
  8538. if currentIndex <= 0 {
  8539. currentIndex = 1
  8540. }
  8541. startSize = paging.StartIndex(currentIndex, pageSize)
  8542. // 获取任务信息
  8543. total, err := company.GetCompanyProductTryOutUpdateLogTotal(companyId, productId)
  8544. if err != nil {
  8545. br.Msg = "获取任务信息失败"
  8546. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  8547. return
  8548. }
  8549. // 获取任务信息
  8550. list, err := company.GetCompanyProductTryOutUpdateLogList(companyId, productId, startSize, pageSize)
  8551. if err != nil {
  8552. br.Msg = "获取任务信息失败"
  8553. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  8554. return
  8555. }
  8556. //var list []*company_todo.CompanyTodoListItem
  8557. //for _, v := range todos {
  8558. // temp := &company_todo.CompanyTodoListItem{
  8559. // CompanyTodo: v,
  8560. // }
  8561. // temp.EndTimeStr = temp.EndTime.Format(utils.FormatDate)
  8562. // if temp.EndTimeStr == "0001-01-01" {
  8563. // temp.EndTimeStr = ""
  8564. // }
  8565. // list = append(list, temp)
  8566. //}
  8567. if len(list) <= 0 {
  8568. list = make([]*company.CompanyProductTryOutUpdateLog, 0)
  8569. }
  8570. page := paging.GetPaging(currentIndex, pageSize, total)
  8571. resp := company.CompanyTryOutDayListResp{
  8572. Paging: page,
  8573. List: list,
  8574. }
  8575. br.Ret = 200
  8576. br.Success = true
  8577. br.Msg = "获取成功"
  8578. br.Data = resp
  8579. }
  8580. // @Title 获取流水信息接口
  8581. // @Description 获取流水信息接口
  8582. // @Param CompanyId query int true "客户id"
  8583. // @Success 200 {object} company.CygxActivityPointsBillListResp
  8584. // @router /company/activity/points/bill [get]
  8585. func (this *CompanyTodoController) CompanyActivityPointsBill() {
  8586. br := new(models.BaseResponse).Init()
  8587. defer func() {
  8588. this.Data["json"] = br
  8589. this.ServeJSON()
  8590. }()
  8591. companyId, _ := this.GetInt("CompanyId")
  8592. if companyId <= 0 {
  8593. br.Msg = "请选择客户"
  8594. return
  8595. }
  8596. // 获取流水信息
  8597. list, err := cygx.CygxActivityPointsBillByCompanyId(companyId)
  8598. if err != nil {
  8599. br.Msg = "获取任务信息失败"
  8600. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  8601. return
  8602. }
  8603. if len(list) <= 0 {
  8604. list = make([]*cygx.CygxActivityPointsBillResp, 0)
  8605. }
  8606. resp := cygx.CygxActivityPointsBillListResp{
  8607. List: list,
  8608. }
  8609. br.Ret = 200
  8610. br.Success = true
  8611. br.Msg = "获取成功"
  8612. br.Data = resp
  8613. }