company.go 318 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "github.com/tealeg/xlsx"
  7. "hongze/hz_crm_api/cache"
  8. "hongze/hz_crm_api/models"
  9. "hongze/hz_crm_api/models/advisory"
  10. "hongze/hz_crm_api/models/company"
  11. "hongze/hz_crm_api/models/company_report_permission_log"
  12. "hongze/hz_crm_api/models/company_todo"
  13. "hongze/hz_crm_api/models/company_user"
  14. "hongze/hz_crm_api/models/cygx"
  15. "hongze/hz_crm_api/models/response"
  16. statisticModels "hongze/hz_crm_api/models/statistic_report"
  17. "hongze/hz_crm_api/models/system"
  18. "hongze/hz_crm_api/services"
  19. "hongze/hz_crm_api/services/alarm_msg"
  20. cygxService "hongze/hz_crm_api/services/cygx"
  21. "hongze/hz_crm_api/services/statistic_report"
  22. "hongze/hz_crm_api/utils"
  23. "os"
  24. "path/filepath"
  25. "strconv"
  26. "strings"
  27. "time"
  28. )
  29. // 客户管理
  30. type CompanyController struct {
  31. BaseAuthController
  32. }
  33. // @Title 客户检索列表
  34. // @Description 客户检索列表接口
  35. // @Param KeyWord query string true "搜索关键词"
  36. // @Param PageSize query int true "每页数据条数"
  37. // @Param CurrentIndex query int true "当前页页码,从1开始"
  38. // @Success 200 {object} company.CompanySearchListResp
  39. // @router /search/list [get]
  40. func (this *CompanyController) SearchList() {
  41. br := new(models.BaseResponse).Init()
  42. defer func() {
  43. this.Data["json"] = br
  44. this.ServeJSON()
  45. }()
  46. sysUser := this.SysUser
  47. if sysUser == nil {
  48. br.Msg = "请登录"
  49. br.ErrMsg = "请登录,SysUser Is Empty"
  50. br.Ret = 408
  51. return
  52. }
  53. pageSize, _ := this.GetInt("PageSize")
  54. currentIndex, _ := this.GetInt("CurrentIndex")
  55. var startSize int
  56. if pageSize <= 0 {
  57. pageSize = utils.PageSize20
  58. }
  59. if currentIndex <= 0 {
  60. currentIndex = 1
  61. }
  62. startSize = paging.StartIndex(currentIndex, pageSize)
  63. roleTypeCode := sysUser.RoleTypeCode
  64. keyWord := this.GetString("KeyWord")
  65. keyWord = strings.Trim(keyWord, " ")
  66. keyWord = strings.Replace(keyWord, "'", "", -1)
  67. resp := new(company.CompanySearchListResp)
  68. var condition string
  69. var pars []interface{}
  70. //需要忽略的关键字
  71. ignoreStrs := []string{"", "有限", "投资", "资本", "管理", "贸易", "资产", "公司", "股份", "集团", "有限公司"}
  72. if strings.Contains(strings.Join(ignoreStrs, ","), keyWord) {
  73. list := make([]*company.CompanySearchItem, 0)
  74. resp.List = list
  75. br.Ret = 200
  76. br.Success = true
  77. br.Msg = "获取成功"
  78. br.Data = resp
  79. return
  80. }
  81. //正常筛选逻辑
  82. companyIdStr, err := company.GetCompanyIdByKeyWordAll(keyWord)
  83. if err != nil {
  84. br.Msg = "获取失败"
  85. br.ErrMsg = "获取失败,Err:" + err.Error()
  86. return
  87. }
  88. companyIdStr = strings.Trim(companyIdStr, ",")
  89. if companyIdStr != "" {
  90. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  91. } else {
  92. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.credit_code LIKE '%` + keyWord + `%')`
  93. //pars = append(pars, keyWord)
  94. //pars = append(pars, keyWord)
  95. }
  96. total, err := company.GetCompanySearchCount(condition, pars)
  97. if err != nil {
  98. br.Msg = "获取失败"
  99. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  100. return
  101. }
  102. list, err := company.GetCompanySearchList(condition, pars, startSize, pageSize)
  103. if err != nil && err.Error() != utils.ErrNoRow() {
  104. br.Msg = "获取失败"
  105. br.ErrMsg = "获取失败,Err:" + err.Error()
  106. return
  107. }
  108. // 查询当前销售是否有领取客户的权限
  109. receiveEnabled, _ := services.CheckCompanyReceiveButton(sysUser.AdminId)
  110. // 白嫖客户标记
  111. scroungeList, err := company.GetScroungeCompany()
  112. if err != nil {
  113. br.Msg = "获取失败"
  114. br.ErrMsg = "获取白嫖客户信息失败,Err:" + err.Error()
  115. return
  116. }
  117. scroungeMap := make(map[int]int)
  118. for _, v := range scroungeList {
  119. scroungeMap[v.CompanyId] = 1
  120. }
  121. /*
  122. 时长根据客户状态定义,
  123. 若为冻结客户或者流失客户,则展示冻结时长或流失时长;
  124. 若为正式或试用客户,展示到期时长;
  125. */
  126. lenList := len(list)
  127. for i := 0; i < lenList; i++ {
  128. duration := ""
  129. item := list[i]
  130. itemStatus := item.Status
  131. //白嫖客户标记
  132. if _, ok := scroungeMap[item.CompanyId]; ok {
  133. item.IsScrounge = 1
  134. }
  135. if !strings.Contains(item.Status, "/") {
  136. if item.Status == utils.COMPANY_STATUS_FREEZE {
  137. if item.FreezeEndDate != "" {
  138. freeZeTime, _ := time.Parse(utils.FormatDate, item.FreezeEndDate)
  139. freeZeTime = freeZeTime.AddDate(0, 0, 1)
  140. sub := freeZeTime.Sub(time.Now())
  141. if sub < 0 {
  142. sub = 0
  143. }
  144. duration = fmt.Sprintf("%v", int(sub.Hours()/24))
  145. }
  146. } else if item.Status == utils.COMPANY_STATUS_LOSE {
  147. if item.LossTime != "" {
  148. lossTime, err := time.Parse(utils.FormatDateTime, item.LossTime)
  149. if err != nil {
  150. fmt.Println("err:" + err.Error())
  151. }
  152. lossTime = lossTime.AddDate(0, 0, 1)
  153. sub := time.Now().Sub(lossTime)
  154. if sub < 0 {
  155. sub = 0
  156. }
  157. duration = fmt.Sprintf("%v", int(sub.Hours()/24))
  158. }
  159. } else if item.Status == utils.COMPANY_STATUS_FORMAL ||
  160. item.Status == utils.COMPANY_STATUS_TRY_OUT {
  161. if item.EndDate != "" {
  162. endDate, _ := time.Parse(utils.FormatDate, item.EndDate)
  163. endDate = endDate.AddDate(0, 0, 1)
  164. sub := endDate.Sub(time.Now())
  165. if sub < 0 {
  166. sub = 0
  167. }
  168. duration = fmt.Sprintf("%v", int(sub.Hours()/24))
  169. }
  170. } else if item.Status == utils.COMPANY_STATUS_TRY_OUT {
  171. duration = "永续"
  172. } else {
  173. duration = "-"
  174. }
  175. } else {
  176. statusArr := strings.Split(item.Status, "/")
  177. //freezeArr := strings.Split(item.FreezeTime, "/") //0:ficc,1:权益
  178. freezeArr := strings.Split(item.FreezeEndDate, "/") //冻结结束日期:0:ficc,1:权益
  179. lossArr := strings.Split(item.LossTime, "/") //0:ficc,1:权益
  180. endDateArr := strings.Split(item.EndDate, "/")
  181. var ficcFreeze, tryFreeze string
  182. var ficcLoss, tryLoss string
  183. var ficcEndDate, tryEndDate string
  184. ficcStatus := statusArr[0]
  185. tryOutStatus := statusArr[1]
  186. //if len(freezeArr) > 1 {
  187. // ficcFreeze = freezeArr[0]
  188. // tryFreeze = freezeArr[1]
  189. //}
  190. //if len(lossArr) > 1 {
  191. // ficcLoss = lossArr[0]
  192. // tryLoss = lossArr[1]
  193. //}
  194. //结束日期
  195. if len(endDateArr) > 1 {
  196. ficcEndDate = endDateArr[0]
  197. tryEndDate = endDateArr[1]
  198. }
  199. //冻结
  200. if ficcStatus == utils.COMPANY_STATUS_FREEZE && len(freezeArr) > 0 {
  201. //ficc
  202. ficcFreeze = freezeArr[0]
  203. }
  204. if tryOutStatus == utils.COMPANY_STATUS_FREEZE && len(freezeArr) > 0 {
  205. //权益
  206. if len(freezeArr) == 1 {
  207. tryFreeze = freezeArr[0]
  208. } else {
  209. tryFreeze = freezeArr[1]
  210. }
  211. }
  212. //流失
  213. if ficcStatus == utils.COMPANY_STATUS_LOSE && len(lossArr) > 0 {
  214. //ficc
  215. ficcLoss = lossArr[0]
  216. }
  217. if tryOutStatus == utils.COMPANY_STATUS_LOSE && len(lossArr) > 0 {
  218. //权益
  219. if len(lossArr) == 1 {
  220. tryLoss = lossArr[0]
  221. } else {
  222. tryLoss = lossArr[1]
  223. }
  224. }
  225. //ficc的判断
  226. switch ficcStatus {
  227. case utils.COMPANY_STATUS_FREEZE: //冻结
  228. if ficcFreeze != "" {
  229. ficcFreeZeTime, _ := time.Parse(utils.FormatDate, ficcFreeze)
  230. ficcFreeZeTime = ficcFreeZeTime.AddDate(0, 0, 1)
  231. sub := ficcFreeZeTime.Sub(time.Now())
  232. if sub < 0 {
  233. sub = 0
  234. }
  235. duration = fmt.Sprintf("%v", int(sub.Hours()/24))
  236. }
  237. case utils.COMPANY_STATUS_LOSE: //流失
  238. if ficcLoss != "" {
  239. ficcLossTime, _ := time.Parse(utils.FormatDateTime, ficcLoss)
  240. ficcLossTime = ficcLossTime.AddDate(0, 0, 1)
  241. sub := time.Now().Sub(ficcLossTime)
  242. if sub < 0 {
  243. sub = 0
  244. }
  245. duration = fmt.Sprintf("%v", int(sub.Hours()/24))
  246. }
  247. case utils.COMPANY_STATUS_FORMAL, utils.COMPANY_STATUS_TRY_OUT:
  248. if ficcEndDate != "" {
  249. ficcEndDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
  250. ficcEndDateTime = ficcEndDateTime.AddDate(0, 0, 1)
  251. sub := ficcEndDateTime.Sub(time.Now())
  252. if sub < 0 {
  253. sub = 0
  254. }
  255. duration = fmt.Sprintf("%v", int(sub.Hours()/24))
  256. }
  257. case utils.COMPANY_STATUS_FOREVER:
  258. duration = "永续"
  259. case utils.COMPANY_STATUS_CLOSE:
  260. duration = "-"
  261. }
  262. //权益的判断
  263. switch tryOutStatus {
  264. case utils.COMPANY_STATUS_FREEZE: //冻结
  265. if tryFreeze != "" {
  266. tryOutFreeZeTime, _ := time.Parse(utils.FormatDate, tryFreeze)
  267. tryOutFreeZeTime = tryOutFreeZeTime.AddDate(0, 0, 1)
  268. sub := tryOutFreeZeTime.Sub(time.Now())
  269. if sub < 0 {
  270. sub = 0
  271. }
  272. if duration != "" {
  273. duration = duration + "/" + fmt.Sprintf("%v", int(sub.Hours()/24))
  274. }
  275. }
  276. case utils.COMPANY_STATUS_LOSE: //流失
  277. if tryLoss != "" {
  278. tryOutLossTime, _ := time.Parse(utils.FormatDateTime, tryLoss)
  279. tryOutLossTime = tryOutLossTime.AddDate(0, 0, 1)
  280. sub := time.Now().Sub(tryOutLossTime)
  281. if sub < 0 {
  282. sub = 0
  283. }
  284. if duration != "" {
  285. duration = duration + "/" + fmt.Sprintf("%v", int(sub.Hours()/24))
  286. }
  287. }
  288. case utils.COMPANY_STATUS_FORMAL, utils.COMPANY_STATUS_TRY_OUT:
  289. if tryEndDate != "" {
  290. tryEndDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
  291. tryEndDateTime = tryEndDateTime.AddDate(0, 0, 1)
  292. sub := tryEndDateTime.Sub(time.Now())
  293. if sub < 0 {
  294. sub = 0
  295. }
  296. if duration != "" {
  297. duration = duration + "/" + fmt.Sprintf("%v", int(sub.Hours()/24))
  298. }
  299. }
  300. case utils.COMPANY_STATUS_FOREVER:
  301. if duration != "" {
  302. duration = duration + "/" + "永续"
  303. }
  304. case utils.COMPANY_STATUS_CLOSE:
  305. duration = "-"
  306. }
  307. //list[i].ApproveStatus = ""
  308. }
  309. approveStatusMap := make(map[int]string)
  310. if item.ProductId == 1 {
  311. approveStatusMap[1] = item.ApproveStatus
  312. } else if item.ProductId == 2 {
  313. approveStatusMap[2] = item.ApproveStatus
  314. }
  315. if strings.Contains(item.ApproveStatus, "/") {
  316. approveStatusSlice := strings.Split(item.ApproveStatus, "/")
  317. approveStatusMap[1] = approveStatusSlice[0]
  318. approveStatusMap[2] = approveStatusSlice[1]
  319. } else {
  320. approveStatusMap[1] = item.ApproveStatus
  321. approveStatusMap[2] = item.ApproveStatus
  322. }
  323. productIdMap := make(map[int]int)
  324. if strings.Contains(item.ProductIds, "/") {
  325. productIdSlice := strings.Split(item.ProductIds, "/")
  326. productIdMap[1], _ = strconv.Atoi(productIdSlice[0])
  327. productIdMap[2], _ = strconv.Atoi(productIdSlice[1])
  328. }
  329. if strings.Contains(item.ApproveStatus, "/") {
  330. approveStatusSlice := strings.Split(item.ApproveStatus, "/")
  331. approveStatusMap[1] = approveStatusSlice[0]
  332. approveStatusMap[2] = approveStatusSlice[1]
  333. for k, v := range productIdMap {
  334. approveStatusMap[v] = approveStatusSlice[k-1]
  335. }
  336. } else {
  337. for _, v := range productIdMap {
  338. approveStatusMap[v] = item.ApproveStatus
  339. }
  340. }
  341. sysProductId := services.GetProductId(sysUser.RoleTypeCode)
  342. if sysProductId > 0 {
  343. list[i].ApproveStatus = approveStatusMap[sysProductId]
  344. }
  345. list[i].Duration = duration
  346. //按钮显示控制
  347. /*btnItem := services.GetCompanySearchPermissionButton(roleTypeCode, itemStatus, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId)
  348. list[i].BtnItem = &btnItem*/
  349. btnItem := new(company.ButtonPermission)
  350. if item.CompanyId != 1 {
  351. *btnItem = services.GetCompanyPermissionButton(roleTypeCode, itemStatus, item.SellerIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, -1, item.ShareSellerIds)
  352. //根据销售"领取客户"的权限对部分按钮做限制
  353. btnItem = services.GetCompanyPermissionButtonByReceiveEnabled(btnItem, receiveEnabled)
  354. }
  355. if list[i].IsShare == 1 && btnItem.BtnModifySeller == true && roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  356. //如果已经是共享客户了,取消共享按钮全都显示,和修改销售权限一样
  357. btnItem.BtnShare = true
  358. }
  359. // 客户搜索页不要共享客户按钮
  360. btnItem.BtnShare = false
  361. //如果是权益客户,操作者又是权益管理员,那么就对他进行展示研选详情按钮
  362. if strings.Contains(item.CompanyType, utils.COMPANY_CLASSIFY_RAI) && sysUser.RoleName == utils.ROLE_TYPE_RAI_PRODUCT {
  363. btnItem.IsResearchShow = true
  364. }
  365. list[i].BtnItem = btnItem
  366. }
  367. for _, v := range list {
  368. v.Status = strings.Replace(v.Status, utils.COMPANY_STATUS_FOREVER, utils.COMPANY_STATUS_X_CLASS_TRY_OUT, -1) // 永续客户类型,映射成 X类试用
  369. v.Duration = strings.Replace(v.Duration, utils.COMPANY_STATUS_FOREVER, utils.COMPANY_STATUS_X_CLASS_TRY_OUT, -1) // 永续客户类型,映射成 X类试用
  370. }
  371. if list == nil {
  372. list = make([]*company.CompanySearchItem, 0)
  373. }
  374. resp.List = list
  375. page := paging.GetPaging(currentIndex, pageSize, total)
  376. resp.Paging = page
  377. br.Ret = 200
  378. br.Success = true
  379. br.Msg = "获取成功"
  380. br.Data = resp
  381. }
  382. // List
  383. // @Title 客户列表
  384. // @Description 客户列表接口
  385. // @Param PageSize query int true "每页数据条数"
  386. // @Param CurrentIndex query int true "当前页页码,从1开始"
  387. // @Param Status query string true "状态:'试用','永续','冻结','流失','正式'"
  388. // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
  389. // @Param IndustryId query int true "行业id,0为全部"
  390. // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
  391. // @Param ChartPermissionIds query string false "阅读权限品种ID,多个用英文逗号分开,空字符串为全部"
  392. // @Param ContractPermissionIds query string false "已购品种ID,多个用英文逗号分开,空字符串为全部"
  393. // @Param StartDate query string true "开始时间"
  394. // @Param EndDate query string true "结束时间"
  395. // @Param CreateStartDate query string true "创建开始时间"
  396. // @Param CreateEndDate query string true "创建结束时间"
  397. // @Param KeyWord query string true "搜索关键词"
  398. // @Param Address query string true "地址 , 多个用英文逗号分开 "
  399. // @Param Province query string true "省 , 多个用英文逗号分开 "
  400. // @Param City query string true "市 , 多个用英文逗号分开 "
  401. // @Param PackageType query int true "套餐类型,0:无,1:大套餐,2:小套餐"
  402. // @Param TodoStatus query string true "任务处理状态;枚举值:'无任务','未完成','已完成'"
  403. // @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:'viewTotal':总阅读次数 、 'viewTime':阅读时间 、 'roadShowTotal':累计路演次数 、`expireDay:到期时间` 、 `createTime:创建时间` 、 'formalTime': 转正时间 、 'freezeTime':冻结时间 、'lossTime':流失时间 、'tryStage':试用标签 、'deadline':距离未完成的任务的截止日期的天数、'tryOutDay':试用天数"
  404. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  405. // @Param SortByTodo query bool true "是否根据待办排序,true或false"
  406. // @Param TryStage query int false "试用客户子标签:0全部、1未分类、2 推进、3 跟踪、4 预备"
  407. // @Param IncludeShare query bool true "是否包含共享客户: true-包含; false-不包含"
  408. // @Success 200 {object} company.CompanyListResp
  409. // @router /list [get]
  410. func (this *CompanyController) List() {
  411. br := new(models.BaseResponse).Init()
  412. defer func() {
  413. this.Data["json"] = br
  414. this.ServeJSON()
  415. }()
  416. sysUser := this.SysUser
  417. if sysUser == nil {
  418. br.Msg = "请登录"
  419. br.ErrMsg = "请登录,SysUser Is Empty"
  420. br.Ret = 408
  421. return
  422. }
  423. roleTypeCode := sysUser.RoleTypeCode
  424. pageSize, _ := this.GetInt("PageSize")
  425. currentIndex, _ := this.GetInt("CurrentIndex")
  426. status := this.GetString("Status")
  427. companyType := this.GetString("CompanyType")
  428. industryId, _ := this.GetInt("IndustryId")
  429. adminId := this.GetString("AdminId")
  430. chartPermissionIds := this.GetString("ChartPermissionIds")
  431. contractPermissionIds := this.GetString("ContractPermissionIds")
  432. startDate := this.GetString("StartDate")
  433. endDate := this.GetString("EndDate")
  434. createStartDate := this.GetString("CreateStartDate")
  435. createEndDate := this.GetString("CreateEndDate")
  436. keyWord := this.GetString("KeyWord")
  437. address := this.GetString("Address")
  438. province := this.GetString("Province")
  439. city := this.GetString("City")
  440. regionType := this.GetString("RegionType")
  441. keyWord = strings.Trim(keyWord, " ")
  442. keyWord = strings.Replace(keyWord, "'", "", -1)
  443. todoStatus := this.GetString("TodoStatus") //任务状态
  444. tryStage, _ := this.GetInt("TryStage") //试用客户标签
  445. includeShare, _ := this.GetBool("IncludeShare") // 是否包含试用客户
  446. // 套餐类型
  447. packageType, _ := this.GetInt("PackageType")
  448. //排序参数
  449. sortParam := this.GetString("SortParam")
  450. sortType := this.GetString("SortType")
  451. sortByTodo, _ := this.GetBool("SortByTodo")
  452. productId := services.GetProductId(roleTypeCode)
  453. var total int
  454. page := paging.GetPaging(currentIndex, pageSize, total)
  455. resp := new(company.CompanyListResp)
  456. statusItems := make([]*company.CompanyStatus, 0)
  457. // 永续客户类型,映射成 X类试用
  458. if status == utils.COMPANY_STATUS_X_CLASS_TRY_OUT {
  459. status = utils.COMPANY_STATUS_FOREVER
  460. }
  461. var statusArr []string
  462. // 对权益用户隐藏关闭
  463. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  464. statusArr = []string{"全部", "试用", "正式", "冻结", "流失", utils.COMPANY_STATUS_X_CLASS_TRY_OUT}
  465. } else {
  466. statusArr = []string{"全部", "试用", "正式", "冻结", "流失", utils.COMPANY_STATUS_CLOSE, utils.COMPANY_STATUS_X_CLASS_TRY_OUT}
  467. }
  468. //var statusArr = [...]string{"全部", "试用-活跃", "试用-非活跃", "正式", "冻结", "流失", "永续"}
  469. var startSize int
  470. if pageSize <= 0 {
  471. pageSize = utils.PageSize20
  472. }
  473. if currentIndex <= 0 {
  474. currentIndex = 1
  475. }
  476. startSize = paging.StartIndex(currentIndex, pageSize)
  477. var condition string
  478. var pars []interface{}
  479. //流失
  480. var lossCondition string
  481. var lossPars []interface{}
  482. //状态分类查询条件
  483. var permissionCondition string
  484. var permissionPars []interface{}
  485. if companyType != "" {
  486. condition += ` AND b.product_name=? `
  487. pars = append(pars, companyType)
  488. }
  489. if industryId > 0 {
  490. condition += ` AND b.industry_id=? `
  491. pars = append(pars, industryId)
  492. }
  493. if adminId != "" {
  494. condition += ` AND b.seller_id IN (` + adminId + `) `
  495. }
  496. if startDate != "" {
  497. condition += ` AND b.start_date>=? `
  498. pars = append(pars, startDate)
  499. }
  500. if endDate != "" {
  501. condition += ` AND b.end_date<=? `
  502. pars = append(pars, endDate)
  503. }
  504. if createStartDate != "" {
  505. condition += ` AND a.created_time>=? `
  506. pars = append(pars, createStartDate)
  507. }
  508. if createEndDate != "" {
  509. condition += ` AND a.created_time<=? `
  510. pars = append(pars, createEndDate)
  511. }
  512. if address != "" {
  513. var addressSql string
  514. slice := strings.Split(address, ",")
  515. for _, v := range slice {
  516. addressSql += "'" + v + "'" + ","
  517. }
  518. addressSql = strings.TrimRight(addressSql, ",")
  519. condition += ` AND a.address IN (` + addressSql + `) `
  520. }
  521. if province != "" {
  522. var provinceSql string
  523. slice := strings.Split(province, ",")
  524. for _, v := range slice {
  525. provinceSql += "'" + v + "'" + ","
  526. }
  527. provinceSql = strings.TrimRight(provinceSql, ",")
  528. condition += ` AND a.province IN (` + provinceSql + `) `
  529. }
  530. if city != "" {
  531. var citySql string
  532. slice := strings.Split(city, ",")
  533. for _, v := range slice {
  534. citySql += "'" + v + "'" + ","
  535. }
  536. citySql = strings.TrimRight(citySql, ",")
  537. condition += ` AND a.city IN (` + citySql + `) `
  538. }
  539. if regionType != "" {
  540. condition += ` AND a.region_type =? `
  541. pars = append(pars, regionType)
  542. }
  543. if keyWord != "" {
  544. companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
  545. if err != nil {
  546. br.Msg = "获取客户信息失败"
  547. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  548. return
  549. }
  550. if companyIdStr != "" {
  551. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.credit_code LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  552. } else {
  553. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.credit_code LIKE '%` + keyWord + `%' ) `
  554. }
  555. }
  556. //任务状态
  557. if todoStatus != "" {
  558. condition += ` AND b.todo_status =? `
  559. pars = append(pars, todoStatus)
  560. }
  561. // 阅读权限/已购品种筛选
  562. cond, emp, e := services.FilterReadAndContractAuth(chartPermissionIds, contractPermissionIds, condition)
  563. if e != nil {
  564. br.Msg = "获取失败"
  565. br.ErrMsg = "FilterReadAndContractAuth err: " + e.Error()
  566. return
  567. }
  568. if emp {
  569. for _, v := range statusArr {
  570. statusCount := new(company.CompanyStatus)
  571. if v == "全部" {
  572. statusCount.Status = "全部"
  573. statusCount.Count = 0
  574. } else {
  575. statusCount.Status = v
  576. statusCount.Count = 0
  577. }
  578. statusItems = append(statusItems, statusCount)
  579. }
  580. items := make([]*company.CompanyListItem, 0)
  581. resp.List = items
  582. resp.Paging = page
  583. resp.StatusCount = statusItems
  584. br.Msg = "获取成功"
  585. br.Ret = 200
  586. br.Data = resp
  587. return
  588. }
  589. condition = cond
  590. //套餐类型
  591. if packageType > 0 {
  592. condition += ` AND b.package_type=? `
  593. pars = append(pars, packageType)
  594. }
  595. lossCondition = condition
  596. lossPars = pars
  597. permissionCondition = condition
  598. permissionPars = pars
  599. //流失客户统计
  600. lossCondition += ` AND status='流失' `
  601. //权限控制
  602. {
  603. //如果不是超级管理员或者财务
  604. if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && roleTypeCode != utils.ROLE_TYPE_CODE_FINANCE {
  605. //如果是部门管理员
  606. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  607. condition += ` AND b.product_id=? `
  608. pars = append(pars, productId)
  609. lossCondition += ` AND b.product_id=? `
  610. lossPars = append(lossPars, productId)
  611. permissionCondition += ` AND b.product_id=? `
  612. permissionPars = append(permissionPars, productId)
  613. //}
  614. //else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DIRECTOR {
  615. // condition += ` AND b.product_id=? `
  616. // pars = append(pars, productId)
  617. //
  618. // lossCondition += ` AND b.product_id=? `
  619. // lossPars = append(lossPars, productId)
  620. //
  621. // permissionCondition += ` AND b.product_id=? `
  622. // permissionPars = append(permissionPars, productId)
  623. } else {
  624. condition += ` AND b.product_id=? `
  625. pars = append(pars, productId)
  626. lossCondition += ` AND b.product_id=? `
  627. lossPars = append(lossPars, productId)
  628. permissionCondition += ` AND b.product_id=? `
  629. permissionPars = append(permissionPars, productId)
  630. if status == "全部" {
  631. ////如果是筛选了流失客户状态
  632. if sysUser.Authority <= 0 {
  633. condition += ` AND (b.seller_id=? OR status='流失' OR (b.share_seller_id = ? AND b.is_share = 1)) `
  634. pars = append(pars, sysUser.AdminId, sysUser.AdminId)
  635. permissionCondition += ` AND (b.seller_id=? OR status='流失' OR (b.share_seller_id = ? AND b.is_share = 1)) `
  636. permissionPars = append(permissionPars, sysUser.AdminId, sysUser.AdminId)
  637. } else {
  638. if sysUser.Authority == 1 {
  639. condition += ` AND (b.department_id=? OR status='流失')`
  640. pars = append(pars, sysUser.DepartmentId)
  641. permissionCondition += ` AND b.department_id=? `
  642. permissionPars = append(permissionPars, sysUser.DepartmentId)
  643. }
  644. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  645. if status != utils.COMPANY_STATUS_LOSE {
  646. condition += ` AND (b.group_id=? OR status='流失') `
  647. pars = append(pars, sysUser.GroupId)
  648. }
  649. permissionCondition += ` AND b.group_id=? `
  650. permissionPars = append(permissionPars, sysUser.GroupId)
  651. }
  652. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  653. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  654. if err != nil {
  655. br.Msg = "获取失败"
  656. br.ErrMsg = "查询父级id异常" + err.Error()
  657. return
  658. }
  659. var ids []*string
  660. if pid != nil {
  661. if *pid != 0 {
  662. //销售主管放在三级列表中
  663. ids, err = company.GetGroupIdsByParentId(*pid)
  664. if err != nil {
  665. fmt.Println(err.Error())
  666. }
  667. } else {
  668. //销售主管放在二级列表中
  669. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  670. if err != nil {
  671. fmt.Println(err.Error())
  672. }
  673. }
  674. }
  675. var idSlice []string
  676. var sid string
  677. for _, id := range ids {
  678. idSlice = append(idSlice, *id)
  679. }
  680. //加入父级groupId
  681. if *pid > 0 {
  682. idSlice = append(idSlice, strconv.Itoa(*pid))
  683. } else {
  684. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  685. }
  686. sid = strings.Join(idSlice, ",")
  687. if len(sid) > 0 {
  688. if status != utils.COMPANY_STATUS_LOSE {
  689. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  690. //pars = append(pars, sysUser.GroupId)
  691. }
  692. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  693. } else {
  694. if status != utils.COMPANY_STATUS_LOSE {
  695. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  696. //pars = append(pars, sysUser.GroupId)
  697. }
  698. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  699. }
  700. //permissionPars = append(permissionPars, sysUser.GroupId)
  701. }
  702. if sysUser.Authority == 4 {
  703. //pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  704. //if err != nil {
  705. // br.Msg = "获取失败"
  706. // br.ErrMsg = "查询父级id异常" + err.Error()
  707. // return
  708. //}
  709. //ids,err := company.GetGroupIdsByParentId(*pid)
  710. //if err != nil {
  711. // br.Msg = "获取失败"
  712. // br.ErrMsg = "查询父级id异常" + err.Error()
  713. // return
  714. //}
  715. //var idSlice []string
  716. //var sid string
  717. //for _, id := range ids {
  718. // idSlice = append(idSlice, *id)
  719. //}
  720. //sid = strings.Join(idSlice,",")
  721. if status != utils.COMPANY_STATUS_LOSE {
  722. condition += ` AND (b.group_id =? OR status='流失') `
  723. pars = append(pars, sysUser.GroupId)
  724. }
  725. permissionCondition += ` AND b.group_id=? `
  726. permissionPars = append(permissionPars, sysUser.GroupId)
  727. }
  728. }
  729. } else {
  730. //如果没有筛选了流失客户状态,那么需要加客户归属条件加入到查询中去
  731. if sysUser.Authority <= 0 {
  732. if status != utils.COMPANY_STATUS_LOSE {
  733. //condition += ` AND b.seller_id=? `
  734. //pars = append(pars, sysUser.AdminId)
  735. // 是否包含共享客户(新增合同时, 关键词搜索客户为true)
  736. if includeShare {
  737. condition += ` AND (b.seller_id = ? OR (b.share_seller_id = ? AND b.is_share = 1)) `
  738. pars = append(pars, sysUser.AdminId, sysUser.AdminId)
  739. } else {
  740. condition += ` AND b.seller_id = ? `
  741. pars = append(pars, sysUser.AdminId)
  742. }
  743. }
  744. permissionCondition += ` AND (b.seller_id=? OR (b.share_seller_id = ? AND b.is_share = 1)) `
  745. permissionPars = append(permissionPars, sysUser.AdminId, sysUser.AdminId)
  746. } else {
  747. if sysUser.Authority == 1 {
  748. if status != utils.COMPANY_STATUS_LOSE {
  749. condition += ` AND b.department_id=?`
  750. pars = append(pars, sysUser.DepartmentId)
  751. }
  752. permissionCondition += ` AND b.department_id=? `
  753. permissionPars = append(permissionPars, sysUser.DepartmentId)
  754. }
  755. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  756. if status != utils.COMPANY_STATUS_LOSE {
  757. condition += ` AND b.group_id=? `
  758. pars = append(pars, sysUser.GroupId)
  759. }
  760. permissionCondition += ` AND b.group_id=? `
  761. permissionPars = append(permissionPars, sysUser.GroupId)
  762. }
  763. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  764. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  765. if err != nil {
  766. br.Msg = "获取失败"
  767. br.ErrMsg = "查询父级id异常" + err.Error()
  768. return
  769. }
  770. var ids []*string
  771. if pid != nil {
  772. if *pid != 0 {
  773. //销售主管放在三级列表中
  774. ids, err = company.GetGroupIdsByParentId(*pid)
  775. if err != nil {
  776. fmt.Println(err.Error())
  777. }
  778. } else {
  779. //销售主管放在二级列表中
  780. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  781. if err != nil {
  782. fmt.Println(err.Error())
  783. }
  784. }
  785. }
  786. var idSlice []string
  787. var sid string
  788. for _, id := range ids {
  789. idSlice = append(idSlice, *id)
  790. }
  791. //加入父级groupId
  792. if *pid > 0 {
  793. idSlice = append(idSlice, strconv.Itoa(*pid))
  794. } else {
  795. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  796. }
  797. sid = strings.Join(idSlice, ",")
  798. if len(sid) > 0 {
  799. if status != utils.COMPANY_STATUS_LOSE {
  800. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  801. //pars = append(pars, sysUser.GroupId)
  802. }
  803. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  804. } else {
  805. if status != utils.COMPANY_STATUS_LOSE {
  806. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  807. //pars = append(pars, sysUser.GroupId)
  808. }
  809. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  810. }
  811. }
  812. if sysUser.Authority == 4 {
  813. if status != utils.COMPANY_STATUS_LOSE {
  814. condition += ` AND b.group_id =? `
  815. pars = append(pars, sysUser.GroupId)
  816. }
  817. permissionCondition += ` AND b.group_id=? `
  818. permissionPars = append(permissionPars, sysUser.GroupId)
  819. }
  820. }
  821. }
  822. }
  823. }
  824. }
  825. //状态控制
  826. if status != "" && status != "全部" {
  827. //switch status {
  828. //case "试用-活跃":
  829. // condition += ` AND b.status="试用" and b.view_total>= ? `
  830. // pars = append(pars, statistic_report.ActiveViewNum)
  831. //case "试用-非活跃":
  832. // condition += ` AND b.status="试用" and b.view_total < ? `
  833. // pars = append(pars, statistic_report.ActiveViewNum)
  834. //default:
  835. // condition += ` AND b.status=? `
  836. // pars = append(pars, status)
  837. //}
  838. condition += ` AND b.status=? `
  839. pars = append(pars, status)
  840. // 试用客户标签
  841. if status == "试用" && tryStage > 0 {
  842. condition += ` AND b.try_stage=? `
  843. pars = append(pars, tryStage)
  844. }
  845. }
  846. total, err := company.GetCompanyListCount(condition, pars)
  847. if err != nil {
  848. br.Msg = "获取失败"
  849. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  850. return
  851. }
  852. //
  853. sortStr := ``
  854. if !sortByTodo {
  855. if sortParam != "" && sortType != "" {
  856. if sortParam == "expireDay" {
  857. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  858. if sortType == "asc" {
  859. sortStr = " ORDER BY min_end_date"
  860. } else {
  861. sortStr = " ORDER BY max_end_date"
  862. }
  863. } else {
  864. sortStr = " ORDER BY b.end_date "
  865. }
  866. } else if sortParam == "createTime" {
  867. sortStr = " ORDER BY a.created_time "
  868. } else if sortParam == "viewTotal" {
  869. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  870. sortStr = " ORDER BY all_view_total"
  871. } else {
  872. sortStr = " ORDER BY b.view_total "
  873. }
  874. } else if sortParam == "viewTime" {
  875. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  876. if sortType == "asc" {
  877. sortStr = " ORDER BY min_last_view_time"
  878. } else {
  879. sortStr = " ORDER BY max_last_view_time"
  880. }
  881. } else {
  882. sortStr = " ORDER BY b.last_view_time "
  883. }
  884. } else if sortParam == "roadShowTotal" {
  885. sortStr = " ORDER BY b.road_show_total "
  886. } else if sortParam == "formalTime" {
  887. sortStr = " ORDER BY b.formal_time "
  888. } else if sortParam == "freezeTime" {
  889. sortStr = " ORDER BY b.freeze_time "
  890. } else if sortParam == "lossTime" {
  891. sortStr = " ORDER BY b.loss_time "
  892. } else if sortParam == "todoCreateTime" {
  893. sortStr = " ORDER BY b.todo_create_time "
  894. } else if sortParam == "todoApproveTime" {
  895. sortStr = " ORDER BY b.todo_approve_time "
  896. } else if sortParam == "tryStage" && status == "试用" {
  897. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  898. sortStr = " ORDER BY sort_try_stage asc, all_view_total desc, a.created_time desc"
  899. } else {
  900. sortStr = " ORDER BY sort_try_stage asc, b.view_total desc, a.created_time desc"
  901. }
  902. } else if sortParam == "deadline" {
  903. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  904. sortStr = " ORDER BY sort_todo_end_time asc, all_view_total desc, a.created_time desc"
  905. } else {
  906. sortStr = " ORDER BY sort_todo_end_time asc, b.view_total desc, a.created_time desc"
  907. }
  908. } else if sortParam == "tryOutDay" {
  909. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  910. sortStr = " ORDER BY all_try_out_day_total "
  911. } else {
  912. sortStr = " ORDER BY b.try_out_day_total "
  913. }
  914. } else if sortParam == "closeTime" {
  915. sortStr = " ORDER BY b.close_time "
  916. } else {
  917. br.Msg = "获取失败"
  918. br.ErrMsg = "排序字段传入数据异常:" + sortParam
  919. return
  920. }
  921. if sortParam != "tryStage" && sortParam != "deadline" {
  922. if sortType == "asc" {
  923. sortStr += " ASC "
  924. } else if sortType == "desc" {
  925. sortStr += " DESC "
  926. } else {
  927. br.Msg = "获取失败"
  928. br.ErrMsg = "排序类型传入数据异常:" + sortType
  929. return
  930. }
  931. }
  932. } else {
  933. //2、客户列表选择“全部”时,支持按照“状态和阅读数”对“全部”分类下所有客户列表进行升降序排列;选择“正式”时按照“转正时间”、选择“冻结”时按照“冻结时间”、选择“流失”时按照“流失时间”、选择“永续”时按照“创建时间”;
  934. if status == "全部" {
  935. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  936. sortStr = " ORDER BY sort_status asc, all_view_total desc, a.created_time "
  937. } else {
  938. sortStr = " ORDER BY sort_status asc, b.view_total desc, a.created_time "
  939. }
  940. } else if status == "永续" {
  941. sortStr = " ORDER BY a.created_time "
  942. } else if status == "正式" {
  943. // 正式客户默认按照周阅读活跃ASC, 同为不活跃则按照转正时间DESC
  944. sortStr = " ORDER BY week_view_active ASC, b.formal_time "
  945. //sortStr = " ORDER BY b.formal_time "
  946. } else if status == "冻结" {
  947. sortStr = " ORDER BY b.freeze_time "
  948. } else if status == "流失" {
  949. sortStr = " ORDER BY b.loss_time "
  950. } else if status == "试用" {
  951. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  952. sortStr = " ORDER BY all_view_total desc, a.created_time "
  953. } else {
  954. sortStr = " ORDER BY b.view_total desc, a.created_time "
  955. }
  956. } else if status == utils.COMPANY_STATUS_CLOSE {
  957. // 关闭客户按照关闭时间DESC
  958. sortStr = " ORDER BY b.close_time "
  959. }
  960. sortStr += " DESC "
  961. }
  962. } else {
  963. sortStr = " ORDER BY FIELD (todo_status,'未完成','已完成','无任务'), todo_modify_time DESC "
  964. }
  965. //任务状态
  966. if todoStatus != "" {
  967. //排序,筛选出的未完成、已完成客户列表排序分别按照 最近一个任务的创建时间、最近一个任务的审核时间排序;
  968. switch todoStatus {
  969. case "未完成":
  970. if sortStr != "" {
  971. sortStr += " ,b.todo_create_time desc "
  972. } else {
  973. sortStr = " ORDER BY b.todo_create_time desc "
  974. }
  975. case "已完成":
  976. if sortStr != "" {
  977. sortStr += " ,b.todo_approve_time desc "
  978. } else {
  979. sortStr = " ORDER BY b.todo_approve_time desc "
  980. }
  981. }
  982. }
  983. list, err := company.GetCompanyList(condition, status, sortStr, pars, startSize, pageSize)
  984. if err != nil {
  985. br.Msg = "获取失败"
  986. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  987. return
  988. }
  989. //企业用户数组切片
  990. companyIdSlice := make([]string, 0)
  991. companyIds := make([]int, 0)
  992. for _, v := range list {
  993. companyIdSlice = append(companyIdSlice, strconv.Itoa(v.CompanyId))
  994. companyIds = append(companyIds, v.CompanyId)
  995. }
  996. //企业用户产品开通数
  997. companyIdStr := strings.Join(companyIdSlice, ",")
  998. companyProductTotalList, _ := company.GetCountProductByCompanyIds(companyIdStr)
  999. companyProductTotalMap := make(map[int]*company.CompanyProductTotalSlice)
  1000. for _, companyProductTotal := range companyProductTotalList {
  1001. companyProductTotalMap[companyProductTotal.CompanyId] = companyProductTotal
  1002. }
  1003. lenList := len(list)
  1004. //companyFiccViewTimeMap := make(map[int]time.Time)
  1005. //companyRaiViewTimeMap := make(map[int]time.Time)
  1006. //companyFiccViewTotal := make(map[int]int)
  1007. //companyRaiViewTotal := make(map[int]int)
  1008. //获取最近阅读时间 和 累计阅读次数
  1009. //if lenList > 0 {
  1010. // //ficc 或者 全品种
  1011. // if productId == 1 || productId == 0 {
  1012. // companyFiccViewTimeMap, err = services.GetFiccLastUserViewHistoryByCompanyIds(companyIdStr)
  1013. // if err != nil {
  1014. // br.Msg = "获取失败"
  1015. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1016. // return
  1017. // }
  1018. // }
  1019. //
  1020. // if productId == 2 || productId == 0 {
  1021. // companyRaiViewTimeMap, err = services.GetRaiLastUserViewHistoryByCompanyIds(companyIdStr)
  1022. // if err != nil {
  1023. // br.Msg = "获取失败"
  1024. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1025. // return
  1026. // }
  1027. // }
  1028. //
  1029. // companyFiccViewTotal, err = services.GetFiccCountUserViewHistoryByCompanyIds(companyIdStr)
  1030. // if err != nil {
  1031. // br.Msg = "获取失败"
  1032. // br.ErrMsg = "获取ficc阅读数据失败,Err:" + err.Error()
  1033. // return
  1034. // }
  1035. // companyRaiViewTotal, err = services.GetRaiCountUserViewHistoryByCompanyIds(companyIdStr)
  1036. // if err != nil {
  1037. // br.Msg = "获取失败"
  1038. // br.ErrMsg = "获取权益阅读数据失败,Err:" + err.Error()
  1039. // return
  1040. // }
  1041. //}
  1042. // 客户产品详细信息
  1043. companyProductMap := make(map[string]*company.CompanyProduct)
  1044. var companyProductCondition string
  1045. var companyProductPars []interface{}
  1046. switch companyType {
  1047. case "ficc":
  1048. companyProductCondition += ` AND product_id=? `
  1049. companyProductPars = append(companyProductPars, 1)
  1050. case "权益":
  1051. companyProductCondition += ` AND product_id=? `
  1052. companyProductPars = append(companyProductPars, 2)
  1053. default:
  1054. }
  1055. companyProductList, err := company.GetCompanyProductsByCompanyIds(companyIdStr, companyProductCondition, companyProductPars)
  1056. if err != nil {
  1057. br.Msg = "获取失败"
  1058. br.ErrMsg = "获取客户产品数据失败,Err:" + err.Error()
  1059. return
  1060. }
  1061. for _, companyProduct := range companyProductList {
  1062. key := fmt.Sprint(companyProduct.CompanyId, "_", companyProduct.ProductId)
  1063. companyProductMap[key] = companyProduct
  1064. }
  1065. //任务待办
  1066. companyTodoMap := make(map[string]*company_todo.CompanyTodo)
  1067. {
  1068. var companyTodoCondition string
  1069. var companyTodoPars []interface{}
  1070. switch companyType {
  1071. case "ficc":
  1072. companyTodoCondition += ` AND product_id=? `
  1073. companyTodoPars = append(companyTodoPars, 1)
  1074. case "权益":
  1075. companyTodoCondition += ` AND product_id=? `
  1076. companyTodoPars = append(companyTodoPars, 2)
  1077. default:
  1078. }
  1079. companyTodoList, err := company_todo.GetDoingCompanyTodoByCompanyIds(companyIdStr, companyTodoCondition, companyTodoPars)
  1080. if err != nil {
  1081. br.Msg = "获取失败"
  1082. br.ErrMsg = "获取客户产品数据失败,Err:" + err.Error()
  1083. return
  1084. }
  1085. for _, companyTodo := range companyTodoList {
  1086. key := fmt.Sprint(companyTodo.CompanyId)
  1087. companyTodoMap[key] = companyTodo
  1088. }
  1089. }
  1090. // 查询是否有服务记录
  1091. btnServiceRecordMap := make(map[int]bool)
  1092. if len(companyIds) > 0 {
  1093. serRecOB := new(company.CompanyServiceRecord)
  1094. serRecCond := ` AND company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `) AND company_type = ? `
  1095. serRecPars := make([]interface{}, 0)
  1096. serRecPars = append(serRecPars, companyIds, 2)
  1097. serRecs, e := serRecOB.GetItemsByCondition(serRecCond, serRecPars, []string{"company_service_record_id", "company_id"}, "")
  1098. if e != nil {
  1099. br.Msg = "获取失败"
  1100. br.ErrMsg = "获取客户服务记录失败, Err: " + e.Error()
  1101. return
  1102. }
  1103. for _, s := range serRecs {
  1104. btnServiceRecordMap[s.CompanyId] = true
  1105. }
  1106. }
  1107. // 查询当前销售是否有领取客户的权限
  1108. receiveEnabled, _ := services.CheckCompanyReceiveButton(sysUser.AdminId)
  1109. for i := 0; i < lenList; i++ {
  1110. item := list[i]
  1111. //校验该客户是否存在多个产品,如果是,那么代表是共享客户
  1112. if companyProductTotal, ok := companyProductTotalMap[int(item.CompanyId)]; ok {
  1113. if companyProductTotal.Total > 1 {
  1114. list[i].IsShared = true
  1115. }
  1116. }
  1117. var expireDay string
  1118. itemStatus := item.Status
  1119. item.Status = strings.Replace(item.Status, utils.COMPANY_STATUS_FOREVER, utils.COMPANY_STATUS_X_CLASS_TRY_OUT, -1) // 永续客户类型,映射成 X类试用
  1120. if itemStatus != "" {
  1121. if !strings.Contains(item.Status, "/") {
  1122. if itemStatus == utils.COMPANY_STATUS_FOREVER { //永续
  1123. expireDay = "-"
  1124. } else if itemStatus == utils.COMPANY_STATUS_TRY_OUT || itemStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  1125. if item.StartDate != "" && item.EndDate != "" {
  1126. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  1127. endDateTime = endDateTime.AddDate(0, 0, 1)
  1128. sub := endDateTime.Sub(time.Now())
  1129. if sub < 0 {
  1130. sub = 0
  1131. }
  1132. expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  1133. } else {
  1134. expireDay = "-"
  1135. }
  1136. } else if itemStatus == utils.COMPANY_STATUS_LOSE {
  1137. expireDay = "-"
  1138. } else if itemStatus == utils.COMPANY_STATUS_FREEZE {
  1139. if item.StartDate != "" && item.EndDate != "" {
  1140. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  1141. endDateTime = endDateTime.AddDate(0, 0, 0)
  1142. sub := endDateTime.Sub(time.Now())
  1143. if sub < 0 {
  1144. sub = 0
  1145. }
  1146. expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  1147. } else {
  1148. expireDay = "-"
  1149. }
  1150. } else {
  1151. expireDay = "-"
  1152. }
  1153. } else {
  1154. tmpStatusArr := strings.Split(item.Status, "/")
  1155. ficcStatus := tmpStatusArr[0]
  1156. raiStatus := tmpStatusArr[1]
  1157. var ficcEndDate, tryEndDate string
  1158. var ficcExpireDay, tryExpireDay string
  1159. if item.EndDate != "" {
  1160. endDateArr := strings.Split(item.EndDate, "/")
  1161. if len(endDateArr) == 1 {
  1162. ficcEndDate = endDateArr[0]
  1163. } else if len(endDateArr) > 1 {
  1164. ficcEndDate = endDateArr[0]
  1165. tryEndDate = endDateArr[1]
  1166. }
  1167. if ficcStatus == utils.COMPANY_STATUS_FOREVER { //永续
  1168. ficcExpireDay = "-"
  1169. } else if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  1170. if ficcEndDate != "" {
  1171. endDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
  1172. endDateTime = endDateTime.AddDate(0, 0, 1)
  1173. sub := endDateTime.Sub(time.Now())
  1174. if sub < 0 {
  1175. sub = 0
  1176. }
  1177. ficcExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  1178. } else {
  1179. ficcExpireDay = "-"
  1180. }
  1181. } else if ficcStatus == utils.COMPANY_STATUS_LOSE { //流失
  1182. ficcExpireDay = "-"
  1183. } else if ficcStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  1184. if item.StartDate != "" && item.EndDate != "" {
  1185. endDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
  1186. endDateTime = endDateTime.AddDate(0, 0, 0)
  1187. sub := endDateTime.Sub(time.Now())
  1188. if sub < 0 {
  1189. sub = 0
  1190. }
  1191. ficcExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  1192. } else {
  1193. ficcExpireDay = "-"
  1194. }
  1195. } else {
  1196. ficcExpireDay = "-"
  1197. }
  1198. if raiStatus == utils.COMPANY_STATUS_FOREVER { //永续
  1199. tryExpireDay = "-"
  1200. } else if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  1201. if tryEndDate != "" {
  1202. endDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
  1203. endDateTime = endDateTime.AddDate(0, 0, 1)
  1204. sub := endDateTime.Sub(time.Now())
  1205. if sub < 0 {
  1206. sub = 0
  1207. }
  1208. tryExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  1209. } else {
  1210. tryExpireDay = "-"
  1211. }
  1212. } else if raiStatus == utils.COMPANY_STATUS_LOSE { //流失
  1213. tryExpireDay = "-"
  1214. } else if raiStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  1215. if item.StartDate != "" && item.EndDate != "" {
  1216. endDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
  1217. endDateTime = endDateTime.AddDate(0, 0, 0)
  1218. sub := endDateTime.Sub(time.Now())
  1219. if sub < 0 {
  1220. sub = 0
  1221. }
  1222. tryExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  1223. } else {
  1224. tryExpireDay = "-"
  1225. }
  1226. } else {
  1227. tryExpireDay = "-"
  1228. }
  1229. }
  1230. expireDay = ficcExpireDay + "/" + tryExpireDay
  1231. }
  1232. }
  1233. list[i].ExpireDay = expireDay
  1234. //按钮显示控制
  1235. btnItem := new(company.ButtonPermission)
  1236. if item.CompanyId != 1 {
  1237. *btnItem = services.GetCompanyPermissionButton(roleTypeCode, itemStatus, item.SellerIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, -1, item.ShareSellerIds)
  1238. //根据销售"领取客户"的权限对部分按钮做限制
  1239. btnItem = services.GetCompanyPermissionButtonByReceiveEnabled(btnItem, receiveEnabled)
  1240. }
  1241. if list[i].IsShare == 1 && btnItem.BtnModifySeller == true && roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  1242. //如果已经是共享客户了,取消共享按钮全都显示,和修改销售权限一样
  1243. btnItem.BtnShare = true
  1244. }
  1245. 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 {
  1246. //权益冻结客户,也可以设置共享。冻结客户操作栏,增加设置共享按钮,可见权限不变(仅对权益管理员开放)
  1247. btnItem.BtnShare = true
  1248. }
  1249. list[i].BtnItem = btnItem
  1250. if item.FreezeStartDate != "" && item.FreezeEndDate != "" && item.Status == utils.COMPANY_STATUS_FREEZE {
  1251. freezeEndDate, _ := time.Parse(utils.FormatDate, item.FreezeEndDate)
  1252. if time.Now().Before(freezeEndDate) {
  1253. expireDays := freezeEndDate.Sub(time.Now()).Hours() / 24
  1254. list[i].FreezeExpireDays = int(expireDays) + 1
  1255. }
  1256. }
  1257. btnItem.BtnServiceRecord = btnServiceRecordMap[list[i].CompanyId]
  1258. //productIdArr := strings.Split(item.ProductIds, "/")
  1259. //// 套餐类型
  1260. //packageTypeArr := strings.Split(item.PackageTypes, "/")
  1261. //viewTotalArr := strings.Split(item.ViewTotals, "/") //总阅读次数
  1262. //lastViewTimeArr := strings.Split(item.LastViewTimes, "/") //最近阅读时间
  1263. //if len(productIdArr) > 1 {
  1264. // if len(packageTypeArr) == 1 {
  1265. // item.PackageTypes = item.PackageTypes + "/" + item.PackageTypes
  1266. // packageTypeArr = strings.Split(item.PackageTypes, "/")
  1267. // }
  1268. // //阅读次数
  1269. // if len(viewTotalArr) == 1 {
  1270. // item.ViewTotals = item.ViewTotals + "/" + item.ViewTotals
  1271. // viewTotalArr = strings.Split(item.ViewTotals, "/") //总阅读次数
  1272. // }
  1273. //
  1274. // if len(lastViewTimeArr) == 1 {
  1275. // item.LastViewTimes = item.LastViewTimes + "/" + item.LastViewTimes
  1276. // lastViewTimeArr = strings.Split(item.LastViewTimes, "/") //最近阅读时间
  1277. // }
  1278. //}
  1279. //for i, tmpProductId := range productIdArr {
  1280. // packageTypeInt, _ := strconv.Atoi(packageTypeArr[i])
  1281. // viewTotalInt, _ := strconv.Atoi(viewTotalArr[i])
  1282. // lastViewTime := lastViewTimeArr[i]
  1283. // //ficc
  1284. // if tmpProductId == "1" {
  1285. // //套餐类型
  1286. // item.FiccPackageType = packageTypeInt
  1287. //
  1288. // //总阅读次数
  1289. // item.FiccView = viewTotalInt
  1290. //
  1291. // //最近一次阅读时间
  1292. // item.FiccLastViewTime = lastViewTime
  1293. // }
  1294. // //权益
  1295. // if tmpProductId == "2" {
  1296. // //总阅读次数
  1297. // item.RaiView = viewTotalInt
  1298. //
  1299. // //最近一次阅读时间
  1300. // item.RaiLastViewTime = lastViewTime
  1301. // }
  1302. //}
  1303. ficcKey := fmt.Sprint(item.CompanyId, "_", 1)
  1304. //ficc
  1305. if tmpCompanyProduct, ok := companyProductMap[ficcKey]; ok {
  1306. //套餐类型
  1307. item.FiccPackageType = tmpCompanyProduct.PackageType
  1308. //总试用天数
  1309. item.FiccTryOutDay = tmpCompanyProduct.TryOutDayTotal
  1310. //总阅读次数
  1311. item.FiccView = tmpCompanyProduct.ViewTotal
  1312. if !tmpCompanyProduct.LastViewTime.IsZero() {
  1313. //最近一次阅读时间
  1314. item.FiccLastViewTime = tmpCompanyProduct.LastViewTime.Format(utils.FormatDateTime)
  1315. }
  1316. }
  1317. //权益
  1318. raiKey := fmt.Sprint(item.CompanyId, "_", 2)
  1319. if tmpCompanyProduct, ok := companyProductMap[raiKey]; ok {
  1320. //总阅读次数
  1321. item.RaiView = tmpCompanyProduct.ViewTotal
  1322. //总试用天数
  1323. item.RaiTryOutDay = tmpCompanyProduct.TryOutDayTotal
  1324. if !tmpCompanyProduct.LastViewTime.IsZero() {
  1325. //最近一次阅读时间
  1326. item.RaiLastViewTime = tmpCompanyProduct.LastViewTime.Format(utils.FormatDateTime)
  1327. }
  1328. }
  1329. //最近阅读时间
  1330. //if viewTime, ok := companyFiccViewTimeMap[item.CompanyId]; ok {
  1331. // item.FiccLastViewTime = viewTime.Format(utils.FormatDateTime)
  1332. //}
  1333. //
  1334. //if viewTime, ok := companyRaiViewTimeMap[item.CompanyId]; ok {
  1335. // item.RaiLastViewTime = viewTime.Format(utils.FormatDateTime)
  1336. //}
  1337. // 试用客户子标签
  1338. if strings.Contains(item.Status, "试用") {
  1339. statusSlice := strings.Split(item.Status, "/")
  1340. stageItemSlice := strings.Split(item.TryStageStr, "/")
  1341. productIdSlice := strings.Split(item.ProductIds, "/")
  1342. for sk, sv := range statusSlice {
  1343. if sv != "试用" {
  1344. continue
  1345. }
  1346. tryItem := new(company.TryStageSliceItem)
  1347. if len(productIdSlice) < (sk+1) || len(stageItemSlice) < (sk+1) {
  1348. continue
  1349. }
  1350. key := fmt.Sprint(item.CompanyId, "_", productIdSlice[sk])
  1351. if pro, ok := companyProductMap[key]; ok {
  1352. tryItem.ProductId, _ = strconv.Atoi(productIdSlice[sk])
  1353. if pro.SellerId == sysUser.AdminId { //产品销售ID和登录ID相等
  1354. tryItem.HasPermission = true
  1355. }
  1356. tryItem.TryStage, _ = strconv.Atoi(stageItemSlice[sk])
  1357. list[i].TryStageSlice = append(list[i].TryStageSlice, tryItem)
  1358. }
  1359. }
  1360. }
  1361. // To-Do任务状态为未完成的对应任务的截止日期-当前日期;
  1362. if strings.Contains(item.TodoStatuss, "未完成") {
  1363. if strings.Contains(item.TodoEndTimeStr, "/") {
  1364. edtSlice := strings.Split(item.TodoEndTimeStr, "/")
  1365. item.TodoEndTime, _ = time.ParseInLocation(utils.FormatDateTime, edtSlice[0], time.Local)
  1366. } else {
  1367. item.TodoEndTime, _ = time.ParseInLocation(utils.FormatDateTime, item.TodoEndTimeStr, time.Local)
  1368. }
  1369. tmpEndTime := item.TodoEndTime.Format(utils.FormatDate)
  1370. if tmpEndTime == "0001-01-01" {
  1371. tmpEndTime = ""
  1372. }
  1373. if tmpEndTime != "" {
  1374. dlTime1 := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 0, 0, 0, 0, time.Local)
  1375. dlTime2 := time.Date(item.TodoEndTime.Year(), item.TodoEndTime.Month(), item.TodoEndTime.Day(), 0, 0, 0, 0, time.Local)
  1376. dldays := int(dlTime2.Sub(dlTime1).Hours() / 24)
  1377. list[i].Deadline = strconv.Itoa(dldays)
  1378. }
  1379. }
  1380. }
  1381. statusCount, err := company.GetCompanyStatusCount(permissionCondition, permissionPars)
  1382. if err != nil {
  1383. br.Msg = "获取失败"
  1384. br.ErrMsg = "获取状态数量失败,Err:" + err.Error()
  1385. return
  1386. }
  1387. statusMap := make(map[string]int, 0)
  1388. var totalCount int
  1389. for _, sv := range statusCount {
  1390. sv.Status = strings.Replace(sv.Status, utils.COMPANY_STATUS_FOREVER, utils.COMPANY_STATUS_X_CLASS_TRY_OUT, -1) // 永续客户类型,映射成 X类试用
  1391. totalCount = totalCount + sv.Count
  1392. statusMap[sv.Status] = sv.Count
  1393. }
  1394. // 统计试用客户的子标签数量,只在试用状态页面统计
  1395. var tryStageCountResp []*company.CompanyTryStageCount
  1396. if status == "试用" {
  1397. tryStageCount, err := company.GetCompanyTryStageCount(permissionCondition, permissionPars)
  1398. if err != nil {
  1399. br.Msg = "获取失败"
  1400. br.ErrMsg = "获取试用状态标签数量失败,Err:" + err.Error()
  1401. return
  1402. }
  1403. tryStageMap := make(map[int]int)
  1404. for _, v := range tryStageCount {
  1405. tryStageMap[0] += v.Count
  1406. tryStageMap[v.TryStage] = v.Count
  1407. }
  1408. tryStageAllMap := map[int]string{
  1409. 0: "全部",
  1410. 2: "推进",
  1411. 3: "跟踪",
  1412. 4: "预备",
  1413. 1: "未分类",
  1414. }
  1415. for k, v := range tryStageAllMap {
  1416. item := new(company.CompanyTryStageCount)
  1417. item.TryStageStr = v
  1418. item.TryStage = k
  1419. if count, ok := tryStageMap[k]; ok {
  1420. item.Count = count
  1421. }
  1422. tryStageCountResp = append(tryStageCountResp, item)
  1423. }
  1424. }
  1425. //
  1426. ////试用-活跃
  1427. //{
  1428. // tmpPermissionCondition := permissionCondition
  1429. // tmpPermissionPars := permissionPars
  1430. // tmpPermissionCondition += ` and b.view_total>=? `
  1431. // tmpPermissionPars = append(tmpPermissionPars, statistic_report.ActiveViewNum)
  1432. //
  1433. // tryOutActiveCount, err := company.GetCompanyTryOutStatusCount(tmpPermissionCondition, tmpPermissionPars)
  1434. // if err != nil {
  1435. // br.Msg = "获取失败"
  1436. // br.ErrMsg = "获取状态数量失败,Err:" + err.Error()
  1437. // return
  1438. // }
  1439. // statusMap["试用-活跃"] = tryOutActiveCount.Count
  1440. //}
  1441. //
  1442. ////试用-非活跃
  1443. //{
  1444. // tmpPermissionCondition := permissionCondition
  1445. // tmpPermissionPars := permissionPars
  1446. // tmpPermissionCondition += ` and b.view_total <? `
  1447. // tmpPermissionPars = append(tmpPermissionPars, statistic_report.ActiveViewNum)
  1448. //
  1449. // tryOutActiveCount, err := company.GetCompanyTryOutStatusCount(tmpPermissionCondition, tmpPermissionPars)
  1450. // if err != nil {
  1451. // br.Msg = "获取失败"
  1452. // br.ErrMsg = "获取状态数量失败,Err:" + err.Error()
  1453. // return
  1454. // }
  1455. // statusMap["试用-非活跃"] = tryOutActiveCount.Count
  1456. //}
  1457. lossItem, err := company.GetCompanyStatusLoseCount(lossCondition, lossPars)
  1458. if err != nil {
  1459. br.Msg = "获取失败"
  1460. br.ErrMsg = "获取流失状态数量失败,Err:" + err.Error()
  1461. return
  1462. }
  1463. totalCount = totalCount + lossItem.Count
  1464. for _, v := range statusArr {
  1465. s := new(company.CompanyStatus)
  1466. if v == "全部" {
  1467. s.Status = "全部"
  1468. s.Count = totalCount
  1469. } else if v == utils.COMPANY_STATUS_LOSE {
  1470. s.Status = v
  1471. s.Count = lossItem.Count
  1472. } else {
  1473. s.Status = v
  1474. if val, ok := statusMap[v]; ok {
  1475. s.Count = val
  1476. }
  1477. }
  1478. statusItems = append(statusItems, s)
  1479. }
  1480. sysUserList, err := system.GetAdminList()
  1481. if err != nil {
  1482. br.Msg = "获取失败"
  1483. br.ErrMsg = "获取admin列表失败, Err:" + err.Error()
  1484. return
  1485. }
  1486. adminMap := make(map[int]*system.Admin, 0)
  1487. for _, v := range sysUserList {
  1488. adminMap[v.AdminId] = v
  1489. }
  1490. companyLists := make([]*company.CompanyListItem, 0)
  1491. //查询阅读次数
  1492. if list == nil {
  1493. companyLists = make([]*company.CompanyListItem, 0)
  1494. } else {
  1495. for _, v := range list {
  1496. //viewTotal:=GetviewTotal(v.CompanyId)
  1497. //活跃(客户状态)
  1498. //if v.IsShare != 1 {
  1499. // if v.BtnItem.BtnModifySeller == true {
  1500. // v.BtnItem.BtnModifySeller = false
  1501. // }
  1502. //}
  1503. //productIdSlice := strings.Split(v.ProductIds, "/")
  1504. //statusSlice := strings.Split(v.Status, "/")
  1505. //for productIndex, tmpProductId := range productIdSlice {
  1506. // tmpStatusIndex := 0
  1507. // if len(statusSlice) > 1 {
  1508. // tmpStatusIndex = productIndex
  1509. // }
  1510. // tmpProductStatus := statusSlice[tmpStatusIndex]
  1511. // if strings.Contains(tmpProductStatus, "试用") {
  1512. // activeType := "非活跃"
  1513. // viewNum := v.FiccView
  1514. // if tmpProductId == "2" {
  1515. // viewNum = v.RaiView
  1516. // }
  1517. // if viewNum >= statistic_report.ActiveViewNum {
  1518. // activeType = "活跃"
  1519. // }
  1520. // statusSlice[tmpStatusIndex] = fmt.Sprint(tmpProductStatus, "(", activeType, ")")
  1521. //
  1522. // tmpStatus = strings.Join(statusSlice, "/")
  1523. // }
  1524. //}
  1525. //ficcViewTotal, ok := companyFiccViewTotal[v.CompanyId]
  1526. //if !ok {
  1527. // ficcViewTotal = 0
  1528. //}
  1529. //raiViewTotal, ok := companyRaiViewTotal[v.CompanyId]
  1530. //if !ok {
  1531. // raiViewTotal = 0
  1532. //}
  1533. // 是否存在进行中的任务
  1534. var todoStatus bool
  1535. if _, ok := companyTodoMap[fmt.Sprint(v.CompanyId)]; ok {
  1536. todoStatus = true
  1537. }
  1538. //是否支持确认完成待办任务
  1539. var canConfirm bool
  1540. var hiddenConfirm bool //是否隐藏确定完成按钮
  1541. var hiddenCreate bool //是否隐藏新增/编辑按钮
  1542. hiddenConfirm = true
  1543. hiddenCreate = true
  1544. for _, vProductId := range []int{1, 2} {
  1545. ficcKey := fmt.Sprint(v.CompanyId, "_", vProductId)
  1546. //ficc
  1547. if tmpCompanyProduct, ok := companyProductMap[ficcKey]; ok {
  1548. if tmpCompanyProduct.Status != utils.COMPANY_STATUS_LOSE && tmpCompanyProduct.Status != utils.COMPANY_STATUS_CLOSE { //非流失或关闭
  1549. hiddenCreate = false
  1550. switch this.SysUser.RoleTypeCode {
  1551. 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:
  1552. //部门管理员、ficc主管、权益组长
  1553. hiddenConfirm = false //不展示
  1554. if todoStatus { //有任务,需要展示
  1555. canConfirm = true
  1556. }
  1557. case utils.ROLE_TYPE_CODE_FICC_TEAM: //ficc组长
  1558. if todoStatus { //有任务,需要展示
  1559. canConfirm = true
  1560. }
  1561. if v.SellerId != this.SysUser.AdminId { //不是自己的客户
  1562. hiddenConfirm = false //展示
  1563. }
  1564. case utils.ROLE_TYPE_CODE_RAI_SELLER: //权益销售
  1565. if v.SellerId == this.SysUser.AdminId { //是自己的客户
  1566. has := services.CheckRaiApprovePermission(sysUser.AdminId) //这些个权益销售是有权限的
  1567. if has {
  1568. if todoStatus { //有任务,需要展示
  1569. canConfirm = true
  1570. }
  1571. hiddenConfirm = false //展示
  1572. }
  1573. }
  1574. }
  1575. }
  1576. }
  1577. }
  1578. todoButtonColor := `green`
  1579. //'无任务','未完成','已完成'
  1580. if strings.Contains(v.TodoStatuss, "未完成") {
  1581. todoButtonColor = "red"
  1582. } else if strings.Contains(v.TodoStatuss, "已完成") {
  1583. todoButtonColor = "green"
  1584. } else if strings.Contains(v.TodoStatuss, "无任务") {
  1585. todoButtonColor = "gray"
  1586. }
  1587. //永续客户X类试用客户出参转换
  1588. v.StatusStr = strings.Replace(v.StatusStr, utils.COMPANY_STATUS_FOREVER, utils.COMPANY_STATUS_X_CLASS_TRY_OUT, -1)
  1589. if !utils.InArrayByStr([]string{"正式", "试用", "永续", "X类试用"}, v.Status) { //不是这几种状态不做标红处理
  1590. v.IsUserMaker = 0
  1591. }
  1592. //解决共享客户正式筛选下是否标红的问题
  1593. if v.WeekViewActive == 0 && v.IsUserMaker == 1 {
  1594. v.WeekViewActive = 1
  1595. }
  1596. companyList := &company.CompanyListItem{
  1597. CompanyId: v.CompanyId,
  1598. CompanyName: v.CompanyName,
  1599. CreditCode: v.CreditCode,
  1600. CompanyCode: v.CompanyCode,
  1601. StartDate: v.StartDate,
  1602. EndDate: v.EndDate,
  1603. LoseReason: v.LoseReason,
  1604. RenewalReason: v.RenewalReason,
  1605. FreezeReason: v.FreezeReason,
  1606. LossTime: v.LossTime,
  1607. Status: v.StatusStr,
  1608. CompanyType: v.CompanyType,
  1609. ApproveStatus: v.ApproveStatus,
  1610. SellerName: v.SellerName,
  1611. SellerId: v.SellerId,
  1612. SellerIds: v.SellerIds,
  1613. ExpireDay: v.ExpireDay,
  1614. FreezeTime: v.FreezeTime,
  1615. GroupId: v.GroupId,
  1616. GroupIds: v.GroupIds,
  1617. DepartmentId: v.DepartmentId,
  1618. IndustryName: v.IndustryName,
  1619. IsSuspend: v.IsSuspend,
  1620. CreatedTime: v.CreatedTime,
  1621. Source: v.Source,
  1622. Province: v.Province,
  1623. City: v.City,
  1624. Address: v.Address,
  1625. Reasons: v.Reasons,
  1626. FreezeStartDate: v.FreezeStartDate,
  1627. FreezeEndDate: v.FreezeEndDate,
  1628. FreezeExpireDays: v.FreezeExpireDays,
  1629. BtnItem: v.BtnItem,
  1630. ProductId: v.ProductId,
  1631. FormalTime: v.FormalTime,
  1632. IsShared: v.IsShared,
  1633. RegionType: v.RegionType,
  1634. FiccPackageType: v.FiccPackageType,
  1635. FiccLastViewTime: v.FiccLastViewTime,
  1636. RaiLastViewTime: v.RaiLastViewTime,
  1637. //FiccView: viewTotal[0],
  1638. //RaiView: viewTotal[1],
  1639. //FiccView: ficcViewTotal,
  1640. //RaiView: raiViewTotal,
  1641. FiccView: v.FiccView,
  1642. RaiView: v.RaiView,
  1643. FiccTryOutDay: v.FiccTryOutDay,
  1644. RaiTryOutDay: v.RaiTryOutDay,
  1645. AllViewTotal: v.AllViewTotal,
  1646. RoadShowTotal: v.RoadShowTotal,
  1647. TodoStatus: todoStatus,
  1648. CanConfirm: canConfirm,
  1649. HiddenConfirm: hiddenConfirm,
  1650. HiddenCreate: hiddenCreate,
  1651. TodoButtonColor: todoButtonColor,
  1652. TryStageSlice: v.TryStageSlice,
  1653. Deadline: v.Deadline,
  1654. WeekViewActive: v.WeekViewActive,
  1655. IsShare: v.IsShare,
  1656. CloseTime: v.CloseTime,
  1657. CloseReason: v.CloseReason,
  1658. ShareSellerId: v.ShareSellerId,
  1659. ShareSellerIds: v.ShareSellerIds,
  1660. IsUserMaker: v.IsUserMaker,
  1661. }
  1662. if v.ShareSellerIds != "" {
  1663. shareSellerIds := strings.Split(v.ShareSellerIds, ",")
  1664. for _, idStr := range shareSellerIds {
  1665. shareSellerId, e := strconv.Atoi(idStr)
  1666. if e != nil {
  1667. err = e
  1668. return
  1669. }
  1670. shareSeller := adminMap[shareSellerId]
  1671. if shareSeller != nil {
  1672. companyList.ShareSeller += shareSeller.RealName + "(" + shareSeller.GroupName + ")" + "/"
  1673. }
  1674. }
  1675. companyList.ShareSeller = strings.TrimRight(companyList.ShareSeller, "/")
  1676. }
  1677. companyLists = append(companyLists, companyList)
  1678. }
  1679. }
  1680. if companyLists == nil {
  1681. companyLists = make([]*company.CompanyListItem, 0)
  1682. }
  1683. // 白嫖客户标记
  1684. scroungeList, err := company.GetScroungeCompany()
  1685. if err != nil {
  1686. br.Msg = "获取失败"
  1687. br.ErrMsg = "获取白嫖客户信息失败,Err:" + err.Error()
  1688. return
  1689. }
  1690. scroungeMap := make(map[int]int)
  1691. for _, v := range scroungeList {
  1692. scroungeMap[v.CompanyId] = 1
  1693. }
  1694. for i, v := range companyLists {
  1695. if _, ok := scroungeMap[v.CompanyId]; ok {
  1696. companyLists[i].IsScrounge = 1
  1697. }
  1698. }
  1699. page = paging.GetPaging(currentIndex, pageSize, total)
  1700. resp.List = companyLists
  1701. resp.StatusCount = statusItems
  1702. resp.TryStageCount = tryStageCountResp
  1703. resp.Paging = page
  1704. resp.AddCompanyBtn = receiveEnabled
  1705. br.Ret = 200
  1706. br.Success = true
  1707. br.Msg = "获取成功"
  1708. br.Data = resp
  1709. }
  1710. //func (this *CompanyController) ListOld() {
  1711. // br := new(models.BaseResponse).Init()
  1712. // defer func() {
  1713. // this.Data["json"] = br
  1714. // this.ServeJSON()
  1715. // }()
  1716. // sysUser := this.SysUser
  1717. // if sysUser == nil {
  1718. // br.Msg = "请登录"
  1719. // br.ErrMsg = "请登录,SysUser Is Empty"
  1720. // br.Ret = 408
  1721. // return
  1722. // }
  1723. // roleTypeCode := sysUser.RoleTypeCode
  1724. //
  1725. // pageSize, _ := this.GetInt("PageSize")
  1726. // currentIndex, _ := this.GetInt("CurrentIndex")
  1727. // status := this.GetString("Status")
  1728. // companyType := this.GetString("CompanyType")
  1729. // industryId, _ := this.GetInt("IndustryId")
  1730. // adminId := this.GetString("AdminId")
  1731. //
  1732. // chartPermissionIds := this.GetString("ChartPermissionIds")
  1733. // startDate := this.GetString("StartDate")
  1734. // endDate := this.GetString("EndDate")
  1735. // createStartDate := this.GetString("CreateStartDate")
  1736. // createEndDate := this.GetString("CreateEndDate")
  1737. // keyWord := this.GetString("KeyWord")
  1738. // keyWord = strings.Trim(keyWord, " ")
  1739. // keyWord = strings.Replace(keyWord, "'", "", -1)
  1740. //
  1741. // //排序参数
  1742. // sortParam := this.GetString("SortParam")
  1743. // sortType := this.GetString("SortType")
  1744. //
  1745. // var total int
  1746. // page := paging.GetPaging(currentIndex, pageSize, total)
  1747. // resp := new(company.CompanyListResp)
  1748. // statusItems := make([]*company.CompanyStatus, 0)
  1749. // var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}
  1750. //
  1751. // var startSize int
  1752. // if pageSize <= 0 {
  1753. // pageSize = utils.PageSize20
  1754. // }
  1755. // if currentIndex <= 0 {
  1756. // currentIndex = 1
  1757. // }
  1758. // startSize = paging.StartIndex(currentIndex, pageSize)
  1759. // var condition string
  1760. // var pars []interface{}
  1761. //
  1762. // //流失
  1763. // var lossCondition string
  1764. // var lossPars []interface{}
  1765. // //冻结
  1766. // var freezeCondition string
  1767. // var freezePars []interface{}
  1768. //
  1769. // //永续
  1770. // var forverCondition string
  1771. // var forverPars []interface{}
  1772. //
  1773. // var permissionCondition string
  1774. // var permissionPars []interface{}
  1775. //
  1776. // if status != "" && status != "全部" {
  1777. // condition += ` AND b.status=? `
  1778. // pars = append(pars, status)
  1779. //
  1780. // //permissionCondition += ` AND b.status=? `
  1781. // //permissionPars = append(permissionPars, status)
  1782. // }
  1783. // if companyType != "" {
  1784. // condition += ` AND b.product_name=? `
  1785. // pars = append(pars, companyType)
  1786. //
  1787. // lossCondition += ` AND b.product_name=? `
  1788. // lossPars = append(lossPars, companyType)
  1789. //
  1790. // freezeCondition += ` AND b.product_name=? `
  1791. // freezePars = append(freezePars, companyType)
  1792. //
  1793. // forverCondition += ` AND b.product_name=? `
  1794. // forverPars = append(forverPars, companyType)
  1795. //
  1796. // permissionCondition += ` AND b.product_name=? `
  1797. // permissionPars = append(permissionPars, companyType)
  1798. // }
  1799. //
  1800. // if industryId > 0 {
  1801. // condition += ` AND b.industry_id=? `
  1802. // pars = append(pars, industryId)
  1803. //
  1804. // lossCondition += ` AND b.industry_id=? `
  1805. // lossPars = append(lossPars, industryId)
  1806. //
  1807. // freezeCondition += ` AND b.industry_id=? `
  1808. // freezePars = append(freezePars, industryId)
  1809. //
  1810. // forverCondition += ` AND b.industry_id=? `
  1811. // forverPars = append(forverPars, industryId)
  1812. //
  1813. // permissionCondition += ` AND b.industry_id=? `
  1814. // permissionPars = append(permissionPars, industryId)
  1815. // }
  1816. //
  1817. // if adminId != "" {
  1818. // condition += ` AND b.seller_id IN (` + adminId + `) `
  1819. //
  1820. // lossCondition += ` AND b.seller_id IN (` + adminId + `) `
  1821. //
  1822. // freezeCondition += ` AND b.seller_id IN (` + adminId + `) `
  1823. //
  1824. // forverCondition += ` AND b.seller_id IN (` + adminId + `) `
  1825. //
  1826. // permissionCondition += ` AND b.seller_id IN (` + adminId + `) `
  1827. // }
  1828. //
  1829. // if startDate != "" {
  1830. // condition += ` AND b.start_date>=? `
  1831. // pars = append(pars, startDate)
  1832. //
  1833. // lossCondition += ` AND b.start_date>=? `
  1834. // lossPars = append(lossPars, startDate)
  1835. //
  1836. // freezeCondition += ` AND b.start_date>=? `
  1837. // freezePars = append(freezePars, startDate)
  1838. //
  1839. // forverCondition += ` AND b.start_date>=? `
  1840. // forverPars = append(forverPars, startDate)
  1841. //
  1842. // permissionCondition += ` AND b.start_date>=? `
  1843. // permissionPars = append(permissionPars, startDate)
  1844. // }
  1845. //
  1846. // if endDate != "" {
  1847. // condition += ` AND b.end_date<=? `
  1848. // pars = append(pars, endDate)
  1849. //
  1850. // lossCondition += ` AND b.end_date<=? `
  1851. // lossPars = append(lossPars, endDate)
  1852. //
  1853. // freezeCondition += ` AND b.end_date<=? `
  1854. // freezePars = append(freezePars, endDate)
  1855. //
  1856. // forverCondition += ` AND b.end_date<=? `
  1857. // forverPars = append(forverPars, endDate)
  1858. //
  1859. // permissionCondition += ` AND b.end_date<=? `
  1860. // permissionPars = append(permissionPars, endDate)
  1861. // }
  1862. //
  1863. // if createStartDate != "" {
  1864. // condition += ` AND a.created_time>=? `
  1865. // pars = append(pars, createStartDate)
  1866. //
  1867. // lossCondition += ` AND a.created_time>=? `
  1868. // lossPars = append(lossPars, createStartDate)
  1869. //
  1870. // freezeCondition += ` AND a.created_time>=? `
  1871. // freezePars = append(freezePars, createStartDate)
  1872. //
  1873. // forverCondition += ` AND a.created_time>=? `
  1874. // forverPars = append(forverPars, createStartDate)
  1875. //
  1876. // permissionCondition += ` AND a.created_time>=? `
  1877. // permissionPars = append(permissionPars, createStartDate)
  1878. // }
  1879. //
  1880. // if createEndDate != "" {
  1881. // condition += ` AND a.created_time<=? `
  1882. // pars = append(pars, createEndDate)
  1883. //
  1884. // lossCondition += ` AND a.created_time<=? `
  1885. // lossPars = append(lossPars, createEndDate)
  1886. //
  1887. // freezeCondition += ` AND a.created_time<=? `
  1888. // freezePars = append(freezePars, createEndDate)
  1889. //
  1890. // forverCondition += ` AND a.created_time<=? `
  1891. // forverPars = append(forverPars, createEndDate)
  1892. //
  1893. // permissionCondition += ` AND a.created_time<=? `
  1894. // permissionPars = append(permissionPars, createEndDate)
  1895. // }
  1896. //
  1897. // if keyWord != "" {
  1898. // companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
  1899. // if err != nil {
  1900. // br.Msg = "获取客户信息失败"
  1901. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1902. // return
  1903. // }
  1904. // if companyIdStr != "" {
  1905. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  1906. // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  1907. // freezeCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  1908. // forverCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  1909. //
  1910. // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  1911. // } else {
  1912. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  1913. // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  1914. // freezeCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  1915. // forverCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  1916. //
  1917. // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  1918. // }
  1919. // }
  1920. // if chartPermissionIds != "" && chartPermissionIds != "1" {
  1921. // //chartPermissionArr := strings.Split(chartPermissionIds, ",")
  1922. // //chartPermissionCount := len(chartPermissionArr)
  1923. // companyIdStr, err := company.GetCompanyListCompanyIdByPermissionIdStr(chartPermissionIds)
  1924. // if err != nil {
  1925. // br.Msg = "获取失败"
  1926. // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
  1927. // return
  1928. // }
  1929. // //var companyIdArr []string
  1930. // //for _, v := range companyIdList {
  1931. // // companyIdArr = append(companyIdArr, strconv.Itoa(v.CompanyId))
  1932. // //}
  1933. // //companyIdStr := strings.Join(companyIdArr, ",")
  1934. // if companyIdStr != "" {
  1935. // condition += ` AND a.company_id IN (` + companyIdStr + `) `
  1936. // lossCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  1937. // freezeCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  1938. // forverCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  1939. // permissionCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  1940. // } else {
  1941. // for _, v := range statusArr {
  1942. // statusCount := new(company.CompanyStatus)
  1943. // if v == "全部" {
  1944. // statusCount.Status = "全部"
  1945. // statusCount.Count = 0
  1946. // } else {
  1947. // statusCount.Status = v
  1948. // statusCount.Count = 0
  1949. // }
  1950. // statusItems = append(statusItems, statusCount)
  1951. // }
  1952. // items := make([]*company.CompanyListItem, 0)
  1953. // resp.List = items
  1954. // resp.Paging = page
  1955. // resp.StatusCount = statusItems
  1956. // br.Msg = "获取成功"
  1957. // br.Ret = 200
  1958. // br.Data = resp
  1959. // return
  1960. // }
  1961. // }
  1962. // //权限控制
  1963. // {
  1964. // fmt.Println(roleTypeCode)
  1965. // if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  1966. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  1967. // condition += ` AND b.product_id=? `
  1968. // pars = append(pars, 1)
  1969. //
  1970. // permissionCondition += ` AND b.product_id=? `
  1971. // permissionPars = append(permissionPars, 1)
  1972. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  1973. // condition += ` AND b.product_id=? `
  1974. // pars = append(pars, 2)
  1975. //
  1976. // permissionCondition += ` AND b.product_id=? `
  1977. // permissionPars = append(permissionPars, 2)
  1978. // } else {
  1979. // if sysUser.Authority <= 0 {
  1980. // if status == utils.COMPANY_STATUS_TRY_OUT || status == utils.COMPANY_STATUS_FORMAL || status == "全部" {
  1981. // if status == "全部" {
  1982. // condition += ` AND (b.seller_id=? OR status='流失' OR status='永续') `
  1983. // pars = append(pars, sysUser.AdminId)
  1984. // } else {
  1985. // condition += ` AND b.seller_id=? `
  1986. // pars = append(pars, sysUser.AdminId)
  1987. // }
  1988. // }
  1989. // permissionCondition += ` AND b.seller_id=? `
  1990. // permissionPars = append(permissionPars, sysUser.AdminId)
  1991. // } else {
  1992. // if sysUser.Authority == 1 {
  1993. // if status == utils.COMPANY_STATUS_TRY_OUT || status == utils.COMPANY_STATUS_FORMAL || status == "全部" {
  1994. // condition += ` AND b.department_id=? `
  1995. // pars = append(pars, sysUser.DepartmentId)
  1996. //
  1997. // permissionCondition += ` AND b.department_id=? `
  1998. // permissionPars = append(permissionPars, sysUser.DepartmentId)
  1999. // } else {
  2000. // permissionCondition += ` AND b.department_id=? `
  2001. // permissionPars = append(permissionPars, sysUser.DepartmentId)
  2002. // }
  2003. // }
  2004. //
  2005. // if sysUser.Authority == 2 {
  2006. // if status == utils.COMPANY_STATUS_TRY_OUT || status == utils.COMPANY_STATUS_FORMAL || status == "全部" {
  2007. // condition += ` AND b.group_id=? `
  2008. // pars = append(pars, sysUser.GroupId)
  2009. //
  2010. // permissionCondition += ` AND b.group_id=? `
  2011. // permissionPars = append(permissionPars, sysUser.GroupId)
  2012. // } else {
  2013. // permissionCondition += ` AND b.group_id=? `
  2014. // permissionPars = append(permissionPars, sysUser.GroupId)
  2015. // }
  2016. // }
  2017. // }
  2018. // }
  2019. // }
  2020. //
  2021. // //if status == utils.COMPANY_STATUS_FREEZE {
  2022. // // condition += ` AND b.seller_id=? `
  2023. // // pars = append(pars, sysUser.AdminId)
  2024. // //
  2025. // // //permissionCondition += ` AND b.seller_id=? `
  2026. // // //permissionPars = append(permissionPars, sysUser.AdminId)
  2027. // //}
  2028. // //if status == "全部" || status == utils.COMPANY_STATUS_FREEZE {
  2029. // // freezeCondition += ` AND b.seller_id=? `
  2030. // // freezePars = append(freezePars, sysUser.AdminId)
  2031. // //}
  2032. // if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  2033. // //freezeCondition += ` AND b.seller_id=? `
  2034. // //freezePars = append(freezePars, sysUser.AdminId)
  2035. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  2036. // permissionCondition += ` AND b.product_id=? `
  2037. // permissionPars = append(permissionPars, 1)
  2038. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  2039. // permissionCondition += ` AND b.product_id=? `
  2040. // permissionPars = append(permissionPars, 2)
  2041. // } else {
  2042. // if status == utils.COMPANY_STATUS_FREEZE {
  2043. // condition += ` AND b.seller_id=? `
  2044. // pars = append(pars, sysUser.AdminId)
  2045. // }
  2046. //
  2047. // freezeCondition += ` AND b.seller_id=? `
  2048. // freezePars = append(freezePars, sysUser.AdminId)
  2049. // }
  2050. // }
  2051. //
  2052. // total, err := company.GetCompanyListCount(condition, pars)
  2053. // if err != nil {
  2054. // br.Msg = "获取失败"
  2055. // br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  2056. // return
  2057. // }
  2058. //
  2059. // sortStr := ``
  2060. // if sortParam != "" && sortType != "" {
  2061. // if sortParam == "endDate" {
  2062. // sortStr = " ORDER BY b.end_date "
  2063. // } else if sortParam == "createTime" {
  2064. // sortStr = " ORDER BY a.created_time "
  2065. // } else {
  2066. // br.Msg = "获取失败"
  2067. // br.ErrMsg = "排序字段传入数据异常:" + sortParam
  2068. // return
  2069. // }
  2070. //
  2071. // if sortType == "asc" {
  2072. // sortStr += " ASC "
  2073. // } else if sortType == "desc" {
  2074. // sortStr += " DESC "
  2075. // } else {
  2076. // br.Msg = "获取失败"
  2077. // br.ErrMsg = "排序类型传入数据异常:" + sortType
  2078. // return
  2079. // }
  2080. // }
  2081. //
  2082. // list, err := company.GetCompanyList(condition, status, sortStr, pars, startSize, pageSize)
  2083. // if err != nil {
  2084. // br.Msg = "获取失败"
  2085. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  2086. // return
  2087. // }
  2088. //
  2089. //
  2090. // //企业用户数组切片
  2091. // companyIdSlice := make([]string, 0)
  2092. // for _, v := range list {
  2093. // companyIdSlice = append(companyIdSlice, strconv.Itoa(v.CompanyId))
  2094. // }
  2095. //
  2096. // //企业用户产品开通数
  2097. // companyIdStr := strings.Join(companyIdSlice, ",")
  2098. // companyProductTotalList, _ := company.GetCountProductByCompanyIds(companyIdStr)
  2099. // companyProductTotalMap := make(map[int]*company.CompanyProductTotalSlice)
  2100. // for _, companyProductTotal := range companyProductTotalList {
  2101. // companyProductTotalMap[companyProductTotal.CompanyId] = companyProductTotal
  2102. // }
  2103. // lenList := len(list)
  2104. // for i := 0; i < lenList; i++ {
  2105. // item := list[i]
  2106. //
  2107. // //校验该客户是否存在多个产品,如果是,那么代表是共享客户
  2108. // if companyProductTotal, ok := companyProductTotalMap[int(item.CompanyId)]; ok {
  2109. // if companyProductTotal.Total > 1 {
  2110. // list[i].IsShared = true
  2111. // }
  2112. // }
  2113. //
  2114. // var expireDay string
  2115. // itemStatus := item.Status
  2116. // if itemStatus != "" {
  2117. // if !strings.Contains(item.Status, "/") {
  2118. // if itemStatus == utils.COMPANY_STATUS_FOREVER { //永续
  2119. // expireDay = "-"
  2120. // } else if itemStatus == utils.COMPANY_STATUS_TRY_OUT || itemStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  2121. // if item.StartDate != "" && item.EndDate != "" {
  2122. // endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  2123. // endDateTime = endDateTime.AddDate(0, 0, 1)
  2124. // sub := endDateTime.Sub(time.Now())
  2125. // if sub < 0 {
  2126. // sub = 0
  2127. // }
  2128. // expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2129. // } else {
  2130. // expireDay = "-"
  2131. // }
  2132. // } else if itemStatus == utils.COMPANY_STATUS_LOSE {
  2133. // expireDay = "-"
  2134. // } else if itemStatus == utils.COMPANY_STATUS_FREEZE {
  2135. // if item.StartDate != "" && item.EndDate != "" {
  2136. // endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  2137. // endDateTime = endDateTime.AddDate(0, 0, 0)
  2138. // sub := endDateTime.Sub(time.Now())
  2139. // if sub < 0 {
  2140. // sub = 0
  2141. // }
  2142. // expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2143. // } else {
  2144. // expireDay = "-"
  2145. // }
  2146. // } else {
  2147. // expireDay = "-"
  2148. // }
  2149. // } else {
  2150. // statusArr := strings.Split(item.Status, "/")
  2151. // ficcStatus := statusArr[0]
  2152. // raiStatus := statusArr[1]
  2153. // var ficcEndDate, tryEndDate string
  2154. // var ficcExpireDay, tryExpireDay string
  2155. // if item.EndDate != "" {
  2156. // endDateArr := strings.Split(item.EndDate, "/")
  2157. // if len(endDateArr) == 1 {
  2158. // ficcEndDate = endDateArr[0]
  2159. // } else if len(endDateArr) > 1 {
  2160. // ficcEndDate = endDateArr[0]
  2161. // tryEndDate = endDateArr[1]
  2162. // }
  2163. // if ficcStatus == utils.COMPANY_STATUS_FOREVER { //永续
  2164. // ficcExpireDay = "-"
  2165. // } else if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  2166. // if ficcEndDate != "" {
  2167. // endDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
  2168. // endDateTime = endDateTime.AddDate(0, 0, 1)
  2169. // sub := endDateTime.Sub(time.Now())
  2170. // if sub < 0 {
  2171. // sub = 0
  2172. // }
  2173. // ficcExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2174. // } else {
  2175. // ficcExpireDay = "-"
  2176. // }
  2177. // } else if ficcStatus == utils.COMPANY_STATUS_LOSE { //流失
  2178. // ficcExpireDay = "-"
  2179. // } else if ficcStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  2180. // if item.StartDate != "" && item.EndDate != "" {
  2181. // endDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
  2182. // endDateTime = endDateTime.AddDate(0, 0, 0)
  2183. // sub := endDateTime.Sub(time.Now())
  2184. // if sub < 0 {
  2185. // sub = 0
  2186. // }
  2187. // ficcExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2188. // } else {
  2189. // ficcExpireDay = "-"
  2190. // }
  2191. // } else {
  2192. // ficcExpireDay = "-"
  2193. // }
  2194. //
  2195. // if raiStatus == utils.COMPANY_STATUS_FOREVER { //永续
  2196. // tryExpireDay = "-"
  2197. // } else if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  2198. // if tryEndDate != "" {
  2199. // endDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
  2200. // endDateTime = endDateTime.AddDate(0, 0, 1)
  2201. // sub := endDateTime.Sub(time.Now())
  2202. // if sub < 0 {
  2203. // sub = 0
  2204. // }
  2205. // tryExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2206. // } else {
  2207. // tryExpireDay = "-"
  2208. // }
  2209. // } else if raiStatus == utils.COMPANY_STATUS_LOSE { //流失
  2210. // tryExpireDay = "-"
  2211. // } else if raiStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  2212. // if item.StartDate != "" && item.EndDate != "" {
  2213. // endDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
  2214. // endDateTime = endDateTime.AddDate(0, 0, 0)
  2215. // sub := endDateTime.Sub(time.Now())
  2216. // if sub < 0 {
  2217. // sub = 0
  2218. // }
  2219. // tryExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2220. // } else {
  2221. // tryExpireDay = "-"
  2222. // }
  2223. // } else {
  2224. // tryExpireDay = "-"
  2225. // }
  2226. // }
  2227. // expireDay = ficcExpireDay + "/" + tryExpireDay
  2228. // }
  2229. // }
  2230. // list[i].ExpireDay = expireDay
  2231. //
  2232. // //按钮显示控制
  2233. // btnItem := new(company.ButtonPermission)
  2234. // if item.CompanyId != 1 {
  2235. // *btnItem = services.GetCompanyPermissionButton(roleTypeCode, itemStatus, item.GroupIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId)
  2236. // }
  2237. // list[i].BtnItem = btnItem
  2238. // if item.FreezeStartDate != "" && item.FreezeEndDate != "" && item.Status == utils.COMPANY_STATUS_FREEZE {
  2239. // freezeEndDate, _ := time.Parse(utils.FormatDate, item.FreezeEndDate)
  2240. // if time.Now().Before(freezeEndDate) {
  2241. // expireDays := freezeEndDate.Sub(time.Now()).Hours() / 24
  2242. // list[i].FreezeExpireDays = int(expireDays) + 1
  2243. // }
  2244. // }
  2245. // }
  2246. //
  2247. // statusCount, err := company.GetCompanyStatusCount(permissionCondition, permissionPars)
  2248. // if err != nil {
  2249. // br.Msg = "获取失败"
  2250. // br.ErrMsg = "获取状态数量失败,Err:" + err.Error()
  2251. // return
  2252. // }
  2253. //
  2254. // statusMap := make(map[string]int, 0)
  2255. // var totalCount int
  2256. // for _, sv := range statusCount {
  2257. // totalCount = totalCount + sv.Count
  2258. // statusMap[sv.Status] = sv.Count
  2259. // }
  2260. //
  2261. // lossItem, err := company.GetCompanyStatusLoseCount(lossCondition, lossPars)
  2262. // if err != nil {
  2263. // br.Msg = "获取失败"
  2264. // br.ErrMsg = "获取流失状态数量失败,Err:" + err.Error()
  2265. // return
  2266. // }
  2267. // totalCount = totalCount + lossItem.Count
  2268. //
  2269. // freezeItem, err := company.GetCompanyStatusFreezeCount(freezeCondition, freezePars)
  2270. // if err != nil {
  2271. // br.Msg = "获取失败"
  2272. // br.ErrMsg = "获取冻结状态数量失败,Err:" + err.Error()
  2273. // return
  2274. // }
  2275. // statusMap["冻结"] = freezeItem.Count
  2276. // totalCount = totalCount + freezeItem.Count
  2277. //
  2278. // forverItem, err := company.GetCompanyStatusForverCount(forverCondition, forverPars)
  2279. // if err != nil {
  2280. // br.Msg = "获取失败"
  2281. // br.ErrMsg = "获取永续状态数量失败,Err:" + err.Error()
  2282. // return
  2283. // }
  2284. // totalCount = totalCount + forverItem.Count
  2285. //
  2286. // for _, v := range statusArr {
  2287. // statusCount := new(company.CompanyStatus)
  2288. // if v == "全部" {
  2289. // statusCount.Status = "全部"
  2290. // statusCount.Count = totalCount
  2291. // } else if v == utils.COMPANY_STATUS_LOSE {
  2292. // statusCount.Status = v
  2293. // statusCount.Count = lossItem.Count
  2294. // } else if v == utils.COMPANY_STATUS_FOREVER {
  2295. // statusCount.Status = v
  2296. // statusCount.Count = forverItem.Count
  2297. // //} else if v == utils.COMPANY_STATUS_FREEZE {
  2298. // // statusCount.Status = v
  2299. // // statusCount.Count = freezeItem.Count
  2300. // //}
  2301. // } else {
  2302. // statusCount.Status = v
  2303. // if val, ok := statusMap[v]; ok {
  2304. // statusCount.Count = val
  2305. // }
  2306. // }
  2307. // statusItems = append(statusItems, statusCount)
  2308. // }
  2309. //
  2310. // companyLists := make([]*company.CompanyListItem, 0)
  2311. // //查询阅读次数
  2312. // if list == nil {
  2313. // companyLists = make([]*company.CompanyListItem, 0)
  2314. // } else {
  2315. // for _, v := range list {
  2316. // viewTotal := GetviewTotal(v.CompanyId)
  2317. // companyList := &company.CompanyListItem{
  2318. // CompanyId: v.CompanyId,
  2319. // CompanyName: v.CompanyName,
  2320. // CreditCode: v.CreditCode,
  2321. // CompanyCode: v.CompanyCode,
  2322. // StartDate: v.StartDate,
  2323. // EndDate: v.EndDate,
  2324. // LoseReason: v.LoseReason,
  2325. // RenewalReason: v.RenewalReason,
  2326. // FreezeReason: v.FreezeReason,
  2327. // LossTime: v.LossTime,
  2328. // Status: v.Status,
  2329. // CompanyType: v.CompanyType,
  2330. // ApproveStatus: v.ApproveStatus,
  2331. // SellerName: v.SellerName,
  2332. // SellerId: v.SellerId,
  2333. // SellerIds: v.SellerIds,
  2334. // ExpireDay: v.ExpireDay,
  2335. // FreezeTime: v.FreezeTime,
  2336. // GroupId: v.GroupId,
  2337. // GroupIds: v.GroupIds,
  2338. // DepartmentId: v.DepartmentId,
  2339. // IndustryName: v.IndustryName,
  2340. // IsSuspend: v.IsSuspend,
  2341. // CreatedTime: v.CreatedTime,
  2342. // Source: v.Source,
  2343. // Province: v.Province,
  2344. // City: v.City,
  2345. // Address: v.Address,
  2346. // Reasons: v.Reasons,
  2347. // FreezeStartDate: v.FreezeStartDate,
  2348. // FreezeEndDate: v.FreezeEndDate,
  2349. // FreezeExpireDays: v.FreezeExpireDays,
  2350. // BtnItem: v.BtnItem,
  2351. // ProductId: v.ProductId,
  2352. // FormalTime: v.FormalTime,
  2353. // IsShared: v.IsShared,
  2354. // RegionType: v.RegionType,
  2355. // FiccView: viewTotal[0],
  2356. // RaiView: viewTotal[1],
  2357. // }
  2358. // companyLists = append(companyLists, companyList)
  2359. // }
  2360. // }
  2361. // if companyLists == nil {
  2362. // companyLists = make([]*company.CompanyListItem, 0)
  2363. // }
  2364. // page = paging.GetPaging(currentIndex, pageSize, total)
  2365. // resp.List = companyLists
  2366. // resp.StatusCount = statusItems
  2367. // resp.Paging = page
  2368. // br.Ret = 200
  2369. // br.Success = true
  2370. // br.Msg = "获取成功"
  2371. // br.Data = resp
  2372. //}
  2373. func GetviewTotal(companyId int) (view []int) {
  2374. list, err := company.GetCompanyUserListById(companyId)
  2375. if err != nil {
  2376. fmt.Println("GetCompanyUserList err:", err.Error())
  2377. return
  2378. }
  2379. //获取企业客户信息
  2380. companyInfo, err := company.GetCompanyById(companyId)
  2381. if err != nil {
  2382. fmt.Println("GetCompanyById err:", err.Error())
  2383. return
  2384. }
  2385. var ficcViewTotal, cygxViewTotal int
  2386. lenList := len(list)
  2387. if lenList > 0 {
  2388. userIdSlice := make([]string, 0)
  2389. mobilesSlice := make([]string, 0)
  2390. emailsSlice := make([]string, 0)
  2391. for _, v := range list {
  2392. userIdSlice = append(userIdSlice, strconv.Itoa(int(v.UserId)))
  2393. if v.Mobile != "" {
  2394. mobilesSlice = append(mobilesSlice, v.Mobile)
  2395. } else if v.Email != "" {
  2396. emailsSlice = append(emailsSlice, v.Email)
  2397. }
  2398. }
  2399. //用户浏览数据
  2400. mobileStr := strings.Join(mobilesSlice, "','")
  2401. mobileStr = "'" + mobileStr + "'"
  2402. emailStr := strings.Join(emailsSlice, "','")
  2403. emailStr = "'" + emailStr + "'"
  2404. //报告统计删除晨报部分统计加入每日资讯 2021-4-9
  2405. //手机号
  2406. userViewMobileTotalMap := make(map[string]*models.UserViewMobileTotalSlice)
  2407. userReportViewMobileTotalMap := make(map[string]*models.ReportViewMobileRecord)
  2408. userAdvisoryViewMobileTotalMap := make(map[string]*advisory.UserViewMobileTotalSlice)
  2409. userCygxArticleHistoryRecordViewMobileTotalMap := make(map[string]*models.UserViewMobileTotalSlice)
  2410. if len(mobilesSlice) > 0 {
  2411. //权益数据
  2412. rightsItems, err := company.GetRightsReportListByMobile(mobileStr)
  2413. if err != nil {
  2414. fmt.Println("GetRightsReportListByMobile err:", err.Error())
  2415. return
  2416. }
  2417. cygxViewTotal = len(rightsItems)
  2418. //FICC数据
  2419. ficcItems, err := company.GetFiccReportListByMobile(mobileStr)
  2420. if err != nil {
  2421. fmt.Println("GetFiccReportListByMobile err:", err.Error())
  2422. return
  2423. }
  2424. ficcViewTotal = len(ficcItems)
  2425. }
  2426. //邮箱
  2427. userViewEmailTotalMap := make(map[string]*models.UserViewEmailTotalSlice)
  2428. userReportViewEmailTotalMap := make(map[string]*models.ReportViewEmailRecord)
  2429. userAdvisoryViewEmailTotalMap := make(map[string]*advisory.UserViewEmailTotalSlice)
  2430. userCygxViewEmailTotalMap := make(map[string]*models.UserViewEmailTotalSlice)
  2431. if len(emailsSlice) > 0 {
  2432. //FICC数据
  2433. ficcItems, err := company.GetFiccReportListByEmail(emailStr)
  2434. if err != nil {
  2435. fmt.Println("GetFiccReportListByEmail err:", err.Error())
  2436. return
  2437. }
  2438. ficcViewTotal += len(ficcItems)
  2439. //权益数据
  2440. rightsItems, err := company.GetRightsReportListByEmail(emailStr)
  2441. if err != nil {
  2442. fmt.Println("GetViewReportListByMobile err:", err.Error())
  2443. return
  2444. }
  2445. cygxViewTotal += len(rightsItems)
  2446. }
  2447. for i := 0; i < lenList; i++ {
  2448. item := list[i]
  2449. //企业名称
  2450. list[i].CompanyName = companyInfo.CompanyName
  2451. //手机号用户累计浏览次数
  2452. if userView, ok := userViewMobileTotalMap[item.Mobile]; ok {
  2453. list[i].ViewTotal += userView.Total
  2454. }
  2455. //邮箱用户累计浏览次数
  2456. if userView, ok := userViewEmailTotalMap[item.Email]; ok {
  2457. //总共浏览的报表数据需要调整为(手机号用户浏览晨报数+邮箱号用户浏览晨报数)
  2458. list[i].ViewTotal += userView.Total
  2459. }
  2460. if item.OpenId != "" {
  2461. list[i].IsRegister = true
  2462. } else {
  2463. if item.RegisterPlatform == 2 {
  2464. if item.Mobile != "" || item.Email != "" {
  2465. list[i].IsRegister = true
  2466. }
  2467. } else if item.RegisterTime != "" {
  2468. list[i].IsRegister = true
  2469. } else {
  2470. list[i].IsRegister = false
  2471. }
  2472. }
  2473. //如果存在手机号用户日评数据,那么需要做处理
  2474. if reportView, ok := userReportViewMobileTotalMap[item.Mobile]; ok {
  2475. //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
  2476. if reportView.LastViewTime.After(list[i].LastViewTime) {
  2477. list[i].LastViewTime = reportView.LastViewTime
  2478. list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
  2479. }
  2480. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
  2481. list[i].ViewTotal += reportView.ViewTotal
  2482. }
  2483. //如果存在手机号用户日评数据,那么需要做处理
  2484. if reportView, ok := userReportViewEmailTotalMap[item.Email]; ok {
  2485. //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
  2486. if reportView.LastViewTime.After(list[i].LastViewTime) {
  2487. list[i].LastViewTime = reportView.LastViewTime
  2488. list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
  2489. }
  2490. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
  2491. list[i].ViewTotal += reportView.ViewTotal
  2492. }
  2493. //如果存在手机号用户每日资讯,那么需要做处理
  2494. if advisoryView, ok := userAdvisoryViewMobileTotalMap[item.Mobile]; ok {
  2495. //fmt.Println("蝴蝶眨几次眼睛")
  2496. //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  2497. if advisoryView.CreatedTime.After(list[i].LastViewTime) {
  2498. list[i].LastViewTime = advisoryView.CreatedTime
  2499. list[i].LastViewTimeStr = advisoryView.CreatedTime.Format(utils.FormatDateTime)
  2500. }
  2501. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数)
  2502. list[i].ViewTotal += advisoryView.Total
  2503. }
  2504. //如果存在邮箱号用户每日资讯,那么需要做处理
  2505. if advisoryView, ok := userAdvisoryViewEmailTotalMap[item.Email]; ok {
  2506. //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  2507. if advisoryView.CreatedTime.After(list[i].LastViewTime) {
  2508. list[i].LastViewTime = advisoryView.CreatedTime
  2509. list[i].LastViewTimeStr = advisoryView.CreatedTime.Format(utils.FormatDateTime)
  2510. }
  2511. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数)
  2512. list[i].ViewTotal += advisoryView.Total
  2513. }
  2514. ficcViewTotal += list[i].ViewTotal
  2515. //如果存在手机号用户查研观向,那么需要做处理
  2516. if cygxView, ok := userCygxArticleHistoryRecordViewMobileTotalMap[item.Mobile]; ok {
  2517. //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  2518. if cygxView.CreatedTime.After(list[i].LastViewTime) {
  2519. list[i].LastViewTime = cygxView.CreatedTime
  2520. list[i].LastViewTimeStr = cygxView.CreatedTime.Format(utils.FormatDateTime)
  2521. }
  2522. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数+查研观向)
  2523. cygxViewTotal += cygxView.Total
  2524. list[i].ViewTotal += cygxView.Total
  2525. }
  2526. //如果存在邮箱号用户查研观向,那么需要做处理
  2527. if cygxView, ok := userCygxViewEmailTotalMap[item.Email]; ok {
  2528. //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  2529. if cygxView.CreatedTime.After(list[i].LastViewTime) {
  2530. list[i].LastViewTime = cygxView.CreatedTime
  2531. list[i].LastViewTimeStr = cygxView.CreatedTime.Format(utils.FormatDateTime)
  2532. }
  2533. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数+查研观向)
  2534. cygxViewTotal += cygxView.Total
  2535. //list[i].ViewTotal += cygxView.Total
  2536. }
  2537. /*if reportView, ok := userReportViewTotalMap[int(item.UserId)]; ok {
  2538. //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
  2539. if reportView.LastViewTime.After(list[i].LastViewTime) {
  2540. list[i].LastViewTime = reportView.LastViewTime
  2541. list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
  2542. }
  2543. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
  2544. list[i].ViewTotal += reportView.ViewTotal
  2545. }*/
  2546. }
  2547. }
  2548. view = append(view, ficcViewTotal)
  2549. view = append(view, cygxViewTotal)
  2550. return
  2551. }
  2552. // @Title 新增客户
  2553. // @Description 新增客户接口
  2554. // @Param request body company.CompanyAddReq true "type json string"
  2555. // @Success 200 {object} company.CompanyAddResp
  2556. // @router /add [post]
  2557. func (this *CompanyController) Add() {
  2558. br := new(models.BaseResponse).Init()
  2559. defer func() {
  2560. this.Data["json"] = br
  2561. this.ServeJSON()
  2562. }()
  2563. sysUser := this.SysUser
  2564. if sysUser == nil {
  2565. br.Msg = "请登录"
  2566. br.ErrMsg = "请登录,SysUser Is Empty"
  2567. br.Ret = 408
  2568. return
  2569. }
  2570. roleTypeCode := sysUser.RoleTypeCode
  2571. var req company.CompanyAddReq
  2572. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2573. if err != nil {
  2574. br.Msg = "参数解析异常!"
  2575. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2576. return
  2577. }
  2578. if req.CompanyName == "" {
  2579. br.Msg = "请填写客户名称"
  2580. return
  2581. }
  2582. if req.CreditCode == "" {
  2583. br.Msg = "请填写社会统一信用码"
  2584. return
  2585. }
  2586. if req.Status == "" {
  2587. br.Msg = "客户状态不可为空"
  2588. return
  2589. }
  2590. //移除空格
  2591. req.CreditCode = utils.TrimStr(req.CreditCode)
  2592. var startDateTime, endDateTime time.Time
  2593. if req.Status == utils.COMPANY_STATUS_TRY_OUT {
  2594. startDateTime = time.Now()
  2595. endDateTime = time.Now().AddDate(0, 2, 0)
  2596. } else if req.Status == utils.COMPANY_STATUS_FOREVER {
  2597. startDateTime = time.Now()
  2598. endDateTime = time.Now().AddDate(100, 0, 0)
  2599. } else {
  2600. br.Msg = "无效的客户状态,请重新选择"
  2601. return
  2602. }
  2603. var startDate, endDate string
  2604. startDate = startDateTime.Format(utils.FormatDate)
  2605. endDate = endDateTime.Format(utils.FormatDate)
  2606. if req.CompanyType == "" {
  2607. br.Msg = "请选择客户类型"
  2608. return
  2609. }
  2610. var productId int
  2611. var productName string
  2612. if req.CompanyType == utils.COMPANY_PRODUCT_FICC_NAME {
  2613. productId = utils.COMPANY_PRODUCT_FICC_ID
  2614. productName = utils.COMPANY_PRODUCT_FICC_NAME
  2615. } else if req.CompanyType == utils.COMPANY_PRODUCT_RAI_NAME {
  2616. productId = utils.COMPANY_PRODUCT_RAI_ID
  2617. productName = utils.COMPANY_PRODUCT_RAI_NAME
  2618. } else {
  2619. br.Msg = "无效的客户类型,请重新选择"
  2620. return
  2621. }
  2622. if req.IndustryId <= 0 {
  2623. br.Msg = "请选择行业"
  2624. return
  2625. }
  2626. if req.SellsId <= 0 {
  2627. br.Msg = "请选择所属销售"
  2628. return
  2629. }
  2630. //if req.Reasons == "" {
  2631. // br.Msg = "请填写新增理由"
  2632. // return
  2633. //}
  2634. if req.PermissionIds == "" {
  2635. br.Msg = "请选择权限"
  2636. return
  2637. } else {
  2638. permissionStr, err := company.GetPermissionIdById(req.PermissionIds)
  2639. if err != nil {
  2640. br.Msg = "获取信息失败"
  2641. br.ErrMsg = "获取主观客观权限信息失败,Err:" + err.Error()
  2642. return
  2643. }
  2644. req.PermissionIds = permissionStr
  2645. }
  2646. industry, err := company.GetCompanyIndustryById(req.IndustryId)
  2647. if err != nil {
  2648. br.Msg = "获取行业信息失败"
  2649. br.ErrMsg = "获取行业信息失败,Err:" + err.Error()
  2650. return
  2651. }
  2652. if industry == nil {
  2653. br.Msg = "行业信息不存在"
  2654. return
  2655. }
  2656. //判断客户是否已经存在
  2657. companyNameIsExist, err := company.GetCompanyCountByCompanyName(req.CompanyName)
  2658. if err != nil {
  2659. br.Msg = "判断客户是否存在失败"
  2660. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  2661. return
  2662. }
  2663. if companyNameIsExist > 0 {
  2664. br.Msg = "客户已存在,请重新输入客户名称"
  2665. return
  2666. }
  2667. //判断客户是否已经存在
  2668. companyCreditCodeIsExist, err := company.GetCompanyCountByCreditCode(req.CreditCode)
  2669. if err != nil {
  2670. br.Msg = "判断客户是否存在失败"
  2671. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  2672. return
  2673. }
  2674. if companyCreditCodeIsExist > 0 {
  2675. br.Msg = "客户已存在,统一社会信用代码"
  2676. return
  2677. }
  2678. seller, err := system.GetSysAdminById(req.SellsId)
  2679. if err != nil {
  2680. br.Msg = "获取销售信息失败"
  2681. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  2682. return
  2683. }
  2684. tryOutCount, err := company.GetCompanyTryOutCount(utils.COMPANY_STATUS_TRY_OUT, seller.AdminId)
  2685. if err != nil {
  2686. br.Msg = "判断试用客户量失败"
  2687. br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  2688. return
  2689. }
  2690. /*
  2691. ROLE_TYPE_CODE_ADMIN = "admin" //管理员
  2692. ROLE_TYPE_CODE_FICC_ADMIN = "ficc_admin" //ficc管理员
  2693. ROLE_TYPE_CODE_FICC_SELLER = "ficc_seller" //ficc销售
  2694. ROLE_TYPE_CODE_RAI_ADMIN = "rai_admin" //权益管理员
  2695. ROLE_TYPE_CODE_RAI_SELLER = "rai_seller" //权益销售
  2696. ROLE_TYPE_CODE_FICC_GROUP = "ficc_group" //ficc组长
  2697. ROLE_TYPE_CODE_RAI_GROUP = "rai_group" //ficc组长
  2698. ROLE_TYPE_CODE_FICC_DEPARTMENT = "ficc_department" //ficc部门经理
  2699. ROLE_TYPE_CODE_RAI_DEPARTMENT = "rai_department" //权益部门经理
  2700. ROLE_TYPE_CODE_FICC_RESEARCHR = "ficc_researcher" //ficc研究员
  2701. ROLE_TYPE_CODE_RAI_RESEARCHR = "rai_researcher" //权益研究员
  2702. */
  2703. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
  2704. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  2705. if tryOutCount >= utils.COMPANY_STATUS_TRY_OUT_COUNT {
  2706. br.Msg = "您的试用客户总数,已超过上限,不可继续新增"
  2707. return
  2708. }
  2709. }
  2710. //// 每个权益销售手中的试用客户最多30个
  2711. //if productId == utils.COMPANY_PRODUCT_RAI_ID && tryOutCount >= utils.COMPANY_STATUS_TRY_OUT_COUNT_RAI {
  2712. // br.Msg = "您的试用客户总数,已超过上限,不可继续新增"
  2713. // return
  2714. //}
  2715. //如果是权益客户,在选择非研选行业试用时,需要判断当前有多少非研选的试用客户(试用状态,且行业是非研选)
  2716. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  2717. permissionArr := strings.Split(req.PermissionIds, ",")
  2718. //如果所选行业不属于研选订阅跟研选扣点包,那就是非研选试用客户
  2719. var isNoResearch bool
  2720. for _, v := range permissionArr {
  2721. if v != strconv.Itoa(utils.CHART_PERMISSION_ID_YANXUAN) && v != strconv.Itoa(utils.YAN_XUAN_KOU_DIAN_BAO_ID) {
  2722. isNoResearch = true
  2723. continue
  2724. }
  2725. }
  2726. if isNoResearch {
  2727. tryOutCountRai, err := company.GetRaiCompanyTryOutCountNoResearch(seller.AdminId)
  2728. if err != nil {
  2729. br.Msg = "判断试用客户量失败"
  2730. br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  2731. return
  2732. }
  2733. if tryOutCountRai >= utils.COMPANY_STATUS_TRY_OUT_COUNT_RAI {
  2734. br.Msg = "非研选试用客户最多40家"
  2735. return
  2736. }
  2737. }
  2738. }
  2739. if seller == nil {
  2740. br.Msg = "所属销售不存在"
  2741. return
  2742. }
  2743. companyCode, err := company.GetCompanyCode()
  2744. if err != nil {
  2745. br.Msg = "获取客户编码信息失败"
  2746. br.ErrMsg = "获取客户编码信息失败,Err:" + err.Error()
  2747. return
  2748. }
  2749. item := new(company.Company)
  2750. item.CompanyName = req.CompanyName
  2751. item.CreditCode = req.CreditCode
  2752. item.CompanyCode = companyCode
  2753. item.Province = req.Province
  2754. item.City = req.City
  2755. item.Address = req.Province + req.City
  2756. item.StartDate = time.Now().Format(utils.FormatDate)
  2757. if req.Status == utils.COMPANY_STATUS_FOREVER {
  2758. item.EndDate = time.Now().AddDate(100, 0, 0).Format(utils.FormatDate)
  2759. item.CompanyType = 5
  2760. }
  2761. if req.Status == utils.COMPANY_STATUS_TRY_OUT {
  2762. item.EndDate = time.Now().AddDate(0, 2, 0).Format(utils.FormatDate)
  2763. item.CompanyType = 2
  2764. }
  2765. item.FirstStartDate = item.StartDate
  2766. item.FirstEndDate = item.EndDate
  2767. item.CreatedTime = time.Now()
  2768. item.LastUpdatedTime = time.Now()
  2769. item.Enabled = 1
  2770. item.RegionType = req.RegionType
  2771. item.Remark = req.Reasons
  2772. item.Nation = req.Nation
  2773. item.OverseasStatus = "试用"
  2774. item.ResetBtn = 1
  2775. companyId, err := company.AddCompany(item)
  2776. if err != nil {
  2777. br.Msg = "新增失败"
  2778. br.ErrMsg = "新增失败,err:" + err.Error()
  2779. return
  2780. }
  2781. item.CompanyId = int(companyId)
  2782. //生成第三方code编号
  2783. item.OpenCompanyCode = services.GenerateOpenCompanyCode(int(companyId))
  2784. item.Update([]string{"OpenCompanyCode"})
  2785. if req.UserId > 0 {
  2786. //修改联系人
  2787. err = company.ModifyCompanyUserCompanyId(req.UserId, int(companyId))
  2788. if err != nil {
  2789. br.Msg = "新增失败"
  2790. br.ErrMsg = "新增失败,ModifyCompanyUserCompanyId err:" + err.Error()
  2791. return
  2792. }
  2793. //获取联系人详情
  2794. userInfo, err := models.GetWxUserByUserId(req.UserId)
  2795. if err != nil {
  2796. br.Msg = "获取联系人异常!"
  2797. br.ErrMsg = "获取联系人异常,Err:" + err.Error()
  2798. return
  2799. }
  2800. //添加该联系人 与 当前销售的关系
  2801. models.AddUserSellerRelation(int64(req.UserId), int(companyId), seller.AdminId, productId, seller.RealName, userInfo.Mobile, userInfo.Email)
  2802. }
  2803. companyProduct := new(company.CompanyProduct)
  2804. companyProduct.CompanyId = int(companyId)
  2805. companyProduct.ProductId = productId
  2806. companyProduct.ProductName = productName
  2807. companyProduct.CompanyName = req.CompanyName
  2808. companyProduct.Source = req.Source
  2809. companyProduct.Reasons = req.Reasons
  2810. companyProduct.Status = req.Status
  2811. companyProduct.StartDate = startDate
  2812. companyProduct.EndDate = endDate
  2813. companyProduct.IndustryId = req.IndustryId
  2814. companyProduct.IndustryName = industry.IndustryName
  2815. companyProduct.SellerId = seller.AdminId
  2816. companyProduct.SellerName = seller.RealName
  2817. companyProduct.GroupId = seller.GroupId
  2818. companyProduct.DepartmentId = seller.DepartmentId
  2819. companyProduct.IsSuspend = 0
  2820. companyProduct.CreateTime = time.Now()
  2821. companyProduct.ModifyTime = time.Now()
  2822. companyProduct.CompanyType = req.CompanyType
  2823. companyProduct.Scale = req.Scale
  2824. companyProduct.OpenCode = services.GenerateOpenCompanyProductCode(int(companyId), productId)
  2825. companyProduct.TodoStatus = "无任务"
  2826. companyProduct.TryStage = 1
  2827. companyProduct.OverseasLabel = 1
  2828. if seller.Mobile == "13065778668" {
  2829. if req.RegionType == "海外" {
  2830. companyProduct.IsOverseas = 0
  2831. } else {
  2832. companyProduct.IsOverseas = 1
  2833. }
  2834. }
  2835. if productId == utils.COMPANY_PRODUCT_RAI_ID && req.Status == utils.COMPANY_STATUS_FOREVER { // 权益的永续客户给一个状态初始化的记录
  2836. companyProduct.InitStatus = req.Status
  2837. }
  2838. companyProduct.SellerIdInit = seller.AdminId
  2839. companyProduct.SellerNameInit = seller.RealName
  2840. companyProductId, err := company.AddCompanyProduct(companyProduct)
  2841. if err != nil {
  2842. br.Msg = "新增失败"
  2843. br.ErrMsg = "新增客户产品失败,err:" + err.Error()
  2844. return
  2845. }
  2846. companyReportPermissionList, err := services.AddCompanyPermission(int(companyId), seller.AdminId, productId, productName, seller.RealName, req.PermissionIds, startDate, endDate)
  2847. if err != nil {
  2848. br.Msg = "新增失败"
  2849. br.ErrMsg = "新增客户设置权限失败,err:" + err.Error()
  2850. return
  2851. }
  2852. {
  2853. record := new(company.CompanyOperationRecord)
  2854. record.CompanyId = int(companyId)
  2855. record.CompanyName = req.CompanyName
  2856. record.SellerId = seller.AdminId
  2857. record.SysUserId = seller.AdminId
  2858. record.SysRealName = seller.RealName
  2859. record.Remark = "新增客户"
  2860. record.Operation = "add"
  2861. record.CreateTime = time.Now()
  2862. record.ProductId = productId
  2863. record.ProductName = productName
  2864. record.Status = req.Status
  2865. _, err = company.AddCompanyOperationRecord(record)
  2866. if err != nil {
  2867. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  2868. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  2869. }
  2870. }
  2871. //新增客户日志
  2872. {
  2873. companyLog := new(company.CompanyLog)
  2874. companyLog.CompanyId = int(companyId)
  2875. companyLog.CompanyName = req.CompanyName
  2876. companyLog.CreditCode = req.CreditCode
  2877. companyLog.CompanyCode = companyCode
  2878. companyLog.Sort = item.Sort
  2879. companyLog.IsFeeCustomer = item.IsFeeCustomer
  2880. companyLog.Country = item.Country
  2881. companyLog.Address = item.Address
  2882. companyLog.City = item.City
  2883. companyLog.Province = item.Province
  2884. companyLog.Enabled = item.Enabled
  2885. companyLog.CreatedTime = item.CreatedTime
  2886. companyLog.LastUpdatedTime = item.LastUpdatedTime
  2887. companyLog.Seller = item.Seller
  2888. companyLog.SellsId = item.SellsId
  2889. companyLog.CompanyBelong = item.CompanyBelong
  2890. companyLog.StartDate = item.StartDate
  2891. companyLog.EndDate = item.EndDate
  2892. companyLog.FirstStartDate = item.FirstStartDate
  2893. companyLog.FirstEndDate = item.FirstEndDate
  2894. companyLog.DateType = item.DateType
  2895. companyLog.AdminId = this.SysUser.AdminId
  2896. companyLog.LogType = "add"
  2897. companyLog.LogCreateTime = time.Now()
  2898. go company.AddCompanyLog(companyLog)
  2899. }
  2900. //新增客户产品日志
  2901. {
  2902. productLog := new(company.CompanyProductLog)
  2903. productLog.CompanyProductId = int(companyProductId)
  2904. productLog.CompanyId = companyProduct.CompanyId
  2905. productLog.ProductId = companyProduct.ProductId
  2906. productLog.ProductName = companyProduct.ProductName
  2907. productLog.CompanyName = companyProduct.CompanyName
  2908. productLog.CompanyName = companyProduct.CompanyName
  2909. productLog.Source = companyProduct.Source
  2910. productLog.Reasons = companyProduct.Reasons
  2911. productLog.Status = companyProduct.Status
  2912. productLog.IndustryId = companyProduct.IndustryId
  2913. productLog.IndustryName = companyProduct.IndustryName
  2914. productLog.SellerId = companyProduct.SellerId
  2915. productLog.SellerName = companyProduct.SellerName
  2916. productLog.GroupId = companyProduct.GroupId
  2917. productLog.DepartmentId = companyProduct.DepartmentId
  2918. productLog.IsSuspend = companyProduct.IsSuspend
  2919. productLog.SuspendTime = companyProduct.SuspendTime
  2920. productLog.ApproveStatus = companyProduct.ApproveStatus
  2921. productLog.FreezeTime = companyProduct.FreezeTime
  2922. productLog.Remark = companyProduct.Remark
  2923. productLog.StartDate = companyProduct.StartDate
  2924. productLog.EndDate = companyProduct.EndDate
  2925. productLog.CreateTime = companyProduct.CreateTime
  2926. productLog.ModifyTime = companyProduct.ModifyTime
  2927. productLog.LoseReason = companyProduct.LoseReason
  2928. productLog.LossTime = companyProduct.LossTime
  2929. productLog.LogType = "add"
  2930. productLog.LogCreateTime = time.Now()
  2931. productLog.AdminId = this.SysUser.AdminId
  2932. productLog.Scale = companyProduct.Scale
  2933. go company.AddCompanyProductLog(productLog)
  2934. }
  2935. //新增客户产品状态变更日志
  2936. {
  2937. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  2938. Id: 0,
  2939. CompanyId: companyProduct.CompanyId,
  2940. ProductId: companyProduct.ProductId,
  2941. Status: "试用",
  2942. Source: "add",
  2943. SellerId: companyProduct.SellerId,
  2944. SellerName: companyProduct.SellerName,
  2945. StartDate: startDateTime,
  2946. EndDate: endDateTime,
  2947. RealEndDate: startDateTime,
  2948. CreateTime: time.Now(),
  2949. }
  2950. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  2951. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  2952. Id: 0,
  2953. CompanyId: companyProduct.CompanyId,
  2954. ProductId: companyProduct.ProductId,
  2955. Source: "add",
  2956. SellerId: companyProduct.SellerId,
  2957. SellerName: companyProduct.SellerName,
  2958. StartDate: startDateTime,
  2959. EndDate: endDateTime,
  2960. RealEndDate: startDateTime,
  2961. IsStop: 0,
  2962. CreateTime: time.Now(),
  2963. }
  2964. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  2965. }
  2966. resp := new(company.CompanyAddResp)
  2967. resp.CompanyId = int(companyId)
  2968. br.Ret = 200
  2969. br.Success = true
  2970. br.Msg = "新增成功"
  2971. br.Data = resp
  2972. }
  2973. // Detail
  2974. // @Title 获取客户详情
  2975. // @Description 获取客户详情接口
  2976. // @Param CompanyId query int true "客户id"
  2977. // @Success 200 {object} company.CompanyDetailResp
  2978. // @router /detail [get]
  2979. func (this *CompanyController) Detail() {
  2980. br := new(models.BaseResponse).Init()
  2981. defer func() {
  2982. this.Data["json"] = br
  2983. this.ServeJSON()
  2984. }()
  2985. sysUser := this.SysUser
  2986. if sysUser == nil {
  2987. br.Msg = "请登录"
  2988. br.ErrMsg = "请登录,SysUser Is Empty"
  2989. br.Ret = 408
  2990. return
  2991. }
  2992. companyId, _ := this.GetInt("CompanyId")
  2993. if companyId <= 0 {
  2994. br.Msg = "参数错误"
  2995. br.ErrMsg = "客户参数小于等于0"
  2996. return
  2997. }
  2998. // CRM8.8-是否为编辑页的客户详情
  2999. isEdit, _ := this.GetBool("IsEdit")
  3000. productId := services.GetProductId(sysUser.RoleTypeCode)
  3001. item, err := company.GetCompanyDetailById(companyId)
  3002. if err != nil {
  3003. br.Msg = "获取信息失败"
  3004. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  3005. return
  3006. }
  3007. shareSellerId := 0
  3008. shareGroupId := 0
  3009. var productItem *company.CompanyProduct
  3010. if productId > 0 {
  3011. var e error
  3012. productItem, e = company.GetCompanyProductByCompanyIdAndProductId(companyId, productId)
  3013. if e != nil && e.Error() != utils.ErrNoRow() {
  3014. br.Msg = "客户信息有误"
  3015. br.ErrMsg = "获取客户信息失败, Err: " + e.Error()
  3016. return
  3017. }
  3018. if productItem != nil {
  3019. shareSellerId = productItem.ShareSellerId
  3020. shareGroupId = productItem.ShareGroupId
  3021. }
  3022. }
  3023. var productName string
  3024. if productId == 1 {
  3025. productName = utils.COMPANY_PRODUCT_FICC_NAME
  3026. } else if productId == 2 {
  3027. productName = utils.COMPANY_PRODUCT_RAI_NAME
  3028. } else {
  3029. productName = "admin"
  3030. }
  3031. resp := new(company.CompanyDetailResp)
  3032. resp.ProductName = productName
  3033. //获取客户产品
  3034. productList, err := company.GetCompanyProductsByCompanyId(companyId)
  3035. if err != nil {
  3036. br.Msg = "获取信息失败"
  3037. br.ErrMsg = "获取产品信息失败,Err:" + err.Error()
  3038. return
  3039. }
  3040. roleTypeCode := sysUser.RoleTypeCode
  3041. itemLen := len(productList)
  3042. btnDetailItem := new(company.ButtonDetailPermission)
  3043. // 客户权限校验
  3044. {
  3045. // 如果不是超管、ficc管理员、权益管理员,那么需要额外校验下权限
  3046. if !utils.InArrayByStr([]string{utils.ROLE_TYPE_CODE_ADMIN, utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_RAI_ADMIN}, sysUser.RoleTypeCode) {
  3047. var isOk bool //是否有权限
  3048. var companyHasProduct bool // 客户当前是否有该产品权限
  3049. for _, productInfo := range productList {
  3050. // 只校验拥有的品种权限:ficc或者权益
  3051. if productInfo.ProductId == productId {
  3052. companyHasProduct = true
  3053. // 自己的客户有权限看
  3054. if productInfo.SellerId == sysUser.AdminId {
  3055. isOk = true
  3056. break
  3057. }
  3058. // 流失客户都有权限看
  3059. if productInfo.Status == utils.COMPANY_STATUS_LOSE || productInfo.Status == utils.COMPANY_STATUS_CLOSE {
  3060. isOk = true
  3061. break
  3062. }
  3063. // 分享的客户 也有权限
  3064. if productItem.IsShare == 1 && productItem.ShareSellerId == sysUser.AdminId {
  3065. isOk = true
  3066. break
  3067. }
  3068. // 分享的客户的组长 也有权限
  3069. if productItem.IsShare == 1 && productItem.ShareGroupId == sysUser.GroupId {
  3070. isOk = true
  3071. break
  3072. }
  3073. // 如果是组长,且该客户属于本组客户
  3074. if sysUser.Authority == 4 && productInfo.GroupId > 0 && productInfo.GroupId == sysUser.GroupId && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM {
  3075. isOk = true
  3076. break
  3077. }
  3078. // 如果是ficc主管或者权益主管
  3079. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  3080. // 获取顶级分组Id
  3081. var sysUserGroupPid, productGroupPid int
  3082. // 当前账号的顶级分组id
  3083. {
  3084. sysUserGroupIdpid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  3085. if err != nil && err.Error() != utils.NotEmpty() {
  3086. break
  3087. }
  3088. if sysUserGroupIdpid == nil || *sysUserGroupIdpid == 0 {
  3089. sysUserGroupPid = sysUser.GroupId
  3090. } else {
  3091. sysUserGroupPid = *sysUserGroupIdpid
  3092. }
  3093. }
  3094. // 当前客户的顶级分组id
  3095. {
  3096. groupIdpid, err := company.GetParentIdFromGroup(productInfo.GroupId)
  3097. if err != nil && err.Error() != utils.NotEmpty() {
  3098. break
  3099. }
  3100. if groupIdpid == nil || *groupIdpid == 0 {
  3101. productGroupPid = productInfo.GroupId
  3102. } else {
  3103. productGroupPid = *groupIdpid
  3104. }
  3105. }
  3106. // 如果客户的顶级分组和当前账号分组id一致
  3107. if sysUserGroupPid == productGroupPid {
  3108. isOk = true
  3109. break
  3110. }
  3111. }
  3112. }
  3113. }
  3114. // 客户当前是否有该产品的权限,如果没有的话,说明是在领取客户,允许访问
  3115. if !companyHasProduct {
  3116. isOk = true
  3117. }
  3118. if !isOk {
  3119. br.Msg = "无访问权限"
  3120. return
  3121. }
  3122. }
  3123. }
  3124. //产品权限map
  3125. statusMap := make(map[int]string)
  3126. for i := 0; i < itemLen; i++ {
  3127. item := productList[i]
  3128. //添加产品权限map
  3129. statusMap[item.ProductId] = item.Status
  3130. if i == 0 {
  3131. if item.ProductId == 1 {
  3132. resp.CreateAuth = 1
  3133. } else {
  3134. resp.CreateAuth = 2
  3135. }
  3136. }
  3137. if item.ProductId == 1 {
  3138. if strings.Contains(sysUser.RoleTypeCode, "ficc") {
  3139. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  3140. btnDetailItem.BtnHistoryList = true
  3141. } else {
  3142. if item.SellerId == sysUser.AdminId || shareSellerId == sysUser.AdminId || shareGroupId == sysUser.GroupId {
  3143. btnDetailItem.BtnHistoryList = true
  3144. }
  3145. if sysUser.Authority > 0 {
  3146. if item.GroupId == sysUser.GroupId {
  3147. btnDetailItem.BtnHistoryList = true
  3148. }
  3149. if item.DepartmentId == sysUser.DepartmentId {
  3150. btnDetailItem.BtnHistoryList = true
  3151. }
  3152. }
  3153. }
  3154. }
  3155. // 编辑回显
  3156. allPermissions, e := company.GetPermissionLookItemsByProductId(utils.COMPANY_PRODUCT_FICC_ID)
  3157. if e != nil {
  3158. br.Msg = "获取失败"
  3159. br.ErrMsg = "获取权限信息失败,Err:" + e.Error()
  3160. return
  3161. }
  3162. permissionMap := make(map[int][]*company.PermissionLookItem, 0)
  3163. permissionCheckMap := make(map[int][]int, 0)
  3164. for _, v := range allPermissions {
  3165. if v.ParentId > 0 {
  3166. permissionMap[v.ParentId] = append(permissionMap[v.ParentId], v)
  3167. if v.IsPublic == 1 {
  3168. permissionCheckMap[v.ParentId] = append(permissionCheckMap[v.ParentId], v.ChartPermissionId)
  3169. }
  3170. }
  3171. }
  3172. for _, v := range allPermissions {
  3173. if v.ParentId == 0 {
  3174. checkList := make([]int, 0)
  3175. plist := new(company.PermissionLookList)
  3176. plist.Items = make([]*company.PermissionLookItem, 0)
  3177. plist.ItemsType = make([]*company.PermissionSetItemType, 0)
  3178. items, ok := permissionMap[v.ChartPermissionId]
  3179. if ok {
  3180. for itemK, n := range items {
  3181. permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  3182. if err != nil && err.Error() != utils.ErrNoRow() {
  3183. br.Msg = "获取失败"
  3184. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3185. return
  3186. }
  3187. if permission != nil && permission.ChartPermissionId > 0 {
  3188. checkList = append(checkList, n.ChartPermissionId)
  3189. items[itemK].StartDate = permission.StartDate
  3190. items[itemK].EndDate = permission.EndDate
  3191. items[itemK].Status = permission.Status
  3192. endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
  3193. endDateTime = endDateTime.AddDate(0, 0, 1)
  3194. sub := endDateTime.Sub(time.Now())
  3195. if sub < 0 {
  3196. sub = 0
  3197. }
  3198. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  3199. items[itemK].ExpireDay = expireDay
  3200. }
  3201. }
  3202. plist.Items = items
  3203. }
  3204. plist.ClassifyName = v.PermissionName
  3205. plist.CheckList = checkList
  3206. item.PermissionList = append(item.PermissionList, plist)
  3207. }
  3208. }
  3209. resp.FiccItem = item
  3210. if resp.FiccItem.Status == utils.COMPANY_STATUS_FOREVER {
  3211. resp.FiccItem.Status = utils.COMPANY_STATUS_X_CLASS_TRY_OUT
  3212. }
  3213. if (roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  3214. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT) &&
  3215. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3216. resp.IsButtonShow = 1
  3217. }
  3218. } else {
  3219. if strings.Contains(sysUser.RoleTypeCode, "rai") {
  3220. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  3221. btnDetailItem.BtnHistoryList = true
  3222. } else {
  3223. if item.SellerId == sysUser.AdminId || item.ShareSellerId == sysUser.AdminId || shareGroupId == sysUser.GroupId {
  3224. btnDetailItem.BtnHistoryList = true
  3225. }
  3226. if sysUser.Authority > 0 {
  3227. if item.GroupId == sysUser.GroupId {
  3228. btnDetailItem.BtnHistoryList = true
  3229. }
  3230. if item.DepartmentId == sysUser.DepartmentId {
  3231. btnDetailItem.BtnHistoryList = true
  3232. }
  3233. }
  3234. }
  3235. }
  3236. // CRM8.8-权益权限列表调用较多、统一进行调整
  3237. plist, e := services.RaiCompanyPermissionAndCheckList(companyId, isEdit, []string{"调研"})
  3238. if e != nil {
  3239. br.Msg = "获取客户权益权限列表信息失败"
  3240. br.ErrMsg = "获取客户权益权限列表信息失败,Err:" + e.Error()
  3241. return
  3242. }
  3243. // cygx8.2专项产业调研展示
  3244. item.SpecialSurplus, err = cygxService.GetSpecialSurplusByCompanyNew(companyId)
  3245. if err != nil {
  3246. br.Msg = "获取失败"
  3247. br.ErrMsg = "获取专项调研信息失败,Err:" + err.Error()
  3248. return
  3249. }
  3250. //研选服务点数
  3251. item.Points = cygxService.GetCygxActivityPointsCompanyByCompanyId(companyId)
  3252. item.PermissionList = append(item.PermissionList, plist)
  3253. resp.RaiItem = item
  3254. if resp.RaiItem.Status == utils.COMPANY_STATUS_FOREVER {
  3255. resp.RaiItem.Status = utils.COMPANY_STATUS_X_CLASS_TRY_OUT
  3256. }
  3257. if (roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  3258. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  3259. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT) &&
  3260. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3261. resp.IsButtonShow = 1
  3262. }
  3263. }
  3264. 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, "")
  3265. //if itemLen > 1 {
  3266. // btnDetailItem.BtnEdit = false
  3267. // btnDetailItem.BtnDelete = false
  3268. //} else {
  3269. // btnDetailItem.BtnEdit = btnItem.BtnEdit
  3270. // btnDetailItem.BtnDelete = btnItem.BtnDelete
  3271. //}
  3272. switch item.ProductId {
  3273. case 1:
  3274. btnDetailItem.FiccEdit = btnItem.BtnEdit
  3275. btnDetailItem.FiccDelete = btnItem.BtnDelete
  3276. case 2:
  3277. btnDetailItem.RaiEdit = btnItem.BtnEdit
  3278. btnDetailItem.RaiDelete = btnItem.BtnDelete
  3279. }
  3280. if !btnDetailItem.BtnEdit {
  3281. btnDetailItem.BtnEdit = btnItem.BtnEdit
  3282. }
  3283. if !btnDetailItem.BtnDelete {
  3284. btnDetailItem.BtnDelete = btnItem.BtnDelete
  3285. }
  3286. //联系人操作权限
  3287. if resp.IsContractButtonShow == false {
  3288. resp.IsContractButtonShow = services.CheckCompanyUserButton(sysUser.RoleTypeCode, item.SellerId, sysUser.AdminId, item.ProductId, shareSellerId, item.Status)
  3289. }
  3290. //校验当前操作员是否具给联系人开通个人研选的权限
  3291. if resp.IsUserYanXuanButtonShow == false {
  3292. resp.IsUserYanXuanButtonShow, err = services.CheckCompanyUserYanXuanButton(sysUser.RoleTypeCode, sysUser.Mobile)
  3293. if err != nil {
  3294. br.Msg = "获取失败"
  3295. br.ErrMsg = "获取专项调研信息失败,Err:" + err.Error()
  3296. return
  3297. }
  3298. }
  3299. }
  3300. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  3301. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  3302. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  3303. resp.IsButtonShow = 1
  3304. btnDetailItem.BtnHistoryList = true
  3305. }
  3306. //ficc权限
  3307. if ficcStatus, ok := statusMap[1]; ok {
  3308. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT {
  3309. if raiStatus, ok := statusMap[2]; ok {
  3310. //另一个权限也是 试用 、冻结、流失
  3311. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3312. //那么超管、部门管理员、销售可以编辑
  3313. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3314. btnDetailItem.BaseInfoEdit = true
  3315. }
  3316. }
  3317. //权益是永续时,超管可编辑基础信息
  3318. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3319. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3320. btnDetailItem.BaseInfoEdit = true
  3321. }
  3322. }
  3323. } else {
  3324. //权限未开,有编辑基础信息权限
  3325. btnDetailItem.BaseInfoEdit = true
  3326. }
  3327. }
  3328. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3329. if raiStatus, ok := statusMap[2]; ok {
  3330. //另一个权限也是 永续 、冻结、流失
  3331. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FOREVER || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3332. //超管可编辑基础信息
  3333. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3334. btnDetailItem.BaseInfoEdit = true
  3335. }
  3336. }
  3337. } else {
  3338. //权限未开,有编辑基础信息权限
  3339. btnDetailItem.BaseInfoEdit = true
  3340. }
  3341. }
  3342. }
  3343. //权益销售
  3344. if raiStatus, ok := statusMap[2]; ok {
  3345. if raiStatus == utils.COMPANY_STATUS_TRY_OUT {
  3346. if ficcStatus, ok := statusMap[1]; ok {
  3347. //另一个权限也是 试用 、冻结、流失
  3348. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3349. //那么超管、部门管理员、销售可以编辑
  3350. if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3351. btnDetailItem.BaseInfoEdit = true
  3352. }
  3353. }
  3354. //ficc是永续时,超管可编辑基础信息
  3355. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3356. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3357. btnDetailItem.BaseInfoEdit = true
  3358. }
  3359. }
  3360. } else {
  3361. //权限未开,有编辑基础信息权限
  3362. btnDetailItem.BaseInfoEdit = true
  3363. }
  3364. }
  3365. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3366. if ficcStatus, ok := statusMap[1]; ok {
  3367. //另一个权限也是 试用、永续 、冻结、流失
  3368. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FOREVER || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3369. //超管可编辑基础信息
  3370. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3371. btnDetailItem.BaseInfoEdit = true
  3372. }
  3373. }
  3374. } else {
  3375. //权限未开,有编辑基础信息权限
  3376. btnDetailItem.BaseInfoEdit = true
  3377. }
  3378. }
  3379. }
  3380. // 白嫖客户标记
  3381. scroungeList, err := company.GetScroungeCompany()
  3382. if err != nil {
  3383. br.Msg = "获取失败"
  3384. br.ErrMsg = "获取白嫖客户信息失败,Err:" + err.Error()
  3385. return
  3386. }
  3387. scroungeMap := make(map[int]int)
  3388. for _, v := range scroungeList {
  3389. scroungeMap[v.CompanyId] = 1
  3390. }
  3391. if _, ok := scroungeMap[item.CompanyId]; ok {
  3392. item.IsScrounge = 1
  3393. }
  3394. resp.Item = item
  3395. resp.BtnItem = btnDetailItem
  3396. br.Ret = 200
  3397. br.Success = true
  3398. br.Msg = "获取成功"
  3399. br.Data = resp
  3400. }
  3401. // DetailByCreditCode
  3402. // @Title 根据社会信用码获取客户详情
  3403. // @Description 根据社会信用码获取客户详情接口
  3404. // @Param CreditCode query string true "客户社会信用码"
  3405. // @Success 200 {object} company.CompanyDetailResp
  3406. // @router /detail_by_credit_code [get]
  3407. func (this *CompanyController) DetailByCreditCode() {
  3408. br := new(models.BaseResponse).Init()
  3409. defer func() {
  3410. this.Data["json"] = br
  3411. this.ServeJSON()
  3412. }()
  3413. sysUser := this.SysUser
  3414. if sysUser == nil {
  3415. br.Msg = "请登录"
  3416. br.ErrMsg = "请登录,SysUser Is Empty"
  3417. br.Ret = 408
  3418. return
  3419. }
  3420. resp := new(company.CompanyDetailResp)
  3421. creditCode := this.GetString("CreditCode")
  3422. if creditCode == "" {
  3423. br.Msg = "参数错误"
  3424. br.ErrMsg = "社会信用码必传"
  3425. return
  3426. }
  3427. item, err := company.GetCompanyDetailByCreditCode(creditCode)
  3428. if err != nil {
  3429. br.Ret = 200
  3430. br.Success = true
  3431. br.Msg = "获取成功"
  3432. br.Data = resp
  3433. return
  3434. }
  3435. companyId := item.CompanyId
  3436. var productName string
  3437. productId := services.GetProductId(sysUser.RoleTypeCode)
  3438. if productId == 1 {
  3439. productName = utils.COMPANY_PRODUCT_FICC_NAME
  3440. } else if productId == 2 {
  3441. productName = utils.COMPANY_PRODUCT_RAI_NAME
  3442. } else {
  3443. productName = "admin"
  3444. }
  3445. resp.ProductName = productName
  3446. //获取客户产品
  3447. productList, err := company.GetCompanyProductsByCompanyId(companyId)
  3448. if err != nil {
  3449. br.Msg = "获取信息失败"
  3450. br.ErrMsg = "获取产品信息失败,Err:" + err.Error()
  3451. return
  3452. }
  3453. roleTypeCode := sysUser.RoleTypeCode
  3454. itemLen := len(productList)
  3455. btnDetailItem := new(company.ButtonDetailPermission)
  3456. //产品权限map
  3457. statusMap := make(map[int]string)
  3458. for i := 0; i < itemLen; i++ {
  3459. item := productList[i]
  3460. //添加产品权限map
  3461. statusMap[item.ProductId] = item.Status
  3462. if i == 0 {
  3463. if item.ProductId == 1 {
  3464. resp.CreateAuth = 1
  3465. } else {
  3466. resp.CreateAuth = 2
  3467. }
  3468. }
  3469. if item.ProductId == 1 {
  3470. if strings.Contains(sysUser.RoleTypeCode, "ficc") {
  3471. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  3472. btnDetailItem.BtnHistoryList = true
  3473. } else {
  3474. if item.SellerId == sysUser.AdminId {
  3475. btnDetailItem.BtnHistoryList = true
  3476. }
  3477. if sysUser.Authority > 0 {
  3478. if item.GroupId == sysUser.GroupId {
  3479. btnDetailItem.BtnHistoryList = true
  3480. }
  3481. if item.DepartmentId == sysUser.DepartmentId {
  3482. btnDetailItem.BtnHistoryList = true
  3483. }
  3484. }
  3485. }
  3486. }
  3487. //子权限切片集合
  3488. allFiccPermissions, permissionMap, e := services.GetBasePermissionLookItem(utils.COMPANY_PRODUCT_FICC_ID)
  3489. if e != nil {
  3490. br.Msg = "查询基础权限失败"
  3491. br.ErrMsg = "查询基础权限失败,Err:" + e.Error()
  3492. return
  3493. }
  3494. //遍历获取
  3495. for _, v := range allFiccPermissions {
  3496. if v.ParentId == 0 {
  3497. checkList := make([]int, 0)
  3498. plist := new(company.PermissionLookList)
  3499. plist.Items = make([]*company.PermissionLookItem, 0)
  3500. items, ok1 := permissionMap[v.ChartPermissionId]
  3501. if ok1 {
  3502. for itemK, n := range items {
  3503. permission, e := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  3504. if e != nil && e.Error() != utils.ErrNoRow() {
  3505. br.Msg = "获取失败"
  3506. br.ErrMsg = "获取权限信息失败,Err:" + e.Error()
  3507. return
  3508. }
  3509. if permission != nil && permission.ChartPermissionId > 0 {
  3510. checkList = append(checkList, n.ChartPermissionId)
  3511. items[itemK].StartDate = permission.StartDate
  3512. items[itemK].EndDate = permission.EndDate
  3513. items[itemK].Status = permission.Status
  3514. endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
  3515. endDateTime = endDateTime.AddDate(0, 0, 1)
  3516. sub := endDateTime.Sub(time.Now())
  3517. if sub < 0 {
  3518. sub = 0
  3519. }
  3520. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  3521. items[itemK].ExpireDay = expireDay
  3522. }
  3523. }
  3524. plist.Items = items
  3525. }
  3526. plist.ClassifyName = v.PermissionName
  3527. plist.CheckList = checkList
  3528. item.PermissionList = append(item.PermissionList, plist)
  3529. }
  3530. }
  3531. resp.FiccItem = item
  3532. if (roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  3533. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT) &&
  3534. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3535. resp.IsButtonShow = 1
  3536. }
  3537. } else {
  3538. if strings.Contains(sysUser.RoleTypeCode, "rai") {
  3539. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  3540. btnDetailItem.BtnHistoryList = true
  3541. } else {
  3542. if item.SellerId == sysUser.AdminId {
  3543. btnDetailItem.BtnHistoryList = true
  3544. }
  3545. if sysUser.Authority > 0 {
  3546. if item.GroupId == sysUser.GroupId {
  3547. btnDetailItem.BtnHistoryList = true
  3548. }
  3549. if item.DepartmentId == sysUser.DepartmentId {
  3550. btnDetailItem.BtnHistoryList = true
  3551. }
  3552. }
  3553. }
  3554. }
  3555. classifyName := "权益"
  3556. checkList := make([]int, 0)
  3557. plist := new(company.PermissionLookList)
  3558. items, err := company.GetPermissionLookItems(item.ProductId, classifyName)
  3559. if err != nil {
  3560. br.Msg = "获取失败"
  3561. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3562. return
  3563. }
  3564. for itemK, n := range items {
  3565. permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  3566. if err != nil && err.Error() != utils.ErrNoRow() {
  3567. br.Msg = "获取失败"
  3568. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3569. return
  3570. }
  3571. if permission != nil && permission.ChartPermissionId > 0 {
  3572. checkList = append(checkList, n.ChartPermissionId)
  3573. items[itemK].StartDate = permission.StartDate
  3574. items[itemK].EndDate = permission.EndDate
  3575. items[itemK].Status = permission.Status
  3576. endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
  3577. endDateTime = endDateTime.AddDate(0, 0, 1)
  3578. sub := endDateTime.Sub(time.Now())
  3579. if sub < 0 {
  3580. sub = 0
  3581. }
  3582. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  3583. items[itemK].ExpireDay = expireDay
  3584. }
  3585. //count, err := company.GetCompanyPermissionCheck(companyId, n.ChartPermissionId)
  3586. //if err != nil {
  3587. // br.Msg = "获取失败"
  3588. // br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3589. // return
  3590. //}
  3591. //if count > 0 {
  3592. // checkList = append(checkList, n.ChartPermissionId)
  3593. //}
  3594. }
  3595. item.SpecialSurplus, err = cygxService.GetSpecialSurplusByCompanyNew(companyId)
  3596. if err != nil {
  3597. br.Msg = "获取失败"
  3598. br.ErrMsg = "获取专项调研信息失败,Err:" + err.Error()
  3599. return
  3600. }
  3601. plist.Items = items
  3602. plist.ClassifyName = classifyName
  3603. plist.CheckList = checkList
  3604. item.PermissionList = append(item.PermissionList, plist)
  3605. resp.RaiItem = item
  3606. if (roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  3607. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  3608. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT) &&
  3609. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3610. resp.IsButtonShow = 1
  3611. }
  3612. }
  3613. btnItem := services.GetCompanyPermissionButton(roleTypeCode, item.Status, strconv.Itoa(item.SellerId), strconv.Itoa(item.GroupId),
  3614. item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, item.ShareSellerId, "")
  3615. //if itemLen > 1 {
  3616. // btnDetailItem.BtnEdit = false
  3617. // btnDetailItem.BtnDelete = false
  3618. //} else {
  3619. // btnDetailItem.BtnEdit = btnItem.BtnEdit
  3620. // btnDetailItem.BtnDelete = btnItem.BtnDelete
  3621. //}
  3622. switch item.ProductId {
  3623. case 1:
  3624. btnDetailItem.FiccEdit = btnItem.BtnEdit
  3625. btnDetailItem.FiccDelete = btnItem.BtnDelete
  3626. case 2:
  3627. btnDetailItem.RaiEdit = btnItem.BtnEdit
  3628. btnDetailItem.RaiDelete = btnItem.BtnDelete
  3629. }
  3630. if !btnDetailItem.BtnEdit {
  3631. btnDetailItem.BtnEdit = btnItem.BtnEdit
  3632. }
  3633. if !btnDetailItem.BtnDelete {
  3634. btnDetailItem.BtnDelete = btnItem.BtnDelete
  3635. }
  3636. //联系人操作权限
  3637. if resp.IsContractButtonShow == false {
  3638. resp.IsContractButtonShow = services.CheckCompanyUserButton(sysUser.RoleTypeCode, item.SellerId, sysUser.AdminId, item.ProductId, item.ShareSellerId, item.Status)
  3639. }
  3640. }
  3641. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  3642. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  3643. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  3644. resp.IsButtonShow = 1
  3645. btnDetailItem.BtnHistoryList = true
  3646. }
  3647. //ficc权限
  3648. if ficcStatus, ok := statusMap[1]; ok {
  3649. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT {
  3650. if raiStatus, ok := statusMap[2]; ok {
  3651. //另一个权限也是 试用 、冻结、流失
  3652. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3653. //那么超管、部门管理员、销售可以编辑
  3654. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3655. btnDetailItem.BaseInfoEdit = true
  3656. }
  3657. }
  3658. //权益是永续时,超管可编辑基础信息
  3659. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3660. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3661. btnDetailItem.BaseInfoEdit = true
  3662. }
  3663. }
  3664. } else {
  3665. //权限未开,有编辑基础信息权限
  3666. btnDetailItem.BaseInfoEdit = true
  3667. }
  3668. }
  3669. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3670. if raiStatus, ok := statusMap[2]; ok {
  3671. //另一个权限也是 永续 、冻结、流失
  3672. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FOREVER || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3673. //超管可编辑基础信息
  3674. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3675. btnDetailItem.BaseInfoEdit = true
  3676. }
  3677. }
  3678. } else {
  3679. //权限未开,有编辑基础信息权限
  3680. btnDetailItem.BaseInfoEdit = true
  3681. }
  3682. }
  3683. }
  3684. //权益销售
  3685. if raiStatus, ok := statusMap[2]; ok {
  3686. if raiStatus == utils.COMPANY_STATUS_TRY_OUT {
  3687. if ficcStatus, ok := statusMap[1]; ok {
  3688. //另一个权限也是 试用 、冻结、流失
  3689. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3690. //那么超管、部门管理员、销售可以编辑
  3691. if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3692. btnDetailItem.BaseInfoEdit = true
  3693. }
  3694. }
  3695. //ficc是永续时,超管可编辑基础信息
  3696. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3697. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3698. btnDetailItem.BaseInfoEdit = true
  3699. }
  3700. }
  3701. } else {
  3702. //权限未开,有编辑基础信息权限
  3703. btnDetailItem.BaseInfoEdit = true
  3704. }
  3705. }
  3706. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3707. if ficcStatus, ok := statusMap[1]; ok {
  3708. //另一个权限也是 试用、永续 、冻结、流失
  3709. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FOREVER || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3710. //超管可编辑基础信息
  3711. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3712. btnDetailItem.BaseInfoEdit = true
  3713. }
  3714. }
  3715. } else {
  3716. //权限未开,有编辑基础信息权限
  3717. btnDetailItem.BaseInfoEdit = true
  3718. }
  3719. }
  3720. }
  3721. resp.Item = item
  3722. resp.BtnItem = btnDetailItem
  3723. br.Ret = 200
  3724. br.Success = true
  3725. br.Msg = "获取成功"
  3726. br.Data = resp
  3727. }
  3728. // @Title 编辑客户
  3729. // @Description 编辑客户接口
  3730. // @Param request body company.CompanyEditReq true "type json string"
  3731. // @Success Ret=200 保存成功
  3732. // @router /edit [post]
  3733. func (this *CompanyController) Edit() {
  3734. br := new(models.BaseResponse).Init()
  3735. defer func() {
  3736. this.Data["json"] = br
  3737. this.ServeJSON()
  3738. }()
  3739. sysUser := this.SysUser
  3740. if sysUser == nil {
  3741. br.Msg = "请登录"
  3742. br.ErrMsg = "请登录,SysUser Is Empty"
  3743. br.Ret = 408
  3744. return
  3745. }
  3746. //roleTypeCode := sysUser.RoleTypeCode
  3747. var req company.CompanyEditReq
  3748. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3749. if err != nil {
  3750. br.Msg = "参数解析异常!"
  3751. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3752. return
  3753. }
  3754. if req.CompanyId <= 0 {
  3755. br.Msg = "参数异常!"
  3756. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  3757. return
  3758. }
  3759. if req.CompanyName == "" {
  3760. br.Msg = "请填写客户名称"
  3761. return
  3762. }
  3763. if req.CreditCode == "" {
  3764. br.Msg = "请填写社会统一信用码"
  3765. return
  3766. }
  3767. //移除空格
  3768. req.CreditCode = utils.TrimStr(req.CreditCode)
  3769. productId := services.GetProductId(sysUser.RoleTypeCode) //产品权限id
  3770. for _, v := range req.Products {
  3771. //X类试用,转为永续
  3772. if v.Status == utils.COMPANY_STATUS_X_CLASS_TRY_OUT {
  3773. v.Status = utils.COMPANY_STATUS_FOREVER
  3774. }
  3775. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  3776. //查询客户的产品权限
  3777. companyReportPermissionListOld, err := company.GetCompanyReportPermission(req.CompanyId, productId)
  3778. if err != nil {
  3779. br.Msg = "查询客户的产品权限异常"
  3780. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  3781. return
  3782. }
  3783. permissionArr := strings.Split(v.PermissionIds, ",")
  3784. //如果所选行业不属于研选订阅跟研选扣点包,那就是非研选试用客户
  3785. var isNoResearch bool
  3786. for _, v := range permissionArr {
  3787. if v != strconv.Itoa(utils.CHART_PERMISSION_ID_YANXUAN) && v != strconv.Itoa(utils.YAN_XUAN_KOU_DIAN_BAO_ID) {
  3788. isNoResearch = true
  3789. continue
  3790. }
  3791. }
  3792. if isNoResearch && len(companyReportPermissionListOld) != len(permissionArr) {
  3793. tryOutCountRai, err := company.GetRaiCompanyTryOutCountNoResearch(sysUser.AdminId)
  3794. if err != nil {
  3795. br.Msg = "判断试用客户量失败"
  3796. br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  3797. return
  3798. }
  3799. if tryOutCountRai >= utils.COMPANY_STATUS_TRY_OUT_COUNT_RAI {
  3800. br.Msg = "非研选试用客户最多40家"
  3801. return
  3802. }
  3803. }
  3804. }
  3805. if v.IndustryId <= 0 {
  3806. br.Msg = "请选择行业"
  3807. br.IsSendEmail = false
  3808. return
  3809. }
  3810. //获取客户产品信息
  3811. productItem, err := company.GetCompanyProductById(v.CompanyProductId)
  3812. if err != nil {
  3813. br.Msg = "数据获取失败!"
  3814. br.ErrMsg = "数据获取失败,Err:" + err.Error()
  3815. return
  3816. }
  3817. if productItem == nil {
  3818. br.Msg = "客户信息不存在!"
  3819. return
  3820. }
  3821. // 如果本身是有权限归属的,同时传入的参数不是当前账号权限的,那么过滤该次循环,进入下次循环
  3822. if productId > 0 && productItem.ProductId != productId {
  3823. continue
  3824. }
  3825. if v.Status == "" {
  3826. br.Msg = "客户状态不可为空"
  3827. return
  3828. }
  3829. //if v.Reasons == "" {
  3830. // br.Msg = "请填写新增理由"
  3831. // return
  3832. //}
  3833. if v.PermissionIds == "" {
  3834. br.Msg = "请选择权限"
  3835. return
  3836. }
  3837. var startDate, endDate string
  3838. startDate = productItem.StartDate
  3839. endDate = productItem.EndDate
  3840. if startDate == "" || endDate == "" {
  3841. br.Msg = "数据错误"
  3842. br.Msg = "数据错误,开始或结束日期为空:startDate:" + startDate + "endDate:" + endDate
  3843. return
  3844. }
  3845. //判断客户是否已经存在
  3846. companyNameIsExist, err := company.GetCompanyCountByCompanyNameAndCompanyId(req.CompanyId, req.CompanyName)
  3847. if err != nil {
  3848. br.Msg = "判断客户是否存在失败"
  3849. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  3850. return
  3851. }
  3852. if companyNameIsExist > 0 {
  3853. br.Msg = "客户已存在,请重新输入客户名称"
  3854. return
  3855. }
  3856. //判断客户是否已经存在
  3857. companyCreditCodeIsExist, err := company.GetCompanyCountByCreditCodeAndCompanyId(req.CompanyId, req.CreditCode)
  3858. if err != nil {
  3859. br.Msg = "判断客户是否存在失败"
  3860. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  3861. return
  3862. }
  3863. if companyCreditCodeIsExist > 0 {
  3864. br.Msg = "客户已存在,请重新输入统一社会信用代码"
  3865. return
  3866. }
  3867. seller, err := system.GetSysAdminById(v.SellsId)
  3868. if err != nil {
  3869. br.Msg = "获取销售信息失败"
  3870. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  3871. return
  3872. }
  3873. if seller == nil {
  3874. br.Msg = "所属销售不存在"
  3875. return
  3876. }
  3877. //tryOutCount, err := company.GetCompanyTryOutCount(utils.COMPANY_STATUS_TRY_OUT, seller.AdminId)
  3878. //if err != nil {
  3879. // br.Msg = "判断试用客户量失败"
  3880. // br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  3881. // return
  3882. //}
  3883. //if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
  3884. // roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  3885. // if tryOutCount >= utils.COMPANY_STATUS_TRY_OUT_COUNT && v.SellsId == sysUser.AdminId {
  3886. // br.Msg = "您的试用客户总数,已超过上限,不可继续新增"
  3887. // return
  3888. // }
  3889. //}
  3890. industry, err := company.GetCompanyIndustryById(v.IndustryId)
  3891. if err != nil {
  3892. br.Msg = "获取行业信息失败"
  3893. br.ErrMsg = "获取行业信息失败,Err:" + err.Error()
  3894. return
  3895. }
  3896. companyProduct := new(company.CompanyProduct)
  3897. companyProduct.ProductId = productItem.ProductId
  3898. companyProduct.CompanyId = req.CompanyId
  3899. companyProduct.CompanyName = req.CompanyName
  3900. companyProduct.Source = v.Source
  3901. companyProduct.Reasons = v.Reasons
  3902. companyProduct.Status = v.Status
  3903. companyProduct.StartDate = startDate
  3904. companyProduct.EndDate = endDate
  3905. companyProduct.IndustryId = v.IndustryId
  3906. companyProduct.IndustryName = industry.IndustryName
  3907. companyProduct.SellerId = seller.AdminId
  3908. companyProduct.SellerName = seller.RealName
  3909. companyProduct.GroupId = seller.GroupId
  3910. companyProduct.DepartmentId = seller.DepartmentId
  3911. companyProduct.IsSuspend = 0
  3912. companyProduct.ModifyTime = time.Now()
  3913. companyProduct.CompanyProductId = v.CompanyProductId
  3914. companyProduct.Scale = v.Scale
  3915. err = company.ModifyCompanyProduct(companyProduct)
  3916. if err != nil {
  3917. br.Msg = "修改客户信息失败"
  3918. br.ErrMsg = "修改客户产品信息失败,Err:" + err.Error()
  3919. return
  3920. }
  3921. // CRM8.8-下面的需求取消, 编辑的时候根据选择开通对应权限
  3922. // 如果是权益客户,编辑的时候开通主观客观权限
  3923. //if v.CompanyType == utils.COMPANY_CLASSIFY_RAI {
  3924. // permissionStr, err := company.GetPermissionIdById(v.PermissionIds)
  3925. // if err != nil {
  3926. // br.Msg = "修改失败"
  3927. // br.ErrMsg = "获取主观客观权限信息失败,Err:" + err.Error()
  3928. // return
  3929. // }
  3930. // v.PermissionIds = permissionStr
  3931. //}
  3932. //处理权限
  3933. companyReportPermissionList, err := services.AddCompanyPermission(req.CompanyId, seller.AdminId, productItem.ProductId, productItem.ProductName, seller.RealName, v.PermissionIds, startDate, endDate)
  3934. if err != nil {
  3935. br.Msg = "修改失败"
  3936. br.ErrMsg = "新增客户设置权限失败,err:" + err.Error()
  3937. return
  3938. }
  3939. //新增操作记录
  3940. {
  3941. record := new(company.CompanyOperationRecord)
  3942. record.CompanyId = req.CompanyId
  3943. record.CompanyName = req.CompanyName
  3944. record.SellerId = companyProduct.SellerId
  3945. record.SysUserId = this.SysUser.AdminId
  3946. record.SysRealName = this.SysUser.RealName
  3947. record.Remark = "编辑客户"
  3948. record.Operation = "edit"
  3949. record.CreateTime = time.Now()
  3950. record.ProductId = productItem.ProductId
  3951. record.ProductName = productItem.ProductName
  3952. record.Status = productItem.Status
  3953. _, err = company.AddCompanyOperationRecord(record)
  3954. if err != nil {
  3955. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  3956. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  3957. }
  3958. }
  3959. //新增客户产品日志
  3960. {
  3961. productLog := new(company.CompanyProductLog)
  3962. productLog.CompanyProductId = v.CompanyProductId
  3963. productLog.CompanyId = companyProduct.CompanyId
  3964. productLog.ProductId = companyProduct.ProductId
  3965. productLog.ProductName = companyProduct.ProductName
  3966. productLog.CompanyName = companyProduct.CompanyName
  3967. productLog.CompanyName = companyProduct.CompanyName
  3968. productLog.Source = companyProduct.Source
  3969. productLog.Reasons = companyProduct.Reasons
  3970. productLog.Status = companyProduct.Status
  3971. productLog.IndustryId = companyProduct.IndustryId
  3972. productLog.IndustryName = companyProduct.IndustryName
  3973. productLog.SellerId = companyProduct.SellerId
  3974. productLog.SellerName = companyProduct.SellerName
  3975. productLog.GroupId = companyProduct.GroupId
  3976. productLog.DepartmentId = companyProduct.DepartmentId
  3977. productLog.IsSuspend = companyProduct.IsSuspend
  3978. productLog.SuspendTime = companyProduct.SuspendTime
  3979. productLog.ApproveStatus = companyProduct.ApproveStatus
  3980. productLog.FreezeTime = companyProduct.FreezeTime
  3981. productLog.Remark = companyProduct.Remark
  3982. productLog.StartDate = companyProduct.StartDate
  3983. productLog.EndDate = companyProduct.EndDate
  3984. productLog.CreateTime = companyProduct.CreateTime
  3985. productLog.ModifyTime = companyProduct.ModifyTime
  3986. productLog.LoseReason = companyProduct.LoseReason
  3987. productLog.LossTime = companyProduct.LossTime
  3988. productLog.LogType = "modify"
  3989. productLog.LogCreateTime = time.Now()
  3990. productLog.AdminId = this.SysUser.AdminId
  3991. productLog.Scale = companyProduct.Scale
  3992. go company.AddCompanyProductLog(productLog)
  3993. }
  3994. //新增客户产品状态变更日志
  3995. {
  3996. startDateTime, _ := time.ParseInLocation(utils.FormatDate, startDate, time.Local)
  3997. endDateTime, _ := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
  3998. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  3999. Id: 0,
  4000. CompanyId: req.CompanyId,
  4001. ProductId: productId,
  4002. Status: "试用",
  4003. Source: "edit",
  4004. SellerId: seller.AdminId,
  4005. SellerName: seller.RealName,
  4006. StartDate: startDateTime,
  4007. EndDate: endDateTime,
  4008. RealEndDate: startDateTime,
  4009. CreateTime: time.Now(),
  4010. }
  4011. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  4012. // 添加试用记录
  4013. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  4014. Id: 0,
  4015. CompanyId: req.CompanyId,
  4016. ProductId: productId,
  4017. Source: "edit",
  4018. SellerId: seller.AdminId,
  4019. SellerName: seller.RealName,
  4020. StartDate: startDateTime,
  4021. EndDate: endDateTime,
  4022. RealEndDate: startDateTime,
  4023. IsStop: 0,
  4024. CreateTime: time.Now(),
  4025. }
  4026. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  4027. }
  4028. }
  4029. companyItem := new(company.Company)
  4030. companyItem.CompanyId = req.CompanyId
  4031. companyItem.CompanyName = req.CompanyName
  4032. companyItem.CreditCode = req.CreditCode
  4033. companyItem.Province = req.Province
  4034. companyItem.City = req.City
  4035. companyItem.Address = req.Province + req.City
  4036. companyItem.LastUpdatedTime = time.Now()
  4037. companyItem.Enabled = 1
  4038. companyItem.Nation = req.Nation
  4039. err = company.ModifyCompany(companyItem)
  4040. if err != nil {
  4041. br.Msg = "修改客户信息失败"
  4042. br.ErrMsg = "修改客户信息失败,Err:" + err.Error()
  4043. return
  4044. }
  4045. //新增客户日志
  4046. {
  4047. companyLog := new(company.CompanyLog)
  4048. companyLog.CompanyId = req.CompanyId
  4049. companyLog.CompanyName = req.CompanyName
  4050. companyLog.CreditCode = req.CreditCode
  4051. companyLog.Address = companyItem.Address
  4052. companyLog.City = companyItem.City
  4053. companyLog.Province = companyItem.Province
  4054. companyLog.LastUpdatedTime = companyItem.LastUpdatedTime
  4055. companyLog.AdminId = this.SysUser.AdminId
  4056. companyLog.LogType = "modify"
  4057. companyLog.LogCreateTime = time.Now()
  4058. go company.AddCompanyLog(companyLog)
  4059. }
  4060. br.Ret = 200
  4061. br.Success = true
  4062. br.Msg = "保存成功"
  4063. }
  4064. // @Title 编辑补充客户信息接口
  4065. // @Description 编辑补充客户信息接口
  4066. // @Param request body company.CompanyInfoEditReq true "type json string"
  4067. // @Success Ret=200 保存成功
  4068. // @router /company_info/edit [post]
  4069. func (this *CompanyController) EditCompanyInfo() {
  4070. br := new(models.BaseResponse).Init()
  4071. defer func() {
  4072. this.Data["json"] = br
  4073. this.ServeJSON()
  4074. }()
  4075. sysUser := this.SysUser
  4076. if sysUser == nil {
  4077. br.Msg = "请登录"
  4078. br.ErrMsg = "请登录,SysUser Is Empty"
  4079. br.Ret = 408
  4080. return
  4081. }
  4082. var req company.CompanyInfoEditReq
  4083. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4084. if err != nil {
  4085. br.Msg = "参数解析异常!"
  4086. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4087. return
  4088. }
  4089. if req.CompanyId <= 0 {
  4090. br.Msg = "参数异常!"
  4091. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  4092. return
  4093. }
  4094. if req.CompanyName == "" {
  4095. br.Msg = "请填写客户名称"
  4096. return
  4097. }
  4098. if req.CreditCode == "" {
  4099. br.Msg = "请填写社会统一信用码"
  4100. return
  4101. }
  4102. //if req.Province == "" {
  4103. // br.Msg = "请选择省份"
  4104. // return
  4105. //}
  4106. //if req.City == "" {
  4107. // br.Msg = "请选择市区"
  4108. // return
  4109. //}
  4110. //if req.IndustryId <= 0 {
  4111. // br.Msg = "请选择所属行业"
  4112. // return
  4113. //}
  4114. //if req.IndustryName == "" {
  4115. // br.Msg = "请选择所属行业"
  4116. // return
  4117. //}
  4118. //if req.Source == "" {
  4119. // br.Msg = "请选择来源"
  4120. // return
  4121. //}
  4122. //移除空格
  4123. req.CreditCode = utils.TrimStr(req.CreditCode)
  4124. //获取产品权限
  4125. productId := services.GetProductId(sysUser.RoleTypeCode)
  4126. if productId <= 0 {
  4127. br.Msg = "当前账号不允许修改客户信息"
  4128. return
  4129. }
  4130. companyNameIsExist, err := company.GetCompanyCountByCompanyNameAndCompanyId(req.CompanyId, req.CompanyName)
  4131. if err != nil {
  4132. br.Msg = "判断客户是否存在失败"
  4133. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  4134. return
  4135. }
  4136. if companyNameIsExist > 0 {
  4137. br.Msg = "客户已存在,请重新输入客户名称"
  4138. return
  4139. }
  4140. //判断客户是否已经存在
  4141. companyCreditCodeIsExist, err := company.GetCompanyCountByCreditCodeAndCompanyId(req.CompanyId, req.CreditCode)
  4142. if err != nil {
  4143. br.Msg = "判断客户是否存在失败"
  4144. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  4145. return
  4146. }
  4147. if companyCreditCodeIsExist > 0 {
  4148. br.Msg = "客户已存在,统一社会信用代码"
  4149. return
  4150. }
  4151. //查询该客户
  4152. companyItem, err := company.GetCompanyById(req.CompanyId)
  4153. if err != nil {
  4154. br.Msg = "查找客户失败"
  4155. br.ErrMsg = "查找客户失败,Err:" + err.Error()
  4156. return
  4157. }
  4158. //待更新字段
  4159. updateCol := make([]string, 0)
  4160. companyItem.CompanyName = req.CompanyName
  4161. companyItem.CreditCode = req.CreditCode
  4162. companyItem.Enabled = 1
  4163. companyItem.LastUpdatedTime = time.Now()
  4164. updateCol = append(updateCol, "CompanyName", "CreditCode", "Enabled", "LastUpdatedTime")
  4165. if req.Province != "" && req.City != "" {
  4166. companyItem.Province = req.Province
  4167. companyItem.City = req.City
  4168. companyItem.Address = req.Province + req.City
  4169. updateCol = append(updateCol, "Province", "City", "Address")
  4170. }
  4171. err = companyItem.Update(updateCol)
  4172. if err != nil {
  4173. br.Msg = "修改客户信息失败"
  4174. br.ErrMsg = "修改客户信息失败,Err:" + err.Error()
  4175. return
  4176. }
  4177. //查询并更新客户产品信息
  4178. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  4179. if err != nil {
  4180. if err.Error() != utils.ErrNoRow() {
  4181. br.Msg = "查询客户产品信息失败"
  4182. br.ErrMsg = "查询客户产品信息失败,Err:" + err.Error()
  4183. return
  4184. }
  4185. } else {
  4186. if companyProduct != nil {
  4187. //客户产品待更新字段
  4188. updateCompanyProductCol := make([]string, 0)
  4189. //产品信息(来源、行业)
  4190. if req.IndustryId != 0 && req.IndustryId != companyProduct.IndustryId {
  4191. companyProduct.IndustryId = req.IndustryId
  4192. companyProduct.IndustryName = req.IndustryName
  4193. updateCompanyProductCol = append(updateCompanyProductCol, "IndustryId", "IndustryName")
  4194. }
  4195. if req.Source != "" && req.Source != companyProduct.Source {
  4196. companyProduct.Source = req.Source
  4197. updateCompanyProductCol = append(updateCompanyProductCol, "Source")
  4198. }
  4199. //更新客户产品信息
  4200. if len(updateCompanyProductCol) > 0 {
  4201. err = companyProduct.Update(updateCompanyProductCol)
  4202. if err != nil {
  4203. br.Msg = "修改客户信息失败"
  4204. br.ErrMsg = "修改客户信息失败,Err:" + err.Error()
  4205. return
  4206. }
  4207. }
  4208. }
  4209. }
  4210. //新增客户日志
  4211. {
  4212. companyLog := new(company.CompanyLog)
  4213. companyLog.CompanyId = req.CompanyId
  4214. companyLog.CompanyName = req.CompanyName
  4215. companyLog.CreditCode = req.CreditCode
  4216. companyLog.Address = companyItem.Address
  4217. companyLog.City = companyItem.City
  4218. companyLog.Province = companyItem.Province
  4219. companyLog.LastUpdatedTime = companyItem.LastUpdatedTime
  4220. companyLog.AdminId = this.SysUser.AdminId
  4221. companyLog.LogType = "modify"
  4222. companyLog.LogCreateTime = time.Now()
  4223. go company.AddCompanyLog(companyLog)
  4224. }
  4225. br.Ret = 200
  4226. br.Success = true
  4227. br.Msg = "保存成功"
  4228. }
  4229. // @Title 客户模糊检索(新增/编辑客户页面试用)
  4230. // @Description 客户模糊检索接口(新增/编辑客户页面试用)
  4231. // @Param KeyWord query string true "搜索关键词"
  4232. // @Success 200 {object} company.CompanyFuzzySearchReq
  4233. // @router /fuzzy/search [get]
  4234. func (this *CompanyController) FuzzySearch() {
  4235. br := new(models.BaseResponse).Init()
  4236. defer func() {
  4237. this.Data["json"] = br
  4238. this.ServeJSON()
  4239. }()
  4240. keyWord := this.GetString("KeyWord")
  4241. list, err := company.GetCompanyFuzzySearch(keyWord)
  4242. if err != nil {
  4243. br.Msg = "获取信息失败"
  4244. br.ErrMsg = "获取信息失败,err:" + err.Error()
  4245. return
  4246. }
  4247. resp := new(company.CompanyFuzzySearchReq)
  4248. resp.List = list
  4249. br.Ret = 200
  4250. br.Success = true
  4251. br.Msg = "获取成功"
  4252. br.Data = resp
  4253. }
  4254. // @Title 删除客户
  4255. // @Description 删除客户接口
  4256. // @Param request body company.DeletePptReq true "type json string"
  4257. // @Success Ret=200 保存成功
  4258. // @router /delete [post]
  4259. func (this *CompanyController) Delete() {
  4260. br := new(models.BaseResponse).Init()
  4261. defer func() {
  4262. this.Data["json"] = br
  4263. this.ServeJSON()
  4264. }()
  4265. sysUser := this.SysUser
  4266. if sysUser == nil {
  4267. br.Msg = "请登录"
  4268. br.ErrMsg = "请登录,SysUser Is Empty"
  4269. br.Ret = 408
  4270. return
  4271. }
  4272. var req company.DeletePptReq
  4273. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4274. if err != nil {
  4275. br.Msg = "参数解析异常!"
  4276. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4277. return
  4278. }
  4279. if req.CompanyId <= 0 {
  4280. br.Msg = "参数错误"
  4281. br.ErrMsg = "客户ID小于等于0"
  4282. return
  4283. }
  4284. roleTypeCode := this.SysUser.RoleTypeCode
  4285. productId := services.GetProductId(roleTypeCode)
  4286. productItems, err := company.GetCompanyProductsByCompanyId(req.CompanyId)
  4287. if err != nil {
  4288. br.Msg = "删除失败"
  4289. br.ErrMsg = "获取客户产品信息失败,Err:" + err.Error()
  4290. return
  4291. }
  4292. // 备份信息
  4293. companyDeleteBakInfo := services.CompanyDeleteBakInfo{
  4294. CompanyId: req.CompanyId,
  4295. CompanyName: "",
  4296. CompanyInfo: &company.Company{},
  4297. CompanyProductInfo: make([]*company.CompanyProduct, 0),
  4298. CompanyPermissionInfo: make([]*company.CompanyReportPermission, 0),
  4299. UserSellerRelationInfo: make([]*models.UserSellerRelation, 0),
  4300. UserRecordInfo: make([]*models.UserRecord, 0),
  4301. UserInfo: make([]*models.WxUser, 0),
  4302. CompanyChartPermissionInfo: make([]*company_user.ChartClassifyPermission, 0),
  4303. OpUserId: this.SysUser.AdminId,
  4304. OpUserName: this.SysUser.RealName,
  4305. }
  4306. if productId == 0 {
  4307. for _, v := range productItems {
  4308. //永续,试用,流失,关闭
  4309. 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 {
  4310. br.Msg = "该客户" + v.ProductName + "属性为" + v.Status + ",暂不可删除"
  4311. br.ErrMsg = "该客户" + v.ProductName + "属性为" + v.Status + ",暂不可删除"
  4312. return
  4313. }
  4314. companyProductList, companyReportPermissionList, err := company.DeleteCompanyProductById(v.CompanyId, v.ProductId, v.CompanyProductId)
  4315. if err != nil {
  4316. br.Msg = "删除失败"
  4317. br.ErrMsg = "删除失败,Err:" + err.Error()
  4318. return
  4319. }
  4320. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductList...)
  4321. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissionList...)
  4322. //新增操作记录
  4323. {
  4324. record := new(company.CompanyOperationRecord)
  4325. record.CompanyId = req.CompanyId
  4326. record.CompanyName = v.CompanyName
  4327. record.SellerId = v.SellerId
  4328. record.SysUserId = this.SysUser.AdminId
  4329. record.SysRealName = this.SysUser.RealName
  4330. record.Remark = "删除客户"
  4331. record.Operation = "delete"
  4332. record.CreateTime = time.Now()
  4333. record.ProductId = v.ProductId
  4334. record.ProductName = v.ProductName
  4335. _, err = company.AddCompanyOperationRecord(record)
  4336. if err != nil {
  4337. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  4338. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  4339. }
  4340. }
  4341. //删除对应产品的联系人
  4342. userSellerRelationList, userRecordList, wxUserList, chartClassifyPermission, _ := services.DeleteCompanyWxUserByProductId(v.CompanyId, v.ProductId)
  4343. //备份信息
  4344. {
  4345. if companyProductList != nil {
  4346. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductList...)
  4347. }
  4348. if companyReportPermissionList != nil {
  4349. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissionList...)
  4350. }
  4351. if userSellerRelationList != nil {
  4352. companyDeleteBakInfo.UserSellerRelationInfo = append(companyDeleteBakInfo.UserSellerRelationInfo, userSellerRelationList...)
  4353. }
  4354. if userRecordList != nil {
  4355. companyDeleteBakInfo.UserRecordInfo = append(companyDeleteBakInfo.UserRecordInfo, userRecordList...)
  4356. }
  4357. if wxUserList != nil {
  4358. companyDeleteBakInfo.UserInfo = append(companyDeleteBakInfo.UserInfo, wxUserList...)
  4359. }
  4360. if chartClassifyPermission != nil {
  4361. companyDeleteBakInfo.CompanyChartPermissionInfo = append(companyDeleteBakInfo.CompanyChartPermissionInfo, chartClassifyPermission...)
  4362. }
  4363. companyDeleteBakInfo.CompanyName = v.CompanyName
  4364. }
  4365. }
  4366. } else {
  4367. productObj, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  4368. if err != nil {
  4369. br.ErrMsg = "获取客户产品信息失败,Err:" + err.Error()
  4370. br.Msg = "删除失败"
  4371. return
  4372. }
  4373. //永续,试用,流失,关闭
  4374. 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 {
  4375. br.Msg = "该客户" + productObj.ProductName + "属性为" + productObj.Status + ",暂不可删除"
  4376. br.ErrMsg = "该客户" + productObj.ProductName + "属性为" + productObj.Status + ",暂不可删除"
  4377. return
  4378. }
  4379. companyProductList, companyReportPermissionList, err := company.DeleteCompanyProductById(productObj.CompanyId, productObj.ProductId, productObj.CompanyProductId)
  4380. if err != nil {
  4381. br.Msg = "删除失败"
  4382. br.ErrMsg = "删除失败,Err:" + err.Error()
  4383. return
  4384. }
  4385. //新增操作记录
  4386. {
  4387. record := new(company.CompanyOperationRecord)
  4388. record.CompanyId = req.CompanyId
  4389. record.CompanyName = productObj.CompanyName
  4390. record.SellerId = productObj.SellerId
  4391. record.SysUserId = this.SysUser.AdminId
  4392. record.SysRealName = this.SysUser.RealName
  4393. record.Remark = "删除客户"
  4394. record.Operation = "delete"
  4395. record.CreateTime = time.Now()
  4396. record.ProductId = productObj.ProductId
  4397. record.ProductName = productObj.ProductName
  4398. _, err = company.AddCompanyOperationRecord(record)
  4399. if err != nil {
  4400. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  4401. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  4402. }
  4403. }
  4404. //删除对应产品的联系人
  4405. userSellerRelationList, userRecordList, wxUserList, chartClassifyPermission, _ := services.DeleteCompanyWxUserByProductId(productObj.CompanyId, productId)
  4406. //备份信息
  4407. {
  4408. if companyProductList != nil {
  4409. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductList...)
  4410. }
  4411. if companyReportPermissionList != nil {
  4412. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissionList...)
  4413. }
  4414. if userSellerRelationList != nil {
  4415. companyDeleteBakInfo.UserSellerRelationInfo = append(companyDeleteBakInfo.UserSellerRelationInfo, userSellerRelationList...)
  4416. }
  4417. if userRecordList != nil {
  4418. companyDeleteBakInfo.UserRecordInfo = append(companyDeleteBakInfo.UserRecordInfo, userRecordList...)
  4419. }
  4420. if wxUserList != nil {
  4421. companyDeleteBakInfo.UserInfo = append(companyDeleteBakInfo.UserInfo, wxUserList...)
  4422. }
  4423. if chartClassifyPermission != nil {
  4424. companyDeleteBakInfo.CompanyChartPermissionInfo = append(companyDeleteBakInfo.CompanyChartPermissionInfo, chartClassifyPermission...)
  4425. }
  4426. companyDeleteBakInfo.CompanyName = productObj.CompanyName
  4427. }
  4428. }
  4429. productItemsNew, err := company.GetCompanyProductsByCompanyId(req.CompanyId)
  4430. if err != nil {
  4431. br.Msg = "删除失败"
  4432. br.ErrMsg = "获取客户产品信息失败,Err:" + err.Error()
  4433. return
  4434. }
  4435. if len(productItemsNew) == 0 {
  4436. //删除之前查询的数据信息
  4437. {
  4438. companyProductLists, companyReportPermissions, wxUsers, userSellerRelations, companyContracts, companyContractPermissions, companyInfo, _ := services.GetBeforeDeleteCompanyInfo(req.CompanyId)
  4439. //companyDeleteBakInfo
  4440. if companyProductLists != nil {
  4441. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductLists...)
  4442. }
  4443. if companyReportPermissions != nil {
  4444. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissions...)
  4445. }
  4446. if wxUsers != nil {
  4447. companyDeleteBakInfo.UserInfo = append(companyDeleteBakInfo.UserInfo, wxUsers...)
  4448. }
  4449. if userSellerRelations != nil {
  4450. companyDeleteBakInfo.UserSellerRelationInfo = append(companyDeleteBakInfo.UserSellerRelationInfo, userSellerRelations...)
  4451. }
  4452. if companyContracts != nil {
  4453. companyDeleteBakInfo.CompanyContract = append(companyDeleteBakInfo.CompanyContract, companyContracts...)
  4454. }
  4455. if companyContractPermissions != nil {
  4456. companyDeleteBakInfo.CompanyContractPermission = append(companyDeleteBakInfo.CompanyContractPermission, companyContractPermissions...)
  4457. }
  4458. if companyInfo != nil {
  4459. companyDeleteBakInfo.CompanyName = companyInfo.CompanyName
  4460. companyDeleteBakInfo.CompanyInfo = companyInfo
  4461. }
  4462. }
  4463. err = company.DeleteCompanyById(req.CompanyId)
  4464. if err != nil {
  4465. br.Msg = "删除失败"
  4466. br.ErrMsg = "删除失败,Err:" + err.Error()
  4467. return
  4468. }
  4469. for _, v := range productItems {
  4470. //新增操作记录
  4471. {
  4472. record := new(company.CompanyOperationRecord)
  4473. record.CompanyId = req.CompanyId
  4474. record.CompanyName = v.CompanyName
  4475. record.SellerId = v.SellerId
  4476. record.SysUserId = this.SysUser.AdminId
  4477. record.SysRealName = this.SysUser.RealName
  4478. record.Remark = "删除客户"
  4479. record.Operation = "delete"
  4480. record.CreateTime = time.Now()
  4481. record.ProductId = v.ProductId
  4482. record.ProductName = v.ProductName
  4483. _, err = company.AddCompanyOperationRecord(record)
  4484. if err != nil {
  4485. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  4486. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  4487. }
  4488. }
  4489. }
  4490. }
  4491. //数据备份入库
  4492. {
  4493. companyInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyInfo)
  4494. companyProductInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyProductInfo)
  4495. companyPermissionInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyPermissionInfo)
  4496. userSellerRelationInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.UserSellerRelationInfo)
  4497. userRecordInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.UserRecordInfo)
  4498. userInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.UserInfo)
  4499. companyChartPermissionInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyChartPermissionInfo)
  4500. companyContractByte, _ := json.Marshal(companyDeleteBakInfo.CompanyContract)
  4501. companyContractPermissionJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyContractPermission)
  4502. companyDeleteBak := &company.CompanyDeleteBak{
  4503. //DeleteBakId: 0,
  4504. CompanyId: companyDeleteBakInfo.CompanyId,
  4505. CompanyName: companyDeleteBakInfo.CompanyName,
  4506. CompanyInfo: string(companyInfoJsonByte),
  4507. CompanyProductInfo: string(companyProductInfoJsonByte),
  4508. CompanyPermissionInfo: string(companyPermissionInfoJsonByte),
  4509. UserSellerRelationInfo: string(userSellerRelationInfoJsonByte),
  4510. UserRecordInfo: string(userRecordInfoJsonByte),
  4511. UserInfo: string(userInfoJsonByte),
  4512. CompanyChartPermissionInfo: string(companyChartPermissionInfoJsonByte),
  4513. CompanyContractInfo: string(companyContractByte),
  4514. CompanyContractPermissionInfo: string(companyContractPermissionJsonByte),
  4515. OpUserId: this.SysUser.AdminId,
  4516. OpUserName: this.SysUser.RealName,
  4517. CreateTime: time.Now(),
  4518. }
  4519. _ = company.AddCompanyDeleteBak(companyDeleteBak)
  4520. }
  4521. br.Ret = 200
  4522. br.Success = true
  4523. br.Msg = "删除成功"
  4524. }
  4525. // @Title 领取客户列表
  4526. // @Description 领取客户列表接口
  4527. // @Param PageSize query int true "每页数据条数"
  4528. // @Param CurrentIndex query int true "当前页页码,从1开始"
  4529. // @Param StartDate query string true "开始时间"
  4530. // @Param EndDate query string true "结束时间"
  4531. // @Param KeyWord query string true "搜索关键词"
  4532. // @Success 200 {object} company.CompanyReceiveListResp
  4533. // @router /receive/list [get]
  4534. func (this *CompanyController) ReceiveList() {
  4535. br := new(models.BaseResponse).Init()
  4536. defer func() {
  4537. this.Data["json"] = br
  4538. this.ServeJSON()
  4539. }()
  4540. sysUser := this.SysUser
  4541. if sysUser == nil {
  4542. br.Msg = "请登录"
  4543. br.ErrMsg = "请登录,SysUser Is Empty"
  4544. br.Ret = 408
  4545. return
  4546. }
  4547. var productId, recevieProductId int
  4548. roleTypeCode := sysUser.RoleTypeCode
  4549. productId = services.GetProductId(roleTypeCode)
  4550. if productId == 1 {
  4551. recevieProductId = 2
  4552. } else if productId == 2 {
  4553. recevieProductId = 1
  4554. }
  4555. if productId == 0 {
  4556. br.Msg = "参数错误"
  4557. br.ErrMsg = "客户类型为:" + roleTypeCode
  4558. return
  4559. }
  4560. pageSize, _ := this.GetInt("PageSize")
  4561. currentIndex, _ := this.GetInt("CurrentIndex")
  4562. adminId := this.GetString("AdminId")
  4563. startDate := this.GetString("StartDate")
  4564. endDate := this.GetString("EndDate")
  4565. keyWord := this.GetString("KeyWord")
  4566. var startSize int
  4567. if pageSize <= 0 {
  4568. pageSize = utils.PageSize20
  4569. }
  4570. if currentIndex <= 0 {
  4571. currentIndex = 1
  4572. }
  4573. startSize = paging.StartIndex(currentIndex, pageSize)
  4574. var condition string
  4575. var pars []interface{}
  4576. if adminId != "" {
  4577. condition += ` AND c.seller_id IN (` + adminId + `) `
  4578. }
  4579. if startDate != "" {
  4580. condition += ` AND c.start_date>=? `
  4581. pars = append(pars, startDate)
  4582. }
  4583. if endDate != "" {
  4584. condition += ` AND c.end_date>=? `
  4585. pars = append(pars, endDate)
  4586. }
  4587. if keyWord != "" {
  4588. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR b.mobile LIKE '%` + keyWord + `%' OR b.email LIKE '%` + keyWord + `%') `
  4589. }
  4590. total, err := company.GetCompanyReceiveListCount(condition, pars, productId, recevieProductId)
  4591. if err != nil {
  4592. br.Msg = "获取失败"
  4593. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  4594. return
  4595. }
  4596. list, err := company.GetCompanyReceiveList(condition, pars, productId, recevieProductId, startSize, pageSize)
  4597. if err != nil {
  4598. br.Msg = "获取失败"
  4599. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  4600. return
  4601. }
  4602. lenList := len(list)
  4603. for i := 0; i < lenList; i++ {
  4604. item := list[i]
  4605. var expireDay string
  4606. if item.Status != "" {
  4607. status := item.Status
  4608. if item.EndDate != "" {
  4609. if status == utils.COMPANY_STATUS_FOREVER { //永续
  4610. expireDay = "-"
  4611. } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用/正式
  4612. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  4613. sub := endDateTime.Sub(time.Now())
  4614. expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  4615. } else if status == utils.COMPANY_STATUS_LOSE { //流失
  4616. expireDay = "-"
  4617. } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  4618. if item.StartDate != "" && item.EndDate != "" {
  4619. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  4620. sub := endDateTime.Sub(time.Now())
  4621. expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  4622. } else {
  4623. expireDay = "-"
  4624. }
  4625. } else {
  4626. expireDay = "-"
  4627. }
  4628. }
  4629. }
  4630. list[i].ExpireDay = expireDay
  4631. }
  4632. page := paging.GetPaging(currentIndex, pageSize, total)
  4633. resp := new(company.CompanyReceiveListResp)
  4634. resp.List = list
  4635. resp.Paging = page
  4636. br.Ret = 200
  4637. br.Success = true
  4638. br.Msg = "获取成功"
  4639. br.Data = resp
  4640. }
  4641. // @Title 领取客户
  4642. // @Description 领取客户接口
  4643. // @Param request body company.CompanyReceiveReq true "type json string"
  4644. // @Success Ret=200 领取成功
  4645. // @router /receive [post]
  4646. func (this *CompanyController) Receive() {
  4647. br := new(models.BaseResponse).Init()
  4648. defer func() {
  4649. this.Data["json"] = br
  4650. this.ServeJSON()
  4651. }()
  4652. sysUser := this.SysUser
  4653. if sysUser == nil {
  4654. br.Msg = "请登录"
  4655. br.ErrMsg = "请登录,SysUser Is Empty"
  4656. br.Ret = 408
  4657. return
  4658. }
  4659. var req company.CompanyReceiveReq
  4660. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4661. if err != nil {
  4662. br.Msg = "参数解析异常!"
  4663. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4664. return
  4665. }
  4666. if req.CompanyId <= 0 {
  4667. br.Msg = "参数异常!"
  4668. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  4669. return
  4670. }
  4671. //权益主观客观权限一块开
  4672. if req.PermissionIds != "" {
  4673. permissionStr, err := company.GetPermissionIdById(req.PermissionIds)
  4674. if err != nil {
  4675. br.Msg = "获取信息失败"
  4676. br.ErrMsg = "获取主观客观权限信息失败,Err:" + err.Error()
  4677. return
  4678. }
  4679. req.PermissionIds = permissionStr
  4680. }
  4681. roleTypeCode := sysUser.RoleTypeCode
  4682. productId := services.GetProductId(roleTypeCode)
  4683. if productId == 0 {
  4684. br.Msg = "参数错误"
  4685. br.ErrMsg = "客户类型为:" + roleTypeCode
  4686. return
  4687. }
  4688. sellsId := 0
  4689. if req.SellsId <= 0 {
  4690. sellsId = sysUser.AdminId
  4691. } else {
  4692. sellsId = req.SellsId
  4693. }
  4694. seller, err := system.GetSysAdminById(sellsId)
  4695. if err != nil {
  4696. br.Msg = "获取销售信息失败"
  4697. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  4698. return
  4699. }
  4700. companyDetail, err := company.GetCompanyDetailById(req.CompanyId)
  4701. if err != nil {
  4702. br.Msg = "获取客户信息失败"
  4703. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  4704. return
  4705. }
  4706. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  4707. if err != nil && err.Error() != utils.ErrNoRow() {
  4708. br.Msg = "获取客户信息失败"
  4709. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  4710. return
  4711. }
  4712. productName := ""
  4713. var status string
  4714. if productId == 1 {
  4715. productName = utils.COMPANY_PRODUCT_FICC_NAME
  4716. } else {
  4717. productName = utils.COMPANY_PRODUCT_RAI_NAME
  4718. }
  4719. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  4720. //查询客户的产品权限
  4721. companyReportPermissionListOld, err := company.GetCompanyReportPermission(req.CompanyId, productId)
  4722. if err != nil {
  4723. br.Msg = "查询客户的产品权限异常"
  4724. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  4725. return
  4726. }
  4727. var isNoResearch bool
  4728. for _, v := range companyReportPermissionListOld {
  4729. if v.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN && v.ChartPermissionId != utils.YAN_XUAN_KOU_DIAN_BAO_ID {
  4730. isNoResearch = true
  4731. continue
  4732. }
  4733. }
  4734. //如果所选行业不属于研选订阅跟研选扣点包,那就是非研选试用客户
  4735. if isNoResearch {
  4736. tryOutCountRai, err := company.GetRaiCompanyTryOutCountNoResearch(req.SellsId)
  4737. if err != nil {
  4738. br.Msg = "判断试用客户量失败"
  4739. br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  4740. return
  4741. }
  4742. if tryOutCountRai >= utils.COMPANY_STATUS_TRY_OUT_COUNT_RAI {
  4743. br.Msg = "非研选试用客户最多40家"
  4744. return
  4745. }
  4746. }
  4747. }
  4748. if cp != nil {
  4749. if cp.Status != utils.COMPANY_STATUS_LOSE {
  4750. br.Msg = "客户状态为:" + cp.Status + ";不可领取"
  4751. br.ErrMsg = "客户状态为:" + cp.Status + ";不可领取"
  4752. return
  4753. }
  4754. if cp.SellerId == sysUser.AdminId {
  4755. br.Msg = "已为自己客户,不可重复领取"
  4756. br.ErrMsg = "已为自己客户,不可领取:company_id:" + strconv.Itoa(cp.CompanyId)
  4757. return
  4758. }
  4759. //转移 销售
  4760. companyReportPermissionList, startDate, endDate, err := company.MoveSeller(req.CompanyId, productId, seller.AdminId, seller.GroupId, seller.DepartmentId, seller.RealName)
  4761. if err != nil {
  4762. br.Msg = "领取失败"
  4763. br.ErrMsg = "领取失败,Err:" + err.Error()
  4764. return
  4765. }
  4766. //新增客户产品状态变更日志
  4767. {
  4768. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  4769. Id: 0,
  4770. CompanyId: req.CompanyId,
  4771. ProductId: productId,
  4772. Status: "试用",
  4773. Source: "receive",
  4774. SellerId: seller.AdminId,
  4775. SellerName: seller.RealName,
  4776. StartDate: startDate,
  4777. EndDate: endDate,
  4778. RealEndDate: startDate,
  4779. CreateTime: time.Now(),
  4780. }
  4781. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  4782. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  4783. Id: 0,
  4784. CompanyId: req.CompanyId,
  4785. ProductId: productId,
  4786. Source: "receive",
  4787. SellerId: seller.AdminId,
  4788. SellerName: seller.RealName,
  4789. StartDate: startDate,
  4790. EndDate: endDate,
  4791. RealEndDate: startDate,
  4792. IsStop: 0,
  4793. CreateTime: time.Now(),
  4794. }
  4795. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  4796. }
  4797. //流失转试用,企业下面的用户自动添加产业关注
  4798. {
  4799. go cygxService.AddUserFllowCompanyLossToTryOut(req.CompanyId)
  4800. }
  4801. } else {
  4802. //跨部门领取
  4803. var startDateTime, endDateTime time.Time
  4804. if req.Status == utils.COMPANY_STATUS_TRY_OUT {
  4805. startDateTime = time.Now()
  4806. endDateTime = time.Now().AddDate(0, 2, 0)
  4807. } else if req.Status == utils.COMPANY_STATUS_FOREVER {
  4808. startDateTime = time.Now()
  4809. endDateTime = time.Now().AddDate(100, 0, 0)
  4810. } else {
  4811. br.Msg = "无效的客户状态,请重新选择"
  4812. return
  4813. }
  4814. var startDate, endDate string
  4815. startDate = startDateTime.Format(utils.FormatDate)
  4816. endDate = endDateTime.Format(utils.FormatDate)
  4817. if req.PermissionIds == "" {
  4818. br.Msg = "请选择权限!"
  4819. return
  4820. }
  4821. industry, err := company.GetCompanyIndustryById(req.IndustryId)
  4822. if err != nil {
  4823. br.Msg = "获取行业信息失败"
  4824. br.ErrMsg = "获取行业信息失败,Err:" + err.Error()
  4825. return
  4826. }
  4827. if industry == nil {
  4828. br.Msg = "行业信息不存在"
  4829. return
  4830. }
  4831. status = req.Status
  4832. companyProduct := new(company.CompanyProduct)
  4833. companyProduct.CompanyId = req.CompanyId
  4834. companyProduct.ProductId = productId
  4835. companyProduct.ProductName = productName
  4836. companyProduct.CompanyName = companyDetail.CompanyName
  4837. companyProduct.Source = req.Source
  4838. companyProduct.Reasons = req.Reasons
  4839. companyProduct.Status = status
  4840. companyProduct.StartDate = startDate
  4841. companyProduct.EndDate = endDate
  4842. companyProduct.IndustryId = req.IndustryId
  4843. companyProduct.IndustryName = industry.IndustryName
  4844. companyProduct.SellerId = seller.AdminId
  4845. companyProduct.SellerName = seller.RealName
  4846. companyProduct.GroupId = seller.GroupId
  4847. companyProduct.DepartmentId = seller.DepartmentId
  4848. companyProduct.IsSuspend = 0
  4849. companyProduct.CreateTime = time.Now()
  4850. companyProduct.ModifyTime = time.Now()
  4851. companyProduct.CompanyType = req.CompanyType
  4852. companyProduct.OpenCode = services.GenerateOpenCompanyProductCode(req.CompanyId, productId)
  4853. companyProduct.TodoStatus = "无任务"
  4854. companyProduct.TryStage = 1
  4855. companyProduct.SellerIdInit = seller.AdminId
  4856. companyProduct.SellerNameInit = seller.RealName
  4857. _, err = company.AddCompanyProduct(companyProduct)
  4858. if err != nil {
  4859. br.Msg = "新增失败"
  4860. br.ErrMsg = "新增客户产品失败,err:" + err.Error()
  4861. return
  4862. }
  4863. companyReportPermissionList, err := services.AddCompanyPermission(req.CompanyId, seller.AdminId, productId, productName, seller.RealName, req.PermissionIds, startDate, endDate)
  4864. if err != nil {
  4865. br.Msg = "新增失败"
  4866. br.ErrMsg = "新增客户设置权限失败,err:" + err.Error()
  4867. return
  4868. }
  4869. //新增客户产品日志
  4870. {
  4871. go services.AddCompanyProductLog(companyProduct, this.SysUser.AdminId, "add")
  4872. }
  4873. //新增客户产品状态变更日志
  4874. {
  4875. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  4876. Id: 0,
  4877. CompanyId: companyProduct.CompanyId,
  4878. ProductId: companyProduct.ProductId,
  4879. Status: "试用",
  4880. SellerId: seller.AdminId,
  4881. SellerName: seller.RealName,
  4882. Source: "add",
  4883. StartDate: startDateTime,
  4884. EndDate: endDateTime,
  4885. RealEndDate: startDateTime,
  4886. CreateTime: time.Now(),
  4887. }
  4888. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  4889. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  4890. Id: 0,
  4891. CompanyId: companyProduct.CompanyId,
  4892. ProductId: companyProduct.ProductId,
  4893. SellerId: seller.AdminId,
  4894. SellerName: seller.RealName,
  4895. Source: "add",
  4896. StartDate: startDateTime,
  4897. EndDate: endDateTime,
  4898. RealEndDate: startDateTime,
  4899. IsStop: 0,
  4900. CreateTime: time.Now(),
  4901. }
  4902. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  4903. }
  4904. //查询当前客户的所有产品的列表数据,并找出非当前产品的销售去发送模板消息
  4905. companyProductList, err := company.GetCompanyProductsByCompanyId(req.CompanyId)
  4906. for _, companyProduct := range companyProductList {
  4907. //如果是当前领取的产品,那么就退出当前循环,进入下一循环
  4908. if companyProduct.ProductId == productId {
  4909. continue
  4910. }
  4911. //查询其他部门销售的信息
  4912. admin, tmpErr := system.GetSysAdminById(companyProduct.SellerId)
  4913. if tmpErr != nil {
  4914. continue
  4915. }
  4916. //发送模板消息给另一个部门的销售
  4917. go services.SendCompanyReceiveWxTemplateMsg(companyDetail.CompanyName, productName, sysUser.RealName, admin.Mobile)
  4918. }
  4919. }
  4920. //新增操作记录
  4921. {
  4922. remark := "领取客户"
  4923. operation := "receive"
  4924. services.AddCompanyOperationRecord(req.CompanyId, seller.AdminId, sysUser.AdminId, productId, sysUser.AdminId, companyDetail.CompanyName,
  4925. productName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", status)
  4926. }
  4927. br.Ret = 200
  4928. br.Success = true
  4929. br.Msg = "领取成功"
  4930. }
  4931. // @Title 移动销售
  4932. // @Description 移动销售接口
  4933. // @Param request body company.MoveSellerReq true "type json string"
  4934. // @Success Ret=200 移动成功
  4935. // @router /move/seller [post]
  4936. func (this *CompanyController) MoveSeller() {
  4937. br := new(models.BaseResponse).Init()
  4938. defer func() {
  4939. this.Data["json"] = br
  4940. this.ServeJSON()
  4941. }()
  4942. sysUser := this.SysUser
  4943. if sysUser == nil {
  4944. br.Msg = "请登录"
  4945. br.ErrMsg = "请登录,SysUser Is Empty"
  4946. br.Ret = 408
  4947. return
  4948. }
  4949. var req company.MoveSellerReq
  4950. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4951. if err != nil {
  4952. br.Msg = "参数解析异常!"
  4953. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4954. return
  4955. }
  4956. if req.CompanyId <= 0 {
  4957. br.Msg = "参数异常!"
  4958. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  4959. return
  4960. }
  4961. if req.SellsId <= 0 {
  4962. br.Msg = "参数异常!"
  4963. br.ErrMsg = "SellsId:" + strconv.Itoa(req.SellsId)
  4964. return
  4965. }
  4966. seller, err := system.GetSysAdminById(req.SellsId)
  4967. if err != nil {
  4968. br.Msg = "获取销售信息失败"
  4969. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  4970. return
  4971. }
  4972. roleTypeCode := sysUser.RoleTypeCode
  4973. productId := services.GetProductId(roleTypeCode)
  4974. if productId == 0 {
  4975. if req.CompanyType == utils.COMPANY_CLASSIFY_FICC {
  4976. productId = 1
  4977. } else if req.CompanyType == utils.COMPANY_CLASSIFY_RAI {
  4978. productId = 2
  4979. }
  4980. }
  4981. if productId == 0 {
  4982. br.Msg = "无效的客户类型"
  4983. br.ErrMsg = "无效的客户类型"
  4984. return
  4985. }
  4986. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  4987. //查询客户的产品权限
  4988. companyReportPermissionListOld, err := company.GetCompanyReportPermission(req.CompanyId, productId)
  4989. if err != nil {
  4990. br.Msg = "查询客户的产品权限异常"
  4991. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  4992. return
  4993. }
  4994. var isNoResearch bool
  4995. for _, v := range companyReportPermissionListOld {
  4996. if v.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN && v.ChartPermissionId != utils.YAN_XUAN_KOU_DIAN_BAO_ID {
  4997. isNoResearch = true
  4998. continue
  4999. }
  5000. }
  5001. //如果所选行业不属于研选订阅跟研选扣点包,那就是非研选试用客户
  5002. if isNoResearch {
  5003. tryOutCountRai, err := company.GetRaiCompanyTryOutCountNoResearch(req.SellsId)
  5004. if err != nil {
  5005. br.Msg = "判断试用客户量失败"
  5006. br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  5007. return
  5008. }
  5009. if tryOutCountRai >= utils.COMPANY_STATUS_TRY_OUT_COUNT_RAI {
  5010. br.Msg = seller.RealName + "的非研选试用客户已超过40家"
  5011. return
  5012. }
  5013. }
  5014. }
  5015. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  5016. if err != nil && err.Error() != utils.ErrNoRow() {
  5017. if err.Error() == utils.ErrNoRow() {
  5018. br.Msg = "客户信息不存在"
  5019. br.ErrMsg = "客户信息不存在,Err:" + err.Error()
  5020. return
  5021. }
  5022. br.Msg = "获取客户信息失败"
  5023. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  5024. return
  5025. }
  5026. if cp == nil {
  5027. br.Msg = "客户信息不存在,请刷新页面"
  5028. br.ErrMsg = "客户信息不存在"
  5029. return
  5030. }
  5031. err = company.MoveCompanySeller(req.CompanyId, productId, req.SellsId, seller.GroupId, seller.DepartmentId, seller.RealName)
  5032. if err != nil {
  5033. br.Msg = "移动失败"
  5034. br.ErrMsg = "移动失败,Err:" + err.Error()
  5035. return
  5036. }
  5037. //新增操作记录
  5038. {
  5039. remark := "移动到:" + seller.RealName
  5040. operation := "move_seller"
  5041. services.AddCompanyOperationRecord(req.CompanyId, seller.AdminId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
  5042. cp.ProductName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
  5043. }
  5044. {
  5045. services.UpdateCompanyContractSellerMove(req.CompanyId, productId) //益客户移动所属销售之后,更新所关联的销售信息
  5046. }
  5047. //变更销售员与联系人关系
  5048. _ = models.UpdateUserSellerRelationByCompanyId(req.CompanyId, productId, seller.AdminId, seller.RealName)
  5049. br.Ret = 200
  5050. br.Success = true
  5051. br.Msg = "移动成功"
  5052. }
  5053. // @Title 修改试用客户标签
  5054. // @Description 修改试用客户标签接口
  5055. // @Param request body company.UpdateTryStageReq true "type json string"
  5056. // @Success Ret=200 设置成功
  5057. // @router /update/tryStage [post]
  5058. func (this *CompanyController) UpdateTryStage() {
  5059. br := new(models.BaseResponse).Init()
  5060. defer func() {
  5061. this.Data["json"] = br
  5062. this.ServeJSON()
  5063. }()
  5064. sysUser := this.SysUser
  5065. if sysUser == nil {
  5066. br.Msg = "请登录"
  5067. br.ErrMsg = "请登录,SysUser Is Empty"
  5068. br.Ret = 408
  5069. return
  5070. }
  5071. var req company.UpdateTryStageReq
  5072. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5073. if err != nil {
  5074. br.Msg = "参数解析异常!"
  5075. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5076. return
  5077. }
  5078. if req.CompanyId <= 0 {
  5079. br.Msg = "参数异常!"
  5080. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  5081. return
  5082. }
  5083. if req.ProductId <= 0 {
  5084. br.Msg = "参数异常!"
  5085. br.ErrMsg = "ProductId:" + strconv.Itoa(req.ProductId)
  5086. return
  5087. }
  5088. if req.TryStage <= 0 {
  5089. br.Msg = "参数异常!"
  5090. br.ErrMsg = "TryStage:" + strconv.Itoa(req.TryStage)
  5091. return
  5092. }
  5093. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  5094. if err != nil && err.Error() != utils.ErrNoRow() {
  5095. if err.Error() == utils.ErrNoRow() {
  5096. br.Msg = "客户信息不存在"
  5097. br.ErrMsg = "客户信息不存在,Err:" + err.Error()
  5098. return
  5099. }
  5100. br.Msg = "获取客户信息失败"
  5101. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  5102. return
  5103. }
  5104. fmt.Println(cp)
  5105. if cp == nil {
  5106. br.Msg = "客户信息不存在,请刷新页面"
  5107. br.ErrMsg = "客户信息不存在"
  5108. return
  5109. }
  5110. if cp.Status != "试用" {
  5111. br.Msg = "客户不是试用状态,不允许修改"
  5112. br.ErrMsg = "客户不是试用状态,不允许修改"
  5113. return
  5114. }
  5115. if cp.SellerId != sysUser.AdminId {
  5116. br.Msg = "无修改权限"
  5117. br.ErrMsg = "无修改权限"
  5118. return
  5119. }
  5120. if cp.TryStage == req.TryStage {
  5121. br.Msg = "与原标签一致,无需修改"
  5122. br.ErrMsg = "与原标签一致,无需修改"
  5123. return
  5124. }
  5125. err = company.UpdateCompanyTryStage(req.CompanyId, req.ProductId, req.TryStage)
  5126. if err != nil {
  5127. br.Msg = "设置失败"
  5128. br.ErrMsg = "设置失败,Err:" + err.Error()
  5129. return
  5130. }
  5131. //新增操作记录
  5132. {
  5133. stage := ""
  5134. tryStageAllMap := map[int]string{
  5135. 1: "未分类",
  5136. 2: "推进",
  5137. 3: "跟踪",
  5138. 4: "预备",
  5139. }
  5140. if v, ok := tryStageAllMap[req.TryStage]; ok {
  5141. stage = v
  5142. }
  5143. remark := "修改试用客户子标签:" + stage
  5144. operation := "UpdateTryStage"
  5145. services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  5146. cp.ProductName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
  5147. }
  5148. br.Ret = 200
  5149. br.Success = true
  5150. br.Msg = "设置成功"
  5151. }
  5152. // @Title 暂停/启用
  5153. // @Description 暂停/启用接口
  5154. // @Param request body company.SuspendReq true "type json string"
  5155. // @Success Ret=200 移动成功
  5156. // @router /suspend [post]
  5157. func (this *CompanyController) Suspend() {
  5158. br := new(models.BaseResponse).Init()
  5159. defer func() {
  5160. this.Data["json"] = br
  5161. this.ServeJSON()
  5162. }()
  5163. sysUser := this.SysUser
  5164. if sysUser == nil {
  5165. br.Msg = "请登录"
  5166. br.ErrMsg = "请登录,SysUser Is Empty"
  5167. br.Ret = 408
  5168. return
  5169. }
  5170. var req company.SuspendReq
  5171. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5172. if err != nil {
  5173. br.Msg = "参数解析异常!"
  5174. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5175. return
  5176. }
  5177. if req.CompanyId <= 0 {
  5178. br.Msg = "参数异常!"
  5179. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  5180. return
  5181. }
  5182. roleTypeCode := sysUser.RoleTypeCode
  5183. productId := services.GetProductId(roleTypeCode)
  5184. if productId == 0 {
  5185. br.Msg = "参数错误"
  5186. br.ErrMsg = "角色类型为:" + roleTypeCode
  5187. return
  5188. }
  5189. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  5190. if err != nil {
  5191. br.Msg = "获取数据异常!"
  5192. br.ErrMsg = "获取数据异常:" + err.Error()
  5193. return
  5194. }
  5195. suspendStatus := ""
  5196. suspend := 0
  5197. if cp.IsSuspend == 1 {
  5198. suspendStatus = "启用"
  5199. suspend = 0
  5200. } else {
  5201. suspendStatus = "暂停"
  5202. suspend = 1
  5203. }
  5204. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  5205. br.Msg = "客户状态为:" + cp.Status + ",不允许进行" + suspendStatus + "操作"
  5206. br.ErrMsg = "客户状态为:" + cp.Status + ",不允许进行" + suspendStatus + "操作"
  5207. return
  5208. }
  5209. err = company.SuspendCompanyProductById(req.CompanyId, productId, suspend)
  5210. if err != nil {
  5211. br.Msg = suspendStatus + "失败"
  5212. br.ErrMsg = suspendStatus + "失败 Err:" + err.Error()
  5213. return
  5214. }
  5215. //新增操作记录
  5216. {
  5217. remark := suspendStatus
  5218. operation := "is_suspend"
  5219. services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
  5220. cp.ProductName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
  5221. }
  5222. br.Ret = 200
  5223. br.Success = true
  5224. br.Msg = suspendStatus + "成功"
  5225. }
  5226. // @Title 检测客户名称或社会信用码
  5227. // @Description 检测客户名称或社会信用码接口(新增/编辑客户页面使用)
  5228. // @Param CompanyName query string true "客户名称"
  5229. // @Param CreditCode query string true "社会统一信用码"
  5230. // @Success 200 {object} company.CheckCompanyInfoResp
  5231. // @router /check/companyInfo [get]
  5232. func (this *CompanyController) CheckCompanyInfo() {
  5233. br := new(models.BaseResponse).Init()
  5234. defer func() {
  5235. this.Data["json"] = br
  5236. this.ServeJSON()
  5237. }()
  5238. sysUser := this.SysUser
  5239. if sysUser == nil {
  5240. br.Msg = "请登录"
  5241. br.ErrMsg = "请登录,SysUser Is Empty"
  5242. br.Ret = 408
  5243. return
  5244. }
  5245. roleTypeCode := sysUser.RoleTypeCode
  5246. productId := services.GetProductId(roleTypeCode)
  5247. companyName := this.GetString("CompanyName")
  5248. creditCode := this.GetString("CreditCode")
  5249. var status, comanyId int
  5250. var productName string
  5251. if productId == 0 {
  5252. productId = 1
  5253. checkProductId := 2
  5254. if companyName != "" {
  5255. nameItem, err := company.CheckCompanyProductByName(companyName, productId)
  5256. if err != nil && err.Error() != utils.ErrNoRow() {
  5257. br.Msg = "校验客户名称是否存在失败"
  5258. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
  5259. return
  5260. }
  5261. if nameItem != nil && nameItem.CompanyId > 0 {
  5262. br.Msg = "客户名称已存在,请重新填写"
  5263. br.ErrMsg = "客户名称已存在,请重新填写"
  5264. br.Ret = 405
  5265. return
  5266. }
  5267. nameCheckItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
  5268. if err != nil && err.Error() != utils.ErrNoRow() {
  5269. br.Msg = "校验客户名称是否存在失败"
  5270. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5271. return
  5272. }
  5273. if nameCheckItem != nil && nameCheckItem.CompanyId > 0 {
  5274. status = 1
  5275. productName = nameCheckItem.ProductName
  5276. comanyId = nameCheckItem.CompanyId
  5277. goto Loop
  5278. }
  5279. }
  5280. if creditCode != "" {
  5281. codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
  5282. if err != nil && err.Error() != utils.ErrNoRow() {
  5283. br.Msg = "校验社会信用码是否存在失败"
  5284. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
  5285. return
  5286. }
  5287. if codeItem != nil && codeItem.CompanyId > 0 {
  5288. br.Msg = "社会信用码已存在,请重新填写"
  5289. br.ErrMsg = "社会信用码已存在,请重新填写"
  5290. br.Ret = 405
  5291. return
  5292. }
  5293. codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
  5294. if err != nil && err.Error() != utils.ErrNoRow() {
  5295. br.Msg = "校验社会信用码是否存在失败"
  5296. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5297. return
  5298. }
  5299. if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
  5300. status = 1
  5301. productName = codeCheckItem.ProductName
  5302. comanyId = codeCheckItem.CompanyId
  5303. goto Loop
  5304. }
  5305. }
  5306. productId = 2
  5307. checkProductId = 1
  5308. if companyName != "" {
  5309. nameItem, err := company.CheckCompanyProductByName(companyName, productId)
  5310. if err != nil && err.Error() != utils.ErrNoRow() {
  5311. br.Msg = "校验客户名称是否存在失败"
  5312. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
  5313. return
  5314. }
  5315. if nameItem != nil && nameItem.CompanyId > 0 {
  5316. br.Msg = "客户名称已存在,请重新填写"
  5317. br.ErrMsg = "客户名称已存在,请重新填写"
  5318. br.Ret = 405
  5319. return
  5320. }
  5321. nameCheckItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
  5322. if err != nil && err.Error() != utils.ErrNoRow() {
  5323. br.Msg = "校验客户名称是否存在失败"
  5324. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5325. return
  5326. }
  5327. if nameCheckItem != nil && nameCheckItem.CompanyId > 0 {
  5328. status = 1
  5329. productName = nameCheckItem.ProductName
  5330. comanyId = nameCheckItem.CompanyId
  5331. goto Loop
  5332. }
  5333. }
  5334. if creditCode != "" {
  5335. codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
  5336. if err != nil && err.Error() != utils.ErrNoRow() {
  5337. br.Msg = "校验社会信用码是否存在失败"
  5338. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
  5339. return
  5340. }
  5341. if codeItem != nil && codeItem.CompanyId > 0 {
  5342. br.Msg = "社会信用码已存在,请重新填写"
  5343. br.ErrMsg = "社会信用码已存在,请重新填写"
  5344. br.Ret = 405
  5345. return
  5346. }
  5347. codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
  5348. if err != nil && err.Error() != utils.ErrNoRow() {
  5349. br.Msg = "校验社会信用码是否存在失败"
  5350. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5351. return
  5352. }
  5353. if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
  5354. status = 1
  5355. productName = codeCheckItem.ProductName
  5356. comanyId = codeCheckItem.CompanyId
  5357. goto Loop
  5358. }
  5359. }
  5360. } else {
  5361. checkProductId := 0
  5362. if productId == 1 {
  5363. checkProductId = 2
  5364. } else if productId == 2 {
  5365. checkProductId = 1
  5366. }
  5367. if companyName != "" {
  5368. nameItem, err := company.CheckCompanyProductByName(companyName, productId)
  5369. if err != nil && err.Error() != utils.ErrNoRow() {
  5370. br.Msg = "校验客户名称是否存在失败"
  5371. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
  5372. return
  5373. }
  5374. if nameItem != nil && nameItem.ProductName != "" {
  5375. br.Msg = "客户名称已存在,请重新填写"
  5376. br.ErrMsg = "客户名称已存在,请重新填写"
  5377. br.Ret = 405
  5378. return
  5379. }
  5380. nameCheckoutItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
  5381. if err != nil && err.Error() != utils.ErrNoRow() {
  5382. br.Msg = "校验客户名称是否存在失败"
  5383. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5384. return
  5385. }
  5386. if nameCheckoutItem != nil && nameCheckoutItem.CompanyId > 0 {
  5387. status = 1
  5388. productName = nameCheckoutItem.ProductName
  5389. comanyId = nameCheckoutItem.CompanyId
  5390. goto Loop
  5391. }
  5392. }
  5393. if creditCode != "" {
  5394. codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
  5395. if err != nil && err.Error() != utils.ErrNoRow() {
  5396. br.Msg = "校验社会信用码是否存在失败"
  5397. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
  5398. return
  5399. }
  5400. if codeItem != nil && codeItem.CompanyId > 0 {
  5401. br.Msg = "社会信用码已存在,请重新填写"
  5402. br.ErrMsg = "社会信用码已存在,请重新填写"
  5403. br.Ret = 405
  5404. return
  5405. }
  5406. codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
  5407. if err != nil && err.Error() != utils.ErrNoRow() {
  5408. br.Msg = "校验社会信用码是否存在失败"
  5409. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5410. return
  5411. }
  5412. if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
  5413. status = 1
  5414. productName = codeCheckItem.ProductName
  5415. comanyId = codeCheckItem.CompanyId
  5416. goto Loop
  5417. }
  5418. }
  5419. }
  5420. Loop:
  5421. resp := new(company.CheckCompanyInfoResp)
  5422. resp.Status = status
  5423. resp.ProductName = productName
  5424. resp.CompanyId = comanyId
  5425. br.Ret = 200
  5426. br.Success = true
  5427. br.Msg = "获取成功"
  5428. br.Data = resp
  5429. }
  5430. // @Title 客户导出
  5431. // @Description 客户导出接口
  5432. // @Param Status query string true "状态:'试用','永续','冻结','流失','正式'"
  5433. // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
  5434. // @Param IndustryId query int true "行业id,0为全部"
  5435. // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
  5436. // @Param ChartPermissionIds query string false "阅读权限品种ID,多个用英文逗号分开,空字符串为全部"
  5437. // @Param ContractPermissionIds query string false "已购品种ID,多个用英文逗号分开,空字符串为全部"
  5438. // @Param StartDate query string true "开始时间"
  5439. // @Param EndDate query string true "结束时间"
  5440. // @Param CreateStartDate query string true "创建开始时间"
  5441. // @Param CreateEndDate query string true "创建结束时间"
  5442. // @Param KeyWord query string true "搜索关键词"
  5443. // @Param Address query string true "地址 , 多个用英文逗号分开 "
  5444. // @Param Province query string true "省 , 多个用英文逗号分开 "
  5445. // @Param City query string true "市 , 多个用英文逗号分开 "
  5446. // @Param PackageType query int true "套餐类型,0:无,1:大套餐,2:小套餐"
  5447. // @Success 200 {object} company.CompanyListResp
  5448. // @router /export [get]
  5449. func (this *CompanyController) Export() {
  5450. br := new(models.BaseResponse).Init()
  5451. defer func() {
  5452. this.Data["json"] = br
  5453. this.ServeJSON()
  5454. }()
  5455. sysUser := this.SysUser
  5456. if sysUser == nil {
  5457. br.Msg = "请登录"
  5458. br.ErrMsg = "请登录,SysUser Is Empty"
  5459. br.Ret = 408
  5460. return
  5461. }
  5462. roleTypeCode := sysUser.RoleTypeCode
  5463. status := this.GetString("Status")
  5464. companyType := this.GetString("CompanyType")
  5465. industryId, _ := this.GetInt("IndustryId")
  5466. adminId := this.GetString("AdminId")
  5467. chartPermissionIds := this.GetString("ChartPermissionIds")
  5468. contractPermissionIds := this.GetString("ContractPermissionIds")
  5469. startDate := this.GetString("StartDate")
  5470. endDate := this.GetString("EndDate")
  5471. createStartDate := this.GetString("CreateStartDate")
  5472. createEndDate := this.GetString("CreateEndDate")
  5473. keyWord := this.GetString("KeyWord")
  5474. keyWord = strings.Trim(keyWord, " ")
  5475. address := this.GetString("Address")
  5476. province := this.GetString("Province")
  5477. city := this.GetString("City")
  5478. // 套餐类型
  5479. packageType, _ := this.GetInt("PackageType")
  5480. resp := new(company.CompanyListResp)
  5481. statusItems := make([]*company.CompanyStatus, 0)
  5482. var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}
  5483. var condition string
  5484. var pars []interface{}
  5485. //状态分类查询条件
  5486. var permissionCondition string
  5487. var permissionPars []interface{}
  5488. if companyType != "" {
  5489. condition += ` AND b.product_name=? `
  5490. pars = append(pars, companyType)
  5491. }
  5492. if industryId > 0 {
  5493. condition += ` AND b.industry_id=? `
  5494. pars = append(pars, industryId)
  5495. }
  5496. if adminId != "" {
  5497. condition += ` AND b.seller_id IN (` + adminId + `) `
  5498. }
  5499. if startDate != "" {
  5500. condition += ` AND b.start_date>=? `
  5501. pars = append(pars, startDate)
  5502. }
  5503. if endDate != "" {
  5504. condition += ` AND b.end_date<=? `
  5505. pars = append(pars, endDate)
  5506. }
  5507. if createStartDate != "" {
  5508. condition += ` AND a.created_time>=? `
  5509. pars = append(pars, createStartDate)
  5510. }
  5511. if createEndDate != "" {
  5512. condition += ` AND a.created_time<=? `
  5513. pars = append(pars, createEndDate)
  5514. }
  5515. if address != "" {
  5516. var addressSql string
  5517. slice := strings.Split(address, ",")
  5518. for _, v := range slice {
  5519. addressSql += "'" + v + "'" + ","
  5520. }
  5521. addressSql = strings.TrimRight(addressSql, ",")
  5522. condition += ` AND a.address IN (` + addressSql + `) `
  5523. }
  5524. if province != "" {
  5525. var provinceSql string
  5526. slice := strings.Split(province, ",")
  5527. for _, v := range slice {
  5528. provinceSql += "'" + v + "'" + ","
  5529. }
  5530. provinceSql = strings.TrimRight(provinceSql, ",")
  5531. condition += ` AND a.province IN (` + provinceSql + `) `
  5532. }
  5533. if city != "" {
  5534. var citySql string
  5535. slice := strings.Split(city, ",")
  5536. for _, v := range slice {
  5537. citySql += "'" + v + "'" + ","
  5538. }
  5539. citySql = strings.TrimRight(citySql, ",")
  5540. condition += ` AND a.city IN (` + citySql + `) `
  5541. }
  5542. if keyWord != "" {
  5543. companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
  5544. if err != nil {
  5545. br.Msg = "获取客户信息失败"
  5546. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  5547. return
  5548. }
  5549. if companyIdStr != "" {
  5550. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  5551. } else {
  5552. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  5553. }
  5554. }
  5555. //if chartPermissionIds != "" && chartPermissionIds != "1" {
  5556. // companyIdStr, err := company.GetCompanyListCompanyIdByPermissionIdStr(chartPermissionIds)
  5557. // if err != nil {
  5558. // br.Msg = "获取失败"
  5559. // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
  5560. // return
  5561. // }
  5562. // if companyIdStr != "" {
  5563. // condition += ` AND a.company_id IN (` + companyIdStr + `) `
  5564. // } else {
  5565. // for _, v := range statusArr {
  5566. // statusCount := new(company.CompanyStatus)
  5567. // if v == "全部" {
  5568. // statusCount.Status = "全部"
  5569. // statusCount.Count = 0
  5570. // } else {
  5571. // statusCount.Status = v
  5572. // statusCount.Count = 0
  5573. // }
  5574. // statusItems = append(statusItems, statusCount)
  5575. // }
  5576. // items := make([]*company.CompanyListItem, 0)
  5577. // resp.List = items
  5578. // resp.StatusCount = statusItems
  5579. // br.Msg = "获取成功"
  5580. // br.Ret = 200
  5581. // br.Data = resp
  5582. // return
  5583. // }
  5584. //}
  5585. // 阅读权限/已购品种筛选
  5586. cond, emp, e := services.FilterReadAndContractAuth(chartPermissionIds, contractPermissionIds, condition)
  5587. if e != nil {
  5588. br.Msg = "获取失败"
  5589. br.ErrMsg = "FilterReadAndContractAuth err: " + e.Error()
  5590. return
  5591. }
  5592. if emp {
  5593. for _, v := range statusArr {
  5594. statusCount := new(company.CompanyStatus)
  5595. if v == "全部" {
  5596. statusCount.Status = "全部"
  5597. statusCount.Count = 0
  5598. } else {
  5599. statusCount.Status = v
  5600. statusCount.Count = 0
  5601. }
  5602. statusItems = append(statusItems, statusCount)
  5603. }
  5604. items := make([]*company.CompanyListItem, 0)
  5605. resp.List = items
  5606. resp.StatusCount = statusItems
  5607. br.Msg = "获取成功"
  5608. br.Ret = 200
  5609. br.Data = resp
  5610. return
  5611. }
  5612. condition = cond
  5613. //套餐类型
  5614. if packageType > 0 {
  5615. condition += ` AND b.package_type=? `
  5616. pars = append(pars, packageType)
  5617. }
  5618. permissionCondition = condition
  5619. permissionPars = pars
  5620. productId := services.GetProductId(roleTypeCode)
  5621. //权限控制
  5622. {
  5623. //如果不是超级管理员
  5624. if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  5625. //如果是部门管理员
  5626. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  5627. condition += ` AND b.product_id=? `
  5628. pars = append(pars, productId)
  5629. permissionCondition += ` AND b.product_id=? `
  5630. permissionPars = append(permissionPars, productId)
  5631. } else {
  5632. condition += ` AND b.product_id=? `
  5633. pars = append(pars, productId)
  5634. permissionCondition += ` AND b.product_id=? `
  5635. permissionPars = append(permissionPars, productId)
  5636. if status == "全部" {
  5637. ////如果是筛选了流失客户状态
  5638. if sysUser.Authority <= 0 {
  5639. condition += ` AND (b.seller_id=? OR status='流失') `
  5640. pars = append(pars, sysUser.AdminId)
  5641. permissionCondition += ` AND b.seller_id=? `
  5642. permissionPars = append(permissionPars, sysUser.AdminId)
  5643. } else {
  5644. if sysUser.Authority == 1 {
  5645. condition += ` AND (b.department_id=? OR status='流失')`
  5646. pars = append(pars, sysUser.DepartmentId)
  5647. permissionCondition += ` AND b.department_id=? `
  5648. permissionPars = append(permissionPars, sysUser.DepartmentId)
  5649. }
  5650. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  5651. if status != utils.COMPANY_STATUS_LOSE {
  5652. condition += ` AND (b.group_id=? OR status='流失') `
  5653. pars = append(pars, sysUser.GroupId)
  5654. }
  5655. permissionCondition += ` AND b.group_id=? `
  5656. permissionPars = append(permissionPars, sysUser.GroupId)
  5657. }
  5658. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  5659. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  5660. if err != nil {
  5661. br.Msg = "获取失败"
  5662. br.ErrMsg = "查询父级id异常" + err.Error()
  5663. return
  5664. }
  5665. var ids []*string
  5666. if pid != nil && *pid != 0 {
  5667. ids, err = company.GetGroupIdsByParentId(*pid)
  5668. if err != nil {
  5669. fmt.Println(err.Error())
  5670. }
  5671. } else {
  5672. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  5673. if err != nil {
  5674. fmt.Println(err.Error())
  5675. }
  5676. }
  5677. var idSlice []string
  5678. var sid string
  5679. for _, id := range ids {
  5680. idSlice = append(idSlice, *id)
  5681. }
  5682. //加入父级groupId
  5683. if *pid > 0 {
  5684. idSlice = append(idSlice, strconv.Itoa(*pid))
  5685. } else {
  5686. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  5687. }
  5688. sid = strings.Join(idSlice, ",")
  5689. if len(sid) > 0 {
  5690. if status != utils.COMPANY_STATUS_LOSE {
  5691. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  5692. //pars = append(pars, sysUser.GroupId)
  5693. }
  5694. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  5695. } else {
  5696. if status != utils.COMPANY_STATUS_LOSE {
  5697. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  5698. //pars = append(pars, sysUser.GroupId)
  5699. }
  5700. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  5701. }
  5702. }
  5703. }
  5704. } else {
  5705. ////如果没有筛选了流失客户状态
  5706. if sysUser.Authority <= 0 {
  5707. condition += ` AND b.seller_id=? `
  5708. pars = append(pars, sysUser.AdminId)
  5709. permissionCondition += ` AND b.seller_id=? `
  5710. permissionPars = append(permissionPars, sysUser.AdminId)
  5711. } else {
  5712. if sysUser.Authority == 1 {
  5713. condition += ` AND b.department_id=?`
  5714. pars = append(pars, sysUser.DepartmentId)
  5715. permissionCondition += ` AND b.department_id=? `
  5716. permissionPars = append(permissionPars, sysUser.DepartmentId)
  5717. }
  5718. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  5719. if status != utils.COMPANY_STATUS_LOSE {
  5720. condition += ` AND b.group_id=? `
  5721. pars = append(pars, sysUser.GroupId)
  5722. }
  5723. permissionCondition += ` AND b.group_id=? `
  5724. permissionPars = append(permissionPars, sysUser.GroupId)
  5725. }
  5726. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  5727. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  5728. if err != nil {
  5729. br.Msg = "获取失败"
  5730. br.ErrMsg = "查询父级id异常" + err.Error()
  5731. return
  5732. }
  5733. var ids []*string
  5734. if pid != nil && *pid != 0 {
  5735. ids, err = company.GetGroupIdsByParentId(*pid)
  5736. if err != nil {
  5737. fmt.Println(err.Error())
  5738. }
  5739. } else {
  5740. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  5741. if err != nil {
  5742. fmt.Println(err.Error())
  5743. }
  5744. }
  5745. var idSlice []string
  5746. var sid string
  5747. for _, id := range ids {
  5748. idSlice = append(idSlice, *id)
  5749. }
  5750. //加入父级groupId
  5751. if *pid > 0 {
  5752. idSlice = append(idSlice, strconv.Itoa(*pid))
  5753. } else {
  5754. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  5755. }
  5756. sid = strings.Join(idSlice, ",")
  5757. if len(sid) > 0 {
  5758. if status != utils.COMPANY_STATUS_LOSE {
  5759. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  5760. //pars = append(pars, sysUser.GroupId)
  5761. }
  5762. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  5763. } else {
  5764. if status != utils.COMPANY_STATUS_LOSE {
  5765. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  5766. //pars = append(pars, sysUser.GroupId)
  5767. }
  5768. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  5769. }
  5770. }
  5771. if sysUser.Authority == 4 {
  5772. if status != utils.COMPANY_STATUS_LOSE {
  5773. condition += ` AND b.group_id =? `
  5774. pars = append(pars, sysUser.GroupId)
  5775. }
  5776. permissionCondition += ` AND b.group_id=? `
  5777. permissionPars = append(permissionPars, sysUser.GroupId)
  5778. }
  5779. }
  5780. }
  5781. }
  5782. }
  5783. }
  5784. //状态控制
  5785. if status != "" && status != "全部" && status != utils.COMPANY_STATUS_LOSE {
  5786. condition += ` AND b.status=? `
  5787. pars = append(pars, status)
  5788. }
  5789. dir, err := os.Executable()
  5790. exPath := filepath.Dir(dir)
  5791. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  5792. xlsxFile := xlsx.NewFile()
  5793. if err != nil {
  5794. br.Msg = "生成文件失败"
  5795. br.ErrMsg = "生成文件失败"
  5796. return
  5797. }
  5798. style := xlsx.NewStyle()
  5799. alignment := xlsx.Alignment{
  5800. Horizontal: "center",
  5801. Vertical: "center",
  5802. WrapText: true,
  5803. }
  5804. style.Alignment = alignment
  5805. style.ApplyAlignment = true
  5806. sheel, err := xlsxFile.AddSheet("客户数据")
  5807. if err != nil {
  5808. br.Msg = "新增Sheet失败"
  5809. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  5810. return
  5811. }
  5812. titleArr := []string{"客户名称", "客户地址", "客户类型", "所属行业", "所属销售", "客户状态", "服务期限", "到期天数", "创建时间", "权限详情"}
  5813. titleLen := len(titleArr)
  5814. titleRow := sheel.AddRow()
  5815. remarkRow := sheel.AddRow() // 备注行
  5816. // 填充空白至Z列
  5817. emptyColNum := 0
  5818. for i := 0; i < 26; i++ {
  5819. remarkRow.AddCell().SetValue("")
  5820. if i >= titleLen {
  5821. emptyColNum += 1
  5822. titleRow.AddCell().SetValue("")
  5823. continue
  5824. }
  5825. titleRow.AddCell().SetValue(titleArr[i])
  5826. }
  5827. // AA列开始为品种权限
  5828. ficcPermissions := make([]int, 0) // 用于后续判断试用暂停客户是否需要暂停这部分权限
  5829. raiPermissions := make([]int, 0)
  5830. permissions, e := models.GetChartPermissionList()
  5831. if e != nil {
  5832. br.Msg = "获取失败"
  5833. br.ErrMsg = "获取品种数据失败,Err:" + err.Error()
  5834. return
  5835. }
  5836. raiArr := []string{"医药", "消费", "科技", "智造"}
  5837. for _, p := range permissions {
  5838. if p.ProductId == 1 {
  5839. ficcPermissions = append(ficcPermissions, p.ChartPermissionId)
  5840. }
  5841. if p.ProductId == 2 {
  5842. raiPermissions = append(raiPermissions, p.ChartPermissionId)
  5843. }
  5844. if utils.InArrayByStr(raiArr, p.PermissionName) {
  5845. titleRow.AddCell().SetValue(p.Remark)
  5846. continue
  5847. }
  5848. titleRow.AddCell().SetValue(p.PermissionName)
  5849. }
  5850. // 第二行, 在品种权限开始列加一行标红备注
  5851. styleRed := xlsx.NewStyle()
  5852. styleRed.Font.Color = "ff0000"
  5853. remarkCell := remarkRow.AddCell()
  5854. remarkCell.SetStyle(styleRed)
  5855. remarkCell.SetString(`第一位数字表示是否已购买该品种,1表示已购,0表示未购;第二位数字表示是否有阅读权限,1表示有权限,0表示没有`)
  5856. list, err := company.GetCompanyListExport(condition, pars)
  5857. if err != nil {
  5858. br.Msg = "获取失败"
  5859. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  5860. return
  5861. }
  5862. companyIds := make([]int, 0)
  5863. for _, c := range list {
  5864. companyIds = append(companyIds, c.CompanyId)
  5865. }
  5866. // 获取客户对应的阅读和合同权限集合
  5867. contractPermissionMap := make(map[int][]int)
  5868. contractPermissions, e := company.GetContractPermissionIdsByCompanyIds(companyIds)
  5869. if e != nil {
  5870. br.Msg = "获取失败"
  5871. br.ErrMsg = "获取已购权限失败, Err: " + e.Error()
  5872. return
  5873. }
  5874. for _, p := range contractPermissions {
  5875. ids := make([]int, 0)
  5876. if p.ChartPermissionIds != "" {
  5877. idArr := strings.Split(p.ChartPermissionIds, ",")
  5878. for _, i := range idArr {
  5879. id, _ := strconv.Atoi(i)
  5880. ids = append(ids, id)
  5881. }
  5882. }
  5883. contractPermissionMap[p.CompanyId] = ids
  5884. }
  5885. reportPermissionMap := make(map[int][]int)
  5886. reportPermissions, e := company.GetReportPermissionIdsByCompanyIds(companyIds)
  5887. if e != nil {
  5888. br.Msg = "获取失败"
  5889. br.ErrMsg = "获取阅读权限失败, Err: " + e.Error()
  5890. return
  5891. }
  5892. for _, p := range reportPermissions {
  5893. ids := make([]int, 0)
  5894. if p.ChartPermissionIds != "" {
  5895. idArr := strings.Split(p.ChartPermissionIds, ",")
  5896. for _, i := range idArr {
  5897. id, _ := strconv.Atoi(i)
  5898. ids = append(ids, id)
  5899. }
  5900. }
  5901. reportPermissionMap[p.CompanyId] = ids
  5902. }
  5903. cpMap := make(map[int][]*company.ExportCompanyProduct)
  5904. permissionMap := make(map[string]string)
  5905. for _, v := range list {
  5906. cpList := make([]*company.ExportCompanyProduct, 1)
  5907. if cps, ok := cpMap[v.CompanyId]; ok {
  5908. cpList = cps
  5909. } else {
  5910. companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  5911. if err != nil {
  5912. br.Msg = "导出失败"
  5913. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  5914. return
  5915. }
  5916. cpMap[v.CompanyId] = companyProduct
  5917. cpList = companyProduct
  5918. }
  5919. var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, expireDay string
  5920. isFiccSuspend := 0
  5921. isRaiSuspend := 0
  5922. for ck, cv := range cpList {
  5923. companyName = cv.CompanyName
  5924. if ck >= 1 {
  5925. companyType = companyType + "/" + cv.ProductName
  5926. status = status + "/" + cv.Status
  5927. } else {
  5928. companyType = cv.ProductName
  5929. status = cv.Status
  5930. }
  5931. if cv.ProductId == 1 {
  5932. industryName = "ficc:" + cv.IndustryName
  5933. sellerName = "ficc:" + cv.SellerName
  5934. startDateStr := cv.StartDate.Format("2006/01/02")
  5935. endDateStr := cv.EndDate.Format("2006/01/02")
  5936. timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  5937. createTime = "ficc:" + cv.CreateTime
  5938. source = "ficc:" + cv.Source
  5939. sub := cv.EndDate.Sub(time.Now())
  5940. if sub < 0 {
  5941. sub = 0
  5942. }
  5943. expireDay = "ficc:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  5944. permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  5945. permissionStr = "ficc:"
  5946. if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  5947. permissionStr += newPermissionStr
  5948. } else {
  5949. getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  5950. if err != nil {
  5951. br.Msg = "导出失败"
  5952. br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  5953. return
  5954. }
  5955. permissionMap[permissionKey] = getPermissionStr
  5956. permissionStr += getPermissionStr
  5957. }
  5958. isFiccSuspend = cv.IsSuspend
  5959. } else {
  5960. industryName = industryName + "\n" + "权益:" + cv.IndustryName
  5961. sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  5962. startDateStr := cv.StartDate.Format("2006/01/02")
  5963. endDateStr := cv.EndDate.Format("2006/01/02")
  5964. timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  5965. createTime = createTime + "\n" + "权益:" + cv.CreateTime
  5966. source = source + "\n" + "权益:" + cv.Source
  5967. sub := cv.EndDate.Sub(time.Now())
  5968. if sub < 0 {
  5969. sub = 0
  5970. }
  5971. expireDay = "\n" + "权益:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  5972. permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  5973. if permissionStr != "" {
  5974. permissionStr = permissionStr + "\n" + "权益:"
  5975. } else {
  5976. permissionStr = "权益:"
  5977. }
  5978. if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  5979. permissionStr += newPermissionStr
  5980. } else {
  5981. getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  5982. if err != nil {
  5983. br.Msg = "导出失败"
  5984. br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  5985. return
  5986. }
  5987. permissionMap[permissionKey] = getPermissionStr
  5988. permissionStr += getPermissionStr
  5989. }
  5990. isRaiSuspend = cv.IsSuspend
  5991. }
  5992. }
  5993. dataRow := sheel.AddRow()
  5994. dataRow.SetHeight(20)
  5995. dataRow.AddCell().SetString(companyName)
  5996. dataRow.AddCell().SetString(v.Address)
  5997. dataRow.AddCell().SetString(companyType)
  5998. dataRow.AddCell().SetString(v.IndustryName)
  5999. dataRow.AddCell().SetString(v.SellerName)
  6000. dataRow.AddCell().SetString(v.Status)
  6001. dataRow.AddCell().SetString(timeLimt)
  6002. dataRow.AddCell().SetString(expireDay)
  6003. dataRow.AddCell().SetString(v.CreatedTime)
  6004. //dataRow.AddCell().SetString(v.Source)
  6005. dataRow.AddCell().SetString(permissionStr)
  6006. // 填充空白至Z列, AA列开始为权限
  6007. for i := 0; i < emptyColNum; i++ {
  6008. dataRow.AddCell().SetString("")
  6009. }
  6010. cpIds := contractPermissionMap[v.CompanyId]
  6011. rpIds := reportPermissionMap[v.CompanyId]
  6012. for _, p := range permissions {
  6013. // 数字含义:11-表示已购且有阅读权限, 01-表示未购买但有阅读权限
  6014. first := 0
  6015. if utils.InArrayByInt(cpIds, p.ChartPermissionId) {
  6016. first = 1
  6017. }
  6018. second := 0
  6019. if utils.InArrayByInt(rpIds, p.ChartPermissionId) {
  6020. second = 1
  6021. // 如果客户是试用暂停, 即使有这部分权限, 也标记为0
  6022. if isFiccSuspend == 1 && utils.InArrayByInt(ficcPermissions, p.ChartPermissionId) {
  6023. second = 0
  6024. }
  6025. if isRaiSuspend == 1 && utils.InArrayByInt(raiPermissions, p.ChartPermissionId) {
  6026. second = 0
  6027. }
  6028. }
  6029. dataRow.AddCell().SetString(fmt.Sprintf("%d%d", first, second))
  6030. }
  6031. }
  6032. err = xlsxFile.Save(downLoadnFilePath)
  6033. if err != nil {
  6034. br.Msg = "保存文件失败"
  6035. br.ErrMsg = "保存文件失败"
  6036. return
  6037. }
  6038. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  6039. downloadFileName := "客户列表_" + randStr + ".xlsx"
  6040. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  6041. defer func() {
  6042. os.Remove(downLoadnFilePath)
  6043. }()
  6044. br.Ret = 200
  6045. br.Success = true
  6046. br.Msg = "导出成功"
  6047. }
  6048. //func (this *CompanyController) ExportOld() {
  6049. // br := new(models.BaseResponse).Init()
  6050. // defer func() {
  6051. // this.Data["json"] = br
  6052. // this.ServeJSON()
  6053. // }()
  6054. // sysUser := this.SysUser
  6055. // if sysUser == nil {
  6056. // br.Msg = "请登录"
  6057. // br.ErrMsg = "请登录,SysUser Is Empty"
  6058. // br.Ret = 408
  6059. // return
  6060. // }
  6061. // roleTypeCode := sysUser.RoleTypeCode
  6062. //
  6063. // status := this.GetString("Status")
  6064. // companyType := this.GetString("CompanyType")
  6065. // industryId, _ := this.GetInt("IndustryId")
  6066. // adminId := this.GetString("AdminId")
  6067. //
  6068. // chartPermissionIds := this.GetString("ChartPermissionIds")
  6069. // startDate := this.GetString("StartDate")
  6070. // endDate := this.GetString("EndDate")
  6071. // createStartDate := this.GetString("CreateStartDate")
  6072. // createEndDate := this.GetString("CreateEndDate")
  6073. // keyWord := this.GetString("KeyWord")
  6074. // keyWord = strings.Trim(keyWord, " ")
  6075. //
  6076. // resp := new(company.CompanyListResp)
  6077. // statusItems := make([]*company.CompanyStatus, 0)
  6078. // var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}
  6079. //
  6080. // var condition string
  6081. // var pars []interface{}
  6082. //
  6083. // var lossCondition string
  6084. // var lossPars []interface{}
  6085. //
  6086. // var permissionCondition string
  6087. // var permissionPars []interface{}
  6088. //
  6089. // if status != "" && status != "全部" {
  6090. // condition += ` AND b.status=? `
  6091. // pars = append(pars, status)
  6092. //
  6093. // //permissionCondition += ` AND b.status=? `
  6094. // //permissionPars = append(permissionPars, status)
  6095. // }
  6096. // if companyType != "" {
  6097. // condition += ` AND b.product_name=? `
  6098. // pars = append(pars, companyType)
  6099. //
  6100. // lossCondition += ` AND b.product_name=? `
  6101. // lossPars = append(lossPars, companyType)
  6102. //
  6103. // permissionCondition += ` AND b.product_name=? `
  6104. // permissionPars = append(permissionPars, companyType)
  6105. // }
  6106. //
  6107. // if industryId > 0 {
  6108. // condition += ` AND b.industry_id=? `
  6109. // pars = append(pars, industryId)
  6110. //
  6111. // lossCondition += ` AND b.industry_id=? `
  6112. // lossPars = append(lossPars, industryId)
  6113. //
  6114. // permissionCondition += ` AND b.industry_id=? `
  6115. // permissionPars = append(permissionPars, industryId)
  6116. // }
  6117. //
  6118. // if adminId != "" {
  6119. // condition += ` AND b.seller_id IN (` + adminId + `) `
  6120. //
  6121. // lossCondition += ` AND b.seller_id IN (` + adminId + `) `
  6122. //
  6123. // permissionCondition += ` AND b.seller_id IN (` + adminId + `) `
  6124. // }
  6125. //
  6126. // if startDate != "" {
  6127. // condition += ` AND b.start_date>=? `
  6128. // pars = append(pars, startDate)
  6129. //
  6130. // lossCondition += ` AND b.start_date>=? `
  6131. // lossPars = append(lossPars, startDate)
  6132. //
  6133. // permissionCondition += ` AND b.start_date>=? `
  6134. // permissionPars = append(permissionPars, startDate)
  6135. // }
  6136. //
  6137. // if endDate != "" {
  6138. // condition += ` AND b.end_date<=? `
  6139. // pars = append(pars, endDate)
  6140. //
  6141. // lossCondition += ` AND b.end_date<=? `
  6142. // lossPars = append(lossPars, endDate)
  6143. //
  6144. // permissionCondition += ` AND b.end_date<=? `
  6145. // permissionPars = append(permissionPars, endDate)
  6146. // }
  6147. //
  6148. // if createStartDate != "" {
  6149. // condition += ` AND a.created_time>=? `
  6150. // pars = append(pars, createStartDate)
  6151. //
  6152. // lossCondition += ` AND a.created_time>=? `
  6153. // lossPars = append(lossPars, createStartDate)
  6154. //
  6155. // permissionCondition += ` AND a.created_time>=? `
  6156. // permissionPars = append(permissionPars, createStartDate)
  6157. // }
  6158. //
  6159. // if createEndDate != "" {
  6160. // condition += ` AND a.created_time<=? `
  6161. // pars = append(pars, createEndDate)
  6162. //
  6163. // lossCondition += ` AND a.created_time<=? `
  6164. // lossPars = append(lossPars, createEndDate)
  6165. //
  6166. // permissionCondition += ` AND a.created_time<=? `
  6167. // permissionPars = append(permissionPars, createEndDate)
  6168. // }
  6169. //
  6170. // if keyWord != "" {
  6171. // companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
  6172. // if err != nil {
  6173. // return
  6174. // }
  6175. // if companyIdStr != "" {
  6176. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  6177. // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  6178. //
  6179. // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  6180. // } else {
  6181. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  6182. // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  6183. //
  6184. // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  6185. // }
  6186. // }
  6187. //
  6188. // if chartPermissionIds != "" && chartPermissionIds != "1" {
  6189. // //chartPermissionArr := strings.Split(chartPermissionIds, ",")
  6190. // //chartPermissionCount := len(chartPermissionArr)
  6191. // companyIdStr, err := company.GetCompanyListCompanyIdByPermissionIdStr(chartPermissionIds)
  6192. // if err != nil {
  6193. // br.Msg = "获取失败"
  6194. // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
  6195. // return
  6196. // }
  6197. // //var companyIdArr []string
  6198. // //for _, v := range companyIdList {
  6199. // // companyIdArr = append(companyIdArr, strconv.Itoa(v.CompanyId))
  6200. // //}
  6201. // //companyIdStr := strings.Join(companyIdArr, ",")
  6202. //
  6203. // if companyIdStr != "" {
  6204. // condition += ` AND a.company_id IN (` + companyIdStr + `) `
  6205. // lossCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  6206. // permissionCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  6207. // } else {
  6208. // for _, v := range statusArr {
  6209. // statusCount := new(company.CompanyStatus)
  6210. // if v == "全部" {
  6211. // statusCount.Status = "全部"
  6212. // statusCount.Count = 0
  6213. // } else {
  6214. // statusCount.Status = v
  6215. // statusCount.Count = 0
  6216. // }
  6217. // statusItems = append(statusItems, statusCount)
  6218. // }
  6219. // items := make([]*company.CompanyListItem, 0)
  6220. // resp.List = items
  6221. // resp.StatusCount = statusItems
  6222. // br.Msg = "获取成功"
  6223. // br.Ret = 200
  6224. // br.Data = resp
  6225. // return
  6226. // }
  6227. // }
  6228. //
  6229. // //权限控制
  6230. // {
  6231. // if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  6232. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  6233. // condition += ` AND b.product_id=? `
  6234. // pars = append(pars, 1)
  6235. //
  6236. // permissionCondition += ` AND b.product_id=? `
  6237. // permissionPars = append(permissionPars, 1)
  6238. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  6239. // condition += ` AND b.product_id=? `
  6240. // pars = append(pars, 2)
  6241. //
  6242. // permissionCondition += ` AND b.product_id=? `
  6243. // permissionPars = append(permissionPars, 2)
  6244. // } else {
  6245. // if sysUser.Authority <= 0 {
  6246. // if status != utils.COMPANY_STATUS_LOSE {
  6247. // condition += ` AND b.seller_id=? `
  6248. // pars = append(pars, sysUser.AdminId)
  6249. // }
  6250. //
  6251. // permissionCondition += ` AND b.seller_id=? `
  6252. // permissionPars = append(permissionPars, sysUser.AdminId)
  6253. // } else {
  6254. // if sysUser.Authority == 1 {
  6255. // if status != utils.COMPANY_STATUS_LOSE {
  6256. // condition += ` AND b.department_id=? `
  6257. // pars = append(pars, sysUser.DepartmentId)
  6258. // }
  6259. // permissionCondition += ` AND b.department_id=? `
  6260. // permissionPars = append(permissionPars, sysUser.DepartmentId)
  6261. // }
  6262. //
  6263. // if sysUser.Authority == 2 {
  6264. // if status != utils.COMPANY_STATUS_LOSE {
  6265. // condition += ` AND b.group_id=? `
  6266. // pars = append(pars, sysUser.GroupId)
  6267. // }
  6268. // permissionCondition += ` AND b.group_id=? `
  6269. // permissionPars = append(permissionPars, sysUser.GroupId)
  6270. // }
  6271. // }
  6272. // }
  6273. // }
  6274. // }
  6275. //
  6276. // dir, err := os.Executable()
  6277. // exPath := filepath.Dir(dir)
  6278. // downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  6279. // xlsxFile := xlsx.NewFile()
  6280. // if err != nil {
  6281. // br.Msg = "生成文件失败"
  6282. // br.ErrMsg = "生成文件失败"
  6283. // return
  6284. // }
  6285. // style := xlsx.NewStyle()
  6286. // alignment := xlsx.Alignment{
  6287. // Horizontal: "center",
  6288. // Vertical: "center",
  6289. // WrapText: true,
  6290. // }
  6291. //
  6292. // style.Alignment = alignment
  6293. // style.ApplyAlignment = true
  6294. //
  6295. // sheel, err := xlsxFile.AddSheet("客户数据")
  6296. // if err != nil {
  6297. // br.Msg = "新增Sheet失败"
  6298. // br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  6299. // return
  6300. // }
  6301. // titleRow := sheel.AddRow()
  6302. // titleRow.AddCell().SetValue("客户名称")
  6303. // titleRow.AddCell().SetValue("客户类型")
  6304. // titleRow.AddCell().SetValue("所属行业")
  6305. // titleRow.AddCell().SetValue("所属销售")
  6306. // titleRow.AddCell().SetValue("客户状态")
  6307. // titleRow.AddCell().SetValue("服务期限")
  6308. // titleRow.AddCell().SetValue("到期天数")
  6309. // titleRow.AddCell().SetValue("创建时间")
  6310. // titleRow.AddCell().SetValue("客户来源")
  6311. // titleRow.AddCell().SetValue("阅读权限")
  6312. //
  6313. // list, err := company.GetCompanyListExport(condition, pars)
  6314. // if err != nil {
  6315. // br.Msg = "获取失败"
  6316. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  6317. // return
  6318. // }
  6319. // cpMap := make(map[int][]*company.ExportCompanyProduct)
  6320. // permissionMap := make(map[string]string)
  6321. // for _, v := range list {
  6322. // cpList := make([]*company.ExportCompanyProduct, 1)
  6323. // if cps, ok := cpMap[v.CompanyId]; ok {
  6324. // cpList = cps
  6325. // } else {
  6326. // companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  6327. // if err != nil {
  6328. // br.Msg = "导出失败"
  6329. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  6330. // return
  6331. // }
  6332. // cpMap[v.CompanyId] = companyProduct
  6333. // cpList = companyProduct
  6334. // }
  6335. // var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, expireDay string
  6336. //
  6337. // for ck, cv := range cpList {
  6338. // companyName = cv.CompanyName
  6339. // if ck >= 1 {
  6340. // companyType = companyType + "/" + cv.ProductName
  6341. // status = status + "/" + cv.Status
  6342. // } else {
  6343. // companyType = cv.ProductName
  6344. // status = cv.Status
  6345. // }
  6346. // if cv.ProductId == 1 {
  6347. // industryName = "ficc:" + cv.IndustryName
  6348. // sellerName = "ficc:" + cv.SellerName
  6349. // startDateStr := cv.StartDate.Format("2006/01/02")
  6350. // endDateStr := cv.EndDate.Format("2006/01/02")
  6351. // timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  6352. // createTime = "ficc:" + cv.CreateTime
  6353. // source = "ficc:" + cv.Source
  6354. // sub := cv.EndDate.Sub(time.Now())
  6355. // if sub < 0 {
  6356. // sub = 0
  6357. // }
  6358. // expireDay = "ficc:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  6359. //
  6360. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6361. //
  6362. // permissionStr = "ficc:"
  6363. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6364. // permissionStr += newPermissionStr
  6365. // } else {
  6366. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6367. // if err != nil {
  6368. // br.Msg = "导出失败"
  6369. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6370. // return
  6371. // }
  6372. // permissionMap[permissionKey] = getPermissionStr
  6373. // permissionStr += getPermissionStr
  6374. // }
  6375. // } else {
  6376. // industryName = industryName + "\n" + "权益:" + cv.IndustryName
  6377. // sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  6378. // startDateStr := cv.StartDate.Format("2006/01/02")
  6379. // endDateStr := cv.EndDate.Format("2006/01/02")
  6380. //
  6381. // timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  6382. // createTime = createTime + "\n" + "权益:" + cv.CreateTime
  6383. // source = source + "\n" + "权益:" + cv.Source
  6384. //
  6385. // sub := cv.EndDate.Sub(time.Now())
  6386. // if sub < 0 {
  6387. // sub = 0
  6388. // }
  6389. // expireDay = "\n" + "权益:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  6390. //
  6391. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6392. // if permissionStr != "" {
  6393. // permissionStr = permissionStr + "\n" + "权益:"
  6394. // } else {
  6395. // permissionStr = "权益:"
  6396. // }
  6397. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6398. // permissionStr += newPermissionStr
  6399. // } else {
  6400. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6401. // if err != nil {
  6402. // br.Msg = "导出失败"
  6403. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6404. // return
  6405. // }
  6406. // permissionMap[permissionKey] = getPermissionStr
  6407. // permissionStr += getPermissionStr
  6408. // }
  6409. // }
  6410. // }
  6411. //
  6412. // dataRow := sheel.AddRow()
  6413. // dataRow.SetHeight(20)
  6414. // dataRow.AddCell().SetString(companyName)
  6415. // dataRow.AddCell().SetString(companyType)
  6416. // dataRow.AddCell().SetString(v.IndustryName)
  6417. // dataRow.AddCell().SetString(v.SellerName)
  6418. // dataRow.AddCell().SetString(v.Status)
  6419. // dataRow.AddCell().SetString(timeLimt)
  6420. // dataRow.AddCell().SetString(expireDay)
  6421. // dataRow.AddCell().SetString(v.CreatedTime)
  6422. // dataRow.AddCell().SetString(v.Source)
  6423. // dataRow.AddCell().SetString(permissionStr)
  6424. // }
  6425. // err = xlsxFile.Save(downLoadnFilePath)
  6426. // if err != nil {
  6427. // br.Msg = "保存文件失败"
  6428. // br.ErrMsg = "保存文件失败"
  6429. // return
  6430. // }
  6431. // randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  6432. // downloadFileName := "客户列表_" + randStr + ".xlsx"
  6433. // this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  6434. // defer func() {
  6435. // os.Remove(downLoadnFilePath)
  6436. // }()
  6437. // br.Ret = 200
  6438. // br.Success = true
  6439. // br.Msg = "导出成功"
  6440. //}
  6441. // @Title 导出
  6442. // @Description 导出接口
  6443. // @Param Status query string true "状态:”试用','永续','冻结','流失','正式'"
  6444. // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
  6445. // @Param IndustryId query int true "行业id,0为全部"
  6446. // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
  6447. // @Param ChartPermissionIds query string false "阅读权限品种ID,多个用英文逗号分开,空字符串为全部"
  6448. // @Param ContractPermissionIds query string false "已购品种ID,多个用英文逗号分开,空字符串为全部"
  6449. // @Param StartDate query string true "开始时间"
  6450. // @Param EndDate query string true "结束时间"
  6451. // @Param KeyWord query string true "搜索关键词"
  6452. // @Param Address query string true "地址 , 多个用英文逗号分开 "
  6453. // @Param Province query string true "省 , 多个用英文逗号分开 "
  6454. // @Param City query string true "市 , 多个用英文逗号分开 "
  6455. // @Param PackageType query int true "套餐类型,0:无,1:大套餐,2:小套餐"
  6456. // @Success Ret=200 移动成功
  6457. // @router /user/export [get]
  6458. func (this *CompanyController) CompanyUserExport() {
  6459. br := new(models.BaseResponse).Init()
  6460. defer func() {
  6461. this.Data["json"] = br
  6462. this.ServeJSON()
  6463. }()
  6464. sysUser := this.SysUser
  6465. if sysUser == nil {
  6466. br.Msg = "请登录"
  6467. br.ErrMsg = "请登录,SysUser Is Empty"
  6468. br.Ret = 408
  6469. return
  6470. }
  6471. roleTypeCode := sysUser.RoleTypeCode
  6472. status := this.GetString("Status")
  6473. companyType := this.GetString("CompanyType")
  6474. industryId, _ := this.GetInt("IndustryId")
  6475. adminId := this.GetString("AdminId")
  6476. chartPermissionIds := this.GetString("ChartPermissionIds")
  6477. contractPermissionIds := this.GetString("ContractPermissionIds")
  6478. startDate := this.GetString("StartDate")
  6479. endDate := this.GetString("EndDate")
  6480. createStartDate := this.GetString("CreateStartDate")
  6481. createEndDate := this.GetString("CreateEndDate")
  6482. keyWord := this.GetString("KeyWord")
  6483. address := this.GetString("Address")
  6484. province := this.GetString("Province")
  6485. city := this.GetString("City")
  6486. // 套餐类型
  6487. packageType, _ := this.GetInt("PackageType")
  6488. var condition string
  6489. var pars []interface{}
  6490. if status != "" && status != "全部" {
  6491. condition += ` AND b.status=? `
  6492. pars = append(pars, status)
  6493. }
  6494. if companyType != "" {
  6495. condition += ` AND b.product_name=? `
  6496. pars = append(pars, companyType)
  6497. }
  6498. if industryId > 0 {
  6499. condition += ` AND b.industry_id=? `
  6500. pars = append(pars, industryId)
  6501. }
  6502. if adminId != "" {
  6503. condition += ` AND b.seller_id IN (` + adminId + `) `
  6504. }
  6505. if startDate != "" {
  6506. condition += ` AND b.start_date>=? `
  6507. pars = append(pars, startDate)
  6508. }
  6509. if endDate != "" {
  6510. condition += ` AND b.end_date<=? `
  6511. pars = append(pars, endDate)
  6512. }
  6513. if createStartDate != "" {
  6514. condition += ` AND a.created_time>=? `
  6515. pars = append(pars, createStartDate)
  6516. }
  6517. if createEndDate != "" {
  6518. condition += ` AND a.created_time<=? `
  6519. pars = append(pars, createEndDate)
  6520. }
  6521. if keyWord != "" {
  6522. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR c.mobile LIKE '%` + keyWord + `%' OR c.email LIKE '%` + keyWord + `%') `
  6523. }
  6524. // 阅读权限/已购品种筛选
  6525. cond, emp, e := services.FilterReadAndContractAuth(chartPermissionIds, contractPermissionIds, condition)
  6526. if e != nil {
  6527. br.Msg = "获取失败"
  6528. br.ErrMsg = "FilterReadAndContractAuth err: " + e.Error()
  6529. return
  6530. }
  6531. if emp {
  6532. condition += ` AND 1 = 2`
  6533. } else {
  6534. condition = cond
  6535. }
  6536. if address != "" {
  6537. var addressSql string
  6538. slice := strings.Split(address, ",")
  6539. for _, v := range slice {
  6540. addressSql += "'" + v + "'" + ","
  6541. }
  6542. addressSql = strings.TrimRight(addressSql, ",")
  6543. condition += ` AND a.address IN (` + addressSql + `) `
  6544. }
  6545. if province != "" {
  6546. var provinceSql string
  6547. slice := strings.Split(province, ",")
  6548. for _, v := range slice {
  6549. provinceSql += "'" + v + "'" + ","
  6550. }
  6551. provinceSql = strings.TrimRight(provinceSql, ",")
  6552. condition += ` AND a.province IN (` + provinceSql + `) `
  6553. }
  6554. if city != "" {
  6555. var citySql string
  6556. slice := strings.Split(city, ",")
  6557. for _, v := range slice {
  6558. citySql += "'" + v + "'" + ","
  6559. }
  6560. citySql = strings.TrimRight(citySql, ",")
  6561. condition += ` AND a.city IN (` + citySql + `) `
  6562. }
  6563. //套餐类型
  6564. if packageType > 0 {
  6565. condition += ` AND b.package_type=? `
  6566. pars = append(pars, packageType)
  6567. }
  6568. //权限控制
  6569. {
  6570. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  6571. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  6572. if status != utils.COMPANY_STATUS_LOSE && status != utils.COMPANY_STATUS_FOREVER {
  6573. condition += ` AND b.seller_id=? `
  6574. pars = append(pars, sysUser.AdminId)
  6575. }
  6576. }
  6577. if sysUser.Authority == 1 {
  6578. condition += ` AND b.department_id=? `
  6579. pars = append(pars, sysUser.DepartmentId)
  6580. }
  6581. if sysUser.Authority == 2 {
  6582. condition += ` AND b.group_id=? `
  6583. pars = append(pars, sysUser.GroupId)
  6584. }
  6585. }
  6586. var statusCond string
  6587. var statusPars []interface{}
  6588. // 根据当前用户角色
  6589. productId := services.GetProductId(roleTypeCode)
  6590. if productId > 0 {
  6591. condition += ` AND b.product_id = ? `
  6592. pars = append(pars, productId)
  6593. statusCond += ` AND b.product_id = ? `
  6594. statusPars = append(statusPars, productId)
  6595. }
  6596. companyIds, err := company.GetExportCompanyIds(condition, pars)
  6597. if err != nil {
  6598. br.Msg = "导出失败"
  6599. br.ErrMsg = "导出失败,Err:" + err.Error()
  6600. return
  6601. }
  6602. dir, err := os.Executable()
  6603. exPath := filepath.Dir(dir)
  6604. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  6605. xlsxFile := xlsx.NewFile()
  6606. if err != nil {
  6607. br.Msg = "生成文件失败"
  6608. br.ErrMsg = "生成文件失败"
  6609. return
  6610. }
  6611. style := xlsx.NewStyle()
  6612. alignment := xlsx.Alignment{
  6613. Horizontal: "center",
  6614. Vertical: "center",
  6615. WrapText: true,
  6616. }
  6617. style.Alignment = alignment
  6618. style.ApplyAlignment = true
  6619. sheel, err := xlsxFile.AddSheet("联系人数据")
  6620. if err != nil {
  6621. br.Msg = "新增Sheet失败"
  6622. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  6623. return
  6624. }
  6625. sheel.SetColWidth(7, 7, 10)
  6626. sheel.SetColWidth(8, 10, 16)
  6627. sheel.SetColWidth(9, 11, 20)
  6628. sheel.SetColWidth(12, 12, 35)
  6629. sheel.SetColWidth(13, 13, 15)
  6630. sheel.SetColWidth(14, 14, 80)
  6631. titleRow := sheel.AddRow()
  6632. titleRow.AddCell().SetValue("联系人")
  6633. titleRow.AddCell().SetValue("是否关注公众号")
  6634. titleRow.AddCell().SetValue("手机号")
  6635. titleRow.AddCell().SetValue("邮箱")
  6636. //titleRow.AddCell().SetValue("职位")
  6637. titleRow.AddCell().SetValue("是否决策人")
  6638. //titleRow.AddCell().SetValue("客户部门")
  6639. titleRow.AddCell().SetValue("客户名称")
  6640. titleRow.AddCell().SetValue("客户状态")
  6641. //titleRow.AddCell().SetValue("社会信用码")
  6642. //titleRow.AddCell().SetValue("所属区域")
  6643. //titleRow.AddCell().SetValue("客户类型")
  6644. //industryCell := titleRow.AddCell()
  6645. //industryCell.SetStyle(style)
  6646. //industryCell.Value = "所属行业"
  6647. //
  6648. //sellerCell := titleRow.AddCell()
  6649. //sellerCell.SetStyle(style)
  6650. //sellerCell.Value = "所属销售"
  6651. //
  6652. //statusCell := titleRow.AddCell()
  6653. //statusCell.SetStyle(style)
  6654. //statusCell.Value = "客户状态"
  6655. //
  6656. //timeLimtCell := titleRow.AddCell()
  6657. //timeLimtCell.SetStyle(style)
  6658. //timeLimtCell.Value = "服务期限"
  6659. //
  6660. //createTimeCell := titleRow.AddCell()
  6661. //createTimeCell.SetStyle(style)
  6662. //createTimeCell.Value = "创建时间"
  6663. //
  6664. //sourceCell := titleRow.AddCell()
  6665. //sourceCell.SetStyle(style)
  6666. //sourceCell.Value = "客户来源"
  6667. //permissionStyle := xlsx.NewStyle()
  6668. //permissionAlignment := xlsx.Alignment{
  6669. // Horizontal: "center",
  6670. // Vertical: "center",
  6671. // WrapText: true,
  6672. //}
  6673. //
  6674. //permissionStyle.Alignment = permissionAlignment
  6675. //permissionStyle.ApplyAlignment = true
  6676. //permissionCell := titleRow.AddCell()
  6677. //permissionCell.SetStyle(permissionStyle)
  6678. //permissionCell.Value = "阅读权限"
  6679. users := make([]*company.ExportUser, 0)
  6680. if companyIds != "" {
  6681. companyIds = strings.Trim(companyIds, ",")
  6682. if productId > 0 {
  6683. users, err = company.GetExportUserByProductId(companyIds, productId)
  6684. if err != nil {
  6685. br.Msg = "导出失败"
  6686. br.ErrMsg = "获取联系人信息失败,Err:" + err.Error()
  6687. return
  6688. }
  6689. } else {
  6690. users, err = company.GetExportUser(companyIds)
  6691. if err != nil {
  6692. br.Msg = "导出失败"
  6693. br.ErrMsg = "获取联系人信息失败,Err:" + err.Error()
  6694. return
  6695. }
  6696. }
  6697. // 获取客户状态
  6698. companyIntIds := make([]int, 0)
  6699. companyIdArr := strings.Split(companyIds, ",")
  6700. for _, c := range companyIdArr {
  6701. id, e := strconv.Atoi(c)
  6702. if e != nil {
  6703. br.Msg = "导出失败"
  6704. br.ErrMsg = "客户ID有误"
  6705. return
  6706. }
  6707. companyIntIds = append(companyIntIds, id)
  6708. }
  6709. if len(companyIntIds) > 0 {
  6710. statusCond += fmt.Sprintf(` AND a.company_id IN (%s) `, utils.GetOrmInReplace(len(companyIntIds)))
  6711. statusPars = append(statusPars, companyIntIds)
  6712. }
  6713. statusMap := make(map[int]string)
  6714. nameMap := make(map[int]string)
  6715. companyStatusList, e := company.GetExportUserCompanyStatus(statusCond, statusPars)
  6716. if e != nil {
  6717. br.Msg = "导出失败"
  6718. br.ErrMsg = "获取客户状态失败, Err: " + e.Error()
  6719. return
  6720. }
  6721. for _, s := range companyStatusList {
  6722. statusMap[s.CompanyId] = s.CompanyStatus
  6723. nameMap[s.CompanyId] = s.CompanyName
  6724. }
  6725. //cpMap := make(map[int][]*company.ExportCompanyProduct)
  6726. //permissionMap := make(map[string]string)
  6727. for _, v := range users {
  6728. dataRow := sheel.AddRow()
  6729. dataRow.SetHeight(20)
  6730. dataRow.AddCell().SetString(v.RealName)
  6731. if v.IsSubscribe == 1 {
  6732. dataRow.AddCell().SetString("是") // 是否关注公众号
  6733. } else {
  6734. dataRow.AddCell().SetString("")
  6735. }
  6736. dataRow.AddCell().SetString(v.Mobile)
  6737. dataRow.AddCell().SetString(v.Email)
  6738. //dataRow.AddCell().SetString(v.Position)
  6739. if v.IsMaker == 1 {
  6740. dataRow.AddCell().SetString("是")
  6741. } else {
  6742. dataRow.AddCell().SetString("否")
  6743. }
  6744. //dataRow.AddCell().SetString(v.DepartmentName)
  6745. //cpList := make([]*company.ExportCompanyProduct, 1)
  6746. //if cps, ok := cpMap[v.CompanyId]; ok {
  6747. // cpList = cps
  6748. //} else {
  6749. // companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  6750. // if err != nil {
  6751. // br.Msg = "导出失败"
  6752. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  6753. // return
  6754. // }
  6755. // cpMap[v.CompanyId] = companyProduct
  6756. // cpList = companyProduct
  6757. //}
  6758. //productList, err := company.GetExportCompanyProduct(v.CompanyId)
  6759. //if err!=nil {
  6760. // fmt.Println("导出失败,Err:"+err.Error())
  6761. // return
  6762. //}
  6763. //var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, creditCode, regionType string
  6764. //for ck, cv := range cpList {
  6765. // companyName = cv.CompanyName
  6766. // creditCode = cv.CreditCode
  6767. // regionType = cv.RegionType
  6768. // if ck >= 1 {
  6769. // companyType = companyType + "/" + cv.ProductName
  6770. // status = status + "/" + cv.Status
  6771. // } else {
  6772. // companyType = cv.ProductName
  6773. // status = cv.Status
  6774. // }
  6775. // if cv.ProductId == 1 {
  6776. // industryName = "ficc:" + cv.IndustryName
  6777. // sellerName = "ficc:" + cv.SellerName
  6778. // startDateStr := cv.StartDate.Format("2006/01/02")
  6779. // endDateStr := cv.EndDate.Format("2006/01/02")
  6780. // if startDateStr != "0001/01/01" {
  6781. // timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  6782. // } else {
  6783. // timeLimt = ""
  6784. // }
  6785. // createTime = "ficc:" + cv.CreateTime
  6786. // source = "ficc:" + cv.Source
  6787. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6788. //
  6789. // permissionStr = "ficc:"
  6790. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6791. // permissionStr += newPermissionStr
  6792. // } else {
  6793. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6794. // if err != nil {
  6795. // br.Msg = "导出失败"
  6796. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6797. // return
  6798. // }
  6799. // permissionMap[permissionKey] = getPermissionStr
  6800. // permissionStr += getPermissionStr
  6801. // }
  6802. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  6803. // permissionStr = ""
  6804. // }
  6805. // } else {
  6806. // industryName = industryName + "\n" + "权益:" + cv.IndustryName
  6807. // sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  6808. // startDateStr := cv.StartDate.Format("2006/01/02")
  6809. // endDateStr := cv.EndDate.Format("2006/01/02")
  6810. //
  6811. // if startDateStr != "0001/01/01" {
  6812. // timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  6813. // } else {
  6814. // timeLimt = timeLimt + ""
  6815. // }
  6816. // createTime = createTime + "\n" + "权益:" + cv.CreateTime
  6817. // source = source + "\n" + "权益:" + cv.Source
  6818. //
  6819. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6820. // if permissionStr != "" {
  6821. // permissionStr = permissionStr + "\n" + "权益:"
  6822. // } else {
  6823. // permissionStr = "权益:"
  6824. // }
  6825. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6826. // permissionStr += newPermissionStr
  6827. // } else {
  6828. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6829. // if err != nil {
  6830. // br.Msg = "导出失败"
  6831. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6832. // return
  6833. // }
  6834. // permissionMap[permissionKey] = getPermissionStr
  6835. // permissionStr += getPermissionStr
  6836. // }
  6837. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  6838. // permissionStr = permissionStr + ""
  6839. // }
  6840. // }
  6841. //}
  6842. // 2023-0420这是谁写的循环查,顺手优化了一下,手动狗头-_-~
  6843. //companyInfo, err := company.GetCompanyById(v.CompanyId)
  6844. //if err != nil {
  6845. // br.Msg = "导出失败"
  6846. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  6847. // return
  6848. //}
  6849. dataRow.AddCell().SetString(nameMap[v.CompanyId])
  6850. dataRow.AddCell().SetString(statusMap[v.CompanyId]) // 客户状态
  6851. //dataRow.AddCell().SetString(creditCode)
  6852. //dataRow.AddCell().SetString(regionType)
  6853. //
  6854. //dataRow.AddCell().SetString(companyType)
  6855. //industryValueCell := dataRow.AddCell()
  6856. //industryValueCell.SetStyle(style)
  6857. //industryValueCell.SetString(industryName)
  6858. //
  6859. //sellerValueCell := dataRow.AddCell()
  6860. //sellerValueCell.SetStyle(style)
  6861. //sellerValueCell.SetString(sellerName)
  6862. //
  6863. //statusValueCell := dataRow.AddCell()
  6864. //statusValueCell.SetStyle(style)
  6865. //statusValueCell.SetValue(status)
  6866. //
  6867. //timeLimitValueCell := dataRow.AddCell()
  6868. //timeLimitValueCell.SetStyle(style)
  6869. //timeLimitValueCell.SetValue(timeLimt)
  6870. //
  6871. //createTimeValueCell := dataRow.AddCell()
  6872. //createTimeValueCell.SetStyle(style)
  6873. //createTimeValueCell.SetValue(createTime)
  6874. //
  6875. //sourceValueCell := dataRow.AddCell()
  6876. //sourceValueCell.SetStyle(style)
  6877. //sourceValueCell.SetValue(source)
  6878. //
  6879. //permissionStrValueCell := dataRow.AddCell()
  6880. //permissionStrValueCell.SetStyle(style)
  6881. //permissionStrValueCell.SetValue(permissionStr)
  6882. }
  6883. }
  6884. err = xlsxFile.Save(downLoadnFilePath)
  6885. if err != nil {
  6886. br.Msg = "保存文件失败"
  6887. br.ErrMsg = "保存文件失败"
  6888. return
  6889. }
  6890. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  6891. downloadFileName := "联系人列表" + randStr + ".xlsx"
  6892. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  6893. defer func() {
  6894. os.Remove(downLoadnFilePath)
  6895. }()
  6896. br.Ret = 200
  6897. br.Success = true
  6898. br.Msg = "导出成功"
  6899. }
  6900. //func (this *CompanyController) CompanyUserExportOld() {
  6901. // br := new(models.BaseResponse).Init()
  6902. // defer func() {
  6903. // this.Data["json"] = br
  6904. // this.ServeJSON()
  6905. // }()
  6906. // sysUser := this.SysUser
  6907. // if sysUser == nil {
  6908. // br.Msg = "请登录"
  6909. // br.ErrMsg = "请登录,SysUser Is Empty"
  6910. // br.Ret = 408
  6911. // return
  6912. // }
  6913. // roleTypeCode := sysUser.RoleTypeCode
  6914. // status := this.GetString("Status")
  6915. // companyType := this.GetString("CompanyType")
  6916. // industryId, _ := this.GetInt("IndustryId")
  6917. // adminId := this.GetString("AdminId")
  6918. //
  6919. // chartPermissionIds := this.GetString("ChartPermissionIds")
  6920. // startDate := this.GetString("StartDate")
  6921. // endDate := this.GetString("EndDate")
  6922. // keyWord := this.GetString("KeyWord")
  6923. //
  6924. // var condition string
  6925. // var pars []interface{}
  6926. //
  6927. // if status != "" && status != "全部" {
  6928. // condition += ` AND b.status=? `
  6929. // pars = append(pars, status)
  6930. // }
  6931. // if companyType != "" {
  6932. // condition += ` AND b.product_name=? `
  6933. // pars = append(pars, companyType)
  6934. // }
  6935. //
  6936. // if industryId > 0 {
  6937. // condition += ` AND b.industry_id=? `
  6938. // pars = append(pars, industryId)
  6939. // }
  6940. //
  6941. // if adminId != "" {
  6942. // condition += ` AND b.seller_id IN (` + adminId + `) `
  6943. // }
  6944. //
  6945. // if startDate != "" {
  6946. // condition += ` AND b.start_date>=? `
  6947. // pars = append(pars, startDate)
  6948. // }
  6949. //
  6950. // if endDate != "" {
  6951. // condition += ` AND b.end_date>=? `
  6952. // pars = append(pars, endDate)
  6953. // }
  6954. //
  6955. // if keyWord != "" {
  6956. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR c.mobile LIKE '%` + keyWord + `%' OR c.email LIKE '%` + keyWord + `%') `
  6957. // }
  6958. //
  6959. // if chartPermissionIds != "" {
  6960. // companyIdStr, err := company.GetCompanyIdStr(chartPermissionIds)
  6961. // if err != nil {
  6962. // br.Msg = "获取失败"
  6963. // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
  6964. // return
  6965. // }
  6966. // if companyIdStr != "" {
  6967. // condition += ` AND a.company_id IN (` + companyIdStr + `) `
  6968. // }
  6969. // }
  6970. //
  6971. // //权限控制
  6972. // {
  6973. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  6974. // roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  6975. // if status != utils.COMPANY_STATUS_LOSE && status != utils.COMPANY_STATUS_FOREVER {
  6976. // condition += ` AND b.seller_id=? `
  6977. // pars = append(pars, sysUser.AdminId)
  6978. // }
  6979. // }
  6980. // if sysUser.Authority == 1 {
  6981. // condition += ` AND b.department_id=? `
  6982. // pars = append(pars, sysUser.DepartmentId)
  6983. // }
  6984. //
  6985. // if sysUser.Authority == 2 {
  6986. // condition += ` AND b.group_id=? `
  6987. // pars = append(pars, sysUser.GroupId)
  6988. // }
  6989. // }
  6990. // companyIds, err := company.GetExportCompanyIds(condition, pars)
  6991. // if err != nil {
  6992. // br.Msg = "导出失败"
  6993. // br.ErrMsg = "导出失败,Err:" + err.Error()
  6994. // return
  6995. // }
  6996. //
  6997. // dir, err := os.Executable()
  6998. // exPath := filepath.Dir(dir)
  6999. //
  7000. // downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  7001. // xlsxFile := xlsx.NewFile()
  7002. // if err != nil {
  7003. // br.Msg = "生成文件失败"
  7004. // br.ErrMsg = "生成文件失败"
  7005. // return
  7006. // }
  7007. // style := xlsx.NewStyle()
  7008. // alignment := xlsx.Alignment{
  7009. // Horizontal: "center",
  7010. // Vertical: "center",
  7011. // WrapText: true,
  7012. // }
  7013. //
  7014. // style.Alignment = alignment
  7015. // style.ApplyAlignment = true
  7016. //
  7017. // sheel, err := xlsxFile.AddSheet("联系人数据")
  7018. // if err != nil {
  7019. // br.Msg = "新增Sheet失败"
  7020. // br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  7021. // return
  7022. // }
  7023. //
  7024. // sheel.SetColWidth(7, 7, 10)
  7025. // sheel.SetColWidth(8, 10, 16)
  7026. // sheel.SetColWidth(9, 11, 20)
  7027. // sheel.SetColWidth(12, 12, 35)
  7028. // sheel.SetColWidth(13, 13, 15)
  7029. // sheel.SetColWidth(14, 14, 80)
  7030. // titleRow := sheel.AddRow()
  7031. // titleRow.AddCell().SetValue("联系人")
  7032. // titleRow.AddCell().SetValue("手机号")
  7033. // titleRow.AddCell().SetValue("邮箱")
  7034. // titleRow.AddCell().SetValue("职位")
  7035. // titleRow.AddCell().SetValue("是否决策人")
  7036. // titleRow.AddCell().SetValue("客户部门")
  7037. // titleRow.AddCell().SetValue("客户名称")
  7038. // titleRow.AddCell().SetValue("社会信用码")
  7039. // titleRow.AddCell().SetValue("所属区域")
  7040. // titleRow.AddCell().SetValue("客户类型")
  7041. //
  7042. // industryCell := titleRow.AddCell()
  7043. // industryCell.SetStyle(style)
  7044. // industryCell.Value = "所属行业"
  7045. //
  7046. // sellerCell := titleRow.AddCell()
  7047. // sellerCell.SetStyle(style)
  7048. // sellerCell.Value = "所属销售"
  7049. //
  7050. // statusCell := titleRow.AddCell()
  7051. // statusCell.SetStyle(style)
  7052. // statusCell.Value = "客户状态"
  7053. //
  7054. // timeLimtCell := titleRow.AddCell()
  7055. // timeLimtCell.SetStyle(style)
  7056. // timeLimtCell.Value = "服务期限"
  7057. //
  7058. // createTimeCell := titleRow.AddCell()
  7059. // createTimeCell.SetStyle(style)
  7060. // createTimeCell.Value = "创建时间"
  7061. //
  7062. // sourceCell := titleRow.AddCell()
  7063. // sourceCell.SetStyle(style)
  7064. // sourceCell.Value = "客户来源"
  7065. //
  7066. // permissionStyle := xlsx.NewStyle()
  7067. // permissionAlignment := xlsx.Alignment{
  7068. // Horizontal: "center",
  7069. // Vertical: "center",
  7070. // WrapText: true,
  7071. // }
  7072. //
  7073. // permissionStyle.Alignment = permissionAlignment
  7074. // permissionStyle.ApplyAlignment = true
  7075. //
  7076. // permissionCell := titleRow.AddCell()
  7077. // permissionCell.SetStyle(permissionStyle)
  7078. // permissionCell.Value = "阅读权限"
  7079. //
  7080. // if companyIds != "" {
  7081. // companyIds = strings.Trim(companyIds, ",")
  7082. // users, err := company.GetExportUser(companyIds)
  7083. // if err != nil {
  7084. // br.Msg = "导出失败"
  7085. // br.ErrMsg = "获取联系人信息失败,Err:" + err.Error()
  7086. // return
  7087. // }
  7088. // cpMap := make(map[int][]*company.ExportCompanyProduct)
  7089. // permissionMap := make(map[string]string)
  7090. // for _, v := range users {
  7091. // dataRow := sheel.AddRow()
  7092. // dataRow.SetHeight(20)
  7093. // dataRow.AddCell().SetString(v.RealName)
  7094. // dataRow.AddCell().SetString(v.Mobile)
  7095. // dataRow.AddCell().SetString(v.Email)
  7096. // dataRow.AddCell().SetString(v.Position)
  7097. // if v.IsMaker == 1 {
  7098. // dataRow.AddCell().SetString("是")
  7099. // } else {
  7100. // dataRow.AddCell().SetString("否")
  7101. // }
  7102. // dataRow.AddCell().SetString(v.DepartmentName)
  7103. // cpList := make([]*company.ExportCompanyProduct, 1)
  7104. // if cps, ok := cpMap[v.CompanyId]; ok {
  7105. // cpList = cps
  7106. // } else {
  7107. // companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  7108. // if err != nil {
  7109. // br.Msg = "导出失败"
  7110. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  7111. // return
  7112. // }
  7113. // cpMap[v.CompanyId] = companyProduct
  7114. // cpList = companyProduct
  7115. // }
  7116. // //productList, err := company.GetExportCompanyProduct(v.CompanyId)
  7117. // //if err!=nil {
  7118. // // fmt.Println("导出失败,Err:"+err.Error())
  7119. // // return
  7120. // //}
  7121. // var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, creditCode, regionType string
  7122. //
  7123. // for ck, cv := range cpList {
  7124. // companyName = cv.CompanyName
  7125. // creditCode = cv.CreditCode
  7126. // regionType = cv.RegionType
  7127. // if ck >= 1 {
  7128. // companyType = companyType + "/" + cv.ProductName
  7129. // status = status + "/" + cv.Status
  7130. // } else {
  7131. // companyType = cv.ProductName
  7132. // status = cv.Status
  7133. // }
  7134. // if cv.ProductId == 1 {
  7135. // industryName = "ficc:" + cv.IndustryName
  7136. // sellerName = "ficc:" + cv.SellerName
  7137. // startDateStr := cv.StartDate.Format("2006/01/02")
  7138. // endDateStr := cv.EndDate.Format("2006/01/02")
  7139. // if startDateStr != "0001/01/01" {
  7140. // timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  7141. // } else {
  7142. // timeLimt = ""
  7143. // }
  7144. // createTime = "ficc:" + cv.CreateTime
  7145. // source = "ficc:" + cv.Source
  7146. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  7147. //
  7148. // permissionStr = "ficc:"
  7149. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  7150. // permissionStr += newPermissionStr
  7151. // } else {
  7152. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  7153. // if err != nil {
  7154. // br.Msg = "导出失败"
  7155. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  7156. // return
  7157. // }
  7158. // permissionMap[permissionKey] = getPermissionStr
  7159. // permissionStr += getPermissionStr
  7160. // }
  7161. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  7162. // permissionStr = ""
  7163. // }
  7164. // } else {
  7165. // industryName = industryName + "\n" + "权益:" + cv.IndustryName
  7166. // sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  7167. // startDateStr := cv.StartDate.Format("2006/01/02")
  7168. // endDateStr := cv.EndDate.Format("2006/01/02")
  7169. //
  7170. // if startDateStr != "0001/01/01" {
  7171. // timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  7172. // } else {
  7173. // timeLimt = timeLimt + ""
  7174. // }
  7175. // createTime = createTime + "\n" + "权益:" + cv.CreateTime
  7176. // source = source + "\n" + "权益:" + cv.Source
  7177. //
  7178. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  7179. // if permissionStr != "" {
  7180. // permissionStr = permissionStr + "\n" + "权益:"
  7181. // } else {
  7182. // permissionStr = "权益:"
  7183. // }
  7184. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  7185. // permissionStr += newPermissionStr
  7186. // } else {
  7187. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  7188. // if err != nil {
  7189. // br.Msg = "导出失败"
  7190. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  7191. // return
  7192. // }
  7193. // permissionMap[permissionKey] = getPermissionStr
  7194. // permissionStr += getPermissionStr
  7195. // }
  7196. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  7197. // permissionStr = permissionStr + ""
  7198. // }
  7199. // }
  7200. // }
  7201. // dataRow.AddCell().SetString(companyName)
  7202. // dataRow.AddCell().SetString(creditCode)
  7203. // dataRow.AddCell().SetString(regionType)
  7204. //
  7205. // dataRow.AddCell().SetString(companyType)
  7206. // industryValueCell := dataRow.AddCell()
  7207. // industryValueCell.SetStyle(style)
  7208. // industryValueCell.SetString(industryName)
  7209. //
  7210. // sellerValueCell := dataRow.AddCell()
  7211. // sellerValueCell.SetStyle(style)
  7212. // sellerValueCell.SetString(sellerName)
  7213. //
  7214. // statusValueCell := dataRow.AddCell()
  7215. // statusValueCell.SetStyle(style)
  7216. // statusValueCell.SetValue(status)
  7217. //
  7218. // timeLimitValueCell := dataRow.AddCell()
  7219. // timeLimitValueCell.SetStyle(style)
  7220. // timeLimitValueCell.SetValue(timeLimt)
  7221. //
  7222. // createTimeValueCell := dataRow.AddCell()
  7223. // createTimeValueCell.SetStyle(style)
  7224. // createTimeValueCell.SetValue(createTime)
  7225. //
  7226. // sourceValueCell := dataRow.AddCell()
  7227. // sourceValueCell.SetStyle(style)
  7228. // sourceValueCell.SetValue(source)
  7229. //
  7230. // permissionStrValueCell := dataRow.AddCell()
  7231. // permissionStrValueCell.SetStyle(style)
  7232. // permissionStrValueCell.SetValue(permissionStr)
  7233. // }
  7234. // }
  7235. // err = xlsxFile.Save(downLoadnFilePath)
  7236. // if err != nil {
  7237. // br.Msg = "保存文件失败"
  7238. // br.ErrMsg = "保存文件失败"
  7239. // return
  7240. // }
  7241. // randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  7242. // downloadFileName := "联系人列表" + randStr + ".xlsx"
  7243. // this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  7244. // defer func() {
  7245. // os.Remove(downLoadnFilePath)
  7246. // }()
  7247. // br.Ret = 200
  7248. // br.Success = true
  7249. // br.Msg = "导出成功"
  7250. //}
  7251. // @Title 冻结客户
  7252. // @Description 冻结客户接口
  7253. // @Param request body company.CompanyFreezeReq true "type json string"
  7254. // @Success Ret=200 冻结成功
  7255. // @router /freeze [post]
  7256. func (this *CompanyController) Freeze() {
  7257. br := new(models.BaseResponse).Init()
  7258. defer func() {
  7259. this.Data["json"] = br
  7260. this.ServeJSON()
  7261. }()
  7262. sysUser := this.SysUser
  7263. if sysUser == nil {
  7264. br.Msg = "请登录"
  7265. br.ErrMsg = "请登录,SysUser Is Empty"
  7266. br.Ret = 408
  7267. return
  7268. }
  7269. var req company.CompanyFreezeReq
  7270. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  7271. if err != nil {
  7272. br.Msg = "参数解析异常!"
  7273. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  7274. return
  7275. }
  7276. if req.CompanyId <= 0 {
  7277. br.Msg = "参数错误!"
  7278. br.ErrMsg = "客户id小于等于0"
  7279. return
  7280. }
  7281. productId := 0
  7282. productName := ""
  7283. if req.CompanyType == utils.COMPANY_CLASSIFY_FICC {
  7284. productId = 1
  7285. productName = "ficc"
  7286. } else if req.CompanyType == utils.COMPANY_CLASSIFY_RAI {
  7287. productId = 2
  7288. productName = "权益"
  7289. } else {
  7290. productId = 3
  7291. productName = "佣金客户"
  7292. }
  7293. if req.CompanyId <= 0 {
  7294. br.Msg = "参数异常!"
  7295. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  7296. return
  7297. }
  7298. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  7299. if err != nil {
  7300. br.Msg = "查询该客户产品异常!"
  7301. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  7302. return
  7303. }
  7304. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  7305. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  7306. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  7307. return
  7308. }
  7309. //查询客户的产品权限
  7310. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, productId)
  7311. if err != nil {
  7312. br.Msg = "查询客户的产品权限异常"
  7313. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  7314. return
  7315. }
  7316. err = company.CompanyFreeze(req.CompanyId, productId, req.Remark)
  7317. if err != nil {
  7318. br.Msg = "冻结失败!"
  7319. br.ErrMsg = "冻结失败,Err:" + err.Error()
  7320. return
  7321. }
  7322. //新增操作记录
  7323. {
  7324. approveContent := req.Remark
  7325. remark := "冻结客户"
  7326. operation := "freeze"
  7327. services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
  7328. productName, sysUser.RealName, remark, operation, approveContent, sysUser.RealName, "", "冻结")
  7329. //新增产品权限冻结操作日志
  7330. for _, companyReportPermission := range companyReportPermissionList {
  7331. record := company_report_permission_log.CompanyReportPermissionLog{
  7332. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  7333. CompanyId: companyReportPermission.CompanyId,
  7334. ProductId: productId,
  7335. ProductName: companyReportPermission.ProductName,
  7336. SysUserId: sysUser.AdminId,
  7337. SysUserName: sysUser.RealName,
  7338. Remark: "冻结客户",
  7339. Operation: "freeze",
  7340. Status: companyReportPermission.Status,
  7341. CreateTime: time.Now(),
  7342. }
  7343. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  7344. }
  7345. }
  7346. br.Ret = 200
  7347. br.Success = true
  7348. br.Msg = "领取成功"
  7349. }
  7350. // @Title 获取客户权限
  7351. // @Description 获取客户权限接口
  7352. // @Param CompanyId query int true "用户id"
  7353. // @Success 200 {object} company.CompanyPermissionResp
  7354. // @router /getCompanyPermission [get]
  7355. func (this *CompanyController) PermissionList() {
  7356. br := new(models.BaseResponse).Init()
  7357. defer func() {
  7358. this.Data["json"] = br
  7359. this.ServeJSON()
  7360. }()
  7361. sysUser := this.SysUser
  7362. if sysUser == nil {
  7363. br.Msg = "请登录"
  7364. br.ErrMsg = "请登录,SysUser Is Empty"
  7365. br.Ret = 408
  7366. return
  7367. }
  7368. companyId, _ := this.GetInt("CompanyId")
  7369. if companyId <= 0 {
  7370. br.Msg = "参数错误"
  7371. br.ErrMsg = "客户参数小于等于0"
  7372. return
  7373. }
  7374. //返回基础参数
  7375. resp := new(company.CompanyPermissionResp)
  7376. //客户类型map
  7377. classifyMap := make(map[string]int)
  7378. classifyMap["ficc"] = 1
  7379. classifyMap["权益"] = 2
  7380. roleTypeCode := sysUser.RoleTypeCode
  7381. var companySlice []string
  7382. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  7383. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  7384. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  7385. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
  7386. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM ||
  7387. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
  7388. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_RESEARCHR {
  7389. companySlice = append(companySlice, "ficc")
  7390. } else if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  7391. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN ||
  7392. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  7393. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  7394. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT ||
  7395. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_RESEARCHR {
  7396. companySlice = append(companySlice, "权益")
  7397. }
  7398. for _, companyType := range companySlice {
  7399. //子权限切片集合
  7400. //var permissionClassifyArr []string
  7401. var permissionProductId int
  7402. if companyType == "ficc" {
  7403. permissionProductId = utils.COMPANY_PRODUCT_FICC_ID
  7404. } else {
  7405. permissionProductId = utils.COMPANY_PRODUCT_RAI_ID
  7406. }
  7407. //子权限切片集合
  7408. permissionClassifyArr, err := models.GetPermissionFirstByProductId(permissionProductId)
  7409. if err != nil {
  7410. br.Msg = "获取失败"
  7411. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  7412. return
  7413. }
  7414. //遍历获取
  7415. for _, v := range permissionClassifyArr {
  7416. checkList := make([]int, 0)
  7417. plist := new(company.PermissionLookList)
  7418. plist.Items = make([]*company.PermissionLookItem, 0)
  7419. items, err := company.GetPermissionLookItemsByParentId(classifyMap[companyType], v.ChartPermissionId)
  7420. if err != nil {
  7421. br.Msg = "获取失败"
  7422. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  7423. return
  7424. }
  7425. mapPermissionCheck := make(map[string]int)
  7426. for i, n := range items {
  7427. item := items[i]
  7428. count, err := company.GetCompanyPermissionCheck(companyId, n.ChartPermissionId)
  7429. if err != nil {
  7430. br.Msg = "获取失败"
  7431. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  7432. return
  7433. }
  7434. //合并主观客观勾选的权限
  7435. if count > 0 && mapPermissionCheck[n.PermissionName] == 0 {
  7436. checkList = append(checkList, n.ChartPermissionId)
  7437. mapPermissionCheck[n.PermissionName] = n.ChartPermissionId
  7438. }
  7439. permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  7440. if err != nil && err.Error() != utils.ErrNoRow() {
  7441. br.Msg = "获取失败"
  7442. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  7443. return
  7444. }
  7445. if permission != nil && permission.ChartPermissionId > 0 {
  7446. items[i].StartDate = permission.StartDate
  7447. items[i].EndDate = permission.EndDate
  7448. items[i].Status = permission.Status
  7449. //判断主观、客观
  7450. if items[i].PermissionType == 1 {
  7451. items[i].PermissionTypeName = "主观"
  7452. } else if items[i].PermissionType == 2 {
  7453. items[i].PermissionTypeName = "客观"
  7454. }
  7455. }
  7456. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  7457. endDateTime = endDateTime.AddDate(0, 0, 1)
  7458. sub := endDateTime.Sub(time.Now())
  7459. if sub < 0 {
  7460. sub = 0
  7461. }
  7462. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  7463. items[i].ExpireDay = expireDay
  7464. items[i].ClassifyName = v.PermissionName
  7465. //if n.PermissionType == 1 {
  7466. // items[i].PermissionTypeName = "主观"
  7467. //} else if n.PermissionType == 2 {
  7468. // items[i].PermissionTypeName = "客观"
  7469. //}
  7470. }
  7471. //合并主观客观
  7472. mapPermissionName := make(map[string]int)
  7473. for _, v := range items {
  7474. if mapPermissionName[v.PermissionName] == 0 {
  7475. //plist.Items = append(plist.Items, v)
  7476. //mapPermissionName[v.PermissionName] = v.ChartPermissionId
  7477. // CRM8.8-只有客观的时候回显
  7478. if mapPermissionCheck[v.PermissionName] == 0 || (mapPermissionCheck[v.PermissionName] > 0 && v.ChartPermissionId == mapPermissionCheck[v.PermissionName]) {
  7479. plist.Items = append(plist.Items, v)
  7480. mapPermissionName[v.PermissionName] = v.ChartPermissionId
  7481. }
  7482. }
  7483. }
  7484. plist.ClassifyName = v.PermissionName
  7485. plist.CheckList = checkList
  7486. if companyType == "ficc" {
  7487. resp.FiccPermissionList = append(resp.FiccPermissionList, plist)
  7488. } else {
  7489. resp.PermissionList = append(resp.PermissionList, plist)
  7490. }
  7491. }
  7492. }
  7493. br.Ret = 200
  7494. br.Success = true
  7495. br.Msg = "获取成功"
  7496. br.Data = resp
  7497. }
  7498. // @Title 获取客户来源列表
  7499. // @Description 获取客户来源列表
  7500. // @Success 200 {object} models.CompanySourceListResp
  7501. // @router /getCompanySourceList [get]
  7502. func (this *CompanyController) CompanySourceList() {
  7503. br := new(models.BaseResponse).Init()
  7504. defer func() {
  7505. this.Data["json"] = br
  7506. this.ServeJSON()
  7507. }()
  7508. sysUser := this.SysUser
  7509. if sysUser == nil {
  7510. br.Msg = "请登录"
  7511. br.ErrMsg = "请登录,SysUser Is Empty"
  7512. br.Ret = 408
  7513. return
  7514. }
  7515. list, err := models.GetAllCompanySourceList()
  7516. if err != nil {
  7517. br.Msg = "查询失败"
  7518. br.ErrMsg = "查询异常:" + err.Error()
  7519. return
  7520. }
  7521. br.Ret = 200
  7522. br.Success = true
  7523. br.Msg = "获取成功"
  7524. br.Data = models.CompanySourceListResp{
  7525. List: list,
  7526. }
  7527. }
  7528. // @Title 获取客户的合同列表
  7529. // @Description 获取客户合同列表接口
  7530. // @Param CompanyId query int true "用户id"
  7531. // @Param CompanyType query string false "用户类型:可取范围:ficc,权益"
  7532. // @Param Status query int true "合同审核结果,枚举值:`0`,`1`; 0:待审核,1:审核通过"
  7533. // @Success 200 {object} company.CompanyPermissionResp
  7534. // @router /getCompanyContract [get]
  7535. func (this *CompanyController) ContractList() {
  7536. br := new(models.BaseResponse).Init()
  7537. defer func() {
  7538. this.Data["json"] = br
  7539. this.ServeJSON()
  7540. }()
  7541. sysUser := this.SysUser
  7542. if sysUser == nil {
  7543. br.Msg = "请登录"
  7544. br.ErrMsg = "请登录,SysUser Is Empty"
  7545. br.Ret = 408
  7546. return
  7547. }
  7548. companyId, _ := this.GetInt("CompanyId")
  7549. if companyId <= 0 {
  7550. br.Msg = "参数错误"
  7551. br.ErrMsg = "客户参数小于等于0"
  7552. return
  7553. }
  7554. //合同状态
  7555. status, _ := this.GetInt("Status")
  7556. //产品类型
  7557. companyType := this.GetString("CompanyType")
  7558. var condition string
  7559. var pars []interface{}
  7560. //产品类型
  7561. if companyType == "" {
  7562. productId := services.GetProductId(sysUser.RoleTypeCode)
  7563. if productId != 0 {
  7564. condition += " AND product_id = ?"
  7565. pars = append(pars, productId)
  7566. }
  7567. } else {
  7568. if companyType == "ficc" {
  7569. condition += " AND product_id = ?"
  7570. pars = append(pars, 1)
  7571. } else {
  7572. condition += " AND product_id = ?"
  7573. pars = append(pars, 2)
  7574. }
  7575. }
  7576. if status != 0 {
  7577. condition += " AND status = ?"
  7578. pars = append(pars, status)
  7579. }
  7580. list, err := company.GetCompanyContractListByCompanyId(companyId, condition, pars)
  7581. if err != nil {
  7582. br.Msg = "查询失败"
  7583. br.ErrMsg = "查询异常:" + err.Error()
  7584. return
  7585. }
  7586. br.Ret = 200
  7587. br.Success = true
  7588. br.Msg = "获取成功"
  7589. br.Data = list
  7590. }
  7591. // @Title 获取客户所属销售
  7592. // @Description 根据客户id获取客户所属销售
  7593. // @Param CompanyId query int true "客户id"
  7594. // @Success 200 {object} response.CompanySellerListResp
  7595. // @router /getCompanySellerList [get]
  7596. func (this *CompanyUserController) GetCompanySellerList() {
  7597. br := new(models.BaseResponse).Init()
  7598. defer func() {
  7599. this.Data["json"] = br
  7600. this.ServeJSON()
  7601. }()
  7602. sysUser := this.SysUser
  7603. if sysUser == nil {
  7604. br.Msg = "请登录"
  7605. br.ErrMsg = "请登录,SysUser Is Empty"
  7606. br.Ret = 408
  7607. return
  7608. }
  7609. companyId, _ := this.GetInt("CompanyId")
  7610. //item := make([]*company.CompanyItem, 0)
  7611. list, err := company.GetCompanySellerByCompanyId(companyId)
  7612. if err != nil && err.Error() != utils.ErrNoRow() {
  7613. br.Msg = "获取失败"
  7614. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  7615. return
  7616. }
  7617. resp := response.CompanySellerListResp{
  7618. List: list,
  7619. }
  7620. //resp.List = list
  7621. br.Ret = 200
  7622. br.Success = true
  7623. br.Msg = "获取成功"
  7624. br.Data = resp
  7625. }
  7626. // GetTryOutCompanyList
  7627. // @Title 获取销售今日待办数据
  7628. // @Description 获取销售今日待办接口
  7629. // @Param CompanyName query string false "客户名称"
  7630. // @Param ReasonStatus query int false "续约情况说明状态:-1:未填写,0:全部,1:已填写"
  7631. // @Param PageSize query int true "每页数据条数"
  7632. // @Param CurrentIndex query int true "当前页页码,从1开始"
  7633. // @Success 200 {object} response.TryOutCompanyListResp
  7634. // @router /getTryOutCompanyList [get]
  7635. func (this *CompanyController) GetTryOutCompanyList() {
  7636. br := new(models.BaseResponse).Init()
  7637. defer func() {
  7638. this.Data["json"] = br
  7639. this.ServeJSON()
  7640. }()
  7641. sysUser := this.SysUser
  7642. if sysUser == nil {
  7643. br.Msg = "请登录"
  7644. br.ErrMsg = "请登录,SysUser Is Empty"
  7645. br.Ret = 408
  7646. return
  7647. }
  7648. companyName := this.GetString("CompanyName")
  7649. reasonStatus, _ := this.GetInt("ReasonStatus", 0)
  7650. pageSize, _ := this.GetInt("PageSize")
  7651. currentIndex, _ := this.GetInt("CurrentIndex")
  7652. productId := services.GetProductId(sysUser.RoleTypeCode)
  7653. var startSize int
  7654. if pageSize <= 0 {
  7655. pageSize = utils.PageSize20
  7656. }
  7657. if currentIndex <= 0 {
  7658. currentIndex = 1
  7659. }
  7660. startSize = paging.StartIndex(currentIndex, pageSize)
  7661. var condition string
  7662. var pars []interface{}
  7663. //sellerId, productId int, tryOutTime time.Time, tryOutReason string
  7664. var tryOutTime, lastDescriptionTime time.Time
  7665. if productId == 1 {
  7666. //ficc
  7667. interval := cache.GetIntervalFromCrmConfig("try_out_time_intervals")
  7668. tryOutTime = time.Now().AddDate(0, 0, -interval)
  7669. interval = cache.GetIntervalFromCrmConfig("last_description_time_intervals")
  7670. lastDescriptionTime = time.Now().AddDate(0, 0, -interval)
  7671. } else {
  7672. //权益
  7673. interval := cache.GetIntervalFromCrmConfig("rai_try_out_time_intervals")
  7674. tryOutTime = time.Now().AddDate(0, 0, -interval)
  7675. interval = cache.GetIntervalFromCrmConfig("rai_last_description_time_intervals")
  7676. lastDescriptionTime = time.Now().AddDate(0, 0, -interval)
  7677. }
  7678. if productId > 0 {
  7679. condition += ` and product_id=? `
  7680. pars = append(pars, productId)
  7681. }
  7682. //客户名称模糊搜索
  7683. if companyName != "" {
  7684. condition += ` and b.company_name like "%` + companyName + `%" `
  7685. }
  7686. //续约情况说明(-1:未填写,0:全部,1:已填写)
  7687. switch reasonStatus {
  7688. case -1:
  7689. 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) `
  7690. pars = append(pars, sysUser.AdminId, tryOutTime, lastDescriptionTime)
  7691. case 1:
  7692. 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) `
  7693. pars = append(pars, sysUser.AdminId, tryOutTime)
  7694. default:
  7695. 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) `
  7696. pars = append(pars, sysUser.AdminId, tryOutTime, lastDescriptionTime)
  7697. }
  7698. total := 0
  7699. list := make([]*company.TryOutCompanyList, 0)
  7700. 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}
  7701. if strings.Contains(strings.Join(ignoreStrs, ","), sysUser.RoleTypeCode) {
  7702. //排除已经签署续约合同的
  7703. notSql := ``
  7704. if productId > 0 {
  7705. notSql = fmt.Sprint(` and product_id = `, productId)
  7706. }
  7707. condition += `and a.company_id not in (select company_id from company_contract where contract_type ="续约合同" and start_date >now() and status = 1 ` + notSql + `) `
  7708. tmpTotal, err := company.GetTryOutCompanyCount(condition, pars)
  7709. if err != nil {
  7710. br.Msg = "获取失败"
  7711. br.ErrMsg = "获取总数失败失败,Err:" + err.Error()
  7712. return
  7713. }
  7714. tmpList, err := company.GetTryOutCompanyList(condition, pars, startSize, pageSize)
  7715. if err != nil {
  7716. br.Msg = "获取失败"
  7717. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  7718. return
  7719. }
  7720. total = tmpTotal
  7721. list = tmpList
  7722. }
  7723. if len(list) > 0 {
  7724. for k, item := range list {
  7725. endTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  7726. endTime = endTime.AddDate(0, 0, 1)
  7727. sub := endTime.Sub(time.Now())
  7728. if sub < 0 {
  7729. sub = 0
  7730. }
  7731. list[k].ExpireDays = int(sub.Hours() / 24)
  7732. }
  7733. }
  7734. page := paging.GetPaging(currentIndex, pageSize, total)
  7735. resp := response.TryOutCompanyListResp{
  7736. List: list,
  7737. Paging: page,
  7738. }
  7739. br.Ret = 200
  7740. br.Success = true
  7741. br.Msg = "获取成功"
  7742. br.Data = resp
  7743. }
  7744. // EditTryOutCompanyReason
  7745. // @Title 编辑续约说明情况
  7746. // @Description 编辑续约说明情况接口
  7747. // @Param request body company.RenewalReasonReq true "type json string"
  7748. // @Success 200 编辑成功
  7749. // @router /editTryOutCompanyReason [post]
  7750. func (this *CompanyController) EditTryOutCompanyReason() {
  7751. br := new(models.BaseResponse).Init()
  7752. defer func() {
  7753. this.Data["json"] = br
  7754. this.ServeJSON()
  7755. }()
  7756. sysUser := this.SysUser
  7757. if sysUser == nil {
  7758. br.Msg = "请登录"
  7759. br.ErrMsg = "请登录,SysUser Is Empty"
  7760. br.Ret = 408
  7761. return
  7762. }
  7763. var req company.RenewalReasonReq
  7764. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  7765. if err != nil {
  7766. br.Msg = "参数解析异常!"
  7767. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  7768. return
  7769. }
  7770. if req.CompanyId <= 0 {
  7771. br.Msg = "参数缺失"
  7772. br.ErrMsg = "参数缺失,客户编号未传!"
  7773. return
  7774. }
  7775. if req.ProductId <= 0 {
  7776. br.Msg = "参数缺失"
  7777. br.ErrMsg = "参数缺失,产品编号未传!"
  7778. return
  7779. }
  7780. if req.Remark == "" {
  7781. br.Msg = "参数缺失"
  7782. br.ErrMsg = "参数缺失,续约情况说明未传!"
  7783. return
  7784. }
  7785. /*if req.RenewalTodo == "" && req.Renew == 0 {
  7786. br.Msg = "参数缺失"
  7787. br.ErrMsg = "参数缺失,待办事项说明未传!"
  7788. return
  7789. }*/
  7790. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  7791. if err != nil {
  7792. br.Msg = "查询客户异常"
  7793. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  7794. return
  7795. }
  7796. if companyProduct.SellerId != sysUser.AdminId {
  7797. br.Msg = "客户异常,没有该客户的操作权限"
  7798. br.ErrMsg = "客户异常,没有该客户的操作权限"
  7799. return
  7800. }
  7801. renewalReason := company.CompanyRenewalReason{
  7802. CompanyRenewalReasonId: 0,
  7803. CompanyId: companyProduct.CompanyId,
  7804. ProductId: companyProduct.ProductId,
  7805. ProductName: companyProduct.ProductName,
  7806. CompanyName: companyProduct.CompanyName,
  7807. TryOutTime: companyProduct.TryOutTime,
  7808. RenewalReason: req.Remark,
  7809. RenewalTodo: req.RenewalTodo,
  7810. LastDescriptionTime: companyProduct.LastDescriptionTime,
  7811. EndDays: companyProduct.ContractEndDate,
  7812. ExpirationTimeExceeded: 0,
  7813. RenewalIntention: req.Renew,
  7814. CreateTime: time.Now(),
  7815. }
  7816. endTime, err := company.GetTryOutTimeFromOperationRecord(renewalReason.CompanyId)
  7817. if err != nil {
  7818. br.Msg = "查询该客户转试用时间异常!"
  7819. br.ErrMsg = "查询该客户转试用时间异常,err:" + err.Error()
  7820. return
  7821. }
  7822. endDateTime, err := time.Parse(utils.FormatDateTime, *endTime)
  7823. if err != nil {
  7824. br.Msg = "时间格式化异常!"
  7825. br.ErrMsg = "时间格式化异常,err:" + err.Error()
  7826. return
  7827. }
  7828. endDate := endDateTime.Format(utils.FormatDate)
  7829. endDateTime, _ = time.Parse(utils.FormatDate, endDate)
  7830. sub := time.Now().Sub(endDateTime)
  7831. renewalReason.ExpirationTimeExceeded = int(sub.Hours() / 24)
  7832. var newId int64
  7833. newId, err = company.AddRenewalReason(&renewalReason)
  7834. if err != nil {
  7835. br.Msg = "新增续约情况说明操作异常!"
  7836. br.ErrMsg = "新增续约情况说明操作异常,err:" + err.Error()
  7837. return
  7838. }
  7839. companyProduct.RenewalIntention = req.Renew
  7840. err = company.EditTryOutCompanyReason(companyProduct, req.Remark, req.RenewalTodo)
  7841. if err != nil {
  7842. br.Msg = "更新客户未续约异常!"
  7843. br.ErrMsg = "更新客户未续约异常,err:" + err.Error()
  7844. return
  7845. }
  7846. if req.Renew == 1 {
  7847. productName := ""
  7848. if req.ProductId == 1 {
  7849. productName = "ficc"
  7850. } else if req.ProductId == 2 {
  7851. productName = "权益"
  7852. } else {
  7853. productName = "佣金客户"
  7854. }
  7855. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  7856. if err != nil {
  7857. br.Msg = "查询该客户产品异常!"
  7858. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  7859. return
  7860. }
  7861. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  7862. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  7863. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  7864. return
  7865. }
  7866. //查询客户的产品权限
  7867. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, req.ProductId)
  7868. if err != nil {
  7869. br.Msg = "查询客户的产品权限异常"
  7870. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  7871. return
  7872. }
  7873. err = company.CompanyFreeze(req.CompanyId, req.ProductId, req.Remark)
  7874. if err != nil {
  7875. br.Msg = "冻结失败!"
  7876. br.ErrMsg = "冻结失败,Err:" + err.Error()
  7877. return
  7878. }
  7879. //新增操作记录
  7880. go func() {
  7881. time.Sleep(time.Second)
  7882. approveContent := req.Remark
  7883. remark := "冻结客户"
  7884. operation := "freeze"
  7885. _ = services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  7886. productName, "超级管理员", remark, operation, approveContent, sysUser.RealName, "", "冻结")
  7887. //新增产品权限冻结操作日志
  7888. for _, companyReportPermission := range companyReportPermissionList {
  7889. record := company_report_permission_log.CompanyReportPermissionLog{
  7890. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  7891. CompanyId: companyReportPermission.CompanyId,
  7892. ProductId: req.ProductId,
  7893. ProductName: companyReportPermission.ProductName,
  7894. SysUserId: sysUser.AdminId,
  7895. SysUserName: "超级管理员",
  7896. Remark: "冻结客户",
  7897. Operation: "freeze",
  7898. Status: companyReportPermission.Status,
  7899. CreateTime: time.Now(),
  7900. }
  7901. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  7902. }
  7903. }()
  7904. }
  7905. approveContent := req.Remark
  7906. approveContentExtra := req.RenewalTodo
  7907. remark := "新增续约说明"
  7908. operation := "edit_renewal_reason"
  7909. _ = services.AddCompanyOperationRecordMore(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  7910. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, approveContentExtra, sysUser.RealName, "", companyProduct.Status)
  7911. items, err := company.ReadCompanyOperationRecord(req.CompanyId)
  7912. if err != nil {
  7913. br.Msg = "编辑失败"
  7914. br.ErrMsg = "编辑失败,Err:" + err.Error()
  7915. return
  7916. }
  7917. if len(items) > 0 {
  7918. record := new(company.CompanyOperationRecord)
  7919. record.Id = items[0].Id
  7920. record.ApproveContent = req.Remark
  7921. record.ApproveContentExtra = req.RenewalTodo
  7922. _, err = company.UpdateCompanyOperationRecord(record)
  7923. if err != nil {
  7924. br.Msg = "编辑失败"
  7925. br.ErrMsg = "编辑失败,Err:" + err.Error()
  7926. return
  7927. }
  7928. } else {
  7929. br.Msg = "编辑失败"
  7930. br.ErrMsg = "编辑失败,未查询到转试用记录"
  7931. return
  7932. }
  7933. if req.ProductId == utils.COMPANY_PRODUCT_RAI_ID {
  7934. //权益客户新增历史备注总表
  7935. itemRecord := new(company.CompanyHistoryRemark)
  7936. itemRecord.CompanyId = req.CompanyId
  7937. itemRecord.Content = req.Remark
  7938. itemRecord.SysAdminId = sysUser.AdminId
  7939. itemRecord.SysAdminName = sysUser.RealName
  7940. itemRecord.CreateTime = time.Now().Local()
  7941. itemRecord.ModifyTime = time.Now().Local()
  7942. itemRecord.ShowTime = time.Now().Local()
  7943. itemRecord.ProductId = 2
  7944. itemRecord.TableName = "company_renewal_reason"
  7945. itemRecord.TableId = int(newId)
  7946. go services.AddCompanyHistoryRemark(itemRecord)
  7947. }
  7948. br.Ret = 200
  7949. br.Success = true
  7950. br.Msg = "编辑成功"
  7951. }
  7952. // AddTryOutCompanyReason
  7953. // @Title 新增续约说明情况
  7954. // @Description 新增续约说明情况接口
  7955. // @Param request body company.RenewalReasonReq true "type json string"
  7956. // @Success 200 编辑成功
  7957. // @router /addTryOutCompanyReason [post]
  7958. func (this *CompanyController) AddTryOutCompanyReason() {
  7959. br := new(models.BaseResponse).Init()
  7960. defer func() {
  7961. this.Data["json"] = br
  7962. this.ServeJSON()
  7963. }()
  7964. sysUser := this.SysUser
  7965. if sysUser == nil {
  7966. br.Msg = "请登录"
  7967. br.ErrMsg = "请登录,SysUser Is Empty"
  7968. br.Ret = 408
  7969. return
  7970. }
  7971. var req company.RenewalReasonReq
  7972. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  7973. if err != nil {
  7974. br.Msg = "参数解析异常!"
  7975. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  7976. return
  7977. }
  7978. if req.CompanyId <= 0 {
  7979. br.Msg = "参数缺失"
  7980. br.ErrMsg = "参数缺失,客户编号未传!"
  7981. return
  7982. }
  7983. if req.ProductId <= 0 {
  7984. br.Msg = "参数缺失"
  7985. br.ErrMsg = "参数缺失,产品编号未传!"
  7986. return
  7987. }
  7988. if req.Remark == "" {
  7989. br.Msg = "参数缺失"
  7990. br.ErrMsg = "参数缺失,续约情况说明未传!"
  7991. return
  7992. }
  7993. if req.RenewalTodo == "" && req.Renew == 0 {
  7994. br.Msg = "参数缺失"
  7995. br.ErrMsg = "参数缺失,待办事项说明未传!"
  7996. return
  7997. }
  7998. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  7999. if err != nil {
  8000. br.Msg = "查询客户异常"
  8001. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  8002. return
  8003. }
  8004. if companyProduct.SellerId != sysUser.AdminId {
  8005. br.Msg = "客户异常,没有该客户的操作权限"
  8006. br.ErrMsg = "客户异常,没有该客户的操作权限"
  8007. return
  8008. }
  8009. renewalReason := company.CompanyRenewalReason{
  8010. CompanyRenewalReasonId: 0,
  8011. CompanyId: companyProduct.CompanyId,
  8012. ProductId: companyProduct.ProductId,
  8013. ProductName: companyProduct.ProductName,
  8014. CompanyName: companyProduct.CompanyName,
  8015. TryOutTime: companyProduct.TryOutTime,
  8016. RenewalReason: req.Remark,
  8017. RenewalTodo: req.RenewalTodo,
  8018. LastDescriptionTime: companyProduct.LastDescriptionTime,
  8019. EndDays: companyProduct.ContractEndDate,
  8020. ExpirationTimeExceeded: 0,
  8021. RenewalIntention: req.Renew,
  8022. CreateTime: time.Now(),
  8023. }
  8024. endTime, err := company.GetTryOutTimeFromOperationRecord(renewalReason.CompanyId)
  8025. if err != nil {
  8026. br.Msg = "查询该客户转试用时间异常!"
  8027. br.ErrMsg = "查询该客户转试用时间异常,err:" + err.Error()
  8028. return
  8029. }
  8030. endDateTime, err := time.Parse(utils.FormatDateTime, *endTime)
  8031. if err != nil {
  8032. br.Msg = "时间格式化异常!"
  8033. br.ErrMsg = "时间格式化异常,err:" + err.Error()
  8034. return
  8035. }
  8036. endDate := endDateTime.Format(utils.FormatDate)
  8037. endDateTime, _ = time.Parse(utils.FormatDate, endDate)
  8038. sub := time.Now().Sub(endDateTime)
  8039. renewalReason.ExpirationTimeExceeded = int(sub.Hours() / 24)
  8040. var newId int64
  8041. newId, err = company.AddRenewalReason(&renewalReason)
  8042. if err != nil {
  8043. br.Msg = "新增续约情况说明操作异常!"
  8044. br.ErrMsg = "新增续约情况说明操作异常,err:" + err.Error()
  8045. return
  8046. }
  8047. companyProduct.RenewalIntention = req.Renew
  8048. err = company.EditTryOutCompanyReason(companyProduct, req.Remark, req.RenewalTodo)
  8049. if err != nil {
  8050. br.Msg = "更新客户续约情况说明异常!"
  8051. br.ErrMsg = "更新客户续约情况说明异常,err:" + err.Error()
  8052. return
  8053. }
  8054. if req.Renew == 1 {
  8055. productName := ""
  8056. if req.ProductId == 1 {
  8057. productName = "ficc"
  8058. } else if req.ProductId == 2 {
  8059. productName = "权益"
  8060. } else {
  8061. productName = "佣金客户"
  8062. }
  8063. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  8064. if err != nil {
  8065. br.Msg = "查询该客户产品异常!"
  8066. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  8067. return
  8068. }
  8069. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  8070. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  8071. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  8072. return
  8073. }
  8074. //查询客户的产品权限
  8075. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, req.ProductId)
  8076. if err != nil {
  8077. br.Msg = "查询客户的产品权限异常"
  8078. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  8079. return
  8080. }
  8081. err = company.CompanyFreeze(req.CompanyId, req.ProductId, req.Remark)
  8082. if err != nil {
  8083. br.Msg = "冻结失败!"
  8084. br.ErrMsg = "冻结失败,Err:" + err.Error()
  8085. return
  8086. }
  8087. //新增操作记录
  8088. go func() {
  8089. time.Sleep(time.Second)
  8090. approveContent := req.Remark
  8091. remark := "冻结客户"
  8092. operation := "freeze"
  8093. _ = services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  8094. productName, "超级管理员", remark, operation, approveContent, sysUser.RealName, "", "冻结")
  8095. //新增产品权限冻结操作日志
  8096. for _, companyReportPermission := range companyReportPermissionList {
  8097. record := company_report_permission_log.CompanyReportPermissionLog{
  8098. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  8099. CompanyId: companyReportPermission.CompanyId,
  8100. ProductId: req.ProductId,
  8101. ProductName: companyReportPermission.ProductName,
  8102. SysUserId: sysUser.AdminId,
  8103. SysUserName: "超级管理员",
  8104. Remark: "冻结客户",
  8105. Operation: "freeze",
  8106. Status: companyReportPermission.Status,
  8107. CreateTime: time.Now(),
  8108. }
  8109. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  8110. }
  8111. }()
  8112. }
  8113. {
  8114. approveContent := req.Remark
  8115. approveContentExtra := req.RenewalTodo
  8116. remark := "新增续约说明"
  8117. operation := "add_renewal_reason"
  8118. _ = services.AddCompanyOperationRecordMore(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  8119. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, approveContentExtra, sysUser.RealName, "", companyProduct.Status)
  8120. }
  8121. if req.ProductId == utils.COMPANY_PRODUCT_RAI_ID {
  8122. //权益客户新增历史备注总表
  8123. itemRecord := new(company.CompanyHistoryRemark)
  8124. itemRecord.CompanyId = req.CompanyId
  8125. itemRecord.Content = req.Remark
  8126. itemRecord.SysAdminId = sysUser.AdminId
  8127. itemRecord.SysAdminName = sysUser.RealName
  8128. itemRecord.CreateTime = time.Now().Local()
  8129. itemRecord.ModifyTime = time.Now().Local()
  8130. itemRecord.ShowTime = time.Now().Local()
  8131. itemRecord.ProductId = 2
  8132. itemRecord.TableName = "company_renewal_reason"
  8133. itemRecord.TableId = int(newId)
  8134. go services.AddCompanyHistoryRemark(itemRecord)
  8135. }
  8136. br.Ret = 200
  8137. br.Success = true
  8138. br.Msg = "编辑成功"
  8139. }
  8140. // RenewReasonList 客户未续约说明历史列表
  8141. // @Title 客户未续约说明历史列表
  8142. // @Description 客户未续约说明历史列表
  8143. // @Param CompanyId query string true "客户id"
  8144. // @Param ProductId query string true "产品id"
  8145. // @Success 200 {object} response.RenewReasonItemResp
  8146. // @router /renewReasonList [get]
  8147. func (this *CompanyController) RenewReasonList() {
  8148. br := new(models.BaseResponse).Init()
  8149. defer func() {
  8150. this.Data["json"] = br
  8151. this.ServeJSON()
  8152. }()
  8153. sysUser := this.SysUser
  8154. if sysUser == nil {
  8155. br.Msg = "请登录"
  8156. br.ErrMsg = "请登录,SysUser Is Empty"
  8157. br.Ret = 408
  8158. return
  8159. }
  8160. CompanyId := this.GetString("CompanyId")
  8161. ProductId := this.GetString("ProductId")
  8162. if CompanyId == "" {
  8163. br.Msg = "请输入客户ID"
  8164. return
  8165. }
  8166. if ProductId != "1" && ProductId != "2" {
  8167. br.Msg = "请输入正确的产品ID"
  8168. return
  8169. }
  8170. renewalReason, err := models.GetMoreRenewalReason(CompanyId, ProductId)
  8171. if err != nil {
  8172. br.Msg = "获取失败"
  8173. br.ErrMsg = "获取失败,Err:" + err.Error()
  8174. return
  8175. }
  8176. resp := make([]response.RenewReasonItemResp, len(renewalReason))
  8177. for i, reason := range renewalReason {
  8178. createDate := reason.CreateTime.Format("2006.01.02 15:04:05")
  8179. resp[i].RenewalReason = reason.RenewalReason
  8180. resp[i].RenewalTodo = reason.RenewalTodo
  8181. resp[i].CreateTime = createDate
  8182. }
  8183. br.Ret = 200
  8184. br.Success = true
  8185. br.Msg = "获取成功"
  8186. br.Data = resp
  8187. }
  8188. // AddRenewalReason
  8189. // @Title 转试用按钮新增续约说明情况
  8190. // @Description 转试用按钮新增续约说明情况
  8191. // @Param request body company.TryOutReq true "type json string"
  8192. // @Success 200 编辑成功
  8193. // @router /addRenewalReason [post]
  8194. func (this *CompanyController) AddRenewalReason() {
  8195. br := new(models.BaseResponse).Init()
  8196. defer func() {
  8197. this.Data["json"] = br
  8198. this.ServeJSON()
  8199. }()
  8200. sysUser := this.SysUser
  8201. if sysUser == nil {
  8202. br.Msg = "请登录"
  8203. br.ErrMsg = "请登录,SysUser Is Empty"
  8204. br.Ret = 408
  8205. return
  8206. }
  8207. var req company.TryOutReq
  8208. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  8209. if err != nil {
  8210. br.Msg = "参数解析异常!"
  8211. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  8212. return
  8213. }
  8214. if req.CompanyId <= 0 {
  8215. br.Msg = "参数缺失"
  8216. br.ErrMsg = "参数缺失,客户编号未传!"
  8217. return
  8218. }
  8219. if req.ProductId <= 0 {
  8220. br.Msg = "参数缺失"
  8221. br.ErrMsg = "参数缺失,产品编号未传!"
  8222. return
  8223. }
  8224. if req.OperationId <= 0 {
  8225. br.Msg = "参数缺失"
  8226. br.ErrMsg = "参数缺失,操作记录表编号未传!"
  8227. return
  8228. }
  8229. if req.Remark == "" {
  8230. br.Msg = "参数缺失"
  8231. br.ErrMsg = "参数缺失,续约情况说明未传!"
  8232. return
  8233. }
  8234. if req.RenewalTodo == "" && req.Renew == 0 {
  8235. br.Msg = "参数缺失"
  8236. br.ErrMsg = "参数缺失,待办事项说明未传!"
  8237. return
  8238. }
  8239. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  8240. if err != nil {
  8241. br.Msg = "查询客户异常"
  8242. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  8243. return
  8244. }
  8245. if companyProduct.SellerId != sysUser.AdminId {
  8246. br.Msg = "客户异常,没有该客户的操作权限"
  8247. br.ErrMsg = "客户异常,没有该客户的操作权限"
  8248. return
  8249. }
  8250. renewalReason := company.CompanyRenewalReason{
  8251. CompanyRenewalReasonId: 0,
  8252. CompanyId: companyProduct.CompanyId,
  8253. ProductId: companyProduct.ProductId,
  8254. ProductName: companyProduct.ProductName,
  8255. CompanyName: companyProduct.CompanyName,
  8256. TryOutTime: companyProduct.TryOutTime,
  8257. RenewalReason: req.Remark,
  8258. RenewalTodo: req.RenewalTodo,
  8259. LastDescriptionTime: companyProduct.LastDescriptionTime,
  8260. EndDays: companyProduct.ContractEndDate,
  8261. ExpirationTimeExceeded: 0,
  8262. RenewalIntention: req.Renew,
  8263. CreateTime: time.Now(),
  8264. }
  8265. endTime, err := company.GetTryOutTimeFromOperationRecord(renewalReason.CompanyId)
  8266. if err != nil {
  8267. br.Msg = "查询该客户转试用时间异常!"
  8268. br.ErrMsg = "查询该客户转试用时间异常,err:" + err.Error()
  8269. return
  8270. }
  8271. endDateTime, err := time.Parse(utils.FormatDateTime, *endTime)
  8272. if err != nil {
  8273. br.Msg = "时间格式化异常!"
  8274. br.ErrMsg = "时间格式化异常,err:" + err.Error()
  8275. return
  8276. }
  8277. endDate := endDateTime.Format(utils.FormatDate)
  8278. endDateTime, _ = time.Parse(utils.FormatDate, endDate)
  8279. sub := time.Now().Sub(endDateTime)
  8280. renewalReason.ExpirationTimeExceeded = int(sub.Hours() / 24)
  8281. var newId int64
  8282. newId, err = company.AddRenewalReason(&renewalReason)
  8283. if err != nil {
  8284. br.Msg = "新增续约情况说明操作异常!"
  8285. br.ErrMsg = "新增续约情况说明操作异常,err:" + err.Error()
  8286. return
  8287. }
  8288. companyProduct.RenewalIntention = req.Renew
  8289. err = company.EditTryOutCompanyReason(companyProduct, req.Remark, req.RenewalTodo)
  8290. if err != nil {
  8291. br.Msg = "更新客户续约情况说明异常!"
  8292. br.ErrMsg = "更新客户续约情况说明异常,err:" + err.Error()
  8293. return
  8294. }
  8295. if req.Renew == 1 {
  8296. productName := ""
  8297. if req.ProductId == 1 {
  8298. productName = "ficc"
  8299. } else if req.ProductId == 2 {
  8300. productName = "权益"
  8301. } else {
  8302. productName = "佣金客户"
  8303. }
  8304. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  8305. if err != nil {
  8306. br.Msg = "查询该客户产品异常!"
  8307. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  8308. return
  8309. }
  8310. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  8311. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  8312. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  8313. return
  8314. }
  8315. //查询客户的产品权限
  8316. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, req.ProductId)
  8317. if err != nil {
  8318. br.Msg = "查询客户的产品权限异常"
  8319. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  8320. return
  8321. }
  8322. err = company.CompanyFreeze(req.CompanyId, req.ProductId, req.Remark)
  8323. if err != nil {
  8324. br.Msg = "冻结失败!"
  8325. br.ErrMsg = "冻结失败,Err:" + err.Error()
  8326. return
  8327. }
  8328. //新增操作记录
  8329. go func() {
  8330. time.Sleep(time.Second)
  8331. approveContent := req.Remark
  8332. remark := "冻结客户"
  8333. operation := "freeze"
  8334. _ = services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  8335. productName, "超级管理员", remark, operation, approveContent, sysUser.RealName, "", "冻结")
  8336. //新增产品权限冻结操作日志
  8337. for _, companyReportPermission := range companyReportPermissionList {
  8338. record := company_report_permission_log.CompanyReportPermissionLog{
  8339. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  8340. CompanyId: companyReportPermission.CompanyId,
  8341. ProductId: req.ProductId,
  8342. ProductName: companyReportPermission.ProductName,
  8343. SysUserId: sysUser.AdminId,
  8344. SysUserName: "超级管理员",
  8345. Remark: "冻结客户",
  8346. Operation: "freeze",
  8347. Status: companyReportPermission.Status,
  8348. CreateTime: time.Now(),
  8349. }
  8350. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  8351. }
  8352. }()
  8353. }
  8354. {
  8355. approveContent := req.Remark
  8356. approveContentExtra := req.RenewalTodo
  8357. remark := "新增续约说明"
  8358. operation := "add_try_out_reason"
  8359. _ = services.AddCompanyOperationRecordMore(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  8360. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, approveContentExtra, sysUser.RealName, "", companyProduct.Status)
  8361. record := new(company.CompanyOperationRecord)
  8362. record.Id = req.OperationId
  8363. record.ApproveContent = req.Remark
  8364. record.ApproveContentExtra = req.RenewalTodo
  8365. _, err = company.UpdateCompanyOperationRecord(record)
  8366. if err != nil {
  8367. br.Msg = "编辑失败"
  8368. br.ErrMsg = "编辑失败,Err:" + err.Error()
  8369. return
  8370. }
  8371. }
  8372. if req.ProductId == utils.COMPANY_PRODUCT_RAI_ID {
  8373. //权益客户新增历史备注总表
  8374. itemRecord := new(company.CompanyHistoryRemark)
  8375. itemRecord.CompanyId = req.CompanyId
  8376. itemRecord.Content = req.Remark
  8377. itemRecord.SysAdminId = sysUser.AdminId
  8378. itemRecord.SysAdminName = sysUser.RealName
  8379. itemRecord.CreateTime = time.Now().Local()
  8380. itemRecord.ModifyTime = time.Now().Local()
  8381. itemRecord.ShowTime = time.Now().Local()
  8382. itemRecord.ProductId = 2
  8383. itemRecord.TableName = "company_renewal_reason"
  8384. itemRecord.TableId = int(newId)
  8385. go services.AddCompanyHistoryRemark(itemRecord)
  8386. }
  8387. br.Ret = 200
  8388. br.Success = true
  8389. br.Msg = "编辑成功"
  8390. }
  8391. // AddRemark
  8392. // @Title 新增备注
  8393. // @Description 新增备注
  8394. // @Param request body company.RemarkReq true "type json string"
  8395. // @Success 200 编辑成功
  8396. // @router /remark/add [post]
  8397. func (this *CompanyController) AddRemark() {
  8398. br := new(models.BaseResponse).Init()
  8399. defer func() {
  8400. this.Data["json"] = br
  8401. this.ServeJSON()
  8402. }()
  8403. sysUser := this.SysUser
  8404. if sysUser == nil {
  8405. br.Msg = "请登录"
  8406. br.ErrMsg = "请登录,SysUser Is Empty"
  8407. br.Ret = 408
  8408. return
  8409. }
  8410. var req company.RemarkReq
  8411. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  8412. if err != nil {
  8413. br.Msg = "参数解析异常!"
  8414. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  8415. return
  8416. }
  8417. if req.CompanyId <= 0 {
  8418. br.Msg = "参数缺失"
  8419. br.ErrMsg = "参数缺失,客户编号未传!"
  8420. return
  8421. }
  8422. if req.Remark == "" {
  8423. br.Msg = "参数缺失"
  8424. br.ErrMsg = "参数缺失,备注说明未传!"
  8425. return
  8426. }
  8427. var productId int
  8428. //var productName string
  8429. 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 {
  8430. productId = 1
  8431. //productName = "ficc"
  8432. } 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 {
  8433. productId = 2
  8434. //productName = "权益"
  8435. } else {
  8436. br.Msg = "角色类型错误"
  8437. br.ErrMsg = "角色类型错误,该角色不能添加备注!"
  8438. return
  8439. }
  8440. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  8441. if err != nil {
  8442. br.Msg = "查询客户异常"
  8443. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  8444. }
  8445. if companyProduct.SellerId != sysUser.AdminId {
  8446. br.Msg = "客户异常,没有该客户的操作权限"
  8447. br.ErrMsg = "客户异常,没有该客户的操作权限"
  8448. return
  8449. }
  8450. remark := company.CompanyProductRemark{
  8451. CompanyId: companyProduct.CompanyId,
  8452. ProductId: companyProduct.ProductId,
  8453. ProductName: companyProduct.ProductName,
  8454. Remark: req.Remark,
  8455. CreateTime: time.Now(),
  8456. SysUserId: sysUser.AdminId,
  8457. SysRealName: sysUser.RealName,
  8458. }
  8459. var newId int64
  8460. newId, err = company.AddCompanyRemark(&remark)
  8461. {
  8462. approveContent := req.Remark
  8463. remark := "新增备注"
  8464. operation := "add_remark"
  8465. services.AddCompanyOperationRecord(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  8466. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, sysUser.RealName, "", companyProduct.Status)
  8467. }
  8468. if err != nil {
  8469. br.Msg = "编辑失败"
  8470. br.ErrMsg = "编辑失败,Err:" + err.Error()
  8471. }
  8472. //如果是权益的写入历史备注表
  8473. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  8474. //权益客户新增历史备注总表
  8475. itemRecord := new(company.CompanyHistoryRemark)
  8476. itemRecord.CompanyId = req.CompanyId
  8477. itemRecord.Content = req.Remark
  8478. itemRecord.SysAdminId = sysUser.AdminId
  8479. itemRecord.SysAdminName = sysUser.RealName
  8480. itemRecord.CreateTime = time.Now().Local()
  8481. itemRecord.ModifyTime = time.Now().Local()
  8482. itemRecord.ShowTime = time.Now().Local()
  8483. itemRecord.ProductId = 2
  8484. itemRecord.TableName = "company_product_remark"
  8485. itemRecord.TableId = int(newId)
  8486. go services.AddCompanyHistoryRemark(itemRecord)
  8487. }
  8488. br.Ret = 200
  8489. br.Success = true
  8490. br.Msg = "编辑成功"
  8491. }
  8492. // RemarkList 备注列表
  8493. // @Title 备注列表
  8494. // @Description 备注列表
  8495. // @Param CompanyId query string true "客户id"
  8496. // @Success 200 {object} company.RemarkResp
  8497. // @router /remark [get]
  8498. func (this *CompanyController) RemarkList() {
  8499. br := new(models.BaseResponse).Init()
  8500. defer func() {
  8501. this.Data["json"] = br
  8502. this.ServeJSON()
  8503. }()
  8504. sysUser := this.SysUser
  8505. if sysUser == nil {
  8506. br.Msg = "请登录"
  8507. br.ErrMsg = "请登录,SysUser Is Empty"
  8508. br.Ret = 408
  8509. return
  8510. }
  8511. companyId := this.GetString("CompanyId")
  8512. var remarkList []*company.CompanyProductRemark
  8513. var err error
  8514. groupFicc := []string{
  8515. utils.ROLE_TYPE_CODE_FICC_SELLER, utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_FICC_GROUP,
  8516. utils.ROLE_TYPE_CODE_FICC_DEPARTMENT, utils.ROLE_TYPE_CODE_FICC_ADMIN,
  8517. }
  8518. groupRai := []string{
  8519. utils.ROLE_TYPE_CODE_RAI_SELLER, utils.ROLE_TYPE_CODE_RAI_GROUP, utils.ROLE_TYPE_CODE_RAI_GROUP,
  8520. utils.ROLE_TYPE_CODE_RAI_DEPARTMENT, utils.ROLE_TYPE_CODE_RAI_ADMIN,
  8521. }
  8522. if utils.InArrayByStr(groupFicc, sysUser.RoleTypeCode) {
  8523. remarkList, err = company.GetRemarkList(companyId, "1")
  8524. if err != nil {
  8525. br.Msg = "获取失败"
  8526. br.ErrMsg = "获取失败,Err:" + err.Error()
  8527. return
  8528. }
  8529. }
  8530. if utils.InArrayByStr(groupRai, sysUser.RoleTypeCode) {
  8531. remarkList, err = company.GetRemarkList(companyId, "2")
  8532. if err != nil {
  8533. br.Msg = "获取失败"
  8534. br.ErrMsg = "获取失败,Err:" + err.Error()
  8535. return
  8536. }
  8537. }
  8538. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  8539. remarkList, err = company.GetRemarkListByCompanyId(companyId)
  8540. if err != nil {
  8541. br.Msg = "获取失败"
  8542. br.ErrMsg = "获取失败,Err:" + err.Error()
  8543. return
  8544. }
  8545. }
  8546. resp := make([]company.RemarkResp, len(remarkList))
  8547. for i, remark := range remarkList {
  8548. createDate := remark.CreateTime.Format(utils.FormatDateTime)
  8549. resp[i].RemarkId = remark.CompanyProductRemarkId
  8550. resp[i].Remark = remark.Remark
  8551. resp[i].ProductName = remark.ProductName
  8552. resp[i].CreateTime = createDate
  8553. // 仅自己添加的可删除
  8554. if remark.SysUserId == sysUser.AdminId {
  8555. resp[i].ButtonDel = true
  8556. }
  8557. }
  8558. br.Ret = 200
  8559. br.Success = true
  8560. br.Msg = "获取成功"
  8561. br.Data = resp
  8562. }
  8563. // RoadShowList 客户列表的路演详情列表
  8564. // @Title 路演详情列表
  8565. // @Description 路演详情列表
  8566. // @Param CompanyId query string true "客户id"
  8567. // @Success 200 {object} company.RoadShowListResp
  8568. // @router /roadShowList [get]
  8569. func (this *CompanyController) RoadShowList() {
  8570. br := new(models.BaseResponse).Init()
  8571. defer func() {
  8572. this.Data["json"] = br
  8573. this.ServeJSON()
  8574. }()
  8575. sysUser := this.SysUser
  8576. if sysUser == nil {
  8577. br.Msg = "请登录"
  8578. br.ErrMsg = "请登录,SysUser Is Empty"
  8579. br.Ret = 408
  8580. return
  8581. }
  8582. companyId := this.GetString("CompanyId")
  8583. companyIdInt, _ := strconv.Atoi(companyId)
  8584. if companyIdInt <= 0 {
  8585. br.Msg = "参数错误"
  8586. return
  8587. }
  8588. var englishCompany int
  8589. if companyIdInt > utils.EnCompanyIdStep {
  8590. companyIdInt = companyIdInt - utils.EnCompanyIdStep
  8591. englishCompany = 1
  8592. }
  8593. var err error
  8594. roadShowList, err := company.GetRoadShowList(companyIdInt, englishCompany)
  8595. if err != nil {
  8596. br.Msg = "获取失败"
  8597. br.ErrMsg = "获取失败,Err:" + err.Error()
  8598. return
  8599. }
  8600. //calendarIdSlice := make([]string, 0)
  8601. //for _, v := range roadShowList {
  8602. // calendarIdSlice = append(calendarIdSlice, strconv.Itoa(v.RsCalendarId))
  8603. //}
  8604. //calendarIdStr := strings.Join(calendarIdSlice, ",")
  8605. //researcherList, _ := company.GetRoadShowResearchers(calendarIdStr)
  8606. //roadShowTotalMap := make(map[int]int)
  8607. //for _, roadShowTotal := range researcherList {
  8608. // roadShowTotalMap[roadShowTotal.CompanyId] = roadShowTotal.Total
  8609. //}
  8610. resp := make([]company.RoadShowListResp, len(roadShowList))
  8611. for i, calendar := range roadShowList {
  8612. resp[i].SysUserRealName = calendar.SysUserRealName
  8613. resp[i].RoadshowType = calendar.RoadshowType
  8614. //线上为平台,线下为省市
  8615. if calendar.RoadshowType == "线上" {
  8616. resp[i].RoadshowPlatform = calendar.RoadshowPlatform
  8617. } else {
  8618. resp[i].RoadshowPlatform = calendar.Province + calendar.City
  8619. }
  8620. researchers, err := company.GetRoadShowResearchers(calendar.RsCalendarId)
  8621. if err != nil && err.Error() != utils.ErrNoRow() {
  8622. br.Msg = "获取研究员信息失败"
  8623. br.ErrMsg = "获取研究员信息失败,Err:" + err.Error()
  8624. return
  8625. }
  8626. var researcherList []string
  8627. for _, researcher := range researchers {
  8628. researcherList = append(researcherList, *researcher)
  8629. }
  8630. researcher := strings.Join(researcherList, ",")
  8631. resp[i].Researchers = researcher
  8632. resp[i].RoadShowTime = calendar.EndDate.Format("2006.01.02")
  8633. }
  8634. br.Ret = 200
  8635. br.Success = true
  8636. br.Msg = "获取成功"
  8637. br.Data = resp
  8638. }
  8639. // CustomerAreaStatistics
  8640. // @Title 客户区域统计
  8641. // @Description 获取客户区域统计接口
  8642. // @Param Date query string true "日期"
  8643. // @Param ProductId query Int true "产品Id"
  8644. // @Success 200 {object} statistic_report.CompanyRenewRecordResp
  8645. // @router /customerAreaStatistics [get]
  8646. func (this *CompanyController) CustomerAreaStatistics() {
  8647. br := new(models.BaseResponse).Init()
  8648. defer func() {
  8649. this.Data["json"] = br
  8650. this.ServeJSON()
  8651. }()
  8652. sysUser := this.SysUser
  8653. if sysUser == nil {
  8654. br.Msg = "请登录"
  8655. br.ErrMsg = "请登录,SysUser Is Empty"
  8656. br.Ret = 408
  8657. return
  8658. }
  8659. date := this.GetString("Date")
  8660. productId, _ := this.GetInt("ProductId", 1)
  8661. //获取列表
  8662. companyAreaDataMapList, _, err := statistic_report.GetAreaDateData(date, productId)
  8663. if err != nil {
  8664. br.Msg = "数据异常"
  8665. br.ErrMsg = "数据异常,Err:" + err.Error()
  8666. return
  8667. }
  8668. //获取省市数据
  8669. areaMap := make(map[string]string)
  8670. provinceMap := make(map[string][]string, 0)
  8671. list, err := statisticModels.GetAllCompanyArea()
  8672. for _, item := range list {
  8673. areaMap[item.City] = item.Province
  8674. }
  8675. for c, p := range areaMap {
  8676. citySlice := make([]string, 0)
  8677. citySlice = provinceMap[p]
  8678. citySlice = append(citySlice, c)
  8679. provinceMap[p] = citySlice
  8680. }
  8681. //数据处理
  8682. groupReportRecordList := make([]statistic_report.GroupCityRecord, 0)
  8683. resp := statistic_report.CustomerAreaStatisticsResp{
  8684. List: groupReportRecordList,
  8685. IsAdmin: false,
  8686. }
  8687. //除ficc管理员和超管之外的角色进入此页面时,正式客户数量>0时可点击,点击查看正式客户列表详情;
  8688. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  8689. resp.IsAdmin = true
  8690. }
  8691. startDateIndexList := make(map[int]string) //开始时间间隔map
  8692. endDateIndexList := make(map[int]string) //结束时间间隔map
  8693. tmpAllTryOutNumMap := make(map[int]int)
  8694. tmpAllFormalNumMap := make(map[int]int)
  8695. tmpAllActiveNumMap := make(map[int]int)
  8696. tmpAllAllActiveNumMap := make(map[int]int)
  8697. tmpAllNoIncrementalActiveNumMap := make(map[int]int)
  8698. tmpAllTryStagePushMap := make(map[int]int)
  8699. tmpAllTryStageFollowMap := make(map[int]int)
  8700. tmpAllTryStageReadyMap := make(map[int]int)
  8701. tmpAllTryStageInitMap := make(map[int]int)
  8702. for province, cityList := range provinceMap {
  8703. tmpGroupCityReportRecord := make([]statistic_report.CityRecord, 0)
  8704. tmpGroupCompanyReportRecordNumList := make([]statistic_report.CompanyAreaNum, 0)
  8705. tmpGroupTryOutNumMap := make(map[int]int)
  8706. tmpGroupFormalNumMap := make(map[int]int)
  8707. tmpGroupFormalCompanyIdsMap := make(map[int]string) //正式客户id
  8708. tmpGroupActiveNumMap := make(map[int]int)
  8709. tmpGroupAllActiveNumMap := make(map[int]int)
  8710. tmpGroupNoIncrementalActiveNumMap := make(map[int]int)
  8711. // 其他类型客户ID
  8712. tmpGroupTryOutCompanyIdsMap := make(map[int]string) //试用客户ID
  8713. tmpGroupPushCompanyIdsMap := make(map[int]string) //试用(推进)客户ID
  8714. tmpGroupFollowCompanyIdsMap := make(map[int]string) //试用(跟踪)客户ID
  8715. tmpGroupReadyCompanyIdsMap := make(map[int]string) //试用(预备)客户ID
  8716. tmpGroupInitCompanyIdsMap := make(map[int]string) //试用(未分类)客户ID
  8717. tmpGroupTryStagePushMap := make(map[int]int)
  8718. tmpGroupTryStageFollowMap := make(map[int]int)
  8719. tmpGroupTryStageReadyMap := make(map[int]int)
  8720. tmpGroupTryStageInitMap := make(map[int]int)
  8721. for _, city := range cityList {
  8722. //城市数据
  8723. //每个城市的数据
  8724. tmpCompanyReportRecordNumList := make([]statistic_report.CompanyAreaNum, 0)
  8725. for index, adminData := range companyAreaDataMapList {
  8726. startDateIndexList[index] = adminData.StartDate
  8727. endDateIndexList[index] = adminData.EndDate
  8728. var tmpTryOutNum, tmpFormalNum, tmpActiveStatus, tmpAllActiveStatus, tmpNoIncrementalActiveStatus int
  8729. var tmpTryStagePushNum, tmpTryStageFollowNum, tmpTryStageReadyNum, tmpTryStageInitNum int
  8730. var tmpFormalCompanyIds string //正式客户id集合
  8731. var tmpTryOutCompanyIds string //试用客户ID集合
  8732. var tmpPushCompanyIds string //试用(推进)客户ID集合
  8733. var tmpFollowCompanyIds string //试用(跟踪)客户ID集合
  8734. var tmpReadyCompanyIds string //试用(预备)客户ID集合
  8735. var tmpInitCompanyIds string //试用(未分类)客户ID集合
  8736. if num, ok := adminData.TryOutMap[city]; ok {
  8737. tmpTryOutNum = num
  8738. }
  8739. if num, ok := adminData.FormalMap[city]; ok {
  8740. tmpFormalNum = num
  8741. }
  8742. if companyIds, ok := adminData.FormalIdMap[city]; ok {
  8743. tmpFormalCompanyIds = companyIds
  8744. }
  8745. if companyIds, ok := adminData.TryOutIdMap[city]; ok {
  8746. tmpTryOutCompanyIds = companyIds
  8747. }
  8748. if companyIds, ok := adminData.TryStagePushIdsMap[city]; ok {
  8749. tmpPushCompanyIds = companyIds
  8750. }
  8751. if companyIds, ok := adminData.TryStageFollowIdsMap[city]; ok {
  8752. tmpFollowCompanyIds = companyIds
  8753. }
  8754. if companyIds, ok := adminData.TryStageReadyIdsMap[city]; ok {
  8755. tmpReadyCompanyIds = companyIds
  8756. }
  8757. if companyIds, ok := adminData.TryStageInitIdsMap[city]; ok {
  8758. tmpInitCompanyIds = companyIds
  8759. }
  8760. if num, ok := adminData.ActiveMap[city]; ok {
  8761. tmpActiveStatus = num
  8762. }
  8763. if num, ok := adminData.AllActiveMap[city]; ok {
  8764. tmpAllActiveStatus = num
  8765. }
  8766. if num, ok := adminData.NoIncrementalActiveMap[city]; ok {
  8767. tmpNoIncrementalActiveStatus = num
  8768. }
  8769. // 每个用户的试用标签统计 推进-跟踪-预备-未分类
  8770. if num, ok := adminData.TryStagePushNum[city]; ok {
  8771. tmpTryStagePushNum = num
  8772. }
  8773. if num, ok := adminData.TryStageFollowNum[city]; ok {
  8774. tmpTryStageFollowNum = num
  8775. }
  8776. if num, ok := adminData.TryStageReadyNum[city]; ok {
  8777. tmpTryStageReadyNum = num
  8778. }
  8779. if num, ok := adminData.TryStageInitNum[city]; ok {
  8780. tmpTryStageInitNum = num
  8781. }
  8782. tmpAdminRsReportRecordNum := statistic_report.CompanyAreaNum{
  8783. TryOutNum: tmpTryOutNum,
  8784. FormalNum: tmpFormalNum,
  8785. FormalIds: tmpFormalCompanyIds,
  8786. ActiveNum: tmpActiveStatus,
  8787. AllActiveNum: tmpAllActiveStatus,
  8788. NoIncrementalActiveNum: tmpNoIncrementalActiveStatus,
  8789. StartDate: adminData.StartDate,
  8790. EndDate: adminData.EndDate,
  8791. TryStagePushNum: tmpTryStagePushNum,
  8792. TryStageFollowNum: tmpTryStageFollowNum,
  8793. TryStageReadyNum: tmpTryStageReadyNum,
  8794. TryStageInitNum: tmpTryStageInitNum,
  8795. TotalNum: tmpTryOutNum + tmpFormalNum,
  8796. }
  8797. tmpCompanyReportRecordNumList = append(tmpCompanyReportRecordNumList, tmpAdminRsReportRecordNum)
  8798. //组内数据汇总
  8799. tmpGroupTryOutNumMap[index] += tmpTryOutNum
  8800. tmpGroupFormalNumMap[index] += tmpFormalNum
  8801. // 正式客户id
  8802. if tmpFormalCompanyIds != `` {
  8803. tmpGroupFormalCompanyIds, ok := tmpGroupFormalCompanyIdsMap[index]
  8804. if ok {
  8805. tmpGroupFormalCompanyIdsMap[index] = tmpGroupFormalCompanyIds + "," + tmpFormalCompanyIds
  8806. } else {
  8807. tmpGroupFormalCompanyIdsMap[index] = tmpFormalCompanyIds
  8808. }
  8809. }
  8810. tmpGroupActiveNumMap[index] += tmpActiveStatus
  8811. tmpGroupAllActiveNumMap[index] += tmpActiveStatus
  8812. tmpGroupNoIncrementalActiveNumMap[index] += tmpActiveStatus
  8813. tmpGroupTryStagePushMap[index] += tmpTryStagePushNum
  8814. tmpGroupTryStageFollowMap[index] += tmpTryStageFollowNum
  8815. tmpGroupTryStageReadyMap[index] += tmpTryStageReadyNum
  8816. tmpGroupTryStageInitMap[index] += tmpTryStageInitNum
  8817. // 其他客户IDs
  8818. if tmpTryOutCompanyIds != `` {
  8819. a, ok := tmpGroupTryOutCompanyIdsMap[index]
  8820. if ok {
  8821. tmpGroupTryOutCompanyIdsMap[index] = a + "," + tmpTryOutCompanyIds
  8822. } else {
  8823. tmpGroupTryOutCompanyIdsMap[index] = tmpTryOutCompanyIds
  8824. }
  8825. }
  8826. if tmpPushCompanyIds != `` {
  8827. a, ok := tmpGroupPushCompanyIdsMap[index]
  8828. if ok {
  8829. tmpGroupPushCompanyIdsMap[index] = a + "," + tmpPushCompanyIds
  8830. } else {
  8831. tmpGroupPushCompanyIdsMap[index] = tmpPushCompanyIds
  8832. }
  8833. }
  8834. if tmpFollowCompanyIds != `` {
  8835. a, ok := tmpGroupFollowCompanyIdsMap[index]
  8836. if ok {
  8837. tmpGroupFollowCompanyIdsMap[index] = a + "," + tmpFollowCompanyIds
  8838. } else {
  8839. tmpGroupFollowCompanyIdsMap[index] = tmpFollowCompanyIds
  8840. }
  8841. }
  8842. if tmpReadyCompanyIds != `` {
  8843. a, ok := tmpGroupReadyCompanyIdsMap[index]
  8844. if ok {
  8845. tmpGroupReadyCompanyIdsMap[index] = a + "," + tmpReadyCompanyIds
  8846. } else {
  8847. tmpGroupReadyCompanyIdsMap[index] = tmpReadyCompanyIds
  8848. }
  8849. }
  8850. if tmpInitCompanyIds != `` {
  8851. a, ok := tmpGroupInitCompanyIdsMap[index]
  8852. if ok {
  8853. tmpGroupInitCompanyIdsMap[index] = a + "," + tmpInitCompanyIds
  8854. } else {
  8855. tmpGroupInitCompanyIdsMap[index] = tmpInitCompanyIds
  8856. }
  8857. }
  8858. //总数据汇总
  8859. tmpAllTryOutNumMap[index] += tmpTryOutNum
  8860. tmpAllFormalNumMap[index] += tmpFormalNum
  8861. tmpAllActiveNumMap[index] += tmpActiveStatus
  8862. tmpAllAllActiveNumMap[index] += tmpAllActiveStatus
  8863. tmpAllNoIncrementalActiveNumMap[index] += tmpNoIncrementalActiveStatus
  8864. // 总数据试用标签数据汇总
  8865. tmpAllTryStagePushMap[index] += tmpTryStagePushNum
  8866. tmpAllTryStageFollowMap[index] += tmpTryStageFollowNum
  8867. tmpAllTryStageReadyMap[index] += tmpTryStageReadyNum
  8868. tmpAllTryStageInitMap[index] += tmpTryStageInitNum
  8869. }
  8870. tmpAdminReportRecord := statistic_report.CityRecord{
  8871. Name: city,
  8872. CompanyAreaNumNumList: tmpCompanyReportRecordNumList,
  8873. }
  8874. tmpGroupCityReportRecord = append(tmpGroupCityReportRecord, tmpAdminReportRecord)
  8875. }
  8876. for i := 0; i < len(tmpGroupActiveNumMap); i++ {
  8877. tmpGroupCompanyReportRecordNum := statistic_report.CompanyAreaNum{
  8878. TryOutNum: tmpGroupTryOutNumMap[i],
  8879. FormalNum: tmpGroupFormalNumMap[i],
  8880. FormalIds: tmpGroupFormalCompanyIdsMap[i],
  8881. ActiveNum: tmpGroupActiveNumMap[i],
  8882. AllActiveNum: tmpGroupAllActiveNumMap[i],
  8883. NoIncrementalActiveNum: tmpGroupNoIncrementalActiveNumMap[i],
  8884. StartDate: startDateIndexList[i],
  8885. EndDate: endDateIndexList[i],
  8886. TryStagePushNum: tmpGroupTryStagePushMap[i],
  8887. TryStageFollowNum: tmpGroupTryStageFollowMap[i],
  8888. TryStageReadyNum: tmpGroupTryStageReadyMap[i],
  8889. TryStageInitNum: tmpGroupTryStageInitMap[i],
  8890. TotalNum: tmpGroupTryOutNumMap[i] + tmpGroupFormalNumMap[i],
  8891. TryOutIds: tmpGroupTryOutCompanyIdsMap[i],
  8892. TryStagePushIds: tmpGroupPushCompanyIdsMap[i],
  8893. TryStageFollowIds: tmpGroupFollowCompanyIdsMap[i],
  8894. TryStageReadyIds: tmpGroupReadyCompanyIdsMap[i],
  8895. TryStageInitIds: tmpGroupInitCompanyIdsMap[i],
  8896. }
  8897. tmpGroupCompanyReportRecordNumList = append(tmpGroupCompanyReportRecordNumList, tmpGroupCompanyReportRecordNum)
  8898. }
  8899. groupReportRecord := statistic_report.GroupCityRecord{
  8900. Item: tmpGroupCityReportRecord,
  8901. Name: province,
  8902. CompanyAreaNumNumList: tmpGroupCompanyReportRecordNumList,
  8903. }
  8904. groupReportRecordList = append(groupReportRecordList, groupReportRecord)
  8905. }
  8906. resp.List = groupReportRecordList
  8907. br.Ret = 200
  8908. br.Success = true
  8909. br.Msg = "获取成功"
  8910. br.Data = resp
  8911. }
  8912. // CompanyTryOutDayList
  8913. // @Title 客户累计试用详情接口
  8914. // @Description 客户累计试用详情接口
  8915. // @Param CompanyId query int true "客户id"
  8916. // @Param ProductId query int true "产品id"
  8917. // @Success 200 {object} company.CompanyTryOutDayListResp
  8918. // @router /company/tryOutDayList [get]
  8919. func (this *CompanyTodoController) CompanyTryOutDayList() {
  8920. br := new(models.BaseResponse).Init()
  8921. defer func() {
  8922. this.Data["json"] = br
  8923. this.ServeJSON()
  8924. }()
  8925. companyId, _ := this.GetInt("CompanyId")
  8926. if companyId <= 0 {
  8927. br.Msg = "请选择客户"
  8928. return
  8929. }
  8930. productId, _ := this.GetInt("ProductId")
  8931. if productId <= 0 {
  8932. br.Msg = "请选择类型"
  8933. return
  8934. }
  8935. pageSize, _ := this.GetInt("PageSize")
  8936. currentIndex, _ := this.GetInt("CurrentIndex")
  8937. var startSize int
  8938. if pageSize <= 0 {
  8939. pageSize = utils.PageSize20
  8940. }
  8941. if currentIndex <= 0 {
  8942. currentIndex = 1
  8943. }
  8944. startSize = paging.StartIndex(currentIndex, pageSize)
  8945. // 获取任务信息
  8946. total, err := company.GetCompanyProductTryOutUpdateLogTotal(companyId, productId)
  8947. if err != nil {
  8948. br.Msg = "获取任务信息失败"
  8949. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  8950. return
  8951. }
  8952. // 获取任务信息
  8953. list, err := company.GetCompanyProductTryOutUpdateLogList(companyId, productId, startSize, pageSize)
  8954. if err != nil {
  8955. br.Msg = "获取任务信息失败"
  8956. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  8957. return
  8958. }
  8959. //var list []*company_todo.CompanyTodoListItem
  8960. //for _, v := range todos {
  8961. // temp := &company_todo.CompanyTodoListItem{
  8962. // CompanyTodo: v,
  8963. // }
  8964. // temp.EndTimeStr = temp.EndTime.Format(utils.FormatDate)
  8965. // if temp.EndTimeStr == "0001-01-01" {
  8966. // temp.EndTimeStr = ""
  8967. // }
  8968. // list = append(list, temp)
  8969. //}
  8970. if len(list) <= 0 {
  8971. list = make([]*company.CompanyProductTryOutUpdateLog, 0)
  8972. }
  8973. page := paging.GetPaging(currentIndex, pageSize, total)
  8974. resp := company.CompanyTryOutDayListResp{
  8975. Paging: page,
  8976. List: list,
  8977. }
  8978. br.Ret = 200
  8979. br.Success = true
  8980. br.Msg = "获取成功"
  8981. br.Data = resp
  8982. }
  8983. // @Title 获取流水信息接口
  8984. // @Description 获取流水信息接口
  8985. // @Param CompanyId query int true "客户id"
  8986. // @Success 200 {object} company.CygxActivityPointsBillListResp
  8987. // @router /company/activity/points/bill [get]
  8988. func (this *CompanyTodoController) CompanyActivityPointsBill() {
  8989. br := new(models.BaseResponse).Init()
  8990. defer func() {
  8991. this.Data["json"] = br
  8992. this.ServeJSON()
  8993. }()
  8994. companyId, _ := this.GetInt("CompanyId")
  8995. if companyId <= 0 {
  8996. br.Msg = "请选择客户"
  8997. return
  8998. }
  8999. // 获取流水信息
  9000. list, err := cygx.CygxActivityPointsBillByCompanyId(companyId)
  9001. if err != nil {
  9002. br.Msg = "获取任务信息失败"
  9003. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  9004. return
  9005. }
  9006. if len(list) <= 0 {
  9007. list = make([]*cygx.CygxActivityPointsBillResp, 0)
  9008. }
  9009. resp := cygx.CygxActivityPointsBillListResp{
  9010. List: list,
  9011. }
  9012. br.Ret = 200
  9013. br.Success = true
  9014. br.Msg = "获取成功"
  9015. br.Data = resp
  9016. }
  9017. // DelRemark
  9018. // @Title 删除备注
  9019. // @Description 删除备注
  9020. // @Param request body company.RemarkDelReq true "type json string"
  9021. // @Success 200 操作成功
  9022. // @router /remark/del [post]
  9023. func (this *CompanyController) DelRemark() {
  9024. br := new(models.BaseResponse).Init()
  9025. defer func() {
  9026. if br.ErrMsg == "" {
  9027. br.IsSendEmail = false
  9028. }
  9029. this.Data["json"] = br
  9030. this.ServeJSON()
  9031. }()
  9032. sysUser := this.SysUser
  9033. if sysUser == nil {
  9034. br.Msg = "请登录"
  9035. br.ErrMsg = "请登录,SysUser Is Empty"
  9036. br.Ret = 408
  9037. return
  9038. }
  9039. var req company.RemarkDelReq
  9040. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  9041. if err != nil {
  9042. br.Msg = "参数解析异常!"
  9043. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  9044. return
  9045. }
  9046. if req.RemarkId <= 0 {
  9047. br.Msg = "参数有误"
  9048. br.ErrMsg = "参数有误, 备注ID有误"
  9049. return
  9050. }
  9051. item, e := company.GetCompanyRemarkById(req.RemarkId)
  9052. if e != nil {
  9053. if e.Error() == utils.ErrNoRow() {
  9054. br.Msg = "备注已被删除, 请刷新页面"
  9055. return
  9056. }
  9057. br.Msg = "备注信息有误"
  9058. br.ErrMsg = "获取客户备注失败, Err: " + e.Error()
  9059. return
  9060. }
  9061. if item.SysUserId != sysUser.AdminId {
  9062. br.Msg = "仅备注添加人可删除"
  9063. return
  9064. }
  9065. product, e := company.GetCompanyProductByCompanyIdAndProductId(item.CompanyId, item.ProductId)
  9066. if e != nil {
  9067. br.Msg = "操作失败"
  9068. br.ErrMsg = "获取客户产品信息失败, Err: " + e.Error()
  9069. return
  9070. }
  9071. if e := company.DelCompanyRemark(req.RemarkId); e != nil {
  9072. br.Msg = "操作失败"
  9073. br.ErrMsg = "删除客户备注失败, Err: " + e.Error()
  9074. return
  9075. }
  9076. content := fmt.Sprintf("%s%s", "删除备注: ", item.Remark)
  9077. _ = 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)
  9078. if item.ProductId == utils.COMPANY_PRODUCT_RAI_ID {
  9079. go services.DelCompanyHistoryRemark("company_product_remark", req.RemarkId) // 删除
  9080. }
  9081. br.Ret = 200
  9082. br.Success = true
  9083. br.Msg = "操作成功"
  9084. }
  9085. // @Title 获取流水信息接口
  9086. // @Description 获取流水信息接口
  9087. // @Param CompanyId query int true "客户id"
  9088. // @Success 200 {object} company.CygxActivityPointsBillListResp
  9089. // @router /company/activity/special/points/bill [get]
  9090. func (this *CompanyTodoController) CompanyActivitySpecialPointsBill() {
  9091. br := new(models.BaseResponse).Init()
  9092. defer func() {
  9093. this.Data["json"] = br
  9094. this.ServeJSON()
  9095. }()
  9096. companyId, _ := this.GetInt("CompanyId")
  9097. if companyId <= 0 {
  9098. br.Msg = "请选择客户"
  9099. return
  9100. }
  9101. // 获取流水信息
  9102. var condition string
  9103. var pars []interface{}
  9104. condition += ` AND company_id = ? `
  9105. pars = append(pars, companyId)
  9106. //查询当年的数据
  9107. //condition += ` AND b.create_time >= ? `
  9108. //pars = append(pars, time.Now().Format(utils.FormatYearDate)+"-01-01")
  9109. list, err := cygx.GetCygxActivitySpecialTripBillDetailListAll(condition, pars)
  9110. if err != nil {
  9111. br.Msg = "获取任务信息失败"
  9112. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  9113. return
  9114. }
  9115. //userType, tripRemaining, mapChartName, err := cygxService.GetChartPermissionSpecialSurplusByCompany(companyId)
  9116. //if err != nil {
  9117. // br.Msg = "获取专项调研剩余次数失败"
  9118. // br.ErrMsg = "获取专项调研剩余次数失败,err:" + err.Error()
  9119. // return
  9120. //}
  9121. //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}
  9122. resp := new(cygx.CygxActivitySpecialPointsBillResp)
  9123. //lastTripRemaining := 0
  9124. for _, v := range list {
  9125. item := cygx.CygxActivitySpecialPointsBillRespItem{
  9126. Id: v.Id,
  9127. CreateTime: v.CreateTime.Format(utils.FormatDateTime),
  9128. CompanyId: v.CompanyId,
  9129. CompanyName: v.CompanyName,
  9130. RealName: v.RealName,
  9131. BillDetailed: v.BillDetailed,
  9132. ActivityName: v.ResearchTheme,
  9133. ChartPermissionId: v.ChartPermissionId,
  9134. ChartPermissionName: v.ChartPermissionName,
  9135. Total: v.Total,
  9136. }
  9137. if v.ActivityId == 0 {
  9138. item.Content = v.Content
  9139. } else {
  9140. if v.DoType == 1 && v.Way != 4 && v.Way != 3 {
  9141. item.Content = item.ActivityName + "--报名"
  9142. } else if v.DoType == 2 && v.Way != 4 && v.Way != 3 {
  9143. item.Content = item.ActivityName + "--取消报名"
  9144. } else if v.Way == 4 {
  9145. item.Content = item.ActivityName + "--活动取消"
  9146. }
  9147. }
  9148. //if userType == 2 {
  9149. // if i== 0 {
  9150. // item.Total += strconv.Itoa(tripRemaining) + "次"
  9151. // } else {
  9152. // item.Total += strconv.Itoa(tripRemaining-list[i-1].BillDetailed) + "次"
  9153. // }
  9154. // //if v.BillDetailed < 4 {
  9155. // // item.Total += strconv.Itoa(lastTripRemaining-list[i-1].BillDetailed) + "次"
  9156. // //} else {
  9157. // // item.Total += strconv.Itoa(lastTripRemaining) + "次"
  9158. // //}
  9159. //} else {
  9160. // for k, num := range mapChartName {
  9161. // if i== 0 {
  9162. // item.Total += k + strconv.Itoa(num) + "次+"
  9163. // } else {
  9164. // if list[i-1].ActivityId == 0 {
  9165. // item.Total += k + strconv.Itoa(num) + "次+"
  9166. // } else {
  9167. // item.Total += k + strconv.Itoa(num-list[i-1].BillDetailed) + "次+"
  9168. // }
  9169. // }
  9170. // //if num > 0 {
  9171. // // if i== 0{
  9172. // // item.Total += k + strconv.Itoa(num) + "次+"
  9173. // // } else {
  9174. // // item.Total += k + strconv.Itoa(num-v.BillDetailed) + "次+"
  9175. // // }
  9176. // //}
  9177. // }
  9178. // item.Total = strings.TrimRight(item.Total, "+")
  9179. //}
  9180. resp.List = append(resp.List, &item)
  9181. }
  9182. br.Ret = 200
  9183. br.Success = true
  9184. br.Msg = "获取成功"
  9185. br.Data = resp
  9186. }