NewsService.php 246 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Article;
  4. use App\Model\ArticleData;
  5. use App\Model\Category;
  6. use App\Model\HistoryToday;
  7. use App\Model\WebsiteCategory;
  8. use App\Model\ArticleSurvey;
  9. use App\Model\District;
  10. use App\Model\Good;
  11. use App\Model\JobCompany;
  12. use App\Model\Website;
  13. use App\Model\JobRecruiting;
  14. use App\Model\JobIndustry;
  15. use App\Model\Book;
  16. use App\Model\JobPosition;
  17. use App\Model\Notice;
  18. use App\Model\JobNature;
  19. use App\Model\JobEnum;
  20. use App\Model\User;
  21. use App\Model\UserRole;
  22. use App\Model\News;
  23. use App\Model\UserInfo;
  24. use App\Model\WebsiteGroup;;
  25. use App\Model\JobResume;
  26. use Hyperf\DbConnection\Db;
  27. use Hyperf\RpcServer\Annotation\RpcService;
  28. use App\Tools\Result;
  29. use Directory;
  30. use Ramsey\Uuid\Uuid;
  31. use Hyperf\Utils\Random;
  32. use Fukuball\Jieba\Jieba;
  33. use Fukuball\Jieba\Finalseg;
  34. use Hyperf\Utils\Collection;
  35. use function Hyperf\Support\retry;
  36. use App\Tools\PublicData;
  37. use App\Model\ChatGroups;
  38. use App\Model\ChatGroupsMember;
  39. use App\Model\ChatRecords;
  40. use App\Model\Complaint;
  41. use Hamcrest\Arrays\IsArray;
  42. use Hyperf\Codec\Json;
  43. use App\Tools\buildMenuTree;
  44. use App\Model\JobApply;
  45. use App\Model\JobHunting;
  46. use App\Model\JobRemuse;
  47. use Hyperf\Redis\Redis;
  48. use Hyperf\Di\Annotation\Inject;
  49. use App\Model\Festival;
  50. use App\Model\Character;
  51. use App\Model\Couplet;
  52. use App\Model\Riddle;
  53. use App\Model\Idiom;
  54. use App\Model\WhiteRouter;
  55. use Illuminate\Support\Facades\Cache;
  56. use App\Model\Company;
  57. use Hyperf\Paginator\Paginator;
  58. use App\Model\Project;
  59. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  60. class NewsService implements NewsServiceInterface
  61. {
  62. #[Inject]
  63. protected Redis $redis;
  64. /**
  65. * 获取导航池列表
  66. * @param array $data
  67. * @return array
  68. */
  69. public function getCategoryList(array $data): array
  70. {
  71. $search = $data['name'] ?? '';
  72. $page = (int)($data['page'] ?? 1);
  73. $perPage = (int)($data['pageSize'] ?? 10);
  74. // 1. 查出所有匹配的分类id
  75. if ($search) {
  76. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  77. if (empty($matchedIds)) {
  78. return Result::success(['rows' => [], 'total' => 0]);
  79. }
  80. // 2. 递归查所有父级,直到一级分类
  81. $idsStr = implode(',', $matchedIds);
  82. $sql = "
  83. WITH RECURSIVE parents AS (
  84. SELECT * FROM category WHERE id IN ($idsStr)
  85. UNION ALL
  86. SELECT c.* FROM category c
  87. INNER JOIN parents p ON c.id = p.pid
  88. )
  89. SELECT * FROM parents
  90. ";
  91. $parents = Db::select($sql);
  92. $parentIds = [];
  93. foreach ($parents as $row) {
  94. if ($row->pid == 0) {
  95. $parentIds[] = $row->id;
  96. }
  97. }
  98. $parentIds = array_unique($parentIds);
  99. } else {
  100. // 没有搜索,一级分类就是根
  101. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  102. }
  103. // 3. 一级分类分页
  104. $total = count($parentIds);
  105. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  106. if (empty($parentIds)) {
  107. return Result::success(['rows' => [], 'total' => $total]);
  108. }
  109. // 4. 递归查所有子孙
  110. $idsStr = implode(',', $parentIds);
  111. $sql = "
  112. WITH RECURSIVE subcategories AS (
  113. SELECT * FROM category WHERE id IN ($idsStr)
  114. UNION ALL
  115. SELECT c.* FROM category c
  116. INNER JOIN subcategories s ON c.pid = s.id
  117. )
  118. SELECT * FROM subcategories ORDER BY updated_at DESC
  119. ";
  120. $allCategories = Db::select($sql);
  121. // 5. 组装树结构
  122. $categoryMap = [];
  123. foreach ($allCategories as $cat) {
  124. $cat = (array)$cat;
  125. $cat['children'] = [];
  126. $categoryMap[$cat['id']] = $cat;
  127. }
  128. foreach ($categoryMap as $id => &$cat) {
  129. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  130. $categoryMap[$cat['pid']]['children'][] = &$cat;
  131. }
  132. }
  133. unset($cat);
  134. $categoryTree = [];
  135. foreach ($parentIds as $id) {
  136. if (isset($categoryMap[$id])) {
  137. $categoryTree[] = $categoryMap[$id];
  138. }
  139. }
  140. return Result::success([
  141. 'rows' => $categoryTree,
  142. 'total' => $total,
  143. ]);
  144. }
  145. private function findMatchedCategories($search)
  146. {
  147. if ($search) {
  148. return Category::where('name', 'like', "%{$search}%")
  149. ->orderBy('updated_at', 'desc')
  150. ->get();
  151. }
  152. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  153. ->get();
  154. }
  155. private function findAllParents($categories)
  156. {
  157. $allCategories = [];
  158. foreach ($categories as $category) {
  159. $parentId = $category->pid;
  160. while ($parentId > 0) {
  161. $parent = Category::find($parentId);
  162. if ($parent) {
  163. $allCategories[$parent->id] = $parent;
  164. $parentId = $parent->pid;
  165. } else {
  166. break;
  167. }
  168. }
  169. $allCategories[$category->id] = $category;
  170. }
  171. return array_values($allCategories);
  172. }
  173. private function buildCategoryTree($category, $allRequiredCategories)
  174. {
  175. $categoryData = $category->toArray();
  176. $children = [];
  177. foreach ($allRequiredCategories as $c) {
  178. if ($c->pid === $category->id) {
  179. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  180. }
  181. }
  182. if (!empty($children)) {
  183. $categoryData['children'] = $children;
  184. }
  185. return $categoryData;
  186. }
  187. public function myCategoryList(array $data): array
  188. {
  189. $sszq = $data['sszq'] ?? '';
  190. unset($data['sszq']);
  191. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  192. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  193. $where[] = [
  194. 'pid',
  195. '=',
  196. $data['pid'],
  197. ];
  198. if (isset($data['name'])) {
  199. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  200. }
  201. var_dump($where);
  202. //根据分类id,从category表中取出分类信息
  203. $result = Category::where($where)
  204. ->whereIn('category.id', $catorytids)
  205. ->select('category.*', 'category.id as category_id')->get();
  206. if (empty($result)) {
  207. return Result::error("没有栏目数据");
  208. }
  209. return Result::success($result);
  210. }
  211. /**
  212. * @param array $data
  213. * @return array
  214. */
  215. public function categoryList(array $data): array
  216. {
  217. $where[] = [
  218. 'pid',
  219. '=',
  220. $data['pid']
  221. ];
  222. if (isset($data['name'])) {
  223. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  224. }
  225. var_dump($where);
  226. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  227. if (empty($result)) {
  228. return Result::error("没有栏目数据");
  229. }
  230. return Result::success($result);
  231. }
  232. /**
  233. * @param array $data
  234. * @return array
  235. */
  236. public function addCategory(array $data): array
  237. {
  238. if (isset($data['id'])) {
  239. unset($data['id']);
  240. }
  241. $id = Category::insertGetId($data);
  242. if (empty($id)) {
  243. return Result::error("添加失败");
  244. }
  245. return Result::success(['id' => $id]);
  246. }
  247. /**
  248. * @param array $data
  249. * @return array
  250. */
  251. public function delCategory(array $data): array
  252. {
  253. Db::beginTransaction();
  254. try {
  255. $categoryList = Category::where(['pid' => $data['id']])->get();
  256. if ($categoryList->toArray()) {
  257. Db::rollBack();
  258. return Result::error("分类下面有子分类不能删除");
  259. }
  260. $articleList = Article::where(['catid' => $data['id']])->get();
  261. if ($articleList->toArray()) {
  262. Db::rollBack();
  263. return Result::error("分类下面有资讯不能删除");
  264. }
  265. $result = Category::where($data)->delete();
  266. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  267. if (!$result) {
  268. Db::rollBack();
  269. return Result::error("删除失败");
  270. }
  271. Db::commit();
  272. return Result::success($result);
  273. } catch (\Exception $e) {
  274. Db::rollBack();
  275. return Result::error("删除失败" . $e->getMessage());
  276. }
  277. }
  278. /**
  279. * @param array $data
  280. * @return array
  281. */
  282. public function updateCategory(array $data): array
  283. {
  284. $where = [
  285. 'id' => $data['id'],
  286. ];
  287. $result = Category::where($where)->update($data);
  288. if ($result) {
  289. return Result::success($result);
  290. } else {
  291. return Result::error("更新失败");
  292. }
  293. }
  294. /**
  295. * 获取导航池信息
  296. * @param array $data
  297. * @return array
  298. */
  299. public function getCategoryInfo(array $data): array
  300. {
  301. $where = [
  302. 'id' => $data['id'],
  303. ];
  304. $result = Category::where($where)->first();
  305. if ($result) {
  306. return Result::success($result);
  307. } else {
  308. return Result::error("更新失败");
  309. }
  310. }
  311. /**
  312. * @param array $data
  313. * @return array
  314. */
  315. public function getArticleList(array $data): array
  316. {
  317. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  318. $type_id = $data['type_id'];
  319. unset($data['type_id']);
  320. $user_id = $data['user_id'];
  321. unset($data['user_id']);
  322. $where = [];
  323. $status1 = [];
  324. if (isset($data['id']) && $data['id']) {
  325. array_push($where, ['article.id', '=', $data['id']]);
  326. }
  327. if (isset($data['title']) && $data['title']) {
  328. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  329. }
  330. if (isset($data['category_name']) && $data['category_name']) {
  331. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  332. }
  333. if (isset($data['author']) && $data['author']) {
  334. array_push($where, ['article.author', '=', $data['author']]);
  335. }
  336. if (isset($data['islink']) && $data['islink'] !== "") {
  337. array_push($where, ['article.islink', '=', $data['islink']]);
  338. }
  339. if (isset($data['status']) && $data['status'] !== "") {
  340. array_push($where, ['article.status', '=', $data['status']]);
  341. }
  342. if (isset($data['status1'])) {
  343. $status1 = json_decode(($data['status1']));
  344. }
  345. //不是管理员展示个人数据;
  346. if ($type_id != 10000) {
  347. $where[] = ['article.admin_user_id', '=', $user_id];
  348. }
  349. $rep = Article::where($where)
  350. ->whereNotIn('article.status', [404])
  351. ->when($status1, function ($query) use ($status1) {
  352. if (isset($status1) && $status1) {
  353. $query->whereIn('article.status', $status1);
  354. }
  355. })
  356. ->leftJoin('category', 'article.catid', 'category.id')
  357. ->leftJoin('website_category', function ($join) {
  358. $join->on('article.web_site_id', '=', 'website_category.website_id')
  359. ->on('article.catid', '=', 'website_category.category_id');
  360. })
  361. ->select("article.*", "category.name as category_name", "website_category.alias")
  362. ->orderBy("article.updated_at", "desc")
  363. ->limit($data['pageSize'])
  364. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  365. $count = Article::where($where)->whereNotIn('article.status', [404])
  366. ->when($status1, function ($query) use ($status1) {
  367. if (isset($status1) && $status1) {
  368. $query->whereIn('article.status', $status1);
  369. }
  370. })
  371. ->leftJoin('category', 'article.catid', 'category.id')->count();
  372. $data = [
  373. 'rows' => $rep->toArray(),
  374. 'count' => $count,
  375. ];
  376. if (empty($rep)) {
  377. return Result::error("没有信息数据");
  378. }
  379. return Result::success($data);
  380. }
  381. /**
  382. * @param array $data
  383. * @return array
  384. */
  385. public function addArticle(array $data): array
  386. {
  387. var_dump($data, '----------12-----------1');
  388. unset($data['user_type']);
  389. unset($data['nav_add_pool_id']);
  390. // unset($data['commend_id']);
  391. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  392. Db::beginTransaction();
  393. try {
  394. //处理投票
  395. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  396. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  397. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  398. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  399. unset($data['is_survey']);
  400. unset($data['survey_name']);
  401. unset($data['suvey_array']);
  402. // unset($data['website_id']);
  403. // unset($data['web_site_id']);
  404. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  405. if ($data['hits'] == '') {
  406. $data['hits'] = 0;
  407. }
  408. if ($data['is_original'] == '') {
  409. $data['is_original'] = 0;
  410. }
  411. if ($data['status'] == '') {
  412. $data['status'] = 0;
  413. }
  414. $articleData = $data;
  415. unset($articleData['content']);
  416. //自动处理缩略图、关键字、描述
  417. if ($articleData['imgurl'] == '') {
  418. //如果没有图,设置level=0
  419. $levelArr = json_decode($articleData['level'], true);
  420. var_dump($levelArr, '----------levelArr-----------1');
  421. //content中提取图片第一个图,正则提取
  422. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  423. preg_match_all($reg, $data['content'], $matches);
  424. if (isset($matches[1][0])) {
  425. //截取varchar240
  426. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  427. //如果有图,设置level=3
  428. if (!in_array(3, $levelArr)) {
  429. $levelArr[] = 3;
  430. }
  431. $articleData['level'] = json_encode($levelArr);
  432. } else {
  433. if (!in_array(0, $levelArr)) {
  434. $levelArr[] = 0;
  435. }
  436. $articleData['level'] = json_encode($levelArr);
  437. }
  438. }
  439. var_dump($articleData['level'], '----------$articleData[level]----------1');
  440. if ($articleData['keyword'] == '') {
  441. //提取标题+内容中的关键词
  442. $articleData['keyword'] = $data['title'];
  443. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  444. Jieba::init(); // 初始化 jieba-php
  445. Finalseg::init();
  446. $segList = Jieba::cut($articleData['keyword']);
  447. $segList1 = array_slice($segList, 0, 8);
  448. $articleData['keyword'] = implode(',', $segList1);
  449. }
  450. if ($articleData['introduce'] == '') {
  451. //提取内容中的描述
  452. $articleData['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  453. }
  454. $id = Article::insertGetId($articleData);
  455. $articleDataContent = [
  456. 'article_id' => $id,
  457. 'content' => $data['content'],
  458. ];
  459. ArticleData::insertGetId($articleDataContent);
  460. //处理投票
  461. if ($is_survey == 1) {
  462. //生成年月日时分秒+8位随机数
  463. $uuid = date('YmdHis') . rand(10000000, 99999999);
  464. var_dump($suvey_array, 'suvey_array________');
  465. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  466. var_dump($suveys_array, '---------------------1');
  467. var_dump($suvey_array, '---------------------2');
  468. $suvey_data = [];
  469. foreach ($suveys_array as $key => $value) {
  470. if ($value == '') {
  471. continue;
  472. }
  473. if (is_array($value)) {
  474. $suvey_data[] = [
  475. 'sur_id' => $uuid,
  476. 'art_id' => $id,
  477. 'website_id' => $website_id ?? 2,
  478. 'survey_name' => $survey_name,
  479. 'choice_name' => $value[1],
  480. 'is_other' => 1,
  481. 'other_id' => 0,
  482. 'results' => 0,
  483. ];
  484. } else {
  485. $suvey_data[] = [
  486. 'sur_id' => $uuid,
  487. 'art_id' => $id,
  488. 'website_id' => $website_id ?? 2,
  489. 'survey_name' => $survey_name,
  490. 'choice_name' => $value,
  491. 'is_other' => 0,
  492. 'other_id' => 0,
  493. 'results' => 0,
  494. ];
  495. }
  496. if (empty($suvey_data)) {
  497. throw new \Exception("投票数据为空");
  498. }
  499. }
  500. $result = ArticleSurvey::insert($suvey_data);
  501. if (!$result) {
  502. throw new \Exception("投票失败,ArticleSurvey插入失败");
  503. }
  504. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  505. if (!$result) {
  506. throw new \Exception("投票失败,更新主表失败");
  507. }
  508. }
  509. Db::commit();
  510. return Result::success(['id' => $id]);
  511. } catch (\Throwable $ex) {
  512. Db::rollBack();
  513. var_dump($ex->getMessage());
  514. return Result::error("创建失败", 0);
  515. }
  516. }
  517. /**
  518. * @param array $data
  519. * @return array
  520. */
  521. public function delArticle(array $data): array
  522. {
  523. $result = Article::where($data)->delete();
  524. //survey投票删除
  525. articleSurvey::where(['art_id' => $data['id']])->delete();
  526. if (!$result) {
  527. return Result::error("删除失败");
  528. }
  529. return Result::success($result);
  530. }
  531. /**
  532. * @param array $data
  533. * @return array
  534. */
  535. public function updateArticle(array $data): array
  536. {
  537. var_dump($data, '----------12-----------1');
  538. Db::beginTransaction();
  539. unset($data['user_type']);
  540. // unset($data['web_site_id']);
  541. unset($data['nav_add_pool_id']);
  542. try {
  543. //处理投票
  544. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  545. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  546. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  547. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  548. unset($data['is_survey']);
  549. unset($data['survey_name']);
  550. unset($data['suvey_array']);
  551. unset($data['website_id']);
  552. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  553. if ($data['hits'] == '') {
  554. $data['hits'] = 0;
  555. }
  556. if ($data['is_original'] == '') {
  557. $data['is_original'] = 0;
  558. }
  559. if ($data['status'] == '') {
  560. $data['status'] = 0;
  561. }
  562. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  563. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  564. $articleData = $data;
  565. unset($articleData['content']);
  566. unset($articleData['status_name']);
  567. unset($articleData['name']);
  568. unset($articleData['content']);
  569. unset($articleData['pid_arr']);
  570. unset($articleData['pid']);
  571. //自动处理缩略图、关键字、描述
  572. if ($articleData['imgurl'] == '') {
  573. //如果没有图,设置level=0
  574. $levelArr = json_decode($articleData['level'], true);
  575. var_dump($levelArr, '----------levelArr-----------1');
  576. //content中提取图片第一个图,正则提取
  577. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  578. preg_match_all($reg, $data['content'], $matches);
  579. if (isset($matches[1][0])) {
  580. //截取varchar240
  581. // 截取到第一个<
  582. $articleData['imgurl'] = $matches[1][0];
  583. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  584. $pos = strpos($articleData['imgurl'], '"');
  585. if ($pos !== false) {
  586. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  587. }
  588. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  589. //如果有图,设置level=3
  590. if (!in_array(3, $levelArr)) {
  591. $levelArr[] = 3;
  592. }
  593. $articleData['level'] = json_encode($levelArr);
  594. } else {
  595. if (!in_array(0, $levelArr)) {
  596. $levelArr[] = 0;
  597. }
  598. $articleData['level'] = json_encode($levelArr);
  599. }
  600. }
  601. var_dump($articleData['level'], '----------$articleData[level]----------1');
  602. if ($articleData['keyword'] == '') {
  603. //提取标题+内容中的关键词
  604. $articleData['keyword'] = $data['title'];
  605. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  606. Jieba::init(); // 初始化 jieba-php
  607. Finalseg::init();
  608. $segList = Jieba::cut($articleData['keyword']);
  609. $segList1 = array_slice($segList, 0, 8);
  610. $articleData['keyword'] = implode(',', $segList1);
  611. }
  612. if ($articleData['introduce'] == '') {
  613. //提取内容中的描述
  614. $articleData['introduce'] = substr(preg_replace('/\s+/', '', strip_tags($data['content'])), 0, 100);
  615. // substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  616. }
  617. $id = Article::where(['id' => $data['id']])->update($articleData);
  618. $articleDataContent = [
  619. 'content' => $data['content'],
  620. ];
  621. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  622. //处理投票
  623. $id = $data['id'];
  624. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  625. var_dump($suvey_array, 'suvey_array________delete');
  626. //处理投票
  627. if ($is_survey == 1) {
  628. //生成年月日时分秒+8位随机数
  629. $uuid = date('YmdHis') . rand(10000000, 99999999);
  630. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  631. var_dump($suveys_array, '---------------------1');
  632. $suvey_data = [];
  633. if (is_array($suveys_array)) {
  634. foreach ($suveys_array as $key => $value) {
  635. if ($value == '') {
  636. continue;
  637. }
  638. if (is_array($value)) {
  639. $suvey_data[] = [
  640. 'sur_id' => $uuid,
  641. 'art_id' => $id,
  642. 'website_id' => $website_id ?? 2,
  643. 'survey_name' => $survey_name,
  644. 'choice_name' => $value[1],
  645. 'is_other' => 1,
  646. 'other_id' => 0,
  647. 'results' => 0,
  648. ];
  649. } else {
  650. $suvey_data[] = [
  651. 'sur_id' => $uuid,
  652. 'art_id' => $id,
  653. 'website_id' => $website_id ?? 2,
  654. 'survey_name' => $survey_name,
  655. 'choice_name' => $value,
  656. 'is_other' => 0,
  657. 'other_id' => 0,
  658. 'results' => 0,
  659. ];
  660. }
  661. if (empty($suvey_data)) {
  662. throw new \Exception("投票数据为空");
  663. }
  664. }
  665. }
  666. $result = ArticleSurvey::insert($suvey_data);
  667. if (!$result) {
  668. throw new \Exception("投票失败");
  669. }
  670. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  671. if (!$result) {
  672. throw new \Exception("投票失败");
  673. }
  674. } else {
  675. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  676. }
  677. Db::commit();
  678. return Result::success([]);
  679. } catch (\Throwable $ex) {
  680. Db::rollBack();
  681. var_dump($ex->getMessage());
  682. return Result::error("更新失败" . $ex->getMessage(), 0);
  683. }
  684. }
  685. /**
  686. * 更新资讯状态
  687. * @param array $data
  688. * @return array
  689. */
  690. public function upArticleStatus(array $data): array
  691. {
  692. $result = Article::where(['id' => $data['id']])->update($data);
  693. if (isset($data['ignore_ids']) && !empty($data['ignore_ids'])) {
  694. //article_ignore 表插入数据 db操作
  695. //转成数组
  696. //删掉数据重新写入
  697. DB::table('article_ignore')->where('article_id', $data['id'])->delete();
  698. $website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  699. $insert_data = [];
  700. foreach ($website_ids as $key => $value) {
  701. $insert_data[] = [
  702. 'article_id' => $data['id'],
  703. 'website_id' => $value,
  704. ];
  705. }
  706. DB::table('article_ignore')->insert($insert_data);
  707. }
  708. if ($result) {
  709. return Result::success();
  710. } else {
  711. return Result::error("更新状态失败", 0);
  712. }
  713. }
  714. /**
  715. * 获取新闻详情
  716. * @param array $data
  717. * @return array
  718. */
  719. public function getArticleInfo(array $data): array
  720. {
  721. $where = [
  722. 'article.id' => $data['id'],
  723. // 'article.status' => 1,
  724. ];
  725. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  726. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  727. $info = $result;
  728. // var_dump($info, 'info');
  729. $info['survey_array'] = $articleSurvey;
  730. if ($result) {
  731. return Result::success($info);
  732. } else {
  733. return Result::error("查询失败", 0);
  734. }
  735. }
  736. /**
  737. * 获取头条新闻
  738. * @param array $data
  739. * @return array
  740. */
  741. public function getWebsiteArticlett(array $data): array
  742. {
  743. $website_id = $data['website_id'];
  744. $categorys = $this->processArticlePro($website_id);
  745. $catiall = $categorys['catiall'];
  746. $categoryIds = $categorys['categoryIds'];
  747. $where = [
  748. 'status' => 1
  749. ];
  750. $website_id = $data['website_id'];
  751. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  752. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  753. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  754. switch ($data['level']) {
  755. case 1:
  756. case 2:
  757. case 3:
  758. case 6:
  759. $query = Article::where($where)
  760. ->where('level', 'like', '%' . $data['level'] . '%')
  761. ->orderBy('updated_at', 'desc');
  762. break;
  763. case 4:
  764. $query = Article::where($where)
  765. ->where('updated_at', '>', $month);
  766. break;
  767. case 5:
  768. $query = Article::where($where)->orderBy('updated_at', 'desc');;
  769. break;
  770. case 7:
  771. if (isset($data['id']) && !empty($data['id'])) {
  772. $keyword = Article::where('id', $data['id'])->value('keyword');
  773. $keywordArray = explode(',', $keyword);
  774. $whereL7 = [];
  775. foreach ($keywordArray as $k => $v) {
  776. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  777. }
  778. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  779. break;
  780. } else {
  781. return Result::error("请输入资讯ID", 0);
  782. break;
  783. }
  784. default:
  785. break;
  786. }
  787. // $whereL7 = [];
  788. // if(isset($data['id']) && !empty($data['id'])){
  789. // $keyword = Article::where('id', $data['id'])->value('keyword');
  790. // $keywordArray = explode(',', $keyword);
  791. // foreach ($keywordArray as $k => $v) {
  792. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  793. // }
  794. // }
  795. // $query = Article::where($where)
  796. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  797. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  798. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  799. // }
  800. // if($data['level'] == 7){
  801. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  802. // }
  803. // if($data['level'] == 4){
  804. // $query = $query->inRandomOrder()
  805. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  806. // }
  807. // if($data['level'] == 5){
  808. // $query = $query->orderBy('updated_at','desc');
  809. // }
  810. // });
  811. if ($data['textnum'] > 0) {
  812. $query = clone $query;
  813. $result['text'] = $query
  814. ->whereIn('catid', $categoryIds)
  815. ->leftJoinSub(function ($query) use ($website_id) {
  816. $query->from('article_ignore')
  817. ->where('website_id', $website_id);
  818. }, 'article_ignore', function ($join) {
  819. $join->on('article_ignore.article_id', '=', 'article.id');
  820. })
  821. ->where(function ($query) use ($website_id) {
  822. $query->whereNull('article_ignore.article_id')
  823. ->orWhere('article_ignore.website_id', '!=', $website_id);
  824. })
  825. ->select(
  826. 'article.id',
  827. 'article.title',
  828. 'article.author',
  829. 'article.updated_at',
  830. 'article.introduce',
  831. 'article.islink',
  832. 'article.linkurl',
  833. 'article.copyfrom',
  834. 'article.cat_arr_id',
  835. 'article.catid',
  836. 'article.level'
  837. )
  838. ->offset($data['placeid'])
  839. ->limit($data['textnum'])
  840. ->get()->all();
  841. foreach ($result['text'] as $k => $v) {
  842. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  843. }
  844. }
  845. if ($data['imgnum'] > 0) {
  846. $query = clone $query;
  847. $result['img'] = $query
  848. ->whereIn('catid', $categoryIds)
  849. ->where('article.imgurl', '!=', '')
  850. ->select(
  851. 'article.id',
  852. 'article.title',
  853. 'article.imgurl',
  854. 'article.author',
  855. 'article.updated_at',
  856. 'article.introduce',
  857. 'article.islink',
  858. 'article.linkurl',
  859. 'article.copyfrom',
  860. 'article.cat_arr_id',
  861. 'article.catid',
  862. 'article.level'
  863. )
  864. ->offset($data['placeid'])
  865. ->limit($data['imgnum'])
  866. ->get()->all();
  867. foreach ($result['img'] as $k => $v) {
  868. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  869. }
  870. }
  871. if (empty($result)) {
  872. return Result::error("暂无相关资讯", 0);
  873. }
  874. return Result::success($result);
  875. }
  876. /**
  877. * 获取模块新闻
  878. * @param array $data
  879. * @return array
  880. */
  881. public function getWebsiteModelArticles(array $data): array
  882. {
  883. $catid = $data['catid'];
  884. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  885. $category = $category->toArray();
  886. if (!empty($category)) {
  887. $where = [
  888. 'status' => 1,
  889. 'catid' => $catid,
  890. ];
  891. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  892. // 1:文字新闻;2:轮播图;3:图文;
  893. // 级别:0:未分类
  894. // 3:推荐图片
  895. if ($data['level'] == 1) {
  896. $data['level'] = 0;
  897. }
  898. $result = Article::where($where)
  899. ->where(function ($query) use ($data) {
  900. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  901. ->orWhereNull("level")
  902. ->orWhereRaw("level = '[]'");
  903. })
  904. ->where(function ($query) use ($data) {
  905. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  906. ->orWhereNull("ignore_ids");
  907. })
  908. ->orderBy("updated_at", "desc")
  909. ->offset($placeid)
  910. ->limit($data['pagesize'])
  911. ->get();
  912. if (empty($result)) {
  913. return Result::error("此栏目暂无相关新闻", 0);
  914. }
  915. } else {
  916. return Result::error("此网站暂无此栏目", 0);
  917. }
  918. return Result::success($result);
  919. }
  920. /**
  921. *获取新闻列表
  922. * @param array $data
  923. * @return array
  924. */
  925. public function getWebsiteArticleList(array $data): array
  926. {
  927. // return Result::success($data);
  928. $where[] = ['status', '=', 1];
  929. $website_id = $data['website_id'];
  930. if (isset($data['catid']) && !empty($data['catid'])) {
  931. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  932. if (empty($category)) {
  933. return Result::error("此网站暂无此栏目", 0);
  934. }
  935. array_push($where, ['catid', '=', $data['catid']]);
  936. }
  937. // return Result::success($where);
  938. $query = Article::where($where)
  939. ->leftJoinSub(function ($query) use ($website_id) {
  940. $query->from('article_ignore')
  941. ->where('website_id', $website_id);
  942. }, 'article_ignore', function ($join) {
  943. $join->on('article_ignore.article_id', '=', 'article.id');
  944. })
  945. ->where(function ($query) use ($website_id) {
  946. $query->whereNull('article_ignore.article_id')
  947. ->orWhere('article_ignore.website_id', '!=', $website_id);
  948. })
  949. ->select(
  950. 'article.id',
  951. 'article.title',
  952. 'article.imgurl',
  953. 'article.author',
  954. 'article.updated_at',
  955. 'article.introduce',
  956. 'article.islink',
  957. 'article.linkurl',
  958. 'article.copyfrom',
  959. 'article.cat_arr_id',
  960. 'article.catid'
  961. );
  962. $count = $query->count();
  963. $rep = $query->orderBy("updated_at", "desc")
  964. ->offset(($data['page'] - 1) * $data['pageSize'])
  965. ->limit($data['pageSize'])
  966. ->get()->all();
  967. $categorys = $this->processArticlePro($website_id);
  968. $cat_1st_arr = $categorys['cat_1st_arr'];
  969. $catiall = $categorys['catiall'];
  970. // $web['website_id'] = $data['website_id'];
  971. foreach ($rep as $k => $v) {
  972. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  973. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  974. }
  975. // $rep = $this->processArticles($rep,$web);
  976. $data = [
  977. 'rows' => $rep,
  978. 'count' => $count,
  979. ];
  980. if (empty($rep)) {
  981. return Result::error("没有信息数据");
  982. }
  983. return Result::success($data);
  984. }
  985. /**
  986. * 前端-获取新闻详情
  987. * @param array $data
  988. * @return array
  989. */
  990. public function selectWebsiteArticleInfo(array $data): array
  991. {
  992. $where = [
  993. 'article.id' => $data['id'],
  994. 'article.status' => 1,
  995. ];
  996. $result = Article::where($where)
  997. ->leftJoin("article_data", "article.id", "article_data.article_id")
  998. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  999. ->where(function ($query) use ($data) {
  1000. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1001. ->orWhereNull("ignore_ids");
  1002. })
  1003. ->first();
  1004. if (empty($result)) {
  1005. return Result::error("暂无此新闻!", 0);
  1006. }
  1007. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1008. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1009. ->where('website_category.website_id', $data['website_id'])
  1010. ->where(['website_category.category_id' => $result['catid']])
  1011. ->first();
  1012. if (empty($category)) {
  1013. return Result::error("查询失败", 0);
  1014. }
  1015. //手动推荐文章
  1016. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1017. $commendArticle = Article::whereIn('id', $commend_ids)
  1018. ->where('status', 1)
  1019. ->select('id', 'title', 'catid', 'imgurl', 'hits', 'created_at')
  1020. ->orderBy('updated_at', 'desc')
  1021. ->limit(5)
  1022. ->get();
  1023. $result['category_id'] = $category['category_id'];
  1024. $result['cat_name'] = $category['alias'];
  1025. $result['website_name'] = $category['website_name'] ?? "";
  1026. $result['suffix'] = $category['suffix'] ?? "";
  1027. $result['commendArticle'] = $commendArticle;
  1028. return Result::success($result);
  1029. }
  1030. /**
  1031. * 前端-获取网站调查问卷
  1032. * @param array $data
  1033. * @return array
  1034. */
  1035. public function getWebsiteSurvey(array $data): array
  1036. {
  1037. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1038. $website = Website::where('id', $data['website_id'])->first();
  1039. if (empty($website)) {
  1040. return Result::error("暂无此网站", 0);
  1041. }
  1042. }
  1043. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1044. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1045. if (empty($article)) {
  1046. return Result::error("暂无此文章", 0);
  1047. }
  1048. // return Result::error($data,0);
  1049. $where['art_id'] = $data['art_id'];
  1050. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1051. } else {
  1052. $survey = Article::where(function ($query) {
  1053. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1054. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1055. })
  1056. ->where('status', 1)
  1057. ->where('is_survey', 1)
  1058. ->select('survey_id')
  1059. ->orderBy('updated_at', 'desc')
  1060. ->first();
  1061. if (empty($survey)) {
  1062. return Result::error("暂无调查问卷", 0);
  1063. }
  1064. $where['sur_id'] = $survey['survey_id'];
  1065. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1066. }
  1067. // return Result::success($where);
  1068. $result = ArticleSurvey::where($where)
  1069. ->where(function ($query) {
  1070. $query->where('is_other', 0)
  1071. ->orWhere(function ($subQuery) {
  1072. $subQuery->where('is_other', 1)
  1073. ->where('other_id', 0);
  1074. });
  1075. })
  1076. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1077. ->select('article_survey.*', 'article.survey_type')
  1078. ->get()->all();
  1079. if (empty($result)) {
  1080. return Result::error("此文章暂无调查问卷", 0);
  1081. }
  1082. return Result::success($result);
  1083. }
  1084. /**
  1085. * 前端-添加网站调查问卷选项
  1086. * @param array $data
  1087. * @return array
  1088. */
  1089. public function addWebsiteSurveyOption(array $data): array
  1090. {
  1091. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1092. $website = Website::where('id', $data['website_id'])->first();
  1093. if (empty($website)) {
  1094. return Result::error("暂无此网站", 0);
  1095. }
  1096. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1097. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1098. if (empty($survey)) {
  1099. return Result::error("此调查问卷不可添加选项", 0);
  1100. }
  1101. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1102. $choice = [
  1103. 'art_id' => $survey['art_id'],
  1104. 'website_id' => $data['website_id'],
  1105. 'survey_name' => $survey['survey_name'],
  1106. 'choice_name' => $data['choice_name'],
  1107. 'sur_id' => $survey['sur_id'],
  1108. 'is_other' => 1,
  1109. 'other_id' => $survey['id'],
  1110. ];
  1111. $result = ArticleSurvey::insertGetId($choice);
  1112. if (empty($result)) {
  1113. return Result::error("添加失败", 0);
  1114. }
  1115. return Result::success($result);
  1116. }
  1117. }
  1118. return Result::error("添加失败", 0);
  1119. }
  1120. return Result::error("添加失败", 0);
  1121. }
  1122. /**
  1123. * 前端-调查问卷投票
  1124. * @param array $data
  1125. * @return array
  1126. */
  1127. public function addWebsiteSurveyVote(array $data): array
  1128. {
  1129. // return Result::success($data);
  1130. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1131. $website = Website::where('id', $data['website_id'])->first();
  1132. if (empty($website)) {
  1133. return Result::error("暂无此网站", 0);
  1134. }
  1135. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1136. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1137. // return Result::success($survey);
  1138. if (empty($is_survey)) {
  1139. return Result::error("此调查问卷不存在", 0);
  1140. }
  1141. // return Result::success($survey);
  1142. // 调查问卷类型
  1143. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1144. //多选 若是json型则转化成数组类型
  1145. if (strpos($data['choice_id'], '[') === 0) {
  1146. $data['choice_id'] = json_decode($data['choice_id'], true);
  1147. } else {
  1148. // 单选 也转换成数组
  1149. $data['choice_id'] = [$data['choice_id']];
  1150. }
  1151. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1152. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1153. // ->where('website_id',$data['website_id'])
  1154. ->where('is_other', 1)
  1155. ->where('other_id', 0)
  1156. ->first();
  1157. if (!empty($other)) {
  1158. return Result::error("请选择已有的选项!", 0);
  1159. }
  1160. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1161. // ->where('website_id',$data['website_id'])
  1162. ->where('is_other', 1)
  1163. ->where('other_id', '!=', 0)
  1164. ->first();
  1165. // return Result::success($choice['other']);
  1166. $choice_id = $data['choice_id'];
  1167. if (!empty($choice['other'])) {
  1168. // array_push($data['choice_id'],$choice['other']['other_id']);
  1169. if (!empty($choice_id)) {
  1170. $key = array_search($choice['other']['id'], $choice_id);
  1171. if ($key !== false) {
  1172. unset($choice_id[$key]);
  1173. $choice_id = array_values($choice_id);
  1174. }
  1175. array_push($choice_id, $choice['other']['other_id']);
  1176. } else {
  1177. $choice_id[0] = $choice['other']['other_id'];
  1178. }
  1179. array_push($data['choice_id'], $choice['other']['other_id']);
  1180. }
  1181. // return Result::success($data);
  1182. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1183. // ->where('website_id',$data['website_id'])
  1184. ->increment('results', 1);
  1185. if (empty($choice)) {
  1186. return Result::error("请选择已有的选项!", 0);
  1187. }
  1188. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1189. // ->where('website_id',$data['website_id'])
  1190. ->where('other_id', 0)
  1191. ->get();
  1192. $survey['choice'] = $choice_id;
  1193. return Result::success($survey);
  1194. }
  1195. return Result::error("参数必填!");
  1196. }
  1197. return Result::error("此调查问卷不存在", 0);
  1198. }
  1199. return Result::error("参数必填!");
  1200. }
  1201. /**
  1202. * 后端-获取网站调查问卷列表
  1203. * @param array $data
  1204. * @return array
  1205. */
  1206. public function getSurveyList(array $data): array
  1207. {
  1208. $where = [];
  1209. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1210. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1211. }
  1212. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1213. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1214. }
  1215. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1216. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1217. }
  1218. // return Result::success($where);
  1219. if (!empty($where)) {
  1220. $query = Article::where($where)->where(function ($q) {
  1221. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1222. });
  1223. } else {
  1224. $query = Article::where(function ($q) {
  1225. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1226. });
  1227. }
  1228. $count = $query->count();
  1229. $survey = $query->orderByDesc('id')
  1230. ->limit($data['pageSize'])
  1231. ->offset(($data['page'] - 1) * $data['pageSize'])
  1232. ->get();
  1233. if (empty($survey->toArray())) {
  1234. return Result::error("暂无调查问卷!", 0);
  1235. }
  1236. $result = [
  1237. 'rows' => $survey,
  1238. 'count' => $count,
  1239. ];
  1240. return Result::success($result);
  1241. }
  1242. /**
  1243. * 后端-获取网站调查问卷详情
  1244. * @param array $data
  1245. * @return array
  1246. */
  1247. public function getSurveyInfo(array $data): array
  1248. {
  1249. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1250. $where = ['sur_id' => $data['sur_id']];
  1251. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1252. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1253. ->select('article_survey.*', 'article.survey_type')
  1254. ->get()->all();
  1255. if (empty($choose)) {
  1256. return Result::error("此调查问卷不存在", 0);
  1257. }
  1258. $resultsArray = array_column($choose, 'results');
  1259. $total = array_sum($resultsArray);
  1260. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1261. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1262. // $total = 0;
  1263. if (!empty($other)) {
  1264. $total = $total + $other['results'];
  1265. $other['choice_name'] = '(其他)';
  1266. if (!empty($others)) {
  1267. $other['hasChildren'] = true;
  1268. // array_push($other,['hasChildren','=',true]);
  1269. $other['children'] = $others;
  1270. $other_choices = [$other->toArray()];
  1271. $mer_choice = array_merge($choose, $other_choices);
  1272. $value_choice = array_values($mer_choice);
  1273. } else {
  1274. // return Result::error('1111');
  1275. $other_choices = [$other->toArray()];
  1276. $other_choices = array_merge($choose, $other_choices);
  1277. $value_choice = array_values($other_choices);
  1278. // return Result::success($result);
  1279. }
  1280. } else {
  1281. $value_choice = $choose;
  1282. }
  1283. $result = [
  1284. 'choose' => $value_choice,
  1285. 'total' => $total,
  1286. ];
  1287. }
  1288. return Result::success($result);
  1289. }
  1290. /**
  1291. * 前端-搜索新闻列表
  1292. * @param array $data
  1293. * @return array
  1294. */
  1295. public function selectWebsiteArticle(array $data): array
  1296. {
  1297. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  1298. $website_id = $data['website_id'];
  1299. $categorys = $this->processArticlePro($website_id);
  1300. $catiall = $categorys['catiall'];
  1301. $query = Article::where('status', 1)
  1302. ->whereIn('catid', $category)
  1303. ->leftJoinSub(function ($query) use ($website_id) {
  1304. $query->from('article_ignore')
  1305. ->where('website_id', $website_id);
  1306. }, 'article_ignore', function ($join) {
  1307. $join->on('article_ignore.article_id', '=', 'article.id');
  1308. })
  1309. ->where(function ($query) use ($website_id) {
  1310. $query->whereNull('article_ignore.article_id')
  1311. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1312. });
  1313. // return Result::success($all_articles);
  1314. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1315. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1316. }
  1317. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1318. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1319. }
  1320. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1321. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1322. }
  1323. // 计算总数
  1324. $count = $query->count();
  1325. // 分页查询
  1326. $articles = $query
  1327. ->select(
  1328. 'article.id',
  1329. 'article.title',
  1330. 'article.imgurl',
  1331. 'article.author',
  1332. 'article.updated_at',
  1333. 'article.introduce',
  1334. 'article.islink',
  1335. 'article.linkurl',
  1336. 'article.copyfrom',
  1337. 'article.cat_arr_id',
  1338. 'article.catid',
  1339. 'article.department_arr_id',
  1340. 'article.city_arr_id',
  1341. )
  1342. ->orderBy("updated_at", "desc")
  1343. ->offset(($data['page'] - 1) * $data['pageSize'])
  1344. ->limit($data['pageSize'])
  1345. ->get();
  1346. foreach ($articles as $k => $v) {
  1347. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1348. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1349. }
  1350. if (empty($articles)) {
  1351. return Result::error("没有符合条件的资讯数据");
  1352. }
  1353. $result = [
  1354. 'rows' => $articles,
  1355. 'count' => $count,
  1356. ];
  1357. return Result::success($result);
  1358. }
  1359. /**
  1360. * 模块新闻加强版
  1361. * @param array $data
  1362. * @return array
  1363. */
  1364. public function getWebsiteCatidArticle(array $data): array
  1365. {
  1366. $where = [
  1367. 'website_category.category_id' => $data['catid'],
  1368. 'website_category.website_id' => $data['website_id'],
  1369. ];
  1370. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1371. $child_catnum = $data['child_catnum'] ?? 1;
  1372. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1373. $childCategoryIds = array_column($category['child'], 'category_id');
  1374. if (empty($childCategoryIds)) {
  1375. return Result::error("暂无子栏目", 0);
  1376. }
  1377. $imgArticles = [];
  1378. $textArticles = [];
  1379. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1380. // 初始化子分类图片新闻和文字新闻数组
  1381. // 查询所有子级栏目的图文新闻
  1382. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1383. ->where(function ($query) use ($data) {
  1384. $query->where(function ($subQuery) use ($data) {
  1385. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1386. })->orWhereNull("ignore_ids");
  1387. })
  1388. ->where('status', 1)
  1389. ->where('imgurl', '!=', '')
  1390. ->select('*')
  1391. ->orderBy('updated_at', 'desc')
  1392. ->limit($data['child_imgnum'])
  1393. ->get();
  1394. }
  1395. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1396. // 查询所有子级栏目的文字新闻
  1397. $textArticles = Article::where('catid', $childCategoryIds[0])
  1398. ->where('status', 1)
  1399. ->where(function ($query) use ($data) {
  1400. $query->where(function ($subQuery) use ($data) {
  1401. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1402. })->orWhereNull("ignore_ids");
  1403. })
  1404. ->select('*')
  1405. ->orderBy('updated_at', 'desc')
  1406. ->limit($data['child_textnum'])
  1407. ->get();
  1408. }
  1409. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1410. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1411. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1412. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1413. return $child;
  1414. }, $category['child']);
  1415. }
  1416. // }
  1417. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1418. $category['img'] = WebsiteCategory::where($where)
  1419. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1420. ->where('article.status', 1)
  1421. ->where('article.imgurl', '!=', '')
  1422. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1423. ->orderBy('article.updated_at', 'desc')
  1424. ->limit($data['img_num'])
  1425. ->get();
  1426. }
  1427. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1428. $category['text'] = WebsiteCategory::where($where)
  1429. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1430. ->where('article.status', 1)
  1431. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1432. ->orderBy('article.updated_at', 'desc')
  1433. ->limit($data['text_num'])
  1434. ->get();
  1435. }
  1436. // $category = $category->get();
  1437. if (empty($category)) {
  1438. return Result::error("查询失败", 0);
  1439. }
  1440. return Result::success($category);
  1441. }
  1442. /**
  1443. * 模块新闻加强plus版
  1444. * @param array $data
  1445. * @return array
  1446. */
  1447. public function getWebsiteAllArticle(array $data): array
  1448. {
  1449. $time1 = microtime(true);
  1450. $wetbsite_id = $data['website_id'] ?? 2;
  1451. $data = json_decode($data['id'], true);
  1452. $categorys = $this->processArticlePro($wetbsite_id);
  1453. $cat_1st_arr = $categorys['cat_1st_arr'];
  1454. $catiall = $categorys['catiall'];
  1455. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  1456. $parent_category = array_column($data, 'parent');
  1457. $parent_cat = [];
  1458. $child_category = array_column($data, 'child');
  1459. if (!empty($parent_category)) {
  1460. foreach ($parent_category as $key => $value) {
  1461. $arr = array_map('intval', explode(',', $value));
  1462. $parent_cat[$key] = $arr[0] ?? 0;
  1463. $parent_category = $arr[0] ?? 0;
  1464. $article_imgnum = $arr[1] ?? 0;
  1465. $article_textnum = $arr[2] ?? 0;
  1466. if ($parent_category != 0) {
  1467. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1468. // return Result::success($category_arr);
  1469. if ($article_imgnum != 0) {
  1470. $img_article = Article::whereIn('catid', $category_arr)
  1471. ->where('status', 1)
  1472. ->where('imgurl', '!=', '')
  1473. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1474. $query->from('article_ignore')
  1475. ->where('website_id', $wetbsite_id);
  1476. }, 'article_ignore', function ($join) {
  1477. $join->on('article_ignore.article_id', '=', 'article.id');
  1478. })
  1479. ->where(function ($query) use ($wetbsite_id) {
  1480. $query->whereNull('article_ignore.article_id')
  1481. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1482. })
  1483. ->select('article.id', 'article.title', 'article.imgurl', 'article.author', 'article.updated_at', 'article.introduce', 'article.islink', 'article.linkurl', 'article.copyfrom', 'article.cat_arr_id', 'article.catid')
  1484. ->orderBy('updated_at', 'desc')
  1485. ->limit($article_imgnum)
  1486. ->get()->all();
  1487. foreach ($img_article as $k => $v) {
  1488. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1489. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1490. }
  1491. } else {
  1492. $img_article = [];
  1493. }
  1494. if ($article_textnum != 0) {
  1495. $text_article = Article::whereIn('catid', $category_arr)
  1496. ->where('status', 1)
  1497. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1498. $query->from('article_ignore')
  1499. ->where('website_id', $wetbsite_id);
  1500. }, 'article_ignore', function ($join) {
  1501. $join->on('article_ignore.article_id', '=', 'article.id');
  1502. })
  1503. ->where(function ($query) use ($wetbsite_id) {
  1504. $query->whereNull('article_ignore.article_id')
  1505. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1506. })
  1507. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1508. ->orderBy('updated_at', 'desc')
  1509. ->limit($article_textnum)
  1510. ->get()->all();
  1511. foreach ($text_article as $k => $v) {
  1512. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1513. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1514. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1515. }
  1516. } else {
  1517. $text_article = [];
  1518. }
  1519. $catiall[$parent_category]['imgnum'] = $img_article;
  1520. $catiall[$parent_category]['textnum'] = $text_article;
  1521. $parent[$key] = $catiall[$parent_category];
  1522. } else {
  1523. $parent[$key] = '';
  1524. }
  1525. }
  1526. }
  1527. if (!empty($child_category)) {
  1528. foreach ($child_category as $key => $value) {
  1529. $arr = array_map('intval', explode(',', $value));
  1530. $parent_category = $parent_cat[$key];
  1531. $child_category = $arr[0] ?? 0;
  1532. $article_imgnum = $arr[1] ?? 0;
  1533. $article_textnum = $arr[2] ?? 0;
  1534. if ($child_category != 0) {
  1535. $all_childcat = $cat_1st_arr[$parent_category];
  1536. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  1537. // 从 $websiteInfoIndexed 中获取对应的数据
  1538. $info = $websiteInfoIndexed[$v];
  1539. // 返回一个包含所需信息的数组
  1540. return [
  1541. 'alias' => $info->alias,
  1542. 'category_id' => $info->category_id,
  1543. 'aLIas_pinyin' => $info->aLIas_pinyin,
  1544. 'pid' => $info->pid,
  1545. 'type' => $info->type,
  1546. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  1547. 'pinyin' => $info->pinyin,
  1548. ];
  1549. }, $all_childcat);
  1550. if ($article_imgnum != 0) {
  1551. $img_article = Article::where('catid', $child_category)
  1552. ->where('status', 1)
  1553. ->where('imgurl', '!=', '')
  1554. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1555. $query->from('article_ignore')
  1556. ->where('website_id', $wetbsite_id);
  1557. }, 'article_ignore', function ($join) {
  1558. $join->on('article_ignore.article_id', '=', 'article.id');
  1559. })
  1560. ->where(function ($query) use ($wetbsite_id) {
  1561. $query->whereNull('article_ignore.article_id')
  1562. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1563. })
  1564. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1565. ->orderBy('updated_at', 'desc')
  1566. ->limit($article_imgnum)
  1567. ->get()->all();
  1568. foreach ($img_article as $k => $v) {
  1569. // var_dump($v);
  1570. // var_dump($k);
  1571. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1572. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1573. }
  1574. } else {
  1575. $img_article = [];
  1576. }
  1577. if ($article_textnum != 0) {
  1578. $text_article = Article::where('catid', $child_category)
  1579. ->where('status', 1)
  1580. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1581. $query->from('article_ignore')
  1582. ->where('website_id', $wetbsite_id);
  1583. }, 'article_ignore', function ($join) {
  1584. $join->on('article_ignore.article_id', '=', 'article.id');
  1585. })
  1586. ->where(function ($query) use ($wetbsite_id) {
  1587. $query->whereNull('article_ignore.article_id')
  1588. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1589. })
  1590. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1591. ->orderBy('updated_at', 'desc')
  1592. ->limit($article_textnum)
  1593. ->get()->all();
  1594. foreach ($text_article as $k => $v) {
  1595. // var_dump($v);
  1596. // var_dump($k);
  1597. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1598. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1599. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1600. }
  1601. } else {
  1602. $text_article = [];
  1603. }
  1604. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  1605. $catiall[$child_category]['imgnum'] = $img_article;
  1606. $catiall[$child_category]['textnum'] = $text_article;
  1607. $child[$key] = $catiall[$child_category];
  1608. // var_dump($pids);
  1609. } else {
  1610. $child[$key] = '';
  1611. }
  1612. }
  1613. }
  1614. foreach ($parent as $key => $value) {
  1615. $result[$key] = $value;
  1616. if (!empty($child[$key])) {
  1617. // var_dump($child[$key]);
  1618. $result[$key]['child'] = $child[$key];
  1619. // $value[$key]['child'] = $child[$key];
  1620. } else {
  1621. $result[$key]['child'] = [
  1622. "alias" => null,
  1623. "category_id" => null,
  1624. "type" => null,
  1625. "pinyin" => null,
  1626. "all_childcat" => [],
  1627. "imgnum" => [],
  1628. "textnum" => []
  1629. ];
  1630. }
  1631. }
  1632. return Result::success($result);
  1633. }
  1634. /**
  1635. * 辅助方法:获取文章列表
  1636. */
  1637. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  1638. {
  1639. sleep(1);
  1640. $query = Article::where('article.status', 1)
  1641. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  1642. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  1643. ->where(function ($query) use ($website) {
  1644. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  1645. })
  1646. ->leftJoin('website_category', function ($join) use ($website) {
  1647. $join->on('article.catid', '=', 'website_category.category_id')
  1648. ->where('website_category.website_id', '=', $website['website_id']);
  1649. })
  1650. ->select(
  1651. 'article.id',
  1652. 'article.title',
  1653. 'article.imgurl',
  1654. 'article.author',
  1655. 'article.updated_at',
  1656. 'article.introduce',
  1657. 'article.islink',
  1658. 'article.linkurl',
  1659. 'article.copyfrom',
  1660. 'article.cat_arr_id',
  1661. 'article.catid',
  1662. 'website_category.alias as category_name'
  1663. )
  1664. ->orderBy('updated_at', 'desc')
  1665. ->limit($limit);
  1666. // 如果是图片文章,添加图片URL条件
  1667. if ($isImageArticle) {
  1668. $query->where('imgurl', '!=', '');
  1669. } else {
  1670. // 文字文章不需要imgurl字段
  1671. $query->addSelect('article.introduce');
  1672. }
  1673. $articles = $query->get();
  1674. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  1675. }
  1676. /**
  1677. * 乡村网-获取特殊新闻模块
  1678. * @param array $data
  1679. * @return array
  1680. */
  1681. public function getWebsiteArticles(array $data): array
  1682. {
  1683. $website_id = $data['website_id'];
  1684. $catids = json_decode($data['id'], true);
  1685. $parent_category = array_column($catids, 'parent');
  1686. if (!empty($parent_category) && is_array($parent_category)) {
  1687. $categorys = $this->processArticlePro($website_id);
  1688. $catiall = $categorys['catiall'];
  1689. $cat_1st_arr = $categorys['cat_1st_arr'];
  1690. // return Result::success($categorys);
  1691. foreach ($parent_category as $key => $value) {
  1692. $arr = array_map('intval', explode(',', $value));
  1693. $parent_category = $arr[0] ?? 0;
  1694. $article_imgnum = $arr[1] ?? 0;
  1695. $article_textnum = $arr[2] ?? 0;
  1696. if ($parent_category != 0) {
  1697. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1698. // return Result::success($category_arr);
  1699. if ($article_imgnum != 0) {
  1700. $img_article = Article::whereIn('catid', $category_arr)
  1701. ->where('status', 1)
  1702. ->where('imgurl', '!=', '')
  1703. ->leftJoinSub(function ($query) use ($website_id) {
  1704. $query->from('article_ignore')
  1705. ->where('website_id', $website_id);
  1706. }, 'article_ignore', function ($join) {
  1707. $join->on('article_ignore.article_id', '=', 'article.id');
  1708. })
  1709. ->where(function ($query) use ($website_id) {
  1710. $query->whereNull('article_ignore.article_id')
  1711. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1712. })
  1713. ->select(
  1714. 'id',
  1715. 'title',
  1716. 'imgurl',
  1717. 'author',
  1718. 'updated_at',
  1719. 'introduce',
  1720. 'islink',
  1721. 'linkurl',
  1722. 'copyfrom',
  1723. 'cat_arr_id',
  1724. 'catid as category_id'
  1725. )
  1726. ->orderBy('updated_at', 'desc')
  1727. ->limit($article_imgnum)
  1728. ->get()->all();
  1729. foreach ($img_article as $k => $v) {
  1730. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  1731. // return Result::success($v);
  1732. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  1733. }
  1734. } else {
  1735. $img_article = [];
  1736. }
  1737. if ($article_textnum != 0) {
  1738. $text_article = Article::whereIn('catid', $category_arr)
  1739. ->where('status', 1)
  1740. ->leftJoinSub(function ($query) use ($website_id) {
  1741. $query->from('article_ignore')
  1742. ->where('website_id', $website_id);
  1743. }, 'article_ignore', function ($join) {
  1744. $join->on('article_ignore.article_id', '=', 'article.id');
  1745. })
  1746. ->where(function ($query) use ($website_id) {
  1747. $query->whereNull('article_ignore.article_id')
  1748. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1749. })
  1750. ->select(
  1751. 'id',
  1752. 'title',
  1753. 'author',
  1754. 'updated_at',
  1755. 'introduce',
  1756. 'islink',
  1757. 'linkurl',
  1758. 'copyfrom',
  1759. 'cat_arr_id',
  1760. 'catid as category_id'
  1761. )
  1762. ->orderBy('updated_at', 'desc')
  1763. ->limit($article_textnum)
  1764. ->get()->all();
  1765. foreach ($text_article as $k => $v) {
  1766. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  1767. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  1768. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1769. }
  1770. } else {
  1771. $text_article = [];
  1772. }
  1773. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  1774. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  1775. $parent[$key] = $catiall[$parent_category];
  1776. } else {
  1777. $parent[$key] = [];
  1778. }
  1779. }
  1780. }
  1781. return Result::success($parent);
  1782. }
  1783. // 封装处理商品的路由问题
  1784. function processGoods($goods, $data)
  1785. {
  1786. return $goods->map(function ($good) use ($data) {
  1787. $catid = $good->catid ?? 0;
  1788. // $pinyin = '';
  1789. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  1790. if (!empty($category->pid) && $category->pid != 0) {
  1791. $level = json_decode($category->category_arr_id, true);
  1792. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  1793. ->whereIn('category_id', $level)
  1794. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1795. ->get(['aLIas_pinyin'])
  1796. ->pluck('aLIas_pinyin')
  1797. ->implode('/');
  1798. } else {
  1799. $pinyin = $category->aLIas_pinyin ?? '';
  1800. }
  1801. if (isset($good->city_id) && !empty($good->city_id)) {
  1802. $city = District::where('id', $good->city_id)->first(['name']);
  1803. $good->city_name = $city->name ?? '';
  1804. }
  1805. // 解析imgurl JSON并取第一条数据
  1806. $imgUrls = json_decode($good->imgurl, true);
  1807. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  1808. $good->pinyin = $pinyin;
  1809. return $good;
  1810. });
  1811. }
  1812. /**
  1813. * 获取商城首页-根据栏目id
  1814. * @param array $data
  1815. * @return array
  1816. * */
  1817. function getWebsiteCatidshop(array $data): array
  1818. {
  1819. $input['catid'] = $data['catid'];
  1820. $input['website_id'] = $data['website_id'];
  1821. $data = json_decode($input['catid'] ?? '', true) ?? [];
  1822. $result = array_map(function ($item) use ($input) {
  1823. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  1824. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  1825. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  1826. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  1827. if (empty($category) || $category->type != 2) {
  1828. return Result::error("暂无此栏目", 0);
  1829. } else {
  1830. $website['website_id'] = $input['website_id'];
  1831. $goods = Good::where('good.status', 2)
  1832. ->where('good.website_id', $website['website_id'])
  1833. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  1834. ->select(
  1835. 'good.id',
  1836. 'good.name',
  1837. 'good.imgurl',
  1838. 'good.description',
  1839. 'good.updated_at',
  1840. 'good.catid',
  1841. 'good.type_id',
  1842. 'good.price',
  1843. 'good.com',
  1844. 'good.level',
  1845. 'good.unit'
  1846. )
  1847. ->orderBy('updated_at', 'desc')
  1848. ->offset($goodStart)
  1849. ->limit($goodNum);
  1850. $all_goods = $goods->get();
  1851. $all_goods = $this->processGoods($all_goods, $website);
  1852. }
  1853. return $all_goods ?? [];
  1854. }
  1855. }, $data);
  1856. return Result::success($result);
  1857. }
  1858. /**
  1859. * 获取商品模块
  1860. * @param array $data
  1861. * @return array
  1862. * */
  1863. public function getWebsiteshop(array $data): array
  1864. {
  1865. $input['id'] = $data['id'];
  1866. $input['website_id'] = $data['website_id'];
  1867. $catid = $data['catid'];
  1868. $data = json_decode($input['id'] ?? '', true) ?? [];
  1869. $result['goods'] = array_map(function ($item) use ($input) {
  1870. // 检查parent元素是否存在且不是undefined
  1871. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  1872. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  1873. $website = $input['website_id'];
  1874. $query = Good::where('good.status', 2)
  1875. ->where('good.website_id', $website);
  1876. switch ($Levelid) {
  1877. case 1:
  1878. case 2:
  1879. case 3:
  1880. $goods = $query->where(function ($q) use ($Levelid) {
  1881. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  1882. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  1883. });
  1884. break;
  1885. case 4:
  1886. $goods = $query;
  1887. break;
  1888. case 5:
  1889. $goods = $query->where('type_id', 1);
  1890. break;
  1891. case 6:
  1892. $goods = $query->where('type_id', 2);
  1893. break;
  1894. default:
  1895. return [];
  1896. }
  1897. $all_goods = $goods
  1898. ->select(
  1899. 'good.id',
  1900. 'good.name',
  1901. 'good.imgurl',
  1902. 'good.description',
  1903. 'good.updated_at',
  1904. 'good.catid',
  1905. 'good.type_id',
  1906. 'good.price',
  1907. 'good.level',
  1908. 'good.website_id'
  1909. )
  1910. ->orderBy('updated_at', 'desc')
  1911. ->offset($goodStart)
  1912. ->limit($goodNum)
  1913. ->get();
  1914. $web['website_id'] = $website;
  1915. $all_goods = $this->processGoods($all_goods, $web);
  1916. }
  1917. return $all_goods;
  1918. }, $data);
  1919. $website = $input['website_id'];
  1920. $result['article'] = Article::where(function ($query) use ($website) {
  1921. $query->where(function ($subQuery) use ($website) {
  1922. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  1923. })->orWhereNull("ignore_ids");
  1924. })
  1925. ->where('catid', $catid)
  1926. ->where('article.status', 1)
  1927. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  1928. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  1929. ->orderBy('article.updated_at', 'desc')
  1930. ->first();
  1931. return Result::success($result);
  1932. }
  1933. /**
  1934. * 获取商品分类
  1935. * @param array $data
  1936. * @return array
  1937. * */
  1938. public function getWebsiteshopCat(array $data): array
  1939. {
  1940. $website = $data['website_id'];
  1941. $category = WebsiteCategory::where('website_id', $website)
  1942. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  1943. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  1944. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  1945. ->orderBy('sort')
  1946. ->get();
  1947. $cat = $category->map(function ($item) use ($website) {
  1948. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  1949. $pid = $item->pid ?? 0;
  1950. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  1951. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  1952. ->where('website_id', $website)
  1953. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  1954. ->get(['aLIas_pinyin'])
  1955. ->pluck('aLIas_pinyin')
  1956. ->implode('/');
  1957. } else {
  1958. $pinyin = $item->aLIas_pinyin ?? '';
  1959. }
  1960. $item->pinyin = $pinyin;
  1961. });
  1962. if (empty($category)) {
  1963. return Result::error("栏目查询失败", 0);
  1964. }
  1965. $cat_tree = Result::buildMenuTree($category);
  1966. $web['website_id'] = $website;
  1967. $goods = Good::where('website_id', $website)
  1968. ->where('status', 2)
  1969. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  1970. ->latest('updated_at')
  1971. ->offset(($data['page'] - 1) * $data['pageSize'])
  1972. ->limit($data['pageSize'])
  1973. ->get();
  1974. if (!empty($goods)) {
  1975. if ($goods->count() > 1 && !empty($goods)) {
  1976. $goods = $this->processGoods($goods, $web);
  1977. }
  1978. } else {
  1979. $goods = [];
  1980. }
  1981. $result = [
  1982. 'category' => $cat_tree,
  1983. 'goods' => $goods,
  1984. ];
  1985. // $resul['goods'] = $goods;
  1986. if (empty($result)) {
  1987. return Result::error("查询失败", 0);
  1988. }
  1989. return Result::success($result);
  1990. }
  1991. /*
  1992. * 获取商品列表
  1993. * @param array $data
  1994. * @return array
  1995. * */
  1996. public function getWebsiteshopList(array $data): array
  1997. {
  1998. // return Result::success($data);
  1999. $where = [
  2000. 'status' => 2,
  2001. 'website_id' => $data['website_id'],
  2002. ];
  2003. if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2004. return Result::error("查询失败", 0);
  2005. }
  2006. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2007. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2008. $data['catid'] = $category->category_id ?? 0;
  2009. }
  2010. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2011. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2012. }
  2013. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2014. array_push($where, ['type_id', $data['type_id']]);
  2015. }
  2016. $query = Good::where($where)
  2017. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2018. $query->where(function ($q) use ($data) {
  2019. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2020. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2021. });
  2022. })
  2023. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2024. $query->where(function ($q) use ($data) {
  2025. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2026. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2027. });
  2028. })
  2029. ->select(
  2030. 'good.id',
  2031. 'good.name',
  2032. 'good.imgurl',
  2033. 'good.description',
  2034. 'good.updated_at',
  2035. 'good.com',
  2036. 'good.catid',
  2037. 'good.type_id',
  2038. 'good.website_id',
  2039. 'good.cat_arr_id',
  2040. 'good.created_at',
  2041. 'good.city_id'
  2042. )
  2043. ->latest('updated_at');
  2044. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2045. $result['count'] = $query->clone()->count();
  2046. $result['goods'] = $this->processGoods(
  2047. $query->clone()
  2048. ->offset(($data['page'] - 1) * $data['pageSize'])
  2049. ->limit($data['pageSize'])
  2050. ->get(),
  2051. $data
  2052. );
  2053. } else {
  2054. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2055. // 获取 type_id 为 1 的数据
  2056. $result['type1'] = $this->processGoods(
  2057. $query->clone()
  2058. ->where('type_id', 1)
  2059. ->offset(($data['page'] - 1) * $data['pageSize'])
  2060. ->limit($data['pageSize'])
  2061. ->get(),
  2062. $data
  2063. );
  2064. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2065. // 获取 type_id 为 2 的数据
  2066. $result['type2'] = $this->processGoods(
  2067. $query->clone()
  2068. ->where('type_id', 2)
  2069. ->offset(($data['page'] - 1) * $data['pageSize'])
  2070. ->limit($data['pageSize'])
  2071. ->get(),
  2072. $data
  2073. );
  2074. }
  2075. if (empty($result)) {
  2076. return Result::error("查询失败", 0);
  2077. }
  2078. return Result::success($result);
  2079. }
  2080. /**
  2081. * 获取商品详情
  2082. * @param array $data
  2083. * @return array
  2084. * */
  2085. public function getWebsiteshopInfo(array $data): array
  2086. {
  2087. $where = [
  2088. 'good.status' => 2,
  2089. 'good.website_id' => $data['website_id'],
  2090. 'good.id' => $data['id'],
  2091. ];
  2092. $goods = Good::where($where)
  2093. ->where('good.id', $data['id'])
  2094. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2095. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2096. ->first();
  2097. if (empty($goods)) {
  2098. return Result::error("查询失败", 0);
  2099. }
  2100. $goods->imgurl = json_decode($goods->imgurl, true);
  2101. return Result::success($goods);
  2102. }
  2103. /**
  2104. * plus pro 处理文章路由问题
  2105. */
  2106. function processArticlePro($website_id)
  2107. {
  2108. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2109. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2110. // 取出category_id 对应的aLIas_pinyin
  2111. $categoryIds = array_column($categorys, 'category_id');
  2112. $categoryPIds = array_column($categorys, 'pid');
  2113. $aliasPinyins = array_column($categorys, 'aLIas_pinyin');
  2114. $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2115. // return Result::success($categorys);
  2116. $catiall = [];
  2117. //一级所有子级的记录
  2118. $cat_1st_arr = [];
  2119. foreach ($categorys as $key => $value) {
  2120. $category_arr_id = json_decode($value->category_arr_id);
  2121. $pinyin_str = '';
  2122. // 算出一级 并且算出子级
  2123. if ($value->pid != 0) {
  2124. $cat_1st_arr[$value->pid][] = $value->category_id;
  2125. }
  2126. foreach ($category_arr_id as $k => $v) {
  2127. $pinyin_str .= $cat_arr[$v] . '/';
  2128. }
  2129. $pinyin_str = rtrim($pinyin_str, '/');
  2130. $catiall[$value->category_id]['alias'] = $value->alias;
  2131. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2132. $catiall[$value->category_id]['type'] = $value->type;
  2133. $catiall[$value->category_id]['pinyin'] = $pinyin_str;
  2134. $websiteInfoIndexed[$value->category_id]->pinyin = $pinyin_str;
  2135. }
  2136. return [
  2137. 'cat_1st_arr' => $cat_1st_arr,
  2138. 'catiall' => $catiall,
  2139. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2140. 'categoryIds' => $categoryIds,
  2141. ];
  2142. }
  2143. /**
  2144. * 封装处理文章的路由问题
  2145. * */
  2146. function processArticles($articles, $data)
  2147. {
  2148. // 检查 $articles 是否为数组或可迭代对象
  2149. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2150. return $articles->map(function ($article) use ($data) {
  2151. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2152. $catid = $article->cat_arr_id ?? '';
  2153. }
  2154. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2155. $catid = $article->category_arr_id ?? '';
  2156. }
  2157. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2158. $level = json_decode($catid, true);
  2159. if (!is_array($level)) {
  2160. return $article;
  2161. } else {
  2162. $level = array_map('intval', $level);
  2163. }
  2164. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2165. ->where($data)
  2166. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2167. ->pluck('aLIas_pinyin')
  2168. ->implode('/');
  2169. $article->pinyin = $pinyin ?? '';
  2170. return $article;
  2171. });
  2172. } else {
  2173. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2174. $catid = $articles->cat_arr_id ?? '';
  2175. $level = json_decode($catid, true);
  2176. if (!is_array($level)) {
  2177. return $articles;
  2178. } else {
  2179. $level = array_map('intval', $level);
  2180. }
  2181. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2182. ->where($data)
  2183. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2184. ->pluck('aLIas_pinyin')
  2185. ->implode('/');
  2186. $articles->pinyin = $pinyin ?? '';
  2187. return $articles;
  2188. }
  2189. }
  2190. // 封装处理由问题
  2191. function processJob($job, $data)
  2192. {
  2193. return $job->map(function ($job) use ($data) {
  2194. $category = $job->cat_arr_id ?? '';
  2195. $cityid = $job->city_arr_id ?? '';
  2196. $city = json_decode($cityid, true);
  2197. $pinyin = '';
  2198. $level = json_decode($category, true);
  2199. // 路由
  2200. if (!empty($level) && is_array($level)) {
  2201. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2202. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2203. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2204. ->get(['aLIas_pinyin'])
  2205. ->pluck('aLIas_pinyin')
  2206. ->implode('/');
  2207. if (empty($pinyin)) {
  2208. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2209. }
  2210. $job->pinyin = $pinyin;
  2211. }
  2212. // 取职位-城市 市??省
  2213. if (!empty($city) && is_array($city)) {
  2214. if (isset($city[1]) && !empty($city[1])) {
  2215. $city = District::where('id', $city[1])->first(['name']);
  2216. $job->city_name = $city->name ?? '';
  2217. } else if (isset($city[0]) && !empty($city[0])) {
  2218. $city = District::where('id', $city[0])->first(['name']);
  2219. $job->city_name = $city->name ?? '';
  2220. } else {
  2221. $job->city_name = '全国';
  2222. }
  2223. }
  2224. // 获取简历最后一级地区
  2225. if (isset($job->city_id) && !empty($job->city_id)) {
  2226. $city = District::where('id', $job->city_id)->first(['name']);
  2227. $job->hunt_cityname = $city->name ?? '';
  2228. }
  2229. // 组合详细地址
  2230. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2231. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2232. if (is_array($address_id) && !empty($address_id)) {
  2233. $address = District::whereIn('id', $address_id)
  2234. ->orderBy('level', 'asc')
  2235. ->get(['name'])
  2236. ->pluck('name')
  2237. ->implode('');
  2238. // $job->address_name = $address ?? '';
  2239. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2240. }
  2241. }
  2242. // 取行业
  2243. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2244. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2245. if (!empty($job->industry)) {
  2246. $query->where('hyid', $job->industry);
  2247. } else if (!empty($job->hy_id)) {
  2248. $query->where('hyid', $job->hy_id);
  2249. } else if (!empty($job->company_hy_id)) {
  2250. $query->where('hyid', $job->company_hy_id);
  2251. } else {
  2252. $query->where('hyid', $job->job_industry);
  2253. }
  2254. })->first(['hyname']);
  2255. $job->hy_name = $hy_name->hyname ?? '';
  2256. }
  2257. // 取职位类别
  2258. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2259. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2260. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2261. $job->zw_name = $zw_name->zwname ?? '';
  2262. }
  2263. // 取具体职位
  2264. if ((isset($job->jtzw_id) && !empty($job->jtzw_id)) || (isset($job->job_name_get) && !empty($job->job_name_get)) || (isset($job->job_name) && !empty($job->job_name))) {
  2265. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2266. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2267. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2268. }
  2269. // 取工作经验
  2270. if (isset($job->experience) && !empty($job->experience)) {
  2271. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2272. $job->experience_name = $experience->ename ?? '';
  2273. }
  2274. // 取学历
  2275. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2276. $education = $job->educational ?? $job->school_education;
  2277. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2278. $job->education_name = $education->ename ?? '';
  2279. }
  2280. // 语言
  2281. if (isset($job->language) && !empty($job->language)) {
  2282. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2283. $job->language_name = $language->ename ?? '';
  2284. }
  2285. // 薪资
  2286. if (isset($job->salary) && !empty($job->salary)) {
  2287. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2288. $job->salary_name = $salary->ename ?? '';
  2289. }
  2290. // 职位性质
  2291. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2292. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2293. $job->job_nature_name = $job_nature->ename ?? '';
  2294. }
  2295. // 公司规模
  2296. if (isset($job->company_size) && !empty($job->company_size)) {
  2297. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2298. $job->company_size_name = $company_size->ename ?? '';
  2299. }
  2300. // 公司性质
  2301. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2302. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2303. $job->company_nature_name = $company_nature->nature_name ?? '';
  2304. }
  2305. // $job->pinyin = $pinyin;
  2306. return $job;
  2307. });
  2308. }
  2309. /**
  2310. * 获取书籍模块
  2311. * @param array $data
  2312. * @return array
  2313. * */
  2314. public function getWebsiteBook(array $data): array
  2315. {
  2316. $input['id'] = $data['id'];
  2317. $input['website_id'] = $data['website_id'];
  2318. // 将 JSON 字符串转换为 PHP 数组
  2319. $data = json_decode($input['id'], true);
  2320. // 使用 array_map 处理每个元素
  2321. $result = array_map(function ($item) use ($input) {
  2322. // 检查parent元素是否存在且不是undefined
  2323. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2324. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2325. $website = [
  2326. 'website_id' => $input['website_id'],
  2327. ];
  2328. // 查询栏目名称
  2329. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2330. if (empty($category)) {
  2331. $parent_alias = '';
  2332. $parent_pinyin = null;
  2333. $imgBooks = [];
  2334. $textBooks = [];
  2335. } else {
  2336. $parent_alias = $category->alias ?? '';
  2337. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2338. // 查找子分类ID数组
  2339. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2340. array_push($childCategoryIds, $parentCatId);
  2341. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2342. if ($parentImgNum != 0) {
  2343. // 查询图片新闻
  2344. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2345. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2346. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2347. })
  2348. ->where('book.status', 2)
  2349. ->where('book.img_url', '!=', '')
  2350. ->leftJoin('website_category', function ($join) use ($website) {
  2351. $join->on('book.cat_id', '=', 'website_category.category_id')
  2352. ->where('website_category.website_id', '=', $website['website_id']);
  2353. })
  2354. ->select(
  2355. 'book.id',
  2356. 'book.title',
  2357. 'book.img_url',
  2358. 'book.price',
  2359. 'book.market_price',
  2360. 'book.description',
  2361. 'book.cat_id',
  2362. 'book.description',
  2363. 'book.updated_at',
  2364. 'website_category.alias as category_name',
  2365. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2366. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2367. )
  2368. ->orderBy('updated_at', 'desc')
  2369. ->limit($parentImgNum)
  2370. ->get()->all();
  2371. // 查询文字新闻
  2372. }
  2373. if ($parentTextNum != 0) {
  2374. $textBooks = [];
  2375. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2376. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2377. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2378. })
  2379. ->where('book.status', 2)
  2380. ->leftJoin('website_category', function ($join) use ($website) {
  2381. $join->on('book.cat_id', '=', 'website_category.category_id')
  2382. ->where('website_category.website_id', '=', $website['website_id']);
  2383. })
  2384. ->select(
  2385. 'book.id',
  2386. 'book.title',
  2387. 'book.img_url',
  2388. 'book.price',
  2389. 'book.market_price',
  2390. 'book.description',
  2391. 'book.cat_id',
  2392. 'book.description',
  2393. 'book.updated_at',
  2394. 'website_category.alias as category_name',
  2395. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2396. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2397. )
  2398. ->orderBy('updated_at', 'desc')
  2399. ->limit($parentTextNum)
  2400. ->get()->all();
  2401. }
  2402. }
  2403. }
  2404. $resultItem = [
  2405. 'alias' => $parent_alias ?? '',
  2406. 'category_id' => $parentCatId ?? 0,
  2407. 'pinyin' => $parent_pinyin ?? null,
  2408. 'imgnum' => $imgBooks ?? [],
  2409. 'textnum' => $textBooks ?? [],
  2410. ];
  2411. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  2412. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  2413. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  2414. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2415. ->get()->all();
  2416. if (!empty($childCategory)) {
  2417. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  2418. // 查询子栏目名称
  2419. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  2420. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2421. ->first();
  2422. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  2423. $childImgArticles = [];
  2424. $childTextArticles = [];
  2425. $resultItem['child'] = [];
  2426. } else {
  2427. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  2428. // 查询子栏目图片新闻
  2429. $childImgArticles = Book::where('cat_id', $childCatId)
  2430. ->where('status', 2)
  2431. ->where('img_url', '!=', '')
  2432. ->leftJoin('website_category', function ($join) use ($website) {
  2433. $join->on('book.cat_id', '=', 'website_category.category_id')
  2434. ->where('website_category.website_id', '=', $website['website_id']);
  2435. })
  2436. ->select(
  2437. 'book.id',
  2438. 'book.title',
  2439. 'book.img_url',
  2440. 'book.price',
  2441. 'book.market_price',
  2442. 'book.description',
  2443. 'book.cat_id',
  2444. 'book.description',
  2445. 'book.updated_at',
  2446. DB::raw("'$child_pinyin' as pinyin")
  2447. )
  2448. ->orderBy('updated_at', 'desc')
  2449. ->limit($childImgNum)
  2450. ->get()->all();
  2451. // 查询子栏目文字新闻
  2452. $childTextArticles = Book::where('cat_id', $childCatId)
  2453. ->where('status', 2)
  2454. ->leftJoin('website_category', function ($join) use ($website) {
  2455. $join->on('book.cat_id', '=', 'website_category.category_id')
  2456. ->where('website_category.website_id', '=', $website['website_id']);
  2457. })
  2458. ->select(
  2459. 'book.id',
  2460. 'book.title',
  2461. 'book.img_url',
  2462. 'book.price',
  2463. 'book.market_price',
  2464. 'book.description',
  2465. 'book.cat_id',
  2466. 'book.description',
  2467. 'book.updated_at',
  2468. DB::raw("'$child_pinyin' as pinyin")
  2469. )
  2470. ->orderBy('updated_at', 'desc')
  2471. ->limit($childTextNum)
  2472. ->get()->all();
  2473. $resultItem['child'] = [
  2474. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  2475. 'category_id' => $childCatId,
  2476. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  2477. 'all_childcat' => $childCategory,
  2478. 'imgnum' => $childImgArticles,
  2479. 'textnum' => $childTextArticles,
  2480. ];
  2481. }
  2482. }
  2483. } else {
  2484. $resultItem['child'] = [];
  2485. }
  2486. return $resultItem;
  2487. }, $data);
  2488. return Result::success($result);
  2489. }
  2490. /**
  2491. * 获取书刊列表
  2492. * @param array $data
  2493. * @return array
  2494. * */
  2495. public function getWebsiteBookList(array $data): array
  2496. {
  2497. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2498. if (empty($web)) {
  2499. return Result::error("查询失败", 0);
  2500. }
  2501. $catid = $data['id'];
  2502. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  2503. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  2504. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  2505. $category_pinyin = $category ? $category->aLias_pinyin : '';
  2506. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  2507. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  2508. ->where('pid', $category['pid'])
  2509. ->select(
  2510. 'category_id',
  2511. 'alias',
  2512. 'aLIas_pinyin',
  2513. 'pid',
  2514. 'sort',
  2515. 'is_url',
  2516. 'web_url',
  2517. 'seo_title',
  2518. 'seo_keywords',
  2519. 'seo_description',
  2520. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  2521. )
  2522. ->orderBy('sort')
  2523. ->get()->all();
  2524. if (empty($category)) {
  2525. return Result::error("查询失败", 0);
  2526. }
  2527. $query = Book::where('book.status', 2)
  2528. ->where('book.website_id', $data['website_id'])
  2529. ->where('book.cat_id', $catid)
  2530. ->select(
  2531. 'book.id',
  2532. 'book.title',
  2533. 'book.img_url',
  2534. 'book.description',
  2535. 'book.updated_at',
  2536. 'book.cat_id',
  2537. DB::raw("'$pinyin' as pinyin")
  2538. )
  2539. ->orderBy('book.updated_at', 'desc');
  2540. $count = $query->count();
  2541. $query = clone $query;
  2542. $Book = $query
  2543. ->limit($data['pageSize'])
  2544. ->offset(($data['page'] - 1) * $data['pageSize'])
  2545. ->get()->all();
  2546. $result = [
  2547. 'category' => $categorys,
  2548. 'books' => $Book,
  2549. 'count' => $count,
  2550. ];
  2551. // if(empty($result)){
  2552. // return Result::error("查询失败", 0);
  2553. // }
  2554. return Result::success($result);
  2555. }
  2556. /**
  2557. * 获取书刊详情
  2558. * @param array $data
  2559. * @return array
  2560. * */
  2561. public function getWebsiteBookInfo(array $data): array
  2562. {
  2563. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2564. if (empty($web)) {
  2565. return Result::error("查询失败", 0);
  2566. }
  2567. $book = Book::where('status', 2)
  2568. ->where('website_id', $data['website_id'])
  2569. ->where('id', $data['id'])
  2570. ->select(
  2571. 'book.*',
  2572. )
  2573. ->orderBy('updated_at', 'desc')
  2574. ->first();
  2575. if (empty($book)) {
  2576. return Result::error("查询失败", 0);
  2577. }
  2578. // 先查询当前分类的 pid
  2579. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  2580. ->where('category_id', $book['cat_id'])
  2581. ->first(['pid', 'category_id']);
  2582. $query = WebsiteCategory::where('website_id', $data['website_id']);
  2583. if (!empty($carpid)) {
  2584. if ($carpid->pid != 0) {
  2585. $pid = $carpid['pid'];
  2586. // $parent_pinyin = '';
  2587. } else {
  2588. $pid = $carpid['category_id'];
  2589. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  2590. }
  2591. }
  2592. $categorys = $query->where('pid', $pid)
  2593. ->select(
  2594. 'category_id',
  2595. 'alias',
  2596. 'aLIas_pinyin',
  2597. 'pid',
  2598. 'sort',
  2599. 'is_url',
  2600. 'web_url',
  2601. 'category_arr_id as cat_arr_id',
  2602. )
  2603. ->orderBy('sort')
  2604. ->get();
  2605. $category = $this->processArticle($categorys, $data);
  2606. $result = [
  2607. 'category' => $category,
  2608. 'books' => $book,
  2609. ];
  2610. return Result::success($result);
  2611. }
  2612. /**
  2613. * 尝试
  2614. * @param array $data
  2615. * @return array
  2616. * */
  2617. public function test(array $data): array
  2618. {
  2619. $input['id'] = $data['id'];
  2620. $input['website_id'] = $data['website_id'];
  2621. // 将 JSON 字符串转换为 PHP 数组
  2622. $data = json_decode($input['id'], true);
  2623. $result = [];
  2624. $article = $data;
  2625. $result = array_map(function ($item) use ($input) {
  2626. $website = [
  2627. 'website_id' => $input['website_id'],
  2628. ];
  2629. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2630. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2631. $parent = [
  2632. 0 => $category['category_id'] ?? [],
  2633. 1 => $parentImgNum ?? [],
  2634. 2 => $parentTextNum ?? [],
  2635. ];
  2636. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  2637. $child = [];
  2638. $resultItem = [
  2639. // 'alias' => $parent_alias ?? '',
  2640. 'category_id' => $parentCatId ?? 0,
  2641. 'pinyin' => $parentImgNum ?? null,
  2642. 'imgnum' => $parentTextNum ?? [],
  2643. // 'textnum' => $textArticles ?? [],
  2644. ];
  2645. return $parent;
  2646. }, $data);
  2647. return Result::success($result);
  2648. // });
  2649. }
  2650. /**
  2651. * 封装处理文章的路由问题
  2652. * */
  2653. function processArticle($article, $data)
  2654. {
  2655. return $article->map(function ($article) use ($data) {
  2656. $catid = $article->cat_arr_id ?? '';
  2657. $level = json_decode($catid, true);
  2658. $pinyin = '';
  2659. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2660. if (!empty($level) && is_array($level)) {
  2661. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2662. ->where('website_id', $data['website_id'])
  2663. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2664. ->get(['aLIas_pinyin'])
  2665. ->pluck('aLIas_pinyin')
  2666. ->implode('/');
  2667. } else {
  2668. $pinyin = '';
  2669. }
  2670. $article->pinyin = $pinyin;
  2671. return $article;
  2672. });
  2673. }
  2674. /**
  2675. * c端-获取招工招聘下拉选框
  2676. * @param array $data
  2677. * @return array
  2678. * */
  2679. public function getWebsiteJobSelect(array $data): array
  2680. {
  2681. $web = Website::where('id', $data['website_id'])->first();
  2682. if (empty($web)) {
  2683. return Result::error("该网站不存在", 0);
  2684. }
  2685. $hy = JobIndustry::get()->all();
  2686. $zw = JobPosition::where('zwpid', 0)->get()->all();
  2687. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  2688. $result = [
  2689. 'hy' => $hy,
  2690. 'zw' => $zw,
  2691. 'jtzw' => $jtzw,
  2692. ];
  2693. if (empty($result)) {
  2694. return Result::error("查询失败", 0);
  2695. }
  2696. return Result::success($result);
  2697. }
  2698. /**
  2699. * c端-获取招工招聘
  2700. * @param array $data
  2701. * @return array
  2702. * */
  2703. public function getWebsiteJob(array $data): array
  2704. {
  2705. $web = Website::where('id', $data['website_id'])->first();
  2706. if (empty($web)) {
  2707. return Result::error("该网站不存在", 0);
  2708. }
  2709. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2710. ->where('job_hunting.website_id', $data['website_id'])
  2711. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2712. $query->where(function ($q) use ($data) {
  2713. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2714. });
  2715. })
  2716. ->select(
  2717. 'job_hunting.id',
  2718. 'job_hunting.cat_arr_id',
  2719. 'job_hunting.job_name_get',
  2720. 'job_hunting.industry',
  2721. 'job_hunting.name',
  2722. 'job_hunting.sexy',
  2723. 'job_hunting.origin',
  2724. 'job_hunting.city_arr_id',
  2725. 'job_hunting.experience',
  2726. 'job_hunting.updated_at',
  2727. 'job_hunting.salary'
  2728. )
  2729. ->orderBy('updated_at', 'desc')
  2730. ->limit($data['job1_num'])
  2731. ->get();
  2732. $web['website_id'] = $data['website_id'];
  2733. if (empty($job_hunting)) {
  2734. $job_huntings = "未查询到相关简历信息";
  2735. } else {
  2736. $job_huntings = $this->processJob($job_hunting, $web);
  2737. }
  2738. // 0:待审核 1:已通过 2:已拒绝
  2739. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  2740. ->where('job_recruiting.website_id', $data['website_id'])
  2741. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2742. $query->where(function ($q) use ($data) {
  2743. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2744. });
  2745. })
  2746. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2747. ->select(
  2748. 'job_recruiting.id',
  2749. 'job_recruiting.cat_arr_id',
  2750. 'job_recruiting.title',
  2751. 'job_recruiting.jtzw_id',
  2752. 'job_recruiting.hy_id',
  2753. 'job_recruiting.city_arr_id',
  2754. 'job_recruiting.due_data',
  2755. 'job_recruiting.updated_at',
  2756. 'job_recruiting.experience',
  2757. 'job_recruiting.educational',
  2758. 'job_recruiting.salary',
  2759. 'job_recruiting.zw_id',
  2760. 'job_company.business_name'
  2761. )
  2762. ->orderBy('updated_at', 'desc')
  2763. ->limit($data['job2_num'])
  2764. ->get();
  2765. if (empty($job_recruiting->toArray())) {
  2766. $job_recruitings = "未查询到相关职位信息";
  2767. } else {
  2768. $job_recruitings = $this->processJob($job_recruiting, $web);
  2769. }
  2770. $result = [
  2771. 'job_hunting' => $job_huntings,
  2772. 'job_recuiting' => $job_recruitings,
  2773. ];
  2774. return Result::success($result);
  2775. }
  2776. /**
  2777. * c端-获取招工招聘列表
  2778. * @param array $data
  2779. * @return array
  2780. * */
  2781. public function getWebsiteJobList(array $data): array
  2782. {
  2783. $recruit_where = [];
  2784. $hunt_where = [];
  2785. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2786. if (empty($web)) {
  2787. return Result::error("此网站不存在", 0);
  2788. }
  2789. $website_id['website_id'] = $data['website_id'];
  2790. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  2791. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2792. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  2793. }
  2794. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2795. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  2796. }
  2797. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2798. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  2799. }
  2800. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2801. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  2802. }
  2803. $query = JobRecruiting::where('job_recruiting.status', 1)
  2804. ->where('job_recruiting.website_id', $data['website_id'])
  2805. ->where($recruit_where)
  2806. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2807. $query->where(function ($q) use ($data) {
  2808. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2809. });
  2810. })
  2811. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2812. $query->where(function ($q) use ($data) {
  2813. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  2814. });
  2815. })
  2816. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2817. ->select(
  2818. 'job_recruiting.id',
  2819. 'job_recruiting.hy_id',
  2820. 'job_recruiting.title',
  2821. 'job_recruiting.zw_id',
  2822. 'job_recruiting.educational',
  2823. 'job_recruiting.jtzw_id',
  2824. 'job_recruiting.city_arr_id',
  2825. 'job_recruiting.due_data',
  2826. 'job_recruiting.experience',
  2827. 'job_recruiting.cat_arr_id',
  2828. 'job_recruiting.updated_at',
  2829. 'job_company.business_name'
  2830. )
  2831. ->orderBy('updated_at', 'desc');
  2832. $recruit_count = $query->count();
  2833. $query = clone $query;
  2834. $JobRecruiting = $query
  2835. ->offset(($data['page'] - 1) * $data['pageSize'])
  2836. ->limit($data['pageSize'])
  2837. ->get();
  2838. if (empty($JobRecruiting)) {
  2839. $JobRecruiting = "暂无相关职位信息";
  2840. } else {
  2841. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  2842. }
  2843. }
  2844. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  2845. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2846. array_push($hunt_where, ['job', $data['zw_id']]);
  2847. }
  2848. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2849. array_push($hunt_where, ['job_name_get', $data['jtzw_id']]);
  2850. }
  2851. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2852. array_push($hunt_where, ['industry', $data['hy_id']]);
  2853. }
  2854. $query = JobHunting::where('status', 2)
  2855. ->where('job_hunting.website_id', $data['website_id'])
  2856. ->where($hunt_where)
  2857. ->when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  2858. $query->where('job_position.zwname', 'like', '%' . $data['keyword'] . '%');
  2859. })
  2860. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2861. $query->where(function ($q) use ($data) {
  2862. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2863. });
  2864. })
  2865. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  2866. $query->where(function ($q) use ($data) {
  2867. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  2868. });
  2869. })
  2870. ->select('id', 'sexy', 'experience', 'origin', 'industry', 'name', 'job', 'job_name_get', 'city_arr_id', 'cat_arr_id', 'created_at', 'updated_at')
  2871. ->orderBy('updated_at', 'desc');
  2872. $hunt_count = $query->count();
  2873. $query = clone $query;
  2874. $JobHunting = $query
  2875. ->offset(($data['page'] - 1) * $data['pageSize'])
  2876. ->limit($data['pageSize'])
  2877. ->get();
  2878. if (empty($JobHunting)) {
  2879. $JobRecruiting = "暂无相关简历信息";
  2880. } else {
  2881. $JobHunting = $this->processJob($JobHunting, $website_id);
  2882. }
  2883. }
  2884. $result = [
  2885. 'JobRecruiting' => $JobRecruiting ?? [],
  2886. 'recruit_count' => $recruit_count ?? 0,
  2887. 'JobHunting' => $JobHunting ?? [],
  2888. 'hunt_count' => $hunt_count ?? 0,
  2889. ];
  2890. return Result::success($result);
  2891. }
  2892. /**
  2893. * c端-获取招工招聘详情
  2894. * @param array $data
  2895. * @return array
  2896. * */
  2897. public function getWebsiteJobInfo(array $data): array
  2898. {
  2899. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2900. if (empty($web)) {
  2901. return Result::error("该网站不存在", 0);
  2902. }
  2903. $webid = [
  2904. 'website_id' => $data['website_id'],
  2905. ];
  2906. // 职位相关信息
  2907. if ($data['type'] == 1) {
  2908. $query = JobRecruiting::where('status', 1)
  2909. ->where('website_id', $data['website_id'])
  2910. ->select('*');
  2911. $job = $query->where('job_recruiting.id', $data['id'])->get();
  2912. $company = JobCompany::where('job_id', $data['id'])->select('id', 'business_name', 'company_hy_id', 'company_size', 'company_nature', 'address_arr_id', 'address', 'job_company.email')->get();
  2913. if (!empty($company)) {
  2914. $result['company'] = $this->processJob($company, $webid);
  2915. }
  2916. $other_job = JobRecruiting::where('status', 1)
  2917. ->where('website_id', $data['website_id'])
  2918. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  2919. ->where('id', '!=', $data['id'])
  2920. ->where('user_id', '=', $job[0]['user_id'])
  2921. ->limit($data['pageSize'])
  2922. ->get();
  2923. if (!empty($other_job)) {
  2924. $result['other_job'] = $this->processJob($other_job, $webid);
  2925. }
  2926. } else {
  2927. // 简历相关信息
  2928. $job = JobHunting::where('job_hunting.status', 2)
  2929. ->where('job_hunting.website_id', $data['website_id'])
  2930. ->where('job_hunting.id', $data['id'])
  2931. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  2932. ->select('job_hunting.*', 'user_name')
  2933. ->get();
  2934. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  2935. if (!empty($resume->toArray())) {
  2936. $result['resume'] = 1;
  2937. } else {
  2938. $result['resume'] = 0;
  2939. }
  2940. }
  2941. if (empty($job->toArray())) {
  2942. return Result::error("id参数错误", 0);
  2943. }
  2944. if (!empty($job[0]['job_experience'])) {
  2945. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  2946. if (!empty($job_experience)) {
  2947. // $hy = [];
  2948. foreach ($job_experience as $key => $value) {
  2949. // $id = $value['id'];
  2950. $hy[$key] = $value['job_industry'];
  2951. $zw_id[$key] = $value['job_typename'];
  2952. $jtzw_id[$key] = $value['job_name'];
  2953. }
  2954. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  2955. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  2956. // 先将关联表转换为索引数组,提高查找效率
  2957. $hyLookup = [];
  2958. foreach ($hy_table as $item) {
  2959. $hyLookup[$item['hyid']] = $item['hyname'];
  2960. }
  2961. $zwLookup = [];
  2962. foreach ($zw_table as $item) {
  2963. $zwLookup[$item['zwid']] = $item['zwname'];
  2964. }
  2965. foreach ($job_experience as $key => &$value) {
  2966. // 处理行业名称
  2967. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  2968. $value['hy_name'] = $hyLookup[$hy[$key]];
  2969. }
  2970. // 处理职位名称
  2971. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  2972. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  2973. }
  2974. // 处理具体职位名称
  2975. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  2976. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  2977. }
  2978. }
  2979. // 释放引用,防止意外修改后续代码
  2980. unset($value);
  2981. }
  2982. $result['job_experience'] = $job_experience ?? [];
  2983. }
  2984. if (!empty($job[0]['education_experience'])) {
  2985. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  2986. if (!empty($education_experience)) {
  2987. foreach ($education_experience as $key => $value) {
  2988. // $id = $value['id'];
  2989. $education[$key] = $value['school_education'];
  2990. }
  2991. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  2992. // // 先将关联表转换为索引数组,提高查找效率
  2993. $educationLookup = [];
  2994. foreach ($education_table as $item) {
  2995. $educationLookup[$item['evalue']] = $item['ename'];
  2996. }
  2997. foreach ($education_experience as $key => &$value) {
  2998. // 处理学历名称
  2999. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3000. $value['education_name'] = $educationLookup[$education[$key]];
  3001. }
  3002. }
  3003. }
  3004. $result['education_experience'] = $job_experience ?? [];
  3005. }
  3006. $result['job'] = $this->processJob($job, $webid);
  3007. // // 返现对应的栏目
  3008. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3009. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3010. ->whereIn('category_id', $catid)
  3011. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3012. ->orderBy('pid')->get()->all();
  3013. if (!empty($category)) {
  3014. $result['category'] = $category;
  3015. }
  3016. $result['job'] = $job;
  3017. $result['job_experience'] = $job_experience ?? [];
  3018. $result['education_experience'] = $education_experience ?? [];
  3019. if (empty($result)) {
  3020. return Result::error("参数错误", 0);
  3021. }
  3022. return Result::success($result);
  3023. }
  3024. /**
  3025. * c端-申请职位
  3026. * @param array $data
  3027. * @return array
  3028. * */
  3029. public function getWebsiteJobApply(array $data): array
  3030. {
  3031. // 首先验证网站是否存在
  3032. // return Result::success($data);
  3033. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3034. if (empty($web)) {
  3035. return Result::error("该网站不存在", 0);
  3036. }
  3037. // 验证用户是否存在且为个人会员/管理员
  3038. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3039. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3040. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3041. return Result::error("用户不存在", 0);
  3042. }
  3043. // 去除重复元素和空元素,并保持原始顺序
  3044. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3045. return !empty($value);
  3046. }));
  3047. // 验证职位是否存在 1:审核通过
  3048. $recruiting = JobRecruiting::where('status', 1)
  3049. ->where('website_id', $data['website_id'])
  3050. ->whereIn('id', $data['recruit_id'])
  3051. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3052. if (empty($recruiting)) {
  3053. return Result::error("该职位不存在", 0);
  3054. }
  3055. // 简历是否存在
  3056. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3057. if (empty($hunt_id)) {
  3058. return Result::error("该简历不存在", 0);
  3059. }
  3060. $data['hunt_id'] = $hunt_id['hunt_id'];
  3061. // // 验证是否已投递过该职位
  3062. $apply = JobApply::where('user_id', $data['user_id'])
  3063. ->where('hunt_id', $data['hunt_id'])
  3064. ->where('website_id', $data['website_id'])
  3065. ->whereIn('recruit_id', $data['recruit_id'])
  3066. ->get(['recruit_id']);
  3067. if (!empty($apply->toArray())) {
  3068. return Result::error("您已投递过该职位!");
  3069. }
  3070. $insertData = array_map(function ($recruiting) use ($data) {
  3071. return [
  3072. 'user_id' => $data['user_id'],
  3073. 'hunt_id' => $data['hunt_id'],
  3074. 'website_id' => $data['website_id'],
  3075. 'recruit_id' => $recruiting['recruit_id'],
  3076. 'receiver_id' => $recruiting['receiver_id'],
  3077. 'status' => 1,
  3078. ];
  3079. }, $recruiting);
  3080. // 批量插入数据
  3081. $result = JobApply::insert($insertData);
  3082. if (empty($result)) {
  3083. return Result::error("投递失败", 0);
  3084. }
  3085. return Result::success($result);
  3086. }
  3087. /**
  3088. * 招工招聘-沟通简历
  3089. * @param array $data
  3090. * @return array
  3091. * */
  3092. public function getWebsiteJobResume(array $data): array
  3093. {
  3094. // 首先验证网站是否存在
  3095. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3096. if (empty($web)) {
  3097. return Result::error("该网站不存在", 0);
  3098. }
  3099. // return Result::success($data);
  3100. // 验证用户是否存在且为企业会员/管理员
  3101. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3102. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3103. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3104. return Result::error("用户不存在", 0);
  3105. }
  3106. // 去除重复元素和空元素,并保持原始顺序
  3107. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3108. return !empty($value);
  3109. }));
  3110. // 验证简历是否存在
  3111. $hunting = JobHunting::where('status', 2)
  3112. ->where('website_id', $data['website_id'])
  3113. ->whereIn('id', $data['hunt_id'])
  3114. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3115. if (empty($hunting)) {
  3116. return Result::error("该简历不存在", 0);
  3117. }
  3118. // 验证是否已沟通过该简历
  3119. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3120. ->where('recruit_id', $data['recruit_id'])
  3121. ->where('website_id', $data['website_id'])
  3122. ->whereIn('hunt_id', $data['hunt_id'])
  3123. ->get(['hunt_id']);
  3124. if (!empty($remuse->toArray())) {
  3125. return Result::error("您已沟通过该简历!");
  3126. }
  3127. // 准备要插入的数据数组
  3128. $insertData = array_map(function ($hunting) use ($data) {
  3129. return [
  3130. 'user_id' => $data['user_id'],
  3131. 'recruit_id' => $data['recruit_id'],
  3132. 'website_id' => $data['website_id'],
  3133. 'hunt_id' => $hunting['hunt_id'],
  3134. 'receiver_id' => $hunting['receiver_id'],
  3135. 'status' => 1,
  3136. ];
  3137. }, $hunting);
  3138. // 批量插入数据
  3139. $result = JobRemuse::insert($insertData);
  3140. if (empty($result)) {
  3141. return Result::error("沟通失败", 0);
  3142. }
  3143. return Result::success($result);
  3144. }
  3145. /**
  3146. * 招工招聘 -我的职位(企业会员)
  3147. * @param array $data
  3148. * @return array
  3149. */
  3150. public function getWebsiteJobRecruiting(array $data): array
  3151. {
  3152. $web = Website::where('id', $data['website_id'])->first('id');
  3153. if (empty($web)) {
  3154. return Result::error("该网站不存在", 0);
  3155. }
  3156. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3157. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3158. return Result::error("用户暂无权限!", 0);
  3159. }
  3160. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3161. $result = JobRecruiting::where('website_id', $data['website_id'])
  3162. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3163. $query->where('user_id', $user['id']);
  3164. })
  3165. ->where('status', 1)
  3166. ->select('id', 'title', 'website_id', 'user_id', 'updated_at')
  3167. ->orderBy('updated_at', 'desc')
  3168. ->limit($data['pageSize'])
  3169. ->get();
  3170. if (empty($result)) {
  3171. return Result::error("暂无相关职位信息", 0);
  3172. }
  3173. return Result::success($result);
  3174. }
  3175. /**
  3176. * c端 - 验证路由
  3177. * @param array $data
  3178. * @return array
  3179. */
  3180. /**
  3181. * c端 - 验证路由
  3182. * @param array $data
  3183. * @return array
  3184. */
  3185. public function checkWebsiteRoute(array $data): array
  3186. {
  3187. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3188. if (empty($web)) {
  3189. return Result::error("该网站不存在", 0);
  3190. } elseif ($web['status'] != 1) {
  3191. return Result::error("网站已经关闭", 0);
  3192. }
  3193. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3194. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3195. if (!empty($whiteRouterInfo)) {
  3196. return Result::success($whiteRouterInfo->toArray());
  3197. }
  3198. }
  3199. // 验证栏目路由
  3200. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3201. ->where('aLIas_pinyin', $data['last_route'])
  3202. ->first();
  3203. if (empty($last_category)) {
  3204. return Result::error("该栏目不存在", 0);
  3205. }
  3206. if (isset($data['id']) && !empty($data['id'])) {
  3207. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3208. switch ($last_category['type']) {
  3209. case 1:
  3210. // 文章
  3211. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3212. $article = Article::where('status', 1)
  3213. ->where('id', $data['id'])
  3214. ->where(function ($query) use ($data) {
  3215. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3216. ->orWhereNull("ignore_ids");
  3217. })
  3218. ->first(['cat_arr_id']);
  3219. if (empty($article)) {
  3220. return Result::error("该文章不存在", 0);
  3221. }
  3222. // return Result::success($article);
  3223. break;
  3224. case 2:
  3225. // 商品
  3226. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3227. $article = Good::where('website_id', $data['website_id'])
  3228. ->where('status', 2)
  3229. ->where('id', $data['id'])
  3230. ->first(['cat_arr_id']);
  3231. if (empty($article)) {
  3232. return Result::error("该商品不存在", 0);
  3233. }
  3234. break;
  3235. case 3:
  3236. // 书刊信息
  3237. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3238. $article = Book::where('website_id', $data['website_id'])
  3239. ->where('status', 2)
  3240. ->where('id', $data['id'])
  3241. ->first(['id', 'cat_arr_id']);
  3242. if (empty($article)) {
  3243. return Result::error("该书刊不存在", 0);
  3244. }
  3245. break;
  3246. case 4:
  3247. // 招聘
  3248. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  3249. $article = JobRecruiting::where('website_id', $data['website_id'])
  3250. ->where('status', 1)
  3251. ->where('id', $data['id'])
  3252. ->first(['cat_arr_id']);
  3253. if (empty($article)) {
  3254. return Result::error("该招聘不存在", 0);
  3255. }
  3256. break;
  3257. case 5:
  3258. // 求职
  3259. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3260. $article = JobHunting::where('website_id', $data['website_id'])
  3261. ->where('status', 2)
  3262. ->where('id', $data['id'])
  3263. ->first(['cat_arr_id']);
  3264. if (empty($article)) {
  3265. return Result::error("该求职不存在", 0);
  3266. }
  3267. break;
  3268. case 6:
  3269. // 招工招聘
  3270. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3271. $article = JobRecruiting::where('website_id', $data['website_id'])
  3272. ->where('status', 1)
  3273. ->where('id', $data['id'])
  3274. ->first(['cat_arr_id']);
  3275. if (empty($article)) {
  3276. $article = JobHunting::where('website_id', $data['website_id'])
  3277. ->where('status', 2)
  3278. ->where('id', $data['id'])
  3279. ->first(['cat_arr_id']);
  3280. }
  3281. if (empty($article)) {
  3282. return Result::error("该招工招聘不存在", 0);
  3283. }
  3284. break;
  3285. default:
  3286. return Result::error("该数据不存在", 0);
  3287. break;
  3288. }
  3289. $catid = json_decode($article['cat_arr_id'], true);
  3290. if (empty($catid)) {
  3291. return Result::error("该数据不存在", 0);
  3292. }
  3293. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3294. ->orderByRaw('FIELD(category_id, ' . implode(',', $catid) . ')')
  3295. ->whereIn('category_id', $catid)
  3296. ->pluck('aLIas_pinyin')
  3297. ->implode('/');
  3298. }
  3299. if ($last_category['pid'] != 0) {
  3300. $cat_arr = json_decode($last_category['category_arr_id'], true);
  3301. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3302. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr) . ')')
  3303. ->whereIn('category_id', $cat_arr)
  3304. ->pluck('aLIas_pinyin')
  3305. ->implode('/');
  3306. } else {
  3307. $pinyin = $last_category['aLIas_pinyin'];
  3308. }
  3309. if (empty($pinyin) || $pinyin != $data['all_route']) {
  3310. return Result::error('非法路径!');
  3311. } else {
  3312. return Result::success($pinyin);
  3313. }
  3314. }
  3315. /**
  3316. * 招工招聘 - 获取推荐职位
  3317. * @param array $data
  3318. * @return array
  3319. */
  3320. public function getWebsiteLevelJob(array $data): array
  3321. {
  3322. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3323. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  3324. ->where('job_recruiting.status', 1)
  3325. ->where('job_level', $data['job_level'])
  3326. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3327. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  3328. ->orderBy('job_recruiting.updated_at', 'desc')
  3329. ->limit($data['pageSize'])
  3330. ->get();
  3331. $web = ['website_id' => $data['website_id']];
  3332. if (!empty($job)) {
  3333. $result = $this->processJob($job, $web);
  3334. }
  3335. if (empty($result)) {
  3336. return Result::error("暂无相关职位信息", 0);
  3337. }
  3338. return Result::success($result);
  3339. }
  3340. /**
  3341. * 验证导航名称是否重复
  3342. * @return void
  3343. */
  3344. //20250226 产品列表
  3345. public function getGoodList(array $data): array
  3346. {
  3347. var_dump($data, '---------1-2--');
  3348. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  3349. unset($data['user_type_id']);
  3350. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3351. $where = [];
  3352. if ($type_id != '10000') {
  3353. $where = [
  3354. 'good.user_id' => $user_id,
  3355. ];
  3356. }
  3357. //类型
  3358. if (isset($data['type_id']) && $data['type_id']) {
  3359. $where['good.type_id'] = $data['type_id'];
  3360. }
  3361. //名称
  3362. if (isset($data['name']) && $data['name']) {
  3363. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  3364. }
  3365. //status
  3366. if (isset($data['status']) && $data['status'] != '') {
  3367. $where['good.status'] = $data['status'];
  3368. }
  3369. //status1
  3370. // if (isset($data['status1']) && $data['status1'] == 1) {
  3371. // $status1 = 1;
  3372. // }
  3373. $where1 = [];
  3374. //website_id
  3375. // if (isset($data['website_id']) && $data['website_id']) {
  3376. // $where1 = [
  3377. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  3378. // ];
  3379. // }
  3380. // website_name
  3381. if (isset($data['website_name']) && $data['website_name']) {
  3382. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  3383. }
  3384. // catid
  3385. if (isset($data['category_name']) && $data['category_name']) {
  3386. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  3387. }
  3388. // $result = Good::where($where)
  3389. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  3390. var_dump($where, '---------1---');
  3391. $result = Good::where($where)
  3392. ->when(!empty($where1), function ($query) use ($where1) {
  3393. return $query->where($where1);
  3394. })
  3395. //status 1待审核2已审核3已拒绝
  3396. ->when(isset($data['status1']), function ($query) {
  3397. return $query->whereIn('good.status', [1, 3]);
  3398. })
  3399. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3400. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3401. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3402. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3403. ->orderBy("updated_at", "desc")
  3404. ->limit($data['page_size'])
  3405. ->offset(($data['page'] - 1) * $data['page_size'])
  3406. ->get();
  3407. $count = Good::where($where)
  3408. ->when(!empty($where1), function ($query) use ($where1) {
  3409. return $query->where($where1);
  3410. })
  3411. //status 1待审核2已审核3已拒绝
  3412. ->when(isset($data['status1']), function ($query) {
  3413. return $query->whereIn('good.status', [1, 3]);
  3414. })
  3415. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3416. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3417. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3418. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3419. ->orderBy("updated_at", "desc")->count();
  3420. $data = [
  3421. 'rows' => $result->toArray(),
  3422. 'count' => $count,
  3423. ];
  3424. if (empty($result)) {
  3425. return Result::error("此栏目暂无相关产品", 0);
  3426. }
  3427. return Result::success($data);
  3428. }
  3429. public function getGoodInfo(array $data): array
  3430. {
  3431. $result = Good::where('id', $data['id'])->first();
  3432. if (empty($result)) {
  3433. return Result::error("此产品不存在", 0);
  3434. }
  3435. return Result::success($result);
  3436. }
  3437. public function addGood(array $data): array
  3438. {
  3439. // unset($data['city_arr_id']);
  3440. // unset($data['cat_arr_id']);
  3441. $data['city_id'] = end($data['city_arr_id']);
  3442. $data['catid'] = end($data['cat_arr_id']);
  3443. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3444. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3445. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3446. unset($data['imgUrl']); //大小写
  3447. if (isset($data['price']) && $data['price'] == '') {
  3448. $data['price'] = 0;
  3449. }
  3450. if ($data['imgurl'] == '') {
  3451. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3452. preg_match_all($reg, $data['detail'], $matches);
  3453. if (isset($matches[1][0])) {
  3454. //截取varchar240
  3455. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3456. }
  3457. }
  3458. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3459. //提取标题+内容中的关键词
  3460. $data['keyword'] = $data['name'];
  3461. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3462. Jieba::init(); // 初始化 jieba-php
  3463. Finalseg::init();
  3464. $segList = Jieba::cut($data['keyword']);
  3465. $segList1 = array_slice($segList, 0, 8);
  3466. $data['keyword'] = implode(',', $segList1);
  3467. }
  3468. if ($data['description'] == '') {
  3469. //提取内容中的描述
  3470. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3471. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3472. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  3473. }
  3474. $result = Good::insert($data);
  3475. if (empty($result)) {
  3476. return Result::error("添加失败", 0);
  3477. }
  3478. return Result::success($result);
  3479. }
  3480. public function updateGood(array $data): array
  3481. {
  3482. $data['city_id'] = end($data['city_arr_id']);
  3483. $data['catid'] = end($data['cat_arr_id']);
  3484. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3485. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3486. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3487. //设置东八区
  3488. date_default_timezone_set('Asia/Shanghai');
  3489. $data['updated_at'] = date('Y-m-d H:i:s');
  3490. if (isset($data['price']) && $data['price'] == '') {
  3491. $data['price'] = 0;
  3492. }
  3493. if ($data['imgurl'] == '') {
  3494. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3495. preg_match_all($reg, $data['detail'], $matches);
  3496. if (isset($matches[1][0])) {
  3497. //截取varchar240
  3498. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3499. }
  3500. }
  3501. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3502. //提取标题+内容中的关键词
  3503. $data['keyword'] = $data['name'];
  3504. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3505. Jieba::init(); // 初始化 jieba-php
  3506. Finalseg::init();
  3507. $segList = Jieba::cut($data['keyword']);
  3508. $segList1 = array_slice($segList, 0, 8);
  3509. $data['keyword'] = implode(',', $segList1);
  3510. }
  3511. if ($data['description'] == '') {
  3512. //提取内容中的描述
  3513. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3514. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3515. }
  3516. $result = Good::where('id', $data['id'])->update($data);
  3517. if (empty($result)) {
  3518. return Result::error("更新失败", 0);
  3519. }
  3520. return Result::success($result);
  3521. }
  3522. public function delGood(array $data): array
  3523. {
  3524. $result = Good::where('id', $data['id'])->delete();
  3525. if (empty($result)) {
  3526. return Result::error("删除失败", 0);
  3527. }
  3528. return Result::success($result);
  3529. }
  3530. //20250226 产品列表
  3531. //20250306 求职信息
  3532. public function getJobHuntingList(array $data): array
  3533. {
  3534. $where = [];
  3535. if (isset($data['username']) && !empty($data['username'])) {
  3536. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3537. }
  3538. //status 1待审核2已审核3已拒绝
  3539. if (isset($data['status']) && $data['status'] != '') {
  3540. $where = [
  3541. 'job_hunting.status' => $data['status'],
  3542. ];
  3543. }
  3544. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3545. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3546. unset($data['type_id']);
  3547. if ($type_id != '10000') {
  3548. $where[] = ['job_hunting.user_id', '=', $user_id];
  3549. }
  3550. $result = JobHunting::where($where)
  3551. ->when(!empty($data['status1']), function ($query) use ($data) {
  3552. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3553. })
  3554. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3555. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3556. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  3557. ->orderBy("updated_at", "desc")
  3558. ->limit($data['page_size'])
  3559. ->offset(($data['page'] - 1) * $data['page_size'])
  3560. ->get();
  3561. if (empty($result)) {
  3562. return Result::error("查询失败", 0);
  3563. }
  3564. $count = JobHunting::where($where)
  3565. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3566. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3567. ->count();
  3568. $data = [
  3569. 'rows' => $result->toArray(),
  3570. 'count' => $count,
  3571. ];
  3572. return Result::success($data);
  3573. }
  3574. public function getJobHuntingApply(array $data): array
  3575. {
  3576. var_dump($data, '-----------------test--------1-');
  3577. $where = [];
  3578. if (isset($data['username']) && !empty($data['username'])) {
  3579. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3580. }
  3581. if (isset($data['salary']) && !empty($data['salary'])) {
  3582. $where[] = [
  3583. 'job_hunting.salary',
  3584. '=',
  3585. $data['salary'],
  3586. ];
  3587. }
  3588. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3589. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3590. unset($data['type_id']);
  3591. if ($type_id != '10000') {
  3592. $where[] = ['job_apply.receiver_id', '=', $user_id];
  3593. }
  3594. var_dump($where, '-----------------test---------');
  3595. $result = jobApply::where($where)
  3596. // ->when(!empty($data['status1']), function ($query) use ($data) {
  3597. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3598. // })
  3599. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  3600. ->where('job_enum.egroup', '=', 'income')
  3601. ->where('job_hunting.status', 2) //已审核
  3602. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3603. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3604. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3605. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3606. //职位----是申请职位
  3607. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3608. ->select('job_apply.*', 'job_position.zwname as job_name', 'job_hunting.salary as salary', 'district.name as cityname', 'job_enum.ename as salary_name', 'user.nickname as nickname', 'user.user_name as username', 'job_hunting.updated_at as updated_at')
  3609. ->orderBy("job_hunting.updated_at", "desc")
  3610. ->limit($data['page_size'])
  3611. ->offset(($data['page'] - 1) * $data['page_size'])
  3612. ->get();
  3613. if (empty($result)) {
  3614. return Result::error("查询失败", 0);
  3615. }
  3616. $count = jobApply::where($where)
  3617. ->where('job_enum.egroup', '=', 'income')
  3618. ->where('job_hunting.status', 2) //已审核
  3619. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3620. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3621. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3622. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3623. //职位----是申请职位
  3624. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3625. ->select('job_apply.*', 'job_position.zwname as job_name', 'job_hunting.salary as salary', 'district.name as cityname', 'job_enum.ename as salary_name', 'user.nickname as nickname', 'user.user_name as username', 'job_hunting.updated_at as updated_at')
  3626. ->count();
  3627. $data = [
  3628. 'rows' => $result->toArray(),
  3629. 'count' => $count,
  3630. ];
  3631. return Result::success($data);
  3632. }
  3633. public function addJobHunting(array $data): array
  3634. {
  3635. date_default_timezone_set('Asia/Shanghai');
  3636. unset($data['company_name']);
  3637. unset($data['job_industry']);
  3638. unset($data['job_name']);
  3639. unset($data['department']);
  3640. unset($data['job_timeList']);
  3641. unset($data['job_content']);
  3642. unset($data['job_typename']); //不知道这是啥,
  3643. $data['created_at'] = date('Y-m-d H:i:s');
  3644. $data['updated_at'] = date('Y-m-d H:i:s');
  3645. //根据用户 user_id 只能添加一次
  3646. $result = JobHunting::where('user_id', $data['user_id'])->first();
  3647. if (!empty($result)) {
  3648. return Result::error("您已添加过求职信息", 0);
  3649. }
  3650. var_dump($result, '-----------------test---------');
  3651. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3652. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3653. $cityArr = json_decode($data['city_arr_id'], true);
  3654. $data['city_id'] = end($cityArr);
  3655. } else {
  3656. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3657. $data['city_id'] = end($data['city_arr_id']);
  3658. }
  3659. $result = JobHunting::create($data);
  3660. if (empty($result)) {
  3661. return Result::error("添加失败", 0);
  3662. }
  3663. return Result::success($result);
  3664. }
  3665. public function delJobHunting(array $data): array
  3666. {
  3667. $result = JobHunting::where('id', $data['id'])->delete();
  3668. if (empty($result)) {
  3669. return Result::error("删除失败", 0);
  3670. }
  3671. return Result::success($result);
  3672. }
  3673. public function updateJobHunting(array $data): array
  3674. {
  3675. //设置东八区
  3676. date_default_timezone_set('Asia/Shanghai');
  3677. unset($data['company_name']);
  3678. unset($data['job_industry']);
  3679. unset($data['job_name']);
  3680. unset($data['department']);
  3681. unset($data['job_timeList']);
  3682. unset($data['job_content']);
  3683. unset($data['job_typename']); //不知道这是啥,
  3684. $data['created_at'] = date('Y-m-d H:i:s');
  3685. $data['updated_at'] = date('Y-m-d H:i:s');
  3686. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3687. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3688. $cityArr = json_decode($data['city_arr_id'], true);
  3689. $data['city_id'] = end($cityArr);
  3690. } else {
  3691. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3692. $data['city_id'] = end($data['city_arr_id']);
  3693. }
  3694. $result = JobHunting::where('id', $data['id'])->update($data);
  3695. if (empty($result)) {
  3696. return Result::error("更新失败", 0);
  3697. }
  3698. return Result::success($result);
  3699. }
  3700. public function getJobHuntingInfo(array $data): array
  3701. {
  3702. $result = JobHunting::where('id', $data['id'])->first();
  3703. if (empty($result)) {
  3704. return Result::error("查询失败", 0);
  3705. }
  3706. return Result::success($result);
  3707. }
  3708. public function getJobHuntingData(array $data): array
  3709. {
  3710. $jobEnum = JobEnum::get();
  3711. $jobIndustry = JobIndustry::get();
  3712. $jobNature = JobNature::get();
  3713. $jobPosition = JobPosition::get();
  3714. $data = [
  3715. 'jobEnum' => $jobEnum,
  3716. 'jobIndustry' => $jobIndustry,
  3717. 'jobNature' => $jobNature,
  3718. 'jobPosition' => $jobPosition,
  3719. ];
  3720. return Result::success($data);
  3721. }
  3722. public function delJobHuntingInfo(array $data): array
  3723. {
  3724. $result = JobHunting::where('id', $data['id'])->delete();
  3725. return Result::success();
  3726. }
  3727. //20250324 通知,公告,消息
  3728. public function delNotice(array $data): array
  3729. {
  3730. $result = Notice::where('id', $data['id'])->delete();
  3731. if ($result) {
  3732. return Result::success();
  3733. } else {
  3734. return Result::error("删除失败", 0);
  3735. }
  3736. }
  3737. public function getNoticeInfo(array $data): array
  3738. {
  3739. $result = Notice::where('id', $data['id'])->first();
  3740. // var_dump($result['re_user_ids'], '--------------------');
  3741. if (empty($result)) {
  3742. return Result::error("查询失败", 0);
  3743. }
  3744. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  3745. $re_user_ids = json_decode($result['re_user_ids'], true);
  3746. var_dump($re_user_ids, '--------------1---test---------');
  3747. var_dump($data, '--------------1---test---------');
  3748. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  3749. //如果已经存在,就不再添加
  3750. if (isset($result['read_id']) && !empty($result['read_id'])) {
  3751. $read_id = json_decode($result['read_id'], true);
  3752. if (!is_array($read_id)) {
  3753. $read_id = [];
  3754. }
  3755. if (!in_array($data['user_id'], $read_id)) {
  3756. $read_id[] = $data['user_id'];
  3757. $result['read_id'] = json_encode($read_id);
  3758. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  3759. }
  3760. } else {
  3761. //如果不存在,就添加
  3762. $result['read_id'] = json_encode([$data['user_id']]);
  3763. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  3764. }
  3765. }
  3766. return Result::success($result);
  3767. }
  3768. public function addNotice(array $data): array
  3769. {
  3770. date_default_timezone_set('Asia/Shanghai');
  3771. $data['created_at'] = date('Y-m-d H:i:s');
  3772. $data['updated_at'] = date('Y-m-d H:i:s');
  3773. $user_id = UserInfo::
  3774. //city_id不是null
  3775. whereNotNull('city_id')
  3776. ->whereNotNull('department_id')
  3777. ->where(function ($query) use ($data) {
  3778. $query->where(function ($subQuery) use ($data) {
  3779. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3780. });
  3781. })
  3782. ->where(function ($query) use ($data) {
  3783. $query->where(function ($subQuery) use ($data) {
  3784. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3785. });
  3786. })
  3787. ->pluck('user_id')->toArray();
  3788. $user_id = array_unique($user_id);
  3789. $chat_ids = $user_id;
  3790. $user_id = json_encode($user_id);
  3791. $data['re_user_ids'] = $user_id;
  3792. $result = Notice::insertGetId($data);
  3793. if ($result && $data['is_group'] == 1) {
  3794. //chat_group
  3795. $group_id = PublicData::uuid();
  3796. $groupData = [
  3797. 'id' => $group_id,
  3798. 'creator_id' => $data['user_id'],
  3799. 'group_name' => $data['group_name'] ?? '',
  3800. 'profile' => $data['profile'] ?? 0,
  3801. ];
  3802. var_dump($groupData, '-----------------groupData-------');
  3803. $groupResult = ChatGroups::insertGetId($groupData);
  3804. var_dump($groupResult, '-----------------groupid-------');
  3805. $groupMemberData = [
  3806. 'id' => PublicData::uuid(),
  3807. 'user_id' => $data['user_id'],
  3808. 'group_id' => $group_id,
  3809. 'leader' => 2,
  3810. ];
  3811. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  3812. //$chat_ids 去除掉$data['user_id']
  3813. $chat_ids = array_diff($chat_ids, [$data['user_id']]);
  3814. //插入群成员表
  3815. $groupMemberDataUser = [];
  3816. $chatData = [];
  3817. foreach ($chat_ids as $key => $value) {
  3818. $groupMemberDataUser[] = [
  3819. 'id' => PublicData::uuid(),
  3820. 'user_id' => $value,
  3821. 'group_id' => $group_id,
  3822. 'leader' => 1,
  3823. ];
  3824. $chatData[] = [
  3825. 'user_id' => $value,
  3826. 'msg_type' => 1,
  3827. 'receiver_id' => $group_id,
  3828. 'content' => '通过通知创建群聊',
  3829. 'group_receiver_id' => $data['user_id'],
  3830. 'action' => 'recieved',
  3831. 'created_at' => date('Y-m-d H:i:s'),
  3832. ];
  3833. }
  3834. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  3835. ChatGroupsMember::insert($groupMemberDataUser);
  3836. //插入一条管理员聊天记录
  3837. $chatData[] = [
  3838. 'user_id' => $data['user_id'],
  3839. 'msg_type' => 1,
  3840. 'receiver_id' => $group_id,
  3841. 'content' => '通过通知创建群聊',
  3842. 'group_receiver_id' => $data['user_id'],
  3843. 'action' => 'said',
  3844. 'created_at' => date('Y-m-d H:i:s'),
  3845. ];
  3846. var_dump($chatData, '-----------------chatData-------');
  3847. $chatResult = ChatRecords::insert($chatData);
  3848. //更新result的 group_id
  3849. $data['group_id'] = $group_id;
  3850. Notice::where(['id' => $result])->update($data);
  3851. }
  3852. if (empty($result)) {
  3853. return Result::error("添加失败", 0);
  3854. }
  3855. return Result::success($result);
  3856. }
  3857. public function updateNotice(array $data): array
  3858. {
  3859. date_default_timezone_set('Asia/Shanghai');
  3860. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  3861. $user_id = UserInfo::
  3862. //city_id不是null
  3863. whereNotNull('city_id')
  3864. ->whereNotNull('department_id')
  3865. ->where(function ($query) use ($data) {
  3866. $query->where(function ($subQuery) use ($data) {
  3867. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3868. });
  3869. })
  3870. ->where(function ($query) use ($data) {
  3871. $query->where(function ($subQuery) use ($data) {
  3872. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3873. });
  3874. })
  3875. ->pluck('user_id')->toArray();
  3876. $user_id = array_unique($user_id);
  3877. $user_id = json_encode($user_id);
  3878. $data['re_user_ids'] = $user_id;
  3879. $data['updated_at'] = date('Y-m-d H:i:s');
  3880. $result = Notice::where('id', $data['id'])->update($data);
  3881. return Result::success($result);
  3882. }
  3883. public function getNoticeList(array $data): array
  3884. {
  3885. $where = [];
  3886. //title
  3887. if (isset($data['title']) && !empty($data['title'])) {
  3888. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  3889. }
  3890. //level
  3891. if (isset($data['level']) && !empty($data['level'])) {
  3892. $where[] = ['notice.level', '=', $data['level']];
  3893. }
  3894. //status
  3895. if (isset($data['status']) && !empty($data['status'])) {
  3896. $where[] = ['notice.status', '=', $data['status']];
  3897. }
  3898. var_dump($data, '------------11111-2----test---------');
  3899. if ($data['type_id'] == 10000) {
  3900. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  3901. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3902. })
  3903. ->where($where)
  3904. ->orderBy('updated_at', 'desc')
  3905. ->limit($data['page_size'])
  3906. ->offset(($data['page'] - 1) * $data['page_size'])
  3907. ->get();
  3908. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  3909. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3910. })
  3911. ->where($where)
  3912. ->orderBy('updated_at', 'desc')
  3913. ->count();
  3914. } else {
  3915. $result = Notice::where($where)
  3916. // ->where('user_id', $data['user_id'])
  3917. ->Where(function ($query) use ($data) {
  3918. $query->Where(function ($q) use ($data) {
  3919. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  3920. ->orWhere('notice.user_id', $data['user_id']);
  3921. });
  3922. })
  3923. ->when(!empty($data['status1']), function ($query) use ($data) {
  3924. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3925. })
  3926. ->orderBy('updated_at', 'desc')
  3927. ->limit($data['page_size'])
  3928. ->offset(($data['page'] - 1) * $data['page_size'])
  3929. ->get();
  3930. $total = Notice::where($where)
  3931. ->when(!empty($data['status1']), function ($query) use ($data) {
  3932. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3933. })
  3934. // ->where('user_id', $data['user_id'])
  3935. ->Where(function ($query) use ($data) {
  3936. $query->Where(function ($q) use ($data) {
  3937. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  3938. ->orWhere('notice.user_id', $data['user_id']);
  3939. });
  3940. })
  3941. ->count();
  3942. }
  3943. if (empty($result)) {
  3944. return Result::error("查询失败", 0);
  3945. }
  3946. $data = [
  3947. 'rows' => $result,
  3948. 'count' => $total,
  3949. ];
  3950. return Result::success($data);
  3951. }
  3952. public function getNoticeDetail(array $data): array
  3953. {
  3954. $result = Notice::where('id', $data['id'])->first();
  3955. if (empty($result)) {
  3956. return Result::error("查询失败", 0);
  3957. }
  3958. return Result::success($result);
  3959. }
  3960. public function deleteNotice(array $data): array
  3961. {
  3962. $notice = Notice::where('id', $data['id'])->first();
  3963. if (empty($notice)) {
  3964. return Result::error("删除失败", 0);
  3965. }
  3966. $chat_group_id = $notice->group_id;
  3967. if ($chat_group_id) {
  3968. //删除群聊
  3969. ChatGroups::where('id', $chat_group_id)->delete();
  3970. //删除群成员
  3971. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  3972. //删除群聊记录
  3973. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  3974. }
  3975. $result = Notice::where('id', $data['id'])->delete();
  3976. return Result::success($result);
  3977. }
  3978. public function c(array $data): array
  3979. {
  3980. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  3981. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3982. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  3983. $result = [];
  3984. if ($type_id == 1) {
  3985. //最近的5篇已审的文章
  3986. $apply_articale = Article::where('status', 1)
  3987. ->where('admin_user_id', $user_id)
  3988. ->orderBy('updated_at', 'desc')
  3989. ->limit(5)->get();
  3990. //获取5条单聊未读聊天消息
  3991. $chat = ChatRecords::where('is_read', 0)
  3992. ->where('user_id', $user_id)
  3993. ->where('talk_type', 1)
  3994. ->orderBy('created_at', 'desc')
  3995. ->limit(5)->get();
  3996. //获取5条未读群聊信息
  3997. $chat_group = ChatRecords::where('is_read', 0)
  3998. ->where('user_id', $user_id)
  3999. ->where('talk_type', 2)
  4000. ->orderBy('created_at', 'desc')
  4001. ->limit(5)->get();
  4002. //获取5条用户的已审核商品
  4003. $good = Good::where('status', 2)
  4004. ->where('user_id', $user_id)
  4005. ->orderBy('updated_at', 'desc')
  4006. ->limit(5)->get();
  4007. //获取5条用户待审核的公告
  4008. $notice = Notice::where('status', 2)
  4009. ->where('user_id', $user_id)
  4010. ->orderBy('updated_at', 'desc')
  4011. ->limit(5)->get();
  4012. //获取5条用户的待审核投诉
  4013. $complaint = Complaint::where('status', 2)
  4014. ->where('user_id', $user_id)
  4015. ->orderBy('updated_at', 'desc')
  4016. ->limit(5)->get();
  4017. //获取5条用户的book
  4018. $book = Book::where('status', 2)
  4019. ->where('user_id', $user_id)
  4020. ->orderBy('updated_at', 'desc')
  4021. ->limit(5)->get();
  4022. //获取5条用户的求职
  4023. //获取5条用户的求职 1
  4024. $job_hunting = JobHunting::where('job_hunting.status', 1)
  4025. ->where('job_hunting.user_id', $user_id)
  4026. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4027. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  4028. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  4029. ->orderBy('updated_at', 'desc')
  4030. ->limit(5)->get();
  4031. //获取5条用户的求职 2
  4032. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  4033. ->where('job_recruiting.user_id', $user_id)
  4034. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4035. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4036. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  4037. ->orderBy('updated_at', 'desc')
  4038. ->limit(5)->get();
  4039. //人才库 1
  4040. $job_apply = JobApply::where('job_apply.status', 1)
  4041. ->where('job_apply.receiver_id', $user_id)
  4042. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  4043. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  4044. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  4045. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  4046. ->select('job_recruiting', 'job_recruiting.', '', '')
  4047. ->select('job_apply.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name', 'job_company.business_name as business_name', 'job_recruiting.title as job_name')
  4048. ->orderBy('updated_at', 'desc')
  4049. ->limit(5)->get();
  4050. // 职场机会 2
  4051. $job_resume = JobResume::where('job_resume.status', 1)
  4052. ->where('job_resume.receiver_id', $user_id)
  4053. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  4054. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  4055. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  4056. ->select('job_resume.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name', 'job_company.business_name as business_name')
  4057. ->orderBy('updated_at', 'desc')
  4058. ->limit(5)->get();
  4059. // count($chat) + count($chat_group) +
  4060. $count = count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting) + count($job_apply) + count($job_resume);
  4061. $result = [
  4062. 'apply_articale' => $apply_articale,
  4063. 'chat' => $chat,
  4064. 'chat_group' => $chat_group,
  4065. 'good' => $good,
  4066. 'notice' => $notice,
  4067. 'complaint' => $complaint,
  4068. 'book' => $book,
  4069. 'job_hunting' => $job_hunting,
  4070. 'job_recruiting' => $job_recruiting,
  4071. 'job_apply' => $job_apply,
  4072. 'job_resume' => $job_resume,
  4073. 'count' => $count,
  4074. ];
  4075. } elseif ($type_id == 2) {
  4076. //最近的5篇已审的文章
  4077. $apply_articale = Article::where('status', 1)
  4078. ->where('admin_user_id', $user_id)
  4079. ->limit(5)->get();
  4080. //获取5条单聊未读聊天消息
  4081. $chat = ChatRecords::where('is_read', 0)
  4082. ->where('user_id', $user_id)
  4083. ->where('talk_type', 1)
  4084. ->orderBy('created_at', 'desc')
  4085. ->limit(5)->get();
  4086. //获取5条未读群聊信息
  4087. $chat_group = ChatRecords::where('is_read', 0)
  4088. ->where('user_id', $user_id)
  4089. ->where('talk_type', 2)
  4090. ->orderBy('created_at', 'desc')
  4091. ->limit(5)->get();
  4092. //获取5条用户的已审核商品
  4093. $good = Good::where('status', 2)
  4094. ->where('user_id', $user_id)
  4095. ->orderBy('updated_at', 'desc')
  4096. ->limit(5)->get();
  4097. //count($chat) + count($chat_group)
  4098. $count = count($apply_articale) + count($good);
  4099. $result = [
  4100. 'apply_articale' => $apply_articale,
  4101. 'chat' => $chat,
  4102. 'chat_group' => $chat_group,
  4103. 'good' => $good,
  4104. 'count' => $count,
  4105. ];
  4106. } elseif ($type_id == 3) {
  4107. //最近的5篇已审的文章
  4108. $apply_articale = Article::where('status', 1)
  4109. ->where('admin_user_id', $user_id)
  4110. ->limit(5)->get();
  4111. //获取5条单聊未读聊天消息
  4112. $chat = ChatRecords::where('is_read', 0)
  4113. ->where('user_id', $user_id)
  4114. ->where('talk_type', 1)
  4115. ->orderBy('created_at', 'desc')
  4116. ->limit(5)->get();
  4117. //获取5条未读群聊信息
  4118. $chat_group = ChatRecords::where('is_read', 0)
  4119. ->where('user_id', $user_id)
  4120. ->where('talk_type', 2)
  4121. ->orderBy('created_at', 'desc')
  4122. ->limit(5)->get();
  4123. //获取5条用户的已审核商品
  4124. $good = Good::where('status', 2)
  4125. ->where('user_id', $user_id)
  4126. ->orderBy('updated_at', 'desc')
  4127. ->limit(5)->get();
  4128. //count($chat) + count($chat_group) +
  4129. $count = count($apply_articale) + count($good);
  4130. $result = [
  4131. 'apply_articale' => $apply_articale,
  4132. 'chat' => $chat,
  4133. 'chat_group' => $chat_group,
  4134. 'good' => $good,
  4135. 'count' => $count,
  4136. ];
  4137. } elseif ($type_id == 4) {
  4138. //最近的5篇已审的文章
  4139. $apply_articale = Article::where('status', 1)
  4140. ->where('admin_user_id', $user_id)
  4141. ->limit(5)->get();
  4142. //获取5条用户的已审核商品
  4143. $good = Good::where('status', 2)
  4144. ->where('user_id', $user_id)
  4145. ->orderBy('updated_at', 'desc')
  4146. ->limit(5)->get();
  4147. $count = count($apply_articale) + count($good);
  4148. $result = [
  4149. 'apply_articale' => $apply_articale,
  4150. 'chat' => '',
  4151. 'chat_group' => '',
  4152. 'good' => $good,
  4153. 'count' => $count,
  4154. ];
  4155. } elseif ($type_id == 10000) {
  4156. //获取未审核的5篇文章
  4157. $apply_articale = Article::where('status', 0)
  4158. ->orderBy('updated_at', 'desc')
  4159. ->limit(5)->get();
  4160. //获取5条单聊未读聊天消息
  4161. $chat = ChatRecords::where('is_read', 0)
  4162. ->where('user_id', $user_id)
  4163. ->where('talk_type', 1)
  4164. ->orderBy('created_at', 'desc')
  4165. ->limit(5)->get();
  4166. //获取5条未读群聊信息
  4167. $chat_group = ChatRecords::where('is_read', 0)
  4168. ->where('user_id', $user_id)
  4169. ->where('talk_type', 2)
  4170. ->orderBy('created_at', 'desc')
  4171. ->limit(5)->get();
  4172. //获取5条用户的已审核商品
  4173. $good = Good::where('status', 1)
  4174. // ->where('user_id', $user_id)
  4175. ->orderBy('updated_at', 'desc')
  4176. ->limit(5)->get();
  4177. //获取5条用户待审核的公告
  4178. $notice = Notice::where('status', 1)
  4179. ->orderBy('updated_at', 'desc')
  4180. ->limit(5)->get();
  4181. //获取5条用户的待审核投诉
  4182. $complaint = Complaint::where('status', 1)
  4183. ->orderBy('updated_at', 'desc')
  4184. ->limit(5)->get();
  4185. //获取5条用户的book
  4186. $book = Book::where('status', 1)
  4187. ->orderBy('updated_at', 'desc')
  4188. ->limit(5)->get();
  4189. //获取5条用户的求职 1
  4190. $job_hunting = JobHunting::where('job_hunting.status', 1)
  4191. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4192. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  4193. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  4194. ->orderBy('updated_at', 'desc')
  4195. ->limit(5)->get();
  4196. //获取5条用户的求职 2
  4197. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  4198. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4199. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4200. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  4201. ->orderBy('updated_at', 'desc')
  4202. ->limit(5)->get();
  4203. //人才库 1
  4204. $job_apply = JobApply::where('job_apply.status', 1)
  4205. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  4206. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  4207. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  4208. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  4209. ->select('job_apply.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name', 'job_company.business_name as business_name', 'job_recruiting.title as job_name')
  4210. ->orderBy('updated_at', 'desc')
  4211. ->limit(5)->get();
  4212. // 职场机会 2
  4213. $job_resume =
  4214. JobResume::where('job_resume.status', 1)
  4215. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  4216. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  4217. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  4218. ->select('job_resume.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name', 'job_company.business_name as business_name')
  4219. ->orderBy('updated_at', 'desc')
  4220. ->limit(5)->get();
  4221. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting) + count($job_apply) + count($job_resume);
  4222. $result = [
  4223. 'apply_articale' => $apply_articale,
  4224. 'chat' => $chat,
  4225. 'chat_group' => $chat_group,
  4226. 'good' => $good,
  4227. 'notice' => $notice,
  4228. 'complaint' => $complaint,
  4229. 'book' => $book,
  4230. 'job_hunting' => $job_hunting,
  4231. 'job_recruiting' => $job_recruiting,
  4232. 'job_apply' => $job_apply,
  4233. 'job_resume' => $job_resume,
  4234. 'count' => $count,
  4235. ];
  4236. } elseif ($type_id == 20000) {
  4237. }
  4238. var_dump($type_id, '-----------------test---------');
  4239. return Result::success($result);
  4240. }
  4241. public function getComplaintList(array $data): array
  4242. {
  4243. var_dump($data, '00000001000000000000');
  4244. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4245. unset($data['type_id']);
  4246. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4247. $where = [];
  4248. if ($type_id != 10000 && empty($data['deal_user'])) {
  4249. $where['complaint.user_id'] = $user_id;
  4250. }
  4251. if (!empty($data['title'])) {
  4252. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4253. }
  4254. if (!empty($data['department_id'])) {
  4255. $where['complaint.department_id'] = $data['department_id'];
  4256. }
  4257. if (!empty($data['deal'])) {
  4258. $where['complaint.deal'] = $data['deal'];
  4259. }
  4260. if (!empty($data['status'])) {
  4261. $where['complaint.status'] = $data['status'];
  4262. }
  4263. var_dump(!empty($data['deal_user']), '----------1');
  4264. var_dump($where, '----------2');
  4265. $result = Complaint::where($where)
  4266. ->when(!empty($data['status1']), function ($query) use ($data) {
  4267. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4268. })
  4269. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4270. //json re_user_ids data[user_id]是不是在里面
  4271. $query->Where(function ($q) use ($data) {
  4272. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4273. ->where('complaint.status', 2);
  4274. });
  4275. })
  4276. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4277. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4278. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4279. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4280. ->orderBy('updated_at', 'desc')
  4281. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4282. //sql输出
  4283. if (empty($result)) {
  4284. return Result::error("暂无投诉信息", 0);
  4285. }
  4286. // 取出数据
  4287. $rows = $result->items();
  4288. $count = $result->total();
  4289. $responseData = [
  4290. 'rows' => $rows,
  4291. 'count' => $count,
  4292. ];
  4293. return Result::success($responseData);
  4294. }
  4295. public function getComplaintInfo(array $data): array
  4296. {
  4297. $result = Complaint::where('id', $data['id'])->first();
  4298. if (empty($result)) {
  4299. return Result::error("查询失败", 0);
  4300. }
  4301. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4302. $re_user_ids = json_decode($result['re_user_ids'], true);
  4303. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4304. //如果已经存在,就不再添加
  4305. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4306. $read_id = json_decode($result['read_id'], true);
  4307. if (!is_array($read_id)) {
  4308. $read_id = [];
  4309. }
  4310. if (!in_array($data['user_id'], $read_id)) {
  4311. $read_id[] = $data['user_id'];
  4312. $result['read_id'] = json_encode($read_id);
  4313. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4314. }
  4315. } else {
  4316. //如果不存在,就添加
  4317. $result['read_id'] = json_encode([$data['user_id']]);
  4318. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4319. }
  4320. }
  4321. return Result::success($result);
  4322. }
  4323. public function addComplaint(array $data): array
  4324. {
  4325. date_default_timezone_set('Asia/Shanghai');
  4326. $data['created_at'] = date('Y-m-d H:i:s');
  4327. $data['updated_at'] = date('Y-m-d H:i:s');
  4328. $result = Complaint::create($data);
  4329. return Result::success($result);
  4330. }
  4331. public function updateComplaint(array $data): array
  4332. {
  4333. date_default_timezone_set('Asia/Shanghai');
  4334. $data['updated_at'] = date('Y-m-d H:i:s');
  4335. $user_id = $data['user_id'] ?? 0;
  4336. $type_id = $data['type_id'] ?? 0;
  4337. unset($data['user_id']);
  4338. unset($data['type_id']);
  4339. $result = Complaint::where('id', $data['id'])->update($data);
  4340. return Result::success($result);
  4341. }
  4342. public function deleteComplaint(array $data): array
  4343. {
  4344. $result = Complaint::where('id', $data['id'])->delete();
  4345. return Result::success($result);
  4346. }
  4347. public function getComplainInfo(array $data): array
  4348. {
  4349. $result = Complaint::where('id', $data['id'])->first();
  4350. if (empty($result)) {
  4351. return Result::error("查询失败", 0);
  4352. }
  4353. return Result::success($result);
  4354. }
  4355. public function updateComplaintStatus(array $data): array
  4356. {
  4357. date_default_timezone_set('Asia/Shanghai');
  4358. $data['updated_at'] = date('Y-m-d H:i:s');
  4359. $user_id = $data['user_id'] ?? 0;
  4360. $type_id = $data['type_id'] ?? 0;
  4361. unset($data['user_id']);
  4362. unset($data['type_id']);
  4363. //处理, 写入处理人
  4364. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4365. $data['real_deal_user'] = $user_id;
  4366. }
  4367. //如果是deal 23,则判断是不是处理人
  4368. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4369. $complaintInof = Complaint::where('id', $data['id'])
  4370. ->where('real_deal_user', $user_id)
  4371. ->first();
  4372. if (empty($complaintInof)) {
  4373. return Result::error("处理人错误", 0);
  4374. }
  4375. }
  4376. $result = complaint::where('id', $data['id'])->update($data);
  4377. return Result::success($result);
  4378. }
  4379. public function updateGoodStatus(array $data): array
  4380. {
  4381. $user_id = $data['user_id'] ?? 0;
  4382. $type_id = $data['type_id'] ?? 0;
  4383. unset($data['user_id']);
  4384. unset($data['type_id']);
  4385. $result = Good::where('id', $data['id'])->update($data);
  4386. return Result::success($result);
  4387. }
  4388. public function updateJobHuntingStatus(array $data): array
  4389. {
  4390. $user_id = $data['user_id'] ?? 0;
  4391. $type_id = $data['type_id'] ?? 0;
  4392. unset($data['user_id']);
  4393. unset($data['type_id']);
  4394. $result = JobHunting::where('id', $data['id'])->update($data);
  4395. return Result::success($result);
  4396. }
  4397. public function updateNoticeStatus(array $data): array
  4398. {
  4399. $user_id = $data['user_id'] ?? 0;
  4400. $type_id = $data['type_id'] ?? 0;
  4401. unset($data['user_id']);
  4402. unset($data['type_id']);
  4403. $result = Notice::where('id', $data['id'])->update($data);
  4404. return Result::success($result);
  4405. }
  4406. public function getDUser(array $data): array
  4407. {
  4408. if (!empty($data['ids'])) {
  4409. $user = User::whereIn('id', $data['ids'])->getall();
  4410. if (empty($user)) {
  4411. return Result::error('无数据', 0);
  4412. }
  4413. return Result::success($user);
  4414. }
  4415. $where = [];
  4416. if (!empty($data['department_id'])) {
  4417. $where['department_id'] = $data['department_id'];
  4418. }
  4419. if (!empty($data['city_id'])) {
  4420. $where['city_id'] = $data['city_id'];
  4421. }
  4422. $result = User::where('type_id', 2)
  4423. ->where('status', 1)
  4424. ->where($where)
  4425. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  4426. ->get();
  4427. if (empty($result)) {
  4428. return Result::error("查询失败", 0);
  4429. }
  4430. return Result::success($result);
  4431. }
  4432. /**
  4433. * 验证导航名称是否重复
  4434. * @return void
  4435. */
  4436. public function checkCategoryName(array $data): array
  4437. {
  4438. $result = Category::when($data, function ($query) use ($data) {
  4439. if (isset($data['name']) && $data['name']) {
  4440. $query->where("name", $data['name']);
  4441. }
  4442. if (isset($data['id']) && $data['id']) {
  4443. $query->where("id", "!=", $data['id']);
  4444. }
  4445. })->first();
  4446. if ($result) {
  4447. return Result::error("已存在");
  4448. } else {
  4449. return Result::success();
  4450. }
  4451. }
  4452. //20250226 产品列表
  4453. // 20250306 -------招聘--------fr
  4454. /*
  4455. * 招聘列表
  4456. * */
  4457. public function getJobRecruitingList(array $data): array
  4458. {
  4459. $where = [];
  4460. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  4461. if ($data['checkout'] == 0) {
  4462. $job_status = [0, 2];
  4463. } else {
  4464. $job_status = [1];
  4465. }
  4466. if (isset($data['keyword']) && !empty($data['keyword'])) {
  4467. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  4468. }
  4469. $user = User::where('id', $data['user_id'])->first();
  4470. if (empty($user)) {
  4471. return Result::error("用户不存在", 0);
  4472. }
  4473. // 3:企业会员
  4474. if ($user['type_id'] == 3) {
  4475. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  4476. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  4477. }
  4478. // 如果 $where 为空,则不添加 where 条件
  4479. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4480. return $query->where($where);
  4481. })
  4482. ->whereIn('job_recruiting.status', $job_status)
  4483. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4484. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4485. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  4486. ->orderBy("updated_at", "desc")
  4487. ->offset(($data['page'] - 1) * $data['page_size'])
  4488. ->limit($data['page_size'])
  4489. ->get()
  4490. ->all();
  4491. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4492. return $query->where($where);
  4493. })
  4494. ->whereIn('job_recruiting.status', $job_status)
  4495. ->count();
  4496. if (empty($result)) {
  4497. return Result::error("暂无招聘信息", 0);
  4498. }
  4499. return Result::success($result);
  4500. }
  4501. /*
  4502. * 招聘信息添加
  4503. * */
  4504. public function addJobRecruiting(array $data): array
  4505. {
  4506. // return Result::success($data);
  4507. $user = User::where('user.id', $data['user_id'])
  4508. ->where('user.status', 1)
  4509. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4510. ->select(
  4511. 'user.type_id',
  4512. 'user.mobile',
  4513. 'user.email',
  4514. 'user_info.business_name',
  4515. 'user_info.company_hy_id',
  4516. 'user_info.company_nature',
  4517. 'user_info.company_size',
  4518. 'user_info.introduction',
  4519. 'user_info.real_name',
  4520. 'user_info.company_url',
  4521. 'user_info.address_arr_id',
  4522. 'user_info.address'
  4523. )
  4524. ->first();
  4525. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4526. return Result::error("用户不存在", 0);
  4527. }
  4528. $web = Website::where('id', $data['website_id'])->first();
  4529. if (empty($web)) {
  4530. return Result::error("网站不存在", 0);
  4531. }
  4532. // return Result::success($user);
  4533. $data['action_id'] = $data['user_id'];
  4534. $data['user_type'] = $user['type_id'];
  4535. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4536. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4537. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4538. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4539. // 公司地址 管理员必填
  4540. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4541. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4542. // 管理员-企业相关信息
  4543. $company = [
  4544. // 'user_id' => $data['user_id']?? null,
  4545. 'business_name' => $data['business_name'] ?? null,
  4546. 'company_hy_id' => $data['company_hy_id'] ?? null,
  4547. 'company_size' => $data['company_size'] ?? null,
  4548. 'company_nature' => $data['company_nature'] ?? null,
  4549. 'introduction' => $data['introduction'] ?? null,
  4550. 'real_name' => $data['real_name'] ?? null,
  4551. 'mobile' => $data['mobile'] ?? null,
  4552. 'company_url' => $data['company_url'] ?? null,
  4553. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4554. 'address' => $data['address'] ?? null,
  4555. 'email' => $data['email'] ?? null,
  4556. ];
  4557. //去掉相关企业信息
  4558. $job = array_diff_key($data, array_flip(array_keys($company)));
  4559. Db::beginTransaction();
  4560. try {
  4561. // 先添加职位相关信息
  4562. if ($user['type_id'] == 10000) {
  4563. $job['status'] = 1;
  4564. }
  4565. if (empty($data['experience']) || $data['experience'] == '') {
  4566. $job['experience'] = null;
  4567. } else {
  4568. $job['experience'] = $data['experience'];
  4569. }
  4570. $jobId = JobRecruiting::insertGetId($job);
  4571. if (empty($jobId)) {
  4572. Db::rollBack();
  4573. return Result::error("添加失败");
  4574. }
  4575. // 添加公司信息
  4576. $company['user_id'] = $data['user_id'] ?? null;
  4577. $company['job_id'] = $jobId;
  4578. $company['user_type'] = $user['type_id'] ?? null;
  4579. $company['website_id'] = $data['website_id'] ?? null;
  4580. if ($user['type_id'] == 10000) {
  4581. // 管理员添加企业信息
  4582. // return Result::success($company);
  4583. $companyId = JobCompany::insertGetId($company);
  4584. if (empty($companyId)) {
  4585. Db::rollBack();
  4586. return Result::error("添加失败");
  4587. }
  4588. } else {
  4589. // 企业会员添加企业信息
  4590. $company = [
  4591. 'user_id' => $data['user_id'] ?? null,
  4592. 'business_name' => $user['business_name'] ?? null,
  4593. 'company_hy_id' => $user['company_hy_id'] ?? null,
  4594. 'company_size' => $user['company_size'] ?? null,
  4595. 'company_nature' => $user['company_nature'] ?? null,
  4596. 'introduction' => $user['introduction'] ?? null,
  4597. 'real_name' => $user['real_name'] ?? null,
  4598. 'mobile' => $user['mobile'] ?? null,
  4599. 'company_url' => $user['company_url'] ?? null,
  4600. 'address_arr_id' => $user['address_arr_id'] ?? null,
  4601. 'address' => $user['address'] ?? null,
  4602. 'email' => $user['email'] ?? null,
  4603. 'website_id' => $data['website_id'] ?? null,
  4604. 'user_type' => $user['type_id'] ?? null,
  4605. 'job_id' => $jobId,
  4606. ];
  4607. $companyId = JobCompany::insertGetId($company);
  4608. if (empty($companyId)) {
  4609. Db::rollBack();
  4610. return Result::error("添加失败");
  4611. }
  4612. // return Result::success($company);
  4613. }
  4614. Db::commit();
  4615. } catch (\Exception $e) {
  4616. Db::rollBack();
  4617. return Result::error($e->getMessage(), 0);
  4618. }
  4619. $result = [
  4620. 'job_id' => $jobId,
  4621. 'company_id' => $companyId,
  4622. ];
  4623. if (empty($result)) {
  4624. return Result::error("添加失败", 0);
  4625. }
  4626. return Result::success($result);
  4627. }
  4628. /*
  4629. * 获取招聘信息详情
  4630. * */
  4631. public function getJobRecruitingInfo(array $data): array
  4632. {
  4633. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  4634. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4635. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4636. ->select(
  4637. 'job_recruiting.*',
  4638. 'website.website_name as website_name',
  4639. 'job_company.business_name',
  4640. 'job_company.company_hy_id',
  4641. 'job_company.company_size',
  4642. 'job_company.company_nature',
  4643. 'job_company.introduction',
  4644. 'job_company.real_name',
  4645. 'job_company.mobile',
  4646. 'job_company.company_url',
  4647. 'job_company.address_arr_id',
  4648. 'job_company.address',
  4649. 'job_company.email'
  4650. )
  4651. ->first();
  4652. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  4653. if (!empty($cityId)) {
  4654. if (isset($cityId[1]) && $cityId[1] != null) {
  4655. $city = District::where('id', $cityId[1])->first(['name']);
  4656. } else {
  4657. $city = District::where('id', $cityId[0])->first(['name']);
  4658. }
  4659. $result['city'] = $city['name'] ?? '';
  4660. }
  4661. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  4662. if (is_array($addressId) && !empty($addressId)) {
  4663. $address = District::whereIn('id', $addressId)
  4664. ->orderBy('level', 'asc')
  4665. ->get(['name'])
  4666. ->pluck('name')
  4667. ->implode('');
  4668. // $job->address_name = $address ?? '';
  4669. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  4670. }
  4671. if (empty($result)) {
  4672. return Result::error("招聘信息不存在", 0);
  4673. }
  4674. // return Result::success($job);
  4675. return Result::success($result);
  4676. }
  4677. /*
  4678. * 修改招聘信息
  4679. * */
  4680. public function upJobRecruiting(array $data): array
  4681. {
  4682. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  4683. // return Result::success($job);
  4684. if (empty($job)) {
  4685. return Result::error("招聘信息不存在", 0);
  4686. }
  4687. $user = User::where('id', $data['user_id'])->first();
  4688. // return Result::success($user);
  4689. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4690. return Result::error("用户不存在", 0);
  4691. }
  4692. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4693. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4694. }
  4695. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4696. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4697. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4698. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4699. // 公司地址 管理员必填
  4700. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4701. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4702. // 管理员-企业相关信息
  4703. $company = [
  4704. 'business_name' => $data['business_name'] ?? null,
  4705. 'company_hy_id' => $data['hy_id'] ?? null,
  4706. 'company_size' => $data['company_size'] ?? null,
  4707. 'company_nature' => $data['company_nature'] ?? null,
  4708. 'introduction' => $data['introduction'] ?? null,
  4709. 'real_name' => $data['real_name'] ?? null,
  4710. 'mobile' => $data['mobile'] ?? null,
  4711. 'company_url' => $data['company_url'] ?? null,
  4712. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4713. 'address' => $data['address'] ?? null,
  4714. 'email' => $data['email'] ?? null,
  4715. ];
  4716. //去掉相关企业信息
  4717. $data = array_diff_key($data, array_flip(array_keys($company)));
  4718. $jobId = $data['id'];
  4719. $web = $data['website_id'];
  4720. $data['action_id'] = $data['user_id'];
  4721. unset($data['user_id']);
  4722. unset($data['user_type']);
  4723. unset($data['id']);
  4724. unset($data['website_id']);
  4725. // return Result::success($data);
  4726. Db::beginTransaction();
  4727. try {
  4728. // 管理员修改招聘信息
  4729. if ($user['type_id'] == 10000) {
  4730. $data['website_id'] = $web;
  4731. $company['website_id'] = $data['website_id'];
  4732. $data['status'] = 1;
  4733. } else {
  4734. $data['status'] = 0;
  4735. }
  4736. if (empty($data['experience']) || $data['experience'] == '') {
  4737. $job['experience'] = null;
  4738. } else {
  4739. $job['experience'] = $data['experience'];
  4740. }
  4741. // Db::rollBack();
  4742. // return Result::success($company);
  4743. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  4744. if (empty($result['job'])) {
  4745. Db::rollBack();
  4746. return Result::error("修改招聘信息失败");
  4747. }
  4748. // 管理员修改企业相关信息
  4749. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  4750. if (empty($result['company'])) {
  4751. Db::rollBack();
  4752. return Result::error("修改企业相关信息失败");
  4753. }
  4754. Db::commit();
  4755. // return Result::success($result);
  4756. } catch (\Exception $e) {
  4757. Db::rollBack();
  4758. return Result::error($e->getMessage(), 0);
  4759. }
  4760. return Result::success($result);
  4761. }
  4762. /*
  4763. * 招聘信息删除
  4764. * */
  4765. public function delJobRecruiting(array $data): array
  4766. {
  4767. $user = User::where('id', $data['user_id'])->first();
  4768. if (empty($user)) {
  4769. return Result::error("用户不存在", 0);
  4770. }
  4771. $job = JobRecruiting::where('id', $data['id'])->first();
  4772. if (empty($job)) {
  4773. return Result::error("招聘信息不存在", 0);
  4774. }
  4775. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4776. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4777. }
  4778. Db::beginTransaction();
  4779. try {
  4780. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  4781. if (empty($result['job'])) {
  4782. Db::rollBack();
  4783. return Result::error("删除招聘信息失败");
  4784. }
  4785. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  4786. if (empty($result['company'])) {
  4787. Db::rollBack();
  4788. return Result::error("删除企业相关信息失败");
  4789. }
  4790. Db::commit();
  4791. } catch (\Exception $e) {
  4792. Db::rollBack();
  4793. return Result::error($e->getMessage(), 0);
  4794. }
  4795. return Result::success($result);
  4796. }
  4797. /*
  4798. * 获取公司信息
  4799. * */
  4800. public function getJobCompany(array $data): array
  4801. {
  4802. $user = User::where('user.id', $data['user_id'])
  4803. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4804. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  4805. ->first();
  4806. // return Result::success($user);
  4807. if (empty($user)) {
  4808. return Result::error("用户不存在", 0);
  4809. }
  4810. if ($user['type_id'] == 3) {
  4811. $result = [
  4812. // 'id' => 0,
  4813. 'user_id' => $data['user_id'],
  4814. 'website_id' => $data['website_id'],
  4815. 'business_name' => $user['business_name'], // 企业名称
  4816. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  4817. 'company_nature' => $user['company_nature'], // 公司性质
  4818. 'company_size' => $user['company_size'], // 公司规模
  4819. 'introduction' => $user['introduction'], // 公司简介
  4820. 'real_name' => $user['real_name'], // 企业联系人
  4821. 'mobile' => $user['mobile'], // 企业联系电话
  4822. 'company_url' => $user['company_url'], // 企业网址
  4823. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  4824. 'address' => $user['address'], // 企业地址
  4825. 'email' => $user['email'], // 企业邮箱
  4826. ];
  4827. } else {
  4828. return Result::error("用户类型错误", 0);
  4829. }
  4830. if (empty($result)) {
  4831. return Result::error("公司信息不存在", 0);
  4832. }
  4833. return Result::success($result);
  4834. }
  4835. /*
  4836. * 修改公司信息
  4837. * */
  4838. public function upJobCompany(array $data): array
  4839. {
  4840. // return Result::success($data);
  4841. $user = User::where('user.id', $data['user_id'])
  4842. ->where('user.status', 1)
  4843. ->select('user.user_name', 'user.type_id')
  4844. ->first();
  4845. if (empty($user)) {
  4846. return Result::error("用户不存在", 0);
  4847. }
  4848. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4849. $company = [
  4850. 'business_name' => $data['business_name'], // 企业名称
  4851. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4852. 'company_nature' => $data['company_nature'], // 公司性质
  4853. 'company_size' => $data['company_size'], // 公司规模
  4854. 'introduction' => $data['introduction'], // 公司简介
  4855. // 'real_name' => $data['real_name'], // 企业联系人
  4856. 'company_url' => $data['company_url'], // 企业网址
  4857. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4858. 'address' => $data['address'], // 企业详细地址
  4859. ];
  4860. if ($user['type_id'] == 3) {
  4861. Db::beginTransaction();
  4862. try {
  4863. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  4864. 'business_name' => $data['business_name'], // 企业名称
  4865. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4866. 'company_nature' => $data['company_nature'], // 公司性质
  4867. 'company_size' => $data['company_size'], // 公司规模
  4868. 'introduction' => $data['introduction'], // 公司简介
  4869. // 'real_name' => $data['real_name'], // 企业联系人
  4870. 'company_url' => $data['company_url'], // 企业网址
  4871. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4872. 'address' => $data['address'], // 企业详细地址
  4873. ]);
  4874. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  4875. Db::commit();
  4876. } catch (\Exception $e) {
  4877. Db::rollBack();
  4878. return Result::error($e->getMessage(), 0);
  4879. }
  4880. } else {
  4881. return Result::error("用户类型错误", 0);
  4882. }
  4883. if (empty($result)) {
  4884. return Result::error("修改失败", 0);
  4885. }
  4886. return Result::success($result);
  4887. }
  4888. /*
  4889. * 获取省-市
  4890. * */
  4891. public function getJobRecruitingArea(array $data): array
  4892. {
  4893. if (isset($data['pid']) && $data['pid'] != null) {
  4894. $result = District::where('pid', $data['pid'])->get()->all();
  4895. } else {
  4896. $result = District::where('level', 1)->get()->all();
  4897. }
  4898. if (empty($result)) {
  4899. return Result::error("暂无此省市", 0);
  4900. }
  4901. return Result::success($result);
  4902. }
  4903. /*
  4904. * 获取行业分类
  4905. * */
  4906. public function getIndustry(array $data): array
  4907. {
  4908. $result = JobIndustry::get()->all();
  4909. if (empty($result)) {
  4910. return Result::error("暂无行业分类", 0);
  4911. }
  4912. return Result::success($result);
  4913. }
  4914. /*
  4915. * 获取职位
  4916. * */
  4917. public function getPositionList(array $data): array
  4918. {
  4919. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  4920. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  4921. } else {
  4922. $result = JobPosition::where('zwpid', 0)->get()->all();
  4923. }
  4924. if (empty($result)) {
  4925. return Result::error("暂无此职位", 0);
  4926. }
  4927. return Result::success($result);
  4928. }
  4929. /*
  4930. * 获取工作性质-菜单
  4931. * */
  4932. public function getJobNature(array $data): array
  4933. {
  4934. $result = JobEnum::where('egroup', 'nature')->get()->all();
  4935. if (empty($result)) {
  4936. return Result::error("暂无工作性质", 0);
  4937. }
  4938. return Result::success($result);
  4939. }
  4940. /*
  4941. * 获取工作经验-菜单
  4942. * */
  4943. public function getExperience(array $data): array
  4944. {
  4945. $result = JobEnum::where('egroup', 'years')->get()->all();
  4946. if (empty($result)) {
  4947. return Result::error("暂无工作经验", 0);
  4948. }
  4949. return Result::success($result);
  4950. }
  4951. /*
  4952. * 获取学历-菜单
  4953. * */
  4954. public function getEducation(array $data): array
  4955. {
  4956. $result = JobEnum::where('egroup', 'education')->get()->all();
  4957. if (empty($result)) {
  4958. return Result::error("暂无学历", 0);
  4959. }
  4960. return Result::success($result);
  4961. }
  4962. /*
  4963. * 获取薪资-菜单
  4964. * */
  4965. public function getSalary(array $data): array
  4966. {
  4967. $result = JobEnum::where('egroup', 'income')->get()->all();
  4968. if (empty($result)) {
  4969. return Result::error("暂无薪资", 0);
  4970. }
  4971. return Result::success($result);
  4972. }
  4973. /*
  4974. * 获取语言-菜单
  4975. * */
  4976. public function getLanguage(array $data): array
  4977. {
  4978. $result = JobEnum::where('egroup', 'language')->get()->all();
  4979. if (empty($result)) {
  4980. return Result::error("暂无语言", 0);
  4981. }
  4982. return Result::success($result);
  4983. }
  4984. /*
  4985. * 获取掌握程度-菜单
  4986. * */
  4987. public function getLevel(array $data): array
  4988. {
  4989. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  4990. if (empty($result)) {
  4991. return Result::error("暂无工作性质", 0);
  4992. }
  4993. return Result::success($result);
  4994. }
  4995. // 公司信息
  4996. /*
  4997. * 获取公司性质-菜单
  4998. * */
  4999. public function getCompanyNature(array $data): array
  5000. {
  5001. $result = JobNature::get()->all();
  5002. if (empty($result)) {
  5003. return Result::error("暂无公司性质", 0);
  5004. }
  5005. return Result::success($result);
  5006. }
  5007. /*
  5008. * 获取公司规模-菜单
  5009. * */
  5010. public function getCompanySize(array $data): array
  5011. {
  5012. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  5013. if (empty($result)) {
  5014. return Result::error("暂无公司规模", 0);
  5015. }
  5016. return Result::success($result);
  5017. }
  5018. /*
  5019. * 招聘信息审核
  5020. * */
  5021. public function checkJobRecruiting(array $data): array
  5022. {
  5023. $user = User::where('id', $data['user_id'])->first();
  5024. if (empty($user)) {
  5025. return Result::error("用户不存在", 0);
  5026. }
  5027. $job = JobRecruiting::where('id', $data['id'])->first();
  5028. if (empty($job)) {
  5029. return Result::error("招聘信息不存在", 0);
  5030. }
  5031. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  5032. if ($user['type_id'] != 10000) {
  5033. return Result::error("用户暂无权限审核此招聘信息!", 0);
  5034. }
  5035. // 驳回原因
  5036. if ($data['status'] == 2) {
  5037. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  5038. }
  5039. $data['action_id'] = $data['user_id'];
  5040. unset($data['user_id']);
  5041. $result = JobRecruiting::where('id', $data['id'])->update($data);
  5042. if (empty($result)) {
  5043. return Result::error("审核失败", 0);
  5044. }
  5045. return Result::success($result);
  5046. }
  5047. public function myApplyList(array $data): array
  5048. {
  5049. var_dump($data, '------参数');
  5050. $user = User::where('id', $data['user_id'])->first();
  5051. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5052. return Result::error("用户不存在", 0);
  5053. }
  5054. // 1:个人会员 职场机会
  5055. if ($user['type_id'] == 1) {
  5056. $where['user_id'] = $user['id'];
  5057. }
  5058. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  5059. $query->where('user_id', $user['id']);
  5060. })
  5061. ->pluck('recruit_id');
  5062. $where = [];
  5063. if (isset($data['salary']) && $data['salary'] != null) {
  5064. $where['job_recruiting.salary'] = $data['salary'];
  5065. }
  5066. if (isset($data['experience']) && $data['experience'] != null) {
  5067. $where['job_recruiting.experience'] = $data['experience'];
  5068. }
  5069. if (isset($data['business_name']) && $data['business_name'] != null) {
  5070. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5071. }
  5072. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5073. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5074. ->where($where);
  5075. // ->count();
  5076. $count = $query->count();
  5077. $query = clone $query;
  5078. $job = $query
  5079. ->leftJoin('job_enum as income_enum', function ($join) {
  5080. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5081. ->where('income_enum.egroup', 'income');
  5082. })
  5083. ->leftJoin('job_enum as years_enum', function ($join) {
  5084. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5085. ->where('years_enum.egroup', 'years');
  5086. })
  5087. // ->where($where)
  5088. ->orderBy('job_recruiting.updated_at', 'desc')
  5089. ->select(
  5090. 'job_recruiting.id',
  5091. 'job_recruiting.title',
  5092. 'job_company.business_name',
  5093. 'income_enum.evalue as salary_evalue',
  5094. 'income_enum.ename as salary_ename',
  5095. 'years_enum.evalue as experience_evalue',
  5096. 'years_enum.ename as experience_ename',
  5097. 'job_recruiting.updated_at'
  5098. )
  5099. ->offset(($data['page'] - 1) * $data['pageSize'])
  5100. ->limit($data['pageSize'])
  5101. ->get()
  5102. ->all();
  5103. if (empty($job)) {
  5104. return Result::error("暂无招聘信息", 0);
  5105. }
  5106. $result = [
  5107. 'row' => $job,
  5108. 'count' => $count,
  5109. ];
  5110. return Result::success($result);
  5111. }
  5112. /*
  5113. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  5114. * */
  5115. public function getRecruitingList(array $data): array
  5116. {
  5117. $user = User::where('id', $data['user_id'])->first();
  5118. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5119. return Result::error("用户不存在", 0);
  5120. }
  5121. // 1:个人会员 职场机会
  5122. if ($user['type_id'] == 1) {
  5123. $where['user_id'] = $user['id'];
  5124. }
  5125. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  5126. $query->where('receiver_id', $user['id']);
  5127. })
  5128. ->pluck('recruit_id');
  5129. // return Result::success($recruitingId);
  5130. $where = [];
  5131. if (isset($data['salary']) && $data['salary'] != null) {
  5132. $where['job_recruiting.salary'] = $data['salary'];
  5133. }
  5134. if (isset($data['experience']) && $data['experience'] != null) {
  5135. $where['job_recruiting.experience'] = $data['experience'];
  5136. }
  5137. if (isset($data['business_name']) && $data['business_name'] != null) {
  5138. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5139. }
  5140. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5141. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5142. ->where($where);
  5143. // ->count();
  5144. $count = $query->count();
  5145. $query = clone $query;
  5146. $job = $query
  5147. ->leftJoin('job_enum as income_enum', function ($join) {
  5148. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5149. ->where('income_enum.egroup', 'income');
  5150. })
  5151. ->leftJoin('job_enum as years_enum', function ($join) {
  5152. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5153. ->where('years_enum.egroup', 'years');
  5154. })
  5155. // ->where($where)
  5156. ->orderBy('job_recruiting.updated_at', 'desc')
  5157. ->select(
  5158. 'job_recruiting.id',
  5159. 'job_recruiting.title',
  5160. 'job_company.business_name',
  5161. 'income_enum.evalue as salary_evalue',
  5162. 'income_enum.ename as salary_ename',
  5163. 'years_enum.evalue as experience_evalue',
  5164. 'years_enum.ename as experience_ename',
  5165. 'job_recruiting.updated_at'
  5166. )
  5167. ->offset(($data['page'] - 1) * $data['pageSize'])
  5168. ->limit($data['pageSize'])
  5169. ->get()
  5170. ->all();
  5171. if (empty($job)) {
  5172. return Result::error("暂无招聘信息", 0);
  5173. }
  5174. $result = [
  5175. 'row' => $job,
  5176. 'count' => $count,
  5177. ];
  5178. return Result::success($result);
  5179. }
  5180. /*
  5181. * 获取企业会员-招聘信息列表
  5182. * */
  5183. public function getRecruitingInfo(array $data): array
  5184. {
  5185. $user = User::where('id', $data['user_id'])->first();
  5186. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5187. return Result::error("用户不存在", 0);
  5188. }
  5189. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  5190. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5191. ->select(
  5192. 'job_recruiting.*',
  5193. 'job_company.business_name',
  5194. 'job_company.company_hy_id',
  5195. 'job_company.company_size',
  5196. 'job_company.company_nature',
  5197. 'job_company.introduction',
  5198. 'job_company.real_name',
  5199. 'job_company.mobile',
  5200. 'job_company.company_url',
  5201. 'job_company.address_arr_id',
  5202. 'job_company.address',
  5203. 'job_company.email'
  5204. )
  5205. ->get();
  5206. if (empty($recruiting)) {
  5207. return Result::error("暂无招聘信息", 0);
  5208. }
  5209. return Result::success($recruiting);
  5210. }
  5211. /*
  5212. * 获取企业会员-我的沟通
  5213. * */
  5214. public function getJobResumeList(array $data): array
  5215. {
  5216. $user = User::where('id', $data['user_id'])->first();
  5217. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  5218. return Result::error("用户不存在", 0);
  5219. }
  5220. $where = [];
  5221. if (isset($data['salary']) && $data['salary'] != null) {
  5222. $where['job_hunting.salary'] = $data['salary'];
  5223. }
  5224. if (isset($data['user_name']) && $data['user_name'] != null) {
  5225. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  5226. }
  5227. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  5228. $query->where('job_resume.user_id', $user['id']);
  5229. })
  5230. ->when(!empty($where), function ($query) use ($where) {
  5231. $query->where($where);
  5232. })
  5233. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  5234. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  5235. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  5236. ->select('job_resume.hunt_id', 'job_resume.recruit_id', 'job_hunting.id', 'job_hunting.salary', 'job_hunting.city_id', 'job_hunting.updated_at', 'job_recruiting.jtzw_id', 'user.user_name');
  5237. $count = $job->count();
  5238. if ($count == 0) {
  5239. return Result::error("暂无沟通记录", 0);
  5240. }
  5241. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  5242. ->offset(($data['page'] - 1) * $data['pageSize'])
  5243. ->limit($data['pageSize'])
  5244. ->get();
  5245. if (empty($jobs)) {
  5246. return Result::error("暂无沟通记录", 0);
  5247. }
  5248. $result['row'] = $this->processJob($jobs, '');
  5249. $result['count'] = $count;
  5250. return Result::success($result);
  5251. }
  5252. // 20250306 招聘
  5253. //20250422 书刊音像
  5254. public function addBook(array $data): array
  5255. {
  5256. // $user_id = $data['user_id'] ?? 0;
  5257. $type_id = $data['type_id'] ?? 0;
  5258. // $website_id = $data['website_id'] ?? 0;
  5259. // unset($data['user_id']);
  5260. unset($data['type_id']);
  5261. // unset($data['website_id']);
  5262. //处理数组
  5263. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5264. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5265. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5266. if ($data['img_url'] == '') {
  5267. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5268. preg_match_all($reg, $data['detail'], $matches);
  5269. if (isset($matches[1][0])) {
  5270. //截取varchar240
  5271. $data['img_url'] = substr($matches[1][0], 0, 240);
  5272. }
  5273. }
  5274. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  5275. //提取标题+内容中的关键词
  5276. $data['keyword'] = $data['title'];
  5277. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5278. Jieba::init(); // 初始化 jieba-php
  5279. Finalseg::init();
  5280. $segList = Jieba::cut($data['keyword']);
  5281. $segList1 = array_slice($segList, 0, 8);
  5282. $data['keyword'] = implode(',', $segList1);
  5283. }
  5284. if ($data['description'] == '') {
  5285. //提取内容中的描述
  5286. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5287. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5288. }
  5289. var_dump($data, '--');
  5290. $result = Book::insertGetId($data);
  5291. if (empty($result)) {
  5292. return Result::error("添加失败", 0);
  5293. }
  5294. return Result::success($result);
  5295. }
  5296. public function getBookList(array $data): array
  5297. {
  5298. $where = [];
  5299. if (!empty($data["title"])) {
  5300. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  5301. }
  5302. if (!empty($data['website_name'])) {
  5303. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  5304. }
  5305. if (!empty($data['status'])) {
  5306. $where[] = ['book.status', '=', $data['status']];
  5307. }
  5308. $user_id = $data['user_id'];
  5309. $type_id = $data['type_id'];
  5310. // $type_id = 4;
  5311. var_dump($type_id, '------1--------');
  5312. if ($type_id != 10000) {
  5313. $where[] = ['book.user_id', '=', $user_id];
  5314. }
  5315. var_dump(!empty($data['status1']), '=-===1');
  5316. $result = Book::where($where)
  5317. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  5318. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  5319. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  5320. ->when(isset($data['status1']), function ($query) use ($data) {
  5321. $query->whereIn('book.status', [1, 3]);
  5322. })
  5323. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  5324. ->orderBy("updated_at", "desc")
  5325. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5326. if (empty($result)) {
  5327. return Result::error("暂无数据", 0);
  5328. }
  5329. // 取出数据
  5330. $rows = $result->items();
  5331. $count = $result->total();
  5332. $responseData = [
  5333. 'rows' => $rows,
  5334. 'count' => $count,
  5335. ];
  5336. return Result::success($responseData);
  5337. }
  5338. public function deleteBook(array $data): array
  5339. {
  5340. $result = Book::where('id', $data['id'])->delete();
  5341. if (empty($result)) {
  5342. return Result::error("删除失败", 0);
  5343. }
  5344. return Result::success($result);
  5345. }
  5346. public function updateBook(array $data): array
  5347. {
  5348. // $user_id = $data['user_id'] ?? 0;
  5349. $type_id = $data['type_id'] ?? 0;
  5350. // $website_id = $data['website_id'] ?? 0;
  5351. unset($data['user_id']);
  5352. unset($data['type_id']);
  5353. // unset($data['website_id']);
  5354. //处理数组
  5355. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5356. if ($data['img_url'] == '') {
  5357. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5358. preg_match_all($reg, $data['detail'], $matches);
  5359. if (isset($matches[1][0])) {
  5360. //截取varchar240
  5361. $data['img_url'] = substr($matches[1][0], 0, 240);
  5362. }
  5363. }
  5364. if ($data['keyword'] == '') {
  5365. //提取标题+内容中的关键词
  5366. $data['keyword'] = $data['title'];
  5367. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5368. Jieba::init(); // 初始化 jieba-php
  5369. Finalseg::init();
  5370. $segList = Jieba::cut($data['keyword']);
  5371. $segList1 = array_slice($segList, 0, 8);
  5372. $data['keyword'] = implode(',', $segList1);
  5373. }
  5374. if ($data['description'] == '') {
  5375. //提取内容中的描述
  5376. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5377. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5378. }
  5379. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5380. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5381. $result = Book::where("id", $data["id"])->update($data);
  5382. if (empty($result)) {
  5383. return Result::error("更新失败", 0);
  5384. }
  5385. return Result::success($result);
  5386. }
  5387. public function getBookInfo(array $data): array
  5388. {
  5389. $result = Book::where("id", $data["id"])->first();
  5390. if (empty($result)) {
  5391. return Result::error("获取失败", 0);
  5392. }
  5393. return Result::success($result);
  5394. }
  5395. public function updateBookStatus(array $data): array
  5396. {
  5397. //审核
  5398. unset($data['user_id']);
  5399. $result = Book::where("id", $data["id"])->update($data);
  5400. if (empty($result)) {
  5401. return Result::error("更新失败", 0);
  5402. }
  5403. return Result::success($result);
  5404. }
  5405. //20250422 书刊音像
  5406. /**
  5407. * 贴身宝贝
  5408. * @param array $data
  5409. * @return array
  5410. */
  5411. public function getWebsiteTsbb(array $data): array
  5412. {
  5413. $month = $data['month'] ?? date('m');
  5414. $day = $data['day'] ?? date('d');
  5415. // 使用缓存键
  5416. $cacheKey = "tsbb_data_{$month}_{$day}";
  5417. // 尝试从缓存获取数据
  5418. $container = \Hyperf\Context\ApplicationContext::getContainer();
  5419. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  5420. if ($cachedData = $cache->get($cacheKey)) {
  5421. return Result::success(unserialize($cachedData));
  5422. }
  5423. //查询老黄历
  5424. try {
  5425. $date = date('Y-m-d');
  5426. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  5427. // 使用 curl 替代 file_get_contents
  5428. $ch = curl_init();
  5429. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  5430. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  5431. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  5432. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  5433. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  5434. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36');
  5435. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  5436. 'Accept: application/json',
  5437. 'Content-Type: application/json',
  5438. 'Referer: https://www.36jxs.com/'
  5439. ]);
  5440. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  5441. curl_setopt($ch, CURLOPT_ENCODING, '');
  5442. $almanacResponse = curl_exec($ch);
  5443. var_dump("====:", $almanacResponse);
  5444. if (curl_errno($ch)) {
  5445. var_dump('Curl error:', curl_error($ch));
  5446. throw new \Exception('Curl error: ' . curl_error($ch));
  5447. }
  5448. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  5449. curl_close($ch);
  5450. if ($almanacResponse === false) {
  5451. throw new \Exception('Failed to fetch almanac data');
  5452. }
  5453. $almanacData = json_decode($almanacResponse, true);
  5454. if (json_last_error() !== JSON_ERROR_NONE) {
  5455. throw new \Exception('Failed to parse almanac data');
  5456. }
  5457. $almanacInfo = $almanacData['data'] ?? [];
  5458. } catch (\Exception $e) {
  5459. var_dump('Exception:', $e->getMessage());
  5460. $almanacInfo = [];
  5461. }
  5462. // 获取历史上的今天数据
  5463. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5464. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  5465. ->orderBy('year', 'asc')
  5466. ->select("title", "id", "year", DB::raw('1 as type'))
  5467. ->limit(16)
  5468. ->get();
  5469. // 获取节日数据 - 从今天开始获取未来4条
  5470. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  5471. ->orderBy('showtime', 'asc')
  5472. ->select("title", "id", "showtime", DB::raw('2 as type'))
  5473. ->limit(16)
  5474. ->get();
  5475. //说文解字
  5476. $chartacterList = Character::orderBy('updated_at', 'desc')
  5477. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  5478. ->limit(6)
  5479. ->get();
  5480. //谜语沙龙
  5481. $riddletList = Riddle::orderBy('updated_at', 'desc')
  5482. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  5483. ->limit(4)
  5484. ->get();
  5485. //成语欣赏
  5486. $idiomList = Idiom::orderBy('updated_at', 'desc')
  5487. ->select("id", "title", "duyin", DB::raw('5 as type'))
  5488. ->limit(32)
  5489. ->get();
  5490. //名联赏析
  5491. $coupletList = Couplet::orderBy('updated_at', 'desc')
  5492. ->select("id", "first", "second", DB::raw('6 as type'))
  5493. ->limit(6)
  5494. ->get();
  5495. // 获取分类文章数据
  5496. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  5497. ->pluck('category_id')
  5498. ->toArray();
  5499. $articlesList = [];
  5500. foreach ($categoryIds as $catid) {
  5501. // 先查有图片的
  5502. $withImg = DB::table('article')
  5503. ->where('status', 1)
  5504. ->where('catid', $catid)
  5505. ->whereNotNull('imgurl')
  5506. ->where('imgurl', '!=', '')
  5507. ->orderBy('updated_at', 'desc')
  5508. ->limit(6)
  5509. ->get();
  5510. $count = $withImg->count();
  5511. if ($count < 6) {
  5512. // 不足6条再查无图片的补足
  5513. $withoutImg = DB::table('article')
  5514. ->where('status', 1)
  5515. ->where('catid', $catid)
  5516. ->where(function ($q) {
  5517. $q->whereNull('imgurl')->orWhere('imgurl', '');
  5518. })
  5519. ->orderBy('updated_at', 'desc')
  5520. ->limit(6 - $count)
  5521. ->get();
  5522. $articles = $withImg->concat($withoutImg);
  5523. } else {
  5524. $articles = $withImg;
  5525. }
  5526. // 组装
  5527. $category = \App\Model\Category::find($catid);
  5528. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  5529. $articlesList[] = [
  5530. 'category_name' => $category ? $category->name : '',
  5531. 'catid' => $catid,
  5532. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  5533. 'type' => 100,
  5534. 'list' => $articles->map(function ($item) {
  5535. return [
  5536. 'id' => $item->id,
  5537. 'title' => $item->title,
  5538. 'imgurl' => $item->imgurl,
  5539. 'created_at' => $item->created_at
  5540. ];
  5541. })->values()
  5542. ];
  5543. }
  5544. $result = [
  5545. 'almanac' => $almanacInfo,
  5546. 'historyTodayList' => [
  5547. 'category_name' => '历史上的今天',
  5548. 'list' => $historyTodayList,
  5549. 'type' => 1
  5550. ],
  5551. 'festivalList' => [
  5552. 'category_name' => '节日预告',
  5553. 'list' => $festivalList,
  5554. 'type' => 2
  5555. ],
  5556. 'chartacterList' => [
  5557. 'category_name' => '说文解字',
  5558. 'list' => $chartacterList,
  5559. 'type' => 3
  5560. ],
  5561. 'coupletList' => [
  5562. 'category_name' => '名联赏析',
  5563. 'list' => $coupletList,
  5564. 'type' => 6
  5565. ],
  5566. 'riddletList' => [
  5567. 'category_name' => '谜语沙龙',
  5568. 'list' => $riddletList,
  5569. 'type' => 4
  5570. ],
  5571. 'idiomList' => [
  5572. 'category_name' => '成语欣赏',
  5573. 'list' => $idiomList,
  5574. 'type' => 5
  5575. ],
  5576. 'articlesList' => $articlesList
  5577. ];
  5578. // 缓存结果,设置1小时过期
  5579. $cache->set($cacheKey, serialize($result), 3600);
  5580. return Result::success($result);
  5581. }
  5582. /**
  5583. * 获取资讯列表
  5584. */
  5585. public function getWebsiteTsbbList(array $data): array
  5586. {
  5587. $page = $data['page'] ?? 1;
  5588. $pageSize = $data['pageSize'] ?? 10;
  5589. // 如果没有传入月份和日期,则使用今天的日期
  5590. $month = $data['month'] ?? date('m');
  5591. $day = $data['day'] ?? date('d');
  5592. $total = 0;
  5593. $result = [];
  5594. $data['type'] = intval($data['type']);
  5595. var_dump("接收参数:", $data);
  5596. switch ($data['type']) {
  5597. case 1:
  5598. $query = HistoryToday::where(function ($q) use ($month, $day) {
  5599. // 当前月份之后的数据
  5600. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  5601. // 或者当前月份且日期大于等于当前日期的数据
  5602. ->orWhere(function ($q) use ($month, $day) {
  5603. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5604. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  5605. });
  5606. })
  5607. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  5608. $total = $query->count();
  5609. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  5610. ->offset(($page - 1) * $pageSize)
  5611. ->limit($pageSize)
  5612. ->get();
  5613. break;
  5614. case 2:
  5615. $query = Festival::where(function ($q) use ($month, $day) {
  5616. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  5617. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  5618. ->orWhere(function ($q) use ($month, $day) {
  5619. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  5620. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  5621. });
  5622. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  5623. $total = $query->count();
  5624. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  5625. ->offset(($page - 1) * $pageSize)
  5626. ->limit($pageSize)
  5627. ->get();
  5628. break;
  5629. case 3:
  5630. $query = Character::orderBy("updated_at", "desc");
  5631. $total = $query->count();
  5632. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  5633. ->offset(($page - 1) * $pageSize)
  5634. ->limit($pageSize)
  5635. ->get();
  5636. break;
  5637. case 4:
  5638. $query = Riddle::orderBy("updated_at", "desc");
  5639. $total = $query->count();
  5640. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  5641. ->offset(($page - 1) * $pageSize)
  5642. ->limit($pageSize)
  5643. ->get();
  5644. break;
  5645. case 5:
  5646. $query = Idiom::orderBy("updated_at", "desc");
  5647. $total = $query->count();
  5648. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  5649. ->offset(($page - 1) * $pageSize)
  5650. ->limit($pageSize)
  5651. ->get();
  5652. break;
  5653. case 6:
  5654. $query = Couplet::orderBy("updated_at", "desc");
  5655. $total = $query->count();
  5656. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  5657. ->offset(($page - 1) * $pageSize)
  5658. ->limit($pageSize)
  5659. ->get();
  5660. break;
  5661. default:
  5662. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  5663. $total = $query->count();
  5664. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  5665. ->offset(($page - 1) * $pageSize)
  5666. ->limit($pageSize)
  5667. ->get();
  5668. }
  5669. return Result::success([
  5670. 'list' => $result,
  5671. 'total' => $total,
  5672. 'page' => (int)$page,
  5673. 'pageSize' => (int)$pageSize,
  5674. 'month' => $month,
  5675. 'day' => $day
  5676. ]);
  5677. }
  5678. /**
  5679. * 1:历史上的今天
  5680. * 2:节日
  5681. * 3:文章
  5682. *
  5683. * 资讯详情信息
  5684. */
  5685. public function getWebsiteTsbbDetail(array $data): array
  5686. {
  5687. $data['type'] = intval($data['type']);
  5688. switch ($data['type']) {
  5689. case 1:
  5690. $result = HistoryToday::where("id", $data['id'])->first();
  5691. break;
  5692. case 2:
  5693. $result = Festival::where("id", $data['id'])->first();
  5694. break;
  5695. case 3:
  5696. $result = Character::where("id", $data['id'])->first();
  5697. break;
  5698. case 4:
  5699. $result = Riddle::where("id", $data['id'])->first();
  5700. break;
  5701. case 5:
  5702. $result = Idiom::where("id", $data['id'])->first();
  5703. break;
  5704. case 6:
  5705. $result = Couplet::where("id", $data['id'])->first();
  5706. break;
  5707. default:
  5708. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  5709. break;
  5710. }
  5711. return Result::success($result);
  5712. }
  5713. /**
  5714. * 农网导航首页数据
  5715. */
  5716. public function getWebsiteNwHomeList(array $data): array
  5717. {
  5718. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  5719. ->pluck('category_id')
  5720. ->toArray();
  5721. // 使用子查询优化
  5722. $articlesList = DB::table('article')
  5723. ->select([
  5724. 'article.id',
  5725. 'article.title',
  5726. 'article.imgurl',
  5727. 'article.created_at',
  5728. 'category.name as category_name',
  5729. 'category.id as category_id',
  5730. 'website_category.aLIas_pinyin as pinyin',
  5731. 'parent_wc.aLIas_pinyin as parent_pinyin',
  5732. DB::raw('100 as type')
  5733. ])
  5734. ->join('category', 'article.catid', '=', 'category.id')
  5735. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  5736. ->leftJoin('website_category as parent_wc', function ($join) {
  5737. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  5738. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  5739. })
  5740. ->where('website_category.website_id', $data['website_id'])
  5741. ->where('article.status', 1)
  5742. ->whereIn('category.id', $categoryIds)
  5743. ->orderBy('article.created_at', 'desc')
  5744. ->get()
  5745. ->groupBy('category_id')
  5746. ->map(function ($group) {
  5747. // 确保第一条数据有图片
  5748. $firstWithImage = $group->first(function ($item) {
  5749. return !empty($item->imgurl);
  5750. });
  5751. if ($firstWithImage) {
  5752. // 如果有带图片的文章,将其放在第一位
  5753. $group = $group->filter(function ($item) use ($firstWithImage) {
  5754. return $item->id !== $firstWithImage->id;
  5755. })->prepend($firstWithImage);
  5756. }
  5757. return [
  5758. 'category_name' => $group->first()->category_name,
  5759. 'catid' => $group->first()->category_id,
  5760. 'pinyin' => $group->first()->pinyin,
  5761. 'parent_pinyin' => $group->first()->parent_pinyin,
  5762. 'list' => $group->take(4)->map(function ($item) {
  5763. return [
  5764. 'id' => $item->id,
  5765. 'title' => $item->title,
  5766. ];
  5767. })->values()
  5768. ];
  5769. })
  5770. ->values()
  5771. ->toArray();
  5772. return Result::success($articlesList);
  5773. }
  5774. /**
  5775. * 企业管理
  5776. * @param array $data
  5777. * @return array
  5778. */
  5779. public function getCompanyList(array $data): array
  5780. {
  5781. // return Result::success($data);
  5782. $where = [];
  5783. $user = User::where('id', $data['user_id'])->first();
  5784. if (empty($user)) {
  5785. return Result::error('用户不存在!');
  5786. }
  5787. if ($user['type_id'] != 10000) {
  5788. $where['user_id'] = $data['user_id'];
  5789. }
  5790. if (isset($data['title']) && !empty($data['title'])) {
  5791. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  5792. }
  5793. if (isset($data['website_name']) && !empty($data['website_name'])) {
  5794. array_push($where, ['website.website_name', 'like', '%' . $data['website_name'] . '%']);
  5795. }
  5796. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  5797. if ($data['ischeck'] == 1) {
  5798. if (isset($data['status']) && $data['status'] != '') {
  5799. array_push($where, ['company.status', $data['status']]);
  5800. $query = Company::where($where);
  5801. } else {
  5802. $query = Company::whereIn('company.status', [0, 2]);
  5803. }
  5804. if ($user['type_id'] != 10000) {
  5805. $where['user_id'] = $data['user_id'];
  5806. }
  5807. if (isset($data['title']) && !empty($data['title'])) {
  5808. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  5809. }
  5810. if (isset($data['website_id']) && !empty($data['website_id'])) {
  5811. array_push($where, ['website.id', $data['website_id']]);
  5812. }
  5813. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  5814. if ($data['ischeck'] == 1) {
  5815. if (isset($data['status']) && $data['status'] != '') {
  5816. array_push($where, ['company.status', $data['status']]);
  5817. $query = Company::where($where);
  5818. } else {
  5819. $query = Company::whereIn('company.status', [0, 2]);
  5820. }
  5821. } else {
  5822. $query = Company::where('company.status', 1);
  5823. }
  5824. }
  5825. $result = $query->where($where)
  5826. ->leftJoin('website_category', function ($query) {
  5827. $query->on('website_category.category_id', '=', 'company.category_id')
  5828. ->on('website_category.website_id', '=', 'company.website_id');
  5829. })
  5830. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  5831. ->select(
  5832. 'company.id',
  5833. 'company.title',
  5834. 'company.website_id',
  5835. 'company.category_id',
  5836. 'website.website_name',
  5837. 'website_category.alias as category_name',
  5838. 'company.status',
  5839. 'company.updated_at',
  5840. )
  5841. ->orderBy('company.updated_at', 'desc')
  5842. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  5843. if ($result->isEmpty()) {
  5844. return Result::error("暂无企业", 0);
  5845. }
  5846. }
  5847. $result = $query->where($where)
  5848. ->leftJoin('website_category', function ($query) {
  5849. $query->on('website_category.category_id', '=', 'company.category_id')
  5850. ->on('website_category.website_id', '=', 'company.website_id');
  5851. })
  5852. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  5853. ->select(
  5854. 'company.id',
  5855. 'company.title',
  5856. 'company.website_id',
  5857. 'company.category_id',
  5858. 'website.website_name',
  5859. 'website_category.alias as category_name',
  5860. 'company.status',
  5861. 'company.updated_at',
  5862. )
  5863. ->orderBy('company.updated_at', 'desc')
  5864. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  5865. if ($result->isEmpty()) {
  5866. return Result::error("暂无企业", 0);
  5867. }
  5868. return Result::success($result);
  5869. }
  5870. }
  5871. /**
  5872. * 添加企业
  5873. * @param array $data
  5874. * @return array
  5875. */
  5876. public function addCompany(array $data): array
  5877. {
  5878. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  5879. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5880. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  5881. $data['cat_arr_id'] = json_encode($car_arr_id);
  5882. } else {
  5883. $data['cat_arr_id'] = '';
  5884. }
  5885. if ($data['imgurl'] == '') {
  5886. //content中提取图片第一个图,正则提取
  5887. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5888. preg_match_all($reg, $data['content'], $matches);
  5889. if (isset($matches[1][0])) {
  5890. //截取varchar240
  5891. $data['imgurl'] = substr($matches[1][0], 0, 240);
  5892. }
  5893. }
  5894. if ($data['keyword'] == '') {
  5895. //提取标题+内容中的关键词
  5896. $data['keyword'] = $data['title'];
  5897. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5898. Jieba::init(); // 初始化 jieba-php
  5899. Finalseg::init();
  5900. $segList = Jieba::cut($data['keyword']);
  5901. $segList1 = array_slice($segList, 0, 8);
  5902. $data['keyword'] = implode(',', $segList1);
  5903. }
  5904. if ($data['introduce'] == '' || empty($data['introduce'])) {
  5905. //提取内容中的描述
  5906. $data['introduce'] = mb_substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100) ?? '';
  5907. }
  5908. $user = User::where('id', $data['user_id'])->first();
  5909. if (empty($user)) {
  5910. return Result::error('用户不存在!');
  5911. }
  5912. if ($user['type_id'] == 10000) {
  5913. $data['status'] = 1;
  5914. }
  5915. if (isset($data['level']) && $data['level'] != null) {
  5916. $data['level'] = intval($data['level']);
  5917. } else {
  5918. $data['level'] = null;
  5919. }
  5920. $result = Company::insertGetId($data);
  5921. if ($result) {
  5922. return Result::success($result);
  5923. } else {
  5924. return Result::error('添加失败');
  5925. }
  5926. }
  5927. /**
  5928. * 更新企业
  5929. * @param array $data
  5930. * @return array
  5931. */
  5932. public function upCompany(array $data): array
  5933. {
  5934. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5935. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  5936. $data['cat_arr_id'] = json_encode($car_arr_id);
  5937. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  5938. } else {
  5939. $data['cat_arr_id'] = '';
  5940. }
  5941. if ($data['imgurl'] == '') {
  5942. //content中提取图片第一个图,正则提取
  5943. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5944. preg_match_all($reg, $data['content'], $matches);
  5945. if (isset($matches[1][0])) {
  5946. //截取varchar
  5947. $data['imgurl'] = substr($matches[1][0], 0, 240);
  5948. }
  5949. }
  5950. if ($data['keyword'] == '') {
  5951. //提取标题+内容中的关键词
  5952. $data['keyword'] = $data['title'];
  5953. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5954. Jieba::init(); // 初始化 jieba-php
  5955. Finalseg::init();
  5956. $segList = Jieba::cut($data['keyword']);
  5957. $segList1 = array_slice($segList, 0, 8);
  5958. $data['keyword'] = implode(',', $segList1);
  5959. }
  5960. if ($data['introduce'] == '') {
  5961. //提取内容中的描述
  5962. // var_dump(11111);
  5963. $data['introduce'] = mb_substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  5964. }
  5965. if (isset($data['level']) && $data['level'] != null) {
  5966. $data['level'] = intval($data['level']);
  5967. } else {
  5968. $data['level'] = null;
  5969. }
  5970. $user = User::where('id', $data['user_id'])->first();
  5971. if (empty($user)) {
  5972. return Result::error('用户不存在!');
  5973. }
  5974. if ($user['type_id'] == 10000) {
  5975. $data['status'] = 1;
  5976. } else {
  5977. $data['status'] = 0;
  5978. }
  5979. $result = Company::where('id', $data['id'])->update($data);
  5980. if ($result) {
  5981. return Result::success($result);
  5982. } else {
  5983. return Result::error('修改失败');
  5984. }
  5985. }
  5986. /**
  5987. * 删除企业
  5988. * @param array $data
  5989. * @return array
  5990. */
  5991. public function delCompany(array $data): array
  5992. {
  5993. $result = Company::where('id', $data['id'])->delete();
  5994. if ($result) {
  5995. return Result::success($result);
  5996. } else {
  5997. return Result::error('删除失败');
  5998. }
  5999. }
  6000. /**
  6001. * 审核企业
  6002. * @param array $data
  6003. * @return array
  6004. */
  6005. public function checkCompany(array $data): array
  6006. {
  6007. $user = User::where('id', $data['user_id'])->first();
  6008. if (empty($user)) {
  6009. return Result::error('用户不存在!');
  6010. }
  6011. $company = Company::where('id', $data['id'])->first();
  6012. if (empty($company)) {
  6013. return Result::error('企业不存在!');
  6014. }
  6015. // 状态:0:未审核 1:已审核 2:已拒绝
  6016. if ($data['status'] == 2 || $data['status'] == '2') {
  6017. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  6018. } else {
  6019. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  6020. }
  6021. if (empty($result)) {
  6022. return Result::error('审核失败!');
  6023. } else {
  6024. return Result::success($result);
  6025. }
  6026. }
  6027. /**
  6028. * 获取企业信息
  6029. * @param array $data
  6030. * @return array
  6031. */
  6032. public function getCompanyInfo(array $data): array
  6033. {
  6034. $result = Company::where('id', $data['id'])->first();
  6035. if (empty($result)) {
  6036. return Result::error('企业不存在!');
  6037. } else {
  6038. return Result::success($result);
  6039. }
  6040. }
  6041. /**
  6042. * @param array $data
  6043. * @return array
  6044. */
  6045. public function getWebsiteCompany(array $data): array
  6046. {
  6047. $where['website_id'] = $data['website_id'];
  6048. $where['status'] = 1;
  6049. if (isset($data['category_id']) && !empty($data['category_id'])) {
  6050. $where['category_id'] = $data['category_id'];
  6051. }
  6052. if (isset($data['level']) && !empty($data['level'])) {
  6053. $where['level'] = $data['level'];
  6054. }
  6055. // return Result::success($where);
  6056. $query = Company::where($where);
  6057. $result['img'] = $this->processArticle(
  6058. $query->clone()
  6059. ->where('imgurl', '!=', '')
  6060. ->whereNotNull('imgurl')
  6061. ->select('id', 'imgurl', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id')
  6062. ->orderBy('updated_at', 'desc')
  6063. ->limit($data['imgnum'])
  6064. ->get(),
  6065. $data
  6066. );
  6067. $result['text'] = $this->processArticle(
  6068. $query->clone()
  6069. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id')
  6070. ->orderBy('updated_at', 'desc')
  6071. ->limit($data['textnum'])
  6072. ->get(),
  6073. $data
  6074. );
  6075. if (empty($result)) {
  6076. return Result::error("暂无相关公司信息", 0);
  6077. }
  6078. return Result::success($result);
  6079. }
  6080. /**
  6081. * @param array $data
  6082. * @return array
  6083. */
  6084. public function getWebsiteCompanyList(array $data): array
  6085. {
  6086. $where['website_id'] = $data['website_id'];
  6087. $where['status'] = 1;
  6088. if (isset($data['category_id']) && !empty($data['category_id'])) {
  6089. $where['category_id'] = $data['category_id'];
  6090. }
  6091. if (isset($data['keyword']) && !empty($data['keyword'])) {
  6092. array_push($where, ['title', 'like', '%' . $data['keyword'] . '%']);
  6093. }
  6094. $query = Company::where($where);
  6095. $company = $this->processArticle(
  6096. $query->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id')
  6097. ->orderBy('updated_at', 'desc')
  6098. ->offset(($data['page'] - 1) * $data['pageSize'])
  6099. ->limit($data['pageSize'])
  6100. ->get(),
  6101. $data
  6102. );
  6103. if (empty($company)) {
  6104. return Result::error("暂无相关公司信息", 0);
  6105. }
  6106. $result = [
  6107. 'count' => $query->clone()->count(),
  6108. 'data' => $company,
  6109. ];
  6110. return Result::success($result);
  6111. }
  6112. /**
  6113. * 获取项目列表
  6114. * @param array $data
  6115. * @return array
  6116. */
  6117. public function getProjectList(array $data): array
  6118. {
  6119. $where = [];
  6120. $user = User::where('id', $data['user_id'])->first();
  6121. if (empty($user)) {
  6122. return Result::error('用户不存在!');
  6123. }
  6124. if ($user->type_id != 10000) {
  6125. array_push($where, ['project.user_id', $data['user_id']]);
  6126. }
  6127. $query = Project::query();
  6128. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6129. array_push($where, ['project.website_id', $data['website_id']]);
  6130. }
  6131. if (isset($data['title']) && !empty($data['title'])) {
  6132. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  6133. }
  6134. if ($data['status'] != 3) {
  6135. array_push($where, ['project.status', $data['status']]);
  6136. }
  6137. $query = Project::where($where)
  6138. ->when($data['status'] == 3, function ($query) {
  6139. $query->whereIn('project.status', [0, 2]);
  6140. });
  6141. $count = $query->clone()
  6142. ->count();
  6143. $rows = $query->clone()
  6144. ->leftJoin('website', 'project.website_id', 'website.id')
  6145. ->leftJoin('website_category', function ($join) {
  6146. $join->on('project.website_id', '=', 'website_category.website_id')
  6147. ->on('project.category_id', '=', 'website_category.category_id');
  6148. })
  6149. ->select(
  6150. 'project.id',
  6151. 'project.title',
  6152. 'project.updated_at',
  6153. 'project.status',
  6154. 'website.website_name',
  6155. 'website_category.alias as category_name'
  6156. )
  6157. ->orderBy('project.updated_at', 'desc')
  6158. ->offset(($data['page'] - 1) * $data['pageSize'])
  6159. ->limit($data['pageSize'])
  6160. ->get();
  6161. if ($rows->isEmpty()) {
  6162. return Result::error("暂无相关项目信息", 0);
  6163. }
  6164. $result = [
  6165. 'count' => $count,
  6166. 'rows' => $rows,
  6167. ];
  6168. return Result::success($result);
  6169. }
  6170. /**
  6171. * 添加项目
  6172. * @param array $data
  6173. * @return array
  6174. */
  6175. public function addProject(array $data): array
  6176. {
  6177. $user = User::where('id', $data['user_id'])->first();
  6178. if (empty($user)) {
  6179. return Result::error("暂无相关用户信息", 0);
  6180. }
  6181. if ($user->type_id == 10000) {
  6182. $data['status'] = 1;
  6183. } else {
  6184. $data['status'] = 0;
  6185. }
  6186. if ($data['keyword'] == '') {
  6187. //提取标题+内容中的关键词
  6188. $data['keyword'] = $data['title'];
  6189. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6190. Jieba::init(); // 初始化 jieba-php
  6191. Finalseg::init();
  6192. $segList = Jieba::cut($data['keyword']);
  6193. $segList1 = array_slice($segList, 0, 8);
  6194. $data['keyword'] = implode(',', $segList1);
  6195. }
  6196. if ($data['description'] == '') {
  6197. //提取内容中的描述
  6198. // var_dump(11111);
  6199. $data['description'] = mb_substr(str_replace(' ', '', strip_tags($data['introduce'])), 0, 100);
  6200. }
  6201. $project = Project::insertGetId($data);
  6202. if (empty($project)) {
  6203. return Result::error("暂无相关项目信息", 0);
  6204. }
  6205. return Result::success($project);
  6206. }
  6207. /**
  6208. * 更新项目
  6209. * @param array $data
  6210. * @return array
  6211. */
  6212. public function upProject(array $data): array
  6213. {
  6214. $project = Project::where('id', $data['id'])->first();
  6215. if (empty($project)) {
  6216. return Result::error("暂无相关项目信息", 0);
  6217. }
  6218. $id = $data['id'];
  6219. unset($data['id']);
  6220. $user = User::where('id', $data['user_id'])->first();
  6221. if (empty($user)) {
  6222. return Result::error("暂无相关用户信息", 0);
  6223. }
  6224. if ($user->type_id == 10000) {
  6225. $data['status'] = 1;
  6226. } else {
  6227. $data['status'] = 0;
  6228. }
  6229. unset($data['user_id']);
  6230. if ($data['keyword'] == '') {
  6231. //提取标题+内容中的关键词
  6232. $data['keyword'] = $data['title'];
  6233. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6234. Jieba::init(); // 初始化 jieba-php
  6235. Finalseg::init();
  6236. $segList = Jieba::cut($data['keyword']);
  6237. $segList1 = array_slice($segList, 0, 8);
  6238. $data['keyword'] = implode(',', $segList1);
  6239. }
  6240. if ($data['description'] == '') {
  6241. //提取内容中的描述
  6242. // var_dump(11111);
  6243. $data['description'] = mb_substr(str_replace(' ', '', strip_tags($data['introduce'])), 0, 100);
  6244. }
  6245. $result = Project::where('id', $id)->update($data);
  6246. if (empty($result)) {
  6247. return Result::error("更新失败", 0);
  6248. }
  6249. return Result::success($result);
  6250. }
  6251. /**
  6252. * 删除项目
  6253. * @param array $data
  6254. * @return array
  6255. */
  6256. public function delProject(array $data): array
  6257. {
  6258. $user = User::where('id', $data['user_id'])->first();
  6259. if (empty($user)) {
  6260. return Result::error("暂无相关用户信息", 0);
  6261. }
  6262. $project = Project::where('id', $data['id'])->first();
  6263. if (empty($project)) {
  6264. return Result::error("暂无相关项目信息", 0);
  6265. }
  6266. $result = Project::where('id', $data['id'])->delete();
  6267. if (empty($result)) {
  6268. return Result::error("删除失败", 0);
  6269. }
  6270. return Result::success($result);
  6271. }
  6272. /**
  6273. * 审核项目
  6274. * @param array $data
  6275. * @return array
  6276. */
  6277. public function checkProject(array $data): array
  6278. {
  6279. $user = User::where('id', $data['user_id'])->first();
  6280. if (empty($user)) {
  6281. return Result::error("暂无相关用户信息", 0);
  6282. }
  6283. // 0:未审核; 1:已审核; 2:已拒绝;
  6284. if ($user->type_id != 10000) {
  6285. if ($data['status'] == 1 || $data['status'] == 2) {
  6286. return Result::error("此用户权限不足", 0);
  6287. }
  6288. }
  6289. $project = Project::where('id', $data['id'])->first();
  6290. if (empty($project)) {
  6291. return Result::error("暂无相关项目信息", 0);
  6292. }
  6293. if ($data['status'] == 2) {
  6294. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  6295. } else {
  6296. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  6297. }
  6298. if (empty($result)) {
  6299. return Result::error("审核失败", 0);
  6300. }
  6301. return Result::success($result);
  6302. }
  6303. /**
  6304. * 获取项目详情
  6305. * @param array $data
  6306. * @return array
  6307. */
  6308. public function getProjectInfo(array $data): array
  6309. {
  6310. $project = Project::where('id', $data['id'])->first();
  6311. if (empty($project)) {
  6312. return Result::error("暂无相关项目信息", 0);
  6313. }
  6314. return Result::success($project);
  6315. }
  6316. public function getWebsiteCompanyInfo(array $data): array
  6317. {
  6318. $company = Company::where('id', $data['id'])
  6319. ->where('status', 1)
  6320. ->where('website_id', $data['website_id'])
  6321. ->select('company.*')
  6322. ->first();
  6323. if (empty($company)) {
  6324. return Result::error("暂无相关公司信息", 0);
  6325. }
  6326. return Result::success($company);
  6327. }
  6328. public function getMSG(array $data): array
  6329. {
  6330. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  6331. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  6332. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  6333. $result = [];
  6334. if ($type_id == 1) {
  6335. //最近的5篇已审的文章
  6336. $apply_articale = Article::where('status', 1)
  6337. ->where('admin_user_id', $user_id)
  6338. ->orderBy('updated_at', 'desc')
  6339. ->limit(5)->get();
  6340. //获取5条单聊未读聊天消息
  6341. $chat = ChatRecords::where('is_read', 0)
  6342. ->where('user_id', $user_id)
  6343. ->where('talk_type', 1)
  6344. ->orderBy('created_at', 'desc')
  6345. ->limit(5)->get();
  6346. //获取5条未读群聊信息
  6347. $chat_group = ChatRecords::where('is_read', 0)
  6348. ->where('user_id', $user_id)
  6349. ->where('talk_type', 2)
  6350. ->orderBy('created_at', 'desc')
  6351. ->limit(5)->get();
  6352. //获取5条用户的已审核商品
  6353. $good = Good::where('status', 2)
  6354. ->where('user_id', $user_id)
  6355. ->orderBy('updated_at', 'desc')
  6356. ->limit(5)->get();
  6357. //获取5条用户待审核的公告
  6358. $notice = Notice::where('status', 2)
  6359. ->where('user_id', $user_id)
  6360. ->orderBy('updated_at', 'desc')
  6361. ->limit(5)->get();
  6362. //获取5条用户的待审核投诉
  6363. $complaint = Complaint::where('status', 2)
  6364. ->where('user_id', $user_id)
  6365. ->orderBy('updated_at', 'desc')
  6366. ->limit(5)->get();
  6367. //获取5条用户的book
  6368. $book = Book::where('status', 2)
  6369. ->where('user_id', $user_id)
  6370. ->orderBy('updated_at', 'desc')
  6371. ->limit(5)->get();
  6372. //获取5条用户的求职
  6373. //获取5条用户的求职 1
  6374. $job_hunting = JobHunting::where('job_hunting.status', 1)
  6375. ->where('job_hunting.user_id', $user_id)
  6376. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  6377. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  6378. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  6379. ->orderBy('updated_at', 'desc')
  6380. ->limit(5)->get();
  6381. //获取5条用户的求职 2
  6382. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  6383. ->where('job_recruiting.user_id', $user_id)
  6384. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  6385. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  6386. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  6387. ->orderBy('updated_at', 'desc')
  6388. ->limit(5)->get();
  6389. //人才库 1
  6390. $job_apply = JobApply::where('job_apply.status', 1)
  6391. ->where('job_apply.receiver_id', $user_id)
  6392. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  6393. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  6394. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  6395. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  6396. ->select('job_recruiting', 'job_recruiting.', '', '')
  6397. ->select('job_apply.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name', 'job_company.business_name as business_name', 'job_recruiting.title as job_name')
  6398. ->orderBy('updated_at', 'desc')
  6399. ->limit(5)->get();
  6400. // 职场机会 2
  6401. $job_resume = JobResume::where('job_resume.status', 1)
  6402. ->where('job_resume.receiver_id', $user_id)
  6403. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  6404. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  6405. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  6406. ->select('job_resume.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name', 'job_company.business_name as business_name')
  6407. ->orderBy('updated_at', 'desc')
  6408. ->limit(5)->get();
  6409. // count($chat) + count($chat_group) +
  6410. $count = count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting) + count($job_apply) + count($job_resume);
  6411. $result = [
  6412. 'apply_articale' => $apply_articale,
  6413. 'chat' => $chat,
  6414. 'chat_group' => $chat_group,
  6415. 'good' => $good,
  6416. 'notice' => $notice,
  6417. 'complaint' => $complaint,
  6418. 'book' => $book,
  6419. 'job_hunting' => $job_hunting,
  6420. 'job_recruiting' => $job_recruiting,
  6421. 'job_apply' => $job_apply,
  6422. 'job_resume' => $job_resume,
  6423. 'count' => $count,
  6424. ];
  6425. } elseif ($type_id == 2) {
  6426. //最近的5篇已审的文章
  6427. $apply_articale = Article::where('status', 1)
  6428. ->where('admin_user_id', $user_id)
  6429. ->limit(5)->get();
  6430. //获取5条单聊未读聊天消息
  6431. $chat = ChatRecords::where('is_read', 0)
  6432. ->where('user_id', $user_id)
  6433. ->where('talk_type', 1)
  6434. ->orderBy('created_at', 'desc')
  6435. ->limit(5)->get();
  6436. //获取5条未读群聊信息
  6437. $chat_group = ChatRecords::where('is_read', 0)
  6438. ->where('user_id', $user_id)
  6439. ->where('talk_type', 2)
  6440. ->orderBy('created_at', 'desc')
  6441. ->limit(5)->get();
  6442. //获取5条用户的已审核商品
  6443. $good = Good::where('status', 2)
  6444. ->where('user_id', $user_id)
  6445. ->orderBy('updated_at', 'desc')
  6446. ->limit(5)->get();
  6447. //count($chat) + count($chat_group)
  6448. $count = count($apply_articale) + count($good);
  6449. $result = [
  6450. 'apply_articale' => $apply_articale,
  6451. 'chat' => $chat,
  6452. 'chat_group' => $chat_group,
  6453. 'good' => $good,
  6454. 'count' => $count,
  6455. ];
  6456. } elseif ($type_id == 3) {
  6457. //最近的5篇已审的文章
  6458. $apply_articale = Article::where('status', 1)
  6459. ->where('admin_user_id', $user_id)
  6460. ->limit(5)->get();
  6461. //获取5条单聊未读聊天消息
  6462. $chat = ChatRecords::where('is_read', 0)
  6463. ->where('user_id', $user_id)
  6464. ->where('talk_type', 1)
  6465. ->orderBy('created_at', 'desc')
  6466. ->limit(5)->get();
  6467. //获取5条未读群聊信息
  6468. $chat_group = ChatRecords::where('is_read', 0)
  6469. ->where('user_id', $user_id)
  6470. ->where('talk_type', 2)
  6471. ->orderBy('created_at', 'desc')
  6472. ->limit(5)->get();
  6473. //获取5条用户的已审核商品
  6474. $good = Good::where('status', 2)
  6475. ->where('user_id', $user_id)
  6476. ->orderBy('updated_at', 'desc')
  6477. ->limit(5)->get();
  6478. //count($chat) + count($chat_group) +
  6479. $count = count($apply_articale) + count($good);
  6480. $result = [
  6481. 'apply_articale' => $apply_articale,
  6482. 'chat' => $chat,
  6483. 'chat_group' => $chat_group,
  6484. 'good' => $good,
  6485. 'count' => $count,
  6486. ];
  6487. } elseif ($type_id == 4) {
  6488. //最近的5篇已审的文章
  6489. $apply_articale = Article::where('status', 1)
  6490. ->where('admin_user_id', $user_id)
  6491. ->limit(5)->get();
  6492. //获取5条用户的已审核商品
  6493. $good = Good::where('status', 2)
  6494. ->where('user_id', $user_id)
  6495. ->orderBy('updated_at', 'desc')
  6496. ->limit(5)->get();
  6497. $count = count($apply_articale) + count($good);
  6498. $result = [
  6499. 'apply_articale' => $apply_articale,
  6500. 'chat' => '',
  6501. 'chat_group' => '',
  6502. 'good' => $good,
  6503. 'count' => $count,
  6504. ];
  6505. } elseif ($type_id == 10000) {
  6506. //获取未审核的5篇文章
  6507. $apply_articale = Article::where('status', 0)
  6508. ->orderBy('updated_at', 'desc')
  6509. ->limit(5)->get();
  6510. //获取5条单聊未读聊天消息
  6511. $chat = ChatRecords::where('is_read', 0)
  6512. ->where('user_id', $user_id)
  6513. ->where('talk_type', 1)
  6514. ->orderBy('created_at', 'desc')
  6515. ->limit(5)->get();
  6516. //获取5条未读群聊信息
  6517. $chat_group = ChatRecords::where('is_read', 0)
  6518. ->where('user_id', $user_id)
  6519. ->where('talk_type', 2)
  6520. ->orderBy('created_at', 'desc')
  6521. ->limit(5)->get();
  6522. //获取5条用户的已审核商品
  6523. $good = Good::where('status', 1)
  6524. // ->where('user_id', $user_id)
  6525. ->orderBy('updated_at', 'desc')
  6526. ->limit(5)->get();
  6527. //获取5条用户待审核的公告
  6528. $notice = Notice::where('status', 1)
  6529. ->orderBy('updated_at', 'desc')
  6530. ->limit(5)->get();
  6531. //获取5条用户的待审核投诉
  6532. $complaint = Complaint::where('status', 1)
  6533. ->orderBy('updated_at', 'desc')
  6534. ->limit(5)->get();
  6535. //获取5条用户的book
  6536. $book = Book::where('status', 1)
  6537. ->orderBy('updated_at', 'desc')
  6538. ->limit(5)->get();
  6539. //获取5条用户的求职 1
  6540. $job_hunting = JobHunting::where('job_hunting.status', 1)
  6541. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  6542. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  6543. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  6544. ->orderBy('updated_at', 'desc')
  6545. ->limit(5)->get();
  6546. //获取5条用户的求职 2
  6547. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  6548. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  6549. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  6550. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  6551. ->orderBy('updated_at', 'desc')
  6552. ->limit(5)->get();
  6553. //人才库 1
  6554. $job_apply = JobApply::where('job_apply.status', 1)
  6555. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  6556. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  6557. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  6558. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  6559. ->select('job_apply.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name', 'job_company.business_name as business_name', 'job_recruiting.title as job_name')
  6560. ->orderBy('updated_at', 'desc')
  6561. ->limit(5)->get();
  6562. // 职场机会 2
  6563. $job_resume = JobResume::where('job_resume.status', 1)
  6564. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  6565. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  6566. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  6567. ->select('job_resume.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name', 'job_company.business_name as business_name')
  6568. ->orderBy('updated_at', 'desc')
  6569. ->limit(5)->get();
  6570. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting) + count($job_apply) + count($job_resume);
  6571. $result = [
  6572. 'apply_articale' => $apply_articale,
  6573. 'chat' => $chat,
  6574. 'chat_group' => $chat_group,
  6575. 'good' => $good,
  6576. 'notice' => $notice,
  6577. 'complaint' => $complaint,
  6578. 'book' => $book,
  6579. 'job_hunting' => $job_hunting,
  6580. 'job_recruiting' => $job_recruiting,
  6581. 'job_apply' => $job_apply,
  6582. 'job_resume' => $job_resume,
  6583. 'count' => $count,
  6584. ];
  6585. } elseif ($type_id == 20000) {
  6586. }
  6587. var_dump($type_id, '-----------------test---------');
  6588. return Result::success($result);
  6589. }
  6590. }