NewsService.php 246 KB

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