user.go 193 KB

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