1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532 |
- package controllers
- import (
- "encoding/json"
- "errors"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "github.com/shopspring/decimal"
- "github.com/tealeg/xlsx"
- "hongze/hz_crm_api/models"
- "hongze/hz_crm_api/models/company"
- "hongze/hz_crm_api/models/fms"
- "hongze/hz_crm_api/models/response"
- "hongze/hz_crm_api/models/roadshow"
- statisticModels "hongze/hz_crm_api/models/statistic_report"
- "hongze/hz_crm_api/models/system"
- "hongze/hz_crm_api/services"
- "hongze/hz_crm_api/services/alarm_msg"
- contractService "hongze/hz_crm_api/services/contract"
- fmsService "hongze/hz_crm_api/services/fms"
- "hongze/hz_crm_api/services/statistic_report"
- "hongze/hz_crm_api/utils"
- "os"
- "path/filepath"
- "strconv"
- "strings"
- "sync"
- "time"
- )
- // StatisticReportController 统计报告基类
- type StatisticReportController struct {
- BaseAuthController
- }
- // StatisticReportCommonController 统计报告
- type StatisticReportCommonController struct {
- BaseCommonController
- }
- // getQueryParams 获取基础查询信息
- func getQueryParams(condition string, pars []interface{}, sysUser *system.Admin, tableAlias string) (newCondition string, newPars []interface{}) {
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
- condition += " AND " + tableAlias + "product_id=?"
- pars = append(pars, 1)
- } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
- condition += " AND " + tableAlias + "product_id=?"
- pars = append(pars, 2)
- } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FINANCE {
- //超级管理员账户,不做条件限制
- } else {
- //如果不是研究员,那么去找对应的 部门、小组、销售
- if sysUser.Authority == 0 {
- //普通用户
- condition += " AND " + tableAlias + "seller_id=?"
- pars = append(pars, sysUser.AdminId)
- } else if sysUser.Authority == 1 {
- //部门主管
- condition += " AND " + tableAlias + "department_id=?"
- pars = append(pars, sysUser.DepartmentId)
- } else if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
- //权益小组负责人
- condition += " AND " + tableAlias + "group_id=?"
- pars = append(pars, sysUser.GroupId)
- } else if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
- //ficc销售主管
- pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
- if err != nil {
- fmt.Println(err.Error())
- return
- }
- var ids []*string
- if pid != nil && *pid != 0 {
- ids, err = company.GetGroupIdsByParentId(*pid)
- if err != nil {
- fmt.Println(err.Error())
- }
- } else {
- ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
- if err != nil {
- fmt.Println(err.Error())
- }
- }
- var idSlice []string
- var sid string
- for _, id := range ids {
- idSlice = append(idSlice, *id)
- }
- //加入父级groupId
- if *pid > 0 {
- idSlice = append(idSlice, strconv.Itoa(*pid))
- } else {
- idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
- }
- sid = strings.Join(idSlice, ",")
- condition += " AND " + tableAlias + `group_id IN (` + sid + `) `
- fmt.Println("condition:", condition)
- //pars = append(pars, sysUser.GroupId)
- } else if sysUser.Authority == 4 {
- //ficc小组负责人
- condition += " AND " + tableAlias + "group_id=?"
- pars = append(pars, sysUser.GroupId)
- } else {
- //不知道什么类型的用户(后面新增的位置类型客户)
- condition += " AND " + tableAlias + "seller_id=?"
- pars = append(pars, sysUser.AdminId)
- }
- }
- newCondition = condition
- newPars = pars
- return
- }
- // Home
- // @Title 获取首页工作台数据
- // @Description 获取首页工作台数据接口
- // @Success 200 {object} response.WorktopResp
- // @router /home [get]
- func (this *StatisticReportController) Home() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- todayStr := utils.GetToday("20060102")
- //近6个月客户增量数据
- var incrementalCompanyChartList response.IncrementalCompanyChartResp
- ch := make(chan response.IncrementalCompanyChartResp, 1)
- go getIncrementalCompanyList(sysUser, ch)
- //未来6个月即将到期
- var willExpireList response.WillExpireChartResp
- ch2 := make(chan response.WillExpireChartResp, 1)
- go getWillExpireList(sysUser, ch2)
- //近6个月收入统计
- var incomeList response.IncomeChartResp
- ch3 := make(chan response.IncomeChartResp, 1)
- go getIncomeList(sysUser, ch3)
- var formalCompanyCount, trialCompanyTotal, newCompanyTotal, renewalCompanyTotal, notRenewalCompanyTotal int
- today := utils.GetToday(utils.FormatDate)
- //正式客户数
- {
- key := "admin:home:formalCompanyCount:" + todayStr + ":" + strconv.Itoa(sysUser.AdminId)
- redisCount, redisErr := utils.Rc.RedisInt(key)
- if redisErr != nil {
- var condition string
- var pars []interface{}
- //根据当前角色来获取查询条件
- condition, pars = getQueryParams(condition, pars, sysUser, "b.")
- condition += ` AND b.status = "正式" `
- tmpFormalCompanyCount, err := models.GetCurrCompanyCount(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取正式客户总数失败"
- br.ErrMsg = "获取正式客户总数失败,Err:" + err.Error()
- return
- }
- redisCount = tmpFormalCompanyCount
- _ = utils.Rc.Put(key, redisCount, time.Minute*30)
- }
- formalCompanyCount = redisCount
- }
- //试用客户数
- {
- key := "admin:home:trialCompanyTotal:" + todayStr + ":" + strconv.Itoa(sysUser.AdminId)
- redisCount, redisErr := utils.Rc.RedisInt(key)
- if redisErr != nil {
- var condition string
- var pars []interface{}
- //根据当前角色来获取查询条件
- //condition, pars = getQueryParams(condition, pars, sysUser, "c.")
- //condition += " AND a.create_time <= ?"
- //pars = append(pars, time.Now())
- //
- //condition += ` AND a.operation in ("add","receive")`
- //tmpTrialCompanyTotal, err := models.GetIncrementalCompanyCountByOperationRecord(condition, pars)
- condition, pars = getQueryParams(condition, pars, sysUser, "b.")
- condition += ` AND b.status = "试用" `
- tmpTrialCompanyTotal, err := models.GetCurrCompanyCount(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取试用客户总数失败"
- br.ErrMsg = "获取试用客户总数失败,Err:" + err.Error()
- return
- }
- redisCount = tmpTrialCompanyTotal
- _ = utils.Rc.Put(key, redisCount, time.Minute*30)
- }
- trialCompanyTotal = redisCount
- }
- //新签客户数
- {
- key := "admin:home:newCompanyTotal:" + todayStr + ":" + strconv.Itoa(sysUser.AdminId)
- redisCount, redisErr := utils.Rc.RedisInt(key)
- if redisErr != nil {
- var condition string
- var pars []interface{}
- //根据当前角色来获取查询条件
- condition, pars = getQueryParams(condition, pars, sysUser, "c.")
- //condition += ` AND c.status ="正式" `
- condition += ` AND a.start_date <= ? AND a.end_date >= ? `
- pars = append(pars, today, today)
- condition += ` AND a.contract_type = ? `
- pars = append(pars, "新签合同")
- total, err := models.GetIncrementalNewCompanyCount(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取新签客户失败"
- br.ErrMsg = "获取新签客户失败,Err:" + err.Error()
- return
- }
- redisCount = total
- _ = utils.Rc.Put(key, redisCount, time.Minute*30)
- }
- newCompanyTotal = redisCount
- }
- //续约客户数
- {
- key := "admin:home:renewalCompanyTotal:" + todayStr + ":" + strconv.Itoa(sysUser.AdminId)
- redisCount, redisErr := utils.Rc.RedisInt(key)
- if redisErr != nil {
- var condition string
- var pars []interface{}
- //根据当前角色来获取查询条件
- condition, pars = getQueryParams(condition, pars, sysUser, "c.")
- //condition += ` AND c.status="正式" `
- condition += ` AND a.start_date <= ? AND a.end_date >= ? `
- pars = append(pars, today, today)
- condition += ` AND a.contract_type = ? `
- pars = append(pars, "续约合同")
- total, err := models.GetIncrementalNewCompanyCount(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取续约客户失败"
- br.ErrMsg = "获取续约客户失败,Err:" + err.Error()
- return
- }
- redisCount = total
- _ = utils.Rc.Put(key, redisCount, time.Minute*30)
- }
- renewalCompanyTotal = redisCount
- }
- //未续约客户数
- //{
- // key := "admin:home:notRenewalCompanyTotal:" + todayStr + ":" + strconv.Itoa(sysUser.AdminId)
- // redisCount, redisErr := utils.Rc.RedisInt(key)
- // if redisErr != nil {
- // var condition string
- // var pars []interface{}
- //
- // //根据当前角色来获取查询条件
- // condition, pars = getQueryParams(condition, pars, sysUser, "c.")
- // condition += ` AND c.status not in ("永续","正式") `
- // total, err := models.GetIncrementalNewCompanyCount(condition, pars)
- // if err != nil && err.Error() != utils.ErrNoRow() {
- // br.Msg = "获取未续约客户失败"
- // br.ErrMsg = "获取未续约客户失败,Err:" + err.Error()
- // return
- // }
- // redisCount = total
- // _ = utils.Rc.Put(key, redisCount, time.Minute*30)
- // }
- // notRenewalCompanyTotal = redisCount
- //}
- //未续约客户数
- {
- key := "admin:home:notRenewalCompanyTotal:" + todayStr + ":" + strconv.Itoa(sysUser.AdminId)
- redisCount, redisErr := utils.Rc.RedisInt(key)
- if redisErr != nil {
- var condition string
- var pars []interface{}
- //根据当前角色来获取查询条件
- condition, pars = getQueryParams(condition, pars, sysUser, "c.")
- condition += ` AND c.status not in ("永续","正式") AND a.create_time <= ? `
- pars = append(pars, time.Now().Format(utils.FormatDateTime))
- condition += ` AND a.operation = 'try_out' `
- total, err := models.GetIncrementalCompanyCountByOperationRecord(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取未续约客户失败"
- br.ErrMsg = "获取未续约客户失败,Err:" + err.Error()
- return
- }
- redisCount = total
- _ = utils.Rc.Put(key, redisCount, time.Minute*30)
- }
- notRenewalCompanyTotal = redisCount
- }
- //合同数据
- contractChartData := response.ContractChartResp{}
- {
- key := "admin:home:contractChartData:" + todayStr + ":" + strconv.Itoa(sysUser.AdminId)
- redisContractChartData, redisErr := utils.Rc.RedisString(key)
- if redisErr != nil {
- var condition string
- var pars []interface{}
- //根据当前角色来获取查询条件
- condition, pars = getQueryParams(condition, pars, sysUser, "c.")
- condition += ` AND a.end_date >= ? `
- pars = append(pars, today)
- //condition += ` AND c.status = "正式" `
- tmpContractCompanyCount, tmpContractTotal, tmpMoney, err := models.GetContractStatListCount(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取未续约客户失败"
- br.ErrMsg = "获取未续约客户失败,Err:" + err.Error()
- return
- }
- return
- }
- //数据赋值
- contractChartData.Title = "当前有效合同存量"
- contractChartData.FormalCompanyCount = tmpContractCompanyCount
- contractChartData.ContractTotal = tmpContractTotal
- contractChartData.MoneyTotal = tmpMoney
- //入缓存
- redisJsonData, err := json.Marshal(contractChartData)
- if err == nil {
- _ = utils.Rc.Put(key, string(redisJsonData), time.Minute*30)
- }
- } else {
- err := json.Unmarshal([]byte(redisContractChartData), &contractChartData)
- if err != nil {
- fmt.Println("合同数据,json转换失败:", err)
- }
- }
- }
- for v := range ch {
- incrementalCompanyChartList = v
- close(ch)
- }
- for v := range ch2 {
- willExpireList = v
- close(ch2)
- }
- for v := range ch3 {
- incomeList = v
- close(ch3)
- }
- resp := response.WorktopResp{
- FormalCompanyCount: formalCompanyCount,
- TrialCompanyTotal: trialCompanyTotal,
- NewCompanyTotal: newCompanyTotal,
- RenewalCompanyTotal: renewalCompanyTotal,
- NotRenewalCompanyTotal: notRenewalCompanyTotal,
- IncrementalCompanyChartList: incrementalCompanyChartList,
- WillExpireChartList: willExpireList,
- IncomeChartList: incomeList,
- ContractData: contractChartData,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // 查询从2021/01开始的,每个月的客户增量数据
- func getIncrementalCompanyList(sysUser *system.Admin, ch chan response.IncrementalCompanyChartResp) (incrementalCompanyChart response.IncrementalCompanyChartResp, err error) {
- defer func() {
- if err != nil {
- go alarm_msg.SendAlarmMsg("查询近6个月的客户增量数据异常,Err:"+err.Error(), 3)
- //go utils.SendEmail(utils.APPNAME+"查询近6个月的客户增量数据异常:"+time.Now().Format("2006-01-02 15:04:05"), err.Error(), utils.EmailSendToUsers)
- }
- ch <- incrementalCompanyChart
- }()
- todayStr := utils.GetToday("20060102")
- key := "admin:home:incrementalCompanyList:" + todayStr + ":" + strconv.Itoa(sysUser.AdminId)
- redisJsonData, redisErr := utils.Rc.RedisString(key)
- if redisErr != nil {
- var condition string
- var pars []interface{}
- //根据当前角色来获取查询条件
- condition, pars = getQueryParams(condition, pars, sysUser, "c.")
- var dateSlice []string
- var newCompanySlice, renewalCompanySlice []int
- //var notRenewalCompanySlice []int
- yearNum := time.Now().Year() - 2021
- monthNum := time.Now().Month() - 1
- numMonth := yearNum*12 + int(monthNum) //距离2021-01存在多少个月
- for i := numMonth; i >= 0; i-- {
- timeNow, _ := time.Parse("2006-01", time.Now().Format("2006-01"))
- dateSlice = append(dateSlice, timeNow.AddDate(0, -i, 0).Format("06/01"))
- //开始日期
- startDate := timeNow.AddDate(0, -i, 0).Format("2006-01")
- startDate = fmt.Sprint(startDate, "-01")
- //结束日期
- endDateTime := timeNow.AddDate(0, -i+1, 0)
- endDate := endDateTime.Format("2006-01")
- //因为就算是当月的后续事件还没到,也要计入数据统计,所以不做限制到当天处理
- //if endDateTime.After(time.Now()) {
- // endDate = time.Now().AddDate(0, 0, 1).Format(utils.FormatDate)
- //} else {
- // endDate = fmt.Sprint(endDate, "-01")
- //}
- endDate = fmt.Sprint(endDate, "-01")
- //新签客户数
- {
- condition1 := condition
- pars1 := pars
- condition1 += ` AND a.start_date >= ? AND a.start_date < ? `
- pars1 = append(pars1, startDate, endDate)
- condition1 += ` AND a.contract_type = ? `
- pars1 = append(pars1, "新签合同")
- total, countErr := models.GetIncrementalNewCompanyCount(condition1, pars1)
- if countErr != nil && countErr.Error() != utils.ErrNoRow() {
- err = countErr
- return
- }
- newCompanySlice = append(newCompanySlice, total)
- }
- //续约客户数
- {
- //2022-02-07 13:26:48注释掉,更改成以下的逻辑,续约客户定义修改:续约合同的起始日期包含在所选时间段内且不包含在新签合同存续期内的客户
- //condition1 := condition
- //pars1 := pars
- //condition1 += ` AND a.start_date >= ? AND a.start_date < ? `
- //pars1 = append(pars1, startDate, endDate)
- //condition1 += ` AND a.contract_type = ? `
- //pars1 = append(pars1, "续约合同")
- //total, countErr := models.GetIncrementalNewCompanyCount(condition1, pars1)
- //if countErr != nil && countErr.Error() != utils.ErrNoRow() {
- // err = countErr
- // return
- //}
- //renewalCompanySlice = append(renewalCompanySlice, total)
- //2022-02-07 13:26:48;更改成以下的逻辑,续约客户定义修改:续约合同的起始日期包含在所选时间段内且不包含在新签合同存续期内的客户
- condition1 := condition
- pars1 := pars
- condition1 += ` AND a.start_date >= ? AND a.start_date < ? `
- pars1 = append(pars1, startDate, endDate)
- condition1 += ` AND a.contract_type = ? `
- pars1 = append(pars1, "续约合同")
- //额外条件(续约合同的起始日期包含在所选时间段内且不包含在新签合同存续期内的客户)
- pars1 = append(pars1, endDate)
- total, countErr := models.GetIncrementalNewCompanyCountV2(condition1, pars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- err = countErr
- return
- }
- renewalCompanySlice = append(renewalCompanySlice, total)
- }
- //未续约客户数
- //{
- // condition1 := condition
- // pars1 := pars
- //
- // condition1 += ` AND a.create_time >= ? AND a.create_time < ? `
- // pars1 = append(pars1, fmt.Sprint(startDate, " 00:00:00"), fmt.Sprint(endDate, " 00:00:00"))
- // condition1 += ` AND a.operation = ? `
- // pars1 = append(pars1, "try_out")
- // total, countErr := models.GetIncrementalCompanyCountByOperationRecord(condition1, pars1)
- // if countErr != nil && countErr.Error() != utils.ErrNoRow() {
- // err = countErr
- // return
- // }
- // notRenewalCompanySlice = append(notRenewalCompanySlice, total)
- //}
- }
- incrementalCompanyChart.Title = "客户增量图"
- incrementalCompanyChart.Date = dateSlice
- incrementalCompanyChart.NewCompanyTotal = newCompanySlice
- incrementalCompanyChart.RenewalCompanyTotal = renewalCompanySlice
- //incrementalCompanyChart.NotRenewalCompanyTotal = notRenewalCompanySlice
- redisJsonData, err := json.Marshal(incrementalCompanyChart)
- if err == nil {
- _ = utils.Rc.Put(key, string(redisJsonData), time.Minute*30)
- }
- } else {
- err = json.Unmarshal([]byte(redisJsonData), &incrementalCompanyChart)
- if err != nil {
- fmt.Println("近6个月客户增量图,json转换失败")
- }
- }
- return
- }
- // 获取未来近6个月的即将到期客户
- func getWillExpireList(sysUser *system.Admin, ch chan response.WillExpireChartResp) (willExpireChart response.WillExpireChartResp, err error) {
- defer func() {
- if err != nil {
- go alarm_msg.SendAlarmMsg("获取未来近6个月的即将到期客户数据异常,Err:"+err.Error(), 3)
- //go utils.SendEmail(utils.APPNAME+"获取未来近6个月的即将到期客户数据异常:"+time.Now().Format("2006-01-02 15:04:05"), err.Error(), utils.EmailSendToUsers)
- }
- ch <- willExpireChart
- }()
- todayStr := utils.GetToday("20060102")
- key := "admin:home:willExpireList:" + todayStr + ":" + strconv.Itoa(sysUser.AdminId)
- redisJsonData, redisErr := utils.Rc.RedisString(key)
- if redisErr != nil {
- var condition string
- var pars []interface{}
- //根据当前角色来获取查询条件
- condition, pars = getQueryParams(condition, pars, sysUser, "a.")
- var dateSlice []string
- var companySlice []int
- for i := 0; i < 6; i++ {
- //timeNow, _ := time.Parse("2006-01", time.Now().Format("2006-01"))
- //startDate := timeNow.Format(utils.FormatDate)
- startDate := utils.GetToday(utils.FormatDate)
- //endDate := timeNow.AddDate(0, i+1, 0).Format(utils.FormatDate)
- endDate := time.Now().AddDate(0, i+1, 0).Format(utils.FormatDate)
- dateSlice = append(dateSlice, fmt.Sprint("未来", i+1, "个月"))
- condition1 := condition
- pars1 := pars
- condition1 += ` AND a.contract_end_date >= ? AND a.contract_end_date <= ? `
- pars1 = append(pars1, startDate, endDate)
- total, countErr := models.GetWillExpireCompanyListCountV2(condition1, pars1)
- if countErr != nil && countErr.Error() != utils.ErrNoRow() {
- err = countErr
- return
- }
- companySlice = append(companySlice, total)
- }
- willExpireChart.Title = "即将到期客户数"
- willExpireChart.Date = dateSlice
- willExpireChart.CompanyTotal = companySlice
- redisJsonData, err := json.Marshal(willExpireChart)
- if err == nil {
- _ = utils.Rc.Put(key, string(redisJsonData), time.Minute*30)
- }
- } else {
- err = json.Unmarshal([]byte(redisJsonData), &willExpireChart)
- if err != nil {
- fmt.Println("未来近6个月的即将到期客户,json转换失败")
- }
- }
- return
- }
- // 获取近12个月的收入统计数据
- func getIncomeList(sysUser *system.Admin, ch chan response.IncomeChartResp) (incomeChart response.IncomeChartResp, err error) {
- defer func() {
- if err != nil {
- go alarm_msg.SendAlarmMsg("获取近12个月的收入统计数据异常,Err:"+err.Error(), 3)
- //go utils.SendEmail(utils.APPNAME+"获取近12个月的收入统计数据异常:"+time.Now().Format("2006-01-02 15:04:05"), err.Error(), utils.EmailSendToUsers)
- }
- ch <- incomeChart
- }()
- todayStr := utils.GetToday("20060102")
- key := "admin:home:incomeList:" + todayStr + ":" + strconv.Itoa(sysUser.AdminId)
- redisJsonData, redisErr := utils.Rc.RedisString(key)
- if redisErr != nil {
- var condition string
- var pars []interface{}
- //根据当前角色来获取查询条件
- condition, pars = getQueryParams(condition, pars, sysUser, "c.")
- var dateSlice []string
- var contractTotalSlice []int
- var moneySlice []float64
- yearNum := time.Now().Year() - 2021
- monthNum := time.Now().Month() - 1
- numMonth := yearNum*12 + int(monthNum) //距离2021-01存在多少个月
- for i := numMonth; i >= 0; i-- {
- timeNow, _ := time.Parse("2006-01", time.Now().Format("2006-01"))
- dateSlice = append(dateSlice, timeNow.AddDate(0, -i, 0).Format("06/01"))
- //开始日期
- startDate := timeNow.AddDate(0, -i, 0).Format("2006-01")
- startDate = fmt.Sprint(startDate, "-01")
- //结束日期
- endDateTime := timeNow.AddDate(0, -i+1, 0)
- endDate := endDateTime.Format("2006-01")
- //因为就算是当月的后续事件还没到,也要计入数据统计,所以不做限制到当天处理
- //if endDateTime.After(time.Now()) {
- // endDate = time.Now().AddDate(0, 0, 1).Format(utils.FormatDate)
- //} else {
- // endDate = fmt.Sprint(endDate, "-01")
- //}
- endDate = fmt.Sprint(endDate, "-01")
- condition1 := condition
- pars1 := pars
- condition1 += ` AND a.start_date >= ? AND a.start_date < ? `
- pars1 = append(pars1, startDate, endDate)
- total, money, countErr := models.GetIncomeListCount(condition1, pars1)
- if countErr != nil && countErr.Error() != utils.ErrNoRow() {
- err = countErr
- return
- }
- contractTotalSlice = append(contractTotalSlice, total)
- moneySlice = append(moneySlice, money)
- }
- incomeChart.Title = "收入统计图"
- incomeChart.Date = dateSlice
- incomeChart.ContractTotal = contractTotalSlice
- incomeChart.MoneyTotal = moneySlice
- redisJsonData, err := json.Marshal(incomeChart)
- if err == nil {
- _ = utils.Rc.Put(key, string(redisJsonData), time.Minute*30)
- }
- } else {
- err = json.Unmarshal([]byte(redisJsonData), &incomeChart)
- if err != nil {
- fmt.Println("近6个月的收入统计数据,json转换失败")
- }
- }
- return
- }
- // WillExpireList
- // @Title 获取即将过期的客户列表
- // @Description 获取即将过期的客户列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param Keyword query string true "客户名称"
- // @Param StartDate query string true "开始日期"
- // @Param EndDate query string true "结束日期"
- // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
- // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
- // @Param RegionType query string false "所属区域:传空字符串或者不传为全部,'国内','海外'"
- // @Param IsExport query bool false "是否导出excel,默认是false"
- // @Success 200 {object} response.WillExpireCompanyListResp
- // @router /will_expire_list [get]
- func (this *StatisticReportController) WillExpireList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- //是否导出报表
- isExport, _ := this.GetBool("IsExport")
- if isExport {
- pageSize = 10000
- currentIndex = 1
- }
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- adminId := this.GetString("AdminId")
- regionType := this.GetString("RegionType")
- companyType := this.GetString("CompanyType")
- keyword := this.GetString("Keyword")
- if startDate == "" {
- startDate = time.Now().Format(utils.FormatDate)
- //br.Msg = "获取失败,开始日期未传"
- //br.ErrMsg = "获取失败,开始日期未传"
- //return
- }
- if endDate == "" {
- endDate = time.Now().AddDate(100, 0, 0).Format(utils.FormatDate)
- //br.Msg = "获取失败,结束日期未传"
- //br.ErrMsg = "获取失败,结束日期未传"
- //return
- }
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- //today := utils.GetToday(utils.FormatDate)
- condition += ` AND a.contract_end_date >= ? AND a.contract_end_date <= ? `
- pars = append(pars, startDate, endDate)
- if adminId != "" {
- condition += ` AND a.seller_id in (` + adminId + `) `
- //pars = append(pars, adminId)
- } else {
- //根据当前角色来获取查询条件
- condition, pars = getQueryParams(condition, pars, sysUser, "a.")
- }
- if regionType != "" {
- condition += ` AND b.region_type = ? `
- pars = append(pars, regionType)
- }
- //关键字搜索
- if keyword != "" {
- condition += ` and b.company_name like "%` + keyword + `%" `
- }
- switch companyType {
- case "ficc":
- condition += ` AND a.product_id = ? `
- pars = append(pars, 1)
- case "权益":
- condition += ` AND a.product_id = ? `
- pars = append(pars, 2)
- case "":
- default:
- br.Msg = "获取失败,客户类型异常"
- br.ErrMsg = "获取失败,客户类型异常"
- return
- }
- totalCompany, err := models.GetWillExpireCompanyListCountV2(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- totalContract, err := models.GetWillExpireContactListCountV2(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list, err := models.GetWillExpireCompanyListV2(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- listLen := len(list)
- permissionListMap := make(map[string][]*company.CompanyReportPermissionAndName)
- if listLen > 0 {
- companyIdSlice := make([]string, 0)
- for _, v := range list {
- companyIdSlice = append(companyIdSlice, strconv.Itoa(v.CompanyId))
- }
- companyIds := strings.Join(companyIdSlice, ",")
- permissionList, permissionErr := company.GetCompanyReportPermissionListByCompanyIds(companyIds)
- if permissionErr != nil {
- br.Msg = "获取权限失败"
- br.ErrMsg = "获取权限失败,Err:" + permissionErr.Error()
- return
- }
- for _, permission := range permissionList {
- key := fmt.Sprint(permission.CompanyId, "_", permission.ProductId)
- permissionListMap[key] = append(permissionListMap[key], permission)
- }
- }
- for i := 0; i < listLen; i++ {
- item := list[i]
- //剩余可用天数
- endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
- endDateTime = endDateTime.AddDate(0, 0, 1)
- sub := endDateTime.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
- list[i].ExpireDay = expireDay
- key := fmt.Sprint(item.CompanyId, "_", item.ProductId)
- if permissionList, ok := permissionListMap[key]; ok {
- for _, permission := range permissionList {
- if item.ProductId == permission.ProductId {
- list[i].PermissionList = append(list[i].PermissionList, permission)
- }
- }
- //list[i].PermissionList = permissionList
- }
- }
- page := paging.GetPaging(currentIndex, pageSize, totalContract)
- resp := response.WillExpireCompanyListResp{
- Paging: page,
- List: list,
- TotalCompany: totalCompany,
- }
- //导出excel
- if isExport {
- WillExpireListExport(this, resp, br)
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // WillExpireListExport 即将过期的客户报表导出
- func WillExpireListExport(this *StatisticReportController, resp response.WillExpireCompanyListResp, br *models.BaseResponse) {
- dir, err := os.Executable()
- exPath := filepath.Dir(dir)
- downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- xlsxFile := xlsx.NewFile()
- if err != nil {
- br.Msg = "生成文件失败"
- br.ErrMsg = "生成文件失败"
- return
- }
- style := xlsx.NewStyle()
- alignment := xlsx.Alignment{
- Horizontal: "center",
- Vertical: "center",
- WrapText: true,
- }
- style.Alignment = alignment
- style.ApplyAlignment = true
- sheel, err := xlsxFile.AddSheet("即将到期客户数据")
- if err != nil {
- br.Msg = "新增Sheet失败"
- br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
- return
- }
- sheel.SetColWidth(0, 0, 30)
- sheel.SetColWidth(1, 1, 15)
- sheel.SetColWidth(2, 2, 15)
- sheel.SetColWidth(3, 3, 18)
- //统计数据
- statisticRow := sheel.AddRow()
- cell1 := statisticRow.AddCell()
- cell1.SetStyle(style)
- cell1.SetValue(fmt.Sprint("即将到期客户数:", resp.TotalCompany))
- //表头
- titleRow := sheel.AddRow()
- cellName := titleRow.AddCell()
- cellName.SetStyle(style)
- cellName.SetValue("客户名称")
- cellProName := titleRow.AddCell()
- cellProName.SetStyle(style)
- cellProName.SetValue("客户类型")
- cellSellerName := titleRow.AddCell()
- cellSellerName.SetStyle(style)
- cellSellerName.SetValue("所属销售")
- cellTime := titleRow.AddCell()
- cellTime.SetStyle(style)
- cellTime.SetValue("服务期限")
- cellDay := titleRow.AddCell()
- cellDay.SetStyle(style)
- cellDay.SetValue("剩余天数")
- for _, v := range resp.List {
- dataRow := sheel.AddRow()
- dataRow.SetHeight(20)
- cellDataName := dataRow.AddCell()
- cellDataName.SetStyle(style)
- cellDataName.SetValue(v.CompanyName)
- cellDataProName := dataRow.AddCell()
- cellDataProName.SetStyle(style)
- cellDataProName.SetValue(v.ProductName)
- cellDataSellerName := dataRow.AddCell()
- cellDataSellerName.SetStyle(style)
- cellDataSellerName.SetValue(v.SellerName)
- cellDataTime := dataRow.AddCell()
- cellDataTime.SetStyle(style)
- cellDataTime.SetValue(fmt.Sprint(v.StartDate, " ~ ", v.EndDate))
- cellDay := dataRow.AddCell()
- cellDay.SetStyle(style)
- cellDay.SetValue(v.ExpireDay)
- }
- err = xlsxFile.Save(downLoadnFilePath)
- if err != nil {
- br.Msg = "保存文件失败"
- br.ErrMsg = "保存文件失败"
- return
- }
- randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
- downloadFileName := "即将到期客户数据_" + randStr + ".xlsx"
- this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
- defer func() {
- os.Remove(downLoadnFilePath)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "导出成功"
- }
- func (this *StatisticReportController) WillExpireListOld() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- adminId := this.GetString("AdminId")
- regionType := this.GetString("RegionType")
- companyType := this.GetString("CompanyType")
- if startDate == "" {
- br.Msg = "获取失败,开始日期未传"
- br.ErrMsg = "获取失败,开始日期未传"
- return
- }
- if endDate == "" {
- br.Msg = "获取失败,结束日期未传"
- br.ErrMsg = "获取失败,结束日期未传"
- return
- }
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- //today := utils.GetToday(utils.FormatDate)
- condition += ` AND a.end_date >= ? AND a.end_date <= ? `
- pars = append(pars, startDate, endDate)
- if adminId != "" {
- condition += ` AND c.seller_id in (` + adminId + `) `
- //pars = append(pars, adminId)
- } else {
- //根据当前角色来获取查询条件
- condition, pars = getQueryParams(condition, pars, sysUser, "c.")
- }
- if regionType != "" {
- condition += ` AND b.region_type = ? `
- pars = append(pars, regionType)
- }
- switch companyType {
- case "ficc":
- condition += ` AND a.product_id = ? `
- pars = append(pars, 1)
- case "权益":
- condition += ` AND a.product_id = ? `
- pars = append(pars, 2)
- case "":
- default:
- br.Msg = "获取失败,客户类型异常"
- br.ErrMsg = "获取失败,客户类型异常"
- return
- }
- totalCompany, err := models.GetWillExpireCompanyListCount(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- totalContract, err := models.GetWillExpireContactListCount(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list, err := models.GetWillExpireCompanyList(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- listLen := len(list)
- permissionListMap := make(map[string][]*company.CompanyReportPermissionAndName)
- if listLen > 0 {
- companyIdSlice := make([]string, 0)
- for _, v := range list {
- companyIdSlice = append(companyIdSlice, strconv.Itoa(v.CompanyId))
- }
- companyIds := strings.Join(companyIdSlice, ",")
- permissionList, permissionErr := company.GetCompanyReportPermissionListByCompanyIds(companyIds)
- if permissionErr != nil {
- br.Msg = "获取权限失败"
- br.ErrMsg = "获取权限失败,Err:" + permissionErr.Error()
- return
- }
- for _, permission := range permissionList {
- key := fmt.Sprint(permission.CompanyId, "_", permission.ProductId)
- permissionListMap[key] = append(permissionListMap[key], permission)
- }
- }
- for i := 0; i < listLen; i++ {
- item := list[i]
- //剩余可用天数
- endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
- endDateTime = endDateTime.AddDate(0, 0, 1)
- sub := endDateTime.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
- list[i].ExpireDay = expireDay
- key := fmt.Sprint(item.CompanyId, "_", item.ProductId)
- if permissionList, ok := permissionListMap[key]; ok {
- for _, permission := range permissionList {
- if item.ProductId == permission.ProductId {
- list[i].PermissionList = append(list[i].PermissionList, permission)
- }
- }
- //list[i].PermissionList = permissionList
- }
- }
- page := paging.GetPaging(currentIndex, pageSize, totalContract)
- resp := response.WillExpireCompanyListResp{
- Paging: page,
- List: list,
- TotalCompany: totalCompany,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // ContractList
- // @Title 获取合同数据报表
- // @Description 获取合同数据报表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param Keyword query string true "客户名称"
- // @Param EndDate query string true "结束日期"
- // @Param CompanyType query string false "客户类型:传空字符串或者不传为全部,'ficc','权益'"
- // @Param AdminId query string false "销售id,多个用英文逗号隔开,空字符串为全部"
- // @Param RegionType query string false "所属区域:传空字符串或者不传为全部,'国内','海外'"
- // @Param DataType query string false "报表类型,枚举值:`普通数据`,`类型数据`;传空字符串或者不传为:普通数据"
- // @Param SourceType query string false "合同类型,枚举值:`系统合同`,`上传附件`;传空字符串或者不传为全部合同"
- // @Param IsExport query bool false "是否导出excel,默认是false"
- // @Success 200 {object} models.ContractStatListResp
- // @router /contract_list [get]
- func (this *StatisticReportController) ContractList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- //是否导出报表
- isExport, _ := this.GetBool("IsExport")
- if isExport {
- pageSize = 10000
- currentIndex = 1
- }
- endDate := this.GetString("EndDate")
- adminId := this.GetString("AdminId")
- regionType := this.GetString("RegionType")
- companyType := this.GetString("CompanyType")
- keyword := this.GetString("Keyword")
- dataType := this.GetString("DataType") //数据报表类型
- sourceType := this.GetString("SourceType") //合同来源
- if endDate == "" {
- br.Msg = "获取失败,结束日期未传"
- br.ErrMsg = "获取失败,结束日期未传"
- return
- }
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- //上传附件
- var sourceFileCondition string
- var sourceFilePars []interface{}
- //系统合同
- var sourceSystemCondition string
- var sourceSystemPars []interface{}
- condition += ` AND a.start_date <= ? AND a.end_date >= ? `
- pars = append(pars, endDate, endDate)
- sourceFileCondition += ` AND a.create_time <= ? `
- sourceFilePars = append(sourceFilePars, endDate)
- sourceSystemCondition += ` AND a.check_back_file_time <= "` + endDate + ` 23:59:59"`
- //sourceSystemPars = append(sourceSystemPars, endDate)
- //condition += ` AND c.status = "正式" `
- if adminId != "" {
- condition += ` AND c.seller_id in (` + adminId + `) `
- sourceFileCondition += ` AND c.seller_id in (` + adminId + `) `
- sourceSystemCondition += ` AND a.seller_id in (` + adminId + `) `
- //pars = append(pars, adminId)
- } else {
- //根据当前角色来获取查询条件
- condition, pars = getQueryParams(condition, pars, sysUser, "c.")
- sourceFileCondition, sourceFilePars = getQueryParams(sourceFileCondition, sourceFilePars, sysUser, "c.")
- //合同
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
- sourceSystemCondition += ` AND a.product_id=? `
- sourceSystemPars = append(sourceSystemPars, 1)
- } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
- sourceSystemCondition += ` AND a.product_id=? `
- sourceSystemPars = append(sourceSystemPars, 2)
- } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FINANCE {
- //超级管理员账户,不做条件限制
- } else {
- //如果不是研究员,那么去找对应的 部门、小组、销售
- if sysUser.Authority == 0 {
- //普通用户
- sourceSystemCondition += ` AND a.seller_id=? `
- sourceSystemPars = append(sourceSystemPars, sysUser.AdminId)
- } else if sysUser.Authority == 1 {
- //部门主管
- sourceSystemCondition += ` AND b.department_id=? `
- sourceSystemPars = append(sourceSystemPars, sysUser.DepartmentId)
- } else if sysUser.Authority == 2 {
- //小组负责人
- sourceSystemCondition += ` AND b.group_id=? `
- sourceSystemPars = append(sourceSystemPars, sysUser.GroupId)
- } else {
- //不知道什么类型的用户(后面新增的位置类型客户)
- sourceSystemCondition += ` AND a.seller_id=? `
- sourceSystemPars = append(sourceSystemPars, sysUser.AdminId)
- }
- }
- }
- if regionType != "" {
- condition += ` AND b.region_type = ? `
- pars = append(pars, regionType)
- }
- //关键字搜索
- if keyword != "" {
- condition += ` and b.company_name like "%` + keyword + `%" `
- }
- switch companyType {
- case "ficc":
- condition += ` AND a.product_id = ? `
- pars = append(pars, 1)
- case "权益":
- condition += ` AND a.product_id = ? `
- pars = append(pars, 2)
- case "":
- default:
- br.Msg = "获取失败,客户类型异常"
- br.ErrMsg = "获取失败,客户类型异常"
- return
- }
- dataTotal := 0 //页面数据总数
- total, totalContract, money, err := models.GetContractStatListCount(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- //上传附件
- totalFileContract, err := models.GetContractStatListCountBySource("上传附件", sourceFileCondition, sourceSystemCondition, sourceFilePars, sourceSystemPars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- //系统合同
- totalSystemContract, err := models.GetContractStatListCountBySource("系统合同", sourceFileCondition, sourceSystemCondition, sourceFilePars, sourceSystemPars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list := make([]*models.ContractStatList, 0)
- if dataType == "类型数据" {
- if sourceType != "" {
- condition += ` AND a.source=? `
- pars = append(pars, sourceType)
- }
- //列表数据
- tmpList, err := models.GetContractStatListBySource(sourceType, sourceFileCondition, sourceSystemCondition, sourceFilePars, sourceSystemPars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- for _, v := range tmpList {
- if v.ProductId == 1 {
- v.ProductName = "ficc"
- } else {
- v.ProductName = "权益"
- }
- }
- list = tmpList
- } else {
- //列表数据
- tmpList, err := models.GetContractStatList(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list = tmpList
- }
- //listLen := len(list)
- //for i := 0; i < listLen; i++ {
- // item := list[i]
- //}
- if dataType == "类型数据" {
- switch sourceType {
- case "上传附件":
- dataTotal = totalFileContract
- case "系统合同":
- dataTotal = totalSystemContract
- default:
- dataTotal = totalFileContract + totalSystemContract
- }
- } else {
- dataTotal = total
- }
- page := paging.GetPaging(currentIndex, pageSize, dataTotal)
- resp := response.ContractStatListResp{
- Paging: page,
- List: list,
- TotalMoney: money,
- TotalCompany: total,
- TotalFileContract: totalFileContract,
- TotalSystemContract: totalSystemContract,
- TotalContract: totalContract,
- }
- //导出excel
- if isExport {
- ContractListExport(this, resp, br)
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // ContractListExport 合同数据报表导出
- func ContractListExport(this *StatisticReportController, resp response.ContractStatListResp, br *models.BaseResponse) {
- dataType := this.GetString("DataType") //数据报表类型
- dir, err := os.Executable()
- exPath := filepath.Dir(dir)
- downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- xlsxFile := xlsx.NewFile()
- if err != nil {
- br.Msg = "生成文件失败"
- br.ErrMsg = "生成文件失败"
- return
- }
- style := xlsx.NewStyle()
- alignment := xlsx.Alignment{
- Horizontal: "center",
- Vertical: "center",
- WrapText: true,
- }
- style.Alignment = alignment
- style.ApplyAlignment = true
- sheel, err := xlsxFile.AddSheet("合同数据报表")
- if err != nil {
- br.Msg = "新增Sheet失败"
- br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
- return
- }
- sheel.SetColWidth(0, 0, 30)
- sheel.SetColWidth(1, 1, 15)
- sheel.SetColWidth(2, 2, 15)
- sheel.SetColWidth(3, 5, 18)
- //统计数据
- statisticRow := sheel.AddRow()
- cell1 := statisticRow.AddCell()
- cell1.SetStyle(style)
- cell1.SetValue(fmt.Sprint("有效合同数:", resp.TotalContract))
- cell2 := statisticRow.AddCell()
- cell2.SetStyle(style)
- cell2.SetValue(fmt.Sprint("有效合同总金额:", resp.TotalMoney))
- cell3 := statisticRow.AddCell()
- cell3.SetStyle(style)
- cell3.SetValue(fmt.Sprint("正式客户数:", resp.TotalCompany))
- cell4 := statisticRow.AddCell()
- cell4.SetStyle(style)
- cell4.SetValue(fmt.Sprint("总上传附件合同数:", resp.TotalFileContract))
- cell5 := statisticRow.AddCell()
- cell5.SetStyle(style)
- cell5.SetValue(fmt.Sprint("总系统生成合同数:", resp.TotalSystemContract))
- //表头
- titleRow := sheel.AddRow()
- cellName := titleRow.AddCell()
- cellName.SetStyle(style)
- cellName.SetValue("客户名称")
- cellProName := titleRow.AddCell()
- cellProName.SetStyle(style)
- cellProName.SetValue("客户类型")
- cellSellerName := titleRow.AddCell()
- cellSellerName.SetStyle(style)
- cellSellerName.SetValue("所属销售")
- if dataType == "类型数据" {
- cellContractNum := titleRow.AddCell()
- cellContractNum.SetStyle(style)
- cellContractNum.SetValue("生成方式")
- cellContractPrice := titleRow.AddCell()
- cellContractPrice.SetStyle(style)
- cellContractPrice.SetValue("合同提交时间")
- } else {
- cellContractNum := titleRow.AddCell()
- cellContractNum.SetStyle(style)
- cellContractNum.SetValue("有效合同数")
- cellContractPrice := titleRow.AddCell()
- cellContractPrice.SetStyle(style)
- cellContractPrice.SetValue("有效合同总金额")
- }
- for _, v := range resp.List {
- dataRow := sheel.AddRow()
- dataRow.SetHeight(20)
- cellDataName := dataRow.AddCell()
- cellDataName.SetStyle(style)
- cellDataName.SetValue(v.CompanyName)
- cellDataProName := dataRow.AddCell()
- cellDataProName.SetStyle(style)
- cellDataProName.SetValue(v.ProductName)
- cellDataSellerName := dataRow.AddCell()
- cellDataSellerName.SetStyle(style)
- cellDataSellerName.SetValue(v.SellerName)
- if dataType == "类型数据" {
- cellDataTime := dataRow.AddCell()
- cellDataTime.SetStyle(style)
- cellDataTime.SetValue(v.Source)
- cellDay := dataRow.AddCell()
- cellDay.SetStyle(style)
- cellDay.SetValue(v.CreateTime)
- } else {
- cellDataTime := dataRow.AddCell()
- cellDataTime.SetStyle(style)
- cellDataTime.SetValue(v.Count)
- cellDay := dataRow.AddCell()
- cellDay.SetStyle(style)
- cellDay.SetValue(v.SumMoney)
- }
- }
- err = xlsxFile.Save(downLoadnFilePath)
- if err != nil {
- br.Msg = "保存文件失败"
- br.ErrMsg = "保存文件失败"
- return
- }
- randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
- downloadFileName := "合同数据报表_" + randStr + ".xlsx"
- this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
- defer func() {
- os.Remove(downLoadnFilePath)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "导出成功"
- }
- // CompanyContractList
- // @Title 获取企业客户的合同数据报表
- // @Description 获取企业客户的合同数据报表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param EndDate query string true "结束日期"
- // @Param CompanyId query int true "企业客户id"
- // @Success 200 {object} response.CompanyContractStatListResp
- // @router /company_contract_list [get]
- func (this *StatisticReportController) CompanyContractList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- endDate := this.GetString("EndDate")
- companyId := this.GetString("CompanyId")
- //companyType := this.GetString("CompanyType")
- if endDate == "" {
- br.Msg = "获取失败,结束日期未传"
- br.ErrMsg = "获取失败,结束日期未传"
- return
- }
- sysUser := this.SysUser
- var condition string
- var pars []interface{}
- condition += ` AND a.start_date <= ? AND a.end_date >= ? `
- pars = append(pars, endDate, endDate)
- if companyId == "" {
- br.Msg = "获取失败,客户id未传"
- br.ErrMsg = "获取失败,客户id未传"
- return
- }
- condition += ` AND a.company_id = ? `
- pars = append(pars, companyId)
- //根据当前角色来获取查询条件
- if strings.Contains(sysUser.RoleTypeCode, "ficc") {
- condition += ` AND a.product_id = ? `
- pars = append(pars, 1)
- } else if strings.Contains(sysUser.RoleTypeCode, "rai") {
- condition += ` AND a.product_id = ? `
- pars = append(pars, 2)
- }
- //switch companyType {
- //case "ficc":
- // condition += ` AND a.product_id = ? `
- // pars = append(pars, 1)
- //case "权益":
- // condition += ` AND a.product_id = ? `
- // pars = append(pars, 2)
- //case "":
- //default:
- // br.Msg = "获取失败,客户类型异常"
- // br.ErrMsg = "获取失败,客户类型异常"
- // return
- //}
- list, err := models.GetCompanyContractStatList(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- listLen := len(list)
- permissionListMap := make(map[int][]*company.CompanyContractPermissionName)
- if listLen > 0 {
- companyContractIdSlice := make([]string, 0)
- for _, v := range list {
- companyContractIdSlice = append(companyContractIdSlice, strconv.Itoa(v.CompanyContractId))
- }
- companyContractIds := strings.Join(companyContractIdSlice, ",")
- permissionList, permissionErr := company.GetCompanyContractPermissionListByContractIds(companyContractIds)
- if permissionErr != nil {
- br.Msg = "获取权限失败"
- br.ErrMsg = "获取权限失败,Err:" + permissionErr.Error()
- return
- }
- // CRM8.8-权益权限主客观合并
- permissionList = contractService.EquityMergeSubjectAndObjectPermission(permissionList)
- //列表数据处理
- for i := 0; i < listLen; i++ {
- item := list[i]
- //权限拼接
- companyContractPermissionList := make([]models.CompanyContractPermission, 0)
- companyContractPermissionMap := make(map[string][]*company.CompanyContractPermissionName)
- for _, permission := range permissionList {
- if permission.IsUpgrade == 1 {
- permission.ChartPermissionName += "(升级)"
- }
- if permission.CompanyContractId == item.CompanyContractId {
- companyContractPermissionMap[permission.ClassifyName] = append(companyContractPermissionMap[permission.ClassifyName], permission)
- }
- permissionListMap[permission.CompanyContractId] = append(permissionListMap[permission.CompanyContractId], permission)
- }
- for classifyName, permissionList := range companyContractPermissionMap {
- companyContractPermission := models.CompanyContractPermission{
- ClassifyName: classifyName,
- PermissionList: permissionList,
- }
- companyContractPermissionList = append(companyContractPermissionList, companyContractPermission)
- }
- list[i].PermissionList = companyContractPermissionList
- }
- }
- resp := response.CompanyContractStatListResp{
- List: list,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // ContractDetailList
- // @Title 获取合同详情
- // @Description 获取企业客户的合同数据报表接口
- // @Param CompanyContractId query int true "客户合同id,进行过客户申请的"
- // @Param ContractId query int true "系统合同id"
- // @Success 200 {object} response.CompanyContractStatListResp
- // @router /contract_detail_list [get]
- func (this *StatisticReportController) ContractDetailList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- list := make([]*models.CompanyContractStatList, 0)
- item := models.CompanyContractStatList{}
- companyContractId, _ := this.GetInt("CompanyContractId")
- contractId, _ := this.GetInt("ContractId")
- companyContractPermissionList := make([]models.CompanyContractPermission, 0)
- if companyContractId > 0 {
- contractInfo, err := company.GetCompanyContractDetailByCompanyContractId(companyContractId)
- if err != nil {
- br.Msg = "获取合同失败"
- br.ErrMsg = "获取合同失败,Err:" + err.Error()
- return
- }
- permissionListMap := make(map[int][]*company.CompanyContractPermissionName)
- permissionList, err := company.GetCompanyContractPermissionListByContractId(contractInfo.CompanyContractId)
- if err != nil {
- br.Msg = "获取权限失败"
- br.ErrMsg = "获取权限失败,Err:" + err.Error()
- return
- }
- companyContractPermissionMap := make(map[string][]*company.CompanyContractPermissionName)
- for _, permission := range permissionList {
- //权限拼接
- if permission.IsUpgrade == 1 {
- permission.PermissionName += "(升级)"
- }
- companyContractPermissionMap[permission.ClassifyName] = append(companyContractPermissionMap[permission.ClassifyName], permission)
- permissionListMap[permission.CompanyContractId] = append(permissionListMap[permission.CompanyContractId], permission)
- }
- for classifyName, permissionList := range companyContractPermissionMap {
- companyContractPermission := models.CompanyContractPermission{
- ClassifyName: classifyName,
- PermissionList: permissionList,
- }
- companyContractPermissionList = append(companyContractPermissionList, companyContractPermission)
- }
- item = models.CompanyContractStatList{
- CompanyContractId: contractInfo.CompanyContractId,
- ContractType: contractInfo.ContractType,
- ProductId: contractInfo.ProductId,
- ProductName: contractInfo.ProductName,
- CompanyId: contractInfo.CompanyId,
- ContractCode: contractInfo.ContractCode,
- StartDate: contractInfo.StartDate,
- EndDate: contractInfo.EndDate,
- Money: contractInfo.Money,
- PayMethod: contractInfo.PayMethod,
- PayChannel: contractInfo.PayChannel,
- PermissionList: companyContractPermissionList,
- }
- list = append(list, &item)
- } else if contractId > 0 {
- contractInfo, err := contractService.GetContractDetail(contractId)
- if err != nil {
- br.Msg = "获取权限失败"
- br.ErrMsg = "获取权限失败,Err:" + err.Error()
- return
- }
- productName := "ficc"
- if contractInfo.ProductId == 2 {
- productName = `权益`
- }
- //合同中包含的产品权限
- permissionLookList, _ := contractService.GetPermissionByContractService(contractInfo.ProductId, contractInfo.Service)
- //权限处理
- for _, v := range permissionLookList {
- permissionList := make([]*company.CompanyContractPermissionName, 0)
- checkIdMap := make(map[int]int)
- for _, checkId := range v.CheckList {
- checkIdMap[checkId] = checkId
- }
- for _, permission := range v.Items {
- if _, ok := checkIdMap[permission.ChartPermissionId]; ok {
- tmpCompanyContractPermissionName := &company.CompanyContractPermissionName{
- ChartPermissionId: permission.ChartPermissionId,
- ChartPermissionName: permission.PermissionName,
- ClassifyName: permission.ClassifyName,
- StartDate: permission.StartDate,
- EndDate: permission.EndDate,
- //CreateTime :permission.ChartPermissionId,
- //ModifyTime :permission.ChartPermissionId,
- }
- permissionList = append(permissionList, tmpCompanyContractPermissionName)
- }
- }
- if len(permissionList) > 0 {
- companyContractPermission := models.CompanyContractPermission{
- ClassifyName: v.ClassifyName,
- PermissionList: permissionList,
- }
- companyContractPermissionList = append(companyContractPermissionList, companyContractPermission)
- }
- }
- item = models.CompanyContractStatList{
- //CompanyContractId :contractInfo.CompanyContractId,
- ContractType: contractInfo.ContractType,
- ProductId: contractInfo.ProductId,
- ProductName: productName,
- ContractCode: contractInfo.ContractCode,
- StartDate: contractInfo.StartDate.Format(utils.FormatDate),
- EndDate: contractInfo.EndDate.Format(utils.FormatDate),
- Money: contractInfo.Price,
- PayMethod: contractInfo.PayRemark,
- PayChannel: contractInfo.PayChannel,
- PermissionList: companyContractPermissionList,
- }
- list = append(list, &item)
- }
- resp := response.CompanyContractStatListResp{
- List: list,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // IncomeList
- // @Title 获取收入统计列表
- // @Description 获取收入统计列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param Keyword query string true "客户名称"
- // @Param StartDate query string true "开始月份"
- // @Param EndDate query string true "结束月份"
- // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
- // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
- // @Param RegionType query string false "所属区域:传空字符串或者不传为全部,'国内','海外'"
- // @Param IsExport query bool false "是否导出excel,默认是false"
- // @Success 200 {object} response.IncomeListResp
- // @router /income_list [get]
- func (this *StatisticReportController) IncomeList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- adminId := this.GetString("AdminId")
- regionType := this.GetString("RegionType")
- companyType := this.GetString("CompanyType")
- keyword := this.GetString("Keyword")
- //if startDate == "" || endDate == "" {
- // br.Msg = "获取失败,开始日期或结束日期未传"
- // br.ErrMsg = "获取失败,开始日期或结束日期未传"
- // return
- //}
- if startDate == "" {
- startDate = "2015-01"
- }
- if endDate == "" {
- endDate = time.Now().AddDate(100, 0, 0).Format("2006-01")
- }
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- //是否导出报表
- isExport, _ := this.GetBool("IsExport")
- if isExport {
- pageSize = 10000
- currentIndex = 1
- }
- var condition string
- var pars []interface{}
- //开始时间
- startDayTimes, startDayErr := time.Parse("2006-01", startDate)
- if startDayErr != nil {
- br.Msg = "获取失败,开始日期格式异常"
- br.ErrMsg = "获取失败,开始日期格式异常" + startDayErr.Error()
- return
- }
- startDay := startDayTimes.Format(utils.FormatDate)
- //结束时间
- endDayTimes, endDayErr := time.Parse("2006-01", endDate)
- if endDayErr != nil {
- br.Msg = "获取失败,结束日期格式异常"
- br.ErrMsg = "获取失败,结束日期格式异常" + endDayErr.Error()
- return
- }
- //本月最后一天
- endDayTimes = endDayTimes.AddDate(0, 1, -1)
- endDay := endDayTimes.Format(utils.FormatDate)
- //条件
- condition += ` AND a.start_date >= ? AND a.start_date <= ?`
- pars = append(pars, startDay, endDay)
- if adminId != "" {
- condition += ` AND c.seller_id in (` + adminId + `) `
- //pars = append(pars, adminId)
- } else {
- //根据当前角色来获取查询条件
- condition, pars = getQueryParams(condition, pars, sysUser, "c.")
- }
- if regionType != "" {
- condition += ` AND b.region_type = ? `
- pars = append(pars, regionType)
- }
- //关键字搜索
- if keyword != "" {
- condition += ` and b.company_name like "%` + keyword + `%" `
- }
- switch companyType {
- case "ficc":
- condition += ` AND a.product_id = ? `
- pars = append(pars, 1)
- case "权益":
- condition += ` AND a.product_id = ? `
- pars = append(pars, 2)
- case "":
- default:
- br.Msg = "获取失败,客户类型异常"
- br.ErrMsg = "获取失败,客户类型异常"
- return
- }
- total, money, err := models.GetIncomeListCount(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list, err := models.GetIncomeList(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- listLen := len(list)
- if listLen > 0 {
- permissionListMap := make(map[int][]*company.CompanyContractPermissionName)
- companyContractIdSlice := make([]string, 0)
- for _, v := range list {
- companyContractIdSlice = append(companyContractIdSlice, strconv.Itoa(v.CompanyContractId))
- }
- companyContractIds := strings.Join(companyContractIdSlice, ",")
- //49, 50,28
- permissionList, permissionErr := company.GetCompanyContractPermissionListByContractIds(companyContractIds)
- if permissionErr != nil {
- br.Msg = "获取权限失败"
- br.ErrMsg = "获取权限失败,Err:" + permissionErr.Error()
- return
- }
- // CRM8.8-权益主客观权限合并
- permissionList = contractService.EquityMergeSubjectAndObjectPermission(permissionList)
- for i := 0; i < listLen; i++ {
- item := list[i]
- //剩余可用天数
- endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
- endDateTime = endDateTime.AddDate(0, 0, 1)
- sub := endDateTime.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
- list[i].ExpireDay = expireDay
- //权限拼接
- companyContractPermissionList := make([]models.CompanyContractPermission, 0)
- companyContractPermissionMap := make(map[string][]*company.CompanyContractPermissionName)
- for _, permission := range permissionList {
- if permission.CompanyContractId == item.CompanyContractId {
- if permission.IsUpgrade == 1 {
- permission.ChartPermissionName += "(升级)"
- }
- companyContractPermissionMap[permission.ClassifyName] = append(companyContractPermissionMap[permission.ClassifyName], permission)
- }
- permissionListMap[permission.CompanyContractId] = append(permissionListMap[permission.CompanyContractId], permission)
- }
- for classifyName, permissionList := range companyContractPermissionMap {
- companyContractPermission := models.CompanyContractPermission{
- ClassifyName: classifyName,
- PermissionList: permissionList,
- }
- companyContractPermissionList = append(companyContractPermissionList, companyContractPermission)
- }
- list[i].PermissionList = companyContractPermissionList
- }
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := response.IncomeListResp{
- Paging: page,
- List: list,
- Total: total,
- Money: money,
- }
- //导出excel
- if isExport {
- IncomeListExport(this, resp, br)
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // IncomeListExport 收入统计报表导出
- func IncomeListExport(this *StatisticReportController, resp response.IncomeListResp, br *models.BaseResponse) {
- dir, err := os.Executable()
- exPath := filepath.Dir(dir)
- downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- xlsxFile := xlsx.NewFile()
- if err != nil {
- br.Msg = "生成文件失败"
- br.ErrMsg = "生成文件失败"
- return
- }
- style := xlsx.NewStyle()
- alignment := xlsx.Alignment{
- Horizontal: "center",
- Vertical: "center",
- WrapText: true,
- }
- style.Alignment = alignment
- style.ApplyAlignment = true
- sheel, err := xlsxFile.AddSheet("收入统计报表")
- if err != nil {
- br.Msg = "新增Sheet失败"
- br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
- return
- }
- sheel.SetColWidth(0, 0, 30)
- sheel.SetColWidth(1, 1, 15)
- sheel.SetColWidth(2, 2, 15)
- sheel.SetColWidth(3, 3, 18)
- //统计数据
- statisticRow := sheel.AddRow()
- cell1 := statisticRow.AddCell()
- cell1.SetStyle(style)
- cell1.SetValue(fmt.Sprint("签约合同数:", resp.Total))
- cell2 := statisticRow.AddCell()
- cell2.SetStyle(style)
- cell2.SetValue(fmt.Sprint("签约合同总金额:", resp.Money))
- //表头
- titleRow := sheel.AddRow()
- cellContractNo := titleRow.AddCell()
- cellContractNo.SetStyle(style)
- cellContractNo.SetValue("合同编号")
- cellName := titleRow.AddCell()
- cellName.SetStyle(style)
- cellName.SetValue("客户名称")
- cellProName := titleRow.AddCell()
- cellProName.SetStyle(style)
- cellProName.SetValue("客户类型")
- cellSellerName := titleRow.AddCell()
- cellSellerName.SetStyle(style)
- cellSellerName.SetValue("所属销售")
- cellContractPrice := titleRow.AddCell()
- cellContractPrice.SetStyle(style)
- cellContractPrice.SetValue("合同金额")
- cellContractPayMethod := titleRow.AddCell()
- cellContractPayMethod.SetStyle(style)
- cellContractPayMethod.SetValue("付款方式")
- cellContractPayChannel := titleRow.AddCell()
- cellContractPayChannel.SetStyle(style)
- cellContractPayChannel.SetValue("付款渠道")
- cellContractDate := titleRow.AddCell()
- cellContractDate.SetStyle(style)
- cellContractDate.SetValue("服务期限")
- for _, v := range resp.List {
- dataRow := sheel.AddRow()
- dataRow.SetHeight(20)
- cellDataContractNo := dataRow.AddCell()
- cellDataContractNo.SetStyle(style)
- cellDataContractNo.SetValue(v.ContractCode)
- cellDataName := dataRow.AddCell()
- cellDataName.SetStyle(style)
- cellDataName.SetValue(v.CompanyName)
- cellDataProName := dataRow.AddCell()
- cellDataProName.SetStyle(style)
- cellDataProName.SetValue(v.ProductName)
- cellDataSellerName := dataRow.AddCell()
- cellDataSellerName.SetStyle(style)
- cellDataSellerName.SetValue(v.SellerName)
- cellDataPrice := dataRow.AddCell()
- cellDataPrice.SetStyle(style)
- cellDataPrice.SetValue(v.Money)
- cellDataPayMethod := dataRow.AddCell()
- cellDataPayMethod.SetStyle(style)
- cellDataPayMethod.SetValue(v.PayMethod)
- cellDataPayChannel := dataRow.AddCell()
- cellDataPayChannel.SetStyle(style)
- cellDataPayChannel.SetValue(v.PayChannel)
- cellDay := dataRow.AddCell()
- cellDay.SetStyle(style)
- cellDay.SetValue(fmt.Sprint(v.StartDate, " ~ ", v.EndDate))
- }
- err = xlsxFile.Save(downLoadnFilePath)
- if err != nil {
- br.Msg = "保存文件失败"
- br.ErrMsg = "保存文件失败"
- return
- }
- randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
- downloadFileName := "收入统计报表_" + randStr + ".xlsx"
- this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
- defer func() {
- os.Remove(downLoadnFilePath)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "导出成功"
- }
- // StackCompanyList
- // @Title 获取存量客户数据列表
- // @Description 获取存量客户数据列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param Keyword query string true "客户名称"
- // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
- // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
- // @Param RegionType query string false "所属区域:传空字符串或者不传为全部,'国内','海外'"
- // @Param Date query string false "日期"
- // @Param DataType query string false "报表类型,枚举值:`新签客户`,`续约客户`,`未续约客户`"
- // @Param TryOutType query string false " '试用', '非试用' 非试用即为冻结/流失"
- // @Param IsExport query bool false "是否导出excel,默认是false"
- // @Param IsConfirm query int false "是否确认续约: -1-默认全部; 0-待确认; 1-已确认"
- // @Param CompanyAscribeId query int false "归因ID"
- // @Success 200 {object} response.StackCompanyListResp
- // @router /stack_company_list [get]
- func (this *StatisticReportController) StackCompanyList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- //是否导出报表
- isExport, _ := this.GetBool("IsExport")
- if isExport {
- pageSize = 10000
- currentIndex = 1
- }
- adminId := this.GetString("AdminId")
- regionType := this.GetString("RegionType")
- companyType := this.GetString("CompanyType")
- dataType := this.GetString("DataType")
- tryOutType := this.GetString("TryOutType")
- keyword := this.GetString("Keyword")
- date := this.GetString("Date")
- isConfirm, _ := this.GetInt("IsConfirm", -1) // CRM 13.9
- companyAscribeId, _ := this.GetInt("CompanyAscribeId", -1) // CRM 13.9
- if date == "" {
- br.Msg = "获取失败,请选择日期"
- br.ErrMsg = "获取失败,请选择日期"
- return
- }
- //获取筛选时间的时间戳
- formatTime, err := time.Parse(utils.FormatDate, date)
- if err != nil {
- br.Msg = "获取失败,日期格式异常"
- br.ErrMsg = "获取失败,日期格式异常"
- return
- }
- dateTime := formatTime.Unix()
- //获取今天零点的时间戳
- todayStr := time.Now().Format(utils.FormatDate)
- todayTime, _ := time.Parse(utils.FormatDate, todayStr)
- todayTimeNumber := todayTime.Unix()
- var resp response.StackCompanyListResp
- //历史统计数据
- if dateTime < todayTimeNumber {
- tmpResp, err := getHistoryStackCompanyList(sysUser, currentIndex, pageSize, isConfirm, companyAscribeId, adminId, regionType, companyType, dataType, tryOutType, date, keyword)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- resp = tmpResp
- } else {
- //获取实时统计数据(今天数据)
- tmpResp, err := getTodayStackCompanyListV2(sysUser, currentIndex, pageSize, isConfirm, companyAscribeId, adminId, regionType, companyType, dataType, tryOutType, keyword)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- resp = tmpResp
- }
- //导出excel
- if isExport {
- StackCompanyListExport(this, dataType, resp, br)
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // StackCompanyListExport 获取存量客户数据报表导出
- func StackCompanyListExport(this *StatisticReportController, dataType string, resp response.StackCompanyListResp, br *models.BaseResponse) {
- dir, err := os.Executable()
- exPath := filepath.Dir(dir)
- downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- xlsxFile := xlsx.NewFile()
- if err != nil {
- br.Msg = "生成文件失败"
- br.ErrMsg = "生成文件失败"
- return
- }
- style := xlsx.NewStyle()
- alignment := xlsx.Alignment{
- Horizontal: "center",
- Vertical: "center",
- WrapText: true,
- }
- style.Alignment = alignment
- style.ApplyAlignment = true
- sheel, err := xlsxFile.AddSheet("存量客户数据")
- if err != nil {
- br.Msg = "新增Sheet失败"
- br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
- return
- }
- sheel.SetColWidth(0, 0, 30)
- sheel.SetColWidth(1, 1, 15)
- sheel.SetColWidth(2, 2, 15)
- sheel.SetColWidth(3, 3, 18)
- //统计数据
- statisticRow := sheel.AddRow()
- cell1 := statisticRow.AddCell()
- cell1.SetStyle(style)
- cell1.SetValue(fmt.Sprint("新签客户数:", resp.NewCompanyTotal))
- cell2 := statisticRow.AddCell()
- cell2.SetStyle(style)
- cell2.SetValue(fmt.Sprint("续约客户数:", resp.RenewalCompanyTotal))
- cell3 := statisticRow.AddCell()
- cell3.SetStyle(style)
- cell3.SetValue(fmt.Sprint("未续约客户数:", resp.NotRenewalCompanyTotal))
- //表头
- titleRow := sheel.AddRow()
- cellName := titleRow.AddCell()
- cellName.SetStyle(style)
- cellName.SetValue("客户名称")
- cellProName := titleRow.AddCell()
- cellProName.SetStyle(style)
- cellProName.SetValue("客户类型")
- cellSellerName := titleRow.AddCell()
- cellSellerName.SetStyle(style)
- cellSellerName.SetValue("所属销售")
- switch dataType {
- case "未续约客户":
- cellTime := titleRow.AddCell()
- cellTime.SetStyle(style)
- cellTime.SetValue("最近合同到期时间")
- cellRemark := titleRow.AddCell()
- cellRemark.SetStyle(style)
- cellRemark.SetValue("未续约说明")
- cellDay := titleRow.AddCell()
- cellDay.SetStyle(style)
- cellDay.SetValue("超出过期天数")
- cellAscribeContent := titleRow.AddCell()
- cellAscribeContent.SetStyle(style)
- cellAscribeContent.SetValue("不续约归因")
- cellContent := titleRow.AddCell()
- cellContent.SetStyle(style)
- cellContent.SetValue("详细原因")
- default:
- cellTime := titleRow.AddCell()
- cellTime.SetStyle(style)
- cellTime.SetValue("服务期限")
- cellDay := titleRow.AddCell()
- cellDay.SetStyle(style)
- cellDay.SetValue("剩余天数")
- }
- for _, v := range resp.List {
- dataRow := sheel.AddRow()
- dataRow.SetHeight(20)
- cellDataName := dataRow.AddCell()
- cellDataName.SetStyle(style)
- cellDataName.SetValue(v.CompanyName)
- cellDataProName := dataRow.AddCell()
- cellDataProName.SetStyle(style)
- cellDataProName.SetValue(v.ProductName)
- cellDataSellerName := dataRow.AddCell()
- cellDataSellerName.SetStyle(style)
- cellDataSellerName.SetValue(v.SellerName)
- cellDataTime := dataRow.AddCell()
- cellDataTime.SetStyle(style)
- switch dataType {
- case "新签客户":
- cellDataTime.SetValue(fmt.Sprint(v.StartDate, " ~ ", v.EndDate))
- case "续约客户":
- cellDataTime.SetValue(fmt.Sprint(v.StartDate, " ~ ", v.EndDate))
- case "未续约客户":
- cellDataTime.SetValue(v.EndDate)
- //未续约说明
- cellDataRemark := dataRow.AddCell()
- cellDataRemark.SetStyle(style)
- cellDataRemark.SetValue(v.RenewalReason)
- }
- cellDay := dataRow.AddCell()
- cellDay.SetStyle(style)
- cellDay.SetValue(v.ExpireDay)
- switch dataType {
- case "未续约客户":
- cellAscribeContent := dataRow.AddCell()
- cellAscribeContent.SetStyle(style)
- cellAscribeContent.SetValue(v.AscribeContent)
- cellContent := dataRow.AddCell()
- cellContent.SetStyle(style)
- cellContent.SetValue(v.Content)
- }
- }
- err = xlsxFile.Save(downLoadnFilePath)
- if err != nil {
- br.Msg = "保存文件失败"
- br.ErrMsg = "保存文件失败"
- return
- }
- randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
- downloadFileName := "存量客户数据_" + randStr + ".xlsx"
- this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
- defer func() {
- os.Remove(downLoadnFilePath)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "导出成功"
- }
- // 获取历史的数据
- func getHistoryStackCompanyList(sysUser *system.Admin, currentIndex, pageSize, isConfirm, companyAscribeId int, adminId, regionType, companyType, dataType, tryOutType, date, keyword string) (returnData response.StackCompanyListResp, err error) {
- if date == "" {
- err = errors.New("请选择日期")
- return
- }
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- //条件
- condition += ` AND date = ? `
- pars = append(pars, date)
- var conditionAscribRai string // 处理权益未续约客户检索列表SQL查询条件
- var parsAscribeRai []interface{}
- //是否确认续约 CRM 13.9
- if isConfirm != -1 {
- var conditionConfirm string
- var parsConfirm []interface{}
- companyConfirmList, e := company.GetCompanyNoRenewedAscribeList(conditionConfirm, parsConfirm, 0, 0)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetCompanyNoRenewedAscribeList" + e.Error())
- return
- }
- var companyIds []int
- if len(companyConfirmList) == 0 {
- companyIds = append(companyIds, 0) // 给一个不存在的ID
- } else {
- for _, v := range companyConfirmList {
- companyIds = append(companyIds, v.CompanyId)
- }
- }
- if isConfirm == 0 {
- conditionAscribRai += ` AND c.company_id NOT IN (` + utils.GetOrmInReplace(len(companyIds)) + `)` // 待确认
- } else {
- conditionAscribRai += ` AND c.company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `)` // 已确认
- }
- parsAscribeRai = append(parsAscribeRai, companyIds)
- }
- //归因ID CRM 13.9
- if companyAscribeId > 0 {
- var conditionAscribe string
- var parsAscribe []interface{}
- conditionAscribe = " AND company_ascribe_id = ? "
- parsAscribe = append(parsAscribe, companyAscribeId)
- companyNoRenewedAscribeList, e := company.GetCompanyNoRenewedAscribeList(conditionAscribe, parsAscribe, 0, 0)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetCompanyNoRenewedAscribeList" + e.Error())
- return
- }
- var companyIds []int
- if len(companyNoRenewedAscribeList) == 0 {
- companyIds = append(companyIds, 0) // 给一个不存在的ID
- } else {
- for _, v := range companyNoRenewedAscribeList {
- companyIds = append(companyIds, v.CompanyId)
- }
- }
- conditionAscribRai += ` AND c.company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `)`
- parsAscribeRai = append(parsAscribeRai, companyIds)
- }
- if adminId != "" {
- condition += ` AND a.seller_id in (` + adminId + `) `
- //pars = append(pars, adminId)
- } else {
- //根据当前角色来获取查询条件
- condition, pars = getQueryParams(condition, pars, sysUser, "a.")
- }
- if regionType != "" {
- condition += ` AND region_type = ? `
- pars = append(pars, regionType)
- }
- switch companyType {
- case "ficc":
- condition += ` AND a.product_id = ? `
- pars = append(pars, 1)
- case "权益":
- condition += ` AND a.product_id = ? `
- pars = append(pars, 2)
- case "":
- default:
- err = errors.New("客户类型异常")
- return
- }
- //关键字搜索
- if keyword != "" {
- condition += ` and c.company_name like "%` + keyword + `%" `
- }
- var dataTotal, newCompanyTotal, renewalCompanyTotal, notRenewalCompanyTotal int
- var notRenewalTryOut, notRenewalNotTryOut int
- //新签客户数
- {
- condition1 := condition
- pars1 := pars
- condition1 += ` AND a.type = ? `
- pars1 = append(pars, "新签客户")
- total, countErr := models.GetStackCompanyCount(condition1, pars1)
- if countErr != nil && countErr.Error() != utils.ErrNoRow() {
- err = countErr
- return
- }
- newCompanyTotal = total
- if dataType == "新签客户" {
- //列表页数据总和
- total, countErr := models.GetStackCompanyProductCount(condition1, pars1)
- if countErr != nil && countErr.Error() != utils.ErrNoRow() {
- err = countErr
- return
- }
- dataTotal = total
- }
- }
- //续约客户数
- {
- condition1 := condition
- pars1 := pars
- condition1 += ` AND a.type = ? `
- pars1 = append(pars, "续约客户")
- total, countErr := models.GetStackCompanyCount(condition1, pars1)
- if countErr != nil && countErr.Error() != utils.ErrNoRow() {
- err = countErr
- return
- }
- renewalCompanyTotal = total
- if dataType == "续约客户" {
- //列表页数据总和
- total, countErr := models.GetStackCompanyProductCount(condition1, pars1)
- if countErr != nil && countErr.Error() != utils.ErrNoRow() {
- err = countErr
- return
- }
- dataTotal = total
- }
- }
- //未续约客户数
- {
- condition1 := condition
- pars1 := pars
- condition1 += ` AND a.type = ? `
- pars1 = append(pars, "未续约客户")
- total, countErr := models.GetStackCompanyCount(condition1, pars1)
- if countErr != nil && countErr.Error() != utils.ErrNoRow() {
- err = countErr
- return
- }
- notRenewalCompanyTotal = total
- condition1 += conditionAscribRai
- pars1 = append(pars1, parsAscribeRai)
- if dataType == "未续约客户" {
- //列表页数据总和
- //统计数据
- for _, v := range []string{"试用", "非试用"} {
- totalCondition1 := condition1
- totalPars1 := pars1
- var tmpTotal int
- if v == "试用" {
- totalCondition1 += ` AND b.status = "试用" `
- tmpTotal, err = models.GetNotRenewalStackCompanyProductCount(totalCondition1, totalPars1)
- if err != nil {
- return
- }
- notRenewalTryOut = tmpTotal
- } else if v == "非试用" {
- totalCondition1 += ` AND b.status IN ("冻结","流失") `
- tmpTotal, err = models.GetNotRenewalStackCompanyProductCount(totalCondition1, totalPars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- return
- }
- notRenewalNotTryOut = tmpTotal
- }
- }
- //列表数据数量
- if tryOutType == "试用" {
- condition1 += ` AND b.status = "试用" `
- total = notRenewalTryOut
- } else if tryOutType == "非试用" {
- condition1 += ` AND b.status IN ("冻结","流失") `
- total = notRenewalNotTryOut
- }
- total, countErr := models.GetNotRenewalStackCompanyProductCount(condition1, pars1)
- if countErr != nil && countErr.Error() != utils.ErrNoRow() {
- err = countErr
- return
- }
- dataTotal = total
- }
- }
- //报表类型,新签客户`,`续约客户`,`未续约客户`
- condition += ` AND a.type = ? `
- pars = append(pars, dataType)
- orderBy := ``
- if dataType == "新签客户" || dataType == "续约客户" {
- orderBy = `start_date desc`
- }
- if tryOutType == "试用" {
- condition += ` AND b.status = "试用" `
- } else if tryOutType == "非试用" {
- condition += ` AND b.status IN ("冻结","流失") `
- }
- list, countErr := models.GetStackCompanyList(condition, orderBy, pars, startSize, pageSize)
- if countErr != nil {
- err = countErr
- return
- }
- listLen := len(list)
- //moreListMap := make(map[int][]*models.StackCompanyStatisticList)
- if dataType == "续约客户" {
- var ids []string
- var ascribecompanyIds []int
- oldCompanyMap := make(map[int]*models.IncrementalList)
- oldMoneyMap := make(map[int]float64)
- countMap := make(map[int]int)
- for _, item := range list {
- ids = append(ids, strconv.Itoa(item.CompanyId))
- ascribecompanyIds = append(ascribecompanyIds, item.CompanyId)
- }
- //归因标签
- mapGetCompanyAscribeContent, mapContent := services.GetCompanyAscribeContentMap(ascribecompanyIds)
- mapNoRenewedNote := services.GetCompanyNoRenewedNoteMap(ascribecompanyIds)
- if len(ids) > 0 {
- idStr := strings.Join(ids, ",")
- lists, contractErr := models.GetLastContractMoney(idStr)
- if contractErr != nil {
- err = contractErr
- return
- }
- for _, item := range lists {
- _, countOk := countMap[item.CompanyId]
- _, ok := oldCompanyMap[item.CompanyId]
- if !ok {
- oldCompanyMap[item.CompanyId] = item
- oldMoneyMap[item.CompanyId] = item.Money
- } else if !countOk {
- countMap[item.CompanyId] = 1
- oldCompanyMap[item.CompanyId] = item
- }
- }
- //给list赋值
- for _, item := range list {
- if item.ProductName == "权益" {
- oldMoney, _ := oldMoneyMap[item.CompanyId]
- lastContract, _ := oldCompanyMap[item.CompanyId]
- if oldMoney > lastContract.Money {
- item.PackageDifference = "增加套餐"
- } else if oldMoney < lastContract.Money {
- item.PackageDifference = "减少套餐"
- } else {
- item.PackageDifference = "维持套餐"
- }
- }
- item.AscribeContent = mapGetCompanyAscribeContent[fmt.Sprint("CID_", item.CompanyId, "PID_", item.ProductId)]
- item.Content = mapContent[fmt.Sprint("CID_", item.CompanyId, "PID_", item.ProductId)]
- item.IsShowNoRenewedNote = mapNoRenewedNote[fmt.Sprint("CID_", item.CompanyId, "PID_", item.ProductId)]
- }
- }
- }
- //获取其他产品数据
- //if listLen > 0 {
- // companyIdSlice := make([]string, 0)
- // statisticIdSlice := make([]string, 0)
- // for _, v := range list {
- // if v.Count > 1 {
- // companyIdSlice = append(companyIdSlice, strconv.Itoa(v.CompanyId))
- // statisticIdSlice = append(statisticIdSlice, strconv.Itoa(v.StatisticId))
- // }
- // }
- // if len(companyIdSlice) > 0 {
- // companyIds := strings.Join(companyIdSlice, ",")
- // statisticIds := strings.Join(statisticIdSlice, ",")
- // stackCompanyList2, list2Err := models.GetStackCompanyListByCompanyIds(companyIds, statisticIds, condition, pars)
- // //companyType
- // if list2Err != nil {
- // err = errors.New("获取其他产品失败,Err:" + list2Err.Error())
- // return
- // }
- //
- // for _, stackCompany := range stackCompanyList2 {
- // moreListMap[stackCompany.CompanyId] = append(moreListMap[stackCompany.CompanyId], stackCompany)
- // }
- // }
- //}
- for i := 0; i < listLen; i++ {
- item := list[i]
- //剩余可用天数
- endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
- endDateTime = endDateTime.AddDate(0, 0, 1)
- sub := endDateTime.Sub(time.Now())
- //if sub < 0 {
- // sub = 0
- //}
- expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
- list[i].ExpireDay = expireDay
- //其他产品数据处理
- //if otherCompanyProductList, ok := moreListMap[item.CompanyId]; ok {
- // for _, otherCompanyProduct := range otherCompanyProductList {
- // list[i].ProductName += "/" + otherCompanyProduct.ProductName
- // list[i].SellerName += "/" + otherCompanyProduct.SellerName
- // list[i].StartDate += "/" + otherCompanyProduct.StartDate
- // list[i].EndDate += "/" + otherCompanyProduct.EndDate
- //
- // endDateTime, _ := time.Parse(utils.FormatDate, otherCompanyProduct.EndDate)
- // endDateTime = endDateTime.AddDate(0, 0, 1)
- // sub := endDateTime.Sub(time.Now())
- // //if sub < 0 {
- // // sub = 0
- // //}
- // tmpExpireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
- // list[i].ExpireDay += "/" + tmpExpireDay
- // }
- //}
- }
- page := paging.GetPaging(currentIndex, pageSize, dataTotal)
- resp := response.StackCompanyListResp{
- Paging: page,
- List: list,
- NewCompanyTotal: newCompanyTotal,
- RenewalCompanyTotal: renewalCompanyTotal,
- NotRenewalCompanyTotal: notRenewalCompanyTotal,
- NotRenewalTryOut: notRenewalTryOut,
- NotRenewalNotTryOut: notRenewalNotTryOut,
- }
- return resp, err
- }
- // 获取今日的数据
- func getTodayStackCompanyList(sysUser *system.Admin, currentIndex, pageSize int, adminId, regionType, companyType, dataType string) (returnData response.StackCompanyListResp, err error) {
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- var condition, listCondition string
- var pars, listPars []interface{}
- today := utils.GetToday(utils.FormatDate)
- //条件
- if adminId != "" {
- condition += ` AND c.seller_id in (` + adminId + `) `
- //pars = append(pars, adminId)
- } else {
- //根据当前角色来获取查询条件
- condition, pars = getQueryParams(condition, pars, sysUser, "c.")
- }
- if regionType != "" {
- condition += ` AND b.region_type = ? `
- pars = append(pars, regionType)
- }
- switch companyType {
- case "ficc":
- condition += ` AND a.product_id = ? `
- pars = append(pars, 1)
- case "权益":
- condition += ` AND a.product_id = ? `
- pars = append(pars, 2)
- case "":
- default:
- err = errors.New("客户类型异常")
- return
- }
- var dataTotal, newCompanyTotal, renewalCompanyTotal, notRenewalCompanyTotal int
- //新签客户数
- {
- condition1 := condition
- pars1 := pars
- condition1 += ` AND c.status = "正式" AND a.start_date <= ? AND a.end_date >= ? `
- pars1 = append(pars1, today, today)
- condition1 += ` AND a.contract_type = ? `
- pars1 = append(pars1, "新签合同")
- total, countErr := models.GetIncrementalNewCompanyCount(condition1, pars1)
- if countErr != nil && countErr.Error() != utils.ErrNoRow() {
- err = countErr
- return
- }
- newCompanyTotal = total
- if dataType == "新签客户" {
- //页表页数据总和
- total, countErr := models.GetTodayStackCompanyProductCount(condition1, pars1)
- if countErr != nil && countErr.Error() != utils.ErrNoRow() {
- err = countErr
- return
- }
- dataTotal = total
- listCondition = condition1
- listPars = pars1
- }
- }
- //续约客户数
- {
- condition1 := condition
- pars1 := pars
- condition1 += ` AND c.status = "正式" `
- condition1 += " AND a.end_date >= ?"
- pars1 = append(pars1, today)
- condition1 += ` AND a.contract_type = ? `
- pars1 = append(pars1, "续约合同")
- total, countErr := models.GetIncrementalNewCompanyCount(condition1, pars1)
- if countErr != nil && countErr.Error() != utils.ErrNoRow() {
- err = countErr
- return
- }
- renewalCompanyTotal = total
- if dataType == "续约客户" {
- //页表页数据总和
- total, countErr := models.GetTodayStackCompanyProductCount(condition1, pars1)
- if countErr != nil && countErr.Error() != utils.ErrNoRow() {
- err = countErr
- return
- }
- dataTotal = total
- listCondition = condition1
- listPars = pars1
- }
- }
- //未续约客户数
- {
- condition1 := condition
- pars1 := pars
- condition1 += ` AND c.status not in ("永续","正式") `
- //condition1 += " AND a.end_date < ?"
- //pars1 = append(pars1, today)
- total, countErr := models.GetIncrementalNewCompanyCount(condition1, pars1)
- if countErr != nil && countErr.Error() != utils.ErrNoRow() {
- err = countErr
- return
- }
- notRenewalCompanyTotal = total
- if dataType == "未续约客户" {
- //页表页数据总和
- total, countErr := models.GetTodayStackCompanyProductCount(condition1, pars1)
- if countErr != nil && countErr.Error() != utils.ErrNoRow() {
- err = countErr
- return
- }
- dataTotal = total
- listCondition = condition1
- listPars = pars1
- }
- }
- list, countErr := models.GetTodayStackCompanyList(listCondition, listPars, startSize, pageSize)
- if countErr != nil {
- err = countErr
- return
- }
- listLen := len(list)
- //moreListMap := make(map[int][]*models.IncrementalList)
- //获取其他产品数据
- //if listLen > 0 {
- // companyIdSlice := make([]string, 0)
- // companyContractIdSlice := make([]string, 0)
- // for _, v := range list {
- // if v.Count > 1 {
- // companyIdSlice = append(companyIdSlice, strconv.Itoa(v.CompanyId))
- // companyContractIdSlice = append(companyContractIdSlice, strconv.Itoa(v.CompanyContractId))
- // }
- // }
- //if len(companyIdSlice) > 0 {
- // companyIds := strings.Join(companyIdSlice, ",")
- // companyContractIds := strings.Join(companyContractIdSlice, ",")
- // incrementalList2, list2Err := models.GetOtherIncrementalNewCompanyList(companyIds, companyContractIds, listCondition, listPars)
- // //companyType
- // if list2Err != nil {
- // err = errors.New("获取其他产品失败,Err:" + list2Err.Error())
- // return
- // }
- //
- // for _, incremental := range incrementalList2 {
- // moreListMap[incremental.CompanyId] = append(moreListMap[incremental.CompanyId], incremental)
- // }
- //}
- //}
- for i := 0; i < listLen; i++ {
- item := list[i]
- //剩余可用天数
- expireDay := "0"
- endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
- endDateTime = endDateTime.AddDate(0, 0, 1)
- var sub time.Duration
- if dataType != "未续约客户" {
- sub = endDateTime.Sub(time.Now())
- //if sub < 0 {
- // sub = 0
- //}
- } else {
- sub = time.Now().Sub(endDateTime)
- }
- expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
- list[i].ExpireDay = expireDay
- //其他产品数据拼接
- //if otherCompanyProductList, ok := moreListMap[item.CompanyId]; ok {
- // for _, otherCompanyProduct := range otherCompanyProductList {
- // list[i].ProductName += "/" + otherCompanyProduct.ProductName
- // list[i].SellerName += "/" + otherCompanyProduct.SellerName
- // list[i].StartDate += "/" + otherCompanyProduct.StartDate
- // list[i].EndDate += "/" + otherCompanyProduct.EndDate
- //
- // tmpExpireDay := "0"
- // endDateTime, _ := time.Parse(utils.FormatDate, otherCompanyProduct.EndDate)
- // endDateTime = endDateTime.AddDate(0, 0, 1)
- // var sub time.Duration
- // if dataType != "未续约客户" {
- // sub = endDateTime.Sub(time.Now())
- // //if sub < 0 {
- // // sub = 0
- // //}
- // } else {
- // sub = time.Now().Sub(endDateTime)
- // }
- // tmpExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
- //
- // list[i].ExpireDay += "/" + tmpExpireDay
- // }
- //}
- }
- var stackCompanyStatisticList []*models.StackCompanyStatisticList
- for _, v := range list {
- stackCompanyStatistic := models.StackCompanyStatisticList{
- Type: dataType,
- CompanyId: v.CompanyId,
- CompanyName: v.CompanyName,
- ProductId: v.ProductId,
- ProductName: v.ProductName,
- ContractNum: v.Count,
- SellerId: v.SellerId,
- SellerName: v.SellerName,
- Date: today,
- StartDate: v.StartDate,
- EndDate: v.EndDate,
- RegionType: v.RegionType,
- //CreateTime :v.CreateTime,
- CreateTimeStr: v.CreateTime,
- ExpireDay: v.ExpireDay,
- }
- stackCompanyStatisticList = append(stackCompanyStatisticList, &stackCompanyStatistic)
- }
- page := paging.GetPaging(currentIndex, pageSize, dataTotal)
- resp := response.StackCompanyListResp{
- Paging: page,
- List: stackCompanyStatisticList,
- NewCompanyTotal: newCompanyTotal,
- RenewalCompanyTotal: renewalCompanyTotal,
- NotRenewalCompanyTotal: notRenewalCompanyTotal,
- }
- return resp, err
- }
- func getTodayStackCompanyListV2(sysUser *system.Admin, currentIndex, pageSize, isConfirm, companyAscribeId int, adminId, regionType, companyType, dataType, tryOutType, keyword string) (returnData response.StackCompanyListResp, err error) {
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- var condition, listCondition string
- var pars, listPars []interface{}
- today := utils.GetToday(utils.FormatDate)
- //条件
- var conditionAscribRai string // 处理权益未续约客户检索列表SQL查询条件
- var parsAscribeRai []interface{}
- //是否确认续约 CRM 13.9
- if isConfirm != -1 {
- var conditionConfirm string
- var parsConfirm []interface{}
- companyConfirmList, e := company.GetCompanyNoRenewedAscribeList(conditionConfirm, parsConfirm, 0, 0)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetCompanyNoRenewedAscribeList" + e.Error())
- return
- }
- var companyIds []int
- if len(companyConfirmList) == 0 {
- companyIds = append(companyIds, 0) // 给一个不存在的ID
- } else {
- for _, v := range companyConfirmList {
- companyIds = append(companyIds, v.CompanyId)
- }
- }
- if isConfirm == 0 {
- conditionAscribRai += ` AND ( c.company_id NOT IN (` + utils.GetOrmInReplace(len(companyIds)) + `) AND c.product_id = 2 ) ` // 待确认
- } else {
- conditionAscribRai += ` AND ( c.company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `) OR c.product_id = 2 )` // 已确认
- }
- parsAscribeRai = append(parsAscribeRai, companyIds)
- }
- //归因ID CRM 13.9
- if companyAscribeId > 0 {
- var conditionAscribe string
- var parsAscribe []interface{}
- conditionAscribe = " AND company_ascribe_id = ? "
- parsAscribe = append(parsAscribe, companyAscribeId)
- companyNoRenewedAscribeList, e := company.GetCompanyNoRenewedAscribeList(conditionAscribe, parsAscribe, 0, 0)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetCompanyNoRenewedAscribeList" + e.Error())
- return
- }
- var companyIds []int
- if len(companyNoRenewedAscribeList) == 0 {
- companyIds = append(companyIds, 0) // 给一个不存在的ID
- } else {
- for _, v := range companyNoRenewedAscribeList {
- companyIds = append(companyIds, v.CompanyId)
- }
- }
- conditionAscribRai += ` AND c.company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `)`
- parsAscribeRai = append(parsAscribeRai, companyIds)
- }
- if adminId != "" {
- condition += ` AND c.seller_id in (` + adminId + `) `
- //pars = append(pars, adminId)
- } else {
- //根据当前角色来获取查询条件
- condition, pars = getQueryParams(condition, pars, sysUser, "c.")
- }
- if regionType != "" {
- condition += ` AND b.region_type = ? `
- pars = append(pars, regionType)
- }
- //关键字搜索
- if keyword != "" {
- condition += ` and b.company_name like "%` + keyword + `%" `
- }
- switch companyType {
- case "ficc":
- condition += ` AND a.product_id = ? `
- pars = append(pars, 1)
- case "权益":
- condition += ` AND a.product_id = ? `
- pars = append(pars, 2)
- case "":
- default:
- err = errors.New("客户类型异常")
- return
- }
- var dataTotal, newCompanyTotal, renewalCompanyTotal, notRenewalCompanyTotal int
- var notRenewalTryOut, notRenewalNotTryOut int
- var list []*models.IncrementalList
- //新签客户数
- {
- condition1 := condition
- pars1 := pars
- //condition1 += ` AND c.status = "正式" `
- condition1 += ` AND a.start_date <= ? AND a.end_date >= ? `
- pars1 = append(pars1, today, today)
- condition1 += ` AND a.contract_type = ? `
- pars1 = append(pars1, "新签合同")
- total, countErr := models.GetIncrementalNewCompanyCount(condition1, pars1)
- if countErr != nil && countErr.Error() != utils.ErrNoRow() {
- err = countErr
- return
- }
- newCompanyTotal = total
- if dataType == "新签客户" {
- //页表页数据总和
- total, countErr := models.GetTodayStackCompanyProductCount(condition1, pars1)
- if countErr != nil && countErr.Error() != utils.ErrNoRow() {
- err = countErr
- return
- }
- dataTotal = total
- listCondition = condition1
- listPars = pars1
- }
- }
- //续约客户数
- {
- condition1 := condition
- pars1 := pars
- //condition1 += ` AND c.status = "正式" `
- condition1 += ` AND a.start_date <= ? AND a.end_date >= ? `
- pars1 = append(pars1, today, today)
- condition1 += ` AND a.contract_type = ? `
- pars1 = append(pars1, "续约合同")
- //额外条件(续约合同的起始日期包含在所选时间段内且不包含在新签合同存续期内的客户)
- pars1 = append(pars1, today)
- total, countErr := models.GetIncrementalNewCompanyCountV2(condition1, pars1)
- if countErr != nil && countErr.Error() != utils.ErrNoRow() {
- err = countErr
- return
- }
- renewalCompanyTotal = total
- if dataType == "续约客户" {
- //页表页数据总和
- total, countErr := models.GetTodayStackCompanyProductCountV2(condition1, pars1)
- if countErr != nil && countErr.Error() != utils.ErrNoRow() {
- err = countErr
- return
- }
- dataTotal = total
- listCondition = condition1
- listPars = pars1
- }
- }
- //未续约客户数
- {
- condition1 := condition
- pars1 := pars
- condition1 += ` AND c.status not in ("永续","正式") AND a.create_time <= ? `
- pars1 = append(pars1, time.Now().Format(utils.FormatDateTime))
- condition1 += ` AND a.operation = 'try_out' `
- total, countErr := models.GetIncrementalCompanyCountByOperationRecord(condition1, pars1)
- if countErr != nil && countErr.Error() != utils.ErrNoRow() {
- err = countErr
- return
- }
- notRenewalCompanyTotal = total
- condition1 += conditionAscribRai
- pars1 = append(pars1, parsAscribeRai)
- if dataType == "未续约客户" {
- //页表页数据总和
- //统计数据
- for _, v := range []string{"试用", "非试用"} {
- totalCondition1 := condition1
- totalPars1 := pars1
- var tmpTotal int
- if v == "试用" {
- totalCondition1 += ` AND c.status = "试用" `
- tmpTotal, err = models.GetIncrementalCompanyProductCountByOperationRecord(totalCondition1, totalPars1)
- if err != nil {
- return
- }
- notRenewalTryOut = tmpTotal
- } else if v == "非试用" {
- totalCondition1 += ` AND c.status IN ("冻结","流失") `
- tmpTotal, err = models.GetIncrementalCompanyProductCountByOperationRecord(totalCondition1, totalPars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- return
- }
- notRenewalNotTryOut = tmpTotal
- }
- }
- //列表数据数量
- if tryOutType == "试用" {
- condition1 += ` AND c.status = "试用" `
- total = notRenewalTryOut
- } else if tryOutType == "非试用" {
- condition1 += ` AND c.status IN ("冻结","流失") `
- total = notRenewalNotTryOut
- }
- //total, countErr := models.GetIncrementalCompanyProductCountByOperationRecord(condition1, pars1)
- //if countErr != nil && countErr.Error() != utils.ErrNoRow() {
- // err = countErr
- // return
- //}
- dataTotal = total
- listCondition = condition1
- listPars = pars1
- if tryOutType == "试用" {
- listCondition += ` AND c.status = "试用" `
- } else if tryOutType == "非试用" {
- listCondition += ` AND c.status IN ("冻结","流失") `
- }
- tmpList, countErr := models.GetIncrementalCompanyListByOperationRecord(listCondition, listPars, startSize, pageSize)
- if countErr != nil {
- err = countErr
- return
- }
- for i := 0; i < len(tmpList); i++ {
- endDateTime, parseErr := time.Parse(utils.FormatDateTime, tmpList[i].CreateTime)
- if parseErr != nil {
- err = parseErr
- return
- }
- tmpList[i].EndDate = endDateTime.Format(utils.FormatDate)
- }
- list = tmpList
- }
- }
- switch dataType {
- case "新签客户":
- tmpList, countErr := models.GetTodayStackCompanyList(listCondition, listPars, startSize, pageSize)
- if countErr != nil {
- err = countErr
- return
- }
- list = tmpList
- case "续约客户":
- tmpList, countErr := models.GetTodayStackCompanyListV2(listCondition, listPars, startSize, pageSize)
- if countErr != nil {
- err = countErr
- return
- }
- list = tmpList
- }
- if dataType == "续约客户" {
- var ids []string
- oldCompanyMap := make(map[int]*models.IncrementalList)
- oldMoneyMap := make(map[int]float64)
- countMap := make(map[int]int)
- for _, item := range list {
- ids = append(ids, strconv.Itoa(item.CompanyId))
- }
- if len(ids) > 0 {
- idStr := strings.Join(ids, ",")
- lists, contractErr := models.GetLastContractMoney(idStr)
- if contractErr != nil {
- err = contractErr
- return
- }
- for _, item := range lists {
- _, countOk := countMap[item.CompanyId]
- _, ok := oldCompanyMap[item.CompanyId]
- if !ok {
- oldCompanyMap[item.CompanyId] = item
- oldMoneyMap[item.CompanyId] = item.Money
- } else if !countOk {
- countMap[item.CompanyId] = 1
- oldCompanyMap[item.CompanyId] = item
- }
- }
- //给list赋值
- for _, item := range list {
- if item.ProductName == "权益" {
- oldMoney, _ := oldMoneyMap[item.CompanyId]
- lastContract, _ := oldCompanyMap[item.CompanyId]
- if oldMoney > lastContract.Money {
- item.PackageDifference = "增加套餐"
- } else if oldMoney < lastContract.Money {
- item.PackageDifference = "减少套餐"
- } else {
- item.PackageDifference = "维持套餐"
- }
- }
- }
- }
- }
- var ascribecompanyIds []int
- for _, item := range list {
- ascribecompanyIds = append(ascribecompanyIds, item.CompanyId)
- }
- //归因标签
- mapGetCompanyAscribeContent, mapContent := services.GetCompanyAscribeContentMap(ascribecompanyIds)
- mapNoRenewedNote := services.GetCompanyNoRenewedNoteMap(ascribecompanyIds)
- for _, item := range list {
- item.AscribeContent = mapGetCompanyAscribeContent[fmt.Sprint("CID_", item.CompanyId, "PID_", item.ProductId)]
- item.Content = mapContent[fmt.Sprint("CID_", item.CompanyId, "PID_", item.ProductId)]
- item.IsShowNoRenewedNote = mapNoRenewedNote[fmt.Sprint("CID_", item.CompanyId, "PID_", item.ProductId)]
- }
- listLen := len(list)
- for i := 0; i < listLen; i++ {
- item := list[i]
- //剩余可用天数
- expireDay := "0"
- endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
- var sub time.Duration
- if dataType != "未续约客户" {
- endDateTime = endDateTime.AddDate(0, 0, 1)
- sub = endDateTime.Sub(time.Now())
- //if sub < 0 {
- // sub = 0
- //}
- } else {
- sub = time.Now().Sub(endDateTime)
- }
- expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
- list[i].ExpireDay = expireDay
- }
- var stackCompanyStatisticList []*models.StackCompanyStatisticList
- for _, v := range list {
- stackCompanyStatistic := models.StackCompanyStatisticList{
- Type: dataType,
- CompanyId: v.CompanyId,
- CompanyName: v.CompanyName,
- ProductId: v.ProductId,
- ProductName: v.ProductName,
- ContractNum: v.Count,
- SellerId: v.SellerId,
- SellerName: v.SellerName,
- Date: today,
- StartDate: v.StartDate,
- EndDate: v.EndDate,
- RegionType: v.RegionType,
- //CreateTime :v.CreateTime,
- CreateTimeStr: v.CreateTime,
- ExpireDay: v.ExpireDay,
- RenewalReason: v.RenewalReason,
- RenewalTodo: v.RenewalTodo,
- Status: v.Status,
- PackageDifference: v.PackageDifference,
- AscribeContent: v.AscribeContent,
- IsShowNoRenewedNote: v.IsShowNoRenewedNote,
- Content: v.Content,
- }
- stackCompanyStatisticList = append(stackCompanyStatisticList, &stackCompanyStatistic)
- }
- page := paging.GetPaging(currentIndex, pageSize, dataTotal)
- resp := response.StackCompanyListResp{
- Paging: page,
- List: stackCompanyStatisticList,
- NewCompanyTotal: newCompanyTotal,
- RenewalCompanyTotal: renewalCompanyTotal,
- NotRenewalCompanyTotal: notRenewalCompanyTotal,
- NotRenewalTryOut: notRenewalTryOut,
- NotRenewalNotTryOut: notRenewalNotTryOut,
- }
- return resp, err
- }
- // IncrementalCompanyList
- // @Title 获取增量客户数据列表
- // @Description 获取增量客户数据列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param Keyword query string true "客户名称"
- // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
- // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
- // @Param RegionType query string false "所属区域:传空字符串或者不传为全部,'国内','海外'"
- // @Param StartDate query string false "开始日期"
- // @Param EndDate query string false "结束日期"
- // @Param DataType query string false "报表类型,枚举值:`新增试用`,`新签客户`,`续约客户`,`未续约客户`"
- // @Param TryOutType query string false " '试用', '非试用' 非试用即为冻结/流失"
- // @Param IsExport query bool false "是否导出excel,默认是false"
- // @Param IsConfirm query int false "是否确认续约: -1-默认全部; 0-待确认; 1-已确认"
- // @Param CompanyAscribeId query int false "归因ID"
- // @Success 200 {object} response.IncrementalCompanyListResp
- // @router /incremental_company_list [get]
- func (this *StatisticReportController) IncrementalCompanyList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- adminId := this.GetString("AdminId")
- regionType := this.GetString("RegionType")
- companyType := this.GetString("CompanyType")
- dataType := this.GetString("DataType")
- tryOutType := this.GetString("TryOutType")
- keyword := this.GetString("Keyword")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- isConfirm, _ := this.GetInt("IsConfirm", -1) // CRM 13.9
- companyAscribeId, _ := this.GetInt("CompanyAscribeId", -1) // CRM 13.9
- //if startDate == "" || endDate == "" {
- // br.Msg = "获取失败,开始日期或结束日期未传"
- // br.ErrMsg = "获取失败,开始日期或结束日期未传"
- // return
- //}
- if startDate == "" {
- startDate = "2015-01-01"
- }
- if endDate == "" {
- endDate = time.Now().Format(utils.FormatDate)
- }
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- //是否导出报表
- isExport, _ := this.GetBool("IsExport")
- if isExport {
- pageSize = 10000
- currentIndex = 1
- }
- var condition string
- var pars []interface{}
- //条件
- if adminId != "" {
- condition += ` AND c.seller_id in (` + adminId + `) `
- //pars = append(pars, adminId)
- } else {
- //根据当前角色来获取查询条件
- condition, pars = getQueryParams(condition, pars, sysUser, "c.")
- }
- if regionType != "" {
- condition += ` AND b.region_type = ? `
- pars = append(pars, regionType)
- }
- //关键字搜索
- if keyword != "" {
- condition += ` and b.company_name like "%` + keyword + `%" `
- }
- var conditionAscribRai string // 处理权益未续约客户检索列表SQL查询条件
- var conditionAscribRaiTotal string // 处理权益未续约客户总量查询条件
- var parsAscribeRai []interface{}
- var parsAscribeRaiTotal []interface{} // 处理权益未续约客户总量查询条件
- var conditionConfirm string
- var parsConfirm []interface{}
- companyConfirmList, err := company.GetCompanyNoRenewedAscribeList(conditionConfirm, parsConfirm, 0, 0)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,GetCompanyNoRenewedAscribeList Err:" + err.Error()
- return
- }
- var noRenewedcompanyIds []int //已经确定未续约的公司ID
- if len(companyConfirmList) == 0 {
- noRenewedcompanyIds = append(noRenewedcompanyIds, 0) // 给一个不存在的ID
- } else {
- for _, v := range companyConfirmList {
- noRenewedcompanyIds = append(noRenewedcompanyIds, v.CompanyId)
- }
- }
- //是否确认续约 CRM 13.9
- conditionAscribRaiTotal += ` AND ( c.company_id IN (` + utils.GetOrmInReplace(len(noRenewedcompanyIds)) + `) OR c.product_id = 1 OR a.create_time < '2023-01-01' ) ` // 已确认
- parsAscribeRaiTotal = append(parsAscribeRaiTotal, noRenewedcompanyIds)
- if isConfirm != -1 {
- if isConfirm == 0 {
- conditionAscribRai += ` AND ( c.company_id NOT IN (` + utils.GetOrmInReplace(len(noRenewedcompanyIds)) + `) AND c.product_id = 2 AND a.create_time >= '2023-01-01' ) ` // 待确认
- } else {
- conditionAscribRai += ` AND ( c.company_id IN (` + utils.GetOrmInReplace(len(noRenewedcompanyIds)) + `) OR c.product_id = 1 OR a.create_time < '2023-01-01' ) ` // 已确认
- }
- parsAscribeRai = append(parsAscribeRai, noRenewedcompanyIds)
- }
- //归因ID CRM 13.9
- if companyAscribeId > 0 {
- var conditionAscribe string
- var parsAscribe []interface{}
- conditionAscribe = " AND company_ascribe_id = ? "
- parsAscribe = append(parsAscribe, companyAscribeId)
- companyNoRenewedAscribeList, err := company.GetCompanyNoRenewedAscribeList(conditionAscribe, parsAscribe, 0, 0)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,GetCompanyNoRenewedAscribeList Err:" + err.Error()
- return
- }
- var companyIds []int
- if len(companyNoRenewedAscribeList) == 0 {
- companyIds = append(companyIds, 0) // 给一个不存在的ID
- } else {
- for _, v := range companyNoRenewedAscribeList {
- companyIds = append(companyIds, v.CompanyId)
- }
- }
- conditionAscribRai += ` AND c.company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `)`
- parsAscribeRai = append(parsAscribeRai, companyIds)
- }
- switch companyType {
- case "ficc":
- condition += ` AND c.product_id = ? `
- pars = append(pars, 1)
- case "权益":
- condition += ` AND c.product_id = ? `
- pars = append(pars, 2)
- case "":
- default:
- br.Msg = "获取失败,客户类型异常"
- br.ErrMsg = "获取失败,客户类型异常"
- return
- }
- var list []*models.IncrementalList
- //moreListMap := make(map[int][]*models.IncrementalList)
- var dataTotal, trialTotal, newCompanyTotal, renewalCompanyTotal, notRenewalCompanyTotal int
- var notRenewalTryOut, notRenewalNotTryOut int
- //试用客户数
- {
- condition1 := condition
- pars1 := pars
- condition1 += ` AND a.create_time >= ? AND a.create_time <= ? AND a.operation in ("add","receive") `
- pars1 = append(pars1, startDate, endDate)
- total, err := models.GetIncrementalCompanyCountByOperationRecord(condition1, pars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- trialTotal = total
- if dataType == "新增试用" {
- //列表数据数量
- total, err := models.GetIncrementalCompanyProductCountByOperationRecord(condition1, pars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- //列表页数据
- tmpList, err := models.GetIncrementalCompanyListByOperationRecord(condition1, pars1, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list = tmpList
- dataTotal = total
- }
- }
- //新签客户数
- {
- condition1 := condition
- pars1 := pars
- condition1 += ` AND a.start_date >= ? AND a.start_date <= ? `
- pars1 = append(pars1, startDate, endDate)
- condition1 += ` AND a.contract_type = ? `
- pars1 = append(pars1, "新签合同")
- total, err := models.GetIncrementalNewCompanyCount(condition1, pars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- newCompanyTotal = total
- if dataType == "新签客户" {
- //列表数据数量
- total, err := models.GetIncrementalNewCompanyProductCount(condition1, pars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- //列表页数据
- tmpList, err := models.GetIncrementalNewCompanyList(condition1, pars1, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list = tmpList
- dataTotal = total
- //获取其他产品
- //if len(list) > 0 {
- // companyIdSlice := make([]string, 0)
- // companyContractIdSlice := make([]string, 0)
- // for _, v := range list {
- // if v.Count > 1 {
- // companyIdSlice = append(companyIdSlice, strconv.Itoa(v.CompanyId))
- // companyContractIdSlice = append(companyContractIdSlice, strconv.Itoa(v.CompanyContractId))
- // }
- // }
- // if len(companyIdSlice) > 0 {
- // companyIds := strings.Join(companyIdSlice, ",")
- // companyContractIds := strings.Join(companyContractIdSlice, ",")
- // otherList, otherListErr := models.GetOtherIncrementalNewCompanyList(companyIds, companyContractIds, condition1, pars1)
- // //companyType
- // if otherListErr != nil {
- // br.Msg = "获取其他产品失败"
- // br.ErrMsg = "获取其他产品失败,Err:" + otherListErr.Error()
- // return
- // }
- //
- // for _, otherCompanyContract := range otherList {
- // moreListMap[otherCompanyContract.CompanyId] = append(moreListMap[otherCompanyContract.CompanyId], otherCompanyContract)
- // }
- // }
- //}
- }
- }
- //续约客户数
- {
- condition1 := condition
- pars1 := pars
- condition1 += ` AND a.start_date >= ? AND a.start_date <= ? `
- pars1 = append(pars1, startDate, endDate)
- condition1 += ` AND a.contract_type = ? `
- pars1 = append(pars1, "续约合同")
- //额外条件(续约合同的起始日期包含在所选时间段内且不包含在新签合同存续期内的客户)
- pars1 = append(pars1, endDate)
- total, err := models.GetIncrementalNewCompanyCountV2(condition1, pars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- renewalCompanyTotal = total
- if dataType == "续约客户" {
- //列表数据数量
- total, err := models.GetIncrementalNewCompanyProductCountV2(condition1, pars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- //列表页数据
- tmpList, err := models.GetIncrementalNewCompanyListV2(condition1, pars1, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list = tmpList
- dataTotal = total
- var ids []string
- companyMap := make(map[int]*models.IncrementalList)
- oldCompanyMap := make(map[int]*models.IncrementalList)
- countMap := make(map[int]int)
- for _, item := range tmpList {
- ids = append(ids, strconv.Itoa(item.CompanyId))
- companyMap[item.CompanyId] = item
- }
- if len(ids) > 0 {
- idStr := strings.Join(ids, ",")
- lists, err := models.GetLastContractMoney(idStr)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- for _, item := range lists {
- _, countOk := countMap[item.CompanyId]
- _, ok := oldCompanyMap[item.CompanyId]
- if !ok {
- oldCompanyMap[item.CompanyId] = item
- } else if !countOk {
- countMap[item.CompanyId] = 1
- oldCompanyMap[item.CompanyId] = item
- }
- }
- //给list赋值
- for _, item := range list {
- if item.ProductName == "权益" {
- lastContract, _ := oldCompanyMap[item.CompanyId]
- if item.Money > lastContract.Money {
- item.PackageDifference = "增加套餐"
- } else if item.Money < lastContract.Money {
- item.PackageDifference = "减少套餐"
- } else {
- item.PackageDifference = "维持套餐"
- }
- }
- }
- }
- //获取其他产品
- //if len(list) > 0 {
- // companyIdSlice := make([]string, 0)
- // companyContractIdSlice := make([]string, 0)
- // for _, v := range list {
- // if v.Count > 1 {
- // companyIdSlice = append(companyIdSlice, strconv.Itoa(v.CompanyId))
- // companyContractIdSlice = append(companyContractIdSlice, strconv.Itoa(v.CompanyContractId))
- // }
- // }
- // if len(companyIdSlice) > 0 {
- // companyIds := strings.Join(companyIdSlice, ",")
- // companyContractIds := strings.Join(companyContractIdSlice, ",")
- // otherList, otherListErr := models.GetOtherIncrementalNewCompanyList(companyIds, companyContractIds, condition1, pars1)
- // //companyType
- // if otherListErr != nil {
- // br.Msg = "获取其他产品失败"
- // br.ErrMsg = "获取其他产品失败,Err:" + otherListErr.Error()
- // return
- // }
- //
- // for _, otherCompanyContract := range otherList {
- // moreListMap[otherCompanyContract.CompanyId] = append(moreListMap[otherCompanyContract.CompanyId], otherCompanyContract)
- // }
- // }
- //}
- }
- }
- //未续约客户数
- {
- condition1 := condition
- pars1 := pars
- endDateTime, err := time.Parse(utils.FormatDate, endDate)
- if err != nil {
- br.Msg = "结束时间异常"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- //选择的日期加一天的原因是因为:筛选条件是截止到时分秒的,如果要把选择的这一天也统计进去,那么需要在选择的结束日期基础上加上一天
- tryOutEndDate := endDateTime.AddDate(0, 0, 1).Format(utils.FormatDate)
- condition1 += ` AND a.create_time >= ? AND a.create_time < ? `
- pars1 = append(pars1, startDate, tryOutEndDate)
- condition1 += ` AND a.operation = ? `
- pars1 = append(pars1, "try_out")
- condition1 += ` AND c.status not in ("永续","正式","关闭") `
- //未续约这里只统计已经确定的
- notRenewalCondition := condition1
- notRenewalPars := pars1
- notRenewalCondition += conditionAscribRaiTotal
- notRenewalPars = append(notRenewalPars, parsAscribeRaiTotal)
- total, err := models.GetIncrementalCompanyProductCountByOperationRecord(notRenewalCondition, notRenewalPars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- notRenewalCompanyTotal = total
- condition1 += conditionAscribRai
- pars1 = append(pars1, parsAscribeRai)
- if dataType == "未续约客户" {
- //统计数据
- for _, v := range []string{"试用", "非试用"} {
- totalCondition1 := condition1
- totalPars1 := pars1
- var tmpTotal int
- if v == "试用" {
- totalCondition1 += ` AND c.status = "试用" `
- tmpTotal, err = models.GetIncrementalCompanyProductCountByOperationRecord(totalCondition1, totalPars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- notRenewalTryOut = tmpTotal
- } else if v == "非试用" {
- totalCondition1 += ` AND c.status IN ("冻结","流失") `
- tmpTotal, err = models.GetIncrementalCompanyProductCountByOperationRecord(totalCondition1, totalPars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- notRenewalNotTryOut = tmpTotal
- }
- }
- //列表数据数量
- if tryOutType == "试用" {
- condition1 += ` AND c.status = "试用" `
- total = notRenewalTryOut
- } else if tryOutType == "非试用" {
- condition1 += ` AND c.status IN ("冻结","流失") `
- total = notRenewalNotTryOut
- }
- //total, err := models.GetIncrementalCompanyProductCountByOperationRecord(condition1, pars1)
- //if err != nil && err.Error() != utils.ErrNoRow() {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,Err:" + err.Error()
- // return
- //}
- //分页total单独计算
- total, err = models.GetIncrementalCompanyProductCountByOperationRecord(condition1, pars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- //列表页数据
- tmpList, err := models.GetIncrementalCompanyListByOperationRecord(condition1, pars1, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- var ascribecompanyIds []int
- for _, item := range tmpList {
- endDateTime, _ := time.Parse(utils.FormatDateTime, item.CreateTime)
- item.EndDate = endDateTime.Format(utils.FormatDate)
- ascribecompanyIds = append(ascribecompanyIds, item.CompanyId)
- }
- //归因标签
- mapGetCompanyAscribeContent, mapContent := services.GetCompanyAscribeContentMap(ascribecompanyIds)
- mapNoRenewedNote := services.GetCompanyNoRenewedNoteMap(ascribecompanyIds)
- for _, item := range tmpList {
- item.AscribeContent = mapGetCompanyAscribeContent[fmt.Sprint("CID_", item.CompanyId, "PID_", item.ProductId)]
- item.Content = mapContent[fmt.Sprint("CID_", item.CompanyId, "PID_", item.ProductId)]
- item.IsShowNoRenewedNote = mapNoRenewedNote[fmt.Sprint("CID_", item.CompanyId, "PID_", item.ProductId)]
- }
- list = tmpList
- dataTotal = total
- //获取其他产品
- //if len(list) > 0 {
- // companyIdSlice := make([]string, 0)
- // for _, v := range list {
- // if v.Count > 1 {
- // companyIdSlice = append(companyIdSlice, strconv.Itoa(v.CompanyId))
- // }
- // }
- // if len(companyIdSlice) > 0 {
- // companyIds := strings.Join(companyIdSlice, ",")
- // otherList, otherListErr := models.GetOtherIncrementalCompanyListByOperationRecord(companyIds, condition1, pars1)
- // //companyType
- // if otherListErr != nil {
- // br.Msg = "获取其他产品失败"
- // br.ErrMsg = "获取其他产品失败,Err:" + otherListErr.Error()
- // return
- // }
- //
- // for _, otherCompanyContract := range otherList {
- // moreListMap[otherCompanyContract.CompanyId] = append(moreListMap[otherCompanyContract.CompanyId], otherCompanyContract)
- // }
- // }
- //}
- }
- }
- listLen := len(list)
- if listLen == 0 {
- list = make([]*models.IncrementalList, 0)
- }
- for i := 0; i < listLen; i++ {
- item := list[i]
- //新增试用不需要计算剩余日期
- if dataType != "新增试用" {
- //剩余可用天数
- endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
- endDateTime = endDateTime.AddDate(0, 0, 1)
- sub := endDateTime.Sub(time.Now())
- expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
- list[i].ExpireDay = expireDay
- }
- //if otherCompanyProductList, ok := moreListMap[item.CompanyId]; ok {
- // for _, otherCompanyProduct := range otherCompanyProductList {
- // //只有改产品不是同一产品,且并没有拼接过,那么才去拼接
- // if item.ProductId != otherCompanyProduct.ProductId && strings.Contains(list[i].ProductName, "/") == false {
- // list[i].ProductName += "/" + otherCompanyProduct.ProductName
- // list[i].SellerName += "/" + otherCompanyProduct.SellerName
- // list[i].StartDate += "/" + otherCompanyProduct.StartDate
- // list[i].EndDate += "/" + otherCompanyProduct.EndDate
- //
- // endDateTime, _ := time.Parse(utils.FormatDate, otherCompanyProduct.EndDate)
- // endDateTime = endDateTime.AddDate(0, 0, 1)
- // sub := endDateTime.Sub(time.Now())
- // //if sub < 0 {
- // // sub = 0
- // //}
- // tmpExpireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
- // list[i].ExpireDay += "/" + tmpExpireDay
- // }
- // }
- //}
- //if company2
- }
- page := paging.GetPaging(currentIndex, pageSize, dataTotal)
- resp := response.IncrementalCompanyListResp{
- Paging: page,
- List: list,
- TrialTotal: trialTotal,
- NewCompanyTotal: newCompanyTotal,
- RenewalCompanyTotal: renewalCompanyTotal,
- NotRenewalCompanyTotal: notRenewalCompanyTotal,
- NotRenewalTryOut: notRenewalTryOut,
- NotRenewalNotTryOut: notRenewalNotTryOut,
- }
- //导出excel
- if isExport {
- IncrementalCompanyListExport(this, dataType, resp, br)
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // IncrementalCompanyListExport 导出增量客户数据报表excel
- func IncrementalCompanyListExport(this *StatisticReportController, dataType string, resp response.IncrementalCompanyListResp, br *models.BaseResponse) {
- dir, err := os.Executable()
- exPath := filepath.Dir(dir)
- downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- xlsxFile := xlsx.NewFile()
- if err != nil {
- br.Msg = "生成文件失败"
- br.ErrMsg = "生成文件失败"
- return
- }
- style := xlsx.NewStyle()
- alignment := xlsx.Alignment{
- Horizontal: "center",
- Vertical: "center",
- WrapText: true,
- }
- style.Alignment = alignment
- style.ApplyAlignment = true
- sheel, err := xlsxFile.AddSheet("增量客户数据")
- if err != nil {
- br.Msg = "新增Sheet失败"
- br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
- return
- }
- sheel.SetColWidth(0, 0, 30)
- sheel.SetColWidth(1, 1, 15)
- sheel.SetColWidth(2, 2, 15)
- sheel.SetColWidth(3, 3, 18)
- sheel.SetColWidth(4, 4, 40)
- sheel.SetColWidth(5, 5, 18)
- //统计数据
- statisticRow := sheel.AddRow()
- cell1 := statisticRow.AddCell()
- cell1.SetStyle(style)
- cell1.SetValue(fmt.Sprint("新增试用客户数:", resp.TrialTotal))
- cell2 := statisticRow.AddCell()
- cell2.SetStyle(style)
- cell2.SetValue(fmt.Sprint("新签客户数:", resp.NewCompanyTotal))
- cell3 := statisticRow.AddCell()
- cell3.SetStyle(style)
- cell3.SetValue(fmt.Sprint("续约客户数:", resp.RenewalCompanyTotal))
- cell4 := statisticRow.AddCell()
- cell4.SetStyle(style)
- cell4.SetValue(fmt.Sprint("未续约客户数:", resp.NotRenewalCompanyTotal))
- //表头
- titleRow := sheel.AddRow()
- cellName := titleRow.AddCell()
- cellName.SetStyle(style)
- cellName.SetValue("客户名称")
- cellProName := titleRow.AddCell()
- cellProName.SetStyle(style)
- cellProName.SetValue("客户类型")
- cellSellerName := titleRow.AddCell()
- cellSellerName.SetStyle(style)
- cellSellerName.SetValue("所属销售")
- permissionMap := make(map[int][]string)
- tmpPermissionMap := make(map[int]map[string][]string)
- companyContractIdList := make([]string, 0)
- for _, v := range resp.List {
- companyContractIdList = append(companyContractIdList, fmt.Sprint(v.CompanyContractId))
- }
- if dataType == "新签客户" || dataType == "续约客户" {
- cellMoney := titleRow.AddCell()
- cellMoney.SetStyle(style)
- cellMoney.SetValue("合同金额")
- cellPermission := titleRow.AddCell()
- cellPermission.SetStyle(style)
- cellPermission.SetValue("合同品种")
- //这么大费周章的目的是为了:权益的品种存在主观、客观的区分,如果一个品种既存在主观,又存在客观,那么就展示品种名称,否则就要列出品种名称+主、客观类型
- if len(companyContractIdList) > 0 {
- list, tmpErr := company.GetCompanyContractPermissionListByContractIds(strings.Join(companyContractIdList, ","))
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range list {
- tmpPermissionNameMap, ok := tmpPermissionMap[v.CompanyContractId]
- if ok {
- tmpPermissionNameList, ok2 := tmpPermissionNameMap[v.ChartPermissionName]
- if ok2 {
- tmpPermissionNameList = append(tmpPermissionNameList, v.PermissionRemark)
- } else {
- tmpPermissionNameList = []string{v.PermissionRemark}
- }
- tmpPermissionNameMap[v.ChartPermissionName] = tmpPermissionNameList
- } else {
- tmpPermissionNameMap = make(map[string][]string)
- tmpPermissionNameMap[v.ChartPermissionName] = []string{v.PermissionRemark}
- }
- tmpPermissionMap[v.CompanyContractId] = tmpPermissionNameMap
- }
- }
- }
- for companyContractId, tmpPermissionNameMap := range tmpPermissionMap {
- tmpPermissionName := ``
- tmpPermissionList := []string{}
- for tmpChartPermissionName, tmpChartPermissionNameList := range tmpPermissionNameMap {
- if len(tmpChartPermissionNameList) > 1 {
- tmpPermissionName = tmpChartPermissionName
- } else {
- tmpPermissionName = tmpChartPermissionNameList[0]
- }
- tmpPermissionList = append(tmpPermissionList, tmpPermissionName)
- }
- permissionMap[companyContractId] = tmpPermissionList
- }
- cellTime := titleRow.AddCell()
- cellTime.SetStyle(style)
- switch dataType {
- case "新增试用":
- cellTime.SetValue("新增时间")
- case "新签客户":
- cellTime.SetValue("签约时间")
- case "续约客户":
- cellTime.SetValue("续约时间")
- case "未续约客户":
- cellTime.SetValue("最近合同到期时间")
- cellAscribeContent := titleRow.AddCell()
- cellAscribeContent.SetStyle(style)
- cellAscribeContent.SetValue("不续约归因")
- cellContent := titleRow.AddCell()
- cellContent.SetStyle(style)
- cellContent.SetValue("详细原因")
- }
- for _, v := range resp.List {
- dataRow := sheel.AddRow()
- dataRow.SetHeight(20)
- cellDataName := dataRow.AddCell()
- cellDataName.SetStyle(style)
- cellDataName.SetValue(v.CompanyName)
- cellDataProName := dataRow.AddCell()
- cellDataProName.SetStyle(style)
- cellDataProName.SetValue(v.ProductName)
- cellDataSellerName := dataRow.AddCell()
- cellDataSellerName.SetStyle(style)
- cellDataSellerName.SetValue(v.SellerName)
- if dataType == "新签客户" || dataType == "续约客户" {
- cellDataMoney := dataRow.AddCell()
- cellDataMoney.SetStyle(style)
- cellDataMoney.SetValue(v.Money)
- cellDataPermission := dataRow.AddCell()
- cellDataPermission.SetStyle(style)
- if permissionStrList, ok := permissionMap[v.CompanyContractId]; ok {
- cellDataPermission.SetValue(strings.Join(permissionStrList, ","))
- }
- }
- cellDataTime := dataRow.AddCell()
- cellDataTime.SetStyle(style)
- switch dataType {
- case "新增试用":
- cellDataTime.SetValue(v.CreateTime)
- case "新签客户":
- cellDataTime.SetValue(v.StartDate)
- case "续约客户":
- cellDataTime.SetValue(v.StartDate)
- case "未续约客户":
- cellDataTime.SetValue(v.EndDate)
- cellAscribeContent := dataRow.AddCell()
- cellAscribeContent.SetStyle(style)
- cellAscribeContent.SetValue(v.AscribeContent)
- cellContent := dataRow.AddCell()
- cellContent.SetStyle(style)
- cellContent.SetValue(v.Content)
- }
- }
- err = xlsxFile.Save(downLoadnFilePath)
- if err != nil {
- br.Msg = "保存文件失败"
- br.ErrMsg = "保存文件失败"
- return
- }
- randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
- downloadFileName := "增量客户数据_" + randStr + ".xlsx"
- this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
- defer func() {
- os.Remove(downLoadnFilePath)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "导出成功"
- }
- // IncrementalCompanyListExport
- // @Title 增量客户数据导出
- // @Description 增量客户数据导出接口
- // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
- // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
- // @Param RegionType query string false "所属区域:传空字符串或者不传为全部,'国内','海外'"
- // @Param StartDate query string false "开始日期"
- // @Param EndDate query string false "结束日期"
- // @Param DataType query string false "报表类型,枚举值:`新增试用`,`新签客户`,`续约客户`,`未续约客户`"
- // @Success 200 Ret=200 导出成功
- // @router /incremental_company/export [get]
- func (this *StatisticReportController) IncrementalCompanyListExport() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- adminId := this.GetString("AdminId")
- regionType := this.GetString("RegionType")
- companyType := this.GetString("CompanyType")
- dataType := this.GetString("DataType")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- if startDate == "" || endDate == "" {
- br.Msg = "获取失败,开始日期或结束日期未传"
- br.ErrMsg = "获取失败,开始日期或结束日期未传"
- return
- }
- var startSize int
- currentIndex := 1
- pageSize := 10000
- startSize = utils.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- //条件
- if adminId != "" {
- condition += ` AND c.seller_id in (` + adminId + `) `
- //pars = append(pars, adminId)
- } else {
- //根据当前角色来获取查询条件
- condition, pars = getQueryParams(condition, pars, sysUser, "c.")
- }
- if regionType != "" {
- condition += ` AND b.region_type = ? `
- pars = append(pars, regionType)
- }
- switch companyType {
- case "ficc":
- condition += ` AND c.product_id = ? `
- pars = append(pars, 1)
- case "权益":
- condition += ` AND c.product_id = ? `
- pars = append(pars, 2)
- case "":
- default:
- br.Msg = "获取失败,客户类型异常"
- br.ErrMsg = "获取失败,客户类型异常"
- return
- }
- var list []*models.IncrementalList
- //moreListMap := make(map[int][]*models.IncrementalList)
- var trialTotal, newCompanyTotal, renewalCompanyTotal, notRenewalCompanyTotal int
- //试用客户数
- {
- condition1 := condition
- pars1 := pars
- condition1 += ` AND a.create_time >= ? AND a.create_time <= ? AND a.operation in ("add","receive") `
- pars1 = append(pars1, startDate, endDate)
- total, err := models.GetIncrementalCompanyCountByOperationRecord(condition1, pars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- trialTotal = total
- if dataType == "新增试用" {
- //列表页数据
- tmpList, err := models.GetIncrementalCompanyListByOperationRecord(condition1, pars1, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list = tmpList
- }
- }
- //新签客户数
- {
- condition1 := condition
- pars1 := pars
- condition1 += ` AND a.start_date >= ? AND a.start_date <= ? `
- pars1 = append(pars1, startDate, endDate)
- condition1 += ` AND a.contract_type = ? `
- pars1 = append(pars1, "新签合同")
- total, err := models.GetIncrementalNewCompanyCount(condition1, pars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- newCompanyTotal = total
- if dataType == "新签客户" {
- //列表页数据
- tmpList, err := models.GetIncrementalNewCompanyList(condition1, pars1, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list = tmpList
- }
- }
- //续约客户数
- {
- condition1 := condition
- pars1 := pars
- condition1 += ` AND a.start_date >= ? AND a.start_date <= ? `
- pars1 = append(pars1, startDate, endDate)
- condition1 += ` AND a.contract_type = ? `
- pars1 = append(pars1, "续约合同")
- total, err := models.GetIncrementalNewCompanyCount(condition1, pars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- renewalCompanyTotal = total
- if dataType == "续约客户" {
- //列表页数据
- tmpList, err := models.GetIncrementalNewCompanyList(condition1, pars1, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list = tmpList
- }
- }
- //未续约客户数
- {
- condition1 := condition
- pars1 := pars
- endDateTime, err := time.Parse(utils.FormatDate, endDate)
- if err != nil {
- br.Msg = "结束时间异常"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- //选择的日期加一天的原因是因为:筛选条件是截止到时分秒的,如果要把选择的这一天也统计进去,那么需要在选择的结束日期基础上加上一天
- tryOutEndDate := endDateTime.AddDate(0, 0, 1).Format(utils.FormatDate)
- condition1 += ` AND a.create_time >= ? AND a.create_time < ? `
- pars1 = append(pars1, startDate, tryOutEndDate)
- condition1 += ` AND a.operation = ? `
- pars1 = append(pars1, "try_out")
- condition1 += ` AND c.status not in ("永续","正式") `
- total, err := models.GetIncrementalCompanyCountByOperationRecord(condition1, pars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- notRenewalCompanyTotal = total
- if dataType == "未续约客户" {
- //列表页数据
- tmpList, err := models.GetIncrementalCompanyListByOperationRecord(condition1, pars1, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- for _, item := range tmpList {
- endDateTime, _ := time.Parse(utils.FormatDateTime, item.CreateTime)
- item.EndDate = endDateTime.Format(utils.FormatDate)
- }
- list = tmpList
- }
- }
- listLen := len(list)
- for i := 0; i < listLen; i++ {
- item := list[i]
- //新增试用不需要计算剩余日期
- if dataType != "新增试用" {
- //剩余可用天数
- endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
- endDateTime = endDateTime.AddDate(0, 0, 1)
- sub := endDateTime.Sub(time.Now())
- expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
- list[i].ExpireDay = expireDay
- }
- }
- dir, err := os.Executable()
- exPath := filepath.Dir(dir)
- downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- xlsxFile := xlsx.NewFile()
- if err != nil {
- br.Msg = "生成文件失败"
- br.ErrMsg = "生成文件失败"
- return
- }
- style := xlsx.NewStyle()
- alignment := xlsx.Alignment{
- Horizontal: "center",
- Vertical: "center",
- WrapText: true,
- }
- style.Alignment = alignment
- style.ApplyAlignment = true
- sheel, err := xlsxFile.AddSheet("增量客户数据")
- if err != nil {
- br.Msg = "新增Sheet失败"
- br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
- return
- }
- sheel.SetColWidth(0, 0, 30)
- sheel.SetColWidth(1, 1, 15)
- sheel.SetColWidth(2, 2, 15)
- sheel.SetColWidth(3, 3, 18)
- //统计数据
- statisticRow := sheel.AddRow()
- cell1 := statisticRow.AddCell()
- cell1.SetStyle(style)
- cell1.SetValue(fmt.Sprint("新增试用客户数:", trialTotal))
- cell2 := statisticRow.AddCell()
- cell2.SetStyle(style)
- cell2.SetValue(fmt.Sprint("新签客户数:", newCompanyTotal))
- cell3 := statisticRow.AddCell()
- cell3.SetStyle(style)
- cell3.SetValue(fmt.Sprint("续约客户数:", renewalCompanyTotal))
- cell4 := statisticRow.AddCell()
- cell4.SetStyle(style)
- cell4.SetValue(fmt.Sprint("未续约客户数:", notRenewalCompanyTotal))
- //表头
- titleRow := sheel.AddRow()
- cellName := titleRow.AddCell()
- cellName.SetStyle(style)
- cellName.SetValue("客户名称")
- cellProName := titleRow.AddCell()
- cellProName.SetStyle(style)
- cellProName.SetValue("客户类型")
- cellSellerName := titleRow.AddCell()
- cellSellerName.SetStyle(style)
- cellSellerName.SetValue("所属销售")
- cellTime := titleRow.AddCell()
- cellTime.SetStyle(style)
- switch dataType {
- case "新增试用":
- cellTime.SetValue("新增时间")
- case "新签客户":
- cellTime.SetValue("签约时间")
- case "续约客户":
- cellTime.SetValue("续约时间")
- case "未续约客户":
- cellTime.SetValue("最近合同到期时间")
- }
- for _, v := range list {
- dataRow := sheel.AddRow()
- dataRow.SetHeight(20)
- cellDataName := dataRow.AddCell()
- cellDataName.SetStyle(style)
- cellDataName.SetValue(v.CompanyName)
- cellDataProName := dataRow.AddCell()
- cellDataProName.SetStyle(style)
- cellDataProName.SetValue(v.ProductName)
- cellDataSellerName := dataRow.AddCell()
- cellDataSellerName.SetStyle(style)
- cellDataSellerName.SetValue(v.SellerName)
- cellDataTime := dataRow.AddCell()
- cellDataTime.SetStyle(style)
- switch dataType {
- case "新增试用":
- cellDataTime.SetValue(v.CreateTime)
- case "新签客户":
- cellDataTime.SetValue(v.StartDate)
- case "续约客户":
- cellDataTime.SetValue(v.StartDate)
- case "未续约客户":
- cellDataTime.SetValue(v.EndDate)
- }
- }
- err = xlsxFile.Save(downLoadnFilePath)
- if err != nil {
- br.Msg = "保存文件失败"
- br.ErrMsg = "保存文件失败"
- return
- }
- randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
- downloadFileName := "增量客户数据_" + randStr + ".xlsx"
- this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
- defer func() {
- os.Remove(downLoadnFilePath)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "导出成功"
- }
- // MoreRenewReason 未续约说明列表
- // @Title 未续约说明列表
- // @Description 未续约说明列表
- // @Param CompanyId query string true "客户id"
- // @Param ProductId query string true "产品id"
- // @Success 200 {object} response.MoreRenewReasonResp
- // @router /more_renew_reason [get]
- func (this *StatisticReportController) MoreRenewReason() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- CompanyId := this.GetString("CompanyId")
- ProductId := this.GetString("ProductId")
- renewalReason, err := models.GetMoreRenewalReason(CompanyId, ProductId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- resp := make([]response.MoreRenewReasonResp, len(renewalReason))
- for i, reason := range renewalReason {
- createDate := reason.CreateTime.Format("2006.01.02")
- resp[i].RenewalReason = reason.RenewalReason
- resp[i].RenewalTodo = reason.RenewalTodo
- resp[i].CreateTime = createDate
- resp[i].ExpirationTimeExceeded = strconv.Itoa(reason.ExpirationTimeExceeded)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // StackCompanyReport
- // @Title 获取存量客户统计数据
- // @Description 获取存量客户统计数据接口
- // @Param ProductId query string true "产品id"
- // @Param Date query string true "日期,格式:2022-04-06"
- // @Success 200 {object} statistic_report.CompanyReportRecordResp
- // @router /report/stack_company [get]
- func (this *StatisticReportController) StackCompanyReport() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- date := this.GetString("Date")
- productId, _ := this.GetInt("ProductId", 1)
- //获取列表
- companyReportDataMapList, firstDate, err := statistic_report.GetDateData(date, productId)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- //获取销售人员分组数据
- var group []services.AdminGroup
- var groupIdRelationMap map[int]int
- var groupMap map[int][]*roadshow.Researcher
- if productId == 1 {
- group, groupIdRelationMap, err = services.GetFiccSystemGroup()
- if err != nil {
- br.Msg = "获取信息失败!"
- br.ErrMsg = "获取分组信息失败!Err:" + err.Error()
- return
- }
- researcherList, tmpErr := services.GetFiccSeller(firstDate, groupIdRelationMap)
- if tmpErr != nil {
- err = tmpErr
- }
- groupMap = make(map[int][]*roadshow.Researcher)
- for _, v := range researcherList {
- if v.RoleTypeCode == "ficc_admin" {
- findItems := groupMap[1]
- findItems = append(findItems, v)
- groupMap[1] = findItems
- } else {
- if findItems, ok := groupMap[v.GroupId]; ok {
- findItems = append(findItems, v)
- groupMap[v.GroupId] = findItems
- } else {
- findItems = append(findItems, v)
- groupMap[v.GroupId] = findItems
- }
- }
- }
- } else {
- group, groupIdRelationMap, err = services.GetRaiSystemGroup()
- if err != nil {
- br.Msg = "获取信息失败!"
- br.ErrMsg = "获取分组信息失败!Err:" + err.Error()
- return
- }
- researcherList, tmpErr := services.GetRaiSeller(groupIdRelationMap)
- if tmpErr != nil {
- err = tmpErr
- }
- groupMap = make(map[int][]*roadshow.Researcher)
- for _, v := range researcherList {
- if v.RoleTypeCode == "rai_admin" {
- findItems := groupMap[1]
- findItems = append(findItems, v)
- groupMap[1] = findItems
- } else {
- if findItems, ok := groupMap[v.GroupId]; ok {
- findItems = append(findItems, v)
- groupMap[v.GroupId] = findItems
- } else {
- findItems = append(findItems, v)
- groupMap[v.GroupId] = findItems
- }
- }
- }
- }
- //数据处理
- groupReportRecordList := make([]statistic_report.GroupReportRecord, 0)
- allCompanyReportRecordNum := make([]statistic_report.CompanyReportRecordNum, 0)
- companyReportRecordResp := statistic_report.CompanyReportRecordResp{
- List: groupReportRecordList,
- CompanyReportRecordNumList: allCompanyReportRecordNum,
- }
- startDateIndexList := make(map[int]string) //开始时间间隔map
- endDateIndexList := make(map[int]string) //结束时间间隔map
- tmpAllTryOutNumMap := make(map[int]int)
- tmpAllFormalNumMap := make(map[int]int)
- tmpAllActiveNumMap := make(map[int]int)
- tmpAllAllActiveNumMap := make(map[int]int)
- tmpAllNoIncrementalActiveNumMap := make(map[int]int)
- tmpAllTryStagePushMap := make(map[int]int)
- tmpAllTryStageFollowMap := make(map[int]int)
- tmpAllTryStageReadyMap := make(map[int]int)
- tmpAllTryStageInitMap := make(map[int]int)
- for _, v := range group {
- v.ResearcherList = groupMap[v.GroupId]
- tmpGroupAdminReportRecord := make([]statistic_report.AdminReportRecord, 0)
- tmpGroupCompanyReportRecordNumList := make([]statistic_report.CompanyReportRecordNum, 0)
- tmpGroupTryOutNumMap := make(map[int]int)
- tmpGroupFormalNumMap := make(map[int]int)
- tmpGroupActiveNumMap := make(map[int]int)
- tmpGroupAllActiveNumMap := make(map[int]int)
- tmpGroupNoIncrementalActiveNumMap := make(map[int]int)
- tmpGroupTryStagePushMap := make(map[int]int)
- tmpGroupTryStageFollowMap := make(map[int]int)
- tmpGroupTryStageReadyMap := make(map[int]int)
- tmpGroupTryStageInitMap := make(map[int]int)
- for _, researcher := range groupMap[v.GroupId] {
- //组内研究员数据
- //每个区间的数据
- tmpCompanyReportRecordNumList := make([]statistic_report.CompanyReportRecordNum, 0)
- for index, adminData := range companyReportDataMapList {
- startDateIndexList[index] = adminData.StartDate
- endDateIndexList[index] = adminData.EndDate
- var tmpTryOutNum, tmpFormalNum, tmpActiveStatus, tmpAllActiveStatus, tmpNoIncrementalActiveStatus int
- var tmpTryStagePushNum, tmpTryStageFollowNum, tmpTryStageReadyNum, tmpTryStageInitNum int
- if num, ok := adminData.TryOutMap[researcher.AdminId]; ok {
- tmpTryOutNum = num
- }
- if num, ok := adminData.FormalMap[researcher.AdminId]; ok {
- tmpFormalNum = num
- }
- if num, ok := adminData.ActiveMap[researcher.AdminId]; ok {
- tmpActiveStatus = num
- }
- if num, ok := adminData.AllActiveMap[researcher.AdminId]; ok {
- tmpAllActiveStatus = num
- }
- if num, ok := adminData.NoIncrementalActiveMap[researcher.AdminId]; ok {
- tmpNoIncrementalActiveStatus = num
- }
- // 每个用户的试用标签统计 推进-跟踪-预备-未分类
- if num, ok := adminData.TryStagePushNum[researcher.AdminId]; ok {
- tmpTryStagePushNum = num
- }
- if num, ok := adminData.TryStageFollowNum[researcher.AdminId]; ok {
- tmpTryStageFollowNum = num
- }
- if num, ok := adminData.TryStageReadyNum[researcher.AdminId]; ok {
- tmpTryStageReadyNum = num
- }
- if num, ok := adminData.TryStageInitNum[researcher.AdminId]; ok {
- tmpTryStageInitNum = num
- }
- tmpAdminRsReportRecordNum := statistic_report.CompanyReportRecordNum{
- TryOutNum: tmpTryOutNum,
- FormalNum: tmpFormalNum,
- ActiveNum: tmpActiveStatus,
- AllActiveNum: tmpAllActiveStatus,
- NoIncrementalActiveNum: tmpNoIncrementalActiveStatus,
- StartDate: adminData.StartDate,
- EndDate: adminData.EndDate,
- TryStagePushNum: tmpTryStagePushNum,
- TryStageFollowNum: tmpTryStageFollowNum,
- TryStageReadyNum: tmpTryStageReadyNum,
- TryStageInitNum: tmpTryStageInitNum,
- }
- tmpCompanyReportRecordNumList = append(tmpCompanyReportRecordNumList, tmpAdminRsReportRecordNum)
- //组内数据汇总
- tmpGroupTryOutNumMap[index] += tmpTryOutNum
- tmpGroupFormalNumMap[index] += tmpFormalNum
- tmpGroupActiveNumMap[index] += tmpActiveStatus
- tmpGroupAllActiveNumMap[index] += tmpActiveStatus
- tmpGroupNoIncrementalActiveNumMap[index] += tmpActiveStatus
- tmpGroupTryStagePushMap[index] += tmpTryStagePushNum
- tmpGroupTryStageFollowMap[index] += tmpTryStageFollowNum
- tmpGroupTryStageReadyMap[index] += tmpTryStageReadyNum
- tmpGroupTryStageInitMap[index] += tmpTryStageInitNum
- //总数据汇总
- tmpAllTryOutNumMap[index] += tmpTryOutNum
- tmpAllFormalNumMap[index] += tmpFormalNum
- tmpAllActiveNumMap[index] += tmpActiveStatus
- tmpAllAllActiveNumMap[index] += tmpAllActiveStatus
- tmpAllNoIncrementalActiveNumMap[index] += tmpNoIncrementalActiveStatus
- // 总数据试用标签数据汇总
- tmpAllTryStagePushMap[index] += tmpTryStagePushNum
- tmpAllTryStageFollowMap[index] += tmpTryStageFollowNum
- tmpAllTryStageReadyMap[index] += tmpTryStageReadyNum
- tmpAllTryStageInitMap[index] += tmpTryStageInitNum
- }
- tmpAdminReportRecord := statistic_report.AdminReportRecord{
- Name: researcher.RealName,
- AdminId: researcher.AdminId,
- CompanyReportRecordNumList: tmpCompanyReportRecordNumList,
- }
- tmpGroupAdminReportRecord = append(tmpGroupAdminReportRecord, tmpAdminReportRecord)
- }
- for i := 0; i < len(tmpGroupActiveNumMap); i++ {
- tmpGroupCompanyReportRecordNum := statistic_report.CompanyReportRecordNum{
- TryOutNum: tmpGroupTryOutNumMap[i],
- FormalNum: tmpGroupFormalNumMap[i],
- ActiveNum: tmpGroupActiveNumMap[i],
- AllActiveNum: tmpGroupAllActiveNumMap[i],
- NoIncrementalActiveNum: tmpGroupNoIncrementalActiveNumMap[i],
- StartDate: startDateIndexList[i],
- EndDate: endDateIndexList[i],
- TryStagePushNum: tmpGroupTryStagePushMap[i],
- TryStageFollowNum: tmpGroupTryStageFollowMap[i],
- TryStageReadyNum: tmpGroupTryStageReadyMap[i],
- TryStageInitNum: tmpGroupTryStageInitMap[i],
- }
- tmpGroupCompanyReportRecordNumList = append(tmpGroupCompanyReportRecordNumList, tmpGroupCompanyReportRecordNum)
- }
- groupReportRecord := statistic_report.GroupReportRecord{
- Item: tmpGroupAdminReportRecord,
- Name: v.GroupName,
- GroupId: v.GroupId,
- CompanyReportRecordNumList: tmpGroupCompanyReportRecordNumList,
- }
- groupReportRecordList = append(groupReportRecordList, groupReportRecord)
- }
- //总体汇总数据
- for i := 0; i < len(tmpAllFormalNumMap); i++ {
- tmpGroupCompanyReportRecordNum := statistic_report.CompanyReportRecordNum{
- TryOutNum: tmpAllTryOutNumMap[i],
- FormalNum: tmpAllFormalNumMap[i],
- ActiveNum: tmpAllActiveNumMap[i],
- AllActiveNum: tmpAllAllActiveNumMap[i],
- NoIncrementalActiveNum: tmpAllNoIncrementalActiveNumMap[i],
- StartDate: startDateIndexList[i],
- EndDate: endDateIndexList[i],
- TryStagePushNum: tmpAllTryStagePushMap[i],
- TryStageFollowNum: tmpAllTryStageFollowMap[i],
- TryStageReadyNum: tmpAllTryStageReadyMap[i],
- TryStageInitNum: tmpAllTryStageInitMap[i],
- }
- allCompanyReportRecordNum = append(allCompanyReportRecordNum, tmpGroupCompanyReportRecordNum)
- }
- companyReportRecordResp.CompanyReportRecordNumList = allCompanyReportRecordNum
- tmpList := groupReportRecordList
- //因为RoleTypeCode不一样,所以需要重新从数据库取数据
- adminInfo, _ := system.GetSysAdminById(sysUser.AdminId)
- adminGroupId := adminInfo.GroupId
- if tmpGroupId, ok := groupIdRelationMap[adminGroupId]; ok {
- adminGroupId = tmpGroupId
- }
- switch adminInfo.RoleTypeCode {
- case utils.ROLE_TYPE_CODE_FICC_GROUP, utils.ROLE_TYPE_CODE_FICC_TEAM:
- for index, v := range tmpList {
- //如果不是同一个分组,那么就移除该分组下的人员数据
- if v.GroupId != adminGroupId {
- tmpList[index].Item = make([]statistic_report.AdminReportRecord, 0)
- } else {
- tmpList[index], tmpList[0] = tmpList[0], tmpList[index]
- }
- }
- companyReportRecordResp.List = tmpList
- case utils.ROLE_TYPE_CODE_RAI_GROUP:
- for index, v := range tmpList {
- //如果不是同一个分组,那么就移除该分组下的人员数据
- if v.GroupId != adminGroupId {
- tmpList[index].Item = make([]statistic_report.AdminReportRecord, 0)
- } else {
- tmpList[index], tmpList[0] = tmpList[0], tmpList[index]
- }
- }
- companyReportRecordResp.List = tmpList
- case utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_ADMIN, utils.ROLE_TYPE_CODE_RAI_ADMIN:
- //管理员、超管看全部数据
- companyReportRecordResp.List = tmpList
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = companyReportRecordResp
- }
- // IncrementalCompanyReport
- // @Title 获取增量客户统计数据
- // @Description 获取增量客户统计数据接口
- // @Param DataType query string true "枚举值:week、month、time_interval"
- // @Param ProductId query int true "客户类型 ficc:1 权益:2"
- // @Param StartDate query string true "开始日期,格式:2022-04-06"
- // @Param EndDate query string true "结束日期,格式:2022-04-06"
- // @Success 200 {object} statistic_report.CompanyReportRecordResp
- // @router /report/incremental_company [get]
- func (this *StatisticReportController) IncrementalCompanyReport() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- dataType := this.GetString("DataType")
- productId, _ := this.GetInt("ProductId", 1)
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- var companyReportDataMapList []statistic_report.CompanyReportDataMap
- var err error
- var firstDate time.Time
- switch dataType {
- //获取列表
- case "week":
- nowWeekMonday := utils.GetNowWeekMonday() //本周周一
- //companyReportDataMapList, firstDate, err = statistic_report.GetWeekData()
- companyReportDataMapList, firstDate, err = statistic_report.GetWeekDataNum(nowWeekMonday, productId, 6)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- case "month":
- nowMonthFirstDay := utils.GetNowMonthFirstDay() //本月第一天
- //companyReportDataMapList, firstDate, err = statistic_report.GetMonthData()
- companyReportDataMapList, firstDate, err = statistic_report.GetMonthDataNum(nowMonthFirstDay, productId, 6)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- case "time_interval":
- if startDate == `` || endDate == `` {
- br.Msg = "开始日期或结束日期不能为空"
- br.ErrMsg = "开始日期或结束日期不能为空,Err:" + err.Error()
- return
- }
- companyReportDataMapList, firstDate, err = statistic_report.GetTimeIntervalData(productId, startDate, endDate)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- }
- //获取销售人员分组数据
- var group []services.AdminGroup
- var groupIdRelationMap map[int]int
- var groupMap map[int][]*roadshow.Researcher
- if productId == 1 {
- group, groupIdRelationMap, err = services.GetFiccSystemGroup()
- if err != nil {
- br.Msg = "获取信息失败!"
- br.ErrMsg = "获取分组信息失败!Err:" + err.Error()
- return
- }
- researcherList, tmpErr := services.GetFiccSeller(firstDate, groupIdRelationMap)
- if tmpErr != nil {
- err = tmpErr
- }
- groupMap = make(map[int][]*roadshow.Researcher)
- for _, v := range researcherList {
- if v.RoleTypeCode == "ficc_admin" {
- findItems := groupMap[1]
- findItems = append(findItems, v)
- groupMap[1] = findItems
- } else {
- if findItems, ok := groupMap[v.GroupId]; ok {
- findItems = append(findItems, v)
- groupMap[v.GroupId] = findItems
- } else {
- findItems = append(findItems, v)
- groupMap[v.GroupId] = findItems
- }
- }
- }
- } else {
- group, groupIdRelationMap, err = services.GetRaiSystemGroup()
- if err != nil {
- br.Msg = "获取信息失败!"
- br.ErrMsg = "获取分组信息失败!Err:" + err.Error()
- return
- }
- researcherList, tmpErr := services.GetRaiSeller(groupIdRelationMap)
- if tmpErr != nil {
- err = tmpErr
- }
- groupMap = make(map[int][]*roadshow.Researcher)
- for _, v := range researcherList {
- if v.RoleTypeCode == "rai_admin" {
- findItems := groupMap[1]
- findItems = append(findItems, v)
- groupMap[1] = findItems
- } else {
- if findItems, ok := groupMap[v.GroupId]; ok {
- findItems = append(findItems, v)
- groupMap[v.GroupId] = findItems
- } else {
- findItems = append(findItems, v)
- groupMap[v.GroupId] = findItems
- }
- }
- }
- }
- //数据处理
- groupReportRecordList := make([]statistic_report.GroupReportRecord, 0)
- allCompanyReportRecordNum := make([]statistic_report.CompanyReportRecordNum, 0)
- companyReportRecordResp := statistic_report.CompanyReportRecordResp{
- List: groupReportRecordList,
- CompanyReportRecordNumList: allCompanyReportRecordNum,
- }
- startDateIndexList := make(map[int]string) //开始时间间隔map
- endDateIndexList := make(map[int]string) //结束时间间隔map
- //客户数汇总
- tmpAllTryOutNumMap := make(map[int]int)
- tmpAllFormalNumMap := make(map[int]int)
- tmpAllActiveNumMap := make(map[int]int)
- tmpAllAllActiveNumMap := make(map[int]int)
- tmpAllNoIncrementalActiveNumMap := make(map[int]int)
- //id集合汇总
- tmpAllTryOutIdMap := make(map[int]string)
- tmpAllFormalIdMap := make(map[int]string)
- tmpAllActiveIdMap := make(map[int]string)
- tmpAllAllActiveIdMap := make(map[int]string)
- tmpAllNoIncrementalActiveIdMap := make(map[int]string)
- for _, v := range group {
- v.ResearcherList = groupMap[v.GroupId]
- tmpGroupAdminReportRecord := make([]statistic_report.AdminReportRecord, 0)
- tmpGroupCompanyReportRecordNumList := make([]statistic_report.CompanyReportRecordNum, 0)
- //数量统计
- tmpGroupTryOutNumMap := make(map[int]int)
- tmpGroupFormalNumMap := make(map[int]int)
- tmpGroupActiveNumMap := make(map[int]int)
- tmpGroupAllActiveNumMap := make(map[int]int)
- tmpGroupNoIncrementalActiveNumMap := make(map[int]int)
- //id集合
- tmpGroupTryOutIdSliceMap := make(map[int][]string)
- tmpGroupFormalIdSliceMap := make(map[int][]string)
- tmpGroupActiveIdSliceMap := make(map[int][]string)
- tmpGroupAllActiveIdSliceMap := make(map[int][]string)
- tmpGroupNoIncrementalActiveIdSliceMap := make(map[int][]string)
- //id集合
- tmpGroupTryOutIdMap := make(map[int]string)
- tmpGroupFormalIdMap := make(map[int]string)
- tmpGroupActiveIdMap := make(map[int]string)
- tmpGroupAllActiveIdMap := make(map[int]string)
- tmpGroupNoIncrementalActiveIdMap := make(map[int]string)
- for _, researcher := range groupMap[v.GroupId] {
- //组内研究员数据
- //每个区间的数据
- tmpCompanyReportRecordNumList := make([]statistic_report.CompanyReportRecordNum, 0)
- for index, adminData := range companyReportDataMapList {
- startDateIndexList[index] = adminData.StartDate
- endDateIndexList[index] = adminData.EndDate
- var tmpTryOutNum, tmpFormalNum, tmpActiveStatus, tmpAllActiveStatus, tmpNoIncrementalActiveStatus int
- //var tmpTryOutIds, tmpFormalIds, tmpActiveIds string
- var tmpTryOutIdSlice, tmpFormalIdSlice, tmpActiveIdSlice, tmpAllActiveIdSlice, tmpNoIncrementalActiveIdSlice []string
- var tmpTryOutId, tmpFormalId, tmpActiveId, tmpAllActiveId, tmpNoIncrementalActiveId string
- if num, ok := adminData.TryOutMap[researcher.AdminId]; ok {
- tmpTryOutNum = num
- tmpTryOutIdSlice = append(tmpTryOutIdSlice, adminData.TryOutIdMap[researcher.AdminId])
- tmpTryOutId = strings.Join(tmpTryOutIdSlice, ",")
- }
- if num, ok := adminData.FormalMap[researcher.AdminId]; ok {
- tmpFormalNum = num
- tmpFormalIdSlice = append(tmpFormalIdSlice, adminData.FormalIdMap[researcher.AdminId])
- tmpFormalId = strings.Join(tmpFormalIdSlice, ",")
- }
- if num, ok := adminData.ActiveMap[researcher.AdminId]; ok {
- tmpActiveStatus = num
- tmpActiveIdSlice = append(tmpActiveIdSlice, adminData.ActiveIdMap[researcher.AdminId])
- tmpActiveId = strings.Join(tmpActiveIdSlice, ",")
- }
- if num, ok := adminData.AllActiveMap[researcher.AdminId]; ok {
- tmpAllActiveStatus = num
- tmpAllActiveIdSlice = append(tmpAllActiveIdSlice, adminData.AllActiveIdMap[researcher.AdminId])
- tmpAllActiveId = strings.Join(tmpAllActiveIdSlice, ",")
- }
- if num, ok := adminData.NoIncrementalActiveMap[researcher.AdminId]; ok {
- tmpNoIncrementalActiveStatus = num
- tmpNoIncrementalActiveIdSlice = append(tmpNoIncrementalActiveIdSlice, adminData.NoIncrementalActiveIdMap[researcher.AdminId])
- tmpNoIncrementalActiveId = strings.Join(tmpNoIncrementalActiveIdSlice, ",")
- }
- tmpAdminRsReportRecordNum := statistic_report.CompanyReportRecordNum{
- TryOutNum: tmpTryOutNum,
- TryOutIds: tmpTryOutId,
- FormalNum: tmpFormalNum,
- FormalIds: tmpFormalId,
- ActiveNum: tmpActiveStatus,
- ActiveIds: tmpActiveId,
- AllActiveNum: tmpAllActiveStatus,
- AllActiveIds: tmpAllActiveId,
- NoIncrementalActiveNum: tmpNoIncrementalActiveStatus,
- NoIncrementalActiveIds: tmpNoIncrementalActiveId,
- StartDate: adminData.StartDate,
- EndDate: adminData.EndDate,
- }
- tmpCompanyReportRecordNumList = append(tmpCompanyReportRecordNumList, tmpAdminRsReportRecordNum)
- //组内数据汇总
- if _, ok := tmpGroupTryOutNumMap[index]; !ok {
- tmpGroupTryOutNumMap[index] = 0
- }
- if _, ok := tmpGroupFormalNumMap[index]; !ok {
- tmpGroupFormalNumMap[index] = 0
- }
- if _, ok := tmpGroupActiveNumMap[index]; !ok {
- tmpGroupActiveNumMap[index] = 0
- }
- if _, ok := tmpGroupAllActiveNumMap[index]; !ok {
- tmpGroupAllActiveNumMap[index] = 0
- }
- if _, ok := tmpGroupNoIncrementalActiveNumMap[index]; !ok {
- tmpGroupNoIncrementalActiveNumMap[index] = 0
- }
- tmpGroupTryOutNumMap[index] += tmpTryOutNum
- tmpGroupFormalNumMap[index] += tmpFormalNum
- tmpGroupActiveNumMap[index] += tmpActiveStatus
- tmpGroupAllActiveNumMap[index] += tmpAllActiveStatus
- tmpGroupNoIncrementalActiveNumMap[index] += tmpNoIncrementalActiveStatus
- //组内数据汇总
- if _, ok := tmpGroupTryOutIdMap[index]; !ok {
- tmpGroupTryOutIdMap[index] = ""
- }
- if _, ok := tmpGroupFormalIdMap[index]; !ok {
- tmpGroupFormalIdMap[index] = ""
- }
- if _, ok := tmpGroupActiveIdMap[index]; !ok {
- tmpGroupActiveIdMap[index] = ""
- }
- if tmpTryOutId != "" {
- tmpGroupTryOutIdSliceMap[index] = append(tmpGroupTryOutIdSliceMap[index], tmpTryOutId)
- }
- if tmpFormalId != "" {
- tmpGroupFormalIdSliceMap[index] = append(tmpGroupFormalIdSliceMap[index], tmpFormalId)
- }
- if tmpActiveId != "" {
- tmpGroupActiveIdSliceMap[index] = append(tmpGroupActiveIdSliceMap[index], tmpActiveId)
- }
- if tmpAllActiveId != "" {
- tmpGroupAllActiveIdSliceMap[index] = append(tmpGroupAllActiveIdSliceMap[index], tmpAllActiveId)
- }
- if tmpNoIncrementalActiveId != "" {
- tmpGroupNoIncrementalActiveIdSliceMap[index] = append(tmpGroupNoIncrementalActiveIdSliceMap[index], tmpNoIncrementalActiveId)
- }
- //总数据汇总
- if _, ok := tmpAllTryOutNumMap[index]; !ok {
- tmpAllTryOutNumMap[index] = 0
- }
- if _, ok := tmpAllFormalNumMap[index]; !ok {
- tmpAllFormalNumMap[index] = 0
- }
- if _, ok := tmpAllActiveNumMap[index]; !ok {
- tmpAllActiveNumMap[index] = 0
- }
- if _, ok := tmpAllAllActiveNumMap[index]; !ok {
- tmpAllAllActiveNumMap[index] = 0
- }
- if _, ok := tmpAllNoIncrementalActiveNumMap[index]; !ok {
- tmpAllNoIncrementalActiveNumMap[index] = 0
- }
- tmpAllTryOutNumMap[index] += tmpTryOutNum
- tmpAllFormalNumMap[index] += tmpFormalNum
- tmpAllActiveNumMap[index] += tmpActiveStatus
- tmpAllAllActiveNumMap[index] += tmpAllActiveStatus
- tmpAllNoIncrementalActiveNumMap[index] += tmpNoIncrementalActiveStatus
- ////总数据汇总
- //if _, ok := tmpAllTryOutIdMap[index]; !ok {
- // tmpAllTryOutIdMap[index] = ""
- //}
- //if _, ok := tmpAllFormalIdMap[index]; !ok {
- // tmpAllFormalIdMap[index] = ""
- //}
- //if _, ok := tmpAllActiveIdMap[index]; !ok {
- // tmpAllActiveIdMap[index] = ""
- //}
- //tmpAllTryOutIdMap[index] += tmpTryOutId
- //tmpAllFormalIdMap[index] += tmpFormalId
- //tmpAllActiveIdMap[index] += tmpActiveId
- }
- tmpAdminReportRecord := statistic_report.AdminReportRecord{
- Name: researcher.RealName,
- AdminId: researcher.AdminId,
- CompanyReportRecordNumList: tmpCompanyReportRecordNumList,
- }
- tmpGroupAdminReportRecord = append(tmpGroupAdminReportRecord, tmpAdminReportRecord)
- }
- for i := 0; i < len(tmpGroupActiveNumMap); i++ {
- tmpGroupTryOutIdMap[i] = strings.Join(tmpGroupTryOutIdSliceMap[i], ",")
- tmpGroupFormalIdMap[i] = strings.Join(tmpGroupFormalIdSliceMap[i], ",")
- tmpGroupActiveIdMap[i] = strings.Join(tmpGroupActiveIdSliceMap[i], ",")
- tmpGroupAllActiveIdMap[i] = strings.Join(tmpGroupAllActiveIdSliceMap[i], ",")
- tmpGroupNoIncrementalActiveIdMap[i] = strings.Join(tmpGroupNoIncrementalActiveIdSliceMap[i], ",")
- tmpGroupCompanyReportRecordNum := statistic_report.CompanyReportRecordNum{
- TryOutNum: tmpGroupTryOutNumMap[i],
- TryOutIds: tmpGroupTryOutIdMap[i],
- FormalNum: tmpGroupFormalNumMap[i],
- FormalIds: tmpGroupFormalIdMap[i],
- ActiveNum: tmpGroupActiveNumMap[i],
- ActiveIds: tmpGroupActiveIdMap[i],
- AllActiveNum: tmpGroupAllActiveNumMap[i],
- AllActiveIds: tmpGroupAllActiveIdMap[i],
- NoIncrementalActiveNum: tmpGroupNoIncrementalActiveNumMap[i],
- NoIncrementalActiveIds: tmpGroupNoIncrementalActiveIdMap[i],
- StartDate: startDateIndexList[i],
- EndDate: endDateIndexList[i],
- }
- tmpGroupCompanyReportRecordNumList = append(tmpGroupCompanyReportRecordNumList, tmpGroupCompanyReportRecordNum)
- }
- groupReportRecord := statistic_report.GroupReportRecord{
- Item: tmpGroupAdminReportRecord,
- Name: v.GroupName,
- GroupId: v.GroupId,
- CompanyReportRecordNumList: tmpGroupCompanyReportRecordNumList,
- }
- groupReportRecordList = append(groupReportRecordList, groupReportRecord)
- }
- //总体汇总数据
- for i := 0; i < len(tmpAllFormalNumMap); i++ {
- tmpGroupCompanyReportRecordNum := statistic_report.CompanyReportRecordNum{
- TryOutNum: tmpAllTryOutNumMap[i],
- TryOutIds: tmpAllTryOutIdMap[i],
- FormalNum: tmpAllFormalNumMap[i],
- FormalIds: tmpAllFormalIdMap[i],
- ActiveNum: tmpAllActiveNumMap[i],
- ActiveIds: tmpAllActiveIdMap[i],
- AllActiveNum: tmpAllAllActiveNumMap[i],
- AllActiveIds: tmpAllAllActiveIdMap[i],
- NoIncrementalActiveNum: tmpAllNoIncrementalActiveNumMap[i],
- NoIncrementalActiveIds: tmpAllNoIncrementalActiveIdMap[i],
- StartDate: startDateIndexList[i],
- EndDate: endDateIndexList[i],
- }
- allCompanyReportRecordNum = append(allCompanyReportRecordNum, tmpGroupCompanyReportRecordNum)
- }
- companyReportRecordResp.CompanyReportRecordNumList = allCompanyReportRecordNum
- tmpList := groupReportRecordList
- //因为RoleTypeCode不一样,所以需要重新从数据库取数据
- adminInfo, _ := system.GetSysAdminById(sysUser.AdminId)
- adminGroupId := adminInfo.GroupId
- if tmpGroupId, ok := groupIdRelationMap[adminGroupId]; ok {
- adminGroupId = tmpGroupId
- }
- switch adminInfo.RoleTypeCode {
- case utils.ROLE_TYPE_CODE_FICC_GROUP, utils.ROLE_TYPE_CODE_FICC_TEAM:
- for index, v := range tmpList {
- //如果不是同一个分组,那么就移除该分组下的人员数据
- if v.GroupId != adminGroupId {
- tmpList[index].Item = make([]statistic_report.AdminReportRecord, 0)
- } else {
- tmpList[index], tmpList[0] = tmpList[0], tmpList[index]
- }
- }
- companyReportRecordResp.List = tmpList
- case utils.ROLE_TYPE_CODE_RAI_GROUP:
- for index, v := range tmpList {
- //如果不是同一个分组,那么就移除该分组下的人员数据
- if v.GroupId != adminGroupId {
- tmpList[index].Item = make([]statistic_report.AdminReportRecord, 0)
- } else {
- tmpList[index], tmpList[0] = tmpList[0], tmpList[index]
- }
- }
- companyReportRecordResp.List = tmpList
- case utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_ADMIN, utils.ROLE_TYPE_CODE_RAI_ADMIN:
- //管理员、超管看全部数据
- companyReportRecordResp.List = tmpList
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = companyReportRecordResp
- }
- // CompanyList
- // @Title 客户列表
- // @Description 客户列表接口
- // @Param request body statisticModels.IncrementalCompanyListReq true "type json string"
- // @Success 200 {object} statistic_report.CompanyListResp
- // @router /report/company_list [post]
- func (this *StatisticReportController) CompanyList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- //roleTypeCode := sysUser.RoleTypeCode
- var req statisticModels.IncrementalCompanyListReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- resp, err, errMsg := statistic_report.CompanyList(sysUser, req)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = errMsg
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // RenewCompanyStatistics
- // @Title 获取续约客户统计数据
- // @Description 获取续约客户统计数据接口
- // @Param DataType query string true "枚举值:week、month、time_interval"
- // @Param ProductId query int true "客户类型 ficc:1 权益:2"
- // @Param StartDate query string true "开始日期,格式:2022-04-06"
- // @Param EndDate query string true "结束日期,格式:2022-04-06"
- // @Success 200 {object} statistic_report.CompanyRenewRecordResp
- // @router /report/renew_company [get]
- func (this *StatisticReportController) RenewCompanyStatistics() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- dataType := this.GetString("DataType")
- productId, _ := this.GetInt("ProductId", 1)
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- var companyRenewDataMapList []statistic_report.CompanyRenewDataMap
- var err error
- var firstDate time.Time
- switch dataType {
- //获取列表
- case "week":
- nowWeekMonday := utils.GetNowWeekMonday() //本周周一
- //companyRenewDataMapList, firstDate, err = statistic_report.GetWeekData()
- companyRenewDataMapList, firstDate, err = statistic_report.GetRenewWeekDataNum(nowWeekMonday, productId, 6)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- case "month":
- nowMonthFirstDay := utils.GetNowMonthFirstDay() //本月第一天
- //companyRenewDataMapList, firstDate, err = statistic_report.GetMonthData()
- companyRenewDataMapList, firstDate, err = statistic_report.GetRenewMonthDataNum(nowMonthFirstDay, productId, 6)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- case "time_interval":
- if startDate == `` || endDate == `` {
- br.Msg = "开始日期或结束日期不能为空"
- br.ErrMsg = "开始日期或结束日期不能为空,Err:" + err.Error()
- return
- }
- companyRenewDataMapList, firstDate, err = statistic_report.GetRenewTimeIntervalData(productId, startDate, endDate)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- }
- var group []services.AdminGroup
- var groupIdRelationMap map[int]int
- var groupMap map[int][]*roadshow.Researcher
- //获取销售人员分组数据
- if productId == 1 {
- group, groupIdRelationMap, err = services.GetFiccSystemGroup()
- if err != nil {
- br.Msg = "获取信息失败!"
- br.ErrMsg = "获取分组信息失败!Err:" + err.Error()
- return
- }
- researcherList, tmpErr := services.GetFiccSeller(firstDate, groupIdRelationMap)
- if tmpErr != nil {
- err = tmpErr
- }
- groupMap = make(map[int][]*roadshow.Researcher)
- for _, v := range researcherList {
- if v.RoleTypeCode == "ficc_admin" {
- findItems := groupMap[1]
- findItems = append(findItems, v)
- groupMap[1] = findItems
- } else {
- if findItems, ok := groupMap[v.GroupId]; ok {
- findItems = append(findItems, v)
- groupMap[v.GroupId] = findItems
- } else {
- findItems = append(findItems, v)
- groupMap[v.GroupId] = findItems
- }
- }
- }
- } else {
- group, groupIdRelationMap, err = services.GetRaiSystemGroup()
- if err != nil {
- br.Msg = "获取信息失败!"
- br.ErrMsg = "获取分组信息失败!Err:" + err.Error()
- return
- }
- researcherList, tmpErr := services.GetRaiSeller(groupIdRelationMap)
- if tmpErr != nil {
- err = tmpErr
- }
- groupMap = make(map[int][]*roadshow.Researcher)
- for _, v := range researcherList {
- if v.RoleTypeCode == "rai_admin" {
- findItems := groupMap[1]
- findItems = append(findItems, v)
- groupMap[1] = findItems
- } else {
- if findItems, ok := groupMap[v.GroupId]; ok {
- findItems = append(findItems, v)
- groupMap[v.GroupId] = findItems
- } else {
- findItems = append(findItems, v)
- groupMap[v.GroupId] = findItems
- }
- }
- }
- }
- //数据处理
- groupRenewRecordList := make([]statistic_report.GroupRenewRecord, 0)
- allCompanyRenewRecordNum := make([]statistic_report.CompanyRenewRecordNum, 0)
- companyRenewRecordResp := statistic_report.CompanyRenewRecordResp{
- List: groupRenewRecordList,
- CompanyRenewRecordNumList: allCompanyRenewRecordNum,
- }
- startDateIndexList := make(map[int]string) //开始时间间隔map
- endDateIndexList := make(map[int]string) //结束时间间隔map
- //客户数汇总
- tmpAllNotRenewNumMap := make(map[int]int)
- tmpAllRenewFollowNumMap := make(map[int]int)
- tmpAllExpireNumMap := make(map[int]int)
- tmpAllRenewNumMap := make(map[int]int)
- tmpAllUnusualRenewNumMap := make(map[int]int) // 续约异常客户数量汇总
- tmpAllFormalCompanyNumMap := make(map[int]int) // 当期正式客户数量汇总
- //id集合汇总
- tmpAllNotRenewIdMap := make(map[int]string)
- tmpAllRenewFollowIdMap := make(map[int]string)
- tmpAllExpireIdMap := make(map[int]string)
- tmpAllRenewIdMap := make(map[int]string)
- tmpAllUnusualRenewIdMap := make(map[int]string) // 续约异常客户id汇总
- tmpAllUnusualRenewIdSlice := make(map[int][]string, 0)
- for _, v := range group {
- v.ResearcherList = groupMap[v.GroupId]
- tmpGroupAdminRenewRecord := make([]statistic_report.AdminRenewRecord, 0)
- tmpGroupCompanyRenewRecordNumList := make([]statistic_report.CompanyRenewRecordNum, 0)
- //数量统计
- tmpGroupNotRenewNumMap := make(map[int]int)
- tmpGroupRenewFollowNumMap := make(map[int]int)
- tmpGroupExpireNumMap := make(map[int]int)
- tmpGroupRenewNumMap := make(map[int]int)
- tmpGroupUnusualRenewNumMap := make(map[int]int) //组内续约异常客户数
- //id集合
- tmpGroupNotRenewIdSliceMap := make(map[int][]string)
- tmpGroupRenewFollowIdSliceMap := make(map[int][]string)
- tmpGroupExpireIdSliceMap := make(map[int][]string)
- tmpGroupRenewIdSliceMap := make(map[int][]string)
- tmpGroupUnusualRenewIdSliceMap := make(map[int][]string) // 组内续约异常客户id汇总
- //id集合
- tmpGroupNotRenewIdMap := make(map[int]string)
- tmpGroupRenewFollowIdMap := make(map[int]string)
- tmpGroupExpireIdMap := make(map[int]string)
- tmpGroupRenewIdMap := make(map[int]string)
- tmpGroupUnusualRenewIdMap := make(map[int]string) // 组内续约异常客户id汇总
- for _, researcher := range groupMap[v.GroupId] {
- //组内研究员数据
- //每个区间的数据
- tmpCompanyRenewRecordNumList := make([]statistic_report.CompanyRenewRecordNum, 0)
- for index, adminData := range companyRenewDataMapList {
- startDateIndexList[index] = adminData.StartDate
- endDateIndexList[index] = adminData.EndDate
- var tmpNotRenewNum, tmpRenewFollowNum, tmpExpireStatus, tmpRenewStatus, tmpUnusualRenewStatus int
- //var tmpNotRenewIds, tmpRenewFollowIds, tmpExpireIds string
- var tmpNotRenewIdSlice, tmpRenewFollowIdSlice, tmpExpireIdSlice, tmpRenewIdSlice, tmpUnusualRenewIdSlice []string
- var tmpNotRenewId, tmpRenewFollowId, tmpExpireId, tmpRenewId, tmpUnusualRenewId string
- if num, ok := adminData.NotRenewMap[researcher.AdminId]; ok {
- tmpNotRenewNum = num
- tmpNotRenewIdSlice = append(tmpNotRenewIdSlice, adminData.NotRenewIdMap[researcher.AdminId])
- tmpNotRenewId = strings.Join(tmpNotRenewIdSlice, ",")
- }
- if num, ok := adminData.RenewFollowMap[researcher.AdminId]; ok {
- tmpRenewFollowNum = num
- tmpRenewFollowIdSlice = append(tmpRenewFollowIdSlice, adminData.RenewFollowIdMap[researcher.AdminId])
- tmpRenewFollowId = strings.Join(tmpRenewFollowIdSlice, ",")
- }
- if num, ok := adminData.ExpireMap[researcher.AdminId]; ok {
- tmpExpireStatus = num
- tmpExpireIdSlice = append(tmpExpireIdSlice, adminData.ExpireIdMap[researcher.AdminId])
- tmpExpireId = strings.Join(tmpExpireIdSlice, ",")
- }
- if num, ok := adminData.RenewMap[researcher.AdminId]; ok {
- tmpRenewStatus = num
- tmpRenewIdSlice = append(tmpRenewIdSlice, adminData.RenewIdMap[researcher.AdminId])
- tmpRenewId = strings.Join(tmpRenewIdSlice, ",")
- }
- // 续约异常客户
- if num, ok := adminData.UnusualRenewMap[researcher.AdminId]; ok {
- tmpUnusualRenewStatus = num
- tmpUnusualRenewIdSlice = append(tmpUnusualRenewIdSlice, adminData.UnusualRenewIdMap[researcher.AdminId])
- tmpUnusualRenewId = strings.Join(tmpUnusualRenewIdSlice, ",")
- }
- tmpAdminRsRenewRecordNum := statistic_report.CompanyRenewRecordNum{
- NotRenewNum: tmpNotRenewNum,
- NotRenewIds: tmpNotRenewId,
- RenewFollowNum: tmpRenewFollowNum,
- RenewFollowIds: tmpRenewFollowId,
- ExpireNum: tmpExpireStatus,
- ExpireIds: tmpExpireId,
- RenewNum: tmpRenewStatus,
- RenewIds: tmpRenewId,
- UnusualRenewNum: tmpUnusualRenewStatus,
- UnusualRenewIds: tmpUnusualRenewId,
- StartDate: adminData.StartDate,
- EndDate: adminData.EndDate,
- }
- tmpCompanyRenewRecordNumList = append(tmpCompanyRenewRecordNumList, tmpAdminRsRenewRecordNum)
- //组内数据汇总
- if _, ok := tmpGroupNotRenewNumMap[index]; !ok {
- tmpGroupNotRenewNumMap[index] = 0
- }
- if _, ok := tmpGroupRenewFollowNumMap[index]; !ok {
- tmpGroupRenewFollowNumMap[index] = 0
- }
- if _, ok := tmpGroupExpireNumMap[index]; !ok {
- tmpGroupExpireNumMap[index] = 0
- }
- if _, ok := tmpGroupRenewNumMap[index]; !ok {
- tmpGroupRenewNumMap[index] = 0
- }
- if _, ok := tmpGroupUnusualRenewNumMap[index]; !ok {
- tmpGroupUnusualRenewNumMap[index] = 0
- }
- tmpGroupNotRenewNumMap[index] += tmpNotRenewNum
- tmpGroupRenewFollowNumMap[index] += tmpRenewFollowNum
- tmpGroupExpireNumMap[index] += tmpExpireStatus
- tmpGroupRenewNumMap[index] += tmpRenewStatus
- tmpGroupUnusualRenewNumMap[index] += tmpUnusualRenewStatus
- //组内数据汇总
- if _, ok := tmpGroupNotRenewIdMap[index]; !ok {
- tmpGroupNotRenewIdMap[index] = ""
- }
- if _, ok := tmpGroupRenewFollowIdMap[index]; !ok {
- tmpGroupRenewFollowIdMap[index] = ""
- }
- if _, ok := tmpGroupExpireIdMap[index]; !ok {
- tmpGroupExpireIdMap[index] = ""
- }
- if tmpNotRenewId != "" {
- tmpGroupNotRenewIdSliceMap[index] = append(tmpGroupNotRenewIdSliceMap[index], tmpNotRenewId)
- }
- if tmpRenewFollowId != "" {
- tmpGroupRenewFollowIdSliceMap[index] = append(tmpGroupRenewFollowIdSliceMap[index], tmpRenewFollowId)
- }
- if tmpExpireId != "" {
- tmpGroupExpireIdSliceMap[index] = append(tmpGroupExpireIdSliceMap[index], tmpExpireId)
- }
- if tmpRenewId != "" {
- tmpGroupRenewIdSliceMap[index] = append(tmpGroupRenewIdSliceMap[index], tmpRenewId)
- }
- if tmpUnusualRenewId != "" {
- tmpGroupUnusualRenewIdSliceMap[index] = append(tmpGroupUnusualRenewIdSliceMap[index], tmpUnusualRenewId)
- tmpSlice := strings.Split(tmpUnusualRenewId, ",")
- tmpAllUnusualRenewIdSlice[index] = append(tmpAllUnusualRenewIdSlice[index], tmpSlice...)
- }
- //总数据汇总
- if _, ok := tmpAllNotRenewNumMap[index]; !ok {
- tmpAllNotRenewNumMap[index] = 0
- }
- if _, ok := tmpAllRenewFollowNumMap[index]; !ok {
- tmpAllRenewFollowNumMap[index] = 0
- }
- if _, ok := tmpAllExpireNumMap[index]; !ok {
- tmpAllExpireNumMap[index] = 0
- }
- if _, ok := tmpAllRenewNumMap[index]; !ok {
- tmpAllRenewNumMap[index] = 0
- }
- tmpAllNotRenewNumMap[index] += tmpNotRenewNum
- tmpAllRenewFollowNumMap[index] += tmpRenewFollowNum
- tmpAllExpireNumMap[index] += tmpExpireStatus
- tmpAllRenewNumMap[index] += tmpRenewStatus
- tmpAllUnusualRenewNumMap[index] = adminData.UnusualRenewTotal
- tmpAllFormalCompanyNumMap[index] = adminData.FormalCompanyTotal
- }
- tmpAdminRenewRecord := statistic_report.AdminRenewRecord{
- Name: researcher.RealName,
- AdminId: researcher.AdminId,
- CompanyRenewRecordNumList: tmpCompanyRenewRecordNumList,
- }
- tmpGroupAdminRenewRecord = append(tmpGroupAdminRenewRecord, tmpAdminRenewRecord)
- }
- for i := 0; i < len(tmpGroupExpireNumMap); i++ {
- tmpGroupNotRenewIdMap[i] = strings.Join(tmpGroupNotRenewIdSliceMap[i], ",")
- tmpGroupRenewFollowIdMap[i] = strings.Join(tmpGroupRenewFollowIdSliceMap[i], ",")
- tmpGroupExpireIdMap[i] = strings.Join(tmpGroupExpireIdSliceMap[i], ",")
- tmpGroupRenewIdMap[i] = strings.Join(tmpGroupRenewIdSliceMap[i], ",")
- tmpGroupUnusualRenewIdMap[i] = strings.Join(tmpGroupUnusualRenewIdSliceMap[i], ",")
- tmpGroupCompanyRenewRecordNum := statistic_report.CompanyRenewRecordNum{
- NotRenewNum: tmpGroupNotRenewNumMap[i],
- NotRenewIds: tmpGroupNotRenewIdMap[i],
- RenewFollowNum: tmpGroupRenewFollowNumMap[i],
- RenewFollowIds: tmpGroupRenewFollowIdMap[i],
- ExpireNum: tmpGroupExpireNumMap[i],
- ExpireIds: tmpGroupExpireIdMap[i],
- RenewNum: tmpGroupRenewNumMap[i],
- RenewIds: tmpGroupRenewIdMap[i],
- UnusualRenewNum: tmpGroupUnusualRenewNumMap[i],
- UnusualRenewIds: tmpGroupUnusualRenewIdMap[i],
- StartDate: startDateIndexList[i],
- EndDate: endDateIndexList[i],
- }
- tmpGroupCompanyRenewRecordNumList = append(tmpGroupCompanyRenewRecordNumList, tmpGroupCompanyRenewRecordNum)
- }
- groupRenewRecord := statistic_report.GroupRenewRecord{
- Item: tmpGroupAdminRenewRecord,
- Name: v.GroupName,
- GroupId: v.GroupId,
- CompanyRenewRecordNumList: tmpGroupCompanyRenewRecordNumList,
- }
- groupRenewRecordList = append(groupRenewRecordList, groupRenewRecord)
- }
- // 总体数据汇总,去掉重复销售的公司个数
- //总体汇总数据
- for i := 0; i < len(tmpAllRenewFollowNumMap); i++ {
- // 未续约统计数据去重
- unusualRenewIdsFinal := make([]string, 0)
- unusualRenewIdsMap := make(map[string]struct{})
- for _, id := range tmpAllUnusualRenewIdSlice[i] {
- if _, ok := unusualRenewIdsMap[id]; !ok {
- unusualRenewIdsFinal = append(unusualRenewIdsFinal, id)
- unusualRenewIdsMap[id] = struct{}{}
- }
- }
- tmpAllUnusualRenewNumMap[i] = len(unusualRenewIdsFinal)
- tmpAllUnusualRenewIdMap[i] = strings.Join(unusualRenewIdsFinal, ",")
- unusualRate := ``
- if tmpAllUnusualRenewNumMap[i] > 0 && tmpAllFormalCompanyNumMap[i] > 0 {
- unusualRate = decimal.NewFromInt(int64(tmpAllUnusualRenewNumMap[i])*100).Div(decimal.NewFromInt(int64(tmpAllFormalCompanyNumMap[i]))).Round(2).String() + "%"
- }
- tmpGroupCompanyRenewRecordNum := statistic_report.CompanyRenewRecordNum{
- NotRenewNum: tmpAllNotRenewNumMap[i],
- NotRenewIds: tmpAllNotRenewIdMap[i],
- RenewFollowNum: tmpAllRenewFollowNumMap[i],
- RenewFollowIds: tmpAllRenewFollowIdMap[i],
- ExpireNum: tmpAllExpireNumMap[i],
- ExpireIds: tmpAllExpireIdMap[i],
- RenewNum: tmpAllRenewNumMap[i],
- RenewIds: tmpAllRenewIdMap[i],
- UnusualRenewNum: tmpAllUnusualRenewNumMap[i],
- UnusualRenewIds: tmpAllUnusualRenewIdMap[i],
- UnusualRate: unusualRate, // 异常率
- StartDate: startDateIndexList[i],
- EndDate: endDateIndexList[i],
- }
- allCompanyRenewRecordNum = append(allCompanyRenewRecordNum, tmpGroupCompanyRenewRecordNum)
- }
- companyRenewRecordResp.CompanyRenewRecordNumList = allCompanyRenewRecordNum
- tmpList := groupRenewRecordList
- //因为RoleTypeCode不一样,所以需要重新从数据库取数据
- adminInfo, _ := system.GetSysAdminById(sysUser.AdminId)
- adminGroupId := adminInfo.GroupId
- if tmpGroupId, ok := groupIdRelationMap[adminGroupId]; ok {
- adminGroupId = tmpGroupId
- }
- if productId == 2 {
- //对权益组排个序
- tmpList = statistic_report.SortGroupSellers(tmpList)
- }
- switch adminInfo.RoleTypeCode {
- case utils.ROLE_TYPE_CODE_FICC_GROUP, utils.ROLE_TYPE_CODE_FICC_TEAM:
- for index, v := range tmpList {
- //如果不是同一个分组,那么就移除该分组下的人员数据
- if v.GroupId != adminGroupId {
- tmpList[index].Item = make([]statistic_report.AdminRenewRecord, 0)
- } else {
- tmpList[index], tmpList[0] = tmpList[0], tmpList[index]
- }
- }
- companyRenewRecordResp.List = tmpList
- case utils.ROLE_TYPE_CODE_RAI_GROUP:
- for index, v := range tmpList {
- //如果不是同一个分组,那么就移除该分组下的人员数据
- if v.GroupId != adminGroupId {
- tmpList[index].Item = make([]statistic_report.AdminRenewRecord, 0)
- } else {
- tmpList[index], tmpList[0] = tmpList[0], tmpList[index]
- }
- }
- companyRenewRecordResp.List = tmpList
- case utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_ADMIN, utils.ROLE_TYPE_CODE_RAI_ADMIN:
- //管理员、超管看全部数据
- companyRenewRecordResp.List = tmpList
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = companyRenewRecordResp
- }
- // List
- // @Title 商品到款统计列表
- // @Description 商品到款统计列表
- // @Param Keyword query string false "关键词"
- // @Param ServiceType query int false "套餐类型"
- // @Param StartDate query string false "合同开始日期"
- // @Param EndDate query string false "合同结束日期"
- // @Param TimeType query int false "时间类型: 1-开票时间; 2-到款时间"
- // @Param hasInvoice query string false "是否已开票: 0-否; 1-是; 空-全部"
- // @Param HasPayment query string false "是否已到款: 0-否; 1-是; 空-全部"
- // @Param ListParam query int false "套餐类型: 0-全部; 1-ficc; 2-权益"
- // @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:'invoice_time':开票日 、 'payment_date':到款日"
- // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
- // @Success 200 {object} fms.ContractRegisterItem
- // @router /census/invoice_payment/list [get]
- func (this *StatisticReportController) InvoicePaymentList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- keyword := this.GetString("Keyword")
- serviceType := this.GetString("ServiceType")
- timeType, _ := this.GetInt("TimeType")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- hasInvoice := this.GetString("HasInvoice")
- hasPayment := this.GetString("HasPayment")
- sortParam := this.GetString("SortParam")
- sortType := this.GetString("SortType")
- sellerIdstr := this.GetString("SellerIds")
- cond := `1 = 1`
- pars := make([]interface{}, 0)
- // 客户姓名/销售
- if keyword != "" {
- kw := "%" + keyword + "%"
- cond += ` AND b.company_name LIKE ?`
- pars = append(pars, kw)
- }
- if sellerIdstr != "" {
- //sellerIds := strings.Split(sellerIdstr, ",")
- cond += ` AND (c.seller_id in (` +sellerIdstr+ `) OR d.seller_id in (` +sellerIdstr+ `))`
- //pars = append(pars, sellerIds, sellerIds)
- }
- // 套餐筛选
- if serviceType != "" {
- serviceTypes := strings.Split(serviceType, ",")
- tempRegisterIds, e := fms.GetContractRegisterIdsByTempId(serviceTypes)
- if e != nil {
- br.Msg = "获取失败!"
- br.ErrMsg = "获取合同登记IDs失败,Err:" + e.Error()
- return
- }
- if len(tempRegisterIds) > 0 {
- cond += ` AND a.register_id IN (` + utils.GetOrmInReplace(len(tempRegisterIds)) + `)`
- pars = append(pars, tempRegisterIds)
- } else {
- cond += ` AND 1 = 2`
- }
- }
- var depId int
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
- depId = 2
- } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
- depId = 5
- }
- dshiAdminId := 13
- if utils.RunMode == "debug" {
- dshiAdminId = 233
- }
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
- sellerIdsList, err := system.GetSellerIdsByDepId(depId)
- if err != nil {
- br.Msg = "获取失败!"
- br.ErrMsg = "获取商品到款统计列表总数失败,Err:" + err.Error()
- return
- }
- cond += ` AND (c.seller_id IN (` + strings.Join(sellerIdsList, ",") + `) OR d.seller_id IN (` + strings.Join(sellerIdsList, ",") + `))`
- } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP && sysUser.AdminId == dshiAdminId {
- groupTeamSellerList, err := system.GetSysUserByParentIdGroupId(5)
- if err != nil {
- br.Msg = "获取销售失败"
- br.ErrMsg = "获取销售失败,Err:" + err.Error()
- return
- }
- sellerIdsList := ""
- for _, v := range groupTeamSellerList {
- sellerIdsList += strconv.Itoa(v.AdminId) + ","
- }
- sellerIdsList = strings.TrimRight(sellerIdsList, ",")
- cond += ` AND (c.seller_id IN (` + sellerIdsList + `) OR d.seller_id IN (` + sellerIdsList + `))`
- pars = append(pars)
- } else if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
- cond += ` AND (c.seller_id=? OR d.seller_id=?)`
- pars = append(pars, sysUser.AdminId, sysUser.AdminId)
- }
- // 开票到款日期
- if timeType != 0 {
- if timeType == 1 && startDate != "" && endDate != "" {
- st := fmt.Sprint(startDate, " 00:00:00")
- ed := fmt.Sprint(endDate, " 23:59:59")
- cond += ` AND (c.invoice_time BETWEEN ? AND ?) `
- pars = append(pars, st, ed)
- } else if timeType == 2 && startDate != "" && endDate != "" {
- st := fmt.Sprint(startDate, " 00:00:00")
- ed := fmt.Sprint(endDate, " 23:59:59")
- cond += ` AND (d.invoice_time BETWEEN ? AND ?) `
- pars = append(pars, st, ed)
- } else if timeType == 3 && startDate != "" && endDate != "" {
- st := fmt.Sprint(startDate, " 00:00:00")
- ed := fmt.Sprint(endDate, " 23:59:59")
- cond += ` AND (c.invoice_time BETWEEN ? AND ?) AND (d.invoice_time BETWEEN ? AND ?) `
- pars = append(pars, st, ed, st, ed)
- }
- } else if startDate != "" && endDate != "" {
- st := fmt.Sprint(startDate, " 00:00:00")
- ed := fmt.Sprint(endDate, " 23:59:59")
- cond += ` AND ((c.invoice_time BETWEEN ? AND ?) or (d.invoice_time BETWEEN ? AND ?))`
- pars = append(pars, st, ed, st, ed)
- }
- if hasInvoice == "1" {
- cond += ` AND a.invoice_id > 0 `
- } else if hasInvoice == "0" {
- cond += ` AND a.invoice_id = 0 `
- }
- if hasPayment == "1" {
- cond += ` AND a.payment_id > 0 `
- } else if hasPayment == "0" {
- cond += ` AND a.payment_id = 0 `
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- //排序
- if sortType == "" {
- sortType = "desc"
- }
- if sortType != "desc" && sortType != "asc" {
- br.Msg = "排序类型不正确!"
- return
- }
- var order string
- if sortParam == "" {
- order = ` ORDER BY sort_invoice_id ,sort_payment_id desc,c.invoice_time desc,c.amount desc,a.create_time desc `
- } else if sortParam == "invoice_time" {
- if sortType == "asc" {
- order = ` ORDER BY sort_invoice_id desc,c.invoice_time ,c.amount ,a.create_time ASC `
- } else {
- order = ` ORDER BY sort_invoice_id ,c.invoice_time desc,c.amount desc,a.create_time desc `
- }
- } else if sortParam == "payment_date" {
- if sortType == "asc" {
- order = ` ORDER BY sort_payment_id desc,d.invoice_time ,d.amount ,a.create_time `
- } else {
- order = ` ORDER BY sort_payment_id ,d.invoice_time desc,d.amount desc,a.create_time desc `
- }
- } else {
- br.Msg = "排序字段不正确!"
- return
- }
- registerList, total, e := fms.GetInvoicePaymentCensusPageList(cond, pars, order, startSize, pageSize)
- if e != nil {
- br.Msg = "获取失败!"
- br.ErrMsg = "获取商品到款统计列表总数失败,Err:" + e.Error()
- return
- }
- queryRegisterIds := make([]int, 0)
- for i := range registerList {
- queryRegisterIds = append(queryRegisterIds, registerList[i].ContractRegisterId)
- }
- //fmt.Println("queryRegisterIds:",queryRegisterIds)
- results := new(fms.InvoicePaymentCensusResp)
- if len(queryRegisterIds) > 0 {
- // 获取汇总数据IDs, 用于查询合计数据
- summaryIdsCond := cond
- summaryIdsPars := pars
- summaryIds, e := fms.GetInvoicePaymentCensusSummaryDataIds(summaryIdsCond, summaryIdsPars)
- if e != nil {
- br.Msg = "获取失败!"
- br.ErrMsg = "获取商品到款汇总IDs失败,Err:" + e.Error()
- return
- }
- //fmt.Println("summaryIds:",summaryIds)
- var listErr, totalErr, totalGroupErr error
- wg := sync.WaitGroup{}
- // 响应列表
- respList := make([]*fms.InvoicePaymentCensusItem, 0)
- summaryList := make([]*fms.InvoicePaymentSummaryItem, 0)
- wg.Add(1)
- go func() {
- defer wg.Done()
- // 获取汇总数据
- summaryCond := cond
- summaryCond += ` AND a.register_id IN (` + utils.GetOrmInReplace(len(queryRegisterIds)) + `)`
- summaryPars := pars
- summaryPars = append(summaryPars, queryRegisterIds)
- summaryData, e := fms.GetInvoicePaymentCensusSummaryData(summaryCond, summaryPars)
- if e != nil {
- br.Msg = "获取失败!"
- br.ErrMsg = "获取商品到款汇总列表失败,Err:" + e.Error()
- return
- }
- summaryList = summaryData
- //summaryIds := make([]int, 0)
- paymentIds := make([]int, 0)
- for i := range summaryList {
- //summaryIds = append(summaryIds, summaryList[i].SummaryId)
- if summaryList[i].PaymentId > 0 {
- paymentIds = append(paymentIds, summaryList[i].PaymentId)
- }
- }
- // 合同套餐
- /*contractServiceCond := `contract_register_id IN ?`
- contractServicePars := make([]interface{}, 0)
- contractServicePars = append(contractServicePars, queryRegisterIds)
- contractServiceOB := new(fms.ContractService)
- contractServiceList, e := contractServiceOB.List(contractServiceCond, contractServicePars)
- if e != nil {
- listErr = fmt.Errorf("获取合同套餐列表失败, Err: %s", e.Error())
- return
- }
- contractServiceMap := make(map[int][]*fms.ContractService, 0)
- servicesNameMap := make(map[int][]string, 0)
- for i := range contractServiceList {
- if contractServiceMap[contractServiceList[i].ContractRegisterId] == nil {
- contractServiceMap[contractServiceList[i].ContractRegisterId] = make([]*fms.ContractService, 0)
- }
- contractServiceMap[contractServiceList[i].ContractRegisterId] = append(contractServiceMap[contractServiceList[i].ContractRegisterId], contractServiceList[i])
- servicesNameMap[contractServiceList[i].ContractRegisterId] = append(servicesNameMap[contractServiceList[i].ContractRegisterId], contractServiceList[i].Title)
- }
- */
- servicesNameMap, serviceFormatMap, e := fmsService.GetContractServiceNameFormat(queryRegisterIds)
- if e != nil {
- listErr = fmt.Errorf("获取合同套餐列表失败, Err: %s", e.Error())
- return
- }
- // 到款套餐分配
- serviceAmountMap := make(map[int][]*fms.ContractPaymentServiceAmount, 0)
- if len(paymentIds) > 0 {
- serviceAmountCond := ` AND contract_payment_id IN (` + utils.GetOrmInReplace(len(paymentIds)) + `)`
- serviceAmountPars := make([]interface{}, 0)
- serviceAmountPars = append(serviceAmountPars, paymentIds)
- serviceAmountOB := new(fms.ContractPaymentServiceAmount)
- serviceAmountList, e := serviceAmountOB.List(serviceAmountCond, serviceAmountPars)
- if e != nil {
- listErr = fmt.Errorf("获取到款套餐分配列表失败, Err: %s", e.Error())
- return
- }
- for i := range serviceAmountList {
- if serviceAmountMap[serviceAmountList[i].ContractPaymentId] == nil {
- serviceAmountMap[serviceAmountList[i].ContractPaymentId] = make([]*fms.ContractPaymentServiceAmount, 0)
- }
- serviceAmountMap[serviceAmountList[i].ContractPaymentId] = append(serviceAmountMap[serviceAmountList[i].ContractPaymentId], serviceAmountList[i])
- }
- }
- // 重组汇总数据
- summaryMap := make(map[int][]*fms.InvoicePaymentCensusInfo)
- amountMap := make(map[string]*fms.ContractPaymentServiceAmount)
- for i := range summaryList {
- v := new(fms.InvoicePaymentCensusInfo)
- v.InvoiceId = summaryList[i].InvoiceId
- v.InvoiceDate = utils.TimeTransferString(utils.FormatDate, summaryList[i].InvoiceDate)
- v.InvoiceAmount = summaryList[i].InvoiceAmount
- v.SellerId = summaryList[i].SellerId
- v.SellerName = summaryList[i].SellerName
- v.SellerGroupId = summaryList[i].SellerGroupId
- v.SellerGroupName = summaryList[i].SellerGroupName
- v.SellerType = summaryList[i].ServiceProductId
- v.PaymentId = summaryList[i].PaymentId
- v.PaymentDate = utils.TimeTransferString(utils.FormatDate, summaryList[i].PaymentDate)
- v.PaymentAmount = summaryList[i].PaymentAmount
- v.PayType = summaryList[i].PayType
- // 套餐到款分配
- svaList := make([]*fms.ContractPaymentServiceAmountItem, 0)
- amountList := serviceAmountMap[summaryList[i].PaymentId]
- if amountList != nil {
- for i := range amountList {
- k := fmt.Sprintf("%d-%d", amountList[i].ContractPaymentId, amountList[i].ServiceTemplateId)
- amountMap[k] = amountList[i]
- }
- }
- // 合同对应的所有套餐
- svList := serviceFormatMap[summaryList[i].RegisterId]
- if svList != nil {
- for ii := range svList {
- vv := new(fms.ContractPaymentServiceAmountItem)
- vv.ServiceTemplateId = svList[ii].ServiceTemplateId
- vv.ServiceTemplateName = svList[ii].FormatTitle
- vv.ServiceTemplatePid = svList[ii].ServiceTemplatePid
- vv.ServiceProductId = svList[ii].ServiceProductId
- k2 := fmt.Sprintf("%d-%d", summaryList[i].PaymentId, svList[ii].ServiceTemplateId)
- a := amountMap[k2]
- if a != nil {
- vv.ContractPaymentServiceAmountId = a.ContractPaymentServiceAmountId
- vv.ContractPaymentId = a.ContractPaymentId
- vv.Amount = a.Amount
- }
- svaList = append(svaList, vv)
- }
- }
- v.ServiceAmountList = svaList
- summaryMap[summaryList[i].SummaryId] = append(summaryMap[summaryList[i].SummaryId], v)
- }
- // 响应列表
- for i := range registerList {
- v := new(fms.InvoicePaymentCensusItem)
- v.SummaryId = registerList[i].SummaryId
- v.ContractRegisterId = registerList[i].ContractRegisterId
- v.CompanyName = registerList[i].CompanyName
- v.NewCompany = registerList[i].NewCompany
- v.StartDate = utils.TimeTransferString(utils.FormatDate, registerList[i].StartDate)
- v.EndDate = utils.TimeTransferString(utils.FormatDate, registerList[i].EndDate)
- v.ServicesName = servicesNameMap[registerList[i].ContractRegisterId]
- v.InvoicePaymentList = summaryMap[registerList[i].SummaryId]
- v.ContractType = registerList[i].ContractType
- v.ActualPayCompanies = registerList[i].ActualPayCompanies
- respList = append(respList, v)
- }
- }()
- // 开票到款金额合计(换算后)
- var invoiceTotal, paymentTotal, amountTotal float64
- wg.Add(1)
- go func() {
- defer wg.Done()
- if len(summaryIds) == 0 {
- return
- }
- amountTotalCond := `a.id IN (` + utils.GetOrmInReplace(len(summaryIds)) + `)`
- amountTotalPars := make([]interface{}, 0)
- amountTotalPars = append(amountTotalPars, summaryIds)
- invoiceSum, e := fms.GetContractSummaryInvoicePaymentAmountTotal(amountTotalCond, amountTotalPars, 1)
- if e != nil {
- totalErr = fmt.Errorf("获取汇总开票金额合计失败, Err: %s", e.Error())
- return
- }
- invoiceTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", invoiceSum), 64)
- paymentSum, e := fms.GetContractSummaryInvoicePaymentAmountTotal(amountTotalCond, amountTotalPars, 2)
- if e != nil {
- totalErr = fmt.Errorf("获取汇总到款金额合计失败, Err: %s", e.Error())
- return
- }
- paymentTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", paymentSum), 64)
- amountCond := `a.id IN (` + utils.GetOrmInReplace(len(summaryIds)) + `) AND (a.invoice_id <> 0 OR (a.payment_id <> 0 AND a.invoice_id =0))`
- amountPars := make([]interface{}, 0)
- amountPars = append(amountPars, summaryIds)
- amountSum, e := fms.GetContractSummaryInvoicePaymentAmount(amountCond, amountPars)
- if e != nil {
- totalErr = fmt.Errorf("获取汇总金额合计失败, Err: %s", e.Error())
- return
- }
- amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
- }()
- // 分币种金额统计
- invoiceCurrencyTotals := make([]*fms.InvoiceListCurrencyTotal, 0)
- paymentCurrencyTotals := make([]*fms.InvoiceListCurrencyTotal, 0)
- wg.Add(1)
- go func() {
- defer wg.Done()
- currencyOB := new(fms.CurrencyUnit)
- currencyCond := `enable = 1`
- currencyPars := make([]interface{}, 0)
- currencyList, e := currencyOB.List(currencyCond, currencyPars)
- if e != nil {
- totalGroupErr = fmt.Errorf("获取货币列表失败, Err: %s", e.Error())
- return
- }
- unitMap := make(map[string]string)
- for i := range currencyList {
- unitMap[currencyList[i].Code] = currencyList[i].UnitName
- invoiceCurrencyTotals = append(invoiceCurrencyTotals, &fms.InvoiceListCurrencyTotal{
- Name: currencyList[i].Name,
- UnitName: currencyList[i].UnitName,
- Code: currencyList[i].Code,
- FlagImg: currencyList[i].FlagImg,
- })
- paymentCurrencyTotals = append(paymentCurrencyTotals, &fms.InvoiceListCurrencyTotal{
- Name: currencyList[i].Name,
- UnitName: currencyList[i].UnitName,
- Code: currencyList[i].Code,
- FlagImg: currencyList[i].FlagImg,
- })
- }
- if len(summaryIds) == 0 {
- return
- }
- totalGroupCond := `a.id IN (` + utils.GetOrmInReplace(len(summaryIds)) + `)`
- totalGroupPars := make([]interface{}, 0)
- totalGroupPars = append(totalGroupPars, summaryIds)
- invoiceSumGroup, e := fms.GetSummaryListCurrencySum(totalGroupCond, totalGroupPars, 1)
- if e != nil {
- totalGroupErr = fmt.Errorf("获取汇总货币合计开票金额失败, Err: %s", e.Error())
- return
- }
- paymentSumGroup, e := fms.GetSummaryListCurrencySum(totalGroupCond, totalGroupPars, 2)
- if e != nil {
- totalGroupErr = fmt.Errorf("获取汇总货币合计到款金额失败, Err: %s", e.Error())
- return
- }
- invoiceSumMap := make(map[string]float64)
- paymentSumMap := make(map[string]float64)
- for i := range invoiceSumGroup {
- invoiceSumMap[invoiceSumGroup[i].CurrencyUnit] = invoiceSumGroup[i].OriginAmountTotal
- continue
- }
- for i := range paymentSumGroup {
- paymentSumMap[paymentSumGroup[i].CurrencyUnit] = paymentSumGroup[i].OriginAmountTotal
- continue
- }
- for i := range invoiceCurrencyTotals {
- a, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", invoiceSumMap[invoiceCurrencyTotals[i].Code]), 64)
- invoiceCurrencyTotals[i].Amount = a
- }
- for i := range paymentCurrencyTotals {
- a, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", paymentSumMap[paymentCurrencyTotals[i].Code]), 64)
- paymentCurrencyTotals[i].Amount = a
- }
- }()
- wg.Wait()
- if listErr != nil {
- br.Msg = "获取失败!"
- br.ErrMsg = "获取商品到款汇总失败,Err:" + listErr.Error()
- return
- }
- if totalErr != nil {
- br.Msg = "获取失败!"
- br.ErrMsg = "获取商品到款汇总失败,Err:" + totalErr.Error()
- return
- }
- if totalGroupErr != nil {
- br.Msg = "获取失败!"
- br.ErrMsg = "获取商品到款汇总失败,Err:" + totalGroupErr.Error()
- return
- }
- results.DataList = respList
- results.InvoiceTotal = invoiceTotal
- results.PaymentTotal = paymentTotal
- results.AmountTotal = amountTotal
- results.InvoiceCurrencyTotal = invoiceCurrencyTotals
- results.PaymentCurrencyTotal = paymentCurrencyTotals
- }
- page := paging.GetPaging(currentIndex, pageSize, int(total))
- results.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = results
- }
- // SimpleList
- // @Title 合同套餐列表
- // @Description 合同套餐列表
- // @Param ProductId query int false "套餐类型: 1-FICC(默认); 2-权益"
- // @Success 200 {object} crm.ContractSearchListResp
- // @router /contract/service/simple [get]
- func (this *StatisticReportController) SimpleList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- list, err := fms.GetContractServiceTemplateSecond()
- if err != nil {
- br.Msg = "获取失败!"
- br.ErrMsg = "获取产品套餐失败,Err:" + err.Error()
- return
- }
- allList := make([]*fms.ContractServiceTemplateItem, 0)
- allMap := make(map[int][]*fms.ContractServiceTemplateMapItems)
- respList := make([]*fms.ContractServiceTemplateList, 0)
- for i := 0; i < len(list); i++ {
- if list[i].Title == "行业套餐" {
- industryList, e := fms.GetContractServiceTemplateMapByParentId(list[i].ServiceTemplateId)
- if e != nil {
- br.Msg = "获取失败!"
- br.ErrMsg = "获取套餐失败,Err:" + e.Error()
- return
- }
- for _, sv := range industryList {
- allList = append(allList, sv)
- }
- } else {
- allList = append(allList, list[i])
- }
- }
- for i := 0; i < len(allList); i++ {
- item := allList[i]
- v := new(fms.ContractServiceTemplateMapItems)
- v.ContractServiceTemplateItem = *item
- allMap[item.ProductId] = append(allMap[item.ProductId], v)
- }
- allTitleMap := map[int]string{
- 1: "FICC套餐",
- 2: "权益套餐",
- }
- tmp1 := &fms.ContractServiceTemplateList{
- Title: allTitleMap[1],
- Children: allMap[1],
- }
- tmp2 := &fms.ContractServiceTemplateList{
- Title: allTitleMap[2],
- Children: allMap[2],
- }
- respList = append(respList, tmp1)
- respList = append(respList, tmp2)
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = respList
- }
- // UnusualRenewCompanyStatistics
- // @Title 获取续约异常的客户统计数据
- // @Description 获取续约客户统计数据接口
- // @Param DataType query string true "枚举值:week、month、time_interval"
- // @Param Source query int true "类型,枚举值,1:续约异常客户;2:续约正常客户;3:超时续约客户;4:合同到期后一个月未续约客户;5:合同到期未续约客户;6:合同到期前一个月还未续约的客户;7:合同到期前两个月还未续约客户;8:合同到期前3个月还未续约客户;9:合同到期前4个月还未续约客户"
- // @Param StartDate query string true "开始日期,格式:2022-04-06"
- // @Param EndDate query string true "结束日期,格式:2022-04-06"
- // @Success 200 {object} statistic_report.CompanyUnusualRenewRecordResp
- // @router /report/unusual_renew_company [get]
- func (this *StatisticReportController) UnusualRenewCompanyStatistics() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- dataType := this.GetString("DataType")
- productId, _ := this.GetInt("ProductId", 1)
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- source, _ := this.GetInt("Source", 1)
- var companyUnusualRenewDataMapList []statistic_report.UnusualCompanyRenewDataMap
- var err error
- //var firstDate time.Time
- switch dataType {
- //获取列表
- case "week":
- nowWeekMonday := utils.GetNowWeekMonday() //本周周一
- //companyRenewDataMapList, firstDate, err = statistic_report.GetWeekData()
- companyUnusualRenewDataMapList, _, err = statistic_report.GetUnusualRenewWeekDataNum(nowWeekMonday, productId, source, 6)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- case "month":
- nowMonthFirstDay := utils.GetNowMonthFirstDay() //本月第一天
- companyUnusualRenewDataMapList, _, err = statistic_report.GetUnusualRenewMonthDataNum(nowMonthFirstDay, productId, source, 6)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- case "time_interval":
- if startDate == `` || endDate == `` {
- br.Msg = "开始日期或结束日期不能为空"
- br.ErrMsg = "开始日期或结束日期不能为空,Err:" + err.Error()
- return
- }
- companyUnusualRenewDataMapList, _, err = statistic_report.GetUnusualRenewTimeIntervalData(productId, source, startDate, endDate)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- }
- groupId := 0
- if utils.RunMode == "release" {
- groupId = 37
- } else {
- groupId = 61
- }
- subAdmins, err := system.GetAdminByGroupId(groupId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取销售失败"
- br.ErrMsg = "获取销售失败,Err:" + err.Error()
- return
- }
- //数据处理
- list := make([]statistic_report.GroupUnusualRenewRecord, 0)
- summaryList := make([]statistic_report.SummaryUnusualRenewRecordNum, 0)
- companyRenewRecordResp := statistic_report.CompanyUnusualRenewRecordResp{
- List: list,
- SummaryList: summaryList,
- }
- unusualRenewTotal := make(map[int]int)
- adminDataUnusualRenewTotal := make(map[int]int)
- // 每日期组数据的汇总客户id
- companyIdIndexMap := make(map[int][]string)
- for k, v := range subAdmins {
- tmpGroupCompanyRenewRecordNumList := make([]statistic_report.CompanyUnusualRenewRecordNum, 0)
- for index, adminData := range companyUnusualRenewDataMapList {
- tmpGroupCompanyRenewRecordNumList = append(tmpGroupCompanyRenewRecordNumList, statistic_report.CompanyUnusualRenewRecordNum{
- UnusualRenewNum: adminData.UnusualRenewMap[v.AdminId],
- UnusualRenewIds: adminData.UnusualRenewIdMap[v.AdminId],
- StartDate: adminData.StartDate,
- EndDate: adminData.EndDate,
- })
- unusualRenewTotal[index] = unusualRenewTotal[index] + adminData.UnusualRenewMap[v.AdminId]
- if adminData.UnusualRenewIdMap[v.AdminId] != `` {
- tmpCompanyIdList, ok := companyIdIndexMap[index]
- if !ok {
- tmpCompanyIdList = make([]string, 0)
- }
- companyIdIndexMap[index] = append(tmpCompanyIdList, adminData.UnusualRenewIdMap[v.AdminId])
- adminDataUnusualRenewTotal[index] = adminData.FormalCompanyTotal
- }
- if k == 0 {
- /*unusualRate := ``
- if adminData.UnusualRenewTotal > 0 && adminData.FormalCompanyTotal > 0 {
- unusualRate = decimal.NewFromInt(int64(adminData.UnusualRenewTotal)*100).Div(decimal.NewFromInt(int64(adminData.FormalCompanyTotal))).Round(2).String() + `%`
- }*/
- summaryList = append(summaryList, statistic_report.SummaryUnusualRenewRecordNum{
- UnusualRenewNum: 0,
- UnusualRate: "0",
- })
- }
- }
- list = append(list, statistic_report.GroupUnusualRenewRecord{
- SellerId: v.AdminId,
- SellerName: v.RealName,
- CompanyRenewRecordNumList: tmpGroupCompanyRenewRecordNumList,
- })
- }
- // 汇总数据
- for index, _ := range summaryList {
- totalSum, ok1 := unusualRenewTotal[index]
- if ok1 {
- summaryList[index].UnusualRenewNum = totalSum
- unusualRate := ``
- formalCompanyTotal, ok2 := adminDataUnusualRenewTotal[index]
- if ok2 {
- if totalSum > 0 && formalCompanyTotal > 0 {
- unusualRate = decimal.NewFromInt(int64(totalSum)*100).Div(decimal.NewFromInt(int64(formalCompanyTotal))).Round(2).String() + `%`
- summaryList[index].UnusualRate = unusualRate
- }
- }
- }
- tmpCompanyIdList, ok := companyIdIndexMap[index]
- if ok {
- summaryList[index].UnusualRenewIds = strings.Join(tmpCompanyIdList, ",")
- }
- }
- companyRenewRecordResp.List = list
- companyRenewRecordResp.SummaryList = summaryList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = companyRenewRecordResp
- }
- // UnusualRenewCompanyList
- // @Title 获取未续约的公司合同列表
- // @Description 获取未续约的公司合同列表
- // @Param ProductId query int false "套餐类型: 1-FICC(默认); 2-权益"
- // @Param Source query int true "类型,枚举值,1:续约异常客户;2:续约正常客户;3:超时续约客户;4:合同到期后一个月未续约客户;5:合同到期未续约客户;6:合同到期前一个月还未续约的客户;7:合同到期前两个月还未续约客户;8:合同到期前3个月还未续约客户;9:合同到期前4个月还未续约客户"
- // @Param StartDate query string true "开始日期,格式:2022-04"
- // @Param EndDate query string true "结束日期,格式:2022-04"
- // @Success 200 {object} company.GetUnusualRenewListGroupMonthResp
- // @router /report/unusual_renew_company/chart [get]
- func (this *StatisticReportController) UnusualRenewCompanyList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- // 起始日期
- // 截止日期
- productId, _ := this.GetInt("ProductId", 1)
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- source, _ := this.GetInt("Source", 1)
- if startDate == `` || endDate == `` {
- br.Msg = "开始日期或结束日期不能为空"
- return
- }
- allList := make([]*company.GetUnusualRenewListGroupMonth, 0)
- resp := new(company.GetUnusualRenewListGroupMonthResp)
- resp.List = allList
- newStartDate := startDate + "-01"
- newEndDate := endDate + "-01"
- startDateTimer, _ := time.ParseInLocation(utils.FormatDate, newStartDate, time.Local)
- endDateTimer, _ := time.ParseInLocation(utils.FormatDate, newEndDate, time.Local)
- endDateTimer = endDateTimer.AddDate(0, 1, 0).Add(-1 * time.Second) //本月最后一天
- // 按月分组
- monthMap := make(map[string]int)
- monthCompanyMap := make(map[string]struct{})
- monthList := make([]string, 0)
- tmpDate, _ := time.ParseInLocation(utils.FormatYearMonthDate, startDate, time.Local)
- tmpEndDate, _ := time.ParseInLocation(utils.FormatYearMonthDate, endDate, time.Local)
- for tmpDate.Before(tmpEndDate) || tmpDate == tmpEndDate {
- monthMap[tmpDate.Format(utils.FormatYearMonthDate)] = 0
- monthList = append(monthList, tmpDate.Format(utils.FormatYearMonthDate))
- tmpDate = tmpDate.AddDate(0, 1, 0)
- }
- // 只查询ficc销售下的客户
- roleTypeCode := "('ficc_seller','ficc_group','ficc_team')"
- researcherList, err := roadshow.GetSellerList(roleTypeCode, "")
- if err != nil {
- return
- }
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取销售失败"
- br.ErrMsg = "获取销售失败,Err:" + err.Error()
- return
- }
- if len(researcherList) == 0 {
- resp = &company.GetUnusualRenewListGroupMonthResp{
- List: allList,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- subAdminIds := make([]string, 0)
- for _, v := range researcherList {
- subAdminIds = append(subAdminIds, strconv.Itoa(v.AdminId))
- }
- sellerIds := strings.Join(subAdminIds, ",")
- list, err := company.GetUnusualRenewList(startDateTimer, endDateTimer, productId, source, sellerIds)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "数据异常,Err:" + err.Error()
- return
- }
- if len(list) > 0 {
- for _, v := range list {
- t := v.ModifyTime.Format(utils.FormatYearMonthDate)
- name := fmt.Sprintf("%s_%d", t, v.CompanyId)
- if _, ok := monthCompanyMap[name]; !ok {
- if num, ok1 := monthMap[t]; ok1 {
- monthMap[t] = num + 1
- }
- monthCompanyMap[name] = struct{}{}
- }
- }
- }
- for _, v := range monthList {
- n, _ := monthMap[v]
- tmp := &company.GetUnusualRenewListGroupMonth{
- Date: v,
- CompanyNum: n,
- }
- allList = append(allList, tmp)
- }
- resp = &company.GetUnusualRenewListGroupMonthResp{
- List: allList,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|