NewsService.php 255 KB

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