company.go 308 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419
  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, item.ShareSellerId)
  352. //根据销售"领取客户"的权限对部分按钮做限制
  353. btnItem = services.GetCompanyPermissionButtonByReceiveEnabled(btnItem, receiveEnabled)
  354. }
  355. //如果是权益客户,操作者又是权益管理员,那么就对他进行展示研选详情按钮
  356. if strings.Contains(item.CompanyType, utils.COMPANY_CLASSIFY_RAI) && sysUser.RoleName == utils.ROLE_TYPE_RAI_PRODUCT {
  357. btnItem.IsResearchShow = true
  358. }
  359. list[i].BtnItem = btnItem
  360. // 签约未签约按钮回显展示
  361. btnCompanyStatusItem := new(company.CompanyStatusButton)
  362. btnCompanyStatusItem = services.GetLsitCompanyStatusButton(list[i].CompanyType, list[i].Status, list[i].SigningStatus)
  363. list[i].CompanyStatusButton = btnCompanyStatusItem
  364. }
  365. for _, v := range list {
  366. v.Status = strings.Replace(v.Status, utils.COMPANY_STATUS_FOREVER, utils.COMPANY_STATUS_X_CLASS_TRY_OUT, -1) // 永续客户类型,映射成 X类试用
  367. v.Duration = strings.Replace(v.Duration, utils.COMPANY_STATUS_FOREVER, utils.COMPANY_STATUS_X_CLASS_TRY_OUT, -1) // 永续客户类型,映射成 X类试用
  368. }
  369. if list == nil {
  370. list = make([]*company.CompanySearchItem, 0)
  371. }
  372. resp.List = list
  373. page := paging.GetPaging(currentIndex, pageSize, total)
  374. resp.Paging = page
  375. br.Ret = 200
  376. br.Success = true
  377. br.Msg = "获取成功"
  378. br.Data = resp
  379. }
  380. // List
  381. // @Title 客户列表
  382. // @Description 客户列表接口
  383. // @Param PageSize query int true "每页数据条数"
  384. // @Param CurrentIndex query int true "当前页页码,从1开始"
  385. // @Param Status query string true "状态:'试用','永续','冻结','流失','正式'"
  386. // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
  387. // @Param IndustryId query int true "行业id,0为全部"
  388. // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
  389. // @Param ChartPermissionIds query string false "阅读权限品种ID,多个用英文逗号分开,空字符串为全部"
  390. // @Param ContractPermissionIds query string false "已购品种ID,多个用英文逗号分开,空字符串为全部"
  391. // @Param StartDate query string true "开始时间"
  392. // @Param EndDate query string true "结束时间"
  393. // @Param CreateStartDate query string true "创建开始时间"
  394. // @Param CreateEndDate query string true "创建结束时间"
  395. // @Param KeyWord query string true "搜索关键词"
  396. // @Param Address query string true "地址 , 多个用英文逗号分开 "
  397. // @Param Province query string true "省 , 多个用英文逗号分开 "
  398. // @Param City query string true "市 , 多个用英文逗号分开 "
  399. // @Param PackageType query int true "套餐类型,0:无,1:大套餐,2:小套餐"
  400. // @Param TodoStatus query string true "任务处理状态;枚举值:'无任务','未完成','已完成'"
  401. // @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:'viewTotal':总阅读次数 、 'viewTime':阅读时间 、 'roadShowTotal':累计路演次数 、`expireDay:到期时间` 、 `createTime:创建时间` 、 'formalTime': 转正时间 、 'freezeTime':冻结时间 、'lossTime':流失时间 、'tryStage':试用标签 、'deadline':距离未完成的任务的截止日期的天数、'tryOutDay':试用天数"
  402. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  403. // @Param SortByTodo query bool true "是否根据待办排序,true或false"
  404. // @Param TryStage query int false "试用客户子标签:0全部、1未分类、2 推进、3 跟踪、4 预备"
  405. // @Param IncludeShare query bool true "是否包含共享客户: true-包含; false-不包含"
  406. // @Param IsSigning query int true "是否签约过: -1-默认全部; 0-否; 1-是"
  407. // @Success 200 {object} company.CompanyListResp
  408. // @router /list [get]
  409. func (this *CompanyController) List() {
  410. br := new(models.BaseResponse).Init()
  411. defer func() {
  412. this.Data["json"] = br
  413. this.ServeJSON()
  414. }()
  415. sysUser := this.SysUser
  416. if sysUser == nil {
  417. br.Msg = "请登录"
  418. br.ErrMsg = "请登录,SysUser Is Empty"
  419. br.Ret = 408
  420. return
  421. }
  422. roleTypeCode := sysUser.RoleTypeCode
  423. pageSize, _ := this.GetInt("PageSize")
  424. currentIndex, _ := this.GetInt("CurrentIndex")
  425. status := this.GetString("Status")
  426. companyType := this.GetString("CompanyType")
  427. industryId, _ := this.GetInt("IndustryId")
  428. adminId := this.GetString("AdminId")
  429. chartPermissionIds := this.GetString("ChartPermissionIds")
  430. contractPermissionIds := this.GetString("ContractPermissionIds")
  431. startDate := this.GetString("StartDate")
  432. endDate := this.GetString("EndDate")
  433. createStartDate := this.GetString("CreateStartDate")
  434. createEndDate := this.GetString("CreateEndDate")
  435. keyWord := this.GetString("KeyWord")
  436. address := this.GetString("Address")
  437. province := this.GetString("Province")
  438. city := this.GetString("City")
  439. keyWord = strings.Trim(keyWord, " ")
  440. keyWord = strings.Replace(keyWord, "'", "", -1)
  441. todoStatus := this.GetString("TodoStatus") //任务状态
  442. tryStage, _ := this.GetInt("TryStage") //试用客户标签
  443. includeShare, _ := this.GetBool("IncludeShare") // 是否包含试用客户
  444. isSigning, _ := this.GetInt("IsSigning", -1)
  445. // 套餐类型
  446. packageType, _ := this.GetInt("PackageType")
  447. //排序参数
  448. sortParam := this.GetString("SortParam")
  449. sortType := this.GetString("SortType")
  450. sortByTodo, _ := this.GetBool("SortByTodo")
  451. productId := services.GetProductId(roleTypeCode)
  452. var total int
  453. page := paging.GetPaging(currentIndex, pageSize, total)
  454. resp := new(company.CompanyListResp)
  455. statusItems := make([]*company.CompanyStatus, 0)
  456. // 永续客户类型,映射成 X类试用
  457. if status == utils.COMPANY_STATUS_X_CLASS_TRY_OUT {
  458. status = utils.COMPANY_STATUS_FOREVER
  459. }
  460. var statusArr []string
  461. // 对权益用户隐藏关闭
  462. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  463. statusArr = []string{"全部", "试用", "正式", "冻结", "流失", utils.COMPANY_STATUS_X_CLASS_TRY_OUT}
  464. } else {
  465. statusArr = []string{"全部", "试用", "正式", "冻结", "流失", utils.COMPANY_STATUS_CLOSE, utils.COMPANY_STATUS_X_CLASS_TRY_OUT}
  466. }
  467. //var statusArr = [...]string{"全部", "试用-活跃", "试用-非活跃", "正式", "冻结", "流失", "永续"}
  468. var startSize int
  469. if pageSize <= 0 {
  470. pageSize = utils.PageSize20
  471. }
  472. if currentIndex <= 0 {
  473. currentIndex = 1
  474. }
  475. startSize = paging.StartIndex(currentIndex, pageSize)
  476. var condition string
  477. var pars []interface{}
  478. //流失
  479. var lossCondition string
  480. var lossPars []interface{}
  481. //状态分类查询条件
  482. var permissionCondition string
  483. var permissionPars []interface{}
  484. if companyType != "" {
  485. condition += ` AND b.product_name=? `
  486. pars = append(pars, companyType)
  487. }
  488. if industryId > 0 {
  489. condition += ` AND b.industry_id=? `
  490. pars = append(pars, industryId)
  491. }
  492. if adminId != "" {
  493. condition += ` AND b.seller_id IN (` + adminId + `) `
  494. }
  495. if startDate != "" {
  496. condition += ` AND b.start_date>=? `
  497. pars = append(pars, startDate)
  498. }
  499. if endDate != "" {
  500. condition += ` AND b.end_date<=? `
  501. pars = append(pars, endDate)
  502. }
  503. if createStartDate != "" {
  504. condition += ` AND a.created_time>=? `
  505. pars = append(pars, createStartDate)
  506. }
  507. if createEndDate != "" {
  508. condition += ` AND a.created_time<=? `
  509. pars = append(pars, createEndDate)
  510. }
  511. if address != "" {
  512. var addressSql string
  513. slice := strings.Split(address, ",")
  514. for _, v := range slice {
  515. addressSql += "'" + v + "'" + ","
  516. }
  517. addressSql = strings.TrimRight(addressSql, ",")
  518. condition += ` AND a.address IN (` + addressSql + `) `
  519. }
  520. if province != "" {
  521. var provinceSql string
  522. slice := strings.Split(province, ",")
  523. for _, v := range slice {
  524. provinceSql += "'" + v + "'" + ","
  525. }
  526. provinceSql = strings.TrimRight(provinceSql, ",")
  527. condition += ` AND a.province IN (` + provinceSql + `) `
  528. }
  529. if city != "" {
  530. var citySql string
  531. slice := strings.Split(city, ",")
  532. for _, v := range slice {
  533. citySql += "'" + v + "'" + ","
  534. }
  535. citySql = strings.TrimRight(citySql, ",")
  536. condition += ` AND a.city IN (` + citySql + `) `
  537. }
  538. //是否签约过
  539. if isSigning == 0 || isSigning == 1 {
  540. condition += ` AND b.is_signing = ? `
  541. pars = append(pars, isSigning)
  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='流失') `
  634. pars = append(pars, sysUser.AdminId)
  635. permissionCondition += ` AND b.seller_id=? `
  636. permissionPars = append(permissionPars, 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 (a.share_seller_id = ? AND a.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=? `
  745. permissionPars = append(permissionPars, 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)) + `)`
  1095. serRecPars := make([]interface{}, 0)
  1096. serRecPars = append(serRecPars, companyIds)
  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.GroupIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, item.ShareSellerId)
  1238. //根据销售"领取客户"的权限对部分按钮做限制
  1239. btnItem = services.GetCompanyPermissionButtonByReceiveEnabled(btnItem, receiveEnabled)
  1240. }
  1241. if list[i].IsShare == 1 && btnItem.BtnModifySeller == true {
  1242. //如果已经是共享客户了,取消共享按钮全都显示,和修改销售权限一样
  1243. btnItem.BtnShare = true
  1244. }
  1245. list[i].BtnItem = btnItem
  1246. if item.FreezeStartDate != "" && item.FreezeEndDate != "" && item.Status == utils.COMPANY_STATUS_FREEZE {
  1247. freezeEndDate, _ := time.Parse(utils.FormatDate, item.FreezeEndDate)
  1248. if time.Now().Before(freezeEndDate) {
  1249. expireDays := freezeEndDate.Sub(time.Now()).Hours() / 24
  1250. list[i].FreezeExpireDays = int(expireDays) + 1
  1251. }
  1252. }
  1253. btnItem.BtnServiceRecord = btnServiceRecordMap[list[i].CompanyId]
  1254. // 签约未签约按钮回显展示
  1255. btnCompanyStatusItem := new(company.CompanyStatusButton)
  1256. btnCompanyStatusItem = services.GetLsitCompanyStatusButton(list[i].CompanyType, list[i].Status, list[i].SigningStatus)
  1257. list[i].CompanyStatusButton = btnCompanyStatusItem
  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. tmpStatus := v.Status
  1499. if v.IsShare == 1 {
  1500. tmpStatus = v.Status + "(共享)"
  1501. }
  1502. //productIdSlice := strings.Split(v.ProductIds, "/")
  1503. //statusSlice := strings.Split(v.Status, "/")
  1504. //for productIndex, tmpProductId := range productIdSlice {
  1505. // tmpStatusIndex := 0
  1506. // if len(statusSlice) > 1 {
  1507. // tmpStatusIndex = productIndex
  1508. // }
  1509. // tmpProductStatus := statusSlice[tmpStatusIndex]
  1510. // if strings.Contains(tmpProductStatus, "试用") {
  1511. // activeType := "非活跃"
  1512. // viewNum := v.FiccView
  1513. // if tmpProductId == "2" {
  1514. // viewNum = v.RaiView
  1515. // }
  1516. // if viewNum >= statistic_report.ActiveViewNum {
  1517. // activeType = "活跃"
  1518. // }
  1519. // statusSlice[tmpStatusIndex] = fmt.Sprint(tmpProductStatus, "(", activeType, ")")
  1520. //
  1521. // tmpStatus = strings.Join(statusSlice, "/")
  1522. // }
  1523. //}
  1524. //ficcViewTotal, ok := companyFiccViewTotal[v.CompanyId]
  1525. //if !ok {
  1526. // ficcViewTotal = 0
  1527. //}
  1528. //raiViewTotal, ok := companyRaiViewTotal[v.CompanyId]
  1529. //if !ok {
  1530. // raiViewTotal = 0
  1531. //}
  1532. // 是否存在进行中的任务
  1533. var todoStatus bool
  1534. if _, ok := companyTodoMap[fmt.Sprint(v.CompanyId)]; ok {
  1535. todoStatus = true
  1536. }
  1537. //是否支持确认完成待办任务
  1538. var canConfirm bool
  1539. var hiddenConfirm bool //是否隐藏确定完成按钮
  1540. var hiddenCreate bool //是否隐藏新增/编辑按钮
  1541. hiddenConfirm = true
  1542. hiddenCreate = true
  1543. for _, vProductId := range []int{1, 2} {
  1544. ficcKey := fmt.Sprint(v.CompanyId, "_", vProductId)
  1545. //ficc
  1546. if tmpCompanyProduct, ok := companyProductMap[ficcKey]; ok {
  1547. if tmpCompanyProduct.Status != utils.COMPANY_STATUS_LOSE && tmpCompanyProduct.Status != utils.COMPANY_STATUS_CLOSE { //非流失或关闭
  1548. hiddenCreate = false
  1549. switch this.SysUser.RoleTypeCode {
  1550. 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:
  1551. //部门管理员、ficc主管、权益组长
  1552. hiddenConfirm = false //不展示
  1553. if todoStatus { //有任务,需要展示
  1554. canConfirm = true
  1555. }
  1556. case utils.ROLE_TYPE_CODE_FICC_TEAM: //ficc组长
  1557. if todoStatus { //有任务,需要展示
  1558. canConfirm = true
  1559. }
  1560. if v.SellerId != this.SysUser.AdminId { //不是自己的客户
  1561. hiddenConfirm = false //展示
  1562. }
  1563. case utils.ROLE_TYPE_CODE_RAI_SELLER: //权益销售
  1564. if v.SellerId == this.SysUser.AdminId { //是自己的客户
  1565. has := services.CheckRaiApprovePermission(sysUser.AdminId) //这些个权益销售是有权限的
  1566. if has {
  1567. if todoStatus { //有任务,需要展示
  1568. canConfirm = true
  1569. }
  1570. hiddenConfirm = false //展示
  1571. }
  1572. }
  1573. }
  1574. }
  1575. }
  1576. }
  1577. todoButtonColor := `green`
  1578. //'无任务','未完成','已完成'
  1579. if strings.Contains(v.TodoStatuss, "未完成") {
  1580. todoButtonColor = "red"
  1581. } else if strings.Contains(v.TodoStatuss, "已完成") {
  1582. todoButtonColor = "green"
  1583. } else if strings.Contains(v.TodoStatuss, "无任务") {
  1584. todoButtonColor = "gray"
  1585. }
  1586. //if str
  1587. companyList := &company.CompanyListItem{
  1588. CompanyId: v.CompanyId,
  1589. CompanyName: v.CompanyName,
  1590. CreditCode: v.CreditCode,
  1591. CompanyCode: v.CompanyCode,
  1592. StartDate: v.StartDate,
  1593. EndDate: v.EndDate,
  1594. LoseReason: v.LoseReason,
  1595. RenewalReason: v.RenewalReason,
  1596. FreezeReason: v.FreezeReason,
  1597. LossTime: v.LossTime,
  1598. Status: tmpStatus,
  1599. CompanyType: v.CompanyType,
  1600. ApproveStatus: v.ApproveStatus,
  1601. SellerName: v.SellerName,
  1602. SellerId: v.SellerId,
  1603. SellerIds: v.SellerIds,
  1604. ExpireDay: v.ExpireDay,
  1605. FreezeTime: v.FreezeTime,
  1606. GroupId: v.GroupId,
  1607. GroupIds: v.GroupIds,
  1608. DepartmentId: v.DepartmentId,
  1609. IndustryName: v.IndustryName,
  1610. IsSuspend: v.IsSuspend,
  1611. CreatedTime: v.CreatedTime,
  1612. Source: v.Source,
  1613. Province: v.Province,
  1614. City: v.City,
  1615. Address: v.Address,
  1616. Reasons: v.Reasons,
  1617. FreezeStartDate: v.FreezeStartDate,
  1618. FreezeEndDate: v.FreezeEndDate,
  1619. FreezeExpireDays: v.FreezeExpireDays,
  1620. BtnItem: v.BtnItem,
  1621. ProductId: v.ProductId,
  1622. FormalTime: v.FormalTime,
  1623. IsShared: v.IsShared,
  1624. RegionType: v.RegionType,
  1625. FiccPackageType: v.FiccPackageType,
  1626. FiccLastViewTime: v.FiccLastViewTime,
  1627. RaiLastViewTime: v.RaiLastViewTime,
  1628. //FiccView: viewTotal[0],
  1629. //RaiView: viewTotal[1],
  1630. //FiccView: ficcViewTotal,
  1631. //RaiView: raiViewTotal,
  1632. FiccView: v.FiccView,
  1633. RaiView: v.RaiView,
  1634. FiccTryOutDay: v.FiccTryOutDay,
  1635. RaiTryOutDay: v.RaiTryOutDay,
  1636. AllViewTotal: v.AllViewTotal,
  1637. RoadShowTotal: v.RoadShowTotal,
  1638. TodoStatus: todoStatus,
  1639. CanConfirm: canConfirm,
  1640. HiddenConfirm: hiddenConfirm,
  1641. HiddenCreate: hiddenCreate,
  1642. TodoButtonColor: todoButtonColor,
  1643. TryStageSlice: v.TryStageSlice,
  1644. Deadline: v.Deadline,
  1645. WeekViewActive: v.WeekViewActive,
  1646. IsShare: v.IsShare,
  1647. CloseTime: v.CloseTime,
  1648. CloseReason: v.CloseReason,
  1649. IsSigning: v.IsSigning,
  1650. CompanyStatusButton: v.CompanyStatusButton,
  1651. ShareSeller: v.ShareSeller,
  1652. ShareSellerId: v.ShareSellerId,
  1653. }
  1654. if v.ShareSellerId != 0 {
  1655. shareSeller := adminMap[v.ShareSellerId]
  1656. if shareSeller != nil {
  1657. companyList.ShareSeller = shareSeller.RealName + "(" + shareSeller.GroupName + ")"
  1658. }
  1659. }
  1660. companyLists = append(companyLists, companyList)
  1661. }
  1662. }
  1663. if companyLists == nil {
  1664. companyLists = make([]*company.CompanyListItem, 0)
  1665. }
  1666. // 白嫖客户标记
  1667. scroungeList, err := company.GetScroungeCompany()
  1668. if err != nil {
  1669. br.Msg = "获取失败"
  1670. br.ErrMsg = "获取白嫖客户信息失败,Err:" + err.Error()
  1671. return
  1672. }
  1673. scroungeMap := make(map[int]int)
  1674. for _, v := range scroungeList {
  1675. scroungeMap[v.CompanyId] = 1
  1676. }
  1677. for i, v := range companyLists {
  1678. if _, ok := scroungeMap[v.CompanyId]; ok {
  1679. companyLists[i].IsScrounge = 1
  1680. }
  1681. }
  1682. page = paging.GetPaging(currentIndex, pageSize, total)
  1683. resp.List = companyLists
  1684. resp.StatusCount = statusItems
  1685. resp.TryStageCount = tryStageCountResp
  1686. resp.Paging = page
  1687. resp.AddCompanyBtn = receiveEnabled
  1688. br.Ret = 200
  1689. br.Success = true
  1690. br.Msg = "获取成功"
  1691. br.Data = resp
  1692. }
  1693. //func (this *CompanyController) ListOld() {
  1694. // br := new(models.BaseResponse).Init()
  1695. // defer func() {
  1696. // this.Data["json"] = br
  1697. // this.ServeJSON()
  1698. // }()
  1699. // sysUser := this.SysUser
  1700. // if sysUser == nil {
  1701. // br.Msg = "请登录"
  1702. // br.ErrMsg = "请登录,SysUser Is Empty"
  1703. // br.Ret = 408
  1704. // return
  1705. // }
  1706. // roleTypeCode := sysUser.RoleTypeCode
  1707. //
  1708. // pageSize, _ := this.GetInt("PageSize")
  1709. // currentIndex, _ := this.GetInt("CurrentIndex")
  1710. // status := this.GetString("Status")
  1711. // companyType := this.GetString("CompanyType")
  1712. // industryId, _ := this.GetInt("IndustryId")
  1713. // adminId := this.GetString("AdminId")
  1714. //
  1715. // chartPermissionIds := this.GetString("ChartPermissionIds")
  1716. // startDate := this.GetString("StartDate")
  1717. // endDate := this.GetString("EndDate")
  1718. // createStartDate := this.GetString("CreateStartDate")
  1719. // createEndDate := this.GetString("CreateEndDate")
  1720. // keyWord := this.GetString("KeyWord")
  1721. // keyWord = strings.Trim(keyWord, " ")
  1722. // keyWord = strings.Replace(keyWord, "'", "", -1)
  1723. //
  1724. // //排序参数
  1725. // sortParam := this.GetString("SortParam")
  1726. // sortType := this.GetString("SortType")
  1727. //
  1728. // var total int
  1729. // page := paging.GetPaging(currentIndex, pageSize, total)
  1730. // resp := new(company.CompanyListResp)
  1731. // statusItems := make([]*company.CompanyStatus, 0)
  1732. // var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}
  1733. //
  1734. // var startSize int
  1735. // if pageSize <= 0 {
  1736. // pageSize = utils.PageSize20
  1737. // }
  1738. // if currentIndex <= 0 {
  1739. // currentIndex = 1
  1740. // }
  1741. // startSize = paging.StartIndex(currentIndex, pageSize)
  1742. // var condition string
  1743. // var pars []interface{}
  1744. //
  1745. // //流失
  1746. // var lossCondition string
  1747. // var lossPars []interface{}
  1748. // //冻结
  1749. // var freezeCondition string
  1750. // var freezePars []interface{}
  1751. //
  1752. // //永续
  1753. // var forverCondition string
  1754. // var forverPars []interface{}
  1755. //
  1756. // var permissionCondition string
  1757. // var permissionPars []interface{}
  1758. //
  1759. // if status != "" && status != "全部" {
  1760. // condition += ` AND b.status=? `
  1761. // pars = append(pars, status)
  1762. //
  1763. // //permissionCondition += ` AND b.status=? `
  1764. // //permissionPars = append(permissionPars, status)
  1765. // }
  1766. // if companyType != "" {
  1767. // condition += ` AND b.product_name=? `
  1768. // pars = append(pars, companyType)
  1769. //
  1770. // lossCondition += ` AND b.product_name=? `
  1771. // lossPars = append(lossPars, companyType)
  1772. //
  1773. // freezeCondition += ` AND b.product_name=? `
  1774. // freezePars = append(freezePars, companyType)
  1775. //
  1776. // forverCondition += ` AND b.product_name=? `
  1777. // forverPars = append(forverPars, companyType)
  1778. //
  1779. // permissionCondition += ` AND b.product_name=? `
  1780. // permissionPars = append(permissionPars, companyType)
  1781. // }
  1782. //
  1783. // if industryId > 0 {
  1784. // condition += ` AND b.industry_id=? `
  1785. // pars = append(pars, industryId)
  1786. //
  1787. // lossCondition += ` AND b.industry_id=? `
  1788. // lossPars = append(lossPars, industryId)
  1789. //
  1790. // freezeCondition += ` AND b.industry_id=? `
  1791. // freezePars = append(freezePars, industryId)
  1792. //
  1793. // forverCondition += ` AND b.industry_id=? `
  1794. // forverPars = append(forverPars, industryId)
  1795. //
  1796. // permissionCondition += ` AND b.industry_id=? `
  1797. // permissionPars = append(permissionPars, industryId)
  1798. // }
  1799. //
  1800. // if adminId != "" {
  1801. // condition += ` AND b.seller_id IN (` + adminId + `) `
  1802. //
  1803. // lossCondition += ` AND b.seller_id IN (` + adminId + `) `
  1804. //
  1805. // freezeCondition += ` AND b.seller_id IN (` + adminId + `) `
  1806. //
  1807. // forverCondition += ` AND b.seller_id IN (` + adminId + `) `
  1808. //
  1809. // permissionCondition += ` AND b.seller_id IN (` + adminId + `) `
  1810. // }
  1811. //
  1812. // if startDate != "" {
  1813. // condition += ` AND b.start_date>=? `
  1814. // pars = append(pars, startDate)
  1815. //
  1816. // lossCondition += ` AND b.start_date>=? `
  1817. // lossPars = append(lossPars, startDate)
  1818. //
  1819. // freezeCondition += ` AND b.start_date>=? `
  1820. // freezePars = append(freezePars, startDate)
  1821. //
  1822. // forverCondition += ` AND b.start_date>=? `
  1823. // forverPars = append(forverPars, startDate)
  1824. //
  1825. // permissionCondition += ` AND b.start_date>=? `
  1826. // permissionPars = append(permissionPars, startDate)
  1827. // }
  1828. //
  1829. // if endDate != "" {
  1830. // condition += ` AND b.end_date<=? `
  1831. // pars = append(pars, endDate)
  1832. //
  1833. // lossCondition += ` AND b.end_date<=? `
  1834. // lossPars = append(lossPars, endDate)
  1835. //
  1836. // freezeCondition += ` AND b.end_date<=? `
  1837. // freezePars = append(freezePars, endDate)
  1838. //
  1839. // forverCondition += ` AND b.end_date<=? `
  1840. // forverPars = append(forverPars, endDate)
  1841. //
  1842. // permissionCondition += ` AND b.end_date<=? `
  1843. // permissionPars = append(permissionPars, endDate)
  1844. // }
  1845. //
  1846. // if createStartDate != "" {
  1847. // condition += ` AND a.created_time>=? `
  1848. // pars = append(pars, createStartDate)
  1849. //
  1850. // lossCondition += ` AND a.created_time>=? `
  1851. // lossPars = append(lossPars, createStartDate)
  1852. //
  1853. // freezeCondition += ` AND a.created_time>=? `
  1854. // freezePars = append(freezePars, createStartDate)
  1855. //
  1856. // forverCondition += ` AND a.created_time>=? `
  1857. // forverPars = append(forverPars, createStartDate)
  1858. //
  1859. // permissionCondition += ` AND a.created_time>=? `
  1860. // permissionPars = append(permissionPars, createStartDate)
  1861. // }
  1862. //
  1863. // if createEndDate != "" {
  1864. // condition += ` AND a.created_time<=? `
  1865. // pars = append(pars, createEndDate)
  1866. //
  1867. // lossCondition += ` AND a.created_time<=? `
  1868. // lossPars = append(lossPars, createEndDate)
  1869. //
  1870. // freezeCondition += ` AND a.created_time<=? `
  1871. // freezePars = append(freezePars, createEndDate)
  1872. //
  1873. // forverCondition += ` AND a.created_time<=? `
  1874. // forverPars = append(forverPars, createEndDate)
  1875. //
  1876. // permissionCondition += ` AND a.created_time<=? `
  1877. // permissionPars = append(permissionPars, createEndDate)
  1878. // }
  1879. //
  1880. // if keyWord != "" {
  1881. // companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
  1882. // if err != nil {
  1883. // br.Msg = "获取客户信息失败"
  1884. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1885. // return
  1886. // }
  1887. // if companyIdStr != "" {
  1888. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  1889. // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  1890. // freezeCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  1891. // forverCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  1892. //
  1893. // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  1894. // } else {
  1895. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  1896. // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  1897. // freezeCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  1898. // forverCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  1899. //
  1900. // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  1901. // }
  1902. // }
  1903. // if chartPermissionIds != "" && chartPermissionIds != "1" {
  1904. // //chartPermissionArr := strings.Split(chartPermissionIds, ",")
  1905. // //chartPermissionCount := len(chartPermissionArr)
  1906. // companyIdStr, err := company.GetCompanyListCompanyIdByPermissionIdStr(chartPermissionIds)
  1907. // if err != nil {
  1908. // br.Msg = "获取失败"
  1909. // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
  1910. // return
  1911. // }
  1912. // //var companyIdArr []string
  1913. // //for _, v := range companyIdList {
  1914. // // companyIdArr = append(companyIdArr, strconv.Itoa(v.CompanyId))
  1915. // //}
  1916. // //companyIdStr := strings.Join(companyIdArr, ",")
  1917. // if companyIdStr != "" {
  1918. // condition += ` AND a.company_id IN (` + companyIdStr + `) `
  1919. // lossCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  1920. // freezeCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  1921. // forverCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  1922. // permissionCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  1923. // } else {
  1924. // for _, v := range statusArr {
  1925. // statusCount := new(company.CompanyStatus)
  1926. // if v == "全部" {
  1927. // statusCount.Status = "全部"
  1928. // statusCount.Count = 0
  1929. // } else {
  1930. // statusCount.Status = v
  1931. // statusCount.Count = 0
  1932. // }
  1933. // statusItems = append(statusItems, statusCount)
  1934. // }
  1935. // items := make([]*company.CompanyListItem, 0)
  1936. // resp.List = items
  1937. // resp.Paging = page
  1938. // resp.StatusCount = statusItems
  1939. // br.Msg = "获取成功"
  1940. // br.Ret = 200
  1941. // br.Data = resp
  1942. // return
  1943. // }
  1944. // }
  1945. // //权限控制
  1946. // {
  1947. // fmt.Println(roleTypeCode)
  1948. // if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  1949. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  1950. // condition += ` AND b.product_id=? `
  1951. // pars = append(pars, 1)
  1952. //
  1953. // permissionCondition += ` AND b.product_id=? `
  1954. // permissionPars = append(permissionPars, 1)
  1955. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  1956. // condition += ` AND b.product_id=? `
  1957. // pars = append(pars, 2)
  1958. //
  1959. // permissionCondition += ` AND b.product_id=? `
  1960. // permissionPars = append(permissionPars, 2)
  1961. // } else {
  1962. // if sysUser.Authority <= 0 {
  1963. // if status == utils.COMPANY_STATUS_TRY_OUT || status == utils.COMPANY_STATUS_FORMAL || status == "全部" {
  1964. // if status == "全部" {
  1965. // condition += ` AND (b.seller_id=? OR status='流失' OR status='永续') `
  1966. // pars = append(pars, sysUser.AdminId)
  1967. // } else {
  1968. // condition += ` AND b.seller_id=? `
  1969. // pars = append(pars, sysUser.AdminId)
  1970. // }
  1971. // }
  1972. // permissionCondition += ` AND b.seller_id=? `
  1973. // permissionPars = append(permissionPars, sysUser.AdminId)
  1974. // } else {
  1975. // if sysUser.Authority == 1 {
  1976. // if status == utils.COMPANY_STATUS_TRY_OUT || status == utils.COMPANY_STATUS_FORMAL || status == "全部" {
  1977. // condition += ` AND b.department_id=? `
  1978. // pars = append(pars, sysUser.DepartmentId)
  1979. //
  1980. // permissionCondition += ` AND b.department_id=? `
  1981. // permissionPars = append(permissionPars, sysUser.DepartmentId)
  1982. // } else {
  1983. // permissionCondition += ` AND b.department_id=? `
  1984. // permissionPars = append(permissionPars, sysUser.DepartmentId)
  1985. // }
  1986. // }
  1987. //
  1988. // if sysUser.Authority == 2 {
  1989. // if status == utils.COMPANY_STATUS_TRY_OUT || status == utils.COMPANY_STATUS_FORMAL || status == "全部" {
  1990. // condition += ` AND b.group_id=? `
  1991. // pars = append(pars, sysUser.GroupId)
  1992. //
  1993. // permissionCondition += ` AND b.group_id=? `
  1994. // permissionPars = append(permissionPars, sysUser.GroupId)
  1995. // } else {
  1996. // permissionCondition += ` AND b.group_id=? `
  1997. // permissionPars = append(permissionPars, sysUser.GroupId)
  1998. // }
  1999. // }
  2000. // }
  2001. // }
  2002. // }
  2003. //
  2004. // //if status == utils.COMPANY_STATUS_FREEZE {
  2005. // // condition += ` AND b.seller_id=? `
  2006. // // pars = append(pars, sysUser.AdminId)
  2007. // //
  2008. // // //permissionCondition += ` AND b.seller_id=? `
  2009. // // //permissionPars = append(permissionPars, sysUser.AdminId)
  2010. // //}
  2011. // //if status == "全部" || status == utils.COMPANY_STATUS_FREEZE {
  2012. // // freezeCondition += ` AND b.seller_id=? `
  2013. // // freezePars = append(freezePars, sysUser.AdminId)
  2014. // //}
  2015. // if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  2016. // //freezeCondition += ` AND b.seller_id=? `
  2017. // //freezePars = append(freezePars, sysUser.AdminId)
  2018. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  2019. // permissionCondition += ` AND b.product_id=? `
  2020. // permissionPars = append(permissionPars, 1)
  2021. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  2022. // permissionCondition += ` AND b.product_id=? `
  2023. // permissionPars = append(permissionPars, 2)
  2024. // } else {
  2025. // if status == utils.COMPANY_STATUS_FREEZE {
  2026. // condition += ` AND b.seller_id=? `
  2027. // pars = append(pars, sysUser.AdminId)
  2028. // }
  2029. //
  2030. // freezeCondition += ` AND b.seller_id=? `
  2031. // freezePars = append(freezePars, sysUser.AdminId)
  2032. // }
  2033. // }
  2034. //
  2035. // total, err := company.GetCompanyListCount(condition, pars)
  2036. // if err != nil {
  2037. // br.Msg = "获取失败"
  2038. // br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  2039. // return
  2040. // }
  2041. //
  2042. // sortStr := ``
  2043. // if sortParam != "" && sortType != "" {
  2044. // if sortParam == "endDate" {
  2045. // sortStr = " ORDER BY b.end_date "
  2046. // } else if sortParam == "createTime" {
  2047. // sortStr = " ORDER BY a.created_time "
  2048. // } else {
  2049. // br.Msg = "获取失败"
  2050. // br.ErrMsg = "排序字段传入数据异常:" + sortParam
  2051. // return
  2052. // }
  2053. //
  2054. // if sortType == "asc" {
  2055. // sortStr += " ASC "
  2056. // } else if sortType == "desc" {
  2057. // sortStr += " DESC "
  2058. // } else {
  2059. // br.Msg = "获取失败"
  2060. // br.ErrMsg = "排序类型传入数据异常:" + sortType
  2061. // return
  2062. // }
  2063. // }
  2064. //
  2065. // list, err := company.GetCompanyList(condition, status, sortStr, pars, startSize, pageSize)
  2066. // if err != nil {
  2067. // br.Msg = "获取失败"
  2068. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  2069. // return
  2070. // }
  2071. //
  2072. //
  2073. // //企业用户数组切片
  2074. // companyIdSlice := make([]string, 0)
  2075. // for _, v := range list {
  2076. // companyIdSlice = append(companyIdSlice, strconv.Itoa(v.CompanyId))
  2077. // }
  2078. //
  2079. // //企业用户产品开通数
  2080. // companyIdStr := strings.Join(companyIdSlice, ",")
  2081. // companyProductTotalList, _ := company.GetCountProductByCompanyIds(companyIdStr)
  2082. // companyProductTotalMap := make(map[int]*company.CompanyProductTotalSlice)
  2083. // for _, companyProductTotal := range companyProductTotalList {
  2084. // companyProductTotalMap[companyProductTotal.CompanyId] = companyProductTotal
  2085. // }
  2086. // lenList := len(list)
  2087. // for i := 0; i < lenList; i++ {
  2088. // item := list[i]
  2089. //
  2090. // //校验该客户是否存在多个产品,如果是,那么代表是共享客户
  2091. // if companyProductTotal, ok := companyProductTotalMap[int(item.CompanyId)]; ok {
  2092. // if companyProductTotal.Total > 1 {
  2093. // list[i].IsShared = true
  2094. // }
  2095. // }
  2096. //
  2097. // var expireDay string
  2098. // itemStatus := item.Status
  2099. // if itemStatus != "" {
  2100. // if !strings.Contains(item.Status, "/") {
  2101. // if itemStatus == utils.COMPANY_STATUS_FOREVER { //永续
  2102. // expireDay = "-"
  2103. // } else if itemStatus == utils.COMPANY_STATUS_TRY_OUT || itemStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  2104. // if item.StartDate != "" && item.EndDate != "" {
  2105. // endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  2106. // endDateTime = endDateTime.AddDate(0, 0, 1)
  2107. // sub := endDateTime.Sub(time.Now())
  2108. // if sub < 0 {
  2109. // sub = 0
  2110. // }
  2111. // expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2112. // } else {
  2113. // expireDay = "-"
  2114. // }
  2115. // } else if itemStatus == utils.COMPANY_STATUS_LOSE {
  2116. // expireDay = "-"
  2117. // } else if itemStatus == utils.COMPANY_STATUS_FREEZE {
  2118. // if item.StartDate != "" && item.EndDate != "" {
  2119. // endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  2120. // endDateTime = endDateTime.AddDate(0, 0, 0)
  2121. // sub := endDateTime.Sub(time.Now())
  2122. // if sub < 0 {
  2123. // sub = 0
  2124. // }
  2125. // expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2126. // } else {
  2127. // expireDay = "-"
  2128. // }
  2129. // } else {
  2130. // expireDay = "-"
  2131. // }
  2132. // } else {
  2133. // statusArr := strings.Split(item.Status, "/")
  2134. // ficcStatus := statusArr[0]
  2135. // raiStatus := statusArr[1]
  2136. // var ficcEndDate, tryEndDate string
  2137. // var ficcExpireDay, tryExpireDay string
  2138. // if item.EndDate != "" {
  2139. // endDateArr := strings.Split(item.EndDate, "/")
  2140. // if len(endDateArr) == 1 {
  2141. // ficcEndDate = endDateArr[0]
  2142. // } else if len(endDateArr) > 1 {
  2143. // ficcEndDate = endDateArr[0]
  2144. // tryEndDate = endDateArr[1]
  2145. // }
  2146. // if ficcStatus == utils.COMPANY_STATUS_FOREVER { //永续
  2147. // ficcExpireDay = "-"
  2148. // } else if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  2149. // if ficcEndDate != "" {
  2150. // endDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
  2151. // endDateTime = endDateTime.AddDate(0, 0, 1)
  2152. // sub := endDateTime.Sub(time.Now())
  2153. // if sub < 0 {
  2154. // sub = 0
  2155. // }
  2156. // ficcExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2157. // } else {
  2158. // ficcExpireDay = "-"
  2159. // }
  2160. // } else if ficcStatus == utils.COMPANY_STATUS_LOSE { //流失
  2161. // ficcExpireDay = "-"
  2162. // } else if ficcStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  2163. // if item.StartDate != "" && item.EndDate != "" {
  2164. // endDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
  2165. // endDateTime = endDateTime.AddDate(0, 0, 0)
  2166. // sub := endDateTime.Sub(time.Now())
  2167. // if sub < 0 {
  2168. // sub = 0
  2169. // }
  2170. // ficcExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2171. // } else {
  2172. // ficcExpireDay = "-"
  2173. // }
  2174. // } else {
  2175. // ficcExpireDay = "-"
  2176. // }
  2177. //
  2178. // if raiStatus == utils.COMPANY_STATUS_FOREVER { //永续
  2179. // tryExpireDay = "-"
  2180. // } else if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  2181. // if tryEndDate != "" {
  2182. // endDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
  2183. // endDateTime = endDateTime.AddDate(0, 0, 1)
  2184. // sub := endDateTime.Sub(time.Now())
  2185. // if sub < 0 {
  2186. // sub = 0
  2187. // }
  2188. // tryExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2189. // } else {
  2190. // tryExpireDay = "-"
  2191. // }
  2192. // } else if raiStatus == utils.COMPANY_STATUS_LOSE { //流失
  2193. // tryExpireDay = "-"
  2194. // } else if raiStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  2195. // if item.StartDate != "" && item.EndDate != "" {
  2196. // endDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
  2197. // endDateTime = endDateTime.AddDate(0, 0, 0)
  2198. // sub := endDateTime.Sub(time.Now())
  2199. // if sub < 0 {
  2200. // sub = 0
  2201. // }
  2202. // tryExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2203. // } else {
  2204. // tryExpireDay = "-"
  2205. // }
  2206. // } else {
  2207. // tryExpireDay = "-"
  2208. // }
  2209. // }
  2210. // expireDay = ficcExpireDay + "/" + tryExpireDay
  2211. // }
  2212. // }
  2213. // list[i].ExpireDay = expireDay
  2214. //
  2215. // //按钮显示控制
  2216. // btnItem := new(company.ButtonPermission)
  2217. // if item.CompanyId != 1 {
  2218. // *btnItem = services.GetCompanyPermissionButton(roleTypeCode, itemStatus, item.GroupIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId)
  2219. // }
  2220. // list[i].BtnItem = btnItem
  2221. // if item.FreezeStartDate != "" && item.FreezeEndDate != "" && item.Status == utils.COMPANY_STATUS_FREEZE {
  2222. // freezeEndDate, _ := time.Parse(utils.FormatDate, item.FreezeEndDate)
  2223. // if time.Now().Before(freezeEndDate) {
  2224. // expireDays := freezeEndDate.Sub(time.Now()).Hours() / 24
  2225. // list[i].FreezeExpireDays = int(expireDays) + 1
  2226. // }
  2227. // }
  2228. // }
  2229. //
  2230. // statusCount, err := company.GetCompanyStatusCount(permissionCondition, permissionPars)
  2231. // if err != nil {
  2232. // br.Msg = "获取失败"
  2233. // br.ErrMsg = "获取状态数量失败,Err:" + err.Error()
  2234. // return
  2235. // }
  2236. //
  2237. // statusMap := make(map[string]int, 0)
  2238. // var totalCount int
  2239. // for _, sv := range statusCount {
  2240. // totalCount = totalCount + sv.Count
  2241. // statusMap[sv.Status] = sv.Count
  2242. // }
  2243. //
  2244. // lossItem, err := company.GetCompanyStatusLoseCount(lossCondition, lossPars)
  2245. // if err != nil {
  2246. // br.Msg = "获取失败"
  2247. // br.ErrMsg = "获取流失状态数量失败,Err:" + err.Error()
  2248. // return
  2249. // }
  2250. // totalCount = totalCount + lossItem.Count
  2251. //
  2252. // freezeItem, err := company.GetCompanyStatusFreezeCount(freezeCondition, freezePars)
  2253. // if err != nil {
  2254. // br.Msg = "获取失败"
  2255. // br.ErrMsg = "获取冻结状态数量失败,Err:" + err.Error()
  2256. // return
  2257. // }
  2258. // statusMap["冻结"] = freezeItem.Count
  2259. // totalCount = totalCount + freezeItem.Count
  2260. //
  2261. // forverItem, err := company.GetCompanyStatusForverCount(forverCondition, forverPars)
  2262. // if err != nil {
  2263. // br.Msg = "获取失败"
  2264. // br.ErrMsg = "获取永续状态数量失败,Err:" + err.Error()
  2265. // return
  2266. // }
  2267. // totalCount = totalCount + forverItem.Count
  2268. //
  2269. // for _, v := range statusArr {
  2270. // statusCount := new(company.CompanyStatus)
  2271. // if v == "全部" {
  2272. // statusCount.Status = "全部"
  2273. // statusCount.Count = totalCount
  2274. // } else if v == utils.COMPANY_STATUS_LOSE {
  2275. // statusCount.Status = v
  2276. // statusCount.Count = lossItem.Count
  2277. // } else if v == utils.COMPANY_STATUS_FOREVER {
  2278. // statusCount.Status = v
  2279. // statusCount.Count = forverItem.Count
  2280. // //} else if v == utils.COMPANY_STATUS_FREEZE {
  2281. // // statusCount.Status = v
  2282. // // statusCount.Count = freezeItem.Count
  2283. // //}
  2284. // } else {
  2285. // statusCount.Status = v
  2286. // if val, ok := statusMap[v]; ok {
  2287. // statusCount.Count = val
  2288. // }
  2289. // }
  2290. // statusItems = append(statusItems, statusCount)
  2291. // }
  2292. //
  2293. // companyLists := make([]*company.CompanyListItem, 0)
  2294. // //查询阅读次数
  2295. // if list == nil {
  2296. // companyLists = make([]*company.CompanyListItem, 0)
  2297. // } else {
  2298. // for _, v := range list {
  2299. // viewTotal := GetviewTotal(v.CompanyId)
  2300. // companyList := &company.CompanyListItem{
  2301. // CompanyId: v.CompanyId,
  2302. // CompanyName: v.CompanyName,
  2303. // CreditCode: v.CreditCode,
  2304. // CompanyCode: v.CompanyCode,
  2305. // StartDate: v.StartDate,
  2306. // EndDate: v.EndDate,
  2307. // LoseReason: v.LoseReason,
  2308. // RenewalReason: v.RenewalReason,
  2309. // FreezeReason: v.FreezeReason,
  2310. // LossTime: v.LossTime,
  2311. // Status: v.Status,
  2312. // CompanyType: v.CompanyType,
  2313. // ApproveStatus: v.ApproveStatus,
  2314. // SellerName: v.SellerName,
  2315. // SellerId: v.SellerId,
  2316. // SellerIds: v.SellerIds,
  2317. // ExpireDay: v.ExpireDay,
  2318. // FreezeTime: v.FreezeTime,
  2319. // GroupId: v.GroupId,
  2320. // GroupIds: v.GroupIds,
  2321. // DepartmentId: v.DepartmentId,
  2322. // IndustryName: v.IndustryName,
  2323. // IsSuspend: v.IsSuspend,
  2324. // CreatedTime: v.CreatedTime,
  2325. // Source: v.Source,
  2326. // Province: v.Province,
  2327. // City: v.City,
  2328. // Address: v.Address,
  2329. // Reasons: v.Reasons,
  2330. // FreezeStartDate: v.FreezeStartDate,
  2331. // FreezeEndDate: v.FreezeEndDate,
  2332. // FreezeExpireDays: v.FreezeExpireDays,
  2333. // BtnItem: v.BtnItem,
  2334. // ProductId: v.ProductId,
  2335. // FormalTime: v.FormalTime,
  2336. // IsShared: v.IsShared,
  2337. // RegionType: v.RegionType,
  2338. // FiccView: viewTotal[0],
  2339. // RaiView: viewTotal[1],
  2340. // }
  2341. // companyLists = append(companyLists, companyList)
  2342. // }
  2343. // }
  2344. // if companyLists == nil {
  2345. // companyLists = make([]*company.CompanyListItem, 0)
  2346. // }
  2347. // page = paging.GetPaging(currentIndex, pageSize, total)
  2348. // resp.List = companyLists
  2349. // resp.StatusCount = statusItems
  2350. // resp.Paging = page
  2351. // br.Ret = 200
  2352. // br.Success = true
  2353. // br.Msg = "获取成功"
  2354. // br.Data = resp
  2355. //}
  2356. func GetviewTotal(companyId int) (view []int) {
  2357. list, err := company.GetCompanyUserListById(companyId)
  2358. if err != nil {
  2359. fmt.Println("GetCompanyUserList err:", err.Error())
  2360. return
  2361. }
  2362. //获取企业客户信息
  2363. companyInfo, err := company.GetCompanyById(companyId)
  2364. if err != nil {
  2365. fmt.Println("GetCompanyById err:", err.Error())
  2366. return
  2367. }
  2368. var ficcViewTotal, cygxViewTotal int
  2369. lenList := len(list)
  2370. if lenList > 0 {
  2371. userIdSlice := make([]string, 0)
  2372. mobilesSlice := make([]string, 0)
  2373. emailsSlice := make([]string, 0)
  2374. for _, v := range list {
  2375. userIdSlice = append(userIdSlice, strconv.Itoa(int(v.UserId)))
  2376. if v.Mobile != "" {
  2377. mobilesSlice = append(mobilesSlice, v.Mobile)
  2378. } else if v.Email != "" {
  2379. emailsSlice = append(emailsSlice, v.Email)
  2380. }
  2381. }
  2382. //用户浏览数据
  2383. mobileStr := strings.Join(mobilesSlice, "','")
  2384. mobileStr = "'" + mobileStr + "'"
  2385. emailStr := strings.Join(emailsSlice, "','")
  2386. emailStr = "'" + emailStr + "'"
  2387. //报告统计删除晨报部分统计加入每日资讯 2021-4-9
  2388. //手机号
  2389. userViewMobileTotalMap := make(map[string]*models.UserViewMobileTotalSlice)
  2390. userReportViewMobileTotalMap := make(map[string]*models.ReportViewMobileRecord)
  2391. userAdvisoryViewMobileTotalMap := make(map[string]*advisory.UserViewMobileTotalSlice)
  2392. userCygxArticleHistoryRecordViewMobileTotalMap := make(map[string]*models.UserViewMobileTotalSlice)
  2393. if len(mobilesSlice) > 0 {
  2394. //权益数据
  2395. rightsItems, err := company.GetRightsReportListByMobile(mobileStr)
  2396. if err != nil {
  2397. fmt.Println("GetRightsReportListByMobile err:", err.Error())
  2398. return
  2399. }
  2400. cygxViewTotal = len(rightsItems)
  2401. //FICC数据
  2402. ficcItems, err := company.GetFiccReportListByMobile(mobileStr)
  2403. if err != nil {
  2404. fmt.Println("GetFiccReportListByMobile err:", err.Error())
  2405. return
  2406. }
  2407. ficcViewTotal = len(ficcItems)
  2408. }
  2409. //邮箱
  2410. userViewEmailTotalMap := make(map[string]*models.UserViewEmailTotalSlice)
  2411. userReportViewEmailTotalMap := make(map[string]*models.ReportViewEmailRecord)
  2412. userAdvisoryViewEmailTotalMap := make(map[string]*advisory.UserViewEmailTotalSlice)
  2413. userCygxViewEmailTotalMap := make(map[string]*models.UserViewEmailTotalSlice)
  2414. if len(emailsSlice) > 0 {
  2415. //FICC数据
  2416. ficcItems, err := company.GetFiccReportListByEmail(emailStr)
  2417. if err != nil {
  2418. fmt.Println("GetFiccReportListByEmail err:", err.Error())
  2419. return
  2420. }
  2421. ficcViewTotal += len(ficcItems)
  2422. //权益数据
  2423. rightsItems, err := company.GetRightsReportListByEmail(emailStr)
  2424. if err != nil {
  2425. fmt.Println("GetViewReportListByMobile err:", err.Error())
  2426. return
  2427. }
  2428. cygxViewTotal += len(rightsItems)
  2429. }
  2430. for i := 0; i < lenList; i++ {
  2431. item := list[i]
  2432. //企业名称
  2433. list[i].CompanyName = companyInfo.CompanyName
  2434. //手机号用户累计浏览次数
  2435. if userView, ok := userViewMobileTotalMap[item.Mobile]; ok {
  2436. list[i].ViewTotal += userView.Total
  2437. }
  2438. //邮箱用户累计浏览次数
  2439. if userView, ok := userViewEmailTotalMap[item.Email]; ok {
  2440. //总共浏览的报表数据需要调整为(手机号用户浏览晨报数+邮箱号用户浏览晨报数)
  2441. list[i].ViewTotal += userView.Total
  2442. }
  2443. if item.OpenId != "" {
  2444. list[i].IsRegister = true
  2445. } else {
  2446. if item.RegisterPlatform == 2 {
  2447. if item.Mobile != "" || item.Email != "" {
  2448. list[i].IsRegister = true
  2449. }
  2450. } else if item.RegisterTime != "" {
  2451. list[i].IsRegister = true
  2452. } else {
  2453. list[i].IsRegister = false
  2454. }
  2455. }
  2456. //如果存在手机号用户日评数据,那么需要做处理
  2457. if reportView, ok := userReportViewMobileTotalMap[item.Mobile]; ok {
  2458. //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
  2459. if reportView.LastViewTime.After(list[i].LastViewTime) {
  2460. list[i].LastViewTime = reportView.LastViewTime
  2461. list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
  2462. }
  2463. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
  2464. list[i].ViewTotal += reportView.ViewTotal
  2465. }
  2466. //如果存在手机号用户日评数据,那么需要做处理
  2467. if reportView, ok := userReportViewEmailTotalMap[item.Email]; ok {
  2468. //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
  2469. if reportView.LastViewTime.After(list[i].LastViewTime) {
  2470. list[i].LastViewTime = reportView.LastViewTime
  2471. list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
  2472. }
  2473. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
  2474. list[i].ViewTotal += reportView.ViewTotal
  2475. }
  2476. //如果存在手机号用户每日资讯,那么需要做处理
  2477. if advisoryView, ok := userAdvisoryViewMobileTotalMap[item.Mobile]; ok {
  2478. //fmt.Println("蝴蝶眨几次眼睛")
  2479. //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  2480. if advisoryView.CreatedTime.After(list[i].LastViewTime) {
  2481. list[i].LastViewTime = advisoryView.CreatedTime
  2482. list[i].LastViewTimeStr = advisoryView.CreatedTime.Format(utils.FormatDateTime)
  2483. }
  2484. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数)
  2485. list[i].ViewTotal += advisoryView.Total
  2486. }
  2487. //如果存在邮箱号用户每日资讯,那么需要做处理
  2488. if advisoryView, ok := userAdvisoryViewEmailTotalMap[item.Email]; ok {
  2489. //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  2490. if advisoryView.CreatedTime.After(list[i].LastViewTime) {
  2491. list[i].LastViewTime = advisoryView.CreatedTime
  2492. list[i].LastViewTimeStr = advisoryView.CreatedTime.Format(utils.FormatDateTime)
  2493. }
  2494. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数)
  2495. list[i].ViewTotal += advisoryView.Total
  2496. }
  2497. ficcViewTotal += list[i].ViewTotal
  2498. //如果存在手机号用户查研观向,那么需要做处理
  2499. if cygxView, ok := userCygxArticleHistoryRecordViewMobileTotalMap[item.Mobile]; ok {
  2500. //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  2501. if cygxView.CreatedTime.After(list[i].LastViewTime) {
  2502. list[i].LastViewTime = cygxView.CreatedTime
  2503. list[i].LastViewTimeStr = cygxView.CreatedTime.Format(utils.FormatDateTime)
  2504. }
  2505. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数+查研观向)
  2506. cygxViewTotal += cygxView.Total
  2507. list[i].ViewTotal += cygxView.Total
  2508. }
  2509. //如果存在邮箱号用户查研观向,那么需要做处理
  2510. if cygxView, ok := userCygxViewEmailTotalMap[item.Email]; ok {
  2511. //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  2512. if cygxView.CreatedTime.After(list[i].LastViewTime) {
  2513. list[i].LastViewTime = cygxView.CreatedTime
  2514. list[i].LastViewTimeStr = cygxView.CreatedTime.Format(utils.FormatDateTime)
  2515. }
  2516. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数+查研观向)
  2517. cygxViewTotal += cygxView.Total
  2518. //list[i].ViewTotal += cygxView.Total
  2519. }
  2520. /*if reportView, ok := userReportViewTotalMap[int(item.UserId)]; ok {
  2521. //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
  2522. if reportView.LastViewTime.After(list[i].LastViewTime) {
  2523. list[i].LastViewTime = reportView.LastViewTime
  2524. list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
  2525. }
  2526. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
  2527. list[i].ViewTotal += reportView.ViewTotal
  2528. }*/
  2529. }
  2530. }
  2531. view = append(view, ficcViewTotal)
  2532. view = append(view, cygxViewTotal)
  2533. return
  2534. }
  2535. // @Title 新增客户
  2536. // @Description 新增客户接口
  2537. // @Param request body company.CompanyAddReq true "type json string"
  2538. // @Success 200 {object} company.CompanyAddResp
  2539. // @router /add [post]
  2540. func (this *CompanyController) Add() {
  2541. br := new(models.BaseResponse).Init()
  2542. defer func() {
  2543. this.Data["json"] = br
  2544. this.ServeJSON()
  2545. }()
  2546. sysUser := this.SysUser
  2547. if sysUser == nil {
  2548. br.Msg = "请登录"
  2549. br.ErrMsg = "请登录,SysUser Is Empty"
  2550. br.Ret = 408
  2551. return
  2552. }
  2553. roleTypeCode := sysUser.RoleTypeCode
  2554. var req company.CompanyAddReq
  2555. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2556. if err != nil {
  2557. br.Msg = "参数解析异常!"
  2558. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2559. return
  2560. }
  2561. if req.CompanyName == "" {
  2562. br.Msg = "请填写客户名称"
  2563. return
  2564. }
  2565. if req.CreditCode == "" {
  2566. br.Msg = "请填写社会统一信用码"
  2567. return
  2568. }
  2569. if req.Status == "" {
  2570. br.Msg = "客户状态不可为空"
  2571. return
  2572. }
  2573. //移除空格
  2574. req.CreditCode = utils.TrimStr(req.CreditCode)
  2575. var startDateTime, endDateTime time.Time
  2576. if req.Status == utils.COMPANY_STATUS_TRY_OUT {
  2577. startDateTime = time.Now()
  2578. endDateTime = time.Now().AddDate(0, 2, 0)
  2579. } else if req.Status == utils.COMPANY_STATUS_FOREVER {
  2580. startDateTime = time.Now()
  2581. endDateTime = time.Now().AddDate(100, 0, 0)
  2582. } else {
  2583. br.Msg = "无效的客户状态,请重新选择"
  2584. return
  2585. }
  2586. var startDate, endDate string
  2587. startDate = startDateTime.Format(utils.FormatDate)
  2588. endDate = endDateTime.Format(utils.FormatDate)
  2589. if req.CompanyType == "" {
  2590. br.Msg = "请选择客户类型"
  2591. return
  2592. }
  2593. var productId int
  2594. var productName string
  2595. if req.CompanyType == utils.COMPANY_PRODUCT_FICC_NAME {
  2596. productId = utils.COMPANY_PRODUCT_FICC_ID
  2597. productName = utils.COMPANY_PRODUCT_FICC_NAME
  2598. } else if req.CompanyType == utils.COMPANY_PRODUCT_RAI_NAME {
  2599. productId = utils.COMPANY_PRODUCT_RAI_ID
  2600. productName = utils.COMPANY_PRODUCT_RAI_NAME
  2601. } else {
  2602. br.Msg = "无效的客户类型,请重新选择"
  2603. return
  2604. }
  2605. if req.IndustryId <= 0 {
  2606. br.Msg = "请选择行业"
  2607. return
  2608. }
  2609. if req.SellsId <= 0 {
  2610. br.Msg = "请选择所属销售"
  2611. return
  2612. }
  2613. //if req.Reasons == "" {
  2614. // br.Msg = "请填写新增理由"
  2615. // return
  2616. //}
  2617. if req.PermissionIds == "" {
  2618. br.Msg = "请选择权限"
  2619. return
  2620. } else {
  2621. permissionStr, err := company.GetPermissionIdById(req.PermissionIds)
  2622. if err != nil {
  2623. br.Msg = "获取信息失败"
  2624. br.ErrMsg = "获取主观客观权限信息失败,Err:" + err.Error()
  2625. return
  2626. }
  2627. req.PermissionIds = permissionStr
  2628. }
  2629. industry, err := company.GetCompanyIndustryById(req.IndustryId)
  2630. if err != nil {
  2631. br.Msg = "获取行业信息失败"
  2632. br.ErrMsg = "获取行业信息失败,Err:" + err.Error()
  2633. return
  2634. }
  2635. if industry == nil {
  2636. br.Msg = "行业信息不存在"
  2637. return
  2638. }
  2639. //判断客户是否已经存在
  2640. companyNameIsExist, err := company.GetCompanyCountByCompanyName(req.CompanyName)
  2641. if err != nil {
  2642. br.Msg = "判断客户是否存在失败"
  2643. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  2644. return
  2645. }
  2646. if companyNameIsExist > 0 {
  2647. br.Msg = "客户已存在,请重新输入客户名称"
  2648. return
  2649. }
  2650. //判断客户是否已经存在
  2651. companyCreditCodeIsExist, err := company.GetCompanyCountByCreditCode(req.CreditCode)
  2652. if err != nil {
  2653. br.Msg = "判断客户是否存在失败"
  2654. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  2655. return
  2656. }
  2657. if companyCreditCodeIsExist > 0 {
  2658. br.Msg = "客户已存在,统一社会信用代码"
  2659. return
  2660. }
  2661. seller, err := system.GetSysAdminById(req.SellsId)
  2662. if err != nil {
  2663. br.Msg = "获取销售信息失败"
  2664. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  2665. return
  2666. }
  2667. tryOutCount, err := company.GetCompanyTryOutCount(utils.COMPANY_STATUS_TRY_OUT, seller.AdminId)
  2668. if err != nil {
  2669. br.Msg = "判断试用客户量失败"
  2670. br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  2671. return
  2672. }
  2673. /*
  2674. ROLE_TYPE_CODE_ADMIN = "admin" //管理员
  2675. ROLE_TYPE_CODE_FICC_ADMIN = "ficc_admin" //ficc管理员
  2676. ROLE_TYPE_CODE_FICC_SELLER = "ficc_seller" //ficc销售
  2677. ROLE_TYPE_CODE_RAI_ADMIN = "rai_admin" //权益管理员
  2678. ROLE_TYPE_CODE_RAI_SELLER = "rai_seller" //权益销售
  2679. ROLE_TYPE_CODE_FICC_GROUP = "ficc_group" //ficc组长
  2680. ROLE_TYPE_CODE_RAI_GROUP = "rai_group" //ficc组长
  2681. ROLE_TYPE_CODE_FICC_DEPARTMENT = "ficc_department" //ficc部门经理
  2682. ROLE_TYPE_CODE_RAI_DEPARTMENT = "rai_department" //权益部门经理
  2683. ROLE_TYPE_CODE_FICC_RESEARCHR = "ficc_researcher" //ficc研究员
  2684. ROLE_TYPE_CODE_RAI_RESEARCHR = "rai_researcher" //权益研究员
  2685. */
  2686. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
  2687. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  2688. if tryOutCount >= utils.COMPANY_STATUS_TRY_OUT_COUNT {
  2689. br.Msg = "您的试用客户总数,已超过上限,不可继续新增"
  2690. return
  2691. }
  2692. }
  2693. if seller == nil {
  2694. br.Msg = "所属销售不存在"
  2695. return
  2696. }
  2697. companyCode, err := company.GetCompanyCode()
  2698. if err != nil {
  2699. br.Msg = "获取客户编码信息失败"
  2700. br.ErrMsg = "获取客户编码信息失败,Err:" + err.Error()
  2701. return
  2702. }
  2703. item := new(company.Company)
  2704. item.CompanyName = req.CompanyName
  2705. item.CreditCode = req.CreditCode
  2706. item.CompanyCode = companyCode
  2707. item.Province = req.Province
  2708. item.City = req.City
  2709. item.Address = req.Province + req.City
  2710. item.StartDate = time.Now().Format(utils.FormatDate)
  2711. if req.Status == utils.COMPANY_STATUS_FOREVER {
  2712. item.EndDate = time.Now().AddDate(100, 0, 0).Format(utils.FormatDate)
  2713. item.CompanyType = 5
  2714. }
  2715. if req.Status == utils.COMPANY_STATUS_TRY_OUT {
  2716. item.EndDate = time.Now().AddDate(0, 2, 0).Format(utils.FormatDate)
  2717. item.CompanyType = 2
  2718. }
  2719. item.FirstStartDate = item.StartDate
  2720. item.FirstEndDate = item.EndDate
  2721. item.CreatedTime = time.Now()
  2722. item.LastUpdatedTime = time.Now()
  2723. item.Enabled = 1
  2724. item.RegionType = req.RegionType
  2725. item.Remark = req.Reasons
  2726. item.Nation = req.Nation
  2727. companyId, err := company.AddCompany(item)
  2728. if err != nil {
  2729. br.Msg = "新增失败"
  2730. br.ErrMsg = "新增失败,err:" + err.Error()
  2731. return
  2732. }
  2733. item.CompanyId = int(companyId)
  2734. //生成第三方code编号
  2735. item.OpenCompanyCode = services.GenerateOpenCompanyCode(int(companyId))
  2736. item.Update([]string{"OpenCompanyCode"})
  2737. if req.UserId > 0 {
  2738. //修改联系人
  2739. err = company.ModifyCompanyUserCompanyId(req.UserId, int(companyId))
  2740. if err != nil {
  2741. br.Msg = "新增失败"
  2742. br.ErrMsg = "新增失败,ModifyCompanyUserCompanyId err:" + err.Error()
  2743. return
  2744. }
  2745. //获取联系人详情
  2746. userInfo, err := models.GetWxUserByUserId(req.UserId)
  2747. if err != nil {
  2748. br.Msg = "获取联系人异常!"
  2749. br.ErrMsg = "获取联系人异常,Err:" + err.Error()
  2750. return
  2751. }
  2752. //添加该联系人 与 当前销售的关系
  2753. models.AddUserSellerRelation(int64(req.UserId), int(companyId), seller.AdminId, productId, seller.RealName, userInfo.Mobile, userInfo.Email)
  2754. }
  2755. companyProduct := new(company.CompanyProduct)
  2756. companyProduct.CompanyId = int(companyId)
  2757. companyProduct.ProductId = productId
  2758. companyProduct.ProductName = productName
  2759. companyProduct.CompanyName = req.CompanyName
  2760. companyProduct.Source = req.Source
  2761. companyProduct.Reasons = req.Reasons
  2762. companyProduct.Status = req.Status
  2763. companyProduct.StartDate = startDate
  2764. companyProduct.EndDate = endDate
  2765. companyProduct.IndustryId = req.IndustryId
  2766. companyProduct.IndustryName = industry.IndustryName
  2767. companyProduct.SellerId = seller.AdminId
  2768. companyProduct.SellerName = seller.RealName
  2769. companyProduct.GroupId = seller.GroupId
  2770. companyProduct.DepartmentId = seller.DepartmentId
  2771. companyProduct.IsSuspend = 0
  2772. companyProduct.CreateTime = time.Now()
  2773. companyProduct.ModifyTime = time.Now()
  2774. companyProduct.CompanyType = req.CompanyType
  2775. companyProduct.Scale = req.Scale
  2776. companyProduct.OpenCode = services.GenerateOpenCompanyProductCode(int(companyId), productId)
  2777. companyProduct.TodoStatus = "无任务"
  2778. companyProduct.TryStage = 1
  2779. companyProduct.OverseasLabel = 1
  2780. companyProductId, err := company.AddCompanyProduct(companyProduct)
  2781. if err != nil {
  2782. br.Msg = "新增失败"
  2783. br.ErrMsg = "新增客户产品失败,err:" + err.Error()
  2784. return
  2785. }
  2786. companyReportPermissionList, err := services.AddCompanyPermission(int(companyId), seller.AdminId, productId, productName, seller.RealName, req.PermissionIds, startDate, endDate)
  2787. if err != nil {
  2788. br.Msg = "新增失败"
  2789. br.ErrMsg = "新增客户设置权限失败,err:" + err.Error()
  2790. return
  2791. }
  2792. {
  2793. record := new(company.CompanyOperationRecord)
  2794. record.CompanyId = int(companyId)
  2795. record.CompanyName = req.CompanyName
  2796. record.SellerId = seller.AdminId
  2797. record.SysUserId = seller.AdminId
  2798. record.SysRealName = seller.RealName
  2799. record.Remark = "新增客户"
  2800. record.Operation = "add"
  2801. record.CreateTime = time.Now()
  2802. record.ProductId = productId
  2803. record.ProductName = productName
  2804. record.Status = req.Status
  2805. _, err = company.AddCompanyOperationRecord(record)
  2806. if err != nil {
  2807. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  2808. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  2809. }
  2810. }
  2811. //新增客户日志
  2812. {
  2813. companyLog := new(company.CompanyLog)
  2814. companyLog.CompanyId = int(companyId)
  2815. companyLog.CompanyName = req.CompanyName
  2816. companyLog.CreditCode = req.CreditCode
  2817. companyLog.CompanyCode = companyCode
  2818. companyLog.Sort = item.Sort
  2819. companyLog.IsFeeCustomer = item.IsFeeCustomer
  2820. companyLog.Country = item.Country
  2821. companyLog.Address = item.Address
  2822. companyLog.City = item.City
  2823. companyLog.Province = item.Province
  2824. companyLog.Enabled = item.Enabled
  2825. companyLog.CreatedTime = item.CreatedTime
  2826. companyLog.LastUpdatedTime = item.LastUpdatedTime
  2827. companyLog.Seller = item.Seller
  2828. companyLog.SellsId = item.SellsId
  2829. companyLog.CompanyBelong = item.CompanyBelong
  2830. companyLog.StartDate = item.StartDate
  2831. companyLog.EndDate = item.EndDate
  2832. companyLog.FirstStartDate = item.FirstStartDate
  2833. companyLog.FirstEndDate = item.FirstEndDate
  2834. companyLog.DateType = item.DateType
  2835. companyLog.AdminId = this.SysUser.AdminId
  2836. companyLog.LogType = "add"
  2837. companyLog.LogCreateTime = time.Now()
  2838. go company.AddCompanyLog(companyLog)
  2839. }
  2840. //新增客户产品日志
  2841. {
  2842. productLog := new(company.CompanyProductLog)
  2843. productLog.CompanyProductId = int(companyProductId)
  2844. productLog.CompanyId = companyProduct.CompanyId
  2845. productLog.ProductId = companyProduct.ProductId
  2846. productLog.ProductName = companyProduct.ProductName
  2847. productLog.CompanyName = companyProduct.CompanyName
  2848. productLog.CompanyName = companyProduct.CompanyName
  2849. productLog.Source = companyProduct.Source
  2850. productLog.Reasons = companyProduct.Reasons
  2851. productLog.Status = companyProduct.Status
  2852. productLog.IndustryId = companyProduct.IndustryId
  2853. productLog.IndustryName = companyProduct.IndustryName
  2854. productLog.SellerId = companyProduct.SellerId
  2855. productLog.SellerName = companyProduct.SellerName
  2856. productLog.GroupId = companyProduct.GroupId
  2857. productLog.DepartmentId = companyProduct.DepartmentId
  2858. productLog.IsSuspend = companyProduct.IsSuspend
  2859. productLog.SuspendTime = companyProduct.SuspendTime
  2860. productLog.ApproveStatus = companyProduct.ApproveStatus
  2861. productLog.FreezeTime = companyProduct.FreezeTime
  2862. productLog.Remark = companyProduct.Remark
  2863. productLog.StartDate = companyProduct.StartDate
  2864. productLog.EndDate = companyProduct.EndDate
  2865. productLog.CreateTime = companyProduct.CreateTime
  2866. productLog.ModifyTime = companyProduct.ModifyTime
  2867. productLog.LoseReason = companyProduct.LoseReason
  2868. productLog.LossTime = companyProduct.LossTime
  2869. productLog.LogType = "add"
  2870. productLog.LogCreateTime = time.Now()
  2871. productLog.AdminId = this.SysUser.AdminId
  2872. productLog.Scale = companyProduct.Scale
  2873. go company.AddCompanyProductLog(productLog)
  2874. }
  2875. //新增客户产品状态变更日志
  2876. {
  2877. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  2878. Id: 0,
  2879. CompanyId: companyProduct.CompanyId,
  2880. ProductId: companyProduct.ProductId,
  2881. Status: "试用",
  2882. Source: "add",
  2883. SellerId: companyProduct.SellerId,
  2884. SellerName: companyProduct.SellerName,
  2885. StartDate: startDateTime,
  2886. EndDate: endDateTime,
  2887. RealEndDate: startDateTime,
  2888. CreateTime: time.Now(),
  2889. }
  2890. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  2891. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  2892. Id: 0,
  2893. CompanyId: companyProduct.CompanyId,
  2894. ProductId: companyProduct.ProductId,
  2895. Source: "add",
  2896. SellerId: companyProduct.SellerId,
  2897. SellerName: companyProduct.SellerName,
  2898. StartDate: startDateTime,
  2899. EndDate: endDateTime,
  2900. RealEndDate: startDateTime,
  2901. IsStop: 0,
  2902. CreateTime: time.Now(),
  2903. }
  2904. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  2905. }
  2906. resp := new(company.CompanyAddResp)
  2907. resp.CompanyId = int(companyId)
  2908. br.Ret = 200
  2909. br.Success = true
  2910. br.Msg = "新增成功"
  2911. br.Data = resp
  2912. }
  2913. // Detail
  2914. // @Title 获取客户详情
  2915. // @Description 获取客户详情接口
  2916. // @Param CompanyId query int true "客户id"
  2917. // @Success 200 {object} company.CompanyDetailResp
  2918. // @router /detail [get]
  2919. func (this *CompanyController) Detail() {
  2920. br := new(models.BaseResponse).Init()
  2921. defer func() {
  2922. this.Data["json"] = br
  2923. this.ServeJSON()
  2924. }()
  2925. sysUser := this.SysUser
  2926. if sysUser == nil {
  2927. br.Msg = "请登录"
  2928. br.ErrMsg = "请登录,SysUser Is Empty"
  2929. br.Ret = 408
  2930. return
  2931. }
  2932. companyId, _ := this.GetInt("CompanyId")
  2933. if companyId <= 0 {
  2934. br.Msg = "参数错误"
  2935. br.ErrMsg = "客户参数小于等于0"
  2936. return
  2937. }
  2938. // CRM8.8-是否为编辑页的客户详情
  2939. isEdit, _ := this.GetBool("IsEdit")
  2940. item, err := company.GetCompanyDetailById(companyId)
  2941. if err != nil {
  2942. br.Msg = "获取信息失败"
  2943. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  2944. return
  2945. }
  2946. shareSellerId := item.ShareSellerId
  2947. var productName string
  2948. productId := services.GetProductId(sysUser.RoleTypeCode)
  2949. if productId == 1 {
  2950. productName = utils.COMPANY_PRODUCT_FICC_NAME
  2951. } else if productId == 2 {
  2952. productName = utils.COMPANY_PRODUCT_RAI_NAME
  2953. } else {
  2954. productName = "admin"
  2955. }
  2956. resp := new(company.CompanyDetailResp)
  2957. resp.ProductName = productName
  2958. //获取客户产品
  2959. productList, err := company.GetCompanyProductsByCompanyId(companyId)
  2960. if err != nil {
  2961. br.Msg = "获取信息失败"
  2962. br.ErrMsg = "获取产品信息失败,Err:" + err.Error()
  2963. return
  2964. }
  2965. roleTypeCode := sysUser.RoleTypeCode
  2966. itemLen := len(productList)
  2967. btnDetailItem := new(company.ButtonDetailPermission)
  2968. // 客户权限校验
  2969. {
  2970. // 如果不是超管、ficc管理员、权益管理员,那么需要额外校验下权限
  2971. if !utils.InArrayByStr([]string{utils.ROLE_TYPE_CODE_ADMIN, utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_RAI_ADMIN}, sysUser.RoleTypeCode) {
  2972. var isOk bool //是否有权限
  2973. var companyHasProduct bool // 客户当前是否有该产品权限
  2974. for _, productInfo := range productList {
  2975. // 只校验拥有的品种权限:ficc或者权益
  2976. if productInfo.ProductId == productId {
  2977. companyHasProduct = true
  2978. // 自己的客户有权限看
  2979. if productInfo.SellerId == sysUser.AdminId {
  2980. isOk = true
  2981. break
  2982. }
  2983. // 流失客户都有权限看
  2984. if productInfo.Status == utils.COMPANY_STATUS_LOSE || productInfo.Status == utils.COMPANY_STATUS_CLOSE {
  2985. isOk = true
  2986. break
  2987. }
  2988. // 分享的客户 也有权限
  2989. if item.IsShare == 1 && item.ShareSellerId == sysUser.AdminId {
  2990. isOk = true
  2991. break
  2992. }
  2993. // 如果是组长,且该客户属于本组客户
  2994. if sysUser.Authority == 4 && productInfo.GroupId > 0 && productInfo.GroupId == sysUser.GroupId && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM {
  2995. isOk = true
  2996. break
  2997. }
  2998. // 如果是ficc主管或者权益主管
  2999. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  3000. // 获取顶级分组Id
  3001. var sysUserGroupPid, productGroupPid int
  3002. // 当前账号的顶级分组id
  3003. {
  3004. sysUserGroupIdpid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  3005. if err != nil && err.Error() != utils.NotEmpty() {
  3006. break
  3007. }
  3008. if sysUserGroupIdpid == nil || *sysUserGroupIdpid == 0 {
  3009. sysUserGroupPid = sysUser.GroupId
  3010. } else {
  3011. sysUserGroupPid = *sysUserGroupIdpid
  3012. }
  3013. }
  3014. // 当前客户的顶级分组id
  3015. {
  3016. groupIdpid, err := company.GetParentIdFromGroup(productInfo.GroupId)
  3017. if err != nil && err.Error() != utils.NotEmpty() {
  3018. break
  3019. }
  3020. if groupIdpid == nil || *groupIdpid == 0 {
  3021. productGroupPid = productInfo.GroupId
  3022. } else {
  3023. productGroupPid = *groupIdpid
  3024. }
  3025. }
  3026. // 如果客户的顶级分组和当前账号分组id一致
  3027. if sysUserGroupPid == productGroupPid {
  3028. isOk = true
  3029. break
  3030. }
  3031. }
  3032. }
  3033. }
  3034. // 客户当前是否有该产品的权限,如果没有的话,说明是在领取客户,允许访问
  3035. if !companyHasProduct {
  3036. isOk = true
  3037. }
  3038. if !isOk {
  3039. br.Msg = "无访问权限"
  3040. return
  3041. }
  3042. }
  3043. }
  3044. //产品权限map
  3045. statusMap := make(map[int]string)
  3046. for i := 0; i < itemLen; i++ {
  3047. item := productList[i]
  3048. //添加产品权限map
  3049. statusMap[item.ProductId] = item.Status
  3050. if i == 0 {
  3051. if item.ProductId == 1 {
  3052. resp.CreateAuth = 1
  3053. } else {
  3054. resp.CreateAuth = 2
  3055. }
  3056. }
  3057. if item.ProductId == 1 {
  3058. if strings.Contains(sysUser.RoleTypeCode, "ficc") {
  3059. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  3060. btnDetailItem.BtnHistoryList = true
  3061. } else {
  3062. if item.SellerId == sysUser.AdminId || shareSellerId == sysUser.AdminId {
  3063. btnDetailItem.BtnHistoryList = true
  3064. }
  3065. if sysUser.Authority > 0 {
  3066. if item.GroupId == sysUser.GroupId {
  3067. btnDetailItem.BtnHistoryList = true
  3068. }
  3069. if item.DepartmentId == sysUser.DepartmentId {
  3070. btnDetailItem.BtnHistoryList = true
  3071. }
  3072. }
  3073. }
  3074. }
  3075. for _, v := range utils.PermissionFiccClassifyArr {
  3076. checkList := make([]int, 0)
  3077. plist := new(company.PermissionLookList)
  3078. items, err := company.GetPermissionLookItems(item.ProductId, v)
  3079. if err != nil {
  3080. br.Msg = "获取失败"
  3081. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3082. return
  3083. }
  3084. for itemK, n := range items {
  3085. permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  3086. if err != nil && err.Error() != utils.ErrNoRow() {
  3087. br.Msg = "获取失败"
  3088. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3089. return
  3090. }
  3091. if permission != nil && permission.ChartPermissionId > 0 {
  3092. checkList = append(checkList, n.ChartPermissionId)
  3093. items[itemK].StartDate = permission.StartDate
  3094. items[itemK].EndDate = permission.EndDate
  3095. items[itemK].Status = permission.Status
  3096. endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
  3097. endDateTime = endDateTime.AddDate(0, 0, 1)
  3098. sub := endDateTime.Sub(time.Now())
  3099. if sub < 0 {
  3100. sub = 0
  3101. }
  3102. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  3103. items[itemK].ExpireDay = expireDay
  3104. }
  3105. //count, err := company.GetCompanyPermissionCheck(companyId, n.ChartPermissionId)
  3106. //if err != nil {
  3107. // br.Msg = "获取失败"
  3108. // br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3109. // return
  3110. //}
  3111. //if count > 0 {
  3112. // checkList = append(checkList, n.ChartPermissionId)
  3113. //}
  3114. }
  3115. plist.Items = items
  3116. plist.ClassifyName = v
  3117. plist.CheckList = checkList
  3118. item.PermissionList = append(item.PermissionList, plist)
  3119. }
  3120. resp.FiccItem = item
  3121. if resp.FiccItem.Status == utils.COMPANY_STATUS_FOREVER {
  3122. resp.FiccItem.Status = utils.COMPANY_STATUS_X_CLASS_TRY_OUT
  3123. }
  3124. if (roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  3125. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT) &&
  3126. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3127. resp.IsButtonShow = 1
  3128. }
  3129. } else {
  3130. if strings.Contains(sysUser.RoleTypeCode, "rai") {
  3131. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  3132. btnDetailItem.BtnHistoryList = true
  3133. } else {
  3134. if item.SellerId == sysUser.AdminId {
  3135. btnDetailItem.BtnHistoryList = true
  3136. }
  3137. if sysUser.Authority > 0 {
  3138. if item.GroupId == sysUser.GroupId {
  3139. btnDetailItem.BtnHistoryList = true
  3140. }
  3141. if item.DepartmentId == sysUser.DepartmentId {
  3142. btnDetailItem.BtnHistoryList = true
  3143. }
  3144. }
  3145. }
  3146. }
  3147. // CRM8.8-权益权限列表调用较多、统一进行调整
  3148. plist, e := services.RaiCompanyPermissionAndCheckList(companyId, isEdit)
  3149. if e != nil {
  3150. br.Msg = "获取客户权益权限列表信息失败"
  3151. br.ErrMsg = "获取客户权益权限列表信息失败,Err:" + e.Error()
  3152. return
  3153. }
  3154. // cygx8.2专项产业调研展示
  3155. item.SpecialSurplus, err = cygxService.GetSpecialSurplusByCompanyNew(companyId)
  3156. if err != nil {
  3157. br.Msg = "获取失败"
  3158. br.ErrMsg = "获取专项调研信息失败,Err:" + err.Error()
  3159. return
  3160. }
  3161. //研选服务点数
  3162. item.Points = cygxService.GetCygxActivityPointsCompanyByCompanyId(companyId)
  3163. item.PermissionList = append(item.PermissionList, plist)
  3164. resp.RaiItem = item
  3165. if resp.RaiItem.Status == utils.COMPANY_STATUS_FOREVER {
  3166. resp.RaiItem.Status = utils.COMPANY_STATUS_X_CLASS_TRY_OUT
  3167. }
  3168. if (roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  3169. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  3170. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT) &&
  3171. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3172. resp.IsButtonShow = 1
  3173. }
  3174. }
  3175. 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)
  3176. //if itemLen > 1 {
  3177. // btnDetailItem.BtnEdit = false
  3178. // btnDetailItem.BtnDelete = false
  3179. //} else {
  3180. // btnDetailItem.BtnEdit = btnItem.BtnEdit
  3181. // btnDetailItem.BtnDelete = btnItem.BtnDelete
  3182. //}
  3183. switch item.ProductId {
  3184. case 1:
  3185. btnDetailItem.FiccEdit = btnItem.BtnEdit
  3186. btnDetailItem.FiccDelete = btnItem.BtnDelete
  3187. case 2:
  3188. btnDetailItem.RaiEdit = btnItem.BtnEdit
  3189. btnDetailItem.RaiDelete = btnItem.BtnDelete
  3190. }
  3191. if !btnDetailItem.BtnEdit {
  3192. btnDetailItem.BtnEdit = btnItem.BtnEdit
  3193. }
  3194. if !btnDetailItem.BtnDelete {
  3195. btnDetailItem.BtnDelete = btnItem.BtnDelete
  3196. }
  3197. //联系人操作权限
  3198. if resp.IsContractButtonShow == false {
  3199. resp.IsContractButtonShow = services.CheckCompanyUserButton(sysUser.RoleTypeCode, item.SellerId, sysUser.AdminId, item.ProductId, shareSellerId, item.Status)
  3200. }
  3201. //校验当前操作员是否具给联系人开通个人研选的权限
  3202. if resp.IsUserYanXuanButtonShow == false {
  3203. resp.IsUserYanXuanButtonShow, err = services.CheckCompanyUserYanXuanButton(sysUser.RoleTypeCode, sysUser.Mobile)
  3204. if err != nil {
  3205. br.Msg = "获取失败"
  3206. br.ErrMsg = "获取专项调研信息失败,Err:" + err.Error()
  3207. return
  3208. }
  3209. }
  3210. }
  3211. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  3212. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  3213. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  3214. resp.IsButtonShow = 1
  3215. btnDetailItem.BtnHistoryList = true
  3216. }
  3217. //ficc权限
  3218. if ficcStatus, ok := statusMap[1]; ok {
  3219. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT {
  3220. if raiStatus, ok := statusMap[2]; ok {
  3221. //另一个权限也是 试用 、冻结、流失
  3222. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3223. //那么超管、部门管理员、销售可以编辑
  3224. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3225. btnDetailItem.BaseInfoEdit = true
  3226. }
  3227. }
  3228. //权益是永续时,超管可编辑基础信息
  3229. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3230. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3231. btnDetailItem.BaseInfoEdit = true
  3232. }
  3233. }
  3234. } else {
  3235. //权限未开,有编辑基础信息权限
  3236. btnDetailItem.BaseInfoEdit = true
  3237. }
  3238. }
  3239. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3240. if raiStatus, ok := statusMap[2]; ok {
  3241. //另一个权限也是 永续 、冻结、流失
  3242. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FOREVER || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3243. //超管可编辑基础信息
  3244. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3245. btnDetailItem.BaseInfoEdit = true
  3246. }
  3247. }
  3248. } else {
  3249. //权限未开,有编辑基础信息权限
  3250. btnDetailItem.BaseInfoEdit = true
  3251. }
  3252. }
  3253. }
  3254. //权益销售
  3255. if raiStatus, ok := statusMap[2]; ok {
  3256. if raiStatus == utils.COMPANY_STATUS_TRY_OUT {
  3257. if ficcStatus, ok := statusMap[1]; ok {
  3258. //另一个权限也是 试用 、冻结、流失
  3259. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3260. //那么超管、部门管理员、销售可以编辑
  3261. if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3262. btnDetailItem.BaseInfoEdit = true
  3263. }
  3264. }
  3265. //ficc是永续时,超管可编辑基础信息
  3266. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3267. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3268. btnDetailItem.BaseInfoEdit = true
  3269. }
  3270. }
  3271. } else {
  3272. //权限未开,有编辑基础信息权限
  3273. btnDetailItem.BaseInfoEdit = true
  3274. }
  3275. }
  3276. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3277. if ficcStatus, ok := statusMap[1]; ok {
  3278. //另一个权限也是 试用、永续 、冻结、流失
  3279. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FOREVER || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3280. //超管可编辑基础信息
  3281. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3282. btnDetailItem.BaseInfoEdit = true
  3283. }
  3284. }
  3285. } else {
  3286. //权限未开,有编辑基础信息权限
  3287. btnDetailItem.BaseInfoEdit = true
  3288. }
  3289. }
  3290. }
  3291. // 白嫖客户标记
  3292. scroungeList, err := company.GetScroungeCompany()
  3293. if err != nil {
  3294. br.Msg = "获取失败"
  3295. br.ErrMsg = "获取白嫖客户信息失败,Err:" + err.Error()
  3296. return
  3297. }
  3298. scroungeMap := make(map[int]int)
  3299. for _, v := range scroungeList {
  3300. scroungeMap[v.CompanyId] = 1
  3301. }
  3302. if _, ok := scroungeMap[item.CompanyId]; ok {
  3303. item.IsScrounge = 1
  3304. }
  3305. resp.Item = item
  3306. resp.BtnItem = btnDetailItem
  3307. br.Ret = 200
  3308. br.Success = true
  3309. br.Msg = "获取成功"
  3310. br.Data = resp
  3311. }
  3312. // DetailByCreditCode
  3313. // @Title 根据社会信用码获取客户详情
  3314. // @Description 根据社会信用码获取客户详情接口
  3315. // @Param CreditCode query string true "客户社会信用码"
  3316. // @Success 200 {object} company.CompanyDetailResp
  3317. // @router /detail_by_credit_code [get]
  3318. func (this *CompanyController) DetailByCreditCode() {
  3319. br := new(models.BaseResponse).Init()
  3320. defer func() {
  3321. this.Data["json"] = br
  3322. this.ServeJSON()
  3323. }()
  3324. sysUser := this.SysUser
  3325. if sysUser == nil {
  3326. br.Msg = "请登录"
  3327. br.ErrMsg = "请登录,SysUser Is Empty"
  3328. br.Ret = 408
  3329. return
  3330. }
  3331. resp := new(company.CompanyDetailResp)
  3332. creditCode := this.GetString("CreditCode")
  3333. if creditCode == "" {
  3334. br.Msg = "参数错误"
  3335. br.ErrMsg = "社会信用码必传"
  3336. return
  3337. }
  3338. item, err := company.GetCompanyDetailByCreditCode(creditCode)
  3339. if err != nil {
  3340. br.Ret = 200
  3341. br.Success = true
  3342. br.Msg = "获取成功"
  3343. br.Data = resp
  3344. return
  3345. }
  3346. shareSellerId := item.ShareSellerId
  3347. companyId := item.CompanyId
  3348. var productName string
  3349. productId := services.GetProductId(sysUser.RoleTypeCode)
  3350. if productId == 1 {
  3351. productName = utils.COMPANY_PRODUCT_FICC_NAME
  3352. } else if productId == 2 {
  3353. productName = utils.COMPANY_PRODUCT_RAI_NAME
  3354. } else {
  3355. productName = "admin"
  3356. }
  3357. resp.ProductName = productName
  3358. //获取客户产品
  3359. productList, err := company.GetCompanyProductsByCompanyId(companyId)
  3360. if err != nil {
  3361. br.Msg = "获取信息失败"
  3362. br.ErrMsg = "获取产品信息失败,Err:" + err.Error()
  3363. return
  3364. }
  3365. roleTypeCode := sysUser.RoleTypeCode
  3366. itemLen := len(productList)
  3367. btnDetailItem := new(company.ButtonDetailPermission)
  3368. //产品权限map
  3369. statusMap := make(map[int]string)
  3370. for i := 0; i < itemLen; i++ {
  3371. item := productList[i]
  3372. //添加产品权限map
  3373. statusMap[item.ProductId] = item.Status
  3374. if i == 0 {
  3375. if item.ProductId == 1 {
  3376. resp.CreateAuth = 1
  3377. } else {
  3378. resp.CreateAuth = 2
  3379. }
  3380. }
  3381. if item.ProductId == 1 {
  3382. if strings.Contains(sysUser.RoleTypeCode, "ficc") {
  3383. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  3384. btnDetailItem.BtnHistoryList = true
  3385. } else {
  3386. if item.SellerId == sysUser.AdminId {
  3387. btnDetailItem.BtnHistoryList = true
  3388. }
  3389. if sysUser.Authority > 0 {
  3390. if item.GroupId == sysUser.GroupId {
  3391. btnDetailItem.BtnHistoryList = true
  3392. }
  3393. if item.DepartmentId == sysUser.DepartmentId {
  3394. btnDetailItem.BtnHistoryList = true
  3395. }
  3396. }
  3397. }
  3398. }
  3399. for _, v := range utils.PermissionFiccClassifyArr {
  3400. checkList := make([]int, 0)
  3401. plist := new(company.PermissionLookList)
  3402. items, err := company.GetPermissionLookItems(item.ProductId, v)
  3403. if err != nil {
  3404. br.Msg = "获取失败"
  3405. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3406. return
  3407. }
  3408. for itemK, n := range items {
  3409. permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  3410. if err != nil && err.Error() != utils.ErrNoRow() {
  3411. br.Msg = "获取失败"
  3412. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3413. return
  3414. }
  3415. if permission != nil && permission.ChartPermissionId > 0 {
  3416. checkList = append(checkList, n.ChartPermissionId)
  3417. items[itemK].StartDate = permission.StartDate
  3418. items[itemK].EndDate = permission.EndDate
  3419. items[itemK].Status = permission.Status
  3420. endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
  3421. endDateTime = endDateTime.AddDate(0, 0, 1)
  3422. sub := endDateTime.Sub(time.Now())
  3423. if sub < 0 {
  3424. sub = 0
  3425. }
  3426. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  3427. items[itemK].ExpireDay = expireDay
  3428. }
  3429. //count, err := company.GetCompanyPermissionCheck(companyId, n.ChartPermissionId)
  3430. //if err != nil {
  3431. // br.Msg = "获取失败"
  3432. // br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3433. // return
  3434. //}
  3435. //if count > 0 {
  3436. // checkList = append(checkList, n.ChartPermissionId)
  3437. //}
  3438. }
  3439. plist.Items = items
  3440. plist.ClassifyName = v
  3441. plist.CheckList = checkList
  3442. item.PermissionList = append(item.PermissionList, plist)
  3443. }
  3444. resp.FiccItem = item
  3445. if (roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  3446. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT) &&
  3447. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3448. resp.IsButtonShow = 1
  3449. }
  3450. } else {
  3451. if strings.Contains(sysUser.RoleTypeCode, "rai") {
  3452. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  3453. btnDetailItem.BtnHistoryList = true
  3454. } else {
  3455. if item.SellerId == sysUser.AdminId {
  3456. btnDetailItem.BtnHistoryList = true
  3457. }
  3458. if sysUser.Authority > 0 {
  3459. if item.GroupId == sysUser.GroupId {
  3460. btnDetailItem.BtnHistoryList = true
  3461. }
  3462. if item.DepartmentId == sysUser.DepartmentId {
  3463. btnDetailItem.BtnHistoryList = true
  3464. }
  3465. }
  3466. }
  3467. }
  3468. classifyName := "权益"
  3469. checkList := make([]int, 0)
  3470. plist := new(company.PermissionLookList)
  3471. items, err := company.GetPermissionLookItems(item.ProductId, classifyName)
  3472. if err != nil {
  3473. br.Msg = "获取失败"
  3474. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3475. return
  3476. }
  3477. for itemK, n := range items {
  3478. permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  3479. if err != nil && err.Error() != utils.ErrNoRow() {
  3480. br.Msg = "获取失败"
  3481. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3482. return
  3483. }
  3484. if permission != nil && permission.ChartPermissionId > 0 {
  3485. checkList = append(checkList, n.ChartPermissionId)
  3486. items[itemK].StartDate = permission.StartDate
  3487. items[itemK].EndDate = permission.EndDate
  3488. items[itemK].Status = permission.Status
  3489. endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
  3490. endDateTime = endDateTime.AddDate(0, 0, 1)
  3491. sub := endDateTime.Sub(time.Now())
  3492. if sub < 0 {
  3493. sub = 0
  3494. }
  3495. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  3496. items[itemK].ExpireDay = expireDay
  3497. }
  3498. //count, err := company.GetCompanyPermissionCheck(companyId, n.ChartPermissionId)
  3499. //if err != nil {
  3500. // br.Msg = "获取失败"
  3501. // br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3502. // return
  3503. //}
  3504. //if count > 0 {
  3505. // checkList = append(checkList, n.ChartPermissionId)
  3506. //}
  3507. }
  3508. item.SpecialSurplus, err = cygxService.GetSpecialSurplusByCompanyNew(companyId)
  3509. if err != nil {
  3510. br.Msg = "获取失败"
  3511. br.ErrMsg = "获取专项调研信息失败,Err:" + err.Error()
  3512. return
  3513. }
  3514. plist.Items = items
  3515. plist.ClassifyName = classifyName
  3516. plist.CheckList = checkList
  3517. item.PermissionList = append(item.PermissionList, plist)
  3518. resp.RaiItem = item
  3519. if (roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  3520. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  3521. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT) &&
  3522. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3523. resp.IsButtonShow = 1
  3524. }
  3525. }
  3526. 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)
  3527. //if itemLen > 1 {
  3528. // btnDetailItem.BtnEdit = false
  3529. // btnDetailItem.BtnDelete = false
  3530. //} else {
  3531. // btnDetailItem.BtnEdit = btnItem.BtnEdit
  3532. // btnDetailItem.BtnDelete = btnItem.BtnDelete
  3533. //}
  3534. switch item.ProductId {
  3535. case 1:
  3536. btnDetailItem.FiccEdit = btnItem.BtnEdit
  3537. btnDetailItem.FiccDelete = btnItem.BtnDelete
  3538. case 2:
  3539. btnDetailItem.RaiEdit = btnItem.BtnEdit
  3540. btnDetailItem.RaiDelete = btnItem.BtnDelete
  3541. }
  3542. if !btnDetailItem.BtnEdit {
  3543. btnDetailItem.BtnEdit = btnItem.BtnEdit
  3544. }
  3545. if !btnDetailItem.BtnDelete {
  3546. btnDetailItem.BtnDelete = btnItem.BtnDelete
  3547. }
  3548. //联系人操作权限
  3549. if resp.IsContractButtonShow == false {
  3550. resp.IsContractButtonShow = services.CheckCompanyUserButton(sysUser.RoleTypeCode, item.SellerId, sysUser.AdminId, item.ProductId, shareSellerId, item.Status)
  3551. }
  3552. }
  3553. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  3554. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  3555. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  3556. resp.IsButtonShow = 1
  3557. btnDetailItem.BtnHistoryList = true
  3558. }
  3559. //ficc权限
  3560. if ficcStatus, ok := statusMap[1]; ok {
  3561. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT {
  3562. if raiStatus, ok := statusMap[2]; ok {
  3563. //另一个权限也是 试用 、冻结、流失
  3564. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3565. //那么超管、部门管理员、销售可以编辑
  3566. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3567. btnDetailItem.BaseInfoEdit = true
  3568. }
  3569. }
  3570. //权益是永续时,超管可编辑基础信息
  3571. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3572. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3573. btnDetailItem.BaseInfoEdit = true
  3574. }
  3575. }
  3576. } else {
  3577. //权限未开,有编辑基础信息权限
  3578. btnDetailItem.BaseInfoEdit = true
  3579. }
  3580. }
  3581. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3582. if raiStatus, ok := statusMap[2]; ok {
  3583. //另一个权限也是 永续 、冻结、流失
  3584. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FOREVER || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3585. //超管可编辑基础信息
  3586. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3587. btnDetailItem.BaseInfoEdit = true
  3588. }
  3589. }
  3590. } else {
  3591. //权限未开,有编辑基础信息权限
  3592. btnDetailItem.BaseInfoEdit = true
  3593. }
  3594. }
  3595. }
  3596. //权益销售
  3597. if raiStatus, ok := statusMap[2]; ok {
  3598. if raiStatus == utils.COMPANY_STATUS_TRY_OUT {
  3599. if ficcStatus, ok := statusMap[1]; ok {
  3600. //另一个权限也是 试用 、冻结、流失
  3601. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3602. //那么超管、部门管理员、销售可以编辑
  3603. if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3604. btnDetailItem.BaseInfoEdit = true
  3605. }
  3606. }
  3607. //ficc是永续时,超管可编辑基础信息
  3608. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3609. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3610. btnDetailItem.BaseInfoEdit = true
  3611. }
  3612. }
  3613. } else {
  3614. //权限未开,有编辑基础信息权限
  3615. btnDetailItem.BaseInfoEdit = true
  3616. }
  3617. }
  3618. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3619. if ficcStatus, ok := statusMap[1]; ok {
  3620. //另一个权限也是 试用、永续 、冻结、流失
  3621. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FOREVER || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3622. //超管可编辑基础信息
  3623. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3624. btnDetailItem.BaseInfoEdit = true
  3625. }
  3626. }
  3627. } else {
  3628. //权限未开,有编辑基础信息权限
  3629. btnDetailItem.BaseInfoEdit = true
  3630. }
  3631. }
  3632. }
  3633. resp.Item = item
  3634. resp.BtnItem = btnDetailItem
  3635. br.Ret = 200
  3636. br.Success = true
  3637. br.Msg = "获取成功"
  3638. br.Data = resp
  3639. }
  3640. // @Title 编辑客户
  3641. // @Description 编辑客户接口
  3642. // @Param request body company.CompanyEditReq true "type json string"
  3643. // @Success Ret=200 保存成功
  3644. // @router /edit [post]
  3645. func (this *CompanyController) Edit() {
  3646. br := new(models.BaseResponse).Init()
  3647. defer func() {
  3648. this.Data["json"] = br
  3649. this.ServeJSON()
  3650. }()
  3651. sysUser := this.SysUser
  3652. if sysUser == nil {
  3653. br.Msg = "请登录"
  3654. br.ErrMsg = "请登录,SysUser Is Empty"
  3655. br.Ret = 408
  3656. return
  3657. }
  3658. //roleTypeCode := sysUser.RoleTypeCode
  3659. var req company.CompanyEditReq
  3660. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3661. if err != nil {
  3662. br.Msg = "参数解析异常!"
  3663. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3664. return
  3665. }
  3666. if req.CompanyId <= 0 {
  3667. br.Msg = "参数异常!"
  3668. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  3669. return
  3670. }
  3671. if req.CompanyName == "" {
  3672. br.Msg = "请填写客户名称"
  3673. return
  3674. }
  3675. if req.CreditCode == "" {
  3676. br.Msg = "请填写社会统一信用码"
  3677. return
  3678. }
  3679. //移除空格
  3680. req.CreditCode = utils.TrimStr(req.CreditCode)
  3681. productId := services.GetProductId(sysUser.RoleTypeCode) //产品权限id
  3682. for _, v := range req.Products {
  3683. if v.IndustryId <= 0 {
  3684. br.Msg = "请选择行业"
  3685. br.IsSendEmail = false
  3686. return
  3687. }
  3688. //获取客户产品信息
  3689. productItem, err := company.GetCompanyProductById(v.CompanyProductId)
  3690. if err != nil {
  3691. br.Msg = "数据获取失败!"
  3692. br.ErrMsg = "数据获取失败,Err:" + err.Error()
  3693. return
  3694. }
  3695. if productItem == nil {
  3696. br.Msg = "客户信息不存在!"
  3697. return
  3698. }
  3699. // 如果本身是有权限归属的,同时传入的参数不是当前账号权限的,那么过滤该次循环,进入下次循环
  3700. if productId > 0 && productItem.ProductId != productId {
  3701. continue
  3702. }
  3703. if v.Status == "" {
  3704. br.Msg = "客户状态不可为空"
  3705. return
  3706. }
  3707. //if v.Reasons == "" {
  3708. // br.Msg = "请填写新增理由"
  3709. // return
  3710. //}
  3711. if v.PermissionIds == "" {
  3712. br.Msg = "请选择权限"
  3713. return
  3714. }
  3715. var startDate, endDate string
  3716. startDate = productItem.StartDate
  3717. endDate = productItem.EndDate
  3718. if startDate == "" || endDate == "" {
  3719. br.Msg = "数据错误"
  3720. br.Msg = "数据错误,开始或结束日期为空:startDate:" + startDate + "endDate:" + endDate
  3721. return
  3722. }
  3723. //判断客户是否已经存在
  3724. companyNameIsExist, err := company.GetCompanyCountByCompanyNameAndCompanyId(req.CompanyId, req.CompanyName)
  3725. if err != nil {
  3726. br.Msg = "判断客户是否存在失败"
  3727. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  3728. return
  3729. }
  3730. if companyNameIsExist > 0 {
  3731. br.Msg = "客户已存在,请重新输入客户名称"
  3732. return
  3733. }
  3734. //判断客户是否已经存在
  3735. companyCreditCodeIsExist, err := company.GetCompanyCountByCreditCodeAndCompanyId(req.CompanyId, req.CreditCode)
  3736. if err != nil {
  3737. br.Msg = "判断客户是否存在失败"
  3738. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  3739. return
  3740. }
  3741. if companyCreditCodeIsExist > 0 {
  3742. br.Msg = "客户已存在,请重新输入统一社会信用代码"
  3743. return
  3744. }
  3745. seller, err := system.GetSysAdminById(v.SellsId)
  3746. if err != nil {
  3747. br.Msg = "获取销售信息失败"
  3748. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  3749. return
  3750. }
  3751. if seller == nil {
  3752. br.Msg = "所属销售不存在"
  3753. return
  3754. }
  3755. //tryOutCount, err := company.GetCompanyTryOutCount(utils.COMPANY_STATUS_TRY_OUT, seller.AdminId)
  3756. //if err != nil {
  3757. // br.Msg = "判断试用客户量失败"
  3758. // br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  3759. // return
  3760. //}
  3761. //if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
  3762. // roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  3763. // if tryOutCount >= utils.COMPANY_STATUS_TRY_OUT_COUNT && v.SellsId == sysUser.AdminId {
  3764. // br.Msg = "您的试用客户总数,已超过上限,不可继续新增"
  3765. // return
  3766. // }
  3767. //}
  3768. industry, err := company.GetCompanyIndustryById(v.IndustryId)
  3769. if err != nil {
  3770. br.Msg = "获取行业信息失败"
  3771. br.ErrMsg = "获取行业信息失败,Err:" + err.Error()
  3772. return
  3773. }
  3774. companyProduct := new(company.CompanyProduct)
  3775. companyProduct.ProductId = productItem.ProductId
  3776. companyProduct.CompanyId = req.CompanyId
  3777. companyProduct.CompanyName = req.CompanyName
  3778. companyProduct.Source = v.Source
  3779. companyProduct.Reasons = v.Reasons
  3780. companyProduct.Status = v.Status
  3781. companyProduct.StartDate = startDate
  3782. companyProduct.EndDate = endDate
  3783. companyProduct.IndustryId = v.IndustryId
  3784. companyProduct.IndustryName = industry.IndustryName
  3785. companyProduct.SellerId = seller.AdminId
  3786. companyProduct.SellerName = seller.RealName
  3787. companyProduct.GroupId = seller.GroupId
  3788. companyProduct.DepartmentId = seller.DepartmentId
  3789. companyProduct.IsSuspend = 0
  3790. companyProduct.ModifyTime = time.Now()
  3791. companyProduct.CompanyProductId = v.CompanyProductId
  3792. companyProduct.Scale = v.Scale
  3793. err = company.ModifyCompanyProduct(companyProduct)
  3794. if err != nil {
  3795. br.Msg = "修改客户信息失败"
  3796. br.ErrMsg = "修改客户产品信息失败,Err:" + err.Error()
  3797. return
  3798. }
  3799. // CRM8.8-下面的需求取消, 编辑的时候根据选择开通对应权限
  3800. // 如果是权益客户,编辑的时候开通主观客观权限
  3801. //if v.CompanyType == utils.COMPANY_CLASSIFY_RAI {
  3802. // permissionStr, err := company.GetPermissionIdById(v.PermissionIds)
  3803. // if err != nil {
  3804. // br.Msg = "修改失败"
  3805. // br.ErrMsg = "获取主观客观权限信息失败,Err:" + err.Error()
  3806. // return
  3807. // }
  3808. // v.PermissionIds = permissionStr
  3809. //}
  3810. //处理权限
  3811. companyReportPermissionList, err := services.AddCompanyPermission(req.CompanyId, seller.AdminId, productItem.ProductId, productItem.ProductName, seller.RealName, v.PermissionIds, startDate, endDate)
  3812. if err != nil {
  3813. br.Msg = "修改失败"
  3814. br.ErrMsg = "新增客户设置权限失败,err:" + err.Error()
  3815. return
  3816. }
  3817. //新增操作记录
  3818. {
  3819. record := new(company.CompanyOperationRecord)
  3820. record.CompanyId = req.CompanyId
  3821. record.CompanyName = req.CompanyName
  3822. record.SellerId = companyProduct.SellerId
  3823. record.SysUserId = this.SysUser.AdminId
  3824. record.SysRealName = this.SysUser.RealName
  3825. record.Remark = "编辑客户"
  3826. record.Operation = "edit"
  3827. record.CreateTime = time.Now()
  3828. record.ProductId = productItem.ProductId
  3829. record.ProductName = productItem.ProductName
  3830. record.Status = productItem.Status
  3831. _, err = company.AddCompanyOperationRecord(record)
  3832. if err != nil {
  3833. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  3834. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  3835. }
  3836. }
  3837. //新增客户产品日志
  3838. {
  3839. productLog := new(company.CompanyProductLog)
  3840. productLog.CompanyProductId = v.CompanyProductId
  3841. productLog.CompanyId = companyProduct.CompanyId
  3842. productLog.ProductId = companyProduct.ProductId
  3843. productLog.ProductName = companyProduct.ProductName
  3844. productLog.CompanyName = companyProduct.CompanyName
  3845. productLog.CompanyName = companyProduct.CompanyName
  3846. productLog.Source = companyProduct.Source
  3847. productLog.Reasons = companyProduct.Reasons
  3848. productLog.Status = companyProduct.Status
  3849. productLog.IndustryId = companyProduct.IndustryId
  3850. productLog.IndustryName = companyProduct.IndustryName
  3851. productLog.SellerId = companyProduct.SellerId
  3852. productLog.SellerName = companyProduct.SellerName
  3853. productLog.GroupId = companyProduct.GroupId
  3854. productLog.DepartmentId = companyProduct.DepartmentId
  3855. productLog.IsSuspend = companyProduct.IsSuspend
  3856. productLog.SuspendTime = companyProduct.SuspendTime
  3857. productLog.ApproveStatus = companyProduct.ApproveStatus
  3858. productLog.FreezeTime = companyProduct.FreezeTime
  3859. productLog.Remark = companyProduct.Remark
  3860. productLog.StartDate = companyProduct.StartDate
  3861. productLog.EndDate = companyProduct.EndDate
  3862. productLog.CreateTime = companyProduct.CreateTime
  3863. productLog.ModifyTime = companyProduct.ModifyTime
  3864. productLog.LoseReason = companyProduct.LoseReason
  3865. productLog.LossTime = companyProduct.LossTime
  3866. productLog.LogType = "modify"
  3867. productLog.LogCreateTime = time.Now()
  3868. productLog.AdminId = this.SysUser.AdminId
  3869. productLog.Scale = companyProduct.Scale
  3870. go company.AddCompanyProductLog(productLog)
  3871. }
  3872. //新增客户产品状态变更日志
  3873. {
  3874. startDateTime, _ := time.ParseInLocation(utils.FormatDate, startDate, time.Local)
  3875. endDateTime, _ := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
  3876. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  3877. Id: 0,
  3878. CompanyId: req.CompanyId,
  3879. ProductId: productId,
  3880. Status: "试用",
  3881. Source: "edit",
  3882. SellerId: seller.AdminId,
  3883. SellerName: seller.RealName,
  3884. StartDate: startDateTime,
  3885. EndDate: endDateTime,
  3886. RealEndDate: startDateTime,
  3887. CreateTime: time.Now(),
  3888. }
  3889. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  3890. // 添加试用记录
  3891. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  3892. Id: 0,
  3893. CompanyId: req.CompanyId,
  3894. ProductId: productId,
  3895. Source: "edit",
  3896. SellerId: seller.AdminId,
  3897. SellerName: seller.RealName,
  3898. StartDate: startDateTime,
  3899. EndDate: endDateTime,
  3900. RealEndDate: startDateTime,
  3901. IsStop: 0,
  3902. CreateTime: time.Now(),
  3903. }
  3904. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  3905. }
  3906. }
  3907. companyItem := new(company.Company)
  3908. companyItem.CompanyId = req.CompanyId
  3909. companyItem.CompanyName = req.CompanyName
  3910. companyItem.CreditCode = req.CreditCode
  3911. companyItem.Province = req.Province
  3912. companyItem.City = req.City
  3913. companyItem.Address = req.Province + req.City
  3914. companyItem.LastUpdatedTime = time.Now()
  3915. companyItem.Enabled = 1
  3916. companyItem.Nation = req.Nation
  3917. err = company.ModifyCompany(companyItem)
  3918. if err != nil {
  3919. br.Msg = "修改客户信息失败"
  3920. br.ErrMsg = "修改客户信息失败,Err:" + err.Error()
  3921. return
  3922. }
  3923. //新增客户日志
  3924. {
  3925. companyLog := new(company.CompanyLog)
  3926. companyLog.CompanyId = req.CompanyId
  3927. companyLog.CompanyName = req.CompanyName
  3928. companyLog.CreditCode = req.CreditCode
  3929. companyLog.Address = companyItem.Address
  3930. companyLog.City = companyItem.City
  3931. companyLog.Province = companyItem.Province
  3932. companyLog.LastUpdatedTime = companyItem.LastUpdatedTime
  3933. companyLog.AdminId = this.SysUser.AdminId
  3934. companyLog.LogType = "modify"
  3935. companyLog.LogCreateTime = time.Now()
  3936. go company.AddCompanyLog(companyLog)
  3937. }
  3938. br.Ret = 200
  3939. br.Success = true
  3940. br.Msg = "保存成功"
  3941. }
  3942. // @Title 编辑补充客户信息接口
  3943. // @Description 编辑补充客户信息接口
  3944. // @Param request body company.CompanyInfoEditReq true "type json string"
  3945. // @Success Ret=200 保存成功
  3946. // @router /company_info/edit [post]
  3947. func (this *CompanyController) EditCompanyInfo() {
  3948. br := new(models.BaseResponse).Init()
  3949. defer func() {
  3950. this.Data["json"] = br
  3951. this.ServeJSON()
  3952. }()
  3953. sysUser := this.SysUser
  3954. if sysUser == nil {
  3955. br.Msg = "请登录"
  3956. br.ErrMsg = "请登录,SysUser Is Empty"
  3957. br.Ret = 408
  3958. return
  3959. }
  3960. var req company.CompanyInfoEditReq
  3961. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3962. if err != nil {
  3963. br.Msg = "参数解析异常!"
  3964. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3965. return
  3966. }
  3967. if req.CompanyId <= 0 {
  3968. br.Msg = "参数异常!"
  3969. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  3970. return
  3971. }
  3972. if req.CompanyName == "" {
  3973. br.Msg = "请填写客户名称"
  3974. return
  3975. }
  3976. if req.CreditCode == "" {
  3977. br.Msg = "请填写社会统一信用码"
  3978. return
  3979. }
  3980. //if req.Province == "" {
  3981. // br.Msg = "请选择省份"
  3982. // return
  3983. //}
  3984. //if req.City == "" {
  3985. // br.Msg = "请选择市区"
  3986. // return
  3987. //}
  3988. //if req.IndustryId <= 0 {
  3989. // br.Msg = "请选择所属行业"
  3990. // return
  3991. //}
  3992. //if req.IndustryName == "" {
  3993. // br.Msg = "请选择所属行业"
  3994. // return
  3995. //}
  3996. //if req.Source == "" {
  3997. // br.Msg = "请选择来源"
  3998. // return
  3999. //}
  4000. //移除空格
  4001. req.CreditCode = utils.TrimStr(req.CreditCode)
  4002. //获取产品权限
  4003. productId := services.GetProductId(sysUser.RoleTypeCode)
  4004. if productId <= 0 {
  4005. br.Msg = "当前账号不允许修改客户信息"
  4006. return
  4007. }
  4008. companyNameIsExist, err := company.GetCompanyCountByCompanyNameAndCompanyId(req.CompanyId, req.CompanyName)
  4009. if err != nil {
  4010. br.Msg = "判断客户是否存在失败"
  4011. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  4012. return
  4013. }
  4014. if companyNameIsExist > 0 {
  4015. br.Msg = "客户已存在,请重新输入客户名称"
  4016. return
  4017. }
  4018. //判断客户是否已经存在
  4019. companyCreditCodeIsExist, err := company.GetCompanyCountByCreditCodeAndCompanyId(req.CompanyId, req.CreditCode)
  4020. if err != nil {
  4021. br.Msg = "判断客户是否存在失败"
  4022. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  4023. return
  4024. }
  4025. if companyCreditCodeIsExist > 0 {
  4026. br.Msg = "客户已存在,统一社会信用代码"
  4027. return
  4028. }
  4029. //查询该客户
  4030. companyItem, err := company.GetCompanyById(req.CompanyId)
  4031. if err != nil {
  4032. br.Msg = "查找客户失败"
  4033. br.ErrMsg = "查找客户失败,Err:" + err.Error()
  4034. return
  4035. }
  4036. //待更新字段
  4037. updateCol := make([]string, 0)
  4038. companyItem.CompanyName = req.CompanyName
  4039. companyItem.CreditCode = req.CreditCode
  4040. companyItem.Enabled = 1
  4041. companyItem.LastUpdatedTime = time.Now()
  4042. updateCol = append(updateCol, "CompanyName", "CreditCode", "Enabled", "LastUpdatedTime")
  4043. if req.Province != "" && req.City != "" {
  4044. companyItem.Province = req.Province
  4045. companyItem.City = req.City
  4046. companyItem.Address = req.Province + req.City
  4047. updateCol = append(updateCol, "Province", "City", "Address")
  4048. }
  4049. err = companyItem.Update(updateCol)
  4050. if err != nil {
  4051. br.Msg = "修改客户信息失败"
  4052. br.ErrMsg = "修改客户信息失败,Err:" + err.Error()
  4053. return
  4054. }
  4055. //查询并更新客户产品信息
  4056. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  4057. if err != nil {
  4058. if err.Error() != utils.ErrNoRow() {
  4059. br.Msg = "查询客户产品信息失败"
  4060. br.ErrMsg = "查询客户产品信息失败,Err:" + err.Error()
  4061. return
  4062. }
  4063. } else {
  4064. if companyProduct != nil {
  4065. //客户产品待更新字段
  4066. updateCompanyProductCol := make([]string, 0)
  4067. //产品信息(来源、行业)
  4068. if req.IndustryId != 0 && req.IndustryId != companyProduct.IndustryId {
  4069. companyProduct.IndustryId = req.IndustryId
  4070. companyProduct.IndustryName = req.IndustryName
  4071. updateCompanyProductCol = append(updateCompanyProductCol, "IndustryId", "IndustryName")
  4072. }
  4073. if req.Source != "" && req.Source != companyProduct.Source {
  4074. companyProduct.Source = req.Source
  4075. updateCompanyProductCol = append(updateCompanyProductCol, "Source")
  4076. }
  4077. //更新客户产品信息
  4078. if len(updateCompanyProductCol) > 0 {
  4079. err = companyProduct.Update(updateCompanyProductCol)
  4080. if err != nil {
  4081. br.Msg = "修改客户信息失败"
  4082. br.ErrMsg = "修改客户信息失败,Err:" + err.Error()
  4083. return
  4084. }
  4085. }
  4086. }
  4087. }
  4088. //新增客户日志
  4089. {
  4090. companyLog := new(company.CompanyLog)
  4091. companyLog.CompanyId = req.CompanyId
  4092. companyLog.CompanyName = req.CompanyName
  4093. companyLog.CreditCode = req.CreditCode
  4094. companyLog.Address = companyItem.Address
  4095. companyLog.City = companyItem.City
  4096. companyLog.Province = companyItem.Province
  4097. companyLog.LastUpdatedTime = companyItem.LastUpdatedTime
  4098. companyLog.AdminId = this.SysUser.AdminId
  4099. companyLog.LogType = "modify"
  4100. companyLog.LogCreateTime = time.Now()
  4101. go company.AddCompanyLog(companyLog)
  4102. }
  4103. br.Ret = 200
  4104. br.Success = true
  4105. br.Msg = "保存成功"
  4106. }
  4107. // @Title 客户模糊检索(新增/编辑客户页面试用)
  4108. // @Description 客户模糊检索接口(新增/编辑客户页面试用)
  4109. // @Param KeyWord query string true "搜索关键词"
  4110. // @Success 200 {object} company.CompanyFuzzySearchReq
  4111. // @router /fuzzy/search [get]
  4112. func (this *CompanyController) FuzzySearch() {
  4113. br := new(models.BaseResponse).Init()
  4114. defer func() {
  4115. this.Data["json"] = br
  4116. this.ServeJSON()
  4117. }()
  4118. keyWord := this.GetString("KeyWord")
  4119. list, err := company.GetCompanyFuzzySearch(keyWord)
  4120. if err != nil {
  4121. br.Msg = "获取信息失败"
  4122. br.ErrMsg = "获取信息失败,err:" + err.Error()
  4123. return
  4124. }
  4125. resp := new(company.CompanyFuzzySearchReq)
  4126. resp.List = list
  4127. br.Ret = 200
  4128. br.Success = true
  4129. br.Msg = "获取成功"
  4130. br.Data = resp
  4131. }
  4132. // @Title 删除客户
  4133. // @Description 删除客户接口
  4134. // @Param request body company.DeletePptReq true "type json string"
  4135. // @Success Ret=200 保存成功
  4136. // @router /delete [post]
  4137. func (this *CompanyController) Delete() {
  4138. br := new(models.BaseResponse).Init()
  4139. defer func() {
  4140. this.Data["json"] = br
  4141. this.ServeJSON()
  4142. }()
  4143. sysUser := this.SysUser
  4144. if sysUser == nil {
  4145. br.Msg = "请登录"
  4146. br.ErrMsg = "请登录,SysUser Is Empty"
  4147. br.Ret = 408
  4148. return
  4149. }
  4150. var req company.DeletePptReq
  4151. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4152. if err != nil {
  4153. br.Msg = "参数解析异常!"
  4154. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4155. return
  4156. }
  4157. if req.CompanyId <= 0 {
  4158. br.Msg = "参数错误"
  4159. br.ErrMsg = "客户ID小于等于0"
  4160. return
  4161. }
  4162. roleTypeCode := this.SysUser.RoleTypeCode
  4163. productId := services.GetProductId(roleTypeCode)
  4164. productItems, err := company.GetCompanyProductsByCompanyId(req.CompanyId)
  4165. if err != nil {
  4166. br.Msg = "删除失败"
  4167. br.ErrMsg = "获取客户产品信息失败,Err:" + err.Error()
  4168. return
  4169. }
  4170. // 备份信息
  4171. companyDeleteBakInfo := services.CompanyDeleteBakInfo{
  4172. CompanyId: req.CompanyId,
  4173. CompanyName: "",
  4174. CompanyInfo: &company.Company{},
  4175. CompanyProductInfo: make([]*company.CompanyProduct, 0),
  4176. CompanyPermissionInfo: make([]*company.CompanyReportPermission, 0),
  4177. UserSellerRelationInfo: make([]*models.UserSellerRelation, 0),
  4178. UserRecordInfo: make([]*models.UserRecord, 0),
  4179. UserInfo: make([]*models.WxUser, 0),
  4180. CompanyChartPermissionInfo: make([]*company_user.ChartClassifyPermission, 0),
  4181. OpUserId: this.SysUser.AdminId,
  4182. OpUserName: this.SysUser.RealName,
  4183. }
  4184. if productId == 0 {
  4185. for _, v := range productItems {
  4186. //永续,试用,流失,关闭
  4187. 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 {
  4188. br.Msg = "该客户" + v.ProductName + "属性为" + v.Status + ",暂不可删除"
  4189. br.ErrMsg = "该客户" + v.ProductName + "属性为" + v.Status + ",暂不可删除"
  4190. return
  4191. }
  4192. companyProductList, companyReportPermissionList, err := company.DeleteCompanyProductById(v.CompanyId, v.ProductId, v.CompanyProductId)
  4193. if err != nil {
  4194. br.Msg = "删除失败"
  4195. br.ErrMsg = "删除失败,Err:" + err.Error()
  4196. return
  4197. }
  4198. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductList...)
  4199. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissionList...)
  4200. //新增操作记录
  4201. {
  4202. record := new(company.CompanyOperationRecord)
  4203. record.CompanyId = req.CompanyId
  4204. record.CompanyName = v.CompanyName
  4205. record.SellerId = v.SellerId
  4206. record.SysUserId = this.SysUser.AdminId
  4207. record.SysRealName = this.SysUser.RealName
  4208. record.Remark = "删除客户"
  4209. record.Operation = "delete"
  4210. record.CreateTime = time.Now()
  4211. record.ProductId = v.ProductId
  4212. record.ProductName = v.ProductName
  4213. _, err = company.AddCompanyOperationRecord(record)
  4214. if err != nil {
  4215. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  4216. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  4217. }
  4218. }
  4219. //删除对应产品的联系人
  4220. userSellerRelationList, userRecordList, wxUserList, chartClassifyPermission, _ := services.DeleteCompanyWxUserByProductId(v.CompanyId, v.ProductId)
  4221. //备份信息
  4222. {
  4223. if companyProductList != nil {
  4224. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductList...)
  4225. }
  4226. if companyReportPermissionList != nil {
  4227. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissionList...)
  4228. }
  4229. if userSellerRelationList != nil {
  4230. companyDeleteBakInfo.UserSellerRelationInfo = append(companyDeleteBakInfo.UserSellerRelationInfo, userSellerRelationList...)
  4231. }
  4232. if userRecordList != nil {
  4233. companyDeleteBakInfo.UserRecordInfo = append(companyDeleteBakInfo.UserRecordInfo, userRecordList...)
  4234. }
  4235. if wxUserList != nil {
  4236. companyDeleteBakInfo.UserInfo = append(companyDeleteBakInfo.UserInfo, wxUserList...)
  4237. }
  4238. if chartClassifyPermission != nil {
  4239. companyDeleteBakInfo.CompanyChartPermissionInfo = append(companyDeleteBakInfo.CompanyChartPermissionInfo, chartClassifyPermission...)
  4240. }
  4241. companyDeleteBakInfo.CompanyName = v.CompanyName
  4242. }
  4243. }
  4244. } else {
  4245. productObj, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  4246. if err != nil {
  4247. br.ErrMsg = "获取客户产品信息失败,Err:" + err.Error()
  4248. br.Msg = "删除失败"
  4249. return
  4250. }
  4251. //永续,试用,流失,关闭
  4252. 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 {
  4253. br.Msg = "该客户" + productObj.ProductName + "属性为" + productObj.Status + ",暂不可删除"
  4254. br.ErrMsg = "该客户" + productObj.ProductName + "属性为" + productObj.Status + ",暂不可删除"
  4255. return
  4256. }
  4257. companyProductList, companyReportPermissionList, err := company.DeleteCompanyProductById(productObj.CompanyId, productObj.ProductId, productObj.CompanyProductId)
  4258. if err != nil {
  4259. br.Msg = "删除失败"
  4260. br.ErrMsg = "删除失败,Err:" + err.Error()
  4261. return
  4262. }
  4263. //新增操作记录
  4264. {
  4265. record := new(company.CompanyOperationRecord)
  4266. record.CompanyId = req.CompanyId
  4267. record.CompanyName = productObj.CompanyName
  4268. record.SellerId = productObj.SellerId
  4269. record.SysUserId = this.SysUser.AdminId
  4270. record.SysRealName = this.SysUser.RealName
  4271. record.Remark = "删除客户"
  4272. record.Operation = "delete"
  4273. record.CreateTime = time.Now()
  4274. record.ProductId = productObj.ProductId
  4275. record.ProductName = productObj.ProductName
  4276. _, err = company.AddCompanyOperationRecord(record)
  4277. if err != nil {
  4278. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  4279. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  4280. }
  4281. }
  4282. //删除对应产品的联系人
  4283. userSellerRelationList, userRecordList, wxUserList, chartClassifyPermission, _ := services.DeleteCompanyWxUserByProductId(productObj.CompanyId, productId)
  4284. //备份信息
  4285. {
  4286. if companyProductList != nil {
  4287. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductList...)
  4288. }
  4289. if companyReportPermissionList != nil {
  4290. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissionList...)
  4291. }
  4292. if userSellerRelationList != nil {
  4293. companyDeleteBakInfo.UserSellerRelationInfo = append(companyDeleteBakInfo.UserSellerRelationInfo, userSellerRelationList...)
  4294. }
  4295. if userRecordList != nil {
  4296. companyDeleteBakInfo.UserRecordInfo = append(companyDeleteBakInfo.UserRecordInfo, userRecordList...)
  4297. }
  4298. if wxUserList != nil {
  4299. companyDeleteBakInfo.UserInfo = append(companyDeleteBakInfo.UserInfo, wxUserList...)
  4300. }
  4301. if chartClassifyPermission != nil {
  4302. companyDeleteBakInfo.CompanyChartPermissionInfo = append(companyDeleteBakInfo.CompanyChartPermissionInfo, chartClassifyPermission...)
  4303. }
  4304. companyDeleteBakInfo.CompanyName = productObj.CompanyName
  4305. }
  4306. }
  4307. productItemsNew, err := company.GetCompanyProductsByCompanyId(req.CompanyId)
  4308. if err != nil {
  4309. br.Msg = "删除失败"
  4310. br.ErrMsg = "获取客户产品信息失败,Err:" + err.Error()
  4311. return
  4312. }
  4313. if len(productItemsNew) == 0 {
  4314. //删除之前查询的数据信息
  4315. {
  4316. companyProductLists, companyReportPermissions, wxUsers, userSellerRelations, companyContracts, companyContractPermissions, companyInfo, _ := services.GetBeforeDeleteCompanyInfo(req.CompanyId)
  4317. //companyDeleteBakInfo
  4318. if companyProductLists != nil {
  4319. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductLists...)
  4320. }
  4321. if companyReportPermissions != nil {
  4322. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissions...)
  4323. }
  4324. if wxUsers != nil {
  4325. companyDeleteBakInfo.UserInfo = append(companyDeleteBakInfo.UserInfo, wxUsers...)
  4326. }
  4327. if userSellerRelations != nil {
  4328. companyDeleteBakInfo.UserSellerRelationInfo = append(companyDeleteBakInfo.UserSellerRelationInfo, userSellerRelations...)
  4329. }
  4330. if companyContracts != nil {
  4331. companyDeleteBakInfo.CompanyContract = append(companyDeleteBakInfo.CompanyContract, companyContracts...)
  4332. }
  4333. if companyContractPermissions != nil {
  4334. companyDeleteBakInfo.CompanyContractPermission = append(companyDeleteBakInfo.CompanyContractPermission, companyContractPermissions...)
  4335. }
  4336. if companyInfo != nil {
  4337. companyDeleteBakInfo.CompanyName = companyInfo.CompanyName
  4338. companyDeleteBakInfo.CompanyInfo = companyInfo
  4339. }
  4340. }
  4341. err = company.DeleteCompanyById(req.CompanyId)
  4342. if err != nil {
  4343. br.Msg = "删除失败"
  4344. br.ErrMsg = "删除失败,Err:" + err.Error()
  4345. return
  4346. }
  4347. for _, v := range productItems {
  4348. //新增操作记录
  4349. {
  4350. record := new(company.CompanyOperationRecord)
  4351. record.CompanyId = req.CompanyId
  4352. record.CompanyName = v.CompanyName
  4353. record.SellerId = v.SellerId
  4354. record.SysUserId = this.SysUser.AdminId
  4355. record.SysRealName = this.SysUser.RealName
  4356. record.Remark = "删除客户"
  4357. record.Operation = "delete"
  4358. record.CreateTime = time.Now()
  4359. record.ProductId = v.ProductId
  4360. record.ProductName = v.ProductName
  4361. _, err = company.AddCompanyOperationRecord(record)
  4362. if err != nil {
  4363. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  4364. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  4365. }
  4366. }
  4367. }
  4368. }
  4369. //数据备份入库
  4370. {
  4371. companyInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyInfo)
  4372. companyProductInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyProductInfo)
  4373. companyPermissionInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyPermissionInfo)
  4374. userSellerRelationInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.UserSellerRelationInfo)
  4375. userRecordInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.UserRecordInfo)
  4376. userInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.UserInfo)
  4377. companyChartPermissionInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyChartPermissionInfo)
  4378. companyContractByte, _ := json.Marshal(companyDeleteBakInfo.CompanyContract)
  4379. companyContractPermissionJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyContractPermission)
  4380. companyDeleteBak := &company.CompanyDeleteBak{
  4381. //DeleteBakId: 0,
  4382. CompanyId: companyDeleteBakInfo.CompanyId,
  4383. CompanyName: companyDeleteBakInfo.CompanyName,
  4384. CompanyInfo: string(companyInfoJsonByte),
  4385. CompanyProductInfo: string(companyProductInfoJsonByte),
  4386. CompanyPermissionInfo: string(companyPermissionInfoJsonByte),
  4387. UserSellerRelationInfo: string(userSellerRelationInfoJsonByte),
  4388. UserRecordInfo: string(userRecordInfoJsonByte),
  4389. UserInfo: string(userInfoJsonByte),
  4390. CompanyChartPermissionInfo: string(companyChartPermissionInfoJsonByte),
  4391. CompanyContractInfo: string(companyContractByte),
  4392. CompanyContractPermissionInfo: string(companyContractPermissionJsonByte),
  4393. OpUserId: this.SysUser.AdminId,
  4394. OpUserName: this.SysUser.RealName,
  4395. CreateTime: time.Now(),
  4396. }
  4397. _ = company.AddCompanyDeleteBak(companyDeleteBak)
  4398. }
  4399. br.Ret = 200
  4400. br.Success = true
  4401. br.Msg = "删除成功"
  4402. }
  4403. // @Title 领取客户列表
  4404. // @Description 领取客户列表接口
  4405. // @Param PageSize query int true "每页数据条数"
  4406. // @Param CurrentIndex query int true "当前页页码,从1开始"
  4407. // @Param StartDate query string true "开始时间"
  4408. // @Param EndDate query string true "结束时间"
  4409. // @Param KeyWord query string true "搜索关键词"
  4410. // @Success 200 {object} company.CompanyReceiveListResp
  4411. // @router /receive/list [get]
  4412. func (this *CompanyController) ReceiveList() {
  4413. br := new(models.BaseResponse).Init()
  4414. defer func() {
  4415. this.Data["json"] = br
  4416. this.ServeJSON()
  4417. }()
  4418. sysUser := this.SysUser
  4419. if sysUser == nil {
  4420. br.Msg = "请登录"
  4421. br.ErrMsg = "请登录,SysUser Is Empty"
  4422. br.Ret = 408
  4423. return
  4424. }
  4425. var productId, recevieProductId int
  4426. roleTypeCode := sysUser.RoleTypeCode
  4427. productId = services.GetProductId(roleTypeCode)
  4428. if productId == 1 {
  4429. recevieProductId = 2
  4430. } else if productId == 2 {
  4431. recevieProductId = 1
  4432. }
  4433. if productId == 0 {
  4434. br.Msg = "参数错误"
  4435. br.ErrMsg = "客户类型为:" + roleTypeCode
  4436. return
  4437. }
  4438. pageSize, _ := this.GetInt("PageSize")
  4439. currentIndex, _ := this.GetInt("CurrentIndex")
  4440. adminId := this.GetString("AdminId")
  4441. startDate := this.GetString("StartDate")
  4442. endDate := this.GetString("EndDate")
  4443. keyWord := this.GetString("KeyWord")
  4444. var startSize int
  4445. if pageSize <= 0 {
  4446. pageSize = utils.PageSize20
  4447. }
  4448. if currentIndex <= 0 {
  4449. currentIndex = 1
  4450. }
  4451. startSize = paging.StartIndex(currentIndex, pageSize)
  4452. var condition string
  4453. var pars []interface{}
  4454. if adminId != "" {
  4455. condition += ` AND c.seller_id IN (` + adminId + `) `
  4456. }
  4457. if startDate != "" {
  4458. condition += ` AND c.start_date>=? `
  4459. pars = append(pars, startDate)
  4460. }
  4461. if endDate != "" {
  4462. condition += ` AND c.end_date>=? `
  4463. pars = append(pars, endDate)
  4464. }
  4465. if keyWord != "" {
  4466. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR b.mobile LIKE '%` + keyWord + `%' OR b.email LIKE '%` + keyWord + `%') `
  4467. }
  4468. total, err := company.GetCompanyReceiveListCount(condition, pars, productId, recevieProductId)
  4469. if err != nil {
  4470. br.Msg = "获取失败"
  4471. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  4472. return
  4473. }
  4474. list, err := company.GetCompanyReceiveList(condition, pars, productId, recevieProductId, startSize, pageSize)
  4475. if err != nil {
  4476. br.Msg = "获取失败"
  4477. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  4478. return
  4479. }
  4480. lenList := len(list)
  4481. for i := 0; i < lenList; i++ {
  4482. item := list[i]
  4483. var expireDay string
  4484. if item.Status != "" {
  4485. status := item.Status
  4486. if item.EndDate != "" {
  4487. if status == utils.COMPANY_STATUS_FOREVER { //永续
  4488. expireDay = "-"
  4489. } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用/正式
  4490. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  4491. sub := endDateTime.Sub(time.Now())
  4492. expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  4493. } else if status == utils.COMPANY_STATUS_LOSE { //流失
  4494. expireDay = "-"
  4495. } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  4496. if item.StartDate != "" && item.EndDate != "" {
  4497. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  4498. sub := endDateTime.Sub(time.Now())
  4499. expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  4500. } else {
  4501. expireDay = "-"
  4502. }
  4503. } else {
  4504. expireDay = "-"
  4505. }
  4506. }
  4507. }
  4508. list[i].ExpireDay = expireDay
  4509. }
  4510. page := paging.GetPaging(currentIndex, pageSize, total)
  4511. resp := new(company.CompanyReceiveListResp)
  4512. resp.List = list
  4513. resp.Paging = page
  4514. br.Ret = 200
  4515. br.Success = true
  4516. br.Msg = "获取成功"
  4517. br.Data = resp
  4518. }
  4519. // @Title 领取客户
  4520. // @Description 领取客户接口
  4521. // @Param request body company.CompanyReceiveReq true "type json string"
  4522. // @Success Ret=200 领取成功
  4523. // @router /receive [post]
  4524. func (this *CompanyController) Receive() {
  4525. br := new(models.BaseResponse).Init()
  4526. defer func() {
  4527. this.Data["json"] = br
  4528. this.ServeJSON()
  4529. }()
  4530. sysUser := this.SysUser
  4531. if sysUser == nil {
  4532. br.Msg = "请登录"
  4533. br.ErrMsg = "请登录,SysUser Is Empty"
  4534. br.Ret = 408
  4535. return
  4536. }
  4537. var req company.CompanyReceiveReq
  4538. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4539. if err != nil {
  4540. br.Msg = "参数解析异常!"
  4541. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4542. return
  4543. }
  4544. if req.CompanyId <= 0 {
  4545. br.Msg = "参数异常!"
  4546. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  4547. return
  4548. }
  4549. //权益主观客观权限一块开
  4550. if req.PermissionIds != "" {
  4551. permissionStr, err := company.GetPermissionIdById(req.PermissionIds)
  4552. if err != nil {
  4553. br.Msg = "获取信息失败"
  4554. br.ErrMsg = "获取主观客观权限信息失败,Err:" + err.Error()
  4555. return
  4556. }
  4557. req.PermissionIds = permissionStr
  4558. }
  4559. roleTypeCode := sysUser.RoleTypeCode
  4560. productId := services.GetProductId(roleTypeCode)
  4561. if productId == 0 {
  4562. br.Msg = "参数错误"
  4563. br.ErrMsg = "客户类型为:" + roleTypeCode
  4564. return
  4565. }
  4566. sellsId := 0
  4567. if req.SellsId <= 0 {
  4568. sellsId = sysUser.AdminId
  4569. } else {
  4570. sellsId = req.SellsId
  4571. }
  4572. seller, err := system.GetSysAdminById(sellsId)
  4573. if err != nil {
  4574. br.Msg = "获取销售信息失败"
  4575. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  4576. return
  4577. }
  4578. companyDetail, err := company.GetCompanyDetailById(req.CompanyId)
  4579. if err != nil {
  4580. br.Msg = "获取客户信息失败"
  4581. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  4582. return
  4583. }
  4584. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  4585. if err != nil && err.Error() != utils.ErrNoRow() {
  4586. br.Msg = "获取客户信息失败"
  4587. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  4588. return
  4589. }
  4590. productName := ""
  4591. var status string
  4592. if productId == 1 {
  4593. productName = utils.COMPANY_PRODUCT_FICC_NAME
  4594. } else {
  4595. productName = utils.COMPANY_PRODUCT_RAI_NAME
  4596. }
  4597. if cp != nil {
  4598. if cp.Status != utils.COMPANY_STATUS_LOSE {
  4599. br.Msg = "客户状态为:" + cp.Status + ";不可领取"
  4600. br.ErrMsg = "客户状态为:" + cp.Status + ";不可领取"
  4601. return
  4602. }
  4603. if cp.SellerId == sysUser.AdminId {
  4604. br.Msg = "已为自己客户,不可重复领取"
  4605. br.ErrMsg = "已为自己客户,不可领取:company_id:" + strconv.Itoa(cp.CompanyId)
  4606. return
  4607. }
  4608. //转移 销售
  4609. companyReportPermissionList, startDate, endDate, err := company.MoveSeller(req.CompanyId, productId, seller.AdminId, seller.GroupId, seller.DepartmentId, seller.RealName)
  4610. if err != nil {
  4611. br.Msg = "领取失败"
  4612. br.ErrMsg = "领取失败,Err:" + err.Error()
  4613. return
  4614. }
  4615. //新增客户产品状态变更日志
  4616. {
  4617. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  4618. Id: 0,
  4619. CompanyId: req.CompanyId,
  4620. ProductId: productId,
  4621. Status: "试用",
  4622. Source: "receive",
  4623. SellerId: seller.AdminId,
  4624. SellerName: seller.RealName,
  4625. StartDate: startDate,
  4626. EndDate: endDate,
  4627. RealEndDate: startDate,
  4628. CreateTime: time.Now(),
  4629. }
  4630. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  4631. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  4632. Id: 0,
  4633. CompanyId: req.CompanyId,
  4634. ProductId: productId,
  4635. Source: "receive",
  4636. SellerId: seller.AdminId,
  4637. SellerName: seller.RealName,
  4638. StartDate: startDate,
  4639. EndDate: endDate,
  4640. RealEndDate: startDate,
  4641. IsStop: 0,
  4642. CreateTime: time.Now(),
  4643. }
  4644. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  4645. }
  4646. //流失转试用,企业下面的用户自动添加产业关注
  4647. {
  4648. go cygxService.AddUserFllowCompanyLossToTryOut(req.CompanyId)
  4649. }
  4650. } else {
  4651. //跨部门领取
  4652. var startDateTime, endDateTime time.Time
  4653. if req.Status == utils.COMPANY_STATUS_TRY_OUT {
  4654. startDateTime = time.Now()
  4655. endDateTime = time.Now().AddDate(0, 2, 0)
  4656. } else if req.Status == utils.COMPANY_STATUS_FOREVER {
  4657. startDateTime = time.Now()
  4658. endDateTime = time.Now().AddDate(100, 0, 0)
  4659. } else {
  4660. br.Msg = "无效的客户状态,请重新选择"
  4661. return
  4662. }
  4663. var startDate, endDate string
  4664. startDate = startDateTime.Format(utils.FormatDate)
  4665. endDate = endDateTime.Format(utils.FormatDate)
  4666. if req.PermissionIds == "" {
  4667. br.Msg = "请选择权限!"
  4668. return
  4669. }
  4670. industry, err := company.GetCompanyIndustryById(req.IndustryId)
  4671. if err != nil {
  4672. br.Msg = "获取行业信息失败"
  4673. br.ErrMsg = "获取行业信息失败,Err:" + err.Error()
  4674. return
  4675. }
  4676. if industry == nil {
  4677. br.Msg = "行业信息不存在"
  4678. return
  4679. }
  4680. status = req.Status
  4681. companyProduct := new(company.CompanyProduct)
  4682. companyProduct.CompanyId = req.CompanyId
  4683. companyProduct.ProductId = productId
  4684. companyProduct.ProductName = productName
  4685. companyProduct.CompanyName = companyDetail.CompanyName
  4686. companyProduct.Source = req.Source
  4687. companyProduct.Reasons = req.Reasons
  4688. companyProduct.Status = status
  4689. companyProduct.StartDate = startDate
  4690. companyProduct.EndDate = endDate
  4691. companyProduct.IndustryId = req.IndustryId
  4692. companyProduct.IndustryName = industry.IndustryName
  4693. companyProduct.SellerId = seller.AdminId
  4694. companyProduct.SellerName = seller.RealName
  4695. companyProduct.GroupId = seller.GroupId
  4696. companyProduct.DepartmentId = seller.DepartmentId
  4697. companyProduct.IsSuspend = 0
  4698. companyProduct.CreateTime = time.Now()
  4699. companyProduct.ModifyTime = time.Now()
  4700. companyProduct.CompanyType = req.CompanyType
  4701. companyProduct.OpenCode = services.GenerateOpenCompanyProductCode(req.CompanyId, productId)
  4702. companyProduct.TodoStatus = "无任务"
  4703. companyProduct.TryStage = 1
  4704. _, err = company.AddCompanyProduct(companyProduct)
  4705. if err != nil {
  4706. br.Msg = "新增失败"
  4707. br.ErrMsg = "新增客户产品失败,err:" + err.Error()
  4708. return
  4709. }
  4710. companyReportPermissionList, err := services.AddCompanyPermission(req.CompanyId, seller.AdminId, productId, productName, seller.RealName, req.PermissionIds, startDate, endDate)
  4711. if err != nil {
  4712. br.Msg = "新增失败"
  4713. br.ErrMsg = "新增客户设置权限失败,err:" + err.Error()
  4714. return
  4715. }
  4716. //新增客户产品日志
  4717. {
  4718. go services.AddCompanyProductLog(companyProduct, this.SysUser.AdminId, "add")
  4719. }
  4720. //新增客户产品状态变更日志
  4721. {
  4722. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  4723. Id: 0,
  4724. CompanyId: companyProduct.CompanyId,
  4725. ProductId: companyProduct.ProductId,
  4726. Status: "试用",
  4727. SellerId: seller.AdminId,
  4728. SellerName: seller.RealName,
  4729. Source: "add",
  4730. StartDate: startDateTime,
  4731. EndDate: endDateTime,
  4732. RealEndDate: startDateTime,
  4733. CreateTime: time.Now(),
  4734. }
  4735. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  4736. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  4737. Id: 0,
  4738. CompanyId: companyProduct.CompanyId,
  4739. ProductId: companyProduct.ProductId,
  4740. SellerId: seller.AdminId,
  4741. SellerName: seller.RealName,
  4742. Source: "add",
  4743. StartDate: startDateTime,
  4744. EndDate: endDateTime,
  4745. RealEndDate: startDateTime,
  4746. IsStop: 0,
  4747. CreateTime: time.Now(),
  4748. }
  4749. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  4750. }
  4751. //查询当前客户的所有产品的列表数据,并找出非当前产品的销售去发送模板消息
  4752. companyProductList, err := company.GetCompanyProductsByCompanyId(req.CompanyId)
  4753. for _, companyProduct := range companyProductList {
  4754. //如果是当前领取的产品,那么就退出当前循环,进入下一循环
  4755. if companyProduct.ProductId == productId {
  4756. continue
  4757. }
  4758. //查询其他部门销售的信息
  4759. admin, tmpErr := system.GetSysAdminById(companyProduct.SellerId)
  4760. if tmpErr != nil {
  4761. continue
  4762. }
  4763. //发送模板消息给另一个部门的销售
  4764. go services.SendCompanyReceiveWxTemplateMsg(companyDetail.CompanyName, productName, sysUser.RealName, admin.Mobile)
  4765. }
  4766. }
  4767. //新增操作记录
  4768. {
  4769. remark := "领取客户"
  4770. operation := "receive"
  4771. services.AddCompanyOperationRecord(req.CompanyId, seller.AdminId, sysUser.AdminId, productId, sysUser.AdminId, companyDetail.CompanyName,
  4772. productName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", status)
  4773. }
  4774. br.Ret = 200
  4775. br.Success = true
  4776. br.Msg = "领取成功"
  4777. }
  4778. // @Title 移动销售
  4779. // @Description 移动销售接口
  4780. // @Param request body company.MoveSellerReq true "type json string"
  4781. // @Success Ret=200 移动成功
  4782. // @router /move/seller [post]
  4783. func (this *CompanyController) MoveSeller() {
  4784. br := new(models.BaseResponse).Init()
  4785. defer func() {
  4786. this.Data["json"] = br
  4787. this.ServeJSON()
  4788. }()
  4789. sysUser := this.SysUser
  4790. if sysUser == nil {
  4791. br.Msg = "请登录"
  4792. br.ErrMsg = "请登录,SysUser Is Empty"
  4793. br.Ret = 408
  4794. return
  4795. }
  4796. var req company.MoveSellerReq
  4797. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4798. if err != nil {
  4799. br.Msg = "参数解析异常!"
  4800. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4801. return
  4802. }
  4803. if req.CompanyId <= 0 {
  4804. br.Msg = "参数异常!"
  4805. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  4806. return
  4807. }
  4808. if req.SellsId <= 0 {
  4809. br.Msg = "参数异常!"
  4810. br.ErrMsg = "SellsId:" + strconv.Itoa(req.SellsId)
  4811. return
  4812. }
  4813. seller, err := system.GetSysAdminById(req.SellsId)
  4814. if err != nil {
  4815. br.Msg = "获取销售信息失败"
  4816. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  4817. return
  4818. }
  4819. roleTypeCode := sysUser.RoleTypeCode
  4820. productId := services.GetProductId(roleTypeCode)
  4821. if productId == 0 {
  4822. if req.CompanyType == utils.COMPANY_CLASSIFY_FICC {
  4823. productId = 1
  4824. } else if req.CompanyType == utils.COMPANY_CLASSIFY_RAI {
  4825. productId = 2
  4826. }
  4827. }
  4828. if productId == 0 {
  4829. br.Msg = "无效的客户类型"
  4830. br.ErrMsg = "无效的客户类型"
  4831. return
  4832. }
  4833. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  4834. if err != nil && err.Error() != utils.ErrNoRow() {
  4835. if err.Error() == utils.ErrNoRow() {
  4836. br.Msg = "客户信息不存在"
  4837. br.ErrMsg = "客户信息不存在,Err:" + err.Error()
  4838. return
  4839. }
  4840. br.Msg = "获取客户信息失败"
  4841. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  4842. return
  4843. }
  4844. fmt.Println(cp)
  4845. if cp == nil {
  4846. br.Msg = "客户信息不存在,请刷新页面"
  4847. br.ErrMsg = "客户信息不存在"
  4848. return
  4849. }
  4850. err = company.MoveCompanySeller(req.CompanyId, productId, req.SellsId, seller.GroupId, seller.DepartmentId, seller.RealName)
  4851. if err != nil {
  4852. br.Msg = "移动失败"
  4853. br.ErrMsg = "移动失败,Err:" + err.Error()
  4854. return
  4855. }
  4856. //新增操作记录
  4857. {
  4858. remark := "移动到:" + seller.RealName
  4859. operation := "move_seller"
  4860. services.AddCompanyOperationRecord(req.CompanyId, seller.AdminId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
  4861. cp.ProductName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
  4862. }
  4863. //变更销售员与联系人关系
  4864. _ = models.UpdateUserSellerRelationByCompanyId(req.CompanyId, productId, seller.AdminId, seller.RealName)
  4865. br.Ret = 200
  4866. br.Success = true
  4867. br.Msg = "移动成功"
  4868. }
  4869. // @Title 修改试用客户标签
  4870. // @Description 修改试用客户标签接口
  4871. // @Param request body company.UpdateTryStageReq true "type json string"
  4872. // @Success Ret=200 设置成功
  4873. // @router /update/tryStage [post]
  4874. func (this *CompanyController) UpdateTryStage() {
  4875. br := new(models.BaseResponse).Init()
  4876. defer func() {
  4877. this.Data["json"] = br
  4878. this.ServeJSON()
  4879. }()
  4880. sysUser := this.SysUser
  4881. if sysUser == nil {
  4882. br.Msg = "请登录"
  4883. br.ErrMsg = "请登录,SysUser Is Empty"
  4884. br.Ret = 408
  4885. return
  4886. }
  4887. var req company.UpdateTryStageReq
  4888. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4889. if err != nil {
  4890. br.Msg = "参数解析异常!"
  4891. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4892. return
  4893. }
  4894. if req.CompanyId <= 0 {
  4895. br.Msg = "参数异常!"
  4896. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  4897. return
  4898. }
  4899. if req.ProductId <= 0 {
  4900. br.Msg = "参数异常!"
  4901. br.ErrMsg = "ProductId:" + strconv.Itoa(req.ProductId)
  4902. return
  4903. }
  4904. if req.TryStage <= 0 {
  4905. br.Msg = "参数异常!"
  4906. br.ErrMsg = "TryStage:" + strconv.Itoa(req.TryStage)
  4907. return
  4908. }
  4909. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  4910. if err != nil && err.Error() != utils.ErrNoRow() {
  4911. if err.Error() == utils.ErrNoRow() {
  4912. br.Msg = "客户信息不存在"
  4913. br.ErrMsg = "客户信息不存在,Err:" + err.Error()
  4914. return
  4915. }
  4916. br.Msg = "获取客户信息失败"
  4917. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  4918. return
  4919. }
  4920. fmt.Println(cp)
  4921. if cp == nil {
  4922. br.Msg = "客户信息不存在,请刷新页面"
  4923. br.ErrMsg = "客户信息不存在"
  4924. return
  4925. }
  4926. if cp.Status != "试用" {
  4927. br.Msg = "客户不是试用状态,不允许修改"
  4928. br.ErrMsg = "客户不是试用状态,不允许修改"
  4929. return
  4930. }
  4931. if cp.SellerId != sysUser.AdminId {
  4932. br.Msg = "无修改权限"
  4933. br.ErrMsg = "无修改权限"
  4934. return
  4935. }
  4936. if cp.TryStage == req.TryStage {
  4937. br.Msg = "与原标签一致,无需修改"
  4938. br.ErrMsg = "与原标签一致,无需修改"
  4939. return
  4940. }
  4941. err = company.UpdateCompanyTryStage(req.CompanyId, req.ProductId, req.TryStage)
  4942. if err != nil {
  4943. br.Msg = "设置失败"
  4944. br.ErrMsg = "设置失败,Err:" + err.Error()
  4945. return
  4946. }
  4947. //新增操作记录
  4948. {
  4949. stage := ""
  4950. tryStageAllMap := map[int]string{
  4951. 1: "未分类",
  4952. 2: "推进",
  4953. 3: "跟踪",
  4954. 4: "预备",
  4955. }
  4956. if v, ok := tryStageAllMap[req.TryStage]; ok {
  4957. stage = v
  4958. }
  4959. remark := "修改试用客户子标签:" + stage
  4960. operation := "UpdateTryStage"
  4961. services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  4962. cp.ProductName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
  4963. }
  4964. br.Ret = 200
  4965. br.Success = true
  4966. br.Msg = "设置成功"
  4967. }
  4968. // @Title 暂停/启用
  4969. // @Description 暂停/启用接口
  4970. // @Param request body company.SuspendReq true "type json string"
  4971. // @Success Ret=200 移动成功
  4972. // @router /suspend [post]
  4973. func (this *CompanyController) Suspend() {
  4974. br := new(models.BaseResponse).Init()
  4975. defer func() {
  4976. this.Data["json"] = br
  4977. this.ServeJSON()
  4978. }()
  4979. sysUser := this.SysUser
  4980. if sysUser == nil {
  4981. br.Msg = "请登录"
  4982. br.ErrMsg = "请登录,SysUser Is Empty"
  4983. br.Ret = 408
  4984. return
  4985. }
  4986. var req company.SuspendReq
  4987. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4988. if err != nil {
  4989. br.Msg = "参数解析异常!"
  4990. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4991. return
  4992. }
  4993. if req.CompanyId <= 0 {
  4994. br.Msg = "参数异常!"
  4995. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  4996. return
  4997. }
  4998. roleTypeCode := sysUser.RoleTypeCode
  4999. productId := services.GetProductId(roleTypeCode)
  5000. if productId == 0 {
  5001. br.Msg = "参数错误"
  5002. br.ErrMsg = "角色类型为:" + roleTypeCode
  5003. return
  5004. }
  5005. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  5006. if err != nil {
  5007. br.Msg = "获取数据异常!"
  5008. br.ErrMsg = "获取数据异常:" + err.Error()
  5009. return
  5010. }
  5011. suspendStatus := ""
  5012. suspend := 0
  5013. if cp.IsSuspend == 1 {
  5014. suspendStatus = "启用"
  5015. suspend = 0
  5016. } else {
  5017. suspendStatus = "暂停"
  5018. suspend = 1
  5019. }
  5020. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  5021. br.Msg = "客户状态为:" + cp.Status + ",不允许进行" + suspendStatus + "操作"
  5022. br.ErrMsg = "客户状态为:" + cp.Status + ",不允许进行" + suspendStatus + "操作"
  5023. return
  5024. }
  5025. err = company.SuspendCompanyProductById(req.CompanyId, productId, suspend)
  5026. if err != nil {
  5027. br.Msg = suspendStatus + "失败"
  5028. br.ErrMsg = suspendStatus + "失败 Err:" + err.Error()
  5029. return
  5030. }
  5031. //新增操作记录
  5032. {
  5033. remark := suspendStatus
  5034. operation := "is_suspend"
  5035. services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
  5036. cp.ProductName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
  5037. }
  5038. br.Ret = 200
  5039. br.Success = true
  5040. br.Msg = suspendStatus + "成功"
  5041. }
  5042. // @Title 检测客户名称或社会信用码
  5043. // @Description 检测客户名称或社会信用码接口(新增/编辑客户页面使用)
  5044. // @Param CompanyName query string true "客户名称"
  5045. // @Param CreditCode query string true "社会统一信用码"
  5046. // @Success 200 {object} company.CheckCompanyInfoResp
  5047. // @router /check/companyInfo [get]
  5048. func (this *CompanyController) CheckCompanyInfo() {
  5049. br := new(models.BaseResponse).Init()
  5050. defer func() {
  5051. this.Data["json"] = br
  5052. this.ServeJSON()
  5053. }()
  5054. sysUser := this.SysUser
  5055. if sysUser == nil {
  5056. br.Msg = "请登录"
  5057. br.ErrMsg = "请登录,SysUser Is Empty"
  5058. br.Ret = 408
  5059. return
  5060. }
  5061. roleTypeCode := sysUser.RoleTypeCode
  5062. productId := services.GetProductId(roleTypeCode)
  5063. companyName := this.GetString("CompanyName")
  5064. creditCode := this.GetString("CreditCode")
  5065. var status, comanyId int
  5066. var productName string
  5067. if productId == 0 {
  5068. productId = 1
  5069. checkProductId := 2
  5070. if companyName != "" {
  5071. nameItem, err := company.CheckCompanyProductByName(companyName, productId)
  5072. if err != nil && err.Error() != utils.ErrNoRow() {
  5073. br.Msg = "校验客户名称是否存在失败"
  5074. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
  5075. return
  5076. }
  5077. if nameItem != nil && nameItem.CompanyId > 0 {
  5078. br.Msg = "客户名称已存在,请重新填写"
  5079. br.ErrMsg = "客户名称已存在,请重新填写"
  5080. br.Ret = 405
  5081. return
  5082. }
  5083. nameCheckItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
  5084. if err != nil && err.Error() != utils.ErrNoRow() {
  5085. br.Msg = "校验客户名称是否存在失败"
  5086. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5087. return
  5088. }
  5089. if nameCheckItem != nil && nameCheckItem.CompanyId > 0 {
  5090. status = 1
  5091. productName = nameCheckItem.ProductName
  5092. comanyId = nameCheckItem.CompanyId
  5093. goto Loop
  5094. }
  5095. }
  5096. if creditCode != "" {
  5097. codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
  5098. if err != nil && err.Error() != utils.ErrNoRow() {
  5099. br.Msg = "校验社会信用码是否存在失败"
  5100. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
  5101. return
  5102. }
  5103. if codeItem != nil && codeItem.CompanyId > 0 {
  5104. br.Msg = "社会信用码已存在,请重新填写"
  5105. br.ErrMsg = "社会信用码已存在,请重新填写"
  5106. br.Ret = 405
  5107. return
  5108. }
  5109. codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
  5110. if err != nil && err.Error() != utils.ErrNoRow() {
  5111. br.Msg = "校验社会信用码是否存在失败"
  5112. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5113. return
  5114. }
  5115. if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
  5116. status = 1
  5117. productName = codeCheckItem.ProductName
  5118. comanyId = codeCheckItem.CompanyId
  5119. goto Loop
  5120. }
  5121. }
  5122. productId = 2
  5123. checkProductId = 1
  5124. if companyName != "" {
  5125. nameItem, err := company.CheckCompanyProductByName(companyName, productId)
  5126. if err != nil && err.Error() != utils.ErrNoRow() {
  5127. br.Msg = "校验客户名称是否存在失败"
  5128. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
  5129. return
  5130. }
  5131. if nameItem != nil && nameItem.CompanyId > 0 {
  5132. br.Msg = "客户名称已存在,请重新填写"
  5133. br.ErrMsg = "客户名称已存在,请重新填写"
  5134. br.Ret = 405
  5135. return
  5136. }
  5137. nameCheckItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
  5138. if err != nil && err.Error() != utils.ErrNoRow() {
  5139. br.Msg = "校验客户名称是否存在失败"
  5140. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5141. return
  5142. }
  5143. if nameCheckItem != nil && nameCheckItem.CompanyId > 0 {
  5144. status = 1
  5145. productName = nameCheckItem.ProductName
  5146. comanyId = nameCheckItem.CompanyId
  5147. goto Loop
  5148. }
  5149. }
  5150. if creditCode != "" {
  5151. codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
  5152. if err != nil && err.Error() != utils.ErrNoRow() {
  5153. br.Msg = "校验社会信用码是否存在失败"
  5154. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
  5155. return
  5156. }
  5157. if codeItem != nil && codeItem.CompanyId > 0 {
  5158. br.Msg = "社会信用码已存在,请重新填写"
  5159. br.ErrMsg = "社会信用码已存在,请重新填写"
  5160. br.Ret = 405
  5161. return
  5162. }
  5163. codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
  5164. if err != nil && err.Error() != utils.ErrNoRow() {
  5165. br.Msg = "校验社会信用码是否存在失败"
  5166. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5167. return
  5168. }
  5169. if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
  5170. status = 1
  5171. productName = codeCheckItem.ProductName
  5172. comanyId = codeCheckItem.CompanyId
  5173. goto Loop
  5174. }
  5175. }
  5176. } else {
  5177. checkProductId := 0
  5178. if productId == 1 {
  5179. checkProductId = 2
  5180. } else if productId == 2 {
  5181. checkProductId = 1
  5182. }
  5183. if companyName != "" {
  5184. nameItem, err := company.CheckCompanyProductByName(companyName, productId)
  5185. if err != nil && err.Error() != utils.ErrNoRow() {
  5186. br.Msg = "校验客户名称是否存在失败"
  5187. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
  5188. return
  5189. }
  5190. if nameItem != nil && nameItem.ProductName != "" {
  5191. br.Msg = "客户名称已存在,请重新填写"
  5192. br.ErrMsg = "客户名称已存在,请重新填写"
  5193. br.Ret = 405
  5194. return
  5195. }
  5196. nameCheckoutItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
  5197. if err != nil && err.Error() != utils.ErrNoRow() {
  5198. br.Msg = "校验客户名称是否存在失败"
  5199. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5200. return
  5201. }
  5202. if nameCheckoutItem != nil && nameCheckoutItem.CompanyId > 0 {
  5203. status = 1
  5204. productName = nameCheckoutItem.ProductName
  5205. comanyId = nameCheckoutItem.CompanyId
  5206. goto Loop
  5207. }
  5208. }
  5209. if creditCode != "" {
  5210. codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
  5211. if err != nil && err.Error() != utils.ErrNoRow() {
  5212. br.Msg = "校验社会信用码是否存在失败"
  5213. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
  5214. return
  5215. }
  5216. if codeItem != nil && codeItem.CompanyId > 0 {
  5217. br.Msg = "社会信用码已存在,请重新填写"
  5218. br.ErrMsg = "社会信用码已存在,请重新填写"
  5219. br.Ret = 405
  5220. return
  5221. }
  5222. codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
  5223. if err != nil && err.Error() != utils.ErrNoRow() {
  5224. br.Msg = "校验社会信用码是否存在失败"
  5225. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5226. return
  5227. }
  5228. if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
  5229. status = 1
  5230. productName = codeCheckItem.ProductName
  5231. comanyId = codeCheckItem.CompanyId
  5232. goto Loop
  5233. }
  5234. }
  5235. }
  5236. Loop:
  5237. resp := new(company.CheckCompanyInfoResp)
  5238. resp.Status = status
  5239. resp.ProductName = productName
  5240. resp.CompanyId = comanyId
  5241. br.Ret = 200
  5242. br.Success = true
  5243. br.Msg = "获取成功"
  5244. br.Data = resp
  5245. }
  5246. // @Title 客户导出
  5247. // @Description 客户导出接口
  5248. // @Param Status query string true "状态:'试用','永续','冻结','流失','正式'"
  5249. // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
  5250. // @Param IndustryId query int true "行业id,0为全部"
  5251. // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
  5252. // @Param ChartPermissionIds query string false "阅读权限品种ID,多个用英文逗号分开,空字符串为全部"
  5253. // @Param ContractPermissionIds query string false "已购品种ID,多个用英文逗号分开,空字符串为全部"
  5254. // @Param StartDate query string true "开始时间"
  5255. // @Param EndDate query string true "结束时间"
  5256. // @Param CreateStartDate query string true "创建开始时间"
  5257. // @Param CreateEndDate query string true "创建结束时间"
  5258. // @Param KeyWord query string true "搜索关键词"
  5259. // @Param Address query string true "地址 , 多个用英文逗号分开 "
  5260. // @Param Province query string true "省 , 多个用英文逗号分开 "
  5261. // @Param City query string true "市 , 多个用英文逗号分开 "
  5262. // @Param PackageType query int true "套餐类型,0:无,1:大套餐,2:小套餐"
  5263. // @Success 200 {object} company.CompanyListResp
  5264. // @router /export [get]
  5265. func (this *CompanyController) Export() {
  5266. br := new(models.BaseResponse).Init()
  5267. defer func() {
  5268. this.Data["json"] = br
  5269. this.ServeJSON()
  5270. }()
  5271. sysUser := this.SysUser
  5272. if sysUser == nil {
  5273. br.Msg = "请登录"
  5274. br.ErrMsg = "请登录,SysUser Is Empty"
  5275. br.Ret = 408
  5276. return
  5277. }
  5278. roleTypeCode := sysUser.RoleTypeCode
  5279. status := this.GetString("Status")
  5280. companyType := this.GetString("CompanyType")
  5281. industryId, _ := this.GetInt("IndustryId")
  5282. adminId := this.GetString("AdminId")
  5283. chartPermissionIds := this.GetString("ChartPermissionIds")
  5284. contractPermissionIds := this.GetString("ContractPermissionIds")
  5285. startDate := this.GetString("StartDate")
  5286. endDate := this.GetString("EndDate")
  5287. createStartDate := this.GetString("CreateStartDate")
  5288. createEndDate := this.GetString("CreateEndDate")
  5289. keyWord := this.GetString("KeyWord")
  5290. keyWord = strings.Trim(keyWord, " ")
  5291. address := this.GetString("Address")
  5292. province := this.GetString("Province")
  5293. city := this.GetString("City")
  5294. // 套餐类型
  5295. packageType, _ := this.GetInt("PackageType")
  5296. resp := new(company.CompanyListResp)
  5297. statusItems := make([]*company.CompanyStatus, 0)
  5298. var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}
  5299. var condition string
  5300. var pars []interface{}
  5301. //状态分类查询条件
  5302. var permissionCondition string
  5303. var permissionPars []interface{}
  5304. if companyType != "" {
  5305. condition += ` AND b.product_name=? `
  5306. pars = append(pars, companyType)
  5307. }
  5308. if industryId > 0 {
  5309. condition += ` AND b.industry_id=? `
  5310. pars = append(pars, industryId)
  5311. }
  5312. if adminId != "" {
  5313. condition += ` AND b.seller_id IN (` + adminId + `) `
  5314. }
  5315. if startDate != "" {
  5316. condition += ` AND b.start_date>=? `
  5317. pars = append(pars, startDate)
  5318. }
  5319. if endDate != "" {
  5320. condition += ` AND b.end_date<=? `
  5321. pars = append(pars, endDate)
  5322. }
  5323. if createStartDate != "" {
  5324. condition += ` AND a.created_time>=? `
  5325. pars = append(pars, createStartDate)
  5326. }
  5327. if createEndDate != "" {
  5328. condition += ` AND a.created_time<=? `
  5329. pars = append(pars, createEndDate)
  5330. }
  5331. if address != "" {
  5332. var addressSql string
  5333. slice := strings.Split(address, ",")
  5334. for _, v := range slice {
  5335. addressSql += "'" + v + "'" + ","
  5336. }
  5337. addressSql = strings.TrimRight(addressSql, ",")
  5338. condition += ` AND a.address IN (` + addressSql + `) `
  5339. }
  5340. if province != "" {
  5341. var provinceSql string
  5342. slice := strings.Split(province, ",")
  5343. for _, v := range slice {
  5344. provinceSql += "'" + v + "'" + ","
  5345. }
  5346. provinceSql = strings.TrimRight(provinceSql, ",")
  5347. condition += ` AND a.province IN (` + provinceSql + `) `
  5348. }
  5349. if city != "" {
  5350. var citySql string
  5351. slice := strings.Split(city, ",")
  5352. for _, v := range slice {
  5353. citySql += "'" + v + "'" + ","
  5354. }
  5355. citySql = strings.TrimRight(citySql, ",")
  5356. condition += ` AND a.city IN (` + citySql + `) `
  5357. }
  5358. if keyWord != "" {
  5359. companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
  5360. if err != nil {
  5361. br.Msg = "获取客户信息失败"
  5362. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  5363. return
  5364. }
  5365. if companyIdStr != "" {
  5366. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  5367. } else {
  5368. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  5369. }
  5370. }
  5371. //if chartPermissionIds != "" && chartPermissionIds != "1" {
  5372. // companyIdStr, err := company.GetCompanyListCompanyIdByPermissionIdStr(chartPermissionIds)
  5373. // if err != nil {
  5374. // br.Msg = "获取失败"
  5375. // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
  5376. // return
  5377. // }
  5378. // if companyIdStr != "" {
  5379. // condition += ` AND a.company_id IN (` + companyIdStr + `) `
  5380. // } else {
  5381. // for _, v := range statusArr {
  5382. // statusCount := new(company.CompanyStatus)
  5383. // if v == "全部" {
  5384. // statusCount.Status = "全部"
  5385. // statusCount.Count = 0
  5386. // } else {
  5387. // statusCount.Status = v
  5388. // statusCount.Count = 0
  5389. // }
  5390. // statusItems = append(statusItems, statusCount)
  5391. // }
  5392. // items := make([]*company.CompanyListItem, 0)
  5393. // resp.List = items
  5394. // resp.StatusCount = statusItems
  5395. // br.Msg = "获取成功"
  5396. // br.Ret = 200
  5397. // br.Data = resp
  5398. // return
  5399. // }
  5400. //}
  5401. // 阅读权限/已购品种筛选
  5402. cond, emp, e := services.FilterReadAndContractAuth(chartPermissionIds, contractPermissionIds, condition)
  5403. if e != nil {
  5404. br.Msg = "获取失败"
  5405. br.ErrMsg = "FilterReadAndContractAuth err: " + e.Error()
  5406. return
  5407. }
  5408. if emp {
  5409. for _, v := range statusArr {
  5410. statusCount := new(company.CompanyStatus)
  5411. if v == "全部" {
  5412. statusCount.Status = "全部"
  5413. statusCount.Count = 0
  5414. } else {
  5415. statusCount.Status = v
  5416. statusCount.Count = 0
  5417. }
  5418. statusItems = append(statusItems, statusCount)
  5419. }
  5420. items := make([]*company.CompanyListItem, 0)
  5421. resp.List = items
  5422. resp.StatusCount = statusItems
  5423. br.Msg = "获取成功"
  5424. br.Ret = 200
  5425. br.Data = resp
  5426. return
  5427. }
  5428. condition = cond
  5429. //套餐类型
  5430. if packageType > 0 {
  5431. condition += ` AND b.package_type=? `
  5432. pars = append(pars, packageType)
  5433. }
  5434. permissionCondition = condition
  5435. permissionPars = pars
  5436. productId := services.GetProductId(roleTypeCode)
  5437. //权限控制
  5438. {
  5439. //如果不是超级管理员
  5440. if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  5441. //如果是部门管理员
  5442. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  5443. condition += ` AND b.product_id=? `
  5444. pars = append(pars, productId)
  5445. permissionCondition += ` AND b.product_id=? `
  5446. permissionPars = append(permissionPars, productId)
  5447. } else {
  5448. condition += ` AND b.product_id=? `
  5449. pars = append(pars, productId)
  5450. permissionCondition += ` AND b.product_id=? `
  5451. permissionPars = append(permissionPars, productId)
  5452. if status == "全部" {
  5453. ////如果是筛选了流失客户状态
  5454. if sysUser.Authority <= 0 {
  5455. condition += ` AND (b.seller_id=? OR status='流失') `
  5456. pars = append(pars, sysUser.AdminId)
  5457. permissionCondition += ` AND b.seller_id=? `
  5458. permissionPars = append(permissionPars, sysUser.AdminId)
  5459. } else {
  5460. if sysUser.Authority == 1 {
  5461. condition += ` AND (b.department_id=? OR status='流失')`
  5462. pars = append(pars, sysUser.DepartmentId)
  5463. permissionCondition += ` AND b.department_id=? `
  5464. permissionPars = append(permissionPars, sysUser.DepartmentId)
  5465. }
  5466. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  5467. if status != utils.COMPANY_STATUS_LOSE {
  5468. condition += ` AND (b.group_id=? OR status='流失') `
  5469. pars = append(pars, sysUser.GroupId)
  5470. }
  5471. permissionCondition += ` AND b.group_id=? `
  5472. permissionPars = append(permissionPars, sysUser.GroupId)
  5473. }
  5474. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  5475. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  5476. if err != nil {
  5477. br.Msg = "获取失败"
  5478. br.ErrMsg = "查询父级id异常" + err.Error()
  5479. return
  5480. }
  5481. var ids []*string
  5482. if pid != nil && *pid != 0 {
  5483. ids, err = company.GetGroupIdsByParentId(*pid)
  5484. if err != nil {
  5485. fmt.Println(err.Error())
  5486. }
  5487. } else {
  5488. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  5489. if err != nil {
  5490. fmt.Println(err.Error())
  5491. }
  5492. }
  5493. var idSlice []string
  5494. var sid string
  5495. for _, id := range ids {
  5496. idSlice = append(idSlice, *id)
  5497. }
  5498. //加入父级groupId
  5499. if *pid > 0 {
  5500. idSlice = append(idSlice, strconv.Itoa(*pid))
  5501. } else {
  5502. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  5503. }
  5504. sid = strings.Join(idSlice, ",")
  5505. if len(sid) > 0 {
  5506. if status != utils.COMPANY_STATUS_LOSE {
  5507. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  5508. //pars = append(pars, sysUser.GroupId)
  5509. }
  5510. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  5511. } else {
  5512. if status != utils.COMPANY_STATUS_LOSE {
  5513. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  5514. //pars = append(pars, sysUser.GroupId)
  5515. }
  5516. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  5517. }
  5518. }
  5519. }
  5520. } else {
  5521. ////如果没有筛选了流失客户状态
  5522. if sysUser.Authority <= 0 {
  5523. condition += ` AND b.seller_id=? `
  5524. pars = append(pars, sysUser.AdminId)
  5525. permissionCondition += ` AND b.seller_id=? `
  5526. permissionPars = append(permissionPars, sysUser.AdminId)
  5527. } else {
  5528. if sysUser.Authority == 1 {
  5529. condition += ` AND b.department_id=?`
  5530. pars = append(pars, sysUser.DepartmentId)
  5531. permissionCondition += ` AND b.department_id=? `
  5532. permissionPars = append(permissionPars, sysUser.DepartmentId)
  5533. }
  5534. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  5535. if status != utils.COMPANY_STATUS_LOSE {
  5536. condition += ` AND b.group_id=? `
  5537. pars = append(pars, sysUser.GroupId)
  5538. }
  5539. permissionCondition += ` AND b.group_id=? `
  5540. permissionPars = append(permissionPars, sysUser.GroupId)
  5541. }
  5542. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  5543. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  5544. if err != nil {
  5545. br.Msg = "获取失败"
  5546. br.ErrMsg = "查询父级id异常" + err.Error()
  5547. return
  5548. }
  5549. var ids []*string
  5550. if pid != nil && *pid != 0 {
  5551. ids, err = company.GetGroupIdsByParentId(*pid)
  5552. if err != nil {
  5553. fmt.Println(err.Error())
  5554. }
  5555. } else {
  5556. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  5557. if err != nil {
  5558. fmt.Println(err.Error())
  5559. }
  5560. }
  5561. var idSlice []string
  5562. var sid string
  5563. for _, id := range ids {
  5564. idSlice = append(idSlice, *id)
  5565. }
  5566. //加入父级groupId
  5567. if *pid > 0 {
  5568. idSlice = append(idSlice, strconv.Itoa(*pid))
  5569. } else {
  5570. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  5571. }
  5572. sid = strings.Join(idSlice, ",")
  5573. if len(sid) > 0 {
  5574. if status != utils.COMPANY_STATUS_LOSE {
  5575. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  5576. //pars = append(pars, sysUser.GroupId)
  5577. }
  5578. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  5579. } else {
  5580. if status != utils.COMPANY_STATUS_LOSE {
  5581. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  5582. //pars = append(pars, sysUser.GroupId)
  5583. }
  5584. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  5585. }
  5586. }
  5587. if sysUser.Authority == 4 {
  5588. if status != utils.COMPANY_STATUS_LOSE {
  5589. condition += ` AND b.group_id =? `
  5590. pars = append(pars, sysUser.GroupId)
  5591. }
  5592. permissionCondition += ` AND b.group_id=? `
  5593. permissionPars = append(permissionPars, sysUser.GroupId)
  5594. }
  5595. }
  5596. }
  5597. }
  5598. }
  5599. }
  5600. //状态控制
  5601. if status != "" && status != "全部" && status != utils.COMPANY_STATUS_LOSE {
  5602. condition += ` AND b.status=? `
  5603. pars = append(pars, status)
  5604. }
  5605. dir, err := os.Executable()
  5606. exPath := filepath.Dir(dir)
  5607. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  5608. xlsxFile := xlsx.NewFile()
  5609. if err != nil {
  5610. br.Msg = "生成文件失败"
  5611. br.ErrMsg = "生成文件失败"
  5612. return
  5613. }
  5614. style := xlsx.NewStyle()
  5615. alignment := xlsx.Alignment{
  5616. Horizontal: "center",
  5617. Vertical: "center",
  5618. WrapText: true,
  5619. }
  5620. style.Alignment = alignment
  5621. style.ApplyAlignment = true
  5622. sheel, err := xlsxFile.AddSheet("客户数据")
  5623. if err != nil {
  5624. br.Msg = "新增Sheet失败"
  5625. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  5626. return
  5627. }
  5628. titleArr := []string{"客户名称", "客户地址", "客户类型", "所属行业", "所属销售", "客户状态", "服务期限", "到期天数", "创建时间", "权限详情"}
  5629. titleLen := len(titleArr)
  5630. titleRow := sheel.AddRow()
  5631. remarkRow := sheel.AddRow() // 备注行
  5632. // 填充空白至Z列
  5633. emptyColNum := 0
  5634. for i := 0; i < 26; i++ {
  5635. remarkRow.AddCell().SetValue("")
  5636. if i >= titleLen {
  5637. emptyColNum += 1
  5638. titleRow.AddCell().SetValue("")
  5639. continue
  5640. }
  5641. titleRow.AddCell().SetValue(titleArr[i])
  5642. }
  5643. // AA列开始为品种权限
  5644. ficcPermissions := make([]int, 0) // 用于后续判断试用暂停客户是否需要暂停这部分权限
  5645. raiPermissions := make([]int, 0)
  5646. permissions, e := models.GetChartPermissionList()
  5647. if e != nil {
  5648. br.Msg = "获取失败"
  5649. br.ErrMsg = "获取品种数据失败,Err:" + err.Error()
  5650. return
  5651. }
  5652. raiArr := []string{"医药", "消费", "科技", "智造"}
  5653. for _, p := range permissions {
  5654. if p.ProductId == 1 {
  5655. ficcPermissions = append(ficcPermissions, p.ChartPermissionId)
  5656. }
  5657. if p.ProductId == 2 {
  5658. raiPermissions = append(raiPermissions, p.ChartPermissionId)
  5659. }
  5660. if utils.InArrayByStr(raiArr, p.PermissionName) {
  5661. titleRow.AddCell().SetValue(p.Remark)
  5662. continue
  5663. }
  5664. titleRow.AddCell().SetValue(p.PermissionName)
  5665. }
  5666. // 第二行, 在品种权限开始列加一行标红备注
  5667. styleRed := xlsx.NewStyle()
  5668. styleRed.Font.Color = "ff0000"
  5669. remarkCell := remarkRow.AddCell()
  5670. remarkCell.SetStyle(styleRed)
  5671. remarkCell.SetString(`第一位数字表示是否已购买该品种,1表示已购,0表示未购;第二位数字表示是否有阅读权限,1表示有权限,0表示没有`)
  5672. list, err := company.GetCompanyListExport(condition, pars)
  5673. if err != nil {
  5674. br.Msg = "获取失败"
  5675. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  5676. return
  5677. }
  5678. companyIds := make([]int, 0)
  5679. for _, c := range list {
  5680. companyIds = append(companyIds, c.CompanyId)
  5681. }
  5682. // 获取客户对应的阅读和合同权限集合
  5683. contractPermissionMap := make(map[int][]int)
  5684. contractPermissions, e := company.GetContractPermissionIdsByCompanyIds(companyIds)
  5685. if e != nil {
  5686. br.Msg = "获取失败"
  5687. br.ErrMsg = "获取已购权限失败, Err: " + e.Error()
  5688. return
  5689. }
  5690. for _, p := range contractPermissions {
  5691. ids := make([]int, 0)
  5692. if p.ChartPermissionIds != "" {
  5693. idArr := strings.Split(p.ChartPermissionIds, ",")
  5694. for _, i := range idArr {
  5695. id, _ := strconv.Atoi(i)
  5696. ids = append(ids, id)
  5697. }
  5698. }
  5699. contractPermissionMap[p.CompanyId] = ids
  5700. }
  5701. reportPermissionMap := make(map[int][]int)
  5702. reportPermissions, e := company.GetReportPermissionIdsByCompanyIds(companyIds)
  5703. if e != nil {
  5704. br.Msg = "获取失败"
  5705. br.ErrMsg = "获取阅读权限失败, Err: " + e.Error()
  5706. return
  5707. }
  5708. for _, p := range reportPermissions {
  5709. ids := make([]int, 0)
  5710. if p.ChartPermissionIds != "" {
  5711. idArr := strings.Split(p.ChartPermissionIds, ",")
  5712. for _, i := range idArr {
  5713. id, _ := strconv.Atoi(i)
  5714. ids = append(ids, id)
  5715. }
  5716. }
  5717. reportPermissionMap[p.CompanyId] = ids
  5718. }
  5719. cpMap := make(map[int][]*company.ExportCompanyProduct)
  5720. permissionMap := make(map[string]string)
  5721. for _, v := range list {
  5722. cpList := make([]*company.ExportCompanyProduct, 1)
  5723. if cps, ok := cpMap[v.CompanyId]; ok {
  5724. cpList = cps
  5725. } else {
  5726. companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  5727. if err != nil {
  5728. br.Msg = "导出失败"
  5729. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  5730. return
  5731. }
  5732. cpMap[v.CompanyId] = companyProduct
  5733. cpList = companyProduct
  5734. }
  5735. var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, expireDay string
  5736. isFiccSuspend := 0
  5737. isRaiSuspend := 0
  5738. for ck, cv := range cpList {
  5739. companyName = cv.CompanyName
  5740. if ck >= 1 {
  5741. companyType = companyType + "/" + cv.ProductName
  5742. status = status + "/" + cv.Status
  5743. } else {
  5744. companyType = cv.ProductName
  5745. status = cv.Status
  5746. }
  5747. if cv.ProductId == 1 {
  5748. industryName = "ficc:" + cv.IndustryName
  5749. sellerName = "ficc:" + cv.SellerName
  5750. startDateStr := cv.StartDate.Format("2006/01/02")
  5751. endDateStr := cv.EndDate.Format("2006/01/02")
  5752. timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  5753. createTime = "ficc:" + cv.CreateTime
  5754. source = "ficc:" + cv.Source
  5755. sub := cv.EndDate.Sub(time.Now())
  5756. if sub < 0 {
  5757. sub = 0
  5758. }
  5759. expireDay = "ficc:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  5760. permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  5761. permissionStr = "ficc:"
  5762. if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  5763. permissionStr += newPermissionStr
  5764. } else {
  5765. getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  5766. if err != nil {
  5767. br.Msg = "导出失败"
  5768. br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  5769. return
  5770. }
  5771. permissionMap[permissionKey] = getPermissionStr
  5772. permissionStr += getPermissionStr
  5773. }
  5774. isFiccSuspend = cv.IsSuspend
  5775. } else {
  5776. industryName = industryName + "\n" + "权益:" + cv.IndustryName
  5777. sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  5778. startDateStr := cv.StartDate.Format("2006/01/02")
  5779. endDateStr := cv.EndDate.Format("2006/01/02")
  5780. timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  5781. createTime = createTime + "\n" + "权益:" + cv.CreateTime
  5782. source = source + "\n" + "权益:" + cv.Source
  5783. sub := cv.EndDate.Sub(time.Now())
  5784. if sub < 0 {
  5785. sub = 0
  5786. }
  5787. expireDay = "\n" + "权益:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  5788. permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  5789. if permissionStr != "" {
  5790. permissionStr = permissionStr + "\n" + "权益:"
  5791. } else {
  5792. permissionStr = "权益:"
  5793. }
  5794. if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  5795. permissionStr += newPermissionStr
  5796. } else {
  5797. getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  5798. if err != nil {
  5799. br.Msg = "导出失败"
  5800. br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  5801. return
  5802. }
  5803. permissionMap[permissionKey] = getPermissionStr
  5804. permissionStr += getPermissionStr
  5805. }
  5806. isRaiSuspend = cv.IsSuspend
  5807. }
  5808. }
  5809. dataRow := sheel.AddRow()
  5810. dataRow.SetHeight(20)
  5811. dataRow.AddCell().SetString(companyName)
  5812. dataRow.AddCell().SetString(v.Address)
  5813. dataRow.AddCell().SetString(companyType)
  5814. dataRow.AddCell().SetString(v.IndustryName)
  5815. dataRow.AddCell().SetString(v.SellerName)
  5816. dataRow.AddCell().SetString(v.Status)
  5817. dataRow.AddCell().SetString(timeLimt)
  5818. dataRow.AddCell().SetString(expireDay)
  5819. dataRow.AddCell().SetString(v.CreatedTime)
  5820. //dataRow.AddCell().SetString(v.Source)
  5821. dataRow.AddCell().SetString(permissionStr)
  5822. // 填充空白至Z列, AA列开始为权限
  5823. for i := 0; i < emptyColNum; i++ {
  5824. dataRow.AddCell().SetString("")
  5825. }
  5826. cpIds := contractPermissionMap[v.CompanyId]
  5827. rpIds := reportPermissionMap[v.CompanyId]
  5828. for _, p := range permissions {
  5829. // 数字含义:11-表示已购且有阅读权限, 01-表示未购买但有阅读权限
  5830. first := 0
  5831. if utils.InArrayByInt(cpIds, p.ChartPermissionId) {
  5832. first = 1
  5833. }
  5834. second := 0
  5835. if utils.InArrayByInt(rpIds, p.ChartPermissionId) {
  5836. second = 1
  5837. // 如果客户是试用暂停, 即使有这部分权限, 也标记为0
  5838. if isFiccSuspend == 1 && utils.InArrayByInt(ficcPermissions, p.ChartPermissionId) {
  5839. second = 0
  5840. }
  5841. if isRaiSuspend == 1 && utils.InArrayByInt(raiPermissions, p.ChartPermissionId) {
  5842. second = 0
  5843. }
  5844. }
  5845. dataRow.AddCell().SetString(fmt.Sprintf("%d%d", first, second))
  5846. }
  5847. }
  5848. err = xlsxFile.Save(downLoadnFilePath)
  5849. if err != nil {
  5850. br.Msg = "保存文件失败"
  5851. br.ErrMsg = "保存文件失败"
  5852. return
  5853. }
  5854. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  5855. downloadFileName := "客户列表_" + randStr + ".xlsx"
  5856. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  5857. defer func() {
  5858. os.Remove(downLoadnFilePath)
  5859. }()
  5860. br.Ret = 200
  5861. br.Success = true
  5862. br.Msg = "导出成功"
  5863. }
  5864. //func (this *CompanyController) ExportOld() {
  5865. // br := new(models.BaseResponse).Init()
  5866. // defer func() {
  5867. // this.Data["json"] = br
  5868. // this.ServeJSON()
  5869. // }()
  5870. // sysUser := this.SysUser
  5871. // if sysUser == nil {
  5872. // br.Msg = "请登录"
  5873. // br.ErrMsg = "请登录,SysUser Is Empty"
  5874. // br.Ret = 408
  5875. // return
  5876. // }
  5877. // roleTypeCode := sysUser.RoleTypeCode
  5878. //
  5879. // status := this.GetString("Status")
  5880. // companyType := this.GetString("CompanyType")
  5881. // industryId, _ := this.GetInt("IndustryId")
  5882. // adminId := this.GetString("AdminId")
  5883. //
  5884. // chartPermissionIds := this.GetString("ChartPermissionIds")
  5885. // startDate := this.GetString("StartDate")
  5886. // endDate := this.GetString("EndDate")
  5887. // createStartDate := this.GetString("CreateStartDate")
  5888. // createEndDate := this.GetString("CreateEndDate")
  5889. // keyWord := this.GetString("KeyWord")
  5890. // keyWord = strings.Trim(keyWord, " ")
  5891. //
  5892. // resp := new(company.CompanyListResp)
  5893. // statusItems := make([]*company.CompanyStatus, 0)
  5894. // var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}
  5895. //
  5896. // var condition string
  5897. // var pars []interface{}
  5898. //
  5899. // var lossCondition string
  5900. // var lossPars []interface{}
  5901. //
  5902. // var permissionCondition string
  5903. // var permissionPars []interface{}
  5904. //
  5905. // if status != "" && status != "全部" {
  5906. // condition += ` AND b.status=? `
  5907. // pars = append(pars, status)
  5908. //
  5909. // //permissionCondition += ` AND b.status=? `
  5910. // //permissionPars = append(permissionPars, status)
  5911. // }
  5912. // if companyType != "" {
  5913. // condition += ` AND b.product_name=? `
  5914. // pars = append(pars, companyType)
  5915. //
  5916. // lossCondition += ` AND b.product_name=? `
  5917. // lossPars = append(lossPars, companyType)
  5918. //
  5919. // permissionCondition += ` AND b.product_name=? `
  5920. // permissionPars = append(permissionPars, companyType)
  5921. // }
  5922. //
  5923. // if industryId > 0 {
  5924. // condition += ` AND b.industry_id=? `
  5925. // pars = append(pars, industryId)
  5926. //
  5927. // lossCondition += ` AND b.industry_id=? `
  5928. // lossPars = append(lossPars, industryId)
  5929. //
  5930. // permissionCondition += ` AND b.industry_id=? `
  5931. // permissionPars = append(permissionPars, industryId)
  5932. // }
  5933. //
  5934. // if adminId != "" {
  5935. // condition += ` AND b.seller_id IN (` + adminId + `) `
  5936. //
  5937. // lossCondition += ` AND b.seller_id IN (` + adminId + `) `
  5938. //
  5939. // permissionCondition += ` AND b.seller_id IN (` + adminId + `) `
  5940. // }
  5941. //
  5942. // if startDate != "" {
  5943. // condition += ` AND b.start_date>=? `
  5944. // pars = append(pars, startDate)
  5945. //
  5946. // lossCondition += ` AND b.start_date>=? `
  5947. // lossPars = append(lossPars, startDate)
  5948. //
  5949. // permissionCondition += ` AND b.start_date>=? `
  5950. // permissionPars = append(permissionPars, startDate)
  5951. // }
  5952. //
  5953. // if endDate != "" {
  5954. // condition += ` AND b.end_date<=? `
  5955. // pars = append(pars, endDate)
  5956. //
  5957. // lossCondition += ` AND b.end_date<=? `
  5958. // lossPars = append(lossPars, endDate)
  5959. //
  5960. // permissionCondition += ` AND b.end_date<=? `
  5961. // permissionPars = append(permissionPars, endDate)
  5962. // }
  5963. //
  5964. // if createStartDate != "" {
  5965. // condition += ` AND a.created_time>=? `
  5966. // pars = append(pars, createStartDate)
  5967. //
  5968. // lossCondition += ` AND a.created_time>=? `
  5969. // lossPars = append(lossPars, createStartDate)
  5970. //
  5971. // permissionCondition += ` AND a.created_time>=? `
  5972. // permissionPars = append(permissionPars, createStartDate)
  5973. // }
  5974. //
  5975. // if createEndDate != "" {
  5976. // condition += ` AND a.created_time<=? `
  5977. // pars = append(pars, createEndDate)
  5978. //
  5979. // lossCondition += ` AND a.created_time<=? `
  5980. // lossPars = append(lossPars, createEndDate)
  5981. //
  5982. // permissionCondition += ` AND a.created_time<=? `
  5983. // permissionPars = append(permissionPars, createEndDate)
  5984. // }
  5985. //
  5986. // if keyWord != "" {
  5987. // companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
  5988. // if err != nil {
  5989. // return
  5990. // }
  5991. // if companyIdStr != "" {
  5992. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  5993. // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  5994. //
  5995. // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  5996. // } else {
  5997. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  5998. // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  5999. //
  6000. // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  6001. // }
  6002. // }
  6003. //
  6004. // if chartPermissionIds != "" && chartPermissionIds != "1" {
  6005. // //chartPermissionArr := strings.Split(chartPermissionIds, ",")
  6006. // //chartPermissionCount := len(chartPermissionArr)
  6007. // companyIdStr, err := company.GetCompanyListCompanyIdByPermissionIdStr(chartPermissionIds)
  6008. // if err != nil {
  6009. // br.Msg = "获取失败"
  6010. // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
  6011. // return
  6012. // }
  6013. // //var companyIdArr []string
  6014. // //for _, v := range companyIdList {
  6015. // // companyIdArr = append(companyIdArr, strconv.Itoa(v.CompanyId))
  6016. // //}
  6017. // //companyIdStr := strings.Join(companyIdArr, ",")
  6018. //
  6019. // if companyIdStr != "" {
  6020. // condition += ` AND a.company_id IN (` + companyIdStr + `) `
  6021. // lossCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  6022. // permissionCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  6023. // } else {
  6024. // for _, v := range statusArr {
  6025. // statusCount := new(company.CompanyStatus)
  6026. // if v == "全部" {
  6027. // statusCount.Status = "全部"
  6028. // statusCount.Count = 0
  6029. // } else {
  6030. // statusCount.Status = v
  6031. // statusCount.Count = 0
  6032. // }
  6033. // statusItems = append(statusItems, statusCount)
  6034. // }
  6035. // items := make([]*company.CompanyListItem, 0)
  6036. // resp.List = items
  6037. // resp.StatusCount = statusItems
  6038. // br.Msg = "获取成功"
  6039. // br.Ret = 200
  6040. // br.Data = resp
  6041. // return
  6042. // }
  6043. // }
  6044. //
  6045. // //权限控制
  6046. // {
  6047. // if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  6048. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  6049. // condition += ` AND b.product_id=? `
  6050. // pars = append(pars, 1)
  6051. //
  6052. // permissionCondition += ` AND b.product_id=? `
  6053. // permissionPars = append(permissionPars, 1)
  6054. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  6055. // condition += ` AND b.product_id=? `
  6056. // pars = append(pars, 2)
  6057. //
  6058. // permissionCondition += ` AND b.product_id=? `
  6059. // permissionPars = append(permissionPars, 2)
  6060. // } else {
  6061. // if sysUser.Authority <= 0 {
  6062. // if status != utils.COMPANY_STATUS_LOSE {
  6063. // condition += ` AND b.seller_id=? `
  6064. // pars = append(pars, sysUser.AdminId)
  6065. // }
  6066. //
  6067. // permissionCondition += ` AND b.seller_id=? `
  6068. // permissionPars = append(permissionPars, sysUser.AdminId)
  6069. // } else {
  6070. // if sysUser.Authority == 1 {
  6071. // if status != utils.COMPANY_STATUS_LOSE {
  6072. // condition += ` AND b.department_id=? `
  6073. // pars = append(pars, sysUser.DepartmentId)
  6074. // }
  6075. // permissionCondition += ` AND b.department_id=? `
  6076. // permissionPars = append(permissionPars, sysUser.DepartmentId)
  6077. // }
  6078. //
  6079. // if sysUser.Authority == 2 {
  6080. // if status != utils.COMPANY_STATUS_LOSE {
  6081. // condition += ` AND b.group_id=? `
  6082. // pars = append(pars, sysUser.GroupId)
  6083. // }
  6084. // permissionCondition += ` AND b.group_id=? `
  6085. // permissionPars = append(permissionPars, sysUser.GroupId)
  6086. // }
  6087. // }
  6088. // }
  6089. // }
  6090. // }
  6091. //
  6092. // dir, err := os.Executable()
  6093. // exPath := filepath.Dir(dir)
  6094. // downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  6095. // xlsxFile := xlsx.NewFile()
  6096. // if err != nil {
  6097. // br.Msg = "生成文件失败"
  6098. // br.ErrMsg = "生成文件失败"
  6099. // return
  6100. // }
  6101. // style := xlsx.NewStyle()
  6102. // alignment := xlsx.Alignment{
  6103. // Horizontal: "center",
  6104. // Vertical: "center",
  6105. // WrapText: true,
  6106. // }
  6107. //
  6108. // style.Alignment = alignment
  6109. // style.ApplyAlignment = true
  6110. //
  6111. // sheel, err := xlsxFile.AddSheet("客户数据")
  6112. // if err != nil {
  6113. // br.Msg = "新增Sheet失败"
  6114. // br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  6115. // return
  6116. // }
  6117. // titleRow := sheel.AddRow()
  6118. // titleRow.AddCell().SetValue("客户名称")
  6119. // titleRow.AddCell().SetValue("客户类型")
  6120. // titleRow.AddCell().SetValue("所属行业")
  6121. // titleRow.AddCell().SetValue("所属销售")
  6122. // titleRow.AddCell().SetValue("客户状态")
  6123. // titleRow.AddCell().SetValue("服务期限")
  6124. // titleRow.AddCell().SetValue("到期天数")
  6125. // titleRow.AddCell().SetValue("创建时间")
  6126. // titleRow.AddCell().SetValue("客户来源")
  6127. // titleRow.AddCell().SetValue("阅读权限")
  6128. //
  6129. // list, err := company.GetCompanyListExport(condition, pars)
  6130. // if err != nil {
  6131. // br.Msg = "获取失败"
  6132. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  6133. // return
  6134. // }
  6135. // cpMap := make(map[int][]*company.ExportCompanyProduct)
  6136. // permissionMap := make(map[string]string)
  6137. // for _, v := range list {
  6138. // cpList := make([]*company.ExportCompanyProduct, 1)
  6139. // if cps, ok := cpMap[v.CompanyId]; ok {
  6140. // cpList = cps
  6141. // } else {
  6142. // companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  6143. // if err != nil {
  6144. // br.Msg = "导出失败"
  6145. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  6146. // return
  6147. // }
  6148. // cpMap[v.CompanyId] = companyProduct
  6149. // cpList = companyProduct
  6150. // }
  6151. // var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, expireDay string
  6152. //
  6153. // for ck, cv := range cpList {
  6154. // companyName = cv.CompanyName
  6155. // if ck >= 1 {
  6156. // companyType = companyType + "/" + cv.ProductName
  6157. // status = status + "/" + cv.Status
  6158. // } else {
  6159. // companyType = cv.ProductName
  6160. // status = cv.Status
  6161. // }
  6162. // if cv.ProductId == 1 {
  6163. // industryName = "ficc:" + cv.IndustryName
  6164. // sellerName = "ficc:" + cv.SellerName
  6165. // startDateStr := cv.StartDate.Format("2006/01/02")
  6166. // endDateStr := cv.EndDate.Format("2006/01/02")
  6167. // timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  6168. // createTime = "ficc:" + cv.CreateTime
  6169. // source = "ficc:" + cv.Source
  6170. // sub := cv.EndDate.Sub(time.Now())
  6171. // if sub < 0 {
  6172. // sub = 0
  6173. // }
  6174. // expireDay = "ficc:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  6175. //
  6176. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6177. //
  6178. // permissionStr = "ficc:"
  6179. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6180. // permissionStr += newPermissionStr
  6181. // } else {
  6182. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6183. // if err != nil {
  6184. // br.Msg = "导出失败"
  6185. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6186. // return
  6187. // }
  6188. // permissionMap[permissionKey] = getPermissionStr
  6189. // permissionStr += getPermissionStr
  6190. // }
  6191. // } else {
  6192. // industryName = industryName + "\n" + "权益:" + cv.IndustryName
  6193. // sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  6194. // startDateStr := cv.StartDate.Format("2006/01/02")
  6195. // endDateStr := cv.EndDate.Format("2006/01/02")
  6196. //
  6197. // timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  6198. // createTime = createTime + "\n" + "权益:" + cv.CreateTime
  6199. // source = source + "\n" + "权益:" + cv.Source
  6200. //
  6201. // sub := cv.EndDate.Sub(time.Now())
  6202. // if sub < 0 {
  6203. // sub = 0
  6204. // }
  6205. // expireDay = "\n" + "权益:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  6206. //
  6207. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6208. // if permissionStr != "" {
  6209. // permissionStr = permissionStr + "\n" + "权益:"
  6210. // } else {
  6211. // permissionStr = "权益:"
  6212. // }
  6213. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6214. // permissionStr += newPermissionStr
  6215. // } else {
  6216. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6217. // if err != nil {
  6218. // br.Msg = "导出失败"
  6219. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6220. // return
  6221. // }
  6222. // permissionMap[permissionKey] = getPermissionStr
  6223. // permissionStr += getPermissionStr
  6224. // }
  6225. // }
  6226. // }
  6227. //
  6228. // dataRow := sheel.AddRow()
  6229. // dataRow.SetHeight(20)
  6230. // dataRow.AddCell().SetString(companyName)
  6231. // dataRow.AddCell().SetString(companyType)
  6232. // dataRow.AddCell().SetString(v.IndustryName)
  6233. // dataRow.AddCell().SetString(v.SellerName)
  6234. // dataRow.AddCell().SetString(v.Status)
  6235. // dataRow.AddCell().SetString(timeLimt)
  6236. // dataRow.AddCell().SetString(expireDay)
  6237. // dataRow.AddCell().SetString(v.CreatedTime)
  6238. // dataRow.AddCell().SetString(v.Source)
  6239. // dataRow.AddCell().SetString(permissionStr)
  6240. // }
  6241. // err = xlsxFile.Save(downLoadnFilePath)
  6242. // if err != nil {
  6243. // br.Msg = "保存文件失败"
  6244. // br.ErrMsg = "保存文件失败"
  6245. // return
  6246. // }
  6247. // randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  6248. // downloadFileName := "客户列表_" + randStr + ".xlsx"
  6249. // this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  6250. // defer func() {
  6251. // os.Remove(downLoadnFilePath)
  6252. // }()
  6253. // br.Ret = 200
  6254. // br.Success = true
  6255. // br.Msg = "导出成功"
  6256. //}
  6257. // @Title 导出
  6258. // @Description 导出接口
  6259. // @Param Status query string true "状态:”试用','永续','冻结','流失','正式'"
  6260. // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
  6261. // @Param IndustryId query int true "行业id,0为全部"
  6262. // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
  6263. // @Param ChartPermissionIds query string false "阅读权限品种ID,多个用英文逗号分开,空字符串为全部"
  6264. // @Param ContractPermissionIds query string false "已购品种ID,多个用英文逗号分开,空字符串为全部"
  6265. // @Param StartDate query string true "开始时间"
  6266. // @Param EndDate query string true "结束时间"
  6267. // @Param KeyWord query string true "搜索关键词"
  6268. // @Param Address query string true "地址 , 多个用英文逗号分开 "
  6269. // @Param Province query string true "省 , 多个用英文逗号分开 "
  6270. // @Param City query string true "市 , 多个用英文逗号分开 "
  6271. // @Param PackageType query int true "套餐类型,0:无,1:大套餐,2:小套餐"
  6272. // @Success Ret=200 移动成功
  6273. // @router /user/export [get]
  6274. func (this *CompanyController) CompanyUserExport() {
  6275. br := new(models.BaseResponse).Init()
  6276. defer func() {
  6277. this.Data["json"] = br
  6278. this.ServeJSON()
  6279. }()
  6280. sysUser := this.SysUser
  6281. if sysUser == nil {
  6282. br.Msg = "请登录"
  6283. br.ErrMsg = "请登录,SysUser Is Empty"
  6284. br.Ret = 408
  6285. return
  6286. }
  6287. roleTypeCode := sysUser.RoleTypeCode
  6288. status := this.GetString("Status")
  6289. companyType := this.GetString("CompanyType")
  6290. industryId, _ := this.GetInt("IndustryId")
  6291. adminId := this.GetString("AdminId")
  6292. chartPermissionIds := this.GetString("ChartPermissionIds")
  6293. contractPermissionIds := this.GetString("ContractPermissionIds")
  6294. startDate := this.GetString("StartDate")
  6295. endDate := this.GetString("EndDate")
  6296. createStartDate := this.GetString("CreateStartDate")
  6297. createEndDate := this.GetString("CreateEndDate")
  6298. keyWord := this.GetString("KeyWord")
  6299. address := this.GetString("Address")
  6300. province := this.GetString("Province")
  6301. city := this.GetString("City")
  6302. // 套餐类型
  6303. packageType, _ := this.GetInt("PackageType")
  6304. var condition string
  6305. var pars []interface{}
  6306. if status != "" && status != "全部" {
  6307. condition += ` AND b.status=? `
  6308. pars = append(pars, status)
  6309. }
  6310. if companyType != "" {
  6311. condition += ` AND b.product_name=? `
  6312. pars = append(pars, companyType)
  6313. }
  6314. if industryId > 0 {
  6315. condition += ` AND b.industry_id=? `
  6316. pars = append(pars, industryId)
  6317. }
  6318. if adminId != "" {
  6319. condition += ` AND b.seller_id IN (` + adminId + `) `
  6320. }
  6321. if startDate != "" {
  6322. condition += ` AND b.start_date>=? `
  6323. pars = append(pars, startDate)
  6324. }
  6325. if endDate != "" {
  6326. condition += ` AND b.end_date<=? `
  6327. pars = append(pars, endDate)
  6328. }
  6329. if createStartDate != "" {
  6330. condition += ` AND a.created_time>=? `
  6331. pars = append(pars, createStartDate)
  6332. }
  6333. if createEndDate != "" {
  6334. condition += ` AND a.created_time<=? `
  6335. pars = append(pars, createEndDate)
  6336. }
  6337. if keyWord != "" {
  6338. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR c.mobile LIKE '%` + keyWord + `%' OR c.email LIKE '%` + keyWord + `%') `
  6339. }
  6340. // 阅读权限/已购品种筛选
  6341. cond, emp, e := services.FilterReadAndContractAuth(chartPermissionIds, contractPermissionIds, condition)
  6342. if e != nil {
  6343. br.Msg = "获取失败"
  6344. br.ErrMsg = "FilterReadAndContractAuth err: " + e.Error()
  6345. return
  6346. }
  6347. if emp {
  6348. condition += ` AND 1 = 2`
  6349. } else {
  6350. condition = cond
  6351. }
  6352. if address != "" {
  6353. var addressSql string
  6354. slice := strings.Split(address, ",")
  6355. for _, v := range slice {
  6356. addressSql += "'" + v + "'" + ","
  6357. }
  6358. addressSql = strings.TrimRight(addressSql, ",")
  6359. condition += ` AND a.address IN (` + addressSql + `) `
  6360. }
  6361. if province != "" {
  6362. var provinceSql string
  6363. slice := strings.Split(province, ",")
  6364. for _, v := range slice {
  6365. provinceSql += "'" + v + "'" + ","
  6366. }
  6367. provinceSql = strings.TrimRight(provinceSql, ",")
  6368. condition += ` AND a.province IN (` + provinceSql + `) `
  6369. }
  6370. if city != "" {
  6371. var citySql string
  6372. slice := strings.Split(city, ",")
  6373. for _, v := range slice {
  6374. citySql += "'" + v + "'" + ","
  6375. }
  6376. citySql = strings.TrimRight(citySql, ",")
  6377. condition += ` AND a.city IN (` + citySql + `) `
  6378. }
  6379. //套餐类型
  6380. if packageType > 0 {
  6381. condition += ` AND b.package_type=? `
  6382. pars = append(pars, packageType)
  6383. }
  6384. //权限控制
  6385. {
  6386. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  6387. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  6388. if status != utils.COMPANY_STATUS_LOSE && status != utils.COMPANY_STATUS_FOREVER {
  6389. condition += ` AND b.seller_id=? `
  6390. pars = append(pars, sysUser.AdminId)
  6391. }
  6392. }
  6393. if sysUser.Authority == 1 {
  6394. condition += ` AND b.department_id=? `
  6395. pars = append(pars, sysUser.DepartmentId)
  6396. }
  6397. if sysUser.Authority == 2 {
  6398. condition += ` AND b.group_id=? `
  6399. pars = append(pars, sysUser.GroupId)
  6400. }
  6401. }
  6402. var statusCond string
  6403. var statusPars []interface{}
  6404. // 根据当前用户角色
  6405. productId := services.GetProductId(roleTypeCode)
  6406. if productId > 0 {
  6407. condition += ` AND b.product_id = ? `
  6408. pars = append(pars, productId)
  6409. statusCond += ` AND b.product_id = ? `
  6410. statusPars = append(statusPars, productId)
  6411. }
  6412. companyIds, err := company.GetExportCompanyIds(condition, pars)
  6413. if err != nil {
  6414. br.Msg = "导出失败"
  6415. br.ErrMsg = "导出失败,Err:" + err.Error()
  6416. return
  6417. }
  6418. dir, err := os.Executable()
  6419. exPath := filepath.Dir(dir)
  6420. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  6421. xlsxFile := xlsx.NewFile()
  6422. if err != nil {
  6423. br.Msg = "生成文件失败"
  6424. br.ErrMsg = "生成文件失败"
  6425. return
  6426. }
  6427. style := xlsx.NewStyle()
  6428. alignment := xlsx.Alignment{
  6429. Horizontal: "center",
  6430. Vertical: "center",
  6431. WrapText: true,
  6432. }
  6433. style.Alignment = alignment
  6434. style.ApplyAlignment = true
  6435. sheel, err := xlsxFile.AddSheet("联系人数据")
  6436. if err != nil {
  6437. br.Msg = "新增Sheet失败"
  6438. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  6439. return
  6440. }
  6441. sheel.SetColWidth(7, 7, 10)
  6442. sheel.SetColWidth(8, 10, 16)
  6443. sheel.SetColWidth(9, 11, 20)
  6444. sheel.SetColWidth(12, 12, 35)
  6445. sheel.SetColWidth(13, 13, 15)
  6446. sheel.SetColWidth(14, 14, 80)
  6447. titleRow := sheel.AddRow()
  6448. titleRow.AddCell().SetValue("联系人")
  6449. titleRow.AddCell().SetValue("是否关注公众号")
  6450. titleRow.AddCell().SetValue("手机号")
  6451. titleRow.AddCell().SetValue("邮箱")
  6452. //titleRow.AddCell().SetValue("职位")
  6453. titleRow.AddCell().SetValue("是否决策人")
  6454. //titleRow.AddCell().SetValue("客户部门")
  6455. titleRow.AddCell().SetValue("客户名称")
  6456. titleRow.AddCell().SetValue("客户状态")
  6457. //titleRow.AddCell().SetValue("社会信用码")
  6458. //titleRow.AddCell().SetValue("所属区域")
  6459. //titleRow.AddCell().SetValue("客户类型")
  6460. //industryCell := titleRow.AddCell()
  6461. //industryCell.SetStyle(style)
  6462. //industryCell.Value = "所属行业"
  6463. //
  6464. //sellerCell := titleRow.AddCell()
  6465. //sellerCell.SetStyle(style)
  6466. //sellerCell.Value = "所属销售"
  6467. //
  6468. //statusCell := titleRow.AddCell()
  6469. //statusCell.SetStyle(style)
  6470. //statusCell.Value = "客户状态"
  6471. //
  6472. //timeLimtCell := titleRow.AddCell()
  6473. //timeLimtCell.SetStyle(style)
  6474. //timeLimtCell.Value = "服务期限"
  6475. //
  6476. //createTimeCell := titleRow.AddCell()
  6477. //createTimeCell.SetStyle(style)
  6478. //createTimeCell.Value = "创建时间"
  6479. //
  6480. //sourceCell := titleRow.AddCell()
  6481. //sourceCell.SetStyle(style)
  6482. //sourceCell.Value = "客户来源"
  6483. //permissionStyle := xlsx.NewStyle()
  6484. //permissionAlignment := xlsx.Alignment{
  6485. // Horizontal: "center",
  6486. // Vertical: "center",
  6487. // WrapText: true,
  6488. //}
  6489. //
  6490. //permissionStyle.Alignment = permissionAlignment
  6491. //permissionStyle.ApplyAlignment = true
  6492. //permissionCell := titleRow.AddCell()
  6493. //permissionCell.SetStyle(permissionStyle)
  6494. //permissionCell.Value = "阅读权限"
  6495. users := make([]*company.ExportUser, 0)
  6496. if companyIds != "" {
  6497. companyIds = strings.Trim(companyIds, ",")
  6498. if productId > 0 {
  6499. users, err = company.GetExportUserByProductId(companyIds, productId)
  6500. if err != nil {
  6501. br.Msg = "导出失败"
  6502. br.ErrMsg = "获取联系人信息失败,Err:" + err.Error()
  6503. return
  6504. }
  6505. } else {
  6506. users, err = company.GetExportUser(companyIds)
  6507. if err != nil {
  6508. br.Msg = "导出失败"
  6509. br.ErrMsg = "获取联系人信息失败,Err:" + err.Error()
  6510. return
  6511. }
  6512. }
  6513. // 获取客户状态
  6514. companyIntIds := make([]int, 0)
  6515. companyIdArr := strings.Split(companyIds, ",")
  6516. for _, c := range companyIdArr {
  6517. id, e := strconv.Atoi(c)
  6518. if e != nil {
  6519. br.Msg = "导出失败"
  6520. br.ErrMsg = "客户ID有误"
  6521. return
  6522. }
  6523. companyIntIds = append(companyIntIds, id)
  6524. }
  6525. if len(companyIntIds) > 0 {
  6526. statusCond += fmt.Sprintf(` AND a.company_id IN (%s) `, utils.GetOrmInReplace(len(companyIntIds)))
  6527. statusPars = append(statusPars, companyIntIds)
  6528. }
  6529. statusMap := make(map[int]string)
  6530. nameMap := make(map[int]string)
  6531. companyStatusList, e := company.GetExportUserCompanyStatus(statusCond, statusPars)
  6532. if e != nil {
  6533. br.Msg = "导出失败"
  6534. br.ErrMsg = "获取客户状态失败, Err: " + e.Error()
  6535. return
  6536. }
  6537. for _, s := range companyStatusList {
  6538. statusMap[s.CompanyId] = s.CompanyStatus
  6539. nameMap[s.CompanyId] = s.CompanyName
  6540. }
  6541. //cpMap := make(map[int][]*company.ExportCompanyProduct)
  6542. //permissionMap := make(map[string]string)
  6543. for _, v := range users {
  6544. dataRow := sheel.AddRow()
  6545. dataRow.SetHeight(20)
  6546. dataRow.AddCell().SetString(v.RealName)
  6547. if v.IsSubscribe == 1 {
  6548. dataRow.AddCell().SetString("是") // 是否关注公众号
  6549. } else {
  6550. dataRow.AddCell().SetString("")
  6551. }
  6552. dataRow.AddCell().SetString(v.Mobile)
  6553. dataRow.AddCell().SetString(v.Email)
  6554. //dataRow.AddCell().SetString(v.Position)
  6555. if v.IsMaker == 1 {
  6556. dataRow.AddCell().SetString("是")
  6557. } else {
  6558. dataRow.AddCell().SetString("否")
  6559. }
  6560. //dataRow.AddCell().SetString(v.DepartmentName)
  6561. //cpList := make([]*company.ExportCompanyProduct, 1)
  6562. //if cps, ok := cpMap[v.CompanyId]; ok {
  6563. // cpList = cps
  6564. //} else {
  6565. // companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  6566. // if err != nil {
  6567. // br.Msg = "导出失败"
  6568. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  6569. // return
  6570. // }
  6571. // cpMap[v.CompanyId] = companyProduct
  6572. // cpList = companyProduct
  6573. //}
  6574. //productList, err := company.GetExportCompanyProduct(v.CompanyId)
  6575. //if err!=nil {
  6576. // fmt.Println("导出失败,Err:"+err.Error())
  6577. // return
  6578. //}
  6579. //var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, creditCode, regionType string
  6580. //for ck, cv := range cpList {
  6581. // companyName = cv.CompanyName
  6582. // creditCode = cv.CreditCode
  6583. // regionType = cv.RegionType
  6584. // if ck >= 1 {
  6585. // companyType = companyType + "/" + cv.ProductName
  6586. // status = status + "/" + cv.Status
  6587. // } else {
  6588. // companyType = cv.ProductName
  6589. // status = cv.Status
  6590. // }
  6591. // if cv.ProductId == 1 {
  6592. // industryName = "ficc:" + cv.IndustryName
  6593. // sellerName = "ficc:" + cv.SellerName
  6594. // startDateStr := cv.StartDate.Format("2006/01/02")
  6595. // endDateStr := cv.EndDate.Format("2006/01/02")
  6596. // if startDateStr != "0001/01/01" {
  6597. // timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  6598. // } else {
  6599. // timeLimt = ""
  6600. // }
  6601. // createTime = "ficc:" + cv.CreateTime
  6602. // source = "ficc:" + cv.Source
  6603. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6604. //
  6605. // permissionStr = "ficc:"
  6606. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6607. // permissionStr += newPermissionStr
  6608. // } else {
  6609. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6610. // if err != nil {
  6611. // br.Msg = "导出失败"
  6612. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6613. // return
  6614. // }
  6615. // permissionMap[permissionKey] = getPermissionStr
  6616. // permissionStr += getPermissionStr
  6617. // }
  6618. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  6619. // permissionStr = ""
  6620. // }
  6621. // } else {
  6622. // industryName = industryName + "\n" + "权益:" + cv.IndustryName
  6623. // sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  6624. // startDateStr := cv.StartDate.Format("2006/01/02")
  6625. // endDateStr := cv.EndDate.Format("2006/01/02")
  6626. //
  6627. // if startDateStr != "0001/01/01" {
  6628. // timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  6629. // } else {
  6630. // timeLimt = timeLimt + ""
  6631. // }
  6632. // createTime = createTime + "\n" + "权益:" + cv.CreateTime
  6633. // source = source + "\n" + "权益:" + cv.Source
  6634. //
  6635. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6636. // if permissionStr != "" {
  6637. // permissionStr = permissionStr + "\n" + "权益:"
  6638. // } else {
  6639. // permissionStr = "权益:"
  6640. // }
  6641. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6642. // permissionStr += newPermissionStr
  6643. // } else {
  6644. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6645. // if err != nil {
  6646. // br.Msg = "导出失败"
  6647. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6648. // return
  6649. // }
  6650. // permissionMap[permissionKey] = getPermissionStr
  6651. // permissionStr += getPermissionStr
  6652. // }
  6653. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  6654. // permissionStr = permissionStr + ""
  6655. // }
  6656. // }
  6657. //}
  6658. // 2023-0420这是谁写的循环查,顺手优化了一下,手动狗头-_-~
  6659. //companyInfo, err := company.GetCompanyById(v.CompanyId)
  6660. //if err != nil {
  6661. // br.Msg = "导出失败"
  6662. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  6663. // return
  6664. //}
  6665. dataRow.AddCell().SetString(nameMap[v.CompanyId])
  6666. dataRow.AddCell().SetString(statusMap[v.CompanyId]) // 客户状态
  6667. //dataRow.AddCell().SetString(creditCode)
  6668. //dataRow.AddCell().SetString(regionType)
  6669. //
  6670. //dataRow.AddCell().SetString(companyType)
  6671. //industryValueCell := dataRow.AddCell()
  6672. //industryValueCell.SetStyle(style)
  6673. //industryValueCell.SetString(industryName)
  6674. //
  6675. //sellerValueCell := dataRow.AddCell()
  6676. //sellerValueCell.SetStyle(style)
  6677. //sellerValueCell.SetString(sellerName)
  6678. //
  6679. //statusValueCell := dataRow.AddCell()
  6680. //statusValueCell.SetStyle(style)
  6681. //statusValueCell.SetValue(status)
  6682. //
  6683. //timeLimitValueCell := dataRow.AddCell()
  6684. //timeLimitValueCell.SetStyle(style)
  6685. //timeLimitValueCell.SetValue(timeLimt)
  6686. //
  6687. //createTimeValueCell := dataRow.AddCell()
  6688. //createTimeValueCell.SetStyle(style)
  6689. //createTimeValueCell.SetValue(createTime)
  6690. //
  6691. //sourceValueCell := dataRow.AddCell()
  6692. //sourceValueCell.SetStyle(style)
  6693. //sourceValueCell.SetValue(source)
  6694. //
  6695. //permissionStrValueCell := dataRow.AddCell()
  6696. //permissionStrValueCell.SetStyle(style)
  6697. //permissionStrValueCell.SetValue(permissionStr)
  6698. }
  6699. }
  6700. err = xlsxFile.Save(downLoadnFilePath)
  6701. if err != nil {
  6702. br.Msg = "保存文件失败"
  6703. br.ErrMsg = "保存文件失败"
  6704. return
  6705. }
  6706. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  6707. downloadFileName := "联系人列表" + randStr + ".xlsx"
  6708. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  6709. defer func() {
  6710. os.Remove(downLoadnFilePath)
  6711. }()
  6712. br.Ret = 200
  6713. br.Success = true
  6714. br.Msg = "导出成功"
  6715. }
  6716. //func (this *CompanyController) CompanyUserExportOld() {
  6717. // br := new(models.BaseResponse).Init()
  6718. // defer func() {
  6719. // this.Data["json"] = br
  6720. // this.ServeJSON()
  6721. // }()
  6722. // sysUser := this.SysUser
  6723. // if sysUser == nil {
  6724. // br.Msg = "请登录"
  6725. // br.ErrMsg = "请登录,SysUser Is Empty"
  6726. // br.Ret = 408
  6727. // return
  6728. // }
  6729. // roleTypeCode := sysUser.RoleTypeCode
  6730. // status := this.GetString("Status")
  6731. // companyType := this.GetString("CompanyType")
  6732. // industryId, _ := this.GetInt("IndustryId")
  6733. // adminId := this.GetString("AdminId")
  6734. //
  6735. // chartPermissionIds := this.GetString("ChartPermissionIds")
  6736. // startDate := this.GetString("StartDate")
  6737. // endDate := this.GetString("EndDate")
  6738. // keyWord := this.GetString("KeyWord")
  6739. //
  6740. // var condition string
  6741. // var pars []interface{}
  6742. //
  6743. // if status != "" && status != "全部" {
  6744. // condition += ` AND b.status=? `
  6745. // pars = append(pars, status)
  6746. // }
  6747. // if companyType != "" {
  6748. // condition += ` AND b.product_name=? `
  6749. // pars = append(pars, companyType)
  6750. // }
  6751. //
  6752. // if industryId > 0 {
  6753. // condition += ` AND b.industry_id=? `
  6754. // pars = append(pars, industryId)
  6755. // }
  6756. //
  6757. // if adminId != "" {
  6758. // condition += ` AND b.seller_id IN (` + adminId + `) `
  6759. // }
  6760. //
  6761. // if startDate != "" {
  6762. // condition += ` AND b.start_date>=? `
  6763. // pars = append(pars, startDate)
  6764. // }
  6765. //
  6766. // if endDate != "" {
  6767. // condition += ` AND b.end_date>=? `
  6768. // pars = append(pars, endDate)
  6769. // }
  6770. //
  6771. // if keyWord != "" {
  6772. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR c.mobile LIKE '%` + keyWord + `%' OR c.email LIKE '%` + keyWord + `%') `
  6773. // }
  6774. //
  6775. // if chartPermissionIds != "" {
  6776. // companyIdStr, err := company.GetCompanyIdStr(chartPermissionIds)
  6777. // if err != nil {
  6778. // br.Msg = "获取失败"
  6779. // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
  6780. // return
  6781. // }
  6782. // if companyIdStr != "" {
  6783. // condition += ` AND a.company_id IN (` + companyIdStr + `) `
  6784. // }
  6785. // }
  6786. //
  6787. // //权限控制
  6788. // {
  6789. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  6790. // roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  6791. // if status != utils.COMPANY_STATUS_LOSE && status != utils.COMPANY_STATUS_FOREVER {
  6792. // condition += ` AND b.seller_id=? `
  6793. // pars = append(pars, sysUser.AdminId)
  6794. // }
  6795. // }
  6796. // if sysUser.Authority == 1 {
  6797. // condition += ` AND b.department_id=? `
  6798. // pars = append(pars, sysUser.DepartmentId)
  6799. // }
  6800. //
  6801. // if sysUser.Authority == 2 {
  6802. // condition += ` AND b.group_id=? `
  6803. // pars = append(pars, sysUser.GroupId)
  6804. // }
  6805. // }
  6806. // companyIds, err := company.GetExportCompanyIds(condition, pars)
  6807. // if err != nil {
  6808. // br.Msg = "导出失败"
  6809. // br.ErrMsg = "导出失败,Err:" + err.Error()
  6810. // return
  6811. // }
  6812. //
  6813. // dir, err := os.Executable()
  6814. // exPath := filepath.Dir(dir)
  6815. //
  6816. // downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  6817. // xlsxFile := xlsx.NewFile()
  6818. // if err != nil {
  6819. // br.Msg = "生成文件失败"
  6820. // br.ErrMsg = "生成文件失败"
  6821. // return
  6822. // }
  6823. // style := xlsx.NewStyle()
  6824. // alignment := xlsx.Alignment{
  6825. // Horizontal: "center",
  6826. // Vertical: "center",
  6827. // WrapText: true,
  6828. // }
  6829. //
  6830. // style.Alignment = alignment
  6831. // style.ApplyAlignment = true
  6832. //
  6833. // sheel, err := xlsxFile.AddSheet("联系人数据")
  6834. // if err != nil {
  6835. // br.Msg = "新增Sheet失败"
  6836. // br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  6837. // return
  6838. // }
  6839. //
  6840. // sheel.SetColWidth(7, 7, 10)
  6841. // sheel.SetColWidth(8, 10, 16)
  6842. // sheel.SetColWidth(9, 11, 20)
  6843. // sheel.SetColWidth(12, 12, 35)
  6844. // sheel.SetColWidth(13, 13, 15)
  6845. // sheel.SetColWidth(14, 14, 80)
  6846. // titleRow := sheel.AddRow()
  6847. // titleRow.AddCell().SetValue("联系人")
  6848. // titleRow.AddCell().SetValue("手机号")
  6849. // titleRow.AddCell().SetValue("邮箱")
  6850. // titleRow.AddCell().SetValue("职位")
  6851. // titleRow.AddCell().SetValue("是否决策人")
  6852. // titleRow.AddCell().SetValue("客户部门")
  6853. // titleRow.AddCell().SetValue("客户名称")
  6854. // titleRow.AddCell().SetValue("社会信用码")
  6855. // titleRow.AddCell().SetValue("所属区域")
  6856. // titleRow.AddCell().SetValue("客户类型")
  6857. //
  6858. // industryCell := titleRow.AddCell()
  6859. // industryCell.SetStyle(style)
  6860. // industryCell.Value = "所属行业"
  6861. //
  6862. // sellerCell := titleRow.AddCell()
  6863. // sellerCell.SetStyle(style)
  6864. // sellerCell.Value = "所属销售"
  6865. //
  6866. // statusCell := titleRow.AddCell()
  6867. // statusCell.SetStyle(style)
  6868. // statusCell.Value = "客户状态"
  6869. //
  6870. // timeLimtCell := titleRow.AddCell()
  6871. // timeLimtCell.SetStyle(style)
  6872. // timeLimtCell.Value = "服务期限"
  6873. //
  6874. // createTimeCell := titleRow.AddCell()
  6875. // createTimeCell.SetStyle(style)
  6876. // createTimeCell.Value = "创建时间"
  6877. //
  6878. // sourceCell := titleRow.AddCell()
  6879. // sourceCell.SetStyle(style)
  6880. // sourceCell.Value = "客户来源"
  6881. //
  6882. // permissionStyle := xlsx.NewStyle()
  6883. // permissionAlignment := xlsx.Alignment{
  6884. // Horizontal: "center",
  6885. // Vertical: "center",
  6886. // WrapText: true,
  6887. // }
  6888. //
  6889. // permissionStyle.Alignment = permissionAlignment
  6890. // permissionStyle.ApplyAlignment = true
  6891. //
  6892. // permissionCell := titleRow.AddCell()
  6893. // permissionCell.SetStyle(permissionStyle)
  6894. // permissionCell.Value = "阅读权限"
  6895. //
  6896. // if companyIds != "" {
  6897. // companyIds = strings.Trim(companyIds, ",")
  6898. // users, err := company.GetExportUser(companyIds)
  6899. // if err != nil {
  6900. // br.Msg = "导出失败"
  6901. // br.ErrMsg = "获取联系人信息失败,Err:" + err.Error()
  6902. // return
  6903. // }
  6904. // cpMap := make(map[int][]*company.ExportCompanyProduct)
  6905. // permissionMap := make(map[string]string)
  6906. // for _, v := range users {
  6907. // dataRow := sheel.AddRow()
  6908. // dataRow.SetHeight(20)
  6909. // dataRow.AddCell().SetString(v.RealName)
  6910. // dataRow.AddCell().SetString(v.Mobile)
  6911. // dataRow.AddCell().SetString(v.Email)
  6912. // dataRow.AddCell().SetString(v.Position)
  6913. // if v.IsMaker == 1 {
  6914. // dataRow.AddCell().SetString("是")
  6915. // } else {
  6916. // dataRow.AddCell().SetString("否")
  6917. // }
  6918. // dataRow.AddCell().SetString(v.DepartmentName)
  6919. // cpList := make([]*company.ExportCompanyProduct, 1)
  6920. // if cps, ok := cpMap[v.CompanyId]; ok {
  6921. // cpList = cps
  6922. // } else {
  6923. // companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  6924. // if err != nil {
  6925. // br.Msg = "导出失败"
  6926. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  6927. // return
  6928. // }
  6929. // cpMap[v.CompanyId] = companyProduct
  6930. // cpList = companyProduct
  6931. // }
  6932. // //productList, err := company.GetExportCompanyProduct(v.CompanyId)
  6933. // //if err!=nil {
  6934. // // fmt.Println("导出失败,Err:"+err.Error())
  6935. // // return
  6936. // //}
  6937. // var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, creditCode, regionType string
  6938. //
  6939. // for ck, cv := range cpList {
  6940. // companyName = cv.CompanyName
  6941. // creditCode = cv.CreditCode
  6942. // regionType = cv.RegionType
  6943. // if ck >= 1 {
  6944. // companyType = companyType + "/" + cv.ProductName
  6945. // status = status + "/" + cv.Status
  6946. // } else {
  6947. // companyType = cv.ProductName
  6948. // status = cv.Status
  6949. // }
  6950. // if cv.ProductId == 1 {
  6951. // industryName = "ficc:" + cv.IndustryName
  6952. // sellerName = "ficc:" + cv.SellerName
  6953. // startDateStr := cv.StartDate.Format("2006/01/02")
  6954. // endDateStr := cv.EndDate.Format("2006/01/02")
  6955. // if startDateStr != "0001/01/01" {
  6956. // timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  6957. // } else {
  6958. // timeLimt = ""
  6959. // }
  6960. // createTime = "ficc:" + cv.CreateTime
  6961. // source = "ficc:" + cv.Source
  6962. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6963. //
  6964. // permissionStr = "ficc:"
  6965. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6966. // permissionStr += newPermissionStr
  6967. // } else {
  6968. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6969. // if err != nil {
  6970. // br.Msg = "导出失败"
  6971. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6972. // return
  6973. // }
  6974. // permissionMap[permissionKey] = getPermissionStr
  6975. // permissionStr += getPermissionStr
  6976. // }
  6977. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  6978. // permissionStr = ""
  6979. // }
  6980. // } else {
  6981. // industryName = industryName + "\n" + "权益:" + cv.IndustryName
  6982. // sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  6983. // startDateStr := cv.StartDate.Format("2006/01/02")
  6984. // endDateStr := cv.EndDate.Format("2006/01/02")
  6985. //
  6986. // if startDateStr != "0001/01/01" {
  6987. // timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  6988. // } else {
  6989. // timeLimt = timeLimt + ""
  6990. // }
  6991. // createTime = createTime + "\n" + "权益:" + cv.CreateTime
  6992. // source = source + "\n" + "权益:" + cv.Source
  6993. //
  6994. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6995. // if permissionStr != "" {
  6996. // permissionStr = permissionStr + "\n" + "权益:"
  6997. // } else {
  6998. // permissionStr = "权益:"
  6999. // }
  7000. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  7001. // permissionStr += newPermissionStr
  7002. // } else {
  7003. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  7004. // if err != nil {
  7005. // br.Msg = "导出失败"
  7006. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  7007. // return
  7008. // }
  7009. // permissionMap[permissionKey] = getPermissionStr
  7010. // permissionStr += getPermissionStr
  7011. // }
  7012. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  7013. // permissionStr = permissionStr + ""
  7014. // }
  7015. // }
  7016. // }
  7017. // dataRow.AddCell().SetString(companyName)
  7018. // dataRow.AddCell().SetString(creditCode)
  7019. // dataRow.AddCell().SetString(regionType)
  7020. //
  7021. // dataRow.AddCell().SetString(companyType)
  7022. // industryValueCell := dataRow.AddCell()
  7023. // industryValueCell.SetStyle(style)
  7024. // industryValueCell.SetString(industryName)
  7025. //
  7026. // sellerValueCell := dataRow.AddCell()
  7027. // sellerValueCell.SetStyle(style)
  7028. // sellerValueCell.SetString(sellerName)
  7029. //
  7030. // statusValueCell := dataRow.AddCell()
  7031. // statusValueCell.SetStyle(style)
  7032. // statusValueCell.SetValue(status)
  7033. //
  7034. // timeLimitValueCell := dataRow.AddCell()
  7035. // timeLimitValueCell.SetStyle(style)
  7036. // timeLimitValueCell.SetValue(timeLimt)
  7037. //
  7038. // createTimeValueCell := dataRow.AddCell()
  7039. // createTimeValueCell.SetStyle(style)
  7040. // createTimeValueCell.SetValue(createTime)
  7041. //
  7042. // sourceValueCell := dataRow.AddCell()
  7043. // sourceValueCell.SetStyle(style)
  7044. // sourceValueCell.SetValue(source)
  7045. //
  7046. // permissionStrValueCell := dataRow.AddCell()
  7047. // permissionStrValueCell.SetStyle(style)
  7048. // permissionStrValueCell.SetValue(permissionStr)
  7049. // }
  7050. // }
  7051. // err = xlsxFile.Save(downLoadnFilePath)
  7052. // if err != nil {
  7053. // br.Msg = "保存文件失败"
  7054. // br.ErrMsg = "保存文件失败"
  7055. // return
  7056. // }
  7057. // randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  7058. // downloadFileName := "联系人列表" + randStr + ".xlsx"
  7059. // this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  7060. // defer func() {
  7061. // os.Remove(downLoadnFilePath)
  7062. // }()
  7063. // br.Ret = 200
  7064. // br.Success = true
  7065. // br.Msg = "导出成功"
  7066. //}
  7067. // @Title 冻结客户
  7068. // @Description 冻结客户接口
  7069. // @Param request body company.CompanyFreezeReq true "type json string"
  7070. // @Success Ret=200 冻结成功
  7071. // @router /freeze [post]
  7072. func (this *CompanyController) Freeze() {
  7073. br := new(models.BaseResponse).Init()
  7074. defer func() {
  7075. this.Data["json"] = br
  7076. this.ServeJSON()
  7077. }()
  7078. sysUser := this.SysUser
  7079. if sysUser == nil {
  7080. br.Msg = "请登录"
  7081. br.ErrMsg = "请登录,SysUser Is Empty"
  7082. br.Ret = 408
  7083. return
  7084. }
  7085. var req company.CompanyFreezeReq
  7086. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  7087. if err != nil {
  7088. br.Msg = "参数解析异常!"
  7089. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  7090. return
  7091. }
  7092. if req.CompanyId <= 0 {
  7093. br.Msg = "参数错误!"
  7094. br.ErrMsg = "客户id小于等于0"
  7095. return
  7096. }
  7097. productId := 0
  7098. productName := ""
  7099. if req.CompanyType == utils.COMPANY_CLASSIFY_FICC {
  7100. productId = 1
  7101. productName = "ficc"
  7102. } else if req.CompanyType == utils.COMPANY_CLASSIFY_RAI {
  7103. productId = 2
  7104. productName = "权益"
  7105. } else {
  7106. productId = 3
  7107. productName = "佣金客户"
  7108. }
  7109. if req.CompanyId <= 0 {
  7110. br.Msg = "参数异常!"
  7111. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  7112. return
  7113. }
  7114. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  7115. if err != nil {
  7116. br.Msg = "查询该客户产品异常!"
  7117. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  7118. return
  7119. }
  7120. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  7121. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  7122. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  7123. return
  7124. }
  7125. //查询客户的产品权限
  7126. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, productId)
  7127. if err != nil {
  7128. br.Msg = "查询客户的产品权限异常"
  7129. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  7130. return
  7131. }
  7132. err = company.CompanyFreeze(req.CompanyId, productId, req.Remark)
  7133. if err != nil {
  7134. br.Msg = "冻结失败!"
  7135. br.ErrMsg = "冻结失败,Err:" + err.Error()
  7136. return
  7137. }
  7138. //新增操作记录
  7139. {
  7140. approveContent := req.Remark
  7141. remark := "冻结客户"
  7142. operation := "freeze"
  7143. services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
  7144. productName, sysUser.RealName, remark, operation, approveContent, sysUser.RealName, "", "冻结")
  7145. //新增产品权限冻结操作日志
  7146. for _, companyReportPermission := range companyReportPermissionList {
  7147. record := company_report_permission_log.CompanyReportPermissionLog{
  7148. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  7149. CompanyId: companyReportPermission.CompanyId,
  7150. ProductId: productId,
  7151. ProductName: companyReportPermission.ProductName,
  7152. SysUserId: sysUser.AdminId,
  7153. SysUserName: sysUser.RealName,
  7154. Remark: "冻结客户",
  7155. Operation: "freeze",
  7156. Status: companyReportPermission.Status,
  7157. CreateTime: time.Now(),
  7158. }
  7159. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  7160. }
  7161. }
  7162. br.Ret = 200
  7163. br.Success = true
  7164. br.Msg = "领取成功"
  7165. }
  7166. // @Title 获取客户权限
  7167. // @Description 获取客户权限接口
  7168. // @Param CompanyId query int true "用户id"
  7169. // @Success 200 {object} company.CompanyPermissionResp
  7170. // @router /getCompanyPermission [get]
  7171. func (this *CompanyController) PermissionList() {
  7172. br := new(models.BaseResponse).Init()
  7173. defer func() {
  7174. this.Data["json"] = br
  7175. this.ServeJSON()
  7176. }()
  7177. sysUser := this.SysUser
  7178. if sysUser == nil {
  7179. br.Msg = "请登录"
  7180. br.ErrMsg = "请登录,SysUser Is Empty"
  7181. br.Ret = 408
  7182. return
  7183. }
  7184. companyId, _ := this.GetInt("CompanyId")
  7185. if companyId <= 0 {
  7186. br.Msg = "参数错误"
  7187. br.ErrMsg = "客户参数小于等于0"
  7188. return
  7189. }
  7190. //返回基础参数
  7191. resp := new(company.CompanyPermissionResp)
  7192. //客户类型map
  7193. classifyMap := make(map[string]int)
  7194. classifyMap["ficc"] = 1
  7195. classifyMap["权益"] = 2
  7196. roleTypeCode := sysUser.RoleTypeCode
  7197. var companySlice []string
  7198. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  7199. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  7200. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  7201. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
  7202. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM ||
  7203. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
  7204. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_RESEARCHR {
  7205. companySlice = append(companySlice, "ficc")
  7206. } else if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  7207. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN ||
  7208. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  7209. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  7210. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT ||
  7211. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_RESEARCHR {
  7212. companySlice = append(companySlice, "权益")
  7213. }
  7214. for _, companyType := range companySlice {
  7215. //子权限切片集合
  7216. var permissionClassifyArr []string
  7217. if companyType == "ficc" {
  7218. for _, v := range utils.PermissionFiccClassifyArr {
  7219. permissionClassifyArr = append(permissionClassifyArr, v)
  7220. }
  7221. } else {
  7222. permissionClassifyArr = append(permissionClassifyArr, "权益")
  7223. }
  7224. //遍历获取
  7225. for _, v := range permissionClassifyArr {
  7226. checkList := make([]int, 0)
  7227. plist := new(company.PermissionLookList)
  7228. items, err := company.GetPermissionLookItems(classifyMap[companyType], v)
  7229. if err != nil {
  7230. br.Msg = "获取失败"
  7231. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  7232. return
  7233. }
  7234. mapPermissionCheck := make(map[string]int)
  7235. for i, n := range items {
  7236. item := items[i]
  7237. count, err := company.GetCompanyPermissionCheck(companyId, n.ChartPermissionId)
  7238. if err != nil {
  7239. br.Msg = "获取失败"
  7240. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  7241. return
  7242. }
  7243. //合并主观客观勾选的权限
  7244. if count > 0 && mapPermissionCheck[n.PermissionName] == 0 {
  7245. checkList = append(checkList, n.ChartPermissionId)
  7246. mapPermissionCheck[n.PermissionName] = n.ChartPermissionId
  7247. }
  7248. permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  7249. if err != nil && err.Error() != utils.ErrNoRow() {
  7250. br.Msg = "获取失败"
  7251. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  7252. return
  7253. }
  7254. if permission != nil && permission.ChartPermissionId > 0 {
  7255. items[i].StartDate = permission.StartDate
  7256. items[i].EndDate = permission.EndDate
  7257. items[i].Status = permission.Status
  7258. //判断主观、客观
  7259. if items[i].PermissionType == 1 {
  7260. items[i].PermissionTypeName = "主观"
  7261. } else if items[i].PermissionType == 2 {
  7262. items[i].PermissionTypeName = "客观"
  7263. }
  7264. }
  7265. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  7266. endDateTime = endDateTime.AddDate(0, 0, 1)
  7267. sub := endDateTime.Sub(time.Now())
  7268. if sub < 0 {
  7269. sub = 0
  7270. }
  7271. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  7272. items[i].ExpireDay = expireDay
  7273. items[i].ClassifyName = v
  7274. //if n.PermissionType == 1 {
  7275. // items[i].PermissionTypeName = "主观"
  7276. //} else if n.PermissionType == 2 {
  7277. // items[i].PermissionTypeName = "客观"
  7278. //}
  7279. }
  7280. //合并主观客观
  7281. mapPermissionName := make(map[string]int)
  7282. for _, v := range items {
  7283. if mapPermissionName[v.PermissionName] == 0 {
  7284. //plist.Items = append(plist.Items, v)
  7285. //mapPermissionName[v.PermissionName] = v.ChartPermissionId
  7286. // CRM8.8-只有客观的时候回显
  7287. if mapPermissionCheck[v.PermissionName] == 0 || (mapPermissionCheck[v.PermissionName] > 0 && v.ChartPermissionId == mapPermissionCheck[v.PermissionName]) {
  7288. plist.Items = append(plist.Items, v)
  7289. mapPermissionName[v.PermissionName] = v.ChartPermissionId
  7290. }
  7291. }
  7292. }
  7293. plist.ClassifyName = v
  7294. plist.CheckList = checkList
  7295. if companyType == "ficc" {
  7296. resp.FiccPermissionList = append(resp.FiccPermissionList, plist)
  7297. } else {
  7298. resp.PermissionList = append(resp.PermissionList, plist)
  7299. }
  7300. }
  7301. }
  7302. br.Ret = 200
  7303. br.Success = true
  7304. br.Msg = "获取成功"
  7305. br.Data = resp
  7306. }
  7307. // @Title 获取客户来源列表
  7308. // @Description 获取客户来源列表
  7309. // @Success 200 {object} models.CompanySourceListResp
  7310. // @router /getCompanySourceList [get]
  7311. func (this *CompanyController) CompanySourceList() {
  7312. br := new(models.BaseResponse).Init()
  7313. defer func() {
  7314. this.Data["json"] = br
  7315. this.ServeJSON()
  7316. }()
  7317. sysUser := this.SysUser
  7318. if sysUser == nil {
  7319. br.Msg = "请登录"
  7320. br.ErrMsg = "请登录,SysUser Is Empty"
  7321. br.Ret = 408
  7322. return
  7323. }
  7324. list, err := models.GetAllCompanySourceList()
  7325. if err != nil {
  7326. br.Msg = "查询失败"
  7327. br.ErrMsg = "查询异常:" + err.Error()
  7328. return
  7329. }
  7330. br.Ret = 200
  7331. br.Success = true
  7332. br.Msg = "获取成功"
  7333. br.Data = models.CompanySourceListResp{
  7334. List: list,
  7335. }
  7336. }
  7337. // @Title 获取客户的合同列表
  7338. // @Description 获取客户合同列表接口
  7339. // @Param CompanyId query int true "用户id"
  7340. // @Param CompanyType query string false "用户类型:可取范围:ficc,权益"
  7341. // @Param Status query int true "合同审核结果,枚举值:`0`,`1`; 0:待审核,1:审核通过"
  7342. // @Success 200 {object} company.CompanyPermissionResp
  7343. // @router /getCompanyContract [get]
  7344. func (this *CompanyController) ContractList() {
  7345. br := new(models.BaseResponse).Init()
  7346. defer func() {
  7347. this.Data["json"] = br
  7348. this.ServeJSON()
  7349. }()
  7350. sysUser := this.SysUser
  7351. if sysUser == nil {
  7352. br.Msg = "请登录"
  7353. br.ErrMsg = "请登录,SysUser Is Empty"
  7354. br.Ret = 408
  7355. return
  7356. }
  7357. companyId, _ := this.GetInt("CompanyId")
  7358. if companyId <= 0 {
  7359. br.Msg = "参数错误"
  7360. br.ErrMsg = "客户参数小于等于0"
  7361. return
  7362. }
  7363. //合同状态
  7364. status, _ := this.GetInt("Status")
  7365. //产品类型
  7366. companyType := this.GetString("CompanyType")
  7367. var condition string
  7368. var pars []interface{}
  7369. //产品类型
  7370. if companyType == "" {
  7371. productId := services.GetProductId(sysUser.RoleTypeCode)
  7372. if productId != 0 {
  7373. condition += " AND product_id = ?"
  7374. pars = append(pars, productId)
  7375. }
  7376. } else {
  7377. if companyType == "ficc" {
  7378. condition += " AND product_id = ?"
  7379. pars = append(pars, 1)
  7380. } else {
  7381. condition += " AND product_id = ?"
  7382. pars = append(pars, 2)
  7383. }
  7384. }
  7385. if status != 0 {
  7386. condition += " AND status = ?"
  7387. pars = append(pars, status)
  7388. }
  7389. list, err := company.GetCompanyContractListByCompanyId(companyId, condition, pars)
  7390. if err != nil {
  7391. br.Msg = "查询失败"
  7392. br.ErrMsg = "查询异常:" + err.Error()
  7393. return
  7394. }
  7395. br.Ret = 200
  7396. br.Success = true
  7397. br.Msg = "获取成功"
  7398. br.Data = list
  7399. }
  7400. // @Title 获取客户所属销售
  7401. // @Description 根据客户id获取客户所属销售
  7402. // @Param CompanyId query int true "客户id"
  7403. // @Success 200 {object} response.CompanySellerListResp
  7404. // @router /getCompanySellerList [get]
  7405. func (this *CompanyUserController) GetCompanySellerList() {
  7406. br := new(models.BaseResponse).Init()
  7407. defer func() {
  7408. this.Data["json"] = br
  7409. this.ServeJSON()
  7410. }()
  7411. sysUser := this.SysUser
  7412. if sysUser == nil {
  7413. br.Msg = "请登录"
  7414. br.ErrMsg = "请登录,SysUser Is Empty"
  7415. br.Ret = 408
  7416. return
  7417. }
  7418. companyId, _ := this.GetInt("CompanyId")
  7419. //item := make([]*company.CompanyItem, 0)
  7420. list, err := company.GetCompanySellerByCompanyId(companyId)
  7421. if err != nil && err.Error() != utils.ErrNoRow() {
  7422. br.Msg = "获取失败"
  7423. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  7424. return
  7425. }
  7426. resp := response.CompanySellerListResp{
  7427. List: list,
  7428. }
  7429. //resp.List = list
  7430. br.Ret = 200
  7431. br.Success = true
  7432. br.Msg = "获取成功"
  7433. br.Data = resp
  7434. }
  7435. // GetTryOutCompanyList
  7436. // @Title 获取销售今日待办数据
  7437. // @Description 获取销售今日待办接口
  7438. // @Param CompanyName query string false "客户名称"
  7439. // @Param ReasonStatus query int false "续约情况说明状态:-1:未填写,0:全部,1:已填写"
  7440. // @Param PageSize query int true "每页数据条数"
  7441. // @Param CurrentIndex query int true "当前页页码,从1开始"
  7442. // @Success 200 {object} response.TryOutCompanyListResp
  7443. // @router /getTryOutCompanyList [get]
  7444. func (this *CompanyController) GetTryOutCompanyList() {
  7445. br := new(models.BaseResponse).Init()
  7446. defer func() {
  7447. this.Data["json"] = br
  7448. this.ServeJSON()
  7449. }()
  7450. sysUser := this.SysUser
  7451. if sysUser == nil {
  7452. br.Msg = "请登录"
  7453. br.ErrMsg = "请登录,SysUser Is Empty"
  7454. br.Ret = 408
  7455. return
  7456. }
  7457. companyName := this.GetString("CompanyName")
  7458. reasonStatus, _ := this.GetInt("ReasonStatus", 0)
  7459. pageSize, _ := this.GetInt("PageSize")
  7460. currentIndex, _ := this.GetInt("CurrentIndex")
  7461. productId := services.GetProductId(sysUser.RoleTypeCode)
  7462. var startSize int
  7463. if pageSize <= 0 {
  7464. pageSize = utils.PageSize20
  7465. }
  7466. if currentIndex <= 0 {
  7467. currentIndex = 1
  7468. }
  7469. startSize = paging.StartIndex(currentIndex, pageSize)
  7470. var condition string
  7471. var pars []interface{}
  7472. //sellerId, productId int, tryOutTime time.Time, tryOutReason string
  7473. var tryOutTime, lastDescriptionTime time.Time
  7474. if productId == 1 {
  7475. //ficc
  7476. interval := cache.GetIntervalFromCrmConfig("try_out_time_intervals")
  7477. tryOutTime = time.Now().AddDate(0, 0, -interval)
  7478. interval = cache.GetIntervalFromCrmConfig("last_description_time_intervals")
  7479. lastDescriptionTime = time.Now().AddDate(0, 0, -interval)
  7480. } else {
  7481. //权益
  7482. interval := cache.GetIntervalFromCrmConfig("rai_try_out_time_intervals")
  7483. tryOutTime = time.Now().AddDate(0, 0, -interval)
  7484. interval = cache.GetIntervalFromCrmConfig("rai_last_description_time_intervals")
  7485. lastDescriptionTime = time.Now().AddDate(0, 0, -interval)
  7486. }
  7487. if productId > 0 {
  7488. condition += ` and product_id=? `
  7489. pars = append(pars, productId)
  7490. }
  7491. //客户名称模糊搜索
  7492. if companyName != "" {
  7493. condition += ` and b.company_name like "%` + companyName + `%" `
  7494. }
  7495. //续约情况说明(-1:未填写,0:全部,1:已填写)
  7496. switch reasonStatus {
  7497. case -1:
  7498. 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) `
  7499. pars = append(pars, sysUser.AdminId, tryOutTime, lastDescriptionTime)
  7500. case 1:
  7501. 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) `
  7502. pars = append(pars, sysUser.AdminId, tryOutTime)
  7503. default:
  7504. 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) `
  7505. pars = append(pars, sysUser.AdminId, tryOutTime, lastDescriptionTime)
  7506. }
  7507. total := 0
  7508. list := make([]*company.TryOutCompanyList, 0)
  7509. 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}
  7510. if strings.Contains(strings.Join(ignoreStrs, ","), sysUser.RoleTypeCode) {
  7511. //排除已经签署续约合同的
  7512. notSql := ``
  7513. if productId > 0 {
  7514. notSql = fmt.Sprint(` and product_id = `, productId)
  7515. }
  7516. condition += `and a.company_id not in (select company_id from company_contract where contract_type ="续约合同" and start_date >now() and status = 1 ` + notSql + `) `
  7517. tmpTotal, err := company.GetTryOutCompanyCount(condition, pars)
  7518. if err != nil {
  7519. br.Msg = "获取失败"
  7520. br.ErrMsg = "获取总数失败失败,Err:" + err.Error()
  7521. return
  7522. }
  7523. tmpList, err := company.GetTryOutCompanyList(condition, pars, startSize, pageSize)
  7524. if err != nil {
  7525. br.Msg = "获取失败"
  7526. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  7527. return
  7528. }
  7529. total = tmpTotal
  7530. list = tmpList
  7531. }
  7532. if len(list) > 0 {
  7533. for k, item := range list {
  7534. endTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  7535. endTime = endTime.AddDate(0, 0, 1)
  7536. sub := endTime.Sub(time.Now())
  7537. if sub < 0 {
  7538. sub = 0
  7539. }
  7540. list[k].ExpireDays = int(sub.Hours() / 24)
  7541. }
  7542. }
  7543. page := paging.GetPaging(currentIndex, pageSize, total)
  7544. resp := response.TryOutCompanyListResp{
  7545. List: list,
  7546. Paging: page,
  7547. }
  7548. br.Ret = 200
  7549. br.Success = true
  7550. br.Msg = "获取成功"
  7551. br.Data = resp
  7552. }
  7553. // EditTryOutCompanyReason
  7554. // @Title 编辑续约说明情况
  7555. // @Description 编辑续约说明情况接口
  7556. // @Param request body company.RenewalReasonReq true "type json string"
  7557. // @Success 200 编辑成功
  7558. // @router /editTryOutCompanyReason [post]
  7559. func (this *CompanyController) EditTryOutCompanyReason() {
  7560. br := new(models.BaseResponse).Init()
  7561. defer func() {
  7562. this.Data["json"] = br
  7563. this.ServeJSON()
  7564. }()
  7565. sysUser := this.SysUser
  7566. if sysUser == nil {
  7567. br.Msg = "请登录"
  7568. br.ErrMsg = "请登录,SysUser Is Empty"
  7569. br.Ret = 408
  7570. return
  7571. }
  7572. var req company.RenewalReasonReq
  7573. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  7574. if err != nil {
  7575. br.Msg = "参数解析异常!"
  7576. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  7577. return
  7578. }
  7579. if req.CompanyId <= 0 {
  7580. br.Msg = "参数缺失"
  7581. br.ErrMsg = "参数缺失,客户编号未传!"
  7582. return
  7583. }
  7584. if req.ProductId <= 0 {
  7585. br.Msg = "参数缺失"
  7586. br.ErrMsg = "参数缺失,产品编号未传!"
  7587. return
  7588. }
  7589. if req.Remark == "" {
  7590. br.Msg = "参数缺失"
  7591. br.ErrMsg = "参数缺失,续约情况说明未传!"
  7592. return
  7593. }
  7594. /*if req.RenewalTodo == "" && req.Renew == 0 {
  7595. br.Msg = "参数缺失"
  7596. br.ErrMsg = "参数缺失,待办事项说明未传!"
  7597. return
  7598. }*/
  7599. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  7600. if err != nil {
  7601. br.Msg = "查询客户异常"
  7602. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  7603. return
  7604. }
  7605. if companyProduct.SellerId != sysUser.AdminId {
  7606. br.Msg = "客户异常,没有该客户的操作权限"
  7607. br.ErrMsg = "客户异常,没有该客户的操作权限"
  7608. return
  7609. }
  7610. renewalReason := company.CompanyRenewalReason{
  7611. CompanyRenewalReasonId: 0,
  7612. CompanyId: companyProduct.CompanyId,
  7613. ProductId: companyProduct.ProductId,
  7614. ProductName: companyProduct.ProductName,
  7615. CompanyName: companyProduct.CompanyName,
  7616. TryOutTime: companyProduct.TryOutTime,
  7617. RenewalReason: req.Remark,
  7618. RenewalTodo: req.RenewalTodo,
  7619. LastDescriptionTime: companyProduct.LastDescriptionTime,
  7620. EndDays: companyProduct.ContractEndDate,
  7621. ExpirationTimeExceeded: 0,
  7622. RenewalIntention: req.Renew,
  7623. CreateTime: time.Now(),
  7624. }
  7625. endTime, err := company.GetTryOutTimeFromOperationRecord(renewalReason.CompanyId)
  7626. if err != nil {
  7627. br.Msg = "查询该客户转试用时间异常!"
  7628. br.ErrMsg = "查询该客户转试用时间异常,err:" + err.Error()
  7629. return
  7630. }
  7631. endDateTime, err := time.Parse(utils.FormatDateTime, *endTime)
  7632. if err != nil {
  7633. br.Msg = "时间格式化异常!"
  7634. br.ErrMsg = "时间格式化异常,err:" + err.Error()
  7635. return
  7636. }
  7637. endDate := endDateTime.Format(utils.FormatDate)
  7638. endDateTime, _ = time.Parse(utils.FormatDate, endDate)
  7639. sub := time.Now().Sub(endDateTime)
  7640. renewalReason.ExpirationTimeExceeded = int(sub.Hours() / 24)
  7641. err = company.AddRenewalReason(&renewalReason)
  7642. if err != nil {
  7643. br.Msg = "新增续约情况说明操作异常!"
  7644. br.ErrMsg = "新增续约情况说明操作异常,err:" + err.Error()
  7645. return
  7646. }
  7647. companyProduct.RenewalIntention = req.Renew
  7648. err = company.EditTryOutCompanyReason(companyProduct, req.Remark, req.RenewalTodo)
  7649. if err != nil {
  7650. br.Msg = "更新客户未续约异常!"
  7651. br.ErrMsg = "更新客户未续约异常,err:" + err.Error()
  7652. return
  7653. }
  7654. if req.Renew == 1 {
  7655. productName := ""
  7656. if req.ProductId == 1 {
  7657. productName = "ficc"
  7658. } else if req.ProductId == 2 {
  7659. productName = "权益"
  7660. } else {
  7661. productName = "佣金客户"
  7662. }
  7663. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  7664. if err != nil {
  7665. br.Msg = "查询该客户产品异常!"
  7666. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  7667. return
  7668. }
  7669. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  7670. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  7671. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  7672. return
  7673. }
  7674. //查询客户的产品权限
  7675. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, req.ProductId)
  7676. if err != nil {
  7677. br.Msg = "查询客户的产品权限异常"
  7678. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  7679. return
  7680. }
  7681. err = company.CompanyFreeze(req.CompanyId, req.ProductId, req.Remark)
  7682. if err != nil {
  7683. br.Msg = "冻结失败!"
  7684. br.ErrMsg = "冻结失败,Err:" + err.Error()
  7685. return
  7686. }
  7687. //新增操作记录
  7688. go func() {
  7689. time.Sleep(time.Second)
  7690. approveContent := req.Remark
  7691. remark := "冻结客户"
  7692. operation := "freeze"
  7693. _ = services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  7694. productName, "超级管理员", remark, operation, approveContent, sysUser.RealName, "", "冻结")
  7695. //新增产品权限冻结操作日志
  7696. for _, companyReportPermission := range companyReportPermissionList {
  7697. record := company_report_permission_log.CompanyReportPermissionLog{
  7698. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  7699. CompanyId: companyReportPermission.CompanyId,
  7700. ProductId: req.ProductId,
  7701. ProductName: companyReportPermission.ProductName,
  7702. SysUserId: sysUser.AdminId,
  7703. SysUserName: "超级管理员",
  7704. Remark: "冻结客户",
  7705. Operation: "freeze",
  7706. Status: companyReportPermission.Status,
  7707. CreateTime: time.Now(),
  7708. }
  7709. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  7710. }
  7711. }()
  7712. }
  7713. approveContent := req.Remark
  7714. approveContentExtra := req.RenewalTodo
  7715. remark := "新增续约说明"
  7716. operation := "edit_renewal_reason"
  7717. _ = services.AddCompanyOperationRecordMore(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  7718. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, approveContentExtra, sysUser.RealName, "", companyProduct.Status)
  7719. items, err := company.ReadCompanyOperationRecord(req.CompanyId)
  7720. if err != nil {
  7721. br.Msg = "编辑失败"
  7722. br.ErrMsg = "编辑失败,Err:" + err.Error()
  7723. return
  7724. }
  7725. if len(items) > 0 {
  7726. record := new(company.CompanyOperationRecord)
  7727. record.Id = items[0].Id
  7728. record.ApproveContent = req.Remark
  7729. record.ApproveContentExtra = req.RenewalTodo
  7730. _, err = company.UpdateCompanyOperationRecord(record)
  7731. if err != nil {
  7732. br.Msg = "编辑失败"
  7733. br.ErrMsg = "编辑失败,Err:" + err.Error()
  7734. return
  7735. }
  7736. } else {
  7737. br.Msg = "编辑失败"
  7738. br.ErrMsg = "编辑失败,未查询到转试用记录"
  7739. return
  7740. }
  7741. br.Ret = 200
  7742. br.Success = true
  7743. br.Msg = "编辑成功"
  7744. }
  7745. // AddTryOutCompanyReason
  7746. // @Title 新增续约说明情况
  7747. // @Description 新增续约说明情况接口
  7748. // @Param request body company.RenewalReasonReq true "type json string"
  7749. // @Success 200 编辑成功
  7750. // @router /addTryOutCompanyReason [post]
  7751. func (this *CompanyController) AddTryOutCompanyReason() {
  7752. br := new(models.BaseResponse).Init()
  7753. defer func() {
  7754. this.Data["json"] = br
  7755. this.ServeJSON()
  7756. }()
  7757. sysUser := this.SysUser
  7758. if sysUser == nil {
  7759. br.Msg = "请登录"
  7760. br.ErrMsg = "请登录,SysUser Is Empty"
  7761. br.Ret = 408
  7762. return
  7763. }
  7764. var req company.RenewalReasonReq
  7765. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  7766. if err != nil {
  7767. br.Msg = "参数解析异常!"
  7768. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  7769. return
  7770. }
  7771. if req.CompanyId <= 0 {
  7772. br.Msg = "参数缺失"
  7773. br.ErrMsg = "参数缺失,客户编号未传!"
  7774. return
  7775. }
  7776. if req.ProductId <= 0 {
  7777. br.Msg = "参数缺失"
  7778. br.ErrMsg = "参数缺失,产品编号未传!"
  7779. return
  7780. }
  7781. if req.Remark == "" {
  7782. br.Msg = "参数缺失"
  7783. br.ErrMsg = "参数缺失,续约情况说明未传!"
  7784. return
  7785. }
  7786. if req.RenewalTodo == "" && req.Renew == 0 {
  7787. br.Msg = "参数缺失"
  7788. br.ErrMsg = "参数缺失,待办事项说明未传!"
  7789. return
  7790. }
  7791. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  7792. if err != nil {
  7793. br.Msg = "查询客户异常"
  7794. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  7795. return
  7796. }
  7797. if companyProduct.SellerId != sysUser.AdminId {
  7798. br.Msg = "客户异常,没有该客户的操作权限"
  7799. br.ErrMsg = "客户异常,没有该客户的操作权限"
  7800. return
  7801. }
  7802. renewalReason := company.CompanyRenewalReason{
  7803. CompanyRenewalReasonId: 0,
  7804. CompanyId: companyProduct.CompanyId,
  7805. ProductId: companyProduct.ProductId,
  7806. ProductName: companyProduct.ProductName,
  7807. CompanyName: companyProduct.CompanyName,
  7808. TryOutTime: companyProduct.TryOutTime,
  7809. RenewalReason: req.Remark,
  7810. RenewalTodo: req.RenewalTodo,
  7811. LastDescriptionTime: companyProduct.LastDescriptionTime,
  7812. EndDays: companyProduct.ContractEndDate,
  7813. ExpirationTimeExceeded: 0,
  7814. RenewalIntention: req.Renew,
  7815. CreateTime: time.Now(),
  7816. }
  7817. endTime, err := company.GetTryOutTimeFromOperationRecord(renewalReason.CompanyId)
  7818. if err != nil {
  7819. br.Msg = "查询该客户转试用时间异常!"
  7820. br.ErrMsg = "查询该客户转试用时间异常,err:" + err.Error()
  7821. return
  7822. }
  7823. endDateTime, err := time.Parse(utils.FormatDateTime, *endTime)
  7824. if err != nil {
  7825. br.Msg = "时间格式化异常!"
  7826. br.ErrMsg = "时间格式化异常,err:" + err.Error()
  7827. return
  7828. }
  7829. endDate := endDateTime.Format(utils.FormatDate)
  7830. endDateTime, _ = time.Parse(utils.FormatDate, endDate)
  7831. sub := time.Now().Sub(endDateTime)
  7832. renewalReason.ExpirationTimeExceeded = int(sub.Hours() / 24)
  7833. err = company.AddRenewalReason(&renewalReason)
  7834. if err != nil {
  7835. br.Msg = "新增续约情况说明操作异常!"
  7836. br.ErrMsg = "新增续约情况说明操作异常,err:" + err.Error()
  7837. return
  7838. }
  7839. companyProduct.RenewalIntention = req.Renew
  7840. err = company.EditTryOutCompanyReason(companyProduct, req.Remark, req.RenewalTodo)
  7841. if err != nil {
  7842. br.Msg = "更新客户续约情况说明异常!"
  7843. br.ErrMsg = "更新客户续约情况说明异常,err:" + err.Error()
  7844. return
  7845. }
  7846. if req.Renew == 1 {
  7847. productName := ""
  7848. if req.ProductId == 1 {
  7849. productName = "ficc"
  7850. } else if req.ProductId == 2 {
  7851. productName = "权益"
  7852. } else {
  7853. productName = "佣金客户"
  7854. }
  7855. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  7856. if err != nil {
  7857. br.Msg = "查询该客户产品异常!"
  7858. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  7859. return
  7860. }
  7861. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  7862. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  7863. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  7864. return
  7865. }
  7866. //查询客户的产品权限
  7867. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, req.ProductId)
  7868. if err != nil {
  7869. br.Msg = "查询客户的产品权限异常"
  7870. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  7871. return
  7872. }
  7873. err = company.CompanyFreeze(req.CompanyId, req.ProductId, req.Remark)
  7874. if err != nil {
  7875. br.Msg = "冻结失败!"
  7876. br.ErrMsg = "冻结失败,Err:" + err.Error()
  7877. return
  7878. }
  7879. //新增操作记录
  7880. go func() {
  7881. time.Sleep(time.Second)
  7882. approveContent := req.Remark
  7883. remark := "冻结客户"
  7884. operation := "freeze"
  7885. _ = services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  7886. productName, "超级管理员", remark, operation, approveContent, sysUser.RealName, "", "冻结")
  7887. //新增产品权限冻结操作日志
  7888. for _, companyReportPermission := range companyReportPermissionList {
  7889. record := company_report_permission_log.CompanyReportPermissionLog{
  7890. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  7891. CompanyId: companyReportPermission.CompanyId,
  7892. ProductId: req.ProductId,
  7893. ProductName: companyReportPermission.ProductName,
  7894. SysUserId: sysUser.AdminId,
  7895. SysUserName: "超级管理员",
  7896. Remark: "冻结客户",
  7897. Operation: "freeze",
  7898. Status: companyReportPermission.Status,
  7899. CreateTime: time.Now(),
  7900. }
  7901. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  7902. }
  7903. }()
  7904. }
  7905. {
  7906. approveContent := req.Remark
  7907. approveContentExtra := req.RenewalTodo
  7908. remark := "新增续约说明"
  7909. operation := "add_renewal_reason"
  7910. _ = services.AddCompanyOperationRecordMore(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  7911. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, approveContentExtra, sysUser.RealName, "", companyProduct.Status)
  7912. }
  7913. br.Ret = 200
  7914. br.Success = true
  7915. br.Msg = "编辑成功"
  7916. }
  7917. // RenewReasonList 客户未续约说明历史列表
  7918. // @Title 客户未续约说明历史列表
  7919. // @Description 客户未续约说明历史列表
  7920. // @Param CompanyId query string true "客户id"
  7921. // @Param ProductId query string true "产品id"
  7922. // @Success 200 {object} response.RenewReasonItemResp
  7923. // @router /renewReasonList [get]
  7924. func (this *CompanyController) RenewReasonList() {
  7925. br := new(models.BaseResponse).Init()
  7926. defer func() {
  7927. this.Data["json"] = br
  7928. this.ServeJSON()
  7929. }()
  7930. sysUser := this.SysUser
  7931. if sysUser == nil {
  7932. br.Msg = "请登录"
  7933. br.ErrMsg = "请登录,SysUser Is Empty"
  7934. br.Ret = 408
  7935. return
  7936. }
  7937. CompanyId := this.GetString("CompanyId")
  7938. ProductId := this.GetString("ProductId")
  7939. if CompanyId == "" {
  7940. br.Msg = "请输入客户ID"
  7941. return
  7942. }
  7943. if ProductId != "1" && ProductId != "2" {
  7944. br.Msg = "请输入正确的产品ID"
  7945. return
  7946. }
  7947. renewalReason, err := models.GetMoreRenewalReason(CompanyId, ProductId)
  7948. if err != nil {
  7949. br.Msg = "获取失败"
  7950. br.ErrMsg = "获取失败,Err:" + err.Error()
  7951. return
  7952. }
  7953. resp := make([]response.RenewReasonItemResp, len(renewalReason))
  7954. for i, reason := range renewalReason {
  7955. createDate := reason.CreateTime.Format("2006.01.02 15:04:05")
  7956. resp[i].RenewalReason = reason.RenewalReason
  7957. resp[i].RenewalTodo = reason.RenewalTodo
  7958. resp[i].CreateTime = createDate
  7959. }
  7960. br.Ret = 200
  7961. br.Success = true
  7962. br.Msg = "获取成功"
  7963. br.Data = resp
  7964. }
  7965. // AddRenewalReason
  7966. // @Title 转试用按钮新增续约说明情况
  7967. // @Description 转试用按钮新增续约说明情况
  7968. // @Param request body company.TryOutReq true "type json string"
  7969. // @Success 200 编辑成功
  7970. // @router /addRenewalReason [post]
  7971. func (this *CompanyController) AddRenewalReason() {
  7972. br := new(models.BaseResponse).Init()
  7973. defer func() {
  7974. this.Data["json"] = br
  7975. this.ServeJSON()
  7976. }()
  7977. sysUser := this.SysUser
  7978. if sysUser == nil {
  7979. br.Msg = "请登录"
  7980. br.ErrMsg = "请登录,SysUser Is Empty"
  7981. br.Ret = 408
  7982. return
  7983. }
  7984. var req company.TryOutReq
  7985. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  7986. if err != nil {
  7987. br.Msg = "参数解析异常!"
  7988. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  7989. return
  7990. }
  7991. if req.CompanyId <= 0 {
  7992. br.Msg = "参数缺失"
  7993. br.ErrMsg = "参数缺失,客户编号未传!"
  7994. return
  7995. }
  7996. if req.ProductId <= 0 {
  7997. br.Msg = "参数缺失"
  7998. br.ErrMsg = "参数缺失,产品编号未传!"
  7999. return
  8000. }
  8001. if req.OperationId <= 0 {
  8002. br.Msg = "参数缺失"
  8003. br.ErrMsg = "参数缺失,操作记录表编号未传!"
  8004. return
  8005. }
  8006. if req.Remark == "" {
  8007. br.Msg = "参数缺失"
  8008. br.ErrMsg = "参数缺失,续约情况说明未传!"
  8009. return
  8010. }
  8011. if req.RenewalTodo == "" && req.Renew == 0 {
  8012. br.Msg = "参数缺失"
  8013. br.ErrMsg = "参数缺失,待办事项说明未传!"
  8014. return
  8015. }
  8016. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  8017. if err != nil {
  8018. br.Msg = "查询客户异常"
  8019. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  8020. return
  8021. }
  8022. if companyProduct.SellerId != sysUser.AdminId {
  8023. br.Msg = "客户异常,没有该客户的操作权限"
  8024. br.ErrMsg = "客户异常,没有该客户的操作权限"
  8025. return
  8026. }
  8027. renewalReason := company.CompanyRenewalReason{
  8028. CompanyRenewalReasonId: 0,
  8029. CompanyId: companyProduct.CompanyId,
  8030. ProductId: companyProduct.ProductId,
  8031. ProductName: companyProduct.ProductName,
  8032. CompanyName: companyProduct.CompanyName,
  8033. TryOutTime: companyProduct.TryOutTime,
  8034. RenewalReason: req.Remark,
  8035. RenewalTodo: req.RenewalTodo,
  8036. LastDescriptionTime: companyProduct.LastDescriptionTime,
  8037. EndDays: companyProduct.ContractEndDate,
  8038. ExpirationTimeExceeded: 0,
  8039. RenewalIntention: req.Renew,
  8040. CreateTime: time.Now(),
  8041. }
  8042. endTime, err := company.GetTryOutTimeFromOperationRecord(renewalReason.CompanyId)
  8043. if err != nil {
  8044. br.Msg = "查询该客户转试用时间异常!"
  8045. br.ErrMsg = "查询该客户转试用时间异常,err:" + err.Error()
  8046. return
  8047. }
  8048. endDateTime, err := time.Parse(utils.FormatDateTime, *endTime)
  8049. if err != nil {
  8050. br.Msg = "时间格式化异常!"
  8051. br.ErrMsg = "时间格式化异常,err:" + err.Error()
  8052. return
  8053. }
  8054. endDate := endDateTime.Format(utils.FormatDate)
  8055. endDateTime, _ = time.Parse(utils.FormatDate, endDate)
  8056. sub := time.Now().Sub(endDateTime)
  8057. renewalReason.ExpirationTimeExceeded = int(sub.Hours() / 24)
  8058. err = company.AddRenewalReason(&renewalReason)
  8059. if err != nil {
  8060. br.Msg = "新增续约情况说明操作异常!"
  8061. br.ErrMsg = "新增续约情况说明操作异常,err:" + err.Error()
  8062. return
  8063. }
  8064. companyProduct.RenewalIntention = req.Renew
  8065. err = company.EditTryOutCompanyReason(companyProduct, req.Remark, req.RenewalTodo)
  8066. if err != nil {
  8067. br.Msg = "更新客户续约情况说明异常!"
  8068. br.ErrMsg = "更新客户续约情况说明异常,err:" + err.Error()
  8069. return
  8070. }
  8071. if req.Renew == 1 {
  8072. productName := ""
  8073. if req.ProductId == 1 {
  8074. productName = "ficc"
  8075. } else if req.ProductId == 2 {
  8076. productName = "权益"
  8077. } else {
  8078. productName = "佣金客户"
  8079. }
  8080. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  8081. if err != nil {
  8082. br.Msg = "查询该客户产品异常!"
  8083. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  8084. return
  8085. }
  8086. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  8087. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  8088. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  8089. return
  8090. }
  8091. //查询客户的产品权限
  8092. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, req.ProductId)
  8093. if err != nil {
  8094. br.Msg = "查询客户的产品权限异常"
  8095. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  8096. return
  8097. }
  8098. err = company.CompanyFreeze(req.CompanyId, req.ProductId, req.Remark)
  8099. if err != nil {
  8100. br.Msg = "冻结失败!"
  8101. br.ErrMsg = "冻结失败,Err:" + err.Error()
  8102. return
  8103. }
  8104. //新增操作记录
  8105. go func() {
  8106. time.Sleep(time.Second)
  8107. approveContent := req.Remark
  8108. remark := "冻结客户"
  8109. operation := "freeze"
  8110. _ = services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  8111. productName, "超级管理员", remark, operation, approveContent, sysUser.RealName, "", "冻结")
  8112. //新增产品权限冻结操作日志
  8113. for _, companyReportPermission := range companyReportPermissionList {
  8114. record := company_report_permission_log.CompanyReportPermissionLog{
  8115. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  8116. CompanyId: companyReportPermission.CompanyId,
  8117. ProductId: req.ProductId,
  8118. ProductName: companyReportPermission.ProductName,
  8119. SysUserId: sysUser.AdminId,
  8120. SysUserName: "超级管理员",
  8121. Remark: "冻结客户",
  8122. Operation: "freeze",
  8123. Status: companyReportPermission.Status,
  8124. CreateTime: time.Now(),
  8125. }
  8126. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  8127. }
  8128. }()
  8129. }
  8130. {
  8131. approveContent := req.Remark
  8132. approveContentExtra := req.RenewalTodo
  8133. remark := "新增续约说明"
  8134. operation := "add_try_out_reason"
  8135. _ = services.AddCompanyOperationRecordMore(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  8136. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, approveContentExtra, sysUser.RealName, "", companyProduct.Status)
  8137. record := new(company.CompanyOperationRecord)
  8138. record.Id = req.OperationId
  8139. record.ApproveContent = req.Remark
  8140. record.ApproveContentExtra = req.RenewalTodo
  8141. _, err = company.UpdateCompanyOperationRecord(record)
  8142. if err != nil {
  8143. br.Msg = "编辑失败"
  8144. br.ErrMsg = "编辑失败,Err:" + err.Error()
  8145. return
  8146. }
  8147. }
  8148. br.Ret = 200
  8149. br.Success = true
  8150. br.Msg = "编辑成功"
  8151. }
  8152. // AddRemark
  8153. // @Title 新增备注
  8154. // @Description 新增备注
  8155. // @Param request body company.RemarkReq true "type json string"
  8156. // @Success 200 编辑成功
  8157. // @router /remark/add [post]
  8158. func (this *CompanyController) AddRemark() {
  8159. br := new(models.BaseResponse).Init()
  8160. defer func() {
  8161. this.Data["json"] = br
  8162. this.ServeJSON()
  8163. }()
  8164. sysUser := this.SysUser
  8165. if sysUser == nil {
  8166. br.Msg = "请登录"
  8167. br.ErrMsg = "请登录,SysUser Is Empty"
  8168. br.Ret = 408
  8169. return
  8170. }
  8171. var req company.RemarkReq
  8172. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  8173. if err != nil {
  8174. br.Msg = "参数解析异常!"
  8175. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  8176. return
  8177. }
  8178. if req.CompanyId <= 0 {
  8179. br.Msg = "参数缺失"
  8180. br.ErrMsg = "参数缺失,客户编号未传!"
  8181. return
  8182. }
  8183. if req.Remark == "" {
  8184. br.Msg = "参数缺失"
  8185. br.ErrMsg = "参数缺失,备注说明未传!"
  8186. return
  8187. }
  8188. var productId int
  8189. //var productName string
  8190. 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 {
  8191. productId = 1
  8192. //productName = "ficc"
  8193. } 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 {
  8194. productId = 2
  8195. //productName = "权益"
  8196. } else {
  8197. br.Msg = "角色类型错误"
  8198. br.ErrMsg = "角色类型错误,该角色不能添加备注!"
  8199. return
  8200. }
  8201. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  8202. if err != nil {
  8203. br.Msg = "查询客户异常"
  8204. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  8205. }
  8206. if companyProduct.SellerId != sysUser.AdminId {
  8207. br.Msg = "客户异常,没有该客户的操作权限"
  8208. br.ErrMsg = "客户异常,没有该客户的操作权限"
  8209. return
  8210. }
  8211. remark := company.CompanyProductRemark{
  8212. CompanyId: companyProduct.CompanyId,
  8213. ProductId: companyProduct.ProductId,
  8214. ProductName: companyProduct.ProductName,
  8215. Remark: req.Remark,
  8216. CreateTime: time.Now(),
  8217. SysUserId: sysUser.AdminId,
  8218. SysRealName: sysUser.RealName,
  8219. }
  8220. err = company.AddCompanyRemark(&remark)
  8221. {
  8222. approveContent := req.Remark
  8223. remark := "新增备注"
  8224. operation := "add_remark"
  8225. services.AddCompanyOperationRecord(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  8226. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, sysUser.RealName, "", companyProduct.Status)
  8227. }
  8228. if err != nil {
  8229. br.Msg = "编辑失败"
  8230. br.ErrMsg = "编辑失败,Err:" + err.Error()
  8231. }
  8232. br.Ret = 200
  8233. br.Success = true
  8234. br.Msg = "编辑成功"
  8235. }
  8236. // RemarkList 备注列表
  8237. // @Title 备注列表
  8238. // @Description 备注列表
  8239. // @Param CompanyId query string true "客户id"
  8240. // @Success 200 {object} company.RemarkResp
  8241. // @router /remark [get]
  8242. func (this *CompanyController) RemarkList() {
  8243. br := new(models.BaseResponse).Init()
  8244. defer func() {
  8245. this.Data["json"] = br
  8246. this.ServeJSON()
  8247. }()
  8248. sysUser := this.SysUser
  8249. if sysUser == nil {
  8250. br.Msg = "请登录"
  8251. br.ErrMsg = "请登录,SysUser Is Empty"
  8252. br.Ret = 408
  8253. return
  8254. }
  8255. companyId := this.GetString("CompanyId")
  8256. var remarkList []*company.CompanyProductRemark
  8257. var err error
  8258. groupFicc := []string{
  8259. utils.ROLE_TYPE_CODE_FICC_SELLER, utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_FICC_GROUP,
  8260. utils.ROLE_TYPE_CODE_FICC_DEPARTMENT, utils.ROLE_TYPE_CODE_FICC_ADMIN,
  8261. }
  8262. groupRai := []string{
  8263. utils.ROLE_TYPE_CODE_RAI_SELLER, utils.ROLE_TYPE_CODE_RAI_GROUP, utils.ROLE_TYPE_CODE_RAI_GROUP,
  8264. utils.ROLE_TYPE_CODE_RAI_DEPARTMENT, utils.ROLE_TYPE_CODE_RAI_ADMIN,
  8265. }
  8266. if utils.InArrayByStr(groupFicc, sysUser.RoleTypeCode) {
  8267. remarkList, err = company.GetRemarkList(companyId, "1")
  8268. if err != nil {
  8269. br.Msg = "获取失败"
  8270. br.ErrMsg = "获取失败,Err:" + err.Error()
  8271. return
  8272. }
  8273. }
  8274. if utils.InArrayByStr(groupRai, sysUser.RoleTypeCode) {
  8275. remarkList, err = company.GetRemarkList(companyId, "2")
  8276. if err != nil {
  8277. br.Msg = "获取失败"
  8278. br.ErrMsg = "获取失败,Err:" + err.Error()
  8279. return
  8280. }
  8281. }
  8282. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  8283. remarkList, err = company.GetRemarkListByCompanyId(companyId)
  8284. if err != nil {
  8285. br.Msg = "获取失败"
  8286. br.ErrMsg = "获取失败,Err:" + err.Error()
  8287. return
  8288. }
  8289. }
  8290. resp := make([]company.RemarkResp, len(remarkList))
  8291. for i, remark := range remarkList {
  8292. createDate := remark.CreateTime.Format(utils.FormatDateTime)
  8293. resp[i].RemarkId = remark.CompanyProductRemarkId
  8294. resp[i].Remark = remark.Remark
  8295. resp[i].ProductName = remark.ProductName
  8296. resp[i].CreateTime = createDate
  8297. // 仅自己添加的可删除
  8298. if remark.SysUserId == sysUser.AdminId {
  8299. resp[i].ButtonDel = true
  8300. }
  8301. }
  8302. br.Ret = 200
  8303. br.Success = true
  8304. br.Msg = "获取成功"
  8305. br.Data = resp
  8306. }
  8307. // RoadShowList 客户列表的路演详情列表
  8308. // @Title 路演详情列表
  8309. // @Description 路演详情列表
  8310. // @Param CompanyId query string true "客户id"
  8311. // @Success 200 {object} company.RoadShowListResp
  8312. // @router /roadShowList [get]
  8313. func (this *CompanyController) RoadShowList() {
  8314. br := new(models.BaseResponse).Init()
  8315. defer func() {
  8316. this.Data["json"] = br
  8317. this.ServeJSON()
  8318. }()
  8319. sysUser := this.SysUser
  8320. if sysUser == nil {
  8321. br.Msg = "请登录"
  8322. br.ErrMsg = "请登录,SysUser Is Empty"
  8323. br.Ret = 408
  8324. return
  8325. }
  8326. companyId := this.GetString("CompanyId")
  8327. var err error
  8328. roadShowList, err := company.GetRoadShowList(companyId)
  8329. if err != nil {
  8330. br.Msg = "获取失败"
  8331. br.ErrMsg = "获取失败,Err:" + err.Error()
  8332. return
  8333. }
  8334. //calendarIdSlice := make([]string, 0)
  8335. //for _, v := range roadShowList {
  8336. // calendarIdSlice = append(calendarIdSlice, strconv.Itoa(v.RsCalendarId))
  8337. //}
  8338. //calendarIdStr := strings.Join(calendarIdSlice, ",")
  8339. //researcherList, _ := company.GetRoadShowResearchers(calendarIdStr)
  8340. //roadShowTotalMap := make(map[int]int)
  8341. //for _, roadShowTotal := range researcherList {
  8342. // roadShowTotalMap[roadShowTotal.CompanyId] = roadShowTotal.Total
  8343. //}
  8344. resp := make([]company.RoadShowListResp, len(roadShowList))
  8345. for i, calendar := range roadShowList {
  8346. resp[i].SysUserRealName = calendar.SysUserRealName
  8347. resp[i].RoadshowType = calendar.RoadshowType
  8348. //线上为平台,线下为省市
  8349. if calendar.RoadshowType == "线上" {
  8350. resp[i].RoadshowPlatform = calendar.RoadshowPlatform
  8351. } else {
  8352. resp[i].RoadshowPlatform = calendar.Province + calendar.City
  8353. }
  8354. researchers, err := company.GetRoadShowResearchers(calendar.RsCalendarId)
  8355. if err != nil && err.Error() != utils.ErrNoRow() {
  8356. br.Msg = "获取研究员信息失败"
  8357. br.ErrMsg = "获取研究员信息失败,Err:" + err.Error()
  8358. return
  8359. }
  8360. var researcherList []string
  8361. for _, researcher := range researchers {
  8362. researcherList = append(researcherList, *researcher)
  8363. }
  8364. researcher := strings.Join(researcherList, ",")
  8365. resp[i].Researchers = researcher
  8366. resp[i].RoadShowTime = calendar.EndDate.Format("2006.01.02")
  8367. }
  8368. br.Ret = 200
  8369. br.Success = true
  8370. br.Msg = "获取成功"
  8371. br.Data = resp
  8372. }
  8373. // CustomerAreaStatistics
  8374. // @Title 客户区域统计
  8375. // @Description 获取客户区域统计接口
  8376. // @Param Date query string true "日期"
  8377. // @Param ProductId query Int true "产品Id"
  8378. // @Success 200 {object} statistic_report.CompanyRenewRecordResp
  8379. // @router /customerAreaStatistics [get]
  8380. func (this *CompanyController) CustomerAreaStatistics() {
  8381. br := new(models.BaseResponse).Init()
  8382. defer func() {
  8383. this.Data["json"] = br
  8384. this.ServeJSON()
  8385. }()
  8386. sysUser := this.SysUser
  8387. if sysUser == nil {
  8388. br.Msg = "请登录"
  8389. br.ErrMsg = "请登录,SysUser Is Empty"
  8390. br.Ret = 408
  8391. return
  8392. }
  8393. date := this.GetString("Date")
  8394. productId, _ := this.GetInt("ProductId", 1)
  8395. //获取列表
  8396. companyAreaDataMapList, _, err := statistic_report.GetAreaDateData(date, productId)
  8397. if err != nil {
  8398. br.Msg = "数据异常"
  8399. br.ErrMsg = "数据异常,Err:" + err.Error()
  8400. return
  8401. }
  8402. //获取省市数据
  8403. areaMap := make(map[string]string)
  8404. provinceMap := make(map[string][]string, 0)
  8405. list, err := statisticModels.GetAllCompanyArea()
  8406. for _, item := range list {
  8407. areaMap[item.City] = item.Province
  8408. }
  8409. for c, p := range areaMap {
  8410. citySlice := make([]string, 0)
  8411. citySlice = provinceMap[p]
  8412. citySlice = append(citySlice, c)
  8413. provinceMap[p] = citySlice
  8414. }
  8415. //数据处理
  8416. groupReportRecordList := make([]statistic_report.GroupCityRecord, 0)
  8417. resp := statistic_report.CustomerAreaStatisticsResp{
  8418. List: groupReportRecordList,
  8419. IsAdmin: false,
  8420. }
  8421. //除ficc管理员和超管之外的角色进入此页面时,正式客户数量>0时可点击,点击查看正式客户列表详情;
  8422. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  8423. resp.IsAdmin = true
  8424. }
  8425. startDateIndexList := make(map[int]string) //开始时间间隔map
  8426. endDateIndexList := make(map[int]string) //结束时间间隔map
  8427. tmpAllTryOutNumMap := make(map[int]int)
  8428. tmpAllFormalNumMap := make(map[int]int)
  8429. tmpAllActiveNumMap := make(map[int]int)
  8430. tmpAllAllActiveNumMap := make(map[int]int)
  8431. tmpAllNoIncrementalActiveNumMap := make(map[int]int)
  8432. tmpAllTryStagePushMap := make(map[int]int)
  8433. tmpAllTryStageFollowMap := make(map[int]int)
  8434. tmpAllTryStageReadyMap := make(map[int]int)
  8435. tmpAllTryStageInitMap := make(map[int]int)
  8436. for province, cityList := range provinceMap {
  8437. tmpGroupCityReportRecord := make([]statistic_report.CityRecord, 0)
  8438. tmpGroupCompanyReportRecordNumList := make([]statistic_report.CompanyAreaNum, 0)
  8439. tmpGroupTryOutNumMap := make(map[int]int)
  8440. tmpGroupFormalNumMap := make(map[int]int)
  8441. tmpGroupFormalCompanyIdsMap := make(map[int]string) //正式客户id
  8442. tmpGroupActiveNumMap := make(map[int]int)
  8443. tmpGroupAllActiveNumMap := make(map[int]int)
  8444. tmpGroupNoIncrementalActiveNumMap := make(map[int]int)
  8445. // 其他类型客户ID
  8446. tmpGroupTryOutCompanyIdsMap := make(map[int]string) //试用客户ID
  8447. tmpGroupPushCompanyIdsMap := make(map[int]string) //试用(推进)客户ID
  8448. tmpGroupFollowCompanyIdsMap := make(map[int]string) //试用(跟踪)客户ID
  8449. tmpGroupReadyCompanyIdsMap := make(map[int]string) //试用(预备)客户ID
  8450. tmpGroupInitCompanyIdsMap := make(map[int]string) //试用(未分类)客户ID
  8451. tmpGroupTryStagePushMap := make(map[int]int)
  8452. tmpGroupTryStageFollowMap := make(map[int]int)
  8453. tmpGroupTryStageReadyMap := make(map[int]int)
  8454. tmpGroupTryStageInitMap := make(map[int]int)
  8455. for _, city := range cityList {
  8456. //城市数据
  8457. //每个城市的数据
  8458. tmpCompanyReportRecordNumList := make([]statistic_report.CompanyAreaNum, 0)
  8459. for index, adminData := range companyAreaDataMapList {
  8460. startDateIndexList[index] = adminData.StartDate
  8461. endDateIndexList[index] = adminData.EndDate
  8462. var tmpTryOutNum, tmpFormalNum, tmpActiveStatus, tmpAllActiveStatus, tmpNoIncrementalActiveStatus int
  8463. var tmpTryStagePushNum, tmpTryStageFollowNum, tmpTryStageReadyNum, tmpTryStageInitNum int
  8464. var tmpFormalCompanyIds string //正式客户id集合
  8465. var tmpTryOutCompanyIds string //试用客户ID集合
  8466. var tmpPushCompanyIds string //试用(推进)客户ID集合
  8467. var tmpFollowCompanyIds string //试用(跟踪)客户ID集合
  8468. var tmpReadyCompanyIds string //试用(预备)客户ID集合
  8469. var tmpInitCompanyIds string //试用(未分类)客户ID集合
  8470. if num, ok := adminData.TryOutMap[city]; ok {
  8471. tmpTryOutNum = num
  8472. }
  8473. if num, ok := adminData.FormalMap[city]; ok {
  8474. tmpFormalNum = num
  8475. }
  8476. if companyIds, ok := adminData.FormalIdMap[city]; ok {
  8477. tmpFormalCompanyIds = companyIds
  8478. }
  8479. if companyIds, ok := adminData.TryOutIdMap[city]; ok {
  8480. tmpTryOutCompanyIds = companyIds
  8481. }
  8482. if companyIds, ok := adminData.TryStagePushIdsMap[city]; ok {
  8483. tmpPushCompanyIds = companyIds
  8484. }
  8485. if companyIds, ok := adminData.TryStageFollowIdsMap[city]; ok {
  8486. tmpFollowCompanyIds = companyIds
  8487. }
  8488. if companyIds, ok := adminData.TryStageReadyIdsMap[city]; ok {
  8489. tmpReadyCompanyIds = companyIds
  8490. }
  8491. if companyIds, ok := adminData.TryStageInitIdsMap[city]; ok {
  8492. tmpInitCompanyIds = companyIds
  8493. }
  8494. if num, ok := adminData.ActiveMap[city]; ok {
  8495. tmpActiveStatus = num
  8496. }
  8497. if num, ok := adminData.AllActiveMap[city]; ok {
  8498. tmpAllActiveStatus = num
  8499. }
  8500. if num, ok := adminData.NoIncrementalActiveMap[city]; ok {
  8501. tmpNoIncrementalActiveStatus = num
  8502. }
  8503. // 每个用户的试用标签统计 推进-跟踪-预备-未分类
  8504. if num, ok := adminData.TryStagePushNum[city]; ok {
  8505. tmpTryStagePushNum = num
  8506. }
  8507. if num, ok := adminData.TryStageFollowNum[city]; ok {
  8508. tmpTryStageFollowNum = num
  8509. }
  8510. if num, ok := adminData.TryStageReadyNum[city]; ok {
  8511. tmpTryStageReadyNum = num
  8512. }
  8513. if num, ok := adminData.TryStageInitNum[city]; ok {
  8514. tmpTryStageInitNum = num
  8515. }
  8516. tmpAdminRsReportRecordNum := statistic_report.CompanyAreaNum{
  8517. TryOutNum: tmpTryOutNum,
  8518. FormalNum: tmpFormalNum,
  8519. FormalIds: tmpFormalCompanyIds,
  8520. ActiveNum: tmpActiveStatus,
  8521. AllActiveNum: tmpAllActiveStatus,
  8522. NoIncrementalActiveNum: tmpNoIncrementalActiveStatus,
  8523. StartDate: adminData.StartDate,
  8524. EndDate: adminData.EndDate,
  8525. TryStagePushNum: tmpTryStagePushNum,
  8526. TryStageFollowNum: tmpTryStageFollowNum,
  8527. TryStageReadyNum: tmpTryStageReadyNum,
  8528. TryStageInitNum: tmpTryStageInitNum,
  8529. TotalNum: tmpTryOutNum + tmpFormalNum,
  8530. }
  8531. tmpCompanyReportRecordNumList = append(tmpCompanyReportRecordNumList, tmpAdminRsReportRecordNum)
  8532. //组内数据汇总
  8533. tmpGroupTryOutNumMap[index] += tmpTryOutNum
  8534. tmpGroupFormalNumMap[index] += tmpFormalNum
  8535. // 正式客户id
  8536. if tmpFormalCompanyIds != `` {
  8537. tmpGroupFormalCompanyIds, ok := tmpGroupFormalCompanyIdsMap[index]
  8538. if ok {
  8539. tmpGroupFormalCompanyIdsMap[index] = tmpGroupFormalCompanyIds + "," + tmpFormalCompanyIds
  8540. } else {
  8541. tmpGroupFormalCompanyIdsMap[index] = tmpFormalCompanyIds
  8542. }
  8543. }
  8544. tmpGroupActiveNumMap[index] += tmpActiveStatus
  8545. tmpGroupAllActiveNumMap[index] += tmpActiveStatus
  8546. tmpGroupNoIncrementalActiveNumMap[index] += tmpActiveStatus
  8547. tmpGroupTryStagePushMap[index] += tmpTryStagePushNum
  8548. tmpGroupTryStageFollowMap[index] += tmpTryStageFollowNum
  8549. tmpGroupTryStageReadyMap[index] += tmpTryStageReadyNum
  8550. tmpGroupTryStageInitMap[index] += tmpTryStageInitNum
  8551. // 其他客户IDs
  8552. if tmpTryOutCompanyIds != `` {
  8553. a, ok := tmpGroupTryOutCompanyIdsMap[index]
  8554. if ok {
  8555. tmpGroupTryOutCompanyIdsMap[index] = a + "," + tmpTryOutCompanyIds
  8556. } else {
  8557. tmpGroupTryOutCompanyIdsMap[index] = tmpTryOutCompanyIds
  8558. }
  8559. }
  8560. if tmpPushCompanyIds != `` {
  8561. a, ok := tmpGroupPushCompanyIdsMap[index]
  8562. if ok {
  8563. tmpGroupPushCompanyIdsMap[index] = a + "," + tmpPushCompanyIds
  8564. } else {
  8565. tmpGroupPushCompanyIdsMap[index] = tmpPushCompanyIds
  8566. }
  8567. }
  8568. if tmpFollowCompanyIds != `` {
  8569. a, ok := tmpGroupFollowCompanyIdsMap[index]
  8570. if ok {
  8571. tmpGroupFollowCompanyIdsMap[index] = a + "," + tmpFollowCompanyIds
  8572. } else {
  8573. tmpGroupFollowCompanyIdsMap[index] = tmpFollowCompanyIds
  8574. }
  8575. }
  8576. if tmpReadyCompanyIds != `` {
  8577. a, ok := tmpGroupReadyCompanyIdsMap[index]
  8578. if ok {
  8579. tmpGroupReadyCompanyIdsMap[index] = a + "," + tmpReadyCompanyIds
  8580. } else {
  8581. tmpGroupReadyCompanyIdsMap[index] = tmpReadyCompanyIds
  8582. }
  8583. }
  8584. if tmpInitCompanyIds != `` {
  8585. a, ok := tmpGroupInitCompanyIdsMap[index]
  8586. if ok {
  8587. tmpGroupInitCompanyIdsMap[index] = a + "," + tmpInitCompanyIds
  8588. } else {
  8589. tmpGroupInitCompanyIdsMap[index] = tmpInitCompanyIds
  8590. }
  8591. }
  8592. //总数据汇总
  8593. tmpAllTryOutNumMap[index] += tmpTryOutNum
  8594. tmpAllFormalNumMap[index] += tmpFormalNum
  8595. tmpAllActiveNumMap[index] += tmpActiveStatus
  8596. tmpAllAllActiveNumMap[index] += tmpAllActiveStatus
  8597. tmpAllNoIncrementalActiveNumMap[index] += tmpNoIncrementalActiveStatus
  8598. // 总数据试用标签数据汇总
  8599. tmpAllTryStagePushMap[index] += tmpTryStagePushNum
  8600. tmpAllTryStageFollowMap[index] += tmpTryStageFollowNum
  8601. tmpAllTryStageReadyMap[index] += tmpTryStageReadyNum
  8602. tmpAllTryStageInitMap[index] += tmpTryStageInitNum
  8603. }
  8604. tmpAdminReportRecord := statistic_report.CityRecord{
  8605. Name: city,
  8606. CompanyAreaNumNumList: tmpCompanyReportRecordNumList,
  8607. }
  8608. tmpGroupCityReportRecord = append(tmpGroupCityReportRecord, tmpAdminReportRecord)
  8609. }
  8610. for i := 0; i < len(tmpGroupActiveNumMap); i++ {
  8611. tmpGroupCompanyReportRecordNum := statistic_report.CompanyAreaNum{
  8612. TryOutNum: tmpGroupTryOutNumMap[i],
  8613. FormalNum: tmpGroupFormalNumMap[i],
  8614. FormalIds: tmpGroupFormalCompanyIdsMap[i],
  8615. ActiveNum: tmpGroupActiveNumMap[i],
  8616. AllActiveNum: tmpGroupAllActiveNumMap[i],
  8617. NoIncrementalActiveNum: tmpGroupNoIncrementalActiveNumMap[i],
  8618. StartDate: startDateIndexList[i],
  8619. EndDate: endDateIndexList[i],
  8620. TryStagePushNum: tmpGroupTryStagePushMap[i],
  8621. TryStageFollowNum: tmpGroupTryStageFollowMap[i],
  8622. TryStageReadyNum: tmpGroupTryStageReadyMap[i],
  8623. TryStageInitNum: tmpGroupTryStageInitMap[i],
  8624. TotalNum: tmpGroupTryOutNumMap[i] + tmpGroupFormalNumMap[i],
  8625. TryOutIds: tmpGroupTryOutCompanyIdsMap[i],
  8626. TryStagePushIds: tmpGroupPushCompanyIdsMap[i],
  8627. TryStageFollowIds: tmpGroupFollowCompanyIdsMap[i],
  8628. TryStageReadyIds: tmpGroupReadyCompanyIdsMap[i],
  8629. TryStageInitIds: tmpGroupInitCompanyIdsMap[i],
  8630. }
  8631. tmpGroupCompanyReportRecordNumList = append(tmpGroupCompanyReportRecordNumList, tmpGroupCompanyReportRecordNum)
  8632. }
  8633. groupReportRecord := statistic_report.GroupCityRecord{
  8634. Item: tmpGroupCityReportRecord,
  8635. Name: province,
  8636. CompanyAreaNumNumList: tmpGroupCompanyReportRecordNumList,
  8637. }
  8638. groupReportRecordList = append(groupReportRecordList, groupReportRecord)
  8639. }
  8640. resp.List = groupReportRecordList
  8641. br.Ret = 200
  8642. br.Success = true
  8643. br.Msg = "获取成功"
  8644. br.Data = resp
  8645. }
  8646. // CompanyTryOutDayList
  8647. // @Title 客户累计试用详情接口
  8648. // @Description 客户累计试用详情接口
  8649. // @Param CompanyId query int true "客户id"
  8650. // @Param ProductId query int true "产品id"
  8651. // @Success 200 {object} company.CompanyTryOutDayListResp
  8652. // @router /company/tryOutDayList [get]
  8653. func (this *CompanyTodoController) CompanyTryOutDayList() {
  8654. br := new(models.BaseResponse).Init()
  8655. defer func() {
  8656. this.Data["json"] = br
  8657. this.ServeJSON()
  8658. }()
  8659. companyId, _ := this.GetInt("CompanyId")
  8660. if companyId <= 0 {
  8661. br.Msg = "请选择客户"
  8662. return
  8663. }
  8664. productId, _ := this.GetInt("ProductId")
  8665. if productId <= 0 {
  8666. br.Msg = "请选择类型"
  8667. return
  8668. }
  8669. pageSize, _ := this.GetInt("PageSize")
  8670. currentIndex, _ := this.GetInt("CurrentIndex")
  8671. var startSize int
  8672. if pageSize <= 0 {
  8673. pageSize = utils.PageSize20
  8674. }
  8675. if currentIndex <= 0 {
  8676. currentIndex = 1
  8677. }
  8678. startSize = paging.StartIndex(currentIndex, pageSize)
  8679. // 获取任务信息
  8680. total, err := company.GetCompanyProductTryOutUpdateLogTotal(companyId, productId)
  8681. if err != nil {
  8682. br.Msg = "获取任务信息失败"
  8683. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  8684. return
  8685. }
  8686. // 获取任务信息
  8687. list, err := company.GetCompanyProductTryOutUpdateLogList(companyId, productId, startSize, pageSize)
  8688. if err != nil {
  8689. br.Msg = "获取任务信息失败"
  8690. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  8691. return
  8692. }
  8693. //var list []*company_todo.CompanyTodoListItem
  8694. //for _, v := range todos {
  8695. // temp := &company_todo.CompanyTodoListItem{
  8696. // CompanyTodo: v,
  8697. // }
  8698. // temp.EndTimeStr = temp.EndTime.Format(utils.FormatDate)
  8699. // if temp.EndTimeStr == "0001-01-01" {
  8700. // temp.EndTimeStr = ""
  8701. // }
  8702. // list = append(list, temp)
  8703. //}
  8704. if len(list) <= 0 {
  8705. list = make([]*company.CompanyProductTryOutUpdateLog, 0)
  8706. }
  8707. page := paging.GetPaging(currentIndex, pageSize, total)
  8708. resp := company.CompanyTryOutDayListResp{
  8709. Paging: page,
  8710. List: list,
  8711. }
  8712. br.Ret = 200
  8713. br.Success = true
  8714. br.Msg = "获取成功"
  8715. br.Data = resp
  8716. }
  8717. // @Title 获取流水信息接口
  8718. // @Description 获取流水信息接口
  8719. // @Param CompanyId query int true "客户id"
  8720. // @Success 200 {object} company.CygxActivityPointsBillListResp
  8721. // @router /company/activity/points/bill [get]
  8722. func (this *CompanyTodoController) CompanyActivityPointsBill() {
  8723. br := new(models.BaseResponse).Init()
  8724. defer func() {
  8725. this.Data["json"] = br
  8726. this.ServeJSON()
  8727. }()
  8728. companyId, _ := this.GetInt("CompanyId")
  8729. if companyId <= 0 {
  8730. br.Msg = "请选择客户"
  8731. return
  8732. }
  8733. // 获取流水信息
  8734. list, err := cygx.CygxActivityPointsBillByCompanyId(companyId)
  8735. if err != nil {
  8736. br.Msg = "获取任务信息失败"
  8737. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  8738. return
  8739. }
  8740. if len(list) <= 0 {
  8741. list = make([]*cygx.CygxActivityPointsBillResp, 0)
  8742. }
  8743. resp := cygx.CygxActivityPointsBillListResp{
  8744. List: list,
  8745. }
  8746. br.Ret = 200
  8747. br.Success = true
  8748. br.Msg = "获取成功"
  8749. br.Data = resp
  8750. }
  8751. // DelRemark
  8752. // @Title 删除备注
  8753. // @Description 删除备注
  8754. // @Param request body company.RemarkDelReq true "type json string"
  8755. // @Success 200 操作成功
  8756. // @router /remark/del [post]
  8757. func (this *CompanyController) DelRemark() {
  8758. br := new(models.BaseResponse).Init()
  8759. defer func() {
  8760. if br.ErrMsg == "" {
  8761. br.IsSendEmail = false
  8762. }
  8763. this.Data["json"] = br
  8764. this.ServeJSON()
  8765. }()
  8766. sysUser := this.SysUser
  8767. if sysUser == nil {
  8768. br.Msg = "请登录"
  8769. br.ErrMsg = "请登录,SysUser Is Empty"
  8770. br.Ret = 408
  8771. return
  8772. }
  8773. var req company.RemarkDelReq
  8774. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  8775. if err != nil {
  8776. br.Msg = "参数解析异常!"
  8777. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  8778. return
  8779. }
  8780. if req.RemarkId <= 0 {
  8781. br.Msg = "参数有误"
  8782. br.ErrMsg = "参数有误, 备注ID有误"
  8783. return
  8784. }
  8785. item, e := company.GetCompanyRemarkById(req.RemarkId)
  8786. if e != nil {
  8787. if e.Error() == utils.ErrNoRow() {
  8788. br.Msg = "备注已被删除, 请刷新页面"
  8789. return
  8790. }
  8791. br.Msg = "备注信息有误"
  8792. br.ErrMsg = "获取客户备注失败, Err: " + e.Error()
  8793. return
  8794. }
  8795. if item.SysUserId != sysUser.AdminId {
  8796. br.Msg = "仅备注添加人可删除"
  8797. return
  8798. }
  8799. product, e := company.GetCompanyProductByCompanyIdAndProductId(item.CompanyId, item.ProductId)
  8800. if e != nil {
  8801. br.Msg = "操作失败"
  8802. br.ErrMsg = "获取客户产品信息失败, Err: " + e.Error()
  8803. return
  8804. }
  8805. if e := company.DelCompanyRemark(req.RemarkId); e != nil {
  8806. br.Msg = "操作失败"
  8807. br.ErrMsg = "删除客户备注失败, Err: " + e.Error()
  8808. return
  8809. }
  8810. content := fmt.Sprintf("%s%s", "删除备注: ", item.Remark)
  8811. _ = 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)
  8812. br.Ret = 200
  8813. br.Success = true
  8814. br.Msg = "操作成功"
  8815. }
  8816. // @Title 获取流水信息接口
  8817. // @Description 获取流水信息接口
  8818. // @Param CompanyId query int true "客户id"
  8819. // @Success 200 {object} company.CygxActivityPointsBillListResp
  8820. // @router /company/activity/special/points/bill [get]
  8821. func (this *CompanyTodoController) CompanyActivitySpecialPointsBill() {
  8822. br := new(models.BaseResponse).Init()
  8823. defer func() {
  8824. this.Data["json"] = br
  8825. this.ServeJSON()
  8826. }()
  8827. companyId, _ := this.GetInt("CompanyId")
  8828. if companyId <= 0 {
  8829. br.Msg = "请选择客户"
  8830. return
  8831. }
  8832. // 获取流水信息
  8833. var condition string
  8834. var pars []interface{}
  8835. condition += ` AND company_id = ? `
  8836. pars = append(pars, companyId)
  8837. //查询当年的数据
  8838. //condition += ` AND b.create_time >= ? `
  8839. //pars = append(pars, time.Now().Format(utils.FormatYearDate)+"-01-01")
  8840. list, err := cygx.GetCygxActivitySpecialTripBillDetailListAll(condition, pars)
  8841. if err != nil {
  8842. br.Msg = "获取任务信息失败"
  8843. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  8844. return
  8845. }
  8846. //userType, tripRemaining, mapChartName, err := cygxService.GetChartPermissionSpecialSurplusByCompany(companyId)
  8847. //if err != nil {
  8848. // br.Msg = "获取专项调研剩余次数失败"
  8849. // br.ErrMsg = "获取专项调研剩余次数失败,err:" + err.Error()
  8850. // return
  8851. //}
  8852. //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}
  8853. resp := new(cygx.CygxActivitySpecialPointsBillResp)
  8854. //lastTripRemaining := 0
  8855. for _, v := range list {
  8856. item := cygx.CygxActivitySpecialPointsBillRespItem{
  8857. Id: v.Id,
  8858. CreateTime: v.CreateTime.Format(utils.FormatDateTime),
  8859. CompanyId: v.CompanyId,
  8860. CompanyName: v.CompanyName,
  8861. RealName: v.RealName,
  8862. BillDetailed: v.BillDetailed,
  8863. ActivityName: v.ResearchTheme,
  8864. ChartPermissionId: v.ChartPermissionId,
  8865. ChartPermissionName: v.ChartPermissionName,
  8866. Total: v.Total,
  8867. }
  8868. if v.ActivityId == 0 {
  8869. item.Content = v.Content
  8870. } else {
  8871. if v.DoType == 1 && v.Way != 4 && v.Way != 3 {
  8872. item.Content = item.ActivityName + "--报名"
  8873. } else if v.DoType == 2 && v.Way != 4 && v.Way != 3 {
  8874. item.Content = item.ActivityName + "--取消报名"
  8875. } else if v.Way == 4 {
  8876. item.Content = item.ActivityName + "--活动取消"
  8877. }
  8878. }
  8879. //if userType == 2 {
  8880. // if i== 0 {
  8881. // item.Total += strconv.Itoa(tripRemaining) + "次"
  8882. // } else {
  8883. // item.Total += strconv.Itoa(tripRemaining-list[i-1].BillDetailed) + "次"
  8884. // }
  8885. // //if v.BillDetailed < 4 {
  8886. // // item.Total += strconv.Itoa(lastTripRemaining-list[i-1].BillDetailed) + "次"
  8887. // //} else {
  8888. // // item.Total += strconv.Itoa(lastTripRemaining) + "次"
  8889. // //}
  8890. //} else {
  8891. // for k, num := range mapChartName {
  8892. // if i== 0 {
  8893. // item.Total += k + strconv.Itoa(num) + "次+"
  8894. // } else {
  8895. // if list[i-1].ActivityId == 0 {
  8896. // item.Total += k + strconv.Itoa(num) + "次+"
  8897. // } else {
  8898. // item.Total += k + strconv.Itoa(num-list[i-1].BillDetailed) + "次+"
  8899. // }
  8900. // }
  8901. // //if num > 0 {
  8902. // // if i== 0{
  8903. // // item.Total += k + strconv.Itoa(num) + "次+"
  8904. // // } else {
  8905. // // item.Total += k + strconv.Itoa(num-v.BillDetailed) + "次+"
  8906. // // }
  8907. // //}
  8908. // }
  8909. // item.Total = strings.TrimRight(item.Total, "+")
  8910. //}
  8911. resp.List = append(resp.List, &item)
  8912. }
  8913. br.Ret = 200
  8914. br.Success = true
  8915. br.Msg = "获取成功"
  8916. br.Data = resp
  8917. }