user.go 184 KB

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