12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521 |
- package controllers
- import (
- "encoding/json"
- "errors"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "github.com/tealeg/xlsx"
- "hongze/hz_crm_api/models"
- "hongze/hz_crm_api/models/advisory"
- "hongze/hz_crm_api/models/company"
- "hongze/hz_crm_api/models/company_user"
- "hongze/hz_crm_api/models/company_user/request"
- "hongze/hz_crm_api/models/company_user/response"
- "hongze/hz_crm_api/models/cygx"
- "hongze/hz_crm_api/models/system"
- "hongze/hz_crm_api/models/yb"
- "hongze/hz_crm_api/services"
- cygxService "hongze/hz_crm_api/services/cygx"
- "hongze/hz_crm_api/services/elastic"
- "hongze/hz_crm_api/utils"
- "os"
- "path"
- "path/filepath"
- "strconv"
- "strings"
- "time"
- "unicode/utf8"
- )
- // 客户联系人管理
- type CompanyUserController struct {
- BaseAuthController
- }
- // @Title 新增客户联系人
- // @Description 新增客户联系人接口
- // @Param request body company.AddUserReq true "type json string"
- // @router /user/add [post]
- func (this *CompanyUserController) AddUser() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req company.AddUserReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.RealName == "" {
- br.Msg = "请填写姓名"
- br.IsSendEmail = false
- return
- }
- //空格移除
- req.MobileOne = utils.TrimStr(req.MobileOne)
- req.MobileTwo = utils.TrimStr(req.MobileTwo)
- req.Email = utils.TrimStr(req.Email)
- req.RealName = utils.TrimStr(req.RealName)
- //判断该手机号、邮箱是否已经添加,如果已经添加,那么就不再添加
- var key string
- if req.MobileOne != "" {
- key = "wx_user:mobile:" + req.MobileOne
- } else {
- key = "wx_user:email:" + req.Email
- }
- isHas := utils.Rc.IsExist(key)
- if isHas == true {
- br.Msg = "重复添加"
- return
- } else {
- //设置3分钟缓存,不允许重复添加
- utils.Rc.SetNX(key, 1, time.Second*300)
- //添加完成删除对应的缓存
- defer utils.Rc.Delete(key)
- }
- source := req.Source
- if source == "" {
- br.Msg = "没有来源"
- return
- }
- regionType := req.RegionType //区域来源
- productId := services.GetProductId(sysUser.RoleTypeCode)
- //操作员的产品权限
- companyProductList := make([]*company.CompanyProduct, 0)
- var companyInfo *company.Company
- var e error
- if req.CompanyId > 0 {
- companyInfo, e = company.GetCompanyById(req.CompanyId)
- if e != nil {
- br.Msg = "客户信息有误"
- br.ErrMsg = "获取客户信息失败, Err: " + e.Error()
- return
- }
- }
- //权益类客户,邮箱必填(2021-03-22 13:32:59修改)
- if productId == 1 || regionType == "国内" { //ficc类客户
- if req.MobileOne == "" && req.Email == "" {
- br.Msg = "请输入手机号或邮箱"
- br.IsSendEmail = false
- return
- }
- } else if productId == 2 { //权益类客户
- if req.MobileOne == "" {
- br.Msg = "请输入手机号"
- br.ErrMsg = "请输入手机号"
- br.IsSendEmail = false
- return
- }
- if req.Email == "" {
- br.Msg = "请输入邮箱"
- br.ErrMsg = "请输入邮箱"
- br.IsSendEmail = false
- return
- }
- } else {
- //如果是管理员账户,那么需要从企业信息里面去获取所属类型客户了
- //获取企业客户信息
- if req.Source == "add_custom" {
- //添加客户时新增联系人
- } else if req.Source == "pick_custom" {
- //领取客户时添加联系人
- br.ErrMsg = "管理员账户不允许领取客户"
- br.Msg = "来源异常"
- return
- } else if req.Source == "add_user" {
- //普通类型添加客户
- //companyInfo, err := company.GetCompanyById(req.CompanyId)
- //if err != nil {
- // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- // br.Msg = "获取客户信息失败"
- // return
- //}
- //手机号、邮箱校验(必填一个)
- if req.MobileOne == "" && req.Email == "" {
- br.Msg = "请输入手机号或邮箱"
- br.IsSendEmail = false
- return
- }
- //shareSellerId = companyInfo.ShareSellerId
- //获取当前操作员产品权限
- tmpCompanyProductList, productErr := getSysCompanyProductList(productId, req.CompanyId)
- if productErr != nil {
- br.Msg = "新增失败"
- br.ErrMsg = "新增失败,获取当前操作员产品权限异常,Err:" + productErr.Error()
- return
- }
- if tmpCompanyProductList == nil {
- br.Msg = "新增失败"
- br.ErrMsg = "新增失败,获取当前操作员找不到产品权限"
- return
- }
- for _, v := range tmpCompanyProductList {
- //权益(海外)客户,需要有提示
- if v.ProductId == 2 && companyInfo.RegionType == "海外" {
- if req.MobileOne == "" {
- br.Msg = "请输入手机号"
- }
- if req.Email == "" {
- br.Msg = "请输入邮箱"
- br.ErrMsg = "请输入邮箱"
- return
- }
- }
- }
- companyProductList = tmpCompanyProductList
- } else {
- br.ErrMsg = "来源异常"
- br.Msg = "来源异常"
- return
- }
- }
- if productId != 0 {
- if req.Source == "add_custom" {
- //添加客户时新增联系人
- } else if req.Source == "pick_custom" {
- //领取客户时添加联系人
- tmpCompanyProduct := &company.CompanyProduct{
- CompanyId: req.CompanyId,
- ProductId: productId,
- ProductName: sysUser.RoleName,
- SellerId: sysUser.AdminId,
- SellerName: sysUser.RealName,
- GroupId: sysUser.GroupId,
- DepartmentId: sysUser.DepartmentId,
- }
- companyProductList = append(companyProductList, tmpCompanyProduct)
- } else if req.Source == "add_user" {
- shareSellerId := 0
- if req.CompanyId > 0 {
- item, e := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
- if e != nil {
- br.Msg = "客户信息有误"
- br.ErrMsg = "获取客户信息失败, Err: " + e.Error()
- return
- }
- shareSellerId = item.ShareSellerId
- }
- //获取当前操作员产品权限
- tmpCompanyProductList, productErr := getSysCompanyProductList(productId, req.CompanyId)
- if productErr != nil {
- br.Msg = "新增失败"
- br.ErrMsg = "新增失败,获取当前操作员产品权限异常,Err:" + productErr.Error()
- return
- }
- if tmpCompanyProductList == nil {
- br.Msg = "新增失败"
- br.ErrMsg = "新增失败,获取当前操作员找不到产品权限"
- return
- }
- companyProductList = tmpCompanyProductList
- //操作权限校验
- for _, v := range tmpCompanyProductList {
- companyUserStatus := services.CheckCompanyUserButton(sysUser.RoleTypeCode, v.SellerId, sysUser.AdminId, v.ProductId, shareSellerId, v.Status)
- if companyUserStatus == false {
- br.Msg = "没有操作权限"
- br.ErrMsg = "没有操作权限"
- br.IsSendEmail = false
- return
- }
- }
- }
- } else {
- //超管
- if req.Source != "add_custom" {
- //不是添加客户的时候添加的联系人
- tmpCompanyProductList, productErr := getSysCompanyProductList(productId, req.CompanyId)
- if productErr != nil {
- br.Msg = "新增失败"
- br.ErrMsg = "新增失败,获取当前操作员产品权限异常,Err:" + productErr.Error()
- return
- }
- if tmpCompanyProductList == nil {
- br.Msg = "新增失败"
- br.ErrMsg = "新增失败,获取当前操作员找不到产品权限"
- return
- }
- companyProductList = tmpCompanyProductList
- }
- }
- userCount, err := company.GetCompanyUserCount(req.CompanyId)
- if err != nil {
- br.Msg = "新增失败"
- br.ErrMsg = "判断联系人数量失败,Err:" + err.Error()
- return
- }
- if userCount == 0 {
- if req.BusinessCardUrl == "" {
- br.Msg = "请上传名片"
- br.IsSendEmail = false
- return
- }
- }
- //systemUser models.Company.CompanyUser
- //var sysemUser company.CompanyUser
- //校验主手机号
- if req.MobileOne != "" {
- mobileOneItem, err := company.GetUserCountByMobile(req.MobileOne)
- if err != nil && err.Error() == utils.ErrNoRow() {
- mobileOneItem, err = company.CheckCompanyUserCountByMobileTwo(req.MobileOne)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "新增失败"
- br.ErrMsg = "判断手机号1是否存在,Err:" + err.Error()
- return
- }
- }
- if mobileOneItem != nil {
- if mobileOneItem.UserId > 0 {
- //如果有传入客户编号,且客户编号与该查出来的用户编号一致的情况下
- if req.CompanyId > 0 {
- //获取联系人分组信息
- userSellerGroupInfo, err := models.GetUserGroupSellerByUserId(int(mobileOneItem.UserId))
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "查询信息异常"
- br.Success = true
- br.Data = mobileOneItem
- br.IsSendEmail = false
- br.Ret = 600
- return
- }
- if req.CompanyId == mobileOneItem.CompanyId {
- //如果是该客户下的用户,那么判断该用户与当前账号是否存在关系,如果没有关系,那么直接添加关系后直接返回
- if len(companyProductList) > 0 {
- isHas := checkUserSellerRelation(companyProductList, mobileOneItem, &req, br)
- if isHas == false {
- return
- }
- }
- //修改返回给前端用户的信息
- if userSellerGroupInfo != nil {
- mobileOneItem.SellerRealName = userSellerGroupInfo.SellerRealName
- mobileOneItem.Status = userSellerGroupInfo.Status
- }
- br.Msg = "手机号1已存在"
- br.Success = true
- br.Data = mobileOneItem
- br.IsSendEmail = false
- br.Ret = 600
- return
- } else {
- hasMove := true //是否可移动
- //如果是大于 1 的客户,那么就是非潜在客户,需要去查询对应的销售
- if mobileOneItem.CompanyId > 1 {
- //获取联系人分组信息
- userSellerGroupInfoList, err := models.GetUserGroupSellersByUserId(int(mobileOneItem.UserId))
- //根据分组校验
- if err == nil && len(userSellerGroupInfoList) > 0 {
- sellerMap := make(map[int]string) //销售信息map
- sellerNameSlice := make([]string, 0) //销售姓名切片
- statusNameSlice := make([]string, 0) //客户状态姓名切片
- for _, v := range userSellerGroupInfoList {
- if v.Status != utils.COMPANY_STATUS_LOSE && v.Status != utils.COMPANY_STATUS_FOREVER && hasMove == true {
- hasMove = false
- }
- statusNameSlice = append(statusNameSlice, v.Status)
- if _, ok := sellerMap[v.SellerId]; ok {
- continue
- }
- sellerMap[v.SellerId] = v.SellerRealName
- sellerNameSlice = append(sellerNameSlice, v.SellerRealName)
- }
- mobileOneItem.SellerRealName = strings.Join(sellerNameSlice, "/")
- mobileOneItem.Status = strings.Join(statusNameSlice, "/")
- }
- }
- //是否可移动
- mobileOneItem.HasMove = hasMove
- br.Msg = "手机号1已存在"
- br.Success = true
- br.Data = mobileOneItem
- br.IsSendEmail = false
- br.Ret = 600
- return
- }
- } else {
- if strings.Contains(mobileOneItem.Status, "/") {
- if strings.Contains(mobileOneItem.Status, "正式") || strings.Contains(mobileOneItem.Status, "试用") {
- mobileOneItem.HasMove = false
- } else {
- mobileOneItem.HasMove = true
- }
- } else {
- if mobileOneItem.Status == utils.COMPANY_STATUS_FREEZE || //冻结
- mobileOneItem.Status == utils.COMPANY_STATUS_LOSE || //流失
- mobileOneItem.Status == utils.COMPANY_STATUS_POTENTIAL || //潜在
- mobileOneItem.Status == utils.COMPANY_STATUS_FOREVER { //永续
- mobileOneItem.HasMove = true
- }
- }
- br.Msg = "手机号1已存在"
- br.Success = true
- br.Data = mobileOneItem
- br.IsSendEmail = false
- br.Ret = 600
- return
- }
- }
- }
- }
- if req.Email != "" {
- emailItem, err := company.CheckCompanyUserCountByEmail(req.Email)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "新增失败"
- br.ErrMsg = "新增失败,Err:" + err.Error()
- return
- }
- if emailItem != nil {
- if emailItem.UserId > 0 {
- if req.CompanyId > 0 {
- //获取联系人分组信息
- userSellerGroupInfo, err := models.GetUserGroupSellerByUserId(int(emailItem.UserId))
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "查询信息异常"
- br.Success = true
- br.Data = emailItem
- br.IsSendEmail = false
- br.Ret = 600
- return
- }
- if req.CompanyId == emailItem.CompanyId {
- //如果是该客户下的用户,那么判断该用户与当前账号是否存在关系,如果没有关系,那么直接添加关系后直接返回
- if len(companyProductList) > 0 {
- isHas := checkUserSellerRelation(companyProductList, emailItem, &req, br)
- if isHas == false {
- return
- }
- }
- //修改返回给前端用户的信息
- if userSellerGroupInfo != nil {
- emailItem.SellerRealName = userSellerGroupInfo.SellerRealName
- emailItem.Status = userSellerGroupInfo.Status
- }
- br.Msg = "邮箱已存在"
- br.Success = true
- br.Data = emailItem
- br.IsSendEmail = false
- br.Ret = 600
- return
- } else {
- hasMove := true //是否可移动
- //如果是大于 1 的客户,那么就是非潜在客户,需要去查询对应的销售
- if emailItem.CompanyId > 1 {
- //获取联系人分组信息
- userSellerGroupInfoList, err := models.GetUserGroupSellersByUserId(int(emailItem.UserId))
- //根据分组校验
- if err == nil && len(userSellerGroupInfoList) > 0 {
- sellerMap := make(map[int]string) //销售信息map
- sellerNameSlice := make([]string, 0) //销售姓名切片
- statusNameSlice := make([]string, 0) //客户状态姓名切片
- for _, v := range userSellerGroupInfoList {
- if v.Status != utils.COMPANY_STATUS_LOSE && v.Status != utils.COMPANY_STATUS_FOREVER && hasMove == true {
- hasMove = false
- }
- statusNameSlice = append(statusNameSlice, v.Status)
- if _, ok := sellerMap[v.SellerId]; ok {
- continue
- }
- sellerMap[v.SellerId] = v.SellerRealName
- sellerNameSlice = append(sellerNameSlice, v.SellerRealName)
- }
- emailItem.SellerRealName = strings.Join(sellerNameSlice, "/")
- emailItem.Status = strings.Join(statusNameSlice, "/")
- }
- }
- //是否可移动
- emailItem.HasMove = hasMove
- br.Msg = "邮箱已存在"
- br.Success = true
- br.Data = emailItem
- br.IsSendEmail = false
- br.Ret = 600
- return
- }
- } else {
- if strings.Contains(emailItem.Status, "/") {
- if strings.Contains(emailItem.Status, "正式") || strings.Contains(emailItem.Status, "试用") {
- emailItem.HasMove = false
- } else {
- emailItem.HasMove = true
- }
- } else {
- if emailItem.Status == utils.COMPANY_STATUS_FREEZE || //冻结
- emailItem.Status == utils.COMPANY_STATUS_LOSE || //流失
- emailItem.Status == utils.COMPANY_STATUS_POTENTIAL || //潜在
- emailItem.Status == utils.COMPANY_STATUS_FOREVER { //永续
- emailItem.HasMove = true
- }
- }
- br.Msg = "邮箱已存在"
- br.Success = true
- br.Data = emailItem
- br.IsSendEmail = false
- br.Ret = 600
- return
- }
- }
- }
- }
- //if req.BusinessCardUrl != "" && utils.RunMode == "release" {
- if req.BusinessCardUrl != "" {
- // 获取图片识别客户名称的配置
- crmConfig, err := company.GetConfigDetailByCode("card_recognition_company_name")
- if err != nil {
- br.Msg = "获取配置失败"
- br.ErrMsg = "获取配置失败"
- br.IsSendEmail = false
- return
- }
- // 获取图片识别手机号的配置
- crmConfig2, err := company.GetConfigDetailByCode("card_recognition_tel")
- if err != nil {
- br.Msg = "获取配置失败"
- br.ErrMsg = "获取配置失败"
- br.IsSendEmail = false
- return
- }
- if crmConfig.ConfigValue == "true" || crmConfig2.ConfigValue == "true" {
- companyName := req.CompanyName
- if companyName == "" {
- companyInfo, err := company.GetCompanyById(req.CompanyId)
- if err != nil {
- br.Msg = "查找客户失败"
- br.ErrMsg = "查找客户失败,err:" + err.Error()
- return
- }
- companyName = companyInfo.CompanyName
- }
- companyName = utils.TrimStr(companyName)
- tmpCompanyNameList, err := elastic.Analyze(companyName)
- if err != nil {
- br.Msg = "添加失败"
- br.ErrMsg = "客户名称分词失败,Err:" + err.Error()
- return
- }
- //公司名称切片
- analyzeNameList := []string{companyName}
- for _, v := range tmpCompanyNameList {
- if v == "" {
- continue
- }
- ignoreStrs := []string{"", "有限", "投资", "资本", "管理", "贸易", "资产", "公司", "股份", "集团", "有限公司"}
- if !strings.Contains(strings.Join(ignoreStrs, ","), v) && utf8.RuneCount([]byte(v)) > 1 {
- //不在上面的过滤字里面,且切出来的字符大于1位
- analyzeNameList = append(analyzeNameList, v)
- }
- }
- //名片识别出来的客户名称切片
- companyNameSlice := make([]string, 0)
- card, err := services.GetBusinessCard(req.BusinessCardUrl)
- if err != nil {
- br.Msg = "名片识别失败"
- br.ErrMsg = "名片识别失败,Err:" + err.Error()
- return
- }
- //if card.Errno != 0 {
- // br.Msg = "您上传了非名片图片,请重新上传"
- // br.ErrMsg = "名片识别失败,ErrMsg:" + card.ErrorMsg + ";errCode:" + strconv.Itoa(card.Errno)
- // return
- //}
- //var mobileStr string
- //for _, v := range card.WordsResult {
- // mobileStr += v.Words + ","
- //}
- isFlag := false
- if len(card.WordsResult.MOBILE) > 0 {
- mobileStr := strings.Join(card.WordsResult.MOBILE, ",")
- //if req.MobileOne != "" {
- // if strings.Contains(mobileStr, req.MobileOne) || mobileStr == "" {
- // isFlag = true
- // } else {
- // isFlag = false
- // }
- //}
- //
- //if isFlag == false && req.MobileTwo != "" {
- // if strings.Contains(mobileStr, req.MobileTwo) {
- // isFlag = true
- // } else {
- // isFlag = false
- // }
- //}
- if req.MobileOne != "" && strings.Contains(mobileStr, req.MobileOne) {
- isFlag = true
- }
- if req.MobileTwo != "" && strings.Contains(mobileStr, req.MobileTwo) {
- isFlag = true
- }
- //如果百度识别出来了客户名称,那么将识别出来的客户名称添加到待校验客户名称切片中
- if len(card.WordsResult.COMPANY) > 0 && card.WordsResult.COMPANY[0] != "" {
- companyNameSlice = card.WordsResult.COMPANY
- }
- }
- //如果百度未识别出来手机号或者公司名称,那么进行阿里识别
- if !isFlag || (len(companyNameSlice) == 0 && crmConfig.ConfigValue == "true") {
- //阿里云识别
- aliyunResult, errMsg, err := services.AliyunOcrBusinessCard(req.BusinessCardUrl)
- if err != nil {
- br.Msg = "识别失败"
- br.ErrMsg = "识别失败,Err:" + err.Error()
- return
- }
- if !aliyunResult.Success {
- br.Msg = "识别失败"
- br.ErrMsg = "识别失败"
- return
- }
- if errMsg != "" {
- br.Msg = errMsg
- return
- }
- //如果百度没有识别出来手机号,那么还需要阿里识别出来的手机号校验下
- if !isFlag {
- if len(aliyunResult.TelCell) > 0 {
- mobileStr := strings.Join(aliyunResult.TelCell, ",")
- if req.MobileOne != "" {
- if strings.Contains(mobileStr, req.MobileOne) {
- isFlag = true
- } else {
- isFlag = false
- }
- }
- } else {
- isFlag = true
- }
- }
- //如果阿里云识别出来了客户名称,那么将识别出来的客户名称添加到待校验客户名称切片中
- if len(aliyunResult.Company) > 0 {
- companyNameSlice = append(companyNameSlice, aliyunResult.Company...)
- }
- }
- if !isFlag && crmConfig2.ConfigValue == "true" {
- br.Msg = "名片信息与联系人手机号不符"
- br.IsSendEmail = false
- return
- }
- //校验识别出来的名片名称与传入的客户名称是否一致
- if len(companyNameSlice) > 0 && crmConfig.ConfigValue == "true" {
- isCompanyNameFlag := false //是否成功匹配客户名称
- //遍历识别出来的客户名称,然后与系统的客户名称做匹配(识别出来的名称包含系统名称的话,那么标记成功匹配)
- for _, tmpCompanyName := range companyNameSlice {
- //空串不处理
- if companyName == "" {
- continue
- }
- for _, analyzeName := range analyzeNameList {
- //如果分词出来的公司名称正好在识别出来的公司名称里面,那么就认为校验通过了
- if strings.Contains(tmpCompanyName, analyzeName) {
- isCompanyNameFlag = true
- break
- }
- }
- if isCompanyNameFlag {
- break
- }
- }
- //如果没有匹配到客户名称,那么就返回报错
- if !isCompanyNameFlag {
- br.Msg = "名片信息与公司名称不符"
- br.IsSendEmail = false
- return
- }
- }
- }
- }
- user := new(models.WxUser)
- user.RealName = utils.TrimStr(req.RealName)
- user.Sex = req.Sex
- user.CountryCode = utils.TrimStr(req.CountryCode)
- user.Mobile = utils.TrimStr(req.MobileOne)
- user.OutboundCountryCode = utils.TrimStr(req.CountryCode)
- user.OutboundMobile = utils.TrimStr(req.MobileOne)
- user.MobileTwo = utils.TrimStr(req.MobileTwo)
- user.Email = utils.TrimStr(req.Email)
- user.Position = req.Position
- user.IsMaker = req.IsMaker
- user.BusinessCardUrl = req.BusinessCardUrl
- user.CompanyId = req.CompanyId
- if req.CompanyId == 0 {
- user.CompanyId = 1
- }
- user.DepartmentName = req.DepartmentName
- user.CreatedTime = time.Now()
- //user.RegisterTime = time.Now()
- user.RegisterPlatform = 3
- newId, err := models.AddWxUser(user)
- user.UserId = newId
- if err != nil {
- br.Msg = "新增失败"
- br.ErrMsg = "新增失败,Err:" + err.Error()
- return
- }
- //如果有传入企业编号,那么需要将该联系人与销售员做绑定
- if len(companyProductList) > 0 {
- for _, companyProduct := range companyProductList {
- models.AddUserSellerRelation(newId, companyProduct.CompanyId, companyProduct.SellerId, companyProduct.ProductId, companyProduct.SellerName, req.MobileOne, req.Email)
- }
- }
- //更新客户最近阅读次数以及最近阅读时间
- go services.ModifyCompanyProductLastViewData([]int{req.CompanyId})
- //联系人信息
- userInfo, _ := json.Marshal(user)
- go services.AddWxUserOpLog(company.WxUserOpLog{
- LogType: "add",
- UserId: int(user.UserId),
- CompanyId: user.CompanyId,
- Mobile: user.Mobile,
- Email: user.Email,
- OriginalUserInfo: "",
- UserInfo: string(userInfo),
- OriginalUserSellerInfo: "",
- UserSellerInfo: "",
- OpUserId: sysUser.AdminId,
- OpUserName: sysUser.RealName,
- CreateTime: time.Now(),
- })
- br.Ret = 200
- br.Success = true
- br.Msg = "新增成功"
- br.Data = newId
- br.IsAddLog = true
- }
- // 获取当前操作员产品权限(所有产品数据)
- func getSysCompanyProductList(productId, companyId int) (companyProduct []*company.CompanyProduct, err error) {
- if productId == 0 {
- tmpCompanyProduct, productErr := company.GetCompanyProductByCompanyIdAndProductId(companyId, 1)
- if productErr != nil && productErr.Error() != utils.ErrNoRow() {
- //sql异常
- err = productErr
- return
- }
- if tmpCompanyProduct != nil {
- companyProduct = append(companyProduct, tmpCompanyProduct)
- }
- tmpCompanyProduct, productErr = company.GetCompanyProductByCompanyIdAndProductId(companyId, 2)
- if productErr != nil && productErr.Error() != utils.ErrNoRow() {
- //sql异常
- err = productErr
- return
- }
- if tmpCompanyProduct != nil {
- companyProduct = append(companyProduct, tmpCompanyProduct)
- }
- } else {
- tmpCompanyProduct, productErr := company.GetCompanyProductByCompanyIdAndProductId(companyId, productId)
- if productErr != nil && productErr.Error() != utils.ErrNoRow() {
- //sql异常
- err = productErr
- return
- }
- if tmpCompanyProduct != nil {
- companyProduct = append(companyProduct, tmpCompanyProduct)
- }
- }
- return
- }
- // 校验用户与销售信息
- func checkUserSellerRelation(companyProductList []*company.CompanyProduct, companyUser *company.CompanyUser, req *company.AddUserReq, br *models.BaseResponse) (isHas bool) {
- for _, companyProduct := range companyProductList {
- _, relationErr := models.GetUserSellerRelation(companyUser.UserId, companyProduct.SellerId)
- //找到数据了
- if relationErr == nil {
- isHas = true
- continue
- }
- //没找到数据,不存在关系
- //如果不存在关系,那么直接添加关系就好了,其他操作不做
- if relationErr.Error() == utils.ErrNoRow() {
- //添加用户与联系人的关系
- models.AddUserSellerRelation(companyUser.UserId, companyProduct.CompanyId, companyProduct.SellerId, companyProduct.ProductId, companyProduct.SellerName, companyUser.Mobile, companyUser.Email)
- } else {
- //sql异常
- br.Msg = "新增失败"
- br.ErrMsg = "判断手机号或邮箱是否存在关联关系,Err:" + relationErr.Error()
- return
- }
- //对老数据做字段数据新增处理,如果该字段已有数据则不做处理start
- {
- mobileOne := companyUser.Mobile
- mobileTwo := companyUser.MobileTwo
- email := companyUser.Email
- businessCardUrl := companyUser.BusinessCardUrl
- if req.MobileOne != "" && companyUser.Mobile == "" {
- mobileOne = utils.TrimStr(req.MobileOne)
- }
- if req.MobileTwo != "" && companyUser.MobileTwo == "" {
- mobileTwo = utils.TrimStr(req.MobileTwo)
- }
- if req.Email != "" && companyUser.Email == "" {
- email = utils.TrimStr(req.Email)
- }
- if req.BusinessCardUrl != "" && companyUser.BusinessCardUrl == "" {
- businessCardUrl = strings.Replace(req.BusinessCardUrl, " ", "", -1)
- }
- _ = company.EditCompanyUserContact(companyUser.UserId, mobileOne, mobileTwo, email, businessCardUrl)
- }
- //对老数据做字段数据新增处理,如果该字段已有数据则不做处理start
- br.Ret = 200
- br.Success = true
- br.Msg = "新增成功"
- br.Data = companyUser.UserId
- return
- }
- return
- }
- // List
- // @Title 联系人列表
- // @Description 联系人列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param CompanyId query int true "公司id,必填"
- // @Param KeyWord query string true "搜索关键词"
- // @Param ProductType query int true "产品类型"
- // @Param ProductId query int true "产品id"
- // @Param IsSubscribe query int true "是否关注了公众号: -1-默认全部; 0-未关注; 1-已关注"
- // @Param IsSubscribeHzyj query int true "是否关注了弘则研究公众号: -1-默认全部; 0-未关注; 1-已关注"
- // @Param IsSubscribeCygx query int true "是否关注了查研观向小助手公众号: -1-默认全部; 0-未关注; 1-已关注"
- // @Success 200 {object} company.CompanyUserListResp
- // @router /user/list [get]
- func (this *CompanyUserController) List() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- companyId, _ := this.GetInt("CompanyId")
- keyWord := utils.TrimStr(this.GetString("KeyWord"))
- productType, _ := this.GetInt("ProductType")
- ybProductId, _ := this.GetInt("ProductId")
- isSubscribe, _ := this.GetInt("IsSubscribe", -1)
- isSubscribeHzyj, _ := this.GetInt("IsSubscribeHzyj", -1)
- isSubscribeCygx, _ := this.GetInt("IsSubscribeCygx", -1)
- // 默认是问答社区
- if productType <= 0 {
- productType = 3
- }
- if companyId <= 0 {
- br.Msg = "请选择客户"
- br.ErrMsg = "客户参数错误"
- return
- }
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- if keyWord != "" {
- condition += ` AND (a.real_name LIKE '%` + keyWord + `%' OR a.mobile LIKE '%` + keyWord + `%' OR a.email LIKE '%` + keyWord + `%') `
- }
- // 是否关注公众号
- if isSubscribe == 0 {
- condition += ` AND (c.subscribe = 0 OR ISNULL(c.subscribe)) `
- }
- if isSubscribe == 1 {
- condition += ` AND c.subscribe = 1 `
- }
- // 是否关注弘则研究公众号
- if isSubscribeHzyj == 0 {
- condition += ` AND (c.subscribe = 0 OR ISNULL(c.subscribe)) `
- }
- if isSubscribeHzyj == 1 {
- condition += ` AND c.subscribe = 1 `
- }
- // 是否关注弘则研究公众号
- if isSubscribeCygx == 0 {
- condition += ` AND (a.cygx_subscribe = 0 OR ISNULL(a.cygx_subscribe)) `
- }
- if isSubscribeCygx == 1 {
- condition += ` AND a.cygx_subscribe = 1 `
- }
- //非管理员,那么只能看到该产品下的联系人
- if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
- productId := services.GetProductId(sysUser.RoleTypeCode)
- condition += ` AND b.product_id = ? `
- pars = append(pars, productId)
- //流失客户(除非是超级管理员或者是部门管理员,要不然不允许看对应的联系人)
- //var companyProduct *company.CompanyProduct
- //当前是ficc权限,且非ficc管理员
- //if productId == 1 && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_FICC_ADMIN {
- // tmpCompanyProduct, _ := company.GetCompanyProductByCompanyIdAndProductId(companyId, 1)
- // companyProduct = tmpCompanyProduct
- //}
- //权益销售查看流失客户时,可以看到非本人名下流失客户的联系人需求池 930 2024-03-25
- //if productId == 2 && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_ADMIN {
- // // 当前是权益权限,且非 权益管理员
- // tmpCompanyProduct, _ := company.GetCompanyProductByCompanyIdAndProductId(companyId, 2)
- // companyProduct = tmpCompanyProduct
- // if companyProduct != nil && companyProduct.Status == utils.COMPANY_STATUS_LOSE {
- // condition += ` AND seller_id=? `
- // pars = append(pars, sysUser.AdminId)
- // }
- //}
- }
- total, err := company.GetCompanyUserListCountV2(condition, pars, companyId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
- return
- }
- list, err := company.GetCompanyUserListV2(condition, pars, companyId, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- //获取企业客户信息
- companyInfo, err := company.GetCompanyById(companyId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- lenList := len(list)
- if lenList > 0 {
- userIdSlice := make([]string, 0)
- mobilesSlice := make([]string, 0)
- emailsSlice := make([]string, 0)
- userIds := make([]int, 0)
- for _, v := range list {
- userIdSlice = append(userIdSlice, strconv.Itoa(int(v.UserId)))
- userIds = append(userIds, int(v.UserId))
- if v.Mobile != "" {
- mobilesSlice = append(mobilesSlice, v.Mobile)
- } else if v.Email != "" {
- emailsSlice = append(emailsSlice, v.Email)
- }
- }
- //用户浏览数据
- userIdStr := strings.Join(userIdSlice, ",")
- mobileStr := strings.Join(mobilesSlice, "','")
- mobileStr = "'" + mobileStr + "'"
- emailStr := strings.Join(emailsSlice, "','")
- emailStr = "'" + emailStr + "'"
- //userViewTotalList, _ := models.GetCountUserViewHistoryByUserIds(userIdStr)
- //userViewTotalMap := make(map[int]*models.UserViewTotalSlice)
- //for _, userView := range userViewTotalList {
- // userViewTotalMap[userView.UserId] = userView
- //}
- //用户日评浏览数据
- //userReportViewTotalList, _ := models.GetReportViewMaxTimeByUserIds(userIdStr)
- //userReportViewTotalMap := make(map[int]*models.ReportViewRecord)
- //for _, userReportView := range userReportViewTotalList {
- // userReportViewTotalMap[userReportView.UserId] = userReportView
- //}
- //报告统计删除晨报部分统计加入每日资讯 2021-4-9
- ////手机号
- //userViewMobileTotalMap := make(map[string]*models.UserViewMobileTotalSlice)
- //userReportViewMobileTotalMap := make(map[string]*models.ReportViewMobileRecord)
- //userAdvisoryViewMobileTotalMap := make(map[string]*advisory.UserViewMobileTotalSlice)
- //userCygxArticleHistoryRecordViewMobileTotalMap := make(map[string]*models.UserViewMobileTotalSlice)
- //if len(mobilesSlice) > 0 {
- // //用户浏览数据
- // userViewMobileTotalList, _ := models.GetCountUserViewHistoryByMobiles(mobileStr)
- // for _, userViewMobile := range userViewMobileTotalList {
- // userViewMobileTotalMap[userViewMobile.Mobile] = userViewMobile
- // }
- //
- // //每日点评手机号数据
- // userReportViewMobileTotalList, _ := models.GetReportViewMaxTimeByMobiles(mobileStr)
- // for _, userReportViewMobile := range userReportViewMobileTotalList {
- // userReportViewMobileTotalMap[userReportViewMobile.Mobile] = userReportViewMobile
- // }
- //
- // //每日资讯
- // userAdvisoryViewMobileTotalList, _ := advisory.GetCountUserViewHistoryByMobiles(mobileStr)
- // //fmt.Println(userAdvisoryViewMobileTotalList)
- // for _, userAdvisoryViewMobile := range userAdvisoryViewMobileTotalList {
- // userAdvisoryViewMobileTotalMap[userAdvisoryViewMobile.Mobile] = userAdvisoryViewMobile
- // }
- // //查研观向
- // userCygxArticleHistoryRecordViewMobileTotalList, _ := models.GetCountCygxArticleHistoryRecordByMobiles(mobileStr)
- // for _, userCygxArticleHistoryRecordViewMobile := range userCygxArticleHistoryRecordViewMobileTotalList {
- // userCygxArticleHistoryRecordViewMobileTotalMap[userCygxArticleHistoryRecordViewMobile.Mobile] = userCygxArticleHistoryRecordViewMobile
- // }
- //}
- ////邮箱
- //userViewEmailTotalMap := make(map[string]*models.UserViewEmailTotalSlice)
- //userReportViewEmailTotalMap := make(map[string]*models.ReportViewEmailRecord)
- //userAdvisoryViewEmailTotalMap := make(map[string]*advisory.UserViewEmailTotalSlice)
- //userCygxViewEmailTotalMap := make(map[string]*models.UserViewEmailTotalSlice)
- //if len(emailsSlice) > 0 {
- // //用户浏览数据
- // userViewEmailTotalList, _ := models.GetCountUserViewHistoryByEmails(emailStr)
- // for _, userViewEmail := range userViewEmailTotalList {
- // userViewEmailTotalMap[userViewEmail.Email] = userViewEmail
- // }
- // //每日点评手机号数据
- // userReportViewEmailTotalList, _ := models.GetReportViewMaxTimeByEmails(emailStr)
- // for _, userReportViewEmail := range userReportViewEmailTotalList {
- // userReportViewEmailTotalMap[userReportViewEmail.Email] = userReportViewEmail
- // }
- // //每日资讯
- // userAdvisoryViewEmailTotalList, _ := advisory.GetCountUserViewHistoryByEmails(emailStr)
- // for _, userAdvisoryViewEmail := range userAdvisoryViewEmailTotalList {
- // userAdvisoryViewEmailTotalMap[userAdvisoryViewEmail.Email] = userAdvisoryViewEmail
- // }
- // //查研观向
- // userCygxViewEmailTotalList, _ := models.GetCountCygxArticleHistoryRecordByEmails(emailStr)
- // for _, userCygxReportViewEmail := range userCygxViewEmailTotalList {
- // userCygxViewEmailTotalMap[userCygxReportViewEmail.Email] = userCygxReportViewEmail
- // }
- //}
- //获取联系人关联产品的条数
- userSellerRelationTotalSlice, err := models.GetUserSellerRelationCountByUserIds(userIdStr)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取联系人与销售员信息失败,Err:" + err.Error()
- return
- }
- userSellerRelationTotalMap := make(map[int]*models.UserSellerRelationSlice)
- for _, userSellerRelationTotal := range userSellerRelationTotalSlice {
- userSellerRelationTotalMap[userSellerRelationTotal.UserId] = userSellerRelationTotal
- }
- userRecordRegisterMap := make(map[int]time.Time)
- if len(userIdSlice) > 0 {
- //用户绑定注册数据
- userRecordRegisterList, _ := models.GetUserRecordRegisterByUserIds(userIdStr)
- for _, userRecordRegister := range userRecordRegisterList {
- userRecordRegisterMap[userRecordRegister.UserId] = userRecordRegister.CreateTime
- }
- }
- // 用户图表权限设置信息
- userChartPermissionMap := make(map[int]*company_user.ChartClassifyPermission)
- userChartPermissionList, err := company_user.GetChartClassifyPermissionListByUserIds(userIdStr)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取联系人图表权限信息失败, Err:" + err.Error()
- return
- }
- for i := 0; i < len(userChartPermissionList); i++ {
- userChartPermissionMap[userChartPermissionList[i].UserId] = userChartPermissionList[i]
- }
- // 获取admin列表-匹配联系人是否为admin用户
- sysUserList, err := system.GetAdminList()
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取admin列表失败, Err:" + err.Error()
- return
- }
- sysUserMobileMap := make(map[string]int, 0)
- for i := 0; i < len(sysUserList); i++ {
- sysUserMobile := sysUserList[i].Mobile
- if sysUserMobile != "" {
- sysUserMobileMap[sysUserList[i].Mobile] = 1
- }
- }
- // 获取研报分产品统计
- //ybViewsList, e := yb.GetCompanyUserYbProductVisitCount(userIds)
- ybViewsList, e := yb.GetCompanyUserYbProductVisitCountByProductType(userIds, productType, ybProductId)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取分产品阅读统计失败, Err:" + e.Error()
- return
- }
- userYbViewsMap := make(map[int]int)
- for _, v := range ybViewsList {
- userYbViewsMap[v.UserId] = v.VisitCount
- }
- userHaveMoveMap := services.GetWxUserHaveMoveMap(mobilesSlice) // 处理用户是否移动过按钮回显
- for i := 0; i < lenList; i++ {
- item := list[i]
- //企业名称
- list[i].CompanyName = companyInfo.CompanyName
- if item.OpenId != "" {
- list[i].IsRegister = true
- } else {
- if item.RegisterPlatform == 2 {
- if item.Mobile != "" || item.Email != "" {
- list[i].IsRegister = true
- }
- } else if item.RegisterTime != "" {
- list[i].IsRegister = true
- } else {
- list[i].IsRegister = false
- }
- }
- ////手机号用户累计浏览次数
- //if userView, ok := userViewMobileTotalMap[item.Mobile]; ok {
- // list[i].ViewTotal += userView.Total
- // if userView.CreatedTime.After(list[i].LastViewTime) {
- // list[i].LastViewTime = userView.CreatedTime
- // list[i].LastViewTimeStr = userView.CreatedTime.Format(utils.FormatDateTime)
- // }
- //}
- ////邮箱用户累计浏览次数
- //if userView, ok := userViewEmailTotalMap[item.Email]; ok {
- // //总共浏览的报表数据需要调整为(手机号用户浏览晨报数+邮箱号用户浏览晨报数)
- // list[i].ViewTotal += userView.Total
- // if userView.CreatedTime.After(list[i].LastViewTime) {
- // list[i].LastViewTime = userView.CreatedTime
- // list[i].LastViewTimeStr = userView.CreatedTime.Format(utils.FormatDateTime)
- // }
- //}
- ////如果存在手机号用户日评数据,那么需要做处理
- //if reportView, ok := userReportViewMobileTotalMap[item.Mobile]; ok {
- // //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
- // if reportView.LastViewTime.After(list[i].LastViewTime) {
- // list[i].LastViewTime = reportView.LastViewTime
- // list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
- // }
- // //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
- // list[i].ViewTotal += reportView.ViewTotal
- //}
- ////如果存在手机号用户日评数据,那么需要做处理
- //if reportView, ok := userReportViewEmailTotalMap[item.Email]; ok {
- // //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
- // if reportView.LastViewTime.After(list[i].LastViewTime) {
- // list[i].LastViewTime = reportView.LastViewTime
- // list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
- // }
- // //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
- // list[i].ViewTotal += reportView.ViewTotal
- //}
- //
- ////如果存在手机号用户每日资讯,那么需要做处理
- //if advisoryView, ok := userAdvisoryViewMobileTotalMap[item.Mobile]; ok {
- // //fmt.Println("蝴蝶眨几次眼睛")
- // //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
- // if advisoryView.CreatedTime.After(list[i].LastViewTime) {
- // list[i].LastViewTime = advisoryView.CreatedTime
- // list[i].LastViewTimeStr = advisoryView.CreatedTime.Format(utils.FormatDateTime)
- // }
- // //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数)
- // list[i].ViewTotal += advisoryView.Total
- //}
- ////如果存在邮箱号用户每日资讯,那么需要做处理
- //if advisoryView, ok := userAdvisoryViewEmailTotalMap[item.Email]; ok {
- // //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
- // if advisoryView.CreatedTime.After(list[i].LastViewTime) {
- // list[i].LastViewTime = advisoryView.CreatedTime
- // list[i].LastViewTimeStr = advisoryView.CreatedTime.Format(utils.FormatDateTime)
- // }
- // //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数)
- // list[i].ViewTotal += advisoryView.Total
- //}
- //
- ////如果存在手机号用户查研观向,那么需要做处理
- //if cygxView, ok := userCygxArticleHistoryRecordViewMobileTotalMap[item.Mobile]; ok {
- // //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
- // if cygxView.CreatedTime.After(list[i].LastViewTime) {
- // list[i].LastViewTime = cygxView.CreatedTime
- // list[i].LastViewTimeStr = cygxView.CreatedTime.Format(utils.FormatDateTime)
- // }
- // //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数+查研观向)
- // list[i].ViewTotal += cygxView.Total
- //}
- ////如果存在邮箱号用户查研观向,那么需要做处理
- //if cygxView, ok := userCygxViewEmailTotalMap[item.Email]; ok {
- // //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
- // if cygxView.CreatedTime.After(list[i].LastViewTime) {
- // list[i].LastViewTime = cygxView.CreatedTime
- // list[i].LastViewTimeStr = cygxView.CreatedTime.Format(utils.FormatDateTime)
- // }
- // //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数+查研观向)
- // list[i].ViewTotal += cygxView.Total
- //}
- ///*if reportView, ok := userReportViewTotalMap[int(item.UserId)]; ok {
- // //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
- // if reportView.LastViewTime.After(list[i].LastViewTime) {
- // list[i].LastViewTime = reportView.LastViewTime
- // list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
- // }
- // //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
- // list[i].ViewTotal += reportView.ViewTotal
- //}*/
- list[i].ViewTotal = list[i].FiccViewTotal + list[i].RaiViewTotal
- var tmpLastViewTime time.Time
- tmpLastViewTime = list[i].FiccLastViewTime
- if !list[i].RaiLastViewTime.IsZero() {
- if tmpLastViewTime.IsZero() || list[i].RaiLastViewTime.After(tmpLastViewTime) {
- tmpLastViewTime = list[i].RaiLastViewTime
- }
- }
- list[i].LastViewTime = tmpLastViewTime
- if !tmpLastViewTime.IsZero() {
- list[i].LastViewTimeStr = tmpLastViewTime.Format(utils.FormatDateTime)
- }
- if list[i].LastViewTime.Before(time.Now().AddDate(0, 0, -7)) && list[i].IsFollow == 1 {
- list[i].NotRead = true
- }
- //如果有绑定数据,那么将数据返回对应的注册绑定数据
- if _, ok := userRecordRegisterMap[int(item.UserId)]; ok {
- list[i].IsRegister = true
- //list[i].RegisterTime = userRecordRegisterTime.Format(utils.FormatDateTime)
- }
- //是否共享联系人
- if userSellerRelationTotal, ok := userSellerRelationTotalMap[int(item.UserId)]; ok {
- //条数大于1,代表这是共享联系人
- //if userSellerRelationTotal.Total > 1 {
- // list[i].IsShared = true
- //}
- list[i].ProductIds = userSellerRelationTotal.ProductIds
- }
- // 图表权限
- if _, isAdmin := sysUserMobileMap[list[i].Mobile]; isAdmin {
- list[i].IsChartPermissionSetting = 2
- } else {
- if _, ok := userChartPermissionMap[int(item.UserId)]; ok {
- list[i].IsChartPermissionSetting = 1
- }
- }
- // 分产品阅读统计
- list[i].YbProductViewTotal = userYbViewsMap[int(item.UserId)]
- //list[i].LastViewTimeStr = list[i].RaiLastViewTime.Format(utils.FormatDateTime)
- if item.Mobile != "" {
- list[i].HaveMoveButton = userHaveMoveMap[item.Mobile]
- }
- }
- isUserYanXuanButtonShow, err := services.CheckCompanyUserYanXuanButton(sysUser.RoleTypeCode, sysUser.Mobile)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败 CheckCompanyUserYanXuanButton ,Err:" + err.Error()
- return
- }
- if isUserYanXuanButtonShow {
- userYanxuanPermissionMap := cygxService.GetCygxUserYanxuanPermissionMapItem(userIds) // 如果是权益部门下的人,则展示研选相关的信息
- userInteractionNumMap := cygxService.GetUserInteractionNumMap(userIds) // 如果是权益部门下的人,展示互动量相关的信息
- mfyxuserRecordRegisterMap := make(map[int]string)
- mfyxuserRecordRegisterTimeMap := make(map[int]time.Time)
- if len(userIdSlice) > 0 {
- //用户查研观向网页版注册时间
- clptuserRecordRegisterList, err := cygx.GetCygxClptSessionrByUserIdsMyfx(userIdStr)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,GetCygxClptSessionrByUserIdsMyfx Err:" + err.Error()
- return
- }
- for _, userRecordRegister := range clptuserRecordRegisterList {
- mfyxuserRecordRegisterTimeMap[userRecordRegister.UserId] = userRecordRegister.CreateTime
- mfyxuserRecordRegisterMap[userRecordRegister.UserId] = userRecordRegister.CreateTime.Format(utils.FormatDateTime)
- }
- //买方研选网页版注册时间
- mfyxwebRecordRegisterList, err := cygx.GetCygxMfyxWebSessionByUserIdsMyfx(userIdStr)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,GetCygxMfyxWebSessionByUserIdsMyfx Err:" + err.Error()
- return
- }
- for _, userRecordRegister := range mfyxwebRecordRegisterList {
- //如果注册时间早于查研观向网页版的,或者没有注册,就用这里的时间替换
- if userRecordRegister.CreateTime.Before(mfyxuserRecordRegisterTimeMap[userRecordRegister.UserId]) || mfyxuserRecordRegisterMap[userRecordRegister.UserId] == "" {
- mfyxuserRecordRegisterTimeMap[userRecordRegister.UserId] = userRecordRegister.CreateTime
- mfyxuserRecordRegisterMap[userRecordRegister.UserId] = userRecordRegister.CreateTime.Format(utils.FormatDateTime)
- }
- }
- mfyxuserRecordRegisterList, err := models.GetUserRecordRegisterByUserIdsMyfx(userIdStr)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败 GetUserRecordRegisterByUserIdsMyfx ,Err:" + err.Error()
- return
- }
- for _, userRecordRegister := range mfyxuserRecordRegisterList {
- //如果注册时间早于网页版的,或者网页版没有注册,就用这里的时间替换
- if userRecordRegister.CreateTime.Before(mfyxuserRecordRegisterTimeMap[userRecordRegister.UserId]) || mfyxuserRecordRegisterMap[userRecordRegister.UserId] == "" {
- mfyxuserRecordRegisterMap[userRecordRegister.UserId] = userRecordRegister.CreateTime.Format(utils.FormatDateTime)
- }
- }
- }
- for i := 0; i < lenList; i++ {
- item := list[i]
- // 分产品阅读统计
- //list[i].YbProductViewTotal = userYbViewsMap[int(item.UserId)]
- list[i].MfyxInteractionNum = userInteractionNumMap[int(item.UserId)]
- //权益销售查看用户研选的信息
- if userYanxuanPermissionMap[int(item.UserId)] != nil {
- mfyxItem := userYanxuanPermissionMap[int(item.UserId)]
- list[i].MfyxStatus = mfyxItem.Status
- list[i].MfyxStartDate = mfyxItem.StartDate
- list[i].MfyxEndDate = mfyxItem.EndDate
- } else {
- list[i].MfyxStatus = "未开通"
- }
- if mfyxuserRecordRegisterMap[int(item.UserId)] != "" {
- list[i].MfyxIsBinding = true
- list[i].MfyxBindingTime = mfyxuserRecordRegisterMap[int(item.UserId)]
- }
- //list[i].LastViewTimeStr = list[i].RaiLastViewTime.Format(utils.FormatDateTime)
- }
- }
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(company.CompanyUserListResp)
- resp.List = list
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- func (this *CompanyUserController) List2() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- companyId, _ := this.GetInt("CompanyId")
- keyWord := this.GetString("KeyWord")
- if companyId <= 0 {
- br.Msg = "请选择客户"
- br.ErrMsg = "客户参数错误"
- return
- }
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- if keyWord != "" {
- condition += ` AND (a.real_name LIKE '%` + keyWord + `%' OR a.mobile LIKE '%` + keyWord + `%' OR a.email LIKE '%` + keyWord + `%') `
- }
- total, err := company.GetCompanyUserListCount(condition, pars, companyId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
- return
- }
- list, err := company.GetCompanyUserList(condition, pars, companyId, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- lenList := len(list)
- for i := 0; i < lenList; i++ {
- item := list[i]
- if item.OpenId != "" {
- list[i].IsRegister = true
- } else {
- if item.RegisterPlatform == 2 {
- if item.Mobile != "" || item.Email != "" {
- list[i].IsRegister = true
- }
- } else {
- list[i].IsRegister = false
- }
- }
- reportView, err := models.GetReportViewMaxTime(int(item.UserId))
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取GetReportViewMaxTime失败,Err:" + err.Error()
- return
- }
- if reportView.LastViewTime.After(list[i].LastViewTime) {
- list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
- } else {
- list[i].LastViewTimeStr = list[i].LastViewTime.Format(utils.FormatDateTime)
- }
- list[i].ViewTotal += reportView.ViewTotal
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(company.CompanyUserListResp)
- resp.List = list
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 获取客户名下联系人数量(根据当前账号角色区分)
- // @Description 获取客户名下联系人数量(根据当前账号角色区分)接口
- // @Param CompanyId query int true "客户id"
- // @Param ProductId query int true "产品权限id"
- // @Success 200 {object} company.CompanyUserTotal
- // @router /company_user/total [get]
- func (this *CompanyUserController) GetUserCountByCompanyId() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- companyId, _ := this.GetInt("CompanyId")
- if companyId <= 0 {
- br.Msg = "参数错误"
- return
- }
- productId, _ := this.GetInt("ProductId")
- //如果没有传入,那么去根据权限来获取id
- if productId <= 0 {
- productId = services.GetProductId(sysUser.RoleTypeCode)
- }
- total, err := services.GetUserCountByCompanyId(companyId, productId)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取联系人总数失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = company.CompanyUserTotal{
- Total: total,
- }
- }
- // @Title 删除客户联系人
- // @Description 删除客户联系人接口
- // @Param request body company.DeleteUserReq true "type json string"
- // @router /user/delete [post]
- func (this *CompanyUserController) DeleteUser() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req company.DeleteUserReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.UserId <= 0 {
- br.Msg = "参数错误!"
- return
- }
- //获取联系人详情
- userInfo, err := models.GetWxUserByUserId(req.UserId)
- if err != nil {
- br.Msg = "获取联系人异常!"
- br.ErrMsg = "获取联系人异常,Err:" + err.Error()
- return
- }
- //产品权限
- productId := services.GetProductId(sysUser.RoleTypeCode)
- //操作权限校验
- errMsg, err := checkOpCompanyUserByUserId(req.UserId, productId, sysUser.AdminId, sysUser.RoleTypeCode)
- if err != nil {
- br.Msg = "删除失败!" + errMsg
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- userRelationList := make([]*models.UserSellerRelation, 0)
- //如果不是超管权限,那么删除的时候,需要获取下联系人归属销售信息
- if productId != 0 {
- tmpUserRelationList, err := models.GetUserSellerRelationList(req.UserId)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
- return
- }
- if len(tmpUserRelationList) > 0 {
- userRelationList = append(userRelationList, tmpUserRelationList...)
- }
- }
- //联系人与销售的关系
- userSellerRelationList, err := models.GetUserSellerRelationList(int(userInfo.UserId))
- if err != nil {
- return
- }
- userSellerRelationInfo, _ := json.Marshal(userSellerRelationList)
- //删除所有的标识,并真正删除数据
- _ = models.DeleteUserSellerRelationByProductId(req.UserId, 1)
- _ = models.DeleteUserSellerRelationByProductId(req.UserId, 2)
- //真正删除用户
- err = services.DeleteWxUser(req.UserId)
- if err != nil {
- br.Msg = "删除失败!"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- if len(userRelationList) > 0 {
- companyInfo, err := company.GetCompanyById(userRelationList[0].CompanyId)
- if err != nil {
- return
- }
- content := fmt.Sprint("联系人:", userInfo.RealName, "被删除")
- if companyInfo != nil {
- content = fmt.Sprint(companyInfo.CompanyName, ":", content)
- }
- for _, userRelation := range userRelationList {
- if userRelation.ProductId != productId {
- go services.AddCompanyMessage(sysUser.AdminId, userRelation.SellerId, userRelation.CompanyId, 0, 1, companyInfo.CompanyName, content, content)
- }
- }
- }
- //更新客户最近阅读次数以及最近阅读时间
- go services.ModifyCompanyProductLastViewData([]int{userInfo.CompanyId})
- //联系人信息
- originalUserInfo, _ := json.Marshal(userInfo)
- go services.AddWxUserOpLog(company.WxUserOpLog{
- LogType: "delete",
- UserId: int(userInfo.UserId),
- CompanyId: userInfo.CompanyId,
- Mobile: userInfo.Mobile,
- Email: userInfo.Email,
- OriginalUserInfo: string(originalUserInfo),
- UserInfo: "",
- OriginalUserSellerInfo: string(userSellerRelationInfo),
- UserSellerInfo: "",
- OpUserId: sysUser.AdminId,
- OpUserName: sysUser.RealName,
- CreateTime: time.Now(),
- })
- // 若该联系人为弘则研究公司下的,则同步禁用手机号关联的系统管理员
- if userInfo.CompanyId == 16 {
- go services.ForbiddenSysUserByMobile(userInfo.Mobile)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "删除成功"
- br.IsAddLog = true
- }
- // @Title 编辑客户联系人
- // @Description 编辑客户联系人接口
- // @Param request body company.EditUserReq true "type json string"
- // @router /user/edit [post]
- func (this *CompanyUserController) EditUser() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req company.EditUserReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.UserId <= 0 {
- br.Msg = "参数错误!"
- return
- }
- //移除空格
- req.MobileOne = utils.TrimStr(req.MobileOne)
- req.MobileTwo = utils.TrimStr(req.MobileTwo)
- req.Email = utils.TrimStr(req.Email)
- req.RealName = utils.TrimStr(req.RealName)
- productId := services.GetProductId(sysUser.RoleTypeCode)
- //操作权限校验
- wxUser, err := models.GetWxUserByUserId(req.UserId)
- if err != nil {
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- br.Msg = "获取信息失败"
- return
- }
- //获取当前操作员产品权限
- companyProductList, productErr := getSysCompanyProductList(productId, wxUser.CompanyId)
- if productErr != nil {
- br.Msg = "编辑失败!获取当前操作员产品权限异常"
- br.ErrMsg = "获取当前操作员产品权限异常,Err:" + productErr.Error()
- return
- }
- if companyProductList == nil {
- br.Msg = "编辑失败!获取当前操作员找不到产品权限"
- br.ErrMsg = "获取当前操作员找不到产品权限"
- return
- }
- //操作权限校验
- for _, v := range companyProductList {
- companyUserStatus := services.CheckCompanyUserButton(sysUser.RoleTypeCode, v.SellerId, sysUser.AdminId, v.ProductId, v.ShareSellerId, v.Status)
- if v.ShareSellerId == sysUser.AdminId {
- companyUserStatus = true
- }
- if companyUserStatus == false {
- br.Msg = "没有操作权限"
- br.ErrMsg = "没有操作权限"
- return
- }
- }
- if req.RealName == "" {
- br.Msg = "请填写姓名"
- return
- }
- oldWxUser := *wxUser //旧的联系人信息(赋值,而不是赋址)
- if req.MobileOne == "" && req.Email == "" {
- br.Msg = "请输入手机号或邮箱"
- return
- }
- //不是管理员的情况下://手机号邮箱填写校验
- if productId != 0 {
- companyInfo, err := company.GetCompanyById(req.CompanyId)
- if err != nil {
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- br.Msg = "获取客户信息失败"
- return
- }
- for _, v := range companyProductList {
- //权益(海外)客户,需要有提示
- if v.ProductId == 2 && companyInfo.RegionType == "海外" {
- if req.MobileOne == "" {
- br.Msg = "请输入手机号"
- }
- if req.Email == "" {
- br.Msg = "请输入邮箱"
- br.ErrMsg = "请输入邮箱"
- return
- }
- }
- }
- }
- if req.MobileOne != "" && req.MobileOne != wxUser.Mobile {
- mobileOneItem, err := company.GetUserCountByMobile(req.MobileOne)
- if err != nil && err.Error() == utils.ErrNoRow() {
- mobileOneItem, err = company.CheckCompanyUserCountByMobileTwo(req.MobileOne)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "编辑失败"
- br.ErrMsg = "判断手机号是否存在,Err:" + err.Error()
- return
- }
- }
- if mobileOneItem != nil {
- if mobileOneItem.UserId > 0 {
- if req.CompanyId > 0 {
- //获取联系人分组信息
- userSellerGroupInfo, err := models.GetUserGroupSellerByUserId(int(mobileOneItem.UserId))
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "查询信息异常"
- br.Success = true
- br.Data = mobileOneItem
- br.IsSendEmail = false
- br.Ret = 600
- return
- }
- if req.CompanyId == mobileOneItem.CompanyId {
- //修改返回给前端用户的信息
- if userSellerGroupInfo != nil {
- mobileOneItem.SellerRealName = userSellerGroupInfo.SellerRealName
- mobileOneItem.Status = userSellerGroupInfo.Status
- }
- br.Msg = "手机号1已存在"
- br.Success = true
- br.Data = mobileOneItem
- br.IsSendEmail = false
- br.Ret = 600
- return
- } else {
- hasMove := true //是否可移动
- //如果是大于 1 的客户,那么就是非潜在客户,需要去查询对应的销售
- if mobileOneItem.CompanyId > 1 {
- //获取联系人分组信息
- userSellerGroupInfoList, err := models.GetUserGroupSellersByUserId(int(mobileOneItem.UserId))
- //根据分组校验
- if err == nil && len(userSellerGroupInfoList) > 0 {
- sellerMap := make(map[int]string) //销售信息map
- sellerNameSlice := make([]string, 0) //销售姓名切片
- statusNameSlice := make([]string, 0) //客户状态姓名切片
- for _, v := range userSellerGroupInfoList {
- if v.Status != utils.COMPANY_STATUS_LOSE && v.Status != utils.COMPANY_STATUS_FOREVER && hasMove == true {
- hasMove = false
- }
- statusNameSlice = append(statusNameSlice, v.Status)
- if _, ok := sellerMap[v.SellerId]; ok {
- continue
- }
- sellerMap[v.SellerId] = v.SellerRealName
- sellerNameSlice = append(sellerNameSlice, v.SellerRealName)
- }
- mobileOneItem.SellerRealName = strings.Join(sellerNameSlice, "/")
- mobileOneItem.Status = strings.Join(statusNameSlice, "/")
- }
- }
- //是否可移动
- mobileOneItem.HasMove = hasMove
- br.Msg = "手机号1已存在"
- br.Success = true
- br.Data = mobileOneItem
- br.IsSendEmail = false
- br.Ret = 600
- return
- }
- } else {
- if strings.Contains(mobileOneItem.Status, "/") {
- if strings.Contains(mobileOneItem.Status, "正式") || strings.Contains(mobileOneItem.Status, "试用") {
- mobileOneItem.HasMove = false
- } else {
- mobileOneItem.HasMove = true
- }
- } else {
- if mobileOneItem.Status == utils.COMPANY_STATUS_FREEZE || //冻结
- mobileOneItem.Status == utils.COMPANY_STATUS_LOSE || //流失
- mobileOneItem.Status == utils.COMPANY_STATUS_POTENTIAL || //潜在
- mobileOneItem.Status == utils.COMPANY_STATUS_FOREVER { //永续
- mobileOneItem.HasMove = true
- }
- }
- br.Msg = "手机号1已存在"
- br.Success = true
- br.Data = mobileOneItem
- br.IsSendEmail = false
- br.Ret = 600
- return
- }
- }
- }
- }
- //手机号2校验(不需要修改,修改时间:2021年03月09日11:23:37)
- /*if req.MobileTwo != "" && req.MobileTwo != wxUser.MobileTwo {
- mobileTwoItem, err := company.GetUserCountByMobile(req.MobileTwo)
- if err != nil && err.Error() == utils.ErrNoRow() {
- mobileTwoItem, err = company.CheckCompanyUserCountByMobileTwo(req.MobileTwo)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "编辑失败"
- br.ErrMsg = "判断手机号2是否存在,Err:" + err.Error()
- return
- }
- }
- if mobileTwoItem != nil {
- if mobileTwoItem.UserId > 0 {
- if req.CompanyId > 0 {
- if req.CompanyId == mobileTwoItem.CompanyId {
- br.Msg = "手机号2已存在"
- br.Success = true
- br.Data = mobileTwoItem
- br.IsSendEmail = false
- br.Ret = 600
- return
- } else {
- if strings.Contains(mobileTwoItem.Status, "/") {
- if strings.Contains(mobileTwoItem.Status, "正式") || strings.Contains(mobileTwoItem.Status, "试用") {
- mobileTwoItem.HasMove = false
- } else {
- mobileTwoItem.HasMove = true
- }
- } else {
- if mobileTwoItem.Status == utils.COMPANY_STATUS_FREEZE || //冻结
- mobileTwoItem.Status == utils.COMPANY_STATUS_LOSE || //流失
- mobileTwoItem.Status == utils.COMPANY_STATUS_POTENTIAL || //潜在
- mobileTwoItem.Status == utils.COMPANY_STATUS_FOREVER { //永续
- mobileTwoItem.HasMove = true
- }
- }
- br.Msg = "手机号2已存在"
- br.Success = true
- br.Data = mobileTwoItem
- br.IsSendEmail = false
- br.Ret = 600
- return
- }
- } else {
- if strings.Contains(mobileTwoItem.Status, "/") {
- if strings.Contains(mobileTwoItem.Status, "正式") || strings.Contains(mobileTwoItem.Status, "试用") {
- mobileTwoItem.HasMove = false
- } else {
- mobileTwoItem.HasMove = true
- }
- } else {
- if mobileTwoItem.Status == utils.COMPANY_STATUS_FREEZE || //冻结
- mobileTwoItem.Status == utils.COMPANY_STATUS_LOSE || //流失
- mobileTwoItem.Status == utils.COMPANY_STATUS_POTENTIAL || //潜在
- mobileTwoItem.Status == utils.COMPANY_STATUS_FOREVER { //永续
- mobileTwoItem.HasMove = true
- }
- }
- br.Msg = "手机号2已存在"
- br.Success = true
- br.Data = mobileTwoItem
- br.IsSendEmail = false
- br.Ret = 600
- return
- }
- }
- }
- }*/
- if req.Email != "" && req.Email != wxUser.Email {
- emailItem, err := company.CheckCompanyUserCountByEmail(req.Email)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "编辑失败"
- br.ErrMsg = "编辑失败,Err:" + err.Error()
- return
- }
- if emailItem != nil {
- if emailItem.UserId > 0 {
- //获取联系人分组信息
- userSellerGroupInfo, err := models.GetUserGroupSellerByUserId(int(emailItem.UserId))
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "查询信息异常"
- br.Success = true
- br.Data = emailItem
- br.IsSendEmail = false
- br.Ret = 600
- return
- }
- if req.CompanyId == emailItem.CompanyId {
- //修改返回给前端用户的信息
- if userSellerGroupInfo != nil {
- emailItem.SellerRealName = userSellerGroupInfo.SellerRealName
- emailItem.Status = userSellerGroupInfo.Status
- }
- br.Msg = "邮箱已存在"
- br.Success = true
- br.Data = emailItem
- br.IsSendEmail = false
- br.Ret = 600
- return
- } else {
- hasMove := true //是否可移动
- //如果是大于 1 的客户,那么就是非潜在客户,需要去查询对应的销售
- if emailItem.CompanyId > 1 {
- //获取联系人分组信息
- userSellerGroupInfoList, err := models.GetUserGroupSellersByUserId(int(emailItem.UserId))
- //根据分组校验
- if err == nil && len(userSellerGroupInfoList) > 0 {
- sellerMap := make(map[int]string) //销售信息map
- sellerNameSlice := make([]string, 0) //销售姓名切片
- statusNameSlice := make([]string, 0) //客户状态姓名切片
- for _, v := range userSellerGroupInfoList {
- if v.Status != utils.COMPANY_STATUS_LOSE && v.Status != utils.COMPANY_STATUS_FOREVER && hasMove == true {
- hasMove = false
- }
- statusNameSlice = append(statusNameSlice, v.Status)
- if _, ok := sellerMap[v.SellerId]; ok {
- continue
- }
- sellerMap[v.SellerId] = v.SellerRealName
- sellerNameSlice = append(sellerNameSlice, v.SellerRealName)
- }
- emailItem.SellerRealName = strings.Join(sellerNameSlice, "/")
- emailItem.Status = strings.Join(statusNameSlice, "/")
- }
- }
- //是否可移动
- emailItem.HasMove = hasMove
- br.Msg = "邮箱已存在"
- br.Success = true
- br.Data = emailItem
- br.IsSendEmail = false
- br.Ret = 600
- return
- }
- } else {
- if strings.Contains(emailItem.Status, "/") {
- if strings.Contains(emailItem.Status, "正式") || strings.Contains(emailItem.Status, "试用") {
- emailItem.HasMove = false
- } else {
- emailItem.HasMove = true
- }
- } else {
- if emailItem.Status == utils.COMPANY_STATUS_FREEZE || //冻结
- emailItem.Status == utils.COMPANY_STATUS_LOSE || //流失
- emailItem.Status == utils.COMPANY_STATUS_POTENTIAL || //潜在
- emailItem.Status == utils.COMPANY_STATUS_FOREVER { //永续
- emailItem.HasMove = true
- }
- }
- br.Msg = "邮箱已存在"
- br.Success = true
- br.Data = emailItem
- br.IsSendEmail = false
- br.Ret = 600
- return
- }
- }
- }
- //if wxUser.BusinessCardUrl != req.BusinessCardUrl && utils.RunMode == "release" {
- if wxUser.BusinessCardUrl != req.BusinessCardUrl {
- // 获取图片识别客户名称的配置
- crmConfig, err := company.GetConfigDetailByCode("card_recognition_company_name")
- if err != nil {
- br.Msg = "获取配置失败"
- br.ErrMsg = "获取配置失败"
- br.IsSendEmail = false
- return
- }
- // 获取图片识别手机号的配置
- crmConfig2, err := company.GetConfigDetailByCode("card_recognition_tel")
- if err != nil {
- br.Msg = "获取配置失败"
- br.ErrMsg = "获取配置失败"
- br.IsSendEmail = false
- return
- }
- if crmConfig.ConfigValue == "true" || crmConfig2.ConfigValue == "true" {
- //companyName := wxUser.CompanyName
- //if companyName == "" {
- companyInfo, err := company.GetCompanyById(req.CompanyId)
- if err != nil {
- br.Msg = "查找客户失败"
- br.ErrMsg = "查找客户失败,err:" + err.Error()
- return
- }
- companyName := companyInfo.CompanyName
- //}
- companyName = utils.TrimStr(companyName)
- tmpCompanyNameList, err := elastic.Analyze(companyName)
- if err != nil {
- br.Msg = "添加失败"
- br.ErrMsg = "客户名称分词失败,Err:" + err.Error()
- return
- }
- //公司名称切片
- analyzeNameList := []string{companyName}
- for _, v := range tmpCompanyNameList {
- if v == "" {
- continue
- }
- ignoreStrs := []string{"", "有限", "投资", "资本", "管理", "贸易", "资产", "公司", "股份", "集团", "有限公司"}
- if !strings.Contains(strings.Join(ignoreStrs, ","), v) && utf8.RuneCount([]byte(v)) > 1 {
- //不在上面的过滤字里面,且切出来的字符大于1位
- analyzeNameList = append(analyzeNameList, v)
- }
- }
- //名片识别出来的客户名称切片
- companyNameSlice := make([]string, 0)
- card, err := services.GetBusinessCard(req.BusinessCardUrl)
- if err != nil {
- br.Msg = "名片识别失败"
- br.ErrMsg = "名片识别失败,Err:" + err.Error()
- return
- }
- //if card.Errno != 0 {
- // br.Msg = "您上传了非名片图片,请重新上传"
- // br.ErrMsg = "名片识别失败,ErrMsg:" + card.ErrorMsg + ";errCode:" + strconv.Itoa(card.Errno)
- // return
- //}
- //var mobileStr string
- //for _, v := range card.WordsResult {
- // mobileStr += v.Words + ","
- //}
- isFlag := false
- if len(card.WordsResult.MOBILE) > 0 {
- mobileStr := strings.Join(card.WordsResult.MOBILE, ",")
- //if req.MobileOne != "" {
- // if strings.Contains(mobileStr, req.MobileOne) || mobileStr == "" {
- // isFlag = true
- // } else {
- // isFlag = false
- // }
- //}
- //
- //if isFlag == false && req.MobileTwo != "" {
- // if strings.Contains(mobileStr, req.MobileTwo) {
- // isFlag = true
- // } else {
- // isFlag = false
- // }
- //}
- if req.MobileOne != "" && strings.Contains(mobileStr, req.MobileOne) {
- isFlag = true
- }
- if req.MobileTwo != "" && strings.Contains(mobileStr, req.MobileTwo) {
- isFlag = true
- }
- //如果百度识别出来了客户名称,那么将识别出来的客户名称添加到待校验客户名称切片中
- if len(card.WordsResult.COMPANY) > 0 && card.WordsResult.COMPANY[0] != "" {
- companyNameSlice = card.WordsResult.COMPANY
- }
- }
- //如果百度未识别出来手机号或者公司名称,那么进行阿里识别
- if !isFlag || (len(companyNameSlice) == 0 && crmConfig.ConfigValue == "true") {
- //阿里云识别
- aliyunResult, errMsg, err := services.AliyunOcrBusinessCard(req.BusinessCardUrl)
- if err != nil {
- br.Msg = "识别失败"
- br.ErrMsg = "识别失败,Err:" + err.Error()
- return
- }
- if !aliyunResult.Success {
- br.Msg = "识别失败"
- br.ErrMsg = "识别失败"
- return
- }
- if errMsg != "" {
- br.Msg = errMsg
- return
- }
- //如果百度没有识别出来手机号,那么还需要阿里识别出来的手机号校验下
- if !isFlag {
- if len(aliyunResult.TelCell) > 0 {
- mobileStr := strings.Join(aliyunResult.TelCell, ",")
- if req.MobileOne != "" {
- if strings.Contains(mobileStr, req.MobileOne) {
- isFlag = true
- } else {
- isFlag = false
- }
- }
- } else {
- isFlag = true
- }
- }
- //如果阿里云识别出来了客户名称,那么将识别出来的客户名称添加到待校验客户名称切片中
- if len(aliyunResult.Company) > 0 {
- companyNameSlice = append(companyNameSlice, aliyunResult.Company...)
- }
- }
- if !isFlag && crmConfig2.ConfigValue == "true" {
- br.Msg = "名片信息与联系人手机号不符"
- br.IsSendEmail = false
- return
- }
- //校验识别出来的名片名称与传入的客户名称是否一致
- if len(companyNameSlice) > 0 && crmConfig.ConfigValue == "true" {
- isCompanyNameFlag := false //是否成功匹配客户名称
- //遍历识别出来的客户名称,然后与系统的客户名称做匹配(识别出来的名称包含系统名称的话,那么标记成功匹配)
- for _, tmpCompanyName := range companyNameSlice {
- //空串不处理
- if companyName == "" {
- continue
- }
- for _, analyzeName := range analyzeNameList {
- //如果分词出来的公司名称正好在识别出来的公司名称里面,那么就认为校验通过了
- if strings.Contains(tmpCompanyName, analyzeName) {
- isCompanyNameFlag = true
- break
- }
- }
- if isCompanyNameFlag {
- break
- }
- }
- //如果没有匹配到客户名称,那么就返回报错
- if !isCompanyNameFlag {
- br.Msg = "名片信息与公司名称不符"
- br.IsSendEmail = false
- return
- }
- }
- }
- }
- //UPDATE wx_user
- // SET
- // last_updated_time = NOW(),
- // position = ?,
- // is_maker = ?,
- // business_card_url = ?,
- // mobile_two= ?,
- // department_name=?,
- // company_id=?,country_code=?
- //待更新字段
- updateCol := []string{"RealName", "Mobile", "MobileTwo", "Email", "Sex", "LastUpdatedTime", "Position", "IsMaker", "BusinessCardUrl", "DepartmentName", "CompanyId", "CountryCode"}
- //外呼手机号、外呼手机号区号
- if wxUser.OutboundMobile == "" || wxUser.OutboundMobile == wxUser.Mobile {
- wxUser.OutboundMobile = req.MobileOne
- wxUser.OutboundCountryCode = req.CountryCode
- //外呼字段数据修改
- updateCol = append(updateCol, "OutboundMobile", "OutboundCountryCode")
- }
- wxUser.RealName = req.RealName
- wxUser.Mobile = req.MobileOne
- wxUser.MobileTwo = req.MobileTwo
- wxUser.Email = req.Email
- wxUser.Sex = req.Sex
- wxUser.LastUpdatedTime = time.Now()
- wxUser.Position = req.Position
- wxUser.IsMaker = req.IsMaker
- wxUser.BusinessCardUrl = req.BusinessCardUrl
- wxUser.DepartmentName = req.DepartmentName
- wxUser.CompanyId = req.CompanyId
- wxUser.CountryCode = req.CountryCode
- fmt.Println("wxUser 2", wxUser)
- err = wxUser.Update(updateCol)
- //err = company.EditCompanyUser(&req)
- if err != nil {
- br.Msg = "编辑失败!"
- br.ErrMsg = "编辑失败,Err:" + err.Error()
- return
- }
- //更新客户最近阅读次数以及最近阅读时间
- go services.ModifyCompanyProductLastViewData([]int{wxUser.CompanyId})
- //联系人信息
- originalUserInfo, _ := json.Marshal(oldWxUser)
- userInfo, _ := json.Marshal(wxUser)
- go services.AddWxUserOpLog(company.WxUserOpLog{
- LogType: "edit",
- UserId: int(wxUser.UserId),
- CompanyId: wxUser.CompanyId,
- Mobile: wxUser.Mobile,
- Email: wxUser.Email,
- OriginalUserInfo: string(originalUserInfo),
- UserInfo: string(userInfo),
- OriginalUserSellerInfo: "",
- UserSellerInfo: "",
- OpUserId: sysUser.AdminId,
- OpUserName: sysUser.RealName,
- CreateTime: time.Now(),
- })
- br.Ret = 200
- br.Success = true
- br.Msg = "编辑成功"
- br.IsAddLog = true
- }
- // @Title 潜在用户列表
- // @Description 潜在用户列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param ApplyMethod query int true "申请方式,0:全部,1:未申请,2:已付费客户申请试用,3:非客户申请试用"
- // @Param KeyWord query string true "搜索关键词"
- // @Success 200 {object} models.PotentialUserListResp
- // @router /potential/user/list [get]
- func (this *CompanyController) PotentialUserList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- keyWord := this.GetString("KeyWord")
- applyMethod, _ := this.GetInt("ApplyMethod")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- if applyMethod > 0 {
- condition += ` AND apply_method=? `
- pars = append(pars, applyMethod-1)
- }
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
- condition += ` AND apply_method=? `
- pars = append(pars, 1)
- }
- //非管理员不让看数据
- if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
- list := make([]*models.PotentialUserItem, 0)
- page := paging.GetPaging(currentIndex, pageSize, 0)
- resp := new(models.PotentialUserListResp)
- resp.List = list
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- if keyWord != "" {
- condition += ` AND (a.real_name LIKE '%` + keyWord + `%' OR a.mobile LIKE '%` + keyWord + `%' OR a.email LIKE '%` + keyWord + `%') `
- }
- total, err := models.GetPotentialUserListCount(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取分页数据失败,Err:" + err.Error()
- return
- }
- list, err := models.GetPotentialUserList(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- listLen := len(list)
- mobilesSlice := make([]string, 0)
- emailsSlice := make([]string, 0)
- for _, v := range list {
- if v.Mobile != "" {
- mobilesSlice = append(mobilesSlice, v.Mobile)
- } else if v.Email != "" {
- emailsSlice = append(emailsSlice, v.Email)
- }
- }
- //用户浏览数据
- mobileStr := strings.Join(mobilesSlice, "','")
- mobileStr = "'" + mobileStr + "'"
- emailStr := strings.Join(emailsSlice, "','")
- emailStr = "'" + emailStr + "'"
- //userViewTotalList, _ := models.GetCountUserViewHistoryByUserIds(userIdStr)
- //userViewTotalMap := make(map[int]*models.UserViewTotalSlice)
- //for _, userView := range userViewTotalList {
- // userViewTotalMap[userView.UserId] = userView
- //}
- //用户日评浏览数据
- //userReportViewTotalList, _ := models.GetReportViewMaxTimeByUserIds(userIdStr)
- //userReportViewTotalMap := make(map[int]*models.ReportViewRecord)
- //for _, userReportView := range userReportViewTotalList {
- // userReportViewTotalMap[userReportView.UserId] = userReportView
- //}
- //手机号
- userViewMobileTotalMap := make(map[string]*models.UserViewMobileTotalSlice)
- userReportViewMobileTotalMap := make(map[string]*models.ReportViewMobileRecord)
- if len(mobilesSlice) > 0 {
- //用户浏览数据
- userViewMobileTotalList, _ := models.GetCountUserViewHistoryByMobiles(mobileStr)
- for _, userViewMobile := range userViewMobileTotalList {
- userViewMobileTotalMap[userViewMobile.Mobile] = userViewMobile
- }
- //每日点评手机号数据
- userReportViewMobileTotalList, _ := models.GetReportViewMaxTimeByMobiles(mobileStr)
- for _, userReportViewMobile := range userReportViewMobileTotalList {
- userReportViewMobileTotalMap[userReportViewMobile.Mobile] = userReportViewMobile
- }
- }
- //邮箱
- userViewEmailTotalMap := make(map[string]*models.UserViewEmailTotalSlice)
- userReportViewEmailTotalMap := make(map[string]*models.ReportViewEmailRecord)
- if len(emailsSlice) > 0 {
- //用户浏览数据
- userViewEmailTotalList, _ := models.GetCountUserViewHistoryByEmails(emailStr)
- for _, userViewEmail := range userViewEmailTotalList {
- userViewEmailTotalMap[userViewEmail.Email] = userViewEmail
- }
- //每日点评手机号数据
- userReportViewEmailTotalList, _ := models.GetReportViewMaxTimeByEmails(emailStr)
- for _, userReportViewEmail := range userReportViewEmailTotalList {
- userReportViewEmailTotalMap[userReportViewEmail.Email] = userReportViewEmail
- }
- }
- for i := 0; i < listLen; i++ {
- item := list[i]
- //item, err := models.GetReportViewMaxTime(list[i].UserId)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取GetReportViewMaxTime失败,Err:" + err.Error()
- // return
- //}
- //list[i].ViewTotal += item.ViewTotal
- //手机号用户累计浏览次数
- if userView, ok := userViewMobileTotalMap[item.Mobile]; ok {
- list[i].ViewTotal += userView.Total
- if userView.CreatedTime.After(list[i].LastViewTime) {
- list[i].LastViewTime = userView.CreatedTime
- list[i].LastViewTimeStr = userView.CreatedTime.Format(utils.FormatDateTime)
- }
- }
- //邮箱用户累计浏览次数
- if userView, ok := userViewEmailTotalMap[item.Email]; ok {
- //总共浏览的报表数据需要调整为(手机号用户浏览晨报数+邮箱号用户浏览晨报数)
- list[i].ViewTotal += userView.Total
- if userView.CreatedTime.After(list[i].LastViewTime) {
- list[i].LastViewTime = userView.CreatedTime
- list[i].LastViewTimeStr = userView.CreatedTime.Format(utils.FormatDateTime)
- }
- }
- //如果存在手机号用户日评数据,那么需要做处理
- if reportView, ok := userReportViewMobileTotalMap[item.Mobile]; ok {
- //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
- if reportView.LastViewTime.After(list[i].LastViewTime) {
- list[i].LastViewTime = reportView.LastViewTime
- list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
- }
- //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
- list[i].ViewTotal += reportView.ViewTotal
- }
- //如果存在手机号用户日评数据,那么需要做处理
- if reportView, ok := userReportViewEmailTotalMap[item.Email]; ok {
- //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
- if reportView.LastViewTime.After(list[i].LastViewTime) {
- list[i].LastViewTime = reportView.LastViewTime
- list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
- }
- //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
- list[i].ViewTotal += reportView.ViewTotal
- }
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(models.PotentialUserListResp)
- resp.List = list
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 标记潜在用户
- // @Description 标记潜在用户接口
- // @Param request body models.PotentialUserDealReq true "type json string"
- // @Success Ret=200 标记成功
- // @router /potential/user/deal [post]
- func (this *CompanyController) PotentialUserDeal() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.PotentialUserDealReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- // 标记处理
- err = services.DealPotentialUser(req.UserId, sysUser.AdminId)
- if err != nil {
- br.Msg = "标记失败"
- br.ErrMsg = "标记失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "标记成功"
- }
- // @Title 删除潜在用户
- // @Description 删除潜在用户接口
- // @Param request body models.PotentialUserDeleteReq true "type json string"
- // @Success Ret=200 删除成功
- // @router /potential/user/delete [post]
- func (this *CompanyController) PotentialUserDelete() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.PotentialUserDeleteReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- //删除用户
- err = services.DeleteWxUser(req.UserId)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "删除成功"
- }
- // @Title 移动潜在用户
- // @Description 移动潜在用户接口
- // @Param request body models.PotentialUserMoveReq true "type json string"
- // @Success Ret=200 移动成功
- // @router /potential/user/move [post]
- func (this *CompanyController) PotentialUserMove() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req models.PotentialUserMoveReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.UserId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "客户id错误"
- return
- }
- //如果移动客户编号小于等于0,那么移动到潜在客户
- if req.CompanyId <= 0 {
- req.CompanyId = 1
- }
- wxUser, err := models.GetWxUserByUserId(req.UserId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
- return
- }
- oldWxUser := *wxUser
- if req.Mobile == "" {
- req.Mobile = wxUser.Mobile
- }
- if req.Email == "" {
- req.Email = wxUser.Email
- }
- if req.Mobile == "" && req.Email == "" {
- br.Msg = "手机号和邮箱不能同时为空"
- return
- }
- //校验手机号
- if req.Mobile != "" && wxUser.Mobile != req.Mobile {
- count, err := models.CheckUserMobileIsRegister(req.UserId, req.Mobile)
- if err != nil {
- br.Msg = "校验数据失败"
- br.ErrMsg = "校验数据失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- br.Msg = "该手机号已经注册过用户"
- return
- }
- }
- //校验邮箱
- if req.Email != "" && wxUser.Email != req.Email {
- if !utils.ValidateEmailFormatat(req.Email) {
- br.Msg = "请输入正确的邮箱(包含@)"
- return
- }
- count, err := models.CheckUserEmailIsRegister(req.UserId, req.Email)
- if err != nil {
- br.Msg = "校验数据失败"
- br.ErrMsg = "校验数据失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- br.Msg = "该邮箱已经注册过用户"
- br.IsSendEmail = false
- return
- }
- }
- updateCol := make([]string, 0)
- if wxUser.OutboundMobile == "" || wxUser.Mobile == wxUser.OutboundMobile {
- wxUser.OutboundMobile = req.Mobile
- wxUser.OutboundCountryCode = req.CountryCode
- updateCol = append(updateCol, "OutboundMobile", "OutboundCountryCode")
- }
- if req.Email != "" {
- wxUser.Email = req.Email
- updateCol = append(updateCol, "Email")
- }
- if req.RealName != "" {
- wxUser.RealName = req.RealName
- updateCol = append(updateCol, "RealName")
- }
- if req.Mobile != "" {
- wxUser.Mobile = req.Mobile
- updateCol = append(updateCol, "Mobile")
- }
- if req.CountryCode != "" {
- wxUser.CountryCode = req.CountryCode
- updateCol = append(updateCol, "CountryCode")
- }
- if req.Position != "" {
- wxUser.Position = req.Position
- updateCol = append(updateCol, "Position")
- }
- if wxUser.DepartmentName == "" && req.DepartmentName != "" {
- wxUser.DepartmentName = req.DepartmentName
- updateCol = append(updateCol, "DepartmentName")
- }
- wxUser.Sex = req.Sex
- wxUser.IsMaker = req.IsMaker
- updateCol = append(updateCol, "Sex", "IsMaker")
- //名片匹配
- if req.BusinessCardUrl != "" {
- //if req.BusinessCardUrl != "" && utils.RunMode == "release" {
- // 获取图片识别手机号的配置
- crmConfig2, err := company.GetConfigDetailByCode("card_recognition_tel")
- if err != nil {
- br.Msg = "获取配置失败"
- br.ErrMsg = "获取配置失败"
- br.IsSendEmail = false
- return
- }
- if crmConfig2.ConfigValue == "true" {
- card, err := services.GetBusinessCard(req.BusinessCardUrl)
- if err != nil {
- br.Msg = "名片识别失败"
- br.ErrMsg = "名片识别失败,Err:" + err.Error()
- return
- }
- isFlag := false
- if len(card.WordsResult.MOBILE) > 0 {
- mobileStr := strings.Join(card.WordsResult.MOBILE, ",")
- //if req.Mobile != "" {
- // if strings.Contains(mobileStr, req.Mobile) || mobileStr == "" {
- // isFlag = true
- // } else {
- // isFlag = false
- // }
- //}
- if req.Mobile != "" && strings.Contains(mobileStr, req.Mobile) {
- isFlag = true
- }
- }
- if !isFlag {
- //阿里云识别
- //if utils.RunMode == "release" {
- aliyunResult, errMsg, err := services.AliyunOcrBusinessCard(req.BusinessCardUrl)
- if err != nil {
- br.Msg = "识别失败"
- br.ErrMsg = "识别失败,Err:" + err.Error()
- return
- }
- if !aliyunResult.Success {
- br.Msg = "识别失败"
- br.ErrMsg = "识别失败"
- return
- }
- if errMsg != "" {
- br.Msg = errMsg
- return
- }
- if len(aliyunResult.TelCell) > 0 {
- mobileStr := strings.Join(aliyunResult.TelCell, ",")
- if req.Mobile != "" {
- if strings.Contains(mobileStr, req.Mobile) {
- isFlag = true
- } else {
- isFlag = false
- }
- }
- } else {
- isFlag = true
- }
- //}
- }
- if !isFlag && crmConfig2.ConfigValue == "true" {
- br.Msg = "名片信息与联系人手机号不符"
- return
- }
- }
- wxUser.BusinessCardUrl = req.BusinessCardUrl
- updateCol = append(updateCol, "BusinessCardUrl")
- }
- productId := services.GetProductId(sysUser.RoleTypeCode)
- companyProductList, _ := getSysCompanyProductList(productId, req.CompanyId)
- //联系人与销售的关系
- userSellerRelationList, err := models.GetUserSellerRelationList(int(wxUser.UserId))
- if err != nil {
- return
- }
- userSellerRelationInfo, _ := json.Marshal(userSellerRelationList)
- err = services.MovePotentialUser(req.UserId, req.CompanyId, req.RealName, req.Mobile, req.Email, req.Remark, companyProductList, wxUser, updateCol)
- //err = models.MovePotentialUser(req.UserId, req.CompanyId, req.RealName, req.Mobile, req.Email, req.Remark)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "移动失败,Err:" + err.Error()
- return
- }
- //更新客户最近阅读次数以及最近阅读时间
- go services.ModifyCompanyProductLastViewData([]int{req.CompanyId})
- //联系人信息
- originalUserInfo, _ := json.Marshal(oldWxUser)
- userInfo, _ := json.Marshal(wxUser)
- go services.AddWxUserOpLog(company.WxUserOpLog{
- LogType: "move",
- UserId: int(wxUser.UserId),
- CompanyId: wxUser.CompanyId,
- Mobile: wxUser.Mobile,
- Email: wxUser.Email,
- OriginalUserInfo: string(originalUserInfo),
- UserInfo: string(userInfo),
- OriginalUserSellerInfo: string(userSellerRelationInfo),
- UserSellerInfo: "",
- OpUserId: sysUser.AdminId,
- OpUserName: sysUser.RealName,
- CreateTime: time.Now(),
- })
- go services.AddWxUserMoveLog(wxUser, sysUser, req.CompanyId) // 添加用户移动日志记录
- br.Ret = 200
- br.Success = true
- br.Msg = "移动成功"
- }
- // @Title 移动联系人
- // @Description 移动联系接口,将联系人从自己名下移动到另一个客户销售名下
- // @Param request body models.UserMoveReq true "type json string"
- // @Success Ret=200 移动成功
- // @router /user/move [post]
- func (this *CompanyController) UserMove() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req models.UserMoveReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.UserId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "联系人id错误"
- return
- }
- if req.CompanyId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "客户id错误"
- return
- }
- if req.SellerId < 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "销售id错误"
- return
- }
- wxUser, err := models.GetWxUserByUserId(req.UserId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
- return
- }
- oldWxUser := *wxUser
- if wxUser.CompanyId == req.CompanyId {
- br.Msg = "移动失败"
- br.ErrMsg = "该联系人属于该客户"
- return
- }
- //产品id
- productId := services.GetProductId(sysUser.RoleTypeCode)
- //操作权限校验
- errMsg, err := checkOpCompanyUserByCompanyId(wxUser.CompanyId, productId, sysUser.AdminId, sysUser.RoleTypeCode)
- if err != nil {
- br.Msg = "移动失败!" + errMsg
- br.ErrMsg = "移动失败,Err:" + err.Error()
- return
- }
- //联系人与销售的关系
- userSellerRelationList, err := models.GetUserSellerRelationList(int(wxUser.UserId))
- if err != nil {
- return
- }
- userSellerRelationInfo, _ := json.Marshal(userSellerRelationList)
- err = services.MoveUser(req.UserId, req.CompanyId, req.SellerId, wxUser, sysUser.AdminId)
- //err = models.MovePotentialUser(req.UserId, req.CompanyId, req.RealName, req.Mobile, req.Email, req.Remark)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "移动失败,Err:" + err.Error()
- return
- }
- //更新客户最近阅读次数以及最近阅读时间
- go services.ModifyCompanyProductLastViewData([]int{wxUser.CompanyId, req.CompanyId})
- //联系人信息
- originalUserInfo, _ := json.Marshal(oldWxUser)
- userInfo, _ := json.Marshal(wxUser)
- {
- // 最新的联系人信息
- newWxUser, err := models.GetWxUserByUserId(req.UserId)
- if err == nil {
- userInfo, _ = json.Marshal(newWxUser)
- }
- }
- go services.AddWxUserOpLog(company.WxUserOpLog{
- LogType: "move",
- UserId: int(wxUser.UserId),
- CompanyId: wxUser.CompanyId,
- Mobile: wxUser.Mobile,
- Email: wxUser.Email,
- OriginalUserInfo: string(originalUserInfo),
- UserInfo: string(userInfo),
- OriginalUserSellerInfo: string(userSellerRelationInfo),
- UserSellerInfo: "",
- OpUserId: sysUser.AdminId,
- OpUserName: sysUser.RealName,
- CreateTime: time.Now(),
- })
- go services.AddWxUserMoveLog(wxUser, sysUser, req.CompanyId) // 添加用户移动日志记录
- br.Ret = 200
- br.Success = true
- br.Msg = "移动成功"
- br.IsAddLog = true
- }
- // @Title 搜索客户
- // @Description 搜索客户接口
- // @Param KeyWord query string true "搜索关键词"
- // @Success 200 {object} company.CompanySearchResp
- // @router /potential/company/search [get]
- func (this *CompanyUserController) CompanySearch() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var err error
- keyWord := this.GetString("KeyWord")
- item := make([]*company.CompanyItem, 0)
- if keyWord != "" {
- item, err = company.GetCompanyBySearch(keyWord)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- }
- resp := new(company.CompanySearchResp)
- resp.List = item
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 企查查模糊查询客户接口
- // @Description 企查查模糊查询客户
- // @Param KeyWord query string true "搜索关键词"
- // @Success 200 {object} services.Result
- // @router /potential/company/qccSearch [get]
- func (this *CompanyUserController) CompanyQCCSearch() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var err error
- var results []services.Result
- keyWord := this.GetString("KeyWord")
- if keyWord != "" {
- results, err = services.QCCFuzzySearch(keyWord)
- if err != nil {
- br.Data = results
- br.Msg = "获取数据失败," + err.Error()
- br.Ret = 200
- br.Success = true
- return
- }
- }
- br.Data = results
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // @Title 检测客户名称或社会信用码重复
- // @Description 检测客户名称或社会信用码重复接口(新增/编辑客户页面使用)
- // @Param CompanyName query string true "客户名称"
- // @Param CreditCode query string true "社会统一信用码"
- // @Success 200 {object} company.CheckCompanyInfoRepeatResp
- // @router /check/RepeatCompanyInfo [get]
- func (this *CompanyController) CheckCompanyInfoRepeat() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- roleTypeCode := sysUser.RoleTypeCode
- productId := services.GetProductId(roleTypeCode)
- companyName := this.GetString("CompanyName")
- creditCode := this.GetString("CreditCode")
- var status, comanyId, repeatStatus int
- var productName string
- if productId == 0 {
- productId = 1
- checkProductId := 2
- if creditCode != "" {
- codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "校验社会信用码是否存在失败"
- br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
- return
- }
- //存在ficc权限
- if codeItem != nil && codeItem.CompanyId > 0 {
- repeatStatus = 1
- goto Loop
- }
- codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "校验社会信用码是否存在失败"
- br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
- return
- }
- if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
- status = 1
- repeatStatus = 1
- productName = codeCheckItem.ProductName
- comanyId = codeCheckItem.CompanyId
- goto Loop
- }
- }
- if companyName != "" {
- nameItem, err := company.CheckCompanyProductByName(companyName, productId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "校验客户名称是否存在失败"
- br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
- return
- }
- if nameItem != nil && nameItem.CompanyId > 0 {
- repeatStatus = 2
- goto Loop
- }
- nameCheckItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "校验客户名称是否存在失败"
- br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
- return
- }
- if nameCheckItem != nil && nameCheckItem.CompanyId > 0 {
- status = 1
- repeatStatus = 2
- productName = nameCheckItem.ProductName
- comanyId = nameCheckItem.CompanyId
- goto Loop
- }
- }
- productId = 2
- checkProductId = 1
- if creditCode != "" {
- codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "校验社会信用码是否存在失败"
- br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
- return
- }
- if codeItem != nil && codeItem.CompanyId > 0 {
- repeatStatus = 1
- goto Loop
- }
- codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "校验社会信用码是否存在失败"
- br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
- return
- }
- if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
- status = 1
- repeatStatus = 1
- productName = codeCheckItem.ProductName
- comanyId = codeCheckItem.CompanyId
- goto Loop
- }
- }
- if companyName != "" {
- nameItem, err := company.CheckCompanyProductByName(companyName, productId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "校验客户名称是否存在失败"
- br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
- return
- }
- if nameItem != nil && nameItem.CompanyId > 0 {
- repeatStatus = 2
- goto Loop
- }
- nameCheckItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "校验客户名称是否存在失败"
- br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
- return
- }
- if nameCheckItem != nil && nameCheckItem.CompanyId > 0 {
- status = 1
- repeatStatus = 2
- productName = nameCheckItem.ProductName
- comanyId = nameCheckItem.CompanyId
- goto Loop
- }
- }
- } else {
- checkProductId := 0
- if productId == 1 {
- checkProductId = 2
- } else if productId == 2 {
- checkProductId = 1
- }
- if creditCode != "" {
- codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "校验社会信用码是否存在失败"
- br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
- return
- }
- if codeItem != nil && codeItem.CompanyId > 0 {
- repeatStatus = 1
- goto Loop
- }
- codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "校验社会信用码是否存在失败"
- br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
- return
- }
- if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
- status = 1
- repeatStatus = 1
- productName = codeCheckItem.ProductName
- comanyId = codeCheckItem.CompanyId
- goto Loop
- }
- }
- if companyName != "" {
- nameItem, err := company.CheckCompanyProductByName(companyName, productId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "校验客户名称是否存在失败"
- br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
- return
- }
- if nameItem != nil && nameItem.ProductName != "" {
- repeatStatus = 2
- goto Loop
- }
- nameCheckoutItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "校验客户名称是否存在失败"
- br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
- return
- }
- if nameCheckoutItem != nil && nameCheckoutItem.CompanyId > 0 {
- status = 1
- repeatStatus = 2
- productName = nameCheckoutItem.ProductName
- comanyId = nameCheckoutItem.CompanyId
- goto Loop
- }
- }
- }
- Loop:
- resp := new(company.CheckCompanyInfoRepeatResp)
- resp.Status = status
- resp.RepeatStatus = repeatStatus
- resp.ProductName = productName
- resp.CompanyId = comanyId
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // ViewReportList
- // @Title 联系人阅读报告记录
- // @Description 联系人阅读报告记录
- // @Param UserId query int true "用户id"
- // @Param TxtType query int true "类型0全部,1权益,2ficc"
- // @Param PageSize query int true "每页数据条数"
- // @Param LastViewTime query string true "最近一次的阅读时间,没有的话,那就是获取最新数据"
- // @Success 200 {object} company.ViewReportListResp
- // @router /view/report/list [get]
- func (this *CompanyUserController) ViewReportList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- userId, _ := this.GetInt("UserId")
- txtType, _ := this.GetInt("TxtType")
- pageSize, _ := this.GetInt("PageSize")
- lastViewTime := this.GetString("LastViewTime")
- if userId <= 0 {
- br.Msg = "参数错误"
- return
- }
- // 默认20条数据
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if userId > 0 {
- }
- item, err := models.GetWxUserByUserId(userId)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取联系人信息失败,Err:" + err.Error()
- return
- }
- var lastViewTimeT time.Time
- if lastViewTime != `` {
- lastViewTimeT, err = time.ParseInLocation(utils.FormatDateTime, lastViewTime, time.Local)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "最近一次阅读时间转换异常,Err:" + err.Error()
- return
- }
- }
- list := make([]*company.ViewReportList, 0)
- recordList := make([]*models.UserReportViewRecord, 0)
- obj := models.UserReportViewRecord{}
- var baseCondition string // 基础条件
- var basePars []interface{}
- if item.Mobile != "" {
- baseCondition = ` AND mobile = ? `
- basePars = append(basePars, item.Mobile)
- } else if item.Email == "" {
- baseCondition = ` AND email = ? `
- basePars = append(basePars, item.Email)
- }
- // 阅读记录汇总数
- total := item.FiccViewTotal + item.RaiViewTotal
- switch txtType {
- case 1:
- baseCondition += ` AND source = ? `
- basePars = append(basePars, 4)
- total = item.RaiViewTotal
- if lastViewTimeT.IsZero() {
- if item.RaiLastViewTime != `` && item.RaiLastViewTime != `0000-00-00 00:00:00` {
- lastViewTimeT, _ = time.ParseInLocation(utils.FormatDateTime, item.RaiLastViewTime, time.Local)
- } else {
- lastViewTimeT = time.Now()
- }
- // 默认要把最新的记录列出来,所以往后加1s
- lastViewTime = lastViewTimeT.Add(1 * time.Second).Format(utils.FormatDateTime)
- }
- // 权益
- case 2: // ficc
- baseCondition += ` AND source in (?,?,?) `
- basePars = append(basePars, 1, 2, 3)
- total = item.FiccViewTotal
- if lastViewTimeT.IsZero() {
- if item.FiccLastViewTime != `` && item.FiccLastViewTime != `0000-00-00 00:00:00` {
- lastViewTimeT, _ = time.ParseInLocation(utils.FormatDateTime, item.FiccLastViewTime, time.Local)
- } else {
- lastViewTimeT = time.Now()
- }
- // 默认要把最新的记录列出来,所以往后加1s
- lastViewTime = lastViewTimeT.Add(1 * time.Second).Format(utils.FormatDateTime)
- }
- default:
- if lastViewTimeT.IsZero() {
- var ficcViewTime, raiViewTime time.Time
- if item.FiccLastViewTime != `` && item.FiccLastViewTime != `0000-00-00 00:00:00` {
- ficcViewTime, _ = time.ParseInLocation(utils.FormatDateTime, item.FiccLastViewTime, time.Local)
- }
- if item.RaiLastViewTime != `` && item.RaiLastViewTime != `0000-00-00 00:00:00` {
- raiViewTime, _ = time.ParseInLocation(utils.FormatDateTime, item.RaiLastViewTime, time.Local)
- }
- // 如果两个都没有值的话,那么就是当前时间
- if ficcViewTime.IsZero() && raiViewTime.IsZero() {
- lastViewTimeT = time.Now()
- } else if !ficcViewTime.IsZero() && !raiViewTime.IsZero() {
- if ficcViewTime.After(raiViewTime) {
- lastViewTimeT = ficcViewTime
- } else {
- lastViewTimeT = raiViewTime
- }
- } else if !ficcViewTime.IsZero() {
- lastViewTimeT = ficcViewTime
- } else {
- lastViewTimeT = raiViewTime
- }
- // 默认要把最新的记录列出来,所以往后加1s
- lastViewTime = lastViewTimeT.Add(1 * time.Second).Format(utils.FormatDateTime)
- }
- }
- // 开始实际的查询
- {
- condition := baseCondition
- pars := basePars
- condition += `AND create_time < ?`
- pars = append(pars, lastViewTime)
- total, items, err := obj.GetViewReportList(lastViewTimeT.Year(), condition, pars, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取失败,Err:" + err.Error()
- return
- }
- recordList = append(recordList, items...)
- // 查询去年的表
- if total < int64(pageSize) {
- secondCondition := baseCondition
- secondPars := basePars
- secondCondition += `AND create_time < ?`
- secondPars = append(secondPars, lastViewTime)
- _, items, err = obj.GetViewReportList(lastViewTimeT.Year()-1, secondCondition, secondPars, pageSize-int(total))
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取失败,Err:" + err.Error()
- return
- }
- recordList = append(recordList, items...)
- }
- }
- viewReportMap := make(map[string]company.ViewReportList) // 阅读记录map
- sourceReportIdListMap := make(map[int8][]int)
- for _, v := range recordList {
- tmpList, ok := sourceReportIdListMap[v.Source]
- if !ok {
- tmpList = make([]int, 0)
- }
- tmpList = append(tmpList, v.ReportId)
- sourceReportIdListMap[v.Source] = tmpList
- tmpTxtType := `ficc`
- if v.Source == 4 {
- tmpTxtType = `rights`
- }
- stopTime := `--`
- if v.StopTime > 0 {
- stopTime = fmt.Sprint(stopTime)
- }
- viewReportMap[fmt.Sprint(v.Source, "_", v.ReportId)] = company.ViewReportList{
- ResearchReportName: "",
- ReportType: "",
- CreatedTime: v.CreateTime,
- TxtType: tmpTxtType,
- MatchTypeName: "--",
- StopTime: stopTime,
- }
- }
- // 获取报告详情
- for source, reportIdList := range sourceReportIdListMap {
- switch source {
- case 1: // rddp报告
- tmpReportList, err := models.GetReportByIdList(reportIdList)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取weekly报告详情失败,Err:" + err.Error()
- return
- }
- for _, v := range tmpReportList {
- tmpKey := fmt.Sprint(source, "_", v.Id)
- if tmpInfo, ok := viewReportMap[tmpKey]; ok {
- tmpInfo.ResearchReportName = v.Title
- tmpInfo.ReportType = `rddp`
- tmpInfo.MatchTypeName = v.ClassifyNameFirst
- viewReportMap[tmpKey] = tmpInfo
- }
- }
- case 2: // weekly报告
- tmpReportList, err := models.GetResearchReportListByIdList(reportIdList)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取weekly报告详情失败,Err:" + err.Error()
- return
- }
- for _, v := range tmpReportList {
- tmpKey := fmt.Sprint(source, "_", v.ResearchReportId)
- if tmpInfo, ok := viewReportMap[tmpKey]; ok {
- tmpInfo.ResearchReportName = v.ResearchReportName
- tmpInfo.ReportType = v.Type
- viewReportMap[tmpKey] = tmpInfo
- }
- }
- case 3: // weekly_report商品的报告(应该是作废了);
- tmpReportList, err := models.GetChartPermissionByIdList(reportIdList)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取weekly报告详情失败,Err:" + err.Error()
- return
- }
- for _, v := range tmpReportList {
- tmpKey := fmt.Sprint(source, "_", v.ChartPermissionId)
- if tmpInfo, ok := viewReportMap[tmpKey]; ok {
- tmpInfo.ResearchReportName = v.ChartPermissionName
- tmpInfo.ReportType = `advisory`
- tmpInfo.MatchTypeName = v.ClassifyName
- viewReportMap[tmpKey] = tmpInfo
- }
- }
- case 4: // 察研观向的报告
- tmpReportList, err := cygx.GetArticleListByIdList(reportIdList)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取weekly报告详情失败,Err:" + err.Error()
- return
- }
- for _, v := range tmpReportList {
- tmpKey := fmt.Sprint(source, "_", v.ArticleId)
- if tmpInfo, ok := viewReportMap[tmpKey]; ok {
- tmpInfo.ResearchReportName = v.Title
- tmpInfo.ReportType = `cygx`
- tmpInfo.MatchTypeName = v.MatchTypeName
- viewReportMap[tmpKey] = tmpInfo
- }
- }
- }
- }
- // 报告标题处理
- for _, v := range recordList {
- tmpKey := fmt.Sprint(v.Source, "_", v.ReportId)
- if tmpInfo, ok := viewReportMap[tmpKey]; ok {
- stopTime := `--`
- if v.StopTime > 0 {
- stopTime = fmt.Sprint(v.StopTime)
- }
- list = append(list, &company.ViewReportList{
- ResearchReportName: tmpInfo.ResearchReportName,
- ReportType: tmpInfo.ReportType,
- CreatedTime: v.CreateTime,
- TxtType: tmpInfo.TxtType,
- MatchTypeName: tmpInfo.MatchTypeName,
- StopTime: stopTime,
- })
- }
- }
- // 类型处理
- for k, v := range list {
- if v.ReportType == "day" {
- list[k].MatchTypeName = "晨报"
- } else if v.ReportType == "week" {
- list[k].MatchTypeName = "周报"
- } else if v.ReportType == "two_week" {
- list[k].MatchTypeName = "双周报"
- } else if v.ReportType == "month" {
- list[k].MatchTypeName = "月报"
- } else if v.ReportType == "rddp" {
- //list[k].MatchTypeName = "日评"
- createdTime := utils.StrTimeToTime(v.CreatedTime)
- monthStr := createdTime.Format("01")
- dayStr := strconv.Itoa(createdTime.Day())
- if len(dayStr) == 1 {
- dayStr = "0" + dayStr
- }
- list[k].ResearchReportName += "(" + monthStr + dayStr + ")"
- }
- if v.StopTime != "--" {
- list[k].StopTime += "s"
- }
- }
- resp := new(company.ViewReportListResp)
- resp.List = list
- resp.Total = total
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 导出潜在用户
- // @Description 导出潜在用户接口
- // @Param ApplyMethod query int true "申请方式,0:全部,1:未申请,2:已付费客户申请试用,3:非客户申请试用"
- // @Param KeyWord query string true "搜索关键词"
- // @Success Ret=200 导出成功
- // @router /potential/user/export [get]
- func (this *CompanyUserController) PotentialUserExport() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- keyWord := this.GetString("KeyWord")
- applyMethod, _ := this.GetInt("ApplyMethod")
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- list := make([]*models.PotentialUserItem, 0)
- //管理员才让导出数据
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- var condition string
- var pars []interface{}
- if applyMethod > 0 {
- condition += ` AND apply_method=? `
- pars = append(pars, applyMethod-1)
- }
- if keyWord != "" {
- condition += ` AND (a.nick_name LIKE '%` + keyWord + `%' OR a.mobile LIKE '%` + keyWord + `%' OR a.email LIKE '%` + keyWord + `%') `
- }
- tmpList, err := models.GetPotentialUserListExport(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list = tmpList
- }
- dir, err := os.Executable()
- exPath := filepath.Dir(dir)
- downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- xlsxFile := xlsx.NewFile()
- if err != nil {
- br.Msg = "生成文件失败"
- br.ErrMsg = "生成文件失败"
- return
- }
- style := xlsx.NewStyle()
- alignment := xlsx.Alignment{
- Horizontal: "center",
- Vertical: "center",
- WrapText: true,
- }
- style.Alignment = alignment
- style.ApplyAlignment = true
- sheel, err := xlsxFile.AddSheet("客户数据")
- if err != nil {
- br.Msg = "新增Sheet失败"
- br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
- return
- }
- titleRow := sheel.AddRow()
- titleRow.AddCell().SetValue("姓名")
- titleRow.AddCell().SetValue("手机号")
- titleRow.AddCell().SetValue("邮箱")
- titleRow.AddCell().SetValue("注册时间")
- titleRow.AddCell().SetValue("公司")
- titleRow.AddCell().SetValue("申请类型")
- titleRow.AddCell().SetValue("累计阅读次数")
- titleRow.AddCell().SetValue("最后一次阅读时间")
- for _, v := range list {
- dataRow := sheel.AddRow()
- dataRow.SetHeight(20)
- dataRow.AddCell().SetString(v.RealName)
- dataRow.AddCell().SetString(v.Mobile)
- dataRow.AddCell().SetString(v.Email)
- dataRow.AddCell().SetString(v.CreatedTime)
- dataRow.AddCell().SetString(v.CompanyName)
- if v.ApplyMethod == 0 {
- dataRow.AddCell().SetString("未申请")
- } else if v.ApplyMethod == 1 {
- dataRow.AddCell().SetString("已付费客户申请试用")
- } else {
- dataRow.AddCell().SetString("非客户申请试用")
- }
- reportView, err := models.GetReportViewMaxTime(int(v.UserId))
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取GetReportViewMaxTime失败,Err:" + err.Error()
- return
- }
- if reportView.LastViewTime.After(v.LastViewTime) {
- v.LastViewTimeStr = v.LastViewTime.Format(utils.FormatDateTime)
- } else {
- v.LastViewTimeStr = v.LastViewTime.Format(utils.FormatDateTime)
- }
- v.ViewTotal += reportView.ViewTotal
- dataRow.AddCell().SetInt(v.ViewTotal)
- if v.LastViewTimeStr == "0001-01-01 00:00:00" {
- v.LastViewTimeStr = ""
- }
- dataRow.AddCell().SetString(v.LastViewTimeStr)
- }
- err = xlsxFile.Save(downLoadnFilePath)
- if err != nil {
- br.Msg = "保存文件失败"
- br.ErrMsg = "保存文件失败"
- return
- }
- randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
- downloadFileName := "潜在用户列表_" + randStr + ".xlsx"
- this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
- defer func() {
- os.Remove(downLoadnFilePath)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "导出成功"
- }
- // @Title 获取批量导入联系人数据
- // @Description 获取批量导入联系人数据
- // @Param File query file true "文件"
- // @Param CompanyId query file true "客户id"
- // @Success 200 {object} models.ImportListResp
- // @router /import/list [post]
- func (this *CompanyUserController) ImportList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- file, h, err := this.GetFile("File")
- if err != nil {
- br.Msg = "获取文件失败"
- br.ErrMsg = "获取文件失败,Err:" + err.Error()
- return
- }
- companyId, _ := this.GetInt("CompanyId")
- if companyId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "客户id为0"
- return
- }
- //产品id
- productId := services.GetProductId(sysUser.RoleTypeCode)
- //操作权限校验
- errMsg, err := checkOpCompanyUserByCompanyId(companyId, productId, sysUser.AdminId, sysUser.RoleTypeCode)
- if err != nil {
- br.Msg = "导入失败!" + errMsg
- br.ErrMsg = "导入失败,Err:" + err.Error()
- return
- }
- //userBusinessCardCount := 0
- //if productId > 0 {
- // tmpUserBusinessCardCount, err := models.GetCompanyUserBusinessCardCountByProductId(companyId, productId)
- // if err != nil {
- // br.Msg = "导入失败"
- // br.ErrMsg = "判断是否已经存在上传名片联系人失败,err:" + err.Error()
- // return
- // }
- // userBusinessCardCount = tmpUserBusinessCardCount
- //} else {
- // tmpUserBusinessCardCount, err := company.GetCompanyUserBusinessCardCount(companyId)
- // if err != nil {
- // br.Msg = "导入失败"
- // br.ErrMsg = "判断是否已经存在上传名片联系人失败,err:" + err.Error()
- // return
- // }
- // userBusinessCardCount = tmpUserBusinessCardCount
- //}
- //
- //if userBusinessCardCount <= 0 {
- // br.Msg = "请先至少添加一位名片联系人"
- // return
- //}
- //客户信息
- companyInfo, err := company.GetCompanyById(companyId)
- if err != nil {
- br.Msg = "导入异常"
- br.Msg = "导入异常:" + err.Error()
- return
- }
- uploadDir := "static/xls"
- err = os.MkdirAll(uploadDir, 766)
- if err != nil {
- br.Msg = "存储目录创建失败"
- br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
- return
- }
- path := uploadDir + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + h.Filename
- defer file.Close()
- err = this.SaveToFile("File", path)
- if err != nil {
- br.Msg = "文件保存失败"
- br.ErrMsg = "文件保存失败,Err:" + err.Error()
- return
- }
- xlFile, err := xlsx.OpenFile(path)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "打开文件失败,Err:" + err.Error() + ";path:" + path
- return
- }
- existUser := make([]*models.WxUser, 0)
- //excel中已经存在的数据,用来判断excel中是否存在相同手机号/邮箱,避免重复提交
- excelData := make(map[string]string)
- //重复数据
- repeatUser := make([]*models.WxUser, 0)
- // 遍历sheet页读取
- for _, sheet := range xlFile.Sheets {
- //遍历行读取
- maxRow := sheet.MaxRow
- fmt.Println("maxRow:", maxRow)
- fmt.Println("maxRow")
- for i := 0; i < maxRow; i++ {
- if i == 0 {
- row := sheet.Row(i)
- cells := row.Cells
- for k, cell := range cells {
- text := cell.String()
- if k == 0 {
- if text != "姓名" {
- br.Msg = "模板格式错误"
- br.ErrMsg = "模板格式错误,title:" + text
- return
- }
- }
- if k == 1 {
- if !strings.Contains(text, "性别") {
- br.Msg = "模板格式错误"
- br.ErrMsg = "模板格式错误,title:" + text
- return
- }
- }
- if k == 2 {
- if !strings.Contains(text, "国际区号(中国大陆填写:86)") {
- br.Msg = "模板格式错误"
- br.ErrMsg = "模板格式错误,title:" + text
- return
- }
- }
- if k == 3 {
- if !strings.Contains(text, "手机号") {
- br.Msg = "模板格式错误"
- br.ErrMsg = "模板格式错误,title:" + text
- return
- }
- }
- if k == 4 {
- if !strings.Contains(text, "邮箱") {
- br.Msg = "模板格式错误"
- br.ErrMsg = "模板格式错误,title:" + text
- return
- }
- }
- if k == 5 {
- if !strings.Contains(text, "是否决策人") {
- br.Msg = "模板格式错误"
- br.ErrMsg = "模板格式错误,title:" + text
- return
- }
- }
- if k == 6 {
- if !strings.Contains(text, "职位") {
- br.Msg = "模板格式错误"
- br.ErrMsg = "模板格式错误,title:" + text
- return
- }
- }
- if k == 7 {
- if !strings.Contains(text, "部门") {
- br.Msg = "模板格式错误"
- br.ErrMsg = "模板格式错误,title:" + text
- return
- }
- }
- }
- }
- if i >= 1 {
- row := sheet.Row(i)
- cells := row.Cells
- var userName, sex, countryCode, mobileOne, email, isMaker, position, departmentName string
- for k, cell := range cells {
- if k == 0 {
- userName = cell.String()
- }
- if k == 1 {
- sex = cell.String()
- }
- if k == 2 {
- countryCode = cell.String()
- }
- if k == 3 {
- mobileOne = cell.String()
- }
- if k == 4 {
- email = cell.String()
- }
- if k == 5 {
- isMaker = cell.String()
- }
- if k == 6 {
- position = cell.String()
- }
- if k == 7 {
- departmentName = cell.String()
- }
- }
- //移除空格
- mobileOne = utils.TrimStr(mobileOne)
- email = utils.TrimStr(email)
- //这些字段都没有的话,系统认为excel到底了
- if userName == "" && sex == "" && mobileOne == "" {
- break
- }
- if userName == "" {
- continue
- }
- //如果手机号或者邮箱都没有填写的情况下
- if mobileOne == "" && email == "" {
- continue
- }
- if mobileOne != "" && countryCode == "" {
- br.Msg = "导入数据中存在【国际区号】为空的联系人,请检查"
- return
- }
- //如果是权益,且是海外用户的情况下,那么手机号、邮箱有一个没有填写的情况下,那么退出当前循环
- if productId == 2 && companyInfo.RegionType == "海外" && (mobileOne == "" || email == "") {
- continue
- }
- item := new(models.WxUser)
- item.CountryCode = countryCode
- item.RealName = userName
- if sex == "男" {
- item.Sex = 1
- } else if sex == "女" {
- item.Sex = 2
- } else {
- item.Sex = 0
- }
- item.Mobile = mobileOne
- item.Email = email
- if isMaker == "是" {
- item.IsMaker = 1
- } else {
- item.IsMaker = 0
- }
- item.Position = position
- item.DepartmentName = departmentName
- if mobileOne != "" {
- if _, ok := excelData[mobileOne]; ok {
- //将用户插入其中,然后退出当前循环,进入下一循环
- repeatUser = append(repeatUser, item)
- continue
- }
- excelData[mobileOne] = ""
- }
- if email != "" {
- if _, ok := excelData[email]; ok {
- //将用户插入其中,然后退出当前循环,进入下一循环
- repeatUser = append(repeatUser, item)
- continue
- }
- excelData[mobileOne] = ""
- }
- //没问题数据
- existUser = append(existUser, item)
- }
- }
- }
- //defer func() {
- // os.Remove(path)
- //}()
- br.Msg = "获取成功"
- br.Ret = 200
- br.Success = true
- br.Data = models.ImportListResp{
- ValidUser: existUser,
- RepeatUser: repeatUser,
- }
- }
- // 需要更新的联系人数据实体
- type UpdateWxUser struct {
- OldWxUser models.WxUser `description:"旧的联系人数据orm实体(未变更前的)"`
- WxUser *models.WxUser `description:"联系人数据orm实体"`
- Cols []string `description:"需要修改的字段名切片"`
- }
- // @Title 批量导入联系人数据
- // @Description 批量导入联系人数据
- // @Param File query file true "文件"
- // @Param CompanyId query file true "客户id"
- // @Success 600 {object} []*company.CompanyUser
- // @Success 200 Ret=200 导入成功
- // @router /import [post]
- func (this *CompanyUserController) Import() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- file, h, err := this.GetFile("File")
- if err != nil {
- br.Msg = "获取文件失败"
- br.ErrMsg = "获取文件失败,Err:" + err.Error()
- return
- }
- companyId, _ := this.GetInt("CompanyId")
- if companyId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "客户id为0"
- return
- }
- //产品id
- productId := services.GetProductId(sysUser.RoleTypeCode)
- //操作权限校验
- errMsg, err := checkOpCompanyUserByCompanyId(companyId, productId, sysUser.AdminId, sysUser.RoleTypeCode)
- if err != nil {
- br.Msg = "导入失败!" + errMsg
- br.ErrMsg = "导入失败,Err:" + err.Error()
- return
- }
- //userBusinessCardCount := 0
- //if productId > 0 {
- // tmpUserBusinessCardCount, err := models.GetCompanyUserBusinessCardCountByProductId(companyId, productId)
- // if err != nil {
- // br.Msg = "导入失败"
- // br.ErrMsg = "判断是否已经存在上传名片联系人失败,err:" + err.Error()
- // return
- // }
- // userBusinessCardCount = tmpUserBusinessCardCount
- //} else {
- // tmpUserBusinessCardCount, err := company.GetCompanyUserBusinessCardCount(companyId)
- // if err != nil {
- // br.Msg = "导入失败"
- // br.ErrMsg = "判断是否已经存在上传名片联系人失败,err:" + err.Error()
- // return
- // }
- // userBusinessCardCount = tmpUserBusinessCardCount
- //}
- //
- //if userBusinessCardCount <= 0 {
- // br.Msg = "请先至少添加一位名片联系人"
- // return
- //}
- uploadDir := "static/xls"
- err = os.MkdirAll(uploadDir, 766)
- if err != nil {
- br.Msg = "存储目录创建失败"
- br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
- return
- }
- path := uploadDir + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + h.Filename
- defer file.Close()
- err = this.SaveToFile("File", path)
- if err != nil {
- br.Msg = "文件保存失败"
- br.ErrMsg = "文件保存失败,Err:" + err.Error()
- return
- }
- xlFile, err := xlsx.OpenFile(path)
- if err != nil {
- br.Msg = "文件导入失败"
- br.ErrMsg = "文件导入失败,Err:" + err.Error()
- return
- }
- //获取当前操作员产品权限列表
- companyProductList, productErr := getSysCompanyProductList(productId, companyId)
- if productErr != nil {
- br.Msg = "新增失败"
- br.ErrMsg = "新增失败,获取当前操作员产品权限异常,Err:" + productErr.Error()
- return
- }
- if companyProductList == nil {
- br.Msg = "新增失败"
- br.ErrMsg = "新增失败,获取当前操作员找不到产品权限"
- return
- }
- //客户信息
- companyInfo, err := company.GetCompanyById(companyId)
- if err != nil {
- br.Msg = "导入异常"
- br.Msg = "导入异常:" + err.Error()
- return
- }
- //已存在联系人的切片
- existUser := make([]*company.CompanyUser, 0)
- //待添加销售员与联系人关系的切片
- notRelationUser := make([]map[int]*company.CompanyUser, 0)
- //允许添加的联系人
- needAddUser := make([]*models.WxUserDetail, 0)
- //excel中已经存在的数据,用来判断excel中是否存在相同手机号/邮箱,避免重复提交
- excelData := make(map[string]string)
- //需要更新的数据实体切片
- updateWxUserSlice := make([]UpdateWxUser, 0)
- // 遍历sheet页读取
- for _, sheet := range xlFile.Sheets {
- //遍历行读取
- maxRow := sheet.MaxRow
- for i := 0; i < maxRow; i++ {
- if i == 0 {
- row := sheet.Row(i)
- cells := row.Cells
- for k, cell := range cells {
- text := cell.String()
- if k == 0 {
- if text != "姓名" {
- br.Msg = "模板格式错误"
- br.ErrMsg = "模板格式错误,title:" + text
- return
- }
- }
- if k == 1 {
- if !strings.Contains(text, "性别") {
- br.Msg = "模板格式错误"
- br.ErrMsg = "模板格式错误,title:" + text
- return
- }
- }
- if k == 2 {
- if !strings.Contains(text, "国际区号(中国大陆填写:86)") {
- br.Msg = "模板格式错误"
- br.ErrMsg = "模板格式错误,title:" + text
- return
- }
- }
- if k == 3 {
- if !strings.Contains(text, "手机号") {
- br.Msg = "模板格式错误"
- br.ErrMsg = "模板格式错误,title:" + text
- return
- }
- }
- if k == 4 {
- if !strings.Contains(text, "邮箱") {
- br.Msg = "模板格式错误"
- br.ErrMsg = "模板格式错误,title:" + text
- return
- }
- }
- if k == 5 {
- if !strings.Contains(text, "是否决策人") {
- br.Msg = "模板格式错误"
- br.ErrMsg = "模板格式错误,title:" + text
- return
- }
- }
- if k == 6 {
- if !strings.Contains(text, "职位") {
- br.Msg = "模板格式错误"
- br.ErrMsg = "模板格式错误,title:" + text
- return
- }
- }
- if k == 7 {
- if !strings.Contains(text, "部门") {
- br.Msg = "模板格式错误"
- br.ErrMsg = "模板格式错误,title:" + text
- return
- }
- }
- }
- }
- if i >= 1 {
- row := sheet.Row(i)
- cells := row.Cells
- var userName, sex, countryCode, mobileOne, email, isMaker, position, departmentName string
- for k, cell := range cells {
- if k == 0 {
- userName = cell.String()
- }
- if k == 1 {
- sex = cell.String()
- }
- if k == 2 {
- countryCode = strings.Replace(cell.String(), "+", "", -1)
- countryCode = strings.Replace(countryCode, "-", "", -1)
- countryCode = strings.Replace(countryCode, " ", "", -1)
- }
- if k == 3 {
- mobileOne = cell.String()
- }
- if k == 4 {
- email = cell.String()
- }
- if k == 5 {
- isMaker = cell.String()
- }
- if k == 6 {
- position = cell.String()
- }
- if k == 7 {
- departmentName = cell.String()
- }
- }
- //移除空格
- mobileOne = utils.TrimStr(mobileOne)
- email = utils.TrimStr(email)
- //这些字段都没有的话,系统认为excel到底了
- if userName == "" && sex == "" && mobileOne == "" {
- break
- }
- if userName == "" {
- br.Msg = "导入数据中存在【姓名】为空的联系人,请检查"
- return
- }
- if sex == "" {
- br.Msg = "导入数据中存在【性别】为空的联系人,请检查"
- return
- }
- if mobileOne != "" && countryCode == "" {
- br.Msg = "导入数据中存在【国际区号】为空的联系人,请检查"
- return
- }
- // 大陆区号校验手机号
- if mobileOne != "" && (countryCode == "86" || countryCode == "086" || countryCode == "+86" || countryCode == "+086") {
- if !utils.ValidateMobileFormatat(mobileOne) {
- br.Msg = "导入数据中存在【大陆手机号】格式有误的联系人,请检查"
- return
- }
- }
- //如果手机号或者邮箱都没有填写的情况下
- if mobileOne == "" && email == "" {
- continue
- }
- //如果是权益,且是海外用户的情况下,那么手机号、邮箱有一个没有填写的情况下,那么退出当前循环
- if productId == 2 && companyInfo.RegionType == "海外" && (mobileOne == "" || email == "") {
- continue
- }
- if isMaker == "" {
- br.Msg = "导入数据中存在【决策人】为空的联系人,请检查"
- return
- }
- item := new(models.WxUserDetail)
- item.RealName = userName
- if sex == "男" {
- item.Sex = 1
- } else if sex == "女" {
- item.Sex = 2
- } else {
- item.Sex = 0
- }
- item.Mobile = mobileOne
- item.Email = email
- if isMaker == "是" {
- item.IsMaker = 1
- } else {
- item.IsMaker = 0
- }
- item.Position = position
- item.DepartmentName = departmentName
- item.SellerRealName = companyProductList[0].SellerName
- item.CompanyName = companyProductList[0].CompanyName
- var mobileOneItem, emailItem *company.CompanyUser
- var mobileNotRelationUserMap, emailNotRelationUserMap map[int]*company.CompanyUser
- //手机号校验
- if mobileOne != "" {
- if _, ok := excelData[mobileOne]; ok {
- br.Msg = "excel表数据异常,存在重复的手机号:" + mobileOne + ",请检查excel表格数据"
- br.ErrMsg = "excel表数据异常,存在重复的手机号:" + mobileOne + ",请检查excel表格数据"
- return
- }
- excelData[mobileOne] = ""
- tmpMobileOneItem, err := company.GetUserCountByMobile(mobileOne)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "新增失败"
- br.ErrMsg = "判断手机号1是否存在,Err:" + err.Error()
- return
- }
- mobileOneItem = tmpMobileOneItem
- if mobileOneItem != nil {
- if mobileOneItem.UserId > 0 {
- hasMove := true //是否可移动
- //如果是大于 1 的客户,那么就是非潜在客户,需要去查询对应的销售
- if mobileOneItem.CompanyId > 1 {
- //获取联系人分组信息
- userSellerGroupInfoList, err := models.GetUserGroupSellersByUserId(int(mobileOneItem.UserId))
- //根据分组校验
- if err == nil && len(userSellerGroupInfoList) > 0 {
- sellerMap := make(map[int]string) //销售信息map
- sellerNameSlice := make([]string, 0) //销售姓名切片
- for _, v := range userSellerGroupInfoList {
- if v.Status != utils.COMPANY_STATUS_LOSE && v.Status != utils.COMPANY_STATUS_FOREVER && hasMove == true {
- hasMove = false
- }
- if _, ok := sellerMap[v.SellerId]; ok {
- continue
- }
- sellerMap[v.SellerId] = v.SellerRealName
- sellerNameSlice = append(sellerNameSlice, v.SellerRealName)
- }
- mobileOneItem.SellerRealName = strings.Join(sellerNameSlice, "/")
- }
- }
- item.SellerRealName = mobileOneItem.SellerRealName
- item.CompanyName = mobileOneItem.CompanyName
- //判断该联系人的 客户企业编号 是否与 当前客户编号 一致,如果不一致,那么将该联系人加入到已经存在的联系人列表中去,并终止当前循环,进入下一循环。
- if mobileOneItem.CompanyId != companyId {
- mobileOneItem.HasMove = hasMove //是否可移动
- if hasMove {
- if mobileOneItem.RealName != item.RealName {
- mobileOneItem.RealName = item.RealName
- }
- if mobileOneItem.DepartmentName != item.DepartmentName {
- mobileOneItem.DepartmentName = item.DepartmentName
- }
- if mobileOneItem.RealName != item.RealName {
- mobileOneItem.RealName = item.RealName
- }
- }
- mobileOneItem.CountryCode = countryCode
- existUser = append(existUser, mobileOneItem)
- continue
- }
- //判断该用户与当前账号是否存在关系,如果没有关系,那么直接返回
- notRelationUserMap, checkErr := checkProductListUser(*item, mobileOneItem, companyProductList)
- //sql异常
- if checkErr != nil && checkErr.Error() != utils.ErrNoRow() {
- br.Msg = "新增失败"
- br.ErrMsg = "新增失败,Err:" + checkErr.Error()
- return
- }
- mobileNotRelationUserMap = notRelationUserMap
- }
- }
- }
- //邮箱校验
- if email != "" {
- if _, ok := excelData[email]; ok {
- br.Msg = "excel表数据异常,存在重复的邮箱:" + email + ",请检查excel表格数据"
- br.ErrMsg = "excel表数据异常,存在重复的邮箱:" + email + ",请检查excel表格数据"
- return
- }
- excelData[email] = ""
- tmpEmailItem, err := company.CheckCompanyUserCountByEmail(email)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "新增失败"
- br.ErrMsg = "新增失败,Err:" + err.Error()
- return
- }
- emailItem = tmpEmailItem
- if emailItem != nil {
- if emailItem.UserId > 0 {
- hasMove := true //是否可移动
- //如果是大于 1 的客户,那么就是非潜在客户,需要去查询对应的销售
- if emailItem.CompanyId > 1 {
- //获取联系人分组信息
- userSellerGroupInfoList, err := models.GetUserGroupSellersByUserId(int(emailItem.UserId))
- //根据分组校验
- if err == nil && len(userSellerGroupInfoList) > 0 {
- sellerMap := make(map[int]string) //销售信息map
- sellerNameSlice := make([]string, 0) //销售姓名切片
- for _, v := range userSellerGroupInfoList {
- if v.Status != utils.COMPANY_STATUS_LOSE && v.Status != utils.COMPANY_STATUS_FOREVER && hasMove == true {
- hasMove = false
- }
- if _, ok := sellerMap[v.SellerId]; ok {
- continue
- }
- sellerMap[v.SellerId] = v.SellerRealName
- sellerNameSlice = append(sellerNameSlice, v.SellerRealName)
- }
- emailItem.SellerRealName = strings.Join(sellerNameSlice, "/")
- }
- }
- item.SellerRealName = emailItem.SellerRealName
- item.CompanyName = emailItem.CompanyName
- //判断该联系人的 客户企业编号 是否与 当前客户编号 一致,如果不一致,那么将该联系人加入到已经存在的联系人列表中去,并终止当前循环,进入下一循环。
- if emailItem.CompanyId != companyId {
- emailItem.HasMove = hasMove //是否可移动
- if hasMove {
- if emailItem.RealName != item.RealName {
- emailItem.RealName = item.RealName
- }
- if emailItem.DepartmentName != item.DepartmentName {
- emailItem.DepartmentName = item.DepartmentName
- }
- if emailItem.RealName != item.RealName {
- emailItem.RealName = item.RealName
- }
- }
- emailItem.CountryCode = countryCode
- existUser = append(existUser, emailItem)
- continue
- }
- //判断该用户与当前账号是否存在关系,如果没有关系,那么直接返回
- notRelationUserMap, checkErr := checkProductListUser(*item, emailItem, companyProductList)
- //sql异常
- if checkErr != nil && checkErr.Error() != utils.ErrNoRow() {
- br.Msg = "新增失败"
- br.ErrMsg = "新增失败,Err:" + checkErr.Error()
- return
- }
- //判断该用户与销售是否存在关系,如果不存在,那么加入到 待添加关系 的切片中
- emailNotRelationUserMap = notRelationUserMap
- }
- }
- }
- //如果系统已存在该联系人,那么逻辑处理后退出当前循环,进入下一循环
- if mobileOneItem != nil || emailItem != nil {
- //如果既存在该手机号联系人,也存在该邮箱联系人;那么需要去判断 这 两个 联系人 是不是同一个,
- //如果不是同一个联系人的话,那么只添加对应的关系,不去修改对应的数据
- var wxUserItem *models.WxUser
- var oldTmpWxUserItem models.WxUser
- cols := make([]string, 0)
- if mobileOneItem != nil && emailItem != nil {
- //如果两个联系人 不是 同一个
- if mobileOneItem.UserId != emailItem.UserId {
- notRelationUser = append(notRelationUser, mobileNotRelationUserMap, emailNotRelationUserMap)
- //wxUserItem = mobileOneItem
- } else {
- //如果两个联系人 是 同一个
- notRelationUser = append(notRelationUser, mobileNotRelationUserMap)
- tmpWxUserItem, err := models.GetWxUserByUserId(int(mobileOneItem.UserId))
- if err != nil {
- br.Msg = "导入失败"
- br.ErrMsg = "查询联系人信息失败,Err:" + err.Error()
- return
- }
- oldTmpWxUserItem := *tmpWxUserItem
- if tmpWxUserItem.IsMaker != item.IsMaker {
- tmpWxUserItem.IsMaker = item.IsMaker
- cols = append(cols, "IsMaker")
- }
- if tmpWxUserItem.DepartmentName != item.DepartmentName {
- tmpWxUserItem.DepartmentName = item.DepartmentName
- cols = append(cols, "DepartmentName")
- }
- if tmpWxUserItem.RealName != item.RealName {
- tmpWxUserItem.RealName = item.RealName
- cols = append(cols, "RealName")
- }
- if len(cols) > 0 {
- updateWxUser := UpdateWxUser{
- OldWxUser: oldTmpWxUserItem,
- WxUser: tmpWxUserItem,
- Cols: cols,
- }
- updateWxUserSlice = append(updateWxUserSlice, updateWxUser)
- }
- wxUserItem = tmpWxUserItem
- }
- } else if mobileOneItem != nil {
- //如果只存在 手机号联系人
- notRelationUser = append(notRelationUser, mobileNotRelationUserMap)
- //获取联系人orm实体类
- tmpWxUserItem, err := models.GetWxUserByUserId(int(mobileOneItem.UserId))
- if err != nil {
- br.Msg = "导入失败"
- br.ErrMsg = "查询联系人信息失败,Err:" + err.Error()
- return
- }
- oldTmpWxUserItem = *tmpWxUserItem
- if tmpWxUserItem.IsMaker != item.IsMaker {
- tmpWxUserItem.IsMaker = item.IsMaker
- cols = append(cols, "IsMaker")
- }
- if tmpWxUserItem.DepartmentName != item.DepartmentName && item.DepartmentName != "" {
- tmpWxUserItem.DepartmentName = item.DepartmentName
- cols = append(cols, "DepartmentName")
- }
- if tmpWxUserItem.RealName != item.RealName && item.RealName != "" {
- tmpWxUserItem.RealName = item.RealName
- cols = append(cols, "RealName")
- }
- if tmpWxUserItem.Email != item.Email && item.Email != "" {
- tmpWxUserItem.Email = item.Email
- cols = append(cols, "Email")
- }
- wxUserItem = tmpWxUserItem
- } else if emailItem != nil {
- //如果只存在 邮箱联系人
- notRelationUser = append(notRelationUser, emailNotRelationUserMap)
- //获取联系人orm实体类
- tmpWxUserItem, err := models.GetWxUserByUserId(int(emailItem.UserId))
- if err != nil {
- br.Msg = "导入失败"
- br.ErrMsg = "查询联系人信息失败,Err:" + err.Error()
- return
- }
- oldTmpWxUserItem = *tmpWxUserItem
- if tmpWxUserItem.IsMaker != item.IsMaker {
- tmpWxUserItem.IsMaker = item.IsMaker
- cols = append(cols, "IsMaker")
- }
- if tmpWxUserItem.DepartmentName != item.DepartmentName && item.DepartmentName != "" {
- tmpWxUserItem.DepartmentName = item.DepartmentName
- cols = append(cols, "DepartmentName")
- }
- if tmpWxUserItem.RealName != item.RealName && item.RealName != "" {
- tmpWxUserItem.RealName = item.RealName
- cols = append(cols, "RealName")
- }
- if tmpWxUserItem.Email != item.Email && item.Email != "" {
- tmpWxUserItem.Email = item.Email
- cols = append(cols, "Email")
- }
- wxUserItem = tmpWxUserItem
- }
- //如果变更字段数量大于0
- if len(cols) > 0 {
- updateWxUser := UpdateWxUser{
- OldWxUser: oldTmpWxUserItem,
- WxUser: wxUserItem,
- Cols: cols,
- }
- updateWxUserSlice = append(updateWxUserSlice, updateWxUser)
- }
- continue
- }
- //确实系统中不存在该用户
- item.CountryCode = countryCode
- needAddUser = append(needAddUser, item)
- }
- }
- }
- fmt.Println("表格中用户与系统中存在用户没有冲突")
- //如果表格中用户与系统中存在用户 没有冲突,那么继续执行
- for _, user := range needAddUser {
- if user.RealName != "" && (user.Mobile != "" || user.Email != "") {
- userData := new(models.WxUser)
- userData.RealName = user.RealName
- userData.Sex = user.Sex
- userData.Mobile = user.Mobile
- userData.CountryCode = user.CountryCode
- userData.OutboundMobile = user.Mobile
- userData.OutboundCountryCode = user.CountryCode
- userData.Email = user.Email
- userData.Position = user.Position
- userData.IsMaker = user.IsMaker
- userData.CompanyId = companyId
- userData.DepartmentName = user.DepartmentName
- userData.CountryCode = user.CountryCode
- //判断该手机号、邮箱是否已经添加,如果已经添加,那么就不再添加
- var key string
- if user.Mobile != "" {
- key = "wx_user:mobile:" + userData.Mobile
- } else {
- key = "wx_user:email:" + userData.Email
- }
- isHas := utils.Rc.IsExist(key)
- if isHas == false {
- newId, err := models.AddWxUser(userData)
- userData.UserId = newId
- if err != nil {
- br.Msg = "导入失败"
- br.ErrMsg = "导入失败,Err:" + err.Error()
- return
- }
- //添加联系人与销售员的关系
- for _, companyProduct := range companyProductList {
- models.AddUserSellerRelation(newId, companyProduct.CompanyId, companyProduct.SellerId, companyProduct.ProductId, companyProduct.SellerName, user.Mobile, user.Email)
- }
- //联系人信息
- userInfo, _ := json.Marshal(userData)
- go services.AddWxUserOpLog(company.WxUserOpLog{
- LogType: "import",
- UserId: int(userData.UserId),
- CompanyId: userData.CompanyId,
- Mobile: userData.Mobile,
- Email: userData.Email,
- OriginalUserInfo: "",
- UserInfo: string(userInfo),
- OriginalUserSellerInfo: "",
- UserSellerInfo: "",
- OpUserId: sysUser.AdminId,
- OpUserName: sysUser.RealName,
- CreateTime: time.Now(),
- })
- }
- }
- }
- //添加已经存在的联系人与销售员关系
- fmt.Println("开始添加已经存在的联系人与销售员关系")
- for _, notRelationUserMap := range notRelationUser {
- if item, ok := notRelationUserMap[1]; ok {
- //添加联系人与销售员的关系
- mobileOne := item.Mobile
- mobileTwo := item.MobileTwo
- email := item.Email
- businessCardUrl := item.BusinessCardUrl
- //对老数据做新增字段处理
- _ = company.EditCompanyUserContact(item.UserId, mobileOne, mobileTwo, email, businessCardUrl)
- models.AddUserSellerRelation(item.UserId, item.CompanyId, item.SellerId, 1, item.SellerName, item.Mobile, item.Email)
- }
- if item, ok := notRelationUserMap[2]; ok {
- //添加联系人与销售员的关系
- mobileOne := item.Mobile
- mobileTwo := item.MobileTwo
- email := item.Email
- businessCardUrl := item.BusinessCardUrl
- //对老数据做新增字段处理
- _ = company.EditCompanyUserContact(item.UserId, mobileOne, mobileTwo, email, businessCardUrl)
- models.AddUserSellerRelation(item.UserId, item.CompanyId, item.SellerId, 2, item.SellerName, item.Mobile, item.Email)
- }
- }
- fmt.Println("开始更新联系人信息")
- for _, updateWxUser := range updateWxUserSlice {
- _ = updateWxUser.WxUser.Update(updateWxUser.Cols)
- //联系人信息
- originalUserInfo, _ := json.Marshal(updateWxUser.OldWxUser)
- userInfo, _ := json.Marshal(updateWxUser.WxUser)
- go services.AddWxUserOpLog(company.WxUserOpLog{
- LogType: "import",
- UserId: int(updateWxUser.WxUser.UserId),
- CompanyId: updateWxUser.WxUser.CompanyId,
- Mobile: updateWxUser.WxUser.Mobile,
- Email: updateWxUser.WxUser.Email,
- OriginalUserInfo: string(originalUserInfo),
- UserInfo: string(userInfo),
- OriginalUserSellerInfo: "",
- UserSellerInfo: "",
- OpUserId: sysUser.AdminId,
- OpUserName: sysUser.RealName,
- CreateTime: time.Now(),
- })
- }
- defer func() {
- os.Remove(path)
- }()
- if len(existUser) > 0 {
- br.Ret = 600
- br.Msg = "系统中已存在用户"
- br.IsSendEmail = false
- br.Data = existUser
- return
- }
- //更新客户最近阅读次数以及最近阅读时间
- go services.ModifyCompanyProductLastViewData([]int{companyId})
- br.Msg = "导入成功"
- br.Ret = 200
- br.Success = true
- }
- // @Title 客户的联系人导出
- // @Description 客户的联系人导出接口
- // @Param CompanyId query int true "公司id,必填"
- // @Param KeyWord query string true "搜索关键词"
- // @Success 200 {object} company.CompanyUserListResp
- // @router /user/exportByCompanyId [get]
- func (this *CompanyUserController) Export() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- companyId, _ := this.GetInt("CompanyId")
- keyWord := utils.TrimStr(this.GetString("KeyWord"))
- if companyId <= 0 {
- br.Msg = "请选择客户"
- br.ErrMsg = "客户参数错误"
- return
- }
- var startSize int
- var condition string
- var pars []interface{}
- if keyWord != "" {
- condition += ` AND (a.real_name LIKE '%` + keyWord + `%' OR a.mobile LIKE '%` + keyWord + `%' OR a.email LIKE '%` + keyWord + `%') `
- }
- //非管理员,那么只能看到该产品下的联系人
- if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
- productId := services.GetProductId(sysUser.RoleTypeCode)
- condition += ` AND b.product_id = ? `
- pars = append(pars, productId)
- }
- list, err := company.GetCompanyUserListV2(condition, pars, companyId, startSize, 100000)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- //获取企业客户信息
- companyInfo, err := company.GetCompanyById(companyId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- lenList := len(list)
- if lenList > 0 {
- userIdSlice := make([]string, 0)
- mobilesSlice := make([]string, 0)
- emailsSlice := make([]string, 0)
- for _, v := range list {
- userIdSlice = append(userIdSlice, strconv.Itoa(int(v.UserId)))
- if v.Mobile != "" {
- mobilesSlice = append(mobilesSlice, v.Mobile)
- } else if v.Email != "" {
- emailsSlice = append(emailsSlice, v.Email)
- }
- }
- //用户浏览数据
- userIdStr := strings.Join(userIdSlice, ",")
- mobileStr := strings.Join(mobilesSlice, "','")
- mobileStr = "'" + mobileStr + "'"
- emailStr := strings.Join(emailsSlice, "','")
- emailStr = "'" + emailStr + "'"
- //userViewTotalList, _ := models.GetCountUserViewHistoryByUserIds(userIdStr)
- //userViewTotalMap := make(map[int]*models.UserViewTotalSlice)
- //for _, userView := range userViewTotalList {
- // userViewTotalMap[userView.UserId] = userView
- //}
- //用户日评浏览数据
- //userReportViewTotalList, _ := models.GetReportViewMaxTimeByUserIds(userIdStr)
- //userReportViewTotalMap := make(map[int]*models.ReportViewRecord)
- //for _, userReportView := range userReportViewTotalList {
- // userReportViewTotalMap[userReportView.UserId] = userReportView
- //}
- //报告统计删除晨报部分统计加入每日资讯 2021-4-9
- //手机号
- userViewMobileTotalMap := make(map[string]*models.UserViewMobileTotalSlice)
- userReportViewMobileTotalMap := make(map[string]*models.ReportViewMobileRecord)
- userAdvisoryViewMobileTotalMap := make(map[string]*advisory.UserViewMobileTotalSlice)
- userCygxArticleHistoryRecordViewMobileTotalMap := make(map[string]*models.UserViewMobileTotalSlice)
- if len(mobilesSlice) > 0 {
- //用户浏览数据
- userViewMobileTotalList, _ := models.GetCountUserViewHistoryByMobiles(mobileStr)
- for _, userViewMobile := range userViewMobileTotalList {
- userViewMobileTotalMap[userViewMobile.Mobile] = userViewMobile
- }
- //每日点评手机号数据
- userReportViewMobileTotalList, _ := models.GetReportViewMaxTimeByMobiles(mobileStr)
- for _, userReportViewMobile := range userReportViewMobileTotalList {
- userReportViewMobileTotalMap[userReportViewMobile.Mobile] = userReportViewMobile
- }
- //每日资讯
- userAdvisoryViewMobileTotalList, _ := advisory.GetCountUserViewHistoryByMobiles(mobileStr)
- //fmt.Println(userAdvisoryViewMobileTotalList)
- for _, userAdvisoryViewMobile := range userAdvisoryViewMobileTotalList {
- userAdvisoryViewMobileTotalMap[userAdvisoryViewMobile.Mobile] = userAdvisoryViewMobile
- }
- //查研观向
- userCygxArticleHistoryRecordViewMobileTotalList, _ := models.GetCountCygxArticleHistoryRecordByMobiles(mobileStr)
- for _, userCygxArticleHistoryRecordViewMobile := range userCygxArticleHistoryRecordViewMobileTotalList {
- userCygxArticleHistoryRecordViewMobileTotalMap[userCygxArticleHistoryRecordViewMobile.Mobile] = userCygxArticleHistoryRecordViewMobile
- }
- }
- //邮箱
- userViewEmailTotalMap := make(map[string]*models.UserViewEmailTotalSlice)
- userReportViewEmailTotalMap := make(map[string]*models.ReportViewEmailRecord)
- userAdvisoryViewEmailTotalMap := make(map[string]*advisory.UserViewEmailTotalSlice)
- userCygxViewEmailTotalMap := make(map[string]*models.UserViewEmailTotalSlice)
- if len(emailsSlice) > 0 {
- //用户浏览数据
- userViewEmailTotalList, _ := models.GetCountUserViewHistoryByEmails(emailStr)
- for _, userViewEmail := range userViewEmailTotalList {
- userViewEmailTotalMap[userViewEmail.Email] = userViewEmail
- }
- //每日点评手机号数据
- userReportViewEmailTotalList, _ := models.GetReportViewMaxTimeByEmails(emailStr)
- for _, userReportViewEmail := range userReportViewEmailTotalList {
- userReportViewEmailTotalMap[userReportViewEmail.Email] = userReportViewEmail
- }
- //每日资讯
- userAdvisoryViewEmailTotalList, _ := advisory.GetCountUserViewHistoryByEmails(emailStr)
- for _, userAdvisoryViewEmail := range userAdvisoryViewEmailTotalList {
- userAdvisoryViewEmailTotalMap[userAdvisoryViewEmail.Email] = userAdvisoryViewEmail
- }
- //查研观向
- userCygxViewEmailTotalList, _ := models.GetCountCygxArticleHistoryRecordByEmails(emailStr)
- for _, userCygxReportViewEmail := range userCygxViewEmailTotalList {
- userCygxViewEmailTotalMap[userCygxReportViewEmail.Email] = userCygxReportViewEmail
- }
- }
- //获取联系人关联产品的条数
- //userSellerRelationTotalSlice, err := models.GetUserSellerRelationCountByUserIds(userIdStr)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取联系人与销售员信息失败,Err:" + err.Error()
- // return
- //}
- //userSellerRelationTotalMap := make(map[int]*models.UserSellerRelationSlice)
- //for _, userSellerRelationTotal := range userSellerRelationTotalSlice {
- // userSellerRelationTotalMap[userSellerRelationTotal.UserId] = userSellerRelationTotal
- //}
- userRecordRegisterMap := make(map[int]time.Time)
- if len(userIdSlice) > 0 {
- //用户绑定注册数据
- userRecordRegisterList, _ := models.GetUserRecordRegisterByUserIds(userIdStr)
- for _, userRecordRegister := range userRecordRegisterList {
- userRecordRegisterMap[userRecordRegister.UserId] = userRecordRegister.CreateTime
- }
- }
- for i := 0; i < lenList; i++ {
- item := list[i]
- //企业名称
- list[i].CompanyName = companyInfo.CompanyName
- //手机号用户累计浏览次数
- if userView, ok := userViewMobileTotalMap[item.Mobile]; ok {
- list[i].ViewTotal += userView.Total
- if userView.CreatedTime.After(list[i].LastViewTime) {
- list[i].LastViewTime = userView.CreatedTime
- list[i].LastViewTimeStr = userView.CreatedTime.Format(utils.FormatDateTime)
- }
- }
- //邮箱用户累计浏览次数
- if userView, ok := userViewEmailTotalMap[item.Email]; ok {
- //总共浏览的报表数据需要调整为(手机号用户浏览晨报数+邮箱号用户浏览晨报数)
- list[i].ViewTotal += userView.Total
- if userView.CreatedTime.After(list[i].LastViewTime) {
- list[i].LastViewTime = userView.CreatedTime
- list[i].LastViewTimeStr = userView.CreatedTime.Format(utils.FormatDateTime)
- }
- }
- if item.OpenId != "" {
- list[i].IsRegister = true
- } else {
- if item.RegisterPlatform == 2 {
- if item.Mobile != "" || item.Email != "" {
- list[i].IsRegister = true
- }
- } else if item.RegisterTime != "" {
- list[i].IsRegister = true
- } else {
- list[i].IsRegister = false
- }
- }
- //如果存在手机号用户日评数据,那么需要做处理
- if reportView, ok := userReportViewMobileTotalMap[item.Mobile]; ok {
- //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
- if reportView.LastViewTime.After(list[i].LastViewTime) {
- list[i].LastViewTime = reportView.LastViewTime
- list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
- }
- //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
- list[i].ViewTotal += reportView.ViewTotal
- }
- //如果存在手机号用户日评数据,那么需要做处理
- if reportView, ok := userReportViewEmailTotalMap[item.Email]; ok {
- //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
- if reportView.LastViewTime.After(list[i].LastViewTime) {
- list[i].LastViewTime = reportView.LastViewTime
- list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
- }
- //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
- list[i].ViewTotal += reportView.ViewTotal
- }
- //如果存在手机号用户每日资讯,那么需要做处理
- if advisoryView, ok := userAdvisoryViewMobileTotalMap[item.Mobile]; ok {
- //fmt.Println("蝴蝶眨几次眼睛")
- //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
- if advisoryView.CreatedTime.After(list[i].LastViewTime) {
- list[i].LastViewTime = advisoryView.CreatedTime
- list[i].LastViewTimeStr = advisoryView.CreatedTime.Format(utils.FormatDateTime)
- }
- //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数)
- list[i].ViewTotal += advisoryView.Total
- }
- //如果存在邮箱号用户每日资讯,那么需要做处理
- if advisoryView, ok := userAdvisoryViewEmailTotalMap[item.Email]; ok {
- //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
- if advisoryView.CreatedTime.After(list[i].LastViewTime) {
- list[i].LastViewTime = advisoryView.CreatedTime
- list[i].LastViewTimeStr = advisoryView.CreatedTime.Format(utils.FormatDateTime)
- }
- //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数)
- list[i].ViewTotal += advisoryView.Total
- }
- //如果存在手机号用户查研观向,那么需要做处理
- if cygxView, ok := userCygxArticleHistoryRecordViewMobileTotalMap[item.Mobile]; ok {
- //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
- if cygxView.CreatedTime.After(list[i].LastViewTime) {
- list[i].LastViewTime = cygxView.CreatedTime
- list[i].LastViewTimeStr = cygxView.CreatedTime.Format(utils.FormatDateTime)
- }
- //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数+查研观向)
- list[i].ViewTotal += cygxView.Total
- }
- //如果存在邮箱号用户查研观向,那么需要做处理
- if cygxView, ok := userCygxViewEmailTotalMap[item.Email]; ok {
- //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
- if cygxView.CreatedTime.After(list[i].LastViewTime) {
- list[i].LastViewTime = cygxView.CreatedTime
- list[i].LastViewTimeStr = cygxView.CreatedTime.Format(utils.FormatDateTime)
- }
- //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数+查研观向)
- list[i].ViewTotal += cygxView.Total
- }
- /*if reportView, ok := userReportViewTotalMap[int(item.UserId)]; ok {
- //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
- if reportView.LastViewTime.After(list[i].LastViewTime) {
- list[i].LastViewTime = reportView.LastViewTime
- list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
- }
- //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
- list[i].ViewTotal += reportView.ViewTotal
- }*/
- //如果有绑定数据,那么将数据返回对应的注册绑定数据
- if _, ok := userRecordRegisterMap[int(item.UserId)]; ok {
- list[i].IsRegister = true
- //list[i].RegisterTime = userRecordRegisterTime.Format(utils.FormatDateTime)
- }
- //是否共享联系人
- //if userSellerRelationTotal, ok := userSellerRelationTotalMap[int(item.UserId)]; ok {
- // //条数大于1,代表这是共享联系人
- // if userSellerRelationTotal.Total > 1 {
- // list[i].IsShared = true
- // }
- //}
- }
- }
- dir, err := os.Executable()
- exPath := filepath.Dir(dir)
- downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- xlsxFile := xlsx.NewFile()
- if err != nil {
- br.Msg = "生成文件失败"
- br.ErrMsg = "生成文件失败"
- return
- }
- style := xlsx.NewStyle()
- alignment := xlsx.Alignment{
- Horizontal: "center",
- Vertical: "center",
- WrapText: true,
- }
- style.Alignment = alignment
- style.ApplyAlignment = true
- sheel, err := xlsxFile.AddSheet("联系人数据")
- if err != nil {
- br.Msg = "新增Sheet失败"
- br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
- return
- }
- sheel.SetColWidth(0, 0, 18)
- sheel.SetColWidth(1, 2, 24)
- sheel.SetColWidth(3, 3, 20)
- sheel.SetColWidth(4, 4, 40)
- titleRow := sheel.AddRow()
- cellName := titleRow.AddCell()
- cellName.SetStyle(style)
- cellName.SetValue("姓名")
- cellMobile := titleRow.AddCell()
- cellMobile.SetStyle(style)
- cellMobile.SetValue("手机号")
- cellEmail := titleRow.AddCell()
- cellEmail.SetStyle(style)
- cellEmail.SetValue("邮箱")
- cellMark := titleRow.AddCell()
- cellMark.SetStyle(style)
- cellMark.SetValue("是否决策人")
- cellCompanyName := titleRow.AddCell()
- cellCompanyName.SetStyle(style)
- cellCompanyName.SetValue("客户名称")
- for _, v := range list {
- dataRow := sheel.AddRow()
- dataRow.SetHeight(20)
- isMark := "否"
- if v.IsMaker == 1 {
- isMark = "是"
- }
- cellDataName := dataRow.AddCell()
- cellDataName.SetStyle(style)
- cellDataName.SetValue(v.RealName)
- cellDataMobile := dataRow.AddCell()
- cellDataMobile.SetStyle(style)
- cellDataMobile.SetValue(v.Mobile)
- cellDataEmail := dataRow.AddCell()
- cellDataEmail.SetStyle(style)
- cellDataEmail.SetValue(v.Email)
- cellDataMark := dataRow.AddCell()
- cellDataMark.SetStyle(style)
- cellDataMark.SetValue(isMark)
- cellDataCompanyName := dataRow.AddCell()
- cellDataCompanyName.SetStyle(style)
- cellDataCompanyName.SetValue(companyInfo.CompanyName)
- }
- err = xlsxFile.Save(downLoadnFilePath)
- if err != nil {
- br.Msg = "保存文件失败"
- br.ErrMsg = "保存文件失败"
- return
- }
- randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
- downloadFileName := "联系人列表_" + randStr + ".xlsx"
- this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
- defer func() {
- os.Remove(downLoadnFilePath)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "导出成功"
- }
- // 检测产品
- func checkProductListUser(item models.WxUserDetail, companyUser *company.CompanyUser, companyProductList []*company.CompanyProduct) (notRelationUserMap map[int]*company.CompanyUser, err error) {
- notRelationUserMap = make(map[int]*company.CompanyUser)
- //判断该用户与当前账号是否存在关系,如果没有关系,那么直接返回
- for _, companyProduct := range companyProductList {
- _, relationErr := models.GetUserSellerRelation(companyUser.UserId, companyProduct.SellerId)
- //找到数据了
- if relationErr == nil {
- continue
- }
- //sql异常
- if relationErr.Error() != utils.ErrNoRow() {
- err = relationErr
- return
- }
- //没找到数据,不存在关系
- //如果不存在关系,那么直接添加关系就好了,其他操作不做
- if relationErr.Error() == utils.ErrNoRow() {
- if item.Mobile != "" && companyUser.Mobile == "" {
- companyUser.Mobile = strings.Replace(item.Mobile, " ", "", -1)
- }
- if item.Email != "" && companyUser.Email == "" {
- companyUser.Email = strings.Replace(companyUser.Email, " ", "", -1)
- }
- companyUser.SellerId = companyProduct.SellerId
- companyUser.SellerName = companyProduct.SellerName
- companyUser.DepartmentId = companyProduct.DepartmentId
- companyUser.GroupId = companyProduct.GroupId
- notRelationUserMap[companyProduct.ProductId] = companyUser
- }
- }
- return
- }
- // @Title 下载模板
- // @Description 下载模板
- // @Success 200
- // @router /template [get]
- func (this *CompanyUserController) TemplateDownload() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- this.Ctx.Output.Download("./static/导入联系人模板.xlsx", "导入联系人模板.xlsx")
- br.Ret = 200
- br.Success = true
- br.Msg = "下载成功"
- }
- //百度
- //func init() {
- // fmt.Println("start")
- // businessCardUrl := `https://hongze.oss-accelerate.aliyuncs.com/static/images/202101/20210111/wB3ELOuH8AxTvrIDXHaFTn9Z0WXB.jpg`
- // services.GetBdGeneralBasic(businessCardUrl)
- // fmt.Println("end")
- //}
- //阿里云
- //func init() {
- // fmt.Println("start")
- // businessCardUrl := `https://hongze.oss-accelerate.aliyuncs.com/static/images/202101/20210111/wB3ELOuH8AxTvrIDXHaFTn9Z0WXB.jpg`
- // aliyunResult, err := services.AliyunBusinessCardOcr(businessCardUrl)
- //
- // if err != nil {
- // fmt.Println("line 1026")
- // return
- // }
- // if !aliyunResult.Success {
- // fmt.Println("line 1026")
- // return
- // }
- //
- // mobileStr := strings.Join(aliyunResult.TelCell, ",")
- // mobileOne:="18366208402"
- // if strings.Contains(mobileStr, mobileOne) {
- // fmt.Println("true")
- // } else {
- // fmt.Println("false")
- // }
- // fmt.Println("end")
- //}
- // 获取是否拥有操作权限
- func checkOpCompanyUserByUserId(userId, productId, opId int, roleTypeCode string) (errMsg string, err error) {
- userInfo, userErr := models.GetWxUserByUserId(userId)
- if userErr != nil {
- errMsg = "查询用户信息失败"
- err = errors.New("查询用户信息失败,Err:" + userErr.Error())
- return
- }
- //产品权限
- //获取当前操作员产品权限
- companyProductList, productErr := getSysCompanyProductList(productId, userInfo.CompanyId)
- if productErr != nil {
- errMsg = "获取当前操作员产品权限异常"
- err = errors.New("删除失败,获取当前操作员产品权限异常,Err:" + productErr.Error())
- return
- }
- if companyProductList == nil {
- errMsg = "删除失败"
- err = errors.New("删除失败,获取当前操作员找不到产品权限")
- return
- }
- //操作权限校验
- for _, v := range companyProductList {
- companyUserStatus := services.CheckCompanyUserButton(roleTypeCode, v.SellerId, opId, v.ProductId, v.ShareSellerId, v.Status)
- if companyUserStatus == false {
- errMsg = "没有操作权限"
- err = errors.New("没有操作权限")
- return
- }
- }
- return
- }
- // 获取是否拥有操作权限
- func checkOpCompanyUserByCompanyId(companyId, productId, opId int, roleTypeCode string) (errMsg string, err error) {
- //获取当前操作员产品权限
- companyProductList, productErr := getSysCompanyProductList(productId, companyId)
- if productErr != nil {
- errMsg = "获取当前操作员产品权限异常"
- err = errors.New("删除失败,获取当前操作员产品权限异常,Err:" + productErr.Error())
- return
- }
- if companyProductList == nil {
- errMsg = "删除失败"
- err = errors.New("删除失败,获取当前操作员找不到产品权限")
- return
- }
- //操作权限校验
- for _, v := range companyProductList {
- companyUserStatus := services.CheckCompanyUserButton(roleTypeCode, v.SellerId, opId, v.ProductId, v.ShareSellerId, v.Status)
- if companyUserStatus == false {
- errMsg = "没有操作权限"
- err = errors.New("没有操作权限")
- return
- }
- }
- return
- }
- // @Title FICC申请单-移动潜在用户
- // @Description FICC申请单移动潜在用户接口
- // @Param request body models.ApplyRecordPotentialUserMoveReq true "type json string"
- // @Success Ret=200 移动成功
- // @router /potential/user/moveByApplyRecord [post]
- func (this *CompanyController) ApplyRecordPotentialUserMove() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req models.ApplyRecordPotentialUserMoveReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.UserId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "客户id错误"
- return
- }
- wxUser, err := models.GetWxUserByUserId(req.UserId)
- //如果移动客户编号小于等于0,那么移动到潜在客户
- if req.CompanyId <= 0 {
- req.CompanyId = 1
- }
- if err != nil {
- br.Msg = "移动失败,该潜在用户已被删除"
- br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
- return
- }
- if req.Mobile == "" {
- req.Mobile = wxUser.Mobile
- }
- if req.Email == "" {
- req.Email = wxUser.Email
- }
- if req.Mobile == "" && req.Email == "" {
- br.Msg = "手机号和邮箱不能同时为空"
- return
- }
- //校验手机号
- if req.Mobile != "" && wxUser.Mobile != req.Mobile {
- count, err := models.CheckUserMobileIsRegister(req.UserId, req.Mobile)
- if err != nil {
- br.Msg = "校验数据失败"
- br.ErrMsg = "校验数据失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- br.Msg = "该手机号已经注册过用户"
- return
- }
- }
- //校验邮箱
- if req.Email != "" && wxUser.Email != req.Email {
- if !utils.ValidateEmailFormatat(req.Email) {
- br.Msg = "请输入正确的邮箱(包含@)"
- return
- }
- count, err := models.CheckUserEmailIsRegister(req.UserId, req.Email)
- if err != nil {
- br.Msg = "校验数据失败"
- br.ErrMsg = "校验数据失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- br.Msg = "该邮箱已经注册过用户"
- br.IsSendEmail = false
- return
- }
- }
- updateCol := make([]string, 0)
- if wxUser.OutboundMobile == "" || wxUser.Mobile == wxUser.OutboundMobile {
- wxUser.OutboundMobile = req.Mobile
- wxUser.OutboundCountryCode = req.CountryCode
- updateCol = append(updateCol, "OutboundMobile", "OutboundCountryCode")
- }
- if req.Email != "" {
- wxUser.Email = req.Email
- updateCol = append(updateCol, "Email")
- }
- if req.RealName != "" {
- wxUser.RealName = req.RealName
- updateCol = append(updateCol, "RealName")
- }
- if req.Mobile != "" {
- wxUser.Mobile = req.Mobile
- updateCol = append(updateCol, "Mobile")
- }
- if req.CountryCode != "" {
- wxUser.CountryCode = req.CountryCode
- updateCol = append(updateCol, "CountryCode")
- }
- if req.Position != "" {
- wxUser.Position = req.Position
- updateCol = append(updateCol, "Position")
- }
- if wxUser.DepartmentName == "" && req.DepartmentName != "" {
- wxUser.DepartmentName = req.DepartmentName
- updateCol = append(updateCol, "DepartmentName")
- }
- wxUser.Sex = req.Sex
- wxUser.IsMaker = req.IsMaker
- updateCol = append(updateCol, "Sex", "IsMaker")
- //名片匹配
- if req.BusinessCardUrl != "" {
- //if req.BusinessCardUrl != "" && utils.RunMode == "release" {
- // 获取图片识别手机号的配置
- crmConfig2, err := company.GetConfigDetailByCode("card_recognition_tel")
- if err != nil {
- br.Msg = "获取配置失败"
- br.ErrMsg = "获取配置失败"
- br.IsSendEmail = false
- return
- }
- if crmConfig2.ConfigValue == "true" {
- card, err := services.GetBusinessCard(req.BusinessCardUrl)
- if err != nil {
- br.Msg = "名片识别失败"
- br.ErrMsg = "名片识别失败,Err:" + err.Error()
- return
- }
- isFlag := false
- if len(card.WordsResult.MOBILE) > 0 {
- mobileStr := strings.Join(card.WordsResult.MOBILE, ",")
- //if req.Mobile != "" {
- // if strings.Contains(mobileStr, req.Mobile) || mobileStr == "" {
- // isFlag = true
- // } else {
- // isFlag = false
- // }
- //}
- if req.Mobile != "" && strings.Contains(mobileStr, req.Mobile) {
- isFlag = true
- }
- }
- if !isFlag {
- //阿里云识别
- //if utils.RunMode == "release" {
- aliyunResult, errMsg, err := services.AliyunOcrBusinessCard(req.BusinessCardUrl)
- if err != nil {
- br.Msg = "识别失败"
- br.ErrMsg = "识别失败,Err:" + err.Error()
- return
- }
- if !aliyunResult.Success {
- br.Msg = "识别失败"
- br.ErrMsg = "识别失败"
- return
- }
- if errMsg != "" {
- br.Msg = errMsg
- return
- }
- if len(aliyunResult.TelCell) > 0 {
- mobileStr := strings.Join(aliyunResult.TelCell, ",")
- if req.Mobile != "" {
- if strings.Contains(mobileStr, req.Mobile) {
- isFlag = true
- } else {
- isFlag = false
- }
- }
- } else {
- isFlag = true
- }
- //}
- }
- if !isFlag && crmConfig2.ConfigValue == "true" {
- br.Msg = "名片信息与联系人手机号不符"
- return
- }
- }
- wxUser.BusinessCardUrl = req.BusinessCardUrl
- updateCol = append(updateCol, "BusinessCardUrl")
- }
- productId := services.GetProductId(sysUser.RoleTypeCode)
- companyProductList, _ := getSysCompanyProductList(productId, req.CompanyId)
- err = services.MovePotentialUserByApplyRecord(sysUser.AdminId, req.UserId, req.CompanyId, req.ApplyRecordId, req.RealName, req.Mobile, req.Email, req.Remark, companyProductList, wxUser, updateCol)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "移动失败,Err:" + err.Error()
- return
- }
- //更新客户最近阅读次数以及最近阅读时间
- go services.ModifyCompanyProductLastViewData([]int{req.CompanyId})
- br.Ret = 200
- br.Success = true
- br.Msg = "移动成功"
- br.IsAddLog = true
- }
- // @Title 新增联系人图表分类权限
- // @Description 新增联系人图表分类权限接口
- // @Param request body request.SaveCompanyUserChartClassifyPermissionReq true "type json string"
- // @Success 200 Ret=200 操作成功
- // @router /user/addChartClassifyPermission [post]
- func (this *CompanyUserController) AddCompanyUserChartClassifyPermission() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.SaveCompanyUserChartClassifyPermissionReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.UserId <= 0 {
- br.Msg = "参数丢失:联系人ID"
- br.ErrMsg = "参数丢失,联系人ID"
- return
- }
- if req.StartTime == "" || req.EndTime == "" {
- br.Msg = "请选择开始结束时间"
- br.ErrMsg = "请选择开始结束时间"
- br.IsSendEmail = false
- return
- }
- startTime, err := time.Parse(utils.FormatDate, req.StartTime)
- if err != nil {
- br.Msg = "开始时间格式有误"
- br.ErrMsg = "开始时间转换失败, Err:" + err.Error()
- return
- }
- endTime, err := time.Parse(utils.FormatDate, req.EndTime)
- if err != nil {
- br.Msg = "结束时间格式有误"
- br.ErrMsg = "结束时间转换失败, Err:" + err.Error()
- return
- }
- if startTime.After(endTime) {
- br.Msg = "结束时间不能小于开始时间"
- br.ErrMsg = "结束时间不能小于开始时间"
- br.IsSendEmail = false
- return
- }
- _, err = company_user.GetChartClassifyPermissionByUserId(req.UserId)
- if err == nil {
- br.Msg = "请勿重复设置图表权限"
- br.ErrMsg = "请勿重复设置图表权限"
- br.IsSendEmail = false
- return
- }
- // 判断是否允许设置
- userInfo, err := models.GetWxUserByUserId(req.UserId)
- if err != nil {
- br.Msg = "联系人信息有误"
- br.ErrMsg = "联系人信息有误, Err: " + err.Error()
- return
- }
- companyInfo, err := company.GetCompanyById(userInfo.CompanyId)
- if err != nil {
- br.Msg = "获取客户信息失败"
- br.ErrMsg = "获取客户信息失败, Err: " + err.Error()
- return
- }
- companyProductInfo, err := company.GetCompanyProductByCompanyIdAndProductId(userInfo.CompanyId, 1)
- if err != nil {
- br.Msg = "获取客户产品信息失败"
- br.ErrMsg = "获取客户产品信息失败, Err: " + err.Error()
- return
- }
- companyStatus := companyProductInfo.Status
- if companyStatus != utils.COMPANY_STATUS_FOREVER {
- // 非永续客户
- if companyStatus == utils.COMPANY_STATUS_TRY_OUT || companyStatus == utils.COMPANY_STATUS_FORMAL {
- // 正式/试用
- expireTimeStr := companyProductInfo.EndDate
- expireTime, _ := time.ParseInLocation(utils.FormatDate, expireTimeStr, time.Local)
- // 服务结束时间小于设置的结束时间则不允许设置
- if endTime.After(expireTime.AddDate(0, 0, 1)) {
- br.Msg = "终止日期不允许超过服务日期, 服务终止日期为: " + expireTimeStr
- br.IsSendEmail = false
- return
- }
- } else {
- br.Msg = "当前客户不允许设置图表权限, 客户状态为: " + companyStatus
- br.IsSendEmail = false
- return
- }
- }
- item := &company_user.ChartClassifyPermission{
- UserId: req.UserId,
- CompanyId: companyInfo.CompanyId,
- StartTime: startTime,
- EndTime: endTime,
- Enabled: req.Enabled,
- CreateTime: time.Now(),
- }
- _, err = company_user.AddChartClassifyPermission(item)
- if err != nil {
- br.Msg = "新增图表权限失败"
- br.ErrMsg = "新增图表权限失败, Err:" + err.Error()
- return
- }
- // 操作记录
- {
- record := &company_user.CompanyUserChartPermissionOperationRecord{
- Type: 1,
- CompanyId: companyInfo.CompanyId,
- UserId: req.UserId,
- AdminId: sysUser.AdminId,
- StartTime: startTime,
- EndTime: endTime,
- Enabled: req.Enabled,
- CreateTime: time.Now(),
- }
- go company_user.AddChartPermissionOperationRecord(record)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // @Title 编辑联系人图表分类权限
- // @Description 编辑联系人图表分类权限接口
- // @Param request body request.SaveCompanyUserChartClassifyPermissionReq true "type json string"
- // @Success 200 Ret=200 操作成功
- // @router /user/editChartClassifyPermission [post]
- func (this *CompanyUserController) EditCompanyUserChartClassifyPermission() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.SaveCompanyUserChartClassifyPermissionReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.UserId <= 0 {
- br.Msg = "参数丢失:联系人ID"
- br.ErrMsg = "参数丢失,联系人ID"
- return
- }
- if req.StartTime == "" || req.EndTime == "" {
- br.Msg = "请选择开始结束时间"
- br.ErrMsg = "请选择开始结束时间"
- br.IsSendEmail = false
- return
- }
- startTime, err := time.Parse(utils.FormatDate, req.StartTime)
- if err != nil {
- br.Msg = "开始时间格式有误"
- br.ErrMsg = "开始时间转换失败, Err:" + err.Error()
- return
- }
- endTime, err := time.Parse(utils.FormatDate, req.EndTime)
- if err != nil {
- br.Msg = "结束时间格式有误"
- br.ErrMsg = "结束时间转换失败, Err:" + err.Error()
- return
- }
- if startTime.After(endTime) {
- br.Msg = "结束时间不能小于开始时间"
- br.ErrMsg = "结束时间不能小于开始时间"
- br.IsSendEmail = false
- return
- }
- // 判断是否允许设置
- userInfo, err := models.GetWxUserByUserId(req.UserId)
- if err != nil {
- br.Msg = "联系人信息有误"
- br.ErrMsg = "联系人信息有误, Err: " + err.Error()
- return
- }
- companyInfo, err := company.GetCompanyById(userInfo.CompanyId)
- if err != nil {
- br.Msg = "获取客户信息失败"
- br.ErrMsg = "获取客户信息失败, Err: " + err.Error()
- return
- }
- companyProductInfo, err := company.GetCompanyProductByCompanyIdAndProductId(userInfo.CompanyId, 1)
- if err != nil {
- br.Msg = "获取客户产品信息失败"
- br.ErrMsg = "获取客户产品信息失败, Err: " + err.Error()
- return
- }
- companyStatus := companyProductInfo.Status
- if companyStatus != utils.COMPANY_STATUS_FOREVER {
- // 非永续客户
- if companyStatus == utils.COMPANY_STATUS_TRY_OUT || companyStatus == utils.COMPANY_STATUS_FORMAL {
- // 正式/试用
- expireTimeStr := companyProductInfo.EndDate
- expireTime, _ := time.ParseInLocation(utils.FormatDate, expireTimeStr, time.Local)
- // 服务结束时间小于设置的结束时间则不允许设置
- if endTime.After(expireTime.AddDate(0, 0, 1)) {
- br.Msg = "终止日期不允许超过服务日期, 服务终止日期为: " + expireTimeStr
- br.IsSendEmail = false
- return
- }
- } else {
- br.Msg = "当前客户不允许设置图表权限, 客户状态为: " + companyStatus
- br.IsSendEmail = false
- return
- }
- }
- permissionInfo, err := company_user.GetChartClassifyPermissionByUserId(req.UserId)
- if err != nil {
- br.Msg = "获取联系人图表分类权限失败"
- br.ErrMsg = "获取联系人图表分类权限失败, Err:" + err.Error()
- return
- }
- permissionInfo.CompanyId = companyInfo.CompanyId
- permissionInfo.Enabled = req.Enabled
- permissionInfo.StartTime = startTime
- permissionInfo.EndTime = endTime
- permissionInfo.UpdateTime = time.Now()
- err = permissionInfo.Update([]string{"CompanyId", "Enabled", "StartTime", "EndTime", "UpdateTime"})
- if err != nil {
- br.Msg = "编辑联系人图表分类权限失败"
- br.ErrMsg = "编辑联系人图表分类权限失败, Err:" + err.Error()
- return
- }
- // 操作记录
- {
- record := &company_user.CompanyUserChartPermissionOperationRecord{
- Type: 2,
- CompanyId: companyInfo.CompanyId,
- UserId: req.UserId,
- AdminId: sysUser.AdminId,
- StartTime: startTime,
- EndTime: endTime,
- Enabled: req.Enabled,
- CreateTime: time.Now(),
- }
- go company_user.AddChartPermissionOperationRecord(record)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // @Title 获取联系人图表分类权限详情
- // @Description 获取联系人图表分类权限详情接口
- // @Param UserId query int true "联系人ID,必填"
- // @Success 200 {object} response.CompanyUserChartClassifyPermissionDetailResp
- // @router /user/getChartClassifyPermissionDetail [get]
- func (this *CompanyUserController) GetCompanyUserChartClassifyPermissionDetail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- reqUserId := this.GetString("UserId", "")
- userId, _ := strconv.Atoi(reqUserId)
- if userId <= 0 {
- br.Msg = "参数丢失:联系人ID"
- return
- }
- userInfo, err := models.GetWxUserByUserId(userId)
- if err != nil {
- br.Msg = "联系人信息有误"
- br.ErrMsg = "联系人信息有误, Err: " + err.Error()
- return
- }
- permissionInfo, err := company_user.GetChartClassifyPermissionByUserId(userId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取联系人图表分类权限失败"
- br.ErrMsg = "获取联系人图表分类权限失败, Err:" + err.Error()
- return
- }
- resp := new(response.CompanyUserChartClassifyPermissionDetailResp)
- // 客户服务日期
- companyProductInfo, err := company.GetCompanyProductByCompanyIdAndProductId(userInfo.CompanyId, 1)
- if err != nil {
- br.Msg = "获取客户产品信息失败"
- br.ErrMsg = "获取客户产品信息失败, Err: " + err.Error()
- return
- }
- companyStatus := companyProductInfo.Status
- // 0-不允许设置 1-允许设置最大90天 2-90天
- nowTime := time.Now()
- free := 0
- if companyStatus == utils.COMPANY_STATUS_FOREVER {
- // 永续客户
- free = 2
- resp.ExpireDay = "2199-12-31"
- } else if companyStatus == utils.COMPANY_STATUS_TRY_OUT || companyStatus == utils.COMPANY_STATUS_FORMAL {
- free = 1
- resp.ExpireDay = companyProductInfo.EndDate
- } else {
- resp.ExpireDay = nowTime.Format(utils.FormatDate)
- }
- var startTime, endTime time.Time
- if permissionInfo != nil {
- // 已设置
- startTime = permissionInfo.StartTime
- endTime = permissionInfo.EndTime
- resp.ChartPermissionId = permissionInfo.Id
- resp.UserId = permissionInfo.UserId
- resp.StartTime = permissionInfo.StartTime.Format(utils.FormatDate)
- resp.EndTime = permissionInfo.EndTime.Format(utils.FormatDate)
- resp.Enabled = permissionInfo.Enabled
- } else {
- // 初次设置
- startTime = nowTime
- endTime = startTime.Add(89 * 24 * time.Hour) // 实际验证时以结束日期的23时59分为过期时间所以此处日期-1
- if free == 0 {
- endTime = nowTime
- } else if free == 1 {
- expireTime, _ := time.ParseInLocation(utils.FormatDate, companyProductInfo.EndDate, time.Local)
- sub := expireTime.Sub(nowTime)
- diff := int(sub.Hours() / 24)
- if diff < 90 {
- // 小于90天则终止时间为服务结束时间
- endTime = expireTime
- }
- }
- resp.StartTime = startTime.Format(utils.FormatDate)
- resp.EndTime = endTime.Format(utils.FormatDate)
- resp.UserId = userId
- resp.Enabled = 0 // 默认关闭
- }
- // 计算阅读时长天数
- subDuration := endTime.Sub(startTime)
- subHours := subDuration.Hours()
- subDays := int(subHours / 24)
- resp.DayDuration = subDays + 1
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // GetOtherProduct
- // @Title 获取其他分产品的筛选列表
- // @Description 获取联系人图表分类权限详情接口
- // @Param UserId query int true "联系人ID,必填"
- // @Success 200 {object} response.CompanyUserChartClassifyPermissionDetailResp
- // @router /user/otherProductList [get]
- func (this *CompanyUserController) GetOtherProduct() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- resp := make([]response.OtherProductTypeListResp, 0)
- statisticFlag, _ := this.GetBool("StatisticFlag")
- questionItem := response.OtherProductTypeListResp{
- ProductId: 0,
- ProductType: 3,
- ProductName: "问答社区",
- }
- roadVideoItem := response.OtherProductTypeListResp{
- ProductId: 2,
- ProductType: 2,
- ProductName: "线上路演",
- }
- videoItem := response.OtherProductTypeListResp{
- ProductId: 1,
- ProductType: 2,
- ProductName: "5分钟小视频",
- }
- if !statisticFlag {
- resp = append(resp, questionItem, roadVideoItem, videoItem)
- }
- voiceSectionList, err := yb.GetAllEnableVoiceSectionList()
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取语音播报版块, Err: " + err.Error()
- return
- }
- for _, v := range voiceSectionList {
- resp = append(resp, response.OtherProductTypeListResp{
- ProductId: v.SectionId,
- ProductType: 1,
- ProductName: v.SectionName,
- })
- }
- if statisticFlag {
- resp = append(resp, questionItem, roadVideoItem, videoItem)
- }
- // 全部
- resp = append(resp, response.OtherProductTypeListResp{
- ProductId: 0,
- ProductType: 99,
- ProductName: "全部",
- })
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- //func init() {
- // BusinessCardUrl := `https://hongze.oss-accelerate.aliyuncs.com/static/images/202107/20210715/R5xT6jw331gPwHZlsIg90cuSbuFW.jpeg`
- // BusinessCardUrl = `https://hongze.oss-accelerate.aliyuncs.com/static/images/202102/20210224/Bdr3Dv8oZDvsAnkzUpx8uA3S4odB.jpg`
- // BusinessCardUrl = `https://hongze.oss-accelerate.aliyuncs.com/static/images/202202/20220215/0glY7kgE07OLBHTnxxwS6u2cAxRx.png`
- // BusinessCardUrl = `https://hongze.oss-accelerate.aliyuncs.com/static/images/202206/20220614/ZHEUpbNtUfE09ZVp6qfQxSPUrLfS.jpg`
- // card, err := services.GetBusinessCard(BusinessCardUrl)
- // if err != nil {
- // fmt.Println("名片识别失败,Err:" + err.Error())
- // return
- // }
- // fmt.Println(card)
- //
- // fmt.Println("company:", card.WordsResult.COMPANY)
- // fmt.Println("===================")
- //
- // {
- // aliyunResult, err := services.AliyunBusinessCardOcr(BusinessCardUrl)
- // if err != nil {
- // fmt.Println("名片识别失败2,Err:" + err.Error())
- // return
- // }
- // fmt.Println(aliyunResult)
- // fmt.Println("company:", aliyunResult.Company)
- // }
- //
- //}
- // @Title 联系人名单匹配导入
- // @Description 联系人名单匹配导入
- // @Param File query file true "文件"
- // @Success 200 {object} company.UserImportMatchResp
- // @router /list/match/import [post]
- func (this *CompanyUserController) ImportListMatch() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- file, h, err := this.GetFile("File")
- if err != nil {
- br.Msg = "获取文件失败"
- br.ErrMsg = "获取文件失败,Err:" + err.Error()
- return
- }
- defer func() {
- _ = file.Close()
- }()
- ext := path.Ext(h.Filename)
- if ext != ".xlsx" && ext != ".xls" {
- br.Msg = "请上传Excel文件"
- return
- }
- uploadDir := "static/xls"
- err = os.MkdirAll(uploadDir, 766)
- if err != nil {
- br.Msg = "存储目录创建失败"
- br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
- return
- }
- uploadPath := uploadDir + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + h.Filename
- err = this.SaveToFile("File", uploadPath)
- if err != nil {
- br.Msg = "文件保存失败"
- br.ErrMsg = "文件保存失败,Err:" + err.Error()
- return
- }
- defer func() {
- _ = os.Remove(uploadPath)
- }()
- xlFile, err := xlsx.OpenFile(uploadPath)
- if err != nil {
- br.Msg = "文件导入失败"
- br.ErrMsg = "文件导入失败,Err:" + err.Error()
- return
- }
- dataList := make([]*company.UserImportMatch, 0)
- mobileArr := make([]string, 0)
- // 遍历sheet页读取
- for _, sheet := range xlFile.Sheets {
- // 遍历行读取
- maxRow := sheet.MaxRow
- for i := 0; i < maxRow; i++ {
- // 首行
- if i == 0 {
- row := sheet.Row(i)
- cells := row.Cells
- for k, cell := range cells {
- text := cell.String()
- if k == 0 {
- if text != "姓名" {
- br.Msg = "匹配失败, 请按模板导入"
- br.ErrMsg = "模板格式错误,title:" + text
- return
- }
- }
- if k == 1 {
- if text != "国际(区号)" {
- br.Msg = "匹配失败, 请按模板导入"
- br.ErrMsg = "模板格式错误,title:" + text
- return
- }
- }
- if k == 2 {
- if text != "手机号" {
- br.Msg = "匹配失败, 请按模板导入"
- br.ErrMsg = "模板格式错误,title:" + text
- return
- }
- }
- if k == 3 {
- if text != "客户公司" {
- br.Msg = "匹配失败, 请按模板导入"
- br.ErrMsg = "模板格式错误,title:" + text
- return
- }
- }
- }
- }
- // 数据行
- if i >= 1 {
- row := sheet.Row(i)
- cells := row.Cells
- var userName, countryCode, mobile, companyName string
- for k, cell := range cells {
- if k == 0 {
- userName = utils.TrimStr(cell.String())
- }
- if k == 1 {
- countryCode = utils.TrimStr(cell.String())
- }
- if k == 2 {
- mobile = utils.TrimStr(cell.String())
- }
- if k == 3 {
- companyName = utils.TrimStr(cell.String())
- }
- }
- // 手机号为空则读取下一行
- if mobile == "" {
- continue
- }
- // mobile列存在"86-11位手机号"这种格式
- if strings.Contains(mobile, "-") {
- mobileArr := strings.Split(mobile, "-")
- if len(mobileArr) == 2 {
- countryCode = mobileArr[0]
- mobile = mobileArr[1]
- }
- }
- mobileArr = append(mobileArr, mobile)
- item := &company.UserImportMatch{
- UserName: userName,
- CountryCode: countryCode,
- Mobile: mobile,
- CompanyName: companyName,
- }
- dataList = append(dataList, item)
- }
- }
- }
- mobileLen := len(mobileArr)
- if mobileLen == 0 {
- br.Msg = "匹配失败, 无有效数据"
- br.ErrMsg = "匹配失败, 无有效数据"
- return
- }
- // 根据手机号查询联系人信息
- var userCond string
- var userPars []interface{}
- userCond += ` AND mobile IN (` + utils.GetOrmInReplace(mobileLen) + `)`
- userPars = append(userPars, mobileArr)
- userList, e := company.GetCompanyUsersByCondition(userCond, userPars)
- if e != nil {
- br.Msg = "匹配失败, 请按模板导入"
- br.ErrMsg = "匹配失败, 获取联系人信息失败, Err: " + e.Error()
- return
- }
- companyIds := make([]int, 0)
- mobileCompanyIdMap := make(map[string]int, 0)
- for i := range userList {
- companyIds = append(companyIds, userList[i].CompanyId)
- mobileCompanyIdMap[userList[i].Mobile] = userList[i].CompanyId
- }
- companyLen := len(companyIds)
- // 查询客户、客户产品
- var productCond string
- var productPars []interface{}
- if companyLen > 0 {
- productCond += ` AND a.company_id IN (` + utils.GetOrmInReplace(companyLen) + `)`
- productPars = append(productPars, companyIds)
- }
- productList, e := company.GetCompanyProductsByCondition(productCond, productPars)
- if e != nil {
- br.Msg = "匹配失败, 请按模板导入"
- br.ErrMsg = "匹配失败, 获取客户产品信息失败, Err: " + e.Error()
- return
- }
- ficcProductMap := make(map[int]*company.CompanyProduct, 0)
- raiProductMap := make(map[int]*company.CompanyProduct, 0)
- for i := range productList {
- if productList[i].ProductId == 1 {
- ficcProductMap[productList[i].CompanyId] = productList[i]
- } else {
- raiProductMap[productList[i].CompanyId] = productList[i]
- }
- }
- // 根据客户信息返回数据
- for i := range dataList {
- companyId := mobileCompanyIdMap[dataList[i].Mobile]
- if companyId == 0 {
- continue
- }
- ficc := ficcProductMap[companyId]
- if ficc != nil {
- dataList[i].SysCompanyName = ficc.CompanyName
- dataList[i].FiccStatus = ficc.Status
- dataList[i].FiccSeller = ficc.SellerName
- }
- rai := raiProductMap[companyId]
- if rai != nil {
- dataList[i].SysCompanyName = rai.CompanyName
- dataList[i].RaiStatus = rai.Status
- dataList[i].RaiSeller = rai.SellerName
- }
- }
- // 缓存导入数据, 导出时用缓存数据生成Excel
- var code, cacheKey string
- dataJson, e := json.Marshal(dataList)
- if e == nil {
- code = fmt.Sprint(time.Now().UnixNano())
- cacheKey = utils.CACHE_KEY_COMPANY_MATCH_PRE + code
- _ = utils.Rc.Put(cacheKey, string(dataJson), time.Minute*30)
- }
- resp := new(company.UserImportMatchResp)
- resp.List = dataList
- resp.Code = code
- br.Data = resp
- br.Msg = "匹配成功"
- br.Ret = 200
- br.Success = true
- }
- // @Title 联系人名单匹配结果下载
- // @Description 联系人名单匹配结果下载
- // @Param Code query string true "导入时返回的Code"
- // @Success 200 Ret=200 匹配成功
- // @router /list/match/download [get]
- func (this *CompanyUserController) ImportListMatchDownload() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- code := this.GetString("Code")
- if code == "" {
- br.Msg = "参数有误"
- return
- }
- cacheKey := utils.CACHE_KEY_COMPANY_MATCH_PRE + code
- // 获取导入时的缓存数据
- dataJson, e := utils.Rc.RedisString(cacheKey)
- if e != nil {
- br.Msg = "获取导出数据失败"
- br.ErrMsg = "获取导出数据失败, Err: " + e.Error()
- return
- }
- if dataJson == "" {
- br.Msg = "匹配数据已失效, 请重新匹配"
- return
- }
- dataList := make([]*company.UserImportMatch, 0)
- if e = json.Unmarshal([]byte(dataJson), &dataList); e != nil {
- br.Msg = "匹配数据已失效, 请重新匹配"
- return
- }
- if len(dataList) == 0 {
- br.Msg = "匹配数据已失效, 请重新匹配"
- return
- }
- // 生成Excel表格
- dir, err := os.Executable()
- exPath := filepath.Dir(dir)
- downloadPath := exPath + "/company_match_" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- excelFile := xlsx.NewFile()
- if err != nil {
- br.Msg = "生成文件失败"
- br.ErrMsg = "生成文件失败"
- return
- }
- style := xlsx.NewStyle()
- alignment := xlsx.Alignment{
- Horizontal: "center",
- Vertical: "center",
- WrapText: true,
- }
- style.Alignment = alignment
- style.ApplyAlignment = true
- // 新增Sheet和表头
- sheet, err := excelFile.AddSheet("客户名单")
- if err != nil {
- br.Msg = "新增Sheet失败"
- br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
- return
- }
- titleRow := sheet.AddRow()
- titleRow.AddCell().SetValue("姓名")
- titleRow.AddCell().SetValue("国际(区号)")
- titleRow.AddCell().SetValue("手机号")
- titleRow.AddCell().SetValue("客户公司")
- titleRow.AddCell().SetValue("系统客户")
- titleRow.AddCell().SetValue("FICC状态")
- titleRow.AddCell().SetValue("FICC销售")
- titleRow.AddCell().SetValue("权益状态")
- titleRow.AddCell().SetValue("权益销售")
- // 表格赋值
- for _, v := range dataList {
- dataRow := sheet.AddRow()
- dataRow.SetHeight(20)
- dataRow.AddCell().SetString(v.UserName)
- dataRow.AddCell().SetString(v.CountryCode)
- dataRow.AddCell().SetString(v.Mobile)
- dataRow.AddCell().SetString(v.CompanyName)
- dataRow.AddCell().SetString(v.SysCompanyName)
- dataRow.AddCell().SetString(v.FiccStatus)
- dataRow.AddCell().SetString(v.FiccSeller)
- dataRow.AddCell().SetString(v.RaiStatus)
- dataRow.AddCell().SetString(v.RaiSeller)
- }
- // 输出Excel
- if e = excelFile.Save(downloadPath); e != nil {
- br.Msg = "保存文件失败"
- br.ErrMsg = "保存文件失败"
- return
- }
- defer func() {
- _ = os.Remove(downloadPath)
- }()
- suffix := time.Now().Format(utils.FormatDateTimeUnSpace)
- downloadFileName := "客户名单匹配_" + suffix + ".xlsx"
- this.Ctx.Output.Download(downloadPath, downloadFileName)
- br.Msg = "导出成功"
- br.Ret = 200
- br.Success = true
- }
- // Follow
- // @Title 关注联系人
- // @Description 关注联系人
- // @Param request body request.ApplyMarkReq true "type json string"
- // @Success 200 {object} 标记处理成功
- // @router /follow [post]
- func (this *CompanyUserController) Follow() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser is Empty"
- br.Ret = 408
- return
- }
- var req request.FollowReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.UserId <= 0 {
- br.Msg = "用户ID异常"
- br.ErrMsg = "用户ID异常"
- return
- }
- // 查公司里有多少已关注,上限三个
- count, err := models.GetCompanyFollowCount(req.CompanyId)
- if err != nil {
- br.Msg = "操作失败! "
- br.ErrMsg = "操作失败,Err:" + err.Error()
- return
- }
- if count == 3 && req.Type == 1 {
- br.Msg = "关注失败,特别关注已达上限(上限三个)"
- br.ErrMsg = "关注失败,特别关注已达上限(上限三个)"
- return
- }
- // 关注或取关
- err = models.SetUserFollow(req.UserId, req.Type)
- if err != nil {
- br.Msg = "操作失败! "
- br.ErrMsg = "操作失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // @Title 开通或者关闭用户研选权限
- // @Description 开通或者关闭用户研选权限
- // @Param request body request.ApplyMarkReq true "type json string"
- // @Success 200 {object} 操作成功
- // @router /update/user/yananxuan/permission [post]
- func (this *CompanyUserController) UpadteUserYanxuanPermission() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser is Empty"
- br.Ret = 408
- return
- }
- var req cygx.UpdateUserYanxuanPermissionReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- userId := req.UserId
- if userId <= 0 {
- br.Msg = "用户ID异常"
- br.ErrMsg = "用户ID异常"
- return
- }
- //获取联系人详情
- userInfo, err := models.GetWxUserByUserId(req.UserId)
- if err != nil {
- br.Msg = "获取联系人异常!"
- br.ErrMsg = "获取联系人异常,Err:" + err.Error()
- return
- }
- if userInfo.BusinessCardUrl == "" {
- br.Msg = "该联系人尚未添加名片,请点击编辑,上传名片后再开通试用"
- return
- }
- companyInfo, err := company.GetCompanyById(userInfo.CompanyId)
- if err != nil {
- br.Msg = "查找客户失败"
- br.ErrMsg = "查找客户失败,err:" + err.Error()
- return
- }
- // 查询用户是否开通过
- count, err := cygx.GetCygxUserYanxuanPermissionCountByUserId(userId)
- if err != nil {
- br.Msg = "操作失败! "
- br.ErrMsg = "操作失败,Err:" + err.Error()
- return
- }
- item := new(cygx.CygxUserYanxuanPermission)
- if req.Type == 0 {
- item.Status = "未开通"
- } else {
- item.Status = "试用"
- }
- item.UserId = userId
- item.CompanyId = companyInfo.CompanyId
- item.CompanyName = companyInfo.CompanyName
- item.StartDate = time.Now().Format(utils.FormatDate)
- item.EndDate = time.Now().AddDate(0, 2, 0).Format(utils.FormatDate) // 试用期两个月
- item.Mobile = userInfo.Mobile
- item.Email = userInfo.Email
- item.RealName = userInfo.RealName
- item.AdminId = sysUser.AdminId
- item.AdminRealName = sysUser.RealName
- item.CreatedTime = time.Now()
- item.LastUpdatedTime = time.Now()
- item.ModifyTime = time.Now()
- if count == 0 {
- _, err = cygx.AddCygxUserYanxuanPermission(item) // 添加
- } else {
- if req.Type == 0 {
- err = cygx.UpdateCygxUserYanxuanPermissionClose(userId) // 关闭
- } else {
- err = cygx.UpdateCygxUserYanxuanPermissionOpen(item) // 开通
- }
- }
- if err != nil {
- br.Msg = "操作失败! "
- br.ErrMsg = "操作失败,Err:" + err.Error()
- return
- }
- go cygxService.AddCygxUserYanxuanPermissionLog(item)
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // ListByReport
- // @Title 联系人列表
- // @Description 联系人列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param CompanyId query int true "公司id,必填"
- // @Param SortParam query int false "排序字段:1-点击量;2-点击时间"
- // @Param SortType query int false "排序方式:1-倒序;2-正序"
- // @Success 200 {object} company.CompanyUserListResp
- // @router /user/listByReport [get]
- func (this *CompanyUserController) ListByReport() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- companyId, _ := this.GetInt("CompanyId")
- sortParam, _ := this.GetInt("SortParam", 2)
- sortType, _ := this.GetInt("SortType", 1)
- if companyId <= 0 {
- br.Msg = "请选择客户"
- br.ErrMsg = "客户参数错误"
- return
- }
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var order string
- sortArr := []int{1, 2}
- if utils.InArrayByInt(sortArr, sortParam) && utils.InArrayByInt(sortArr, sortType) {
- pMap := map[int]string{1: "ficc_view_total", 2: "ficc_last_view_time"}
- tMap := map[int]string{1: "DESC", 2: "ASC"}
- order = fmt.Sprintf(` ORDER BY %s %s`, pMap[sortParam], tMap[sortType])
- }
- total, err := company.GetCompanyUserListByReportCount(companyId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
- return
- }
- list, err := company.GetCompanyUserListByReport(companyId, startSize, pageSize, order)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- respList := make([]*company.CompanyViewResp, 0)
- for i := range list {
- v := &company.CompanyViewResp{
- UserId: int(list[i].UserId),
- UserName: list[i].RealName,
- Mobile: list[i].Mobile,
- Email: list[i].Email,
- ViewTotal: list[i].FiccViewTotal,
- LastViewTime: list[i].FiccLastViewTime.Format(utils.FormatDateTime),
- }
- if v.LastViewTime == "0001-01-01 00:00:00" {
- v.LastViewTime = ""
- }
- respList = append(respList, v)
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := &company.CompanyViewPageListResp{
- Paging: page,
- List: respList,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // listMoveLog
- // @Title 联系人移动记录列表
- // @Description 联系人移动记录列表接口
- // @Param Mobile query string true "手机号"
- // @Success 200 {object} company.CompanyUserListResp
- // @router /user/listMoveLog [get]
- func (this *CompanyUserController) ListMoveLog() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- mobile := this.GetString("Mobile")
- if mobile == "" {
- br.Msg = "手机号不能为空"
- return
- }
- list, err := company.GetWxUserMoveLogListmByMobile(mobile)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- respList := make([]*company.WxUserMoveLogResp, 0)
- for _, v := range list {
- item := new(company.WxUserMoveLogResp)
- item.UserName = v.RealName
- item.Mobile = v.Mobile
- item.Email = v.Email
- item.CompanyId = v.CompanyId
- item.CompanyName = v.CompanyName
- item.CompanyIdMove = v.CompanyIdMove
- item.CompanyNameMove = v.CompanyNameMove
- item.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
- respList = append(respList, item)
- }
- resp := &company.WxUserMoveLogListResp{
- List: respList,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 修改联系人外呼手机号
- // @Description 修改联系人外呼手机号接口
- // @Param request body models.PotentialUserDealReq true "type json string"
- // @Success Ret=200 修改成功
- // @router /user/edit/outbound_mobile [post]
- func (this *CompanyController) EditUserOutboundMobile() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.EditUserOutboundMobileReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- if req.OutboundMobile == "" {
- br.Msg = "手机号不能为空"
- return
- }
- //if !utils.ValidateMobileFormatat(req.OutboundMobile) {
- // br.Msg = "手机号格式有误"
- // return
- //}
- err = models.UpdateUserOutboundMobile(req.OutboundMobile, req.OutboundCountryCode, req.UserId)
- br.Ret = 200
- br.Success = true
- br.Msg = "标记成功"
- }
|