company_user.go 204 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. "github.com/tealeg/xlsx"
  8. "hongze/hz_crm_api/models"
  9. "hongze/hz_crm_api/models/advisory"
  10. "hongze/hz_crm_api/models/company"
  11. "hongze/hz_crm_api/models/company_user"
  12. "hongze/hz_crm_api/models/company_user/request"
  13. "hongze/hz_crm_api/models/company_user/response"
  14. "hongze/hz_crm_api/models/cygx"
  15. "hongze/hz_crm_api/models/system"
  16. "hongze/hz_crm_api/models/yb"
  17. "hongze/hz_crm_api/services"
  18. cygxService "hongze/hz_crm_api/services/cygx"
  19. "hongze/hz_crm_api/services/elastic"
  20. "hongze/hz_crm_api/utils"
  21. "os"
  22. "path"
  23. "path/filepath"
  24. "strconv"
  25. "strings"
  26. "time"
  27. "unicode/utf8"
  28. )
  29. // 客户联系人管理
  30. type CompanyUserController struct {
  31. BaseAuthController
  32. }
  33. // @Title 新增客户联系人
  34. // @Description 新增客户联系人接口
  35. // @Param request body company.AddUserReq true "type json string"
  36. // @router /user/add [post]
  37. func (this *CompanyUserController) AddUser() {
  38. br := new(models.BaseResponse).Init()
  39. defer func() {
  40. this.Data["json"] = br
  41. this.ServeJSON()
  42. }()
  43. sysUser := this.SysUser
  44. if sysUser == nil {
  45. br.Msg = "请登录"
  46. br.ErrMsg = "请登录,SysUser Is Empty"
  47. br.Ret = 408
  48. return
  49. }
  50. var req company.AddUserReq
  51. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  52. if err != nil {
  53. br.Msg = "参数解析异常!"
  54. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  55. return
  56. }
  57. if req.RealName == "" {
  58. br.Msg = "请填写姓名"
  59. br.IsSendEmail = false
  60. return
  61. }
  62. //空格移除
  63. req.MobileOne = utils.TrimStr(req.MobileOne)
  64. req.MobileTwo = utils.TrimStr(req.MobileTwo)
  65. req.Email = utils.TrimStr(req.Email)
  66. req.RealName = utils.TrimStr(req.RealName)
  67. //判断该手机号、邮箱是否已经添加,如果已经添加,那么就不再添加
  68. var key string
  69. if req.MobileOne != "" {
  70. key = "wx_user:mobile:" + req.MobileOne
  71. } else {
  72. key = "wx_user:email:" + req.Email
  73. }
  74. isHas := utils.Rc.IsExist(key)
  75. if isHas == true {
  76. br.Msg = "重复添加"
  77. return
  78. } else {
  79. //设置3分钟缓存,不允许重复添加
  80. utils.Rc.SetNX(key, 1, time.Second*300)
  81. //添加完成删除对应的缓存
  82. defer utils.Rc.Delete(key)
  83. }
  84. source := req.Source
  85. if source == "" {
  86. br.Msg = "没有来源"
  87. return
  88. }
  89. regionType := req.RegionType //区域来源
  90. productId := services.GetProductId(sysUser.RoleTypeCode)
  91. //操作员的产品权限
  92. companyProductList := make([]*company.CompanyProduct, 0)
  93. var companyInfo *company.Company
  94. var e error
  95. if req.CompanyId > 0 {
  96. companyInfo, e = company.GetCompanyById(req.CompanyId)
  97. if e != nil {
  98. br.Msg = "客户信息有误"
  99. br.ErrMsg = "获取客户信息失败, Err: " + e.Error()
  100. return
  101. }
  102. }
  103. //权益类客户,邮箱必填(2021-03-22 13:32:59修改)
  104. if productId == 1 || regionType == "国内" { //ficc类客户
  105. if req.MobileOne == "" && req.Email == "" {
  106. br.Msg = "请输入手机号或邮箱"
  107. br.IsSendEmail = false
  108. return
  109. }
  110. } else if productId == 2 { //权益类客户
  111. if req.MobileOne == "" {
  112. br.Msg = "请输入手机号"
  113. br.ErrMsg = "请输入手机号"
  114. br.IsSendEmail = false
  115. return
  116. }
  117. if req.Email == "" {
  118. br.Msg = "请输入邮箱"
  119. br.ErrMsg = "请输入邮箱"
  120. br.IsSendEmail = false
  121. return
  122. }
  123. } else {
  124. //如果是管理员账户,那么需要从企业信息里面去获取所属类型客户了
  125. //获取企业客户信息
  126. if req.Source == "add_custom" {
  127. //添加客户时新增联系人
  128. } else if req.Source == "pick_custom" {
  129. //领取客户时添加联系人
  130. br.ErrMsg = "管理员账户不允许领取客户"
  131. br.Msg = "来源异常"
  132. return
  133. } else if req.Source == "add_user" {
  134. //普通类型添加客户
  135. //companyInfo, err := company.GetCompanyById(req.CompanyId)
  136. //if err != nil {
  137. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  138. // br.Msg = "获取客户信息失败"
  139. // return
  140. //}
  141. //手机号、邮箱校验(必填一个)
  142. if req.MobileOne == "" && req.Email == "" {
  143. br.Msg = "请输入手机号或邮箱"
  144. br.IsSendEmail = false
  145. return
  146. }
  147. //shareSellerId = companyInfo.ShareSellerId
  148. //获取当前操作员产品权限
  149. tmpCompanyProductList, productErr := getSysCompanyProductList(productId, req.CompanyId)
  150. if productErr != nil {
  151. br.Msg = "新增失败"
  152. br.ErrMsg = "新增失败,获取当前操作员产品权限异常,Err:" + productErr.Error()
  153. return
  154. }
  155. if tmpCompanyProductList == nil {
  156. br.Msg = "新增失败"
  157. br.ErrMsg = "新增失败,获取当前操作员找不到产品权限"
  158. return
  159. }
  160. for _, v := range tmpCompanyProductList {
  161. //权益(海外)客户,需要有提示
  162. if v.ProductId == 2 && companyInfo.RegionType == "海外" {
  163. if req.MobileOne == "" {
  164. br.Msg = "请输入手机号"
  165. }
  166. if req.Email == "" {
  167. br.Msg = "请输入邮箱"
  168. br.ErrMsg = "请输入邮箱"
  169. return
  170. }
  171. }
  172. }
  173. companyProductList = tmpCompanyProductList
  174. } else {
  175. br.ErrMsg = "来源异常"
  176. br.Msg = "来源异常"
  177. return
  178. }
  179. }
  180. if productId != 0 {
  181. if req.Source == "add_custom" {
  182. //添加客户时新增联系人
  183. } else if req.Source == "pick_custom" {
  184. //领取客户时添加联系人
  185. tmpCompanyProduct := &company.CompanyProduct{
  186. CompanyId: req.CompanyId,
  187. ProductId: productId,
  188. ProductName: sysUser.RoleName,
  189. SellerId: sysUser.AdminId,
  190. SellerName: sysUser.RealName,
  191. GroupId: sysUser.GroupId,
  192. DepartmentId: sysUser.DepartmentId,
  193. }
  194. companyProductList = append(companyProductList, tmpCompanyProduct)
  195. } else if req.Source == "add_user" {
  196. shareSellerId := 0
  197. if req.CompanyId > 0 {
  198. item, e := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  199. if e != nil {
  200. br.Msg = "客户信息有误"
  201. br.ErrMsg = "获取客户信息失败, Err: " + e.Error()
  202. return
  203. }
  204. shareSellerId = item.ShareSellerId
  205. }
  206. //获取当前操作员产品权限
  207. tmpCompanyProductList, productErr := getSysCompanyProductList(productId, req.CompanyId)
  208. if productErr != nil {
  209. br.Msg = "新增失败"
  210. br.ErrMsg = "新增失败,获取当前操作员产品权限异常,Err:" + productErr.Error()
  211. return
  212. }
  213. if tmpCompanyProductList == nil {
  214. br.Msg = "新增失败"
  215. br.ErrMsg = "新增失败,获取当前操作员找不到产品权限"
  216. return
  217. }
  218. companyProductList = tmpCompanyProductList
  219. //操作权限校验
  220. for _, v := range tmpCompanyProductList {
  221. companyUserStatus := services.CheckCompanyUserButton(sysUser.RoleTypeCode, v.SellerId, sysUser.AdminId, v.ProductId, shareSellerId, v.Status)
  222. if companyUserStatus == false {
  223. br.Msg = "没有操作权限"
  224. br.ErrMsg = "没有操作权限"
  225. br.IsSendEmail = false
  226. return
  227. }
  228. }
  229. }
  230. } else {
  231. //超管
  232. if req.Source != "add_custom" {
  233. //不是添加客户的时候添加的联系人
  234. tmpCompanyProductList, productErr := getSysCompanyProductList(productId, req.CompanyId)
  235. if productErr != nil {
  236. br.Msg = "新增失败"
  237. br.ErrMsg = "新增失败,获取当前操作员产品权限异常,Err:" + productErr.Error()
  238. return
  239. }
  240. if tmpCompanyProductList == nil {
  241. br.Msg = "新增失败"
  242. br.ErrMsg = "新增失败,获取当前操作员找不到产品权限"
  243. return
  244. }
  245. companyProductList = tmpCompanyProductList
  246. }
  247. }
  248. userCount, err := company.GetCompanyUserCount(req.CompanyId)
  249. if err != nil {
  250. br.Msg = "新增失败"
  251. br.ErrMsg = "判断联系人数量失败,Err:" + err.Error()
  252. return
  253. }
  254. if userCount == 0 {
  255. if req.BusinessCardUrl == "" {
  256. br.Msg = "请上传名片"
  257. br.IsSendEmail = false
  258. return
  259. }
  260. }
  261. //systemUser models.Company.CompanyUser
  262. //var sysemUser company.CompanyUser
  263. //校验主手机号
  264. if req.MobileOne != "" {
  265. mobileOneItem, err := company.GetUserCountByMobile(req.MobileOne)
  266. if err != nil && err.Error() == utils.ErrNoRow() {
  267. mobileOneItem, err = company.CheckCompanyUserCountByMobileTwo(req.MobileOne)
  268. if err != nil && err.Error() != utils.ErrNoRow() {
  269. br.Msg = "新增失败"
  270. br.ErrMsg = "判断手机号1是否存在,Err:" + err.Error()
  271. return
  272. }
  273. }
  274. if mobileOneItem != nil {
  275. if mobileOneItem.UserId > 0 {
  276. //如果有传入客户编号,且客户编号与该查出来的用户编号一致的情况下
  277. if req.CompanyId > 0 {
  278. //获取联系人分组信息
  279. userSellerGroupInfo, err := models.GetUserGroupSellerByUserId(int(mobileOneItem.UserId))
  280. if err != nil && err.Error() != utils.ErrNoRow() {
  281. br.Msg = "查询信息异常"
  282. br.Success = true
  283. br.Data = mobileOneItem
  284. br.IsSendEmail = false
  285. br.Ret = 600
  286. return
  287. }
  288. if req.CompanyId == mobileOneItem.CompanyId {
  289. //如果是该客户下的用户,那么判断该用户与当前账号是否存在关系,如果没有关系,那么直接添加关系后直接返回
  290. if len(companyProductList) > 0 {
  291. isHas := checkUserSellerRelation(companyProductList, mobileOneItem, &req, br)
  292. if isHas == false {
  293. return
  294. }
  295. }
  296. //修改返回给前端用户的信息
  297. if userSellerGroupInfo != nil {
  298. mobileOneItem.SellerRealName = userSellerGroupInfo.SellerRealName
  299. mobileOneItem.Status = userSellerGroupInfo.Status
  300. }
  301. br.Msg = "手机号1已存在"
  302. br.Success = true
  303. br.Data = mobileOneItem
  304. br.IsSendEmail = false
  305. br.Ret = 600
  306. return
  307. } else {
  308. hasMove := true //是否可移动
  309. //如果是大于 1 的客户,那么就是非潜在客户,需要去查询对应的销售
  310. if mobileOneItem.CompanyId > 1 {
  311. //获取联系人分组信息
  312. userSellerGroupInfoList, err := models.GetUserGroupSellersByUserId(int(mobileOneItem.UserId))
  313. //根据分组校验
  314. if err == nil && len(userSellerGroupInfoList) > 0 {
  315. sellerMap := make(map[int]string) //销售信息map
  316. sellerNameSlice := make([]string, 0) //销售姓名切片
  317. statusNameSlice := make([]string, 0) //客户状态姓名切片
  318. for _, v := range userSellerGroupInfoList {
  319. if v.Status != utils.COMPANY_STATUS_LOSE && v.Status != utils.COMPANY_STATUS_FOREVER && hasMove == true {
  320. hasMove = false
  321. }
  322. statusNameSlice = append(statusNameSlice, v.Status)
  323. if _, ok := sellerMap[v.SellerId]; ok {
  324. continue
  325. }
  326. sellerMap[v.SellerId] = v.SellerRealName
  327. sellerNameSlice = append(sellerNameSlice, v.SellerRealName)
  328. }
  329. mobileOneItem.SellerRealName = strings.Join(sellerNameSlice, "/")
  330. mobileOneItem.Status = strings.Join(statusNameSlice, "/")
  331. }
  332. }
  333. //是否可移动
  334. mobileOneItem.HasMove = hasMove
  335. br.Msg = "手机号1已存在"
  336. br.Success = true
  337. br.Data = mobileOneItem
  338. br.IsSendEmail = false
  339. br.Ret = 600
  340. return
  341. }
  342. } else {
  343. if strings.Contains(mobileOneItem.Status, "/") {
  344. if strings.Contains(mobileOneItem.Status, "正式") || strings.Contains(mobileOneItem.Status, "试用") {
  345. mobileOneItem.HasMove = false
  346. } else {
  347. mobileOneItem.HasMove = true
  348. }
  349. } else {
  350. if mobileOneItem.Status == utils.COMPANY_STATUS_FREEZE || //冻结
  351. mobileOneItem.Status == utils.COMPANY_STATUS_LOSE || //流失
  352. mobileOneItem.Status == utils.COMPANY_STATUS_POTENTIAL || //潜在
  353. mobileOneItem.Status == utils.COMPANY_STATUS_FOREVER { //永续
  354. mobileOneItem.HasMove = true
  355. }
  356. }
  357. br.Msg = "手机号1已存在"
  358. br.Success = true
  359. br.Data = mobileOneItem
  360. br.IsSendEmail = false
  361. br.Ret = 600
  362. return
  363. }
  364. }
  365. }
  366. }
  367. if req.Email != "" {
  368. emailItem, err := company.CheckCompanyUserCountByEmail(req.Email)
  369. if err != nil && err.Error() != utils.ErrNoRow() {
  370. br.Msg = "新增失败"
  371. br.ErrMsg = "新增失败,Err:" + err.Error()
  372. return
  373. }
  374. if emailItem != nil {
  375. if emailItem.UserId > 0 {
  376. if req.CompanyId > 0 {
  377. //获取联系人分组信息
  378. userSellerGroupInfo, err := models.GetUserGroupSellerByUserId(int(emailItem.UserId))
  379. if err != nil && err.Error() != utils.ErrNoRow() {
  380. br.Msg = "查询信息异常"
  381. br.Success = true
  382. br.Data = emailItem
  383. br.IsSendEmail = false
  384. br.Ret = 600
  385. return
  386. }
  387. if req.CompanyId == emailItem.CompanyId {
  388. //如果是该客户下的用户,那么判断该用户与当前账号是否存在关系,如果没有关系,那么直接添加关系后直接返回
  389. if len(companyProductList) > 0 {
  390. isHas := checkUserSellerRelation(companyProductList, emailItem, &req, br)
  391. if isHas == false {
  392. return
  393. }
  394. }
  395. //修改返回给前端用户的信息
  396. if userSellerGroupInfo != nil {
  397. emailItem.SellerRealName = userSellerGroupInfo.SellerRealName
  398. emailItem.Status = userSellerGroupInfo.Status
  399. }
  400. br.Msg = "邮箱已存在"
  401. br.Success = true
  402. br.Data = emailItem
  403. br.IsSendEmail = false
  404. br.Ret = 600
  405. return
  406. } else {
  407. hasMove := true //是否可移动
  408. //如果是大于 1 的客户,那么就是非潜在客户,需要去查询对应的销售
  409. if emailItem.CompanyId > 1 {
  410. //获取联系人分组信息
  411. userSellerGroupInfoList, err := models.GetUserGroupSellersByUserId(int(emailItem.UserId))
  412. //根据分组校验
  413. if err == nil && len(userSellerGroupInfoList) > 0 {
  414. sellerMap := make(map[int]string) //销售信息map
  415. sellerNameSlice := make([]string, 0) //销售姓名切片
  416. statusNameSlice := make([]string, 0) //客户状态姓名切片
  417. for _, v := range userSellerGroupInfoList {
  418. if v.Status != utils.COMPANY_STATUS_LOSE && v.Status != utils.COMPANY_STATUS_FOREVER && hasMove == true {
  419. hasMove = false
  420. }
  421. statusNameSlice = append(statusNameSlice, v.Status)
  422. if _, ok := sellerMap[v.SellerId]; ok {
  423. continue
  424. }
  425. sellerMap[v.SellerId] = v.SellerRealName
  426. sellerNameSlice = append(sellerNameSlice, v.SellerRealName)
  427. }
  428. emailItem.SellerRealName = strings.Join(sellerNameSlice, "/")
  429. emailItem.Status = strings.Join(statusNameSlice, "/")
  430. }
  431. }
  432. //是否可移动
  433. emailItem.HasMove = hasMove
  434. br.Msg = "邮箱已存在"
  435. br.Success = true
  436. br.Data = emailItem
  437. br.IsSendEmail = false
  438. br.Ret = 600
  439. return
  440. }
  441. } else {
  442. if strings.Contains(emailItem.Status, "/") {
  443. if strings.Contains(emailItem.Status, "正式") || strings.Contains(emailItem.Status, "试用") {
  444. emailItem.HasMove = false
  445. } else {
  446. emailItem.HasMove = true
  447. }
  448. } else {
  449. if emailItem.Status == utils.COMPANY_STATUS_FREEZE || //冻结
  450. emailItem.Status == utils.COMPANY_STATUS_LOSE || //流失
  451. emailItem.Status == utils.COMPANY_STATUS_POTENTIAL || //潜在
  452. emailItem.Status == utils.COMPANY_STATUS_FOREVER { //永续
  453. emailItem.HasMove = true
  454. }
  455. }
  456. br.Msg = "邮箱已存在"
  457. br.Success = true
  458. br.Data = emailItem
  459. br.IsSendEmail = false
  460. br.Ret = 600
  461. return
  462. }
  463. }
  464. }
  465. }
  466. //if req.BusinessCardUrl != "" && utils.RunMode == "release" {
  467. if req.BusinessCardUrl != "" {
  468. // 获取图片识别客户名称的配置
  469. crmConfig, err := company.GetConfigDetailByCode("card_recognition_company_name")
  470. if err != nil {
  471. br.Msg = "获取配置失败"
  472. br.ErrMsg = "获取配置失败"
  473. br.IsSendEmail = false
  474. return
  475. }
  476. // 获取图片识别手机号的配置
  477. crmConfig2, err := company.GetConfigDetailByCode("card_recognition_tel")
  478. if err != nil {
  479. br.Msg = "获取配置失败"
  480. br.ErrMsg = "获取配置失败"
  481. br.IsSendEmail = false
  482. return
  483. }
  484. if crmConfig.ConfigValue == "true" || crmConfig2.ConfigValue == "true" {
  485. companyName := req.CompanyName
  486. if companyName == "" {
  487. companyInfo, err := company.GetCompanyById(req.CompanyId)
  488. if err != nil {
  489. br.Msg = "查找客户失败"
  490. br.ErrMsg = "查找客户失败,err:" + err.Error()
  491. return
  492. }
  493. companyName = companyInfo.CompanyName
  494. }
  495. companyName = utils.TrimStr(companyName)
  496. tmpCompanyNameList, err := elastic.Analyze(companyName)
  497. if err != nil {
  498. br.Msg = "添加失败"
  499. br.ErrMsg = "客户名称分词失败,Err:" + err.Error()
  500. return
  501. }
  502. //公司名称切片
  503. analyzeNameList := []string{companyName}
  504. for _, v := range tmpCompanyNameList {
  505. if v == "" {
  506. continue
  507. }
  508. ignoreStrs := []string{"", "有限", "投资", "资本", "管理", "贸易", "资产", "公司", "股份", "集团", "有限公司"}
  509. if !strings.Contains(strings.Join(ignoreStrs, ","), v) && utf8.RuneCount([]byte(v)) > 1 {
  510. //不在上面的过滤字里面,且切出来的字符大于1位
  511. analyzeNameList = append(analyzeNameList, v)
  512. }
  513. }
  514. //名片识别出来的客户名称切片
  515. companyNameSlice := make([]string, 0)
  516. card, err := services.GetBusinessCard(req.BusinessCardUrl)
  517. if err != nil {
  518. br.Msg = "名片识别失败"
  519. br.ErrMsg = "名片识别失败,Err:" + err.Error()
  520. return
  521. }
  522. //if card.Errno != 0 {
  523. // br.Msg = "您上传了非名片图片,请重新上传"
  524. // br.ErrMsg = "名片识别失败,ErrMsg:" + card.ErrorMsg + ";errCode:" + strconv.Itoa(card.Errno)
  525. // return
  526. //}
  527. //var mobileStr string
  528. //for _, v := range card.WordsResult {
  529. // mobileStr += v.Words + ","
  530. //}
  531. isFlag := false
  532. if len(card.WordsResult.MOBILE) > 0 {
  533. mobileStr := strings.Join(card.WordsResult.MOBILE, ",")
  534. //if req.MobileOne != "" {
  535. // if strings.Contains(mobileStr, req.MobileOne) || mobileStr == "" {
  536. // isFlag = true
  537. // } else {
  538. // isFlag = false
  539. // }
  540. //}
  541. //
  542. //if isFlag == false && req.MobileTwo != "" {
  543. // if strings.Contains(mobileStr, req.MobileTwo) {
  544. // isFlag = true
  545. // } else {
  546. // isFlag = false
  547. // }
  548. //}
  549. if req.MobileOne != "" && strings.Contains(mobileStr, req.MobileOne) {
  550. isFlag = true
  551. }
  552. if req.MobileTwo != "" && strings.Contains(mobileStr, req.MobileTwo) {
  553. isFlag = true
  554. }
  555. //如果百度识别出来了客户名称,那么将识别出来的客户名称添加到待校验客户名称切片中
  556. if len(card.WordsResult.COMPANY) > 0 && card.WordsResult.COMPANY[0] != "" {
  557. companyNameSlice = card.WordsResult.COMPANY
  558. }
  559. }
  560. //如果百度未识别出来手机号或者公司名称,那么进行阿里识别
  561. if !isFlag || (len(companyNameSlice) == 0 && crmConfig.ConfigValue == "true") {
  562. //阿里云识别
  563. aliyunResult, errMsg, err := services.AliyunOcrBusinessCard(req.BusinessCardUrl)
  564. if err != nil {
  565. br.Msg = "识别失败"
  566. br.ErrMsg = "识别失败,Err:" + err.Error()
  567. return
  568. }
  569. if !aliyunResult.Success {
  570. br.Msg = "识别失败"
  571. br.ErrMsg = "识别失败"
  572. return
  573. }
  574. if errMsg != "" {
  575. br.Msg = errMsg
  576. return
  577. }
  578. //如果百度没有识别出来手机号,那么还需要阿里识别出来的手机号校验下
  579. if !isFlag {
  580. if len(aliyunResult.TelCell) > 0 {
  581. mobileStr := strings.Join(aliyunResult.TelCell, ",")
  582. if req.MobileOne != "" {
  583. if strings.Contains(mobileStr, req.MobileOne) {
  584. isFlag = true
  585. } else {
  586. isFlag = false
  587. }
  588. }
  589. } else {
  590. isFlag = true
  591. }
  592. }
  593. //如果阿里云识别出来了客户名称,那么将识别出来的客户名称添加到待校验客户名称切片中
  594. if len(aliyunResult.Company) > 0 {
  595. companyNameSlice = append(companyNameSlice, aliyunResult.Company...)
  596. }
  597. }
  598. if !isFlag && crmConfig2.ConfigValue == "true" {
  599. br.Msg = "名片信息与联系人手机号不符"
  600. br.IsSendEmail = false
  601. return
  602. }
  603. //校验识别出来的名片名称与传入的客户名称是否一致
  604. if len(companyNameSlice) > 0 && crmConfig.ConfigValue == "true" {
  605. isCompanyNameFlag := false //是否成功匹配客户名称
  606. //遍历识别出来的客户名称,然后与系统的客户名称做匹配(识别出来的名称包含系统名称的话,那么标记成功匹配)
  607. for _, tmpCompanyName := range companyNameSlice {
  608. //空串不处理
  609. if companyName == "" {
  610. continue
  611. }
  612. for _, analyzeName := range analyzeNameList {
  613. //如果分词出来的公司名称正好在识别出来的公司名称里面,那么就认为校验通过了
  614. if strings.Contains(tmpCompanyName, analyzeName) {
  615. isCompanyNameFlag = true
  616. break
  617. }
  618. }
  619. if isCompanyNameFlag {
  620. break
  621. }
  622. }
  623. //如果没有匹配到客户名称,那么就返回报错
  624. if !isCompanyNameFlag {
  625. br.Msg = "名片信息与公司名称不符"
  626. br.IsSendEmail = false
  627. return
  628. }
  629. }
  630. }
  631. }
  632. user := new(models.WxUser)
  633. user.RealName = utils.TrimStr(req.RealName)
  634. user.Sex = req.Sex
  635. user.CountryCode = utils.TrimStr(req.CountryCode)
  636. user.Mobile = utils.TrimStr(req.MobileOne)
  637. user.OutboundCountryCode = utils.TrimStr(req.CountryCode)
  638. user.OutboundMobile = utils.TrimStr(req.MobileOne)
  639. user.MobileTwo = utils.TrimStr(req.MobileTwo)
  640. user.Email = utils.TrimStr(req.Email)
  641. user.Position = req.Position
  642. user.IsMaker = req.IsMaker
  643. user.BusinessCardUrl = req.BusinessCardUrl
  644. user.CompanyId = req.CompanyId
  645. if req.CompanyId == 0 {
  646. user.CompanyId = 1
  647. }
  648. user.DepartmentName = req.DepartmentName
  649. user.CreatedTime = time.Now()
  650. //user.RegisterTime = time.Now()
  651. user.RegisterPlatform = 3
  652. newId, err := models.AddWxUser(user)
  653. user.UserId = newId
  654. if err != nil {
  655. br.Msg = "新增失败"
  656. br.ErrMsg = "新增失败,Err:" + err.Error()
  657. return
  658. }
  659. //如果有传入企业编号,那么需要将该联系人与销售员做绑定
  660. if len(companyProductList) > 0 {
  661. for _, companyProduct := range companyProductList {
  662. models.AddUserSellerRelation(newId, companyProduct.CompanyId, companyProduct.SellerId, companyProduct.ProductId, companyProduct.SellerName, req.MobileOne, req.Email)
  663. }
  664. }
  665. //更新客户最近阅读次数以及最近阅读时间
  666. go services.ModifyCompanyProductLastViewData([]int{req.CompanyId})
  667. //联系人信息
  668. userInfo, _ := json.Marshal(user)
  669. go services.AddWxUserOpLog(company.WxUserOpLog{
  670. LogType: "add",
  671. UserId: int(user.UserId),
  672. CompanyId: user.CompanyId,
  673. Mobile: user.Mobile,
  674. Email: user.Email,
  675. OriginalUserInfo: "",
  676. UserInfo: string(userInfo),
  677. OriginalUserSellerInfo: "",
  678. UserSellerInfo: "",
  679. OpUserId: sysUser.AdminId,
  680. OpUserName: sysUser.RealName,
  681. CreateTime: time.Now(),
  682. })
  683. br.Ret = 200
  684. br.Success = true
  685. br.Msg = "新增成功"
  686. br.Data = newId
  687. br.IsAddLog = true
  688. }
  689. // 获取当前操作员产品权限(所有产品数据)
  690. func getSysCompanyProductList(productId, companyId int) (companyProduct []*company.CompanyProduct, err error) {
  691. if productId == 0 {
  692. tmpCompanyProduct, productErr := company.GetCompanyProductByCompanyIdAndProductId(companyId, 1)
  693. if productErr != nil && productErr.Error() != utils.ErrNoRow() {
  694. //sql异常
  695. err = productErr
  696. return
  697. }
  698. if tmpCompanyProduct != nil {
  699. companyProduct = append(companyProduct, tmpCompanyProduct)
  700. }
  701. tmpCompanyProduct, productErr = company.GetCompanyProductByCompanyIdAndProductId(companyId, 2)
  702. if productErr != nil && productErr.Error() != utils.ErrNoRow() {
  703. //sql异常
  704. err = productErr
  705. return
  706. }
  707. if tmpCompanyProduct != nil {
  708. companyProduct = append(companyProduct, tmpCompanyProduct)
  709. }
  710. } else {
  711. tmpCompanyProduct, productErr := company.GetCompanyProductByCompanyIdAndProductId(companyId, productId)
  712. if productErr != nil && productErr.Error() != utils.ErrNoRow() {
  713. //sql异常
  714. err = productErr
  715. return
  716. }
  717. if tmpCompanyProduct != nil {
  718. companyProduct = append(companyProduct, tmpCompanyProduct)
  719. }
  720. }
  721. return
  722. }
  723. // 校验用户与销售信息
  724. func checkUserSellerRelation(companyProductList []*company.CompanyProduct, companyUser *company.CompanyUser, req *company.AddUserReq, br *models.BaseResponse) (isHas bool) {
  725. for _, companyProduct := range companyProductList {
  726. _, relationErr := models.GetUserSellerRelation(companyUser.UserId, companyProduct.SellerId)
  727. //找到数据了
  728. if relationErr == nil {
  729. isHas = true
  730. continue
  731. }
  732. //没找到数据,不存在关系
  733. //如果不存在关系,那么直接添加关系就好了,其他操作不做
  734. if relationErr.Error() == utils.ErrNoRow() {
  735. //添加用户与联系人的关系
  736. models.AddUserSellerRelation(companyUser.UserId, companyProduct.CompanyId, companyProduct.SellerId, companyProduct.ProductId, companyProduct.SellerName, companyUser.Mobile, companyUser.Email)
  737. } else {
  738. //sql异常
  739. br.Msg = "新增失败"
  740. br.ErrMsg = "判断手机号或邮箱是否存在关联关系,Err:" + relationErr.Error()
  741. return
  742. }
  743. //对老数据做字段数据新增处理,如果该字段已有数据则不做处理start
  744. {
  745. mobileOne := companyUser.Mobile
  746. mobileTwo := companyUser.MobileTwo
  747. email := companyUser.Email
  748. businessCardUrl := companyUser.BusinessCardUrl
  749. if req.MobileOne != "" && companyUser.Mobile == "" {
  750. mobileOne = utils.TrimStr(req.MobileOne)
  751. }
  752. if req.MobileTwo != "" && companyUser.MobileTwo == "" {
  753. mobileTwo = utils.TrimStr(req.MobileTwo)
  754. }
  755. if req.Email != "" && companyUser.Email == "" {
  756. email = utils.TrimStr(req.Email)
  757. }
  758. if req.BusinessCardUrl != "" && companyUser.BusinessCardUrl == "" {
  759. businessCardUrl = strings.Replace(req.BusinessCardUrl, " ", "", -1)
  760. }
  761. _ = company.EditCompanyUserContact(companyUser.UserId, mobileOne, mobileTwo, email, businessCardUrl)
  762. }
  763. //对老数据做字段数据新增处理,如果该字段已有数据则不做处理start
  764. br.Ret = 200
  765. br.Success = true
  766. br.Msg = "新增成功"
  767. br.Data = companyUser.UserId
  768. return
  769. }
  770. return
  771. }
  772. // List
  773. // @Title 联系人列表
  774. // @Description 联系人列表接口
  775. // @Param PageSize query int true "每页数据条数"
  776. // @Param CurrentIndex query int true "当前页页码,从1开始"
  777. // @Param CompanyId query int true "公司id,必填"
  778. // @Param KeyWord query string true "搜索关键词"
  779. // @Param ProductType query int true "产品类型"
  780. // @Param ProductId query int true "产品id"
  781. // @Param IsSubscribe query int true "是否关注了公众号: -1-默认全部; 0-未关注; 1-已关注"
  782. // @Param IsSubscribeHzyj query int true "是否关注了弘则研究公众号: -1-默认全部; 0-未关注; 1-已关注"
  783. // @Param IsSubscribeCygx query int true "是否关注了查研观向小助手公众号: -1-默认全部; 0-未关注; 1-已关注"
  784. // @Success 200 {object} company.CompanyUserListResp
  785. // @router /user/list [get]
  786. func (this *CompanyUserController) List() {
  787. br := new(models.BaseResponse).Init()
  788. defer func() {
  789. this.Data["json"] = br
  790. this.ServeJSON()
  791. }()
  792. sysUser := this.SysUser
  793. if sysUser == nil {
  794. br.Msg = "请登录"
  795. br.ErrMsg = "请登录,SysUser Is Empty"
  796. br.Ret = 408
  797. return
  798. }
  799. pageSize, _ := this.GetInt("PageSize")
  800. currentIndex, _ := this.GetInt("CurrentIndex")
  801. companyId, _ := this.GetInt("CompanyId")
  802. keyWord := utils.TrimStr(this.GetString("KeyWord"))
  803. productType, _ := this.GetInt("ProductType")
  804. ybProductId, _ := this.GetInt("ProductId")
  805. isSubscribe, _ := this.GetInt("IsSubscribe", -1)
  806. isSubscribeHzyj, _ := this.GetInt("IsSubscribeHzyj", -1)
  807. isSubscribeCygx, _ := this.GetInt("IsSubscribeCygx", -1)
  808. // 默认是问答社区
  809. if productType <= 0 {
  810. productType = 3
  811. }
  812. if companyId <= 0 {
  813. br.Msg = "请选择客户"
  814. br.ErrMsg = "客户参数错误"
  815. return
  816. }
  817. var startSize int
  818. if pageSize <= 0 {
  819. pageSize = utils.PageSize20
  820. }
  821. if currentIndex <= 0 {
  822. currentIndex = 1
  823. }
  824. startSize = paging.StartIndex(currentIndex, pageSize)
  825. var condition string
  826. var pars []interface{}
  827. if keyWord != "" {
  828. condition += ` AND (a.real_name LIKE '%` + keyWord + `%' OR a.mobile LIKE '%` + keyWord + `%' OR a.email LIKE '%` + keyWord + `%') `
  829. }
  830. // 是否关注公众号
  831. if isSubscribe == 0 {
  832. condition += ` AND (c.subscribe = 0 OR ISNULL(c.subscribe)) `
  833. }
  834. if isSubscribe == 1 {
  835. condition += ` AND c.subscribe = 1 `
  836. }
  837. // 是否关注弘则研究公众号
  838. if isSubscribeHzyj == 0 {
  839. condition += ` AND (c.subscribe = 0 OR ISNULL(c.subscribe)) `
  840. }
  841. if isSubscribeHzyj == 1 {
  842. condition += ` AND c.subscribe = 1 `
  843. }
  844. // 是否关注弘则研究公众号
  845. if isSubscribeCygx == 0 {
  846. condition += ` AND (a.cygx_subscribe = 0 OR ISNULL(a.cygx_subscribe)) `
  847. }
  848. if isSubscribeCygx == 1 {
  849. condition += ` AND a.cygx_subscribe = 1 `
  850. }
  851. //非管理员,那么只能看到该产品下的联系人
  852. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  853. productId := services.GetProductId(sysUser.RoleTypeCode)
  854. condition += ` AND b.product_id = ? `
  855. pars = append(pars, productId)
  856. //流失客户(除非是超级管理员或者是部门管理员,要不然不允许看对应的联系人)
  857. //var companyProduct *company.CompanyProduct
  858. //当前是ficc权限,且非ficc管理员
  859. //if productId == 1 && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_FICC_ADMIN {
  860. // tmpCompanyProduct, _ := company.GetCompanyProductByCompanyIdAndProductId(companyId, 1)
  861. // companyProduct = tmpCompanyProduct
  862. //}
  863. //权益销售查看流失客户时,可以看到非本人名下流失客户的联系人需求池 930 2024-03-25
  864. //if productId == 2 && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_ADMIN {
  865. // // 当前是权益权限,且非 权益管理员
  866. // tmpCompanyProduct, _ := company.GetCompanyProductByCompanyIdAndProductId(companyId, 2)
  867. // companyProduct = tmpCompanyProduct
  868. // if companyProduct != nil && companyProduct.Status == utils.COMPANY_STATUS_LOSE {
  869. // condition += ` AND seller_id=? `
  870. // pars = append(pars, sysUser.AdminId)
  871. // }
  872. //}
  873. }
  874. total, err := company.GetCompanyUserListCountV2(condition, pars, companyId)
  875. if err != nil {
  876. br.Msg = "获取失败"
  877. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  878. return
  879. }
  880. list, err := company.GetCompanyUserListV2(condition, pars, companyId, startSize, pageSize)
  881. if err != nil {
  882. br.Msg = "获取失败"
  883. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  884. return
  885. }
  886. //获取企业客户信息
  887. companyInfo, err := company.GetCompanyById(companyId)
  888. if err != nil {
  889. br.Msg = "获取失败"
  890. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  891. return
  892. }
  893. lenList := len(list)
  894. if lenList > 0 {
  895. userIdSlice := make([]string, 0)
  896. mobilesSlice := make([]string, 0)
  897. emailsSlice := make([]string, 0)
  898. userIds := make([]int, 0)
  899. for _, v := range list {
  900. userIdSlice = append(userIdSlice, strconv.Itoa(int(v.UserId)))
  901. userIds = append(userIds, int(v.UserId))
  902. if v.Mobile != "" {
  903. mobilesSlice = append(mobilesSlice, v.Mobile)
  904. } else if v.Email != "" {
  905. emailsSlice = append(emailsSlice, v.Email)
  906. }
  907. }
  908. //用户浏览数据
  909. userIdStr := strings.Join(userIdSlice, ",")
  910. mobileStr := strings.Join(mobilesSlice, "','")
  911. mobileStr = "'" + mobileStr + "'"
  912. emailStr := strings.Join(emailsSlice, "','")
  913. emailStr = "'" + emailStr + "'"
  914. //userViewTotalList, _ := models.GetCountUserViewHistoryByUserIds(userIdStr)
  915. //userViewTotalMap := make(map[int]*models.UserViewTotalSlice)
  916. //for _, userView := range userViewTotalList {
  917. // userViewTotalMap[userView.UserId] = userView
  918. //}
  919. //用户日评浏览数据
  920. //userReportViewTotalList, _ := models.GetReportViewMaxTimeByUserIds(userIdStr)
  921. //userReportViewTotalMap := make(map[int]*models.ReportViewRecord)
  922. //for _, userReportView := range userReportViewTotalList {
  923. // userReportViewTotalMap[userReportView.UserId] = userReportView
  924. //}
  925. //报告统计删除晨报部分统计加入每日资讯 2021-4-9
  926. ////手机号
  927. //userViewMobileTotalMap := make(map[string]*models.UserViewMobileTotalSlice)
  928. //userReportViewMobileTotalMap := make(map[string]*models.ReportViewMobileRecord)
  929. //userAdvisoryViewMobileTotalMap := make(map[string]*advisory.UserViewMobileTotalSlice)
  930. //userCygxArticleHistoryRecordViewMobileTotalMap := make(map[string]*models.UserViewMobileTotalSlice)
  931. //if len(mobilesSlice) > 0 {
  932. // //用户浏览数据
  933. // userViewMobileTotalList, _ := models.GetCountUserViewHistoryByMobiles(mobileStr)
  934. // for _, userViewMobile := range userViewMobileTotalList {
  935. // userViewMobileTotalMap[userViewMobile.Mobile] = userViewMobile
  936. // }
  937. //
  938. // //每日点评手机号数据
  939. // userReportViewMobileTotalList, _ := models.GetReportViewMaxTimeByMobiles(mobileStr)
  940. // for _, userReportViewMobile := range userReportViewMobileTotalList {
  941. // userReportViewMobileTotalMap[userReportViewMobile.Mobile] = userReportViewMobile
  942. // }
  943. //
  944. // //每日资讯
  945. // userAdvisoryViewMobileTotalList, _ := advisory.GetCountUserViewHistoryByMobiles(mobileStr)
  946. // //fmt.Println(userAdvisoryViewMobileTotalList)
  947. // for _, userAdvisoryViewMobile := range userAdvisoryViewMobileTotalList {
  948. // userAdvisoryViewMobileTotalMap[userAdvisoryViewMobile.Mobile] = userAdvisoryViewMobile
  949. // }
  950. // //查研观向
  951. // userCygxArticleHistoryRecordViewMobileTotalList, _ := models.GetCountCygxArticleHistoryRecordByMobiles(mobileStr)
  952. // for _, userCygxArticleHistoryRecordViewMobile := range userCygxArticleHistoryRecordViewMobileTotalList {
  953. // userCygxArticleHistoryRecordViewMobileTotalMap[userCygxArticleHistoryRecordViewMobile.Mobile] = userCygxArticleHistoryRecordViewMobile
  954. // }
  955. //}
  956. ////邮箱
  957. //userViewEmailTotalMap := make(map[string]*models.UserViewEmailTotalSlice)
  958. //userReportViewEmailTotalMap := make(map[string]*models.ReportViewEmailRecord)
  959. //userAdvisoryViewEmailTotalMap := make(map[string]*advisory.UserViewEmailTotalSlice)
  960. //userCygxViewEmailTotalMap := make(map[string]*models.UserViewEmailTotalSlice)
  961. //if len(emailsSlice) > 0 {
  962. // //用户浏览数据
  963. // userViewEmailTotalList, _ := models.GetCountUserViewHistoryByEmails(emailStr)
  964. // for _, userViewEmail := range userViewEmailTotalList {
  965. // userViewEmailTotalMap[userViewEmail.Email] = userViewEmail
  966. // }
  967. // //每日点评手机号数据
  968. // userReportViewEmailTotalList, _ := models.GetReportViewMaxTimeByEmails(emailStr)
  969. // for _, userReportViewEmail := range userReportViewEmailTotalList {
  970. // userReportViewEmailTotalMap[userReportViewEmail.Email] = userReportViewEmail
  971. // }
  972. // //每日资讯
  973. // userAdvisoryViewEmailTotalList, _ := advisory.GetCountUserViewHistoryByEmails(emailStr)
  974. // for _, userAdvisoryViewEmail := range userAdvisoryViewEmailTotalList {
  975. // userAdvisoryViewEmailTotalMap[userAdvisoryViewEmail.Email] = userAdvisoryViewEmail
  976. // }
  977. // //查研观向
  978. // userCygxViewEmailTotalList, _ := models.GetCountCygxArticleHistoryRecordByEmails(emailStr)
  979. // for _, userCygxReportViewEmail := range userCygxViewEmailTotalList {
  980. // userCygxViewEmailTotalMap[userCygxReportViewEmail.Email] = userCygxReportViewEmail
  981. // }
  982. //}
  983. //获取联系人关联产品的条数
  984. userSellerRelationTotalSlice, err := models.GetUserSellerRelationCountByUserIds(userIdStr)
  985. if err != nil {
  986. br.Msg = "获取失败"
  987. br.ErrMsg = "获取联系人与销售员信息失败,Err:" + err.Error()
  988. return
  989. }
  990. userSellerRelationTotalMap := make(map[int]*models.UserSellerRelationSlice)
  991. for _, userSellerRelationTotal := range userSellerRelationTotalSlice {
  992. userSellerRelationTotalMap[userSellerRelationTotal.UserId] = userSellerRelationTotal
  993. }
  994. userRecordRegisterMap := make(map[int]time.Time)
  995. if len(userIdSlice) > 0 {
  996. //用户绑定注册数据
  997. userRecordRegisterList, _ := models.GetUserRecordRegisterByUserIds(userIdStr)
  998. for _, userRecordRegister := range userRecordRegisterList {
  999. userRecordRegisterMap[userRecordRegister.UserId] = userRecordRegister.CreateTime
  1000. }
  1001. }
  1002. // 用户图表权限设置信息
  1003. userChartPermissionMap := make(map[int]*company_user.ChartClassifyPermission)
  1004. userChartPermissionList, err := company_user.GetChartClassifyPermissionListByUserIds(userIdStr)
  1005. if err != nil {
  1006. br.Msg = "获取失败"
  1007. br.ErrMsg = "获取联系人图表权限信息失败, Err:" + err.Error()
  1008. return
  1009. }
  1010. for i := 0; i < len(userChartPermissionList); i++ {
  1011. userChartPermissionMap[userChartPermissionList[i].UserId] = userChartPermissionList[i]
  1012. }
  1013. // 获取admin列表-匹配联系人是否为admin用户
  1014. sysUserList, err := system.GetAdminList()
  1015. if err != nil {
  1016. br.Msg = "获取失败"
  1017. br.ErrMsg = "获取admin列表失败, Err:" + err.Error()
  1018. return
  1019. }
  1020. sysUserMobileMap := make(map[string]int, 0)
  1021. for i := 0; i < len(sysUserList); i++ {
  1022. sysUserMobile := sysUserList[i].Mobile
  1023. if sysUserMobile != "" {
  1024. sysUserMobileMap[sysUserList[i].Mobile] = 1
  1025. }
  1026. }
  1027. // 获取研报分产品统计
  1028. //ybViewsList, e := yb.GetCompanyUserYbProductVisitCount(userIds)
  1029. ybViewsList, e := yb.GetCompanyUserYbProductVisitCountByProductType(userIds, productType, ybProductId)
  1030. if e != nil {
  1031. br.Msg = "获取失败"
  1032. br.ErrMsg = "获取分产品阅读统计失败, Err:" + e.Error()
  1033. return
  1034. }
  1035. userYbViewsMap := make(map[int]int)
  1036. for _, v := range ybViewsList {
  1037. userYbViewsMap[v.UserId] = v.VisitCount
  1038. }
  1039. userHaveMoveMap := services.GetWxUserHaveMoveMap(mobilesSlice) // 处理用户是否移动过按钮回显
  1040. for i := 0; i < lenList; i++ {
  1041. item := list[i]
  1042. //企业名称
  1043. list[i].CompanyName = companyInfo.CompanyName
  1044. if item.OpenId != "" {
  1045. list[i].IsRegister = true
  1046. } else {
  1047. if item.RegisterPlatform == 2 {
  1048. if item.Mobile != "" || item.Email != "" {
  1049. list[i].IsRegister = true
  1050. }
  1051. } else if item.RegisterTime != "" {
  1052. list[i].IsRegister = true
  1053. } else {
  1054. list[i].IsRegister = false
  1055. }
  1056. }
  1057. ////手机号用户累计浏览次数
  1058. //if userView, ok := userViewMobileTotalMap[item.Mobile]; ok {
  1059. // list[i].ViewTotal += userView.Total
  1060. // if userView.CreatedTime.After(list[i].LastViewTime) {
  1061. // list[i].LastViewTime = userView.CreatedTime
  1062. // list[i].LastViewTimeStr = userView.CreatedTime.Format(utils.FormatDateTime)
  1063. // }
  1064. //}
  1065. ////邮箱用户累计浏览次数
  1066. //if userView, ok := userViewEmailTotalMap[item.Email]; ok {
  1067. // //总共浏览的报表数据需要调整为(手机号用户浏览晨报数+邮箱号用户浏览晨报数)
  1068. // list[i].ViewTotal += userView.Total
  1069. // if userView.CreatedTime.After(list[i].LastViewTime) {
  1070. // list[i].LastViewTime = userView.CreatedTime
  1071. // list[i].LastViewTimeStr = userView.CreatedTime.Format(utils.FormatDateTime)
  1072. // }
  1073. //}
  1074. ////如果存在手机号用户日评数据,那么需要做处理
  1075. //if reportView, ok := userReportViewMobileTotalMap[item.Mobile]; ok {
  1076. // //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
  1077. // if reportView.LastViewTime.After(list[i].LastViewTime) {
  1078. // list[i].LastViewTime = reportView.LastViewTime
  1079. // list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
  1080. // }
  1081. // //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
  1082. // list[i].ViewTotal += reportView.ViewTotal
  1083. //}
  1084. ////如果存在手机号用户日评数据,那么需要做处理
  1085. //if reportView, ok := userReportViewEmailTotalMap[item.Email]; ok {
  1086. // //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
  1087. // if reportView.LastViewTime.After(list[i].LastViewTime) {
  1088. // list[i].LastViewTime = reportView.LastViewTime
  1089. // list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
  1090. // }
  1091. // //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
  1092. // list[i].ViewTotal += reportView.ViewTotal
  1093. //}
  1094. //
  1095. ////如果存在手机号用户每日资讯,那么需要做处理
  1096. //if advisoryView, ok := userAdvisoryViewMobileTotalMap[item.Mobile]; ok {
  1097. // //fmt.Println("蝴蝶眨几次眼睛")
  1098. // //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  1099. // if advisoryView.CreatedTime.After(list[i].LastViewTime) {
  1100. // list[i].LastViewTime = advisoryView.CreatedTime
  1101. // list[i].LastViewTimeStr = advisoryView.CreatedTime.Format(utils.FormatDateTime)
  1102. // }
  1103. // //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数)
  1104. // list[i].ViewTotal += advisoryView.Total
  1105. //}
  1106. ////如果存在邮箱号用户每日资讯,那么需要做处理
  1107. //if advisoryView, ok := userAdvisoryViewEmailTotalMap[item.Email]; ok {
  1108. // //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  1109. // if advisoryView.CreatedTime.After(list[i].LastViewTime) {
  1110. // list[i].LastViewTime = advisoryView.CreatedTime
  1111. // list[i].LastViewTimeStr = advisoryView.CreatedTime.Format(utils.FormatDateTime)
  1112. // }
  1113. // //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数)
  1114. // list[i].ViewTotal += advisoryView.Total
  1115. //}
  1116. //
  1117. ////如果存在手机号用户查研观向,那么需要做处理
  1118. //if cygxView, ok := userCygxArticleHistoryRecordViewMobileTotalMap[item.Mobile]; ok {
  1119. // //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  1120. // if cygxView.CreatedTime.After(list[i].LastViewTime) {
  1121. // list[i].LastViewTime = cygxView.CreatedTime
  1122. // list[i].LastViewTimeStr = cygxView.CreatedTime.Format(utils.FormatDateTime)
  1123. // }
  1124. // //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数+查研观向)
  1125. // list[i].ViewTotal += cygxView.Total
  1126. //}
  1127. ////如果存在邮箱号用户查研观向,那么需要做处理
  1128. //if cygxView, ok := userCygxViewEmailTotalMap[item.Email]; ok {
  1129. // //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  1130. // if cygxView.CreatedTime.After(list[i].LastViewTime) {
  1131. // list[i].LastViewTime = cygxView.CreatedTime
  1132. // list[i].LastViewTimeStr = cygxView.CreatedTime.Format(utils.FormatDateTime)
  1133. // }
  1134. // //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数+查研观向)
  1135. // list[i].ViewTotal += cygxView.Total
  1136. //}
  1137. ///*if reportView, ok := userReportViewTotalMap[int(item.UserId)]; ok {
  1138. // //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
  1139. // if reportView.LastViewTime.After(list[i].LastViewTime) {
  1140. // list[i].LastViewTime = reportView.LastViewTime
  1141. // list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
  1142. // }
  1143. // //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
  1144. // list[i].ViewTotal += reportView.ViewTotal
  1145. //}*/
  1146. list[i].ViewTotal = list[i].FiccViewTotal + list[i].RaiViewTotal
  1147. var tmpLastViewTime time.Time
  1148. tmpLastViewTime = list[i].FiccLastViewTime
  1149. if !list[i].RaiLastViewTime.IsZero() {
  1150. if tmpLastViewTime.IsZero() || list[i].RaiLastViewTime.After(tmpLastViewTime) {
  1151. tmpLastViewTime = list[i].RaiLastViewTime
  1152. }
  1153. }
  1154. list[i].LastViewTime = tmpLastViewTime
  1155. if !tmpLastViewTime.IsZero() {
  1156. list[i].LastViewTimeStr = tmpLastViewTime.Format(utils.FormatDateTime)
  1157. }
  1158. if list[i].LastViewTime.Before(time.Now().AddDate(0, 0, -7)) && list[i].IsFollow == 1 {
  1159. list[i].NotRead = true
  1160. }
  1161. //如果有绑定数据,那么将数据返回对应的注册绑定数据
  1162. if _, ok := userRecordRegisterMap[int(item.UserId)]; ok {
  1163. list[i].IsRegister = true
  1164. //list[i].RegisterTime = userRecordRegisterTime.Format(utils.FormatDateTime)
  1165. }
  1166. //是否共享联系人
  1167. if userSellerRelationTotal, ok := userSellerRelationTotalMap[int(item.UserId)]; ok {
  1168. //条数大于1,代表这是共享联系人
  1169. //if userSellerRelationTotal.Total > 1 {
  1170. // list[i].IsShared = true
  1171. //}
  1172. list[i].ProductIds = userSellerRelationTotal.ProductIds
  1173. }
  1174. // 图表权限
  1175. if _, isAdmin := sysUserMobileMap[list[i].Mobile]; isAdmin {
  1176. list[i].IsChartPermissionSetting = 2
  1177. } else {
  1178. if _, ok := userChartPermissionMap[int(item.UserId)]; ok {
  1179. list[i].IsChartPermissionSetting = 1
  1180. }
  1181. }
  1182. // 分产品阅读统计
  1183. list[i].YbProductViewTotal = userYbViewsMap[int(item.UserId)]
  1184. //list[i].LastViewTimeStr = list[i].RaiLastViewTime.Format(utils.FormatDateTime)
  1185. if item.Mobile != "" {
  1186. list[i].HaveMoveButton = userHaveMoveMap[item.Mobile]
  1187. }
  1188. }
  1189. isUserYanXuanButtonShow, err := services.CheckCompanyUserYanXuanButton(sysUser.RoleTypeCode, sysUser.Mobile)
  1190. if err != nil {
  1191. br.Msg = "获取失败"
  1192. br.ErrMsg = "获取失败 CheckCompanyUserYanXuanButton ,Err:" + err.Error()
  1193. return
  1194. }
  1195. if isUserYanXuanButtonShow {
  1196. userYanxuanPermissionMap := cygxService.GetCygxUserYanxuanPermissionMapItem(userIds) // 如果是权益部门下的人,则展示研选相关的信息
  1197. userInteractionNumMap := cygxService.GetUserInteractionNumMap(userIds) // 如果是权益部门下的人,展示互动量相关的信息
  1198. mfyxuserRecordRegisterMap := make(map[int]string)
  1199. mfyxuserRecordRegisterTimeMap := make(map[int]time.Time)
  1200. if len(userIdSlice) > 0 {
  1201. //用户查研观向网页版注册时间
  1202. clptuserRecordRegisterList, err := cygx.GetCygxClptSessionrByUserIdsMyfx(userIdStr)
  1203. if err != nil {
  1204. br.Msg = "获取失败"
  1205. br.ErrMsg = "获取失败,GetCygxClptSessionrByUserIdsMyfx Err:" + err.Error()
  1206. return
  1207. }
  1208. for _, userRecordRegister := range clptuserRecordRegisterList {
  1209. mfyxuserRecordRegisterTimeMap[userRecordRegister.UserId] = userRecordRegister.CreateTime
  1210. mfyxuserRecordRegisterMap[userRecordRegister.UserId] = userRecordRegister.CreateTime.Format(utils.FormatDateTime)
  1211. }
  1212. //买方研选网页版注册时间
  1213. mfyxwebRecordRegisterList, err := cygx.GetCygxMfyxWebSessionByUserIdsMyfx(userIdStr)
  1214. if err != nil {
  1215. br.Msg = "获取失败"
  1216. br.ErrMsg = "获取失败,GetCygxMfyxWebSessionByUserIdsMyfx Err:" + err.Error()
  1217. return
  1218. }
  1219. for _, userRecordRegister := range mfyxwebRecordRegisterList {
  1220. //如果注册时间早于查研观向网页版的,或者没有注册,就用这里的时间替换
  1221. if userRecordRegister.CreateTime.Before(mfyxuserRecordRegisterTimeMap[userRecordRegister.UserId]) || mfyxuserRecordRegisterMap[userRecordRegister.UserId] == "" {
  1222. mfyxuserRecordRegisterTimeMap[userRecordRegister.UserId] = userRecordRegister.CreateTime
  1223. mfyxuserRecordRegisterMap[userRecordRegister.UserId] = userRecordRegister.CreateTime.Format(utils.FormatDateTime)
  1224. }
  1225. }
  1226. mfyxuserRecordRegisterList, err := models.GetUserRecordRegisterByUserIdsMyfx(userIdStr)
  1227. if err != nil {
  1228. br.Msg = "获取失败"
  1229. br.ErrMsg = "获取失败 GetUserRecordRegisterByUserIdsMyfx ,Err:" + err.Error()
  1230. return
  1231. }
  1232. for _, userRecordRegister := range mfyxuserRecordRegisterList {
  1233. //如果注册时间早于网页版的,或者网页版没有注册,就用这里的时间替换
  1234. if userRecordRegister.CreateTime.Before(mfyxuserRecordRegisterTimeMap[userRecordRegister.UserId]) || mfyxuserRecordRegisterMap[userRecordRegister.UserId] == "" {
  1235. mfyxuserRecordRegisterMap[userRecordRegister.UserId] = userRecordRegister.CreateTime.Format(utils.FormatDateTime)
  1236. }
  1237. }
  1238. }
  1239. for i := 0; i < lenList; i++ {
  1240. item := list[i]
  1241. // 分产品阅读统计
  1242. //list[i].YbProductViewTotal = userYbViewsMap[int(item.UserId)]
  1243. list[i].MfyxInteractionNum = userInteractionNumMap[int(item.UserId)]
  1244. //权益销售查看用户研选的信息
  1245. if userYanxuanPermissionMap[int(item.UserId)] != nil {
  1246. mfyxItem := userYanxuanPermissionMap[int(item.UserId)]
  1247. list[i].MfyxStatus = mfyxItem.Status
  1248. list[i].MfyxStartDate = mfyxItem.StartDate
  1249. list[i].MfyxEndDate = mfyxItem.EndDate
  1250. } else {
  1251. list[i].MfyxStatus = "未开通"
  1252. }
  1253. if mfyxuserRecordRegisterMap[int(item.UserId)] != "" {
  1254. list[i].MfyxIsBinding = true
  1255. list[i].MfyxBindingTime = mfyxuserRecordRegisterMap[int(item.UserId)]
  1256. }
  1257. //list[i].LastViewTimeStr = list[i].RaiLastViewTime.Format(utils.FormatDateTime)
  1258. }
  1259. }
  1260. }
  1261. page := paging.GetPaging(currentIndex, pageSize, total)
  1262. resp := new(company.CompanyUserListResp)
  1263. resp.List = list
  1264. resp.Paging = page
  1265. br.Ret = 200
  1266. br.Success = true
  1267. br.Msg = "获取成功"
  1268. br.Data = resp
  1269. }
  1270. func (this *CompanyUserController) List2() {
  1271. br := new(models.BaseResponse).Init()
  1272. defer func() {
  1273. this.Data["json"] = br
  1274. this.ServeJSON()
  1275. }()
  1276. sysUser := this.SysUser
  1277. if sysUser == nil {
  1278. br.Msg = "请登录"
  1279. br.ErrMsg = "请登录,SysUser Is Empty"
  1280. br.Ret = 408
  1281. return
  1282. }
  1283. pageSize, _ := this.GetInt("PageSize")
  1284. currentIndex, _ := this.GetInt("CurrentIndex")
  1285. companyId, _ := this.GetInt("CompanyId")
  1286. keyWord := this.GetString("KeyWord")
  1287. if companyId <= 0 {
  1288. br.Msg = "请选择客户"
  1289. br.ErrMsg = "客户参数错误"
  1290. return
  1291. }
  1292. var startSize int
  1293. if pageSize <= 0 {
  1294. pageSize = utils.PageSize20
  1295. }
  1296. if currentIndex <= 0 {
  1297. currentIndex = 1
  1298. }
  1299. startSize = paging.StartIndex(currentIndex, pageSize)
  1300. var condition string
  1301. var pars []interface{}
  1302. if keyWord != "" {
  1303. condition += ` AND (a.real_name LIKE '%` + keyWord + `%' OR a.mobile LIKE '%` + keyWord + `%' OR a.email LIKE '%` + keyWord + `%') `
  1304. }
  1305. total, err := company.GetCompanyUserListCount(condition, pars, companyId)
  1306. if err != nil {
  1307. br.Msg = "获取失败"
  1308. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  1309. return
  1310. }
  1311. list, err := company.GetCompanyUserList(condition, pars, companyId, startSize, pageSize)
  1312. if err != nil {
  1313. br.Msg = "获取失败"
  1314. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1315. return
  1316. }
  1317. lenList := len(list)
  1318. for i := 0; i < lenList; i++ {
  1319. item := list[i]
  1320. if item.OpenId != "" {
  1321. list[i].IsRegister = true
  1322. } else {
  1323. if item.RegisterPlatform == 2 {
  1324. if item.Mobile != "" || item.Email != "" {
  1325. list[i].IsRegister = true
  1326. }
  1327. } else {
  1328. list[i].IsRegister = false
  1329. }
  1330. }
  1331. reportView, err := models.GetReportViewMaxTime(int(item.UserId))
  1332. if err != nil {
  1333. br.Msg = "获取失败"
  1334. br.ErrMsg = "获取GetReportViewMaxTime失败,Err:" + err.Error()
  1335. return
  1336. }
  1337. if reportView.LastViewTime.After(list[i].LastViewTime) {
  1338. list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
  1339. } else {
  1340. list[i].LastViewTimeStr = list[i].LastViewTime.Format(utils.FormatDateTime)
  1341. }
  1342. list[i].ViewTotal += reportView.ViewTotal
  1343. }
  1344. page := paging.GetPaging(currentIndex, pageSize, total)
  1345. resp := new(company.CompanyUserListResp)
  1346. resp.List = list
  1347. resp.Paging = page
  1348. br.Ret = 200
  1349. br.Success = true
  1350. br.Msg = "获取成功"
  1351. br.Data = resp
  1352. }
  1353. // @Title 获取客户名下联系人数量(根据当前账号角色区分)
  1354. // @Description 获取客户名下联系人数量(根据当前账号角色区分)接口
  1355. // @Param CompanyId query int true "客户id"
  1356. // @Param ProductId query int true "产品权限id"
  1357. // @Success 200 {object} company.CompanyUserTotal
  1358. // @router /company_user/total [get]
  1359. func (this *CompanyUserController) GetUserCountByCompanyId() {
  1360. br := new(models.BaseResponse).Init()
  1361. defer func() {
  1362. this.Data["json"] = br
  1363. this.ServeJSON()
  1364. }()
  1365. sysUser := this.SysUser
  1366. if sysUser == nil {
  1367. br.Msg = "请登录"
  1368. br.ErrMsg = "请登录,SysUser Is Empty"
  1369. br.Ret = 408
  1370. return
  1371. }
  1372. companyId, _ := this.GetInt("CompanyId")
  1373. if companyId <= 0 {
  1374. br.Msg = "参数错误"
  1375. return
  1376. }
  1377. productId, _ := this.GetInt("ProductId")
  1378. //如果没有传入,那么去根据权限来获取id
  1379. if productId <= 0 {
  1380. productId = services.GetProductId(sysUser.RoleTypeCode)
  1381. }
  1382. total, err := services.GetUserCountByCompanyId(companyId, productId)
  1383. if err != nil {
  1384. br.Msg = "获取失败"
  1385. br.Msg = "获取联系人总数失败,Err:" + err.Error()
  1386. return
  1387. }
  1388. br.Ret = 200
  1389. br.Success = true
  1390. br.Msg = "获取成功"
  1391. br.Data = company.CompanyUserTotal{
  1392. Total: total,
  1393. }
  1394. }
  1395. // @Title 删除客户联系人
  1396. // @Description 删除客户联系人接口
  1397. // @Param request body company.DeleteUserReq true "type json string"
  1398. // @router /user/delete [post]
  1399. func (this *CompanyUserController) DeleteUser() {
  1400. br := new(models.BaseResponse).Init()
  1401. defer func() {
  1402. this.Data["json"] = br
  1403. this.ServeJSON()
  1404. }()
  1405. sysUser := this.SysUser
  1406. if sysUser == nil {
  1407. br.Msg = "请登录"
  1408. br.ErrMsg = "请登录,SysUser Is Empty"
  1409. br.Ret = 408
  1410. return
  1411. }
  1412. var req company.DeleteUserReq
  1413. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1414. if err != nil {
  1415. br.Msg = "参数解析异常!"
  1416. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1417. return
  1418. }
  1419. if req.UserId <= 0 {
  1420. br.Msg = "参数错误!"
  1421. return
  1422. }
  1423. //获取联系人详情
  1424. userInfo, err := models.GetWxUserByUserId(req.UserId)
  1425. if err != nil {
  1426. br.Msg = "获取联系人异常!"
  1427. br.ErrMsg = "获取联系人异常,Err:" + err.Error()
  1428. return
  1429. }
  1430. //产品权限
  1431. productId := services.GetProductId(sysUser.RoleTypeCode)
  1432. //操作权限校验
  1433. errMsg, err := checkOpCompanyUserByUserId(req.UserId, productId, sysUser.AdminId, sysUser.RoleTypeCode)
  1434. if err != nil {
  1435. br.Msg = "删除失败!" + errMsg
  1436. br.ErrMsg = "删除失败,Err:" + err.Error()
  1437. return
  1438. }
  1439. userRelationList := make([]*models.UserSellerRelation, 0)
  1440. //如果不是超管权限,那么删除的时候,需要获取下联系人归属销售信息
  1441. if productId != 0 {
  1442. tmpUserRelationList, err := models.GetUserSellerRelationList(req.UserId)
  1443. if err != nil {
  1444. br.Msg = "删除失败"
  1445. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  1446. return
  1447. }
  1448. if len(tmpUserRelationList) > 0 {
  1449. userRelationList = append(userRelationList, tmpUserRelationList...)
  1450. }
  1451. }
  1452. //联系人与销售的关系
  1453. userSellerRelationList, err := models.GetUserSellerRelationList(int(userInfo.UserId))
  1454. if err != nil {
  1455. return
  1456. }
  1457. userSellerRelationInfo, _ := json.Marshal(userSellerRelationList)
  1458. //删除所有的标识,并真正删除数据
  1459. _ = models.DeleteUserSellerRelationByProductId(req.UserId, 1)
  1460. _ = models.DeleteUserSellerRelationByProductId(req.UserId, 2)
  1461. //真正删除用户
  1462. err = services.DeleteWxUser(req.UserId)
  1463. if err != nil {
  1464. br.Msg = "删除失败!"
  1465. br.ErrMsg = "删除失败,Err:" + err.Error()
  1466. return
  1467. }
  1468. if len(userRelationList) > 0 {
  1469. companyInfo, err := company.GetCompanyById(userRelationList[0].CompanyId)
  1470. if err != nil {
  1471. return
  1472. }
  1473. content := fmt.Sprint("联系人:", userInfo.RealName, "被删除")
  1474. if companyInfo != nil {
  1475. content = fmt.Sprint(companyInfo.CompanyName, ":", content)
  1476. }
  1477. for _, userRelation := range userRelationList {
  1478. if userRelation.ProductId != productId {
  1479. go services.AddCompanyMessage(sysUser.AdminId, userRelation.SellerId, userRelation.CompanyId, 0, 1, companyInfo.CompanyName, content, content)
  1480. }
  1481. }
  1482. }
  1483. //更新客户最近阅读次数以及最近阅读时间
  1484. go services.ModifyCompanyProductLastViewData([]int{userInfo.CompanyId})
  1485. //联系人信息
  1486. originalUserInfo, _ := json.Marshal(userInfo)
  1487. go services.AddWxUserOpLog(company.WxUserOpLog{
  1488. LogType: "delete",
  1489. UserId: int(userInfo.UserId),
  1490. CompanyId: userInfo.CompanyId,
  1491. Mobile: userInfo.Mobile,
  1492. Email: userInfo.Email,
  1493. OriginalUserInfo: string(originalUserInfo),
  1494. UserInfo: "",
  1495. OriginalUserSellerInfo: string(userSellerRelationInfo),
  1496. UserSellerInfo: "",
  1497. OpUserId: sysUser.AdminId,
  1498. OpUserName: sysUser.RealName,
  1499. CreateTime: time.Now(),
  1500. })
  1501. // 若该联系人为弘则研究公司下的,则同步禁用手机号关联的系统管理员
  1502. if userInfo.CompanyId == 16 {
  1503. go services.ForbiddenSysUserByMobile(userInfo.Mobile)
  1504. }
  1505. br.Ret = 200
  1506. br.Success = true
  1507. br.Msg = "删除成功"
  1508. br.IsAddLog = true
  1509. }
  1510. // @Title 编辑客户联系人
  1511. // @Description 编辑客户联系人接口
  1512. // @Param request body company.EditUserReq true "type json string"
  1513. // @router /user/edit [post]
  1514. func (this *CompanyUserController) EditUser() {
  1515. br := new(models.BaseResponse).Init()
  1516. defer func() {
  1517. this.Data["json"] = br
  1518. this.ServeJSON()
  1519. }()
  1520. sysUser := this.SysUser
  1521. if sysUser == nil {
  1522. br.Msg = "请登录"
  1523. br.ErrMsg = "请登录,SysUser Is Empty"
  1524. br.Ret = 408
  1525. return
  1526. }
  1527. var req company.EditUserReq
  1528. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1529. if err != nil {
  1530. br.Msg = "参数解析异常!"
  1531. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1532. return
  1533. }
  1534. if req.UserId <= 0 {
  1535. br.Msg = "参数错误!"
  1536. return
  1537. }
  1538. //移除空格
  1539. req.MobileOne = utils.TrimStr(req.MobileOne)
  1540. req.MobileTwo = utils.TrimStr(req.MobileTwo)
  1541. req.Email = utils.TrimStr(req.Email)
  1542. req.RealName = utils.TrimStr(req.RealName)
  1543. productId := services.GetProductId(sysUser.RoleTypeCode)
  1544. //操作权限校验
  1545. wxUser, err := models.GetWxUserByUserId(req.UserId)
  1546. if err != nil {
  1547. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1548. br.Msg = "获取信息失败"
  1549. return
  1550. }
  1551. //获取当前操作员产品权限
  1552. companyProductList, productErr := getSysCompanyProductList(productId, wxUser.CompanyId)
  1553. if productErr != nil {
  1554. br.Msg = "编辑失败!获取当前操作员产品权限异常"
  1555. br.ErrMsg = "获取当前操作员产品权限异常,Err:" + productErr.Error()
  1556. return
  1557. }
  1558. if companyProductList == nil {
  1559. br.Msg = "编辑失败!获取当前操作员找不到产品权限"
  1560. br.ErrMsg = "获取当前操作员找不到产品权限"
  1561. return
  1562. }
  1563. //操作权限校验
  1564. for _, v := range companyProductList {
  1565. companyUserStatus := services.CheckCompanyUserButton(sysUser.RoleTypeCode, v.SellerId, sysUser.AdminId, v.ProductId, v.ShareSellerId, v.Status)
  1566. if v.ShareSellerId == sysUser.AdminId {
  1567. companyUserStatus = true
  1568. }
  1569. if companyUserStatus == false {
  1570. br.Msg = "没有操作权限"
  1571. br.ErrMsg = "没有操作权限"
  1572. return
  1573. }
  1574. }
  1575. if req.RealName == "" {
  1576. br.Msg = "请填写姓名"
  1577. return
  1578. }
  1579. oldWxUser := *wxUser //旧的联系人信息(赋值,而不是赋址)
  1580. if req.MobileOne == "" && req.Email == "" {
  1581. br.Msg = "请输入手机号或邮箱"
  1582. return
  1583. }
  1584. //不是管理员的情况下://手机号邮箱填写校验
  1585. if productId != 0 {
  1586. companyInfo, err := company.GetCompanyById(req.CompanyId)
  1587. if err != nil {
  1588. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1589. br.Msg = "获取客户信息失败"
  1590. return
  1591. }
  1592. for _, v := range companyProductList {
  1593. //权益(海外)客户,需要有提示
  1594. if v.ProductId == 2 && companyInfo.RegionType == "海外" {
  1595. if req.MobileOne == "" {
  1596. br.Msg = "请输入手机号"
  1597. }
  1598. if req.Email == "" {
  1599. br.Msg = "请输入邮箱"
  1600. br.ErrMsg = "请输入邮箱"
  1601. return
  1602. }
  1603. }
  1604. }
  1605. }
  1606. if req.MobileOne != "" && req.MobileOne != wxUser.Mobile {
  1607. mobileOneItem, err := company.GetUserCountByMobile(req.MobileOne)
  1608. if err != nil && err.Error() == utils.ErrNoRow() {
  1609. mobileOneItem, err = company.CheckCompanyUserCountByMobileTwo(req.MobileOne)
  1610. if err != nil && err.Error() != utils.ErrNoRow() {
  1611. br.Msg = "编辑失败"
  1612. br.ErrMsg = "判断手机号是否存在,Err:" + err.Error()
  1613. return
  1614. }
  1615. }
  1616. if mobileOneItem != nil {
  1617. if mobileOneItem.UserId > 0 {
  1618. if req.CompanyId > 0 {
  1619. //获取联系人分组信息
  1620. userSellerGroupInfo, err := models.GetUserGroupSellerByUserId(int(mobileOneItem.UserId))
  1621. if err != nil && err.Error() != utils.ErrNoRow() {
  1622. br.Msg = "查询信息异常"
  1623. br.Success = true
  1624. br.Data = mobileOneItem
  1625. br.IsSendEmail = false
  1626. br.Ret = 600
  1627. return
  1628. }
  1629. if req.CompanyId == mobileOneItem.CompanyId {
  1630. //修改返回给前端用户的信息
  1631. if userSellerGroupInfo != nil {
  1632. mobileOneItem.SellerRealName = userSellerGroupInfo.SellerRealName
  1633. mobileOneItem.Status = userSellerGroupInfo.Status
  1634. }
  1635. br.Msg = "手机号1已存在"
  1636. br.Success = true
  1637. br.Data = mobileOneItem
  1638. br.IsSendEmail = false
  1639. br.Ret = 600
  1640. return
  1641. } else {
  1642. hasMove := true //是否可移动
  1643. //如果是大于 1 的客户,那么就是非潜在客户,需要去查询对应的销售
  1644. if mobileOneItem.CompanyId > 1 {
  1645. //获取联系人分组信息
  1646. userSellerGroupInfoList, err := models.GetUserGroupSellersByUserId(int(mobileOneItem.UserId))
  1647. //根据分组校验
  1648. if err == nil && len(userSellerGroupInfoList) > 0 {
  1649. sellerMap := make(map[int]string) //销售信息map
  1650. sellerNameSlice := make([]string, 0) //销售姓名切片
  1651. statusNameSlice := make([]string, 0) //客户状态姓名切片
  1652. for _, v := range userSellerGroupInfoList {
  1653. if v.Status != utils.COMPANY_STATUS_LOSE && v.Status != utils.COMPANY_STATUS_FOREVER && hasMove == true {
  1654. hasMove = false
  1655. }
  1656. statusNameSlice = append(statusNameSlice, v.Status)
  1657. if _, ok := sellerMap[v.SellerId]; ok {
  1658. continue
  1659. }
  1660. sellerMap[v.SellerId] = v.SellerRealName
  1661. sellerNameSlice = append(sellerNameSlice, v.SellerRealName)
  1662. }
  1663. mobileOneItem.SellerRealName = strings.Join(sellerNameSlice, "/")
  1664. mobileOneItem.Status = strings.Join(statusNameSlice, "/")
  1665. }
  1666. }
  1667. //是否可移动
  1668. mobileOneItem.HasMove = hasMove
  1669. br.Msg = "手机号1已存在"
  1670. br.Success = true
  1671. br.Data = mobileOneItem
  1672. br.IsSendEmail = false
  1673. br.Ret = 600
  1674. return
  1675. }
  1676. } else {
  1677. if strings.Contains(mobileOneItem.Status, "/") {
  1678. if strings.Contains(mobileOneItem.Status, "正式") || strings.Contains(mobileOneItem.Status, "试用") {
  1679. mobileOneItem.HasMove = false
  1680. } else {
  1681. mobileOneItem.HasMove = true
  1682. }
  1683. } else {
  1684. if mobileOneItem.Status == utils.COMPANY_STATUS_FREEZE || //冻结
  1685. mobileOneItem.Status == utils.COMPANY_STATUS_LOSE || //流失
  1686. mobileOneItem.Status == utils.COMPANY_STATUS_POTENTIAL || //潜在
  1687. mobileOneItem.Status == utils.COMPANY_STATUS_FOREVER { //永续
  1688. mobileOneItem.HasMove = true
  1689. }
  1690. }
  1691. br.Msg = "手机号1已存在"
  1692. br.Success = true
  1693. br.Data = mobileOneItem
  1694. br.IsSendEmail = false
  1695. br.Ret = 600
  1696. return
  1697. }
  1698. }
  1699. }
  1700. }
  1701. //手机号2校验(不需要修改,修改时间:2021年03月09日11:23:37)
  1702. /*if req.MobileTwo != "" && req.MobileTwo != wxUser.MobileTwo {
  1703. mobileTwoItem, err := company.GetUserCountByMobile(req.MobileTwo)
  1704. if err != nil && err.Error() == utils.ErrNoRow() {
  1705. mobileTwoItem, err = company.CheckCompanyUserCountByMobileTwo(req.MobileTwo)
  1706. if err != nil && err.Error() != utils.ErrNoRow() {
  1707. br.Msg = "编辑失败"
  1708. br.ErrMsg = "判断手机号2是否存在,Err:" + err.Error()
  1709. return
  1710. }
  1711. }
  1712. if mobileTwoItem != nil {
  1713. if mobileTwoItem.UserId > 0 {
  1714. if req.CompanyId > 0 {
  1715. if req.CompanyId == mobileTwoItem.CompanyId {
  1716. br.Msg = "手机号2已存在"
  1717. br.Success = true
  1718. br.Data = mobileTwoItem
  1719. br.IsSendEmail = false
  1720. br.Ret = 600
  1721. return
  1722. } else {
  1723. if strings.Contains(mobileTwoItem.Status, "/") {
  1724. if strings.Contains(mobileTwoItem.Status, "正式") || strings.Contains(mobileTwoItem.Status, "试用") {
  1725. mobileTwoItem.HasMove = false
  1726. } else {
  1727. mobileTwoItem.HasMove = true
  1728. }
  1729. } else {
  1730. if mobileTwoItem.Status == utils.COMPANY_STATUS_FREEZE || //冻结
  1731. mobileTwoItem.Status == utils.COMPANY_STATUS_LOSE || //流失
  1732. mobileTwoItem.Status == utils.COMPANY_STATUS_POTENTIAL || //潜在
  1733. mobileTwoItem.Status == utils.COMPANY_STATUS_FOREVER { //永续
  1734. mobileTwoItem.HasMove = true
  1735. }
  1736. }
  1737. br.Msg = "手机号2已存在"
  1738. br.Success = true
  1739. br.Data = mobileTwoItem
  1740. br.IsSendEmail = false
  1741. br.Ret = 600
  1742. return
  1743. }
  1744. } else {
  1745. if strings.Contains(mobileTwoItem.Status, "/") {
  1746. if strings.Contains(mobileTwoItem.Status, "正式") || strings.Contains(mobileTwoItem.Status, "试用") {
  1747. mobileTwoItem.HasMove = false
  1748. } else {
  1749. mobileTwoItem.HasMove = true
  1750. }
  1751. } else {
  1752. if mobileTwoItem.Status == utils.COMPANY_STATUS_FREEZE || //冻结
  1753. mobileTwoItem.Status == utils.COMPANY_STATUS_LOSE || //流失
  1754. mobileTwoItem.Status == utils.COMPANY_STATUS_POTENTIAL || //潜在
  1755. mobileTwoItem.Status == utils.COMPANY_STATUS_FOREVER { //永续
  1756. mobileTwoItem.HasMove = true
  1757. }
  1758. }
  1759. br.Msg = "手机号2已存在"
  1760. br.Success = true
  1761. br.Data = mobileTwoItem
  1762. br.IsSendEmail = false
  1763. br.Ret = 600
  1764. return
  1765. }
  1766. }
  1767. }
  1768. }*/
  1769. if req.Email != "" && req.Email != wxUser.Email {
  1770. emailItem, err := company.CheckCompanyUserCountByEmail(req.Email)
  1771. if err != nil && err.Error() != utils.ErrNoRow() {
  1772. br.Msg = "编辑失败"
  1773. br.ErrMsg = "编辑失败,Err:" + err.Error()
  1774. return
  1775. }
  1776. if emailItem != nil {
  1777. if emailItem.UserId > 0 {
  1778. //获取联系人分组信息
  1779. userSellerGroupInfo, err := models.GetUserGroupSellerByUserId(int(emailItem.UserId))
  1780. if err != nil && err.Error() != utils.ErrNoRow() {
  1781. br.Msg = "查询信息异常"
  1782. br.Success = true
  1783. br.Data = emailItem
  1784. br.IsSendEmail = false
  1785. br.Ret = 600
  1786. return
  1787. }
  1788. if req.CompanyId == emailItem.CompanyId {
  1789. //修改返回给前端用户的信息
  1790. if userSellerGroupInfo != nil {
  1791. emailItem.SellerRealName = userSellerGroupInfo.SellerRealName
  1792. emailItem.Status = userSellerGroupInfo.Status
  1793. }
  1794. br.Msg = "邮箱已存在"
  1795. br.Success = true
  1796. br.Data = emailItem
  1797. br.IsSendEmail = false
  1798. br.Ret = 600
  1799. return
  1800. } else {
  1801. hasMove := true //是否可移动
  1802. //如果是大于 1 的客户,那么就是非潜在客户,需要去查询对应的销售
  1803. if emailItem.CompanyId > 1 {
  1804. //获取联系人分组信息
  1805. userSellerGroupInfoList, err := models.GetUserGroupSellersByUserId(int(emailItem.UserId))
  1806. //根据分组校验
  1807. if err == nil && len(userSellerGroupInfoList) > 0 {
  1808. sellerMap := make(map[int]string) //销售信息map
  1809. sellerNameSlice := make([]string, 0) //销售姓名切片
  1810. statusNameSlice := make([]string, 0) //客户状态姓名切片
  1811. for _, v := range userSellerGroupInfoList {
  1812. if v.Status != utils.COMPANY_STATUS_LOSE && v.Status != utils.COMPANY_STATUS_FOREVER && hasMove == true {
  1813. hasMove = false
  1814. }
  1815. statusNameSlice = append(statusNameSlice, v.Status)
  1816. if _, ok := sellerMap[v.SellerId]; ok {
  1817. continue
  1818. }
  1819. sellerMap[v.SellerId] = v.SellerRealName
  1820. sellerNameSlice = append(sellerNameSlice, v.SellerRealName)
  1821. }
  1822. emailItem.SellerRealName = strings.Join(sellerNameSlice, "/")
  1823. emailItem.Status = strings.Join(statusNameSlice, "/")
  1824. }
  1825. }
  1826. //是否可移动
  1827. emailItem.HasMove = hasMove
  1828. br.Msg = "邮箱已存在"
  1829. br.Success = true
  1830. br.Data = emailItem
  1831. br.IsSendEmail = false
  1832. br.Ret = 600
  1833. return
  1834. }
  1835. } else {
  1836. if strings.Contains(emailItem.Status, "/") {
  1837. if strings.Contains(emailItem.Status, "正式") || strings.Contains(emailItem.Status, "试用") {
  1838. emailItem.HasMove = false
  1839. } else {
  1840. emailItem.HasMove = true
  1841. }
  1842. } else {
  1843. if emailItem.Status == utils.COMPANY_STATUS_FREEZE || //冻结
  1844. emailItem.Status == utils.COMPANY_STATUS_LOSE || //流失
  1845. emailItem.Status == utils.COMPANY_STATUS_POTENTIAL || //潜在
  1846. emailItem.Status == utils.COMPANY_STATUS_FOREVER { //永续
  1847. emailItem.HasMove = true
  1848. }
  1849. }
  1850. br.Msg = "邮箱已存在"
  1851. br.Success = true
  1852. br.Data = emailItem
  1853. br.IsSendEmail = false
  1854. br.Ret = 600
  1855. return
  1856. }
  1857. }
  1858. }
  1859. //if wxUser.BusinessCardUrl != req.BusinessCardUrl && utils.RunMode == "release" {
  1860. if wxUser.BusinessCardUrl != req.BusinessCardUrl {
  1861. // 获取图片识别客户名称的配置
  1862. crmConfig, err := company.GetConfigDetailByCode("card_recognition_company_name")
  1863. if err != nil {
  1864. br.Msg = "获取配置失败"
  1865. br.ErrMsg = "获取配置失败"
  1866. br.IsSendEmail = false
  1867. return
  1868. }
  1869. // 获取图片识别手机号的配置
  1870. crmConfig2, err := company.GetConfigDetailByCode("card_recognition_tel")
  1871. if err != nil {
  1872. br.Msg = "获取配置失败"
  1873. br.ErrMsg = "获取配置失败"
  1874. br.IsSendEmail = false
  1875. return
  1876. }
  1877. if crmConfig.ConfigValue == "true" || crmConfig2.ConfigValue == "true" {
  1878. //companyName := wxUser.CompanyName
  1879. //if companyName == "" {
  1880. companyInfo, err := company.GetCompanyById(req.CompanyId)
  1881. if err != nil {
  1882. br.Msg = "查找客户失败"
  1883. br.ErrMsg = "查找客户失败,err:" + err.Error()
  1884. return
  1885. }
  1886. companyName := companyInfo.CompanyName
  1887. //}
  1888. companyName = utils.TrimStr(companyName)
  1889. tmpCompanyNameList, err := elastic.Analyze(companyName)
  1890. if err != nil {
  1891. br.Msg = "添加失败"
  1892. br.ErrMsg = "客户名称分词失败,Err:" + err.Error()
  1893. return
  1894. }
  1895. //公司名称切片
  1896. analyzeNameList := []string{companyName}
  1897. for _, v := range tmpCompanyNameList {
  1898. if v == "" {
  1899. continue
  1900. }
  1901. ignoreStrs := []string{"", "有限", "投资", "资本", "管理", "贸易", "资产", "公司", "股份", "集团", "有限公司"}
  1902. if !strings.Contains(strings.Join(ignoreStrs, ","), v) && utf8.RuneCount([]byte(v)) > 1 {
  1903. //不在上面的过滤字里面,且切出来的字符大于1位
  1904. analyzeNameList = append(analyzeNameList, v)
  1905. }
  1906. }
  1907. //名片识别出来的客户名称切片
  1908. companyNameSlice := make([]string, 0)
  1909. card, err := services.GetBusinessCard(req.BusinessCardUrl)
  1910. if err != nil {
  1911. br.Msg = "名片识别失败"
  1912. br.ErrMsg = "名片识别失败,Err:" + err.Error()
  1913. return
  1914. }
  1915. //if card.Errno != 0 {
  1916. // br.Msg = "您上传了非名片图片,请重新上传"
  1917. // br.ErrMsg = "名片识别失败,ErrMsg:" + card.ErrorMsg + ";errCode:" + strconv.Itoa(card.Errno)
  1918. // return
  1919. //}
  1920. //var mobileStr string
  1921. //for _, v := range card.WordsResult {
  1922. // mobileStr += v.Words + ","
  1923. //}
  1924. isFlag := false
  1925. if len(card.WordsResult.MOBILE) > 0 {
  1926. mobileStr := strings.Join(card.WordsResult.MOBILE, ",")
  1927. //if req.MobileOne != "" {
  1928. // if strings.Contains(mobileStr, req.MobileOne) || mobileStr == "" {
  1929. // isFlag = true
  1930. // } else {
  1931. // isFlag = false
  1932. // }
  1933. //}
  1934. //
  1935. //if isFlag == false && req.MobileTwo != "" {
  1936. // if strings.Contains(mobileStr, req.MobileTwo) {
  1937. // isFlag = true
  1938. // } else {
  1939. // isFlag = false
  1940. // }
  1941. //}
  1942. if req.MobileOne != "" && strings.Contains(mobileStr, req.MobileOne) {
  1943. isFlag = true
  1944. }
  1945. if req.MobileTwo != "" && strings.Contains(mobileStr, req.MobileTwo) {
  1946. isFlag = true
  1947. }
  1948. //如果百度识别出来了客户名称,那么将识别出来的客户名称添加到待校验客户名称切片中
  1949. if len(card.WordsResult.COMPANY) > 0 && card.WordsResult.COMPANY[0] != "" {
  1950. companyNameSlice = card.WordsResult.COMPANY
  1951. }
  1952. }
  1953. //如果百度未识别出来手机号或者公司名称,那么进行阿里识别
  1954. if !isFlag || (len(companyNameSlice) == 0 && crmConfig.ConfigValue == "true") {
  1955. //阿里云识别
  1956. aliyunResult, errMsg, err := services.AliyunOcrBusinessCard(req.BusinessCardUrl)
  1957. if err != nil {
  1958. br.Msg = "识别失败"
  1959. br.ErrMsg = "识别失败,Err:" + err.Error()
  1960. return
  1961. }
  1962. if !aliyunResult.Success {
  1963. br.Msg = "识别失败"
  1964. br.ErrMsg = "识别失败"
  1965. return
  1966. }
  1967. if errMsg != "" {
  1968. br.Msg = errMsg
  1969. return
  1970. }
  1971. //如果百度没有识别出来手机号,那么还需要阿里识别出来的手机号校验下
  1972. if !isFlag {
  1973. if len(aliyunResult.TelCell) > 0 {
  1974. mobileStr := strings.Join(aliyunResult.TelCell, ",")
  1975. if req.MobileOne != "" {
  1976. if strings.Contains(mobileStr, req.MobileOne) {
  1977. isFlag = true
  1978. } else {
  1979. isFlag = false
  1980. }
  1981. }
  1982. } else {
  1983. isFlag = true
  1984. }
  1985. }
  1986. //如果阿里云识别出来了客户名称,那么将识别出来的客户名称添加到待校验客户名称切片中
  1987. if len(aliyunResult.Company) > 0 {
  1988. companyNameSlice = append(companyNameSlice, aliyunResult.Company...)
  1989. }
  1990. }
  1991. if !isFlag && crmConfig2.ConfigValue == "true" {
  1992. br.Msg = "名片信息与联系人手机号不符"
  1993. br.IsSendEmail = false
  1994. return
  1995. }
  1996. //校验识别出来的名片名称与传入的客户名称是否一致
  1997. if len(companyNameSlice) > 0 && crmConfig.ConfigValue == "true" {
  1998. isCompanyNameFlag := false //是否成功匹配客户名称
  1999. //遍历识别出来的客户名称,然后与系统的客户名称做匹配(识别出来的名称包含系统名称的话,那么标记成功匹配)
  2000. for _, tmpCompanyName := range companyNameSlice {
  2001. //空串不处理
  2002. if companyName == "" {
  2003. continue
  2004. }
  2005. for _, analyzeName := range analyzeNameList {
  2006. //如果分词出来的公司名称正好在识别出来的公司名称里面,那么就认为校验通过了
  2007. if strings.Contains(tmpCompanyName, analyzeName) {
  2008. isCompanyNameFlag = true
  2009. break
  2010. }
  2011. }
  2012. if isCompanyNameFlag {
  2013. break
  2014. }
  2015. }
  2016. //如果没有匹配到客户名称,那么就返回报错
  2017. if !isCompanyNameFlag {
  2018. br.Msg = "名片信息与公司名称不符"
  2019. br.IsSendEmail = false
  2020. return
  2021. }
  2022. }
  2023. }
  2024. }
  2025. //UPDATE wx_user
  2026. // SET
  2027. // last_updated_time = NOW(),
  2028. // position = ?,
  2029. // is_maker = ?,
  2030. // business_card_url = ?,
  2031. // mobile_two= ?,
  2032. // department_name=?,
  2033. // company_id=?,country_code=?
  2034. //待更新字段
  2035. updateCol := []string{"RealName", "Mobile", "MobileTwo", "Email", "Sex", "LastUpdatedTime", "Position", "IsMaker", "BusinessCardUrl", "DepartmentName", "CompanyId", "CountryCode"}
  2036. //外呼手机号、外呼手机号区号
  2037. if wxUser.OutboundMobile == "" || wxUser.OutboundMobile == wxUser.Mobile {
  2038. wxUser.OutboundMobile = req.MobileOne
  2039. wxUser.OutboundCountryCode = req.CountryCode
  2040. //外呼字段数据修改
  2041. updateCol = append(updateCol, "OutboundMobile", "OutboundCountryCode")
  2042. }
  2043. wxUser.RealName = req.RealName
  2044. wxUser.Mobile = req.MobileOne
  2045. wxUser.MobileTwo = req.MobileTwo
  2046. wxUser.Email = req.Email
  2047. wxUser.Sex = req.Sex
  2048. wxUser.LastUpdatedTime = time.Now()
  2049. wxUser.Position = req.Position
  2050. wxUser.IsMaker = req.IsMaker
  2051. wxUser.BusinessCardUrl = req.BusinessCardUrl
  2052. wxUser.DepartmentName = req.DepartmentName
  2053. wxUser.CompanyId = req.CompanyId
  2054. wxUser.CountryCode = req.CountryCode
  2055. fmt.Println("wxUser 2", wxUser)
  2056. err = wxUser.Update(updateCol)
  2057. //err = company.EditCompanyUser(&req)
  2058. if err != nil {
  2059. br.Msg = "编辑失败!"
  2060. br.ErrMsg = "编辑失败,Err:" + err.Error()
  2061. return
  2062. }
  2063. //更新客户最近阅读次数以及最近阅读时间
  2064. go services.ModifyCompanyProductLastViewData([]int{wxUser.CompanyId})
  2065. //联系人信息
  2066. originalUserInfo, _ := json.Marshal(oldWxUser)
  2067. userInfo, _ := json.Marshal(wxUser)
  2068. go services.AddWxUserOpLog(company.WxUserOpLog{
  2069. LogType: "edit",
  2070. UserId: int(wxUser.UserId),
  2071. CompanyId: wxUser.CompanyId,
  2072. Mobile: wxUser.Mobile,
  2073. Email: wxUser.Email,
  2074. OriginalUserInfo: string(originalUserInfo),
  2075. UserInfo: string(userInfo),
  2076. OriginalUserSellerInfo: "",
  2077. UserSellerInfo: "",
  2078. OpUserId: sysUser.AdminId,
  2079. OpUserName: sysUser.RealName,
  2080. CreateTime: time.Now(),
  2081. })
  2082. br.Ret = 200
  2083. br.Success = true
  2084. br.Msg = "编辑成功"
  2085. br.IsAddLog = true
  2086. }
  2087. // @Title 潜在用户列表
  2088. // @Description 潜在用户列表接口
  2089. // @Param PageSize query int true "每页数据条数"
  2090. // @Param CurrentIndex query int true "当前页页码,从1开始"
  2091. // @Param ApplyMethod query int true "申请方式,0:全部,1:未申请,2:已付费客户申请试用,3:非客户申请试用"
  2092. // @Param KeyWord query string true "搜索关键词"
  2093. // @Success 200 {object} models.PotentialUserListResp
  2094. // @router /potential/user/list [get]
  2095. func (this *CompanyController) PotentialUserList() {
  2096. br := new(models.BaseResponse).Init()
  2097. defer func() {
  2098. this.Data["json"] = br
  2099. this.ServeJSON()
  2100. }()
  2101. sysUser := this.SysUser
  2102. if sysUser == nil {
  2103. br.Msg = "请登录"
  2104. br.ErrMsg = "请登录,SysUser Is Empty"
  2105. br.Ret = 408
  2106. return
  2107. }
  2108. pageSize, _ := this.GetInt("PageSize")
  2109. currentIndex, _ := this.GetInt("CurrentIndex")
  2110. keyWord := this.GetString("KeyWord")
  2111. applyMethod, _ := this.GetInt("ApplyMethod")
  2112. var startSize int
  2113. if pageSize <= 0 {
  2114. pageSize = utils.PageSize20
  2115. }
  2116. if currentIndex <= 0 {
  2117. currentIndex = 1
  2118. }
  2119. startSize = utils.StartIndex(currentIndex, pageSize)
  2120. var condition string
  2121. var pars []interface{}
  2122. if applyMethod > 0 {
  2123. condition += ` AND apply_method=? `
  2124. pars = append(pars, applyMethod-1)
  2125. }
  2126. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  2127. condition += ` AND apply_method=? `
  2128. pars = append(pars, 1)
  2129. }
  2130. //非管理员不让看数据
  2131. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  2132. list := make([]*models.PotentialUserItem, 0)
  2133. page := paging.GetPaging(currentIndex, pageSize, 0)
  2134. resp := new(models.PotentialUserListResp)
  2135. resp.List = list
  2136. resp.Paging = page
  2137. br.Ret = 200
  2138. br.Success = true
  2139. br.Msg = "获取成功"
  2140. br.Data = resp
  2141. return
  2142. }
  2143. if keyWord != "" {
  2144. condition += ` AND (a.real_name LIKE '%` + keyWord + `%' OR a.mobile LIKE '%` + keyWord + `%' OR a.email LIKE '%` + keyWord + `%') `
  2145. }
  2146. total, err := models.GetPotentialUserListCount(condition, pars)
  2147. if err != nil {
  2148. br.Msg = "获取失败"
  2149. br.ErrMsg = "获取分页数据失败,Err:" + err.Error()
  2150. return
  2151. }
  2152. list, err := models.GetPotentialUserList(condition, pars, startSize, pageSize)
  2153. if err != nil {
  2154. br.Msg = "获取失败"
  2155. br.ErrMsg = "获取失败,Err:" + err.Error()
  2156. return
  2157. }
  2158. listLen := len(list)
  2159. mobilesSlice := make([]string, 0)
  2160. emailsSlice := make([]string, 0)
  2161. for _, v := range list {
  2162. if v.Mobile != "" {
  2163. mobilesSlice = append(mobilesSlice, v.Mobile)
  2164. } else if v.Email != "" {
  2165. emailsSlice = append(emailsSlice, v.Email)
  2166. }
  2167. }
  2168. //用户浏览数据
  2169. mobileStr := strings.Join(mobilesSlice, "','")
  2170. mobileStr = "'" + mobileStr + "'"
  2171. emailStr := strings.Join(emailsSlice, "','")
  2172. emailStr = "'" + emailStr + "'"
  2173. //userViewTotalList, _ := models.GetCountUserViewHistoryByUserIds(userIdStr)
  2174. //userViewTotalMap := make(map[int]*models.UserViewTotalSlice)
  2175. //for _, userView := range userViewTotalList {
  2176. // userViewTotalMap[userView.UserId] = userView
  2177. //}
  2178. //用户日评浏览数据
  2179. //userReportViewTotalList, _ := models.GetReportViewMaxTimeByUserIds(userIdStr)
  2180. //userReportViewTotalMap := make(map[int]*models.ReportViewRecord)
  2181. //for _, userReportView := range userReportViewTotalList {
  2182. // userReportViewTotalMap[userReportView.UserId] = userReportView
  2183. //}
  2184. //手机号
  2185. userViewMobileTotalMap := make(map[string]*models.UserViewMobileTotalSlice)
  2186. userReportViewMobileTotalMap := make(map[string]*models.ReportViewMobileRecord)
  2187. if len(mobilesSlice) > 0 {
  2188. //用户浏览数据
  2189. userViewMobileTotalList, _ := models.GetCountUserViewHistoryByMobiles(mobileStr)
  2190. for _, userViewMobile := range userViewMobileTotalList {
  2191. userViewMobileTotalMap[userViewMobile.Mobile] = userViewMobile
  2192. }
  2193. //每日点评手机号数据
  2194. userReportViewMobileTotalList, _ := models.GetReportViewMaxTimeByMobiles(mobileStr)
  2195. for _, userReportViewMobile := range userReportViewMobileTotalList {
  2196. userReportViewMobileTotalMap[userReportViewMobile.Mobile] = userReportViewMobile
  2197. }
  2198. }
  2199. //邮箱
  2200. userViewEmailTotalMap := make(map[string]*models.UserViewEmailTotalSlice)
  2201. userReportViewEmailTotalMap := make(map[string]*models.ReportViewEmailRecord)
  2202. if len(emailsSlice) > 0 {
  2203. //用户浏览数据
  2204. userViewEmailTotalList, _ := models.GetCountUserViewHistoryByEmails(emailStr)
  2205. for _, userViewEmail := range userViewEmailTotalList {
  2206. userViewEmailTotalMap[userViewEmail.Email] = userViewEmail
  2207. }
  2208. //每日点评手机号数据
  2209. userReportViewEmailTotalList, _ := models.GetReportViewMaxTimeByEmails(emailStr)
  2210. for _, userReportViewEmail := range userReportViewEmailTotalList {
  2211. userReportViewEmailTotalMap[userReportViewEmail.Email] = userReportViewEmail
  2212. }
  2213. }
  2214. for i := 0; i < listLen; i++ {
  2215. item := list[i]
  2216. //item, err := models.GetReportViewMaxTime(list[i].UserId)
  2217. //if err != nil {
  2218. // br.Msg = "获取失败"
  2219. // br.ErrMsg = "获取GetReportViewMaxTime失败,Err:" + err.Error()
  2220. // return
  2221. //}
  2222. //list[i].ViewTotal += item.ViewTotal
  2223. //手机号用户累计浏览次数
  2224. if userView, ok := userViewMobileTotalMap[item.Mobile]; ok {
  2225. list[i].ViewTotal += userView.Total
  2226. if userView.CreatedTime.After(list[i].LastViewTime) {
  2227. list[i].LastViewTime = userView.CreatedTime
  2228. list[i].LastViewTimeStr = userView.CreatedTime.Format(utils.FormatDateTime)
  2229. }
  2230. }
  2231. //邮箱用户累计浏览次数
  2232. if userView, ok := userViewEmailTotalMap[item.Email]; ok {
  2233. //总共浏览的报表数据需要调整为(手机号用户浏览晨报数+邮箱号用户浏览晨报数)
  2234. list[i].ViewTotal += userView.Total
  2235. if userView.CreatedTime.After(list[i].LastViewTime) {
  2236. list[i].LastViewTime = userView.CreatedTime
  2237. list[i].LastViewTimeStr = userView.CreatedTime.Format(utils.FormatDateTime)
  2238. }
  2239. }
  2240. //如果存在手机号用户日评数据,那么需要做处理
  2241. if reportView, ok := userReportViewMobileTotalMap[item.Mobile]; ok {
  2242. //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
  2243. if reportView.LastViewTime.After(list[i].LastViewTime) {
  2244. list[i].LastViewTime = reportView.LastViewTime
  2245. list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
  2246. }
  2247. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
  2248. list[i].ViewTotal += reportView.ViewTotal
  2249. }
  2250. //如果存在手机号用户日评数据,那么需要做处理
  2251. if reportView, ok := userReportViewEmailTotalMap[item.Email]; ok {
  2252. //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
  2253. if reportView.LastViewTime.After(list[i].LastViewTime) {
  2254. list[i].LastViewTime = reportView.LastViewTime
  2255. list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
  2256. }
  2257. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
  2258. list[i].ViewTotal += reportView.ViewTotal
  2259. }
  2260. }
  2261. page := paging.GetPaging(currentIndex, pageSize, total)
  2262. resp := new(models.PotentialUserListResp)
  2263. resp.List = list
  2264. resp.Paging = page
  2265. br.Ret = 200
  2266. br.Success = true
  2267. br.Msg = "获取成功"
  2268. br.Data = resp
  2269. }
  2270. // @Title 标记潜在用户
  2271. // @Description 标记潜在用户接口
  2272. // @Param request body models.PotentialUserDealReq true "type json string"
  2273. // @Success Ret=200 标记成功
  2274. // @router /potential/user/deal [post]
  2275. func (this *CompanyController) PotentialUserDeal() {
  2276. br := new(models.BaseResponse).Init()
  2277. defer func() {
  2278. this.Data["json"] = br
  2279. this.ServeJSON()
  2280. }()
  2281. var req models.PotentialUserDealReq
  2282. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2283. if err != nil {
  2284. br.Msg = "参数解析异常!"
  2285. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2286. return
  2287. }
  2288. sysUser := this.SysUser
  2289. if sysUser == nil {
  2290. br.Msg = "请登录"
  2291. br.ErrMsg = "请登录,SysUser Is Empty"
  2292. br.Ret = 408
  2293. return
  2294. }
  2295. // 标记处理
  2296. err = services.DealPotentialUser(req.UserId, sysUser.AdminId)
  2297. if err != nil {
  2298. br.Msg = "标记失败"
  2299. br.ErrMsg = "标记失败,Err:" + err.Error()
  2300. return
  2301. }
  2302. br.Ret = 200
  2303. br.Success = true
  2304. br.Msg = "标记成功"
  2305. }
  2306. // @Title 删除潜在用户
  2307. // @Description 删除潜在用户接口
  2308. // @Param request body models.PotentialUserDeleteReq true "type json string"
  2309. // @Success Ret=200 删除成功
  2310. // @router /potential/user/delete [post]
  2311. func (this *CompanyController) PotentialUserDelete() {
  2312. br := new(models.BaseResponse).Init()
  2313. defer func() {
  2314. this.Data["json"] = br
  2315. this.ServeJSON()
  2316. }()
  2317. var req models.PotentialUserDeleteReq
  2318. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2319. if err != nil {
  2320. br.Msg = "参数解析异常!"
  2321. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2322. return
  2323. }
  2324. sysUser := this.SysUser
  2325. if sysUser == nil {
  2326. br.Msg = "请登录"
  2327. br.ErrMsg = "请登录,SysUser Is Empty"
  2328. br.Ret = 408
  2329. return
  2330. }
  2331. //删除用户
  2332. err = services.DeleteWxUser(req.UserId)
  2333. if err != nil {
  2334. br.Msg = "删除失败"
  2335. br.ErrMsg = "删除失败,Err:" + err.Error()
  2336. return
  2337. }
  2338. br.Ret = 200
  2339. br.Success = true
  2340. br.Msg = "删除成功"
  2341. }
  2342. // @Title 移动潜在用户
  2343. // @Description 移动潜在用户接口
  2344. // @Param request body models.PotentialUserMoveReq true "type json string"
  2345. // @Success Ret=200 移动成功
  2346. // @router /potential/user/move [post]
  2347. func (this *CompanyController) PotentialUserMove() {
  2348. br := new(models.BaseResponse).Init()
  2349. defer func() {
  2350. this.Data["json"] = br
  2351. this.ServeJSON()
  2352. }()
  2353. sysUser := this.SysUser
  2354. if sysUser == nil {
  2355. br.Msg = "请登录"
  2356. br.ErrMsg = "请登录,SysUser Is Empty"
  2357. br.Ret = 408
  2358. return
  2359. }
  2360. var req models.PotentialUserMoveReq
  2361. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2362. if err != nil {
  2363. br.Msg = "参数解析异常!"
  2364. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2365. return
  2366. }
  2367. if req.UserId <= 0 {
  2368. br.Msg = "参数错误"
  2369. br.ErrMsg = "客户id错误"
  2370. return
  2371. }
  2372. //如果移动客户编号小于等于0,那么移动到潜在客户
  2373. if req.CompanyId <= 0 {
  2374. req.CompanyId = 1
  2375. }
  2376. wxUser, err := models.GetWxUserByUserId(req.UserId)
  2377. if err != nil {
  2378. br.Msg = "移动失败"
  2379. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  2380. return
  2381. }
  2382. oldWxUser := *wxUser
  2383. if req.Mobile == "" {
  2384. req.Mobile = wxUser.Mobile
  2385. }
  2386. if req.Email == "" {
  2387. req.Email = wxUser.Email
  2388. }
  2389. if req.Mobile == "" && req.Email == "" {
  2390. br.Msg = "手机号和邮箱不能同时为空"
  2391. return
  2392. }
  2393. //校验手机号
  2394. if req.Mobile != "" && wxUser.Mobile != req.Mobile {
  2395. count, err := models.CheckUserMobileIsRegister(req.UserId, req.Mobile)
  2396. if err != nil {
  2397. br.Msg = "校验数据失败"
  2398. br.ErrMsg = "校验数据失败,Err:" + err.Error()
  2399. return
  2400. }
  2401. if count > 0 {
  2402. br.Msg = "该手机号已经注册过用户"
  2403. return
  2404. }
  2405. }
  2406. //校验邮箱
  2407. if req.Email != "" && wxUser.Email != req.Email {
  2408. if !utils.ValidateEmailFormatat(req.Email) {
  2409. br.Msg = "请输入正确的邮箱(包含@)"
  2410. return
  2411. }
  2412. count, err := models.CheckUserEmailIsRegister(req.UserId, req.Email)
  2413. if err != nil {
  2414. br.Msg = "校验数据失败"
  2415. br.ErrMsg = "校验数据失败,Err:" + err.Error()
  2416. return
  2417. }
  2418. if count > 0 {
  2419. br.Msg = "该邮箱已经注册过用户"
  2420. br.IsSendEmail = false
  2421. return
  2422. }
  2423. }
  2424. updateCol := make([]string, 0)
  2425. if wxUser.OutboundMobile == "" || wxUser.Mobile == wxUser.OutboundMobile {
  2426. wxUser.OutboundMobile = req.Mobile
  2427. wxUser.OutboundCountryCode = req.CountryCode
  2428. updateCol = append(updateCol, "OutboundMobile", "OutboundCountryCode")
  2429. }
  2430. if req.Email != "" {
  2431. wxUser.Email = req.Email
  2432. updateCol = append(updateCol, "Email")
  2433. }
  2434. if req.RealName != "" {
  2435. wxUser.RealName = req.RealName
  2436. updateCol = append(updateCol, "RealName")
  2437. }
  2438. if req.Mobile != "" {
  2439. wxUser.Mobile = req.Mobile
  2440. updateCol = append(updateCol, "Mobile")
  2441. }
  2442. if req.CountryCode != "" {
  2443. wxUser.CountryCode = req.CountryCode
  2444. updateCol = append(updateCol, "CountryCode")
  2445. }
  2446. if req.Position != "" {
  2447. wxUser.Position = req.Position
  2448. updateCol = append(updateCol, "Position")
  2449. }
  2450. if wxUser.DepartmentName == "" && req.DepartmentName != "" {
  2451. wxUser.DepartmentName = req.DepartmentName
  2452. updateCol = append(updateCol, "DepartmentName")
  2453. }
  2454. wxUser.Sex = req.Sex
  2455. wxUser.IsMaker = req.IsMaker
  2456. updateCol = append(updateCol, "Sex", "IsMaker")
  2457. //名片匹配
  2458. if req.BusinessCardUrl != "" {
  2459. //if req.BusinessCardUrl != "" && utils.RunMode == "release" {
  2460. // 获取图片识别手机号的配置
  2461. crmConfig2, err := company.GetConfigDetailByCode("card_recognition_tel")
  2462. if err != nil {
  2463. br.Msg = "获取配置失败"
  2464. br.ErrMsg = "获取配置失败"
  2465. br.IsSendEmail = false
  2466. return
  2467. }
  2468. if crmConfig2.ConfigValue == "true" {
  2469. card, err := services.GetBusinessCard(req.BusinessCardUrl)
  2470. if err != nil {
  2471. br.Msg = "名片识别失败"
  2472. br.ErrMsg = "名片识别失败,Err:" + err.Error()
  2473. return
  2474. }
  2475. isFlag := false
  2476. if len(card.WordsResult.MOBILE) > 0 {
  2477. mobileStr := strings.Join(card.WordsResult.MOBILE, ",")
  2478. //if req.Mobile != "" {
  2479. // if strings.Contains(mobileStr, req.Mobile) || mobileStr == "" {
  2480. // isFlag = true
  2481. // } else {
  2482. // isFlag = false
  2483. // }
  2484. //}
  2485. if req.Mobile != "" && strings.Contains(mobileStr, req.Mobile) {
  2486. isFlag = true
  2487. }
  2488. }
  2489. if !isFlag {
  2490. //阿里云识别
  2491. //if utils.RunMode == "release" {
  2492. aliyunResult, errMsg, err := services.AliyunOcrBusinessCard(req.BusinessCardUrl)
  2493. if err != nil {
  2494. br.Msg = "识别失败"
  2495. br.ErrMsg = "识别失败,Err:" + err.Error()
  2496. return
  2497. }
  2498. if !aliyunResult.Success {
  2499. br.Msg = "识别失败"
  2500. br.ErrMsg = "识别失败"
  2501. return
  2502. }
  2503. if errMsg != "" {
  2504. br.Msg = errMsg
  2505. return
  2506. }
  2507. if len(aliyunResult.TelCell) > 0 {
  2508. mobileStr := strings.Join(aliyunResult.TelCell, ",")
  2509. if req.Mobile != "" {
  2510. if strings.Contains(mobileStr, req.Mobile) {
  2511. isFlag = true
  2512. } else {
  2513. isFlag = false
  2514. }
  2515. }
  2516. } else {
  2517. isFlag = true
  2518. }
  2519. //}
  2520. }
  2521. if !isFlag && crmConfig2.ConfigValue == "true" {
  2522. br.Msg = "名片信息与联系人手机号不符"
  2523. return
  2524. }
  2525. }
  2526. wxUser.BusinessCardUrl = req.BusinessCardUrl
  2527. updateCol = append(updateCol, "BusinessCardUrl")
  2528. }
  2529. productId := services.GetProductId(sysUser.RoleTypeCode)
  2530. companyProductList, _ := getSysCompanyProductList(productId, req.CompanyId)
  2531. //联系人与销售的关系
  2532. userSellerRelationList, err := models.GetUserSellerRelationList(int(wxUser.UserId))
  2533. if err != nil {
  2534. return
  2535. }
  2536. userSellerRelationInfo, _ := json.Marshal(userSellerRelationList)
  2537. err = services.MovePotentialUser(req.UserId, req.CompanyId, req.RealName, req.Mobile, req.Email, req.Remark, companyProductList, wxUser, updateCol)
  2538. //err = models.MovePotentialUser(req.UserId, req.CompanyId, req.RealName, req.Mobile, req.Email, req.Remark)
  2539. if err != nil {
  2540. br.Msg = "移动失败"
  2541. br.ErrMsg = "移动失败,Err:" + err.Error()
  2542. return
  2543. }
  2544. //更新客户最近阅读次数以及最近阅读时间
  2545. go services.ModifyCompanyProductLastViewData([]int{req.CompanyId})
  2546. //联系人信息
  2547. originalUserInfo, _ := json.Marshal(oldWxUser)
  2548. userInfo, _ := json.Marshal(wxUser)
  2549. go services.AddWxUserOpLog(company.WxUserOpLog{
  2550. LogType: "move",
  2551. UserId: int(wxUser.UserId),
  2552. CompanyId: wxUser.CompanyId,
  2553. Mobile: wxUser.Mobile,
  2554. Email: wxUser.Email,
  2555. OriginalUserInfo: string(originalUserInfo),
  2556. UserInfo: string(userInfo),
  2557. OriginalUserSellerInfo: string(userSellerRelationInfo),
  2558. UserSellerInfo: "",
  2559. OpUserId: sysUser.AdminId,
  2560. OpUserName: sysUser.RealName,
  2561. CreateTime: time.Now(),
  2562. })
  2563. go services.AddWxUserMoveLog(wxUser, sysUser, req.CompanyId) // 添加用户移动日志记录
  2564. br.Ret = 200
  2565. br.Success = true
  2566. br.Msg = "移动成功"
  2567. }
  2568. // @Title 移动联系人
  2569. // @Description 移动联系接口,将联系人从自己名下移动到另一个客户销售名下
  2570. // @Param request body models.UserMoveReq true "type json string"
  2571. // @Success Ret=200 移动成功
  2572. // @router /user/move [post]
  2573. func (this *CompanyController) UserMove() {
  2574. br := new(models.BaseResponse).Init()
  2575. defer func() {
  2576. this.Data["json"] = br
  2577. this.ServeJSON()
  2578. }()
  2579. sysUser := this.SysUser
  2580. if sysUser == nil {
  2581. br.Msg = "请登录"
  2582. br.ErrMsg = "请登录,SysUser Is Empty"
  2583. br.Ret = 408
  2584. return
  2585. }
  2586. var req models.UserMoveReq
  2587. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2588. if err != nil {
  2589. br.Msg = "参数解析异常!"
  2590. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2591. return
  2592. }
  2593. if req.UserId <= 0 {
  2594. br.Msg = "参数错误"
  2595. br.ErrMsg = "联系人id错误"
  2596. return
  2597. }
  2598. if req.CompanyId <= 0 {
  2599. br.Msg = "参数错误"
  2600. br.ErrMsg = "客户id错误"
  2601. return
  2602. }
  2603. if req.SellerId < 0 {
  2604. br.Msg = "参数错误"
  2605. br.ErrMsg = "销售id错误"
  2606. return
  2607. }
  2608. wxUser, err := models.GetWxUserByUserId(req.UserId)
  2609. if err != nil {
  2610. br.Msg = "移动失败"
  2611. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  2612. return
  2613. }
  2614. oldWxUser := *wxUser
  2615. if wxUser.CompanyId == req.CompanyId {
  2616. br.Msg = "移动失败"
  2617. br.ErrMsg = "该联系人属于该客户"
  2618. return
  2619. }
  2620. //产品id
  2621. productId := services.GetProductId(sysUser.RoleTypeCode)
  2622. //操作权限校验
  2623. errMsg, err := checkOpCompanyUserByCompanyId(wxUser.CompanyId, productId, sysUser.AdminId, sysUser.RoleTypeCode)
  2624. if err != nil {
  2625. br.Msg = "移动失败!" + errMsg
  2626. br.ErrMsg = "移动失败,Err:" + err.Error()
  2627. return
  2628. }
  2629. //联系人与销售的关系
  2630. userSellerRelationList, err := models.GetUserSellerRelationList(int(wxUser.UserId))
  2631. if err != nil {
  2632. return
  2633. }
  2634. userSellerRelationInfo, _ := json.Marshal(userSellerRelationList)
  2635. err = services.MoveUser(req.UserId, req.CompanyId, req.SellerId, wxUser, sysUser.AdminId)
  2636. //err = models.MovePotentialUser(req.UserId, req.CompanyId, req.RealName, req.Mobile, req.Email, req.Remark)
  2637. if err != nil {
  2638. br.Msg = "移动失败"
  2639. br.ErrMsg = "移动失败,Err:" + err.Error()
  2640. return
  2641. }
  2642. //更新客户最近阅读次数以及最近阅读时间
  2643. go services.ModifyCompanyProductLastViewData([]int{wxUser.CompanyId, req.CompanyId})
  2644. //联系人信息
  2645. originalUserInfo, _ := json.Marshal(oldWxUser)
  2646. userInfo, _ := json.Marshal(wxUser)
  2647. {
  2648. // 最新的联系人信息
  2649. newWxUser, err := models.GetWxUserByUserId(req.UserId)
  2650. if err == nil {
  2651. userInfo, _ = json.Marshal(newWxUser)
  2652. }
  2653. }
  2654. go services.AddWxUserOpLog(company.WxUserOpLog{
  2655. LogType: "move",
  2656. UserId: int(wxUser.UserId),
  2657. CompanyId: wxUser.CompanyId,
  2658. Mobile: wxUser.Mobile,
  2659. Email: wxUser.Email,
  2660. OriginalUserInfo: string(originalUserInfo),
  2661. UserInfo: string(userInfo),
  2662. OriginalUserSellerInfo: string(userSellerRelationInfo),
  2663. UserSellerInfo: "",
  2664. OpUserId: sysUser.AdminId,
  2665. OpUserName: sysUser.RealName,
  2666. CreateTime: time.Now(),
  2667. })
  2668. go services.AddWxUserMoveLog(wxUser, sysUser, req.CompanyId) // 添加用户移动日志记录
  2669. br.Ret = 200
  2670. br.Success = true
  2671. br.Msg = "移动成功"
  2672. br.IsAddLog = true
  2673. }
  2674. // @Title 搜索客户
  2675. // @Description 搜索客户接口
  2676. // @Param KeyWord query string true "搜索关键词"
  2677. // @Success 200 {object} company.CompanySearchResp
  2678. // @router /potential/company/search [get]
  2679. func (this *CompanyUserController) CompanySearch() {
  2680. br := new(models.BaseResponse).Init()
  2681. defer func() {
  2682. this.Data["json"] = br
  2683. this.ServeJSON()
  2684. }()
  2685. sysUser := this.SysUser
  2686. if sysUser == nil {
  2687. br.Msg = "请登录"
  2688. br.ErrMsg = "请登录,SysUser Is Empty"
  2689. br.Ret = 408
  2690. return
  2691. }
  2692. var err error
  2693. keyWord := this.GetString("KeyWord")
  2694. item := make([]*company.CompanyItem, 0)
  2695. if keyWord != "" {
  2696. item, err = company.GetCompanyBySearch(keyWord)
  2697. if err != nil && err.Error() != utils.ErrNoRow() {
  2698. br.Msg = "获取失败"
  2699. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  2700. return
  2701. }
  2702. }
  2703. resp := new(company.CompanySearchResp)
  2704. resp.List = item
  2705. br.Ret = 200
  2706. br.Success = true
  2707. br.Msg = "获取成功"
  2708. br.Data = resp
  2709. }
  2710. // @Title 企查查模糊查询客户接口
  2711. // @Description 企查查模糊查询客户
  2712. // @Param KeyWord query string true "搜索关键词"
  2713. // @Success 200 {object} services.Result
  2714. // @router /potential/company/qccSearch [get]
  2715. func (this *CompanyUserController) CompanyQCCSearch() {
  2716. br := new(models.BaseResponse).Init()
  2717. defer func() {
  2718. this.Data["json"] = br
  2719. this.ServeJSON()
  2720. }()
  2721. sysUser := this.SysUser
  2722. if sysUser == nil {
  2723. br.Msg = "请登录"
  2724. br.ErrMsg = "请登录,SysUser Is Empty"
  2725. br.Ret = 408
  2726. return
  2727. }
  2728. var err error
  2729. var results []services.Result
  2730. keyWord := this.GetString("KeyWord")
  2731. if keyWord != "" {
  2732. results, err = services.QCCFuzzySearch(keyWord)
  2733. if err != nil {
  2734. br.Data = results
  2735. br.Msg = "获取数据失败," + err.Error()
  2736. br.Ret = 200
  2737. br.Success = true
  2738. return
  2739. }
  2740. }
  2741. br.Data = results
  2742. br.Ret = 200
  2743. br.Success = true
  2744. br.Msg = "获取成功"
  2745. }
  2746. // @Title 检测客户名称或社会信用码重复
  2747. // @Description 检测客户名称或社会信用码重复接口(新增/编辑客户页面使用)
  2748. // @Param CompanyName query string true "客户名称"
  2749. // @Param CreditCode query string true "社会统一信用码"
  2750. // @Success 200 {object} company.CheckCompanyInfoRepeatResp
  2751. // @router /check/RepeatCompanyInfo [get]
  2752. func (this *CompanyController) CheckCompanyInfoRepeat() {
  2753. br := new(models.BaseResponse).Init()
  2754. defer func() {
  2755. this.Data["json"] = br
  2756. this.ServeJSON()
  2757. }()
  2758. sysUser := this.SysUser
  2759. if sysUser == nil {
  2760. br.Msg = "请登录"
  2761. br.ErrMsg = "请登录,SysUser Is Empty"
  2762. br.Ret = 408
  2763. return
  2764. }
  2765. roleTypeCode := sysUser.RoleTypeCode
  2766. productId := services.GetProductId(roleTypeCode)
  2767. companyName := this.GetString("CompanyName")
  2768. creditCode := this.GetString("CreditCode")
  2769. var status, comanyId, repeatStatus int
  2770. var productName string
  2771. if productId == 0 {
  2772. productId = 1
  2773. checkProductId := 2
  2774. if creditCode != "" {
  2775. codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
  2776. if err != nil && err.Error() != utils.ErrNoRow() {
  2777. br.Msg = "校验社会信用码是否存在失败"
  2778. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
  2779. return
  2780. }
  2781. //存在ficc权限
  2782. if codeItem != nil && codeItem.CompanyId > 0 {
  2783. repeatStatus = 1
  2784. goto Loop
  2785. }
  2786. codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
  2787. if err != nil && err.Error() != utils.ErrNoRow() {
  2788. br.Msg = "校验社会信用码是否存在失败"
  2789. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  2790. return
  2791. }
  2792. if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
  2793. status = 1
  2794. repeatStatus = 1
  2795. productName = codeCheckItem.ProductName
  2796. comanyId = codeCheckItem.CompanyId
  2797. goto Loop
  2798. }
  2799. }
  2800. if companyName != "" {
  2801. nameItem, err := company.CheckCompanyProductByName(companyName, productId)
  2802. if err != nil && err.Error() != utils.ErrNoRow() {
  2803. br.Msg = "校验客户名称是否存在失败"
  2804. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
  2805. return
  2806. }
  2807. if nameItem != nil && nameItem.CompanyId > 0 {
  2808. repeatStatus = 2
  2809. goto Loop
  2810. }
  2811. nameCheckItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
  2812. if err != nil && err.Error() != utils.ErrNoRow() {
  2813. br.Msg = "校验客户名称是否存在失败"
  2814. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  2815. return
  2816. }
  2817. if nameCheckItem != nil && nameCheckItem.CompanyId > 0 {
  2818. status = 1
  2819. repeatStatus = 2
  2820. productName = nameCheckItem.ProductName
  2821. comanyId = nameCheckItem.CompanyId
  2822. goto Loop
  2823. }
  2824. }
  2825. productId = 2
  2826. checkProductId = 1
  2827. if creditCode != "" {
  2828. codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
  2829. if err != nil && err.Error() != utils.ErrNoRow() {
  2830. br.Msg = "校验社会信用码是否存在失败"
  2831. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
  2832. return
  2833. }
  2834. if codeItem != nil && codeItem.CompanyId > 0 {
  2835. repeatStatus = 1
  2836. goto Loop
  2837. }
  2838. codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
  2839. if err != nil && err.Error() != utils.ErrNoRow() {
  2840. br.Msg = "校验社会信用码是否存在失败"
  2841. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  2842. return
  2843. }
  2844. if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
  2845. status = 1
  2846. repeatStatus = 1
  2847. productName = codeCheckItem.ProductName
  2848. comanyId = codeCheckItem.CompanyId
  2849. goto Loop
  2850. }
  2851. }
  2852. if companyName != "" {
  2853. nameItem, err := company.CheckCompanyProductByName(companyName, productId)
  2854. if err != nil && err.Error() != utils.ErrNoRow() {
  2855. br.Msg = "校验客户名称是否存在失败"
  2856. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
  2857. return
  2858. }
  2859. if nameItem != nil && nameItem.CompanyId > 0 {
  2860. repeatStatus = 2
  2861. goto Loop
  2862. }
  2863. nameCheckItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
  2864. if err != nil && err.Error() != utils.ErrNoRow() {
  2865. br.Msg = "校验客户名称是否存在失败"
  2866. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  2867. return
  2868. }
  2869. if nameCheckItem != nil && nameCheckItem.CompanyId > 0 {
  2870. status = 1
  2871. repeatStatus = 2
  2872. productName = nameCheckItem.ProductName
  2873. comanyId = nameCheckItem.CompanyId
  2874. goto Loop
  2875. }
  2876. }
  2877. } else {
  2878. checkProductId := 0
  2879. if productId == 1 {
  2880. checkProductId = 2
  2881. } else if productId == 2 {
  2882. checkProductId = 1
  2883. }
  2884. if creditCode != "" {
  2885. codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
  2886. if err != nil && err.Error() != utils.ErrNoRow() {
  2887. br.Msg = "校验社会信用码是否存在失败"
  2888. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
  2889. return
  2890. }
  2891. if codeItem != nil && codeItem.CompanyId > 0 {
  2892. repeatStatus = 1
  2893. goto Loop
  2894. }
  2895. codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
  2896. if err != nil && err.Error() != utils.ErrNoRow() {
  2897. br.Msg = "校验社会信用码是否存在失败"
  2898. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  2899. return
  2900. }
  2901. if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
  2902. status = 1
  2903. repeatStatus = 1
  2904. productName = codeCheckItem.ProductName
  2905. comanyId = codeCheckItem.CompanyId
  2906. goto Loop
  2907. }
  2908. }
  2909. if companyName != "" {
  2910. nameItem, err := company.CheckCompanyProductByName(companyName, productId)
  2911. if err != nil && err.Error() != utils.ErrNoRow() {
  2912. br.Msg = "校验客户名称是否存在失败"
  2913. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
  2914. return
  2915. }
  2916. if nameItem != nil && nameItem.ProductName != "" {
  2917. repeatStatus = 2
  2918. goto Loop
  2919. }
  2920. nameCheckoutItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
  2921. if err != nil && err.Error() != utils.ErrNoRow() {
  2922. br.Msg = "校验客户名称是否存在失败"
  2923. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  2924. return
  2925. }
  2926. if nameCheckoutItem != nil && nameCheckoutItem.CompanyId > 0 {
  2927. status = 1
  2928. repeatStatus = 2
  2929. productName = nameCheckoutItem.ProductName
  2930. comanyId = nameCheckoutItem.CompanyId
  2931. goto Loop
  2932. }
  2933. }
  2934. }
  2935. Loop:
  2936. resp := new(company.CheckCompanyInfoRepeatResp)
  2937. resp.Status = status
  2938. resp.RepeatStatus = repeatStatus
  2939. resp.ProductName = productName
  2940. resp.CompanyId = comanyId
  2941. br.Ret = 200
  2942. br.Success = true
  2943. br.Msg = "获取成功"
  2944. br.Data = resp
  2945. }
  2946. // ViewReportList
  2947. // @Title 联系人阅读报告记录
  2948. // @Description 联系人阅读报告记录
  2949. // @Param UserId query int true "用户id"
  2950. // @Param TxtType query int true "类型0全部,1权益,2ficc"
  2951. // @Param PageSize query int true "每页数据条数"
  2952. // @Param LastViewTime query string true "最近一次的阅读时间,没有的话,那就是获取最新数据"
  2953. // @Success 200 {object} company.ViewReportListResp
  2954. // @router /view/report/list [get]
  2955. func (this *CompanyUserController) ViewReportList() {
  2956. br := new(models.BaseResponse).Init()
  2957. defer func() {
  2958. this.Data["json"] = br
  2959. this.ServeJSON()
  2960. }()
  2961. sysUser := this.SysUser
  2962. if sysUser == nil {
  2963. br.Msg = "请登录"
  2964. br.ErrMsg = "请登录,SysUser Is Empty"
  2965. br.Ret = 408
  2966. return
  2967. }
  2968. userId, _ := this.GetInt("UserId")
  2969. txtType, _ := this.GetInt("TxtType")
  2970. pageSize, _ := this.GetInt("PageSize")
  2971. lastViewTime := this.GetString("LastViewTime")
  2972. if userId <= 0 {
  2973. br.Msg = "参数错误"
  2974. return
  2975. }
  2976. // 默认20条数据
  2977. if pageSize <= 0 {
  2978. pageSize = utils.PageSize20
  2979. }
  2980. if userId > 0 {
  2981. }
  2982. item, err := models.GetWxUserByUserId(userId)
  2983. if err != nil {
  2984. br.Msg = "获取失败"
  2985. br.Msg = "获取联系人信息失败,Err:" + err.Error()
  2986. return
  2987. }
  2988. var lastViewTimeT time.Time
  2989. if lastViewTime != `` {
  2990. lastViewTimeT, err = time.ParseInLocation(utils.FormatDateTime, lastViewTime, time.Local)
  2991. if err != nil {
  2992. br.Msg = "获取失败"
  2993. br.Msg = "最近一次阅读时间转换异常,Err:" + err.Error()
  2994. return
  2995. }
  2996. }
  2997. list := make([]*company.ViewReportList, 0)
  2998. recordList := make([]*models.UserReportViewRecord, 0)
  2999. obj := models.UserReportViewRecord{}
  3000. var baseCondition string // 基础条件
  3001. var basePars []interface{}
  3002. if item.Mobile != "" {
  3003. baseCondition = ` AND mobile = ? `
  3004. basePars = append(basePars, item.Mobile)
  3005. } else if item.Email == "" {
  3006. baseCondition = ` AND email = ? `
  3007. basePars = append(basePars, item.Email)
  3008. }
  3009. // 阅读记录汇总数
  3010. total := item.FiccViewTotal + item.RaiViewTotal
  3011. switch txtType {
  3012. case 1:
  3013. baseCondition += ` AND source = ? `
  3014. basePars = append(basePars, 4)
  3015. total = item.RaiViewTotal
  3016. if lastViewTimeT.IsZero() {
  3017. if item.RaiLastViewTime != `` && item.RaiLastViewTime != `0000-00-00 00:00:00` {
  3018. lastViewTimeT, _ = time.ParseInLocation(utils.FormatDateTime, item.RaiLastViewTime, time.Local)
  3019. } else {
  3020. lastViewTimeT = time.Now()
  3021. }
  3022. // 默认要把最新的记录列出来,所以往后加1s
  3023. lastViewTime = lastViewTimeT.Add(1 * time.Second).Format(utils.FormatDateTime)
  3024. }
  3025. // 权益
  3026. case 2: // ficc
  3027. baseCondition += ` AND source in (?,?,?) `
  3028. basePars = append(basePars, 1, 2, 3)
  3029. total = item.FiccViewTotal
  3030. if lastViewTimeT.IsZero() {
  3031. if item.FiccLastViewTime != `` && item.FiccLastViewTime != `0000-00-00 00:00:00` {
  3032. lastViewTimeT, _ = time.ParseInLocation(utils.FormatDateTime, item.FiccLastViewTime, time.Local)
  3033. } else {
  3034. lastViewTimeT = time.Now()
  3035. }
  3036. // 默认要把最新的记录列出来,所以往后加1s
  3037. lastViewTime = lastViewTimeT.Add(1 * time.Second).Format(utils.FormatDateTime)
  3038. }
  3039. default:
  3040. if lastViewTimeT.IsZero() {
  3041. var ficcViewTime, raiViewTime time.Time
  3042. if item.FiccLastViewTime != `` && item.FiccLastViewTime != `0000-00-00 00:00:00` {
  3043. ficcViewTime, _ = time.ParseInLocation(utils.FormatDateTime, item.FiccLastViewTime, time.Local)
  3044. }
  3045. if item.RaiLastViewTime != `` && item.RaiLastViewTime != `0000-00-00 00:00:00` {
  3046. raiViewTime, _ = time.ParseInLocation(utils.FormatDateTime, item.RaiLastViewTime, time.Local)
  3047. }
  3048. // 如果两个都没有值的话,那么就是当前时间
  3049. if ficcViewTime.IsZero() && raiViewTime.IsZero() {
  3050. lastViewTimeT = time.Now()
  3051. } else if !ficcViewTime.IsZero() && !raiViewTime.IsZero() {
  3052. if ficcViewTime.After(raiViewTime) {
  3053. lastViewTimeT = ficcViewTime
  3054. } else {
  3055. lastViewTimeT = raiViewTime
  3056. }
  3057. } else if !ficcViewTime.IsZero() {
  3058. lastViewTimeT = ficcViewTime
  3059. } else {
  3060. lastViewTimeT = raiViewTime
  3061. }
  3062. // 默认要把最新的记录列出来,所以往后加1s
  3063. lastViewTime = lastViewTimeT.Add(1 * time.Second).Format(utils.FormatDateTime)
  3064. }
  3065. }
  3066. // 开始实际的查询
  3067. {
  3068. condition := baseCondition
  3069. pars := basePars
  3070. condition += `AND create_time < ?`
  3071. pars = append(pars, lastViewTime)
  3072. total, items, err := obj.GetViewReportList(lastViewTimeT.Year(), condition, pars, pageSize)
  3073. if err != nil {
  3074. br.Msg = "获取失败"
  3075. br.Msg = "获取失败,Err:" + err.Error()
  3076. return
  3077. }
  3078. recordList = append(recordList, items...)
  3079. // 查询去年的表
  3080. if total < int64(pageSize) {
  3081. secondCondition := baseCondition
  3082. secondPars := basePars
  3083. secondCondition += `AND create_time < ?`
  3084. secondPars = append(secondPars, lastViewTime)
  3085. _, items, err = obj.GetViewReportList(lastViewTimeT.Year(), secondCondition, secondPars, int(total)-pageSize)
  3086. if err != nil {
  3087. br.Msg = "获取失败"
  3088. br.Msg = "获取失败,Err:" + err.Error()
  3089. return
  3090. }
  3091. recordList = append(recordList, items...)
  3092. }
  3093. }
  3094. viewReportMap := make(map[string]company.ViewReportList) // 阅读记录map
  3095. sourceReportIdListMap := make(map[int8][]int)
  3096. for _, v := range recordList {
  3097. tmpList, ok := sourceReportIdListMap[v.Source]
  3098. if !ok {
  3099. tmpList = make([]int, 0)
  3100. }
  3101. tmpList = append(tmpList, v.ReportId)
  3102. sourceReportIdListMap[v.Source] = tmpList
  3103. tmpTxtType := `ficc`
  3104. if v.Source == 4 {
  3105. tmpTxtType = `rights`
  3106. }
  3107. stopTime := `--`
  3108. if v.StopTime > 0 {
  3109. stopTime = fmt.Sprint(stopTime)
  3110. }
  3111. viewReportMap[fmt.Sprint(v.Source, "_", v.ReportId)] = company.ViewReportList{
  3112. ResearchReportName: "",
  3113. ReportType: "",
  3114. CreatedTime: v.CreateTime,
  3115. TxtType: tmpTxtType,
  3116. MatchTypeName: "--",
  3117. StopTime: stopTime,
  3118. }
  3119. }
  3120. // 获取报告详情
  3121. for source, reportIdList := range sourceReportIdListMap {
  3122. switch source {
  3123. case 1: // rddp报告
  3124. tmpReportList, err := models.GetReportByIdList(reportIdList)
  3125. if err != nil {
  3126. br.Msg = "获取失败"
  3127. br.Msg = "获取weekly报告详情失败,Err:" + err.Error()
  3128. return
  3129. }
  3130. for _, v := range tmpReportList {
  3131. tmpKey := fmt.Sprint(source, "_", v.Id)
  3132. if tmpInfo, ok := viewReportMap[tmpKey]; ok {
  3133. tmpInfo.ResearchReportName = v.Title
  3134. tmpInfo.ReportType = `rddp`
  3135. tmpInfo.MatchTypeName = v.ClassifyNameFirst
  3136. viewReportMap[tmpKey] = tmpInfo
  3137. }
  3138. }
  3139. case 2: // weekly报告
  3140. tmpReportList, err := models.GetResearchReportListByIdList(reportIdList)
  3141. if err != nil {
  3142. br.Msg = "获取失败"
  3143. br.Msg = "获取weekly报告详情失败,Err:" + err.Error()
  3144. return
  3145. }
  3146. for _, v := range tmpReportList {
  3147. tmpKey := fmt.Sprint(source, "_", v.ResearchReportId)
  3148. if tmpInfo, ok := viewReportMap[tmpKey]; ok {
  3149. tmpInfo.ResearchReportName = v.ResearchReportName
  3150. tmpInfo.ReportType = v.Type
  3151. viewReportMap[tmpKey] = tmpInfo
  3152. }
  3153. }
  3154. case 3: // weekly_report商品的报告(应该是作废了);
  3155. tmpReportList, err := models.GetChartPermissionByIdList(reportIdList)
  3156. if err != nil {
  3157. br.Msg = "获取失败"
  3158. br.Msg = "获取weekly报告详情失败,Err:" + err.Error()
  3159. return
  3160. }
  3161. for _, v := range tmpReportList {
  3162. tmpKey := fmt.Sprint(source, "_", v.ChartPermissionId)
  3163. if tmpInfo, ok := viewReportMap[tmpKey]; ok {
  3164. tmpInfo.ResearchReportName = v.ChartPermissionName
  3165. tmpInfo.ReportType = `advisory`
  3166. tmpInfo.MatchTypeName = v.ClassifyName
  3167. viewReportMap[tmpKey] = tmpInfo
  3168. }
  3169. }
  3170. case 4: // 察研观向的报告
  3171. tmpReportList, err := cygx.GetArticleListByIdList(reportIdList)
  3172. if err != nil {
  3173. br.Msg = "获取失败"
  3174. br.Msg = "获取weekly报告详情失败,Err:" + err.Error()
  3175. return
  3176. }
  3177. for _, v := range tmpReportList {
  3178. tmpKey := fmt.Sprint(source, "_", v.ArticleId)
  3179. if tmpInfo, ok := viewReportMap[tmpKey]; ok {
  3180. tmpInfo.ResearchReportName = v.Title
  3181. tmpInfo.ReportType = `cygx`
  3182. tmpInfo.MatchTypeName = v.MatchTypeName
  3183. viewReportMap[tmpKey] = tmpInfo
  3184. }
  3185. }
  3186. }
  3187. }
  3188. // 报告标题处理
  3189. for _, v := range recordList {
  3190. tmpKey := fmt.Sprint(v.Source, "_", v.ReportId)
  3191. if tmpInfo, ok := viewReportMap[tmpKey]; ok {
  3192. stopTime := `--`
  3193. if v.StopTime > 0 {
  3194. stopTime = fmt.Sprint(v.StopTime)
  3195. }
  3196. list = append(list, &company.ViewReportList{
  3197. ResearchReportName: tmpInfo.ResearchReportName,
  3198. ReportType: tmpInfo.ReportType,
  3199. CreatedTime: v.CreateTime,
  3200. TxtType: tmpInfo.TxtType,
  3201. MatchTypeName: tmpInfo.MatchTypeName,
  3202. StopTime: stopTime,
  3203. })
  3204. }
  3205. }
  3206. // 类型处理
  3207. for k, v := range list {
  3208. if v.ReportType == "day" {
  3209. list[k].MatchTypeName = "晨报"
  3210. } else if v.ReportType == "week" {
  3211. list[k].MatchTypeName = "周报"
  3212. } else if v.ReportType == "two_week" {
  3213. list[k].MatchTypeName = "双周报"
  3214. } else if v.ReportType == "month" {
  3215. list[k].MatchTypeName = "月报"
  3216. } else if v.ReportType == "rddp" {
  3217. //list[k].MatchTypeName = "日评"
  3218. createdTime := utils.StrTimeToTime(v.CreatedTime)
  3219. monthStr := createdTime.Format("01")
  3220. dayStr := strconv.Itoa(createdTime.Day())
  3221. if len(dayStr) == 1 {
  3222. dayStr = "0" + dayStr
  3223. }
  3224. list[k].ResearchReportName += "(" + monthStr + dayStr + ")"
  3225. }
  3226. if v.StopTime != "--" {
  3227. list[k].StopTime += "s"
  3228. }
  3229. }
  3230. resp := new(company.ViewReportListResp)
  3231. resp.List = list
  3232. resp.Total = total
  3233. br.Ret = 200
  3234. br.Success = true
  3235. br.Msg = "获取成功"
  3236. br.Data = resp
  3237. }
  3238. // @Title 导出潜在用户
  3239. // @Description 导出潜在用户接口
  3240. // @Param ApplyMethod query int true "申请方式,0:全部,1:未申请,2:已付费客户申请试用,3:非客户申请试用"
  3241. // @Param KeyWord query string true "搜索关键词"
  3242. // @Success Ret=200 导出成功
  3243. // @router /potential/user/export [get]
  3244. func (this *CompanyUserController) PotentialUserExport() {
  3245. br := new(models.BaseResponse).Init()
  3246. defer func() {
  3247. this.Data["json"] = br
  3248. this.ServeJSON()
  3249. }()
  3250. keyWord := this.GetString("KeyWord")
  3251. applyMethod, _ := this.GetInt("ApplyMethod")
  3252. sysUser := this.SysUser
  3253. if sysUser == nil {
  3254. br.Msg = "请登录"
  3255. br.ErrMsg = "请登录,SysUser Is Empty"
  3256. br.Ret = 408
  3257. return
  3258. }
  3259. list := make([]*models.PotentialUserItem, 0)
  3260. //管理员才让导出数据
  3261. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3262. var condition string
  3263. var pars []interface{}
  3264. if applyMethod > 0 {
  3265. condition += ` AND apply_method=? `
  3266. pars = append(pars, applyMethod-1)
  3267. }
  3268. if keyWord != "" {
  3269. condition += ` AND (a.nick_name LIKE '%` + keyWord + `%' OR a.mobile LIKE '%` + keyWord + `%' OR a.email LIKE '%` + keyWord + `%') `
  3270. }
  3271. tmpList, err := models.GetPotentialUserListExport(condition, pars)
  3272. if err != nil {
  3273. br.Msg = "获取失败"
  3274. br.ErrMsg = "获取失败,Err:" + err.Error()
  3275. return
  3276. }
  3277. list = tmpList
  3278. }
  3279. dir, err := os.Executable()
  3280. exPath := filepath.Dir(dir)
  3281. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  3282. xlsxFile := xlsx.NewFile()
  3283. if err != nil {
  3284. br.Msg = "生成文件失败"
  3285. br.ErrMsg = "生成文件失败"
  3286. return
  3287. }
  3288. style := xlsx.NewStyle()
  3289. alignment := xlsx.Alignment{
  3290. Horizontal: "center",
  3291. Vertical: "center",
  3292. WrapText: true,
  3293. }
  3294. style.Alignment = alignment
  3295. style.ApplyAlignment = true
  3296. sheel, err := xlsxFile.AddSheet("客户数据")
  3297. if err != nil {
  3298. br.Msg = "新增Sheet失败"
  3299. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  3300. return
  3301. }
  3302. titleRow := sheel.AddRow()
  3303. titleRow.AddCell().SetValue("姓名")
  3304. titleRow.AddCell().SetValue("手机号")
  3305. titleRow.AddCell().SetValue("邮箱")
  3306. titleRow.AddCell().SetValue("注册时间")
  3307. titleRow.AddCell().SetValue("公司")
  3308. titleRow.AddCell().SetValue("申请类型")
  3309. titleRow.AddCell().SetValue("累计阅读次数")
  3310. titleRow.AddCell().SetValue("最后一次阅读时间")
  3311. for _, v := range list {
  3312. dataRow := sheel.AddRow()
  3313. dataRow.SetHeight(20)
  3314. dataRow.AddCell().SetString(v.RealName)
  3315. dataRow.AddCell().SetString(v.Mobile)
  3316. dataRow.AddCell().SetString(v.Email)
  3317. dataRow.AddCell().SetString(v.CreatedTime)
  3318. dataRow.AddCell().SetString(v.CompanyName)
  3319. if v.ApplyMethod == 0 {
  3320. dataRow.AddCell().SetString("未申请")
  3321. } else if v.ApplyMethod == 1 {
  3322. dataRow.AddCell().SetString("已付费客户申请试用")
  3323. } else {
  3324. dataRow.AddCell().SetString("非客户申请试用")
  3325. }
  3326. reportView, err := models.GetReportViewMaxTime(int(v.UserId))
  3327. if err != nil {
  3328. br.Msg = "获取失败"
  3329. br.ErrMsg = "获取GetReportViewMaxTime失败,Err:" + err.Error()
  3330. return
  3331. }
  3332. if reportView.LastViewTime.After(v.LastViewTime) {
  3333. v.LastViewTimeStr = v.LastViewTime.Format(utils.FormatDateTime)
  3334. } else {
  3335. v.LastViewTimeStr = v.LastViewTime.Format(utils.FormatDateTime)
  3336. }
  3337. v.ViewTotal += reportView.ViewTotal
  3338. dataRow.AddCell().SetInt(v.ViewTotal)
  3339. if v.LastViewTimeStr == "0001-01-01 00:00:00" {
  3340. v.LastViewTimeStr = ""
  3341. }
  3342. dataRow.AddCell().SetString(v.LastViewTimeStr)
  3343. }
  3344. err = xlsxFile.Save(downLoadnFilePath)
  3345. if err != nil {
  3346. br.Msg = "保存文件失败"
  3347. br.ErrMsg = "保存文件失败"
  3348. return
  3349. }
  3350. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  3351. downloadFileName := "潜在用户列表_" + randStr + ".xlsx"
  3352. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  3353. defer func() {
  3354. os.Remove(downLoadnFilePath)
  3355. }()
  3356. br.Ret = 200
  3357. br.Success = true
  3358. br.Msg = "导出成功"
  3359. }
  3360. // @Title 获取批量导入联系人数据
  3361. // @Description 获取批量导入联系人数据
  3362. // @Param File query file true "文件"
  3363. // @Param CompanyId query file true "客户id"
  3364. // @Success 200 {object} models.ImportListResp
  3365. // @router /import/list [post]
  3366. func (this *CompanyUserController) ImportList() {
  3367. br := new(models.BaseResponse).Init()
  3368. defer func() {
  3369. this.Data["json"] = br
  3370. this.ServeJSON()
  3371. }()
  3372. sysUser := this.SysUser
  3373. if sysUser == nil {
  3374. br.Msg = "请重新登录"
  3375. return
  3376. }
  3377. file, h, err := this.GetFile("File")
  3378. if err != nil {
  3379. br.Msg = "获取文件失败"
  3380. br.ErrMsg = "获取文件失败,Err:" + err.Error()
  3381. return
  3382. }
  3383. companyId, _ := this.GetInt("CompanyId")
  3384. if companyId <= 0 {
  3385. br.Msg = "参数错误"
  3386. br.ErrMsg = "客户id为0"
  3387. return
  3388. }
  3389. //产品id
  3390. productId := services.GetProductId(sysUser.RoleTypeCode)
  3391. //操作权限校验
  3392. errMsg, err := checkOpCompanyUserByCompanyId(companyId, productId, sysUser.AdminId, sysUser.RoleTypeCode)
  3393. if err != nil {
  3394. br.Msg = "导入失败!" + errMsg
  3395. br.ErrMsg = "导入失败,Err:" + err.Error()
  3396. return
  3397. }
  3398. //userBusinessCardCount := 0
  3399. //if productId > 0 {
  3400. // tmpUserBusinessCardCount, err := models.GetCompanyUserBusinessCardCountByProductId(companyId, productId)
  3401. // if err != nil {
  3402. // br.Msg = "导入失败"
  3403. // br.ErrMsg = "判断是否已经存在上传名片联系人失败,err:" + err.Error()
  3404. // return
  3405. // }
  3406. // userBusinessCardCount = tmpUserBusinessCardCount
  3407. //} else {
  3408. // tmpUserBusinessCardCount, err := company.GetCompanyUserBusinessCardCount(companyId)
  3409. // if err != nil {
  3410. // br.Msg = "导入失败"
  3411. // br.ErrMsg = "判断是否已经存在上传名片联系人失败,err:" + err.Error()
  3412. // return
  3413. // }
  3414. // userBusinessCardCount = tmpUserBusinessCardCount
  3415. //}
  3416. //
  3417. //if userBusinessCardCount <= 0 {
  3418. // br.Msg = "请先至少添加一位名片联系人"
  3419. // return
  3420. //}
  3421. //客户信息
  3422. companyInfo, err := company.GetCompanyById(companyId)
  3423. if err != nil {
  3424. br.Msg = "导入异常"
  3425. br.Msg = "导入异常:" + err.Error()
  3426. return
  3427. }
  3428. uploadDir := "static/xls"
  3429. err = os.MkdirAll(uploadDir, 766)
  3430. if err != nil {
  3431. br.Msg = "存储目录创建失败"
  3432. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  3433. return
  3434. }
  3435. path := uploadDir + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + h.Filename
  3436. defer file.Close()
  3437. err = this.SaveToFile("File", path)
  3438. if err != nil {
  3439. br.Msg = "文件保存失败"
  3440. br.ErrMsg = "文件保存失败,Err:" + err.Error()
  3441. return
  3442. }
  3443. xlFile, err := xlsx.OpenFile(path)
  3444. if err != nil {
  3445. br.Msg = "获取失败"
  3446. br.ErrMsg = "打开文件失败,Err:" + err.Error() + ";path:" + path
  3447. return
  3448. }
  3449. existUser := make([]*models.WxUser, 0)
  3450. //excel中已经存在的数据,用来判断excel中是否存在相同手机号/邮箱,避免重复提交
  3451. excelData := make(map[string]string)
  3452. //重复数据
  3453. repeatUser := make([]*models.WxUser, 0)
  3454. // 遍历sheet页读取
  3455. for _, sheet := range xlFile.Sheets {
  3456. //遍历行读取
  3457. maxRow := sheet.MaxRow
  3458. fmt.Println("maxRow:", maxRow)
  3459. fmt.Println("maxRow")
  3460. for i := 0; i < maxRow; i++ {
  3461. if i == 0 {
  3462. row := sheet.Row(i)
  3463. cells := row.Cells
  3464. for k, cell := range cells {
  3465. text := cell.String()
  3466. if k == 0 {
  3467. if text != "姓名" {
  3468. br.Msg = "模板格式错误"
  3469. br.ErrMsg = "模板格式错误,title:" + text
  3470. return
  3471. }
  3472. }
  3473. if k == 1 {
  3474. if !strings.Contains(text, "性别") {
  3475. br.Msg = "模板格式错误"
  3476. br.ErrMsg = "模板格式错误,title:" + text
  3477. return
  3478. }
  3479. }
  3480. if k == 2 {
  3481. if !strings.Contains(text, "国际区号(中国大陆填写:86)") {
  3482. br.Msg = "模板格式错误"
  3483. br.ErrMsg = "模板格式错误,title:" + text
  3484. return
  3485. }
  3486. }
  3487. if k == 3 {
  3488. if !strings.Contains(text, "手机号") {
  3489. br.Msg = "模板格式错误"
  3490. br.ErrMsg = "模板格式错误,title:" + text
  3491. return
  3492. }
  3493. }
  3494. if k == 4 {
  3495. if !strings.Contains(text, "邮箱") {
  3496. br.Msg = "模板格式错误"
  3497. br.ErrMsg = "模板格式错误,title:" + text
  3498. return
  3499. }
  3500. }
  3501. if k == 5 {
  3502. if !strings.Contains(text, "是否决策人") {
  3503. br.Msg = "模板格式错误"
  3504. br.ErrMsg = "模板格式错误,title:" + text
  3505. return
  3506. }
  3507. }
  3508. if k == 6 {
  3509. if !strings.Contains(text, "职位") {
  3510. br.Msg = "模板格式错误"
  3511. br.ErrMsg = "模板格式错误,title:" + text
  3512. return
  3513. }
  3514. }
  3515. if k == 7 {
  3516. if !strings.Contains(text, "部门") {
  3517. br.Msg = "模板格式错误"
  3518. br.ErrMsg = "模板格式错误,title:" + text
  3519. return
  3520. }
  3521. }
  3522. }
  3523. }
  3524. if i >= 1 {
  3525. row := sheet.Row(i)
  3526. cells := row.Cells
  3527. var userName, sex, countryCode, mobileOne, email, isMaker, position, departmentName string
  3528. for k, cell := range cells {
  3529. if k == 0 {
  3530. userName = cell.String()
  3531. }
  3532. if k == 1 {
  3533. sex = cell.String()
  3534. }
  3535. if k == 2 {
  3536. countryCode = cell.String()
  3537. }
  3538. if k == 3 {
  3539. mobileOne = cell.String()
  3540. }
  3541. if k == 4 {
  3542. email = cell.String()
  3543. }
  3544. if k == 5 {
  3545. isMaker = cell.String()
  3546. }
  3547. if k == 6 {
  3548. position = cell.String()
  3549. }
  3550. if k == 7 {
  3551. departmentName = cell.String()
  3552. }
  3553. }
  3554. //移除空格
  3555. mobileOne = utils.TrimStr(mobileOne)
  3556. email = utils.TrimStr(email)
  3557. //这些字段都没有的话,系统认为excel到底了
  3558. if userName == "" && sex == "" && mobileOne == "" {
  3559. break
  3560. }
  3561. if userName == "" {
  3562. continue
  3563. }
  3564. //如果手机号或者邮箱都没有填写的情况下
  3565. if mobileOne == "" && email == "" {
  3566. continue
  3567. }
  3568. if mobileOne != "" && countryCode == "" {
  3569. br.Msg = "导入数据中存在【国际区号】为空的联系人,请检查"
  3570. return
  3571. }
  3572. //如果是权益,且是海外用户的情况下,那么手机号、邮箱有一个没有填写的情况下,那么退出当前循环
  3573. if productId == 2 && companyInfo.RegionType == "海外" && (mobileOne == "" || email == "") {
  3574. continue
  3575. }
  3576. item := new(models.WxUser)
  3577. item.CountryCode = countryCode
  3578. item.RealName = userName
  3579. if sex == "男" {
  3580. item.Sex = 1
  3581. } else if sex == "女" {
  3582. item.Sex = 2
  3583. } else {
  3584. item.Sex = 0
  3585. }
  3586. item.Mobile = mobileOne
  3587. item.Email = email
  3588. if isMaker == "是" {
  3589. item.IsMaker = 1
  3590. } else {
  3591. item.IsMaker = 0
  3592. }
  3593. item.Position = position
  3594. item.DepartmentName = departmentName
  3595. if mobileOne != "" {
  3596. if _, ok := excelData[mobileOne]; ok {
  3597. //将用户插入其中,然后退出当前循环,进入下一循环
  3598. repeatUser = append(repeatUser, item)
  3599. continue
  3600. }
  3601. excelData[mobileOne] = ""
  3602. }
  3603. if email != "" {
  3604. if _, ok := excelData[email]; ok {
  3605. //将用户插入其中,然后退出当前循环,进入下一循环
  3606. repeatUser = append(repeatUser, item)
  3607. continue
  3608. }
  3609. excelData[mobileOne] = ""
  3610. }
  3611. //没问题数据
  3612. existUser = append(existUser, item)
  3613. }
  3614. }
  3615. }
  3616. //defer func() {
  3617. // os.Remove(path)
  3618. //}()
  3619. br.Msg = "获取成功"
  3620. br.Ret = 200
  3621. br.Success = true
  3622. br.Data = models.ImportListResp{
  3623. ValidUser: existUser,
  3624. RepeatUser: repeatUser,
  3625. }
  3626. }
  3627. // 需要更新的联系人数据实体
  3628. type UpdateWxUser struct {
  3629. OldWxUser models.WxUser `description:"旧的联系人数据orm实体(未变更前的)"`
  3630. WxUser *models.WxUser `description:"联系人数据orm实体"`
  3631. Cols []string `description:"需要修改的字段名切片"`
  3632. }
  3633. // @Title 批量导入联系人数据
  3634. // @Description 批量导入联系人数据
  3635. // @Param File query file true "文件"
  3636. // @Param CompanyId query file true "客户id"
  3637. // @Success 600 {object} []*company.CompanyUser
  3638. // @Success 200 Ret=200 导入成功
  3639. // @router /import [post]
  3640. func (this *CompanyUserController) Import() {
  3641. br := new(models.BaseResponse).Init()
  3642. defer func() {
  3643. this.Data["json"] = br
  3644. this.ServeJSON()
  3645. }()
  3646. sysUser := this.SysUser
  3647. if sysUser == nil {
  3648. br.Msg = "请重新登录"
  3649. return
  3650. }
  3651. file, h, err := this.GetFile("File")
  3652. if err != nil {
  3653. br.Msg = "获取文件失败"
  3654. br.ErrMsg = "获取文件失败,Err:" + err.Error()
  3655. return
  3656. }
  3657. companyId, _ := this.GetInt("CompanyId")
  3658. if companyId <= 0 {
  3659. br.Msg = "参数错误"
  3660. br.ErrMsg = "客户id为0"
  3661. return
  3662. }
  3663. //产品id
  3664. productId := services.GetProductId(sysUser.RoleTypeCode)
  3665. //操作权限校验
  3666. errMsg, err := checkOpCompanyUserByCompanyId(companyId, productId, sysUser.AdminId, sysUser.RoleTypeCode)
  3667. if err != nil {
  3668. br.Msg = "导入失败!" + errMsg
  3669. br.ErrMsg = "导入失败,Err:" + err.Error()
  3670. return
  3671. }
  3672. //userBusinessCardCount := 0
  3673. //if productId > 0 {
  3674. // tmpUserBusinessCardCount, err := models.GetCompanyUserBusinessCardCountByProductId(companyId, productId)
  3675. // if err != nil {
  3676. // br.Msg = "导入失败"
  3677. // br.ErrMsg = "判断是否已经存在上传名片联系人失败,err:" + err.Error()
  3678. // return
  3679. // }
  3680. // userBusinessCardCount = tmpUserBusinessCardCount
  3681. //} else {
  3682. // tmpUserBusinessCardCount, err := company.GetCompanyUserBusinessCardCount(companyId)
  3683. // if err != nil {
  3684. // br.Msg = "导入失败"
  3685. // br.ErrMsg = "判断是否已经存在上传名片联系人失败,err:" + err.Error()
  3686. // return
  3687. // }
  3688. // userBusinessCardCount = tmpUserBusinessCardCount
  3689. //}
  3690. //
  3691. //if userBusinessCardCount <= 0 {
  3692. // br.Msg = "请先至少添加一位名片联系人"
  3693. // return
  3694. //}
  3695. uploadDir := "static/xls"
  3696. err = os.MkdirAll(uploadDir, 766)
  3697. if err != nil {
  3698. br.Msg = "存储目录创建失败"
  3699. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  3700. return
  3701. }
  3702. path := uploadDir + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + h.Filename
  3703. defer file.Close()
  3704. err = this.SaveToFile("File", path)
  3705. if err != nil {
  3706. br.Msg = "文件保存失败"
  3707. br.ErrMsg = "文件保存失败,Err:" + err.Error()
  3708. return
  3709. }
  3710. xlFile, err := xlsx.OpenFile(path)
  3711. if err != nil {
  3712. br.Msg = "文件导入失败"
  3713. br.ErrMsg = "文件导入失败,Err:" + err.Error()
  3714. return
  3715. }
  3716. //获取当前操作员产品权限列表
  3717. companyProductList, productErr := getSysCompanyProductList(productId, companyId)
  3718. if productErr != nil {
  3719. br.Msg = "新增失败"
  3720. br.ErrMsg = "新增失败,获取当前操作员产品权限异常,Err:" + productErr.Error()
  3721. return
  3722. }
  3723. if companyProductList == nil {
  3724. br.Msg = "新增失败"
  3725. br.ErrMsg = "新增失败,获取当前操作员找不到产品权限"
  3726. return
  3727. }
  3728. //客户信息
  3729. companyInfo, err := company.GetCompanyById(companyId)
  3730. if err != nil {
  3731. br.Msg = "导入异常"
  3732. br.Msg = "导入异常:" + err.Error()
  3733. return
  3734. }
  3735. //已存在联系人的切片
  3736. existUser := make([]*company.CompanyUser, 0)
  3737. //待添加销售员与联系人关系的切片
  3738. notRelationUser := make([]map[int]*company.CompanyUser, 0)
  3739. //允许添加的联系人
  3740. needAddUser := make([]*models.WxUserDetail, 0)
  3741. //excel中已经存在的数据,用来判断excel中是否存在相同手机号/邮箱,避免重复提交
  3742. excelData := make(map[string]string)
  3743. //需要更新的数据实体切片
  3744. updateWxUserSlice := make([]UpdateWxUser, 0)
  3745. // 遍历sheet页读取
  3746. for _, sheet := range xlFile.Sheets {
  3747. //遍历行读取
  3748. maxRow := sheet.MaxRow
  3749. for i := 0; i < maxRow; i++ {
  3750. if i == 0 {
  3751. row := sheet.Row(i)
  3752. cells := row.Cells
  3753. for k, cell := range cells {
  3754. text := cell.String()
  3755. if k == 0 {
  3756. if text != "姓名" {
  3757. br.Msg = "模板格式错误"
  3758. br.ErrMsg = "模板格式错误,title:" + text
  3759. return
  3760. }
  3761. }
  3762. if k == 1 {
  3763. if !strings.Contains(text, "性别") {
  3764. br.Msg = "模板格式错误"
  3765. br.ErrMsg = "模板格式错误,title:" + text
  3766. return
  3767. }
  3768. }
  3769. if k == 2 {
  3770. if !strings.Contains(text, "国际区号(中国大陆填写:86)") {
  3771. br.Msg = "模板格式错误"
  3772. br.ErrMsg = "模板格式错误,title:" + text
  3773. return
  3774. }
  3775. }
  3776. if k == 3 {
  3777. if !strings.Contains(text, "手机号") {
  3778. br.Msg = "模板格式错误"
  3779. br.ErrMsg = "模板格式错误,title:" + text
  3780. return
  3781. }
  3782. }
  3783. if k == 4 {
  3784. if !strings.Contains(text, "邮箱") {
  3785. br.Msg = "模板格式错误"
  3786. br.ErrMsg = "模板格式错误,title:" + text
  3787. return
  3788. }
  3789. }
  3790. if k == 5 {
  3791. if !strings.Contains(text, "是否决策人") {
  3792. br.Msg = "模板格式错误"
  3793. br.ErrMsg = "模板格式错误,title:" + text
  3794. return
  3795. }
  3796. }
  3797. if k == 6 {
  3798. if !strings.Contains(text, "职位") {
  3799. br.Msg = "模板格式错误"
  3800. br.ErrMsg = "模板格式错误,title:" + text
  3801. return
  3802. }
  3803. }
  3804. if k == 7 {
  3805. if !strings.Contains(text, "部门") {
  3806. br.Msg = "模板格式错误"
  3807. br.ErrMsg = "模板格式错误,title:" + text
  3808. return
  3809. }
  3810. }
  3811. }
  3812. }
  3813. if i >= 1 {
  3814. row := sheet.Row(i)
  3815. cells := row.Cells
  3816. var userName, sex, countryCode, mobileOne, email, isMaker, position, departmentName string
  3817. for k, cell := range cells {
  3818. if k == 0 {
  3819. userName = cell.String()
  3820. }
  3821. if k == 1 {
  3822. sex = cell.String()
  3823. }
  3824. if k == 2 {
  3825. countryCode = strings.Replace(cell.String(), "+", "", -1)
  3826. countryCode = strings.Replace(countryCode, "-", "", -1)
  3827. countryCode = strings.Replace(countryCode, " ", "", -1)
  3828. }
  3829. if k == 3 {
  3830. mobileOne = cell.String()
  3831. }
  3832. if k == 4 {
  3833. email = cell.String()
  3834. }
  3835. if k == 5 {
  3836. isMaker = cell.String()
  3837. }
  3838. if k == 6 {
  3839. position = cell.String()
  3840. }
  3841. if k == 7 {
  3842. departmentName = cell.String()
  3843. }
  3844. }
  3845. //移除空格
  3846. mobileOne = utils.TrimStr(mobileOne)
  3847. email = utils.TrimStr(email)
  3848. //这些字段都没有的话,系统认为excel到底了
  3849. if userName == "" && sex == "" && mobileOne == "" {
  3850. break
  3851. }
  3852. if userName == "" {
  3853. br.Msg = "导入数据中存在【姓名】为空的联系人,请检查"
  3854. return
  3855. }
  3856. if sex == "" {
  3857. br.Msg = "导入数据中存在【性别】为空的联系人,请检查"
  3858. return
  3859. }
  3860. if mobileOne != "" && countryCode == "" {
  3861. br.Msg = "导入数据中存在【国际区号】为空的联系人,请检查"
  3862. return
  3863. }
  3864. // 大陆区号校验手机号
  3865. if mobileOne != "" && (countryCode == "86" || countryCode == "086" || countryCode == "+86" || countryCode == "+086") {
  3866. if !utils.ValidateMobileFormatat(mobileOne) {
  3867. br.Msg = "导入数据中存在【大陆手机号】格式有误的联系人,请检查"
  3868. return
  3869. }
  3870. }
  3871. //如果手机号或者邮箱都没有填写的情况下
  3872. if mobileOne == "" && email == "" {
  3873. continue
  3874. }
  3875. //如果是权益,且是海外用户的情况下,那么手机号、邮箱有一个没有填写的情况下,那么退出当前循环
  3876. if productId == 2 && companyInfo.RegionType == "海外" && (mobileOne == "" || email == "") {
  3877. continue
  3878. }
  3879. if isMaker == "" {
  3880. br.Msg = "导入数据中存在【决策人】为空的联系人,请检查"
  3881. return
  3882. }
  3883. item := new(models.WxUserDetail)
  3884. item.RealName = userName
  3885. if sex == "男" {
  3886. item.Sex = 1
  3887. } else if sex == "女" {
  3888. item.Sex = 2
  3889. } else {
  3890. item.Sex = 0
  3891. }
  3892. item.Mobile = mobileOne
  3893. item.Email = email
  3894. if isMaker == "是" {
  3895. item.IsMaker = 1
  3896. } else {
  3897. item.IsMaker = 0
  3898. }
  3899. item.Position = position
  3900. item.DepartmentName = departmentName
  3901. item.SellerRealName = companyProductList[0].SellerName
  3902. item.CompanyName = companyProductList[0].CompanyName
  3903. var mobileOneItem, emailItem *company.CompanyUser
  3904. var mobileNotRelationUserMap, emailNotRelationUserMap map[int]*company.CompanyUser
  3905. //手机号校验
  3906. if mobileOne != "" {
  3907. if _, ok := excelData[mobileOne]; ok {
  3908. br.Msg = "excel表数据异常,存在重复的手机号:" + mobileOne + ",请检查excel表格数据"
  3909. br.ErrMsg = "excel表数据异常,存在重复的手机号:" + mobileOne + ",请检查excel表格数据"
  3910. return
  3911. }
  3912. excelData[mobileOne] = ""
  3913. tmpMobileOneItem, err := company.GetUserCountByMobile(mobileOne)
  3914. if err != nil && err.Error() != utils.ErrNoRow() {
  3915. br.Msg = "新增失败"
  3916. br.ErrMsg = "判断手机号1是否存在,Err:" + err.Error()
  3917. return
  3918. }
  3919. mobileOneItem = tmpMobileOneItem
  3920. if mobileOneItem != nil {
  3921. if mobileOneItem.UserId > 0 {
  3922. hasMove := true //是否可移动
  3923. //如果是大于 1 的客户,那么就是非潜在客户,需要去查询对应的销售
  3924. if mobileOneItem.CompanyId > 1 {
  3925. //获取联系人分组信息
  3926. userSellerGroupInfoList, err := models.GetUserGroupSellersByUserId(int(mobileOneItem.UserId))
  3927. //根据分组校验
  3928. if err == nil && len(userSellerGroupInfoList) > 0 {
  3929. sellerMap := make(map[int]string) //销售信息map
  3930. sellerNameSlice := make([]string, 0) //销售姓名切片
  3931. for _, v := range userSellerGroupInfoList {
  3932. if v.Status != utils.COMPANY_STATUS_LOSE && v.Status != utils.COMPANY_STATUS_FOREVER && hasMove == true {
  3933. hasMove = false
  3934. }
  3935. if _, ok := sellerMap[v.SellerId]; ok {
  3936. continue
  3937. }
  3938. sellerMap[v.SellerId] = v.SellerRealName
  3939. sellerNameSlice = append(sellerNameSlice, v.SellerRealName)
  3940. }
  3941. mobileOneItem.SellerRealName = strings.Join(sellerNameSlice, "/")
  3942. }
  3943. }
  3944. item.SellerRealName = mobileOneItem.SellerRealName
  3945. item.CompanyName = mobileOneItem.CompanyName
  3946. //判断该联系人的 客户企业编号 是否与 当前客户编号 一致,如果不一致,那么将该联系人加入到已经存在的联系人列表中去,并终止当前循环,进入下一循环。
  3947. if mobileOneItem.CompanyId != companyId {
  3948. mobileOneItem.HasMove = hasMove //是否可移动
  3949. if hasMove {
  3950. if mobileOneItem.RealName != item.RealName {
  3951. mobileOneItem.RealName = item.RealName
  3952. }
  3953. if mobileOneItem.DepartmentName != item.DepartmentName {
  3954. mobileOneItem.DepartmentName = item.DepartmentName
  3955. }
  3956. if mobileOneItem.RealName != item.RealName {
  3957. mobileOneItem.RealName = item.RealName
  3958. }
  3959. }
  3960. mobileOneItem.CountryCode = countryCode
  3961. existUser = append(existUser, mobileOneItem)
  3962. continue
  3963. }
  3964. //判断该用户与当前账号是否存在关系,如果没有关系,那么直接返回
  3965. notRelationUserMap, checkErr := checkProductListUser(*item, mobileOneItem, companyProductList)
  3966. //sql异常
  3967. if checkErr != nil && checkErr.Error() != utils.ErrNoRow() {
  3968. br.Msg = "新增失败"
  3969. br.ErrMsg = "新增失败,Err:" + checkErr.Error()
  3970. return
  3971. }
  3972. mobileNotRelationUserMap = notRelationUserMap
  3973. }
  3974. }
  3975. }
  3976. //邮箱校验
  3977. if email != "" {
  3978. if _, ok := excelData[email]; ok {
  3979. br.Msg = "excel表数据异常,存在重复的邮箱:" + email + ",请检查excel表格数据"
  3980. br.ErrMsg = "excel表数据异常,存在重复的邮箱:" + email + ",请检查excel表格数据"
  3981. return
  3982. }
  3983. excelData[email] = ""
  3984. tmpEmailItem, err := company.CheckCompanyUserCountByEmail(email)
  3985. if err != nil && err.Error() != utils.ErrNoRow() {
  3986. br.Msg = "新增失败"
  3987. br.ErrMsg = "新增失败,Err:" + err.Error()
  3988. return
  3989. }
  3990. emailItem = tmpEmailItem
  3991. if emailItem != nil {
  3992. if emailItem.UserId > 0 {
  3993. hasMove := true //是否可移动
  3994. //如果是大于 1 的客户,那么就是非潜在客户,需要去查询对应的销售
  3995. if emailItem.CompanyId > 1 {
  3996. //获取联系人分组信息
  3997. userSellerGroupInfoList, err := models.GetUserGroupSellersByUserId(int(emailItem.UserId))
  3998. //根据分组校验
  3999. if err == nil && len(userSellerGroupInfoList) > 0 {
  4000. sellerMap := make(map[int]string) //销售信息map
  4001. sellerNameSlice := make([]string, 0) //销售姓名切片
  4002. for _, v := range userSellerGroupInfoList {
  4003. if v.Status != utils.COMPANY_STATUS_LOSE && v.Status != utils.COMPANY_STATUS_FOREVER && hasMove == true {
  4004. hasMove = false
  4005. }
  4006. if _, ok := sellerMap[v.SellerId]; ok {
  4007. continue
  4008. }
  4009. sellerMap[v.SellerId] = v.SellerRealName
  4010. sellerNameSlice = append(sellerNameSlice, v.SellerRealName)
  4011. }
  4012. emailItem.SellerRealName = strings.Join(sellerNameSlice, "/")
  4013. }
  4014. }
  4015. item.SellerRealName = emailItem.SellerRealName
  4016. item.CompanyName = emailItem.CompanyName
  4017. //判断该联系人的 客户企业编号 是否与 当前客户编号 一致,如果不一致,那么将该联系人加入到已经存在的联系人列表中去,并终止当前循环,进入下一循环。
  4018. if emailItem.CompanyId != companyId {
  4019. emailItem.HasMove = hasMove //是否可移动
  4020. if hasMove {
  4021. if emailItem.RealName != item.RealName {
  4022. emailItem.RealName = item.RealName
  4023. }
  4024. if emailItem.DepartmentName != item.DepartmentName {
  4025. emailItem.DepartmentName = item.DepartmentName
  4026. }
  4027. if emailItem.RealName != item.RealName {
  4028. emailItem.RealName = item.RealName
  4029. }
  4030. }
  4031. emailItem.CountryCode = countryCode
  4032. existUser = append(existUser, emailItem)
  4033. continue
  4034. }
  4035. //判断该用户与当前账号是否存在关系,如果没有关系,那么直接返回
  4036. notRelationUserMap, checkErr := checkProductListUser(*item, emailItem, companyProductList)
  4037. //sql异常
  4038. if checkErr != nil && checkErr.Error() != utils.ErrNoRow() {
  4039. br.Msg = "新增失败"
  4040. br.ErrMsg = "新增失败,Err:" + checkErr.Error()
  4041. return
  4042. }
  4043. //判断该用户与销售是否存在关系,如果不存在,那么加入到 待添加关系 的切片中
  4044. emailNotRelationUserMap = notRelationUserMap
  4045. }
  4046. }
  4047. }
  4048. //如果系统已存在该联系人,那么逻辑处理后退出当前循环,进入下一循环
  4049. if mobileOneItem != nil || emailItem != nil {
  4050. //如果既存在该手机号联系人,也存在该邮箱联系人;那么需要去判断 这 两个 联系人 是不是同一个,
  4051. //如果不是同一个联系人的话,那么只添加对应的关系,不去修改对应的数据
  4052. var wxUserItem *models.WxUser
  4053. var oldTmpWxUserItem models.WxUser
  4054. cols := make([]string, 0)
  4055. if mobileOneItem != nil && emailItem != nil {
  4056. //如果两个联系人 不是 同一个
  4057. if mobileOneItem.UserId != emailItem.UserId {
  4058. notRelationUser = append(notRelationUser, mobileNotRelationUserMap, emailNotRelationUserMap)
  4059. //wxUserItem = mobileOneItem
  4060. } else {
  4061. //如果两个联系人 是 同一个
  4062. notRelationUser = append(notRelationUser, mobileNotRelationUserMap)
  4063. tmpWxUserItem, err := models.GetWxUserByUserId(int(mobileOneItem.UserId))
  4064. if err != nil {
  4065. br.Msg = "导入失败"
  4066. br.ErrMsg = "查询联系人信息失败,Err:" + err.Error()
  4067. return
  4068. }
  4069. oldTmpWxUserItem := *tmpWxUserItem
  4070. if tmpWxUserItem.IsMaker != item.IsMaker {
  4071. tmpWxUserItem.IsMaker = item.IsMaker
  4072. cols = append(cols, "IsMaker")
  4073. }
  4074. if tmpWxUserItem.DepartmentName != item.DepartmentName {
  4075. tmpWxUserItem.DepartmentName = item.DepartmentName
  4076. cols = append(cols, "DepartmentName")
  4077. }
  4078. if tmpWxUserItem.RealName != item.RealName {
  4079. tmpWxUserItem.RealName = item.RealName
  4080. cols = append(cols, "RealName")
  4081. }
  4082. if len(cols) > 0 {
  4083. updateWxUser := UpdateWxUser{
  4084. OldWxUser: oldTmpWxUserItem,
  4085. WxUser: tmpWxUserItem,
  4086. Cols: cols,
  4087. }
  4088. updateWxUserSlice = append(updateWxUserSlice, updateWxUser)
  4089. }
  4090. wxUserItem = tmpWxUserItem
  4091. }
  4092. } else if mobileOneItem != nil {
  4093. //如果只存在 手机号联系人
  4094. notRelationUser = append(notRelationUser, mobileNotRelationUserMap)
  4095. //获取联系人orm实体类
  4096. tmpWxUserItem, err := models.GetWxUserByUserId(int(mobileOneItem.UserId))
  4097. if err != nil {
  4098. br.Msg = "导入失败"
  4099. br.ErrMsg = "查询联系人信息失败,Err:" + err.Error()
  4100. return
  4101. }
  4102. oldTmpWxUserItem = *tmpWxUserItem
  4103. if tmpWxUserItem.IsMaker != item.IsMaker {
  4104. tmpWxUserItem.IsMaker = item.IsMaker
  4105. cols = append(cols, "IsMaker")
  4106. }
  4107. if tmpWxUserItem.DepartmentName != item.DepartmentName && item.DepartmentName != "" {
  4108. tmpWxUserItem.DepartmentName = item.DepartmentName
  4109. cols = append(cols, "DepartmentName")
  4110. }
  4111. if tmpWxUserItem.RealName != item.RealName && item.RealName != "" {
  4112. tmpWxUserItem.RealName = item.RealName
  4113. cols = append(cols, "RealName")
  4114. }
  4115. if tmpWxUserItem.Email != item.Email && item.Email != "" {
  4116. tmpWxUserItem.Email = item.Email
  4117. cols = append(cols, "Email")
  4118. }
  4119. wxUserItem = tmpWxUserItem
  4120. } else if emailItem != nil {
  4121. //如果只存在 邮箱联系人
  4122. notRelationUser = append(notRelationUser, emailNotRelationUserMap)
  4123. //获取联系人orm实体类
  4124. tmpWxUserItem, err := models.GetWxUserByUserId(int(emailItem.UserId))
  4125. if err != nil {
  4126. br.Msg = "导入失败"
  4127. br.ErrMsg = "查询联系人信息失败,Err:" + err.Error()
  4128. return
  4129. }
  4130. oldTmpWxUserItem = *tmpWxUserItem
  4131. if tmpWxUserItem.IsMaker != item.IsMaker {
  4132. tmpWxUserItem.IsMaker = item.IsMaker
  4133. cols = append(cols, "IsMaker")
  4134. }
  4135. if tmpWxUserItem.DepartmentName != item.DepartmentName && item.DepartmentName != "" {
  4136. tmpWxUserItem.DepartmentName = item.DepartmentName
  4137. cols = append(cols, "DepartmentName")
  4138. }
  4139. if tmpWxUserItem.RealName != item.RealName && item.RealName != "" {
  4140. tmpWxUserItem.RealName = item.RealName
  4141. cols = append(cols, "RealName")
  4142. }
  4143. if tmpWxUserItem.Email != item.Email && item.Email != "" {
  4144. tmpWxUserItem.Email = item.Email
  4145. cols = append(cols, "Email")
  4146. }
  4147. wxUserItem = tmpWxUserItem
  4148. }
  4149. //如果变更字段数量大于0
  4150. if len(cols) > 0 {
  4151. updateWxUser := UpdateWxUser{
  4152. OldWxUser: oldTmpWxUserItem,
  4153. WxUser: wxUserItem,
  4154. Cols: cols,
  4155. }
  4156. updateWxUserSlice = append(updateWxUserSlice, updateWxUser)
  4157. }
  4158. continue
  4159. }
  4160. //确实系统中不存在该用户
  4161. item.CountryCode = countryCode
  4162. needAddUser = append(needAddUser, item)
  4163. }
  4164. }
  4165. }
  4166. fmt.Println("表格中用户与系统中存在用户没有冲突")
  4167. //如果表格中用户与系统中存在用户 没有冲突,那么继续执行
  4168. for _, user := range needAddUser {
  4169. if user.RealName != "" && (user.Mobile != "" || user.Email != "") {
  4170. userData := new(models.WxUser)
  4171. userData.RealName = user.RealName
  4172. userData.Sex = user.Sex
  4173. userData.Mobile = user.Mobile
  4174. userData.CountryCode = user.CountryCode
  4175. userData.OutboundMobile = user.Mobile
  4176. userData.OutboundCountryCode = user.CountryCode
  4177. userData.Email = user.Email
  4178. userData.Position = user.Position
  4179. userData.IsMaker = user.IsMaker
  4180. userData.CompanyId = companyId
  4181. userData.DepartmentName = user.DepartmentName
  4182. userData.CountryCode = user.CountryCode
  4183. //判断该手机号、邮箱是否已经添加,如果已经添加,那么就不再添加
  4184. var key string
  4185. if user.Mobile != "" {
  4186. key = "wx_user:mobile:" + userData.Mobile
  4187. } else {
  4188. key = "wx_user:email:" + userData.Email
  4189. }
  4190. isHas := utils.Rc.IsExist(key)
  4191. if isHas == false {
  4192. newId, err := models.AddWxUser(userData)
  4193. userData.UserId = newId
  4194. if err != nil {
  4195. br.Msg = "导入失败"
  4196. br.ErrMsg = "导入失败,Err:" + err.Error()
  4197. return
  4198. }
  4199. //添加联系人与销售员的关系
  4200. for _, companyProduct := range companyProductList {
  4201. models.AddUserSellerRelation(newId, companyProduct.CompanyId, companyProduct.SellerId, companyProduct.ProductId, companyProduct.SellerName, user.Mobile, user.Email)
  4202. }
  4203. //联系人信息
  4204. userInfo, _ := json.Marshal(userData)
  4205. go services.AddWxUserOpLog(company.WxUserOpLog{
  4206. LogType: "import",
  4207. UserId: int(userData.UserId),
  4208. CompanyId: userData.CompanyId,
  4209. Mobile: userData.Mobile,
  4210. Email: userData.Email,
  4211. OriginalUserInfo: "",
  4212. UserInfo: string(userInfo),
  4213. OriginalUserSellerInfo: "",
  4214. UserSellerInfo: "",
  4215. OpUserId: sysUser.AdminId,
  4216. OpUserName: sysUser.RealName,
  4217. CreateTime: time.Now(),
  4218. })
  4219. }
  4220. }
  4221. }
  4222. //添加已经存在的联系人与销售员关系
  4223. fmt.Println("开始添加已经存在的联系人与销售员关系")
  4224. for _, notRelationUserMap := range notRelationUser {
  4225. if item, ok := notRelationUserMap[1]; ok {
  4226. //添加联系人与销售员的关系
  4227. mobileOne := item.Mobile
  4228. mobileTwo := item.MobileTwo
  4229. email := item.Email
  4230. businessCardUrl := item.BusinessCardUrl
  4231. //对老数据做新增字段处理
  4232. _ = company.EditCompanyUserContact(item.UserId, mobileOne, mobileTwo, email, businessCardUrl)
  4233. models.AddUserSellerRelation(item.UserId, item.CompanyId, item.SellerId, 1, item.SellerName, item.Mobile, item.Email)
  4234. }
  4235. if item, ok := notRelationUserMap[2]; ok {
  4236. //添加联系人与销售员的关系
  4237. mobileOne := item.Mobile
  4238. mobileTwo := item.MobileTwo
  4239. email := item.Email
  4240. businessCardUrl := item.BusinessCardUrl
  4241. //对老数据做新增字段处理
  4242. _ = company.EditCompanyUserContact(item.UserId, mobileOne, mobileTwo, email, businessCardUrl)
  4243. models.AddUserSellerRelation(item.UserId, item.CompanyId, item.SellerId, 2, item.SellerName, item.Mobile, item.Email)
  4244. }
  4245. }
  4246. fmt.Println("开始更新联系人信息")
  4247. for _, updateWxUser := range updateWxUserSlice {
  4248. _ = updateWxUser.WxUser.Update(updateWxUser.Cols)
  4249. //联系人信息
  4250. originalUserInfo, _ := json.Marshal(updateWxUser.OldWxUser)
  4251. userInfo, _ := json.Marshal(updateWxUser.WxUser)
  4252. go services.AddWxUserOpLog(company.WxUserOpLog{
  4253. LogType: "import",
  4254. UserId: int(updateWxUser.WxUser.UserId),
  4255. CompanyId: updateWxUser.WxUser.CompanyId,
  4256. Mobile: updateWxUser.WxUser.Mobile,
  4257. Email: updateWxUser.WxUser.Email,
  4258. OriginalUserInfo: string(originalUserInfo),
  4259. UserInfo: string(userInfo),
  4260. OriginalUserSellerInfo: "",
  4261. UserSellerInfo: "",
  4262. OpUserId: sysUser.AdminId,
  4263. OpUserName: sysUser.RealName,
  4264. CreateTime: time.Now(),
  4265. })
  4266. }
  4267. defer func() {
  4268. os.Remove(path)
  4269. }()
  4270. if len(existUser) > 0 {
  4271. br.Ret = 600
  4272. br.Msg = "系统中已存在用户"
  4273. br.IsSendEmail = false
  4274. br.Data = existUser
  4275. return
  4276. }
  4277. //更新客户最近阅读次数以及最近阅读时间
  4278. go services.ModifyCompanyProductLastViewData([]int{companyId})
  4279. br.Msg = "导入成功"
  4280. br.Ret = 200
  4281. br.Success = true
  4282. }
  4283. // @Title 客户的联系人导出
  4284. // @Description 客户的联系人导出接口
  4285. // @Param CompanyId query int true "公司id,必填"
  4286. // @Param KeyWord query string true "搜索关键词"
  4287. // @Success 200 {object} company.CompanyUserListResp
  4288. // @router /user/exportByCompanyId [get]
  4289. func (this *CompanyUserController) Export() {
  4290. br := new(models.BaseResponse).Init()
  4291. defer func() {
  4292. this.Data["json"] = br
  4293. this.ServeJSON()
  4294. }()
  4295. sysUser := this.SysUser
  4296. if sysUser == nil {
  4297. br.Msg = "请登录"
  4298. br.ErrMsg = "请登录,SysUser Is Empty"
  4299. br.Ret = 408
  4300. return
  4301. }
  4302. companyId, _ := this.GetInt("CompanyId")
  4303. keyWord := utils.TrimStr(this.GetString("KeyWord"))
  4304. if companyId <= 0 {
  4305. br.Msg = "请选择客户"
  4306. br.ErrMsg = "客户参数错误"
  4307. return
  4308. }
  4309. var startSize int
  4310. var condition string
  4311. var pars []interface{}
  4312. if keyWord != "" {
  4313. condition += ` AND (a.real_name LIKE '%` + keyWord + `%' OR a.mobile LIKE '%` + keyWord + `%' OR a.email LIKE '%` + keyWord + `%') `
  4314. }
  4315. //非管理员,那么只能看到该产品下的联系人
  4316. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  4317. productId := services.GetProductId(sysUser.RoleTypeCode)
  4318. condition += ` AND b.product_id = ? `
  4319. pars = append(pars, productId)
  4320. }
  4321. list, err := company.GetCompanyUserListV2(condition, pars, companyId, startSize, 100000)
  4322. if err != nil {
  4323. br.Msg = "获取失败"
  4324. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  4325. return
  4326. }
  4327. //获取企业客户信息
  4328. companyInfo, err := company.GetCompanyById(companyId)
  4329. if err != nil {
  4330. br.Msg = "获取失败"
  4331. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  4332. return
  4333. }
  4334. lenList := len(list)
  4335. if lenList > 0 {
  4336. userIdSlice := make([]string, 0)
  4337. mobilesSlice := make([]string, 0)
  4338. emailsSlice := make([]string, 0)
  4339. for _, v := range list {
  4340. userIdSlice = append(userIdSlice, strconv.Itoa(int(v.UserId)))
  4341. if v.Mobile != "" {
  4342. mobilesSlice = append(mobilesSlice, v.Mobile)
  4343. } else if v.Email != "" {
  4344. emailsSlice = append(emailsSlice, v.Email)
  4345. }
  4346. }
  4347. //用户浏览数据
  4348. userIdStr := strings.Join(userIdSlice, ",")
  4349. mobileStr := strings.Join(mobilesSlice, "','")
  4350. mobileStr = "'" + mobileStr + "'"
  4351. emailStr := strings.Join(emailsSlice, "','")
  4352. emailStr = "'" + emailStr + "'"
  4353. //userViewTotalList, _ := models.GetCountUserViewHistoryByUserIds(userIdStr)
  4354. //userViewTotalMap := make(map[int]*models.UserViewTotalSlice)
  4355. //for _, userView := range userViewTotalList {
  4356. // userViewTotalMap[userView.UserId] = userView
  4357. //}
  4358. //用户日评浏览数据
  4359. //userReportViewTotalList, _ := models.GetReportViewMaxTimeByUserIds(userIdStr)
  4360. //userReportViewTotalMap := make(map[int]*models.ReportViewRecord)
  4361. //for _, userReportView := range userReportViewTotalList {
  4362. // userReportViewTotalMap[userReportView.UserId] = userReportView
  4363. //}
  4364. //报告统计删除晨报部分统计加入每日资讯 2021-4-9
  4365. //手机号
  4366. userViewMobileTotalMap := make(map[string]*models.UserViewMobileTotalSlice)
  4367. userReportViewMobileTotalMap := make(map[string]*models.ReportViewMobileRecord)
  4368. userAdvisoryViewMobileTotalMap := make(map[string]*advisory.UserViewMobileTotalSlice)
  4369. userCygxArticleHistoryRecordViewMobileTotalMap := make(map[string]*models.UserViewMobileTotalSlice)
  4370. if len(mobilesSlice) > 0 {
  4371. //用户浏览数据
  4372. userViewMobileTotalList, _ := models.GetCountUserViewHistoryByMobiles(mobileStr)
  4373. for _, userViewMobile := range userViewMobileTotalList {
  4374. userViewMobileTotalMap[userViewMobile.Mobile] = userViewMobile
  4375. }
  4376. //每日点评手机号数据
  4377. userReportViewMobileTotalList, _ := models.GetReportViewMaxTimeByMobiles(mobileStr)
  4378. for _, userReportViewMobile := range userReportViewMobileTotalList {
  4379. userReportViewMobileTotalMap[userReportViewMobile.Mobile] = userReportViewMobile
  4380. }
  4381. //每日资讯
  4382. userAdvisoryViewMobileTotalList, _ := advisory.GetCountUserViewHistoryByMobiles(mobileStr)
  4383. //fmt.Println(userAdvisoryViewMobileTotalList)
  4384. for _, userAdvisoryViewMobile := range userAdvisoryViewMobileTotalList {
  4385. userAdvisoryViewMobileTotalMap[userAdvisoryViewMobile.Mobile] = userAdvisoryViewMobile
  4386. }
  4387. //查研观向
  4388. userCygxArticleHistoryRecordViewMobileTotalList, _ := models.GetCountCygxArticleHistoryRecordByMobiles(mobileStr)
  4389. for _, userCygxArticleHistoryRecordViewMobile := range userCygxArticleHistoryRecordViewMobileTotalList {
  4390. userCygxArticleHistoryRecordViewMobileTotalMap[userCygxArticleHistoryRecordViewMobile.Mobile] = userCygxArticleHistoryRecordViewMobile
  4391. }
  4392. }
  4393. //邮箱
  4394. userViewEmailTotalMap := make(map[string]*models.UserViewEmailTotalSlice)
  4395. userReportViewEmailTotalMap := make(map[string]*models.ReportViewEmailRecord)
  4396. userAdvisoryViewEmailTotalMap := make(map[string]*advisory.UserViewEmailTotalSlice)
  4397. userCygxViewEmailTotalMap := make(map[string]*models.UserViewEmailTotalSlice)
  4398. if len(emailsSlice) > 0 {
  4399. //用户浏览数据
  4400. userViewEmailTotalList, _ := models.GetCountUserViewHistoryByEmails(emailStr)
  4401. for _, userViewEmail := range userViewEmailTotalList {
  4402. userViewEmailTotalMap[userViewEmail.Email] = userViewEmail
  4403. }
  4404. //每日点评手机号数据
  4405. userReportViewEmailTotalList, _ := models.GetReportViewMaxTimeByEmails(emailStr)
  4406. for _, userReportViewEmail := range userReportViewEmailTotalList {
  4407. userReportViewEmailTotalMap[userReportViewEmail.Email] = userReportViewEmail
  4408. }
  4409. //每日资讯
  4410. userAdvisoryViewEmailTotalList, _ := advisory.GetCountUserViewHistoryByEmails(emailStr)
  4411. for _, userAdvisoryViewEmail := range userAdvisoryViewEmailTotalList {
  4412. userAdvisoryViewEmailTotalMap[userAdvisoryViewEmail.Email] = userAdvisoryViewEmail
  4413. }
  4414. //查研观向
  4415. userCygxViewEmailTotalList, _ := models.GetCountCygxArticleHistoryRecordByEmails(emailStr)
  4416. for _, userCygxReportViewEmail := range userCygxViewEmailTotalList {
  4417. userCygxViewEmailTotalMap[userCygxReportViewEmail.Email] = userCygxReportViewEmail
  4418. }
  4419. }
  4420. //获取联系人关联产品的条数
  4421. //userSellerRelationTotalSlice, err := models.GetUserSellerRelationCountByUserIds(userIdStr)
  4422. //if err != nil {
  4423. // br.Msg = "获取失败"
  4424. // br.ErrMsg = "获取联系人与销售员信息失败,Err:" + err.Error()
  4425. // return
  4426. //}
  4427. //userSellerRelationTotalMap := make(map[int]*models.UserSellerRelationSlice)
  4428. //for _, userSellerRelationTotal := range userSellerRelationTotalSlice {
  4429. // userSellerRelationTotalMap[userSellerRelationTotal.UserId] = userSellerRelationTotal
  4430. //}
  4431. userRecordRegisterMap := make(map[int]time.Time)
  4432. if len(userIdSlice) > 0 {
  4433. //用户绑定注册数据
  4434. userRecordRegisterList, _ := models.GetUserRecordRegisterByUserIds(userIdStr)
  4435. for _, userRecordRegister := range userRecordRegisterList {
  4436. userRecordRegisterMap[userRecordRegister.UserId] = userRecordRegister.CreateTime
  4437. }
  4438. }
  4439. for i := 0; i < lenList; i++ {
  4440. item := list[i]
  4441. //企业名称
  4442. list[i].CompanyName = companyInfo.CompanyName
  4443. //手机号用户累计浏览次数
  4444. if userView, ok := userViewMobileTotalMap[item.Mobile]; ok {
  4445. list[i].ViewTotal += userView.Total
  4446. if userView.CreatedTime.After(list[i].LastViewTime) {
  4447. list[i].LastViewTime = userView.CreatedTime
  4448. list[i].LastViewTimeStr = userView.CreatedTime.Format(utils.FormatDateTime)
  4449. }
  4450. }
  4451. //邮箱用户累计浏览次数
  4452. if userView, ok := userViewEmailTotalMap[item.Email]; ok {
  4453. //总共浏览的报表数据需要调整为(手机号用户浏览晨报数+邮箱号用户浏览晨报数)
  4454. list[i].ViewTotal += userView.Total
  4455. if userView.CreatedTime.After(list[i].LastViewTime) {
  4456. list[i].LastViewTime = userView.CreatedTime
  4457. list[i].LastViewTimeStr = userView.CreatedTime.Format(utils.FormatDateTime)
  4458. }
  4459. }
  4460. if item.OpenId != "" {
  4461. list[i].IsRegister = true
  4462. } else {
  4463. if item.RegisterPlatform == 2 {
  4464. if item.Mobile != "" || item.Email != "" {
  4465. list[i].IsRegister = true
  4466. }
  4467. } else if item.RegisterTime != "" {
  4468. list[i].IsRegister = true
  4469. } else {
  4470. list[i].IsRegister = false
  4471. }
  4472. }
  4473. //如果存在手机号用户日评数据,那么需要做处理
  4474. if reportView, ok := userReportViewMobileTotalMap[item.Mobile]; ok {
  4475. //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
  4476. if reportView.LastViewTime.After(list[i].LastViewTime) {
  4477. list[i].LastViewTime = reportView.LastViewTime
  4478. list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
  4479. }
  4480. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
  4481. list[i].ViewTotal += reportView.ViewTotal
  4482. }
  4483. //如果存在手机号用户日评数据,那么需要做处理
  4484. if reportView, ok := userReportViewEmailTotalMap[item.Email]; ok {
  4485. //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
  4486. if reportView.LastViewTime.After(list[i].LastViewTime) {
  4487. list[i].LastViewTime = reportView.LastViewTime
  4488. list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
  4489. }
  4490. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
  4491. list[i].ViewTotal += reportView.ViewTotal
  4492. }
  4493. //如果存在手机号用户每日资讯,那么需要做处理
  4494. if advisoryView, ok := userAdvisoryViewMobileTotalMap[item.Mobile]; ok {
  4495. //fmt.Println("蝴蝶眨几次眼睛")
  4496. //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  4497. if advisoryView.CreatedTime.After(list[i].LastViewTime) {
  4498. list[i].LastViewTime = advisoryView.CreatedTime
  4499. list[i].LastViewTimeStr = advisoryView.CreatedTime.Format(utils.FormatDateTime)
  4500. }
  4501. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数)
  4502. list[i].ViewTotal += advisoryView.Total
  4503. }
  4504. //如果存在邮箱号用户每日资讯,那么需要做处理
  4505. if advisoryView, ok := userAdvisoryViewEmailTotalMap[item.Email]; ok {
  4506. //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  4507. if advisoryView.CreatedTime.After(list[i].LastViewTime) {
  4508. list[i].LastViewTime = advisoryView.CreatedTime
  4509. list[i].LastViewTimeStr = advisoryView.CreatedTime.Format(utils.FormatDateTime)
  4510. }
  4511. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数)
  4512. list[i].ViewTotal += advisoryView.Total
  4513. }
  4514. //如果存在手机号用户查研观向,那么需要做处理
  4515. if cygxView, ok := userCygxArticleHistoryRecordViewMobileTotalMap[item.Mobile]; ok {
  4516. //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  4517. if cygxView.CreatedTime.After(list[i].LastViewTime) {
  4518. list[i].LastViewTime = cygxView.CreatedTime
  4519. list[i].LastViewTimeStr = cygxView.CreatedTime.Format(utils.FormatDateTime)
  4520. }
  4521. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数+查研观向)
  4522. list[i].ViewTotal += cygxView.Total
  4523. }
  4524. //如果存在邮箱号用户查研观向,那么需要做处理
  4525. if cygxView, ok := userCygxViewEmailTotalMap[item.Email]; ok {
  4526. //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  4527. if cygxView.CreatedTime.After(list[i].LastViewTime) {
  4528. list[i].LastViewTime = cygxView.CreatedTime
  4529. list[i].LastViewTimeStr = cygxView.CreatedTime.Format(utils.FormatDateTime)
  4530. }
  4531. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数+查研观向)
  4532. list[i].ViewTotal += cygxView.Total
  4533. }
  4534. /*if reportView, ok := userReportViewTotalMap[int(item.UserId)]; ok {
  4535. //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
  4536. if reportView.LastViewTime.After(list[i].LastViewTime) {
  4537. list[i].LastViewTime = reportView.LastViewTime
  4538. list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
  4539. }
  4540. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
  4541. list[i].ViewTotal += reportView.ViewTotal
  4542. }*/
  4543. //如果有绑定数据,那么将数据返回对应的注册绑定数据
  4544. if _, ok := userRecordRegisterMap[int(item.UserId)]; ok {
  4545. list[i].IsRegister = true
  4546. //list[i].RegisterTime = userRecordRegisterTime.Format(utils.FormatDateTime)
  4547. }
  4548. //是否共享联系人
  4549. //if userSellerRelationTotal, ok := userSellerRelationTotalMap[int(item.UserId)]; ok {
  4550. // //条数大于1,代表这是共享联系人
  4551. // if userSellerRelationTotal.Total > 1 {
  4552. // list[i].IsShared = true
  4553. // }
  4554. //}
  4555. }
  4556. }
  4557. dir, err := os.Executable()
  4558. exPath := filepath.Dir(dir)
  4559. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  4560. xlsxFile := xlsx.NewFile()
  4561. if err != nil {
  4562. br.Msg = "生成文件失败"
  4563. br.ErrMsg = "生成文件失败"
  4564. return
  4565. }
  4566. style := xlsx.NewStyle()
  4567. alignment := xlsx.Alignment{
  4568. Horizontal: "center",
  4569. Vertical: "center",
  4570. WrapText: true,
  4571. }
  4572. style.Alignment = alignment
  4573. style.ApplyAlignment = true
  4574. sheel, err := xlsxFile.AddSheet("联系人数据")
  4575. if err != nil {
  4576. br.Msg = "新增Sheet失败"
  4577. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  4578. return
  4579. }
  4580. sheel.SetColWidth(0, 0, 18)
  4581. sheel.SetColWidth(1, 2, 24)
  4582. sheel.SetColWidth(3, 3, 20)
  4583. sheel.SetColWidth(4, 4, 40)
  4584. titleRow := sheel.AddRow()
  4585. cellName := titleRow.AddCell()
  4586. cellName.SetStyle(style)
  4587. cellName.SetValue("姓名")
  4588. cellMobile := titleRow.AddCell()
  4589. cellMobile.SetStyle(style)
  4590. cellMobile.SetValue("手机号")
  4591. cellEmail := titleRow.AddCell()
  4592. cellEmail.SetStyle(style)
  4593. cellEmail.SetValue("邮箱")
  4594. cellMark := titleRow.AddCell()
  4595. cellMark.SetStyle(style)
  4596. cellMark.SetValue("是否决策人")
  4597. cellCompanyName := titleRow.AddCell()
  4598. cellCompanyName.SetStyle(style)
  4599. cellCompanyName.SetValue("客户名称")
  4600. for _, v := range list {
  4601. dataRow := sheel.AddRow()
  4602. dataRow.SetHeight(20)
  4603. isMark := "否"
  4604. if v.IsMaker == 1 {
  4605. isMark = "是"
  4606. }
  4607. cellDataName := dataRow.AddCell()
  4608. cellDataName.SetStyle(style)
  4609. cellDataName.SetValue(v.RealName)
  4610. cellDataMobile := dataRow.AddCell()
  4611. cellDataMobile.SetStyle(style)
  4612. cellDataMobile.SetValue(v.Mobile)
  4613. cellDataEmail := dataRow.AddCell()
  4614. cellDataEmail.SetStyle(style)
  4615. cellDataEmail.SetValue(v.Email)
  4616. cellDataMark := dataRow.AddCell()
  4617. cellDataMark.SetStyle(style)
  4618. cellDataMark.SetValue(isMark)
  4619. cellDataCompanyName := dataRow.AddCell()
  4620. cellDataCompanyName.SetStyle(style)
  4621. cellDataCompanyName.SetValue(companyInfo.CompanyName)
  4622. }
  4623. err = xlsxFile.Save(downLoadnFilePath)
  4624. if err != nil {
  4625. br.Msg = "保存文件失败"
  4626. br.ErrMsg = "保存文件失败"
  4627. return
  4628. }
  4629. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  4630. downloadFileName := "联系人列表_" + randStr + ".xlsx"
  4631. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  4632. defer func() {
  4633. os.Remove(downLoadnFilePath)
  4634. }()
  4635. br.Ret = 200
  4636. br.Success = true
  4637. br.Msg = "导出成功"
  4638. }
  4639. // 检测产品
  4640. func checkProductListUser(item models.WxUserDetail, companyUser *company.CompanyUser, companyProductList []*company.CompanyProduct) (notRelationUserMap map[int]*company.CompanyUser, err error) {
  4641. notRelationUserMap = make(map[int]*company.CompanyUser)
  4642. //判断该用户与当前账号是否存在关系,如果没有关系,那么直接返回
  4643. for _, companyProduct := range companyProductList {
  4644. _, relationErr := models.GetUserSellerRelation(companyUser.UserId, companyProduct.SellerId)
  4645. //找到数据了
  4646. if relationErr == nil {
  4647. continue
  4648. }
  4649. //sql异常
  4650. if relationErr.Error() != utils.ErrNoRow() {
  4651. err = relationErr
  4652. return
  4653. }
  4654. //没找到数据,不存在关系
  4655. //如果不存在关系,那么直接添加关系就好了,其他操作不做
  4656. if relationErr.Error() == utils.ErrNoRow() {
  4657. if item.Mobile != "" && companyUser.Mobile == "" {
  4658. companyUser.Mobile = strings.Replace(item.Mobile, " ", "", -1)
  4659. }
  4660. if item.Email != "" && companyUser.Email == "" {
  4661. companyUser.Email = strings.Replace(companyUser.Email, " ", "", -1)
  4662. }
  4663. companyUser.SellerId = companyProduct.SellerId
  4664. companyUser.SellerName = companyProduct.SellerName
  4665. companyUser.DepartmentId = companyProduct.DepartmentId
  4666. companyUser.GroupId = companyProduct.GroupId
  4667. notRelationUserMap[companyProduct.ProductId] = companyUser
  4668. }
  4669. }
  4670. return
  4671. }
  4672. // @Title 下载模板
  4673. // @Description 下载模板
  4674. // @Success 200
  4675. // @router /template [get]
  4676. func (this *CompanyUserController) TemplateDownload() {
  4677. br := new(models.BaseResponse).Init()
  4678. defer func() {
  4679. this.Data["json"] = br
  4680. this.ServeJSON()
  4681. }()
  4682. this.Ctx.Output.Download("./static/导入联系人模板.xlsx", "导入联系人模板.xlsx")
  4683. br.Ret = 200
  4684. br.Success = true
  4685. br.Msg = "下载成功"
  4686. }
  4687. //百度
  4688. //func init() {
  4689. // fmt.Println("start")
  4690. // businessCardUrl := `https://hongze.oss-accelerate.aliyuncs.com/static/images/202101/20210111/wB3ELOuH8AxTvrIDXHaFTn9Z0WXB.jpg`
  4691. // services.GetBdGeneralBasic(businessCardUrl)
  4692. // fmt.Println("end")
  4693. //}
  4694. //阿里云
  4695. //func init() {
  4696. // fmt.Println("start")
  4697. // businessCardUrl := `https://hongze.oss-accelerate.aliyuncs.com/static/images/202101/20210111/wB3ELOuH8AxTvrIDXHaFTn9Z0WXB.jpg`
  4698. // aliyunResult, err := services.AliyunBusinessCardOcr(businessCardUrl)
  4699. //
  4700. // if err != nil {
  4701. // fmt.Println("line 1026")
  4702. // return
  4703. // }
  4704. // if !aliyunResult.Success {
  4705. // fmt.Println("line 1026")
  4706. // return
  4707. // }
  4708. //
  4709. // mobileStr := strings.Join(aliyunResult.TelCell, ",")
  4710. // mobileOne:="18366208402"
  4711. // if strings.Contains(mobileStr, mobileOne) {
  4712. // fmt.Println("true")
  4713. // } else {
  4714. // fmt.Println("false")
  4715. // }
  4716. // fmt.Println("end")
  4717. //}
  4718. // 获取是否拥有操作权限
  4719. func checkOpCompanyUserByUserId(userId, productId, opId int, roleTypeCode string) (errMsg string, err error) {
  4720. userInfo, userErr := models.GetWxUserByUserId(userId)
  4721. if userErr != nil {
  4722. errMsg = "查询用户信息失败"
  4723. err = errors.New("查询用户信息失败,Err:" + userErr.Error())
  4724. return
  4725. }
  4726. //产品权限
  4727. //获取当前操作员产品权限
  4728. companyProductList, productErr := getSysCompanyProductList(productId, userInfo.CompanyId)
  4729. if productErr != nil {
  4730. errMsg = "获取当前操作员产品权限异常"
  4731. err = errors.New("删除失败,获取当前操作员产品权限异常,Err:" + productErr.Error())
  4732. return
  4733. }
  4734. if companyProductList == nil {
  4735. errMsg = "删除失败"
  4736. err = errors.New("删除失败,获取当前操作员找不到产品权限")
  4737. return
  4738. }
  4739. //操作权限校验
  4740. for _, v := range companyProductList {
  4741. companyUserStatus := services.CheckCompanyUserButton(roleTypeCode, v.SellerId, opId, v.ProductId, v.ShareSellerId, v.Status)
  4742. if companyUserStatus == false {
  4743. errMsg = "没有操作权限"
  4744. err = errors.New("没有操作权限")
  4745. return
  4746. }
  4747. }
  4748. return
  4749. }
  4750. // 获取是否拥有操作权限
  4751. func checkOpCompanyUserByCompanyId(companyId, productId, opId int, roleTypeCode string) (errMsg string, err error) {
  4752. //获取当前操作员产品权限
  4753. companyProductList, productErr := getSysCompanyProductList(productId, companyId)
  4754. if productErr != nil {
  4755. errMsg = "获取当前操作员产品权限异常"
  4756. err = errors.New("删除失败,获取当前操作员产品权限异常,Err:" + productErr.Error())
  4757. return
  4758. }
  4759. if companyProductList == nil {
  4760. errMsg = "删除失败"
  4761. err = errors.New("删除失败,获取当前操作员找不到产品权限")
  4762. return
  4763. }
  4764. //操作权限校验
  4765. for _, v := range companyProductList {
  4766. companyUserStatus := services.CheckCompanyUserButton(roleTypeCode, v.SellerId, opId, v.ProductId, v.ShareSellerId, v.Status)
  4767. if companyUserStatus == false {
  4768. errMsg = "没有操作权限"
  4769. err = errors.New("没有操作权限")
  4770. return
  4771. }
  4772. }
  4773. return
  4774. }
  4775. // @Title FICC申请单-移动潜在用户
  4776. // @Description FICC申请单移动潜在用户接口
  4777. // @Param request body models.ApplyRecordPotentialUserMoveReq true "type json string"
  4778. // @Success Ret=200 移动成功
  4779. // @router /potential/user/moveByApplyRecord [post]
  4780. func (this *CompanyController) ApplyRecordPotentialUserMove() {
  4781. br := new(models.BaseResponse).Init()
  4782. defer func() {
  4783. this.Data["json"] = br
  4784. this.ServeJSON()
  4785. }()
  4786. sysUser := this.SysUser
  4787. if sysUser == nil {
  4788. br.Msg = "请登录"
  4789. br.ErrMsg = "请登录,SysUser Is Empty"
  4790. br.Ret = 408
  4791. return
  4792. }
  4793. var req models.ApplyRecordPotentialUserMoveReq
  4794. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4795. if err != nil {
  4796. br.Msg = "参数解析异常!"
  4797. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4798. return
  4799. }
  4800. if req.UserId <= 0 {
  4801. br.Msg = "参数错误"
  4802. br.ErrMsg = "客户id错误"
  4803. return
  4804. }
  4805. wxUser, err := models.GetWxUserByUserId(req.UserId)
  4806. //如果移动客户编号小于等于0,那么移动到潜在客户
  4807. if req.CompanyId <= 0 {
  4808. req.CompanyId = 1
  4809. }
  4810. if err != nil {
  4811. br.Msg = "移动失败,该潜在用户已被删除"
  4812. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  4813. return
  4814. }
  4815. if req.Mobile == "" {
  4816. req.Mobile = wxUser.Mobile
  4817. }
  4818. if req.Email == "" {
  4819. req.Email = wxUser.Email
  4820. }
  4821. if req.Mobile == "" && req.Email == "" {
  4822. br.Msg = "手机号和邮箱不能同时为空"
  4823. return
  4824. }
  4825. //校验手机号
  4826. if req.Mobile != "" && wxUser.Mobile != req.Mobile {
  4827. count, err := models.CheckUserMobileIsRegister(req.UserId, req.Mobile)
  4828. if err != nil {
  4829. br.Msg = "校验数据失败"
  4830. br.ErrMsg = "校验数据失败,Err:" + err.Error()
  4831. return
  4832. }
  4833. if count > 0 {
  4834. br.Msg = "该手机号已经注册过用户"
  4835. return
  4836. }
  4837. }
  4838. //校验邮箱
  4839. if req.Email != "" && wxUser.Email != req.Email {
  4840. if !utils.ValidateEmailFormatat(req.Email) {
  4841. br.Msg = "请输入正确的邮箱(包含@)"
  4842. return
  4843. }
  4844. count, err := models.CheckUserEmailIsRegister(req.UserId, req.Email)
  4845. if err != nil {
  4846. br.Msg = "校验数据失败"
  4847. br.ErrMsg = "校验数据失败,Err:" + err.Error()
  4848. return
  4849. }
  4850. if count > 0 {
  4851. br.Msg = "该邮箱已经注册过用户"
  4852. br.IsSendEmail = false
  4853. return
  4854. }
  4855. }
  4856. updateCol := make([]string, 0)
  4857. if wxUser.OutboundMobile == "" || wxUser.Mobile == wxUser.OutboundMobile {
  4858. wxUser.OutboundMobile = req.Mobile
  4859. wxUser.OutboundCountryCode = req.CountryCode
  4860. updateCol = append(updateCol, "OutboundMobile", "OutboundCountryCode")
  4861. }
  4862. if req.Email != "" {
  4863. wxUser.Email = req.Email
  4864. updateCol = append(updateCol, "Email")
  4865. }
  4866. if req.RealName != "" {
  4867. wxUser.RealName = req.RealName
  4868. updateCol = append(updateCol, "RealName")
  4869. }
  4870. if req.Mobile != "" {
  4871. wxUser.Mobile = req.Mobile
  4872. updateCol = append(updateCol, "Mobile")
  4873. }
  4874. if req.CountryCode != "" {
  4875. wxUser.CountryCode = req.CountryCode
  4876. updateCol = append(updateCol, "CountryCode")
  4877. }
  4878. if req.Position != "" {
  4879. wxUser.Position = req.Position
  4880. updateCol = append(updateCol, "Position")
  4881. }
  4882. if wxUser.DepartmentName == "" && req.DepartmentName != "" {
  4883. wxUser.DepartmentName = req.DepartmentName
  4884. updateCol = append(updateCol, "DepartmentName")
  4885. }
  4886. wxUser.Sex = req.Sex
  4887. wxUser.IsMaker = req.IsMaker
  4888. updateCol = append(updateCol, "Sex", "IsMaker")
  4889. //名片匹配
  4890. if req.BusinessCardUrl != "" {
  4891. //if req.BusinessCardUrl != "" && utils.RunMode == "release" {
  4892. // 获取图片识别手机号的配置
  4893. crmConfig2, err := company.GetConfigDetailByCode("card_recognition_tel")
  4894. if err != nil {
  4895. br.Msg = "获取配置失败"
  4896. br.ErrMsg = "获取配置失败"
  4897. br.IsSendEmail = false
  4898. return
  4899. }
  4900. if crmConfig2.ConfigValue == "true" {
  4901. card, err := services.GetBusinessCard(req.BusinessCardUrl)
  4902. if err != nil {
  4903. br.Msg = "名片识别失败"
  4904. br.ErrMsg = "名片识别失败,Err:" + err.Error()
  4905. return
  4906. }
  4907. isFlag := false
  4908. if len(card.WordsResult.MOBILE) > 0 {
  4909. mobileStr := strings.Join(card.WordsResult.MOBILE, ",")
  4910. //if req.Mobile != "" {
  4911. // if strings.Contains(mobileStr, req.Mobile) || mobileStr == "" {
  4912. // isFlag = true
  4913. // } else {
  4914. // isFlag = false
  4915. // }
  4916. //}
  4917. if req.Mobile != "" && strings.Contains(mobileStr, req.Mobile) {
  4918. isFlag = true
  4919. }
  4920. }
  4921. if !isFlag {
  4922. //阿里云识别
  4923. //if utils.RunMode == "release" {
  4924. aliyunResult, errMsg, err := services.AliyunOcrBusinessCard(req.BusinessCardUrl)
  4925. if err != nil {
  4926. br.Msg = "识别失败"
  4927. br.ErrMsg = "识别失败,Err:" + err.Error()
  4928. return
  4929. }
  4930. if !aliyunResult.Success {
  4931. br.Msg = "识别失败"
  4932. br.ErrMsg = "识别失败"
  4933. return
  4934. }
  4935. if errMsg != "" {
  4936. br.Msg = errMsg
  4937. return
  4938. }
  4939. if len(aliyunResult.TelCell) > 0 {
  4940. mobileStr := strings.Join(aliyunResult.TelCell, ",")
  4941. if req.Mobile != "" {
  4942. if strings.Contains(mobileStr, req.Mobile) {
  4943. isFlag = true
  4944. } else {
  4945. isFlag = false
  4946. }
  4947. }
  4948. } else {
  4949. isFlag = true
  4950. }
  4951. //}
  4952. }
  4953. if !isFlag && crmConfig2.ConfigValue == "true" {
  4954. br.Msg = "名片信息与联系人手机号不符"
  4955. return
  4956. }
  4957. }
  4958. wxUser.BusinessCardUrl = req.BusinessCardUrl
  4959. updateCol = append(updateCol, "BusinessCardUrl")
  4960. }
  4961. productId := services.GetProductId(sysUser.RoleTypeCode)
  4962. companyProductList, _ := getSysCompanyProductList(productId, req.CompanyId)
  4963. err = services.MovePotentialUserByApplyRecord(sysUser.AdminId, req.UserId, req.CompanyId, req.ApplyRecordId, req.RealName, req.Mobile, req.Email, req.Remark, companyProductList, wxUser, updateCol)
  4964. if err != nil {
  4965. br.Msg = "移动失败"
  4966. br.ErrMsg = "移动失败,Err:" + err.Error()
  4967. return
  4968. }
  4969. //更新客户最近阅读次数以及最近阅读时间
  4970. go services.ModifyCompanyProductLastViewData([]int{req.CompanyId})
  4971. br.Ret = 200
  4972. br.Success = true
  4973. br.Msg = "移动成功"
  4974. br.IsAddLog = true
  4975. }
  4976. // @Title 新增联系人图表分类权限
  4977. // @Description 新增联系人图表分类权限接口
  4978. // @Param request body request.SaveCompanyUserChartClassifyPermissionReq true "type json string"
  4979. // @Success 200 Ret=200 操作成功
  4980. // @router /user/addChartClassifyPermission [post]
  4981. func (this *CompanyUserController) AddCompanyUserChartClassifyPermission() {
  4982. br := new(models.BaseResponse).Init()
  4983. defer func() {
  4984. this.Data["json"] = br
  4985. this.ServeJSON()
  4986. }()
  4987. sysUser := this.SysUser
  4988. if sysUser == nil {
  4989. br.Msg = "请登录"
  4990. br.ErrMsg = "请登录,SysUser Is Empty"
  4991. br.Ret = 408
  4992. return
  4993. }
  4994. var req request.SaveCompanyUserChartClassifyPermissionReq
  4995. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4996. if err != nil {
  4997. br.Msg = "参数解析异常!"
  4998. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4999. return
  5000. }
  5001. if req.UserId <= 0 {
  5002. br.Msg = "参数丢失:联系人ID"
  5003. br.ErrMsg = "参数丢失,联系人ID"
  5004. return
  5005. }
  5006. if req.StartTime == "" || req.EndTime == "" {
  5007. br.Msg = "请选择开始结束时间"
  5008. br.ErrMsg = "请选择开始结束时间"
  5009. br.IsSendEmail = false
  5010. return
  5011. }
  5012. startTime, err := time.Parse(utils.FormatDate, req.StartTime)
  5013. if err != nil {
  5014. br.Msg = "开始时间格式有误"
  5015. br.ErrMsg = "开始时间转换失败, Err:" + err.Error()
  5016. return
  5017. }
  5018. endTime, err := time.Parse(utils.FormatDate, req.EndTime)
  5019. if err != nil {
  5020. br.Msg = "结束时间格式有误"
  5021. br.ErrMsg = "结束时间转换失败, Err:" + err.Error()
  5022. return
  5023. }
  5024. if startTime.After(endTime) {
  5025. br.Msg = "结束时间不能小于开始时间"
  5026. br.ErrMsg = "结束时间不能小于开始时间"
  5027. br.IsSendEmail = false
  5028. return
  5029. }
  5030. _, err = company_user.GetChartClassifyPermissionByUserId(req.UserId)
  5031. if err == nil {
  5032. br.Msg = "请勿重复设置图表权限"
  5033. br.ErrMsg = "请勿重复设置图表权限"
  5034. br.IsSendEmail = false
  5035. return
  5036. }
  5037. // 判断是否允许设置
  5038. userInfo, err := models.GetWxUserByUserId(req.UserId)
  5039. if err != nil {
  5040. br.Msg = "联系人信息有误"
  5041. br.ErrMsg = "联系人信息有误, Err: " + err.Error()
  5042. return
  5043. }
  5044. companyInfo, err := company.GetCompanyById(userInfo.CompanyId)
  5045. if err != nil {
  5046. br.Msg = "获取客户信息失败"
  5047. br.ErrMsg = "获取客户信息失败, Err: " + err.Error()
  5048. return
  5049. }
  5050. companyProductInfo, err := company.GetCompanyProductByCompanyIdAndProductId(userInfo.CompanyId, 1)
  5051. if err != nil {
  5052. br.Msg = "获取客户产品信息失败"
  5053. br.ErrMsg = "获取客户产品信息失败, Err: " + err.Error()
  5054. return
  5055. }
  5056. companyStatus := companyProductInfo.Status
  5057. if companyStatus != utils.COMPANY_STATUS_FOREVER {
  5058. // 非永续客户
  5059. if companyStatus == utils.COMPANY_STATUS_TRY_OUT || companyStatus == utils.COMPANY_STATUS_FORMAL {
  5060. // 正式/试用
  5061. expireTimeStr := companyProductInfo.EndDate
  5062. expireTime, _ := time.ParseInLocation(utils.FormatDate, expireTimeStr, time.Local)
  5063. // 服务结束时间小于设置的结束时间则不允许设置
  5064. if endTime.After(expireTime.AddDate(0, 0, 1)) {
  5065. br.Msg = "终止日期不允许超过服务日期, 服务终止日期为: " + expireTimeStr
  5066. br.IsSendEmail = false
  5067. return
  5068. }
  5069. } else {
  5070. br.Msg = "当前客户不允许设置图表权限, 客户状态为: " + companyStatus
  5071. br.IsSendEmail = false
  5072. return
  5073. }
  5074. }
  5075. item := &company_user.ChartClassifyPermission{
  5076. UserId: req.UserId,
  5077. CompanyId: companyInfo.CompanyId,
  5078. StartTime: startTime,
  5079. EndTime: endTime,
  5080. Enabled: req.Enabled,
  5081. CreateTime: time.Now(),
  5082. }
  5083. _, err = company_user.AddChartClassifyPermission(item)
  5084. if err != nil {
  5085. br.Msg = "新增图表权限失败"
  5086. br.ErrMsg = "新增图表权限失败, Err:" + err.Error()
  5087. return
  5088. }
  5089. // 操作记录
  5090. {
  5091. record := &company_user.CompanyUserChartPermissionOperationRecord{
  5092. Type: 1,
  5093. CompanyId: companyInfo.CompanyId,
  5094. UserId: req.UserId,
  5095. AdminId: sysUser.AdminId,
  5096. StartTime: startTime,
  5097. EndTime: endTime,
  5098. Enabled: req.Enabled,
  5099. CreateTime: time.Now(),
  5100. }
  5101. go company_user.AddChartPermissionOperationRecord(record)
  5102. }
  5103. br.Ret = 200
  5104. br.Success = true
  5105. br.Msg = "操作成功"
  5106. }
  5107. // @Title 编辑联系人图表分类权限
  5108. // @Description 编辑联系人图表分类权限接口
  5109. // @Param request body request.SaveCompanyUserChartClassifyPermissionReq true "type json string"
  5110. // @Success 200 Ret=200 操作成功
  5111. // @router /user/editChartClassifyPermission [post]
  5112. func (this *CompanyUserController) EditCompanyUserChartClassifyPermission() {
  5113. br := new(models.BaseResponse).Init()
  5114. defer func() {
  5115. this.Data["json"] = br
  5116. this.ServeJSON()
  5117. }()
  5118. sysUser := this.SysUser
  5119. if sysUser == nil {
  5120. br.Msg = "请登录"
  5121. br.ErrMsg = "请登录,SysUser Is Empty"
  5122. br.Ret = 408
  5123. return
  5124. }
  5125. var req request.SaveCompanyUserChartClassifyPermissionReq
  5126. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5127. if err != nil {
  5128. br.Msg = "参数解析异常!"
  5129. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5130. return
  5131. }
  5132. if req.UserId <= 0 {
  5133. br.Msg = "参数丢失:联系人ID"
  5134. br.ErrMsg = "参数丢失,联系人ID"
  5135. return
  5136. }
  5137. if req.StartTime == "" || req.EndTime == "" {
  5138. br.Msg = "请选择开始结束时间"
  5139. br.ErrMsg = "请选择开始结束时间"
  5140. br.IsSendEmail = false
  5141. return
  5142. }
  5143. startTime, err := time.Parse(utils.FormatDate, req.StartTime)
  5144. if err != nil {
  5145. br.Msg = "开始时间格式有误"
  5146. br.ErrMsg = "开始时间转换失败, Err:" + err.Error()
  5147. return
  5148. }
  5149. endTime, err := time.Parse(utils.FormatDate, req.EndTime)
  5150. if err != nil {
  5151. br.Msg = "结束时间格式有误"
  5152. br.ErrMsg = "结束时间转换失败, Err:" + err.Error()
  5153. return
  5154. }
  5155. if startTime.After(endTime) {
  5156. br.Msg = "结束时间不能小于开始时间"
  5157. br.ErrMsg = "结束时间不能小于开始时间"
  5158. br.IsSendEmail = false
  5159. return
  5160. }
  5161. // 判断是否允许设置
  5162. userInfo, err := models.GetWxUserByUserId(req.UserId)
  5163. if err != nil {
  5164. br.Msg = "联系人信息有误"
  5165. br.ErrMsg = "联系人信息有误, Err: " + err.Error()
  5166. return
  5167. }
  5168. companyInfo, err := company.GetCompanyById(userInfo.CompanyId)
  5169. if err != nil {
  5170. br.Msg = "获取客户信息失败"
  5171. br.ErrMsg = "获取客户信息失败, Err: " + err.Error()
  5172. return
  5173. }
  5174. companyProductInfo, err := company.GetCompanyProductByCompanyIdAndProductId(userInfo.CompanyId, 1)
  5175. if err != nil {
  5176. br.Msg = "获取客户产品信息失败"
  5177. br.ErrMsg = "获取客户产品信息失败, Err: " + err.Error()
  5178. return
  5179. }
  5180. companyStatus := companyProductInfo.Status
  5181. if companyStatus != utils.COMPANY_STATUS_FOREVER {
  5182. // 非永续客户
  5183. if companyStatus == utils.COMPANY_STATUS_TRY_OUT || companyStatus == utils.COMPANY_STATUS_FORMAL {
  5184. // 正式/试用
  5185. expireTimeStr := companyProductInfo.EndDate
  5186. expireTime, _ := time.ParseInLocation(utils.FormatDate, expireTimeStr, time.Local)
  5187. // 服务结束时间小于设置的结束时间则不允许设置
  5188. if endTime.After(expireTime.AddDate(0, 0, 1)) {
  5189. br.Msg = "终止日期不允许超过服务日期, 服务终止日期为: " + expireTimeStr
  5190. br.IsSendEmail = false
  5191. return
  5192. }
  5193. } else {
  5194. br.Msg = "当前客户不允许设置图表权限, 客户状态为: " + companyStatus
  5195. br.IsSendEmail = false
  5196. return
  5197. }
  5198. }
  5199. permissionInfo, err := company_user.GetChartClassifyPermissionByUserId(req.UserId)
  5200. if err != nil {
  5201. br.Msg = "获取联系人图表分类权限失败"
  5202. br.ErrMsg = "获取联系人图表分类权限失败, Err:" + err.Error()
  5203. return
  5204. }
  5205. permissionInfo.CompanyId = companyInfo.CompanyId
  5206. permissionInfo.Enabled = req.Enabled
  5207. permissionInfo.StartTime = startTime
  5208. permissionInfo.EndTime = endTime
  5209. permissionInfo.UpdateTime = time.Now()
  5210. err = permissionInfo.Update([]string{"CompanyId", "Enabled", "StartTime", "EndTime", "UpdateTime"})
  5211. if err != nil {
  5212. br.Msg = "编辑联系人图表分类权限失败"
  5213. br.ErrMsg = "编辑联系人图表分类权限失败, Err:" + err.Error()
  5214. return
  5215. }
  5216. // 操作记录
  5217. {
  5218. record := &company_user.CompanyUserChartPermissionOperationRecord{
  5219. Type: 2,
  5220. CompanyId: companyInfo.CompanyId,
  5221. UserId: req.UserId,
  5222. AdminId: sysUser.AdminId,
  5223. StartTime: startTime,
  5224. EndTime: endTime,
  5225. Enabled: req.Enabled,
  5226. CreateTime: time.Now(),
  5227. }
  5228. go company_user.AddChartPermissionOperationRecord(record)
  5229. }
  5230. br.Ret = 200
  5231. br.Success = true
  5232. br.Msg = "操作成功"
  5233. }
  5234. // @Title 获取联系人图表分类权限详情
  5235. // @Description 获取联系人图表分类权限详情接口
  5236. // @Param UserId query int true "联系人ID,必填"
  5237. // @Success 200 {object} response.CompanyUserChartClassifyPermissionDetailResp
  5238. // @router /user/getChartClassifyPermissionDetail [get]
  5239. func (this *CompanyUserController) GetCompanyUserChartClassifyPermissionDetail() {
  5240. br := new(models.BaseResponse).Init()
  5241. defer func() {
  5242. this.Data["json"] = br
  5243. this.ServeJSON()
  5244. }()
  5245. sysUser := this.SysUser
  5246. if sysUser == nil {
  5247. br.Msg = "请登录"
  5248. br.ErrMsg = "请登录,SysUser Is Empty"
  5249. br.Ret = 408
  5250. return
  5251. }
  5252. reqUserId := this.GetString("UserId", "")
  5253. userId, _ := strconv.Atoi(reqUserId)
  5254. if userId <= 0 {
  5255. br.Msg = "参数丢失:联系人ID"
  5256. return
  5257. }
  5258. userInfo, err := models.GetWxUserByUserId(userId)
  5259. if err != nil {
  5260. br.Msg = "联系人信息有误"
  5261. br.ErrMsg = "联系人信息有误, Err: " + err.Error()
  5262. return
  5263. }
  5264. permissionInfo, err := company_user.GetChartClassifyPermissionByUserId(userId)
  5265. if err != nil && err.Error() != utils.ErrNoRow() {
  5266. br.Msg = "获取联系人图表分类权限失败"
  5267. br.ErrMsg = "获取联系人图表分类权限失败, Err:" + err.Error()
  5268. return
  5269. }
  5270. resp := new(response.CompanyUserChartClassifyPermissionDetailResp)
  5271. // 客户服务日期
  5272. companyProductInfo, err := company.GetCompanyProductByCompanyIdAndProductId(userInfo.CompanyId, 1)
  5273. if err != nil {
  5274. br.Msg = "获取客户产品信息失败"
  5275. br.ErrMsg = "获取客户产品信息失败, Err: " + err.Error()
  5276. return
  5277. }
  5278. companyStatus := companyProductInfo.Status
  5279. // 0-不允许设置 1-允许设置最大90天 2-90天
  5280. nowTime := time.Now()
  5281. free := 0
  5282. if companyStatus == utils.COMPANY_STATUS_FOREVER {
  5283. // 永续客户
  5284. free = 2
  5285. resp.ExpireDay = "2199-12-31"
  5286. } else if companyStatus == utils.COMPANY_STATUS_TRY_OUT || companyStatus == utils.COMPANY_STATUS_FORMAL {
  5287. free = 1
  5288. resp.ExpireDay = companyProductInfo.EndDate
  5289. } else {
  5290. resp.ExpireDay = nowTime.Format(utils.FormatDate)
  5291. }
  5292. var startTime, endTime time.Time
  5293. if permissionInfo != nil {
  5294. // 已设置
  5295. startTime = permissionInfo.StartTime
  5296. endTime = permissionInfo.EndTime
  5297. resp.ChartPermissionId = permissionInfo.Id
  5298. resp.UserId = permissionInfo.UserId
  5299. resp.StartTime = permissionInfo.StartTime.Format(utils.FormatDate)
  5300. resp.EndTime = permissionInfo.EndTime.Format(utils.FormatDate)
  5301. resp.Enabled = permissionInfo.Enabled
  5302. } else {
  5303. // 初次设置
  5304. startTime = nowTime
  5305. endTime = startTime.Add(89 * 24 * time.Hour) // 实际验证时以结束日期的23时59分为过期时间所以此处日期-1
  5306. if free == 0 {
  5307. endTime = nowTime
  5308. } else if free == 1 {
  5309. expireTime, _ := time.ParseInLocation(utils.FormatDate, companyProductInfo.EndDate, time.Local)
  5310. sub := expireTime.Sub(nowTime)
  5311. diff := int(sub.Hours() / 24)
  5312. if diff < 90 {
  5313. // 小于90天则终止时间为服务结束时间
  5314. endTime = expireTime
  5315. }
  5316. }
  5317. resp.StartTime = startTime.Format(utils.FormatDate)
  5318. resp.EndTime = endTime.Format(utils.FormatDate)
  5319. resp.UserId = userId
  5320. resp.Enabled = 0 // 默认关闭
  5321. }
  5322. // 计算阅读时长天数
  5323. subDuration := endTime.Sub(startTime)
  5324. subHours := subDuration.Hours()
  5325. subDays := int(subHours / 24)
  5326. resp.DayDuration = subDays + 1
  5327. br.Ret = 200
  5328. br.Success = true
  5329. br.Msg = "获取成功"
  5330. br.Data = resp
  5331. }
  5332. // GetOtherProduct
  5333. // @Title 获取其他分产品的筛选列表
  5334. // @Description 获取联系人图表分类权限详情接口
  5335. // @Param UserId query int true "联系人ID,必填"
  5336. // @Success 200 {object} response.CompanyUserChartClassifyPermissionDetailResp
  5337. // @router /user/otherProductList [get]
  5338. func (this *CompanyUserController) GetOtherProduct() {
  5339. br := new(models.BaseResponse).Init()
  5340. defer func() {
  5341. this.Data["json"] = br
  5342. this.ServeJSON()
  5343. }()
  5344. sysUser := this.SysUser
  5345. if sysUser == nil {
  5346. br.Msg = "请登录"
  5347. br.ErrMsg = "请登录,SysUser Is Empty"
  5348. br.Ret = 408
  5349. return
  5350. }
  5351. resp := make([]response.OtherProductTypeListResp, 0)
  5352. statisticFlag, _ := this.GetBool("StatisticFlag")
  5353. questionItem := response.OtherProductTypeListResp{
  5354. ProductId: 0,
  5355. ProductType: 3,
  5356. ProductName: "问答社区",
  5357. }
  5358. roadVideoItem := response.OtherProductTypeListResp{
  5359. ProductId: 2,
  5360. ProductType: 2,
  5361. ProductName: "线上路演",
  5362. }
  5363. videoItem := response.OtherProductTypeListResp{
  5364. ProductId: 1,
  5365. ProductType: 2,
  5366. ProductName: "5分钟小视频",
  5367. }
  5368. if !statisticFlag {
  5369. resp = append(resp, questionItem, roadVideoItem, videoItem)
  5370. }
  5371. voiceSectionList, err := yb.GetAllEnableVoiceSectionList()
  5372. if err != nil {
  5373. br.Msg = "获取数据失败"
  5374. br.ErrMsg = "获取语音播报版块, Err: " + err.Error()
  5375. return
  5376. }
  5377. for _, v := range voiceSectionList {
  5378. resp = append(resp, response.OtherProductTypeListResp{
  5379. ProductId: v.SectionId,
  5380. ProductType: 1,
  5381. ProductName: v.SectionName,
  5382. })
  5383. }
  5384. if statisticFlag {
  5385. resp = append(resp, questionItem, roadVideoItem, videoItem)
  5386. }
  5387. // 全部
  5388. resp = append(resp, response.OtherProductTypeListResp{
  5389. ProductId: 0,
  5390. ProductType: 99,
  5391. ProductName: "全部",
  5392. })
  5393. br.Ret = 200
  5394. br.Success = true
  5395. br.Msg = "获取成功"
  5396. br.Data = resp
  5397. }
  5398. //func init() {
  5399. // BusinessCardUrl := `https://hongze.oss-accelerate.aliyuncs.com/static/images/202107/20210715/R5xT6jw331gPwHZlsIg90cuSbuFW.jpeg`
  5400. // BusinessCardUrl = `https://hongze.oss-accelerate.aliyuncs.com/static/images/202102/20210224/Bdr3Dv8oZDvsAnkzUpx8uA3S4odB.jpg`
  5401. // BusinessCardUrl = `https://hongze.oss-accelerate.aliyuncs.com/static/images/202202/20220215/0glY7kgE07OLBHTnxxwS6u2cAxRx.png`
  5402. // BusinessCardUrl = `https://hongze.oss-accelerate.aliyuncs.com/static/images/202206/20220614/ZHEUpbNtUfE09ZVp6qfQxSPUrLfS.jpg`
  5403. // card, err := services.GetBusinessCard(BusinessCardUrl)
  5404. // if err != nil {
  5405. // fmt.Println("名片识别失败,Err:" + err.Error())
  5406. // return
  5407. // }
  5408. // fmt.Println(card)
  5409. //
  5410. // fmt.Println("company:", card.WordsResult.COMPANY)
  5411. // fmt.Println("===================")
  5412. //
  5413. // {
  5414. // aliyunResult, err := services.AliyunBusinessCardOcr(BusinessCardUrl)
  5415. // if err != nil {
  5416. // fmt.Println("名片识别失败2,Err:" + err.Error())
  5417. // return
  5418. // }
  5419. // fmt.Println(aliyunResult)
  5420. // fmt.Println("company:", aliyunResult.Company)
  5421. // }
  5422. //
  5423. //}
  5424. // @Title 联系人名单匹配导入
  5425. // @Description 联系人名单匹配导入
  5426. // @Param File query file true "文件"
  5427. // @Success 200 {object} company.UserImportMatchResp
  5428. // @router /list/match/import [post]
  5429. func (this *CompanyUserController) ImportListMatch() {
  5430. br := new(models.BaseResponse).Init()
  5431. defer func() {
  5432. this.Data["json"] = br
  5433. this.ServeJSON()
  5434. }()
  5435. sysUser := this.SysUser
  5436. if sysUser == nil {
  5437. br.Msg = "请重新登录"
  5438. return
  5439. }
  5440. file, h, err := this.GetFile("File")
  5441. if err != nil {
  5442. br.Msg = "获取文件失败"
  5443. br.ErrMsg = "获取文件失败,Err:" + err.Error()
  5444. return
  5445. }
  5446. defer func() {
  5447. _ = file.Close()
  5448. }()
  5449. ext := path.Ext(h.Filename)
  5450. if ext != ".xlsx" && ext != ".xls" {
  5451. br.Msg = "请上传Excel文件"
  5452. return
  5453. }
  5454. uploadDir := "static/xls"
  5455. err = os.MkdirAll(uploadDir, 766)
  5456. if err != nil {
  5457. br.Msg = "存储目录创建失败"
  5458. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  5459. return
  5460. }
  5461. uploadPath := uploadDir + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + h.Filename
  5462. err = this.SaveToFile("File", uploadPath)
  5463. if err != nil {
  5464. br.Msg = "文件保存失败"
  5465. br.ErrMsg = "文件保存失败,Err:" + err.Error()
  5466. return
  5467. }
  5468. defer func() {
  5469. _ = os.Remove(uploadPath)
  5470. }()
  5471. xlFile, err := xlsx.OpenFile(uploadPath)
  5472. if err != nil {
  5473. br.Msg = "文件导入失败"
  5474. br.ErrMsg = "文件导入失败,Err:" + err.Error()
  5475. return
  5476. }
  5477. dataList := make([]*company.UserImportMatch, 0)
  5478. mobileArr := make([]string, 0)
  5479. // 遍历sheet页读取
  5480. for _, sheet := range xlFile.Sheets {
  5481. // 遍历行读取
  5482. maxRow := sheet.MaxRow
  5483. for i := 0; i < maxRow; i++ {
  5484. // 首行
  5485. if i == 0 {
  5486. row := sheet.Row(i)
  5487. cells := row.Cells
  5488. for k, cell := range cells {
  5489. text := cell.String()
  5490. if k == 0 {
  5491. if text != "姓名" {
  5492. br.Msg = "匹配失败, 请按模板导入"
  5493. br.ErrMsg = "模板格式错误,title:" + text
  5494. return
  5495. }
  5496. }
  5497. if k == 1 {
  5498. if text != "国际(区号)" {
  5499. br.Msg = "匹配失败, 请按模板导入"
  5500. br.ErrMsg = "模板格式错误,title:" + text
  5501. return
  5502. }
  5503. }
  5504. if k == 2 {
  5505. if text != "手机号" {
  5506. br.Msg = "匹配失败, 请按模板导入"
  5507. br.ErrMsg = "模板格式错误,title:" + text
  5508. return
  5509. }
  5510. }
  5511. if k == 3 {
  5512. if text != "客户公司" {
  5513. br.Msg = "匹配失败, 请按模板导入"
  5514. br.ErrMsg = "模板格式错误,title:" + text
  5515. return
  5516. }
  5517. }
  5518. }
  5519. }
  5520. // 数据行
  5521. if i >= 1 {
  5522. row := sheet.Row(i)
  5523. cells := row.Cells
  5524. var userName, countryCode, mobile, companyName string
  5525. for k, cell := range cells {
  5526. if k == 0 {
  5527. userName = utils.TrimStr(cell.String())
  5528. }
  5529. if k == 1 {
  5530. countryCode = utils.TrimStr(cell.String())
  5531. }
  5532. if k == 2 {
  5533. mobile = utils.TrimStr(cell.String())
  5534. }
  5535. if k == 3 {
  5536. companyName = utils.TrimStr(cell.String())
  5537. }
  5538. }
  5539. // 手机号为空则读取下一行
  5540. if mobile == "" {
  5541. continue
  5542. }
  5543. // mobile列存在"86-11位手机号"这种格式
  5544. if strings.Contains(mobile, "-") {
  5545. mobileArr := strings.Split(mobile, "-")
  5546. if len(mobileArr) == 2 {
  5547. countryCode = mobileArr[0]
  5548. mobile = mobileArr[1]
  5549. }
  5550. }
  5551. mobileArr = append(mobileArr, mobile)
  5552. item := &company.UserImportMatch{
  5553. UserName: userName,
  5554. CountryCode: countryCode,
  5555. Mobile: mobile,
  5556. CompanyName: companyName,
  5557. }
  5558. dataList = append(dataList, item)
  5559. }
  5560. }
  5561. }
  5562. mobileLen := len(mobileArr)
  5563. if mobileLen == 0 {
  5564. br.Msg = "匹配失败, 无有效数据"
  5565. br.ErrMsg = "匹配失败, 无有效数据"
  5566. return
  5567. }
  5568. // 根据手机号查询联系人信息
  5569. var userCond string
  5570. var userPars []interface{}
  5571. userCond += ` AND mobile IN (` + utils.GetOrmInReplace(mobileLen) + `)`
  5572. userPars = append(userPars, mobileArr)
  5573. userList, e := company.GetCompanyUsersByCondition(userCond, userPars)
  5574. if e != nil {
  5575. br.Msg = "匹配失败, 请按模板导入"
  5576. br.ErrMsg = "匹配失败, 获取联系人信息失败, Err: " + e.Error()
  5577. return
  5578. }
  5579. companyIds := make([]int, 0)
  5580. mobileCompanyIdMap := make(map[string]int, 0)
  5581. for i := range userList {
  5582. companyIds = append(companyIds, userList[i].CompanyId)
  5583. mobileCompanyIdMap[userList[i].Mobile] = userList[i].CompanyId
  5584. }
  5585. companyLen := len(companyIds)
  5586. // 查询客户、客户产品
  5587. var productCond string
  5588. var productPars []interface{}
  5589. if companyLen > 0 {
  5590. productCond += ` AND a.company_id IN (` + utils.GetOrmInReplace(companyLen) + `)`
  5591. productPars = append(productPars, companyIds)
  5592. }
  5593. productList, e := company.GetCompanyProductsByCondition(productCond, productPars)
  5594. if e != nil {
  5595. br.Msg = "匹配失败, 请按模板导入"
  5596. br.ErrMsg = "匹配失败, 获取客户产品信息失败, Err: " + e.Error()
  5597. return
  5598. }
  5599. ficcProductMap := make(map[int]*company.CompanyProduct, 0)
  5600. raiProductMap := make(map[int]*company.CompanyProduct, 0)
  5601. for i := range productList {
  5602. if productList[i].ProductId == 1 {
  5603. ficcProductMap[productList[i].CompanyId] = productList[i]
  5604. } else {
  5605. raiProductMap[productList[i].CompanyId] = productList[i]
  5606. }
  5607. }
  5608. // 根据客户信息返回数据
  5609. for i := range dataList {
  5610. companyId := mobileCompanyIdMap[dataList[i].Mobile]
  5611. if companyId == 0 {
  5612. continue
  5613. }
  5614. ficc := ficcProductMap[companyId]
  5615. if ficc != nil {
  5616. dataList[i].SysCompanyName = ficc.CompanyName
  5617. dataList[i].FiccStatus = ficc.Status
  5618. dataList[i].FiccSeller = ficc.SellerName
  5619. }
  5620. rai := raiProductMap[companyId]
  5621. if rai != nil {
  5622. dataList[i].SysCompanyName = rai.CompanyName
  5623. dataList[i].RaiStatus = rai.Status
  5624. dataList[i].RaiSeller = rai.SellerName
  5625. }
  5626. }
  5627. // 缓存导入数据, 导出时用缓存数据生成Excel
  5628. var code, cacheKey string
  5629. dataJson, e := json.Marshal(dataList)
  5630. if e == nil {
  5631. code = fmt.Sprint(time.Now().UnixNano())
  5632. cacheKey = utils.CACHE_KEY_COMPANY_MATCH_PRE + code
  5633. _ = utils.Rc.Put(cacheKey, string(dataJson), time.Minute*30)
  5634. }
  5635. resp := new(company.UserImportMatchResp)
  5636. resp.List = dataList
  5637. resp.Code = code
  5638. br.Data = resp
  5639. br.Msg = "匹配成功"
  5640. br.Ret = 200
  5641. br.Success = true
  5642. }
  5643. // @Title 联系人名单匹配结果下载
  5644. // @Description 联系人名单匹配结果下载
  5645. // @Param Code query string true "导入时返回的Code"
  5646. // @Success 200 Ret=200 匹配成功
  5647. // @router /list/match/download [get]
  5648. func (this *CompanyUserController) ImportListMatchDownload() {
  5649. br := new(models.BaseResponse).Init()
  5650. defer func() {
  5651. this.Data["json"] = br
  5652. this.ServeJSON()
  5653. }()
  5654. sysUser := this.SysUser
  5655. if sysUser == nil {
  5656. br.Msg = "请重新登录"
  5657. return
  5658. }
  5659. code := this.GetString("Code")
  5660. if code == "" {
  5661. br.Msg = "参数有误"
  5662. return
  5663. }
  5664. cacheKey := utils.CACHE_KEY_COMPANY_MATCH_PRE + code
  5665. // 获取导入时的缓存数据
  5666. dataJson, e := utils.Rc.RedisString(cacheKey)
  5667. if e != nil {
  5668. br.Msg = "获取导出数据失败"
  5669. br.ErrMsg = "获取导出数据失败, Err: " + e.Error()
  5670. return
  5671. }
  5672. if dataJson == "" {
  5673. br.Msg = "匹配数据已失效, 请重新匹配"
  5674. return
  5675. }
  5676. dataList := make([]*company.UserImportMatch, 0)
  5677. if e = json.Unmarshal([]byte(dataJson), &dataList); e != nil {
  5678. br.Msg = "匹配数据已失效, 请重新匹配"
  5679. return
  5680. }
  5681. if len(dataList) == 0 {
  5682. br.Msg = "匹配数据已失效, 请重新匹配"
  5683. return
  5684. }
  5685. // 生成Excel表格
  5686. dir, err := os.Executable()
  5687. exPath := filepath.Dir(dir)
  5688. downloadPath := exPath + "/company_match_" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  5689. excelFile := xlsx.NewFile()
  5690. if err != nil {
  5691. br.Msg = "生成文件失败"
  5692. br.ErrMsg = "生成文件失败"
  5693. return
  5694. }
  5695. style := xlsx.NewStyle()
  5696. alignment := xlsx.Alignment{
  5697. Horizontal: "center",
  5698. Vertical: "center",
  5699. WrapText: true,
  5700. }
  5701. style.Alignment = alignment
  5702. style.ApplyAlignment = true
  5703. // 新增Sheet和表头
  5704. sheet, err := excelFile.AddSheet("客户名单")
  5705. if err != nil {
  5706. br.Msg = "新增Sheet失败"
  5707. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  5708. return
  5709. }
  5710. titleRow := sheet.AddRow()
  5711. titleRow.AddCell().SetValue("姓名")
  5712. titleRow.AddCell().SetValue("国际(区号)")
  5713. titleRow.AddCell().SetValue("手机号")
  5714. titleRow.AddCell().SetValue("客户公司")
  5715. titleRow.AddCell().SetValue("系统客户")
  5716. titleRow.AddCell().SetValue("FICC状态")
  5717. titleRow.AddCell().SetValue("FICC销售")
  5718. titleRow.AddCell().SetValue("权益状态")
  5719. titleRow.AddCell().SetValue("权益销售")
  5720. // 表格赋值
  5721. for _, v := range dataList {
  5722. dataRow := sheet.AddRow()
  5723. dataRow.SetHeight(20)
  5724. dataRow.AddCell().SetString(v.UserName)
  5725. dataRow.AddCell().SetString(v.CountryCode)
  5726. dataRow.AddCell().SetString(v.Mobile)
  5727. dataRow.AddCell().SetString(v.CompanyName)
  5728. dataRow.AddCell().SetString(v.SysCompanyName)
  5729. dataRow.AddCell().SetString(v.FiccStatus)
  5730. dataRow.AddCell().SetString(v.FiccSeller)
  5731. dataRow.AddCell().SetString(v.RaiStatus)
  5732. dataRow.AddCell().SetString(v.RaiSeller)
  5733. }
  5734. // 输出Excel
  5735. if e = excelFile.Save(downloadPath); e != nil {
  5736. br.Msg = "保存文件失败"
  5737. br.ErrMsg = "保存文件失败"
  5738. return
  5739. }
  5740. defer func() {
  5741. _ = os.Remove(downloadPath)
  5742. }()
  5743. suffix := time.Now().Format(utils.FormatDateTimeUnSpace)
  5744. downloadFileName := "客户名单匹配_" + suffix + ".xlsx"
  5745. this.Ctx.Output.Download(downloadPath, downloadFileName)
  5746. br.Msg = "导出成功"
  5747. br.Ret = 200
  5748. br.Success = true
  5749. }
  5750. // Follow
  5751. // @Title 关注联系人
  5752. // @Description 关注联系人
  5753. // @Param request body request.ApplyMarkReq true "type json string"
  5754. // @Success 200 {object} 标记处理成功
  5755. // @router /follow [post]
  5756. func (this *CompanyUserController) Follow() {
  5757. br := new(models.BaseResponse).Init()
  5758. defer func() {
  5759. this.Data["json"] = br
  5760. this.ServeJSON()
  5761. }()
  5762. sysUser := this.SysUser
  5763. if sysUser == nil {
  5764. br.Msg = "请登录"
  5765. br.ErrMsg = "请登录,SysUser is Empty"
  5766. br.Ret = 408
  5767. return
  5768. }
  5769. var req request.FollowReq
  5770. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5771. if err != nil {
  5772. br.Msg = "参数解析异常"
  5773. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5774. return
  5775. }
  5776. if req.UserId <= 0 {
  5777. br.Msg = "用户ID异常"
  5778. br.ErrMsg = "用户ID异常"
  5779. return
  5780. }
  5781. // 查公司里有多少已关注,上限三个
  5782. count, err := models.GetCompanyFollowCount(req.CompanyId)
  5783. if err != nil {
  5784. br.Msg = "操作失败! "
  5785. br.ErrMsg = "操作失败,Err:" + err.Error()
  5786. return
  5787. }
  5788. if count == 3 && req.Type == 1 {
  5789. br.Msg = "关注失败,特别关注已达上限(上限三个)"
  5790. br.ErrMsg = "关注失败,特别关注已达上限(上限三个)"
  5791. return
  5792. }
  5793. // 关注或取关
  5794. err = models.SetUserFollow(req.UserId, req.Type)
  5795. if err != nil {
  5796. br.Msg = "操作失败! "
  5797. br.ErrMsg = "操作失败,Err:" + err.Error()
  5798. return
  5799. }
  5800. br.Ret = 200
  5801. br.Success = true
  5802. br.Msg = "操作成功"
  5803. }
  5804. // @Title 开通或者关闭用户研选权限
  5805. // @Description 开通或者关闭用户研选权限
  5806. // @Param request body request.ApplyMarkReq true "type json string"
  5807. // @Success 200 {object} 操作成功
  5808. // @router /update/user/yananxuan/permission [post]
  5809. func (this *CompanyUserController) UpadteUserYanxuanPermission() {
  5810. br := new(models.BaseResponse).Init()
  5811. defer func() {
  5812. this.Data["json"] = br
  5813. this.ServeJSON()
  5814. }()
  5815. sysUser := this.SysUser
  5816. if sysUser == nil {
  5817. br.Msg = "请登录"
  5818. br.ErrMsg = "请登录,SysUser is Empty"
  5819. br.Ret = 408
  5820. return
  5821. }
  5822. var req cygx.UpdateUserYanxuanPermissionReq
  5823. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5824. if err != nil {
  5825. br.Msg = "参数解析异常"
  5826. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5827. return
  5828. }
  5829. userId := req.UserId
  5830. if userId <= 0 {
  5831. br.Msg = "用户ID异常"
  5832. br.ErrMsg = "用户ID异常"
  5833. return
  5834. }
  5835. //获取联系人详情
  5836. userInfo, err := models.GetWxUserByUserId(req.UserId)
  5837. if err != nil {
  5838. br.Msg = "获取联系人异常!"
  5839. br.ErrMsg = "获取联系人异常,Err:" + err.Error()
  5840. return
  5841. }
  5842. if userInfo.BusinessCardUrl == "" {
  5843. br.Msg = "该联系人尚未添加名片,请点击编辑,上传名片后再开通试用"
  5844. return
  5845. }
  5846. companyInfo, err := company.GetCompanyById(userInfo.CompanyId)
  5847. if err != nil {
  5848. br.Msg = "查找客户失败"
  5849. br.ErrMsg = "查找客户失败,err:" + err.Error()
  5850. return
  5851. }
  5852. // 查询用户是否开通过
  5853. count, err := cygx.GetCygxUserYanxuanPermissionCountByUserId(userId)
  5854. if err != nil {
  5855. br.Msg = "操作失败! "
  5856. br.ErrMsg = "操作失败,Err:" + err.Error()
  5857. return
  5858. }
  5859. item := new(cygx.CygxUserYanxuanPermission)
  5860. if req.Type == 0 {
  5861. item.Status = "未开通"
  5862. } else {
  5863. item.Status = "试用"
  5864. }
  5865. item.UserId = userId
  5866. item.CompanyId = companyInfo.CompanyId
  5867. item.CompanyName = companyInfo.CompanyName
  5868. item.StartDate = time.Now().Format(utils.FormatDate)
  5869. item.EndDate = time.Now().AddDate(0, 2, 0).Format(utils.FormatDate) // 试用期两个月
  5870. item.Mobile = userInfo.Mobile
  5871. item.Email = userInfo.Email
  5872. item.RealName = userInfo.RealName
  5873. item.AdminId = sysUser.AdminId
  5874. item.AdminRealName = sysUser.RealName
  5875. item.CreatedTime = time.Now()
  5876. item.LastUpdatedTime = time.Now()
  5877. item.ModifyTime = time.Now()
  5878. if count == 0 {
  5879. _, err = cygx.AddCygxUserYanxuanPermission(item) // 添加
  5880. } else {
  5881. if req.Type == 0 {
  5882. err = cygx.UpdateCygxUserYanxuanPermissionClose(userId) // 关闭
  5883. } else {
  5884. err = cygx.UpdateCygxUserYanxuanPermissionOpen(item) // 开通
  5885. }
  5886. }
  5887. if err != nil {
  5888. br.Msg = "操作失败! "
  5889. br.ErrMsg = "操作失败,Err:" + err.Error()
  5890. return
  5891. }
  5892. go cygxService.AddCygxUserYanxuanPermissionLog(item)
  5893. br.Ret = 200
  5894. br.Success = true
  5895. br.Msg = "操作成功"
  5896. }
  5897. // ListByReport
  5898. // @Title 联系人列表
  5899. // @Description 联系人列表接口
  5900. // @Param PageSize query int true "每页数据条数"
  5901. // @Param CurrentIndex query int true "当前页页码,从1开始"
  5902. // @Param CompanyId query int true "公司id,必填"
  5903. // @Param SortParam query int false "排序字段:1-点击量;2-点击时间"
  5904. // @Param SortType query int false "排序方式:1-倒序;2-正序"
  5905. // @Success 200 {object} company.CompanyUserListResp
  5906. // @router /user/listByReport [get]
  5907. func (this *CompanyUserController) ListByReport() {
  5908. br := new(models.BaseResponse).Init()
  5909. defer func() {
  5910. this.Data["json"] = br
  5911. this.ServeJSON()
  5912. }()
  5913. sysUser := this.SysUser
  5914. if sysUser == nil {
  5915. br.Msg = "请登录"
  5916. br.ErrMsg = "请登录,SysUser Is Empty"
  5917. br.Ret = 408
  5918. return
  5919. }
  5920. pageSize, _ := this.GetInt("PageSize")
  5921. currentIndex, _ := this.GetInt("CurrentIndex")
  5922. companyId, _ := this.GetInt("CompanyId")
  5923. sortParam, _ := this.GetInt("SortParam", 2)
  5924. sortType, _ := this.GetInt("SortType", 1)
  5925. if companyId <= 0 {
  5926. br.Msg = "请选择客户"
  5927. br.ErrMsg = "客户参数错误"
  5928. return
  5929. }
  5930. var startSize int
  5931. if pageSize <= 0 {
  5932. pageSize = utils.PageSize20
  5933. }
  5934. if currentIndex <= 0 {
  5935. currentIndex = 1
  5936. }
  5937. startSize = paging.StartIndex(currentIndex, pageSize)
  5938. var order string
  5939. sortArr := []int{1, 2}
  5940. if utils.InArrayByInt(sortArr, sortParam) && utils.InArrayByInt(sortArr, sortType) {
  5941. pMap := map[int]string{1: "ficc_view_total", 2: "ficc_last_view_time"}
  5942. tMap := map[int]string{1: "DESC", 2: "ASC"}
  5943. order = fmt.Sprintf(` ORDER BY %s %s`, pMap[sortParam], tMap[sortType])
  5944. }
  5945. total, err := company.GetCompanyUserListByReportCount(companyId)
  5946. if err != nil {
  5947. br.Msg = "获取失败"
  5948. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  5949. return
  5950. }
  5951. list, err := company.GetCompanyUserListByReport(companyId, startSize, pageSize, order)
  5952. if err != nil {
  5953. br.Msg = "获取失败"
  5954. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  5955. return
  5956. }
  5957. respList := make([]*company.CompanyViewResp, 0)
  5958. for i := range list {
  5959. v := &company.CompanyViewResp{
  5960. UserId: int(list[i].UserId),
  5961. UserName: list[i].RealName,
  5962. Mobile: list[i].Mobile,
  5963. Email: list[i].Email,
  5964. ViewTotal: list[i].FiccViewTotal,
  5965. LastViewTime: list[i].FiccLastViewTime.Format(utils.FormatDateTime),
  5966. }
  5967. if v.LastViewTime == "0001-01-01 00:00:00" {
  5968. v.LastViewTime = ""
  5969. }
  5970. respList = append(respList, v)
  5971. }
  5972. page := paging.GetPaging(currentIndex, pageSize, total)
  5973. resp := &company.CompanyViewPageListResp{
  5974. Paging: page,
  5975. List: respList,
  5976. }
  5977. br.Ret = 200
  5978. br.Success = true
  5979. br.Msg = "获取成功"
  5980. br.Data = resp
  5981. }
  5982. // listMoveLog
  5983. // @Title 联系人移动记录列表
  5984. // @Description 联系人移动记录列表接口
  5985. // @Param Mobile query string true "手机号"
  5986. // @Success 200 {object} company.CompanyUserListResp
  5987. // @router /user/listMoveLog [get]
  5988. func (this *CompanyUserController) ListMoveLog() {
  5989. br := new(models.BaseResponse).Init()
  5990. defer func() {
  5991. this.Data["json"] = br
  5992. this.ServeJSON()
  5993. }()
  5994. sysUser := this.SysUser
  5995. if sysUser == nil {
  5996. br.Msg = "请登录"
  5997. br.ErrMsg = "请登录,SysUser Is Empty"
  5998. br.Ret = 408
  5999. return
  6000. }
  6001. mobile := this.GetString("Mobile")
  6002. if mobile == "" {
  6003. br.Msg = "手机号不能为空"
  6004. return
  6005. }
  6006. list, err := company.GetWxUserMoveLogListmByMobile(mobile)
  6007. if err != nil {
  6008. br.Msg = "获取失败"
  6009. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  6010. return
  6011. }
  6012. respList := make([]*company.WxUserMoveLogResp, 0)
  6013. for _, v := range list {
  6014. item := new(company.WxUserMoveLogResp)
  6015. item.UserName = v.RealName
  6016. item.Mobile = v.Mobile
  6017. item.Email = v.Email
  6018. item.CompanyId = v.CompanyId
  6019. item.CompanyName = v.CompanyName
  6020. item.CompanyIdMove = v.CompanyIdMove
  6021. item.CompanyNameMove = v.CompanyNameMove
  6022. item.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
  6023. respList = append(respList, item)
  6024. }
  6025. resp := &company.WxUserMoveLogListResp{
  6026. List: respList,
  6027. }
  6028. br.Ret = 200
  6029. br.Success = true
  6030. br.Msg = "获取成功"
  6031. br.Data = resp
  6032. }