NewsService.php 334 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129
  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. use Hyperf\Context\Context;
  60. use Hyperf\Context\ApplicationContext as ContextApplicationContext;
  61. use Hyperf\Amqp\Producer;
  62. use App\Amqp\Producer\MqProducer;
  63. use App\Model\Web;
  64. use App\Model\GroupMemberImp;
  65. use App\Model\GroupImp;
  66. use App\Model\GroupTalkImp;
  67. use App\Model\GroupTalkMessagerImp;
  68. use App\Model\ArticleIgnore;
  69. use App\Model\Message;
  70. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  71. class NewsService implements NewsServiceInterface
  72. {
  73. #[Inject]
  74. protected Redis $redis;
  75. /**
  76. * 获取导航池列表
  77. * @param array $data
  78. * @return array
  79. */
  80. public function getCategoryList(array $data): array
  81. {
  82. $search = $data['name'] ?? '';
  83. $page = (int)($data['page'] ?? 1);
  84. $perPage = (int)($data['pageSize'] ?? 10);
  85. // 1. 查出所有匹配的分类id
  86. if ($search) {
  87. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  88. if (empty($matchedIds)) {
  89. return Result::success(['rows' => [], 'total' => 0]);
  90. }
  91. // 2. 递归查所有父级,直到一级分类
  92. $idsStr = implode(',', $matchedIds);
  93. $sql = "
  94. WITH RECURSIVE parents AS (
  95. SELECT * FROM category WHERE id IN ($idsStr)
  96. UNION ALL
  97. SELECT c.* FROM category c
  98. INNER JOIN parents p ON c.id = p.pid
  99. )
  100. SELECT * FROM parents
  101. ";
  102. $parents = Db::select($sql);
  103. $parentIds = [];
  104. foreach ($parents as $row) {
  105. if ($row->pid == 0) {
  106. $parentIds[] = $row->id;
  107. }
  108. }
  109. $parentIds = array_unique($parentIds);
  110. } else {
  111. // 没有搜索,一级分类就是根
  112. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  113. }
  114. // 3. 一级分类分页
  115. $total = count($parentIds);
  116. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  117. if (empty($parentIds)) {
  118. return Result::success(['rows' => [], 'total' => $total]);
  119. }
  120. // 4. 递归查所有子孙
  121. $idsStr = implode(',', $parentIds);
  122. $sql = "
  123. WITH RECURSIVE subcategories AS (
  124. SELECT * FROM category WHERE id IN ($idsStr)
  125. UNION ALL
  126. SELECT c.* FROM category c
  127. INNER JOIN subcategories s ON c.pid = s.id
  128. )
  129. SELECT * FROM subcategories ORDER BY updated_at DESC
  130. ";
  131. $allCategories = Db::select($sql);
  132. // 5. 组装树结构
  133. $categoryMap = [];
  134. foreach ($allCategories as $cat) {
  135. $cat = (array)$cat;
  136. $cat['children'] = [];
  137. $categoryMap[$cat['id']] = $cat;
  138. }
  139. foreach ($categoryMap as $id => &$cat) {
  140. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  141. $categoryMap[$cat['pid']]['children'][] = &$cat;
  142. }
  143. }
  144. unset($cat);
  145. $categoryTree = [];
  146. foreach ($parentIds as $id) {
  147. if (isset($categoryMap[$id])) {
  148. $categoryTree[] = $categoryMap[$id];
  149. }
  150. }
  151. return Result::success([
  152. 'rows' => $categoryTree,
  153. 'total' => $total,
  154. ]);
  155. }
  156. private function findMatchedCategories($search)
  157. {
  158. if ($search) {
  159. return Category::where('name', 'like', "%{$search}%")
  160. ->orderBy('updated_at', 'desc')
  161. ->get();
  162. }
  163. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  164. ->get();
  165. }
  166. private function findAllParents($categories)
  167. {
  168. $allCategories = [];
  169. foreach ($categories as $category) {
  170. $parentId = $category->pid;
  171. while ($parentId > 0) {
  172. $parent = Category::find($parentId);
  173. if ($parent) {
  174. $allCategories[$parent->id] = $parent;
  175. $parentId = $parent->pid;
  176. } else {
  177. break;
  178. }
  179. }
  180. $allCategories[$category->id] = $category;
  181. }
  182. return array_values($allCategories);
  183. }
  184. private function buildCategoryTree($category, $allRequiredCategories)
  185. {
  186. $categoryData = $category->toArray();
  187. $children = [];
  188. foreach ($allRequiredCategories as $c) {
  189. if ($c->pid === $category->id) {
  190. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  191. }
  192. }
  193. if (!empty($children)) {
  194. $categoryData['children'] = $children;
  195. }
  196. return $categoryData;
  197. }
  198. public function myCategoryList(array $data): array
  199. {
  200. $sszq = $data['sszq'] ?? '';
  201. unset($data['sszq']);
  202. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  203. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  204. $where[] = [
  205. 'pid',
  206. '=',
  207. $data['pid'],
  208. ];
  209. if (isset($data['name'])) {
  210. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  211. }
  212. var_dump($where);
  213. //根据分类id,从category表中取出分类信息
  214. $result = Category::where($where)
  215. ->whereIn('category.id', $catorytids)
  216. ->select('category.*', 'category.id as category_id')->get();
  217. if (empty($result)) {
  218. return Result::error("没有栏目数据");
  219. }
  220. return Result::success($result);
  221. }
  222. /**
  223. * @param array $data
  224. * @return array
  225. */
  226. public function categoryList(array $data): array
  227. {
  228. $where[] = [
  229. 'pid',
  230. '=',
  231. $data['pid']
  232. ];
  233. if (isset($data['name'])) {
  234. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  235. }
  236. var_dump($where);
  237. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  238. if (empty($result)) {
  239. return Result::error("没有栏目数据");
  240. }
  241. return Result::success($result);
  242. }
  243. /**
  244. * @param array $data
  245. * @return array
  246. */
  247. public function addCategory(array $data): array
  248. {
  249. if (isset($data['id'])) {
  250. unset($data['id']);
  251. }
  252. $id = Category::insertGetId($data);
  253. if (empty($id)) {
  254. return Result::error("添加失败");
  255. }
  256. return Result::success(['id' => $id]);
  257. }
  258. /**
  259. * @param array $data
  260. * @return array
  261. */
  262. public function delCategory(array $data): array
  263. {
  264. Db::beginTransaction();
  265. try {
  266. $categoryList = Category::where(['pid' => $data['id']])->get();
  267. if ($categoryList->toArray()) {
  268. Db::rollBack();
  269. return Result::error("分类下面有子分类不能删除");
  270. }
  271. $articleList = Article::where(['catid' => $data['id']])->get();
  272. if ($articleList->toArray()) {
  273. Db::rollBack();
  274. return Result::error("分类下面有资讯不能删除");
  275. }
  276. $result = Category::where($data)->delete();
  277. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  278. if (!$result) {
  279. Db::rollBack();
  280. return Result::error("删除失败");
  281. }
  282. Db::commit();
  283. return Result::success($result);
  284. } catch (\Exception $e) {
  285. Db::rollBack();
  286. return Result::error("删除失败" . $e->getMessage());
  287. }
  288. }
  289. /**
  290. * @param array $data
  291. * @return array
  292. */
  293. public function updateCategory(array $data): array
  294. {
  295. $where = [
  296. 'id' => $data['id'],
  297. ];
  298. $result = Category::where($where)->update($data);
  299. if ($result) {
  300. return Result::success($result);
  301. } else {
  302. return Result::error("更新失败");
  303. }
  304. }
  305. /**
  306. * 获取导航池信息
  307. * @param array $data
  308. * @return array
  309. */
  310. public function getCategoryInfo(array $data): array
  311. {
  312. $where = [
  313. 'id' => $data['id'],
  314. ];
  315. $result = Category::where($where)->first();
  316. if ($result) {
  317. return Result::success($result);
  318. } else {
  319. return Result::error("更新失败");
  320. }
  321. }
  322. public function getArticleCommend(array $data): array
  323. {
  324. $where = [
  325. 'website_id' => $data['website_id'],
  326. ];
  327. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  328. var_dump($ids);
  329. if (empty($ids)) {
  330. return Result::error("没有推荐数据");
  331. }
  332. //id
  333. $whereArticle = [];
  334. if (isset($data['id'])) {
  335. $whereArticle['id'] = $data['id'];
  336. }
  337. //title like
  338. if (isset($data['title'])) {
  339. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  340. }
  341. $article = Article::whereIn('catid', values: $ids)->where('status', 1)
  342. ->where($whereArticle)
  343. ->orderBy('id', 'desc')
  344. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  345. if ($article) {
  346. $data = [
  347. 'rows' => $article->items(),
  348. 'count' => $article->total(),
  349. ];
  350. return Result::success($data);
  351. } else {
  352. return Result::error("获取失败失败");
  353. }
  354. }
  355. /**
  356. * @param array $data
  357. * @return array
  358. */
  359. public function getArticleList(array $data): array
  360. {
  361. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  362. $type_id = $data['type_id'];
  363. unset($data['type_id']);
  364. $user_id = $data['user_id'];
  365. unset($data['user_id']);
  366. $where = [];
  367. $status1 = [];
  368. if (isset($data['id']) && $data['id']) {
  369. array_push($where, ['article.id', '=', $data['id']]);
  370. }
  371. if (isset($data['title']) && $data['title']) {
  372. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  373. }
  374. if (isset($data['category_name']) && $data['category_name']) {
  375. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  376. }
  377. if (isset($data['catid']) && $data['catid']) {
  378. array_push($where, ['article.catid', '=', $data['catid']]);
  379. }
  380. if (isset($data['author']) && $data['author']) {
  381. array_push($where, ['article.author', '=', $data['author']]);
  382. }
  383. if (isset($data['islink']) && $data['islink'] !== "") {
  384. array_push($where, ['article.islink', '=', $data['islink']]);
  385. }
  386. if (isset($data['status']) && $data['status'] !== "") {
  387. array_push($where, ['article.status', '=', $data['status']]);
  388. }
  389. if (isset($data['status1'])) {
  390. $status1 = json_decode(($data['status1']));
  391. }
  392. //不是管理员展示个人数据;
  393. if ($type_id != 10000) {
  394. $where[] = ['article.admin_user_id', '=', $user_id];
  395. }
  396. $startTime = microtime(true);
  397. $rep = Article::query()
  398. // 预加载相关关联
  399. ->with([
  400. 'category' => function ($query) {
  401. $query->select('id', 'name');
  402. },
  403. 'websiteCategory' => function ($query) {
  404. $query->select('website_id', 'category_id', 'alias');
  405. },'user' => function ($query) {
  406. $query->select('id', 'nickname');
  407. }
  408. ])
  409. // 构建where条件
  410. ->when(isset($data['id']) && $data['id'], function ($query) use ($data) {
  411. $query->where('article.id', '=', $data['id']);
  412. })
  413. ->when(isset($data['title']) && $data['title'], function ($query) use ($data) {
  414. $query->where('article.title', 'like', '%' . $data['title'] . '%');
  415. })
  416. ->when(isset($data['category_name']) && $data['category_name'], function ($query) use ($data) {
  417. // 使用子查询替代左连接进行模糊搜索
  418. $query->whereHas('category', function ($subQuery) use ($data) {
  419. $subQuery->where('name', 'like', '%' . $data['category_name'] . '%');
  420. });
  421. })
  422. ->when(isset($data['catid']) && $data['catid'], function ($query) use ($data) {
  423. $query->where('article.catid', '=', $data['catid']);
  424. })
  425. ->when(isset($data['author']) && $data['author'], function ($query) use ($data) {
  426. $query->where('article.author', '=', $data['author']);
  427. })
  428. ->when(isset($data['islink']) && $data['islink'] !== "", function ($query) use ($data) {
  429. $query->where('article.islink', '=', $data['islink']);
  430. })
  431. ->when(isset($data['status']) && $data['status'] !== "", function ($query) use ($data) {
  432. $query->where('article.status', '=', $data['status']);
  433. })
  434. ->when(isset($data['status1']) && $data['status1'], function ($query) use ($data) {
  435. // 安全地处理JSON字符串
  436. $status1 = is_array($data['status1']) ? $data['status1'] : json_decode($data['status1'], true) ?? [];
  437. if (!empty($status1)) {
  438. $query->whereIn('article.status', $status1);
  439. }
  440. })
  441. ->select('article.*')
  442. // 非管理员限制
  443. ->when($type_id != 10000, function ($query) use ($user_id) {
  444. // 非管理员只能看自己的文章,同时把 article_ignore 的 c_show_time 一起查出来
  445. $query->where('article.admin_user_id', $user_id)
  446. ->leftJoin('article_ignore', function ($join) {
  447. // 关联条件:article.id = article_ignore.article_id 且 article.web_site_id = article_ignore.website_id
  448. $join->on('article_ignore.article_id', '=', 'article.id')
  449. ->whereColumn('article_ignore.website_id', 'article.web_site_id');
  450. })
  451. ->addSelect('article_ignore.article_id','article_ignore.c_show_time'); // 用 addSelect 追加字段,避免覆盖原有 select
  452. })
  453. // 基础条件
  454. ->whereNotIn('article.status', [404])
  455. // 排序和分页
  456. ->orderBy('article.updated_at', 'desc')
  457. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  458. // 获取结果并格式化
  459. $data = [
  460. 'rows' => $rep->items(),
  461. 'count' => $rep->total(),
  462. ];
  463. // 执行查询
  464. $endTime = microtime(true);
  465. $executionTime = ($endTime - $startTime) * 1000;
  466. echo "查询执行时间: {$executionTime}ms\n";
  467. return Result::success($data);
  468. }
  469. /**
  470. * @param array $data
  471. * @return array
  472. */
  473. public function addArticle(array $data): array
  474. {
  475. var_dump($data, '----------12-----------1');
  476. // ------c_show_time********add***1****
  477. $is_collect = $data['is_collect'] ?? 0;
  478. $user_type = $data['user_type'];
  479. unset($data['is_collect']);
  480. unset($data['user_type']);
  481. // ------c_show_time********add***1****
  482. unset($data['nav_add_pool_id']);
  483. // unset($data['commend_id']);
  484. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  485. Db::beginTransaction();
  486. try {
  487. //处理投票
  488. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  489. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  490. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  491. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  492. unset($data['is_survey']);
  493. unset($data['survey_name']);
  494. unset($data['suvey_array']);
  495. // unset($data['website_id']);
  496. // unset($data['web_site_id']);
  497. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  498. if ($data['hits'] == '') {
  499. $data['hits'] = 0;
  500. }
  501. if ($data['is_original'] == '') {
  502. $data['is_original'] = 0;
  503. }
  504. if ($data['status'] == '') {
  505. $data['status'] = 0;
  506. }
  507. $articleData = $data;
  508. unset($articleData['content']);
  509. //自动处理缩略图、关键字、描述
  510. if ($articleData['imgurl'] == '') {
  511. //如果没有图,设置level=0
  512. $levelArr = json_decode($articleData['level'], true);
  513. var_dump($levelArr, '----------levelArr-----------1');
  514. //content中提取图片第一个图,正则提取
  515. // -------采集器相关优化-----
  516. // 优化正则表达式,仅匹配 src 属性值,避免匹配到多余内容
  517. if ($is_collect == 1) {
  518. $reg = '/<img.*?src=[\'"]?((?!.*\.gif)[^\'" >]+)[\'"]?.*?>/i';
  519. } else {
  520. $reg = '/<img.*?src=[\'"]?([^\'" >]+)[\'"]?.*?>/i';
  521. }
  522. // -------采集器相关优化-----
  523. preg_match_all($reg, $data['content'], $matches);
  524. if (isset($matches[1][0])) {
  525. //截取varchar240
  526. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  527. //如果有图,设置level=3
  528. if (!in_array(3, $levelArr)) {
  529. $levelArr[] = 3;
  530. }
  531. $articleData['level'] = json_encode($levelArr);
  532. } else {
  533. if (!in_array(0, $levelArr)) {
  534. $levelArr[] = 0;
  535. }
  536. $articleData['level'] = json_encode($levelArr);
  537. }
  538. }
  539. var_dump($articleData['level'], '----------$articleData[level]----------1');
  540. if ($articleData['keyword'] == '') {
  541. //提取标题+内容中的关键词
  542. $articleData['keyword'] = $data['title'];
  543. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  544. Jieba::init(); // 初始化 jieba-php
  545. Finalseg::init();
  546. $segList = Jieba::cut($articleData['keyword']);
  547. $segList1 = array_slice($segList, 0, 8);
  548. $articleData['keyword'] = implode(',', $segList1);
  549. }
  550. if ($articleData['introduce'] == '') {
  551. //提取内容中的描述
  552. $content = $data['content'];
  553. // 去除 <style> 和 <script> 标签及其内容
  554. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  555. // 去除所有 HTML 标签
  556. $content = strip_tags($content);
  557. // 去除 HTML 实体
  558. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  559. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  560. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  561. // 去除多余空白
  562. $content = preg_replace('/\s+/u', '', $content);
  563. // 截取 100 个字符
  564. $articleData['introduce'] = mb_substr($content, 0, 100);
  565. }
  566. if ($articleData['status'] == 0) {
  567. $this->sendMessage([
  568. 'talk_type' => 100,
  569. 'title' => $articleData['title'],
  570. 'content' => '提交了审核',
  571. 'messageType' => 2,
  572. ]);
  573. }
  574. if(!empty($data['fujian'])){
  575. $articleData['fujian'] = $data['fujian'];
  576. }
  577. $id = Article::insertGetId($articleData);
  578. if (!$id) {
  579. throw new \Exception('文章插入失败');
  580. }
  581. $articleDataContent = [
  582. 'article_id' => $id,
  583. 'content' => $data['content'],
  584. ];
  585. // 采集器中的文章内容,在添加时,去掉div标签
  586. if ($is_collect == 1) {
  587. // 采集来的文章,content中可能包含div标签,需要先移除
  588. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  589. $article_data = preg_replace($pattern, '', $data['content']);
  590. $$articleDataContent['content'] = $article_data;
  591. }
  592. $contentInsertId = ArticleData::insertGetId($articleDataContent);
  593. if (!$contentInsertId) {
  594. throw new \Exception('文章内容插入失败');
  595. }
  596. // ------c_show_time********add***2****
  597. // 直接使用当前系统时间,不再强制添加8小时
  598. $now = date('Y-m-d H:i:s');
  599. if ($user_type == 10000 || $is_collect == 1) {
  600. // 管理员添加文章时,核心站c端显示时间就是创建时间;非核心站c端显示时间就是此创建时间往后推二十分钟;
  601. // 非管理员添加文章时,不做操作只有在审核通过时获取c端显示时间
  602. if (!isset($data['catid'])) {
  603. throw new \Exception('缺少必要字段:catid');
  604. }
  605. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  606. $web = WebsiteCategory::where('category_id', $data['catid'])
  607. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  608. ->select(
  609. 'website_id',
  610. Db::raw('CASE WHEN website.id IS NULL THEN 2 WHEN JSON_CONTAINS(website.`website_column_arr_id`, \'3\') THEN 1 ELSE 0 END as is_core')
  611. )
  612. ->get();
  613. // $id = 225; -----测试开启
  614. // 采集来的文章,错开时间在两小时之内发布
  615. if ($user_type == 10000 && $is_collect == 1) {
  616. $web_num = $web->where('is_core', '!=', 2)->count();
  617. $waiting_interval = 10;
  618. if ($web_num > 12) {
  619. // 若网站数量大于12个,则每个网站间隔时间取均值
  620. // 防止除数为 0,虽然这里 $web_num 是 count 结果不会为 0,但做健壮性检查
  621. $waiting_interval = 120 / max(1, $web_num);
  622. }
  623. $time = 0;
  624. } else {
  625. // 非核心站与核心站----显示时间-----间隔
  626. $time = 20;
  627. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  628. $waiting_interval = 5;
  629. }
  630. // 将 Hyperf\Database\Model\Collection 转换为数组
  631. $webArray = $web->toArray();
  632. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $id, $waiting_interval, $is_collect) {
  633. // 检查 $item 对象是否有 is_core 属性
  634. if (!isset($item['is_core'])) {
  635. throw new \Exception('$item 对象缺少 is_core 属性');
  636. }
  637. // 当 is_core 为 2 时,则表示此网站不存在
  638. if ($item['is_core'] == 2) {
  639. return null;
  640. }
  641. if ($is_collect == 1) {
  642. // 采集来的文章,错开时间在两小时之内发布
  643. // $time = 0;
  644. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  645. $time += $waiting_interval;
  646. } else if ($item['is_core'] == 1) {
  647. // 当 is_core 为 1 时,则表示此网站是核心站
  648. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  649. } else {
  650. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  651. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  652. if ($item['is_core'] == 0) {
  653. $time += $waiting_interval;
  654. }
  655. }
  656. return [
  657. 'article_id' => $id,
  658. 'website_id' => $item['website_id'],
  659. 'c_show_time' => $c_show_time,
  660. // 'is_core' => $item['is_core'],
  661. // 'time' => $time
  662. ];
  663. }, array_keys($webArray), $webArray)));
  664. // Db::commit();
  665. // return Result::success($article_ignore);
  666. if (!empty($article_ignore)) {
  667. $article_ignores = ArticleIgnore::insert($article_ignore);
  668. if (!$article_ignores) {
  669. throw new \Exception('c端展示时间插入失败');
  670. }
  671. }
  672. }
  673. // ------c_show_time********add***2****
  674. //处理投票
  675. if ($is_survey == 1) {
  676. //生成年月日时分秒+8位随机数
  677. $uuid = date('YmdHis') . rand(10000000, 99999999);
  678. var_dump($suvey_array, 'suvey_array________');
  679. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  680. var_dump($suveys_array, '---------------------1');
  681. var_dump($suvey_array, '---------------------2');
  682. $suvey_data = [];
  683. foreach ($suveys_array as $key => $value) {
  684. if ($value == '') {
  685. continue;
  686. }
  687. if (is_array($value)) {
  688. $suvey_data[] = [
  689. 'sur_id' => $uuid,
  690. 'art_id' => $id,
  691. 'website_id' => $website_id ?? 2,
  692. 'survey_name' => $survey_name,
  693. 'choice_name' => $value[1],
  694. 'is_other' => 1,
  695. 'other_id' => 0,
  696. 'results' => 0,
  697. ];
  698. } else {
  699. $suvey_data[] = [
  700. 'sur_id' => $uuid,
  701. 'art_id' => $id,
  702. 'website_id' => $website_id ?? 2,
  703. 'survey_name' => $survey_name,
  704. 'choice_name' => $value,
  705. 'is_other' => 0,
  706. 'other_id' => 0,
  707. 'results' => 0,
  708. ];
  709. }
  710. if (empty($suvey_data)) {
  711. throw new \Exception("投票数据为空");
  712. }
  713. }
  714. $result = ArticleSurvey::insert($suvey_data);
  715. if (!$result) {
  716. throw new \Exception("投票失败,ArticleSurvey插入失败");
  717. }
  718. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  719. if (!$result) {
  720. throw new \Exception("投票失败,更新主表失败");
  721. }
  722. }
  723. Db::commit();
  724. return Result::success(['id' => $id]);
  725. } catch (\Throwable $ex) {
  726. Db::rollBack();
  727. var_dump($ex->getMessage());
  728. return Result::error("创建失败", 0);
  729. }
  730. }
  731. /**
  732. * @param array $data
  733. * @return array
  734. */
  735. public function delArticle(array $data): array
  736. {
  737. // ------c_show_time********del*******
  738. Db::beginTransaction();
  739. try {
  740. $article = Article::where(['id' => $data['id']])->delete();
  741. // 若文章删除失败,抛出异常,后续 SQL 语句不会执行
  742. if (!$article) {
  743. throw new \Exception("删除失败,文章删除失败");
  744. }
  745. //survey投票删除
  746. ArticleSurvey::where(['art_id' => $data['id']])->delete(); // 修正类名大小写
  747. $articleIgnore = ArticleIgnore::where(['article_id' => $data['id']])->delete();
  748. $article_data = ArticleData::where(['article_id' => $data['id']])->delete();
  749. // 若文章详情删除失败,抛出异常
  750. if (!$article_data) {
  751. throw new \Exception("删除失败,文章详情删除失败");
  752. }
  753. Db::commit(); // 所有操作成功,提交事务
  754. } catch (\Throwable $ex) {
  755. Db::rollBack();
  756. var_dump($ex->getMessage());
  757. return Result::error("删除失败: " . $ex->getMessage(), 0);
  758. }
  759. // ------c_show_time********del*******
  760. if (!$article) {
  761. return Result::error("删除失败");
  762. }
  763. return Result::success($article);
  764. }
  765. /**
  766. * @param array $data
  767. * @return array
  768. */
  769. public function updateArticle(array $data): array
  770. {
  771. var_dump($data, '----------12-----------1');
  772. Db::beginTransaction();
  773. // ------c_show_time********up*******
  774. $user_type = isset($data['user_type']) ? $data['user_type'] : 0;
  775. // 无论是否改变了c端显示时间或者栏目,都需要将未屏蔽的网站显示时间删除记录
  776. // 若是存在交集,则进行修改,若无,则合并(此表中的记录应该包含被屏蔽网站及涉及所有网站的展示时间)
  777. $web = WebsiteCategory::where('category_id', $data['catid'])
  778. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  779. ->select(
  780. 'website_id',
  781. Db::raw('CASE WHEN website.id IS NULL THEN 2 WHEN JSON_CONTAINS(website.`website_column_arr_id`, \'3\') THEN 1 ELSE 0 END as is_core')
  782. )
  783. ->get();
  784. // 根据错误信息,问题在于 $web 可能是一个包含对象的集合,不能直接用于 whereNotIn 方法
  785. // 先从 $web 集合中提取 website_id 字段的值,再进行删除操作
  786. $websiteIds = $web->pluck('website_id')->toArray();
  787. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  788. if ($user_type == 0) {
  789. throw new \Exception("用户类型不能为空");
  790. }
  791. if ($user_type == 10000) {
  792. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  793. $web = WebsiteCategory::where('category_id', $data['catid'])
  794. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  795. ->select(
  796. 'website_id',
  797. Db::raw('CASE WHEN website.id IS NULL THEN 2 WHEN JSON_CONTAINS(website.`website_column_arr_id`, \'3\') THEN 1 ELSE 0 END as is_core')
  798. )
  799. ->get();
  800. // 非核心站与核心站----显示时间-----间隔
  801. $time = 20;
  802. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  803. $waiting_interval = 5;
  804. $webArray = $web->toArray();
  805. if (empty($webArray)) {
  806. throw new \Exception('网站分类不存在');
  807. }
  808. // 直接使用当前系统时间,不再强制添加8小时
  809. $now = date('Y-m-d H:i:s');
  810. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  811. // 检查 $item 对象是否有 is_core 属性
  812. if (!isset($item['is_core'])) {
  813. throw new \Exception('$item 对象缺少 is_core 属性');
  814. }
  815. // 当 is_core 为 2 时,则表示此网站不存在
  816. if ($item['is_core'] == 2) {
  817. return null;
  818. } else if ($item['is_core'] == 1) {
  819. // 当 is_core 为 1 时,则表示此网站是核心站
  820. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  821. } else {
  822. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  823. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  824. if ($item['is_core'] == 0) {
  825. $time += $waiting_interval;
  826. }
  827. }
  828. return [
  829. 'article_id' => $data['id'],
  830. 'website_id' => $item['website_id'],
  831. 'c_show_time' => $c_show_time,
  832. ];
  833. }, array_keys($webArray), $webArray)));
  834. if (!empty($article_ignore)) {
  835. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  836. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  837. $article_ignores = ArticleIgnore::upsert(
  838. $article_ignore,
  839. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  840. ['c_show_time'] // 需要更新的字段
  841. );
  842. if (!$article_ignores) {
  843. throw new \Exception('c端展示时间插入失败');
  844. }
  845. }
  846. // Db::commit();
  847. // return Result::success($article_ignore);
  848. }
  849. // ------c_show_time********up*******
  850. unset($data['user_type']);
  851. // unset($data['web_site_id']);
  852. unset($data['nav_add_pool_id']);
  853. try {
  854. //处理投票
  855. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  856. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  857. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  858. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  859. unset($data['is_survey']);
  860. unset($data['survey_name']);
  861. unset($data['suvey_array']);
  862. unset($data['website_id']);
  863. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  864. if ($data['hits'] == '') {
  865. $data['hits'] = 0;
  866. }
  867. if ($data['is_original'] == '') {
  868. $data['is_original'] = 0;
  869. }
  870. if ($data['status'] == '') {
  871. $data['status'] = 0;
  872. }
  873. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  874. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  875. $articleData = $data;
  876. unset($articleData['content']);
  877. unset($articleData['status_name']);
  878. unset($articleData['name']);
  879. unset($articleData['content']);
  880. unset($articleData['pid_arr']);
  881. unset($articleData['pid']);
  882. //自动处理缩略图、关键字、描述
  883. if ($articleData['imgurl'] == '') {
  884. //如果没有图,设置level=0
  885. $levelArr = json_decode($articleData['level'], true);
  886. var_dump($levelArr, '----------levelArr-----------1');
  887. //content中提取图片第一个图,正则提取
  888. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  889. preg_match_all($reg, $data['content'], $matches);
  890. if (isset($matches[1][0])) {
  891. //截取varchar240
  892. // 截取到第一个<
  893. $articleData['imgurl'] = $matches[1][0];
  894. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  895. $pos = strpos($articleData['imgurl'], '"');
  896. if ($pos !== false) {
  897. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  898. }
  899. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  900. //如果有图,设置level=3
  901. if (!in_array(3, $levelArr)) {
  902. $levelArr[] = 3;
  903. }
  904. $articleData['level'] = json_encode($levelArr);
  905. } else {
  906. if (!in_array(0, $levelArr)) {
  907. $levelArr[] = 0;
  908. }
  909. $articleData['level'] = json_encode($levelArr);
  910. }
  911. }
  912. var_dump($articleData['level'], '----------$articleData[level]----------1');
  913. if ($articleData['keyword'] == '') {
  914. //提取标题+内容中的关键词
  915. $articleData['keyword'] = $data['title'];
  916. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  917. Jieba::init(); // 初始化 jieba-php
  918. Finalseg::init();
  919. $segList = Jieba::cut($articleData['keyword']);
  920. $segList1 = array_slice($segList, 0, 8);
  921. $articleData['keyword'] = implode(',', $segList1);
  922. }
  923. if ($articleData['introduce'] == '') {
  924. //提取内容中的描述
  925. $content = $data['content'];
  926. // 去除 <style> 和 <script> 标签及其内容
  927. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  928. // 去除所有 HTML 标签
  929. $content = strip_tags($content);
  930. // 去除 HTML 实体
  931. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  932. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  933. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  934. // 去除多余空白
  935. $content = preg_replace('/\s+/u', '', $content);
  936. // 截取 100 个字符
  937. $articleData['introduce'] = mb_substr($content, 0, 100);
  938. }
  939. if ($articleData['status'] == 0) {
  940. $this->sendMessage([
  941. 'talk_type' => 100,
  942. 'title' => $articleData['title'],
  943. 'content' => '提交了审核',
  944. 'messageType' => 2,
  945. ]);
  946. }
  947. if(!empty($data['fujian'])){
  948. $articleData['fujian'] = $data['fujian'];
  949. }
  950. $id = Article::where(['id' => $data['id']])->update($articleData);
  951. // $articleDataContent = [
  952. // 'content' => $data['content'],
  953. // ];
  954. // 采集来的文章,content中可能包含div标签,需要先移除
  955. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  956. $article_data = preg_replace($pattern, '', $data['content']);
  957. $articleDataContent['content'] = $article_data;
  958. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  959. //处理投票
  960. $id = $data['id'];
  961. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  962. var_dump($suvey_array, 'suvey_array________delete');
  963. //处理投票
  964. if ($is_survey == 1) {
  965. //生成年月日时分秒+8位随机数
  966. $uuid = date('YmdHis') . rand(10000000, 99999999);
  967. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  968. var_dump($suveys_array, '---------------------1');
  969. $suvey_data = [];
  970. if (is_array($suveys_array)) {
  971. foreach ($suveys_array as $key => $value) {
  972. if ($value == '') {
  973. continue;
  974. }
  975. if (is_array($value)) {
  976. $suvey_data[] = [
  977. 'sur_id' => $uuid,
  978. 'art_id' => $id,
  979. 'website_id' => $website_id ?? 2,
  980. 'survey_name' => $survey_name,
  981. 'choice_name' => $value[1],
  982. 'is_other' => 1,
  983. 'other_id' => 0,
  984. 'results' => 0,
  985. ];
  986. } else {
  987. $suvey_data[] = [
  988. 'sur_id' => $uuid,
  989. 'art_id' => $id,
  990. 'website_id' => $website_id ?? 2,
  991. 'survey_name' => $survey_name,
  992. 'choice_name' => $value,
  993. 'is_other' => 0,
  994. 'other_id' => 0,
  995. 'results' => 0,
  996. ];
  997. }
  998. if (empty($suvey_data)) {
  999. throw new \Exception("投票数据为空");
  1000. }
  1001. }
  1002. }
  1003. $result = ArticleSurvey::insert($suvey_data);
  1004. if (!$result) {
  1005. throw new \Exception("投票失败");
  1006. }
  1007. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  1008. if (!$result) {
  1009. throw new \Exception("投票失败");
  1010. }
  1011. } else {
  1012. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  1013. }
  1014. Db::commit();
  1015. return Result::success([]);
  1016. } catch (\Throwable $ex) {
  1017. Db::rollBack();
  1018. var_dump($ex->getMessage());
  1019. return Result::error("更新失败" . $ex->getMessage(), 0);
  1020. }
  1021. }
  1022. /**
  1023. * 更新资讯状态
  1024. * @param array $data
  1025. * @return array
  1026. */
  1027. public function upArticleStatus(array $data): array
  1028. {
  1029. $articleData = Article::where(['id' => $data['id']])->first();
  1030. //发送10次
  1031. // for ($i = 0; $i < 10; $i++) {
  1032. // $this->sendMessage([
  1033. // 'talk_type' => 100,
  1034. // 'title' => $i . $articleData['title'],
  1035. // 'content' => '审核通过',
  1036. // 'messageType' => 2,
  1037. // 'user_id' => $articleData['admin_user_id'],
  1038. // ]);
  1039. // }
  1040. // var_dump($data['status'], 'status');
  1041. // return Result::success();
  1042. if ($data['status'] == 1) {
  1043. $this->sendMessage([
  1044. 'talk_type' => 101,
  1045. 'title' => $articleData['title'],
  1046. 'content' => '审核通过',
  1047. 'messageType' => 2,
  1048. 'user_id' => $articleData['admin_user_id'],
  1049. ]);
  1050. }
  1051. if ($data['status'] == 2) {
  1052. $this->sendMessage([
  1053. 'talk_type' => 101,
  1054. 'title' => $articleData['title'],
  1055. 'content' => '审核拒绝',
  1056. 'messageType' => 2,
  1057. 'user_id' => $articleData['admin_user_id'],
  1058. ]);
  1059. }
  1060. if ($data['status'] == 0) {
  1061. $this->sendMessage([
  1062. 'talk_type' => 100,
  1063. 'title' => $articleData['title'],
  1064. 'content' => '提交了审核',
  1065. 'messageType' => 2,
  1066. ]);
  1067. }
  1068. $result = Article::where(['id' => $data['id']])->update($data);
  1069. // ------c_show_time********up_status*******
  1070. // 若是审核通过 则更新c_show_time
  1071. if ($data['status'] == 1) {
  1072. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  1073. $web = Article::where('article.id', $data['id'])
  1074. ->leftJoin('website_category', 'article.catid', 'website_category.category_id')
  1075. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  1076. ->select(
  1077. 'website_id',
  1078. Db::raw('CASE WHEN website.id IS NULL THEN 2 WHEN JSON_CONTAINS(website.`website_column_arr_id`, \'3\') THEN 1 ELSE 0 END as is_core')
  1079. )
  1080. ->get();
  1081. // 非核心站与核心站----显示时间-----间隔
  1082. $time = 20;
  1083. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  1084. $waiting_interval = 5;
  1085. $webArray = $web->toArray();
  1086. if (empty($webArray)) {
  1087. throw new \Exception('网站分类不存在');
  1088. }
  1089. // 直接使用当前系统时间,不再强制添加8小时
  1090. $now = date('Y-m-d H:i:s');
  1091. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  1092. if (isset($data['ignore_ids'])) {
  1093. $ignore_website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  1094. if (in_array($item['website_id'], $ignore_website_ids)) {
  1095. $is_ignore = 1;
  1096. } else {
  1097. $is_ignore = 0;
  1098. }
  1099. return [
  1100. 'article_id' => $data['id'],
  1101. 'website_id' => $item['website_id'],
  1102. 'is_ignore' => $is_ignore,
  1103. ];
  1104. } else {
  1105. // 检查 $item 对象是否有 is_core 属性
  1106. if (!isset($item['is_core'])) {
  1107. throw new \Exception('$item 对象缺少 is_core 属性');
  1108. }
  1109. // 当 is_core 为 2 时,则表示此网站不存在
  1110. if ($item['is_core'] == 2) {
  1111. return null;
  1112. } else if ($item['is_core'] == 1) {
  1113. // 当 is_core 为 1 时,则表示此网站是核心站
  1114. $c_show_time = $now;
  1115. } else {
  1116. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  1117. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  1118. if ($item['is_core'] == 0) {
  1119. $time += $waiting_interval;
  1120. }
  1121. }
  1122. return [
  1123. 'article_id' => $data['id'],
  1124. 'website_id' => $item['website_id'],
  1125. 'c_show_time' => $c_show_time,
  1126. ];
  1127. }
  1128. }, array_keys($webArray), $webArray)));
  1129. if (!empty($article_ignore) && !isset($data['ignore_ids'])) {
  1130. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  1131. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  1132. $websiteIds = $web->pluck('website_id')->toArray();
  1133. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  1134. $article_ignores = ArticleIgnore::upsert(
  1135. $article_ignore,
  1136. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1137. ['c_show_time'] // 需要更新的字段
  1138. );
  1139. if (!$article_ignores) {
  1140. throw new \Exception('c端展示时间插入失败');
  1141. }
  1142. }
  1143. if (!empty($data['ignore_ids'])) {
  1144. // return Result::success($article_ignore);
  1145. // 从数据库中删除 article_id 为 $data['id'] 且 website_id 在 $website_ids 中的记录
  1146. if (!empty($article_ignore)) {
  1147. $article_ignores = ArticleIgnore::upsert(
  1148. $article_ignore,
  1149. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1150. ['is_ignore'] // 需要更新的字段
  1151. );
  1152. // if(!$article_ignores){
  1153. // throw new \Exception('屏蔽网站更新失败');
  1154. // }
  1155. }
  1156. }
  1157. }
  1158. // ------c_show_time********up_status*******
  1159. if ($result) {
  1160. return Result::success();
  1161. } else {
  1162. return Result::error("更新状态失败", 0);
  1163. }
  1164. }
  1165. /**
  1166. * 获取新闻详情
  1167. * @param array $data
  1168. * @return array
  1169. */
  1170. public function getArticleInfo(array $data): array
  1171. {
  1172. $where = [
  1173. 'article.id' => $data['id'],
  1174. // 'article.status' => 1,
  1175. ];
  1176. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  1177. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  1178. $info = $result;
  1179. // var_dump($info, 'info');
  1180. $info['survey_array'] = $articleSurvey;
  1181. if ($result) {
  1182. return Result::success($info);
  1183. } else {
  1184. return Result::error("查询失败", 0);
  1185. }
  1186. }
  1187. /**
  1188. * 获取头条新闻
  1189. * @param array $data
  1190. * @return array
  1191. */
  1192. public function getWebsiteArticlett(array $data): array
  1193. {
  1194. $website_id = $data['website_id'];
  1195. $website = Website::where('id', $data['website_id'])->first();
  1196. if (empty($website)) {
  1197. return Result::error("网站不存在", 0);
  1198. }
  1199. $categorys = $this->processArticlePro($website_id);
  1200. $catiall = $categorys['catiall'];
  1201. $categoryIds = $categorys['categoryIds'];
  1202. $where = [
  1203. 'status' => 1
  1204. ];
  1205. // $website_column = $website['column'];
  1206. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1207. $website_column = json_decode($website['website_column_arr_id'], true);
  1208. }
  1209. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1210. // return Result::success($diff_pid_categoryIds);
  1211. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1212. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1213. }
  1214. // $website_id = $data['website_id'];
  1215. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  1216. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  1217. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  1218. switch ($data['level']) {
  1219. case 1:
  1220. case 2:
  1221. case 3:
  1222. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  1223. $query = Article::where($where)
  1224. ->where('level', 'like', '%' . $data['level'] . '%')
  1225. ->orderBy('updated_at', 'desc');
  1226. break;
  1227. case 4: //最新资讯
  1228. $query = Article::where($where)->orderBy('updated_at', 'desc');
  1229. break;
  1230. case 5: //资讯推荐
  1231. $query = Article::where($where)
  1232. ->where('updated_at', '>', $month);
  1233. break;
  1234. case 7: //资讯分类
  1235. if (isset($data['id']) && !empty($data['id'])) {
  1236. $keyword = Article::where('id', $data['id'])->value('keyword');
  1237. $keywordArray = explode(',', $keyword);
  1238. $whereL7 = [];
  1239. foreach ($keywordArray as $k => $v) {
  1240. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1241. }
  1242. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  1243. break;
  1244. } else {
  1245. return Result::error("请输入资讯ID", 0);
  1246. break;
  1247. }
  1248. default:
  1249. break;
  1250. }
  1251. // $whereL7 = [];
  1252. // if(isset($data['id']) && !empty($data['id'])){
  1253. // $keyword = Article::where('id', $data['id'])->value('keyword');
  1254. // $keywordArray = explode(',', $keyword);
  1255. // foreach ($keywordArray as $k => $v) {
  1256. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1257. // }
  1258. // }
  1259. // $query = Article::where($where)
  1260. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  1261. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  1262. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  1263. // }
  1264. // if($data['level'] == 7){
  1265. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  1266. // }
  1267. // if($data['level'] == 4){
  1268. // $query = $query->inRandomOrder()
  1269. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  1270. // }
  1271. // if($data['level'] == 5){
  1272. // $query = $query->orderBy('updated_at','desc');
  1273. // }
  1274. // });
  1275. if ($data['textnum'] > 0) {
  1276. $query = clone $query;
  1277. $result['text'] = $query
  1278. ->whereIn('catid', $categoryIds)
  1279. ->leftJoinSub(function ($query) use ($website_id) {
  1280. $query->from('article_ignore')
  1281. ->where('website_id', $website_id);
  1282. }, 'article_ignore', function ($join) {
  1283. $join->on('article_ignore.article_id', '=', 'article.id');
  1284. })
  1285. ->where(function ($query) {
  1286. $query->whereNull('article_ignore.article_id')
  1287. ->orWhere(function ($subQuery) {
  1288. $subQuery->whereNotNull('article_ignore.article_id')
  1289. ->where('article_ignore.is_ignore', 0)
  1290. ->where(function ($subSubQuery) {
  1291. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1292. ->orWhereNull('article_ignore.c_show_time');
  1293. });
  1294. });
  1295. })
  1296. // ->where(function ($query) use ($website_id) {
  1297. // $query->whereNull('article_ignore.article_id')
  1298. // ->orWhere('article_ignore.website_id', '!=', $website_id);
  1299. // })
  1300. ->select(
  1301. 'article.id',
  1302. 'article.title',
  1303. 'article.author',
  1304. 'article.updated_at',
  1305. 'article.introduce',
  1306. 'article.islink',
  1307. 'article.linkurl',
  1308. 'article.copyfrom',
  1309. 'article.cat_arr_id',
  1310. 'article.catid',
  1311. 'article.level',
  1312. // 'article_ignore.is_ignore',
  1313. // 'article_ignore.c_show_time',
  1314. )
  1315. ->offset($data['placeid'])
  1316. ->limit($data['textnum'])
  1317. ->get()->all();
  1318. foreach ($result['text'] as $k => $v) {
  1319. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1320. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  1321. }
  1322. }
  1323. if ($data['imgnum'] > 0) {
  1324. $query = clone $query;
  1325. if ($data['textnum'] == 0) {
  1326. $query = $query->leftJoinSub(function ($query) use ($website_id) {
  1327. $query->from('article_ignore')
  1328. ->where('website_id', $website_id);
  1329. }, 'article_ignore', function ($join) {
  1330. $join->on('article_ignore.article_id', '=', 'article.id');
  1331. })
  1332. ->where(function ($query) {
  1333. $query->whereNull('article_ignore.article_id')
  1334. ->orWhere(function ($subQuery) {
  1335. $subQuery->whereNotNull('article_ignore.article_id')
  1336. ->where('article_ignore.is_ignore', 0)
  1337. ->where(function ($subSubQuery) {
  1338. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1339. ->orWhereNull('article_ignore.c_show_time');
  1340. });
  1341. });
  1342. });
  1343. }
  1344. $result['img'] = $query
  1345. ->whereIn('catid', $categoryIds)
  1346. ->where('article.imgurl', '!=', '')
  1347. ->select(
  1348. 'article.id',
  1349. 'article.title',
  1350. 'article.imgurl',
  1351. 'article.author',
  1352. 'article.updated_at',
  1353. 'article.introduce',
  1354. 'article.islink',
  1355. 'article.linkurl',
  1356. 'article.copyfrom',
  1357. 'article.cat_arr_id',
  1358. 'article.catid',
  1359. 'article.level',
  1360. // 'article_ignore.is_ignore',
  1361. // 'article_ignore.c_show_time',
  1362. )
  1363. ->offset($data['placeid'])
  1364. ->limit($data['imgnum'])
  1365. ->get()->all();
  1366. foreach ($result['img'] as $k => $v) {
  1367. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1368. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1369. }
  1370. }
  1371. if (empty($result)) {
  1372. return Result::error("暂无相关资讯", 0);
  1373. }
  1374. return Result::success($result);
  1375. }
  1376. /**
  1377. * 获取模块新闻
  1378. * @param array $data
  1379. * @return array
  1380. */
  1381. public function getWebsiteModelArticles(array $data): array
  1382. {
  1383. $catid = $data['catid'];
  1384. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1385. $category = $category->toArray();
  1386. if (!empty($category)) {
  1387. $where = [
  1388. 'status' => 1,
  1389. 'catid' => $catid,
  1390. ];
  1391. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1392. // 1:文字新闻;2:轮播图;3:图文;
  1393. // 级别:0:未分类
  1394. // 3:推荐图片
  1395. if ($data['level'] == 1) {
  1396. $data['level'] = 0;
  1397. }
  1398. $result = Article::where($where)
  1399. ->where(function ($query) use ($data) {
  1400. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1401. ->orWhereNull("level")
  1402. ->orWhereRaw("level = '[]'");
  1403. })
  1404. ->leftJoinSub(function ($query) use ($data) {
  1405. $query->from('article_ignore')
  1406. ->where('website_id', $data['website_id']);
  1407. }, 'article_ignore', function ($join) {
  1408. $join->on('article_ignore.article_id', '=', 'article.id');
  1409. })
  1410. ->where(function ($query) {
  1411. $query->whereNull('article_ignore.article_id')
  1412. ->orWhere(function ($subQuery) {
  1413. $subQuery->whereNotNull('article_ignore.article_id')
  1414. ->where('article_ignore.is_ignore', 0)
  1415. ->where(function ($subSubQuery) {
  1416. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1417. ->orWhereNull('article_ignore.c_show_time');
  1418. });
  1419. });
  1420. })
  1421. // ->where(function ($query) use ($data) {
  1422. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1423. // ->orWhereNull("ignore_ids");
  1424. // })
  1425. ->orderBy("updated_at", "desc")
  1426. ->offset($placeid)
  1427. ->limit($data['pagesize'])
  1428. ->get();
  1429. if (empty($result)) {
  1430. return Result::error("此栏目暂无相关新闻", 0);
  1431. }
  1432. } else {
  1433. return Result::error("此网站暂无此栏目", 0);
  1434. }
  1435. return Result::success($result);
  1436. }
  1437. /**
  1438. *获取新闻列表
  1439. * @param array $data
  1440. * @return array
  1441. */
  1442. public function getWebsiteArticleList(array $data): array
  1443. {
  1444. // return Result::success($data);
  1445. $where[] = ['status', '=', 1];
  1446. $website_id = $data['website_id'];
  1447. $website = Website::where('id', $data['website_id'])->first();
  1448. if (empty($website)) {
  1449. return Result::error("网站不存在", 0);
  1450. }
  1451. // $website_column = $website['column'];
  1452. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1453. $website_column = json_decode($website['website_column_arr_id'], true);
  1454. }
  1455. $categorys = $this->processArticlePro($website_id);
  1456. $cat_1st_arr = $categorys['cat_1st_arr'];
  1457. $catiall = $categorys['catiall'];
  1458. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1459. // return Result::success($diff_pid_categoryIds);
  1460. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1461. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1462. }
  1463. if (isset($data['catid']) && !empty($data['catid'])) {
  1464. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1465. if (empty($category)) {
  1466. return Result::error("此网站暂无此栏目", 0);
  1467. }
  1468. array_push($where, ['catid', '=', $data['catid']]);
  1469. }
  1470. // return Result::success($where);
  1471. $query = Article::where($where)
  1472. ->leftJoinSub(function ($query) use ($website_id) {
  1473. $query->from('article_ignore')
  1474. ->where('website_id', $website_id);
  1475. }, 'article_ignore', function ($join) {
  1476. $join->on('article_ignore.article_id', '=', 'article.id');
  1477. })
  1478. ->where(function ($query) {
  1479. $query->whereNull('article_ignore.article_id')
  1480. ->orWhere(function ($subQuery) {
  1481. $subQuery->whereNotNull('article_ignore.article_id')
  1482. ->where('article_ignore.is_ignore', 0)
  1483. ->where(function ($subSubQuery) {
  1484. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1485. ->orWhereNull('article_ignore.c_show_time');
  1486. });
  1487. });
  1488. })
  1489. ->select(
  1490. 'article.id',
  1491. 'article.title',
  1492. 'article.imgurl',
  1493. 'article.author',
  1494. 'article.updated_at',
  1495. 'article.introduce',
  1496. 'article.islink',
  1497. 'article.linkurl',
  1498. 'article.copyfrom',
  1499. 'article.cat_arr_id',
  1500. 'article.catid'
  1501. );
  1502. $count = $query->count();
  1503. $rep = $query->orderBy("updated_at", "desc")
  1504. ->offset(($data['page'] - 1) * $data['pageSize'])
  1505. ->limit($data['pageSize'])
  1506. ->get()->all();
  1507. $categorys = $this->processArticlePro($website_id);
  1508. $cat_1st_arr = $categorys['cat_1st_arr'];
  1509. $catiall = $categorys['catiall'];
  1510. // $web['website_id'] = $data['website_id'];
  1511. foreach ($rep as $k => $v) {
  1512. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1513. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1514. }
  1515. // $rep = $this->processArticles($rep,$web);
  1516. $data = [
  1517. 'rows' => $rep,
  1518. 'count' => $count,
  1519. ];
  1520. if (empty($rep)) {
  1521. return Result::error("没有信息数据");
  1522. }
  1523. return Result::success($data);
  1524. }
  1525. /**
  1526. * 前端-获取新闻详情
  1527. * @param array $data
  1528. * @return array
  1529. */
  1530. public function selectWebsiteArticleInfo(array $data): array
  1531. {
  1532. $where = [
  1533. 'article.id' => $data['id'],
  1534. 'article.status' => 1,
  1535. ];
  1536. $result = Article::where($where)
  1537. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1538. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1539. // ->where(function ($query) use ($data) {
  1540. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1541. // ->orWhereNull("ignore_ids");
  1542. // })
  1543. ->leftJoinSub(function ($query) use ($data) {
  1544. $query->from('article_ignore')
  1545. ->where('website_id', $data['website_id']);
  1546. }, 'article_ignore', function ($join) {
  1547. $join->on('article_ignore.article_id', '=', 'article.id');
  1548. })
  1549. ->where(function ($query) {
  1550. $query->whereNull('article_ignore.article_id')
  1551. ->orWhere(function ($subQuery) {
  1552. $subQuery->whereNotNull('article_ignore.article_id')
  1553. ->where('article_ignore.is_ignore', 0)
  1554. ->where(function ($subSubQuery) {
  1555. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1556. ->orWhereNull('article_ignore.c_show_time');
  1557. });
  1558. });
  1559. })
  1560. ->select(
  1561. 'article.*',
  1562. 'article_data.content',
  1563. 'article_data.article_id',
  1564. 'article_extend.website_url',
  1565. 'article_extend.email',
  1566. 'article_extend.contacts',
  1567. 'article_extend.contacts_mobile',
  1568. 'article_extend.contacts_address',
  1569. 'article_extend.zip_code',
  1570. 'article_extend.enterprise_name'
  1571. )
  1572. ->first();
  1573. if (empty($result)) {
  1574. return Result::error("暂无此新闻!", 0);
  1575. }
  1576. if (!empty($result['publiced_at'])) {
  1577. $result['updated_at'] = $result['publiced_at'];
  1578. }
  1579. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1580. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1581. ->where('website_category.website_id', $data['website_id'])
  1582. ->where(['website_category.category_id' => $result['catid']])
  1583. ->first();
  1584. if (empty($category)) {
  1585. return Result::error("查询失败", 0);
  1586. }
  1587. //手动推荐文章
  1588. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1589. if (empty($commend_ids)) {
  1590. $commendArticle = [];
  1591. } else {
  1592. //去除不存在的文章ID
  1593. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1594. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1595. ->leftJoinSub(function ($query) use ($data) {
  1596. $query->from('article_ignore')
  1597. ->where('website_id', $data['website_id']);
  1598. }, 'article_ignore', function ($join) {
  1599. $join->on('article_ignore.article_id', '=', 'article.id');
  1600. })
  1601. ->where(function ($query) {
  1602. $query->whereNull('article_ignore.article_id')
  1603. ->orWhere(function ($subQuery) {
  1604. $subQuery->whereNotNull('article_ignore.article_id')
  1605. ->where('article_ignore.is_ignore', 0)
  1606. ->where(function ($subSubQuery) {
  1607. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1608. ->orWhereNull('article_ignore.c_show_time');
  1609. });
  1610. });
  1611. })
  1612. ->where('article.status', 1)
  1613. ->where('website_category.website_id', $data['website_id'])
  1614. ->select('article.id', 'article.cat_arr_id', 'article.title', 'article.catid', 'article.imgurl', 'article.hits', 'article.created_at', 'website_category.alias', 'website_category.alias_pinyin', 'website_category.website_id')
  1615. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1616. // ->orderBy('article.updated_at', 'desc')
  1617. ->limit(5)
  1618. ->get();
  1619. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1620. foreach ($commendArticle as $k => $v) {
  1621. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1622. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1623. $cat_arr_id = array_unique($cat_arr_id);
  1624. // 从website_category取出alias_pinyin
  1625. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1626. ->whereIn('category_id', $cat_arr_id)
  1627. ->pluck('alias_pinyin', 'category_id')
  1628. ->toArray();
  1629. // 将cat_arr_id的json转成路径/隔开
  1630. $path_parts = [];
  1631. foreach ($cat_arr_id as $cat_id) {
  1632. if (isset($cat_arr[$cat_id])) {
  1633. $path_parts[] = $cat_arr[$cat_id];
  1634. }
  1635. }
  1636. $v->alias_pinyin = implode('/', $path_parts);
  1637. } else {
  1638. $v->alias_pinyin = '';
  1639. }
  1640. }
  1641. }
  1642. $result['category_id'] = $category['category_id'];
  1643. $result['cat_name'] = $category['alias'];
  1644. $result['website_name'] = $category['website_name'] ?? "";
  1645. $result['suffix'] = $category['suffix'] ?? "";
  1646. $result['commendArticle'] = $commendArticle;
  1647. $result['commend_ids'] = $commend_ids;
  1648. return Result::success($result);
  1649. }
  1650. /**
  1651. * 前端-获取网站调查问卷
  1652. * @param array $data
  1653. * @return array
  1654. */
  1655. public function getWebsiteSurvey(array $data): array
  1656. {
  1657. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1658. $website = Website::where('id', $data['website_id'])->first();
  1659. if (empty($website)) {
  1660. return Result::error("暂无此网站", 0);
  1661. }
  1662. }
  1663. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1664. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1665. if (empty($article)) {
  1666. return Result::error("暂无此文章", 0);
  1667. }
  1668. // return Result::error($data,0);
  1669. $where['art_id'] = $data['art_id'];
  1670. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1671. } else {
  1672. $survey = Article::where(function ($query) {
  1673. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1674. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1675. })
  1676. ->where('status', 1)
  1677. ->where('is_survey', 1)
  1678. ->select('survey_id')
  1679. ->orderBy('updated_at', 'desc')
  1680. ->first();
  1681. if (empty($survey)) {
  1682. return Result::error("暂无调查问卷", 0);
  1683. }
  1684. $where['sur_id'] = $survey['survey_id'];
  1685. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1686. }
  1687. // return Result::success($where);
  1688. $result = ArticleSurvey::where($where)
  1689. ->where(function ($query) {
  1690. $query->where('is_other', 0)
  1691. ->orWhere(function ($subQuery) {
  1692. $subQuery->where('is_other', 1)
  1693. ->where('other_id', 0);
  1694. });
  1695. })
  1696. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1697. ->select('article_survey.*', 'article.survey_type')
  1698. ->get()->all();
  1699. if (empty($result)) {
  1700. return Result::error("此文章暂无调查问卷", 0);
  1701. }
  1702. return Result::success($result);
  1703. }
  1704. /**
  1705. * 前端-添加网站调查问卷选项
  1706. * @param array $data
  1707. * @return array
  1708. */
  1709. public function addWebsiteSurveyOption(array $data): array
  1710. {
  1711. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1712. $website = Website::where('id', $data['website_id'])->first();
  1713. if (empty($website)) {
  1714. return Result::error("暂无此网站", 0);
  1715. }
  1716. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1717. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1718. if (empty($survey)) {
  1719. return Result::error("此调查问卷不可添加选项", 0);
  1720. }
  1721. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1722. $choice = [
  1723. 'art_id' => $survey['art_id'],
  1724. 'website_id' => $data['website_id'],
  1725. 'survey_name' => $survey['survey_name'],
  1726. 'choice_name' => $data['choice_name'],
  1727. 'sur_id' => $survey['sur_id'],
  1728. 'is_other' => 1,
  1729. 'other_id' => $survey['id'],
  1730. ];
  1731. $result = ArticleSurvey::insertGetId($choice);
  1732. if (empty($result)) {
  1733. return Result::error("添加失败", 0);
  1734. }
  1735. return Result::success($result);
  1736. }
  1737. }
  1738. return Result::error("添加失败", 0);
  1739. }
  1740. return Result::error("添加失败", 0);
  1741. }
  1742. /**
  1743. * 前端-调查问卷投票
  1744. * @param array $data
  1745. * @return array
  1746. */
  1747. public function addWebsiteSurveyVote(array $data): array
  1748. {
  1749. // return Result::success($data);
  1750. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1751. $website = Website::where('id', $data['website_id'])->first();
  1752. if (empty($website)) {
  1753. return Result::error("暂无此网站", 0);
  1754. }
  1755. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1756. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1757. // return Result::success($survey);
  1758. if (empty($is_survey)) {
  1759. return Result::error("此调查问卷不存在", 0);
  1760. }
  1761. // return Result::success($survey);
  1762. // 调查问卷类型
  1763. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1764. //多选 若是json型则转化成数组类型
  1765. if (strpos($data['choice_id'], '[') === 0) {
  1766. $data['choice_id'] = json_decode($data['choice_id'], true);
  1767. } else {
  1768. // 单选 也转换成数组
  1769. $data['choice_id'] = [$data['choice_id']];
  1770. }
  1771. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1772. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1773. // ->where('website_id',$data['website_id'])
  1774. ->where('is_other', 1)
  1775. ->where('other_id', 0)
  1776. ->first();
  1777. if (!empty($other)) {
  1778. return Result::error("请选择已有的选项!", 0);
  1779. }
  1780. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1781. // ->where('website_id',$data['website_id'])
  1782. ->where('is_other', 1)
  1783. ->where('other_id', '!=', 0)
  1784. ->first();
  1785. // return Result::success($choice['other']);
  1786. $choice_id = $data['choice_id'];
  1787. if (!empty($choice['other'])) {
  1788. // array_push($data['choice_id'],$choice['other']['other_id']);
  1789. if (!empty($choice_id)) {
  1790. $key = array_search($choice['other']['id'], $choice_id);
  1791. if ($key !== false) {
  1792. unset($choice_id[$key]);
  1793. $choice_id = array_values($choice_id);
  1794. }
  1795. array_push($choice_id, $choice['other']['other_id']);
  1796. } else {
  1797. $choice_id[0] = $choice['other']['other_id'];
  1798. }
  1799. array_push($data['choice_id'], $choice['other']['other_id']);
  1800. }
  1801. // return Result::success($data);
  1802. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1803. // ->where('website_id',$data['website_id'])
  1804. ->increment('results', 1);
  1805. if (empty($choice)) {
  1806. return Result::error("请选择已有的选项!", 0);
  1807. }
  1808. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1809. // ->where('website_id',$data['website_id'])
  1810. ->where('other_id', 0)
  1811. ->get();
  1812. $survey['choice'] = $choice_id;
  1813. return Result::success($survey);
  1814. }
  1815. return Result::error("参数必填!");
  1816. }
  1817. return Result::error("此调查问卷不存在", 0);
  1818. }
  1819. return Result::error("参数必填!");
  1820. }
  1821. /**
  1822. * 后端-获取网站调查问卷列表
  1823. * @param array $data
  1824. * @return array
  1825. */
  1826. public function getSurveyList(array $data): array
  1827. {
  1828. $where = [];
  1829. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1830. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1831. }
  1832. $survey_type = isset($data['survey_type']) && $data['survey_type'] !== '' ? $data['survey_type'] : null;
  1833. if (!empty($where)) {
  1834. // 修复:先关联 article 再按 survey_type 过滤,避免查不到数据
  1835. $query = ArticleSurvey::select(
  1836. 'art_id as id',
  1837. Db::raw('MAX(id) as surid'),
  1838. Db::raw('MAX(survey_name) as survey_name'),
  1839. Db::raw('MAX(sur_id) as survey_id')
  1840. )
  1841. ->groupBy('art_id')
  1842. ->where($where)
  1843. ->when(!is_null($survey_type), function ($q) use ($survey_type) {
  1844. $q->whereIn('art_id', function ($sub) use ($survey_type) {
  1845. $sub->select('id')
  1846. ->from('article')
  1847. ->where('survey_type', $survey_type);
  1848. });
  1849. })
  1850. ->with(['article' => function ($query) {
  1851. $query->select('id', 'survey_type','created_at','updated_at','created_at');
  1852. }]);
  1853. ;
  1854. }else{
  1855. $query = ArticleSurvey::select(
  1856. 'art_id as id',
  1857. Db::raw('MAX(id) as surid'),
  1858. Db::raw('MAX(survey_name) as survey_name'),
  1859. Db::raw('MAX(sur_id) as survey_id'),
  1860. )
  1861. ->groupBy('art_id')
  1862. ->when(!is_null($survey_type), function ($q) use ($survey_type) {
  1863. $q->whereIn('art_id', function ($sub) use ($survey_type) {
  1864. $sub->select('id')
  1865. ->from('article')
  1866. ->where('survey_type', $survey_type);
  1867. });
  1868. })
  1869. ->with(['article' => function ($query) {
  1870. $query->select('id', 'survey_type','created_at','updated_at','created_at');
  1871. }]);
  1872. }
  1873. $count = $query->get()->count();
  1874. // 简单写法:直接统计分组后的 art_id 数量
  1875. $survey = $query->orderBy('id', 'desc')
  1876. ->limit($data['pageSize'])
  1877. ->offset(($data['page'] - 1) * $data['pageSize'])
  1878. ->get();
  1879. if (empty($survey->toArray())) {
  1880. return Result::error("暂无调查问卷!", 0);
  1881. }
  1882. $survey = array_map(function ($item) {
  1883. $item['survey_type'] = $item['article']['survey_type'];
  1884. $item['created_at'] = $item['article']['created_at'];
  1885. $item['updated_at'] = $item['article']['updated_at'];
  1886. unset($item['article']);
  1887. return $item;
  1888. }, $survey->toArray());
  1889. $result = [
  1890. 'rows' => $survey,
  1891. 'count' => $count,
  1892. ];
  1893. return Result::success($result);
  1894. }
  1895. /**
  1896. * 后端-获取网站调查问卷详情
  1897. * @param array $data
  1898. * @return array
  1899. */
  1900. public function getSurveyInfo(array $data): array
  1901. {
  1902. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1903. $where = ['sur_id' => $data['sur_id']];
  1904. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1905. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1906. ->select('article_survey.*', 'article.survey_type')
  1907. ->get()->all();
  1908. if (empty($choose)) {
  1909. return Result::error("此调查问卷不存在", 0);
  1910. }
  1911. $resultsArray = array_column($choose, 'results');
  1912. $total = array_sum($resultsArray);
  1913. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1914. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1915. // $total = 0;
  1916. if (!empty($other)) {
  1917. $total = $total + $other['results'];
  1918. $other['choice_name'] = '(其他)';
  1919. if (!empty($others)) {
  1920. $other['hasChildren'] = true;
  1921. // array_push($other,['hasChildren','=',true]);
  1922. $other['children'] = $others;
  1923. $other_choices = [$other->toArray()];
  1924. $mer_choice = array_merge($choose, $other_choices);
  1925. $value_choice = array_values($mer_choice);
  1926. } else {
  1927. // return Result::error('1111');
  1928. $other_choices = [$other->toArray()];
  1929. $other_choices = array_merge($choose, $other_choices);
  1930. $value_choice = array_values($other_choices);
  1931. // return Result::success($result);
  1932. }
  1933. } else {
  1934. $value_choice = $choose;
  1935. }
  1936. $result = [
  1937. 'choose' => $value_choice,
  1938. 'total' => $total,
  1939. ];
  1940. }
  1941. return Result::success($result);
  1942. }
  1943. /**
  1944. * 前端-搜索新闻列表
  1945. * @param array $data
  1946. * @return array
  1947. */
  1948. public function selectWebsiteArticle(array $data): array
  1949. {
  1950. $website = Website::where('id', $data['website_id'])->first();
  1951. if (empty($website)) {
  1952. return Result::error("网站不存在", 0);
  1953. }
  1954. // $website_column = $website['column'];
  1955. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1956. $website_column = json_decode($website['website_column_arr_id'], true);
  1957. }
  1958. $website_id = $data['website_id'];
  1959. $categorys = $this->processArticlePro($website_id);
  1960. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1961. // return Result::success($diff_pid_categoryIds);
  1962. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1963. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1964. }
  1965. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1966. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1967. $catiall = $categorys['catiall'];
  1968. $categoryIds = $categorys['categoryIds'];
  1969. // return Result::success($categoryIds);
  1970. $query = Article::where('status', 1)
  1971. ->whereIn('catid', $categoryIds)
  1972. ->leftJoinSub(function ($query) use ($website_id) {
  1973. $query->from('article_ignore')
  1974. ->where('website_id', $website_id);
  1975. }, 'article_ignore', function ($join) {
  1976. $join->on('article_ignore.article_id', '=', 'article.id');
  1977. })
  1978. ->where(function ($query) {
  1979. $query->whereNull('article_ignore.article_id')
  1980. ->orWhere(function ($subQuery) {
  1981. $subQuery->whereNotNull('article_ignore.article_id')
  1982. ->where('article_ignore.is_ignore', 0)
  1983. ->where(function ($subSubQuery) {
  1984. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1985. ->orWhereNull('article_ignore.c_show_time');
  1986. });
  1987. });
  1988. });
  1989. // ->get()->all();
  1990. // return Result::success($query);
  1991. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1992. $query->whereRaw("JSON_CONTAINS(article.city_arr_id, '" . intval($data['cityid']) . "')");
  1993. }
  1994. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1995. $query->whereRaw("JSON_CONTAINS(article.department_arr_id, '" . intval($data['department_id']) . "')");
  1996. }
  1997. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1998. $query->where('article.title', 'like', '%' . $data['keyword'] . '%');
  1999. }
  2000. // 计算总数
  2001. $count = $query->count();
  2002. // return Result::success($count);
  2003. // 分页查询
  2004. $articles = $query
  2005. ->select(
  2006. 'article.id',
  2007. 'article.title',
  2008. 'article.imgurl',
  2009. 'article.author',
  2010. 'article.updated_at',
  2011. 'article.introduce',
  2012. 'article.islink',
  2013. 'article.linkurl',
  2014. 'article.copyfrom',
  2015. 'article.cat_arr_id',
  2016. 'article.catid',
  2017. 'article.department_arr_id',
  2018. 'article.city_arr_id',
  2019. // 'article_ignore.c_show_time',
  2020. // 'article_ignore.is_ignore'
  2021. )
  2022. ->orderBy("updated_at", "desc")
  2023. ->offset(($data['page'] - 1) * $data['pageSize'])
  2024. ->limit($data['pageSize'])
  2025. ->get();
  2026. // return Result::success($articles);
  2027. foreach ($articles as $k => $v) {
  2028. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  2029. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2030. }
  2031. if (empty($articles)) {
  2032. return Result::error("没有符合条件的资讯数据");
  2033. }
  2034. $result = [
  2035. 'rows' => $articles,
  2036. 'count' => $count,
  2037. ];
  2038. return Result::success($result);
  2039. }
  2040. /**
  2041. * 模块新闻加强版
  2042. * @param array $data
  2043. * @return array
  2044. */
  2045. public function getWebsiteCatidArticle(array $data): array
  2046. {
  2047. $where = [
  2048. 'website_category.category_id' => $data['catid'],
  2049. 'website_category.website_id' => $data['website_id'],
  2050. ];
  2051. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  2052. $child_catnum = $data['child_catnum'] ?? 1;
  2053. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  2054. $childCategoryIds = array_column($category['child'], 'category_id');
  2055. if (empty($childCategoryIds)) {
  2056. return Result::error("暂无子栏目", 0);
  2057. }
  2058. $imgArticles = [];
  2059. $textArticles = [];
  2060. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  2061. // 初始化子分类图片新闻和文字新闻数组
  2062. // 查询所有子级栏目的图文新闻
  2063. $imgArticles = Article::where('catid', $childCategoryIds[0])
  2064. ->where(function ($query) use ($data) {
  2065. $query->where(function ($subQuery) use ($data) {
  2066. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2067. })->orWhereNull("ignore_ids");
  2068. })
  2069. ->where('status', 1)
  2070. ->where('imgurl', '!=', '')
  2071. ->select('*')
  2072. ->orderBy('updated_at', 'desc')
  2073. ->limit($data['child_imgnum'])
  2074. ->get();
  2075. }
  2076. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  2077. // 查询所有子级栏目的文字新闻
  2078. $textArticles = Article::where('catid', $childCategoryIds[0])
  2079. ->where('status', 1)
  2080. ->where(function ($query) use ($data) {
  2081. $query->where(function ($subQuery) use ($data) {
  2082. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2083. })->orWhereNull("ignore_ids");
  2084. })
  2085. ->select('*')
  2086. ->orderBy('updated_at', 'desc')
  2087. ->limit($data['child_textnum'])
  2088. ->get();
  2089. }
  2090. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  2091. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  2092. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  2093. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  2094. return $child;
  2095. }, $category['child']);
  2096. }
  2097. // }
  2098. if (isset($data['img_num']) && !empty($data['img_num'])) {
  2099. $category['img'] = WebsiteCategory::where($where)
  2100. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2101. ->where('article.status', 1)
  2102. ->where('article.imgurl', '!=', '')
  2103. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2104. ->orderBy('article.updated_at', 'desc')
  2105. ->limit($data['img_num'])
  2106. ->get();
  2107. }
  2108. if (isset($data['text_num']) && !empty($data['text_num'])) {
  2109. $category['text'] = WebsiteCategory::where($where)
  2110. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2111. ->where('article.status', 1)
  2112. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2113. ->orderBy('article.updated_at', 'desc')
  2114. ->limit($data['text_num'])
  2115. ->get();
  2116. }
  2117. // $category = $category->get();
  2118. if (empty($category)) {
  2119. return Result::error("查询失败", 0);
  2120. }
  2121. return Result::success($category);
  2122. }
  2123. /**
  2124. * 模块新闻加强plus版
  2125. * @param array $data
  2126. * @return array
  2127. */
  2128. public function getWebsiteAllArticle(array $data): array
  2129. {
  2130. // return Result::success($data);
  2131. $time1 = microtime(true);
  2132. $wetbsite_id = $data['website_id'] ?? 2;
  2133. $data = json_decode($data['id'], true);
  2134. $website = Website::where('id', $wetbsite_id)->first();
  2135. if (empty($website)) {
  2136. return Result::error("网站不存在", 0);
  2137. }
  2138. // return Result::success($website);
  2139. $website_column = $website['website_column_arr_id'] ?? '[]';
  2140. $website_column = json_decode($website_column, true);
  2141. $categorys = $this->processArticlePro($wetbsite_id);
  2142. $cat_1st_arr = $categorys['cat_1st_arr'];
  2143. $catiall = $categorys['catiall'];
  2144. // return Result::success($catiall);
  2145. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2146. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2147. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2148. }
  2149. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  2150. // return Result::success($categorys);
  2151. $parent_category = array_column($data, 'parent');
  2152. $parent_cat = [];
  2153. $child_category = array_column($data, 'child');
  2154. if (!empty($parent_category)) {
  2155. foreach ($parent_category as $key => $value) {
  2156. $arr = array_map('intval', explode(',', $value));
  2157. $parent_cat[$key] = $arr[0] ?? 0;
  2158. $parent_category = $arr[0] ?? 0;
  2159. $article_imgnum = $arr[1] ?? 0;
  2160. $article_textnum = $arr[2] ?? 0;
  2161. if ($parent_category != 0) {
  2162. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2163. // return Result::success($category_arr);
  2164. if ($article_imgnum != 0) {
  2165. $img_article = Article::whereIn('catid', $category_arr)
  2166. ->where('status', 1)
  2167. ->where('imgurl', '!=', '')
  2168. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2169. $query->from('article_ignore')
  2170. ->where('website_id', $wetbsite_id);
  2171. }, 'article_ignore', function ($join) {
  2172. $join->on('article_ignore.article_id', '=', 'article.id');
  2173. })
  2174. ->where(function ($query) {
  2175. $query->whereNull('article_ignore.article_id')
  2176. ->orWhere(function ($subQuery) {
  2177. $subQuery->whereNotNull('article_ignore.article_id')
  2178. ->where('article_ignore.is_ignore', 0)
  2179. ->where(function ($subSubQuery) {
  2180. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2181. ->orWhereNull('article_ignore.c_show_time');
  2182. });
  2183. });
  2184. })
  2185. ->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')
  2186. ->orderBy('updated_at', 'desc')
  2187. ->limit($article_imgnum)
  2188. ->get()->all();
  2189. foreach ($img_article as $k => $v) {
  2190. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2191. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2192. }
  2193. } else {
  2194. $img_article = [];
  2195. }
  2196. if ($article_textnum != 0) {
  2197. $text_article = Article::whereIn('catid', $category_arr)
  2198. ->where('status', 1)
  2199. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2200. $query->from('article_ignore')
  2201. ->where('website_id', $wetbsite_id);
  2202. }, 'article_ignore', function ($join) {
  2203. $join->on('article_ignore.article_id', '=', 'article.id');
  2204. })
  2205. ->where(function ($query) {
  2206. $query->whereNull('article_ignore.article_id')
  2207. ->orWhere(function ($subQuery) {
  2208. $subQuery->whereNotNull('article_ignore.article_id')
  2209. ->where('article_ignore.is_ignore', 0)
  2210. ->where(function ($subSubQuery) {
  2211. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2212. ->orWhereNull('article_ignore.c_show_time');
  2213. });
  2214. });
  2215. })
  2216. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2217. ->orderBy('updated_at', 'desc')
  2218. ->limit($article_textnum)
  2219. ->get()->all();
  2220. foreach ($text_article as $k => $v) {
  2221. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2222. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2223. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2224. }
  2225. } else {
  2226. $text_article = [];
  2227. }
  2228. $catiall[$parent_category]['imgnum'] = $img_article;
  2229. $catiall[$parent_category]['textnum'] = $text_article;
  2230. $parent[$key] = $catiall[$parent_category];
  2231. } else {
  2232. $parent[$key] = '';
  2233. }
  2234. }
  2235. }
  2236. if (!empty($child_category)) {
  2237. foreach ($child_category as $key => $value) {
  2238. $arr = array_map('intval', explode(',', $value));
  2239. $parent_category = $parent_cat[$key];
  2240. $child_category = $arr[0] ?? 0;
  2241. $article_imgnum = $arr[1] ?? 0;
  2242. $article_textnum = $arr[2] ?? 0;
  2243. if ($child_category != 0) {
  2244. $all_childcat = $cat_1st_arr[$parent_category];
  2245. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  2246. // 从 $websiteInfoIndexed 中获取对应的数据
  2247. $info = $websiteInfoIndexed[$v];
  2248. // 返回一个包含所需信息的数组
  2249. return [
  2250. 'alias' => $info->alias,
  2251. 'category_id' => $info->category_id,
  2252. 'aLIas_pinyin' => $info->aLIas_pinyin,
  2253. 'pid' => $info->pid,
  2254. 'type' => $info->type,
  2255. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  2256. 'pinyin' => $info->pinyin,
  2257. ];
  2258. }, $all_childcat);
  2259. if ($article_imgnum != 0) {
  2260. $img_article = Article::where('catid', $child_category)
  2261. ->where('status', 1)
  2262. ->where('imgurl', '!=', '')
  2263. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2264. $query->from('article_ignore')
  2265. ->where('website_id', $wetbsite_id);
  2266. }, 'article_ignore', function ($join) {
  2267. $join->on('article_ignore.article_id', '=', 'article.id');
  2268. })
  2269. ->where(function ($query) {
  2270. $query->whereNull('article_ignore.article_id')
  2271. ->orWhere(function ($subQuery) {
  2272. $subQuery->whereNotNull('article_ignore.article_id')
  2273. ->where('article_ignore.is_ignore', 0)
  2274. ->where(function ($subSubQuery) {
  2275. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2276. ->orWhereNull('article_ignore.c_show_time');
  2277. });
  2278. });
  2279. })
  2280. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2281. ->orderBy('updated_at', 'desc')
  2282. ->limit($article_imgnum)
  2283. ->get()->all();
  2284. foreach ($img_article as $k => $v) {
  2285. // var_dump($v);
  2286. // var_dump($k);
  2287. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2288. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2289. }
  2290. } else {
  2291. $img_article = [];
  2292. }
  2293. if ($article_textnum != 0) {
  2294. $text_article = Article::where('catid', $child_category)
  2295. ->where('status', 1)
  2296. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2297. $query->from('article_ignore')
  2298. ->where('website_id', $wetbsite_id);
  2299. }, 'article_ignore', function ($join) {
  2300. $join->on('article_ignore.article_id', '=', 'article.id');
  2301. })
  2302. ->where(function ($query) {
  2303. $query->whereNull('article_ignore.article_id')
  2304. ->orWhere(function ($subQuery) {
  2305. $subQuery->whereNotNull('article_ignore.article_id')
  2306. ->where('article_ignore.is_ignore', 0)
  2307. ->where(function ($subSubQuery) {
  2308. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2309. ->orWhereNull('article_ignore.c_show_time');
  2310. });
  2311. });
  2312. })
  2313. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2314. ->orderBy('updated_at', 'desc')
  2315. ->limit($article_textnum)
  2316. ->get()->all();
  2317. foreach ($text_article as $k => $v) {
  2318. // var_dump($v);
  2319. // var_dump($k);
  2320. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2321. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2322. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2323. }
  2324. } else {
  2325. $text_article = [];
  2326. }
  2327. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  2328. $catiall[$child_category]['imgnum'] = $img_article;
  2329. $catiall[$child_category]['textnum'] = $text_article;
  2330. $child[$key] = $catiall[$child_category];
  2331. // var_dump($pids);
  2332. } else {
  2333. $child[$key] = '';
  2334. }
  2335. }
  2336. }
  2337. foreach ($parent as $key => $value) {
  2338. $result[$key] = $value;
  2339. if (!empty($child[$key])) {
  2340. // var_dump($child[$key]);
  2341. $result[$key]['child'] = $child[$key];
  2342. // $value[$key]['child'] = $child[$key];
  2343. } else {
  2344. $result[$key]['child'] = [
  2345. "alias" => null,
  2346. "category_id" => null,
  2347. "type" => null,
  2348. "pinyin" => null,
  2349. "all_childcat" => [],
  2350. "imgnum" => [],
  2351. "textnum" => []
  2352. ];
  2353. }
  2354. }
  2355. return Result::success($result);
  2356. }
  2357. /**
  2358. * 辅助方法:获取文章列表
  2359. */
  2360. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  2361. {
  2362. sleep(1);
  2363. $query = Article::where('article.status', 1)
  2364. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  2365. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  2366. ->where(function ($query) use ($website) {
  2367. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  2368. })
  2369. ->leftJoin('website_category', function ($join) use ($website) {
  2370. $join->on('article.catid', '=', 'website_category.category_id')
  2371. ->where('website_category.website_id', '=', $website['website_id']);
  2372. })
  2373. ->select(
  2374. 'article.id',
  2375. 'article.title',
  2376. 'article.imgurl',
  2377. 'article.author',
  2378. 'article.updated_at',
  2379. 'article.introduce',
  2380. 'article.islink',
  2381. 'article.linkurl',
  2382. 'article.copyfrom',
  2383. 'article.cat_arr_id',
  2384. 'article.catid',
  2385. 'website_category.alias as category_name'
  2386. )
  2387. ->orderBy('updated_at', 'desc')
  2388. ->limit($limit);
  2389. // 如果是图片文章,添加图片URL条件
  2390. if ($isImageArticle) {
  2391. $query->where('imgurl', '!=', '');
  2392. } else {
  2393. // 文字文章不需要imgurl字段
  2394. $query->addSelect('article.introduce');
  2395. }
  2396. $articles = $query->get();
  2397. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  2398. }
  2399. /**
  2400. * 乡村网-获取特殊新闻模块
  2401. * @param array $data
  2402. * @return array
  2403. */
  2404. public function getWebsiteArticles(array $data): array
  2405. {
  2406. $website_id = $data['website_id'];
  2407. $website = Website::where('id', $website_id)->first();
  2408. if (empty($website)) {
  2409. return Result::error("网站不存在", 0);
  2410. }
  2411. // return Result::success($website);
  2412. $website_column = $website['website_column_arr_id'] ?? '[]';
  2413. $website_column = json_decode($website_column, true);
  2414. $catids = json_decode($data['id'], true);
  2415. $parent_category = array_column($catids, 'parent');
  2416. if (!empty($parent_category) && is_array($parent_category)) {
  2417. $categorys = $this->processArticlePro($website_id);
  2418. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2419. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2420. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2421. }
  2422. $catiall = $categorys['catiall'];
  2423. $cat_1st_arr = $categorys['cat_1st_arr'];
  2424. // return Result::success($categorys);
  2425. foreach ($parent_category as $key => $value) {
  2426. $arr = array_map('intval', explode(',', $value));
  2427. $parent_category = $arr[0] ?? 0;
  2428. $article_imgnum = $arr[1] ?? 0;
  2429. $article_textnum = $arr[2] ?? 0;
  2430. if ($parent_category != 0) {
  2431. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2432. // return Result::success($category_arr);
  2433. if ($article_imgnum != 0) {
  2434. $img_article = Article::whereIn('article.catid', $category_arr)
  2435. ->where('article.status', 1)
  2436. ->where('article.imgurl', '!=', '')
  2437. ->leftJoinSub(function ($query) use ($website_id) {
  2438. $query->from('article_ignore')
  2439. ->where('website_id', $website_id);
  2440. }, 'article_ignore', function ($join) {
  2441. $join->on('article_ignore.article_id', '=', 'article.id');
  2442. })
  2443. ->where(function ($query) {
  2444. $query->whereNull('article_ignore.article_id')
  2445. ->orWhere(function ($subQuery) {
  2446. $subQuery->whereNotNull('article_ignore.article_id')
  2447. ->where('article_ignore.is_ignore', 0)
  2448. ->where(function ($subSubQuery) {
  2449. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2450. ->orWhereNull('article_ignore.c_show_time');
  2451. });
  2452. });
  2453. })
  2454. ->select(
  2455. 'article.id',
  2456. 'article.title',
  2457. 'article.imgurl',
  2458. 'article.author',
  2459. 'article.updated_at',
  2460. 'article.introduce',
  2461. 'article.islink',
  2462. 'article.linkurl',
  2463. 'article.copyfrom',
  2464. 'article.cat_arr_id',
  2465. 'article.catid as category_id'
  2466. )
  2467. ->orderBy('updated_at', 'desc')
  2468. ->limit($article_imgnum)
  2469. ->get()->all();
  2470. foreach ($img_article as $k => $v) {
  2471. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2472. // return Result::success($v);
  2473. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2474. }
  2475. } else {
  2476. $img_article = [];
  2477. }
  2478. if ($article_textnum != 0) {
  2479. $text_article = Article::whereIn('article.catid', $category_arr)
  2480. ->where('article.status', 1)
  2481. ->leftJoinSub(function ($query) use ($website_id) {
  2482. $query->from('article_ignore')
  2483. ->where('website_id', $website_id);
  2484. }, 'article_ignore', function ($join) {
  2485. $join->on('article_ignore.article_id', '=', 'article.id');
  2486. })
  2487. ->where(function ($query) {
  2488. $query->whereNull('article_ignore.article_id')
  2489. ->orWhere(function ($subQuery) {
  2490. $subQuery->whereNotNull('article_ignore.article_id')
  2491. ->where('article_ignore.is_ignore', 0)
  2492. ->where(function ($subSubQuery) {
  2493. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2494. ->orWhereNull('article_ignore.c_show_time');
  2495. });
  2496. });
  2497. })
  2498. ->select(
  2499. 'article.id',
  2500. 'article.title',
  2501. 'article.author',
  2502. 'article.updated_at',
  2503. 'article.introduce',
  2504. 'article.islink',
  2505. 'article.linkurl',
  2506. 'article.copyfrom',
  2507. 'article.cat_arr_id',
  2508. 'article.catid as category_id'
  2509. )
  2510. ->orderBy('updated_at', 'desc')
  2511. ->limit($article_textnum)
  2512. ->get()->all();
  2513. foreach ($text_article as $k => $v) {
  2514. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2515. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2516. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2517. }
  2518. } else {
  2519. $text_article = [];
  2520. }
  2521. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2522. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2523. $parent[$key] = $catiall[$parent_category];
  2524. } else {
  2525. $parent[$key] = [];
  2526. }
  2527. }
  2528. }
  2529. return Result::success($parent);
  2530. }
  2531. // 封装处理商品的路由问题
  2532. function processGoods($goods, $data)
  2533. {
  2534. return $goods->map(function ($good) use ($data) {
  2535. $catid = $good->catid ?? 0;
  2536. // $pinyin = '';
  2537. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2538. if (!empty($category->pid) && $category->pid != 0) {
  2539. $level = json_decode($category->category_arr_id, true);
  2540. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2541. ->whereIn('category_id', $level)
  2542. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2543. ->get(['aLIas_pinyin'])
  2544. ->pluck('aLIas_pinyin')
  2545. ->implode('/');
  2546. } else {
  2547. $pinyin = $category->aLIas_pinyin ?? '';
  2548. }
  2549. if (isset($good->city_id) && !empty($good->city_id)) {
  2550. $city = District::where('id', $good->city_id)->first(['name']);
  2551. $good->city_name = $city->name ?? '';
  2552. }
  2553. // 解析imgurl JSON并取第一条数据
  2554. $imgUrls = json_decode($good->imgurl, true);
  2555. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2556. $good->pinyin = $pinyin;
  2557. return $good;
  2558. });
  2559. }
  2560. /**
  2561. * 获取商城首页-根据栏目id
  2562. * @param array $data
  2563. * @return array
  2564. * */
  2565. function getWebsiteCatidshop(array $data): array
  2566. {
  2567. $input['catid'] = $data['catid'];
  2568. $input['website_id'] = $data['website_id'];
  2569. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2570. $result = array_map(function ($item) use ($input) {
  2571. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2572. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2573. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2574. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2575. if (empty($category) || $category->type != 2) {
  2576. return Result::error("暂无此栏目", 0);
  2577. } else {
  2578. $website['website_id'] = $input['website_id'];
  2579. $goods = Good::where('good.status', 2)
  2580. ->where('good.website_id', $website['website_id'])
  2581. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2582. ->select(
  2583. 'good.id',
  2584. 'good.name',
  2585. 'good.imgurl',
  2586. 'good.description',
  2587. 'good.updated_at',
  2588. 'good.catid',
  2589. 'good.type_id',
  2590. 'good.price',
  2591. 'good.com',
  2592. 'good.level',
  2593. 'good.unit'
  2594. )
  2595. ->orderBy('updated_at', 'desc')
  2596. ->offset($goodStart)
  2597. ->limit($goodNum);
  2598. $all_goods = $goods->get();
  2599. $all_goods = $this->processGoods($all_goods, $website);
  2600. }
  2601. return $all_goods ?? [];
  2602. }
  2603. }, $data);
  2604. return Result::success($result);
  2605. }
  2606. /**
  2607. * 获取商品模块
  2608. * @param array $data
  2609. * @return array
  2610. * */
  2611. public function getWebsiteshop(array $data): array
  2612. {
  2613. $input['id'] = $data['id'];
  2614. $input['website_id'] = $data['website_id'];
  2615. $catid = $data['catid'];
  2616. $data = json_decode($input['id'] ?? '', true) ?? [];
  2617. $result['goods'] = array_map(function ($item) use ($input) {
  2618. // 检查parent元素是否存在且不是undefined
  2619. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2620. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2621. $website = $input['website_id'];
  2622. $query = Good::where('good.status', 2)
  2623. ->where('good.website_id', $website);
  2624. switch ($Levelid) {
  2625. case 1:
  2626. case 2:
  2627. case 3:
  2628. $goods = $query->where(function ($q) use ($Levelid) {
  2629. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2630. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2631. });
  2632. break;
  2633. case 4:
  2634. $goods = $query;
  2635. break;
  2636. case 5:
  2637. $goods = $query->where('type_id', 1);
  2638. break;
  2639. case 6:
  2640. $goods = $query->where('type_id', 2);
  2641. break;
  2642. default:
  2643. return [];
  2644. }
  2645. $all_goods = $goods
  2646. ->select(
  2647. 'good.id',
  2648. 'good.name',
  2649. 'good.imgurl',
  2650. 'good.description',
  2651. 'good.updated_at',
  2652. 'good.catid',
  2653. 'good.type_id',
  2654. 'good.price',
  2655. 'good.level',
  2656. 'good.website_id'
  2657. )
  2658. ->orderBy('updated_at', 'desc')
  2659. ->offset($goodStart)
  2660. ->limit($goodNum)
  2661. ->get();
  2662. $web['website_id'] = $website;
  2663. $all_goods = $this->processGoods($all_goods, $web);
  2664. }
  2665. return $all_goods;
  2666. }, $data);
  2667. $website = $input['website_id'];
  2668. $result['article'] = Article::where(function ($query) use ($website) {
  2669. $query->where(function ($subQuery) use ($website) {
  2670. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2671. })->orWhereNull("ignore_ids");
  2672. })
  2673. ->where('catid', $catid)
  2674. ->where('article.status', 1)
  2675. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2676. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2677. ->orderBy('article.updated_at', 'desc')
  2678. ->first();
  2679. return Result::success($result);
  2680. }
  2681. /**
  2682. * 获取商品分类
  2683. * @param array $data
  2684. * @return array
  2685. * */
  2686. public function getWebsiteshopCat(array $data): array
  2687. {
  2688. $website = $data['website_id'];
  2689. $category = WebsiteCategory::where('website_id', $website)
  2690. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2691. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2692. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2693. ->orderBy('sort')
  2694. ->get();
  2695. $cat = $category->map(function ($item) use ($website) {
  2696. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2697. $pid = $item->pid ?? 0;
  2698. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2699. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2700. ->where('website_id', $website)
  2701. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2702. ->get(['aLIas_pinyin'])
  2703. ->pluck('aLIas_pinyin')
  2704. ->implode('/');
  2705. } else {
  2706. $pinyin = $item->aLIas_pinyin ?? '';
  2707. }
  2708. $item->pinyin = $pinyin;
  2709. });
  2710. if (empty($category)) {
  2711. return Result::error("栏目查询失败", 0);
  2712. }
  2713. $cat_tree = Result::buildMenuTree($category);
  2714. $web['website_id'] = $website;
  2715. $goods = Good::where('website_id', $website)
  2716. ->where('status', 2)
  2717. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2718. ->latest('updated_at')
  2719. ->offset(($data['page'] - 1) * $data['pageSize'])
  2720. ->limit($data['pageSize'])
  2721. ->get();
  2722. if (!empty($goods)) {
  2723. if ($goods->count() > 1 && !empty($goods)) {
  2724. $goods = $this->processGoods($goods, $web);
  2725. }
  2726. } else {
  2727. $goods = [];
  2728. }
  2729. $result = [
  2730. 'category' => $cat_tree,
  2731. 'goods' => $goods,
  2732. ];
  2733. // $resul['goods'] = $goods;
  2734. if (empty($result)) {
  2735. return Result::error("查询失败", 0);
  2736. }
  2737. return Result::success($result);
  2738. }
  2739. /*
  2740. * 获取商品列表
  2741. * @param array $data
  2742. * @return array
  2743. * */
  2744. public function getWebsiteshopList(array $data): array
  2745. {
  2746. // return Result::success($data);
  2747. $where = [
  2748. 'status' => 2,
  2749. 'website_id' => $data['website_id'],
  2750. ];
  2751. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2752. // return Result::error("查询失败", 0);
  2753. // }
  2754. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2755. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2756. $data['catid'] = $category->category_id ?? 0;
  2757. }
  2758. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2759. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2760. }
  2761. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2762. array_push($where, ['type_id', $data['type_id']]);
  2763. }
  2764. $query = Good::where($where)
  2765. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2766. $query->where(function ($q) use ($data) {
  2767. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2768. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2769. });
  2770. })
  2771. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2772. $query->where(function ($q) use ($data) {
  2773. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2774. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2775. });
  2776. })
  2777. ->select(
  2778. 'good.id',
  2779. 'good.name',
  2780. 'good.imgurl',
  2781. 'good.description',
  2782. 'good.updated_at',
  2783. 'good.com',
  2784. 'good.catid',
  2785. 'good.type_id',
  2786. 'good.website_id',
  2787. 'good.cat_arr_id',
  2788. 'good.created_at',
  2789. 'good.city_id'
  2790. )
  2791. ->latest('updated_at');
  2792. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2793. $result['count'] = $query->clone()->count();
  2794. $result['goods'] = $this->processGoods(
  2795. $query->clone()
  2796. ->offset(($data['page'] - 1) * $data['pageSize'])
  2797. ->limit($data['pageSize'])
  2798. ->get(),
  2799. $data
  2800. );
  2801. } else {
  2802. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2803. // 获取 type_id 为 1 的数据
  2804. $result['type1'] = $this->processGoods(
  2805. $query->clone()
  2806. ->where('type_id', 1)
  2807. ->offset(($data['page'] - 1) * $data['pageSize'])
  2808. ->limit($data['pageSize'])
  2809. ->get(),
  2810. $data
  2811. );
  2812. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2813. // 获取 type_id 为 2 的数据
  2814. $result['type2'] = $this->processGoods(
  2815. $query->clone()
  2816. ->where('type_id', 2)
  2817. ->offset(($data['page'] - 1) * $data['pageSize'])
  2818. ->limit($data['pageSize'])
  2819. ->get(),
  2820. $data
  2821. );
  2822. }
  2823. if (empty($result)) {
  2824. return Result::error("查询失败", 0);
  2825. }
  2826. return Result::success($result);
  2827. }
  2828. /**
  2829. * 获取商品详情
  2830. * @param array $data
  2831. * @return array
  2832. * */
  2833. public function getWebsiteshopInfo(array $data): array
  2834. {
  2835. $where = [
  2836. 'good.status' => 2,
  2837. 'good.website_id' => $data['website_id'],
  2838. 'good.id' => $data['id'],
  2839. ];
  2840. $goods = Good::where($where)
  2841. ->where('good.id', $data['id'])
  2842. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2843. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2844. ->first();
  2845. if (empty($goods)) {
  2846. return Result::error("查询失败", 0);
  2847. }
  2848. $goods->imgurl = json_decode($goods->imgurl, true);
  2849. return Result::success($goods);
  2850. }
  2851. /**
  2852. * plus pro 处理文章路由问题
  2853. */
  2854. function processArticlePro($website_id)
  2855. {
  2856. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2857. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2858. // // 取出category_id 对应的aLIas_pinyin
  2859. // $categoryIds = array_column($categorys, 'category_id');
  2860. // $categoryPIds = array_column($categorys, 'pid');
  2861. // $aliasPinyins = array_column($categorys, 'path');
  2862. // $alias = array_column($categorys, 'alias');
  2863. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2864. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2865. // // return Result::success($cat_arr);
  2866. // // $catiall = [];
  2867. // //一级所有子级的记录
  2868. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2869. // return [
  2870. // 'cat_1st_arr' => $cat_alias_arr,
  2871. // 'catiall' => $cat_arr,
  2872. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2873. // 'categoryIds' => $categoryIds,
  2874. // ];
  2875. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2876. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2877. // 取出category_id 对应的aLIas_pinyin
  2878. $categoryIds = array_column($categorys, 'category_id');
  2879. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
  2880. return $pid != 0;
  2881. })));
  2882. $category_path = array_column($categorys, 'path');
  2883. $cat_arr = array_combine($categoryIds, $category_path);
  2884. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2885. $catiall = [];
  2886. //一级所有子级的记录
  2887. $cat_1st_arr = [];
  2888. foreach ($categorys as $key => $value) {
  2889. // $category_arr_id = json_decode($value->category_arr_id);
  2890. // $pinyin_str = '';
  2891. // // 算出一级 并且算出子级
  2892. if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
  2893. $cat_1st_arr[$value->pid][] = $value->category_id;
  2894. }
  2895. // foreach ($category_arr_id as $k => $v) {
  2896. // $pinyin_str .= $cat_arr[$v] . '/';
  2897. // }
  2898. // $pinyin_str = rtrim($pinyin_str, '/');
  2899. $catiall[$value->category_id]['alias'] = $value->alias;
  2900. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2901. $catiall[$value->category_id]['type'] = $value->type;
  2902. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2903. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2904. }
  2905. return [
  2906. 'cat_1st_arr' => $cat_1st_arr,
  2907. 'catiall' => $catiall,
  2908. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2909. 'categoryIds' => $categoryIds,
  2910. 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
  2911. 'categoryPIds' => $categoryPIds,
  2912. ];
  2913. }
  2914. /**
  2915. * 封装处理文章的路由问题
  2916. * */
  2917. function processArticles($articles, $data)
  2918. {
  2919. // 检查 $articles 是否为数组或可迭代对象
  2920. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2921. return $articles->map(function ($article) use ($data) {
  2922. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2923. $catid = $article->cat_arr_id ?? '';
  2924. }
  2925. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2926. $catid = $article->category_arr_id ?? '';
  2927. }
  2928. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2929. $level = json_decode($catid, true);
  2930. if (!is_array($level)) {
  2931. return $article;
  2932. } else {
  2933. $level = array_map('intval', $level);
  2934. }
  2935. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2936. ->where($data)
  2937. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2938. ->pluck('aLIas_pinyin')
  2939. ->implode('/');
  2940. $article->pinyin = $pinyin ?? '';
  2941. return $article;
  2942. });
  2943. } else {
  2944. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2945. $catid = $articles->cat_arr_id ?? '';
  2946. $level = json_decode($catid, true);
  2947. if (!is_array($level)) {
  2948. return $articles;
  2949. } else {
  2950. $level = array_map('intval', $level);
  2951. }
  2952. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2953. ->where($data)
  2954. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2955. ->pluck('aLIas_pinyin')
  2956. ->implode('/');
  2957. $articles->pinyin = $pinyin ?? '';
  2958. return $articles;
  2959. }
  2960. }
  2961. // 封装处理由问题
  2962. function processJob($job, $data)
  2963. {
  2964. return $job->map(function ($job) use ($data) {
  2965. $category = $job->cat_arr_id ?? '';
  2966. $cityid = $job->city_arr_id ?? '';
  2967. $city = json_decode($cityid, true);
  2968. $pinyin = '';
  2969. $level = json_decode($category, true);
  2970. // 路由
  2971. if (!empty($level) && is_array($level)) {
  2972. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2973. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2974. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2975. ->get(['aLIas_pinyin'])
  2976. ->pluck('aLIas_pinyin')
  2977. ->implode('/');
  2978. if (empty($pinyin)) {
  2979. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2980. }
  2981. $job->pinyin = $pinyin;
  2982. }
  2983. // 取职位-城市 市??省
  2984. if (!empty($city) && is_array($city)) {
  2985. if (isset($city[1]) && !empty($city[1])) {
  2986. $city = District::where('id', $city[1])->first(['name']);
  2987. $job->city_name = $city->name ?? '';
  2988. } else if (isset($city[0]) && !empty($city[0])) {
  2989. $city = District::where('id', $city[0])->first(['name']);
  2990. $job->city_name = $city->name ?? '';
  2991. } else {
  2992. $job->city_name = '全国';
  2993. }
  2994. }
  2995. // 获取简历最后一级地区
  2996. if (isset($job->city_id) && !empty($job->city_id)) {
  2997. $city = District::where('id', $job->city_id)->first(['name']);
  2998. $job->hunt_cityname = $city->name ?? '';
  2999. }
  3000. // 组合详细地址
  3001. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  3002. $address_id = json_decode($job->address_arr_id, true) ?? [];
  3003. if (is_array($address_id) && !empty($address_id)) {
  3004. $address = District::whereIn('id', $address_id)
  3005. ->orderBy('level', 'asc')
  3006. ->get(['name'])
  3007. ->pluck('name')
  3008. ->implode('');
  3009. // $job->address_name = $address ?? '';
  3010. $job->address_name = ($address ?? '') . ($job->address ?? '');
  3011. }
  3012. }
  3013. // 取行业
  3014. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  3015. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  3016. if (!empty($job->industry)) {
  3017. $query->where('hyid', $job->industry);
  3018. } else if (!empty($job->hy_id)) {
  3019. $query->where('hyid', $job->hy_id);
  3020. } else if (!empty($job->company_hy_id)) {
  3021. $query->where('hyid', $job->company_hy_id);
  3022. } else {
  3023. $query->where('hyid', $job->job_industry);
  3024. }
  3025. })->first(['hyname']);
  3026. $job->hy_name = $hy_name->hyname ?? '';
  3027. }
  3028. // 取职位类别
  3029. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  3030. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  3031. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  3032. $job->zw_name = $zw_name->zwname ?? '';
  3033. }
  3034. // 取具体职位
  3035. 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))) {
  3036. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  3037. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  3038. $job->jtzw_name = $jtzw_name->zwname ?? '';
  3039. }
  3040. // 取工作经验
  3041. if (isset($job->experience) && !empty($job->experience)) {
  3042. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  3043. $job->experience_name = $experience->ename ?? '';
  3044. }
  3045. // 取学历
  3046. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  3047. $education = $job->educational ?? $job->school_education;
  3048. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  3049. $job->education_name = $education->ename ?? '';
  3050. }
  3051. // 语言
  3052. if (isset($job->language) && !empty($job->language)) {
  3053. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  3054. $job->language_name = $language->ename ?? '';
  3055. }
  3056. // 薪资
  3057. if (isset($job->salary) && !empty($job->salary)) {
  3058. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  3059. $job->salary_name = $salary->ename ?? '';
  3060. }
  3061. // 职位性质
  3062. if (isset($job->nature_id) && !empty($job->nature_id)) {
  3063. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  3064. $job->job_nature_name = $job_nature->ename ?? '';
  3065. }
  3066. // 公司规模
  3067. if (isset($job->company_size) && !empty($job->company_size)) {
  3068. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  3069. $job->company_size_name = $company_size->ename ?? '';
  3070. }
  3071. // 公司性质
  3072. if (isset($job->company_nature) && !empty($job->company_nature)) {
  3073. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  3074. $job->company_nature_name = $company_nature->nature_name ?? '';
  3075. }
  3076. // $job->pinyin = $pinyin;
  3077. return $job;
  3078. });
  3079. }
  3080. /**
  3081. * 获取书籍模块
  3082. * @param array $data
  3083. * @return array
  3084. * */
  3085. public function getWebsiteBook(array $data): array
  3086. {
  3087. $input['id'] = $data['id'];
  3088. $input['website_id'] = $data['website_id'];
  3089. // 将 JSON 字符串转换为 PHP 数组
  3090. $data = json_decode($input['id'], true);
  3091. // 使用 array_map 处理每个元素
  3092. $result = array_map(function ($item) use ($input) {
  3093. // 检查parent元素是否存在且不是undefined
  3094. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  3095. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3096. $website = [
  3097. 'website_id' => $input['website_id'],
  3098. ];
  3099. // 查询栏目名称
  3100. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3101. if (empty($category)) {
  3102. $parent_alias = '';
  3103. $parent_pinyin = null;
  3104. $imgBooks = [];
  3105. $textBooks = [];
  3106. } else {
  3107. $parent_alias = $category->alias ?? '';
  3108. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  3109. // 查找子分类ID数组
  3110. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  3111. array_push($childCategoryIds, $parentCatId);
  3112. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  3113. if ($parentImgNum != 0) {
  3114. // 查询图片新闻
  3115. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  3116. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3117. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3118. })
  3119. ->where('book.status', 2)
  3120. ->where('book.img_url', '!=', '')
  3121. ->where('book.website_id', $website['website_id'])
  3122. ->leftJoin('website_category', function ($join) use ($website) {
  3123. $join->on('book.cat_id', '=', 'website_category.category_id')
  3124. ->where('website_category.website_id', '=', $website['website_id']);
  3125. })
  3126. ->select(
  3127. 'book.id',
  3128. 'book.title',
  3129. 'book.img_url',
  3130. 'book.price',
  3131. 'book.market_price',
  3132. 'book.description',
  3133. 'book.cat_id',
  3134. 'book.description',
  3135. 'book.updated_at',
  3136. 'website_category.alias as category_name',
  3137. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3138. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3139. )
  3140. ->orderBy('updated_at', 'desc')
  3141. ->limit($parentImgNum)
  3142. ->get()->all();
  3143. // 查询文字新闻
  3144. }
  3145. if ($parentTextNum != 0) {
  3146. $textBooks = [];
  3147. $textBooks = Book::where(function ($query) use ($parentCatId) {
  3148. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3149. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3150. })
  3151. ->where('book.status', 2)
  3152. ->where('book.website_id', $website['website_id'])
  3153. ->leftJoin('website_category', function ($join) use ($website) {
  3154. $join->on('book.cat_id', '=', 'website_category.category_id')
  3155. ->where('website_category.website_id', '=', $website['website_id']);
  3156. })
  3157. ->select(
  3158. 'book.id',
  3159. 'book.title',
  3160. 'book.img_url',
  3161. 'book.price',
  3162. 'book.market_price',
  3163. 'book.description',
  3164. 'book.cat_id',
  3165. 'book.description',
  3166. 'book.updated_at',
  3167. 'website_category.alias as category_name',
  3168. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3169. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3170. )
  3171. ->orderBy('updated_at', 'desc')
  3172. ->limit($parentTextNum)
  3173. ->get()->all();
  3174. }
  3175. }
  3176. }
  3177. $resultItem = [
  3178. 'alias' => $parent_alias ?? '',
  3179. 'category_id' => $parentCatId ?? 0,
  3180. 'pinyin' => $parent_pinyin ?? null,
  3181. 'imgnum' => $imgBooks ?? [],
  3182. 'textnum' => $textBooks ?? [],
  3183. ];
  3184. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  3185. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  3186. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  3187. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3188. ->get()->all();
  3189. if (!empty($childCategory)) {
  3190. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  3191. // 查询子栏目名称
  3192. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  3193. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3194. ->first();
  3195. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  3196. $childImgArticles = [];
  3197. $childTextArticles = [];
  3198. $resultItem['child'] = [];
  3199. } else {
  3200. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  3201. // 查询子栏目图片新闻
  3202. $childImgArticles = Book::where('cat_id', $childCatId)
  3203. ->where('status', 2)
  3204. ->where('img_url', '!=', '')
  3205. ->where('book.website_id', $website['website_id'])
  3206. ->leftJoin('website_category', function ($join) use ($website) {
  3207. $join->on('book.cat_id', '=', 'website_category.category_id')
  3208. ->where('website_category.website_id', '=', $website['website_id']);
  3209. })
  3210. ->select(
  3211. 'book.id',
  3212. 'book.title',
  3213. 'book.img_url',
  3214. 'book.price',
  3215. 'book.market_price',
  3216. 'book.description',
  3217. 'book.cat_id',
  3218. 'book.description',
  3219. 'book.updated_at',
  3220. DB::raw("'$child_pinyin' as pinyin")
  3221. )
  3222. ->orderBy('updated_at', 'desc')
  3223. ->limit($childImgNum)
  3224. ->get()->all();
  3225. // 查询子栏目文字新闻
  3226. $childTextArticles = Book::where('cat_id', $childCatId)
  3227. ->where('status', 2)
  3228. ->where('book.website_id', $website['website_id'])
  3229. ->leftJoin('website_category', function ($join) use ($website) {
  3230. $join->on('book.cat_id', '=', 'website_category.category_id')
  3231. ->where('website_category.website_id', '=', $website['website_id']);
  3232. })
  3233. ->select(
  3234. 'book.id',
  3235. 'book.title',
  3236. 'book.img_url',
  3237. 'book.price',
  3238. 'book.market_price',
  3239. 'book.description',
  3240. 'book.cat_id',
  3241. 'book.description',
  3242. 'book.updated_at',
  3243. DB::raw("'$child_pinyin' as pinyin")
  3244. )
  3245. ->orderBy('updated_at', 'desc')
  3246. ->limit($childTextNum)
  3247. ->get()->all();
  3248. $resultItem['child'] = [
  3249. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  3250. 'category_id' => $childCatId,
  3251. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  3252. 'all_childcat' => $childCategory,
  3253. 'imgnum' => $childImgArticles,
  3254. 'textnum' => $childTextArticles,
  3255. ];
  3256. }
  3257. }
  3258. } else {
  3259. $resultItem['child'] = [];
  3260. }
  3261. return $resultItem;
  3262. }, $data);
  3263. return Result::success($result);
  3264. }
  3265. /**
  3266. * 获取书刊列表
  3267. * @param array $data
  3268. * @return array
  3269. * */
  3270. public function getWebsiteBookList(array $data): array
  3271. {
  3272. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3273. if (empty($web)) {
  3274. return Result::error("查询失败", 0);
  3275. }
  3276. $catid = $data['id'];
  3277. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  3278. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  3279. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  3280. $category_pinyin = $category ? $category->aLias_pinyin : '';
  3281. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  3282. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  3283. ->where('pid', $category['pid'])
  3284. ->select(
  3285. 'category_id',
  3286. 'alias',
  3287. 'aLIas_pinyin',
  3288. 'pid',
  3289. 'sort',
  3290. 'is_url',
  3291. 'web_url',
  3292. 'seo_title',
  3293. 'seo_keywords',
  3294. 'seo_description',
  3295. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  3296. )
  3297. ->orderBy('sort')
  3298. ->get()->all();
  3299. if (empty($category)) {
  3300. return Result::error("查询失败", 0);
  3301. }
  3302. $query = Book::where('book.status', 2)
  3303. ->where('book.website_id', $data['website_id'])
  3304. ->where('book.cat_id', $catid)
  3305. ->select(
  3306. 'book.id',
  3307. 'book.title',
  3308. 'book.img_url',
  3309. 'book.description',
  3310. 'book.updated_at',
  3311. 'book.cat_id',
  3312. DB::raw("'$pinyin' as pinyin")
  3313. )
  3314. ->orderBy('book.updated_at', 'desc');
  3315. $count = $query->count();
  3316. $query = clone $query;
  3317. $Book = $query
  3318. ->limit($data['pageSize'])
  3319. ->offset(($data['page'] - 1) * $data['pageSize'])
  3320. ->get()->all();
  3321. $result = [
  3322. 'category' => $categorys,
  3323. 'books' => $Book,
  3324. 'count' => $count,
  3325. ];
  3326. // if(empty($result)){
  3327. // return Result::error("查询失败", 0);
  3328. // }
  3329. return Result::success($result);
  3330. }
  3331. /**
  3332. * 获取书刊详情
  3333. * @param array $data
  3334. * @return array
  3335. * */
  3336. public function getWebsiteBookInfo(array $data): array
  3337. {
  3338. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3339. if (empty($web)) {
  3340. return Result::error("查询失败", 0);
  3341. }
  3342. $book = Book::where('status', 2)
  3343. ->where('website_id', $data['website_id'])
  3344. ->where('id', $data['id'])
  3345. ->select(
  3346. 'book.*',
  3347. )
  3348. ->orderBy('updated_at', 'desc')
  3349. ->first();
  3350. if (empty($book)) {
  3351. return Result::error("查询失败", 0);
  3352. }
  3353. // 先查询当前分类的 pid
  3354. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  3355. ->where('category_id', $book['cat_id'])
  3356. ->first(['pid', 'category_id']);
  3357. $query = WebsiteCategory::where('website_id', $data['website_id']);
  3358. if (!empty($carpid)) {
  3359. if ($carpid->pid != 0) {
  3360. $pid = $carpid['pid'];
  3361. // $parent_pinyin = '';
  3362. } else {
  3363. $pid = $carpid['category_id'];
  3364. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  3365. }
  3366. }
  3367. $categorys = $query->where('pid', $pid)
  3368. ->select(
  3369. 'category_id',
  3370. 'alias',
  3371. 'aLIas_pinyin',
  3372. 'pid',
  3373. 'sort',
  3374. 'is_url',
  3375. 'web_url',
  3376. 'category_arr_id as cat_arr_id',
  3377. )
  3378. ->orderBy('sort')
  3379. ->get();
  3380. $category = $this->processArticle($categorys, $data);
  3381. $result = [
  3382. 'category' => $category,
  3383. 'books' => $book,
  3384. ];
  3385. return Result::success($result);
  3386. }
  3387. /**
  3388. * 尝试
  3389. * @param array $data
  3390. * @return array
  3391. * */
  3392. public function test(array $data): array
  3393. {
  3394. $input['id'] = $data['id'];
  3395. $input['website_id'] = $data['website_id'];
  3396. // 将 JSON 字符串转换为 PHP 数组
  3397. $data = json_decode($input['id'], true);
  3398. $result = [];
  3399. $article = $data;
  3400. $result = array_map(function ($item) use ($input) {
  3401. $website = [
  3402. 'website_id' => $input['website_id'],
  3403. ];
  3404. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3405. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3406. $parent = [
  3407. 0 => $category['category_id'] ?? [],
  3408. 1 => $parentImgNum ?? [],
  3409. 2 => $parentTextNum ?? [],
  3410. ];
  3411. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  3412. $child = [];
  3413. $resultItem = [
  3414. // 'alias' => $parent_alias ?? '',
  3415. 'category_id' => $parentCatId ?? 0,
  3416. 'pinyin' => $parentImgNum ?? null,
  3417. 'imgnum' => $parentTextNum ?? [],
  3418. // 'textnum' => $textArticles ?? [],
  3419. ];
  3420. return $parent;
  3421. }, $data);
  3422. return Result::success($result);
  3423. // });
  3424. }
  3425. /**
  3426. * 封装处理文章的路由问题
  3427. * */
  3428. function processArticle($article, $data)
  3429. {
  3430. return $article->map(function ($article) use ($data) {
  3431. $catid = $article->cat_arr_id ?? '';
  3432. $level = json_decode($catid, true);
  3433. $pinyin = '';
  3434. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  3435. if (!empty($level) && is_array($level)) {
  3436. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  3437. ->where('website_id', $data['website_id'])
  3438. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3439. ->get(['aLIas_pinyin'])
  3440. ->pluck('aLIas_pinyin')
  3441. ->implode('/');
  3442. } else {
  3443. $pinyin = '';
  3444. }
  3445. $article->pinyin = $pinyin;
  3446. return $article;
  3447. });
  3448. }
  3449. /**
  3450. * c端-获取招工招聘下拉选框
  3451. * @param array $data
  3452. * @return array
  3453. * */
  3454. public function getWebsiteJobSelect(array $data): array
  3455. {
  3456. $web = Website::where('id', $data['website_id'])->first();
  3457. if (empty($web)) {
  3458. return Result::error("该网站不存在", 0);
  3459. }
  3460. $hy = JobIndustry::get()->all();
  3461. $zw = JobPosition::where('zwpid', 0)->get()->all();
  3462. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  3463. $result = [
  3464. 'hy' => $hy,
  3465. 'zw' => $zw,
  3466. 'jtzw' => $jtzw,
  3467. ];
  3468. if (empty($result)) {
  3469. return Result::error("查询失败", 0);
  3470. }
  3471. return Result::success($result);
  3472. }
  3473. /**
  3474. * c端-获取招工招聘
  3475. * @param array $data
  3476. * @return array
  3477. * */
  3478. public function getWebsiteJob(array $data): array
  3479. {
  3480. $web = Website::where('id', $data['website_id'])->first();
  3481. if (empty($web)) {
  3482. return Result::error("该网站不存在", 0);
  3483. }
  3484. $job_hunting = JobHunting::where('job_hunting.status', 2)
  3485. ->where('job_hunting.website_id', $data['website_id'])
  3486. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3487. $query->where(function ($q) use ($data) {
  3488. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3489. });
  3490. })
  3491. ->select(
  3492. 'job_hunting.id',
  3493. 'job_hunting.catid',
  3494. 'job_hunting.cat_arr_id',
  3495. 'job_hunting.job_name_get',
  3496. 'job_hunting.industry',
  3497. 'job_hunting.name',
  3498. 'job_hunting.sexy',
  3499. 'job_hunting.origin',
  3500. 'job_hunting.city_arr_id',
  3501. 'job_hunting.experience',
  3502. 'job_hunting.updated_at',
  3503. 'job_hunting.salary',
  3504. 'job_hunting.skillList',
  3505. 'job_hunting.slelf_evaluation',
  3506. )
  3507. ->orderBy('updated_at', 'desc')
  3508. ->limit($data['job1_num'])
  3509. ->get();
  3510. $web['website_id'] = $data['website_id'];
  3511. if (empty($job_hunting)) {
  3512. $job_huntings = "未查询到相关简历信息";
  3513. } else {
  3514. $job_huntings = $this->processJob($job_hunting, $web);
  3515. }
  3516. // 0:待审核 1:已通过 2:已拒绝
  3517. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3518. ->where('job_recruiting.website_id', $data['website_id'])
  3519. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3520. $query->where(function ($q) use ($data) {
  3521. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3522. });
  3523. })
  3524. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3525. ->select(
  3526. 'job_recruiting.id',
  3527. 'job_recruiting.catid',
  3528. 'job_recruiting.cat_arr_id',
  3529. 'job_recruiting.title',
  3530. 'job_recruiting.jtzw_id',
  3531. 'job_recruiting.hy_id',
  3532. 'job_recruiting.city_arr_id',
  3533. 'job_recruiting.due_data',
  3534. 'job_recruiting.updated_at',
  3535. 'job_recruiting.experience',
  3536. 'job_recruiting.educational',
  3537. 'job_recruiting.salary',
  3538. 'job_recruiting.zw_id',
  3539. 'job_company.business_name',
  3540. 'job_recruiting.keyword',
  3541. 'job_recruiting.description',
  3542. )
  3543. ->orderBy('updated_at', 'desc')
  3544. ->limit($data['job2_num'])
  3545. ->get();
  3546. if (empty($job_recruiting->toArray())) {
  3547. $job_recruitings = "未查询到相关职位信息";
  3548. } else {
  3549. $job_recruitings = $this->processJob($job_recruiting, $web);
  3550. }
  3551. $result = [
  3552. 'job_hunting' => $job_huntings,
  3553. 'job_recuiting' => $job_recruitings,
  3554. ];
  3555. return Result::success($result);
  3556. }
  3557. /**
  3558. * c端-获取招工招聘列表
  3559. * @param array $data
  3560. * @return array
  3561. * */
  3562. public function getWebsiteJobList(array $data): array
  3563. {
  3564. $recruit_where = [];
  3565. $hunt_where = [];
  3566. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3567. if (empty($web)) {
  3568. return Result::error("此网站不存在", 0);
  3569. }
  3570. $website_id['website_id'] = $data['website_id'];
  3571. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3572. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3573. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3574. }
  3575. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3576. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3577. }
  3578. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3579. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3580. }
  3581. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3582. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3583. }
  3584. $query = JobRecruiting::where('job_recruiting.status', 1)
  3585. ->where('job_recruiting.website_id', $data['website_id'])
  3586. ->where($recruit_where)
  3587. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3588. $query->where(function ($q) use ($data) {
  3589. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3590. });
  3591. })
  3592. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3593. $query->where(function ($q) use ($data) {
  3594. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3595. });
  3596. })
  3597. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3598. ->select(
  3599. 'job_recruiting.id',
  3600. 'job_recruiting.catid',
  3601. 'job_recruiting.hy_id',
  3602. 'job_recruiting.title',
  3603. 'job_recruiting.zw_id',
  3604. 'job_recruiting.educational',
  3605. 'job_recruiting.jtzw_id',
  3606. 'job_recruiting.city_arr_id',
  3607. 'job_recruiting.due_data',
  3608. 'job_recruiting.experience',
  3609. 'job_recruiting.cat_arr_id',
  3610. 'job_recruiting.updated_at',
  3611. 'job_company.business_name',
  3612. 'job_recruiting.keyword',
  3613. 'job_recruiting.description',
  3614. )
  3615. ->orderBy('job_recruiting.updated_at', 'desc');
  3616. $recruit_count = $query->count();
  3617. $query = clone $query;
  3618. $JobRecruiting = $query
  3619. ->offset(($data['page'] - 1) * $data['pageSize'])
  3620. ->limit($data['pageSize'])
  3621. ->get();
  3622. if (empty($JobRecruiting)) {
  3623. $JobRecruiting = "暂无相关职位信息";
  3624. } else {
  3625. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3626. }
  3627. }
  3628. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3629. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3630. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3631. }
  3632. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3633. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3634. }
  3635. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3636. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3637. }
  3638. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3639. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3640. }
  3641. $query = JobHunting::where('job_hunting.status', 2)
  3642. ->where('job_hunting.website_id', $data['website_id'])
  3643. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3644. ->where($hunt_where)
  3645. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3646. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3647. // })
  3648. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3649. $query->where(function ($q) use ($data) {
  3650. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3651. });
  3652. })
  3653. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3654. $query->where(function ($q) use ($data) {
  3655. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3656. });
  3657. })
  3658. ->select(
  3659. 'job_hunting.id',
  3660. 'job_hunting.catid',
  3661. 'job_hunting.sexy',
  3662. 'job_hunting.experience',
  3663. 'job_hunting.origin',
  3664. 'job_hunting.industry',
  3665. 'job_hunting.name',
  3666. 'job_hunting.job',
  3667. 'job_hunting.job_name_get',
  3668. 'job_hunting.city_arr_id',
  3669. 'job_hunting.cat_arr_id',
  3670. 'job_hunting.created_at',
  3671. 'job_hunting.updated_at',
  3672. 'job_position.zwname as job_name',
  3673. 'job_hunting.skillList',
  3674. 'job_hunting.slelf_evaluation',
  3675. )
  3676. ->orderBy('job_hunting.updated_at', 'desc');
  3677. $hunt_count = $query->count();
  3678. $query = clone $query;
  3679. $JobHunting = $query
  3680. ->offset(($data['page'] - 1) * $data['pageSize'])
  3681. ->limit($data['pageSize'])
  3682. ->get();
  3683. if (empty($JobHunting)) {
  3684. $JobRecruiting = "暂无相关简历信息";
  3685. } else {
  3686. $JobHunting = $this->processJob($JobHunting, $website_id);
  3687. }
  3688. }
  3689. $result = [
  3690. 'JobRecruiting' => $JobRecruiting ?? [],
  3691. 'recruit_count' => $recruit_count ?? 0,
  3692. 'JobHunting' => $JobHunting ?? [],
  3693. 'hunt_count' => $hunt_count ?? 0,
  3694. ];
  3695. return Result::success($result);
  3696. }
  3697. /**
  3698. * c端-获取招工招聘详情
  3699. * @param array $data
  3700. * @return array
  3701. * */
  3702. public function getWebsiteJobInfo(array $data): array
  3703. {
  3704. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3705. if (empty($web)) {
  3706. return Result::error("该网站不存在", 0);
  3707. }
  3708. $webid = [
  3709. 'website_id' => $data['website_id'],
  3710. ];
  3711. // 职位相关信息
  3712. if ($data['type'] == 1) {
  3713. $query = JobRecruiting::where('status', 1)
  3714. ->where('website_id', $data['website_id'])
  3715. ->select('*');
  3716. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3717. $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();
  3718. if (!empty($company)) {
  3719. $result['company'] = $this->processJob($company, $webid);
  3720. }
  3721. $other_job = JobRecruiting::where('status', 1)
  3722. ->where('website_id', $data['website_id'])
  3723. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3724. ->where('id', '!=', $data['id'])
  3725. ->where('user_id', '=', $job[0]['user_id'])
  3726. ->limit($data['pageSize'])
  3727. ->get();
  3728. if (!empty($other_job)) {
  3729. $result['other_job'] = $this->processJob($other_job, $webid);
  3730. }
  3731. } else {
  3732. // 简历相关信息
  3733. $job = JobHunting::where('job_hunting.status', 2)
  3734. ->where('job_hunting.website_id', $data['website_id'])
  3735. ->where('job_hunting.id', $data['id'])
  3736. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3737. ->select('job_hunting.*', 'user_name')
  3738. ->get();
  3739. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3740. if (!empty($resume->toArray())) {
  3741. $result['resume'] = 1;
  3742. } else {
  3743. $result['resume'] = 0;
  3744. }
  3745. }
  3746. if (empty($job->toArray())) {
  3747. return Result::error("id参数错误", 0);
  3748. }
  3749. if (!empty($job[0]['job_experience'])) {
  3750. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3751. if (!empty($job_experience)) {
  3752. // $hy = [];
  3753. foreach ($job_experience as $key => $value) {
  3754. // $id = $value['id'];
  3755. $hy[$key] = $value['job_industry'];
  3756. $zw_id[$key] = $value['job_typename'];
  3757. $jtzw_id[$key] = $value['job_name'];
  3758. }
  3759. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3760. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3761. // 先将关联表转换为索引数组,提高查找效率
  3762. $hyLookup = [];
  3763. foreach ($hy_table as $item) {
  3764. $hyLookup[$item['hyid']] = $item['hyname'];
  3765. }
  3766. $zwLookup = [];
  3767. foreach ($zw_table as $item) {
  3768. $zwLookup[$item['zwid']] = $item['zwname'];
  3769. }
  3770. foreach ($job_experience as $key => &$value) {
  3771. // 处理行业名称
  3772. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3773. $value['hy_name'] = $hyLookup[$hy[$key]];
  3774. }
  3775. // 处理职位名称
  3776. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3777. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3778. }
  3779. // 处理具体职位名称
  3780. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3781. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3782. }
  3783. }
  3784. // 释放引用,防止意外修改后续代码
  3785. unset($value);
  3786. }
  3787. $result['job_experience'] = $job_experience ?? [];
  3788. }
  3789. if (!empty($job[0]['education_experience'])) {
  3790. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3791. if (!empty($education_experience)) {
  3792. foreach ($education_experience as $key => $value) {
  3793. // $id = $value['id'];
  3794. $education[$key] = $value['school_education'];
  3795. }
  3796. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3797. // // 先将关联表转换为索引数组,提高查找效率
  3798. $educationLookup = [];
  3799. foreach ($education_table as $item) {
  3800. $educationLookup[$item['evalue']] = $item['ename'];
  3801. }
  3802. foreach ($education_experience as $key => &$value) {
  3803. // 处理学历名称
  3804. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3805. $value['education_name'] = $educationLookup[$education[$key]];
  3806. }
  3807. }
  3808. }
  3809. $result['education_experience'] = $job_experience ?? [];
  3810. }
  3811. $result['job'] = $this->processJob($job, $webid);
  3812. // // 返现对应的栏目
  3813. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3814. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3815. ->whereIn('category_id', $catid)
  3816. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3817. ->orderBy('pid')->get()->all();
  3818. if (!empty($category)) {
  3819. $result['category'] = $category;
  3820. }
  3821. $result['job'] = $job;
  3822. $result['job_experience'] = $job_experience ?? [];
  3823. $result['education_experience'] = $education_experience ?? [];
  3824. if (empty($result)) {
  3825. return Result::error("参数错误", 0);
  3826. }
  3827. return Result::success($result);
  3828. }
  3829. /**
  3830. * c端-申请职位
  3831. * @param array $data
  3832. * @return array
  3833. * */
  3834. public function getWebsiteJobApply(array $data): array
  3835. {
  3836. // 首先验证网站是否存在
  3837. // return Result::success($data);
  3838. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3839. if (empty($web)) {
  3840. return Result::error("该网站不存在", 0);
  3841. }
  3842. // 验证用户是否存在且为个人会员/管理员
  3843. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3844. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3845. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3846. return Result::error("用户不存在", 0);
  3847. }
  3848. // 去除重复元素和空元素,并保持原始顺序
  3849. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3850. return !empty($value);
  3851. }));
  3852. // 验证职位是否存在 1:审核通过
  3853. $recruiting = JobRecruiting::where('status', 1)
  3854. ->where('website_id', $data['website_id'])
  3855. ->whereIn('id', $data['recruit_id'])
  3856. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3857. if (empty($recruiting)) {
  3858. return Result::error("该职位不存在", 0);
  3859. }
  3860. // 简历是否存在
  3861. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3862. if (empty($hunt_id)) {
  3863. return Result::error("该简历不存在", 0);
  3864. }
  3865. $data['hunt_id'] = $hunt_id['hunt_id'];
  3866. // // 验证是否已投递过该职位
  3867. $apply = JobApply::where('user_id', $data['user_id'])
  3868. ->where('hunt_id', $data['hunt_id'])
  3869. ->where('website_id', $data['website_id'])
  3870. ->whereIn('recruit_id', $data['recruit_id'])
  3871. ->get(['recruit_id']);
  3872. if (!empty($apply->toArray())) {
  3873. return Result::error("您已投递过该职位!");
  3874. }
  3875. $insertData = array_map(function ($recruiting) use ($data) {
  3876. return [
  3877. 'user_id' => $data['user_id'],
  3878. 'hunt_id' => $data['hunt_id'],
  3879. 'website_id' => $data['website_id'],
  3880. 'recruit_id' => $recruiting['recruit_id'],
  3881. 'receiver_id' => $recruiting['receiver_id'],
  3882. 'status' => 1,
  3883. ];
  3884. }, $recruiting);
  3885. // 批量插入数据
  3886. $result = JobApply::insert($insertData);
  3887. if (empty($result)) {
  3888. return Result::error("投递失败", 0);
  3889. }
  3890. return Result::success($result);
  3891. }
  3892. /**
  3893. * 招工招聘-沟通简历
  3894. * @param array $data
  3895. * @return array
  3896. * */
  3897. public function getWebsiteJobResume(array $data): array
  3898. {
  3899. // 首先验证网站是否存在
  3900. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3901. if (empty($web)) {
  3902. return Result::error("该网站不存在", 0);
  3903. }
  3904. // return Result::success($data);
  3905. // 验证用户是否存在且为企业会员/管理员
  3906. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3907. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3908. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3909. return Result::error("用户不存在", 0);
  3910. }
  3911. // 去除重复元素和空元素,并保持原始顺序
  3912. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3913. return !empty($value);
  3914. }));
  3915. // 验证简历是否存在
  3916. $hunting = JobHunting::where('status', 2)
  3917. ->where('website_id', $data['website_id'])
  3918. ->whereIn('id', $data['hunt_id'])
  3919. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3920. if (empty($hunting)) {
  3921. return Result::error("该简历不存在", 0);
  3922. }
  3923. // 验证是否已沟通过该简历
  3924. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3925. ->where('recruit_id', $data['recruit_id'])
  3926. ->where('website_id', $data['website_id'])
  3927. ->whereIn('hunt_id', $data['hunt_id'])
  3928. ->get(['hunt_id']);
  3929. if (!empty($remuse->toArray())) {
  3930. return Result::error("您已沟通过该简历!");
  3931. }
  3932. // 准备要插入的数据数组
  3933. $insertData = array_map(function ($hunting) use ($data) {
  3934. return [
  3935. 'user_id' => $data['user_id'],
  3936. 'recruit_id' => $data['recruit_id'],
  3937. 'website_id' => $data['website_id'],
  3938. 'hunt_id' => $hunting['hunt_id'],
  3939. 'receiver_id' => $hunting['receiver_id'],
  3940. 'status' => 1,
  3941. ];
  3942. }, $hunting);
  3943. // 批量插入数据
  3944. $result = JobRemuse::insert($insertData);
  3945. if (empty($result)) {
  3946. return Result::error("沟通失败", 0);
  3947. }
  3948. return Result::success($result);
  3949. }
  3950. /**
  3951. * 招工招聘 -我的职位(企业会员)
  3952. * @param array $data
  3953. * @return array
  3954. */
  3955. public function getWebsiteJobRecruiting(array $data): array
  3956. {
  3957. $web = Website::where('id', $data['website_id'])->first('id');
  3958. if (empty($web)) {
  3959. return Result::error("该网站不存在", 0);
  3960. }
  3961. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3962. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3963. return Result::error("用户暂无权限!", 0);
  3964. }
  3965. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3966. $result = JobRecruiting::where('website_id', $data['website_id'])
  3967. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3968. $query->where('user_id', $user['id']);
  3969. })
  3970. ->where('status', 1)
  3971. ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
  3972. ->orderBy('updated_at', 'desc')
  3973. ->limit($data['pageSize'])
  3974. ->get();
  3975. if (empty($result)) {
  3976. return Result::error("暂无相关职位信息", 0);
  3977. }
  3978. return Result::success($result);
  3979. }
  3980. /**
  3981. * c端 - 验证路由
  3982. * @param array $data
  3983. * @return array
  3984. */
  3985. /**
  3986. * c端 - 验证路由
  3987. * @param array $data
  3988. * @return array
  3989. */
  3990. public function checkWebsiteRoute(array $data): array
  3991. {
  3992. // 测试001111111222
  3993. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3994. if (empty($web)) {
  3995. return Result::error("该网站不存在", 0);
  3996. } elseif ($web['status'] != 1) {
  3997. return Result::error("网站已经关闭", 0);
  3998. }
  3999. if (isset($data['other_route']) && !empty($data['other_route'])) {
  4000. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  4001. // 验证路由是否存在
  4002. if (empty($whiteRouterInfo)) {
  4003. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  4004. }
  4005. if (!empty($whiteRouterInfo)) {
  4006. return Result::success($whiteRouterInfo->toArray());
  4007. }
  4008. }
  4009. // 验证栏目路由
  4010. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  4011. ->where('path', $data['all_route'])
  4012. ->get()->all();
  4013. if (count($last_category) == 0) {
  4014. return Result::error("该栏目不存在", 0);
  4015. }
  4016. if (count($last_category) > 1) {
  4017. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  4018. }
  4019. if (count($last_category) == 1) {
  4020. $last_category = $last_category[0];
  4021. }
  4022. // return Result::success($last_category);
  4023. if (isset($data['id']) && !empty($data['id'])) {
  4024. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  4025. switch ($last_category['type']) {
  4026. case 1:
  4027. // 文章
  4028. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  4029. $article = Article::where('status', 1)
  4030. ->where('id', $data['id'])
  4031. ->where(function ($query) use ($data) {
  4032. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  4033. ->orWhereNull("ignore_ids");
  4034. })
  4035. ->first(['catid']);
  4036. if (empty($article)) {
  4037. return Result::error("该文章不存在", 0);
  4038. }
  4039. // return Result::success($article);
  4040. break;
  4041. case 2:
  4042. // 商品
  4043. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4044. $article = Good::where('website_id', $data['website_id'])
  4045. ->where('status', 2)
  4046. ->where('id', $data['id'])
  4047. ->first(['cat_arr_id']);
  4048. if (empty($article)) {
  4049. return Result::error("该商品不存在", 0);
  4050. }
  4051. break;
  4052. case 3:
  4053. // 书刊信息
  4054. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4055. $article = Book::where('website_id', $data['website_id'])
  4056. ->where('status', 2)
  4057. ->where('id', $data['id'])
  4058. ->first(['id', 'cat_arr_id']);
  4059. if (empty($article)) {
  4060. return Result::error("该书刊不存在", 0);
  4061. }
  4062. break;
  4063. case 4:
  4064. // 招聘
  4065. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  4066. $article = JobRecruiting::where('website_id', $data['website_id'])
  4067. ->where('status', 1)
  4068. ->where('id', $data['id'])
  4069. ->first(['cat_arr_id']);
  4070. if (empty($article)) {
  4071. return Result::error("该招聘不存在", 0);
  4072. }
  4073. break;
  4074. case 5:
  4075. // 求职
  4076. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4077. $article = JobHunting::where('website_id', $data['website_id'])
  4078. ->where('status', 2)
  4079. ->where('id', $data['id'])
  4080. ->first(['cat_arr_id']);
  4081. if (empty($article)) {
  4082. return Result::error("该求职不存在", 0);
  4083. }
  4084. break;
  4085. case 6:
  4086. // 企业
  4087. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4088. $article = Company::
  4089. // where('website_id', $data['website_id'])
  4090. // ->
  4091. where('status', 1)
  4092. ->where('id', $data['id'])
  4093. ->first(['cat_arr_id']);
  4094. if (empty($article)) {
  4095. return Result::error("该企业不存在", 0);
  4096. }
  4097. break;
  4098. case 7:
  4099. // 项目
  4100. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4101. $article = Project::where('website_id', $data['website_id'])
  4102. ->where('status', 1)
  4103. ->where('id', $data['id'])
  4104. ->first(['cat_arr_id']);
  4105. if (empty($article)) {
  4106. return Result::error("该项目不存在", 0);
  4107. }
  4108. break;
  4109. default:
  4110. return Result::error("该数据不存在", 0);
  4111. break;
  4112. }
  4113. // return Result::success($article);
  4114. // $catid =0 ;
  4115. if (!isset($article['cat_arr_id'])) {
  4116. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  4117. } else {
  4118. $catidArray = json_decode($article['cat_arr_id'], true);
  4119. $catid = !empty($catidArray) ? end($catidArray) : null;
  4120. }
  4121. // return Result::success($catid);
  4122. // // return Result::success($article['cat_arr_id']);
  4123. if (empty($catid)) {
  4124. return Result::error("该栏目路径不存在", 0);
  4125. }
  4126. $path = WebsiteCategory::where('website_id', $data['website_id'])
  4127. ->where('category_id', $catid)
  4128. ->first('path');
  4129. }
  4130. // else{
  4131. // // if ($last_category['pid'] != 0) {
  4132. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  4133. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  4134. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  4135. // ->where('category_id',$catid)
  4136. // ->where('path',$data['all_route'])
  4137. // ->first('path');
  4138. // // } else {
  4139. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  4140. // // }
  4141. // }
  4142. // return Result::success($path);
  4143. if (!empty($path) && $path['path'] != $data['all_route']) {
  4144. return Result::error('非法路径!');
  4145. } else {
  4146. return Result::success($last_category['path']);
  4147. }
  4148. }
  4149. /**
  4150. * 招工招聘 - 获取推荐职位
  4151. * @param array $data
  4152. * @return array
  4153. */
  4154. public function getWebsiteLevelJob(array $data): array
  4155. {
  4156. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  4157. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  4158. ->where('job_recruiting.status', 1)
  4159. ->where('job_level', $data['job_level'])
  4160. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4161. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  4162. ->orderBy('job_recruiting.updated_at', 'desc')
  4163. ->limit($data['pageSize'])
  4164. ->get();
  4165. $web = ['website_id' => $data['website_id']];
  4166. if (!empty($job)) {
  4167. $result = $this->processJob($job, $web);
  4168. }
  4169. if (empty($result)) {
  4170. return Result::error("暂无相关职位信息", 0);
  4171. }
  4172. return Result::success($result);
  4173. }
  4174. /**
  4175. * 验证导航名称是否重复
  4176. * @return void
  4177. */
  4178. //20250226 产品列表
  4179. public function getGoodList(array $data): array
  4180. {
  4181. var_dump($data, '---------1-2--');
  4182. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  4183. unset($data['user_type_id']);
  4184. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4185. $where = [];
  4186. if ($type_id != '10000') {
  4187. $where = [
  4188. 'good.user_id' => $user_id,
  4189. ];
  4190. }
  4191. //类型
  4192. if (isset($data['type_id']) && $data['type_id']) {
  4193. $where['good.type_id'] = $data['type_id'];
  4194. }
  4195. //名称
  4196. if (isset($data['name']) && $data['name']) {
  4197. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  4198. }
  4199. //status
  4200. if (isset($data['status']) && $data['status'] != '') {
  4201. $where['good.status'] = $data['status'];
  4202. }
  4203. //status1
  4204. // if (isset($data['status1']) && $data['status1'] == 1) {
  4205. // $status1 = 1;
  4206. // }
  4207. $where1 = [];
  4208. //website_id
  4209. // if (isset($data['website_id']) && $data['website_id']) {
  4210. // $where1 = [
  4211. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  4212. // ];
  4213. // }
  4214. // website_name
  4215. if (isset($data['website_name']) && $data['website_name']) {
  4216. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  4217. }
  4218. // catid
  4219. if (isset($data['category_name']) && $data['category_name']) {
  4220. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  4221. }
  4222. // $result = Good::where($where)
  4223. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  4224. var_dump($where, '---------1---');
  4225. $result = Good::where($where)
  4226. ->when(!empty($where1), function ($query) use ($where1) {
  4227. return $query->where($where1);
  4228. })
  4229. //status 1待审核2已审核3已拒绝
  4230. ->when(isset($data['status1']), function ($query) {
  4231. return $query->whereIn('good.status', [1, 3]);
  4232. })
  4233. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4234. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4235. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4236. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4237. ->orderBy("updated_at", "desc")
  4238. ->limit($data['page_size'])
  4239. ->offset(($data['page'] - 1) * $data['page_size'])
  4240. ->get();
  4241. $count = Good::where($where)
  4242. ->when(!empty($where1), function ($query) use ($where1) {
  4243. return $query->where($where1);
  4244. })
  4245. //status 1待审核2已审核3已拒绝
  4246. ->when(isset($data['status1']), function ($query) {
  4247. return $query->whereIn('good.status', [1, 3]);
  4248. })
  4249. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4250. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4251. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4252. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4253. ->orderBy("updated_at", "desc")->count();
  4254. $data = [
  4255. 'rows' => $result->toArray(),
  4256. 'count' => $count,
  4257. ];
  4258. if (empty($result)) {
  4259. return Result::error("此栏目暂无相关产品", 0);
  4260. }
  4261. return Result::success($data);
  4262. }
  4263. public function getGoodInfo(array $data): array
  4264. {
  4265. $result = Good::where('id', $data['id'])->first();
  4266. if (empty($result)) {
  4267. return Result::error("此产品不存在", 0);
  4268. }
  4269. return Result::success($result);
  4270. }
  4271. public function addGood(array $data): array
  4272. {
  4273. // unset($data['city_arr_id']);
  4274. // unset($data['cat_arr_id']);
  4275. $data['city_id'] = end($data['city_arr_id']);
  4276. $data['catid'] = end($data['cat_arr_id']);
  4277. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4278. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4279. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4280. unset($data['imgUrl']); //大小写
  4281. if (isset($data['price']) && $data['price'] == '') {
  4282. $data['price'] = 0;
  4283. }
  4284. if ($data['imgurl'] == '') {
  4285. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4286. preg_match_all($reg, $data['detail'], $matches);
  4287. if (isset($matches[1][0])) {
  4288. //截取varchar240
  4289. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4290. }
  4291. }
  4292. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4293. //提取标题+内容中的关键词
  4294. $data['keyword'] = $data['name'];
  4295. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4296. Jieba::init(); // 初始化 jieba-php
  4297. Finalseg::init();
  4298. $segList = Jieba::cut($data['keyword']);
  4299. $segList1 = array_slice($segList, 0, 8);
  4300. $data['keyword'] = implode(',', $segList1);
  4301. }
  4302. if ($data['description'] == '') {
  4303. //提取内容中的描述
  4304. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4305. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4306. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4307. }
  4308. if ($data['status'] == 1) {
  4309. $this->sendMessage([
  4310. 'talk_type' => 200,
  4311. 'title' => $data['name'],
  4312. 'content' => '提交了审核',
  4313. 'messageType' => 3,
  4314. ]);
  4315. }
  4316. $result = Good::insert($data);
  4317. if (empty($result)) {
  4318. return Result::error("添加失败", 0);
  4319. }
  4320. return Result::success($result);
  4321. }
  4322. public function updateGood(array $data): array
  4323. {
  4324. $data['city_id'] = end($data['city_arr_id']);
  4325. $data['catid'] = end($data['cat_arr_id']);
  4326. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4327. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4328. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4329. //设置东八区
  4330. date_default_timezone_set('Asia/Shanghai');
  4331. $data['updated_at'] = date('Y-m-d H:i:s');
  4332. if (isset($data['price']) && $data['price'] == '') {
  4333. $data['price'] = 0;
  4334. }
  4335. if ($data['imgurl'] == '') {
  4336. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4337. preg_match_all($reg, $data['detail'], $matches);
  4338. if (isset($matches[1][0])) {
  4339. //截取varchar240
  4340. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4341. }
  4342. }
  4343. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4344. //提取标题+内容中的关键词
  4345. $data['keyword'] = $data['name'];
  4346. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4347. Jieba::init(); // 初始化 jieba-php
  4348. Finalseg::init();
  4349. $segList = Jieba::cut($data['keyword']);
  4350. $segList1 = array_slice($segList, 0, 8);
  4351. $data['keyword'] = implode(',', $segList1);
  4352. }
  4353. if ($data['description'] == '') {
  4354. //提取内容中的描述
  4355. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4356. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4357. }
  4358. if ($data['status'] == 1) {
  4359. $this->sendMessage([
  4360. 'talk_type' => 200,
  4361. 'title' => $data['name'],
  4362. 'content' => '提交了审核',
  4363. 'messageType' => 3,
  4364. ]);
  4365. }
  4366. $result = Good::where('id', $data['id'])->update($data);
  4367. if (empty($result)) {
  4368. return Result::error("更新失败", 0);
  4369. }
  4370. return Result::success($result);
  4371. }
  4372. public function delGood(array $data): array
  4373. {
  4374. $result = Good::where('id', $data['id'])->delete();
  4375. if (empty($result)) {
  4376. return Result::error("删除失败", 0);
  4377. }
  4378. return Result::success($result);
  4379. }
  4380. //20250226 产品列表
  4381. //20250306 求职信息
  4382. public function getJobHuntingList(array $data): array
  4383. {
  4384. $where = [];
  4385. if (isset($data['username']) && !empty($data['username'])) {
  4386. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4387. }
  4388. //status 1待审核2已审核3已拒绝
  4389. if (isset($data['status']) && $data['status'] != '') {
  4390. $where = [
  4391. 'job_hunting.status' => $data['status'],
  4392. ];
  4393. }
  4394. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4395. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4396. unset($data['type_id']);
  4397. if ($type_id != '10000') {
  4398. $where[] = ['job_hunting.user_id', '=', $user_id];
  4399. }
  4400. $result = JobHunting::where($where)
  4401. ->when(!empty($data['status1']), function ($query) use ($data) {
  4402. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4403. })
  4404. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4405. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4406. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  4407. ->orderBy("updated_at", "desc")
  4408. ->limit($data['page_size'])
  4409. ->offset(($data['page'] - 1) * $data['page_size'])
  4410. ->get();
  4411. if (empty($result)) {
  4412. return Result::error("查询失败", 0);
  4413. }
  4414. $count = JobHunting::where($where)
  4415. ->when(!empty($data['status1']), function ($query) use ($data) {
  4416. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4417. })
  4418. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4419. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4420. ->count();
  4421. $data = [
  4422. 'rows' => $result->toArray(),
  4423. 'count' => $count,
  4424. ];
  4425. return Result::success($data);
  4426. }
  4427. public function getJobHuntingApply(array $data): array
  4428. {
  4429. var_dump($data, '-----------------test--------1-');
  4430. $where = [];
  4431. if (isset($data['username']) && !empty($data['username'])) {
  4432. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4433. }
  4434. if (isset($data['salary']) && !empty($data['salary'])) {
  4435. $where[] = [
  4436. 'job_hunting.salary',
  4437. '=',
  4438. $data['salary'],
  4439. ];
  4440. }
  4441. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4442. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4443. unset($data['type_id']);
  4444. if ($type_id != '10000') {
  4445. $where[] = ['job_apply.receiver_id', '=', $user_id];
  4446. }
  4447. var_dump($where, '-----------------test---------');
  4448. $result = jobApply::where($where)
  4449. // ->when(!empty($data['status1']), function ($query) use ($data) {
  4450. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4451. // })
  4452. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  4453. ->where('job_enum.egroup', '=', 'income')
  4454. ->where('job_hunting.status', 2) //已审核
  4455. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4456. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4457. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4458. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4459. //职位----是申请职位
  4460. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4461. ->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')
  4462. ->orderBy("job_hunting.updated_at", "desc")
  4463. ->limit($data['page_size'])
  4464. ->offset(($data['page'] - 1) * $data['page_size'])
  4465. ->get();
  4466. if (empty($result)) {
  4467. return Result::error("查询失败", 0);
  4468. }
  4469. $count = jobApply::where($where)
  4470. ->where('job_enum.egroup', '=', 'income')
  4471. ->where('job_hunting.status', 2) //已审核
  4472. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4473. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4474. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4475. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4476. //职位----是申请职位
  4477. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4478. ->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')
  4479. ->count();
  4480. $data = [
  4481. 'rows' => $result->toArray(),
  4482. 'count' => $count,
  4483. ];
  4484. return Result::success($data);
  4485. }
  4486. public function addJobHunting(array $data): array
  4487. {
  4488. date_default_timezone_set('Asia/Shanghai');
  4489. unset($data['company_name']);
  4490. unset($data['job_industry']);
  4491. unset($data['job_name']);
  4492. unset($data['department']);
  4493. unset($data['job_timeList']);
  4494. unset($data['job_content']);
  4495. unset($data['job_typename']); //不知道这是啥,
  4496. $data['created_at'] = date('Y-m-d H:i:s');
  4497. $data['updated_at'] = date('Y-m-d H:i:s');
  4498. //根据用户 user_id 只能添加一次
  4499. $result = JobHunting::where('user_id', $data['user_id'])->first();
  4500. if (!empty($result)) {
  4501. return Result::error("您已添加过求职信息", 0);
  4502. }
  4503. var_dump($result, '-----------------test---------');
  4504. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  4505. if (is_string($data['city_arr_id'])) {
  4506. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4507. $cityArr = json_decode($data['city_arr_id'], true);
  4508. // 确保 $cityArr 是数组
  4509. if (is_array($cityArr)) {
  4510. $data['city_id'] = end($cityArr);
  4511. }
  4512. } else {
  4513. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4514. if (is_array($data['city_arr_id'])) {
  4515. $data['city_id'] = end($data['city_arr_id']);
  4516. }
  4517. }
  4518. }
  4519. // 处理求职所绑定栏目
  4520. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4521. if (is_string($data['cat_arr_id'])) {
  4522. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4523. // 先清理可能存在的无效 JSON 字符
  4524. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4525. $catArr = json_decode($cleanedCatArrStr, true);
  4526. // 检查 JSON 解码是否成功且结果是数组
  4527. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4528. $data['catid'] = end($catArr);
  4529. }
  4530. } else {
  4531. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4532. if (is_array($data['cat_arr_id'])) {
  4533. $data['catid'] = end($data['cat_arr_id']);
  4534. }
  4535. }
  4536. }
  4537. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4538. $this->sendMessage([
  4539. 'talk_type' => 600,
  4540. 'title' => $data['name'],
  4541. 'content' => '提交了审核',
  4542. 'messageType' => 11,
  4543. ]);
  4544. }
  4545. $result = JobHunting::create($data);
  4546. if (empty($result)) {
  4547. return Result::error("添加失败", 0);
  4548. }
  4549. return Result::success($result);
  4550. }
  4551. public function delJobHunting(array $data): array
  4552. {
  4553. $result = JobHunting::where('id', $data['id'])->delete();
  4554. if (empty($result)) {
  4555. return Result::error("删除失败", 0);
  4556. }
  4557. return Result::success($result);
  4558. }
  4559. public function updateJobHunting(array $data): array
  4560. {
  4561. //设置东八区
  4562. date_default_timezone_set('Asia/Shanghai');
  4563. unset($data['company_name']);
  4564. unset($data['job_industry']);
  4565. unset($data['job_name']);
  4566. unset($data['department']);
  4567. unset($data['job_timeList']);
  4568. unset($data['job_content']);
  4569. unset($data['job_typename']); //不知道这是啥,
  4570. $data['created_at'] = date('Y-m-d H:i:s');
  4571. $data['updated_at'] = date('Y-m-d H:i:s');
  4572. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4573. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4574. $cityArr = json_decode($data['city_arr_id'], true);
  4575. $data['city_id'] = end($cityArr);
  4576. } else {
  4577. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4578. $data['city_id'] = end($data['city_arr_id']);
  4579. }
  4580. // 处理求职所绑定栏目
  4581. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4582. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4583. $catArr = json_decode($data['cat_arr_id'], true);
  4584. $data['catid'] = end($catArr);
  4585. } else {
  4586. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4587. $data['catid'] = end($data['cat_arr_id']);
  4588. }
  4589. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4590. $this->sendMessage([
  4591. 'talk_type' => 600,
  4592. 'title' => $data['name'],
  4593. 'content' => '提交了审核',
  4594. 'messageType' => 11,
  4595. ]);
  4596. }
  4597. $result = JobHunting::where('id', $data['id'])->update($data);
  4598. if (empty($result)) {
  4599. return Result::error("更新失败", 0);
  4600. }
  4601. return Result::success($result);
  4602. }
  4603. public function getJobHuntingInfo(array $data): array
  4604. {
  4605. $result = JobHunting::where('id', $data['id'])->first();
  4606. if (empty($result)) {
  4607. return Result::error("查询失败", 0);
  4608. }
  4609. return Result::success($result);
  4610. }
  4611. public function getJobHuntingData(array $data): array
  4612. {
  4613. $jobEnum = JobEnum::get();
  4614. $jobIndustry = JobIndustry::get();
  4615. $jobNature = JobNature::get();
  4616. $jobPosition = JobPosition::get();
  4617. $data = [
  4618. 'jobEnum' => $jobEnum,
  4619. 'jobIndustry' => $jobIndustry,
  4620. 'jobNature' => $jobNature,
  4621. 'jobPosition' => $jobPosition,
  4622. ];
  4623. return Result::success($data);
  4624. }
  4625. public function delJobHuntingInfo(array $data): array
  4626. {
  4627. $result = JobHunting::where('id', $data['id'])->delete();
  4628. return Result::success();
  4629. }
  4630. //20250324 通知,公告,消息
  4631. public function delNotice(array $data): array
  4632. {
  4633. $result = Notice::where('id', $data['id'])->delete();
  4634. if ($result) {
  4635. return Result::success();
  4636. } else {
  4637. return Result::error("删除失败", 0);
  4638. }
  4639. }
  4640. public function getNoticeInfo(array $data): array
  4641. {
  4642. $result = Notice::where('id', $data['id'])->first();
  4643. // var_dump($result['re_user_ids'], '--------------------');
  4644. if (empty($result)) {
  4645. return Result::error("查询失败", 0);
  4646. }
  4647. return Result::success($result);
  4648. }
  4649. public function readNotice(array $data): array
  4650. {
  4651. $result = Notice::where('id', $data['id'])->first();
  4652. // var_dump($result['re_user_ids'], '--------------------');
  4653. if (empty($result)) {
  4654. return Result::error("查询失败", 0);
  4655. }
  4656. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4657. $re_user_ids = json_decode($result['re_user_ids'], true);
  4658. var_dump($re_user_ids, '--------------1---test---------');
  4659. var_dump($data, '--------------1---test---------');
  4660. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4661. //如果已经存在,就不再添加
  4662. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4663. $read_id = json_decode($result['read_id'], true);
  4664. if (!is_array($read_id)) {
  4665. $read_id = [];
  4666. }
  4667. if (!in_array($data['user_id'], $read_id)) {
  4668. $read_id[] = $data['user_id'];
  4669. $result['read_id'] = json_encode($read_id);
  4670. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4671. }
  4672. } else {
  4673. //如果不存在,就添加
  4674. $result['read_id'] = json_encode([$data['user_id']]);
  4675. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4676. }
  4677. }
  4678. return Result::success($result);
  4679. }
  4680. public function addNotice(array $data): array
  4681. {
  4682. date_default_timezone_set('Asia/Shanghai');
  4683. $data['created_at'] = date('Y-m-d H:i:s');
  4684. $data['updated_at'] = date('Y-m-d H:i:s');
  4685. // $data['level'] = "1,2,3,4,5";
  4686. $level = json_decode($data['level'], true);
  4687. $user_id = UserInfo::
  4688. //city_id不是null
  4689. whereNotNull('city_id')
  4690. ->whereNotNull('department_id')
  4691. ->where(function ($query) use ($data) {
  4692. $query->where(function ($subQuery) use ($data) {
  4693. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4694. });
  4695. })
  4696. ->where(function ($query) use ($data) {
  4697. $query->where(function ($subQuery) use ($data) {
  4698. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4699. });
  4700. })
  4701. ->when(isset($level) && is_array($level), function ($query) use ($level) {
  4702. $query->whereIn('level', $level);
  4703. })
  4704. ->pluck('user_id')->toArray();
  4705. $user_id = array_unique($user_id);
  4706. $chat_ids = $user_id;
  4707. $user_id = json_encode($user_id);
  4708. $data['re_user_ids'] = $user_id;
  4709. $this->sendMessage([
  4710. 'talk_type' => 700,
  4711. 'title' => $data['title'],
  4712. 'content' => '提交了审核',
  4713. 'messageType' => 5,
  4714. ]);
  4715. $result = Notice::insertGetId($data);
  4716. if (empty($result)) {
  4717. return Result::error("添加失败", 0);
  4718. }
  4719. return Result::success($result);
  4720. }
  4721. public function updateNotice(array $data): array
  4722. {
  4723. date_default_timezone_set('Asia/Shanghai');
  4724. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4725. $user_id = UserInfo::
  4726. //city_id不是null
  4727. whereNotNull('city_id')
  4728. ->whereNotNull('department_id')
  4729. ->where(function ($query) use ($data) {
  4730. $query->where(function ($subQuery) use ($data) {
  4731. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4732. });
  4733. })
  4734. ->where(function ($query) use ($data) {
  4735. $query->where(function ($subQuery) use ($data) {
  4736. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4737. });
  4738. })
  4739. ->pluck('user_id')->toArray();
  4740. $user_id = array_unique($user_id);
  4741. $user_id = json_encode($user_id);
  4742. $data['re_user_ids'] = $user_id;
  4743. $data['updated_at'] = date('Y-m-d H:i:s');
  4744. $this->sendMessage([
  4745. 'talk_type' => 700,
  4746. 'title' => $data['title'],
  4747. 'content' => '提交了审核',
  4748. 'messageType' => 5,
  4749. ]);
  4750. $result = Notice::where('id', $data['id'])->update($data);
  4751. return Result::success($result);
  4752. }
  4753. public function getNoticeList(array $data): array
  4754. {
  4755. $where = [];
  4756. //title
  4757. if (isset($data['title']) && !empty($data['title'])) {
  4758. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4759. }
  4760. //level
  4761. if (isset($data['level']) && !empty($data['level'])) {
  4762. $where[] = ['notice.level', '=', $data['level']];
  4763. }
  4764. //status
  4765. if (isset($data['status']) && !empty($data['status'])) {
  4766. $where[] = ['notice.status', '=', $data['status']];
  4767. }
  4768. //type
  4769. if (isset($data['type']) && !empty($data['type'])) {
  4770. $where[] = ['notice.type', '=', $data['type']];
  4771. }
  4772. var_dump($data, '------------11111-2----test---------');
  4773. if ($data['type_id'] == 10000) {
  4774. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4775. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4776. })
  4777. ->where($where)
  4778. ->orderBy('updated_at', 'desc')
  4779. ->limit($data['page_size'])
  4780. ->offset(($data['page'] - 1) * $data['page_size'])
  4781. ->get();
  4782. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4783. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4784. })
  4785. ->where($where)
  4786. ->orderBy('updated_at', 'desc')
  4787. ->count();
  4788. } else {
  4789. $result = Notice::where($where)
  4790. // ->where('user_id', $data['user_id'])
  4791. ->Where(function ($query) use ($data) {
  4792. $query->Where(function ($q) use ($data) {
  4793. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4794. ->orWhere('notice.user_id', $data['user_id']);
  4795. });
  4796. })
  4797. ->when(!empty($data['status1']), function ($query) use ($data) {
  4798. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4799. })
  4800. ->orderBy('updated_at', 'desc')
  4801. ->limit($data['page_size'])
  4802. ->offset(($data['page'] - 1) * $data['page_size'])
  4803. ->get();
  4804. $total = Notice::where($where)
  4805. ->when(!empty($data['status1']), function ($query) use ($data) {
  4806. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4807. })
  4808. // ->where('user_id', $data['user_id'])
  4809. ->Where(function ($query) use ($data) {
  4810. $query->Where(function ($q) use ($data) {
  4811. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4812. ->orWhere('notice.user_id', $data['user_id']);
  4813. });
  4814. })
  4815. ->count();
  4816. }
  4817. if (empty($result)) {
  4818. return Result::error("查询失败", 0);
  4819. }
  4820. $data = [
  4821. 'rows' => $result,
  4822. 'count' => $total,
  4823. ];
  4824. return Result::success($data);
  4825. }
  4826. public function noticeList(array $data): array
  4827. {
  4828. $where = [];
  4829. //title
  4830. if (isset($data['title']) && !empty($data['title'])) {
  4831. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4832. }
  4833. //level
  4834. if (isset($data['level']) && !empty($data['level'])) {
  4835. $where[] = ['notice.level', '=', $data['level']];
  4836. }
  4837. //status
  4838. if (isset($data['status']) && !empty($data['status'])) {
  4839. $where[] = ['notice.status', '=', $data['status']];
  4840. }
  4841. //type
  4842. if (isset($data['type']) && !empty($data['type'])) {
  4843. $where[] = ['notice.type', '=', $data['type']];
  4844. }
  4845. var_dump($data, '------------11111-2----test---------');
  4846. if ($data['type_id'] == 10000) {
  4847. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4848. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4849. })
  4850. ->where($where)
  4851. ->orderBy('updated_at', 'desc')
  4852. ->limit($data['page_size'])
  4853. ->offset(($data['page'] - 1) * $data['page_size'])
  4854. ->get();
  4855. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4856. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4857. })
  4858. ->where($where)
  4859. ->orderBy('updated_at', 'desc')
  4860. ->count();
  4861. } else {
  4862. $result = Notice::where($where)
  4863. // ->where('user_id', $data['user_id'])
  4864. ->Where(function ($query) use ($data) {
  4865. $query->Where(function ($q) use ($data) {
  4866. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4867. ->orWhere('notice.user_id', $data['user_id']);
  4868. });
  4869. })
  4870. ->when(!empty($data['status1']), function ($query) use ($data) {
  4871. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4872. })
  4873. ->orderBy('updated_at', 'desc')
  4874. ->limit($data['page_size'])
  4875. ->offset(($data['page'] - 1) * $data['page_size'])
  4876. ->get();
  4877. $total = Notice::where($where)
  4878. ->when(!empty($data['status1']), function ($query) use ($data) {
  4879. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4880. })
  4881. // ->where('user_id', $data['user_id'])
  4882. ->Where(function ($query) use ($data) {
  4883. $query->Where(function ($q) use ($data) {
  4884. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4885. ->orWhere('notice.user_id', $data['user_id']);
  4886. });
  4887. })
  4888. ->count();
  4889. }
  4890. if (empty($result)) {
  4891. return Result::error("查询失败", 0);
  4892. }
  4893. $data = [
  4894. 'rows' => $result,
  4895. 'count' => $total,
  4896. ];
  4897. return Result::success($data);
  4898. }
  4899. public function getNoticeDetail(array $data): array
  4900. {
  4901. $result = Notice::where('id', $data['id'])->first();
  4902. if (empty($result)) {
  4903. return Result::error("查询失败", 0);
  4904. }
  4905. return Result::success($result);
  4906. }
  4907. public function deleteNotice(array $data): array
  4908. {
  4909. $notice = Notice::where('id', $data['id'])->first();
  4910. if (empty($notice)) {
  4911. return Result::error("删除失败", 0);
  4912. }
  4913. $chat_group_id = $notice->group_id;
  4914. if ($chat_group_id) {
  4915. //删除群聊
  4916. ChatGroups::where('id', $chat_group_id)->delete();
  4917. //删除群成员
  4918. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4919. //删除群聊记录
  4920. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4921. }
  4922. $result = Notice::where('id', $data['id'])->delete();
  4923. return Result::success($result);
  4924. }
  4925. public function complaintList(array $data): array
  4926. {
  4927. var_dump($data, '---------1---------');
  4928. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4929. unset($data['type_id']);
  4930. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4931. $where = [];
  4932. if ($type_id != 10000 && empty($data['deal_user'])) {
  4933. // $where['complaint.user_id'] = $user_id;
  4934. }
  4935. if (!empty($data['title'])) {
  4936. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4937. }
  4938. if (!empty($data['department_id'])) {
  4939. $where['complaint.department_id'] = $data['department_id'];
  4940. }
  4941. if (!empty($data['deal'])) {
  4942. $where['complaint.deal'] = $data['deal'];
  4943. }
  4944. if (!empty($data['status'])) {
  4945. $where['complaint.status'] = $data['status'];
  4946. }
  4947. var_dump(!empty($data['deal_user']), '----------1');
  4948. var_dump($where, '----------2');
  4949. $result = Complaint::where($where)
  4950. ->when(!empty($data['status1']), function ($query) use ($data) {
  4951. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4952. })
  4953. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4954. //json re_user_ids data[user_id]是不是在里面
  4955. $query->Where(function ($q) use ($data) {
  4956. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4957. ->where('complaint.status', 2);
  4958. });
  4959. })
  4960. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4961. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4962. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4963. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4964. ->orderBy('updated_at', 'desc')
  4965. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4966. //sql输出
  4967. if (empty($result)) {
  4968. return Result::error("暂无投诉信息", 0);
  4969. }
  4970. // 取出数据
  4971. $rows = $result->items();
  4972. $count = $result->total();
  4973. $responseData = [
  4974. 'rows' => $rows,
  4975. 'count' => $count,
  4976. ];
  4977. return Result::success($responseData);
  4978. }
  4979. public function getComplaintList(array $data): array
  4980. {
  4981. var_dump($data, '00000001000000000000');
  4982. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4983. unset($data['type_id']);
  4984. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4985. $where = [];
  4986. if ($type_id != 10000 && empty($data['deal_user'])) {
  4987. $where['complaint.user_id'] = $user_id;
  4988. }
  4989. if (!empty($data['title'])) {
  4990. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4991. }
  4992. if (!empty($data['department_id'])) {
  4993. $where['complaint.department_id'] = $data['department_id'];
  4994. }
  4995. if (!empty($data['deal'])) {
  4996. $where['complaint.deal'] = $data['deal'];
  4997. }
  4998. if (!empty($data['status'])) {
  4999. $where['complaint.status'] = $data['status'];
  5000. }
  5001. var_dump(!empty($data['deal_user']), '----------1');
  5002. var_dump($where, '----------2');
  5003. $result = Complaint::where($where)
  5004. ->when(!empty($data['status1']), function ($query) use ($data) {
  5005. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  5006. })
  5007. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  5008. // //json re_user_ids data[user_id]是不是在里面
  5009. // $query->Where(function ($q) use ($data) {
  5010. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  5011. // ->where('complaint.status', 2);
  5012. // });
  5013. // })
  5014. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  5015. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  5016. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  5017. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  5018. ->orderBy('updated_at', 'desc')
  5019. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5020. //sql输出
  5021. if (empty($result)) {
  5022. return Result::error("暂无投诉信息", 0);
  5023. }
  5024. // 取出数据
  5025. $rows = $result->items();
  5026. $count = $result->total();
  5027. $responseData = [
  5028. 'rows' => $rows,
  5029. 'count' => $count,
  5030. ];
  5031. return Result::success($responseData);
  5032. }
  5033. public function getComplaintInfo(array $data): array
  5034. {
  5035. $result = Complaint::where('id', $data['id'])->first();
  5036. if (empty($result)) {
  5037. return Result::error("查询失败", 0);
  5038. }
  5039. return Result::success($result);
  5040. }
  5041. public function readComplaint(array $data): array
  5042. {
  5043. $result = Complaint::where('id', $data['id'])->first();
  5044. if (empty($result)) {
  5045. return Result::error("查询失败", 0);
  5046. }
  5047. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  5048. $re_user_ids = json_decode($result['re_user_ids'], true);
  5049. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  5050. //如果已经存在,就不再添加
  5051. if (isset($result['read_id']) && !empty($result['read_id'])) {
  5052. $read_id = json_decode($result['read_id'], true);
  5053. if (!is_array($read_id)) {
  5054. $read_id = [];
  5055. }
  5056. if (!in_array($data['user_id'], $read_id)) {
  5057. $read_id[] = $data['user_id'];
  5058. $result['read_id'] = json_encode($read_id);
  5059. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  5060. }
  5061. } else {
  5062. //如果不存在,就添加
  5063. $result['read_id'] = json_encode([$data['user_id']]);
  5064. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  5065. }
  5066. }
  5067. return Result::success($result);
  5068. }
  5069. public function addComplaint(array $data): array
  5070. {
  5071. date_default_timezone_set('Asia/Shanghai');
  5072. $data['created_at'] = date('Y-m-d H:i:s');
  5073. $data['updated_at'] = date('Y-m-d H:i:s');
  5074. $this->sendMessage([
  5075. 'talk_type' => 800,
  5076. 'title' => $data['title'],
  5077. 'content' => '提交了审核',
  5078. 'messageType' => 6,
  5079. ]);
  5080. $result = Complaint::create($data);
  5081. return Result::success($result);
  5082. }
  5083. public function updateComplaint(array $data): array
  5084. {
  5085. date_default_timezone_set('Asia/Shanghai');
  5086. $data['updated_at'] = date('Y-m-d H:i:s');
  5087. $user_id = $data['user_id'] ?? 0;
  5088. $type_id = $data['type_id'] ?? 0;
  5089. unset($data['user_id']);
  5090. unset($data['type_id']);
  5091. $this->sendMessage([
  5092. 'talk_type' => 800,
  5093. 'title' => $data['title'],
  5094. 'content' => '提交了审核',
  5095. 'messageType' => 6,
  5096. ]);
  5097. $result = Complaint::where('id', $data['id'])->update($data);
  5098. return Result::success($result);
  5099. }
  5100. public function deleteComplaint(array $data): array
  5101. {
  5102. $result = Complaint::where('id', $data['id'])->delete();
  5103. return Result::success($result);
  5104. }
  5105. public function getComplainInfo(array $data): array
  5106. {
  5107. $result = Complaint::where('id', $data['id'])->first();
  5108. if (empty($result)) {
  5109. return Result::error("查询失败", 0);
  5110. }
  5111. return Result::success($result);
  5112. }
  5113. public function updateComplaintStatus(array $data): array
  5114. {
  5115. date_default_timezone_set('Asia/Shanghai');
  5116. $data['updated_at'] = date('Y-m-d H:i:s');
  5117. $user_id = $data['user_id'] ?? 0;
  5118. $type_id = $data['type_id'] ?? 0;
  5119. unset($data['user_id']);
  5120. unset($data['type_id']);
  5121. //处理, 写入处理人
  5122. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  5123. $data['real_deal_user'] = $user_id;
  5124. }
  5125. //如果是deal 23,则判断是不是处理人
  5126. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  5127. $complaintInof = Complaint::where('id', $data['id'])
  5128. ->where('real_deal_user', $user_id)
  5129. ->first();
  5130. if (empty($complaintInof)) {
  5131. return Result::error("处理人错误", 0);
  5132. }
  5133. }
  5134. $complaintInfo = Complaint::where('id', $data['id'])->first();
  5135. if ($data['status'] == 1) {
  5136. $this->sendMessage([
  5137. 'talk_type' => 800,
  5138. 'title' => $complaintInfo['title'],
  5139. 'content' => '提交了审核',
  5140. 'messageType' => 6,
  5141. ]);
  5142. }
  5143. if ($data['status'] == 2 && !isset($data['deal'])) {
  5144. $this->sendMessage([
  5145. 'talk_type' => 801,
  5146. 'title' => $complaintInfo['title'],
  5147. 'content' => '审核通过',
  5148. 'messageType' => 6,
  5149. 'user_id' => $complaintInfo['user_id'],
  5150. ]);
  5151. $this->sendMessage([
  5152. 'talk_type' => 802,
  5153. 'title' => $complaintInfo['title'],
  5154. 'content' => '待处理',
  5155. 'messageType' => 6,
  5156. 'user_id' => $complaintInfo['re_user_ids'],
  5157. ]);
  5158. }
  5159. if ($data['status'] == 3 && !isset($data['deal'])) {
  5160. $this->sendMessage([
  5161. 'talk_type' => 801,
  5162. 'title' => $complaintInfo['title'],
  5163. 'content' => '审核拒绝',
  5164. 'messageType' => 6,
  5165. 'user_id' => $complaintInfo['user_id'],
  5166. ]);
  5167. }
  5168. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  5169. $this->sendMessage([
  5170. 'talk_type' => 802,
  5171. 'title' => $complaintInfo['title'],
  5172. 'content' => '处理中',
  5173. 'messageType' => 6,
  5174. 'user_id' => $complaintInfo['re_user_ids'],
  5175. ]);
  5176. }
  5177. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  5178. $this->sendMessage([
  5179. 'talk_type' => 802,
  5180. 'title' => $complaintInfo['title'],
  5181. 'content' => '不予处理',
  5182. 'messageType' => 6,
  5183. 'user_id' => $complaintInfo['re_user_ids'],
  5184. ]);
  5185. }
  5186. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  5187. $this->sendMessage([
  5188. 'talk_type' => 802,
  5189. 'title' => $complaintInfo['title'],
  5190. 'content' => '已完结',
  5191. 'messageType' => 6,
  5192. 'user_id' => $complaintInfo['re_user_ids'],
  5193. ]);
  5194. }
  5195. $result = complaint::where('id', $data['id'])->update($data);
  5196. return Result::success($result);
  5197. }
  5198. public function updateGoodStatus(array $data): array
  5199. {
  5200. $user_id = $data['user_id'] ?? 0;
  5201. $type_id = $data['type_id'] ?? 0;
  5202. unset($data['user_id']);
  5203. unset($data['type_id']);
  5204. $goodInfo = Good::where('id', $data['id'])->first();
  5205. if ($data['status'] == 2) {
  5206. $this->sendMessage([
  5207. 'talk_type' => 201,
  5208. 'title' => $goodInfo['name'],
  5209. 'content' => '审核通过',
  5210. 'messageType' => 3,
  5211. 'user_id' => $goodInfo['user_id'],
  5212. ]);
  5213. }
  5214. if ($data['status'] == 3) {
  5215. $this->sendMessage([
  5216. 'talk_type' => 201,
  5217. 'title' => $goodInfo['name'],
  5218. 'content' => '审核拒绝',
  5219. 'messageType' => 3,
  5220. 'user_id' => $goodInfo['user_id'],
  5221. ]);
  5222. }
  5223. if ($data['status'] == 1) {
  5224. $this->sendMessage([
  5225. 'talk_type' => 200,
  5226. 'title' => $goodInfo['name'],
  5227. 'content' => '提交了审核',
  5228. 'messageType' => 3,
  5229. ]);
  5230. }
  5231. $result = Good::where('id', $data['id'])->update($data);
  5232. return Result::success($result);
  5233. }
  5234. public function updateJobHuntingStatus(array $data): array
  5235. {
  5236. $user_id = $data['user_id'] ?? 0;
  5237. $type_id = $data['type_id'] ?? 0;
  5238. unset($data['user_id']);
  5239. unset($data['type_id']);
  5240. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  5241. if ($data['status'] == 2) {
  5242. $this->sendMessage([
  5243. 'talk_type' => 601,
  5244. 'title' => $jogHuntingInfo['name'],
  5245. 'content' => '审核通过',
  5246. 'messageType' => 11,
  5247. 'user_id' => $jogHuntingInfo['user_id'],
  5248. ]);
  5249. }
  5250. if ($data['status'] == 3) {
  5251. $this->sendMessage([
  5252. 'talk_type' => 601,
  5253. 'title' => $jogHuntingInfo['name'],
  5254. 'content' => '审核拒绝',
  5255. 'messageType' => 11,
  5256. 'user_id' => $jogHuntingInfo['user_id'],
  5257. ]);
  5258. }
  5259. if ($data['status'] == 1) {
  5260. $this->sendMessage([
  5261. 'talk_type' => 600,
  5262. 'title' => $jogHuntingInfo['name'],
  5263. 'content' => '提交了审核',
  5264. 'messageType' => 11,
  5265. ]);
  5266. }
  5267. $result = JobHunting::where('id', $data['id'])->update($data);
  5268. return Result::success($result);
  5269. }
  5270. public function updateNoticeStatus(array $data): array
  5271. {
  5272. $user_id = $data['user_id'] ?? 0;
  5273. $type_id = $data['type_id'] ?? 0;
  5274. unset($data['user_id']);
  5275. unset($data['type_id']);
  5276. //查询公告
  5277. $notice = Notice::where('id', $data['id'])->first();
  5278. if (empty($notice)) {
  5279. return Result::error("公告不存在", 0);
  5280. }
  5281. //$chat_ids 去除掉$data['user_id']
  5282. $chat_ids = json_decode($notice['re_user_ids'], true);
  5283. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  5284. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  5285. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  5286. //chat_group
  5287. $group_id = PublicData::uuid();
  5288. $groupData = [
  5289. 'id' => $group_id,
  5290. 'creator_id' => $notice['user_id'],
  5291. 'group_name' => $notice['group_name'] ?? '',
  5292. 'profile' => $notice['profile'] ?? 0,
  5293. ];
  5294. var_dump($groupData, '-----------------groupData-------');
  5295. $groupResult = ChatGroups::insertGetId($groupData);
  5296. var_dump($groupResult, '-----------------groupid-------');
  5297. $groupMemberData = [
  5298. 'id' => PublicData::uuid(),
  5299. 'user_id' => $notice['user_id'],
  5300. 'group_id' => $group_id,
  5301. 'leader' => 2,
  5302. ];
  5303. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  5304. //插入群成员表
  5305. $groupMemberDataUser = [];
  5306. $chatData = [];
  5307. foreach ($chat_ids as $key => $value) {
  5308. $groupMemberDataUser[] = [
  5309. 'id' => PublicData::uuid(),
  5310. 'user_id' => $value,
  5311. 'group_id' => $group_id,
  5312. 'leader' => 1,
  5313. ];
  5314. $chatData[] = [
  5315. 'user_id' => $value,
  5316. 'msg_type' => 1,
  5317. 'receiver_id' => $group_id,
  5318. 'content' => '通过通知创建群聊',
  5319. 'group_receiver_id' => $notice['user_id'],
  5320. 'action' => 'recieved',
  5321. 'created_at' => date('Y-m-d H:i:s'),
  5322. ];
  5323. }
  5324. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  5325. ChatGroupsMember::insert($groupMemberDataUser);
  5326. //插入一条管理员聊天记录
  5327. $chatData[] = [
  5328. 'user_id' => $notice['user_id'],
  5329. 'msg_type' => 1,
  5330. 'receiver_id' => $group_id,
  5331. 'content' => '通过通知创建群聊',
  5332. 'group_receiver_id' => $notice['user_id'],
  5333. 'action' => 'said',
  5334. 'created_at' => date('Y-m-d H:i:s'),
  5335. ];
  5336. var_dump($chatData, '-----------------chatData-------');
  5337. $chatResult = ChatRecords::insert($chatData);
  5338. //处理imp
  5339. $group = [
  5340. 'type' => 1,
  5341. 'name' => $notice['group_name'] ?? '',
  5342. 'profile' => '',
  5343. 'avatar' => '',
  5344. 'creator_id' => $notice['user_id'],
  5345. ];
  5346. $groupResult = GroupImp::insertGetId($group);
  5347. var_dump($groupResult, '获取imp group_id');
  5348. $groupMember = [
  5349. 'user_id' => $notice['user_id'],
  5350. 'group_id' => $groupResult,
  5351. 'leader' => 1,
  5352. 'join_time' => Date('Y-m-d H:i:s')
  5353. ];
  5354. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  5355. $talk_session = [
  5356. 'user_id' => $notice['user_id'],
  5357. 'to_from_id' => $groupResult,
  5358. 'talk_mode' => 2,
  5359. 'created_at' => Date('Y-m-d H:i:s'),
  5360. 'updated_at' => Date('Y-m-d H:i:s'),
  5361. ];
  5362. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  5363. //被通知人员处理
  5364. foreach ($chat_ids as $key => $value) {
  5365. $groupMemberdata[] = [
  5366. 'user_id' => $value,
  5367. 'group_id' => $groupResult,
  5368. 'leader' => 3,
  5369. 'join_time' => Date('Y-m-d H:i:s')
  5370. ];
  5371. $talk_sessionData[] = [
  5372. 'user_id' => $value,
  5373. 'to_from_id' => $groupResult,
  5374. 'talk_mode' => 2,
  5375. 'created_at' => Date('Y-m-d H:i:s'),
  5376. 'updated_at' => Date('Y-m-d H:i:s'),
  5377. ];
  5378. }
  5379. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  5380. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  5381. $group_id = $groupResult;
  5382. //更新result的 group_id
  5383. $data['group_id'] = $group_id;
  5384. Notice::where(['id' => $data['id']])->update($data);
  5385. }
  5386. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  5387. //删除掉信息
  5388. GroupImp::where('id', $notice['group_id'])->delete();
  5389. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  5390. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  5391. foreach ($chat_ids as $key => $value) {
  5392. }
  5393. //聊天记录删除
  5394. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  5395. $data['group_id'] = null;
  5396. Notice::where(['id' => $data['id']])->update($data);
  5397. }
  5398. $result = Notice::where('id', $data['id'])->update($data);
  5399. $noticeInfo = Notice::where('id', $data['id'])->first();
  5400. if ($data['status'] == 2) {
  5401. $this->sendMessage([
  5402. 'talk_type' => 701,
  5403. 'title' => $noticeInfo['title'],
  5404. 'content' => '审核通过',
  5405. 'messageType' => 3,
  5406. 'user_id' => $noticeInfo['user_id'],
  5407. ]);
  5408. }
  5409. if ($data['status'] == 3) {
  5410. $this->sendMessage([
  5411. 'talk_type' => 701,
  5412. 'title' => $noticeInfo['title'],
  5413. 'content' => '审核拒绝',
  5414. 'messageType' => 3,
  5415. 'user_id' => $noticeInfo['user_id'],
  5416. ]);
  5417. }
  5418. if ($data['status'] == 1) {
  5419. $this->sendMessage([
  5420. 'talk_type' => 700,
  5421. 'title' => $noticeInfo['title'],
  5422. 'content' => '提交了审核',
  5423. 'messageType' => 3,
  5424. ]);
  5425. }
  5426. return Result::success($result);
  5427. }
  5428. public function getDUser(array $data): array
  5429. {
  5430. if (!empty($data['ids'])) {
  5431. $user = User::whereIn('id', $data['ids'])->getall();
  5432. if (empty($user)) {
  5433. return Result::error('无数据', 0);
  5434. }
  5435. return Result::success($user);
  5436. }
  5437. $where = [];
  5438. if (!empty($data['department_id'])) {
  5439. $where['department_id'] = $data['department_id'];
  5440. }
  5441. if (!empty($data['city_id'])) {
  5442. $where['city_id'] = $data['city_id'];
  5443. }
  5444. $result = User::where('type_id', 2)
  5445. ->where('status', 1)
  5446. ->where($where)
  5447. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  5448. ->get();
  5449. if (empty($result)) {
  5450. return Result::error("查询失败", 0);
  5451. }
  5452. return Result::success($result);
  5453. }
  5454. /**
  5455. * 验证导航名称是否重复
  5456. * @return void
  5457. */
  5458. public function checkCategoryName(array $data): array
  5459. {
  5460. $result = Category::when($data, function ($query) use ($data) {
  5461. if (isset($data['name']) && $data['name']) {
  5462. $query->where("name", $data['name']);
  5463. }
  5464. if (isset($data['id']) && $data['id']) {
  5465. $query->where("id", "!=", $data['id']);
  5466. }
  5467. })->first();
  5468. if ($result) {
  5469. return Result::error("已存在");
  5470. } else {
  5471. return Result::success();
  5472. }
  5473. }
  5474. //20250226 产品列表
  5475. // 20250306 -------招聘--------fr
  5476. /*
  5477. * 招聘列表
  5478. * */
  5479. public function getJobRecruitingList(array $data): array
  5480. {
  5481. $where = [];
  5482. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  5483. if ($data['checkout'] == 0) {
  5484. $job_status = [0, 2];
  5485. } else {
  5486. $job_status = [1];
  5487. }
  5488. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5489. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  5490. }
  5491. $user = User::where('id', $data['user_id'])->first();
  5492. if (empty($user)) {
  5493. return Result::error("用户不存在", 0);
  5494. }
  5495. // 3:企业会员
  5496. if ($user['type_id'] == 3) {
  5497. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  5498. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  5499. }
  5500. // 如果 $where 为空,则不添加 where 条件
  5501. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5502. return $query->where($where);
  5503. })
  5504. ->whereIn('job_recruiting.status', $job_status)
  5505. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5506. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  5507. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  5508. ->orderBy("updated_at", "desc")
  5509. ->offset(($data['page'] - 1) * $data['page_size'])
  5510. ->limit($data['page_size'])
  5511. ->get()
  5512. ->all();
  5513. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5514. return $query->where($where);
  5515. })
  5516. ->whereIn('job_recruiting.status', $job_status)
  5517. ->count();
  5518. if (empty($result)) {
  5519. return Result::error("暂无招聘信息", 0);
  5520. }
  5521. return Result::success($result);
  5522. }
  5523. /*
  5524. * 招聘信息添加
  5525. * */
  5526. public function addJobRecruiting(array $data): array
  5527. {
  5528. // var_dump('添加招聘进入news------data',$data);
  5529. // return Result::success($data);
  5530. $user = User::where('user.id', $data['user_id'])
  5531. ->where('user.status', 1)
  5532. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5533. ->select(
  5534. 'user.type_id',
  5535. 'user.mobile',
  5536. 'user.email',
  5537. 'user_info.business_name',
  5538. 'user_info.company_hy_id',
  5539. 'user_info.company_nature',
  5540. 'user_info.company_size',
  5541. 'user_info.introduction',
  5542. 'user_info.real_name',
  5543. 'user_info.company_url',
  5544. 'user_info.address_arr_id',
  5545. 'user_info.address'
  5546. )
  5547. ->first();
  5548. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5549. return Result::error("用户不存在", 0);
  5550. }
  5551. $web = Website::where('id', $data['website_id'])->first();
  5552. if (empty($web)) {
  5553. return Result::error("网站不存在", 0);
  5554. }
  5555. // var_dump('添加招聘进入news---user---user',$user);
  5556. // 处理招聘关键词
  5557. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5558. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5559. } else {
  5560. Jieba::init(); // 初始化 jieba-php
  5561. Finalseg::init();
  5562. $segList = Jieba::cut($data['title']);
  5563. $segList1 = array_slice($segList, 0, 8);
  5564. $data['keyword'] = implode(',', $segList1);
  5565. }
  5566. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5567. $content = $data['description'];
  5568. // 去除 <style> 和 <script> 标签及其内容
  5569. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5570. // 去除所有 HTML 标签
  5571. $content = strip_tags($content);
  5572. // 去除 HTML 实体
  5573. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5574. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5575. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5576. // 去除多余空白
  5577. $content = preg_replace('/\s+/u', '', $content);
  5578. // 截取 100 个字符
  5579. $data['seo_description'] = mb_substr($content, 0, 100);
  5580. }
  5581. // return Result::success($user);
  5582. $data['action_id'] = $data['user_id'] ?? null;
  5583. $data['user_type'] = $user['type_id'] ?? null;
  5584. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5585. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5586. $data['catid'] = end($data['cat_arr_id']);
  5587. } else {
  5588. $data['catid'] = 0;
  5589. }
  5590. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5591. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5592. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5593. // 公司地址 管理员必填
  5594. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5595. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5596. // 管理员-企业相关信息
  5597. $company = [
  5598. // 'user_id' => $data['user_id']?? null,
  5599. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5600. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5601. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5602. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5603. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5604. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5605. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5606. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5607. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5608. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5609. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5610. ];
  5611. //去掉相关企业信息
  5612. $job = array_diff_key($data, array_flip(array_keys($company)));
  5613. // var_dump('添加招聘进入news---job---user',$job);
  5614. Db::beginTransaction();
  5615. try {
  5616. // // 先添加职位相关信息
  5617. if ($user['type_id'] == 10000) {
  5618. $job['status'] = 1;
  5619. }
  5620. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5621. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5622. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5623. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5624. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5625. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5626. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5627. // return Result::success($job);
  5628. $jobId = JobRecruiting::insertGetId($job);
  5629. if (empty($jobId)) {
  5630. Db::rollBack();
  5631. return Result::error("添加失败");
  5632. }
  5633. // 添加公司信息
  5634. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5635. $company['job_id'] = $jobId;
  5636. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5637. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5638. if ($user['type_id'] == 10000) {
  5639. // 管理员添加企业信息
  5640. $companyId = JobCompany::insertGetId($company);
  5641. if (empty($companyId)) {
  5642. Db::rollBack();
  5643. return Result::error("添加失败");
  5644. }
  5645. } else {
  5646. // 企业会员添加企业信息
  5647. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5648. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5649. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5650. $company['job_id'] = $jobId;
  5651. $companyId = JobCompany::insertGetId($company);
  5652. if (empty($companyId)) {
  5653. Db::rollBack();
  5654. return Result::error("添加失败");
  5655. }
  5656. }
  5657. Db::commit();
  5658. $result = [
  5659. 'job_id' => $jobId,
  5660. 'company_id' => $companyId,
  5661. ];
  5662. return Result::success($result);
  5663. } catch (\Exception $e) {
  5664. Db::rollBack();
  5665. return Result::error($e->getMessage(), 0);
  5666. }
  5667. // return Result::success($result);
  5668. }
  5669. /*
  5670. * 获取招聘信息详情
  5671. * */
  5672. public function getJobRecruitingInfo(array $data): array
  5673. {
  5674. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5675. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5676. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5677. ->select(
  5678. 'job_recruiting.*',
  5679. 'website.website_name as website_name',
  5680. 'job_company.business_name',
  5681. 'job_company.company_hy_id',
  5682. 'job_company.company_size',
  5683. 'job_company.company_nature',
  5684. 'job_company.introduction',
  5685. 'job_company.real_name',
  5686. 'job_company.mobile',
  5687. 'job_company.company_url',
  5688. 'job_company.address_arr_id',
  5689. 'job_company.address',
  5690. 'job_company.email'
  5691. )
  5692. ->first();
  5693. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5694. if (!empty($cityId)) {
  5695. if (isset($cityId[1]) && $cityId[1] != null) {
  5696. $city = District::where('id', $cityId[1])->first(['name']);
  5697. } else {
  5698. $city = District::where('id', $cityId[0])->first(['name']);
  5699. }
  5700. $result['city'] = $city['name'] ?? '';
  5701. }
  5702. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5703. if (is_array($addressId) && !empty($addressId)) {
  5704. $address = District::whereIn('id', $addressId)
  5705. ->orderBy('level', 'asc')
  5706. ->get(['name'])
  5707. ->pluck('name')
  5708. ->implode('');
  5709. // $job->address_name = $address ?? '';
  5710. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5711. }
  5712. if (empty($result)) {
  5713. return Result::error("招聘信息不存在", 0);
  5714. }
  5715. // return Result::success($job);
  5716. return Result::success($result);
  5717. }
  5718. /*
  5719. * 修改招聘信息
  5720. * */
  5721. public function upJobRecruiting(array $data): array
  5722. {
  5723. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5724. // return Result::success($job);
  5725. if (empty($job)) {
  5726. return Result::error("招聘信息不存在", 0);
  5727. }
  5728. $user = User::where('id', $data['user_id'])->first();
  5729. // return Result::success($user);
  5730. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5731. return Result::error("用户不存在", 0);
  5732. }
  5733. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5734. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5735. }
  5736. // 处理招聘关键词
  5737. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5738. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5739. } else {
  5740. Jieba::init(); // 初始化 jieba-php
  5741. Finalseg::init();
  5742. $segList = Jieba::cut($data['title']);
  5743. $segList1 = array_slice($segList, 0, 8);
  5744. $data['keyword'] = implode(',', $segList1);
  5745. }
  5746. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5747. $content = $data['description'];
  5748. // 去除 <style> 和 <script> 标签及其内容
  5749. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5750. // 去除所有 HTML 标签
  5751. $content = strip_tags($content);
  5752. // 去除 HTML 实体
  5753. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5754. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5755. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5756. // 去除多余空白
  5757. $content = preg_replace('/\s+/u', '', $content);
  5758. // 截取 100 个字符
  5759. $data['seo_description'] = mb_substr($content, 0, 100);
  5760. }
  5761. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5762. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5763. $data['catid'] = end($data['cat_arr_id']);
  5764. } else {
  5765. }
  5766. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5767. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5768. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5769. // 公司地址 管理员必填
  5770. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5771. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5772. // 管理员-企业相关信息
  5773. $company = [
  5774. // 'user_id' => $data['user_id']?? null,
  5775. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5776. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5777. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5778. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5779. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5780. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5781. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5782. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5783. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5784. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5785. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5786. ];
  5787. //去掉相关企业信息
  5788. $data = array_diff_key($data, array_flip(array_keys($company)));
  5789. $jobId = $data['id'];
  5790. $web = $data['website_id'];
  5791. $data['action_id'] = $data['user_id'];
  5792. unset($data['user_id']);
  5793. unset($data['user_type']);
  5794. unset($data['id']);
  5795. unset($data['website_id']);
  5796. // return Result::success($data);
  5797. Db::beginTransaction();
  5798. try {
  5799. // 管理员修改招聘信息
  5800. if ($user['type_id'] == 10000) {
  5801. $data['website_id'] = $web;
  5802. $company['website_id'] = $data['website_id'];
  5803. $data['status'] = 1;
  5804. } else {
  5805. $data['status'] = 0;
  5806. }
  5807. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5808. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5809. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5810. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5811. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5812. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5813. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5814. // return Result::success($job);
  5815. // Db::rollBack();
  5816. // return Result::success($company);
  5817. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5818. $this->sendMessage([
  5819. 'talk_type' => 500,
  5820. 'title' => $data['title'],
  5821. 'content' => '提交了审核',
  5822. 'messageType' => 10,
  5823. ]);
  5824. }
  5825. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5826. if (empty($result['job'])) {
  5827. Db::rollBack();
  5828. return Result::error("修改招聘信息失败");
  5829. }
  5830. // 管理员修改企业相关信息
  5831. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5832. if (empty($result['company'])) {
  5833. Db::rollBack();
  5834. return Result::error("修改企业相关信息失败");
  5835. }
  5836. Db::commit();
  5837. // return Result::success($result);
  5838. } catch (\Exception $e) {
  5839. Db::rollBack();
  5840. return Result::error($e->getMessage(), 0);
  5841. }
  5842. return Result::success($result);
  5843. }
  5844. /*
  5845. * 招聘信息删除
  5846. * */
  5847. public function delJobRecruiting(array $data): array
  5848. {
  5849. $user = User::where('id', $data['user_id'])->first();
  5850. if (empty($user)) {
  5851. return Result::error("用户不存在", 0);
  5852. }
  5853. $job = JobRecruiting::where('id', $data['id'])->first();
  5854. if (empty($job)) {
  5855. return Result::error("招聘信息不存在", 0);
  5856. }
  5857. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5858. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5859. }
  5860. Db::beginTransaction();
  5861. try {
  5862. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5863. if (empty($result['job'])) {
  5864. Db::rollBack();
  5865. return Result::error("删除招聘信息失败");
  5866. }
  5867. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5868. if (empty($result['company'])) {
  5869. Db::rollBack();
  5870. return Result::error("删除企业相关信息失败");
  5871. }
  5872. Db::commit();
  5873. } catch (\Exception $e) {
  5874. Db::rollBack();
  5875. return Result::error($e->getMessage(), 0);
  5876. }
  5877. return Result::success($result);
  5878. }
  5879. /*
  5880. * 获取公司信息
  5881. * */
  5882. public function getJobCompany(array $data): array
  5883. {
  5884. $user = User::where('user.id', $data['user_id'])
  5885. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5886. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5887. ->first();
  5888. // return Result::success($user);
  5889. if (empty($user)) {
  5890. return Result::error("用户不存在", 0);
  5891. }
  5892. if ($user['type_id'] == 3) {
  5893. $result = [
  5894. // 'id' => 0,
  5895. 'user_id' => $data['user_id'],
  5896. 'website_id' => $data['website_id'],
  5897. 'business_name' => $user['business_name'], // 企业名称
  5898. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5899. 'company_nature' => $user['company_nature'], // 公司性质
  5900. 'company_size' => $user['company_size'], // 公司规模
  5901. 'introduction' => $user['introduction'], // 公司简介
  5902. 'real_name' => $user['real_name'], // 企业联系人
  5903. 'mobile' => $user['mobile'], // 企业联系电话
  5904. 'company_url' => $user['company_url'], // 企业网址
  5905. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5906. 'address' => $user['address'], // 企业地址
  5907. 'email' => $user['email'], // 企业邮箱
  5908. ];
  5909. } else {
  5910. return Result::error("用户类型错误", 0);
  5911. }
  5912. if (empty($result)) {
  5913. return Result::error("公司信息不存在", 0);
  5914. }
  5915. return Result::success($result);
  5916. }
  5917. /*
  5918. * 修改公司信息
  5919. * */
  5920. public function upJobCompany(array $data): array
  5921. {
  5922. // return Result::success($data);
  5923. $user = User::where('user.id', $data['user_id'])
  5924. ->where('user.status', 1)
  5925. ->select('user.user_name', 'user.type_id')
  5926. ->first();
  5927. if (empty($user)) {
  5928. return Result::error("用户不存在", 0);
  5929. }
  5930. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5931. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5932. $company = [
  5933. 'business_name' => $data['business_name'], // 企业名称
  5934. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5935. 'company_nature' => $data['company_nature'], // 公司性质
  5936. 'company_size' => $data['company_size'], // 公司规模
  5937. 'introduction' => $data['introduction'], // 公司简介
  5938. // 'real_name' => $data['real_name'], // 企业联系人
  5939. 'company_url' => $data['company_url'], // 企业网址
  5940. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5941. 'address' => $data['address'], // 企业详细地址
  5942. // 'email' => $data['email'], // 企业邮箱
  5943. ];
  5944. if ($user['type_id'] == 3) {
  5945. Db::beginTransaction();
  5946. try {
  5947. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5948. 'business_name' => $data['business_name'], // 企业名称
  5949. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5950. 'company_nature' => $data['company_nature'], // 公司性质
  5951. 'company_size' => $data['company_size'], // 公司规模
  5952. 'introduction' => $data['introduction'], // 公司简介
  5953. // 'real_name' => $data['real_name'], // 企业联系人
  5954. 'company_url' => $data['company_url'], // 企业网址
  5955. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5956. 'address' => $data['address'], // 企业详细地址
  5957. ]);
  5958. if (empty($result['userinfo'])) {
  5959. Db::rollBack();
  5960. return Result::error('修改企业会员信息失败!');
  5961. }
  5962. $result['user'] = User::where('id', $data['user_id'])->update([
  5963. 'email' => $data['email'], // 企业邮箱
  5964. ]);
  5965. if (empty($result['user'])) {
  5966. Db::rollBack();
  5967. return Result::error('修改个人中心信息失败!');
  5968. }
  5969. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5970. if (!empty($job_company)) {
  5971. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5972. if (empty($result['job_company'])) {
  5973. Db::rollBack();
  5974. return Result::error('修改企业会员信息失败!');
  5975. }
  5976. }
  5977. Db::commit();
  5978. return Result::success($result);
  5979. } catch (\Exception $e) {
  5980. Db::rollBack();
  5981. return Result::error($e->getMessage(), 0);
  5982. }
  5983. } else {
  5984. return Result::error("用户类型错误", 0);
  5985. }
  5986. }
  5987. /*
  5988. * 获取省-市
  5989. * */
  5990. public function getJobRecruitingArea(array $data): array
  5991. {
  5992. if (isset($data['pid']) && $data['pid'] != null) {
  5993. $result = District::where('pid', $data['pid'])->get()->all();
  5994. } else {
  5995. $result = District::where('level', 1)->get()->all();
  5996. }
  5997. if (empty($result)) {
  5998. return Result::error("暂无此省市", 0);
  5999. }
  6000. return Result::success($result);
  6001. }
  6002. /*
  6003. * 获取行业分类
  6004. * */
  6005. public function getIndustry(array $data): array
  6006. {
  6007. $result = JobIndustry::get()->all();
  6008. if (empty($result)) {
  6009. return Result::error("暂无行业分类", 0);
  6010. }
  6011. return Result::success($result);
  6012. }
  6013. /*
  6014. * 获取职位
  6015. * */
  6016. public function getPositionList(array $data): array
  6017. {
  6018. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  6019. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  6020. } else {
  6021. $result = JobPosition::where('zwpid', 0)->get()->all();
  6022. }
  6023. if (empty($result)) {
  6024. return Result::error("暂无此职位", 0);
  6025. }
  6026. return Result::success($result);
  6027. }
  6028. /*
  6029. * 获取工作性质-菜单
  6030. * */
  6031. public function getJobNature(array $data): array
  6032. {
  6033. $result = JobEnum::where('egroup', 'nature')->get()->all();
  6034. if (empty($result)) {
  6035. return Result::error("暂无工作性质", 0);
  6036. }
  6037. return Result::success($result);
  6038. }
  6039. /*
  6040. * 获取工作经验-菜单
  6041. * */
  6042. public function getExperience(array $data): array
  6043. {
  6044. $result = JobEnum::where('egroup', 'years')->get()->all();
  6045. if (empty($result)) {
  6046. return Result::error("暂无工作经验", 0);
  6047. }
  6048. return Result::success($result);
  6049. }
  6050. /*
  6051. * 获取学历-菜单
  6052. * */
  6053. public function getEducation(array $data): array
  6054. {
  6055. $result = JobEnum::where('egroup', 'education')->get()->all();
  6056. if (empty($result)) {
  6057. return Result::error("暂无学历", 0);
  6058. }
  6059. return Result::success($result);
  6060. }
  6061. /*
  6062. * 获取薪资-菜单
  6063. * */
  6064. public function getSalary(array $data): array
  6065. {
  6066. $result = JobEnum::where('egroup', 'income')->get()->all();
  6067. if (empty($result)) {
  6068. return Result::error("暂无薪资", 0);
  6069. }
  6070. return Result::success($result);
  6071. }
  6072. /*
  6073. * 获取语言-菜单
  6074. * */
  6075. public function getLanguage(array $data): array
  6076. {
  6077. $result = JobEnum::where('egroup', 'language')->get()->all();
  6078. if (empty($result)) {
  6079. return Result::error("暂无语言", 0);
  6080. }
  6081. return Result::success($result);
  6082. }
  6083. /*
  6084. * 获取掌握程度-菜单
  6085. * */
  6086. public function getLevel(array $data): array
  6087. {
  6088. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  6089. if (empty($result)) {
  6090. return Result::error("暂无工作性质", 0);
  6091. }
  6092. return Result::success($result);
  6093. }
  6094. // 公司信息
  6095. /*
  6096. * 获取公司性质-菜单
  6097. * */
  6098. public function getCompanyNature(array $data): array
  6099. {
  6100. $result = JobNature::get()->all();
  6101. if (empty($result)) {
  6102. return Result::error("暂无公司性质", 0);
  6103. }
  6104. return Result::success($result);
  6105. }
  6106. /*
  6107. * 获取公司规模-菜单
  6108. * */
  6109. public function getCompanySize(array $data): array
  6110. {
  6111. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  6112. if (empty($result)) {
  6113. return Result::error("暂无公司规模", 0);
  6114. }
  6115. return Result::success($result);
  6116. }
  6117. /*
  6118. * 招聘信息审核
  6119. * */
  6120. public function checkJobRecruiting(array $data): array
  6121. {
  6122. $user = User::where('id', $data['user_id'])->first();
  6123. if (empty($user)) {
  6124. return Result::error("用户不存在", 0);
  6125. }
  6126. $job = JobRecruiting::where('id', $data['id'])->first();
  6127. if (empty($job)) {
  6128. return Result::error("招聘信息不存在", 0);
  6129. }
  6130. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  6131. if ($user['type_id'] != 10000) {
  6132. return Result::error("用户暂无权限审核此招聘信息!", 0);
  6133. }
  6134. // 驳回原因
  6135. if ($data['status'] == 2) {
  6136. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  6137. }
  6138. $data['action_id'] = $data['user_id'];
  6139. unset($data['user_id']);
  6140. if ($data['status'] == 1) {
  6141. $this->sendMessage([
  6142. 'talk_type' => 501,
  6143. 'title' => $job['title'],
  6144. 'content' => '审核通过',
  6145. 'messageType' => 10,
  6146. 'user_id' => $job['user_id'],
  6147. ]);
  6148. }
  6149. if ($data['status'] == 2) {
  6150. $this->sendMessage([
  6151. 'talk_type' => 501,
  6152. 'title' => $job['title'],
  6153. 'content' => '审核拒绝',
  6154. 'messageType' => 10,
  6155. 'user_id' => $job['user_id'],
  6156. ]);
  6157. }
  6158. if ($data['status'] == 0) {
  6159. $this->sendMessage([
  6160. 'talk_type' => 500,
  6161. 'title' => $job['title'],
  6162. 'content' => '提交了审核',
  6163. 'messageType' => 10,
  6164. ]);
  6165. }
  6166. $result = JobRecruiting::where('id', $data['id'])->update($data);
  6167. if (empty($result)) {
  6168. return Result::error("审核失败", 0);
  6169. }
  6170. return Result::success($result);
  6171. }
  6172. public function myApplyList(array $data): array
  6173. {
  6174. var_dump($data, '------参数');
  6175. $user = User::where('id', $data['user_id'])->first();
  6176. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6177. return Result::error("用户不存在", 0);
  6178. }
  6179. // 1:个人会员 职场机会
  6180. if ($user['type_id'] == 1) {
  6181. $where['user_id'] = $user['id'];
  6182. }
  6183. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  6184. $query->where('user_id', $user['id']);
  6185. })
  6186. ->pluck('recruit_id');
  6187. $where = [];
  6188. if (isset($data['salary']) && $data['salary'] != null) {
  6189. $where['job_recruiting.salary'] = $data['salary'];
  6190. }
  6191. if (isset($data['experience']) && $data['experience'] != null) {
  6192. $where['job_recruiting.experience'] = $data['experience'];
  6193. }
  6194. if (isset($data['business_name']) && $data['business_name'] != null) {
  6195. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6196. }
  6197. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6198. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6199. ->where($where);
  6200. // ->count();
  6201. $count = $query->count();
  6202. $query = clone $query;
  6203. $job = $query
  6204. ->leftJoin('job_enum as income_enum', function ($join) {
  6205. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6206. ->where('income_enum.egroup', 'income');
  6207. })
  6208. ->leftJoin('job_enum as years_enum', function ($join) {
  6209. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6210. ->where('years_enum.egroup', 'years');
  6211. })
  6212. // ->where($where)
  6213. ->orderBy('job_recruiting.updated_at', 'desc')
  6214. ->select(
  6215. 'job_recruiting.id',
  6216. 'job_recruiting.title',
  6217. 'job_company.business_name',
  6218. 'income_enum.evalue as salary_evalue',
  6219. 'income_enum.ename as salary_ename',
  6220. 'years_enum.evalue as experience_evalue',
  6221. 'years_enum.ename as experience_ename',
  6222. 'job_recruiting.updated_at'
  6223. )
  6224. ->offset(($data['page'] - 1) * $data['pageSize'])
  6225. ->limit($data['pageSize'])
  6226. ->get()
  6227. ->all();
  6228. if (empty($job)) {
  6229. return Result::error("暂无招聘信息", 0);
  6230. }
  6231. $result = [
  6232. 'row' => $job,
  6233. 'count' => $count,
  6234. ];
  6235. return Result::success($result);
  6236. }
  6237. public function readJobApply(array $data): array
  6238. {
  6239. $result = JobApply::where('id', $data['id'])->first();
  6240. if (empty($result)) {
  6241. return Result::error("查询失败", 0);
  6242. }
  6243. $result = JobApply::where('id', $data['id'])->update([
  6244. 'status' => 2,
  6245. ]);
  6246. return Result::success($result);
  6247. }
  6248. /*
  6249. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  6250. * */
  6251. public function getRecruitingList(array $data): array
  6252. {
  6253. $user = User::where('id', $data['user_id'])->first();
  6254. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6255. return Result::error("用户不存在", 0);
  6256. }
  6257. // 1:个人会员 职场机会
  6258. if ($user['type_id'] == 1) {
  6259. $where['user_id'] = $user['id'];
  6260. }
  6261. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  6262. $query->where('receiver_id', $user['id']);
  6263. })
  6264. ->pluck('recruit_id');
  6265. // return Result::success($recruitingId);
  6266. $where = [];
  6267. if (isset($data['salary']) && $data['salary'] != null) {
  6268. $where['job_recruiting.salary'] = $data['salary'];
  6269. }
  6270. if (isset($data['experience']) && $data['experience'] != null) {
  6271. $where['job_recruiting.experience'] = $data['experience'];
  6272. }
  6273. if (isset($data['business_name']) && $data['business_name'] != null) {
  6274. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6275. }
  6276. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6277. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6278. ->where($where);
  6279. // ->count();
  6280. $count = $query->count();
  6281. $query = clone $query;
  6282. $job = $query
  6283. ->leftJoin('job_enum as income_enum', function ($join) {
  6284. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6285. ->where('income_enum.egroup', 'income');
  6286. })
  6287. ->leftJoin('job_enum as years_enum', function ($join) {
  6288. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6289. ->where('years_enum.egroup', 'years');
  6290. })
  6291. // ->where($where)
  6292. ->orderBy('job_recruiting.updated_at', 'desc')
  6293. ->select(
  6294. 'job_recruiting.id',
  6295. 'job_recruiting.title',
  6296. 'job_company.business_name',
  6297. 'income_enum.evalue as salary_evalue',
  6298. 'income_enum.ename as salary_ename',
  6299. 'years_enum.evalue as experience_evalue',
  6300. 'years_enum.ename as experience_ename',
  6301. 'job_recruiting.updated_at'
  6302. )
  6303. ->offset(($data['page'] - 1) * $data['pageSize'])
  6304. ->limit($data['pageSize'])
  6305. ->get()
  6306. ->all();
  6307. if (empty($job)) {
  6308. return Result::error("暂无招聘信息", 0);
  6309. }
  6310. $result = [
  6311. 'row' => $job,
  6312. 'count' => $count,
  6313. ];
  6314. return Result::success($result);
  6315. }
  6316. /*
  6317. * 获取企业会员-招聘信息列表
  6318. * */
  6319. public function getRecruitingInfo(array $data): array
  6320. {
  6321. $user = User::where('id', $data['user_id'])->first();
  6322. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6323. return Result::error("用户不存在", 0);
  6324. }
  6325. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  6326. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6327. ->select(
  6328. 'job_recruiting.*',
  6329. 'job_company.business_name',
  6330. 'job_company.company_hy_id',
  6331. 'job_company.company_size',
  6332. 'job_company.company_nature',
  6333. 'job_company.introduction',
  6334. 'job_company.real_name',
  6335. 'job_company.mobile',
  6336. 'job_company.company_url',
  6337. 'job_company.address_arr_id',
  6338. 'job_company.address',
  6339. 'job_company.email'
  6340. )
  6341. ->get();
  6342. if (empty($recruiting)) {
  6343. return Result::error("暂无招聘信息", 0);
  6344. }
  6345. return Result::success($recruiting);
  6346. }
  6347. /*
  6348. * 获取企业会员-我的沟通
  6349. * */
  6350. public function getJobResumeList(array $data): array
  6351. {
  6352. $user = User::where('id', $data['user_id'])->first();
  6353. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  6354. return Result::error("用户不存在", 0);
  6355. }
  6356. $where = [];
  6357. if (isset($data['salary']) && $data['salary'] != null) {
  6358. $where['job_hunting.salary'] = $data['salary'];
  6359. }
  6360. if (isset($data['user_name']) && $data['user_name'] != null) {
  6361. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  6362. }
  6363. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  6364. $query->where('job_resume.user_id', $user['id']);
  6365. })
  6366. ->when(!empty($where), function ($query) use ($where) {
  6367. $query->where($where);
  6368. })
  6369. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  6370. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  6371. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  6372. ->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');
  6373. $count = $job->count();
  6374. if ($count == 0) {
  6375. return Result::error("暂无沟通记录", 0);
  6376. }
  6377. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  6378. ->offset(($data['page'] - 1) * $data['pageSize'])
  6379. ->limit($data['pageSize'])
  6380. ->get();
  6381. if (empty($jobs)) {
  6382. return Result::error("暂无沟通记录", 0);
  6383. }
  6384. $result['row'] = $this->processJob($jobs, '');
  6385. $result['count'] = $count;
  6386. return Result::success($result);
  6387. }
  6388. public function readJobResume(array $data): array
  6389. {
  6390. $result = JobResume::where('id', $data['id'])->first();
  6391. if (empty($result)) {
  6392. return Result::error("查询失败", 0);
  6393. }
  6394. $result = JobResume::where('id', $data['id'])->update([
  6395. 'status' => 2,
  6396. ]);
  6397. return Result::success($result);
  6398. }
  6399. // 20250306 招聘
  6400. //20250422 书刊音像
  6401. public function addBook(array $data): array
  6402. {
  6403. $user_id = $data['user_id'] ?? 0;
  6404. $type_id = $data['type_id'] ?? 0;
  6405. // $website_id = $data['website_id'] ?? 0;
  6406. // unset($data['user_id']);
  6407. unset($data['type_id']);
  6408. // unset($data['website_id']);
  6409. //处理数组
  6410. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6411. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6412. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6413. if ($data['img_url'] == '') {
  6414. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6415. preg_match_all($reg, $data['detail'], $matches);
  6416. if (isset($matches[1][0])) {
  6417. //截取varchar240
  6418. $data['img_url'] = substr($matches[1][0], 0, 240);
  6419. }
  6420. }
  6421. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  6422. //提取标题+内容中的关键词
  6423. $data['keyword'] = $data['title'];
  6424. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6425. Jieba::init(); // 初始化 jieba-php
  6426. Finalseg::init();
  6427. $segList = Jieba::cut($data['keyword']);
  6428. $segList1 = array_slice($segList, 0, 8);
  6429. $data['keyword'] = implode(',', $segList1);
  6430. }
  6431. if ($data['description'] == '') {
  6432. //提取内容中的描述
  6433. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6434. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6435. }
  6436. var_dump($data, '--');
  6437. if ($data['status'] == 1) {
  6438. $this->sendMessage([
  6439. 'talk_type' => 400,
  6440. 'title' => $data['title'],
  6441. 'content' => '提交了审核',
  6442. 'messageType' => 7,
  6443. ]);
  6444. }
  6445. $result = Book::insertGetId($data);
  6446. if (empty($result)) {
  6447. return Result::error("添加失败", 0);
  6448. }
  6449. return Result::success($result);
  6450. }
  6451. public function getBookList(array $data): array
  6452. {
  6453. $where = [];
  6454. if (!empty($data["title"])) {
  6455. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  6456. }
  6457. if (!empty($data['website_name'])) {
  6458. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  6459. }
  6460. if (!empty($data['status'])) {
  6461. $where[] = ['book.status', '=', $data['status']];
  6462. }
  6463. $user_id = $data['user_id'];
  6464. $type_id = $data['type_id'];
  6465. // $type_id = 4;
  6466. var_dump($type_id, '------1--------');
  6467. if ($type_id != 10000) {
  6468. $where[] = ['book.user_id', '=', $user_id];
  6469. }
  6470. var_dump(!empty($data['status1']), '=-===1');
  6471. $result = Book::where($where)
  6472. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  6473. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  6474. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  6475. ->when(isset($data['status1']), function ($query) use ($data) {
  6476. $query->whereIn('book.status', [1, 3]);
  6477. })
  6478. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  6479. ->orderBy("updated_at", "desc")
  6480. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  6481. if (empty($result)) {
  6482. return Result::error("暂无数据", 0);
  6483. }
  6484. // 取出数据
  6485. $rows = $result->items();
  6486. $count = $result->total();
  6487. $responseData = [
  6488. 'rows' => $rows,
  6489. 'count' => $count,
  6490. ];
  6491. return Result::success($responseData);
  6492. }
  6493. public function deleteBook(array $data): array
  6494. {
  6495. $result = Book::where('id', $data['id'])->delete();
  6496. if (empty($result)) {
  6497. return Result::error("删除失败", 0);
  6498. }
  6499. return Result::success($result);
  6500. }
  6501. public function updateBook(array $data): array
  6502. {
  6503. // $user_id = $data['user_id'] ?? 0;
  6504. $type_id = $data['type_id'] ?? 0;
  6505. // $website_id = $data['website_id'] ?? 0;
  6506. unset($data['user_id']);
  6507. unset($data['type_id']);
  6508. // unset($data['website_id']);
  6509. //处理数组
  6510. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6511. if ($data['img_url'] == '') {
  6512. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6513. preg_match_all($reg, $data['detail'], $matches);
  6514. if (isset($matches[1][0])) {
  6515. //截取varchar240
  6516. $data['img_url'] = substr($matches[1][0], 0, 240);
  6517. }
  6518. }
  6519. if ($data['keyword'] == '') {
  6520. //提取标题+内容中的关键词
  6521. $data['keyword'] = $data['title'];
  6522. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6523. Jieba::init(); // 初始化 jieba-php
  6524. Finalseg::init();
  6525. $segList = Jieba::cut($data['keyword']);
  6526. $segList1 = array_slice($segList, 0, 8);
  6527. $data['keyword'] = implode(',', $segList1);
  6528. }
  6529. if ($data['description'] == '') {
  6530. //提取内容中的描述
  6531. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6532. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6533. }
  6534. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6535. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6536. if ($data['status'] == 1) {
  6537. $this->sendMessage([
  6538. 'talk_type' => 400,
  6539. 'title' => $data['title'],
  6540. 'content' => '提交了审核',
  6541. 'messageType' => 7,
  6542. ]);
  6543. }
  6544. $result = Book::where("id", $data["id"])->update($data);
  6545. if (empty($result)) {
  6546. return Result::error("更新失败", 0);
  6547. }
  6548. return Result::success($result);
  6549. }
  6550. public function getBookInfo(array $data): array
  6551. {
  6552. $result = Book::where("id", $data["id"])->first();
  6553. if (empty($result)) {
  6554. return Result::error("获取失败", 0);
  6555. }
  6556. return Result::success($result);
  6557. }
  6558. public function updateBookStatus(array $data): array
  6559. {
  6560. //审核
  6561. unset($data['user_id']);
  6562. $bookInfo = Book::where("id", $data["id"])->first();
  6563. var_dump($bookInfo, '----');
  6564. if ($data['status'] == 2) {
  6565. $this->sendMessage([
  6566. 'talk_type' => 401,
  6567. 'title' => $bookInfo['title'],
  6568. 'content' => '审核通过',
  6569. 'messageType' => 7,
  6570. 'user_id' => $bookInfo['user_id'],
  6571. ]);
  6572. }
  6573. if ($data['status'] == 3) {
  6574. $this->sendMessage([
  6575. 'talk_type' => 401,
  6576. 'title' => $bookInfo['title'],
  6577. 'content' => '审核拒绝',
  6578. 'messageType' => 7,
  6579. 'user_id' => $bookInfo['user_id'],
  6580. ]);
  6581. }
  6582. if ($data['status'] == 1) {
  6583. $this->sendMessage([
  6584. 'talk_type' => 400,
  6585. 'title' => $bookInfo['title'],
  6586. 'content' => '提交了审核',
  6587. 'messageType' => 7,
  6588. // 'user_id'=>$bookInfo['user_id'],
  6589. ]);
  6590. }
  6591. $result = Book::where("id", $data["id"])->update($data);
  6592. if (empty($result)) {
  6593. return Result::error("更新失败", 0);
  6594. }
  6595. return Result::success($result);
  6596. }
  6597. //20250422 书刊音像
  6598. /**
  6599. * 贴身宝贝
  6600. * @param array $data
  6601. * @return array
  6602. */
  6603. public function getWebsiteTsbb(array $data): array
  6604. {
  6605. $month = $data['month'] ?? date('m');
  6606. $day = $data['day'] ?? date('d');
  6607. // 使用缓存键
  6608. $cacheKey = "tsbb_data_{$month}_{$day}";
  6609. // 尝试从缓存获取数据
  6610. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6611. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6612. if ($cachedData = $cache->get($cacheKey)) {
  6613. return Result::success(unserialize($cachedData));
  6614. }
  6615. //查询老黄历
  6616. try {
  6617. $date = date('Y-m-d');
  6618. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6619. // 使用 curl 替代 file_get_contents
  6620. $ch = curl_init();
  6621. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6622. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6623. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6624. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6625. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6626. 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');
  6627. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6628. 'Accept: application/json',
  6629. 'Content-Type: application/json',
  6630. 'Referer: https://www.36jxs.com/'
  6631. ]);
  6632. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6633. curl_setopt($ch, CURLOPT_ENCODING, '');
  6634. $almanacResponse = curl_exec($ch);
  6635. var_dump("====:", $almanacResponse);
  6636. if (curl_errno($ch)) {
  6637. var_dump('Curl error:', curl_error($ch));
  6638. throw new \Exception('Curl error: ' . curl_error($ch));
  6639. }
  6640. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6641. curl_close($ch);
  6642. if ($almanacResponse === false) {
  6643. throw new \Exception('Failed to fetch almanac data');
  6644. }
  6645. $almanacData = json_decode($almanacResponse, true);
  6646. if (json_last_error() !== JSON_ERROR_NONE) {
  6647. throw new \Exception('Failed to parse almanac data');
  6648. }
  6649. $almanacInfo = $almanacData['data'] ?? [];
  6650. } catch (\Exception $e) {
  6651. var_dump('Exception:', $e->getMessage());
  6652. $almanacInfo = [];
  6653. }
  6654. // 获取历史上的今天数据
  6655. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6656. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6657. ->orderBy('year', 'asc')
  6658. ->select("title", "id", "year", DB::raw('1 as type'))
  6659. ->limit(16)
  6660. ->get();
  6661. // 获取节日数据 - 从今天开始获取未来4条
  6662. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6663. ->orderBy('showtime', 'asc')
  6664. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6665. ->limit(16)
  6666. ->get();
  6667. //说文解字
  6668. $chartacterList = Character::orderBy('updated_at', 'desc')
  6669. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6670. ->limit(6)
  6671. ->get();
  6672. //谜语沙龙
  6673. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6674. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6675. ->limit(4)
  6676. ->get();
  6677. //成语欣赏
  6678. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6679. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6680. ->limit(32)
  6681. ->get();
  6682. //名联赏析
  6683. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6684. ->select("id", "first", "second", DB::raw('6 as type'))
  6685. ->limit(6)
  6686. ->get();
  6687. // 获取分类文章数据
  6688. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6689. ->pluck('category_id')
  6690. ->toArray();
  6691. $articlesList = [];
  6692. foreach ($categoryIds as $catid) {
  6693. // 先查有图片的
  6694. $withImg = DB::table('article')
  6695. ->where('status', 1)
  6696. ->where('catid', $catid)
  6697. ->whereNotNull('imgurl')
  6698. ->where('imgurl', '!=', '')
  6699. ->orderBy('updated_at', 'desc')
  6700. ->limit(6)
  6701. ->get();
  6702. $count = $withImg->count();
  6703. if ($count < 6) {
  6704. // 不足6条再查无图片的补足
  6705. $withoutImg = DB::table('article')
  6706. ->where('status', 1)
  6707. ->where('catid', $catid)
  6708. ->where(function ($q) {
  6709. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6710. })
  6711. ->orderBy('updated_at', 'desc')
  6712. ->limit(6 - $count)
  6713. ->get();
  6714. $articles = $withImg->concat($withoutImg);
  6715. } else {
  6716. $articles = $withImg;
  6717. }
  6718. // 组装
  6719. $category = \App\Model\Category::find($catid);
  6720. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6721. $articlesList[] = [
  6722. 'category_name' => $category ? $category->name : '',
  6723. 'catid' => $catid,
  6724. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6725. 'type' => 100,
  6726. 'list' => $articles->map(function ($item) {
  6727. return [
  6728. 'id' => $item->id,
  6729. 'title' => $item->title,
  6730. 'imgurl' => $item->imgurl,
  6731. 'created_at' => $item->created_at
  6732. ];
  6733. })->values()
  6734. ];
  6735. }
  6736. $result = [
  6737. 'almanac' => $almanacInfo,
  6738. 'historyTodayList' => [
  6739. 'category_name' => '历史上的今天',
  6740. 'list' => $historyTodayList,
  6741. 'type' => 1
  6742. ],
  6743. 'festivalList' => [
  6744. 'category_name' => '节日预告',
  6745. 'list' => $festivalList,
  6746. 'type' => 2
  6747. ],
  6748. 'chartacterList' => [
  6749. 'category_name' => '说文解字',
  6750. 'list' => $chartacterList,
  6751. 'type' => 3
  6752. ],
  6753. 'coupletList' => [
  6754. 'category_name' => '名联赏析',
  6755. 'list' => $coupletList,
  6756. 'type' => 6
  6757. ],
  6758. 'riddletList' => [
  6759. 'category_name' => '谜语沙龙',
  6760. 'list' => $riddletList,
  6761. 'type' => 4
  6762. ],
  6763. 'idiomList' => [
  6764. 'category_name' => '成语欣赏',
  6765. 'list' => $idiomList,
  6766. 'type' => 5
  6767. ],
  6768. 'articlesList' => $articlesList
  6769. ];
  6770. // 缓存结果,设置1小时过期
  6771. $cache->set($cacheKey, serialize($result), 3600);
  6772. return Result::success($result);
  6773. }
  6774. /**
  6775. * 获取资讯列表
  6776. */
  6777. public function getWebsiteTsbbList(array $data): array
  6778. {
  6779. $page = $data['page'] ?? 1;
  6780. $pageSize = $data['pageSize'] ?? 10;
  6781. // 如果没有传入月份和日期,则使用今天的日期
  6782. $month = $data['month'] ?? date('m');
  6783. $day = $data['day'] ?? date('d');
  6784. $total = 0;
  6785. $result = [];
  6786. $data['type'] = intval($data['type']);
  6787. var_dump("接收参数:", $data);
  6788. switch ($data['type']) {
  6789. case 1:
  6790. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6791. // 当前月份之后的数据
  6792. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6793. // 或者当前月份且日期大于等于当前日期的数据
  6794. ->orWhere(function ($q) use ($month, $day) {
  6795. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6796. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6797. });
  6798. })
  6799. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6800. $total = $query->count();
  6801. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6802. ->offset(($page - 1) * $pageSize)
  6803. ->limit($pageSize)
  6804. ->get();
  6805. break;
  6806. case 2:
  6807. $query = Festival::where(function ($q) use ($month, $day) {
  6808. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6809. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6810. ->orWhere(function ($q) use ($month, $day) {
  6811. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6812. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6813. });
  6814. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6815. $total = $query->count();
  6816. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6817. ->offset(($page - 1) * $pageSize)
  6818. ->limit($pageSize)
  6819. ->get();
  6820. break;
  6821. case 3:
  6822. $query = Character::orderBy("updated_at", "desc");
  6823. $total = $query->count();
  6824. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6825. ->offset(($page - 1) * $pageSize)
  6826. ->limit($pageSize)
  6827. ->get();
  6828. break;
  6829. case 4:
  6830. $query = Riddle::orderBy("updated_at", "desc");
  6831. $total = $query->count();
  6832. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6833. ->offset(($page - 1) * $pageSize)
  6834. ->limit($pageSize)
  6835. ->get();
  6836. break;
  6837. case 5:
  6838. $query = Idiom::orderBy("updated_at", "desc");
  6839. $total = $query->count();
  6840. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6841. ->offset(($page - 1) * $pageSize)
  6842. ->limit($pageSize)
  6843. ->get();
  6844. break;
  6845. case 6:
  6846. $query = Couplet::orderBy("updated_at", "desc");
  6847. $total = $query->count();
  6848. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6849. ->offset(($page - 1) * $pageSize)
  6850. ->limit($pageSize)
  6851. ->get();
  6852. break;
  6853. default:
  6854. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6855. $total = $query->count();
  6856. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6857. ->offset(($page - 1) * $pageSize)
  6858. ->limit($pageSize)
  6859. ->get();
  6860. }
  6861. return Result::success([
  6862. 'list' => $result,
  6863. 'total' => $total,
  6864. 'page' => (int)$page,
  6865. 'pageSize' => (int)$pageSize,
  6866. 'month' => $month,
  6867. 'day' => $day
  6868. ]);
  6869. }
  6870. /**
  6871. * 1:历史上的今天
  6872. * 2:节日
  6873. * 3:文章
  6874. *
  6875. * 资讯详情信息
  6876. */
  6877. public function getWebsiteTsbbDetail(array $data): array
  6878. {
  6879. $data['type'] = intval($data['type']);
  6880. switch ($data['type']) {
  6881. case 1:
  6882. $result = HistoryToday::where("id", $data['id'])->first();
  6883. break;
  6884. case 2:
  6885. $result = Festival::where("id", $data['id'])->first();
  6886. break;
  6887. case 3:
  6888. $result = Character::where("id", $data['id'])->first();
  6889. break;
  6890. case 4:
  6891. $result = Riddle::where("id", $data['id'])->first();
  6892. break;
  6893. case 5:
  6894. $result = Idiom::where("id", $data['id'])->first();
  6895. break;
  6896. case 6:
  6897. $result = Couplet::where("id", $data['id'])->first();
  6898. break;
  6899. default:
  6900. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6901. break;
  6902. }
  6903. return Result::success($result);
  6904. }
  6905. /**
  6906. * 农网导航首页数据
  6907. */
  6908. public function getWebsiteNwHomeList(array $data): array
  6909. {
  6910. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6911. ->pluck('category_id')
  6912. ->toArray();
  6913. // 使用子查询优化
  6914. $articlesList = DB::table('article')
  6915. ->select([
  6916. 'article.id',
  6917. 'article.title',
  6918. 'article.imgurl',
  6919. 'article.created_at',
  6920. 'category.name as category_name',
  6921. 'category.id as category_id',
  6922. 'website_category.aLIas_pinyin as pinyin',
  6923. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6924. DB::raw('100 as type')
  6925. ])
  6926. ->join('category', 'article.catid', '=', 'category.id')
  6927. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6928. ->leftJoin('website_category as parent_wc', function ($join) {
  6929. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6930. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6931. })
  6932. ->where('website_category.website_id', $data['website_id'])
  6933. ->where('article.status', 1)
  6934. ->whereIn('category.id', $categoryIds)
  6935. ->orderBy('article.created_at', 'desc')
  6936. ->get()
  6937. ->groupBy('category_id')
  6938. ->map(function ($group) {
  6939. // 确保第一条数据有图片
  6940. $firstWithImage = $group->first(function ($item) {
  6941. return !empty($item->imgurl);
  6942. });
  6943. if ($firstWithImage) {
  6944. // 如果有带图片的文章,将其放在第一位
  6945. $group = $group->filter(function ($item) use ($firstWithImage) {
  6946. return $item->id !== $firstWithImage->id;
  6947. })->prepend($firstWithImage);
  6948. }
  6949. return [
  6950. 'category_name' => $group->first()->category_name,
  6951. 'catid' => $group->first()->category_id,
  6952. 'pinyin' => $group->first()->pinyin,
  6953. 'parent_pinyin' => $group->first()->parent_pinyin,
  6954. 'list' => $group->take(4)->map(function ($item) {
  6955. return [
  6956. 'id' => $item->id,
  6957. 'title' => $item->title,
  6958. ];
  6959. })->values()
  6960. ];
  6961. })
  6962. ->values()
  6963. ->toArray();
  6964. return Result::success($articlesList);
  6965. }
  6966. /**
  6967. * 企业管理
  6968. * @param array $data
  6969. * @return array
  6970. */
  6971. public function getCompanyList(array $data): array
  6972. {
  6973. // return Result::success($data);
  6974. $where = [];
  6975. $user = User::where('id', $data['user_id'])->first();
  6976. if (empty($user)) {
  6977. return Result::error('用户不存在!');
  6978. }
  6979. if ($user['type_id'] != 10000) {
  6980. $where['user_id'] = $data['user_id'];
  6981. }
  6982. if (isset($data['title']) && !empty($data['title'])) {
  6983. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6984. }
  6985. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6986. array_push($where, ['website.id', $data['website_id']]);
  6987. }
  6988. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6989. if ($data['ischeck'] == 1) {
  6990. if (isset($data['status']) && $data['status'] != '') {
  6991. array_push($where, ['company.status', $data['status']]);
  6992. $query = Company::where($where);
  6993. } else {
  6994. $query = Company::whereIn('company.status', [0, 2]);
  6995. }
  6996. } else {
  6997. $query = Company::where('company.status', 1);
  6998. }
  6999. }
  7000. $result = $query->where($where)
  7001. ->leftJoin('website_category', function ($query) {
  7002. $query->on('website_category.category_id', '=', 'company.category_id')
  7003. ->on('website_category.website_id', '=', 'company.website_id');
  7004. })
  7005. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  7006. ->select(
  7007. 'company.id',
  7008. 'company.title',
  7009. 'company.website_id',
  7010. 'company.category_id',
  7011. 'website.website_name',
  7012. 'website_category.alias as category_name',
  7013. 'company.status',
  7014. 'company.updated_at',
  7015. 'company.user_id'
  7016. )
  7017. ->orderBy('company.updated_at', 'desc')
  7018. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7019. if ($result->isEmpty()) {
  7020. return Result::error("暂无企业", 0);
  7021. }
  7022. return Result::success($result);
  7023. }
  7024. /**
  7025. * 添加企业
  7026. * @param array $data
  7027. * @return array
  7028. */
  7029. public function addCompany(array $data): array
  7030. {
  7031. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  7032. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  7033. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  7034. $data['cat_arr_id'] = json_encode($car_arr_id);
  7035. } else {
  7036. $data['cat_arr_id'] = '';
  7037. }
  7038. if ($data['imgurl'] == '') {
  7039. //content中提取图片第一个图,正则提取
  7040. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7041. preg_match_all($reg, $data['content'], $matches);
  7042. if (isset($matches[1][0])) {
  7043. //截取varchar240
  7044. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7045. }
  7046. }
  7047. if ($data['keyword'] == '') {
  7048. //提取标题+内容中的关键词
  7049. $data['keyword'] = $data['title'];
  7050. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7051. Jieba::init(); // 初始化 jieba-php
  7052. Finalseg::init();
  7053. $segList = Jieba::cut($data['keyword']);
  7054. $segList1 = array_slice($segList, 0, 8);
  7055. $data['keyword'] = implode(',', $segList1);
  7056. }
  7057. if ($data['introduce'] == '' || empty($data['introduce'])) {
  7058. //提取内容中的描述
  7059. $content = $data['content'];
  7060. // 去除 <style> 和 <script> 标签及其内容
  7061. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7062. // 去除所有 HTML 标签
  7063. $content = strip_tags($content);
  7064. // 去除 HTML 实体
  7065. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7066. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7067. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7068. // 去除多余空白
  7069. $content = preg_replace('/\s+/u', '', $content);
  7070. // 截取 100 个字符
  7071. $data['introduce'] = mb_substr($content, 0, 100);
  7072. }
  7073. $user = User::where('id', $data['user_id'])->first();
  7074. if (empty($user)) {
  7075. return Result::error('用户不存在!');
  7076. }
  7077. if ($user['type_id'] == 10000) {
  7078. $data['status'] = 1;
  7079. }
  7080. if (isset($data['level']) && $data['level'] != null) {
  7081. $data['level'] = intval($data['level']);
  7082. } else {
  7083. $data['level'] = null;
  7084. }
  7085. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7086. $this->sendMessage([
  7087. 'talk_type' => 900,
  7088. 'title' => $data['title'],
  7089. 'content' => '提交了审核',
  7090. 'messageType' => 8,
  7091. ]);
  7092. }
  7093. $result = Company::insertGetId($data);
  7094. if ($result) {
  7095. return Result::success($result);
  7096. } else {
  7097. return Result::error('添加失败');
  7098. }
  7099. }
  7100. /**
  7101. * 更新企业
  7102. * @param array $data
  7103. * @return array
  7104. */
  7105. public function upCompany(array $data): array
  7106. {
  7107. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  7108. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  7109. $data['cat_arr_id'] = json_encode($car_arr_id);
  7110. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  7111. } else {
  7112. $data['cat_arr_id'] = '';
  7113. }
  7114. if ($data['imgurl'] == '') {
  7115. //content中提取图片第一个图,正则提取
  7116. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7117. preg_match_all($reg, $data['content'], $matches);
  7118. if (isset($matches[1][0])) {
  7119. //截取varchar
  7120. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7121. }
  7122. }
  7123. if ($data['keyword'] == '') {
  7124. //提取标题+内容中的关键词
  7125. $data['keyword'] = $data['title'];
  7126. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7127. Jieba::init(); // 初始化 jieba-php
  7128. Finalseg::init();
  7129. $segList = Jieba::cut($data['keyword']);
  7130. $segList1 = array_slice($segList, 0, 8);
  7131. $data['keyword'] = implode(',', $segList1);
  7132. }
  7133. if ($data['introduce'] == '') {
  7134. //提取内容中的描述
  7135. $content = $data['content'];
  7136. // 去除 <style> 和 <script> 标签及其内容
  7137. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7138. // 去除所有 HTML 标签
  7139. $content = strip_tags($content);
  7140. // 去除 HTML 实体
  7141. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7142. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7143. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7144. // 去除多余空白
  7145. $content = preg_replace('/\s+/u', '', $content);
  7146. // 截取 100 个字符
  7147. $data['introduce'] = mb_substr($content, 0, 100);
  7148. }
  7149. if (isset($data['level']) && $data['level'] != null) {
  7150. $data['level'] = intval($data['level']);
  7151. } else {
  7152. $data['level'] = null;
  7153. }
  7154. $user = User::where('id', $data['user_id'])->first();
  7155. if (empty($user)) {
  7156. return Result::error('用户不存在!');
  7157. }
  7158. if ($user['type_id'] == 10000) {
  7159. $data['status'] = 1;
  7160. } else {
  7161. $data['status'] = 0;
  7162. }
  7163. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7164. $this->sendMessage([
  7165. 'talk_type' => 900,
  7166. 'title' => $data['title'],
  7167. 'content' => '提交了审核',
  7168. 'messageType' => 8,
  7169. ]);
  7170. }
  7171. $result = Company::where('id', $data['id'])->update($data);
  7172. if ($result) {
  7173. return Result::success($result);
  7174. } else {
  7175. return Result::error('修改失败');
  7176. }
  7177. }
  7178. /**
  7179. * 删除企业
  7180. * @param array $data
  7181. * @return array
  7182. */
  7183. public function delCompany(array $data): array
  7184. {
  7185. $result = Company::where('id', $data['id'])->delete();
  7186. if ($result) {
  7187. return Result::success($result);
  7188. } else {
  7189. return Result::error('删除失败');
  7190. }
  7191. }
  7192. /**
  7193. * 审核企业
  7194. * @param array $data
  7195. * @return array
  7196. */
  7197. public function checkCompany(array $data): array
  7198. {
  7199. $user = User::where('id', $data['user_id'])->first();
  7200. if (empty($user)) {
  7201. return Result::error('用户不存在!');
  7202. }
  7203. $company = Company::where('id', $data['id'])->first();
  7204. if (empty($company)) {
  7205. return Result::error('企业不存在!');
  7206. }
  7207. // 状态:0:未审核 1:已审核 2:已拒绝
  7208. if ($data['status'] == 2 || $data['status'] == '2') {
  7209. $this->sendMessage([
  7210. 'talk_type' => 901,
  7211. 'title' => $company['title'],
  7212. 'content' => '审核拒绝',
  7213. 'messageType' => 8,
  7214. 'user_id' => $company['user_id'],
  7215. ]);
  7216. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  7217. } else {
  7218. if ($data['status'] == 1) {
  7219. $this->sendMessage([
  7220. 'talk_type' => 901,
  7221. 'title' => $company['title'],
  7222. 'content' => '审核通过',
  7223. 'messageType' => 8,
  7224. 'user_id' => $company['user_id'],
  7225. ]);
  7226. } else if ($data['status'] == 0) {
  7227. $this->sendMessage([
  7228. 'talk_type' => 900,
  7229. 'title' => $company['title'],
  7230. 'content' => '提交了审核',
  7231. 'messageType' => 8,
  7232. ]);
  7233. }
  7234. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  7235. }
  7236. if (empty($result)) {
  7237. return Result::error('审核失败!');
  7238. } else {
  7239. return Result::success($result);
  7240. }
  7241. }
  7242. /**
  7243. * 获取企业信息
  7244. * @param array $data
  7245. * @return array
  7246. */
  7247. public function getCompanyInfo(array $data): array
  7248. {
  7249. $result = Company::where('id', $data['id'])->first();
  7250. $city_arr = json_decode($result['city_arr_id']);
  7251. $result['city_name'] = District::whereIn('id', $city_arr)
  7252. ->pluck('name')
  7253. ->implode('-');
  7254. if (empty($result)) {
  7255. return Result::error('企业不存在!');
  7256. } else {
  7257. return Result::success($result);
  7258. }
  7259. }
  7260. /**
  7261. * @param array $data
  7262. * @return array
  7263. */
  7264. public function getWebsiteCompany(array $data): array
  7265. {
  7266. $categorys = json_decode($data['id'], true);
  7267. $category_arr = $this->processArticlePro($data['website_id']);
  7268. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7269. $catiall = $category_arr['catiall'];
  7270. $categoryIds = $category_arr['categoryIds'];
  7271. // return Result::success($category_arr);
  7272. foreach ($categorys as $key => $value) {
  7273. if (array_key_exists('level', $value)) {
  7274. $parts = explode(',', $value['level']);
  7275. $level = $parts[0] ?? null;
  7276. $imgnum = $parts[1] ?? null;
  7277. $textnum = $parts[2] ?? null;
  7278. if (!empty($textnum) && $textnum > 0) {
  7279. $text_num = Company::where('level', $level)
  7280. ->whereIn('category_id', $categoryIds)
  7281. ->where('status', 1)
  7282. ->select(
  7283. 'company.id',
  7284. 'company.title',
  7285. 'company.description',
  7286. 'company.updated_at',
  7287. 'company.category_id',
  7288. 'company.cat_arr_id'
  7289. )
  7290. ->orderBy('updated_at', 'desc')
  7291. ->limit($textnum)
  7292. ->get()->all();
  7293. }
  7294. if (!empty($imgnum) && $imgnum > 0) {
  7295. $img_num = Company::where('level', $level)
  7296. ->whereIn('category_id', $categoryIds)
  7297. ->where('status', 1)
  7298. ->where('imgurl', '!=', '')
  7299. ->whereNotNull('imgurl')
  7300. ->select(
  7301. 'company.id',
  7302. 'company.title',
  7303. 'company.description',
  7304. 'company.updated_at',
  7305. 'company.imgurl as imgs',
  7306. 'company.category_id',
  7307. 'company.cat_arr_id'
  7308. )
  7309. ->orderBy('updated_at', 'desc')
  7310. ->limit($imgnum)
  7311. ->get()->all();
  7312. }
  7313. }
  7314. if (array_key_exists('id', $value)) {
  7315. $parts = explode(',', $value['id']);
  7316. $category_id = $parts[0] ?? null;
  7317. $imgnum = $parts[1] ?? null;
  7318. $textnum = $parts[2] ?? null;
  7319. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  7320. if (!empty($textnum) && $textnum > 0) {
  7321. $text_num = Company::whereIn('category_id', $category_arr)
  7322. // ->where('website_id', $data['website_id'])
  7323. ->where('status', 1)
  7324. ->select(
  7325. 'company.id',
  7326. 'company.title',
  7327. 'company.description',
  7328. 'company.updated_at',
  7329. 'company.category_id',
  7330. 'company.cat_arr_id'
  7331. )
  7332. ->orderBy('updated_at', 'desc')
  7333. ->limit($textnum)
  7334. ->get()->all();
  7335. }
  7336. if (!empty($imgnum) && $imgnum > 0) {
  7337. $img_num = Company::whereIn('category_id', $category_arr)
  7338. // ->where('website_id', $data['website_id'])
  7339. ->where('status', 1)
  7340. ->where('imgurl', '!=', '')
  7341. ->whereNotNull('imgurl')
  7342. ->select(
  7343. 'company.id',
  7344. 'company.title',
  7345. 'company.description',
  7346. 'company.updated_at',
  7347. 'company.imgurl as imgs',
  7348. 'company.category_id',
  7349. 'company.cat_arr_id'
  7350. )
  7351. ->orderBy('updated_at', 'desc')
  7352. ->limit($imgnum)
  7353. ->get()->all();
  7354. }
  7355. }
  7356. if (!empty($text_num)) {
  7357. foreach ($text_num as $k => $v) {
  7358. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7359. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7360. }
  7361. }
  7362. if (!empty($img_num)) {
  7363. foreach ($img_num as $k => $v) {
  7364. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7365. $imgurl = json_decode($v['imgs'], true);
  7366. if (!empty($imgurl)) {
  7367. $img_num[$k]->imgurl = $imgurl[0];
  7368. }
  7369. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7370. }
  7371. }
  7372. $company[$key]['img_num'] = $img_num ?? [];
  7373. $company[$key]['text_num'] = $text_num ?? [];
  7374. }
  7375. if (empty($company)) {
  7376. return Result::error("暂无相关企业信息", 0);
  7377. }
  7378. return Result::success($company);
  7379. }
  7380. /**
  7381. * @param array $data
  7382. * @return array
  7383. */
  7384. public function getWebsiteCompanyList(array $data): array
  7385. {
  7386. $where['website_id'] = $data['website_id'];
  7387. $where['status'] = 1;
  7388. $categoryIds = [];
  7389. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7390. $category_id = $data['category_id'];
  7391. }
  7392. $category_arr = $this->processArticlePro($data['website_id']);
  7393. $categoryIds = $category_arr['categoryIds'];
  7394. // return Result::success($cat_1st_arr);
  7395. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  7396. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  7397. })
  7398. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  7399. $query->whereIn('category_id', $categoryIds);
  7400. })
  7401. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  7402. $query->where('category_id', $category_id);
  7403. })
  7404. ->where('status',1)
  7405. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  7406. ->orderBy('updated_at', 'desc')
  7407. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7408. if (empty($company)) {
  7409. return Result::error("暂无相关公司信息", 0);
  7410. }
  7411. $result = [
  7412. 'count' => $company->total(),
  7413. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  7414. ];
  7415. return Result::success($result);
  7416. }
  7417. /**
  7418. * 获取项目列表
  7419. * @param array $data
  7420. * @return array
  7421. */
  7422. public function getProjectList(array $data): array
  7423. {
  7424. $where = [];
  7425. $user = User::where('id', $data['user_id'])->first();
  7426. if (empty($user)) {
  7427. return Result::error('用户不存在!');
  7428. }
  7429. if ($user->type_id != 10000) {
  7430. array_push($where, ['project.user_id', $data['user_id']]);
  7431. }
  7432. $query = Project::query();
  7433. if (isset($data['website_id']) && !empty($data['website_id'])) {
  7434. array_push($where, ['project.website_id', $data['website_id']]);
  7435. }
  7436. if (isset($data['title']) && !empty($data['title'])) {
  7437. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  7438. }
  7439. if ($data['status'] != 3) {
  7440. array_push($where, ['project.status', $data['status']]);
  7441. }
  7442. $query = Project::where($where)
  7443. ->when($data['status'] == 3, function ($query) {
  7444. $query->whereIn('project.status', [0, 2]);
  7445. });
  7446. $count = $query->clone()
  7447. ->count();
  7448. $rows = $query->clone()
  7449. ->leftJoin('website', 'project.website_id', 'website.id')
  7450. ->leftJoin('website_category', function ($join) {
  7451. $join->on('project.website_id', '=', 'website_category.website_id')
  7452. ->on('project.category_id', '=', 'website_category.category_id');
  7453. })
  7454. ->select(
  7455. 'project.id',
  7456. 'project.title',
  7457. 'project.updated_at',
  7458. 'project.status',
  7459. 'website.website_name',
  7460. 'website_category.alias as category_name',
  7461. 'project.website_id',
  7462. 'project.user_id'
  7463. )
  7464. ->orderBy('project.updated_at', 'desc')
  7465. ->offset(($data['page'] - 1) * $data['pageSize'])
  7466. ->limit($data['pageSize'])
  7467. ->get();
  7468. if ($rows->isEmpty()) {
  7469. return Result::error("暂无相关项目信息", 0);
  7470. }
  7471. $result = [
  7472. 'count' => $count,
  7473. 'rows' => $rows,
  7474. ];
  7475. return Result::success($result);
  7476. }
  7477. /**
  7478. * 添加项目
  7479. * @param array $data
  7480. * @return array
  7481. */
  7482. public function addProject(array $data): array
  7483. {
  7484. $user = User::where('id', $data['user_id'])->first();
  7485. if (empty($user)) {
  7486. return Result::error("暂无相关用户信息", 0);
  7487. }
  7488. if ($user->type_id == 10000) {
  7489. $data['status'] = 1;
  7490. } else {
  7491. $data['status'] = 0;
  7492. }
  7493. if ($data['keyword'] == '') {
  7494. //提取标题+内容中的关键词
  7495. $data['keyword'] = $data['title'];
  7496. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7497. Jieba::init(); // 初始化 jieba-php
  7498. Finalseg::init();
  7499. $segList = Jieba::cut($data['keyword']);
  7500. $segList1 = array_slice($segList, 0, 8);
  7501. $data['keyword'] = implode(',', $segList1);
  7502. }
  7503. if ($data['description'] == '') {
  7504. //提取内容中的描述
  7505. // var_dump(11111);
  7506. //提取内容中的描述
  7507. $content = $data['introduce'];
  7508. // 去除 <style> 和 <script> 标签及其内容
  7509. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7510. // 去除所有 HTML 标签
  7511. $content = strip_tags($content);
  7512. // 去除 HTML 实体
  7513. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7514. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7515. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7516. // 去除多余空白
  7517. $content = preg_replace('/\s+/u', '', $content);
  7518. // 截取 100 个字符
  7519. $data['description'] = mb_substr($content, 0, 100);
  7520. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7521. }
  7522. if ($data['status'] == 0) {
  7523. $this->sendMessage([
  7524. 'talk_type' => 1000,
  7525. 'title' => $data['title'],
  7526. 'content' => '提交了审核',
  7527. 'messageType' => 9,
  7528. ]);
  7529. }
  7530. $project = Project::insertGetId($data);
  7531. if (empty($project)) {
  7532. return Result::error("暂无相关项目信息", 0);
  7533. }
  7534. return Result::success($project);
  7535. }
  7536. /**
  7537. * 更新项目
  7538. * @param array $data
  7539. * @return array
  7540. */
  7541. public function upProject(array $data): array
  7542. {
  7543. $project = Project::where('id', $data['id'])->first();
  7544. if (empty($project)) {
  7545. return Result::error("暂无相关项目信息", 0);
  7546. }
  7547. $id = $data['id'];
  7548. unset($data['id']);
  7549. $user = User::where('id', $data['user_id'])->first();
  7550. if (empty($user)) {
  7551. return Result::error("暂无相关用户信息", 0);
  7552. }
  7553. if ($user->type_id == 10000) {
  7554. $data['status'] = 1;
  7555. } else {
  7556. $data['status'] = 0;
  7557. }
  7558. unset($data['user_id']);
  7559. if ($data['keyword'] == '') {
  7560. //提取标题+内容中的关键词
  7561. $data['keyword'] = $data['title'];
  7562. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7563. Jieba::init(); // 初始化 jieba-php
  7564. Finalseg::init();
  7565. $segList = Jieba::cut($data['keyword']);
  7566. $segList1 = array_slice($segList, 0, 8);
  7567. $data['keyword'] = implode(',', $segList1);
  7568. }
  7569. if ($data['description'] == '') {
  7570. //提取内容中的描述
  7571. // var_dump(11111);
  7572. //提取内容中的描述
  7573. $content = $data['introduce'];
  7574. // 去除 <style> 和 <script> 标签及其内容
  7575. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7576. // 去除所有 HTML 标签
  7577. $content = strip_tags($content);
  7578. // 去除 HTML 实体
  7579. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7580. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7581. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7582. // 去除多余空白
  7583. $content = preg_replace('/\s+/u', '', $content);
  7584. // 截取 100 个字符
  7585. $data['description'] = mb_substr($content, 0, 100);
  7586. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7587. }
  7588. if ($data['status'] == 0) {
  7589. $this->sendMessage([
  7590. 'talk_type' => 1000,
  7591. 'title' => $data['title'],
  7592. 'content' => '提交了审核',
  7593. 'messageType' => 9,
  7594. ]);
  7595. }
  7596. $result = Project::where('id', $id)->update($data);
  7597. if (empty($result)) {
  7598. return Result::error("更新失败", 0);
  7599. }
  7600. return Result::success($result);
  7601. }
  7602. /**
  7603. * 删除项目
  7604. * @param array $data
  7605. * @return array
  7606. */
  7607. public function delProject(array $data): array
  7608. {
  7609. $user = User::where('id', $data['user_id'])->first();
  7610. if (empty($user)) {
  7611. return Result::error("暂无相关用户信息", 0);
  7612. }
  7613. $project = Project::where('id', $data['id'])->first();
  7614. if (empty($project)) {
  7615. return Result::error("暂无相关项目信息", 0);
  7616. }
  7617. $result = Project::where('id', $data['id'])->delete();
  7618. if (empty($result)) {
  7619. return Result::error("删除失败", 0);
  7620. }
  7621. return Result::success($result);
  7622. }
  7623. /**
  7624. * 审核项目
  7625. * @param array $data
  7626. * @return array
  7627. */
  7628. public function checkProject(array $data): array
  7629. {
  7630. $user = User::where('id', $data['user_id'])->first();
  7631. if (empty($user)) {
  7632. return Result::error("暂无相关用户信息", 0);
  7633. }
  7634. // 0:未审核; 1:已审核; 2:已拒绝;
  7635. if ($user->type_id != 10000) {
  7636. if ($data['status'] == 1 || $data['status'] == 2) {
  7637. return Result::error("此用户权限不足", 0);
  7638. }
  7639. }
  7640. $project = Project::where('id', $data['id'])->first();
  7641. if (empty($project)) {
  7642. return Result::error("暂无相关项目信息", 0);
  7643. }
  7644. if ($data['status'] == 2) {
  7645. $this->sendMessage([
  7646. 'talk_type' => 1001,
  7647. 'title' => $project['title'],
  7648. 'content' => '审核拒绝',
  7649. 'messageType' => 9,
  7650. 'user_id' => $project['user_id'],
  7651. ]);
  7652. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7653. } else {
  7654. if ($data['status'] == 1) {
  7655. $this->sendMessage([
  7656. 'talk_type' => 1001,
  7657. 'title' => $project['title'],
  7658. 'content' => '审核通过',
  7659. 'messageType' => 9,
  7660. 'user_id' => $project['user_id'],
  7661. ]);
  7662. } else if ($data['status'] == 0) {
  7663. $this->sendMessage([
  7664. 'talk_type' => 1000,
  7665. 'title' => $project['title'],
  7666. 'content' => '提交了审核',
  7667. 'messageType' => 9,
  7668. ]);
  7669. }
  7670. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7671. }
  7672. if (empty($result)) {
  7673. return Result::error("审核失败", 0);
  7674. }
  7675. return Result::success($result);
  7676. }
  7677. /**
  7678. * 获取项目详情
  7679. * @param array $data
  7680. * @return array
  7681. */
  7682. public function getProjectInfo(array $data): array
  7683. {
  7684. $project = Project::where('id', $data['id'])->first();
  7685. if (empty($project)) {
  7686. return Result::error("暂无相关项目信息", 0);
  7687. }
  7688. return Result::success($project);
  7689. }
  7690. public function getWebsiteCompanyInfo(array $data): array
  7691. {
  7692. $company = Company::where('id', $data['id'])
  7693. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7694. ->where('status', 1)
  7695. // ->where('website_id', $data['website_id'])
  7696. ->select('company.*', 'job_industry.hyname as hy_name')
  7697. ->first();
  7698. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7699. $jobnature_id = $company['jobnature_id'] ?? null;
  7700. if ($jobnature_id !== null) {
  7701. switch ($jobnature_id) {
  7702. case 0:
  7703. $company->jobnature_name = '市场监督';
  7704. break;
  7705. case 1:
  7706. $company->jobnature_name = '信访纪检';
  7707. break;
  7708. case 2:
  7709. $company->jobnature_name = '公检法司';
  7710. break;
  7711. case 3:
  7712. $company->jobnature_name = '高关注机构';
  7713. break;
  7714. default:
  7715. $company->jobnature_name = '';
  7716. break;
  7717. }
  7718. } else {
  7719. $company->jobnature_name = '';
  7720. }
  7721. $city_arr = $company->city_arr_id;
  7722. if (!empty($city_arr)) {
  7723. $city_arr = json_decode($city_arr, true);
  7724. $cityNames = District::whereIn('id', $city_arr)
  7725. ->pluck('name')
  7726. ->implode('-');
  7727. $company->city_name = $cityNames;
  7728. } else {
  7729. $company->city_name = '';
  7730. }
  7731. if (empty($company)) {
  7732. return Result::error("暂无相关公司信息", 0);
  7733. }
  7734. return Result::success($company);
  7735. }
  7736. public function getMSG(array $data): array
  7737. {
  7738. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7739. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7740. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7741. $result = [];
  7742. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7743. //最近的5篇已审的文章
  7744. $apply_articale = Article::where('status', 1)
  7745. ->where('admin_user_id', $user_id)
  7746. ->orderBy('updated_at', 'desc')
  7747. // ->limit(5)
  7748. ->get();
  7749. //获取5条用户的已审核商品
  7750. $good = Good::where('status', 2)
  7751. ->where('user_id', $user_id)
  7752. ->orderBy('updated_at', 'desc')
  7753. // ->limit(5)
  7754. ->get();
  7755. //获取5条用户待审核的公告
  7756. $notice = Notice::where('status', 2)
  7757. ->where('user_id', $user_id)
  7758. ->orderBy('updated_at', 'desc')
  7759. ->limit(5)->get();
  7760. //获取5条用户的待审核投诉
  7761. $complaint = Complaint::where('status', 2)
  7762. ->where('user_id', $user_id)
  7763. ->orderBy('updated_at', 'desc')
  7764. // ->limit(5)
  7765. ->get();
  7766. //获取5条用户的book
  7767. $book = Book::where('status', 2)
  7768. ->where('user_id', $user_id)
  7769. ->orderBy('updated_at', 'desc')
  7770. // ->limit(5)
  7771. ->get();
  7772. //获取5条用户的求职
  7773. //获取5条用户的求职 1
  7774. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7775. ->where('job_hunting.user_id', $user_id)
  7776. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7777. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7778. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7779. ->orderBy('updated_at', 'desc')
  7780. // ->limit(5)
  7781. ->get();
  7782. //获取5条用户的求职 2
  7783. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7784. ->where('job_recruiting.user_id', $user_id)
  7785. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7786. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7787. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7788. ->orderBy('updated_at', 'desc')
  7789. // ->limit(5)
  7790. ->get();
  7791. //人才库 1
  7792. $job_apply = JobApply::where('job_apply.status', 1)
  7793. ->where('job_apply.receiver_id', $user_id)
  7794. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7795. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7796. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7797. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7798. ->select('job_recruiting', 'job_recruiting.', '', '')
  7799. ->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')
  7800. ->orderBy('updated_at', 'desc')
  7801. // ->limit(5)
  7802. ->get();
  7803. // 职场机会 2
  7804. $job_resume = JobResume::where('job_resume.status', 1)
  7805. ->where('job_resume.receiver_id', $user_id)
  7806. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7807. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7808. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7809. ->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')
  7810. ->orderBy('updated_at', 'desc')
  7811. // ->limit(5)
  7812. ->get();
  7813. //获取5条用户待处理的投诉
  7814. $complaint_deal = Complaint::where('status', 2)
  7815. ->where('deal', 1)
  7816. ->whereJsonContains('re_user_ids', $user_id)
  7817. ->orderBy('updated_at', 'desc')
  7818. // ->limit(5)
  7819. ->get();
  7820. //获取 被通知者未读信息
  7821. $notice_unread = Notice::where('status', 2)
  7822. ->whereJsonContains('re_user_ids', $user_id)
  7823. //未读消息
  7824. ->where(function ($query) use ($user_id) {
  7825. $query->whereJsonDoesntContain('read_id', $user_id)
  7826. ->orWhereNull('read_id');
  7827. })
  7828. ->orderBy('updated_at', 'desc')
  7829. ->get();
  7830. $complaint_unread = Complaint::where('status', 2)
  7831. ->whereJsonContains('re_user_ids', $user_id)
  7832. //未读消息
  7833. ->where(function ($query) use ($user_id) {
  7834. $query->whereJsonDoesntContain('read_id', $user_id)
  7835. ->orWhereNull('read_id');
  7836. })
  7837. ->orderBy('updated_at', 'desc')
  7838. ->get();
  7839. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7840. $complany = Company::where('status', 1)
  7841. ->where('user_id', $user_id)
  7842. ->orderBy('updated_at', 'desc')
  7843. // ->limit(5)
  7844. ->get();
  7845. //获取5条单聊未读聊天消息
  7846. // $chat = ChatRecords::where('is_read', 0)
  7847. // ->where('user_id', $user_id)
  7848. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7849. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7850. // ->where('action', 'recieved')
  7851. // ->where('talk_type', 1)
  7852. // ->orderBy('created_at', 'desc')
  7853. // // ->limit(5)
  7854. // ->get();
  7855. //获取5条未读群聊信息
  7856. // $chat_group = ChatRecords::where('is_read', 0)
  7857. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7858. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7859. // ->where('user_id', $user_id)
  7860. // ->where('talk_type', 2)
  7861. // ->orderBy('created_at', 'desc')
  7862. // // ->limit(5)
  7863. // ->get();
  7864. //获取5条用户的待审核项目
  7865. $project = Project::where('status', 1)
  7866. ->where('user_id', $user_id)
  7867. ->orderBy('updated_at', 'desc')
  7868. // ->limit(5)
  7869. ->get();
  7870. // count($chat) + count($chat_group) +
  7871. $count = count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting) + count($job_apply) + count($job_resume) + count($complaint_deal)
  7872. + count($complany)
  7873. + count($project)
  7874. + count($notice_unread)
  7875. + count($complaint_unread)
  7876. // + count($chat) + count($chat_group)
  7877. ;
  7878. $result = [
  7879. 'apply_articale' => $apply_articale,
  7880. // 'chat' => $chat,
  7881. // 'chat_group' => $chat_group,
  7882. 'good' => $good,
  7883. 'notice' => $notice,
  7884. 'complaint' => $complaint,
  7885. 'book' => $book,
  7886. 'job_hunting' => $job_hunting,
  7887. 'job_recruiting' => $job_recruiting,
  7888. 'job_apply' => $job_apply,
  7889. 'job_resume' => $job_resume,
  7890. 'complaint_deal' => $complaint_deal,
  7891. 'complany' => $complany,
  7892. 'project' => $project,
  7893. 'notice_unread' => $notice_unread,
  7894. 'complaint_unread' => $complaint_unread,
  7895. 'count' => $count,
  7896. ];
  7897. } elseif ($type_id == 12) {
  7898. //最近的5篇已审的文章
  7899. $apply_articale = Article::where('status', 1)
  7900. ->where('admin_user_id', $user_id)
  7901. ->limit(5)->get();
  7902. //获取5条单聊未读聊天消息
  7903. $chat = ChatRecords::where('is_read', 0)
  7904. ->where('user_id', $user_id)
  7905. ->where('talk_type', 1)
  7906. ->orderBy('created_at', 'desc')
  7907. ->limit(5)->get();
  7908. //获取5条未读群聊信息
  7909. $chat_group = ChatRecords::where('is_read', 0)
  7910. ->where('user_id', $user_id)
  7911. ->where('talk_type', 2)
  7912. ->orderBy('created_at', 'desc')
  7913. ->limit(5)->get();
  7914. //获取5条用户的已审核商品
  7915. $good = Good::where('status', 2)
  7916. ->where('user_id', $user_id)
  7917. ->orderBy('updated_at', 'desc')
  7918. ->limit(5)->get();
  7919. //获取5条用户的book
  7920. $book = Book::where('status', 2)
  7921. ->where('user_id', $user_id)
  7922. ->orderBy('updated_at', 'desc')
  7923. ->limit(5)->get();
  7924. //获取5条用户的求职
  7925. //获取5条用户的求职 1
  7926. //count($chat) + count($chat_group)
  7927. $count = count($apply_articale) + count($good);
  7928. $result = [
  7929. 'apply_articale' => $apply_articale,
  7930. 'chat' => $chat,
  7931. 'chat_group' => $chat_group,
  7932. 'good' => $good,
  7933. 'book' => $book,
  7934. 'count' => $count,
  7935. ];
  7936. } elseif ($type_id == 13) {
  7937. //最近的5篇已审的文章
  7938. $apply_articale = Article::where('status', 1)
  7939. ->where('admin_user_id', $user_id)
  7940. ->limit(5)->get();
  7941. //获取5条单聊未读聊天消息
  7942. $chat = ChatRecords::where('is_read', 0)
  7943. ->where('user_id', $user_id)
  7944. ->where('talk_type', 1)
  7945. ->orderBy('created_at', 'desc')
  7946. ->limit(5)->get();
  7947. //获取5条未读群聊信息
  7948. $chat_group = ChatRecords::where('is_read', 0)
  7949. ->where('user_id', $user_id)
  7950. ->where('talk_type', 2)
  7951. ->orderBy('created_at', 'desc')
  7952. ->limit(5)->get();
  7953. //获取5条用户的已审核商品
  7954. $good = Good::where('status', 2)
  7955. ->where('user_id', $user_id)
  7956. ->orderBy('updated_at', 'desc')
  7957. ->limit(5)->get();
  7958. //count($chat) + count($chat_group) +
  7959. $count = count($apply_articale) + count($good);
  7960. $result = [
  7961. 'apply_articale' => $apply_articale,
  7962. 'chat' => $chat,
  7963. 'chat_group' => $chat_group,
  7964. 'good' => $good,
  7965. 'count' => $count,
  7966. ];
  7967. } elseif ($type_id == 14) {
  7968. //最近的5篇已审的文章
  7969. $apply_articale = Article::where('status', 1)
  7970. ->where('admin_user_id', $user_id)
  7971. // ->limit(5)
  7972. ->get();
  7973. //获取5条用户的已审核商品
  7974. $good = Good::where('status', 2)
  7975. ->where('user_id', $user_id)
  7976. ->orderBy('updated_at', 'desc')
  7977. // ->limit(5)
  7978. ->get();
  7979. $count = count($apply_articale) + count($good);
  7980. $result = [
  7981. 'apply_articale' => $apply_articale,
  7982. 'chat' => '',
  7983. 'chat_group' => '',
  7984. 'good' => $good,
  7985. 'count' => $count,
  7986. ];
  7987. } elseif ($type_id == 10000) {
  7988. //获取未审核的5篇文章
  7989. $apply_articale = Article::where('status', 0)
  7990. ->orderBy('updated_at', 'desc')
  7991. // ->limit(5)
  7992. ->get();
  7993. //获取5条单聊未读聊天消息
  7994. //获取5条单聊未读聊天消息
  7995. // $chat = ChatRecords::where('is_read', 0)
  7996. // ->where('user_id', $user_id)
  7997. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7998. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7999. // ->where('action', 'recieved')
  8000. // ->where('talk_type', 1)
  8001. // ->orderBy('created_at', 'desc')
  8002. // // ->limit(5)
  8003. // ->get();
  8004. // //获取5条未读群聊信息
  8005. // $chat_group = ChatRecords::where('is_read', 0)
  8006. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  8007. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  8008. // ->where('user_id', $user_id)
  8009. // ->where('talk_type', 2)
  8010. // ->orderBy('created_at', 'desc')
  8011. // // ->limit(5)
  8012. // ->get();
  8013. //获取5条用户的已审核商品
  8014. $good = Good::where('status', 1)
  8015. // ->where('user_id', $user_id)
  8016. ->orderBy('updated_at', 'desc')
  8017. // ->limit(5)
  8018. ->get();
  8019. //获取5条用户待审核的公告
  8020. $notice = Notice::where('status', 1)
  8021. ->orderBy('updated_at', 'desc')
  8022. // ->limit(5)
  8023. ->get();
  8024. //获取5条用户的待审核投诉
  8025. $complaint = Complaint::where('status', 1)
  8026. ->orderBy('updated_at', 'desc')
  8027. // ->limit(5)
  8028. ->get();
  8029. //获取5条用户的book
  8030. $book = Book::where('status', 1)
  8031. ->orderBy('updated_at', 'desc')
  8032. // ->limit(5)
  8033. ->get();
  8034. //获取5条用户的求职 1
  8035. $job_hunting = JobHunting::where('job_hunting.status', 1)
  8036. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  8037. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  8038. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  8039. ->orderBy('updated_at', 'desc')
  8040. // ->limit(5)
  8041. ->get();
  8042. //获取5条用户的求职 2
  8043. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  8044. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  8045. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  8046. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  8047. ->orderBy('updated_at', 'desc')
  8048. // ->limit(5)
  8049. ->get();
  8050. //人才库 1
  8051. $job_apply = JobApply::where('job_apply.status', 1)
  8052. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  8053. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  8054. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  8055. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  8056. ->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')
  8057. ->orderBy('updated_at', 'desc')
  8058. // ->limit(5)
  8059. ->get();
  8060. // 职场机会 2
  8061. $job_resume = JobResume::where('job_resume.status', 1)
  8062. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  8063. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  8064. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  8065. ->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')
  8066. ->orderBy('updated_at', 'desc')
  8067. // ->limit(5)
  8068. ->get();
  8069. //待审核数据com pro
  8070. $complany = Company::where('status', 0)
  8071. ->orderBy('updated_at', 'desc')
  8072. // ->limit(5)
  8073. ->get();
  8074. $project = Project::where('status', 0)
  8075. ->orderBy('updated_at', 'desc')
  8076. // ->limit(5)
  8077. ->get();
  8078. $count =
  8079. // count($chat) +
  8080. // count($chat_group) +
  8081. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  8082. // + count($job_apply)
  8083. // + count($job_resume)
  8084. + count($complany)
  8085. + count($project);
  8086. $result = [
  8087. 'apply_articale' => $apply_articale,
  8088. // 'chat' => $chat,
  8089. // 'chat_group' => $chat_group,
  8090. 'good' => $good,
  8091. 'notice' => $notice,
  8092. 'complaint' => $complaint,
  8093. 'book' => $book,
  8094. 'job_hunting' => $job_hunting,
  8095. 'job_recruiting' => $job_recruiting,
  8096. // 'job_apply' => $job_apply,
  8097. // 'job_resume' => $job_resume,
  8098. 'complany' => $complany,
  8099. 'project' => $project,
  8100. 'count' => $count,
  8101. ];
  8102. } elseif ($type_id == 20000) {
  8103. }
  8104. var_dump($type_id, '-----------------test---------');
  8105. return Result::success($result);
  8106. }
  8107. /**
  8108. * @param array $data
  8109. * @return array
  8110. */
  8111. public function getWebsiteProject(array $data): array
  8112. {
  8113. $categorys = json_decode($data['id'], true);
  8114. if (!empty($categorys)) {
  8115. $category_arr = $this->processArticlePro($data['website_id']);
  8116. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8117. $catiall = $category_arr['catiall'];
  8118. // return Result::success($catiall);
  8119. foreach ($categorys as $key => $val) {
  8120. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  8121. $level = explode(',', $val['level'])[0];
  8122. $imgnum = explode(',', $val['level'])[1] ?? null;
  8123. $textnum = explode(',', $val['level'])[2] ?? null;
  8124. if ($level == 1) {
  8125. if (!empty($textnum) && $textnum > 0) {
  8126. $text_num = Project::where('level', $level)
  8127. ->where('website_id', $data['website_id'])
  8128. ->where('status', 1)
  8129. ->select(
  8130. 'project.id',
  8131. 'project.title',
  8132. 'project.description',
  8133. 'project.updated_at',
  8134. 'project.category_id',
  8135. 'project.cat_arr_id'
  8136. )
  8137. ->orderBy('updated_at', 'desc')
  8138. ->limit($textnum)
  8139. ->get()->all();
  8140. }
  8141. if (!empty($imgnum) && $imgnum > 0) {
  8142. $img_num = Project::where('level', $level)
  8143. ->where('website_id', $data['website_id'])
  8144. ->where('status', 1)
  8145. ->where('imgurl', '!=', '')
  8146. ->whereNotNull('imgurl')
  8147. ->select(
  8148. 'project.id',
  8149. 'project.title',
  8150. 'project.description',
  8151. 'project.updated_at',
  8152. 'project.imgurl as imgs',
  8153. 'project.category_id',
  8154. 'project.cat_arr_id'
  8155. )
  8156. ->orderBy('updated_at', 'desc')
  8157. ->limit($imgnum)
  8158. ->get()->all();
  8159. }
  8160. } else {
  8161. if (!empty($textnum) && $textnum > 0) {
  8162. $text_num = Project::where('website_id', $data['website_id'])
  8163. ->where('status', 1)
  8164. ->select(
  8165. 'project.id',
  8166. 'project.title',
  8167. 'project.description',
  8168. 'project.updated_at',
  8169. 'project.category_id',
  8170. 'project.cat_arr_id',
  8171. 'project.website_id',
  8172. 'project.updated_at',
  8173. 'project.created_at'
  8174. )
  8175. ->orderBy('updated_at', 'desc')
  8176. ->limit($textnum)
  8177. ->get()->all();
  8178. }
  8179. if (!empty($imgnum) && $imgnum > 0) {
  8180. $img_num = Project::where('website_id', $data['website_id'])
  8181. ->where('status', 1)
  8182. ->where('imgurl', '!=', '')
  8183. ->whereNotNull('imgurl')
  8184. ->select(
  8185. 'project.id',
  8186. 'project.title',
  8187. 'project.description',
  8188. 'project.updated_at',
  8189. 'project.imgurl as imgs',
  8190. 'project.category_id',
  8191. 'project.cat_arr_id'
  8192. )
  8193. ->orderBy('updated_at', 'desc')
  8194. ->limit($imgnum)
  8195. ->get()->all();
  8196. }
  8197. }
  8198. }
  8199. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  8200. $category_ids = explode(',', $val['id'])[0];
  8201. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  8202. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  8203. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  8204. if (!empty($cat_textnum) && $cat_textnum > 0) {
  8205. $text_num = Project::whereIn('category_id', $category_arr)
  8206. ->where('website_id', $data['website_id'])
  8207. ->where('status', 1)
  8208. ->select(
  8209. 'project.id',
  8210. 'project.title',
  8211. 'project.description',
  8212. 'project.updated_at',
  8213. 'project.category_id',
  8214. 'project.cat_arr_id'
  8215. )
  8216. ->orderBy('updated_at', 'desc')
  8217. ->limit($cat_textnum)
  8218. ->get()->all();
  8219. }
  8220. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  8221. $img_num = Project::whereIn('category_id', $category_arr)
  8222. ->where('website_id', $data['website_id'])
  8223. ->where('status', 1)
  8224. ->where('imgurl', '!=', '')
  8225. ->whereNotNull('imgurl')
  8226. ->select(
  8227. 'project.id',
  8228. 'project.title',
  8229. 'project.description',
  8230. 'project.updated_at',
  8231. 'project.imgurl as imgs',
  8232. 'project.category_id',
  8233. 'project.cat_arr_id'
  8234. )
  8235. ->orderBy('updated_at', 'desc')
  8236. ->limit($cat_imgnum)
  8237. ->get()->all();
  8238. }
  8239. }
  8240. if (!empty($img_num)) {
  8241. foreach ($img_num as $k => $v) {
  8242. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8243. $imgurl = json_decode($v['imgs'], true);
  8244. if (!empty($imgurl)) {
  8245. $img_num[$k]->imgurl = $imgurl[0];
  8246. }
  8247. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8248. }
  8249. }
  8250. if (!empty($text_num)) {
  8251. foreach ($text_num as $k => $v) {
  8252. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8253. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8254. }
  8255. }
  8256. $project[$key]['img_num'] = $img_num ?? [];
  8257. $project[$key]['text_num'] = $text_num ?? [];
  8258. }
  8259. }
  8260. if (empty($project)) {
  8261. return Result::error("暂无相关项目信息", 0);
  8262. }
  8263. return Result::success($project);
  8264. }
  8265. /**
  8266. * @param array $data
  8267. * @return array
  8268. */
  8269. public function getWebsiteProjectInfo(array $data): array
  8270. {
  8271. $project = Project::where('id', $data['id'])
  8272. ->where('status', 1)
  8273. ->where('website_id', $data['website_id'])
  8274. ->select('project.*')
  8275. ->first();
  8276. if (empty($project)) {
  8277. return Result::error("暂无相关项目信息", 0);
  8278. }
  8279. return Result::success($project);
  8280. }
  8281. /**
  8282. * @param array $data
  8283. * @return array
  8284. */
  8285. public function getWebsiteProjectList(array $data): array
  8286. {
  8287. $where = [];
  8288. if (isset($data['category_id']) && !empty($data['category_id'])) {
  8289. $where['category_id'] = $data['category_id'];
  8290. }
  8291. if (isset($data['keyword']) && !empty($data['keyword'])) {
  8292. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  8293. }
  8294. $query = Project::where($where)
  8295. ->where('status', 1)
  8296. ->where('website_id', $data['website_id'])
  8297. ->select(
  8298. 'project.id',
  8299. 'project.title',
  8300. 'project.description',
  8301. 'project.imgurl as imgs',
  8302. 'project.category_id',
  8303. 'project.cat_arr_id'
  8304. )
  8305. ->orderBy('updated_at', 'desc');
  8306. $count = $query->count();
  8307. $project = $query->clone()
  8308. ->offset(($data['page'] - 1) * $data['pageSize'])
  8309. ->limit($data['pageSize'])
  8310. ->get()->all();
  8311. if (empty($project)) {
  8312. return Result::error("暂无相关项目信息", 0);
  8313. }
  8314. $categorys = $this->processArticlePro($data['website_id']);
  8315. $catiall = $categorys['catiall'];
  8316. foreach ($project as $key => $val) {
  8317. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  8318. if (!empty($val['imgs'])) {
  8319. $imgurl = json_decode($val['imgs'], true);
  8320. if (!empty($imgurl)) {
  8321. $project[$key]->imgurl = $imgurl[0];
  8322. }
  8323. } else {
  8324. $project[$key]->imgurl = '';
  8325. }
  8326. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  8327. }
  8328. $result = [
  8329. 'rows' => $project,
  8330. 'count' => $count,
  8331. ];
  8332. return Result::success($result);
  8333. }
  8334. /**
  8335. * @param array $data
  8336. * @return array
  8337. */
  8338. public function getWebsiteCategoryJob(array $data): array
  8339. {
  8340. $categorys = json_decode($data['id'], true);
  8341. if (!empty($categorys)) {
  8342. $category_arr = $this->processArticlePro($data['website_id']);
  8343. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8344. $catiall = $category_arr['catiall'];
  8345. foreach ($categorys as $key => $val) {
  8346. if (isset($val['id']) && !empty($val['id'])) {
  8347. $catid = explode(',', $val['id'])[0] ?? null;
  8348. $type = explode(',', $val['id'])[1] ?? null;
  8349. $textnum = explode(',', $val['id'])[2] ?? null;
  8350. }
  8351. // 4:招聘;5:求职;
  8352. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  8353. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  8354. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  8355. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  8356. ->where('job_recruiting.status', 1)
  8357. ->where('job_recruiting.website_id', $data['website_id'])
  8358. ->select(
  8359. 'job_recruiting.id',
  8360. 'job_recruiting.title',
  8361. 'job_company.business_name',
  8362. 'job_recruiting.updated_at',
  8363. 'job_recruiting.cat_arr_id',
  8364. 'job_recruiting.keyword',
  8365. 'job_recruiting.description'
  8366. )
  8367. ->orderBy('job_recruiting.updated_at', 'desc')
  8368. ->limit($textnum)
  8369. ->get()->all();
  8370. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  8371. // 状态 审核状态,1待审核2已审核3已拒绝
  8372. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  8373. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  8374. ->where('job_hunting.status', 2)
  8375. ->where('job_hunting.website_id', $data['website_id'])
  8376. ->select(
  8377. 'job_hunting.id',
  8378. 'job_hunting.name',
  8379. 'job_hunting.cat_arr_id',
  8380. 'job_position.zwname as job_name',
  8381. 'job_hunting.updated_at',
  8382. // 'job_hunting.keyword',
  8383. 'job_hunting.slelf_evaluation'
  8384. )
  8385. ->orderBy('updated_at', 'desc')
  8386. ->limit($textnum)
  8387. ->get()->all();
  8388. } else {
  8389. $job = [];
  8390. }
  8391. // var_dump($catid.'222uuuuuuu'.$key);
  8392. if (!empty($job)) {
  8393. foreach ($job as $k => $value) {
  8394. if (isset($value->cat_arr_id)) {
  8395. $catArr = json_decode($value->cat_arr_id, true);
  8396. $catId = end($catArr);
  8397. } else {
  8398. continue;
  8399. }
  8400. if (isset($catiall[$catId])) {
  8401. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  8402. }
  8403. }
  8404. }
  8405. // var_dump($catid.'xxxxx'.$key);
  8406. $result[$key] = $job ?? [];
  8407. }
  8408. }
  8409. if (empty($result)) {
  8410. return Result::error("暂无相关分类信息", 0);
  8411. }
  8412. return Result::success($result);
  8413. }
  8414. /**
  8415. * 发送消息
  8416. * @param array $messageData
  8417. * @return void
  8418. */
  8419. public function sendMessage($messageData)
  8420. {
  8421. $msg = [
  8422. 'talk_type' => $messageData['talk_type'],
  8423. 'title' => $messageData['title'],
  8424. 'content' => $messageData['content'],
  8425. 'messageType' => $messageData['messageType'],
  8426. 'user_id' => $messageData['user_id'] ?? '',
  8427. 'time' => microtime(),
  8428. ];
  8429. $message = new MqProducer($msg);
  8430. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  8431. $producer->produce($message);
  8432. }
  8433. /**
  8434. * 行业分类管理 ------1121
  8435. * @param array $data
  8436. * @return array
  8437. */
  8438. public function getJobIndustryList(array $data): array
  8439. {
  8440. $page = $data['page'] ?? 1;
  8441. $page_size = $data['page_size'] ?? 10;
  8442. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8443. $where = ['hyname', 'like', '%' . $data['hyname'] . '%'];
  8444. } else {
  8445. $where = [];
  8446. }
  8447. $rs_query = JobIndustry::when(!empty($where), function ($query) use ($where) {
  8448. $query->where([$where]); // 修复:将条件包装成二维数组
  8449. })
  8450. ->orderBy('updated_at', 'desc');
  8451. $count = $rs_query->count();
  8452. $hy = $rs_query->offset(($page - 1) * $page_size)->limit($page_size)->get()->all();
  8453. $result = [
  8454. 'count' => $count,
  8455. 'list' => $hy,
  8456. ];
  8457. if (empty($hy)) {
  8458. return Result::success('暂无数据');
  8459. }
  8460. return Result::success($result);
  8461. }
  8462. /**
  8463. * 添加行业分类
  8464. * @param array $data
  8465. * @return array
  8466. */
  8467. public function addJobIndustry(array $data): array
  8468. {
  8469. $hy_name = JobIndustry::where('hyname', $data['hyname'])->first(['hyid']);
  8470. if (!empty($hy_name)) {
  8471. return Result::error('行业分类已存在');
  8472. }
  8473. $hy = JobIndustry::insertGetId($data);
  8474. if (empty($hy)) {
  8475. return Result::error('添加失败');
  8476. }
  8477. return Result::success($hy);
  8478. }
  8479. /**
  8480. * 更新行业分类
  8481. * @param array $data
  8482. * @return array
  8483. */
  8484. public function upJobIndustry(array $data): array
  8485. {
  8486. $hy_query = JobIndustry::get();
  8487. $hy_ids = $hy_query->pluck('hyid')->toArray();
  8488. $hy_names = $hy_query->pluck('hyname')->toArray();
  8489. if (!in_array($data['hyid'], $hy_ids)) {
  8490. return Result::error('行业分类不存在');
  8491. }
  8492. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8493. $other_key_hy = array_search($data['hyid'], $hy_ids);
  8494. // return Result::success($other_key_hy);
  8495. unset($hy_names[$other_key_hy]);
  8496. if (in_array($data['hyname'], $hy_names)) {
  8497. return Result::error('行业分类名称已存在');
  8498. }
  8499. }
  8500. $hy = JobIndustry::where('hyid', $data['hyid'])->update($data);
  8501. if (empty($hy)) {
  8502. return Result::error('更新失败');
  8503. }
  8504. return Result::success($hy);
  8505. }
  8506. /**
  8507. * 删除行业分类
  8508. * @param array $data
  8509. * @return array
  8510. */
  8511. public function delJobIndustry(array $data): array
  8512. {
  8513. $hy_id = JobIndustry::where('hyid', $data['hyid'])->first(['hyid']);
  8514. if (empty($hy_id)) {
  8515. return Result::error('行业分类不存在');
  8516. }
  8517. $hy = JobIndustry::where('hyid', $data['hyid'])->delete();
  8518. if (empty($hy)) {
  8519. return Result::error('删除失败');
  8520. }
  8521. return Result::success($hy);
  8522. }
  8523. /**
  8524. * 职位分类-列表
  8525. * @param array $data
  8526. * @return array
  8527. */
  8528. public function getJobPositionList(array $data): array
  8529. {
  8530. $page = $data['page'] ?? 1;
  8531. $page_size = $data['page_size'] ?? 10;
  8532. $where = [];
  8533. if (isset($data['zwname']) && !empty($data['zwname'])) {
  8534. $zwids = JobPosition::where('zwpid', 0)
  8535. ->when(!empty($data['zwname']), function ($query) use ($data) {
  8536. $query->where('zwname', 'like', '%' . $data['zwname'] . '%');
  8537. })
  8538. ->orderBy('updated_at', 'desc')
  8539. ->pluck('zwid')
  8540. // ->get()
  8541. ->toArray();
  8542. }
  8543. if (isset($data['childname']) && !empty($data['childname'])) {
  8544. $child_zwids = JobPosition::where('zwpid', '!=', 0)
  8545. ->when(!empty($data['childname']), function ($query) use ($data) {
  8546. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8547. })
  8548. ->orderBy('updated_at', 'desc')
  8549. ->pluck('zwpid')
  8550. // ->get()
  8551. ->toArray();
  8552. if (isset($zwids) && is_array($zwids) && is_array($child_zwids)) {
  8553. $child_zwids = array_intersect($zwids, $child_zwids);
  8554. }
  8555. $zwids = array_values(array_unique($child_zwids));
  8556. }
  8557. $zwids = $zwids ?? null;
  8558. $count = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8559. $query->whereIn('zwid', $zwids);
  8560. })
  8561. ->where('zwpid', 0)
  8562. ->count();
  8563. $position = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8564. $query->whereIn('zwid', $zwids);
  8565. })
  8566. ->where('zwpid', 0)
  8567. ->orderBy('updated_at', 'desc')
  8568. ->offset(($page - 1) * $page_size)
  8569. ->limit($page_size)->get()
  8570. ->map(function ($item) use ($data) {
  8571. $item->children = $item->where('zwpid', $item->zwid)
  8572. ->when(!empty($data['childname']), function ($query) use ($data) {
  8573. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8574. })
  8575. ->orderBy('updated_at', 'desc')
  8576. ->get();
  8577. return $item;
  8578. })
  8579. ->all();
  8580. $result = [
  8581. 'count' => $count,
  8582. 'list' => $position,
  8583. ];
  8584. if (empty($result)) {
  8585. return Result::success('暂无数据');
  8586. }
  8587. return Result::success($result);
  8588. }
  8589. /**
  8590. * 职位分类-添加
  8591. * @param array $data
  8592. * @return array
  8593. */
  8594. public function addJobPosition(array $data): array
  8595. {
  8596. $zw_name = JobPosition::where('zwpid', $data['zwpid'])
  8597. ->where('zwname', $data['zwname'])->first(['zwid']);
  8598. if (!empty($zw_name)) {
  8599. return Result::error('职位分类已存在');
  8600. }
  8601. $zw = JobPosition::insertGetId($data);
  8602. if(empty($zw)){
  8603. return Result::error('添加失败');
  8604. }
  8605. return Result::success($zw);
  8606. }
  8607. /**
  8608. * 更新职位分类
  8609. * @param array $data
  8610. * @return array
  8611. */
  8612. public function upJobPosition(array $data): array
  8613. {
  8614. $zw_position = JobPosition::get();
  8615. if (!in_array($data['zwid'], $zw_position->pluck('zwid')->toArray())) {
  8616. return Result::error('职位分类不存在');
  8617. }
  8618. $zw_name = $zw_position->where('zwid', '!=', $data['zwid'])
  8619. ->where('zwpid', $data['zwpid'])
  8620. ->where('zwname', $data['zwname'])->first();
  8621. if (!empty($zw_name)) {
  8622. return Result::error('职位分类已存在');
  8623. }
  8624. $result = JobPosition::where('zwid', $data['zwid'])->update($data);
  8625. if (empty($result)) {
  8626. return Result::error('更新失败');
  8627. }
  8628. return Result::success($result);
  8629. }
  8630. /**
  8631. * 删除职位分类
  8632. * @param array $data
  8633. * @return array
  8634. */
  8635. public function delJobPosition(array $data): array
  8636. {
  8637. $zw_jobposition = JobPosition::get();
  8638. $zw_id = $zw_jobposition->where('zwid', $data['zwid'])->first();
  8639. if (empty($zw_id)) {
  8640. return Result::error('职位分类不存在');
  8641. }
  8642. if($zw_id->zwpid == 0){
  8643. $zw_job = JobPosition::where('zwpid', $zw_id->zwid)->first();
  8644. if(!empty($zw_job)){
  8645. return Result::error('请先删除子分类');
  8646. }
  8647. }
  8648. $result = JobPosition::where('zwid', $data['zwid'])->delete();
  8649. if (empty($result)) {
  8650. return Result::error('删除失败');
  8651. }
  8652. return Result::success($result);
  8653. }
  8654. /**
  8655. * 网民留言-添加
  8656. * @param array $data
  8657. * @return array
  8658. */
  8659. public function addMessage(array $data): array
  8660. {
  8661. $user = User::where('id', $data['user_id'])->first();
  8662. if (empty($user)) {
  8663. return Result::error('用户不存在');
  8664. }
  8665. if($user['type_id'] == 10000){
  8666. $data['status'] = 1;
  8667. }else{
  8668. $data['status'] = 0;
  8669. }
  8670. if ($data['keyword'] == '') {
  8671. //提取标题+内容中的关键词
  8672. $data['keyword'] = $data['title'];
  8673. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  8674. Jieba::init(); // 初始化 jieba-php
  8675. Finalseg::init();
  8676. $segList = Jieba::cut($data['keyword']);
  8677. $segList1 = array_slice($segList, 0, 8);
  8678. $data['keyword'] = implode(',', $segList1);
  8679. }
  8680. if ($data['description'] == '') {
  8681. //提取内容中的描述
  8682. $content = $data['content'];
  8683. // 去除 <style> 和 <script> 标签及其内容
  8684. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  8685. // 去除所有 HTML 标签
  8686. $content = strip_tags($content);
  8687. // 去除 HTML 实体
  8688. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  8689. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  8690. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  8691. // 去除多余空白
  8692. $content = preg_replace('/\s+/u', '', $content);
  8693. // 截取 100 个字符
  8694. $data['description'] = mb_substr($content, 0, 100);
  8695. }
  8696. if(!empty($data['reply'])){
  8697. $data['reply_userid'] = $data['user_id'];
  8698. }
  8699. $result = Message::insertGetId($data);
  8700. if(empty($result)){
  8701. return Result::error('添加失败');
  8702. }
  8703. return Result::success($result);
  8704. }
  8705. /**
  8706. * 网民留言-更新
  8707. * @param array $data
  8708. * @return array
  8709. */
  8710. public function upMessage(array $data): array
  8711. {
  8712. $user = User::where('id', $data['user_id'])->first();
  8713. if (empty($user)) {
  8714. return Result::error('用户不存在');
  8715. }
  8716. if($user['type_id'] == 10000){
  8717. $data['status'] = 1;
  8718. }
  8719. $message = Message::where('id', $data['id'])->first();
  8720. if (empty($message)) {
  8721. return Result::error('留言不存在');
  8722. }
  8723. if($data['user_id'] != $message['user_id']){
  8724. return Result::error('非留言人不能更新');
  8725. }
  8726. if ($data['keyword'] == '') {
  8727. //提取标题+内容中的关键词
  8728. $data['keyword'] = $data['title'];
  8729. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  8730. Jieba::init(); // 初始化 jieba-php
  8731. Finalseg::init();
  8732. $segList = Jieba::cut($data['keyword']);
  8733. $segList1 = array_slice($segList, 0, 8);
  8734. $data['keyword'] = implode(',', $segList1);
  8735. }
  8736. if ($data['description'] == '') {
  8737. //提取内容中的描述
  8738. $content = $data['content'];
  8739. // 去除 <style> 和 <script> 标签及其内容
  8740. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  8741. // 去除所有 HTML 标签
  8742. $content = strip_tags($content);
  8743. // 去除 HTML 实体
  8744. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  8745. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  8746. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  8747. // 去除多余空白
  8748. $content = preg_replace('/\s+/u', '', $content);
  8749. // 截取 100 个字符
  8750. $data['description'] = mb_substr($content, 0, 100);
  8751. }
  8752. unset($data['id']);
  8753. if(!empty($data['reply'])){
  8754. $data['reply_userid'] = $data['user_id'];
  8755. }
  8756. $result = Message::where('id', $message['id'])->update($data);
  8757. if (empty($result)) {
  8758. return Result::error('更新失败');
  8759. }
  8760. return Result::success($result);
  8761. }
  8762. /**
  8763. * 网民留言-删除
  8764. * @param array $data
  8765. * @return array
  8766. */
  8767. public function delMessage(array $data): array
  8768. {
  8769. $result = Message::where('id', $data['id'])->delete();
  8770. if (empty($result)) {
  8771. return Result::error('删除失败');
  8772. }
  8773. return Result::success($result);
  8774. }
  8775. /**
  8776. * 网民留言-更新状态
  8777. * @param array $data
  8778. * @return array
  8779. */
  8780. public function upMessageStatus(array $data): array
  8781. {
  8782. $message = Message::where('id', $data['id'])->first();
  8783. if (empty($message)) {
  8784. return Result::error('留言不存在!');
  8785. }
  8786. unset($data['id']);
  8787. if($data['status'] != 2){
  8788. $data['reason'] = null;
  8789. }
  8790. $result = Message::where('id', $message['id'])->update($data);
  8791. if (empty($result)) {
  8792. return Result::error('留言更新失败!');
  8793. }
  8794. return Result::success($result);
  8795. }
  8796. /**
  8797. * 网民留言-获取详情
  8798. * @param array $data
  8799. * @return array
  8800. */
  8801. public function getMessageInfo(array $data): array
  8802. {
  8803. $result = Message::where('message.id', $data['id'])
  8804. ->leftJoin('website_column', 'message.column_id', '=', 'website_column.id')
  8805. ->select('message.*', 'website_column.column_arr_id')
  8806. ->first();
  8807. if (empty($result)) {
  8808. return Result::error('留言不存在!');
  8809. }
  8810. $result['column_arr_id'] = json_decode($result['column_arr_id'] ?? [], true);
  8811. return Result::success($result);
  8812. }
  8813. /**
  8814. * 网民留言-获取列表
  8815. * @param array $data
  8816. * @return array
  8817. */
  8818. public function getMessageList(array $data): array
  8819. {
  8820. $where = [];
  8821. if($data['is_master'] == 1){
  8822. $where['status'] = 1;
  8823. }else if($data['is_master'] == 2){
  8824. $where['status'] = 2;
  8825. }else if($data['is_master'] == 3){
  8826. $where['status'] = 0;
  8827. }
  8828. $user = User::where('id', $data['user_id'])->first();
  8829. if (empty($user)) {
  8830. return Result::error('用户不存在');
  8831. }
  8832. if($user['type_id'] != 10000){
  8833. $where['user_id'] = $data['user_id'];
  8834. }
  8835. if(!empty($data['title'])){
  8836. array_push($where, ['title', 'like', '%'.$data['title'].'%']);
  8837. }
  8838. $result = Message::when($data['is_master'] == 0, function ($query) {
  8839. $query->whereIn('status', [0, 2]);
  8840. })
  8841. ->when(!empty($where), function ($query) use ($where) {
  8842. $query->where($where);
  8843. })
  8844. ->orderBy('updated_at', 'desc')
  8845. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  8846. if(empty($result)) {
  8847. return Result::error('留言不存在!');
  8848. }
  8849. $result = [
  8850. 'data' => $result->items(),
  8851. 'count' => $result->total(),
  8852. ];
  8853. return Result::success($result);
  8854. }
  8855. /**
  8856. * 网民留言-检查是否可编辑
  8857. * @param array $data
  8858. * @return array
  8859. */
  8860. public function checkMessageEdit(array $data): array
  8861. {
  8862. $message = Message::where('id', $data['id'])->first();
  8863. if (empty($message)) {
  8864. return Result::error('留言不存在!');
  8865. }
  8866. $web = Website::where('id', $data['website_id'])->first();
  8867. if (empty($web)) {
  8868. return Result::error('网站不存在!');
  8869. }
  8870. $column_arr = json_decode($web['website_column_arr_id'] ?? [], true);
  8871. if(empty($column_arr)){
  8872. return Result::error('该网站未关联任何属性!');
  8873. }
  8874. if(!in_array($message['column_id'], $column_arr)){
  8875. return Result::error('不可编辑');
  8876. }
  8877. return Result::success('可编辑');
  8878. }
  8879. }