company_user.go 205 KB

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