company_user.go 205 KB

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