NewsService.php 253 KB

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