123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611 |
- <?php
- namespace app\sys\controller;
- use app\logics\CustomerLogic;
- use app\model\Customer;
- use app\model\CustomerClue;
- use app\model\CustomerVisitLog;
- use app\model\Employee;
- use app\model\Inspectors as InspectorsModel;
- use app\model\Org;
- use app\model\Setting;
- use app\model\StatisticsSetting;
- use think\facade\View;
- use think\helper\Str;
- use app\model\Company;
- use app\model\Activity as ModelActivity;
- use app\model\CustomerPackage;
- use app\model\CustomerPortraitField;
- use app\model\CustomerRecycle;
- use app\model\CustomerSource;
- use app\model\CustomerDropPool;
- use think\facade\Request;
- use app\model\ShareLog;
- use app\model\TrainCourseView;
- use app\model\TrainDoneLog;
- use app\model\CustomerPortraitFieldSelect;
- use app\model\CustomersSubscribe;
- use app\model\ExamEmpResult;
- use app\model\TalkskillViewLog;
- use app\model\OperateLog;
- use app\model\Shop;
- use app\model\AsyncTask;
- use app\model\OutCallLog;
- use app\model\CustomerInvalidLog;
- use app\model\OutCallMbLog;
- use think\facade\Log;
- use think\facade\Db;
- use toolkits\Aec;
- use app\model\CustomerExtension;
- use app\model\ExportLog;
- use openssl\Aes;
- /**
- * 数据统计
- */
- class Statistics
- {
- private $request;
- private $root_id;
- /**
- * 构造方法
- */
- public function __construct()
- {
- $this->request = request();
- $this->root_id = $this->request->employee->root_id;
- $xinjushang = 0;
- View::assign('xinjushang', $xinjushang);
- }
- /**
- * 数据获取接口
- *
- * @param string $metod
- * @return void
- */
- public function __call($method, $arguments)
- {
- if (!$this->request->isAjax()) {
- if (Str::snake($method) == 'customer' || Str::snake($method) == 'clue') {
- //返回组织列表
- $org = Org::where([['path', 'like', $this->root_id . '-%']])->select()->toArray();
- View::assign('org', $org);
- }
- $aes = new Aes('zqxg@screen');
- $rootAes = $aes->encrypt($this->root_id);
- view::assign('rootId', $rootAes);
- return View::fetch(Str::snake($method) . '_data');
- }
- $method .= 'Data';
- if (method_exists($this, $method)) {
- if ($method == 'followUpData') {
- $rs = $this->followUpData($arguments);
- } elseif ($method == 'customerData') {
- $rs = $this->customerData($arguments);
- } elseif ($method == 'clueData') {
- $rs = $this->clueData($arguments);
- } elseif ($method == 'editInspectorData') {
- $rs = $this->editInspectorData($arguments);
- } elseif ($method == 'inspectorsData') {
- $rs = $this->inspectorsData($arguments);
- } elseif ($method == 'addInspectorData') {
- $rs = $this->addInspectorData($arguments);
- } elseif ($method == 'houseData') {
- $rs = $this->houseData($arguments);
- } elseif ($method == 'sourceData') {
- $rs = $this->sourceData($arguments);
- }
- // $rs = $this->$method($arguments);
- return json($rs);
- }
- return json(['code' => 0, 'data' => [], 'count' => 0]);
- }
- /**
- * 客户数据统计
- *
- * @return string
- */
- private function customerData($param)
- {
- $startCondition = ['addtime', '>', date('Y-m-d H:i:s', 0)];
- $endCondition = ['addtime', '<', date('Y-m-d H:i:s')];
- $beforeCondition = '';
- //2023-02-15页面逻辑修改 传参方式改为 start_date=2023/2/15 - 2023/2/15
- if (!empty($param['start_date'])) {
- $count_dates = explode(' - ', $param['start_date']);
- $param['start_date'] = date('Y-m-d', strtotime($count_dates[0]));
- $param['end_date'] = date('Y-m-d', strtotime($count_dates[1]));
- $startCondition = ['addtime', '>', date('Y-m-d H:i:s', strtotime($param['start_date']))];
- $beforeCondition = date('Y-m-d H:i:s', strtotime($param['start_date']));
- }
- if (!empty($param['end_date'])) {
- $endCondition = ['addtime', '<', date('Y-m-d', strtotime($param['end_date'])) . ' 23:59:59'];
- }
- $param['page'] = !empty($param['page']) ? $param['page'] : 1;
- $param['limit'] = !empty($param['limit']) ? $param['limit'] : 10;
- // 占位数据
- $initdata = ', 0 as customer_num, 0 as unconfirm_num, 0 as deposit_num, 0 as signed_num, 0 as deposit_total_money, 0 as signed_total_money, 0 as shop_num,
- 0 as measure_num, 0 as clue_num, 0 as effective_num, 0 as meet_num, "0%" as meet_lv, "0%" as deposit_lv, "0%" as signed_lv, 0 as average_val, "0%" as effective_lv, 0 as maika_num';
- /** 不同数据内容整理 */
- if (empty($param['type']) || $param['type'] == 1) {
- $group = 'org_id';
- // 部门名称列表获取(只获取没有子部门的部门)
- if (!empty($param['select_org_id'])) {
- $select_org_path = Org::where('id', $param['select_org_id'])->value('path');
- $condition = [['path', 'like', $select_org_path . '%']];
- } else {
- $condition = [['path', 'like', $this->root_id . '-%']];
- }
- $org_where = [];
- $org_data = Org::where($condition)->select()->toArray();
- foreach ($org_data as $item) {
- $search = 'false';
- foreach ($org_data as $val) {
- if ($search == 'false') {
- if ($val['pid'] == $item['id']) {
- $search = 'true';
- }
- }
- }
- if ($search == 'false') $org_where[] = $item['id'];
- }
- $data = Org::where([['path', 'like', $this->root_id . '-%'], ['id', 'in', $org_where]])->page($param['page'], $param['limit'])->column('id,name as org_name, 0 as employee_num' . $initdata);
- // 部门id
- $orgIdList = array_column($data, 'id');
- // 查询条件
- $typeCondition = ['org_id', 'in', $orgIdList];
- // 量房,到店,见面数(量房+到店)
- $customerVisitData = $this->getCustomerVisitNum('org', $orgIdList, $startCondition, $endCondition, $beforeCondition, $typeCondition);
- $count = Org::where([['path', 'like', $this->root_id . '-%'], ['id', 'in', $org_where]])->count();
- } else {
- $group = 'employee_id';
- $orgCondition = [];
- if (!empty($param['org_id'])) $orgCondition = ['org_id', '=', $param['org_id']];
- // 部门人员获取
- $data = Employee::where([['root_id', '=', $this->root_id], ['state', '=', '在职'], ['uid', '<>', 0], $orgCondition])->page($param['page'], $param['limit'])->column('id, org_id, name' . $initdata);
- // 员工id
- $employeeIdList = array_column($data, 'id');
- // 查询条件
- $typeCondition = ['employee_id', 'in', $employeeIdList];
- // 量房,到店,见面数(量房+到店)
- $customerVisitData = $this->getCustomerVisitNum('employee', $employeeIdList, $startCondition, $endCondition, $beforeCondition, $typeCondition);
- // 员工部门获取
- $orgs = Org::where([['path', 'like', $this->root_id . '-%']])->column('name', 'id');
- $count = Employee::where([['root_id', '=', $this->root_id], ['state', '=', '在职'], ['uid', '<>', 0], $orgCondition])->count();
- $typeCondition = ['org_id', '=', $param['org_id']];
- }
- // 线索获取-转移客户没有转移线索导致数据对不上
- $sql = CustomerClue::where([$startCondition, $endCondition, $typeCondition, ['employee_id', 'in', $customerVisitData['eid']]])->group($group)->field("count(id) as clue_num,count(if(state=1, '1', null)) as effective_num, org_id, $group")->buildSql();
- $clueData = Db::query($sql);
- $clueData = array_combine(array_column($clueData, $group), $clueData);
- foreach ($data as &$item) {
- // 员工数据,添加部门信息
- if (!empty($param['type']) && $param['type'] != 1) {
- if (isset($orgs[$item['org_id']])) {
- $item['org_name'] = $orgs[$item['org_id']];
- } else {
- $item['org_name'] = '';
- }
- }
- if (isset($clueData[$item['id']])) {
- $item['clue_num'] = $clueData[$item['id']]['clue_num'];
- $item['effective_num'] = $clueData[$item['id']]['effective_num'];
- if (isset($customerVisitData['data'][$item['id']])) {
- $item['effective_num'] += $customerVisitData['data'][$item['id']]['effective_total_number'];
- }
- }
- if (isset($customerVisitData['data'][$item['id']])) {
- $item['deposit_total_money'] = $customerVisitData['data'][$item['id']]['deposit_total_money'];
- $item['signed_total_money'] = $customerVisitData['data'][$item['id']]['signed_total_money'];
- $item['signed_num'] = $customerVisitData['data'][$item['id']]['signed_num'];
- $item['deposit_num'] = $customerVisitData['data'][$item['id']]['deposit_num'];
- $item['unconfirm_num'] = $customerVisitData['data'][$item['id']]['unconfirm_num'];
- $item['shop_num'] = $customerVisitData['data'][$item['id']]['shop_num'];
- $item['measure_num'] = $customerVisitData['data'][$item['id']]['measure_num'];
- $item['meet_num'] = $customerVisitData['data'][$item['id']]['meet_num'];
- $item['maika_num'] = $customerVisitData['data'][$item['id']]['maika_num'];
- if (empty($param['type']) || $param['type'] == 1) {
- $item['employee_num'] = $customerVisitData['data'][$item['id']]['employee_num'];
- }
- $item['customer_num'] = $customerVisitData['data'][$item['id']]['customer_num'];
- }
- // 计算数据
- if ($item['signed_num'] != 0) $item['average_val'] = floor($item['signed_total_money'] / $item['signed_num']);
- if ($item['customer_num'] !== 0) $item['meet_lv'] = $item['customer_num'] ? round($item['meet_num'] / $item['customer_num'] * 100, 2) . '%' : '0%';
- if ($item['meet_num'] !== 0) $item['deposit_lv'] = round($item['deposit_num'] / $item['meet_num'] * 100, 2) . '%';
- if ($item['meet_num'] !== 0) $item['signed_lv'] = round($item['signed_num'] / $item['meet_num'] * 100, 2) . '%';
- if ($item['customer_num'] != 0) $item['effective_lv'] = round($item['effective_num'] / $item['customer_num'] * 100, 2) . '%';
- }
- return ['code' => 0, 'data' => $data, 'count' => $count];
- }
- /**
- * 量房到店数获取(用户客户数据统计获取优化)
- */
- public function getCustomerVisitNum($type, $ids, $startCondition, $endCondition, $beforeCondition, $typeCondition)
- {
- $orgId = $ids;
- if ($type == 'org') {
- // 部门人员获取
- $employees = Employee::where([['org_id', 'in', $ids], ['state', '=', '在职'], ['uid', '<>', 0]])->column('org_id', 'id');
- // 员工id
- $ids = array_keys($employees);
- }
- $state2 = CustomerVisitLog::changeState('待确认', 'chaos');
- $state3 = CustomerVisitLog::changeState('已到访', 'chaos');
- $state4 = CustomerVisitLog::changeState('已交定', 'chaos');
- $state5 = CustomerVisitLog::changeState('已量房', 'chaos');
- $state8 = CustomerVisitLog::changeState('已到场', 'chaos');
- $state6 = CustomerVisitLog::changeState('已签单', 'chaos');
- $state15 = CustomerVisitLog::changeState('已卖卡', 'chaos');
- //查询时间之前的见面数量
- $beforeCustomersId = [];
- if ($beforeCondition) {
- $vis_where = [['state', 'in', array_merge($state3, $state5, $state8)], ['addtime', '<', $beforeCondition]];
- $beforeCustomers = Customer::with([
- 'visitLog' => function ($query) use ($vis_where) {
- $query->where($vis_where)->field('customer_id,state');
- }
- ])->where(function ($query) {
- $not_sure = Customer::changeState('待确认', 'chaos');
- $or1[] = ['crm_res_id', 'null', null];
- $or2[] = ['crm_res_id', 'not null', null];
- $or2[] = ['state', 'not in', $not_sure];
- $query->whereOr([$or1, $or2]);
- })->where([$typeCondition])->field('id,employee_id,state')->select()->toArray();
- foreach ($beforeCustomers as $v) {
- foreach ($v['visitLog'] as $va) {
- if (in_array($va['state'], array_merge($state3, $state5, $state8))) {
- $beforeCustomersId[] = $v['id'];
- }
- }
- }
- }
- $vis_where = [$startCondition, $endCondition, ['state', 'in', array_merge($state2, $state3, $state4, $state5, $state6, $state8, $state15)]];
- $customers = Customer::with(['visitLog' => function ($query) use ($vis_where) {
- $query->where($vis_where)->field('customer_id,addtime,state,money')->order('addtime desc');
- }])->where(function ($query) {
- $not_sure = Customer::changeState('待确认', 'chaos');
- $or1[] = ['crm_res_id', 'null', null];
- $or2[] = ['crm_res_id', 'not null', null];
- $or2[] = ['state', 'not in', $not_sure];
- $query->whereOr([$or1, $or2]);
- })->where([$typeCondition])->field('id,employee_id,state')->select();
- // 无效客户数
- $no_where = [
- ['employee_id', 'in', $ids],
- $startCondition,
- $endCondition
- ];
- $no_valid_customer = CustomerInvalidLog::where($no_where)->column('customer_id,org_id,employee_id');
- $customerVisitData = [];
- $checkDaraIds = [];
- $measureMumIds = []; //量房数
- $shopNumIds = []; //到店数
- $meetNumIds = []; //见面数
- $depositNumIds = []; //订金数-签单数
- $signedNumIds = []; //签单数-转单数
- $unconfirmNumIds = []; //待确认
- $maikaNumIds = []; //卖卡
- foreach ($customers as $c) {
- if (!isset($customerVisitData[$c['employee_id']])) {
- $customerVisitData[$c['employee_id']] = ['maika_num' => 0, 'effective_total_number' => 0, 'signed_total_money' => 0, 'deposit_total_money' => 0, 'signed_num' => 0, 'deposit_num' => 0, 'unconfirm_num' => 0, 'shop_num' => 0, 'measure_num' => 0, 'meet_num' => 0, 'customer_num' => 0, 'customer' => []];
- }
- $state = [];
- $signed_total_money = [];
- $deposit_total_money = [];
- foreach ($c['visitLog'] as $v) {
- $state[$v['state']][] = $v;
- }
- foreach ($state as $k => $v) {
- if (in_array($k, $state15) && !in_array($c['id'], $maikaNumIds)) {
- $customerVisitData[$c['employee_id']]['maika_num']++;
- $measureMumIds[] = $c['id'];
- }
- if (in_array($k, $state6) && !in_array($c['id'], $signedNumIds)) {
- $customerVisitData[$c['employee_id']]['signed_num']++;
- $signedNumIds[] = $c['id'];
- $signed_total_money[] = $v[0]['money'];
- }
- if (in_array($k, $state4) && !in_array($c['id'], $depositNumIds)) {
- $customerVisitData[$c['employee_id']]['deposit_num']++;
- $depositNumIds[] = $c['id'];
- $deposit_total_money[] = $v[0]['money'];
- }
- if (in_array($k, $state2) && !in_array($c['id'], $unconfirmNumIds)) {
- $customerVisitData[$c['employee_id']]['unconfirm_num']++;
- $unconfirmNumIds[] = $c['id'];
- }
- if (in_array($k, $state3) && !in_array($c['id'], $shopNumIds)) {
- $customerVisitData[$c['employee_id']]['shop_num']++;
- $shopNumIds[] = $c['id'];
- }
- if (in_array($k, $state5) && !in_array($c['id'], $measureMumIds)) {
- $customerVisitData[$c['employee_id']]['measure_num']++;
- $measureMumIds[] = $c['id'];
- }
- if (!in_array($c['id'], $beforeCustomersId) && in_array($k, array_merge($state3, $state4, $state5, $state6, $state8)) && !in_array($c['id'], $meetNumIds)) {
- $customerVisitData[$c['employee_id']]['meet_num']++;
- $meetNumIds[] = $c['id'];
- }
- if (!in_array($c['id'], $checkDaraIds) && in_array($k, array_merge($state3, $state4, $state5, $state6, $state8, $state15))) {
- $customerVisitData[$c['employee_id']]['effective_total_number']++;
- $checkDaraIds[] = $c['id'];
- }
- }
- $customerVisitData[$c['employee_id']]['signed_total_money'] += array_sum($signed_total_money);
- $customerVisitData[$c['employee_id']]['deposit_total_money'] += array_sum($deposit_total_money);
- $customerVisitData[$c['employee_id']]['customer'][] = $c['id'];
- }
- $no_employee = [];
- foreach ($no_valid_customer as $k => $v) {
- $no_employee[$v['employee_id']][] = $v['customer_id'];
- }
- // 赋值无效客户
- foreach ($customerVisitData as $k => $v) {
- if (isset($no_employee[$k])) {
- $customer_ids = array_unique(array_merge($v['customer'], $no_employee[$k]));
- $customerVisitData[$k]['customer_num'] = count($customer_ids);
- } else {
- $customerVisitData[$k]['customer_num'] = count($customerVisitData[$k]['customer']);
- }
- }
- if ($type == 'org') {
- $visitData = [];
- foreach ($employees as $empId => $org_id) {
- if (!isset($visitData[$org_id])) $visitData[$org_id] = ['maika_num' => 0, 'effective_total_number' => 0, 'signed_total_money' => 0, 'deposit_total_money' => 0, 'signed_num' => 0, 'deposit_num' => 0, 'unconfirm_num' => 0, 'shop_num' => 0, 'measure_num' => 0, 'employee_num' => 0, 'meet_num' => 0, 'customer_num' => 0];
- if (isset($customerVisitData[$empId])) {
- $visitData[$org_id]['maika_num'] += $customerVisitData[$empId]['maika_num'];
- $visitData[$org_id]['effective_total_number'] += $customerVisitData[$empId]['effective_total_number'];
- $visitData[$org_id]['signed_total_money'] += $customerVisitData[$empId]['signed_total_money'];
- $visitData[$org_id]['deposit_total_money'] += $customerVisitData[$empId]['deposit_total_money'];
- $visitData[$org_id]['signed_num'] += $customerVisitData[$empId]['signed_num'];
- $visitData[$org_id]['deposit_num'] += $customerVisitData[$empId]['deposit_num'];
- $visitData[$org_id]['unconfirm_num'] += $customerVisitData[$empId]['unconfirm_num'];
- $visitData[$org_id]['shop_num'] += $customerVisitData[$empId]['shop_num'];
- $visitData[$org_id]['measure_num'] += $customerVisitData[$empId]['measure_num'];
- $visitData[$org_id]['meet_num'] += $customerVisitData[$empId]['meet_num'];
- $visitData[$org_id]['customer_num'] += $customerVisitData[$empId]['customer_num'];
- }
- $visitData[$org_id]['employee_num']++;
- }
- return ['data' => $visitData, 'eid' => $ids];
- }
- return ['data' => $customerVisitData, 'eid' => $ids];
- }
- /**
- * 跟进情况统计
- *
- * @return string
- */
- private function followUpData($param)
- {
- $startCondition = ['addtime', '>', date('Y-m-d H:i:s', 0)];
- $endCondition = ['addtime', '<', date('Y-m-d H:i:s')];
- if (!empty($param['start_date'])) {
- $startCondition = ['addtime', '>', date('Y-m-d H:i:s', strtotime($param['start_date']))];
- }
- if (!empty($param['end_date'])) {
- $endCondition = ['addtime', '<', date('Y-m-d', strtotime($param['end_date'])) . ' 23:59:59'];
- }
- // 客户等级获取(该项在系统中被写死,如需改变需调查后调整)
- if (!empty($param['level'])) {
- $level = [$param['level']];
- $levelCondition = ['level', '=', $param['level']];
- } else {
- $level = ['A', 'B', 'C'];
- $levelCondition = ['level', 'in', $level];
- }
- $param['page'] = !empty($param['page']) ? $param['page'] : 1;
- $param['limit'] = !empty($param['limit']) ? $param['limit'] : 10;
- /** 不同数据内容整理 */
- if (empty($param['type']) || $param['type'] == 1) {
- $group = 'org_id';
- // 部门名称列表获取
- $data = Org::where([['path', 'like', $this->root_id . '-%']])->page($param['page'], $param['limit'])->column('id,name as org_name');
- // 部门id
- $orgIdList = array_column($data, 'id');
- // 员工查找
- $employees = Employee::where([['org_id', 'in', $orgIdList], ['state', '=', '在职'], ['uid', '<>', 0]])->column('org_id', 'id');
- // 员工id
- $employeeIdList = array_keys($employees);
- // 查询条件
- $typeCondition = ['org_id', 'in', $orgIdList];
- $count = Org::where([['path', 'like', $this->root_id . '-%']])->count();
- } else {
- $group = 'employee_id';
- $orgCondition = [];
- if (!empty($param['org_id'])) $orgCondition = ['org_id', '=', $param['org_id']];
- // 部门人员获取
- $data = Employee::where([['root_id', '=', $this->root_id], ['state', '=', '在职'], ['uid', '<>', 0], $orgCondition])->page($param['page'], $param['limit'])->column('id, org_id, name');
- // 员工id
- $employeeIdList = array_column($data, 'id');
- // 查询条件
- $typeCondition = ['employee_id', 'in', $employeeIdList];
- // 员工部门获取
- $orgs = Org::where([['path', 'like', $this->root_id . '-%']])->column('name', 'id');
- foreach ($data as &$c) {
- $c['org_name'] = $orgs[$c['org_id']];
- }
- $count = Employee::where([['root_id', '=', $this->root_id], ['state', '=', '在职'], ['uid', '<>', 0], $orgCondition])->count();
- }
- // 客户数据获取
- $customerData = Customer::where([$typeCondition, $startCondition, $endCondition, $levelCondition, ['state', '<>', '无效']])
- ->column("
- id,
- $group,
- level,
- state,
- deposit_money,
- signed_money
- ");
- // 查询访问记录
- $customerVisitData = CustomerVisitLog::where([['employee_id', 'in', $employeeIdList], $startCondition, $endCondition])
- ->group('customer_id')->column("
- count(if(state in ('" . implode('\',\'', CustomerVisitLog::changeState('已到店', 'chaos')) . "'), '1', null)) as shop_num,
- count(if(state in ('" . implode('\',\'', CustomerVisitLog::changeState('已量房', 'chaos')) . "'), '1', null)) as measure_num
- ", 'customer_id');
- // 数据整理 结构【分组名ID】【客户类型】{num,confirm_num,shop_num,measure_num,deposit_num,signed_num}
- $clearData = [];
- foreach ($customerData as $customer) {
- if (!isset($clearData[$customer[$group]][$customer['level']]))
- $clearData[$customer[$group]][$customer['level']] = [
- 'level' => $customer['level'],
- 'num' => 0,
- 'confirm_num' => 0,
- 'shop_num' => 0,
- 'measure_num' => 0,
- 'deposit_num' => 0,
- 'signed_num' => 0
- ];
- $clearData[$customer[$group]][$customer['level']]['num'] += 1;
- if (in_array($customer['state'], Customer::changeState('待确认', 'chaos')))
- $clearData[$customer[$group]][$customer['level']]['confirm_num'] += 1;
- if (isset($customerVisitData[$customer['id']])) {
- ($customerVisitData[$customer['id']]['shop_num'] > 0 || in_array($customer['state'], Customer::changeState('确认到店', 'chaos'))) ?? $clearData[$customer[$group]][$customer['level']]['shop_num'] += 1;
- ($customerVisitData[$customer['id']]['measure_num'] > 0 || in_array($customer['state'], Customer::changeState('确认量房', 'chaos'))) ?? $clearData[$customer[$group]][$customer['level']]['measure_num'] += 1;
- }
- if ($customer['deposit_money'] > 0 || in_array($customer['state'], Customer::changeState('交定', 'chaos')))
- $clearData[$customer[$group]][$customer['level']]['deposit_num'] += 1;
- if ($customer['signed_money'] > 0 || in_array($customer['state'], Customer::changeState('签单', 'chaos')))
- $clearData[$customer[$group]][$customer['level']]['signed_num'] += 1;
- }
- // 数据二次处理
- $dealData = [];
- foreach ($data as &$i) {
- if (isset($i['org_name'])) $i['org_name'] = '<a href="follow_up.html?type=2&org_id=' . $i['id'] . '">' . $i['org_name'] . '</a>';
- foreach ($level as $n => $l) {
- if (isset($clearData[$i['id']]) && isset($clearData[$i['id']][$l])) {
- $item = $clearData[$i['id']][$l];
- $item['unshop_num'] = $item['num'] - $item['shop_num'];
- } else {
- $item = [
- 'level' => $l,
- 'num' => 0,
- 'confirm_num' => 0,
- 'shop_num' => 0,
- 'measure_num' => 0,
- 'deposit_num' => 0,
- 'signed_num' => 0,
- 'unshop_num' => 0
- ];
- }
- $dealData[] = array_merge($i, $item);
- }
- }
- return ['code' => 0, 'data' => $dealData, 'count' => $count];
- }
- /**
- * 房屋信息统计
- *
- * @return string
- */
- private function houseData()
- {
- return ['code' => 0, 'data' => [], 'count' => 0];
- }
- /**
- * 客户来源渠道统计
- *
- * @return string
- */
- private function sourceData()
- {
- return ['code' => 0, 'data' => [], 'count' => 0];
- }
- /**
- * 线索统计
- *
- * @return string
- */
- public function clueData($param)
- {
- $startCondition = ['addtime', '>', date('Y-m-d H:i:s', 0)];
- $endCondition = ['addtime', '<', date('Y-m-d H:i:s')];
- //2023-02-15页面逻辑修改 传参方式改为 start_date=2023/2/15 - 2023/2/15
- if (!empty($param['start_date'])) {
- $count_dates = explode(' - ', $param['start_date']);
- $param['start_date'] = date('Y-m-d', strtotime($count_dates[0]));
- $param['end_date'] = date('Y-m-d', strtotime($count_dates[1]));
- $startCondition = ['addtime', '>', date('Y-m-d H:i:s', strtotime($param['start_date']))];
- }
- if (!empty($param['end_date'])) {
- $endCondition = ['addtime', '<', date('Y-m-d', strtotime($param['end_date'])) . ' 23:59:59'];
- }
- $param['page'] = !empty($param['page']) ? $param['page'] : 1;
- $param['limit'] = !empty($param['limit']) ? $param['limit'] : 10;
- /** 不同数据内容整理 */
- if (empty($param['type']) || $param['type'] == 1) {
- // 部门名称列表获取
- $org_where = [['path', 'like', $this->root_id . '-%']];
- if (!empty($param['org_id'])) {
- $org = Org::where([['id', '=', $param['org_id']]], ['path', 'like', $this->root_id . '-%'])->find();
- unset($org_where);
- $org_where[] = ['path', 'like', $org['path'] . '%'];
- }
- $data = Org::where($org_where)->page($param['page'], $param['limit'])->column('id,name as org_name');
- $count = Org::where($org_where)->count();
- foreach ($data as &$i) {
- $employee_id = Employee::where([['root_id', '=', $this->root_id], ['state', '=', '在职'], ['uid', '<>', 0], ['org_id', '=', $i['id']]])->column('id');
- $clueData = [];
- if (isset($employee_id) && $employee_id) {
- $typeConditionOrg = ['org_id', '=', $i['id']];
- $typeConditionEmployee = ['employee_id', 'in', $employee_id];
- $clueData = CustomerClue::where([$startCondition, $endCondition, $typeConditionOrg, $typeConditionEmployee])->field("count(*) as num,count(if(state=1,1,null)) as valid_num,count(if(state=2,1,null)) as invalid_num")->find();
- }
- $i['org_name'] = '<a href="clue.html?type=2&org_id=' . $i['id'] . '">' . $i['org_name'] . '</a>';
- if (isset($clueData) && $clueData) {
- $i['num'] = $clueData['num'];
- $i['valid_num'] = $clueData['valid_num'];
- $i['invalid_num'] = $clueData['invalid_num'];
- } else {
- $i['num'] = 0;
- $i['valid_num'] = 0;
- $i['invalid_num'] = 0;
- }
- $i['valid_lv'] = $i['num'] == 0 ? '0%' : round($i['valid_num'] / $i['num'], 2) * 100 . '%';
- }
- } else {
- // 部门人员获取
- $data = Employee::where([['root_id', '=', $this->root_id], ['state', '=', '在职'], ['uid', '<>', 0], ['org_id', '=', $param['org_id']]])->page($param['page'], $param['limit'])->column('id, org_id, name');
- // 员工id
- $employeeIdList = array_column($data, 'id');
- $orgs = Org::where([['path', 'like', $this->root_id . '-%']])->column('name', 'id');
- foreach ($data as &$c) {
- $c['org_name'] = $orgs[$c['org_id']];
- }
- $count = Employee::where([['root_id', '=', $this->root_id], ['state', '=', '在职'], ['uid', '<>', 0], ['org_id', '=', $param['org_id']]])->count();
- //查询部门下的员工保证数据里外一致
- $typeConditionOrg = ['org_id', 'in', $param['org_id']];
- $typeConditionEmployee = ['employee_id', 'in', $employeeIdList];
- $clueData = CustomerClue::where([$startCondition, $endCondition, $typeConditionOrg, $typeConditionEmployee])->field("employee_id,count(id) as num,count(if(state=1,1,null)) as valid_num,count(if(state=2,1,null)) as invalid_num")->group('employee_id')->select()->toArray();
- $clueData = array_combine(array_column($clueData, 'employee_id'), $clueData);
- // 数据处理
- foreach ($data as &$i) {
- if (isset($clueData[$i['id']])) {
- $i['num'] = $clueData[$i['id']]['num'];
- $i['valid_num'] = $clueData[$i['id']]['valid_num'];
- $i['invalid_num'] = $clueData[$i['id']]['invalid_num'];
- } else {
- $i['num'] = 0;
- $i['valid_num'] = 0;
- $i['invalid_num'] = 0;
- }
- $i['valid_lv'] = $i['num'] == 0 ? '0%' : round($i['valid_num'] / $i['num'], 2) * 100 . '%';
- }
- }
- return ['code' => 0, 'data' => $data, 'count' => $count];
- }
- //客户扩展字段转换
- public function emp_extfield_change($customerList)
- {
- $chmod = new CustomerLogic;
- $list = CustomerPortraitField::with(['select'])->where([['root_id', '=', $this->root_id], ['pid', '<>', 0]])->select()->toArray();
- foreach ($customerList as $key => $val) {
- $new = '';
- if (!empty($val['ext']) && $val['ext'] != 'null') {
- //$extdata=get_object_vars($val['ext']);
- $extdata = json_decode($val['ext'], true);
- if (isset($extdata['ext1'])) {
- $new = $chmod->old_data_saves($val, $list);
- } else {
- $new = $chmod->new_data_saves($val, $extdata, $list);
- }
- } else {
- $new = $chmod->no_ext_saves($val, $list);
- }
- $new = array_combine(array_column($new, 'keyname'), array_column($new, 'valname'));
- //$customerList[$key]['newext']=$new;
- $customerList[$key]['ext'] = $new;
- }
- return $customerList;
- }
- /**
- * 客户跟进数据统计
- */
- public function customer_statistics($page, $limit, $getTotal = false)
- {
- $param = $this->request->only(['sdate' => '', 'edate' => '', 'org_id' => 0, 'add_wechat_time']);
- // 获取部门id
- $root_id = request()->employee->root_id;
- $orgs = Org::where([['path', 'like', $root_id . '-%']])->column('name,id,pid,level,path', 'id');
- // 部门领导获取
- $leaders = Employee::with('org')->where([['root_id', '=', $this->root_id], ['state', '=', '在职'], ['is_manager', '=', '1'], ['uid', '<>', 0]])->select();
- // 领导结构修改
- $leadersData = [];
- foreach ($leaders as $l) {
- if (isset($leadersData[$l['org_id']])) {
- $leadersData[$l['org_id']]['leaders'][] = $l['name'];
- $leadersData[$l['org_id']]['leaders_ids'][] = $l['id'];
- } else {
- $leadersData[$l['org_id']] = [
- 'org_name' => $l['org']['name'],
- 'level' => $l['org']['level'],
- 'path' => $l['org']['path'],
- 'leaders_ids' => [
- $l['id']
- ],
- 'leaders' => [
- $l['name']
- ]
- ];
- }
- }
- // 补充没领导的部门
- foreach ($orgs as $k => $item) {
- if (!isset($leadersData[$k])) {
- $leadersData[$k] = [
- 'org_name' => $item['name'],
- 'level' => $item['level'],
- 'path' => $item['path'],
- 'leaders' => [],
- 'leaders_ids' => []
- ];
- }
- }
- // 查询最近访问的客户
- $where = [];
- if ($param['org_id']) {
- //查询本部门下面是否有部门
- $childorg = orgSubIds($param['org_id']);
- $where[] = ['org_id|customer_org_id', 'in', $childorg];
- // $where[] = ['org_id', '=', $param['org_id']];
- } else {
- $where[] = ['org_id', 'in', array_keys($orgs)];
- }
- if ($param['sdate']) {
- $param['sdate'] = date('Y-m-d', strtotime($param['sdate']));
- $where[] = ['addtime', '>=', $param['sdate'] . ' 00:00:00'];
- }
- if ($param['edate']) {
- $param['edate'] = date('Y-m-d', strtotime($param['edate']));
- $where[] = ['addtime', '<=', $param['edate'] . ' 23:59:59'];
- }
- // 查询排除的部门
- $sheji = Org::where([['path', 'like', $this->root_id . '-%'], ['name', '=', '设计部']])->value('id');
- $xiaoshou = Org::where([['path', 'like', $this->root_id . '-%'], ['name', '=', '市场部']])->value('id');
- $fanweinei = Org::whereOr([
- [['path', 'like', $this->root_id . '-%'], ['path', 'like', $this->root_id . '-' . $sheji . '-%']],
- [['path', 'like', $this->root_id . '-%'], ['path', 'like', $this->root_id . '-' . $xiaoshou . '-%']],
- ])->column('id');
- $searchEmployeeIdList = Employee::where([['org_id', 'in', $fanweinei]])->column('id');
- //如果有部门筛选把员工控制在本部门
- if ($param['org_id']) $searchEmployeeIdList = Employee::where([['org_id', 'in', $childorg]])->column('id');
- //$where[] = ['employee_id', 'in', $searchEmployeeIdList];
- $where[] = ['customer_employee_id', 'in', $searchEmployeeIdList];
- //2022-10-31辛居尚重11月1号开始正式使用
- $where[] = ['addtime', '>', date('2022-10-31 23:59:59')];
- if (!empty($param['add_wechat_time'])) {
- $newtime = explode(' - ', $param['add_wechat_time']);
- $sdate = strtotime($newtime[0]);
- $edate = strtotime($newtime[1]);
- $wechat_count = [];
- $wechat_count = Customer::where([['ext', 'not null', ''], ['ext', '<>', ''], ['add_wechat_time', '>=', date('Y-m-d', $sdate)], ['add_wechat_time', '<=', date('Y-m-d', $edate)]])->column('id');
- $cids = CustomerVisitLog::where($where)->group('customer_id')->column('customer_id');
- $wechat_count = array_intersect($cids, $wechat_count);
- $where[] = ['customer_id', 'in', $wechat_count];
- }
- $total = CustomerVisitLog::field("customer_id, DATE_FORMAT(addtime,'%Y-%m-%d') as date")->where($where)->group('customer_id,date')->count();
- $searchObject = CustomerVisitLog::field("customer_id, DATE_FORMAT(addtime,'%Y-%m-%d') as date, max(addtime) as addtime, SUM(number_of_visitors) as number_of_visitors, SUM(measure_room_img_type='量房图片') as measure_type1, SUM(measure_room_img_type='量房报告图片') as measure_type2, SUM(measure_room_img_type='客户需求表') as measure_type3,GROUP_CONCAT(aid) as aid_list")->where($where)->order('date desc,addtime desc')->group('customer_id,date');
- if ($getTotal == false) $searchObject->page($page, $limit);
- $lastVisitCustomerList = $searchObject->select();
- // 获取客户信息
- $customerIdList = array_unique(array_column(empty($lastVisitCustomerList) ? [] : $lastVisitCustomerList->toArray(), 'customer_id'));
- $customerList = Customer::with(['employee', 'designer'])->where([['id', 'in', $customerIdList]])->field('id,name,designer_id,employee_id,phone,phone1,phone2,square,community_name,ext,house_delivery_time,plan_deco_time,source_id,house_type,package_id,level,age_range,house_type,deco_style,source_id')->select();
- $customerList1 = CustomerRecycle::with(['employee', 'designer'])->where([['customer_id', 'in', $customerIdList]])->field('customer_id as id,name,designer_id,employee_id,phone,phone1,phone2,square,community_name,ext,house_delivery_time,plan_deco_time,source_id,house_type,package_id,level,age_range,house_type,deco_style,source_id')->select();
- $customerList2 = CustomerDropPool::with(['employee', 'designer'])->where([['customer_id', 'in', $customerIdList]])->field('customer_id as id,name,designer_id,employee_id,phone,phone1,phone2,square,community_name,ext,house_delivery_time,plan_deco_time,source_id,house_type,package_id,level,age_range,house_type,deco_style,source_id')->select();
- $customerList = array_merge($customerList->toArray(), $customerList1->toArray(), $customerList2->toArray());
- $customerList = array_combine(array_column($customerList, 'id'), $customerList);
- $customerList = $this->emp_extfield_change($customerList);
- // 查询爆品产品
- $packageId = implode(',', array_column($customerList, 'package_id'));
- $package = CustomerPackage::where([['id', 'in', $packageId]])->column('total_price', 'id');
- // 获取公司名称
- $companyName = Company::where([['root_id', '=', $this->root_id]])->value('company_name');
- // 公司负责人获取
- // $companyLeader = Employee::where([['root_id', '=', $this->root_id], ['state', '=', '在职'], ['is_manager', '=', '1'], ['org_id', '=', $this->root_id], ['uid', '<>', 0]])->column('name');
- // 来源
- $sourseIdList = array_column($customerList, 'source_id');
- $sourseList = CustomerSource::where([['id', 'in', $sourseIdList]])->column('source', 'id');
- $num = ($page - 1) * $limit + 1;
- // 处理数据
- $data = [];
- foreach ($lastVisitCustomerList as $c) {
- $item = [
- 'key' => $num,
- 'customer_id' => $c['customer_id'],
- ];
- if (!isset($customerList[$c['customer_id']])) {
- $data[] = $item;
- $num++;
- continue;
- }
- list($Y, $m, $d) = explode('-', $c['date']);
- $leader_arr = ['941' => '罗镐', '1847' => '刘有凤']; //馨居尚,菡萏怡景,部门负责人
- $item = [
- 'key' => $num,
- 'customer_name' => $customerList[$c['customer_id']]['name'],
- 'date' => $Y . '年' . $m . '月' . $d . '日',
- 'addtime' => $c['addtime'],
- 'company_name' => $companyName,
- 'leader' => !empty($leader_arr[$this->root_id]) ? $leader_arr[$this->root_id] : '罗镐',
- 'community_name' => $customerList[$c['customer_id']]['community_name'],
- // 'measure_type1' => $c['measure_type1'] ? '√' : '',
- // 'measure_type2' => $c['measure_type2'] ? '√' : '',
- // 'measure_type3' => $c['measure_type3'] ? '√' : '',
- 'measure_room_store' => $this->measureRoomStore($c['date'], $c['customer_id']),
- 'number_of_visitors' => $c['number_of_visitors'] == 0 ? '' : $c['number_of_visitors'],
- 'area' => $c['area'],
- //'ext39' => $customerList[$c['customer_id']]['ext']['房屋位置'],
- 'ext39' => $customerList[$c['customer_id']]['ext']['house_location'],
- //'talking_about_single_time' => isset($customerList[$c['customer_id']]['ext']['谈单时长']) ? $customerList[$c['customer_id']]['ext']['谈单时长'] : 0,
- 'talking_about_single_time' => isset($customerList[$c['customer_id']]['ext']['talking_about_single_time']) ? $customerList[$c['customer_id']]['ext']['talking_about_single_time'] : 0,
- 'source' => isset($sourseList[$customerList[$c['customer_id']]['source_id']]) ? $sourseList[$customerList[$c['customer_id']]['source_id']] : '',
- 'square' => $customerList[$c['customer_id']]['square'],
- //'ext42' => $customerList[$c['customer_id']]['ext']['门牌单元号']
- 'ext42' => $customerList[$c['customer_id']]['ext']['unit_number']
- ];
- //量房图片类型
- $where_img_type = [];
- $where_img_type[] = ['addtime', 'like', '%' . $c['date'] . '%'];
- $where_img_type[] = ['customer_id', '=', $c['customer_id']];
- $where_img_type[] = CustomerVisitLog::changeState(['state', '=', '确认量房']);
- $str = CustomerVisitLog::where($where_img_type)->column('measure_room_img_type');
- $str = $str ? implode(',', $str) : '';
- $item['measure_type2'] = ($str && (strpos($str, '量房图片') !== false || strpos($str, '量房报告图片') !== false || strpos($str, '量房验房报告') !== false)) ? '√' : '';
- $item['measure_type3'] = ($str && strpos($str, '客户需求图片') !== false) ? '√' : '';
- // 计算交房相差月份
- $houseDeliveryTime = strtotime($customerList[$c['customer_id']]['house_delivery_time']);
- $month = (date('Y', $houseDeliveryTime) - date('Y')) * 12 + date('m', $houseDeliveryTime) - date('m');
- $type = '0';
- // if ($customerList[$c['customer_id']]['ext']['加微类型'] == '常规加微') {
- // $type = '1';
- // } elseif ($customerList[$c['customer_id']]['ext']['加微类型'] == '社群加微') {
- // $type = '2';
- // }
- $item['add_wechat_time'] = $customerList[$c['customer_id']]['ext']['add_wechat_time'];
- if ($customerList[$c['customer_id']]['ext']['add_wechat_type'] == '常规加微') {
- $type = '1';
- } elseif ($customerList[$c['customer_id']]['ext']['add_wechat_type'] == '社群加微') {
- $type = '2';
- } elseif ($customerList[$c['customer_id']]['ext']['add_wechat_type'] == '历史加微') {
- $type = '3';
- }
- if ($type !== '0') {
- $item['house_type' . $type] = in_array($customerList[$c['customer_id']]['house_type'], ['现房', '二手房']) ? '√' : '';
- if ($item['house_type' . $type] != '√' && !empty($customerList[$c['customer_id']]['house_delivery_time'])) {
- $item['delivery_month' . $type . '_1'] = $month <= 3 ? '√' : '';
- $item['delivery_month' . $type . '_2'] = $month > 3 && $month <= 6 ? '√' : '';
- $item['delivery_month' . $type . '_3'] = $month > 6 && $month <= 12 ? '√' : '';
- $item['delivery_month' . $type . '_4'] = $month > 12 ? '√' : '';
- } else {
- $item['delivery_month' . $type . '_1'] = '';
- $item['delivery_month' . $type . '_2'] = '';
- $item['delivery_month' . $type . '_3'] = '';
- $item['delivery_month' . $type . '_4'] = '';
- }
- }
- // 设计师
- if (!empty($customerList[$c['customer_id']]['designer'])) {
- $designerOrgId = $customerList[$c['customer_id']]['designer']['org_id'];
- $item['designer_name'] = $customerList[$c['customer_id']]['designer']['name'];
- $item['designer_org'] = $orgs[$designerOrgId]['name'];
- $item['designer_leader'] = isset($leadersData[$designerOrgId]) ? implode(',', $leadersData[$designerOrgId]['leaders']) : '';
- $path = $leadersData[$designerOrgId]['path'];
- $pathList = array_filter(explode('-', $path));
- foreach ($pathList as $od) {
- if (strstr($leadersData[$od]['org_name'], '部') !== false && $leadersData[$od]['org_name'] != '设计部') {
- $level = 3;
- } else {
- $level = $leadersData[$od]['level'];
- }
- if (isset($item['employee_org_level' . $level])) $level++;
- $item['designer_leader_level' . $level] = implode(',', $leadersData[$od]['leaders']);
- $item['designer_org_level' . $level] = $leadersData[$od]['org_name'];
- }
- } else {
- $item['designer_name'] = $item['designer_org'] = $item['designer_leader'] = '';
- }
- // 员工
- if (!empty($customerList[$c['customer_id']]['employee'])) {
- $employeeOrgId = $customerList[$c['customer_id']]['employee']['org_id'];
- $item['employee_name'] = $customerList[$c['customer_id']]['employee']['name'];
- $item['employee_org'] = $orgs[$employeeOrgId]['name'];
- $item['employee_leader'] = implode(',', $leadersData[$employeeOrgId]['leaders']);
- $path = $leadersData[$employeeOrgId]['path'];
- $pathList = array_filter(explode('-', $path));
- foreach ($pathList as $od) {
- if (strstr($leadersData[$od]['org_name'], '区中区') !== false) {
- $level = 3;
- } elseif (strstr($leadersData[$od]['org_name'], '中心') !== false) {
- $level = 4;
- } elseif (strstr($leadersData[$od]['org_name'], '区') !== false) {
- $level = 2;
- } else {
- $level = $leadersData[$od]['level'];
- }
- if (isset($item['employee_org_level' . $level])) $level++;
- // $level = $leadersData[$od]['level'];
- $item['employee_leader_level' . $level] = implode(',', $leadersData[$od]['leaders']);
- $item['employee_org_level' . $level] = $leadersData[$od]['org_name'];
- }
- // 查询直属领导是否跟踪过
- // 获取直属领导id
- $leaderIdList = $leadersData[$employeeOrgId]['leaders_ids'];
- $query = [];
- $query[] = ['employee_id', 'in', $leaderIdList];
- $query[] = ['addtime', 'like', $c['date'] . '%'];
- $query[] = ['customer_id', '=', $c['customer_id']];
- $item['leader_visit'] = !CustomerVisitLog::where($query)->findOrEmpty()->isEmpty() && ($item['measure_type2'] == '√' || $item['measure_type3'] == '√') ? "√" : "";
- } else {
- $item['employee_name'] = $item['employee_org'] = $item['employee_leader'] = '';
- $item['leader_visit'] = '';
- }
- // 量房验房
- $item['measure_type1'] = ($item['leader_visit'] == '√' || $item['measure_type2'] == '√' || $item['measure_type3'] == '√') ? '√' : '';
- // 手机号
- $phoneArr = array_filter([$customerList[$c['customer_id']]['phone'], $customerList[$c['customer_id']]['phone1'], $customerList[$c['customer_id']]['phone2']]);
- $item['phone'] = substr_replace(array_shift($phoneArr), '******', 3, 6);
- // 建群情况
- //$jianqun = explode(',', $customerList[$c['customer_id']]['ext']['建群情况']);
- $jianqun = explode(',', $customerList[$c['customer_id']]['ext']['group_building']);
- $item['ext35_1'] = in_array('1对1小群', $jianqun) || in_array('一对一小群', $jianqun) ? '√' : '';
- $item['ext35_2'] = in_array('临时大群', $jianqun) ? '√' : '';
- $item['ext35_3'] = in_array('社群', $jianqun) ? '√' : '';
- // 直播
- //$zhibo = explode(',', $customerList[$c['customer_id']]['ext']['直播情况']);
- $zhibo = explode(',', $customerList[$c['customer_id']]['ext']['live_broadcast']);
- $item['ext36_1'] = in_array('一对一直播', $zhibo) || in_array('1对1业务直播', $zhibo) ? '√' : '';
- $item['ext36_2'] = in_array('1对1设计直播', $zhibo) ? '√' : '';
- $item['ext36_3'] = in_array('一对多直播', $zhibo) ? '√' : '';
- // $item['ext37_1'] = $item['ext36_1'] == '√' ? $customerList[$c['customer_id']]['ext']['1对1业务人员'] : '';
- // $item['ext37_2'] = $item['ext36_2'] == '√' ? $customerList[$c['customer_id']]['ext']['1对1设计人员'] : '';
- // $item['ext37_3'] = $item['ext36_3'] == '√' ? $customerList[$c['customer_id']]['ext']['直播人员'] : '';
- $item['ext37_1'] = $item['ext36_1'] == '√' ? $customerList[$c['customer_id']]['ext']['live_broadcast_business'] : '';
- $item['ext37_2'] = $item['ext36_2'] == '√' ? $customerList[$c['customer_id']]['ext']['live_broadcast_design'] : '';
- $item['ext37_3'] = $item['ext36_3'] == '√' ? $customerList[$c['customer_id']]['ext']['live_broadcast_personnel'] : '';
- // 签单金额
- $condition = [];
- $condition[] = ['addtime', 'like', $c['date'] . '%'];
- $condition[] = ['customer_id', '=', $c['customer_id']];
- $condition1 = $condition;
- $condition2 = $condition;
- $condition1[] = CustomerVisitLog::changeState(['state', '=', '已交定']);
- $condition2[] = CustomerVisitLog::changeState(['state', '=', '已签单']);
- $item['signature_money'] = CustomerVisitLog::where($condition2)->order('addtime desc')->value('money');
- $deposit = CustomerVisitLog::where($condition1)->order('addtime desc')->field('money,deposit_mode')->find();
- if (!empty($deposit)) {
- $deposit['deposit_mode'] !== 0 ? $item['deposit_money1'] = $deposit['money'] : $item['deposit_money2'] = $deposit['money'];
- // 爆品定金
- if ($customerList[$c['customer_id']]['package_id']) {
- $packageIdList = explode(',', $customerList[$c['customer_id']]['package_id']);
- $totalMoney = 0;
- foreach ($packageIdList as $pid) {
- $totalMoney += $package[$pid];
- }
- if ($totalMoney !== 0) {
- $item['package'] = $deposit['money'] / $totalMoney * 100 >= 10 ? '√' : '';
- }
- }
- }
- // 预计装修时间 -> 高意向到店客户
- if (!empty($customerList[$c['customer_id']]['plan_deco_time'])) {
- $planDecoTime = strtotime($customerList[$c['customer_id']]['plan_deco_time']);
- $item['plan_month_day'] = ($planDecoTime - time()) / 86400 < 30 ? '√' : '';
- }
- //活动见面类型
- $query_actmet = [];
- $query_actmet[] = ['addtime', 'like', $c['date'] . '%'];
- $query_actmet[] = ['customer_id', '=', $c['customer_id']];
- $query_actmet[] = ['actmeet_type', '<>', 0];
- $query_actmet[] = CustomerVisitLog::changeState(['state', '=', '已到场']);
- $actmet = CustomerVisitLog::where($query_actmet)->order('addtime desc')->value('actmeet_type');
- if (!empty($actmet)) {
- $item['actmeet_type1'] = ($actmet == 1) ? '√' : '';
- $item['actmeet_type2'] = ($actmet == 2) ? '√' : '';
- $item['actmeet_type3'] = ($actmet == 3) ? '√' : '';
- } else {
- $item['actmeet_type1'] = '';
- $item['actmeet_type2'] = '';
- $item['actmeet_type3'] = '';
- }
- // if (!empty($customerList[$c['customer_id']]['plan_deco_time'])) {
- // $planDecoTime = strtotime($customerList[$c['customer_id']]['plan_deco_time']);
- // $month = (date('Y') - date('Y', $planDecoTime)) * 12 + date('m') - date('m', $planDecoTime);
- // $item['plan_month1'] = $month <= 3 ? '√' : 0;
- // $item['plan_month2'] = $month > 3 && $month <= 6 ? '√' : 0;
- // $item['plan_month3'] = $month > 6 ? '√' : 0;
- // } else {
- // $item['plan_month1'] = '';
- // $item['plan_month2'] = '';
- // $item['plan_month3'] = '';
- // }
- // 到店次数
- $where = [];
- $where[] = ['addtime', '<', $c['date'] . ' 23:59:59'];
- $where[] = ['customer_id', '=', $c['customer_id']];
- $state1 = CustomerVisitLog::changeState('确定到店', 'chaos');
- $where[] = ['state', 'in', $state1];
- $count = CustomerVisitLog::where($where)->count();
- $item['visit_number1'] = $count == 1 ? '√' : '';
- $item['visit_number2'] = $count == 2 ? '√' : '';
- $item['visit_number3'] = $count >= 3 ? '√' : '';
- // 外场活动名
- $aidList = array_unique(explode(',', $c['aid_list']));
- $huodong = ModelActivity::where([['id', 'in', $aidList], ['cate', '=', 1]])->column('title,address');
- $huodongList = [];
- foreach ($huodong as $h) {
- if ($h['address']) {
- $huodongList[] = $h['title'] . '(' . $h['address'] . ')';
- } else {
- $huodongList[] = $h['title'];
- }
- }
- $daochang = CustomerVisitLog::where([['customer_id', '=', $c['customer_id']], ['addtime', 'between', [$c['date'] . ' 00:00:00', $c['date'] . ' 23:59:59']], ['state', 'in', CustomerVisitLog::changeState('已到场', 'chaos')]])->count();
- $item['outfield_activities'] = $daochang ? implode(',', $huodongList) : '';
- // 外场活动转内场新客户 活动前未到店以及后续状态,参加活动后,第一次到店显示
- $item['outfield_infield'] = $this->getIsNewCusomerVisitAfterActivity($c['date'], $c['customer_id']);
- $data[] = $item;
- $num++;
- }
- // if (!empty($param['add_wechat_time'])) {
- // foreach ($data as $key => $val) {
- // if (!empty($val['add_wechat_time'])) {
- // $xin[] = $val;
- // }
- // }
- // $newtime = explode(' - ', $param['add_wechat_time']);
- // $startwetime = str_replace('-', '/', $newtime[0]);
- // $endwetime = str_replace('-', '/', $newtime[1]);
- // foreach ($xin as $key => $val) {
- // if ($val['add_wechat_time'] >= $startwetime && $val['add_wechat_time'] <= $endwetime) {
- // $tian[] = $val;
- // }
- // }
- // $total = count($tian);
- // if ($getTotal == true) {
- // $data = $tian;
- // } else {
- // $data = array_slice($tian, ($param['page'] - 1) * $param['limit'], $param['limit']);
- // }
- // }
- return json(['code' => 0, 'data' => $data, 'count' => $total, 'page' => ceil($total / $limit)]);
- }
- /**
- * 统计部报表数据统计
- */
- public function new_customer_statistics($page, $limit, $getTotal = false)
- {
- $param = $this->request->only(['sdate' => '', 'edate' => '', 'org_id' => 0, 'add_wechat_time']);
- // 获取部门id
- $root_id = request()->employee->root_id;
- $orgs = Org::where([['path', 'like', $root_id . '-%']])->column('name,id,pid,level,path', 'id');
- // 部门领导获取
- $leaders = Employee::with('org')->where([['root_id', '=', $this->root_id], ['state', '=', '在职'], ['is_manager', '=', '1'], ['uid', '<>', 0]])->select();
- // 领导结构修改
- $leadersData = [];
- foreach ($leaders as $l) {
- if (isset($leadersData[$l['org_id']])) {
- $leadersData[$l['org_id']]['leaders'][] = $l['name'];
- $leadersData[$l['org_id']]['leaders_ids'][] = $l['id'];
- } else {
- $leadersData[$l['org_id']] = [
- 'org_name' => $l['org']['name'],
- 'level' => $l['org']['level'],
- 'path' => $l['org']['path'],
- 'leaders_ids' => [
- $l['id']
- ],
- 'leaders' => [
- $l['name']
- ]
- ];
- }
- }
- // 补充没领导的部门
- foreach ($orgs as $k => $item) {
- if (!isset($leadersData[$k])) {
- $leadersData[$k] = [
- 'org_name' => $item['name'],
- 'level' => $item['level'],
- 'path' => $item['path'],
- 'leaders' => [],
- 'leaders_ids' => []
- ];
- }
- }
- // 查询最近访问的客户
- $where = [];
- if ($param['org_id']) {
- //查询本部门下面是否有部门
- $childorg = orgSubIds($param['org_id']);
- $where[] = ['org_id|customer_org_id', 'in', $childorg];
- // $where[] = ['org_id', '=', $param['org_id']];
- } else {
- $where[] = ['org_id', 'in', array_keys($orgs)];
- }
- if ($param['sdate']) {
- $param['sdate'] = date('Y-m-d', strtotime($param['sdate']));
- $where[] = ['addtime', '>=', $param['sdate'] . ' 00:00:00'];
- }
- if ($param['edate']) {
- $param['edate'] = date('Y-m-d', strtotime($param['edate']));
- $where[] = ['addtime', '<=', $param['edate'] . ' 23:59:59'];
- }
- // 查询排除的部门
- $sheji = Org::where([['path', 'like', $this->root_id . '-%'], ['name', '=', '设计部']])->value('id');
- $xiaoshou = Org::where([['path', 'like', $this->root_id . '-%'], ['name', '=', '市场部']])->value('id');
- $fanweinei = Org::whereOr([
- [['path', 'like', $this->root_id . '-%'], ['path', 'like', $this->root_id . '-' . $sheji . '-%']],
- [['path', 'like', $this->root_id . '-%'], ['path', 'like', $this->root_id . '-' . $xiaoshou . '-%']],
- ])->column('id');
- $searchEmployeeIdList = Employee::where([['org_id', 'in', $fanweinei]])->column('id');
- //如果有部门筛选把员工控制在本部门
- if ($param['org_id']) $searchEmployeeIdList = Employee::where([['org_id', 'in', $childorg]])->column('id');
- //$where[] = ['employee_id', 'in', $searchEmployeeIdList];
- $where[] = ['customer_employee_id', 'in', $searchEmployeeIdList];
- //2022-10-31辛居尚重11月1号开始正式使用
- $where[] = ['addtime', '>', date('2022-10-31 23:59:59')];
- //新增加查询记录到前一天的24点
- $sel_endtime = date('Y-m-d');
- if (empty($param['edate']) && empty($param['sdate'])) $where[] = ['addtime', '<', date('Y-m-d', strtotime("$sel_endtime -1 days")).' 23:59:59'];
- if (!empty($param['add_wechat_time'])) {
- $newtime = explode(' - ', $param['add_wechat_time']);
- $sdate = strtotime($newtime[0]);
- $edate = strtotime($newtime[1]);
- $wechat_count = [];
- $wechat_count = Customer::where([['ext', 'not null', ''], ['ext', '<>', ''], ['add_wechat_time', '>=', date('Y-m-d', $sdate)], ['add_wechat_time', '<=', date('Y-m-d', $edate)]])->column('id');
- $cids = CustomerVisitLog::where($where)->group('customer_id')->column('customer_id');
- $wechat_count = array_intersect($cids, $wechat_count);
- $where[] = ['customer_id', 'in', $wechat_count];
- }
- //去掉不需要的跟进记录
- $state1 = CustomerVisitLog::changeState('已到店', 'chaos');
- $state2 = CustomerVisitLog::changeState('已到场', 'chaos');
- $state3 = CustomerVisitLog::changeState('已量房', 'chaos');
- $state4 = CustomerVisitLog::changeState('已交定', 'chaos');
- $state5 = CustomerVisitLog::changeState('已签单', 'chaos');
- $where[] = ['state', 'in', array_merge($state1, $state2, $state3, $state4, $state5)];
- $total = CustomerVisitLog::field("customer_id, DATE_FORMAT(addtime,'%Y-%m-%d') as date")->where($where)->group('customer_id,date')->count();
- $searchObject = CustomerVisitLog::field("customer_id, DATE_FORMAT(addtime,'%Y-%m-%d') as date, max(addtime) as addtime, SUM(number_of_visitors) as number_of_visitors, SUM(measure_room_img_type='量房图片') as measure_type1, SUM(measure_room_img_type='量房报告图片') as measure_type2, SUM(measure_room_img_type='客户需求表') as measure_type3,GROUP_CONCAT(aid) as aid_list")->where($where)->order('date desc,addtime desc')->group('customer_id,date');
- if ($getTotal == false) $searchObject->page($page, $limit);
- $lastVisitCustomerList = $searchObject->select();
- // 获取客户信息
- $customerIdList = array_unique(array_column(empty($lastVisitCustomerList) ? [] : $lastVisitCustomerList->toArray(), 'customer_id'));
- $customerList = Customer::with(['employee', 'designer'])->where([['id', 'in', $customerIdList]])->field('id,name,designer_id,employee_id,phone,phone1,phone2,square,community_name,ext,house_delivery_time,plan_deco_time,source_id,house_type,package_id,level,age_range,house_type,deco_style,source_id')->select();
- $customerList1 = CustomerRecycle::with(['employee', 'designer'])->where([['customer_id', 'in', $customerIdList]])->field('customer_id as id,name,designer_id,employee_id,phone,phone1,phone2,square,community_name,ext,house_delivery_time,plan_deco_time,source_id,house_type,package_id,level,age_range,house_type,deco_style,source_id')->select();
- $customerList2 = CustomerDropPool::with(['employee', 'designer'])->where([['customer_id', 'in', $customerIdList]])->field('customer_id as id,name,designer_id,employee_id,phone,phone1,phone2,square,community_name,ext,house_delivery_time,plan_deco_time,source_id,house_type,package_id,level,age_range,house_type,deco_style,source_id')->select();
- $customerList = array_merge($customerList->toArray(), $customerList1->toArray(), $customerList2->toArray());
- $customerList = array_combine(array_column($customerList, 'id'), $customerList);
- $customerList = $this->emp_extfield_change($customerList);
- // 查询爆品产品
- $packageId = implode(',', array_column($customerList, 'package_id'));
- $package = CustomerPackage::where([['id', 'in', $packageId]])->column('total_price', 'id');
- // 获取公司名称
- $companyName = Company::where([['root_id', '=', $this->root_id]])->value('company_name');
- // 公司负责人获取
- // $companyLeader = Employee::where([['root_id', '=', $this->root_id], ['state', '=', '在职'], ['is_manager', '=', '1'], ['org_id', '=', $this->root_id], ['uid', '<>', 0]])->column('name');
- // 来源
- $sourseIdList = array_column($customerList, 'source_id');
- $sourseList = CustomerSource::where([['id', 'in', $sourseIdList]])->column('source', 'id');
- $num = ($page - 1) * $limit + 1;
- // 处理数据
- $data = [];
- foreach ($lastVisitCustomerList as $c) {
- $item = [
- 'key' => $num,
- 'customer_id' => $c['customer_id'],
- ];
- if (!isset($customerList[$c['customer_id']])) {
- $data[] = $item;
- $num++;
- continue;
- }
- list($Y, $m, $d) = explode('-', $c['date']);
- $leader_arr = ['941' => '罗镐', '1847' => '刘有凤']; //馨居尚,菡萏怡景,部门负责人
- $item = [
- 'key' => $num,
- 'customer_name' => $customerList[$c['customer_id']]['name'],
- 'date' => $Y . '年' . $m . '月' . $d . '日',
- 'addtime' => $c['addtime'],
- 'company_name' => $companyName,
- 'leader' => !empty($leader_arr[$this->root_id]) ? $leader_arr[$this->root_id] : '罗镐',
- 'community_name' => $customerList[$c['customer_id']]['community_name'],
- // 'measure_type1' => $c['measure_type1'] ? '√' : '',
- // 'measure_type2' => $c['measure_type2'] ? '√' : '',
- // 'measure_type3' => $c['measure_type3'] ? '√' : '',
- 'measure_room_store' => $this->measureRoomStore($c['date'], $c['customer_id']),
- 'number_of_visitors' => $c['number_of_visitors'] == 0 ? '' : $c['number_of_visitors'],
- 'area' => $c['area'],
- //'ext39' => $customerList[$c['customer_id']]['ext']['房屋位置'],
- 'ext39' => $customerList[$c['customer_id']]['ext']['house_location'],
- //'talking_about_single_time' => isset($customerList[$c['customer_id']]['ext']['谈单时长']) ? $customerList[$c['customer_id']]['ext']['谈单时长'] : 0,
- 'talking_about_single_time' => isset($customerList[$c['customer_id']]['ext']['talking_about_single_time']) ? $customerList[$c['customer_id']]['ext']['talking_about_single_time'] : 0,
- 'source' => isset($sourseList[$customerList[$c['customer_id']]['source_id']]) ? $sourseList[$customerList[$c['customer_id']]['source_id']] : '',
- 'square' => $customerList[$c['customer_id']]['square'],
- //'ext42' => $customerList[$c['customer_id']]['ext']['门牌单元号']
- 'ext42' => $customerList[$c['customer_id']]['ext']['unit_number']
- ];
- //量房图片类型
- $where_img_type = [];
- $where_img_type[] = ['addtime', 'like', '%' . $c['date'] . '%'];
- $where_img_type[] = ['customer_id', '=', $c['customer_id']];
- $where_img_type[] = CustomerVisitLog::changeState(['state', '=', '确认量房']);
- $str = CustomerVisitLog::where($where_img_type)->order('addtime desc')->column('measure_room_img_type', 'addtime');
- $measure_type2 = $measure_type3 = '';
- foreach ($str as $k => $v) {
- if ($v && (strpos($v, '量房图片') !== false || strpos($v, '量房报告图片') !== false || strpos($v, '量房验房报告') !== false)) {
- $measure_type2 = $k;
- break;
- }
- if ($v && (strpos($v, '客户需求图片') !== false)) {
- $measure_type3 = $k;
- break;
- }
- }
- $item['measure_type2'] = $measure_type2;
- $item['measure_type3'] = $measure_type3;
- $lastmeasure_time = CustomerVisitlog::where($where_img_type)->order('addtime desc')->value('addtime');
- // $str = $str ? implode(',', $str) : '';
- // $item['measure_type2'] = ($str && (strpos($str, '量房图片') !== false || strpos($str, '量房报告图片') !== false || strpos($str, '量房验房报告') !== false)) ? '√' : '';
- // $item['measure_type3'] = ($str && strpos($str, '客户需求图片') !== false) ? '√' : '';
- // 计算交房相差月份
- $houseDeliveryTime = strtotime($customerList[$c['customer_id']]['house_delivery_time']);
- $month = (date('Y', $houseDeliveryTime) - date('Y')) * 12 + date('m', $houseDeliveryTime) - date('m');
- $type = '0';
- // if ($customerList[$c['customer_id']]['ext']['加微类型'] == '常规加微') {
- // $type = '1';
- // } elseif ($customerList[$c['customer_id']]['ext']['加微类型'] == '社群加微') {
- // $type = '2';
- // }
- $item['add_wechat_time'] = $customerList[$c['customer_id']]['ext']['add_wechat_time'];
- if ($customerList[$c['customer_id']]['ext']['add_wechat_type'] == '常规加微') {
- $type = '1';
- } elseif ($customerList[$c['customer_id']]['ext']['add_wechat_type'] == '社群加微') {
- $type = '2';
- } elseif ($customerList[$c['customer_id']]['ext']['add_wechat_type'] == '历史加微') {
- $type = '3';
- }
- if ($type !== '0') {
- $item['house_type' . $type] = in_array($customerList[$c['customer_id']]['house_type'], ['现房', '二手房']) ? '√' : '';
- if ($item['house_type' . $type] != '√' && !empty($customerList[$c['customer_id']]['house_delivery_time'])) {
- $item['delivery_month' . $type . '_1'] = $month <= 3 ? '√' : '';
- $item['delivery_month' . $type . '_2'] = $month > 3 && $month <= 6 ? '√' : '';
- $item['delivery_month' . $type . '_3'] = $month > 6 && $month <= 12 ? '√' : '';
- $item['delivery_month' . $type . '_4'] = $month > 12 ? '√' : '';
- } else {
- $item['delivery_month' . $type . '_1'] = '';
- $item['delivery_month' . $type . '_2'] = '';
- $item['delivery_month' . $type . '_3'] = '';
- $item['delivery_month' . $type . '_4'] = '';
- }
- }
- // 设计师
- if (!empty($customerList[$c['customer_id']]['designer'])) {
- $designerOrgId = $customerList[$c['customer_id']]['designer']['org_id'];
- $item['designer_name'] = $customerList[$c['customer_id']]['designer']['name'];
- $item['designer_org'] = $orgs[$designerOrgId]['name'];
- $item['designer_leader'] = isset($leadersData[$designerOrgId]) ? implode(',', $leadersData[$designerOrgId]['leaders']) : '';
- $path = $leadersData[$designerOrgId]['path'];
- $pathList = array_filter(explode('-', $path));
- foreach ($pathList as $od) {
- if (strstr($leadersData[$od]['org_name'], '部') !== false && $leadersData[$od]['org_name'] != '设计部') {
- $level = 3;
- } else {
- $level = $leadersData[$od]['level'];
- }
- if (isset($item['employee_org_level' . $level])) $level++;
- $item['designer_leader_level' . $level] = implode(',', $leadersData[$od]['leaders']);
- $item['designer_org_level' . $level] = $leadersData[$od]['org_name'];
- }
- } else {
- $item['designer_name'] = $item['designer_org'] = $item['designer_leader'] = '';
- }
- // 员工
- if (!empty($customerList[$c['customer_id']]['employee'])) {
- $employeeOrgId = $customerList[$c['customer_id']]['employee']['org_id'];
- $item['employee_name'] = $customerList[$c['customer_id']]['employee']['name'];
- $item['employee_org'] = $orgs[$employeeOrgId]['name'];
- $item['employee_leader'] = implode(',', $leadersData[$employeeOrgId]['leaders']);
- $path = $leadersData[$employeeOrgId]['path'];
- $pathList = array_filter(explode('-', $path));
- foreach ($pathList as $od) {
- if (strstr($leadersData[$od]['org_name'], '区中区') !== false) {
- $level = 3;
- } elseif (strstr($leadersData[$od]['org_name'], '中心') !== false) {
- $level = 4;
- } elseif (strstr($leadersData[$od]['org_name'], '区') !== false) {
- $level = 2;
- } else {
- $level = $leadersData[$od]['level'];
- }
- if (isset($item['employee_org_level' . $level])) $level++;
- // $level = $leadersData[$od]['level'];
- $item['employee_leader_level' . $level] = implode(',', $leadersData[$od]['leaders']);
- $item['employee_org_level' . $level] = $leadersData[$od]['org_name'];
- }
- // 查询直属领导是否跟踪过
- // 获取直属领导id
- $leaderIdList = $leadersData[$employeeOrgId]['leaders_ids'];
- $query = [];
- $query[] = ['employee_id', 'in', $leaderIdList];
- $query[] = ['addtime', 'like', $c['date'] . '%'];
- $query[] = ['customer_id', '=', $c['customer_id']];
- $leader_visit_time = CustomerVisitLog::where($query)->order('addtime desc')->value('addtime');
- $item['leader_visit'] = !empty($leader_visit_time) && ($item['measure_type2'] || $item['measure_type3']) ? $leader_visit_time : "";
- //$item['leader_visit'] = !CustomerVisitLog::where($query)->findOrEmpty()->isEmpty() && ($item['measure_type2'] == '√' || $item['measure_type3'] == '√') ? "√" : "";
- } else {
- $item['employee_name'] = $item['employee_org'] = $item['employee_leader'] = '';
- $item['leader_visit'] = '';
- }
- // 量房验房
- //$item['measure_type1'] = ($item['leader_visit'] == '√' || $item['measure_type2'] == '√' || $item['measure_type3'] == '√') ? $lastmeasure_time : '';
- $item['measure_type1'] = ($item['leader_visit'] || $item['measure_type2'] || $item['measure_type3']) ? $lastmeasure_time : '';
- // 手机号
- $phoneArr = array_filter([$customerList[$c['customer_id']]['phone'], $customerList[$c['customer_id']]['phone1'], $customerList[$c['customer_id']]['phone2']]);
- $item['phone'] = substr_replace(array_shift($phoneArr), '******', 3, 6);
- // 建群情况
- //$jianqun = explode(',', $customerList[$c['customer_id']]['ext']['建群情况']);
- $jianqun = explode(',', $customerList[$c['customer_id']]['ext']['group_building']);
- //建群时间
- $jianqun_time = !empty($customerList[$c['customer_id']]['ext']['group_building_date']) ? $customerList[$c['customer_id']]['ext']['group_building_date'] : '';
- if (empty($jianqun_time)) {
- $jianqun_time = CustomerVisitLog::where([['customer_id', '=', $c['customer_id']], ['save_portrait_field', 'like', '%group_building%']])->value('addtime');
- }
- $item['ext35_1'] = (in_array('1对1小群', $jianqun) || in_array('一对一小群', $jianqun)) && $jianqun_time ? $jianqun_time : '';
- $item['ext35_2'] = in_array('临时大群', $jianqun) && $jianqun_time ? $jianqun_time : '';
- $item['ext35_3'] = in_array('社群', $jianqun) && $jianqun_time ? $jianqun_time : '';
- // 直播
- //$zhibo = explode(',', $customerList[$c['customer_id']]['ext']['直播情况']);
- $zhibo = explode(',', $customerList[$c['customer_id']]['ext']['live_broadcast']);
- $zhibo_time = !empty($customerList[$c['customer_id']]['ext']['live_broadcast_date']) ? $customerList[$c['customer_id']]['ext']['live_broadcast_date'] : '';
- if (empty($zhibo_time)) {
- $zhibo_time = CustomerVisitLog::where([['customer_id', '=', $c['customer_id']], ['save_portrait_field', 'like', '%live_broadcast%']])->value('addtime');
- }
- $item['ext36_1'] = (in_array('一对一直播', $zhibo) || in_array('1对1业务直播', $zhibo)) && $zhibo_time ? $zhibo_time : '';
- $item['ext36_2'] = in_array('1对1设计直播', $zhibo) && $zhibo_time ? $zhibo_time : '';
- $item['ext36_3'] = in_array('一对多直播', $zhibo) && $zhibo_time ? $zhibo_time : '';
- $item['ext37_1'] = !empty($item['ext36_1']) ? $customerList[$c['customer_id']]['ext']['live_broadcast_business'] : '';
- $item['ext37_2'] = !empty($item['ext36_2']) ? $customerList[$c['customer_id']]['ext']['live_broadcast_design'] : '';
- $item['ext37_3'] = !empty($item['ext36_3']) ? $customerList[$c['customer_id']]['ext']['live_broadcast_personnel'] : '';
- // 签单金额
- $condition = [];
- // $condition[] = ['addtime', 'like', $c['date'] . '%'];
- $condition[] = ['customer_id', '=', $c['customer_id']];
- $condition1 = $condition;
- $condition2 = $condition;
- $condition1[] = CustomerVisitLog::changeState(['state', '=', '已交定']);
- $condition2[] = CustomerVisitLog::changeState(['state', '=', '已签单']);
- $item['signature_money'] = CustomerVisitLog::where($condition2)->order('addtime desc')->value('money');
- $deposit = CustomerVisitLog::where($condition1)->order('addtime desc')->field('money,deposit_mode')->find();
- if (!empty($deposit)) {
- $deposit['deposit_mode'] !== 0 ? $item['deposit_money1'] = $deposit['money'] : $item['deposit_money2'] = $deposit['money'];
- // 爆品定金
- if ($customerList[$c['customer_id']]['package_id']) {
- $packageIdList = explode(',', $customerList[$c['customer_id']]['package_id']);
- $totalMoney = 0;
- foreach ($packageIdList as $pid) {
- $totalMoney += $package[$pid];
- }
- if ($totalMoney !== 0) {
- $item['package'] = $deposit['money'] / $totalMoney * 100 >= 10 ? '√' : '';
- }
- }
- }
- // 预计装修时间 -> 高意向到店客户
- if (!empty($customerList[$c['customer_id']]['plan_deco_time'])) {
- $planDecoTime = strtotime($customerList[$c['customer_id']]['plan_deco_time']);
- $item['plan_month_day'] = ($planDecoTime - time()) / 86400 < 30 ? $customerList[$c['customer_id']]['plan_deco_time'] : '';
- }
- //活动见面类型
- $query_actmet = [];
- $query_actmet[] = ['addtime', 'like', $c['date'] . '%'];
- $query_actmet[] = ['customer_id', '=', $c['customer_id']];
- $query_actmet[] = ['actmeet_type', '<>', 0];
- $query_actmet[] = CustomerVisitLog::changeState(['state', '=', '已到场']);
- $actmet = CustomerVisitLog::where($query_actmet)->order('addtime desc')->value('addtime,actmeet_type');
- if (!empty($actmet)) {
- $item['actmeet_type1'] = !empty($actmet['actmeet_type']) && $actmet['actmeet_type'] == 1 ? $actmet['addtime'] : '';
- $item['actmeet_type2'] = !empty($actmet['actmeet_type']) && $actmet['actmeet_type'] == 2 ? $actmet['addtime'] : '';
- $item['actmeet_type3'] = !empty($actmet['actmeet_type']) && $actmet['actmeet_type'] == 3 ? $actmet['addtime'] : '';
- } else {
- $item['actmeet_type1'] = '';
- $item['actmeet_type2'] = '';
- $item['actmeet_type3'] = '';
- }
- //查询谈单时长
- $query_order_time = [];
- $query_order_time[] = ['addtime', 'like', $c['date'] . '%'];
- $query_order_time[] = ['customer_id', '=', $c['customer_id']];
- $query_order_time[] = CustomerVisitLog::changeState(['state', '=', '已到店']);
- $order_time = CustomerVisitLog::where($query_order_time)->sum('talking_order_time');
- $item['order_time'] = $order_time;
- //新的判断网谈登记,茶楼见面
- // $query_actmet1 = [];
- // $query_actmet1[] = ['addtime', 'like', $c['date'] . '%'];
- // $query_actmet1[] = ['customer_id', '=', $c['customer_id']];
- // //$query_actmet1[] = ['save_portrait_field','not null',''];
- // //$query_actmet1[] = ['save_portrait_field','like','online_meet_checked%'];
- // $query_actmet1[] = ['save_portrait_field', 'like', ['%online_meet_checked%', '%teahouse_meet%'], 'OR'];
- // $query_actmet1[] = CustomerVisitLog::changeState(['state', '=', '未到访']);
- // $actmet_data = CustomerVisitLog::where($query_actmet1)->column('save_portrait_field', 'id');
- // $online_meet_checked = $teahouse_meet = '';
- // if ($actmet_data) {
- // foreach ($actmet_data as $m => $p) {
- // $save_field_list = json_decode($p, true);
- // foreach ($save_field_list as $k => $v) {
- // if ($v['keyname'] == 'online_meet_checked') $online_meet_checked = $v['value'];
- // if ($v['keyname'] == 'teahouse_meet') $teahouse_meet = $v['value'];
- // }
- // }
- // }
- // $item['actmeet_type2'] = $teahouse_meet ? $teahouse_meet : '';
- // $item['actmeet_type3'] = $online_meet_checked ? $online_meet_checked : '';
- //查询定金客户转到店
- $item['djzdd'] = $this->isStateToShop($c['date'], $c['customer_id'], '已交定', $customerList[$c['customer_id']]['ext']);
- //查询量房客户转到店
- $item['lfzdd'] = $this->isStateToShop($c['date'], $c['customer_id'], '已量房', $customerList[$c['customer_id']]['ext']);
- //查询外场活动转到店
- $item['wczdd'] = $this->isStateToShop($c['date'], $c['customer_id'], '已到场', $customerList[$c['customer_id']]['ext']);
- //新到店次数
- $where = [];
- $starttime = date('Y-m', strtotime($c['date'])) . '-01 00:00:00';
- $where[] = ['addtime', '<', $c['date'] . ' 23:59:59'];
- $where[] = ['addtime', '>', $starttime];
- $where[] = ['customer_id', '=', $c['customer_id']];
- $state1 = CustomerVisitLog::changeState('确定到店', 'chaos');
- $where[] = ['state', 'in', $state1];
- $list = CustomerVisitLog::where($where)->order('addtime desc')->column('addtime,id');
- $newlist = [];
- if (!empty($list)) {
- foreach ($list as $k => $v) {
- $list[$k]['newtime'] = date('Y-m-d', strtotime($v['addtime']));
- }
- foreach ($list as $k => $v) {
- $newlist[$v['newtime']][] = $v;
- }
- }
- $count = count($newlist);
- $daodian = CustomerVisitLog::where([['customer_id', '=', $c['customer_id']], ['addtime', 'between', [$c['date'] . ' 00:00:00', $c['date'] . ' 23:59:59']], ['state', 'in', CustomerVisitLog::changeState('已到店', 'chaos')]])->order('addtime desc')->value('addtime');
- $item['visit_number1'] = $count == 1 && $daodian ? end($newlist)[0]['addtime'] : '';
- //$item['visit_number2'] = $count == 2 ? array_pop($newlist)[0]['addtime'] : '';
- $item['visit_number2'] = $count == 2 && $daodian ? current($newlist)[0]['addtime'] : '';
- $item['visit_number3'] = $count >= 3 && $daodian ? '√' : '';
- // 外场活动名
- $aidList = array_unique(explode(',', $c['aid_list']));
- $huodong = ModelActivity::where([['id', 'in', $aidList], ['cate', '=', 1]])->column('title,address');
- $huodongList = [];
- foreach ($huodong as $h) {
- if ($h['address']) {
- $huodongList[] = $h['title'] . '(' . $h['address'] . ')';
- } else {
- $huodongList[] = $h['title'];
- }
- }
- $daochang = CustomerVisitLog::where([['customer_id', '=', $c['customer_id']], ['addtime', 'between', [$c['date'] . ' 00:00:00', $c['date'] . ' 23:59:59']], ['state', 'in', CustomerVisitLog::changeState('已到场', 'chaos')]])->count();
- $item['outfield_activities'] = $daochang ? implode(',', $huodongList) : '';
- // 外场活动转内场新客户 活动前未到店以及后续状态,参加活动后,第一次到店显示
- //$item['outfield_infield'] = $this->getIsNewCusomerVisitAfterActivity($c['date'], $c['customer_id']);
- $item['outfield_infield'] = $daodian && empty($item['djzdd']) && empty($item['lfzdd']) && empty($item['wczdd']) ? $daodian : '';
- $data[] = $item;
- $num++;
- }
- return json(['code' => 0, 'data' => $data, 'count' => $total, 'page' => ceil($total / $limit)]);
- }
- /**
- * 查询是否是定金,量房,外场客户转到店
- */
- public function isStateToShop($date, $customerId, $state, $cusext)
- {
- $where = [];
- $where[] = ['addtime', '<', $date . ' 23:59:59'];
- $where[] = ['customer_id', '=', $customerId];
- $state1 = CustomerVisitLog::changeState('已到店', 'chaos');
- $where[] = ['state', 'in', $state1];
- // 查询日期必须到店
- $had = CustomerVisitLog::where($where)->order('addtime asc')->column('addtime');
- // 是否多次到店或未到店,当天到店多次算一次
- if (empty($had)) return '';
- foreach ($had as $k => $v) {
- if ($v < $date . ' 00:00:00') return '';
- }
- //$lastTime = strtotime($had[0]);
- $lastTime = strtotime(end($had));
- // 判断到店日期是否是所选日期
- if (date('Y-m-d', $lastTime) != $date) return '';
- // 判断是否参加过活动
- $state_time = CustomerVisitLog::where([
- ['addtime', '<', $date . ' 23:59:59'],
- ['state', 'in', CustomerVisitLog::changeState($state, 'chaos')],
- ['customer_id', '=', $customerId]
- ])->order('addtime asc')->value('addtime');
- if (empty($state_time)) return '';
- //if (in_array($state, ['已量房', '已交定']) && empty($state_time)) return '';
- //如果已到场时间为空再查询网谈登记时间跟茶楼见面时间,如果两个都有值取最早时间的值
- // if ($state == '已到场' && empty($state_time)) {
- // if (isset($cusext['online_meet_checked']) && isset($cusext['teahouse_meet'])) $state_time = $cusext['online_meet_checked'] > isset($cusext['teahouse_meet']) ? isset($cusext['teahouse_meet']) : isset($cusext['online_meet_checked']);
- // if (isset($cusext['online_meet_checked'])) $state_time = $cusext['online_meet_checked'];
- // if (isset($cusext['teahouse_meet'])) $state_time = $cusext['teahouse_meet'];
- // if (empty($state_time)) return '';
- // }
- if (strtotime($state_time) < $lastTime) return date('Y-m-d H:i:s', $lastTime);
- return '';
- }
- /**
- * 获取客户跟进数据表表头
- */
- public function new_table_data()
- {
- // 领导获取
- $orgLeader = Employee::where([['root_id', '=', $this->root_id], ['is_manager', '=', 1], ['state', '=', '在职']])->column('id, org_id, name');
- $orgDealLeader = [];
- foreach ($orgLeader as $leader) {
- $orgDealLeader[$leader['org_id']][] = $leader['name'];
- }
- // 查询设计师部门
- $designerOrg = Org::where([['path', 'like', $this->root_id . '-%'], ['id', "<>", $this->root_id], ['org_type', '=', 2]])->order('level desc')->column('level, id, name');
- // 部门处理
- $dealDesignerOrg = [];
- foreach ($designerOrg as $org) {
- $dealDesignerOrg[$org['level']]['name'][] = $org['name'];
- isset($dealDesignerOrg[$org['level']]['leader']) ?: $dealDesignerOrg[$org['level']]['leader'] = [];
- if (isset($orgDealLeader[$org['id']]))
- $dealDesignerOrg[$org['level']]['leader'] = array_merge($dealDesignerOrg[$org['level']]['leader'], $orgDealLeader[$org['id']]);
- }
- // 剔除末枝部门
- $del = false;
- foreach ($dealDesignerOrg as $k => $item) {
- if (!$del) {
- unset($dealDesignerOrg[$k]);
- $del = true;
- }
- }
- // 查询销售部门
- $sellerOrg = Org::where([['path', 'like', $this->root_id . '-%'], ['id', "<>", $this->root_id], ['org_type', '=', 1]])->order('level desc')->column('level, id, name');
- // 部门处理
- $dealSellerOrg = [];
- foreach ($sellerOrg as $org) {
- $dealSellerOrg[$org['level']]['name'][] = $org['name'];
- isset($dealSellerOrg[$org['level']]['leader']) ?: $dealSellerOrg[$org['level']]['leader'] = [];
- if (isset($orgDealLeader[$org['id']]))
- $dealSellerOrg[$org['level']]['leader'] = array_merge($dealSellerOrg[$org['level']]['leader'], $orgDealLeader[$org['id']]);
- }
- // 剔除末枝部门
- $del = false;
- foreach ($dealSellerOrg as $k => $item) {
- if (!$del) {
- unset($dealSellerOrg[$k]);
- $del = true;
- }
- }
- $header = $this->getNewVisitLogHeaders();
- view::assign('header1', $header['header1']);
- view::assign('header2', $header['header2']);
- $org = Org::where([['path', 'like', request()->employee->root_id . '-%'], ['org_type', '=', 1]])->field('id,name')->select()->toArray();
- View::assign('org', $org);
- $row = [];
- foreach ($header['header1'] as $item) {
- if (isset($item['child'])) {
- foreach ($item['child'] as $c) {
- $row[] = $c;
- }
- } else {
- $row[] = $item['field'];
- }
- }
- view::assign('row', json_encode($row));
- return View::fetch();
- }
- /**
- * 获取线上跟踪客户记录表头
- */
- private function getNewVisitLogHeaders()
- {
- // 第二行头部
- $header2 = [];
- // 设计师部门插入头部
- $header2[] = ["field" => 'customer_name', "title" => '客户名字', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'phone', "title" => '客户电话', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'ext39', "title" => '省市区', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'community_name', "title" => '楼盘', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'ext42', "title" => '门牌单元号', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'square', "title" => '面积', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'employee_name', "title" => '业务员', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'employee_org', "title" => '业务部门', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'employee_leader', "title" => '业务经理', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'employee_org_level4', "title" => '业务中心', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'employee_leader_level4', "title" => '业务总监', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'employee_org_level3', "title" => '区中区', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'employee_leader_level3', "title" => '区中区副总', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'employee_org_level2', "title" => '大区', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'employee_leader_level2', "title" => '大区副总', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'designer_name', "title" => '设计师', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'designer_org', "title" => '设计部门', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'designer_leader', "title" => '设计经理', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'designer_org_level2', "title" => '设计中心', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'designer_leader_level2', "title" => '设计总监', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'designer_leader_level1', "title" => '设计副总', "align" => 'center', "class" => "bgEEECE1"];
- // 加微
- $header2[] = ["field" => 'house_type1', "title" => '现房', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month1_1', "title" => '0-3个月', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month1_2', "title" => '3-6个月', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month1_3', "title" => '6-12个月', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month1_4', "title" => '12个月以上', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'house_type2', "title" => '现房', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month2_1', "title" => '0-3个月', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month2_2', "title" => '3-6个月', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month2_3', "title" => '6-12个月', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month2_4', "title" => '12个月以上', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'house_type3', "title" => '现房', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month3_1', "title" => '0-3个月', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month3_2', "title" => '3-6个月', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month3_3', "title" => '6-12个月', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month3_4', "title" => '12个月以上', "align" => 'center', "class" => "bgDCE6F1"];
- // 建群
- $header2[] = ["field" => 'ext35_1', "title" => '1对1小群', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'ext35_2', "title" => '临时大群', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'ext35_3', "title" => '社群', "align" => 'center', "class" => "bgEEECE1"];
- // 直播
- $header2[] = ["field" => 'ext36_1', "title" => '1对1业务直播', "align" => 'center', "class" => "bgF2DCDB"];
- $header2[] = ["field" => 'ext37_1', "title" => '业务员', "align" => 'center', "class" => "bgF2DCDB"];
- $header2[] = ["field" => 'ext36_2', "title" => '1对1设计直播', "align" => 'center', "class" => "bgF2DCDB"];
- $header2[] = ["field" => 'ext37_2', "title" => '设计师', "align" => 'center', "class" => "bgF2DCDB"];
- $header2[] = ["field" => 'ext36_3', "title" => '一对多直播', "align" => 'center', "class" => "bgF2DCDB"];
- $header2[] = ["field" => 'ext37_3', "title" => '直播人员', "align" => 'center', "class" => "bgF2DCDB"];
- // 量房验房
- $header2[] = ["field" => 'measure_type2', "title" => '量房验房报告', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'measure_type3', "title" => '客户需求表', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'leader_visit', "title" => '经理是否回访', "align" => 'center', "class" => "bgEEECE1"];
- // 到店
- $header2[] = ["field" => 'outfield_activities', "title" => '外场活动到店', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'outfield_infield', "title" => '内场直接到店', "align" => 'center', "class" => "bgEEECE1"];
- //见面方式
- $header2[] = ["field" => 'actmeet_type1', "title" => '外场活动', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'actmeet_type2', "title" => '茶楼见面', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'actmeet_type3', "title" => '网谈登记', "align" => 'center', "class" => "bgEEECE1"];
- // 管理到店数据
- $header2[] = ["field" => 'deposit_money2', "title" => '线上定金', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'deposit_money1', "title" => '线下定金', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'djzdd', "title" => '定金客户转到店', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'package', "title" => '爆品定金(10%以上)', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'measure_type1', "title" => '量房验房', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'lfzdd', "title" => '量房客户转到店', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'visit_number1', "title" => '一次到店<br>(内场到店)', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'visit_number2', "title" => '二次到店', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'visit_number3', "title" => '三次及以上到店', "align" => 'center', "class" => "bgEEECE1"];
- // 插入销售部门
- $employeeChild = ['employee_name', 'employee_org', 'employee_leader', 'employee_org_level4', 'employee_leader_level4', 'employee_org_level3', 'employee_leader_level3', 'employee_org_level2', 'employee_leader_level2'];
- // 设计部门
- $designerChild = ['designer_name', 'designer_org', 'designer_leader', 'designer_org_level2', 'designer_leader_level2', 'designer_leader_level1'];
- // 第一行头部
- $header1 = [];
- $header1[] = ["type" => 'key', "field" => 'key', "title" => '序号', "align" => 'center', "rowspan" => 2, "class" => "bgEEECE1"];
- $header1[] = ["field" => 'date', "title" => '日期', "align" => 'center', "rowspan" => 2, "class" => "bgEEECE1"];
- $header1[] = ["field" => "", "child" => ['customer_name', 'phone', 'ext39', 'community_name', 'ext42', 'square'], "title" => '客户信息 ', "align" => 'center', "colspan" => 6, "class" => "bgEEECE1"];
- $header1[] = ["field" => 'company_name', "title" => '公司', "align" => 'center', "rowspan" => 2, "class" => "bgA6A6A6"];
- $header1[] = ["field" => 'leader', "title" => '负责人', "align" => 'center', "rowspan" => 2, "class" => "bgA6A6A6"];
- $header1[] = ["field" => "", "child" => $employeeChild, "title" => '营销', "align" => 'center', "colspan" => 9, "class" => "bgEEECE1"];
- $header1[] = ["field" => "", "child" => $designerChild, "title" => '设计', "align" => 'center', "colspan" => 6, "class" => "bgEEECE1"];
- $header1[] = ["field" => "", "child" => ['house_type1', 'delivery_month1_1', 'delivery_month1_2', 'delivery_month1_3', 'delivery_month1_4'], "title" => '常规加微<br>(交房时间)', "align" => 'center', "colspan" => 5, "class" => "bgDCE6F1"];
- $header1[] = ["field" => "", "child" => ['house_type2', 'delivery_month2_1', 'delivery_month2_2', 'delivery_month2_3', 'delivery_month2_4'], "title" => '社群加微<br>(交房时间)', "align" => 'center', "colspan" => 5, "class" => "bgDCE6F1"];
- $header1[] = ["field" => "", "child" => ['house_type3', 'delivery_month3_1', 'delivery_month3_2', 'delivery_month3_3', 'delivery_month3_4'], "title" => '历史加微<br>(交房时间)', "align" => 'center', "colspan" => 5, "class" => "bgDCE6F1"];
- $header1[] = ["field" => "add_wechat_time", "title" => '加微时间', "align" => 'center', "rowspan" => 2, "class" => "bgEEECE1"];
- $header1[] = ["field" => "plan_month_day", "title" => '高意向到店客户<br>(1个月内装修)', "align" => 'center', "rowspan" => 2, "class" => "bgEEECE1"];
- $header1[] = ["field" => "", "child" => ['ext35_1', 'ext35_2', 'ext35_3'], "title" => '建群', "align" => 'center', "colspan" => 3, "class" => "bgEEECE1"];
- $header1[] = ["field" => "", "child" => ['ext36_1', 'ext37_1', 'ext36_2', 'ext37_2', 'ext36_3', 'ext37_3'], "title" => '直播', "align" => 'center', "colspan" => 6, "class" => "bgF2DCDB"];
- $header1[] = ["field" => "", "child" => ['measure_type2', 'measure_type3', 'leader_visit'], "title" => '量房验房', "align" => 'center', "colspan" => 3, "class" => "bgEEECE1"];
- // $header1[] = ["field" => "yylf", "title" => '预约量房', "align" => 'center', "rowspan" => 2, "class" => "bgEEECE1"];
- // $header1[] = ["field" => "yydd", "title" => '预约到店', "align" => 'center', "rowspan" => 2, "class" => "bgEEECE1"];
- // $header1[] = ["field" => "yydc", "title" => '预约到场', "align" => 'center', "rowspan" => 2, "class" => "bgEEECE1"];
- $header1[] = ["field" => '', "child" => ['outfield_activities', 'outfield_infield'], "title" => '到店', "align" => 'center', "colspan" => 2, "class" => "bgFDE9D9"];
- $header1[] = ["field" => '', "child" => ['actmeet_type1', 'actmeet_type2', 'actmeet_type3'], "title" => '见面方式', "align" => 'center', "colspan" => 3, "class" => "bgEEECE1"];
- $header1[] = ["field" => '', "child" => ['deposit_money2', 'deposit_money1', 'djzdd', 'package', 'measure_type1', 'lfzdd', 'visit_number1', 'visit_number2', 'visit_number3'], "title" => '管理到店数据', "align" => 'center', "colspan" => 9, "class" => "bgFDE9D9"];
- $header1[] = ["field" => 'number_of_visitors', "title" => '到店人数', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"];
- $header1[] = ["field" => 'signature_money', "title" => '合同价', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"];
- $header1[] = ["field" => 'wczdd', "title" => '外场转内场到店', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"];
- $header1[] = ["field" => 'order_time', "title" => '谈单时长', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"];
- return ['header1' => $header1, 'header2' => $header2];
- }
- /**
- * 总经办报表
- */
- public function officeStatistics($page, $limit)
- {
- $param = $this->request->only(['sdate' => '', 'edate' => '', 'org_id' => 0, 'add_wechat_time']);
- // 获取部门id
- $root_id = request()->employee->root_id;
- $orgs = Org::where([['path', 'like', $root_id . '-%']])->column('name,id,pid,level,path', 'id');
- // 部门领导获取
- $leaders = Employee::with('org')->where([['root_id', '=', $this->root_id], ['state', '=', '在职'], ['is_manager', '=', '1'], ['uid', '<>', 0]])->select();
- // 领导结构修改
- $leadersData = [];
- foreach ($leaders as $l) {
- if (isset($leadersData[$l['org_id']])) {
- $leadersData[$l['org_id']]['leaders'][] = $l['name'];
- $leadersData[$l['org_id']]['leaders_ids'][] = $l['id'];
- } else {
- $leadersData[$l['org_id']] = [
- 'org_name' => $l['org']['name'],
- 'level' => $l['org']['level'],
- 'path' => $l['org']['path'],
- 'leaders_ids' => [
- $l['id']
- ],
- 'leaders' => [
- $l['name']
- ]
- ];
- }
- }
- // 补充没领导的部门
- foreach ($orgs as $k => $item) {
- if (!isset($leadersData[$k])) {
- $leadersData[$k] = [
- 'org_name' => $item['name'],
- 'level' => $item['level'],
- 'path' => $item['path'],
- 'leaders' => [],
- 'leaders_ids' => []
- ];
- }
- }
- // 查询最近访问的客户
- $where = [];
- if ($param['org_id']) {
- //查询本部门下面是否有部门
- $childorg = orgSubIds($param['org_id']);
- $where[] = ['org_id|customer_org_id', 'in', $childorg];
- // $where[] = ['org_id', '=', $param['org_id']];
- } else {
- $where[] = ['org_id', 'in', array_keys($orgs)];
- }
- if ($param['sdate']) {
- $param['sdate'] = date('Y-m-d', strtotime($param['sdate']));
- $where[] = ['addtime', '>=', $param['sdate'] . ' 00:00:00'];
- }
- if ($param['edate']) {
- $param['edate'] = date('Y-m-d', strtotime($param['edate']));
- $where[] = ['addtime', '<=', $param['edate'] . ' 23:59:59'];
- }
- // 查询排除的部门
- $sheji = Org::where([['path', 'like', $this->root_id . '-%'], ['name', '=', '设计部']])->value('id');
- $xiaoshou = Org::where([['path', 'like', $this->root_id . '-%'], ['name', '=', '市场部']])->value('id');
- $fanweinei = Org::whereOr([
- [['path', 'like', $this->root_id . '-%'], ['path', 'like', $this->root_id . '-' . $sheji . '-%']],
- [['path', 'like', $this->root_id . '-%'], ['path', 'like', $this->root_id . '-' . $xiaoshou . '-%']],
- ])->column('id');
- $searchEmployeeIdList = Employee::where([['org_id', 'in', $fanweinei]])->column('id');
- //如果有部门筛选把员工控制在本部门
- if ($param['org_id']) $searchEmployeeIdList = Employee::where([['org_id', 'in', $childorg]])->column('id');
- //$where[] = ['employee_id', 'in', $searchEmployeeIdList];
- $where[] = ['customer_employee_id', 'in', $searchEmployeeIdList];
- //2022-10-31辛居尚重11月1号开始正式使用
- $where[] = ['addtime', '>', date('2022-10-31 23:59:59')];
- //新增加查询记录到前一天的24点
- $sel_endtime = date('Y-m-d');
- //if (empty($param['edate']) && empty($param['sdate'])) $where[] = ['addtime', '<', date('Y-m-d', strtotime("$sel_endtime -1 days")).' 23:59:59'];
- if (!empty($param['add_wechat_time'])) {
- $newtime = explode(' - ', $param['add_wechat_time']);
- $sdate = strtotime($newtime[0]);
- $edate = strtotime($newtime[1]);
- $wechat_count = [];
- $wechat_count = Customer::where([['ext', 'not null', ''], ['ext', '<>', ''], ['add_wechat_time', '>=', date('Y-m-d', $sdate)], ['add_wechat_time', '<=', date('Y-m-d', $edate)]])->column('id');
- $cids = CustomerVisitLog::where($where)->group('customer_id')->column('customer_id');
- $wechat_count = array_intersect($cids, $wechat_count);
- $where[] = ['customer_id', 'in', $wechat_count];
- }
- //只查询客户的扩展字段更新跟量房的记录
- $where1[] = ['save_portrait_field', 'like', ['%add_wechat_time%', '%add_wechat_type%', '%group_building"%', '%live_broadcast%'], 'OR'];
- $where1[] = ['state', 'in', CustomerVisitLog::changeState('已量房', 'chaos')];
- $total = CustomerVisitLog::field("customer_id, DATE_FORMAT(addtime,'%Y-%m-%d') as date")->where($where)
- ->where(function ($query) use ($where1) {
- $query->whereOr($where1);
- })->group('customer_id,date')->count();
- $lastVisitCustomerList = CustomerVisitLog::field("customer_id,state,save_portrait_field,DATE_FORMAT(addtime,'%Y-%m-%d') as date, max(addtime) as addtime")->where($where)
- ->where(function ($query) use ($where1) {
- $query->whereOr($where1);
- })->order('date desc,addtime desc')->group('customer_id,date')->page($page, $limit)->select();
- // 获取客户信息
- $customerIdList = array_unique(array_column(empty($lastVisitCustomerList) ? [] : $lastVisitCustomerList->toArray(), 'customer_id'));
- $customerList = Customer::with(['employee', 'designer'])->where([['id', 'in', $customerIdList]])->field('id,name,designer_id,employee_id,phone,phone1,phone2,square,community_name,ext,house_delivery_time,plan_deco_time,source_id,house_type,package_id,level,age_range,house_type,deco_style,source_id')->select();
- $customerList1 = CustomerRecycle::with(['employee', 'designer'])->where([['customer_id', 'in', $customerIdList]])->field('customer_id as id,name,designer_id,employee_id,phone,phone1,phone2,square,community_name,ext,house_delivery_time,plan_deco_time,source_id,house_type,package_id,level,age_range,house_type,deco_style,source_id')->select();
- $customerList2 = CustomerDropPool::with(['employee', 'designer'])->where([['customer_id', 'in', $customerIdList]])->field('customer_id as id,name,designer_id,employee_id,phone,phone1,phone2,square,community_name,ext,house_delivery_time,plan_deco_time,source_id,house_type,package_id,level,age_range,house_type,deco_style,source_id')->select();
- $customerList = array_merge($customerList->toArray(), $customerList1->toArray(), $customerList2->toArray());
- $customerList = array_combine(array_column($customerList, 'id'), $customerList);
- $customerList = $this->emp_extfield_change($customerList);
- // 获取公司名称
- $companyName = Company::where([['root_id', '=', $this->root_id]])->value('company_name');
- $num = ($page - 1) * $limit + 1;
- // 处理数据
- $data = [];
- foreach ($lastVisitCustomerList as $c) {
- $item = [
- 'key' => $num,
- 'customer_id' => $c['customer_id'],
- ];
- if (!isset($customerList[$c['customer_id']])) {
- $data[] = $item;
- $num++;
- continue;
- }
- list($Y, $m, $d) = explode('-', $c['date']);
- $leader_arr = ['941' => '罗镐', '1847' => '刘有凤']; //馨居尚,菡萏怡景,部门负责人
- $item = [
- 'key' => $num,
- 'customer_name' => $customerList[$c['customer_id']]['name'],
- 'date' => $Y . '年' . $m . '月' . $d . '日',
- 'addtime' => $c['addtime'],
- 'company_name' => $companyName,
- 'leader' => !empty($leader_arr[$this->root_id]) ? $leader_arr[$this->root_id] : '罗镐',
- 'community_name' => $customerList[$c['customer_id']]['community_name'],
- 'measure_room_store' => $this->measureRoomStore($c['date'], $c['customer_id']),
- 'number_of_visitors' => $c['number_of_visitors'] == 0 ? '' : $c['number_of_visitors'],
- 'area' => $c['area'],
- 'ext39' => $customerList[$c['customer_id']]['ext']['house_location'],
- 'talking_about_single_time' => isset($customerList[$c['customer_id']]['ext']['talking_about_single_time']) ? $customerList[$c['customer_id']]['ext']['talking_about_single_time'] : 0,
- 'source' => isset($sourseList[$customerList[$c['customer_id']]['source_id']]) ? $sourseList[$customerList[$c['customer_id']]['source_id']] : '',
- 'square' => $customerList[$c['customer_id']]['square'],
- 'ext42' => $customerList[$c['customer_id']]['ext']['unit_number']
- ];
- //查询当天所有的修改扩展字段的记录
- $savelist = CustomerVisitLog::where([['addtime', 'between', [$c['date'] . ' 00:00:00', $c['date'] . ' 23:59:59']], ['save_portrait_field', 'like', ['%add_wechat_time%', '%add_wechat_type%', '%group_building"%', '%live_broadcast%'], 'OR'], ['customer_id', '=', $c['customer_id']]])->column('save_portrait_field');
- $day_savefild = [];
- if (!empty($savelist)) {
- foreach ($savelist as $k => $v) {
- $day_savefild = array_merge(json_decode($v, true), $day_savefild);
- }
- $day_savefild = array_unique(array_column($day_savefild, 'keyname'));
- }
- $item['day_savefild'] = $day_savefild;
- // 计算交房相差月份
- $houseDeliveryTime = strtotime($customerList[$c['customer_id']]['house_delivery_time']);
- $month = (date('Y', $houseDeliveryTime) - date('Y')) * 12 + date('m', $houseDeliveryTime) - date('m');
- $type = '0';
- $item['add_wechat_time'] = in_array('add_wechat_time', $day_savefild) ? $customerList[$c['customer_id']]['ext']['add_wechat_time'] : '';
- if ($customerList[$c['customer_id']]['ext']['add_wechat_type'] == '常规加微') {
- $type = '1';
- } elseif ($customerList[$c['customer_id']]['ext']['add_wechat_type'] == '社群加微') {
- $type = '2';
- } elseif ($customerList[$c['customer_id']]['ext']['add_wechat_type'] == '历史加微') {
- $type = '3';
- }
- if ($type !== '0' && in_array('add_wechat_type', $day_savefild)) {
- $item['house_type' . $type] = in_array($customerList[$c['customer_id']]['house_type'], ['现房', '二手房']) ? '√' : '';
- if ($item['house_type' . $type] != '√' && !empty($customerList[$c['customer_id']]['house_delivery_time'])) {
- $item['delivery_month' . $type . '_1'] = $month <= 3 ? '√' : '';
- $item['delivery_month' . $type . '_2'] = $month > 3 && $month <= 6 ? '√' : '';
- $item['delivery_month' . $type . '_3'] = $month > 6 && $month <= 12 ? '√' : '';
- $item['delivery_month' . $type . '_4'] = $month > 12 ? '√' : '';
- } else {
- $item['delivery_month' . $type . '_1'] = '';
- $item['delivery_month' . $type . '_2'] = '';
- $item['delivery_month' . $type . '_3'] = '';
- $item['delivery_month' . $type . '_4'] = '';
- }
- }
- // 设计师
- if (!empty($customerList[$c['customer_id']]['designer'])) {
- $designerOrgId = $customerList[$c['customer_id']]['designer']['org_id'];
- $item['designer_name'] = $customerList[$c['customer_id']]['designer']['name'];
- $item['designer_org'] = $orgs[$designerOrgId]['name'];
- $item['designer_leader'] = isset($leadersData[$designerOrgId]) ? implode(',', $leadersData[$designerOrgId]['leaders']) : '';
- $path = $leadersData[$designerOrgId]['path'];
- $pathList = array_filter(explode('-', $path));
- foreach ($pathList as $od) {
- if (strstr($leadersData[$od]['org_name'], '部') !== false && $leadersData[$od]['org_name'] != '设计部') {
- $level = 3;
- } else {
- $level = $leadersData[$od]['level'];
- }
- if (isset($item['employee_org_level' . $level])) $level++;
- $item['designer_leader_level' . $level] = implode(',', $leadersData[$od]['leaders']);
- $item['designer_org_level' . $level] = $leadersData[$od]['org_name'];
- }
- } else {
- $item['designer_name'] = $item['designer_org'] = $item['designer_leader'] = '';
- }
- // 员工
- if (!empty($customerList[$c['customer_id']]['employee'])) {
- $employeeOrgId = $customerList[$c['customer_id']]['employee']['org_id'];
- $item['employee_name'] = $customerList[$c['customer_id']]['employee']['name'];
- $item['employee_org'] = $orgs[$employeeOrgId]['name'];
- $item['employee_leader'] = implode(',', $leadersData[$employeeOrgId]['leaders']);
- $path = $leadersData[$employeeOrgId]['path'];
- $pathList = array_filter(explode('-', $path));
- foreach ($pathList as $od) {
- if (strstr($leadersData[$od]['org_name'], '区中区') !== false) {
- $level = 3;
- } elseif (strstr($leadersData[$od]['org_name'], '中心') !== false) {
- $level = 4;
- } elseif (strstr($leadersData[$od]['org_name'], '区') !== false) {
- $level = 2;
- } else {
- $level = $leadersData[$od]['level'];
- }
- if (isset($item['employee_org_level' . $level])) $level++;
- $item['employee_leader_level' . $level] = implode(',', $leadersData[$od]['leaders']);
- $item['employee_org_level' . $level] = $leadersData[$od]['org_name'];
- }
- // 查询直属领导是否跟踪过
- // 获取直属领导id
- $leaderIdList = $leadersData[$employeeOrgId]['leaders_ids'];
- } else {
- $item['employee_name'] = $item['employee_org'] = $item['employee_leader'] = '';
- $item['leader_visit'] = '';
- }
- // 量房验房
- $item['measure_type1'] = in_array($c['state'], [8, '已量房', '确定量房', '确认量房', '8']) ? '√' : '';
- // 手机号
- $phoneArr = array_filter([$customerList[$c['customer_id']]['phone'], $customerList[$c['customer_id']]['phone1'], $customerList[$c['customer_id']]['phone2']]);
- $item['phone'] = substr_replace(array_shift($phoneArr), '******', 3, 6);
- // 建群情况
- $jianqun = in_array('group_building', $day_savefild) ? explode(',', $customerList[$c['customer_id']]['ext']['group_building']) : [];
- $item['ext35_1'] = (in_array('1对1小群', $jianqun) || in_array('一对一小群', $jianqun)) ? '√' : '';
- $item['ext35_2'] = in_array('临时大群', $jianqun) ? '√' : '';
- $item['ext35_3'] = in_array('社群', $jianqun) ? '√' : '';
- // 直播
- $zhibo = in_array('live_broadcast', $day_savefild) ? explode(',', $customerList[$c['customer_id']]['ext']['live_broadcast']) : [];
- $item['ext36_1'] = (in_array('一对一直播', $zhibo) || in_array('1对1业务直播', $zhibo)) ? '√' : '';
- $item['ext36_2'] = in_array('1对1设计直播', $zhibo) ? '√' : '';
- $item['ext36_3'] = in_array('一对多直播', $zhibo) ? '√' : '';
- $item['ext37_1'] = !empty($item['ext36_1']) ? $customerList[$c['customer_id']]['ext']['live_broadcast_business'] : '';
- $item['ext37_2'] = !empty($item['ext36_2']) ? $customerList[$c['customer_id']]['ext']['live_broadcast_design'] : '';
- $item['ext37_3'] = !empty($item['ext36_3']) ? $customerList[$c['customer_id']]['ext']['live_broadcast_personnel'] : '';
- $data[] = $item;
- $num++;
- }
- return json(['code' => 0, 'data' => $data, 'count' => $total, 'page' => ceil($total / $limit)]);
- }
- /**
- * 总经办报表表格
- */
- public function office_table_data()
- {
- // 领导获取
- $orgLeader = Employee::where([['root_id', '=', $this->root_id], ['is_manager', '=', 1], ['state', '=', '在职']])->column('id, org_id, name');
- $orgDealLeader = [];
- foreach ($orgLeader as $leader) {
- $orgDealLeader[$leader['org_id']][] = $leader['name'];
- }
- // 查询设计师部门
- $designerOrg = Org::where([['path', 'like', $this->root_id . '-%'], ['id', "<>", $this->root_id], ['org_type', '=', 2]])->order('level desc')->column('level, id, name');
- // 部门处理
- $dealDesignerOrg = [];
- foreach ($designerOrg as $org) {
- $dealDesignerOrg[$org['level']]['name'][] = $org['name'];
- isset($dealDesignerOrg[$org['level']]['leader']) ?: $dealDesignerOrg[$org['level']]['leader'] = [];
- if (isset($orgDealLeader[$org['id']]))
- $dealDesignerOrg[$org['level']]['leader'] = array_merge($dealDesignerOrg[$org['level']]['leader'], $orgDealLeader[$org['id']]);
- }
- // 剔除末枝部门
- $del = false;
- foreach ($dealDesignerOrg as $k => $item) {
- if (!$del) {
- unset($dealDesignerOrg[$k]);
- $del = true;
- }
- }
- // 查询销售部门
- $sellerOrg = Org::where([['path', 'like', $this->root_id . '-%'], ['id', "<>", $this->root_id], ['org_type', '=', 1]])->order('level desc')->column('level, id, name');
- // 部门处理
- $dealSellerOrg = [];
- foreach ($sellerOrg as $org) {
- $dealSellerOrg[$org['level']]['name'][] = $org['name'];
- isset($dealSellerOrg[$org['level']]['leader']) ?: $dealSellerOrg[$org['level']]['leader'] = [];
- if (isset($orgDealLeader[$org['id']]))
- $dealSellerOrg[$org['level']]['leader'] = array_merge($dealSellerOrg[$org['level']]['leader'], $orgDealLeader[$org['id']]);
- }
- // 剔除末枝部门
- $del = false;
- foreach ($dealSellerOrg as $k => $item) {
- if (!$del) {
- unset($dealSellerOrg[$k]);
- $del = true;
- }
- }
- $header = $this->getOfficeHeaders();
- view::assign('header1', $header['header1']);
- view::assign('header2', $header['header2']);
- $org = Org::where([['path', 'like', request()->employee->root_id . '-%'], ['org_type', '=', 1]])->field('id,name')->select()->toArray();
- View::assign('org', $org);
- $row = [];
- foreach ($header['header1'] as $item) {
- if (isset($item['child'])) {
- foreach ($item['child'] as $c) {
- $row[] = $c;
- }
- } else {
- $row[] = $item['field'];
- }
- }
- view::assign('row', json_encode($row));
- return View::fetch();
- }
- /**
- * 获取线上跟踪客户记录表头
- */
- private function getOfficeHeaders()
- {
- // 第二行头部
- $header2 = [];
- // 设计师部门插入头部
- $header2[] = ["field" => 'customer_name', "title" => '客户名字', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'phone', "title" => '客户电话', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'ext39', "title" => '省市区', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'community_name', "title" => '楼盘', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'ext42', "title" => '门牌单元号', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'square', "title" => '面积', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'employee_name', "title" => '业务员', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'employee_org', "title" => '业务部门', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'employee_leader', "title" => '业务经理', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'employee_org_level4', "title" => '业务中心', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'employee_leader_level4', "title" => '业务总监', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'employee_org_level3', "title" => '区中区', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'employee_leader_level3', "title" => '区中区副总', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'employee_org_level2', "title" => '大区', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'employee_leader_level2', "title" => '大区副总', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'designer_name', "title" => '设计师', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'designer_org', "title" => '设计部门', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'designer_leader', "title" => '设计经理', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'designer_org_level2', "title" => '设计中心', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'designer_leader_level2', "title" => '设计总监', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'designer_leader_level1', "title" => '设计副总', "align" => 'center', "class" => "bgEEECE1"];
- // 加微
- $header2[] = ["field" => 'house_type1', "title" => '现房', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month1_1', "title" => '0-3个月', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month1_2', "title" => '3-6个月', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month1_3', "title" => '6-12个月', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month1_4', "title" => '12个月以上', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'house_type2', "title" => '现房', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month2_1', "title" => '0-3个月', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month2_2', "title" => '3-6个月', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month2_3', "title" => '6-12个月', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month2_4', "title" => '12个月以上', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'house_type3', "title" => '现房', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month3_1', "title" => '0-3个月', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month3_2', "title" => '3-6个月', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month3_3', "title" => '6-12个月', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month3_4', "title" => '12个月以上', "align" => 'center', "class" => "bgDCE6F1"];
- // 建群
- $header2[] = ["field" => 'ext35_1', "title" => '1对1小群', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'ext35_2', "title" => '临时大群', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'ext35_3', "title" => '社群', "align" => 'center', "class" => "bgEEECE1"];
- // 直播
- $header2[] = ["field" => 'ext36_1', "title" => '1对1业务直播', "align" => 'center', "class" => "bgF2DCDB"];
- //$header2[] = ["field" => 'ext37_1', "title" => '业务员', "align" => 'center', "class" => "bgF2DCDB"];
- $header2[] = ["field" => 'ext36_2', "title" => '1对1设计直播', "align" => 'center', "class" => "bgF2DCDB"];
- //$header2[] = ["field" => 'ext37_2', "title" => '设计师', "align" => 'center', "class" => "bgF2DCDB"];
- $header2[] = ["field" => 'ext36_3', "title" => '一对多直播', "align" => 'center', "class" => "bgF2DCDB"];
- //$header2[] = ["field" => 'ext37_3', "title" => '直播人员', "align" => 'center', "class" => "bgF2DCDB"];
- // 插入销售部门
- $employeeChild = ['employee_name', 'employee_org', 'employee_leader', 'employee_org_level4', 'employee_leader_level4', 'employee_org_level3', 'employee_leader_level3', 'employee_org_level2', 'employee_leader_level2'];
- // 设计部门
- $designerChild = ['designer_name', 'designer_org', 'designer_leader', 'designer_org_level2', 'designer_leader_level2', 'designer_leader_level1'];
- // 第一行头部
- $header1 = [];
- $header1[] = ["type" => 'key', "field" => 'key', "title" => '序号', "align" => 'center', "rowspan" => 2, "class" => "bgEEECE1"];
- $header1[] = ["field" => 'date', "title" => '日期', "align" => 'center', "rowspan" => 2, "class" => "bgEEECE1"];
- $header1[] = ["field" => "", "child" => ['customer_name', 'phone', 'ext39', 'community_name', 'ext42', 'square'], "title" => '客户信息 ', "align" => 'center', "colspan" => 6, "class" => "bgEEECE1"];
- $header1[] = ["field" => 'company_name', "title" => '公司', "align" => 'center', "rowspan" => 2, "class" => "bgA6A6A6"];
- $header1[] = ["field" => 'leader', "title" => '负责人', "align" => 'center', "rowspan" => 2, "class" => "bgA6A6A6"];
- $header1[] = ["field" => "", "child" => $employeeChild, "title" => '营销', "align" => 'center', "colspan" => 9, "class" => "bgEEECE1"];
- $header1[] = ["field" => "", "child" => $designerChild, "title" => '设计', "align" => 'center', "colspan" => 6, "class" => "bgEEECE1"];
- $header1[] = ["field" => "", "child" => ['house_type1', 'delivery_month1_1', 'delivery_month1_2', 'delivery_month1_3', 'delivery_month1_4'], "title" => '常规加微<br>(交房时间)', "align" => 'center', "colspan" => 5, "class" => "bgDCE6F1"];
- $header1[] = ["field" => "", "child" => ['house_type2', 'delivery_month2_1', 'delivery_month2_2', 'delivery_month2_3', 'delivery_month2_4'], "title" => '社群加微<br>(交房时间)', "align" => 'center', "colspan" => 5, "class" => "bgDCE6F1"];
- $header1[] = ["field" => "", "child" => ['house_type3', 'delivery_month3_1', 'delivery_month3_2', 'delivery_month3_3', 'delivery_month3_4'], "title" => '历史加微<br>(交房时间)', "align" => 'center', "colspan" => 5, "class" => "bgDCE6F1"];
- $header1[] = ["field" => "add_wechat_time", "title" => '加微时间', "align" => 'center', "rowspan" => 2, "class" => "bgEEECE1"];
- $header1[] = ["field" => "", "child" => ['ext35_1', 'ext35_2', 'ext35_3'], "title" => '建群', "align" => 'center', "colspan" => 3, "class" => "bgEEECE1"];
- $header1[] = ["field" => "", "child" => ['ext36_1', 'ext36_2', 'ext36_3'], "title" => '直播', "align" => 'center', "colspan" => 3, "class" => "bgF2DCDB"];
- $header1[] = ["field" => "measure_type1", "title" => '量房验房', "align" => 'center', "rowspan" => 2, "class" => "bgEEECE1"];
- return ['header1' => $header1, 'header2' => $header2];
- }
- /**
- * 检测客户是否是外场转内场新客户
- */
- public function getIsNewCusomerVisitAfterActivity($date, $customerId)
- {
- $where = [];
- $where[] = ['addtime', '<', $date . ' 23:59:59'];
- $where[] = ['customer_id', '=', $customerId];
- $state1 = CustomerVisitLog::changeState('已到店', 'chaos');
- $where[] = ['state', 'in', $state1];
- // 查询日期必须到店
- $had = CustomerVisitLog::where($where)->order('addtime desc')->column('addtime, aid');
- // 是否多次到店或未到店
- if (count($had) != 1) return '';
- $lastTime = strtotime($had[0]['addtime']);
- // 判断到店日期是否是所选日期
- if (date('Y-m-d', $lastTime) != $date) return '';
- // 判断是否参加过活动
- $aidExit = CustomerVisitLog::where([
- ['addtime', '<', $date . ' 23:59:59'],
- ['customer_id', '=', $customerId]
- ])->order('addtime desc')->column('aid');
- if (empty($aidExit)) return '';
- $nei = ModelActivity::where([['id', 'in', $aidExit], ['cate', '=', 1]])->count();
- if ($nei) return '√';
- return '';
- }
- /**
- * 量房转到店
- */
- public function measureRoomStore($date, $customer_id)
- {
- $where = [];
- //单日内先量房,在到店
- $where[] = ['addtime', 'like', '%' . $date . '%'];
- $where[] = ['customer_id', '=', $customer_id];
- $state1 = CustomerVisitLog::changeState('确认量房', 'chaos');
- $state2 = CustomerVisitLog::changeState('确认到店', 'chaos');
- $where[] = ['state', 'in', array_merge($state1, $state2)];
- $arr = CustomerVisitLog::where($where)->order('id asc')->column('id,state');
- $measure = $store = 0;
- foreach ($arr as $k => $v) {
- if ($measure == 0 && in_array($v['state'], $state1)) {
- $measure = $v['id'];
- }
- if ($store == 0 && in_array($v['state'], $state2)) {
- $store = $v['id'];
- }
- }
- return ($measure > 0 && $store > 0 && $measure < $store) ? '√' : '';
- }
- /**
- * 获取客户跟进数据表表头
- */
- public function table()
- {
- // 领导获取
- $orgLeader = Employee::where([['root_id', '=', $this->root_id], ['is_manager', '=', 1], ['state', '=', '在职']])->column('id, org_id, name');
- $orgDealLeader = [];
- foreach ($orgLeader as $leader) {
- $orgDealLeader[$leader['org_id']][] = $leader['name'];
- }
- // 查询设计师部门
- $designerOrg = Org::where([['path', 'like', $this->root_id . '-%'], ['id', "<>", $this->root_id], ['org_type', '=', 2]])->order('level desc')->column('level, id, name');
- // 部门处理
- $dealDesignerOrg = [];
- foreach ($designerOrg as $org) {
- $dealDesignerOrg[$org['level']]['name'][] = $org['name'];
- isset($dealDesignerOrg[$org['level']]['leader']) ?: $dealDesignerOrg[$org['level']]['leader'] = [];
- if (isset($orgDealLeader[$org['id']]))
- $dealDesignerOrg[$org['level']]['leader'] = array_merge($dealDesignerOrg[$org['level']]['leader'], $orgDealLeader[$org['id']]);
- }
- // 剔除末枝部门
- $del = false;
- foreach ($dealDesignerOrg as $k => $item) {
- if (!$del) {
- unset($dealDesignerOrg[$k]);
- $del = true;
- }
- }
- // 查询销售部门
- $sellerOrg = Org::where([['path', 'like', $this->root_id . '-%'], ['id', "<>", $this->root_id], ['org_type', '=', 1]])->order('level desc')->column('level, id, name');
- // 部门处理
- $dealSellerOrg = [];
- foreach ($sellerOrg as $org) {
- $dealSellerOrg[$org['level']]['name'][] = $org['name'];
- isset($dealSellerOrg[$org['level']]['leader']) ?: $dealSellerOrg[$org['level']]['leader'] = [];
- if (isset($orgDealLeader[$org['id']]))
- $dealSellerOrg[$org['level']]['leader'] = array_merge($dealSellerOrg[$org['level']]['leader'], $orgDealLeader[$org['id']]);
- }
- // 剔除末枝部门
- $del = false;
- foreach ($dealSellerOrg as $k => $item) {
- if (!$del) {
- unset($dealSellerOrg[$k]);
- $del = true;
- }
- }
- // // 设计师部门数量
- // $designerCount = count($dealDesignerOrg) * 2 + 3;
- // $sellerCount = count($dealSellerOrg) * 2 + 3;
- // View::assign('dealDesignerOrg', $dealDesignerOrg);
- // View::assign('designerCount', $designerCount);
- // View::assign('dealSellerOrg', $dealSellerOrg);
- // View::assign('sellerCount', $sellerCount);
- $header = $this->getVisitLogHeaders();
- view::assign('header1', $header['header1']);
- view::assign('header2', $header['header2']);
- $org = Org::where([['path', 'like', request()->employee->root_id . '-%'], ['org_type', '=', 1]])->field('id,name')->select()->toArray();
- View::assign('org', $org);
- $row = [];
- foreach ($header['header1'] as $item) {
- if (isset($item['child'])) {
- foreach ($item['child'] as $c) {
- $row[] = $c;
- }
- } else {
- $row[] = $item['field'];
- }
- }
- view::assign('row', json_encode($row));
- return View::fetch('table_data');
- }
- private function tree($data, $pid = 0)
- {
- $new_arr = [];
- foreach ($data as $k => $v) {
- if ($v['pid'] == $pid) {
- $children = $this->tree($data, $v['id']);
- $v['children'] = $children;
- $new_arr[] = $v;
- }
- }
- return $new_arr;
- }
- /*
- * 人员树
- */
- public function get_person()
- {
- $ids = input('id', '');
- $root_id = request()->employee->root_id;
- //树形
- $where = [
- ['path', 'like', $root_id . '-%'],
- ['status', '=', 1]
- ];
- $allnodes = Org::where($where)->field('id value,id,pid,name')->order('level asc, id asc')->select()->toArray();
- $tree = $this->tree($allnodes, 0);
- return json($tree);
- }
- /**
- * 获取线上跟踪客户记录表头
- */
- private function getVisitLogHeaders()
- {
- // 第二行头部
- $header2 = [];
- // 设计师部门插入头部
- $header2[] = ["field" => 'customer_name', "title" => '客户名字', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'phone', "title" => '客户电话', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'ext39', "title" => '省市区', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'community_name', "title" => '楼盘', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'ext42', "title" => '门牌单元号', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'square', "title" => '面积', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'employee_name', "title" => '业务员', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'employee_org', "title" => '业务部门', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'employee_leader', "title" => '业务经理', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'employee_org_level4', "title" => '业务中心', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'employee_leader_level4', "title" => '业务总监', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'employee_org_level3', "title" => '区中区', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'employee_leader_level3', "title" => '区中区副总', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'employee_org_level2', "title" => '大区', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'employee_leader_level2', "title" => '大区副总', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'designer_name', "title" => '设计师', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'designer_org', "title" => '设计部门', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'designer_leader', "title" => '设计经理', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'designer_org_level2', "title" => '设计中心', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'designer_leader_level2', "title" => '设计总监', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'designer_leader_level1', "title" => '设计副总', "align" => 'center', "class" => "bgEEECE1"];
- // 加微
- $header2[] = ["field" => 'house_type1', "title" => '现房', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month1_1', "title" => '0-3个月', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month1_2', "title" => '3-6个月', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month1_3', "title" => '6-12个月', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month1_4', "title" => '12个月以上', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'house_type2', "title" => '现房', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month2_1', "title" => '0-3个月', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month2_2', "title" => '3-6个月', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month2_3', "title" => '6-12个月', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month2_4', "title" => '12个月以上', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'house_type3', "title" => '现房', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month3_1', "title" => '0-3个月', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month3_2', "title" => '3-6个月', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month3_3', "title" => '6-12个月', "align" => 'center', "class" => "bgDCE6F1"];
- $header2[] = ["field" => 'delivery_month3_4', "title" => '12个月以上', "align" => 'center', "class" => "bgDCE6F1"];
- // 建群
- $header2[] = ["field" => 'ext35_1', "title" => '1对1小群', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'ext35_2', "title" => '临时大群', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'ext35_3', "title" => '社群', "align" => 'center', "class" => "bgEEECE1"];
- // 直播
- $header2[] = ["field" => 'ext36_1', "title" => '1对1业务直播', "align" => 'center', "class" => "bgF2DCDB"];
- $header2[] = ["field" => 'ext37_1', "title" => '业务员', "align" => 'center', "class" => "bgF2DCDB"];
- $header2[] = ["field" => 'ext36_2', "title" => '1对1设计直播', "align" => 'center', "class" => "bgF2DCDB"];
- $header2[] = ["field" => 'ext37_2', "title" => '设计师', "align" => 'center', "class" => "bgF2DCDB"];
- $header2[] = ["field" => 'ext36_3', "title" => '一对多直播', "align" => 'center', "class" => "bgF2DCDB"];
- $header2[] = ["field" => 'ext37_3', "title" => '直播人员', "align" => 'center', "class" => "bgF2DCDB"];
- // 量房验房
- $header2[] = ["field" => 'measure_type2', "title" => '量房验房报告', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'measure_type3', "title" => '客户需求表', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'leader_visit', "title" => '经理是否回访', "align" => 'center', "class" => "bgEEECE1"];
- // 到店
- $header2[] = ["field" => 'outfield_activities', "title" => '外场活动到店', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'outfield_infield', "title" => '内场直接到店', "align" => 'center', "class" => "bgEEECE1"];
- //见面方式
- $header2[] = ["field" => 'actmeet_type1', "title" => '外场活动', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'actmeet_type2', "title" => '茶楼见面', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'actmeet_type3', "title" => '网谈登记', "align" => 'center', "class" => "bgEEECE1"];
- // 管理到店数据
- $header2[] = ["field" => 'deposit_money2', "title" => '线上定金', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'deposit_money1', "title" => '线下定金', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'package', "title" => '爆品定金(10%以上)', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'measure_type1', "title" => '量房验房', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'visit_number1', "title" => '一次到店<br>(内场到店)', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'visit_number2', "title" => '二次到店', "align" => 'center', "class" => "bgEEECE1"];
- $header2[] = ["field" => 'visit_number3', "title" => '三次及以上到店', "align" => 'center', "class" => "bgEEECE1"];
- // 插入销售部门
- $employeeChild = ['employee_name', 'employee_org', 'employee_leader', 'employee_org_level4', 'employee_leader_level4', 'employee_org_level3', 'employee_leader_level3', 'employee_org_level2', 'employee_leader_level2'];
- // 设计部门
- $designerChild = ['designer_name', 'designer_org', 'designer_leader', 'designer_org_level2', 'designer_leader_level2', 'designer_leader_level1'];
- // 第一行头部
- $header1 = [];
- $header1[] = ["type" => 'key', "field" => 'key', "title" => '序号', "align" => 'center', "rowspan" => 2, "class" => "bgEEECE1"];
- $header1[] = ["field" => 'date', "title" => '日期', "align" => 'center', "rowspan" => 2, "class" => "bgEEECE1"];
- $header1[] = ["field" => "", "child" => ['customer_name', 'phone', 'ext39', 'community_name', 'ext42', 'square'], "title" => '客户信息 ', "align" => 'center', "colspan" => 6, "class" => "bgEEECE1"];
- $header1[] = ["field" => 'company_name', "title" => '公司', "align" => 'center', "rowspan" => 2, "class" => "bgA6A6A6"];
- $header1[] = ["field" => 'leader', "title" => '负责人', "align" => 'center', "rowspan" => 2, "class" => "bgA6A6A6"];
- $header1[] = ["field" => "", "child" => $employeeChild, "title" => '营销', "align" => 'center', "colspan" => 9, "class" => "bgEEECE1"];
- $header1[] = ["field" => "", "child" => $designerChild, "title" => '设计', "align" => 'center', "colspan" => 6, "class" => "bgEEECE1"];
- $header1[] = ["field" => "", "child" => ['house_type1', 'delivery_month1_1', 'delivery_month1_2', 'delivery_month1_3', 'delivery_month1_4'], "title" => '常规加微<br>(交房时间)', "align" => 'center', "colspan" => 5, "class" => "bgDCE6F1"];
- $header1[] = ["field" => "", "child" => ['house_type2', 'delivery_month2_1', 'delivery_month2_2', 'delivery_month2_3', 'delivery_month2_4'], "title" => '社群加微<br>(交房时间)', "align" => 'center', "colspan" => 5, "class" => "bgDCE6F1"];
- $header1[] = ["field" => "", "child" => ['house_type3', 'delivery_month3_1', 'delivery_month3_2', 'delivery_month3_3', 'delivery_month3_4'], "title" => '历史加微<br>(交房时间)', "align" => 'center', "colspan" => 5, "class" => "bgDCE6F1"];
- $header1[] = ["field" => "add_wechat_time", "title" => '加微时间', "align" => 'center', "rowspan" => 2, "class" => "bgEEECE1"];
- $header1[] = ["field" => "plan_month_day", "title" => '高意向到店客户<br>(1个月内装修)', "align" => 'center', "rowspan" => 2, "class" => "bgEEECE1"];
- $header1[] = ["field" => "", "child" => ['ext35_1', 'ext35_2', 'ext35_3'], "title" => '建群', "align" => 'center', "colspan" => 3, "class" => "bgEEECE1"];
- $header1[] = ["field" => "", "child" => ['ext36_1', 'ext37_1', 'ext36_2', 'ext37_2', 'ext36_3', 'ext37_3'], "title" => '直播', "align" => 'center', "colspan" => 6, "class" => "bgF2DCDB"];
- $header1[] = ["field" => "", "child" => ['measure_type2', 'measure_type3', 'leader_visit'], "title" => '量房验房', "align" => 'center', "colspan" => 3, "class" => "bgEEECE1"];
- $header1[] = ["field" => '', "child" => ['outfield_activities', 'visit_number1'], "title" => '到店', "align" => 'center', "colspan" => 2, "class" => "bgFDE9D9"];
- $header1[] = ["field" => '', "child" => ['actmeet_type1', 'actmeet_type2', 'actmeet_type3'], "title" => '见面方式', "align" => 'center', "colspan" => 3, "class" => "bgEEECE1"];
- $header1[] = ["field" => '', "child" => ['deposit_money2', 'deposit_money1', 'package', 'measure_type1', 'visit_number1', 'visit_number2', 'visit_number3'], "title" => '管理到店数据', "align" => 'center', "colspan" => 7, "class" => "bgFDE9D9"];
- $header1[] = ["field" => 'number_of_visitors', "title" => '到店人数', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"];
- $header1[] = ["field" => 'signature_money', "title" => '合同价', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"];
- return ['header1' => $header1, 'header2' => $header2];
- }
- /**
- * 渠道统计
- * 昨日,近一周,近一月
- */
- public function channelStatistics()
- {
- return View::fetch();
- }
- /**
- * 渠道统计
- * 昨日,近一周,近一月
- */
- public function channelStatisticsList()
- {
- $request = request();
- $root_id = $request->employee->root_id;
- $team_orgs = orgSubIds($request->employee->org_id);
- $param = Request()->only(['page' => 1, 'limit' => 10, 'start_date', 'keyword']);
- $startDateTime = date('Y-m-d H:i:s', 0);
- $endDateTime = date('Y-m-d H:i:s', time());
- if (!empty($param['start_date'])) {
- $count_dates = explode(' - ', $param['start_date']);
- $startDateTime = date('Y-m-d H:i:s', strtotime($count_dates[0]));
- $endDateTime = date('Y-m-d H:i:s', strtotime($count_dates[1]) + 86400);
- }
- $soud_where[] = ['root_id', '=', $root_id];
- setCondition($param, ['keyword', 'source'], ['like', '%VALUE%'], $soud_where);
- $org_employee = Employee::where([['org_id', 'in', $team_orgs], ['state', '=', '在职'], ['uid', '>', 0]])->column('id');
- if (!empty($param['source_id'])) $soud_where[] = ['id', 'in', explode(',', $param['source_id'])];
- $soud_list = CustomerSource::field('id,source as name')->where($soud_where)->select()->toArray();
- $where[] = ['addtime', 'between', [$startDateTime, $endDateTime]];
- if (!empty($param['employee_id'])) $org_employee = [$param['employee_id']];
- $where[] = ['employee_id', 'in', $org_employee];
- $exten_where[] = ['root_id', '=', $root_id];
- $exten_where[] = ['addtime', 'between', [$startDateTime, $endDateTime]];
- if (!empty($param['employee_id'])) $exten_where[] = ['id', '=', 0];
- $exten_list = CustomerExtension::with(['source' => function ($query) {
- $query->field('id,source');
- }])->where($exten_where)->select()->toArray();
- $t = ['number' => 0, 'clue_count' => 0, 'valid_count' => 0, 'meet_count' => 0, 'delivery_count' => 0, 'order_count' => 0, 'maika_count' => 0, 'order_money' => 0, 'meet_grawth' => '0%', 'valid_grawth' => '0%', 'delivery_grawth' => '0%', 'order_grawth' => '0%'];
- $state1 = CustomerVisitLog::changeState('确认到店', 'chaos');
- $state2 = CustomerVisitLog::changeState('已交定', 'chaos');
- $state3 = CustomerVisitLog::changeState('已签单', 'chaos');
- $state5 = Customer::changeState('无效', 'chaos');
- $state6 = Customer::changeState('待确认', 'chaos');
- $state7 = CustomerVisitLog::changeState('已量房', 'chaos');
- $state8 = CustomerVisitLog::changeState('已到场', 'chaos');
- $state9 = CustomerVisitLog::changeState('已卖卡', 'chaos');
- $ismeet = [];
- foreach ($soud_list as $key => $val) {
- $soud_list[$key]['employee_id'] = !empty($param['employee_id']) ? $param['employee_id'] : '';
- $exten_money = $exten_show = $exten_click = $clue_cont = $valid = $meet = $deposit = $sign = $basic_money = $maika_count = 0;
- $validids = $cusids = [];
- $customer_list = Customer::where($where)->where([['source_id', '=', $val['id']], ['state', 'not in', $state6]])->column('state', 'id');
- $clue_ids = Customer::where($where)->where([['source_id', '=', $val['id']]])->column('id');
- $clue_cont = count($clue_ids);
- foreach ($customer_list as $k => $v) {
- if (!in_array($v, $state5)) {
- $cusids[] = $k;
- $valid++;
- }
- }
- unset($customer_list);
- $validids = $cusids;
- //查询无效的客户
- $invalidcus = CustomerInvalidLog::where([['employee_id', 'in', $org_employee], ['root_id', '=', $root_id], ['source_id', '=', $val['id']], ['cus_addtime', 'between', [$startDateTime, $endDateTime]]])->column('customer_id,employee_id,status');
- foreach ($invalidcus as $k => $v) {
- if (!in_array($v['customer_id'], $validids)) {
- if ($v['status'] == 1) {
- $valid++;
- $validids[] = $v['customer_id'];
- }
- }
- if (!in_array($v['customer_id'], $clue_ids)) {
- $clue_cont++;
- $clue_ids[] = $v['customer_id'];
- }
- }
- unset($clue_ids, $validids, $cusids);
- foreach ($exten_list as $k => $v) {
- if ($v['source_id'] == $val['id']) {
- $exten_money += $v['money'];
- $exten_show += $v['show'];
- $exten_click += $v['click'];
- }
- }
- $visitlog_list = CustomerVisitLog::hasWhere('customer', ['source_id' => $val['id']])
- ->where([['CustomerVisitLog.customer_employee_id', 'in', $org_employee], ['CustomerVisitLog.state', '<>', 'null'], ['CustomerVisitLog.confirm_date', 'between', [$startDateTime, $endDateTime]]])
- ->order('CustomerVisitLog.addtime desc')->column('CustomerVisitLog.id,CustomerVisitLog.customer_id,CustomerVisitLog.state,CustomerVisitLog.money');
- $metids = [];
- foreach ($visitlog_list as $k => $v) {
- if (in_array($v['state'], array_merge($state1, $state7, $state8))) $metids[] = $v['customer_id'];
- }
- $yesids = !empty(array_unique($metids)) ? $this->selBeforelog(array_unique($metids), $startDateTime) : [];
- $depositIds = []; //交定
- $signIds = []; //签单
- $maikaIds = []; //卖卡
- foreach ($visitlog_list as $k => $v) {
- if (in_array($v['state'], array_merge($state1, $state7, $state8)) && !in_array($v['customer_id'], $ismeet) && in_array($v['customer_id'], $yesids)) {
- $meet++;
- $ismeet[] = $v['customer_id'];
- }
- if (in_array($v['state'], $state2) && !in_array($v['customer_id'], $depositIds)) {
- $deposit++;
- $depositIds[] = $v['customer_id'];
- }
- if (in_array($v['state'], $state3) && !in_array($v['customer_id'], $signIds)) {
- $sign++;
- $basic_money += $v['money'];
- $signIds[] = $v['customer_id'];
- }
- if (in_array($v['state'], $state9) && !in_array($v['customer_id'], $maikaIds)) {
- $maika_count++;
- $maikaIds[] = $v['customer_id'];
- }
- }
- unset($visitlog_list);
- $soud_list[$key]['source'] = $val['name'];
- $soud_list[$key]['clue_count'] = $clue_cont;
- $soud_list[$key]['valid_count'] = $valid;
- $soud_list[$key]['meet_count'] = $meet;
- $soud_list[$key]['delivery_count'] = $deposit;
- $soud_list[$key]['order_count'] = $sign;
- $soud_list[$key]['maika_count'] = $maika_count;
- $soud_list[$key]['order_money'] = $basic_money;
- $soud_list[$key]['meet_grawth'] = !empty($meet) && !empty($clue_cont) ? round($meet / $clue_cont * 100, 2) . '%' : '0%';
- $soud_list[$key]['valid_grawth'] = $valid && $clue_cont ? round($valid / $clue_cont * 100, 2) . '%' : '0%';
- $soud_list[$key]['delivery_grawth'] = !empty($deposit) && !empty($meet) ? round($deposit / $meet * 100, 2) . '%' : '0%';
- $soud_list[$key]['order_grawth'] = !empty($sign) && !empty($meet) ? round($sign / $meet * 100, 2) . '%' : '0%';
- //总数
- $t['number']++;
- $t['clue_count'] += $clue_cont;
- $t['valid_count'] += $valid;
- $t['meet_count'] += $meet;
- $t['delivery_count'] += $deposit;
- $t['order_count'] += $sign;
- $t['maika_count'] += $maika_count;
- $t['order_money'] += $basic_money;
- }
- $t['meet_grawth'] = ($t['clue_count'] == 0 || $t['meet_count'] == 0) ? '0%' : round($t['meet_count'] / $t['clue_count'] * 100, 2) . '%';
- $t['valid_grawth'] = ($t['valid_count'] == 0 || $t['clue_count'] == 0) ? '0%' : round($t['valid_count'] / $t['clue_count'] * 100, 2) . '%';
- $t['delivery_grawth'] = ($t['delivery_count'] == 0 || $t['meet_count'] == 0) ? '0%' : round($t['delivery_count'] / $t['meet_count'] * 100, 2) . '%';
- $t['order_grawth'] = ($t['order_count'] == 0 || $t['meet_count'] == 0) ? '0%' : round($t['order_count'] / $t['meet_count'] * 100, 2) . '%';
- return json(['code' => 0, 'data' => $soud_list, 'header' => $t, 'count' => 0, 'msg' => '获取成功']);
- }
- public function selBeforelog($metids, $firstday)
- {
- $statday = '2021-12-01 00:00:00';
- $state1 = CustomerVisitLog::changeState('确认到店', 'chaos');
- $state2 = CustomerVisitLog::changeState('已到场', 'chaos');
- $state3 = CustomerVisitLog::changeState('已量房', 'chaos');
- $q_where[] = ['customer_id', 'in', $metids];
- $q_where[] = ['state', 'in', array_merge($state1, $state2, $state3)];
- $q_where[] = ['addtime', 'between', [$statday, $firstday]];
- $qianvslog = CustomerVisitLog::where($q_where)->group('customer_id')->column('customer_id');
- $yesids = array_diff($metids, $qianvslog);
- return $yesids;
- }
- /**
- * 渠道统计合计
- */
- public function channelStatisticsTotal()
- {
- //合计
- $param = Request()->only(['start_date' => '', 'end_date' => '', 'keyword' => '']);
- $root_id = request()->employee->root_id;
- $startDateTime = date('Y-m-d H:i:s', 0);
- $endDateTime = date('Y-m-d H:i:s', time());
- if (!empty($param['start_date'])) {
- $count_dates = explode(' - ', $param['start_date']);
- $startDateTime = date('Y-m-d H:i:s', strtotime($count_dates[0]));
- $endDateTime = date('Y-m-d H:i:s', strtotime($count_dates[1]) + 86400);
- }
- //渠道列表
- $where[] = ['root_id', '=', $root_id];
- if ($param['keyword']) {
- $where[] = ['source', 'like', '%' . $param['keyword'] . '%'];
- }
- //有效量,确认到场,确认量房,确认到店,交定签单
- $state1 = CustomerVisitLog::changeState('确认到店', 'chaos');
- $state2 = CustomerVisitLog::changeState('确认量房', 'chaos');
- $state3 = CustomerVisitLog::changeState('确认到场', 'chaos');
- $state4 = CustomerVisitLog::changeState('交定', 'chaos');
- $state5 = CustomerVisitLog::changeState('签单', 'chaos');
- $state6 = CustomerVisitLog::changeState('待确认', 'chaos');
- $state7 = CustomerVisitLog::changeState('无效', 'chaos');
- $state8 = CustomerVisitLog::changeState('已卖卡', 'chaos');
- // 见面状态
- $make_state0 = array_merge($state1, $state2, $state3);
- $make_state1 = array_merge($state1, $state2, $state3, $state4, $state5);
- $make_state2 = array_merge($state1, $state2, $state3, $state4, $state5, $state8);
- //员工id
- $eids = Employee::where([['root_id', '=', $root_id], ['uid', '>', 0], ['state', '=', '在职']])->column('id');
- //渠道ID
- $sourceId = CustomerSource::where($where)->column('id');
- //查询搜索日期之前的见面量
- $beforeId = [];
- if (!empty($param['start_date'])) {
- $vis_where = [['state', 'in', $make_state2], ['addtime', '<', $startDateTime]];
- $beforeList = Customer::with(['visitLog' => function ($query) use ($vis_where) {
- $query->where($vis_where)->field('customer_id,state,money');
- }])
- ->where([['source_id', 'in', $sourceId], ['employee_id', 'in', $eids]])
- ->where(function ($query) {
- $not_sure = Customer::changeState('待确认', 'chaos');
- $or1[] = ['crm_res_id', 'null', null];
- $or2[] = ['crm_res_id', 'not null', null];
- $or2[] = ['state', 'not in', $not_sure];
- $query->whereOr([$or1, $or2]);
- })->field('id,source_id')->select()->toArray();
- foreach ($beforeList as $v) {
- if ($v['visitLog']) $beforeId[] = $v['id'];
- }
- }
- $vis_where = [['state', 'in', $make_state2], ['addtime', '>=', $startDateTime], ['addtime', '<', $endDateTime]];
- $customerList = Customer::with(['visitLog' => function ($query) use ($vis_where) {
- $query->where($vis_where)->field('customer_id,state,money');
- }])
- ->where([['source_id', 'in', $sourceId], ['employee_id', 'in', $eids]])
- ->where(function ($query) {
- $not_sure = Customer::changeState('待确认', 'chaos');
- $or1[] = ['crm_res_id', 'null', null];
- $or2[] = ['crm_res_id', 'not null', null];
- $or2[] = ['state', 'not in', $not_sure];
- $query->whereOr([$or1, $or2]);
- })->field('id,source_id')->select()->toArray();
- $data['source_count'] = count($sourceId); //渠道总数
- $data['clue_count'] = 0; //线索总数
- $data['valid_count'] = 0; //有效线索数量
- $data['meet_count'] = 0; //见面数量
- $data['delivery_count'] = 0; //交定数量
- $data['order_count'] = 0; //签单数量
- $data['maika_count'] = 0; //卖卡数量
- $tmp_valid_count = $tmp_meet_count = $tmp_delivery_count = $tmp_order_count = $tmp_maika_count = [];
- foreach ($customerList as $v) {
- $data['clue_count'] += 1; //线索量
- $tmp_valid_count[$v['source_id']][] = 0; //有效量
- $tmp_meet_count[$v['source_id']][] = 0; //见面
- $tmp_delivery_count[$v['source_id']][] = 0; //交定
- $tmp_order_count[$v['source_id']][] = 0; //签单量
- $tmp_maika_count[$v['source_id']][] = 0; //卖卡
- foreach ($v['visitLog'] as $tmp) {
- if (!in_array($v['id'], $tmp_valid_count[$v['source_id']]) && in_array($tmp['state'], $make_state2)) {
- $tmp_valid_count[$v['source_id']][] = $v['id']; //有效量
- $data['valid_count'] += 1;
- }
- if (!in_array($v['id'], $tmp_meet_count[$v['source_id']]) && in_array($tmp['state'], $make_state0) && !in_array($v['id'], $beforeId)) {
- $tmp_meet_count[$v['source_id']][] = $v['id']; //见面
- $data['meet_count'] += 1;
- }
- if (!in_array($v['id'], $tmp_delivery_count[$v['source_id']]) && in_array($tmp['state'], $state4)) {
- $tmp_delivery_count[$v['source_id']][] = $v['id']; //交定
- $data['delivery_count'] += 1;
- }
- if (!in_array($v['id'], $tmp_order_count[$v['source_id']]) && in_array($tmp['state'], $state5)) {
- $tmp_order_count[$v['source_id']][] = $v['id']; //签单量
- $data['order_count'] += 1;
- }
- if (!in_array($v['id'], $tmp_maika_count) && in_array($tmp['state'], $state8)) {
- $tmp_maika_count[$v['source_id']][] = $v['id']; //卖卡
- $data['maika_count'] += 1;
- }
- }
- }
- $data['valid_grawth'] = $data['clue_count'] == 0 ? '0%' : round($data['valid_count'] / $data['clue_count'] * 100, 2) . '%'; //有效率
- if ($data['valid_count'] > 0) {
- $data['meet_grawth'] = round($data['meet_count'] / $data['valid_count'] * 100, 2) . '%';
- } else {
- $data['meet_grawth'] = '0%';
- }
- if ($data['meet_count'] > 0) {
- $data['delivery_grawth'] = round($data['delivery_count'] / $data['meet_count'] * 100, 2) . '%';
- $data['order_grawth'] = round($data['order_count'] / $data['meet_count'] * 100, 2) . '%';
- } else {
- $data['delivery_grawth'] = '0%';
- $data['order_grawth'] = '0%';
- }
- return json(['code' => 0, 'data' => $data, 'msg' => '操作成功']);
- }
- /**
- * 线上巡店查询结果导出
- */
- public function export($m)
- {
- $typeList = [
- 'newStatisticsExport' => ['headerMethod' => 'getNewVisitLogHeaders', 'dataMethod' => 'new_customer_statistics'],
- 'officeStatisticsExport' => ['headerMethod' => 'getOfficeHeaders', 'dataMethod' => 'officeStatistics'],
- 'statisticsExport' => ['headerMethod' => 'getVisitLogHeaders', 'dataMethod' => 'customer_statistics'],
- ];
- if (!isset($typeList[$m])) {
- json(['code' => 1, 'msg' => '类型不存在'])->send();
- return;
- }
- $param = Request::post();
- $filename = uniqid();
- $log = [
- 'root_id' => request()->employee->root_id,
- 'file' => $filename . '.csv',
- 'type' => $m,
- 'employee_id' => request()->employee->id,
- 'search' => json_encode($param)
- ];
- $exportLog = ExportLog::create($log);
- json(['code' => 0, 'msg' => '导出中,请稍后在记录中查看'])->send();
- $headerMethod = $typeList[$m]['headerMethod'];
- $dataMethod = $typeList[$m]['dataMethod'];
- $header = $this->$headerMethod();
- $row = [];
- $title = [];
- foreach ($header['header1'] as $item) {
- if (isset($item['colspan'])) {
- for ($s = 0; $s < $item['colspan']; $s++) {
- $h2 = array_shift($header['header2']);
- $title[] = strip_tags($h2['title']);
- }
- } else {
- $title[] = strip_tags($item['title']);
- }
- if (isset($item['child'])) {
- foreach ($item['child'] as $k) {
- $row[] = $k;
- }
- } else {
- $row[] = $item['field'];
- }
- }
- touch('../download/' . $filename . '.csv');
- $fp = fopen('../download/' . $filename . '.csv', 'a');
- fputcsv($fp, $title);
- $n = 2000;
- $p = 1;
- do {
- $data = $this->$dataMethod($p, $n);
- $data = $data->getData();
- foreach ($data['data'] as $rowData) {
- $r = [];
- foreach ($row as $field) {
- $r[] = isset($rowData[$field]) ? $rowData[$field] : '';
- }
- fputcsv($fp, $r);
- }
- $p++;
- } while ($n * ($p - 1) < $data['count']);
- fclose($fp);
- // 文件上传
- $rs = ossUpload($m . '/' . $filename . '.csv', './download/' . $filename . '.csv');
- if ($rs) {
- unlink('../download/' . $filename . '.csv');
- }
- $exportLog->save(['state' => 1]);
- }
- /**
- * 线上巡店查询结果导出
- */
- public function exportList()
- {
- $param = request()->param();
- $methodtype = 'statisticsExport';
- if (!empty($param['methodtype'])) $methodtype = $param['methodtype'];
- if (!in_array($methodtype, ['statisticsExport', 'newStatisticsExport', 'officeStatisticsExport'])) return json(['code' => 1, 'msg' => '方法参数错误']);
- if (!request()->isAjax()) {
- View::assign('methodtype', $methodtype);
- return View::fetch();
- }
- $count = AsyncTask::where([['root_id', '=', request()->employee->root_id], ['method', '=', $methodtype]])->count();
- $data = AsyncTask::field('params, addtime,state,complete_time,result')
- ->where([['root_id', '=', request()->employee->root_id], ['method', '=', $methodtype]])
- ->order('id desc')
- ->page($param['page'], $param['limit'])
- ->select();
- if (!empty($data)) $data = $data->toArray();
- $org = Org::where([['path', 'like', request()->employee->root_id . '-%']])->column('name', 'id');
- foreach ($data as &$item) {
- if (isset($item['params']['sdate']) && $item['params']['sdate'] != '') $item['params']['sdate'] = date('Y-m-d', strtotime($item['params']['sdate']));
- if (isset($item['params']['edate']) && $item['params']['edate'] != '') $item['params']['edate'] = date('Y-m-d', strtotime($item['params']['edate']));
- if (isset($item['params']['org_id']) && isset($org[$item['params']['org_id']])) $item['params']['org_id'] = $org[$item['params']['org_id']];
- }
- return json(['code' => 0, 'count' => $count, 'data' => $data]);
- }
- /**
- * daochu文件下载
- */
- public function downloadXls($path, $methodtype)
- {
- if (in_array($methodtype, ['statisticsExport', 'newStatisticsExport', 'officeStatisticsExport', 'behaviorStatisticsData', 'highBehaviorStatisticsData', 'manageStatisticsData', 'customer_list_data', 'generalStatisticsData'])) {
- $had = ExportLog::where([['root_id', '=', request()->employee->root_id], ['type', '=', $methodtype], ['file', '=', $path], ['state', '=', 1]])->find();
- $floder = 'statisticsExport/';
- if (in_array($methodtype, ['newStatisticsExport'])) $floder = $methodtype . '/';
- } else {
- return json(['code' => 1, 'msg' => '方法参数错误']);
- }
- $ossExit = ossFileExist($floder . $path);
- if (empty($had) || (!file_exists('../download/' . $path) && !$ossExit)) return View::display('<script>alert("{$msg}");window.close();</script>', ['msg' => '文件不存在或数据处理中,请稍后再试']);
- // 检测文件
- if ($ossExit) {
- $path = 'https://' . config('app.ali_oss_bindurl') . '/' . $floder . $path;
- return redirect($path);
- }
- return download('../download/' . $path, $path);
- }
- /**
- * 客户管理数据统计
- */
- public function customer_list()
- {
- $root_id = request()->employee->root_id;
- $org = Org::where([['path', 'like', $root_id . '-%'], ['org_type', '=', 1]])->field('id,name')->select()->toArray();
- View::assign('org', $org);
- //渠道来源下拉
- $source = CustomerSource::where('root_id', $root_id)->column('id,source');
- View::assign('source', $source);
- return View::fetch();
- }
- /**
- * 客户统计列表数据
- */
- public function customer_list_data($page = 1, $limit = 20)
- {
- $root_id = request()->employee->root_id;
- $source_id = input('source_id', 0);
- $employee_name = input('employee_name', '', 'trim');
- $customer_type = input('customer_type', '', 'intval');
- switch ($customer_type) {
- case 1:
- $where[] = ['crm_res_id', '>', 0];
- $where[] = ['remark', '<>', '公海获取'];
- break;
- case 2:
- $where[] = ['remark', '=', '活动报名建档'];
- break;
- case 3:
- $where[] = ['agents_id', '>', 0];
- break;
- case 4:
- $where[] = ['crm_res_id', 'NULL', null];
- $where[] = ['remark', '<>', '活动报名建档'];
- $where[] = ['remark', '<>', '公海获取'];
- $where[] = ['agents_id', 'NULL', null];
- break;
- case 5:
- $where[] = ['remark', '=', '公海获取'];
- break;
- default:
- break;
- }
- if ($employee_name) {
- $employee_ids = Employee::where([['name', 'like', '%' . $employee_name . '%'], ['root_id', '=', $root_id]])->column('id');
- $where[] = ['employee_id', 'in', $employee_ids];
- }
- $start_date = input('start_date', '', 'trim');
- $end_date = input('end_date', '', 'trim');
- if ($start_date) {
- $count_dates = explode(' - ', $start_date);
- $start_date = $count_dates[0];
- $end_date = $count_dates[1];
- } else {
- $start_date = $end_date = '';
- }
- if ($start_date && $end_date) {
- $where[] = ['addtime', 'between', [$start_date . ' 00:00:00', $end_date . ' 23:59:59']];
- } elseif ($start_date) {
- $where[] = ['addtime', '>', $start_date . ' 00:00:00'];
- } elseif ($end_date) {
- $where[] = ['addtime', '<', $end_date . ' 23:59:59'];
- }
- $org_id = input('select_org_id', '', 'trim');
- $org_ids = orgSubIds($root_id);
- if ($org_id) {
- $org_id = explode(',', $org_id);
- $sel_org_ids = [];
- foreach ($org_id as $k => $v) {
- if (in_array($v, $org_ids)) {
- $sel_org_ids[] = $v;
- }
- }
- $where[] = ['org_id', 'in', $sel_org_ids];
- } else {
- $where[] = ['org_id', 'in', $org_ids];
- }
- if ($source_id) $where[] = ['source_id', '=', $source_id];
- $where[] = ['died', '<>', 2];
- $where[] = ['employee_id', 'not null', ''];
- $where[] = ['state', 'not in', Customer::changeState('无效', 'chaos')];
- //2023-02-26 只统计有效客户 和CRM客户管理-店面客户管理保持一致
- $state11 = Customer::changeState('待确认', 'chaos');
- $state22 = Customer::changeState('无效', 'chaos');
- $model = Customer::where($where)->where(function ($query) {
- $state11 = Customer::changeState('待确认', 'chaos');
- $state22 = Customer::changeState('无效', 'chaos');
- $or1[] = ['crm_res_id', 'null', null];
- $or1[] = ['state', 'not in', array_merge($state11, $state22)];
- $or2[] = ['crm_res_id', '>', 0];
- $or2[] = ['state', 'not in', $state22];
- $query->whereOr([$or1, $or2]);
- });
- $count = $model->count();
- $list = $model->with(['employee', 'org', 'designer', 'source'])->page($page, $limit)->order('addtime desc')->select()->each(function ($item) {
- if ($item['remark'] == '公海获取') {
- $customer_type = '公海获取';
- } elseif ($item['agents_id']) {
- $customer_type = '装修推荐管';
- } elseif ($item['remark'] == '活动报名建档') {
- $customer_type = '活动报名';
- } elseif ($item['crm_res_id']) {
- $customer_type = '资源库';
- } else {
- $customer_type = '自建';
- }
- $item['customer_type'] = $customer_type;
- if (empty($item['name'])) {
- $item['name'] = '未知';
- }
- if (empty($item['community_name'])) {
- $item['community_name'] = '未知';
- }
- if (empty($item['house_type'])) {
- $item['house_type'] = '未知';
- }
- if (empty($item['square'])) {
- $item['square'] = '未知';
- }
- $item['phone'] = substr_replace($item['phone'], '******', 3, 6);
- $item['signed_money_data'] = $item->getData('signed_money');
- // 指派客户经理及设计师
- $assigned_personal_manager_ids = [];
- if ($item['assigned_personnel']) {
- $assigned_personal = explode(',', $item['assigned_personnel']);
- $assigned_personal_list = Employee::with('org')->where('id', 'in', $assigned_personal)->select()->toArray();
- $assigned_personal_designer = [];
- $assigned_personal_manager = [];
- $assigned_personal_designer_org = [];
- foreach ($assigned_personal_list as $k => $v) {
- if ($v['org']['org_type'] == 2) {
- $assigned_personal_designer[] = $v['name'];
- $assigned_personal_designer_org[] = $v['org']['name'];
- } else {
- $assigned_personal_manager[] = $v['name'];
- $assigned_personal_manager_ids[] = $v['id'];
- }
- }
- $item['assigned_personal_manager'] = $assigned_personal_manager ? implode('、', $assigned_personal_manager) : '无';
- $item['assigned_personal_designer'] = $assigned_personal_designer ? implode('、', $assigned_personal_designer) : '无';
- $item['assigned_personal_designer_org'] = $assigned_personal_designer_org ? implode('、', $assigned_personal_designer_org) : '无';
- } else {
- $item['assigned_personal_manager'] = '无';
- $item['assigned_personal_designer'] = '无';
- $item['assigned_personal_designer_org'] = '无';
- }
- // 未跟踪天数
- $last_visit_log = CustomerVisitLog::where('customer_id', '=', $item['id'])->findOrEmpty();
- if (!$last_visit_log->isEmpty()) {
- $time_long = time() - strtotime($last_visit_log['addtime']);
- } else {
- $time_long = time() - strtotime($item['addtime']);
- }
- $no_visit_day = ceil($time_long / (24 * 3600));
- $item['no_visit_day'] = $no_visit_day;
- // 是否加微
- $ext = json_decode($item['ext'], true);
- $item['wechat'] = '否'; // 是否加微
- $item['add_wechat_type'] = '无'; // 加微类型
- $item['add_wechat_time'] = '无'; // 加微时间
- $item['plan_issuing_date'] = '无'; //出方案时间
- $item['drawing_date'] = '无'; // 出图时间
- $item['group_building_date'] = '无'; // 建群时间
- if (!empty($ext)) {
- foreach ($ext as $v) {
- if (isset($v['keyname']) && $v['keyname'] == 'wechat' && !empty($v['value'])) {
- $item['wechat'] = CustomerPortraitFieldSelect::where('id', $v['value'])->value('name');
- } elseif (isset($v['keyname']) && $v['keyname'] == 'add_wechat_time' && !empty($v['value'])) {
- $item['wechat'] = '是';
- } elseif (isset($v['keyname']) && $v['keyname'] == 'add_wechat_type' && !empty($v['value'])) {
- $item['wechat'] = '是';
- }
- if (isset($v['keyname']) && $v['keyname'] == 'add_wechat_time' && !empty($v['value'])) {
- $item['add_wechat_time'] = $v['value'];
- }
- if (isset($v['keyname']) && $v['keyname'] == 'add_wechat_type' && !empty($v['value'])) {
- $item['add_wechat_type'] = CustomerPortraitFieldSelect::where('id', $v['value'])->value('name');
- }
- if (isset($v['keyname']) && $v['keyname'] == 'plan_issuing_date' && !empty($v['value'])) {
- $item['plan_issuing_date'] = $v['value'];
- }
- if (isset($v['keyname']) && $v['keyname'] == 'drawing_date' && !empty($v['value'])) {
- $item['drawing_date'] = $v['value'];
- }
- if (isset($v['keyname']) && $v['keyname'] == 'group_building_date' && !empty($v['value'])) {
- $item['group_building_date'] = $v['value'];
- }
- }
- }
- $lf_state = CustomerVisitLog::changeState('已量房', 'chaos');
- $lf_list = CustomerVisitLog::where([['customer_id', '=', $item['id']], ['state', 'in', $lf_state]])->order('addtime asc')->select()->toArray();
- if (!empty($lf_list)) {
- $item['is_liangfang'] = '是';
- $item['liangfang_date'] = $lf_list[0]['addtime'];
- $item['once_liangfang_days'] = ceil((strtotime($lf_list[0]['addtime']) - strtotime($item['addtime'])) / (24 * 3600));
- } else {
- $item['is_liangfang'] = '否';
- $item['liangfang_date'] = '无';
- $item['once_liangfang_days'] = '无';
- }
- // 到店
- $dd_state = CustomerVisitLog::changeState('已到店', 'chaos');
- $dd_list = CustomerVisitLog::where([['customer_id', '=', $item['id']], ['state', 'in', $dd_state]])->order('addtime asc')->select()->toArray();
- $item['once_daodian'] = '否';
- $item['daodian_date'] = '无';
- $item['once_daodian_days'] = '无';
- $item['once_daodian_shop'] = '无';
- $item['twice_daodian_date'] = '无'; //二次到店时间
- $item['twice_daodian_days'] = '无'; // 二次到店周期 二次到店时间 - 一次到店时间
- $item['twice_daodian_shop'] = '无';
- if (!empty($dd_list)) {
- $item['once_daodian'] = '是';
- $item['daodian_date'] = $dd_list[0]['addtime'];
- $item['once_daodian_days'] = ceil((strtotime($dd_list[0]['addtime']) - strtotime($item['addtime'])) / (24 * 3600));
- if (!empty($dd_list[0]['shop_id'])) {
- $shop_name = Shop::where('id', $dd_list[0]['shop_id'])->findOrEmpty();
- if ($shop_name->isEmpty()) {
- $item['once_daodian_shop'] = '未知';
- } else {
- $item['once_daodian_shop'] = $shop_name['name'];
- }
- }
- // 二次到店
- if (count($dd_list) > 1) {
- $item['twice_daodian_date'] = $dd_list[1]['addtime'];
- $item['twice_daodian_days'] = ceil((strtotime($dd_list[1]['addtime']) - strtotime($dd_list[0]['addtime'])) / (24 * 3600));
- $shop_name = Shop::where('id', $dd_list[1]['shop_id'])->findOrEmpty();
- if ($shop_name->isEmpty()) {
- $item['twice_daodian_shop'] = '未知';
- } else {
- $item['twice_daodian_shop'] = $shop_name['name'];
- }
- }
- }
- // 量房 - 到店 周期
- if (!empty($lf_list) && !empty($dd_list)) {
- if ($lf_list[0]['addtime'] > $dd_list[0]['addtime']) {
- $item['liangfang_daodian_days'] = ceil((strtotime($lf_list[0]['addtime']) - strtotime($dd_list[0]['addtime'])) / (24 * 3600));
- } else {
- $item['liangfang_daodian_days'] = ceil((strtotime($dd_list[0]['addtime']) - strtotime($lf_list[0]['addtime'])) / (24 * 3600));
- }
- } else {
- $item['liangfang_daodian_days'] = '无';
- }
- // 交定(签单)
- $jd_state = CustomerVisitLog::changeState('已交定', 'chaos');
- $jd_list = CustomerVisitLog::where([['customer_id', '=', $item['id']], ['state', 'in', $jd_state]])->order('addtime asc')->select()->toArray();
- if (!empty($jd_list)) {
- $item['is_deposit'] = '是';
- $item['deposit_date'] = $jd_list[0]['addtime'];
- $item['deposit_days'] = ceil((strtotime($jd_list[0]['addtime']) - strtotime($item['addtime'])) / (24 * 3600));
- } else {
- $item['is_deposit'] = '否';
- $item['deposit_date'] = '无';
- $item['deposit_days'] = '无';
- }
- // 签单(转单)
- $qd_state = CustomerVisitLog::changeState('已签单', 'chaos');
- $qd_list = CustomerVisitLog::where([['customer_id', '=', $item['id']], ['state', 'in', $qd_state]])->order('addtime asc')->select()->toArray();
- if (!empty($qd_list)) {
- $item['sign_date'] = $qd_list[0]['addtime'];
- $item['sign_days'] = ceil((strtotime($qd_list[0]['addtime']) - strtotime($item['addtime'])) / (24 * 3600));
- } else {
- $item['sign_date'] = '无';
- $item['sign_days'] = '无';
- }
- // 交定转单周期
- if (!empty($jd_list) && !empty($qd_list)) {
- if ($jd_list[0]['addtime'] > $qd_list[0]['addtime']) {
- $item['deposit_sign_days'] = ceil((strtotime($jd_list[0]['addtime']) - strtotime($qd_list[0]['addtime'])) / (24 * 3600));
- } else {
- $item['deposit_sign_days'] = ceil((strtotime($qd_list[0]['addtime']) - strtotime($jd_list[0]['addtime'])) / (24 * 3600));
- }
- } else {
- $item['deposit_sign_days'] = '无';
- }
- // 一次到店未签单时间
- $first_visit = CustomerVisitLog::where([['customer_id', '=', $item['id']], ['state', 'in', $dd_state]])->order('addtime asc')->findOrEmpty();
- $item['first_visit_no_sign'] = '无';
- if (!$first_visit->isEmpty()) {
- $first_visit_no_sign = CustomerVisitLog::where([['customer_id', '=', $item['id']], ['addtime', '>', $first_visit['addtime']]])->order('addtime asc')->findOrEmpty();
- if (!$first_visit_no_sign->isEmpty()) {
- if (!in_array($first_visit_no_sign['state'], $qd_state)) {
- $item['first_visit_no_sign'] = $first_visit['addtime'];
- }
- }
- }
- // 客户经理回访
- if (!empty($assigned_personal_manager_ids)) {
- $manager_next_visit = CustomerVisitLog::where([['employee_id', 'in', $assigned_personal_manager_ids], ['next_contact_date', 'not null', ''], ['customer_id', '=', $item['id']]])->field('customer_id,next_contact_date,addtime,employee_id')->select()->toArray();
- $manager_visit_times = 0;
- $manager_visit_days = 0;
- foreach ($manager_next_visit as $k => $v) {
- unset($visit_where);
- $visit_where[] = ['addtime', 'between', [$v['next_contact_date'] . ' 00:00:00', $v['next_contact_date'] . ' 23:59:59']];
- $visit_where[] = ['customer_id', '=', $v['customer_id']];
- $visit_where[] = ['employee_id', '=', $v['employee_id']];
- $visit_next_find = CustomerVisitLog::where($visit_where)->findOrEmpty();
- if (!$visit_next_find->isEmpty()) {
- $manager_visit_times++;
- $next_days = ceil((strtotime($visit_next_find['addtime']) - strtotime($v['next_contact_date'])) / (24 * 3600));
- $manager_visit_days += $next_days;
- }
- }
- $item['manager_visit_times'] = $manager_visit_times;
- $item['manager_visit_cycle'] = $manager_visit_times ? round($manager_visit_days / $manager_visit_times, 1) : '无';
- } else {
- $item['manager_visit_times'] = 0;
- $item['manager_visit_cycle'] = '无';
- }
- // 经理回访
- $employee_next_visit = CustomerVisitLog::where([['customer_id', '=', $item['id']], ['next_contact_date', 'not null', ''], ['employee_id', '=', $item['employee_id']]])->field('customer_id,next_contact_date,employee_id')->select()->toArray();
- $employee_visit_times = 0;
- $employee_visit_days = 0;
- foreach ($employee_next_visit as $k => $v) {
- unset($visit_where);
- $visit_where[] = ['addtime', 'between', [$v['next_contact_date'] . ' 00:00:00', $v['next_contact_date'] . ' 23:59:59']];
- $visit_where[] = ['customer_id', '=', $v['customer_id']];
- $visit_where[] = ['employee_id', '=', $v['employee_id']];
- $visit_next_find = CustomerVisitLog::where($visit_where)->findOrEmpty();
- if (!$visit_next_find->isEmpty()) {
- $employee_visit_times++;
- $next_days = ceil((strtotime($visit_next_find['addtime']) - strtotime($v['next_contact_date'])) / (24 * 3600));
- $employee_visit_days += $next_days;
- }
- }
- $item['employee_visit_times'] = $employee_visit_times;
- $item['employee_visit_cycle'] = $employee_visit_times ? round($employee_visit_days / $employee_visit_times, 1) : '无';
- $wx_state = Customer::changeState('无效', 'chaos');
- if (in_array($item['state'], $wx_state)) {
- $item['invalid'] = '是';
- } else {
- $item['invalid'] = '否';
- }
- if ($item['died'] == 2) {
- $item['died'] = '是';
- } else {
- $item['died'] = '否';
- }
- // 卖卡时间
- $maika_state = CustomerVisitLog::changeState('已卖卡', 'chaos');
- $maika_visit = CustomerVisitLog::where([['customer_id', '=', $item['id']], ['state', 'in', $maika_state]])->order('addtime desc')->findOrEmpty();
- $item['maika_time'] = '无';
- if (!$maika_visit->isEmpty()) {
- $item['maika_time'] = $maika_visit['addtime'];
- }
- })->toArray();
- $clue_where[] = ['name', '=', 'clueTag'];
- $clue_where[] = ['root_id', '=', request()->employee->root_id];
- $find = Setting::where($clue_where)->findOrEmpty();
- if ($find->isEmpty()) {
- $clue_tag = ['已装修', '无需求', '有需求', '超地域', '未交房', '在外地', '无购买力', '未接通电话'];
- } else {
- $clue_tag = array_filter(explode(',', $find['content']));
- }
- foreach ($list as $k => $v) {
- $list[$k]['house_delivery_time'] = $v['house_delivery_time'] ? $v['house_delivery_time'] : '未知';
- $list[$k]['employee_name'] = $v['employee']['name'] ?? '无';
- $list[$k]['source_name'] = $v['source']['source'] ?? '未知';
- if ($v['invalid'] == '否') {
- $list[$k]['invalid_remark'] = '';
- } else {
- $wx_state = CustomerVisitLog::changeState('无效', 'chaos');
- $invalid_log = CustomerVisitLog::where([['customer_id', '=', $v['id']], ['state', 'in', $wx_state]])->order('addtime desc')->findOrEmpty();
- if (!$invalid_log->isEmpty() && !empty($invalid_log['remark']) && in_array($invalid_log['remark'], $clue_tag)) {
- $list[$k]['invalid_remark'] = $invalid_log['remark'];
- } else {
- $list[$k]['invalid_remark'] = '其他';
- }
- }
- }
- return json(['code' => 0, 'data' => $list, 'count' => $count, 'page' => ceil($count / $limit)]);
- }
- /**
- * 客户统计列表导出
- */
- public function customer_list_export()
- {
- if (!request()->isAjax()) {
- $header = [
- ["field" => 'name', "title" => '客户姓名', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'phone', "title" => '手机号', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'community_name', "title" => '小 区', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'house_type', "title" => '房屋类型', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'house_delivery_time', "title" => '交房时间', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'square', "title" => '面积', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'org_name', "title" => '部门', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'employee_name', "title" => '业务员', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'addtime', "title" => '添加时间', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'source_name', "title" => '来源', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'assigned_personal_manager', "title" => '指派客户经理', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'assigned_personal_designer_org', "title" => '指派设计部', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'assigned_personal_designer', "title" => '指派设计师', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'no_visit_day', "title" => '未跟踪天数', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'wechat', "title" => '是否加微信', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'add_wechat_type', "title" => '加微类型', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'add_wechat_time', "title" => '加微时间', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'group_building_date', "title" => '建群时间', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'is_liangfang', "title" => '是否量房', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'liangfang_date', "title" => '量房时间', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'once_liangfang_days', "title" => '量房周期', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'plan_issuing_date', "title" => '计划出初步方案时间', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'once_daodian', "title" => '是否一次到店', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'daodian_date', "title" => '一次到店时间', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'once_daodian_shop', "title" => '一次所到店面', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'once_daodian_days', "title" => '一次到店周期', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'liangfang_daodian_days', "title" => '量房到店周期', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'twice_daodian_date', "title" => '二次到店时间', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'twice_daodian_shop', "title" => '二次所到店面', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'twice_daodian_days', "title" => '二次到店周期', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'is_deposit', "title" => '是否交定/签单', "align" => 'center', "rowspan" => 1, "class" => "bgFED9D9"],
- ["field" => 'deposit_date', "title" => '交定/签单时间', "align" => 'center', "rowspan" => 1, "class" => "bgFED9D9"],
- ["field" => 'drawing_date', "title" => '出图时间', "align" => 'center', "rowspan" => 1, "class" => "bgFED9D9"],
- ["field" => 'sign_date', "title" => '转单时间', "align" => 'center', "rowspan" => 1, "class" => "bgFED9D9"],
- ["field" => 'sign_days', "title" => '交定转单周期', "align" => 'center', "rowspan" => 1, "class" => "bgFED9D9"],
- ["field" => 'signed_money_data', "title" => '合同金额(元)', "align" => 'center', "rowspan" => 1, "class" => "bgFED9D9"],
- ["field" => 'first_visit_no_sign', "title" => '一次到店未签单时间', "align" => 'center', "rowspan" => 1, "class" => "bgFED9D9"],
- ["field" => 'manager_visit_times', "title" => '客户经理回访次数', "align" => 'center', "rowspan" => 1, "class" => "bgFED9D9"],
- ["field" => 'manager_visit_cycle', "title" => '客户经理回访周期', "align" => 'center', "rowspan" => 1, "class" => "bgFED9D9"],
- ["field" => 'employee_visit_times', "title" => '经理回访次数', "align" => 'center', "rowspan" => 1, "class" => "bgFED9D9"],
- ["field" => 'employee_visit_cycle', "title" => '经理回访平均周期', "align" => 'center', "rowspan" => 1, "class" => "bgFED9D9"],
- ["field" => 'invalid', "title" => '无效客户', "align" => 'center', "rowspan" => 1, "class" => "bgFED9D9"],
- ["field" => 'invalid_remark', "title" => '无效原因', "align" => 'center', "rowspan" => 1, "class" => "bgFED9D9"],
- ["field" => 'died', "title" => '是否死单', " align" => 'center', "rowspan" => 1, "class" => "bgFED9D9"]
- ];
- view::assign('row', json_encode($header));
- view::assign('header', $header);
- return View::fetch();
- } else {
- return $this->customer_list_data();
- }
- }
- /**
- * 总统计页面
- */
- public function generalStatistics()
- {
- $root_id = request()->employee->root_id;
- //房屋状态是否开启
- $house_status_where = [
- ['root_id', '=', $root_id],
- ['keyname', '=', 'house_status'],
- ['status', '=', 0]
- ];
- $house_status_per = CustomerPortraitField::where($house_status_where)->findOrEmpty();
- $field = [];
- if (!$house_status_per->isEmpty()) {
- $field = CustomerPortraitFieldSelect::where('pid', $house_status_per->id)->column('name,id');
- $fields = [];
- foreach ($field as $v) {
- $fields[] = [
- 'field' => 'house_status_' . $v['id'],
- 'title' => $v['name'],
- 'align' => 'center',
- 'width' => 100,
- 'rowspan' => 2
- ];
- }
- $field = $fields;
- }
- View::assign('field', json_encode($field));
- //无效客资
- $invalid_customer = Setting::where([['name', '=', 'clueTag'], ['root_id', '=', $root_id]])->value('content');
- $arr3 = [];
- if ($invalid_customer) {
- $arr3 = explode(',', $invalid_customer);
- } else {
- $arr3 = ['已装修', '无需求', '有需求', '超地域', '未交房', '在外地', '无购买力', '未接通电话'];
- }
- $field4 = [];
- foreach ($arr3 as $k3 => $v3) {
- $field4[] = [
- 'field' => 'invalid_customer_' . $k3,
- 'title' => $v3,
- 'align' => 'center',
- 'width' => 100,
- 'rowspan' => 1
- ];
- }
- View::assign('field4', json_encode($field4));
- //返回组织列表
- $org = Org::where([['path', 'like', $this->root_id . '-%']])->select()->toArray();
- View::assign('org', $org);
- $type = input('type', '', 'intval');
- View::assign('type', 2);
- $org_id = input('org_id', '', 'intval');
- View::assign('org_id', $org_id);
- return View::fetch();
- }
- /**
- * 平均周期
- */
- public function avgCycle($cus, $vis)
- {
- $state1 = CustomerVisitLog::changeState('已交定', 'chaos');
- $state2 = CustomerVisitLog::changeState('已量房', 'chaos');
- $state3 = CustomerVisitLog::changeState('已到店', 'chaos');
- $dep_time = [];
- $room_time = [];
- $store_time = [];
- $next_date = [];
- foreach ($vis as $v) {
- //交定日期
- if (in_array($v['state'], $state1)) {
- $dep_time[$v['customer_id']] = $v['addtime'];
- } elseif (in_array($v['state'], $state2)) {
- $room_time[$v['customer_id']] = $v['addtime'];
- } elseif (in_array($v['state'], $state3)) {
- $store_time[$v['customer_id']] = $v['addtime'];
- }
- //平均回访次数
- if (!isset($next_date[$v['customer_id']]['addtime'])) {
- $next_date[$v['customer_id']]['addtime'] = [];
- }
- if (!isset($next_date[$v['customer_id']]['next_date'])) {
- $next_date[$v['customer_id']]['next_date'] = [];
- }
- $next_date[$v['customer_id']]['addtime'][] = date('Y-m-d', strtotime($v['addtime']));
- $next_date[$v['customer_id']]['next_date'][] = date('Y-m-d', strtotime($v['next_contact_date']));
- }
- $dep_cycle = $room_cycle = $room_store_cycle = $next = [];
- foreach ($cus as $v2) {
- if (isset($dep_time[$v2['id']])) {
- $dep_cycle[] = strtotime($dep_time[$v2['id']]) - strtotime($v2['addtime']);
- }
- if (isset($room_time[$v2['id']])) {
- $room_cycle[] = strtotime($room_time[$v2['id']]) - strtotime($v2['addtime']);
- }
- if (isset($room_time[$v2['id']]) && isset($store_time[$v2['id']])) {
- $room_store_cycle[] = abs(strtotime($room_time[$v2['id']]) - strtotime($store_time[$v2['id']]));
- }
- if (isset($next_date[$v2['id']]['addtime']) && $next_date[$v2['id']]['next_date']) {
- $next[] = count(array_filter(array_intersect($next_date[$v2['id']]['addtime'], $next_date[$v2['id']]['next_date'])));
- }
- }
- //平均交定周期
- $data['dep_cycle'] = empty($dep_cycle) ? 0 : ceil(count($dep_cycle) / array_sum($dep_cycle));
- //平均量房周期
- $data['room_cycle'] = empty($room_cycle) ? 0 : ceil(count($room_cycle) / array_sum($room_cycle));
- //平均量房到店周期
- $data['room_store_cycle'] = empty($room_store_cycle) ? 0 : ceil(count($room_store_cycle) / array_sum($room_store_cycle));
- //平均回访次数
- $data['next'] = !array_sum($next) ? 0 : ceil(count($next) / array_sum($next));
- return $data;
- }
- /**
- * 获取见面客户
- * @param $search_list 要判断有多少见面的log记录
- * @param $before_list 之前见面的客户id集合
- */
- public function visitDeal($search_list, $before_list)
- {
- // 见面状态
- $state2 = CustomerVisitLog::changeState('已到场', 'chaos');
- $state3 = CustomerVisitLog::changeState('已量房', 'chaos');
- $state4 = CustomerVisitLog::changeState('已到店', 'chaos');
- $state5 = CustomerVisitLog::changeState('已交定', 'chaos');
- $state6 = CustomerVisitLog::changeState('已签单', 'chaos');
- $visit_state = array_merge($state2, $state3, $state4, $state5, $state6);
- $search_ids = [];
- foreach ($search_list as $k => $v) {
- if (in_array($v['state'], $visit_state)) {
- $search_ids[] = $v['customer_id'];
- }
- }
- $visit_ids = array_values(array_unique(array_diff($search_ids, $before_list)));
- return $visit_ids;
- }
- /**
- * 总统计数据
- */
- public function generalStatisticsData($page = 1, $limit = 10)
- {
- $param = request()->only(['date' => '', 'keyword' => '', 'org_id' => '', 'start_date' => '', 'end_date' => '', 'type' => '', 'source_id' => '']);
- $root_id = request()->employee->root_id;
- //日期搜索//2023-02-15页面逻辑修改 传参方式改为 start_date=2023/2/15 - 2023/2/15
- if ($param['start_date']) {
- $count_dates = explode(' - ', $param['start_date']);
- $param['start_date'] = date('Y-m-d 00:00:00', strtotime($count_dates[0]));
- $param['end_date'] = date('Y-m-d 23:59:59', strtotime($count_dates[1]));
- } else {
- $param['start_date'] = '2010-01-01 00:00:00';
- $param['end_date'] = date('Y-m-d H:i:s', time());
- }
- $date_query = [['addtime', 'between', [$param['start_date'], $param['end_date']]]];
- $date_query1 = [['share_time', 'between', [$param['start_date'], $param['end_date']]]];
- //加微时间筛选
- $sdate = strtotime($param['start_date']);
- $edate = strtotime($param['end_date']);
- $where = [
- ['root_id', '=', $root_id],
- ['uid', '>', 0],
- ['state', '=', '在职']
- ];
- if ($param['keyword']) {
- $where[] = ['name', 'like', '%' . $param['keyword'] . '%'];
- }
- $org_id = $param['org_id'] ? $param['org_id'] : $root_id;
- $sub_orgs = orgSubIds($org_id);
- if ($param['org_id']) {
- $o = Org::where([['id', '=', $param['org_id']]], ['path', 'like', $this->root_id . '-%'])->find();
- $orgIds = Org::where([['path', 'like', $o['path'] . '%']])->column('id');
- $where[] = ['org_id', 'in', $orgIds];
- } else {
- $where[] = ['org_id', 'in', $sub_orgs];
- }
- $list = Employee::with(['org' => function ($query) {
- $query->field('id, name');
- }])->where($where)->field('id,org_id,name')->page($page, $limit)->select()->toArray();
- $count = Employee::where($where)->count();
- $page_employee = array_column($list, 'id');
- $state2 = CustomerVisitLog::changeState('已到场', 'chaos');
- $state3 = CustomerVisitLog::changeState('已量房', 'chaos');
- $state4 = CustomerVisitLog::changeState('已到店', 'chaos');
- $state5 = CustomerVisitLog::changeState('已交定', 'chaos');
- $state6 = CustomerVisitLog::changeState('已签单', 'chaos');
- $state7 = CustomerVisitLog::changeState('已卖卡', 'chaos');
- $wuxiao_log_state = CustomerVisitLog::changeState('无效', 'chaos');
- $c_where[] = ['Customer.employee_id', 'in', $page_employee];
- $c_where[] = ['CustomerVisitLog.confirm_date', 'between', [$param['start_date'], $param['end_date']]];
- $c_where[] = ['Customer.state', 'NOT NULL', null];
- $add_where[] = ['employee_id', 'in', $page_employee];
- $add_where[] = ['addtime|employee_time', 'between', [$param['start_date'], $param['end_date']]];
- $add_where[] = ['state', 'NOT NULL', null];
- $db_where[] = ['Customer.employee_id', 'in', $page_employee];
- $db_where[] = ['Customer.state', 'NOT NULL', null];
- if ($param['source_id']) {
- $c_where[] = ['Customer.source_id', '=', $param['source_id']];
- $db_where[] = ['Customer.source_id', '=', $param['source_id']];
- $jiav_where[] = ['source_id', '=', $param['source_id']];
- $j_w_where[] = ['source_id', '=', $param['source_id']];
- $add_where[] = ['source_id', '=', $param['source_id']];
- }
- // 加微客户查询
- // 先查搜索时间段内部门客户的加微数据,再判断哪些客户是page_employee中员工的客户,再判断其中哪些是已经置为无效的客户,再把这些置为无效的客户拼接到page_empployee员工身上。
- $page_employee_org = array_unique(array_column($list, 'org_id'));
- $jiav_where[] = ['org_id', 'in', $page_employee_org];
- $jiav_where[] = ['add_wechat_time', 'between', [$param['start_date'], $param['end_date']]];
- $jiav_list = Customer::where($jiav_where)->column('id,employee_id,state');
- $db_where[] = ['CustomerVisitLog.is_merge', '=', 0];
- if ($date_query) {
- $db_where[] = ['CustomerVisitLog.confirm_date', 'between', [$param['start_date'], $param['end_date']]];
- }
- // $customer_list = Customer::where($c_where)->column('id,employee_id,state,ext,is_resource,source_id,addtime,signed_money,house_type,square,house_status,remark,crm_res_id,agents_id,died,assign_type,employee_time');
- // 搜索时间段内的跟踪客户
- $customer_list = Db::view('Customer', 'id,employee_id,state,ext,is_resource,source_id,addtime,signed_money,house_type,square,house_status,remark,crm_res_id,agents_id,died,assign_type,employee_time')
- ->view('CustomerVisitLog', [], 'Customer.id=CustomerVisitLog.customer_id')
- ->where($c_where)
- ->group('Customer.id')
- ->select()
- ->toArray();
- // 搜索时间段内添加的客户
- $add_customer = Customer::where($add_where)->column('id,employee_id,crm_res_id,addtime,employee_time');
- $add_cus_employee = [];
- $fenpei_cus_employee = [];
- foreach ($add_customer as $k => $v) {
- if (empty($v['crm_res_id'])) {
- if ($v['addtime'] > $param['start_date'] && $v['addtime'] < $param['end_date']) {
- $add_cus_employee[$v['employee_id']][] = $v;
- }
- } else {
- if ((!empty($v['employee_time']) && $v['employee_time'] > $param['start_date'] && $v['employee_time'] < $param['end_date'])) {
- $fenpei_cus_employee[$v['employee_id']][] = $v;
- }
- }
- }
- // 搜索时间段内的跟踪记录
- $vislog_list = Db::view('CustomerVisitLog', 'id,customer_id,state,addtime,next_contact_date,remark,employee_id,confirm_date')
- ->view('Customer', [], 'Customer.id=CustomerVisitLog.customer_id')
- ->where($db_where)
- ->select()
- ->toArray();
- $visit_state = array_merge($state2, $state3, $state4, $state5, $state6);
- $be_where[] = ['Customer.employee_id', 'in', $page_employee];
- $be_where[] = ['Customer.state', 'NOT NULL', null];
- $be_where[] = ['CustomerVisitLog.confirm_date', '<', $param['start_date']];
- $be_where[] = ['CustomerVisitLog.state', 'in', $visit_state];
- // 搜索时间段外的到访记录
- $before_log = Db::view('CustomerVisitLog', 'id,customer_id')
- ->view('Customer', 'employee_id', 'Customer.id=CustomerVisitLog.customer_id')
- ->where($be_where)
- ->select()
- ->toArray();
- // 员工见过面的客户
- $employee_visit = [];
- foreach ($before_log as $k => $v) {
- $employee_visit[$v['employee_id']][] = $v['customer_id'];
- }
- // 处理加微数据
- $jiav_employee = []; // 正常的客户
- $jiav_employee_wuxiao = []; // 无效的客户
- foreach ($jiav_list as $k => $v) {
- if (in_array($v['employee_id'], $page_employee) && !in_array($v['state'], Customer::changeState('无效', 'chaos', true))) {
- $jiav_employee[$v['employee_id']][] = $v['id'];
- } elseif (in_array($v['state'], Customer::changeState('无效', 'chaos', true))) {
- $jiav_employee_wuxiao[] = $v['id'];
- }
- }
- // 去查询这些置为无效的加微客户原先都是谁的
- $j_w_where[] = ['customer_id', 'in', $jiav_employee_wuxiao];
- $j_w_where[] = ['employee_id', 'in', $page_employee];
- $jiav_wuxiao_log = CustomerInvalidLog::where($j_w_where)->column('customer_id,employee_id');
- $jiav_wuxiao_log_deal = [];
- foreach ($jiav_wuxiao_log as $v) {
- $jiav_wuxiao_log_deal[$v['employee_id']][] = $v['customer_id'];
- }
- foreach ($jiav_employee as $k => $v) {
- if (isset($jiav_wuxiao_log_deal[$k])) {
- $jiav_employee[$k] = array_unique(array_merge($v, $jiav_wuxiao_log_deal[$k]));
- }
- }
- $customer_employee = []; // 员工下的客户
- $customer_ids_employee = []; // 员工下的客户id
- $customer_ids_key = []; // 客户所属员工
- foreach ($customer_list as $k => $v) {
- $customer_employee[$v['employee_id']][] = $v;
- $customer_ids_employee[$v['employee_id']][] = $v['id'];
- $customer_ids_key[$v['id']] = $v['employee_id'];
- }
- //2023-03-18 3.3客户标记无效后不能影响数据统计内的有效数据、线索数据 https://kdocs.cn/l/cfx92KlU838H
- $no_where = [
- ['employee_id', 'in', array_column($list, 'id')],
- ['state', 'in', CustomerVisitLog::changeState('无效', 'chaos')],
- ['addtime', 'between', [$param['start_date'], $param['end_date']]]
- ];
- $no_valid_customer = CustomerVisitLog::where($no_where)->column('id,customer_id,state,addtime,next_contact_date,remark,employee_id,confirm_date');
- $vislog_list = array_merge($vislog_list, $no_valid_customer);
- $visit_log_employee = []; //员工跟进记录
- foreach ($vislog_list as $k => $v) {
- $have_employee = $customer_ids_key[$v['customer_id']] ?? 0;
- if ($have_employee) {
- $v_customer_ids = $customer_ids_employee[$have_employee] ?? [];
- // 只保留还是员工客户的跟踪记录,或者是员工置为无效的客户记录
- if (!in_array($v['customer_id'], $v_customer_ids) && !in_array($v['state'], $wuxiao_log_state, true)) {
- unset($vislog_list[$k]);
- continue;
- }
- $visit_log_employee[$have_employee][] = $v;
- }
- }
- $vislog_list = array_values($vislog_list);
- foreach ($list as $k => $v) {
- $list[$k]['visit_log'] = $visit_log_employee[$v['id']] ?? [];
- $list[$k]['customer'] = $customer_employee[$v['id']] ?? [];
- }
- $customer['sign_customer'] = []; //签单客户
- $customer['measuring_room_customer'] = []; //量房客户
- $customer['maika_customer'] = []; //卖卡客户
- $customer['measuring_room_time'] = []; //量房时间
- $customer['to_the_store'] = []; //到店客户id
- $customer['to_the_store_time'] = []; //到店时间
- $customer['deposit_customer'] = []; //交定客户
- $customer['deposit_date'] = []; // 交定时间
- foreach ($vislog_list as $v) {
- if (in_array($v['state'], $state6, true)) { //签单客户id
- $customer['sign_customer'][] = $v['customer_id'];
- } elseif (in_array($v['state'], $state3, true)) { //量房客户id
- $customer['measuring_room_customer'][] = $v['customer_id'];
- //量房时间 按照时间升序排列
- if (empty($customer['measuring_room_time'][$v['customer_id']])) {
- $customer['measuring_room_time'][$v['customer_id']] = [];
- $customer['measuring_room_time'][$v['customer_id']][] = $v['confirm_date'];
- } else {
- $customer['measuring_room_time'][$v['customer_id']][] = $v['confirm_date'];
- }
- } elseif (in_array($v['state'], $state4, true)) { //到店客户id
- $customer['to_the_store'][] = $v['customer_id'];
- //到店时间 按照时间升序排列
- if (empty($customer['to_the_store_time'][$v['customer_id']])) {
- $customer['to_the_store_time'][$v['customer_id']] = [];
- $customer['to_the_store_time'][$v['customer_id']][] = $v['confirm_date'];
- } else {
- $customer['to_the_store_time'][$v['customer_id']][] = $v['confirm_date'];
- }
- } elseif (in_array($v['state'], $state5, true)) { //交定客户
- $customer['deposit_customer'][] = $v['customer_id'];
- //交定时间 按照时间升序排列
- if (empty($customer['deposit_date'][$v['customer_id']])) {
- $customer['deposit_date'][$v['customer_id']] = [];
- $customer['deposit_date'][$v['customer_id']][] = $v['confirm_date'];
- } else {
- $customer['deposit_date'][$v['customer_id']][] = $v['confirm_date'];
- }
- } elseif (in_array($v['state'], $state7, true)) { //卖卡客户
- $customer['maika_customer'][] = $v['customer_id'];
- }
- }
- // 有跟进客户
- $log_customer_id = []; // 某个员工下的跟踪客户id数组
- //智慧屏讲解次数
- $zhihui = [];
- // 无效
- $wuxiao_visit_log = [];
- foreach ($vislog_list as $k => $v) {
- if (in_array($v['state'], $wuxiao_log_state, true)) {
- $wuxiao_visit_log[] = $v;
- }
- $have_employee = $customer_ids_key[$v['customer_id']] ?? 0;
- if ($have_employee) {
- if (strpos($v['remark'], '讲解智慧屏##') !== false) {
- if (empty($zhihui[$have_employee])) {
- $zhihui[$have_employee] = 1;
- } else {
- $zhihui[$have_employee] += 1;
- }
- }
- }
- if (in_array($v['state'], $wuxiao_log_state, true)) {
- continue;
- }
- if (in_array($v['remark'], ['客户再分配', '资源库分配', '客户转移'], true) || (strpos($v['remark'], '业务员') !== false && strpos($v['remark'], '对客户') !== false && strpos($v['remark'], '进行报备') !== false)) {
- continue;
- }
- if ($have_employee) {
- if (isset($log_customer_id[$have_employee])) {
- $log_customer_id[$have_employee][] = $v['customer_id'];
- } else {
- $log_customer_id[$have_employee] = [];
- $log_customer_id[$have_employee][] = $v['customer_id'];
- }
- }
- }
- foreach ($log_customer_id as $k => $v) {
- $log_customer_id[$k] = array_values(array_unique($v));
- }
- // 外呼数据
- $outCallLog = OutCallLog::where([['root_id', '=', $root_id], ['employee_id', 'in', $page_employee]])->where($date_query)->field("count(id) as phone_count, sum(if(`status`>0,1,0)) as on_phone_count, sum(if(`status`<0,1,0)) as off_phone_count,sum(billsec) as phone_time,employee_id")->group('employee_id')->select()->toArray();
- $outCallLog = array_combine(array_column($outCallLog, 'employee_id'), $outCallLog);
- // 手机打电话次数获取
- $outCallMbLog = OutCallMbLog::where([
- ['root_id', '=', $root_id], ['employee_id', 'in', $page_employee]
- ])->where($date_query)->field("count(id) as phone_count,employee_id")->group('employee_id')->select()->toArray();
- $outCallMbLog = array_combine(array_column($outCallMbLog, 'employee_id'), $outCallMbLog);
- // 房屋状态设置项
- //房屋状态是否开启
- $house_status_where = [
- ['root_id', '=', $root_id],
- ['keyname', '=', 'house_status'],
- ['status', '=', 0]
- ];
- $house_status_per = CustomerPortraitField::where($house_status_where)->findOrEmpty();
- $house_status_field = [];
- if (!$house_status_per->isEmpty()) {
- $house_status_field = CustomerPortraitFieldSelect::where('pid', $house_status_per->id)->column('name,id');
- }
- // 户型是否开启
- $housetype_where = [
- ['root_id', '=', $root_id],
- ['keyname', '=', 'housetype_arrow'],
- ['status', '=', 0]
- ];
- $housetype_per = CustomerPortraitField::where($housetype_where)->findOrEmpty();
- $housetype_arrow = [];
- if (!$housetype_per->isEmpty()) {
- $housetype_arrow = CustomerPortraitFieldSelect::where('pid', $housetype_per->id)->column('name,id');
- }
- //分享内容次数
- $share_where = ['CompanyStrength', 'Article', 'Construction', 'Activity', 'MaterialEvidence', 'Video', 'MaterialCase', 'Building'];
- $share = ShareLog::where([['employee_id', 'in', $page_employee], ['type', 'in', $share_where]])->where($date_query1)->field('concat(employee_id,type,data_id) as str,employee_id')->select()->toArray();
- $shares = [];
- foreach ($share as $v) {
- if (empty($shares[$v['employee_id']])) {
- $shares[$v['employee_id']] = 1;
- } else {
- $shares[$v['employee_id']] += 1;
- }
- }
- // 培训资料是否看了 课程是否学习过
- $look = TrainCourseView::where([['employee_id', 'in', $page_employee], ['time', '>', 0]])->where($date_query)->group('employee_id')->column('employee_id');
- //考核次数 通过次数
- $don = TrainDoneLog::where([['employee_id', 'in', $page_employee]])->where($date_query)->column('employee_id,done_percent');
- $don1 = $don2 = [];
- foreach ($don as $don_k => $don_v) {
- if (empty($don1[$don_v['employee_id']])) {
- $don1[$don_v['employee_id']] = 1;
- } else {
- $don1[$don_v['employee_id']] += 1;
- }
- if ($don_v['done_percent'] == 100) {
- if (empty($don2[$don_v['employee_id']])) {
- $don2[$don_v['employee_id']] = 1;
- } else {
- $don2[$don_v['employee_id']] += 1;
- }
- }
- }
- //无效客资
- $invalid = Setting::where([['name', '=', 'clueTag'], ['root_id', '=', $root_id]])->value('content');
- $invalid = $invalid ? explode(',', $invalid) : ['已装修', '无需求', '有需求', '超地域', '未交房', '在外地', '无购买力', '未接通电话'];
- $invalid_customer = [];
- // 按客户来源搜索处理
- $wuxiao_customer_id = array_values(array_unique(array_column($wuxiao_visit_log, 'customer_id')));
- $no_valid_customers = []; //2023-03-18 3.3客户标记无效后不能影响数据统计内的有效数据、线索数据 https://kdocs.cn/l/cfx92KlU838H 康
- if ($param['source_id']) {
- $wuxiao_source_customer_id = Customer::where([['id', 'in', $wuxiao_customer_id], ['source_id', '=', $param['source_id']]])->column('id');
- foreach ($wuxiao_visit_log as $k => $v) {
- if (in_array($v['customer_id'], $wuxiao_source_customer_id)) {
- $remark = '';
- if (in_array($v['remark'], $invalid)) {
- $remark = $v['remark'];
- } else {
- foreach ($invalid as $i_k => $i_v) {
- if (strpos($v['remark'], $i_v) !== false) {
- $remark = $i_v;
- break;
- }
- }
- }
- if (isset($invalid_customer[$v['employee_id']])) {
- $invalid_customer[$v['employee_id']][] = ['remark' => $remark, 'customer_id' => $v['customer_id']];
- } else {
- $invalid_customer[$v['employee_id']] = [];
- $invalid_customer[$v['employee_id']][] = ['remark' => $remark, 'customer_id' => $v['customer_id']];
- }
- if (isset($no_valid_customers[$v['employee_id']])) {
- $no_valid_customers[$v['employee_id']][] = $v['customer_id'];
- } else {
- $no_valid_customers[$v['employee_id']] = [];
- $no_valid_customers[$v['employee_id']][] = $v['customer_id'];
- }
- }
- }
- } else {
- foreach ($wuxiao_visit_log as $k => $v) {
- $remark = '';
- if (in_array($v['remark'], $invalid)) {
- $remark = $v['remark'];
- } else {
- foreach ($invalid as $i_k => $i_v) {
- if (strpos($v['remark'], $i_v) !== false) {
- $remark = $i_v;
- break;
- }
- }
- }
- if (isset($invalid_customer[$v['employee_id']])) {
- $invalid_customer[$v['employee_id']][] = ['remark' => $remark, 'customer_id' => $v['customer_id']];
- } else {
- $invalid_customer[$v['employee_id']] = [];
- $invalid_customer[$v['employee_id']][] = ['remark' => $remark, 'customer_id' => $v['customer_id']];
- }
- if (isset($no_valid_customers[$v['employee_id']])) {
- $no_valid_customers[$v['employee_id']][] = $v['customer_id'];
- } else {
- $no_valid_customers[$v['employee_id']] = [];
- $no_valid_customers[$v['employee_id']][] = $v['customer_id'];
- }
- }
- }
- // 无效客资来自资源分配
- $wuxiao_customer_res_id = Customer::where([['id', 'in', $wuxiao_customer_id], ['crm_res_id', '>', 0]])->column('id');
- $wuxiao_customer_res_employee = [];
- // 无效客资来自自建
- $wuxiao_customer_build_employee = [];
- foreach ($invalid_customer as $k => $v) {
- $customer_id_v = array_column($v, 'customer_id');
- foreach ($customer_id_v as $vv) {
- if (in_array($vv, $wuxiao_customer_res_id)) {
- $wuxiao_customer_res_employee[$k][] = $vv;
- } else {
- $wuxiao_customer_build_employee[$k][] = $vv;
- }
- }
- }
- $f_invalid = array_flip($invalid);
- //预约记录
- $sub_where = [
- ['CustomersSubscribe.state', '=', 0],
- ['CustomersSubscribe.type', 'in', [1, 3]],
- ['CustomersSubscribe.employee_id', 'in', $page_employee]
- ];
- if ($date_query) $sub_where[] = ['CustomersSubscribe.addtime', 'between', [$param['start_date'], $param['end_date']]]; //日期条件
- $sub1 = $sub2 = []; //1到店 2量房
- $subscribe = Db::view('CustomersSubscribe')
- ->view('Customer', 'id', 'CustomersSubscribe.customer_id=Customer.id')
- ->where($sub_where)
- ->column('CustomersSubscribe.type,CustomersSubscribe.employee_id');
- foreach ($subscribe as $v) {
- $v['type'] == 1 ? @$sub1[$v['employee_id']] += 1 : @$sub2[$v['employee_id']] += 1;
- }
- foreach ($list as $k => $v) {
- //部门名称
- $list[$k]['org_name'] = $v['org']['name'];
- //预计到店数
- $list[$k]['yuji_store'] = isset($sub1[$v['id']]) ? $sub1[$v['id']] : 0;
- //客户id 所有的客户ID 包括资源,自创,无效等
- $all_customer_id = array_column($v['customer'], 'id');
- //数据处理
- $customer_data = $this->dealCustomerData($v['customer'], $sdate, $edate, $customer['measuring_room_time'], $customer['to_the_store_time'], $customer['deposit_date']);
- $cycle_data = $this->avgCycle($v['customer'], $v['visit_log']);
- $v_employee_visit = $employee_visit[$v['id']] ?? [];
- $visit_data = $this->visitDeal($v['visit_log'], $v_employee_visit);
- // 分配资源数量 包含已置入公海的
- $resource_wuxiao_ids = [];
- if (isset($wuxiao_customer_res_employee[$v['id']])) {
- $resource_wuxiao_ids = array_values(array_unique($wuxiao_customer_res_employee[$v['id']]));
- }
- // 由于置为无效之后没有了获取客户时间(employee_time) 所以资源不统计无效
- // $list[$k]['resource_count'] = count(array_unique(array_merge($customer_data['is_resource'], $resource_wuxiao_ids)));
- $resource_count = $fenpei_cus_employee[$v['id']] ?? [];
- $list[$k]['resource_count'] = count($resource_count);
- if (isset($outCallLog[$v['id']])) {
- // 拨打电话数量
- $list[$k]['connecting_count'] = $outCallLog[$v['id']]['phone_count'];
- // 接通数量
- $list[$k]['connecting_capacity'] = $outCallLog[$v['id']]['on_phone_count'];
- // 接通率
- $list[$k]['connecting_capacity_grawth'] = $outCallLog[$v['id']]['phone_count'] == 0 ? '0%' : round($outCallLog[$v['id']]['on_phone_count'] / $outCallLog[$v['id']]['phone_count'] * 100, 1) . '%';
- // 未接通数量
- $list[$k]['connecting_no'] = $outCallLog[$v['id']]['off_phone_count'];
- // 总通话时长(分)
- $list[$k]['phone_time'] = round($outCallLog[$v['id']]['phone_time'] / 60, 1);
- // 平均通话时长(秒)
- $list[$k]['average_duration'] = $outCallLog[$v['id']]['on_phone_count'] == 0 ? 0 : round($outCallLog[$v['id']]['phone_time'] / $outCallLog[$v['id']]['on_phone_count'], 0);
- } else {
- $list[$k]['connecting_count'] = $list[$k]['connecting_capacity'] = $list[$k]['connecting_no'] = $list[$k]['phone_time'] = $list[$k]['average_duration'] = 0;
- $list[$k]['connecting_capacity_grawth'] = '0%';
- }
- // 手机通话
- if (isset($outCallMbLog[$v['id']])) $list[$k]['connecting_count'] += $outCallMbLog[$v['id']]['phone_count'];
- // 客户总量
- $customer_count = $customer_data['customer_count'];
- $list[$k]['following_up_count'] = count($customer_count);
- // 加微客户数量
- $v_wechat_count = $jiav_employee[$v['id']] ?? [];
- $list[$k]['add_wechat_count'] = count($v_wechat_count);
- // 待确认客户数
- $list[$k]['not_sure_count'] = count($customer_data['not_sure_count']);
- // 有效客户数
- if (isset($no_valid_customers[$v['id']])) {
- $list[$k]['valid_count'] = count(array_unique(array_merge($customer_data['valid_count'], $no_valid_customers[$v['id']])));
- } else {
- $list[$k]['valid_count'] = count($customer_data['valid_count']);
- }
- //有效未加微
- $list[$k]['valid_no_wechat'] = count(array_diff($customer_data['valid_count'], $customer_data['wechat_count']));
- // 报备客户数
- //$reported_diff = array_diff($all_customer_id, $customer_data['is_resource']); //现有客户除去资源库来的
- // $reported_quantity = isset($wuxiao_customer_build_employee[$v['id']]) ? array_unique(array_merge($reported_diff, $wuxiao_customer_build_employee[$v['id']])) : $reported_diff;
- $reported_diff = $add_cus_employee[$v['id']] ?? [];
- $list[$k]['reported_quantity'] = count($reported_diff);
- // 加微率
- $list[$k]['add_wechat_count_grawth'] = count($customer_count) == 0 ? '0%' : round(count($v_wechat_count) / count($customer_count) * 100, 2) . '%';
- // 无效客户数
- foreach ($invalid as $invalid_k => $invalid_v) {
- $list[$k]['invalid_customer_' . $invalid_k] = [];
- }
- if (isset($invalid_customer[$v['id']])) {
- $invalid_customer_all = array_unique(array_column($invalid_customer[$v['id']], 'customer_id'));
- $list[$k]['invalid_customer_count'] = count($invalid_customer_all);
- if ($invalid) {
- foreach ($invalid_customer[$v['id']] as $key => $value) {
- if ($value['remark']) {
- $key = $f_invalid[$value['remark']];
- $list[$k]['invalid_customer_' . $key][] = $value['customer_id'];
- }
- }
- }
- } else {
- $invalid_customer_all = [];
- $list[$k]['invalid_customer_count'] = 0;
- }
- foreach ($invalid as $invalid_k => $invalid_v) {
- $list[$k]['invalid_customer_' . $invalid_k] = count(array_unique($list[$k]['invalid_customer_' . $invalid_k]));
- }
- // 线索总量
- $v_customer = !empty($v['customer']) ? array_column($v['customer'], 'id') : [];
- $all_customer = array_unique(array_merge($v_customer, $invalid_customer_all));
- $list[$k]['all_customer_count'] = count($all_customer);
- // 有效率(%)
- $list[$k]['valid_grawth'] = count($all_customer) == 0 ? '0%' : round(count($customer_data['valid_count']) / count($all_customer) * 100, 2) . '%';
- // 未跟进客户数
- if (isset($log_customer_id[$v['id']])) {
- $following_up_count = $log_customer_id[$v['id']];
- } else {
- $following_up_count = [];
- }
- $list[$k]['not_following_up_count'] = count($customer_count) - count(array_intersect($customer_count, $following_up_count)); // 总的减去有跟进的
- // 意向分派客户数
- $list[$k]['yixiang_assigned_count'] = count($customer_data['yixiang_assigned_count']);
- // 到店分派客户数
- $list[$k]['daodian_assigned_count'] = count($customer_data['daodian_assigned_count']);
- // 量房分配客户数
- $list[$k]['measuring_assigned_count'] = count($customer_data['liangfang_assigned_count']);
- // 智慧屏讲解次数
- $list[$k]['number_of_explanations'] = isset($zhihui[$v['id']]) ? $zhihui[$v['id']] : 0;
- // 量房客户数
- $measuring_room_customer = array_intersect($all_customer_id, $customer['measuring_room_customer']); //量房客户ID
- $to_the_store_ids = array_intersect($all_customer_id, $customer['to_the_store']); // 到店客户ID
- $list[$k]['measuring_room_customer'] = count($measuring_room_customer);
- // 量房未到店
- $measuring_room_customer_to_store = array_intersect($measuring_room_customer, $to_the_store_ids); // 量房 和 到店
- $measuring_room_customer_no_to_store = array_diff($measuring_room_customer, $measuring_room_customer_to_store);
- $list[$k]['measuring_room_customer_no_to_store'] = count($measuring_room_customer_no_to_store);
- // 量房已到店
- $list[$k]['measuring_room_customer_to_store'] = count($measuring_room_customer_to_store);
- //平均量房到店周期
- $list[$k]['avg_room_store_zhouqi'] = $cycle_data['room_store_cycle'];
- // 平均量房周期(天)
- $list[$k]['measuring_room_zhouqi'] = $cycle_data['room_cycle'];
- // 量房率
- $list[$k]['measuring_room_grawth'] = count($customer_count) == 0 ? '0%' : round(count($measuring_room_customer) / count($customer_count) * 100, 2) . '%';
- // 到店数 次数
- $to_the_store = 0;
- foreach ($customer['to_the_store'] as $kk => $vv) {
- if (in_array($vv, $all_customer_id)) {
- $to_the_store++;
- }
- }
- //有户型图的客户
- $list[$k]['drawing_date_count'] = count($customer_data['drawing_date']);
- $list[$k]['to_the_store'] = $to_the_store;
- // 一次到店数
- $list[$k]['to_the_store_1'] = $customer_data['strtore_count_0'];
- // 二次到店
- $list[$k]['to_the_store_2'] = $customer_data['strtore_count_1'];
- // 二次到店比率
- $list[$k]['strtore_2v1'] = $customer_data['strtore_count_0'] == 0 ? '0%' : round($customer_data['strtore_count_1'] / $customer_data['strtore_count_0'] * 100, 2) . '%';
- // 三次及以上到店
- $list[$k]['to_the_store_3'] = $customer_data['strtore_count_2'];
- // 平均到店周期(天)
- $list[$k]['strtore_avg_days_1'] = ceil($customer_data['strtore_0'] / 86400); // 一次
- $list[$k]['strtore_avg_days_2'] = ceil($customer_data['strtore_1'] / 86400); // 二次
- $list[$k]['strtore_avg_days_3'] = ceil($customer_data['strtore_2'] / 86400); // 三次
- //一次 二次 三次 到店率
- $list[$k]['strtore_count_1_grawth'] = count($customer_count) == 0 ? '0%' : round($customer_data['strtore_count_0'] / count($customer_count) * 100, 2) . '%';
- $list[$k]['strtore_count_2_grawth'] = count($customer_count) == 0 ? '0%' : round($customer_data['strtore_count_1'] / count($customer_count) * 100, 2) . '%';
- $list[$k]['strtore_count_3_grawth'] = count($customer_count) == 0 ? '0%' : round($customer_data['strtore_count_2'] / count($customer_count) * 100, 2) . '%';
- // 到店客户数
- $list[$k]['strtore_customer_count'] = count($to_the_store_ids);
- // 到店率
- $list[$k]['strtore_customer_grawth'] = count($customer_count) == 0 ? '0%' : round(count($to_the_store_ids) / count($customer_count) * 100, 2) . '%';
- // 签单客户数量
- $deposit_count_ids = array_intersect($all_customer_id, $customer['deposit_customer']);
- $list[$k]['deposit_count'] = count($deposit_count_ids);
- // 签单率
- $list[$k]['deposit_avg'] = count($visit_data) == 0 ? '0%' : round(count($deposit_count_ids) / count($visit_data) * 100, 2) . '%';
- // 平均签单周期
- $list[$k]['deposit_avg_days'] = $cycle_data['dep_cycle'];
- // 转单客户数量
- $sign_customer_ids = array_intersect($all_customer_id, $customer['sign_customer']);
- $list[$k]['sign_count'] = count($sign_customer_ids);
- //一次 二次 三次 到店交定个数
- $list[$k]['strtore_deposit_count_0'] = count(array_unique(array_intersect($customer['deposit_customer'], $customer_data['strtore_customer_0'])));
- $list[$k]['strtore_deposit_count_1'] = count(array_unique(array_intersect($customer['deposit_customer'], $customer_data['strtore_customer_1'])));
- $list[$k]['strtore_deposit_count_2'] = count(array_unique(array_intersect($customer['deposit_customer'], $customer_data['strtore_customer_2'])));
- //一次 二次 三次 到店交定率 数量/有效
- $list[$k]['strtore_deposit_grawth_0'] = count($customer_count) == 0 ? '0%' : round($list[$k]['strtore_deposit_count_0'] / count($customer_count) * 100, 2) . '%';
- $list[$k]['strtore_deposit_grawth_1'] = count($customer_count) == 0 ? '0%' : round($list[$k]['strtore_deposit_count_1'] / count($customer_count) * 100, 2) . '%';
- $list[$k]['strtore_deposit_grawth_2'] = count($customer_count) == 0 ? '0%' : round($list[$k]['strtore_deposit_count_2'] / count($customer_count) * 100, 2) . '%';
- // 卖卡客户数量
- $maika_customer_ids = array_intersect($all_customer_id, $customer['maika_customer']);
- $list[$k]['maika_count'] = count($maika_customer_ids);
- // 转单率
- $list[$k]['sign_count_grawth'] = count($visit_data) == 0 ? '0%' : round(count($sign_customer_ids) / count($visit_data) * 100, 2) . '%';
- // 平均跟进次数
- $list[$k]['avg_visit_count'] = $cycle_data['next'];
- // 平均合同金额(元)
- $list[$k]['signed_money'] = $customer_data['signed_money'];
- // 合同总金额
- $list[$k]['signed_money_all'] = $customer_data['signed_money_all'];
- // 面积
- $list[$k]['square'] = $customer_data['square'];
- $list[$k]['square_0_80'] = $customer_data['square_0_80'];
- $list[$k]['square_80_100'] = $customer_data['square_80_100'];
- $list[$k]['square_100_120'] = $customer_data['square_100_120'];
- $list[$k]['square_120_200'] = $customer_data['square_120_200'];
- $list[$k]['square_200_500'] = $customer_data['square_200_500'];
- $list[$k]['square_500'] = $customer_data['square_500'];
- // 房屋状态
- $list[$k]['house_status'] = 0;
- if ($house_status_field) {
- $house_status = $this->getHouseStatus($customer_data['house_status'], $house_status_field);
- $list[$k] = array_merge($list[$k], $house_status);
- $list[$k]['house_status'] = array_sum($house_status);
- }
- //房屋户型 及 对应的转单率
- if ($housetype_arrow) {
- $housetype_arrow_data = $this->getHousetypeArrow($customer_data['housetype_arrow'], $housetype_arrow, $sign_customer_ids);
- $list[$k] = array_merge($list[$k], $housetype_arrow_data);
- }
- // 房屋类型
- $list[$k]['house_type'] = $customer_data['existing_homes_count'] + $customer_data['forward_housing_count'];
- $list[$k]['existing_homes_count'] = $customer_data['existing_homes_count'];
- $list[$k]['forward_housing_count'] = $customer_data['forward_housing_count'];
- // 调用内容数量
- // 分享内容次数
- $list[$k]['shares_count'] = isset($shares[$v['id']]) ? $shares[$v['id']] : 0;
- // 考核次数
- $list[$k]['assessment_times'] = isset($don1[$v['id']]) ? $don1[$v['id']] : 0;
- // 通过次数
- $list[$k]['number_of_passes'] = isset($don2[$v['id']]) ? $don2[$v['id']] : 0;
- //培训资料是否看了 课程是否学习过
- $list[$k]['look_data'] = in_array($v['id'], $look) ? '是' : '否';
- unset($list[$k]['customer']);
- unset($list[$k]['visit_log']);
- }
- return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
- }
- /**
- * 处理客户数据
- * $list 业务员的客户数组
- * $sdate 开始时间筛选
- * $edate 结束时间筛选
- * $measuring_room_time 客户量房时间 计算平均量房时间
- * $to_the_store_time 客户到店时间 计算平均到店时间
- * $deposit_customer 客户交定时间 计算平均交定周期
- */
- static function dealCustomerData($list, $sdate, $edate, $measuring_room_time, $to_the_store_time, $deposit_customer)
- {
- $time = time();
- $data['not_sure_count'] = []; // 待确认客户id
- $data['customer_count'] = []; // 客户量 除去资源、无效、死单
- $data['valid_count'] = []; // 有效客户 除去资源、无效、死单、待确认 (客户量的基础上减去待确认的)
- $data['yixiang_assigned_count'] = []; // 意向分配客户数
- $data['daodian_assigned_count'] = []; // 到店分配客户数
- $data['liangfang_assigned_count'] = []; // 量房分配客户数
- $data['wechat_count'] = []; //加微客户id
- $data['is_resource'] = []; //资源库分配客户id
- $data['drawing_date'] = []; //有户型图的客户
- $row['room_cycle_0'] = $row['room_cycle_1'] = $row['room_cycle_2'] = []; //一次 二次 三次量房周期
- $row['strtore_0'] = $row['strtore_1'] = $row['strtore_2'] = []; //一次 二次 三次到店周期
- $row['deposit_0'] = $row['deposit_1'] = $row['deposit_2'] = []; //一次 二次 三次交定周期
- $data['room_cycle_customer_0'] = $data['room_cycle_customer_1'] = $data['room_cycle_customer_2'] = []; //一次 两次 三次量房客户
- $data['strtore_customer_0'] = $data['strtore_customer_1'] = $data['strtore_customer_2'] = []; //一次 两次 三次到店客户
- $data['deposit_customer_0'] = $data['deposit_customer_1'] = $data['deposit_customer_2'] = []; //一次 两次 三次交定客户
- $row['signed_money'] = []; //合同金额
- $house_type = []; //房屋类型
- $housetype_arrow = []; // 房屋户型
- $square = []; //房屋面积
- $data['house_status'] = []; //房屋状态
- //报备客户
- $data['reported_quantity'] = 0;
- //死单客户
- $data['died'] = 0;
- $not_sure_state = Customer::changeState('待确认', 'chaos');
- $invalid_state = Customer::changeState('无效', 'chaos');
- $invalid_not_sure_state = array_values(array_merge($invalid_state, $not_sure_state));
- foreach ($list as $v) {
- // 待确认客户
- if (empty($v['crm_res_id']) && in_array($v['state'], $not_sure_state, true)) {
- $data['not_sure_count'][] = $v['id'];
- }
- //客户添加时间
- $addtime = strtotime($v['addtime']);
- // 客户数量
- if (intval($v['died']) != 2) {
- if ((empty($v['crm_res_id']) && !in_array($v['state'], $invalid_state, true)) || (!empty($v['crm_res_id']) && !in_array($v['state'], $invalid_not_sure_state, true))) {
- $data['customer_count'][] = $v['id'];
- $square[] = $v['square']; //面积
- }
- }
- // 有效客户 一部分数据只是有效时候才做统计
- if (intval($v['died']) != 2 && !in_array($v['state'], $invalid_not_sure_state, true)) {
- $data['valid_count'][] = $v['id'];
- // 房屋类型
- $house_type[] = $v['house_type'];
- $row['signed_money'][] = $v['signed_money']; //合同金额
- $data['house_status'][] = $v['house_status'];
- // 房屋户型
- $ext = json_decode($v['ext'], true);
- if (!empty($ext) && is_array($ext)) {
- $ext = array_filter($ext);
- foreach ($ext as $e) {
- if (isset($e['keyname']) && $e['keyname'] == 'housetype_arrow' && !empty($e['value'])) {
- $housetype_arrow[$v['id']] = $e['value'];
- }
- }
- }
- }
- // 意向分派客户数
- if (!empty($v['assign_type']) && $v['assign_type'] == 'yixiang') {
- $data['yixiang_assigned_count'][] = $v['id'];
- }
- // 到店分派客户数
- if (!empty($v['assign_type']) && $v['assign_type'] == 'daodian') {
- $data['daodian_assigned_count'][] = $v['id'];
- }
- // 量房分派客户数
- if (!empty($v['assign_type']) && $v['assign_type'] == 'liangfang') {
- $data['liangfang_assigned_count'][] = $v['id'];
- }
- //资源库分配数量
- if ($v['crm_res_id'] && strtotime($v['employee_time']) >= $sdate && strtotime($v['employee_time']) <= $edate) {
- $data['is_resource'][] = $v['id'];
- }
- //加微客户,有户型图客户
- $v2 = $v['ext'];
- $ext = json_decode($v2, true);
- if (!empty($ext) && is_array($ext)) {
- $ext = array_filter($ext);
- foreach ($ext as $e) {
- if (isset($e['keyname']) && $e['keyname'] == 'add_wechat_time' && !empty($e['value'])) {
- $data['wechat_count'][] = $v['id'];
- } elseif (isset($e['keyname']) && $e['keyname'] == 'drawing_date' && !empty($e['value']) && strtotime($e['value']) <= $time) {
- $data['drawing_date'][] = $v['id'];
- }
- }
- }
- //一次 二次 三次量房周期
- if (isset($measuring_room_time[$v['id']])) {
- $count = count($measuring_room_time[$v['id']]);
- $start = $count >= 3 ? 2 : $count - 1;
- $measuring_room_cycle = [];
- $measuring_room_cycle[$start] = $measuring_room_time[$v['id']][$start];
- // $measuring_room_cycle = array_slice($measuring_room_time[$v['id']],0, 3);
- foreach ($measuring_room_cycle as $cycle_key => $cycle_item) {
- $cycle_addtime = strtotime($cycle_item);
- if ($addtime < $cycle_addtime) $row['room_cycle_' . $cycle_key][] = $cycle_addtime - $addtime;
- $data['room_cycle_customer_' . $cycle_key][] = $v['id'];
- }
- }
- //一次 二次 三次到店周期
- if (isset($to_the_store_time[$v['id']])) {
- $count = count($to_the_store_time[$v['id']]);
- $start = $count >= 3 ? 2 : $count - 1;
- $to_the_store_times = [];
- $to_the_store_times[$start] = $to_the_store_time[$v['id']][$start];
- // $to_the_store_times = array_slice($to_the_store_time[$v['id']],0, 3);
- foreach ($to_the_store_times as $store_key => $store_item) {
- $store_addtime = strtotime($store_item);
- if ($addtime < $store_addtime) $row['strtore_' . $store_key][] = $store_addtime - $addtime;
- $data['strtore_customer_' . $store_key][] = $v['id'];
- }
- }
- //一次 二次 三次交定周期
- if (isset($deposit_customer[$v['id']])) {
- $count = count($deposit_customer[$v['id']]);
- $start = $count >= 3 ? 2 : $count - 1;
- $deposit_customer_time = [];
- $deposit_customer_time[$start] = $deposit_customer[$v['id']][$start];
- // $deposit_customer_time = array_slice($deposit_customer[$v['id']],0, 3);
- foreach ($deposit_customer_time as $deposit_key => $deposit_item) {
- $deposit_addtime = strtotime($deposit_item);
- if ($addtime < $deposit_item) $row['deposit_' . $deposit_key][] = $deposit_addtime - $addtime;
- $data['deposit_customer_' . $deposit_key][] = $v['id'];
- }
- }
- //死单
- if (intval($v['died']) == 2) $data['died'] += 1;
- }
- $data['housetype_arrow'] = $housetype_arrow;
- foreach ([0, 1, 2] as $range) {
- //平均一次,二次,三次量房周期
- $data['room_cycle_' . $range] = $row['room_cycle_' . $range] ? ceil(array_sum($row['room_cycle_' . $range]) / count($row['room_cycle_' . $range])) : 0;
- //一次,二次,三次 量房人数
- $data['room_cycle_count_' . $range] = count($data['room_cycle_customer_' . $range]);
- //平均到店周期
- $data['strtore_' . $range] = $row['strtore_' . $range] ? ceil(array_sum($row['strtore_' . $range]) / count($row['strtore_' . $range])) : 0;
- //一次 二次 三次 到店人数
- $data['strtore_count_' . $range] = count($data['strtore_customer_' . $range]);
- //平均交定周期
- $data['deposit_' . $range] = $row['deposit_' . $range] ? ceil(array_sum($row['deposit_' . $range]) / count($row['deposit_' . $range])) : 0;
- //一次 二次 三次 交定人数
- $data['deposit_count_' . $range] = count($data['deposit_customer_' . $range]);
- }
- //平均合同金额
- $signed_money = array_filter($row['signed_money']);
- $data['signed_money'] = empty($signed_money) ? 0 : round(array_sum($signed_money) / count($signed_money), 2);
- $data['signed_money_all'] = array_sum($signed_money);
- //房屋类型
- $data['existing_homes_count'] = 0; //现房数量
- $data['forward_housing_count'] = 0; //期房数量
- foreach ($house_type as $house_type_item) {
- if (strpos($house_type_item, '现房') !== false) {
- $data['existing_homes_count'] += 1;
- } elseif (strpos($house_type_item, '期房') !== false) {
- $data['forward_housing_count'] += 1;
- }
- }
- //房屋面积
- $data['square'] = $data['square_0_80'] = $data['square_80_100'] = $data['square_100_120'] = $data['square_120_200'] = $data['square_200_500'] = $data['square_500'] = 0;
- foreach ($square as $square_item) {
- if (!$square_item) continue;
- $data['square'] += 1;
- if ($square_item <= 80) {
- $data['square_0_80'] += 1;
- } elseif ($square_item <= 100) {
- $data['square_80_100'] += 1;
- } elseif ($square_item <= 120) {
- $data['square_100_120'] += 1;
- } elseif ($square_item <= 200) {
- $data['square_120_200'] += 1;
- } elseif ($square_item <= 500) {
- $data['square_200_500'] += 1;
- } else {
- $data['square_500'] += 1;
- }
- }
- return $data;
- }
- /**
- * 弹框页面
- */
- public function generalOpen()
- {
- $root_id = request()->employee->root_id;
- $eid = input('eid', '', 'intval');
- View::assign('eid', $eid);
- $type = input('type', '');
- $start_date = input('start_date', '');
- $end_date = input('end_date', '');
- if ($start_date) {
- $ls_date = explode(' - ', $start_date);
- if (count($ls_date) == 2) {
- $start_date = $ls_date[0];
- $end_date = $ls_date[1];
- }
- }
- if ($type == 'assign') {
- //待指派
- $field = [
- ['field' => 'name', 'title' => '姓名'],
- ['field' => 'phone', 'title' => '电话']
- ];
- $url = url("statistics/generalOpenData", ["eid" => $eid, 'type' => $type, 'end_date' => $end_date, 'start_date' => $start_date]);
- } elseif ($type == 'share') {
- //调用内容
- $field = [
- ['field' => 'share_time', 'title' => '分享时间'],
- ['field' => 'title', 'title' => '分享内容']
- ];
- $url = url("statistics/generalOpenData", ["eid" => $eid, 'type' => $type, 'end_date' => $end_date, 'start_date' => $start_date]);
- } elseif ($type == 'yuji_store') {
- //预计到店
- $field = [
- ['field' => 'name', 'title' => '姓名'],
- ['field' => 'date', 'title' => '预约时间']
- ];
- $url = url("statistics/generalOpenData", ["eid" => $eid, 'type' => $type, 'end_date' => $end_date, 'start_date' => $start_date]);
- } elseif ($type == 'number_of_explanations') {
- //智慧屏讲解客户列表
- $field = [
- ['field' => 'name', 'title' => '姓名'],
- ['field' => 'phone', 'title' => '电话'],
- ['field' => 'addtime', 'title' => '讲解时间']
- ];
- $url = url("statistics/generalOpenData", ["eid" => $eid, 'type' => $type, 'end_date' => $end_date, 'start_date' => $start_date]);
- } elseif ($type == 'invalid') {
- //无效客资
- $field = [
- ['field' => 'name', 'title' => '姓名'],
- ['field' => 'phone', 'title' => '电话']
- ];
- $url = url("statistics/generalOpenData", ["eid" => $eid, 'type' => $type, 'end_date' => $end_date, 'start_date' => $start_date, 'key' => input('key', '')]);
- } else {
- //加微客户
- $field = [
- ['field' => 'name', 'title' => '姓名'],
- ['field' => 'phone', 'title' => '电话']
- ];
- $url = url("statistics/generalOpenData", ["eid" => $eid, 'type' => $type, 'end_date' => $end_date, 'start_date' => $start_date]);
- }
- View::assign('fields', json_encode($field));
- View::assign('url', $url);
- return View::fetch('add_wechat');
- }
- /**
- * 弹框列表
- */
- public function generalOpenData()
- {
- $param = Request::only(['page' => 1, 'limit' => 10, 'eid' => 0, 'type' => '', 'start_date' => '', 'end_date' => '']);
- $page = $param['page'];
- $limit = $param['limit'];
- $root_id = request()->employee->root_id;
- $where = [
- ['employee_id', '=', $param['eid']]
- ];
- $sdate = strtotime('2015-01-01');
- $edate = time();
- if ($param['start_date'] && $param['end_date']) {
- $sdate = strtotime($param['start_date']);
- $edate = strtotime($param['end_date']);
- }
- $start_date = date('Y-m-d 00:00:00', $sdate);
- $end_date = date('Y-m-d 23:59:59', $edate);
- if ($param['type'] == 'wechat') {
- $where[] = ['add_wechat_time', 'between', [$start_date, $end_date]];
- $wuxiao_state = Customer::changeState('无效', 'chaos');
- $w_where[] = ['add_wechat_time', 'between', [$start_date, $end_date]];
- $w_where[] = ['employee_id', 'null', null];
- $w_where[] = ['state', 'in', $wuxiao_state];
- $ids_wuxiao = Customer::where($w_where)->column('id'); //这是加微的,但是置为无效的客户
- $j_w_where[] = ['customer_id', 'in', $ids_wuxiao];
- $j_w_where[] = ['employee_id', '=', $param['eid']];
- // 无效的加微客户id
- $jiav_wuxiao_log = CustomerInvalidLog::where($j_w_where)->column('customer_id');
- // 所属员工的加微客户id
- $customer_ids = Customer::where($where)->column('id');
- $ids = array_unique(array_merge($customer_ids, $jiav_wuxiao_log));
- $where1[] = ['id', 'in', $ids];
- $where2[] = ['customer_id', 'in', $ids];
- $data = $this->selCustomerValid($where1, $where2, $page, $limit, []);
- $list = $data['list'];
- $count = $data['count'];
- } elseif ($param['type'] == 'drawing') {
- $field = 'drawing_date';
- $vis_where[] = ['Customer.employee_id', '=', $param['eid']];
- $vis_where[] = ['Customer.ext', 'like', '%' . $field . '%'];
- $vis_where[] = ['Customer.died', '<>', 2];
- $vis_where[] = ['CustomerVisitLog.confirm_date', 'between', [$start_date, $end_date]];
- $ext = Db::view('CustomerVisitLog', 'customer_id')
- ->view('Customer', [], 'CustomerVisitLog.customer_id=Customer.id')
- ->where($vis_where)
- ->group('Customer.id')
- ->column('Customer.id,Customer.ext');
- $cid = [];
- foreach ($ext as $v) {
- $json = json_decode($v['ext'], true);
- foreach ($json as $v2) {
- if (!isset($v2['keyname'])) continue;
- if ($v2['keyname'] == $field && !empty($v2['value']) && strtotime($v2['value']) >= $sdate && strtotime($v2['value']) <= $edate) {
- $cid[] = $v['id'];
- }
- }
- }
- $where[] = ['id', 'in', $cid];
- $count = Customer::where($where)->count();
- $list = Customer::where($where)->field('name,phone')->page($page, $limit)->select()->toArray();
- } elseif ($param['type'] == 'share') {
- //调用内容
- $share_where = ['CompanyStrength', 'Article', 'Construction', 'Activity', 'MaterialEvidence', 'Video', 'MaterialCase', 'Building'];
- $wheres = [
- ['employee_id', '=', $param['eid']],
- ['type', 'in', $share_where],
- ['share_time', 'between', [$start_date, $end_date]]
- ];
- $model = ShareLog::with('content')->where($wheres)->order('id desc');
- $count = $model->count();
- $list = $model->page($page, $limit)->select()->toArray();
- $arr = [
- 'Activity' => '#活动#',
- 'Article' => '#图文素材#',
- 'Building' => '#楼盘进度#',
- 'Card' => '#名片#',
- 'CompanyStrength' => '#公司实力#',
- 'Construction' => '#在施工地#',
- 'CustomerJsAll' => '',
- 'MaterialCase' => '#装修案例#',
- 'MaterialEvidence' => '#口碑见证#',
- 'ToolAll' => '#谈单工具#',
- 'Video' => '#视频#',
- 'Weiwang' => '#个人微网#'
- ];
- foreach ($list as $k => $v) {
- $type = isset($arr[$v['type']]) ? $arr[$v['type']] : '';
- $field = $v['type'] == 'Building' ? 'name' : 'title';
- if ($v['content'] && isset($v['content'][$field])) {
- $list[$k]['title'] = $type . '《' . $v['content'][$field] . '》';
- } else {
- $list[$k]['title'] = '暂无';
- }
- }
- } elseif ($param['type'] == 'resource') { //分配
- $where[] = ['crm_res_id', 'not null', null];
- $where[] = ['died', '<>', 2];
- $where[] = ['employee_time', 'between', [$start_date, $end_date]];
- $where[] = ['employee_id', '=', $param['eid']];
- $ids = Customer::where($where)->column('id');
- // 无效客资来自资源分配
- $i_where[] = ['employee_id', '=', $param['eid']];
- $i_where[] = ['cus_employee_time', 'between', [$start_date, $end_date]];
- $wuxiao_ids = CustomerInvalidLog::where($i_where)->column('customer_id');
- $ids = array_merge($ids, $wuxiao_ids);
- $where1[] = ['id', 'in', $ids];
- $where1[] = ['crm_res_id', '>', 0];
- $where2[] = ['customer_id', 'in', $ids];
- $where2[] = ['crm_res_id', '>', 0];
- $data = $this->selCustomerValid($where1, $where2, $page, $limit, []);
- $list = $data['list'];
- $count = $data['count'];
- } elseif ($param['type'] == 'reported_quantity') {
- // 报备客户数
- $where[] = ['crm_res_id', 'null', null];
- $where[] = ['addtime', 'between', [$start_date, $end_date]];
- $where[] = ['employee_id', '=', $param['eid']];
- $where[] = ['state', 'not null', null];
- $count = Customer::where($where)->count();
- $list = Customer::where($where)->field('name,phone')->page($page, $limit)->select()->toArray();
- /* $ids = Customer::where($where)->column('id');
- // 无效客资
- $i_where[] = ['employee_id', '=', $param['eid']];
- $i_where[] = ['cus_addtime', 'between', [$start_date, $end_date]];
- $i_where[] = ['is_resource', '=', 0];
- $wuxiao_ids = CustomerInvalidLog::where($i_where)->column('customer_id');
- $ids = array_merge($ids, $wuxiao_ids);
-
- $where1[] = ['id', 'in', $ids];
- $where1[] = ['crm_res_id', 'null', null];
- $where2[] = ['customer_id', 'in', $ids];
- $where2[] = ['crm_res_id', 'null', null];
- $data = $this->selCustomerValid($where1, $where2, $page, $limit, []);
-
- $list = $data['list'];
- $count = $data['count']; */
- } elseif ($param['type'] == 'foolow') { //在跟进
- //客户总数
- $vis_where[] = ['Customer.employee_id', '=', $param['eid']];
- $vis_where[] = ['Customer.died', '<>', 2];
- $vis_where[] = ['CustomerVisitLog.confirm_date', 'between', [$start_date, $end_date]];
- $ids = Db::view('CustomerVisitLog', 'customer_id')
- ->view('Customer', [], 'CustomerVisitLog.customer_id=Customer.id')
- ->where($vis_where)
- ->where(function ($query) {
- $or1[] = ['Customer.crm_res_id', 'NULL', null];
- $or1[] = ['Customer.state', 'not in', Customer::changeState('无效', 'chaos')];
- $or2[] = ['Customer.crm_res_id', 'NOT NULL', null];
- $or2[] = ['Customer.state', 'not in', array_merge(Customer::changeState('待确认', 'chaos'), Customer::changeState('无效', 'chaos'))];
- $query->whereOr([$or1, $or2]);
- })
- ->group('CustomerVisitLog.customer_id')
- ->column('CustomerVisitLog.customer_id');
- $where[] = ['id', 'in', $ids];
- $count = Customer::where($where)->count();
- $list = Customer::where($where)->field('id,name,phone')->page($page, $limit)->select()->toArray();
- } elseif (in_array($param['type'], ['dep', 'sign_count', 'room'])) {
- //量房,到店,签单,转单客户数
- $all_state_type = ['room' => '已量房', 'dep' => '已交定', 'sign_count' => '已签单', 'invalid_customer_count' => '无效'];
- if (empty($all_state_type[$param['type']])) return json(['code' => 1, 'data' => '', 'count' => 0, 'msg' => '参数错误']);
- $db_where[] = ['CustomerVisitLog.confirm_date', 'between', [$start_date, $end_date]];
- switch ($param['type']) {
- case 'room':
- $state = CustomerVisitLog::changeState('已量房', 'chaos');
- break;
- case 'dep':
- $state = CustomerVisitLog::changeState('已交定', 'chaos');
- break;
- case 'sign_count':
- $state = CustomerVisitLog::changeState('已签单', 'chaos');
- break;
- break;
- default:
- $state = '';
- break;
- }
- if ($state) {
- $db_where[] = ['CustomerVisitLog.state', 'in', $state];
- }
- $db_where[] = ['Customer.employee_id', '=', $param['eid']];
- $db_where[] = ['CustomerVisitLog.is_merge', '=', 0];
- $cids = Db::view('Customer', 'id')
- ->view('CustomerVisitLog', [], 'Customer.id=CustomerVisitLog.customer_id')
- ->where($db_where)
- ->group('Customer.id')
- ->column('Customer.id');
- $count = Customer::where([['id', 'in', $cids]])->count();
- $list = Customer::where([['id', 'in', $cids]])->field('name,phone')->page($page, $limit)->select()->toArray();
- } elseif ($param['type'] == 'valid') {
- //有效客户数量
- $state1 = Customer::changeState('待确认', 'chaos');
- $state2 = Customer::changeState('无效', 'chaos');
- $vis_where[] = ['Customer.employee_id', '=', $param['eid']];
- $vis_where[] = ['Customer.state', 'not in', array_merge($state1, $state2)];
- $vis_where[] = ['Customer.died', '<>', 2];
- $vis_where[] = ['CustomerVisitLog.confirm_date', 'between', [$start_date, $end_date]];
- $ids = Db::view('CustomerVisitLog', 'customer_id')
- ->view('Customer', [], 'CustomerVisitLog.customer_id=Customer.id')
- ->where($vis_where)
- ->group('CustomerVisitLog.customer_id')
- ->column('CustomerVisitLog.customer_id');
- //2023-03-18 3.3客户标记无效后不能影响数据统计内的有效数据、线索数据 https://kdocs.cn/l/cfx92KlU838H
- $no_where[] = ['employee_id', '=', $param['eid']];
- $no_where[] = ['state', 'in', CustomerVisitLog::changeState('无效', 'chaos')];
- $no_where[] = ['addtime', 'between', [$start_date, $end_date]];
- $no_valid_customer = CustomerVisitLog::where($no_where)->group('customer_id')->column('customer_id');
- $ids = array_unique(array_merge($ids, $no_valid_customer));
- $where1[] = ['id', 'in', $ids];
- $where2[] = ['customer_id', 'in', $ids];
- $data = $this->selCustomerValid($where1, $where2, $page, $limit, []);
- $list = $data['list'];
- $count = $data['count'];
- } elseif ($param['type'] == 'valid_no_wechat') {
- //有效客户数量
- $state1 = Customer::changeState('待确认', 'chaos');
- $state2 = Customer::changeState('无效', 'chaos');
- $vis_where[] = ['Customer.employee_id', '=', $param['eid']];
- $vis_where[] = ['Customer.state', 'not in', array_merge($state1, $state2)];
- $vis_where[] = ['Customer.died', '<>', 2];
- $vis_where[] = ['CustomerVisitLog.confirm_date', 'between', [$start_date, $end_date]];
- $list = Db::view('CustomerVisitLog', 'customer_id')
- ->view('Customer', [], 'CustomerVisitLog.customer_id=Customer.id')
- ->where($vis_where)
- ->group('Customer.id')
- ->column('Customer.id,Customer.ext');
- $cid = [];
- foreach ($list as $k => $v) {
- if ($v['ext']) {
- $json = json_decode($v['ext'], true);
- $i = 0;
- foreach ($json as $v2) {
- if (!isset($v2['keyname'])) continue;
- if ($v2['keyname'] == 'add_wechat_time' && !empty($v2['value'])) {
- $i++;
- continue;
- }
- }
- if ($i == 0) $cid[] = $v['id'];
- } else {
- $cid[] = $v['id'];
- }
- }
- $count = Customer::where([['id', 'in', $cid]])->count();
- $list = Customer::where([['id', 'in', $cid]])->field('name,phone')->page($page, $limit)->select()->toArray();
- } elseif ($param['type'] == 'room_no_store') {
- //量房未到店
- $state3 = CustomerVisitLog::changeState('已量房', 'chaos');
- $state4 = CustomerVisitLog::changeState('已到店', 'chaos');
- $db_where[] = ['CustomerVisitLog.confirm_date', 'between', [$start_date, $end_date]];
- $db_where[] = ['Customer.employee_id', '=', $param['eid']];
- $db_where[] = ['CustomerVisitLog.is_merge', '=', 0];
- $db_where1 = $db_where;
- $db_where1[] = ['CustomerVisitLog.state', 'in', $state3];
- $cids1 = Db::view('Customer')
- ->view('CustomerVisitLog', '', 'Customer.id=CustomerVisitLog.customer_id')
- ->where($db_where1)
- ->group('Customer.id')
- ->column('Customer.id');
- $db_where2 = $db_where;
- $db_where2[] = ['CustomerVisitLog.state', 'in', $state4];
- $cids2 = Db::view('Customer')
- ->view('CustomerVisitLog', '', 'Customer.id=CustomerVisitLog.customer_id')
- ->where($db_where2)
- ->group('Customer.id')
- ->column('Customer.id');
- $cids = array_diff($cids1, $cids2);
- $count = Customer::where([['id', 'in', $cids]])->count();
- $list = Customer::where([['id', 'in', $cids]])->field('name,phone')->page($page, $limit)->select()->toArray();
- } elseif ($param['type'] == 'yuji_store') {
- //预计到店
- $sub_where[] = ['CustomersSubscribe.employee_id', '=', $param['eid']];
- $sub_where[] = ['CustomersSubscribe.type', '=', 1];
- $sub_where[] = ['CustomersSubscribe.state', '=', 0];
- $sub_where[] = ['CustomersSubscribe.addtime', 'between', [$start_date, $end_date]];
- $count = Db::view('CustomersSubscribe')
- ->view('Customer', 'id', 'CustomersSubscribe.customer_id=Customer.id')
- ->where($sub_where)->count();
- $list = Db::view('CustomersSubscribe')
- ->view('Customer', 'id', 'CustomersSubscribe.customer_id=Customer.id')
- ->where($sub_where)
- ->page($page, $limit)
- ->column('CustomersSubscribe.customer_id,CustomersSubscribe.subscribe_date date,customer.name');
- } elseif (in_array($param['type'], ['strtore_count_0', 'strtore_count_1', 'strtore_count_2'])) {
- $arr = ['strtore_count_0' => 'count(CustomerVisitLog.id)=1', 'strtore_count_1' => 'count(CustomerVisitLog.id)=2', 'strtore_count_2' => 'count(CustomerVisitLog.id)>=3'];
- $state3 = CustomerVisitLog::changeState('已到店', 'chaos');
- $vis_where[] = ['Customer.employee_id', '=', $param['eid']];
- $vis_where[] = ['CustomerVisitLog.confirm_date', 'between', [$start_date, $end_date]];
- $vis_where[] = ['CustomerVisitLog.state', 'in', $state3];
- $vislog_list = Db::view('CustomerVisitLog', 'customer_id')
- ->view('Customer', [], 'CustomerVisitLog.customer_id=Customer.id')
- ->where($vis_where)
- ->where([['CustomerVisitLog.is_merge', '=', 0]])
- ->group('CustomerVisitLog.customer_id')
- ->having($arr[$param['type']])
- ->column('CustomerVisitLog.customer_id');
- $where[] = ['id', 'in', $vislog_list];
- $count = Customer::where($where)->count();
- $list = Customer::where($where)->field('name,phone')->page($page, $limit)->select()->toArray();
- } elseif (in_array($param['type'], ['strtore_deposit_count_0', 'strtore_deposit_count_1', 'strtore_deposit_count_2'])) {
- //到店签单
- $arr = ['strtore_deposit_count_0' => 'count(CustomerVisitLog.id)=1', 'strtore_deposit_count_1' => 'count(CustomerVisitLog.id)=2', 'strtore_deposit_count_2' => 'count(CustomerVisitLog.id)>=3'];
- $state3 = CustomerVisitLog::changeState('已到店', 'chaos');
- $vis_where1[] = ['Customer.employee_id', '=', $param['eid']];
- $vis_where1[] = ['CustomerVisitLog.confirm_date', 'between', [$start_date, $end_date]];
- $vis_where1[] = ['CustomerVisitLog.state', 'in', $state3];
- $customer_ids = Db::view('CustomerVisitLog', 'customer_id')
- ->view('Customer', [], 'CustomerVisitLog.customer_id=Customer.id')
- ->where($vis_where1)
- ->where([['CustomerVisitLog.is_merge', '=', 0]])
- ->group('CustomerVisitLog.customer_id')
- ->having($arr[$param['type']])
- ->column('CustomerVisitLog.customer_id');
- $state2 = CustomerVisitLog::changeState('已交定', 'chaos');
- $vis_where2[] = ['Customer.employee_id', '=', $param['eid']];
- $vis_where2[] = ['CustomerVisitLog.confirm_date', 'between', [$start_date, $end_date]];
- $vis_where2[] = ['CustomerVisitLog.state', 'in', $state2];
- $customer_ids_ding = Db::view('CustomerVisitLog', 'customer_id')
- ->view('Customer', [], 'CustomerVisitLog.customer_id=Customer.id')
- ->where($vis_where2)
- ->where([['CustomerVisitLog.is_merge', '=', 0]])
- ->group('CustomerVisitLog.customer_id')
- ->column('CustomerVisitLog.customer_id');
- $where[] = ['id', 'in', array_intersect($customer_ids, $customer_ids_ding)];
- $count = Customer::where($where)->count();
- $list = Customer::where($where)->field('name,phone')->page($page, $limit)->select()->toArray();
- } elseif (in_array($param['type'], ['square_0_80', 'square_80_100', 'square_100_120', 'square_120_200', 'square_200_500', 'square_500'])) {
- $arr = [
- 'square_0_80' => [0, 80],
- 'square_80_100' => [80, 100],
- 'square_100_120' => [101, 120],
- 'square_120_200' => [121, 200],
- 'square_200_500' => [201, 500],
- 'square_500' => [501, 999999],
- ];
- $vis_where[] = ['Customer.employee_id', '=', $param['eid']];
- $vis_where[] = ['Customer.died', '<>', 2];
- $vis_where[] = ['CustomerVisitLog.confirm_date', 'between', [$start_date, $end_date]];
- $square = Db::view('CustomerVisitLog', 'customer_id')
- ->view('Customer', [], 'CustomerVisitLog.customer_id=Customer.id')
- ->where($vis_where)
- ->where(function ($query) {
- $or1[] = ['Customer.crm_res_id', 'NULL', null];
- $or1[] = ['Customer.state', 'not in', Customer::changeState('无效', 'chaos')];
- $or2[] = ['Customer.crm_res_id', 'NOT NULL', null];
- $or2[] = ['Customer.state', 'not in', array_merge(Customer::changeState('待确认', 'chaos'), Customer::changeState('无效', 'chaos'))];
- $query->whereOr([$or1, $or2]);
- })
- ->group('Customer.id')
- ->column('Customer.id,Customer.square');
- $cid = [];
- foreach ($square as $v) {
- if ($v['square'] && $v['square'] > $arr[$param['type']][0] && $v['square'] <= $arr[$param['type']][1]) $cid[] = $v['id'];
- }
- $where[] = ['id', 'in', $cid];
- $count = Customer::where($where)->count();
- $list = Customer::where($where)->field('name,phone')->page($page, $limit)->select()->toArray();
- } elseif ($param['type'] == 'existing_homes_count' || $param['type'] == 'forward_housing_count') {
- //现房 期房客户
- $field = $param['type'] == 'existing_homes_count' ? '现房' : '期房';
- $vis_where[] = ['Customer.employee_id', '=', $param['eid']];
- $vis_where[] = ['Customer.died', '<>', 2];
- $vis_where[] = ['CustomerVisitLog.confirm_date', 'between', [$start_date, $end_date]];
- $vis_where[] = ['Customer.house_type', 'like', '%' . $field . '%'];
- $vis_where[] = ['state', 'not in', array_merge(Customer::changeState('待确认', 'chaos'), Customer::changeState('无效', 'chaos'))];
- $ids = Db::view('CustomerVisitLog', 'customer_id')
- ->view('Customer', [], 'CustomerVisitLog.customer_id=Customer.id')
- ->where($vis_where)
- ->group('Customer.id')
- ->column('Customer.id');
- $where[] = ['id', 'in', $ids];
- $model = Customer::where($where)->field('name,phone');
- $count = $model->count();
- $list = $model->page($page, $limit)->select()->toArray();
- } elseif ($param['type'] == 'number_of_explanations') {
- $db_where[] = ['CustomerVisitLog.remark', 'like', '%讲解智慧屏##%'];
- $db_where[] = ['CustomerVisitLog.addtime', 'between', [$start_date, $end_date]];
- $db_where[] = ['Customer.employee_id', '=', $param['eid']];
- $db_where[] = ['CustomerVisitLog.is_merge', '=', 0];
- $model = Db::view('Customer', ['name', 'phone'])
- ->view('CustomerVisitLog', 'customer_id,addtime', 'Customer.id=CustomerVisitLog.customer_id')
- ->where($db_where);
- $count = $model->count();
- $list = $model->page($page, $limit)->select()->toArray();
- $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
- foreach ($list as $k => $v) {
- $list[$k]['phone'] = $aec->decrypt($v['phone']);
- }
- } elseif ($param['type'] == 'invalid') {
- $key = input('key', '');
- if ($key === '') {
- return json(['code' => 0, 'data' => [], 'count' => [], 'msg' => '获取成功']);
- }
- $setting = Setting::where([['root_id', '=', $root_id], ['name', '=', 'clueTag']])->value('content');
- if (empty($setting)) return json(['code' => 0, 'data' => [], 'count' => [], 'msg' => '获取成功']);
- $setting = explode(',', $setting)[$key];
- $where[] = ['employee_id', '=', $param['eid']];
- $where[] = ['confirm_date', 'between', [$start_date, $end_date]];
- $where[] = ['state', 'in', CustomerVisitLog::changeState('无效', 'chaos')];
- $where[] = ['remark', 'like', '%' . $setting . '%'];
- $customer_ids = CustomerVisitLog::where($where)->group('customer_id')->column('customer_id');
- $count = Customer::where([['id', 'in', $customer_ids]])->count();
- $list = Customer::where([['id', 'in', $customer_ids]])->field('name,phone')->page($page, $limit)->select()->toArray();
- }
- if ($param['type'] == 'share') {
- foreach ($list as $k => $v) {
- $type = isset($arr[$v['type']]) ? $arr[$v['type']] : '';
- $field = $v['type'] == 'Building' ? 'name' : 'title';
- if ($v['content'] && isset($v['content'][$field])) {
- $list[$k]['title'] = $type . '《' . $v['content'][$field] . '》';
- } else {
- $list[$k]['title'] = '暂无';
- }
- }
- } elseif ($param['type'] == 'yuji_store') {
- /* foreach ($list as $k => $v) {
- $list[$k]['name'] = isset($customer_ids[$v['customer_id']]) ? $customer_ids[$v['customer_id']] : '未知';
- } */
- } else {
- foreach ($list as $k => $v) {
- $list[$k]['phone'] = substr_replace($v['phone'], '******', 3, 6);
- $list[$k]['name'] = empty($v['name']) ? '未知' : $v['name'];
- }
- }
- return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
- }
- /**
- * 有效客户联查(包含回收站)
- */
- public function selCustomerValid($condition, $con_union, $page, $limit, $order)
- {
- $prefix = env('database.prefix');
- $model = Db::table($prefix . 'customer')
- ->field('id,designer_id,employee_id,name,community_name,phone,state,addtime,phone1,phone2,remark,ext,deposit_money,signed_money,org_id')
- ->where($condition)
- ->union(function ($query) use ($con_union) {
- $prefix = env('database.prefix');
- $query->field('customer_id id,designer_id,employee_id,name,community_name,phone,state,addtime,phone1,phone2,remark,ext,deposit_money,signed_money,org_id')->where($con_union)->table($prefix . 'customer_recycle');
- });
- $count = count($model->select()->toArray());
- $list = $model->page($page, $limit)->order($order)->select()->toArray();
- $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
- foreach ($list as $k => $v) {
- $list[$k]['state'] = Customer::changeState($v['state'], 'state');
- $phone = $aec->decrypt($v['phone']);
- $phone1 = !empty($v['phone1']) ? $aec->decrypt($v['phone1']) : '';
- $phone2 = !empty($v['phone2']) ? $aec->decrypt($v['phone2']) : '';
- $list[$k]['phone'] = substr_replace($phone, '******', 3, 6);
- $list[$k]['phone1'] = $phone1 ? substr_replace($phone1, '******', 3, 6) : '';
- $list[$k]['phone2'] = $phone2 ? substr_replace($phone2, '******', 3, 6) : '';
- $employee = Employee::find($v['employee_id']);
- $list[$k]['employee_name'] = '';
- if (!empty($employee)) {
- $list[$k]['employee_name'] = $employee['name'];
- }
- $designer = Employee::find($v['designer_id']);
- $list[$k]['designer_name'] = '';
- if (!empty($designer)) {
- $list[$k]['designer_name'] = $designer['name'];
- }
- $list[$k]['org_name'] = '';
- if ($v['org_id']) {
- $org = Org::where('id', '=', $v['org_id'])->find();
- if (!empty($org)) {
- $list[$k]['org_name'] = $org['name'];
- }
- }
- }
- $data = ['count' => $count, 'list' => $list];
- return $data;
- }
- /**
- * 房屋状态
- */
- private function getHouseStatus($house_status, $field)
- {
- $data = [];
- $name = array_column($field, 'name');
- $house = [];
- foreach ($house_status as $v) {
- @$house[$v] += 1;
- }
- foreach ($field as $k2 => $v2) {
- $data['house_status_' . $v2['id']] = isset($house[$v2['name']]) ? $house[$v2['name']] : 0;
- }
- return $data;
- }
- /**
- * 房屋户型
- */
- private function getHousetypeArrow($housetype, $field, $sign_ids)
- {
- $data = [];
- $house = [];
- foreach ($housetype as $k => $v) {
- @$house[$v][] = $k; // $v 是户型id,$k是客户id
- }
- // 每个户型的成交率
- foreach ($field as $k => $v) {
- $v_customer = $house[$v['id']] ?? [];
- $v_sign = array_intersect($v_customer, $sign_ids);
- $data['housetype_arrow_lv_' . $v['id']] = count($v_customer) > 0 ? round(count($v_sign) / count($v_customer) * 100, 2) . '%' : '0%';
- }
- // 每个户型的客户数
- foreach ($field as $k => $v) {
- $data['housetype_arrow_' . $v['id']] = isset($house[$v['id']]) ? count($house[$v['id']]) : 0;
- }
- return $data;
- }
- /**
- * 加微数量
- * $wechat 业务员的客户数组
- * $sdate 开始时间筛选
- * $edate 结束时间筛选
- * $measuring_room_time 客户量房时间 计算平均量房时间
- * $to_the_store_time 客户到店时间 计算平均到店时间
- * $deposit_customer 客户交定时间 计算平均交定周期
- */
- private function getWechatCount($wechat, $sdate, $edate, $measuring_room_time, $to_the_store_time, $deposit_customer)
- {
- $time = time();
- $data['wechat_count'] = []; //加微客户id
- $data['is_resource'] = []; //资源库分配客户id
- $data['drawing_date'] = []; //有户型图的客户
- $row['room_cycle_0'] = $row['room_cycle_1'] = $row['room_cycle_2'] = []; //一次 二次 三次量房周期
- $row['strtore_0'] = $row['strtore_1'] = $row['strtore_2'] = []; //一次 二次 三次到店周期
- $row['deposit_0'] = $row['deposit_1'] = $row['deposit_2'] = []; //一次 二次 三次交定周期
- $data['room_cycle_customer_0'] = $data['room_cycle_customer_1'] = $data['room_cycle_customer_2'] = []; //一次 两次 三次量房客户
- $data['strtore_customer_0'] = $data['strtore_customer_1'] = $data['strtore_customer_2'] = []; //一次 两次 三次到店客户
- $data['deposit_customer_0'] = $data['deposit_customer_1'] = $data['deposit_customer_2'] = []; //一次 两次 三次交定客户
- $row['signed_money'] = []; //合同金额
- $house_type = []; //房屋类型
- $square = []; //房屋面积
- $data['house_status'] = []; //房屋状态
- //报备客户
- $data['reported_quantity'] = 0;
- //死单客户
- $data['dead_order'] = 0;
- foreach ($wechat as $v) {
- //客户添加时间
- $addtime = strtotime($v['addtime']);
- //资源库分配数量
- if ($v['crm_res_id']) $data['is_resource'][] = $v['id'];
- $row['signed_money'][] = $v['signed_money']; //合同金额
- $house_type[] = $v['house_type'];
- $square[] = $v['square'];
- $data['house_status'][] = $v['house_status'];
- //加微客户,有户型图客户
- $v2 = $v['ext'];
- $ext = json_decode($v2, true);
- if (!empty($ext) && is_array($ext)) {
- $ext = array_filter($ext);
- foreach ($ext as $e) {
- if (isset($e['keyname']) && $e['keyname'] == 'add_wechat_time' && !empty($e['value']) && strtotime($e['value']) >= $sdate && strtotime($e['value']) <= $edate) {
- $data['wechat_count'][] = $v['id'];
- } elseif (isset($e['keyname']) && $e['keyname'] == 'drawing_date' && !empty($e['value']) && strtotime($e['value']) <= $time) {
- $data['drawing_date'][] = $v['id'];
- }
- }
- }
- //一次 二次 三次量房周期
- if (isset($measuring_room_time[$v['id']])) {
- $count = count($measuring_room_time[$v['id']]);
- $start = $count >= 3 ? 2 : $count - 1;
- $measuring_room_cycle = [];
- $measuring_room_cycle[$start] = $measuring_room_time[$v['id']][$start];
- // $measuring_room_cycle = array_slice($measuring_room_time[$v['id']],0, 3);
- foreach ($measuring_room_cycle as $cycle_key => $cycle_item) {
- $cycle_addtime = strtotime($cycle_item);
- if ($addtime < $cycle_addtime) $row['room_cycle_' . $cycle_key][] = $cycle_addtime - $addtime;
- $data['room_cycle_customer_' . $cycle_key][] = $v['id'];
- }
- }
- //一次 二次 三次到店周期
- if (isset($to_the_store_time[$v['id']])) {
- $count = count($to_the_store_time[$v['id']]);
- $start = $count >= 3 ? 2 : $count - 1;
- $to_the_store_times = [];
- $to_the_store_times[$start] = $to_the_store_time[$v['id']][$start];
- // $to_the_store_times = array_slice($to_the_store_time[$v['id']],0, 3);
- foreach ($to_the_store_times as $store_key => $store_item) {
- $store_addtime = strtotime($store_item);
- if ($addtime < $store_addtime) $row['strtore_' . $store_key][] = $store_addtime - $addtime;
- $data['strtore_customer_' . $store_key][] = $v['id'];
- }
- }
- //一次 二次 三次交定周期
- if (isset($deposit_customer[$v['id']])) {
- $count = count($deposit_customer[$v['id']]);
- $start = $count >= 3 ? 2 : $count - 1;
- $deposit_customer_time = [];
- $deposit_customer_time[$start] = $deposit_customer[$v['id']][$start];
- // $deposit_customer_time = array_slice($deposit_customer[$v['id']],0, 3);
- foreach ($deposit_customer_time as $deposit_key => $deposit_item) {
- $deposit_addtime = strtotime($deposit_item);
- if ($addtime < $deposit_item) $row['deposit_' . $deposit_key][] = $deposit_addtime - $addtime;
- $data['deposit_customer_' . $deposit_key][] = $v['id'];
- }
- }
- //报备客户
- // if () {
- // # code...
- // }
- //死单
- if ($v['dead_order'] == 2) $data['dead_order'] += 1;
- }
- foreach ([0, 1, 2] as $range) {
- //平均一次,二次,三次量房周期
- $data['room_cycle_' . $range] = $row['room_cycle_' . $range] ? ceil(array_sum($row['room_cycle_' . $range]) / count($row['room_cycle_' . $range])) : 0;
- //一次,二次,三次 量房人数
- $data['room_cycle_count_' . $range] = count($row['room_cycle_' . $range]);
- //平均到店周期
- $data['strtore_' . $range] = $row['strtore_' . $range] ? ceil(array_sum($row['strtore_' . $range]) / count($row['strtore_' . $range])) : 0;
- //一次 二次 三次 到店人数
- $data['strtore_count_' . $range] = count($row['strtore_' . $range]);
- //平均交定周期
- $data['deposit_' . $range] = $row['deposit_' . $range] ? ceil(array_sum($row['deposit_' . $range]) / count($row['deposit_' . $range])) : 0;
- //一次 二次 三次 交定人数
- $data['deposit_count_' . $range] = count($row['deposit_' . $range]);
- }
- //平均合同金额
- $signed_money = array_filter($row['signed_money']);
- $data['signed_money'] = empty($signed_money) ? 0 : round(array_sum($signed_money) / count($signed_money), 2);
- //房屋类型
- $data['existing_homes_count'] = 0; //现房数量
- $data['forward_housing_count'] = 0; //期房数量
- foreach ($house_type as $house_type_item) {
- if (strpos($house_type_item, '现房') !== false) {
- $data['existing_homes_count'] += 1;
- } elseif (strpos($house_type_item, '期房') !== false) {
- $data['forward_housing_count'] += 1;
- }
- }
- //房屋面积
- $data['square_0_80'] = $data['square_80_100'] = $data['square_100_120'] = $data['square_120_200'] = $data['square_200_500'] = $data['square_500'] = 0;
- foreach ($square as $square_item) {
- if (!$square_item) continue;
- if ($square_item <= 80) {
- $data['square_0_80'] += 1;
- } elseif ($square_item <= 100) {
- $data['square_80_100'] += 1;
- } elseif ($square_item <= 120) {
- $data['square_100_120'] += 1;
- } elseif ($square_item <= 200) {
- $data['square_120_200'] += 1;
- } elseif ($square_item <= 500) {
- $data['square_200_500'] += 1;
- } else {
- $data['square_500'] += 1;
- }
- }
- return $data;
- }
- /**
- * 行为统计页面
- */
- public function behaviorStatistics()
- {
- //返回组织列表
- $org = Org::where([['path', 'like', $this->root_id . '-%']])->select()->toArray();
- View::assign('org', $org);
- return View::fetch();
- }
- /**
- * 行为统计接口
- * 日期截止到 2022011-20
- */
- public function behaviorStatisticsData($page = 1, $limit = 10)
- {
- $param = Request::only(['page' => 1, 'start_date' => '', 'end_date' => '', 'keyword' => '', 'org_id' => '']);
- $root_id = request()->employee->root_id;
- if ($param['start_date']) {
- $count_dates = explode(' - ', $param['start_date']);
- $start_date = strtotime($count_dates[0]);
- $end_date = strtotime($count_dates[1]);
- } else {
- $start_date = strtotime('2022-11-20');
- $end_date = strtotime(date('Y-m-d'));
- }
- //登录记录
- $login_where = [
- ['root_id', '=', $root_id],
- ['content', '=', '小程序登录'],
- ['addtime', 'between', [date('Y-m-d H:i:s', $start_date), date('Y-m-d H:i:s', $end_date + 86399)]]
- ];
- $login = OperateLog::where($login_where)->field("concat(employee_id,'@',DATE_FORMAT(addtime,'%Y-%m-%d')) as indexx")->group('indexx')->select()->toArray();
- $login = array_column($login, 'indexx');
- if ($param['keyword']) {
- $where[] = ['name', 'like', '%' . $param['keyword'] . '%'];
- }
- $where[] = ['root_id', '=', $root_id];
- $where[] = ['uid', '>', 0];
- $where[] = ['state', 'in', ['在职', '离职']];
- if (!empty($param['org_id'])) {
- //部门筛选
- $org = Org::where([['id', '=', $param['org_id']]], ['path', 'like', $this->root_id . '-%'])->find();
- $orgIds = Org::where([['path', 'like', $org['path'] . '%']])->column('id');
- $where[] = ['org_id', 'in', $orgIds];
- }
- $employees = Employee::where($where)->column('id,name,org_id,addtime,state,termination_time');
- $day = ($end_date - $start_date) / 86400;
- $list = [];
- for ($i = 0; $i <= $day; $i++) {
- $date = date('Y-m-d', $end_date - $i * 86400);
- $time = strtotime($date) + 86399;
- foreach ($employees as $k => $v) {
- $addtime = strtotime($v['addtime']);
- $now_date = date('Y-m-d', strtotime($date));
- $indexx = $v['id'] . '@' . $now_date;
- $termination_time = strtotime(date('Y-m-d 23:59:59', strtotime($v['termination_time'])));
- // if ($time >= $addtime && in_array($indexx,$login)) {
- $status_state = $v['state'] == '离职' ? ($termination_time >= $time ? true : false) : true;
- if ($time >= $addtime && $status_state) {
- $j = $v;
- $j['x_date'] = date('Y年m月d日', strtotime($date));
- $j['date'] = $now_date;
- $j['index'] = $indexx;
- $list[] = $j;
- }
- }
- }
- $count = count($list);
- $list = array_slice($list, $limit * ($page - 1), $limit);
- // $dates = array_unique(array_column($list,'date'));
- $eids = array_unique(array_column($list, 'id'));
- $query1 = ['employee_id', 'in', $eids];
- $query2 = ['share_time', 'between', [date('Y-m-d H:i:s', $start_date), date('Y-m-d H:i:s', $end_date + 86399)]];
- $query3 = ['addtime', 'between', [date('Y-m-d H:i:s', $start_date), date('Y-m-d H:i:s', $end_date + 86399)]];
- $custoemr_where = [
- ['employee_id', 'in', $eids]
- ];
- $customer = Customer::where($custoemr_where)->column('id,ext,employee_id,house_delivery_time');
- //加微客户 预计转施工时间
- $add_wechat_date = [];
- $house_delivery_time = [];
- foreach ($customer as $v1) {
- $v2 = $v1['ext'];
- $ext = json_decode($v2, true);
- if (!empty($ext) && is_array($ext)) {
- $ext = array_filter($ext);
- foreach ($ext as $e) {
- if (isset($e['keyname']) && $e['keyname'] == 'add_wechat_time' && !empty($e['value'])) {
- @$add_wechat_date[$v1['employee_id'] . '@' . date('Y-m-d', strtotime($e['value']))] += 1;
- } elseif (isset($e['keyname']) && $e['keyname'] == 'will_transfer_to_construction_date' && !empty($e['value'])) {
- @$house_delivery_time[$v1['employee_id'] . '@' . date('Y-m-d', strtotime($e['value']))] += 1;
- }
- }
- }
- }
- //调用内容数量,分享内容次数
- $share_where = ['CompanyStrength', 'Article', 'Construction', 'Activity', 'MaterialEvidence', 'Video', 'MaterialCase', 'Building'];
- $share = ShareLog::where([$query1, $query2, ['type', 'in', $share_where]])->field("id,concat(employee_id,'@',DATE_FORMAT(share_time,'%Y-%m-%d')) as indexx,concat(employee_id,type,data_id,DATE_FORMAT(share_time,'%Y-%m-%d')) as str,employee_id")->select()->toArray();
- $shares = [];
- foreach ($share as $share_v) {
- @$shares[$share_v['indexx']] += 1;
- }
- ///培训资料是否看了 课程是否学习过
- $look = TrainCourseView::where([$query1, $query3, ['time', '>', 0]])->column("concat(employee_id,'@',DATE_FORMAT(addtime,'%Y-%m-%d')) as indexx");
- $look = array_unique(array_column($look, 'indexx'));
- //考核次数 通过次数
- $don = ExamEmpResult::with(['paperInfo' => function ($query) {
- $query->field('id,base_score')->bind(['base_score' => 'base_score']);
- }])->where([$query1, $query3, ['state', '=', 1]])->field("id,paper_id,final_score,concat(employee_id,'@',DATE_FORMAT(addtime,'%Y-%m-%d')) as indexx")->select()->toArray();
- $don1 = $don2 = []; //是否有考核,考核是否通过
- foreach ($don as $vv) {
- @$don1[$vv['indexx']] += 1; //考核次数
- if ($vv['final_score'] >= $vv['base_score']) @$don2[$vv['indexx']] += 1; //考核通过次数
- }
- //客户跟进数量
- $vislog = CustomerVisitLog::where([
- ['employee_id|customer_employee_id', 'in', $eids], $query3
- ])->column("state,IF(employee_id,employee_id,customer_employee_id) as employee,DATE_FORMAT(addtime,'%Y-%m-%d') as date,customer_id,concat(IF(employee_id,employee_id,customer_employee_id),'@',DATE_FORMAT(addtime,'%Y-%m-%d')) as indexx");
- $log1 = $log2 = []; //跟进次数 , 跟进客户数
- $state1 = CustomerVisitLog::changeState('已量房', 'chaos');
- $state2 = CustomerVisitLog::changeState('已到店', 'chaos');
- $state3 = CustomerVisitLog::changeState('已交定', 'chaos');
- $state4 = CustomerVisitLog::changeState('已签单', 'chaos');
- $state_count1 = $state_count2 = $state_count3 = $state_count4 = [];
- foreach ($vislog as $ke => $va) {
- @$log1[$va['indexx']] += 1;
- @$log2[$va['indexx']][] = $va['customer_id'];
- if (in_array($va['state'], $state1)) {
- @$state_count1[$va['indexx']][] = $va['customer_id'];
- } elseif (in_array($va['state'], $state2)) {
- @$state_count2[$va['indexx']][] = $va['customer_id'];
- } elseif (in_array($va['state'], $state3)) {
- @$state_count3[$va['indexx']][] = $va['customer_id'];
- } elseif (in_array($va['state'], $state4)) {
- @$state_count4[$va['indexx']][] = $va['customer_id'];
- }
- }
- //预约记录
- $query4 = [
- ['state', '=', 0],
- ['type', 'in', [1, 3]],
- ['employee_id', 'in', $eids],
- ['subscribe_date', 'between', [date('Y-m-d H:i:s', $start_date), date('Y-m-d H:i:s', $end_date + 86399)]]
- ];
- $sub1 = $sub2 = []; //1到店 2量房
- $subscribe = CustomersSubscribe::where($query4)->column("employee_id,customer_id,subscribe_date,type,concat(employee_id,'@',DATE_FORMAT(subscribe_date,'%Y-%m-%d')) as indexx");
- foreach ($subscribe as $v4) {
- $v4['type'] == 1 ? @$sub1[$v4['indexx']] += 1 : @$sub2[$v4['indexx']] += 1;
- }
- //话术浏览次数
- $talk_view = TalkskillViewLog::where([$query1, $query3])->column("concat(employee_id,'@',DATE_FORMAT(addtime,'%Y-%m-%d')) as indexx");
- $talk_count = [];
- foreach ($talk_view as $t_item) {
- @$talk_count[$t_item['indexx']] += 1;
- }
- //智慧屏讲解次数
- $zhihuis = CustomerVisitLog::where([['employee_id|customer_employee_id', 'in', $eids], $query3, ['remark', 'like', '%讲解智慧屏##%']])
- ->field("IF(employee_id,employee_id,customer_employee_id) as employee,DATE_FORMAT(addtime,'%Y-%m-%d') as date,customer_id,concat(IF(employee_id,employee_id,customer_employee_id),'@',DATE_FORMAT(addtime,'%Y-%m-%d')) as indexx")->select()->toArray();
- $zhihui = [];
- foreach ($zhihuis as $v) {
- @$zhihui[$v['indexx']] += 1;
- }
- // 外呼系统统计
- $outCallLog = OutCallLog::where([['employee_id', 'in', $eids]])->field("count(id) as phone_count, sum(if(`status`>0,1,0)) as on_phone_count, sum(if(`status`<0,1,0)) as off_phone_count,sum(billsec) as phone_time,concat(employee_id,'@',DATE_FORMAT(addtime,'%Y-%m-%d')) as indexx")->group('indexx')->select()->toArray();
- $outCallLog = array_combine(array_column($outCallLog, 'indexx'), $outCallLog);
- // 手机打电话次数获取
- $outCallMbLog = OutCallMbLog::where([
- ['employee_id', 'in', $eids]
- ])->field("count(id) as phone_count,concat(employee_id,'@',DATE_FORMAT(addtime,'%Y-%m-%d')) as indexx")->group('indexx')->select()->toArray();
- $outCallMbLog = array_combine(array_column($outCallMbLog, 'indexx'), $outCallMbLog);
- $org = Org::where([['id', 'in', array_column($list, 'org_id')]])->column('name', 'id');
- foreach ($list as $key => $val) {
- //部门名称
- $list[$key]['org_name'] = isset($org[$val['org_id']]) ? $org[$val['org_id']] : '无';
- //电话量
- $list[$key]['phone_count'] = 0;
- //接通量
- $list[$key]['on_phone_count'] = 0;
- //未接通
- $list[$key]['off_phone_count'] = 0;
- //平均通话时长
- $list[$key]['avg_phone_time'] = 0;
- if (isset($outCallLog[$val['index']])) {
- //电话量
- $list[$key]['phone_count'] = $outCallLog[$val['index']]['phone_count'];
- //接通量
- $list[$key]['on_phone_count'] = $outCallLog[$val['index']]['on_phone_count'];
- //未接通
- $list[$key]['off_phone_count'] = $outCallLog[$val['index']]['off_phone_count'];
- //平均通话时长
- $list[$key]['avg_phone_time'] = $list[$key]['on_phone_count'] == 0 ? 0 : round($outCallLog[$val['index']]['phone_time'] / $list[$key]['on_phone_count'], 2);
- }
- if (isset($outCallMbLog[$val['index']])) {
- $list[$key]['phone_count'] += $outCallMbLog[$val['index']]['phone_count'];
- }
- //加微数量
- $list[$key]['add_wechat_count'] = isset($add_wechat_date[$val['index']]) ? $add_wechat_date[$val['index']] : 0;
- //分享内容数量
- $list[$key]['share_count'] = isset($shares[$val['index']]) ? $shares[$val['index']] : 0;
- //智慧屏讲解次数
- $list[$key]['explain_count'] = isset($zhihui[$val['index']]) ? $zhihui[$val['index']] : 0;
- //话术浏览次数
- $list[$key]['talkskill_view_count'] = isset($talk_count[$val['index']]) ? $talk_count[$val['index']] : 0;
- //培训是否看
- $list[$key]['is_look'] = in_array($val['index'], $look) ? '是' : '否';
- //跟进次数
- $list[$key]['log_count'] = isset($log1[$val['index']]) ? $log1[$val['index']] : 0;
- //跟进客户数量
- $list[$key]['log_customer_count'] = isset($log2[$val['index']]) ? count(array_unique($log2[$val['index']])) : 0;
- //量房客户数
- $list[$key]['measuring_room_customer_count'] = isset($state_count1[$val['index']]) ? count(array_unique($state_count1[$val['index']])) : 0;
- //到店客户数
- $list[$key]['sto_customer_count'] = isset($state_count2[$val['index']]) ? count(array_unique($state_count2[$val['index']])) : 0;
- //交定
- $list[$key]['deposit_customer_count'] = isset($state_count3[$val['index']]) ? count(array_unique($state_count3[$val['index']])) : 0;
- //签单
- $list[$key]['sign_customer_count'] = isset($state_count4[$val['index']]) ? count(array_unique($state_count4[$val['index']])) : 0;
- //预计转施工客户数量
- $list[$key]['house_delivery_count'] = isset($house_delivery_time[$val['index']]) ? $house_delivery_time[$val['index']] : 0;
- //预计到店数
- $list[$key]['subscribe_store_count'] = isset($sub1[$val['index']]) ? $sub1[$val['index']] : 0;
- //预计量房数量
- $list[$key]['subscribe_room_count'] = isset($sub2[$val['index']]) ? $sub2[$val['index']] : 0;
- //是否有考核
- $list[$key]['is_exam'] = isset($don1[$val['index']]) ? '是' : '否';
- //考核是否通过
- $list[$key]['is_exam_ok'] = isset($don2[$val['index']]) ? '是' : '否';
- }
- return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功', 'page' => ceil($count / $limit)]);
- }
- /**
- * 行为统计数据导出
- */
- public function behaviorStatisticsDataExport()
- {
- $root_id = request()->employee->root_id;
- $type = input('type', '');
- if (!request()->isAjax()) {
- $header2 = $header3 = [];
- if ($type == 'high') {
- //高层统计
- $header1 = [
- ["field" => 'x_date', "title" => '时 间', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'name', "title" => '员工姓名', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'org_name', "title" => '所属部门', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'position', "title" => '职位', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'phone_count', "title" => '电话数量', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'on_phone_count', "title" => '接通数量', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'off_phone_count', "title" => '未接通', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'avg_phone_time', "title" => '平均通话时长', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'add_wechat_count', "title" => '加微数量', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'share_count', "title" => '调用内容数量', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'talkskill_view_count', "title" => '浏览话术次数', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'is_look', "title" => '看培训次数', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'look_time', "title" => '看培训时长(S)', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'is_exam', "title" => '考核次数', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'is_exam_ok', "title" => '考核通过次数', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'log_customer_count', "title" => '客户跟进数', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'log_count', "title" => '总回访次数', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'log_time', "title" => '平均回访时长', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'log_time1', "title" => '平均回访周期', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'explain_count', "title" => '智慧屏讲解次数', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'explain_count1', "title" => '每个客户讲解次数', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'measuring_room_customer_count', "title" => '量房客户数', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'store_1', "title" => '一次到店客户数', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'store_1_grawth', "title" => '一次到店率', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'store_2', "title" => '二次到店客户数', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'store_2_grawth', "title" => '二次到店率', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'store_3', "title" => '三次及以上到店客户数', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'store_3_grawth', "title" => '三次及以上到店率', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'store_1_dep', "title" => '一次到店签单客户数', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'store_1_dep_grawth', "title" => '一次到店签单率', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'deposit_customer_count', "title" => '总签单数', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'deposit_customer_grawth', "title" => '总签单率', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"]
- ];
- view::assign('row', json_encode($header1));
- } elseif ($type == 'manager') {
- $header1 = [
- ["field" => 'name', "title" => '员工名称', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'customer_count', "title" => '客户数量', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'return_visit_count', "title" => '待回访客户数', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'no_assigned_personnel', "title" => '待指派客户数', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'no_visit_3', "title" => '3天内未跟进客户数', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'no_visit_7', "title" => '7天内未跟进客户数', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'no_visit_15', "title" => '15天内未跟进客户数', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'no_visit_30', "title" => '一个月内未跟进客户数', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'no_visit_31', "title" => '一个月以上未跟进客户数', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'valid_count', "title" => '有效客户', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'valid_grawth', "title" => '有效率', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'phone_count', "title" => '电话数量', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'on_phone_count', "title" => '接通数量', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'on_phone_grawth', "title" => '接通率', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'off_phone_count', "title" => '未接通', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'avg_phone_time', "title" => '平均通话时长', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'add_wechat_count', "title" => '加微数量', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'add_wechat_grawth', "title" => '加微率', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'room', "title" => '量房客户数', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'room_grawth', "title" => '量房率', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'store1', "title" => '一次到店客户数', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'store1_grawth', "title" => '一次到店率', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'store2', "title" => '二次到店客户数', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'store2_grawth', "title" => '二次到店率', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'store3', "title" => '三次及以上到店客户数', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'store3_grawth', "title" => '三次及以上到店率', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'store1_dep', "title" => '一次到店签单客户数', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'store1_dep_grawth', "title" => '一次到店签单率', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'store2_dep', "title" => '二次到店签单数', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'store2_dep_grawth', "title" => '二次到店签单率', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'store3_dep', "title" => '三次及以上到店签单数', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'store3_dep_grawth', "title" => '三次及以上到店签单率', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'dep', "title" => '总签单数', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'dep_grawth', "title" => '总签单率', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'drawing_date', "title" => '出方案客户数', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'sign_count', "title" => '转单客户', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'sign_grawth', "title" => '转单率', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => '', "child" => ['square_0_80', 'square_80_100', 'square_100_120', 'square_120_200', 'square_200_500', 'square_500'], "title" => '面积分布', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9", 'colspan' => 6],
- ["field" => 'existing_homes_count', "title" => '现房数量', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ["field" => 'forward_housing_count', "title" => '期房数量', "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"],
- ];
- //房屋状态是否开启
- $house_status_where = [
- ['root_id', '=', $root_id],
- ['keyname', '=', 'house_status'],
- ['status', '=', 0]
- ];
- $house_status_per = CustomerPortraitField::where($house_status_where)->findOrEmpty();
- $field = [];
- if (!$house_status_per->isEmpty()) {
- $field = CustomerPortraitFieldSelect::where('pid', $house_status_per->id)->column('id,name');
- foreach ($field as $val) {
- $header1[] = ["field" => 'house_status_' . $val['id'], "title" => $val['name'], "align" => 'center', "rowspan" => 2, "class" => "bgFDE9D9"];
- }
- }
- $header2 = [
- ["field" => 'square_0_80', "title" => '80以下', "align" => 'center', "class" => "bgFDE9D9"],
- ["field" => 'square_80_100', "title" => '81-100', "align" => 'center', "class" => "bgFDE9D9"],
- ["field" => 'square_100_120', "title" => '101-120', "align" => 'center', "class" => "bgFDE9D9"],
- ["field" => 'square_120_200', "title" => '121-200', "align" => 'center', "class" => "bgFDE9D9"],
- ["field" => 'square_200_500', "title" => '201-500', "align" => 'center', "class" => "bgFDE9D9"],
- ["field" => 'square_500', "title" => '500以上', "align" => 'center', "class" => "bgFDE9D9"]
- ];
- $header = $header1;
- foreach ($header as $k => $v) {
- if (isset($v['child'])) {
- array_splice($header, $k, 1, $header2);
- }
- }
- view::assign('row', json_encode($header));
- } elseif ($type == 'general') {
- $header1 = [
- ['field' => 'name', 'title' => '业务员名称', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'org_name', 'title' => '业务员所在部门', 'align' => 'center', 'width' => 130, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'connecting_capacity', 'title' => '接通多少', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'connecting_capacity_grawth', 'title' => '接通率', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'average_duration', 'title' => '平均通话时长', 'align' => 'center', 'width' => 130, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'add_wechat_count', 'title' => '加微数量', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'add_wechat_count_grawth', 'title' => '微信通过率', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'shares_count', 'title' => '调用内容数量', 'align' => 'center', 'width' => 130, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'number_of_explanations', 'title' => '智慧屏讲解次数', 'align' => 'center', 'width' => 150, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'look_data', 'title' => '培训资料是否看了', 'align' => 'center', 'width' => 150, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'assessment_times', 'title' => '考核次数', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'number_of_passes', 'title' => '通过次数', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'resource_count', 'title' => '分配数量', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'following_up_count', 'title' => '在跟进数量', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'deposit_count', 'title' => '签单数量', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'reported_quantity', 'title' => '报备数量', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'valid_count', 'title' => '有效数量', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'valid_grawth', 'title' => '有效率', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'valid_no_wechat', 'title' => '有效未加微', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'measuring_room_customer_no_to_store', 'title' => '量房未到店', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'drawing_date_count', 'title' => '户型图', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'measuring_room_customer', 'title' => '量房数量', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'measuring_room_zhouqi', 'title' => '平均量房周期', 'align' => 'center', 'width' => 130, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'measuring_room_grawth', 'title' => '量房率', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'yuji_store', 'title' => '预计到店数', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'to_the_store_1', 'title' => '一次到店', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'to_the_store_2', 'title' => '二次到店', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'to_the_store_3', 'title' => '三次及以上到店', 'align' => 'center', 'width' => 130, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'strtore_avg_days_1', 'title' => '平均一次到店周期', 'align' => 'center', 'width' => 150, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'strtore_avg_days_2', 'title' => '平均二次到店周期', 'align' => 'center', 'width' => 150, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'strtore_avg_days_3', 'title' => '平均三次及以上到店周期', 'align' => 'center', 'width' => 200, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'strtore_count_1_grawth', 'title' => '一次到店率', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'strtore_count_2_grawth', 'title' => '二次到店率', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'strtore_count_3_grawth', 'title' => '三次及以上到店率', 'align' => 'center', 'width' => 150, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'avg_room_store_zhouqi', 'title' => '平均量房到店周期', 'align' => 'center', 'width' => 170, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'strtore_deposit_count_0', 'title' => '一次到店签单数量', 'align' => 'center', 'width' => 150, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'strtore_deposit_count_1', 'title' => '二次到店签单数量', 'align' => 'center', 'width' => 150, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'strtore_deposit_count_2', 'title' => '三次到及以上店签单数量', 'align' => 'center', 'width' => 200, 'rowspan' => 1, 'class' => 'bgFDE9D9', 'sort' => 38],
- ['field' => 'strtore_deposit_grawth_0', 'title' => '一次到店签单率', 'align' => 'center', 'width' => 130, 'rowspan' => 1, 'class' => 'bgFDE9D9', 'sort' => 39],
- ['field' => 'strtore_deposit_grawth_1', 'title' => '二次到店签单率', 'align' => 'center', 'width' => 130, 'rowspan' => 1, 'class' => 'bgFDE9D9', 'sort' => 40],
- ['field' => 'strtore_deposit_grawth_2', 'title' => '三次到及以上店签单率', 'align' => 'center', 'width' => 180, 'rowspan' => 1, 'class' => 'bgFDE9D9', 'sort' => 41],
- ['field' => 'deposit_avg_days', 'title' => '平均签单周期', 'align' => 'center', 'width' => 135, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'sign_count', 'title' => '转单数量', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'sign_count_grawth', 'title' => '转单率', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'avg_visit_count', 'title' => '平均回访次数', 'align' => 'center', 'width' => 130, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'signed_money', 'title' => '平均合同金额', 'align' => 'center', 'width' => 130, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'square_0_80', 'title' => '80以下', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'square_80_100', 'title' => '81-100', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'square_100_120', 'title' => '101-120', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'square_120_200', 'title' => '121-200', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'square_200_500', 'title' => '201-500', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'square_500', 'title' => '500以上', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'existing_homes_count', 'title' => '现房数量', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'forward_housing_count', 'title' => '期房数量', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ['field' => 'maika_count', 'title' => '卖卡数量', 'align' => 'center', 'width' => 100, 'rowspan' => 1, 'class' => 'bgFDE9D9'],
- ];
- //网销端已增加type值到10,如增加type请往10后面加
- $root_id = request()->employee->root_id;
- //房屋状态是否开启
- $house_status_where = [
- ['root_id', '=', $root_id],
- ['keyname', '=', 'house_status'],
- ['status', '=', 0]
- ];
- $house_status_per = CustomerPortraitField::where($house_status_where)->findOrEmpty();
- $house_field = [];
- if (!$house_status_per->isEmpty()) {
- $field = CustomerPortraitFieldSelect::where('pid', $house_status_per->id)->column('name,id');
- $fields = [];
- foreach ($field as $v) {
- $fields[] = [
- 'field' => 'house_status_' . $v['id'],
- 'title' => $v['name'],
- 'align' => 'center',
- 'width' => 100,
- 'rowspan' => 1,
- 'class' => 'bgFDE9D9'
- ];
- }
- $house_field = $fields;
- }
- $header1 = array_merge($header1, $house_field);
- // 户型
- $housetype_where = [
- ['root_id', '=', $root_id],
- ['keyname', '=', 'housetype_arrow'],
- ['status', '=', 0]
- ];
- $housetype_per = CustomerPortraitField::where($housetype_where)->findOrEmpty();
- $housetype_field = [];
- $housetype_done_field = [];
- if (!$housetype_per->isEmpty()) {
- $field = CustomerPortraitFieldSelect::where('pid', $housetype_per->id)->column('name,id');
- $fields = [];
- $fields_done = [];
- foreach ($field as $v) {
- $fields[] = [
- 'field' => 'housetype_arrow_' . $v['id'],
- 'title' => $v['name'],
- 'align' => 'center',
- 'width' => 100,
- 'rowspan' => 1,
- 'class' => 'bgFDE9D9'
- ];
- $fields_done[] = [
- 'field' => 'housetype_arrow_lv_' . $v['id'],
- 'title' => $v['name'] . '成交率',
- 'align' => 'center',
- 'width' => 100,
- 'rowspan' => 1,
- 'class' => 'bgFDE9D9'
- ];
- }
- $housetype_field = $fields;
- $housetype_done_field = $fields_done;
- }
- $header1 = array_merge($header1, $housetype_field);
- $header1 = array_merge($header1, $housetype_done_field);
- //无效客资
- $invalid_customer = Setting::where([['name', '=', 'clueTag'], ['root_id', '=', $root_id]])->value('content');
- if ($invalid_customer) {
- $invalid_arr = explode(',', $invalid_customer);
- } else {
- $invalid_arr = ['已装修', '无需求', '有需求', '超地域', '未交房', '在外地', '无购买力', '未接通电话'];
- }
- $invalid_field = [];
- foreach ($invalid_arr as $k => $v) {
- $invalid_field[] = [
- 'field' => 'invalid_customer_' . $k,
- 'title' => $v,
- 'align' => 'center',
- 'width' => 100,
- 'rowspan' => 1,
- 'class' => 'bgFDE9D9'
- ];
- }
- $new_type_5_3 = [];
- foreach ($header1 as $k => $v) {
- $new_type_5_3[$k] = $v;
- if ($v['field'] == 'signed_money') {
- $new_type_5_3 = array_merge($new_type_5_3, $invalid_field);
- }
- }
- $header1 = $new_type_5_3;
- view::assign('row', json_encode($header1));
- } else {
- // 行为统计
- $header1 = [
- ["field" => 'x_date', "title" => '时 间', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'name', "title" => '员工姓名', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'org_name', "title" => '所属部门', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'phone_count', "title" => '电话量', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'on_phone_count', "title" => '接通量', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'off_phone_count', "title" => '未接通', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'avg_phone_time', "title" => '平均通话时长', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'add_wechat_count', "title" => '加微数量', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'share_count', "title" => '调用内容数量', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'explain_count', "title" => '智慧屏讲解次数', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'talkskill_view_count', "title" => '浏览话术次数', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'is_look', "title" => '培训是否看了', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'is_exam', "title" => '是否有考核', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'is_exam_ok', "title" => '考核是否通过', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'log_customer_count', "title" => '客户跟进数', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'log_count', "title" => '总回访次数', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'subscribe_room_count', "title" => '预计量房客户数', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'subscribe_store_count', "title" => '预计到店客户数', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'measuring_room_customer_count', "title" => '量房客户数', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'sto_customer_count', "title" => '到店客户数', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'deposit_customer_count', "title" => '交定/签单客户数', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'house_delivery_count', "title" => '预计转施工客户数', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"],
- ["field" => 'sign_customer_count', "title" => '转单客户数', "align" => 'center', "rowspan" => 1, "class" => "bgFDE9D9"]
- ];
- view::assign('row', json_encode($header1));
- }
- View::assign('header1', $header1);
- View::assign('header2', $header2);
- View::assign('header3', $header3);
- return View::fetch();
- }
- if ($type == 'high') {
- return $this->highBehaviorStatisticsData();
- } elseif ($type == 'manager') {
- return $this->manageStatisticsData();
- } elseif ($type == 'general') {
- return $this->generalStatisticsData();
- } else {
- return $this->behaviorStatisticsData();
- }
- }
- /**
- * 分享内容页面
- */
- public function behaviorStatisticsShareLog()
- {
- $root_id = request()->employee->root_id;
- $index = input('index', '');
- View::assign('index', $index);
- return View::fetch();
- }
- /**
- * 分享内容列表接口
- */
- public function behaviorStatisticsShareLogData($page = 1, $limit = 10)
- {
- $param = Request::only(['page' => 1, 'index' => '']);
- $root_id = request()->employee->root_id;
- $arr = explode('@', $param['index']);
- $share_where = ['CompanyStrength', 'Article', 'Construction', 'Activity', 'MaterialEvidence', 'Video', 'MaterialCase', 'Building'];
- $where = [
- ['employee_id', '=', $arr[0]],
- ['share_time', 'like', '%' . $arr[1] . '%'],
- ['type', 'in', $share_where]
- ];
- $list = ShareLog::with('content')->where($where)->page($page, $limit)->order('id desc')->select()->toArray();
- $count = ShareLog::where($where)->count();
- $arr = [
- 'Activity' => '#活动#',
- 'Article' => '#图文素材#',
- 'Building' => '#楼盘进度#',
- 'Card' => '#名片#',
- 'CompanyStrength' => '#公司实力#',
- 'Construction' => '#在施工地#',
- 'CustomerJsAll' => '',
- 'MaterialCase' => '#装修案例#',
- 'MaterialEvidence' => '#口碑见证#',
- 'ToolAll' => '#谈单工具#',
- 'Video' => '#视频#',
- 'Weiwang' => '#个人微网#'
- ];
- foreach ($list as $k => $v) {
- $type = isset($arr[$v['type']]) ? $arr[$v['type']] : '';
- if ($v['content']) {
- $field = $v['type'] == 'Building' ? 'name' : 'title';
- $list[$k]['title'] = $type . '《' . $v['content'][$field] . '》';
- } else {
- $list[$k]['title'] = '';
- }
- }
- return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
- }
- /**
- * 高层行为统计页面
- */
- public function highBehaviorStatistics()
- {
- //返回组织列表
- $org = Org::where([['path', 'like', $this->root_id . '-%']])->select()->toArray();
- View::assign('org', $org);
- return View::fetch();
- }
- /**
- * 高层行为统计接口
- * 日期截止到 2022011-20
- */
- public function highBehaviorStatisticsData($page = 1, $limit = 10)
- {
- $param = Request::only(['page' => 1, 'start_date' => '', 'end_date' => '', 'keyword' => '', 'org_id' => '']);
- $root_id = request()->employee->root_id;
- if ($param['start_date']) {
- $count_dates = explode(' - ', $param['start_date']);
- $start_date = strtotime($count_dates[0]);
- $end_date = strtotime($count_dates[1]);
- } else {
- $start_date = strtotime('2022-11-20');
- $end_date = strtotime(date('Y-m-d'));
- }
- if ($param['keyword']) $where[] = ['name', 'like', '%' . $param['keyword'] . '%'];
- if ($param['org_id']) {
- $o = Org::where([['id', '=', $param['org_id']]], ['path', 'like', $this->root_id . '-%'])->find();
- $orgIds = Org::where([['path', 'like', $o['path'] . '%']])->column('id');
- $where[] = ['org_id', 'in', $orgIds];
- }
- $where[] = ['root_id', '=', $root_id];
- $where[] = ['uid', '>', 0];
- $where[] = ['state', 'in', ['在职', '离职']];
- $eids = Employee::where($where)->column('id');
- $e_count = count($eids);
- //每页开始的位置
- $start = ($page - 1) * $limit;
- $end = $start + $limit - 1;
- //统计日期总天数
- $day = ($end_date - $start_date) / 86400;
- //数据总量
- $count = ($day + 1) * $e_count;
- $ids = [];
- for ($i = 0; $i <= $day; $i++) {
- $j = $i * $e_count;
- if (($j + $e_count) < $start) continue;
- $e = false;
- foreach ($eids as $k => $v) {
- $g = $j + $k;
- if ($g >= $start && $g <= $end) {
- $date = date('Y-m-d', $end_date - ($i * 86400));
- $ids[] = ['id' => $v, 'index' => $v . '@' . $date, 'g' => $g];
- } elseif ($j > $end) {
- $e = true;
- break;
- }
- }
- if ($e) break;
- }
- $lists = array_column($ids, 'index');
- $where[] = ['id', 'in', array_column($ids, 'id')];
- $employees = Employee::with(['customer' => function ($query) {
- $query->field("id,employee_id,DATE_FORMAT(addtime,'%Y-%m-%d') as addtime");
- }])->where($where)->field('id,name,org_id,addtime,position,state,termination_time')->select()->toArray();
- $em_dates = [];
- foreach ($employees as $emp_key => $emp_item) {
- $em_dates[$emp_item['id']] = $emp_item;
- }
- $list = [];
- foreach ($lists as $list_key => $list_item) {
- $arr = explode('@', $list_item);
- $j = $em_dates[$arr[0]];
- $j['x_date'] = date('Y年m月d日', strtotime($arr[1]));
- $j['date'] = $arr[1];
- $j['index'] = $list_item;
- $list[] = $j;
- }
- $eids = array_unique(array_column($list, 'id'));
- $query1 = ['employee_id', 'in', $eids];
- $query2 = ['share_time', 'between', [date('Y-m-d H:i:s', $start_date), date('Y-m-d H:i:s', $end_date + 86399)]];
- $query3 = ['addtime', 'between', [date('Y-m-d H:i:s', $start_date), date('Y-m-d H:i:s', $end_date + 86399)]];
- $custoemr_where = [
- ['employee_id', 'in', $eids]
- ];
- $customer = Customer::where($custoemr_where)->column("id,ext,employee_id,house_delivery_time,DATE_FORMAT(addtime,'%Y-%m-%d') as addtime");
- //加微客户 预计转施工时间
- $add_wechat_date = [];
- $house_delivery_time = [];
- $e_cids = [];
- foreach ($customer as $v1) {
- $v2 = $v1['ext'];
- $ext = json_decode($v2, true);
- if (!empty($ext) && is_array($ext)) {
- $ext = array_filter($ext);
- foreach ($ext as $e) {
- if (isset($e['keyname']) && $e['keyname'] == 'add_wechat_time' && !empty($e['value'])) {
- @$add_wechat_date[$v1['employee_id'] . '@' . date('Y-m-d', strtotime($e['value']))] += 1;
- } elseif (isset($e['keyname']) && $e['keyname'] == 'will_transfer_to_construction_date' && !empty($e['value'])) {
- @$house_delivery_time[$v1['employee_id'] . '@' . date('Y-m-d', strtotime($e['value']))] += 1;
- }
- }
- }
- $e_cids[$v1['employee_id']][] = $v1['id'];
- }
- //客户添加日期截至到列表日期的天数
- $vis = CustomerVisitLog::where([['customer_id', 'in', array_column($customer, 'id')], ['customer_employee_id', 'in', $eids]])->field("DATE_FORMAT(addtime,'%Y-%m-%d') as addtime,concat(customer_id,'@',DATE_FORMAT(addtime,'%Y-%m-%d')) indexx,customer_id,customer_employee_id")->group('indexx')->order('id asc')->select()->toArray();
- $viss = [];
- foreach ($vis as $vis_k => $vis_v) {
- $viss[$vis_v['customer_id']][] = strtotime($vis_v['addtime']);
- }
- foreach ($list as $list_key => $list_val) {
- $customers = $list_val['customer'];
- foreach ($customers as $customers_key => $customers_val) {
- //列表日期
- $customers[$customers_key]['list_date'] = $list_val['date'];
- $start = strtotime($list_val['date']);
- //客户添加日期截至到列表日期的天数
- $customers[$customers_key]['date_diff'] = ceil(($start - strtotime($customers_val['addtime']) + 1) / 86400);
- $customers[$customers_key]['visit_count'] = 0;
- //从客户添加日期截至列表日期的客户的回访次数
- if (isset($viss[$customers_val['id']])) {
- $flip = array_flip($viss[$customers_val['id']]);
- foreach ($flip as $flip_k => $flip_v) {
- if ($flip_k > $start) {
- break;
- }
- $customers[$customers_key]['visit_count'] += 1;
- }
- }
- //客户回访周期
- $customers[$customers_key]['visit_cycle'] = $customers[$customers_key]['visit_count'] == 0 ? 0 : ceil($customers[$customers_key]['date_diff'] / $customers[$customers_key]['visit_count']);
- }
- $cycle = array_filter(array_column($customers, 'visit_cycle'));
- $list[$list_key]['log_time1'] = $cycle ? ceil(array_sum($cycle) / count($cycle)) : 0;
- unset($list[$list_key]['customer']);
- }
- //每人截止到日期的回访次数 和 天数
- $dates = array_column($list, 'date'); //要查询的所有日期
- //调用内容数量,分享内容次数
- $share_where = ['CompanyStrength', 'Article', 'Construction', 'Activity', 'MaterialEvidence', 'Video', 'MaterialCase', 'Building'];
- $share = ShareLog::where([$query1, $query2, ['type', 'in', $share_where]])->field("id,concat(employee_id,'@',DATE_FORMAT(share_time,'%Y-%m-%d')) as indexx,concat(employee_id,type,data_id,DATE_FORMAT(share_time,'%Y-%m-%d')) as str,employee_id")->select()->toArray();
- $shares = [];
- foreach ($share as $share_v) {
- @$shares[$share_v['indexx']] += 1;
- }
- ///培训资料是否看了 课程是否学习过
- $look = TrainCourseView::where([$query1, $query3, ['time', '>', 0]])->column("concat(employee_id,'@',DATE_FORMAT(addtime,'%Y-%m-%d')) as indexx,time");
- $looks = [];
- $look_time = [];
- foreach ($look as $look_item) {
- @$looks[$look_item['indexx']] += 1;
- @$look_time[$look_item['indexx']] += $look_item['time'];
- }
- //考核次数 通过次数
- $don = ExamEmpResult::with(['paperInfo' => function ($query) {
- $query->field('id,base_score')->bind(['base_score' => 'base_score']);
- }])->where([$query1, $query3, ['state', '=', 1]])->field("id,paper_id,final_score,concat(employee_id,'@',DATE_FORMAT(addtime,'%Y-%m-%d')) as indexx")->select()->toArray();
- $don1 = $don2 = []; //是否有考核,考核是否通过
- foreach ($don as $vv) {
- @$don1[$vv['indexx']] += 1; //考核次数
- if ($vv['final_score'] >= $vv['base_score']) @$don2[$vv['indexx']] += 1; //考核通过次数
- }
- //客户跟进数量
- $vislog = CustomerVisitLog::where([
- ['employee_id|customer_employee_id', 'in', $eids], $query3
- ])->order('id asc')->column("state,IF(employee_id,employee_id,customer_employee_id) as employee,DATE_FORMAT(addtime,'%Y-%m-%d') as date,customer_id,concat(IF(employee_id,employee_id,customer_employee_id),'@',DATE_FORMAT(addtime,'%Y-%m-%d')) as indexx");
- $log1 = $log2 = []; //跟进次数 , 跟进客户数
- $state1 = CustomerVisitLog::changeState('已量房', 'chaos');
- $state2 = CustomerVisitLog::changeState('已到店', 'chaos');
- $state3 = CustomerVisitLog::changeState('已交定', 'chaos');
- $state4 = CustomerVisitLog::changeState('已签单', 'chaos');
- $state_count1 = $state_count2 = $state_count3 = $state_count4 = $store = [];
- foreach ($vislog as $ke => $va) {
- @$log1[$va['indexx']] += 1;
- @$log2[$va['indexx']][] = $va['customer_id'];
- if (in_array($va['state'], $state1)) {
- @$state_count1[$va['indexx']][] = $va['customer_id'];
- } elseif (in_array($va['state'], $state2)) {
- @$state_count2[$va['indexx']][] = $va['customer_id'];
- @$store[$va['indexx']][$va['customer_id']][] = $va['addtime'];
- } elseif (in_array($va['state'], $state3)) {
- @$state_count3[$va['indexx']][] = $va['customer_id'];
- } elseif (in_array($va['state'], $state4)) {
- @$state_count4[$va['indexx']][] = $va['customer_id'];
- }
- }
- //一次到店,2次到店 ,3次及以上到店
- $s1 = $cus1 = $s2 = $cus2 = $s3 = $cus3 = [];
- foreach ($store as $store_key => $store_item) {
- foreach ($store_item as $store_item_key => $store_item_item) {
- if (count($store_item_item) == 1) {
- @$s1[$store_key] += 1;
- $cus1[] = $store_item_key;
- } elseif (count($store_item_item) == 2) {
- @$s2[$store_key] += 1;
- $cus2[] = $store_item_key;
- } elseif (count($store_item_item) >= 3) {
- @$s3[$store_key] += 1;
- $cus3[] = $store_item_key;
- }
- }
- }
- //预约记录
- $query4 = [
- ['state', '=', 0],
- ['type', 'in', [1, 3]],
- ['employee_id', 'in', $eids],
- ['subscribe_date', 'between', [date('Y-m-d H:i:s', $start_date), date('Y-m-d H:i:s', $end_date + 86399)]]
- ];
- $sub1 = $sub2 = []; //1到店 2量房
- $subscribe = CustomersSubscribe::where($query4)->column("employee_id,customer_id,subscribe_date,type,concat(employee_id,'@',DATE_FORMAT(subscribe_date,'%Y-%m-%d')) as indexx");
- foreach ($subscribe as $v4) {
- $v4['type'] == 1 ? @$sub1[$v4['indexx']] += 1 : @$sub2[$v4['indexx']] += 1;
- }
- //话术浏览次数
- $talk_view = TalkskillViewLog::where([$query1, $query3])->column("concat(employee_id,'@',DATE_FORMAT(addtime,'%Y-%m-%d')) as indexx");
- $talk_count = [];
- foreach ($talk_view as $t_item) {
- @$talk_count[$t_item['indexx']] += 1;
- }
- //智慧屏讲解次数
- $zhihuis = CustomerVisitLog::where([['employee_id|customer_employee_id', 'in', $eids], $query3, ['remark', 'like', '%讲解智慧屏##%']])
- ->field("IF(employee_id,employee_id,customer_employee_id) as employee,DATE_FORMAT(addtime,'%Y-%m-%d') as date,customer_id,concat(IF(employee_id,employee_id,customer_employee_id),'@',DATE_FORMAT(addtime,'%Y-%m-%d')) as indexx")->select()->toArray();
- $zhihui = [];
- foreach ($zhihuis as $v) {
- @$zhihui[$v['indexx']] += 1;
- }
- // 外呼系统统计
- $outCallLog = OutCallLog::where([['employee_id', 'in', $eids]])->field("count(id) as phone_count, sum(if(`status`>0,1,0)) as on_phone_count, sum(if(`status`<0,1,0)) as off_phone_count,sum(billsec) as phone_time,concat(employee_id,'@',DATE_FORMAT(addtime,'%Y-%m-%d')) as indexx")->group('indexx')->select()->toArray();
- $outCallLog = array_combine(array_column($outCallLog, 'indexx'), $outCallLog);
- // 手机打电话次数获取
- $outCallMbLog = OutCallMbLog::where([
- ['employee_id', 'in', $eids]
- ])->field("count(id) as phone_count,concat(employee_id,'@',DATE_FORMAT(addtime,'%Y-%m-%d')) as indexx")->group('indexx')->select()->toArray();
- $outCallMbLog = array_combine(array_column($outCallMbLog, 'indexx'), $outCallMbLog);
- $org = Org::where([['id', 'in', array_column($list, 'org_id')]])->column('name', 'id');
- foreach ($list as $key => $val) {
- //部门名称
- $list[$key]['org_name'] = isset($org[$val['org_id']]) ? $org[$val['org_id']] : '无';
- //职位
- // $list[$key]['position'] = $val['position'];
- //电话量
- $list[$key]['phone_count'] = 0;
- //接通量
- $list[$key]['on_phone_count'] = 0;
- //未接通
- $list[$key]['off_phone_count'] = 0;
- //平均通话时长
- $list[$key]['avg_phone_time'] = 0;
- if (isset($outCallLog[$val['index']])) {
- //电话量
- $list[$key]['phone_count'] = $outCallLog[$val['index']]['phone_count'];
- //接通量
- $list[$key]['on_phone_count'] = $outCallLog[$val['index']]['on_phone_count'];
- //未接通
- $list[$key]['off_phone_count'] = $outCallLog[$val['index']]['off_phone_count'];
- //平均通话时长
- $list[$key]['avg_phone_time'] = $list[$key]['on_phone_count'] == 0 ? 0 : round($outCallLog[$val['index']]['phone_time'] / $list[$key]['on_phone_count'], 2);
- }
- if (isset($outCallMbLog[$val['index']])) {
- //电话量
- $list[$key]['phone_count'] += $outCallMbLog[$val['index']]['phone_count'];
- }
- //加微数量
- $list[$key]['add_wechat_count'] = isset($add_wechat_date[$val['index']]) ? $add_wechat_date[$val['index']] : 0;
- //分享内容数量
- $list[$key]['share_count'] = isset($shares[$val['index']]) ? $shares[$val['index']] : 0;
- //智慧屏讲解次数
- $list[$key]['explain_count'] = isset($zhihui[$val['index']]) ? $zhihui[$val['index']] : 0;
- //每个客户讲解次数
- $list[$key]['explain_count1'] = $list[$key]['add_wechat_count'] == 0 ? $list[$key]['explain_count'] : ceil($list[$key]['explain_count'] / $list[$key]['add_wechat_count']);
- //话术浏览次数
- $list[$key]['talkskill_view_count'] = isset($talk_count[$val['index']]) ? $talk_count[$val['index']] : 0;
- //培训观看次数
- $list[$key]['is_look'] = isset($looks[$val['index']]) ? $looks[$val['index']] : 0;
- //培训观看时长
- $list[$key]['look_time'] = isset($look_time[$val['index']]) ? $look_time[$val['index']] : 0;
- //跟进次数
- $list[$key]['log_count'] = isset($log1[$val['index']]) ? $log1[$val['index']] : 0;
- //平均回访时长
- $list[$key]['log_time'] = 0;
- //一次到店客户数
- $list[$key]['store_1'] = isset($s1[$val['index']]) ? $s1[$val['index']] : 0;
- //二次到店客户数
- $list[$key]['store_2'] = isset($s2[$val['index']]) ? $s2[$val['index']] : 0;
- //三次到店客户数
- $list[$key]['store_3'] = isset($s3[$val['index']]) ? $s3[$val['index']] : 0;
- //跟进客户数量
- $list[$key]['log_customer_count'] = isset($log2[$val['index']]) ? count(array_unique($log2[$val['index']])) : 0;
- //量房客户数
- $list[$key]['measuring_room_customer_count'] = isset($state_count1[$val['index']]) ? count(array_unique($state_count1[$val['index']])) : 0;
- //到店客户数
- $list[$key]['sto_customer_count'] = isset($state_count2[$val['index']]) ? count(array_unique($state_count2[$val['index']])) : 0;
- //一次到店率
- $list[$key]['store_1_grawth'] = $list[$key]['sto_customer_count'] == 0 ? '0%' : round($list[$key]['store_1'] / $list[$key]['sto_customer_count'] * 100, 2) . '%';
- //二次到店率
- $list[$key]['store_2_grawth'] = $list[$key]['sto_customer_count'] == 0 ? '0%' : round($list[$key]['store_2'] / $list[$key]['sto_customer_count'] * 100, 2) . '%';
- //三次及以上到店率
- $list[$key]['store_3_grawth'] = $list[$key]['sto_customer_count'] == 0 ? '0%' : round($list[$key]['store_3'] / $list[$key]['sto_customer_count'] * 100, 2) . '%';
- //交定
- $list[$key]['deposit_customer_count'] = isset($state_count3[$val['index']]) ? count(array_unique($state_count3[$val['index']])) : 0;
- // 一次到店交定客户数量
- $list[$key]['store_1_dep'] = $list[$key]['deposit_customer_count'] == 0 ? 0 : count(array_intersect($state_count3[$val['index']], $cus1));
- //一次到店交定率
- $list[$key]['store_1_dep_grawth'] = $list[$key]['sto_customer_count'] == 0 ? '0%' : round($list[$key]['store_1_dep'] / $list[$key]['sto_customer_count'] * 100, 2) . '%';
- //交定率
- $list[$key]['deposit_customer_grawth'] = $list[$key]['log_customer_count'] == 0 ? '0%' : round($list[$key]['deposit_customer_count'] / $list[$key]['log_customer_count'] * 100, 2) . '%';
- //签单
- $list[$key]['sign_customer_count'] = isset($state_count4[$val['index']]) ? count(array_unique($state_count4[$val['index']])) : 0;
- //预计转施工客户数量
- $list[$key]['house_delivery_count'] = isset($house_delivery_time[$val['index']]) ? $house_delivery_time[$val['index']] : 0;
- //预计到店数
- $list[$key]['subscribe_store_count'] = isset($sub1[$val['index']]) ? $sub1[$val['index']] : 0;
- //预计量房数量
- $list[$key]['subscribe_room_count'] = isset($sub2[$val['index']]) ? $sub2[$val['index']] : 0;
- //考核次数
- $list[$key]['is_exam'] = isset($don1[$val['index']]) ? $don1[$val['index']] : 0;
- //考核通过次数
- $list[$key]['is_exam_ok'] = isset($don2[$val['index']]) ? $don2[$val['index']] : 0;
- //回访次数 从客户报备开始截至到日期的回访次数,一天按一次计算
- //平均回访周期
- // $list[$key]['log_time1'] = 0;
- }
- return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功', 'page' => ceil($count / $limit)]);
- }
- /**
- * 加微客户页面
- */
- public function addWechat()
- {
- $root_id = request()->employee->root_id;
- $index = input('index', '');
- View::assign('index', $index);
- $type = input('type', '');
- if ($type == 'customerLog') {
- //跟进记录
- $field = [
- ['field' => 'name', 'title' => '姓名'],
- ['field' => 'addtime', 'title' => '跟进时间']
- ];
- $url = url("statistics/customerLog", ["index" => $index]);
- } elseif ($type == 'customerLogs') {
- //跟进记录
- $field = [
- ['field' => 'name', 'title' => '姓名'],
- ['field' => 'addtime', 'title' => '回访时间']
- ];
- $url = url("statistics/customerLog", ["index" => $index, 'type' => 'log']);
- } elseif ($type == 'room') {
- //量房客户
- $field = [
- ['field' => 'name', 'title' => '姓名'],
- ['field' => 'addtime', 'title' => '量房时间']
- ];
- $url = url("statistics/customerLog", ["index" => $index, 'type' => 'room']);
- } elseif (in_array($type, ['store1', 'store2'])) {
- //一次到店两次到店客户
- $field = [
- ['field' => 'name', 'title' => '姓名'],
- ['field' => 'addtime', 'title' => '到店时间']
- ];
- $url = url("statistics/customerLog", ["index" => $index, 'type' => $type]);
- } elseif ($type == 'store_dep') {
- //到店交定客户
- $field = [
- ['field' => 'name', 'title' => '姓名'],
- ['field' => 'store_time', 'title' => '到店时间'],
- ['field' => 'dep_time', 'title' => '签单时间']
- ];
- $url = url("statistics/customerLog", ["index" => $index, 'type' => $type]);
- } elseif ($type == 'dep') {
- //交定客户
- $field = [
- ['field' => 'name', 'title' => '姓名'],
- ['field' => 'addtime', 'title' => '签单时间']
- ];
- $url = url("statistics/customerLog", ["index" => $index, 'type' => $type]);
- } elseif ($type == 'explain_count') {
- //智慧屏讲解客户列表
- $field = [
- ['field' => 'name', 'title' => '姓名'],
- ['field' => 'phone', 'title' => '电话'],
- ['field' => 'addtime', 'title' => '讲解时间'],
- ];
- $url = url("statistics/customerLog", ["index" => $index, 'type' => $type]);
- } else {
- //加微客户
- $field = [
- ['field' => 'name', 'title' => '姓名'],
- ['field' => 'phone', 'title' => '电话'],
- ['field' => 'date', 'title' => '加微日期'],
- ];
- $url = url("statistics/addWechatList", ["index" => $index]);
- }
- View::assign('fields', json_encode($field));
- View::assign('url', $url);
- return View::fetch();
- }
- /**
- * 加微客户列表接口
- */
- public function addWechatList()
- {
- $param = Request::only(['page' => 1, 'limit' => 10, 'index' => '']);
- $root_id = request()->employee->root_id;
- $arr = explode('@', $param['index']);
- $time = $arr[1];
- $where = [
- ['employee_id', '=', $arr[0]],
- ['add_wechat_time', 'like', $time]
- ];
- $list = Customer::where($where)->field('phone,name,add_wechat_time date')->page($param['page'], $param['limit'])->select()->toArray();
- foreach ($list as $k => $v) {
- $list[$k]['phone'] = substr_replace($v['phone'], '******', 3, 6);
- }
- $count = Customer::where($where)->count();
- return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
- }
- /**
- * 跟进列表接口
- */
- public function customerLog()
- {
- $param = Request::only(['page' => 1, 'limit' => 10, 'index' => '', 'type' => '']);
- $root_id = request()->employee->root_id;
- $arr = explode('@', $param['index']);
- $where = [
- ['employee_id|customer_employee_id', '=', $arr[0]],
- ['addtime', 'like', '%' . $arr[1] . '%']
- ];
- if ($param['type'] == 'log') {
- // 跟进记录
- $field = 'addtime,customer_id,state';
- } elseif ($param['type'] == 'room') {
- //量房客户
- $field = 'max(addtime) addtime,customer_id,state';
- $where[] = ['state', 'in', CustomerVisitLog::changeState('已量房', 'chaos')];
- } elseif (in_array($param['type'], ['store1', 'store2'])) {
- //一次到店客户 , 二次到店客户
- $field = "max(addtime) addtime,customer_id,state";
- $where[] = ['state', 'in', CustomerVisitLog::changeState('已到店', 'chaos')];
- } elseif ($param['type'] == 'store_dep') {
- //一次到店交定
- $field = 'id,name';
- } elseif ($param['type'] == 'dep') {
- //交定
- $where[] = ['state', 'in', CustomerVisitLog::changeState('已交定', 'chaos')];
- $field = 'max(addtime) addtime,customer_id,state';
- } elseif ($param['type'] == 'explain_count') {
- //智慧屏讲解客户列表
- $where[] = ['remark', 'like', '%讲解智慧屏##%'];
- $field = 'id,addtime,customer_id';
- } else {
- //跟进客户
- $field = 'max(addtime) addtime,customer_id,state';
- }
- if ($param['type'] != 'store_dep' || $param['type'] == 'explain_count') {
- $list = CustomerVisitLog::with(['customer' => function ($query) {
- $query->field('id,name,phone')->bind(['name' => 'name', 'phone' => 'phone']);
- }])->where($where)->field($field);
- }
- if (in_array($param['type'], ['', 'room', 'dep'])) {
- $list = $list->group('customer_id');
- } elseif (in_array($param['type'], ['store1', 'store2'])) {
- $c = $param['type'] == 'store1' ? 1 : 2;
- $list = $list->group('customer_id')->having('count(customer_id)=' . $c);
- } elseif ($param['type'] == 'store_dep') {
- //一次到店
- $store = CustomerVisitLog::where(array_merge($where, [['state', 'in', CustomerVisitLog::changeState('已到店', 'chaos')]]))->group('customer_id')->having('count(customer_id)=1')->column('addtime', 'customer_id');
- //交定
- $dep = CustomerVisitLog::where(array_merge($where, [['state', 'in', CustomerVisitLog::changeState('已交定', 'chaos')]]))->column('addtime', 'customer_id');
- $cids = array_intersect(array_keys($store), array_keys($dep));
- $list = Customer::where([['id', 'in', $cids]])->field($field);
- }
- $count = $list->count();
- $list = $list->page($param['page'], $param['limit'])->select()->toArray();
- if ($param['type'] == 'store_dep') {
- foreach ($list as $k => $v) {
- $list[$k]['store_time'] = $store[$v['id']];
- $list[$k]['dep_time'] = $dep[$v['id']];
- }
- } elseif ($param['type'] == 'explain_count') {
- foreach ($list as $k => $v) {
- $list[$k]['phone'] = substr_replace($v['phone'], '******', 3, 6);
- $list[$k]['name'] = empty($v['name']) ? '未知' : $v['name'];
- }
- }
- return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
- }
- /**
- * 管理行为统计页面
- */
- public function manageStatistics()
- {
- $root_id = request()->employee->root_id;
- //房屋状态是否开启
- $house_status_where = [
- ['root_id', '=', $root_id],
- ['keyname', '=', 'house_status'],
- ['status', '=', 0]
- ];
- $house_status_per = CustomerPortraitField::where($house_status_where)->findOrEmpty();
- $field = [];
- if (!$house_status_per->isEmpty()) {
- $field = CustomerPortraitFieldSelect::where('pid', $house_status_per->id)->column('name,id');
- $fields = [];
- foreach ($field as $v) {
- $fields[] = [
- 'field' => 'house_status_' . $v['id'],
- 'title' => $v['name'],
- 'align' => 'center',
- 'width' => 100,
- 'rowspan' => 2
- ];
- }
- $field = $fields;
- }
- View::assign('field', json_encode($field));
- //返回组织列表
- $org = Org::where([['path', 'like', $this->root_id . '-%']])->select()->toArray();
- View::assign('org', $org);
- return View::fetch();
- }
- /**
- * 管理层数据统计
- */
- public function manageStatisticsData($page = 1, $limit = 10)
- {
- $param = Request::only(['page' => 1, 'start_date' => '', 'end_date' => '', 'keyword' => '', 'org_id' => '']);
- //日期搜索//2023-02-15页面逻辑修改 传参方式改为 start_date=2023/2/15 - 2023/2/15
- if ($param['start_date']) {
- $count_dates = explode(' - ', $param['start_date']);
- $param['start_date'] = date('Y-m-d 00:00:00', strtotime($count_dates[0]));
- $param['end_date'] = date('Y-m-d 23:59:59', strtotime($count_dates[1]));
- } else {
- $param['start_date'] = $param['end_date'] = '';
- }
- $query_date = ($param['start_date'] && $param['end_date']) ? [['addtime', 'between', [$param['start_date'], $param['end_date']]]] : [];
- $root_id = request()->employee->root_id;
- $where = [
- ['root_id', '=', $root_id],
- ['uid', '>', 0],
- ['state', '=', '在职']
- // ['is_manager', '=', 1]
- ];
- if ($param['start_date'] && $param['end_date']) {
- $sdate = strtotime($param['start_date']);
- $edate = strtotime($param['end_date']);
- } else {
- $edate = time();
- $sdate = 972473642;
- }
- if ($param['keyword']) {
- $where[] = ['name', 'like', '%' . $param['keyword'] . '%'];
- }
- if ($param['org_id']) {
- $o = Org::where([['id', '=', $param['org_id']]], ['path', 'like', $this->root_id . '-%'])->find();
- $orgIds = Org::where([['path', 'like', $o['path'] . '%']])->column('id');
- $where[] = ['org_id', 'in', $orgIds];
- }
- $employee_date = [$param['start_date'], $param['end_date']];
- $list = Employee::with(['customer' => function ($query) use ($employee_date) {
- //手动报备查addtime,分配查询employee_time
- if ($employee_date[0] && $employee_date[1]) {
- $e_where1 = [
- ['addtime', 'between', [$employee_date[0], $employee_date[1]]],
- ['crm_res_id', '=', 0]
- ];
- $e_where2 = [
- ['crm_res_id', '>', 0],
- ['employee_time', 'between', [$employee_date[0], $employee_date[1]]]
- ];
- $query->whereOr([$e_where1, $e_where2])->field('id,employee_id,ext,is_resource,addtime,signed_money,house_type,square,house_status,return_visit,assigned_personnel');
- } else {
- $query->field('id,employee_id,ext,is_resource,addtime,signed_money,house_type,square,house_status,return_visit,assigned_personnel');
- }
- }])->where($where)->field('id,org_id,name')->page($page, $limit)->select()->toArray();
- $count = Employee::where($where)->count();
- //客户ID
- $customer_ids = [];
- foreach ($list as $key => $val) {
- $cid = array_column($val['customer'], 'id');
- $customer_ids = array_merge($customer_ids, $cid);
- }
- //2023-02-21 有效客户查询
- $state1 = Customer::changeState('待确认', 'chaos');
- $state2 = Customer::changeState('无效', 'chaos');
- $queryv1 = [['state', 'not in', array_merge($state1, $state2)], ['id', 'in', $customer_ids]];
- $queryv2 = [['state', 'in', $state1], ['crm_res_id', 'null', null], ['id', 'in', $customer_ids]];
- $valid_vislog = Customer::whereOr([$queryv1, $queryv2])->column('id');
- //最近跟进时间
- $max_addtime = CustomerVisitLog::where([['is_merge', '=', 0], ['customer_id', 'in', $customer_ids]])->group('customer_id')->column('max(addtime) addtime', 'customer_id');
- //查询有效数量 //有效性判断 ,, //有效状态 未到访,已到访,确定到场,已量房,交定,签单
- $state1 = CustomerVisitLog::changeState('未到访', 'chaos');
- $state2 = CustomerVisitLog::changeState('已到访', 'chaos');
- $state3 = CustomerVisitLog::changeState('已量房', 'chaos');
- $state4 = CustomerVisitLog::changeState('已到店', 'chaos');
- $state5 = CustomerVisitLog::changeState('已交定', 'chaos');
- $state6 = CustomerVisitLog::changeState('已签单', 'chaos');
- $state7 = CustomerVisitLog::changeState('已到场', 'chaos');
- $vis_where[] = ['customer_id', 'in', $customer_ids];
- $vis_where[] = ['state', 'in', array_merge($state1, $state2, $state3, $state4, $state5, $state6, $state7)];
- if($query_date) $vis_where[] = $query_date[0];
- $vislog_list = CustomerVisitLog::where($vis_where)->order('addtime asc')->column('customer_id,state,addtime,next_contact_date');
- // $valid_vislog = array_unique(array_column($vislog_list, 'customer_id'));
- $rooms = $store = $dep = $sign = [];
- foreach ($vislog_list as $vislog_list_item) {
- if (in_array($vislog_list_item['state'], $state3)) {
- $rooms[] = $vislog_list_item['customer_id'];
- } elseif (in_array($vislog_list_item['state'], $state4)) {
- @$store[$vislog_list_item['customer_id']][] = $vislog_list_item['addtime'];
- } elseif (in_array($vislog_list_item['state'], $state5)) {
- @$dep[$vislog_list_item['customer_id']][] = $vislog_list_item['addtime'];
- } elseif (in_array($vislog_list_item['state'], $state6)) {
- $sign[] = $vislog_list_item['customer_id'];
- }
- }
- $rooms = array_unique($rooms); //量房客户
- //到店客户
- $store1 = $store2 = $store3 = [];
- foreach ($store as $store_key => $store_val) {
- if (count($store_val) == 1) {
- $store1[] = $store_key;
- } elseif (count($store_val) == 2) {
- $store2[] = $store_key;
- } else {
- $store3[] = $store_key;
- }
- }
- //交定客户
- $dep1 = $dep2 = $dep3 = [];
- foreach ($dep as $dep_key => $dep_item) {
- if (count($dep_item) == 1) {
- $dep1[] = $dep_key;
- } elseif (count($dep_item) == 2) {
- $dep2[] = $dep_key;
- } else {
- $dep3[] = $dep_key;
- }
- }
- //房屋状态是否开启
- $house_status_where = [
- ['root_id', '=', $root_id],
- ['keyname', '=', 'house_status'],
- ['status', '=', 0]
- ];
- $house_status_per = CustomerPortraitField::where($house_status_where)->findOrEmpty();
- $field = [];
- if (!$house_status_per->isEmpty()) {
- $field = CustomerPortraitFieldSelect::where('pid', $house_status_per->id)->column('name,id');
- }
- // 电话统计
- $outCallLog = OutCallLog::where([['root_id', '=', $root_id]])->where($query_date)->field("count(id) as phone_count, sum(if(`status`>0,1,0)) as on_phone_count, sum(if(`status`<0,1,0)) as off_phone_count,sum(billsec) as phone_time,employee_id")->group('employee_id')->select()->toArray();
- $outCallLog = array_combine(array_column($outCallLog, 'employee_id'), $outCallLog);
- // 手机打电话次数获取
- $outCallMbLog = OutCallMbLog::where([
- ['root_id', '=', $root_id]
- ])->field("count(id) as phone_count,employee_id")->group('employee_id')->select()->toArray();
- $outCallMbLog = array_combine(array_column($outCallMbLog, 'employee_id'), $outCallMbLog);
- foreach ($list as $k => $v) {
- //客户ID
- $cids = array_column($v['customer'], 'id');
- //客户数量
- $list[$k]['customer_count'] = count($cids);
- //待回访
- $list[$k]['return_visit_count'] = count(array_filter(array_column($v['customer'], 'return_visit')));
- //待指派
- $assigned_personnel = count(array_filter(array_column($v['customer'], 'assigned_personnel')));
- $list[$k]['no_assigned_personnel'] = $list[$k]['customer_count'] - $assigned_personnel;
- //三天,七天,十五天,三十天,三十天以上未跟进
- $list[$k]['no_visit_3'] = $list[$k]['no_visit_7'] = $list[$k]['no_visit_15'] = $list[$k]['no_visit_30'] = $list[$k]['no_visit_31'] = 0;
- foreach ($v['customer'] as $customer_item) {
- //最近跟进时间
- $visit_time = isset($max_addtime[$customer_item['id']]) ? $max_addtime[$customer_item['id']] : $customer_item['addtime'];
- $day = ceil((time() - strtotime($visit_time)) / 86400);
- if ($day <= 3 && $day > 1) {
- $list[$k]['no_visit_3'] += 1;
- } elseif ($day <= 7 && $day > 3) {
- $list[$k]['no_visit_7'] += 1;
- } elseif ($day < 15 && $day > 7) {
- $list[$k]['no_visit_15'] += 1;
- } elseif ($day <= 30 && $day > 15) {
- $list[$k]['no_visit_30'] += 1;
- } elseif ($day > 30) {
- $list[$k]['no_visit_31'] += 1;
- }
- }
- //有效客户
- $valid = array_intersect($cids, $valid_vislog);
- //有效客户数量
- $list[$k]['valid_count'] = count($valid);
- //有效率
- $list[$k]['valid_grawth'] = $this->grawth($list[$k]['customer_count'], $list[$k]['valid_count']);
- //电话量
- $list[$k]['phone_count'] = 0;
- //接通量
- $list[$k]['on_phone_count'] = 0;
- //接通率
- $list[$k]['on_phone_grawth'] = 0;
- //未接通
- $list[$k]['off_phone_count'] = 0;
- //平均通话时长
- $list[$k]['avg_phone_time'] = 0;
- if (isset($outCallLog[$v['id']])) {
- //电话量
- $list[$k]['phone_count'] = $outCallLog[$v['id']]['phone_count'];
- //接通量
- $list[$k]['on_phone_count'] = $outCallLog[$v['id']]['on_phone_count'];
- //接通率
- $list[$k]['on_phone_grawth'] = $this->grawth($list[$k]['phone_count'], $list[$k]['on_phone_count']);
- //未接通
- $list[$k]['off_phone_count'] = $outCallLog[$v['id']]['off_phone_count'];
- //平均通话时长
- $list[$k]['avg_phone_time'] = $list[$k]['on_phone_count'] == 0 ? 0 : round($outCallLog[$v['id']]['phone_time'] / $list[$k]['on_phone_count'], 2);
- }
- if (isset($outCallMbLog[$v['id']])) {
- //电话量
- $list[$k]['phone_count'] += $outCallMbLog[$v['id']]['phone_count'];
- }
- $customer = $this->addWechatCount($v['customer'], $sdate, $edate);
- //加微数量
- $list[$k]['add_wechat_count'] = count($customer['wechat_count']);
- //出方案客户数
- $list[$k]['drawing_date'] = count($customer['plan_issuing_date']);
- //加微率
- $list[$k]['add_wechat_grawth'] = $this->grawth($list[$k]['valid_count'], $list[$k]['add_wechat_count']);
- //量房客户数
- $list[$k]['room'] = count(array_intersect($rooms, $cids));
- //量房率
- $list[$k]['room_grawth'] = $this->grawth($list[$k]['valid_count'], $list[$k]['room']);
- //到店客户数
- $store1 = array_intersect($store1, $cids);
- $store2 = array_intersect($store2, $cids);
- $store3 = array_intersect($store3, $cids);
- $list[$k]['store1'] = count($store1);
- $list[$k]['store2'] = count($store2);
- $list[$k]['store3'] = count($store3);
- $list[$k]['store1_grawth'] = $this->grawth($list[$k]['customer_count'], $list[$k]['store1']);
- $list[$k]['store2_grawth'] = $this->grawth($list[$k]['customer_count'], $list[$k]['store2']);
- $list[$k]['store3_grawth'] = $this->grawth($list[$k]['customer_count'], $list[$k]['store3']);
- //交定客户数
- $z_dep = array_intersect(array_keys($dep), $cids);
- $dep1 = array_intersect($dep1, $cids);
- $dep2 = array_intersect($dep2, $cids);
- $dep3 = array_intersect($dep3, $cids);
- $list[$k]['dep1'] = count($dep1);
- $list[$k]['dep2'] = count($dep2);
- $list[$k]['dep3'] = count($dep3);
- $list[$k]['dep1_grawth'] = $this->grawth($list[$k]['customer_count'], $list[$k]['dep1']);
- $list[$k]['dep2_grawth'] = $this->grawth($list[$k]['customer_count'], $list[$k]['dep2']);
- $list[$k]['dep3_grawth'] = $this->grawth($list[$k]['customer_count'], $list[$k]['dep3']);
- $list[$k]['dep'] = count($z_dep);
- $list[$k]['dep_grawth'] = $this->grawth($list[$k]['customer_count'], $list[$k]['dep']);
- //一次到店签单客户数
- $list[$k]['store1_dep'] = count(array_intersect($z_dep, $store1));
- $list[$k]['store1_dep_grawth'] = $this->grawth($list[$k]['customer_count'], $list[$k]['store1_dep']);
- $list[$k]['store2_dep'] = count(array_intersect($z_dep, $store2));
- $list[$k]['store2_dep_grawth'] = $this->grawth($list[$k]['customer_count'], $list[$k]['store2_dep']);
- $list[$k]['store3_dep'] = count(array_intersect($z_dep, $store3));
- $list[$k]['store3_dep_grawth'] = $this->grawth($list[$k]['customer_count'], $list[$k]['store3_dep']);
- //签单
- $list[$k]['sign_count'] = count(array_intersect($cids, $sign));
- $list[$k]['sign_grawth'] = $this->grawth($list[$k]['customer_count'], $list[$k]['sign_count']);
- //面积
- $list[$k]['square_0_80'] = $customer['square_0_80']; //
- $list[$k]['square_80_100'] = $customer['square_80_100']; //
- $list[$k]['square_100_120'] = $customer['square_100_120']; //
- $list[$k]['square_120_200'] = $customer['square_120_200']; //
- $list[$k]['square_200_500'] = $customer['square_200_500']; //
- $list[$k]['square_500'] = $customer['square_500']; //
- //房屋类型
- $list[$k]['existing_homes_count'] = $customer['existing_homes_count']; //现房数量
- $list[$k]['forward_housing_count'] = $customer['forward_housing_count']; //期房数量
- //房屋状态
- if ($field) {
- $house_status = $this->getHouseStatus($customer['house_status'], $field);
- $list[$k] = array_merge($list[$k], $house_status);
- }
- unset($list[$k]['customer']);
- }
- return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功', 'page' => ceil($count / $limit)]);
- }
- /**
- * 率
- */
- private function grawth($zcount, $count)
- {
- $res = $zcount == 0 ? '0%' : round($count / $zcount * 100, 2) . '%';
- return $res;
- }
- /**
- * 加微数量
- */
- private function addWechatCount($wechat, $sdate, $edate)
- {
- $data['wechat_count'] = [];
- $data['plan_issuing_date'] = []; //出方案时间
- $square = $house_type = [];
- $data['house_status'] = [];
- foreach ($wechat as $v) {
- $data['house_status'][] = $v['house_status'];
- $square[] = $v['square'];
- $house_type[] = $v['house_type'];
- //客户添加时间
- $addtime = strtotime($v['addtime']);
- //加微客户,有户型图客户
- $v2 = $v['ext'];
- $ext = json_decode($v2, true);
- if (!empty($ext) && is_array($ext)) {
- $ext = array_filter($ext);
- foreach ($ext as $e) {
- if (isset($e['keyname']) && $e['keyname'] == 'add_wechat_time' && !empty($e['value']) && strtotime($e['value']) >= $sdate && strtotime($e['value']) <= $edate) {
- $data['wechat_count'][] = $v['id'];
- } elseif (isset($e['keyname']) && $e['keyname'] == 'drawing_date' && !empty($e['value']) && strtotime($e['value']) >= $sdate && strtotime($e['value']) <= $edate) {
- $data['drawing_date'][] = $v['id'];
- }
- }
- }
- }
- //面积
- //房屋面积
- $data['square_0_80'] = $data['square_80_100'] = $data['square_100_120'] = $data['square_120_200'] = $data['square_200_500'] = $data['square_500'] = 0;
- foreach ($square as $square_item) {
- if (!$square_item) continue; //不填不计算
- if ($square_item <= 80) {
- $data['square_0_80'] += 1;
- } elseif ($square_item <= 100) {
- $data['square_80_100'] += 1;
- } elseif ($square_item <= 120) {
- $data['square_100_120'] += 1;
- } elseif ($square_item <= 200) {
- $data['square_120_200'] += 1;
- } elseif ($square_item <= 500) {
- $data['square_200_500'] += 1;
- } else {
- $data['square_500'] += 1;
- }
- }
- //房屋类型
- $data['existing_homes_count'] = 0; //现房数量
- $data['forward_housing_count'] = 0; //期房数量
- foreach ($house_type as $house_type_item) {
- if (strpos($house_type_item, '现房') !== false) {
- $data['existing_homes_count'] += 1;
- } elseif (strpos($house_type_item, '期房') !== false) {
- $data['forward_housing_count'] += 1;
- }
- }
- return $data;
- }
- /**
- * 弹框页面
- */
- public function manageOpen()
- {
- $root_id = request()->employee->root_id;
- $eid = input('eid',);
- View::assign('eid', $eid);
- $type = input('type', '');
- $start_date = input('start_date', '');
- $end_date = input('end_date', '');
- if ($type == 'assign') {
- //待指派
- $field = [
- ['field' => 'name', 'title' => '姓名'],
- ['field' => 'phone', 'title' => '电话']
- ];
- $url = url("statistics/manageOpenData", ["eid" => $eid, 'type' => $type, 'end_date' => $end_date, 'start_date' => $start_date]);
- } else if (in_array($type, ['v3', 'v7', 'v15', 'v30', 'v31'])) {
- //天未指派
- $field = [
- ['field' => 'name', 'title' => '姓名'],
- ['field' => 'phone', 'title' => '电话']
- ];
- $url = url("statistics/manageOpenData", ["eid" => $eid, 'type' => $type, 'end_date' => $end_date, 'start_date' => $start_date]);
- } else if (in_array($type, ['valid', 'wechat', 'room'])) {
- //天未指派
- $field = [
- ['field' => 'name', 'title' => '姓名'],
- ['field' => 'phone', 'title' => '电话']
- ];
- $url = url("statistics/manageOpenData", ["eid" => $eid, 'type' => $type, 'end_date' => $end_date, 'start_date' => $start_date]);
- } elseif ($type == 'invalid') {
- $key = input('key', '');
- //无效客资
- $field = [
- ['field' => 'name', 'title' => '姓名'],
- ['field' => 'phone', 'title' => '电话']
- ];
- $url = url("statistics/manageOpenData", ["eid" => $eid, 'type' => $type, 'end_date' => $end_date, 'start_date' => $start_date, 'key' => $key]);
- } elseif ($type == 'number_of_explanations') {
- //智慧屏讲解
- $field = [
- ['field' => 'name', 'title' => '姓名'],
- ['field' => 'phone', 'title' => '电话'],
- ['field' => 'addtime', 'title' => '讲解时间']
- ];
- $url = url("statistics/manageOpenData", ["eid" => $eid, 'type' => $type, 'end_date' => $end_date, 'start_date' => $start_date]);
- } else {
- //待回访客户
- $field = [
- ['field' => 'name', 'title' => '姓名'],
- ['field' => 'phone', 'title' => '电话']
- ];
- $url = url("statistics/manageOpenData", ["eid" => $eid, 'type' => $type, 'end_date' => $end_date, 'start_date' => $start_date]);
- }
- View::assign('fields', json_encode($field));
- View::assign('url', $url);
- return View::fetch('add_wechat');
- }
- /**
- * 弹框页面数据
- */
- public function manageOpenData()
- {
- $param = Request::only(['page' => 1, 'limit' => 10, 'eid' => 0, 'type' => '', 'start_date' => '', 'end_date' => '']);
- $root_id = request()->employee->root_id;
- $where = [
- ['employee_id', '=', $param['eid']]
- ];
- if ($param['start_date'] && $param['end_date']) {
- $where[] = ['addtime', 'between', [$param['start_date'], $param['end_date'] . ' 23:59:59']];
- }
- if ($param['type'] == 'assign') {
- //待指派
- $where[] = ['assigned_personnel', '=', NULL];
- $list = Customer::where($where)->where(function ($query) {
- $or1[] = ['crm_res_id', 'null', null];
- $or2[] = ['crm_res_id', '>', 0];
- $or2[] = ['state', 'not in', Customer::changeState('待确认', 'chaos')];
- $query->whereOr([$or1, $or2]);
- })->field('name,phone');
- } elseif (in_array($param['type'], ['v3', 'v7', 'v15', 'v30', 'v31'])) {
- $arr = ['v3' => [1, 3], 'v7' => [3, 7], 'v15' => [7, 15], 'v30' => [15, 30], 'v31' => [30, 999999]];
- //3天未回访
- $cids = Customer::where($where)->column('addtime', 'id');
- $max_addtime = CustomerVisitLog::where([['is_merge', '=', 0], ['customer_id', 'in', array_keys($cids)]])->group('customer_id')->column('max(addtime) addtime', 'customer_id');
- $cid = [];
- foreach ($cids as $k => $v) {
- //最近跟进时间
- $visit_time = isset($max_addtime[$k]) ? $max_addtime[$k] : $v;
- $day = ceil((time() - strtotime($visit_time)) / 86400);
- if ($day > $arr[$param['type']][0] && $day <= $arr[$param['type']][1]) {
- $cid[] = $k;
- }
- }
- if (empty($cid)) return json(['code' => 0, 'data' => [], 'count' => 0, 'msg' => '获取成功']);
- $where[] = ['id', 'in', $cid];
- $list = Customer::where($where)->field('name,phone');
- } elseif ($param['type'] == 'valid') {
- //有效客户数量
- $state1 = Customer::changeState('待确认', 'chaos');
- $state2 = Customer::changeState('无效', 'chaos');
- $query1 = [['state', 'not in', array_merge($state1, $state2)], ['employee_id', '=', $param['eid']]];
- $query2 = [['state', 'in', $state1], ['crm_res_id', 'null', null], ['employee_id', '=', $param['eid']]];
- $ids = Customer::whereOr([$query1, $query2])->column('id');
- if ($param['start_date'] && $param['end_date']) {
- $query1 = [['id', 'in', $ids], ['crm_res_id', 'null', null], ['addtime', 'between', [$param['start_date'], $param['end_date']]]];
- $query2 = [['id', 'in', $ids], ['crm_res_id', 'not null', null], ['employee_time', 'between', [$param['start_date'], $param['end_date']]]];
- $list = Customer::whereOr([$query1, $query2])->field('name,phone');
- } else {
- $list = Customer::where([['id', 'in', $ids]])->field('name,phone');
- }
- } elseif ($param['type'] == 'wechat' || $param['type'] == 'drawing') {
- $field = $param['type'] == 'wechat' ? 'add_wechat_time' : 'drawing_date';
- //加微客户
- $where1[] = ['ext', 'like', '%' . $field . '%'];
- $ext = Customer::where(array_merge($where, $where1))->column('id,ext');
- $cid = [];
- foreach ($ext as $v) {
- $json = json_decode($v['ext'], true);
- foreach ($json as $v2) {
- if ($v2['keyname'] == $field && !empty($v2['value'])) {
- $cid[] = $v['id'];
- }
- }
- }
- $where[] = ['id', 'in', $cid];
- $list = Customer::where($where)->field('name,phone');
- } elseif ($param['type'] == 'room') {
- //量房客户
- $customer_ids = Customer::where($where)->column('id');
- $state3 = CustomerVisitLog::changeState('已量房', 'chaos');
- $vis_where[] = ['customer_id', 'in', $customer_ids];
- $vis_where[] = ['state', 'in', $state3];
- $cid = CustomerVisitLog::where($vis_where)->group('customer_id')->column('customer_id');
- $where[] = ['id', 'in', $cid];
- $list = Customer::where($where)->field('name,phone');
- } elseif (in_array($param['type'], ['store1', 'store2', 'store3'])) {
- $having = ['store1' => 'count(id)=1', 'store2' => 'count(id)=2', 'store3' => 'count(id)>=3'];
- //一次到店客户数
- $customer_ids = Customer::where($where)->column('id');
- $state = CustomerVisitLog::changeState('已到店', 'chaos');
- $vis_where[] = ['customer_id', 'in', $customer_ids];
- $vis_where[] = ['state', 'in', $state];
- $cid = CustomerVisitLog::where($vis_where)->group('customer_id')->having($having[$param['type']])->column('customer_id');
- $where[] = ['id', 'in', $cid];
- $list = Customer::where($where)->field('name,phone');
- } elseif (in_array($param['type'], ['store1_dep', 'store2_dep', 'store3_dep'])) {
- $having = ['store1_dep' => 'count(id)=1', 'store2_dep' => 'count(id)=2', 'store3_dep' => 'count(id)>=3'];
- //一次到店客户数
- $customer_ids = Customer::where($where)->column('id');
- $state = CustomerVisitLog::changeState('已到店', 'chaos');
- $state1 = CustomerVisitLog::changeState('已交定', 'chaos');
- $vis_where[] = ['customer_id', 'in', $customer_ids];
- $vis_where[] = ['state', 'in', $state];
- $c1 = CustomerVisitLog::where($vis_where)->group('customer_id')->having($having[$param['type']])->column('customer_id');
- //交定
- $vis_where1[] = ['customer_id', 'in', $customer_ids];
- $vis_where1[] = ['state', 'in', $state1];
- $c2 = CustomerVisitLog::where($vis_where1)->group('customer_id')->column('customer_id');
- $where[] = ['id', 'in', array_intersect($c1, $c2)];
- $list = Customer::where($where)->field('name,phone');
- } elseif ($param['type'] == 'dep' || $param['type'] == 'sign_count') {
- $state = $param['type'] == 'dep' ? '已交定' : '已签单';
- $customer_ids = Customer::where($where)->column('id');
- $state1 = CustomerVisitLog::changeState($state, 'chaos');
- //交定
- $vis_where1[] = ['customer_id', 'in', $customer_ids];
- $vis_where1[] = ['state', 'in', $state1];
- $c2 = CustomerVisitLog::where($vis_where1)->group('customer_id')->column('customer_id');
- $where[] = ['id', 'in', $c2];
- $list = Customer::where($where)->field('name,phone');
- } elseif (in_array($param['type'], ['square_0_80', 'square_80_100', 'square_100_120', 'square_120_200', 'square_200_500', 'square_500'])) {
- $arr = [
- 'square_0_80' => [0, 80],
- 'square_80_100' => [81, 100],
- 'square_100_120' => [101, 120],
- 'square_120_200' => [121, 200],
- 'square_200_500' => [201, 500],
- 'square_500' => [501, 999999],
- ];
- $square = Customer::where($where)->column('square,id');
- $cid = [];
- foreach ($square as $v) {
- if ($v['square'] && $v['square'] > $arr[$param['type']][0] && $v['square'] <= $arr[$param['type']][1]) $cid[] = $v['id'];
- }
- $where[] = ['id', 'in', $cid];
- $list = Customer::where($where)->field('name,phone');
- } elseif ($param['type'] == 'existing_homes_count' || $param['type'] == 'forward_housing_count') {
- //现房 期房客户
- $field = $param['type'] == 'existing_homes_count' ? '现房' : '期房';
- $where[] = ['house_type', 'like', '%' . $field . '%'];
- $list = Customer::where($where)->field('name,phone');
- } elseif ($param['type'] == 'invalid') {
- $invalid_customer = Setting::where([['name', '=', 'clueTag'], ['root_id', '=', $root_id]])->value('content');
- $arr = $invalid_customer ? explode(',', $invalid_customer) : ['已装修', '无需求', '有需求', '超地域', '未交房', '在外地', '无购买力', '未接通电话'];
- $field = (int)input('key', '');
- if (empty($arr) || !isset($arr[$field])) return json(['code' => 0, 'data' => [], 'count' => [], 'msg' => '获取成功']);
- $status = $arr[$field];
- $customer_ids = Customer::where($where)->column('id');
- $state3 = CustomerVisitLog::where([['remark', 'like', '%' . $status . '%'], ['customer_id', 'in', $customer_ids]])->group('customer_id')->column('customer_id');
- $where[] = ['id', 'in', $state3];
- $list = Customer::where($where)->field('name,phone');
- } elseif ($param['type'] == 'number_of_explanations') {
- //智慧屏讲解客户列表
- // $list = CustomerVisitLog::with(['custoemr'=>function($query){}])->where([['employee_id|customer_employee_id','=',$param['eid']],['remark','like','%讲解智慧屏##%']])->field('customer_id,addtime')->select()->toArray();
- } else {
- $where[] = ['return_visit', '=', 1];
- $list = Customer::where($where)->field('name,phone');
- }
- $count = $list->count();
- $list = $list->page($param['page'], $param['limit'])->select()->toArray();
- foreach ($list as $k => $v) {
- $list[$k]['phone'] = substr_replace($v['phone'], '******', 3, 6);
- $list[$k]['name'] = empty($v['name']) ? '未知' : $v['name'];
- }
- return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
- }
- /**
- * 统计展示字段 网销端已增加type值到10,
- */
- public function statisticsFields($type)
- {
- // 行为统计
- $type1 = [
- 'x_date' => ['name' => '时间', 'show' => 1, 'width' => 150, 'sort' => 1],
- 'name' => ['name' => '员工姓名', 'show' => 1, 'width' => 100, 'sort' => 2],
- 'org_name' => ['name' => '所属部门', 'show' => 1, 'width' => 100, 'sort' => 3],
- 'phone_count' => ['name' => '电话量', 'show' => 1, 'width' => 75, 'sort' => 4],
- 'on_phone_count' => ['name' => '接通量', 'show' => 1, 'width' => 75, 'sort' => 5],
- 'off_phone_count' => ['name' => '未接通', 'show' => 1, 'width' => 75, 'sort' => 6],
- 'avg_phone_time' => ['name' => '平均通话时长', 'show' => 1, 'width' => 130, 'sort' => 7],
- 'add_wechat_count' => ['name' => '加微数量', 'show' => 1, 'width' => 90, 'sort' => 8],
- 'share_count' => ['name' => '调用内容数量', 'show' => 1, 'width' => 130, 'sort' => 9],
- 'explain_count' => ['name' => '智慧屏讲解次数', 'show' => 1, 'width' => 150, 'sort' => 10],
- 'talkskill_view_count' => ['name' => '浏览话术次数', 'show' => 1, 'width' => 130, 'sort' => 11],
- 'is_look' => ['name' => '培训是否看了', 'show' => 1, 'width' => 120, 'sort' => 12],
- 'is_exam' => ['name' => '是否有考核', 'show' => 1, 'width' => 110, 'sort' => 13],
- 'is_exam_ok' => ['name' => '考核是否通过', 'show' => 1, 'width' => 130, 'sort' => 14],
- 'log_customer_count' => ['name' => '客户跟进数', 'show' => 1, 'width' => 100, 'sort' => 15],
- 'log_count' => ['name' => '总回访次数', 'show' => 1, 'width' => 100, 'sort' => 16],
- 'subscribe_room_count' => ['name' => '预计量房客户数', 'show' => 1, 'width' => 150, 'sort' => 17],
- 'subscribe_store_count' => ['name' => '预计到店客户数', 'show' => 1, 'width' => 150, 'sort' => 18],
- 'measuring_room_customer_count' => ['name' => '量房客户数', 'show' => 1, 'width' => 120, 'sort' => 19],
- 'sto_customer_count' => ['name' => '到店客户数', 'show' => 1, 'width' => 120, 'sort' => 20],
- 'deposit_customer_count' => ['name' => '交定/签单客户数', 'show' => 1, 'width' => 150, 'sort' => 21],
- 'house_delivery_count' => ['name' => '预计转施工客户数', 'show' => 1, 'width' => 150, 'sort' => 22],
- 'sign_customer_count' => ['name' => '转单客户数', 'show' => 1, 'width' => 100, 'sort' => 23],
- ];
- // 高层统计
- $type2 = [
- 'x_date' => ['name' => '时间', 'show' => 1, 'width' => 150, 'sort' => 1],
- 'name' => ['name' => '员工姓名', 'show' => 1, 'width' => 100, 'sort' => 2],
- 'org_name' => ['name' => '所属部门', 'show' => 1, 'width' => 100, 'sort' => 3],
- 'position' => ['name' => '职位', 'show' => 1, 'width' => 80, 'sort' => 4],
- 'phone_count' => ['name' => '电话量', 'show' => 1, 'width' => 75, 'sort' => 5],
- 'on_phone_count' => ['name' => '接通量', 'show' => 1, 'width' => 75, 'sort' => 6],
- 'off_phone_count' => ['name' => '未接通', 'show' => 1, 'width' => 75, 'sort' => 7],
- 'avg_phone_time' => ['name' => '平均通话时长', 'show' => 1, 'width' => 130, 'sort' => 8],
- 'add_wechat_count' => ['name' => '加微数量', 'show' => 1, 'width' => 90, 'sort' => 9],
- 'share_count' => ['name' => '调用内容数量', 'show' => 1, 'width' => 130, 'sort' => 10],
- 'explain_count' => ['name' => '智慧屏讲解次数', 'show' => 1, 'width' => 150, 'sort' => 11],
- 'explain_count1' => ['name' => '每个客户讲解次数', 'show' => 1, 'width' => 200, 'sort' => 12],
- 'talkskill_view_count' => ['name' => '浏览话术次数', 'show' => 1, 'width' => 130, 'sort' => 13],
- 'is_look' => ['name' => '看培训次数', 'show' => 1, 'width' => 120, 'sort' => 14],
- 'look_time' => ['name' => '看培训时长(S)', 'show' => 1, 'width' => 150, 'sort' => 15],
- 'is_exam' => ['name' => '是否有考核', 'show' => 1, 'width' => 110, 'sort' => 16],
- 'is_exam_ok' => ['name' => '考核是否通过', 'show' => 1, 'width' => 130, 'sort' => 17],
- 'log_customer_count' => ['name' => '客户跟进数', 'show' => 1, 'width' => 100, 'sort' => 18],
- 'log_count' => ['name' => '总回访次数', 'show' => 1, 'width' => 100, 'sort' => 19],
- 'log_time' => ['name' => '平均回访时长', 'show' => 1, 'width' => 150, 'sort' => 20],
- 'log_time1' => ['name' => '平均回访周期', 'show' => 1, 'width' => 150, 'sort' => 21],
- 'measuring_room_customer_count' => ['name' => '量房客户数', 'show' => 1, 'width' => 120, 'sort' => 22],
- 'store_1' => ['name' => '一次到店客户数', 'show' => 1, 'width' => 175, 'sort' => 23],
- 'store_1_grawth' => ['name' => '一次到店率', 'show' => 1, 'width' => 125, 'sort' => 24],
- 'store_2' => ['name' => '二次到店客户数', 'show' => 1, 'width' => 175, 'sort' => 25],
- 'store_2_grawth' => ['name' => '二次到店率', 'show' => 1, 'width' => 125, 'sort' => 26],
- 'store_3' => ['name' => '三次及以上到店客户数', 'show' => 1, 'width' => 250, 'sort' => 27],
- 'store_3_grawth' => ['name' => '三次及以上到店率', 'show' => 1, 'width' => 200, 'sort' => 28],
- 'store_1_dep' => ['name' => '一次到店签单客户数', 'show' => 1, 'width' => 225, 'sort' => 29],
- 'store_1_dep_grawth' => ['name' => '一次到店签单率', 'show' => 1, 'width' => 175, 'sort' => 30],
- 'deposit_customer_count' => ['name' => '总签单数', 'show' => 1, 'width' => 100, 'sort' => 31],
- 'deposit_customer_grawth' => ['name' => '总签单率', 'show' => 1, 'width' => 100, 'sort' => 32],
- ];
- // 管理层统计
- $type3 = [
- 'name' => ['name' => '员工姓名', 'show' => 1, 'width' => 100, 'sort' => 1],
- 'customer_count' => ['name' => '客户数量', 'show' => 1, 'width' => 100, 'sort' => 2],
- 'return_visit_count' => ['name' => '待回访客户数', 'show' => 1, 'width' => 150, 'sort' => 3],
- 'no_assigned_personnel' => ['name' => '待指派客户数', 'show' => 1, 'width' => 150, 'sort' => 4],
- 'no_visit_3' => ['name' => '3天内未跟进客户数', 'show' => 1, 'width' => 225, 'sort' => 5],
- 'no_visit_7' => ['name' => '7天内未跟进客户数', 'show' => 1, 'width' => 225, 'sort' => 6],
- 'no_visit_15' => ['name' => '15天内未跟进客户数', 'show' => 1, 'width' => 225, 'sort' => 7],
- 'no_visit_30' => ['name' => '一个月内未跟进客户数', 'show' => 1, 'width' => 250, 'sort' => 8],
- 'no_visit_31' => ['name' => '一个月以上未跟进客户数', 'show' => 1, 'width' => 275, 'sort' => 9],
- 'valid_count' => ['name' => '有效客户', 'show' => 1, 'width' => 100, 'sort' => 10],
- 'valid_grawth' => ['name' => '有效率', 'show' => 1, 'width' => 75, 'sort' => 11],
- 'phone_count' => ['name' => '电话数量', 'show' => 1, 'width' => 100, 'sort' => 12],
- 'on_phone_count' => ['name' => '接通数量', 'show' => 1, 'width' => 100, 'sort' => 13],
- 'on_phone_grawth' => ['name' => '接通率', 'show' => 1, 'width' => 75, 'sort' => 14],
- 'off_phone_count' => ['name' => '未接通', 'show' => 1, 'width' => 75, 'sort' => 15],
- 'avg_phone_time' => ['name' => '平均通话时长', 'show' => 1, 'width' => 150, 'sort' => 16],
- 'add_wechat_count' => ['name' => '加微数量', 'show' => 1, 'width' => 100, 'sort' => 17],
- 'add_wechat_grawth' => ['name' => '加微率', 'show' => 1, 'width' => 75, 'sort' => 18],
- 'room' => ['name' => '量房客户数', 'show' => 1, 'width' => 125, 'sort' => 19],
- 'room_grawth' => ['name' => '量房率', 'show' => 1, 'width' => 75, 'sort' => 20],
- 'store1' => ['name' => '一次到店客户数', 'show' => 1, 'width' => 175, 'sort' => 21],
- 'store1_grawth' => ['name' => '一次到店率', 'show' => 1, 'width' => 125, 'sort' => 22],
- 'store2' => ['name' => '二次到店客户数', 'show' => 1, 'width' => 175, 'sort' => 23],
- 'store2_grawth' => ['name' => '二次到店率', 'show' => 1, 'width' => 125, 'sort' => 24],
- 'store3' => ['name' => '三次及以上到店客户数', 'show' => 1, 'width' => 250, 'sort' => 25],
- 'store3_grawth' => ['name' => '三次及以上到店率', 'show' => 1, 'width' => 200, 'sort' => 26],
- 'store1_dep' => ['name' => '一次到店签单客户数', 'show' => 1, 'width' => 225, 'sort' => 27],
- 'store1_dep_grawth' => ['name' => '一次到店签单率', 'show' => 1, 'width' => 175, 'sort' => 28],
- 'store2_dep' => ['name' => '二次到店签单数', 'show' => 1, 'width' => 175, 'sort' => 29],
- 'store2_dep_grawth' => ['name' => '二次到店签单率', 'show' => 1, 'width' => 175, 'sort' => 30],
- 'store3_dep' => ['name' => '三次及以上到店签单数', 'show' => 1, 'width' => 250, 'sort' => 31],
- 'store3_dep_grawth' => ['name' => '三次及以上到店签单率', 'show' => 1, 'width' => 250, 'sort' => 32],
- 'dep' => ['name' => '总签单数', 'show' => 1, 'width' => 100, 'sort' => 33],
- 'dep_grawth' => ['name' => '总签单率', 'show' => 1, 'width' => 100, 'sort' => 34],
- 'drawing_date' => ['name' => '出方案客户数', 'show' => 1, 'width' => 150, 'sort' => 35],
- 'sign_count' => ['name' => '转单客户', 'show' => 1, 'width' => 100, 'sort' => 36],
- 'sign_grawth' => ['name' => '转单率', 'show' => 1, 'width' => 75, 'sort' => 37],
- 'area' => ['name' => '面积分布', 'show' => 1, 'width' => 100, 'sort' => 38],
- 'existing_homes_count' => ['name' => '现房数量', 'show' => 1, 'width' => 100, 'sort' => 40],
- 'forward_housing_count' => ['name' => '期房数量', 'show' => 1, 'width' => 100, 'sort' => 41],
- ];
- // 客户统计列表
- $type4 = [
- 'name' => ['name' => '客户姓名', 'show' => 1, 'width' => 100, 'sort' => 1],
- 'phone' => ['name' => '手机号', 'show' => 1, 'width' => 125, 'sort' => 2],
- 'community_name' => ['name' => '小区', 'show' => 1, 'width' => 150, 'sort' => 3],
- 'house_type' => ['name' => '房屋类型', 'show' => 1, 'width' => 100, 'sort' => 4],
- 'house_delivery_time' => ['name' => '交房时间', 'show' => 1, 'width' => 100, 'sort' => 5],
- 'square' => ['name' => '面积', 'show' => 1, 'width' => 75, 'sort' => 6],
- 'org_name' => ['name' => '部门', 'show' => 1, 'width' => 120, 'sort' => 7],
- 'employee_name' => ['name' => '业务员', 'show' => 1, 'width' => 90, 'sort' => 8],
- 'addtime' => ['name' => '添加时间', 'show' => 1, 'width' => 170, 'sort' => 9],
- 'source_name' => ['name' => '来源渠道', 'show' => 1, 'width' => 100, 'sort' => 10],
- 'assigned_personal_manager' => ['name' => '指派客户经理', 'show' => 1, 'width' => 150, 'sort' => 11],
- 'assigned_personal_designer_org' => ['name' => '指派设计部', 'show' => 1, 'width' => 125, 'sort' => 12],
- 'assigned_personal_designer' => ['name' => '指派设计师', 'show' => 1, 'width' => 125, 'sort' => 13],
- 'no_visit_day' => ['name' => '未跟踪天数', 'show' => 1, 'width' => 125, 'sort' => 14],
- 'wechat' => ['name' => '是否加微信', 'show' => 1, 'width' => 125, 'sort' => 15],
- 'add_wechat_type' => ['name' => '加微类型', 'show' => 1, 'width' => 100, 'sort' => 16],
- 'add_wechat_time' => ['name' => '加微时间', 'show' => 1, 'width' => 120, 'sort' => 17],
- 'group_building_date' => ['name' => '建群时间', 'show' => 1, 'width' => 250, 'sort' => 18],
- 'is_liangfang' => ['name' => '是否量房', 'show' => 1, 'width' => 125, 'sort' => 19],
- 'liangfang_date' => ['name' => '量房时间', 'show' => 1, 'width' => 170, 'sort' => 20],
- 'once_liangfang_days' => ['name' => '量房周期', 'show' => 1, 'width' => 120, 'sort' => 21],
- 'plan_issuing_date' => ['name' => '计划出初步方案时间', 'show' => 1, 'width' => 225, 'sort' => 22],
- 'once_daodian' => ['name' => '是否一次到店', 'show' => 1, 'width' => 150, 'sort' => 23],
- 'daodian_date' => ['name' => '一次到店时间', 'show' => 1, 'width' => 170, 'sort' => 24],
- 'once_daodian_shop' => ['name' => '一次所到店面', 'show' => 1, 'width' => 150, 'sort' => 25],
- 'once_daodian_days' => ['name' => '一次到店周期', 'show' => 1, 'width' => 150, 'sort' => 26],
- 'liangfang_daodian_days' => ['name' => '量房到店周期', 'show' => 1, 'width' => 150, 'sort' => 27],
- 'twice_daodian_date' => ['name' => '二次到店时间', 'show' => 1, 'width' => 170, 'sort' => 28],
- 'twice_daodian_shop' => ['name' => '二次所到店面', 'show' => 1, 'width' => 150, 'sort' => 29],
- 'twice_daodian_days' => ['name' => '二次到店周期', 'show' => 1, 'width' => 150, 'sort' => 30],
- 'is_deposit' => ['name' => '是否交定/签单', 'show' => 1, 'width' => 170, 'sort' => 31],
- 'deposit_date' => ['name' => '交定/签单时间', 'show' => 1, 'width' => 170, 'sort' => 32],
- 'drawing_date' => ['name' => '出图时间', 'show' => 1, 'width' => 100, 'sort' => 33],
- 'sign_date' => ['name' => '转单时间', 'show' => 1, 'width' => 170, 'sort' => 34],
- 'sign_days' => ['name' => '交定转单周期', 'show' => 1, 'width' => 150, 'sort' => 35],
- 'signed_money_data' => ['name' => '合同金额(元)', 'show' => 1, 'width' => 125, 'sort' => 36],
- 'first_visit_no_sign' => ['name' => '一次到店未签单时间', 'show' => 1, 'width' => 200, 'sort' => 37],
- 'manager_visit_times' => ['name' => '客户经理回访次数', 'show' => 1, 'width' => 200, 'sort' => 38],
- 'manager_visit_cycle' => ['name' => '客户经理回访周期', 'show' => 1, 'width' => 100, 'sort' => 39],
- 'employee_visit_times' => ['name' => '经理回访次数', 'show' => 1, 'width' => 150, 'sort' => 40],
- 'employee_visit_cycle' => ['name' => '经理回访平均周期', 'show' => 1, 'width' => 200, 'sort' => 41],
- 'invalid' => ['name' => '无效客户', 'show' => 1, 'width' => 100, 'sort' => 42],
- 'invalid_remark' => ['name' => '无效原因', 'show' => 1, 'width' => 100, 'sort' => 43],
- 'died' => ['name' => '是否死单', 'show' => 1, 'width' => 100, 'sort' => 44],
- 'customer_type' => ['name' => '客户种类', 'show' => 1, 'width' => 100, 'sort' => 11],
- ];
- // 总统计
- // 一级标题
- $type5_1 = [
- 'name' => ['name' => '业务员名称', 'show' => 1, 'width' => 100],
- 'org_name' => ['name' => '业务员所在部门', 'show' => 1, 'width' => 130],
- 'behavior' => ['name' => '行为统计', 'show' => 1, 'width' => 100],
- 'customer' => ['name' => '客户统计', 'show' => 1, 'width' => 100],
- 'house' => ['name' => '房屋信息统计', 'show' => 1, 'width' => 100],
- ];
- // 二级标题
- $type5_2 = [
- 'name' => ['name' => '业务员名称', 'show' => 1, 'width' => 100, 'parent' => 'name'],
- 'org_name' => ['name' => '业务员所在部门', 'show' => 1, 'width' => 130, 'parent' => 'org_name'],
- 'connecting_count' => ['name' => '电话量', 'show' => 1, 'width' => 150, 'parent' => 'behavior'],
- 'add_wechat_count' => ['name' => '加微数量', 'show' => 1, 'width' => 100, 'parent' => 'behavior'],
- 'add_wechat_count_grawth' => ['name' => '微信通过率', 'show' => 1, 'width' => 100, 'parent' => 'behavior'],
- 'shares_count' => ['name' => '调用内容数量', 'show' => 1, 'width' => 130, 'parent' => 'behavior'],
- 'number_of_explanations' => ['name' => '智慧屏讲解次数', 'show' => 1, 'width' => 150, 'parent' => 'behavior'],
- 'look_data' => ['name' => '培训资料是否看了', 'show' => 1, 'width' => 150, 'parent' => 'behavior'],
- 'exam_data' => ['name' => '考核通过情况', 'show' => 1, 'width' => 100, 'parent' => 'behavior'],
- 'customer_data' => ['name' => '客户总量', 'show' => 1, 'width' => 100, 'parent' => 'customer'],
- 'valid_count' => ['name' => '有效数量', 'show' => 1, 'width' => 100, 'parent' => 'customer'],
- 'valid_grawth' => ['name' => '有效率', 'show' => 1, 'width' => 100, 'parent' => 'customer'],
- 'valid_no_wechat' => ['name' => '有效未加微', 'show' => 1, 'width' => 100, 'parent' => 'customer'],
- 'measuring_room_customer_no_to_store' => ['name' => '量房未到店', 'show' => 1, 'width' => 100, 'parent' => 'customer'],
- 'drawing_date_count' => ['name' => '户型图', 'show' => 1, 'width' => 100, 'parent' => 'customer'],
- 'measuring_room_customer' => ['name' => '量房数量', 'show' => 1, 'width' => 100, 'parent' => 'customer'],
- 'measuring_room_zhouqi' => ['name' => '平均量房周期', 'show' => 1, 'width' => 130, 'parent' => 'customer'],
- 'measuring_room_grawth' => ['name' => '量房率', 'show' => 1, 'width' => 100, 'parent' => 'customer'],
- 'yuji_store' => ['name' => '预计到店数', 'show' => 1, 'width' => 100, 'parent' => 'customer'],
- 'daodian_count' => ['name' => '到店数', 'show' => 1, 'width' => 120, 'parent' => 'customer'],
- 'daodian_avg' => ['name' => '平均到店周期', 'show' => 1, 'width' => 225, 'parent' => 'customer'],
- 'daodian_grawth' => ['name' => '到店率', 'show' => 1, 'width' => 150, 'parent' => 'customer'],
- 'avg_room_store_zhouqi' => ['name' => '平均量房到店周期', 'show' => 1, 'width' => 170, 'parent' => 'customer'],
- 'daodian_deposit' => ['name' => '到店签单数量', 'show' => 1, 'width' => 150, 'parent' => 'customer'],
- 'daodian_deposit_grawth' => ['name' => '到店签单率', 'show' => 1, 'width' => 150, 'parent' => 'customer'],
- 'avg_dep_zhouqi'=> ['name'=> '平均签单周期', 'show'=> 1, 'width'=> 135, 'parent'=> 'customer'],
- 'sign_count' => ['name' => '转单数量', 'show' => 1, 'width' => 100, 'parent' => 'customer'],
- 'sign_grawth' => ['name' => '转单率', 'show' => 1, 'width' => 100, 'parent' => 'customer'],
- 'avg_visit_count' => ['name' => '平均回访次数', 'show' => 1, 'width' => 130, 'parent' => 'customer'],
- 'signed_money' => ['name' => '平均合同金额', 'show' => 1, 'width' => 130, 'parent' => 'customer'],
- 'died_customer' => ['name' => '无效客资', 'show' => 1, 'width' => 100, 'parent' => 'customer'],
- 'area' => ['name' => '面积分布', 'show' => 1, 'width' => 170, 'parent' => 'house'],
- 'existing_homes_count' => ['name' => '现房数量', 'show' => 1, 'width' => 100, 'parent' => 'house'],
- 'forward_housing_count' => ['name' => '期房数量', 'show' => 1, 'width' => 100, 'parent' => 'house'],
- ];
- // 三级标题
- $type5_3 = [
- 'name' => ['name' => '业务员名称', 'show' => 1, 'width' => 100, 'parent' => 'name', 'sort' => 1],
- 'org_name' => ['name' => '业务员所在部门', 'show' => 1, 'width' => 130, 'parent' => 'org_name', 'sort' => 2],
- 'connecting_count' => ['name' => '拨打量', 'show' => 1, 'width' => 100, 'parent' => 'call_count', 'sort' => 2],
- 'connecting_capacity' => ['name' => '接通多少', 'show' => 1, 'width' => 100, 'parent' => 'call_count', 'sort' => 3],
- 'connecting_capacity_grawth' => ['name' => '接通率', 'show' => 1, 'width' => 100, 'parent' => 'call_count', 'sort' => 4],
- 'average_duration' => ['name' => '平均通话时长', 'show' => 1, 'width' => 130, 'parent' => 'call_count', 'sort' => 5],
- 'add_wechat_count' => ['name' => '加微数量', 'show' => 1, 'width' => 100, 'parent' => 'behavior', 'sort' => 6],
- 'add_wechat_count_grawth' => ['name' => '微信通过率', 'show' => 1, 'width' => 100, 'parent' => 'behavior', 'sort' => 7],
- 'shares_count' => ['name' => '调用内容数量', 'show' => 1, 'width' => 130, 'parent' => 'behavior', 'sort' => 8],
- 'number_of_explanations' => ['name' => '智慧屏讲解次数', 'show' => 1, 'width' => 150, 'parent' => 'behavior', 'sort' => 9],
- 'look_data' => ['name' => '培训资料是否看了', 'show' => 1, 'width' => 150, 'parent' => 'behavior', 'sort' => 10],
- 'assessment_times' => ['name' => '考核次数', 'show' => 1, 'width' => 100, 'parent' => 'exam_data', 'sort' => 11],
- 'number_of_passes' => ['name' => '通过次数', 'show' => 1, 'width' => 100, 'parent' => 'exam_data', 'sort' => 12],
- 'resource_count' => ['name' => '分配数量', 'show' => 1, 'width' => 100, 'parent' => 'customer_data', 'sort' => 13],
- 'following_up_count' => ['name' => '在跟进数量', 'show' => 1, 'width' => 100, 'parent' => 'customer_data', 'sort' => 14],
- 'deposit_count' => ['name' => '签单数量', 'show' => 1, 'width' => 100, 'parent' => 'customer_data', 'sort' => 15],
- 'reported_quantity' => ['name' => '报备数量', 'show' => 1, 'width' => 100, 'parent' => 'customer_data', 'sort' => 16],
- 'valid_count' => ['name' => '有效数量', 'show' => 1, 'width' => 100, 'parent' => 'customer', 'sort' => 17],
- 'valid_grawth' => ['name' => '有效率', 'show' => 1, 'width' => 100, 'parent' => 'customer', 'sort' => 18],
- 'valid_no_wechat' => ['name' => '有效未加微', 'show' => 1, 'width' => 100, 'parent' => 'customer', 'sort' => 19],
- 'measuring_room_customer_no_to_store' => ['name' => '量房未到店', 'show' => 1, 'width' => 100, 'parent' => 'customer', 'sort' => 20],
- 'drawing_date_count' => ['name' => '户型图', 'show' => 1, 'width' => 100, 'parent' => 'customer', 'sort' => 21],
- 'measuring_room_customer' => ['name' => '量房数量', 'show' => 1, 'width' => 100, 'parent' => 'customer', 'sort' => 22],
- 'measuring_room_zhouqi' => ['name' => '平均量房周期', 'show' => 1, 'width' => 130, 'parent' => 'customer', 'sort' => 23],
- 'measuring_room_grawth' => ['name' => '量房率', 'show' => 1, 'width' => 100, 'parent' => 'customer', 'sort' => 24],
- 'yuji_store' => ['name' => '预计到店数', 'show' => 1, 'width' => 100, 'parent' => 'customer', 'sort' => 25],
- 'to_the_store_1' => ['name' => '一次到店', 'show' => 1, 'width' => 100, 'parent' => 'daodian_count', 'sort' => 26],
- 'to_the_store_2' => ['name' => '二次到店', 'show' => 1, 'width' => 100, 'parent' => 'daodian_count', 'sort' => 27],
- 'strtore_2v1' => ['name' => '二访比率', 'show' => 1, 'width' => 100, 'parent' => 'daodian_count', 'sort' => 28],
- 'to_the_store_3' => ['name' => '三次及以上到店', 'show' => 1, 'width' => 130, 'parent' => 'daodian_count', 'sort' => 28],
- 'strtore_avg_days_1' => ['name' => '平均一次到店周期', 'show' => 1, 'width' => 150, 'parent' => 'daodian_avg', 'sort' => 29],
- 'strtore_avg_days_2' => ['name' => '平均二次到店周期', 'show' => 1, 'width' => 150, 'parent' => 'daodian_avg', 'sort' => 30],
- 'strtore_avg_days_3' => ['name' => '平均三次及以上到店周期', 'show' => 1, 'width' => 200, 'parent' => 'daodian_avg', 'sort' => 31],
- 'strtore_count_1_grawth' => ['name' => '一次到店率', 'show' => 1, 'width' => 100, 'parent' => 'daodian_grawth', 'sort' => 32],
- 'strtore_count_2_grawth' => ['name' => '二次到店率', 'show' => 1, 'width' => 100, 'parent' => 'daodian_grawth', 'sort' => 33],
- 'strtore_count_3_grawth' => ['name' => '三次及以上到店率', 'show' => 1, 'width' => 150, 'parent' => 'daodian_grawth', 'sort' => 34],
- 'avg_room_store_zhouqi' => ['name' => '平均量房到店周期', 'show' => 1, 'width' => 170, 'parent' => 'customer', 'sort' => 35],
- 'strtore_deposit_count_0' => ['name' => '一次到店签单数量', 'show' => 1, 'width' => 150, 'parent' => 'daodian_deposit', 'sort' => 36],
- 'strtore_deposit_count_1' => ['name' => '二次到店签单数量', 'show' => 1, 'width' => 150, 'parent' => 'daodian_deposit', 'sort' => 37],
- 'strtore_deposit_count_2' => ['name' => '三次到及以上店签单数量', 'show' => 1, 'width' => 200, 'parent' => 'daodian_deposit', 'sort' => 38],
- 'strtore_deposit_grawth_0' => ['name' => '一次到店签单率', 'show' => 1, 'width' => 130, 'parent' => 'daodian_deposit_grawth', 'sort' => 39],
- 'strtore_deposit_grawth_1' => ['name' => '二次到店签单率', 'show' => 1, 'width' => 130, 'parent' => 'daodian_deposit_grawth', 'sort' => 40],
- 'strtore_deposit_grawth_2' => ['name' => '三次到及以上店签单率', 'show' => 1, 'width' => 180, 'parent' => 'daodian_deposit_grawth', 'sort' => 41],
- 'deposit_avg_days' => ['name' => '平均签单周期', 'show' => 1, 'width' => 135, 'parent' => 'customer', 'sort' => 42],
- 'sign_count' => ['name' => '转单数量', 'show' => 1, 'width' => 100, 'parent' => 'customer', 'sort' => 43],
- 'sign_count_grawth' => ['name' => '转单率', 'show' => 1, 'width' => 100, 'parent' => 'customer', 'sort' => 44],
- 'avg_visit_count' => ['name' => '平均回访次数', 'show' => 1, 'width' => 130, 'parent' => 'customer', 'sort' => 45],
- 'signed_money' => ['name' => '平均合同金额', 'show' => 1, 'width' => 130, 'parent' => 'customer', 'sort' => 46],
- 'square_0_80' => ['name' => '80以下', 'show' => 1, 'width' => 100, 'parent' => 'area', 'sort' => 47],
- 'square_80_100' => ['name' => '81-100', 'show' => 1, 'width' => 100, 'parent' => 'area', 'sort' => 48],
- 'square_100_120' => ['name' => '101-120', 'show' => 1, 'width' => 100, 'parent' => 'area', 'sort' => 49],
- 'square_120_200' => ['name' => '121-200', 'show' => 1, 'width' => 100, 'parent' => 'area', 'sort' => 50],
- 'square_200_500' => ['name' => '201-500', 'show' => 1, 'width' => 100, 'parent' => 'area', 'sort' => 51],
- 'square_500' => ['name' => '500以上', 'show' => 1, 'width' => 100, 'parent' => 'area', 'sort' => 52],
- 'existing_homes_count' => ['name' => '现房数量', 'show' => 1, 'width' => 100, 'parent' => 'house', 'sort' => 53],
- 'forward_housing_count' => ['name' => '期房数量', 'show' => 1, 'width' => 100, 'parent' => 'house', 'sort' => 54],
- ];
- //网销端已增加type值到10,如增加type请往10后面加
- $root_id = request()->employee->root_id;
- //房屋状态是否开启
- $house_status_where = [
- ['root_id', '=', $root_id],
- ['keyname', '=', 'house_status'],
- ['status', '=', 0]
- ];
- $house_status_per = CustomerPortraitField::where($house_status_where)->findOrEmpty();
- $house_field = [];
- if (!$house_status_per->isEmpty()) {
- $field = CustomerPortraitFieldSelect::where('pid', $house_status_per->id)->column('name,id');
- $fields = [];
- foreach ($field as $v) {
- $fields['house_status_' . $v['id']] = [
- 'name' => $v['name'],
- 'show' => 1,
- 'width' => 100,
- 'parent' => 'house',
- 'sort' => 50
- ];
- }
- $house_field = $fields;
- }
- $type5_2 = array_merge($type5_2, $house_field);
- $type5_3 = array_merge($type5_3, $house_field);
- // 户型
- $housetype_where = [
- ['root_id', '=', $root_id],
- ['keyname', '=', 'housetype_arrow'],
- ['status', '=', 0]
- ];
- $housetype_per = CustomerPortraitField::where($housetype_where)->findOrEmpty();
- $housetype_field = [];
- $housetype_done_field = [];
- if (!$housetype_per->isEmpty()) {
- $field = CustomerPortraitFieldSelect::where('pid', $housetype_per->id)->column('name,id');
- $fields = [];
- $fields_done = [];
- foreach ($field as $v) {
- $fields['housetype_arrow_' . $v['id']] = [
- 'name' => $v['name'],
- 'show' => 1,
- 'width' => 100,
- 'parent' => 'house',
- 'sort' => 51
- ];
- $fields_done['housetype_arrow_lv_' . $v['id']] = [
- 'name' => $v['name'] . '成交率',
- 'show' => 1,
- 'width' => 150,
- 'parent' => 'house',
- 'sort' => 51
- ];
- }
- $housetype_field = $fields;
- $housetype_done_field = $fields_done;
- }
- $type5_2 = array_merge($type5_2, $housetype_field);
- $type5_3 = array_merge($type5_3, $housetype_field);
- $type5_2 = array_merge($type5_2, $housetype_done_field);
- $type5_3 = array_merge($type5_3, $housetype_done_field);
- //无效客资
- $invalid_customer = Setting::where([['name', '=', 'clueTag'], ['root_id', '=', $root_id]])->value('content');
- if ($invalid_customer) {
- $invalid_arr = explode(',', $invalid_customer);
- } else {
- $invalid_arr = ['已装修', '无需求', '有需求', '超地域', '未交房', '在外地', '无购买力', '未接通电话'];
- }
- $invalid_field = [];
- foreach ($invalid_arr as $k => $v) {
- $invalid_field['invalid_customer_' . $k] = [
- 'name' => $v,
- 'show' => 1,
- 'width' => 100,
- 'parent' => 'died_customer',
- 'sort' => 55
- ];
- }
- $new_type_5_3 = [];
- foreach ($type5_3 as $k => $v) {
- $new_type_5_3[$k] = $v;
- if ($k == 'signed_money') {
- $new_type_5_3 = array_merge($new_type_5_3, $invalid_field);
- }
- }
- $type5_3 = $new_type_5_3;
- // 管理层户型分布
- $new_type_3 = [];
- foreach ($type3 as $k => $v) {
- $new_type_3[$k] = $v;
- if ($k == 'area') {
- $new_type_3 = array_merge($new_type_3, $house_field);
- }
- }
- switch ($type) {
- case 1: // 行为统计全部字段
- return $type1;
- break;
- case 2: // 高层统计全部字段
- return $type2;
- break;
- case 3: // 管理层统计全部字段
- return $type3;
- break;
- case 4: // 客户统计列表
- return $type4;
- break;
- case 5: // 总统计
- return $type5_3;
- break;
- default:
- return [];
- break;
- }
- }
- /**
- * 统计表字段
- */
- public function fieldList($type = 0, $is_org = 0)
- {
- $field = $this->statisticsFields($type);
- $root_id = request()->employee->root_id;
- $employee_id = request()->employee->id;
- $save_field = StatisticsSetting::where([['root_id', '=', $root_id], ['employee_id', '=', $employee_id], ['type', '=', $type]])->findOrEmpty();
- if (!$save_field->isEmpty()) {
- $save_content = json_decode($save_field['content'], true);
- if (!empty($save_content)) {
- foreach ($save_content as $k => $v) {
- if (isset($field[$k])) {
- $field[$k]['show'] = $v['show'];
- $field[$k]['sort'] = $v['sort'];
- }
- }
- array_multisort(array_column($field, 'sort'), SORT_ASC, $field);
- }
- }
- if ($type == 5) {
- if ($is_org == 1) {
- $field_5['org_name'] = ['name' => '部门名称', 'show' => 1, 'width' => 100, 'sort' => 1];
- foreach ($field as $k => $v) {
- if ($k == 'name' || $k == 'org_name' || $k == 'look_data') {
- unset($field[$k]);
- }
- }
- $field_5 = array_merge($field_5, $field);
- $field = $field_5;
- } else {
- $field_5['name'] = [];
- $field_5['org_name'] = [];
- foreach ($field as $k => $v) {
- if (isset($field_5[$k])) {
- $field_5[$k] = $v;
- unset($field[$k]);
- }
- }
- $field_5 = array_merge($field_5, $field);
- $field = $field_5;
- }
- }
- return json(['code' => 0, 'data' => $field, 'msg' => 'success']);
- }
- /**
- * 统计字段展示设置
- */
- public function fieldSetting()
- {
- $type = input('type', '', 'intval'); // 类型
- $content = input('content', '', 'trim'); // 内容
- $content = json_decode($content, true);
- $default_field = $this->statisticsFields($type);
- $root_id = request()->employee->root_id;
- $employee_id = request()->employee->id;
- $find = StatisticsSetting::where([['root_id', '=', $root_id], ['employee_id', '=', $employee_id], ['type', '=', $type]])->findOrEmpty();
- foreach ($content as $k => $v) {
- if (isset($v['name']) && isset($v['show']) && isset($v['sort']) && isset($default_field[$v['name']])) {
- $default_field[$v['name']]['show'] = $v['show'];
- $default_field[$v['name']]['sort'] = $v['sort'];
- }
- }
- $save_content = json_encode($default_field);
- if ($find->isEmpty()) {
- $result = StatisticsSetting::insert(['root_id' => $root_id, 'employee_id' => $employee_id, 'type' => $type, 'content' => $save_content]);
- } else {
- $find->content = $save_content;
- $find->save();
- }
- return json(['code' => 0, 'data' => [], 'msg' => '设置成功']);
- }
- /**
- * 导出记录
- */
- public function export2($m)
- {
- $typeList = ['behaviorStatisticsData' => ['type' => 1], 'highBehaviorStatisticsData' => ['type' => 2], 'manageStatisticsData' => ['type' => 3], 'customer_list_data' => ['type' => 4], 'generalStatisticsData' => ['type' => 5, 'is_org' => 2]];
- if (!isset($typeList[$m])) {
- json(['code' => 1, 'msg' => '类型不存在'])->send();
- return;
- }
- $param = Request::post();
- $filename = uniqid();
- $log = [
- 'root_id' => request()->employee->root_id,
- 'file' => $filename . '.csv',
- 'type' => $m,
- 'employee_id' => request()->employee->id,
- 'search' => json_encode($param)
- ];
- $exportLog = ExportLog::create($log);
- json(['code' => 0, 'msg' => '导出中,请稍后在记录中查看'])->send();
- $type = $typeList[$m]['type'];
- $is_org = isset($typeList[$m]['is_org']) ? $typeList[$m]['is_org'] : 0;
- $c = $this->fieldList($type, $is_org);
- $c = $c->getData();
- $title = $c['data'];
- array_multisort(array_column($title, 'sort'), $title);
- touch('../download/' . $filename . '.csv');
- $fp = fopen('../download/' . $filename . '.csv', 'a');
- $t = [];
- foreach ($title as $ti) {
- $t[] = $ti['name'];
- }
- fputcsv($fp, $t);
- $n = 2000;
- $p = 1;
- do {
- $data = $this->$m($p, $n);
- $data = $data->getData();
- foreach ($data['data'] as $row) {
- $r = [];
- foreach ($title as $k => $f) {
- $r[] = isset($row[$k]) ? $row[$k] : '';
- }
- fputcsv($fp, $r);
- }
- $p++;
- } while ($n * ($p - 1) < $data['count']);
- fclose($fp);
- // 文件上传
- $rs = ossUpload('statisticsExport/' . $filename . '.csv', '../download/' . $filename . '.csv');
- if ($rs) {
- unlink('../download/' . $filename . '.csv');
- }
- $exportLog->save(['state' => 1]);
- }
- public function exportList2($type)
- {
- if (!request()->isAjax()) {
- return View::fetch();
- }
- $where = [
- ['type', '=', $type],
- ['root_id', '=', request()->employee->root_id]
- ];
- $data = ExportLog::with(['employee' => function ($query) {
- $query->bind(['opt_name']);
- }])->field('id,state,employee_id,addtime,file')->where($where)->order('addtime desc')->select();
- $count = ExportLog::where($where)->count();
- return json(['code' => 0, 'count' => $count, 'data' => $data]);
- }
- public function export3($m)
- {
- // $param = Request::get();
- // $filename = uniqid();
- // $log = [
- // 'root_id' => request()->employee->root_id,
- // 'file' => $filename . '.csv',
- // 'type' => $m,
- // 'employee_id' => request()->employee->id,
- // 'search' => json_encode($param)
- // ];
- // $exportLog = ExportLog::create($log);
- return json(['code' => 0, 'msg' => '1111'])->send();
- $type = $typeList[$m]['type'];
- $is_org = isset($typeList[$m]['is_org']) ? $typeList[$m]['is_org'] : 0;
- $c = $this->fieldList($type, $is_org);
- $c = $c->getData();
- $title = $c['data'];
- array_multisort(array_column($title, 'sort'), $title);
- touch('../download/' . $filename . '.csv');
- $fp = fopen('../download/' . $filename . '.csv', 'a');
- $t = [];
- foreach ($title as $ti) {
- $t[] = $ti['name'];
- }
- fputcsv($fp, $t);
- $n = 2000;
- $p = 1;
- do {
- $data = $this->$m($p, $n);
- $data = $data->getData();
- foreach ($data['data'] as $row) {
- $r = [];
- foreach ($title as $k => $f) {
- $r[] = isset($row[$k]) ? $row[$k] : '';
- }
- fputcsv($fp, $r);
- }
- $p++;
- } while ($n * ($p - 1) < $data['count']);
- fclose($fp);
- // 文件上传
- $rs = ossUpload('statisticsExport/' . $filename . '.csv', '../download/' . $filename . '.csv');
- if ($rs) {
- unlink('../download/' . $filename . '.csv');
- }
- $exportLog->save(['state' => 1]);
- }
- }
|