company_user.go 207 KB

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