12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710 |
- package controllers
- import (
- "encoding/json"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "github.com/tealeg/xlsx"
- "hongze/hz_crm_api/cache"
- "hongze/hz_crm_api/models"
- "hongze/hz_crm_api/models/advisory"
- "hongze/hz_crm_api/models/company"
- "hongze/hz_crm_api/models/company_report_permission_log"
- "hongze/hz_crm_api/models/company_todo"
- "hongze/hz_crm_api/models/company_user"
- "hongze/hz_crm_api/models/cygx"
- "hongze/hz_crm_api/models/response"
- statisticModels "hongze/hz_crm_api/models/statistic_report"
- "hongze/hz_crm_api/models/system"
- "hongze/hz_crm_api/services"
- "hongze/hz_crm_api/services/alarm_msg"
- cygxService "hongze/hz_crm_api/services/cygx"
- "hongze/hz_crm_api/services/statistic_report"
- "hongze/hz_crm_api/utils"
- "os"
- "path/filepath"
- "strconv"
- "strings"
- "time"
- )
- // 客户管理
- type CompanyController struct {
- BaseAuthController
- }
- // @Title 客户检索列表
- // @Description 客户检索列表接口
- // @Param KeyWord query string true "搜索关键词"
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} company.CompanySearchListResp
- // @router /search/list [get]
- func (this *CompanyController) SearchList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- roleTypeCode := sysUser.RoleTypeCode
- keyWord := this.GetString("KeyWord")
- keyWord = strings.Trim(keyWord, " ")
- keyWord = strings.Replace(keyWord, "'", "", -1)
- resp := new(company.CompanySearchListResp)
- var condition string
- var pars []interface{}
- //需要忽略的关键字
- ignoreStrs := []string{"", "有限", "投资", "资本", "管理", "贸易", "资产", "公司", "股份", "集团", "有限公司"}
- if strings.Contains(strings.Join(ignoreStrs, ","), keyWord) {
- list := make([]*company.CompanySearchItem, 0)
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- //正常筛选逻辑
- companyIdStr, err := company.GetCompanyIdByKeyWordAll(keyWord)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- companyIdStr = strings.Trim(companyIdStr, ",")
- if companyIdStr != "" {
- condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
- } else {
- condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.credit_code LIKE '%` + keyWord + `%')`
- //pars = append(pars, keyWord)
- //pars = append(pars, keyWord)
- }
- total, err := company.GetCompanySearchCount(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
- return
- }
- list, err := company.GetCompanySearchList(condition, pars, startSize, pageSize)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- // 查询当前销售是否有领取客户的权限
- receiveEnabled, _ := services.CheckCompanyReceiveButton(sysUser.AdminId)
- // 白嫖客户标记
- scroungeList, err := company.GetScroungeCompany()
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取白嫖客户信息失败,Err:" + err.Error()
- return
- }
- scroungeMap := make(map[int]int)
- for _, v := range scroungeList {
- scroungeMap[v.CompanyId] = 1
- }
- /*
- 时长根据客户状态定义,
- 若为冻结客户或者流失客户,则展示冻结时长或流失时长;
- 若为正式或试用客户,展示到期时长;
- */
- lenList := len(list)
- for i := 0; i < lenList; i++ {
- duration := ""
- item := list[i]
- itemStatus := item.Status
- //白嫖客户标记
- if _, ok := scroungeMap[item.CompanyId]; ok {
- item.IsScrounge = 1
- }
- if !strings.Contains(item.Status, "/") {
- if item.Status == utils.COMPANY_STATUS_FREEZE {
- if item.FreezeEndDate != "" {
- freeZeTime, _ := time.Parse(utils.FormatDate, item.FreezeEndDate)
- freeZeTime = freeZeTime.AddDate(0, 0, 1)
- sub := freeZeTime.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- duration = fmt.Sprintf("%v", int(sub.Hours()/24))
- }
- } else if item.Status == utils.COMPANY_STATUS_LOSE {
- if item.LossTime != "" {
- lossTime, err := time.Parse(utils.FormatDateTime, item.LossTime)
- if err != nil {
- fmt.Println("err:" + err.Error())
- }
- lossTime = lossTime.AddDate(0, 0, 1)
- sub := time.Now().Sub(lossTime)
- if sub < 0 {
- sub = 0
- }
- duration = fmt.Sprintf("%v", int(sub.Hours()/24))
- }
- } else if item.Status == utils.COMPANY_STATUS_FORMAL ||
- item.Status == utils.COMPANY_STATUS_TRY_OUT {
- if item.EndDate != "" {
- endDate, _ := time.Parse(utils.FormatDate, item.EndDate)
- endDate = endDate.AddDate(0, 0, 1)
- sub := endDate.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- duration = fmt.Sprintf("%v", int(sub.Hours()/24))
- }
- } else if item.Status == utils.COMPANY_STATUS_TRY_OUT {
- duration = "永续"
- } else {
- duration = "-"
- }
- } else {
- statusArr := strings.Split(item.Status, "/")
- //freezeArr := strings.Split(item.FreezeTime, "/") //0:ficc,1:权益
- freezeArr := strings.Split(item.FreezeEndDate, "/") //冻结结束日期:0:ficc,1:权益
- lossArr := strings.Split(item.LossTime, "/") //0:ficc,1:权益
- endDateArr := strings.Split(item.EndDate, "/")
- var ficcFreeze, tryFreeze string
- var ficcLoss, tryLoss string
- var ficcEndDate, tryEndDate string
- ficcStatus := statusArr[0]
- tryOutStatus := statusArr[1]
- //if len(freezeArr) > 1 {
- // ficcFreeze = freezeArr[0]
- // tryFreeze = freezeArr[1]
- //}
- //if len(lossArr) > 1 {
- // ficcLoss = lossArr[0]
- // tryLoss = lossArr[1]
- //}
- //结束日期
- if len(endDateArr) > 1 {
- ficcEndDate = endDateArr[0]
- tryEndDate = endDateArr[1]
- }
- //冻结
- if ficcStatus == utils.COMPANY_STATUS_FREEZE && len(freezeArr) > 0 {
- //ficc
- ficcFreeze = freezeArr[0]
- }
- if tryOutStatus == utils.COMPANY_STATUS_FREEZE && len(freezeArr) > 0 {
- //权益
- if len(freezeArr) == 1 {
- tryFreeze = freezeArr[0]
- } else {
- tryFreeze = freezeArr[1]
- }
- }
- //流失
- if ficcStatus == utils.COMPANY_STATUS_LOSE && len(lossArr) > 0 {
- //ficc
- ficcLoss = lossArr[0]
- }
- if tryOutStatus == utils.COMPANY_STATUS_LOSE && len(lossArr) > 0 {
- //权益
- if len(lossArr) == 1 {
- tryLoss = lossArr[0]
- } else {
- tryLoss = lossArr[1]
- }
- }
- //ficc的判断
- switch ficcStatus {
- case utils.COMPANY_STATUS_FREEZE: //冻结
- if ficcFreeze != "" {
- ficcFreeZeTime, _ := time.Parse(utils.FormatDate, ficcFreeze)
- ficcFreeZeTime = ficcFreeZeTime.AddDate(0, 0, 1)
- sub := ficcFreeZeTime.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- duration = fmt.Sprintf("%v", int(sub.Hours()/24))
- }
- case utils.COMPANY_STATUS_LOSE: //流失
- if ficcLoss != "" {
- ficcLossTime, _ := time.Parse(utils.FormatDateTime, ficcLoss)
- ficcLossTime = ficcLossTime.AddDate(0, 0, 1)
- sub := time.Now().Sub(ficcLossTime)
- if sub < 0 {
- sub = 0
- }
- duration = fmt.Sprintf("%v", int(sub.Hours()/24))
- }
- case utils.COMPANY_STATUS_FORMAL, utils.COMPANY_STATUS_TRY_OUT:
- if ficcEndDate != "" {
- ficcEndDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
- ficcEndDateTime = ficcEndDateTime.AddDate(0, 0, 1)
- sub := ficcEndDateTime.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- duration = fmt.Sprintf("%v", int(sub.Hours()/24))
- }
- case utils.COMPANY_STATUS_FOREVER:
- duration = "永续"
- case utils.COMPANY_STATUS_CLOSE:
- duration = "-"
- }
- //权益的判断
- switch tryOutStatus {
- case utils.COMPANY_STATUS_FREEZE: //冻结
- if tryFreeze != "" {
- tryOutFreeZeTime, _ := time.Parse(utils.FormatDate, tryFreeze)
- tryOutFreeZeTime = tryOutFreeZeTime.AddDate(0, 0, 1)
- sub := tryOutFreeZeTime.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- if duration != "" {
- duration = duration + "/" + fmt.Sprintf("%v", int(sub.Hours()/24))
- }
- }
- case utils.COMPANY_STATUS_LOSE: //流失
- if tryLoss != "" {
- tryOutLossTime, _ := time.Parse(utils.FormatDateTime, tryLoss)
- tryOutLossTime = tryOutLossTime.AddDate(0, 0, 1)
- sub := time.Now().Sub(tryOutLossTime)
- if sub < 0 {
- sub = 0
- }
- if duration != "" {
- duration = duration + "/" + fmt.Sprintf("%v", int(sub.Hours()/24))
- }
- }
- case utils.COMPANY_STATUS_FORMAL, utils.COMPANY_STATUS_TRY_OUT:
- if tryEndDate != "" {
- tryEndDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
- tryEndDateTime = tryEndDateTime.AddDate(0, 0, 1)
- sub := tryEndDateTime.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- if duration != "" {
- duration = duration + "/" + fmt.Sprintf("%v", int(sub.Hours()/24))
- }
- }
- case utils.COMPANY_STATUS_FOREVER:
- if duration != "" {
- duration = duration + "/" + "永续"
- }
- case utils.COMPANY_STATUS_CLOSE:
- duration = "-"
- }
- //list[i].ApproveStatus = ""
- }
- approveStatusMap := make(map[int]string)
- if item.ProductId == 1 {
- approveStatusMap[1] = item.ApproveStatus
- } else if item.ProductId == 2 {
- approveStatusMap[2] = item.ApproveStatus
- }
- if strings.Contains(item.ApproveStatus, "/") {
- approveStatusSlice := strings.Split(item.ApproveStatus, "/")
- approveStatusMap[1] = approveStatusSlice[0]
- approveStatusMap[2] = approveStatusSlice[1]
- } else {
- approveStatusMap[1] = item.ApproveStatus
- approveStatusMap[2] = item.ApproveStatus
- }
- productIdMap := make(map[int]int)
- if strings.Contains(item.ProductIds, "/") {
- productIdSlice := strings.Split(item.ProductIds, "/")
- productIdMap[1], _ = strconv.Atoi(productIdSlice[0])
- productIdMap[2], _ = strconv.Atoi(productIdSlice[1])
- }
- if strings.Contains(item.ApproveStatus, "/") {
- approveStatusSlice := strings.Split(item.ApproveStatus, "/")
- approveStatusMap[1] = approveStatusSlice[0]
- approveStatusMap[2] = approveStatusSlice[1]
- for k, v := range productIdMap {
- approveStatusMap[v] = approveStatusSlice[k-1]
- }
- } else {
- for _, v := range productIdMap {
- approveStatusMap[v] = item.ApproveStatus
- }
- }
- sysProductId := services.GetProductId(sysUser.RoleTypeCode)
- if sysProductId > 0 {
- list[i].ApproveStatus = approveStatusMap[sysProductId]
- }
- list[i].Duration = duration
- //按钮显示控制
- /*btnItem := services.GetCompanySearchPermissionButton(roleTypeCode, itemStatus, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId)
- list[i].BtnItem = &btnItem*/
- btnItem := new(company.ButtonPermission)
- if item.CompanyId != 1 {
- *btnItem = services.GetCompanyPermissionButton(roleTypeCode, itemStatus, item.SellerIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, -1, item.ShareSellerIds)
- //根据销售"领取客户"的权限对部分按钮做限制
- btnItem = services.GetCompanyPermissionButtonByReceiveEnabled(btnItem, receiveEnabled)
- }
- if list[i].IsShare == 1 && btnItem.BtnModifySeller == true && roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
- //如果已经是共享客户了,取消共享按钮全都显示,和修改销售权限一样
- btnItem.BtnShare = true
- }
- // 客户搜索页不要共享客户按钮
- btnItem.BtnShare = false
- //如果是权益客户,操作者又是权益管理员,那么就对他进行展示研选详情按钮
- if strings.Contains(item.CompanyType, utils.COMPANY_CLASSIFY_RAI) && sysUser.RoleName == utils.ROLE_TYPE_RAI_PRODUCT {
- btnItem.IsResearchShow = true
- }
- list[i].BtnItem = btnItem
- }
- for _, v := range list {
- v.Status = strings.Replace(v.Status, utils.COMPANY_STATUS_FOREVER, utils.COMPANY_STATUS_X_CLASS_TRY_OUT, -1) // 永续客户类型,映射成 X类试用
- v.Duration = strings.Replace(v.Duration, utils.COMPANY_STATUS_FOREVER, utils.COMPANY_STATUS_X_CLASS_TRY_OUT, -1) // 永续客户类型,映射成 X类试用
- }
- if list == nil {
- list = make([]*company.CompanySearchItem, 0)
- }
- resp.List = list
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // List
- // @Title 客户列表
- // @Description 客户列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param Status query string true "状态:'试用','永续','冻结','流失','正式'"
- // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
- // @Param IndustryId query int true "行业id,0为全部"
- // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
- // @Param ChartPermissionIds query string false "阅读权限品种ID,多个用英文逗号分开,空字符串为全部"
- // @Param ContractPermissionIds query string false "已购品种ID,多个用英文逗号分开,空字符串为全部"
- // @Param StartDate query string true "开始时间"
- // @Param EndDate query string true "结束时间"
- // @Param CreateStartDate query string true "创建开始时间"
- // @Param CreateEndDate query string true "创建结束时间"
- // @Param KeyWord query string true "搜索关键词"
- // @Param Address query string true "地址 , 多个用英文逗号分开 "
- // @Param Province query string true "省 , 多个用英文逗号分开 "
- // @Param City query string true "市 , 多个用英文逗号分开 "
- // @Param PackageType query int true "套餐类型,0:无,1:大套餐,2:小套餐"
- // @Param TodoStatus query string true "任务处理状态;枚举值:'无任务','未完成','已完成'"
- // @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:'viewTotal':总阅读次数 、 'viewTime':阅读时间 、 'roadShowTotal':累计路演次数 、`expireDay:到期时间` 、 `createTime:创建时间` 、 'formalTime': 转正时间 、 'freezeTime':冻结时间 、'lossTime':流失时间 、'tryStage':试用标签 、'deadline':距离未完成的任务的截止日期的天数、'tryOutDay':试用天数"
- // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
- // @Param SortByTodo query bool true "是否根据待办排序,true或false"
- // @Param TryStage query int false "试用客户子标签:0全部、1未分类、2 推进、3 跟踪、4 预备"
- // @Param IncludeShare query bool true "是否包含共享客户: true-包含; false-不包含"
- // @Success 200 {object} company.CompanyListResp
- // @router /list [get]
- func (this *CompanyController) List() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- roleTypeCode := sysUser.RoleTypeCode
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- status := this.GetString("Status")
- companyType := this.GetString("CompanyType")
- industryId, _ := this.GetInt("IndustryId")
- adminId := this.GetString("AdminId")
- chartPermissionIds := this.GetString("ChartPermissionIds")
- contractPermissionIds := this.GetString("ContractPermissionIds")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- createStartDate := this.GetString("CreateStartDate")
- createEndDate := this.GetString("CreateEndDate")
- keyWord := this.GetString("KeyWord")
- address := this.GetString("Address")
- province := this.GetString("Province")
- city := this.GetString("City")
- regionType := this.GetString("RegionType")
- keyWord = strings.Trim(keyWord, " ")
- keyWord = strings.Replace(keyWord, "'", "", -1)
- todoStatus := this.GetString("TodoStatus") //任务状态
- tryStage, _ := this.GetInt("TryStage") //试用客户标签
- includeShare, _ := this.GetBool("IncludeShare") // 是否包含试用客户
- // 套餐类型
- packageType, _ := this.GetInt("PackageType")
- //排序参数
- sortParam := this.GetString("SortParam")
- sortType := this.GetString("SortType")
- sortByTodo, _ := this.GetBool("SortByTodo")
- productId := services.GetProductId(roleTypeCode)
- var total int
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(company.CompanyListResp)
- statusItems := make([]*company.CompanyStatus, 0)
- // 永续客户类型,映射成 X类试用
- if status == utils.COMPANY_STATUS_X_CLASS_TRY_OUT {
- status = utils.COMPANY_STATUS_FOREVER
- }
- var statusArr []string
- // 对权益用户隐藏关闭
- if productId == utils.COMPANY_PRODUCT_RAI_ID {
- statusArr = []string{"全部", "试用", "正式", "冻结", "流失", utils.COMPANY_STATUS_X_CLASS_TRY_OUT}
- } else {
- statusArr = []string{"全部", "试用", "正式", "冻结", "流失", utils.COMPANY_STATUS_CLOSE, utils.COMPANY_STATUS_X_CLASS_TRY_OUT}
- }
- //var statusArr = [...]string{"全部", "试用-活跃", "试用-非活跃", "正式", "冻结", "流失", "永续"}
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- //流失
- var lossCondition string
- var lossPars []interface{}
- //状态分类查询条件
- var permissionCondition string
- var permissionPars []interface{}
- if companyType != "" {
- condition += ` AND b.product_name=? `
- pars = append(pars, companyType)
- }
- if industryId > 0 {
- condition += ` AND b.industry_id=? `
- pars = append(pars, industryId)
- }
- if adminId != "" {
- condition += ` AND b.seller_id IN (` + adminId + `) `
- }
- if startDate != "" {
- condition += ` AND b.start_date>=? `
- pars = append(pars, startDate)
- }
- if endDate != "" {
- condition += ` AND b.end_date<=? `
- pars = append(pars, endDate)
- }
- if createStartDate != "" {
- condition += ` AND a.created_time>=? `
- pars = append(pars, createStartDate)
- }
- if createEndDate != "" {
- condition += ` AND a.created_time<=? `
- pars = append(pars, createEndDate)
- }
- if address != "" {
- var addressSql string
- slice := strings.Split(address, ",")
- for _, v := range slice {
- addressSql += "'" + v + "'" + ","
- }
- addressSql = strings.TrimRight(addressSql, ",")
- condition += ` AND a.address IN (` + addressSql + `) `
- }
- if province != "" {
- var provinceSql string
- slice := strings.Split(province, ",")
- for _, v := range slice {
- provinceSql += "'" + v + "'" + ","
- }
- provinceSql = strings.TrimRight(provinceSql, ",")
- condition += ` AND a.province IN (` + provinceSql + `) `
- }
- if city != "" {
- var citySql string
- slice := strings.Split(city, ",")
- for _, v := range slice {
- citySql += "'" + v + "'" + ","
- }
- citySql = strings.TrimRight(citySql, ",")
- condition += ` AND a.city IN (` + citySql + `) `
- }
- if regionType != "" {
- condition += ` AND a.region_type =? `
- pars = append(pars, regionType)
- }
- if keyWord != "" {
- companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
- if err != nil {
- br.Msg = "获取客户信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- if companyIdStr != "" {
- condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.credit_code LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
- } else {
- condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.credit_code LIKE '%` + keyWord + `%' ) `
- }
- }
- //任务状态
- if todoStatus != "" {
- condition += ` AND b.todo_status =? `
- pars = append(pars, todoStatus)
- }
- // 阅读权限/已购品种筛选
- cond, emp, e := services.FilterReadAndContractAuth(chartPermissionIds, contractPermissionIds, condition)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "FilterReadAndContractAuth err: " + e.Error()
- return
- }
- if emp {
- for _, v := range statusArr {
- statusCount := new(company.CompanyStatus)
- if v == "全部" {
- statusCount.Status = "全部"
- statusCount.Count = 0
- } else {
- statusCount.Status = v
- statusCount.Count = 0
- }
- statusItems = append(statusItems, statusCount)
- }
- items := make([]*company.CompanyListItem, 0)
- resp.List = items
- resp.Paging = page
- resp.StatusCount = statusItems
- br.Msg = "获取成功"
- br.Ret = 200
- br.Data = resp
- return
- }
- condition = cond
- //套餐类型
- if packageType > 0 {
- condition += ` AND b.package_type=? `
- pars = append(pars, packageType)
- }
- lossCondition = condition
- lossPars = pars
- permissionCondition = condition
- permissionPars = pars
- //流失客户统计
- lossCondition += ` AND status='流失' `
- //权限控制
- {
- //如果不是超级管理员或者财务
- if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && roleTypeCode != utils.ROLE_TYPE_CODE_FINANCE {
- //如果是部门管理员
- if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
- condition += ` AND b.product_id=? `
- pars = append(pars, productId)
- lossCondition += ` AND b.product_id=? `
- lossPars = append(lossPars, productId)
- permissionCondition += ` AND b.product_id=? `
- permissionPars = append(permissionPars, productId)
- //}
- //else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DIRECTOR {
- // condition += ` AND b.product_id=? `
- // pars = append(pars, productId)
- //
- // lossCondition += ` AND b.product_id=? `
- // lossPars = append(lossPars, productId)
- //
- // permissionCondition += ` AND b.product_id=? `
- // permissionPars = append(permissionPars, productId)
- } else {
- condition += ` AND b.product_id=? `
- pars = append(pars, productId)
- lossCondition += ` AND b.product_id=? `
- lossPars = append(lossPars, productId)
- permissionCondition += ` AND b.product_id=? `
- permissionPars = append(permissionPars, productId)
- if status == "全部" {
- ////如果是筛选了流失客户状态
- if sysUser.Authority <= 0 {
- condition += ` AND (b.seller_id=? OR status='流失' OR (b.share_seller_id = ? AND b.is_share = 1)) `
- pars = append(pars, sysUser.AdminId, sysUser.AdminId)
- permissionCondition += ` AND (b.seller_id=? OR status='流失' OR (b.share_seller_id = ? AND b.is_share = 1)) `
- permissionPars = append(permissionPars, sysUser.AdminId, sysUser.AdminId)
- } else {
- if sysUser.Authority == 1 {
- condition += ` AND (b.department_id=? OR status='流失')`
- pars = append(pars, sysUser.DepartmentId)
- permissionCondition += ` AND b.department_id=? `
- permissionPars = append(permissionPars, sysUser.DepartmentId)
- }
- if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND (b.group_id=? OR status='流失') `
- pars = append(pars, sysUser.GroupId)
- }
- permissionCondition += ` AND b.group_id=? `
- permissionPars = append(permissionPars, sysUser.GroupId)
- }
- if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
- pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "查询父级id异常" + err.Error()
- return
- }
- var ids []*string
- if pid != nil {
- if *pid != 0 {
- //销售主管放在三级列表中
- ids, err = company.GetGroupIdsByParentId(*pid)
- if err != nil {
- fmt.Println(err.Error())
- }
- } else {
- //销售主管放在二级列表中
- ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
- if err != nil {
- fmt.Println(err.Error())
- }
- }
- }
- var idSlice []string
- var sid string
- for _, id := range ids {
- idSlice = append(idSlice, *id)
- }
- //加入父级groupId
- if *pid > 0 {
- idSlice = append(idSlice, strconv.Itoa(*pid))
- } else {
- idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
- }
- sid = strings.Join(idSlice, ",")
- if len(sid) > 0 {
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
- //pars = append(pars, sysUser.GroupId)
- }
- permissionCondition += ` AND b.group_id IN (` + sid + `) `
- } else {
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
- //pars = append(pars, sysUser.GroupId)
- }
- permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
- }
- //permissionPars = append(permissionPars, sysUser.GroupId)
- }
- if sysUser.Authority == 4 {
- //pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "查询父级id异常" + err.Error()
- // return
- //}
- //ids,err := company.GetGroupIdsByParentId(*pid)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "查询父级id异常" + err.Error()
- // return
- //}
- //var idSlice []string
- //var sid string
- //for _, id := range ids {
- // idSlice = append(idSlice, *id)
- //}
- //sid = strings.Join(idSlice,",")
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND (b.group_id =? OR status='流失') `
- pars = append(pars, sysUser.GroupId)
- }
- permissionCondition += ` AND b.group_id=? `
- permissionPars = append(permissionPars, sysUser.GroupId)
- }
- }
- } else {
- //如果没有筛选了流失客户状态,那么需要加客户归属条件加入到查询中去
- if sysUser.Authority <= 0 {
- if status != utils.COMPANY_STATUS_LOSE {
- //condition += ` AND b.seller_id=? `
- //pars = append(pars, sysUser.AdminId)
- // 是否包含共享客户(新增合同时, 关键词搜索客户为true)
- if includeShare {
- condition += ` AND (b.seller_id = ? OR (b.share_seller_id = ? AND b.is_share = 1)) `
- pars = append(pars, sysUser.AdminId, sysUser.AdminId)
- } else {
- condition += ` AND b.seller_id = ? `
- pars = append(pars, sysUser.AdminId)
- }
- }
- permissionCondition += ` AND (b.seller_id=? OR (b.share_seller_id = ? AND b.is_share = 1)) `
- permissionPars = append(permissionPars, sysUser.AdminId, sysUser.AdminId)
- } else {
- if sysUser.Authority == 1 {
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND b.department_id=?`
- pars = append(pars, sysUser.DepartmentId)
- }
- permissionCondition += ` AND b.department_id=? `
- permissionPars = append(permissionPars, sysUser.DepartmentId)
- }
- if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND b.group_id=? `
- pars = append(pars, sysUser.GroupId)
- }
- permissionCondition += ` AND b.group_id=? `
- permissionPars = append(permissionPars, sysUser.GroupId)
- }
- if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
- pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "查询父级id异常" + err.Error()
- return
- }
- var ids []*string
- if pid != nil {
- if *pid != 0 {
- //销售主管放在三级列表中
- ids, err = company.GetGroupIdsByParentId(*pid)
- if err != nil {
- fmt.Println(err.Error())
- }
- } else {
- //销售主管放在二级列表中
- ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
- if err != nil {
- fmt.Println(err.Error())
- }
- }
- }
- var idSlice []string
- var sid string
- for _, id := range ids {
- idSlice = append(idSlice, *id)
- }
- //加入父级groupId
- if *pid > 0 {
- idSlice = append(idSlice, strconv.Itoa(*pid))
- } else {
- idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
- }
- sid = strings.Join(idSlice, ",")
- if len(sid) > 0 {
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
- //pars = append(pars, sysUser.GroupId)
- }
- permissionCondition += ` AND b.group_id IN (` + sid + `) `
- } else {
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
- //pars = append(pars, sysUser.GroupId)
- }
- permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
- }
- }
- if sysUser.Authority == 4 {
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND b.group_id =? `
- pars = append(pars, sysUser.GroupId)
- }
- permissionCondition += ` AND b.group_id=? `
- permissionPars = append(permissionPars, sysUser.GroupId)
- }
- }
- }
- }
- }
- }
- //状态控制
- if status != "" && status != "全部" {
- //switch status {
- //case "试用-活跃":
- // condition += ` AND b.status="试用" and b.view_total>= ? `
- // pars = append(pars, statistic_report.ActiveViewNum)
- //case "试用-非活跃":
- // condition += ` AND b.status="试用" and b.view_total < ? `
- // pars = append(pars, statistic_report.ActiveViewNum)
- //default:
- // condition += ` AND b.status=? `
- // pars = append(pars, status)
- //}
- condition += ` AND b.status=? `
- pars = append(pars, status)
- // 试用客户标签
- if status == "试用" && tryStage > 0 {
- condition += ` AND b.try_stage=? `
- pars = append(pars, tryStage)
- }
- }
- total, err := company.GetCompanyListCount(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
- return
- }
- //
- sortStr := ``
- if !sortByTodo {
- if sortParam != "" && sortType != "" {
- if sortParam == "expireDay" {
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- if sortType == "asc" {
- sortStr = " ORDER BY min_end_date"
- } else {
- sortStr = " ORDER BY max_end_date"
- }
- } else {
- sortStr = " ORDER BY b.end_date "
- }
- } else if sortParam == "createTime" {
- sortStr = " ORDER BY a.created_time "
- } else if sortParam == "viewTotal" {
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- sortStr = " ORDER BY all_view_total"
- } else {
- sortStr = " ORDER BY b.view_total "
- }
- } else if sortParam == "viewTime" {
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- if sortType == "asc" {
- sortStr = " ORDER BY min_last_view_time"
- } else {
- sortStr = " ORDER BY max_last_view_time"
- }
- } else {
- sortStr = " ORDER BY b.last_view_time "
- }
- } else if sortParam == "roadShowTotal" {
- sortStr = " ORDER BY b.road_show_total "
- } else if sortParam == "formalTime" {
- sortStr = " ORDER BY b.formal_time "
- } else if sortParam == "freezeTime" {
- sortStr = " ORDER BY b.freeze_time "
- } else if sortParam == "lossTime" {
- sortStr = " ORDER BY b.loss_time "
- } else if sortParam == "todoCreateTime" {
- sortStr = " ORDER BY b.todo_create_time "
- } else if sortParam == "todoApproveTime" {
- sortStr = " ORDER BY b.todo_approve_time "
- } else if sortParam == "tryStage" && status == "试用" {
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- sortStr = " ORDER BY sort_try_stage asc, all_view_total desc, a.created_time desc"
- } else {
- sortStr = " ORDER BY sort_try_stage asc, b.view_total desc, a.created_time desc"
- }
- } else if sortParam == "deadline" {
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- sortStr = " ORDER BY sort_todo_end_time asc, all_view_total desc, a.created_time desc"
- } else {
- sortStr = " ORDER BY sort_todo_end_time asc, b.view_total desc, a.created_time desc"
- }
- } else if sortParam == "tryOutDay" {
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- sortStr = " ORDER BY all_try_out_day_total "
- } else {
- sortStr = " ORDER BY b.try_out_day_total "
- }
- } else if sortParam == "closeTime" {
- sortStr = " ORDER BY b.close_time "
- } else {
- br.Msg = "获取失败"
- br.ErrMsg = "排序字段传入数据异常:" + sortParam
- return
- }
- if sortParam != "tryStage" && sortParam != "deadline" {
- if sortType == "asc" {
- sortStr += " ASC "
- } else if sortType == "desc" {
- sortStr += " DESC "
- } else {
- br.Msg = "获取失败"
- br.ErrMsg = "排序类型传入数据异常:" + sortType
- return
- }
- }
- } else {
- //2、客户列表选择“全部”时,支持按照“状态和阅读数”对“全部”分类下所有客户列表进行升降序排列;选择“正式”时按照“转正时间”、选择“冻结”时按照“冻结时间”、选择“流失”时按照“流失时间”、选择“永续”时按照“创建时间”;
- if status == "全部" {
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- sortStr = " ORDER BY sort_status asc, all_view_total desc, a.created_time "
- } else {
- sortStr = " ORDER BY sort_status asc, b.view_total desc, a.created_time "
- }
- } else if status == "永续" {
- sortStr = " ORDER BY a.created_time "
- } else if status == "正式" {
- // 正式客户默认按照周阅读活跃ASC, 同为不活跃则按照转正时间DESC
- sortStr = " ORDER BY week_view_active ASC, b.formal_time "
- //sortStr = " ORDER BY b.formal_time "
- } else if status == "冻结" {
- sortStr = " ORDER BY b.freeze_time "
- } else if status == "流失" {
- sortStr = " ORDER BY b.loss_time "
- } else if status == "试用" {
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- sortStr = " ORDER BY all_view_total desc, a.created_time "
- } else {
- sortStr = " ORDER BY b.view_total desc, a.created_time "
- }
- } else if status == utils.COMPANY_STATUS_CLOSE {
- // 关闭客户按照关闭时间DESC
- sortStr = " ORDER BY b.close_time "
- }
- sortStr += " DESC "
- }
- } else {
- sortStr = " ORDER BY FIELD (todo_status,'未完成','已完成','无任务'), todo_modify_time DESC "
- }
- //任务状态
- if todoStatus != "" {
- //排序,筛选出的未完成、已完成客户列表排序分别按照 最近一个任务的创建时间、最近一个任务的审核时间排序;
- switch todoStatus {
- case "未完成":
- if sortStr != "" {
- sortStr += " ,b.todo_create_time desc "
- } else {
- sortStr = " ORDER BY b.todo_create_time desc "
- }
- case "已完成":
- if sortStr != "" {
- sortStr += " ,b.todo_approve_time desc "
- } else {
- sortStr = " ORDER BY b.todo_approve_time desc "
- }
- }
- }
- list, err := company.GetCompanyList(condition, status, sortStr, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- //企业用户数组切片
- companyIdSlice := make([]string, 0)
- companyIds := make([]int, 0)
- for _, v := range list {
- companyIdSlice = append(companyIdSlice, strconv.Itoa(v.CompanyId))
- companyIds = append(companyIds, v.CompanyId)
- }
- //企业用户产品开通数
- companyIdStr := strings.Join(companyIdSlice, ",")
- companyProductTotalList, _ := company.GetCountProductByCompanyIds(companyIdStr)
- companyProductTotalMap := make(map[int]*company.CompanyProductTotalSlice)
- for _, companyProductTotal := range companyProductTotalList {
- companyProductTotalMap[companyProductTotal.CompanyId] = companyProductTotal
- }
- lenList := len(list)
- //companyFiccViewTimeMap := make(map[int]time.Time)
- //companyRaiViewTimeMap := make(map[int]time.Time)
- //companyFiccViewTotal := make(map[int]int)
- //companyRaiViewTotal := make(map[int]int)
- //获取最近阅读时间 和 累计阅读次数
- //if lenList > 0 {
- // //ficc 或者 全品种
- // if productId == 1 || productId == 0 {
- // companyFiccViewTimeMap, err = services.GetFiccLastUserViewHistoryByCompanyIds(companyIdStr)
- // if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取数据失败,Err:" + err.Error()
- // return
- // }
- // }
- //
- // if productId == 2 || productId == 0 {
- // companyRaiViewTimeMap, err = services.GetRaiLastUserViewHistoryByCompanyIds(companyIdStr)
- // if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取数据失败,Err:" + err.Error()
- // return
- // }
- // }
- //
- // companyFiccViewTotal, err = services.GetFiccCountUserViewHistoryByCompanyIds(companyIdStr)
- // if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取ficc阅读数据失败,Err:" + err.Error()
- // return
- // }
- // companyRaiViewTotal, err = services.GetRaiCountUserViewHistoryByCompanyIds(companyIdStr)
- // if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取权益阅读数据失败,Err:" + err.Error()
- // return
- // }
- //}
- // 客户产品详细信息
- companyProductMap := make(map[string]*company.CompanyProduct)
- var companyProductCondition string
- var companyProductPars []interface{}
- switch companyType {
- case "ficc":
- companyProductCondition += ` AND product_id=? `
- companyProductPars = append(companyProductPars, 1)
- case "权益":
- companyProductCondition += ` AND product_id=? `
- companyProductPars = append(companyProductPars, 2)
- default:
- }
- companyProductList, err := company.GetCompanyProductsByCompanyIds(companyIdStr, companyProductCondition, companyProductPars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取客户产品数据失败,Err:" + err.Error()
- return
- }
- for _, companyProduct := range companyProductList {
- key := fmt.Sprint(companyProduct.CompanyId, "_", companyProduct.ProductId)
- companyProductMap[key] = companyProduct
- }
- //任务待办
- companyTodoMap := make(map[string]*company_todo.CompanyTodo)
- {
- var companyTodoCondition string
- var companyTodoPars []interface{}
- switch companyType {
- case "ficc":
- companyTodoCondition += ` AND product_id=? `
- companyTodoPars = append(companyTodoPars, 1)
- case "权益":
- companyTodoCondition += ` AND product_id=? `
- companyTodoPars = append(companyTodoPars, 2)
- default:
- }
- companyTodoList, err := company_todo.GetDoingCompanyTodoByCompanyIds(companyIdStr, companyTodoCondition, companyTodoPars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取客户产品数据失败,Err:" + err.Error()
- return
- }
- for _, companyTodo := range companyTodoList {
- key := fmt.Sprint(companyTodo.CompanyId)
- companyTodoMap[key] = companyTodo
- }
- }
- // 查询是否有服务记录
- btnServiceRecordMap := make(map[int]bool)
- if len(companyIds) > 0 {
- serRecOB := new(company.CompanyServiceRecord)
- serRecCond := ` AND company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `) AND company_type = ? `
- serRecPars := make([]interface{}, 0)
- serRecPars = append(serRecPars, companyIds, 2)
- serRecs, e := serRecOB.GetItemsByCondition(serRecCond, serRecPars, []string{"company_service_record_id", "company_id"}, "")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取客户服务记录失败, Err: " + e.Error()
- return
- }
- for _, s := range serRecs {
- btnServiceRecordMap[s.CompanyId] = true
- }
- }
- // 查询当前销售是否有领取客户的权限
- receiveEnabled, _ := services.CheckCompanyReceiveButton(sysUser.AdminId)
- for i := 0; i < lenList; i++ {
- item := list[i]
- //校验该客户是否存在多个产品,如果是,那么代表是共享客户
- if companyProductTotal, ok := companyProductTotalMap[int(item.CompanyId)]; ok {
- if companyProductTotal.Total > 1 {
- list[i].IsShared = true
- }
- }
- var expireDay string
- itemStatus := item.Status
- item.Status = strings.Replace(item.Status, utils.COMPANY_STATUS_FOREVER, utils.COMPANY_STATUS_X_CLASS_TRY_OUT, -1) // 永续客户类型,映射成 X类试用
- if itemStatus != "" {
- if !strings.Contains(item.Status, "/") {
- if itemStatus == utils.COMPANY_STATUS_FOREVER { //永续
- expireDay = "-"
- } else if itemStatus == utils.COMPANY_STATUS_TRY_OUT || itemStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
- if item.StartDate != "" && item.EndDate != "" {
- endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
- endDateTime = endDateTime.AddDate(0, 0, 1)
- sub := endDateTime.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
- } else {
- expireDay = "-"
- }
- } else if itemStatus == utils.COMPANY_STATUS_LOSE {
- expireDay = "-"
- } else if itemStatus == utils.COMPANY_STATUS_FREEZE {
- if item.StartDate != "" && item.EndDate != "" {
- endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
- endDateTime = endDateTime.AddDate(0, 0, 0)
- sub := endDateTime.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
- } else {
- expireDay = "-"
- }
- } else {
- expireDay = "-"
- }
- } else {
- tmpStatusArr := strings.Split(item.Status, "/")
- ficcStatus := tmpStatusArr[0]
- raiStatus := tmpStatusArr[1]
- var ficcEndDate, tryEndDate string
- var ficcExpireDay, tryExpireDay string
- if item.EndDate != "" {
- endDateArr := strings.Split(item.EndDate, "/")
- if len(endDateArr) == 1 {
- ficcEndDate = endDateArr[0]
- } else if len(endDateArr) > 1 {
- ficcEndDate = endDateArr[0]
- tryEndDate = endDateArr[1]
- }
- if ficcStatus == utils.COMPANY_STATUS_FOREVER { //永续
- ficcExpireDay = "-"
- } else if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
- if ficcEndDate != "" {
- endDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
- endDateTime = endDateTime.AddDate(0, 0, 1)
- sub := endDateTime.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- ficcExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
- } else {
- ficcExpireDay = "-"
- }
- } else if ficcStatus == utils.COMPANY_STATUS_LOSE { //流失
- ficcExpireDay = "-"
- } else if ficcStatus == utils.COMPANY_STATUS_FREEZE { //冻结
- if item.StartDate != "" && item.EndDate != "" {
- endDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
- endDateTime = endDateTime.AddDate(0, 0, 0)
- sub := endDateTime.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- ficcExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
- } else {
- ficcExpireDay = "-"
- }
- } else {
- ficcExpireDay = "-"
- }
- if raiStatus == utils.COMPANY_STATUS_FOREVER { //永续
- tryExpireDay = "-"
- } else if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
- if tryEndDate != "" {
- endDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
- endDateTime = endDateTime.AddDate(0, 0, 1)
- sub := endDateTime.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- tryExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
- } else {
- tryExpireDay = "-"
- }
- } else if raiStatus == utils.COMPANY_STATUS_LOSE { //流失
- tryExpireDay = "-"
- } else if raiStatus == utils.COMPANY_STATUS_FREEZE { //冻结
- if item.StartDate != "" && item.EndDate != "" {
- endDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
- endDateTime = endDateTime.AddDate(0, 0, 0)
- sub := endDateTime.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- tryExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
- } else {
- tryExpireDay = "-"
- }
- } else {
- tryExpireDay = "-"
- }
- }
- expireDay = ficcExpireDay + "/" + tryExpireDay
- }
- }
- list[i].ExpireDay = expireDay
- //按钮显示控制
- btnItem := new(company.ButtonPermission)
- if item.CompanyId != 1 {
- *btnItem = services.GetCompanyPermissionButton(roleTypeCode, itemStatus, item.SellerIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, -1, item.ShareSellerIds)
- //根据销售"领取客户"的权限对部分按钮做限制
- btnItem = services.GetCompanyPermissionButtonByReceiveEnabled(btnItem, receiveEnabled)
- }
- if list[i].IsShare == 1 && btnItem.BtnModifySeller == true && roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
- //如果已经是共享客户了,取消共享按钮全都显示,和修改销售权限一样
- btnItem.BtnShare = true
- }
- if list[i].Status == utils.COMPANY_STATUS_FREEZE && list[i].CompanyType == utils.COMPANY_CLASSIFY_RAI && btnItem.BtnModifySeller == true && roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
- //权益冻结客户,也可以设置共享。冻结客户操作栏,增加设置共享按钮,可见权限不变(仅对权益管理员开放)
- btnItem.BtnShare = true
- }
- list[i].BtnItem = btnItem
- if item.FreezeStartDate != "" && item.FreezeEndDate != "" && item.Status == utils.COMPANY_STATUS_FREEZE {
- freezeEndDate, _ := time.Parse(utils.FormatDate, item.FreezeEndDate)
- if time.Now().Before(freezeEndDate) {
- expireDays := freezeEndDate.Sub(time.Now()).Hours() / 24
- list[i].FreezeExpireDays = int(expireDays) + 1
- }
- }
- btnItem.BtnServiceRecord = btnServiceRecordMap[list[i].CompanyId]
- //productIdArr := strings.Split(item.ProductIds, "/")
- //// 套餐类型
- //packageTypeArr := strings.Split(item.PackageTypes, "/")
- //viewTotalArr := strings.Split(item.ViewTotals, "/") //总阅读次数
- //lastViewTimeArr := strings.Split(item.LastViewTimes, "/") //最近阅读时间
- //if len(productIdArr) > 1 {
- // if len(packageTypeArr) == 1 {
- // item.PackageTypes = item.PackageTypes + "/" + item.PackageTypes
- // packageTypeArr = strings.Split(item.PackageTypes, "/")
- // }
- // //阅读次数
- // if len(viewTotalArr) == 1 {
- // item.ViewTotals = item.ViewTotals + "/" + item.ViewTotals
- // viewTotalArr = strings.Split(item.ViewTotals, "/") //总阅读次数
- // }
- //
- // if len(lastViewTimeArr) == 1 {
- // item.LastViewTimes = item.LastViewTimes + "/" + item.LastViewTimes
- // lastViewTimeArr = strings.Split(item.LastViewTimes, "/") //最近阅读时间
- // }
- //}
- //for i, tmpProductId := range productIdArr {
- // packageTypeInt, _ := strconv.Atoi(packageTypeArr[i])
- // viewTotalInt, _ := strconv.Atoi(viewTotalArr[i])
- // lastViewTime := lastViewTimeArr[i]
- // //ficc
- // if tmpProductId == "1" {
- // //套餐类型
- // item.FiccPackageType = packageTypeInt
- //
- // //总阅读次数
- // item.FiccView = viewTotalInt
- //
- // //最近一次阅读时间
- // item.FiccLastViewTime = lastViewTime
- // }
- // //权益
- // if tmpProductId == "2" {
- // //总阅读次数
- // item.RaiView = viewTotalInt
- //
- // //最近一次阅读时间
- // item.RaiLastViewTime = lastViewTime
- // }
- //}
- ficcKey := fmt.Sprint(item.CompanyId, "_", 1)
- //ficc
- if tmpCompanyProduct, ok := companyProductMap[ficcKey]; ok {
- //套餐类型
- item.FiccPackageType = tmpCompanyProduct.PackageType
- //总试用天数
- item.FiccTryOutDay = tmpCompanyProduct.TryOutDayTotal
- //总阅读次数
- item.FiccView = tmpCompanyProduct.ViewTotal
- if !tmpCompanyProduct.LastViewTime.IsZero() {
- //最近一次阅读时间
- item.FiccLastViewTime = tmpCompanyProduct.LastViewTime.Format(utils.FormatDateTime)
- }
- }
- //权益
- raiKey := fmt.Sprint(item.CompanyId, "_", 2)
- if tmpCompanyProduct, ok := companyProductMap[raiKey]; ok {
- //总阅读次数
- item.RaiView = tmpCompanyProduct.ViewTotal
- //总试用天数
- item.RaiTryOutDay = tmpCompanyProduct.TryOutDayTotal
- if !tmpCompanyProduct.LastViewTime.IsZero() {
- //最近一次阅读时间
- item.RaiLastViewTime = tmpCompanyProduct.LastViewTime.Format(utils.FormatDateTime)
- }
- }
- //最近阅读时间
- //if viewTime, ok := companyFiccViewTimeMap[item.CompanyId]; ok {
- // item.FiccLastViewTime = viewTime.Format(utils.FormatDateTime)
- //}
- //
- //if viewTime, ok := companyRaiViewTimeMap[item.CompanyId]; ok {
- // item.RaiLastViewTime = viewTime.Format(utils.FormatDateTime)
- //}
- // 试用客户子标签
- if strings.Contains(item.Status, "试用") {
- statusSlice := strings.Split(item.Status, "/")
- stageItemSlice := strings.Split(item.TryStageStr, "/")
- productIdSlice := strings.Split(item.ProductIds, "/")
- for sk, sv := range statusSlice {
- if sv != "试用" {
- continue
- }
- tryItem := new(company.TryStageSliceItem)
- if len(productIdSlice) < (sk+1) || len(stageItemSlice) < (sk+1) {
- continue
- }
- key := fmt.Sprint(item.CompanyId, "_", productIdSlice[sk])
- if pro, ok := companyProductMap[key]; ok {
- tryItem.ProductId, _ = strconv.Atoi(productIdSlice[sk])
- if pro.SellerId == sysUser.AdminId { //产品销售ID和登录ID相等
- tryItem.HasPermission = true
- }
- tryItem.TryStage, _ = strconv.Atoi(stageItemSlice[sk])
- list[i].TryStageSlice = append(list[i].TryStageSlice, tryItem)
- }
- }
- }
- // To-Do任务状态为未完成的对应任务的截止日期-当前日期;
- if strings.Contains(item.TodoStatuss, "未完成") {
- if strings.Contains(item.TodoEndTimeStr, "/") {
- edtSlice := strings.Split(item.TodoEndTimeStr, "/")
- item.TodoEndTime, _ = time.ParseInLocation(utils.FormatDateTime, edtSlice[0], time.Local)
- } else {
- item.TodoEndTime, _ = time.ParseInLocation(utils.FormatDateTime, item.TodoEndTimeStr, time.Local)
- }
- tmpEndTime := item.TodoEndTime.Format(utils.FormatDate)
- if tmpEndTime == "0001-01-01" {
- tmpEndTime = ""
- }
- if tmpEndTime != "" {
- dlTime1 := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 0, 0, 0, 0, time.Local)
- dlTime2 := time.Date(item.TodoEndTime.Year(), item.TodoEndTime.Month(), item.TodoEndTime.Day(), 0, 0, 0, 0, time.Local)
- dldays := int(dlTime2.Sub(dlTime1).Hours() / 24)
- list[i].Deadline = strconv.Itoa(dldays)
- }
- }
- }
- statusCount, err := company.GetCompanyStatusCount(permissionCondition, permissionPars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取状态数量失败,Err:" + err.Error()
- return
- }
- statusMap := make(map[string]int, 0)
- var totalCount int
- for _, sv := range statusCount {
- sv.Status = strings.Replace(sv.Status, utils.COMPANY_STATUS_FOREVER, utils.COMPANY_STATUS_X_CLASS_TRY_OUT, -1) // 永续客户类型,映射成 X类试用
- totalCount = totalCount + sv.Count
- statusMap[sv.Status] = sv.Count
- }
- // 统计试用客户的子标签数量,只在试用状态页面统计
- var tryStageCountResp []*company.CompanyTryStageCount
- if status == "试用" {
- tryStageCount, err := company.GetCompanyTryStageCount(permissionCondition, permissionPars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取试用状态标签数量失败,Err:" + err.Error()
- return
- }
- tryStageMap := make(map[int]int)
- for _, v := range tryStageCount {
- tryStageMap[0] += v.Count
- tryStageMap[v.TryStage] = v.Count
- }
- tryStageAllMap := map[int]string{
- 0: "全部",
- 2: "推进",
- 3: "跟踪",
- 4: "预备",
- 1: "未分类",
- }
- for k, v := range tryStageAllMap {
- item := new(company.CompanyTryStageCount)
- item.TryStageStr = v
- item.TryStage = k
- if count, ok := tryStageMap[k]; ok {
- item.Count = count
- }
- tryStageCountResp = append(tryStageCountResp, item)
- }
- }
- //
- ////试用-活跃
- //{
- // tmpPermissionCondition := permissionCondition
- // tmpPermissionPars := permissionPars
- // tmpPermissionCondition += ` and b.view_total>=? `
- // tmpPermissionPars = append(tmpPermissionPars, statistic_report.ActiveViewNum)
- //
- // tryOutActiveCount, err := company.GetCompanyTryOutStatusCount(tmpPermissionCondition, tmpPermissionPars)
- // if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取状态数量失败,Err:" + err.Error()
- // return
- // }
- // statusMap["试用-活跃"] = tryOutActiveCount.Count
- //}
- //
- ////试用-非活跃
- //{
- // tmpPermissionCondition := permissionCondition
- // tmpPermissionPars := permissionPars
- // tmpPermissionCondition += ` and b.view_total <? `
- // tmpPermissionPars = append(tmpPermissionPars, statistic_report.ActiveViewNum)
- //
- // tryOutActiveCount, err := company.GetCompanyTryOutStatusCount(tmpPermissionCondition, tmpPermissionPars)
- // if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取状态数量失败,Err:" + err.Error()
- // return
- // }
- // statusMap["试用-非活跃"] = tryOutActiveCount.Count
- //}
- lossItem, err := company.GetCompanyStatusLoseCount(lossCondition, lossPars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取流失状态数量失败,Err:" + err.Error()
- return
- }
- totalCount = totalCount + lossItem.Count
- for _, v := range statusArr {
- s := new(company.CompanyStatus)
- if v == "全部" {
- s.Status = "全部"
- s.Count = totalCount
- } else if v == utils.COMPANY_STATUS_LOSE {
- s.Status = v
- s.Count = lossItem.Count
- } else {
- s.Status = v
- if val, ok := statusMap[v]; ok {
- s.Count = val
- }
- }
- statusItems = append(statusItems, s)
- }
- sysUserList, err := system.GetAdminList()
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取admin列表失败, Err:" + err.Error()
- return
- }
- adminMap := make(map[int]*system.Admin, 0)
- for _, v := range sysUserList {
- adminMap[v.AdminId] = v
- }
- companyLists := make([]*company.CompanyListItem, 0)
- //查询阅读次数
- if list == nil {
- companyLists = make([]*company.CompanyListItem, 0)
- } else {
- for _, v := range list {
- //viewTotal:=GetviewTotal(v.CompanyId)
- //活跃(客户状态)
- //if v.IsShare != 1 {
- // if v.BtnItem.BtnModifySeller == true {
- // v.BtnItem.BtnModifySeller = false
- // }
- //}
- //productIdSlice := strings.Split(v.ProductIds, "/")
- //statusSlice := strings.Split(v.Status, "/")
- //for productIndex, tmpProductId := range productIdSlice {
- // tmpStatusIndex := 0
- // if len(statusSlice) > 1 {
- // tmpStatusIndex = productIndex
- // }
- // tmpProductStatus := statusSlice[tmpStatusIndex]
- // if strings.Contains(tmpProductStatus, "试用") {
- // activeType := "非活跃"
- // viewNum := v.FiccView
- // if tmpProductId == "2" {
- // viewNum = v.RaiView
- // }
- // if viewNum >= statistic_report.ActiveViewNum {
- // activeType = "活跃"
- // }
- // statusSlice[tmpStatusIndex] = fmt.Sprint(tmpProductStatus, "(", activeType, ")")
- //
- // tmpStatus = strings.Join(statusSlice, "/")
- // }
- //}
- //ficcViewTotal, ok := companyFiccViewTotal[v.CompanyId]
- //if !ok {
- // ficcViewTotal = 0
- //}
- //raiViewTotal, ok := companyRaiViewTotal[v.CompanyId]
- //if !ok {
- // raiViewTotal = 0
- //}
- // 是否存在进行中的任务
- var todoStatus bool
- if _, ok := companyTodoMap[fmt.Sprint(v.CompanyId)]; ok {
- todoStatus = true
- }
- //是否支持确认完成待办任务
- var canConfirm bool
- var hiddenConfirm bool //是否隐藏确定完成按钮
- var hiddenCreate bool //是否隐藏新增/编辑按钮
- hiddenConfirm = true
- hiddenCreate = true
- for _, vProductId := range []int{1, 2} {
- ficcKey := fmt.Sprint(v.CompanyId, "_", vProductId)
- //ficc
- if tmpCompanyProduct, ok := companyProductMap[ficcKey]; ok {
- if tmpCompanyProduct.Status != utils.COMPANY_STATUS_LOSE && tmpCompanyProduct.Status != utils.COMPANY_STATUS_CLOSE { //非流失或关闭
- hiddenCreate = false
- switch this.SysUser.RoleTypeCode {
- case utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_RAI_ADMIN, utils.ROLE_TYPE_CODE_FICC_GROUP, utils.ROLE_TYPE_CODE_RAI_GROUP:
- //部门管理员、ficc主管、权益组长
- hiddenConfirm = false //不展示
- if todoStatus { //有任务,需要展示
- canConfirm = true
- }
- case utils.ROLE_TYPE_CODE_FICC_TEAM: //ficc组长
- if todoStatus { //有任务,需要展示
- canConfirm = true
- }
- if v.SellerId != this.SysUser.AdminId { //不是自己的客户
- hiddenConfirm = false //展示
- }
- case utils.ROLE_TYPE_CODE_RAI_SELLER: //权益销售
- if v.SellerId == this.SysUser.AdminId { //是自己的客户
- has := services.CheckRaiApprovePermission(sysUser.AdminId) //这些个权益销售是有权限的
- if has {
- if todoStatus { //有任务,需要展示
- canConfirm = true
- }
- hiddenConfirm = false //展示
- }
- }
- }
- }
- }
- }
- todoButtonColor := `green`
- //'无任务','未完成','已完成'
- if strings.Contains(v.TodoStatuss, "未完成") {
- todoButtonColor = "red"
- } else if strings.Contains(v.TodoStatuss, "已完成") {
- todoButtonColor = "green"
- } else if strings.Contains(v.TodoStatuss, "无任务") {
- todoButtonColor = "gray"
- }
- //永续客户X类试用客户出参转换
- v.StatusStr = strings.Replace(v.StatusStr, utils.COMPANY_STATUS_FOREVER, utils.COMPANY_STATUS_X_CLASS_TRY_OUT, -1)
- if !utils.InArrayByStr([]string{"正式", "试用", "永续", "X类试用"}, v.Status) { //不是这几种状态不做标红处理
- v.IsUserMaker = 0
- }
- //解决共享客户正式筛选下是否标红的问题
- if v.WeekViewActive == 0 && v.IsUserMaker == 1 {
- v.WeekViewActive = 1
- }
- companyList := &company.CompanyListItem{
- CompanyId: v.CompanyId,
- CompanyName: v.CompanyName,
- CreditCode: v.CreditCode,
- CompanyCode: v.CompanyCode,
- StartDate: v.StartDate,
- EndDate: v.EndDate,
- LoseReason: v.LoseReason,
- RenewalReason: v.RenewalReason,
- FreezeReason: v.FreezeReason,
- LossTime: v.LossTime,
- Status: v.StatusStr,
- CompanyType: v.CompanyType,
- ApproveStatus: v.ApproveStatus,
- SellerName: v.SellerName,
- SellerId: v.SellerId,
- SellerIds: v.SellerIds,
- ExpireDay: v.ExpireDay,
- FreezeTime: v.FreezeTime,
- GroupId: v.GroupId,
- GroupIds: v.GroupIds,
- DepartmentId: v.DepartmentId,
- IndustryName: v.IndustryName,
- IsSuspend: v.IsSuspend,
- CreatedTime: v.CreatedTime,
- Source: v.Source,
- Province: v.Province,
- City: v.City,
- Address: v.Address,
- Reasons: v.Reasons,
- FreezeStartDate: v.FreezeStartDate,
- FreezeEndDate: v.FreezeEndDate,
- FreezeExpireDays: v.FreezeExpireDays,
- BtnItem: v.BtnItem,
- ProductId: v.ProductId,
- FormalTime: v.FormalTime,
- IsShared: v.IsShared,
- RegionType: v.RegionType,
- FiccPackageType: v.FiccPackageType,
- FiccLastViewTime: v.FiccLastViewTime,
- RaiLastViewTime: v.RaiLastViewTime,
- //FiccView: viewTotal[0],
- //RaiView: viewTotal[1],
- //FiccView: ficcViewTotal,
- //RaiView: raiViewTotal,
- FiccView: v.FiccView,
- RaiView: v.RaiView,
- FiccTryOutDay: v.FiccTryOutDay,
- RaiTryOutDay: v.RaiTryOutDay,
- AllViewTotal: v.AllViewTotal,
- RoadShowTotal: v.RoadShowTotal,
- TodoStatus: todoStatus,
- CanConfirm: canConfirm,
- HiddenConfirm: hiddenConfirm,
- HiddenCreate: hiddenCreate,
- TodoButtonColor: todoButtonColor,
- TryStageSlice: v.TryStageSlice,
- Deadline: v.Deadline,
- WeekViewActive: v.WeekViewActive,
- IsShare: v.IsShare,
- CloseTime: v.CloseTime,
- CloseReason: v.CloseReason,
- ShareSellerId: v.ShareSellerId,
- ShareSellerIds: v.ShareSellerIds,
- IsUserMaker: v.IsUserMaker,
- }
- if v.ShareSellerIds != "" {
- shareSellerIds := strings.Split(v.ShareSellerIds, ",")
- for _, idStr := range shareSellerIds {
- shareSellerId, e := strconv.Atoi(idStr)
- if e != nil {
- err = e
- return
- }
- shareSeller := adminMap[shareSellerId]
- if shareSeller != nil {
- companyList.ShareSeller += shareSeller.RealName + "(" + shareSeller.GroupName + ")" + "/"
- }
- }
- companyList.ShareSeller = strings.TrimRight(companyList.ShareSeller, "/")
- }
- companyLists = append(companyLists, companyList)
- }
- }
- if companyLists == nil {
- companyLists = make([]*company.CompanyListItem, 0)
- }
- // 白嫖客户标记
- scroungeList, err := company.GetScroungeCompany()
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取白嫖客户信息失败,Err:" + err.Error()
- return
- }
- scroungeMap := make(map[int]int)
- for _, v := range scroungeList {
- scroungeMap[v.CompanyId] = 1
- }
- for i, v := range companyLists {
- if _, ok := scroungeMap[v.CompanyId]; ok {
- companyLists[i].IsScrounge = 1
- }
- }
- page = paging.GetPaging(currentIndex, pageSize, total)
- resp.List = companyLists
- resp.StatusCount = statusItems
- resp.TryStageCount = tryStageCountResp
- resp.Paging = page
- resp.AddCompanyBtn = receiveEnabled
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- //func (this *CompanyController) ListOld() {
- // br := new(models.BaseResponse).Init()
- // defer func() {
- // this.Data["json"] = br
- // this.ServeJSON()
- // }()
- // sysUser := this.SysUser
- // if sysUser == nil {
- // br.Msg = "请登录"
- // br.ErrMsg = "请登录,SysUser Is Empty"
- // br.Ret = 408
- // return
- // }
- // roleTypeCode := sysUser.RoleTypeCode
- //
- // pageSize, _ := this.GetInt("PageSize")
- // currentIndex, _ := this.GetInt("CurrentIndex")
- // status := this.GetString("Status")
- // companyType := this.GetString("CompanyType")
- // industryId, _ := this.GetInt("IndustryId")
- // adminId := this.GetString("AdminId")
- //
- // chartPermissionIds := this.GetString("ChartPermissionIds")
- // startDate := this.GetString("StartDate")
- // endDate := this.GetString("EndDate")
- // createStartDate := this.GetString("CreateStartDate")
- // createEndDate := this.GetString("CreateEndDate")
- // keyWord := this.GetString("KeyWord")
- // keyWord = strings.Trim(keyWord, " ")
- // keyWord = strings.Replace(keyWord, "'", "", -1)
- //
- // //排序参数
- // sortParam := this.GetString("SortParam")
- // sortType := this.GetString("SortType")
- //
- // var total int
- // page := paging.GetPaging(currentIndex, pageSize, total)
- // resp := new(company.CompanyListResp)
- // statusItems := make([]*company.CompanyStatus, 0)
- // var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}
- //
- // var startSize int
- // if pageSize <= 0 {
- // pageSize = utils.PageSize20
- // }
- // if currentIndex <= 0 {
- // currentIndex = 1
- // }
- // startSize = paging.StartIndex(currentIndex, pageSize)
- // var condition string
- // var pars []interface{}
- //
- // //流失
- // var lossCondition string
- // var lossPars []interface{}
- // //冻结
- // var freezeCondition string
- // var freezePars []interface{}
- //
- // //永续
- // var forverCondition string
- // var forverPars []interface{}
- //
- // var permissionCondition string
- // var permissionPars []interface{}
- //
- // if status != "" && status != "全部" {
- // condition += ` AND b.status=? `
- // pars = append(pars, status)
- //
- // //permissionCondition += ` AND b.status=? `
- // //permissionPars = append(permissionPars, status)
- // }
- // if companyType != "" {
- // condition += ` AND b.product_name=? `
- // pars = append(pars, companyType)
- //
- // lossCondition += ` AND b.product_name=? `
- // lossPars = append(lossPars, companyType)
- //
- // freezeCondition += ` AND b.product_name=? `
- // freezePars = append(freezePars, companyType)
- //
- // forverCondition += ` AND b.product_name=? `
- // forverPars = append(forverPars, companyType)
- //
- // permissionCondition += ` AND b.product_name=? `
- // permissionPars = append(permissionPars, companyType)
- // }
- //
- // if industryId > 0 {
- // condition += ` AND b.industry_id=? `
- // pars = append(pars, industryId)
- //
- // lossCondition += ` AND b.industry_id=? `
- // lossPars = append(lossPars, industryId)
- //
- // freezeCondition += ` AND b.industry_id=? `
- // freezePars = append(freezePars, industryId)
- //
- // forverCondition += ` AND b.industry_id=? `
- // forverPars = append(forverPars, industryId)
- //
- // permissionCondition += ` AND b.industry_id=? `
- // permissionPars = append(permissionPars, industryId)
- // }
- //
- // if adminId != "" {
- // condition += ` AND b.seller_id IN (` + adminId + `) `
- //
- // lossCondition += ` AND b.seller_id IN (` + adminId + `) `
- //
- // freezeCondition += ` AND b.seller_id IN (` + adminId + `) `
- //
- // forverCondition += ` AND b.seller_id IN (` + adminId + `) `
- //
- // permissionCondition += ` AND b.seller_id IN (` + adminId + `) `
- // }
- //
- // if startDate != "" {
- // condition += ` AND b.start_date>=? `
- // pars = append(pars, startDate)
- //
- // lossCondition += ` AND b.start_date>=? `
- // lossPars = append(lossPars, startDate)
- //
- // freezeCondition += ` AND b.start_date>=? `
- // freezePars = append(freezePars, startDate)
- //
- // forverCondition += ` AND b.start_date>=? `
- // forverPars = append(forverPars, startDate)
- //
- // permissionCondition += ` AND b.start_date>=? `
- // permissionPars = append(permissionPars, startDate)
- // }
- //
- // if endDate != "" {
- // condition += ` AND b.end_date<=? `
- // pars = append(pars, endDate)
- //
- // lossCondition += ` AND b.end_date<=? `
- // lossPars = append(lossPars, endDate)
- //
- // freezeCondition += ` AND b.end_date<=? `
- // freezePars = append(freezePars, endDate)
- //
- // forverCondition += ` AND b.end_date<=? `
- // forverPars = append(forverPars, endDate)
- //
- // permissionCondition += ` AND b.end_date<=? `
- // permissionPars = append(permissionPars, endDate)
- // }
- //
- // if createStartDate != "" {
- // condition += ` AND a.created_time>=? `
- // pars = append(pars, createStartDate)
- //
- // lossCondition += ` AND a.created_time>=? `
- // lossPars = append(lossPars, createStartDate)
- //
- // freezeCondition += ` AND a.created_time>=? `
- // freezePars = append(freezePars, createStartDate)
- //
- // forverCondition += ` AND a.created_time>=? `
- // forverPars = append(forverPars, createStartDate)
- //
- // permissionCondition += ` AND a.created_time>=? `
- // permissionPars = append(permissionPars, createStartDate)
- // }
- //
- // if createEndDate != "" {
- // condition += ` AND a.created_time<=? `
- // pars = append(pars, createEndDate)
- //
- // lossCondition += ` AND a.created_time<=? `
- // lossPars = append(lossPars, createEndDate)
- //
- // freezeCondition += ` AND a.created_time<=? `
- // freezePars = append(freezePars, createEndDate)
- //
- // forverCondition += ` AND a.created_time<=? `
- // forverPars = append(forverPars, createEndDate)
- //
- // permissionCondition += ` AND a.created_time<=? `
- // permissionPars = append(permissionPars, createEndDate)
- // }
- //
- // if keyWord != "" {
- // companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
- // if err != nil {
- // br.Msg = "获取客户信息失败"
- // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- // return
- // }
- // if companyIdStr != "" {
- // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
- // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
- // freezeCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
- // forverCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
- //
- // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
- // } else {
- // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
- // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
- // freezeCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
- // forverCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
- //
- // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
- // }
- // }
- // if chartPermissionIds != "" && chartPermissionIds != "1" {
- // //chartPermissionArr := strings.Split(chartPermissionIds, ",")
- // //chartPermissionCount := len(chartPermissionArr)
- // companyIdStr, err := company.GetCompanyListCompanyIdByPermissionIdStr(chartPermissionIds)
- // if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
- // return
- // }
- // //var companyIdArr []string
- // //for _, v := range companyIdList {
- // // companyIdArr = append(companyIdArr, strconv.Itoa(v.CompanyId))
- // //}
- // //companyIdStr := strings.Join(companyIdArr, ",")
- // if companyIdStr != "" {
- // condition += ` AND a.company_id IN (` + companyIdStr + `) `
- // lossCondition += ` AND a.company_id IN (` + companyIdStr + `) `
- // freezeCondition += ` AND a.company_id IN (` + companyIdStr + `) `
- // forverCondition += ` AND a.company_id IN (` + companyIdStr + `) `
- // permissionCondition += ` AND a.company_id IN (` + companyIdStr + `) `
- // } else {
- // for _, v := range statusArr {
- // statusCount := new(company.CompanyStatus)
- // if v == "全部" {
- // statusCount.Status = "全部"
- // statusCount.Count = 0
- // } else {
- // statusCount.Status = v
- // statusCount.Count = 0
- // }
- // statusItems = append(statusItems, statusCount)
- // }
- // items := make([]*company.CompanyListItem, 0)
- // resp.List = items
- // resp.Paging = page
- // resp.StatusCount = statusItems
- // br.Msg = "获取成功"
- // br.Ret = 200
- // br.Data = resp
- // return
- // }
- // }
- // //权限控制
- // {
- // fmt.Println(roleTypeCode)
- // if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
- // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
- // condition += ` AND b.product_id=? `
- // pars = append(pars, 1)
- //
- // permissionCondition += ` AND b.product_id=? `
- // permissionPars = append(permissionPars, 1)
- // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
- // condition += ` AND b.product_id=? `
- // pars = append(pars, 2)
- //
- // permissionCondition += ` AND b.product_id=? `
- // permissionPars = append(permissionPars, 2)
- // } else {
- // if sysUser.Authority <= 0 {
- // if status == utils.COMPANY_STATUS_TRY_OUT || status == utils.COMPANY_STATUS_FORMAL || status == "全部" {
- // if status == "全部" {
- // condition += ` AND (b.seller_id=? OR status='流失' OR status='永续') `
- // pars = append(pars, sysUser.AdminId)
- // } else {
- // condition += ` AND b.seller_id=? `
- // pars = append(pars, sysUser.AdminId)
- // }
- // }
- // permissionCondition += ` AND b.seller_id=? `
- // permissionPars = append(permissionPars, sysUser.AdminId)
- // } else {
- // if sysUser.Authority == 1 {
- // if status == utils.COMPANY_STATUS_TRY_OUT || status == utils.COMPANY_STATUS_FORMAL || status == "全部" {
- // condition += ` AND b.department_id=? `
- // pars = append(pars, sysUser.DepartmentId)
- //
- // permissionCondition += ` AND b.department_id=? `
- // permissionPars = append(permissionPars, sysUser.DepartmentId)
- // } else {
- // permissionCondition += ` AND b.department_id=? `
- // permissionPars = append(permissionPars, sysUser.DepartmentId)
- // }
- // }
- //
- // if sysUser.Authority == 2 {
- // if status == utils.COMPANY_STATUS_TRY_OUT || status == utils.COMPANY_STATUS_FORMAL || status == "全部" {
- // condition += ` AND b.group_id=? `
- // pars = append(pars, sysUser.GroupId)
- //
- // permissionCondition += ` AND b.group_id=? `
- // permissionPars = append(permissionPars, sysUser.GroupId)
- // } else {
- // permissionCondition += ` AND b.group_id=? `
- // permissionPars = append(permissionPars, sysUser.GroupId)
- // }
- // }
- // }
- // }
- // }
- //
- // //if status == utils.COMPANY_STATUS_FREEZE {
- // // condition += ` AND b.seller_id=? `
- // // pars = append(pars, sysUser.AdminId)
- // //
- // // //permissionCondition += ` AND b.seller_id=? `
- // // //permissionPars = append(permissionPars, sysUser.AdminId)
- // //}
- // //if status == "全部" || status == utils.COMPANY_STATUS_FREEZE {
- // // freezeCondition += ` AND b.seller_id=? `
- // // freezePars = append(freezePars, sysUser.AdminId)
- // //}
- // if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- // //freezeCondition += ` AND b.seller_id=? `
- // //freezePars = append(freezePars, sysUser.AdminId)
- // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
- // permissionCondition += ` AND b.product_id=? `
- // permissionPars = append(permissionPars, 1)
- // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
- // permissionCondition += ` AND b.product_id=? `
- // permissionPars = append(permissionPars, 2)
- // } else {
- // if status == utils.COMPANY_STATUS_FREEZE {
- // condition += ` AND b.seller_id=? `
- // pars = append(pars, sysUser.AdminId)
- // }
- //
- // freezeCondition += ` AND b.seller_id=? `
- // freezePars = append(freezePars, sysUser.AdminId)
- // }
- // }
- //
- // total, err := company.GetCompanyListCount(condition, pars)
- // if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
- // return
- // }
- //
- // sortStr := ``
- // if sortParam != "" && sortType != "" {
- // if sortParam == "endDate" {
- // sortStr = " ORDER BY b.end_date "
- // } else if sortParam == "createTime" {
- // sortStr = " ORDER BY a.created_time "
- // } else {
- // br.Msg = "获取失败"
- // br.ErrMsg = "排序字段传入数据异常:" + sortParam
- // return
- // }
- //
- // if sortType == "asc" {
- // sortStr += " ASC "
- // } else if sortType == "desc" {
- // sortStr += " DESC "
- // } else {
- // br.Msg = "获取失败"
- // br.ErrMsg = "排序类型传入数据异常:" + sortType
- // return
- // }
- // }
- //
- // list, err := company.GetCompanyList(condition, status, sortStr, pars, startSize, pageSize)
- // if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取数据失败,Err:" + err.Error()
- // return
- // }
- //
- //
- // //企业用户数组切片
- // companyIdSlice := make([]string, 0)
- // for _, v := range list {
- // companyIdSlice = append(companyIdSlice, strconv.Itoa(v.CompanyId))
- // }
- //
- // //企业用户产品开通数
- // companyIdStr := strings.Join(companyIdSlice, ",")
- // companyProductTotalList, _ := company.GetCountProductByCompanyIds(companyIdStr)
- // companyProductTotalMap := make(map[int]*company.CompanyProductTotalSlice)
- // for _, companyProductTotal := range companyProductTotalList {
- // companyProductTotalMap[companyProductTotal.CompanyId] = companyProductTotal
- // }
- // lenList := len(list)
- // for i := 0; i < lenList; i++ {
- // item := list[i]
- //
- // //校验该客户是否存在多个产品,如果是,那么代表是共享客户
- // if companyProductTotal, ok := companyProductTotalMap[int(item.CompanyId)]; ok {
- // if companyProductTotal.Total > 1 {
- // list[i].IsShared = true
- // }
- // }
- //
- // var expireDay string
- // itemStatus := item.Status
- // if itemStatus != "" {
- // if !strings.Contains(item.Status, "/") {
- // if itemStatus == utils.COMPANY_STATUS_FOREVER { //永续
- // expireDay = "-"
- // } else if itemStatus == utils.COMPANY_STATUS_TRY_OUT || itemStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
- // if item.StartDate != "" && item.EndDate != "" {
- // endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
- // endDateTime = endDateTime.AddDate(0, 0, 1)
- // sub := endDateTime.Sub(time.Now())
- // if sub < 0 {
- // sub = 0
- // }
- // expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
- // } else {
- // expireDay = "-"
- // }
- // } else if itemStatus == utils.COMPANY_STATUS_LOSE {
- // expireDay = "-"
- // } else if itemStatus == utils.COMPANY_STATUS_FREEZE {
- // if item.StartDate != "" && item.EndDate != "" {
- // endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
- // endDateTime = endDateTime.AddDate(0, 0, 0)
- // sub := endDateTime.Sub(time.Now())
- // if sub < 0 {
- // sub = 0
- // }
- // expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
- // } else {
- // expireDay = "-"
- // }
- // } else {
- // expireDay = "-"
- // }
- // } else {
- // statusArr := strings.Split(item.Status, "/")
- // ficcStatus := statusArr[0]
- // raiStatus := statusArr[1]
- // var ficcEndDate, tryEndDate string
- // var ficcExpireDay, tryExpireDay string
- // if item.EndDate != "" {
- // endDateArr := strings.Split(item.EndDate, "/")
- // if len(endDateArr) == 1 {
- // ficcEndDate = endDateArr[0]
- // } else if len(endDateArr) > 1 {
- // ficcEndDate = endDateArr[0]
- // tryEndDate = endDateArr[1]
- // }
- // if ficcStatus == utils.COMPANY_STATUS_FOREVER { //永续
- // ficcExpireDay = "-"
- // } else if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
- // if ficcEndDate != "" {
- // endDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
- // endDateTime = endDateTime.AddDate(0, 0, 1)
- // sub := endDateTime.Sub(time.Now())
- // if sub < 0 {
- // sub = 0
- // }
- // ficcExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
- // } else {
- // ficcExpireDay = "-"
- // }
- // } else if ficcStatus == utils.COMPANY_STATUS_LOSE { //流失
- // ficcExpireDay = "-"
- // } else if ficcStatus == utils.COMPANY_STATUS_FREEZE { //冻结
- // if item.StartDate != "" && item.EndDate != "" {
- // endDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
- // endDateTime = endDateTime.AddDate(0, 0, 0)
- // sub := endDateTime.Sub(time.Now())
- // if sub < 0 {
- // sub = 0
- // }
- // ficcExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
- // } else {
- // ficcExpireDay = "-"
- // }
- // } else {
- // ficcExpireDay = "-"
- // }
- //
- // if raiStatus == utils.COMPANY_STATUS_FOREVER { //永续
- // tryExpireDay = "-"
- // } else if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
- // if tryEndDate != "" {
- // endDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
- // endDateTime = endDateTime.AddDate(0, 0, 1)
- // sub := endDateTime.Sub(time.Now())
- // if sub < 0 {
- // sub = 0
- // }
- // tryExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
- // } else {
- // tryExpireDay = "-"
- // }
- // } else if raiStatus == utils.COMPANY_STATUS_LOSE { //流失
- // tryExpireDay = "-"
- // } else if raiStatus == utils.COMPANY_STATUS_FREEZE { //冻结
- // if item.StartDate != "" && item.EndDate != "" {
- // endDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
- // endDateTime = endDateTime.AddDate(0, 0, 0)
- // sub := endDateTime.Sub(time.Now())
- // if sub < 0 {
- // sub = 0
- // }
- // tryExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
- // } else {
- // tryExpireDay = "-"
- // }
- // } else {
- // tryExpireDay = "-"
- // }
- // }
- // expireDay = ficcExpireDay + "/" + tryExpireDay
- // }
- // }
- // list[i].ExpireDay = expireDay
- //
- // //按钮显示控制
- // btnItem := new(company.ButtonPermission)
- // if item.CompanyId != 1 {
- // *btnItem = services.GetCompanyPermissionButton(roleTypeCode, itemStatus, item.GroupIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId)
- // }
- // list[i].BtnItem = btnItem
- // if item.FreezeStartDate != "" && item.FreezeEndDate != "" && item.Status == utils.COMPANY_STATUS_FREEZE {
- // freezeEndDate, _ := time.Parse(utils.FormatDate, item.FreezeEndDate)
- // if time.Now().Before(freezeEndDate) {
- // expireDays := freezeEndDate.Sub(time.Now()).Hours() / 24
- // list[i].FreezeExpireDays = int(expireDays) + 1
- // }
- // }
- // }
- //
- // statusCount, err := company.GetCompanyStatusCount(permissionCondition, permissionPars)
- // if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取状态数量失败,Err:" + err.Error()
- // return
- // }
- //
- // statusMap := make(map[string]int, 0)
- // var totalCount int
- // for _, sv := range statusCount {
- // totalCount = totalCount + sv.Count
- // statusMap[sv.Status] = sv.Count
- // }
- //
- // lossItem, err := company.GetCompanyStatusLoseCount(lossCondition, lossPars)
- // if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取流失状态数量失败,Err:" + err.Error()
- // return
- // }
- // totalCount = totalCount + lossItem.Count
- //
- // freezeItem, err := company.GetCompanyStatusFreezeCount(freezeCondition, freezePars)
- // if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取冻结状态数量失败,Err:" + err.Error()
- // return
- // }
- // statusMap["冻结"] = freezeItem.Count
- // totalCount = totalCount + freezeItem.Count
- //
- // forverItem, err := company.GetCompanyStatusForverCount(forverCondition, forverPars)
- // if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取永续状态数量失败,Err:" + err.Error()
- // return
- // }
- // totalCount = totalCount + forverItem.Count
- //
- // for _, v := range statusArr {
- // statusCount := new(company.CompanyStatus)
- // if v == "全部" {
- // statusCount.Status = "全部"
- // statusCount.Count = totalCount
- // } else if v == utils.COMPANY_STATUS_LOSE {
- // statusCount.Status = v
- // statusCount.Count = lossItem.Count
- // } else if v == utils.COMPANY_STATUS_FOREVER {
- // statusCount.Status = v
- // statusCount.Count = forverItem.Count
- // //} else if v == utils.COMPANY_STATUS_FREEZE {
- // // statusCount.Status = v
- // // statusCount.Count = freezeItem.Count
- // //}
- // } else {
- // statusCount.Status = v
- // if val, ok := statusMap[v]; ok {
- // statusCount.Count = val
- // }
- // }
- // statusItems = append(statusItems, statusCount)
- // }
- //
- // companyLists := make([]*company.CompanyListItem, 0)
- // //查询阅读次数
- // if list == nil {
- // companyLists = make([]*company.CompanyListItem, 0)
- // } else {
- // for _, v := range list {
- // viewTotal := GetviewTotal(v.CompanyId)
- // companyList := &company.CompanyListItem{
- // CompanyId: v.CompanyId,
- // CompanyName: v.CompanyName,
- // CreditCode: v.CreditCode,
- // CompanyCode: v.CompanyCode,
- // StartDate: v.StartDate,
- // EndDate: v.EndDate,
- // LoseReason: v.LoseReason,
- // RenewalReason: v.RenewalReason,
- // FreezeReason: v.FreezeReason,
- // LossTime: v.LossTime,
- // Status: v.Status,
- // CompanyType: v.CompanyType,
- // ApproveStatus: v.ApproveStatus,
- // SellerName: v.SellerName,
- // SellerId: v.SellerId,
- // SellerIds: v.SellerIds,
- // ExpireDay: v.ExpireDay,
- // FreezeTime: v.FreezeTime,
- // GroupId: v.GroupId,
- // GroupIds: v.GroupIds,
- // DepartmentId: v.DepartmentId,
- // IndustryName: v.IndustryName,
- // IsSuspend: v.IsSuspend,
- // CreatedTime: v.CreatedTime,
- // Source: v.Source,
- // Province: v.Province,
- // City: v.City,
- // Address: v.Address,
- // Reasons: v.Reasons,
- // FreezeStartDate: v.FreezeStartDate,
- // FreezeEndDate: v.FreezeEndDate,
- // FreezeExpireDays: v.FreezeExpireDays,
- // BtnItem: v.BtnItem,
- // ProductId: v.ProductId,
- // FormalTime: v.FormalTime,
- // IsShared: v.IsShared,
- // RegionType: v.RegionType,
- // FiccView: viewTotal[0],
- // RaiView: viewTotal[1],
- // }
- // companyLists = append(companyLists, companyList)
- // }
- // }
- // if companyLists == nil {
- // companyLists = make([]*company.CompanyListItem, 0)
- // }
- // page = paging.GetPaging(currentIndex, pageSize, total)
- // resp.List = companyLists
- // resp.StatusCount = statusItems
- // resp.Paging = page
- // br.Ret = 200
- // br.Success = true
- // br.Msg = "获取成功"
- // br.Data = resp
- //}
- func GetviewTotal(companyId int) (view []int) {
- list, err := company.GetCompanyUserListById(companyId)
- if err != nil {
- fmt.Println("GetCompanyUserList err:", err.Error())
- return
- }
- //获取企业客户信息
- companyInfo, err := company.GetCompanyById(companyId)
- if err != nil {
- fmt.Println("GetCompanyById err:", err.Error())
- return
- }
- var ficcViewTotal, cygxViewTotal int
- lenList := len(list)
- if lenList > 0 {
- userIdSlice := make([]string, 0)
- mobilesSlice := make([]string, 0)
- emailsSlice := make([]string, 0)
- for _, v := range list {
- userIdSlice = append(userIdSlice, strconv.Itoa(int(v.UserId)))
- if v.Mobile != "" {
- mobilesSlice = append(mobilesSlice, v.Mobile)
- } else if v.Email != "" {
- emailsSlice = append(emailsSlice, v.Email)
- }
- }
- //用户浏览数据
- mobileStr := strings.Join(mobilesSlice, "','")
- mobileStr = "'" + mobileStr + "'"
- emailStr := strings.Join(emailsSlice, "','")
- emailStr = "'" + emailStr + "'"
- //报告统计删除晨报部分统计加入每日资讯 2021-4-9
- //手机号
- userViewMobileTotalMap := make(map[string]*models.UserViewMobileTotalSlice)
- userReportViewMobileTotalMap := make(map[string]*models.ReportViewMobileRecord)
- userAdvisoryViewMobileTotalMap := make(map[string]*advisory.UserViewMobileTotalSlice)
- userCygxArticleHistoryRecordViewMobileTotalMap := make(map[string]*models.UserViewMobileTotalSlice)
- if len(mobilesSlice) > 0 {
- //权益数据
- rightsItems, err := company.GetRightsReportListByMobile(mobileStr)
- if err != nil {
- fmt.Println("GetRightsReportListByMobile err:", err.Error())
- return
- }
- cygxViewTotal = len(rightsItems)
- //FICC数据
- ficcItems, err := company.GetFiccReportListByMobile(mobileStr)
- if err != nil {
- fmt.Println("GetFiccReportListByMobile err:", err.Error())
- return
- }
- ficcViewTotal = len(ficcItems)
- }
- //邮箱
- userViewEmailTotalMap := make(map[string]*models.UserViewEmailTotalSlice)
- userReportViewEmailTotalMap := make(map[string]*models.ReportViewEmailRecord)
- userAdvisoryViewEmailTotalMap := make(map[string]*advisory.UserViewEmailTotalSlice)
- userCygxViewEmailTotalMap := make(map[string]*models.UserViewEmailTotalSlice)
- if len(emailsSlice) > 0 {
- //FICC数据
- ficcItems, err := company.GetFiccReportListByEmail(emailStr)
- if err != nil {
- fmt.Println("GetFiccReportListByEmail err:", err.Error())
- return
- }
- ficcViewTotal += len(ficcItems)
- //权益数据
- rightsItems, err := company.GetRightsReportListByEmail(emailStr)
- if err != nil {
- fmt.Println("GetViewReportListByMobile err:", err.Error())
- return
- }
- cygxViewTotal += len(rightsItems)
- }
- for i := 0; i < lenList; i++ {
- item := list[i]
- //企业名称
- list[i].CompanyName = companyInfo.CompanyName
- //手机号用户累计浏览次数
- if userView, ok := userViewMobileTotalMap[item.Mobile]; ok {
- list[i].ViewTotal += userView.Total
- }
- //邮箱用户累计浏览次数
- if userView, ok := userViewEmailTotalMap[item.Email]; ok {
- //总共浏览的报表数据需要调整为(手机号用户浏览晨报数+邮箱号用户浏览晨报数)
- list[i].ViewTotal += userView.Total
- }
- if item.OpenId != "" {
- list[i].IsRegister = true
- } else {
- if item.RegisterPlatform == 2 {
- if item.Mobile != "" || item.Email != "" {
- list[i].IsRegister = true
- }
- } else if item.RegisterTime != "" {
- list[i].IsRegister = true
- } else {
- list[i].IsRegister = false
- }
- }
- //如果存在手机号用户日评数据,那么需要做处理
- if reportView, ok := userReportViewMobileTotalMap[item.Mobile]; ok {
- //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
- if reportView.LastViewTime.After(list[i].LastViewTime) {
- list[i].LastViewTime = reportView.LastViewTime
- list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
- }
- //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
- list[i].ViewTotal += reportView.ViewTotal
- }
- //如果存在手机号用户日评数据,那么需要做处理
- if reportView, ok := userReportViewEmailTotalMap[item.Email]; ok {
- //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
- if reportView.LastViewTime.After(list[i].LastViewTime) {
- list[i].LastViewTime = reportView.LastViewTime
- list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
- }
- //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
- list[i].ViewTotal += reportView.ViewTotal
- }
- //如果存在手机号用户每日资讯,那么需要做处理
- if advisoryView, ok := userAdvisoryViewMobileTotalMap[item.Mobile]; ok {
- //fmt.Println("蝴蝶眨几次眼睛")
- //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
- if advisoryView.CreatedTime.After(list[i].LastViewTime) {
- list[i].LastViewTime = advisoryView.CreatedTime
- list[i].LastViewTimeStr = advisoryView.CreatedTime.Format(utils.FormatDateTime)
- }
- //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数)
- list[i].ViewTotal += advisoryView.Total
- }
- //如果存在邮箱号用户每日资讯,那么需要做处理
- if advisoryView, ok := userAdvisoryViewEmailTotalMap[item.Email]; ok {
- //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
- if advisoryView.CreatedTime.After(list[i].LastViewTime) {
- list[i].LastViewTime = advisoryView.CreatedTime
- list[i].LastViewTimeStr = advisoryView.CreatedTime.Format(utils.FormatDateTime)
- }
- //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数)
- list[i].ViewTotal += advisoryView.Total
- }
- ficcViewTotal += list[i].ViewTotal
- //如果存在手机号用户查研观向,那么需要做处理
- if cygxView, ok := userCygxArticleHistoryRecordViewMobileTotalMap[item.Mobile]; ok {
- //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
- if cygxView.CreatedTime.After(list[i].LastViewTime) {
- list[i].LastViewTime = cygxView.CreatedTime
- list[i].LastViewTimeStr = cygxView.CreatedTime.Format(utils.FormatDateTime)
- }
- //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数+查研观向)
- cygxViewTotal += cygxView.Total
- list[i].ViewTotal += cygxView.Total
- }
- //如果存在邮箱号用户查研观向,那么需要做处理
- if cygxView, ok := userCygxViewEmailTotalMap[item.Email]; ok {
- //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
- if cygxView.CreatedTime.After(list[i].LastViewTime) {
- list[i].LastViewTime = cygxView.CreatedTime
- list[i].LastViewTimeStr = cygxView.CreatedTime.Format(utils.FormatDateTime)
- }
- //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数+查研观向)
- cygxViewTotal += cygxView.Total
- //list[i].ViewTotal += cygxView.Total
- }
- /*if reportView, ok := userReportViewTotalMap[int(item.UserId)]; ok {
- //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
- if reportView.LastViewTime.After(list[i].LastViewTime) {
- list[i].LastViewTime = reportView.LastViewTime
- list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
- }
- //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
- list[i].ViewTotal += reportView.ViewTotal
- }*/
- }
- }
- view = append(view, ficcViewTotal)
- view = append(view, cygxViewTotal)
- return
- }
- // @Title 新增客户
- // @Description 新增客户接口
- // @Param request body company.CompanyAddReq true "type json string"
- // @Success 200 {object} company.CompanyAddResp
- // @router /add [post]
- func (this *CompanyController) Add() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- roleTypeCode := sysUser.RoleTypeCode
- var req company.CompanyAddReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.CompanyName == "" {
- br.Msg = "请填写客户名称"
- return
- }
- if req.CreditCode == "" {
- br.Msg = "请填写社会统一信用码"
- return
- }
- if req.Status == "" {
- br.Msg = "客户状态不可为空"
- return
- }
- //移除空格
- req.CreditCode = utils.TrimStr(req.CreditCode)
- var startDateTime, endDateTime time.Time
- if req.Status == utils.COMPANY_STATUS_TRY_OUT {
- startDateTime = time.Now()
- endDateTime = time.Now().AddDate(0, 2, 0)
- } else if req.Status == utils.COMPANY_STATUS_FOREVER {
- startDateTime = time.Now()
- endDateTime = time.Now().AddDate(100, 0, 0)
- } else {
- br.Msg = "无效的客户状态,请重新选择"
- return
- }
- var startDate, endDate string
- startDate = startDateTime.Format(utils.FormatDate)
- endDate = endDateTime.Format(utils.FormatDate)
- if req.CompanyType == "" {
- br.Msg = "请选择客户类型"
- return
- }
- var productId int
- var productName string
- if req.CompanyType == utils.COMPANY_PRODUCT_FICC_NAME {
- productId = utils.COMPANY_PRODUCT_FICC_ID
- productName = utils.COMPANY_PRODUCT_FICC_NAME
- } else if req.CompanyType == utils.COMPANY_PRODUCT_RAI_NAME {
- productId = utils.COMPANY_PRODUCT_RAI_ID
- productName = utils.COMPANY_PRODUCT_RAI_NAME
- } else {
- br.Msg = "无效的客户类型,请重新选择"
- return
- }
- if req.IndustryId <= 0 {
- br.Msg = "请选择行业"
- return
- }
- if req.SellsId <= 0 {
- br.Msg = "请选择所属销售"
- return
- }
- //if req.Reasons == "" {
- // br.Msg = "请填写新增理由"
- // return
- //}
- if req.PermissionIds == "" {
- br.Msg = "请选择权限"
- return
- } else {
- permissionStr, err := company.GetPermissionIdById(req.PermissionIds)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取主观客观权限信息失败,Err:" + err.Error()
- return
- }
- req.PermissionIds = permissionStr
- }
- industry, err := company.GetCompanyIndustryById(req.IndustryId)
- if err != nil {
- br.Msg = "获取行业信息失败"
- br.ErrMsg = "获取行业信息失败,Err:" + err.Error()
- return
- }
- if industry == nil {
- br.Msg = "行业信息不存在"
- return
- }
- //判断客户是否已经存在
- companyNameIsExist, err := company.GetCompanyCountByCompanyName(req.CompanyName)
- if err != nil {
- br.Msg = "判断客户是否存在失败"
- br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
- return
- }
- if companyNameIsExist > 0 {
- br.Msg = "客户已存在,请重新输入客户名称"
- return
- }
- //判断客户是否已经存在
- companyCreditCodeIsExist, err := company.GetCompanyCountByCreditCode(req.CreditCode)
- if err != nil {
- br.Msg = "判断客户是否存在失败"
- br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
- return
- }
- if companyCreditCodeIsExist > 0 {
- br.Msg = "客户已存在,统一社会信用代码"
- return
- }
- seller, err := system.GetSysAdminById(req.SellsId)
- if err != nil {
- br.Msg = "获取销售信息失败"
- br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
- return
- }
- tryOutCount, err := company.GetCompanyTryOutCount(utils.COMPANY_STATUS_TRY_OUT, seller.AdminId)
- if err != nil {
- br.Msg = "判断试用客户量失败"
- br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
- return
- }
- /*
- ROLE_TYPE_CODE_ADMIN = "admin" //管理员
- ROLE_TYPE_CODE_FICC_ADMIN = "ficc_admin" //ficc管理员
- ROLE_TYPE_CODE_FICC_SELLER = "ficc_seller" //ficc销售
- ROLE_TYPE_CODE_RAI_ADMIN = "rai_admin" //权益管理员
- ROLE_TYPE_CODE_RAI_SELLER = "rai_seller" //权益销售
- ROLE_TYPE_CODE_FICC_GROUP = "ficc_group" //ficc组长
- ROLE_TYPE_CODE_RAI_GROUP = "rai_group" //ficc组长
- ROLE_TYPE_CODE_FICC_DEPARTMENT = "ficc_department" //ficc部门经理
- ROLE_TYPE_CODE_RAI_DEPARTMENT = "rai_department" //权益部门经理
- ROLE_TYPE_CODE_FICC_RESEARCHR = "ficc_researcher" //ficc研究员
- ROLE_TYPE_CODE_RAI_RESEARCHR = "rai_researcher" //权益研究员
- */
- if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
- roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
- if tryOutCount >= utils.COMPANY_STATUS_TRY_OUT_COUNT {
- br.Msg = "您的试用客户总数,已超过上限,不可继续新增"
- return
- }
- }
- //// 每个权益销售手中的试用客户最多30个
- //if productId == utils.COMPANY_PRODUCT_RAI_ID && tryOutCount >= utils.COMPANY_STATUS_TRY_OUT_COUNT_RAI {
- // br.Msg = "您的试用客户总数,已超过上限,不可继续新增"
- // return
- //}
- //如果是权益客户,在选择非研选行业试用时,需要判断当前有多少非研选的试用客户(试用状态,且行业是非研选)
- if productId == utils.COMPANY_PRODUCT_RAI_ID {
- permissionArr := strings.Split(req.PermissionIds, ",")
- //如果所选行业不属于研选订阅跟研选扣点包,那就是非研选试用客户
- var isNoResearch bool
- for _, v := range permissionArr {
- if v != strconv.Itoa(utils.CHART_PERMISSION_ID_YANXUAN) && v != strconv.Itoa(utils.YAN_XUAN_KOU_DIAN_BAO_ID) {
- isNoResearch = true
- continue
- }
- }
- if isNoResearch {
- tryOutCountRai, err := company.GetRaiCompanyTryOutCountNoResearch(seller.AdminId)
- if err != nil {
- br.Msg = "判断试用客户量失败"
- br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
- return
- }
- if tryOutCountRai >= utils.COMPANY_STATUS_TRY_OUT_COUNT_RAI {
- br.Msg = "非研选试用客户最多40家"
- return
- }
- }
- }
- if seller == nil {
- br.Msg = "所属销售不存在"
- return
- }
- companyCode, err := company.GetCompanyCode()
- if err != nil {
- br.Msg = "获取客户编码信息失败"
- br.ErrMsg = "获取客户编码信息失败,Err:" + err.Error()
- return
- }
- item := new(company.Company)
- item.CompanyName = req.CompanyName
- item.CreditCode = req.CreditCode
- item.CompanyCode = companyCode
- item.Province = req.Province
- item.City = req.City
- item.Address = req.Province + req.City
- item.StartDate = time.Now().Format(utils.FormatDate)
- if req.Status == utils.COMPANY_STATUS_FOREVER {
- item.EndDate = time.Now().AddDate(100, 0, 0).Format(utils.FormatDate)
- item.CompanyType = 5
- }
- if req.Status == utils.COMPANY_STATUS_TRY_OUT {
- item.EndDate = time.Now().AddDate(0, 2, 0).Format(utils.FormatDate)
- item.CompanyType = 2
- }
- item.FirstStartDate = item.StartDate
- item.FirstEndDate = item.EndDate
- item.CreatedTime = time.Now()
- item.LastUpdatedTime = time.Now()
- item.Enabled = 1
- item.RegionType = req.RegionType
- item.Remark = req.Reasons
- item.Nation = req.Nation
- item.OverseasStatus = "试用"
- item.ResetBtn = 1
- companyId, err := company.AddCompany(item)
- if err != nil {
- br.Msg = "新增失败"
- br.ErrMsg = "新增失败,err:" + err.Error()
- return
- }
- item.CompanyId = int(companyId)
- //生成第三方code编号
- item.OpenCompanyCode = services.GenerateOpenCompanyCode(int(companyId))
- item.Update([]string{"OpenCompanyCode"})
- if req.UserId > 0 {
- //修改联系人
- err = company.ModifyCompanyUserCompanyId(req.UserId, int(companyId))
- if err != nil {
- br.Msg = "新增失败"
- br.ErrMsg = "新增失败,ModifyCompanyUserCompanyId err:" + err.Error()
- return
- }
- //获取联系人详情
- userInfo, err := models.GetWxUserByUserId(req.UserId)
- if err != nil {
- br.Msg = "获取联系人异常!"
- br.ErrMsg = "获取联系人异常,Err:" + err.Error()
- return
- }
- //添加该联系人 与 当前销售的关系
- models.AddUserSellerRelation(int64(req.UserId), int(companyId), seller.AdminId, productId, seller.RealName, userInfo.Mobile, userInfo.Email)
- }
- companyProduct := new(company.CompanyProduct)
- companyProduct.CompanyId = int(companyId)
- companyProduct.ProductId = productId
- companyProduct.ProductName = productName
- companyProduct.CompanyName = req.CompanyName
- companyProduct.Source = req.Source
- companyProduct.Reasons = req.Reasons
- companyProduct.Status = req.Status
- companyProduct.StartDate = startDate
- companyProduct.EndDate = endDate
- companyProduct.IndustryId = req.IndustryId
- companyProduct.IndustryName = industry.IndustryName
- companyProduct.SellerId = seller.AdminId
- companyProduct.SellerName = seller.RealName
- companyProduct.GroupId = seller.GroupId
- companyProduct.DepartmentId = seller.DepartmentId
- companyProduct.IsSuspend = 0
- companyProduct.CreateTime = time.Now()
- companyProduct.ModifyTime = time.Now()
- companyProduct.CompanyType = req.CompanyType
- companyProduct.Scale = req.Scale
- companyProduct.OpenCode = services.GenerateOpenCompanyProductCode(int(companyId), productId)
- companyProduct.TodoStatus = "无任务"
- companyProduct.TryStage = 1
- companyProduct.OverseasLabel = 1
- if seller.Mobile == "13065778668" {
- if req.RegionType == "海外" {
- companyProduct.IsOverseas = 0
- } else {
- companyProduct.IsOverseas = 1
- }
- }
- if productId == utils.COMPANY_PRODUCT_RAI_ID && req.Status == utils.COMPANY_STATUS_FOREVER { // 权益的永续客户给一个状态初始化的记录
- companyProduct.InitStatus = req.Status
- }
- companyProduct.SellerIdInit = seller.AdminId
- companyProduct.SellerNameInit = seller.RealName
- companyProductId, err := company.AddCompanyProduct(companyProduct)
- if err != nil {
- br.Msg = "新增失败"
- br.ErrMsg = "新增客户产品失败,err:" + err.Error()
- return
- }
- companyReportPermissionList, err := services.AddCompanyPermission(int(companyId), seller.AdminId, productId, productName, seller.RealName, req.PermissionIds, startDate, endDate)
- if err != nil {
- br.Msg = "新增失败"
- br.ErrMsg = "新增客户设置权限失败,err:" + err.Error()
- return
- }
- {
- record := new(company.CompanyOperationRecord)
- record.CompanyId = int(companyId)
- record.CompanyName = req.CompanyName
- record.SellerId = seller.AdminId
- record.SysUserId = seller.AdminId
- record.SysRealName = seller.RealName
- record.Remark = "新增客户"
- record.Operation = "add"
- record.CreateTime = time.Now()
- record.ProductId = productId
- record.ProductName = productName
- record.Status = req.Status
- _, err = company.AddCompanyOperationRecord(record)
- if err != nil {
- go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
- //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
- }
- }
- //新增客户日志
- {
- companyLog := new(company.CompanyLog)
- companyLog.CompanyId = int(companyId)
- companyLog.CompanyName = req.CompanyName
- companyLog.CreditCode = req.CreditCode
- companyLog.CompanyCode = companyCode
- companyLog.Sort = item.Sort
- companyLog.IsFeeCustomer = item.IsFeeCustomer
- companyLog.Country = item.Country
- companyLog.Address = item.Address
- companyLog.City = item.City
- companyLog.Province = item.Province
- companyLog.Enabled = item.Enabled
- companyLog.CreatedTime = item.CreatedTime
- companyLog.LastUpdatedTime = item.LastUpdatedTime
- companyLog.Seller = item.Seller
- companyLog.SellsId = item.SellsId
- companyLog.CompanyBelong = item.CompanyBelong
- companyLog.StartDate = item.StartDate
- companyLog.EndDate = item.EndDate
- companyLog.FirstStartDate = item.FirstStartDate
- companyLog.FirstEndDate = item.FirstEndDate
- companyLog.DateType = item.DateType
- companyLog.AdminId = this.SysUser.AdminId
- companyLog.LogType = "add"
- companyLog.LogCreateTime = time.Now()
- go company.AddCompanyLog(companyLog)
- }
- //新增客户产品日志
- {
- productLog := new(company.CompanyProductLog)
- productLog.CompanyProductId = int(companyProductId)
- productLog.CompanyId = companyProduct.CompanyId
- productLog.ProductId = companyProduct.ProductId
- productLog.ProductName = companyProduct.ProductName
- productLog.CompanyName = companyProduct.CompanyName
- productLog.CompanyName = companyProduct.CompanyName
- productLog.Source = companyProduct.Source
- productLog.Reasons = companyProduct.Reasons
- productLog.Status = companyProduct.Status
- productLog.IndustryId = companyProduct.IndustryId
- productLog.IndustryName = companyProduct.IndustryName
- productLog.SellerId = companyProduct.SellerId
- productLog.SellerName = companyProduct.SellerName
- productLog.GroupId = companyProduct.GroupId
- productLog.DepartmentId = companyProduct.DepartmentId
- productLog.IsSuspend = companyProduct.IsSuspend
- productLog.SuspendTime = companyProduct.SuspendTime
- productLog.ApproveStatus = companyProduct.ApproveStatus
- productLog.FreezeTime = companyProduct.FreezeTime
- productLog.Remark = companyProduct.Remark
- productLog.StartDate = companyProduct.StartDate
- productLog.EndDate = companyProduct.EndDate
- productLog.CreateTime = companyProduct.CreateTime
- productLog.ModifyTime = companyProduct.ModifyTime
- productLog.LoseReason = companyProduct.LoseReason
- productLog.LossTime = companyProduct.LossTime
- productLog.LogType = "add"
- productLog.LogCreateTime = time.Now()
- productLog.AdminId = this.SysUser.AdminId
- productLog.Scale = companyProduct.Scale
- go company.AddCompanyProductLog(productLog)
- }
- //新增客户产品状态变更日志
- {
- companyProductUpdateLog := &company.CompanyProductUpdateLog{
- Id: 0,
- CompanyId: companyProduct.CompanyId,
- ProductId: companyProduct.ProductId,
- Status: "试用",
- Source: "add",
- SellerId: companyProduct.SellerId,
- SellerName: companyProduct.SellerName,
- StartDate: startDateTime,
- EndDate: endDateTime,
- RealEndDate: startDateTime,
- CreateTime: time.Now(),
- }
- go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
- companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
- Id: 0,
- CompanyId: companyProduct.CompanyId,
- ProductId: companyProduct.ProductId,
- Source: "add",
- SellerId: companyProduct.SellerId,
- SellerName: companyProduct.SellerName,
- StartDate: startDateTime,
- EndDate: endDateTime,
- RealEndDate: startDateTime,
- IsStop: 0,
- CreateTime: time.Now(),
- }
- go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
- }
- resp := new(company.CompanyAddResp)
- resp.CompanyId = int(companyId)
- br.Ret = 200
- br.Success = true
- br.Msg = "新增成功"
- br.Data = resp
- }
- // Detail
- // @Title 获取客户详情
- // @Description 获取客户详情接口
- // @Param CompanyId query int true "客户id"
- // @Success 200 {object} company.CompanyDetailResp
- // @router /detail [get]
- func (this *CompanyController) Detail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- companyId, _ := this.GetInt("CompanyId")
- if companyId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "客户参数小于等于0"
- return
- }
- // CRM8.8-是否为编辑页的客户详情
- isEdit, _ := this.GetBool("IsEdit")
- productId := services.GetProductId(sysUser.RoleTypeCode)
- item, err := company.GetCompanyDetailById(companyId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- shareSellerId := 0
- shareGroupId := 0
- var productItem *company.CompanyProduct
- if productId > 0 {
- var e error
- productItem, e = company.GetCompanyProductByCompanyIdAndProductId(companyId, productId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- br.Msg = "客户信息有误"
- br.ErrMsg = "获取客户信息失败, Err: " + e.Error()
- return
- }
- if productItem != nil {
- shareSellerId = productItem.ShareSellerId
- shareGroupId = productItem.ShareGroupId
- }
- }
- var productName string
- if productId == 1 {
- productName = utils.COMPANY_PRODUCT_FICC_NAME
- } else if productId == 2 {
- productName = utils.COMPANY_PRODUCT_RAI_NAME
- } else {
- productName = "admin"
- }
- resp := new(company.CompanyDetailResp)
- resp.ProductName = productName
- //获取客户产品
- productList, err := company.GetCompanyProductsByCompanyId(companyId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取产品信息失败,Err:" + err.Error()
- return
- }
- roleTypeCode := sysUser.RoleTypeCode
- itemLen := len(productList)
- btnDetailItem := new(company.ButtonDetailPermission)
- // 客户权限校验
- {
- // 如果不是超管、ficc管理员、权益管理员,那么需要额外校验下权限
- if !utils.InArrayByStr([]string{utils.ROLE_TYPE_CODE_ADMIN, utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_RAI_ADMIN}, sysUser.RoleTypeCode) {
- var isOk bool //是否有权限
- var companyHasProduct bool // 客户当前是否有该产品权限
- for _, productInfo := range productList {
- // 只校验拥有的品种权限:ficc或者权益
- if productInfo.ProductId == productId {
- companyHasProduct = true
- // 自己的客户有权限看
- if productInfo.SellerId == sysUser.AdminId {
- isOk = true
- break
- }
- // 流失客户都有权限看
- if productInfo.Status == utils.COMPANY_STATUS_LOSE || productInfo.Status == utils.COMPANY_STATUS_CLOSE {
- isOk = true
- break
- }
- // 分享的客户 也有权限
- if productItem.IsShare == 1 && productItem.ShareSellerId == sysUser.AdminId {
- isOk = true
- break
- }
- // 分享的客户的组长 也有权限
- if productItem.IsShare == 1 && productItem.ShareGroupId == sysUser.GroupId {
- isOk = true
- break
- }
- // 如果是组长,且该客户属于本组客户
- if sysUser.Authority == 4 && productInfo.GroupId > 0 && productInfo.GroupId == sysUser.GroupId && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM {
- isOk = true
- break
- }
- // 如果是ficc主管或者权益主管
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
- // 获取顶级分组Id
- var sysUserGroupPid, productGroupPid int
- // 当前账号的顶级分组id
- {
- sysUserGroupIdpid, err := company.GetParentIdFromGroup(sysUser.GroupId)
- if err != nil && err.Error() != utils.NotEmpty() {
- break
- }
- if sysUserGroupIdpid == nil || *sysUserGroupIdpid == 0 {
- sysUserGroupPid = sysUser.GroupId
- } else {
- sysUserGroupPid = *sysUserGroupIdpid
- }
- }
- // 当前客户的顶级分组id
- {
- groupIdpid, err := company.GetParentIdFromGroup(productInfo.GroupId)
- if err != nil && err.Error() != utils.NotEmpty() {
- break
- }
- if groupIdpid == nil || *groupIdpid == 0 {
- productGroupPid = productInfo.GroupId
- } else {
- productGroupPid = *groupIdpid
- }
- }
- // 如果客户的顶级分组和当前账号分组id一致
- if sysUserGroupPid == productGroupPid {
- isOk = true
- break
- }
- }
- }
- }
- // 客户当前是否有该产品的权限,如果没有的话,说明是在领取客户,允许访问
- if !companyHasProduct {
- isOk = true
- }
- if !isOk {
- br.Msg = "无访问权限"
- return
- }
- }
- }
- //产品权限map
- statusMap := make(map[int]string)
- for i := 0; i < itemLen; i++ {
- item := productList[i]
- //添加产品权限map
- statusMap[item.ProductId] = item.Status
- if i == 0 {
- if item.ProductId == 1 {
- resp.CreateAuth = 1
- } else {
- resp.CreateAuth = 2
- }
- }
- if item.ProductId == 1 {
- if strings.Contains(sysUser.RoleTypeCode, "ficc") {
- if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
- btnDetailItem.BtnHistoryList = true
- } else {
- if item.SellerId == sysUser.AdminId || shareSellerId == sysUser.AdminId || shareGroupId == sysUser.GroupId {
- btnDetailItem.BtnHistoryList = true
- }
- if sysUser.Authority > 0 {
- if item.GroupId == sysUser.GroupId {
- btnDetailItem.BtnHistoryList = true
- }
- if item.DepartmentId == sysUser.DepartmentId {
- btnDetailItem.BtnHistoryList = true
- }
- }
- }
- }
- // 编辑回显
- allPermissions, e := company.GetPermissionLookItemsByProductId(utils.COMPANY_PRODUCT_FICC_ID)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取权限信息失败,Err:" + e.Error()
- return
- }
- permissionMap := make(map[int][]*company.PermissionLookItem, 0)
- permissionCheckMap := make(map[int][]int, 0)
- for _, v := range allPermissions {
- if v.ParentId > 0 {
- permissionMap[v.ParentId] = append(permissionMap[v.ParentId], v)
- if v.IsPublic == 1 {
- permissionCheckMap[v.ParentId] = append(permissionCheckMap[v.ParentId], v.ChartPermissionId)
- }
- }
- }
- for _, v := range allPermissions {
- if v.ParentId == 0 {
- checkList := make([]int, 0)
- plist := new(company.PermissionLookList)
- plist.Items = make([]*company.PermissionLookItem, 0)
- plist.ItemsType = make([]*company.PermissionSetItemType, 0)
- items, ok := permissionMap[v.ChartPermissionId]
- if ok {
- for itemK, n := range items {
- permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
- return
- }
- if permission != nil && permission.ChartPermissionId > 0 {
- checkList = append(checkList, n.ChartPermissionId)
- items[itemK].StartDate = permission.StartDate
- items[itemK].EndDate = permission.EndDate
- items[itemK].Status = permission.Status
- endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
- endDateTime = endDateTime.AddDate(0, 0, 1)
- sub := endDateTime.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
- items[itemK].ExpireDay = expireDay
- }
- }
- plist.Items = items
- }
- plist.ClassifyName = v.PermissionName
- plist.CheckList = checkList
- item.PermissionList = append(item.PermissionList, plist)
- }
- }
- resp.FiccItem = item
- if resp.FiccItem.Status == utils.COMPANY_STATUS_FOREVER {
- resp.FiccItem.Status = utils.COMPANY_STATUS_X_CLASS_TRY_OUT
- }
- if (roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
- roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT) &&
- item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
- resp.IsButtonShow = 1
- }
- } else {
- if strings.Contains(sysUser.RoleTypeCode, "rai") {
- if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
- btnDetailItem.BtnHistoryList = true
- } else {
- if item.SellerId == sysUser.AdminId || item.ShareSellerId == sysUser.AdminId || shareGroupId == sysUser.GroupId {
- btnDetailItem.BtnHistoryList = true
- }
- if sysUser.Authority > 0 {
- if item.GroupId == sysUser.GroupId {
- btnDetailItem.BtnHistoryList = true
- }
- if item.DepartmentId == sysUser.DepartmentId {
- btnDetailItem.BtnHistoryList = true
- }
- }
- }
- }
- // CRM8.8-权益权限列表调用较多、统一进行调整
- plist, e := services.RaiCompanyPermissionAndCheckList(companyId, isEdit, []string{"调研"})
- if e != nil {
- br.Msg = "获取客户权益权限列表信息失败"
- br.ErrMsg = "获取客户权益权限列表信息失败,Err:" + e.Error()
- return
- }
- // cygx8.2专项产业调研展示
- item.SpecialSurplus, err = cygxService.GetSpecialSurplusByCompanyNew(companyId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取专项调研信息失败,Err:" + err.Error()
- return
- }
- //研选服务点数
- item.Points = cygxService.GetCygxActivityPointsCompanyByCompanyId(companyId)
- item.PermissionList = append(item.PermissionList, plist)
- resp.RaiItem = item
- if resp.RaiItem.Status == utils.COMPANY_STATUS_FOREVER {
- resp.RaiItem.Status = utils.COMPANY_STATUS_X_CLASS_TRY_OUT
- }
- if (roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT) &&
- item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
- resp.IsButtonShow = 1
- }
- }
- btnItem := services.GetCompanyPermissionButton(roleTypeCode, item.Status, strconv.Itoa(item.SellerId), strconv.Itoa(item.GroupId), item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, shareSellerId, "")
- //if itemLen > 1 {
- // btnDetailItem.BtnEdit = false
- // btnDetailItem.BtnDelete = false
- //} else {
- // btnDetailItem.BtnEdit = btnItem.BtnEdit
- // btnDetailItem.BtnDelete = btnItem.BtnDelete
- //}
- switch item.ProductId {
- case 1:
- btnDetailItem.FiccEdit = btnItem.BtnEdit
- btnDetailItem.FiccDelete = btnItem.BtnDelete
- case 2:
- btnDetailItem.RaiEdit = btnItem.BtnEdit
- btnDetailItem.RaiDelete = btnItem.BtnDelete
- }
- if !btnDetailItem.BtnEdit {
- btnDetailItem.BtnEdit = btnItem.BtnEdit
- }
- if !btnDetailItem.BtnDelete {
- btnDetailItem.BtnDelete = btnItem.BtnDelete
- }
- //联系人操作权限
- if resp.IsContractButtonShow == false {
- resp.IsContractButtonShow = services.CheckCompanyUserButton(sysUser.RoleTypeCode, item.SellerId, sysUser.AdminId, item.ProductId, shareSellerId, item.Status)
- }
- //校验当前操作员是否具给联系人开通个人研选的权限
- if resp.IsUserYanXuanButtonShow == false {
- resp.IsUserYanXuanButtonShow, err = services.CheckCompanyUserYanXuanButton(sysUser.RoleTypeCode, sysUser.Mobile)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取专项调研信息失败,Err:" + err.Error()
- return
- }
- }
- }
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
- roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
- resp.IsButtonShow = 1
- btnDetailItem.BtnHistoryList = true
- }
- //ficc权限
- if ficcStatus, ok := statusMap[1]; ok {
- if ficcStatus == utils.COMPANY_STATUS_TRY_OUT {
- if raiStatus, ok := statusMap[2]; ok {
- //另一个权限也是 试用 、冻结、流失
- if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
- //那么超管、部门管理员、销售可以编辑
- if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- btnDetailItem.BaseInfoEdit = true
- }
- }
- //权益是永续时,超管可编辑基础信息
- if raiStatus == utils.COMPANY_STATUS_FOREVER {
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- btnDetailItem.BaseInfoEdit = true
- }
- }
- } else {
- //权限未开,有编辑基础信息权限
- btnDetailItem.BaseInfoEdit = true
- }
- }
- if ficcStatus == utils.COMPANY_STATUS_FOREVER {
- if raiStatus, ok := statusMap[2]; ok {
- //另一个权限也是 永续 、冻结、流失
- if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FOREVER || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
- //超管可编辑基础信息
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- btnDetailItem.BaseInfoEdit = true
- }
- }
- } else {
- //权限未开,有编辑基础信息权限
- btnDetailItem.BaseInfoEdit = true
- }
- }
- }
- //权益销售
- if raiStatus, ok := statusMap[2]; ok {
- if raiStatus == utils.COMPANY_STATUS_TRY_OUT {
- if ficcStatus, ok := statusMap[1]; ok {
- //另一个权限也是 试用 、冻结、流失
- if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
- //那么超管、部门管理员、销售可以编辑
- if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- btnDetailItem.BaseInfoEdit = true
- }
- }
- //ficc是永续时,超管可编辑基础信息
- if ficcStatus == utils.COMPANY_STATUS_FOREVER {
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- btnDetailItem.BaseInfoEdit = true
- }
- }
- } else {
- //权限未开,有编辑基础信息权限
- btnDetailItem.BaseInfoEdit = true
- }
- }
- if raiStatus == utils.COMPANY_STATUS_FOREVER {
- if ficcStatus, ok := statusMap[1]; ok {
- //另一个权限也是 试用、永续 、冻结、流失
- if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FOREVER || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
- //超管可编辑基础信息
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- btnDetailItem.BaseInfoEdit = true
- }
- }
- } else {
- //权限未开,有编辑基础信息权限
- btnDetailItem.BaseInfoEdit = true
- }
- }
- }
- // 白嫖客户标记
- scroungeList, err := company.GetScroungeCompany()
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取白嫖客户信息失败,Err:" + err.Error()
- return
- }
- scroungeMap := make(map[int]int)
- for _, v := range scroungeList {
- scroungeMap[v.CompanyId] = 1
- }
- if _, ok := scroungeMap[item.CompanyId]; ok {
- item.IsScrounge = 1
- }
- resp.Item = item
- resp.BtnItem = btnDetailItem
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // DetailByCreditCode
- // @Title 根据社会信用码获取客户详情
- // @Description 根据社会信用码获取客户详情接口
- // @Param CreditCode query string true "客户社会信用码"
- // @Success 200 {object} company.CompanyDetailResp
- // @router /detail_by_credit_code [get]
- func (this *CompanyController) DetailByCreditCode() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- resp := new(company.CompanyDetailResp)
- creditCode := this.GetString("CreditCode")
- if creditCode == "" {
- br.Msg = "参数错误"
- br.ErrMsg = "社会信用码必传"
- return
- }
- item, err := company.GetCompanyDetailByCreditCode(creditCode)
- if err != nil {
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- companyId := item.CompanyId
- var productName string
- productId := services.GetProductId(sysUser.RoleTypeCode)
- if productId == 1 {
- productName = utils.COMPANY_PRODUCT_FICC_NAME
- } else if productId == 2 {
- productName = utils.COMPANY_PRODUCT_RAI_NAME
- } else {
- productName = "admin"
- }
- resp.ProductName = productName
- //获取客户产品
- productList, err := company.GetCompanyProductsByCompanyId(companyId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取产品信息失败,Err:" + err.Error()
- return
- }
- roleTypeCode := sysUser.RoleTypeCode
- itemLen := len(productList)
- btnDetailItem := new(company.ButtonDetailPermission)
- //产品权限map
- statusMap := make(map[int]string)
- for i := 0; i < itemLen; i++ {
- item := productList[i]
- //添加产品权限map
- statusMap[item.ProductId] = item.Status
- if i == 0 {
- if item.ProductId == 1 {
- resp.CreateAuth = 1
- } else {
- resp.CreateAuth = 2
- }
- }
- if item.ProductId == 1 {
- if strings.Contains(sysUser.RoleTypeCode, "ficc") {
- if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
- btnDetailItem.BtnHistoryList = true
- } else {
- if item.SellerId == sysUser.AdminId {
- btnDetailItem.BtnHistoryList = true
- }
- if sysUser.Authority > 0 {
- if item.GroupId == sysUser.GroupId {
- btnDetailItem.BtnHistoryList = true
- }
- if item.DepartmentId == sysUser.DepartmentId {
- btnDetailItem.BtnHistoryList = true
- }
- }
- }
- }
- //子权限切片集合
- allFiccPermissions, permissionMap, e := services.GetBasePermissionLookItem(utils.COMPANY_PRODUCT_FICC_ID)
- if e != nil {
- br.Msg = "查询基础权限失败"
- br.ErrMsg = "查询基础权限失败,Err:" + e.Error()
- return
- }
- //遍历获取
- for _, v := range allFiccPermissions {
- if v.ParentId == 0 {
- checkList := make([]int, 0)
- plist := new(company.PermissionLookList)
- plist.Items = make([]*company.PermissionLookItem, 0)
- items, ok1 := permissionMap[v.ChartPermissionId]
- if ok1 {
- for itemK, n := range items {
- permission, e := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取权限信息失败,Err:" + e.Error()
- return
- }
- if permission != nil && permission.ChartPermissionId > 0 {
- checkList = append(checkList, n.ChartPermissionId)
- items[itemK].StartDate = permission.StartDate
- items[itemK].EndDate = permission.EndDate
- items[itemK].Status = permission.Status
- endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
- endDateTime = endDateTime.AddDate(0, 0, 1)
- sub := endDateTime.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
- items[itemK].ExpireDay = expireDay
- }
- }
- plist.Items = items
- }
- plist.ClassifyName = v.PermissionName
- plist.CheckList = checkList
- item.PermissionList = append(item.PermissionList, plist)
- }
- }
- resp.FiccItem = item
- if (roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
- roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT) &&
- item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
- resp.IsButtonShow = 1
- }
- } else {
- if strings.Contains(sysUser.RoleTypeCode, "rai") {
- if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
- btnDetailItem.BtnHistoryList = true
- } else {
- if item.SellerId == sysUser.AdminId {
- btnDetailItem.BtnHistoryList = true
- }
- if sysUser.Authority > 0 {
- if item.GroupId == sysUser.GroupId {
- btnDetailItem.BtnHistoryList = true
- }
- if item.DepartmentId == sysUser.DepartmentId {
- btnDetailItem.BtnHistoryList = true
- }
- }
- }
- }
- classifyName := "权益"
- checkList := make([]int, 0)
- plist := new(company.PermissionLookList)
- items, err := company.GetPermissionLookItems(item.ProductId, classifyName)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
- return
- }
- for itemK, n := range items {
- permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
- return
- }
- if permission != nil && permission.ChartPermissionId > 0 {
- checkList = append(checkList, n.ChartPermissionId)
- items[itemK].StartDate = permission.StartDate
- items[itemK].EndDate = permission.EndDate
- items[itemK].Status = permission.Status
- endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
- endDateTime = endDateTime.AddDate(0, 0, 1)
- sub := endDateTime.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
- items[itemK].ExpireDay = expireDay
- }
- //count, err := company.GetCompanyPermissionCheck(companyId, n.ChartPermissionId)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
- // return
- //}
- //if count > 0 {
- // checkList = append(checkList, n.ChartPermissionId)
- //}
- }
- item.SpecialSurplus, err = cygxService.GetSpecialSurplusByCompanyNew(companyId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取专项调研信息失败,Err:" + err.Error()
- return
- }
- plist.Items = items
- plist.ClassifyName = classifyName
- plist.CheckList = checkList
- item.PermissionList = append(item.PermissionList, plist)
- resp.RaiItem = item
- if (roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT) &&
- item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
- resp.IsButtonShow = 1
- }
- }
- btnItem := services.GetCompanyPermissionButton(roleTypeCode, item.Status, strconv.Itoa(item.SellerId), strconv.Itoa(item.GroupId),
- item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, item.ShareSellerId, "")
- //if itemLen > 1 {
- // btnDetailItem.BtnEdit = false
- // btnDetailItem.BtnDelete = false
- //} else {
- // btnDetailItem.BtnEdit = btnItem.BtnEdit
- // btnDetailItem.BtnDelete = btnItem.BtnDelete
- //}
- switch item.ProductId {
- case 1:
- btnDetailItem.FiccEdit = btnItem.BtnEdit
- btnDetailItem.FiccDelete = btnItem.BtnDelete
- case 2:
- btnDetailItem.RaiEdit = btnItem.BtnEdit
- btnDetailItem.RaiDelete = btnItem.BtnDelete
- }
- if !btnDetailItem.BtnEdit {
- btnDetailItem.BtnEdit = btnItem.BtnEdit
- }
- if !btnDetailItem.BtnDelete {
- btnDetailItem.BtnDelete = btnItem.BtnDelete
- }
- //联系人操作权限
- if resp.IsContractButtonShow == false {
- resp.IsContractButtonShow = services.CheckCompanyUserButton(sysUser.RoleTypeCode, item.SellerId, sysUser.AdminId, item.ProductId, item.ShareSellerId, item.Status)
- }
- }
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
- roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
- resp.IsButtonShow = 1
- btnDetailItem.BtnHistoryList = true
- }
- //ficc权限
- if ficcStatus, ok := statusMap[1]; ok {
- if ficcStatus == utils.COMPANY_STATUS_TRY_OUT {
- if raiStatus, ok := statusMap[2]; ok {
- //另一个权限也是 试用 、冻结、流失
- if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
- //那么超管、部门管理员、销售可以编辑
- if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- btnDetailItem.BaseInfoEdit = true
- }
- }
- //权益是永续时,超管可编辑基础信息
- if raiStatus == utils.COMPANY_STATUS_FOREVER {
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- btnDetailItem.BaseInfoEdit = true
- }
- }
- } else {
- //权限未开,有编辑基础信息权限
- btnDetailItem.BaseInfoEdit = true
- }
- }
- if ficcStatus == utils.COMPANY_STATUS_FOREVER {
- if raiStatus, ok := statusMap[2]; ok {
- //另一个权限也是 永续 、冻结、流失
- if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FOREVER || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
- //超管可编辑基础信息
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- btnDetailItem.BaseInfoEdit = true
- }
- }
- } else {
- //权限未开,有编辑基础信息权限
- btnDetailItem.BaseInfoEdit = true
- }
- }
- }
- //权益销售
- if raiStatus, ok := statusMap[2]; ok {
- if raiStatus == utils.COMPANY_STATUS_TRY_OUT {
- if ficcStatus, ok := statusMap[1]; ok {
- //另一个权限也是 试用 、冻结、流失
- if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
- //那么超管、部门管理员、销售可以编辑
- if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- btnDetailItem.BaseInfoEdit = true
- }
- }
- //ficc是永续时,超管可编辑基础信息
- if ficcStatus == utils.COMPANY_STATUS_FOREVER {
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- btnDetailItem.BaseInfoEdit = true
- }
- }
- } else {
- //权限未开,有编辑基础信息权限
- btnDetailItem.BaseInfoEdit = true
- }
- }
- if raiStatus == utils.COMPANY_STATUS_FOREVER {
- if ficcStatus, ok := statusMap[1]; ok {
- //另一个权限也是 试用、永续 、冻结、流失
- if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FOREVER || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
- //超管可编辑基础信息
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- btnDetailItem.BaseInfoEdit = true
- }
- }
- } else {
- //权限未开,有编辑基础信息权限
- btnDetailItem.BaseInfoEdit = true
- }
- }
- }
- resp.Item = item
- resp.BtnItem = btnDetailItem
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 编辑客户
- // @Description 编辑客户接口
- // @Param request body company.CompanyEditReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /edit [post]
- func (this *CompanyController) Edit() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- //roleTypeCode := sysUser.RoleTypeCode
- var req company.CompanyEditReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.CompanyId <= 0 {
- br.Msg = "参数异常!"
- br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
- return
- }
- if req.CompanyName == "" {
- br.Msg = "请填写客户名称"
- return
- }
- if req.CreditCode == "" {
- br.Msg = "请填写社会统一信用码"
- return
- }
- //移除空格
- req.CreditCode = utils.TrimStr(req.CreditCode)
- productId := services.GetProductId(sysUser.RoleTypeCode) //产品权限id
- for _, v := range req.Products {
- //X类试用,转为永续
- if v.Status == utils.COMPANY_STATUS_X_CLASS_TRY_OUT {
- v.Status = utils.COMPANY_STATUS_FOREVER
- }
- if productId == utils.COMPANY_PRODUCT_RAI_ID {
- //查询客户的产品权限
- companyReportPermissionListOld, err := company.GetCompanyReportPermission(req.CompanyId, productId)
- if err != nil {
- br.Msg = "查询客户的产品权限异常"
- br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
- return
- }
- permissionArr := strings.Split(v.PermissionIds, ",")
- //如果所选行业不属于研选订阅跟研选扣点包,那就是非研选试用客户
- var isNoResearch bool
- for _, v := range permissionArr {
- if v != strconv.Itoa(utils.CHART_PERMISSION_ID_YANXUAN) && v != strconv.Itoa(utils.YAN_XUAN_KOU_DIAN_BAO_ID) {
- isNoResearch = true
- continue
- }
- }
- if isNoResearch && len(companyReportPermissionListOld) != len(permissionArr) {
- tryOutCountRai, err := company.GetRaiCompanyTryOutCountNoResearch(sysUser.AdminId)
- if err != nil {
- br.Msg = "判断试用客户量失败"
- br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
- return
- }
- if tryOutCountRai >= utils.COMPANY_STATUS_TRY_OUT_COUNT_RAI {
- br.Msg = "非研选试用客户最多40家"
- return
- }
- }
- }
- if v.IndustryId <= 0 {
- br.Msg = "请选择行业"
- br.IsSendEmail = false
- return
- }
- //获取客户产品信息
- productItem, err := company.GetCompanyProductById(v.CompanyProductId)
- if err != nil {
- br.Msg = "数据获取失败!"
- br.ErrMsg = "数据获取失败,Err:" + err.Error()
- return
- }
- if productItem == nil {
- br.Msg = "客户信息不存在!"
- return
- }
- // 如果本身是有权限归属的,同时传入的参数不是当前账号权限的,那么过滤该次循环,进入下次循环
- if productId > 0 && productItem.ProductId != productId {
- continue
- }
- if v.Status == "" {
- br.Msg = "客户状态不可为空"
- return
- }
- //if v.Reasons == "" {
- // br.Msg = "请填写新增理由"
- // return
- //}
- if v.PermissionIds == "" {
- br.Msg = "请选择权限"
- return
- }
- var startDate, endDate string
- startDate = productItem.StartDate
- endDate = productItem.EndDate
- if startDate == "" || endDate == "" {
- br.Msg = "数据错误"
- br.Msg = "数据错误,开始或结束日期为空:startDate:" + startDate + "endDate:" + endDate
- return
- }
- //判断客户是否已经存在
- companyNameIsExist, err := company.GetCompanyCountByCompanyNameAndCompanyId(req.CompanyId, req.CompanyName)
- if err != nil {
- br.Msg = "判断客户是否存在失败"
- br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
- return
- }
- if companyNameIsExist > 0 {
- br.Msg = "客户已存在,请重新输入客户名称"
- return
- }
- //判断客户是否已经存在
- companyCreditCodeIsExist, err := company.GetCompanyCountByCreditCodeAndCompanyId(req.CompanyId, req.CreditCode)
- if err != nil {
- br.Msg = "判断客户是否存在失败"
- br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
- return
- }
- if companyCreditCodeIsExist > 0 {
- br.Msg = "客户已存在,请重新输入统一社会信用代码"
- return
- }
- seller, err := system.GetSysAdminById(v.SellsId)
- if err != nil {
- br.Msg = "获取销售信息失败"
- br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
- return
- }
- if seller == nil {
- br.Msg = "所属销售不存在"
- return
- }
- //tryOutCount, err := company.GetCompanyTryOutCount(utils.COMPANY_STATUS_TRY_OUT, seller.AdminId)
- //if err != nil {
- // br.Msg = "判断试用客户量失败"
- // br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
- // return
- //}
- //if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
- // roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
- // if tryOutCount >= utils.COMPANY_STATUS_TRY_OUT_COUNT && v.SellsId == sysUser.AdminId {
- // br.Msg = "您的试用客户总数,已超过上限,不可继续新增"
- // return
- // }
- //}
- industry, err := company.GetCompanyIndustryById(v.IndustryId)
- if err != nil {
- br.Msg = "获取行业信息失败"
- br.ErrMsg = "获取行业信息失败,Err:" + err.Error()
- return
- }
- companyProduct := new(company.CompanyProduct)
- companyProduct.ProductId = productItem.ProductId
- companyProduct.CompanyId = req.CompanyId
- companyProduct.CompanyName = req.CompanyName
- companyProduct.Source = v.Source
- companyProduct.Reasons = v.Reasons
- companyProduct.Status = v.Status
- companyProduct.StartDate = startDate
- companyProduct.EndDate = endDate
- companyProduct.IndustryId = v.IndustryId
- companyProduct.IndustryName = industry.IndustryName
- companyProduct.SellerId = seller.AdminId
- companyProduct.SellerName = seller.RealName
- companyProduct.GroupId = seller.GroupId
- companyProduct.DepartmentId = seller.DepartmentId
- companyProduct.IsSuspend = 0
- companyProduct.ModifyTime = time.Now()
- companyProduct.CompanyProductId = v.CompanyProductId
- companyProduct.Scale = v.Scale
- err = company.ModifyCompanyProduct(companyProduct)
- if err != nil {
- br.Msg = "修改客户信息失败"
- br.ErrMsg = "修改客户产品信息失败,Err:" + err.Error()
- return
- }
- // CRM8.8-下面的需求取消, 编辑的时候根据选择开通对应权限
- // 如果是权益客户,编辑的时候开通主观客观权限
- //if v.CompanyType == utils.COMPANY_CLASSIFY_RAI {
- // permissionStr, err := company.GetPermissionIdById(v.PermissionIds)
- // if err != nil {
- // br.Msg = "修改失败"
- // br.ErrMsg = "获取主观客观权限信息失败,Err:" + err.Error()
- // return
- // }
- // v.PermissionIds = permissionStr
- //}
- //处理权限
- companyReportPermissionList, err := services.AddCompanyPermission(req.CompanyId, seller.AdminId, productItem.ProductId, productItem.ProductName, seller.RealName, v.PermissionIds, startDate, endDate)
- if err != nil {
- br.Msg = "修改失败"
- br.ErrMsg = "新增客户设置权限失败,err:" + err.Error()
- return
- }
- //新增操作记录
- {
- record := new(company.CompanyOperationRecord)
- record.CompanyId = req.CompanyId
- record.CompanyName = req.CompanyName
- record.SellerId = companyProduct.SellerId
- record.SysUserId = this.SysUser.AdminId
- record.SysRealName = this.SysUser.RealName
- record.Remark = "编辑客户"
- record.Operation = "edit"
- record.CreateTime = time.Now()
- record.ProductId = productItem.ProductId
- record.ProductName = productItem.ProductName
- record.Status = productItem.Status
- _, err = company.AddCompanyOperationRecord(record)
- if err != nil {
- go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
- //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
- }
- }
- //新增客户产品日志
- {
- productLog := new(company.CompanyProductLog)
- productLog.CompanyProductId = v.CompanyProductId
- productLog.CompanyId = companyProduct.CompanyId
- productLog.ProductId = companyProduct.ProductId
- productLog.ProductName = companyProduct.ProductName
- productLog.CompanyName = companyProduct.CompanyName
- productLog.CompanyName = companyProduct.CompanyName
- productLog.Source = companyProduct.Source
- productLog.Reasons = companyProduct.Reasons
- productLog.Status = companyProduct.Status
- productLog.IndustryId = companyProduct.IndustryId
- productLog.IndustryName = companyProduct.IndustryName
- productLog.SellerId = companyProduct.SellerId
- productLog.SellerName = companyProduct.SellerName
- productLog.GroupId = companyProduct.GroupId
- productLog.DepartmentId = companyProduct.DepartmentId
- productLog.IsSuspend = companyProduct.IsSuspend
- productLog.SuspendTime = companyProduct.SuspendTime
- productLog.ApproveStatus = companyProduct.ApproveStatus
- productLog.FreezeTime = companyProduct.FreezeTime
- productLog.Remark = companyProduct.Remark
- productLog.StartDate = companyProduct.StartDate
- productLog.EndDate = companyProduct.EndDate
- productLog.CreateTime = companyProduct.CreateTime
- productLog.ModifyTime = companyProduct.ModifyTime
- productLog.LoseReason = companyProduct.LoseReason
- productLog.LossTime = companyProduct.LossTime
- productLog.LogType = "modify"
- productLog.LogCreateTime = time.Now()
- productLog.AdminId = this.SysUser.AdminId
- productLog.Scale = companyProduct.Scale
- go company.AddCompanyProductLog(productLog)
- }
- //新增客户产品状态变更日志
- {
- startDateTime, _ := time.ParseInLocation(utils.FormatDate, startDate, time.Local)
- endDateTime, _ := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
- companyProductUpdateLog := &company.CompanyProductUpdateLog{
- Id: 0,
- CompanyId: req.CompanyId,
- ProductId: productId,
- Status: "试用",
- Source: "edit",
- SellerId: seller.AdminId,
- SellerName: seller.RealName,
- StartDate: startDateTime,
- EndDate: endDateTime,
- RealEndDate: startDateTime,
- CreateTime: time.Now(),
- }
- go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
- // 添加试用记录
- companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
- Id: 0,
- CompanyId: req.CompanyId,
- ProductId: productId,
- Source: "edit",
- SellerId: seller.AdminId,
- SellerName: seller.RealName,
- StartDate: startDateTime,
- EndDate: endDateTime,
- RealEndDate: startDateTime,
- IsStop: 0,
- CreateTime: time.Now(),
- }
- go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
- }
- }
- companyItem := new(company.Company)
- companyItem.CompanyId = req.CompanyId
- companyItem.CompanyName = req.CompanyName
- companyItem.CreditCode = req.CreditCode
- companyItem.Province = req.Province
- companyItem.City = req.City
- companyItem.Address = req.Province + req.City
- companyItem.LastUpdatedTime = time.Now()
- companyItem.Enabled = 1
- companyItem.Nation = req.Nation
- err = company.ModifyCompany(companyItem)
- if err != nil {
- br.Msg = "修改客户信息失败"
- br.ErrMsg = "修改客户信息失败,Err:" + err.Error()
- return
- }
- //新增客户日志
- {
- companyLog := new(company.CompanyLog)
- companyLog.CompanyId = req.CompanyId
- companyLog.CompanyName = req.CompanyName
- companyLog.CreditCode = req.CreditCode
- companyLog.Address = companyItem.Address
- companyLog.City = companyItem.City
- companyLog.Province = companyItem.Province
- companyLog.LastUpdatedTime = companyItem.LastUpdatedTime
- companyLog.AdminId = this.SysUser.AdminId
- companyLog.LogType = "modify"
- companyLog.LogCreateTime = time.Now()
- go company.AddCompanyLog(companyLog)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- }
- // @Title 编辑补充客户信息接口
- // @Description 编辑补充客户信息接口
- // @Param request body company.CompanyInfoEditReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /company_info/edit [post]
- func (this *CompanyController) EditCompanyInfo() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req company.CompanyInfoEditReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.CompanyId <= 0 {
- br.Msg = "参数异常!"
- br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
- return
- }
- if req.CompanyName == "" {
- br.Msg = "请填写客户名称"
- return
- }
- if req.CreditCode == "" {
- br.Msg = "请填写社会统一信用码"
- return
- }
- //if req.Province == "" {
- // br.Msg = "请选择省份"
- // return
- //}
- //if req.City == "" {
- // br.Msg = "请选择市区"
- // return
- //}
- //if req.IndustryId <= 0 {
- // br.Msg = "请选择所属行业"
- // return
- //}
- //if req.IndustryName == "" {
- // br.Msg = "请选择所属行业"
- // return
- //}
- //if req.Source == "" {
- // br.Msg = "请选择来源"
- // return
- //}
- //移除空格
- req.CreditCode = utils.TrimStr(req.CreditCode)
- //获取产品权限
- productId := services.GetProductId(sysUser.RoleTypeCode)
- if productId <= 0 {
- br.Msg = "当前账号不允许修改客户信息"
- return
- }
- companyNameIsExist, err := company.GetCompanyCountByCompanyNameAndCompanyId(req.CompanyId, req.CompanyName)
- if err != nil {
- br.Msg = "判断客户是否存在失败"
- br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
- return
- }
- if companyNameIsExist > 0 {
- br.Msg = "客户已存在,请重新输入客户名称"
- return
- }
- //判断客户是否已经存在
- companyCreditCodeIsExist, err := company.GetCompanyCountByCreditCodeAndCompanyId(req.CompanyId, req.CreditCode)
- if err != nil {
- br.Msg = "判断客户是否存在失败"
- br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
- return
- }
- if companyCreditCodeIsExist > 0 {
- br.Msg = "客户已存在,统一社会信用代码"
- return
- }
- //查询该客户
- companyItem, err := company.GetCompanyById(req.CompanyId)
- if err != nil {
- br.Msg = "查找客户失败"
- br.ErrMsg = "查找客户失败,Err:" + err.Error()
- return
- }
- //待更新字段
- updateCol := make([]string, 0)
- companyItem.CompanyName = req.CompanyName
- companyItem.CreditCode = req.CreditCode
- companyItem.Enabled = 1
- companyItem.LastUpdatedTime = time.Now()
- updateCol = append(updateCol, "CompanyName", "CreditCode", "Enabled", "LastUpdatedTime")
- if req.Province != "" && req.City != "" {
- companyItem.Province = req.Province
- companyItem.City = req.City
- companyItem.Address = req.Province + req.City
- updateCol = append(updateCol, "Province", "City", "Address")
- }
- err = companyItem.Update(updateCol)
- if err != nil {
- br.Msg = "修改客户信息失败"
- br.ErrMsg = "修改客户信息失败,Err:" + err.Error()
- return
- }
- //查询并更新客户产品信息
- companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
- if err != nil {
- if err.Error() != utils.ErrNoRow() {
- br.Msg = "查询客户产品信息失败"
- br.ErrMsg = "查询客户产品信息失败,Err:" + err.Error()
- return
- }
- } else {
- if companyProduct != nil {
- //客户产品待更新字段
- updateCompanyProductCol := make([]string, 0)
- //产品信息(来源、行业)
- if req.IndustryId != 0 && req.IndustryId != companyProduct.IndustryId {
- companyProduct.IndustryId = req.IndustryId
- companyProduct.IndustryName = req.IndustryName
- updateCompanyProductCol = append(updateCompanyProductCol, "IndustryId", "IndustryName")
- }
- if req.Source != "" && req.Source != companyProduct.Source {
- companyProduct.Source = req.Source
- updateCompanyProductCol = append(updateCompanyProductCol, "Source")
- }
- //更新客户产品信息
- if len(updateCompanyProductCol) > 0 {
- err = companyProduct.Update(updateCompanyProductCol)
- if err != nil {
- br.Msg = "修改客户信息失败"
- br.ErrMsg = "修改客户信息失败,Err:" + err.Error()
- return
- }
- }
- }
- }
- //新增客户日志
- {
- companyLog := new(company.CompanyLog)
- companyLog.CompanyId = req.CompanyId
- companyLog.CompanyName = req.CompanyName
- companyLog.CreditCode = req.CreditCode
- companyLog.Address = companyItem.Address
- companyLog.City = companyItem.City
- companyLog.Province = companyItem.Province
- companyLog.LastUpdatedTime = companyItem.LastUpdatedTime
- companyLog.AdminId = this.SysUser.AdminId
- companyLog.LogType = "modify"
- companyLog.LogCreateTime = time.Now()
- go company.AddCompanyLog(companyLog)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- }
- // @Title 客户模糊检索(新增/编辑客户页面试用)
- // @Description 客户模糊检索接口(新增/编辑客户页面试用)
- // @Param KeyWord query string true "搜索关键词"
- // @Success 200 {object} company.CompanyFuzzySearchReq
- // @router /fuzzy/search [get]
- func (this *CompanyController) FuzzySearch() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- keyWord := this.GetString("KeyWord")
- list, err := company.GetCompanyFuzzySearch(keyWord)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,err:" + err.Error()
- return
- }
- resp := new(company.CompanyFuzzySearchReq)
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 删除客户
- // @Description 删除客户接口
- // @Param request body company.DeletePptReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /delete [post]
- func (this *CompanyController) Delete() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req company.DeletePptReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.CompanyId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "客户ID小于等于0"
- return
- }
- roleTypeCode := this.SysUser.RoleTypeCode
- productId := services.GetProductId(roleTypeCode)
- productItems, err := company.GetCompanyProductsByCompanyId(req.CompanyId)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "获取客户产品信息失败,Err:" + err.Error()
- return
- }
- // 备份信息
- companyDeleteBakInfo := services.CompanyDeleteBakInfo{
- CompanyId: req.CompanyId,
- CompanyName: "",
- CompanyInfo: &company.Company{},
- CompanyProductInfo: make([]*company.CompanyProduct, 0),
- CompanyPermissionInfo: make([]*company.CompanyReportPermission, 0),
- UserSellerRelationInfo: make([]*models.UserSellerRelation, 0),
- UserRecordInfo: make([]*models.UserRecord, 0),
- UserInfo: make([]*models.WxUser, 0),
- CompanyChartPermissionInfo: make([]*company_user.ChartClassifyPermission, 0),
- OpUserId: this.SysUser.AdminId,
- OpUserName: this.SysUser.RealName,
- }
- if productId == 0 {
- for _, v := range productItems {
- //永续,试用,流失,关闭
- if v.Status != utils.COMPANY_STATUS_FOREVER && v.Status != utils.COMPANY_STATUS_TRY_OUT && v.Status != utils.COMPANY_STATUS_LOSE && v.Status != utils.COMPANY_STATUS_CLOSE {
- br.Msg = "该客户" + v.ProductName + "属性为" + v.Status + ",暂不可删除"
- br.ErrMsg = "该客户" + v.ProductName + "属性为" + v.Status + ",暂不可删除"
- return
- }
- companyProductList, companyReportPermissionList, err := company.DeleteCompanyProductById(v.CompanyId, v.ProductId, v.CompanyProductId)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductList...)
- companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissionList...)
- //新增操作记录
- {
- record := new(company.CompanyOperationRecord)
- record.CompanyId = req.CompanyId
- record.CompanyName = v.CompanyName
- record.SellerId = v.SellerId
- record.SysUserId = this.SysUser.AdminId
- record.SysRealName = this.SysUser.RealName
- record.Remark = "删除客户"
- record.Operation = "delete"
- record.CreateTime = time.Now()
- record.ProductId = v.ProductId
- record.ProductName = v.ProductName
- _, err = company.AddCompanyOperationRecord(record)
- if err != nil {
- go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
- //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
- }
- }
- //删除对应产品的联系人
- userSellerRelationList, userRecordList, wxUserList, chartClassifyPermission, _ := services.DeleteCompanyWxUserByProductId(v.CompanyId, v.ProductId)
- //备份信息
- {
- if companyProductList != nil {
- companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductList...)
- }
- if companyReportPermissionList != nil {
- companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissionList...)
- }
- if userSellerRelationList != nil {
- companyDeleteBakInfo.UserSellerRelationInfo = append(companyDeleteBakInfo.UserSellerRelationInfo, userSellerRelationList...)
- }
- if userRecordList != nil {
- companyDeleteBakInfo.UserRecordInfo = append(companyDeleteBakInfo.UserRecordInfo, userRecordList...)
- }
- if wxUserList != nil {
- companyDeleteBakInfo.UserInfo = append(companyDeleteBakInfo.UserInfo, wxUserList...)
- }
- if chartClassifyPermission != nil {
- companyDeleteBakInfo.CompanyChartPermissionInfo = append(companyDeleteBakInfo.CompanyChartPermissionInfo, chartClassifyPermission...)
- }
- companyDeleteBakInfo.CompanyName = v.CompanyName
- }
- }
- } else {
- productObj, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
- if err != nil {
- br.ErrMsg = "获取客户产品信息失败,Err:" + err.Error()
- br.Msg = "删除失败"
- return
- }
- //永续,试用,流失,关闭
- if productObj.Status != utils.COMPANY_STATUS_FOREVER && productObj.Status != utils.COMPANY_STATUS_TRY_OUT && productObj.Status != utils.COMPANY_STATUS_LOSE && productObj.Status != utils.COMPANY_STATUS_CLOSE {
- br.Msg = "该客户" + productObj.ProductName + "属性为" + productObj.Status + ",暂不可删除"
- br.ErrMsg = "该客户" + productObj.ProductName + "属性为" + productObj.Status + ",暂不可删除"
- return
- }
- companyProductList, companyReportPermissionList, err := company.DeleteCompanyProductById(productObj.CompanyId, productObj.ProductId, productObj.CompanyProductId)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- //新增操作记录
- {
- record := new(company.CompanyOperationRecord)
- record.CompanyId = req.CompanyId
- record.CompanyName = productObj.CompanyName
- record.SellerId = productObj.SellerId
- record.SysUserId = this.SysUser.AdminId
- record.SysRealName = this.SysUser.RealName
- record.Remark = "删除客户"
- record.Operation = "delete"
- record.CreateTime = time.Now()
- record.ProductId = productObj.ProductId
- record.ProductName = productObj.ProductName
- _, err = company.AddCompanyOperationRecord(record)
- if err != nil {
- go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
- //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
- }
- }
- //删除对应产品的联系人
- userSellerRelationList, userRecordList, wxUserList, chartClassifyPermission, _ := services.DeleteCompanyWxUserByProductId(productObj.CompanyId, productId)
- //备份信息
- {
- if companyProductList != nil {
- companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductList...)
- }
- if companyReportPermissionList != nil {
- companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissionList...)
- }
- if userSellerRelationList != nil {
- companyDeleteBakInfo.UserSellerRelationInfo = append(companyDeleteBakInfo.UserSellerRelationInfo, userSellerRelationList...)
- }
- if userRecordList != nil {
- companyDeleteBakInfo.UserRecordInfo = append(companyDeleteBakInfo.UserRecordInfo, userRecordList...)
- }
- if wxUserList != nil {
- companyDeleteBakInfo.UserInfo = append(companyDeleteBakInfo.UserInfo, wxUserList...)
- }
- if chartClassifyPermission != nil {
- companyDeleteBakInfo.CompanyChartPermissionInfo = append(companyDeleteBakInfo.CompanyChartPermissionInfo, chartClassifyPermission...)
- }
- companyDeleteBakInfo.CompanyName = productObj.CompanyName
- }
- }
- productItemsNew, err := company.GetCompanyProductsByCompanyId(req.CompanyId)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "获取客户产品信息失败,Err:" + err.Error()
- return
- }
- if len(productItemsNew) == 0 {
- //删除之前查询的数据信息
- {
- companyProductLists, companyReportPermissions, wxUsers, userSellerRelations, companyContracts, companyContractPermissions, companyInfo, _ := services.GetBeforeDeleteCompanyInfo(req.CompanyId)
- //companyDeleteBakInfo
- if companyProductLists != nil {
- companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductLists...)
- }
- if companyReportPermissions != nil {
- companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissions...)
- }
- if wxUsers != nil {
- companyDeleteBakInfo.UserInfo = append(companyDeleteBakInfo.UserInfo, wxUsers...)
- }
- if userSellerRelations != nil {
- companyDeleteBakInfo.UserSellerRelationInfo = append(companyDeleteBakInfo.UserSellerRelationInfo, userSellerRelations...)
- }
- if companyContracts != nil {
- companyDeleteBakInfo.CompanyContract = append(companyDeleteBakInfo.CompanyContract, companyContracts...)
- }
- if companyContractPermissions != nil {
- companyDeleteBakInfo.CompanyContractPermission = append(companyDeleteBakInfo.CompanyContractPermission, companyContractPermissions...)
- }
- if companyInfo != nil {
- companyDeleteBakInfo.CompanyName = companyInfo.CompanyName
- companyDeleteBakInfo.CompanyInfo = companyInfo
- }
- }
- err = company.DeleteCompanyById(req.CompanyId)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- for _, v := range productItems {
- //新增操作记录
- {
- record := new(company.CompanyOperationRecord)
- record.CompanyId = req.CompanyId
- record.CompanyName = v.CompanyName
- record.SellerId = v.SellerId
- record.SysUserId = this.SysUser.AdminId
- record.SysRealName = this.SysUser.RealName
- record.Remark = "删除客户"
- record.Operation = "delete"
- record.CreateTime = time.Now()
- record.ProductId = v.ProductId
- record.ProductName = v.ProductName
- _, err = company.AddCompanyOperationRecord(record)
- if err != nil {
- go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
- //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
- }
- }
- }
- }
- //数据备份入库
- {
- companyInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyInfo)
- companyProductInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyProductInfo)
- companyPermissionInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyPermissionInfo)
- userSellerRelationInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.UserSellerRelationInfo)
- userRecordInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.UserRecordInfo)
- userInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.UserInfo)
- companyChartPermissionInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyChartPermissionInfo)
- companyContractByte, _ := json.Marshal(companyDeleteBakInfo.CompanyContract)
- companyContractPermissionJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyContractPermission)
- companyDeleteBak := &company.CompanyDeleteBak{
- //DeleteBakId: 0,
- CompanyId: companyDeleteBakInfo.CompanyId,
- CompanyName: companyDeleteBakInfo.CompanyName,
- CompanyInfo: string(companyInfoJsonByte),
- CompanyProductInfo: string(companyProductInfoJsonByte),
- CompanyPermissionInfo: string(companyPermissionInfoJsonByte),
- UserSellerRelationInfo: string(userSellerRelationInfoJsonByte),
- UserRecordInfo: string(userRecordInfoJsonByte),
- UserInfo: string(userInfoJsonByte),
- CompanyChartPermissionInfo: string(companyChartPermissionInfoJsonByte),
- CompanyContractInfo: string(companyContractByte),
- CompanyContractPermissionInfo: string(companyContractPermissionJsonByte),
- OpUserId: this.SysUser.AdminId,
- OpUserName: this.SysUser.RealName,
- CreateTime: time.Now(),
- }
- _ = company.AddCompanyDeleteBak(companyDeleteBak)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "删除成功"
- }
- // @Title 领取客户列表
- // @Description 领取客户列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param StartDate query string true "开始时间"
- // @Param EndDate query string true "结束时间"
- // @Param KeyWord query string true "搜索关键词"
- // @Success 200 {object} company.CompanyReceiveListResp
- // @router /receive/list [get]
- func (this *CompanyController) ReceiveList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var productId, recevieProductId int
- roleTypeCode := sysUser.RoleTypeCode
- productId = services.GetProductId(roleTypeCode)
- if productId == 1 {
- recevieProductId = 2
- } else if productId == 2 {
- recevieProductId = 1
- }
- if productId == 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "客户类型为:" + roleTypeCode
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- adminId := this.GetString("AdminId")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- keyWord := this.GetString("KeyWord")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- if adminId != "" {
- condition += ` AND c.seller_id IN (` + adminId + `) `
- }
- if startDate != "" {
- condition += ` AND c.start_date>=? `
- pars = append(pars, startDate)
- }
- if endDate != "" {
- condition += ` AND c.end_date>=? `
- pars = append(pars, endDate)
- }
- if keyWord != "" {
- condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR b.mobile LIKE '%` + keyWord + `%' OR b.email LIKE '%` + keyWord + `%') `
- }
- total, err := company.GetCompanyReceiveListCount(condition, pars, productId, recevieProductId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
- return
- }
- list, err := company.GetCompanyReceiveList(condition, pars, productId, recevieProductId, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- lenList := len(list)
- for i := 0; i < lenList; i++ {
- item := list[i]
- var expireDay string
- if item.Status != "" {
- status := item.Status
- if item.EndDate != "" {
- if status == utils.COMPANY_STATUS_FOREVER { //永续
- expireDay = "-"
- } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用/正式
- endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
- sub := endDateTime.Sub(time.Now())
- expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
- } else if status == utils.COMPANY_STATUS_LOSE { //流失
- expireDay = "-"
- } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- if item.StartDate != "" && item.EndDate != "" {
- endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
- sub := endDateTime.Sub(time.Now())
- expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
- } else {
- expireDay = "-"
- }
- } else {
- expireDay = "-"
- }
- }
- }
- list[i].ExpireDay = expireDay
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(company.CompanyReceiveListResp)
- resp.List = list
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 领取客户
- // @Description 领取客户接口
- // @Param request body company.CompanyReceiveReq true "type json string"
- // @Success Ret=200 领取成功
- // @router /receive [post]
- func (this *CompanyController) Receive() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req company.CompanyReceiveReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.CompanyId <= 0 {
- br.Msg = "参数异常!"
- br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
- return
- }
- //权益主观客观权限一块开
- if req.PermissionIds != "" {
- permissionStr, err := company.GetPermissionIdById(req.PermissionIds)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取主观客观权限信息失败,Err:" + err.Error()
- return
- }
- req.PermissionIds = permissionStr
- }
- roleTypeCode := sysUser.RoleTypeCode
- productId := services.GetProductId(roleTypeCode)
- if productId == 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "客户类型为:" + roleTypeCode
- return
- }
- sellsId := 0
- if req.SellsId <= 0 {
- sellsId = sysUser.AdminId
- } else {
- sellsId = req.SellsId
- }
- seller, err := system.GetSysAdminById(sellsId)
- if err != nil {
- br.Msg = "获取销售信息失败"
- br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
- return
- }
- companyDetail, err := company.GetCompanyDetailById(req.CompanyId)
- if err != nil {
- br.Msg = "获取客户信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取客户信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- productName := ""
- var status string
- if productId == 1 {
- productName = utils.COMPANY_PRODUCT_FICC_NAME
- } else {
- productName = utils.COMPANY_PRODUCT_RAI_NAME
- }
- if productId == utils.COMPANY_PRODUCT_RAI_ID {
- //查询客户的产品权限
- companyReportPermissionListOld, err := company.GetCompanyReportPermission(req.CompanyId, productId)
- if err != nil {
- br.Msg = "查询客户的产品权限异常"
- br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
- return
- }
- var isNoResearch bool
- for _, v := range companyReportPermissionListOld {
- if v.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN && v.ChartPermissionId != utils.YAN_XUAN_KOU_DIAN_BAO_ID {
- isNoResearch = true
- continue
- }
- }
- //如果所选行业不属于研选订阅跟研选扣点包,那就是非研选试用客户
- if isNoResearch {
- tryOutCountRai, err := company.GetRaiCompanyTryOutCountNoResearch(req.SellsId)
- if err != nil {
- br.Msg = "判断试用客户量失败"
- br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
- return
- }
- if tryOutCountRai >= utils.COMPANY_STATUS_TRY_OUT_COUNT_RAI {
- br.Msg = "非研选试用客户最多40家"
- return
- }
- }
- }
- if cp != nil {
- if cp.Status != utils.COMPANY_STATUS_LOSE {
- br.Msg = "客户状态为:" + cp.Status + ";不可领取"
- br.ErrMsg = "客户状态为:" + cp.Status + ";不可领取"
- return
- }
- if cp.SellerId == sysUser.AdminId {
- br.Msg = "已为自己客户,不可重复领取"
- br.ErrMsg = "已为自己客户,不可领取:company_id:" + strconv.Itoa(cp.CompanyId)
- return
- }
- //转移 销售
- companyReportPermissionList, startDate, endDate, err := company.MoveSeller(req.CompanyId, productId, seller.AdminId, seller.GroupId, seller.DepartmentId, seller.RealName)
- if err != nil {
- br.Msg = "领取失败"
- br.ErrMsg = "领取失败,Err:" + err.Error()
- return
- }
- //新增客户产品状态变更日志
- {
- companyProductUpdateLog := &company.CompanyProductUpdateLog{
- Id: 0,
- CompanyId: req.CompanyId,
- ProductId: productId,
- Status: "试用",
- Source: "receive",
- SellerId: seller.AdminId,
- SellerName: seller.RealName,
- StartDate: startDate,
- EndDate: endDate,
- RealEndDate: startDate,
- CreateTime: time.Now(),
- }
- go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
- companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
- Id: 0,
- CompanyId: req.CompanyId,
- ProductId: productId,
- Source: "receive",
- SellerId: seller.AdminId,
- SellerName: seller.RealName,
- StartDate: startDate,
- EndDate: endDate,
- RealEndDate: startDate,
- IsStop: 0,
- CreateTime: time.Now(),
- }
- go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
- }
- //流失转试用,企业下面的用户自动添加产业关注
- {
- go cygxService.AddUserFllowCompanyLossToTryOut(req.CompanyId)
- }
- } else {
- //跨部门领取
- var startDateTime, endDateTime time.Time
- if req.Status == utils.COMPANY_STATUS_TRY_OUT {
- startDateTime = time.Now()
- endDateTime = time.Now().AddDate(0, 2, 0)
- } else if req.Status == utils.COMPANY_STATUS_FOREVER {
- startDateTime = time.Now()
- endDateTime = time.Now().AddDate(100, 0, 0)
- } else {
- br.Msg = "无效的客户状态,请重新选择"
- return
- }
- var startDate, endDate string
- startDate = startDateTime.Format(utils.FormatDate)
- endDate = endDateTime.Format(utils.FormatDate)
- if req.PermissionIds == "" {
- br.Msg = "请选择权限!"
- return
- }
- industry, err := company.GetCompanyIndustryById(req.IndustryId)
- if err != nil {
- br.Msg = "获取行业信息失败"
- br.ErrMsg = "获取行业信息失败,Err:" + err.Error()
- return
- }
- if industry == nil {
- br.Msg = "行业信息不存在"
- return
- }
- status = req.Status
- companyProduct := new(company.CompanyProduct)
- companyProduct.CompanyId = req.CompanyId
- companyProduct.ProductId = productId
- companyProduct.ProductName = productName
- companyProduct.CompanyName = companyDetail.CompanyName
- companyProduct.Source = req.Source
- companyProduct.Reasons = req.Reasons
- companyProduct.Status = status
- companyProduct.StartDate = startDate
- companyProduct.EndDate = endDate
- companyProduct.IndustryId = req.IndustryId
- companyProduct.IndustryName = industry.IndustryName
- companyProduct.SellerId = seller.AdminId
- companyProduct.SellerName = seller.RealName
- companyProduct.GroupId = seller.GroupId
- companyProduct.DepartmentId = seller.DepartmentId
- companyProduct.IsSuspend = 0
- companyProduct.CreateTime = time.Now()
- companyProduct.ModifyTime = time.Now()
- companyProduct.CompanyType = req.CompanyType
- companyProduct.OpenCode = services.GenerateOpenCompanyProductCode(req.CompanyId, productId)
- companyProduct.TodoStatus = "无任务"
- companyProduct.TryStage = 1
- companyProduct.SellerIdInit = seller.AdminId
- companyProduct.SellerNameInit = seller.RealName
- _, err = company.AddCompanyProduct(companyProduct)
- if err != nil {
- br.Msg = "新增失败"
- br.ErrMsg = "新增客户产品失败,err:" + err.Error()
- return
- }
- companyReportPermissionList, err := services.AddCompanyPermission(req.CompanyId, seller.AdminId, productId, productName, seller.RealName, req.PermissionIds, startDate, endDate)
- if err != nil {
- br.Msg = "新增失败"
- br.ErrMsg = "新增客户设置权限失败,err:" + err.Error()
- return
- }
- //新增客户产品日志
- {
- go services.AddCompanyProductLog(companyProduct, this.SysUser.AdminId, "add")
- }
- //新增客户产品状态变更日志
- {
- companyProductUpdateLog := &company.CompanyProductUpdateLog{
- Id: 0,
- CompanyId: companyProduct.CompanyId,
- ProductId: companyProduct.ProductId,
- Status: "试用",
- SellerId: seller.AdminId,
- SellerName: seller.RealName,
- Source: "add",
- StartDate: startDateTime,
- EndDate: endDateTime,
- RealEndDate: startDateTime,
- CreateTime: time.Now(),
- }
- go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
- companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
- Id: 0,
- CompanyId: companyProduct.CompanyId,
- ProductId: companyProduct.ProductId,
- SellerId: seller.AdminId,
- SellerName: seller.RealName,
- Source: "add",
- StartDate: startDateTime,
- EndDate: endDateTime,
- RealEndDate: startDateTime,
- IsStop: 0,
- CreateTime: time.Now(),
- }
- go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
- }
- //查询当前客户的所有产品的列表数据,并找出非当前产品的销售去发送模板消息
- companyProductList, err := company.GetCompanyProductsByCompanyId(req.CompanyId)
- for _, companyProduct := range companyProductList {
- //如果是当前领取的产品,那么就退出当前循环,进入下一循环
- if companyProduct.ProductId == productId {
- continue
- }
- //查询其他部门销售的信息
- admin, tmpErr := system.GetSysAdminById(companyProduct.SellerId)
- if tmpErr != nil {
- continue
- }
- //发送模板消息给另一个部门的销售
- go services.SendCompanyReceiveWxTemplateMsg(companyDetail.CompanyName, productName, sysUser.RealName, admin.Mobile)
- }
- }
- //新增操作记录
- {
- remark := "领取客户"
- operation := "receive"
- services.AddCompanyOperationRecord(req.CompanyId, seller.AdminId, sysUser.AdminId, productId, sysUser.AdminId, companyDetail.CompanyName,
- productName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", status)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "领取成功"
- }
- // @Title 移动销售
- // @Description 移动销售接口
- // @Param request body company.MoveSellerReq true "type json string"
- // @Success Ret=200 移动成功
- // @router /move/seller [post]
- func (this *CompanyController) MoveSeller() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req company.MoveSellerReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.CompanyId <= 0 {
- br.Msg = "参数异常!"
- br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
- return
- }
- if req.SellsId <= 0 {
- br.Msg = "参数异常!"
- br.ErrMsg = "SellsId:" + strconv.Itoa(req.SellsId)
- return
- }
- seller, err := system.GetSysAdminById(req.SellsId)
- if err != nil {
- br.Msg = "获取销售信息失败"
- br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
- return
- }
- roleTypeCode := sysUser.RoleTypeCode
- productId := services.GetProductId(roleTypeCode)
- if productId == 0 {
- if req.CompanyType == utils.COMPANY_CLASSIFY_FICC {
- productId = 1
- } else if req.CompanyType == utils.COMPANY_CLASSIFY_RAI {
- productId = 2
- }
- }
- if productId == 0 {
- br.Msg = "无效的客户类型"
- br.ErrMsg = "无效的客户类型"
- return
- }
- if productId == utils.COMPANY_PRODUCT_RAI_ID {
- //查询客户的产品权限
- companyReportPermissionListOld, err := company.GetCompanyReportPermission(req.CompanyId, productId)
- if err != nil {
- br.Msg = "查询客户的产品权限异常"
- br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
- return
- }
- var isNoResearch bool
- for _, v := range companyReportPermissionListOld {
- if v.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN && v.ChartPermissionId != utils.YAN_XUAN_KOU_DIAN_BAO_ID {
- isNoResearch = true
- continue
- }
- }
- //如果所选行业不属于研选订阅跟研选扣点包,那就是非研选试用客户
- if isNoResearch {
- tryOutCountRai, err := company.GetRaiCompanyTryOutCountNoResearch(req.SellsId)
- if err != nil {
- br.Msg = "判断试用客户量失败"
- br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
- return
- }
- if tryOutCountRai >= utils.COMPANY_STATUS_TRY_OUT_COUNT_RAI {
- br.Msg = seller.RealName + "的非研选试用客户已超过40家"
- return
- }
- }
- }
- cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "客户信息不存在"
- br.ErrMsg = "客户信息不存在,Err:" + err.Error()
- return
- }
- br.Msg = "获取客户信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- if cp == nil {
- br.Msg = "客户信息不存在,请刷新页面"
- br.ErrMsg = "客户信息不存在"
- return
- }
- err = company.MoveCompanySeller(req.CompanyId, productId, req.SellsId, seller.GroupId, seller.DepartmentId, seller.RealName)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "移动失败,Err:" + err.Error()
- return
- }
- //新增操作记录
- {
- remark := "移动到:" + seller.RealName
- operation := "move_seller"
- services.AddCompanyOperationRecord(req.CompanyId, seller.AdminId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
- cp.ProductName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
- }
- {
- services.UpdateCompanyContractSellerMove(req.CompanyId, productId) //益客户移动所属销售之后,更新所关联的销售信息
- }
- //变更销售员与联系人关系
- _ = models.UpdateUserSellerRelationByCompanyId(req.CompanyId, productId, seller.AdminId, seller.RealName)
- br.Ret = 200
- br.Success = true
- br.Msg = "移动成功"
- }
- // @Title 修改试用客户标签
- // @Description 修改试用客户标签接口
- // @Param request body company.UpdateTryStageReq true "type json string"
- // @Success Ret=200 设置成功
- // @router /update/tryStage [post]
- func (this *CompanyController) UpdateTryStage() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req company.UpdateTryStageReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.CompanyId <= 0 {
- br.Msg = "参数异常!"
- br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
- return
- }
- if req.ProductId <= 0 {
- br.Msg = "参数异常!"
- br.ErrMsg = "ProductId:" + strconv.Itoa(req.ProductId)
- return
- }
- if req.TryStage <= 0 {
- br.Msg = "参数异常!"
- br.ErrMsg = "TryStage:" + strconv.Itoa(req.TryStage)
- return
- }
- cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "客户信息不存在"
- br.ErrMsg = "客户信息不存在,Err:" + err.Error()
- return
- }
- br.Msg = "获取客户信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- fmt.Println(cp)
- if cp == nil {
- br.Msg = "客户信息不存在,请刷新页面"
- br.ErrMsg = "客户信息不存在"
- return
- }
- if cp.Status != "试用" {
- br.Msg = "客户不是试用状态,不允许修改"
- br.ErrMsg = "客户不是试用状态,不允许修改"
- return
- }
- if cp.SellerId != sysUser.AdminId {
- br.Msg = "无修改权限"
- br.ErrMsg = "无修改权限"
- return
- }
- if cp.TryStage == req.TryStage {
- br.Msg = "与原标签一致,无需修改"
- br.ErrMsg = "与原标签一致,无需修改"
- return
- }
- err = company.UpdateCompanyTryStage(req.CompanyId, req.ProductId, req.TryStage)
- if err != nil {
- br.Msg = "设置失败"
- br.ErrMsg = "设置失败,Err:" + err.Error()
- return
- }
- //新增操作记录
- {
- stage := ""
- tryStageAllMap := map[int]string{
- 1: "未分类",
- 2: "推进",
- 3: "跟踪",
- 4: "预备",
- }
- if v, ok := tryStageAllMap[req.TryStage]; ok {
- stage = v
- }
- remark := "修改试用客户子标签:" + stage
- operation := "UpdateTryStage"
- services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
- cp.ProductName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "设置成功"
- }
- // @Title 暂停/启用
- // @Description 暂停/启用接口
- // @Param request body company.SuspendReq true "type json string"
- // @Success Ret=200 移动成功
- // @router /suspend [post]
- func (this *CompanyController) Suspend() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req company.SuspendReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.CompanyId <= 0 {
- br.Msg = "参数异常!"
- br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
- return
- }
- roleTypeCode := sysUser.RoleTypeCode
- productId := services.GetProductId(roleTypeCode)
- if productId == 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "角色类型为:" + roleTypeCode
- return
- }
- cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
- if err != nil {
- br.Msg = "获取数据异常!"
- br.ErrMsg = "获取数据异常:" + err.Error()
- return
- }
- suspendStatus := ""
- suspend := 0
- if cp.IsSuspend == 1 {
- suspendStatus = "启用"
- suspend = 0
- } else {
- suspendStatus = "暂停"
- suspend = 1
- }
- if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
- br.Msg = "客户状态为:" + cp.Status + ",不允许进行" + suspendStatus + "操作"
- br.ErrMsg = "客户状态为:" + cp.Status + ",不允许进行" + suspendStatus + "操作"
- return
- }
- err = company.SuspendCompanyProductById(req.CompanyId, productId, suspend)
- if err != nil {
- br.Msg = suspendStatus + "失败"
- br.ErrMsg = suspendStatus + "失败 Err:" + err.Error()
- return
- }
- //新增操作记录
- {
- remark := suspendStatus
- operation := "is_suspend"
- services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
- cp.ProductName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = suspendStatus + "成功"
- }
- // @Title 检测客户名称或社会信用码
- // @Description 检测客户名称或社会信用码接口(新增/编辑客户页面使用)
- // @Param CompanyName query string true "客户名称"
- // @Param CreditCode query string true "社会统一信用码"
- // @Success 200 {object} company.CheckCompanyInfoResp
- // @router /check/companyInfo [get]
- func (this *CompanyController) CheckCompanyInfo() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- roleTypeCode := sysUser.RoleTypeCode
- productId := services.GetProductId(roleTypeCode)
- companyName := this.GetString("CompanyName")
- creditCode := this.GetString("CreditCode")
- var status, comanyId int
- var productName string
- if productId == 0 {
- productId = 1
- checkProductId := 2
- if companyName != "" {
- nameItem, err := company.CheckCompanyProductByName(companyName, productId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "校验客户名称是否存在失败"
- br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
- return
- }
- if nameItem != nil && nameItem.CompanyId > 0 {
- br.Msg = "客户名称已存在,请重新填写"
- br.ErrMsg = "客户名称已存在,请重新填写"
- br.Ret = 405
- return
- }
- nameCheckItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "校验客户名称是否存在失败"
- br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
- return
- }
- if nameCheckItem != nil && nameCheckItem.CompanyId > 0 {
- status = 1
- productName = nameCheckItem.ProductName
- comanyId = nameCheckItem.CompanyId
- goto Loop
- }
- }
- if creditCode != "" {
- codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "校验社会信用码是否存在失败"
- br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
- return
- }
- if codeItem != nil && codeItem.CompanyId > 0 {
- br.Msg = "社会信用码已存在,请重新填写"
- br.ErrMsg = "社会信用码已存在,请重新填写"
- br.Ret = 405
- return
- }
- codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "校验社会信用码是否存在失败"
- br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
- return
- }
- if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
- status = 1
- productName = codeCheckItem.ProductName
- comanyId = codeCheckItem.CompanyId
- goto Loop
- }
- }
- productId = 2
- checkProductId = 1
- if companyName != "" {
- nameItem, err := company.CheckCompanyProductByName(companyName, productId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "校验客户名称是否存在失败"
- br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
- return
- }
- if nameItem != nil && nameItem.CompanyId > 0 {
- br.Msg = "客户名称已存在,请重新填写"
- br.ErrMsg = "客户名称已存在,请重新填写"
- br.Ret = 405
- return
- }
- nameCheckItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "校验客户名称是否存在失败"
- br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
- return
- }
- if nameCheckItem != nil && nameCheckItem.CompanyId > 0 {
- status = 1
- productName = nameCheckItem.ProductName
- comanyId = nameCheckItem.CompanyId
- goto Loop
- }
- }
- if creditCode != "" {
- codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "校验社会信用码是否存在失败"
- br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
- return
- }
- if codeItem != nil && codeItem.CompanyId > 0 {
- br.Msg = "社会信用码已存在,请重新填写"
- br.ErrMsg = "社会信用码已存在,请重新填写"
- br.Ret = 405
- return
- }
- codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "校验社会信用码是否存在失败"
- br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
- return
- }
- if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
- status = 1
- productName = codeCheckItem.ProductName
- comanyId = codeCheckItem.CompanyId
- goto Loop
- }
- }
- } else {
- checkProductId := 0
- if productId == 1 {
- checkProductId = 2
- } else if productId == 2 {
- checkProductId = 1
- }
- if companyName != "" {
- nameItem, err := company.CheckCompanyProductByName(companyName, productId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "校验客户名称是否存在失败"
- br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
- return
- }
- if nameItem != nil && nameItem.ProductName != "" {
- br.Msg = "客户名称已存在,请重新填写"
- br.ErrMsg = "客户名称已存在,请重新填写"
- br.Ret = 405
- return
- }
- nameCheckoutItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "校验客户名称是否存在失败"
- br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
- return
- }
- if nameCheckoutItem != nil && nameCheckoutItem.CompanyId > 0 {
- status = 1
- productName = nameCheckoutItem.ProductName
- comanyId = nameCheckoutItem.CompanyId
- goto Loop
- }
- }
- if creditCode != "" {
- codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "校验社会信用码是否存在失败"
- br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
- return
- }
- if codeItem != nil && codeItem.CompanyId > 0 {
- br.Msg = "社会信用码已存在,请重新填写"
- br.ErrMsg = "社会信用码已存在,请重新填写"
- br.Ret = 405
- return
- }
- codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "校验社会信用码是否存在失败"
- br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
- return
- }
- if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
- status = 1
- productName = codeCheckItem.ProductName
- comanyId = codeCheckItem.CompanyId
- goto Loop
- }
- }
- }
- Loop:
- resp := new(company.CheckCompanyInfoResp)
- resp.Status = status
- resp.ProductName = productName
- resp.CompanyId = comanyId
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 客户导出
- // @Description 客户导出接口
- // @Param Status query string true "状态:'试用','永续','冻结','流失','正式'"
- // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
- // @Param IndustryId query int true "行业id,0为全部"
- // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
- // @Param ChartPermissionIds query string false "阅读权限品种ID,多个用英文逗号分开,空字符串为全部"
- // @Param ContractPermissionIds query string false "已购品种ID,多个用英文逗号分开,空字符串为全部"
- // @Param StartDate query string true "开始时间"
- // @Param EndDate query string true "结束时间"
- // @Param CreateStartDate query string true "创建开始时间"
- // @Param CreateEndDate query string true "创建结束时间"
- // @Param KeyWord query string true "搜索关键词"
- // @Param Address query string true "地址 , 多个用英文逗号分开 "
- // @Param Province query string true "省 , 多个用英文逗号分开 "
- // @Param City query string true "市 , 多个用英文逗号分开 "
- // @Param PackageType query int true "套餐类型,0:无,1:大套餐,2:小套餐"
- // @Success 200 {object} company.CompanyListResp
- // @router /export [get]
- func (this *CompanyController) Export() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- roleTypeCode := sysUser.RoleTypeCode
- status := this.GetString("Status")
- companyType := this.GetString("CompanyType")
- industryId, _ := this.GetInt("IndustryId")
- adminId := this.GetString("AdminId")
- chartPermissionIds := this.GetString("ChartPermissionIds")
- contractPermissionIds := this.GetString("ContractPermissionIds")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- createStartDate := this.GetString("CreateStartDate")
- createEndDate := this.GetString("CreateEndDate")
- keyWord := this.GetString("KeyWord")
- keyWord = strings.Trim(keyWord, " ")
- address := this.GetString("Address")
- province := this.GetString("Province")
- city := this.GetString("City")
- // 套餐类型
- packageType, _ := this.GetInt("PackageType")
- resp := new(company.CompanyListResp)
- statusItems := make([]*company.CompanyStatus, 0)
- var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}
- var condition string
- var pars []interface{}
- //状态分类查询条件
- var permissionCondition string
- var permissionPars []interface{}
- if companyType != "" {
- condition += ` AND b.product_name=? `
- pars = append(pars, companyType)
- }
- if industryId > 0 {
- condition += ` AND b.industry_id=? `
- pars = append(pars, industryId)
- }
- if adminId != "" {
- condition += ` AND b.seller_id IN (` + adminId + `) `
- }
- if startDate != "" {
- condition += ` AND b.start_date>=? `
- pars = append(pars, startDate)
- }
- if endDate != "" {
- condition += ` AND b.end_date<=? `
- pars = append(pars, endDate)
- }
- if createStartDate != "" {
- condition += ` AND a.created_time>=? `
- pars = append(pars, createStartDate)
- }
- if createEndDate != "" {
- condition += ` AND a.created_time<=? `
- pars = append(pars, createEndDate)
- }
- if address != "" {
- var addressSql string
- slice := strings.Split(address, ",")
- for _, v := range slice {
- addressSql += "'" + v + "'" + ","
- }
- addressSql = strings.TrimRight(addressSql, ",")
- condition += ` AND a.address IN (` + addressSql + `) `
- }
- if province != "" {
- var provinceSql string
- slice := strings.Split(province, ",")
- for _, v := range slice {
- provinceSql += "'" + v + "'" + ","
- }
- provinceSql = strings.TrimRight(provinceSql, ",")
- condition += ` AND a.province IN (` + provinceSql + `) `
- }
- if city != "" {
- var citySql string
- slice := strings.Split(city, ",")
- for _, v := range slice {
- citySql += "'" + v + "'" + ","
- }
- citySql = strings.TrimRight(citySql, ",")
- condition += ` AND a.city IN (` + citySql + `) `
- }
- if keyWord != "" {
- companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
- if err != nil {
- br.Msg = "获取客户信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- if companyIdStr != "" {
- condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
- } else {
- condition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
- }
- }
- //if chartPermissionIds != "" && chartPermissionIds != "1" {
- // companyIdStr, err := company.GetCompanyListCompanyIdByPermissionIdStr(chartPermissionIds)
- // if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
- // return
- // }
- // if companyIdStr != "" {
- // condition += ` AND a.company_id IN (` + companyIdStr + `) `
- // } else {
- // for _, v := range statusArr {
- // statusCount := new(company.CompanyStatus)
- // if v == "全部" {
- // statusCount.Status = "全部"
- // statusCount.Count = 0
- // } else {
- // statusCount.Status = v
- // statusCount.Count = 0
- // }
- // statusItems = append(statusItems, statusCount)
- // }
- // items := make([]*company.CompanyListItem, 0)
- // resp.List = items
- // resp.StatusCount = statusItems
- // br.Msg = "获取成功"
- // br.Ret = 200
- // br.Data = resp
- // return
- // }
- //}
- // 阅读权限/已购品种筛选
- cond, emp, e := services.FilterReadAndContractAuth(chartPermissionIds, contractPermissionIds, condition)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "FilterReadAndContractAuth err: " + e.Error()
- return
- }
- if emp {
- for _, v := range statusArr {
- statusCount := new(company.CompanyStatus)
- if v == "全部" {
- statusCount.Status = "全部"
- statusCount.Count = 0
- } else {
- statusCount.Status = v
- statusCount.Count = 0
- }
- statusItems = append(statusItems, statusCount)
- }
- items := make([]*company.CompanyListItem, 0)
- resp.List = items
- resp.StatusCount = statusItems
- br.Msg = "获取成功"
- br.Ret = 200
- br.Data = resp
- return
- }
- condition = cond
- //套餐类型
- if packageType > 0 {
- condition += ` AND b.package_type=? `
- pars = append(pars, packageType)
- }
- permissionCondition = condition
- permissionPars = pars
- productId := services.GetProductId(roleTypeCode)
- //权限控制
- {
- //如果不是超级管理员
- if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
- //如果是部门管理员
- if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
- condition += ` AND b.product_id=? `
- pars = append(pars, productId)
- permissionCondition += ` AND b.product_id=? `
- permissionPars = append(permissionPars, productId)
- } else {
- condition += ` AND b.product_id=? `
- pars = append(pars, productId)
- permissionCondition += ` AND b.product_id=? `
- permissionPars = append(permissionPars, productId)
- if status == "全部" {
- ////如果是筛选了流失客户状态
- if sysUser.Authority <= 0 {
- condition += ` AND (b.seller_id=? OR status='流失') `
- pars = append(pars, sysUser.AdminId)
- permissionCondition += ` AND b.seller_id=? `
- permissionPars = append(permissionPars, sysUser.AdminId)
- } else {
- if sysUser.Authority == 1 {
- condition += ` AND (b.department_id=? OR status='流失')`
- pars = append(pars, sysUser.DepartmentId)
- permissionCondition += ` AND b.department_id=? `
- permissionPars = append(permissionPars, sysUser.DepartmentId)
- }
- if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND (b.group_id=? OR status='流失') `
- pars = append(pars, sysUser.GroupId)
- }
- permissionCondition += ` AND b.group_id=? `
- permissionPars = append(permissionPars, sysUser.GroupId)
- }
- if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
- pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "查询父级id异常" + err.Error()
- return
- }
- var ids []*string
- if pid != nil && *pid != 0 {
- ids, err = company.GetGroupIdsByParentId(*pid)
- if err != nil {
- fmt.Println(err.Error())
- }
- } else {
- ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
- if err != nil {
- fmt.Println(err.Error())
- }
- }
- var idSlice []string
- var sid string
- for _, id := range ids {
- idSlice = append(idSlice, *id)
- }
- //加入父级groupId
- if *pid > 0 {
- idSlice = append(idSlice, strconv.Itoa(*pid))
- } else {
- idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
- }
- sid = strings.Join(idSlice, ",")
- if len(sid) > 0 {
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
- //pars = append(pars, sysUser.GroupId)
- }
- permissionCondition += ` AND b.group_id IN (` + sid + `) `
- } else {
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
- //pars = append(pars, sysUser.GroupId)
- }
- permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
- }
- }
- }
- } else {
- ////如果没有筛选了流失客户状态
- if sysUser.Authority <= 0 {
- condition += ` AND b.seller_id=? `
- pars = append(pars, sysUser.AdminId)
- permissionCondition += ` AND b.seller_id=? `
- permissionPars = append(permissionPars, sysUser.AdminId)
- } else {
- if sysUser.Authority == 1 {
- condition += ` AND b.department_id=?`
- pars = append(pars, sysUser.DepartmentId)
- permissionCondition += ` AND b.department_id=? `
- permissionPars = append(permissionPars, sysUser.DepartmentId)
- }
- if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND b.group_id=? `
- pars = append(pars, sysUser.GroupId)
- }
- permissionCondition += ` AND b.group_id=? `
- permissionPars = append(permissionPars, sysUser.GroupId)
- }
- if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
- pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "查询父级id异常" + err.Error()
- return
- }
- var ids []*string
- if pid != nil && *pid != 0 {
- ids, err = company.GetGroupIdsByParentId(*pid)
- if err != nil {
- fmt.Println(err.Error())
- }
- } else {
- ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
- if err != nil {
- fmt.Println(err.Error())
- }
- }
- var idSlice []string
- var sid string
- for _, id := range ids {
- idSlice = append(idSlice, *id)
- }
- //加入父级groupId
- if *pid > 0 {
- idSlice = append(idSlice, strconv.Itoa(*pid))
- } else {
- idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
- }
- sid = strings.Join(idSlice, ",")
- if len(sid) > 0 {
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
- //pars = append(pars, sysUser.GroupId)
- }
- permissionCondition += ` AND b.group_id IN (` + sid + `) `
- } else {
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
- //pars = append(pars, sysUser.GroupId)
- }
- permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
- }
- }
- if sysUser.Authority == 4 {
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND b.group_id =? `
- pars = append(pars, sysUser.GroupId)
- }
- permissionCondition += ` AND b.group_id=? `
- permissionPars = append(permissionPars, sysUser.GroupId)
- }
- }
- }
- }
- }
- }
- //状态控制
- if status != "" && status != "全部" && status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND b.status=? `
- pars = append(pars, status)
- }
- dir, err := os.Executable()
- exPath := filepath.Dir(dir)
- downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- xlsxFile := xlsx.NewFile()
- if err != nil {
- br.Msg = "生成文件失败"
- br.ErrMsg = "生成文件失败"
- return
- }
- style := xlsx.NewStyle()
- alignment := xlsx.Alignment{
- Horizontal: "center",
- Vertical: "center",
- WrapText: true,
- }
- style.Alignment = alignment
- style.ApplyAlignment = true
- sheel, err := xlsxFile.AddSheet("客户数据")
- if err != nil {
- br.Msg = "新增Sheet失败"
- br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
- return
- }
- titleArr := []string{"客户名称", "客户地址", "客户类型", "所属行业", "所属销售", "客户状态", "服务期限", "到期天数", "创建时间", "权限详情"}
- titleLen := len(titleArr)
- titleRow := sheel.AddRow()
- remarkRow := sheel.AddRow() // 备注行
- // 填充空白至Z列
- emptyColNum := 0
- for i := 0; i < 26; i++ {
- remarkRow.AddCell().SetValue("")
- if i >= titleLen {
- emptyColNum += 1
- titleRow.AddCell().SetValue("")
- continue
- }
- titleRow.AddCell().SetValue(titleArr[i])
- }
- // AA列开始为品种权限
- ficcPermissions := make([]int, 0) // 用于后续判断试用暂停客户是否需要暂停这部分权限
- raiPermissions := make([]int, 0)
- permissions, e := models.GetChartPermissionList()
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取品种数据失败,Err:" + err.Error()
- return
- }
- raiArr := []string{"医药", "消费", "科技", "智造"}
- for _, p := range permissions {
- if p.ProductId == 1 {
- ficcPermissions = append(ficcPermissions, p.ChartPermissionId)
- }
- if p.ProductId == 2 {
- raiPermissions = append(raiPermissions, p.ChartPermissionId)
- }
- if utils.InArrayByStr(raiArr, p.PermissionName) {
- titleRow.AddCell().SetValue(p.Remark)
- continue
- }
- titleRow.AddCell().SetValue(p.PermissionName)
- }
- // 第二行, 在品种权限开始列加一行标红备注
- styleRed := xlsx.NewStyle()
- styleRed.Font.Color = "ff0000"
- remarkCell := remarkRow.AddCell()
- remarkCell.SetStyle(styleRed)
- remarkCell.SetString(`第一位数字表示是否已购买该品种,1表示已购,0表示未购;第二位数字表示是否有阅读权限,1表示有权限,0表示没有`)
- list, err := company.GetCompanyListExport(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- companyIds := make([]int, 0)
- for _, c := range list {
- companyIds = append(companyIds, c.CompanyId)
- }
- // 获取客户对应的阅读和合同权限集合
- contractPermissionMap := make(map[int][]int)
- contractPermissions, e := company.GetContractPermissionIdsByCompanyIds(companyIds)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取已购权限失败, Err: " + e.Error()
- return
- }
- for _, p := range contractPermissions {
- ids := make([]int, 0)
- if p.ChartPermissionIds != "" {
- idArr := strings.Split(p.ChartPermissionIds, ",")
- for _, i := range idArr {
- id, _ := strconv.Atoi(i)
- ids = append(ids, id)
- }
- }
- contractPermissionMap[p.CompanyId] = ids
- }
- reportPermissionMap := make(map[int][]int)
- reportPermissions, e := company.GetReportPermissionIdsByCompanyIds(companyIds)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取阅读权限失败, Err: " + e.Error()
- return
- }
- for _, p := range reportPermissions {
- ids := make([]int, 0)
- if p.ChartPermissionIds != "" {
- idArr := strings.Split(p.ChartPermissionIds, ",")
- for _, i := range idArr {
- id, _ := strconv.Atoi(i)
- ids = append(ids, id)
- }
- }
- reportPermissionMap[p.CompanyId] = ids
- }
- cpMap := make(map[int][]*company.ExportCompanyProduct)
- permissionMap := make(map[string]string)
- for _, v := range list {
- cpList := make([]*company.ExportCompanyProduct, 1)
- if cps, ok := cpMap[v.CompanyId]; ok {
- cpList = cps
- } else {
- companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
- if err != nil {
- br.Msg = "导出失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- cpMap[v.CompanyId] = companyProduct
- cpList = companyProduct
- }
- var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, expireDay string
- isFiccSuspend := 0
- isRaiSuspend := 0
- for ck, cv := range cpList {
- companyName = cv.CompanyName
- if ck >= 1 {
- companyType = companyType + "/" + cv.ProductName
- status = status + "/" + cv.Status
- } else {
- companyType = cv.ProductName
- status = cv.Status
- }
- if cv.ProductId == 1 {
- industryName = "ficc:" + cv.IndustryName
- sellerName = "ficc:" + cv.SellerName
- startDateStr := cv.StartDate.Format("2006/01/02")
- endDateStr := cv.EndDate.Format("2006/01/02")
- timeLimt = "ficc:" + startDateStr + "~" + endDateStr
- createTime = "ficc:" + cv.CreateTime
- source = "ficc:" + cv.Source
- sub := cv.EndDate.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- expireDay = "ficc:" + fmt.Sprintf("%v", int(sub.Hours()/24))
- permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
- permissionStr = "ficc:"
- if newPermissionStr, ok := permissionMap[permissionKey]; ok {
- permissionStr += newPermissionStr
- } else {
- getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
- if err != nil {
- br.Msg = "导出失败"
- br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
- return
- }
- permissionMap[permissionKey] = getPermissionStr
- permissionStr += getPermissionStr
- }
- isFiccSuspend = cv.IsSuspend
- } else {
- industryName = industryName + "\n" + "权益:" + cv.IndustryName
- sellerName = sellerName + "\n" + "权益:" + cv.SellerName
- startDateStr := cv.StartDate.Format("2006/01/02")
- endDateStr := cv.EndDate.Format("2006/01/02")
- timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
- createTime = createTime + "\n" + "权益:" + cv.CreateTime
- source = source + "\n" + "权益:" + cv.Source
- sub := cv.EndDate.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- expireDay = "\n" + "权益:" + fmt.Sprintf("%v", int(sub.Hours()/24))
- permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
- if permissionStr != "" {
- permissionStr = permissionStr + "\n" + "权益:"
- } else {
- permissionStr = "权益:"
- }
- if newPermissionStr, ok := permissionMap[permissionKey]; ok {
- permissionStr += newPermissionStr
- } else {
- getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
- if err != nil {
- br.Msg = "导出失败"
- br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
- return
- }
- permissionMap[permissionKey] = getPermissionStr
- permissionStr += getPermissionStr
- }
- isRaiSuspend = cv.IsSuspend
- }
- }
- dataRow := sheel.AddRow()
- dataRow.SetHeight(20)
- dataRow.AddCell().SetString(companyName)
- dataRow.AddCell().SetString(v.Address)
- dataRow.AddCell().SetString(companyType)
- dataRow.AddCell().SetString(v.IndustryName)
- dataRow.AddCell().SetString(v.SellerName)
- dataRow.AddCell().SetString(v.Status)
- dataRow.AddCell().SetString(timeLimt)
- dataRow.AddCell().SetString(expireDay)
- dataRow.AddCell().SetString(v.CreatedTime)
- //dataRow.AddCell().SetString(v.Source)
- dataRow.AddCell().SetString(permissionStr)
- // 填充空白至Z列, AA列开始为权限
- for i := 0; i < emptyColNum; i++ {
- dataRow.AddCell().SetString("")
- }
- cpIds := contractPermissionMap[v.CompanyId]
- rpIds := reportPermissionMap[v.CompanyId]
- for _, p := range permissions {
- // 数字含义:11-表示已购且有阅读权限, 01-表示未购买但有阅读权限
- first := 0
- if utils.InArrayByInt(cpIds, p.ChartPermissionId) {
- first = 1
- }
- second := 0
- if utils.InArrayByInt(rpIds, p.ChartPermissionId) {
- second = 1
- // 如果客户是试用暂停, 即使有这部分权限, 也标记为0
- if isFiccSuspend == 1 && utils.InArrayByInt(ficcPermissions, p.ChartPermissionId) {
- second = 0
- }
- if isRaiSuspend == 1 && utils.InArrayByInt(raiPermissions, p.ChartPermissionId) {
- second = 0
- }
- }
- dataRow.AddCell().SetString(fmt.Sprintf("%d%d", first, second))
- }
- }
- err = xlsxFile.Save(downLoadnFilePath)
- if err != nil {
- br.Msg = "保存文件失败"
- br.ErrMsg = "保存文件失败"
- return
- }
- randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
- downloadFileName := "客户列表_" + randStr + ".xlsx"
- this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
- defer func() {
- os.Remove(downLoadnFilePath)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "导出成功"
- }
- //func (this *CompanyController) ExportOld() {
- // br := new(models.BaseResponse).Init()
- // defer func() {
- // this.Data["json"] = br
- // this.ServeJSON()
- // }()
- // sysUser := this.SysUser
- // if sysUser == nil {
- // br.Msg = "请登录"
- // br.ErrMsg = "请登录,SysUser Is Empty"
- // br.Ret = 408
- // return
- // }
- // roleTypeCode := sysUser.RoleTypeCode
- //
- // status := this.GetString("Status")
- // companyType := this.GetString("CompanyType")
- // industryId, _ := this.GetInt("IndustryId")
- // adminId := this.GetString("AdminId")
- //
- // chartPermissionIds := this.GetString("ChartPermissionIds")
- // startDate := this.GetString("StartDate")
- // endDate := this.GetString("EndDate")
- // createStartDate := this.GetString("CreateStartDate")
- // createEndDate := this.GetString("CreateEndDate")
- // keyWord := this.GetString("KeyWord")
- // keyWord = strings.Trim(keyWord, " ")
- //
- // resp := new(company.CompanyListResp)
- // statusItems := make([]*company.CompanyStatus, 0)
- // var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}
- //
- // var condition string
- // var pars []interface{}
- //
- // var lossCondition string
- // var lossPars []interface{}
- //
- // var permissionCondition string
- // var permissionPars []interface{}
- //
- // if status != "" && status != "全部" {
- // condition += ` AND b.status=? `
- // pars = append(pars, status)
- //
- // //permissionCondition += ` AND b.status=? `
- // //permissionPars = append(permissionPars, status)
- // }
- // if companyType != "" {
- // condition += ` AND b.product_name=? `
- // pars = append(pars, companyType)
- //
- // lossCondition += ` AND b.product_name=? `
- // lossPars = append(lossPars, companyType)
- //
- // permissionCondition += ` AND b.product_name=? `
- // permissionPars = append(permissionPars, companyType)
- // }
- //
- // if industryId > 0 {
- // condition += ` AND b.industry_id=? `
- // pars = append(pars, industryId)
- //
- // lossCondition += ` AND b.industry_id=? `
- // lossPars = append(lossPars, industryId)
- //
- // permissionCondition += ` AND b.industry_id=? `
- // permissionPars = append(permissionPars, industryId)
- // }
- //
- // if adminId != "" {
- // condition += ` AND b.seller_id IN (` + adminId + `) `
- //
- // lossCondition += ` AND b.seller_id IN (` + adminId + `) `
- //
- // permissionCondition += ` AND b.seller_id IN (` + adminId + `) `
- // }
- //
- // if startDate != "" {
- // condition += ` AND b.start_date>=? `
- // pars = append(pars, startDate)
- //
- // lossCondition += ` AND b.start_date>=? `
- // lossPars = append(lossPars, startDate)
- //
- // permissionCondition += ` AND b.start_date>=? `
- // permissionPars = append(permissionPars, startDate)
- // }
- //
- // if endDate != "" {
- // condition += ` AND b.end_date<=? `
- // pars = append(pars, endDate)
- //
- // lossCondition += ` AND b.end_date<=? `
- // lossPars = append(lossPars, endDate)
- //
- // permissionCondition += ` AND b.end_date<=? `
- // permissionPars = append(permissionPars, endDate)
- // }
- //
- // if createStartDate != "" {
- // condition += ` AND a.created_time>=? `
- // pars = append(pars, createStartDate)
- //
- // lossCondition += ` AND a.created_time>=? `
- // lossPars = append(lossPars, createStartDate)
- //
- // permissionCondition += ` AND a.created_time>=? `
- // permissionPars = append(permissionPars, createStartDate)
- // }
- //
- // if createEndDate != "" {
- // condition += ` AND a.created_time<=? `
- // pars = append(pars, createEndDate)
- //
- // lossCondition += ` AND a.created_time<=? `
- // lossPars = append(lossPars, createEndDate)
- //
- // permissionCondition += ` AND a.created_time<=? `
- // permissionPars = append(permissionPars, createEndDate)
- // }
- //
- // if keyWord != "" {
- // companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
- // if err != nil {
- // return
- // }
- // if companyIdStr != "" {
- // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
- // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
- //
- // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
- // } else {
- // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
- // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
- //
- // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
- // }
- // }
- //
- // if chartPermissionIds != "" && chartPermissionIds != "1" {
- // //chartPermissionArr := strings.Split(chartPermissionIds, ",")
- // //chartPermissionCount := len(chartPermissionArr)
- // companyIdStr, err := company.GetCompanyListCompanyIdByPermissionIdStr(chartPermissionIds)
- // if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
- // return
- // }
- // //var companyIdArr []string
- // //for _, v := range companyIdList {
- // // companyIdArr = append(companyIdArr, strconv.Itoa(v.CompanyId))
- // //}
- // //companyIdStr := strings.Join(companyIdArr, ",")
- //
- // if companyIdStr != "" {
- // condition += ` AND a.company_id IN (` + companyIdStr + `) `
- // lossCondition += ` AND a.company_id IN (` + companyIdStr + `) `
- // permissionCondition += ` AND a.company_id IN (` + companyIdStr + `) `
- // } else {
- // for _, v := range statusArr {
- // statusCount := new(company.CompanyStatus)
- // if v == "全部" {
- // statusCount.Status = "全部"
- // statusCount.Count = 0
- // } else {
- // statusCount.Status = v
- // statusCount.Count = 0
- // }
- // statusItems = append(statusItems, statusCount)
- // }
- // items := make([]*company.CompanyListItem, 0)
- // resp.List = items
- // resp.StatusCount = statusItems
- // br.Msg = "获取成功"
- // br.Ret = 200
- // br.Data = resp
- // return
- // }
- // }
- //
- // //权限控制
- // {
- // if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
- // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
- // condition += ` AND b.product_id=? `
- // pars = append(pars, 1)
- //
- // permissionCondition += ` AND b.product_id=? `
- // permissionPars = append(permissionPars, 1)
- // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
- // condition += ` AND b.product_id=? `
- // pars = append(pars, 2)
- //
- // permissionCondition += ` AND b.product_id=? `
- // permissionPars = append(permissionPars, 2)
- // } else {
- // if sysUser.Authority <= 0 {
- // if status != utils.COMPANY_STATUS_LOSE {
- // condition += ` AND b.seller_id=? `
- // pars = append(pars, sysUser.AdminId)
- // }
- //
- // permissionCondition += ` AND b.seller_id=? `
- // permissionPars = append(permissionPars, sysUser.AdminId)
- // } else {
- // if sysUser.Authority == 1 {
- // if status != utils.COMPANY_STATUS_LOSE {
- // condition += ` AND b.department_id=? `
- // pars = append(pars, sysUser.DepartmentId)
- // }
- // permissionCondition += ` AND b.department_id=? `
- // permissionPars = append(permissionPars, sysUser.DepartmentId)
- // }
- //
- // if sysUser.Authority == 2 {
- // if status != utils.COMPANY_STATUS_LOSE {
- // condition += ` AND b.group_id=? `
- // pars = append(pars, sysUser.GroupId)
- // }
- // permissionCondition += ` AND b.group_id=? `
- // permissionPars = append(permissionPars, sysUser.GroupId)
- // }
- // }
- // }
- // }
- // }
- //
- // dir, err := os.Executable()
- // exPath := filepath.Dir(dir)
- // downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- // xlsxFile := xlsx.NewFile()
- // if err != nil {
- // br.Msg = "生成文件失败"
- // br.ErrMsg = "生成文件失败"
- // return
- // }
- // style := xlsx.NewStyle()
- // alignment := xlsx.Alignment{
- // Horizontal: "center",
- // Vertical: "center",
- // WrapText: true,
- // }
- //
- // style.Alignment = alignment
- // style.ApplyAlignment = true
- //
- // sheel, err := xlsxFile.AddSheet("客户数据")
- // if err != nil {
- // br.Msg = "新增Sheet失败"
- // br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
- // return
- // }
- // titleRow := sheel.AddRow()
- // titleRow.AddCell().SetValue("客户名称")
- // titleRow.AddCell().SetValue("客户类型")
- // titleRow.AddCell().SetValue("所属行业")
- // titleRow.AddCell().SetValue("所属销售")
- // titleRow.AddCell().SetValue("客户状态")
- // titleRow.AddCell().SetValue("服务期限")
- // titleRow.AddCell().SetValue("到期天数")
- // titleRow.AddCell().SetValue("创建时间")
- // titleRow.AddCell().SetValue("客户来源")
- // titleRow.AddCell().SetValue("阅读权限")
- //
- // list, err := company.GetCompanyListExport(condition, pars)
- // if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取数据失败,Err:" + err.Error()
- // return
- // }
- // cpMap := make(map[int][]*company.ExportCompanyProduct)
- // permissionMap := make(map[string]string)
- // for _, v := range list {
- // cpList := make([]*company.ExportCompanyProduct, 1)
- // if cps, ok := cpMap[v.CompanyId]; ok {
- // cpList = cps
- // } else {
- // companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
- // if err != nil {
- // br.Msg = "导出失败"
- // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- // return
- // }
- // cpMap[v.CompanyId] = companyProduct
- // cpList = companyProduct
- // }
- // var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, expireDay string
- //
- // for ck, cv := range cpList {
- // companyName = cv.CompanyName
- // if ck >= 1 {
- // companyType = companyType + "/" + cv.ProductName
- // status = status + "/" + cv.Status
- // } else {
- // companyType = cv.ProductName
- // status = cv.Status
- // }
- // if cv.ProductId == 1 {
- // industryName = "ficc:" + cv.IndustryName
- // sellerName = "ficc:" + cv.SellerName
- // startDateStr := cv.StartDate.Format("2006/01/02")
- // endDateStr := cv.EndDate.Format("2006/01/02")
- // timeLimt = "ficc:" + startDateStr + "~" + endDateStr
- // createTime = "ficc:" + cv.CreateTime
- // source = "ficc:" + cv.Source
- // sub := cv.EndDate.Sub(time.Now())
- // if sub < 0 {
- // sub = 0
- // }
- // expireDay = "ficc:" + fmt.Sprintf("%v", int(sub.Hours()/24))
- //
- // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
- //
- // permissionStr = "ficc:"
- // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
- // permissionStr += newPermissionStr
- // } else {
- // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
- // if err != nil {
- // br.Msg = "导出失败"
- // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
- // return
- // }
- // permissionMap[permissionKey] = getPermissionStr
- // permissionStr += getPermissionStr
- // }
- // } else {
- // industryName = industryName + "\n" + "权益:" + cv.IndustryName
- // sellerName = sellerName + "\n" + "权益:" + cv.SellerName
- // startDateStr := cv.StartDate.Format("2006/01/02")
- // endDateStr := cv.EndDate.Format("2006/01/02")
- //
- // timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
- // createTime = createTime + "\n" + "权益:" + cv.CreateTime
- // source = source + "\n" + "权益:" + cv.Source
- //
- // sub := cv.EndDate.Sub(time.Now())
- // if sub < 0 {
- // sub = 0
- // }
- // expireDay = "\n" + "权益:" + fmt.Sprintf("%v", int(sub.Hours()/24))
- //
- // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
- // if permissionStr != "" {
- // permissionStr = permissionStr + "\n" + "权益:"
- // } else {
- // permissionStr = "权益:"
- // }
- // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
- // permissionStr += newPermissionStr
- // } else {
- // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
- // if err != nil {
- // br.Msg = "导出失败"
- // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
- // return
- // }
- // permissionMap[permissionKey] = getPermissionStr
- // permissionStr += getPermissionStr
- // }
- // }
- // }
- //
- // dataRow := sheel.AddRow()
- // dataRow.SetHeight(20)
- // dataRow.AddCell().SetString(companyName)
- // dataRow.AddCell().SetString(companyType)
- // dataRow.AddCell().SetString(v.IndustryName)
- // dataRow.AddCell().SetString(v.SellerName)
- // dataRow.AddCell().SetString(v.Status)
- // dataRow.AddCell().SetString(timeLimt)
- // dataRow.AddCell().SetString(expireDay)
- // dataRow.AddCell().SetString(v.CreatedTime)
- // dataRow.AddCell().SetString(v.Source)
- // dataRow.AddCell().SetString(permissionStr)
- // }
- // err = xlsxFile.Save(downLoadnFilePath)
- // if err != nil {
- // br.Msg = "保存文件失败"
- // br.ErrMsg = "保存文件失败"
- // return
- // }
- // randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
- // downloadFileName := "客户列表_" + randStr + ".xlsx"
- // this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
- // defer func() {
- // os.Remove(downLoadnFilePath)
- // }()
- // br.Ret = 200
- // br.Success = true
- // br.Msg = "导出成功"
- //}
- // @Title 导出
- // @Description 导出接口
- // @Param Status query string true "状态:”试用','永续','冻结','流失','正式'"
- // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
- // @Param IndustryId query int true "行业id,0为全部"
- // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
- // @Param ChartPermissionIds query string false "阅读权限品种ID,多个用英文逗号分开,空字符串为全部"
- // @Param ContractPermissionIds query string false "已购品种ID,多个用英文逗号分开,空字符串为全部"
- // @Param StartDate query string true "开始时间"
- // @Param EndDate query string true "结束时间"
- // @Param KeyWord query string true "搜索关键词"
- // @Param Address query string true "地址 , 多个用英文逗号分开 "
- // @Param Province query string true "省 , 多个用英文逗号分开 "
- // @Param City query string true "市 , 多个用英文逗号分开 "
- // @Param PackageType query int true "套餐类型,0:无,1:大套餐,2:小套餐"
- // @Success Ret=200 移动成功
- // @router /user/export [get]
- func (this *CompanyController) CompanyUserExport() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- roleTypeCode := sysUser.RoleTypeCode
- status := this.GetString("Status")
- companyType := this.GetString("CompanyType")
- industryId, _ := this.GetInt("IndustryId")
- adminId := this.GetString("AdminId")
- chartPermissionIds := this.GetString("ChartPermissionIds")
- contractPermissionIds := this.GetString("ContractPermissionIds")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- createStartDate := this.GetString("CreateStartDate")
- createEndDate := this.GetString("CreateEndDate")
- keyWord := this.GetString("KeyWord")
- address := this.GetString("Address")
- province := this.GetString("Province")
- city := this.GetString("City")
- // 套餐类型
- packageType, _ := this.GetInt("PackageType")
- var condition string
- var pars []interface{}
- if status != "" && status != "全部" {
- condition += ` AND b.status=? `
- pars = append(pars, status)
- }
- if companyType != "" {
- condition += ` AND b.product_name=? `
- pars = append(pars, companyType)
- }
- if industryId > 0 {
- condition += ` AND b.industry_id=? `
- pars = append(pars, industryId)
- }
- if adminId != "" {
- condition += ` AND b.seller_id IN (` + adminId + `) `
- }
- if startDate != "" {
- condition += ` AND b.start_date>=? `
- pars = append(pars, startDate)
- }
- if endDate != "" {
- condition += ` AND b.end_date<=? `
- pars = append(pars, endDate)
- }
- if createStartDate != "" {
- condition += ` AND a.created_time>=? `
- pars = append(pars, createStartDate)
- }
- if createEndDate != "" {
- condition += ` AND a.created_time<=? `
- pars = append(pars, createEndDate)
- }
- if keyWord != "" {
- condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR c.mobile LIKE '%` + keyWord + `%' OR c.email LIKE '%` + keyWord + `%') `
- }
- // 阅读权限/已购品种筛选
- cond, emp, e := services.FilterReadAndContractAuth(chartPermissionIds, contractPermissionIds, condition)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "FilterReadAndContractAuth err: " + e.Error()
- return
- }
- if emp {
- condition += ` AND 1 = 2`
- } else {
- condition = cond
- }
- if address != "" {
- var addressSql string
- slice := strings.Split(address, ",")
- for _, v := range slice {
- addressSql += "'" + v + "'" + ","
- }
- addressSql = strings.TrimRight(addressSql, ",")
- condition += ` AND a.address IN (` + addressSql + `) `
- }
- if province != "" {
- var provinceSql string
- slice := strings.Split(province, ",")
- for _, v := range slice {
- provinceSql += "'" + v + "'" + ","
- }
- provinceSql = strings.TrimRight(provinceSql, ",")
- condition += ` AND a.province IN (` + provinceSql + `) `
- }
- if city != "" {
- var citySql string
- slice := strings.Split(city, ",")
- for _, v := range slice {
- citySql += "'" + v + "'" + ","
- }
- citySql = strings.TrimRight(citySql, ",")
- condition += ` AND a.city IN (` + citySql + `) `
- }
- //套餐类型
- if packageType > 0 {
- condition += ` AND b.package_type=? `
- pars = append(pars, packageType)
- }
- //权限控制
- {
- if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
- if status != utils.COMPANY_STATUS_LOSE && status != utils.COMPANY_STATUS_FOREVER {
- condition += ` AND b.seller_id=? `
- pars = append(pars, sysUser.AdminId)
- }
- }
- if sysUser.Authority == 1 {
- condition += ` AND b.department_id=? `
- pars = append(pars, sysUser.DepartmentId)
- }
- if sysUser.Authority == 2 {
- condition += ` AND b.group_id=? `
- pars = append(pars, sysUser.GroupId)
- }
- }
- var statusCond string
- var statusPars []interface{}
- // 根据当前用户角色
- productId := services.GetProductId(roleTypeCode)
- if productId > 0 {
- condition += ` AND b.product_id = ? `
- pars = append(pars, productId)
- statusCond += ` AND b.product_id = ? `
- statusPars = append(statusPars, productId)
- }
- companyIds, err := company.GetExportCompanyIds(condition, pars)
- if err != nil {
- br.Msg = "导出失败"
- br.ErrMsg = "导出失败,Err:" + err.Error()
- return
- }
- dir, err := os.Executable()
- exPath := filepath.Dir(dir)
- downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- xlsxFile := xlsx.NewFile()
- if err != nil {
- br.Msg = "生成文件失败"
- br.ErrMsg = "生成文件失败"
- return
- }
- style := xlsx.NewStyle()
- alignment := xlsx.Alignment{
- Horizontal: "center",
- Vertical: "center",
- WrapText: true,
- }
- style.Alignment = alignment
- style.ApplyAlignment = true
- sheel, err := xlsxFile.AddSheet("联系人数据")
- if err != nil {
- br.Msg = "新增Sheet失败"
- br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
- return
- }
- sheel.SetColWidth(7, 7, 10)
- sheel.SetColWidth(8, 10, 16)
- sheel.SetColWidth(9, 11, 20)
- sheel.SetColWidth(12, 12, 35)
- sheel.SetColWidth(13, 13, 15)
- sheel.SetColWidth(14, 14, 80)
- titleRow := sheel.AddRow()
- titleRow.AddCell().SetValue("联系人")
- titleRow.AddCell().SetValue("是否关注公众号")
- titleRow.AddCell().SetValue("手机号")
- titleRow.AddCell().SetValue("邮箱")
- //titleRow.AddCell().SetValue("职位")
- titleRow.AddCell().SetValue("是否决策人")
- //titleRow.AddCell().SetValue("客户部门")
- titleRow.AddCell().SetValue("客户名称")
- titleRow.AddCell().SetValue("客户状态")
- //titleRow.AddCell().SetValue("社会信用码")
- //titleRow.AddCell().SetValue("所属区域")
- //titleRow.AddCell().SetValue("客户类型")
- //industryCell := titleRow.AddCell()
- //industryCell.SetStyle(style)
- //industryCell.Value = "所属行业"
- //
- //sellerCell := titleRow.AddCell()
- //sellerCell.SetStyle(style)
- //sellerCell.Value = "所属销售"
- //
- //statusCell := titleRow.AddCell()
- //statusCell.SetStyle(style)
- //statusCell.Value = "客户状态"
- //
- //timeLimtCell := titleRow.AddCell()
- //timeLimtCell.SetStyle(style)
- //timeLimtCell.Value = "服务期限"
- //
- //createTimeCell := titleRow.AddCell()
- //createTimeCell.SetStyle(style)
- //createTimeCell.Value = "创建时间"
- //
- //sourceCell := titleRow.AddCell()
- //sourceCell.SetStyle(style)
- //sourceCell.Value = "客户来源"
- //permissionStyle := xlsx.NewStyle()
- //permissionAlignment := xlsx.Alignment{
- // Horizontal: "center",
- // Vertical: "center",
- // WrapText: true,
- //}
- //
- //permissionStyle.Alignment = permissionAlignment
- //permissionStyle.ApplyAlignment = true
- //permissionCell := titleRow.AddCell()
- //permissionCell.SetStyle(permissionStyle)
- //permissionCell.Value = "阅读权限"
- users := make([]*company.ExportUser, 0)
- if companyIds != "" {
- companyIds = strings.Trim(companyIds, ",")
- if productId > 0 {
- users, err = company.GetExportUserByProductId(companyIds, productId)
- if err != nil {
- br.Msg = "导出失败"
- br.ErrMsg = "获取联系人信息失败,Err:" + err.Error()
- return
- }
- } else {
- users, err = company.GetExportUser(companyIds)
- if err != nil {
- br.Msg = "导出失败"
- br.ErrMsg = "获取联系人信息失败,Err:" + err.Error()
- return
- }
- }
- // 获取客户状态
- companyIntIds := make([]int, 0)
- companyIdArr := strings.Split(companyIds, ",")
- for _, c := range companyIdArr {
- id, e := strconv.Atoi(c)
- if e != nil {
- br.Msg = "导出失败"
- br.ErrMsg = "客户ID有误"
- return
- }
- companyIntIds = append(companyIntIds, id)
- }
- if len(companyIntIds) > 0 {
- statusCond += fmt.Sprintf(` AND a.company_id IN (%s) `, utils.GetOrmInReplace(len(companyIntIds)))
- statusPars = append(statusPars, companyIntIds)
- }
- statusMap := make(map[int]string)
- nameMap := make(map[int]string)
- companyStatusList, e := company.GetExportUserCompanyStatus(statusCond, statusPars)
- if e != nil {
- br.Msg = "导出失败"
- br.ErrMsg = "获取客户状态失败, Err: " + e.Error()
- return
- }
- for _, s := range companyStatusList {
- statusMap[s.CompanyId] = s.CompanyStatus
- nameMap[s.CompanyId] = s.CompanyName
- }
- //cpMap := make(map[int][]*company.ExportCompanyProduct)
- //permissionMap := make(map[string]string)
- for _, v := range users {
- dataRow := sheel.AddRow()
- dataRow.SetHeight(20)
- dataRow.AddCell().SetString(v.RealName)
- if v.IsSubscribe == 1 {
- dataRow.AddCell().SetString("是") // 是否关注公众号
- } else {
- dataRow.AddCell().SetString("")
- }
- dataRow.AddCell().SetString(v.Mobile)
- dataRow.AddCell().SetString(v.Email)
- //dataRow.AddCell().SetString(v.Position)
- if v.IsMaker == 1 {
- dataRow.AddCell().SetString("是")
- } else {
- dataRow.AddCell().SetString("否")
- }
- //dataRow.AddCell().SetString(v.DepartmentName)
- //cpList := make([]*company.ExportCompanyProduct, 1)
- //if cps, ok := cpMap[v.CompanyId]; ok {
- // cpList = cps
- //} else {
- // companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
- // if err != nil {
- // br.Msg = "导出失败"
- // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- // return
- // }
- // cpMap[v.CompanyId] = companyProduct
- // cpList = companyProduct
- //}
- //productList, err := company.GetExportCompanyProduct(v.CompanyId)
- //if err!=nil {
- // fmt.Println("导出失败,Err:"+err.Error())
- // return
- //}
- //var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, creditCode, regionType string
- //for ck, cv := range cpList {
- // companyName = cv.CompanyName
- // creditCode = cv.CreditCode
- // regionType = cv.RegionType
- // if ck >= 1 {
- // companyType = companyType + "/" + cv.ProductName
- // status = status + "/" + cv.Status
- // } else {
- // companyType = cv.ProductName
- // status = cv.Status
- // }
- // if cv.ProductId == 1 {
- // industryName = "ficc:" + cv.IndustryName
- // sellerName = "ficc:" + cv.SellerName
- // startDateStr := cv.StartDate.Format("2006/01/02")
- // endDateStr := cv.EndDate.Format("2006/01/02")
- // if startDateStr != "0001/01/01" {
- // timeLimt = "ficc:" + startDateStr + "~" + endDateStr
- // } else {
- // timeLimt = ""
- // }
- // createTime = "ficc:" + cv.CreateTime
- // source = "ficc:" + cv.Source
- // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
- //
- // permissionStr = "ficc:"
- // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
- // permissionStr += newPermissionStr
- // } else {
- // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
- // if err != nil {
- // br.Msg = "导出失败"
- // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
- // return
- // }
- // permissionMap[permissionKey] = getPermissionStr
- // permissionStr += getPermissionStr
- // }
- // if cv.Status == utils.COMPANY_STATUS_LOSE {
- // permissionStr = ""
- // }
- // } else {
- // industryName = industryName + "\n" + "权益:" + cv.IndustryName
- // sellerName = sellerName + "\n" + "权益:" + cv.SellerName
- // startDateStr := cv.StartDate.Format("2006/01/02")
- // endDateStr := cv.EndDate.Format("2006/01/02")
- //
- // if startDateStr != "0001/01/01" {
- // timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
- // } else {
- // timeLimt = timeLimt + ""
- // }
- // createTime = createTime + "\n" + "权益:" + cv.CreateTime
- // source = source + "\n" + "权益:" + cv.Source
- //
- // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
- // if permissionStr != "" {
- // permissionStr = permissionStr + "\n" + "权益:"
- // } else {
- // permissionStr = "权益:"
- // }
- // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
- // permissionStr += newPermissionStr
- // } else {
- // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
- // if err != nil {
- // br.Msg = "导出失败"
- // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
- // return
- // }
- // permissionMap[permissionKey] = getPermissionStr
- // permissionStr += getPermissionStr
- // }
- // if cv.Status == utils.COMPANY_STATUS_LOSE {
- // permissionStr = permissionStr + ""
- // }
- // }
- //}
- // 2023-0420这是谁写的循环查,顺手优化了一下,手动狗头-_-~
- //companyInfo, err := company.GetCompanyById(v.CompanyId)
- //if err != nil {
- // br.Msg = "导出失败"
- // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- // return
- //}
- dataRow.AddCell().SetString(nameMap[v.CompanyId])
- dataRow.AddCell().SetString(statusMap[v.CompanyId]) // 客户状态
- //dataRow.AddCell().SetString(creditCode)
- //dataRow.AddCell().SetString(regionType)
- //
- //dataRow.AddCell().SetString(companyType)
- //industryValueCell := dataRow.AddCell()
- //industryValueCell.SetStyle(style)
- //industryValueCell.SetString(industryName)
- //
- //sellerValueCell := dataRow.AddCell()
- //sellerValueCell.SetStyle(style)
- //sellerValueCell.SetString(sellerName)
- //
- //statusValueCell := dataRow.AddCell()
- //statusValueCell.SetStyle(style)
- //statusValueCell.SetValue(status)
- //
- //timeLimitValueCell := dataRow.AddCell()
- //timeLimitValueCell.SetStyle(style)
- //timeLimitValueCell.SetValue(timeLimt)
- //
- //createTimeValueCell := dataRow.AddCell()
- //createTimeValueCell.SetStyle(style)
- //createTimeValueCell.SetValue(createTime)
- //
- //sourceValueCell := dataRow.AddCell()
- //sourceValueCell.SetStyle(style)
- //sourceValueCell.SetValue(source)
- //
- //permissionStrValueCell := dataRow.AddCell()
- //permissionStrValueCell.SetStyle(style)
- //permissionStrValueCell.SetValue(permissionStr)
- }
- }
- err = xlsxFile.Save(downLoadnFilePath)
- if err != nil {
- br.Msg = "保存文件失败"
- br.ErrMsg = "保存文件失败"
- return
- }
- randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
- downloadFileName := "联系人列表" + randStr + ".xlsx"
- this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
- defer func() {
- os.Remove(downLoadnFilePath)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "导出成功"
- }
- //func (this *CompanyController) CompanyUserExportOld() {
- // br := new(models.BaseResponse).Init()
- // defer func() {
- // this.Data["json"] = br
- // this.ServeJSON()
- // }()
- // sysUser := this.SysUser
- // if sysUser == nil {
- // br.Msg = "请登录"
- // br.ErrMsg = "请登录,SysUser Is Empty"
- // br.Ret = 408
- // return
- // }
- // roleTypeCode := sysUser.RoleTypeCode
- // status := this.GetString("Status")
- // companyType := this.GetString("CompanyType")
- // industryId, _ := this.GetInt("IndustryId")
- // adminId := this.GetString("AdminId")
- //
- // chartPermissionIds := this.GetString("ChartPermissionIds")
- // startDate := this.GetString("StartDate")
- // endDate := this.GetString("EndDate")
- // keyWord := this.GetString("KeyWord")
- //
- // var condition string
- // var pars []interface{}
- //
- // if status != "" && status != "全部" {
- // condition += ` AND b.status=? `
- // pars = append(pars, status)
- // }
- // if companyType != "" {
- // condition += ` AND b.product_name=? `
- // pars = append(pars, companyType)
- // }
- //
- // if industryId > 0 {
- // condition += ` AND b.industry_id=? `
- // pars = append(pars, industryId)
- // }
- //
- // if adminId != "" {
- // condition += ` AND b.seller_id IN (` + adminId + `) `
- // }
- //
- // if startDate != "" {
- // condition += ` AND b.start_date>=? `
- // pars = append(pars, startDate)
- // }
- //
- // if endDate != "" {
- // condition += ` AND b.end_date>=? `
- // pars = append(pars, endDate)
- // }
- //
- // if keyWord != "" {
- // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR c.mobile LIKE '%` + keyWord + `%' OR c.email LIKE '%` + keyWord + `%') `
- // }
- //
- // if chartPermissionIds != "" {
- // companyIdStr, err := company.GetCompanyIdStr(chartPermissionIds)
- // if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
- // return
- // }
- // if companyIdStr != "" {
- // condition += ` AND a.company_id IN (` + companyIdStr + `) `
- // }
- // }
- //
- // //权限控制
- // {
- // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
- // roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
- // if status != utils.COMPANY_STATUS_LOSE && status != utils.COMPANY_STATUS_FOREVER {
- // condition += ` AND b.seller_id=? `
- // pars = append(pars, sysUser.AdminId)
- // }
- // }
- // if sysUser.Authority == 1 {
- // condition += ` AND b.department_id=? `
- // pars = append(pars, sysUser.DepartmentId)
- // }
- //
- // if sysUser.Authority == 2 {
- // condition += ` AND b.group_id=? `
- // pars = append(pars, sysUser.GroupId)
- // }
- // }
- // companyIds, err := company.GetExportCompanyIds(condition, pars)
- // if err != nil {
- // br.Msg = "导出失败"
- // br.ErrMsg = "导出失败,Err:" + err.Error()
- // return
- // }
- //
- // dir, err := os.Executable()
- // exPath := filepath.Dir(dir)
- //
- // downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- // xlsxFile := xlsx.NewFile()
- // if err != nil {
- // br.Msg = "生成文件失败"
- // br.ErrMsg = "生成文件失败"
- // return
- // }
- // style := xlsx.NewStyle()
- // alignment := xlsx.Alignment{
- // Horizontal: "center",
- // Vertical: "center",
- // WrapText: true,
- // }
- //
- // style.Alignment = alignment
- // style.ApplyAlignment = true
- //
- // sheel, err := xlsxFile.AddSheet("联系人数据")
- // if err != nil {
- // br.Msg = "新增Sheet失败"
- // br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
- // return
- // }
- //
- // sheel.SetColWidth(7, 7, 10)
- // sheel.SetColWidth(8, 10, 16)
- // sheel.SetColWidth(9, 11, 20)
- // sheel.SetColWidth(12, 12, 35)
- // sheel.SetColWidth(13, 13, 15)
- // sheel.SetColWidth(14, 14, 80)
- // titleRow := sheel.AddRow()
- // titleRow.AddCell().SetValue("联系人")
- // titleRow.AddCell().SetValue("手机号")
- // titleRow.AddCell().SetValue("邮箱")
- // titleRow.AddCell().SetValue("职位")
- // titleRow.AddCell().SetValue("是否决策人")
- // titleRow.AddCell().SetValue("客户部门")
- // titleRow.AddCell().SetValue("客户名称")
- // titleRow.AddCell().SetValue("社会信用码")
- // titleRow.AddCell().SetValue("所属区域")
- // titleRow.AddCell().SetValue("客户类型")
- //
- // industryCell := titleRow.AddCell()
- // industryCell.SetStyle(style)
- // industryCell.Value = "所属行业"
- //
- // sellerCell := titleRow.AddCell()
- // sellerCell.SetStyle(style)
- // sellerCell.Value = "所属销售"
- //
- // statusCell := titleRow.AddCell()
- // statusCell.SetStyle(style)
- // statusCell.Value = "客户状态"
- //
- // timeLimtCell := titleRow.AddCell()
- // timeLimtCell.SetStyle(style)
- // timeLimtCell.Value = "服务期限"
- //
- // createTimeCell := titleRow.AddCell()
- // createTimeCell.SetStyle(style)
- // createTimeCell.Value = "创建时间"
- //
- // sourceCell := titleRow.AddCell()
- // sourceCell.SetStyle(style)
- // sourceCell.Value = "客户来源"
- //
- // permissionStyle := xlsx.NewStyle()
- // permissionAlignment := xlsx.Alignment{
- // Horizontal: "center",
- // Vertical: "center",
- // WrapText: true,
- // }
- //
- // permissionStyle.Alignment = permissionAlignment
- // permissionStyle.ApplyAlignment = true
- //
- // permissionCell := titleRow.AddCell()
- // permissionCell.SetStyle(permissionStyle)
- // permissionCell.Value = "阅读权限"
- //
- // if companyIds != "" {
- // companyIds = strings.Trim(companyIds, ",")
- // users, err := company.GetExportUser(companyIds)
- // if err != nil {
- // br.Msg = "导出失败"
- // br.ErrMsg = "获取联系人信息失败,Err:" + err.Error()
- // return
- // }
- // cpMap := make(map[int][]*company.ExportCompanyProduct)
- // permissionMap := make(map[string]string)
- // for _, v := range users {
- // dataRow := sheel.AddRow()
- // dataRow.SetHeight(20)
- // dataRow.AddCell().SetString(v.RealName)
- // dataRow.AddCell().SetString(v.Mobile)
- // dataRow.AddCell().SetString(v.Email)
- // dataRow.AddCell().SetString(v.Position)
- // if v.IsMaker == 1 {
- // dataRow.AddCell().SetString("是")
- // } else {
- // dataRow.AddCell().SetString("否")
- // }
- // dataRow.AddCell().SetString(v.DepartmentName)
- // cpList := make([]*company.ExportCompanyProduct, 1)
- // if cps, ok := cpMap[v.CompanyId]; ok {
- // cpList = cps
- // } else {
- // companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
- // if err != nil {
- // br.Msg = "导出失败"
- // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- // return
- // }
- // cpMap[v.CompanyId] = companyProduct
- // cpList = companyProduct
- // }
- // //productList, err := company.GetExportCompanyProduct(v.CompanyId)
- // //if err!=nil {
- // // fmt.Println("导出失败,Err:"+err.Error())
- // // return
- // //}
- // var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, creditCode, regionType string
- //
- // for ck, cv := range cpList {
- // companyName = cv.CompanyName
- // creditCode = cv.CreditCode
- // regionType = cv.RegionType
- // if ck >= 1 {
- // companyType = companyType + "/" + cv.ProductName
- // status = status + "/" + cv.Status
- // } else {
- // companyType = cv.ProductName
- // status = cv.Status
- // }
- // if cv.ProductId == 1 {
- // industryName = "ficc:" + cv.IndustryName
- // sellerName = "ficc:" + cv.SellerName
- // startDateStr := cv.StartDate.Format("2006/01/02")
- // endDateStr := cv.EndDate.Format("2006/01/02")
- // if startDateStr != "0001/01/01" {
- // timeLimt = "ficc:" + startDateStr + "~" + endDateStr
- // } else {
- // timeLimt = ""
- // }
- // createTime = "ficc:" + cv.CreateTime
- // source = "ficc:" + cv.Source
- // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
- //
- // permissionStr = "ficc:"
- // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
- // permissionStr += newPermissionStr
- // } else {
- // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
- // if err != nil {
- // br.Msg = "导出失败"
- // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
- // return
- // }
- // permissionMap[permissionKey] = getPermissionStr
- // permissionStr += getPermissionStr
- // }
- // if cv.Status == utils.COMPANY_STATUS_LOSE {
- // permissionStr = ""
- // }
- // } else {
- // industryName = industryName + "\n" + "权益:" + cv.IndustryName
- // sellerName = sellerName + "\n" + "权益:" + cv.SellerName
- // startDateStr := cv.StartDate.Format("2006/01/02")
- // endDateStr := cv.EndDate.Format("2006/01/02")
- //
- // if startDateStr != "0001/01/01" {
- // timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
- // } else {
- // timeLimt = timeLimt + ""
- // }
- // createTime = createTime + "\n" + "权益:" + cv.CreateTime
- // source = source + "\n" + "权益:" + cv.Source
- //
- // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
- // if permissionStr != "" {
- // permissionStr = permissionStr + "\n" + "权益:"
- // } else {
- // permissionStr = "权益:"
- // }
- // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
- // permissionStr += newPermissionStr
- // } else {
- // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
- // if err != nil {
- // br.Msg = "导出失败"
- // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
- // return
- // }
- // permissionMap[permissionKey] = getPermissionStr
- // permissionStr += getPermissionStr
- // }
- // if cv.Status == utils.COMPANY_STATUS_LOSE {
- // permissionStr = permissionStr + ""
- // }
- // }
- // }
- // dataRow.AddCell().SetString(companyName)
- // dataRow.AddCell().SetString(creditCode)
- // dataRow.AddCell().SetString(regionType)
- //
- // dataRow.AddCell().SetString(companyType)
- // industryValueCell := dataRow.AddCell()
- // industryValueCell.SetStyle(style)
- // industryValueCell.SetString(industryName)
- //
- // sellerValueCell := dataRow.AddCell()
- // sellerValueCell.SetStyle(style)
- // sellerValueCell.SetString(sellerName)
- //
- // statusValueCell := dataRow.AddCell()
- // statusValueCell.SetStyle(style)
- // statusValueCell.SetValue(status)
- //
- // timeLimitValueCell := dataRow.AddCell()
- // timeLimitValueCell.SetStyle(style)
- // timeLimitValueCell.SetValue(timeLimt)
- //
- // createTimeValueCell := dataRow.AddCell()
- // createTimeValueCell.SetStyle(style)
- // createTimeValueCell.SetValue(createTime)
- //
- // sourceValueCell := dataRow.AddCell()
- // sourceValueCell.SetStyle(style)
- // sourceValueCell.SetValue(source)
- //
- // permissionStrValueCell := dataRow.AddCell()
- // permissionStrValueCell.SetStyle(style)
- // permissionStrValueCell.SetValue(permissionStr)
- // }
- // }
- // err = xlsxFile.Save(downLoadnFilePath)
- // if err != nil {
- // br.Msg = "保存文件失败"
- // br.ErrMsg = "保存文件失败"
- // return
- // }
- // randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
- // downloadFileName := "联系人列表" + randStr + ".xlsx"
- // this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
- // defer func() {
- // os.Remove(downLoadnFilePath)
- // }()
- // br.Ret = 200
- // br.Success = true
- // br.Msg = "导出成功"
- //}
- // @Title 冻结客户
- // @Description 冻结客户接口
- // @Param request body company.CompanyFreezeReq true "type json string"
- // @Success Ret=200 冻结成功
- // @router /freeze [post]
- func (this *CompanyController) Freeze() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req company.CompanyFreezeReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.CompanyId <= 0 {
- br.Msg = "参数错误!"
- br.ErrMsg = "客户id小于等于0"
- return
- }
- productId := 0
- productName := ""
- if req.CompanyType == utils.COMPANY_CLASSIFY_FICC {
- productId = 1
- productName = "ficc"
- } else if req.CompanyType == utils.COMPANY_CLASSIFY_RAI {
- productId = 2
- productName = "权益"
- } else {
- productId = 3
- productName = "佣金客户"
- }
- if req.CompanyId <= 0 {
- br.Msg = "参数异常!"
- br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
- return
- }
- cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
- if err != nil {
- br.Msg = "查询该客户产品异常!"
- br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
- return
- }
- if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
- br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
- br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
- return
- }
- //查询客户的产品权限
- companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, productId)
- if err != nil {
- br.Msg = "查询客户的产品权限异常"
- br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
- return
- }
- err = company.CompanyFreeze(req.CompanyId, productId, req.Remark)
- if err != nil {
- br.Msg = "冻结失败!"
- br.ErrMsg = "冻结失败,Err:" + err.Error()
- return
- }
- //新增操作记录
- {
- approveContent := req.Remark
- remark := "冻结客户"
- operation := "freeze"
- services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
- productName, sysUser.RealName, remark, operation, approveContent, sysUser.RealName, "", "冻结")
- //新增产品权限冻结操作日志
- for _, companyReportPermission := range companyReportPermissionList {
- record := company_report_permission_log.CompanyReportPermissionLog{
- CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
- CompanyId: companyReportPermission.CompanyId,
- ProductId: productId,
- ProductName: companyReportPermission.ProductName,
- SysUserId: sysUser.AdminId,
- SysUserName: sysUser.RealName,
- Remark: "冻结客户",
- Operation: "freeze",
- Status: companyReportPermission.Status,
- CreateTime: time.Now(),
- }
- _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "领取成功"
- }
- // @Title 获取客户权限
- // @Description 获取客户权限接口
- // @Param CompanyId query int true "用户id"
- // @Success 200 {object} company.CompanyPermissionResp
- // @router /getCompanyPermission [get]
- func (this *CompanyController) PermissionList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- companyId, _ := this.GetInt("CompanyId")
- if companyId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "客户参数小于等于0"
- return
- }
- //返回基础参数
- resp := new(company.CompanyPermissionResp)
- //客户类型map
- classifyMap := make(map[string]int)
- classifyMap["ficc"] = 1
- classifyMap["权益"] = 2
- roleTypeCode := sysUser.RoleTypeCode
- var companySlice []string
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
- roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
- roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
- roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
- roleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM ||
- roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
- roleTypeCode == utils.ROLE_TYPE_CODE_FICC_RESEARCHR {
- companySlice = append(companySlice, "ficc")
- } else if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_RESEARCHR {
- companySlice = append(companySlice, "权益")
- }
- for _, companyType := range companySlice {
- //子权限切片集合
- //var permissionClassifyArr []string
- var permissionProductId int
- if companyType == "ficc" {
- permissionProductId = utils.COMPANY_PRODUCT_FICC_ID
- } else {
- permissionProductId = utils.COMPANY_PRODUCT_RAI_ID
- }
- //子权限切片集合
- permissionClassifyArr, err := models.GetPermissionFirstByProductId(permissionProductId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
- return
- }
- //遍历获取
- for _, v := range permissionClassifyArr {
- checkList := make([]int, 0)
- plist := new(company.PermissionLookList)
- plist.Items = make([]*company.PermissionLookItem, 0)
- items, err := company.GetPermissionLookItemsByParentId(classifyMap[companyType], v.ChartPermissionId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
- return
- }
- mapPermissionCheck := make(map[string]int)
- for i, n := range items {
- item := items[i]
- count, err := company.GetCompanyPermissionCheck(companyId, n.ChartPermissionId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
- return
- }
- //合并主观客观勾选的权限
- if count > 0 && mapPermissionCheck[n.PermissionName] == 0 {
- checkList = append(checkList, n.ChartPermissionId)
- mapPermissionCheck[n.PermissionName] = n.ChartPermissionId
- }
- permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
- return
- }
- if permission != nil && permission.ChartPermissionId > 0 {
- items[i].StartDate = permission.StartDate
- items[i].EndDate = permission.EndDate
- items[i].Status = permission.Status
- //判断主观、客观
- if items[i].PermissionType == 1 {
- items[i].PermissionTypeName = "主观"
- } else if items[i].PermissionType == 2 {
- items[i].PermissionTypeName = "客观"
- }
- }
- endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
- endDateTime = endDateTime.AddDate(0, 0, 1)
- sub := endDateTime.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
- items[i].ExpireDay = expireDay
- items[i].ClassifyName = v.PermissionName
- //if n.PermissionType == 1 {
- // items[i].PermissionTypeName = "主观"
- //} else if n.PermissionType == 2 {
- // items[i].PermissionTypeName = "客观"
- //}
- }
- //合并主观客观
- mapPermissionName := make(map[string]int)
- for _, v := range items {
- if mapPermissionName[v.PermissionName] == 0 {
- //plist.Items = append(plist.Items, v)
- //mapPermissionName[v.PermissionName] = v.ChartPermissionId
- // CRM8.8-只有客观的时候回显
- if mapPermissionCheck[v.PermissionName] == 0 || (mapPermissionCheck[v.PermissionName] > 0 && v.ChartPermissionId == mapPermissionCheck[v.PermissionName]) {
- plist.Items = append(plist.Items, v)
- mapPermissionName[v.PermissionName] = v.ChartPermissionId
- }
- }
- }
- plist.ClassifyName = v.PermissionName
- plist.CheckList = checkList
- if companyType == "ficc" {
- resp.FiccPermissionList = append(resp.FiccPermissionList, plist)
- } else {
- resp.PermissionList = append(resp.PermissionList, plist)
- }
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 获取客户来源列表
- // @Description 获取客户来源列表
- // @Success 200 {object} models.CompanySourceListResp
- // @router /getCompanySourceList [get]
- func (this *CompanyController) CompanySourceList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- list, err := models.GetAllCompanySourceList()
- if err != nil {
- br.Msg = "查询失败"
- br.ErrMsg = "查询异常:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = models.CompanySourceListResp{
- List: list,
- }
- }
- // @Title 获取客户的合同列表
- // @Description 获取客户合同列表接口
- // @Param CompanyId query int true "用户id"
- // @Param CompanyType query string false "用户类型:可取范围:ficc,权益"
- // @Param Status query int true "合同审核结果,枚举值:`0`,`1`; 0:待审核,1:审核通过"
- // @Success 200 {object} company.CompanyPermissionResp
- // @router /getCompanyContract [get]
- func (this *CompanyController) ContractList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- companyId, _ := this.GetInt("CompanyId")
- if companyId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "客户参数小于等于0"
- return
- }
- //合同状态
- status, _ := this.GetInt("Status")
- //产品类型
- companyType := this.GetString("CompanyType")
- var condition string
- var pars []interface{}
- //产品类型
- if companyType == "" {
- productId := services.GetProductId(sysUser.RoleTypeCode)
- if productId != 0 {
- condition += " AND product_id = ?"
- pars = append(pars, productId)
- }
- } else {
- if companyType == "ficc" {
- condition += " AND product_id = ?"
- pars = append(pars, 1)
- } else {
- condition += " AND product_id = ?"
- pars = append(pars, 2)
- }
- }
- if status != 0 {
- condition += " AND status = ?"
- pars = append(pars, status)
- }
- list, err := company.GetCompanyContractListByCompanyId(companyId, condition, pars)
- if err != nil {
- br.Msg = "查询失败"
- br.ErrMsg = "查询异常:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = list
- }
- // @Title 获取客户所属销售
- // @Description 根据客户id获取客户所属销售
- // @Param CompanyId query int true "客户id"
- // @Success 200 {object} response.CompanySellerListResp
- // @router /getCompanySellerList [get]
- func (this *CompanyUserController) GetCompanySellerList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- companyId, _ := this.GetInt("CompanyId")
- //item := make([]*company.CompanyItem, 0)
- list, err := company.GetCompanySellerByCompanyId(companyId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- resp := response.CompanySellerListResp{
- List: list,
- }
- //resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // GetTryOutCompanyList
- // @Title 获取销售今日待办数据
- // @Description 获取销售今日待办接口
- // @Param CompanyName query string false "客户名称"
- // @Param ReasonStatus query int false "续约情况说明状态:-1:未填写,0:全部,1:已填写"
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} response.TryOutCompanyListResp
- // @router /getTryOutCompanyList [get]
- func (this *CompanyController) GetTryOutCompanyList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- companyName := this.GetString("CompanyName")
- reasonStatus, _ := this.GetInt("ReasonStatus", 0)
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- productId := services.GetProductId(sysUser.RoleTypeCode)
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- //sellerId, productId int, tryOutTime time.Time, tryOutReason string
- var tryOutTime, lastDescriptionTime time.Time
- if productId == 1 {
- //ficc
- interval := cache.GetIntervalFromCrmConfig("try_out_time_intervals")
- tryOutTime = time.Now().AddDate(0, 0, -interval)
- interval = cache.GetIntervalFromCrmConfig("last_description_time_intervals")
- lastDescriptionTime = time.Now().AddDate(0, 0, -interval)
- } else {
- //权益
- interval := cache.GetIntervalFromCrmConfig("rai_try_out_time_intervals")
- tryOutTime = time.Now().AddDate(0, 0, -interval)
- interval = cache.GetIntervalFromCrmConfig("rai_last_description_time_intervals")
- lastDescriptionTime = time.Now().AddDate(0, 0, -interval)
- }
- if productId > 0 {
- condition += ` and product_id=? `
- pars = append(pars, productId)
- }
- //客户名称模糊搜索
- if companyName != "" {
- condition += ` and b.company_name like "%` + companyName + `%" `
- }
- //续约情况说明(-1:未填写,0:全部,1:已填写)
- switch reasonStatus {
- case -1:
- condition += ` and seller_id=? and try_out_time <=? and (last_description_time <=? OR last_description_time IS NULL) and (renewal_intention is NULL or renewal_reason is NULL or renewal_intention = 0) and (freeze_time='' OR freeze_time IS NULL) `
- pars = append(pars, sysUser.AdminId, tryOutTime, lastDescriptionTime)
- case 1:
- condition += ` and seller_id=? and try_out_time <= ? and (renewal_intention is NULL or renewal_reason is NULL or renewal_intention = 0) and (freeze_time='' OR freeze_time IS NULL) `
- pars = append(pars, sysUser.AdminId, tryOutTime)
- default:
- condition += ` and seller_id=? and (try_out_time <= ? or last_description_time <= ?) and (renewal_intention is NULL or renewal_reason is NULL or renewal_intention = 0) and (freeze_time='' OR freeze_time IS NULL) `
- pars = append(pars, sysUser.AdminId, tryOutTime, lastDescriptionTime)
- }
- total := 0
- list := make([]*company.TryOutCompanyList, 0)
- ignoreStrs := []string{utils.ROLE_TYPE_CODE_FICC_SELLER, utils.ROLE_TYPE_CODE_RAI_SELLER, utils.ROLE_TYPE_CODE_FICC_GROUP, utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_RAI_GROUP}
- if strings.Contains(strings.Join(ignoreStrs, ","), sysUser.RoleTypeCode) {
- //排除已经签署续约合同的
- notSql := ``
- if productId > 0 {
- notSql = fmt.Sprint(` and product_id = `, productId)
- }
- condition += `and a.company_id not in (select company_id from company_contract where contract_type ="续约合同" and start_date >now() and status = 1 ` + notSql + `) `
- tmpTotal, err := company.GetTryOutCompanyCount(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取总数失败失败,Err:" + err.Error()
- return
- }
- tmpList, err := company.GetTryOutCompanyList(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- total = tmpTotal
- list = tmpList
- }
- if len(list) > 0 {
- for k, item := range list {
- endTime, _ := time.Parse(utils.FormatDate, item.EndDate)
- endTime = endTime.AddDate(0, 0, 1)
- sub := endTime.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- list[k].ExpireDays = int(sub.Hours() / 24)
- }
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := response.TryOutCompanyListResp{
- List: list,
- Paging: page,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // EditTryOutCompanyReason
- // @Title 编辑续约说明情况
- // @Description 编辑续约说明情况接口
- // @Param request body company.RenewalReasonReq true "type json string"
- // @Success 200 编辑成功
- // @router /editTryOutCompanyReason [post]
- func (this *CompanyController) EditTryOutCompanyReason() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req company.RenewalReasonReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.CompanyId <= 0 {
- br.Msg = "参数缺失"
- br.ErrMsg = "参数缺失,客户编号未传!"
- return
- }
- if req.ProductId <= 0 {
- br.Msg = "参数缺失"
- br.ErrMsg = "参数缺失,产品编号未传!"
- return
- }
- if req.Remark == "" {
- br.Msg = "参数缺失"
- br.ErrMsg = "参数缺失,续约情况说明未传!"
- return
- }
- /*if req.RenewalTodo == "" && req.Renew == 0 {
- br.Msg = "参数缺失"
- br.ErrMsg = "参数缺失,待办事项说明未传!"
- return
- }*/
- companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
- if err != nil {
- br.Msg = "查询客户异常"
- br.ErrMsg = "查询客户异常,Err:" + err.Error()
- return
- }
- if companyProduct.SellerId != sysUser.AdminId {
- br.Msg = "客户异常,没有该客户的操作权限"
- br.ErrMsg = "客户异常,没有该客户的操作权限"
- return
- }
- renewalReason := company.CompanyRenewalReason{
- CompanyRenewalReasonId: 0,
- CompanyId: companyProduct.CompanyId,
- ProductId: companyProduct.ProductId,
- ProductName: companyProduct.ProductName,
- CompanyName: companyProduct.CompanyName,
- TryOutTime: companyProduct.TryOutTime,
- RenewalReason: req.Remark,
- RenewalTodo: req.RenewalTodo,
- LastDescriptionTime: companyProduct.LastDescriptionTime,
- EndDays: companyProduct.ContractEndDate,
- ExpirationTimeExceeded: 0,
- RenewalIntention: req.Renew,
- CreateTime: time.Now(),
- }
- endTime, err := company.GetTryOutTimeFromOperationRecord(renewalReason.CompanyId)
- if err != nil {
- br.Msg = "查询该客户转试用时间异常!"
- br.ErrMsg = "查询该客户转试用时间异常,err:" + err.Error()
- return
- }
- endDateTime, err := time.Parse(utils.FormatDateTime, *endTime)
- if err != nil {
- br.Msg = "时间格式化异常!"
- br.ErrMsg = "时间格式化异常,err:" + err.Error()
- return
- }
- endDate := endDateTime.Format(utils.FormatDate)
- endDateTime, _ = time.Parse(utils.FormatDate, endDate)
- sub := time.Now().Sub(endDateTime)
- renewalReason.ExpirationTimeExceeded = int(sub.Hours() / 24)
- var newId int64
- newId, err = company.AddRenewalReason(&renewalReason)
- if err != nil {
- br.Msg = "新增续约情况说明操作异常!"
- br.ErrMsg = "新增续约情况说明操作异常,err:" + err.Error()
- return
- }
- companyProduct.RenewalIntention = req.Renew
- err = company.EditTryOutCompanyReason(companyProduct, req.Remark, req.RenewalTodo)
- if err != nil {
- br.Msg = "更新客户未续约异常!"
- br.ErrMsg = "更新客户未续约异常,err:" + err.Error()
- return
- }
- if req.Renew == 1 {
- productName := ""
- if req.ProductId == 1 {
- productName = "ficc"
- } else if req.ProductId == 2 {
- productName = "权益"
- } else {
- productName = "佣金客户"
- }
- cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
- if err != nil {
- br.Msg = "查询该客户产品异常!"
- br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
- return
- }
- if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
- br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
- br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
- return
- }
- //查询客户的产品权限
- companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, req.ProductId)
- if err != nil {
- br.Msg = "查询客户的产品权限异常"
- br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
- return
- }
- err = company.CompanyFreeze(req.CompanyId, req.ProductId, req.Remark)
- if err != nil {
- br.Msg = "冻结失败!"
- br.ErrMsg = "冻结失败,Err:" + err.Error()
- return
- }
- //新增操作记录
- go func() {
- time.Sleep(time.Second)
- approveContent := req.Remark
- remark := "冻结客户"
- operation := "freeze"
- _ = services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
- productName, "超级管理员", remark, operation, approveContent, sysUser.RealName, "", "冻结")
- //新增产品权限冻结操作日志
- for _, companyReportPermission := range companyReportPermissionList {
- record := company_report_permission_log.CompanyReportPermissionLog{
- CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
- CompanyId: companyReportPermission.CompanyId,
- ProductId: req.ProductId,
- ProductName: companyReportPermission.ProductName,
- SysUserId: sysUser.AdminId,
- SysUserName: "超级管理员",
- Remark: "冻结客户",
- Operation: "freeze",
- Status: companyReportPermission.Status,
- CreateTime: time.Now(),
- }
- _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
- }
- }()
- }
- approveContent := req.Remark
- approveContentExtra := req.RenewalTodo
- remark := "新增续约说明"
- operation := "edit_renewal_reason"
- _ = services.AddCompanyOperationRecordMore(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
- companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, approveContentExtra, sysUser.RealName, "", companyProduct.Status)
- items, err := company.ReadCompanyOperationRecord(req.CompanyId)
- if err != nil {
- br.Msg = "编辑失败"
- br.ErrMsg = "编辑失败,Err:" + err.Error()
- return
- }
- if len(items) > 0 {
- record := new(company.CompanyOperationRecord)
- record.Id = items[0].Id
- record.ApproveContent = req.Remark
- record.ApproveContentExtra = req.RenewalTodo
- _, err = company.UpdateCompanyOperationRecord(record)
- if err != nil {
- br.Msg = "编辑失败"
- br.ErrMsg = "编辑失败,Err:" + err.Error()
- return
- }
- } else {
- br.Msg = "编辑失败"
- br.ErrMsg = "编辑失败,未查询到转试用记录"
- return
- }
- if req.ProductId == utils.COMPANY_PRODUCT_RAI_ID {
- //权益客户新增历史备注总表
- itemRecord := new(company.CompanyHistoryRemark)
- itemRecord.CompanyId = req.CompanyId
- itemRecord.Content = req.Remark
- itemRecord.SysAdminId = sysUser.AdminId
- itemRecord.SysAdminName = sysUser.RealName
- itemRecord.CreateTime = time.Now().Local()
- itemRecord.ModifyTime = time.Now().Local()
- itemRecord.ShowTime = time.Now().Local()
- itemRecord.ProductId = 2
- itemRecord.TableName = "company_renewal_reason"
- itemRecord.TableId = int(newId)
- go services.AddCompanyHistoryRemark(itemRecord)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "编辑成功"
- }
- // AddTryOutCompanyReason
- // @Title 新增续约说明情况
- // @Description 新增续约说明情况接口
- // @Param request body company.RenewalReasonReq true "type json string"
- // @Success 200 编辑成功
- // @router /addTryOutCompanyReason [post]
- func (this *CompanyController) AddTryOutCompanyReason() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req company.RenewalReasonReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.CompanyId <= 0 {
- br.Msg = "参数缺失"
- br.ErrMsg = "参数缺失,客户编号未传!"
- return
- }
- if req.ProductId <= 0 {
- br.Msg = "参数缺失"
- br.ErrMsg = "参数缺失,产品编号未传!"
- return
- }
- if req.Remark == "" {
- br.Msg = "参数缺失"
- br.ErrMsg = "参数缺失,续约情况说明未传!"
- return
- }
- if req.RenewalTodo == "" && req.Renew == 0 {
- br.Msg = "参数缺失"
- br.ErrMsg = "参数缺失,待办事项说明未传!"
- return
- }
- companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
- if err != nil {
- br.Msg = "查询客户异常"
- br.ErrMsg = "查询客户异常,Err:" + err.Error()
- return
- }
- if companyProduct.SellerId != sysUser.AdminId {
- br.Msg = "客户异常,没有该客户的操作权限"
- br.ErrMsg = "客户异常,没有该客户的操作权限"
- return
- }
- renewalReason := company.CompanyRenewalReason{
- CompanyRenewalReasonId: 0,
- CompanyId: companyProduct.CompanyId,
- ProductId: companyProduct.ProductId,
- ProductName: companyProduct.ProductName,
- CompanyName: companyProduct.CompanyName,
- TryOutTime: companyProduct.TryOutTime,
- RenewalReason: req.Remark,
- RenewalTodo: req.RenewalTodo,
- LastDescriptionTime: companyProduct.LastDescriptionTime,
- EndDays: companyProduct.ContractEndDate,
- ExpirationTimeExceeded: 0,
- RenewalIntention: req.Renew,
- CreateTime: time.Now(),
- }
- endTime, err := company.GetTryOutTimeFromOperationRecord(renewalReason.CompanyId)
- if err != nil {
- br.Msg = "查询该客户转试用时间异常!"
- br.ErrMsg = "查询该客户转试用时间异常,err:" + err.Error()
- return
- }
- endDateTime, err := time.Parse(utils.FormatDateTime, *endTime)
- if err != nil {
- br.Msg = "时间格式化异常!"
- br.ErrMsg = "时间格式化异常,err:" + err.Error()
- return
- }
- endDate := endDateTime.Format(utils.FormatDate)
- endDateTime, _ = time.Parse(utils.FormatDate, endDate)
- sub := time.Now().Sub(endDateTime)
- renewalReason.ExpirationTimeExceeded = int(sub.Hours() / 24)
- var newId int64
- newId, err = company.AddRenewalReason(&renewalReason)
- if err != nil {
- br.Msg = "新增续约情况说明操作异常!"
- br.ErrMsg = "新增续约情况说明操作异常,err:" + err.Error()
- return
- }
- companyProduct.RenewalIntention = req.Renew
- err = company.EditTryOutCompanyReason(companyProduct, req.Remark, req.RenewalTodo)
- if err != nil {
- br.Msg = "更新客户续约情况说明异常!"
- br.ErrMsg = "更新客户续约情况说明异常,err:" + err.Error()
- return
- }
- if req.Renew == 1 {
- productName := ""
- if req.ProductId == 1 {
- productName = "ficc"
- } else if req.ProductId == 2 {
- productName = "权益"
- } else {
- productName = "佣金客户"
- }
- cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
- if err != nil {
- br.Msg = "查询该客户产品异常!"
- br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
- return
- }
- if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
- br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
- br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
- return
- }
- //查询客户的产品权限
- companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, req.ProductId)
- if err != nil {
- br.Msg = "查询客户的产品权限异常"
- br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
- return
- }
- err = company.CompanyFreeze(req.CompanyId, req.ProductId, req.Remark)
- if err != nil {
- br.Msg = "冻结失败!"
- br.ErrMsg = "冻结失败,Err:" + err.Error()
- return
- }
- //新增操作记录
- go func() {
- time.Sleep(time.Second)
- approveContent := req.Remark
- remark := "冻结客户"
- operation := "freeze"
- _ = services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
- productName, "超级管理员", remark, operation, approveContent, sysUser.RealName, "", "冻结")
- //新增产品权限冻结操作日志
- for _, companyReportPermission := range companyReportPermissionList {
- record := company_report_permission_log.CompanyReportPermissionLog{
- CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
- CompanyId: companyReportPermission.CompanyId,
- ProductId: req.ProductId,
- ProductName: companyReportPermission.ProductName,
- SysUserId: sysUser.AdminId,
- SysUserName: "超级管理员",
- Remark: "冻结客户",
- Operation: "freeze",
- Status: companyReportPermission.Status,
- CreateTime: time.Now(),
- }
- _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
- }
- }()
- }
- {
- approveContent := req.Remark
- approveContentExtra := req.RenewalTodo
- remark := "新增续约说明"
- operation := "add_renewal_reason"
- _ = services.AddCompanyOperationRecordMore(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
- companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, approveContentExtra, sysUser.RealName, "", companyProduct.Status)
- }
- if req.ProductId == utils.COMPANY_PRODUCT_RAI_ID {
- //权益客户新增历史备注总表
- itemRecord := new(company.CompanyHistoryRemark)
- itemRecord.CompanyId = req.CompanyId
- itemRecord.Content = req.Remark
- itemRecord.SysAdminId = sysUser.AdminId
- itemRecord.SysAdminName = sysUser.RealName
- itemRecord.CreateTime = time.Now().Local()
- itemRecord.ModifyTime = time.Now().Local()
- itemRecord.ShowTime = time.Now().Local()
- itemRecord.ProductId = 2
- itemRecord.TableName = "company_renewal_reason"
- itemRecord.TableId = int(newId)
- go services.AddCompanyHistoryRemark(itemRecord)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "编辑成功"
- }
- // RenewReasonList 客户未续约说明历史列表
- // @Title 客户未续约说明历史列表
- // @Description 客户未续约说明历史列表
- // @Param CompanyId query string true "客户id"
- // @Param ProductId query string true "产品id"
- // @Success 200 {object} response.RenewReasonItemResp
- // @router /renewReasonList [get]
- func (this *CompanyController) RenewReasonList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- CompanyId := this.GetString("CompanyId")
- ProductId := this.GetString("ProductId")
- if CompanyId == "" {
- br.Msg = "请输入客户ID"
- return
- }
- if ProductId != "1" && ProductId != "2" {
- br.Msg = "请输入正确的产品ID"
- return
- }
- renewalReason, err := models.GetMoreRenewalReason(CompanyId, ProductId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- resp := make([]response.RenewReasonItemResp, len(renewalReason))
- for i, reason := range renewalReason {
- createDate := reason.CreateTime.Format("2006.01.02 15:04:05")
- resp[i].RenewalReason = reason.RenewalReason
- resp[i].RenewalTodo = reason.RenewalTodo
- resp[i].CreateTime = createDate
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // AddRenewalReason
- // @Title 转试用按钮新增续约说明情况
- // @Description 转试用按钮新增续约说明情况
- // @Param request body company.TryOutReq true "type json string"
- // @Success 200 编辑成功
- // @router /addRenewalReason [post]
- func (this *CompanyController) AddRenewalReason() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req company.TryOutReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.CompanyId <= 0 {
- br.Msg = "参数缺失"
- br.ErrMsg = "参数缺失,客户编号未传!"
- return
- }
- if req.ProductId <= 0 {
- br.Msg = "参数缺失"
- br.ErrMsg = "参数缺失,产品编号未传!"
- return
- }
- if req.OperationId <= 0 {
- br.Msg = "参数缺失"
- br.ErrMsg = "参数缺失,操作记录表编号未传!"
- return
- }
- if req.Remark == "" {
- br.Msg = "参数缺失"
- br.ErrMsg = "参数缺失,续约情况说明未传!"
- return
- }
- if req.RenewalTodo == "" && req.Renew == 0 {
- br.Msg = "参数缺失"
- br.ErrMsg = "参数缺失,待办事项说明未传!"
- return
- }
- companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
- if err != nil {
- br.Msg = "查询客户异常"
- br.ErrMsg = "查询客户异常,Err:" + err.Error()
- return
- }
- if companyProduct.SellerId != sysUser.AdminId {
- br.Msg = "客户异常,没有该客户的操作权限"
- br.ErrMsg = "客户异常,没有该客户的操作权限"
- return
- }
- renewalReason := company.CompanyRenewalReason{
- CompanyRenewalReasonId: 0,
- CompanyId: companyProduct.CompanyId,
- ProductId: companyProduct.ProductId,
- ProductName: companyProduct.ProductName,
- CompanyName: companyProduct.CompanyName,
- TryOutTime: companyProduct.TryOutTime,
- RenewalReason: req.Remark,
- RenewalTodo: req.RenewalTodo,
- LastDescriptionTime: companyProduct.LastDescriptionTime,
- EndDays: companyProduct.ContractEndDate,
- ExpirationTimeExceeded: 0,
- RenewalIntention: req.Renew,
- CreateTime: time.Now(),
- }
- endTime, err := company.GetTryOutTimeFromOperationRecord(renewalReason.CompanyId)
- if err != nil {
- br.Msg = "查询该客户转试用时间异常!"
- br.ErrMsg = "查询该客户转试用时间异常,err:" + err.Error()
- return
- }
- endDateTime, err := time.Parse(utils.FormatDateTime, *endTime)
- if err != nil {
- br.Msg = "时间格式化异常!"
- br.ErrMsg = "时间格式化异常,err:" + err.Error()
- return
- }
- endDate := endDateTime.Format(utils.FormatDate)
- endDateTime, _ = time.Parse(utils.FormatDate, endDate)
- sub := time.Now().Sub(endDateTime)
- renewalReason.ExpirationTimeExceeded = int(sub.Hours() / 24)
- var newId int64
- newId, err = company.AddRenewalReason(&renewalReason)
- if err != nil {
- br.Msg = "新增续约情况说明操作异常!"
- br.ErrMsg = "新增续约情况说明操作异常,err:" + err.Error()
- return
- }
- companyProduct.RenewalIntention = req.Renew
- err = company.EditTryOutCompanyReason(companyProduct, req.Remark, req.RenewalTodo)
- if err != nil {
- br.Msg = "更新客户续约情况说明异常!"
- br.ErrMsg = "更新客户续约情况说明异常,err:" + err.Error()
- return
- }
- if req.Renew == 1 {
- productName := ""
- if req.ProductId == 1 {
- productName = "ficc"
- } else if req.ProductId == 2 {
- productName = "权益"
- } else {
- productName = "佣金客户"
- }
- cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
- if err != nil {
- br.Msg = "查询该客户产品异常!"
- br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
- return
- }
- if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
- br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
- br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
- return
- }
- //查询客户的产品权限
- companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, req.ProductId)
- if err != nil {
- br.Msg = "查询客户的产品权限异常"
- br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
- return
- }
- err = company.CompanyFreeze(req.CompanyId, req.ProductId, req.Remark)
- if err != nil {
- br.Msg = "冻结失败!"
- br.ErrMsg = "冻结失败,Err:" + err.Error()
- return
- }
- //新增操作记录
- go func() {
- time.Sleep(time.Second)
- approveContent := req.Remark
- remark := "冻结客户"
- operation := "freeze"
- _ = services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
- productName, "超级管理员", remark, operation, approveContent, sysUser.RealName, "", "冻结")
- //新增产品权限冻结操作日志
- for _, companyReportPermission := range companyReportPermissionList {
- record := company_report_permission_log.CompanyReportPermissionLog{
- CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
- CompanyId: companyReportPermission.CompanyId,
- ProductId: req.ProductId,
- ProductName: companyReportPermission.ProductName,
- SysUserId: sysUser.AdminId,
- SysUserName: "超级管理员",
- Remark: "冻结客户",
- Operation: "freeze",
- Status: companyReportPermission.Status,
- CreateTime: time.Now(),
- }
- _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
- }
- }()
- }
- {
- approveContent := req.Remark
- approveContentExtra := req.RenewalTodo
- remark := "新增续约说明"
- operation := "add_try_out_reason"
- _ = services.AddCompanyOperationRecordMore(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
- companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, approveContentExtra, sysUser.RealName, "", companyProduct.Status)
- record := new(company.CompanyOperationRecord)
- record.Id = req.OperationId
- record.ApproveContent = req.Remark
- record.ApproveContentExtra = req.RenewalTodo
- _, err = company.UpdateCompanyOperationRecord(record)
- if err != nil {
- br.Msg = "编辑失败"
- br.ErrMsg = "编辑失败,Err:" + err.Error()
- return
- }
- }
- if req.ProductId == utils.COMPANY_PRODUCT_RAI_ID {
- //权益客户新增历史备注总表
- itemRecord := new(company.CompanyHistoryRemark)
- itemRecord.CompanyId = req.CompanyId
- itemRecord.Content = req.Remark
- itemRecord.SysAdminId = sysUser.AdminId
- itemRecord.SysAdminName = sysUser.RealName
- itemRecord.CreateTime = time.Now().Local()
- itemRecord.ModifyTime = time.Now().Local()
- itemRecord.ShowTime = time.Now().Local()
- itemRecord.ProductId = 2
- itemRecord.TableName = "company_renewal_reason"
- itemRecord.TableId = int(newId)
- go services.AddCompanyHistoryRemark(itemRecord)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "编辑成功"
- }
- // AddRemark
- // @Title 新增备注
- // @Description 新增备注
- // @Param request body company.RemarkReq true "type json string"
- // @Success 200 编辑成功
- // @router /remark/add [post]
- func (this *CompanyController) AddRemark() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req company.RemarkReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.CompanyId <= 0 {
- br.Msg = "参数缺失"
- br.ErrMsg = "参数缺失,客户编号未传!"
- return
- }
- if req.Remark == "" {
- br.Msg = "参数缺失"
- br.ErrMsg = "参数缺失,备注说明未传!"
- return
- }
- var productId int
- //var productName string
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
- productId = 1
- //productName = "ficc"
- } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT {
- productId = 2
- //productName = "权益"
- } else {
- br.Msg = "角色类型错误"
- br.ErrMsg = "角色类型错误,该角色不能添加备注!"
- return
- }
- companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
- if err != nil {
- br.Msg = "查询客户异常"
- br.ErrMsg = "查询客户异常,Err:" + err.Error()
- }
- if companyProduct.SellerId != sysUser.AdminId {
- br.Msg = "客户异常,没有该客户的操作权限"
- br.ErrMsg = "客户异常,没有该客户的操作权限"
- return
- }
- remark := company.CompanyProductRemark{
- CompanyId: companyProduct.CompanyId,
- ProductId: companyProduct.ProductId,
- ProductName: companyProduct.ProductName,
- Remark: req.Remark,
- CreateTime: time.Now(),
- SysUserId: sysUser.AdminId,
- SysRealName: sysUser.RealName,
- }
- var newId int64
- newId, err = company.AddCompanyRemark(&remark)
- {
- approveContent := req.Remark
- remark := "新增备注"
- operation := "add_remark"
- services.AddCompanyOperationRecord(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
- companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, sysUser.RealName, "", companyProduct.Status)
- }
- if err != nil {
- br.Msg = "编辑失败"
- br.ErrMsg = "编辑失败,Err:" + err.Error()
- }
- //如果是权益的写入历史备注表
- if productId == utils.COMPANY_PRODUCT_RAI_ID {
- //权益客户新增历史备注总表
- itemRecord := new(company.CompanyHistoryRemark)
- itemRecord.CompanyId = req.CompanyId
- itemRecord.Content = req.Remark
- itemRecord.SysAdminId = sysUser.AdminId
- itemRecord.SysAdminName = sysUser.RealName
- itemRecord.CreateTime = time.Now().Local()
- itemRecord.ModifyTime = time.Now().Local()
- itemRecord.ShowTime = time.Now().Local()
- itemRecord.ProductId = 2
- itemRecord.TableName = "company_product_remark"
- itemRecord.TableId = int(newId)
- go services.AddCompanyHistoryRemark(itemRecord)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "编辑成功"
- }
- // RemarkList 备注列表
- // @Title 备注列表
- // @Description 备注列表
- // @Param CompanyId query string true "客户id"
- // @Success 200 {object} company.RemarkResp
- // @router /remark [get]
- func (this *CompanyController) RemarkList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- companyId := this.GetString("CompanyId")
- var remarkList []*company.CompanyProductRemark
- var err error
- groupFicc := []string{
- utils.ROLE_TYPE_CODE_FICC_SELLER, utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_FICC_GROUP,
- utils.ROLE_TYPE_CODE_FICC_DEPARTMENT, utils.ROLE_TYPE_CODE_FICC_ADMIN,
- }
- groupRai := []string{
- utils.ROLE_TYPE_CODE_RAI_SELLER, utils.ROLE_TYPE_CODE_RAI_GROUP, utils.ROLE_TYPE_CODE_RAI_GROUP,
- utils.ROLE_TYPE_CODE_RAI_DEPARTMENT, utils.ROLE_TYPE_CODE_RAI_ADMIN,
- }
- if utils.InArrayByStr(groupFicc, sysUser.RoleTypeCode) {
- remarkList, err = company.GetRemarkList(companyId, "1")
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- }
- if utils.InArrayByStr(groupRai, sysUser.RoleTypeCode) {
- remarkList, err = company.GetRemarkList(companyId, "2")
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- }
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- remarkList, err = company.GetRemarkListByCompanyId(companyId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- }
- resp := make([]company.RemarkResp, len(remarkList))
- for i, remark := range remarkList {
- createDate := remark.CreateTime.Format(utils.FormatDateTime)
- resp[i].RemarkId = remark.CompanyProductRemarkId
- resp[i].Remark = remark.Remark
- resp[i].ProductName = remark.ProductName
- resp[i].CreateTime = createDate
- // 仅自己添加的可删除
- if remark.SysUserId == sysUser.AdminId {
- resp[i].ButtonDel = true
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // RoadShowList 客户列表的路演详情列表
- // @Title 路演详情列表
- // @Description 路演详情列表
- // @Param CompanyId query string true "客户id"
- // @Success 200 {object} company.RoadShowListResp
- // @router /roadShowList [get]
- func (this *CompanyController) RoadShowList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- companyId := this.GetString("CompanyId")
- companyIdInt, _ := strconv.Atoi(companyId)
- if companyIdInt <= 0 {
- br.Msg = "参数错误"
- return
- }
- var englishCompany int
- if companyIdInt > utils.EnCompanyIdStep {
- companyIdInt = companyIdInt - utils.EnCompanyIdStep
- englishCompany = 1
- }
- var err error
- roadShowList, err := company.GetRoadShowList(companyIdInt, englishCompany)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- //calendarIdSlice := make([]string, 0)
- //for _, v := range roadShowList {
- // calendarIdSlice = append(calendarIdSlice, strconv.Itoa(v.RsCalendarId))
- //}
- //calendarIdStr := strings.Join(calendarIdSlice, ",")
- //researcherList, _ := company.GetRoadShowResearchers(calendarIdStr)
- //roadShowTotalMap := make(map[int]int)
- //for _, roadShowTotal := range researcherList {
- // roadShowTotalMap[roadShowTotal.CompanyId] = roadShowTotal.Total
- //}
- resp := make([]company.RoadShowListResp, len(roadShowList))
- for i, calendar := range roadShowList {
- resp[i].SysUserRealName = calendar.SysUserRealName
- resp[i].RoadshowType = calendar.RoadshowType
- //线上为平台,线下为省市
- if calendar.RoadshowType == "线上" {
- resp[i].RoadshowPlatform = calendar.RoadshowPlatform
- } else {
- resp[i].RoadshowPlatform = calendar.Province + calendar.City
- }
- researchers, err := company.GetRoadShowResearchers(calendar.RsCalendarId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取研究员信息失败"
- br.ErrMsg = "获取研究员信息失败,Err:" + err.Error()
- return
- }
- var researcherList []string
- for _, researcher := range researchers {
- researcherList = append(researcherList, *researcher)
- }
- researcher := strings.Join(researcherList, ",")
- resp[i].Researchers = researcher
- resp[i].RoadShowTime = calendar.EndDate.Format("2006.01.02")
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // CustomerAreaStatistics
- // @Title 客户区域统计
- // @Description 获取客户区域统计接口
- // @Param Date query string true "日期"
- // @Param ProductId query Int true "产品Id"
- // @Success 200 {object} statistic_report.CompanyRenewRecordResp
- // @router /customerAreaStatistics [get]
- func (this *CompanyController) CustomerAreaStatistics() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- date := this.GetString("Date")
- productId, _ := this.GetInt("ProductId", 1)
- //获取列表
- companyAreaDataMapList, _, err := statistic_report.GetAreaDateData(date, productId)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- //获取省市数据
- areaMap := make(map[string]string)
- provinceMap := make(map[string][]string, 0)
- list, err := statisticModels.GetAllCompanyArea()
- for _, item := range list {
- areaMap[item.City] = item.Province
- }
- for c, p := range areaMap {
- citySlice := make([]string, 0)
- citySlice = provinceMap[p]
- citySlice = append(citySlice, c)
- provinceMap[p] = citySlice
- }
- //数据处理
- groupReportRecordList := make([]statistic_report.GroupCityRecord, 0)
- resp := statistic_report.CustomerAreaStatisticsResp{
- List: groupReportRecordList,
- IsAdmin: false,
- }
- //除ficc管理员和超管之外的角色进入此页面时,正式客户数量>0时可点击,点击查看正式客户列表详情;
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- resp.IsAdmin = true
- }
- startDateIndexList := make(map[int]string) //开始时间间隔map
- endDateIndexList := make(map[int]string) //结束时间间隔map
- tmpAllTryOutNumMap := make(map[int]int)
- tmpAllFormalNumMap := make(map[int]int)
- tmpAllActiveNumMap := make(map[int]int)
- tmpAllAllActiveNumMap := make(map[int]int)
- tmpAllNoIncrementalActiveNumMap := make(map[int]int)
- tmpAllTryStagePushMap := make(map[int]int)
- tmpAllTryStageFollowMap := make(map[int]int)
- tmpAllTryStageReadyMap := make(map[int]int)
- tmpAllTryStageInitMap := make(map[int]int)
- for province, cityList := range provinceMap {
- tmpGroupCityReportRecord := make([]statistic_report.CityRecord, 0)
- tmpGroupCompanyReportRecordNumList := make([]statistic_report.CompanyAreaNum, 0)
- tmpGroupTryOutNumMap := make(map[int]int)
- tmpGroupFormalNumMap := make(map[int]int)
- tmpGroupFormalCompanyIdsMap := make(map[int]string) //正式客户id
- tmpGroupActiveNumMap := make(map[int]int)
- tmpGroupAllActiveNumMap := make(map[int]int)
- tmpGroupNoIncrementalActiveNumMap := make(map[int]int)
- // 其他类型客户ID
- tmpGroupTryOutCompanyIdsMap := make(map[int]string) //试用客户ID
- tmpGroupPushCompanyIdsMap := make(map[int]string) //试用(推进)客户ID
- tmpGroupFollowCompanyIdsMap := make(map[int]string) //试用(跟踪)客户ID
- tmpGroupReadyCompanyIdsMap := make(map[int]string) //试用(预备)客户ID
- tmpGroupInitCompanyIdsMap := make(map[int]string) //试用(未分类)客户ID
- tmpGroupTryStagePushMap := make(map[int]int)
- tmpGroupTryStageFollowMap := make(map[int]int)
- tmpGroupTryStageReadyMap := make(map[int]int)
- tmpGroupTryStageInitMap := make(map[int]int)
- for _, city := range cityList {
- //城市数据
- //每个城市的数据
- tmpCompanyReportRecordNumList := make([]statistic_report.CompanyAreaNum, 0)
- for index, adminData := range companyAreaDataMapList {
- startDateIndexList[index] = adminData.StartDate
- endDateIndexList[index] = adminData.EndDate
- var tmpTryOutNum, tmpFormalNum, tmpActiveStatus, tmpAllActiveStatus, tmpNoIncrementalActiveStatus int
- var tmpTryStagePushNum, tmpTryStageFollowNum, tmpTryStageReadyNum, tmpTryStageInitNum int
- var tmpFormalCompanyIds string //正式客户id集合
- var tmpTryOutCompanyIds string //试用客户ID集合
- var tmpPushCompanyIds string //试用(推进)客户ID集合
- var tmpFollowCompanyIds string //试用(跟踪)客户ID集合
- var tmpReadyCompanyIds string //试用(预备)客户ID集合
- var tmpInitCompanyIds string //试用(未分类)客户ID集合
- if num, ok := adminData.TryOutMap[city]; ok {
- tmpTryOutNum = num
- }
- if num, ok := adminData.FormalMap[city]; ok {
- tmpFormalNum = num
- }
- if companyIds, ok := adminData.FormalIdMap[city]; ok {
- tmpFormalCompanyIds = companyIds
- }
- if companyIds, ok := adminData.TryOutIdMap[city]; ok {
- tmpTryOutCompanyIds = companyIds
- }
- if companyIds, ok := adminData.TryStagePushIdsMap[city]; ok {
- tmpPushCompanyIds = companyIds
- }
- if companyIds, ok := adminData.TryStageFollowIdsMap[city]; ok {
- tmpFollowCompanyIds = companyIds
- }
- if companyIds, ok := adminData.TryStageReadyIdsMap[city]; ok {
- tmpReadyCompanyIds = companyIds
- }
- if companyIds, ok := adminData.TryStageInitIdsMap[city]; ok {
- tmpInitCompanyIds = companyIds
- }
- if num, ok := adminData.ActiveMap[city]; ok {
- tmpActiveStatus = num
- }
- if num, ok := adminData.AllActiveMap[city]; ok {
- tmpAllActiveStatus = num
- }
- if num, ok := adminData.NoIncrementalActiveMap[city]; ok {
- tmpNoIncrementalActiveStatus = num
- }
- // 每个用户的试用标签统计 推进-跟踪-预备-未分类
- if num, ok := adminData.TryStagePushNum[city]; ok {
- tmpTryStagePushNum = num
- }
- if num, ok := adminData.TryStageFollowNum[city]; ok {
- tmpTryStageFollowNum = num
- }
- if num, ok := adminData.TryStageReadyNum[city]; ok {
- tmpTryStageReadyNum = num
- }
- if num, ok := adminData.TryStageInitNum[city]; ok {
- tmpTryStageInitNum = num
- }
- tmpAdminRsReportRecordNum := statistic_report.CompanyAreaNum{
- TryOutNum: tmpTryOutNum,
- FormalNum: tmpFormalNum,
- FormalIds: tmpFormalCompanyIds,
- ActiveNum: tmpActiveStatus,
- AllActiveNum: tmpAllActiveStatus,
- NoIncrementalActiveNum: tmpNoIncrementalActiveStatus,
- StartDate: adminData.StartDate,
- EndDate: adminData.EndDate,
- TryStagePushNum: tmpTryStagePushNum,
- TryStageFollowNum: tmpTryStageFollowNum,
- TryStageReadyNum: tmpTryStageReadyNum,
- TryStageInitNum: tmpTryStageInitNum,
- TotalNum: tmpTryOutNum + tmpFormalNum,
- }
- tmpCompanyReportRecordNumList = append(tmpCompanyReportRecordNumList, tmpAdminRsReportRecordNum)
- //组内数据汇总
- tmpGroupTryOutNumMap[index] += tmpTryOutNum
- tmpGroupFormalNumMap[index] += tmpFormalNum
- // 正式客户id
- if tmpFormalCompanyIds != `` {
- tmpGroupFormalCompanyIds, ok := tmpGroupFormalCompanyIdsMap[index]
- if ok {
- tmpGroupFormalCompanyIdsMap[index] = tmpGroupFormalCompanyIds + "," + tmpFormalCompanyIds
- } else {
- tmpGroupFormalCompanyIdsMap[index] = tmpFormalCompanyIds
- }
- }
- tmpGroupActiveNumMap[index] += tmpActiveStatus
- tmpGroupAllActiveNumMap[index] += tmpActiveStatus
- tmpGroupNoIncrementalActiveNumMap[index] += tmpActiveStatus
- tmpGroupTryStagePushMap[index] += tmpTryStagePushNum
- tmpGroupTryStageFollowMap[index] += tmpTryStageFollowNum
- tmpGroupTryStageReadyMap[index] += tmpTryStageReadyNum
- tmpGroupTryStageInitMap[index] += tmpTryStageInitNum
- // 其他客户IDs
- if tmpTryOutCompanyIds != `` {
- a, ok := tmpGroupTryOutCompanyIdsMap[index]
- if ok {
- tmpGroupTryOutCompanyIdsMap[index] = a + "," + tmpTryOutCompanyIds
- } else {
- tmpGroupTryOutCompanyIdsMap[index] = tmpTryOutCompanyIds
- }
- }
- if tmpPushCompanyIds != `` {
- a, ok := tmpGroupPushCompanyIdsMap[index]
- if ok {
- tmpGroupPushCompanyIdsMap[index] = a + "," + tmpPushCompanyIds
- } else {
- tmpGroupPushCompanyIdsMap[index] = tmpPushCompanyIds
- }
- }
- if tmpFollowCompanyIds != `` {
- a, ok := tmpGroupFollowCompanyIdsMap[index]
- if ok {
- tmpGroupFollowCompanyIdsMap[index] = a + "," + tmpFollowCompanyIds
- } else {
- tmpGroupFollowCompanyIdsMap[index] = tmpFollowCompanyIds
- }
- }
- if tmpReadyCompanyIds != `` {
- a, ok := tmpGroupReadyCompanyIdsMap[index]
- if ok {
- tmpGroupReadyCompanyIdsMap[index] = a + "," + tmpReadyCompanyIds
- } else {
- tmpGroupReadyCompanyIdsMap[index] = tmpReadyCompanyIds
- }
- }
- if tmpInitCompanyIds != `` {
- a, ok := tmpGroupInitCompanyIdsMap[index]
- if ok {
- tmpGroupInitCompanyIdsMap[index] = a + "," + tmpInitCompanyIds
- } else {
- tmpGroupInitCompanyIdsMap[index] = tmpInitCompanyIds
- }
- }
- //总数据汇总
- tmpAllTryOutNumMap[index] += tmpTryOutNum
- tmpAllFormalNumMap[index] += tmpFormalNum
- tmpAllActiveNumMap[index] += tmpActiveStatus
- tmpAllAllActiveNumMap[index] += tmpAllActiveStatus
- tmpAllNoIncrementalActiveNumMap[index] += tmpNoIncrementalActiveStatus
- // 总数据试用标签数据汇总
- tmpAllTryStagePushMap[index] += tmpTryStagePushNum
- tmpAllTryStageFollowMap[index] += tmpTryStageFollowNum
- tmpAllTryStageReadyMap[index] += tmpTryStageReadyNum
- tmpAllTryStageInitMap[index] += tmpTryStageInitNum
- }
- tmpAdminReportRecord := statistic_report.CityRecord{
- Name: city,
- CompanyAreaNumNumList: tmpCompanyReportRecordNumList,
- }
- tmpGroupCityReportRecord = append(tmpGroupCityReportRecord, tmpAdminReportRecord)
- }
- for i := 0; i < len(tmpGroupActiveNumMap); i++ {
- tmpGroupCompanyReportRecordNum := statistic_report.CompanyAreaNum{
- TryOutNum: tmpGroupTryOutNumMap[i],
- FormalNum: tmpGroupFormalNumMap[i],
- FormalIds: tmpGroupFormalCompanyIdsMap[i],
- ActiveNum: tmpGroupActiveNumMap[i],
- AllActiveNum: tmpGroupAllActiveNumMap[i],
- NoIncrementalActiveNum: tmpGroupNoIncrementalActiveNumMap[i],
- StartDate: startDateIndexList[i],
- EndDate: endDateIndexList[i],
- TryStagePushNum: tmpGroupTryStagePushMap[i],
- TryStageFollowNum: tmpGroupTryStageFollowMap[i],
- TryStageReadyNum: tmpGroupTryStageReadyMap[i],
- TryStageInitNum: tmpGroupTryStageInitMap[i],
- TotalNum: tmpGroupTryOutNumMap[i] + tmpGroupFormalNumMap[i],
- TryOutIds: tmpGroupTryOutCompanyIdsMap[i],
- TryStagePushIds: tmpGroupPushCompanyIdsMap[i],
- TryStageFollowIds: tmpGroupFollowCompanyIdsMap[i],
- TryStageReadyIds: tmpGroupReadyCompanyIdsMap[i],
- TryStageInitIds: tmpGroupInitCompanyIdsMap[i],
- }
- tmpGroupCompanyReportRecordNumList = append(tmpGroupCompanyReportRecordNumList, tmpGroupCompanyReportRecordNum)
- }
- groupReportRecord := statistic_report.GroupCityRecord{
- Item: tmpGroupCityReportRecord,
- Name: province,
- CompanyAreaNumNumList: tmpGroupCompanyReportRecordNumList,
- }
- groupReportRecordList = append(groupReportRecordList, groupReportRecord)
- }
- resp.List = groupReportRecordList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // CompanyTryOutDayList
- // @Title 客户累计试用详情接口
- // @Description 客户累计试用详情接口
- // @Param CompanyId query int true "客户id"
- // @Param ProductId query int true "产品id"
- // @Success 200 {object} company.CompanyTryOutDayListResp
- // @router /company/tryOutDayList [get]
- func (this *CompanyTodoController) CompanyTryOutDayList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- companyId, _ := this.GetInt("CompanyId")
- if companyId <= 0 {
- br.Msg = "请选择客户"
- return
- }
- productId, _ := this.GetInt("ProductId")
- if productId <= 0 {
- br.Msg = "请选择类型"
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- // 获取任务信息
- total, err := company.GetCompanyProductTryOutUpdateLogTotal(companyId, productId)
- if err != nil {
- br.Msg = "获取任务信息失败"
- br.ErrMsg = "获取任务信息失败,err:" + err.Error()
- return
- }
- // 获取任务信息
- list, err := company.GetCompanyProductTryOutUpdateLogList(companyId, productId, startSize, pageSize)
- if err != nil {
- br.Msg = "获取任务信息失败"
- br.ErrMsg = "获取任务信息失败,err:" + err.Error()
- return
- }
- //var list []*company_todo.CompanyTodoListItem
- //for _, v := range todos {
- // temp := &company_todo.CompanyTodoListItem{
- // CompanyTodo: v,
- // }
- // temp.EndTimeStr = temp.EndTime.Format(utils.FormatDate)
- // if temp.EndTimeStr == "0001-01-01" {
- // temp.EndTimeStr = ""
- // }
- // list = append(list, temp)
- //}
- if len(list) <= 0 {
- list = make([]*company.CompanyProductTryOutUpdateLog, 0)
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := company.CompanyTryOutDayListResp{
- Paging: page,
- List: list,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 获取流水信息接口
- // @Description 获取流水信息接口
- // @Param CompanyId query int true "客户id"
- // @Success 200 {object} company.CygxActivityPointsBillListResp
- // @router /company/activity/points/bill [get]
- func (this *CompanyTodoController) CompanyActivityPointsBill() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- companyId, _ := this.GetInt("CompanyId")
- if companyId <= 0 {
- br.Msg = "请选择客户"
- return
- }
- // 获取流水信息
- list, err := cygx.CygxActivityPointsBillByCompanyId(companyId)
- if err != nil {
- br.Msg = "获取任务信息失败"
- br.ErrMsg = "获取任务信息失败,err:" + err.Error()
- return
- }
- if len(list) <= 0 {
- list = make([]*cygx.CygxActivityPointsBillResp, 0)
- }
- resp := cygx.CygxActivityPointsBillListResp{
- List: list,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // DelRemark
- // @Title 删除备注
- // @Description 删除备注
- // @Param request body company.RemarkDelReq true "type json string"
- // @Success 200 操作成功
- // @router /remark/del [post]
- func (this *CompanyController) DelRemark() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req company.RemarkDelReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.RemarkId <= 0 {
- br.Msg = "参数有误"
- br.ErrMsg = "参数有误, 备注ID有误"
- return
- }
- item, e := company.GetCompanyRemarkById(req.RemarkId)
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "备注已被删除, 请刷新页面"
- return
- }
- br.Msg = "备注信息有误"
- br.ErrMsg = "获取客户备注失败, Err: " + e.Error()
- return
- }
- if item.SysUserId != sysUser.AdminId {
- br.Msg = "仅备注添加人可删除"
- return
- }
- product, e := company.GetCompanyProductByCompanyIdAndProductId(item.CompanyId, item.ProductId)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取客户产品信息失败, Err: " + e.Error()
- return
- }
- if e := company.DelCompanyRemark(req.RemarkId); e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "删除客户备注失败, Err: " + e.Error()
- return
- }
- content := fmt.Sprintf("%s%s", "删除备注: ", item.Remark)
- _ = services.AddCompanyOperationRecord(product.CompanyId, product.SellerId, sysUser.AdminId, product.ProductId, sysUser.AdminId, product.CompanyName, product.ProductName, sysUser.RealName, "删除备注", "del_remark", content, sysUser.RealName, "", product.Status)
- if item.ProductId == utils.COMPANY_PRODUCT_RAI_ID {
- go services.DelCompanyHistoryRemark("company_product_remark", req.RemarkId) // 删除
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // @Title 获取流水信息接口
- // @Description 获取流水信息接口
- // @Param CompanyId query int true "客户id"
- // @Success 200 {object} company.CygxActivityPointsBillListResp
- // @router /company/activity/special/points/bill [get]
- func (this *CompanyTodoController) CompanyActivitySpecialPointsBill() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- companyId, _ := this.GetInt("CompanyId")
- if companyId <= 0 {
- br.Msg = "请选择客户"
- return
- }
- // 获取流水信息
- var condition string
- var pars []interface{}
- condition += ` AND company_id = ? `
- pars = append(pars, companyId)
- //查询当年的数据
- //condition += ` AND b.create_time >= ? `
- //pars = append(pars, time.Now().Format(utils.FormatYearDate)+"-01-01")
- list, err := cygx.GetCygxActivitySpecialTripBillDetailListAll(condition, pars)
- if err != nil {
- br.Msg = "获取任务信息失败"
- br.ErrMsg = "获取任务信息失败,err:" + err.Error()
- return
- }
- //userType, tripRemaining, mapChartName, err := cygxService.GetChartPermissionSpecialSurplusByCompany(companyId)
- //if err != nil {
- // br.Msg = "获取专项调研剩余次数失败"
- // br.ErrMsg = "获取专项调研剩余次数失败,err:" + err.Error()
- // return
- //}
- //chartMap := map[int]string{utils.YI_YAO_ID: utils.YI_YAO_NAME, utils.XIAO_FEI_ID: utils.XIAO_FEI_NAME, utils.KE_JI_ID: utils.KE_JI_NAME, utils.ZHI_ZAO_ID: utils.ZHI_ZAO_NAME}
- resp := new(cygx.CygxActivitySpecialPointsBillResp)
- //lastTripRemaining := 0
- for _, v := range list {
- item := cygx.CygxActivitySpecialPointsBillRespItem{
- Id: v.Id,
- CreateTime: v.CreateTime.Format(utils.FormatDateTime),
- CompanyId: v.CompanyId,
- CompanyName: v.CompanyName,
- RealName: v.RealName,
- BillDetailed: v.BillDetailed,
- ActivityName: v.ResearchTheme,
- ChartPermissionId: v.ChartPermissionId,
- ChartPermissionName: v.ChartPermissionName,
- Total: v.Total,
- }
- if v.ActivityId == 0 {
- item.Content = v.Content
- } else {
- if v.DoType == 1 && v.Way != 4 && v.Way != 3 {
- item.Content = item.ActivityName + "--报名"
- } else if v.DoType == 2 && v.Way != 4 && v.Way != 3 {
- item.Content = item.ActivityName + "--取消报名"
- } else if v.Way == 4 {
- item.Content = item.ActivityName + "--活动取消"
- }
- }
- //if userType == 2 {
- // if i== 0 {
- // item.Total += strconv.Itoa(tripRemaining) + "次"
- // } else {
- // item.Total += strconv.Itoa(tripRemaining-list[i-1].BillDetailed) + "次"
- // }
- // //if v.BillDetailed < 4 {
- // // item.Total += strconv.Itoa(lastTripRemaining-list[i-1].BillDetailed) + "次"
- // //} else {
- // // item.Total += strconv.Itoa(lastTripRemaining) + "次"
- // //}
- //} else {
- // for k, num := range mapChartName {
- // if i== 0 {
- // item.Total += k + strconv.Itoa(num) + "次+"
- // } else {
- // if list[i-1].ActivityId == 0 {
- // item.Total += k + strconv.Itoa(num) + "次+"
- // } else {
- // item.Total += k + strconv.Itoa(num-list[i-1].BillDetailed) + "次+"
- // }
- // }
- // //if num > 0 {
- // // if i== 0{
- // // item.Total += k + strconv.Itoa(num) + "次+"
- // // } else {
- // // item.Total += k + strconv.Itoa(num-v.BillDetailed) + "次+"
- // // }
- // //}
- // }
- // item.Total = strings.TrimRight(item.Total, "+")
- //}
- resp.List = append(resp.List, &item)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|