company.go 307 KB

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