company_user.go 206 KB

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