company_user.go 205 KB

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