company.go 318 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701
  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. companyProductId, err := company.AddCompanyProduct(companyProduct)
  2839. if err != nil {
  2840. br.Msg = "新增失败"
  2841. br.ErrMsg = "新增客户产品失败,err:" + err.Error()
  2842. return
  2843. }
  2844. companyReportPermissionList, err := services.AddCompanyPermission(int(companyId), seller.AdminId, productId, productName, seller.RealName, req.PermissionIds, startDate, endDate)
  2845. if err != nil {
  2846. br.Msg = "新增失败"
  2847. br.ErrMsg = "新增客户设置权限失败,err:" + err.Error()
  2848. return
  2849. }
  2850. {
  2851. record := new(company.CompanyOperationRecord)
  2852. record.CompanyId = int(companyId)
  2853. record.CompanyName = req.CompanyName
  2854. record.SellerId = seller.AdminId
  2855. record.SysUserId = seller.AdminId
  2856. record.SysRealName = seller.RealName
  2857. record.Remark = "新增客户"
  2858. record.Operation = "add"
  2859. record.CreateTime = time.Now()
  2860. record.ProductId = productId
  2861. record.ProductName = productName
  2862. record.Status = req.Status
  2863. _, err = company.AddCompanyOperationRecord(record)
  2864. if err != nil {
  2865. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  2866. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  2867. }
  2868. }
  2869. //新增客户日志
  2870. {
  2871. companyLog := new(company.CompanyLog)
  2872. companyLog.CompanyId = int(companyId)
  2873. companyLog.CompanyName = req.CompanyName
  2874. companyLog.CreditCode = req.CreditCode
  2875. companyLog.CompanyCode = companyCode
  2876. companyLog.Sort = item.Sort
  2877. companyLog.IsFeeCustomer = item.IsFeeCustomer
  2878. companyLog.Country = item.Country
  2879. companyLog.Address = item.Address
  2880. companyLog.City = item.City
  2881. companyLog.Province = item.Province
  2882. companyLog.Enabled = item.Enabled
  2883. companyLog.CreatedTime = item.CreatedTime
  2884. companyLog.LastUpdatedTime = item.LastUpdatedTime
  2885. companyLog.Seller = item.Seller
  2886. companyLog.SellsId = item.SellsId
  2887. companyLog.CompanyBelong = item.CompanyBelong
  2888. companyLog.StartDate = item.StartDate
  2889. companyLog.EndDate = item.EndDate
  2890. companyLog.FirstStartDate = item.FirstStartDate
  2891. companyLog.FirstEndDate = item.FirstEndDate
  2892. companyLog.DateType = item.DateType
  2893. companyLog.AdminId = this.SysUser.AdminId
  2894. companyLog.LogType = "add"
  2895. companyLog.LogCreateTime = time.Now()
  2896. go company.AddCompanyLog(companyLog)
  2897. }
  2898. //新增客户产品日志
  2899. {
  2900. productLog := new(company.CompanyProductLog)
  2901. productLog.CompanyProductId = int(companyProductId)
  2902. productLog.CompanyId = companyProduct.CompanyId
  2903. productLog.ProductId = companyProduct.ProductId
  2904. productLog.ProductName = companyProduct.ProductName
  2905. productLog.CompanyName = companyProduct.CompanyName
  2906. productLog.CompanyName = companyProduct.CompanyName
  2907. productLog.Source = companyProduct.Source
  2908. productLog.Reasons = companyProduct.Reasons
  2909. productLog.Status = companyProduct.Status
  2910. productLog.IndustryId = companyProduct.IndustryId
  2911. productLog.IndustryName = companyProduct.IndustryName
  2912. productLog.SellerId = companyProduct.SellerId
  2913. productLog.SellerName = companyProduct.SellerName
  2914. productLog.GroupId = companyProduct.GroupId
  2915. productLog.DepartmentId = companyProduct.DepartmentId
  2916. productLog.IsSuspend = companyProduct.IsSuspend
  2917. productLog.SuspendTime = companyProduct.SuspendTime
  2918. productLog.ApproveStatus = companyProduct.ApproveStatus
  2919. productLog.FreezeTime = companyProduct.FreezeTime
  2920. productLog.Remark = companyProduct.Remark
  2921. productLog.StartDate = companyProduct.StartDate
  2922. productLog.EndDate = companyProduct.EndDate
  2923. productLog.CreateTime = companyProduct.CreateTime
  2924. productLog.ModifyTime = companyProduct.ModifyTime
  2925. productLog.LoseReason = companyProduct.LoseReason
  2926. productLog.LossTime = companyProduct.LossTime
  2927. productLog.LogType = "add"
  2928. productLog.LogCreateTime = time.Now()
  2929. productLog.AdminId = this.SysUser.AdminId
  2930. productLog.Scale = companyProduct.Scale
  2931. go company.AddCompanyProductLog(productLog)
  2932. }
  2933. //新增客户产品状态变更日志
  2934. {
  2935. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  2936. Id: 0,
  2937. CompanyId: companyProduct.CompanyId,
  2938. ProductId: companyProduct.ProductId,
  2939. Status: "试用",
  2940. Source: "add",
  2941. SellerId: companyProduct.SellerId,
  2942. SellerName: companyProduct.SellerName,
  2943. StartDate: startDateTime,
  2944. EndDate: endDateTime,
  2945. RealEndDate: startDateTime,
  2946. CreateTime: time.Now(),
  2947. }
  2948. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  2949. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  2950. Id: 0,
  2951. CompanyId: companyProduct.CompanyId,
  2952. ProductId: companyProduct.ProductId,
  2953. Source: "add",
  2954. SellerId: companyProduct.SellerId,
  2955. SellerName: companyProduct.SellerName,
  2956. StartDate: startDateTime,
  2957. EndDate: endDateTime,
  2958. RealEndDate: startDateTime,
  2959. IsStop: 0,
  2960. CreateTime: time.Now(),
  2961. }
  2962. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  2963. }
  2964. resp := new(company.CompanyAddResp)
  2965. resp.CompanyId = int(companyId)
  2966. br.Ret = 200
  2967. br.Success = true
  2968. br.Msg = "新增成功"
  2969. br.Data = resp
  2970. }
  2971. // Detail
  2972. // @Title 获取客户详情
  2973. // @Description 获取客户详情接口
  2974. // @Param CompanyId query int true "客户id"
  2975. // @Success 200 {object} company.CompanyDetailResp
  2976. // @router /detail [get]
  2977. func (this *CompanyController) Detail() {
  2978. br := new(models.BaseResponse).Init()
  2979. defer func() {
  2980. this.Data["json"] = br
  2981. this.ServeJSON()
  2982. }()
  2983. sysUser := this.SysUser
  2984. if sysUser == nil {
  2985. br.Msg = "请登录"
  2986. br.ErrMsg = "请登录,SysUser Is Empty"
  2987. br.Ret = 408
  2988. return
  2989. }
  2990. companyId, _ := this.GetInt("CompanyId")
  2991. if companyId <= 0 {
  2992. br.Msg = "参数错误"
  2993. br.ErrMsg = "客户参数小于等于0"
  2994. return
  2995. }
  2996. // CRM8.8-是否为编辑页的客户详情
  2997. isEdit, _ := this.GetBool("IsEdit")
  2998. productId := services.GetProductId(sysUser.RoleTypeCode)
  2999. item, err := company.GetCompanyDetailById(companyId)
  3000. if err != nil {
  3001. br.Msg = "获取信息失败"
  3002. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  3003. return
  3004. }
  3005. shareSellerId := 0
  3006. shareGroupId := 0
  3007. var productItem *company.CompanyProduct
  3008. if productId > 0 {
  3009. var e error
  3010. productItem, e = company.GetCompanyProductByCompanyIdAndProductId(companyId, productId)
  3011. if e != nil && e.Error() != utils.ErrNoRow() {
  3012. br.Msg = "客户信息有误"
  3013. br.ErrMsg = "获取客户信息失败, Err: " + e.Error()
  3014. return
  3015. }
  3016. if productItem != nil {
  3017. shareSellerId = productItem.ShareSellerId
  3018. shareGroupId = productItem.ShareGroupId
  3019. }
  3020. }
  3021. var productName string
  3022. if productId == 1 {
  3023. productName = utils.COMPANY_PRODUCT_FICC_NAME
  3024. } else if productId == 2 {
  3025. productName = utils.COMPANY_PRODUCT_RAI_NAME
  3026. } else {
  3027. productName = "admin"
  3028. }
  3029. resp := new(company.CompanyDetailResp)
  3030. resp.ProductName = productName
  3031. //获取客户产品
  3032. productList, err := company.GetCompanyProductsByCompanyId(companyId)
  3033. if err != nil {
  3034. br.Msg = "获取信息失败"
  3035. br.ErrMsg = "获取产品信息失败,Err:" + err.Error()
  3036. return
  3037. }
  3038. roleTypeCode := sysUser.RoleTypeCode
  3039. itemLen := len(productList)
  3040. btnDetailItem := new(company.ButtonDetailPermission)
  3041. // 客户权限校验
  3042. {
  3043. // 如果不是超管、ficc管理员、权益管理员,那么需要额外校验下权限
  3044. if !utils.InArrayByStr([]string{utils.ROLE_TYPE_CODE_ADMIN, utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_RAI_ADMIN}, sysUser.RoleTypeCode) {
  3045. var isOk bool //是否有权限
  3046. var companyHasProduct bool // 客户当前是否有该产品权限
  3047. for _, productInfo := range productList {
  3048. // 只校验拥有的品种权限:ficc或者权益
  3049. if productInfo.ProductId == productId {
  3050. companyHasProduct = true
  3051. // 自己的客户有权限看
  3052. if productInfo.SellerId == sysUser.AdminId {
  3053. isOk = true
  3054. break
  3055. }
  3056. // 流失客户都有权限看
  3057. if productInfo.Status == utils.COMPANY_STATUS_LOSE || productInfo.Status == utils.COMPANY_STATUS_CLOSE {
  3058. isOk = true
  3059. break
  3060. }
  3061. // 分享的客户 也有权限
  3062. if productItem.IsShare == 1 && productItem.ShareSellerId == sysUser.AdminId {
  3063. isOk = true
  3064. break
  3065. }
  3066. // 分享的客户的组长 也有权限
  3067. if productItem.IsShare == 1 && productItem.ShareGroupId == sysUser.GroupId {
  3068. isOk = true
  3069. break
  3070. }
  3071. // 如果是组长,且该客户属于本组客户
  3072. if sysUser.Authority == 4 && productInfo.GroupId > 0 && productInfo.GroupId == sysUser.GroupId && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM {
  3073. isOk = true
  3074. break
  3075. }
  3076. // 如果是ficc主管或者权益主管
  3077. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  3078. // 获取顶级分组Id
  3079. var sysUserGroupPid, productGroupPid int
  3080. // 当前账号的顶级分组id
  3081. {
  3082. sysUserGroupIdpid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  3083. if err != nil && err.Error() != utils.NotEmpty() {
  3084. break
  3085. }
  3086. if sysUserGroupIdpid == nil || *sysUserGroupIdpid == 0 {
  3087. sysUserGroupPid = sysUser.GroupId
  3088. } else {
  3089. sysUserGroupPid = *sysUserGroupIdpid
  3090. }
  3091. }
  3092. // 当前客户的顶级分组id
  3093. {
  3094. groupIdpid, err := company.GetParentIdFromGroup(productInfo.GroupId)
  3095. if err != nil && err.Error() != utils.NotEmpty() {
  3096. break
  3097. }
  3098. if groupIdpid == nil || *groupIdpid == 0 {
  3099. productGroupPid = productInfo.GroupId
  3100. } else {
  3101. productGroupPid = *groupIdpid
  3102. }
  3103. }
  3104. // 如果客户的顶级分组和当前账号分组id一致
  3105. if sysUserGroupPid == productGroupPid {
  3106. isOk = true
  3107. break
  3108. }
  3109. }
  3110. }
  3111. }
  3112. // 客户当前是否有该产品的权限,如果没有的话,说明是在领取客户,允许访问
  3113. if !companyHasProduct {
  3114. isOk = true
  3115. }
  3116. if !isOk {
  3117. br.Msg = "无访问权限"
  3118. return
  3119. }
  3120. }
  3121. }
  3122. //产品权限map
  3123. statusMap := make(map[int]string)
  3124. for i := 0; i < itemLen; i++ {
  3125. item := productList[i]
  3126. //添加产品权限map
  3127. statusMap[item.ProductId] = item.Status
  3128. if i == 0 {
  3129. if item.ProductId == 1 {
  3130. resp.CreateAuth = 1
  3131. } else {
  3132. resp.CreateAuth = 2
  3133. }
  3134. }
  3135. if item.ProductId == 1 {
  3136. if strings.Contains(sysUser.RoleTypeCode, "ficc") {
  3137. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  3138. btnDetailItem.BtnHistoryList = true
  3139. } else {
  3140. if item.SellerId == sysUser.AdminId || shareSellerId == sysUser.AdminId || shareGroupId == sysUser.GroupId {
  3141. btnDetailItem.BtnHistoryList = true
  3142. }
  3143. if sysUser.Authority > 0 {
  3144. if item.GroupId == sysUser.GroupId {
  3145. btnDetailItem.BtnHistoryList = true
  3146. }
  3147. if item.DepartmentId == sysUser.DepartmentId {
  3148. btnDetailItem.BtnHistoryList = true
  3149. }
  3150. }
  3151. }
  3152. }
  3153. // 编辑回显
  3154. allPermissions, e := company.GetPermissionLookItemsByProductId(utils.COMPANY_PRODUCT_FICC_ID)
  3155. if e != nil {
  3156. br.Msg = "获取失败"
  3157. br.ErrMsg = "获取权限信息失败,Err:" + e.Error()
  3158. return
  3159. }
  3160. permissionMap := make(map[int][]*company.PermissionLookItem, 0)
  3161. permissionCheckMap := make(map[int][]int, 0)
  3162. for _, v := range allPermissions {
  3163. if v.ParentId > 0 {
  3164. permissionMap[v.ParentId] = append(permissionMap[v.ParentId], v)
  3165. if v.IsPublic == 1 {
  3166. permissionCheckMap[v.ParentId] = append(permissionCheckMap[v.ParentId], v.ChartPermissionId)
  3167. }
  3168. }
  3169. }
  3170. for _, v := range allPermissions {
  3171. if v.ParentId == 0 {
  3172. checkList := make([]int, 0)
  3173. plist := new(company.PermissionLookList)
  3174. plist.Items = make([]*company.PermissionLookItem, 0)
  3175. plist.ItemsType = make([]*company.PermissionSetItemType, 0)
  3176. items, ok := permissionMap[v.ChartPermissionId]
  3177. if ok {
  3178. for itemK, n := range items {
  3179. permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  3180. if err != nil && err.Error() != utils.ErrNoRow() {
  3181. br.Msg = "获取失败"
  3182. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3183. return
  3184. }
  3185. if permission != nil && permission.ChartPermissionId > 0 {
  3186. checkList = append(checkList, n.ChartPermissionId)
  3187. items[itemK].StartDate = permission.StartDate
  3188. items[itemK].EndDate = permission.EndDate
  3189. items[itemK].Status = permission.Status
  3190. endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
  3191. endDateTime = endDateTime.AddDate(0, 0, 1)
  3192. sub := endDateTime.Sub(time.Now())
  3193. if sub < 0 {
  3194. sub = 0
  3195. }
  3196. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  3197. items[itemK].ExpireDay = expireDay
  3198. }
  3199. }
  3200. plist.Items = items
  3201. }
  3202. plist.ClassifyName = v.PermissionName
  3203. plist.CheckList = checkList
  3204. item.PermissionList = append(item.PermissionList, plist)
  3205. }
  3206. }
  3207. resp.FiccItem = item
  3208. if resp.FiccItem.Status == utils.COMPANY_STATUS_FOREVER {
  3209. resp.FiccItem.Status = utils.COMPANY_STATUS_X_CLASS_TRY_OUT
  3210. }
  3211. if (roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  3212. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT) &&
  3213. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3214. resp.IsButtonShow = 1
  3215. }
  3216. } else {
  3217. if strings.Contains(sysUser.RoleTypeCode, "rai") {
  3218. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  3219. btnDetailItem.BtnHistoryList = true
  3220. } else {
  3221. if item.SellerId == sysUser.AdminId || item.ShareSellerId == sysUser.AdminId || shareGroupId == sysUser.GroupId {
  3222. btnDetailItem.BtnHistoryList = true
  3223. }
  3224. if sysUser.Authority > 0 {
  3225. if item.GroupId == sysUser.GroupId {
  3226. btnDetailItem.BtnHistoryList = true
  3227. }
  3228. if item.DepartmentId == sysUser.DepartmentId {
  3229. btnDetailItem.BtnHistoryList = true
  3230. }
  3231. }
  3232. }
  3233. }
  3234. // CRM8.8-权益权限列表调用较多、统一进行调整
  3235. plist, e := services.RaiCompanyPermissionAndCheckList(companyId, isEdit, []string{"调研"})
  3236. if e != nil {
  3237. br.Msg = "获取客户权益权限列表信息失败"
  3238. br.ErrMsg = "获取客户权益权限列表信息失败,Err:" + e.Error()
  3239. return
  3240. }
  3241. // cygx8.2专项产业调研展示
  3242. item.SpecialSurplus, err = cygxService.GetSpecialSurplusByCompanyNew(companyId)
  3243. if err != nil {
  3244. br.Msg = "获取失败"
  3245. br.ErrMsg = "获取专项调研信息失败,Err:" + err.Error()
  3246. return
  3247. }
  3248. //研选服务点数
  3249. item.Points = cygxService.GetCygxActivityPointsCompanyByCompanyId(companyId)
  3250. item.PermissionList = append(item.PermissionList, plist)
  3251. resp.RaiItem = item
  3252. if resp.RaiItem.Status == utils.COMPANY_STATUS_FOREVER {
  3253. resp.RaiItem.Status = utils.COMPANY_STATUS_X_CLASS_TRY_OUT
  3254. }
  3255. if (roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  3256. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  3257. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT) &&
  3258. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3259. resp.IsButtonShow = 1
  3260. }
  3261. }
  3262. 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, "")
  3263. //if itemLen > 1 {
  3264. // btnDetailItem.BtnEdit = false
  3265. // btnDetailItem.BtnDelete = false
  3266. //} else {
  3267. // btnDetailItem.BtnEdit = btnItem.BtnEdit
  3268. // btnDetailItem.BtnDelete = btnItem.BtnDelete
  3269. //}
  3270. switch item.ProductId {
  3271. case 1:
  3272. btnDetailItem.FiccEdit = btnItem.BtnEdit
  3273. btnDetailItem.FiccDelete = btnItem.BtnDelete
  3274. case 2:
  3275. btnDetailItem.RaiEdit = btnItem.BtnEdit
  3276. btnDetailItem.RaiDelete = btnItem.BtnDelete
  3277. }
  3278. if !btnDetailItem.BtnEdit {
  3279. btnDetailItem.BtnEdit = btnItem.BtnEdit
  3280. }
  3281. if !btnDetailItem.BtnDelete {
  3282. btnDetailItem.BtnDelete = btnItem.BtnDelete
  3283. }
  3284. //联系人操作权限
  3285. if resp.IsContractButtonShow == false {
  3286. resp.IsContractButtonShow = services.CheckCompanyUserButton(sysUser.RoleTypeCode, item.SellerId, sysUser.AdminId, item.ProductId, shareSellerId, item.Status)
  3287. }
  3288. //校验当前操作员是否具给联系人开通个人研选的权限
  3289. if resp.IsUserYanXuanButtonShow == false {
  3290. resp.IsUserYanXuanButtonShow, err = services.CheckCompanyUserYanXuanButton(sysUser.RoleTypeCode, sysUser.Mobile)
  3291. if err != nil {
  3292. br.Msg = "获取失败"
  3293. br.ErrMsg = "获取专项调研信息失败,Err:" + err.Error()
  3294. return
  3295. }
  3296. }
  3297. }
  3298. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  3299. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  3300. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  3301. resp.IsButtonShow = 1
  3302. btnDetailItem.BtnHistoryList = true
  3303. }
  3304. //ficc权限
  3305. if ficcStatus, ok := statusMap[1]; ok {
  3306. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT {
  3307. if raiStatus, ok := statusMap[2]; ok {
  3308. //另一个权限也是 试用 、冻结、流失
  3309. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3310. //那么超管、部门管理员、销售可以编辑
  3311. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3312. btnDetailItem.BaseInfoEdit = true
  3313. }
  3314. }
  3315. //权益是永续时,超管可编辑基础信息
  3316. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3317. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3318. btnDetailItem.BaseInfoEdit = true
  3319. }
  3320. }
  3321. } else {
  3322. //权限未开,有编辑基础信息权限
  3323. btnDetailItem.BaseInfoEdit = true
  3324. }
  3325. }
  3326. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3327. if raiStatus, ok := statusMap[2]; ok {
  3328. //另一个权限也是 永续 、冻结、流失
  3329. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FOREVER || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3330. //超管可编辑基础信息
  3331. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3332. btnDetailItem.BaseInfoEdit = true
  3333. }
  3334. }
  3335. } else {
  3336. //权限未开,有编辑基础信息权限
  3337. btnDetailItem.BaseInfoEdit = true
  3338. }
  3339. }
  3340. }
  3341. //权益销售
  3342. if raiStatus, ok := statusMap[2]; ok {
  3343. if raiStatus == utils.COMPANY_STATUS_TRY_OUT {
  3344. if ficcStatus, ok := statusMap[1]; ok {
  3345. //另一个权限也是 试用 、冻结、流失
  3346. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3347. //那么超管、部门管理员、销售可以编辑
  3348. if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3349. btnDetailItem.BaseInfoEdit = true
  3350. }
  3351. }
  3352. //ficc是永续时,超管可编辑基础信息
  3353. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3354. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3355. btnDetailItem.BaseInfoEdit = true
  3356. }
  3357. }
  3358. } else {
  3359. //权限未开,有编辑基础信息权限
  3360. btnDetailItem.BaseInfoEdit = true
  3361. }
  3362. }
  3363. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3364. if ficcStatus, ok := statusMap[1]; ok {
  3365. //另一个权限也是 试用、永续 、冻结、流失
  3366. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FOREVER || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3367. //超管可编辑基础信息
  3368. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3369. btnDetailItem.BaseInfoEdit = true
  3370. }
  3371. }
  3372. } else {
  3373. //权限未开,有编辑基础信息权限
  3374. btnDetailItem.BaseInfoEdit = true
  3375. }
  3376. }
  3377. }
  3378. // 白嫖客户标记
  3379. scroungeList, err := company.GetScroungeCompany()
  3380. if err != nil {
  3381. br.Msg = "获取失败"
  3382. br.ErrMsg = "获取白嫖客户信息失败,Err:" + err.Error()
  3383. return
  3384. }
  3385. scroungeMap := make(map[int]int)
  3386. for _, v := range scroungeList {
  3387. scroungeMap[v.CompanyId] = 1
  3388. }
  3389. if _, ok := scroungeMap[item.CompanyId]; ok {
  3390. item.IsScrounge = 1
  3391. }
  3392. resp.Item = item
  3393. resp.BtnItem = btnDetailItem
  3394. br.Ret = 200
  3395. br.Success = true
  3396. br.Msg = "获取成功"
  3397. br.Data = resp
  3398. }
  3399. // DetailByCreditCode
  3400. // @Title 根据社会信用码获取客户详情
  3401. // @Description 根据社会信用码获取客户详情接口
  3402. // @Param CreditCode query string true "客户社会信用码"
  3403. // @Success 200 {object} company.CompanyDetailResp
  3404. // @router /detail_by_credit_code [get]
  3405. func (this *CompanyController) DetailByCreditCode() {
  3406. br := new(models.BaseResponse).Init()
  3407. defer func() {
  3408. this.Data["json"] = br
  3409. this.ServeJSON()
  3410. }()
  3411. sysUser := this.SysUser
  3412. if sysUser == nil {
  3413. br.Msg = "请登录"
  3414. br.ErrMsg = "请登录,SysUser Is Empty"
  3415. br.Ret = 408
  3416. return
  3417. }
  3418. resp := new(company.CompanyDetailResp)
  3419. creditCode := this.GetString("CreditCode")
  3420. if creditCode == "" {
  3421. br.Msg = "参数错误"
  3422. br.ErrMsg = "社会信用码必传"
  3423. return
  3424. }
  3425. item, err := company.GetCompanyDetailByCreditCode(creditCode)
  3426. if err != nil {
  3427. br.Ret = 200
  3428. br.Success = true
  3429. br.Msg = "获取成功"
  3430. br.Data = resp
  3431. return
  3432. }
  3433. companyId := item.CompanyId
  3434. var productName string
  3435. productId := services.GetProductId(sysUser.RoleTypeCode)
  3436. if productId == 1 {
  3437. productName = utils.COMPANY_PRODUCT_FICC_NAME
  3438. } else if productId == 2 {
  3439. productName = utils.COMPANY_PRODUCT_RAI_NAME
  3440. } else {
  3441. productName = "admin"
  3442. }
  3443. resp.ProductName = productName
  3444. //获取客户产品
  3445. productList, err := company.GetCompanyProductsByCompanyId(companyId)
  3446. if err != nil {
  3447. br.Msg = "获取信息失败"
  3448. br.ErrMsg = "获取产品信息失败,Err:" + err.Error()
  3449. return
  3450. }
  3451. roleTypeCode := sysUser.RoleTypeCode
  3452. itemLen := len(productList)
  3453. btnDetailItem := new(company.ButtonDetailPermission)
  3454. //产品权限map
  3455. statusMap := make(map[int]string)
  3456. for i := 0; i < itemLen; i++ {
  3457. item := productList[i]
  3458. //添加产品权限map
  3459. statusMap[item.ProductId] = item.Status
  3460. if i == 0 {
  3461. if item.ProductId == 1 {
  3462. resp.CreateAuth = 1
  3463. } else {
  3464. resp.CreateAuth = 2
  3465. }
  3466. }
  3467. if item.ProductId == 1 {
  3468. if strings.Contains(sysUser.RoleTypeCode, "ficc") {
  3469. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  3470. btnDetailItem.BtnHistoryList = true
  3471. } else {
  3472. if item.SellerId == sysUser.AdminId {
  3473. btnDetailItem.BtnHistoryList = true
  3474. }
  3475. if sysUser.Authority > 0 {
  3476. if item.GroupId == sysUser.GroupId {
  3477. btnDetailItem.BtnHistoryList = true
  3478. }
  3479. if item.DepartmentId == sysUser.DepartmentId {
  3480. btnDetailItem.BtnHistoryList = true
  3481. }
  3482. }
  3483. }
  3484. }
  3485. //子权限切片集合
  3486. allFiccPermissions, permissionMap, e := services.GetBasePermissionLookItem(utils.COMPANY_PRODUCT_FICC_ID)
  3487. if e != nil {
  3488. br.Msg = "查询基础权限失败"
  3489. br.ErrMsg = "查询基础权限失败,Err:" + e.Error()
  3490. return
  3491. }
  3492. //遍历获取
  3493. for _, v := range allFiccPermissions {
  3494. if v.ParentId == 0 {
  3495. checkList := make([]int, 0)
  3496. plist := new(company.PermissionLookList)
  3497. plist.Items = make([]*company.PermissionLookItem, 0)
  3498. items, ok1 := permissionMap[v.ChartPermissionId]
  3499. if ok1 {
  3500. for itemK, n := range items {
  3501. permission, e := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  3502. if e != nil && e.Error() != utils.ErrNoRow() {
  3503. br.Msg = "获取失败"
  3504. br.ErrMsg = "获取权限信息失败,Err:" + e.Error()
  3505. return
  3506. }
  3507. if permission != nil && permission.ChartPermissionId > 0 {
  3508. checkList = append(checkList, n.ChartPermissionId)
  3509. items[itemK].StartDate = permission.StartDate
  3510. items[itemK].EndDate = permission.EndDate
  3511. items[itemK].Status = permission.Status
  3512. endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
  3513. endDateTime = endDateTime.AddDate(0, 0, 1)
  3514. sub := endDateTime.Sub(time.Now())
  3515. if sub < 0 {
  3516. sub = 0
  3517. }
  3518. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  3519. items[itemK].ExpireDay = expireDay
  3520. }
  3521. }
  3522. plist.Items = items
  3523. }
  3524. plist.ClassifyName = v.PermissionName
  3525. plist.CheckList = checkList
  3526. item.PermissionList = append(item.PermissionList, plist)
  3527. }
  3528. }
  3529. resp.FiccItem = item
  3530. if (roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  3531. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT) &&
  3532. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3533. resp.IsButtonShow = 1
  3534. }
  3535. } else {
  3536. if strings.Contains(sysUser.RoleTypeCode, "rai") {
  3537. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  3538. btnDetailItem.BtnHistoryList = true
  3539. } else {
  3540. if item.SellerId == sysUser.AdminId {
  3541. btnDetailItem.BtnHistoryList = true
  3542. }
  3543. if sysUser.Authority > 0 {
  3544. if item.GroupId == sysUser.GroupId {
  3545. btnDetailItem.BtnHistoryList = true
  3546. }
  3547. if item.DepartmentId == sysUser.DepartmentId {
  3548. btnDetailItem.BtnHistoryList = true
  3549. }
  3550. }
  3551. }
  3552. }
  3553. classifyName := "权益"
  3554. checkList := make([]int, 0)
  3555. plist := new(company.PermissionLookList)
  3556. items, err := company.GetPermissionLookItems(item.ProductId, classifyName)
  3557. if err != nil {
  3558. br.Msg = "获取失败"
  3559. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3560. return
  3561. }
  3562. for itemK, n := range items {
  3563. permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  3564. if err != nil && err.Error() != utils.ErrNoRow() {
  3565. br.Msg = "获取失败"
  3566. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3567. return
  3568. }
  3569. if permission != nil && permission.ChartPermissionId > 0 {
  3570. checkList = append(checkList, n.ChartPermissionId)
  3571. items[itemK].StartDate = permission.StartDate
  3572. items[itemK].EndDate = permission.EndDate
  3573. items[itemK].Status = permission.Status
  3574. endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
  3575. endDateTime = endDateTime.AddDate(0, 0, 1)
  3576. sub := endDateTime.Sub(time.Now())
  3577. if sub < 0 {
  3578. sub = 0
  3579. }
  3580. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  3581. items[itemK].ExpireDay = expireDay
  3582. }
  3583. //count, err := company.GetCompanyPermissionCheck(companyId, n.ChartPermissionId)
  3584. //if err != nil {
  3585. // br.Msg = "获取失败"
  3586. // br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3587. // return
  3588. //}
  3589. //if count > 0 {
  3590. // checkList = append(checkList, n.ChartPermissionId)
  3591. //}
  3592. }
  3593. item.SpecialSurplus, err = cygxService.GetSpecialSurplusByCompanyNew(companyId)
  3594. if err != nil {
  3595. br.Msg = "获取失败"
  3596. br.ErrMsg = "获取专项调研信息失败,Err:" + err.Error()
  3597. return
  3598. }
  3599. plist.Items = items
  3600. plist.ClassifyName = classifyName
  3601. plist.CheckList = checkList
  3602. item.PermissionList = append(item.PermissionList, plist)
  3603. resp.RaiItem = item
  3604. if (roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  3605. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  3606. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT) &&
  3607. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3608. resp.IsButtonShow = 1
  3609. }
  3610. }
  3611. btnItem := services.GetCompanyPermissionButton(roleTypeCode, item.Status, strconv.Itoa(item.SellerId), strconv.Itoa(item.GroupId),
  3612. item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, item.ShareSellerId, "")
  3613. //if itemLen > 1 {
  3614. // btnDetailItem.BtnEdit = false
  3615. // btnDetailItem.BtnDelete = false
  3616. //} else {
  3617. // btnDetailItem.BtnEdit = btnItem.BtnEdit
  3618. // btnDetailItem.BtnDelete = btnItem.BtnDelete
  3619. //}
  3620. switch item.ProductId {
  3621. case 1:
  3622. btnDetailItem.FiccEdit = btnItem.BtnEdit
  3623. btnDetailItem.FiccDelete = btnItem.BtnDelete
  3624. case 2:
  3625. btnDetailItem.RaiEdit = btnItem.BtnEdit
  3626. btnDetailItem.RaiDelete = btnItem.BtnDelete
  3627. }
  3628. if !btnDetailItem.BtnEdit {
  3629. btnDetailItem.BtnEdit = btnItem.BtnEdit
  3630. }
  3631. if !btnDetailItem.BtnDelete {
  3632. btnDetailItem.BtnDelete = btnItem.BtnDelete
  3633. }
  3634. //联系人操作权限
  3635. if resp.IsContractButtonShow == false {
  3636. resp.IsContractButtonShow = services.CheckCompanyUserButton(sysUser.RoleTypeCode, item.SellerId, sysUser.AdminId, item.ProductId, item.ShareSellerId, item.Status)
  3637. }
  3638. }
  3639. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  3640. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  3641. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  3642. resp.IsButtonShow = 1
  3643. btnDetailItem.BtnHistoryList = true
  3644. }
  3645. //ficc权限
  3646. if ficcStatus, ok := statusMap[1]; ok {
  3647. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT {
  3648. if raiStatus, ok := statusMap[2]; ok {
  3649. //另一个权限也是 试用 、冻结、流失
  3650. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3651. //那么超管、部门管理员、销售可以编辑
  3652. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3653. btnDetailItem.BaseInfoEdit = true
  3654. }
  3655. }
  3656. //权益是永续时,超管可编辑基础信息
  3657. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3658. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3659. btnDetailItem.BaseInfoEdit = true
  3660. }
  3661. }
  3662. } else {
  3663. //权限未开,有编辑基础信息权限
  3664. btnDetailItem.BaseInfoEdit = true
  3665. }
  3666. }
  3667. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3668. if raiStatus, ok := statusMap[2]; ok {
  3669. //另一个权限也是 永续 、冻结、流失
  3670. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FOREVER || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3671. //超管可编辑基础信息
  3672. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3673. btnDetailItem.BaseInfoEdit = true
  3674. }
  3675. }
  3676. } else {
  3677. //权限未开,有编辑基础信息权限
  3678. btnDetailItem.BaseInfoEdit = true
  3679. }
  3680. }
  3681. }
  3682. //权益销售
  3683. if raiStatus, ok := statusMap[2]; ok {
  3684. if raiStatus == utils.COMPANY_STATUS_TRY_OUT {
  3685. if ficcStatus, ok := statusMap[1]; ok {
  3686. //另一个权限也是 试用 、冻结、流失
  3687. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3688. //那么超管、部门管理员、销售可以编辑
  3689. if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3690. btnDetailItem.BaseInfoEdit = true
  3691. }
  3692. }
  3693. //ficc是永续时,超管可编辑基础信息
  3694. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3695. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3696. btnDetailItem.BaseInfoEdit = true
  3697. }
  3698. }
  3699. } else {
  3700. //权限未开,有编辑基础信息权限
  3701. btnDetailItem.BaseInfoEdit = true
  3702. }
  3703. }
  3704. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3705. if ficcStatus, ok := statusMap[1]; ok {
  3706. //另一个权限也是 试用、永续 、冻结、流失
  3707. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FOREVER || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3708. //超管可编辑基础信息
  3709. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3710. btnDetailItem.BaseInfoEdit = true
  3711. }
  3712. }
  3713. } else {
  3714. //权限未开,有编辑基础信息权限
  3715. btnDetailItem.BaseInfoEdit = true
  3716. }
  3717. }
  3718. }
  3719. resp.Item = item
  3720. resp.BtnItem = btnDetailItem
  3721. br.Ret = 200
  3722. br.Success = true
  3723. br.Msg = "获取成功"
  3724. br.Data = resp
  3725. }
  3726. // @Title 编辑客户
  3727. // @Description 编辑客户接口
  3728. // @Param request body company.CompanyEditReq true "type json string"
  3729. // @Success Ret=200 保存成功
  3730. // @router /edit [post]
  3731. func (this *CompanyController) Edit() {
  3732. br := new(models.BaseResponse).Init()
  3733. defer func() {
  3734. this.Data["json"] = br
  3735. this.ServeJSON()
  3736. }()
  3737. sysUser := this.SysUser
  3738. if sysUser == nil {
  3739. br.Msg = "请登录"
  3740. br.ErrMsg = "请登录,SysUser Is Empty"
  3741. br.Ret = 408
  3742. return
  3743. }
  3744. //roleTypeCode := sysUser.RoleTypeCode
  3745. var req company.CompanyEditReq
  3746. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3747. if err != nil {
  3748. br.Msg = "参数解析异常!"
  3749. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3750. return
  3751. }
  3752. if req.CompanyId <= 0 {
  3753. br.Msg = "参数异常!"
  3754. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  3755. return
  3756. }
  3757. if req.CompanyName == "" {
  3758. br.Msg = "请填写客户名称"
  3759. return
  3760. }
  3761. if req.CreditCode == "" {
  3762. br.Msg = "请填写社会统一信用码"
  3763. return
  3764. }
  3765. //移除空格
  3766. req.CreditCode = utils.TrimStr(req.CreditCode)
  3767. productId := services.GetProductId(sysUser.RoleTypeCode) //产品权限id
  3768. for _, v := range req.Products {
  3769. //X类试用,转为永续
  3770. if v.Status == utils.COMPANY_STATUS_X_CLASS_TRY_OUT {
  3771. v.Status = utils.COMPANY_STATUS_FOREVER
  3772. }
  3773. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  3774. //查询客户的产品权限
  3775. companyReportPermissionListOld, err := company.GetCompanyReportPermission(req.CompanyId, productId)
  3776. if err != nil {
  3777. br.Msg = "查询客户的产品权限异常"
  3778. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  3779. return
  3780. }
  3781. permissionArr := strings.Split(v.PermissionIds, ",")
  3782. //如果所选行业不属于研选订阅跟研选扣点包,那就是非研选试用客户
  3783. var isNoResearch bool
  3784. for _, v := range permissionArr {
  3785. if v != strconv.Itoa(utils.CHART_PERMISSION_ID_YANXUAN) && v != strconv.Itoa(utils.YAN_XUAN_KOU_DIAN_BAO_ID) {
  3786. isNoResearch = true
  3787. continue
  3788. }
  3789. }
  3790. if isNoResearch && len(companyReportPermissionListOld) != len(permissionArr) {
  3791. tryOutCountRai, err := company.GetRaiCompanyTryOutCountNoResearch(sysUser.AdminId)
  3792. if err != nil {
  3793. br.Msg = "判断试用客户量失败"
  3794. br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  3795. return
  3796. }
  3797. if tryOutCountRai >= utils.COMPANY_STATUS_TRY_OUT_COUNT_RAI {
  3798. br.Msg = "非研选试用客户最多40家"
  3799. return
  3800. }
  3801. }
  3802. }
  3803. if v.IndustryId <= 0 {
  3804. br.Msg = "请选择行业"
  3805. br.IsSendEmail = false
  3806. return
  3807. }
  3808. //获取客户产品信息
  3809. productItem, err := company.GetCompanyProductById(v.CompanyProductId)
  3810. if err != nil {
  3811. br.Msg = "数据获取失败!"
  3812. br.ErrMsg = "数据获取失败,Err:" + err.Error()
  3813. return
  3814. }
  3815. if productItem == nil {
  3816. br.Msg = "客户信息不存在!"
  3817. return
  3818. }
  3819. // 如果本身是有权限归属的,同时传入的参数不是当前账号权限的,那么过滤该次循环,进入下次循环
  3820. if productId > 0 && productItem.ProductId != productId {
  3821. continue
  3822. }
  3823. if v.Status == "" {
  3824. br.Msg = "客户状态不可为空"
  3825. return
  3826. }
  3827. //if v.Reasons == "" {
  3828. // br.Msg = "请填写新增理由"
  3829. // return
  3830. //}
  3831. if v.PermissionIds == "" {
  3832. br.Msg = "请选择权限"
  3833. return
  3834. }
  3835. var startDate, endDate string
  3836. startDate = productItem.StartDate
  3837. endDate = productItem.EndDate
  3838. if startDate == "" || endDate == "" {
  3839. br.Msg = "数据错误"
  3840. br.Msg = "数据错误,开始或结束日期为空:startDate:" + startDate + "endDate:" + endDate
  3841. return
  3842. }
  3843. //判断客户是否已经存在
  3844. companyNameIsExist, err := company.GetCompanyCountByCompanyNameAndCompanyId(req.CompanyId, req.CompanyName)
  3845. if err != nil {
  3846. br.Msg = "判断客户是否存在失败"
  3847. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  3848. return
  3849. }
  3850. if companyNameIsExist > 0 {
  3851. br.Msg = "客户已存在,请重新输入客户名称"
  3852. return
  3853. }
  3854. //判断客户是否已经存在
  3855. companyCreditCodeIsExist, err := company.GetCompanyCountByCreditCodeAndCompanyId(req.CompanyId, req.CreditCode)
  3856. if err != nil {
  3857. br.Msg = "判断客户是否存在失败"
  3858. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  3859. return
  3860. }
  3861. if companyCreditCodeIsExist > 0 {
  3862. br.Msg = "客户已存在,请重新输入统一社会信用代码"
  3863. return
  3864. }
  3865. seller, err := system.GetSysAdminById(v.SellsId)
  3866. if err != nil {
  3867. br.Msg = "获取销售信息失败"
  3868. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  3869. return
  3870. }
  3871. if seller == nil {
  3872. br.Msg = "所属销售不存在"
  3873. return
  3874. }
  3875. //tryOutCount, err := company.GetCompanyTryOutCount(utils.COMPANY_STATUS_TRY_OUT, seller.AdminId)
  3876. //if err != nil {
  3877. // br.Msg = "判断试用客户量失败"
  3878. // br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  3879. // return
  3880. //}
  3881. //if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
  3882. // roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  3883. // if tryOutCount >= utils.COMPANY_STATUS_TRY_OUT_COUNT && v.SellsId == sysUser.AdminId {
  3884. // br.Msg = "您的试用客户总数,已超过上限,不可继续新增"
  3885. // return
  3886. // }
  3887. //}
  3888. industry, err := company.GetCompanyIndustryById(v.IndustryId)
  3889. if err != nil {
  3890. br.Msg = "获取行业信息失败"
  3891. br.ErrMsg = "获取行业信息失败,Err:" + err.Error()
  3892. return
  3893. }
  3894. companyProduct := new(company.CompanyProduct)
  3895. companyProduct.ProductId = productItem.ProductId
  3896. companyProduct.CompanyId = req.CompanyId
  3897. companyProduct.CompanyName = req.CompanyName
  3898. companyProduct.Source = v.Source
  3899. companyProduct.Reasons = v.Reasons
  3900. companyProduct.Status = v.Status
  3901. companyProduct.StartDate = startDate
  3902. companyProduct.EndDate = endDate
  3903. companyProduct.IndustryId = v.IndustryId
  3904. companyProduct.IndustryName = industry.IndustryName
  3905. companyProduct.SellerId = seller.AdminId
  3906. companyProduct.SellerName = seller.RealName
  3907. companyProduct.GroupId = seller.GroupId
  3908. companyProduct.DepartmentId = seller.DepartmentId
  3909. companyProduct.IsSuspend = 0
  3910. companyProduct.ModifyTime = time.Now()
  3911. companyProduct.CompanyProductId = v.CompanyProductId
  3912. companyProduct.Scale = v.Scale
  3913. err = company.ModifyCompanyProduct(companyProduct)
  3914. if err != nil {
  3915. br.Msg = "修改客户信息失败"
  3916. br.ErrMsg = "修改客户产品信息失败,Err:" + err.Error()
  3917. return
  3918. }
  3919. // CRM8.8-下面的需求取消, 编辑的时候根据选择开通对应权限
  3920. // 如果是权益客户,编辑的时候开通主观客观权限
  3921. //if v.CompanyType == utils.COMPANY_CLASSIFY_RAI {
  3922. // permissionStr, err := company.GetPermissionIdById(v.PermissionIds)
  3923. // if err != nil {
  3924. // br.Msg = "修改失败"
  3925. // br.ErrMsg = "获取主观客观权限信息失败,Err:" + err.Error()
  3926. // return
  3927. // }
  3928. // v.PermissionIds = permissionStr
  3929. //}
  3930. //处理权限
  3931. companyReportPermissionList, err := services.AddCompanyPermission(req.CompanyId, seller.AdminId, productItem.ProductId, productItem.ProductName, seller.RealName, v.PermissionIds, startDate, endDate)
  3932. if err != nil {
  3933. br.Msg = "修改失败"
  3934. br.ErrMsg = "新增客户设置权限失败,err:" + err.Error()
  3935. return
  3936. }
  3937. //新增操作记录
  3938. {
  3939. record := new(company.CompanyOperationRecord)
  3940. record.CompanyId = req.CompanyId
  3941. record.CompanyName = req.CompanyName
  3942. record.SellerId = companyProduct.SellerId
  3943. record.SysUserId = this.SysUser.AdminId
  3944. record.SysRealName = this.SysUser.RealName
  3945. record.Remark = "编辑客户"
  3946. record.Operation = "edit"
  3947. record.CreateTime = time.Now()
  3948. record.ProductId = productItem.ProductId
  3949. record.ProductName = productItem.ProductName
  3950. record.Status = productItem.Status
  3951. _, err = company.AddCompanyOperationRecord(record)
  3952. if err != nil {
  3953. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  3954. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  3955. }
  3956. }
  3957. //新增客户产品日志
  3958. {
  3959. productLog := new(company.CompanyProductLog)
  3960. productLog.CompanyProductId = v.CompanyProductId
  3961. productLog.CompanyId = companyProduct.CompanyId
  3962. productLog.ProductId = companyProduct.ProductId
  3963. productLog.ProductName = companyProduct.ProductName
  3964. productLog.CompanyName = companyProduct.CompanyName
  3965. productLog.CompanyName = companyProduct.CompanyName
  3966. productLog.Source = companyProduct.Source
  3967. productLog.Reasons = companyProduct.Reasons
  3968. productLog.Status = companyProduct.Status
  3969. productLog.IndustryId = companyProduct.IndustryId
  3970. productLog.IndustryName = companyProduct.IndustryName
  3971. productLog.SellerId = companyProduct.SellerId
  3972. productLog.SellerName = companyProduct.SellerName
  3973. productLog.GroupId = companyProduct.GroupId
  3974. productLog.DepartmentId = companyProduct.DepartmentId
  3975. productLog.IsSuspend = companyProduct.IsSuspend
  3976. productLog.SuspendTime = companyProduct.SuspendTime
  3977. productLog.ApproveStatus = companyProduct.ApproveStatus
  3978. productLog.FreezeTime = companyProduct.FreezeTime
  3979. productLog.Remark = companyProduct.Remark
  3980. productLog.StartDate = companyProduct.StartDate
  3981. productLog.EndDate = companyProduct.EndDate
  3982. productLog.CreateTime = companyProduct.CreateTime
  3983. productLog.ModifyTime = companyProduct.ModifyTime
  3984. productLog.LoseReason = companyProduct.LoseReason
  3985. productLog.LossTime = companyProduct.LossTime
  3986. productLog.LogType = "modify"
  3987. productLog.LogCreateTime = time.Now()
  3988. productLog.AdminId = this.SysUser.AdminId
  3989. productLog.Scale = companyProduct.Scale
  3990. go company.AddCompanyProductLog(productLog)
  3991. }
  3992. //新增客户产品状态变更日志
  3993. {
  3994. startDateTime, _ := time.ParseInLocation(utils.FormatDate, startDate, time.Local)
  3995. endDateTime, _ := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
  3996. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  3997. Id: 0,
  3998. CompanyId: req.CompanyId,
  3999. ProductId: productId,
  4000. Status: "试用",
  4001. Source: "edit",
  4002. SellerId: seller.AdminId,
  4003. SellerName: seller.RealName,
  4004. StartDate: startDateTime,
  4005. EndDate: endDateTime,
  4006. RealEndDate: startDateTime,
  4007. CreateTime: time.Now(),
  4008. }
  4009. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  4010. // 添加试用记录
  4011. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  4012. Id: 0,
  4013. CompanyId: req.CompanyId,
  4014. ProductId: productId,
  4015. Source: "edit",
  4016. SellerId: seller.AdminId,
  4017. SellerName: seller.RealName,
  4018. StartDate: startDateTime,
  4019. EndDate: endDateTime,
  4020. RealEndDate: startDateTime,
  4021. IsStop: 0,
  4022. CreateTime: time.Now(),
  4023. }
  4024. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  4025. }
  4026. }
  4027. companyItem := new(company.Company)
  4028. companyItem.CompanyId = req.CompanyId
  4029. companyItem.CompanyName = req.CompanyName
  4030. companyItem.CreditCode = req.CreditCode
  4031. companyItem.Province = req.Province
  4032. companyItem.City = req.City
  4033. companyItem.Address = req.Province + req.City
  4034. companyItem.LastUpdatedTime = time.Now()
  4035. companyItem.Enabled = 1
  4036. companyItem.Nation = req.Nation
  4037. err = company.ModifyCompany(companyItem)
  4038. if err != nil {
  4039. br.Msg = "修改客户信息失败"
  4040. br.ErrMsg = "修改客户信息失败,Err:" + err.Error()
  4041. return
  4042. }
  4043. //新增客户日志
  4044. {
  4045. companyLog := new(company.CompanyLog)
  4046. companyLog.CompanyId = req.CompanyId
  4047. companyLog.CompanyName = req.CompanyName
  4048. companyLog.CreditCode = req.CreditCode
  4049. companyLog.Address = companyItem.Address
  4050. companyLog.City = companyItem.City
  4051. companyLog.Province = companyItem.Province
  4052. companyLog.LastUpdatedTime = companyItem.LastUpdatedTime
  4053. companyLog.AdminId = this.SysUser.AdminId
  4054. companyLog.LogType = "modify"
  4055. companyLog.LogCreateTime = time.Now()
  4056. go company.AddCompanyLog(companyLog)
  4057. }
  4058. br.Ret = 200
  4059. br.Success = true
  4060. br.Msg = "保存成功"
  4061. }
  4062. // @Title 编辑补充客户信息接口
  4063. // @Description 编辑补充客户信息接口
  4064. // @Param request body company.CompanyInfoEditReq true "type json string"
  4065. // @Success Ret=200 保存成功
  4066. // @router /company_info/edit [post]
  4067. func (this *CompanyController) EditCompanyInfo() {
  4068. br := new(models.BaseResponse).Init()
  4069. defer func() {
  4070. this.Data["json"] = br
  4071. this.ServeJSON()
  4072. }()
  4073. sysUser := this.SysUser
  4074. if sysUser == nil {
  4075. br.Msg = "请登录"
  4076. br.ErrMsg = "请登录,SysUser Is Empty"
  4077. br.Ret = 408
  4078. return
  4079. }
  4080. var req company.CompanyInfoEditReq
  4081. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4082. if err != nil {
  4083. br.Msg = "参数解析异常!"
  4084. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4085. return
  4086. }
  4087. if req.CompanyId <= 0 {
  4088. br.Msg = "参数异常!"
  4089. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  4090. return
  4091. }
  4092. if req.CompanyName == "" {
  4093. br.Msg = "请填写客户名称"
  4094. return
  4095. }
  4096. if req.CreditCode == "" {
  4097. br.Msg = "请填写社会统一信用码"
  4098. return
  4099. }
  4100. //if req.Province == "" {
  4101. // br.Msg = "请选择省份"
  4102. // return
  4103. //}
  4104. //if req.City == "" {
  4105. // br.Msg = "请选择市区"
  4106. // return
  4107. //}
  4108. //if req.IndustryId <= 0 {
  4109. // br.Msg = "请选择所属行业"
  4110. // return
  4111. //}
  4112. //if req.IndustryName == "" {
  4113. // br.Msg = "请选择所属行业"
  4114. // return
  4115. //}
  4116. //if req.Source == "" {
  4117. // br.Msg = "请选择来源"
  4118. // return
  4119. //}
  4120. //移除空格
  4121. req.CreditCode = utils.TrimStr(req.CreditCode)
  4122. //获取产品权限
  4123. productId := services.GetProductId(sysUser.RoleTypeCode)
  4124. if productId <= 0 {
  4125. br.Msg = "当前账号不允许修改客户信息"
  4126. return
  4127. }
  4128. companyNameIsExist, err := company.GetCompanyCountByCompanyNameAndCompanyId(req.CompanyId, req.CompanyName)
  4129. if err != nil {
  4130. br.Msg = "判断客户是否存在失败"
  4131. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  4132. return
  4133. }
  4134. if companyNameIsExist > 0 {
  4135. br.Msg = "客户已存在,请重新输入客户名称"
  4136. return
  4137. }
  4138. //判断客户是否已经存在
  4139. companyCreditCodeIsExist, err := company.GetCompanyCountByCreditCodeAndCompanyId(req.CompanyId, req.CreditCode)
  4140. if err != nil {
  4141. br.Msg = "判断客户是否存在失败"
  4142. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  4143. return
  4144. }
  4145. if companyCreditCodeIsExist > 0 {
  4146. br.Msg = "客户已存在,统一社会信用代码"
  4147. return
  4148. }
  4149. //查询该客户
  4150. companyItem, err := company.GetCompanyById(req.CompanyId)
  4151. if err != nil {
  4152. br.Msg = "查找客户失败"
  4153. br.ErrMsg = "查找客户失败,Err:" + err.Error()
  4154. return
  4155. }
  4156. //待更新字段
  4157. updateCol := make([]string, 0)
  4158. companyItem.CompanyName = req.CompanyName
  4159. companyItem.CreditCode = req.CreditCode
  4160. companyItem.Enabled = 1
  4161. companyItem.LastUpdatedTime = time.Now()
  4162. updateCol = append(updateCol, "CompanyName", "CreditCode", "Enabled", "LastUpdatedTime")
  4163. if req.Province != "" && req.City != "" {
  4164. companyItem.Province = req.Province
  4165. companyItem.City = req.City
  4166. companyItem.Address = req.Province + req.City
  4167. updateCol = append(updateCol, "Province", "City", "Address")
  4168. }
  4169. err = companyItem.Update(updateCol)
  4170. if err != nil {
  4171. br.Msg = "修改客户信息失败"
  4172. br.ErrMsg = "修改客户信息失败,Err:" + err.Error()
  4173. return
  4174. }
  4175. //查询并更新客户产品信息
  4176. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  4177. if err != nil {
  4178. if err.Error() != utils.ErrNoRow() {
  4179. br.Msg = "查询客户产品信息失败"
  4180. br.ErrMsg = "查询客户产品信息失败,Err:" + err.Error()
  4181. return
  4182. }
  4183. } else {
  4184. if companyProduct != nil {
  4185. //客户产品待更新字段
  4186. updateCompanyProductCol := make([]string, 0)
  4187. //产品信息(来源、行业)
  4188. if req.IndustryId != 0 && req.IndustryId != companyProduct.IndustryId {
  4189. companyProduct.IndustryId = req.IndustryId
  4190. companyProduct.IndustryName = req.IndustryName
  4191. updateCompanyProductCol = append(updateCompanyProductCol, "IndustryId", "IndustryName")
  4192. }
  4193. if req.Source != "" && req.Source != companyProduct.Source {
  4194. companyProduct.Source = req.Source
  4195. updateCompanyProductCol = append(updateCompanyProductCol, "Source")
  4196. }
  4197. //更新客户产品信息
  4198. if len(updateCompanyProductCol) > 0 {
  4199. err = companyProduct.Update(updateCompanyProductCol)
  4200. if err != nil {
  4201. br.Msg = "修改客户信息失败"
  4202. br.ErrMsg = "修改客户信息失败,Err:" + err.Error()
  4203. return
  4204. }
  4205. }
  4206. }
  4207. }
  4208. //新增客户日志
  4209. {
  4210. companyLog := new(company.CompanyLog)
  4211. companyLog.CompanyId = req.CompanyId
  4212. companyLog.CompanyName = req.CompanyName
  4213. companyLog.CreditCode = req.CreditCode
  4214. companyLog.Address = companyItem.Address
  4215. companyLog.City = companyItem.City
  4216. companyLog.Province = companyItem.Province
  4217. companyLog.LastUpdatedTime = companyItem.LastUpdatedTime
  4218. companyLog.AdminId = this.SysUser.AdminId
  4219. companyLog.LogType = "modify"
  4220. companyLog.LogCreateTime = time.Now()
  4221. go company.AddCompanyLog(companyLog)
  4222. }
  4223. br.Ret = 200
  4224. br.Success = true
  4225. br.Msg = "保存成功"
  4226. }
  4227. // @Title 客户模糊检索(新增/编辑客户页面试用)
  4228. // @Description 客户模糊检索接口(新增/编辑客户页面试用)
  4229. // @Param KeyWord query string true "搜索关键词"
  4230. // @Success 200 {object} company.CompanyFuzzySearchReq
  4231. // @router /fuzzy/search [get]
  4232. func (this *CompanyController) FuzzySearch() {
  4233. br := new(models.BaseResponse).Init()
  4234. defer func() {
  4235. this.Data["json"] = br
  4236. this.ServeJSON()
  4237. }()
  4238. keyWord := this.GetString("KeyWord")
  4239. list, err := company.GetCompanyFuzzySearch(keyWord)
  4240. if err != nil {
  4241. br.Msg = "获取信息失败"
  4242. br.ErrMsg = "获取信息失败,err:" + err.Error()
  4243. return
  4244. }
  4245. resp := new(company.CompanyFuzzySearchReq)
  4246. resp.List = list
  4247. br.Ret = 200
  4248. br.Success = true
  4249. br.Msg = "获取成功"
  4250. br.Data = resp
  4251. }
  4252. // @Title 删除客户
  4253. // @Description 删除客户接口
  4254. // @Param request body company.DeletePptReq true "type json string"
  4255. // @Success Ret=200 保存成功
  4256. // @router /delete [post]
  4257. func (this *CompanyController) Delete() {
  4258. br := new(models.BaseResponse).Init()
  4259. defer func() {
  4260. this.Data["json"] = br
  4261. this.ServeJSON()
  4262. }()
  4263. sysUser := this.SysUser
  4264. if sysUser == nil {
  4265. br.Msg = "请登录"
  4266. br.ErrMsg = "请登录,SysUser Is Empty"
  4267. br.Ret = 408
  4268. return
  4269. }
  4270. var req company.DeletePptReq
  4271. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4272. if err != nil {
  4273. br.Msg = "参数解析异常!"
  4274. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4275. return
  4276. }
  4277. if req.CompanyId <= 0 {
  4278. br.Msg = "参数错误"
  4279. br.ErrMsg = "客户ID小于等于0"
  4280. return
  4281. }
  4282. roleTypeCode := this.SysUser.RoleTypeCode
  4283. productId := services.GetProductId(roleTypeCode)
  4284. productItems, err := company.GetCompanyProductsByCompanyId(req.CompanyId)
  4285. if err != nil {
  4286. br.Msg = "删除失败"
  4287. br.ErrMsg = "获取客户产品信息失败,Err:" + err.Error()
  4288. return
  4289. }
  4290. // 备份信息
  4291. companyDeleteBakInfo := services.CompanyDeleteBakInfo{
  4292. CompanyId: req.CompanyId,
  4293. CompanyName: "",
  4294. CompanyInfo: &company.Company{},
  4295. CompanyProductInfo: make([]*company.CompanyProduct, 0),
  4296. CompanyPermissionInfo: make([]*company.CompanyReportPermission, 0),
  4297. UserSellerRelationInfo: make([]*models.UserSellerRelation, 0),
  4298. UserRecordInfo: make([]*models.UserRecord, 0),
  4299. UserInfo: make([]*models.WxUser, 0),
  4300. CompanyChartPermissionInfo: make([]*company_user.ChartClassifyPermission, 0),
  4301. OpUserId: this.SysUser.AdminId,
  4302. OpUserName: this.SysUser.RealName,
  4303. }
  4304. if productId == 0 {
  4305. for _, v := range productItems {
  4306. //永续,试用,流失,关闭
  4307. 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 {
  4308. br.Msg = "该客户" + v.ProductName + "属性为" + v.Status + ",暂不可删除"
  4309. br.ErrMsg = "该客户" + v.ProductName + "属性为" + v.Status + ",暂不可删除"
  4310. return
  4311. }
  4312. companyProductList, companyReportPermissionList, err := company.DeleteCompanyProductById(v.CompanyId, v.ProductId, v.CompanyProductId)
  4313. if err != nil {
  4314. br.Msg = "删除失败"
  4315. br.ErrMsg = "删除失败,Err:" + err.Error()
  4316. return
  4317. }
  4318. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductList...)
  4319. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissionList...)
  4320. //新增操作记录
  4321. {
  4322. record := new(company.CompanyOperationRecord)
  4323. record.CompanyId = req.CompanyId
  4324. record.CompanyName = v.CompanyName
  4325. record.SellerId = v.SellerId
  4326. record.SysUserId = this.SysUser.AdminId
  4327. record.SysRealName = this.SysUser.RealName
  4328. record.Remark = "删除客户"
  4329. record.Operation = "delete"
  4330. record.CreateTime = time.Now()
  4331. record.ProductId = v.ProductId
  4332. record.ProductName = v.ProductName
  4333. _, err = company.AddCompanyOperationRecord(record)
  4334. if err != nil {
  4335. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  4336. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  4337. }
  4338. }
  4339. //删除对应产品的联系人
  4340. userSellerRelationList, userRecordList, wxUserList, chartClassifyPermission, _ := services.DeleteCompanyWxUserByProductId(v.CompanyId, v.ProductId)
  4341. //备份信息
  4342. {
  4343. if companyProductList != nil {
  4344. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductList...)
  4345. }
  4346. if companyReportPermissionList != nil {
  4347. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissionList...)
  4348. }
  4349. if userSellerRelationList != nil {
  4350. companyDeleteBakInfo.UserSellerRelationInfo = append(companyDeleteBakInfo.UserSellerRelationInfo, userSellerRelationList...)
  4351. }
  4352. if userRecordList != nil {
  4353. companyDeleteBakInfo.UserRecordInfo = append(companyDeleteBakInfo.UserRecordInfo, userRecordList...)
  4354. }
  4355. if wxUserList != nil {
  4356. companyDeleteBakInfo.UserInfo = append(companyDeleteBakInfo.UserInfo, wxUserList...)
  4357. }
  4358. if chartClassifyPermission != nil {
  4359. companyDeleteBakInfo.CompanyChartPermissionInfo = append(companyDeleteBakInfo.CompanyChartPermissionInfo, chartClassifyPermission...)
  4360. }
  4361. companyDeleteBakInfo.CompanyName = v.CompanyName
  4362. }
  4363. }
  4364. } else {
  4365. productObj, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  4366. if err != nil {
  4367. br.ErrMsg = "获取客户产品信息失败,Err:" + err.Error()
  4368. br.Msg = "删除失败"
  4369. return
  4370. }
  4371. //永续,试用,流失,关闭
  4372. 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 {
  4373. br.Msg = "该客户" + productObj.ProductName + "属性为" + productObj.Status + ",暂不可删除"
  4374. br.ErrMsg = "该客户" + productObj.ProductName + "属性为" + productObj.Status + ",暂不可删除"
  4375. return
  4376. }
  4377. companyProductList, companyReportPermissionList, err := company.DeleteCompanyProductById(productObj.CompanyId, productObj.ProductId, productObj.CompanyProductId)
  4378. if err != nil {
  4379. br.Msg = "删除失败"
  4380. br.ErrMsg = "删除失败,Err:" + err.Error()
  4381. return
  4382. }
  4383. //新增操作记录
  4384. {
  4385. record := new(company.CompanyOperationRecord)
  4386. record.CompanyId = req.CompanyId
  4387. record.CompanyName = productObj.CompanyName
  4388. record.SellerId = productObj.SellerId
  4389. record.SysUserId = this.SysUser.AdminId
  4390. record.SysRealName = this.SysUser.RealName
  4391. record.Remark = "删除客户"
  4392. record.Operation = "delete"
  4393. record.CreateTime = time.Now()
  4394. record.ProductId = productObj.ProductId
  4395. record.ProductName = productObj.ProductName
  4396. _, err = company.AddCompanyOperationRecord(record)
  4397. if err != nil {
  4398. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  4399. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  4400. }
  4401. }
  4402. //删除对应产品的联系人
  4403. userSellerRelationList, userRecordList, wxUserList, chartClassifyPermission, _ := services.DeleteCompanyWxUserByProductId(productObj.CompanyId, productId)
  4404. //备份信息
  4405. {
  4406. if companyProductList != nil {
  4407. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductList...)
  4408. }
  4409. if companyReportPermissionList != nil {
  4410. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissionList...)
  4411. }
  4412. if userSellerRelationList != nil {
  4413. companyDeleteBakInfo.UserSellerRelationInfo = append(companyDeleteBakInfo.UserSellerRelationInfo, userSellerRelationList...)
  4414. }
  4415. if userRecordList != nil {
  4416. companyDeleteBakInfo.UserRecordInfo = append(companyDeleteBakInfo.UserRecordInfo, userRecordList...)
  4417. }
  4418. if wxUserList != nil {
  4419. companyDeleteBakInfo.UserInfo = append(companyDeleteBakInfo.UserInfo, wxUserList...)
  4420. }
  4421. if chartClassifyPermission != nil {
  4422. companyDeleteBakInfo.CompanyChartPermissionInfo = append(companyDeleteBakInfo.CompanyChartPermissionInfo, chartClassifyPermission...)
  4423. }
  4424. companyDeleteBakInfo.CompanyName = productObj.CompanyName
  4425. }
  4426. }
  4427. productItemsNew, err := company.GetCompanyProductsByCompanyId(req.CompanyId)
  4428. if err != nil {
  4429. br.Msg = "删除失败"
  4430. br.ErrMsg = "获取客户产品信息失败,Err:" + err.Error()
  4431. return
  4432. }
  4433. if len(productItemsNew) == 0 {
  4434. //删除之前查询的数据信息
  4435. {
  4436. companyProductLists, companyReportPermissions, wxUsers, userSellerRelations, companyContracts, companyContractPermissions, companyInfo, _ := services.GetBeforeDeleteCompanyInfo(req.CompanyId)
  4437. //companyDeleteBakInfo
  4438. if companyProductLists != nil {
  4439. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductLists...)
  4440. }
  4441. if companyReportPermissions != nil {
  4442. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissions...)
  4443. }
  4444. if wxUsers != nil {
  4445. companyDeleteBakInfo.UserInfo = append(companyDeleteBakInfo.UserInfo, wxUsers...)
  4446. }
  4447. if userSellerRelations != nil {
  4448. companyDeleteBakInfo.UserSellerRelationInfo = append(companyDeleteBakInfo.UserSellerRelationInfo, userSellerRelations...)
  4449. }
  4450. if companyContracts != nil {
  4451. companyDeleteBakInfo.CompanyContract = append(companyDeleteBakInfo.CompanyContract, companyContracts...)
  4452. }
  4453. if companyContractPermissions != nil {
  4454. companyDeleteBakInfo.CompanyContractPermission = append(companyDeleteBakInfo.CompanyContractPermission, companyContractPermissions...)
  4455. }
  4456. if companyInfo != nil {
  4457. companyDeleteBakInfo.CompanyName = companyInfo.CompanyName
  4458. companyDeleteBakInfo.CompanyInfo = companyInfo
  4459. }
  4460. }
  4461. err = company.DeleteCompanyById(req.CompanyId)
  4462. if err != nil {
  4463. br.Msg = "删除失败"
  4464. br.ErrMsg = "删除失败,Err:" + err.Error()
  4465. return
  4466. }
  4467. for _, v := range productItems {
  4468. //新增操作记录
  4469. {
  4470. record := new(company.CompanyOperationRecord)
  4471. record.CompanyId = req.CompanyId
  4472. record.CompanyName = v.CompanyName
  4473. record.SellerId = v.SellerId
  4474. record.SysUserId = this.SysUser.AdminId
  4475. record.SysRealName = this.SysUser.RealName
  4476. record.Remark = "删除客户"
  4477. record.Operation = "delete"
  4478. record.CreateTime = time.Now()
  4479. record.ProductId = v.ProductId
  4480. record.ProductName = v.ProductName
  4481. _, err = company.AddCompanyOperationRecord(record)
  4482. if err != nil {
  4483. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  4484. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  4485. }
  4486. }
  4487. }
  4488. }
  4489. //数据备份入库
  4490. {
  4491. companyInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyInfo)
  4492. companyProductInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyProductInfo)
  4493. companyPermissionInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyPermissionInfo)
  4494. userSellerRelationInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.UserSellerRelationInfo)
  4495. userRecordInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.UserRecordInfo)
  4496. userInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.UserInfo)
  4497. companyChartPermissionInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyChartPermissionInfo)
  4498. companyContractByte, _ := json.Marshal(companyDeleteBakInfo.CompanyContract)
  4499. companyContractPermissionJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyContractPermission)
  4500. companyDeleteBak := &company.CompanyDeleteBak{
  4501. //DeleteBakId: 0,
  4502. CompanyId: companyDeleteBakInfo.CompanyId,
  4503. CompanyName: companyDeleteBakInfo.CompanyName,
  4504. CompanyInfo: string(companyInfoJsonByte),
  4505. CompanyProductInfo: string(companyProductInfoJsonByte),
  4506. CompanyPermissionInfo: string(companyPermissionInfoJsonByte),
  4507. UserSellerRelationInfo: string(userSellerRelationInfoJsonByte),
  4508. UserRecordInfo: string(userRecordInfoJsonByte),
  4509. UserInfo: string(userInfoJsonByte),
  4510. CompanyChartPermissionInfo: string(companyChartPermissionInfoJsonByte),
  4511. CompanyContractInfo: string(companyContractByte),
  4512. CompanyContractPermissionInfo: string(companyContractPermissionJsonByte),
  4513. OpUserId: this.SysUser.AdminId,
  4514. OpUserName: this.SysUser.RealName,
  4515. CreateTime: time.Now(),
  4516. }
  4517. _ = company.AddCompanyDeleteBak(companyDeleteBak)
  4518. }
  4519. br.Ret = 200
  4520. br.Success = true
  4521. br.Msg = "删除成功"
  4522. }
  4523. // @Title 领取客户列表
  4524. // @Description 领取客户列表接口
  4525. // @Param PageSize query int true "每页数据条数"
  4526. // @Param CurrentIndex query int true "当前页页码,从1开始"
  4527. // @Param StartDate query string true "开始时间"
  4528. // @Param EndDate query string true "结束时间"
  4529. // @Param KeyWord query string true "搜索关键词"
  4530. // @Success 200 {object} company.CompanyReceiveListResp
  4531. // @router /receive/list [get]
  4532. func (this *CompanyController) ReceiveList() {
  4533. br := new(models.BaseResponse).Init()
  4534. defer func() {
  4535. this.Data["json"] = br
  4536. this.ServeJSON()
  4537. }()
  4538. sysUser := this.SysUser
  4539. if sysUser == nil {
  4540. br.Msg = "请登录"
  4541. br.ErrMsg = "请登录,SysUser Is Empty"
  4542. br.Ret = 408
  4543. return
  4544. }
  4545. var productId, recevieProductId int
  4546. roleTypeCode := sysUser.RoleTypeCode
  4547. productId = services.GetProductId(roleTypeCode)
  4548. if productId == 1 {
  4549. recevieProductId = 2
  4550. } else if productId == 2 {
  4551. recevieProductId = 1
  4552. }
  4553. if productId == 0 {
  4554. br.Msg = "参数错误"
  4555. br.ErrMsg = "客户类型为:" + roleTypeCode
  4556. return
  4557. }
  4558. pageSize, _ := this.GetInt("PageSize")
  4559. currentIndex, _ := this.GetInt("CurrentIndex")
  4560. adminId := this.GetString("AdminId")
  4561. startDate := this.GetString("StartDate")
  4562. endDate := this.GetString("EndDate")
  4563. keyWord := this.GetString("KeyWord")
  4564. var startSize int
  4565. if pageSize <= 0 {
  4566. pageSize = utils.PageSize20
  4567. }
  4568. if currentIndex <= 0 {
  4569. currentIndex = 1
  4570. }
  4571. startSize = paging.StartIndex(currentIndex, pageSize)
  4572. var condition string
  4573. var pars []interface{}
  4574. if adminId != "" {
  4575. condition += ` AND c.seller_id IN (` + adminId + `) `
  4576. }
  4577. if startDate != "" {
  4578. condition += ` AND c.start_date>=? `
  4579. pars = append(pars, startDate)
  4580. }
  4581. if endDate != "" {
  4582. condition += ` AND c.end_date>=? `
  4583. pars = append(pars, endDate)
  4584. }
  4585. if keyWord != "" {
  4586. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR b.mobile LIKE '%` + keyWord + `%' OR b.email LIKE '%` + keyWord + `%') `
  4587. }
  4588. total, err := company.GetCompanyReceiveListCount(condition, pars, productId, recevieProductId)
  4589. if err != nil {
  4590. br.Msg = "获取失败"
  4591. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  4592. return
  4593. }
  4594. list, err := company.GetCompanyReceiveList(condition, pars, productId, recevieProductId, startSize, pageSize)
  4595. if err != nil {
  4596. br.Msg = "获取失败"
  4597. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  4598. return
  4599. }
  4600. lenList := len(list)
  4601. for i := 0; i < lenList; i++ {
  4602. item := list[i]
  4603. var expireDay string
  4604. if item.Status != "" {
  4605. status := item.Status
  4606. if item.EndDate != "" {
  4607. if status == utils.COMPANY_STATUS_FOREVER { //永续
  4608. expireDay = "-"
  4609. } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用/正式
  4610. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  4611. sub := endDateTime.Sub(time.Now())
  4612. expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  4613. } else if status == utils.COMPANY_STATUS_LOSE { //流失
  4614. expireDay = "-"
  4615. } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  4616. if item.StartDate != "" && item.EndDate != "" {
  4617. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  4618. sub := endDateTime.Sub(time.Now())
  4619. expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  4620. } else {
  4621. expireDay = "-"
  4622. }
  4623. } else {
  4624. expireDay = "-"
  4625. }
  4626. }
  4627. }
  4628. list[i].ExpireDay = expireDay
  4629. }
  4630. page := paging.GetPaging(currentIndex, pageSize, total)
  4631. resp := new(company.CompanyReceiveListResp)
  4632. resp.List = list
  4633. resp.Paging = page
  4634. br.Ret = 200
  4635. br.Success = true
  4636. br.Msg = "获取成功"
  4637. br.Data = resp
  4638. }
  4639. // @Title 领取客户
  4640. // @Description 领取客户接口
  4641. // @Param request body company.CompanyReceiveReq true "type json string"
  4642. // @Success Ret=200 领取成功
  4643. // @router /receive [post]
  4644. func (this *CompanyController) Receive() {
  4645. br := new(models.BaseResponse).Init()
  4646. defer func() {
  4647. this.Data["json"] = br
  4648. this.ServeJSON()
  4649. }()
  4650. sysUser := this.SysUser
  4651. if sysUser == nil {
  4652. br.Msg = "请登录"
  4653. br.ErrMsg = "请登录,SysUser Is Empty"
  4654. br.Ret = 408
  4655. return
  4656. }
  4657. var req company.CompanyReceiveReq
  4658. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4659. if err != nil {
  4660. br.Msg = "参数解析异常!"
  4661. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4662. return
  4663. }
  4664. if req.CompanyId <= 0 {
  4665. br.Msg = "参数异常!"
  4666. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  4667. return
  4668. }
  4669. //权益主观客观权限一块开
  4670. if req.PermissionIds != "" {
  4671. permissionStr, err := company.GetPermissionIdById(req.PermissionIds)
  4672. if err != nil {
  4673. br.Msg = "获取信息失败"
  4674. br.ErrMsg = "获取主观客观权限信息失败,Err:" + err.Error()
  4675. return
  4676. }
  4677. req.PermissionIds = permissionStr
  4678. }
  4679. roleTypeCode := sysUser.RoleTypeCode
  4680. productId := services.GetProductId(roleTypeCode)
  4681. if productId == 0 {
  4682. br.Msg = "参数错误"
  4683. br.ErrMsg = "客户类型为:" + roleTypeCode
  4684. return
  4685. }
  4686. sellsId := 0
  4687. if req.SellsId <= 0 {
  4688. sellsId = sysUser.AdminId
  4689. } else {
  4690. sellsId = req.SellsId
  4691. }
  4692. seller, err := system.GetSysAdminById(sellsId)
  4693. if err != nil {
  4694. br.Msg = "获取销售信息失败"
  4695. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  4696. return
  4697. }
  4698. companyDetail, err := company.GetCompanyDetailById(req.CompanyId)
  4699. if err != nil {
  4700. br.Msg = "获取客户信息失败"
  4701. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  4702. return
  4703. }
  4704. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  4705. if err != nil && err.Error() != utils.ErrNoRow() {
  4706. br.Msg = "获取客户信息失败"
  4707. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  4708. return
  4709. }
  4710. productName := ""
  4711. var status string
  4712. if productId == 1 {
  4713. productName = utils.COMPANY_PRODUCT_FICC_NAME
  4714. } else {
  4715. productName = utils.COMPANY_PRODUCT_RAI_NAME
  4716. }
  4717. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  4718. //查询客户的产品权限
  4719. companyReportPermissionListOld, err := company.GetCompanyReportPermission(req.CompanyId, productId)
  4720. if err != nil {
  4721. br.Msg = "查询客户的产品权限异常"
  4722. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  4723. return
  4724. }
  4725. var isNoResearch bool
  4726. for _, v := range companyReportPermissionListOld {
  4727. if v.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN && v.ChartPermissionId != utils.YAN_XUAN_KOU_DIAN_BAO_ID {
  4728. isNoResearch = true
  4729. continue
  4730. }
  4731. }
  4732. //如果所选行业不属于研选订阅跟研选扣点包,那就是非研选试用客户
  4733. if isNoResearch {
  4734. tryOutCountRai, err := company.GetRaiCompanyTryOutCountNoResearch(req.SellsId)
  4735. if err != nil {
  4736. br.Msg = "判断试用客户量失败"
  4737. br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  4738. return
  4739. }
  4740. if tryOutCountRai >= utils.COMPANY_STATUS_TRY_OUT_COUNT_RAI {
  4741. br.Msg = "非研选试用客户最多40家"
  4742. return
  4743. }
  4744. }
  4745. }
  4746. if cp != nil {
  4747. if cp.Status != utils.COMPANY_STATUS_LOSE {
  4748. br.Msg = "客户状态为:" + cp.Status + ";不可领取"
  4749. br.ErrMsg = "客户状态为:" + cp.Status + ";不可领取"
  4750. return
  4751. }
  4752. if cp.SellerId == sysUser.AdminId {
  4753. br.Msg = "已为自己客户,不可重复领取"
  4754. br.ErrMsg = "已为自己客户,不可领取:company_id:" + strconv.Itoa(cp.CompanyId)
  4755. return
  4756. }
  4757. //转移 销售
  4758. companyReportPermissionList, startDate, endDate, err := company.MoveSeller(req.CompanyId, productId, seller.AdminId, seller.GroupId, seller.DepartmentId, seller.RealName)
  4759. if err != nil {
  4760. br.Msg = "领取失败"
  4761. br.ErrMsg = "领取失败,Err:" + err.Error()
  4762. return
  4763. }
  4764. //新增客户产品状态变更日志
  4765. {
  4766. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  4767. Id: 0,
  4768. CompanyId: req.CompanyId,
  4769. ProductId: productId,
  4770. Status: "试用",
  4771. Source: "receive",
  4772. SellerId: seller.AdminId,
  4773. SellerName: seller.RealName,
  4774. StartDate: startDate,
  4775. EndDate: endDate,
  4776. RealEndDate: startDate,
  4777. CreateTime: time.Now(),
  4778. }
  4779. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  4780. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  4781. Id: 0,
  4782. CompanyId: req.CompanyId,
  4783. ProductId: productId,
  4784. Source: "receive",
  4785. SellerId: seller.AdminId,
  4786. SellerName: seller.RealName,
  4787. StartDate: startDate,
  4788. EndDate: endDate,
  4789. RealEndDate: startDate,
  4790. IsStop: 0,
  4791. CreateTime: time.Now(),
  4792. }
  4793. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  4794. }
  4795. //流失转试用,企业下面的用户自动添加产业关注
  4796. {
  4797. go cygxService.AddUserFllowCompanyLossToTryOut(req.CompanyId)
  4798. }
  4799. } else {
  4800. //跨部门领取
  4801. var startDateTime, endDateTime time.Time
  4802. if req.Status == utils.COMPANY_STATUS_TRY_OUT {
  4803. startDateTime = time.Now()
  4804. endDateTime = time.Now().AddDate(0, 2, 0)
  4805. } else if req.Status == utils.COMPANY_STATUS_FOREVER {
  4806. startDateTime = time.Now()
  4807. endDateTime = time.Now().AddDate(100, 0, 0)
  4808. } else {
  4809. br.Msg = "无效的客户状态,请重新选择"
  4810. return
  4811. }
  4812. var startDate, endDate string
  4813. startDate = startDateTime.Format(utils.FormatDate)
  4814. endDate = endDateTime.Format(utils.FormatDate)
  4815. if req.PermissionIds == "" {
  4816. br.Msg = "请选择权限!"
  4817. return
  4818. }
  4819. industry, err := company.GetCompanyIndustryById(req.IndustryId)
  4820. if err != nil {
  4821. br.Msg = "获取行业信息失败"
  4822. br.ErrMsg = "获取行业信息失败,Err:" + err.Error()
  4823. return
  4824. }
  4825. if industry == nil {
  4826. br.Msg = "行业信息不存在"
  4827. return
  4828. }
  4829. status = req.Status
  4830. companyProduct := new(company.CompanyProduct)
  4831. companyProduct.CompanyId = req.CompanyId
  4832. companyProduct.ProductId = productId
  4833. companyProduct.ProductName = productName
  4834. companyProduct.CompanyName = companyDetail.CompanyName
  4835. companyProduct.Source = req.Source
  4836. companyProduct.Reasons = req.Reasons
  4837. companyProduct.Status = status
  4838. companyProduct.StartDate = startDate
  4839. companyProduct.EndDate = endDate
  4840. companyProduct.IndustryId = req.IndustryId
  4841. companyProduct.IndustryName = industry.IndustryName
  4842. companyProduct.SellerId = seller.AdminId
  4843. companyProduct.SellerName = seller.RealName
  4844. companyProduct.GroupId = seller.GroupId
  4845. companyProduct.DepartmentId = seller.DepartmentId
  4846. companyProduct.IsSuspend = 0
  4847. companyProduct.CreateTime = time.Now()
  4848. companyProduct.ModifyTime = time.Now()
  4849. companyProduct.CompanyType = req.CompanyType
  4850. companyProduct.OpenCode = services.GenerateOpenCompanyProductCode(req.CompanyId, productId)
  4851. companyProduct.TodoStatus = "无任务"
  4852. companyProduct.TryStage = 1
  4853. _, err = company.AddCompanyProduct(companyProduct)
  4854. if err != nil {
  4855. br.Msg = "新增失败"
  4856. br.ErrMsg = "新增客户产品失败,err:" + err.Error()
  4857. return
  4858. }
  4859. companyReportPermissionList, err := services.AddCompanyPermission(req.CompanyId, seller.AdminId, productId, productName, seller.RealName, req.PermissionIds, startDate, endDate)
  4860. if err != nil {
  4861. br.Msg = "新增失败"
  4862. br.ErrMsg = "新增客户设置权限失败,err:" + err.Error()
  4863. return
  4864. }
  4865. //新增客户产品日志
  4866. {
  4867. go services.AddCompanyProductLog(companyProduct, this.SysUser.AdminId, "add")
  4868. }
  4869. //新增客户产品状态变更日志
  4870. {
  4871. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  4872. Id: 0,
  4873. CompanyId: companyProduct.CompanyId,
  4874. ProductId: companyProduct.ProductId,
  4875. Status: "试用",
  4876. SellerId: seller.AdminId,
  4877. SellerName: seller.RealName,
  4878. Source: "add",
  4879. StartDate: startDateTime,
  4880. EndDate: endDateTime,
  4881. RealEndDate: startDateTime,
  4882. CreateTime: time.Now(),
  4883. }
  4884. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  4885. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  4886. Id: 0,
  4887. CompanyId: companyProduct.CompanyId,
  4888. ProductId: companyProduct.ProductId,
  4889. SellerId: seller.AdminId,
  4890. SellerName: seller.RealName,
  4891. Source: "add",
  4892. StartDate: startDateTime,
  4893. EndDate: endDateTime,
  4894. RealEndDate: startDateTime,
  4895. IsStop: 0,
  4896. CreateTime: time.Now(),
  4897. }
  4898. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  4899. }
  4900. //查询当前客户的所有产品的列表数据,并找出非当前产品的销售去发送模板消息
  4901. companyProductList, err := company.GetCompanyProductsByCompanyId(req.CompanyId)
  4902. for _, companyProduct := range companyProductList {
  4903. //如果是当前领取的产品,那么就退出当前循环,进入下一循环
  4904. if companyProduct.ProductId == productId {
  4905. continue
  4906. }
  4907. //查询其他部门销售的信息
  4908. admin, tmpErr := system.GetSysAdminById(companyProduct.SellerId)
  4909. if tmpErr != nil {
  4910. continue
  4911. }
  4912. //发送模板消息给另一个部门的销售
  4913. go services.SendCompanyReceiveWxTemplateMsg(companyDetail.CompanyName, productName, sysUser.RealName, admin.Mobile)
  4914. }
  4915. }
  4916. //新增操作记录
  4917. {
  4918. remark := "领取客户"
  4919. operation := "receive"
  4920. services.AddCompanyOperationRecord(req.CompanyId, seller.AdminId, sysUser.AdminId, productId, sysUser.AdminId, companyDetail.CompanyName,
  4921. productName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", status)
  4922. }
  4923. br.Ret = 200
  4924. br.Success = true
  4925. br.Msg = "领取成功"
  4926. }
  4927. // @Title 移动销售
  4928. // @Description 移动销售接口
  4929. // @Param request body company.MoveSellerReq true "type json string"
  4930. // @Success Ret=200 移动成功
  4931. // @router /move/seller [post]
  4932. func (this *CompanyController) MoveSeller() {
  4933. br := new(models.BaseResponse).Init()
  4934. defer func() {
  4935. this.Data["json"] = br
  4936. this.ServeJSON()
  4937. }()
  4938. sysUser := this.SysUser
  4939. if sysUser == nil {
  4940. br.Msg = "请登录"
  4941. br.ErrMsg = "请登录,SysUser Is Empty"
  4942. br.Ret = 408
  4943. return
  4944. }
  4945. var req company.MoveSellerReq
  4946. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4947. if err != nil {
  4948. br.Msg = "参数解析异常!"
  4949. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4950. return
  4951. }
  4952. if req.CompanyId <= 0 {
  4953. br.Msg = "参数异常!"
  4954. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  4955. return
  4956. }
  4957. if req.SellsId <= 0 {
  4958. br.Msg = "参数异常!"
  4959. br.ErrMsg = "SellsId:" + strconv.Itoa(req.SellsId)
  4960. return
  4961. }
  4962. seller, err := system.GetSysAdminById(req.SellsId)
  4963. if err != nil {
  4964. br.Msg = "获取销售信息失败"
  4965. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  4966. return
  4967. }
  4968. roleTypeCode := sysUser.RoleTypeCode
  4969. productId := services.GetProductId(roleTypeCode)
  4970. if productId == 0 {
  4971. if req.CompanyType == utils.COMPANY_CLASSIFY_FICC {
  4972. productId = 1
  4973. } else if req.CompanyType == utils.COMPANY_CLASSIFY_RAI {
  4974. productId = 2
  4975. }
  4976. }
  4977. if productId == 0 {
  4978. br.Msg = "无效的客户类型"
  4979. br.ErrMsg = "无效的客户类型"
  4980. return
  4981. }
  4982. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  4983. //查询客户的产品权限
  4984. companyReportPermissionListOld, err := company.GetCompanyReportPermission(req.CompanyId, productId)
  4985. if err != nil {
  4986. br.Msg = "查询客户的产品权限异常"
  4987. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  4988. return
  4989. }
  4990. var isNoResearch bool
  4991. for _, v := range companyReportPermissionListOld {
  4992. if v.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN && v.ChartPermissionId != utils.YAN_XUAN_KOU_DIAN_BAO_ID {
  4993. isNoResearch = true
  4994. continue
  4995. }
  4996. }
  4997. //如果所选行业不属于研选订阅跟研选扣点包,那就是非研选试用客户
  4998. if isNoResearch {
  4999. tryOutCountRai, err := company.GetRaiCompanyTryOutCountNoResearch(req.SellsId)
  5000. if err != nil {
  5001. br.Msg = "判断试用客户量失败"
  5002. br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  5003. return
  5004. }
  5005. if tryOutCountRai >= utils.COMPANY_STATUS_TRY_OUT_COUNT_RAI {
  5006. br.Msg = seller.RealName + "的非研选试用客户已超过40家"
  5007. return
  5008. }
  5009. }
  5010. }
  5011. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  5012. if err != nil && err.Error() != utils.ErrNoRow() {
  5013. if err.Error() == utils.ErrNoRow() {
  5014. br.Msg = "客户信息不存在"
  5015. br.ErrMsg = "客户信息不存在,Err:" + err.Error()
  5016. return
  5017. }
  5018. br.Msg = "获取客户信息失败"
  5019. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  5020. return
  5021. }
  5022. if cp == nil {
  5023. br.Msg = "客户信息不存在,请刷新页面"
  5024. br.ErrMsg = "客户信息不存在"
  5025. return
  5026. }
  5027. err = company.MoveCompanySeller(req.CompanyId, productId, req.SellsId, seller.GroupId, seller.DepartmentId, seller.RealName)
  5028. if err != nil {
  5029. br.Msg = "移动失败"
  5030. br.ErrMsg = "移动失败,Err:" + err.Error()
  5031. return
  5032. }
  5033. //新增操作记录
  5034. {
  5035. remark := "移动到:" + seller.RealName
  5036. operation := "move_seller"
  5037. services.AddCompanyOperationRecord(req.CompanyId, seller.AdminId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
  5038. cp.ProductName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
  5039. }
  5040. //变更销售员与联系人关系
  5041. _ = models.UpdateUserSellerRelationByCompanyId(req.CompanyId, productId, seller.AdminId, seller.RealName)
  5042. br.Ret = 200
  5043. br.Success = true
  5044. br.Msg = "移动成功"
  5045. }
  5046. // @Title 修改试用客户标签
  5047. // @Description 修改试用客户标签接口
  5048. // @Param request body company.UpdateTryStageReq true "type json string"
  5049. // @Success Ret=200 设置成功
  5050. // @router /update/tryStage [post]
  5051. func (this *CompanyController) UpdateTryStage() {
  5052. br := new(models.BaseResponse).Init()
  5053. defer func() {
  5054. this.Data["json"] = br
  5055. this.ServeJSON()
  5056. }()
  5057. sysUser := this.SysUser
  5058. if sysUser == nil {
  5059. br.Msg = "请登录"
  5060. br.ErrMsg = "请登录,SysUser Is Empty"
  5061. br.Ret = 408
  5062. return
  5063. }
  5064. var req company.UpdateTryStageReq
  5065. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5066. if err != nil {
  5067. br.Msg = "参数解析异常!"
  5068. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5069. return
  5070. }
  5071. if req.CompanyId <= 0 {
  5072. br.Msg = "参数异常!"
  5073. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  5074. return
  5075. }
  5076. if req.ProductId <= 0 {
  5077. br.Msg = "参数异常!"
  5078. br.ErrMsg = "ProductId:" + strconv.Itoa(req.ProductId)
  5079. return
  5080. }
  5081. if req.TryStage <= 0 {
  5082. br.Msg = "参数异常!"
  5083. br.ErrMsg = "TryStage:" + strconv.Itoa(req.TryStage)
  5084. return
  5085. }
  5086. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  5087. if err != nil && err.Error() != utils.ErrNoRow() {
  5088. if err.Error() == utils.ErrNoRow() {
  5089. br.Msg = "客户信息不存在"
  5090. br.ErrMsg = "客户信息不存在,Err:" + err.Error()
  5091. return
  5092. }
  5093. br.Msg = "获取客户信息失败"
  5094. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  5095. return
  5096. }
  5097. fmt.Println(cp)
  5098. if cp == nil {
  5099. br.Msg = "客户信息不存在,请刷新页面"
  5100. br.ErrMsg = "客户信息不存在"
  5101. return
  5102. }
  5103. if cp.Status != "试用" {
  5104. br.Msg = "客户不是试用状态,不允许修改"
  5105. br.ErrMsg = "客户不是试用状态,不允许修改"
  5106. return
  5107. }
  5108. if cp.SellerId != sysUser.AdminId {
  5109. br.Msg = "无修改权限"
  5110. br.ErrMsg = "无修改权限"
  5111. return
  5112. }
  5113. if cp.TryStage == req.TryStage {
  5114. br.Msg = "与原标签一致,无需修改"
  5115. br.ErrMsg = "与原标签一致,无需修改"
  5116. return
  5117. }
  5118. err = company.UpdateCompanyTryStage(req.CompanyId, req.ProductId, req.TryStage)
  5119. if err != nil {
  5120. br.Msg = "设置失败"
  5121. br.ErrMsg = "设置失败,Err:" + err.Error()
  5122. return
  5123. }
  5124. //新增操作记录
  5125. {
  5126. stage := ""
  5127. tryStageAllMap := map[int]string{
  5128. 1: "未分类",
  5129. 2: "推进",
  5130. 3: "跟踪",
  5131. 4: "预备",
  5132. }
  5133. if v, ok := tryStageAllMap[req.TryStage]; ok {
  5134. stage = v
  5135. }
  5136. remark := "修改试用客户子标签:" + stage
  5137. operation := "UpdateTryStage"
  5138. services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  5139. cp.ProductName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
  5140. }
  5141. br.Ret = 200
  5142. br.Success = true
  5143. br.Msg = "设置成功"
  5144. }
  5145. // @Title 暂停/启用
  5146. // @Description 暂停/启用接口
  5147. // @Param request body company.SuspendReq true "type json string"
  5148. // @Success Ret=200 移动成功
  5149. // @router /suspend [post]
  5150. func (this *CompanyController) Suspend() {
  5151. br := new(models.BaseResponse).Init()
  5152. defer func() {
  5153. this.Data["json"] = br
  5154. this.ServeJSON()
  5155. }()
  5156. sysUser := this.SysUser
  5157. if sysUser == nil {
  5158. br.Msg = "请登录"
  5159. br.ErrMsg = "请登录,SysUser Is Empty"
  5160. br.Ret = 408
  5161. return
  5162. }
  5163. var req company.SuspendReq
  5164. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5165. if err != nil {
  5166. br.Msg = "参数解析异常!"
  5167. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5168. return
  5169. }
  5170. if req.CompanyId <= 0 {
  5171. br.Msg = "参数异常!"
  5172. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  5173. return
  5174. }
  5175. roleTypeCode := sysUser.RoleTypeCode
  5176. productId := services.GetProductId(roleTypeCode)
  5177. if productId == 0 {
  5178. br.Msg = "参数错误"
  5179. br.ErrMsg = "角色类型为:" + roleTypeCode
  5180. return
  5181. }
  5182. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  5183. if err != nil {
  5184. br.Msg = "获取数据异常!"
  5185. br.ErrMsg = "获取数据异常:" + err.Error()
  5186. return
  5187. }
  5188. suspendStatus := ""
  5189. suspend := 0
  5190. if cp.IsSuspend == 1 {
  5191. suspendStatus = "启用"
  5192. suspend = 0
  5193. } else {
  5194. suspendStatus = "暂停"
  5195. suspend = 1
  5196. }
  5197. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  5198. br.Msg = "客户状态为:" + cp.Status + ",不允许进行" + suspendStatus + "操作"
  5199. br.ErrMsg = "客户状态为:" + cp.Status + ",不允许进行" + suspendStatus + "操作"
  5200. return
  5201. }
  5202. err = company.SuspendCompanyProductById(req.CompanyId, productId, suspend)
  5203. if err != nil {
  5204. br.Msg = suspendStatus + "失败"
  5205. br.ErrMsg = suspendStatus + "失败 Err:" + err.Error()
  5206. return
  5207. }
  5208. //新增操作记录
  5209. {
  5210. remark := suspendStatus
  5211. operation := "is_suspend"
  5212. services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
  5213. cp.ProductName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
  5214. }
  5215. br.Ret = 200
  5216. br.Success = true
  5217. br.Msg = suspendStatus + "成功"
  5218. }
  5219. // @Title 检测客户名称或社会信用码
  5220. // @Description 检测客户名称或社会信用码接口(新增/编辑客户页面使用)
  5221. // @Param CompanyName query string true "客户名称"
  5222. // @Param CreditCode query string true "社会统一信用码"
  5223. // @Success 200 {object} company.CheckCompanyInfoResp
  5224. // @router /check/companyInfo [get]
  5225. func (this *CompanyController) CheckCompanyInfo() {
  5226. br := new(models.BaseResponse).Init()
  5227. defer func() {
  5228. this.Data["json"] = br
  5229. this.ServeJSON()
  5230. }()
  5231. sysUser := this.SysUser
  5232. if sysUser == nil {
  5233. br.Msg = "请登录"
  5234. br.ErrMsg = "请登录,SysUser Is Empty"
  5235. br.Ret = 408
  5236. return
  5237. }
  5238. roleTypeCode := sysUser.RoleTypeCode
  5239. productId := services.GetProductId(roleTypeCode)
  5240. companyName := this.GetString("CompanyName")
  5241. creditCode := this.GetString("CreditCode")
  5242. var status, comanyId int
  5243. var productName string
  5244. if productId == 0 {
  5245. productId = 1
  5246. checkProductId := 2
  5247. if companyName != "" {
  5248. nameItem, err := company.CheckCompanyProductByName(companyName, productId)
  5249. if err != nil && err.Error() != utils.ErrNoRow() {
  5250. br.Msg = "校验客户名称是否存在失败"
  5251. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
  5252. return
  5253. }
  5254. if nameItem != nil && nameItem.CompanyId > 0 {
  5255. br.Msg = "客户名称已存在,请重新填写"
  5256. br.ErrMsg = "客户名称已存在,请重新填写"
  5257. br.Ret = 405
  5258. return
  5259. }
  5260. nameCheckItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
  5261. if err != nil && err.Error() != utils.ErrNoRow() {
  5262. br.Msg = "校验客户名称是否存在失败"
  5263. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5264. return
  5265. }
  5266. if nameCheckItem != nil && nameCheckItem.CompanyId > 0 {
  5267. status = 1
  5268. productName = nameCheckItem.ProductName
  5269. comanyId = nameCheckItem.CompanyId
  5270. goto Loop
  5271. }
  5272. }
  5273. if creditCode != "" {
  5274. codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
  5275. if err != nil && err.Error() != utils.ErrNoRow() {
  5276. br.Msg = "校验社会信用码是否存在失败"
  5277. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
  5278. return
  5279. }
  5280. if codeItem != nil && codeItem.CompanyId > 0 {
  5281. br.Msg = "社会信用码已存在,请重新填写"
  5282. br.ErrMsg = "社会信用码已存在,请重新填写"
  5283. br.Ret = 405
  5284. return
  5285. }
  5286. codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
  5287. if err != nil && err.Error() != utils.ErrNoRow() {
  5288. br.Msg = "校验社会信用码是否存在失败"
  5289. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5290. return
  5291. }
  5292. if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
  5293. status = 1
  5294. productName = codeCheckItem.ProductName
  5295. comanyId = codeCheckItem.CompanyId
  5296. goto Loop
  5297. }
  5298. }
  5299. productId = 2
  5300. checkProductId = 1
  5301. if companyName != "" {
  5302. nameItem, err := company.CheckCompanyProductByName(companyName, productId)
  5303. if err != nil && err.Error() != utils.ErrNoRow() {
  5304. br.Msg = "校验客户名称是否存在失败"
  5305. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
  5306. return
  5307. }
  5308. if nameItem != nil && nameItem.CompanyId > 0 {
  5309. br.Msg = "客户名称已存在,请重新填写"
  5310. br.ErrMsg = "客户名称已存在,请重新填写"
  5311. br.Ret = 405
  5312. return
  5313. }
  5314. nameCheckItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
  5315. if err != nil && err.Error() != utils.ErrNoRow() {
  5316. br.Msg = "校验客户名称是否存在失败"
  5317. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5318. return
  5319. }
  5320. if nameCheckItem != nil && nameCheckItem.CompanyId > 0 {
  5321. status = 1
  5322. productName = nameCheckItem.ProductName
  5323. comanyId = nameCheckItem.CompanyId
  5324. goto Loop
  5325. }
  5326. }
  5327. if creditCode != "" {
  5328. codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
  5329. if err != nil && err.Error() != utils.ErrNoRow() {
  5330. br.Msg = "校验社会信用码是否存在失败"
  5331. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
  5332. return
  5333. }
  5334. if codeItem != nil && codeItem.CompanyId > 0 {
  5335. br.Msg = "社会信用码已存在,请重新填写"
  5336. br.ErrMsg = "社会信用码已存在,请重新填写"
  5337. br.Ret = 405
  5338. return
  5339. }
  5340. codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
  5341. if err != nil && err.Error() != utils.ErrNoRow() {
  5342. br.Msg = "校验社会信用码是否存在失败"
  5343. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5344. return
  5345. }
  5346. if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
  5347. status = 1
  5348. productName = codeCheckItem.ProductName
  5349. comanyId = codeCheckItem.CompanyId
  5350. goto Loop
  5351. }
  5352. }
  5353. } else {
  5354. checkProductId := 0
  5355. if productId == 1 {
  5356. checkProductId = 2
  5357. } else if productId == 2 {
  5358. checkProductId = 1
  5359. }
  5360. if companyName != "" {
  5361. nameItem, err := company.CheckCompanyProductByName(companyName, productId)
  5362. if err != nil && err.Error() != utils.ErrNoRow() {
  5363. br.Msg = "校验客户名称是否存在失败"
  5364. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
  5365. return
  5366. }
  5367. if nameItem != nil && nameItem.ProductName != "" {
  5368. br.Msg = "客户名称已存在,请重新填写"
  5369. br.ErrMsg = "客户名称已存在,请重新填写"
  5370. br.Ret = 405
  5371. return
  5372. }
  5373. nameCheckoutItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
  5374. if err != nil && err.Error() != utils.ErrNoRow() {
  5375. br.Msg = "校验客户名称是否存在失败"
  5376. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5377. return
  5378. }
  5379. if nameCheckoutItem != nil && nameCheckoutItem.CompanyId > 0 {
  5380. status = 1
  5381. productName = nameCheckoutItem.ProductName
  5382. comanyId = nameCheckoutItem.CompanyId
  5383. goto Loop
  5384. }
  5385. }
  5386. if creditCode != "" {
  5387. codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
  5388. if err != nil && err.Error() != utils.ErrNoRow() {
  5389. br.Msg = "校验社会信用码是否存在失败"
  5390. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
  5391. return
  5392. }
  5393. if codeItem != nil && codeItem.CompanyId > 0 {
  5394. br.Msg = "社会信用码已存在,请重新填写"
  5395. br.ErrMsg = "社会信用码已存在,请重新填写"
  5396. br.Ret = 405
  5397. return
  5398. }
  5399. codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
  5400. if err != nil && err.Error() != utils.ErrNoRow() {
  5401. br.Msg = "校验社会信用码是否存在失败"
  5402. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5403. return
  5404. }
  5405. if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
  5406. status = 1
  5407. productName = codeCheckItem.ProductName
  5408. comanyId = codeCheckItem.CompanyId
  5409. goto Loop
  5410. }
  5411. }
  5412. }
  5413. Loop:
  5414. resp := new(company.CheckCompanyInfoResp)
  5415. resp.Status = status
  5416. resp.ProductName = productName
  5417. resp.CompanyId = comanyId
  5418. br.Ret = 200
  5419. br.Success = true
  5420. br.Msg = "获取成功"
  5421. br.Data = resp
  5422. }
  5423. // @Title 客户导出
  5424. // @Description 客户导出接口
  5425. // @Param Status query string true "状态:'试用','永续','冻结','流失','正式'"
  5426. // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
  5427. // @Param IndustryId query int true "行业id,0为全部"
  5428. // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
  5429. // @Param ChartPermissionIds query string false "阅读权限品种ID,多个用英文逗号分开,空字符串为全部"
  5430. // @Param ContractPermissionIds query string false "已购品种ID,多个用英文逗号分开,空字符串为全部"
  5431. // @Param StartDate query string true "开始时间"
  5432. // @Param EndDate query string true "结束时间"
  5433. // @Param CreateStartDate query string true "创建开始时间"
  5434. // @Param CreateEndDate query string true "创建结束时间"
  5435. // @Param KeyWord query string true "搜索关键词"
  5436. // @Param Address query string true "地址 , 多个用英文逗号分开 "
  5437. // @Param Province query string true "省 , 多个用英文逗号分开 "
  5438. // @Param City query string true "市 , 多个用英文逗号分开 "
  5439. // @Param PackageType query int true "套餐类型,0:无,1:大套餐,2:小套餐"
  5440. // @Success 200 {object} company.CompanyListResp
  5441. // @router /export [get]
  5442. func (this *CompanyController) Export() {
  5443. br := new(models.BaseResponse).Init()
  5444. defer func() {
  5445. this.Data["json"] = br
  5446. this.ServeJSON()
  5447. }()
  5448. sysUser := this.SysUser
  5449. if sysUser == nil {
  5450. br.Msg = "请登录"
  5451. br.ErrMsg = "请登录,SysUser Is Empty"
  5452. br.Ret = 408
  5453. return
  5454. }
  5455. roleTypeCode := sysUser.RoleTypeCode
  5456. status := this.GetString("Status")
  5457. companyType := this.GetString("CompanyType")
  5458. industryId, _ := this.GetInt("IndustryId")
  5459. adminId := this.GetString("AdminId")
  5460. chartPermissionIds := this.GetString("ChartPermissionIds")
  5461. contractPermissionIds := this.GetString("ContractPermissionIds")
  5462. startDate := this.GetString("StartDate")
  5463. endDate := this.GetString("EndDate")
  5464. createStartDate := this.GetString("CreateStartDate")
  5465. createEndDate := this.GetString("CreateEndDate")
  5466. keyWord := this.GetString("KeyWord")
  5467. keyWord = strings.Trim(keyWord, " ")
  5468. address := this.GetString("Address")
  5469. province := this.GetString("Province")
  5470. city := this.GetString("City")
  5471. // 套餐类型
  5472. packageType, _ := this.GetInt("PackageType")
  5473. resp := new(company.CompanyListResp)
  5474. statusItems := make([]*company.CompanyStatus, 0)
  5475. var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}
  5476. var condition string
  5477. var pars []interface{}
  5478. //状态分类查询条件
  5479. var permissionCondition string
  5480. var permissionPars []interface{}
  5481. if companyType != "" {
  5482. condition += ` AND b.product_name=? `
  5483. pars = append(pars, companyType)
  5484. }
  5485. if industryId > 0 {
  5486. condition += ` AND b.industry_id=? `
  5487. pars = append(pars, industryId)
  5488. }
  5489. if adminId != "" {
  5490. condition += ` AND b.seller_id IN (` + adminId + `) `
  5491. }
  5492. if startDate != "" {
  5493. condition += ` AND b.start_date>=? `
  5494. pars = append(pars, startDate)
  5495. }
  5496. if endDate != "" {
  5497. condition += ` AND b.end_date<=? `
  5498. pars = append(pars, endDate)
  5499. }
  5500. if createStartDate != "" {
  5501. condition += ` AND a.created_time>=? `
  5502. pars = append(pars, createStartDate)
  5503. }
  5504. if createEndDate != "" {
  5505. condition += ` AND a.created_time<=? `
  5506. pars = append(pars, createEndDate)
  5507. }
  5508. if address != "" {
  5509. var addressSql string
  5510. slice := strings.Split(address, ",")
  5511. for _, v := range slice {
  5512. addressSql += "'" + v + "'" + ","
  5513. }
  5514. addressSql = strings.TrimRight(addressSql, ",")
  5515. condition += ` AND a.address IN (` + addressSql + `) `
  5516. }
  5517. if province != "" {
  5518. var provinceSql string
  5519. slice := strings.Split(province, ",")
  5520. for _, v := range slice {
  5521. provinceSql += "'" + v + "'" + ","
  5522. }
  5523. provinceSql = strings.TrimRight(provinceSql, ",")
  5524. condition += ` AND a.province IN (` + provinceSql + `) `
  5525. }
  5526. if city != "" {
  5527. var citySql string
  5528. slice := strings.Split(city, ",")
  5529. for _, v := range slice {
  5530. citySql += "'" + v + "'" + ","
  5531. }
  5532. citySql = strings.TrimRight(citySql, ",")
  5533. condition += ` AND a.city IN (` + citySql + `) `
  5534. }
  5535. if keyWord != "" {
  5536. companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
  5537. if err != nil {
  5538. br.Msg = "获取客户信息失败"
  5539. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  5540. return
  5541. }
  5542. if companyIdStr != "" {
  5543. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  5544. } else {
  5545. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  5546. }
  5547. }
  5548. //if chartPermissionIds != "" && chartPermissionIds != "1" {
  5549. // companyIdStr, err := company.GetCompanyListCompanyIdByPermissionIdStr(chartPermissionIds)
  5550. // if err != nil {
  5551. // br.Msg = "获取失败"
  5552. // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
  5553. // return
  5554. // }
  5555. // if companyIdStr != "" {
  5556. // condition += ` AND a.company_id IN (` + companyIdStr + `) `
  5557. // } else {
  5558. // for _, v := range statusArr {
  5559. // statusCount := new(company.CompanyStatus)
  5560. // if v == "全部" {
  5561. // statusCount.Status = "全部"
  5562. // statusCount.Count = 0
  5563. // } else {
  5564. // statusCount.Status = v
  5565. // statusCount.Count = 0
  5566. // }
  5567. // statusItems = append(statusItems, statusCount)
  5568. // }
  5569. // items := make([]*company.CompanyListItem, 0)
  5570. // resp.List = items
  5571. // resp.StatusCount = statusItems
  5572. // br.Msg = "获取成功"
  5573. // br.Ret = 200
  5574. // br.Data = resp
  5575. // return
  5576. // }
  5577. //}
  5578. // 阅读权限/已购品种筛选
  5579. cond, emp, e := services.FilterReadAndContractAuth(chartPermissionIds, contractPermissionIds, condition)
  5580. if e != nil {
  5581. br.Msg = "获取失败"
  5582. br.ErrMsg = "FilterReadAndContractAuth err: " + e.Error()
  5583. return
  5584. }
  5585. if emp {
  5586. for _, v := range statusArr {
  5587. statusCount := new(company.CompanyStatus)
  5588. if v == "全部" {
  5589. statusCount.Status = "全部"
  5590. statusCount.Count = 0
  5591. } else {
  5592. statusCount.Status = v
  5593. statusCount.Count = 0
  5594. }
  5595. statusItems = append(statusItems, statusCount)
  5596. }
  5597. items := make([]*company.CompanyListItem, 0)
  5598. resp.List = items
  5599. resp.StatusCount = statusItems
  5600. br.Msg = "获取成功"
  5601. br.Ret = 200
  5602. br.Data = resp
  5603. return
  5604. }
  5605. condition = cond
  5606. //套餐类型
  5607. if packageType > 0 {
  5608. condition += ` AND b.package_type=? `
  5609. pars = append(pars, packageType)
  5610. }
  5611. permissionCondition = condition
  5612. permissionPars = pars
  5613. productId := services.GetProductId(roleTypeCode)
  5614. //权限控制
  5615. {
  5616. //如果不是超级管理员
  5617. if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  5618. //如果是部门管理员
  5619. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  5620. condition += ` AND b.product_id=? `
  5621. pars = append(pars, productId)
  5622. permissionCondition += ` AND b.product_id=? `
  5623. permissionPars = append(permissionPars, productId)
  5624. } else {
  5625. condition += ` AND b.product_id=? `
  5626. pars = append(pars, productId)
  5627. permissionCondition += ` AND b.product_id=? `
  5628. permissionPars = append(permissionPars, productId)
  5629. if status == "全部" {
  5630. ////如果是筛选了流失客户状态
  5631. if sysUser.Authority <= 0 {
  5632. condition += ` AND (b.seller_id=? OR status='流失') `
  5633. pars = append(pars, sysUser.AdminId)
  5634. permissionCondition += ` AND b.seller_id=? `
  5635. permissionPars = append(permissionPars, sysUser.AdminId)
  5636. } else {
  5637. if sysUser.Authority == 1 {
  5638. condition += ` AND (b.department_id=? OR status='流失')`
  5639. pars = append(pars, sysUser.DepartmentId)
  5640. permissionCondition += ` AND b.department_id=? `
  5641. permissionPars = append(permissionPars, sysUser.DepartmentId)
  5642. }
  5643. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  5644. if status != utils.COMPANY_STATUS_LOSE {
  5645. condition += ` AND (b.group_id=? OR status='流失') `
  5646. pars = append(pars, sysUser.GroupId)
  5647. }
  5648. permissionCondition += ` AND b.group_id=? `
  5649. permissionPars = append(permissionPars, sysUser.GroupId)
  5650. }
  5651. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  5652. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  5653. if err != nil {
  5654. br.Msg = "获取失败"
  5655. br.ErrMsg = "查询父级id异常" + err.Error()
  5656. return
  5657. }
  5658. var ids []*string
  5659. if pid != nil && *pid != 0 {
  5660. ids, err = company.GetGroupIdsByParentId(*pid)
  5661. if err != nil {
  5662. fmt.Println(err.Error())
  5663. }
  5664. } else {
  5665. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  5666. if err != nil {
  5667. fmt.Println(err.Error())
  5668. }
  5669. }
  5670. var idSlice []string
  5671. var sid string
  5672. for _, id := range ids {
  5673. idSlice = append(idSlice, *id)
  5674. }
  5675. //加入父级groupId
  5676. if *pid > 0 {
  5677. idSlice = append(idSlice, strconv.Itoa(*pid))
  5678. } else {
  5679. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  5680. }
  5681. sid = strings.Join(idSlice, ",")
  5682. if len(sid) > 0 {
  5683. if status != utils.COMPANY_STATUS_LOSE {
  5684. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  5685. //pars = append(pars, sysUser.GroupId)
  5686. }
  5687. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  5688. } else {
  5689. if status != utils.COMPANY_STATUS_LOSE {
  5690. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  5691. //pars = append(pars, sysUser.GroupId)
  5692. }
  5693. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  5694. }
  5695. }
  5696. }
  5697. } else {
  5698. ////如果没有筛选了流失客户状态
  5699. if sysUser.Authority <= 0 {
  5700. condition += ` AND b.seller_id=? `
  5701. pars = append(pars, sysUser.AdminId)
  5702. permissionCondition += ` AND b.seller_id=? `
  5703. permissionPars = append(permissionPars, sysUser.AdminId)
  5704. } else {
  5705. if sysUser.Authority == 1 {
  5706. condition += ` AND b.department_id=?`
  5707. pars = append(pars, sysUser.DepartmentId)
  5708. permissionCondition += ` AND b.department_id=? `
  5709. permissionPars = append(permissionPars, sysUser.DepartmentId)
  5710. }
  5711. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  5712. if status != utils.COMPANY_STATUS_LOSE {
  5713. condition += ` AND b.group_id=? `
  5714. pars = append(pars, sysUser.GroupId)
  5715. }
  5716. permissionCondition += ` AND b.group_id=? `
  5717. permissionPars = append(permissionPars, sysUser.GroupId)
  5718. }
  5719. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  5720. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  5721. if err != nil {
  5722. br.Msg = "获取失败"
  5723. br.ErrMsg = "查询父级id异常" + err.Error()
  5724. return
  5725. }
  5726. var ids []*string
  5727. if pid != nil && *pid != 0 {
  5728. ids, err = company.GetGroupIdsByParentId(*pid)
  5729. if err != nil {
  5730. fmt.Println(err.Error())
  5731. }
  5732. } else {
  5733. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  5734. if err != nil {
  5735. fmt.Println(err.Error())
  5736. }
  5737. }
  5738. var idSlice []string
  5739. var sid string
  5740. for _, id := range ids {
  5741. idSlice = append(idSlice, *id)
  5742. }
  5743. //加入父级groupId
  5744. if *pid > 0 {
  5745. idSlice = append(idSlice, strconv.Itoa(*pid))
  5746. } else {
  5747. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  5748. }
  5749. sid = strings.Join(idSlice, ",")
  5750. if len(sid) > 0 {
  5751. if status != utils.COMPANY_STATUS_LOSE {
  5752. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  5753. //pars = append(pars, sysUser.GroupId)
  5754. }
  5755. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  5756. } else {
  5757. if status != utils.COMPANY_STATUS_LOSE {
  5758. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  5759. //pars = append(pars, sysUser.GroupId)
  5760. }
  5761. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  5762. }
  5763. }
  5764. if sysUser.Authority == 4 {
  5765. if status != utils.COMPANY_STATUS_LOSE {
  5766. condition += ` AND b.group_id =? `
  5767. pars = append(pars, sysUser.GroupId)
  5768. }
  5769. permissionCondition += ` AND b.group_id=? `
  5770. permissionPars = append(permissionPars, sysUser.GroupId)
  5771. }
  5772. }
  5773. }
  5774. }
  5775. }
  5776. }
  5777. //状态控制
  5778. if status != "" && status != "全部" && status != utils.COMPANY_STATUS_LOSE {
  5779. condition += ` AND b.status=? `
  5780. pars = append(pars, status)
  5781. }
  5782. dir, err := os.Executable()
  5783. exPath := filepath.Dir(dir)
  5784. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  5785. xlsxFile := xlsx.NewFile()
  5786. if err != nil {
  5787. br.Msg = "生成文件失败"
  5788. br.ErrMsg = "生成文件失败"
  5789. return
  5790. }
  5791. style := xlsx.NewStyle()
  5792. alignment := xlsx.Alignment{
  5793. Horizontal: "center",
  5794. Vertical: "center",
  5795. WrapText: true,
  5796. }
  5797. style.Alignment = alignment
  5798. style.ApplyAlignment = true
  5799. sheel, err := xlsxFile.AddSheet("客户数据")
  5800. if err != nil {
  5801. br.Msg = "新增Sheet失败"
  5802. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  5803. return
  5804. }
  5805. titleArr := []string{"客户名称", "客户地址", "客户类型", "所属行业", "所属销售", "客户状态", "服务期限", "到期天数", "创建时间", "权限详情"}
  5806. titleLen := len(titleArr)
  5807. titleRow := sheel.AddRow()
  5808. remarkRow := sheel.AddRow() // 备注行
  5809. // 填充空白至Z列
  5810. emptyColNum := 0
  5811. for i := 0; i < 26; i++ {
  5812. remarkRow.AddCell().SetValue("")
  5813. if i >= titleLen {
  5814. emptyColNum += 1
  5815. titleRow.AddCell().SetValue("")
  5816. continue
  5817. }
  5818. titleRow.AddCell().SetValue(titleArr[i])
  5819. }
  5820. // AA列开始为品种权限
  5821. ficcPermissions := make([]int, 0) // 用于后续判断试用暂停客户是否需要暂停这部分权限
  5822. raiPermissions := make([]int, 0)
  5823. permissions, e := models.GetChartPermissionList()
  5824. if e != nil {
  5825. br.Msg = "获取失败"
  5826. br.ErrMsg = "获取品种数据失败,Err:" + err.Error()
  5827. return
  5828. }
  5829. raiArr := []string{"医药", "消费", "科技", "智造"}
  5830. for _, p := range permissions {
  5831. if p.ProductId == 1 {
  5832. ficcPermissions = append(ficcPermissions, p.ChartPermissionId)
  5833. }
  5834. if p.ProductId == 2 {
  5835. raiPermissions = append(raiPermissions, p.ChartPermissionId)
  5836. }
  5837. if utils.InArrayByStr(raiArr, p.PermissionName) {
  5838. titleRow.AddCell().SetValue(p.Remark)
  5839. continue
  5840. }
  5841. titleRow.AddCell().SetValue(p.PermissionName)
  5842. }
  5843. // 第二行, 在品种权限开始列加一行标红备注
  5844. styleRed := xlsx.NewStyle()
  5845. styleRed.Font.Color = "ff0000"
  5846. remarkCell := remarkRow.AddCell()
  5847. remarkCell.SetStyle(styleRed)
  5848. remarkCell.SetString(`第一位数字表示是否已购买该品种,1表示已购,0表示未购;第二位数字表示是否有阅读权限,1表示有权限,0表示没有`)
  5849. list, err := company.GetCompanyListExport(condition, pars)
  5850. if err != nil {
  5851. br.Msg = "获取失败"
  5852. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  5853. return
  5854. }
  5855. companyIds := make([]int, 0)
  5856. for _, c := range list {
  5857. companyIds = append(companyIds, c.CompanyId)
  5858. }
  5859. // 获取客户对应的阅读和合同权限集合
  5860. contractPermissionMap := make(map[int][]int)
  5861. contractPermissions, e := company.GetContractPermissionIdsByCompanyIds(companyIds)
  5862. if e != nil {
  5863. br.Msg = "获取失败"
  5864. br.ErrMsg = "获取已购权限失败, Err: " + e.Error()
  5865. return
  5866. }
  5867. for _, p := range contractPermissions {
  5868. ids := make([]int, 0)
  5869. if p.ChartPermissionIds != "" {
  5870. idArr := strings.Split(p.ChartPermissionIds, ",")
  5871. for _, i := range idArr {
  5872. id, _ := strconv.Atoi(i)
  5873. ids = append(ids, id)
  5874. }
  5875. }
  5876. contractPermissionMap[p.CompanyId] = ids
  5877. }
  5878. reportPermissionMap := make(map[int][]int)
  5879. reportPermissions, e := company.GetReportPermissionIdsByCompanyIds(companyIds)
  5880. if e != nil {
  5881. br.Msg = "获取失败"
  5882. br.ErrMsg = "获取阅读权限失败, Err: " + e.Error()
  5883. return
  5884. }
  5885. for _, p := range reportPermissions {
  5886. ids := make([]int, 0)
  5887. if p.ChartPermissionIds != "" {
  5888. idArr := strings.Split(p.ChartPermissionIds, ",")
  5889. for _, i := range idArr {
  5890. id, _ := strconv.Atoi(i)
  5891. ids = append(ids, id)
  5892. }
  5893. }
  5894. reportPermissionMap[p.CompanyId] = ids
  5895. }
  5896. cpMap := make(map[int][]*company.ExportCompanyProduct)
  5897. permissionMap := make(map[string]string)
  5898. for _, v := range list {
  5899. cpList := make([]*company.ExportCompanyProduct, 1)
  5900. if cps, ok := cpMap[v.CompanyId]; ok {
  5901. cpList = cps
  5902. } else {
  5903. companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  5904. if err != nil {
  5905. br.Msg = "导出失败"
  5906. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  5907. return
  5908. }
  5909. cpMap[v.CompanyId] = companyProduct
  5910. cpList = companyProduct
  5911. }
  5912. var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, expireDay string
  5913. isFiccSuspend := 0
  5914. isRaiSuspend := 0
  5915. for ck, cv := range cpList {
  5916. companyName = cv.CompanyName
  5917. if ck >= 1 {
  5918. companyType = companyType + "/" + cv.ProductName
  5919. status = status + "/" + cv.Status
  5920. } else {
  5921. companyType = cv.ProductName
  5922. status = cv.Status
  5923. }
  5924. if cv.ProductId == 1 {
  5925. industryName = "ficc:" + cv.IndustryName
  5926. sellerName = "ficc:" + cv.SellerName
  5927. startDateStr := cv.StartDate.Format("2006/01/02")
  5928. endDateStr := cv.EndDate.Format("2006/01/02")
  5929. timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  5930. createTime = "ficc:" + cv.CreateTime
  5931. source = "ficc:" + cv.Source
  5932. sub := cv.EndDate.Sub(time.Now())
  5933. if sub < 0 {
  5934. sub = 0
  5935. }
  5936. expireDay = "ficc:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  5937. permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  5938. permissionStr = "ficc:"
  5939. if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  5940. permissionStr += newPermissionStr
  5941. } else {
  5942. getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  5943. if err != nil {
  5944. br.Msg = "导出失败"
  5945. br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  5946. return
  5947. }
  5948. permissionMap[permissionKey] = getPermissionStr
  5949. permissionStr += getPermissionStr
  5950. }
  5951. isFiccSuspend = cv.IsSuspend
  5952. } else {
  5953. industryName = industryName + "\n" + "权益:" + cv.IndustryName
  5954. sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  5955. startDateStr := cv.StartDate.Format("2006/01/02")
  5956. endDateStr := cv.EndDate.Format("2006/01/02")
  5957. timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  5958. createTime = createTime + "\n" + "权益:" + cv.CreateTime
  5959. source = source + "\n" + "权益:" + cv.Source
  5960. sub := cv.EndDate.Sub(time.Now())
  5961. if sub < 0 {
  5962. sub = 0
  5963. }
  5964. expireDay = "\n" + "权益:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  5965. permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  5966. if permissionStr != "" {
  5967. permissionStr = permissionStr + "\n" + "权益:"
  5968. } else {
  5969. permissionStr = "权益:"
  5970. }
  5971. if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  5972. permissionStr += newPermissionStr
  5973. } else {
  5974. getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  5975. if err != nil {
  5976. br.Msg = "导出失败"
  5977. br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  5978. return
  5979. }
  5980. permissionMap[permissionKey] = getPermissionStr
  5981. permissionStr += getPermissionStr
  5982. }
  5983. isRaiSuspend = cv.IsSuspend
  5984. }
  5985. }
  5986. dataRow := sheel.AddRow()
  5987. dataRow.SetHeight(20)
  5988. dataRow.AddCell().SetString(companyName)
  5989. dataRow.AddCell().SetString(v.Address)
  5990. dataRow.AddCell().SetString(companyType)
  5991. dataRow.AddCell().SetString(v.IndustryName)
  5992. dataRow.AddCell().SetString(v.SellerName)
  5993. dataRow.AddCell().SetString(v.Status)
  5994. dataRow.AddCell().SetString(timeLimt)
  5995. dataRow.AddCell().SetString(expireDay)
  5996. dataRow.AddCell().SetString(v.CreatedTime)
  5997. //dataRow.AddCell().SetString(v.Source)
  5998. dataRow.AddCell().SetString(permissionStr)
  5999. // 填充空白至Z列, AA列开始为权限
  6000. for i := 0; i < emptyColNum; i++ {
  6001. dataRow.AddCell().SetString("")
  6002. }
  6003. cpIds := contractPermissionMap[v.CompanyId]
  6004. rpIds := reportPermissionMap[v.CompanyId]
  6005. for _, p := range permissions {
  6006. // 数字含义:11-表示已购且有阅读权限, 01-表示未购买但有阅读权限
  6007. first := 0
  6008. if utils.InArrayByInt(cpIds, p.ChartPermissionId) {
  6009. first = 1
  6010. }
  6011. second := 0
  6012. if utils.InArrayByInt(rpIds, p.ChartPermissionId) {
  6013. second = 1
  6014. // 如果客户是试用暂停, 即使有这部分权限, 也标记为0
  6015. if isFiccSuspend == 1 && utils.InArrayByInt(ficcPermissions, p.ChartPermissionId) {
  6016. second = 0
  6017. }
  6018. if isRaiSuspend == 1 && utils.InArrayByInt(raiPermissions, p.ChartPermissionId) {
  6019. second = 0
  6020. }
  6021. }
  6022. dataRow.AddCell().SetString(fmt.Sprintf("%d%d", first, second))
  6023. }
  6024. }
  6025. err = xlsxFile.Save(downLoadnFilePath)
  6026. if err != nil {
  6027. br.Msg = "保存文件失败"
  6028. br.ErrMsg = "保存文件失败"
  6029. return
  6030. }
  6031. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  6032. downloadFileName := "客户列表_" + randStr + ".xlsx"
  6033. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  6034. defer func() {
  6035. os.Remove(downLoadnFilePath)
  6036. }()
  6037. br.Ret = 200
  6038. br.Success = true
  6039. br.Msg = "导出成功"
  6040. }
  6041. //func (this *CompanyController) ExportOld() {
  6042. // br := new(models.BaseResponse).Init()
  6043. // defer func() {
  6044. // this.Data["json"] = br
  6045. // this.ServeJSON()
  6046. // }()
  6047. // sysUser := this.SysUser
  6048. // if sysUser == nil {
  6049. // br.Msg = "请登录"
  6050. // br.ErrMsg = "请登录,SysUser Is Empty"
  6051. // br.Ret = 408
  6052. // return
  6053. // }
  6054. // roleTypeCode := sysUser.RoleTypeCode
  6055. //
  6056. // status := this.GetString("Status")
  6057. // companyType := this.GetString("CompanyType")
  6058. // industryId, _ := this.GetInt("IndustryId")
  6059. // adminId := this.GetString("AdminId")
  6060. //
  6061. // chartPermissionIds := this.GetString("ChartPermissionIds")
  6062. // startDate := this.GetString("StartDate")
  6063. // endDate := this.GetString("EndDate")
  6064. // createStartDate := this.GetString("CreateStartDate")
  6065. // createEndDate := this.GetString("CreateEndDate")
  6066. // keyWord := this.GetString("KeyWord")
  6067. // keyWord = strings.Trim(keyWord, " ")
  6068. //
  6069. // resp := new(company.CompanyListResp)
  6070. // statusItems := make([]*company.CompanyStatus, 0)
  6071. // var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}
  6072. //
  6073. // var condition string
  6074. // var pars []interface{}
  6075. //
  6076. // var lossCondition string
  6077. // var lossPars []interface{}
  6078. //
  6079. // var permissionCondition string
  6080. // var permissionPars []interface{}
  6081. //
  6082. // if status != "" && status != "全部" {
  6083. // condition += ` AND b.status=? `
  6084. // pars = append(pars, status)
  6085. //
  6086. // //permissionCondition += ` AND b.status=? `
  6087. // //permissionPars = append(permissionPars, status)
  6088. // }
  6089. // if companyType != "" {
  6090. // condition += ` AND b.product_name=? `
  6091. // pars = append(pars, companyType)
  6092. //
  6093. // lossCondition += ` AND b.product_name=? `
  6094. // lossPars = append(lossPars, companyType)
  6095. //
  6096. // permissionCondition += ` AND b.product_name=? `
  6097. // permissionPars = append(permissionPars, companyType)
  6098. // }
  6099. //
  6100. // if industryId > 0 {
  6101. // condition += ` AND b.industry_id=? `
  6102. // pars = append(pars, industryId)
  6103. //
  6104. // lossCondition += ` AND b.industry_id=? `
  6105. // lossPars = append(lossPars, industryId)
  6106. //
  6107. // permissionCondition += ` AND b.industry_id=? `
  6108. // permissionPars = append(permissionPars, industryId)
  6109. // }
  6110. //
  6111. // if adminId != "" {
  6112. // condition += ` AND b.seller_id IN (` + adminId + `) `
  6113. //
  6114. // lossCondition += ` AND b.seller_id IN (` + adminId + `) `
  6115. //
  6116. // permissionCondition += ` AND b.seller_id IN (` + adminId + `) `
  6117. // }
  6118. //
  6119. // if startDate != "" {
  6120. // condition += ` AND b.start_date>=? `
  6121. // pars = append(pars, startDate)
  6122. //
  6123. // lossCondition += ` AND b.start_date>=? `
  6124. // lossPars = append(lossPars, startDate)
  6125. //
  6126. // permissionCondition += ` AND b.start_date>=? `
  6127. // permissionPars = append(permissionPars, startDate)
  6128. // }
  6129. //
  6130. // if endDate != "" {
  6131. // condition += ` AND b.end_date<=? `
  6132. // pars = append(pars, endDate)
  6133. //
  6134. // lossCondition += ` AND b.end_date<=? `
  6135. // lossPars = append(lossPars, endDate)
  6136. //
  6137. // permissionCondition += ` AND b.end_date<=? `
  6138. // permissionPars = append(permissionPars, endDate)
  6139. // }
  6140. //
  6141. // if createStartDate != "" {
  6142. // condition += ` AND a.created_time>=? `
  6143. // pars = append(pars, createStartDate)
  6144. //
  6145. // lossCondition += ` AND a.created_time>=? `
  6146. // lossPars = append(lossPars, createStartDate)
  6147. //
  6148. // permissionCondition += ` AND a.created_time>=? `
  6149. // permissionPars = append(permissionPars, createStartDate)
  6150. // }
  6151. //
  6152. // if createEndDate != "" {
  6153. // condition += ` AND a.created_time<=? `
  6154. // pars = append(pars, createEndDate)
  6155. //
  6156. // lossCondition += ` AND a.created_time<=? `
  6157. // lossPars = append(lossPars, createEndDate)
  6158. //
  6159. // permissionCondition += ` AND a.created_time<=? `
  6160. // permissionPars = append(permissionPars, createEndDate)
  6161. // }
  6162. //
  6163. // if keyWord != "" {
  6164. // companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
  6165. // if err != nil {
  6166. // return
  6167. // }
  6168. // if companyIdStr != "" {
  6169. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  6170. // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  6171. //
  6172. // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  6173. // } else {
  6174. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  6175. // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  6176. //
  6177. // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  6178. // }
  6179. // }
  6180. //
  6181. // if chartPermissionIds != "" && chartPermissionIds != "1" {
  6182. // //chartPermissionArr := strings.Split(chartPermissionIds, ",")
  6183. // //chartPermissionCount := len(chartPermissionArr)
  6184. // companyIdStr, err := company.GetCompanyListCompanyIdByPermissionIdStr(chartPermissionIds)
  6185. // if err != nil {
  6186. // br.Msg = "获取失败"
  6187. // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
  6188. // return
  6189. // }
  6190. // //var companyIdArr []string
  6191. // //for _, v := range companyIdList {
  6192. // // companyIdArr = append(companyIdArr, strconv.Itoa(v.CompanyId))
  6193. // //}
  6194. // //companyIdStr := strings.Join(companyIdArr, ",")
  6195. //
  6196. // if companyIdStr != "" {
  6197. // condition += ` AND a.company_id IN (` + companyIdStr + `) `
  6198. // lossCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  6199. // permissionCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  6200. // } else {
  6201. // for _, v := range statusArr {
  6202. // statusCount := new(company.CompanyStatus)
  6203. // if v == "全部" {
  6204. // statusCount.Status = "全部"
  6205. // statusCount.Count = 0
  6206. // } else {
  6207. // statusCount.Status = v
  6208. // statusCount.Count = 0
  6209. // }
  6210. // statusItems = append(statusItems, statusCount)
  6211. // }
  6212. // items := make([]*company.CompanyListItem, 0)
  6213. // resp.List = items
  6214. // resp.StatusCount = statusItems
  6215. // br.Msg = "获取成功"
  6216. // br.Ret = 200
  6217. // br.Data = resp
  6218. // return
  6219. // }
  6220. // }
  6221. //
  6222. // //权限控制
  6223. // {
  6224. // if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  6225. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  6226. // condition += ` AND b.product_id=? `
  6227. // pars = append(pars, 1)
  6228. //
  6229. // permissionCondition += ` AND b.product_id=? `
  6230. // permissionPars = append(permissionPars, 1)
  6231. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  6232. // condition += ` AND b.product_id=? `
  6233. // pars = append(pars, 2)
  6234. //
  6235. // permissionCondition += ` AND b.product_id=? `
  6236. // permissionPars = append(permissionPars, 2)
  6237. // } else {
  6238. // if sysUser.Authority <= 0 {
  6239. // if status != utils.COMPANY_STATUS_LOSE {
  6240. // condition += ` AND b.seller_id=? `
  6241. // pars = append(pars, sysUser.AdminId)
  6242. // }
  6243. //
  6244. // permissionCondition += ` AND b.seller_id=? `
  6245. // permissionPars = append(permissionPars, sysUser.AdminId)
  6246. // } else {
  6247. // if sysUser.Authority == 1 {
  6248. // if status != utils.COMPANY_STATUS_LOSE {
  6249. // condition += ` AND b.department_id=? `
  6250. // pars = append(pars, sysUser.DepartmentId)
  6251. // }
  6252. // permissionCondition += ` AND b.department_id=? `
  6253. // permissionPars = append(permissionPars, sysUser.DepartmentId)
  6254. // }
  6255. //
  6256. // if sysUser.Authority == 2 {
  6257. // if status != utils.COMPANY_STATUS_LOSE {
  6258. // condition += ` AND b.group_id=? `
  6259. // pars = append(pars, sysUser.GroupId)
  6260. // }
  6261. // permissionCondition += ` AND b.group_id=? `
  6262. // permissionPars = append(permissionPars, sysUser.GroupId)
  6263. // }
  6264. // }
  6265. // }
  6266. // }
  6267. // }
  6268. //
  6269. // dir, err := os.Executable()
  6270. // exPath := filepath.Dir(dir)
  6271. // downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  6272. // xlsxFile := xlsx.NewFile()
  6273. // if err != nil {
  6274. // br.Msg = "生成文件失败"
  6275. // br.ErrMsg = "生成文件失败"
  6276. // return
  6277. // }
  6278. // style := xlsx.NewStyle()
  6279. // alignment := xlsx.Alignment{
  6280. // Horizontal: "center",
  6281. // Vertical: "center",
  6282. // WrapText: true,
  6283. // }
  6284. //
  6285. // style.Alignment = alignment
  6286. // style.ApplyAlignment = true
  6287. //
  6288. // sheel, err := xlsxFile.AddSheet("客户数据")
  6289. // if err != nil {
  6290. // br.Msg = "新增Sheet失败"
  6291. // br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  6292. // return
  6293. // }
  6294. // titleRow := sheel.AddRow()
  6295. // titleRow.AddCell().SetValue("客户名称")
  6296. // titleRow.AddCell().SetValue("客户类型")
  6297. // titleRow.AddCell().SetValue("所属行业")
  6298. // titleRow.AddCell().SetValue("所属销售")
  6299. // titleRow.AddCell().SetValue("客户状态")
  6300. // titleRow.AddCell().SetValue("服务期限")
  6301. // titleRow.AddCell().SetValue("到期天数")
  6302. // titleRow.AddCell().SetValue("创建时间")
  6303. // titleRow.AddCell().SetValue("客户来源")
  6304. // titleRow.AddCell().SetValue("阅读权限")
  6305. //
  6306. // list, err := company.GetCompanyListExport(condition, pars)
  6307. // if err != nil {
  6308. // br.Msg = "获取失败"
  6309. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  6310. // return
  6311. // }
  6312. // cpMap := make(map[int][]*company.ExportCompanyProduct)
  6313. // permissionMap := make(map[string]string)
  6314. // for _, v := range list {
  6315. // cpList := make([]*company.ExportCompanyProduct, 1)
  6316. // if cps, ok := cpMap[v.CompanyId]; ok {
  6317. // cpList = cps
  6318. // } else {
  6319. // companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  6320. // if err != nil {
  6321. // br.Msg = "导出失败"
  6322. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  6323. // return
  6324. // }
  6325. // cpMap[v.CompanyId] = companyProduct
  6326. // cpList = companyProduct
  6327. // }
  6328. // var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, expireDay string
  6329. //
  6330. // for ck, cv := range cpList {
  6331. // companyName = cv.CompanyName
  6332. // if ck >= 1 {
  6333. // companyType = companyType + "/" + cv.ProductName
  6334. // status = status + "/" + cv.Status
  6335. // } else {
  6336. // companyType = cv.ProductName
  6337. // status = cv.Status
  6338. // }
  6339. // if cv.ProductId == 1 {
  6340. // industryName = "ficc:" + cv.IndustryName
  6341. // sellerName = "ficc:" + cv.SellerName
  6342. // startDateStr := cv.StartDate.Format("2006/01/02")
  6343. // endDateStr := cv.EndDate.Format("2006/01/02")
  6344. // timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  6345. // createTime = "ficc:" + cv.CreateTime
  6346. // source = "ficc:" + cv.Source
  6347. // sub := cv.EndDate.Sub(time.Now())
  6348. // if sub < 0 {
  6349. // sub = 0
  6350. // }
  6351. // expireDay = "ficc:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  6352. //
  6353. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6354. //
  6355. // permissionStr = "ficc:"
  6356. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6357. // permissionStr += newPermissionStr
  6358. // } else {
  6359. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6360. // if err != nil {
  6361. // br.Msg = "导出失败"
  6362. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6363. // return
  6364. // }
  6365. // permissionMap[permissionKey] = getPermissionStr
  6366. // permissionStr += getPermissionStr
  6367. // }
  6368. // } else {
  6369. // industryName = industryName + "\n" + "权益:" + cv.IndustryName
  6370. // sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  6371. // startDateStr := cv.StartDate.Format("2006/01/02")
  6372. // endDateStr := cv.EndDate.Format("2006/01/02")
  6373. //
  6374. // timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  6375. // createTime = createTime + "\n" + "权益:" + cv.CreateTime
  6376. // source = source + "\n" + "权益:" + cv.Source
  6377. //
  6378. // sub := cv.EndDate.Sub(time.Now())
  6379. // if sub < 0 {
  6380. // sub = 0
  6381. // }
  6382. // expireDay = "\n" + "权益:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  6383. //
  6384. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6385. // if permissionStr != "" {
  6386. // permissionStr = permissionStr + "\n" + "权益:"
  6387. // } else {
  6388. // permissionStr = "权益:"
  6389. // }
  6390. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6391. // permissionStr += newPermissionStr
  6392. // } else {
  6393. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6394. // if err != nil {
  6395. // br.Msg = "导出失败"
  6396. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6397. // return
  6398. // }
  6399. // permissionMap[permissionKey] = getPermissionStr
  6400. // permissionStr += getPermissionStr
  6401. // }
  6402. // }
  6403. // }
  6404. //
  6405. // dataRow := sheel.AddRow()
  6406. // dataRow.SetHeight(20)
  6407. // dataRow.AddCell().SetString(companyName)
  6408. // dataRow.AddCell().SetString(companyType)
  6409. // dataRow.AddCell().SetString(v.IndustryName)
  6410. // dataRow.AddCell().SetString(v.SellerName)
  6411. // dataRow.AddCell().SetString(v.Status)
  6412. // dataRow.AddCell().SetString(timeLimt)
  6413. // dataRow.AddCell().SetString(expireDay)
  6414. // dataRow.AddCell().SetString(v.CreatedTime)
  6415. // dataRow.AddCell().SetString(v.Source)
  6416. // dataRow.AddCell().SetString(permissionStr)
  6417. // }
  6418. // err = xlsxFile.Save(downLoadnFilePath)
  6419. // if err != nil {
  6420. // br.Msg = "保存文件失败"
  6421. // br.ErrMsg = "保存文件失败"
  6422. // return
  6423. // }
  6424. // randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  6425. // downloadFileName := "客户列表_" + randStr + ".xlsx"
  6426. // this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  6427. // defer func() {
  6428. // os.Remove(downLoadnFilePath)
  6429. // }()
  6430. // br.Ret = 200
  6431. // br.Success = true
  6432. // br.Msg = "导出成功"
  6433. //}
  6434. // @Title 导出
  6435. // @Description 导出接口
  6436. // @Param Status query string true "状态:”试用','永续','冻结','流失','正式'"
  6437. // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
  6438. // @Param IndustryId query int true "行业id,0为全部"
  6439. // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
  6440. // @Param ChartPermissionIds query string false "阅读权限品种ID,多个用英文逗号分开,空字符串为全部"
  6441. // @Param ContractPermissionIds query string false "已购品种ID,多个用英文逗号分开,空字符串为全部"
  6442. // @Param StartDate query string true "开始时间"
  6443. // @Param EndDate query string true "结束时间"
  6444. // @Param KeyWord query string true "搜索关键词"
  6445. // @Param Address query string true "地址 , 多个用英文逗号分开 "
  6446. // @Param Province query string true "省 , 多个用英文逗号分开 "
  6447. // @Param City query string true "市 , 多个用英文逗号分开 "
  6448. // @Param PackageType query int true "套餐类型,0:无,1:大套餐,2:小套餐"
  6449. // @Success Ret=200 移动成功
  6450. // @router /user/export [get]
  6451. func (this *CompanyController) CompanyUserExport() {
  6452. br := new(models.BaseResponse).Init()
  6453. defer func() {
  6454. this.Data["json"] = br
  6455. this.ServeJSON()
  6456. }()
  6457. sysUser := this.SysUser
  6458. if sysUser == nil {
  6459. br.Msg = "请登录"
  6460. br.ErrMsg = "请登录,SysUser Is Empty"
  6461. br.Ret = 408
  6462. return
  6463. }
  6464. roleTypeCode := sysUser.RoleTypeCode
  6465. status := this.GetString("Status")
  6466. companyType := this.GetString("CompanyType")
  6467. industryId, _ := this.GetInt("IndustryId")
  6468. adminId := this.GetString("AdminId")
  6469. chartPermissionIds := this.GetString("ChartPermissionIds")
  6470. contractPermissionIds := this.GetString("ContractPermissionIds")
  6471. startDate := this.GetString("StartDate")
  6472. endDate := this.GetString("EndDate")
  6473. createStartDate := this.GetString("CreateStartDate")
  6474. createEndDate := this.GetString("CreateEndDate")
  6475. keyWord := this.GetString("KeyWord")
  6476. address := this.GetString("Address")
  6477. province := this.GetString("Province")
  6478. city := this.GetString("City")
  6479. // 套餐类型
  6480. packageType, _ := this.GetInt("PackageType")
  6481. var condition string
  6482. var pars []interface{}
  6483. if status != "" && status != "全部" {
  6484. condition += ` AND b.status=? `
  6485. pars = append(pars, status)
  6486. }
  6487. if companyType != "" {
  6488. condition += ` AND b.product_name=? `
  6489. pars = append(pars, companyType)
  6490. }
  6491. if industryId > 0 {
  6492. condition += ` AND b.industry_id=? `
  6493. pars = append(pars, industryId)
  6494. }
  6495. if adminId != "" {
  6496. condition += ` AND b.seller_id IN (` + adminId + `) `
  6497. }
  6498. if startDate != "" {
  6499. condition += ` AND b.start_date>=? `
  6500. pars = append(pars, startDate)
  6501. }
  6502. if endDate != "" {
  6503. condition += ` AND b.end_date<=? `
  6504. pars = append(pars, endDate)
  6505. }
  6506. if createStartDate != "" {
  6507. condition += ` AND a.created_time>=? `
  6508. pars = append(pars, createStartDate)
  6509. }
  6510. if createEndDate != "" {
  6511. condition += ` AND a.created_time<=? `
  6512. pars = append(pars, createEndDate)
  6513. }
  6514. if keyWord != "" {
  6515. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR c.mobile LIKE '%` + keyWord + `%' OR c.email LIKE '%` + keyWord + `%') `
  6516. }
  6517. // 阅读权限/已购品种筛选
  6518. cond, emp, e := services.FilterReadAndContractAuth(chartPermissionIds, contractPermissionIds, condition)
  6519. if e != nil {
  6520. br.Msg = "获取失败"
  6521. br.ErrMsg = "FilterReadAndContractAuth err: " + e.Error()
  6522. return
  6523. }
  6524. if emp {
  6525. condition += ` AND 1 = 2`
  6526. } else {
  6527. condition = cond
  6528. }
  6529. if address != "" {
  6530. var addressSql string
  6531. slice := strings.Split(address, ",")
  6532. for _, v := range slice {
  6533. addressSql += "'" + v + "'" + ","
  6534. }
  6535. addressSql = strings.TrimRight(addressSql, ",")
  6536. condition += ` AND a.address IN (` + addressSql + `) `
  6537. }
  6538. if province != "" {
  6539. var provinceSql string
  6540. slice := strings.Split(province, ",")
  6541. for _, v := range slice {
  6542. provinceSql += "'" + v + "'" + ","
  6543. }
  6544. provinceSql = strings.TrimRight(provinceSql, ",")
  6545. condition += ` AND a.province IN (` + provinceSql + `) `
  6546. }
  6547. if city != "" {
  6548. var citySql string
  6549. slice := strings.Split(city, ",")
  6550. for _, v := range slice {
  6551. citySql += "'" + v + "'" + ","
  6552. }
  6553. citySql = strings.TrimRight(citySql, ",")
  6554. condition += ` AND a.city IN (` + citySql + `) `
  6555. }
  6556. //套餐类型
  6557. if packageType > 0 {
  6558. condition += ` AND b.package_type=? `
  6559. pars = append(pars, packageType)
  6560. }
  6561. //权限控制
  6562. {
  6563. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  6564. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  6565. if status != utils.COMPANY_STATUS_LOSE && status != utils.COMPANY_STATUS_FOREVER {
  6566. condition += ` AND b.seller_id=? `
  6567. pars = append(pars, sysUser.AdminId)
  6568. }
  6569. }
  6570. if sysUser.Authority == 1 {
  6571. condition += ` AND b.department_id=? `
  6572. pars = append(pars, sysUser.DepartmentId)
  6573. }
  6574. if sysUser.Authority == 2 {
  6575. condition += ` AND b.group_id=? `
  6576. pars = append(pars, sysUser.GroupId)
  6577. }
  6578. }
  6579. var statusCond string
  6580. var statusPars []interface{}
  6581. // 根据当前用户角色
  6582. productId := services.GetProductId(roleTypeCode)
  6583. if productId > 0 {
  6584. condition += ` AND b.product_id = ? `
  6585. pars = append(pars, productId)
  6586. statusCond += ` AND b.product_id = ? `
  6587. statusPars = append(statusPars, productId)
  6588. }
  6589. companyIds, err := company.GetExportCompanyIds(condition, pars)
  6590. if err != nil {
  6591. br.Msg = "导出失败"
  6592. br.ErrMsg = "导出失败,Err:" + err.Error()
  6593. return
  6594. }
  6595. dir, err := os.Executable()
  6596. exPath := filepath.Dir(dir)
  6597. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  6598. xlsxFile := xlsx.NewFile()
  6599. if err != nil {
  6600. br.Msg = "生成文件失败"
  6601. br.ErrMsg = "生成文件失败"
  6602. return
  6603. }
  6604. style := xlsx.NewStyle()
  6605. alignment := xlsx.Alignment{
  6606. Horizontal: "center",
  6607. Vertical: "center",
  6608. WrapText: true,
  6609. }
  6610. style.Alignment = alignment
  6611. style.ApplyAlignment = true
  6612. sheel, err := xlsxFile.AddSheet("联系人数据")
  6613. if err != nil {
  6614. br.Msg = "新增Sheet失败"
  6615. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  6616. return
  6617. }
  6618. sheel.SetColWidth(7, 7, 10)
  6619. sheel.SetColWidth(8, 10, 16)
  6620. sheel.SetColWidth(9, 11, 20)
  6621. sheel.SetColWidth(12, 12, 35)
  6622. sheel.SetColWidth(13, 13, 15)
  6623. sheel.SetColWidth(14, 14, 80)
  6624. titleRow := sheel.AddRow()
  6625. titleRow.AddCell().SetValue("联系人")
  6626. titleRow.AddCell().SetValue("是否关注公众号")
  6627. titleRow.AddCell().SetValue("手机号")
  6628. titleRow.AddCell().SetValue("邮箱")
  6629. //titleRow.AddCell().SetValue("职位")
  6630. titleRow.AddCell().SetValue("是否决策人")
  6631. //titleRow.AddCell().SetValue("客户部门")
  6632. titleRow.AddCell().SetValue("客户名称")
  6633. titleRow.AddCell().SetValue("客户状态")
  6634. //titleRow.AddCell().SetValue("社会信用码")
  6635. //titleRow.AddCell().SetValue("所属区域")
  6636. //titleRow.AddCell().SetValue("客户类型")
  6637. //industryCell := titleRow.AddCell()
  6638. //industryCell.SetStyle(style)
  6639. //industryCell.Value = "所属行业"
  6640. //
  6641. //sellerCell := titleRow.AddCell()
  6642. //sellerCell.SetStyle(style)
  6643. //sellerCell.Value = "所属销售"
  6644. //
  6645. //statusCell := titleRow.AddCell()
  6646. //statusCell.SetStyle(style)
  6647. //statusCell.Value = "客户状态"
  6648. //
  6649. //timeLimtCell := titleRow.AddCell()
  6650. //timeLimtCell.SetStyle(style)
  6651. //timeLimtCell.Value = "服务期限"
  6652. //
  6653. //createTimeCell := titleRow.AddCell()
  6654. //createTimeCell.SetStyle(style)
  6655. //createTimeCell.Value = "创建时间"
  6656. //
  6657. //sourceCell := titleRow.AddCell()
  6658. //sourceCell.SetStyle(style)
  6659. //sourceCell.Value = "客户来源"
  6660. //permissionStyle := xlsx.NewStyle()
  6661. //permissionAlignment := xlsx.Alignment{
  6662. // Horizontal: "center",
  6663. // Vertical: "center",
  6664. // WrapText: true,
  6665. //}
  6666. //
  6667. //permissionStyle.Alignment = permissionAlignment
  6668. //permissionStyle.ApplyAlignment = true
  6669. //permissionCell := titleRow.AddCell()
  6670. //permissionCell.SetStyle(permissionStyle)
  6671. //permissionCell.Value = "阅读权限"
  6672. users := make([]*company.ExportUser, 0)
  6673. if companyIds != "" {
  6674. companyIds = strings.Trim(companyIds, ",")
  6675. if productId > 0 {
  6676. users, err = company.GetExportUserByProductId(companyIds, productId)
  6677. if err != nil {
  6678. br.Msg = "导出失败"
  6679. br.ErrMsg = "获取联系人信息失败,Err:" + err.Error()
  6680. return
  6681. }
  6682. } else {
  6683. users, err = company.GetExportUser(companyIds)
  6684. if err != nil {
  6685. br.Msg = "导出失败"
  6686. br.ErrMsg = "获取联系人信息失败,Err:" + err.Error()
  6687. return
  6688. }
  6689. }
  6690. // 获取客户状态
  6691. companyIntIds := make([]int, 0)
  6692. companyIdArr := strings.Split(companyIds, ",")
  6693. for _, c := range companyIdArr {
  6694. id, e := strconv.Atoi(c)
  6695. if e != nil {
  6696. br.Msg = "导出失败"
  6697. br.ErrMsg = "客户ID有误"
  6698. return
  6699. }
  6700. companyIntIds = append(companyIntIds, id)
  6701. }
  6702. if len(companyIntIds) > 0 {
  6703. statusCond += fmt.Sprintf(` AND a.company_id IN (%s) `, utils.GetOrmInReplace(len(companyIntIds)))
  6704. statusPars = append(statusPars, companyIntIds)
  6705. }
  6706. statusMap := make(map[int]string)
  6707. nameMap := make(map[int]string)
  6708. companyStatusList, e := company.GetExportUserCompanyStatus(statusCond, statusPars)
  6709. if e != nil {
  6710. br.Msg = "导出失败"
  6711. br.ErrMsg = "获取客户状态失败, Err: " + e.Error()
  6712. return
  6713. }
  6714. for _, s := range companyStatusList {
  6715. statusMap[s.CompanyId] = s.CompanyStatus
  6716. nameMap[s.CompanyId] = s.CompanyName
  6717. }
  6718. //cpMap := make(map[int][]*company.ExportCompanyProduct)
  6719. //permissionMap := make(map[string]string)
  6720. for _, v := range users {
  6721. dataRow := sheel.AddRow()
  6722. dataRow.SetHeight(20)
  6723. dataRow.AddCell().SetString(v.RealName)
  6724. if v.IsSubscribe == 1 {
  6725. dataRow.AddCell().SetString("是") // 是否关注公众号
  6726. } else {
  6727. dataRow.AddCell().SetString("")
  6728. }
  6729. dataRow.AddCell().SetString(v.Mobile)
  6730. dataRow.AddCell().SetString(v.Email)
  6731. //dataRow.AddCell().SetString(v.Position)
  6732. if v.IsMaker == 1 {
  6733. dataRow.AddCell().SetString("是")
  6734. } else {
  6735. dataRow.AddCell().SetString("否")
  6736. }
  6737. //dataRow.AddCell().SetString(v.DepartmentName)
  6738. //cpList := make([]*company.ExportCompanyProduct, 1)
  6739. //if cps, ok := cpMap[v.CompanyId]; ok {
  6740. // cpList = cps
  6741. //} else {
  6742. // companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  6743. // if err != nil {
  6744. // br.Msg = "导出失败"
  6745. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  6746. // return
  6747. // }
  6748. // cpMap[v.CompanyId] = companyProduct
  6749. // cpList = companyProduct
  6750. //}
  6751. //productList, err := company.GetExportCompanyProduct(v.CompanyId)
  6752. //if err!=nil {
  6753. // fmt.Println("导出失败,Err:"+err.Error())
  6754. // return
  6755. //}
  6756. //var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, creditCode, regionType string
  6757. //for ck, cv := range cpList {
  6758. // companyName = cv.CompanyName
  6759. // creditCode = cv.CreditCode
  6760. // regionType = cv.RegionType
  6761. // if ck >= 1 {
  6762. // companyType = companyType + "/" + cv.ProductName
  6763. // status = status + "/" + cv.Status
  6764. // } else {
  6765. // companyType = cv.ProductName
  6766. // status = cv.Status
  6767. // }
  6768. // if cv.ProductId == 1 {
  6769. // industryName = "ficc:" + cv.IndustryName
  6770. // sellerName = "ficc:" + cv.SellerName
  6771. // startDateStr := cv.StartDate.Format("2006/01/02")
  6772. // endDateStr := cv.EndDate.Format("2006/01/02")
  6773. // if startDateStr != "0001/01/01" {
  6774. // timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  6775. // } else {
  6776. // timeLimt = ""
  6777. // }
  6778. // createTime = "ficc:" + cv.CreateTime
  6779. // source = "ficc:" + cv.Source
  6780. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6781. //
  6782. // permissionStr = "ficc:"
  6783. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6784. // permissionStr += newPermissionStr
  6785. // } else {
  6786. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6787. // if err != nil {
  6788. // br.Msg = "导出失败"
  6789. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6790. // return
  6791. // }
  6792. // permissionMap[permissionKey] = getPermissionStr
  6793. // permissionStr += getPermissionStr
  6794. // }
  6795. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  6796. // permissionStr = ""
  6797. // }
  6798. // } else {
  6799. // industryName = industryName + "\n" + "权益:" + cv.IndustryName
  6800. // sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  6801. // startDateStr := cv.StartDate.Format("2006/01/02")
  6802. // endDateStr := cv.EndDate.Format("2006/01/02")
  6803. //
  6804. // if startDateStr != "0001/01/01" {
  6805. // timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  6806. // } else {
  6807. // timeLimt = timeLimt + ""
  6808. // }
  6809. // createTime = createTime + "\n" + "权益:" + cv.CreateTime
  6810. // source = source + "\n" + "权益:" + cv.Source
  6811. //
  6812. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6813. // if permissionStr != "" {
  6814. // permissionStr = permissionStr + "\n" + "权益:"
  6815. // } else {
  6816. // permissionStr = "权益:"
  6817. // }
  6818. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6819. // permissionStr += newPermissionStr
  6820. // } else {
  6821. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6822. // if err != nil {
  6823. // br.Msg = "导出失败"
  6824. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6825. // return
  6826. // }
  6827. // permissionMap[permissionKey] = getPermissionStr
  6828. // permissionStr += getPermissionStr
  6829. // }
  6830. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  6831. // permissionStr = permissionStr + ""
  6832. // }
  6833. // }
  6834. //}
  6835. // 2023-0420这是谁写的循环查,顺手优化了一下,手动狗头-_-~
  6836. //companyInfo, err := company.GetCompanyById(v.CompanyId)
  6837. //if err != nil {
  6838. // br.Msg = "导出失败"
  6839. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  6840. // return
  6841. //}
  6842. dataRow.AddCell().SetString(nameMap[v.CompanyId])
  6843. dataRow.AddCell().SetString(statusMap[v.CompanyId]) // 客户状态
  6844. //dataRow.AddCell().SetString(creditCode)
  6845. //dataRow.AddCell().SetString(regionType)
  6846. //
  6847. //dataRow.AddCell().SetString(companyType)
  6848. //industryValueCell := dataRow.AddCell()
  6849. //industryValueCell.SetStyle(style)
  6850. //industryValueCell.SetString(industryName)
  6851. //
  6852. //sellerValueCell := dataRow.AddCell()
  6853. //sellerValueCell.SetStyle(style)
  6854. //sellerValueCell.SetString(sellerName)
  6855. //
  6856. //statusValueCell := dataRow.AddCell()
  6857. //statusValueCell.SetStyle(style)
  6858. //statusValueCell.SetValue(status)
  6859. //
  6860. //timeLimitValueCell := dataRow.AddCell()
  6861. //timeLimitValueCell.SetStyle(style)
  6862. //timeLimitValueCell.SetValue(timeLimt)
  6863. //
  6864. //createTimeValueCell := dataRow.AddCell()
  6865. //createTimeValueCell.SetStyle(style)
  6866. //createTimeValueCell.SetValue(createTime)
  6867. //
  6868. //sourceValueCell := dataRow.AddCell()
  6869. //sourceValueCell.SetStyle(style)
  6870. //sourceValueCell.SetValue(source)
  6871. //
  6872. //permissionStrValueCell := dataRow.AddCell()
  6873. //permissionStrValueCell.SetStyle(style)
  6874. //permissionStrValueCell.SetValue(permissionStr)
  6875. }
  6876. }
  6877. err = xlsxFile.Save(downLoadnFilePath)
  6878. if err != nil {
  6879. br.Msg = "保存文件失败"
  6880. br.ErrMsg = "保存文件失败"
  6881. return
  6882. }
  6883. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  6884. downloadFileName := "联系人列表" + randStr + ".xlsx"
  6885. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  6886. defer func() {
  6887. os.Remove(downLoadnFilePath)
  6888. }()
  6889. br.Ret = 200
  6890. br.Success = true
  6891. br.Msg = "导出成功"
  6892. }
  6893. //func (this *CompanyController) CompanyUserExportOld() {
  6894. // br := new(models.BaseResponse).Init()
  6895. // defer func() {
  6896. // this.Data["json"] = br
  6897. // this.ServeJSON()
  6898. // }()
  6899. // sysUser := this.SysUser
  6900. // if sysUser == nil {
  6901. // br.Msg = "请登录"
  6902. // br.ErrMsg = "请登录,SysUser Is Empty"
  6903. // br.Ret = 408
  6904. // return
  6905. // }
  6906. // roleTypeCode := sysUser.RoleTypeCode
  6907. // status := this.GetString("Status")
  6908. // companyType := this.GetString("CompanyType")
  6909. // industryId, _ := this.GetInt("IndustryId")
  6910. // adminId := this.GetString("AdminId")
  6911. //
  6912. // chartPermissionIds := this.GetString("ChartPermissionIds")
  6913. // startDate := this.GetString("StartDate")
  6914. // endDate := this.GetString("EndDate")
  6915. // keyWord := this.GetString("KeyWord")
  6916. //
  6917. // var condition string
  6918. // var pars []interface{}
  6919. //
  6920. // if status != "" && status != "全部" {
  6921. // condition += ` AND b.status=? `
  6922. // pars = append(pars, status)
  6923. // }
  6924. // if companyType != "" {
  6925. // condition += ` AND b.product_name=? `
  6926. // pars = append(pars, companyType)
  6927. // }
  6928. //
  6929. // if industryId > 0 {
  6930. // condition += ` AND b.industry_id=? `
  6931. // pars = append(pars, industryId)
  6932. // }
  6933. //
  6934. // if adminId != "" {
  6935. // condition += ` AND b.seller_id IN (` + adminId + `) `
  6936. // }
  6937. //
  6938. // if startDate != "" {
  6939. // condition += ` AND b.start_date>=? `
  6940. // pars = append(pars, startDate)
  6941. // }
  6942. //
  6943. // if endDate != "" {
  6944. // condition += ` AND b.end_date>=? `
  6945. // pars = append(pars, endDate)
  6946. // }
  6947. //
  6948. // if keyWord != "" {
  6949. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR c.mobile LIKE '%` + keyWord + `%' OR c.email LIKE '%` + keyWord + `%') `
  6950. // }
  6951. //
  6952. // if chartPermissionIds != "" {
  6953. // companyIdStr, err := company.GetCompanyIdStr(chartPermissionIds)
  6954. // if err != nil {
  6955. // br.Msg = "获取失败"
  6956. // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
  6957. // return
  6958. // }
  6959. // if companyIdStr != "" {
  6960. // condition += ` AND a.company_id IN (` + companyIdStr + `) `
  6961. // }
  6962. // }
  6963. //
  6964. // //权限控制
  6965. // {
  6966. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  6967. // roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  6968. // if status != utils.COMPANY_STATUS_LOSE && status != utils.COMPANY_STATUS_FOREVER {
  6969. // condition += ` AND b.seller_id=? `
  6970. // pars = append(pars, sysUser.AdminId)
  6971. // }
  6972. // }
  6973. // if sysUser.Authority == 1 {
  6974. // condition += ` AND b.department_id=? `
  6975. // pars = append(pars, sysUser.DepartmentId)
  6976. // }
  6977. //
  6978. // if sysUser.Authority == 2 {
  6979. // condition += ` AND b.group_id=? `
  6980. // pars = append(pars, sysUser.GroupId)
  6981. // }
  6982. // }
  6983. // companyIds, err := company.GetExportCompanyIds(condition, pars)
  6984. // if err != nil {
  6985. // br.Msg = "导出失败"
  6986. // br.ErrMsg = "导出失败,Err:" + err.Error()
  6987. // return
  6988. // }
  6989. //
  6990. // dir, err := os.Executable()
  6991. // exPath := filepath.Dir(dir)
  6992. //
  6993. // downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  6994. // xlsxFile := xlsx.NewFile()
  6995. // if err != nil {
  6996. // br.Msg = "生成文件失败"
  6997. // br.ErrMsg = "生成文件失败"
  6998. // return
  6999. // }
  7000. // style := xlsx.NewStyle()
  7001. // alignment := xlsx.Alignment{
  7002. // Horizontal: "center",
  7003. // Vertical: "center",
  7004. // WrapText: true,
  7005. // }
  7006. //
  7007. // style.Alignment = alignment
  7008. // style.ApplyAlignment = true
  7009. //
  7010. // sheel, err := xlsxFile.AddSheet("联系人数据")
  7011. // if err != nil {
  7012. // br.Msg = "新增Sheet失败"
  7013. // br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  7014. // return
  7015. // }
  7016. //
  7017. // sheel.SetColWidth(7, 7, 10)
  7018. // sheel.SetColWidth(8, 10, 16)
  7019. // sheel.SetColWidth(9, 11, 20)
  7020. // sheel.SetColWidth(12, 12, 35)
  7021. // sheel.SetColWidth(13, 13, 15)
  7022. // sheel.SetColWidth(14, 14, 80)
  7023. // titleRow := sheel.AddRow()
  7024. // titleRow.AddCell().SetValue("联系人")
  7025. // titleRow.AddCell().SetValue("手机号")
  7026. // titleRow.AddCell().SetValue("邮箱")
  7027. // titleRow.AddCell().SetValue("职位")
  7028. // titleRow.AddCell().SetValue("是否决策人")
  7029. // titleRow.AddCell().SetValue("客户部门")
  7030. // titleRow.AddCell().SetValue("客户名称")
  7031. // titleRow.AddCell().SetValue("社会信用码")
  7032. // titleRow.AddCell().SetValue("所属区域")
  7033. // titleRow.AddCell().SetValue("客户类型")
  7034. //
  7035. // industryCell := titleRow.AddCell()
  7036. // industryCell.SetStyle(style)
  7037. // industryCell.Value = "所属行业"
  7038. //
  7039. // sellerCell := titleRow.AddCell()
  7040. // sellerCell.SetStyle(style)
  7041. // sellerCell.Value = "所属销售"
  7042. //
  7043. // statusCell := titleRow.AddCell()
  7044. // statusCell.SetStyle(style)
  7045. // statusCell.Value = "客户状态"
  7046. //
  7047. // timeLimtCell := titleRow.AddCell()
  7048. // timeLimtCell.SetStyle(style)
  7049. // timeLimtCell.Value = "服务期限"
  7050. //
  7051. // createTimeCell := titleRow.AddCell()
  7052. // createTimeCell.SetStyle(style)
  7053. // createTimeCell.Value = "创建时间"
  7054. //
  7055. // sourceCell := titleRow.AddCell()
  7056. // sourceCell.SetStyle(style)
  7057. // sourceCell.Value = "客户来源"
  7058. //
  7059. // permissionStyle := xlsx.NewStyle()
  7060. // permissionAlignment := xlsx.Alignment{
  7061. // Horizontal: "center",
  7062. // Vertical: "center",
  7063. // WrapText: true,
  7064. // }
  7065. //
  7066. // permissionStyle.Alignment = permissionAlignment
  7067. // permissionStyle.ApplyAlignment = true
  7068. //
  7069. // permissionCell := titleRow.AddCell()
  7070. // permissionCell.SetStyle(permissionStyle)
  7071. // permissionCell.Value = "阅读权限"
  7072. //
  7073. // if companyIds != "" {
  7074. // companyIds = strings.Trim(companyIds, ",")
  7075. // users, err := company.GetExportUser(companyIds)
  7076. // if err != nil {
  7077. // br.Msg = "导出失败"
  7078. // br.ErrMsg = "获取联系人信息失败,Err:" + err.Error()
  7079. // return
  7080. // }
  7081. // cpMap := make(map[int][]*company.ExportCompanyProduct)
  7082. // permissionMap := make(map[string]string)
  7083. // for _, v := range users {
  7084. // dataRow := sheel.AddRow()
  7085. // dataRow.SetHeight(20)
  7086. // dataRow.AddCell().SetString(v.RealName)
  7087. // dataRow.AddCell().SetString(v.Mobile)
  7088. // dataRow.AddCell().SetString(v.Email)
  7089. // dataRow.AddCell().SetString(v.Position)
  7090. // if v.IsMaker == 1 {
  7091. // dataRow.AddCell().SetString("是")
  7092. // } else {
  7093. // dataRow.AddCell().SetString("否")
  7094. // }
  7095. // dataRow.AddCell().SetString(v.DepartmentName)
  7096. // cpList := make([]*company.ExportCompanyProduct, 1)
  7097. // if cps, ok := cpMap[v.CompanyId]; ok {
  7098. // cpList = cps
  7099. // } else {
  7100. // companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  7101. // if err != nil {
  7102. // br.Msg = "导出失败"
  7103. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  7104. // return
  7105. // }
  7106. // cpMap[v.CompanyId] = companyProduct
  7107. // cpList = companyProduct
  7108. // }
  7109. // //productList, err := company.GetExportCompanyProduct(v.CompanyId)
  7110. // //if err!=nil {
  7111. // // fmt.Println("导出失败,Err:"+err.Error())
  7112. // // return
  7113. // //}
  7114. // var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, creditCode, regionType string
  7115. //
  7116. // for ck, cv := range cpList {
  7117. // companyName = cv.CompanyName
  7118. // creditCode = cv.CreditCode
  7119. // regionType = cv.RegionType
  7120. // if ck >= 1 {
  7121. // companyType = companyType + "/" + cv.ProductName
  7122. // status = status + "/" + cv.Status
  7123. // } else {
  7124. // companyType = cv.ProductName
  7125. // status = cv.Status
  7126. // }
  7127. // if cv.ProductId == 1 {
  7128. // industryName = "ficc:" + cv.IndustryName
  7129. // sellerName = "ficc:" + cv.SellerName
  7130. // startDateStr := cv.StartDate.Format("2006/01/02")
  7131. // endDateStr := cv.EndDate.Format("2006/01/02")
  7132. // if startDateStr != "0001/01/01" {
  7133. // timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  7134. // } else {
  7135. // timeLimt = ""
  7136. // }
  7137. // createTime = "ficc:" + cv.CreateTime
  7138. // source = "ficc:" + cv.Source
  7139. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  7140. //
  7141. // permissionStr = "ficc:"
  7142. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  7143. // permissionStr += newPermissionStr
  7144. // } else {
  7145. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  7146. // if err != nil {
  7147. // br.Msg = "导出失败"
  7148. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  7149. // return
  7150. // }
  7151. // permissionMap[permissionKey] = getPermissionStr
  7152. // permissionStr += getPermissionStr
  7153. // }
  7154. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  7155. // permissionStr = ""
  7156. // }
  7157. // } else {
  7158. // industryName = industryName + "\n" + "权益:" + cv.IndustryName
  7159. // sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  7160. // startDateStr := cv.StartDate.Format("2006/01/02")
  7161. // endDateStr := cv.EndDate.Format("2006/01/02")
  7162. //
  7163. // if startDateStr != "0001/01/01" {
  7164. // timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  7165. // } else {
  7166. // timeLimt = timeLimt + ""
  7167. // }
  7168. // createTime = createTime + "\n" + "权益:" + cv.CreateTime
  7169. // source = source + "\n" + "权益:" + cv.Source
  7170. //
  7171. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  7172. // if permissionStr != "" {
  7173. // permissionStr = permissionStr + "\n" + "权益:"
  7174. // } else {
  7175. // permissionStr = "权益:"
  7176. // }
  7177. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  7178. // permissionStr += newPermissionStr
  7179. // } else {
  7180. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  7181. // if err != nil {
  7182. // br.Msg = "导出失败"
  7183. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  7184. // return
  7185. // }
  7186. // permissionMap[permissionKey] = getPermissionStr
  7187. // permissionStr += getPermissionStr
  7188. // }
  7189. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  7190. // permissionStr = permissionStr + ""
  7191. // }
  7192. // }
  7193. // }
  7194. // dataRow.AddCell().SetString(companyName)
  7195. // dataRow.AddCell().SetString(creditCode)
  7196. // dataRow.AddCell().SetString(regionType)
  7197. //
  7198. // dataRow.AddCell().SetString(companyType)
  7199. // industryValueCell := dataRow.AddCell()
  7200. // industryValueCell.SetStyle(style)
  7201. // industryValueCell.SetString(industryName)
  7202. //
  7203. // sellerValueCell := dataRow.AddCell()
  7204. // sellerValueCell.SetStyle(style)
  7205. // sellerValueCell.SetString(sellerName)
  7206. //
  7207. // statusValueCell := dataRow.AddCell()
  7208. // statusValueCell.SetStyle(style)
  7209. // statusValueCell.SetValue(status)
  7210. //
  7211. // timeLimitValueCell := dataRow.AddCell()
  7212. // timeLimitValueCell.SetStyle(style)
  7213. // timeLimitValueCell.SetValue(timeLimt)
  7214. //
  7215. // createTimeValueCell := dataRow.AddCell()
  7216. // createTimeValueCell.SetStyle(style)
  7217. // createTimeValueCell.SetValue(createTime)
  7218. //
  7219. // sourceValueCell := dataRow.AddCell()
  7220. // sourceValueCell.SetStyle(style)
  7221. // sourceValueCell.SetValue(source)
  7222. //
  7223. // permissionStrValueCell := dataRow.AddCell()
  7224. // permissionStrValueCell.SetStyle(style)
  7225. // permissionStrValueCell.SetValue(permissionStr)
  7226. // }
  7227. // }
  7228. // err = xlsxFile.Save(downLoadnFilePath)
  7229. // if err != nil {
  7230. // br.Msg = "保存文件失败"
  7231. // br.ErrMsg = "保存文件失败"
  7232. // return
  7233. // }
  7234. // randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  7235. // downloadFileName := "联系人列表" + randStr + ".xlsx"
  7236. // this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  7237. // defer func() {
  7238. // os.Remove(downLoadnFilePath)
  7239. // }()
  7240. // br.Ret = 200
  7241. // br.Success = true
  7242. // br.Msg = "导出成功"
  7243. //}
  7244. // @Title 冻结客户
  7245. // @Description 冻结客户接口
  7246. // @Param request body company.CompanyFreezeReq true "type json string"
  7247. // @Success Ret=200 冻结成功
  7248. // @router /freeze [post]
  7249. func (this *CompanyController) Freeze() {
  7250. br := new(models.BaseResponse).Init()
  7251. defer func() {
  7252. this.Data["json"] = br
  7253. this.ServeJSON()
  7254. }()
  7255. sysUser := this.SysUser
  7256. if sysUser == nil {
  7257. br.Msg = "请登录"
  7258. br.ErrMsg = "请登录,SysUser Is Empty"
  7259. br.Ret = 408
  7260. return
  7261. }
  7262. var req company.CompanyFreezeReq
  7263. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  7264. if err != nil {
  7265. br.Msg = "参数解析异常!"
  7266. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  7267. return
  7268. }
  7269. if req.CompanyId <= 0 {
  7270. br.Msg = "参数错误!"
  7271. br.ErrMsg = "客户id小于等于0"
  7272. return
  7273. }
  7274. productId := 0
  7275. productName := ""
  7276. if req.CompanyType == utils.COMPANY_CLASSIFY_FICC {
  7277. productId = 1
  7278. productName = "ficc"
  7279. } else if req.CompanyType == utils.COMPANY_CLASSIFY_RAI {
  7280. productId = 2
  7281. productName = "权益"
  7282. } else {
  7283. productId = 3
  7284. productName = "佣金客户"
  7285. }
  7286. if req.CompanyId <= 0 {
  7287. br.Msg = "参数异常!"
  7288. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  7289. return
  7290. }
  7291. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  7292. if err != nil {
  7293. br.Msg = "查询该客户产品异常!"
  7294. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  7295. return
  7296. }
  7297. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  7298. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  7299. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  7300. return
  7301. }
  7302. //查询客户的产品权限
  7303. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, productId)
  7304. if err != nil {
  7305. br.Msg = "查询客户的产品权限异常"
  7306. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  7307. return
  7308. }
  7309. err = company.CompanyFreeze(req.CompanyId, productId, req.Remark)
  7310. if err != nil {
  7311. br.Msg = "冻结失败!"
  7312. br.ErrMsg = "冻结失败,Err:" + err.Error()
  7313. return
  7314. }
  7315. //新增操作记录
  7316. {
  7317. approveContent := req.Remark
  7318. remark := "冻结客户"
  7319. operation := "freeze"
  7320. services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
  7321. productName, sysUser.RealName, remark, operation, approveContent, sysUser.RealName, "", "冻结")
  7322. //新增产品权限冻结操作日志
  7323. for _, companyReportPermission := range companyReportPermissionList {
  7324. record := company_report_permission_log.CompanyReportPermissionLog{
  7325. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  7326. CompanyId: companyReportPermission.CompanyId,
  7327. ProductId: productId,
  7328. ProductName: companyReportPermission.ProductName,
  7329. SysUserId: sysUser.AdminId,
  7330. SysUserName: sysUser.RealName,
  7331. Remark: "冻结客户",
  7332. Operation: "freeze",
  7333. Status: companyReportPermission.Status,
  7334. CreateTime: time.Now(),
  7335. }
  7336. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  7337. }
  7338. }
  7339. br.Ret = 200
  7340. br.Success = true
  7341. br.Msg = "领取成功"
  7342. }
  7343. // @Title 获取客户权限
  7344. // @Description 获取客户权限接口
  7345. // @Param CompanyId query int true "用户id"
  7346. // @Success 200 {object} company.CompanyPermissionResp
  7347. // @router /getCompanyPermission [get]
  7348. func (this *CompanyController) PermissionList() {
  7349. br := new(models.BaseResponse).Init()
  7350. defer func() {
  7351. this.Data["json"] = br
  7352. this.ServeJSON()
  7353. }()
  7354. sysUser := this.SysUser
  7355. if sysUser == nil {
  7356. br.Msg = "请登录"
  7357. br.ErrMsg = "请登录,SysUser Is Empty"
  7358. br.Ret = 408
  7359. return
  7360. }
  7361. companyId, _ := this.GetInt("CompanyId")
  7362. if companyId <= 0 {
  7363. br.Msg = "参数错误"
  7364. br.ErrMsg = "客户参数小于等于0"
  7365. return
  7366. }
  7367. //返回基础参数
  7368. resp := new(company.CompanyPermissionResp)
  7369. //客户类型map
  7370. classifyMap := make(map[string]int)
  7371. classifyMap["ficc"] = 1
  7372. classifyMap["权益"] = 2
  7373. roleTypeCode := sysUser.RoleTypeCode
  7374. var companySlice []string
  7375. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  7376. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  7377. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  7378. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
  7379. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM ||
  7380. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
  7381. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_RESEARCHR {
  7382. companySlice = append(companySlice, "ficc")
  7383. } else if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  7384. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN ||
  7385. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  7386. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  7387. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT ||
  7388. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_RESEARCHR {
  7389. companySlice = append(companySlice, "权益")
  7390. }
  7391. for _, companyType := range companySlice {
  7392. //子权限切片集合
  7393. //var permissionClassifyArr []string
  7394. var permissionProductId int
  7395. if companyType == "ficc" {
  7396. permissionProductId = utils.COMPANY_PRODUCT_FICC_ID
  7397. } else {
  7398. permissionProductId = utils.COMPANY_PRODUCT_RAI_ID
  7399. }
  7400. //子权限切片集合
  7401. permissionClassifyArr, err := models.GetPermissionFirstByProductId(permissionProductId)
  7402. if err != nil {
  7403. br.Msg = "获取失败"
  7404. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  7405. return
  7406. }
  7407. //遍历获取
  7408. for _, v := range permissionClassifyArr {
  7409. checkList := make([]int, 0)
  7410. plist := new(company.PermissionLookList)
  7411. plist.Items = make([]*company.PermissionLookItem, 0)
  7412. items, err := company.GetPermissionLookItemsByParentId(classifyMap[companyType], v.ChartPermissionId)
  7413. if err != nil {
  7414. br.Msg = "获取失败"
  7415. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  7416. return
  7417. }
  7418. mapPermissionCheck := make(map[string]int)
  7419. for i, n := range items {
  7420. item := items[i]
  7421. count, err := company.GetCompanyPermissionCheck(companyId, n.ChartPermissionId)
  7422. if err != nil {
  7423. br.Msg = "获取失败"
  7424. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  7425. return
  7426. }
  7427. //合并主观客观勾选的权限
  7428. if count > 0 && mapPermissionCheck[n.PermissionName] == 0 {
  7429. checkList = append(checkList, n.ChartPermissionId)
  7430. mapPermissionCheck[n.PermissionName] = n.ChartPermissionId
  7431. }
  7432. permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  7433. if err != nil && err.Error() != utils.ErrNoRow() {
  7434. br.Msg = "获取失败"
  7435. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  7436. return
  7437. }
  7438. if permission != nil && permission.ChartPermissionId > 0 {
  7439. items[i].StartDate = permission.StartDate
  7440. items[i].EndDate = permission.EndDate
  7441. items[i].Status = permission.Status
  7442. //判断主观、客观
  7443. if items[i].PermissionType == 1 {
  7444. items[i].PermissionTypeName = "主观"
  7445. } else if items[i].PermissionType == 2 {
  7446. items[i].PermissionTypeName = "客观"
  7447. }
  7448. }
  7449. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  7450. endDateTime = endDateTime.AddDate(0, 0, 1)
  7451. sub := endDateTime.Sub(time.Now())
  7452. if sub < 0 {
  7453. sub = 0
  7454. }
  7455. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  7456. items[i].ExpireDay = expireDay
  7457. items[i].ClassifyName = v.PermissionName
  7458. //if n.PermissionType == 1 {
  7459. // items[i].PermissionTypeName = "主观"
  7460. //} else if n.PermissionType == 2 {
  7461. // items[i].PermissionTypeName = "客观"
  7462. //}
  7463. }
  7464. //合并主观客观
  7465. mapPermissionName := make(map[string]int)
  7466. for _, v := range items {
  7467. if mapPermissionName[v.PermissionName] == 0 {
  7468. //plist.Items = append(plist.Items, v)
  7469. //mapPermissionName[v.PermissionName] = v.ChartPermissionId
  7470. // CRM8.8-只有客观的时候回显
  7471. if mapPermissionCheck[v.PermissionName] == 0 || (mapPermissionCheck[v.PermissionName] > 0 && v.ChartPermissionId == mapPermissionCheck[v.PermissionName]) {
  7472. plist.Items = append(plist.Items, v)
  7473. mapPermissionName[v.PermissionName] = v.ChartPermissionId
  7474. }
  7475. }
  7476. }
  7477. plist.ClassifyName = v.PermissionName
  7478. plist.CheckList = checkList
  7479. if companyType == "ficc" {
  7480. resp.FiccPermissionList = append(resp.FiccPermissionList, plist)
  7481. } else {
  7482. resp.PermissionList = append(resp.PermissionList, plist)
  7483. }
  7484. }
  7485. }
  7486. br.Ret = 200
  7487. br.Success = true
  7488. br.Msg = "获取成功"
  7489. br.Data = resp
  7490. }
  7491. // @Title 获取客户来源列表
  7492. // @Description 获取客户来源列表
  7493. // @Success 200 {object} models.CompanySourceListResp
  7494. // @router /getCompanySourceList [get]
  7495. func (this *CompanyController) CompanySourceList() {
  7496. br := new(models.BaseResponse).Init()
  7497. defer func() {
  7498. this.Data["json"] = br
  7499. this.ServeJSON()
  7500. }()
  7501. sysUser := this.SysUser
  7502. if sysUser == nil {
  7503. br.Msg = "请登录"
  7504. br.ErrMsg = "请登录,SysUser Is Empty"
  7505. br.Ret = 408
  7506. return
  7507. }
  7508. list, err := models.GetAllCompanySourceList()
  7509. if err != nil {
  7510. br.Msg = "查询失败"
  7511. br.ErrMsg = "查询异常:" + err.Error()
  7512. return
  7513. }
  7514. br.Ret = 200
  7515. br.Success = true
  7516. br.Msg = "获取成功"
  7517. br.Data = models.CompanySourceListResp{
  7518. List: list,
  7519. }
  7520. }
  7521. // @Title 获取客户的合同列表
  7522. // @Description 获取客户合同列表接口
  7523. // @Param CompanyId query int true "用户id"
  7524. // @Param CompanyType query string false "用户类型:可取范围:ficc,权益"
  7525. // @Param Status query int true "合同审核结果,枚举值:`0`,`1`; 0:待审核,1:审核通过"
  7526. // @Success 200 {object} company.CompanyPermissionResp
  7527. // @router /getCompanyContract [get]
  7528. func (this *CompanyController) ContractList() {
  7529. br := new(models.BaseResponse).Init()
  7530. defer func() {
  7531. this.Data["json"] = br
  7532. this.ServeJSON()
  7533. }()
  7534. sysUser := this.SysUser
  7535. if sysUser == nil {
  7536. br.Msg = "请登录"
  7537. br.ErrMsg = "请登录,SysUser Is Empty"
  7538. br.Ret = 408
  7539. return
  7540. }
  7541. companyId, _ := this.GetInt("CompanyId")
  7542. if companyId <= 0 {
  7543. br.Msg = "参数错误"
  7544. br.ErrMsg = "客户参数小于等于0"
  7545. return
  7546. }
  7547. //合同状态
  7548. status, _ := this.GetInt("Status")
  7549. //产品类型
  7550. companyType := this.GetString("CompanyType")
  7551. var condition string
  7552. var pars []interface{}
  7553. //产品类型
  7554. if companyType == "" {
  7555. productId := services.GetProductId(sysUser.RoleTypeCode)
  7556. if productId != 0 {
  7557. condition += " AND product_id = ?"
  7558. pars = append(pars, productId)
  7559. }
  7560. } else {
  7561. if companyType == "ficc" {
  7562. condition += " AND product_id = ?"
  7563. pars = append(pars, 1)
  7564. } else {
  7565. condition += " AND product_id = ?"
  7566. pars = append(pars, 2)
  7567. }
  7568. }
  7569. if status != 0 {
  7570. condition += " AND status = ?"
  7571. pars = append(pars, status)
  7572. }
  7573. list, err := company.GetCompanyContractListByCompanyId(companyId, condition, pars)
  7574. if err != nil {
  7575. br.Msg = "查询失败"
  7576. br.ErrMsg = "查询异常:" + err.Error()
  7577. return
  7578. }
  7579. br.Ret = 200
  7580. br.Success = true
  7581. br.Msg = "获取成功"
  7582. br.Data = list
  7583. }
  7584. // @Title 获取客户所属销售
  7585. // @Description 根据客户id获取客户所属销售
  7586. // @Param CompanyId query int true "客户id"
  7587. // @Success 200 {object} response.CompanySellerListResp
  7588. // @router /getCompanySellerList [get]
  7589. func (this *CompanyUserController) GetCompanySellerList() {
  7590. br := new(models.BaseResponse).Init()
  7591. defer func() {
  7592. this.Data["json"] = br
  7593. this.ServeJSON()
  7594. }()
  7595. sysUser := this.SysUser
  7596. if sysUser == nil {
  7597. br.Msg = "请登录"
  7598. br.ErrMsg = "请登录,SysUser Is Empty"
  7599. br.Ret = 408
  7600. return
  7601. }
  7602. companyId, _ := this.GetInt("CompanyId")
  7603. //item := make([]*company.CompanyItem, 0)
  7604. list, err := company.GetCompanySellerByCompanyId(companyId)
  7605. if err != nil && err.Error() != utils.ErrNoRow() {
  7606. br.Msg = "获取失败"
  7607. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  7608. return
  7609. }
  7610. resp := response.CompanySellerListResp{
  7611. List: list,
  7612. }
  7613. //resp.List = list
  7614. br.Ret = 200
  7615. br.Success = true
  7616. br.Msg = "获取成功"
  7617. br.Data = resp
  7618. }
  7619. // GetTryOutCompanyList
  7620. // @Title 获取销售今日待办数据
  7621. // @Description 获取销售今日待办接口
  7622. // @Param CompanyName query string false "客户名称"
  7623. // @Param ReasonStatus query int false "续约情况说明状态:-1:未填写,0:全部,1:已填写"
  7624. // @Param PageSize query int true "每页数据条数"
  7625. // @Param CurrentIndex query int true "当前页页码,从1开始"
  7626. // @Success 200 {object} response.TryOutCompanyListResp
  7627. // @router /getTryOutCompanyList [get]
  7628. func (this *CompanyController) GetTryOutCompanyList() {
  7629. br := new(models.BaseResponse).Init()
  7630. defer func() {
  7631. this.Data["json"] = br
  7632. this.ServeJSON()
  7633. }()
  7634. sysUser := this.SysUser
  7635. if sysUser == nil {
  7636. br.Msg = "请登录"
  7637. br.ErrMsg = "请登录,SysUser Is Empty"
  7638. br.Ret = 408
  7639. return
  7640. }
  7641. companyName := this.GetString("CompanyName")
  7642. reasonStatus, _ := this.GetInt("ReasonStatus", 0)
  7643. pageSize, _ := this.GetInt("PageSize")
  7644. currentIndex, _ := this.GetInt("CurrentIndex")
  7645. productId := services.GetProductId(sysUser.RoleTypeCode)
  7646. var startSize int
  7647. if pageSize <= 0 {
  7648. pageSize = utils.PageSize20
  7649. }
  7650. if currentIndex <= 0 {
  7651. currentIndex = 1
  7652. }
  7653. startSize = paging.StartIndex(currentIndex, pageSize)
  7654. var condition string
  7655. var pars []interface{}
  7656. //sellerId, productId int, tryOutTime time.Time, tryOutReason string
  7657. var tryOutTime, lastDescriptionTime time.Time
  7658. if productId == 1 {
  7659. //ficc
  7660. interval := cache.GetIntervalFromCrmConfig("try_out_time_intervals")
  7661. tryOutTime = time.Now().AddDate(0, 0, -interval)
  7662. interval = cache.GetIntervalFromCrmConfig("last_description_time_intervals")
  7663. lastDescriptionTime = time.Now().AddDate(0, 0, -interval)
  7664. } else {
  7665. //权益
  7666. interval := cache.GetIntervalFromCrmConfig("rai_try_out_time_intervals")
  7667. tryOutTime = time.Now().AddDate(0, 0, -interval)
  7668. interval = cache.GetIntervalFromCrmConfig("rai_last_description_time_intervals")
  7669. lastDescriptionTime = time.Now().AddDate(0, 0, -interval)
  7670. }
  7671. if productId > 0 {
  7672. condition += ` and product_id=? `
  7673. pars = append(pars, productId)
  7674. }
  7675. //客户名称模糊搜索
  7676. if companyName != "" {
  7677. condition += ` and b.company_name like "%` + companyName + `%" `
  7678. }
  7679. //续约情况说明(-1:未填写,0:全部,1:已填写)
  7680. switch reasonStatus {
  7681. case -1:
  7682. 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) `
  7683. pars = append(pars, sysUser.AdminId, tryOutTime, lastDescriptionTime)
  7684. case 1:
  7685. 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) `
  7686. pars = append(pars, sysUser.AdminId, tryOutTime)
  7687. default:
  7688. 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) `
  7689. pars = append(pars, sysUser.AdminId, tryOutTime, lastDescriptionTime)
  7690. }
  7691. total := 0
  7692. list := make([]*company.TryOutCompanyList, 0)
  7693. 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}
  7694. if strings.Contains(strings.Join(ignoreStrs, ","), sysUser.RoleTypeCode) {
  7695. //排除已经签署续约合同的
  7696. notSql := ``
  7697. if productId > 0 {
  7698. notSql = fmt.Sprint(` and product_id = `, productId)
  7699. }
  7700. condition += `and a.company_id not in (select company_id from company_contract where contract_type ="续约合同" and start_date >now() and status = 1 ` + notSql + `) `
  7701. tmpTotal, err := company.GetTryOutCompanyCount(condition, pars)
  7702. if err != nil {
  7703. br.Msg = "获取失败"
  7704. br.ErrMsg = "获取总数失败失败,Err:" + err.Error()
  7705. return
  7706. }
  7707. tmpList, err := company.GetTryOutCompanyList(condition, pars, startSize, pageSize)
  7708. if err != nil {
  7709. br.Msg = "获取失败"
  7710. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  7711. return
  7712. }
  7713. total = tmpTotal
  7714. list = tmpList
  7715. }
  7716. if len(list) > 0 {
  7717. for k, item := range list {
  7718. endTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  7719. endTime = endTime.AddDate(0, 0, 1)
  7720. sub := endTime.Sub(time.Now())
  7721. if sub < 0 {
  7722. sub = 0
  7723. }
  7724. list[k].ExpireDays = int(sub.Hours() / 24)
  7725. }
  7726. }
  7727. page := paging.GetPaging(currentIndex, pageSize, total)
  7728. resp := response.TryOutCompanyListResp{
  7729. List: list,
  7730. Paging: page,
  7731. }
  7732. br.Ret = 200
  7733. br.Success = true
  7734. br.Msg = "获取成功"
  7735. br.Data = resp
  7736. }
  7737. // EditTryOutCompanyReason
  7738. // @Title 编辑续约说明情况
  7739. // @Description 编辑续约说明情况接口
  7740. // @Param request body company.RenewalReasonReq true "type json string"
  7741. // @Success 200 编辑成功
  7742. // @router /editTryOutCompanyReason [post]
  7743. func (this *CompanyController) EditTryOutCompanyReason() {
  7744. br := new(models.BaseResponse).Init()
  7745. defer func() {
  7746. this.Data["json"] = br
  7747. this.ServeJSON()
  7748. }()
  7749. sysUser := this.SysUser
  7750. if sysUser == nil {
  7751. br.Msg = "请登录"
  7752. br.ErrMsg = "请登录,SysUser Is Empty"
  7753. br.Ret = 408
  7754. return
  7755. }
  7756. var req company.RenewalReasonReq
  7757. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  7758. if err != nil {
  7759. br.Msg = "参数解析异常!"
  7760. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  7761. return
  7762. }
  7763. if req.CompanyId <= 0 {
  7764. br.Msg = "参数缺失"
  7765. br.ErrMsg = "参数缺失,客户编号未传!"
  7766. return
  7767. }
  7768. if req.ProductId <= 0 {
  7769. br.Msg = "参数缺失"
  7770. br.ErrMsg = "参数缺失,产品编号未传!"
  7771. return
  7772. }
  7773. if req.Remark == "" {
  7774. br.Msg = "参数缺失"
  7775. br.ErrMsg = "参数缺失,续约情况说明未传!"
  7776. return
  7777. }
  7778. /*if req.RenewalTodo == "" && req.Renew == 0 {
  7779. br.Msg = "参数缺失"
  7780. br.ErrMsg = "参数缺失,待办事项说明未传!"
  7781. return
  7782. }*/
  7783. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  7784. if err != nil {
  7785. br.Msg = "查询客户异常"
  7786. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  7787. return
  7788. }
  7789. if companyProduct.SellerId != sysUser.AdminId {
  7790. br.Msg = "客户异常,没有该客户的操作权限"
  7791. br.ErrMsg = "客户异常,没有该客户的操作权限"
  7792. return
  7793. }
  7794. renewalReason := company.CompanyRenewalReason{
  7795. CompanyRenewalReasonId: 0,
  7796. CompanyId: companyProduct.CompanyId,
  7797. ProductId: companyProduct.ProductId,
  7798. ProductName: companyProduct.ProductName,
  7799. CompanyName: companyProduct.CompanyName,
  7800. TryOutTime: companyProduct.TryOutTime,
  7801. RenewalReason: req.Remark,
  7802. RenewalTodo: req.RenewalTodo,
  7803. LastDescriptionTime: companyProduct.LastDescriptionTime,
  7804. EndDays: companyProduct.ContractEndDate,
  7805. ExpirationTimeExceeded: 0,
  7806. RenewalIntention: req.Renew,
  7807. CreateTime: time.Now(),
  7808. }
  7809. endTime, err := company.GetTryOutTimeFromOperationRecord(renewalReason.CompanyId)
  7810. if err != nil {
  7811. br.Msg = "查询该客户转试用时间异常!"
  7812. br.ErrMsg = "查询该客户转试用时间异常,err:" + err.Error()
  7813. return
  7814. }
  7815. endDateTime, err := time.Parse(utils.FormatDateTime, *endTime)
  7816. if err != nil {
  7817. br.Msg = "时间格式化异常!"
  7818. br.ErrMsg = "时间格式化异常,err:" + err.Error()
  7819. return
  7820. }
  7821. endDate := endDateTime.Format(utils.FormatDate)
  7822. endDateTime, _ = time.Parse(utils.FormatDate, endDate)
  7823. sub := time.Now().Sub(endDateTime)
  7824. renewalReason.ExpirationTimeExceeded = int(sub.Hours() / 24)
  7825. var newId int64
  7826. newId, err = company.AddRenewalReason(&renewalReason)
  7827. if err != nil {
  7828. br.Msg = "新增续约情况说明操作异常!"
  7829. br.ErrMsg = "新增续约情况说明操作异常,err:" + err.Error()
  7830. return
  7831. }
  7832. companyProduct.RenewalIntention = req.Renew
  7833. err = company.EditTryOutCompanyReason(companyProduct, req.Remark, req.RenewalTodo)
  7834. if err != nil {
  7835. br.Msg = "更新客户未续约异常!"
  7836. br.ErrMsg = "更新客户未续约异常,err:" + err.Error()
  7837. return
  7838. }
  7839. if req.Renew == 1 {
  7840. productName := ""
  7841. if req.ProductId == 1 {
  7842. productName = "ficc"
  7843. } else if req.ProductId == 2 {
  7844. productName = "权益"
  7845. } else {
  7846. productName = "佣金客户"
  7847. }
  7848. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  7849. if err != nil {
  7850. br.Msg = "查询该客户产品异常!"
  7851. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  7852. return
  7853. }
  7854. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  7855. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  7856. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  7857. return
  7858. }
  7859. //查询客户的产品权限
  7860. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, req.ProductId)
  7861. if err != nil {
  7862. br.Msg = "查询客户的产品权限异常"
  7863. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  7864. return
  7865. }
  7866. err = company.CompanyFreeze(req.CompanyId, req.ProductId, req.Remark)
  7867. if err != nil {
  7868. br.Msg = "冻结失败!"
  7869. br.ErrMsg = "冻结失败,Err:" + err.Error()
  7870. return
  7871. }
  7872. //新增操作记录
  7873. go func() {
  7874. time.Sleep(time.Second)
  7875. approveContent := req.Remark
  7876. remark := "冻结客户"
  7877. operation := "freeze"
  7878. _ = services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  7879. productName, "超级管理员", remark, operation, approveContent, sysUser.RealName, "", "冻结")
  7880. //新增产品权限冻结操作日志
  7881. for _, companyReportPermission := range companyReportPermissionList {
  7882. record := company_report_permission_log.CompanyReportPermissionLog{
  7883. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  7884. CompanyId: companyReportPermission.CompanyId,
  7885. ProductId: req.ProductId,
  7886. ProductName: companyReportPermission.ProductName,
  7887. SysUserId: sysUser.AdminId,
  7888. SysUserName: "超级管理员",
  7889. Remark: "冻结客户",
  7890. Operation: "freeze",
  7891. Status: companyReportPermission.Status,
  7892. CreateTime: time.Now(),
  7893. }
  7894. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  7895. }
  7896. }()
  7897. }
  7898. approveContent := req.Remark
  7899. approveContentExtra := req.RenewalTodo
  7900. remark := "新增续约说明"
  7901. operation := "edit_renewal_reason"
  7902. _ = services.AddCompanyOperationRecordMore(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  7903. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, approveContentExtra, sysUser.RealName, "", companyProduct.Status)
  7904. items, err := company.ReadCompanyOperationRecord(req.CompanyId)
  7905. if err != nil {
  7906. br.Msg = "编辑失败"
  7907. br.ErrMsg = "编辑失败,Err:" + err.Error()
  7908. return
  7909. }
  7910. if len(items) > 0 {
  7911. record := new(company.CompanyOperationRecord)
  7912. record.Id = items[0].Id
  7913. record.ApproveContent = req.Remark
  7914. record.ApproveContentExtra = req.RenewalTodo
  7915. _, err = company.UpdateCompanyOperationRecord(record)
  7916. if err != nil {
  7917. br.Msg = "编辑失败"
  7918. br.ErrMsg = "编辑失败,Err:" + err.Error()
  7919. return
  7920. }
  7921. } else {
  7922. br.Msg = "编辑失败"
  7923. br.ErrMsg = "编辑失败,未查询到转试用记录"
  7924. return
  7925. }
  7926. if req.ProductId == utils.COMPANY_PRODUCT_RAI_ID {
  7927. //权益客户新增历史备注总表
  7928. itemRecord := new(company.CompanyHistoryRemark)
  7929. itemRecord.CompanyId = req.CompanyId
  7930. itemRecord.Content = req.Remark
  7931. itemRecord.SysAdminId = sysUser.AdminId
  7932. itemRecord.SysAdminName = sysUser.RealName
  7933. itemRecord.CreateTime = time.Now().Local()
  7934. itemRecord.ModifyTime = time.Now().Local()
  7935. itemRecord.ShowTime = time.Now().Local()
  7936. itemRecord.ProductId = 2
  7937. itemRecord.TableName = "company_renewal_reason"
  7938. itemRecord.TableId = int(newId)
  7939. go services.AddCompanyHistoryRemark(itemRecord)
  7940. }
  7941. br.Ret = 200
  7942. br.Success = true
  7943. br.Msg = "编辑成功"
  7944. }
  7945. // AddTryOutCompanyReason
  7946. // @Title 新增续约说明情况
  7947. // @Description 新增续约说明情况接口
  7948. // @Param request body company.RenewalReasonReq true "type json string"
  7949. // @Success 200 编辑成功
  7950. // @router /addTryOutCompanyReason [post]
  7951. func (this *CompanyController) AddTryOutCompanyReason() {
  7952. br := new(models.BaseResponse).Init()
  7953. defer func() {
  7954. this.Data["json"] = br
  7955. this.ServeJSON()
  7956. }()
  7957. sysUser := this.SysUser
  7958. if sysUser == nil {
  7959. br.Msg = "请登录"
  7960. br.ErrMsg = "请登录,SysUser Is Empty"
  7961. br.Ret = 408
  7962. return
  7963. }
  7964. var req company.RenewalReasonReq
  7965. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  7966. if err != nil {
  7967. br.Msg = "参数解析异常!"
  7968. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  7969. return
  7970. }
  7971. if req.CompanyId <= 0 {
  7972. br.Msg = "参数缺失"
  7973. br.ErrMsg = "参数缺失,客户编号未传!"
  7974. return
  7975. }
  7976. if req.ProductId <= 0 {
  7977. br.Msg = "参数缺失"
  7978. br.ErrMsg = "参数缺失,产品编号未传!"
  7979. return
  7980. }
  7981. if req.Remark == "" {
  7982. br.Msg = "参数缺失"
  7983. br.ErrMsg = "参数缺失,续约情况说明未传!"
  7984. return
  7985. }
  7986. if req.RenewalTodo == "" && req.Renew == 0 {
  7987. br.Msg = "参数缺失"
  7988. br.ErrMsg = "参数缺失,待办事项说明未传!"
  7989. return
  7990. }
  7991. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  7992. if err != nil {
  7993. br.Msg = "查询客户异常"
  7994. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  7995. return
  7996. }
  7997. if companyProduct.SellerId != sysUser.AdminId {
  7998. br.Msg = "客户异常,没有该客户的操作权限"
  7999. br.ErrMsg = "客户异常,没有该客户的操作权限"
  8000. return
  8001. }
  8002. renewalReason := company.CompanyRenewalReason{
  8003. CompanyRenewalReasonId: 0,
  8004. CompanyId: companyProduct.CompanyId,
  8005. ProductId: companyProduct.ProductId,
  8006. ProductName: companyProduct.ProductName,
  8007. CompanyName: companyProduct.CompanyName,
  8008. TryOutTime: companyProduct.TryOutTime,
  8009. RenewalReason: req.Remark,
  8010. RenewalTodo: req.RenewalTodo,
  8011. LastDescriptionTime: companyProduct.LastDescriptionTime,
  8012. EndDays: companyProduct.ContractEndDate,
  8013. ExpirationTimeExceeded: 0,
  8014. RenewalIntention: req.Renew,
  8015. CreateTime: time.Now(),
  8016. }
  8017. endTime, err := company.GetTryOutTimeFromOperationRecord(renewalReason.CompanyId)
  8018. if err != nil {
  8019. br.Msg = "查询该客户转试用时间异常!"
  8020. br.ErrMsg = "查询该客户转试用时间异常,err:" + err.Error()
  8021. return
  8022. }
  8023. endDateTime, err := time.Parse(utils.FormatDateTime, *endTime)
  8024. if err != nil {
  8025. br.Msg = "时间格式化异常!"
  8026. br.ErrMsg = "时间格式化异常,err:" + err.Error()
  8027. return
  8028. }
  8029. endDate := endDateTime.Format(utils.FormatDate)
  8030. endDateTime, _ = time.Parse(utils.FormatDate, endDate)
  8031. sub := time.Now().Sub(endDateTime)
  8032. renewalReason.ExpirationTimeExceeded = int(sub.Hours() / 24)
  8033. var newId int64
  8034. newId, err = company.AddRenewalReason(&renewalReason)
  8035. if err != nil {
  8036. br.Msg = "新增续约情况说明操作异常!"
  8037. br.ErrMsg = "新增续约情况说明操作异常,err:" + err.Error()
  8038. return
  8039. }
  8040. companyProduct.RenewalIntention = req.Renew
  8041. err = company.EditTryOutCompanyReason(companyProduct, req.Remark, req.RenewalTodo)
  8042. if err != nil {
  8043. br.Msg = "更新客户续约情况说明异常!"
  8044. br.ErrMsg = "更新客户续约情况说明异常,err:" + err.Error()
  8045. return
  8046. }
  8047. if req.Renew == 1 {
  8048. productName := ""
  8049. if req.ProductId == 1 {
  8050. productName = "ficc"
  8051. } else if req.ProductId == 2 {
  8052. productName = "权益"
  8053. } else {
  8054. productName = "佣金客户"
  8055. }
  8056. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  8057. if err != nil {
  8058. br.Msg = "查询该客户产品异常!"
  8059. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  8060. return
  8061. }
  8062. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  8063. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  8064. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  8065. return
  8066. }
  8067. //查询客户的产品权限
  8068. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, req.ProductId)
  8069. if err != nil {
  8070. br.Msg = "查询客户的产品权限异常"
  8071. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  8072. return
  8073. }
  8074. err = company.CompanyFreeze(req.CompanyId, req.ProductId, req.Remark)
  8075. if err != nil {
  8076. br.Msg = "冻结失败!"
  8077. br.ErrMsg = "冻结失败,Err:" + err.Error()
  8078. return
  8079. }
  8080. //新增操作记录
  8081. go func() {
  8082. time.Sleep(time.Second)
  8083. approveContent := req.Remark
  8084. remark := "冻结客户"
  8085. operation := "freeze"
  8086. _ = services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  8087. productName, "超级管理员", remark, operation, approveContent, sysUser.RealName, "", "冻结")
  8088. //新增产品权限冻结操作日志
  8089. for _, companyReportPermission := range companyReportPermissionList {
  8090. record := company_report_permission_log.CompanyReportPermissionLog{
  8091. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  8092. CompanyId: companyReportPermission.CompanyId,
  8093. ProductId: req.ProductId,
  8094. ProductName: companyReportPermission.ProductName,
  8095. SysUserId: sysUser.AdminId,
  8096. SysUserName: "超级管理员",
  8097. Remark: "冻结客户",
  8098. Operation: "freeze",
  8099. Status: companyReportPermission.Status,
  8100. CreateTime: time.Now(),
  8101. }
  8102. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  8103. }
  8104. }()
  8105. }
  8106. {
  8107. approveContent := req.Remark
  8108. approveContentExtra := req.RenewalTodo
  8109. remark := "新增续约说明"
  8110. operation := "add_renewal_reason"
  8111. _ = services.AddCompanyOperationRecordMore(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  8112. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, approveContentExtra, sysUser.RealName, "", companyProduct.Status)
  8113. }
  8114. if req.ProductId == utils.COMPANY_PRODUCT_RAI_ID {
  8115. //权益客户新增历史备注总表
  8116. itemRecord := new(company.CompanyHistoryRemark)
  8117. itemRecord.CompanyId = req.CompanyId
  8118. itemRecord.Content = req.Remark
  8119. itemRecord.SysAdminId = sysUser.AdminId
  8120. itemRecord.SysAdminName = sysUser.RealName
  8121. itemRecord.CreateTime = time.Now().Local()
  8122. itemRecord.ModifyTime = time.Now().Local()
  8123. itemRecord.ShowTime = time.Now().Local()
  8124. itemRecord.ProductId = 2
  8125. itemRecord.TableName = "company_renewal_reason"
  8126. itemRecord.TableId = int(newId)
  8127. go services.AddCompanyHistoryRemark(itemRecord)
  8128. }
  8129. br.Ret = 200
  8130. br.Success = true
  8131. br.Msg = "编辑成功"
  8132. }
  8133. // RenewReasonList 客户未续约说明历史列表
  8134. // @Title 客户未续约说明历史列表
  8135. // @Description 客户未续约说明历史列表
  8136. // @Param CompanyId query string true "客户id"
  8137. // @Param ProductId query string true "产品id"
  8138. // @Success 200 {object} response.RenewReasonItemResp
  8139. // @router /renewReasonList [get]
  8140. func (this *CompanyController) RenewReasonList() {
  8141. br := new(models.BaseResponse).Init()
  8142. defer func() {
  8143. this.Data["json"] = br
  8144. this.ServeJSON()
  8145. }()
  8146. sysUser := this.SysUser
  8147. if sysUser == nil {
  8148. br.Msg = "请登录"
  8149. br.ErrMsg = "请登录,SysUser Is Empty"
  8150. br.Ret = 408
  8151. return
  8152. }
  8153. CompanyId := this.GetString("CompanyId")
  8154. ProductId := this.GetString("ProductId")
  8155. if CompanyId == "" {
  8156. br.Msg = "请输入客户ID"
  8157. return
  8158. }
  8159. if ProductId != "1" && ProductId != "2" {
  8160. br.Msg = "请输入正确的产品ID"
  8161. return
  8162. }
  8163. renewalReason, err := models.GetMoreRenewalReason(CompanyId, ProductId)
  8164. if err != nil {
  8165. br.Msg = "获取失败"
  8166. br.ErrMsg = "获取失败,Err:" + err.Error()
  8167. return
  8168. }
  8169. resp := make([]response.RenewReasonItemResp, len(renewalReason))
  8170. for i, reason := range renewalReason {
  8171. createDate := reason.CreateTime.Format("2006.01.02 15:04:05")
  8172. resp[i].RenewalReason = reason.RenewalReason
  8173. resp[i].RenewalTodo = reason.RenewalTodo
  8174. resp[i].CreateTime = createDate
  8175. }
  8176. br.Ret = 200
  8177. br.Success = true
  8178. br.Msg = "获取成功"
  8179. br.Data = resp
  8180. }
  8181. // AddRenewalReason
  8182. // @Title 转试用按钮新增续约说明情况
  8183. // @Description 转试用按钮新增续约说明情况
  8184. // @Param request body company.TryOutReq true "type json string"
  8185. // @Success 200 编辑成功
  8186. // @router /addRenewalReason [post]
  8187. func (this *CompanyController) AddRenewalReason() {
  8188. br := new(models.BaseResponse).Init()
  8189. defer func() {
  8190. this.Data["json"] = br
  8191. this.ServeJSON()
  8192. }()
  8193. sysUser := this.SysUser
  8194. if sysUser == nil {
  8195. br.Msg = "请登录"
  8196. br.ErrMsg = "请登录,SysUser Is Empty"
  8197. br.Ret = 408
  8198. return
  8199. }
  8200. var req company.TryOutReq
  8201. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  8202. if err != nil {
  8203. br.Msg = "参数解析异常!"
  8204. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  8205. return
  8206. }
  8207. if req.CompanyId <= 0 {
  8208. br.Msg = "参数缺失"
  8209. br.ErrMsg = "参数缺失,客户编号未传!"
  8210. return
  8211. }
  8212. if req.ProductId <= 0 {
  8213. br.Msg = "参数缺失"
  8214. br.ErrMsg = "参数缺失,产品编号未传!"
  8215. return
  8216. }
  8217. if req.OperationId <= 0 {
  8218. br.Msg = "参数缺失"
  8219. br.ErrMsg = "参数缺失,操作记录表编号未传!"
  8220. return
  8221. }
  8222. if req.Remark == "" {
  8223. br.Msg = "参数缺失"
  8224. br.ErrMsg = "参数缺失,续约情况说明未传!"
  8225. return
  8226. }
  8227. if req.RenewalTodo == "" && req.Renew == 0 {
  8228. br.Msg = "参数缺失"
  8229. br.ErrMsg = "参数缺失,待办事项说明未传!"
  8230. return
  8231. }
  8232. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  8233. if err != nil {
  8234. br.Msg = "查询客户异常"
  8235. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  8236. return
  8237. }
  8238. if companyProduct.SellerId != sysUser.AdminId {
  8239. br.Msg = "客户异常,没有该客户的操作权限"
  8240. br.ErrMsg = "客户异常,没有该客户的操作权限"
  8241. return
  8242. }
  8243. renewalReason := company.CompanyRenewalReason{
  8244. CompanyRenewalReasonId: 0,
  8245. CompanyId: companyProduct.CompanyId,
  8246. ProductId: companyProduct.ProductId,
  8247. ProductName: companyProduct.ProductName,
  8248. CompanyName: companyProduct.CompanyName,
  8249. TryOutTime: companyProduct.TryOutTime,
  8250. RenewalReason: req.Remark,
  8251. RenewalTodo: req.RenewalTodo,
  8252. LastDescriptionTime: companyProduct.LastDescriptionTime,
  8253. EndDays: companyProduct.ContractEndDate,
  8254. ExpirationTimeExceeded: 0,
  8255. RenewalIntention: req.Renew,
  8256. CreateTime: time.Now(),
  8257. }
  8258. endTime, err := company.GetTryOutTimeFromOperationRecord(renewalReason.CompanyId)
  8259. if err != nil {
  8260. br.Msg = "查询该客户转试用时间异常!"
  8261. br.ErrMsg = "查询该客户转试用时间异常,err:" + err.Error()
  8262. return
  8263. }
  8264. endDateTime, err := time.Parse(utils.FormatDateTime, *endTime)
  8265. if err != nil {
  8266. br.Msg = "时间格式化异常!"
  8267. br.ErrMsg = "时间格式化异常,err:" + err.Error()
  8268. return
  8269. }
  8270. endDate := endDateTime.Format(utils.FormatDate)
  8271. endDateTime, _ = time.Parse(utils.FormatDate, endDate)
  8272. sub := time.Now().Sub(endDateTime)
  8273. renewalReason.ExpirationTimeExceeded = int(sub.Hours() / 24)
  8274. var newId int64
  8275. newId, err = company.AddRenewalReason(&renewalReason)
  8276. if err != nil {
  8277. br.Msg = "新增续约情况说明操作异常!"
  8278. br.ErrMsg = "新增续约情况说明操作异常,err:" + err.Error()
  8279. return
  8280. }
  8281. companyProduct.RenewalIntention = req.Renew
  8282. err = company.EditTryOutCompanyReason(companyProduct, req.Remark, req.RenewalTodo)
  8283. if err != nil {
  8284. br.Msg = "更新客户续约情况说明异常!"
  8285. br.ErrMsg = "更新客户续约情况说明异常,err:" + err.Error()
  8286. return
  8287. }
  8288. if req.Renew == 1 {
  8289. productName := ""
  8290. if req.ProductId == 1 {
  8291. productName = "ficc"
  8292. } else if req.ProductId == 2 {
  8293. productName = "权益"
  8294. } else {
  8295. productName = "佣金客户"
  8296. }
  8297. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  8298. if err != nil {
  8299. br.Msg = "查询该客户产品异常!"
  8300. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  8301. return
  8302. }
  8303. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  8304. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  8305. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  8306. return
  8307. }
  8308. //查询客户的产品权限
  8309. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, req.ProductId)
  8310. if err != nil {
  8311. br.Msg = "查询客户的产品权限异常"
  8312. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  8313. return
  8314. }
  8315. err = company.CompanyFreeze(req.CompanyId, req.ProductId, req.Remark)
  8316. if err != nil {
  8317. br.Msg = "冻结失败!"
  8318. br.ErrMsg = "冻结失败,Err:" + err.Error()
  8319. return
  8320. }
  8321. //新增操作记录
  8322. go func() {
  8323. time.Sleep(time.Second)
  8324. approveContent := req.Remark
  8325. remark := "冻结客户"
  8326. operation := "freeze"
  8327. _ = services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  8328. productName, "超级管理员", remark, operation, approveContent, sysUser.RealName, "", "冻结")
  8329. //新增产品权限冻结操作日志
  8330. for _, companyReportPermission := range companyReportPermissionList {
  8331. record := company_report_permission_log.CompanyReportPermissionLog{
  8332. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  8333. CompanyId: companyReportPermission.CompanyId,
  8334. ProductId: req.ProductId,
  8335. ProductName: companyReportPermission.ProductName,
  8336. SysUserId: sysUser.AdminId,
  8337. SysUserName: "超级管理员",
  8338. Remark: "冻结客户",
  8339. Operation: "freeze",
  8340. Status: companyReportPermission.Status,
  8341. CreateTime: time.Now(),
  8342. }
  8343. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  8344. }
  8345. }()
  8346. }
  8347. {
  8348. approveContent := req.Remark
  8349. approveContentExtra := req.RenewalTodo
  8350. remark := "新增续约说明"
  8351. operation := "add_try_out_reason"
  8352. _ = services.AddCompanyOperationRecordMore(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  8353. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, approveContentExtra, sysUser.RealName, "", companyProduct.Status)
  8354. record := new(company.CompanyOperationRecord)
  8355. record.Id = req.OperationId
  8356. record.ApproveContent = req.Remark
  8357. record.ApproveContentExtra = req.RenewalTodo
  8358. _, err = company.UpdateCompanyOperationRecord(record)
  8359. if err != nil {
  8360. br.Msg = "编辑失败"
  8361. br.ErrMsg = "编辑失败,Err:" + err.Error()
  8362. return
  8363. }
  8364. }
  8365. if req.ProductId == utils.COMPANY_PRODUCT_RAI_ID {
  8366. //权益客户新增历史备注总表
  8367. itemRecord := new(company.CompanyHistoryRemark)
  8368. itemRecord.CompanyId = req.CompanyId
  8369. itemRecord.Content = req.Remark
  8370. itemRecord.SysAdminId = sysUser.AdminId
  8371. itemRecord.SysAdminName = sysUser.RealName
  8372. itemRecord.CreateTime = time.Now().Local()
  8373. itemRecord.ModifyTime = time.Now().Local()
  8374. itemRecord.ShowTime = time.Now().Local()
  8375. itemRecord.ProductId = 2
  8376. itemRecord.TableName = "company_renewal_reason"
  8377. itemRecord.TableId = int(newId)
  8378. go services.AddCompanyHistoryRemark(itemRecord)
  8379. }
  8380. br.Ret = 200
  8381. br.Success = true
  8382. br.Msg = "编辑成功"
  8383. }
  8384. // AddRemark
  8385. // @Title 新增备注
  8386. // @Description 新增备注
  8387. // @Param request body company.RemarkReq true "type json string"
  8388. // @Success 200 编辑成功
  8389. // @router /remark/add [post]
  8390. func (this *CompanyController) AddRemark() {
  8391. br := new(models.BaseResponse).Init()
  8392. defer func() {
  8393. this.Data["json"] = br
  8394. this.ServeJSON()
  8395. }()
  8396. sysUser := this.SysUser
  8397. if sysUser == nil {
  8398. br.Msg = "请登录"
  8399. br.ErrMsg = "请登录,SysUser Is Empty"
  8400. br.Ret = 408
  8401. return
  8402. }
  8403. var req company.RemarkReq
  8404. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  8405. if err != nil {
  8406. br.Msg = "参数解析异常!"
  8407. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  8408. return
  8409. }
  8410. if req.CompanyId <= 0 {
  8411. br.Msg = "参数缺失"
  8412. br.ErrMsg = "参数缺失,客户编号未传!"
  8413. return
  8414. }
  8415. if req.Remark == "" {
  8416. br.Msg = "参数缺失"
  8417. br.ErrMsg = "参数缺失,备注说明未传!"
  8418. return
  8419. }
  8420. var productId int
  8421. //var productName string
  8422. 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 {
  8423. productId = 1
  8424. //productName = "ficc"
  8425. } 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 {
  8426. productId = 2
  8427. //productName = "权益"
  8428. } else {
  8429. br.Msg = "角色类型错误"
  8430. br.ErrMsg = "角色类型错误,该角色不能添加备注!"
  8431. return
  8432. }
  8433. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  8434. if err != nil {
  8435. br.Msg = "查询客户异常"
  8436. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  8437. }
  8438. if companyProduct.SellerId != sysUser.AdminId {
  8439. br.Msg = "客户异常,没有该客户的操作权限"
  8440. br.ErrMsg = "客户异常,没有该客户的操作权限"
  8441. return
  8442. }
  8443. remark := company.CompanyProductRemark{
  8444. CompanyId: companyProduct.CompanyId,
  8445. ProductId: companyProduct.ProductId,
  8446. ProductName: companyProduct.ProductName,
  8447. Remark: req.Remark,
  8448. CreateTime: time.Now(),
  8449. SysUserId: sysUser.AdminId,
  8450. SysRealName: sysUser.RealName,
  8451. }
  8452. var newId int64
  8453. newId, err = company.AddCompanyRemark(&remark)
  8454. {
  8455. approveContent := req.Remark
  8456. remark := "新增备注"
  8457. operation := "add_remark"
  8458. services.AddCompanyOperationRecord(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  8459. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, sysUser.RealName, "", companyProduct.Status)
  8460. }
  8461. if err != nil {
  8462. br.Msg = "编辑失败"
  8463. br.ErrMsg = "编辑失败,Err:" + err.Error()
  8464. }
  8465. //如果是权益的写入历史备注表
  8466. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  8467. //权益客户新增历史备注总表
  8468. itemRecord := new(company.CompanyHistoryRemark)
  8469. itemRecord.CompanyId = req.CompanyId
  8470. itemRecord.Content = req.Remark
  8471. itemRecord.SysAdminId = sysUser.AdminId
  8472. itemRecord.SysAdminName = sysUser.RealName
  8473. itemRecord.CreateTime = time.Now().Local()
  8474. itemRecord.ModifyTime = time.Now().Local()
  8475. itemRecord.ShowTime = time.Now().Local()
  8476. itemRecord.ProductId = 2
  8477. itemRecord.TableName = "company_product_remark"
  8478. itemRecord.TableId = int(newId)
  8479. go services.AddCompanyHistoryRemark(itemRecord)
  8480. }
  8481. br.Ret = 200
  8482. br.Success = true
  8483. br.Msg = "编辑成功"
  8484. }
  8485. // RemarkList 备注列表
  8486. // @Title 备注列表
  8487. // @Description 备注列表
  8488. // @Param CompanyId query string true "客户id"
  8489. // @Success 200 {object} company.RemarkResp
  8490. // @router /remark [get]
  8491. func (this *CompanyController) RemarkList() {
  8492. br := new(models.BaseResponse).Init()
  8493. defer func() {
  8494. this.Data["json"] = br
  8495. this.ServeJSON()
  8496. }()
  8497. sysUser := this.SysUser
  8498. if sysUser == nil {
  8499. br.Msg = "请登录"
  8500. br.ErrMsg = "请登录,SysUser Is Empty"
  8501. br.Ret = 408
  8502. return
  8503. }
  8504. companyId := this.GetString("CompanyId")
  8505. var remarkList []*company.CompanyProductRemark
  8506. var err error
  8507. groupFicc := []string{
  8508. utils.ROLE_TYPE_CODE_FICC_SELLER, utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_FICC_GROUP,
  8509. utils.ROLE_TYPE_CODE_FICC_DEPARTMENT, utils.ROLE_TYPE_CODE_FICC_ADMIN,
  8510. }
  8511. groupRai := []string{
  8512. utils.ROLE_TYPE_CODE_RAI_SELLER, utils.ROLE_TYPE_CODE_RAI_GROUP, utils.ROLE_TYPE_CODE_RAI_GROUP,
  8513. utils.ROLE_TYPE_CODE_RAI_DEPARTMENT, utils.ROLE_TYPE_CODE_RAI_ADMIN,
  8514. }
  8515. if utils.InArrayByStr(groupFicc, sysUser.RoleTypeCode) {
  8516. remarkList, err = company.GetRemarkList(companyId, "1")
  8517. if err != nil {
  8518. br.Msg = "获取失败"
  8519. br.ErrMsg = "获取失败,Err:" + err.Error()
  8520. return
  8521. }
  8522. }
  8523. if utils.InArrayByStr(groupRai, sysUser.RoleTypeCode) {
  8524. remarkList, err = company.GetRemarkList(companyId, "2")
  8525. if err != nil {
  8526. br.Msg = "获取失败"
  8527. br.ErrMsg = "获取失败,Err:" + err.Error()
  8528. return
  8529. }
  8530. }
  8531. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  8532. remarkList, err = company.GetRemarkListByCompanyId(companyId)
  8533. if err != nil {
  8534. br.Msg = "获取失败"
  8535. br.ErrMsg = "获取失败,Err:" + err.Error()
  8536. return
  8537. }
  8538. }
  8539. resp := make([]company.RemarkResp, len(remarkList))
  8540. for i, remark := range remarkList {
  8541. createDate := remark.CreateTime.Format(utils.FormatDateTime)
  8542. resp[i].RemarkId = remark.CompanyProductRemarkId
  8543. resp[i].Remark = remark.Remark
  8544. resp[i].ProductName = remark.ProductName
  8545. resp[i].CreateTime = createDate
  8546. // 仅自己添加的可删除
  8547. if remark.SysUserId == sysUser.AdminId {
  8548. resp[i].ButtonDel = true
  8549. }
  8550. }
  8551. br.Ret = 200
  8552. br.Success = true
  8553. br.Msg = "获取成功"
  8554. br.Data = resp
  8555. }
  8556. // RoadShowList 客户列表的路演详情列表
  8557. // @Title 路演详情列表
  8558. // @Description 路演详情列表
  8559. // @Param CompanyId query string true "客户id"
  8560. // @Success 200 {object} company.RoadShowListResp
  8561. // @router /roadShowList [get]
  8562. func (this *CompanyController) RoadShowList() {
  8563. br := new(models.BaseResponse).Init()
  8564. defer func() {
  8565. this.Data["json"] = br
  8566. this.ServeJSON()
  8567. }()
  8568. sysUser := this.SysUser
  8569. if sysUser == nil {
  8570. br.Msg = "请登录"
  8571. br.ErrMsg = "请登录,SysUser Is Empty"
  8572. br.Ret = 408
  8573. return
  8574. }
  8575. companyId := this.GetString("CompanyId")
  8576. companyIdInt, _ := strconv.Atoi(companyId)
  8577. if companyIdInt <= 0 {
  8578. br.Msg = "参数错误"
  8579. return
  8580. }
  8581. var englishCompany int
  8582. if companyIdInt > utils.EnCompanyIdStep {
  8583. companyIdInt = companyIdInt - utils.EnCompanyIdStep
  8584. englishCompany = 1
  8585. }
  8586. var err error
  8587. roadShowList, err := company.GetRoadShowList(companyIdInt, englishCompany)
  8588. if err != nil {
  8589. br.Msg = "获取失败"
  8590. br.ErrMsg = "获取失败,Err:" + err.Error()
  8591. return
  8592. }
  8593. //calendarIdSlice := make([]string, 0)
  8594. //for _, v := range roadShowList {
  8595. // calendarIdSlice = append(calendarIdSlice, strconv.Itoa(v.RsCalendarId))
  8596. //}
  8597. //calendarIdStr := strings.Join(calendarIdSlice, ",")
  8598. //researcherList, _ := company.GetRoadShowResearchers(calendarIdStr)
  8599. //roadShowTotalMap := make(map[int]int)
  8600. //for _, roadShowTotal := range researcherList {
  8601. // roadShowTotalMap[roadShowTotal.CompanyId] = roadShowTotal.Total
  8602. //}
  8603. resp := make([]company.RoadShowListResp, len(roadShowList))
  8604. for i, calendar := range roadShowList {
  8605. resp[i].SysUserRealName = calendar.SysUserRealName
  8606. resp[i].RoadshowType = calendar.RoadshowType
  8607. //线上为平台,线下为省市
  8608. if calendar.RoadshowType == "线上" {
  8609. resp[i].RoadshowPlatform = calendar.RoadshowPlatform
  8610. } else {
  8611. resp[i].RoadshowPlatform = calendar.Province + calendar.City
  8612. }
  8613. researchers, err := company.GetRoadShowResearchers(calendar.RsCalendarId)
  8614. if err != nil && err.Error() != utils.ErrNoRow() {
  8615. br.Msg = "获取研究员信息失败"
  8616. br.ErrMsg = "获取研究员信息失败,Err:" + err.Error()
  8617. return
  8618. }
  8619. var researcherList []string
  8620. for _, researcher := range researchers {
  8621. researcherList = append(researcherList, *researcher)
  8622. }
  8623. researcher := strings.Join(researcherList, ",")
  8624. resp[i].Researchers = researcher
  8625. resp[i].RoadShowTime = calendar.EndDate.Format("2006.01.02")
  8626. }
  8627. br.Ret = 200
  8628. br.Success = true
  8629. br.Msg = "获取成功"
  8630. br.Data = resp
  8631. }
  8632. // CustomerAreaStatistics
  8633. // @Title 客户区域统计
  8634. // @Description 获取客户区域统计接口
  8635. // @Param Date query string true "日期"
  8636. // @Param ProductId query Int true "产品Id"
  8637. // @Success 200 {object} statistic_report.CompanyRenewRecordResp
  8638. // @router /customerAreaStatistics [get]
  8639. func (this *CompanyController) CustomerAreaStatistics() {
  8640. br := new(models.BaseResponse).Init()
  8641. defer func() {
  8642. this.Data["json"] = br
  8643. this.ServeJSON()
  8644. }()
  8645. sysUser := this.SysUser
  8646. if sysUser == nil {
  8647. br.Msg = "请登录"
  8648. br.ErrMsg = "请登录,SysUser Is Empty"
  8649. br.Ret = 408
  8650. return
  8651. }
  8652. date := this.GetString("Date")
  8653. productId, _ := this.GetInt("ProductId", 1)
  8654. //获取列表
  8655. companyAreaDataMapList, _, err := statistic_report.GetAreaDateData(date, productId)
  8656. if err != nil {
  8657. br.Msg = "数据异常"
  8658. br.ErrMsg = "数据异常,Err:" + err.Error()
  8659. return
  8660. }
  8661. //获取省市数据
  8662. areaMap := make(map[string]string)
  8663. provinceMap := make(map[string][]string, 0)
  8664. list, err := statisticModels.GetAllCompanyArea()
  8665. for _, item := range list {
  8666. areaMap[item.City] = item.Province
  8667. }
  8668. for c, p := range areaMap {
  8669. citySlice := make([]string, 0)
  8670. citySlice = provinceMap[p]
  8671. citySlice = append(citySlice, c)
  8672. provinceMap[p] = citySlice
  8673. }
  8674. //数据处理
  8675. groupReportRecordList := make([]statistic_report.GroupCityRecord, 0)
  8676. resp := statistic_report.CustomerAreaStatisticsResp{
  8677. List: groupReportRecordList,
  8678. IsAdmin: false,
  8679. }
  8680. //除ficc管理员和超管之外的角色进入此页面时,正式客户数量>0时可点击,点击查看正式客户列表详情;
  8681. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  8682. resp.IsAdmin = true
  8683. }
  8684. startDateIndexList := make(map[int]string) //开始时间间隔map
  8685. endDateIndexList := make(map[int]string) //结束时间间隔map
  8686. tmpAllTryOutNumMap := make(map[int]int)
  8687. tmpAllFormalNumMap := make(map[int]int)
  8688. tmpAllActiveNumMap := make(map[int]int)
  8689. tmpAllAllActiveNumMap := make(map[int]int)
  8690. tmpAllNoIncrementalActiveNumMap := make(map[int]int)
  8691. tmpAllTryStagePushMap := make(map[int]int)
  8692. tmpAllTryStageFollowMap := make(map[int]int)
  8693. tmpAllTryStageReadyMap := make(map[int]int)
  8694. tmpAllTryStageInitMap := make(map[int]int)
  8695. for province, cityList := range provinceMap {
  8696. tmpGroupCityReportRecord := make([]statistic_report.CityRecord, 0)
  8697. tmpGroupCompanyReportRecordNumList := make([]statistic_report.CompanyAreaNum, 0)
  8698. tmpGroupTryOutNumMap := make(map[int]int)
  8699. tmpGroupFormalNumMap := make(map[int]int)
  8700. tmpGroupFormalCompanyIdsMap := make(map[int]string) //正式客户id
  8701. tmpGroupActiveNumMap := make(map[int]int)
  8702. tmpGroupAllActiveNumMap := make(map[int]int)
  8703. tmpGroupNoIncrementalActiveNumMap := make(map[int]int)
  8704. // 其他类型客户ID
  8705. tmpGroupTryOutCompanyIdsMap := make(map[int]string) //试用客户ID
  8706. tmpGroupPushCompanyIdsMap := make(map[int]string) //试用(推进)客户ID
  8707. tmpGroupFollowCompanyIdsMap := make(map[int]string) //试用(跟踪)客户ID
  8708. tmpGroupReadyCompanyIdsMap := make(map[int]string) //试用(预备)客户ID
  8709. tmpGroupInitCompanyIdsMap := make(map[int]string) //试用(未分类)客户ID
  8710. tmpGroupTryStagePushMap := make(map[int]int)
  8711. tmpGroupTryStageFollowMap := make(map[int]int)
  8712. tmpGroupTryStageReadyMap := make(map[int]int)
  8713. tmpGroupTryStageInitMap := make(map[int]int)
  8714. for _, city := range cityList {
  8715. //城市数据
  8716. //每个城市的数据
  8717. tmpCompanyReportRecordNumList := make([]statistic_report.CompanyAreaNum, 0)
  8718. for index, adminData := range companyAreaDataMapList {
  8719. startDateIndexList[index] = adminData.StartDate
  8720. endDateIndexList[index] = adminData.EndDate
  8721. var tmpTryOutNum, tmpFormalNum, tmpActiveStatus, tmpAllActiveStatus, tmpNoIncrementalActiveStatus int
  8722. var tmpTryStagePushNum, tmpTryStageFollowNum, tmpTryStageReadyNum, tmpTryStageInitNum int
  8723. var tmpFormalCompanyIds string //正式客户id集合
  8724. var tmpTryOutCompanyIds string //试用客户ID集合
  8725. var tmpPushCompanyIds string //试用(推进)客户ID集合
  8726. var tmpFollowCompanyIds string //试用(跟踪)客户ID集合
  8727. var tmpReadyCompanyIds string //试用(预备)客户ID集合
  8728. var tmpInitCompanyIds string //试用(未分类)客户ID集合
  8729. if num, ok := adminData.TryOutMap[city]; ok {
  8730. tmpTryOutNum = num
  8731. }
  8732. if num, ok := adminData.FormalMap[city]; ok {
  8733. tmpFormalNum = num
  8734. }
  8735. if companyIds, ok := adminData.FormalIdMap[city]; ok {
  8736. tmpFormalCompanyIds = companyIds
  8737. }
  8738. if companyIds, ok := adminData.TryOutIdMap[city]; ok {
  8739. tmpTryOutCompanyIds = companyIds
  8740. }
  8741. if companyIds, ok := adminData.TryStagePushIdsMap[city]; ok {
  8742. tmpPushCompanyIds = companyIds
  8743. }
  8744. if companyIds, ok := adminData.TryStageFollowIdsMap[city]; ok {
  8745. tmpFollowCompanyIds = companyIds
  8746. }
  8747. if companyIds, ok := adminData.TryStageReadyIdsMap[city]; ok {
  8748. tmpReadyCompanyIds = companyIds
  8749. }
  8750. if companyIds, ok := adminData.TryStageInitIdsMap[city]; ok {
  8751. tmpInitCompanyIds = companyIds
  8752. }
  8753. if num, ok := adminData.ActiveMap[city]; ok {
  8754. tmpActiveStatus = num
  8755. }
  8756. if num, ok := adminData.AllActiveMap[city]; ok {
  8757. tmpAllActiveStatus = num
  8758. }
  8759. if num, ok := adminData.NoIncrementalActiveMap[city]; ok {
  8760. tmpNoIncrementalActiveStatus = num
  8761. }
  8762. // 每个用户的试用标签统计 推进-跟踪-预备-未分类
  8763. if num, ok := adminData.TryStagePushNum[city]; ok {
  8764. tmpTryStagePushNum = num
  8765. }
  8766. if num, ok := adminData.TryStageFollowNum[city]; ok {
  8767. tmpTryStageFollowNum = num
  8768. }
  8769. if num, ok := adminData.TryStageReadyNum[city]; ok {
  8770. tmpTryStageReadyNum = num
  8771. }
  8772. if num, ok := adminData.TryStageInitNum[city]; ok {
  8773. tmpTryStageInitNum = num
  8774. }
  8775. tmpAdminRsReportRecordNum := statistic_report.CompanyAreaNum{
  8776. TryOutNum: tmpTryOutNum,
  8777. FormalNum: tmpFormalNum,
  8778. FormalIds: tmpFormalCompanyIds,
  8779. ActiveNum: tmpActiveStatus,
  8780. AllActiveNum: tmpAllActiveStatus,
  8781. NoIncrementalActiveNum: tmpNoIncrementalActiveStatus,
  8782. StartDate: adminData.StartDate,
  8783. EndDate: adminData.EndDate,
  8784. TryStagePushNum: tmpTryStagePushNum,
  8785. TryStageFollowNum: tmpTryStageFollowNum,
  8786. TryStageReadyNum: tmpTryStageReadyNum,
  8787. TryStageInitNum: tmpTryStageInitNum,
  8788. TotalNum: tmpTryOutNum + tmpFormalNum,
  8789. }
  8790. tmpCompanyReportRecordNumList = append(tmpCompanyReportRecordNumList, tmpAdminRsReportRecordNum)
  8791. //组内数据汇总
  8792. tmpGroupTryOutNumMap[index] += tmpTryOutNum
  8793. tmpGroupFormalNumMap[index] += tmpFormalNum
  8794. // 正式客户id
  8795. if tmpFormalCompanyIds != `` {
  8796. tmpGroupFormalCompanyIds, ok := tmpGroupFormalCompanyIdsMap[index]
  8797. if ok {
  8798. tmpGroupFormalCompanyIdsMap[index] = tmpGroupFormalCompanyIds + "," + tmpFormalCompanyIds
  8799. } else {
  8800. tmpGroupFormalCompanyIdsMap[index] = tmpFormalCompanyIds
  8801. }
  8802. }
  8803. tmpGroupActiveNumMap[index] += tmpActiveStatus
  8804. tmpGroupAllActiveNumMap[index] += tmpActiveStatus
  8805. tmpGroupNoIncrementalActiveNumMap[index] += tmpActiveStatus
  8806. tmpGroupTryStagePushMap[index] += tmpTryStagePushNum
  8807. tmpGroupTryStageFollowMap[index] += tmpTryStageFollowNum
  8808. tmpGroupTryStageReadyMap[index] += tmpTryStageReadyNum
  8809. tmpGroupTryStageInitMap[index] += tmpTryStageInitNum
  8810. // 其他客户IDs
  8811. if tmpTryOutCompanyIds != `` {
  8812. a, ok := tmpGroupTryOutCompanyIdsMap[index]
  8813. if ok {
  8814. tmpGroupTryOutCompanyIdsMap[index] = a + "," + tmpTryOutCompanyIds
  8815. } else {
  8816. tmpGroupTryOutCompanyIdsMap[index] = tmpTryOutCompanyIds
  8817. }
  8818. }
  8819. if tmpPushCompanyIds != `` {
  8820. a, ok := tmpGroupPushCompanyIdsMap[index]
  8821. if ok {
  8822. tmpGroupPushCompanyIdsMap[index] = a + "," + tmpPushCompanyIds
  8823. } else {
  8824. tmpGroupPushCompanyIdsMap[index] = tmpPushCompanyIds
  8825. }
  8826. }
  8827. if tmpFollowCompanyIds != `` {
  8828. a, ok := tmpGroupFollowCompanyIdsMap[index]
  8829. if ok {
  8830. tmpGroupFollowCompanyIdsMap[index] = a + "," + tmpFollowCompanyIds
  8831. } else {
  8832. tmpGroupFollowCompanyIdsMap[index] = tmpFollowCompanyIds
  8833. }
  8834. }
  8835. if tmpReadyCompanyIds != `` {
  8836. a, ok := tmpGroupReadyCompanyIdsMap[index]
  8837. if ok {
  8838. tmpGroupReadyCompanyIdsMap[index] = a + "," + tmpReadyCompanyIds
  8839. } else {
  8840. tmpGroupReadyCompanyIdsMap[index] = tmpReadyCompanyIds
  8841. }
  8842. }
  8843. if tmpInitCompanyIds != `` {
  8844. a, ok := tmpGroupInitCompanyIdsMap[index]
  8845. if ok {
  8846. tmpGroupInitCompanyIdsMap[index] = a + "," + tmpInitCompanyIds
  8847. } else {
  8848. tmpGroupInitCompanyIdsMap[index] = tmpInitCompanyIds
  8849. }
  8850. }
  8851. //总数据汇总
  8852. tmpAllTryOutNumMap[index] += tmpTryOutNum
  8853. tmpAllFormalNumMap[index] += tmpFormalNum
  8854. tmpAllActiveNumMap[index] += tmpActiveStatus
  8855. tmpAllAllActiveNumMap[index] += tmpAllActiveStatus
  8856. tmpAllNoIncrementalActiveNumMap[index] += tmpNoIncrementalActiveStatus
  8857. // 总数据试用标签数据汇总
  8858. tmpAllTryStagePushMap[index] += tmpTryStagePushNum
  8859. tmpAllTryStageFollowMap[index] += tmpTryStageFollowNum
  8860. tmpAllTryStageReadyMap[index] += tmpTryStageReadyNum
  8861. tmpAllTryStageInitMap[index] += tmpTryStageInitNum
  8862. }
  8863. tmpAdminReportRecord := statistic_report.CityRecord{
  8864. Name: city,
  8865. CompanyAreaNumNumList: tmpCompanyReportRecordNumList,
  8866. }
  8867. tmpGroupCityReportRecord = append(tmpGroupCityReportRecord, tmpAdminReportRecord)
  8868. }
  8869. for i := 0; i < len(tmpGroupActiveNumMap); i++ {
  8870. tmpGroupCompanyReportRecordNum := statistic_report.CompanyAreaNum{
  8871. TryOutNum: tmpGroupTryOutNumMap[i],
  8872. FormalNum: tmpGroupFormalNumMap[i],
  8873. FormalIds: tmpGroupFormalCompanyIdsMap[i],
  8874. ActiveNum: tmpGroupActiveNumMap[i],
  8875. AllActiveNum: tmpGroupAllActiveNumMap[i],
  8876. NoIncrementalActiveNum: tmpGroupNoIncrementalActiveNumMap[i],
  8877. StartDate: startDateIndexList[i],
  8878. EndDate: endDateIndexList[i],
  8879. TryStagePushNum: tmpGroupTryStagePushMap[i],
  8880. TryStageFollowNum: tmpGroupTryStageFollowMap[i],
  8881. TryStageReadyNum: tmpGroupTryStageReadyMap[i],
  8882. TryStageInitNum: tmpGroupTryStageInitMap[i],
  8883. TotalNum: tmpGroupTryOutNumMap[i] + tmpGroupFormalNumMap[i],
  8884. TryOutIds: tmpGroupTryOutCompanyIdsMap[i],
  8885. TryStagePushIds: tmpGroupPushCompanyIdsMap[i],
  8886. TryStageFollowIds: tmpGroupFollowCompanyIdsMap[i],
  8887. TryStageReadyIds: tmpGroupReadyCompanyIdsMap[i],
  8888. TryStageInitIds: tmpGroupInitCompanyIdsMap[i],
  8889. }
  8890. tmpGroupCompanyReportRecordNumList = append(tmpGroupCompanyReportRecordNumList, tmpGroupCompanyReportRecordNum)
  8891. }
  8892. groupReportRecord := statistic_report.GroupCityRecord{
  8893. Item: tmpGroupCityReportRecord,
  8894. Name: province,
  8895. CompanyAreaNumNumList: tmpGroupCompanyReportRecordNumList,
  8896. }
  8897. groupReportRecordList = append(groupReportRecordList, groupReportRecord)
  8898. }
  8899. resp.List = groupReportRecordList
  8900. br.Ret = 200
  8901. br.Success = true
  8902. br.Msg = "获取成功"
  8903. br.Data = resp
  8904. }
  8905. // CompanyTryOutDayList
  8906. // @Title 客户累计试用详情接口
  8907. // @Description 客户累计试用详情接口
  8908. // @Param CompanyId query int true "客户id"
  8909. // @Param ProductId query int true "产品id"
  8910. // @Success 200 {object} company.CompanyTryOutDayListResp
  8911. // @router /company/tryOutDayList [get]
  8912. func (this *CompanyTodoController) CompanyTryOutDayList() {
  8913. br := new(models.BaseResponse).Init()
  8914. defer func() {
  8915. this.Data["json"] = br
  8916. this.ServeJSON()
  8917. }()
  8918. companyId, _ := this.GetInt("CompanyId")
  8919. if companyId <= 0 {
  8920. br.Msg = "请选择客户"
  8921. return
  8922. }
  8923. productId, _ := this.GetInt("ProductId")
  8924. if productId <= 0 {
  8925. br.Msg = "请选择类型"
  8926. return
  8927. }
  8928. pageSize, _ := this.GetInt("PageSize")
  8929. currentIndex, _ := this.GetInt("CurrentIndex")
  8930. var startSize int
  8931. if pageSize <= 0 {
  8932. pageSize = utils.PageSize20
  8933. }
  8934. if currentIndex <= 0 {
  8935. currentIndex = 1
  8936. }
  8937. startSize = paging.StartIndex(currentIndex, pageSize)
  8938. // 获取任务信息
  8939. total, err := company.GetCompanyProductTryOutUpdateLogTotal(companyId, productId)
  8940. if err != nil {
  8941. br.Msg = "获取任务信息失败"
  8942. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  8943. return
  8944. }
  8945. // 获取任务信息
  8946. list, err := company.GetCompanyProductTryOutUpdateLogList(companyId, productId, startSize, pageSize)
  8947. if err != nil {
  8948. br.Msg = "获取任务信息失败"
  8949. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  8950. return
  8951. }
  8952. //var list []*company_todo.CompanyTodoListItem
  8953. //for _, v := range todos {
  8954. // temp := &company_todo.CompanyTodoListItem{
  8955. // CompanyTodo: v,
  8956. // }
  8957. // temp.EndTimeStr = temp.EndTime.Format(utils.FormatDate)
  8958. // if temp.EndTimeStr == "0001-01-01" {
  8959. // temp.EndTimeStr = ""
  8960. // }
  8961. // list = append(list, temp)
  8962. //}
  8963. if len(list) <= 0 {
  8964. list = make([]*company.CompanyProductTryOutUpdateLog, 0)
  8965. }
  8966. page := paging.GetPaging(currentIndex, pageSize, total)
  8967. resp := company.CompanyTryOutDayListResp{
  8968. Paging: page,
  8969. List: list,
  8970. }
  8971. br.Ret = 200
  8972. br.Success = true
  8973. br.Msg = "获取成功"
  8974. br.Data = resp
  8975. }
  8976. // @Title 获取流水信息接口
  8977. // @Description 获取流水信息接口
  8978. // @Param CompanyId query int true "客户id"
  8979. // @Success 200 {object} company.CygxActivityPointsBillListResp
  8980. // @router /company/activity/points/bill [get]
  8981. func (this *CompanyTodoController) CompanyActivityPointsBill() {
  8982. br := new(models.BaseResponse).Init()
  8983. defer func() {
  8984. this.Data["json"] = br
  8985. this.ServeJSON()
  8986. }()
  8987. companyId, _ := this.GetInt("CompanyId")
  8988. if companyId <= 0 {
  8989. br.Msg = "请选择客户"
  8990. return
  8991. }
  8992. // 获取流水信息
  8993. list, err := cygx.CygxActivityPointsBillByCompanyId(companyId)
  8994. if err != nil {
  8995. br.Msg = "获取任务信息失败"
  8996. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  8997. return
  8998. }
  8999. if len(list) <= 0 {
  9000. list = make([]*cygx.CygxActivityPointsBillResp, 0)
  9001. }
  9002. resp := cygx.CygxActivityPointsBillListResp{
  9003. List: list,
  9004. }
  9005. br.Ret = 200
  9006. br.Success = true
  9007. br.Msg = "获取成功"
  9008. br.Data = resp
  9009. }
  9010. // DelRemark
  9011. // @Title 删除备注
  9012. // @Description 删除备注
  9013. // @Param request body company.RemarkDelReq true "type json string"
  9014. // @Success 200 操作成功
  9015. // @router /remark/del [post]
  9016. func (this *CompanyController) DelRemark() {
  9017. br := new(models.BaseResponse).Init()
  9018. defer func() {
  9019. if br.ErrMsg == "" {
  9020. br.IsSendEmail = false
  9021. }
  9022. this.Data["json"] = br
  9023. this.ServeJSON()
  9024. }()
  9025. sysUser := this.SysUser
  9026. if sysUser == nil {
  9027. br.Msg = "请登录"
  9028. br.ErrMsg = "请登录,SysUser Is Empty"
  9029. br.Ret = 408
  9030. return
  9031. }
  9032. var req company.RemarkDelReq
  9033. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  9034. if err != nil {
  9035. br.Msg = "参数解析异常!"
  9036. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  9037. return
  9038. }
  9039. if req.RemarkId <= 0 {
  9040. br.Msg = "参数有误"
  9041. br.ErrMsg = "参数有误, 备注ID有误"
  9042. return
  9043. }
  9044. item, e := company.GetCompanyRemarkById(req.RemarkId)
  9045. if e != nil {
  9046. if e.Error() == utils.ErrNoRow() {
  9047. br.Msg = "备注已被删除, 请刷新页面"
  9048. return
  9049. }
  9050. br.Msg = "备注信息有误"
  9051. br.ErrMsg = "获取客户备注失败, Err: " + e.Error()
  9052. return
  9053. }
  9054. if item.SysUserId != sysUser.AdminId {
  9055. br.Msg = "仅备注添加人可删除"
  9056. return
  9057. }
  9058. product, e := company.GetCompanyProductByCompanyIdAndProductId(item.CompanyId, item.ProductId)
  9059. if e != nil {
  9060. br.Msg = "操作失败"
  9061. br.ErrMsg = "获取客户产品信息失败, Err: " + e.Error()
  9062. return
  9063. }
  9064. if e := company.DelCompanyRemark(req.RemarkId); e != nil {
  9065. br.Msg = "操作失败"
  9066. br.ErrMsg = "删除客户备注失败, Err: " + e.Error()
  9067. return
  9068. }
  9069. content := fmt.Sprintf("%s%s", "删除备注: ", item.Remark)
  9070. _ = 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)
  9071. if item.ProductId == utils.COMPANY_PRODUCT_RAI_ID {
  9072. go services.DelCompanyHistoryRemark("company_product_remark", req.RemarkId) // 删除
  9073. }
  9074. br.Ret = 200
  9075. br.Success = true
  9076. br.Msg = "操作成功"
  9077. }
  9078. // @Title 获取流水信息接口
  9079. // @Description 获取流水信息接口
  9080. // @Param CompanyId query int true "客户id"
  9081. // @Success 200 {object} company.CygxActivityPointsBillListResp
  9082. // @router /company/activity/special/points/bill [get]
  9083. func (this *CompanyTodoController) CompanyActivitySpecialPointsBill() {
  9084. br := new(models.BaseResponse).Init()
  9085. defer func() {
  9086. this.Data["json"] = br
  9087. this.ServeJSON()
  9088. }()
  9089. companyId, _ := this.GetInt("CompanyId")
  9090. if companyId <= 0 {
  9091. br.Msg = "请选择客户"
  9092. return
  9093. }
  9094. // 获取流水信息
  9095. var condition string
  9096. var pars []interface{}
  9097. condition += ` AND company_id = ? `
  9098. pars = append(pars, companyId)
  9099. //查询当年的数据
  9100. //condition += ` AND b.create_time >= ? `
  9101. //pars = append(pars, time.Now().Format(utils.FormatYearDate)+"-01-01")
  9102. list, err := cygx.GetCygxActivitySpecialTripBillDetailListAll(condition, pars)
  9103. if err != nil {
  9104. br.Msg = "获取任务信息失败"
  9105. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  9106. return
  9107. }
  9108. //userType, tripRemaining, mapChartName, err := cygxService.GetChartPermissionSpecialSurplusByCompany(companyId)
  9109. //if err != nil {
  9110. // br.Msg = "获取专项调研剩余次数失败"
  9111. // br.ErrMsg = "获取专项调研剩余次数失败,err:" + err.Error()
  9112. // return
  9113. //}
  9114. //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}
  9115. resp := new(cygx.CygxActivitySpecialPointsBillResp)
  9116. //lastTripRemaining := 0
  9117. for _, v := range list {
  9118. item := cygx.CygxActivitySpecialPointsBillRespItem{
  9119. Id: v.Id,
  9120. CreateTime: v.CreateTime.Format(utils.FormatDateTime),
  9121. CompanyId: v.CompanyId,
  9122. CompanyName: v.CompanyName,
  9123. RealName: v.RealName,
  9124. BillDetailed: v.BillDetailed,
  9125. ActivityName: v.ResearchTheme,
  9126. ChartPermissionId: v.ChartPermissionId,
  9127. ChartPermissionName: v.ChartPermissionName,
  9128. Total: v.Total,
  9129. }
  9130. if v.ActivityId == 0 {
  9131. item.Content = v.Content
  9132. } else {
  9133. if v.DoType == 1 && v.Way != 4 && v.Way != 3 {
  9134. item.Content = item.ActivityName + "--报名"
  9135. } else if v.DoType == 2 && v.Way != 4 && v.Way != 3 {
  9136. item.Content = item.ActivityName + "--取消报名"
  9137. } else if v.Way == 4 {
  9138. item.Content = item.ActivityName + "--活动取消"
  9139. }
  9140. }
  9141. //if userType == 2 {
  9142. // if i== 0 {
  9143. // item.Total += strconv.Itoa(tripRemaining) + "次"
  9144. // } else {
  9145. // item.Total += strconv.Itoa(tripRemaining-list[i-1].BillDetailed) + "次"
  9146. // }
  9147. // //if v.BillDetailed < 4 {
  9148. // // item.Total += strconv.Itoa(lastTripRemaining-list[i-1].BillDetailed) + "次"
  9149. // //} else {
  9150. // // item.Total += strconv.Itoa(lastTripRemaining) + "次"
  9151. // //}
  9152. //} else {
  9153. // for k, num := range mapChartName {
  9154. // if i== 0 {
  9155. // item.Total += k + strconv.Itoa(num) + "次+"
  9156. // } else {
  9157. // if list[i-1].ActivityId == 0 {
  9158. // item.Total += k + strconv.Itoa(num) + "次+"
  9159. // } else {
  9160. // item.Total += k + strconv.Itoa(num-list[i-1].BillDetailed) + "次+"
  9161. // }
  9162. // }
  9163. // //if num > 0 {
  9164. // // if i== 0{
  9165. // // item.Total += k + strconv.Itoa(num) + "次+"
  9166. // // } else {
  9167. // // item.Total += k + strconv.Itoa(num-v.BillDetailed) + "次+"
  9168. // // }
  9169. // //}
  9170. // }
  9171. // item.Total = strings.TrimRight(item.Total, "+")
  9172. //}
  9173. resp.List = append(resp.List, &item)
  9174. }
  9175. br.Ret = 200
  9176. br.Success = true
  9177. br.Msg = "获取成功"
  9178. br.Data = resp
  9179. }