user.go 200 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213
  1. package cygx
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "github.com/tealeg/xlsx"
  7. "hongze/hz_crm_api/controllers"
  8. "hongze/hz_crm_api/models"
  9. "hongze/hz_crm_api/models/company"
  10. "hongze/hz_crm_api/models/cygx"
  11. "hongze/hz_crm_api/models/roadshow"
  12. "hongze/hz_crm_api/models/system"
  13. "hongze/hz_crm_api/services"
  14. cygxService "hongze/hz_crm_api/services/cygx"
  15. "hongze/hz_crm_api/utils"
  16. "os"
  17. "path/filepath"
  18. "sort"
  19. "strconv"
  20. "strings"
  21. "time"
  22. )
  23. // 权益用户管理
  24. type UserController struct {
  25. controllers.BaseAuthController
  26. }
  27. // List
  28. // @Title 用户列表
  29. // @Description 用户列表接口
  30. // @Param PageSize query int true "每页数据条数"
  31. // @Param CurrentIndex query int true "当前页页码,从1开始"
  32. // @Param Status query string true "状态:”试用','永续','冻结','流失','正式'"
  33. // @Param IsMaker query int false "是否决策人,1:是,0:否 ,2:全部'"
  34. // @Param IsRegister query int false "是否决策人,1:是,0:否 ,2:全部'"
  35. // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
  36. // @Param KeyWord query string true "搜索关键词"
  37. // @Param Label query string true "搜索用户标签"
  38. // @Param TryStage query int false "试用客户子标签:0全部、1未分类、2 推进、3 跟踪、4 预备。正式:套餐类型,0:无,1:大套餐,2:小套餐"
  39. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  40. // @Param IsSubscribeCygx query int true "是否关注了查研观向小助手公众号: -1-默认全部; 0-未关注; 1-已关注"
  41. // @Success 200 {object} cygx.CompanyUserListResp
  42. // @router /user/list [get]
  43. func (this *UserController) List() {
  44. br := new(models.BaseResponse).Init()
  45. defer func() {
  46. this.Data["json"] = br
  47. this.ServeJSON()
  48. }()
  49. sysUser := this.SysUser
  50. if sysUser == nil {
  51. br.Msg = "请登录"
  52. br.ErrMsg = "请登录,SysUser Is Empty"
  53. br.Ret = 408
  54. return
  55. }
  56. roleTypeCode := sysUser.RoleTypeCode
  57. pageSize, _ := this.GetInt("PageSize")
  58. currentIndex, _ := this.GetInt("CurrentIndex")
  59. isMaker, _ := this.GetInt("IsMaker")
  60. isRegister, _ := this.GetInt("IsRegister")
  61. status := this.GetString("Status")
  62. adminId := this.GetString("AdminId")
  63. keyWord := this.GetString("KeyWord")
  64. label := this.GetString("Label")
  65. tryStage, _ := this.GetInt("TryStage") //试用客户标签
  66. sortType := this.GetString("SortType") //试用客户标签
  67. // 套餐类型
  68. //packageType, _ := this.GetInt("PackageType")
  69. keyWord = strings.Trim(keyWord, " ")
  70. keyWord = strings.Replace(keyWord, "'", "", -1)
  71. isSubscribeCygx, _ := this.GetInt("IsSubscribeCygx", -1)
  72. if status == "X类试用" {
  73. status = "永续"
  74. }
  75. var total int
  76. page := paging.GetPaging(currentIndex, pageSize, total)
  77. //statusItems := make([]*company.CompanyStatus, 0)
  78. //var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}
  79. var startSize int
  80. if pageSize <= 0 {
  81. pageSize = utils.PageSize20
  82. }
  83. if currentIndex <= 0 {
  84. currentIndex = 1
  85. }
  86. startSize = paging.StartIndex(currentIndex, pageSize)
  87. var condition string
  88. var sqlOrder string
  89. var usercondition string
  90. var kwywordcondition string
  91. var pars []interface{}
  92. var parsUser []interface{}
  93. //流失
  94. var lossCondition string
  95. //var lossPars []interface{}
  96. //状态分类查询条件
  97. //var permissionCondition string
  98. if adminId != "" {
  99. condition += ` AND b.seller_id IN (` + adminId + `) `
  100. }
  101. lossCondition = condition
  102. //lossPars = pars
  103. //permissionCondition = condition
  104. //流失客户统计
  105. lossCondition += ` AND status='流失' `
  106. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER { //权益销售的查询逻辑
  107. condition += ` AND ( cp.seller_id = ` + strconv.Itoa(sysUser.AdminId) + ` OR cp.share_seller_id = ` + strconv.Itoa(sysUser.AdminId) + `)`
  108. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP { // 权益销售组长查询逻辑
  109. adminList, err := system.GetAdminListByGroupId(sysUser.GroupId)
  110. if err != nil {
  111. br.Msg = "获取失败"
  112. br.ErrMsg = "获取失败,GetAdminListByGroupIdErr:" + err.Error()
  113. return
  114. }
  115. var adminIds []string
  116. var companyIdsStr []string
  117. for _, v := range adminList {
  118. adminIds = append(adminIds, strconv.Itoa(v.AdminId))
  119. }
  120. //再获取组员下被共享的公司
  121. var parsShare []interface{}
  122. var conditionShare string
  123. conditionShare = " AND share_seller_id IN (" + strings.Join(adminIds, ",") + ") "
  124. listCompanyProduct, err := company.GetCompanyProductList(conditionShare, parsShare)
  125. if err != nil {
  126. br.Msg = "获取失败"
  127. br.ErrMsg = "获取失败,GetCompanyProductList:" + err.Error()
  128. return
  129. }
  130. for _, v := range listCompanyProduct {
  131. companyIdsStr = append(companyIdsStr, strconv.Itoa(v.CompanyId))
  132. }
  133. companyIdsStr = append(companyIdsStr, "0")
  134. //本组的或者被分享到本组下面的公司
  135. condition += ` AND (cp.group_id = ` + strconv.Itoa(sysUser.GroupId) + ` OR cp.company_id IN (` + strings.Join(companyIdsStr, ",") + `) )`
  136. }
  137. //状态控制
  138. if status != "" && status != "全部" {
  139. condition += ` AND b.status= '` + status + `'`
  140. usercondition += ` AND cp.status= '` + status + `'`
  141. } else {
  142. condition += ` AND b.status IN ('正式','试用','冻结','永续') `
  143. }
  144. // 试用客户标签
  145. if (status == "试用" || status == "永续") && tryStage > 0 {
  146. condition += ` AND b.try_stage= '` + strconv.Itoa(tryStage) + `'`
  147. usercondition += ` AND cp.try_stage= '` + strconv.Itoa(tryStage) + `'`
  148. }
  149. //套餐类型 权益客户除了大套餐就是小套餐
  150. if status == "正式" && tryStage > 0 {
  151. if tryStage == 1 {
  152. condition += ` AND b.package_type= '` + strconv.Itoa(tryStage) + `'`
  153. usercondition += ` AND cp.package_type= '` + strconv.Itoa(tryStage) + `'`
  154. } else {
  155. condition += ` AND b.package_type!= 1 `
  156. usercondition += ` AND cp.package_type != 1 `
  157. }
  158. }
  159. if isMaker != 2 {
  160. if isMaker == 1 {
  161. usercondition += ` AND u.is_maker = 1 `
  162. } else {
  163. //部分脏数据
  164. usercondition += ` AND u.is_maker != 1 `
  165. }
  166. //parsUser = append(parsUser, isMaker)
  167. }
  168. if isRegister != 2 {
  169. if isRegister == 1 {
  170. usercondition += ` AND u.register_time IS NOT NULL`
  171. } else {
  172. //部分脏数据
  173. usercondition += ` AND u.register_time IS NULL`
  174. }
  175. //parsUser = append(parsUser, isRegister)
  176. }
  177. kwywordcondition = condition
  178. if keyWord != "" {
  179. companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
  180. if err != nil {
  181. br.Msg = "获取客户信息失败"
  182. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  183. return
  184. }
  185. if companyIdStr != "" {
  186. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.credit_code LIKE '%` + keyWord + `%' AND a.company_id IN(` + companyIdStr + `)) `
  187. } else {
  188. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.credit_code LIKE '%` + keyWord + `%' ) `
  189. }
  190. }
  191. if label != "" {
  192. usercondition += ` AND u.user_label LIKE '%` + label + `%'`
  193. }
  194. //
  195. usercondition += ` AND cp.product_id = 2 AND sr.product_id = 2 `
  196. // 是否关注弘则研究公众号
  197. if isSubscribeCygx == 0 {
  198. usercondition += ` AND (u.cygx_subscribe = 0 OR ISNULL(u.cygx_subscribe)) `
  199. }
  200. if isSubscribeCygx == 1 {
  201. usercondition += ` AND u.cygx_subscribe = 1 `
  202. }
  203. condition += ` AND cp.product_id = 2 `
  204. total, err := cygx.GetCompanyListCount(usercondition, keyWord, kwywordcondition, condition, roleTypeCode, pars)
  205. if err != nil {
  206. br.Msg = "获取失败"
  207. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  208. return
  209. }
  210. if sortType == "" {
  211. sqlOrder = ` GROUP by u.user_id ORDER BY c.created_time DESC, u.register_time DESC `
  212. } else {
  213. if sortType == "asc" {
  214. sqlOrder = ` GROUP by u.user_id ORDER BY u.interaction_num ASC , u.register_time DESC `
  215. } else {
  216. sqlOrder = ` GROUP by u.user_id ORDER BY u.interaction_num DESC , u.register_time DESC `
  217. }
  218. }
  219. list, err := cygx.GetCygxCompanyUserList(usercondition, keyWord, kwywordcondition, condition, roleTypeCode, sqlOrder, parsUser, startSize, pageSize)
  220. if err != nil {
  221. br.Msg = "获取失败"
  222. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  223. return
  224. }
  225. var isAdminRole bool
  226. //如果不是管理员身份或者研究员身份则需要添加可见范围处理
  227. if sysUser.Role == utils.ROLE_TYPE_CODE_ADMIN || sysUser.Role == utils.ROLE_TYPE_CODE_RESEARCHR {
  228. isAdminRole = true
  229. }
  230. var userIds string
  231. var userIdArr []int
  232. var companyIds []int
  233. if list != nil {
  234. for k, v := range list {
  235. if v.RegisterTime != "" {
  236. list[k].IsRegister = true
  237. } else {
  238. list[k].IsRegister = false
  239. }
  240. if v.IsShowSeeNum > 0 {
  241. list[k].IsShowSee = true
  242. }
  243. if v.Status == "正式" {
  244. if v.PackageType == 1 {
  245. list[k].Status += "(大套餐)"
  246. } else {
  247. list[k].Status += "(小套餐)"
  248. }
  249. }
  250. if v.Status == "试用" {
  251. if v.TryStage == 1 {
  252. list[k].Status += "(未分类)"
  253. } else if v.TryStage == 2 {
  254. list[k].Status += "(推进)"
  255. } else if v.TryStage == 3 {
  256. list[k].Status += "(跟踪)"
  257. } else if v.TryStage == 4 {
  258. list[k].Status += "(预备)"
  259. }
  260. }
  261. if v.Status == "永续" {
  262. v.Status = "X类试用"
  263. }
  264. userIds += strconv.Itoa(int(v.UserId)) + ","
  265. userIdArr = append(userIdArr, int(v.UserId))
  266. if !isAdminRole {
  267. list[k].CompanyInteractionNum = v.CompanyInteractionNumSeller
  268. }
  269. companyIds = append(companyIds, v.CompanyId)
  270. }
  271. userIds = strings.TrimRight(userIds, ",")
  272. splitList, err := cygx.GetCygxCompanyUserListSplit(userIds)
  273. if err != nil && err.Error() != utils.ErrNoRow() {
  274. br.Msg = "获取失败"
  275. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  276. return
  277. }
  278. //用户备注
  279. userRemarksList, err := cygx.GetUserRemarksListByUserIds(userIds)
  280. if err != nil && err.Error() != utils.ErrNoRow() {
  281. br.Msg = "获取失败"
  282. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  283. return
  284. }
  285. mapUserRemarks := make(map[int]string)
  286. for _, v := range userRemarksList {
  287. if mapUserRemarks[v.UserId] == "" {
  288. mapUserRemarks[v.UserId] = v.Content
  289. }
  290. }
  291. UserRemindListMap := cygxService.GetCygxUserRemindListMap(userIdArr)
  292. mapIsUserMaker := cygxService.GetCompanyProductIsUserMakerByCompanyIds(companyIds) //根据公司ID获取近四周之内有决策人互动的客户
  293. for k, v := range list {
  294. for _, vsplit := range splitList {
  295. if vsplit.UserId == v.UserId {
  296. list[k].HistoryNum = vsplit.HistoryNum
  297. list[k].CountNum = vsplit.CountNum
  298. list[k].IndustryFllowNum = vsplit.IndustryFllowNum
  299. list[k].DepartmentFollowNum = vsplit.DepartmentFollowNum
  300. list[k].KeyWordNum = vsplit.KeyWordNum
  301. list[k].OnLineNum = vsplit.OnLineNum
  302. list[k].OfficeNum = vsplit.OfficeNum
  303. list[k].ChartNum = vsplit.ChartNum
  304. list[k].TripNum = vsplit.TripNum
  305. list[k].RoadshowVideoNum = vsplit.RoadshowVideoNum
  306. list[k].ActivityVideoNum = vsplit.ActivityVideoNum
  307. list[k].ActivityVoiceNum = vsplit.ActivityVoiceNum
  308. list[k].YanxuanspecialNum = vsplit.YanxuanspecialNum
  309. }
  310. }
  311. if mapUserRemarks[int(v.UserId)] != "" {
  312. list[k].Content = mapUserRemarks[int(v.UserId)]
  313. }
  314. list[k].IsRemind = UserRemindListMap[int(v.UserId)]
  315. list[k].IsUserMaker = mapIsUserMaker[v.CompanyId]
  316. }
  317. for k := range list {
  318. list[k].InteractionNum = list[k].HistoryNum + list[k].CountNum + list[k].IndustryFllowNum + list[k].DepartmentFollowNum + list[k].KeyWordNum + list[k].OnLineNum + list[k].OfficeNum + list[k].ChartNum + list[k].TripNum + list[k].RoadshowVideoNum + list[k].ActivityVideoNum + list[k].ActivityVoiceNum + list[k].YanxuanspecialNum
  319. }
  320. } else {
  321. list = make([]*cygx.CygxCompanyUser, 0)
  322. }
  323. page = paging.GetPaging(currentIndex, pageSize, total)
  324. resp := new(cygx.CompanyUserListResp)
  325. resp.List = list
  326. resp.Paging = page
  327. br.Ret = 200
  328. br.Success = true
  329. br.Msg = "获取成功"
  330. br.Data = resp
  331. }
  332. // @Title 新增备注接口
  333. // @Description 新增备注
  334. // @Param request body cygx.UserRemarAddReq true "type json string"
  335. // @Success 200 新增成功
  336. // @router /user/addRemarks [post]
  337. func (this *UserController) Add() {
  338. br := new(models.BaseResponse).Init()
  339. defer func() {
  340. this.Data["json"] = br
  341. this.ServeJSON()
  342. }()
  343. sysUser := this.SysUser
  344. if sysUser == nil {
  345. br.Msg = "请登录"
  346. br.ErrMsg = "请登录,SysUser Is Empty"
  347. br.Ret = 408
  348. return
  349. }
  350. var req cygx.UserRemarAddReq
  351. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  352. if err != nil {
  353. br.Msg = "参数解析异常!"
  354. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  355. return
  356. }
  357. if req.Content == "" {
  358. br.Msg = "请填写内容"
  359. return
  360. }
  361. item := new(cygx.UserRemarks)
  362. item.UserId = req.UserId
  363. item.AdminId = sysUser.AdminId
  364. item.Content = req.Content
  365. item.CreateTime = time.Now()
  366. err = cygx.AddUserRemarks(item)
  367. if err != nil {
  368. br.Msg = "新增失败."
  369. br.ErrMsg = "新增失败,Err:" + err.Error()
  370. return
  371. }
  372. br.Ret = 200
  373. br.Success = true
  374. br.Msg = "新增成功"
  375. }
  376. // @Title 备注列表
  377. // @Description 备注列表接口
  378. // @Param UserId query int true "用户id"
  379. // @Success 200 {object} cygx.UserRemarksListResp
  380. // @router /user/remark/list [get]
  381. func (this *UserController) RemarkList() {
  382. br := new(models.BaseResponse).Init()
  383. defer func() {
  384. this.Data["json"] = br
  385. this.ServeJSON()
  386. }()
  387. sysUser := this.SysUser
  388. if sysUser == nil {
  389. br.Msg = "请登录"
  390. br.ErrMsg = "请登录,SysUser Is Empty"
  391. br.Ret = 408
  392. return
  393. }
  394. userId, _ := this.GetInt("UserId")
  395. if userId < 1 {
  396. br.Msg = "用户不存在"
  397. return
  398. }
  399. list, err := cygx.GetUserRemarksList(userId)
  400. if err != nil && err.Error() != utils.ErrNoRow() {
  401. br.Msg = "获取信息失败"
  402. br.ErrMsg = "获取备注信息失败,Err:" + err.Error()
  403. return
  404. }
  405. resp := new(cygx.UserRemarksListResp)
  406. resp.List = list
  407. br.Ret = 200
  408. br.Success = true
  409. br.Msg = "获取成功"
  410. br.Data = resp
  411. }
  412. // @Title 互动详情table栏
  413. // @Description 互动详情table栏接口
  414. // @Param UserId query int true "用户id"
  415. // @Param ClassType query int true "列表类型,1:权益,2:研选,默认1"
  416. // @Success 200 {object} cygx.UserRemarksListResp
  417. // @router /user/table/list [get]
  418. func (this *UserController) TableList() {
  419. br := new(models.BaseResponse).Init()
  420. defer func() {
  421. this.Data["json"] = br
  422. this.ServeJSON()
  423. }()
  424. sysUser := this.SysUser
  425. if sysUser == nil {
  426. br.Msg = "请登录"
  427. br.ErrMsg = "请登录,SysUser Is Empty"
  428. br.Ret = 408
  429. return
  430. }
  431. userId, _ := this.GetInt("UserId")
  432. if userId < 1 {
  433. br.Msg = "用户不存在"
  434. return
  435. }
  436. classType, _ := this.GetInt("ClassType", 1)
  437. wxUser, err := models.GetWxUserByUserId(userId)
  438. if err != nil {
  439. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  440. br.Msg = "获取信息失败"
  441. return
  442. }
  443. comanyDetail, err := company.GetCompanyDetailById(wxUser.CompanyId)
  444. if err != nil {
  445. br.Msg = "获取信息失败"
  446. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  447. return
  448. }
  449. resp := new(cygx.CygxUserTableListRep)
  450. if classType == 1 {
  451. countDetail, err := cygx.GetUserInteractionTableCount(userId)
  452. if err != nil {
  453. br.Msg = "获取信息失败"
  454. br.ErrMsg = "获取各个阅读总数失败,Err:" + err.Error()
  455. return
  456. }
  457. calendarTotal, err := roadshow.GetRsCalendarMeetingUserCountByUserId(userId)
  458. if err != nil {
  459. br.Msg = "获取信息失败"
  460. br.ErrMsg = "GetCygxUserFeedbackCountByUserId,Err:" + err.Error()
  461. return
  462. }
  463. List := []*cygx.CygxUserTableRep{{PermissionName: "报告阅读列表", Source: 1, TotalNum: countDetail.HistoryNum},
  464. {PermissionName: "活动互动记录", Source: 2, TotalNum: countDetail.OnLineNum + countDetail.OfficeNum},
  465. {PermissionName: "专项调研", Source: 8, TotalNum: countDetail.TripNum},
  466. {PermissionName: "1v1路演", Source: 15, TotalNum: calendarTotal},
  467. {PermissionName: "收藏的报告", Source: 3, TotalNum: countDetail.CountNum},
  468. {PermissionName: "收藏的图表", Source: 4, TotalNum: countDetail.ChartNum},
  469. {PermissionName: "关注的产业", Source: 5, TotalNum: countDetail.IndustryFllowNum},
  470. {PermissionName: "搜索", Source: 7, TotalNum: countDetail.KeyWordNum},
  471. {PermissionName: "音视频播放", Source: 9, TotalNum: countDetail.RoadshowVideoNum + countDetail.ActivityVideoNum + countDetail.ActivityVoiceNum},
  472. {PermissionName: "首页标签点击", Source: 10, TotalNum: countDetail.TagNum},
  473. {PermissionName: "交流反馈", Source: 14, TotalNum: countDetail.FeedbackNum}}
  474. resp.List = List
  475. } else {
  476. countDetail, err := cygx.GetUserInteractionTableCountByYanXuan(userId)
  477. if err != nil {
  478. br.Msg = "获取信息失败"
  479. br.ErrMsg = "获取各个阅读总数失败,Err:" + err.Error()
  480. return
  481. }
  482. List := []*cygx.CygxUserTableRep{{PermissionName: "报告阅读列表", Source: 1, TotalNum: countDetail.HistoryNum},
  483. {PermissionName: "活动互动记录", Source: 2, TotalNum: countDetail.OnLineNum + countDetail.OfficeNum},
  484. {PermissionName: "收藏的报告", Source: 3, TotalNum: countDetail.CountNum},
  485. {PermissionName: "关注的产业", Source: 5, TotalNum: countDetail.IndustryFllowNum},
  486. {PermissionName: "关注的作者", Source: 6, TotalNum: countDetail.DepartmentFollowNum},
  487. {PermissionName: "专栏文章阅读记录", Source: 11, TotalNum: countDetail.YanxuanSpecialNum},
  488. {PermissionName: "收藏的专栏文章", Source: 12, TotalNum: countDetail.YanxuanSpecialCollectNum},
  489. {PermissionName: "关注的专栏作者", Source: 13, TotalNum: countDetail.YanxuanSpecialFollowNum},
  490. {PermissionName: "搜索", Source: 7, TotalNum: countDetail.KeyWordNum}}
  491. resp.List = List
  492. }
  493. //阅读记录总数
  494. resp.UserName = wxUser.RealName
  495. resp.Mobile = wxUser.Mobile
  496. resp.ComapnyName = comanyDetail.CompanyName
  497. br.Ret = 200
  498. br.Success = true
  499. br.Msg = "获取成功"
  500. br.Data = resp
  501. }
  502. // @Title 互动详情
  503. // @Description 互动详情接口
  504. // @Param UserId query int true "用户id"
  505. // @Param Source query int true "来源"
  506. // @Param IdentityType query int true "身份类型,1:用户,2机构。默认1 (图表分页使用)"
  507. // @Param IsMeeting query string true "是否到会 1到会、2未到会"
  508. // @Param MeetType query string true "参会方式 1线上,2线下 默认为线上"
  509. // @Param PageSize query int true "每页数据条数"
  510. // @Param CurrentIndex query int true "当前页页码,从1开始"
  511. // @Param StartDate query string true "开始时间"
  512. // @Param EndDate query string true "结束时间"
  513. // @Param KeyWord query string true "搜索关键词"
  514. // @Param ClassType query int true "列表类型,1:权益,2:研选,默认1"
  515. // @Param IsExport query bool false "是否导出excel,默认是false"
  516. // @Success 200 {object} cygx.UserInteractionListResp
  517. // @router /user/interaction/detail [get]
  518. func (this *UserController) TableDetail() {
  519. br := new(models.BaseResponse).Init()
  520. defer func() {
  521. this.Data["json"] = br
  522. this.ServeJSON()
  523. }()
  524. sysUser := this.SysUser
  525. if sysUser == nil {
  526. br.Msg = "请登录"
  527. br.ErrMsg = "请登录,SysUser Is Empty"
  528. br.Ret = 408
  529. return
  530. }
  531. pageSize, _ := this.GetInt("PageSize")
  532. currentIndex, _ := this.GetInt("CurrentIndex")
  533. var startSize int
  534. if pageSize <= 0 {
  535. pageSize = utils.PageSize20
  536. }
  537. if currentIndex <= 0 {
  538. currentIndex = 1
  539. }
  540. startSize = paging.StartIndex(currentIndex, pageSize)
  541. userId, _ := this.GetInt("UserId")
  542. isMeeting := this.GetString("IsMeeting")
  543. meetType := this.GetString("MeetType")
  544. startDate := this.GetString("StartDate")
  545. endDate := this.GetString("EndDate")
  546. keyWord := this.GetString("KeyWord")
  547. source, _ := this.GetInt("Source")
  548. identityType, _ := this.GetInt("IdentityType")
  549. classType, _ := this.GetInt("ClassType", 1)
  550. //是否导出报表
  551. isExport, _ := this.GetBool("IsExport")
  552. if isExport {
  553. pageSize = 10000
  554. currentIndex = 1
  555. }
  556. if userId < 1 {
  557. br.Msg = "用户不存在"
  558. return
  559. }
  560. // 1.标记用户表
  561. //操作权限校验
  562. var err error
  563. wxUser, err := models.GetWxUserByUserId(userId)
  564. if err != nil {
  565. br.Msg = "获取信息失败"
  566. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  567. return
  568. }
  569. mobile := wxUser.Mobile
  570. //var checkSource bool
  571. var MeetingNum int
  572. var NoMeetingNum int
  573. var list []*cygx.UserInteraction
  574. var total int
  575. var condition string
  576. var pars []interface{}
  577. if source == 1 {
  578. if startDate != "" {
  579. startDate += " 00:00:00"
  580. condition += ` AND r.create_time >= '` + startDate + `' `
  581. }
  582. if endDate != "" {
  583. endDate += " 23:59:59"
  584. condition += ` AND r.create_time <= '` + endDate + `' `
  585. }
  586. if wxUser.Mobile == "" {
  587. wxUser.Mobile = wxUser.Email
  588. }
  589. //total, err = cygx.GetCygxArticleHistoryCount(wxUser.Mobile, wxUser.Email, condition)
  590. //if err != nil {
  591. // br.Msg = "获取信息失败"
  592. // br.ErrMsg = "获取用户阅读记录总数失败,Err:" + err.Error()
  593. // return
  594. //}
  595. if classType == 1 {
  596. condition += " AND art.article_type_id = 0 "
  597. } else {
  598. condition += " AND art.article_type_id > 0 "
  599. }
  600. condition += " AND (r.mobile = '" + wxUser.Mobile + "' OR r.email = '" + wxUser.Mobile + "') "
  601. total, list, err = cygx.GetCygxArticleHistoryRecordByUserNew(condition, startSize, pageSize)
  602. if err != nil && err.Error() != utils.ErrNoRow() {
  603. br.Msg = "获取信息失败"
  604. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  605. return
  606. }
  607. var articleIds string
  608. var articleIdArr []int
  609. if len(list) > 0 {
  610. articleIds = ""
  611. mapAricleId := make(map[int]int)
  612. mapAricleIndustrialSubjectName := make(map[int]*cygx.ArticleIndustrialSubjectNameResp)
  613. for k, v := range list {
  614. if v.ArticleId >= utils.SummaryArticleId {
  615. list[k].ArticleType = 1
  616. } else {
  617. list[k].ArticleType = 2
  618. }
  619. if mapAricleId[v.ArticleId] == 0 {
  620. articleIds += strconv.Itoa(v.ArticleId) + ","
  621. mapAricleId[v.ArticleId] = v.ArticleId
  622. }
  623. list[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
  624. list[k].RegisterPlatformText = cygxService.GetArticleSourcePlatformText(v.RegisterPlatform)
  625. articleIdArr = append(articleIdArr, v.ArticleId)
  626. }
  627. articleIds = strings.TrimRight(articleIds, ",")
  628. listArticleIndustrialSubjectList, err := cygx.GetCygxArticleIndustrialSubjectName(articleIds)
  629. if err != nil && err.Error() != utils.ErrNoRow() {
  630. br.Msg = "获取信息失败"
  631. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  632. return
  633. }
  634. if len(listArticleIndustrialSubjectList) > 0 {
  635. for _, v := range listArticleIndustrialSubjectList {
  636. mapAricleIndustrialSubjectName[v.ArticleId] = v
  637. }
  638. for k, v := range list {
  639. if mapAricleIndustrialSubjectName[v.ArticleId] != nil {
  640. list[k].IndustryName = mapAricleIndustrialSubjectName[v.ArticleId].IndustryName // 产业
  641. list[k].SubjectNameStr = mapAricleIndustrialSubjectName[v.ArticleId].SubjectNameStr // 标的
  642. }
  643. }
  644. }
  645. //行业
  646. mapPerssionName := cygxService.GetCygxArticlePerssionNameListMap(articleIdArr)
  647. for k, v := range list {
  648. if v.SpecialType > 0 {
  649. list[k].PermissionName = utils.CHART_PERMISSION_NAME_MF_YANXUAN
  650. } else {
  651. list[k].PermissionName = mapPerssionName[v.ArticleId]
  652. }
  653. if classType == 1 {
  654. list[k].HttpUrl = utils.CYGX_WEB_URL + "/material/info/" + strconv.Itoa(v.ArticleId)
  655. } else {
  656. list[k].HttpUrl = utils.CYGX_MFYX_URL + "/material/info/" + strconv.Itoa(v.ArticleId)
  657. }
  658. }
  659. //导出excel
  660. if isExport {
  661. exportListArticle(this, list, 1, br)
  662. return
  663. }
  664. }
  665. } else if source == 2 {
  666. if mobile != "" {
  667. condition = ` AND s.mobile = '` + mobile + `' `
  668. if classType == 1 {
  669. condition += " AND a.chart_permission_id != 31 "
  670. } else {
  671. condition += " AND a.chart_permission_id = 31 "
  672. }
  673. if isMeeting == "1" {
  674. condition += ` AND s.is_meeting = 1 `
  675. }
  676. if isMeeting == "2" {
  677. condition += ` AND s.is_meeting = 0 `
  678. }
  679. if meetType == "1" {
  680. condition += ` AND t.activity_type = 1 `
  681. }
  682. if meetType == "2" {
  683. condition += ` AND t.activity_type = 0 `
  684. }
  685. if startDate != "" {
  686. startDate += " 00:00:00"
  687. condition += ` AND a.activity_time >= '` + startDate + `' `
  688. }
  689. if endDate != "" {
  690. endDate += " 23:59:59"
  691. condition += ` AND a.activity_time <= '` + endDate + `' `
  692. }
  693. if keyWord != "" {
  694. condition += ` AND a.activity_name LIKE '%` + keyWord + `%' `
  695. }
  696. total, err = cygx.GetActivityMeetByUserCount(condition)
  697. if err != nil {
  698. br.Msg = "获取信息失败"
  699. br.ErrMsg = "获取参会总数失败,Err:" + err.Error()
  700. return
  701. }
  702. list, err = cygx.GetActivityMeetByUser(condition, startSize, pageSize)
  703. if err != nil && err.Error() != utils.ErrNoRow() {
  704. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  705. br.Msg = "获取参会人数列表失败"
  706. return
  707. }
  708. if len(list) > 0 {
  709. for k, v := range list {
  710. if v.ActivityType == 1 {
  711. if v.SignupType == "2" {
  712. list[k].InteractionType = "自主拨入"
  713. } else {
  714. list[k].InteractionType = "预约外呼"
  715. }
  716. if v.ReminderNum > 0 {
  717. list[k].InteractionType += "会议提醒"
  718. }
  719. }
  720. if v.IsMeeting == 0 {
  721. list[k].FirstMeetingTime = ""
  722. list[k].LastMeetingTime = ""
  723. }
  724. if v.FirstMeetingTime == "0000-00-00 00:00:00" {
  725. list[k].FirstMeetingTime = ""
  726. list[k].LastMeetingTime = ""
  727. }
  728. }
  729. }
  730. }
  731. //导出excel
  732. if isExport {
  733. exportListActivity(this, list, 1, br)
  734. return
  735. }
  736. } else if source == 3 {
  737. if classType == 1 {
  738. condition += " AND art.article_type_id = 0 "
  739. } else {
  740. condition += " AND art.article_type_id > 0 "
  741. }
  742. total, err = cygx.GetCygxArticleCollectCount(userId, condition)
  743. if err != nil {
  744. br.Msg = "获取信息失败"
  745. br.ErrMsg = "获取用户收藏记录总数失败,Err:" + err.Error()
  746. return
  747. }
  748. list, err = cygx.GetCygxArticleCollectByUser(userId, startSize, pageSize, condition)
  749. if err != nil && err.Error() != utils.ErrNoRow() {
  750. br.Msg = "获取信息失败"
  751. br.ErrMsg = "获取用户搜藏记录失败,Err:" + err.Error()
  752. return
  753. }
  754. if len(list) > 0 {
  755. for k, v := range list {
  756. if v.ArticleId >= utils.SummaryArticleId {
  757. list[k].ArticleType = 1
  758. } else {
  759. list[k].ArticleType = 2
  760. }
  761. if classType == 1 {
  762. list[k].HttpUrl = utils.CYGX_WEB_URL + "/material/info/" + strconv.Itoa(v.ArticleId)
  763. } else {
  764. list[k].HttpUrl = utils.CYGX_MFYX_URL + "/material/info/" + strconv.Itoa(v.ArticleId)
  765. }
  766. }
  767. }
  768. } else if source == 4 {
  769. if identityType == 2 {
  770. condition += ` AND r.create_time < date_format(now(),'%Y-%m-%d') ` //过滤当天时间
  771. }
  772. condition += ` AND a.publish_status = 1 AND user_id = ` + strconv.Itoa(userId)
  773. var err error
  774. total, err = cygx.GetChartCountByUser(condition)
  775. if err != nil {
  776. br.Msg = "获取信息失败"
  777. br.ErrMsg = "获取总数失败,Err:" + err.Error()
  778. return
  779. }
  780. list, err = cygx.GetChartListCollectionWithCygx(condition, startSize, pageSize)
  781. if err != nil {
  782. br.Msg = "获取信息失败"
  783. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  784. return
  785. }
  786. for k, v := range list {
  787. if v.PtagName != "" {
  788. list[k].CtagNamePc = v.PtagName
  789. }
  790. if v.CtagName != "" {
  791. list[k].CtagNamePc += "," + v.CtagName
  792. }
  793. if v.PtagNameTwo != "" {
  794. list[k].CtagNamePc += "," + v.PtagNameTwo
  795. }
  796. if v.CtagNameTwo != "" {
  797. list[k].CtagNamePc += "," + v.CtagNameTwo
  798. }
  799. }
  800. } else if source == 5 {
  801. if classType == 1 {
  802. condition += " AND a.chart_permission_id = 31 "
  803. } else {
  804. condition += " AND a.chart_permission_id = 31 "
  805. }
  806. total, err = cygx.GetCygxIndustryFllowCount(userId, condition)
  807. if err != nil {
  808. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  809. br.Msg = "获取用户关注总数失败"
  810. return
  811. }
  812. list, err = cygx.GetCygxIndustryFllowByUser(userId, startSize, pageSize, condition)
  813. if err != nil && err.Error() != utils.ErrNoRow() {
  814. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  815. br.Msg = "获取用户关注总数失败"
  816. return
  817. }
  818. } else if source == 6 {
  819. total, err = cygx.GetCygArticleDepartmentFollowCount(userId)
  820. if err != nil {
  821. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  822. br.Msg = "获取关注作者总数失败"
  823. return
  824. }
  825. list, err = cygx.GetCygArticleDepartmentFollowByUser(userId, startSize, pageSize)
  826. if err != nil && err.Error() != utils.ErrNoRow() {
  827. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  828. br.Msg = "获取关注作者列表失败"
  829. return
  830. }
  831. if len(list) > 0 {
  832. for k, v := range list {
  833. var condition string
  834. var pars []interface{}
  835. condition += ` WHERE art.source = 1 AND art.is_summary = 1 AND art.department_id = ` + strconv.Itoa(v.DepartmentId)
  836. listArt, errList := cygx.GetSummaryManageList(condition, pars, 0, 20)
  837. if errList != nil && errList.Error() != utils.ErrNoRow() {
  838. br.Msg = "获取失败"
  839. br.ErrMsg = "获取失败,Err:" + errList.Error()
  840. return
  841. }
  842. if len(listArt) > 0 {
  843. mapIndustryName := make(map[string]string)
  844. mapSubjectName := make(map[string]string)
  845. var articleIdStr string
  846. for _, vArt := range listArt {
  847. if vArt.IndustryName != "" && mapIndustryName[vArt.IndustryName] == "" {
  848. list[k].IndustryName += vArt.IndustryName + "/"
  849. mapIndustryName[vArt.IndustryName] = vArt.IndustryName
  850. }
  851. articleIdStr += strconv.Itoa(vArt.ArticleId) + ","
  852. }
  853. list[k].IndustryName = strings.TrimRight(list[k].IndustryName, "/")
  854. articleIdStr = strings.TrimRight(articleIdStr, ",")
  855. listSubject, err := cygx.GetArticleSubjectList(articleIdStr)
  856. if err != nil {
  857. br.Msg = "获取失败"
  858. br.ErrMsg = "获取失败,Err:" + err.Error()
  859. return
  860. }
  861. if len(listSubject) > 0 {
  862. for _, vSub := range listSubject {
  863. if vSub.SubjectName != "" && mapSubjectName[vSub.SubjectName] == "" {
  864. list[k].SubjectNameStr += vSub.SubjectName + "/"
  865. mapSubjectName[vSub.SubjectName] = vSub.SubjectName
  866. }
  867. }
  868. list[k].SubjectNameStr = strings.TrimRight(list[k].SubjectNameStr, "/")
  869. }
  870. }
  871. }
  872. }
  873. } else if source == 7 {
  874. if classType == 1 {
  875. condition += " AND register_platform IN (1,2) "
  876. } else {
  877. condition += " AND register_platform IN (5,6) "
  878. }
  879. total, err = cygx.GetCygxSearchKeyWordCount(userId, condition)
  880. if err != nil {
  881. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  882. br.Msg = "获取搜索记录失败"
  883. return
  884. }
  885. list, err = cygx.GetCygxSearchKeyWordByUser(condition, userId, startSize, pageSize)
  886. if err != nil && err.Error() != utils.ErrNoRow() {
  887. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  888. br.Msg = "获取搜索记录列表失败"
  889. return
  890. }
  891. } else if source == 8 {
  892. condition += ` AND h.user_id = ? `
  893. pars = append(pars, userId)
  894. total, err = cygx.GetCygxActivitySpecialTripCount(condition, pars)
  895. if err != nil {
  896. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  897. br.Msg = "获取搜索记录失败"
  898. return
  899. }
  900. list, err = cygx.GetCygxActivitySpecialTripByUser(userId, startSize, pageSize)
  901. if err != nil && err.Error() != utils.ErrNoRow() {
  902. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  903. br.Msg = "获取搜索记录列表失败"
  904. return
  905. }
  906. } else if source == 9 {
  907. total, err = cygx.GetCygxRoadshowCount(userId)
  908. if err != nil {
  909. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  910. br.Msg = "获取搜索记录失败"
  911. return
  912. }
  913. list, err = cygx.GetCygxRoadshowByUser(userId, startSize, pageSize)
  914. if err != nil && err.Error() != utils.ErrNoRow() {
  915. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  916. br.Msg = "获取搜索记录列表失败"
  917. return
  918. }
  919. } else if source == 10 { //标签点击记录
  920. total, err = cygx.GetCygxTagHistoryCountByUserId(userId)
  921. if err != nil {
  922. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  923. br.Msg = "获取搜索记录失败"
  924. return
  925. }
  926. list, err = cygx.GetCygxTagHistoryByUserId(userId, startSize, pageSize)
  927. if err != nil && err.Error() != utils.ErrNoRow() {
  928. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  929. br.Msg = "获取搜索记录列表失败"
  930. return
  931. }
  932. } else if source == 11 { //专栏文章阅读记录
  933. if startDate != "" {
  934. startDate += " 00:00:00"
  935. condition += ` AND r.create_time >= '` + startDate + `' `
  936. }
  937. if endDate != "" {
  938. endDate += " 23:59:59"
  939. condition += ` AND r.create_time <= '` + endDate + `' `
  940. }
  941. if wxUser.Mobile == "" {
  942. wxUser.Mobile = wxUser.Email
  943. }
  944. condition += " AND (r.mobile = '" + wxUser.Mobile + "' OR r.email = '" + wxUser.Mobile + "') "
  945. total, list, err = cygx.GetCygxYanxuaSspecialHistoryRecordByUser(condition, startSize, pageSize)
  946. if err != nil && err.Error() != utils.ErrNoRow() {
  947. br.Msg = "获取信息失败"
  948. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  949. return
  950. }
  951. if len(list) > 0 {
  952. for k, v := range list {
  953. list[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
  954. list[k].RegisterPlatformText = cygxService.GetArticleSourcePlatformText(v.RegisterPlatform)
  955. list[k].HttpUrl = utils.CYGX_MFYX_URL + "/column/detail/" + strconv.Itoa(v.ArticleId)
  956. }
  957. }
  958. //导出excel
  959. if isExport {
  960. exportListYanxuanSpecial(this, list, 1, br)
  961. return
  962. }
  963. } else if source == 12 { //收藏的专栏文章
  964. if startDate != "" {
  965. startDate += " 00:00:00"
  966. condition += ` AND r.create_time >= '` + startDate + `' `
  967. }
  968. if endDate != "" {
  969. endDate += " 23:59:59"
  970. condition += ` AND r.create_time <= '` + endDate + `' `
  971. }
  972. if wxUser.Mobile == "" {
  973. wxUser.Mobile = wxUser.Email
  974. }
  975. condition += " AND (r.mobile = '" + wxUser.Mobile + "' OR r.email = '" + wxUser.Mobile + "') "
  976. total, list, err = cygx.GetCygxYanxuanSpecialCollectByUser(condition, startSize, pageSize)
  977. if err != nil && err.Error() != utils.ErrNoRow() {
  978. br.Msg = "获取信息失败"
  979. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  980. return
  981. }
  982. if len(list) > 0 {
  983. for k, v := range list {
  984. list[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
  985. list[k].RegisterPlatformText = cygxService.GetArticleSourcePlatformText(v.RegisterPlatform)
  986. list[k].HttpUrl = utils.CYGX_MFYX_URL + "/column/detail/" + strconv.Itoa(v.ArticleId)
  987. }
  988. }
  989. } else if source == 13 { //关注的专栏作者
  990. if startDate != "" {
  991. startDate += " 00:00:00"
  992. condition += ` AND r.create_time >= '` + startDate + `' `
  993. }
  994. if endDate != "" {
  995. endDate += " 23:59:59"
  996. condition += ` AND r.create_time <= '` + endDate + `' `
  997. }
  998. if wxUser.Mobile == "" {
  999. wxUser.Mobile = wxUser.Email
  1000. }
  1001. condition += " AND (r.mobile = '" + wxUser.Mobile + "' OR r.email = '" + wxUser.Mobile + "') "
  1002. total, list, err = cygx.GetCygxYanxuanSpecialAuthorByUser(condition, startSize, pageSize)
  1003. if err != nil && err.Error() != utils.ErrNoRow() {
  1004. br.Msg = "获取信息失败"
  1005. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  1006. return
  1007. }
  1008. if len(list) > 0 {
  1009. for k, v := range list {
  1010. list[k].HttpUrl = utils.CYGX_MFYX_URL + "/column/view/" + strconv.Itoa(v.DepartmentId)
  1011. }
  1012. }
  1013. } else if source == 14 { //交流反馈
  1014. if startDate != "" {
  1015. startDate += " 00:00:00"
  1016. condition += ` AND r.create_time >= '` + startDate + `' `
  1017. }
  1018. if endDate != "" {
  1019. endDate += " 23:59:59"
  1020. condition += ` AND r.create_time <= '` + endDate + `' `
  1021. }
  1022. if wxUser.Mobile == "" {
  1023. wxUser.Mobile = wxUser.Email
  1024. }
  1025. condition += " AND (r.mobile = '" + wxUser.Mobile + "' OR r.email = '" + wxUser.Mobile + "') "
  1026. total, list, err = cygx.GetCygxUserFeedback(condition, startSize, pageSize)
  1027. if err != nil {
  1028. br.Msg = "获取信息失败"
  1029. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  1030. return
  1031. }
  1032. } else if source == 15 { //1V1路演
  1033. if startDate != "" {
  1034. condition += ` AND b.start_date >= '` + startDate + `' `
  1035. }
  1036. if endDate != "" {
  1037. condition += ` AND b.start_date <= '` + endDate + `' `
  1038. }
  1039. if wxUser.Mobile == "" {
  1040. wxUser.Mobile = wxUser.Email
  1041. }
  1042. condition += " AND (r.mobile = '" + wxUser.Mobile + "' OR r.email = '" + wxUser.Mobile + "') "
  1043. totalRsCalendar, listRsCalendar, err := roadshow.GetRsCalendarMeetingUserByRai(condition, startSize, pageSize)
  1044. if err != nil {
  1045. br.Msg = "获取信息失败"
  1046. br.ErrMsg = "获取用户阅读记录,GetRsCalendarMeetingUserByRai Err:" + err.Error()
  1047. return
  1048. }
  1049. total = totalRsCalendar
  1050. list, err = cygxService.HandleListRsCalendar(listRsCalendar)
  1051. if err != nil {
  1052. br.Msg = "获取信息失败"
  1053. br.ErrMsg = "HandleListRsCalendar,Err:" + err.Error()
  1054. return
  1055. }
  1056. //导出excel
  1057. if isExport {
  1058. exportListRsCalendar(this, list, 1, br)
  1059. return
  1060. }
  1061. }
  1062. page := paging.GetPaging(currentIndex, pageSize, total)
  1063. resp := new(cygx.UserInteractionListResp)
  1064. if len(list) == 0 {
  1065. list = make([]*cygx.UserInteraction, 0)
  1066. }
  1067. resp.MeetingNum = MeetingNum
  1068. resp.NoMeetingNum = NoMeetingNum
  1069. resp.List = list
  1070. resp.Paging = page
  1071. br.Ret = 200
  1072. br.Success = true
  1073. br.Msg = "获取成功"
  1074. br.Data = resp
  1075. }
  1076. // @Title 获取用户标签详情
  1077. // @Description 获取用户标签详情接口
  1078. // @Param UserId query int true "用户id"
  1079. // @Success 200 {object} cygx.UserLabel
  1080. // @router /user/label/detail [get]
  1081. func (this *UserController) LabelDetail() {
  1082. br := new(models.BaseResponse).Init()
  1083. defer func() {
  1084. this.Data["json"] = br
  1085. this.ServeJSON()
  1086. }()
  1087. sysUser := this.SysUser
  1088. if sysUser == nil {
  1089. br.Msg = "请登录"
  1090. br.ErrMsg = "请登录,SysUser Is Empty"
  1091. br.Ret = 408
  1092. return
  1093. }
  1094. userId, _ := this.GetInt("UserId")
  1095. if userId < 1 {
  1096. br.Msg = "用户不存在"
  1097. return
  1098. }
  1099. wxUser, err := models.GetWxUserByUserId(userId)
  1100. if err != nil {
  1101. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1102. br.Msg = "获取信息失败"
  1103. return
  1104. }
  1105. if userId > 0 {
  1106. resp := new(cygx.UserLabel)
  1107. resp.Label = wxUser.UserLabel
  1108. br.Ret = 200
  1109. br.Success = true
  1110. br.Msg = "获取成功"
  1111. br.Data = resp
  1112. return
  1113. }
  1114. list, err := cygx.GetCygxCompanyUserListSplit(strconv.Itoa(userId))
  1115. if err != nil {
  1116. br.Msg = "获取失败"
  1117. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1118. return
  1119. }
  1120. mapLabels := make(map[string]string)
  1121. var labelsListStr []*cygx.UserLabel
  1122. mapActivityLabels := make(map[string]string)
  1123. for k := range list {
  1124. labels := list[k].Labels
  1125. labelsList := strings.Split(labels, ",")
  1126. for _, vL := range labelsList {
  1127. if mapLabels[vL] == "" && vL != "" {
  1128. mapLabels[vL] = vL
  1129. item := new(cygx.UserLabel)
  1130. item.Label = vL
  1131. labelsListStr = append(labelsListStr, item)
  1132. }
  1133. }
  1134. }
  1135. dateTime := time.Now().AddDate(0, -3, 0).Format(utils.FormatDate)
  1136. listArticlePv, err := cygx.GetArticlePvCount(wxUser.Mobile, wxUser.Email, dateTime)
  1137. if err != nil && err.Error() != utils.ErrNoRow() {
  1138. br.Msg = "获取失败"
  1139. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1140. return
  1141. }
  1142. var articleIds string
  1143. mapArticleIdLabelTotal := make(map[string]int)
  1144. mapArticleIdPv := make(map[int]int)
  1145. if len(listArticlePv) > 0 {
  1146. for _, v := range listArticlePv {
  1147. articleIds += strconv.Itoa(v.ArticleId) + ","
  1148. mapArticleIdPv[v.ArticleId] = v.Pv
  1149. }
  1150. articleIds = strings.TrimRight(articleIds, ",")
  1151. //产业、标的标签
  1152. listLabelName, err := cygx.GetArticleGroupyIndustryName(articleIds)
  1153. if err != nil && err.Error() != utils.ErrNoRow() {
  1154. br.Msg = "获取失败"
  1155. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1156. return
  1157. }
  1158. if len(listLabelName) > 0 {
  1159. for _, v := range listLabelName {
  1160. labelsIndustryList := strings.Split(v.IndustryName, "/")
  1161. labelsSubjectList := strings.Split(v.SubjectName, "/")
  1162. //添加产业统计
  1163. if len(labelsIndustryList) > 0 {
  1164. for _, vIn := range labelsIndustryList {
  1165. if mapActivityLabels[vIn] != "" {
  1166. mapArticleIdLabelTotal[vIn] += mapArticleIdPv[v.ArticleId]
  1167. } else {
  1168. mapArticleIdLabelTotal[vIn] = mapArticleIdPv[v.ArticleId]
  1169. mapActivityLabels[vIn] = vIn
  1170. }
  1171. }
  1172. }
  1173. if len(labelsSubjectList) > 0 {
  1174. //添加标的统计
  1175. for _, vIn := range labelsSubjectList {
  1176. if mapActivityLabels[vIn] != "" {
  1177. mapArticleIdLabelTotal[vIn] += mapArticleIdPv[v.ArticleId]
  1178. } else {
  1179. mapArticleIdLabelTotal[vIn] = mapArticleIdPv[v.ArticleId]
  1180. mapActivityLabels[vIn] = vIn
  1181. }
  1182. }
  1183. }
  1184. }
  1185. }
  1186. }
  1187. articleIds, err = cygx.GetCygxArticleCollectId(userId, dateTime)
  1188. if err != nil && err.Error() != utils.ErrNoRow() {
  1189. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1190. br.Msg = "获取用户搜藏记录失败"
  1191. return
  1192. }
  1193. if articleIds != "" {
  1194. //产业、标的标签
  1195. listLabelName, err := cygx.GetArticleGroupyIndustryName(articleIds)
  1196. if err != nil && err.Error() != utils.ErrNoRow() {
  1197. br.Msg = "获取失败"
  1198. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1199. return
  1200. }
  1201. if len(listLabelName) > 0 {
  1202. for _, v := range listLabelName {
  1203. labelsIndustryList := strings.Split(v.IndustryName, "/")
  1204. labelsSubjectList := strings.Split(v.SubjectName, "/")
  1205. //添加产业统计
  1206. if len(labelsIndustryList) > 0 {
  1207. for _, vIn := range labelsIndustryList {
  1208. if mapActivityLabels[vIn] != "" {
  1209. mapArticleIdLabelTotal[vIn] += 1
  1210. } else {
  1211. mapArticleIdLabelTotal[vIn] = 1
  1212. mapActivityLabels[vIn] = vIn
  1213. }
  1214. }
  1215. }
  1216. if len(labelsSubjectList) > 0 {
  1217. //添加标的统计
  1218. for _, vIn := range labelsSubjectList {
  1219. if mapActivityLabels[vIn] != "" {
  1220. mapArticleIdLabelTotal[vIn] += 1
  1221. } else {
  1222. mapArticleIdLabelTotal[vIn] = 1
  1223. mapActivityLabels[vIn] = vIn
  1224. }
  1225. }
  1226. }
  1227. }
  1228. }
  1229. }
  1230. //活动标签计算
  1231. listActivityPv, err := cygx.GetActivitySignCount(wxUser.Mobile, dateTime)
  1232. if err != nil && err.Error() != utils.ErrNoRow() {
  1233. br.Msg = "获取失败"
  1234. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1235. return
  1236. }
  1237. if len(listActivityPv) > 0 {
  1238. for _, v := range listActivityPv {
  1239. labelsList := strings.Split(v.Label, "-")
  1240. for _, v2 := range labelsList {
  1241. labelsListSon := strings.Split(v2, "/")
  1242. for _, v3 := range labelsListSon {
  1243. if mapActivityLabels[v3] != "" {
  1244. mapArticleIdLabelTotal[v3] += 1
  1245. } else {
  1246. mapArticleIdLabelTotal[v3] = 1
  1247. mapActivityLabels[v3] = v3
  1248. }
  1249. }
  1250. }
  1251. }
  1252. }
  1253. //会议提醒部分标签
  1254. listActivityPvByReminder, err := cygx.GetActivityMeetingReminder(wxUser.Mobile, dateTime)
  1255. if err != nil && err.Error() != utils.ErrNoRow() {
  1256. br.Msg = "获取失败"
  1257. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1258. return
  1259. }
  1260. if len(listActivityPvByReminder) > 0 {
  1261. for _, v := range listActivityPvByReminder {
  1262. labelsList := strings.Split(v.Label, "-")
  1263. for _, v2 := range labelsList {
  1264. labelsListSon := strings.Split(v2, "/")
  1265. for _, v3 := range labelsListSon {
  1266. if mapActivityLabels[v3] != "" {
  1267. mapArticleIdLabelTotal[v3] += 1
  1268. } else {
  1269. mapArticleIdLabelTotal[v3] = 1
  1270. mapActivityLabels[v3] = v3
  1271. }
  1272. }
  1273. }
  1274. }
  1275. }
  1276. //对标签数量进行排序
  1277. type KvPair struct {
  1278. Key string
  1279. Val int
  1280. }
  1281. tmpList := make([]KvPair, 0)
  1282. for k, v := range mapArticleIdLabelTotal {
  1283. tmpList = append(tmpList, KvPair{Key: k, Val: v})
  1284. }
  1285. sort.Slice(tmpList, func(i, j int) bool {
  1286. return tmpList[i].Val > tmpList[j].Val // 降序
  1287. })
  1288. for _, v := range tmpList {
  1289. if v.Key != "" {
  1290. mapLabels[v.Key] = v.Key
  1291. item := new(cygx.UserLabel)
  1292. item.Label = v.Key
  1293. labelsListStr = append(labelsListStr, item)
  1294. }
  1295. }
  1296. var labelNew string
  1297. for _, v := range labelsListStr {
  1298. labelNew += v.Label + ","
  1299. }
  1300. labelNew = strings.TrimRight(labelNew, ",")
  1301. resp := new(cygx.UserLabel)
  1302. resp.Label = labelNew
  1303. br.Ret = 200
  1304. br.Success = true
  1305. br.Msg = "获取成功"
  1306. br.Data = resp
  1307. }
  1308. // @Title 状态搜索栏
  1309. // @Description 状态搜索栏接口
  1310. // @Success 200 {object} cygx.CygxUserTableStatusListRep
  1311. // @router /user/status/table [get]
  1312. func (this *UserController) StatusTable() {
  1313. br := new(models.BaseResponse).Init()
  1314. defer func() {
  1315. this.Data["json"] = br
  1316. this.ServeJSON()
  1317. }()
  1318. sysUser := this.SysUser
  1319. if sysUser == nil {
  1320. br.Msg = "请登录"
  1321. br.ErrMsg = "请登录,SysUser Is Empty"
  1322. br.Ret = 408
  1323. return
  1324. }
  1325. listType := []*cygx.CygxTryStageRep{{Name: "大套餐", TryStage: 1}, {Name: "小套餐", TryStage: 2}}
  1326. listStatus := []*cygx.CygxTryStageRep{{Name: "未分类", TryStage: 1}, {Name: "推进", TryStage: 2}, {Name: "跟踪", TryStage: 3}, {Name: "预备", TryStage: 4}}
  1327. List := []*cygx.CygxUserTableStatusRep{{Name: "正式", List: listType, TryStage: "正式"}, {Name: "试用", List: listStatus, TryStage: "试用"}, {Name: "冻结", List: []*cygx.CygxTryStageRep{}, TryStage: "冻结"}, {Name: "X类试用", List: []*cygx.CygxTryStageRep{}, TryStage: "X类试用"}}
  1328. resp := new(cygx.CygxUserTableStatusListRep)
  1329. resp.List = List
  1330. br.Ret = 200
  1331. br.Success = true
  1332. br.Msg = "获取成功"
  1333. br.Data = resp
  1334. }
  1335. // @Title 用户互动量
  1336. // @Description 状态搜索栏接口
  1337. // @Param UserId query int true "用户id"
  1338. // @Success 200 {object} cygx.CygxUserTableStatusListRep
  1339. // @router /user/interactionNum [get]
  1340. func (this *UserController) InteractionNum() {
  1341. br := new(models.BaseResponse).Init()
  1342. defer func() {
  1343. this.Data["json"] = br
  1344. this.ServeJSON()
  1345. }()
  1346. sysUser := this.SysUser
  1347. if sysUser == nil {
  1348. br.Msg = "请登录"
  1349. br.ErrMsg = "请登录,SysUser Is Empty"
  1350. br.Ret = 408
  1351. return
  1352. }
  1353. userId, _ := this.GetInt("UserId")
  1354. if userId < 1 {
  1355. br.Msg = "用户不存在"
  1356. return
  1357. }
  1358. wxUser, err := models.GetWxUserByUserId(userId)
  1359. if err != nil {
  1360. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1361. br.Msg = "获取信息失败"
  1362. return
  1363. }
  1364. cp, err := company.GetCompanyProductByCompanyIdAndProductId(wxUser.CompanyId, 2)
  1365. if err != nil && err.Error() != utils.ErrNoRow() {
  1366. br.Msg = "获取客户信息失败"
  1367. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1368. return
  1369. }
  1370. resp := new(cygx.CygxCygxInteractionNumRespListResp)
  1371. for i := 0; i < 4; i++ {
  1372. item := new(cygx.CygxInteractionNumResp)
  1373. if cp != nil && cp.Status == "正式" {
  1374. //阅读记录总数
  1375. var startDate, endDate string
  1376. item.DateTime = time.Now().AddDate(0, -i, 0).Format("2006.01")
  1377. startDate = utils.GetOneMonthFirstDay(time.Now().AddDate(0, -i, 0)).Format(utils.FormatDate)
  1378. endDate = utils.GetOneMonthLastDay(time.Now().AddDate(0, -i, 0)).Format(utils.FormatDate)
  1379. countDetail, err := cygx.GetCompanyInteractionTableCountBytime(wxUser.CompanyId, startDate, endDate)
  1380. if err != nil {
  1381. br.Msg = "获取信息失败"
  1382. br.ErrMsg = "获取各个阅读总数失败,Err:" + err.Error()
  1383. return
  1384. }
  1385. item.InteractionNum = countDetail.HistoryNum + countDetail.CountNum + countDetail.IndustryFllowNum + countDetail.DepartmentFollowNum + countDetail.KeyWordNum + countDetail.OnLineNum + countDetail.OfficeNum + countDetail.ChartNum
  1386. } else {
  1387. var weekStr string
  1388. switch i {
  1389. case 0:
  1390. weekStr = "本周("
  1391. case 1:
  1392. weekStr = "上周("
  1393. case 2:
  1394. weekStr = "上两周("
  1395. case 3:
  1396. weekStr = "上三周("
  1397. }
  1398. item.DateTime = weekStr + utils.GetNowWeekMonday().AddDate(0, 0, -i*7).Format("01.02") + "~" + utils.GetNowWeekMonday().AddDate(0, 0, -i*7+6).Format("01.02") + ")"
  1399. var startDate, endDate string
  1400. startDate = utils.GetNowWeekMonday().AddDate(0, 0, -i*7).Format(utils.FormatDate)
  1401. endDate = utils.GetNowWeekMonday().AddDate(0, 0, -i*7+6).Format(utils.FormatDate)
  1402. countDetail, err := cygx.GetCompanyInteractionTableCountBytime(wxUser.CompanyId, startDate, endDate)
  1403. if err != nil {
  1404. br.Msg = "获取信息失败"
  1405. br.ErrMsg = "获取各个阅读总数失败,Err:" + err.Error()
  1406. return
  1407. }
  1408. item.InteractionNum = countDetail.HistoryNum + countDetail.CountNum + countDetail.IndustryFllowNum + countDetail.DepartmentFollowNum + countDetail.KeyWordNum + countDetail.OnLineNum + countDetail.OfficeNum + countDetail.ChartNum + countDetail.TripNum + countDetail.RoadshowVideoNum + countDetail.ActivityVideoNum + countDetail.ActivityVoiceNum
  1409. }
  1410. resp.List = append(resp.List, item)
  1411. }
  1412. br.Ret = 200
  1413. br.Success = true
  1414. br.Msg = "获取成功"
  1415. br.Data = resp
  1416. }
  1417. // @Title 标签检索用户相关互动
  1418. // @Description 标签检索用户相关互动接口
  1419. // @Param UserId query int true "用户id"
  1420. // @Param KeyWord query string true "搜索关键词"
  1421. // @Param Source query int true "来源 1:报告阅读,2:报告收藏,3:相关活动,4:专项产业调研"
  1422. // @Success 200 {object} cygx.UserInteractionrelevantListResp
  1423. // @router /user/interaction/relevant [get]
  1424. func (this *UserController) InteractionRelevant() {
  1425. br := new(models.BaseResponse).Init()
  1426. defer func() {
  1427. this.Data["json"] = br
  1428. this.ServeJSON()
  1429. }()
  1430. sysUser := this.SysUser
  1431. if sysUser == nil {
  1432. br.Msg = "请登录"
  1433. br.ErrMsg = "请登录,SysUser Is Empty"
  1434. br.Ret = 408
  1435. return
  1436. }
  1437. userId, _ := this.GetInt("UserId")
  1438. source, _ := this.GetInt("Source")
  1439. keyWord := this.GetString("KeyWord")
  1440. if userId < 1 {
  1441. br.Msg = "用户不存在"
  1442. return
  1443. }
  1444. wxUser, err := models.GetWxUserByUserId(userId)
  1445. if err != nil {
  1446. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1447. br.Msg = "获取信息失败"
  1448. return
  1449. }
  1450. managementIds, err := cygx.GetManagementIdsByName(keyWord)
  1451. if err != nil {
  1452. br.Msg = "获取信息失败"
  1453. br.ErrMsg = "获取产业信息失败,Err:" + err.Error()
  1454. return
  1455. }
  1456. subjectIds, err := cygx.GetIndustrialSubjectIdsByName(keyWord)
  1457. if err != nil {
  1458. br.Msg = "获取信息失败"
  1459. br.ErrMsg = "获取标的信息失败,Err:" + err.Error()
  1460. return
  1461. }
  1462. resp := new(cygx.UserInteractionrelevantListResp)
  1463. var condition string
  1464. if source == 1 || source == 2 {
  1465. var articleIds string
  1466. if managementIds != "" || subjectIds != "" {
  1467. var articleIdmanagement string
  1468. var articleIdsubject string
  1469. if managementIds != "" {
  1470. articleIdmanagement, err = cygx.GetArticleIdsByIndustrialManagementId(managementIds)
  1471. if err != nil {
  1472. br.Msg = "获取信息失败"
  1473. br.ErrMsg = "获取活动ID信息失败,Err:" + err.Error()
  1474. return
  1475. }
  1476. }
  1477. if subjectIds != "" {
  1478. articleIdsubject, err = cygx.GetArticleIdsBySubjectId(subjectIds)
  1479. if err != nil {
  1480. br.Msg = "获取信息失败"
  1481. br.ErrMsg = "获取活动ID信息失败,Err:" + err.Error()
  1482. return
  1483. }
  1484. }
  1485. if articleIdmanagement != "" && articleIdsubject != "" {
  1486. articleIds = articleIdmanagement + "," + articleIdsubject
  1487. } else if articleIdmanagement != "" && articleIdsubject == "" {
  1488. articleIds = articleIdmanagement
  1489. } else if articleIdmanagement == "" && articleIdsubject != "" {
  1490. articleIds = articleIdsubject
  1491. }
  1492. } else {
  1493. matchDetail, err := cygx.GetCygxReportMappingCygxDetailByName(keyWord)
  1494. if err != nil && err.Error() != utils.ErrNoRow() {
  1495. br.Msg = "获取信息失败"
  1496. br.ErrMsg = "GetCygxReportMappingCygxDetail,Err:" + err.Error()
  1497. return
  1498. }
  1499. if matchDetail != nil {
  1500. var condition string
  1501. var pars []interface{}
  1502. condition = ` AND id_cygx = ? `
  1503. pars = append(pars, matchDetail.Id)
  1504. listGroup, err := cygx.GetCygxReportMappingGroupList(condition, pars, 0, 999)
  1505. if err != nil && err.Error() != utils.ErrNoRow() {
  1506. br.Msg = "获取失败"
  1507. br.ErrMsg = "获取失败,Err:" + err.Error()
  1508. return
  1509. }
  1510. var categoryIds []int
  1511. for _, v := range listGroup {
  1512. categoryIds = append(categoryIds, v.CategoryIdCelue)
  1513. }
  1514. pars = make([]interface{}, 0)
  1515. condition = ` AND category_id IN (` + utils.GetOrmInReplace(len(categoryIds)) + `)`
  1516. pars = append(pars, categoryIds)
  1517. listArticle, err := cygx.GetArticlList(condition, pars, 0, 999)
  1518. if err != nil && err.Error() != utils.ErrNoRow() {
  1519. br.Msg = "获取失败"
  1520. br.ErrMsg = "获取失败,Err:" + err.Error()
  1521. return
  1522. }
  1523. for _, v := range listArticle {
  1524. articleIds += strconv.Itoa(v.ArticleId) + ","
  1525. }
  1526. articleIds = strings.TrimRight(articleIds, ",")
  1527. }
  1528. }
  1529. if articleIds != "" {
  1530. condition = ` AND r.article_id IN (` + articleIds + `)`
  1531. if source == 1 {
  1532. condition += ` AND r.stop_time > 4 `
  1533. resp.List, err = cygx.GetCygxArticleHistoryRecordByUser(wxUser.Mobile, wxUser.Email, condition, 0, 0)
  1534. } else {
  1535. resp.List, err = cygx.GetCygxArticleCollectByUser(userId, 0, 0, condition)
  1536. }
  1537. if err != nil && err.Error() != utils.ErrNoRow() {
  1538. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1539. br.Msg = "获取用户阅读记录"
  1540. return
  1541. }
  1542. if len(resp.List) > 0 {
  1543. for k, v := range resp.List {
  1544. resp.List[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
  1545. resp.List[k].RegisterPlatformText = cygxService.GetArticleSourcePlatformText(v.RegisterPlatform)
  1546. if v.ArticleId >= utils.SummaryArticleId {
  1547. resp.List[k].ArticleType = 1
  1548. } else {
  1549. resp.List[k].ArticleType = 2
  1550. }
  1551. }
  1552. }
  1553. }
  1554. } else if source == 3 {
  1555. activityIdByLabel, err := cygx.GetactivityIdsByLabel(keyWord)
  1556. if err != nil {
  1557. br.Msg = "获取信息失败"
  1558. br.ErrMsg = "获取活动ID信息失败,Err:" + err.Error()
  1559. return
  1560. }
  1561. activityId := activityIdByLabel
  1562. if activityId != "" {
  1563. condition = ` AND s.is_meeting = 1 AND s.activity_id IN (` + activityId + `) AND s.mobile = ` + wxUser.Mobile
  1564. resp.List, err = cygx.GetActivityMeetByUser(condition, 0, 0)
  1565. if err != nil && err.Error() != utils.ErrNoRow() {
  1566. br.Msg = "获取信息失败"
  1567. br.ErrMsg = "获取用户搜藏记录失败,Err:" + err.Error()
  1568. return
  1569. }
  1570. }
  1571. } else if source == 4 {
  1572. activityIdByLabel, err := cygx.GetactivitySpecilIdsByLabel(keyWord)
  1573. if err != nil {
  1574. br.Msg = "获取信息失败"
  1575. br.ErrMsg = "获取活动ID信息失败,Err:" + err.Error()
  1576. return
  1577. }
  1578. activityId := activityIdByLabel
  1579. if activityId != "" {
  1580. condition = ` AND s.is_meeting = 1 AND s.activity_id IN (` + activityId + `) AND s.mobile = ` + wxUser.Mobile
  1581. resp.List, err = cygx.GetActivitySpecialMeetByUser(condition, 0, 0)
  1582. if err != nil && err.Error() != utils.ErrNoRow() {
  1583. br.Msg = "获取信息失败"
  1584. br.ErrMsg = "获取用户搜藏记录失败,Err:" + err.Error()
  1585. return
  1586. }
  1587. }
  1588. }
  1589. if len(resp.List) == 0 {
  1590. resp.List = make([]*cygx.UserInteraction, 0)
  1591. }
  1592. resp.IndustryName = keyWord
  1593. if managementIds != "" {
  1594. count, err := cygx.GetCygxIndustryFllowCountByUser(userId, managementIds)
  1595. if err != nil {
  1596. br.Msg = "获取信息失败"
  1597. br.ErrMsg = "获取用户是否关注失败,Err:" + err.Error()
  1598. return
  1599. }
  1600. if count > 0 {
  1601. resp.IsFllow = true
  1602. }
  1603. }
  1604. br.Ret = 200
  1605. br.Success = true
  1606. br.Msg = "获取成功"
  1607. br.Data = resp
  1608. }
  1609. // @Title 用户相关互动下载
  1610. // @Description 用户相关互动下载接口
  1611. // @Param UserId query int true "用户id"
  1612. // @Param Source query int true "来源 报告阅读列表: 1, 活动互动记录: 2"
  1613. // @Param IsMeeting query string true "是否到会 1到会、2未到会"
  1614. // @Param MeetType query string true "参会方式 1线上,2线下 默认为线上"
  1615. // @Param StartDate query string true "开始时间"
  1616. // @Param EndDate query string true "结束时间"
  1617. // @Param KeyWord query string true "搜索关键词"
  1618. // @Param ClassType query int true "列表类型,1:权益,2:研选,默认1"
  1619. // @Success 200 {object} cygx.CygxUserTableStatusListRep
  1620. // @router /user/export/interaction [get]
  1621. func (this *UserController) ExportInteraction() {
  1622. br := new(models.BaseResponse).Init()
  1623. defer func() {
  1624. this.Data["json"] = br
  1625. this.ServeJSON()
  1626. }()
  1627. sysUser := this.SysUser
  1628. if sysUser == nil {
  1629. br.Msg = "请登录"
  1630. br.ErrMsg = "请登录,SysUser Is Empty"
  1631. br.Ret = 408
  1632. return
  1633. }
  1634. userId, _ := this.GetInt("UserId")
  1635. isMeeting := this.GetString("IsMeeting")
  1636. meetType := this.GetString("MeetType")
  1637. startDate := this.GetString("StartDate")
  1638. endDate := this.GetString("EndDate")
  1639. keyWord := this.GetString("KeyWord")
  1640. source, _ := this.GetInt("Source")
  1641. classType, _ := this.GetInt("ClassType", 1)
  1642. if userId < 1 {
  1643. br.Msg = "用户不存在"
  1644. return
  1645. }
  1646. wxUser, err := models.GetWxUserByUserId(userId)
  1647. if err != nil {
  1648. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1649. br.Msg = "获取信息失败"
  1650. return
  1651. }
  1652. mobile := wxUser.Mobile
  1653. var list []*cygx.UserInteraction
  1654. var condition string
  1655. var sheetName string
  1656. if source == 1 {
  1657. sheetName = "报告阅读列表"
  1658. if startDate != "" {
  1659. startDate += " 00:00:00"
  1660. condition += ` AND r.create_time >= '` + startDate + `' `
  1661. }
  1662. if endDate != "" {
  1663. endDate += " 23:59:59"
  1664. condition += ` AND r.create_time <= '` + endDate + `' `
  1665. }
  1666. if wxUser.Mobile == "" {
  1667. wxUser.Mobile = wxUser.Email
  1668. }
  1669. //total, err = cygx.GetCygxArticleHistoryCount(wxUser.Mobile, wxUser.Email, condition)
  1670. //if err != nil {
  1671. // br.Msg = "获取信息失败"
  1672. // br.ErrMsg = "获取用户阅读记录总数失败,Err:" + err.Error()
  1673. // return
  1674. //}
  1675. if classType == 1 {
  1676. condition += " AND art.article_type_id = 0 "
  1677. } else {
  1678. condition += " AND art.article_type_id > 0 "
  1679. }
  1680. condition += " AND (r.mobile = '" + wxUser.Mobile + "' OR r.email = '" + wxUser.Mobile + "') "
  1681. _, list, err = cygx.GetCygxArticleHistoryRecordByUserNew(condition, 0, 9999)
  1682. if err != nil && err.Error() != utils.ErrNoRow() {
  1683. br.Msg = "获取信息失败"
  1684. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  1685. return
  1686. }
  1687. var articleIds []int
  1688. if len(list) > 0 {
  1689. for k, v := range list {
  1690. if v.ArticleId >= utils.SummaryArticleId {
  1691. list[k].ArticleType = 1
  1692. } else {
  1693. list[k].ArticleType = 2
  1694. }
  1695. if list[k].PermissionName == "" {
  1696. list[k].PermissionName = v.CategoryName
  1697. }
  1698. if v.SpecialType == 0 {
  1699. articleIds = append(articleIds, v.ArticleId)
  1700. }
  1701. }
  1702. mapIndustrialLabel := cygxService.GetArticleIndustrialLabelByArticleId(articleIds) // 关联产业
  1703. mapSubjectLabel := cygxService.GetArticleSubjectLabelByArticleId(articleIds) // 关联标的
  1704. for _, v := range list {
  1705. v.IndustryName = strings.Join(mapIndustrialLabel[v.ArticleId], "/")
  1706. v.SubjectNameStr = strings.Join(mapSubjectLabel[v.ArticleId], "/")
  1707. }
  1708. }
  1709. } else if source == 2 {
  1710. sheetName = "到会管理名单"
  1711. if mobile != "" {
  1712. condition = ` AND s.mobile = '` + mobile + `' `
  1713. if classType == 1 {
  1714. condition += " AND a.chart_permission_id != 31 "
  1715. } else {
  1716. condition += " AND a.chart_permission_id = 31 "
  1717. }
  1718. if isMeeting == "1" {
  1719. condition += ` AND s.is_meeting = 1 `
  1720. }
  1721. if isMeeting == "2" {
  1722. condition += ` AND s.is_meeting = 0 `
  1723. }
  1724. if meetType == "1" {
  1725. condition += ` AND t.activity_type = 1 `
  1726. }
  1727. if meetType == "2" {
  1728. condition += ` AND t.activity_type = 0 `
  1729. }
  1730. if startDate != "" {
  1731. startDate += " 00:00:00"
  1732. condition += ` AND a.activity_time >= '` + startDate + `' `
  1733. }
  1734. if endDate != "" {
  1735. endDate += " 23:59:59"
  1736. condition += ` AND a.activity_time <= '` + endDate + `' `
  1737. }
  1738. if keyWord != "" {
  1739. condition += ` AND a.activity_name LIKE '%` + keyWord + `%' `
  1740. }
  1741. list, err = cygx.GetActivityMeetByUser(condition, 0, 0)
  1742. if err != nil && err.Error() != utils.ErrNoRow() {
  1743. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1744. br.Msg = "获取参会人数列表失败"
  1745. return
  1746. }
  1747. if len(list) > 0 {
  1748. for k, v := range list {
  1749. if v.ActivityType == 1 {
  1750. if v.SignupType == "2" {
  1751. list[k].InteractionType = "自主拨入"
  1752. } else {
  1753. list[k].InteractionType = "预约外呼"
  1754. }
  1755. if v.ReminderNum > 0 {
  1756. list[k].InteractionType += ",会议提醒"
  1757. }
  1758. }
  1759. }
  1760. }
  1761. }
  1762. } else if source == 11 {
  1763. sheetName = "专栏文章阅读记录"
  1764. if startDate != "" {
  1765. startDate += " 00:00:00"
  1766. condition += ` AND r.create_time >= '` + startDate + `' `
  1767. }
  1768. if endDate != "" {
  1769. endDate += " 23:59:59"
  1770. condition += ` AND r.create_time <= '` + endDate + `' `
  1771. }
  1772. if wxUser.Mobile == "" {
  1773. wxUser.Mobile = wxUser.Email
  1774. }
  1775. condition += " AND (r.mobile = '" + wxUser.Mobile + "' OR r.email = '" + wxUser.Mobile + "') "
  1776. _, list, err = cygx.GetCygxYanxuaSspecialHistoryRecordByUser(condition, 0, 9999)
  1777. if err != nil && err.Error() != utils.ErrNoRow() {
  1778. br.Msg = "获取信息失败"
  1779. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  1780. return
  1781. }
  1782. }
  1783. //创建excel
  1784. dir, err := os.Executable()
  1785. exPath := filepath.Dir(dir)
  1786. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  1787. xlsxFile := xlsx.NewFile()
  1788. if err != nil {
  1789. br.Msg = "生成文件失败"
  1790. br.ErrMsg = "生成文件失败"
  1791. return
  1792. }
  1793. style := xlsx.NewStyle()
  1794. alignment := xlsx.Alignment{
  1795. Horizontal: "center",
  1796. Vertical: "center",
  1797. WrapText: true,
  1798. }
  1799. style.Alignment = alignment
  1800. style.ApplyAlignment = true
  1801. sheet, err := xlsxFile.AddSheet(sheetName)
  1802. if err != nil {
  1803. br.Msg = "新增Sheet失败"
  1804. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  1805. return
  1806. }
  1807. if source == 1 {
  1808. //标头
  1809. rowTitle := sheet.AddRow()
  1810. cellA := rowTitle.AddCell()
  1811. cellA.Value = "报告标题"
  1812. cellB := rowTitle.AddCell()
  1813. cellB.Value = "所属行业"
  1814. cellC := rowTitle.AddCell()
  1815. cellC.Value = "所属产业"
  1816. cellD := rowTitle.AddCell()
  1817. cellD.Value = "关联标的"
  1818. cellE := rowTitle.AddCell()
  1819. cellE.Value = "发布时间"
  1820. cellF := rowTitle.AddCell()
  1821. cellF.Value = "阅读时间"
  1822. cellG := rowTitle.AddCell()
  1823. cellG.Value = "阅读时长"
  1824. for _, item := range list {
  1825. row := sheet.AddRow()
  1826. cellA := row.AddCell()
  1827. cellA.Value = item.Title
  1828. cellB := row.AddCell()
  1829. cellB.Value = item.PermissionName
  1830. cellC := row.AddCell()
  1831. cellC.Value = item.IndustryName
  1832. cellD := row.AddCell()
  1833. cellD.Value = item.SubjectNameStr
  1834. cellE := row.AddCell()
  1835. cellE.Value = item.PublishDate
  1836. cellF := row.AddCell()
  1837. cellF.Value = item.CreateTime
  1838. cellG := row.AddCell()
  1839. cellG.Value = item.StopTime
  1840. }
  1841. } else if source == 2 {
  1842. //标头
  1843. rowTitle := sheet.AddRow()
  1844. cellA := rowTitle.AddCell()
  1845. cellA.Value = "活动名称"
  1846. cellB := rowTitle.AddCell()
  1847. cellB.Value = "所属行业"
  1848. cellC := rowTitle.AddCell()
  1849. cellC.Value = "活动类型"
  1850. cellD := rowTitle.AddCell()
  1851. cellD.Value = "活动主题"
  1852. cellE := rowTitle.AddCell()
  1853. cellE.Value = "活动时间"
  1854. cellF := rowTitle.AddCell()
  1855. cellF.Value = "是否到会"
  1856. cellG := rowTitle.AddCell()
  1857. cellG.Value = "首次入会时间"
  1858. cellH := rowTitle.AddCell()
  1859. cellH.Value = "最后退出时间"
  1860. cellI := rowTitle.AddCell()
  1861. cellI.Value = "参与总时长"
  1862. cellJ := rowTitle.AddCell()
  1863. cellJ.Value = "参会方式"
  1864. cellK := rowTitle.AddCell()
  1865. cellK.Value = "参会权鉴"
  1866. cellL := rowTitle.AddCell()
  1867. cellL.Value = "参会状态"
  1868. for _, item := range list {
  1869. row := sheet.AddRow()
  1870. cellA := row.AddCell()
  1871. cellA.Value = item.ActivityName
  1872. cellB := row.AddCell()
  1873. cellB.Value = item.PermissionName
  1874. cellC := row.AddCell()
  1875. cellC.Value = item.ActivityTypeName
  1876. cellD := row.AddCell()
  1877. cellD.Value = item.Label
  1878. cellE := row.AddCell()
  1879. cellE.Value = item.ActivityTime
  1880. cellF := row.AddCell()
  1881. if item.IsMeeting == 1 {
  1882. cellF.Value = "到会"
  1883. cellG := row.AddCell()
  1884. cellG.Value = item.FirstMeetingTime
  1885. cellH := row.AddCell()
  1886. cellH.Value = item.LastMeetingTime
  1887. cellI := row.AddCell()
  1888. cellI.Value = item.Duration
  1889. cellJ := row.AddCell()
  1890. cellJ.Value = item.LastMeetingTime
  1891. cellK := row.AddCell()
  1892. cellK.Value = item.MeetingTypeStr
  1893. cellL := row.AddCell()
  1894. cellL.Value = item.MeetingStatusStr
  1895. } else {
  1896. cellF.Value = "未到会"
  1897. }
  1898. }
  1899. } else if source == 11 {
  1900. //标头
  1901. rowTitle := sheet.AddRow()
  1902. cellA := rowTitle.AddCell()
  1903. cellA.Value = "文章标题"
  1904. cellB := rowTitle.AddCell()
  1905. cellB.Value = "文章类型"
  1906. cellC := rowTitle.AddCell()
  1907. cellC.Value = "标签"
  1908. cellD := rowTitle.AddCell()
  1909. cellD.Value = "发布时间"
  1910. cellE := rowTitle.AddCell()
  1911. cellE.Value = "阅读时间"
  1912. cellF := rowTitle.AddCell()
  1913. cellF.Value = "阅读时长"
  1914. cellG := rowTitle.AddCell()
  1915. cellG.Value = "阅读来源"
  1916. for _, item := range list {
  1917. row := sheet.AddRow()
  1918. cellA := row.AddCell()
  1919. cellA.Value = item.Title
  1920. cellB := row.AddCell()
  1921. if item.SpecialType == 1 {
  1922. cellB.Value = "笔记"
  1923. } else {
  1924. cellB.Value = "观点"
  1925. }
  1926. cellC := row.AddCell()
  1927. cellC.Value = item.IndustryName
  1928. cellD := row.AddCell()
  1929. cellD.Value = item.PublishDate
  1930. cellE := row.AddCell()
  1931. cellE.Value = item.CreateTime
  1932. cellF := row.AddCell()
  1933. cellF.Value = item.StopTime
  1934. cellG := row.AddCell()
  1935. cellG.Value = cygxService.GetArticleSourcePlatformText(item.RegisterPlatform)
  1936. }
  1937. } else if source == 11 {
  1938. //标头
  1939. rowTitle := sheet.AddRow()
  1940. cellA := rowTitle.AddCell()
  1941. cellA.Value = "文章标题"
  1942. cellB := rowTitle.AddCell()
  1943. cellB.Value = "文章类型"
  1944. cellC := rowTitle.AddCell()
  1945. cellC.Value = "标签"
  1946. cellD := rowTitle.AddCell()
  1947. cellD.Value = "发布时间"
  1948. cellE := rowTitle.AddCell()
  1949. cellE.Value = "阅读时间"
  1950. cellF := rowTitle.AddCell()
  1951. cellF.Value = "阅读时长"
  1952. cellG := rowTitle.AddCell()
  1953. cellG.Value = "阅读来源"
  1954. for _, item := range list {
  1955. row := sheet.AddRow()
  1956. cellA := row.AddCell()
  1957. cellA.Value = item.Title
  1958. cellB := row.AddCell()
  1959. if item.SpecialType == 1 {
  1960. cellB.Value = "笔记"
  1961. } else {
  1962. cellB.Value = "观点"
  1963. }
  1964. cellC := row.AddCell()
  1965. cellC.Value = item.IndustryName
  1966. cellD := row.AddCell()
  1967. cellD.Value = item.PublishDate
  1968. cellE := row.AddCell()
  1969. cellE.Value = item.CreateTime
  1970. cellF := row.AddCell()
  1971. cellF.Value = item.StopTime
  1972. cellG := row.AddCell()
  1973. cellG.Value = cygxService.GetArticleSourcePlatformText(item.RegisterPlatform)
  1974. }
  1975. }
  1976. err = xlsxFile.Save(downLoadnFilePath)
  1977. if err != nil {
  1978. br.Msg = "保存文件失败"
  1979. br.ErrMsg = "保存文件失败"
  1980. return
  1981. }
  1982. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  1983. downloadFileName := wxUser.RealName + randStr + ".xlsx"
  1984. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  1985. defer func() {
  1986. os.Remove(downLoadnFilePath)
  1987. }()
  1988. br.Ret = 200
  1989. br.Success = true
  1990. br.Msg = "获取成功"
  1991. }
  1992. // @Title 机构互动详情table栏
  1993. // @Description 互动详情table栏接口
  1994. // @Param CompanyId query int true "公司ID"
  1995. // @Param ClassType query int true "列表类型,1:权益,2:研选,默认1"
  1996. // @Success 200 {object} cygx.UserRemarksListResp
  1997. // @router /user/company/table/list [get]
  1998. func (this *UserController) CompanyTableList() {
  1999. br := new(models.BaseResponse).Init()
  2000. defer func() {
  2001. this.Data["json"] = br
  2002. this.ServeJSON()
  2003. }()
  2004. sysUser := this.SysUser
  2005. if sysUser == nil {
  2006. br.Msg = "请登录"
  2007. br.ErrMsg = "请登录,SysUser Is Empty"
  2008. br.Ret = 408
  2009. return
  2010. }
  2011. companyId, _ := this.GetInt("CompanyId")
  2012. classType, _ := this.GetInt("ClassType", 1)
  2013. if companyId < 1 {
  2014. br.Msg = "机构不存在"
  2015. return
  2016. }
  2017. comanyDetail, err := company.GetCompanyDetailById(companyId)
  2018. if err != nil {
  2019. br.Msg = "获取信息失败"
  2020. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  2021. return
  2022. }
  2023. resp := new(cygx.CygxUserTableListRep)
  2024. var isAdminRole bool
  2025. //如果不是管理员身份或者研究员身份则需要添加可见范围处理
  2026. if sysUser.Role == utils.ROLE_TYPE_CODE_ADMIN || sysUser.Role == utils.ROLE_TYPE_CODE_RESEARCHR {
  2027. isAdminRole = true
  2028. }
  2029. var pars []interface{}
  2030. condition := ` AND r.company_id IN ( ` + strconv.Itoa(companyId) + ` ) AND r.create_time < '` + time.Now().Format(utils.FormatDate) + `' ` //过滤当天时间
  2031. //totalEs, _, err := services.SearcCygxArticleHistoryData(utils.IndexNameArticleHistory, "", "", "", strconv.Itoa(companyId), 0, 0)
  2032. //if err != nil {
  2033. // br.Msg = "获取信息失败"
  2034. // br.ErrMsg = "获取Es文章阅读数量失败,Err:" + err.Error()
  2035. // return
  2036. //}
  2037. conditionArtcile := condition //文章搜索条件
  2038. conditionActivityMeet := condition //活动到会搜索条件
  2039. conditionIndustryFllow := condition //产业关注搜索条件
  2040. conditionKeyWord := condition //关键词记录搜索条件
  2041. if classType == 1 {
  2042. conditionArtcile += " AND art.article_type_id = 0 "
  2043. conditionActivityMeet += " AND a.chart_permission_id != 31 "
  2044. conditionIndustryFllow += " AND m.chart_permission_id != 31 "
  2045. conditionKeyWord += " AND r.register_platform IN (1,2) "
  2046. } else {
  2047. conditionArtcile += " AND art.article_type_id > 0 "
  2048. conditionActivityMeet += " AND a.chart_permission_id = 31 "
  2049. conditionIndustryFllow += " AND m.chart_permission_id = 31 "
  2050. conditionKeyWord += " AND r.register_platform IN (5,6) "
  2051. }
  2052. var historyNum int //报告阅读列表
  2053. var activityNum int //活动互动记录
  2054. var triptotal int //专项调研
  2055. var articleCollect int //收藏的报告
  2056. var chartNum int //收藏图表
  2057. var industryFllowNum int //关注的产业
  2058. var departmentFollowNum int //关注的作者
  2059. var keyWordNum int //搜索
  2060. var roadshowTotal int //音视频播放
  2061. var tagNum int //首页标签点击
  2062. var yanxuanSpecialNum int //专栏文章阅读记录
  2063. var yanxuanSpecialCollectNum int //收藏的专栏文章
  2064. var yanxuanSpecialFollowNum int //关注的专栏作者
  2065. var feedbackNum int //交流反馈数量
  2066. var calendarMeetingNum int //1v1 路演数量
  2067. if isAdminRole {
  2068. historyNum, err = cygx.GetCygxArticleAndYanxuanRecordCount(conditionArtcile, pars)
  2069. if err != nil {
  2070. br.Msg = "获取信息失败"
  2071. br.ErrMsg = "获取用户阅读记录数量失败,Err:" + err.Error()
  2072. return
  2073. }
  2074. activityNum, err = cygx.GetActivityMeetByCompanyCount(conditionActivityMeet)
  2075. if err != nil {
  2076. br.Msg = "获取信息失败"
  2077. br.ErrMsg = "获取参会总数失败,Err:" + err.Error()
  2078. return
  2079. }
  2080. //获取用户收藏记录总数
  2081. articleCollect, err = cygx.GetCygxArticleCollectCountByCompany(conditionArtcile)
  2082. if err != nil {
  2083. br.Msg = "获取信息失败"
  2084. br.ErrMsg = "获取用户收藏记录总数失败,Err:" + err.Error()
  2085. return
  2086. }
  2087. //获取用户关注总数
  2088. industryFllowNum, err = cygx.GetCygxIndustryFllowCountByCompany(conditionIndustryFllow)
  2089. if err != nil {
  2090. br.Msg = "获取信息失败 "
  2091. br.ErrMsg = "获取用户关注总数失败,Err:" + err.Error()
  2092. return
  2093. }
  2094. //获取关注作者总数
  2095. departmentFollowNum, err = cygx.GetCygArticleDepartmentFollowCountByCompany(condition)
  2096. if err != nil {
  2097. br.Msg = "获取信息失败"
  2098. br.ErrMsg = "获取关注作者总数失败,Err:" + err.Error()
  2099. return
  2100. }
  2101. //获取搜索记录
  2102. keyWordNum, err = cygx.GetCygxSearchKeyWordCountBuCompany(conditionKeyWord)
  2103. if err != nil {
  2104. br.Msg = "获取信息失败"
  2105. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  2106. return
  2107. }
  2108. chartNum, err = cygx.GetChartCountByUserMobile(condition)
  2109. if err != nil {
  2110. br.Msg = "获取信息失败"
  2111. br.ErrMsg = "获取总数失败,Err:" + err.Error()
  2112. return
  2113. }
  2114. triptotal, err = cygx.GetCygxActivitySpecialTripCountByCompany(condition)
  2115. if err != nil {
  2116. br.Msg = "获取信息失败"
  2117. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  2118. return
  2119. }
  2120. roadshowTotal, err = cygx.GetCygxRoadshowCountByCompany(condition)
  2121. if err != nil {
  2122. br.Msg = "获取信息失败"
  2123. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  2124. return
  2125. }
  2126. tagNum, err = cygx.GetCygxTagHistoryCount(condition)
  2127. if err != nil {
  2128. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2129. br.Msg = "获取搜索记录失败"
  2130. return
  2131. }
  2132. yanxuanSpecialNum, err = cygx.GetCygxYanxuanSpecialRecordCount(condition, pars)
  2133. if err != nil {
  2134. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2135. br.Msg = "获取研选专栏阅读数量失败"
  2136. return
  2137. }
  2138. yanxuanSpecialCollectNum, err = cygx.GetCygxYanxuanSpecialCollectCount(condition, pars)
  2139. if err != nil {
  2140. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2141. br.Msg = "获取收藏的专栏文章数量失败"
  2142. return
  2143. }
  2144. yanxuanSpecialFollowNum, err = cygx.GetCygxYanxuanSpecialFollowCount(condition, pars)
  2145. if err != nil {
  2146. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2147. br.Msg = "获取关注的专栏作者数量失败"
  2148. return
  2149. }
  2150. feedbackNum, err = cygx.GetCygxUserFeedbackCountByUserModel(condition, pars)
  2151. if err != nil {
  2152. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2153. br.Msg = "获取交流反馈数量失败"
  2154. return
  2155. }
  2156. calendarMeetingNum, err = roadshow.GetRsCalendarMeetingUserCountByUserModel(condition, pars)
  2157. if err != nil {
  2158. br.Msg = "获取信息失败"
  2159. br.ErrMsg = "GetRsCalendarMeetingUserCountByUserModel,Err:" + err.Error()
  2160. return
  2161. }
  2162. } else {
  2163. historyNum, err = cygx.GetCygxArticleAndYanxuanRecordCountWeekly(conditionArtcile, pars)
  2164. if err != nil {
  2165. br.Msg = "获取信息失败"
  2166. br.ErrMsg = "获取用户阅读记录数量失败,Err:" + err.Error()
  2167. return
  2168. }
  2169. activityNum, err = cygx.GetActivityMeetByCompanyCountWeekly(conditionActivityMeet)
  2170. if err != nil {
  2171. br.Msg = "获取信息失败"
  2172. br.ErrMsg = "获取参会总数失败,Err:" + err.Error()
  2173. return
  2174. }
  2175. //获取用户收藏记录总数
  2176. articleCollect, err = cygx.GetCygxArticleCollectCountByCompanyWeekly(conditionArtcile)
  2177. if err != nil {
  2178. br.Msg = "获取信息失败"
  2179. br.ErrMsg = "获取用户收藏记录总数失败,Err:" + err.Error()
  2180. return
  2181. }
  2182. //获取用户关注总数
  2183. industryFllowNum, err = cygx.GetCygxIndustryFllowCountByCompanyWeekly(condition)
  2184. if err != nil {
  2185. br.Msg = "获取信息失败 "
  2186. br.ErrMsg = "获取用户关注总数失败,Err:" + err.Error()
  2187. return
  2188. }
  2189. //获取关注作者总数
  2190. departmentFollowNum, err = cygx.GetCygArticleDepartmentFollowCountByCompanyWeekly(condition)
  2191. if err != nil {
  2192. br.Msg = "获取信息失败"
  2193. br.ErrMsg = "获取关注作者总数失败,Err:" + err.Error()
  2194. return
  2195. }
  2196. //获取搜索记录
  2197. keyWordNum, err = cygx.GetCygxSearchKeyWordCountBuCompanyWeekly(conditionKeyWord)
  2198. if err != nil {
  2199. br.Msg = "获取信息失败"
  2200. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  2201. return
  2202. }
  2203. chartNum, err = cygx.GetChartCountByUserMobileWeekly(condition)
  2204. if err != nil {
  2205. br.Msg = "获取信息失败"
  2206. br.ErrMsg = "获取总数失败,Err:" + err.Error()
  2207. return
  2208. }
  2209. triptotal, err = cygx.GetCygxActivitySpecialTripCountByCompanyWeekly(condition)
  2210. if err != nil {
  2211. br.Msg = "获取信息失败"
  2212. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  2213. return
  2214. }
  2215. roadshowTotal, err = cygx.GetCygxRoadshowCountByCompanyWeekly(condition)
  2216. if err != nil {
  2217. br.Msg = "获取信息失败"
  2218. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  2219. return
  2220. }
  2221. tagNum, err = cygx.GetCygxTagHistoryCountWeekly(condition)
  2222. if err != nil {
  2223. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2224. br.Msg = "获取搜索记录失败"
  2225. return
  2226. }
  2227. yanxuanSpecialNum, err = cygx.GetCygxYanxuanSpecialRecordCountWeekly(condition, pars)
  2228. if err != nil {
  2229. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2230. br.Msg = "获取研选专栏阅读数量失败"
  2231. return
  2232. }
  2233. yanxuanSpecialCollectNum, err = cygx.GetCygxYanxuanSpecialCollectCountWeekly(condition, pars)
  2234. if err != nil {
  2235. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2236. br.Msg = "获取收藏的专栏文章数量失败"
  2237. return
  2238. }
  2239. yanxuanSpecialFollowNum, err = cygx.GetCygxYanxuanSpecialFollowCountWeekly(condition, pars)
  2240. if err != nil {
  2241. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2242. br.Msg = "获取关注的专栏作者数量失败"
  2243. return
  2244. }
  2245. feedbackNum, err = cygx.GetCygxUserFeedbackCountByUserModelWeekly(condition, pars)
  2246. if err != nil {
  2247. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2248. br.Msg = "获取交流反馈数量失败"
  2249. return
  2250. }
  2251. calendarMeetingNum, err = roadshow.GetRsCalendarMeetingUserCountByUserModelWeekly(condition, pars)
  2252. if err != nil {
  2253. br.Msg = "获取信息失败"
  2254. br.ErrMsg = "GetRsCalendarMeetingUserCountByUserModelWeekly,Err:" + err.Error()
  2255. return
  2256. }
  2257. }
  2258. if classType == 1 {
  2259. List := []*cygx.CygxUserTableRep{{PermissionName: "报告阅读列表", Source: 1, TotalNum: historyNum},
  2260. {PermissionName: "活动互动记录", Source: 2, TotalNum: activityNum},
  2261. {PermissionName: "专项调研", Source: 8, TotalNum: triptotal},
  2262. {PermissionName: "1v1路演", Source: 15, TotalNum: calendarMeetingNum},
  2263. {PermissionName: "收藏的报告", Source: 3, TotalNum: articleCollect},
  2264. {PermissionName: "收藏图表", Source: 4, TotalNum: chartNum},
  2265. {PermissionName: "关注的产业", Source: 5, TotalNum: industryFllowNum},
  2266. {PermissionName: "搜索", Source: 7, TotalNum: keyWordNum},
  2267. {PermissionName: "音视频播放", Source: 9, TotalNum: roadshowTotal},
  2268. {PermissionName: "首页标签点击", Source: 10, TotalNum: tagNum},
  2269. {PermissionName: "交流反馈", Source: 14, TotalNum: feedbackNum}}
  2270. resp.List = List
  2271. } else {
  2272. List := []*cygx.CygxUserTableRep{{PermissionName: "报告阅读列表", Source: 1, TotalNum: historyNum},
  2273. {PermissionName: "活动互动记录", Source: 2, TotalNum: activityNum},
  2274. {PermissionName: "收藏的报告", Source: 3, TotalNum: articleCollect},
  2275. {PermissionName: "关注的产业", Source: 5, TotalNum: industryFllowNum},
  2276. {PermissionName: "关注的作者", Source: 6, TotalNum: departmentFollowNum},
  2277. {PermissionName: "专栏文章阅读记录", Source: 11, TotalNum: yanxuanSpecialNum},
  2278. {PermissionName: "收藏的专栏文章", Source: 12, TotalNum: yanxuanSpecialCollectNum},
  2279. {PermissionName: "关注的专栏作者", Source: 13, TotalNum: yanxuanSpecialFollowNum},
  2280. {PermissionName: "搜索", Source: 7, TotalNum: keyWordNum}}
  2281. resp.List = List
  2282. }
  2283. resp.ComapnyName = comanyDetail.CompanyName
  2284. br.Ret = 200
  2285. br.Success = true
  2286. br.Msg = "获取成功"
  2287. br.Data = resp
  2288. }
  2289. // @Title 机构互动详情
  2290. // @Description 机构互动详情接口
  2291. // @Param CompanyId query int true "公司ID"
  2292. // @Param Source query int true "来源"
  2293. // @Param IsMeeting query string false "是否到会 1到会、2未到会"
  2294. // @Param MeetType query string false "参会方式 1线上,2线下 默认为线上"
  2295. // @Param PageSize query int true "每页数据条数"
  2296. // @Param CurrentIndex query int true "当前页页码,从1开始"
  2297. // @Param StartDate query string false "开始时间"
  2298. // @Param EndDate query string false "结束时间"
  2299. // @Param KeyWord query string false "搜索关键词"
  2300. // @Param ActivityName query string false "活动名称"
  2301. // @Param ClassType query int true "列表类型,1:权益,2:研选,默认1"
  2302. // @Param IsExport query bool false "是否导出excel,默认是false"
  2303. // @Success 200 {object} cygx.UserInteractionListResp
  2304. // @router /user/company/interaction/detail [get]
  2305. func (this *UserController) CompanyTableDetail() {
  2306. br := new(models.BaseResponse).Init()
  2307. defer func() {
  2308. this.Data["json"] = br
  2309. this.ServeJSON()
  2310. }()
  2311. sysUser := this.SysUser
  2312. if sysUser == nil {
  2313. br.Msg = "请登录"
  2314. br.ErrMsg = "请登录,SysUser Is Empty"
  2315. br.Ret = 408
  2316. return
  2317. }
  2318. pageSize, _ := this.GetInt("PageSize")
  2319. currentIndex, _ := this.GetInt("CurrentIndex")
  2320. var startSize int
  2321. if pageSize <= 0 {
  2322. pageSize = utils.PageSize20
  2323. }
  2324. if currentIndex <= 0 {
  2325. currentIndex = 1
  2326. }
  2327. startSize = paging.StartIndex(currentIndex, pageSize)
  2328. companyId, _ := this.GetInt("CompanyId")
  2329. isMeeting := this.GetString("IsMeeting")
  2330. meetType := this.GetString("MeetType")
  2331. startDate := this.GetString("StartDate")
  2332. endDate := this.GetString("EndDate")
  2333. keyWord := this.GetString("KeyWord")
  2334. activityName := this.GetString("ActivityName")
  2335. source, _ := this.GetInt("Source")
  2336. classType, _ := this.GetInt("ClassType", 1)
  2337. if companyId < 1 {
  2338. br.Msg = "用户不存在"
  2339. return
  2340. }
  2341. isExport, _ := this.GetBool("IsExport")
  2342. if isExport {
  2343. pageSize = 10000
  2344. currentIndex = 1
  2345. }
  2346. // 1.标记用户表
  2347. //操作权限校验
  2348. resp := new(cygx.UserInteractionListResp)
  2349. var err error
  2350. var list []*cygx.UserInteraction
  2351. var total int
  2352. var condition string
  2353. var pars []interface{}
  2354. condition += ` AND r.company_id = ` + strconv.Itoa(companyId) + ` AND r.create_time < '` + time.Now().Format(utils.FormatDate) + `' `
  2355. if keyWord != "" {
  2356. condition += ` AND ( r.mobile LIKE '%` + keyWord + `%' OR r.email LIKE '%` + keyWord + `%' OR r.real_name LIKE '%` + keyWord + `%')`
  2357. }
  2358. var isAdminRole bool
  2359. //如果不是管理员身份或者研究员身份则需要添加可见范围处理
  2360. if sysUser.Role == utils.ROLE_TYPE_CODE_ADMIN || sysUser.Role == utils.ROLE_TYPE_CODE_RESEARCHR {
  2361. isAdminRole = true
  2362. }
  2363. if source == 1 {
  2364. if startDate != "" {
  2365. startDate += " 00:00:00"
  2366. condition += ` AND r.create_time >= '` + startDate + `' `
  2367. }
  2368. if endDate != "" {
  2369. endDate += " 23:59:59"
  2370. condition += ` AND r.create_time <= '` + endDate + `' `
  2371. }
  2372. condition += " AND r.source = 'article' "
  2373. if classType == 1 {
  2374. condition += " AND art.article_type_id = 0 "
  2375. } else {
  2376. condition += " AND art.article_type_id > 0 "
  2377. }
  2378. condition += " ORDER BY r.create_time DESC "
  2379. var listRecord []*cygx.CygxArticleAndYanxuanRecordResp
  2380. if isAdminRole {
  2381. total, err = cygx.GetCygxArticleAndYanxuanRecordCount(condition, pars)
  2382. if err != nil {
  2383. br.Msg = "获取信息失败"
  2384. br.ErrMsg = "获取用户阅读记录数量失败,Err:" + err.Error()
  2385. return
  2386. }
  2387. listRecord, err = cygx.GetCygxArticleAndYanxuanRecordRespList(condition, pars, startSize, pageSize)
  2388. if err != nil && err.Error() != utils.ErrNoRow() {
  2389. br.Msg = "获取信息失败"
  2390. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  2391. return
  2392. }
  2393. } else {
  2394. total, err = cygx.GetCygxArticleAndYanxuanRecordCountWeekly(condition, pars)
  2395. if err != nil {
  2396. br.Msg = "获取信息失败"
  2397. br.ErrMsg = "获取用户阅读记录数量失败,Err:" + err.Error()
  2398. return
  2399. }
  2400. listRecord, err = cygx.GetCygxArticleAndYanxuanRecordRespListWeekly(condition, pars, startSize, pageSize)
  2401. if err != nil && err.Error() != utils.ErrNoRow() {
  2402. br.Msg = "获取信息失败"
  2403. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  2404. return
  2405. }
  2406. }
  2407. //处理查询信息回显
  2408. list, err = cygxService.HandleArticleAndYanxuanRecordList(listRecord)
  2409. if err != nil && err.Error() != utils.ErrNoRow() {
  2410. br.Msg = "获取信息失败"
  2411. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  2412. return
  2413. }
  2414. for k, v := range list {
  2415. if classType == 1 {
  2416. list[k].HttpUrl = utils.CYGX_WEB_URL + "/material/info/" + strconv.Itoa(v.ArticleId)
  2417. } else {
  2418. list[k].HttpUrl = utils.CYGX_MFYX_URL + "/material/info/" + strconv.Itoa(v.ArticleId)
  2419. }
  2420. }
  2421. //导出excel
  2422. if isExport {
  2423. exportListArticle(this, list, 2, br)
  2424. return
  2425. }
  2426. } else if source == 2 {
  2427. if isMeeting == "1" {
  2428. condition += ` AND r.is_meeting = 1 `
  2429. }
  2430. if isMeeting == "2" {
  2431. condition += ` AND r.is_meeting = 0 `
  2432. }
  2433. if meetType == "1" {
  2434. condition += ` AND t.activity_type = 1 `
  2435. }
  2436. if meetType == "2" {
  2437. condition += ` AND t.activity_type = 0 `
  2438. }
  2439. if startDate != "" {
  2440. startDate += " 00:00:00"
  2441. condition += ` AND a.activity_time >= '` + startDate + `' `
  2442. }
  2443. if endDate != "" {
  2444. endDate += " 23:59:59"
  2445. condition += ` AND a.activity_time <= '` + endDate + `' `
  2446. }
  2447. if activityName != "" {
  2448. condition += ` AND a.activity_name LIKE '%` + activityName + `%' `
  2449. }
  2450. if classType == 1 {
  2451. condition += " AND a.chart_permission_id != 31 "
  2452. } else {
  2453. condition += " AND a.chart_permission_id = 31 "
  2454. }
  2455. if isAdminRole {
  2456. total, err = cygx.GetActivityMeetByCompanyCount(condition)
  2457. if err != nil {
  2458. br.Msg = "获取信息失败"
  2459. br.ErrMsg = "获取参会总数失败,Err:" + err.Error()
  2460. return
  2461. }
  2462. list, err = cygx.GetActivityMeetByCompany(condition, startSize, pageSize)
  2463. if err != nil && err.Error() != utils.ErrNoRow() {
  2464. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2465. br.Msg = "获取参会人数列表失败"
  2466. return
  2467. }
  2468. } else {
  2469. total, err = cygx.GetActivityMeetByCompanyCountWeekly(condition)
  2470. if err != nil {
  2471. br.Msg = "获取信息失败"
  2472. br.ErrMsg = "获取参会总数失败,Err:" + err.Error()
  2473. return
  2474. }
  2475. list, err = cygx.GetActivityMeetByCompanyWeekly(condition, startSize, pageSize)
  2476. if err != nil && err.Error() != utils.ErrNoRow() {
  2477. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2478. br.Msg = "获取参会人数列表失败"
  2479. return
  2480. }
  2481. }
  2482. if len(list) > 0 {
  2483. for k, v := range list {
  2484. if v.ActivityType == 1 {
  2485. if v.SignupType == "2" {
  2486. list[k].InteractionType = "自主拨入"
  2487. } else {
  2488. list[k].InteractionType = "预约外呼"
  2489. }
  2490. if v.ReminderNum > 0 {
  2491. list[k].InteractionType += ",会议提醒"
  2492. }
  2493. }
  2494. if v.IsMeeting == 0 || v.FirstMeetingTime == "0000-00-00 00:00:00" {
  2495. list[k].FirstMeetingTime = ""
  2496. list[k].LastMeetingTime = ""
  2497. }
  2498. if v.FirstMeetingTime == "0000-00-00 00:00:00" {
  2499. list[k].FirstMeetingTime = ""
  2500. list[k].LastMeetingTime = ""
  2501. }
  2502. }
  2503. }
  2504. //导出excel
  2505. if isExport {
  2506. exportListActivity(this, list, 2, br)
  2507. return
  2508. }
  2509. } else if source == 3 {
  2510. if classType == 1 {
  2511. condition += " AND art.article_type_id = 0 "
  2512. } else {
  2513. condition += " AND art.article_type_id > 0 "
  2514. }
  2515. if isAdminRole {
  2516. total, err = cygx.GetCygxArticleCollectCountByCompany(condition)
  2517. if err != nil {
  2518. br.Msg = "获取信息失败"
  2519. br.ErrMsg = "获取用户收藏记录总数失败,Err:" + err.Error()
  2520. return
  2521. }
  2522. list, err = cygx.GetCygxArticleCollectByCompany(startSize, pageSize, condition)
  2523. if err != nil && err.Error() != utils.ErrNoRow() {
  2524. br.Msg = "获取信息失败"
  2525. br.ErrMsg = "获取用户搜藏记录失败,Err:" + err.Error()
  2526. return
  2527. }
  2528. } else {
  2529. total, err = cygx.GetCygxArticleCollectCountByCompanyWeekly(condition)
  2530. if err != nil {
  2531. br.Msg = "获取信息失败"
  2532. br.ErrMsg = "获取用户收藏记录总数失败,Err:" + err.Error()
  2533. return
  2534. }
  2535. list, err = cygx.GetCygxArticleCollectByCompanyWeekly(startSize, pageSize, condition)
  2536. if err != nil && err.Error() != utils.ErrNoRow() {
  2537. br.Msg = "获取信息失败"
  2538. br.ErrMsg = "获取用户搜藏记录失败,Err:" + err.Error()
  2539. return
  2540. }
  2541. }
  2542. if len(list) > 0 {
  2543. for k, v := range list {
  2544. if v.ArticleId >= utils.SummaryArticleId {
  2545. list[k].ArticleType = 1
  2546. } else {
  2547. list[k].ArticleType = 2
  2548. }
  2549. if classType == 1 {
  2550. list[k].HttpUrl = utils.CYGX_WEB_URL + "/material/info/" + strconv.Itoa(v.ArticleId)
  2551. } else {
  2552. list[k].HttpUrl = utils.CYGX_MFYX_URL + "/material/info/" + strconv.Itoa(v.ArticleId)
  2553. }
  2554. }
  2555. }
  2556. } else if source == 4 {
  2557. if isAdminRole {
  2558. list, err = cygx.GetChartCollectList(condition)
  2559. if err != nil {
  2560. br.Msg = "获取信息失败"
  2561. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2562. return
  2563. }
  2564. } else {
  2565. list, err = cygx.GetChartCollectListWeekly(condition)
  2566. if err != nil {
  2567. br.Msg = "获取信息失败"
  2568. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2569. return
  2570. }
  2571. }
  2572. if len(list) > 0 {
  2573. for k, v := range list {
  2574. var err error
  2575. condition = ` AND a.publish_status = 1 AND r.company_id = ` + strconv.Itoa(companyId) + ` AND r.mobile = ` + v.Mobile + ` AND r.create_time < '` + time.Now().Format(utils.FormatDate) + `' ` //过滤当天时间
  2576. total, err = cygx.GetChartCountByUserMobile(condition)
  2577. if err != nil {
  2578. br.Msg = "获取信息失败"
  2579. br.ErrMsg = "获取总数失败,Err:" + err.Error()
  2580. return
  2581. }
  2582. listChart, err := cygx.GetChartListCollectionWithCygxByMobile(condition, 0, 18)
  2583. if err != nil {
  2584. br.Msg = "获取信息失败"
  2585. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2586. return
  2587. }
  2588. for k, vChart := range listChart {
  2589. if vChart.PtagName != "" {
  2590. listChart[k].CtagNamePc = vChart.PtagName
  2591. }
  2592. if vChart.CtagName != "" {
  2593. listChart[k].CtagNamePc += "," + vChart.CtagName
  2594. }
  2595. if vChart.PtagNameTwo != "" {
  2596. listChart[k].CtagNamePc += "," + vChart.PtagNameTwo
  2597. }
  2598. if vChart.CtagNameTwo != "" {
  2599. listChart[k].CtagNamePc += "," + vChart.CtagNameTwo
  2600. }
  2601. }
  2602. pageChart := paging.GetPaging(currentIndex, 18, total)
  2603. list[k].ListChart = listChart
  2604. list[k].Paging = pageChart
  2605. list[k].IsEnd = pageChart.IsEnd
  2606. list[k].CurrentIndex = pageChart.CurrentIndex
  2607. }
  2608. }
  2609. } else if source == 5 {
  2610. if classType == 1 {
  2611. condition += " AND m.chart_permission_id != 31 "
  2612. } else {
  2613. condition += " AND m.chart_permission_id = 31 "
  2614. }
  2615. if isAdminRole {
  2616. total, err = cygx.GetCygxIndustryFllowCountByCompany(condition)
  2617. if err != nil {
  2618. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2619. br.Msg = "获取用户关注总数失败"
  2620. return
  2621. }
  2622. list, err = cygx.GetCygxIndustryFllowByCompany(condition, startSize, pageSize)
  2623. if err != nil && err.Error() != utils.ErrNoRow() {
  2624. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2625. br.Msg = "获取用户关注总数失败"
  2626. return
  2627. }
  2628. } else {
  2629. total, err = cygx.GetCygxIndustryFllowCountByCompanyWeekly(condition)
  2630. if err != nil {
  2631. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2632. br.Msg = "获取用户关注总数失败"
  2633. return
  2634. }
  2635. if err != nil {
  2636. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2637. br.Msg = "获取用户关注总数失败"
  2638. return
  2639. }
  2640. list, err = cygx.GetCygxIndustryFllowByCompanyWeekly(condition, startSize, pageSize)
  2641. if err != nil && err.Error() != utils.ErrNoRow() {
  2642. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2643. br.Msg = "获取用户关注总数失败"
  2644. return
  2645. }
  2646. }
  2647. } else if source == 6 {
  2648. if isAdminRole {
  2649. total, err = cygx.GetCygArticleDepartmentFollowCountByCompany(condition)
  2650. if err != nil {
  2651. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2652. br.Msg = "获取关注作者总数失败"
  2653. return
  2654. }
  2655. list, err = cygx.GetCygArticleDepartmentFollowByCompany(condition, startSize, pageSize)
  2656. if err != nil && err.Error() != utils.ErrNoRow() {
  2657. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2658. br.Msg = "获取关注作者列表失败"
  2659. return
  2660. }
  2661. } else {
  2662. total, err = cygx.GetCygArticleDepartmentFollowCountByCompanyWeekly(condition)
  2663. if err != nil {
  2664. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2665. br.Msg = "获取关注作者总数失败"
  2666. return
  2667. }
  2668. list, err = cygx.GetCygArticleDepartmentFollowByCompanyWeekly(condition, startSize, pageSize)
  2669. if err != nil && err.Error() != utils.ErrNoRow() {
  2670. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2671. br.Msg = "获取关注作者列表失败"
  2672. return
  2673. }
  2674. }
  2675. if len(list) > 0 {
  2676. var departmentIds []int
  2677. for _, v := range list {
  2678. departmentIds = append(departmentIds, v.DepartmentId)
  2679. }
  2680. mapIndustrialLabel := cygxService.GetArticleIndustrialLabelByDepartmentId(departmentIds) // 关联产业
  2681. for _, v := range list {
  2682. v.SubjectNameStr = strings.Join(mapIndustrialLabel[v.DepartmentId], "/")
  2683. }
  2684. }
  2685. } else if source == 7 {
  2686. if classType == 1 {
  2687. condition += " AND r.register_platform IN (1,2) "
  2688. } else {
  2689. condition += " AND r.register_platform IN (5,6) "
  2690. }
  2691. if isAdminRole {
  2692. total, err = cygx.GetCygxSearchKeyWordCountBuCompany(condition)
  2693. if err != nil {
  2694. br.Msg = "获取信息失败"
  2695. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  2696. return
  2697. }
  2698. list, err = cygx.GetCygxSearchKeyWordByCompany(condition, startSize, pageSize)
  2699. if err != nil && err.Error() != utils.ErrNoRow() {
  2700. br.Msg = "获取信息失败"
  2701. br.ErrMsg = "获取搜索记录列表失败,Err:" + err.Error()
  2702. return
  2703. }
  2704. } else {
  2705. total, err = cygx.GetCygxSearchKeyWordCountBuCompanyWeekly(condition)
  2706. if err != nil {
  2707. br.Msg = "获取信息失败"
  2708. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  2709. return
  2710. }
  2711. list, err = cygx.GetCygxSearchKeyWordByCompanyWeekly(condition, startSize, pageSize)
  2712. if err != nil && err.Error() != utils.ErrNoRow() {
  2713. br.Msg = "获取信息失败"
  2714. br.ErrMsg = "获取搜索记录列表失败,Err:" + err.Error()
  2715. return
  2716. }
  2717. }
  2718. } else if source == 8 {
  2719. if isAdminRole {
  2720. total, err = cygx.GetCygxActivitySpecialTripCountByCompany(condition)
  2721. if err != nil {
  2722. br.Msg = "获取信息失败"
  2723. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  2724. return
  2725. }
  2726. list, err = cygx.CygxActivitySpecialTripByCompany(condition, startSize, pageSize)
  2727. if err != nil && err.Error() != utils.ErrNoRow() {
  2728. br.Msg = "获取信息失败"
  2729. br.ErrMsg = "获取搜索记录列表失败,Err:" + err.Error()
  2730. return
  2731. }
  2732. } else {
  2733. total, err = cygx.GetCygxActivitySpecialTripCountByCompanyWeekly(condition)
  2734. if err != nil {
  2735. br.Msg = "获取信息失败"
  2736. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  2737. return
  2738. }
  2739. list, err = cygx.CygxActivitySpecialTripByCompanyWeekly(condition, startSize, pageSize)
  2740. if err != nil && err.Error() != utils.ErrNoRow() {
  2741. br.Msg = "获取信息失败"
  2742. br.ErrMsg = "获取搜索记录列表失败,Err:" + err.Error()
  2743. return
  2744. }
  2745. }
  2746. } else if source == 9 {
  2747. if isAdminRole {
  2748. total, err = cygx.GetCygxRoadshowCountByCompany(condition)
  2749. if err != nil {
  2750. br.Msg = "获取信息失败"
  2751. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  2752. return
  2753. }
  2754. list, err = cygx.GetCygxRoadshowByCompany(condition, startSize, pageSize)
  2755. if err != nil && err.Error() != utils.ErrNoRow() {
  2756. br.Msg = "获取信息失败"
  2757. br.ErrMsg = "获取搜索记录列表失败,Err:" + err.Error()
  2758. return
  2759. }
  2760. } else {
  2761. total, err = cygx.GetCygxRoadshowCountByCompanyWeekly(condition)
  2762. if err != nil {
  2763. br.Msg = "获取信息失败"
  2764. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  2765. return
  2766. }
  2767. list, err = cygx.GetCygxRoadshowByCompanyWeekly(condition, startSize, pageSize)
  2768. if err != nil && err.Error() != utils.ErrNoRow() {
  2769. br.Msg = "获取信息失败"
  2770. br.ErrMsg = "获取搜索记录列表失败,Err:" + err.Error()
  2771. return
  2772. }
  2773. }
  2774. } else if source == 10 { //标签点击记录
  2775. if isAdminRole {
  2776. total, err = cygx.GetCygxTagHistoryCount(condition)
  2777. if err != nil {
  2778. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2779. br.Msg = "获取搜索记录失败"
  2780. return
  2781. }
  2782. list, err = cygx.GetCygxTagHistoryListBycondition(condition, startSize, pageSize)
  2783. if err != nil && err.Error() != utils.ErrNoRow() {
  2784. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2785. br.Msg = "获取搜索记录列表失败"
  2786. return
  2787. }
  2788. } else {
  2789. total, err = cygx.GetCygxTagHistoryCountWeekly(condition)
  2790. if err != nil {
  2791. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2792. br.Msg = "获取搜索记录失败"
  2793. return
  2794. }
  2795. list, err = cygx.GetCygxTagHistoryListByconditionWeekly(condition, startSize, pageSize)
  2796. if err != nil && err.Error() != utils.ErrNoRow() {
  2797. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2798. br.Msg = "获取搜索记录列表失败"
  2799. return
  2800. }
  2801. }
  2802. } else if source == 11 { //专栏文章阅读记录
  2803. if isAdminRole {
  2804. total, list, err = cygx.GetCygxYanxuaSspecialHistoryRecordByUser(condition, startSize, pageSize)
  2805. if err != nil && err.Error() != utils.ErrNoRow() {
  2806. br.Msg = "获取信息失败"
  2807. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  2808. return
  2809. }
  2810. } else {
  2811. total, list, err = cygx.GetCygxYanxuaSspecialHistoryRecordByUserWeekly(condition, startSize, pageSize)
  2812. if err != nil && err.Error() != utils.ErrNoRow() {
  2813. br.Msg = "获取信息失败"
  2814. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  2815. return
  2816. }
  2817. }
  2818. if len(list) > 0 {
  2819. for k, v := range list {
  2820. list[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
  2821. list[k].RegisterPlatformText = cygxService.GetArticleSourcePlatformText(v.RegisterPlatform)
  2822. list[k].HttpUrl = utils.CYGX_MFYX_URL + "/column/detail/" + strconv.Itoa(v.ArticleId)
  2823. }
  2824. }
  2825. //导出excel
  2826. if isExport {
  2827. exportListYanxuanSpecial(this, list, 2, br)
  2828. return
  2829. }
  2830. } else if source == 12 { //收藏的专栏文章
  2831. if isAdminRole {
  2832. total, list, err = cygx.GetCygxYanxuanSpecialCollectByUser(condition, startSize, pageSize)
  2833. if err != nil && err.Error() != utils.ErrNoRow() {
  2834. br.Msg = "获取信息失败"
  2835. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  2836. return
  2837. }
  2838. } else {
  2839. total, list, err = cygx.GetCygxYanxuanSpecialCollectByUserWeekly(condition, startSize, pageSize)
  2840. if err != nil && err.Error() != utils.ErrNoRow() {
  2841. br.Msg = "获取信息失败"
  2842. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  2843. return
  2844. }
  2845. }
  2846. if len(list) > 0 {
  2847. for k, v := range list {
  2848. list[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
  2849. list[k].RegisterPlatformText = cygxService.GetArticleSourcePlatformText(v.RegisterPlatform)
  2850. list[k].HttpUrl = utils.CYGX_MFYX_URL + "/column/detail/" + strconv.Itoa(v.ArticleId)
  2851. }
  2852. }
  2853. } else if source == 13 { //关注的专栏作者
  2854. if isAdminRole {
  2855. total, list, err = cygx.GetCygxYanxuanSpecialAuthorByUser(condition, startSize, pageSize)
  2856. if err != nil && err.Error() != utils.ErrNoRow() {
  2857. br.Msg = "获取信息失败"
  2858. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  2859. return
  2860. }
  2861. } else {
  2862. total, list, err = cygx.GetCygxYanxuanSpecialAuthorByUserWeekly(condition, startSize, pageSize)
  2863. if err != nil && err.Error() != utils.ErrNoRow() {
  2864. br.Msg = "获取信息失败"
  2865. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  2866. return
  2867. }
  2868. }
  2869. if len(list) > 0 {
  2870. for k, v := range list {
  2871. list[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
  2872. list[k].RegisterPlatformText = cygxService.GetArticleSourcePlatformText(v.RegisterPlatform)
  2873. list[k].HttpUrl = utils.CYGX_MFYX_URL + "/column/view/" + strconv.Itoa(v.DepartmentId)
  2874. }
  2875. }
  2876. } else if source == 14 { //交流反馈
  2877. if isAdminRole {
  2878. total, list, err = cygx.GetCygxUserFeedback(condition, startSize, pageSize)
  2879. if err != nil && err.Error() != utils.ErrNoRow() {
  2880. br.Msg = "获取信息失败"
  2881. br.ErrMsg = "获取用户交流反馈,Err:" + err.Error()
  2882. return
  2883. }
  2884. } else {
  2885. total, list, err = cygx.GetCygxUserFeedbackWeekly(condition, startSize, pageSize)
  2886. if err != nil && err.Error() != utils.ErrNoRow() {
  2887. br.Msg = "获取信息失败"
  2888. br.ErrMsg = "获取用户交流反馈,Err:" + err.Error()
  2889. return
  2890. }
  2891. }
  2892. } else if source == 15 { //1V1路演
  2893. if startDate != "" {
  2894. condition += ` AND b.start_date >= '` + startDate + `' `
  2895. }
  2896. if endDate != "" {
  2897. condition += ` AND b.start_date <= '` + endDate + `' `
  2898. }
  2899. var totalRsCalendar int
  2900. var listRsCalendar []*roadshow.RsCalendarMeetingUserByRai
  2901. if isAdminRole {
  2902. totalRsCalendar, listRsCalendar, err = roadshow.GetRsCalendarMeetingUserByRai(condition, startSize, pageSize)
  2903. if err != nil {
  2904. br.Msg = "获取信息失败"
  2905. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  2906. return
  2907. }
  2908. } else {
  2909. totalRsCalendar, listRsCalendar, err = roadshow.GetRsCalendarMeetingUserByRaiWeekly(condition, startSize, pageSize)
  2910. if err != nil {
  2911. br.Msg = "获取信息失败"
  2912. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  2913. return
  2914. }
  2915. }
  2916. total = totalRsCalendar
  2917. list, err = cygxService.HandleListRsCalendar(listRsCalendar)
  2918. if err != nil {
  2919. br.Msg = "获取信息失败"
  2920. br.ErrMsg = "HandleListRsCalendar,Err:" + err.Error()
  2921. return
  2922. }
  2923. //导出excel
  2924. if isExport {
  2925. exportListRsCalendar(this, list, 2, br)
  2926. return
  2927. }
  2928. }
  2929. page := paging.GetPaging(currentIndex, pageSize, total)
  2930. if len(list) == 0 {
  2931. list = make([]*cygx.UserInteraction, 0)
  2932. }
  2933. resp.List = list
  2934. resp.Paging = page
  2935. br.Ret = 200
  2936. br.Success = true
  2937. br.Msg = "获取成功"
  2938. br.Data = resp
  2939. }
  2940. // @Title 机构相关互动下载
  2941. // @Description 机构相关互动下载接口
  2942. // @Param CompanyId query int true "公司id"
  2943. // @Param Source query int true "来源 报告阅读列表: 1, 活动互动记录: 2"
  2944. // @Param IsMeeting query string true "是否到会 1到会、2未到会"
  2945. // @Param MeetType query string true "参会方式 1线上,2线下 默认为线上"
  2946. // @Param StartDate query string true "开始时间"
  2947. // @Param EndDate query string true "结束时间"
  2948. // @Param KeyWord query string true "搜索关键词"
  2949. // @Param ActivityName query string true "活动名称"
  2950. // @Param ClassType query int true "列表类型,1:权益,2:研选,默认1"
  2951. // @Success 200 {object} cygx.CygxUserTableStatusListRep
  2952. // @router /user/company/export/interaction [get]
  2953. func (this *UserController) CompanyExportInteraction() {
  2954. br := new(models.BaseResponse).Init()
  2955. defer func() {
  2956. this.Data["json"] = br
  2957. this.ServeJSON()
  2958. }()
  2959. sysUser := this.SysUser
  2960. if sysUser == nil {
  2961. br.Msg = "请登录"
  2962. br.ErrMsg = "请登录,SysUser Is Empty"
  2963. br.Ret = 408
  2964. return
  2965. }
  2966. companyId, _ := this.GetInt("CompanyId")
  2967. isMeeting := this.GetString("IsMeeting")
  2968. meetType := this.GetString("MeetType")
  2969. startDate := this.GetString("StartDate")
  2970. endDate := this.GetString("EndDate")
  2971. keyWord := this.GetString("KeyWord")
  2972. activityName := this.GetString("ActivityName")
  2973. source, _ := this.GetInt("Source")
  2974. classType, _ := this.GetInt("ClassType", 1)
  2975. if companyId < 1 {
  2976. br.Msg = "用户不存在"
  2977. return
  2978. }
  2979. //获取企业客户信息
  2980. companyInfo, err := company.GetCompanyById(companyId)
  2981. if err != nil {
  2982. br.Msg = "获取信息失败"
  2983. br.ErrMsg = "GetCompanyById,Err:" + err.Error()
  2984. return
  2985. }
  2986. var isAdminRole bool
  2987. //如果不是管理员身份或者研究员身份则需要添加可见范围处理
  2988. if sysUser.Role == utils.ROLE_TYPE_CODE_ADMIN || sysUser.Role == utils.ROLE_TYPE_CODE_RESEARCHR {
  2989. isAdminRole = true
  2990. }
  2991. var pageSize = 9999
  2992. var list []*cygx.UserInteraction
  2993. var condition string
  2994. condition += ` AND r.company_id = ` + strconv.Itoa(companyId) + ` AND r.create_time < date_format(now(),'%Y-%m-%d') ` //过滤当天时间
  2995. if keyWord != "" {
  2996. //condition += ` AND r.user_id IN (SELECT user_id FROM wx_user WHERE mobile LIKE '%` + keyWord + `%' OR email LIKE '%` + keyWord + `%' OR real_name LIKE '%` + keyWord + `%')`
  2997. condition += ` AND ( r.mobile LIKE '%` + keyWord + `%' OR r.email LIKE '%` + keyWord + `%' OR r.real_name LIKE '%` + keyWord + `%')`
  2998. }
  2999. if source == 1 {
  3000. if classType == 1 {
  3001. condition += " AND art.article_type_id = 0 "
  3002. } else {
  3003. condition += " AND art.article_type_id > 0 "
  3004. }
  3005. if startDate != "" {
  3006. startDate += " 00:00:00"
  3007. condition += ` AND r.create_time >= '` + startDate + `' `
  3008. }
  3009. if endDate != "" {
  3010. endDate += " 23:59:59"
  3011. condition += ` AND r.create_time <= '` + endDate + `' `
  3012. }
  3013. condition += ` ORDER BY r.create_time DESC `
  3014. var pars []interface{}
  3015. var listRecord []*cygx.CygxArticleAndYanxuanRecordResp
  3016. if isAdminRole {
  3017. listRecord, err = cygx.GetCygxArticleAndYanxuanRecordRespList(condition, pars, 0, pageSize)
  3018. if err != nil && err.Error() != utils.ErrNoRow() {
  3019. br.Msg = "获取信息失败"
  3020. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  3021. return
  3022. }
  3023. } else {
  3024. listRecord, err = cygx.GetCygxArticleAndYanxuanRecordRespListWeekly(condition, pars, 0, pageSize)
  3025. if err != nil && err.Error() != utils.ErrNoRow() {
  3026. br.Msg = "获取信息失败"
  3027. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  3028. return
  3029. }
  3030. }
  3031. //处理查询信息回显
  3032. list, err = cygxService.HandleArticleAndYanxuanRecordList(listRecord)
  3033. if err != nil && err.Error() != utils.ErrNoRow() {
  3034. br.Msg = "获取信息失败"
  3035. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  3036. return
  3037. }
  3038. if len(list) > 0 {
  3039. var articleIds string
  3040. mapAricleId := make(map[int]int)
  3041. mapAricleIndustrialSubjectName := make(map[int]*cygx.ArticleIndustrialSubjectNameResp)
  3042. for k, v := range list {
  3043. if v.ArticleId >= utils.SummaryArticleId {
  3044. list[k].ArticleType = 1
  3045. } else {
  3046. list[k].ArticleType = 2
  3047. }
  3048. if list[k].PermissionName == "" {
  3049. list[k].PermissionName = v.CategoryName
  3050. }
  3051. if mapAricleId[v.ArticleId] == 0 {
  3052. articleIds += strconv.Itoa(v.ArticleId) + ","
  3053. mapAricleId[v.ArticleId] = v.ArticleId
  3054. }
  3055. }
  3056. articleIds = strings.TrimRight(articleIds, ",")
  3057. if articleIds != "" {
  3058. listArticleIndustrialSubjectList, err := cygx.GetCygxArticleIndustrialSubjectName(articleIds)
  3059. if err != nil && err.Error() != utils.ErrNoRow() {
  3060. br.Msg = "获取信息失败"
  3061. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  3062. return
  3063. }
  3064. if len(listArticleIndustrialSubjectList) > 0 {
  3065. for _, v := range listArticleIndustrialSubjectList {
  3066. mapAricleIndustrialSubjectName[v.ArticleId] = v
  3067. }
  3068. for k, v := range list {
  3069. if mapAricleIndustrialSubjectName[v.ArticleId] != nil {
  3070. list[k].IndustryName = mapAricleIndustrialSubjectName[v.ArticleId].IndustryName
  3071. list[k].SubjectNameStr = mapAricleIndustrialSubjectName[v.ArticleId].SubjectNameStr
  3072. }
  3073. }
  3074. }
  3075. }
  3076. }
  3077. } else if source == 2 {
  3078. if classType == 1 {
  3079. condition += " AND a.chart_permission_id != 31 "
  3080. } else {
  3081. condition += " AND a.chart_permission_id = 31 "
  3082. }
  3083. if isMeeting == "1" {
  3084. condition += ` AND r.is_meeting = 1 `
  3085. }
  3086. if isMeeting == "2" {
  3087. condition += ` AND r.is_meeting = 0 `
  3088. }
  3089. if meetType == "1" {
  3090. condition += ` AND t.activity_type = 1 `
  3091. }
  3092. if meetType == "2" {
  3093. condition += ` AND t.activity_type = 0 `
  3094. }
  3095. if startDate != "" {
  3096. startDate += " 00:00:00"
  3097. condition += ` AND a.activity_time >= '` + startDate + `' `
  3098. }
  3099. if endDate != "" {
  3100. endDate += " 23:59:59"
  3101. condition += ` AND a.activity_time <= '` + endDate + `' `
  3102. }
  3103. if activityName != "" {
  3104. condition += ` AND a.activity_name LIKE '%` + activityName + `%' `
  3105. }
  3106. if isAdminRole {
  3107. list, err = cygx.GetActivityMeetByCompany(condition, 0, pageSize)
  3108. if err != nil && err.Error() != utils.ErrNoRow() {
  3109. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3110. br.Msg = "获取参会人数列表失败"
  3111. return
  3112. }
  3113. } else {
  3114. list, err = cygx.GetActivityMeetByCompanyWeekly(condition, 0, pageSize)
  3115. if err != nil && err.Error() != utils.ErrNoRow() {
  3116. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3117. br.Msg = "获取参会人数列表失败"
  3118. return
  3119. }
  3120. }
  3121. if len(list) > 0 {
  3122. for k, v := range list {
  3123. if v.ActivityType == 1 {
  3124. if v.SignupType == "2" {
  3125. list[k].InteractionType = "自主拨入"
  3126. } else {
  3127. list[k].InteractionType = "预约外呼"
  3128. }
  3129. if v.ReminderNum > 0 {
  3130. list[k].InteractionType += ",会议提醒"
  3131. }
  3132. }
  3133. }
  3134. }
  3135. } else if source == 11 {
  3136. if isAdminRole {
  3137. _, list, err = cygx.GetCygxYanxuaSspecialHistoryRecordByUser(condition, 0, 9999)
  3138. if err != nil && err.Error() != utils.ErrNoRow() {
  3139. br.Msg = "获取信息失败"
  3140. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  3141. return
  3142. }
  3143. } else {
  3144. _, list, err = cygx.GetCygxYanxuaSspecialHistoryRecordByUserWeekly(condition, 0, 9999)
  3145. if err != nil && err.Error() != utils.ErrNoRow() {
  3146. br.Msg = "获取信息失败"
  3147. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  3148. return
  3149. }
  3150. }
  3151. }
  3152. //创建excel
  3153. dir, err := os.Executable()
  3154. exPath := filepath.Dir(dir)
  3155. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  3156. xlsxFile := xlsx.NewFile()
  3157. if err != nil {
  3158. br.Msg = "生成文件失败"
  3159. br.ErrMsg = "生成文件失败"
  3160. return
  3161. }
  3162. style := xlsx.NewStyle()
  3163. alignment := xlsx.Alignment{
  3164. Horizontal: "center",
  3165. Vertical: "center",
  3166. WrapText: true,
  3167. }
  3168. style.Alignment = alignment
  3169. style.ApplyAlignment = true
  3170. sheet, err := xlsxFile.AddSheet("用户名单")
  3171. if err != nil {
  3172. br.Msg = "新增Sheet失败"
  3173. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  3174. return
  3175. }
  3176. var excelName string
  3177. if source == 1 {
  3178. excelName = "阅读记录"
  3179. //标头
  3180. rowTitle := sheet.AddRow()
  3181. cellA := rowTitle.AddCell()
  3182. cellA.Value = "姓名"
  3183. cellB := rowTitle.AddCell()
  3184. cellB.Value = "手机号"
  3185. cellC := rowTitle.AddCell()
  3186. cellC.Value = "报告标题"
  3187. cellD := rowTitle.AddCell()
  3188. cellD.Value = "所属行业"
  3189. cellE := rowTitle.AddCell()
  3190. cellE.Value = "所属产业"
  3191. cellF := rowTitle.AddCell()
  3192. cellF.Value = "关联标的"
  3193. cellG := rowTitle.AddCell()
  3194. cellG.Value = "发布时间"
  3195. cellH := rowTitle.AddCell()
  3196. cellH.Value = "阅读时间"
  3197. cellI := rowTitle.AddCell()
  3198. cellI.Value = "阅读时长"
  3199. for _, item := range list {
  3200. row := sheet.AddRow()
  3201. cellA := row.AddCell()
  3202. cellA.Value = item.RealName
  3203. cellB := row.AddCell()
  3204. cellB.Value = item.Mobile
  3205. cellC := row.AddCell()
  3206. cellC.Value = item.Title
  3207. cellD := row.AddCell()
  3208. cellD.Value = item.PermissionName
  3209. cellE := row.AddCell()
  3210. cellE.Value = item.IndustryName
  3211. cellF := row.AddCell()
  3212. cellF.Value = item.SubjectNameStr
  3213. cellG := row.AddCell()
  3214. cellG.Value = item.PublishDate
  3215. cellH := row.AddCell()
  3216. cellH.Value = item.CreateTime
  3217. cellI := row.AddCell()
  3218. cellI.Value = item.StopTime
  3219. }
  3220. } else if source == 2 {
  3221. excelName = "参会记录"
  3222. //标头
  3223. rowTitle := sheet.AddRow()
  3224. cellA := rowTitle.AddCell()
  3225. cellA.Value = "姓名"
  3226. cellB := rowTitle.AddCell()
  3227. cellB.Value = "手机号"
  3228. cellC := rowTitle.AddCell()
  3229. cellC.Value = "活动名称"
  3230. cellD := rowTitle.AddCell()
  3231. cellD.Value = "所属行业"
  3232. cellE := rowTitle.AddCell()
  3233. cellE.Value = "活动类型"
  3234. cellF := rowTitle.AddCell()
  3235. cellF.Value = "活动主题"
  3236. cellG := rowTitle.AddCell()
  3237. cellG.Value = "活动时间"
  3238. cellH := rowTitle.AddCell()
  3239. cellH.Value = "是否到会"
  3240. cellI := rowTitle.AddCell()
  3241. cellI.Value = "首次入会时间"
  3242. cellJ := rowTitle.AddCell()
  3243. cellJ.Value = "最后退出时间"
  3244. cellK := rowTitle.AddCell()
  3245. cellK.Value = "参与总时长"
  3246. cellL := rowTitle.AddCell()
  3247. cellL.Value = "参会方式"
  3248. cellM := rowTitle.AddCell()
  3249. cellM.Value = "参会权鉴"
  3250. cellN := rowTitle.AddCell()
  3251. cellN.Value = "参会状态"
  3252. for _, item := range list {
  3253. row := sheet.AddRow()
  3254. cellA := row.AddCell()
  3255. cellA.Value = item.RealName
  3256. cellB := row.AddCell()
  3257. cellB.Value = item.Mobile
  3258. cellC := row.AddCell()
  3259. cellC.Value = item.ActivityName
  3260. cellD := row.AddCell()
  3261. cellD.Value = item.PermissionName
  3262. cellE := row.AddCell()
  3263. cellE.Value = item.ActivityTypeName
  3264. cellF := row.AddCell()
  3265. cellF.Value = item.Label
  3266. cellG := row.AddCell()
  3267. cellG.Value = item.ActivityTime
  3268. cellH := row.AddCell()
  3269. if item.IsMeeting == 1 {
  3270. cellH.Value = "到会"
  3271. } else {
  3272. cellH.Value = "未到会"
  3273. }
  3274. cellI := row.AddCell()
  3275. cellI.Value = item.FirstMeetingTime
  3276. cellJ := row.AddCell()
  3277. cellJ.Value = item.LastMeetingTime
  3278. cellK := row.AddCell()
  3279. cellK.Value = item.Duration
  3280. cellL := row.AddCell()
  3281. cellL.Value = item.LastMeetingTime
  3282. cellM := row.AddCell()
  3283. cellM.Value = item.MeetingTypeStr
  3284. cellN := row.AddCell()
  3285. cellN.Value = item.MeetingStatusStr
  3286. }
  3287. } else if source == 11 {
  3288. //标头
  3289. rowTitle := sheet.AddRow()
  3290. cellA := rowTitle.AddCell()
  3291. cellA.Value = "文章标题"
  3292. cellB := rowTitle.AddCell()
  3293. cellB.Value = "文章类型"
  3294. cellC := rowTitle.AddCell()
  3295. cellC.Value = "标签"
  3296. cellD := rowTitle.AddCell()
  3297. cellD.Value = "发布时间"
  3298. cellE := rowTitle.AddCell()
  3299. cellE.Value = "阅读时间"
  3300. cellF := rowTitle.AddCell()
  3301. cellF.Value = "阅读时长"
  3302. cellG := rowTitle.AddCell()
  3303. cellG.Value = "阅读来源"
  3304. for _, item := range list {
  3305. row := sheet.AddRow()
  3306. cellA := row.AddCell()
  3307. cellA.Value = item.Title
  3308. cellB := row.AddCell()
  3309. if item.SpecialType == 1 {
  3310. cellB.Value = "笔记"
  3311. } else {
  3312. cellB.Value = "观点"
  3313. }
  3314. cellC := row.AddCell()
  3315. cellC.Value = item.IndustryName
  3316. cellD := row.AddCell()
  3317. cellD.Value = item.PublishDate
  3318. cellE := row.AddCell()
  3319. cellE.Value = item.CreateTime
  3320. cellF := row.AddCell()
  3321. cellF.Value = item.StopTime
  3322. cellG := row.AddCell()
  3323. cellG.Value = cygxService.GetArticleSourcePlatformText(item.RegisterPlatform)
  3324. }
  3325. }
  3326. err = xlsxFile.Save(downLoadnFilePath)
  3327. if err != nil {
  3328. br.Msg = "保存文件失败"
  3329. br.ErrMsg = "保存文件失败"
  3330. return
  3331. }
  3332. randStr := time.Now().Format(utils.FormatDate)
  3333. downloadFileName := excelName + companyInfo.CompanyName + randStr + ".xlsx"
  3334. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  3335. defer func() {
  3336. os.Remove(downLoadnFilePath)
  3337. }()
  3338. br.Ret = 200
  3339. br.Success = true
  3340. br.Msg = "获取成功"
  3341. }
  3342. // @Title 全机构互动列表
  3343. // @Description 全机构互动列表接口
  3344. // @Param Source query int true "来源"
  3345. // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
  3346. // @Param IsMeeting query string false "是否到会 1到会、2未到会"
  3347. // @Param MeetType query string false "参会方式 1线上,2线下 默认为线上"
  3348. // @Param PageSize query int true "每页数据条数"
  3349. // @Param CurrentIndex query int true "当前页页码,从1开始"
  3350. // @Param StartDate query string false "开始时间"
  3351. // @Param EndDate query string false "结束时间"
  3352. // @Param KeyWord query string false "搜索关键词"
  3353. // @Param ActivityName query string false "活动名称"
  3354. // @Param ClassType query int true "列表类型,1:权益,2:研选,默认1"
  3355. // @Param IsExport query bool false "是否导出excel,默认是false"
  3356. // @Success 200 {object} cygx.UserInteractionListResp
  3357. // @router /user/company/list [get]
  3358. func (this *UserController) CompanyList() {
  3359. br := new(models.BaseResponse).Init()
  3360. defer func() {
  3361. this.Data["json"] = br
  3362. this.ServeJSON()
  3363. }()
  3364. sysUser := this.SysUser
  3365. if sysUser == nil {
  3366. br.Msg = "请登录"
  3367. br.ErrMsg = "请登录,SysUser Is Empty"
  3368. br.Ret = 408
  3369. return
  3370. }
  3371. roleTypeCode := sysUser.RoleTypeCode
  3372. pageSize, _ := this.GetInt("PageSize")
  3373. currentIndex, _ := this.GetInt("CurrentIndex")
  3374. adminId := this.GetString("AdminId")
  3375. keyWord := this.GetString("KeyWord")
  3376. isMeeting := this.GetString("IsMeeting")
  3377. meetType := this.GetString("MeetType")
  3378. startDate := this.GetString("StartDate")
  3379. endDate := this.GetString("EndDate")
  3380. activityName := this.GetString("ActivityName")
  3381. source, _ := this.GetInt("Source")
  3382. status := this.GetString("Status")
  3383. classType, _ := this.GetInt("ClassType", 1)
  3384. // 套餐类型
  3385. //packageType, _ := this.GetInt("PackageType")
  3386. keyWord = strings.Trim(keyWord, " ")
  3387. keyWord = strings.Replace(keyWord, "'", "", -1)
  3388. isExport, _ := this.GetBool("IsExport")
  3389. if isExport {
  3390. pageSize = 10000
  3391. currentIndex = 1
  3392. }
  3393. var total int
  3394. //statusItems := make([]*company.CompanyStatus, 0)
  3395. //var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}
  3396. var startSize int
  3397. if pageSize <= 0 {
  3398. pageSize = utils.PageSize20
  3399. }
  3400. if currentIndex <= 0 {
  3401. currentIndex = 1
  3402. }
  3403. startSize = paging.StartIndex(currentIndex, pageSize)
  3404. var condition string
  3405. resp := new(cygx.UserInteractionListResp)
  3406. var err error
  3407. var list []*cygx.UserInteraction
  3408. //流失
  3409. var lossCondition string
  3410. //var lossPars []interface{}
  3411. //状态分类查询条件
  3412. var permissionCondition string
  3413. if adminId != "" {
  3414. condition += ` AND b.seller_id IN (` + adminId + `) `
  3415. }
  3416. lossCondition = condition
  3417. //lossPars = pars
  3418. permissionCondition = condition
  3419. //流失客户统计
  3420. lossCondition += ` AND status='流失' `
  3421. //productId := services.GetProductId(roleTypeCode)
  3422. productId := 2
  3423. //权限控制
  3424. {
  3425. //如果不是超级管理员或者财务
  3426. if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && roleTypeCode != utils.ROLE_TYPE_CODE_FINANCE {
  3427. //如果是部门管理员
  3428. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  3429. condition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  3430. lossCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  3431. permissionCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  3432. } else {
  3433. condition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  3434. lossCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  3435. permissionCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  3436. if status == "全部" {
  3437. ////如果是筛选了流失客户状态
  3438. if sysUser.Authority <= 0 {
  3439. condition += ` AND (b.seller_id= '` + strconv.Itoa(sysUser.AdminId) + `' OR status='流失') `
  3440. permissionCondition += ` AND b.seller_id= ` + strconv.Itoa(sysUser.AdminId)
  3441. } else {
  3442. if sysUser.Authority == 1 {
  3443. condition += ` AND (b.department_id=` + strconv.Itoa(sysUser.DepartmentId) + ` OR status='流失')`
  3444. permissionCondition += ` AND b.department_id=` + strconv.Itoa(sysUser.DepartmentId)
  3445. }
  3446. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  3447. if status != utils.COMPANY_STATUS_LOSE {
  3448. condition += ` AND (b.group_id=` + strconv.Itoa(sysUser.GroupId) + ` OR status='流失') `
  3449. }
  3450. permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
  3451. }
  3452. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  3453. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  3454. if err != nil {
  3455. br.Msg = "获取失败"
  3456. br.ErrMsg = "查询父级id异常" + err.Error()
  3457. return
  3458. }
  3459. var ids []*string
  3460. if pid != nil {
  3461. if *pid != 0 {
  3462. //销售主管放在三级列表中
  3463. ids, err = company.GetGroupIdsByParentId(*pid)
  3464. if err != nil {
  3465. fmt.Println(err.Error())
  3466. }
  3467. } else {
  3468. //销售主管放在二级列表中
  3469. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  3470. if err != nil {
  3471. fmt.Println(err.Error())
  3472. }
  3473. }
  3474. }
  3475. var idSlice []string
  3476. var sid string
  3477. for _, id := range ids {
  3478. idSlice = append(idSlice, *id)
  3479. }
  3480. //加入父级groupId
  3481. if *pid > 0 {
  3482. idSlice = append(idSlice, strconv.Itoa(*pid))
  3483. } else {
  3484. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  3485. }
  3486. sid = strings.Join(idSlice, ",")
  3487. if len(sid) > 0 {
  3488. if status != utils.COMPANY_STATUS_LOSE {
  3489. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  3490. }
  3491. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  3492. } else {
  3493. if status != utils.COMPANY_STATUS_LOSE {
  3494. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  3495. }
  3496. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  3497. }
  3498. }
  3499. if sysUser.Authority == 4 {
  3500. if status != utils.COMPANY_STATUS_LOSE {
  3501. condition += ` AND (b.group_id =` + strconv.Itoa(sysUser.GroupId) + ` OR status='流失') `
  3502. //pars = append(pars, sysUser.GroupId)
  3503. }
  3504. permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
  3505. //permissionPars = append(permissionPars, sysUser.GroupId)
  3506. }
  3507. }
  3508. } else {
  3509. //如果没有筛选了流失客户状态,那么需要加客户归属条件加入到查询中去
  3510. if sysUser.Authority <= 0 {
  3511. if status != utils.COMPANY_STATUS_LOSE {
  3512. condition += ` AND b.seller_id=` + strconv.Itoa(sysUser.AdminId)
  3513. //pars = append(pars, sysUser.AdminId)
  3514. }
  3515. permissionCondition += ` AND b.seller_id=` + strconv.Itoa(sysUser.AdminId)
  3516. //permissionPars = append(permissionPars, sysUser.AdminId)
  3517. } else {
  3518. if sysUser.Authority == 1 {
  3519. if status != utils.COMPANY_STATUS_LOSE {
  3520. condition += ` AND b.department_id=` + strconv.Itoa(sysUser.DepartmentId)
  3521. //pars = append(pars, sysUser.DepartmentId)
  3522. }
  3523. permissionCondition += ` AND b.department_id=` + strconv.Itoa(sysUser.DepartmentId)
  3524. //permissionPars = append(permissionPars, sysUser.DepartmentId)
  3525. }
  3526. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  3527. if status != utils.COMPANY_STATUS_LOSE {
  3528. condition += ` AND b.group_id= ` + strconv.Itoa(sysUser.GroupId)
  3529. //pars = append(pars, sysUser.GroupId)
  3530. }
  3531. permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
  3532. //permissionPars = append(permissionPars, sysUser.GroupId)
  3533. }
  3534. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  3535. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  3536. if err != nil {
  3537. br.Msg = "获取失败"
  3538. br.ErrMsg = "查询父级id异常" + err.Error()
  3539. return
  3540. }
  3541. var ids []*string
  3542. if pid != nil {
  3543. if *pid != 0 {
  3544. //销售主管放在三级列表中
  3545. ids, err = company.GetGroupIdsByParentId(*pid)
  3546. if err != nil {
  3547. fmt.Println(err.Error())
  3548. }
  3549. } else {
  3550. //销售主管放在二级列表中
  3551. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  3552. if err != nil {
  3553. fmt.Println(err.Error())
  3554. }
  3555. }
  3556. }
  3557. var idSlice []string
  3558. var sid string
  3559. for _, id := range ids {
  3560. idSlice = append(idSlice, *id)
  3561. }
  3562. //加入父级groupId
  3563. if *pid > 0 {
  3564. idSlice = append(idSlice, strconv.Itoa(*pid))
  3565. } else {
  3566. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  3567. }
  3568. sid = strings.Join(idSlice, ",")
  3569. if len(sid) > 0 {
  3570. if status != utils.COMPANY_STATUS_LOSE {
  3571. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  3572. //pars = append(pars, sysUser.GroupId)
  3573. }
  3574. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  3575. } else {
  3576. if status != utils.COMPANY_STATUS_LOSE {
  3577. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  3578. //pars = append(pars, sysUser.GroupId)
  3579. }
  3580. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  3581. }
  3582. }
  3583. if sysUser.Authority == 4 {
  3584. if status != utils.COMPANY_STATUS_LOSE {
  3585. condition += ` AND b.group_id =` + strconv.Itoa(sysUser.GroupId)
  3586. //pars = append(pars, sysUser.GroupId)
  3587. }
  3588. permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
  3589. //permissionPars = append(permissionPars, sysUser.GroupId)
  3590. }
  3591. }
  3592. }
  3593. }
  3594. }
  3595. }
  3596. condition += ` AND b.status IN ('正式','试用','冻结') `
  3597. companyCondition := `SELECT a.company_id FROM company AS a INNER JOIN company_product AS b ON a.company_id=b.company_id WHERE a.enabled=1 `
  3598. companyIdsCondition := `SELECT GROUP_CONCAT( DISTINCT a.company_id SEPARATOR ',' ) AS company_ids FROM company AS a INNER JOIN company_product AS b ON a.company_id=b.company_id WHERE a.enabled=1 `
  3599. if condition != "" {
  3600. companyCondition += condition
  3601. }
  3602. companyIdsCondition += condition
  3603. var companyIds string
  3604. companyIds, err = cygx.GetCompanyIdsCondition(companyIdsCondition)
  3605. if err != nil {
  3606. br.Msg = "获取失败"
  3607. br.ErrMsg = "获取公司ID数据失败,Err:" + err.Error()
  3608. return
  3609. }
  3610. condition = ` AND r.company_id IN ( ` + companyIds + ` ) AND r.create_time < '` + time.Now().Format(utils.FormatDate) + `' ` // 过滤当天查询时间
  3611. if keyWord != "" {
  3612. condition += ` AND (r.mobile LIKE '%` + keyWord + `%' OR r.email LIKE '%` + keyWord + `%' OR r.real_name LIKE '%` + keyWord + `%'` + ` OR r.company_name LIKE '%` + keyWord + `%') `
  3613. }
  3614. var isAdminRole bool
  3615. //如果不是管理员身份或者研究员身份则需要添加可见范围处理
  3616. if sysUser.Role == utils.ROLE_TYPE_CODE_ADMIN || sysUser.Role == utils.ROLE_TYPE_CODE_RESEARCHR {
  3617. isAdminRole = true
  3618. }
  3619. if source == 1 {
  3620. if startDate != "" {
  3621. startDate += " 00:00:00"
  3622. condition += ` AND r.create_time >= '` + startDate + `' `
  3623. }
  3624. if endDate != "" {
  3625. endDate += " 23:59:59"
  3626. condition += ` AND r.create_time <= '` + endDate + `' `
  3627. }
  3628. if classType == 1 {
  3629. condition += " AND art.article_type_id = 0 "
  3630. } else {
  3631. condition += " AND art.article_type_id > 0 "
  3632. }
  3633. condition += " AND r.source = 'article' "
  3634. var pars []interface{}
  3635. condition += " ORDER BY r.create_time DESC "
  3636. var listRecord []*cygx.CygxArticleAndYanxuanRecordResp
  3637. if isAdminRole {
  3638. listRecord, err = cygx.GetCygxArticleAndYanxuanRecordRespList(condition, pars, startSize, pageSize)
  3639. if err != nil && err.Error() != utils.ErrNoRow() {
  3640. br.Msg = "获取信息失败"
  3641. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  3642. return
  3643. }
  3644. total, err = cygx.GetCygxArticleAndYanxuanRecordCount(condition, pars)
  3645. if err != nil {
  3646. br.Msg = "获取信息失败"
  3647. br.ErrMsg = "获取用户阅读记录数量失败,Err:" + err.Error()
  3648. return
  3649. }
  3650. } else {
  3651. listRecord, err = cygx.GetCygxArticleAndYanxuanRecordRespListWeekly(condition, pars, startSize, pageSize)
  3652. if err != nil && err.Error() != utils.ErrNoRow() {
  3653. br.Msg = "获取信息失败"
  3654. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  3655. return
  3656. }
  3657. total, err = cygx.GetCygxArticleAndYanxuanRecordCountWeekly(condition, pars)
  3658. if err != nil {
  3659. br.Msg = "获取信息失败"
  3660. br.ErrMsg = "获取用户阅读记录数量失败,Err:" + err.Error()
  3661. return
  3662. }
  3663. }
  3664. //处理查询信息回显
  3665. list, err = cygxService.HandleArticleAndYanxuanRecordList(listRecord)
  3666. if err != nil && err.Error() != utils.ErrNoRow() {
  3667. br.Msg = "获取信息失败"
  3668. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  3669. return
  3670. }
  3671. for k, v := range list {
  3672. if classType == 1 {
  3673. list[k].HttpUrl = utils.CYGX_WEB_URL + "/material/info/" + strconv.Itoa(v.ArticleId)
  3674. } else {
  3675. list[k].HttpUrl = utils.CYGX_MFYX_URL + "/material/info/" + strconv.Itoa(v.ArticleId)
  3676. }
  3677. }
  3678. //导出excel
  3679. if isExport {
  3680. exportListArticle(this, list, 3, br)
  3681. return
  3682. }
  3683. } else if source == 2 {
  3684. if isMeeting == "1" {
  3685. condition += ` AND r.is_meeting = 1 `
  3686. }
  3687. if isMeeting == "2" {
  3688. condition += ` AND r.is_meeting = 0 `
  3689. }
  3690. if meetType == "1" {
  3691. condition += ` AND t.activity_type = 1 `
  3692. }
  3693. if meetType == "2" {
  3694. condition += ` AND t.activity_type = 0 `
  3695. }
  3696. if startDate != "" {
  3697. startDate += " 00:00:00"
  3698. condition += ` AND a.activity_time >= '` + startDate + `' `
  3699. }
  3700. if endDate != "" {
  3701. endDate += " 23:59:59"
  3702. condition += ` AND a.activity_time <= '` + endDate + `' `
  3703. }
  3704. if activityName != "" {
  3705. condition += ` AND a.activity_name LIKE '%` + activityName + `%' `
  3706. }
  3707. if classType == 1 {
  3708. condition += " AND a.chart_permission_id != 31 "
  3709. } else {
  3710. condition += " AND a.chart_permission_id = 31 "
  3711. }
  3712. if isAdminRole {
  3713. total, err = cygx.GetActivityMeetByCompanyCount(condition)
  3714. if err != nil {
  3715. br.Msg = "获取信息失败"
  3716. br.ErrMsg = "获取参会总数失败,Err:" + err.Error()
  3717. return
  3718. }
  3719. list, err = cygx.GetActivityMeetByCompanyList(condition, startSize, pageSize)
  3720. if err != nil && err.Error() != utils.ErrNoRow() {
  3721. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3722. br.Msg = "获取参会人数列表失败"
  3723. return
  3724. }
  3725. } else {
  3726. total, err = cygx.GetActivityMeetByCompanyCountWeekly(condition)
  3727. if err != nil {
  3728. br.Msg = "获取信息失败"
  3729. br.ErrMsg = "获取参会总数失败,Err:" + err.Error()
  3730. return
  3731. }
  3732. list, err = cygx.GetActivityMeetByCompanyWeekly(condition, startSize, pageSize)
  3733. if err != nil && err.Error() != utils.ErrNoRow() {
  3734. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3735. br.Msg = "获取参会人数列表失败"
  3736. return
  3737. }
  3738. }
  3739. //根据公司ID获取对应销售
  3740. var sellerCompanyIds []int
  3741. for _, v := range list {
  3742. sellerCompanyIds = append(sellerCompanyIds, v.CompanyId)
  3743. }
  3744. sellNameMap := services.GetSellNameMapByCompanyIds(sellerCompanyIds)
  3745. if len(list) > 0 {
  3746. for k, v := range list {
  3747. if v.ActivityType == 1 {
  3748. if v.SignupType == "2" {
  3749. list[k].InteractionType = "自主拨入"
  3750. } else {
  3751. list[k].InteractionType = "预约外呼"
  3752. }
  3753. if v.ReminderNum > 0 {
  3754. list[k].InteractionType += ",会议提醒"
  3755. }
  3756. }
  3757. if v.IsMeeting == 0 {
  3758. list[k].FirstMeetingTime = ""
  3759. list[k].LastMeetingTime = ""
  3760. }
  3761. v.SellerName = sellNameMap[v.CompanyId]
  3762. }
  3763. }
  3764. //导出excel
  3765. if isExport {
  3766. exportListActivity(this, list, 3, br)
  3767. return
  3768. }
  3769. } else if source == 3 {
  3770. if classType == 1 {
  3771. condition += " AND art.article_type_id = 0 "
  3772. } else {
  3773. condition += " AND art.article_type_id > 0 "
  3774. }
  3775. if isAdminRole {
  3776. total, err = cygx.GetCygxArticleCollectCountByCompany(condition)
  3777. if err != nil {
  3778. br.Msg = "获取信息失败"
  3779. br.ErrMsg = "获取用户收藏记录总数失败,Err:" + err.Error()
  3780. return
  3781. }
  3782. list, err = cygx.GetCygxArticleCollectByCompanyList(startSize, pageSize, condition)
  3783. if err != nil && err.Error() != utils.ErrNoRow() {
  3784. br.Msg = "获取信息失败"
  3785. br.ErrMsg = "获取用户搜藏记录失败,Err:" + err.Error()
  3786. return
  3787. }
  3788. } else {
  3789. total, err = cygx.GetCygxArticleCollectCountByCompanyWeekly(condition)
  3790. if err != nil {
  3791. br.Msg = "获取信息失败"
  3792. br.ErrMsg = "获取用户收藏记录总数失败,Err:" + err.Error()
  3793. return
  3794. }
  3795. list, err = cygx.GetCygxArticleCollectByCompanyWeekly(startSize, pageSize, condition)
  3796. if err != nil && err.Error() != utils.ErrNoRow() {
  3797. br.Msg = "获取信息失败"
  3798. br.ErrMsg = "获取用户搜藏记录失败,Err:" + err.Error()
  3799. return
  3800. }
  3801. }
  3802. //根据公司ID获取对应销售
  3803. var sellerCompanyIds []int
  3804. for _, v := range list {
  3805. sellerCompanyIds = append(sellerCompanyIds, v.CompanyId)
  3806. }
  3807. sellNameMap := services.GetSellNameMapByCompanyIds(sellerCompanyIds)
  3808. if len(list) > 0 {
  3809. for k, v := range list {
  3810. if v.ArticleId >= utils.SummaryArticleId {
  3811. list[k].ArticleType = 1
  3812. } else {
  3813. list[k].ArticleType = 2
  3814. }
  3815. v.SellerName = sellNameMap[v.CompanyId]
  3816. if classType == 1 {
  3817. list[k].HttpUrl = utils.CYGX_WEB_URL + "/material/info/" + strconv.Itoa(v.ArticleId)
  3818. } else {
  3819. list[k].HttpUrl = utils.CYGX_MFYX_URL + "/material/info/" + strconv.Itoa(v.ArticleId)
  3820. }
  3821. }
  3822. }
  3823. } else if source == 4 {
  3824. if isAdminRole {
  3825. total, err = cygx.GetChartCountByUserCount(condition)
  3826. if err != nil {
  3827. br.Msg = "获取信息失败"
  3828. br.ErrMsg = "获取总数失败,Err:" + err.Error()
  3829. return
  3830. }
  3831. //condition += ` AND r.company_id = ` + strconv.Itoa(companyId) + ` AND r.create_time < date_format(now(),'%Y-%m-%d')` //过滤当天时间
  3832. list, err = cygx.GetChartCollectBycompanyList(condition, startSize, pageSize)
  3833. if err != nil {
  3834. br.Msg = "获取信息失败"
  3835. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3836. return
  3837. }
  3838. } else {
  3839. total, err = cygx.GetChartCountByUserMobileWeekly(condition)
  3840. if err != nil {
  3841. br.Msg = "获取信息失败"
  3842. br.ErrMsg = "获取总数失败,Err:" + err.Error()
  3843. return
  3844. }
  3845. //condition += ` AND r.company_id = ` + strconv.Itoa(companyId) + ` AND r.create_time < date_format(now(),'%Y-%m-%d')` //过滤当天时间
  3846. list, err = cygx.GetChartCollectBycompanyListWeekly(condition, startSize, pageSize)
  3847. if err != nil {
  3848. br.Msg = "获取信息失败"
  3849. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3850. return
  3851. }
  3852. }
  3853. if len(list) > 0 {
  3854. for k, v := range list {
  3855. var err error
  3856. condition = ` AND a.publish_status = 1 AND r.mobile = ` + v.Mobile + ` AND r.create_time < date_format(now(),'%Y-%m-%d')` //过滤当天时间
  3857. totalUser, err := cygx.GetChartCountByUserMobile(condition)
  3858. if err != nil {
  3859. br.Msg = "获取信息失败"
  3860. br.ErrMsg = "获取总数失败,Err:" + err.Error()
  3861. return
  3862. }
  3863. listChart, err := cygx.GetChartListCollectionWithCygxByMobile(condition, 0, 18)
  3864. if err != nil {
  3865. br.Msg = "获取信息失败"
  3866. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3867. return
  3868. }
  3869. for k, vChart := range listChart {
  3870. if vChart.PtagName != "" {
  3871. listChart[k].CtagNamePc = vChart.PtagName
  3872. }
  3873. if vChart.CtagName != "" {
  3874. listChart[k].CtagNamePc += "," + vChart.CtagName
  3875. }
  3876. if vChart.PtagNameTwo != "" {
  3877. listChart[k].CtagNamePc += "," + vChart.PtagNameTwo
  3878. }
  3879. if vChart.CtagNameTwo != "" {
  3880. listChart[k].CtagNamePc += "," + vChart.CtagNameTwo
  3881. }
  3882. }
  3883. pageChart := paging.GetPaging(currentIndex, pageSize, totalUser)
  3884. list[k].ListChart = listChart
  3885. list[k].Paging = pageChart
  3886. list[k].IsEnd = pageChart.IsEnd
  3887. list[k].CurrentIndex = pageChart.CurrentIndex
  3888. }
  3889. }
  3890. } else if source == 5 {
  3891. if classType == 1 {
  3892. condition += " AND m.chart_permission_id != 31 "
  3893. } else {
  3894. condition += " AND m.chart_permission_id = 31 "
  3895. }
  3896. if isAdminRole {
  3897. total, err = cygx.GetCygxIndustryFllowCountByCompany(condition)
  3898. if err != nil {
  3899. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3900. br.Msg = "获取用户关注总数失败"
  3901. return
  3902. }
  3903. list, err = cygx.GetCygxIndustryFllowByCompanyList(condition, startSize, pageSize)
  3904. if err != nil && err.Error() != utils.ErrNoRow() {
  3905. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3906. br.Msg = "获取用户关注总数失败"
  3907. return
  3908. }
  3909. } else {
  3910. total, err = cygx.GetCygxIndustryFllowCountByCompanyWeekly(condition)
  3911. if err != nil {
  3912. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3913. br.Msg = "获取用户关注总数失败"
  3914. return
  3915. }
  3916. list, err = cygx.GetCygxIndustryFllowByCompanyWeekly(condition, startSize, pageSize)
  3917. if err != nil && err.Error() != utils.ErrNoRow() {
  3918. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3919. br.Msg = "获取用户关注总数失败"
  3920. return
  3921. }
  3922. }
  3923. //根据公司ID获取对应销售
  3924. var sellerCompanyIds []int
  3925. for _, v := range list {
  3926. sellerCompanyIds = append(sellerCompanyIds, v.CompanyId)
  3927. }
  3928. sellNameMap := services.GetSellNameMapByCompanyIds(sellerCompanyIds)
  3929. for _, v := range list {
  3930. v.SellerName = sellNameMap[v.CompanyId]
  3931. }
  3932. } else if source == 6 {
  3933. if isAdminRole {
  3934. total, err = cygx.GetCygArticleDepartmentFollowCountByCompany(condition)
  3935. if err != nil {
  3936. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3937. br.Msg = "获取关注作者总数失败"
  3938. return
  3939. }
  3940. list, err = cygx.GetCygArticleDepartmentFollowByCompanyList(condition, startSize, pageSize)
  3941. if err != nil && err.Error() != utils.ErrNoRow() {
  3942. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3943. br.Msg = "获取关注作者列表失败"
  3944. return
  3945. }
  3946. } else {
  3947. total, err = cygx.GetCygArticleDepartmentFollowCountByCompanyWeekly(condition)
  3948. if err != nil {
  3949. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3950. br.Msg = "获取关注作者总数失败"
  3951. return
  3952. }
  3953. list, err = cygx.GetCygArticleDepartmentFollowByCompanyWeekly(condition, startSize, pageSize)
  3954. if err != nil && err.Error() != utils.ErrNoRow() {
  3955. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3956. br.Msg = "获取关注作者列表失败"
  3957. return
  3958. }
  3959. }
  3960. if len(list) > 0 {
  3961. //根据公司ID获取对应销售
  3962. var sellerCompanyIds []int
  3963. var departmentIds []int
  3964. for _, v := range list {
  3965. sellerCompanyIds = append(sellerCompanyIds, v.CompanyId)
  3966. departmentIds = append(departmentIds, v.DepartmentId)
  3967. }
  3968. sellNameMap := services.GetSellNameMapByCompanyIds(sellerCompanyIds)
  3969. mapIndustrialLabel := cygxService.GetArticleIndustrialLabelByDepartmentId(departmentIds) // 关联产业
  3970. for _, v := range list {
  3971. v.SellerName = sellNameMap[v.CompanyId]
  3972. v.SubjectNameStr = strings.Join(mapIndustrialLabel[v.DepartmentId], "/")
  3973. }
  3974. }
  3975. } else if source == 7 {
  3976. if classType == 1 {
  3977. condition += " AND r.register_platform IN (1,2) "
  3978. } else {
  3979. condition += " AND r.register_platform IN (5,6) "
  3980. }
  3981. if isAdminRole {
  3982. total, err = cygx.GetCygxSearchKeyWordCountBuCompany(condition)
  3983. if err != nil {
  3984. br.Msg = "获取信息失败"
  3985. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  3986. return
  3987. }
  3988. list, err = cygx.GetCygxSearchKeyWordByCompanyList(condition, startSize, pageSize)
  3989. if err != nil && err.Error() != utils.ErrNoRow() {
  3990. br.Msg = "获取信息失败"
  3991. br.ErrMsg = "获取搜索记录列表失败,Err:" + err.Error()
  3992. return
  3993. }
  3994. } else {
  3995. total, err = cygx.GetCygxSearchKeyWordCountBuCompanyWeekly(condition)
  3996. if err != nil {
  3997. br.Msg = "获取信息失败"
  3998. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  3999. return
  4000. }
  4001. list, err = cygx.GetCygxSearchKeyWordByCompanyWeekly(condition, startSize, pageSize)
  4002. if err != nil && err.Error() != utils.ErrNoRow() {
  4003. br.Msg = "获取信息失败"
  4004. br.ErrMsg = "获取搜索记录列表失败,Err:" + err.Error()
  4005. return
  4006. }
  4007. }
  4008. //根据公司ID获取对应销售
  4009. var sellerCompanyIds []int
  4010. for _, v := range list {
  4011. sellerCompanyIds = append(sellerCompanyIds, v.CompanyId)
  4012. }
  4013. sellNameMap := services.GetSellNameMapByCompanyIds(sellerCompanyIds)
  4014. for _, v := range list {
  4015. v.SellerName = sellNameMap[v.CompanyId]
  4016. }
  4017. } else if source == 8 {
  4018. if isAdminRole {
  4019. total, err = cygx.GetCygxActivitySpecialTripCountByCompany(condition)
  4020. if err != nil {
  4021. br.Msg = "获取信息失败"
  4022. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  4023. return
  4024. }
  4025. list, err = cygx.GetCygxActivitySpecialTripByCompanyList(condition, startSize, pageSize)
  4026. if err != nil && err.Error() != utils.ErrNoRow() {
  4027. br.Msg = "获取信息失败"
  4028. br.ErrMsg = "获取搜索记录列表失败,Err:" + err.Error()
  4029. return
  4030. }
  4031. } else {
  4032. total, err = cygx.GetCygxActivitySpecialTripCountByCompanyWeekly(condition)
  4033. if err != nil {
  4034. br.Msg = "获取信息失败"
  4035. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  4036. return
  4037. }
  4038. list, err = cygx.CygxActivitySpecialTripByCompanyWeekly(condition, startSize, pageSize)
  4039. if err != nil && err.Error() != utils.ErrNoRow() {
  4040. br.Msg = "获取信息失败"
  4041. br.ErrMsg = "获取搜索记录列表失败,Err:" + err.Error()
  4042. return
  4043. }
  4044. }
  4045. } else if source == 9 {
  4046. if isAdminRole {
  4047. total, err = cygx.GetCygxRoadshowCountByCompany(condition)
  4048. if err != nil {
  4049. br.Msg = "获取信息失败"
  4050. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  4051. return
  4052. }
  4053. list, err = cygx.GetCygxRoadshowByCompanyList(condition, startSize, pageSize)
  4054. if err != nil && err.Error() != utils.ErrNoRow() {
  4055. br.Msg = "获取信息失败"
  4056. br.ErrMsg = "获取搜索记录列表失败,Err:" + err.Error()
  4057. return
  4058. }
  4059. } else {
  4060. total, err = cygx.GetCygxRoadshowCountByCompanyWeekly(condition)
  4061. if err != nil {
  4062. br.Msg = "获取信息失败"
  4063. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  4064. return
  4065. }
  4066. list, err = cygx.GetCygxRoadshowByCompanyWeekly(condition, startSize, pageSize)
  4067. if err != nil && err.Error() != utils.ErrNoRow() {
  4068. br.Msg = "获取信息失败"
  4069. br.ErrMsg = "获取搜索记录列表失败,Err:" + err.Error()
  4070. return
  4071. }
  4072. }
  4073. //根据公司ID获取对应销售
  4074. var sellerCompanyIds []int
  4075. for _, v := range list {
  4076. sellerCompanyIds = append(sellerCompanyIds, v.CompanyId)
  4077. }
  4078. sellNameMap := services.GetSellNameMapByCompanyIds(sellerCompanyIds)
  4079. for _, v := range list {
  4080. v.SellerName = sellNameMap[v.CompanyId]
  4081. }
  4082. } else if source == 10 { //标签点击记录
  4083. if isAdminRole {
  4084. total, err = cygx.GetCygxTagHistoryCount(condition)
  4085. if err != nil {
  4086. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  4087. br.Msg = "获取搜索记录失败"
  4088. return
  4089. }
  4090. list, err = cygx.GetCygxTagHistoryListBycondition(condition, startSize, pageSize)
  4091. if err != nil && err.Error() != utils.ErrNoRow() {
  4092. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  4093. br.Msg = "获取搜索记录列表失败"
  4094. return
  4095. }
  4096. } else {
  4097. total, err = cygx.GetCygxTagHistoryCountWeekly(condition)
  4098. if err != nil {
  4099. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  4100. br.Msg = "获取搜索记录失败"
  4101. return
  4102. }
  4103. list, err = cygx.GetCygxTagHistoryListByconditionWeekly(condition, startSize, pageSize)
  4104. if err != nil && err.Error() != utils.ErrNoRow() {
  4105. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  4106. br.Msg = "获取搜索记录列表失败"
  4107. return
  4108. }
  4109. }
  4110. } else if source == 11 { //专栏文章阅读记录
  4111. if isAdminRole {
  4112. total, list, err = cygx.GetCygxYanxuaSspecialHistoryRecordByUser(condition, startSize, pageSize)
  4113. if err != nil && err.Error() != utils.ErrNoRow() {
  4114. br.Msg = "获取信息失败"
  4115. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  4116. return
  4117. }
  4118. } else {
  4119. total, list, err = cygx.GetCygxYanxuaSspecialHistoryRecordByUserWeekly(condition, startSize, pageSize)
  4120. if err != nil && err.Error() != utils.ErrNoRow() {
  4121. br.Msg = "获取信息失败"
  4122. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  4123. return
  4124. }
  4125. }
  4126. if len(list) > 0 {
  4127. for k, v := range list {
  4128. list[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
  4129. list[k].RegisterPlatformText = cygxService.GetArticleSourcePlatformText(v.RegisterPlatform)
  4130. list[k].HttpUrl = utils.CYGX_MFYX_URL + "/column/detail/" + strconv.Itoa(v.ArticleId)
  4131. }
  4132. for k, v := range list {
  4133. list[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
  4134. list[k].RegisterPlatformText = cygxService.GetArticleSourcePlatformText(v.RegisterPlatform)
  4135. list[k].HttpUrl = utils.CYGX_MFYX_URL + "/column/detail/" + strconv.Itoa(v.ArticleId)
  4136. }
  4137. }
  4138. //导出excel
  4139. if isExport {
  4140. exportListYanxuanSpecial(this, list, 3, br)
  4141. return
  4142. }
  4143. } else if source == 12 { //收藏的专栏文章
  4144. if isAdminRole {
  4145. total, list, err = cygx.GetCygxYanxuanSpecialCollectByUser(condition, startSize, pageSize)
  4146. if err != nil && err.Error() != utils.ErrNoRow() {
  4147. br.Msg = "获取信息失败"
  4148. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  4149. return
  4150. }
  4151. } else {
  4152. total, list, err = cygx.GetCygxYanxuanSpecialCollectByUserWeekly(condition, startSize, pageSize)
  4153. if err != nil && err.Error() != utils.ErrNoRow() {
  4154. br.Msg = "获取信息失败"
  4155. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  4156. return
  4157. }
  4158. }
  4159. if len(list) > 0 {
  4160. for k, v := range list {
  4161. list[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
  4162. list[k].RegisterPlatformText = cygxService.GetArticleSourcePlatformText(v.RegisterPlatform)
  4163. list[k].HttpUrl = utils.CYGX_MFYX_URL + "/column/detail/" + strconv.Itoa(v.ArticleId)
  4164. }
  4165. }
  4166. } else if source == 13 { //关注的专栏作者
  4167. if isAdminRole {
  4168. total, list, err = cygx.GetCygxYanxuanSpecialAuthorByUser(condition, startSize, pageSize)
  4169. if err != nil && err.Error() != utils.ErrNoRow() {
  4170. br.Msg = "获取信息失败"
  4171. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  4172. return
  4173. }
  4174. } else {
  4175. total, list, err = cygx.GetCygxYanxuanSpecialAuthorByUserWeekly(condition, startSize, pageSize)
  4176. if err != nil && err.Error() != utils.ErrNoRow() {
  4177. br.Msg = "获取信息失败"
  4178. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  4179. return
  4180. }
  4181. }
  4182. if len(list) > 0 {
  4183. for k, v := range list {
  4184. list[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
  4185. list[k].RegisterPlatformText = cygxService.GetArticleSourcePlatformText(v.RegisterPlatform)
  4186. list[k].HttpUrl = utils.CYGX_MFYX_URL + "/column/view/" + strconv.Itoa(v.DepartmentId)
  4187. }
  4188. }
  4189. } else if source == 14 { //交流反馈
  4190. if isAdminRole {
  4191. total, list, err = cygx.GetCygxUserFeedback(condition, startSize, pageSize)
  4192. if err != nil && err.Error() != utils.ErrNoRow() {
  4193. br.Msg = "获取信息失败"
  4194. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  4195. return
  4196. }
  4197. } else {
  4198. total, list, err = cygx.GetCygxUserFeedbackWeekly(condition, startSize, pageSize)
  4199. if err != nil && err.Error() != utils.ErrNoRow() {
  4200. br.Msg = "获取信息失败"
  4201. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  4202. return
  4203. }
  4204. }
  4205. } else if source == 15 {
  4206. if startDate != "" {
  4207. condition += ` AND b.start_date >= '` + startDate + `' `
  4208. }
  4209. if endDate != "" {
  4210. condition += ` AND b.start_date <= '` + endDate + `' `
  4211. }
  4212. var totalRsCalendar int
  4213. var listRsCalendar []*roadshow.RsCalendarMeetingUserByRai
  4214. if isAdminRole {
  4215. totalRsCalendar, listRsCalendar, err = roadshow.GetRsCalendarMeetingUserByRai(condition, startSize, pageSize)
  4216. if err != nil {
  4217. br.Msg = "获取信息失败"
  4218. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  4219. return
  4220. }
  4221. } else {
  4222. totalRsCalendar, listRsCalendar, err = roadshow.GetRsCalendarMeetingUserByRaiWeekly(condition, startSize, pageSize)
  4223. if err != nil {
  4224. br.Msg = "获取信息失败"
  4225. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  4226. return
  4227. }
  4228. }
  4229. total = totalRsCalendar
  4230. list, err = cygxService.HandleListRsCalendar(listRsCalendar)
  4231. if err != nil {
  4232. br.Msg = "获取信息失败"
  4233. br.ErrMsg = "HandleListRsCalendar,Err:" + err.Error()
  4234. return
  4235. }
  4236. //导出excel
  4237. if isExport {
  4238. exportListRsCalendar(this, list, 3, br)
  4239. return
  4240. }
  4241. }
  4242. page := paging.GetPaging(currentIndex, pageSize, total)
  4243. if len(list) == 0 {
  4244. list = make([]*cygx.UserInteraction, 0)
  4245. }
  4246. resp.List = list
  4247. resp.Paging = page
  4248. br.Ret = 200
  4249. br.Success = true
  4250. br.Msg = "获取成功"
  4251. br.Data = resp
  4252. }
  4253. // @Title 机构列表相关互动下载
  4254. // @Description 机构相关互动下载接口
  4255. // @Param Source query int true "来源 报告阅读列表: 1, 活动互动记录: 2"
  4256. // @Param IsMeeting query string true "是否到会 1到会、2未到会"
  4257. // @Param MeetType query string true "参会方式 1线上,2线下 默认为线上"
  4258. // @Param StartDate query string true "开始时间"
  4259. // @Param EndDate query string true "结束时间"
  4260. // @Param KeyWord query string true "搜索关键词"
  4261. // @Param ActivityName query string true "活动名称"
  4262. // @Param ClassType query int true "列表类型,1:权益,2:研选,默认1"
  4263. // @Success 200 {object} cygx.CygxUserTableStatusListRep
  4264. // @router /user/companyList/export/interaction [get]
  4265. func (this *UserController) CompanyExportInteractionList() {
  4266. br := new(models.BaseResponse).Init()
  4267. defer func() {
  4268. this.Data["json"] = br
  4269. this.ServeJSON()
  4270. }()
  4271. sysUser := this.SysUser
  4272. if sysUser == nil {
  4273. br.Msg = "请登录"
  4274. br.ErrMsg = "请登录,SysUser Is Empty"
  4275. br.Ret = 408
  4276. return
  4277. }
  4278. roleTypeCode := sysUser.RoleTypeCode
  4279. adminId := this.GetString("AdminId")
  4280. keyWord := this.GetString("KeyWord")
  4281. isMeeting := this.GetString("IsMeeting")
  4282. meetType := this.GetString("MeetType")
  4283. startDate := this.GetString("StartDate")
  4284. endDate := this.GetString("EndDate")
  4285. activityName := this.GetString("ActivityName")
  4286. source, _ := this.GetInt("Source")
  4287. status := this.GetString("Status")
  4288. classType, _ := this.GetInt("ClassType", 1)
  4289. // 套餐类型
  4290. //packageType, _ := this.GetInt("PackageType")
  4291. keyWord = strings.Trim(keyWord, " ")
  4292. keyWord = strings.Replace(keyWord, "'", "", -1)
  4293. var list []*cygx.UserInteraction
  4294. var err error
  4295. var condition string
  4296. //流失
  4297. var lossCondition string
  4298. //var lossPars []interface{}
  4299. //状态分类查询条件
  4300. var permissionCondition string
  4301. if adminId != "" {
  4302. condition += ` AND b.seller_id IN (` + adminId + `) `
  4303. }
  4304. lossCondition = condition
  4305. //lossPars = pars
  4306. permissionCondition = condition
  4307. //流失客户统计
  4308. lossCondition += ` AND status='流失' `
  4309. //productId := services.GetProductId(roleTypeCode)
  4310. productId := 2
  4311. //权限控制
  4312. {
  4313. //如果不是超级管理员或者财务
  4314. if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && roleTypeCode != utils.ROLE_TYPE_CODE_FINANCE {
  4315. //如果是部门管理员
  4316. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  4317. condition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  4318. lossCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  4319. permissionCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  4320. } else {
  4321. condition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  4322. lossCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  4323. permissionCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  4324. if status == "全部" {
  4325. ////如果是筛选了流失客户状态
  4326. if sysUser.Authority <= 0 {
  4327. condition += ` AND (b.seller_id= '` + strconv.Itoa(sysUser.AdminId) + `' OR status='流失') `
  4328. permissionCondition += ` AND b.seller_id= ` + strconv.Itoa(sysUser.AdminId)
  4329. } else {
  4330. if sysUser.Authority == 1 {
  4331. condition += ` AND (b.department_id=` + strconv.Itoa(sysUser.DepartmentId) + ` OR status='流失')`
  4332. permissionCondition += ` AND b.department_id=` + strconv.Itoa(sysUser.DepartmentId)
  4333. }
  4334. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  4335. if status != utils.COMPANY_STATUS_LOSE {
  4336. condition += ` AND (b.group_id=` + strconv.Itoa(sysUser.GroupId) + ` OR status='流失') `
  4337. }
  4338. permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
  4339. }
  4340. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  4341. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  4342. if err != nil {
  4343. br.Msg = "获取失败"
  4344. br.ErrMsg = "查询父级id异常" + err.Error()
  4345. return
  4346. }
  4347. var ids []*string
  4348. if pid != nil {
  4349. if *pid != 0 {
  4350. //销售主管放在三级列表中
  4351. ids, err = company.GetGroupIdsByParentId(*pid)
  4352. if err != nil {
  4353. fmt.Println(err.Error())
  4354. }
  4355. } else {
  4356. //销售主管放在二级列表中
  4357. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  4358. if err != nil {
  4359. fmt.Println(err.Error())
  4360. }
  4361. }
  4362. }
  4363. var idSlice []string
  4364. var sid string
  4365. for _, id := range ids {
  4366. idSlice = append(idSlice, *id)
  4367. }
  4368. //加入父级groupId
  4369. if *pid > 0 {
  4370. idSlice = append(idSlice, strconv.Itoa(*pid))
  4371. } else {
  4372. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  4373. }
  4374. sid = strings.Join(idSlice, ",")
  4375. if len(sid) > 0 {
  4376. if status != utils.COMPANY_STATUS_LOSE {
  4377. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  4378. }
  4379. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  4380. } else {
  4381. if status != utils.COMPANY_STATUS_LOSE {
  4382. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  4383. }
  4384. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  4385. }
  4386. }
  4387. if sysUser.Authority == 4 {
  4388. if status != utils.COMPANY_STATUS_LOSE {
  4389. condition += ` AND (b.group_id =` + strconv.Itoa(sysUser.GroupId) + ` OR status='流失') `
  4390. //pars = append(pars, sysUser.GroupId)
  4391. }
  4392. permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
  4393. //permissionPars = append(permissionPars, sysUser.GroupId)
  4394. }
  4395. }
  4396. } else {
  4397. //如果没有筛选了流失客户状态,那么需要加客户归属条件加入到查询中去
  4398. if sysUser.Authority <= 0 {
  4399. if status != utils.COMPANY_STATUS_LOSE {
  4400. condition += ` AND b.seller_id=` + strconv.Itoa(sysUser.AdminId)
  4401. //pars = append(pars, sysUser.AdminId)
  4402. }
  4403. permissionCondition += ` AND b.seller_id=` + strconv.Itoa(sysUser.AdminId)
  4404. //permissionPars = append(permissionPars, sysUser.AdminId)
  4405. } else {
  4406. if sysUser.Authority == 1 {
  4407. if status != utils.COMPANY_STATUS_LOSE {
  4408. condition += ` AND b.department_id=` + strconv.Itoa(sysUser.DepartmentId)
  4409. //pars = append(pars, sysUser.DepartmentId)
  4410. }
  4411. permissionCondition += ` AND b.department_id=` + strconv.Itoa(sysUser.DepartmentId)
  4412. //permissionPars = append(permissionPars, sysUser.DepartmentId)
  4413. }
  4414. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  4415. if status != utils.COMPANY_STATUS_LOSE {
  4416. condition += ` AND b.group_id= ` + strconv.Itoa(sysUser.GroupId)
  4417. //pars = append(pars, sysUser.GroupId)
  4418. }
  4419. permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
  4420. //permissionPars = append(permissionPars, sysUser.GroupId)
  4421. }
  4422. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  4423. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  4424. if err != nil {
  4425. br.Msg = "获取失败"
  4426. br.ErrMsg = "查询父级id异常" + err.Error()
  4427. return
  4428. }
  4429. var ids []*string
  4430. if pid != nil {
  4431. if *pid != 0 {
  4432. //销售主管放在三级列表中
  4433. ids, err = company.GetGroupIdsByParentId(*pid)
  4434. if err != nil {
  4435. fmt.Println(err.Error())
  4436. }
  4437. } else {
  4438. //销售主管放在二级列表中
  4439. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  4440. if err != nil {
  4441. fmt.Println(err.Error())
  4442. }
  4443. }
  4444. }
  4445. var idSlice []string
  4446. var sid string
  4447. for _, id := range ids {
  4448. idSlice = append(idSlice, *id)
  4449. }
  4450. //加入父级groupId
  4451. if *pid > 0 {
  4452. idSlice = append(idSlice, strconv.Itoa(*pid))
  4453. } else {
  4454. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  4455. }
  4456. sid = strings.Join(idSlice, ",")
  4457. if len(sid) > 0 {
  4458. if status != utils.COMPANY_STATUS_LOSE {
  4459. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  4460. //pars = append(pars, sysUser.GroupId)
  4461. }
  4462. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  4463. } else {
  4464. if status != utils.COMPANY_STATUS_LOSE {
  4465. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  4466. //pars = append(pars, sysUser.GroupId)
  4467. }
  4468. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  4469. }
  4470. }
  4471. if sysUser.Authority == 4 {
  4472. if status != utils.COMPANY_STATUS_LOSE {
  4473. condition += ` AND b.group_id =` + strconv.Itoa(sysUser.GroupId)
  4474. //pars = append(pars, sysUser.GroupId)
  4475. }
  4476. permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
  4477. //permissionPars = append(permissionPars, sysUser.GroupId)
  4478. }
  4479. }
  4480. }
  4481. }
  4482. }
  4483. }
  4484. //condition += ` AND b.status IN ('正式','试用','冻结') `
  4485. //companyCondition := `SELECT a.company_id FROM company AS a INNER JOIN company_product AS b ON a.company_id=b.company_id WHERE a.enabled=1 `
  4486. //if condition != "" {
  4487. // companyCondition += condition
  4488. //}
  4489. condition += ` AND b.status IN ('正式','试用','冻结') `
  4490. companyCondition := `SELECT a.company_id FROM company AS a INNER JOIN company_product AS b ON a.company_id=b.company_id WHERE a.enabled=1 `
  4491. companyIdsCondition := `SELECT GROUP_CONCAT( DISTINCT a.company_id SEPARATOR ',' ) AS company_ids FROM company AS a INNER JOIN company_product AS b ON a.company_id=b.company_id WHERE a.enabled=1 `
  4492. if condition != "" {
  4493. companyCondition += condition
  4494. }
  4495. companyIdsCondition += condition
  4496. var companyIds string
  4497. companyIds, err = cygx.GetCompanyIdsCondition(companyIdsCondition)
  4498. companyIds, err = cygx.GetCompanyIdsCondition(companyIdsCondition)
  4499. if err != nil {
  4500. br.Msg = "获取失败"
  4501. br.ErrMsg = "获取公司ID数据失败,Err:" + err.Error()
  4502. return
  4503. }
  4504. condition = ` AND r.company_id IN ( ` + companyIds + ` )AND r.create_time < date_format(now(),'%Y-%m-%d') ` //过滤当天时间
  4505. if keyWord != "" {
  4506. condition += ` AND (r.mobile LIKE '%` + keyWord + `%' OR r.email LIKE '%` + keyWord + `%' OR r.real_name LIKE '%` + keyWord + `%'` + ` OR r.company_name LIKE '%` + keyWord + `%') `
  4507. }
  4508. var isAdminRole bool
  4509. var pageSize = 9999
  4510. //如果不是管理员身份或者研究员身份则需要添加可见范围处理
  4511. if sysUser.Role == utils.ROLE_TYPE_CODE_ADMIN || sysUser.Role == utils.ROLE_TYPE_CODE_RESEARCHR {
  4512. isAdminRole = true
  4513. }
  4514. if source == 1 {
  4515. if classType == 1 {
  4516. condition += " AND art.article_type_id = 0 "
  4517. } else {
  4518. condition += " AND art.article_type_id > 0 "
  4519. }
  4520. if startDate != "" {
  4521. startDate += " 00:00:00"
  4522. condition += ` AND r.create_time >= '` + startDate + `' `
  4523. }
  4524. if endDate != "" {
  4525. endDate += " 23:59:59"
  4526. condition += ` AND r.create_time <= '` + endDate + `' `
  4527. }
  4528. condition += ` ORDER BY r.create_time DESC `
  4529. var pars []interface{}
  4530. var listRecord []*cygx.CygxArticleAndYanxuanRecordResp
  4531. if isAdminRole {
  4532. listRecord, err = cygx.GetCygxArticleAndYanxuanRecordRespList(condition, pars, 0, pageSize)
  4533. if err != nil && err.Error() != utils.ErrNoRow() {
  4534. br.Msg = "获取信息失败"
  4535. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  4536. return
  4537. }
  4538. } else {
  4539. listRecord, err = cygx.GetCygxArticleAndYanxuanRecordRespListWeekly(condition, pars, 0, pageSize)
  4540. if err != nil && err.Error() != utils.ErrNoRow() {
  4541. br.Msg = "获取信息失败"
  4542. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  4543. return
  4544. }
  4545. }
  4546. //处理查询信息回显
  4547. list, err = cygxService.HandleArticleAndYanxuanRecordList(listRecord)
  4548. if err != nil && err.Error() != utils.ErrNoRow() {
  4549. br.Msg = "获取信息失败"
  4550. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  4551. return
  4552. }
  4553. if len(list) > 0 {
  4554. var articleIds string
  4555. mapAricleId := make(map[int]int)
  4556. mapAricleIndustrialSubjectName := make(map[int]*cygx.ArticleIndustrialSubjectNameResp)
  4557. for k, v := range list {
  4558. if v.ArticleId >= utils.SummaryArticleId {
  4559. list[k].ArticleType = 1
  4560. } else {
  4561. list[k].ArticleType = 2
  4562. }
  4563. if list[k].PermissionName == "" {
  4564. list[k].PermissionName = v.CategoryName
  4565. }
  4566. if mapAricleId[v.ArticleId] == 0 {
  4567. articleIds += strconv.Itoa(v.ArticleId) + ","
  4568. mapAricleId[v.ArticleId] = v.ArticleId
  4569. }
  4570. }
  4571. articleIds = strings.TrimRight(articleIds, ",")
  4572. if articleIds != "" {
  4573. listArticleIndustrialSubjectList, err := cygx.GetCygxArticleIndustrialSubjectName(articleIds)
  4574. if err != nil && err.Error() != utils.ErrNoRow() {
  4575. br.Msg = "获取信息失败"
  4576. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  4577. return
  4578. }
  4579. if len(listArticleIndustrialSubjectList) > 0 {
  4580. for _, v := range listArticleIndustrialSubjectList {
  4581. mapAricleIndustrialSubjectName[v.ArticleId] = v
  4582. }
  4583. for k, v := range list {
  4584. if mapAricleIndustrialSubjectName[v.ArticleId] != nil {
  4585. fmt.Println(mapAricleIndustrialSubjectName[v.ArticleId].IndustryName)
  4586. list[k].IndustryName = mapAricleIndustrialSubjectName[v.ArticleId].IndustryName
  4587. list[k].SubjectNameStr = mapAricleIndustrialSubjectName[v.ArticleId].SubjectNameStr
  4588. }
  4589. }
  4590. }
  4591. }
  4592. }
  4593. } else if source == 2 {
  4594. if classType == 1 {
  4595. condition += " AND a.chart_permission_id != 31 "
  4596. } else {
  4597. condition += " AND a.chart_permission_id = 31 "
  4598. }
  4599. if isMeeting == "1" {
  4600. condition += ` AND r.is_meeting = 1 `
  4601. }
  4602. if isMeeting == "2" {
  4603. condition += ` AND r.is_meeting = 0 `
  4604. }
  4605. if meetType == "1" {
  4606. condition += ` AND t.activity_type = 1 `
  4607. }
  4608. if meetType == "2" {
  4609. condition += ` AND t.activity_type = 0 `
  4610. }
  4611. if startDate != "" {
  4612. startDate += " 00:00:00"
  4613. condition += ` AND a.activity_time >= '` + startDate + `' `
  4614. }
  4615. if endDate != "" {
  4616. endDate += " 23:59:59"
  4617. condition += ` AND a.activity_time <= '` + endDate + `' `
  4618. }
  4619. if activityName != "" {
  4620. condition += ` AND a.activity_name LIKE '%` + activityName + `%' `
  4621. }
  4622. if isAdminRole {
  4623. list, err = cygx.GetActivityMeetByCompany(condition, 0, pageSize)
  4624. if err != nil && err.Error() != utils.ErrNoRow() {
  4625. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  4626. br.Msg = "获取参会人数列表失败"
  4627. return
  4628. }
  4629. } else {
  4630. list, err = cygx.GetActivityMeetByCompanyWeekly(condition, 0, pageSize)
  4631. if err != nil && err.Error() != utils.ErrNoRow() {
  4632. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  4633. br.Msg = "获取参会人数列表失败"
  4634. return
  4635. }
  4636. }
  4637. if len(list) > 0 {
  4638. for k, v := range list {
  4639. if v.ActivityType == 1 {
  4640. if v.SignupType == "2" {
  4641. list[k].InteractionType = "自主拨入"
  4642. } else {
  4643. list[k].InteractionType = "预约外呼"
  4644. }
  4645. if v.ReminderNum > 0 {
  4646. list[k].InteractionType += ",会议提醒"
  4647. }
  4648. }
  4649. }
  4650. }
  4651. } else if source == 11 {
  4652. if isAdminRole {
  4653. _, list, err = cygx.GetCygxYanxuaSspecialHistoryRecordByUser(condition, 0, 9999)
  4654. if err != nil && err.Error() != utils.ErrNoRow() {
  4655. br.Msg = "获取信息失败"
  4656. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  4657. return
  4658. }
  4659. } else {
  4660. _, list, err = cygx.GetCygxYanxuaSspecialHistoryRecordByUserWeekly(condition, 0, 9999)
  4661. if err != nil && err.Error() != utils.ErrNoRow() {
  4662. br.Msg = "获取信息失败"
  4663. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  4664. return
  4665. }
  4666. }
  4667. }
  4668. //创建excel
  4669. dir, err := os.Executable()
  4670. exPath := filepath.Dir(dir)
  4671. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  4672. xlsxFile := xlsx.NewFile()
  4673. if err != nil {
  4674. br.Msg = "生成文件失败"
  4675. br.ErrMsg = "生成文件失败"
  4676. return
  4677. }
  4678. style := xlsx.NewStyle()
  4679. alignment := xlsx.Alignment{
  4680. Horizontal: "center",
  4681. Vertical: "center",
  4682. WrapText: true,
  4683. }
  4684. var excelName string
  4685. style.Alignment = alignment
  4686. style.ApplyAlignment = true
  4687. sheet, err := xlsxFile.AddSheet("到会管理名单")
  4688. if err != nil {
  4689. br.Msg = "新增Sheet失败"
  4690. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  4691. return
  4692. }
  4693. if source == 1 {
  4694. excelName = "客户阅读记录"
  4695. //标头
  4696. rowTitle := sheet.AddRow()
  4697. cellA := rowTitle.AddCell()
  4698. cellA.Value = "客户名称"
  4699. cellB := rowTitle.AddCell()
  4700. cellB.Value = "所属销售"
  4701. cellC := rowTitle.AddCell()
  4702. cellC.Value = "姓名"
  4703. cellD := rowTitle.AddCell()
  4704. cellD.Value = "手机号"
  4705. cellE := rowTitle.AddCell()
  4706. cellE.Value = "报告标题"
  4707. cellF := rowTitle.AddCell()
  4708. cellF.Value = "所属行业"
  4709. cellG := rowTitle.AddCell()
  4710. cellG.Value = "所属产业"
  4711. cellH := rowTitle.AddCell()
  4712. cellH.Value = "关联标的"
  4713. cellI := rowTitle.AddCell()
  4714. cellI.Value = "发布时间"
  4715. cellJ := rowTitle.AddCell()
  4716. cellJ.Value = "阅读时间"
  4717. cellK := rowTitle.AddCell()
  4718. cellK.Value = "阅读时长"
  4719. for _, item := range list {
  4720. row := sheet.AddRow()
  4721. cellA := row.AddCell()
  4722. cellA.Value = item.CompanyName
  4723. cellB := row.AddCell()
  4724. cellB.Value = item.SellerName
  4725. cellC := row.AddCell()
  4726. cellC.Value = item.RealName
  4727. cellD := row.AddCell()
  4728. cellD.Value = item.Mobile
  4729. cellE := row.AddCell()
  4730. cellE.Value = item.Title
  4731. cellF := row.AddCell()
  4732. cellF.Value = item.PermissionName
  4733. cellG := row.AddCell()
  4734. cellG.Value = item.IndustryName
  4735. cellH := row.AddCell()
  4736. cellH.Value = item.SubjectNameStr
  4737. cellI := row.AddCell()
  4738. cellI.Value = item.PublishDate
  4739. cellJ := row.AddCell()
  4740. cellJ.Value = item.CreateTime
  4741. cellK := row.AddCell()
  4742. cellK.Value = item.StopTime
  4743. }
  4744. } else if source == 2 {
  4745. excelName = "客户参会记录"
  4746. //标头
  4747. rowTitle := sheet.AddRow()
  4748. cellA := rowTitle.AddCell()
  4749. cellA.Value = "客户名称"
  4750. cellB := rowTitle.AddCell()
  4751. cellB.Value = "所属销售"
  4752. cellC := rowTitle.AddCell()
  4753. cellC.Value = "姓名"
  4754. cellD := rowTitle.AddCell()
  4755. cellD.Value = "手机号"
  4756. cellE := rowTitle.AddCell()
  4757. cellE.Value = "活动名称"
  4758. cellF := rowTitle.AddCell()
  4759. cellF.Value = "所属行业"
  4760. cellG := rowTitle.AddCell()
  4761. cellG.Value = "活动类型"
  4762. cellH := rowTitle.AddCell()
  4763. cellH.Value = "活动主题"
  4764. cellI := rowTitle.AddCell()
  4765. cellI.Value = "活动时间"
  4766. cellJ := rowTitle.AddCell()
  4767. cellJ.Value = "是否到会"
  4768. cellK := rowTitle.AddCell()
  4769. cellK.Value = "首次入会时间"
  4770. cellL := rowTitle.AddCell()
  4771. cellL.Value = "最后退出时间"
  4772. cellM := rowTitle.AddCell()
  4773. cellM.Value = "参与总时长"
  4774. cellN := rowTitle.AddCell()
  4775. cellN.Value = "参会方式"
  4776. cellO := rowTitle.AddCell()
  4777. cellO.Value = "参会权鉴"
  4778. cellP := rowTitle.AddCell()
  4779. cellP.Value = "参会状态"
  4780. for _, item := range list {
  4781. row := sheet.AddRow()
  4782. cellA := row.AddCell()
  4783. cellA.Value = item.CompanyName
  4784. cellB := row.AddCell()
  4785. cellB.Value = item.SellerName
  4786. cellC := row.AddCell()
  4787. cellC.Value = item.RealName
  4788. cellD := row.AddCell()
  4789. cellD.Value = item.Mobile
  4790. cellE := row.AddCell()
  4791. cellE.Value = item.ActivityName
  4792. cellF := row.AddCell()
  4793. cellF.Value = item.PermissionName
  4794. cellG := row.AddCell()
  4795. cellG.Value = item.ActivityTypeName
  4796. cellH := row.AddCell()
  4797. cellH.Value = item.Label
  4798. cellI := row.AddCell()
  4799. cellI.Value = item.ActivityTime
  4800. cellJ := row.AddCell()
  4801. if item.IsMeeting == 1 {
  4802. cellJ.Value = "到会"
  4803. } else {
  4804. cellJ.Value = "未到会"
  4805. }
  4806. cellK := row.AddCell()
  4807. cellK.Value = item.FirstMeetingTime
  4808. cellL := row.AddCell()
  4809. cellL.Value = item.LastMeetingTime
  4810. cellM := row.AddCell()
  4811. cellM.Value = item.Duration
  4812. cellN := row.AddCell()
  4813. cellN.Value = item.LastMeetingTime
  4814. cellO := row.AddCell()
  4815. cellO.Value = item.MeetingTypeStr
  4816. cellP := row.AddCell()
  4817. cellP.Value = item.MeetingStatusStr
  4818. }
  4819. } else if source == 11 {
  4820. //标头
  4821. rowTitle := sheet.AddRow()
  4822. cellA := rowTitle.AddCell()
  4823. cellA.Value = "文章标题"
  4824. cellB := rowTitle.AddCell()
  4825. cellB.Value = "文章类型"
  4826. cellC := rowTitle.AddCell()
  4827. cellC.Value = "标签"
  4828. cellD := rowTitle.AddCell()
  4829. cellD.Value = "发布时间"
  4830. cellE := rowTitle.AddCell()
  4831. cellE.Value = "阅读时间"
  4832. cellF := rowTitle.AddCell()
  4833. cellF.Value = "阅读时长"
  4834. cellG := rowTitle.AddCell()
  4835. cellG.Value = "阅读来源"
  4836. for _, item := range list {
  4837. row := sheet.AddRow()
  4838. cellA := row.AddCell()
  4839. cellA.Value = item.Title
  4840. cellB := row.AddCell()
  4841. if item.SpecialType == 1 {
  4842. cellB.Value = "笔记"
  4843. } else {
  4844. cellB.Value = "观点"
  4845. }
  4846. cellC := row.AddCell()
  4847. cellC.Value = item.IndustryName
  4848. cellD := row.AddCell()
  4849. cellD.Value = item.PublishDate
  4850. cellE := row.AddCell()
  4851. cellE.Value = item.CreateTime
  4852. cellF := row.AddCell()
  4853. cellF.Value = item.StopTime
  4854. cellG := row.AddCell()
  4855. cellG.Value = cygxService.GetArticleSourcePlatformText(item.RegisterPlatform)
  4856. }
  4857. }
  4858. err = xlsxFile.Save(downLoadnFilePath)
  4859. if err != nil {
  4860. br.Msg = "保存文件失败"
  4861. br.ErrMsg = "保存文件失败"
  4862. return
  4863. }
  4864. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  4865. downloadFileName := excelName + randStr + ".xlsx"
  4866. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  4867. defer func() {
  4868. os.Remove(downLoadnFilePath)
  4869. }()
  4870. br.Ret = 200
  4871. br.Success = true
  4872. br.Msg = "获取成功"
  4873. }
  4874. // @Title 机构列表互动详情table栏
  4875. // @Description 机构列表互动详情table栏接口
  4876. // @Param ClassType query int true "列表类型,1:权益,2:研选,默认1"
  4877. // @Success 200 {object} cygx.CygxUserTableListRep
  4878. // @router /user/table/companyList [get]
  4879. func (this *UserController) TableCompanyList() {
  4880. br := new(models.BaseResponse).Init()
  4881. defer func() {
  4882. this.Data["json"] = br
  4883. this.ServeJSON()
  4884. }()
  4885. sysUser := this.SysUser
  4886. if sysUser == nil {
  4887. br.Msg = "请登录"
  4888. br.ErrMsg = "请登录,SysUser Is Empty"
  4889. br.Ret = 408
  4890. return
  4891. }
  4892. roleTypeCode := sysUser.RoleTypeCode
  4893. status := this.GetString("Status")
  4894. classType, _ := this.GetInt("ClassType", 1)
  4895. //流失
  4896. var lossCondition string
  4897. var condition string
  4898. //var lossPars []interface{}
  4899. //状态分类查询条件
  4900. var permissionCondition string
  4901. lossCondition = condition
  4902. //lossPars = pars
  4903. permissionCondition = condition
  4904. //流失客户统计
  4905. lossCondition += ` AND status='流失' `
  4906. //productId := services.GetProductId(roleTypeCode)
  4907. productId := 2
  4908. //权限控制
  4909. {
  4910. //如果不是超级管理员或者财务
  4911. if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && roleTypeCode != utils.ROLE_TYPE_CODE_FINANCE {
  4912. //如果是部门管理员
  4913. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  4914. condition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  4915. lossCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  4916. permissionCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  4917. } else {
  4918. condition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  4919. lossCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  4920. permissionCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  4921. if status == "全部" {
  4922. ////如果是筛选了流失客户状态
  4923. if sysUser.Authority <= 0 {
  4924. condition += ` AND (b.seller_id= '` + strconv.Itoa(sysUser.AdminId) + `' OR status='流失') `
  4925. permissionCondition += ` AND b.seller_id= ` + strconv.Itoa(sysUser.AdminId)
  4926. } else {
  4927. if sysUser.Authority == 1 {
  4928. condition += ` AND (b.department_id=` + strconv.Itoa(sysUser.DepartmentId) + ` OR status='流失')`
  4929. permissionCondition += ` AND b.department_id=` + strconv.Itoa(sysUser.DepartmentId)
  4930. }
  4931. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  4932. if status != utils.COMPANY_STATUS_LOSE {
  4933. condition += ` AND (b.group_id=` + strconv.Itoa(sysUser.GroupId) + ` OR status='流失') `
  4934. }
  4935. permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
  4936. }
  4937. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  4938. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  4939. if err != nil {
  4940. br.Msg = "获取失败"
  4941. br.ErrMsg = "查询父级id异常" + err.Error()
  4942. return
  4943. }
  4944. var ids []*string
  4945. if pid != nil {
  4946. if *pid != 0 {
  4947. //销售主管放在三级列表中
  4948. ids, err = company.GetGroupIdsByParentId(*pid)
  4949. if err != nil {
  4950. fmt.Println(err.Error())
  4951. }
  4952. } else {
  4953. //销售主管放在二级列表中
  4954. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  4955. if err != nil {
  4956. fmt.Println(err.Error())
  4957. }
  4958. }
  4959. }
  4960. var idSlice []string
  4961. var sid string
  4962. for _, id := range ids {
  4963. idSlice = append(idSlice, *id)
  4964. }
  4965. //加入父级groupId
  4966. if *pid > 0 {
  4967. idSlice = append(idSlice, strconv.Itoa(*pid))
  4968. } else {
  4969. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  4970. }
  4971. sid = strings.Join(idSlice, ",")
  4972. if len(sid) > 0 {
  4973. if status != utils.COMPANY_STATUS_LOSE {
  4974. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  4975. }
  4976. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  4977. } else {
  4978. if status != utils.COMPANY_STATUS_LOSE {
  4979. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  4980. }
  4981. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  4982. }
  4983. }
  4984. if sysUser.Authority == 4 {
  4985. if status != utils.COMPANY_STATUS_LOSE {
  4986. condition += ` AND (b.group_id =` + strconv.Itoa(sysUser.GroupId) + ` OR status='流失') `
  4987. //pars = append(pars, sysUser.GroupId)
  4988. }
  4989. permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
  4990. //permissionPars = append(permissionPars, sysUser.GroupId)
  4991. }
  4992. }
  4993. } else {
  4994. //如果没有筛选了流失客户状态,那么需要加客户归属条件加入到查询中去
  4995. if sysUser.Authority <= 0 {
  4996. if status != utils.COMPANY_STATUS_LOSE {
  4997. condition += ` AND b.seller_id=` + strconv.Itoa(sysUser.AdminId)
  4998. //pars = append(pars, sysUser.AdminId)
  4999. }
  5000. permissionCondition += ` AND b.seller_id=` + strconv.Itoa(sysUser.AdminId)
  5001. //permissionPars = append(permissionPars, sysUser.AdminId)
  5002. } else {
  5003. if sysUser.Authority == 1 {
  5004. if status != utils.COMPANY_STATUS_LOSE {
  5005. condition += ` AND b.department_id=` + strconv.Itoa(sysUser.DepartmentId)
  5006. //pars = append(pars, sysUser.DepartmentId)
  5007. }
  5008. permissionCondition += ` AND b.department_id=` + strconv.Itoa(sysUser.DepartmentId)
  5009. //permissionPars = append(permissionPars, sysUser.DepartmentId)
  5010. }
  5011. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  5012. if status != utils.COMPANY_STATUS_LOSE {
  5013. condition += ` AND b.group_id= ` + strconv.Itoa(sysUser.GroupId)
  5014. //pars = append(pars, sysUser.GroupId)
  5015. }
  5016. permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
  5017. //permissionPars = append(permissionPars, sysUser.GroupId)
  5018. }
  5019. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  5020. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  5021. if err != nil {
  5022. br.Msg = "获取失败"
  5023. br.ErrMsg = "查询父级id异常" + err.Error()
  5024. return
  5025. }
  5026. var ids []*string
  5027. if pid != nil {
  5028. if *pid != 0 {
  5029. //销售主管放在三级列表中
  5030. ids, err = company.GetGroupIdsByParentId(*pid)
  5031. if err != nil {
  5032. fmt.Println(err.Error())
  5033. }
  5034. } else {
  5035. //销售主管放在二级列表中
  5036. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  5037. if err != nil {
  5038. fmt.Println(err.Error())
  5039. }
  5040. }
  5041. }
  5042. var idSlice []string
  5043. var sid string
  5044. for _, id := range ids {
  5045. idSlice = append(idSlice, *id)
  5046. }
  5047. //加入父级groupId
  5048. if *pid > 0 {
  5049. idSlice = append(idSlice, strconv.Itoa(*pid))
  5050. } else {
  5051. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  5052. }
  5053. sid = strings.Join(idSlice, ",")
  5054. if len(sid) > 0 {
  5055. if status != utils.COMPANY_STATUS_LOSE {
  5056. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  5057. //pars = append(pars, sysUser.GroupId)
  5058. }
  5059. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  5060. } else {
  5061. if status != utils.COMPANY_STATUS_LOSE {
  5062. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  5063. //pars = append(pars, sysUser.GroupId)
  5064. }
  5065. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  5066. }
  5067. }
  5068. if sysUser.Authority == 4 {
  5069. if status != utils.COMPANY_STATUS_LOSE {
  5070. condition += ` AND b.group_id =` + strconv.Itoa(sysUser.GroupId)
  5071. //pars = append(pars, sysUser.GroupId)
  5072. }
  5073. permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
  5074. //permissionPars = append(permissionPars, sysUser.GroupId)
  5075. }
  5076. }
  5077. }
  5078. }
  5079. }
  5080. }
  5081. condition += ` AND b.status IN ('正式','试用','冻结') `
  5082. companyCondition := ` AND a.enabled=1 `
  5083. if condition != "" {
  5084. companyCondition += condition
  5085. }
  5086. resp := new(cygx.CygxUserTableListRep)
  5087. var isAdminRole bool
  5088. //如果不是管理员身份或者研究员身份则需要添加可见范围处理
  5089. if sysUser.Role == utils.ROLE_TYPE_CODE_ADMIN || sysUser.Role == utils.ROLE_TYPE_CODE_RESEARCHR {
  5090. isAdminRole = true
  5091. }
  5092. var pars []interface{}
  5093. lsitCompany, err := company.GetCompanyProductListBycondition(condition, pars)
  5094. if err != nil {
  5095. br.Msg = "获取失败"
  5096. br.ErrMsg = "获取数据失败,GetCompanyProductListBycondition Err:" + err.Error()
  5097. return
  5098. }
  5099. var companyIds []string
  5100. for _, v := range lsitCompany {
  5101. companyIds = append(companyIds, strconv.Itoa(v.CompanyId))
  5102. }
  5103. condition = " AND r.company_id IN (" + strings.Join(companyIds, ",") + ")"
  5104. condition += ` AND r.create_time < date_format(now(),'%Y-%m-%d') ` //过滤当天时间
  5105. conditionArtcile := condition //文章搜索条件
  5106. conditionActivityMeet := condition //活动到会搜索条件
  5107. conditionIndustryFllow := condition //产业关注搜索条件
  5108. conditionKeyWord := condition //关键词记录搜索条件
  5109. if classType == 1 {
  5110. conditionArtcile += " AND art.article_type_id = 0 "
  5111. conditionActivityMeet += " AND a.chart_permission_id != 31 "
  5112. conditionIndustryFllow += " AND m.chart_permission_id != 31 "
  5113. conditionKeyWord += " AND r.register_platform IN (1,2) "
  5114. } else {
  5115. conditionArtcile += " AND art.article_type_id > 0 "
  5116. conditionActivityMeet += " AND a.chart_permission_id = 31 "
  5117. conditionIndustryFllow += " AND m.chart_permission_id = 31 "
  5118. conditionKeyWord += " AND r.register_platform IN (5,6) "
  5119. }
  5120. var historyNum int //报告阅读列表
  5121. var activityNum int //活动互动记录
  5122. var triptotal int //专项调研
  5123. var articleCollect int //收藏的报告
  5124. var chartNum int //收藏图表
  5125. var industryFllowNum int //关注的产业
  5126. var departmentFollowNum int //关注的作者
  5127. var keyWordNum int //搜索
  5128. var roadshowTotal int //音视频播放
  5129. var tagNum int //首页标签点击
  5130. var yanxuanSpecialNum int //专栏文章阅读记录
  5131. var yanxuanSpecialCollectNum int //收藏的专栏文章
  5132. var yanxuanSpecialFollowNum int //关注的专栏作者
  5133. var feedbackNum int //交流反馈数量
  5134. var calendarMeetingNum int //1v1 路演数量
  5135. if isAdminRole {
  5136. historyNum, err = cygx.GetCygxArticleAndYanxuanRecordCount(conditionArtcile, pars)
  5137. if err != nil {
  5138. br.Msg = "获取信息失败"
  5139. br.ErrMsg = "获取用户阅读记录数量失败,Err:" + err.Error()
  5140. return
  5141. }
  5142. //获取参会总数
  5143. activityNum, err = cygx.GetActivityMeetByCompanyCount(conditionActivityMeet)
  5144. if err != nil {
  5145. br.Msg = "获取信息失败"
  5146. br.ErrMsg = "获取参会总数失败,Err:" + err.Error()
  5147. return
  5148. }
  5149. //获取用户收藏记录总数
  5150. articleCollect, err = cygx.GetCygxArticleCollectCountByCompany(conditionArtcile)
  5151. if err != nil {
  5152. br.Msg = "获取信息失败"
  5153. br.ErrMsg = "获取用户收藏记录总数失败,Err:" + err.Error()
  5154. return
  5155. }
  5156. //获取用户关注总数
  5157. industryFllowNum, err = cygx.GetCygxIndustryFllowCountByCompany(conditionIndustryFllow)
  5158. if err != nil {
  5159. br.Msg = "获取信息失败 "
  5160. br.ErrMsg = "获取用户关注总数失败,Err:" + err.Error()
  5161. return
  5162. }
  5163. //获取关注作者总数
  5164. departmentFollowNum, err = cygx.GetCygArticleDepartmentFollowCountByCompany(condition)
  5165. if err != nil {
  5166. br.Msg = "获取信息失败"
  5167. br.ErrMsg = "获取关注作者总数失败,Err:" + err.Error()
  5168. return
  5169. }
  5170. //获取搜索记录
  5171. keyWordNum, err = cygx.GetCygxSearchKeyWordCountBuCompany(conditionKeyWord)
  5172. if err != nil {
  5173. br.Msg = "获取信息失败"
  5174. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  5175. return
  5176. }
  5177. chartNum, err = cygx.GetChartCountByUserMobile(condition)
  5178. if err != nil {
  5179. br.Msg = "获取信息失败"
  5180. br.ErrMsg = "获取总数失败,Err:" + err.Error()
  5181. return
  5182. }
  5183. triptotal, err = cygx.GetCygxActivitySpecialTripCountByCompany(condition)
  5184. if err != nil {
  5185. br.Msg = "获取信息失败"
  5186. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  5187. return
  5188. }
  5189. roadshowTotal, err = cygx.GetCygxRoadshowCountByCompany(condition)
  5190. if err != nil {
  5191. br.Msg = "获取信息失败"
  5192. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  5193. return
  5194. }
  5195. tagNum, err = cygx.GetCygxTagHistoryCount(condition)
  5196. if err != nil {
  5197. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  5198. br.Msg = "获取搜索记录失败"
  5199. return
  5200. }
  5201. yanxuanSpecialNum, err = cygx.GetCygxYanxuanSpecialRecordCount(condition, pars)
  5202. if err != nil {
  5203. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  5204. br.Msg = "获取研选专栏阅读数量失败"
  5205. return
  5206. }
  5207. yanxuanSpecialCollectNum, err = cygx.GetCygxYanxuanSpecialCollectCount(condition, pars)
  5208. if err != nil {
  5209. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  5210. br.Msg = "获取收藏的专栏文章数量失败"
  5211. return
  5212. }
  5213. yanxuanSpecialFollowNum, err = cygx.GetCygxYanxuanSpecialFollowCount(condition, pars)
  5214. if err != nil {
  5215. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  5216. br.Msg = "获取关注的专栏作者数量失败"
  5217. return
  5218. }
  5219. feedbackNum, err = cygx.GetCygxUserFeedbackCountByUserModel(condition, pars)
  5220. if err != nil {
  5221. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  5222. br.Msg = "获取交流反馈数量失败"
  5223. return
  5224. }
  5225. calendarMeetingNum, err = roadshow.GetRsCalendarMeetingUserCountByUserModel(condition, pars)
  5226. if err != nil {
  5227. br.Msg = "获取信息失败"
  5228. br.ErrMsg = "GetRsCalendarMeetingUserCountByUserModel,Err:" + err.Error()
  5229. return
  5230. }
  5231. } else {
  5232. historyNum, err = cygx.GetCygxArticleAndYanxuanRecordCountWeekly(conditionArtcile, pars)
  5233. if err != nil {
  5234. br.Msg = "获取信息失败"
  5235. br.ErrMsg = "获取用户阅读记录数量失败,Err:" + err.Error()
  5236. return
  5237. }
  5238. //获取参会总数
  5239. activityNum, err = cygx.GetActivityMeetByCompanyCountWeekly(conditionActivityMeet)
  5240. if err != nil {
  5241. br.Msg = "获取信息失败"
  5242. br.ErrMsg = "获取参会总数失败,Err:" + err.Error()
  5243. return
  5244. }
  5245. //获取用户收藏记录总数
  5246. articleCollect, err = cygx.GetCygxArticleCollectCountByCompanyWeekly(conditionArtcile)
  5247. if err != nil {
  5248. br.Msg = "获取信息失败"
  5249. br.ErrMsg = "获取用户收藏记录总数失败,Err:" + err.Error()
  5250. return
  5251. }
  5252. //获取用户关注总数
  5253. industryFllowNum, err = cygx.GetCygxIndustryFllowCountByCompanyWeekly(conditionIndustryFllow)
  5254. if err != nil {
  5255. br.Msg = "获取信息失败 "
  5256. br.ErrMsg = "获取用户关注总数失败,Err:" + err.Error()
  5257. return
  5258. }
  5259. //获取关注作者总数
  5260. departmentFollowNum, err = cygx.GetCygArticleDepartmentFollowCountByCompanyWeekly(condition)
  5261. if err != nil {
  5262. br.Msg = "获取信息失败"
  5263. br.ErrMsg = "获取关注作者总数失败,Err:" + err.Error()
  5264. return
  5265. }
  5266. //获取搜索记录
  5267. keyWordNum, err = cygx.GetCygxSearchKeyWordCountBuCompanyWeekly(conditionKeyWord)
  5268. if err != nil {
  5269. br.Msg = "获取信息失败"
  5270. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  5271. return
  5272. }
  5273. chartNum, err = cygx.GetChartCountByUserMobileWeekly(condition)
  5274. if err != nil {
  5275. br.Msg = "获取信息失败"
  5276. br.ErrMsg = "获取总数失败,Err:" + err.Error()
  5277. return
  5278. }
  5279. triptotal, err = cygx.GetCygxActivitySpecialTripCountByCompanyWeekly(condition)
  5280. if err != nil {
  5281. br.Msg = "获取信息失败"
  5282. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  5283. return
  5284. }
  5285. roadshowTotal, err = cygx.GetCygxRoadshowCountByCompanyWeekly(condition)
  5286. if err != nil {
  5287. br.Msg = "获取信息失败"
  5288. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  5289. return
  5290. }
  5291. tagNum, err = cygx.GetCygxTagHistoryCountWeekly(condition)
  5292. if err != nil {
  5293. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  5294. br.Msg = "获取搜索记录失败"
  5295. return
  5296. }
  5297. yanxuanSpecialNum, err = cygx.GetCygxYanxuanSpecialRecordCountWeekly(condition, pars)
  5298. if err != nil {
  5299. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  5300. br.Msg = "获取研选专栏阅读数量失败"
  5301. return
  5302. }
  5303. yanxuanSpecialCollectNum, err = cygx.GetCygxYanxuanSpecialCollectCountWeekly(condition, pars)
  5304. if err != nil {
  5305. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  5306. br.Msg = "获取收藏的专栏文章数量失败"
  5307. return
  5308. }
  5309. yanxuanSpecialFollowNum, err = cygx.GetCygxYanxuanSpecialFollowCountWeekly(condition, pars)
  5310. if err != nil {
  5311. br.Msg = "获取关注的专栏作者数量失败"
  5312. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  5313. return
  5314. }
  5315. feedbackNum, err = cygx.GetCygxUserFeedbackCountByUserModelWeekly(condition, pars)
  5316. if err != nil {
  5317. br.Msg = "获取交流反馈数量失败"
  5318. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  5319. return
  5320. }
  5321. calendarMeetingNum, err = roadshow.GetRsCalendarMeetingUserCountByUserModelWeekly(condition, pars)
  5322. if err != nil {
  5323. br.Msg = "获取信息失败"
  5324. br.ErrMsg = "GetRsCalendarMeetingUserCountByUserModelWeekly,Err:" + err.Error()
  5325. return
  5326. }
  5327. }
  5328. if classType == 1 {
  5329. List := []*cygx.CygxUserTableRep{{PermissionName: "报告阅读列表", Source: 1, TotalNum: historyNum},
  5330. {PermissionName: "活动互动记录", Source: 2, TotalNum: activityNum},
  5331. {PermissionName: "专项调研", Source: 8, TotalNum: triptotal},
  5332. {PermissionName: "1v1路演", Source: 15, TotalNum: calendarMeetingNum},
  5333. {PermissionName: "收藏的报告", Source: 3, TotalNum: articleCollect},
  5334. {PermissionName: "收藏图表", Source: 4, TotalNum: chartNum},
  5335. {PermissionName: "关注的产业", Source: 5, TotalNum: industryFllowNum},
  5336. {PermissionName: "搜索", Source: 7, TotalNum: keyWordNum},
  5337. {PermissionName: "音视频播放", Source: 9, TotalNum: roadshowTotal},
  5338. {PermissionName: "首页标签点击", Source: 10, TotalNum: tagNum},
  5339. {PermissionName: "交流反馈", Source: 14, TotalNum: feedbackNum}}
  5340. resp.List = List
  5341. } else {
  5342. List := []*cygx.CygxUserTableRep{{PermissionName: "报告阅读列表", Source: 1, TotalNum: historyNum},
  5343. {PermissionName: "活动互动记录", Source: 2, TotalNum: activityNum},
  5344. {PermissionName: "收藏的报告", Source: 3, TotalNum: articleCollect},
  5345. {PermissionName: "关注的产业", Source: 5, TotalNum: industryFllowNum},
  5346. {PermissionName: "关注的作者", Source: 6, TotalNum: departmentFollowNum},
  5347. {PermissionName: "专栏文章阅读记录", Source: 11, TotalNum: yanxuanSpecialNum},
  5348. {PermissionName: "收藏的专栏文章", Source: 12, TotalNum: yanxuanSpecialCollectNum},
  5349. {PermissionName: "关注的专栏作者", Source: 13, TotalNum: yanxuanSpecialFollowNum},
  5350. {PermissionName: "搜索", Source: 7, TotalNum: keyWordNum}}
  5351. resp.List = List
  5352. }
  5353. br.Ret = 200
  5354. br.Success = true
  5355. br.Msg = "获取成功"
  5356. br.Data = resp
  5357. }
  5358. // @Title 添加/取消用户提醒
  5359. // @Description 添加/取消用户提醒
  5360. // @Param request body cygx.UserRemarAddReq true "type json string"
  5361. // @Success 200 新增成功
  5362. // @router /user/remind [post]
  5363. func (this *UserController) UserRemind() {
  5364. br := new(models.BaseResponse).Init()
  5365. defer func() {
  5366. this.Data["json"] = br
  5367. this.ServeJSON()
  5368. }()
  5369. sysUser := this.SysUser
  5370. if sysUser == nil {
  5371. br.Msg = "请登录"
  5372. br.ErrMsg = "请登录,SysUser Is Empty"
  5373. br.Ret = 408
  5374. return
  5375. }
  5376. var req cygx.UserRemarAddReq
  5377. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5378. if err != nil {
  5379. br.Msg = "参数解析异常!"
  5380. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5381. return
  5382. }
  5383. userId := req.UserId
  5384. sourceType := req.SourceType
  5385. doType := req.DoType
  5386. wxUser, err := cygx.GetUserAndCompanyNameList(userId)
  5387. if err != nil {
  5388. br.Msg = "设置互动提醒失败"
  5389. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  5390. return
  5391. }
  5392. if sourceType != 1 && sourceType != 2 {
  5393. br.Msg = "设置互动提醒失败"
  5394. br.ErrMsg = "设置互动提醒失败,sourceType:" + strconv.Itoa(sourceType)
  5395. return
  5396. }
  5397. if doType != 1 && doType != 2 {
  5398. br.Msg = "设置互动提醒失败"
  5399. br.ErrMsg = "设置互动提醒失败,doType:" + strconv.Itoa(doType)
  5400. return
  5401. }
  5402. count, err := cygx.GetCygxUserRemindCount(userId)
  5403. if err != nil {
  5404. br.Msg = "获取数据失败!"
  5405. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  5406. return
  5407. }
  5408. resp := new(cygx.CygxUserRemindResp)
  5409. if count <= 0 {
  5410. var items []*cygx.CygxUserRemind
  5411. if sourceType == 1 {
  5412. item := new(cygx.CygxUserRemind)
  5413. item.AdminId = sysUser.AdminId
  5414. item.AdminName = sysUser.RealName
  5415. item.UserId = userId
  5416. item.Mobile = wxUser.Mobile
  5417. item.Email = wxUser.Email
  5418. item.CompanyId = wxUser.CompanyId
  5419. item.CompanyName = wxUser.CompanyName
  5420. item.RealName = wxUser.RealName
  5421. item.CreateTime = time.Now()
  5422. item.ModifyTime = time.Now()
  5423. items = append(items, item)
  5424. } else {
  5425. //获取机构下所有的用户
  5426. listUser, err := models.GetWxUserListCompanyId(wxUser.CompanyId)
  5427. if err != nil {
  5428. br.Msg = "获取数据失败!"
  5429. br.ErrMsg = "获取数据失败,GetWxUserListCompanyId Err:" + err.Error()
  5430. return
  5431. }
  5432. //获取已经添加消息提醒的
  5433. listUserRemind, err := cygx.GetCygxUserRemindListByCompanyId(wxUser.CompanyId)
  5434. if err != nil {
  5435. br.Msg = "获取数据失败!"
  5436. br.ErrMsg = "获取数据失败,GetCygxUserRemindListByCompanyId Err:" + err.Error()
  5437. return
  5438. }
  5439. mapUserRemind := make(map[int]bool)
  5440. for _, v := range listUserRemind {
  5441. mapUserRemind[v.UserId] = true
  5442. }
  5443. for _, v := range listUser {
  5444. //如果已经添加了提醒的用户就不做添加处理
  5445. if mapUserRemind[v.UserId] {
  5446. continue
  5447. }
  5448. item := new(cygx.CygxUserRemind)
  5449. item.AdminId = sysUser.AdminId
  5450. item.AdminName = sysUser.RealName
  5451. item.UserId = v.UserId
  5452. item.Mobile = v.Mobile
  5453. item.Email = v.Email
  5454. item.CompanyId = v.CompanyId
  5455. item.CompanyName = v.CompanyName
  5456. item.RealName = v.RealName
  5457. item.CreateTime = time.Now()
  5458. item.ModifyTime = time.Now()
  5459. items = append(items, item)
  5460. }
  5461. }
  5462. //批量加入
  5463. err = cygx.AddCygxUserRemindMulti(items)
  5464. if err != nil {
  5465. br.Msg = "添加失败"
  5466. br.ErrMsg = "添加失败,Err:" + err.Error()
  5467. return
  5468. }
  5469. br.Msg = "收藏成功"
  5470. resp.Status = 1
  5471. } else {
  5472. if sourceType == 1 {
  5473. err = cygx.RemoveCygxUserRemind(userId) //取消个人提醒
  5474. } else {
  5475. err = cygx.RemoveCygxUserRemindByCompanyId(wxUser.CompanyId) //取消整个机构提醒
  5476. }
  5477. if err != nil {
  5478. br.Msg = "取消失败"
  5479. br.ErrMsg = "取消失败,Err:" + err.Error()
  5480. return
  5481. }
  5482. br.Msg = "已取消收藏"
  5483. resp.Status = 2
  5484. }
  5485. br.Ret = 200
  5486. br.Success = true
  5487. br.Data = resp
  5488. }
  5489. // exportListRsCalendar 1v1路演导出Excel
  5490. func exportListRsCalendar(this *UserController, list []*cygx.UserInteraction, excelType int, br *models.BaseResponse) {
  5491. dir, err := os.Executable()
  5492. exPath := filepath.Dir(dir)
  5493. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  5494. xlsxFile := xlsx.NewFile()
  5495. if err != nil {
  5496. br.Msg = "生成文件失败"
  5497. br.ErrMsg = "生成文件失败"
  5498. return
  5499. }
  5500. style := xlsx.NewStyle()
  5501. border := xlsx.NewBorder("thin", "thin", "thin", "thin")
  5502. alignment := xlsx.Alignment{
  5503. Horizontal: "center",
  5504. Vertical: "center",
  5505. WrapText: true,
  5506. }
  5507. redStyle := xlsx.NewStyle()
  5508. redStyle.Alignment = alignment
  5509. redStyle.ApplyAlignment = true
  5510. redStyle.Font.Color = "ff0000"
  5511. redStyle.Border = *border
  5512. style.Alignment = alignment
  5513. style.ApplyAlignment = true
  5514. sheel, err := xlsxFile.AddSheet("1V1路演")
  5515. if err != nil {
  5516. br.Msg = "新增Sheet失败"
  5517. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  5518. return
  5519. }
  5520. sheel.SetColWidth(0, 0, 30)
  5521. sheel.SetColWidth(1, 1, 15)
  5522. sheel.SetColWidth(2, 2, 15)
  5523. sheel.SetColWidth(3, 3, 18)
  5524. titleRow := sheel.AddRow()
  5525. if excelType > 2 {
  5526. cellA := titleRow.AddCell()
  5527. cellA.SetStyle(style)
  5528. cellA.SetValue("客户名称")
  5529. }
  5530. if excelType > 1 {
  5531. cellB := titleRow.AddCell()
  5532. cellB.SetStyle(style)
  5533. cellB.SetValue("姓名")
  5534. cellC := titleRow.AddCell()
  5535. cellC.SetStyle(style)
  5536. cellC.SetValue("手机号")
  5537. }
  5538. cellD := titleRow.AddCell()
  5539. cellD.SetStyle(style)
  5540. cellD.SetValue("路演时间")
  5541. cellE := titleRow.AddCell()
  5542. cellE.SetStyle(style)
  5543. cellE.SetValue("研究员")
  5544. cellF := titleRow.AddCell()
  5545. cellF.SetStyle(style)
  5546. cellF.SetValue("路演形式")
  5547. cellG := titleRow.AddCell()
  5548. cellG.SetStyle(style)
  5549. cellG.SetValue("主题标签")
  5550. for _, v := range list {
  5551. dataRow := sheel.AddRow()
  5552. dataRow.SetHeight(20)
  5553. if excelType > 2 {
  5554. cellAData := dataRow.AddCell()
  5555. cellAData.SetStyle(style)
  5556. cellAData.Value = v.CompanyName
  5557. }
  5558. if excelType > 1 {
  5559. cellBData := dataRow.AddCell()
  5560. cellBData.SetStyle(style)
  5561. cellBData.Value = v.RealName
  5562. cellCData := dataRow.AddCell()
  5563. cellCData.SetStyle(style)
  5564. cellCData.Value = v.Mobile
  5565. }
  5566. cellDData := dataRow.AddCell()
  5567. cellDData.SetStyle(style)
  5568. cellDData.Value = v.ActivityTimeText
  5569. cellEData := dataRow.AddCell()
  5570. cellEData.SetStyle(style)
  5571. cellEData.Value = v.ResearcherName
  5572. cellFData := dataRow.AddCell()
  5573. cellFData.SetStyle(style)
  5574. if v.ActivityType == 1 {
  5575. cellFData.Value = "线上"
  5576. } else {
  5577. cellFData.Value = "线下"
  5578. }
  5579. cellGData := dataRow.AddCell()
  5580. cellGData.SetStyle(style)
  5581. cellGData.Value = v.LabelKeyWord
  5582. }
  5583. err = xlsxFile.Save(downLoadnFilePath)
  5584. if err != nil {
  5585. br.Msg = "保存文件失败"
  5586. br.ErrMsg = "保存文件失败"
  5587. return
  5588. }
  5589. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  5590. downloadFileName := "1V1路演导出数据_" + randStr + ".xlsx"
  5591. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  5592. defer func() {
  5593. os.Remove(downLoadnFilePath)
  5594. }()
  5595. br.Ret = 200
  5596. br.Success = true
  5597. br.Msg = "导出成功"
  5598. }
  5599. // exportListArticle 文章阅读数据导出
  5600. func exportListArticle(this *UserController, list []*cygx.UserInteraction, excelType int, br *models.BaseResponse) {
  5601. //创建excel
  5602. dir, err := os.Executable()
  5603. exPath := filepath.Dir(dir)
  5604. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  5605. xlsxFile := xlsx.NewFile()
  5606. if err != nil {
  5607. br.Msg = "生成文件失败"
  5608. br.ErrMsg = "生成文件失败"
  5609. return
  5610. }
  5611. style := xlsx.NewStyle()
  5612. alignment := xlsx.Alignment{
  5613. Horizontal: "center",
  5614. Vertical: "center",
  5615. WrapText: true,
  5616. }
  5617. style.Alignment = alignment
  5618. style.ApplyAlignment = true
  5619. sheet, err := xlsxFile.AddSheet("报告阅读列表")
  5620. if err != nil {
  5621. br.Msg = "新增Sheet失败"
  5622. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  5623. return
  5624. }
  5625. //标头
  5626. rowTitle := sheet.AddRow()
  5627. if excelType > 2 {
  5628. cellA := rowTitle.AddCell()
  5629. cellA.Value = "客户名称"
  5630. cellB := rowTitle.AddCell()
  5631. cellB.Value = "所属销售"
  5632. }
  5633. if excelType > 1 {
  5634. cellC := rowTitle.AddCell()
  5635. cellC.Value = "姓名"
  5636. cellD := rowTitle.AddCell()
  5637. cellD.Value = "手机号"
  5638. }
  5639. cellE := rowTitle.AddCell()
  5640. cellE.Value = "报告标题"
  5641. cellF := rowTitle.AddCell()
  5642. cellF.Value = "所属行业"
  5643. cellG := rowTitle.AddCell()
  5644. cellG.Value = "所属产业"
  5645. cellH := rowTitle.AddCell()
  5646. cellH.Value = "关联标的"
  5647. cellI := rowTitle.AddCell()
  5648. cellI.Value = "发布时间"
  5649. cellJ := rowTitle.AddCell()
  5650. cellJ.Value = "阅读时间"
  5651. cellK := rowTitle.AddCell()
  5652. cellK.Value = "阅读时长"
  5653. for _, item := range list {
  5654. row := sheet.AddRow()
  5655. if excelType > 2 {
  5656. cellA := row.AddCell()
  5657. cellA.Value = item.CompanyName
  5658. cellB := row.AddCell()
  5659. cellB.Value = item.SellerName
  5660. }
  5661. if excelType > 1 {
  5662. cellC := row.AddCell()
  5663. cellC.Value = item.RealName
  5664. cellD := row.AddCell()
  5665. cellD.Value = item.Mobile
  5666. }
  5667. cellEData := row.AddCell()
  5668. cellEData.Value = item.Title
  5669. cellFData := row.AddCell()
  5670. cellFData.Value = item.PermissionName
  5671. cellGData := row.AddCell()
  5672. cellGData.Value = item.IndustryName
  5673. cellHData := row.AddCell()
  5674. cellHData.Value = item.SubjectNameStr
  5675. cellIData := row.AddCell()
  5676. cellIData.Value = item.PublishDate
  5677. cellJData := row.AddCell()
  5678. cellJData.Value = item.CreateTime
  5679. cellKData := row.AddCell()
  5680. cellKData.Value = item.StopTime
  5681. }
  5682. err = xlsxFile.Save(downLoadnFilePath)
  5683. if err != nil {
  5684. br.Msg = "保存文件失败"
  5685. br.ErrMsg = "保存文件失败"
  5686. return
  5687. }
  5688. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  5689. downloadFileName := "报告阅读列表导出数据_" + randStr + ".xlsx"
  5690. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  5691. defer func() {
  5692. os.Remove(downLoadnFilePath)
  5693. }()
  5694. br.Ret = 200
  5695. br.Success = true
  5696. br.Msg = "导出成功"
  5697. }
  5698. // exportListArticle 文章阅读数据导出
  5699. func exportListActivity(this *UserController, list []*cygx.UserInteraction, excelType int, br *models.BaseResponse) {
  5700. //创建excel
  5701. dir, err := os.Executable()
  5702. exPath := filepath.Dir(dir)
  5703. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  5704. xlsxFile := xlsx.NewFile()
  5705. if err != nil {
  5706. br.Msg = "生成文件失败"
  5707. br.ErrMsg = "生成文件失败"
  5708. return
  5709. }
  5710. style := xlsx.NewStyle()
  5711. alignment := xlsx.Alignment{
  5712. Horizontal: "center",
  5713. Vertical: "center",
  5714. WrapText: true,
  5715. }
  5716. style.Alignment = alignment
  5717. style.ApplyAlignment = true
  5718. sheet, err := xlsxFile.AddSheet("客户参会记录")
  5719. if err != nil {
  5720. br.Msg = "新增Sheet失败"
  5721. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  5722. return
  5723. }
  5724. //标头
  5725. rowTitle := sheet.AddRow()
  5726. if excelType > 2 {
  5727. cellA := rowTitle.AddCell()
  5728. cellA.Value = "客户名称"
  5729. cellB := rowTitle.AddCell()
  5730. cellB.Value = "所属销售"
  5731. }
  5732. if excelType > 1 {
  5733. cellC := rowTitle.AddCell()
  5734. cellC.Value = "姓名"
  5735. cellD := rowTitle.AddCell()
  5736. cellD.Value = "手机号"
  5737. }
  5738. cellE := rowTitle.AddCell()
  5739. cellE.Value = "活动名称"
  5740. cellF := rowTitle.AddCell()
  5741. cellF.Value = "所属行业"
  5742. cellG := rowTitle.AddCell()
  5743. cellG.Value = "活动类型"
  5744. cellH := rowTitle.AddCell()
  5745. cellH.Value = "活动主题"
  5746. cellI := rowTitle.AddCell()
  5747. cellI.Value = "活动时间"
  5748. cellJ := rowTitle.AddCell()
  5749. cellJ.Value = "是否到会"
  5750. cellK := rowTitle.AddCell()
  5751. cellK.Value = "首次入会时间"
  5752. cellL := rowTitle.AddCell()
  5753. cellL.Value = "最后退出时间"
  5754. cellM := rowTitle.AddCell()
  5755. cellM.Value = "参与总时长"
  5756. cellN := rowTitle.AddCell()
  5757. cellN.Value = "参会方式"
  5758. cellO := rowTitle.AddCell()
  5759. cellO.Value = "参会权鉴"
  5760. cellP := rowTitle.AddCell()
  5761. cellP.Value = "参会状态"
  5762. for _, item := range list {
  5763. row := sheet.AddRow()
  5764. if excelType > 2 {
  5765. cellAData := row.AddCell()
  5766. cellAData.Value = item.CompanyName
  5767. cellBData := row.AddCell()
  5768. cellBData.Value = item.SellerName
  5769. }
  5770. if excelType > 1 {
  5771. cellCData := row.AddCell()
  5772. cellCData.Value = item.RealName
  5773. cellDData := row.AddCell()
  5774. cellDData.Value = item.Mobile
  5775. }
  5776. cellEData := row.AddCell()
  5777. cellEData.Value = item.ActivityName
  5778. cellFData := row.AddCell()
  5779. cellFData.Value = item.PermissionName
  5780. cellGData := row.AddCell()
  5781. cellGData.Value = item.ActivityTypeName
  5782. cellHData := row.AddCell()
  5783. cellHData.Value = item.Label
  5784. cellIData := row.AddCell()
  5785. cellIData.Value = item.ActivityTime
  5786. cellJData := row.AddCell()
  5787. if item.IsMeeting == 1 {
  5788. cellJData.Value = "到会"
  5789. } else {
  5790. cellJData.Value = "未到会"
  5791. }
  5792. cellKData := row.AddCell()
  5793. cellKData.Value = item.FirstMeetingTime
  5794. cellLData := row.AddCell()
  5795. cellLData.Value = item.LastMeetingTime
  5796. cellMData := row.AddCell()
  5797. cellMData.Value = item.Duration
  5798. cellNData := row.AddCell()
  5799. cellNData.Value = item.LastMeetingTime
  5800. cellOData := row.AddCell()
  5801. cellOData.Value = item.MeetingTypeStr
  5802. cellPData := row.AddCell()
  5803. cellPData.Value = item.MeetingStatusStr
  5804. }
  5805. err = xlsxFile.Save(downLoadnFilePath)
  5806. if err != nil {
  5807. br.Msg = "保存文件失败"
  5808. br.ErrMsg = "保存文件失败"
  5809. return
  5810. }
  5811. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  5812. downloadFileName := "客户参会记录导出数据_" + randStr + ".xlsx"
  5813. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  5814. defer func() {
  5815. os.Remove(downLoadnFilePath)
  5816. }()
  5817. br.Ret = 200
  5818. br.Success = true
  5819. br.Msg = "导出成功"
  5820. }
  5821. // exportListYanxuanSpecial 研选专栏阅读记录
  5822. func exportListYanxuanSpecial(this *UserController, list []*cygx.UserInteraction, excelType int, br *models.BaseResponse) {
  5823. //创建excel
  5824. dir, err := os.Executable()
  5825. exPath := filepath.Dir(dir)
  5826. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  5827. xlsxFile := xlsx.NewFile()
  5828. if err != nil {
  5829. br.Msg = "生成文件失败"
  5830. br.ErrMsg = "生成文件失败"
  5831. return
  5832. }
  5833. style := xlsx.NewStyle()
  5834. alignment := xlsx.Alignment{
  5835. Horizontal: "center",
  5836. Vertical: "center",
  5837. WrapText: true,
  5838. }
  5839. style.Alignment = alignment
  5840. style.ApplyAlignment = true
  5841. sheet, err := xlsxFile.AddSheet("客户参会记录")
  5842. if err != nil {
  5843. br.Msg = "新增Sheet失败"
  5844. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  5845. return
  5846. }
  5847. //标头
  5848. rowTitle := sheet.AddRow()
  5849. if excelType > 2 {
  5850. cellAy := rowTitle.AddCell()
  5851. cellAy.Value = "客户名称"
  5852. cellBy := rowTitle.AddCell()
  5853. cellBy.Value = "所属销售"
  5854. }
  5855. if excelType > 1 {
  5856. cellC := rowTitle.AddCell()
  5857. cellC.Value = "姓名"
  5858. cellD := rowTitle.AddCell()
  5859. cellD.Value = "手机号"
  5860. }
  5861. cellA := rowTitle.AddCell()
  5862. cellA.Value = "文章标题"
  5863. cellB := rowTitle.AddCell()
  5864. cellB.Value = "文章类型"
  5865. cellC := rowTitle.AddCell()
  5866. cellC.Value = "标签"
  5867. cellD := rowTitle.AddCell()
  5868. cellD.Value = "发布时间"
  5869. cellE := rowTitle.AddCell()
  5870. cellE.Value = "阅读时间"
  5871. cellF := rowTitle.AddCell()
  5872. cellF.Value = "阅读时长"
  5873. cellG := rowTitle.AddCell()
  5874. cellG.Value = "阅读来源"
  5875. for _, item := range list {
  5876. row := sheet.AddRow()
  5877. if excelType > 2 {
  5878. cellADatay := row.AddCell()
  5879. cellADatay.Value = item.CompanyName
  5880. cellBDatay := row.AddCell()
  5881. cellBDatay.Value = item.SellerName
  5882. }
  5883. if excelType > 1 {
  5884. cellCData := row.AddCell()
  5885. cellCData.Value = item.RealName
  5886. cellDData := row.AddCell()
  5887. cellDData.Value = item.Mobile
  5888. }
  5889. cellAData := row.AddCell()
  5890. cellAData.Value = item.Title
  5891. cellBData := row.AddCell()
  5892. if item.SpecialType == 1 {
  5893. cellBData.Value = "笔记"
  5894. } else {
  5895. cellBData.Value = "观点"
  5896. }
  5897. cellCData := row.AddCell()
  5898. cellCData.Value = item.IndustryName
  5899. cellDData := row.AddCell()
  5900. cellDData.Value = item.PublishDate
  5901. cellEData := row.AddCell()
  5902. cellEData.Value = item.CreateTime
  5903. cellFData := row.AddCell()
  5904. cellFData.Value = item.StopTime
  5905. cellGData := row.AddCell()
  5906. cellGData.Value = cygxService.GetArticleSourcePlatformText(item.RegisterPlatform)
  5907. }
  5908. err = xlsxFile.Save(downLoadnFilePath)
  5909. if err != nil {
  5910. br.Msg = "保存文件失败"
  5911. br.ErrMsg = "保存文件失败"
  5912. return
  5913. }
  5914. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  5915. downloadFileName := "客户参会记录导出数据_" + randStr + ".xlsx"
  5916. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  5917. defer func() {
  5918. os.Remove(downLoadnFilePath)
  5919. }()
  5920. br.Ret = 200
  5921. br.Success = true
  5922. br.Msg = "导出成功"
  5923. }