NewsService.php 368 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098
  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. use App\Model\ResearchTopic;
  71. use App\Model\RetopicUser;
  72. use App\Model\WebCateinfo;
  73. use App\Model\SinglePage;
  74. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  75. class NewsService implements NewsServiceInterface
  76. {
  77. #[Inject]
  78. protected Redis $redis;
  79. /**
  80. * 获取导航池列表
  81. * @param array $data
  82. * @return array
  83. */
  84. public function getCategoryList(array $data): array
  85. {
  86. $search = $data['name'] ?? '';
  87. $page = (int)($data['page'] ?? 1);
  88. $perPage = (int)($data['pageSize'] ?? 10);
  89. // 1. 查出所有匹配的分类id
  90. if ($search) {
  91. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  92. if (empty($matchedIds)) {
  93. return Result::success(['rows' => [], 'total' => 0]);
  94. }
  95. // 2. 递归查所有父级,直到一级分类
  96. $idsStr = implode(',', $matchedIds);
  97. $sql = "
  98. WITH RECURSIVE parents AS (
  99. SELECT * FROM category WHERE id IN ($idsStr)
  100. UNION ALL
  101. SELECT c.* FROM category c
  102. INNER JOIN parents p ON c.id = p.pid
  103. )
  104. SELECT * FROM parents
  105. ";
  106. $parents = Db::select($sql);
  107. $parentIds = [];
  108. foreach ($parents as $row) {
  109. if ($row->pid == 0) {
  110. $parentIds[] = $row->id;
  111. }
  112. }
  113. $parentIds = array_unique($parentIds);
  114. } else {
  115. // 没有搜索,一级分类就是根
  116. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  117. }
  118. // 3. 一级分类分页
  119. $total = count($parentIds);
  120. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  121. if (empty($parentIds)) {
  122. return Result::success(['rows' => [], 'total' => $total]);
  123. }
  124. // 4. 递归查所有子孙
  125. $idsStr = implode(',', $parentIds);
  126. $sql = "
  127. WITH RECURSIVE subcategories AS (
  128. SELECT * FROM category WHERE id IN ($idsStr)
  129. UNION ALL
  130. SELECT c.* FROM category c
  131. INNER JOIN subcategories s ON c.pid = s.id
  132. )
  133. SELECT * FROM subcategories ORDER BY updated_at DESC
  134. ";
  135. $allCategories = Db::select($sql);
  136. // 5. 组装树结构
  137. $categoryMap = [];
  138. foreach ($allCategories as $cat) {
  139. $cat = (array)$cat;
  140. $cat['children'] = [];
  141. $categoryMap[$cat['id']] = $cat;
  142. }
  143. foreach ($categoryMap as $id => &$cat) {
  144. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  145. $categoryMap[$cat['pid']]['children'][] = &$cat;
  146. }
  147. }
  148. unset($cat);
  149. $categoryTree = [];
  150. foreach ($parentIds as $id) {
  151. if (isset($categoryMap[$id])) {
  152. $categoryTree[] = $categoryMap[$id];
  153. }
  154. }
  155. return Result::success([
  156. 'rows' => $categoryTree,
  157. 'total' => $total,
  158. ]);
  159. }
  160. private function findMatchedCategories($search)
  161. {
  162. if ($search) {
  163. return Category::where('name', 'like', "%{$search}%")
  164. ->orderBy('updated_at', 'desc')
  165. ->get();
  166. }
  167. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  168. ->get();
  169. }
  170. private function findAllParents($categories)
  171. {
  172. $allCategories = [];
  173. foreach ($categories as $category) {
  174. $parentId = $category->pid;
  175. while ($parentId > 0) {
  176. $parent = Category::find($parentId);
  177. if ($parent) {
  178. $allCategories[$parent->id] = $parent;
  179. $parentId = $parent->pid;
  180. } else {
  181. break;
  182. }
  183. }
  184. $allCategories[$category->id] = $category;
  185. }
  186. return array_values($allCategories);
  187. }
  188. private function buildCategoryTree($category, $allRequiredCategories)
  189. {
  190. $categoryData = $category->toArray();
  191. $children = [];
  192. foreach ($allRequiredCategories as $c) {
  193. if ($c->pid === $category->id) {
  194. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  195. }
  196. }
  197. if (!empty($children)) {
  198. $categoryData['children'] = $children;
  199. }
  200. return $categoryData;
  201. }
  202. public function myCategoryList(array $data): array
  203. {
  204. $sszq = $data['sszq'] ?? '';
  205. unset($data['sszq']);
  206. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  207. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  208. $where[] = [
  209. 'pid',
  210. '=',
  211. $data['pid'],
  212. ];
  213. if (isset($data['name'])) {
  214. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  215. }
  216. var_dump($where);
  217. //根据分类id,从category表中取出分类信息
  218. $result = Category::where($where)
  219. ->whereIn('category.id', $catorytids)
  220. ->select('category.*', 'category.id as category_id')->get();
  221. if (empty($result)) {
  222. return Result::error("没有栏目数据");
  223. }
  224. return Result::success($result);
  225. }
  226. /**
  227. * @param array $data
  228. * @return array
  229. */
  230. public function categoryList(array $data): array
  231. {
  232. $where[] = [
  233. 'pid',
  234. '=',
  235. $data['pid']
  236. ];
  237. if (isset($data['name'])) {
  238. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  239. }
  240. var_dump($where);
  241. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  242. if (empty($result)) {
  243. return Result::error("没有栏目数据");
  244. }
  245. return Result::success($result);
  246. }
  247. /**
  248. * @param array $data
  249. * @return array
  250. */
  251. public function addCategory(array $data): array
  252. {
  253. if (isset($data['id'])) {
  254. unset($data['id']);
  255. }
  256. $id = Category::insertGetId($data);
  257. if (empty($id)) {
  258. return Result::error("添加失败");
  259. }
  260. return Result::success(['id' => $id]);
  261. }
  262. /**
  263. * @param array $data
  264. * @return array
  265. */
  266. public function delCategory(array $data): array
  267. {
  268. Db::beginTransaction();
  269. try {
  270. $categoryList = Category::where(['pid' => $data['id']])->get();
  271. if ($categoryList->toArray()) {
  272. Db::rollBack();
  273. return Result::error("分类下面有子分类不能删除");
  274. }
  275. $articleList = Article::where(['catid' => $data['id']])->get();
  276. if ($articleList->toArray()) {
  277. Db::rollBack();
  278. return Result::error("分类下面有资讯不能删除");
  279. }
  280. $result = Category::where($data)->delete();
  281. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  282. if (!$result) {
  283. Db::rollBack();
  284. return Result::error("删除失败");
  285. }
  286. Db::commit();
  287. return Result::success($result);
  288. } catch (\Exception $e) {
  289. Db::rollBack();
  290. return Result::error("删除失败" . $e->getMessage());
  291. }
  292. }
  293. /**
  294. * @param array $data
  295. * @return array
  296. */
  297. public function updateCategory(array $data): array
  298. {
  299. $where = [
  300. 'id' => $data['id'],
  301. ];
  302. $result = Category::where($where)->update($data);
  303. if ($result) {
  304. return Result::success($result);
  305. } else {
  306. return Result::error("更新失败");
  307. }
  308. }
  309. /**
  310. * 获取导航池信息
  311. * @param array $data
  312. * @return array
  313. */
  314. public function getCategoryInfo(array $data): array
  315. {
  316. $where = [
  317. 'id' => $data['id'],
  318. ];
  319. $result = Category::where($where)->first();
  320. if ($result) {
  321. return Result::success($result);
  322. } else {
  323. return Result::error("更新失败");
  324. }
  325. }
  326. public function getArticleCommend(array $data): array
  327. {
  328. $where = [
  329. 'website_id' => $data['website_id'],
  330. ];
  331. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  332. var_dump($ids);
  333. if (empty($ids)) {
  334. return Result::error("没有推荐数据");
  335. }
  336. //id
  337. $whereArticle = [];
  338. if (isset($data['id'])) {
  339. $whereArticle['id'] = $data['id'];
  340. }
  341. //title like
  342. if (isset($data['title'])) {
  343. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  344. }
  345. $article = Article::whereIn('catid', values: $ids)->where('status', 1)
  346. ->where($whereArticle)
  347. ->orderBy('id', 'desc')
  348. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  349. if ($article) {
  350. $data = [
  351. 'rows' => $article->items(),
  352. 'count' => $article->total(),
  353. ];
  354. return Result::success($data);
  355. } else {
  356. return Result::error("获取失败失败");
  357. }
  358. }
  359. /**
  360. * @param array $data
  361. * @return array
  362. */
  363. public function getArticleList(array $data): array
  364. {
  365. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  366. $type_id = $data['type_id'];
  367. unset($data['type_id']);
  368. $user_id = $data['user_id'];
  369. unset($data['user_id']);
  370. $where = [];
  371. $status1 = [];
  372. if (isset($data['id']) && $data['id']) {
  373. array_push($where, ['article.id', '=', $data['id']]);
  374. }
  375. if (isset($data['title']) && $data['title']) {
  376. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  377. }
  378. if (isset($data['category_name']) && $data['category_name']) {
  379. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  380. }
  381. if (isset($data['catid']) && $data['catid']) {
  382. array_push($where, ['article.catid', '=', $data['catid']]);
  383. }
  384. if (isset($data['author']) && $data['author']) {
  385. array_push($where, ['article.author', '=', $data['author']]);
  386. }
  387. if (isset($data['islink']) && $data['islink'] !== "") {
  388. array_push($where, ['article.islink', '=', $data['islink']]);
  389. }
  390. if (isset($data['status']) && $data['status'] !== "") {
  391. array_push($where, ['article.status', '=', $data['status']]);
  392. }
  393. if (isset($data['status1'])) {
  394. $status1 = json_decode(($data['status1']));
  395. }
  396. //不是管理员展示个人数据;
  397. if ($type_id != 10000) {
  398. $where[] = ['article.admin_user_id', '=', $user_id];
  399. }
  400. $startTime = microtime(true);
  401. $rep = Article::query()
  402. // 预加载相关关联
  403. ->with([
  404. 'category' => function ($query) {
  405. $query->select('id', 'name');
  406. },
  407. 'websiteCategory' => function ($query) {
  408. $query->select('website_id', 'category_id', 'alias');
  409. },'user' => function ($query) {
  410. $query->select('id', 'nickname');
  411. }
  412. ])
  413. // 构建where条件
  414. ->when(isset($data['id']) && $data['id'], function ($query) use ($data) {
  415. $query->where('article.id', '=', $data['id']);
  416. })
  417. ->when(isset($data['title']) && $data['title'], function ($query) use ($data) {
  418. $query->where('article.title', 'like', '%' . $data['title'] . '%');
  419. })
  420. ->when(isset($data['category_name']) && $data['category_name'], function ($query) use ($data) {
  421. // 使用子查询替代左连接进行模糊搜索
  422. $query->whereHas('category', function ($subQuery) use ($data) {
  423. $subQuery->where('name', 'like', '%' . $data['category_name'] . '%');
  424. });
  425. })
  426. ->when(isset($data['catid']) && $data['catid'], function ($query) use ($data) {
  427. $query->where('article.catid', '=', $data['catid']);
  428. })
  429. ->when(isset($data['author']) && $data['author'], function ($query) use ($data) {
  430. $query->where('article.author', '=', $data['author']);
  431. })
  432. ->when(isset($data['islink']) && $data['islink'] !== "", function ($query) use ($data) {
  433. $query->where('article.islink', '=', $data['islink']);
  434. })
  435. ->when(isset($data['status']) && $data['status'] !== "", function ($query) use ($data) {
  436. $query->where('article.status', '=', $data['status']);
  437. })
  438. ->when(isset($data['status1']) && $data['status1'], function ($query) use ($data) {
  439. // 安全地处理JSON字符串
  440. $status1 = is_array($data['status1']) ? $data['status1'] : json_decode($data['status1'], true) ?? [];
  441. if (!empty($status1)) {
  442. $query->whereIn('article.status', $status1);
  443. }
  444. })
  445. ->select('article.*')
  446. // 非管理员限制
  447. ->when($type_id != 10000, function ($query) use ($user_id) {
  448. // 非管理员只能看自己的文章,同时把 article_ignore 的 c_show_time 一起查出来
  449. $query->where('article.admin_user_id', $user_id)
  450. ->leftJoin('article_ignore', function ($join) {
  451. // 关联条件:article.id = article_ignore.article_id 且 article.web_site_id = article_ignore.website_id
  452. $join->on('article_ignore.article_id', '=', 'article.id')
  453. ->whereColumn('article_ignore.website_id', 'article.web_site_id');
  454. })
  455. ->addSelect('article_ignore.article_id','article_ignore.c_show_time'); // 用 addSelect 追加字段,避免覆盖原有 select
  456. })
  457. // 基础条件
  458. ->whereNotIn('article.status', [404])
  459. // 排序和分页
  460. ->orderBy('article.updated_at', 'desc')
  461. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  462. // 获取结果并格式化
  463. $data = [
  464. 'rows' => $rep->items(),
  465. 'count' => $rep->total(),
  466. ];
  467. // 执行查询
  468. $endTime = microtime(true);
  469. $executionTime = ($endTime - $startTime) * 1000;
  470. echo "查询执行时间: {$executionTime}ms\n";
  471. return Result::success($data);
  472. }
  473. /**
  474. * @param array $data
  475. * @return array
  476. */
  477. public function addArticle(array $data): array
  478. {
  479. var_dump($data, '----------12-----------1');
  480. // ------c_show_time********add***1****
  481. $is_collect = $data['is_collect'] ?? 0;
  482. $user_type = $data['user_type'];
  483. unset($data['is_collect']);
  484. unset($data['user_type']);
  485. // ------c_show_time********add***1****
  486. unset($data['nav_add_pool_id']);
  487. // unset($data['commend_id']);
  488. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  489. Db::beginTransaction();
  490. try {
  491. //处理投票
  492. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  493. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  494. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  495. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  496. unset($data['is_survey']);
  497. unset($data['survey_name']);
  498. unset($data['suvey_array']);
  499. // unset($data['website_id']);
  500. // unset($data['web_site_id']);
  501. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  502. if ($data['hits'] == '') {
  503. $data['hits'] = 0;
  504. }
  505. if ($data['is_original'] == '') {
  506. $data['is_original'] = 0;
  507. }
  508. if ($data['status'] == '') {
  509. $data['status'] = 0;
  510. }
  511. $articleData = $data;
  512. unset($articleData['content']);
  513. //自动处理缩略图、关键字、描述
  514. if ($articleData['imgurl'] == '') {
  515. //如果没有图,设置level=0
  516. $levelArr = json_decode($articleData['level'], true);
  517. var_dump($levelArr, '----------levelArr-----------1');
  518. //content中提取图片第一个图,正则提取
  519. // -------采集器相关优化-----
  520. // 优化正则表达式,仅匹配 src 属性值,避免匹配到多余内容
  521. if ($is_collect == 1) {
  522. $reg = '/<img.*?src=[\'"]?((?!.*\.gif)[^\'" >]+)[\'"]?.*?>/i';
  523. } else {
  524. $reg = '/<img.*?src=[\'"]?([^\'" >]+)[\'"]?.*?>/i';
  525. }
  526. // -------采集器相关优化-----
  527. preg_match_all($reg, $data['content'], $matches);
  528. if (isset($matches[1][0])) {
  529. //截取varchar240
  530. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  531. //如果有图,设置level=3
  532. if (!in_array(3, $levelArr)) {
  533. $levelArr[] = 3;
  534. }
  535. $articleData['level'] = json_encode($levelArr);
  536. } else {
  537. if (!in_array(0, $levelArr)) {
  538. $levelArr[] = 0;
  539. }
  540. $articleData['level'] = json_encode($levelArr);
  541. }
  542. }
  543. var_dump($articleData['level'], '----------$articleData[level]----------1');
  544. if ($articleData['keyword'] == '') {
  545. //提取标题+内容中的关键词
  546. $articleData['keyword'] = $data['title'];
  547. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  548. Jieba::init(); // 初始化 jieba-php
  549. Finalseg::init();
  550. $segList = Jieba::cut($articleData['keyword']);
  551. $segList1 = array_slice($segList, 0, 8);
  552. $articleData['keyword'] = implode(',', $segList1);
  553. }
  554. if ($articleData['introduce'] == '') {
  555. //提取内容中的描述
  556. $content = $data['content'];
  557. // 去除 <style> 和 <script> 标签及其内容
  558. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  559. // 去除所有 HTML 标签
  560. $content = strip_tags($content);
  561. // 去除 HTML 实体
  562. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  563. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  564. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  565. // 去除多余空白
  566. $content = preg_replace('/\s+/u', '', $content);
  567. // 截取 100 个字符
  568. $articleData['introduce'] = mb_substr($content, 0, 100);
  569. }
  570. if ($articleData['status'] == 0) {
  571. $this->sendMessage([
  572. 'talk_type' => 100,
  573. 'title' => $articleData['title'],
  574. 'content' => '提交了审核',
  575. 'messageType' => 2,
  576. ]);
  577. }
  578. if(!empty($data['fujian'])){
  579. $articleData['fujian'] = $data['fujian'];
  580. }
  581. $id = Article::insertGetId($articleData);
  582. if (!$id) {
  583. throw new \Exception('文章插入失败');
  584. }
  585. $articleDataContent = [
  586. 'article_id' => $id,
  587. 'content' => $data['content'],
  588. ];
  589. // 采集器中的文章内容,在添加时,去掉div标签
  590. if ($is_collect == 1) {
  591. // 采集来的文章,content中可能包含div标签,需要先移除
  592. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  593. $article_data = preg_replace($pattern, '', $data['content']);
  594. $$articleDataContent['content'] = $article_data;
  595. }
  596. $contentInsertId = ArticleData::insertGetId($articleDataContent);
  597. if (!$contentInsertId) {
  598. throw new \Exception('文章内容插入失败');
  599. }
  600. // ------c_show_time********add***2****
  601. // 直接使用当前系统时间,不再强制添加8小时
  602. $now = date('Y-m-d H:i:s');
  603. if ($user_type == 10000 || $is_collect == 1) {
  604. // 管理员添加文章时,核心站c端显示时间就是创建时间;非核心站c端显示时间就是此创建时间往后推二十分钟;
  605. // 非管理员添加文章时,不做操作只有在审核通过时获取c端显示时间
  606. if (!isset($data['catid'])) {
  607. throw new \Exception('缺少必要字段:catid');
  608. }
  609. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  610. $web = WebsiteCategory::where('category_id', $data['catid'])
  611. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  612. ->select(
  613. 'website_id',
  614. 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')
  615. )
  616. ->get();
  617. // $id = 225; -----测试开启
  618. // 采集来的文章,错开时间在两小时之内发布
  619. if ($user_type == 10000 && $is_collect == 1) {
  620. $web_num = $web->where('is_core', '!=', 2)->count();
  621. $waiting_interval = 10;
  622. if ($web_num > 12) {
  623. // 若网站数量大于12个,则每个网站间隔时间取均值
  624. // 防止除数为 0,虽然这里 $web_num 是 count 结果不会为 0,但做健壮性检查
  625. $waiting_interval = 120 / max(1, $web_num);
  626. }
  627. $time = 0;
  628. } else {
  629. // 非核心站与核心站----显示时间-----间隔
  630. $time = 20;
  631. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  632. $waiting_interval = 5;
  633. }
  634. // 将 Hyperf\Database\Model\Collection 转换为数组
  635. $webArray = $web->toArray();
  636. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $id, $waiting_interval, $is_collect) {
  637. // 检查 $item 对象是否有 is_core 属性
  638. if (!isset($item['is_core'])) {
  639. throw new \Exception('$item 对象缺少 is_core 属性');
  640. }
  641. // 当 is_core 为 2 时,则表示此网站不存在
  642. if ($item['is_core'] == 2) {
  643. return null;
  644. }
  645. if ($is_collect == 1) {
  646. // 采集来的文章,错开时间在两小时之内发布
  647. // $time = 0;
  648. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  649. $time += $waiting_interval;
  650. } else if ($item['is_core'] == 1) {
  651. // 当 is_core 为 1 时,则表示此网站是核心站
  652. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  653. } else {
  654. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  655. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  656. if ($item['is_core'] == 0) {
  657. $time += $waiting_interval;
  658. }
  659. }
  660. return [
  661. 'article_id' => $id,
  662. 'website_id' => $item['website_id'],
  663. 'c_show_time' => $c_show_time,
  664. // 'is_core' => $item['is_core'],
  665. // 'time' => $time
  666. ];
  667. }, array_keys($webArray), $webArray)));
  668. // Db::commit();
  669. // return Result::success($article_ignore);
  670. if (!empty($article_ignore)) {
  671. $article_ignores = ArticleIgnore::insert($article_ignore);
  672. if (!$article_ignores) {
  673. throw new \Exception('c端展示时间插入失败');
  674. }
  675. }
  676. }
  677. // ------c_show_time********add***2****
  678. //处理投票
  679. if ($is_survey == 1) {
  680. //生成年月日时分秒+8位随机数
  681. $uuid = date('YmdHis') . rand(10000000, 99999999);
  682. var_dump($suvey_array, 'suvey_array________');
  683. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  684. var_dump($suveys_array, '---------------------1');
  685. var_dump($suvey_array, '---------------------2');
  686. $suvey_data = [];
  687. foreach ($suveys_array as $key => $value) {
  688. if ($value == '') {
  689. continue;
  690. }
  691. if (is_array($value)) {
  692. $suvey_data[] = [
  693. 'sur_id' => $uuid,
  694. 'art_id' => $id,
  695. 'website_id' => $website_id ?? 2,
  696. 'survey_name' => $survey_name,
  697. 'choice_name' => $value[1],
  698. 'is_other' => 1,
  699. 'other_id' => 0,
  700. 'results' => 0,
  701. ];
  702. } else {
  703. $suvey_data[] = [
  704. 'sur_id' => $uuid,
  705. 'art_id' => $id,
  706. 'website_id' => $website_id ?? 2,
  707. 'survey_name' => $survey_name,
  708. 'choice_name' => $value,
  709. 'is_other' => 0,
  710. 'other_id' => 0,
  711. 'results' => 0,
  712. ];
  713. }
  714. if (empty($suvey_data)) {
  715. throw new \Exception("投票数据为空");
  716. }
  717. }
  718. $result = ArticleSurvey::insert($suvey_data);
  719. if (!$result) {
  720. throw new \Exception("投票失败,ArticleSurvey插入失败");
  721. }
  722. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  723. if (!$result) {
  724. throw new \Exception("投票失败,更新主表失败");
  725. }
  726. }
  727. Db::commit();
  728. return Result::success(['id' => $id]);
  729. } catch (\Throwable $ex) {
  730. Db::rollBack();
  731. var_dump($ex->getMessage());
  732. return Result::error("创建失败", 0);
  733. }
  734. }
  735. /**
  736. * @param array $data
  737. * @return array
  738. */
  739. public function delArticle(array $data): array
  740. {
  741. // ------c_show_time********del*******
  742. Db::beginTransaction();
  743. try {
  744. $article = Article::where(['id' => $data['id']])->delete();
  745. // 若文章删除失败,抛出异常,后续 SQL 语句不会执行
  746. if (!$article) {
  747. throw new \Exception("删除失败,文章删除失败");
  748. }
  749. //survey投票删除
  750. ArticleSurvey::where(['art_id' => $data['id']])->delete(); // 修正类名大小写
  751. $articleIgnore = ArticleIgnore::where(['article_id' => $data['id']])->delete();
  752. $article_data = ArticleData::where(['article_id' => $data['id']])->delete();
  753. // 若文章详情删除失败,抛出异常
  754. if (!$article_data) {
  755. throw new \Exception("删除失败,文章详情删除失败");
  756. }
  757. Db::commit(); // 所有操作成功,提交事务
  758. } catch (\Throwable $ex) {
  759. Db::rollBack();
  760. var_dump($ex->getMessage());
  761. return Result::error("删除失败: " . $ex->getMessage(), 0);
  762. }
  763. // ------c_show_time********del*******
  764. if (!$article) {
  765. return Result::error("删除失败");
  766. }
  767. return Result::success($article);
  768. }
  769. /**
  770. * @param array $data
  771. * @return array
  772. */
  773. public function updateArticle(array $data): array
  774. {
  775. var_dump($data, '----------12-----------1');
  776. Db::beginTransaction();
  777. // ------c_show_time********up*******
  778. $user_type = isset($data['user_type']) ? $data['user_type'] : 0;
  779. // 无论是否改变了c端显示时间或者栏目,都需要将未屏蔽的网站显示时间删除记录
  780. // 若是存在交集,则进行修改,若无,则合并(此表中的记录应该包含被屏蔽网站及涉及所有网站的展示时间)
  781. $web = WebsiteCategory::where('category_id', $data['catid'])
  782. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  783. ->select(
  784. 'website_id',
  785. 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')
  786. )
  787. ->get();
  788. // 根据错误信息,问题在于 $web 可能是一个包含对象的集合,不能直接用于 whereNotIn 方法
  789. // 先从 $web 集合中提取 website_id 字段的值,再进行删除操作
  790. $websiteIds = $web->pluck('website_id')->toArray();
  791. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  792. if ($user_type == 0) {
  793. throw new \Exception("用户类型不能为空");
  794. }
  795. if ($user_type == 10000) {
  796. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  797. $web = WebsiteCategory::where('category_id', $data['catid'])
  798. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  799. ->select(
  800. 'website_id',
  801. 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')
  802. )
  803. ->get();
  804. // 非核心站与核心站----显示时间-----间隔
  805. $time = 20;
  806. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  807. $waiting_interval = 5;
  808. $webArray = $web->toArray();
  809. if (empty($webArray)) {
  810. throw new \Exception('网站分类不存在');
  811. }
  812. // 直接使用当前系统时间,不再强制添加8小时
  813. $now = date('Y-m-d H:i:s');
  814. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  815. // 检查 $item 对象是否有 is_core 属性
  816. if (!isset($item['is_core'])) {
  817. throw new \Exception('$item 对象缺少 is_core 属性');
  818. }
  819. // 当 is_core 为 2 时,则表示此网站不存在
  820. if ($item['is_core'] == 2) {
  821. return null;
  822. } else if ($item['is_core'] == 1) {
  823. // 当 is_core 为 1 时,则表示此网站是核心站
  824. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  825. } else {
  826. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  827. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  828. if ($item['is_core'] == 0) {
  829. $time += $waiting_interval;
  830. }
  831. }
  832. return [
  833. 'article_id' => $data['id'],
  834. 'website_id' => $item['website_id'],
  835. 'c_show_time' => $c_show_time,
  836. ];
  837. }, array_keys($webArray), $webArray)));
  838. if (!empty($article_ignore)) {
  839. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  840. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  841. $article_ignores = ArticleIgnore::upsert(
  842. $article_ignore,
  843. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  844. ['c_show_time'] // 需要更新的字段
  845. );
  846. if (!$article_ignores) {
  847. throw new \Exception('c端展示时间插入失败');
  848. }
  849. }
  850. // Db::commit();
  851. // return Result::success($article_ignore);
  852. }
  853. // ------c_show_time********up*******
  854. unset($data['user_type']);
  855. // unset($data['web_site_id']);
  856. unset($data['nav_add_pool_id']);
  857. try {
  858. //处理投票
  859. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  860. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  861. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  862. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  863. unset($data['is_survey']);
  864. unset($data['survey_name']);
  865. unset($data['suvey_array']);
  866. unset($data['website_id']);
  867. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  868. if ($data['hits'] == '') {
  869. $data['hits'] = 0;
  870. }
  871. if ($data['is_original'] == '') {
  872. $data['is_original'] = 0;
  873. }
  874. if ($data['status'] == '') {
  875. $data['status'] = 0;
  876. }
  877. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  878. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  879. $articleData = $data;
  880. unset($articleData['content']);
  881. unset($articleData['status_name']);
  882. unset($articleData['name']);
  883. unset($articleData['content']);
  884. unset($articleData['pid_arr']);
  885. unset($articleData['pid']);
  886. //自动处理缩略图、关键字、描述
  887. if ($articleData['imgurl'] == '') {
  888. //如果没有图,设置level=0
  889. $levelArr = json_decode($articleData['level'], true);
  890. var_dump($levelArr, '----------levelArr-----------1');
  891. //content中提取图片第一个图,正则提取
  892. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  893. preg_match_all($reg, $data['content'], $matches);
  894. if (isset($matches[1][0])) {
  895. //截取varchar240
  896. // 截取到第一个<
  897. $articleData['imgurl'] = $matches[1][0];
  898. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  899. $pos = strpos($articleData['imgurl'], '"');
  900. if ($pos !== false) {
  901. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  902. }
  903. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  904. //如果有图,设置level=3
  905. if (!in_array(3, $levelArr)) {
  906. $levelArr[] = 3;
  907. }
  908. $articleData['level'] = json_encode($levelArr);
  909. } else {
  910. if (!in_array(0, $levelArr)) {
  911. $levelArr[] = 0;
  912. }
  913. $articleData['level'] = json_encode($levelArr);
  914. }
  915. }
  916. var_dump($articleData['level'], '----------$articleData[level]----------1');
  917. if ($articleData['keyword'] == '') {
  918. //提取标题+内容中的关键词
  919. $articleData['keyword'] = $data['title'];
  920. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  921. Jieba::init(); // 初始化 jieba-php
  922. Finalseg::init();
  923. $segList = Jieba::cut($articleData['keyword']);
  924. $segList1 = array_slice($segList, 0, 8);
  925. $articleData['keyword'] = implode(',', $segList1);
  926. }
  927. if ($articleData['introduce'] == '') {
  928. //提取内容中的描述
  929. $content = $data['content'];
  930. // 去除 <style> 和 <script> 标签及其内容
  931. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  932. // 去除所有 HTML 标签
  933. $content = strip_tags($content);
  934. // 去除 HTML 实体
  935. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  936. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  937. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  938. // 去除多余空白
  939. $content = preg_replace('/\s+/u', '', $content);
  940. // 截取 100 个字符
  941. $articleData['introduce'] = mb_substr($content, 0, 100);
  942. }
  943. if ($articleData['status'] == 0) {
  944. $this->sendMessage([
  945. 'talk_type' => 100,
  946. 'title' => $articleData['title'],
  947. 'content' => '提交了审核',
  948. 'messageType' => 2,
  949. ]);
  950. }
  951. if(!empty($data['fujian'])){
  952. $articleData['fujian'] = $data['fujian'];
  953. }
  954. $id = Article::where(['id' => $data['id']])->update($articleData);
  955. // $articleDataContent = [
  956. // 'content' => $data['content'],
  957. // ];
  958. // 采集来的文章,content中可能包含div标签,需要先移除
  959. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  960. $article_data = preg_replace($pattern, '', $data['content']);
  961. $articleDataContent['content'] = $article_data;
  962. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  963. //处理投票
  964. $id = $data['id'];
  965. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  966. var_dump($suvey_array, 'suvey_array________delete');
  967. //处理投票
  968. if ($is_survey == 1) {
  969. //生成年月日时分秒+8位随机数
  970. $uuid = date('YmdHis') . rand(10000000, 99999999);
  971. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  972. var_dump($suveys_array, '---------------------1');
  973. $suvey_data = [];
  974. if (is_array($suveys_array)) {
  975. foreach ($suveys_array as $key => $value) {
  976. if ($value == '') {
  977. continue;
  978. }
  979. if (is_array($value)) {
  980. $suvey_data[] = [
  981. 'sur_id' => $uuid,
  982. 'art_id' => $id,
  983. 'website_id' => $website_id ?? 2,
  984. 'survey_name' => $survey_name,
  985. 'choice_name' => $value[1],
  986. 'is_other' => 1,
  987. 'other_id' => 0,
  988. 'results' => 0,
  989. ];
  990. } else {
  991. $suvey_data[] = [
  992. 'sur_id' => $uuid,
  993. 'art_id' => $id,
  994. 'website_id' => $website_id ?? 2,
  995. 'survey_name' => $survey_name,
  996. 'choice_name' => $value,
  997. 'is_other' => 0,
  998. 'other_id' => 0,
  999. 'results' => 0,
  1000. ];
  1001. }
  1002. if (empty($suvey_data)) {
  1003. throw new \Exception("投票数据为空");
  1004. }
  1005. }
  1006. }
  1007. $result = ArticleSurvey::insert($suvey_data);
  1008. if (!$result) {
  1009. throw new \Exception("投票失败");
  1010. }
  1011. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  1012. if (!$result) {
  1013. throw new \Exception("投票失败");
  1014. }
  1015. } else {
  1016. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  1017. }
  1018. Db::commit();
  1019. return Result::success([]);
  1020. } catch (\Throwable $ex) {
  1021. Db::rollBack();
  1022. var_dump($ex->getMessage());
  1023. return Result::error("更新失败" . $ex->getMessage(), 0);
  1024. }
  1025. }
  1026. /**
  1027. * 更新资讯状态
  1028. * @param array $data
  1029. * @return array
  1030. */
  1031. public function upArticleStatus(array $data): array
  1032. {
  1033. $articleData = Article::where(['id' => $data['id']])->first();
  1034. //发送10次
  1035. // for ($i = 0; $i < 10; $i++) {
  1036. // $this->sendMessage([
  1037. // 'talk_type' => 100,
  1038. // 'title' => $i . $articleData['title'],
  1039. // 'content' => '审核通过',
  1040. // 'messageType' => 2,
  1041. // 'user_id' => $articleData['admin_user_id'],
  1042. // ]);
  1043. // }
  1044. // var_dump($data['status'], 'status');
  1045. // return Result::success();
  1046. if ($data['status'] == 1) {
  1047. $this->sendMessage([
  1048. 'talk_type' => 101,
  1049. 'title' => $articleData['title'],
  1050. 'content' => '审核通过',
  1051. 'messageType' => 2,
  1052. 'user_id' => $articleData['admin_user_id'],
  1053. ]);
  1054. }
  1055. if ($data['status'] == 2) {
  1056. $this->sendMessage([
  1057. 'talk_type' => 101,
  1058. 'title' => $articleData['title'],
  1059. 'content' => '审核拒绝',
  1060. 'messageType' => 2,
  1061. 'user_id' => $articleData['admin_user_id'],
  1062. ]);
  1063. }
  1064. if ($data['status'] == 0) {
  1065. $this->sendMessage([
  1066. 'talk_type' => 100,
  1067. 'title' => $articleData['title'],
  1068. 'content' => '提交了审核',
  1069. 'messageType' => 2,
  1070. ]);
  1071. }
  1072. $result = Article::where(['id' => $data['id']])->update($data);
  1073. // ------c_show_time********up_status*******
  1074. // 若是审核通过 则更新c_show_time
  1075. if ($data['status'] == 1) {
  1076. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  1077. $web = Article::where('article.id', $data['id'])
  1078. ->leftJoin('website_category', 'article.catid', 'website_category.category_id')
  1079. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  1080. ->select(
  1081. 'website_id',
  1082. 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')
  1083. )
  1084. ->get();
  1085. // 非核心站与核心站----显示时间-----间隔
  1086. $time = 20;
  1087. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  1088. $waiting_interval = 5;
  1089. $webArray = $web->toArray();
  1090. if (empty($webArray)) {
  1091. throw new \Exception('网站分类不存在');
  1092. }
  1093. // 直接使用当前系统时间,不再强制添加8小时
  1094. $now = date('Y-m-d H:i:s');
  1095. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  1096. if (isset($data['ignore_ids'])) {
  1097. $ignore_website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  1098. if (in_array($item['website_id'], $ignore_website_ids)) {
  1099. $is_ignore = 1;
  1100. } else {
  1101. $is_ignore = 0;
  1102. }
  1103. return [
  1104. 'article_id' => $data['id'],
  1105. 'website_id' => $item['website_id'],
  1106. 'is_ignore' => $is_ignore,
  1107. ];
  1108. } else {
  1109. // 检查 $item 对象是否有 is_core 属性
  1110. if (!isset($item['is_core'])) {
  1111. throw new \Exception('$item 对象缺少 is_core 属性');
  1112. }
  1113. // 当 is_core 为 2 时,则表示此网站不存在
  1114. if ($item['is_core'] == 2) {
  1115. return null;
  1116. } else if ($item['is_core'] == 1) {
  1117. // 当 is_core 为 1 时,则表示此网站是核心站
  1118. $c_show_time = $now;
  1119. } else {
  1120. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  1121. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  1122. if ($item['is_core'] == 0) {
  1123. $time += $waiting_interval;
  1124. }
  1125. }
  1126. return [
  1127. 'article_id' => $data['id'],
  1128. 'website_id' => $item['website_id'],
  1129. 'c_show_time' => $c_show_time,
  1130. ];
  1131. }
  1132. }, array_keys($webArray), $webArray)));
  1133. if (!empty($article_ignore) && !isset($data['ignore_ids'])) {
  1134. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  1135. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  1136. $websiteIds = $web->pluck('website_id')->toArray();
  1137. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  1138. $article_ignores = ArticleIgnore::upsert(
  1139. $article_ignore,
  1140. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1141. ['c_show_time'] // 需要更新的字段
  1142. );
  1143. if (!$article_ignores) {
  1144. throw new \Exception('c端展示时间插入失败');
  1145. }
  1146. }
  1147. if (!empty($data['ignore_ids'])) {
  1148. // return Result::success($article_ignore);
  1149. // 从数据库中删除 article_id 为 $data['id'] 且 website_id 在 $website_ids 中的记录
  1150. if (!empty($article_ignore)) {
  1151. $article_ignores = ArticleIgnore::upsert(
  1152. $article_ignore,
  1153. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1154. ['is_ignore'] // 需要更新的字段
  1155. );
  1156. // if(!$article_ignores){
  1157. // throw new \Exception('屏蔽网站更新失败');
  1158. // }
  1159. }
  1160. }
  1161. }
  1162. // ------c_show_time********up_status*******
  1163. if ($result) {
  1164. return Result::success();
  1165. } else {
  1166. return Result::error("更新状态失败", 0);
  1167. }
  1168. }
  1169. /**
  1170. * 获取新闻详情
  1171. * @param array $data
  1172. * @return array
  1173. */
  1174. public function getArticleInfo(array $data): array
  1175. {
  1176. $where = [
  1177. 'article.id' => $data['id'],
  1178. // 'article.status' => 1,
  1179. ];
  1180. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  1181. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  1182. $info = $result;
  1183. // var_dump($info, 'info');
  1184. $info['survey_array'] = $articleSurvey;
  1185. if ($result) {
  1186. return Result::success($info);
  1187. } else {
  1188. return Result::error("查询失败", 0);
  1189. }
  1190. }
  1191. /**
  1192. * 获取头条新闻
  1193. * @param array $data
  1194. * @return array
  1195. */
  1196. public function getWebsiteArticlett(array $data): array
  1197. {
  1198. $website_id = $data['website_id'];
  1199. $website = Website::where('id', $data['website_id'])->first();
  1200. if (empty($website)) {
  1201. return Result::error("网站不存在", 0);
  1202. }
  1203. $categorys = $this->processArticlePro($website_id);
  1204. $catiall = $categorys['catiall'];
  1205. $categoryIds = $categorys['categoryIds'];
  1206. $where = [
  1207. 'status' => 1
  1208. ];
  1209. // $website_column = $website['column'];
  1210. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1211. $website_column = json_decode($website['website_column_arr_id'], true);
  1212. }
  1213. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1214. // return Result::success($diff_pid_categoryIds);
  1215. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1216. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1217. }
  1218. // $website_id = $data['website_id'];
  1219. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  1220. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  1221. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  1222. switch ($data['level']) {
  1223. case 1:
  1224. case 2:
  1225. case 3:
  1226. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  1227. $query = Article::where($where)
  1228. ->where('level', 'like', '%' . $data['level'] . '%')
  1229. ->orderBy('updated_at', 'desc');
  1230. break;
  1231. case 4: //最新资讯
  1232. $query = Article::where($where)->orderBy('updated_at', 'desc');
  1233. break;
  1234. case 5: //资讯推荐
  1235. $query = Article::where($where)
  1236. ->where('updated_at', '>', $month);
  1237. break;
  1238. case 7: //资讯分类
  1239. if (isset($data['id']) && !empty($data['id'])) {
  1240. $keyword = Article::where('id', $data['id'])->value('keyword');
  1241. $keywordArray = explode(',', $keyword);
  1242. $whereL7 = [];
  1243. foreach ($keywordArray as $k => $v) {
  1244. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1245. }
  1246. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  1247. break;
  1248. } else {
  1249. return Result::error("请输入资讯ID", 0);
  1250. break;
  1251. }
  1252. default:
  1253. break;
  1254. }
  1255. // $whereL7 = [];
  1256. // if(isset($data['id']) && !empty($data['id'])){
  1257. // $keyword = Article::where('id', $data['id'])->value('keyword');
  1258. // $keywordArray = explode(',', $keyword);
  1259. // foreach ($keywordArray as $k => $v) {
  1260. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1261. // }
  1262. // }
  1263. // $query = Article::where($where)
  1264. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  1265. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  1266. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  1267. // }
  1268. // if($data['level'] == 7){
  1269. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  1270. // }
  1271. // if($data['level'] == 4){
  1272. // $query = $query->inRandomOrder()
  1273. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  1274. // }
  1275. // if($data['level'] == 5){
  1276. // $query = $query->orderBy('updated_at','desc');
  1277. // }
  1278. // });
  1279. if ($data['textnum'] > 0) {
  1280. $query = clone $query;
  1281. $result['text'] = $query
  1282. ->whereIn('catid', $categoryIds)
  1283. ->leftJoinSub(function ($query) use ($website_id) {
  1284. $query->from('article_ignore')
  1285. ->where('website_id', $website_id);
  1286. }, 'article_ignore', function ($join) {
  1287. $join->on('article_ignore.article_id', '=', 'article.id');
  1288. })
  1289. ->where(function ($query) {
  1290. $query->whereNull('article_ignore.article_id')
  1291. ->orWhere(function ($subQuery) {
  1292. $subQuery->whereNotNull('article_ignore.article_id')
  1293. ->where('article_ignore.is_ignore', 0)
  1294. ->where(function ($subSubQuery) {
  1295. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1296. ->orWhereNull('article_ignore.c_show_time');
  1297. });
  1298. });
  1299. })
  1300. // ->where(function ($query) use ($website_id) {
  1301. // $query->whereNull('article_ignore.article_id')
  1302. // ->orWhere('article_ignore.website_id', '!=', $website_id);
  1303. // })
  1304. ->select(
  1305. 'article.id',
  1306. 'article.title',
  1307. 'article.author',
  1308. 'article.updated_at',
  1309. 'article.introduce',
  1310. 'article.islink',
  1311. 'article.linkurl',
  1312. 'article.copyfrom',
  1313. 'article.cat_arr_id',
  1314. 'article.catid',
  1315. 'article.level',
  1316. // 'article_ignore.is_ignore',
  1317. // 'article_ignore.c_show_time',
  1318. )
  1319. ->offset($data['placeid'])
  1320. ->limit($data['textnum'])
  1321. ->get()->all();
  1322. foreach ($result['text'] as $k => $v) {
  1323. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1324. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  1325. }
  1326. }
  1327. if ($data['imgnum'] > 0) {
  1328. $query = clone $query;
  1329. if ($data['textnum'] == 0) {
  1330. $query = $query->leftJoinSub(function ($query) use ($website_id) {
  1331. $query->from('article_ignore')
  1332. ->where('website_id', $website_id);
  1333. }, 'article_ignore', function ($join) {
  1334. $join->on('article_ignore.article_id', '=', 'article.id');
  1335. })
  1336. ->where(function ($query) {
  1337. $query->whereNull('article_ignore.article_id')
  1338. ->orWhere(function ($subQuery) {
  1339. $subQuery->whereNotNull('article_ignore.article_id')
  1340. ->where('article_ignore.is_ignore', 0)
  1341. ->where(function ($subSubQuery) {
  1342. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1343. ->orWhereNull('article_ignore.c_show_time');
  1344. });
  1345. });
  1346. });
  1347. }
  1348. $result['img'] = $query
  1349. ->whereIn('catid', $categoryIds)
  1350. ->where('article.imgurl', '!=', '')
  1351. ->select(
  1352. 'article.id',
  1353. 'article.title',
  1354. 'article.imgurl',
  1355. 'article.author',
  1356. 'article.updated_at',
  1357. 'article.introduce',
  1358. 'article.islink',
  1359. 'article.linkurl',
  1360. 'article.copyfrom',
  1361. 'article.cat_arr_id',
  1362. 'article.catid',
  1363. 'article.level',
  1364. // 'article_ignore.is_ignore',
  1365. // 'article_ignore.c_show_time',
  1366. )
  1367. ->offset($data['placeid'])
  1368. ->limit($data['imgnum'])
  1369. ->get()->all();
  1370. foreach ($result['img'] as $k => $v) {
  1371. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1372. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1373. }
  1374. }
  1375. if (empty($result)) {
  1376. return Result::error("暂无相关资讯", 0);
  1377. }
  1378. return Result::success($result);
  1379. }
  1380. /**
  1381. * 获取模块新闻
  1382. * @param array $data
  1383. * @return array
  1384. */
  1385. public function getWebsiteModelArticles(array $data): array
  1386. {
  1387. $catid = $data['catid'];
  1388. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1389. $category = $category->toArray();
  1390. if (!empty($category)) {
  1391. $where = [
  1392. 'status' => 1,
  1393. 'catid' => $catid,
  1394. ];
  1395. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1396. // 1:文字新闻;2:轮播图;3:图文;
  1397. // 级别:0:未分类
  1398. // 3:推荐图片
  1399. if ($data['level'] == 1) {
  1400. $data['level'] = 0;
  1401. }
  1402. $result = Article::where($where)
  1403. ->where(function ($query) use ($data) {
  1404. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1405. ->orWhereNull("level")
  1406. ->orWhereRaw("level = '[]'");
  1407. })
  1408. ->leftJoinSub(function ($query) use ($data) {
  1409. $query->from('article_ignore')
  1410. ->where('website_id', $data['website_id']);
  1411. }, 'article_ignore', function ($join) {
  1412. $join->on('article_ignore.article_id', '=', 'article.id');
  1413. })
  1414. ->where(function ($query) {
  1415. $query->whereNull('article_ignore.article_id')
  1416. ->orWhere(function ($subQuery) {
  1417. $subQuery->whereNotNull('article_ignore.article_id')
  1418. ->where('article_ignore.is_ignore', 0)
  1419. ->where(function ($subSubQuery) {
  1420. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1421. ->orWhereNull('article_ignore.c_show_time');
  1422. });
  1423. });
  1424. })
  1425. // ->where(function ($query) use ($data) {
  1426. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1427. // ->orWhereNull("ignore_ids");
  1428. // })
  1429. ->orderBy("updated_at", "desc")
  1430. ->offset($placeid)
  1431. ->limit($data['pagesize'])
  1432. ->get();
  1433. if (empty($result)) {
  1434. return Result::error("此栏目暂无相关新闻", 0);
  1435. }
  1436. } else {
  1437. return Result::error("此网站暂无此栏目", 0);
  1438. }
  1439. return Result::success($result);
  1440. }
  1441. /**
  1442. *获取新闻列表
  1443. * @param array $data
  1444. * @return array
  1445. */
  1446. public function getWebsiteArticleList(array $data): array
  1447. {
  1448. // return Result::success($data);
  1449. $where[] = ['status', '=', 1];
  1450. $website_id = $data['website_id'];
  1451. $website = Website::where('id', $data['website_id'])->first();
  1452. if (empty($website)) {
  1453. return Result::error("网站不存在", 0);
  1454. }
  1455. // $website_column = $website['column'];
  1456. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1457. $website_column = json_decode($website['website_column_arr_id'], true);
  1458. }
  1459. $categorys = $this->processArticlePro($website_id);
  1460. $cat_1st_arr = $categorys['cat_1st_arr'];
  1461. $catiall = $categorys['catiall'];
  1462. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1463. // return Result::success($diff_pid_categoryIds);
  1464. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1465. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1466. }
  1467. if (isset($data['catid']) && !empty($data['catid'])) {
  1468. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1469. if (empty($category)) {
  1470. return Result::error("此网站暂无此栏目", 0);
  1471. }
  1472. array_push($where, ['catid', '=', $data['catid']]);
  1473. }
  1474. // return Result::success($where);
  1475. $query = Article::where($where)
  1476. ->leftJoinSub(function ($query) use ($website_id) {
  1477. $query->from('article_ignore')
  1478. ->where('website_id', $website_id);
  1479. }, 'article_ignore', function ($join) {
  1480. $join->on('article_ignore.article_id', '=', 'article.id');
  1481. })
  1482. ->where(function ($query) {
  1483. $query->whereNull('article_ignore.article_id')
  1484. ->orWhere(function ($subQuery) {
  1485. $subQuery->whereNotNull('article_ignore.article_id')
  1486. ->where('article_ignore.is_ignore', 0)
  1487. ->where(function ($subSubQuery) {
  1488. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1489. ->orWhereNull('article_ignore.c_show_time');
  1490. });
  1491. });
  1492. })
  1493. ->select(
  1494. 'article.id',
  1495. 'article.title',
  1496. 'article.imgurl',
  1497. 'article.author',
  1498. 'article.updated_at',
  1499. 'article.introduce',
  1500. 'article.islink',
  1501. 'article.linkurl',
  1502. 'article.copyfrom',
  1503. 'article.cat_arr_id',
  1504. 'article.catid'
  1505. );
  1506. $count = $query->count();
  1507. $rep = $query->orderBy("updated_at", "desc")
  1508. ->offset(($data['page'] - 1) * $data['pageSize'])
  1509. ->limit($data['pageSize'])
  1510. ->get()->all();
  1511. $categorys = $this->processArticlePro($website_id);
  1512. $cat_1st_arr = $categorys['cat_1st_arr'];
  1513. $catiall = $categorys['catiall'];
  1514. // $web['website_id'] = $data['website_id'];
  1515. foreach ($rep as $k => $v) {
  1516. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1517. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1518. }
  1519. // $rep = $this->processArticles($rep,$web);
  1520. $data = [
  1521. 'rows' => $rep,
  1522. 'count' => $count,
  1523. ];
  1524. if (empty($rep)) {
  1525. return Result::error("没有信息数据");
  1526. }
  1527. return Result::success($data);
  1528. }
  1529. /**
  1530. * 前端-获取新闻详情
  1531. * @param array $data
  1532. * @return array
  1533. */
  1534. public function selectWebsiteArticleInfo(array $data): array
  1535. {
  1536. $where = [
  1537. 'article.id' => $data['id'],
  1538. 'article.status' => 1,
  1539. ];
  1540. $result = Article::where($where)
  1541. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1542. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1543. // ->where(function ($query) use ($data) {
  1544. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1545. // ->orWhereNull("ignore_ids");
  1546. // })
  1547. ->leftJoinSub(function ($query) use ($data) {
  1548. $query->from('article_ignore')
  1549. ->where('website_id', $data['website_id']);
  1550. }, 'article_ignore', function ($join) {
  1551. $join->on('article_ignore.article_id', '=', 'article.id');
  1552. })
  1553. ->where(function ($query) {
  1554. $query->whereNull('article_ignore.article_id')
  1555. ->orWhere(function ($subQuery) {
  1556. $subQuery->whereNotNull('article_ignore.article_id')
  1557. ->where('article_ignore.is_ignore', 0)
  1558. ->where(function ($subSubQuery) {
  1559. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1560. ->orWhereNull('article_ignore.c_show_time');
  1561. });
  1562. });
  1563. })
  1564. ->select(
  1565. 'article.*',
  1566. 'article_data.content',
  1567. 'article_data.article_id',
  1568. 'article_extend.website_url',
  1569. 'article_extend.email',
  1570. 'article_extend.contacts',
  1571. 'article_extend.contacts_mobile',
  1572. 'article_extend.contacts_address',
  1573. 'article_extend.zip_code',
  1574. 'article_extend.enterprise_name'
  1575. )
  1576. ->first();
  1577. if (empty($result)) {
  1578. return Result::error("暂无此新闻!", 0);
  1579. }
  1580. if (!empty($result['publiced_at'])) {
  1581. $result['updated_at'] = $result['publiced_at'];
  1582. }
  1583. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1584. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1585. ->where('website_category.website_id', $data['website_id'])
  1586. ->where(['website_category.category_id' => $result['catid']])
  1587. ->first();
  1588. if (empty($category)) {
  1589. return Result::error("查询失败", 0);
  1590. }
  1591. //手动推荐文章
  1592. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1593. if (empty($commend_ids)) {
  1594. $commendArticle = [];
  1595. } else {
  1596. //去除不存在的文章ID
  1597. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1598. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1599. ->leftJoinSub(function ($query) use ($data) {
  1600. $query->from('article_ignore')
  1601. ->where('website_id', $data['website_id']);
  1602. }, 'article_ignore', function ($join) {
  1603. $join->on('article_ignore.article_id', '=', 'article.id');
  1604. })
  1605. ->where(function ($query) {
  1606. $query->whereNull('article_ignore.article_id')
  1607. ->orWhere(function ($subQuery) {
  1608. $subQuery->whereNotNull('article_ignore.article_id')
  1609. ->where('article_ignore.is_ignore', 0)
  1610. ->where(function ($subSubQuery) {
  1611. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1612. ->orWhereNull('article_ignore.c_show_time');
  1613. });
  1614. });
  1615. })
  1616. ->where('article.status', 1)
  1617. ->where('website_category.website_id', $data['website_id'])
  1618. ->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')
  1619. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1620. // ->orderBy('article.updated_at', 'desc')
  1621. ->limit(5)
  1622. ->get();
  1623. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1624. foreach ($commendArticle as $k => $v) {
  1625. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1626. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1627. $cat_arr_id = array_unique($cat_arr_id);
  1628. // 从website_category取出alias_pinyin
  1629. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1630. ->whereIn('category_id', $cat_arr_id)
  1631. ->pluck('alias_pinyin', 'category_id')
  1632. ->toArray();
  1633. // 将cat_arr_id的json转成路径/隔开
  1634. $path_parts = [];
  1635. foreach ($cat_arr_id as $cat_id) {
  1636. if (isset($cat_arr[$cat_id])) {
  1637. $path_parts[] = $cat_arr[$cat_id];
  1638. }
  1639. }
  1640. $v->alias_pinyin = implode('/', $path_parts);
  1641. } else {
  1642. $v->alias_pinyin = '';
  1643. }
  1644. }
  1645. }
  1646. $result['category_id'] = $category['category_id'];
  1647. $result['cat_name'] = $category['alias'];
  1648. $result['website_name'] = $category['website_name'] ?? "";
  1649. $result['suffix'] = $category['suffix'] ?? "";
  1650. $result['commendArticle'] = $commendArticle;
  1651. $result['commend_ids'] = $commend_ids;
  1652. return Result::success($result);
  1653. }
  1654. /**
  1655. * 前端-获取网站调查问卷
  1656. * @param array $data
  1657. * @return array
  1658. */
  1659. public function getWebsiteSurvey(array $data): array
  1660. {
  1661. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1662. $website = Website::where('id', $data['website_id'])->first();
  1663. if (empty($website)) {
  1664. return Result::error("暂无此网站", 0);
  1665. }
  1666. }
  1667. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1668. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1669. if (empty($article)) {
  1670. return Result::error("暂无此文章", 0);
  1671. }
  1672. // return Result::error($data,0);
  1673. $where['art_id'] = $data['art_id'];
  1674. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1675. } else {
  1676. $survey = Article::where(function ($query) {
  1677. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1678. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1679. })
  1680. ->where('status', 1)
  1681. ->where('is_survey', 1)
  1682. ->select('survey_id')
  1683. ->orderBy('updated_at', 'desc')
  1684. ->first();
  1685. if (empty($survey)) {
  1686. return Result::error("暂无调查问卷", 0);
  1687. }
  1688. $where['sur_id'] = $survey['survey_id'];
  1689. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1690. }
  1691. // return Result::success($where);
  1692. $result = ArticleSurvey::where($where)
  1693. ->where(function ($query) {
  1694. $query->where('is_other', 0)
  1695. ->orWhere(function ($subQuery) {
  1696. $subQuery->where('is_other', 1)
  1697. ->where('other_id', 0);
  1698. });
  1699. })
  1700. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1701. ->select('article_survey.*', 'article.survey_type')
  1702. ->get()->all();
  1703. if (empty($result)) {
  1704. return Result::error("此文章暂无调查问卷", 0);
  1705. }
  1706. return Result::success($result);
  1707. }
  1708. /**
  1709. * 前端-添加网站调查问卷选项
  1710. * @param array $data
  1711. * @return array
  1712. */
  1713. public function addWebsiteSurveyOption(array $data): array
  1714. {
  1715. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1716. $website = Website::where('id', $data['website_id'])->first();
  1717. if (empty($website)) {
  1718. return Result::error("暂无此网站", 0);
  1719. }
  1720. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1721. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1722. if (empty($survey)) {
  1723. return Result::error("此调查问卷不可添加选项", 0);
  1724. }
  1725. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1726. $choice = [
  1727. 'art_id' => $survey['art_id'],
  1728. 'website_id' => $data['website_id'],
  1729. 'survey_name' => $survey['survey_name'],
  1730. 'choice_name' => $data['choice_name'],
  1731. 'sur_id' => $survey['sur_id'],
  1732. 'is_other' => 1,
  1733. 'other_id' => $survey['id'],
  1734. ];
  1735. $result = ArticleSurvey::insertGetId($choice);
  1736. if (empty($result)) {
  1737. return Result::error("添加失败", 0);
  1738. }
  1739. return Result::success($result);
  1740. }
  1741. }
  1742. return Result::error("添加失败", 0);
  1743. }
  1744. return Result::error("添加失败", 0);
  1745. }
  1746. /**
  1747. * 前端-调查问卷投票
  1748. * @param array $data
  1749. * @return array
  1750. */
  1751. public function addWebsiteSurveyVote(array $data): array
  1752. {
  1753. // return Result::success($data);
  1754. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1755. $website = Website::where('id', $data['website_id'])->first();
  1756. if (empty($website)) {
  1757. return Result::error("暂无此网站", 0);
  1758. }
  1759. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1760. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1761. // return Result::success($survey);
  1762. if (empty($is_survey)) {
  1763. return Result::error("此调查问卷不存在", 0);
  1764. }
  1765. // return Result::success($survey);
  1766. // 调查问卷类型
  1767. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1768. //多选 若是json型则转化成数组类型
  1769. if (strpos($data['choice_id'], '[') === 0) {
  1770. $data['choice_id'] = json_decode($data['choice_id'], true);
  1771. } else {
  1772. // 单选 也转换成数组
  1773. $data['choice_id'] = [$data['choice_id']];
  1774. }
  1775. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1776. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1777. // ->where('website_id',$data['website_id'])
  1778. ->where('is_other', 1)
  1779. ->where('other_id', 0)
  1780. ->first();
  1781. if (!empty($other)) {
  1782. return Result::error("请选择已有的选项!", 0);
  1783. }
  1784. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1785. // ->where('website_id',$data['website_id'])
  1786. ->where('is_other', 1)
  1787. ->where('other_id', '!=', 0)
  1788. ->first();
  1789. // return Result::success($choice['other']);
  1790. $choice_id = $data['choice_id'];
  1791. if (!empty($choice['other'])) {
  1792. // array_push($data['choice_id'],$choice['other']['other_id']);
  1793. if (!empty($choice_id)) {
  1794. $key = array_search($choice['other']['id'], $choice_id);
  1795. if ($key !== false) {
  1796. unset($choice_id[$key]);
  1797. $choice_id = array_values($choice_id);
  1798. }
  1799. array_push($choice_id, $choice['other']['other_id']);
  1800. } else {
  1801. $choice_id[0] = $choice['other']['other_id'];
  1802. }
  1803. array_push($data['choice_id'], $choice['other']['other_id']);
  1804. }
  1805. // return Result::success($data);
  1806. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1807. // ->where('website_id',$data['website_id'])
  1808. ->increment('results', 1);
  1809. if (empty($choice)) {
  1810. return Result::error("请选择已有的选项!", 0);
  1811. }
  1812. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1813. // ->where('website_id',$data['website_id'])
  1814. ->where('other_id', 0)
  1815. ->get();
  1816. $survey['choice'] = $choice_id;
  1817. return Result::success($survey);
  1818. }
  1819. return Result::error("参数必填!");
  1820. }
  1821. return Result::error("此调查问卷不存在", 0);
  1822. }
  1823. return Result::error("参数必填!");
  1824. }
  1825. /**
  1826. * 后端-获取网站调查问卷列表
  1827. * @param array $data
  1828. * @return array
  1829. */
  1830. public function getSurveyList(array $data): array
  1831. {
  1832. $where = [];
  1833. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1834. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1835. }
  1836. $survey_type = isset($data['survey_type']) && $data['survey_type'] !== '' ? $data['survey_type'] : null;
  1837. if (!empty($where)) {
  1838. // 修复:先关联 article 再按 survey_type 过滤,避免查不到数据
  1839. $query = ArticleSurvey::select(
  1840. 'art_id as id',
  1841. Db::raw('MAX(id) as surid'),
  1842. Db::raw('MAX(survey_name) as survey_name'),
  1843. Db::raw('MAX(sur_id) as survey_id')
  1844. )
  1845. ->groupBy('art_id')
  1846. ->where($where)
  1847. ->when(!is_null($survey_type), function ($q) use ($survey_type) {
  1848. $q->whereIn('art_id', function ($sub) use ($survey_type) {
  1849. $sub->select('id')
  1850. ->from('article')
  1851. ->where('survey_type', $survey_type);
  1852. });
  1853. })
  1854. ->with(['article' => function ($query) {
  1855. $query->select('id', 'survey_type','created_at','updated_at','created_at');
  1856. }]);
  1857. ;
  1858. }else{
  1859. $query = ArticleSurvey::select(
  1860. 'art_id as id',
  1861. Db::raw('MAX(id) as surid'),
  1862. Db::raw('MAX(survey_name) as survey_name'),
  1863. Db::raw('MAX(sur_id) as survey_id'),
  1864. )
  1865. ->groupBy('art_id')
  1866. ->when(!is_null($survey_type), function ($q) use ($survey_type) {
  1867. $q->whereIn('art_id', function ($sub) use ($survey_type) {
  1868. $sub->select('id')
  1869. ->from('article')
  1870. ->where('survey_type', $survey_type);
  1871. });
  1872. })
  1873. ->with(['article' => function ($query) {
  1874. $query->select('id', 'survey_type','created_at','updated_at','created_at');
  1875. }]);
  1876. }
  1877. $count = $query->get()->count();
  1878. // 简单写法:直接统计分组后的 art_id 数量
  1879. $survey = $query->orderBy('id', 'desc')
  1880. ->limit($data['pageSize'])
  1881. ->offset(($data['page'] - 1) * $data['pageSize'])
  1882. ->get();
  1883. if (empty($survey->toArray())) {
  1884. return Result::error("暂无调查问卷!", 0);
  1885. }
  1886. $survey = array_map(function ($item) {
  1887. if (isset($item['article'])) {
  1888. $item['survey_type'] = $item['article']['survey_type'];
  1889. $item['created_at'] = $item['article']['created_at'];
  1890. $item['updated_at'] = $item['article']['updated_at'];
  1891. } else {
  1892. // 处理article为null的情况,设置默认值
  1893. $item['survey_type'] = null;
  1894. $item['created_at'] = null;
  1895. $item['updated_at'] = null;
  1896. }
  1897. unset($item['article']);
  1898. return $item;
  1899. }, $survey->toArray());
  1900. $result = [
  1901. 'rows' => $survey,
  1902. 'count' => $count,
  1903. ];
  1904. return Result::success($result);
  1905. }
  1906. /**
  1907. * 后端-获取网站调查问卷详情
  1908. * @param array $data
  1909. * @return array
  1910. */
  1911. public function getSurveyInfo(array $data): array
  1912. {
  1913. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1914. $where = ['sur_id' => $data['sur_id']];
  1915. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1916. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1917. ->select('article_survey.*', 'article.survey_type')
  1918. ->get()->all();
  1919. if (empty($choose)) {
  1920. return Result::error("此调查问卷不存在", 0);
  1921. }
  1922. $resultsArray = array_column($choose, 'results');
  1923. $total = array_sum($resultsArray);
  1924. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1925. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1926. // $total = 0;
  1927. if (!empty($other)) {
  1928. $total = $total + $other['results'];
  1929. $other['choice_name'] = '(其他)';
  1930. if (!empty($others)) {
  1931. $other['hasChildren'] = true;
  1932. // array_push($other,['hasChildren','=',true]);
  1933. $other['children'] = $others;
  1934. $other_choices = [$other->toArray()];
  1935. $mer_choice = array_merge($choose, $other_choices);
  1936. $value_choice = array_values($mer_choice);
  1937. } else {
  1938. // return Result::error('1111');
  1939. $other_choices = [$other->toArray()];
  1940. $other_choices = array_merge($choose, $other_choices);
  1941. $value_choice = array_values($other_choices);
  1942. // return Result::success($result);
  1943. }
  1944. } else {
  1945. $value_choice = $choose;
  1946. }
  1947. $result = [
  1948. 'choose' => $value_choice,
  1949. 'total' => $total,
  1950. ];
  1951. }
  1952. return Result::success($result);
  1953. }
  1954. /**
  1955. * 前端-搜索新闻列表
  1956. * @param array $data
  1957. * @return array
  1958. */
  1959. public function selectWebsiteArticle(array $data): array
  1960. {
  1961. $website = Website::where('id', $data['website_id'])->first();
  1962. if (empty($website)) {
  1963. return Result::error("网站不存在", 0);
  1964. }
  1965. // $website_column = $website['column'];
  1966. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1967. $website_column = json_decode($website['website_column_arr_id'], true);
  1968. }
  1969. $website_id = $data['website_id'];
  1970. $categorys = $this->processArticlePro($website_id);
  1971. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1972. // return Result::success($diff_pid_categoryIds);
  1973. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1974. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1975. }
  1976. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1977. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1978. $catiall = $categorys['catiall'];
  1979. $categoryIds = $categorys['categoryIds'];
  1980. // return Result::success($categoryIds);
  1981. $query = Article::where('status', 1)
  1982. ->whereIn('catid', $categoryIds)
  1983. ->leftJoinSub(function ($query) use ($website_id) {
  1984. $query->from('article_ignore')
  1985. ->where('website_id', $website_id);
  1986. }, 'article_ignore', function ($join) {
  1987. $join->on('article_ignore.article_id', '=', 'article.id');
  1988. })
  1989. ->where(function ($query) {
  1990. $query->whereNull('article_ignore.article_id')
  1991. ->orWhere(function ($subQuery) {
  1992. $subQuery->whereNotNull('article_ignore.article_id')
  1993. ->where('article_ignore.is_ignore', 0)
  1994. ->where(function ($subSubQuery) {
  1995. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1996. ->orWhereNull('article_ignore.c_show_time');
  1997. });
  1998. });
  1999. });
  2000. // ->get()->all();
  2001. // return Result::success($query);
  2002. if (isset($data['cityid']) && !empty($data['cityid'])) {
  2003. $query->whereRaw("JSON_CONTAINS(article.city_arr_id, '" . intval($data['cityid']) . "')");
  2004. }
  2005. if (isset($data['department_id']) && !empty($data['department_id'])) {
  2006. $query->whereRaw("JSON_CONTAINS(article.department_arr_id, '" . intval($data['department_id']) . "')");
  2007. }
  2008. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2009. $query->where('article.title', 'like', '%' . $data['keyword'] . '%');
  2010. }
  2011. // 计算总数
  2012. $count = $query->count();
  2013. // return Result::success($count);
  2014. // 分页查询
  2015. $articles = $query
  2016. ->select(
  2017. 'article.id',
  2018. 'article.title',
  2019. 'article.imgurl',
  2020. 'article.author',
  2021. 'article.updated_at',
  2022. 'article.introduce',
  2023. 'article.islink',
  2024. 'article.linkurl',
  2025. 'article.copyfrom',
  2026. 'article.cat_arr_id',
  2027. 'article.catid',
  2028. 'article.department_arr_id',
  2029. 'article.city_arr_id',
  2030. // 'article_ignore.c_show_time',
  2031. // 'article_ignore.is_ignore'
  2032. )
  2033. ->orderBy("updated_at", "desc")
  2034. ->offset(($data['page'] - 1) * $data['pageSize'])
  2035. ->limit($data['pageSize'])
  2036. ->get();
  2037. // return Result::success($articles);
  2038. foreach ($articles as $k => $v) {
  2039. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  2040. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2041. }
  2042. if (empty($articles)) {
  2043. return Result::error("没有符合条件的资讯数据");
  2044. }
  2045. $result = [
  2046. 'rows' => $articles,
  2047. 'count' => $count,
  2048. ];
  2049. return Result::success($result);
  2050. }
  2051. /**
  2052. * 模块新闻加强版
  2053. * @param array $data
  2054. * @return array
  2055. */
  2056. public function getWebsiteCatidArticle(array $data): array
  2057. {
  2058. $where = [
  2059. 'website_category.category_id' => $data['catid'],
  2060. 'website_category.website_id' => $data['website_id'],
  2061. ];
  2062. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  2063. $child_catnum = $data['child_catnum'] ?? 1;
  2064. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  2065. $childCategoryIds = array_column($category['child'], 'category_id');
  2066. if (empty($childCategoryIds)) {
  2067. return Result::error("暂无子栏目", 0);
  2068. }
  2069. $imgArticles = [];
  2070. $textArticles = [];
  2071. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  2072. // 初始化子分类图片新闻和文字新闻数组
  2073. // 查询所有子级栏目的图文新闻
  2074. $imgArticles = Article::where('catid', $childCategoryIds[0])
  2075. ->where(function ($query) use ($data) {
  2076. $query->where(function ($subQuery) use ($data) {
  2077. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2078. })->orWhereNull("ignore_ids");
  2079. })
  2080. ->where('status', 1)
  2081. ->where('imgurl', '!=', '')
  2082. ->select('*')
  2083. ->orderBy('updated_at', 'desc')
  2084. ->limit($data['child_imgnum'])
  2085. ->get();
  2086. }
  2087. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  2088. // 查询所有子级栏目的文字新闻
  2089. $textArticles = Article::where('catid', $childCategoryIds[0])
  2090. ->where('status', 1)
  2091. ->where(function ($query) use ($data) {
  2092. $query->where(function ($subQuery) use ($data) {
  2093. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2094. })->orWhereNull("ignore_ids");
  2095. })
  2096. ->select('*')
  2097. ->orderBy('updated_at', 'desc')
  2098. ->limit($data['child_textnum'])
  2099. ->get();
  2100. }
  2101. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  2102. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  2103. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  2104. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  2105. return $child;
  2106. }, $category['child']);
  2107. }
  2108. // }
  2109. if (isset($data['img_num']) && !empty($data['img_num'])) {
  2110. $category['img'] = WebsiteCategory::where($where)
  2111. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2112. ->where('article.status', 1)
  2113. ->where('article.imgurl', '!=', '')
  2114. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2115. ->orderBy('article.updated_at', 'desc')
  2116. ->limit($data['img_num'])
  2117. ->get();
  2118. }
  2119. if (isset($data['text_num']) && !empty($data['text_num'])) {
  2120. $category['text'] = WebsiteCategory::where($where)
  2121. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2122. ->where('article.status', 1)
  2123. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2124. ->orderBy('article.updated_at', 'desc')
  2125. ->limit($data['text_num'])
  2126. ->get();
  2127. }
  2128. // $category = $category->get();
  2129. if (empty($category)) {
  2130. return Result::error("查询失败", 0);
  2131. }
  2132. return Result::success($category);
  2133. }
  2134. /**
  2135. * 模块新闻加强plus版
  2136. * @param array $data
  2137. * @return array
  2138. */
  2139. public function getWebsiteAllArticle(array $data): array
  2140. {
  2141. // return Result::success($data);
  2142. $time1 = microtime(true);
  2143. $wetbsite_id = $data['website_id'] ?? 2;
  2144. $data = json_decode($data['id'], true);
  2145. $website = Website::where('id', $wetbsite_id)->first();
  2146. if (empty($website)) {
  2147. return Result::error("网站不存在", 0);
  2148. }
  2149. // return Result::success($website);
  2150. $website_column = $website['website_column_arr_id'] ?? '[]';
  2151. $website_column = json_decode($website_column, true);
  2152. $categorys = $this->processArticlePro($wetbsite_id);
  2153. $cat_1st_arr = $categorys['cat_1st_arr'];
  2154. $catiall = $categorys['catiall'];
  2155. // return Result::success($catiall);
  2156. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2157. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2158. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2159. }
  2160. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  2161. // return Result::success($categorys);
  2162. $parent_category = array_column($data, 'parent');
  2163. $parent_cat = [];
  2164. $child_category = array_column($data, 'child');
  2165. if (!empty($parent_category)) {
  2166. foreach ($parent_category as $key => $value) {
  2167. $arr = array_map('intval', explode(',', $value));
  2168. $parent_cat[$key] = $arr[0] ?? 0;
  2169. $parent_category = $arr[0] ?? 0;
  2170. $article_imgnum = $arr[1] ?? 0;
  2171. $article_textnum = $arr[2] ?? 0;
  2172. if ($parent_category != 0) {
  2173. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2174. // return Result::success($category_arr);
  2175. if ($article_imgnum != 0) {
  2176. $img_article = Article::whereIn('catid', $category_arr)
  2177. ->where('status', 1)
  2178. ->where('imgurl', '!=', '')
  2179. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2180. $query->from('article_ignore')
  2181. ->where('website_id', $wetbsite_id);
  2182. }, 'article_ignore', function ($join) {
  2183. $join->on('article_ignore.article_id', '=', 'article.id');
  2184. })
  2185. ->where(function ($query) {
  2186. $query->whereNull('article_ignore.article_id')
  2187. ->orWhere(function ($subQuery) {
  2188. $subQuery->whereNotNull('article_ignore.article_id')
  2189. ->where('article_ignore.is_ignore', 0)
  2190. ->where(function ($subSubQuery) {
  2191. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2192. ->orWhereNull('article_ignore.c_show_time');
  2193. });
  2194. });
  2195. })
  2196. ->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')
  2197. ->orderBy('updated_at', 'desc')
  2198. ->limit($article_imgnum)
  2199. ->get()->all();
  2200. foreach ($img_article as $k => $v) {
  2201. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2202. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2203. }
  2204. } else {
  2205. $img_article = [];
  2206. }
  2207. if ($article_textnum != 0) {
  2208. $text_article = Article::whereIn('catid', $category_arr)
  2209. ->where('status', 1)
  2210. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2211. $query->from('article_ignore')
  2212. ->where('website_id', $wetbsite_id);
  2213. }, 'article_ignore', function ($join) {
  2214. $join->on('article_ignore.article_id', '=', 'article.id');
  2215. })
  2216. ->where(function ($query) {
  2217. $query->whereNull('article_ignore.article_id')
  2218. ->orWhere(function ($subQuery) {
  2219. $subQuery->whereNotNull('article_ignore.article_id')
  2220. ->where('article_ignore.is_ignore', 0)
  2221. ->where(function ($subSubQuery) {
  2222. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2223. ->orWhereNull('article_ignore.c_show_time');
  2224. });
  2225. });
  2226. })
  2227. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2228. ->orderBy('updated_at', 'desc')
  2229. ->limit($article_textnum)
  2230. ->get()->all();
  2231. foreach ($text_article as $k => $v) {
  2232. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2233. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2234. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2235. }
  2236. } else {
  2237. $text_article = [];
  2238. }
  2239. $catiall[$parent_category]['imgnum'] = $img_article;
  2240. $catiall[$parent_category]['textnum'] = $text_article;
  2241. $parent[$key] = $catiall[$parent_category];
  2242. } else {
  2243. $parent[$key] = '';
  2244. }
  2245. }
  2246. }
  2247. if (!empty($child_category)) {
  2248. foreach ($child_category as $key => $value) {
  2249. $arr = array_map('intval', explode(',', $value));
  2250. $parent_category = $parent_cat[$key];
  2251. $child_category = $arr[0] ?? 0;
  2252. $article_imgnum = $arr[1] ?? 0;
  2253. $article_textnum = $arr[2] ?? 0;
  2254. if ($child_category != 0) {
  2255. $all_childcat = $cat_1st_arr[$parent_category];
  2256. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  2257. // 从 $websiteInfoIndexed 中获取对应的数据
  2258. $info = $websiteInfoIndexed[$v];
  2259. // 返回一个包含所需信息的数组
  2260. return [
  2261. 'alias' => $info->alias,
  2262. 'category_id' => $info->category_id,
  2263. 'aLIas_pinyin' => $info->aLIas_pinyin,
  2264. 'pid' => $info->pid,
  2265. 'type' => $info->type,
  2266. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  2267. 'pinyin' => $info->pinyin,
  2268. ];
  2269. }, $all_childcat);
  2270. if ($article_imgnum != 0) {
  2271. $img_article = Article::where('catid', $child_category)
  2272. ->where('status', 1)
  2273. ->where('imgurl', '!=', '')
  2274. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2275. $query->from('article_ignore')
  2276. ->where('website_id', $wetbsite_id);
  2277. }, 'article_ignore', function ($join) {
  2278. $join->on('article_ignore.article_id', '=', 'article.id');
  2279. })
  2280. ->where(function ($query) {
  2281. $query->whereNull('article_ignore.article_id')
  2282. ->orWhere(function ($subQuery) {
  2283. $subQuery->whereNotNull('article_ignore.article_id')
  2284. ->where('article_ignore.is_ignore', 0)
  2285. ->where(function ($subSubQuery) {
  2286. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2287. ->orWhereNull('article_ignore.c_show_time');
  2288. });
  2289. });
  2290. })
  2291. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2292. ->orderBy('updated_at', 'desc')
  2293. ->limit($article_imgnum)
  2294. ->get()->all();
  2295. foreach ($img_article as $k => $v) {
  2296. // var_dump($v);
  2297. // var_dump($k);
  2298. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2299. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2300. }
  2301. } else {
  2302. $img_article = [];
  2303. }
  2304. if ($article_textnum != 0) {
  2305. $text_article = Article::where('catid', $child_category)
  2306. ->where('status', 1)
  2307. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2308. $query->from('article_ignore')
  2309. ->where('website_id', $wetbsite_id);
  2310. }, 'article_ignore', function ($join) {
  2311. $join->on('article_ignore.article_id', '=', 'article.id');
  2312. })
  2313. ->where(function ($query) {
  2314. $query->whereNull('article_ignore.article_id')
  2315. ->orWhere(function ($subQuery) {
  2316. $subQuery->whereNotNull('article_ignore.article_id')
  2317. ->where('article_ignore.is_ignore', 0)
  2318. ->where(function ($subSubQuery) {
  2319. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2320. ->orWhereNull('article_ignore.c_show_time');
  2321. });
  2322. });
  2323. })
  2324. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2325. ->orderBy('updated_at', 'desc')
  2326. ->limit($article_textnum)
  2327. ->get()->all();
  2328. foreach ($text_article as $k => $v) {
  2329. // var_dump($v);
  2330. // var_dump($k);
  2331. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2332. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2333. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2334. }
  2335. } else {
  2336. $text_article = [];
  2337. }
  2338. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  2339. $catiall[$child_category]['imgnum'] = $img_article;
  2340. $catiall[$child_category]['textnum'] = $text_article;
  2341. $child[$key] = $catiall[$child_category];
  2342. // var_dump($pids);
  2343. } else {
  2344. $child[$key] = '';
  2345. }
  2346. }
  2347. }
  2348. foreach ($parent as $key => $value) {
  2349. $result[$key] = $value;
  2350. if (!empty($child[$key])) {
  2351. // var_dump($child[$key]);
  2352. $result[$key]['child'] = $child[$key];
  2353. // $value[$key]['child'] = $child[$key];
  2354. } else {
  2355. $result[$key]['child'] = [
  2356. "alias" => null,
  2357. "category_id" => null,
  2358. "type" => null,
  2359. "pinyin" => null,
  2360. "all_childcat" => [],
  2361. "imgnum" => [],
  2362. "textnum" => []
  2363. ];
  2364. }
  2365. }
  2366. return Result::success($result);
  2367. }
  2368. /**
  2369. * 辅助方法:获取文章列表
  2370. */
  2371. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  2372. {
  2373. sleep(1);
  2374. $query = Article::where('article.status', 1)
  2375. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  2376. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  2377. ->where(function ($query) use ($website) {
  2378. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  2379. })
  2380. ->leftJoin('website_category', function ($join) use ($website) {
  2381. $join->on('article.catid', '=', 'website_category.category_id')
  2382. ->where('website_category.website_id', '=', $website['website_id']);
  2383. })
  2384. ->select(
  2385. 'article.id',
  2386. 'article.title',
  2387. 'article.imgurl',
  2388. 'article.author',
  2389. 'article.updated_at',
  2390. 'article.introduce',
  2391. 'article.islink',
  2392. 'article.linkurl',
  2393. 'article.copyfrom',
  2394. 'article.cat_arr_id',
  2395. 'article.catid',
  2396. 'website_category.alias as category_name'
  2397. )
  2398. ->orderBy('updated_at', 'desc')
  2399. ->limit($limit);
  2400. // 如果是图片文章,添加图片URL条件
  2401. if ($isImageArticle) {
  2402. $query->where('imgurl', '!=', '');
  2403. } else {
  2404. // 文字文章不需要imgurl字段
  2405. $query->addSelect('article.introduce');
  2406. }
  2407. $articles = $query->get();
  2408. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  2409. }
  2410. /**
  2411. * 乡村网-获取特殊新闻模块
  2412. * @param array $data
  2413. * @return array
  2414. */
  2415. public function getWebsiteArticles(array $data): array
  2416. {
  2417. $website_id = $data['website_id'];
  2418. $website = Website::where('id', $website_id)->first();
  2419. if (empty($website)) {
  2420. return Result::error("网站不存在", 0);
  2421. }
  2422. // return Result::success($website);
  2423. $website_column = $website['website_column_arr_id'] ?? '[]';
  2424. $website_column = json_decode($website_column, true);
  2425. $catids = json_decode($data['id'], true);
  2426. $parent_category = array_column($catids, 'parent');
  2427. if (!empty($parent_category) && is_array($parent_category)) {
  2428. $categorys = $this->processArticlePro($website_id);
  2429. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2430. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2431. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2432. }
  2433. $catiall = $categorys['catiall'];
  2434. $cat_1st_arr = $categorys['cat_1st_arr'];
  2435. // return Result::success($categorys);
  2436. foreach ($parent_category as $key => $value) {
  2437. $arr = array_map('intval', explode(',', $value));
  2438. $parent_category = $arr[0] ?? 0;
  2439. $article_imgnum = $arr[1] ?? 0;
  2440. $article_textnum = $arr[2] ?? 0;
  2441. if ($parent_category != 0) {
  2442. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2443. // return Result::success($category_arr);
  2444. if ($article_imgnum != 0) {
  2445. $img_article = Article::whereIn('article.catid', $category_arr)
  2446. ->where('article.status', 1)
  2447. ->where('article.imgurl', '!=', '')
  2448. ->leftJoinSub(function ($query) use ($website_id) {
  2449. $query->from('article_ignore')
  2450. ->where('website_id', $website_id);
  2451. }, 'article_ignore', function ($join) {
  2452. $join->on('article_ignore.article_id', '=', 'article.id');
  2453. })
  2454. ->where(function ($query) {
  2455. $query->whereNull('article_ignore.article_id')
  2456. ->orWhere(function ($subQuery) {
  2457. $subQuery->whereNotNull('article_ignore.article_id')
  2458. ->where('article_ignore.is_ignore', 0)
  2459. ->where(function ($subSubQuery) {
  2460. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2461. ->orWhereNull('article_ignore.c_show_time');
  2462. });
  2463. });
  2464. })
  2465. ->select(
  2466. 'article.id',
  2467. 'article.title',
  2468. 'article.imgurl',
  2469. 'article.author',
  2470. 'article.updated_at',
  2471. 'article.introduce',
  2472. 'article.islink',
  2473. 'article.linkurl',
  2474. 'article.copyfrom',
  2475. 'article.cat_arr_id',
  2476. 'article.catid as category_id'
  2477. )
  2478. ->orderBy('updated_at', 'desc')
  2479. ->limit($article_imgnum)
  2480. ->get()->all();
  2481. foreach ($img_article as $k => $v) {
  2482. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2483. // return Result::success($v);
  2484. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2485. }
  2486. } else {
  2487. $img_article = [];
  2488. }
  2489. if ($article_textnum != 0) {
  2490. $text_article = Article::whereIn('article.catid', $category_arr)
  2491. ->where('article.status', 1)
  2492. ->leftJoinSub(function ($query) use ($website_id) {
  2493. $query->from('article_ignore')
  2494. ->where('website_id', $website_id);
  2495. }, 'article_ignore', function ($join) {
  2496. $join->on('article_ignore.article_id', '=', 'article.id');
  2497. })
  2498. ->where(function ($query) {
  2499. $query->whereNull('article_ignore.article_id')
  2500. ->orWhere(function ($subQuery) {
  2501. $subQuery->whereNotNull('article_ignore.article_id')
  2502. ->where('article_ignore.is_ignore', 0)
  2503. ->where(function ($subSubQuery) {
  2504. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2505. ->orWhereNull('article_ignore.c_show_time');
  2506. });
  2507. });
  2508. })
  2509. ->select(
  2510. 'article.id',
  2511. 'article.title',
  2512. 'article.author',
  2513. 'article.updated_at',
  2514. 'article.introduce',
  2515. 'article.islink',
  2516. 'article.linkurl',
  2517. 'article.copyfrom',
  2518. 'article.cat_arr_id',
  2519. 'article.catid as category_id'
  2520. )
  2521. ->orderBy('updated_at', 'desc')
  2522. ->limit($article_textnum)
  2523. ->get()->all();
  2524. foreach ($text_article as $k => $v) {
  2525. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2526. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2527. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2528. }
  2529. } else {
  2530. $text_article = [];
  2531. }
  2532. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2533. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2534. $parent[$key] = $catiall[$parent_category];
  2535. } else {
  2536. $parent[$key] = [];
  2537. }
  2538. }
  2539. }
  2540. return Result::success($parent);
  2541. }
  2542. // 封装处理商品的路由问题
  2543. function processGoods($goods, $data)
  2544. {
  2545. return $goods->map(function ($good) use ($data) {
  2546. $catid = $good->catid ?? 0;
  2547. // $pinyin = '';
  2548. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2549. if (!empty($category->pid) && $category->pid != 0) {
  2550. $level = json_decode($category->category_arr_id, true);
  2551. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2552. ->whereIn('category_id', $level)
  2553. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2554. ->get(['aLIas_pinyin'])
  2555. ->pluck('aLIas_pinyin')
  2556. ->implode('/');
  2557. } else {
  2558. $pinyin = $category->aLIas_pinyin ?? '';
  2559. }
  2560. if (isset($good->city_id) && !empty($good->city_id)) {
  2561. $city = District::where('id', $good->city_id)->first(['name']);
  2562. $good->city_name = $city->name ?? '';
  2563. }
  2564. // 解析imgurl JSON并取第一条数据
  2565. $imgUrls = json_decode($good->imgurl, true);
  2566. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2567. $good->pinyin = $pinyin;
  2568. return $good;
  2569. });
  2570. }
  2571. /**
  2572. * 获取商城首页-根据栏目id
  2573. * @param array $data
  2574. * @return array
  2575. * */
  2576. function getWebsiteCatidshop(array $data): array
  2577. {
  2578. $input['catid'] = $data['catid'];
  2579. $input['website_id'] = $data['website_id'];
  2580. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2581. $result = array_map(function ($item) use ($input) {
  2582. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2583. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2584. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2585. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2586. if (empty($category) || $category->type != 2) {
  2587. return Result::error("暂无此栏目", 0);
  2588. } else {
  2589. $website['website_id'] = $input['website_id'];
  2590. $goods = Good::where('good.status', 2)
  2591. ->where('good.website_id', $website['website_id'])
  2592. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2593. ->select(
  2594. 'good.id',
  2595. 'good.name',
  2596. 'good.imgurl',
  2597. 'good.description',
  2598. 'good.updated_at',
  2599. 'good.catid',
  2600. 'good.type_id',
  2601. 'good.price',
  2602. 'good.com',
  2603. 'good.level',
  2604. 'good.unit'
  2605. )
  2606. ->orderBy('updated_at', 'desc')
  2607. ->offset($goodStart)
  2608. ->limit($goodNum);
  2609. $all_goods = $goods->get();
  2610. $all_goods = $this->processGoods($all_goods, $website);
  2611. }
  2612. return $all_goods ?? [];
  2613. }
  2614. }, $data);
  2615. return Result::success($result);
  2616. }
  2617. /**
  2618. * 获取商品模块
  2619. * @param array $data
  2620. * @return array
  2621. * */
  2622. public function getWebsiteshop(array $data): array
  2623. {
  2624. $input['id'] = $data['id'];
  2625. $input['website_id'] = $data['website_id'];
  2626. $catid = $data['catid'];
  2627. $data = json_decode($input['id'] ?? '', true) ?? [];
  2628. $result['goods'] = array_map(function ($item) use ($input) {
  2629. // 检查parent元素是否存在且不是undefined
  2630. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2631. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2632. $website = $input['website_id'];
  2633. $query = Good::where('good.status', 2)
  2634. ->where('good.website_id', $website);
  2635. switch ($Levelid) {
  2636. case 1:
  2637. case 2:
  2638. case 3:
  2639. $goods = $query->where(function ($q) use ($Levelid) {
  2640. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2641. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2642. });
  2643. break;
  2644. case 4:
  2645. $goods = $query;
  2646. break;
  2647. case 5:
  2648. $goods = $query->where('type_id', 1);
  2649. break;
  2650. case 6:
  2651. $goods = $query->where('type_id', 2);
  2652. break;
  2653. default:
  2654. return [];
  2655. }
  2656. $all_goods = $goods
  2657. ->select(
  2658. 'good.id',
  2659. 'good.name',
  2660. 'good.imgurl',
  2661. 'good.description',
  2662. 'good.updated_at',
  2663. 'good.catid',
  2664. 'good.type_id',
  2665. 'good.price',
  2666. 'good.level',
  2667. 'good.website_id'
  2668. )
  2669. ->orderBy('updated_at', 'desc')
  2670. ->offset($goodStart)
  2671. ->limit($goodNum)
  2672. ->get();
  2673. $web['website_id'] = $website;
  2674. $all_goods = $this->processGoods($all_goods, $web);
  2675. }
  2676. return $all_goods;
  2677. }, $data);
  2678. $website = $input['website_id'];
  2679. $result['article'] = Article::where(function ($query) use ($website) {
  2680. $query->where(function ($subQuery) use ($website) {
  2681. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2682. })->orWhereNull("ignore_ids");
  2683. })
  2684. ->where('catid', $catid)
  2685. ->where('article.status', 1)
  2686. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2687. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2688. ->orderBy('article.updated_at', 'desc')
  2689. ->first();
  2690. return Result::success($result);
  2691. }
  2692. /**
  2693. * 获取商品分类
  2694. * @param array $data
  2695. * @return array
  2696. * */
  2697. public function getWebsiteshopCat(array $data): array
  2698. {
  2699. $website = $data['website_id'];
  2700. $category = WebsiteCategory::where('website_id', $website)
  2701. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2702. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2703. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2704. ->orderBy('sort')
  2705. ->get();
  2706. $cat = $category->map(function ($item) use ($website) {
  2707. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2708. $pid = $item->pid ?? 0;
  2709. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2710. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2711. ->where('website_id', $website)
  2712. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2713. ->get(['aLIas_pinyin'])
  2714. ->pluck('aLIas_pinyin')
  2715. ->implode('/');
  2716. } else {
  2717. $pinyin = $item->aLIas_pinyin ?? '';
  2718. }
  2719. $item->pinyin = $pinyin;
  2720. });
  2721. if (empty($category)) {
  2722. return Result::error("栏目查询失败", 0);
  2723. }
  2724. $cat_tree = Result::buildMenuTree($category);
  2725. $web['website_id'] = $website;
  2726. $goods = Good::where('website_id', $website)
  2727. ->where('status', 2)
  2728. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2729. ->latest('updated_at')
  2730. ->offset(($data['page'] - 1) * $data['pageSize'])
  2731. ->limit($data['pageSize'])
  2732. ->get();
  2733. if (!empty($goods)) {
  2734. if ($goods->count() > 1 && !empty($goods)) {
  2735. $goods = $this->processGoods($goods, $web);
  2736. }
  2737. } else {
  2738. $goods = [];
  2739. }
  2740. $result = [
  2741. 'category' => $cat_tree,
  2742. 'goods' => $goods,
  2743. ];
  2744. // $resul['goods'] = $goods;
  2745. if (empty($result)) {
  2746. return Result::error("查询失败", 0);
  2747. }
  2748. return Result::success($result);
  2749. }
  2750. /*
  2751. * 获取商品列表
  2752. * @param array $data
  2753. * @return array
  2754. * */
  2755. public function getWebsiteshopList(array $data): array
  2756. {
  2757. // return Result::success($data);
  2758. $where = [
  2759. 'status' => 2,
  2760. 'website_id' => $data['website_id'],
  2761. ];
  2762. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2763. // return Result::error("查询失败", 0);
  2764. // }
  2765. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2766. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2767. $data['catid'] = $category->category_id ?? 0;
  2768. }
  2769. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2770. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2771. }
  2772. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2773. array_push($where, ['type_id', $data['type_id']]);
  2774. }
  2775. $query = Good::where($where)
  2776. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2777. $query->where(function ($q) use ($data) {
  2778. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2779. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2780. });
  2781. })
  2782. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2783. $query->where(function ($q) use ($data) {
  2784. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2785. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2786. });
  2787. })
  2788. ->select(
  2789. 'good.id',
  2790. 'good.name',
  2791. 'good.imgurl',
  2792. 'good.description',
  2793. 'good.updated_at',
  2794. 'good.com',
  2795. 'good.catid',
  2796. 'good.type_id',
  2797. 'good.website_id',
  2798. 'good.cat_arr_id',
  2799. 'good.created_at',
  2800. 'good.city_id'
  2801. )
  2802. ->latest('updated_at');
  2803. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2804. $result['count'] = $query->clone()->count();
  2805. $result['goods'] = $this->processGoods(
  2806. $query->clone()
  2807. ->offset(($data['page'] - 1) * $data['pageSize'])
  2808. ->limit($data['pageSize'])
  2809. ->get(),
  2810. $data
  2811. );
  2812. } else {
  2813. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2814. // 获取 type_id 为 1 的数据
  2815. $result['type1'] = $this->processGoods(
  2816. $query->clone()
  2817. ->where('type_id', 1)
  2818. ->offset(($data['page'] - 1) * $data['pageSize'])
  2819. ->limit($data['pageSize'])
  2820. ->get(),
  2821. $data
  2822. );
  2823. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2824. // 获取 type_id 为 2 的数据
  2825. $result['type2'] = $this->processGoods(
  2826. $query->clone()
  2827. ->where('type_id', 2)
  2828. ->offset(($data['page'] - 1) * $data['pageSize'])
  2829. ->limit($data['pageSize'])
  2830. ->get(),
  2831. $data
  2832. );
  2833. }
  2834. if (empty($result)) {
  2835. return Result::error("查询失败", 0);
  2836. }
  2837. return Result::success($result);
  2838. }
  2839. /**
  2840. * 获取商品详情
  2841. * @param array $data
  2842. * @return array
  2843. * */
  2844. public function getWebsiteshopInfo(array $data): array
  2845. {
  2846. $where = [
  2847. 'good.status' => 2,
  2848. 'good.website_id' => $data['website_id'],
  2849. 'good.id' => $data['id'],
  2850. ];
  2851. $goods = Good::where($where)
  2852. ->where('good.id', $data['id'])
  2853. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2854. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2855. ->first();
  2856. if (empty($goods)) {
  2857. return Result::error("查询失败", 0);
  2858. }
  2859. $goods->imgurl = json_decode($goods->imgurl, true);
  2860. return Result::success($goods);
  2861. }
  2862. /**
  2863. * plus pro 处理文章路由问题
  2864. */
  2865. function processArticlePro($website_id)
  2866. {
  2867. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2868. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2869. // // 取出category_id 对应的aLIas_pinyin
  2870. // $categoryIds = array_column($categorys, 'category_id');
  2871. // $categoryPIds = array_column($categorys, 'pid');
  2872. // $aliasPinyins = array_column($categorys, 'path');
  2873. // $alias = array_column($categorys, 'alias');
  2874. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2875. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2876. // // return Result::success($cat_arr);
  2877. // // $catiall = [];
  2878. // //一级所有子级的记录
  2879. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2880. // return [
  2881. // 'cat_1st_arr' => $cat_alias_arr,
  2882. // 'catiall' => $cat_arr,
  2883. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2884. // 'categoryIds' => $categoryIds,
  2885. // ];
  2886. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2887. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2888. // 取出category_id 对应的aLIas_pinyin
  2889. $categoryIds = array_column($categorys, 'category_id');
  2890. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
  2891. return $pid != 0;
  2892. })));
  2893. $category_path = array_column($categorys, 'path');
  2894. $cat_arr = array_combine($categoryIds, $category_path);
  2895. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2896. $catiall = [];
  2897. //一级所有子级的记录
  2898. $cat_1st_arr = [];
  2899. foreach ($categorys as $key => $value) {
  2900. // $category_arr_id = json_decode($value->category_arr_id);
  2901. // $pinyin_str = '';
  2902. // // 算出一级 并且算出子级
  2903. if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
  2904. $cat_1st_arr[$value->pid][] = $value->category_id;
  2905. }
  2906. // foreach ($category_arr_id as $k => $v) {
  2907. // $pinyin_str .= $cat_arr[$v] . '/';
  2908. // }
  2909. // $pinyin_str = rtrim($pinyin_str, '/');
  2910. $catiall[$value->category_id]['alias'] = $value->alias;
  2911. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2912. $catiall[$value->category_id]['type'] = $value->type;
  2913. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2914. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2915. }
  2916. return [
  2917. 'cat_1st_arr' => $cat_1st_arr,
  2918. 'catiall' => $catiall,
  2919. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2920. 'categoryIds' => $categoryIds,
  2921. 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
  2922. 'categoryPIds' => $categoryPIds,
  2923. ];
  2924. }
  2925. /**
  2926. * 封装处理文章的路由问题
  2927. * */
  2928. function processArticles($articles, $data)
  2929. {
  2930. // 检查 $articles 是否为数组或可迭代对象
  2931. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2932. return $articles->map(function ($article) use ($data) {
  2933. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2934. $catid = $article->cat_arr_id ?? '';
  2935. }
  2936. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2937. $catid = $article->category_arr_id ?? '';
  2938. }
  2939. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2940. $level = json_decode($catid, true);
  2941. if (!is_array($level)) {
  2942. return $article;
  2943. } else {
  2944. $level = array_map('intval', $level);
  2945. }
  2946. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2947. ->where($data)
  2948. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2949. ->pluck('aLIas_pinyin')
  2950. ->implode('/');
  2951. $article->pinyin = $pinyin ?? '';
  2952. return $article;
  2953. });
  2954. } else {
  2955. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2956. $catid = $articles->cat_arr_id ?? '';
  2957. $level = json_decode($catid, true);
  2958. if (!is_array($level)) {
  2959. return $articles;
  2960. } else {
  2961. $level = array_map('intval', $level);
  2962. }
  2963. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2964. ->where($data)
  2965. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2966. ->pluck('aLIas_pinyin')
  2967. ->implode('/');
  2968. $articles->pinyin = $pinyin ?? '';
  2969. return $articles;
  2970. }
  2971. }
  2972. // 封装处理由问题
  2973. function processJob($job, $data)
  2974. {
  2975. return $job->map(function ($job) use ($data) {
  2976. $category = $job->cat_arr_id ?? '';
  2977. $cityid = $job->city_arr_id ?? '';
  2978. $city = json_decode($cityid, true);
  2979. $pinyin = '';
  2980. $level = json_decode($category, true);
  2981. // 路由
  2982. if (!empty($level) && is_array($level)) {
  2983. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2984. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2985. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2986. ->get(['aLIas_pinyin'])
  2987. ->pluck('aLIas_pinyin')
  2988. ->implode('/');
  2989. if (empty($pinyin)) {
  2990. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2991. }
  2992. $job->pinyin = $pinyin;
  2993. }
  2994. // 取职位-城市 市??省
  2995. if (!empty($city) && is_array($city)) {
  2996. if (isset($city[1]) && !empty($city[1])) {
  2997. $city = District::where('id', $city[1])->first(['name']);
  2998. $job->city_name = $city->name ?? '';
  2999. } else if (isset($city[0]) && !empty($city[0])) {
  3000. $city = District::where('id', $city[0])->first(['name']);
  3001. $job->city_name = $city->name ?? '';
  3002. } else {
  3003. $job->city_name = '全国';
  3004. }
  3005. }
  3006. // 获取简历最后一级地区
  3007. if (isset($job->city_id) && !empty($job->city_id)) {
  3008. $city = District::where('id', $job->city_id)->first(['name']);
  3009. $job->hunt_cityname = $city->name ?? '';
  3010. }
  3011. // 组合详细地址
  3012. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  3013. $address_id = json_decode($job->address_arr_id, true) ?? [];
  3014. if (is_array($address_id) && !empty($address_id)) {
  3015. $address = District::whereIn('id', $address_id)
  3016. ->orderBy('level', 'asc')
  3017. ->get(['name'])
  3018. ->pluck('name')
  3019. ->implode('');
  3020. // $job->address_name = $address ?? '';
  3021. $job->address_name = ($address ?? '') . ($job->address ?? '');
  3022. }
  3023. }
  3024. // 取行业
  3025. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  3026. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  3027. if (!empty($job->industry)) {
  3028. $query->where('hyid', $job->industry);
  3029. } else if (!empty($job->hy_id)) {
  3030. $query->where('hyid', $job->hy_id);
  3031. } else if (!empty($job->company_hy_id)) {
  3032. $query->where('hyid', $job->company_hy_id);
  3033. } else {
  3034. $query->where('hyid', $job->job_industry);
  3035. }
  3036. })->first(['hyname']);
  3037. $job->hy_name = $hy_name->hyname ?? '';
  3038. }
  3039. // 取职位类别
  3040. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  3041. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  3042. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  3043. $job->zw_name = $zw_name->zwname ?? '';
  3044. }
  3045. // 取具体职位
  3046. 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))) {
  3047. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  3048. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  3049. $job->jtzw_name = $jtzw_name->zwname ?? '';
  3050. }
  3051. // 取工作经验
  3052. if (isset($job->experience) && !empty($job->experience)) {
  3053. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  3054. $job->experience_name = $experience->ename ?? '';
  3055. }
  3056. // 取学历
  3057. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  3058. $education = $job->educational ?? $job->school_education;
  3059. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  3060. $job->education_name = $education->ename ?? '';
  3061. }
  3062. // 语言
  3063. if (isset($job->language) && !empty($job->language)) {
  3064. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  3065. $job->language_name = $language->ename ?? '';
  3066. }
  3067. // 薪资
  3068. if (isset($job->salary) && !empty($job->salary)) {
  3069. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  3070. $job->salary_name = $salary->ename ?? '';
  3071. }
  3072. // 职位性质
  3073. if (isset($job->nature_id) && !empty($job->nature_id)) {
  3074. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  3075. $job->job_nature_name = $job_nature->ename ?? '';
  3076. }
  3077. // 公司规模
  3078. if (isset($job->company_size) && !empty($job->company_size)) {
  3079. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  3080. $job->company_size_name = $company_size->ename ?? '';
  3081. }
  3082. // 公司性质
  3083. if (isset($job->company_nature) && !empty($job->company_nature)) {
  3084. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  3085. $job->company_nature_name = $company_nature->nature_name ?? '';
  3086. }
  3087. // $job->pinyin = $pinyin;
  3088. return $job;
  3089. });
  3090. }
  3091. /**
  3092. * 获取书籍模块
  3093. * @param array $data
  3094. * @return array
  3095. * */
  3096. public function getWebsiteBook(array $data): array
  3097. {
  3098. $input['id'] = $data['id'];
  3099. $input['website_id'] = $data['website_id'];
  3100. // 将 JSON 字符串转换为 PHP 数组
  3101. $data = json_decode($input['id'], true);
  3102. // 使用 array_map 处理每个元素
  3103. $result = array_map(function ($item) use ($input) {
  3104. // 检查parent元素是否存在且不是undefined
  3105. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  3106. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3107. $website = [
  3108. 'website_id' => $input['website_id'],
  3109. ];
  3110. // 查询栏目名称
  3111. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3112. if (empty($category)) {
  3113. $parent_alias = '';
  3114. $parent_pinyin = null;
  3115. $imgBooks = [];
  3116. $textBooks = [];
  3117. } else {
  3118. $parent_alias = $category->alias ?? '';
  3119. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  3120. // 查找子分类ID数组
  3121. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  3122. array_push($childCategoryIds, $parentCatId);
  3123. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  3124. if ($parentImgNum != 0) {
  3125. // 查询图片新闻
  3126. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  3127. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3128. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3129. })
  3130. ->where('book.status', 2)
  3131. ->where('book.img_url', '!=', '')
  3132. ->where('book.website_id', $website['website_id'])
  3133. ->leftJoin('website_category', function ($join) use ($website) {
  3134. $join->on('book.cat_id', '=', 'website_category.category_id')
  3135. ->where('website_category.website_id', '=', $website['website_id']);
  3136. })
  3137. ->select(
  3138. 'book.id',
  3139. 'book.title',
  3140. 'book.img_url',
  3141. 'book.price',
  3142. 'book.market_price',
  3143. 'book.description',
  3144. 'book.cat_id',
  3145. 'book.description',
  3146. 'book.updated_at',
  3147. 'website_category.alias as category_name',
  3148. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3149. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3150. )
  3151. ->orderBy('updated_at', 'desc')
  3152. ->limit($parentImgNum)
  3153. ->get()->all();
  3154. // 查询文字新闻
  3155. }
  3156. if ($parentTextNum != 0) {
  3157. $textBooks = [];
  3158. $textBooks = Book::where(function ($query) use ($parentCatId) {
  3159. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3160. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3161. })
  3162. ->where('book.status', 2)
  3163. ->where('book.website_id', $website['website_id'])
  3164. ->leftJoin('website_category', function ($join) use ($website) {
  3165. $join->on('book.cat_id', '=', 'website_category.category_id')
  3166. ->where('website_category.website_id', '=', $website['website_id']);
  3167. })
  3168. ->select(
  3169. 'book.id',
  3170. 'book.title',
  3171. 'book.img_url',
  3172. 'book.price',
  3173. 'book.market_price',
  3174. 'book.description',
  3175. 'book.cat_id',
  3176. 'book.description',
  3177. 'book.updated_at',
  3178. 'website_category.alias as category_name',
  3179. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3180. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3181. )
  3182. ->orderBy('updated_at', 'desc')
  3183. ->limit($parentTextNum)
  3184. ->get()->all();
  3185. }
  3186. }
  3187. }
  3188. $resultItem = [
  3189. 'alias' => $parent_alias ?? '',
  3190. 'category_id' => $parentCatId ?? 0,
  3191. 'pinyin' => $parent_pinyin ?? null,
  3192. 'imgnum' => $imgBooks ?? [],
  3193. 'textnum' => $textBooks ?? [],
  3194. ];
  3195. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  3196. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  3197. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  3198. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3199. ->get()->all();
  3200. if (!empty($childCategory)) {
  3201. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  3202. // 查询子栏目名称
  3203. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  3204. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3205. ->first();
  3206. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  3207. $childImgArticles = [];
  3208. $childTextArticles = [];
  3209. $resultItem['child'] = [];
  3210. } else {
  3211. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  3212. // 查询子栏目图片新闻
  3213. $childImgArticles = Book::where('cat_id', $childCatId)
  3214. ->where('status', 2)
  3215. ->where('img_url', '!=', '')
  3216. ->where('book.website_id', $website['website_id'])
  3217. ->leftJoin('website_category', function ($join) use ($website) {
  3218. $join->on('book.cat_id', '=', 'website_category.category_id')
  3219. ->where('website_category.website_id', '=', $website['website_id']);
  3220. })
  3221. ->select(
  3222. 'book.id',
  3223. 'book.title',
  3224. 'book.img_url',
  3225. 'book.price',
  3226. 'book.market_price',
  3227. 'book.description',
  3228. 'book.cat_id',
  3229. 'book.description',
  3230. 'book.updated_at',
  3231. DB::raw("'$child_pinyin' as pinyin")
  3232. )
  3233. ->orderBy('updated_at', 'desc')
  3234. ->limit($childImgNum)
  3235. ->get()->all();
  3236. // 查询子栏目文字新闻
  3237. $childTextArticles = Book::where('cat_id', $childCatId)
  3238. ->where('status', 2)
  3239. ->where('book.website_id', $website['website_id'])
  3240. ->leftJoin('website_category', function ($join) use ($website) {
  3241. $join->on('book.cat_id', '=', 'website_category.category_id')
  3242. ->where('website_category.website_id', '=', $website['website_id']);
  3243. })
  3244. ->select(
  3245. 'book.id',
  3246. 'book.title',
  3247. 'book.img_url',
  3248. 'book.price',
  3249. 'book.market_price',
  3250. 'book.description',
  3251. 'book.cat_id',
  3252. 'book.description',
  3253. 'book.updated_at',
  3254. DB::raw("'$child_pinyin' as pinyin")
  3255. )
  3256. ->orderBy('updated_at', 'desc')
  3257. ->limit($childTextNum)
  3258. ->get()->all();
  3259. $resultItem['child'] = [
  3260. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  3261. 'category_id' => $childCatId,
  3262. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  3263. 'all_childcat' => $childCategory,
  3264. 'imgnum' => $childImgArticles,
  3265. 'textnum' => $childTextArticles,
  3266. ];
  3267. }
  3268. }
  3269. } else {
  3270. $resultItem['child'] = [];
  3271. }
  3272. return $resultItem;
  3273. }, $data);
  3274. return Result::success($result);
  3275. }
  3276. /**
  3277. * 获取书刊列表
  3278. * @param array $data
  3279. * @return array
  3280. * */
  3281. public function getWebsiteBookList(array $data): array
  3282. {
  3283. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3284. if (empty($web)) {
  3285. return Result::error("查询失败", 0);
  3286. }
  3287. $catid = $data['id'];
  3288. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  3289. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  3290. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  3291. $category_pinyin = $category ? $category->aLias_pinyin : '';
  3292. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  3293. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  3294. ->where('pid', $category['pid'])
  3295. ->select(
  3296. 'category_id',
  3297. 'alias',
  3298. 'aLIas_pinyin',
  3299. 'pid',
  3300. 'sort',
  3301. 'is_url',
  3302. 'web_url',
  3303. 'seo_title',
  3304. 'seo_keywords',
  3305. 'seo_description',
  3306. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  3307. )
  3308. ->orderBy('sort')
  3309. ->get()->all();
  3310. if (empty($category)) {
  3311. return Result::error("查询失败", 0);
  3312. }
  3313. $query = Book::where('book.status', 2)
  3314. ->where('book.website_id', $data['website_id'])
  3315. ->where('book.cat_id', $catid)
  3316. ->select(
  3317. 'book.id',
  3318. 'book.title',
  3319. 'book.img_url',
  3320. 'book.description',
  3321. 'book.updated_at',
  3322. 'book.cat_id',
  3323. DB::raw("'$pinyin' as pinyin")
  3324. )
  3325. ->orderBy('book.updated_at', 'desc');
  3326. $count = $query->count();
  3327. $query = clone $query;
  3328. $Book = $query
  3329. ->limit($data['pageSize'])
  3330. ->offset(($data['page'] - 1) * $data['pageSize'])
  3331. ->get()->all();
  3332. $result = [
  3333. 'category' => $categorys,
  3334. 'books' => $Book,
  3335. 'count' => $count,
  3336. ];
  3337. // if(empty($result)){
  3338. // return Result::error("查询失败", 0);
  3339. // }
  3340. return Result::success($result);
  3341. }
  3342. /**
  3343. * 获取书刊详情
  3344. * @param array $data
  3345. * @return array
  3346. * */
  3347. public function getWebsiteBookInfo(array $data): array
  3348. {
  3349. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3350. if (empty($web)) {
  3351. return Result::error("查询失败", 0);
  3352. }
  3353. $book = Book::where('status', 2)
  3354. ->where('website_id', $data['website_id'])
  3355. ->where('id', $data['id'])
  3356. ->select(
  3357. 'book.*',
  3358. )
  3359. ->orderBy('updated_at', 'desc')
  3360. ->first();
  3361. if (empty($book)) {
  3362. return Result::error("查询失败", 0);
  3363. }
  3364. // 先查询当前分类的 pid
  3365. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  3366. ->where('category_id', $book['cat_id'])
  3367. ->first(['pid', 'category_id']);
  3368. $query = WebsiteCategory::where('website_id', $data['website_id']);
  3369. if (!empty($carpid)) {
  3370. if ($carpid->pid != 0) {
  3371. $pid = $carpid['pid'];
  3372. // $parent_pinyin = '';
  3373. } else {
  3374. $pid = $carpid['category_id'];
  3375. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  3376. }
  3377. }
  3378. $categorys = $query->where('pid', $pid)
  3379. ->select(
  3380. 'category_id',
  3381. 'alias',
  3382. 'aLIas_pinyin',
  3383. 'pid',
  3384. 'sort',
  3385. 'is_url',
  3386. 'web_url',
  3387. 'category_arr_id as cat_arr_id',
  3388. )
  3389. ->orderBy('sort')
  3390. ->get();
  3391. $category = $this->processArticle($categorys, $data);
  3392. $result = [
  3393. 'category' => $category,
  3394. 'books' => $book,
  3395. ];
  3396. return Result::success($result);
  3397. }
  3398. /**
  3399. * 尝试
  3400. * @param array $data
  3401. * @return array
  3402. * */
  3403. public function test(array $data): array
  3404. {
  3405. $input['id'] = $data['id'];
  3406. $input['website_id'] = $data['website_id'];
  3407. // 将 JSON 字符串转换为 PHP 数组
  3408. $data = json_decode($input['id'], true);
  3409. $result = [];
  3410. $article = $data;
  3411. $result = array_map(function ($item) use ($input) {
  3412. $website = [
  3413. 'website_id' => $input['website_id'],
  3414. ];
  3415. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3416. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3417. $parent = [
  3418. 0 => $category['category_id'] ?? [],
  3419. 1 => $parentImgNum ?? [],
  3420. 2 => $parentTextNum ?? [],
  3421. ];
  3422. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  3423. $child = [];
  3424. $resultItem = [
  3425. // 'alias' => $parent_alias ?? '',
  3426. 'category_id' => $parentCatId ?? 0,
  3427. 'pinyin' => $parentImgNum ?? null,
  3428. 'imgnum' => $parentTextNum ?? [],
  3429. // 'textnum' => $textArticles ?? [],
  3430. ];
  3431. return $parent;
  3432. }, $data);
  3433. return Result::success($result);
  3434. // });
  3435. }
  3436. /**
  3437. * 封装处理文章的路由问题
  3438. * */
  3439. function processArticle($article, $data)
  3440. {
  3441. return $article->map(function ($article) use ($data) {
  3442. $catid = $article->cat_arr_id ?? '';
  3443. $level = json_decode($catid, true);
  3444. $pinyin = '';
  3445. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  3446. if (!empty($level) && is_array($level)) {
  3447. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  3448. ->where('website_id', $data['website_id'])
  3449. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3450. ->get(['aLIas_pinyin'])
  3451. ->pluck('aLIas_pinyin')
  3452. ->implode('/');
  3453. } else {
  3454. $pinyin = '';
  3455. }
  3456. $article->pinyin = $pinyin;
  3457. return $article;
  3458. });
  3459. }
  3460. /**
  3461. * c端-获取招工招聘下拉选框
  3462. * @param array $data
  3463. * @return array
  3464. * */
  3465. public function getWebsiteJobSelect(array $data): array
  3466. {
  3467. $web = Website::where('id', $data['website_id'])->first();
  3468. if (empty($web)) {
  3469. return Result::error("该网站不存在", 0);
  3470. }
  3471. $hy = JobIndustry::get()->all();
  3472. $zw = JobPosition::where('zwpid', 0)->get()->all();
  3473. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  3474. $result = [
  3475. 'hy' => $hy,
  3476. 'zw' => $zw,
  3477. 'jtzw' => $jtzw,
  3478. ];
  3479. if (empty($result)) {
  3480. return Result::error("查询失败", 0);
  3481. }
  3482. return Result::success($result);
  3483. }
  3484. /**
  3485. * c端-获取招工招聘
  3486. * @param array $data
  3487. * @return array
  3488. * */
  3489. public function getWebsiteJob(array $data): array
  3490. {
  3491. $web = Website::where('id', $data['website_id'])->first();
  3492. if (empty($web)) {
  3493. return Result::error("该网站不存在", 0);
  3494. }
  3495. $job_hunting = JobHunting::where('job_hunting.status', 2)
  3496. ->where('job_hunting.website_id', $data['website_id'])
  3497. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3498. $query->where(function ($q) use ($data) {
  3499. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3500. });
  3501. })
  3502. ->select(
  3503. 'job_hunting.id',
  3504. 'job_hunting.catid',
  3505. 'job_hunting.cat_arr_id',
  3506. 'job_hunting.job_name_get',
  3507. 'job_hunting.industry',
  3508. 'job_hunting.name',
  3509. 'job_hunting.sexy',
  3510. 'job_hunting.origin',
  3511. 'job_hunting.city_arr_id',
  3512. 'job_hunting.experience',
  3513. 'job_hunting.updated_at',
  3514. 'job_hunting.salary',
  3515. 'job_hunting.skillList',
  3516. 'job_hunting.slelf_evaluation',
  3517. )
  3518. ->orderBy('updated_at', 'desc')
  3519. ->limit($data['job1_num'])
  3520. ->get();
  3521. $web['website_id'] = $data['website_id'];
  3522. if (empty($job_hunting)) {
  3523. $job_huntings = "未查询到相关简历信息";
  3524. } else {
  3525. $job_huntings = $this->processJob($job_hunting, $web);
  3526. }
  3527. // 0:待审核 1:已通过 2:已拒绝
  3528. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3529. ->where('job_recruiting.website_id', $data['website_id'])
  3530. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3531. $query->where(function ($q) use ($data) {
  3532. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3533. });
  3534. })
  3535. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3536. ->select(
  3537. 'job_recruiting.id',
  3538. 'job_recruiting.catid',
  3539. 'job_recruiting.cat_arr_id',
  3540. 'job_recruiting.title',
  3541. 'job_recruiting.jtzw_id',
  3542. 'job_recruiting.hy_id',
  3543. 'job_recruiting.city_arr_id',
  3544. 'job_recruiting.due_data',
  3545. 'job_recruiting.updated_at',
  3546. 'job_recruiting.experience',
  3547. 'job_recruiting.educational',
  3548. 'job_recruiting.salary',
  3549. 'job_recruiting.zw_id',
  3550. 'job_company.business_name',
  3551. 'job_recruiting.keyword',
  3552. 'job_recruiting.description',
  3553. )
  3554. ->orderBy('updated_at', 'desc')
  3555. ->limit($data['job2_num'])
  3556. ->get();
  3557. if (empty($job_recruiting->toArray())) {
  3558. $job_recruitings = "未查询到相关职位信息";
  3559. } else {
  3560. $job_recruitings = $this->processJob($job_recruiting, $web);
  3561. }
  3562. $result = [
  3563. 'job_hunting' => $job_huntings,
  3564. 'job_recuiting' => $job_recruitings,
  3565. ];
  3566. return Result::success($result);
  3567. }
  3568. /**
  3569. * c端-获取招工招聘列表
  3570. * @param array $data
  3571. * @return array
  3572. * */
  3573. public function getWebsiteJobList(array $data): array
  3574. {
  3575. $recruit_where = [];
  3576. $hunt_where = [];
  3577. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3578. if (empty($web)) {
  3579. return Result::error("此网站不存在", 0);
  3580. }
  3581. $website_id['website_id'] = $data['website_id'];
  3582. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3583. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3584. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3585. }
  3586. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3587. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3588. }
  3589. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3590. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3591. }
  3592. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3593. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3594. }
  3595. $query = JobRecruiting::where('job_recruiting.status', 1)
  3596. ->where('job_recruiting.website_id', $data['website_id'])
  3597. ->where($recruit_where)
  3598. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3599. $query->where(function ($q) use ($data) {
  3600. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3601. });
  3602. })
  3603. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3604. $query->where(function ($q) use ($data) {
  3605. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3606. });
  3607. })
  3608. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3609. ->select(
  3610. 'job_recruiting.id',
  3611. 'job_recruiting.catid',
  3612. 'job_recruiting.hy_id',
  3613. 'job_recruiting.title',
  3614. 'job_recruiting.zw_id',
  3615. 'job_recruiting.educational',
  3616. 'job_recruiting.jtzw_id',
  3617. 'job_recruiting.city_arr_id',
  3618. 'job_recruiting.due_data',
  3619. 'job_recruiting.experience',
  3620. 'job_recruiting.cat_arr_id',
  3621. 'job_recruiting.updated_at',
  3622. 'job_company.business_name',
  3623. 'job_recruiting.keyword',
  3624. 'job_recruiting.description',
  3625. )
  3626. ->orderBy('job_recruiting.updated_at', 'desc');
  3627. $recruit_count = $query->count();
  3628. $query = clone $query;
  3629. $JobRecruiting = $query
  3630. ->offset(($data['page'] - 1) * $data['pageSize'])
  3631. ->limit($data['pageSize'])
  3632. ->get();
  3633. if (empty($JobRecruiting)) {
  3634. $JobRecruiting = "暂无相关职位信息";
  3635. } else {
  3636. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3637. }
  3638. }
  3639. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3640. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3641. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3642. }
  3643. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3644. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3645. }
  3646. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3647. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3648. }
  3649. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3650. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3651. }
  3652. $query = JobHunting::where('job_hunting.status', 2)
  3653. ->where('job_hunting.website_id', $data['website_id'])
  3654. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3655. ->where($hunt_where)
  3656. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3657. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3658. // })
  3659. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3660. $query->where(function ($q) use ($data) {
  3661. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3662. });
  3663. })
  3664. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3665. $query->where(function ($q) use ($data) {
  3666. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3667. });
  3668. })
  3669. ->select(
  3670. 'job_hunting.id',
  3671. 'job_hunting.catid',
  3672. 'job_hunting.sexy',
  3673. 'job_hunting.experience',
  3674. 'job_hunting.origin',
  3675. 'job_hunting.industry',
  3676. 'job_hunting.name',
  3677. 'job_hunting.job',
  3678. 'job_hunting.job_name_get',
  3679. 'job_hunting.city_arr_id',
  3680. 'job_hunting.cat_arr_id',
  3681. 'job_hunting.created_at',
  3682. 'job_hunting.updated_at',
  3683. 'job_position.zwname as job_name',
  3684. 'job_hunting.skillList',
  3685. 'job_hunting.slelf_evaluation',
  3686. )
  3687. ->orderBy('job_hunting.updated_at', 'desc');
  3688. $hunt_count = $query->count();
  3689. $query = clone $query;
  3690. $JobHunting = $query
  3691. ->offset(($data['page'] - 1) * $data['pageSize'])
  3692. ->limit($data['pageSize'])
  3693. ->get();
  3694. if (empty($JobHunting)) {
  3695. $JobRecruiting = "暂无相关简历信息";
  3696. } else {
  3697. $JobHunting = $this->processJob($JobHunting, $website_id);
  3698. }
  3699. }
  3700. $result = [
  3701. 'JobRecruiting' => $JobRecruiting ?? [],
  3702. 'recruit_count' => $recruit_count ?? 0,
  3703. 'JobHunting' => $JobHunting ?? [],
  3704. 'hunt_count' => $hunt_count ?? 0,
  3705. ];
  3706. return Result::success($result);
  3707. }
  3708. /**
  3709. * c端-获取招工招聘详情
  3710. * @param array $data
  3711. * @return array
  3712. * */
  3713. public function getWebsiteJobInfo(array $data): array
  3714. {
  3715. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3716. if (empty($web)) {
  3717. return Result::error("该网站不存在", 0);
  3718. }
  3719. $webid = [
  3720. 'website_id' => $data['website_id'],
  3721. ];
  3722. // 职位相关信息
  3723. if ($data['type'] == 1) {
  3724. $query = JobRecruiting::where('status', 1)
  3725. ->where('website_id', $data['website_id'])
  3726. ->select('*');
  3727. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3728. $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();
  3729. if (!empty($company)) {
  3730. $result['company'] = $this->processJob($company, $webid);
  3731. }
  3732. $other_job = JobRecruiting::where('status', 1)
  3733. ->where('website_id', $data['website_id'])
  3734. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3735. ->where('id', '!=', $data['id'])
  3736. ->where('user_id', '=', $job[0]['user_id'])
  3737. ->limit($data['pageSize'])
  3738. ->get();
  3739. if (!empty($other_job)) {
  3740. $result['other_job'] = $this->processJob($other_job, $webid);
  3741. }
  3742. } else {
  3743. // 简历相关信息
  3744. $job = JobHunting::where('job_hunting.status', 2)
  3745. ->where('job_hunting.website_id', $data['website_id'])
  3746. ->where('job_hunting.id', $data['id'])
  3747. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3748. ->select('job_hunting.*', 'user_name')
  3749. ->get();
  3750. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3751. if (!empty($resume->toArray())) {
  3752. $result['resume'] = 1;
  3753. } else {
  3754. $result['resume'] = 0;
  3755. }
  3756. }
  3757. if (empty($job->toArray())) {
  3758. return Result::error("id参数错误", 0);
  3759. }
  3760. if (!empty($job[0]['job_experience'])) {
  3761. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3762. if (!empty($job_experience)) {
  3763. // $hy = [];
  3764. foreach ($job_experience as $key => $value) {
  3765. // $id = $value['id'];
  3766. $hy[$key] = $value['job_industry'];
  3767. $zw_id[$key] = $value['job_typename'];
  3768. $jtzw_id[$key] = $value['job_name'];
  3769. }
  3770. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3771. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3772. // 先将关联表转换为索引数组,提高查找效率
  3773. $hyLookup = [];
  3774. foreach ($hy_table as $item) {
  3775. $hyLookup[$item['hyid']] = $item['hyname'];
  3776. }
  3777. $zwLookup = [];
  3778. foreach ($zw_table as $item) {
  3779. $zwLookup[$item['zwid']] = $item['zwname'];
  3780. }
  3781. foreach ($job_experience as $key => &$value) {
  3782. // 处理行业名称
  3783. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3784. $value['hy_name'] = $hyLookup[$hy[$key]];
  3785. }
  3786. // 处理职位名称
  3787. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3788. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3789. }
  3790. // 处理具体职位名称
  3791. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3792. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3793. }
  3794. }
  3795. // 释放引用,防止意外修改后续代码
  3796. unset($value);
  3797. }
  3798. $result['job_experience'] = $job_experience ?? [];
  3799. }
  3800. if (!empty($job[0]['education_experience'])) {
  3801. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3802. if (!empty($education_experience)) {
  3803. foreach ($education_experience as $key => $value) {
  3804. // $id = $value['id'];
  3805. $education[$key] = $value['school_education'];
  3806. }
  3807. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3808. // // 先将关联表转换为索引数组,提高查找效率
  3809. $educationLookup = [];
  3810. foreach ($education_table as $item) {
  3811. $educationLookup[$item['evalue']] = $item['ename'];
  3812. }
  3813. foreach ($education_experience as $key => &$value) {
  3814. // 处理学历名称
  3815. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3816. $value['education_name'] = $educationLookup[$education[$key]];
  3817. }
  3818. }
  3819. }
  3820. $result['education_experience'] = $job_experience ?? [];
  3821. }
  3822. $result['job'] = $this->processJob($job, $webid);
  3823. // // 返现对应的栏目
  3824. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3825. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3826. ->whereIn('category_id', $catid)
  3827. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3828. ->orderBy('pid')->get()->all();
  3829. if (!empty($category)) {
  3830. $result['category'] = $category;
  3831. }
  3832. $result['job'] = $job;
  3833. $result['job_experience'] = $job_experience ?? [];
  3834. $result['education_experience'] = $education_experience ?? [];
  3835. if (empty($result)) {
  3836. return Result::error("参数错误", 0);
  3837. }
  3838. return Result::success($result);
  3839. }
  3840. /**
  3841. * c端-申请职位
  3842. * @param array $data
  3843. * @return array
  3844. * */
  3845. public function getWebsiteJobApply(array $data): array
  3846. {
  3847. // 首先验证网站是否存在
  3848. // return Result::success($data);
  3849. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3850. if (empty($web)) {
  3851. return Result::error("该网站不存在", 0);
  3852. }
  3853. // 验证用户是否存在且为个人会员/管理员
  3854. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3855. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3856. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3857. return Result::error("用户不存在", 0);
  3858. }
  3859. // 去除重复元素和空元素,并保持原始顺序
  3860. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3861. return !empty($value);
  3862. }));
  3863. // 验证职位是否存在 1:审核通过
  3864. $recruiting = JobRecruiting::where('status', 1)
  3865. ->where('website_id', $data['website_id'])
  3866. ->whereIn('id', $data['recruit_id'])
  3867. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3868. if (empty($recruiting)) {
  3869. return Result::error("该职位不存在", 0);
  3870. }
  3871. // 简历是否存在
  3872. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3873. if (empty($hunt_id)) {
  3874. return Result::error("该简历不存在", 0);
  3875. }
  3876. $data['hunt_id'] = $hunt_id['hunt_id'];
  3877. // // 验证是否已投递过该职位
  3878. $apply = JobApply::where('user_id', $data['user_id'])
  3879. ->where('hunt_id', $data['hunt_id'])
  3880. ->where('website_id', $data['website_id'])
  3881. ->whereIn('recruit_id', $data['recruit_id'])
  3882. ->get(['recruit_id']);
  3883. if (!empty($apply->toArray())) {
  3884. return Result::error("您已投递过该职位!");
  3885. }
  3886. $insertData = array_map(function ($recruiting) use ($data) {
  3887. return [
  3888. 'user_id' => $data['user_id'],
  3889. 'hunt_id' => $data['hunt_id'],
  3890. 'website_id' => $data['website_id'],
  3891. 'recruit_id' => $recruiting['recruit_id'],
  3892. 'receiver_id' => $recruiting['receiver_id'],
  3893. 'status' => 1,
  3894. ];
  3895. }, $recruiting);
  3896. // 批量插入数据
  3897. $result = JobApply::insert($insertData);
  3898. if (empty($result)) {
  3899. return Result::error("投递失败", 0);
  3900. }
  3901. return Result::success($result);
  3902. }
  3903. /**
  3904. * 招工招聘-沟通简历
  3905. * @param array $data
  3906. * @return array
  3907. * */
  3908. public function getWebsiteJobResume(array $data): array
  3909. {
  3910. // 首先验证网站是否存在
  3911. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3912. if (empty($web)) {
  3913. return Result::error("该网站不存在", 0);
  3914. }
  3915. // return Result::success($data);
  3916. // 验证用户是否存在且为企业会员/管理员
  3917. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3918. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3919. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3920. return Result::error("用户不存在", 0);
  3921. }
  3922. // 去除重复元素和空元素,并保持原始顺序
  3923. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3924. return !empty($value);
  3925. }));
  3926. // 验证简历是否存在
  3927. $hunting = JobHunting::where('status', 2)
  3928. ->where('website_id', $data['website_id'])
  3929. ->whereIn('id', $data['hunt_id'])
  3930. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3931. if (empty($hunting)) {
  3932. return Result::error("该简历不存在", 0);
  3933. }
  3934. // 验证是否已沟通过该简历
  3935. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3936. ->where('recruit_id', $data['recruit_id'])
  3937. ->where('website_id', $data['website_id'])
  3938. ->whereIn('hunt_id', $data['hunt_id'])
  3939. ->get(['hunt_id']);
  3940. if (!empty($remuse->toArray())) {
  3941. return Result::error("您已沟通过该简历!");
  3942. }
  3943. // 准备要插入的数据数组
  3944. $insertData = array_map(function ($hunting) use ($data) {
  3945. return [
  3946. 'user_id' => $data['user_id'],
  3947. 'recruit_id' => $data['recruit_id'],
  3948. 'website_id' => $data['website_id'],
  3949. 'hunt_id' => $hunting['hunt_id'],
  3950. 'receiver_id' => $hunting['receiver_id'],
  3951. 'status' => 1,
  3952. ];
  3953. }, $hunting);
  3954. // 批量插入数据
  3955. $result = JobRemuse::insert($insertData);
  3956. if (empty($result)) {
  3957. return Result::error("沟通失败", 0);
  3958. }
  3959. return Result::success($result);
  3960. }
  3961. /**
  3962. * 招工招聘 -我的职位(企业会员)
  3963. * @param array $data
  3964. * @return array
  3965. */
  3966. public function getWebsiteJobRecruiting(array $data): array
  3967. {
  3968. $web = Website::where('id', $data['website_id'])->first('id');
  3969. if (empty($web)) {
  3970. return Result::error("该网站不存在", 0);
  3971. }
  3972. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3973. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3974. return Result::error("用户暂无权限!", 0);
  3975. }
  3976. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3977. $result = JobRecruiting::where('website_id', $data['website_id'])
  3978. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3979. $query->where('user_id', $user['id']);
  3980. })
  3981. ->where('status', 1)
  3982. ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
  3983. ->orderBy('updated_at', 'desc')
  3984. ->limit($data['pageSize'])
  3985. ->get();
  3986. if (empty($result)) {
  3987. return Result::error("暂无相关职位信息", 0);
  3988. }
  3989. return Result::success($result);
  3990. }
  3991. /**
  3992. * c端 - 验证路由
  3993. * @param array $data
  3994. * @return array
  3995. */
  3996. /**
  3997. * c端 - 验证路由
  3998. * @param array $data
  3999. * @return array
  4000. */
  4001. public function checkWebsiteRoute(array $data): array
  4002. {
  4003. // 测试001111111222
  4004. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  4005. if (empty($web)) {
  4006. return Result::error("该网站不存在", 0);
  4007. } elseif ($web['status'] != 1) {
  4008. return Result::error("网站已经关闭", 0);
  4009. }
  4010. if (isset($data['other_route']) && !empty($data['other_route'])) {
  4011. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  4012. // 验证路由是否存在
  4013. if (empty($whiteRouterInfo)) {
  4014. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  4015. }
  4016. if (!empty($whiteRouterInfo)) {
  4017. return Result::success($whiteRouterInfo->toArray());
  4018. }
  4019. }
  4020. // 验证栏目路由
  4021. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  4022. ->where('path', $data['all_route'])
  4023. ->get()->all();
  4024. if (count($last_category) == 0) {
  4025. return Result::error("该栏目不存在", 0);
  4026. }
  4027. if (count($last_category) > 1) {
  4028. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  4029. }
  4030. if (count($last_category) == 1) {
  4031. $last_category = $last_category[0];
  4032. }
  4033. // return Result::success($last_category);
  4034. if (isset($data['id']) && !empty($data['id'])) {
  4035. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  4036. switch ($last_category['type']) {
  4037. case 1:
  4038. // 文章
  4039. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  4040. $article = Article::where('status', 1)
  4041. ->where('id', $data['id'])
  4042. ->where(function ($query) use ($data) {
  4043. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  4044. ->orWhereNull("ignore_ids");
  4045. })
  4046. ->first(['catid']);
  4047. if (empty($article)) {
  4048. return Result::error("该文章不存在", 0);
  4049. }
  4050. // return Result::success($article);
  4051. break;
  4052. case 2:
  4053. // 商品
  4054. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4055. $article = Good::where('website_id', $data['website_id'])
  4056. ->where('status', 2)
  4057. ->where('id', $data['id'])
  4058. ->first(['cat_arr_id']);
  4059. if (empty($article)) {
  4060. return Result::error("该商品不存在", 0);
  4061. }
  4062. break;
  4063. case 3:
  4064. // 书刊信息
  4065. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4066. $article = Book::where('website_id', $data['website_id'])
  4067. ->where('status', 2)
  4068. ->where('id', $data['id'])
  4069. ->first(['id', 'cat_arr_id']);
  4070. if (empty($article)) {
  4071. return Result::error("该书刊不存在", 0);
  4072. }
  4073. break;
  4074. case 4:
  4075. // 招聘
  4076. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  4077. $article = JobRecruiting::where('website_id', $data['website_id'])
  4078. ->where('status', 1)
  4079. ->where('id', $data['id'])
  4080. ->first(['cat_arr_id']);
  4081. if (empty($article)) {
  4082. return Result::error("该招聘不存在", 0);
  4083. }
  4084. break;
  4085. case 5:
  4086. // 求职
  4087. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4088. $article = JobHunting::where('website_id', $data['website_id'])
  4089. ->where('status', 2)
  4090. ->where('id', $data['id'])
  4091. ->first(['cat_arr_id']);
  4092. if (empty($article)) {
  4093. return Result::error("该求职不存在", 0);
  4094. }
  4095. break;
  4096. case 6:
  4097. // 企业
  4098. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4099. $article = Company::
  4100. // where('website_id', $data['website_id'])
  4101. // ->
  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. case 7:
  4110. // 项目
  4111. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4112. $article = Project::where('website_id', $data['website_id'])
  4113. ->where('status', 1)
  4114. ->where('id', $data['id'])
  4115. ->first(['cat_arr_id']);
  4116. if (empty($article)) {
  4117. return Result::error("该项目不存在", 0);
  4118. }
  4119. break;
  4120. default:
  4121. return Result::error("该数据不存在", 0);
  4122. break;
  4123. }
  4124. // return Result::success($article);
  4125. // $catid =0 ;
  4126. if (!isset($article['cat_arr_id'])) {
  4127. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  4128. } else {
  4129. $catidArray = json_decode($article['cat_arr_id'], true);
  4130. $catid = !empty($catidArray) ? end($catidArray) : null;
  4131. }
  4132. // return Result::success($catid);
  4133. // // return Result::success($article['cat_arr_id']);
  4134. if (empty($catid)) {
  4135. return Result::error("该栏目路径不存在", 0);
  4136. }
  4137. $path = WebsiteCategory::where('website_id', $data['website_id'])
  4138. ->where('category_id', $catid)
  4139. ->first('path');
  4140. }
  4141. // else{
  4142. // // if ($last_category['pid'] != 0) {
  4143. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  4144. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  4145. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  4146. // ->where('category_id',$catid)
  4147. // ->where('path',$data['all_route'])
  4148. // ->first('path');
  4149. // // } else {
  4150. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  4151. // // }
  4152. // }
  4153. // return Result::success($path);
  4154. if (!empty($path) && $path['path'] != $data['all_route']) {
  4155. return Result::error('非法路径!');
  4156. } else {
  4157. return Result::success($last_category['path']);
  4158. }
  4159. }
  4160. /**
  4161. * 招工招聘 - 获取推荐职位
  4162. * @param array $data
  4163. * @return array
  4164. */
  4165. public function getWebsiteLevelJob(array $data): array
  4166. {
  4167. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  4168. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  4169. ->where('job_recruiting.status', 1)
  4170. ->where('job_level', $data['job_level'])
  4171. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4172. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  4173. ->orderBy('job_recruiting.updated_at', 'desc')
  4174. ->limit($data['pageSize'])
  4175. ->get();
  4176. $web = ['website_id' => $data['website_id']];
  4177. if (!empty($job)) {
  4178. $result = $this->processJob($job, $web);
  4179. }
  4180. if (empty($result)) {
  4181. return Result::error("暂无相关职位信息", 0);
  4182. }
  4183. return Result::success($result);
  4184. }
  4185. /**
  4186. * 验证导航名称是否重复
  4187. * @return void
  4188. */
  4189. //20250226 产品列表
  4190. public function getGoodList(array $data): array
  4191. {
  4192. var_dump($data, '---------1-2--');
  4193. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  4194. unset($data['user_type_id']);
  4195. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4196. $where = [];
  4197. if ($type_id != '10000') {
  4198. $where = [
  4199. 'good.user_id' => $user_id,
  4200. ];
  4201. }
  4202. //类型
  4203. if (isset($data['type_id']) && $data['type_id']) {
  4204. $where['good.type_id'] = $data['type_id'];
  4205. }
  4206. //名称
  4207. if (isset($data['name']) && $data['name']) {
  4208. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  4209. }
  4210. //status
  4211. if (isset($data['status']) && $data['status'] != '') {
  4212. $where['good.status'] = $data['status'];
  4213. }
  4214. //status1
  4215. // if (isset($data['status1']) && $data['status1'] == 1) {
  4216. // $status1 = 1;
  4217. // }
  4218. $where1 = [];
  4219. //website_id
  4220. // if (isset($data['website_id']) && $data['website_id']) {
  4221. // $where1 = [
  4222. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  4223. // ];
  4224. // }
  4225. // website_name
  4226. if (isset($data['website_name']) && $data['website_name']) {
  4227. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  4228. }
  4229. // catid
  4230. if (isset($data['category_name']) && $data['category_name']) {
  4231. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  4232. }
  4233. // $result = Good::where($where)
  4234. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  4235. var_dump($where, '---------1---');
  4236. $result = Good::where($where)
  4237. ->when(!empty($where1), function ($query) use ($where1) {
  4238. return $query->where($where1);
  4239. })
  4240. //status 1待审核2已审核3已拒绝
  4241. ->when(isset($data['status1']), function ($query) {
  4242. return $query->whereIn('good.status', [1, 3]);
  4243. })
  4244. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4245. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4246. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4247. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4248. ->orderBy("updated_at", "desc")
  4249. ->limit($data['page_size'])
  4250. ->offset(($data['page'] - 1) * $data['page_size'])
  4251. ->get();
  4252. $count = Good::where($where)
  4253. ->when(!empty($where1), function ($query) use ($where1) {
  4254. return $query->where($where1);
  4255. })
  4256. //status 1待审核2已审核3已拒绝
  4257. ->when(isset($data['status1']), function ($query) {
  4258. return $query->whereIn('good.status', [1, 3]);
  4259. })
  4260. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4261. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4262. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4263. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4264. ->orderBy("updated_at", "desc")->count();
  4265. $data = [
  4266. 'rows' => $result->toArray(),
  4267. 'count' => $count,
  4268. ];
  4269. if (empty($result)) {
  4270. return Result::error("此栏目暂无相关产品", 0);
  4271. }
  4272. return Result::success($data);
  4273. }
  4274. public function getGoodInfo(array $data): array
  4275. {
  4276. $result = Good::where('id', $data['id'])->first();
  4277. if (empty($result)) {
  4278. return Result::error("此产品不存在", 0);
  4279. }
  4280. return Result::success($result);
  4281. }
  4282. public function addGood(array $data): array
  4283. {
  4284. // unset($data['city_arr_id']);
  4285. // unset($data['cat_arr_id']);
  4286. $data['city_id'] = end($data['city_arr_id']);
  4287. $data['catid'] = end($data['cat_arr_id']);
  4288. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4289. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4290. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4291. unset($data['imgUrl']); //大小写
  4292. if (isset($data['price']) && $data['price'] == '') {
  4293. $data['price'] = 0;
  4294. }
  4295. if ($data['imgurl'] == '') {
  4296. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4297. preg_match_all($reg, $data['detail'], $matches);
  4298. if (isset($matches[1][0])) {
  4299. //截取varchar240
  4300. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4301. }
  4302. }
  4303. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4304. //提取标题+内容中的关键词
  4305. $data['keyword'] = $data['name'];
  4306. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4307. Jieba::init(); // 初始化 jieba-php
  4308. Finalseg::init();
  4309. $segList = Jieba::cut($data['keyword']);
  4310. $segList1 = array_slice($segList, 0, 8);
  4311. $data['keyword'] = implode(',', $segList1);
  4312. }
  4313. if ($data['description'] == '') {
  4314. //提取内容中的描述
  4315. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4316. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4317. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4318. }
  4319. if ($data['status'] == 1) {
  4320. $this->sendMessage([
  4321. 'talk_type' => 200,
  4322. 'title' => $data['name'],
  4323. 'content' => '提交了审核',
  4324. 'messageType' => 3,
  4325. ]);
  4326. }
  4327. $result = Good::insert($data);
  4328. if (empty($result)) {
  4329. return Result::error("添加失败", 0);
  4330. }
  4331. return Result::success($result);
  4332. }
  4333. public function updateGood(array $data): array
  4334. {
  4335. $data['city_id'] = end($data['city_arr_id']);
  4336. $data['catid'] = end($data['cat_arr_id']);
  4337. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4338. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4339. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4340. //设置东八区
  4341. date_default_timezone_set('Asia/Shanghai');
  4342. $data['updated_at'] = date('Y-m-d H:i:s');
  4343. if (isset($data['price']) && $data['price'] == '') {
  4344. $data['price'] = 0;
  4345. }
  4346. if ($data['imgurl'] == '') {
  4347. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4348. preg_match_all($reg, $data['detail'], $matches);
  4349. if (isset($matches[1][0])) {
  4350. //截取varchar240
  4351. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4352. }
  4353. }
  4354. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4355. //提取标题+内容中的关键词
  4356. $data['keyword'] = $data['name'];
  4357. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4358. Jieba::init(); // 初始化 jieba-php
  4359. Finalseg::init();
  4360. $segList = Jieba::cut($data['keyword']);
  4361. $segList1 = array_slice($segList, 0, 8);
  4362. $data['keyword'] = implode(',', $segList1);
  4363. }
  4364. if ($data['description'] == '') {
  4365. //提取内容中的描述
  4366. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4367. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4368. }
  4369. if ($data['status'] == 1) {
  4370. $this->sendMessage([
  4371. 'talk_type' => 200,
  4372. 'title' => $data['name'],
  4373. 'content' => '提交了审核',
  4374. 'messageType' => 3,
  4375. ]);
  4376. }
  4377. $result = Good::where('id', $data['id'])->update($data);
  4378. if (empty($result)) {
  4379. return Result::error("更新失败", 0);
  4380. }
  4381. return Result::success($result);
  4382. }
  4383. public function delGood(array $data): array
  4384. {
  4385. $result = Good::where('id', $data['id'])->delete();
  4386. if (empty($result)) {
  4387. return Result::error("删除失败", 0);
  4388. }
  4389. return Result::success($result);
  4390. }
  4391. //20250226 产品列表
  4392. //20250306 求职信息
  4393. public function getJobHuntingList(array $data): array
  4394. {
  4395. $where = [];
  4396. if (isset($data['username']) && !empty($data['username'])) {
  4397. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4398. }
  4399. //status 1待审核2已审核3已拒绝
  4400. if (isset($data['status']) && $data['status'] != '') {
  4401. $where = [
  4402. 'job_hunting.status' => $data['status'],
  4403. ];
  4404. }
  4405. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4406. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4407. unset($data['type_id']);
  4408. if ($type_id != '10000') {
  4409. $where[] = ['job_hunting.user_id', '=', $user_id];
  4410. }
  4411. $result = JobHunting::where($where)
  4412. ->when(!empty($data['status1']), function ($query) use ($data) {
  4413. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4414. })
  4415. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4416. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4417. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  4418. ->orderBy("updated_at", "desc")
  4419. ->limit($data['page_size'])
  4420. ->offset(($data['page'] - 1) * $data['page_size'])
  4421. ->get();
  4422. if (empty($result)) {
  4423. return Result::error("查询失败", 0);
  4424. }
  4425. $count = JobHunting::where($where)
  4426. ->when(!empty($data['status1']), function ($query) use ($data) {
  4427. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4428. })
  4429. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4430. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4431. ->count();
  4432. $data = [
  4433. 'rows' => $result->toArray(),
  4434. 'count' => $count,
  4435. ];
  4436. return Result::success($data);
  4437. }
  4438. public function getJobHuntingApply(array $data): array
  4439. {
  4440. var_dump($data, '-----------------test--------1-');
  4441. $where = [];
  4442. if (isset($data['username']) && !empty($data['username'])) {
  4443. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4444. }
  4445. if (isset($data['salary']) && !empty($data['salary'])) {
  4446. $where[] = [
  4447. 'job_hunting.salary',
  4448. '=',
  4449. $data['salary'],
  4450. ];
  4451. }
  4452. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4453. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4454. unset($data['type_id']);
  4455. if ($type_id != '10000') {
  4456. $where[] = ['job_apply.receiver_id', '=', $user_id];
  4457. }
  4458. var_dump($where, '-----------------test---------');
  4459. $result = jobApply::where($where)
  4460. // ->when(!empty($data['status1']), function ($query) use ($data) {
  4461. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4462. // })
  4463. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  4464. ->where('job_enum.egroup', '=', 'income')
  4465. ->where('job_hunting.status', 2) //已审核
  4466. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4467. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4468. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4469. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4470. //职位----是申请职位
  4471. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4472. ->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')
  4473. ->orderBy("job_hunting.updated_at", "desc")
  4474. ->limit($data['page_size'])
  4475. ->offset(($data['page'] - 1) * $data['page_size'])
  4476. ->get();
  4477. if (empty($result)) {
  4478. return Result::error("查询失败", 0);
  4479. }
  4480. $count = jobApply::where($where)
  4481. ->where('job_enum.egroup', '=', 'income')
  4482. ->where('job_hunting.status', 2) //已审核
  4483. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4484. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4485. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4486. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4487. //职位----是申请职位
  4488. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4489. ->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')
  4490. ->count();
  4491. $data = [
  4492. 'rows' => $result->toArray(),
  4493. 'count' => $count,
  4494. ];
  4495. return Result::success($data);
  4496. }
  4497. public function addJobHunting(array $data): array
  4498. {
  4499. date_default_timezone_set('Asia/Shanghai');
  4500. unset($data['company_name']);
  4501. unset($data['job_industry']);
  4502. unset($data['job_name']);
  4503. unset($data['department']);
  4504. unset($data['job_timeList']);
  4505. unset($data['job_content']);
  4506. unset($data['job_typename']); //不知道这是啥,
  4507. $data['created_at'] = date('Y-m-d H:i:s');
  4508. $data['updated_at'] = date('Y-m-d H:i:s');
  4509. //根据用户 user_id 只能添加一次
  4510. $result = JobHunting::where('user_id', $data['user_id'])->first();
  4511. if (!empty($result)) {
  4512. return Result::error("您已添加过求职信息", 0);
  4513. }
  4514. var_dump($result, '-----------------test---------');
  4515. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  4516. if (is_string($data['city_arr_id'])) {
  4517. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4518. $cityArr = json_decode($data['city_arr_id'], true);
  4519. // 确保 $cityArr 是数组
  4520. if (is_array($cityArr)) {
  4521. $data['city_id'] = end($cityArr);
  4522. }
  4523. } else {
  4524. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4525. if (is_array($data['city_arr_id'])) {
  4526. $data['city_id'] = end($data['city_arr_id']);
  4527. }
  4528. }
  4529. }
  4530. // 处理求职所绑定栏目
  4531. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4532. if (is_string($data['cat_arr_id'])) {
  4533. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4534. // 先清理可能存在的无效 JSON 字符
  4535. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4536. $catArr = json_decode($cleanedCatArrStr, true);
  4537. // 检查 JSON 解码是否成功且结果是数组
  4538. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4539. $data['catid'] = end($catArr);
  4540. }
  4541. } else {
  4542. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4543. if (is_array($data['cat_arr_id'])) {
  4544. $data['catid'] = end($data['cat_arr_id']);
  4545. }
  4546. }
  4547. }
  4548. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4549. $this->sendMessage([
  4550. 'talk_type' => 600,
  4551. 'title' => $data['name'],
  4552. 'content' => '提交了审核',
  4553. 'messageType' => 11,
  4554. ]);
  4555. }
  4556. $result = JobHunting::create($data);
  4557. if (empty($result)) {
  4558. return Result::error("添加失败", 0);
  4559. }
  4560. return Result::success($result);
  4561. }
  4562. public function delJobHunting(array $data): array
  4563. {
  4564. $result = JobHunting::where('id', $data['id'])->delete();
  4565. if (empty($result)) {
  4566. return Result::error("删除失败", 0);
  4567. }
  4568. return Result::success($result);
  4569. }
  4570. public function updateJobHunting(array $data): array
  4571. {
  4572. //设置东八区
  4573. date_default_timezone_set('Asia/Shanghai');
  4574. unset($data['company_name']);
  4575. unset($data['job_industry']);
  4576. unset($data['job_name']);
  4577. unset($data['department']);
  4578. unset($data['job_timeList']);
  4579. unset($data['job_content']);
  4580. unset($data['job_typename']); //不知道这是啥,
  4581. $data['created_at'] = date('Y-m-d H:i:s');
  4582. $data['updated_at'] = date('Y-m-d H:i:s');
  4583. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4584. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4585. $cityArr = json_decode($data['city_arr_id'], true);
  4586. $data['city_id'] = end($cityArr);
  4587. } else {
  4588. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4589. $data['city_id'] = end($data['city_arr_id']);
  4590. }
  4591. // 处理求职所绑定栏目
  4592. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4593. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4594. $catArr = json_decode($data['cat_arr_id'], true);
  4595. $data['catid'] = end($catArr);
  4596. } else {
  4597. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4598. $data['catid'] = end($data['cat_arr_id']);
  4599. }
  4600. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4601. $this->sendMessage([
  4602. 'talk_type' => 600,
  4603. 'title' => $data['name'],
  4604. 'content' => '提交了审核',
  4605. 'messageType' => 11,
  4606. ]);
  4607. }
  4608. $result = JobHunting::where('id', $data['id'])->update($data);
  4609. if (empty($result)) {
  4610. return Result::error("更新失败", 0);
  4611. }
  4612. return Result::success($result);
  4613. }
  4614. public function getJobHuntingInfo(array $data): array
  4615. {
  4616. $result = JobHunting::where('id', $data['id'])->first();
  4617. if (empty($result)) {
  4618. return Result::error("查询失败", 0);
  4619. }
  4620. return Result::success($result);
  4621. }
  4622. public function getJobHuntingData(array $data): array
  4623. {
  4624. $jobEnum = JobEnum::get();
  4625. $jobIndustry = JobIndustry::get();
  4626. $jobNature = JobNature::get();
  4627. $jobPosition = JobPosition::get();
  4628. $data = [
  4629. 'jobEnum' => $jobEnum,
  4630. 'jobIndustry' => $jobIndustry,
  4631. 'jobNature' => $jobNature,
  4632. 'jobPosition' => $jobPosition,
  4633. ];
  4634. return Result::success($data);
  4635. }
  4636. public function delJobHuntingInfo(array $data): array
  4637. {
  4638. $result = JobHunting::where('id', $data['id'])->delete();
  4639. return Result::success();
  4640. }
  4641. //20250324 通知,公告,消息
  4642. public function delNotice(array $data): array
  4643. {
  4644. $result = Notice::where('id', $data['id'])->delete();
  4645. if ($result) {
  4646. return Result::success();
  4647. } else {
  4648. return Result::error("删除失败", 0);
  4649. }
  4650. }
  4651. public function getNoticeInfo(array $data): array
  4652. {
  4653. $result = Notice::where('id', $data['id'])->first();
  4654. // var_dump($result['re_user_ids'], '--------------------');
  4655. if (empty($result)) {
  4656. return Result::error("查询失败", 0);
  4657. }
  4658. return Result::success($result);
  4659. }
  4660. public function readNotice(array $data): array
  4661. {
  4662. $result = Notice::where('id', $data['id'])->first();
  4663. // var_dump($result['re_user_ids'], '--------------------');
  4664. if (empty($result)) {
  4665. return Result::error("查询失败", 0);
  4666. }
  4667. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4668. $re_user_ids = json_decode($result['re_user_ids'], true);
  4669. var_dump($re_user_ids, '--------------1---test---------');
  4670. var_dump($data, '--------------1---test---------');
  4671. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4672. //如果已经存在,就不再添加
  4673. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4674. $read_id = json_decode($result['read_id'], true);
  4675. if (!is_array($read_id)) {
  4676. $read_id = [];
  4677. }
  4678. if (!in_array($data['user_id'], $read_id)) {
  4679. $read_id[] = $data['user_id'];
  4680. $result['read_id'] = json_encode($read_id);
  4681. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4682. }
  4683. } else {
  4684. //如果不存在,就添加
  4685. $result['read_id'] = json_encode([$data['user_id']]);
  4686. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4687. }
  4688. }
  4689. return Result::success($result);
  4690. }
  4691. public function addNotice(array $data): array
  4692. {
  4693. date_default_timezone_set('Asia/Shanghai');
  4694. $data['created_at'] = date('Y-m-d H:i:s');
  4695. $data['updated_at'] = date('Y-m-d H:i:s');
  4696. // $data['level'] = "1,2,3,4,5";
  4697. $level = json_decode($data['level'], true);
  4698. $user_id = UserInfo::
  4699. //city_id不是null
  4700. whereNotNull('city_id')
  4701. ->whereNotNull('department_id')
  4702. ->where(function ($query) use ($data) {
  4703. $query->where(function ($subQuery) use ($data) {
  4704. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4705. });
  4706. })
  4707. ->where(function ($query) use ($data) {
  4708. $query->where(function ($subQuery) use ($data) {
  4709. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4710. });
  4711. })
  4712. ->when(isset($level) && is_array($level), function ($query) use ($level) {
  4713. $query->whereIn('level', $level);
  4714. })
  4715. ->pluck('user_id')->toArray();
  4716. $user_id = array_unique($user_id);
  4717. $chat_ids = $user_id;
  4718. $user_id = json_encode($user_id);
  4719. $data['re_user_ids'] = $user_id;
  4720. $this->sendMessage([
  4721. 'talk_type' => 700,
  4722. 'title' => $data['title'],
  4723. 'content' => '提交了审核',
  4724. 'messageType' => 5,
  4725. ]);
  4726. $result = Notice::insertGetId($data);
  4727. if (empty($result)) {
  4728. return Result::error("添加失败", 0);
  4729. }
  4730. return Result::success($result);
  4731. }
  4732. public function updateNotice(array $data): array
  4733. {
  4734. date_default_timezone_set('Asia/Shanghai');
  4735. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4736. $user_id = UserInfo::
  4737. //city_id不是null
  4738. whereNotNull('city_id')
  4739. ->whereNotNull('department_id')
  4740. ->where(function ($query) use ($data) {
  4741. $query->where(function ($subQuery) use ($data) {
  4742. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4743. });
  4744. })
  4745. ->where(function ($query) use ($data) {
  4746. $query->where(function ($subQuery) use ($data) {
  4747. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4748. });
  4749. })
  4750. ->pluck('user_id')->toArray();
  4751. $user_id = array_unique($user_id);
  4752. $user_id = json_encode($user_id);
  4753. $data['re_user_ids'] = $user_id;
  4754. $data['updated_at'] = date('Y-m-d H:i:s');
  4755. $this->sendMessage([
  4756. 'talk_type' => 700,
  4757. 'title' => $data['title'],
  4758. 'content' => '提交了审核',
  4759. 'messageType' => 5,
  4760. ]);
  4761. $result = Notice::where('id', $data['id'])->update($data);
  4762. return Result::success($result);
  4763. }
  4764. public function getNoticeList(array $data): array
  4765. {
  4766. $where = [];
  4767. //title
  4768. if (isset($data['title']) && !empty($data['title'])) {
  4769. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4770. }
  4771. //level
  4772. if (isset($data['level']) && !empty($data['level'])) {
  4773. $where[] = ['notice.level', '=', $data['level']];
  4774. }
  4775. //status
  4776. if (isset($data['status']) && !empty($data['status'])) {
  4777. $where[] = ['notice.status', '=', $data['status']];
  4778. }
  4779. //type
  4780. if (isset($data['type']) && !empty($data['type'])) {
  4781. $where[] = ['notice.type', '=', $data['type']];
  4782. }
  4783. var_dump($data, '------------11111-2----test---------');
  4784. if ($data['type_id'] == 10000) {
  4785. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4786. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4787. })
  4788. ->where($where)
  4789. ->orderBy('updated_at', 'desc')
  4790. ->limit($data['page_size'])
  4791. ->offset(($data['page'] - 1) * $data['page_size'])
  4792. ->get();
  4793. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4794. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4795. })
  4796. ->where($where)
  4797. ->orderBy('updated_at', 'desc')
  4798. ->count();
  4799. } else {
  4800. $result = Notice::where($where)
  4801. // ->where('user_id', $data['user_id'])
  4802. ->Where(function ($query) use ($data) {
  4803. $query->Where(function ($q) use ($data) {
  4804. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4805. ->orWhere('notice.user_id', $data['user_id']);
  4806. });
  4807. })
  4808. ->when(!empty($data['status1']), function ($query) use ($data) {
  4809. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4810. })
  4811. ->orderBy('updated_at', 'desc')
  4812. ->limit($data['page_size'])
  4813. ->offset(($data['page'] - 1) * $data['page_size'])
  4814. ->get();
  4815. $total = Notice::where($where)
  4816. ->when(!empty($data['status1']), function ($query) use ($data) {
  4817. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4818. })
  4819. // ->where('user_id', $data['user_id'])
  4820. ->Where(function ($query) use ($data) {
  4821. $query->Where(function ($q) use ($data) {
  4822. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4823. ->orWhere('notice.user_id', $data['user_id']);
  4824. });
  4825. })
  4826. ->count();
  4827. }
  4828. if (empty($result)) {
  4829. return Result::error("查询失败", 0);
  4830. }
  4831. $data = [
  4832. 'rows' => $result,
  4833. 'count' => $total,
  4834. ];
  4835. return Result::success($data);
  4836. }
  4837. public function noticeList(array $data): array
  4838. {
  4839. $where = [];
  4840. //title
  4841. if (isset($data['title']) && !empty($data['title'])) {
  4842. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4843. }
  4844. //level
  4845. if (isset($data['level']) && !empty($data['level'])) {
  4846. $where[] = ['notice.level', '=', $data['level']];
  4847. }
  4848. //status
  4849. if (isset($data['status']) && !empty($data['status'])) {
  4850. $where[] = ['notice.status', '=', $data['status']];
  4851. }
  4852. //type
  4853. if (isset($data['type']) && !empty($data['type'])) {
  4854. $where[] = ['notice.type', '=', $data['type']];
  4855. }
  4856. var_dump($data, '------------11111-2----test---------');
  4857. if ($data['type_id'] == 10000) {
  4858. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4859. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4860. })
  4861. ->where($where)
  4862. ->orderBy('updated_at', 'desc')
  4863. ->limit($data['page_size'])
  4864. ->offset(($data['page'] - 1) * $data['page_size'])
  4865. ->get();
  4866. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4867. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4868. })
  4869. ->where($where)
  4870. ->orderBy('updated_at', 'desc')
  4871. ->count();
  4872. } else {
  4873. $result = Notice::where($where)
  4874. // ->where('user_id', $data['user_id'])
  4875. ->Where(function ($query) use ($data) {
  4876. $query->Where(function ($q) use ($data) {
  4877. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4878. ->orWhere('notice.user_id', $data['user_id']);
  4879. });
  4880. })
  4881. ->when(!empty($data['status1']), function ($query) use ($data) {
  4882. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4883. })
  4884. ->orderBy('updated_at', 'desc')
  4885. ->limit($data['page_size'])
  4886. ->offset(($data['page'] - 1) * $data['page_size'])
  4887. ->get();
  4888. $total = Notice::where($where)
  4889. ->when(!empty($data['status1']), function ($query) use ($data) {
  4890. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4891. })
  4892. // ->where('user_id', $data['user_id'])
  4893. ->Where(function ($query) use ($data) {
  4894. $query->Where(function ($q) use ($data) {
  4895. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4896. ->orWhere('notice.user_id', $data['user_id']);
  4897. });
  4898. })
  4899. ->count();
  4900. }
  4901. if (empty($result)) {
  4902. return Result::error("查询失败", 0);
  4903. }
  4904. $data = [
  4905. 'rows' => $result,
  4906. 'count' => $total,
  4907. ];
  4908. return Result::success($data);
  4909. }
  4910. public function getNoticeDetail(array $data): array
  4911. {
  4912. $result = Notice::where('id', $data['id'])->first();
  4913. if (empty($result)) {
  4914. return Result::error("查询失败", 0);
  4915. }
  4916. return Result::success($result);
  4917. }
  4918. public function deleteNotice(array $data): array
  4919. {
  4920. $notice = Notice::where('id', $data['id'])->first();
  4921. if (empty($notice)) {
  4922. return Result::error("删除失败", 0);
  4923. }
  4924. $chat_group_id = $notice->group_id;
  4925. if ($chat_group_id) {
  4926. //删除群聊
  4927. ChatGroups::where('id', $chat_group_id)->delete();
  4928. //删除群成员
  4929. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4930. //删除群聊记录
  4931. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4932. }
  4933. $result = Notice::where('id', $data['id'])->delete();
  4934. return Result::success($result);
  4935. }
  4936. public function complaintList(array $data): array
  4937. {
  4938. var_dump($data, '---------1---------');
  4939. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4940. unset($data['type_id']);
  4941. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4942. $where = [];
  4943. if ($type_id != 10000 && empty($data['deal_user'])) {
  4944. // $where['complaint.user_id'] = $user_id;
  4945. }
  4946. if (!empty($data['title'])) {
  4947. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4948. }
  4949. if (!empty($data['department_id'])) {
  4950. $where['complaint.department_id'] = $data['department_id'];
  4951. }
  4952. if (!empty($data['deal'])) {
  4953. $where['complaint.deal'] = $data['deal'];
  4954. }
  4955. if (!empty($data['status'])) {
  4956. $where['complaint.status'] = $data['status'];
  4957. }
  4958. var_dump(!empty($data['deal_user']), '----------1');
  4959. var_dump($where, '----------2');
  4960. $result = Complaint::where($where)
  4961. ->when(!empty($data['status1']), function ($query) use ($data) {
  4962. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4963. })
  4964. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4965. //json re_user_ids data[user_id]是不是在里面
  4966. $query->Where(function ($q) use ($data) {
  4967. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4968. ->where('complaint.status', 2);
  4969. });
  4970. })
  4971. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4972. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4973. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4974. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4975. ->orderBy('updated_at', 'desc')
  4976. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4977. //sql输出
  4978. if (empty($result)) {
  4979. return Result::error("暂无投诉信息", 0);
  4980. }
  4981. // 取出数据
  4982. $rows = $result->items();
  4983. $count = $result->total();
  4984. $responseData = [
  4985. 'rows' => $rows,
  4986. 'count' => $count,
  4987. ];
  4988. return Result::success($responseData);
  4989. }
  4990. public function getComplaintList(array $data): array
  4991. {
  4992. var_dump($data, '00000001000000000000');
  4993. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4994. unset($data['type_id']);
  4995. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4996. $where = [];
  4997. if ($type_id != 10000 && empty($data['deal_user'])) {
  4998. $where['complaint.user_id'] = $user_id;
  4999. }
  5000. if (!empty($data['title'])) {
  5001. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  5002. }
  5003. if (!empty($data['department_id'])) {
  5004. $where['complaint.department_id'] = $data['department_id'];
  5005. }
  5006. if (!empty($data['deal'])) {
  5007. $where['complaint.deal'] = $data['deal'];
  5008. }
  5009. if (!empty($data['status'])) {
  5010. $where['complaint.status'] = $data['status'];
  5011. }
  5012. var_dump(!empty($data['deal_user']), '----------1');
  5013. var_dump($where, '----------2');
  5014. $result = Complaint::where($where)
  5015. ->when(!empty($data['status1']), function ($query) use ($data) {
  5016. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  5017. })
  5018. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  5019. // //json re_user_ids data[user_id]是不是在里面
  5020. // $query->Where(function ($q) use ($data) {
  5021. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  5022. // ->where('complaint.status', 2);
  5023. // });
  5024. // })
  5025. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  5026. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  5027. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  5028. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  5029. ->orderBy('updated_at', 'desc')
  5030. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5031. //sql输出
  5032. if (empty($result)) {
  5033. return Result::error("暂无投诉信息", 0);
  5034. }
  5035. // 取出数据
  5036. $rows = $result->items();
  5037. $count = $result->total();
  5038. $responseData = [
  5039. 'rows' => $rows,
  5040. 'count' => $count,
  5041. ];
  5042. return Result::success($responseData);
  5043. }
  5044. public function getComplaintInfo(array $data): array
  5045. {
  5046. $result = Complaint::where('id', $data['id'])->first();
  5047. if (empty($result)) {
  5048. return Result::error("查询失败", 0);
  5049. }
  5050. return Result::success($result);
  5051. }
  5052. public function readComplaint(array $data): array
  5053. {
  5054. $result = Complaint::where('id', $data['id'])->first();
  5055. if (empty($result)) {
  5056. return Result::error("查询失败", 0);
  5057. }
  5058. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  5059. $re_user_ids = json_decode($result['re_user_ids'], true);
  5060. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  5061. //如果已经存在,就不再添加
  5062. if (isset($result['read_id']) && !empty($result['read_id'])) {
  5063. $read_id = json_decode($result['read_id'], true);
  5064. if (!is_array($read_id)) {
  5065. $read_id = [];
  5066. }
  5067. if (!in_array($data['user_id'], $read_id)) {
  5068. $read_id[] = $data['user_id'];
  5069. $result['read_id'] = json_encode($read_id);
  5070. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  5071. }
  5072. } else {
  5073. //如果不存在,就添加
  5074. $result['read_id'] = json_encode([$data['user_id']]);
  5075. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  5076. }
  5077. }
  5078. return Result::success($result);
  5079. }
  5080. public function addComplaint(array $data): array
  5081. {
  5082. date_default_timezone_set('Asia/Shanghai');
  5083. $data['created_at'] = date('Y-m-d H:i:s');
  5084. $data['updated_at'] = date('Y-m-d H:i:s');
  5085. $this->sendMessage([
  5086. 'talk_type' => 800,
  5087. 'title' => $data['title'],
  5088. 'content' => '提交了审核',
  5089. 'messageType' => 6,
  5090. ]);
  5091. $result = Complaint::create($data);
  5092. return Result::success($result);
  5093. }
  5094. public function updateComplaint(array $data): array
  5095. {
  5096. date_default_timezone_set('Asia/Shanghai');
  5097. $data['updated_at'] = date('Y-m-d H:i:s');
  5098. $user_id = $data['user_id'] ?? 0;
  5099. $type_id = $data['type_id'] ?? 0;
  5100. unset($data['user_id']);
  5101. unset($data['type_id']);
  5102. $this->sendMessage([
  5103. 'talk_type' => 800,
  5104. 'title' => $data['title'],
  5105. 'content' => '提交了审核',
  5106. 'messageType' => 6,
  5107. ]);
  5108. $result = Complaint::where('id', $data['id'])->update($data);
  5109. return Result::success($result);
  5110. }
  5111. public function deleteComplaint(array $data): array
  5112. {
  5113. $result = Complaint::where('id', $data['id'])->delete();
  5114. return Result::success($result);
  5115. }
  5116. public function getComplainInfo(array $data): array
  5117. {
  5118. $result = Complaint::where('id', $data['id'])->first();
  5119. if (empty($result)) {
  5120. return Result::error("查询失败", 0);
  5121. }
  5122. return Result::success($result);
  5123. }
  5124. public function updateComplaintStatus(array $data): array
  5125. {
  5126. date_default_timezone_set('Asia/Shanghai');
  5127. $data['updated_at'] = date('Y-m-d H:i:s');
  5128. $user_id = $data['user_id'] ?? 0;
  5129. $type_id = $data['type_id'] ?? 0;
  5130. unset($data['user_id']);
  5131. unset($data['type_id']);
  5132. //处理, 写入处理人
  5133. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  5134. $data['real_deal_user'] = $user_id;
  5135. }
  5136. //如果是deal 23,则判断是不是处理人
  5137. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  5138. $complaintInof = Complaint::where('id', $data['id'])
  5139. ->where('real_deal_user', $user_id)
  5140. ->first();
  5141. if (empty($complaintInof)) {
  5142. return Result::error("处理人错误", 0);
  5143. }
  5144. }
  5145. $complaintInfo = Complaint::where('id', $data['id'])->first();
  5146. if ($data['status'] == 1) {
  5147. $this->sendMessage([
  5148. 'talk_type' => 800,
  5149. 'title' => $complaintInfo['title'],
  5150. 'content' => '提交了审核',
  5151. 'messageType' => 6,
  5152. ]);
  5153. }
  5154. if ($data['status'] == 2 && !isset($data['deal'])) {
  5155. $this->sendMessage([
  5156. 'talk_type' => 801,
  5157. 'title' => $complaintInfo['title'],
  5158. 'content' => '审核通过',
  5159. 'messageType' => 6,
  5160. 'user_id' => $complaintInfo['user_id'],
  5161. ]);
  5162. $this->sendMessage([
  5163. 'talk_type' => 802,
  5164. 'title' => $complaintInfo['title'],
  5165. 'content' => '待处理',
  5166. 'messageType' => 6,
  5167. 'user_id' => $complaintInfo['re_user_ids'],
  5168. ]);
  5169. }
  5170. if ($data['status'] == 3 && !isset($data['deal'])) {
  5171. $this->sendMessage([
  5172. 'talk_type' => 801,
  5173. 'title' => $complaintInfo['title'],
  5174. 'content' => '审核拒绝',
  5175. 'messageType' => 6,
  5176. 'user_id' => $complaintInfo['user_id'],
  5177. ]);
  5178. }
  5179. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  5180. $this->sendMessage([
  5181. 'talk_type' => 802,
  5182. 'title' => $complaintInfo['title'],
  5183. 'content' => '处理中',
  5184. 'messageType' => 6,
  5185. 'user_id' => $complaintInfo['re_user_ids'],
  5186. ]);
  5187. }
  5188. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  5189. $this->sendMessage([
  5190. 'talk_type' => 802,
  5191. 'title' => $complaintInfo['title'],
  5192. 'content' => '不予处理',
  5193. 'messageType' => 6,
  5194. 'user_id' => $complaintInfo['re_user_ids'],
  5195. ]);
  5196. }
  5197. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  5198. $this->sendMessage([
  5199. 'talk_type' => 802,
  5200. 'title' => $complaintInfo['title'],
  5201. 'content' => '已完结',
  5202. 'messageType' => 6,
  5203. 'user_id' => $complaintInfo['re_user_ids'],
  5204. ]);
  5205. }
  5206. $result = complaint::where('id', $data['id'])->update($data);
  5207. return Result::success($result);
  5208. }
  5209. public function updateGoodStatus(array $data): array
  5210. {
  5211. $user_id = $data['user_id'] ?? 0;
  5212. $type_id = $data['type_id'] ?? 0;
  5213. unset($data['user_id']);
  5214. unset($data['type_id']);
  5215. $goodInfo = Good::where('id', $data['id'])->first();
  5216. if ($data['status'] == 2) {
  5217. $this->sendMessage([
  5218. 'talk_type' => 201,
  5219. 'title' => $goodInfo['name'],
  5220. 'content' => '审核通过',
  5221. 'messageType' => 3,
  5222. 'user_id' => $goodInfo['user_id'],
  5223. ]);
  5224. }
  5225. if ($data['status'] == 3) {
  5226. $this->sendMessage([
  5227. 'talk_type' => 201,
  5228. 'title' => $goodInfo['name'],
  5229. 'content' => '审核拒绝',
  5230. 'messageType' => 3,
  5231. 'user_id' => $goodInfo['user_id'],
  5232. ]);
  5233. }
  5234. if ($data['status'] == 1) {
  5235. $this->sendMessage([
  5236. 'talk_type' => 200,
  5237. 'title' => $goodInfo['name'],
  5238. 'content' => '提交了审核',
  5239. 'messageType' => 3,
  5240. ]);
  5241. }
  5242. $result = Good::where('id', $data['id'])->update($data);
  5243. return Result::success($result);
  5244. }
  5245. public function updateJobHuntingStatus(array $data): array
  5246. {
  5247. $user_id = $data['user_id'] ?? 0;
  5248. $type_id = $data['type_id'] ?? 0;
  5249. unset($data['user_id']);
  5250. unset($data['type_id']);
  5251. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  5252. if ($data['status'] == 2) {
  5253. $this->sendMessage([
  5254. 'talk_type' => 601,
  5255. 'title' => $jogHuntingInfo['name'],
  5256. 'content' => '审核通过',
  5257. 'messageType' => 11,
  5258. 'user_id' => $jogHuntingInfo['user_id'],
  5259. ]);
  5260. }
  5261. if ($data['status'] == 3) {
  5262. $this->sendMessage([
  5263. 'talk_type' => 601,
  5264. 'title' => $jogHuntingInfo['name'],
  5265. 'content' => '审核拒绝',
  5266. 'messageType' => 11,
  5267. 'user_id' => $jogHuntingInfo['user_id'],
  5268. ]);
  5269. }
  5270. if ($data['status'] == 1) {
  5271. $this->sendMessage([
  5272. 'talk_type' => 600,
  5273. 'title' => $jogHuntingInfo['name'],
  5274. 'content' => '提交了审核',
  5275. 'messageType' => 11,
  5276. ]);
  5277. }
  5278. $result = JobHunting::where('id', $data['id'])->update($data);
  5279. return Result::success($result);
  5280. }
  5281. public function updateNoticeStatus(array $data): array
  5282. {
  5283. $user_id = $data['user_id'] ?? 0;
  5284. $type_id = $data['type_id'] ?? 0;
  5285. unset($data['user_id']);
  5286. unset($data['type_id']);
  5287. //查询公告
  5288. $notice = Notice::where('id', $data['id'])->first();
  5289. if (empty($notice)) {
  5290. return Result::error("公告不存在", 0);
  5291. }
  5292. //$chat_ids 去除掉$data['user_id']
  5293. $chat_ids = json_decode($notice['re_user_ids'], true);
  5294. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  5295. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  5296. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  5297. //chat_group
  5298. $group_id = PublicData::uuid();
  5299. $groupData = [
  5300. 'id' => $group_id,
  5301. 'creator_id' => $notice['user_id'],
  5302. 'group_name' => $notice['group_name'] ?? '',
  5303. 'profile' => $notice['profile'] ?? 0,
  5304. ];
  5305. var_dump($groupData, '-----------------groupData-------');
  5306. $groupResult = ChatGroups::insertGetId($groupData);
  5307. var_dump($groupResult, '-----------------groupid-------');
  5308. $groupMemberData = [
  5309. 'id' => PublicData::uuid(),
  5310. 'user_id' => $notice['user_id'],
  5311. 'group_id' => $group_id,
  5312. 'leader' => 2,
  5313. ];
  5314. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  5315. //插入群成员表
  5316. $groupMemberDataUser = [];
  5317. $chatData = [];
  5318. foreach ($chat_ids as $key => $value) {
  5319. $groupMemberDataUser[] = [
  5320. 'id' => PublicData::uuid(),
  5321. 'user_id' => $value,
  5322. 'group_id' => $group_id,
  5323. 'leader' => 1,
  5324. ];
  5325. $chatData[] = [
  5326. 'user_id' => $value,
  5327. 'msg_type' => 1,
  5328. 'receiver_id' => $group_id,
  5329. 'content' => '通过通知创建群聊',
  5330. 'group_receiver_id' => $notice['user_id'],
  5331. 'action' => 'recieved',
  5332. 'created_at' => date('Y-m-d H:i:s'),
  5333. ];
  5334. }
  5335. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  5336. ChatGroupsMember::insert($groupMemberDataUser);
  5337. //插入一条管理员聊天记录
  5338. $chatData[] = [
  5339. 'user_id' => $notice['user_id'],
  5340. 'msg_type' => 1,
  5341. 'receiver_id' => $group_id,
  5342. 'content' => '通过通知创建群聊',
  5343. 'group_receiver_id' => $notice['user_id'],
  5344. 'action' => 'said',
  5345. 'created_at' => date('Y-m-d H:i:s'),
  5346. ];
  5347. var_dump($chatData, '-----------------chatData-------');
  5348. $chatResult = ChatRecords::insert($chatData);
  5349. //处理imp
  5350. $group = [
  5351. 'type' => 1,
  5352. 'name' => $notice['group_name'] ?? '',
  5353. 'profile' => '',
  5354. 'avatar' => '',
  5355. 'creator_id' => $notice['user_id'],
  5356. ];
  5357. $groupResult = GroupImp::insertGetId($group);
  5358. var_dump($groupResult, '获取imp group_id');
  5359. $groupMember = [
  5360. 'user_id' => $notice['user_id'],
  5361. 'group_id' => $groupResult,
  5362. 'leader' => 1,
  5363. 'join_time' => Date('Y-m-d H:i:s')
  5364. ];
  5365. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  5366. $talk_session = [
  5367. 'user_id' => $notice['user_id'],
  5368. 'to_from_id' => $groupResult,
  5369. 'talk_mode' => 2,
  5370. 'created_at' => Date('Y-m-d H:i:s'),
  5371. 'updated_at' => Date('Y-m-d H:i:s'),
  5372. ];
  5373. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  5374. //被通知人员处理
  5375. foreach ($chat_ids as $key => $value) {
  5376. $groupMemberdata[] = [
  5377. 'user_id' => $value,
  5378. 'group_id' => $groupResult,
  5379. 'leader' => 3,
  5380. 'join_time' => Date('Y-m-d H:i:s')
  5381. ];
  5382. $talk_sessionData[] = [
  5383. 'user_id' => $value,
  5384. 'to_from_id' => $groupResult,
  5385. 'talk_mode' => 2,
  5386. 'created_at' => Date('Y-m-d H:i:s'),
  5387. 'updated_at' => Date('Y-m-d H:i:s'),
  5388. ];
  5389. }
  5390. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  5391. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  5392. $group_id = $groupResult;
  5393. //更新result的 group_id
  5394. $data['group_id'] = $group_id;
  5395. Notice::where(['id' => $data['id']])->update($data);
  5396. }
  5397. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  5398. //删除掉信息
  5399. GroupImp::where('id', $notice['group_id'])->delete();
  5400. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  5401. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  5402. foreach ($chat_ids as $key => $value) {
  5403. }
  5404. //聊天记录删除
  5405. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  5406. $data['group_id'] = null;
  5407. Notice::where(['id' => $data['id']])->update($data);
  5408. }
  5409. $result = Notice::where('id', $data['id'])->update($data);
  5410. $noticeInfo = Notice::where('id', $data['id'])->first();
  5411. if ($data['status'] == 2) {
  5412. $this->sendMessage([
  5413. 'talk_type' => 701,
  5414. 'title' => $noticeInfo['title'],
  5415. 'content' => '审核通过',
  5416. 'messageType' => 3,
  5417. 'user_id' => $noticeInfo['user_id'],
  5418. ]);
  5419. }
  5420. if ($data['status'] == 3) {
  5421. $this->sendMessage([
  5422. 'talk_type' => 701,
  5423. 'title' => $noticeInfo['title'],
  5424. 'content' => '审核拒绝',
  5425. 'messageType' => 3,
  5426. 'user_id' => $noticeInfo['user_id'],
  5427. ]);
  5428. }
  5429. if ($data['status'] == 1) {
  5430. $this->sendMessage([
  5431. 'talk_type' => 700,
  5432. 'title' => $noticeInfo['title'],
  5433. 'content' => '提交了审核',
  5434. 'messageType' => 3,
  5435. ]);
  5436. }
  5437. return Result::success($result);
  5438. }
  5439. public function getDUser(array $data): array
  5440. {
  5441. if (!empty($data['ids'])) {
  5442. $user = User::whereIn('id', $data['ids'])->getall();
  5443. if (empty($user)) {
  5444. return Result::error('无数据', 0);
  5445. }
  5446. return Result::success($user);
  5447. }
  5448. $where = [];
  5449. if (!empty($data['department_id'])) {
  5450. $where['department_id'] = $data['department_id'];
  5451. }
  5452. if (!empty($data['city_id'])) {
  5453. $where['city_id'] = $data['city_id'];
  5454. }
  5455. $result = User::where('type_id', 2)
  5456. ->where('status', 1)
  5457. ->where($where)
  5458. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  5459. ->get();
  5460. if (empty($result)) {
  5461. return Result::error("查询失败", 0);
  5462. }
  5463. return Result::success($result);
  5464. }
  5465. /**
  5466. * 验证导航名称是否重复
  5467. * @return void
  5468. */
  5469. public function checkCategoryName(array $data): array
  5470. {
  5471. $result = Category::when($data, function ($query) use ($data) {
  5472. if (isset($data['name']) && $data['name']) {
  5473. $query->where("name", $data['name']);
  5474. }
  5475. if (isset($data['id']) && $data['id']) {
  5476. $query->where("id", "!=", $data['id']);
  5477. }
  5478. })->first();
  5479. if ($result) {
  5480. return Result::error("已存在");
  5481. } else {
  5482. return Result::success();
  5483. }
  5484. }
  5485. //20250226 产品列表
  5486. // 20250306 -------招聘--------fr
  5487. /*
  5488. * 招聘列表
  5489. * */
  5490. public function getJobRecruitingList(array $data): array
  5491. {
  5492. $where = [];
  5493. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  5494. if ($data['checkout'] == 0) {
  5495. $job_status = [0, 2];
  5496. } else {
  5497. $job_status = [1];
  5498. }
  5499. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5500. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  5501. }
  5502. $user = User::where('id', $data['user_id'])->first();
  5503. if (empty($user)) {
  5504. return Result::error("用户不存在", 0);
  5505. }
  5506. // 3:企业会员
  5507. if ($user['type_id'] == 3) {
  5508. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  5509. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  5510. }
  5511. // 如果 $where 为空,则不添加 where 条件
  5512. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5513. return $query->where($where);
  5514. })
  5515. ->whereIn('job_recruiting.status', $job_status)
  5516. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5517. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  5518. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  5519. ->orderBy("updated_at", "desc")
  5520. ->offset(($data['page'] - 1) * $data['page_size'])
  5521. ->limit($data['page_size'])
  5522. ->get()
  5523. ->all();
  5524. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5525. return $query->where($where);
  5526. })
  5527. ->whereIn('job_recruiting.status', $job_status)
  5528. ->count();
  5529. if (empty($result)) {
  5530. return Result::error("暂无招聘信息", 0);
  5531. }
  5532. return Result::success($result);
  5533. }
  5534. /*
  5535. * 招聘信息添加
  5536. * */
  5537. public function addJobRecruiting(array $data): array
  5538. {
  5539. // var_dump('添加招聘进入news------data',$data);
  5540. // return Result::success($data);
  5541. $user = User::where('user.id', $data['user_id'])
  5542. ->where('user.status', 1)
  5543. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5544. ->select(
  5545. 'user.type_id',
  5546. 'user.mobile',
  5547. 'user.email',
  5548. 'user_info.business_name',
  5549. 'user_info.company_hy_id',
  5550. 'user_info.company_nature',
  5551. 'user_info.company_size',
  5552. 'user_info.introduction',
  5553. 'user_info.real_name',
  5554. 'user_info.company_url',
  5555. 'user_info.address_arr_id',
  5556. 'user_info.address'
  5557. )
  5558. ->first();
  5559. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5560. return Result::error("用户不存在", 0);
  5561. }
  5562. $web = Website::where('id', $data['website_id'])->first();
  5563. if (empty($web)) {
  5564. return Result::error("网站不存在", 0);
  5565. }
  5566. // var_dump('添加招聘进入news---user---user',$user);
  5567. // 处理招聘关键词
  5568. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5569. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5570. } else {
  5571. Jieba::init(); // 初始化 jieba-php
  5572. Finalseg::init();
  5573. $segList = Jieba::cut($data['title']);
  5574. $segList1 = array_slice($segList, 0, 8);
  5575. $data['keyword'] = implode(',', $segList1);
  5576. }
  5577. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5578. $content = $data['description'];
  5579. // 去除 <style> 和 <script> 标签及其内容
  5580. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5581. // 去除所有 HTML 标签
  5582. $content = strip_tags($content);
  5583. // 去除 HTML 实体
  5584. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5585. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5586. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5587. // 去除多余空白
  5588. $content = preg_replace('/\s+/u', '', $content);
  5589. // 截取 100 个字符
  5590. $data['seo_description'] = mb_substr($content, 0, 100);
  5591. }
  5592. // return Result::success($user);
  5593. $data['action_id'] = $data['user_id'] ?? null;
  5594. $data['user_type'] = $user['type_id'] ?? null;
  5595. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5596. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5597. $data['catid'] = end($data['cat_arr_id']);
  5598. } else {
  5599. $data['catid'] = 0;
  5600. }
  5601. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5602. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5603. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5604. // 公司地址 管理员必填
  5605. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5606. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5607. // 管理员-企业相关信息
  5608. $company = [
  5609. // 'user_id' => $data['user_id']?? null,
  5610. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5611. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5612. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5613. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5614. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5615. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5616. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5617. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5618. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5619. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5620. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5621. ];
  5622. //去掉相关企业信息
  5623. $job = array_diff_key($data, array_flip(array_keys($company)));
  5624. // var_dump('添加招聘进入news---job---user',$job);
  5625. Db::beginTransaction();
  5626. try {
  5627. // // 先添加职位相关信息
  5628. if ($user['type_id'] == 10000) {
  5629. $job['status'] = 1;
  5630. }
  5631. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5632. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5633. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5634. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5635. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5636. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5637. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5638. // return Result::success($job);
  5639. $jobId = JobRecruiting::insertGetId($job);
  5640. if (empty($jobId)) {
  5641. Db::rollBack();
  5642. return Result::error("添加失败");
  5643. }
  5644. // 添加公司信息
  5645. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5646. $company['job_id'] = $jobId;
  5647. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5648. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5649. if ($user['type_id'] == 10000) {
  5650. // 管理员添加企业信息
  5651. $companyId = JobCompany::insertGetId($company);
  5652. if (empty($companyId)) {
  5653. Db::rollBack();
  5654. return Result::error("添加失败");
  5655. }
  5656. } else {
  5657. // 企业会员添加企业信息
  5658. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5659. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5660. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5661. $company['job_id'] = $jobId;
  5662. $companyId = JobCompany::insertGetId($company);
  5663. if (empty($companyId)) {
  5664. Db::rollBack();
  5665. return Result::error("添加失败");
  5666. }
  5667. }
  5668. Db::commit();
  5669. $result = [
  5670. 'job_id' => $jobId,
  5671. 'company_id' => $companyId,
  5672. ];
  5673. return Result::success($result);
  5674. } catch (\Exception $e) {
  5675. Db::rollBack();
  5676. return Result::error($e->getMessage(), 0);
  5677. }
  5678. // return Result::success($result);
  5679. }
  5680. /*
  5681. * 获取招聘信息详情
  5682. * */
  5683. public function getJobRecruitingInfo(array $data): array
  5684. {
  5685. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5686. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5687. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5688. ->select(
  5689. 'job_recruiting.*',
  5690. 'website.website_name as website_name',
  5691. 'job_company.business_name',
  5692. 'job_company.company_hy_id',
  5693. 'job_company.company_size',
  5694. 'job_company.company_nature',
  5695. 'job_company.introduction',
  5696. 'job_company.real_name',
  5697. 'job_company.mobile',
  5698. 'job_company.company_url',
  5699. 'job_company.address_arr_id',
  5700. 'job_company.address',
  5701. 'job_company.email'
  5702. )
  5703. ->first();
  5704. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5705. if (!empty($cityId)) {
  5706. if (isset($cityId[1]) && $cityId[1] != null) {
  5707. $city = District::where('id', $cityId[1])->first(['name']);
  5708. } else {
  5709. $city = District::where('id', $cityId[0])->first(['name']);
  5710. }
  5711. $result['city'] = $city['name'] ?? '';
  5712. }
  5713. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5714. if (is_array($addressId) && !empty($addressId)) {
  5715. $address = District::whereIn('id', $addressId)
  5716. ->orderBy('level', 'asc')
  5717. ->get(['name'])
  5718. ->pluck('name')
  5719. ->implode('');
  5720. // $job->address_name = $address ?? '';
  5721. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5722. }
  5723. if (empty($result)) {
  5724. return Result::error("招聘信息不存在", 0);
  5725. }
  5726. // return Result::success($job);
  5727. return Result::success($result);
  5728. }
  5729. /*
  5730. * 修改招聘信息
  5731. * */
  5732. public function upJobRecruiting(array $data): array
  5733. {
  5734. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5735. // return Result::success($job);
  5736. if (empty($job)) {
  5737. return Result::error("招聘信息不存在", 0);
  5738. }
  5739. $user = User::where('id', $data['user_id'])->first();
  5740. // return Result::success($user);
  5741. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5742. return Result::error("用户不存在", 0);
  5743. }
  5744. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5745. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5746. }
  5747. // 处理招聘关键词
  5748. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5749. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5750. } else {
  5751. Jieba::init(); // 初始化 jieba-php
  5752. Finalseg::init();
  5753. $segList = Jieba::cut($data['title']);
  5754. $segList1 = array_slice($segList, 0, 8);
  5755. $data['keyword'] = implode(',', $segList1);
  5756. }
  5757. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5758. $content = $data['description'];
  5759. // 去除 <style> 和 <script> 标签及其内容
  5760. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5761. // 去除所有 HTML 标签
  5762. $content = strip_tags($content);
  5763. // 去除 HTML 实体
  5764. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5765. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5766. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5767. // 去除多余空白
  5768. $content = preg_replace('/\s+/u', '', $content);
  5769. // 截取 100 个字符
  5770. $data['seo_description'] = mb_substr($content, 0, 100);
  5771. }
  5772. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5773. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5774. $data['catid'] = end($data['cat_arr_id']);
  5775. } else {
  5776. }
  5777. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5778. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5779. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5780. // 公司地址 管理员必填
  5781. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5782. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5783. // 管理员-企业相关信息
  5784. $company = [
  5785. // 'user_id' => $data['user_id']?? null,
  5786. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5787. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5788. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5789. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5790. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5791. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5792. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5793. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5794. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5795. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5796. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5797. ];
  5798. //去掉相关企业信息
  5799. $data = array_diff_key($data, array_flip(array_keys($company)));
  5800. $jobId = $data['id'];
  5801. $web = $data['website_id'];
  5802. $data['action_id'] = $data['user_id'];
  5803. unset($data['user_id']);
  5804. unset($data['user_type']);
  5805. unset($data['id']);
  5806. unset($data['website_id']);
  5807. // return Result::success($data);
  5808. Db::beginTransaction();
  5809. try {
  5810. // 管理员修改招聘信息
  5811. if ($user['type_id'] == 10000) {
  5812. $data['website_id'] = $web;
  5813. $company['website_id'] = $data['website_id'];
  5814. $data['status'] = 1;
  5815. } else {
  5816. $data['status'] = 0;
  5817. }
  5818. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5819. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5820. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5821. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5822. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5823. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5824. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5825. // return Result::success($job);
  5826. // Db::rollBack();
  5827. // return Result::success($company);
  5828. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5829. $this->sendMessage([
  5830. 'talk_type' => 500,
  5831. 'title' => $data['title'],
  5832. 'content' => '提交了审核',
  5833. 'messageType' => 10,
  5834. ]);
  5835. }
  5836. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5837. if (empty($result['job'])) {
  5838. Db::rollBack();
  5839. return Result::error("修改招聘信息失败");
  5840. }
  5841. // 管理员修改企业相关信息
  5842. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5843. if (empty($result['company'])) {
  5844. Db::rollBack();
  5845. return Result::error("修改企业相关信息失败");
  5846. }
  5847. Db::commit();
  5848. // return Result::success($result);
  5849. } catch (\Exception $e) {
  5850. Db::rollBack();
  5851. return Result::error($e->getMessage(), 0);
  5852. }
  5853. return Result::success($result);
  5854. }
  5855. /*
  5856. * 招聘信息删除
  5857. * */
  5858. public function delJobRecruiting(array $data): array
  5859. {
  5860. $user = User::where('id', $data['user_id'])->first();
  5861. if (empty($user)) {
  5862. return Result::error("用户不存在", 0);
  5863. }
  5864. $job = JobRecruiting::where('id', $data['id'])->first();
  5865. if (empty($job)) {
  5866. return Result::error("招聘信息不存在", 0);
  5867. }
  5868. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5869. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5870. }
  5871. Db::beginTransaction();
  5872. try {
  5873. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5874. if (empty($result['job'])) {
  5875. Db::rollBack();
  5876. return Result::error("删除招聘信息失败");
  5877. }
  5878. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5879. if (empty($result['company'])) {
  5880. Db::rollBack();
  5881. return Result::error("删除企业相关信息失败");
  5882. }
  5883. Db::commit();
  5884. } catch (\Exception $e) {
  5885. Db::rollBack();
  5886. return Result::error($e->getMessage(), 0);
  5887. }
  5888. return Result::success($result);
  5889. }
  5890. /*
  5891. * 获取公司信息
  5892. * */
  5893. public function getJobCompany(array $data): array
  5894. {
  5895. $user = User::where('user.id', $data['user_id'])
  5896. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5897. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5898. ->first();
  5899. // return Result::success($user);
  5900. if (empty($user)) {
  5901. return Result::error("用户不存在", 0);
  5902. }
  5903. if ($user['type_id'] == 3) {
  5904. $result = [
  5905. // 'id' => 0,
  5906. 'user_id' => $data['user_id'],
  5907. 'website_id' => $data['website_id'],
  5908. 'business_name' => $user['business_name'], // 企业名称
  5909. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5910. 'company_nature' => $user['company_nature'], // 公司性质
  5911. 'company_size' => $user['company_size'], // 公司规模
  5912. 'introduction' => $user['introduction'], // 公司简介
  5913. 'real_name' => $user['real_name'], // 企业联系人
  5914. 'mobile' => $user['mobile'], // 企业联系电话
  5915. 'company_url' => $user['company_url'], // 企业网址
  5916. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5917. 'address' => $user['address'], // 企业地址
  5918. 'email' => $user['email'], // 企业邮箱
  5919. ];
  5920. } else {
  5921. return Result::error("用户类型错误", 0);
  5922. }
  5923. if (empty($result)) {
  5924. return Result::error("公司信息不存在", 0);
  5925. }
  5926. return Result::success($result);
  5927. }
  5928. /*
  5929. * 修改公司信息
  5930. * */
  5931. public function upJobCompany(array $data): array
  5932. {
  5933. // return Result::success($data);
  5934. $user = User::where('user.id', $data['user_id'])
  5935. ->where('user.status', 1)
  5936. ->select('user.user_name', 'user.type_id')
  5937. ->first();
  5938. if (empty($user)) {
  5939. return Result::error("用户不存在", 0);
  5940. }
  5941. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5942. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5943. $company = [
  5944. 'business_name' => $data['business_name'], // 企业名称
  5945. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5946. 'company_nature' => $data['company_nature'], // 公司性质
  5947. 'company_size' => $data['company_size'], // 公司规模
  5948. 'introduction' => $data['introduction'], // 公司简介
  5949. // 'real_name' => $data['real_name'], // 企业联系人
  5950. 'company_url' => $data['company_url'], // 企业网址
  5951. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5952. 'address' => $data['address'], // 企业详细地址
  5953. // 'email' => $data['email'], // 企业邮箱
  5954. ];
  5955. if ($user['type_id'] == 3) {
  5956. Db::beginTransaction();
  5957. try {
  5958. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5959. 'business_name' => $data['business_name'], // 企业名称
  5960. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5961. 'company_nature' => $data['company_nature'], // 公司性质
  5962. 'company_size' => $data['company_size'], // 公司规模
  5963. 'introduction' => $data['introduction'], // 公司简介
  5964. // 'real_name' => $data['real_name'], // 企业联系人
  5965. 'company_url' => $data['company_url'], // 企业网址
  5966. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5967. 'address' => $data['address'], // 企业详细地址
  5968. ]);
  5969. if (empty($result['userinfo'])) {
  5970. Db::rollBack();
  5971. return Result::error('修改企业会员信息失败!');
  5972. }
  5973. $result['user'] = User::where('id', $data['user_id'])->update([
  5974. 'email' => $data['email'], // 企业邮箱
  5975. ]);
  5976. if (empty($result['user'])) {
  5977. Db::rollBack();
  5978. return Result::error('修改个人中心信息失败!');
  5979. }
  5980. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5981. if (!empty($job_company)) {
  5982. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5983. if (empty($result['job_company'])) {
  5984. Db::rollBack();
  5985. return Result::error('修改企业会员信息失败!');
  5986. }
  5987. }
  5988. Db::commit();
  5989. return Result::success($result);
  5990. } catch (\Exception $e) {
  5991. Db::rollBack();
  5992. return Result::error($e->getMessage(), 0);
  5993. }
  5994. } else {
  5995. return Result::error("用户类型错误", 0);
  5996. }
  5997. }
  5998. /*
  5999. * 获取省-市
  6000. * */
  6001. public function getJobRecruitingArea(array $data): array
  6002. {
  6003. if (isset($data['pid']) && $data['pid'] != null) {
  6004. $result = District::where('pid', $data['pid'])->get()->all();
  6005. } else {
  6006. $result = District::where('level', 1)->get()->all();
  6007. }
  6008. if (empty($result)) {
  6009. return Result::error("暂无此省市", 0);
  6010. }
  6011. return Result::success($result);
  6012. }
  6013. /*
  6014. * 获取行业分类
  6015. * */
  6016. public function getIndustry(array $data): array
  6017. {
  6018. $result = JobIndustry::get()->all();
  6019. if (empty($result)) {
  6020. return Result::error("暂无行业分类", 0);
  6021. }
  6022. return Result::success($result);
  6023. }
  6024. /*
  6025. * 获取职位
  6026. * */
  6027. public function getPositionList(array $data): array
  6028. {
  6029. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  6030. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  6031. } else {
  6032. $result = JobPosition::where('zwpid', 0)->get()->all();
  6033. }
  6034. if (empty($result)) {
  6035. return Result::error("暂无此职位", 0);
  6036. }
  6037. return Result::success($result);
  6038. }
  6039. /*
  6040. * 获取工作性质-菜单
  6041. * */
  6042. public function getJobNature(array $data): array
  6043. {
  6044. $result = JobEnum::where('egroup', 'nature')->get()->all();
  6045. if (empty($result)) {
  6046. return Result::error("暂无工作性质", 0);
  6047. }
  6048. return Result::success($result);
  6049. }
  6050. /*
  6051. * 获取工作经验-菜单
  6052. * */
  6053. public function getExperience(array $data): array
  6054. {
  6055. $result = JobEnum::where('egroup', 'years')->get()->all();
  6056. if (empty($result)) {
  6057. return Result::error("暂无工作经验", 0);
  6058. }
  6059. return Result::success($result);
  6060. }
  6061. /*
  6062. * 获取学历-菜单
  6063. * */
  6064. public function getEducation(array $data): array
  6065. {
  6066. $result = JobEnum::where('egroup', 'education')->get()->all();
  6067. if (empty($result)) {
  6068. return Result::error("暂无学历", 0);
  6069. }
  6070. return Result::success($result);
  6071. }
  6072. /*
  6073. * 获取薪资-菜单
  6074. * */
  6075. public function getSalary(array $data): array
  6076. {
  6077. $result = JobEnum::where('egroup', 'income')->get()->all();
  6078. if (empty($result)) {
  6079. return Result::error("暂无薪资", 0);
  6080. }
  6081. return Result::success($result);
  6082. }
  6083. /*
  6084. * 获取语言-菜单
  6085. * */
  6086. public function getLanguage(array $data): array
  6087. {
  6088. $result = JobEnum::where('egroup', 'language')->get()->all();
  6089. if (empty($result)) {
  6090. return Result::error("暂无语言", 0);
  6091. }
  6092. return Result::success($result);
  6093. }
  6094. /*
  6095. * 获取掌握程度-菜单
  6096. * */
  6097. public function getLevel(array $data): array
  6098. {
  6099. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  6100. if (empty($result)) {
  6101. return Result::error("暂无工作性质", 0);
  6102. }
  6103. return Result::success($result);
  6104. }
  6105. // 公司信息
  6106. /*
  6107. * 获取公司性质-菜单
  6108. * */
  6109. public function getCompanyNature(array $data): array
  6110. {
  6111. $result = JobNature::get()->all();
  6112. if (empty($result)) {
  6113. return Result::error("暂无公司性质", 0);
  6114. }
  6115. return Result::success($result);
  6116. }
  6117. /*
  6118. * 获取公司规模-菜单
  6119. * */
  6120. public function getCompanySize(array $data): array
  6121. {
  6122. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  6123. if (empty($result)) {
  6124. return Result::error("暂无公司规模", 0);
  6125. }
  6126. return Result::success($result);
  6127. }
  6128. /*
  6129. * 招聘信息审核
  6130. * */
  6131. public function checkJobRecruiting(array $data): array
  6132. {
  6133. $user = User::where('id', $data['user_id'])->first();
  6134. if (empty($user)) {
  6135. return Result::error("用户不存在", 0);
  6136. }
  6137. $job = JobRecruiting::where('id', $data['id'])->first();
  6138. if (empty($job)) {
  6139. return Result::error("招聘信息不存在", 0);
  6140. }
  6141. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  6142. if ($user['type_id'] != 10000) {
  6143. return Result::error("用户暂无权限审核此招聘信息!", 0);
  6144. }
  6145. // 驳回原因
  6146. if ($data['status'] == 2) {
  6147. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  6148. }
  6149. $data['action_id'] = $data['user_id'];
  6150. unset($data['user_id']);
  6151. if ($data['status'] == 1) {
  6152. $this->sendMessage([
  6153. 'talk_type' => 501,
  6154. 'title' => $job['title'],
  6155. 'content' => '审核通过',
  6156. 'messageType' => 10,
  6157. 'user_id' => $job['user_id'],
  6158. ]);
  6159. }
  6160. if ($data['status'] == 2) {
  6161. $this->sendMessage([
  6162. 'talk_type' => 501,
  6163. 'title' => $job['title'],
  6164. 'content' => '审核拒绝',
  6165. 'messageType' => 10,
  6166. 'user_id' => $job['user_id'],
  6167. ]);
  6168. }
  6169. if ($data['status'] == 0) {
  6170. $this->sendMessage([
  6171. 'talk_type' => 500,
  6172. 'title' => $job['title'],
  6173. 'content' => '提交了审核',
  6174. 'messageType' => 10,
  6175. ]);
  6176. }
  6177. $result = JobRecruiting::where('id', $data['id'])->update($data);
  6178. if (empty($result)) {
  6179. return Result::error("审核失败", 0);
  6180. }
  6181. return Result::success($result);
  6182. }
  6183. public function myApplyList(array $data): array
  6184. {
  6185. var_dump($data, '------参数');
  6186. $user = User::where('id', $data['user_id'])->first();
  6187. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6188. return Result::error("用户不存在", 0);
  6189. }
  6190. // 1:个人会员 职场机会
  6191. if ($user['type_id'] == 1) {
  6192. $where['user_id'] = $user['id'];
  6193. }
  6194. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  6195. $query->where('user_id', $user['id']);
  6196. })
  6197. ->pluck('recruit_id');
  6198. $where = [];
  6199. if (isset($data['salary']) && $data['salary'] != null) {
  6200. $where['job_recruiting.salary'] = $data['salary'];
  6201. }
  6202. if (isset($data['experience']) && $data['experience'] != null) {
  6203. $where['job_recruiting.experience'] = $data['experience'];
  6204. }
  6205. if (isset($data['business_name']) && $data['business_name'] != null) {
  6206. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6207. }
  6208. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6209. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6210. ->where($where);
  6211. // ->count();
  6212. $count = $query->count();
  6213. $query = clone $query;
  6214. $job = $query
  6215. ->leftJoin('job_enum as income_enum', function ($join) {
  6216. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6217. ->where('income_enum.egroup', 'income');
  6218. })
  6219. ->leftJoin('job_enum as years_enum', function ($join) {
  6220. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6221. ->where('years_enum.egroup', 'years');
  6222. })
  6223. // ->where($where)
  6224. ->orderBy('job_recruiting.updated_at', 'desc')
  6225. ->select(
  6226. 'job_recruiting.id',
  6227. 'job_recruiting.title',
  6228. 'job_company.business_name',
  6229. 'income_enum.evalue as salary_evalue',
  6230. 'income_enum.ename as salary_ename',
  6231. 'years_enum.evalue as experience_evalue',
  6232. 'years_enum.ename as experience_ename',
  6233. 'job_recruiting.updated_at'
  6234. )
  6235. ->offset(($data['page'] - 1) * $data['pageSize'])
  6236. ->limit($data['pageSize'])
  6237. ->get()
  6238. ->all();
  6239. if (empty($job)) {
  6240. return Result::error("暂无招聘信息", 0);
  6241. }
  6242. $result = [
  6243. 'row' => $job,
  6244. 'count' => $count,
  6245. ];
  6246. return Result::success($result);
  6247. }
  6248. public function readJobApply(array $data): array
  6249. {
  6250. $result = JobApply::where('id', $data['id'])->first();
  6251. if (empty($result)) {
  6252. return Result::error("查询失败", 0);
  6253. }
  6254. $result = JobApply::where('id', $data['id'])->update([
  6255. 'status' => 2,
  6256. ]);
  6257. return Result::success($result);
  6258. }
  6259. /*
  6260. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  6261. * */
  6262. public function getRecruitingList(array $data): array
  6263. {
  6264. $user = User::where('id', $data['user_id'])->first();
  6265. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6266. return Result::error("用户不存在", 0);
  6267. }
  6268. // 1:个人会员 职场机会
  6269. if ($user['type_id'] == 1) {
  6270. $where['user_id'] = $user['id'];
  6271. }
  6272. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  6273. $query->where('receiver_id', $user['id']);
  6274. })
  6275. ->pluck('recruit_id');
  6276. // return Result::success($recruitingId);
  6277. $where = [];
  6278. if (isset($data['salary']) && $data['salary'] != null) {
  6279. $where['job_recruiting.salary'] = $data['salary'];
  6280. }
  6281. if (isset($data['experience']) && $data['experience'] != null) {
  6282. $where['job_recruiting.experience'] = $data['experience'];
  6283. }
  6284. if (isset($data['business_name']) && $data['business_name'] != null) {
  6285. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6286. }
  6287. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6288. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6289. ->where($where);
  6290. // ->count();
  6291. $count = $query->count();
  6292. $query = clone $query;
  6293. $job = $query
  6294. ->leftJoin('job_enum as income_enum', function ($join) {
  6295. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6296. ->where('income_enum.egroup', 'income');
  6297. })
  6298. ->leftJoin('job_enum as years_enum', function ($join) {
  6299. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6300. ->where('years_enum.egroup', 'years');
  6301. })
  6302. // ->where($where)
  6303. ->orderBy('job_recruiting.updated_at', 'desc')
  6304. ->select(
  6305. 'job_recruiting.id',
  6306. 'job_recruiting.title',
  6307. 'job_company.business_name',
  6308. 'income_enum.evalue as salary_evalue',
  6309. 'income_enum.ename as salary_ename',
  6310. 'years_enum.evalue as experience_evalue',
  6311. 'years_enum.ename as experience_ename',
  6312. 'job_recruiting.updated_at'
  6313. )
  6314. ->offset(($data['page'] - 1) * $data['pageSize'])
  6315. ->limit($data['pageSize'])
  6316. ->get()
  6317. ->all();
  6318. if (empty($job)) {
  6319. return Result::error("暂无招聘信息", 0);
  6320. }
  6321. $result = [
  6322. 'row' => $job,
  6323. 'count' => $count,
  6324. ];
  6325. return Result::success($result);
  6326. }
  6327. /*
  6328. * 获取企业会员-招聘信息列表
  6329. * */
  6330. public function getRecruitingInfo(array $data): array
  6331. {
  6332. $user = User::where('id', $data['user_id'])->first();
  6333. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6334. return Result::error("用户不存在", 0);
  6335. }
  6336. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  6337. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6338. ->select(
  6339. 'job_recruiting.*',
  6340. 'job_company.business_name',
  6341. 'job_company.company_hy_id',
  6342. 'job_company.company_size',
  6343. 'job_company.company_nature',
  6344. 'job_company.introduction',
  6345. 'job_company.real_name',
  6346. 'job_company.mobile',
  6347. 'job_company.company_url',
  6348. 'job_company.address_arr_id',
  6349. 'job_company.address',
  6350. 'job_company.email'
  6351. )
  6352. ->get();
  6353. if (empty($recruiting)) {
  6354. return Result::error("暂无招聘信息", 0);
  6355. }
  6356. return Result::success($recruiting);
  6357. }
  6358. /*
  6359. * 获取企业会员-我的沟通
  6360. * */
  6361. public function getJobResumeList(array $data): array
  6362. {
  6363. $user = User::where('id', $data['user_id'])->first();
  6364. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  6365. return Result::error("用户不存在", 0);
  6366. }
  6367. $where = [];
  6368. if (isset($data['salary']) && $data['salary'] != null) {
  6369. $where['job_hunting.salary'] = $data['salary'];
  6370. }
  6371. if (isset($data['user_name']) && $data['user_name'] != null) {
  6372. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  6373. }
  6374. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  6375. $query->where('job_resume.user_id', $user['id']);
  6376. })
  6377. ->when(!empty($where), function ($query) use ($where) {
  6378. $query->where($where);
  6379. })
  6380. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  6381. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  6382. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  6383. ->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');
  6384. $count = $job->count();
  6385. if ($count == 0) {
  6386. return Result::error("暂无沟通记录", 0);
  6387. }
  6388. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  6389. ->offset(($data['page'] - 1) * $data['pageSize'])
  6390. ->limit($data['pageSize'])
  6391. ->get();
  6392. if (empty($jobs)) {
  6393. return Result::error("暂无沟通记录", 0);
  6394. }
  6395. $result['row'] = $this->processJob($jobs, '');
  6396. $result['count'] = $count;
  6397. return Result::success($result);
  6398. }
  6399. public function readJobResume(array $data): array
  6400. {
  6401. $result = JobResume::where('id', $data['id'])->first();
  6402. if (empty($result)) {
  6403. return Result::error("查询失败", 0);
  6404. }
  6405. $result = JobResume::where('id', $data['id'])->update([
  6406. 'status' => 2,
  6407. ]);
  6408. return Result::success($result);
  6409. }
  6410. // 20250306 招聘
  6411. //20250422 书刊音像
  6412. public function addBook(array $data): array
  6413. {
  6414. $user_id = $data['user_id'] ?? 0;
  6415. $type_id = $data['type_id'] ?? 0;
  6416. // $website_id = $data['website_id'] ?? 0;
  6417. // unset($data['user_id']);
  6418. unset($data['type_id']);
  6419. // unset($data['website_id']);
  6420. //处理数组
  6421. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6422. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6423. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6424. if ($data['img_url'] == '') {
  6425. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6426. preg_match_all($reg, $data['detail'], $matches);
  6427. if (isset($matches[1][0])) {
  6428. //截取varchar240
  6429. $data['img_url'] = substr($matches[1][0], 0, 240);
  6430. }
  6431. }
  6432. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  6433. //提取标题+内容中的关键词
  6434. $data['keyword'] = $data['title'];
  6435. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6436. Jieba::init(); // 初始化 jieba-php
  6437. Finalseg::init();
  6438. $segList = Jieba::cut($data['keyword']);
  6439. $segList1 = array_slice($segList, 0, 8);
  6440. $data['keyword'] = implode(',', $segList1);
  6441. }
  6442. if ($data['description'] == '') {
  6443. //提取内容中的描述
  6444. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6445. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6446. }
  6447. var_dump($data, '--');
  6448. if ($data['status'] == 1) {
  6449. $this->sendMessage([
  6450. 'talk_type' => 400,
  6451. 'title' => $data['title'],
  6452. 'content' => '提交了审核',
  6453. 'messageType' => 7,
  6454. ]);
  6455. }
  6456. $result = Book::insertGetId($data);
  6457. if (empty($result)) {
  6458. return Result::error("添加失败", 0);
  6459. }
  6460. return Result::success($result);
  6461. }
  6462. public function getBookList(array $data): array
  6463. {
  6464. $where = [];
  6465. if (!empty($data["title"])) {
  6466. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  6467. }
  6468. if (!empty($data['website_name'])) {
  6469. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  6470. }
  6471. if (!empty($data['status'])) {
  6472. $where[] = ['book.status', '=', $data['status']];
  6473. }
  6474. $user_id = $data['user_id'];
  6475. $type_id = $data['type_id'];
  6476. // $type_id = 4;
  6477. var_dump($type_id, '------1--------');
  6478. if ($type_id != 10000) {
  6479. $where[] = ['book.user_id', '=', $user_id];
  6480. }
  6481. var_dump(!empty($data['status1']), '=-===1');
  6482. $result = Book::where($where)
  6483. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  6484. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  6485. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  6486. ->when(isset($data['status1']), function ($query) use ($data) {
  6487. $query->whereIn('book.status', [1, 3]);
  6488. })
  6489. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  6490. ->orderBy("updated_at", "desc")
  6491. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  6492. if (empty($result)) {
  6493. return Result::error("暂无数据", 0);
  6494. }
  6495. // 取出数据
  6496. $rows = $result->items();
  6497. $count = $result->total();
  6498. $responseData = [
  6499. 'rows' => $rows,
  6500. 'count' => $count,
  6501. ];
  6502. return Result::success($responseData);
  6503. }
  6504. public function deleteBook(array $data): array
  6505. {
  6506. $result = Book::where('id', $data['id'])->delete();
  6507. if (empty($result)) {
  6508. return Result::error("删除失败", 0);
  6509. }
  6510. return Result::success($result);
  6511. }
  6512. public function updateBook(array $data): array
  6513. {
  6514. // $user_id = $data['user_id'] ?? 0;
  6515. $type_id = $data['type_id'] ?? 0;
  6516. // $website_id = $data['website_id'] ?? 0;
  6517. unset($data['user_id']);
  6518. unset($data['type_id']);
  6519. // unset($data['website_id']);
  6520. //处理数组
  6521. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6522. if ($data['img_url'] == '') {
  6523. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6524. preg_match_all($reg, $data['detail'], $matches);
  6525. if (isset($matches[1][0])) {
  6526. //截取varchar240
  6527. $data['img_url'] = substr($matches[1][0], 0, 240);
  6528. }
  6529. }
  6530. if ($data['keyword'] == '') {
  6531. //提取标题+内容中的关键词
  6532. $data['keyword'] = $data['title'];
  6533. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6534. Jieba::init(); // 初始化 jieba-php
  6535. Finalseg::init();
  6536. $segList = Jieba::cut($data['keyword']);
  6537. $segList1 = array_slice($segList, 0, 8);
  6538. $data['keyword'] = implode(',', $segList1);
  6539. }
  6540. if ($data['description'] == '') {
  6541. //提取内容中的描述
  6542. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6543. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6544. }
  6545. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6546. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6547. if ($data['status'] == 1) {
  6548. $this->sendMessage([
  6549. 'talk_type' => 400,
  6550. 'title' => $data['title'],
  6551. 'content' => '提交了审核',
  6552. 'messageType' => 7,
  6553. ]);
  6554. }
  6555. $result = Book::where("id", $data["id"])->update($data);
  6556. if (empty($result)) {
  6557. return Result::error("更新失败", 0);
  6558. }
  6559. return Result::success($result);
  6560. }
  6561. public function getBookInfo(array $data): array
  6562. {
  6563. $result = Book::where("id", $data["id"])->first();
  6564. if (empty($result)) {
  6565. return Result::error("获取失败", 0);
  6566. }
  6567. return Result::success($result);
  6568. }
  6569. public function updateBookStatus(array $data): array
  6570. {
  6571. //审核
  6572. unset($data['user_id']);
  6573. $bookInfo = Book::where("id", $data["id"])->first();
  6574. var_dump($bookInfo, '----');
  6575. if ($data['status'] == 2) {
  6576. $this->sendMessage([
  6577. 'talk_type' => 401,
  6578. 'title' => $bookInfo['title'],
  6579. 'content' => '审核通过',
  6580. 'messageType' => 7,
  6581. 'user_id' => $bookInfo['user_id'],
  6582. ]);
  6583. }
  6584. if ($data['status'] == 3) {
  6585. $this->sendMessage([
  6586. 'talk_type' => 401,
  6587. 'title' => $bookInfo['title'],
  6588. 'content' => '审核拒绝',
  6589. 'messageType' => 7,
  6590. 'user_id' => $bookInfo['user_id'],
  6591. ]);
  6592. }
  6593. if ($data['status'] == 1) {
  6594. $this->sendMessage([
  6595. 'talk_type' => 400,
  6596. 'title' => $bookInfo['title'],
  6597. 'content' => '提交了审核',
  6598. 'messageType' => 7,
  6599. // 'user_id'=>$bookInfo['user_id'],
  6600. ]);
  6601. }
  6602. $result = Book::where("id", $data["id"])->update($data);
  6603. if (empty($result)) {
  6604. return Result::error("更新失败", 0);
  6605. }
  6606. return Result::success($result);
  6607. }
  6608. //20250422 书刊音像
  6609. /**
  6610. * 贴身宝贝
  6611. * @param array $data
  6612. * @return array
  6613. */
  6614. public function getWebsiteTsbb(array $data): array
  6615. {
  6616. $month = $data['month'] ?? date('m');
  6617. $day = $data['day'] ?? date('d');
  6618. // 使用缓存键
  6619. $cacheKey = "tsbb_data_{$month}_{$day}";
  6620. // 尝试从缓存获取数据
  6621. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6622. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6623. if ($cachedData = $cache->get($cacheKey)) {
  6624. return Result::success(unserialize($cachedData));
  6625. }
  6626. //查询老黄历
  6627. try {
  6628. $date = date('Y-m-d');
  6629. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6630. // 使用 curl 替代 file_get_contents
  6631. $ch = curl_init();
  6632. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6633. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6634. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6635. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6636. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6637. 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');
  6638. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6639. 'Accept: application/json',
  6640. 'Content-Type: application/json',
  6641. 'Referer: https://www.36jxs.com/'
  6642. ]);
  6643. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6644. curl_setopt($ch, CURLOPT_ENCODING, '');
  6645. $almanacResponse = curl_exec($ch);
  6646. var_dump("====:", $almanacResponse);
  6647. if (curl_errno($ch)) {
  6648. var_dump('Curl error:', curl_error($ch));
  6649. throw new \Exception('Curl error: ' . curl_error($ch));
  6650. }
  6651. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6652. curl_close($ch);
  6653. if ($almanacResponse === false) {
  6654. throw new \Exception('Failed to fetch almanac data');
  6655. }
  6656. $almanacData = json_decode($almanacResponse, true);
  6657. if (json_last_error() !== JSON_ERROR_NONE) {
  6658. throw new \Exception('Failed to parse almanac data');
  6659. }
  6660. $almanacInfo = $almanacData['data'] ?? [];
  6661. } catch (\Exception $e) {
  6662. var_dump('Exception:', $e->getMessage());
  6663. $almanacInfo = [];
  6664. }
  6665. // 获取历史上的今天数据
  6666. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6667. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6668. ->orderBy('year', 'asc')
  6669. ->select("title", "id", "year", DB::raw('1 as type'))
  6670. ->limit(16)
  6671. ->get();
  6672. // 获取节日数据 - 从今天开始获取未来4条
  6673. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6674. ->orderBy('showtime', 'asc')
  6675. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6676. ->limit(16)
  6677. ->get();
  6678. //说文解字
  6679. $chartacterList = Character::orderBy('updated_at', 'desc')
  6680. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6681. ->limit(6)
  6682. ->get();
  6683. //谜语沙龙
  6684. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6685. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6686. ->limit(4)
  6687. ->get();
  6688. //成语欣赏
  6689. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6690. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6691. ->limit(32)
  6692. ->get();
  6693. //名联赏析
  6694. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6695. ->select("id", "first", "second", DB::raw('6 as type'))
  6696. ->limit(6)
  6697. ->get();
  6698. // 获取分类文章数据
  6699. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6700. ->pluck('category_id')
  6701. ->toArray();
  6702. $articlesList = [];
  6703. foreach ($categoryIds as $catid) {
  6704. // 先查有图片的
  6705. $withImg = DB::table('article')
  6706. ->where('status', 1)
  6707. ->where('catid', $catid)
  6708. ->whereNotNull('imgurl')
  6709. ->where('imgurl', '!=', '')
  6710. ->orderBy('updated_at', 'desc')
  6711. ->limit(6)
  6712. ->get();
  6713. $count = $withImg->count();
  6714. if ($count < 6) {
  6715. // 不足6条再查无图片的补足
  6716. $withoutImg = DB::table('article')
  6717. ->where('status', 1)
  6718. ->where('catid', $catid)
  6719. ->where(function ($q) {
  6720. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6721. })
  6722. ->orderBy('updated_at', 'desc')
  6723. ->limit(6 - $count)
  6724. ->get();
  6725. $articles = $withImg->concat($withoutImg);
  6726. } else {
  6727. $articles = $withImg;
  6728. }
  6729. // 组装
  6730. $category = \App\Model\Category::find($catid);
  6731. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6732. $articlesList[] = [
  6733. 'category_name' => $category ? $category->name : '',
  6734. 'catid' => $catid,
  6735. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6736. 'type' => 100,
  6737. 'list' => $articles->map(function ($item) {
  6738. return [
  6739. 'id' => $item->id,
  6740. 'title' => $item->title,
  6741. 'imgurl' => $item->imgurl,
  6742. 'created_at' => $item->created_at
  6743. ];
  6744. })->values()
  6745. ];
  6746. }
  6747. $result = [
  6748. 'almanac' => $almanacInfo,
  6749. 'historyTodayList' => [
  6750. 'category_name' => '历史上的今天',
  6751. 'list' => $historyTodayList,
  6752. 'type' => 1
  6753. ],
  6754. 'festivalList' => [
  6755. 'category_name' => '节日预告',
  6756. 'list' => $festivalList,
  6757. 'type' => 2
  6758. ],
  6759. 'chartacterList' => [
  6760. 'category_name' => '说文解字',
  6761. 'list' => $chartacterList,
  6762. 'type' => 3
  6763. ],
  6764. 'coupletList' => [
  6765. 'category_name' => '名联赏析',
  6766. 'list' => $coupletList,
  6767. 'type' => 6
  6768. ],
  6769. 'riddletList' => [
  6770. 'category_name' => '谜语沙龙',
  6771. 'list' => $riddletList,
  6772. 'type' => 4
  6773. ],
  6774. 'idiomList' => [
  6775. 'category_name' => '成语欣赏',
  6776. 'list' => $idiomList,
  6777. 'type' => 5
  6778. ],
  6779. 'articlesList' => $articlesList
  6780. ];
  6781. // 缓存结果,设置1小时过期
  6782. $cache->set($cacheKey, serialize($result), 3600);
  6783. return Result::success($result);
  6784. }
  6785. /**
  6786. * 获取资讯列表
  6787. */
  6788. public function getWebsiteTsbbList(array $data): array
  6789. {
  6790. $page = $data['page'] ?? 1;
  6791. $pageSize = $data['pageSize'] ?? 10;
  6792. // 如果没有传入月份和日期,则使用今天的日期
  6793. $month = $data['month'] ?? date('m');
  6794. $day = $data['day'] ?? date('d');
  6795. $total = 0;
  6796. $result = [];
  6797. $data['type'] = intval($data['type']);
  6798. var_dump("接收参数:", $data);
  6799. switch ($data['type']) {
  6800. case 1:
  6801. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6802. // 当前月份之后的数据
  6803. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6804. // 或者当前月份且日期大于等于当前日期的数据
  6805. ->orWhere(function ($q) use ($month, $day) {
  6806. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6807. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6808. });
  6809. })
  6810. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6811. $total = $query->count();
  6812. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6813. ->offset(($page - 1) * $pageSize)
  6814. ->limit($pageSize)
  6815. ->get();
  6816. break;
  6817. case 2:
  6818. $query = Festival::where(function ($q) use ($month, $day) {
  6819. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6820. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6821. ->orWhere(function ($q) use ($month, $day) {
  6822. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6823. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6824. });
  6825. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6826. $total = $query->count();
  6827. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6828. ->offset(($page - 1) * $pageSize)
  6829. ->limit($pageSize)
  6830. ->get();
  6831. break;
  6832. case 3:
  6833. $query = Character::orderBy("updated_at", "desc");
  6834. $total = $query->count();
  6835. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6836. ->offset(($page - 1) * $pageSize)
  6837. ->limit($pageSize)
  6838. ->get();
  6839. break;
  6840. case 4:
  6841. $query = Riddle::orderBy("updated_at", "desc");
  6842. $total = $query->count();
  6843. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6844. ->offset(($page - 1) * $pageSize)
  6845. ->limit($pageSize)
  6846. ->get();
  6847. break;
  6848. case 5:
  6849. $query = Idiom::orderBy("updated_at", "desc");
  6850. $total = $query->count();
  6851. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6852. ->offset(($page - 1) * $pageSize)
  6853. ->limit($pageSize)
  6854. ->get();
  6855. break;
  6856. case 6:
  6857. $query = Couplet::orderBy("updated_at", "desc");
  6858. $total = $query->count();
  6859. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6860. ->offset(($page - 1) * $pageSize)
  6861. ->limit($pageSize)
  6862. ->get();
  6863. break;
  6864. default:
  6865. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6866. $total = $query->count();
  6867. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6868. ->offset(($page - 1) * $pageSize)
  6869. ->limit($pageSize)
  6870. ->get();
  6871. }
  6872. return Result::success([
  6873. 'list' => $result,
  6874. 'total' => $total,
  6875. 'page' => (int)$page,
  6876. 'pageSize' => (int)$pageSize,
  6877. 'month' => $month,
  6878. 'day' => $day
  6879. ]);
  6880. }
  6881. /**
  6882. * 1:历史上的今天
  6883. * 2:节日
  6884. * 3:文章
  6885. *
  6886. * 资讯详情信息
  6887. */
  6888. public function getWebsiteTsbbDetail(array $data): array
  6889. {
  6890. $data['type'] = intval($data['type']);
  6891. switch ($data['type']) {
  6892. case 1:
  6893. $result = HistoryToday::where("id", $data['id'])->first();
  6894. break;
  6895. case 2:
  6896. $result = Festival::where("id", $data['id'])->first();
  6897. break;
  6898. case 3:
  6899. $result = Character::where("id", $data['id'])->first();
  6900. break;
  6901. case 4:
  6902. $result = Riddle::where("id", $data['id'])->first();
  6903. break;
  6904. case 5:
  6905. $result = Idiom::where("id", $data['id'])->first();
  6906. break;
  6907. case 6:
  6908. $result = Couplet::where("id", $data['id'])->first();
  6909. break;
  6910. default:
  6911. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6912. break;
  6913. }
  6914. return Result::success($result);
  6915. }
  6916. /**
  6917. * 农网导航首页数据
  6918. */
  6919. public function getWebsiteNwHomeList(array $data): array
  6920. {
  6921. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6922. ->pluck('category_id')
  6923. ->toArray();
  6924. // 使用子查询优化
  6925. $articlesList = DB::table('article')
  6926. ->select([
  6927. 'article.id',
  6928. 'article.title',
  6929. 'article.imgurl',
  6930. 'article.created_at',
  6931. 'category.name as category_name',
  6932. 'category.id as category_id',
  6933. 'website_category.aLIas_pinyin as pinyin',
  6934. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6935. DB::raw('100 as type')
  6936. ])
  6937. ->join('category', 'article.catid', '=', 'category.id')
  6938. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6939. ->leftJoin('website_category as parent_wc', function ($join) {
  6940. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6941. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6942. })
  6943. ->where('website_category.website_id', $data['website_id'])
  6944. ->where('article.status', 1)
  6945. ->whereIn('category.id', $categoryIds)
  6946. ->orderBy('article.created_at', 'desc')
  6947. ->get()
  6948. ->groupBy('category_id')
  6949. ->map(function ($group) {
  6950. // 确保第一条数据有图片
  6951. $firstWithImage = $group->first(function ($item) {
  6952. return !empty($item->imgurl);
  6953. });
  6954. if ($firstWithImage) {
  6955. // 如果有带图片的文章,将其放在第一位
  6956. $group = $group->filter(function ($item) use ($firstWithImage) {
  6957. return $item->id !== $firstWithImage->id;
  6958. })->prepend($firstWithImage);
  6959. }
  6960. return [
  6961. 'category_name' => $group->first()->category_name,
  6962. 'catid' => $group->first()->category_id,
  6963. 'pinyin' => $group->first()->pinyin,
  6964. 'parent_pinyin' => $group->first()->parent_pinyin,
  6965. 'list' => $group->take(4)->map(function ($item) {
  6966. return [
  6967. 'id' => $item->id,
  6968. 'title' => $item->title,
  6969. ];
  6970. })->values()
  6971. ];
  6972. })
  6973. ->values()
  6974. ->toArray();
  6975. return Result::success($articlesList);
  6976. }
  6977. /**
  6978. * 企业管理
  6979. * @param array $data
  6980. * @return array
  6981. */
  6982. public function getCompanyList(array $data): array
  6983. {
  6984. // return Result::success($data);
  6985. $where = [];
  6986. $user = User::where('id', $data['user_id'])->first();
  6987. if (empty($user)) {
  6988. return Result::error('用户不存在!');
  6989. }
  6990. if ($user['type_id'] != 10000) {
  6991. $where['user_id'] = $data['user_id'];
  6992. }
  6993. if (isset($data['title']) && !empty($data['title'])) {
  6994. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6995. }
  6996. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6997. array_push($where, ['website.id', $data['website_id']]);
  6998. }
  6999. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  7000. if ($data['ischeck'] == 1) {
  7001. if (isset($data['status']) && $data['status'] != '') {
  7002. array_push($where, ['company.status', $data['status']]);
  7003. $query = Company::where($where);
  7004. } else {
  7005. $query = Company::whereIn('company.status', [0, 2]);
  7006. }
  7007. } else {
  7008. $query = Company::where('company.status', 1);
  7009. }
  7010. }
  7011. $result = $query->where($where)
  7012. ->leftJoin('website_category', function ($query) {
  7013. $query->on('website_category.category_id', '=', 'company.category_id')
  7014. ->on('website_category.website_id', '=', 'company.website_id');
  7015. })
  7016. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  7017. ->select(
  7018. 'company.id',
  7019. 'company.title',
  7020. 'company.website_id',
  7021. 'company.category_id',
  7022. 'website.website_name',
  7023. 'website_category.alias as category_name',
  7024. 'company.status',
  7025. 'company.updated_at',
  7026. 'company.user_id'
  7027. )
  7028. ->orderBy('company.updated_at', 'desc')
  7029. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7030. if ($result->isEmpty()) {
  7031. return Result::error("暂无企业", 0);
  7032. }
  7033. return Result::success($result);
  7034. }
  7035. /**
  7036. * 添加企业
  7037. * @param array $data
  7038. * @return array
  7039. */
  7040. public function addCompany(array $data): array
  7041. {
  7042. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  7043. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  7044. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  7045. $data['cat_arr_id'] = json_encode($car_arr_id);
  7046. } else {
  7047. $data['cat_arr_id'] = '';
  7048. }
  7049. if ($data['imgurl'] == '') {
  7050. //content中提取图片第一个图,正则提取
  7051. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7052. preg_match_all($reg, $data['content'], $matches);
  7053. if (isset($matches[1][0])) {
  7054. //截取varchar240
  7055. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7056. }
  7057. }
  7058. if ($data['keyword'] == '') {
  7059. //提取标题+内容中的关键词
  7060. $data['keyword'] = $data['title'];
  7061. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7062. Jieba::init(); // 初始化 jieba-php
  7063. Finalseg::init();
  7064. $segList = Jieba::cut($data['keyword']);
  7065. $segList1 = array_slice($segList, 0, 8);
  7066. $data['keyword'] = implode(',', $segList1);
  7067. }
  7068. if ($data['introduce'] == '' || empty($data['introduce'])) {
  7069. //提取内容中的描述
  7070. $content = $data['content'];
  7071. // 去除 <style> 和 <script> 标签及其内容
  7072. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7073. // 去除所有 HTML 标签
  7074. $content = strip_tags($content);
  7075. // 去除 HTML 实体
  7076. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7077. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7078. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7079. // 去除多余空白
  7080. $content = preg_replace('/\s+/u', '', $content);
  7081. // 截取 100 个字符
  7082. $data['introduce'] = mb_substr($content, 0, 100);
  7083. }
  7084. $user = User::where('id', $data['user_id'])->first();
  7085. if (empty($user)) {
  7086. return Result::error('用户不存在!');
  7087. }
  7088. if ($user['type_id'] == 10000) {
  7089. $data['status'] = 1;
  7090. }
  7091. if (isset($data['level']) && $data['level'] != null) {
  7092. $data['level'] = intval($data['level']);
  7093. } else {
  7094. $data['level'] = null;
  7095. }
  7096. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7097. $this->sendMessage([
  7098. 'talk_type' => 900,
  7099. 'title' => $data['title'],
  7100. 'content' => '提交了审核',
  7101. 'messageType' => 8,
  7102. ]);
  7103. }
  7104. $result = Company::insertGetId($data);
  7105. if ($result) {
  7106. return Result::success($result);
  7107. } else {
  7108. return Result::error('添加失败');
  7109. }
  7110. }
  7111. /**
  7112. * 更新企业
  7113. * @param array $data
  7114. * @return array
  7115. */
  7116. public function upCompany(array $data): array
  7117. {
  7118. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  7119. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  7120. $data['cat_arr_id'] = json_encode($car_arr_id);
  7121. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  7122. } else {
  7123. $data['cat_arr_id'] = '';
  7124. }
  7125. if ($data['imgurl'] == '') {
  7126. //content中提取图片第一个图,正则提取
  7127. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7128. preg_match_all($reg, $data['content'], $matches);
  7129. if (isset($matches[1][0])) {
  7130. //截取varchar
  7131. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7132. }
  7133. }
  7134. if ($data['keyword'] == '') {
  7135. //提取标题+内容中的关键词
  7136. $data['keyword'] = $data['title'];
  7137. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7138. Jieba::init(); // 初始化 jieba-php
  7139. Finalseg::init();
  7140. $segList = Jieba::cut($data['keyword']);
  7141. $segList1 = array_slice($segList, 0, 8);
  7142. $data['keyword'] = implode(',', $segList1);
  7143. }
  7144. if ($data['introduce'] == '') {
  7145. //提取内容中的描述
  7146. $content = $data['content'];
  7147. // 去除 <style> 和 <script> 标签及其内容
  7148. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7149. // 去除所有 HTML 标签
  7150. $content = strip_tags($content);
  7151. // 去除 HTML 实体
  7152. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7153. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7154. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7155. // 去除多余空白
  7156. $content = preg_replace('/\s+/u', '', $content);
  7157. // 截取 100 个字符
  7158. $data['introduce'] = mb_substr($content, 0, 100);
  7159. }
  7160. if (isset($data['level']) && $data['level'] != null) {
  7161. $data['level'] = intval($data['level']);
  7162. } else {
  7163. $data['level'] = null;
  7164. }
  7165. $user = User::where('id', $data['user_id'])->first();
  7166. if (empty($user)) {
  7167. return Result::error('用户不存在!');
  7168. }
  7169. if ($user['type_id'] == 10000) {
  7170. $data['status'] = 1;
  7171. } else {
  7172. $data['status'] = 0;
  7173. }
  7174. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7175. $this->sendMessage([
  7176. 'talk_type' => 900,
  7177. 'title' => $data['title'],
  7178. 'content' => '提交了审核',
  7179. 'messageType' => 8,
  7180. ]);
  7181. }
  7182. $result = Company::where('id', $data['id'])->update($data);
  7183. if ($result) {
  7184. return Result::success($result);
  7185. } else {
  7186. return Result::error('修改失败');
  7187. }
  7188. }
  7189. /**
  7190. * 删除企业
  7191. * @param array $data
  7192. * @return array
  7193. */
  7194. public function delCompany(array $data): array
  7195. {
  7196. $result = Company::where('id', $data['id'])->delete();
  7197. if ($result) {
  7198. return Result::success($result);
  7199. } else {
  7200. return Result::error('删除失败');
  7201. }
  7202. }
  7203. /**
  7204. * 审核企业
  7205. * @param array $data
  7206. * @return array
  7207. */
  7208. public function checkCompany(array $data): array
  7209. {
  7210. $user = User::where('id', $data['user_id'])->first();
  7211. if (empty($user)) {
  7212. return Result::error('用户不存在!');
  7213. }
  7214. $company = Company::where('id', $data['id'])->first();
  7215. if (empty($company)) {
  7216. return Result::error('企业不存在!');
  7217. }
  7218. // 状态:0:未审核 1:已审核 2:已拒绝
  7219. if ($data['status'] == 2 || $data['status'] == '2') {
  7220. $this->sendMessage([
  7221. 'talk_type' => 901,
  7222. 'title' => $company['title'],
  7223. 'content' => '审核拒绝',
  7224. 'messageType' => 8,
  7225. 'user_id' => $company['user_id'],
  7226. ]);
  7227. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  7228. } else {
  7229. if ($data['status'] == 1) {
  7230. $this->sendMessage([
  7231. 'talk_type' => 901,
  7232. 'title' => $company['title'],
  7233. 'content' => '审核通过',
  7234. 'messageType' => 8,
  7235. 'user_id' => $company['user_id'],
  7236. ]);
  7237. } else if ($data['status'] == 0) {
  7238. $this->sendMessage([
  7239. 'talk_type' => 900,
  7240. 'title' => $company['title'],
  7241. 'content' => '提交了审核',
  7242. 'messageType' => 8,
  7243. ]);
  7244. }
  7245. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  7246. }
  7247. if (empty($result)) {
  7248. return Result::error('审核失败!');
  7249. } else {
  7250. return Result::success($result);
  7251. }
  7252. }
  7253. /**
  7254. * 获取企业信息
  7255. * @param array $data
  7256. * @return array
  7257. */
  7258. public function getCompanyInfo(array $data): array
  7259. {
  7260. $result = Company::where('id', $data['id'])->first();
  7261. $city_arr = json_decode($result['city_arr_id']);
  7262. $result['city_name'] = District::whereIn('id', $city_arr)
  7263. ->pluck('name')
  7264. ->implode('-');
  7265. if (empty($result)) {
  7266. return Result::error('企业不存在!');
  7267. } else {
  7268. return Result::success($result);
  7269. }
  7270. }
  7271. /**
  7272. * @param array $data
  7273. * @return array
  7274. */
  7275. public function getWebsiteCompany(array $data): array
  7276. {
  7277. $categorys = json_decode($data['id'], true);
  7278. $category_arr = $this->processArticlePro($data['website_id']);
  7279. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7280. $catiall = $category_arr['catiall'];
  7281. $categoryIds = $category_arr['categoryIds'];
  7282. // return Result::success($category_arr);
  7283. foreach ($categorys as $key => $value) {
  7284. if (array_key_exists('level', $value)) {
  7285. $parts = explode(',', $value['level']);
  7286. $level = $parts[0] ?? null;
  7287. $imgnum = $parts[1] ?? null;
  7288. $textnum = $parts[2] ?? null;
  7289. if (!empty($textnum) && $textnum > 0) {
  7290. $text_num = Company::where('level', $level)
  7291. ->whereIn('category_id', $categoryIds)
  7292. ->where('status', 1)
  7293. ->select(
  7294. 'company.id',
  7295. 'company.title',
  7296. 'company.description',
  7297. 'company.updated_at',
  7298. 'company.category_id',
  7299. 'company.cat_arr_id'
  7300. )
  7301. ->orderBy('updated_at', 'desc')
  7302. ->limit($textnum)
  7303. ->get()->all();
  7304. }
  7305. if (!empty($imgnum) && $imgnum > 0) {
  7306. $img_num = Company::where('level', $level)
  7307. ->whereIn('category_id', $categoryIds)
  7308. ->where('status', 1)
  7309. ->where('imgurl', '!=', '')
  7310. ->whereNotNull('imgurl')
  7311. ->select(
  7312. 'company.id',
  7313. 'company.title',
  7314. 'company.description',
  7315. 'company.updated_at',
  7316. 'company.imgurl as imgs',
  7317. 'company.category_id',
  7318. 'company.cat_arr_id'
  7319. )
  7320. ->orderBy('updated_at', 'desc')
  7321. ->limit($imgnum)
  7322. ->get()->all();
  7323. }
  7324. }
  7325. if (array_key_exists('id', $value)) {
  7326. $parts = explode(',', $value['id']);
  7327. $category_id = $parts[0] ?? null;
  7328. $imgnum = $parts[1] ?? null;
  7329. $textnum = $parts[2] ?? null;
  7330. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  7331. if (!empty($textnum) && $textnum > 0) {
  7332. $text_num = Company::whereIn('category_id', $category_arr)
  7333. // ->where('website_id', $data['website_id'])
  7334. ->where('status', 1)
  7335. ->select(
  7336. 'company.id',
  7337. 'company.title',
  7338. 'company.description',
  7339. 'company.updated_at',
  7340. 'company.category_id',
  7341. 'company.cat_arr_id'
  7342. )
  7343. ->orderBy('updated_at', 'desc')
  7344. ->limit($textnum)
  7345. ->get()->all();
  7346. }
  7347. if (!empty($imgnum) && $imgnum > 0) {
  7348. $img_num = Company::whereIn('category_id', $category_arr)
  7349. // ->where('website_id', $data['website_id'])
  7350. ->where('status', 1)
  7351. ->where('imgurl', '!=', '')
  7352. ->whereNotNull('imgurl')
  7353. ->select(
  7354. 'company.id',
  7355. 'company.title',
  7356. 'company.description',
  7357. 'company.updated_at',
  7358. 'company.imgurl as imgs',
  7359. 'company.category_id',
  7360. 'company.cat_arr_id'
  7361. )
  7362. ->orderBy('updated_at', 'desc')
  7363. ->limit($imgnum)
  7364. ->get()->all();
  7365. }
  7366. }
  7367. if (!empty($text_num)) {
  7368. foreach ($text_num as $k => $v) {
  7369. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7370. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7371. }
  7372. }
  7373. if (!empty($img_num)) {
  7374. foreach ($img_num as $k => $v) {
  7375. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7376. $imgurl = json_decode($v['imgs'], true);
  7377. if (!empty($imgurl)) {
  7378. $img_num[$k]->imgurl = $imgurl[0];
  7379. }
  7380. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7381. }
  7382. }
  7383. $company[$key]['img_num'] = $img_num ?? [];
  7384. $company[$key]['text_num'] = $text_num ?? [];
  7385. }
  7386. if (empty($company)) {
  7387. return Result::error("暂无相关企业信息", 0);
  7388. }
  7389. return Result::success($company);
  7390. }
  7391. /**
  7392. * @param array $data
  7393. * @return array
  7394. */
  7395. public function getWebsiteCompanyList(array $data): array
  7396. {
  7397. $where['website_id'] = $data['website_id'];
  7398. $where['status'] = 1;
  7399. $categoryIds = [];
  7400. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7401. $category_id = $data['category_id'];
  7402. }
  7403. $category_arr = $this->processArticlePro($data['website_id']);
  7404. $categoryIds = $category_arr['categoryIds'];
  7405. // return Result::success($cat_1st_arr);
  7406. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  7407. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  7408. })
  7409. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  7410. $query->whereIn('category_id', $categoryIds);
  7411. })
  7412. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  7413. $query->where('category_id', $category_id);
  7414. })
  7415. ->where('status',1)
  7416. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  7417. ->orderBy('updated_at', 'desc')
  7418. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7419. if (empty($company)) {
  7420. return Result::error("暂无相关公司信息", 0);
  7421. }
  7422. $result = [
  7423. 'count' => $company->total(),
  7424. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  7425. ];
  7426. return Result::success($result);
  7427. }
  7428. /**
  7429. * 获取项目列表
  7430. * @param array $data
  7431. * @return array
  7432. */
  7433. public function getProjectList(array $data): array
  7434. {
  7435. $where = [];
  7436. $user = User::where('id', $data['user_id'])->first();
  7437. if (empty($user)) {
  7438. return Result::error('用户不存在!');
  7439. }
  7440. if ($user->type_id != 10000) {
  7441. array_push($where, ['project.user_id', $data['user_id']]);
  7442. }
  7443. $query = Project::query();
  7444. if (isset($data['website_id']) && !empty($data['website_id'])) {
  7445. array_push($where, ['project.website_id', $data['website_id']]);
  7446. }
  7447. if (isset($data['title']) && !empty($data['title'])) {
  7448. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  7449. }
  7450. if ($data['status'] != 3) {
  7451. array_push($where, ['project.status', $data['status']]);
  7452. }
  7453. $query = Project::where($where)
  7454. ->when($data['status'] == 3, function ($query) {
  7455. $query->whereIn('project.status', [0, 2]);
  7456. });
  7457. $count = $query->clone()
  7458. ->count();
  7459. $rows = $query->clone()
  7460. ->leftJoin('website', 'project.website_id', 'website.id')
  7461. ->leftJoin('website_category', function ($join) {
  7462. $join->on('project.website_id', '=', 'website_category.website_id')
  7463. ->on('project.category_id', '=', 'website_category.category_id');
  7464. })
  7465. ->select(
  7466. 'project.id',
  7467. 'project.title',
  7468. 'project.updated_at',
  7469. 'project.status',
  7470. 'website.website_name',
  7471. 'website_category.alias as category_name',
  7472. 'project.website_id',
  7473. 'project.user_id'
  7474. )
  7475. ->orderBy('project.updated_at', 'desc')
  7476. ->offset(($data['page'] - 1) * $data['pageSize'])
  7477. ->limit($data['pageSize'])
  7478. ->get();
  7479. if ($rows->isEmpty()) {
  7480. return Result::error("暂无相关项目信息", 0);
  7481. }
  7482. $result = [
  7483. 'count' => $count,
  7484. 'rows' => $rows,
  7485. ];
  7486. return Result::success($result);
  7487. }
  7488. /**
  7489. * 添加项目
  7490. * @param array $data
  7491. * @return array
  7492. */
  7493. public function addProject(array $data): array
  7494. {
  7495. $user = User::where('id', $data['user_id'])->first();
  7496. if (empty($user)) {
  7497. return Result::error("暂无相关用户信息", 0);
  7498. }
  7499. if ($user->type_id == 10000) {
  7500. $data['status'] = 1;
  7501. } else {
  7502. $data['status'] = 0;
  7503. }
  7504. if ($data['keyword'] == '') {
  7505. //提取标题+内容中的关键词
  7506. $data['keyword'] = $data['title'];
  7507. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7508. Jieba::init(); // 初始化 jieba-php
  7509. Finalseg::init();
  7510. $segList = Jieba::cut($data['keyword']);
  7511. $segList1 = array_slice($segList, 0, 8);
  7512. $data['keyword'] = implode(',', $segList1);
  7513. }
  7514. if ($data['description'] == '') {
  7515. //提取内容中的描述
  7516. // var_dump(11111);
  7517. //提取内容中的描述
  7518. $content = $data['introduce'];
  7519. // 去除 <style> 和 <script> 标签及其内容
  7520. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7521. // 去除所有 HTML 标签
  7522. $content = strip_tags($content);
  7523. // 去除 HTML 实体
  7524. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7525. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7526. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7527. // 去除多余空白
  7528. $content = preg_replace('/\s+/u', '', $content);
  7529. // 截取 100 个字符
  7530. $data['description'] = mb_substr($content, 0, 100);
  7531. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7532. }
  7533. if ($data['status'] == 0) {
  7534. $this->sendMessage([
  7535. 'talk_type' => 1000,
  7536. 'title' => $data['title'],
  7537. 'content' => '提交了审核',
  7538. 'messageType' => 9,
  7539. ]);
  7540. }
  7541. $project = Project::insertGetId($data);
  7542. if (empty($project)) {
  7543. return Result::error("暂无相关项目信息", 0);
  7544. }
  7545. return Result::success($project);
  7546. }
  7547. /**
  7548. * 更新项目
  7549. * @param array $data
  7550. * @return array
  7551. */
  7552. public function upProject(array $data): array
  7553. {
  7554. $project = Project::where('id', $data['id'])->first();
  7555. if (empty($project)) {
  7556. return Result::error("暂无相关项目信息", 0);
  7557. }
  7558. $id = $data['id'];
  7559. unset($data['id']);
  7560. $user = User::where('id', $data['user_id'])->first();
  7561. if (empty($user)) {
  7562. return Result::error("暂无相关用户信息", 0);
  7563. }
  7564. if ($user->type_id == 10000) {
  7565. $data['status'] = 1;
  7566. } else {
  7567. $data['status'] = 0;
  7568. }
  7569. unset($data['user_id']);
  7570. if ($data['keyword'] == '') {
  7571. //提取标题+内容中的关键词
  7572. $data['keyword'] = $data['title'];
  7573. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7574. Jieba::init(); // 初始化 jieba-php
  7575. Finalseg::init();
  7576. $segList = Jieba::cut($data['keyword']);
  7577. $segList1 = array_slice($segList, 0, 8);
  7578. $data['keyword'] = implode(',', $segList1);
  7579. }
  7580. if ($data['description'] == '') {
  7581. //提取内容中的描述
  7582. // var_dump(11111);
  7583. //提取内容中的描述
  7584. $content = $data['introduce'];
  7585. // 去除 <style> 和 <script> 标签及其内容
  7586. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7587. // 去除所有 HTML 标签
  7588. $content = strip_tags($content);
  7589. // 去除 HTML 实体
  7590. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7591. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7592. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7593. // 去除多余空白
  7594. $content = preg_replace('/\s+/u', '', $content);
  7595. // 截取 100 个字符
  7596. $data['description'] = mb_substr($content, 0, 100);
  7597. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7598. }
  7599. if ($data['status'] == 0) {
  7600. $this->sendMessage([
  7601. 'talk_type' => 1000,
  7602. 'title' => $data['title'],
  7603. 'content' => '提交了审核',
  7604. 'messageType' => 9,
  7605. ]);
  7606. }
  7607. $result = Project::where('id', $id)->update($data);
  7608. if (empty($result)) {
  7609. return Result::error("更新失败", 0);
  7610. }
  7611. return Result::success($result);
  7612. }
  7613. /**
  7614. * 删除项目
  7615. * @param array $data
  7616. * @return array
  7617. */
  7618. public function delProject(array $data): array
  7619. {
  7620. $user = User::where('id', $data['user_id'])->first();
  7621. if (empty($user)) {
  7622. return Result::error("暂无相关用户信息", 0);
  7623. }
  7624. $project = Project::where('id', $data['id'])->first();
  7625. if (empty($project)) {
  7626. return Result::error("暂无相关项目信息", 0);
  7627. }
  7628. $result = Project::where('id', $data['id'])->delete();
  7629. if (empty($result)) {
  7630. return Result::error("删除失败", 0);
  7631. }
  7632. return Result::success($result);
  7633. }
  7634. /**
  7635. * 审核项目
  7636. * @param array $data
  7637. * @return array
  7638. */
  7639. public function checkProject(array $data): array
  7640. {
  7641. $user = User::where('id', $data['user_id'])->first();
  7642. if (empty($user)) {
  7643. return Result::error("暂无相关用户信息", 0);
  7644. }
  7645. // 0:未审核; 1:已审核; 2:已拒绝;
  7646. if ($user->type_id != 10000) {
  7647. if ($data['status'] == 1 || $data['status'] == 2) {
  7648. return Result::error("此用户权限不足", 0);
  7649. }
  7650. }
  7651. $project = Project::where('id', $data['id'])->first();
  7652. if (empty($project)) {
  7653. return Result::error("暂无相关项目信息", 0);
  7654. }
  7655. if ($data['status'] == 2) {
  7656. $this->sendMessage([
  7657. 'talk_type' => 1001,
  7658. 'title' => $project['title'],
  7659. 'content' => '审核拒绝',
  7660. 'messageType' => 9,
  7661. 'user_id' => $project['user_id'],
  7662. ]);
  7663. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7664. } else {
  7665. if ($data['status'] == 1) {
  7666. $this->sendMessage([
  7667. 'talk_type' => 1001,
  7668. 'title' => $project['title'],
  7669. 'content' => '审核通过',
  7670. 'messageType' => 9,
  7671. 'user_id' => $project['user_id'],
  7672. ]);
  7673. } else if ($data['status'] == 0) {
  7674. $this->sendMessage([
  7675. 'talk_type' => 1000,
  7676. 'title' => $project['title'],
  7677. 'content' => '提交了审核',
  7678. 'messageType' => 9,
  7679. ]);
  7680. }
  7681. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7682. }
  7683. if (empty($result)) {
  7684. return Result::error("审核失败", 0);
  7685. }
  7686. return Result::success($result);
  7687. }
  7688. /**
  7689. * 获取项目详情
  7690. * @param array $data
  7691. * @return array
  7692. */
  7693. public function getProjectInfo(array $data): array
  7694. {
  7695. $project = Project::where('id', $data['id'])->first();
  7696. if (empty($project)) {
  7697. return Result::error("暂无相关项目信息", 0);
  7698. }
  7699. return Result::success($project);
  7700. }
  7701. public function getWebsiteCompanyInfo(array $data): array
  7702. {
  7703. $company = Company::where('id', $data['id'])
  7704. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7705. ->where('status', 1)
  7706. // ->where('website_id', $data['website_id'])
  7707. ->select('company.*', 'job_industry.hyname as hy_name')
  7708. ->first();
  7709. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7710. $jobnature_id = $company['jobnature_id'] ?? null;
  7711. if ($jobnature_id !== null) {
  7712. switch ($jobnature_id) {
  7713. case 0:
  7714. $company->jobnature_name = '市场监督';
  7715. break;
  7716. case 1:
  7717. $company->jobnature_name = '信访纪检';
  7718. break;
  7719. case 2:
  7720. $company->jobnature_name = '公检法司';
  7721. break;
  7722. case 3:
  7723. $company->jobnature_name = '高关注机构';
  7724. break;
  7725. default:
  7726. $company->jobnature_name = '';
  7727. break;
  7728. }
  7729. } else {
  7730. $company->jobnature_name = '';
  7731. }
  7732. $city_arr = $company->city_arr_id;
  7733. if (!empty($city_arr)) {
  7734. $city_arr = json_decode($city_arr, true);
  7735. $cityNames = District::whereIn('id', $city_arr)
  7736. ->pluck('name')
  7737. ->implode('-');
  7738. $company->city_name = $cityNames;
  7739. } else {
  7740. $company->city_name = '';
  7741. }
  7742. if (empty($company)) {
  7743. return Result::error("暂无相关公司信息", 0);
  7744. }
  7745. return Result::success($company);
  7746. }
  7747. public function getMSG(array $data): array
  7748. {
  7749. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7750. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7751. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7752. $result = [];
  7753. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7754. //最近的5篇已审的文章
  7755. $apply_articale = Article::where('status', 1)
  7756. ->where('admin_user_id', $user_id)
  7757. ->orderBy('updated_at', 'desc')
  7758. // ->limit(5)
  7759. ->get();
  7760. //获取5条用户的已审核商品
  7761. $good = Good::where('status', 2)
  7762. ->where('user_id', $user_id)
  7763. ->orderBy('updated_at', 'desc')
  7764. // ->limit(5)
  7765. ->get();
  7766. //获取5条用户待审核的公告
  7767. $notice = Notice::where('status', 2)
  7768. ->where('user_id', $user_id)
  7769. ->orderBy('updated_at', 'desc')
  7770. ->limit(5)->get();
  7771. //获取5条用户的待审核投诉
  7772. $complaint = Complaint::where('status', 2)
  7773. ->where('user_id', $user_id)
  7774. ->orderBy('updated_at', 'desc')
  7775. // ->limit(5)
  7776. ->get();
  7777. //获取5条用户的book
  7778. $book = Book::where('status', 2)
  7779. ->where('user_id', $user_id)
  7780. ->orderBy('updated_at', 'desc')
  7781. // ->limit(5)
  7782. ->get();
  7783. //获取5条用户的求职
  7784. //获取5条用户的求职 1
  7785. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7786. ->where('job_hunting.user_id', $user_id)
  7787. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7788. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7789. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7790. ->orderBy('updated_at', 'desc')
  7791. // ->limit(5)
  7792. ->get();
  7793. //获取5条用户的求职 2
  7794. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7795. ->where('job_recruiting.user_id', $user_id)
  7796. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7797. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7798. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7799. ->orderBy('updated_at', 'desc')
  7800. // ->limit(5)
  7801. ->get();
  7802. //人才库 1
  7803. $job_apply = JobApply::where('job_apply.status', 1)
  7804. ->where('job_apply.receiver_id', $user_id)
  7805. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7806. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7807. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7808. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7809. ->select('job_recruiting', 'job_recruiting.', '', '')
  7810. ->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')
  7811. ->orderBy('updated_at', 'desc')
  7812. // ->limit(5)
  7813. ->get();
  7814. // 职场机会 2
  7815. $job_resume = JobResume::where('job_resume.status', 1)
  7816. ->where('job_resume.receiver_id', $user_id)
  7817. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7818. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7819. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7820. ->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')
  7821. ->orderBy('updated_at', 'desc')
  7822. // ->limit(5)
  7823. ->get();
  7824. //获取5条用户待处理的投诉
  7825. $complaint_deal = Complaint::where('status', 2)
  7826. ->where('deal', 1)
  7827. ->whereJsonContains('re_user_ids', $user_id)
  7828. ->orderBy('updated_at', 'desc')
  7829. // ->limit(5)
  7830. ->get();
  7831. //获取 被通知者未读信息
  7832. $notice_unread = Notice::where('status', 2)
  7833. ->whereJsonContains('re_user_ids', $user_id)
  7834. //未读消息
  7835. ->where(function ($query) use ($user_id) {
  7836. $query->whereJsonDoesntContain('read_id', $user_id)
  7837. ->orWhereNull('read_id');
  7838. })
  7839. ->orderBy('updated_at', 'desc')
  7840. ->get();
  7841. $complaint_unread = Complaint::where('status', 2)
  7842. ->whereJsonContains('re_user_ids', $user_id)
  7843. //未读消息
  7844. ->where(function ($query) use ($user_id) {
  7845. $query->whereJsonDoesntContain('read_id', $user_id)
  7846. ->orWhereNull('read_id');
  7847. })
  7848. ->orderBy('updated_at', 'desc')
  7849. ->get();
  7850. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7851. $complany = Company::where('status', 1)
  7852. ->where('user_id', $user_id)
  7853. ->orderBy('updated_at', 'desc')
  7854. // ->limit(5)
  7855. ->get();
  7856. //获取5条单聊未读聊天消息
  7857. // $chat = ChatRecords::where('is_read', 0)
  7858. // ->where('user_id', $user_id)
  7859. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7860. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7861. // ->where('action', 'recieved')
  7862. // ->where('talk_type', 1)
  7863. // ->orderBy('created_at', 'desc')
  7864. // // ->limit(5)
  7865. // ->get();
  7866. //获取5条未读群聊信息
  7867. // $chat_group = ChatRecords::where('is_read', 0)
  7868. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7869. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7870. // ->where('user_id', $user_id)
  7871. // ->where('talk_type', 2)
  7872. // ->orderBy('created_at', 'desc')
  7873. // // ->limit(5)
  7874. // ->get();
  7875. //获取5条用户的待审核项目
  7876. $project = Project::where('status', 1)
  7877. ->where('user_id', $user_id)
  7878. ->orderBy('updated_at', 'desc')
  7879. // ->limit(5)
  7880. ->get();
  7881. // count($chat) + count($chat_group) +
  7882. $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)
  7883. + count($complany)
  7884. + count($project)
  7885. + count($notice_unread)
  7886. + count($complaint_unread)
  7887. // + count($chat) + count($chat_group)
  7888. ;
  7889. $result = [
  7890. 'apply_articale' => $apply_articale,
  7891. // 'chat' => $chat,
  7892. // 'chat_group' => $chat_group,
  7893. 'good' => $good,
  7894. 'notice' => $notice,
  7895. 'complaint' => $complaint,
  7896. 'book' => $book,
  7897. 'job_hunting' => $job_hunting,
  7898. 'job_recruiting' => $job_recruiting,
  7899. 'job_apply' => $job_apply,
  7900. 'job_resume' => $job_resume,
  7901. 'complaint_deal' => $complaint_deal,
  7902. 'complany' => $complany,
  7903. 'project' => $project,
  7904. 'notice_unread' => $notice_unread,
  7905. 'complaint_unread' => $complaint_unread,
  7906. 'count' => $count,
  7907. ];
  7908. } elseif ($type_id == 12) {
  7909. //最近的5篇已审的文章
  7910. $apply_articale = Article::where('status', 1)
  7911. ->where('admin_user_id', $user_id)
  7912. ->limit(5)->get();
  7913. //获取5条单聊未读聊天消息
  7914. $chat = ChatRecords::where('is_read', 0)
  7915. ->where('user_id', $user_id)
  7916. ->where('talk_type', 1)
  7917. ->orderBy('created_at', 'desc')
  7918. ->limit(5)->get();
  7919. //获取5条未读群聊信息
  7920. $chat_group = ChatRecords::where('is_read', 0)
  7921. ->where('user_id', $user_id)
  7922. ->where('talk_type', 2)
  7923. ->orderBy('created_at', 'desc')
  7924. ->limit(5)->get();
  7925. //获取5条用户的已审核商品
  7926. $good = Good::where('status', 2)
  7927. ->where('user_id', $user_id)
  7928. ->orderBy('updated_at', 'desc')
  7929. ->limit(5)->get();
  7930. //获取5条用户的book
  7931. $book = Book::where('status', 2)
  7932. ->where('user_id', $user_id)
  7933. ->orderBy('updated_at', 'desc')
  7934. ->limit(5)->get();
  7935. //获取5条用户的求职
  7936. //获取5条用户的求职 1
  7937. //count($chat) + count($chat_group)
  7938. $count = count($apply_articale) + count($good);
  7939. $result = [
  7940. 'apply_articale' => $apply_articale,
  7941. 'chat' => $chat,
  7942. 'chat_group' => $chat_group,
  7943. 'good' => $good,
  7944. 'book' => $book,
  7945. 'count' => $count,
  7946. ];
  7947. } elseif ($type_id == 13) {
  7948. //最近的5篇已审的文章
  7949. $apply_articale = Article::where('status', 1)
  7950. ->where('admin_user_id', $user_id)
  7951. ->limit(5)->get();
  7952. //获取5条单聊未读聊天消息
  7953. $chat = ChatRecords::where('is_read', 0)
  7954. ->where('user_id', $user_id)
  7955. ->where('talk_type', 1)
  7956. ->orderBy('created_at', 'desc')
  7957. ->limit(5)->get();
  7958. //获取5条未读群聊信息
  7959. $chat_group = ChatRecords::where('is_read', 0)
  7960. ->where('user_id', $user_id)
  7961. ->where('talk_type', 2)
  7962. ->orderBy('created_at', 'desc')
  7963. ->limit(5)->get();
  7964. //获取5条用户的已审核商品
  7965. $good = Good::where('status', 2)
  7966. ->where('user_id', $user_id)
  7967. ->orderBy('updated_at', 'desc')
  7968. ->limit(5)->get();
  7969. //count($chat) + count($chat_group) +
  7970. $count = count($apply_articale) + count($good);
  7971. $result = [
  7972. 'apply_articale' => $apply_articale,
  7973. 'chat' => $chat,
  7974. 'chat_group' => $chat_group,
  7975. 'good' => $good,
  7976. 'count' => $count,
  7977. ];
  7978. } elseif ($type_id == 14) {
  7979. //最近的5篇已审的文章
  7980. $apply_articale = Article::where('status', 1)
  7981. ->where('admin_user_id', $user_id)
  7982. // ->limit(5)
  7983. ->get();
  7984. //获取5条用户的已审核商品
  7985. $good = Good::where('status', 2)
  7986. ->where('user_id', $user_id)
  7987. ->orderBy('updated_at', 'desc')
  7988. // ->limit(5)
  7989. ->get();
  7990. $count = count($apply_articale) + count($good);
  7991. $result = [
  7992. 'apply_articale' => $apply_articale,
  7993. 'chat' => '',
  7994. 'chat_group' => '',
  7995. 'good' => $good,
  7996. 'count' => $count,
  7997. ];
  7998. } elseif ($type_id == 10000) {
  7999. //获取未审核的5篇文章
  8000. $apply_articale = Article::where('status', 0)
  8001. ->orderBy('updated_at', 'desc')
  8002. // ->limit(5)
  8003. ->get();
  8004. //获取5条单聊未读聊天消息
  8005. //获取5条单聊未读聊天消息
  8006. // $chat = ChatRecords::where('is_read', 0)
  8007. // ->where('user_id', $user_id)
  8008. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  8009. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  8010. // ->where('action', 'recieved')
  8011. // ->where('talk_type', 1)
  8012. // ->orderBy('created_at', 'desc')
  8013. // // ->limit(5)
  8014. // ->get();
  8015. // //获取5条未读群聊信息
  8016. // $chat_group = ChatRecords::where('is_read', 0)
  8017. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  8018. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  8019. // ->where('user_id', $user_id)
  8020. // ->where('talk_type', 2)
  8021. // ->orderBy('created_at', 'desc')
  8022. // // ->limit(5)
  8023. // ->get();
  8024. //获取5条用户的已审核商品
  8025. $good = Good::where('status', 1)
  8026. // ->where('user_id', $user_id)
  8027. ->orderBy('updated_at', 'desc')
  8028. // ->limit(5)
  8029. ->get();
  8030. //获取5条用户待审核的公告
  8031. $notice = Notice::where('status', 1)
  8032. ->orderBy('updated_at', 'desc')
  8033. // ->limit(5)
  8034. ->get();
  8035. //获取5条用户的待审核投诉
  8036. $complaint = Complaint::where('status', 1)
  8037. ->orderBy('updated_at', 'desc')
  8038. // ->limit(5)
  8039. ->get();
  8040. //获取5条用户的book
  8041. $book = Book::where('status', 1)
  8042. ->orderBy('updated_at', 'desc')
  8043. // ->limit(5)
  8044. ->get();
  8045. //获取5条用户的求职 1
  8046. $job_hunting = JobHunting::where('job_hunting.status', 1)
  8047. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  8048. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  8049. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  8050. ->orderBy('updated_at', 'desc')
  8051. // ->limit(5)
  8052. ->get();
  8053. //获取5条用户的求职 2
  8054. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  8055. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  8056. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  8057. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  8058. ->orderBy('updated_at', 'desc')
  8059. // ->limit(5)
  8060. ->get();
  8061. //人才库 1
  8062. $job_apply = JobApply::where('job_apply.status', 1)
  8063. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  8064. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  8065. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  8066. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  8067. ->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')
  8068. ->orderBy('updated_at', 'desc')
  8069. // ->limit(5)
  8070. ->get();
  8071. // 职场机会 2
  8072. $job_resume = JobResume::where('job_resume.status', 1)
  8073. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  8074. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  8075. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  8076. ->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')
  8077. ->orderBy('updated_at', 'desc')
  8078. // ->limit(5)
  8079. ->get();
  8080. //待审核数据com pro
  8081. $complany = Company::where('status', 0)
  8082. ->orderBy('updated_at', 'desc')
  8083. // ->limit(5)
  8084. ->get();
  8085. $project = Project::where('status', 0)
  8086. ->orderBy('updated_at', 'desc')
  8087. // ->limit(5)
  8088. ->get();
  8089. $count =
  8090. // count($chat) +
  8091. // count($chat_group) +
  8092. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  8093. // + count($job_apply)
  8094. // + count($job_resume)
  8095. + count($complany)
  8096. + count($project);
  8097. $result = [
  8098. 'apply_articale' => $apply_articale,
  8099. // 'chat' => $chat,
  8100. // 'chat_group' => $chat_group,
  8101. 'good' => $good,
  8102. 'notice' => $notice,
  8103. 'complaint' => $complaint,
  8104. 'book' => $book,
  8105. 'job_hunting' => $job_hunting,
  8106. 'job_recruiting' => $job_recruiting,
  8107. // 'job_apply' => $job_apply,
  8108. // 'job_resume' => $job_resume,
  8109. 'complany' => $complany,
  8110. 'project' => $project,
  8111. 'count' => $count,
  8112. ];
  8113. } elseif ($type_id == 20000) {
  8114. }
  8115. var_dump($type_id, '-----------------test---------');
  8116. return Result::success($result);
  8117. }
  8118. /**
  8119. * @param array $data
  8120. * @return array
  8121. */
  8122. public function getWebsiteProject(array $data): array
  8123. {
  8124. $categorys = json_decode($data['id'], true);
  8125. if (!empty($categorys)) {
  8126. $category_arr = $this->processArticlePro($data['website_id']);
  8127. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8128. $catiall = $category_arr['catiall'];
  8129. // return Result::success($catiall);
  8130. foreach ($categorys as $key => $val) {
  8131. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  8132. $level = explode(',', $val['level'])[0];
  8133. $imgnum = explode(',', $val['level'])[1] ?? null;
  8134. $textnum = explode(',', $val['level'])[2] ?? null;
  8135. if ($level == 1) {
  8136. if (!empty($textnum) && $textnum > 0) {
  8137. $text_num = Project::where('level', $level)
  8138. ->where('website_id', $data['website_id'])
  8139. ->where('status', 1)
  8140. ->select(
  8141. 'project.id',
  8142. 'project.title',
  8143. 'project.description',
  8144. 'project.updated_at',
  8145. 'project.category_id',
  8146. 'project.cat_arr_id'
  8147. )
  8148. ->orderBy('updated_at', 'desc')
  8149. ->limit($textnum)
  8150. ->get()->all();
  8151. }
  8152. if (!empty($imgnum) && $imgnum > 0) {
  8153. $img_num = Project::where('level', $level)
  8154. ->where('website_id', $data['website_id'])
  8155. ->where('status', 1)
  8156. ->where('imgurl', '!=', '')
  8157. ->whereNotNull('imgurl')
  8158. ->select(
  8159. 'project.id',
  8160. 'project.title',
  8161. 'project.description',
  8162. 'project.updated_at',
  8163. 'project.imgurl as imgs',
  8164. 'project.category_id',
  8165. 'project.cat_arr_id'
  8166. )
  8167. ->orderBy('updated_at', 'desc')
  8168. ->limit($imgnum)
  8169. ->get()->all();
  8170. }
  8171. } else {
  8172. if (!empty($textnum) && $textnum > 0) {
  8173. $text_num = Project::where('website_id', $data['website_id'])
  8174. ->where('status', 1)
  8175. ->select(
  8176. 'project.id',
  8177. 'project.title',
  8178. 'project.description',
  8179. 'project.updated_at',
  8180. 'project.category_id',
  8181. 'project.cat_arr_id',
  8182. 'project.website_id',
  8183. 'project.updated_at',
  8184. 'project.created_at'
  8185. )
  8186. ->orderBy('updated_at', 'desc')
  8187. ->limit($textnum)
  8188. ->get()->all();
  8189. }
  8190. if (!empty($imgnum) && $imgnum > 0) {
  8191. $img_num = Project::where('website_id', $data['website_id'])
  8192. ->where('status', 1)
  8193. ->where('imgurl', '!=', '')
  8194. ->whereNotNull('imgurl')
  8195. ->select(
  8196. 'project.id',
  8197. 'project.title',
  8198. 'project.description',
  8199. 'project.updated_at',
  8200. 'project.imgurl as imgs',
  8201. 'project.category_id',
  8202. 'project.cat_arr_id'
  8203. )
  8204. ->orderBy('updated_at', 'desc')
  8205. ->limit($imgnum)
  8206. ->get()->all();
  8207. }
  8208. }
  8209. }
  8210. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  8211. $category_ids = explode(',', $val['id'])[0];
  8212. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  8213. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  8214. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  8215. if (!empty($cat_textnum) && $cat_textnum > 0) {
  8216. $text_num = Project::whereIn('category_id', $category_arr)
  8217. ->where('website_id', $data['website_id'])
  8218. ->where('status', 1)
  8219. ->select(
  8220. 'project.id',
  8221. 'project.title',
  8222. 'project.description',
  8223. 'project.updated_at',
  8224. 'project.category_id',
  8225. 'project.cat_arr_id'
  8226. )
  8227. ->orderBy('updated_at', 'desc')
  8228. ->limit($cat_textnum)
  8229. ->get()->all();
  8230. }
  8231. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  8232. $img_num = Project::whereIn('category_id', $category_arr)
  8233. ->where('website_id', $data['website_id'])
  8234. ->where('status', 1)
  8235. ->where('imgurl', '!=', '')
  8236. ->whereNotNull('imgurl')
  8237. ->select(
  8238. 'project.id',
  8239. 'project.title',
  8240. 'project.description',
  8241. 'project.updated_at',
  8242. 'project.imgurl as imgs',
  8243. 'project.category_id',
  8244. 'project.cat_arr_id'
  8245. )
  8246. ->orderBy('updated_at', 'desc')
  8247. ->limit($cat_imgnum)
  8248. ->get()->all();
  8249. }
  8250. }
  8251. if (!empty($img_num)) {
  8252. foreach ($img_num as $k => $v) {
  8253. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8254. $imgurl = json_decode($v['imgs'], true);
  8255. if (!empty($imgurl)) {
  8256. $img_num[$k]->imgurl = $imgurl[0];
  8257. }
  8258. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8259. }
  8260. }
  8261. if (!empty($text_num)) {
  8262. foreach ($text_num as $k => $v) {
  8263. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8264. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8265. }
  8266. }
  8267. $project[$key]['img_num'] = $img_num ?? [];
  8268. $project[$key]['text_num'] = $text_num ?? [];
  8269. }
  8270. }
  8271. if (empty($project)) {
  8272. return Result::error("暂无相关项目信息", 0);
  8273. }
  8274. return Result::success($project);
  8275. }
  8276. /**
  8277. * @param array $data
  8278. * @return array
  8279. */
  8280. public function getWebsiteProjectInfo(array $data): array
  8281. {
  8282. $project = Project::where('id', $data['id'])
  8283. ->where('status', 1)
  8284. ->where('website_id', $data['website_id'])
  8285. ->select('project.*')
  8286. ->first();
  8287. if (empty($project)) {
  8288. return Result::error("暂无相关项目信息", 0);
  8289. }
  8290. return Result::success($project);
  8291. }
  8292. /**
  8293. * @param array $data
  8294. * @return array
  8295. */
  8296. public function getWebsiteProjectList(array $data): array
  8297. {
  8298. $where = [];
  8299. if (isset($data['category_id']) && !empty($data['category_id'])) {
  8300. $where['category_id'] = $data['category_id'];
  8301. }
  8302. if (isset($data['keyword']) && !empty($data['keyword'])) {
  8303. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  8304. }
  8305. $query = Project::where($where)
  8306. ->where('status', 1)
  8307. ->where('website_id', $data['website_id'])
  8308. ->select(
  8309. 'project.id',
  8310. 'project.title',
  8311. 'project.description',
  8312. 'project.imgurl as imgs',
  8313. 'project.category_id',
  8314. 'project.cat_arr_id'
  8315. )
  8316. ->orderBy('updated_at', 'desc');
  8317. $count = $query->count();
  8318. $project = $query->clone()
  8319. ->offset(($data['page'] - 1) * $data['pageSize'])
  8320. ->limit($data['pageSize'])
  8321. ->get()->all();
  8322. if (empty($project)) {
  8323. return Result::error("暂无相关项目信息", 0);
  8324. }
  8325. $categorys = $this->processArticlePro($data['website_id']);
  8326. $catiall = $categorys['catiall'];
  8327. foreach ($project as $key => $val) {
  8328. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  8329. if (!empty($val['imgs'])) {
  8330. $imgurl = json_decode($val['imgs'], true);
  8331. if (!empty($imgurl)) {
  8332. $project[$key]->imgurl = $imgurl[0];
  8333. }
  8334. } else {
  8335. $project[$key]->imgurl = '';
  8336. }
  8337. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  8338. }
  8339. $result = [
  8340. 'rows' => $project,
  8341. 'count' => $count,
  8342. ];
  8343. return Result::success($result);
  8344. }
  8345. /**
  8346. * @param array $data
  8347. * @return array
  8348. */
  8349. public function getWebsiteCategoryJob(array $data): array
  8350. {
  8351. $categorys = json_decode($data['id'], true);
  8352. if (!empty($categorys)) {
  8353. $category_arr = $this->processArticlePro($data['website_id']);
  8354. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8355. $catiall = $category_arr['catiall'];
  8356. foreach ($categorys as $key => $val) {
  8357. if (isset($val['id']) && !empty($val['id'])) {
  8358. $catid = explode(',', $val['id'])[0] ?? null;
  8359. $type = explode(',', $val['id'])[1] ?? null;
  8360. $textnum = explode(',', $val['id'])[2] ?? null;
  8361. }
  8362. // 4:招聘;5:求职;
  8363. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  8364. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  8365. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  8366. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  8367. ->where('job_recruiting.status', 1)
  8368. ->where('job_recruiting.website_id', $data['website_id'])
  8369. ->select(
  8370. 'job_recruiting.id',
  8371. 'job_recruiting.title',
  8372. 'job_company.business_name',
  8373. 'job_recruiting.updated_at',
  8374. 'job_recruiting.cat_arr_id',
  8375. 'job_recruiting.keyword',
  8376. 'job_recruiting.description'
  8377. )
  8378. ->orderBy('job_recruiting.updated_at', 'desc')
  8379. ->limit($textnum)
  8380. ->get()->all();
  8381. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  8382. // 状态 审核状态,1待审核2已审核3已拒绝
  8383. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  8384. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  8385. ->where('job_hunting.status', 2)
  8386. ->where('job_hunting.website_id', $data['website_id'])
  8387. ->select(
  8388. 'job_hunting.id',
  8389. 'job_hunting.name',
  8390. 'job_hunting.cat_arr_id',
  8391. 'job_position.zwname as job_name',
  8392. 'job_hunting.updated_at',
  8393. // 'job_hunting.keyword',
  8394. 'job_hunting.slelf_evaluation'
  8395. )
  8396. ->orderBy('updated_at', 'desc')
  8397. ->limit($textnum)
  8398. ->get()->all();
  8399. } else {
  8400. $job = [];
  8401. }
  8402. // var_dump($catid.'222uuuuuuu'.$key);
  8403. if (!empty($job)) {
  8404. foreach ($job as $k => $value) {
  8405. if (isset($value->cat_arr_id)) {
  8406. $catArr = json_decode($value->cat_arr_id, true);
  8407. $catId = end($catArr);
  8408. } else {
  8409. continue;
  8410. }
  8411. if (isset($catiall[$catId])) {
  8412. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  8413. }
  8414. }
  8415. }
  8416. // var_dump($catid.'xxxxx'.$key);
  8417. $result[$key] = $job ?? [];
  8418. }
  8419. }
  8420. if (empty($result)) {
  8421. return Result::error("暂无相关分类信息", 0);
  8422. }
  8423. return Result::success($result);
  8424. }
  8425. /**
  8426. * 发送消息
  8427. * @param array $messageData
  8428. * @return void
  8429. */
  8430. public function sendMessage($messageData)
  8431. {
  8432. $msg = [
  8433. 'talk_type' => $messageData['talk_type'],
  8434. 'title' => $messageData['title'],
  8435. 'content' => $messageData['content'],
  8436. 'messageType' => $messageData['messageType'],
  8437. 'user_id' => $messageData['user_id'] ?? '',
  8438. 'time' => microtime(),
  8439. ];
  8440. $message = new MqProducer($msg);
  8441. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  8442. $producer->produce($message);
  8443. }
  8444. /**
  8445. * 行业分类管理 ------1121
  8446. * @param array $data
  8447. * @return array
  8448. */
  8449. public function getJobIndustryList(array $data): array
  8450. {
  8451. $page = $data['page'] ?? 1;
  8452. $page_size = $data['page_size'] ?? 10;
  8453. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8454. $where = ['hyname', 'like', '%' . $data['hyname'] . '%'];
  8455. } else {
  8456. $where = [];
  8457. }
  8458. $rs_query = JobIndustry::when(!empty($where), function ($query) use ($where) {
  8459. $query->where([$where]); // 修复:将条件包装成二维数组
  8460. })
  8461. ->orderBy('updated_at', 'desc');
  8462. $count = $rs_query->count();
  8463. $hy = $rs_query->offset(($page - 1) * $page_size)->limit($page_size)->get()->all();
  8464. $result = [
  8465. 'count' => $count,
  8466. 'list' => $hy,
  8467. ];
  8468. if (empty($hy)) {
  8469. return Result::success('暂无数据');
  8470. }
  8471. return Result::success($result);
  8472. }
  8473. /**
  8474. * 添加行业分类
  8475. * @param array $data
  8476. * @return array
  8477. */
  8478. public function addJobIndustry(array $data): array
  8479. {
  8480. $hy_name = JobIndustry::where('hyname', $data['hyname'])->first(['hyid']);
  8481. if (!empty($hy_name)) {
  8482. return Result::error('行业分类已存在');
  8483. }
  8484. $hy = JobIndustry::insertGetId($data);
  8485. if (empty($hy)) {
  8486. return Result::error('添加失败');
  8487. }
  8488. return Result::success($hy);
  8489. }
  8490. /**
  8491. * 更新行业分类
  8492. * @param array $data
  8493. * @return array
  8494. */
  8495. public function upJobIndustry(array $data): array
  8496. {
  8497. $hy_query = JobIndustry::get();
  8498. $hy_ids = $hy_query->pluck('hyid')->toArray();
  8499. $hy_names = $hy_query->pluck('hyname')->toArray();
  8500. if (!in_array($data['hyid'], $hy_ids)) {
  8501. return Result::error('行业分类不存在');
  8502. }
  8503. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8504. $other_key_hy = array_search($data['hyid'], $hy_ids);
  8505. // return Result::success($other_key_hy);
  8506. unset($hy_names[$other_key_hy]);
  8507. if (in_array($data['hyname'], $hy_names)) {
  8508. return Result::error('行业分类名称已存在');
  8509. }
  8510. }
  8511. $hy = JobIndustry::where('hyid', $data['hyid'])->update($data);
  8512. if (empty($hy)) {
  8513. return Result::error('更新失败');
  8514. }
  8515. return Result::success($hy);
  8516. }
  8517. /**
  8518. * 删除行业分类
  8519. * @param array $data
  8520. * @return array
  8521. */
  8522. public function delJobIndustry(array $data): array
  8523. {
  8524. $hy_id = JobIndustry::where('hyid', $data['hyid'])->first(['hyid']);
  8525. if (empty($hy_id)) {
  8526. return Result::error('行业分类不存在');
  8527. }
  8528. $hy = JobIndustry::where('hyid', $data['hyid'])->delete();
  8529. if (empty($hy)) {
  8530. return Result::error('删除失败');
  8531. }
  8532. return Result::success($hy);
  8533. }
  8534. /**
  8535. * 职位分类-列表
  8536. * @param array $data
  8537. * @return array
  8538. */
  8539. public function getJobPositionList(array $data): array
  8540. {
  8541. $page = $data['page'] ?? 1;
  8542. $page_size = $data['page_size'] ?? 10;
  8543. $where = [];
  8544. if (isset($data['zwname']) && !empty($data['zwname'])) {
  8545. $zwids = JobPosition::where('zwpid', 0)
  8546. ->when(!empty($data['zwname']), function ($query) use ($data) {
  8547. $query->where('zwname', 'like', '%' . $data['zwname'] . '%');
  8548. })
  8549. ->orderBy('updated_at', 'desc')
  8550. ->pluck('zwid')
  8551. // ->get()
  8552. ->toArray();
  8553. }
  8554. if (isset($data['childname']) && !empty($data['childname'])) {
  8555. $child_zwids = JobPosition::where('zwpid', '!=', 0)
  8556. ->when(!empty($data['childname']), function ($query) use ($data) {
  8557. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8558. })
  8559. ->orderBy('updated_at', 'desc')
  8560. ->pluck('zwpid')
  8561. // ->get()
  8562. ->toArray();
  8563. if (isset($zwids) && is_array($zwids) && is_array($child_zwids)) {
  8564. $child_zwids = array_intersect($zwids, $child_zwids);
  8565. }
  8566. $zwids = array_values(array_unique($child_zwids));
  8567. }
  8568. $zwids = $zwids ?? null;
  8569. $count = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8570. $query->whereIn('zwid', $zwids);
  8571. })
  8572. ->where('zwpid', 0)
  8573. ->count();
  8574. $position = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8575. $query->whereIn('zwid', $zwids);
  8576. })
  8577. ->where('zwpid', 0)
  8578. ->orderBy('updated_at', 'desc')
  8579. ->offset(($page - 1) * $page_size)
  8580. ->limit($page_size)->get()
  8581. ->map(function ($item) use ($data) {
  8582. $item->children = $item->where('zwpid', $item->zwid)
  8583. ->when(!empty($data['childname']), function ($query) use ($data) {
  8584. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8585. })
  8586. ->orderBy('updated_at', 'desc')
  8587. ->get();
  8588. return $item;
  8589. })
  8590. ->all();
  8591. $result = [
  8592. 'count' => $count,
  8593. 'list' => $position,
  8594. ];
  8595. if (empty($result)) {
  8596. return Result::success('暂无数据');
  8597. }
  8598. return Result::success($result);
  8599. }
  8600. /**
  8601. * 职位分类-添加
  8602. * @param array $data
  8603. * @return array
  8604. */
  8605. public function addJobPosition(array $data): array
  8606. {
  8607. $zw_name = JobPosition::where('zwpid', $data['zwpid'])
  8608. ->where('zwname', $data['zwname'])->first(['zwid']);
  8609. if (!empty($zw_name)) {
  8610. return Result::error('职位分类已存在');
  8611. }
  8612. $zw = JobPosition::insertGetId($data);
  8613. if(empty($zw)){
  8614. return Result::error('添加失败');
  8615. }
  8616. return Result::success($zw);
  8617. }
  8618. /**
  8619. * 更新职位分类
  8620. * @param array $data
  8621. * @return array
  8622. */
  8623. public function upJobPosition(array $data): array
  8624. {
  8625. $zw_position = JobPosition::get();
  8626. if (!in_array($data['zwid'], $zw_position->pluck('zwid')->toArray())) {
  8627. return Result::error('职位分类不存在');
  8628. }
  8629. $zw_name = $zw_position->where('zwid', '!=', $data['zwid'])
  8630. ->where('zwpid', $data['zwpid'])
  8631. ->where('zwname', $data['zwname'])->first();
  8632. if (!empty($zw_name)) {
  8633. return Result::error('职位分类已存在');
  8634. }
  8635. $result = JobPosition::where('zwid', $data['zwid'])->update($data);
  8636. if (empty($result)) {
  8637. return Result::error('更新失败');
  8638. }
  8639. return Result::success($result);
  8640. }
  8641. /**
  8642. * 删除职位分类
  8643. * @param array $data
  8644. * @return array
  8645. */
  8646. public function delJobPosition(array $data): array
  8647. {
  8648. $zw_jobposition = JobPosition::get();
  8649. $zw_id = $zw_jobposition->where('zwid', $data['zwid'])->first();
  8650. if (empty($zw_id)) {
  8651. return Result::error('职位分类不存在');
  8652. }
  8653. if($zw_id->zwpid == 0){
  8654. $zw_job = JobPosition::where('zwpid', $zw_id->zwid)->first();
  8655. if(!empty($zw_job)){
  8656. return Result::error('请先删除子分类');
  8657. }
  8658. }
  8659. $result = JobPosition::where('zwid', $data['zwid'])->delete();
  8660. if (empty($result)) {
  8661. return Result::error('删除失败');
  8662. }
  8663. return Result::success($result);
  8664. }
  8665. /**
  8666. * 网民留言-添加
  8667. * @param array $data
  8668. * @return array
  8669. */
  8670. public function addMessage(array $data): array
  8671. {
  8672. $user = User::where('id', $data['user_id'])->first();
  8673. if (empty($user)) {
  8674. return Result::error('用户不存在');
  8675. }
  8676. if($user['type_id'] == 10000){
  8677. $data['status'] = 1;
  8678. }else{
  8679. $data['status'] = 0;
  8680. }
  8681. if ($data['keyword'] == '') {
  8682. //提取标题+内容中的关键词
  8683. $data['keyword'] = $data['title'];
  8684. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  8685. Jieba::init(); // 初始化 jieba-php
  8686. Finalseg::init();
  8687. $segList = Jieba::cut($data['keyword']);
  8688. $segList1 = array_slice($segList, 0, 8);
  8689. $data['keyword'] = implode(',', $segList1);
  8690. }
  8691. if ($data['description'] == '') {
  8692. //提取内容中的描述
  8693. $content = $data['content'];
  8694. // 去除 <style> 和 <script> 标签及其内容
  8695. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  8696. // 去除所有 HTML 标签
  8697. $content = strip_tags($content);
  8698. // 去除 HTML 实体
  8699. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  8700. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  8701. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  8702. // 去除多余空白
  8703. $content = preg_replace('/\s+/u', '', $content);
  8704. // 截取 100 个字符
  8705. $data['description'] = mb_substr($content, 0, 100);
  8706. }
  8707. if(!empty($data['reply'])){
  8708. $data['reply_userid'] = $data['user_id'];
  8709. }
  8710. $result = Message::insertGetId($data);
  8711. if(empty($result)){
  8712. return Result::error('添加失败');
  8713. }
  8714. return Result::success($result);
  8715. }
  8716. /**
  8717. * 网民留言-更新
  8718. * @param array $data
  8719. * @return array
  8720. */
  8721. public function upMessage(array $data): array
  8722. {
  8723. $user = User::where('id', $data['user_id'])->first();
  8724. if (empty($user)) {
  8725. return Result::error('用户不存在');
  8726. }
  8727. if($user['type_id'] == 10000){
  8728. $data['status'] = 1;
  8729. }else{
  8730. $data['status'] = 0;
  8731. }
  8732. $message = Message::where('id', $data['id'])->first();
  8733. if (empty($message)) {
  8734. return Result::error('留言不存在');
  8735. }
  8736. if($data['user_id'] != $message['user_id'] && $user['type_id'] != 10000){
  8737. return Result::error('非留言人不能更新');
  8738. }
  8739. if ($data['keyword'] == '') {
  8740. //提取标题+内容中的关键词
  8741. $data['keyword'] = $data['title'];
  8742. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  8743. Jieba::init(); // 初始化 jieba-php
  8744. Finalseg::init();
  8745. $segList = Jieba::cut($data['keyword']);
  8746. $segList1 = array_slice($segList, 0, 8);
  8747. $data['keyword'] = implode(',', $segList1);
  8748. }
  8749. if ($data['description'] == '') {
  8750. //提取内容中的描述
  8751. $content = $data['content'];
  8752. // 去除 <style> 和 <script> 标签及其内容
  8753. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  8754. // 去除所有 HTML 标签
  8755. $content = strip_tags($content);
  8756. // 去除 HTML 实体
  8757. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  8758. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  8759. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  8760. // 去除多余空白
  8761. $content = preg_replace('/\s+/u', '', $content);
  8762. // 截取 100 个字符
  8763. $data['description'] = mb_substr($content, 0, 100);
  8764. }
  8765. unset($data['id']);
  8766. if(!empty($data['reply'])){
  8767. $data['reply_userid'] = $data['user_id'];
  8768. unset($data['user_id']);
  8769. }
  8770. $result = Message::where('id', $message['id'])->update($data);
  8771. if (empty($result)) {
  8772. return Result::error('更新失败');
  8773. }
  8774. return Result::success($result);
  8775. }
  8776. /**
  8777. * 网民留言-删除
  8778. * @param array $data
  8779. * @return array
  8780. */
  8781. public function delMessage(array $data): array
  8782. {
  8783. $result = Message::where('id', $data['id'])->delete();
  8784. if (empty($result)) {
  8785. return Result::error('删除失败');
  8786. }
  8787. return Result::success($result);
  8788. }
  8789. /**
  8790. * 网民留言-更新状态
  8791. * @param array $data
  8792. * @return array
  8793. */
  8794. public function upMessageStatus(array $data): array
  8795. {
  8796. $message = Message::where('id', $data['id'])->first();
  8797. if (empty($message)) {
  8798. return Result::error('留言不存在!');
  8799. }
  8800. unset($data['id']);
  8801. unset($data['user_id']);
  8802. if($data['status'] != 2){
  8803. $data['reason'] = null;
  8804. }
  8805. $result = Message::where('id', $message['id'])->update($data);
  8806. if (empty($result)) {
  8807. return Result::error('留言更新失败!');
  8808. }
  8809. return Result::success($result);
  8810. }
  8811. /**
  8812. * 网民留言-获取详情
  8813. * @param array $data
  8814. * @return array
  8815. */
  8816. public function getMessageInfo(array $data): array
  8817. {
  8818. $result = Message::where('message.id', $data['id'])
  8819. ->leftJoin('website_column', 'message.column_id', '=', 'website_column.id')
  8820. ->select('message.*', 'website_column.column_arr_id')
  8821. ->first();
  8822. if (empty($result)) {
  8823. return Result::error('留言不存在!');
  8824. }
  8825. $result['column_arr_id'] = json_decode($result['column_arr_id'] ?? [], true);
  8826. return Result::success($result);
  8827. }
  8828. /**
  8829. * 网民留言-获取列表
  8830. * @param array $data
  8831. * @return array
  8832. */
  8833. public function getMessageList(array $data): array
  8834. {
  8835. $where = [];
  8836. if($data['is_master'] == 1){
  8837. $where['message.status'] = 1;
  8838. }else if($data['is_master'] == 2){
  8839. $where['message.status'] = 2;
  8840. }else if($data['is_master'] == 3){
  8841. $where['message.status'] = 0;
  8842. }
  8843. $user = User::where('id', $data['user_id'])->first();
  8844. if (empty($user)) {
  8845. return Result::error('用户不存在');
  8846. }
  8847. $column_arr_id = [];
  8848. if($user['type_id'] != 10000 && !empty($data['website_id'])){
  8849. $where['message.user_id'] = $data['user_id'];
  8850. $web = Website::where('id',$data['website_id'])->first('website_column_arr_id');
  8851. if(empty($web)){
  8852. return Result::error('此网站未关联任何网站属性!');
  8853. }
  8854. $column_arr_id = json_decode($web['website_column_arr_id'],true);
  8855. }
  8856. if(!empty($data['title'])){
  8857. array_push($where, ['message.title', 'like', '%'.$data['title'].'%']);
  8858. }
  8859. $result = Message::when($data['is_master'] == 0, function ($query) {
  8860. $query->whereIn('message.status', [0, 2]);
  8861. })
  8862. ->when(!empty($where), function ($query) use ($where) {
  8863. $query->where($where);
  8864. })
  8865. ->leftJoin('user', 'message.user_id', '=', 'user.id')
  8866. ->select('message.*', 'user.nickname')
  8867. ->orderBy('message.updated_at', 'desc')
  8868. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  8869. if(empty($result->items())) {
  8870. return Result::error('留言不存在!');
  8871. }
  8872. $result = [
  8873. 'data' => $result->items(),
  8874. 'count' => $result->total(),
  8875. ];
  8876. if(!empty($column_arr_id) && $user['type_id'] != 10000){
  8877. foreach($result['data'] as $key => $value){
  8878. if(in_array($value['column_id'], $column_arr_id)){
  8879. $result['data'][$key]['is_update'] = 1;
  8880. }else{
  8881. $result['data'][$key]['is_update'] = 0;
  8882. }
  8883. }
  8884. }
  8885. return Result::success($result);
  8886. }
  8887. /**
  8888. * 网民留言-检查是否可编辑
  8889. * @param array $data
  8890. * @return array
  8891. */
  8892. public function checkMessageEdit(array $data): array
  8893. {
  8894. $message = Message::where('id', $data['id'])->first();
  8895. if (empty($message)) {
  8896. return Result::error('留言不存在!');
  8897. }
  8898. $web = Website::where('id', $data['website_id'])->first();
  8899. if (empty($web)) {
  8900. return Result::error('网站不存在!');
  8901. }
  8902. $column_arr = json_decode($web['website_column_arr_id'] ?? [], true);
  8903. if(empty($column_arr)){
  8904. return Result::error('该网站未关联任何属性!');
  8905. }
  8906. if(!in_array($message['column_id'], $column_arr)){
  8907. return Result::error('不可编辑');
  8908. }
  8909. return Result::success('可编辑');
  8910. }
  8911. /**
  8912. * 调研选题-获取所有Researchers
  8913. * @param array $data
  8914. * @return array
  8915. */
  8916. public function getAllResearcher(array $data): array
  8917. {
  8918. $where['role_user.role_id'] = 21;
  8919. if(!empty($data['id'])){
  8920. $where['user.id'] = $data['id'];
  8921. }
  8922. if(!empty($data['real_name'])){
  8923. array_push($where, ['user_info.real_name', 'like', '%'.$data['real_name'].'%']);
  8924. }
  8925. $users = User::leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  8926. ->leftJoin('role_user', 'user.id', '=', 'role_user.user_id')
  8927. ->where($where)
  8928. ->select('user.id', 'user_info.real_name','user_info.number')
  8929. ->get()->toArray();
  8930. if (empty($users)) {
  8931. return Result::error('此调研员不存在!');
  8932. }
  8933. $user_number = array_search($data['user_id'], array_column($users, 'id'));
  8934. if($user_number == false){
  8935. $result['number'] = null;
  8936. }else{
  8937. $result['number'] = $users[$user_number]['number'];
  8938. }
  8939. $result['users'] = $users;
  8940. $result['user_id'] = $data['user_id'];
  8941. return Result::success($result);
  8942. }
  8943. /**
  8944. * 调研选题-添加
  8945. * @param array $data
  8946. * @return array
  8947. */
  8948. public function addResearchTopic(array $data): array
  8949. {
  8950. $user = User::where('id', $data['user_id'])->first();
  8951. if (empty($user)) {
  8952. return Result::error('用户不存在');
  8953. }
  8954. if($user['type_id'] == 10000){
  8955. $data['status'] = 1;
  8956. }else{
  8957. $data['status'] = 0;
  8958. }
  8959. if ($data['keyword'] == '') {
  8960. //提取标题+内容中的关键词
  8961. $data['keyword'] = $data['title'];
  8962. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  8963. Jieba::init(); // 初始化 jieba-php
  8964. Finalseg::init();
  8965. $segList = Jieba::cut($data['keyword']);
  8966. $segList1 = array_slice($segList, 0, 8);
  8967. $data['keyword'] = implode(',', $segList1);
  8968. }
  8969. if ($data['description'] == '') {
  8970. //提取内容中的描述
  8971. $content = $data['content'];
  8972. // 去除 <style> 和 <script> 标签及其内容
  8973. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  8974. // 去除所有 HTML 标签
  8975. $content = strip_tags($content);
  8976. // 去除 HTML 实体
  8977. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  8978. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  8979. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  8980. // 去除多余空白
  8981. $content = preg_replace('/\s+/u', '', $content);
  8982. // 截取 100 个字符
  8983. $data['description'] = mb_substr($content, 0, 100);
  8984. }
  8985. $data['level'] = empty($data['level']) ? null : $data['level'];
  8986. $data['province_id'] = empty($data['province_id']) ? null : $data['province_id'];
  8987. $data['city_id'] = empty($data['city_id']) ? null : $data['city_id'];
  8988. $data['county_id'] = empty($data['county_id']) ? null : $data['county_id'];
  8989. $data['due_time'] = empty($data['due_time']) ? null : $data['due_time'];
  8990. $users_id = empty($data['users_id']) ? null : $data['users_id'];
  8991. unset($data['users_id']);
  8992. // return Result::success($data);
  8993. Db::beginTransaction();
  8994. try{
  8995. $result = ResearchTopic::insertGetId($data);
  8996. if (empty($result)) {
  8997. Db::rollBack();
  8998. return Result::error('添加失败');
  8999. }
  9000. if(!empty($users_id) && is_string($users_id)){
  9001. $users = json_decode($users_id ?? '[]',true);
  9002. }
  9003. $users_type4 = User::where('type_id', 4)->pluck('id');
  9004. $type4_num = array_intersect($users, $users_type4->toArray());
  9005. if(count($users) != count($type4_num)){
  9006. Db::rollBack();
  9007. return Result::error('请选择调研员!');
  9008. }
  9009. // return Result::success($users);
  9010. if(!empty($users) && is_array($users)){
  9011. // 去重:确保同一 retopic_id + user_id 组合唯一
  9012. $users = array_values(array_unique($users));
  9013. // 组装关联数据
  9014. $users_topic = [];
  9015. foreach ($users as $key => $value) {
  9016. $users_topic[$key] = [
  9017. 'user_id' => $value,
  9018. 'retopic_id' => $result,
  9019. ];
  9020. }
  9021. // 使用 insertOrIgnore 忽略重复主键/唯一索引冲突
  9022. $retopic_user = RetopicUser::insert($users_topic);
  9023. if(empty($retopic_user)){
  9024. Db::rollBack();
  9025. return Result::error('添加失败');
  9026. }
  9027. }
  9028. Db::commit();
  9029. return Result::success($result);
  9030. }catch(\Exception $e){
  9031. Db::rollBack();
  9032. return Result::error($e->getMessage());
  9033. }
  9034. }
  9035. /**
  9036. * 调研选题-编辑
  9037. * @param array $data
  9038. * @return array
  9039. */
  9040. public function upResearchTopic(array $data): array
  9041. {
  9042. $user = User::where('id', $data['user_id'])->first();
  9043. if (empty($user)) {
  9044. return Result::error('用户不存在');
  9045. }
  9046. if($user['type_id'] == 10000){
  9047. $data['status'] = 1;
  9048. }else{
  9049. $data['status'] = 0;
  9050. }
  9051. $topic = ResearchTopic::where('id', $data['id'])->first();
  9052. if (empty($topic)) {
  9053. return Result::error('此调研选题不存在');
  9054. }
  9055. if ($data['keyword'] == '') {
  9056. //提取标题+内容中的关键词
  9057. $data['keyword'] = $data['title'];
  9058. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  9059. Jieba::init(); // 初始化 jieba-php
  9060. Finalseg::init();
  9061. $segList = Jieba::cut($data['keyword']);
  9062. $segList1 = array_slice($segList, 0, 8);
  9063. $data['keyword'] = implode(',', $segList1);
  9064. }
  9065. if ($data['description'] == '') {
  9066. //提取内容中的描述
  9067. $content = $data['content'];
  9068. // 去除 <style> 和 <script> 标签及其内容
  9069. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9070. // 去除所有 HTML 标签
  9071. $content = strip_tags($content);
  9072. // 去除 HTML 实体
  9073. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9074. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9075. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9076. // 去除多余空白
  9077. $content = preg_replace('/\s+/u', '', $content);
  9078. // 截取 100 个字符
  9079. $data['description'] = mb_substr($content, 0, 100);
  9080. }
  9081. $data['level'] = empty($data['level']) ? null : $data['level'];
  9082. $data['province_id'] = empty($data['province_id']) ? null : $data['province_id'];
  9083. $data['city_id'] = empty($data['city_id']) ? null : $data['city_id'];
  9084. $data['county_id'] = empty($data['county_id']) ? null : $data['county_id'];
  9085. $data['due_time'] = empty($data['due_time']) ? null : $data['due_time'];
  9086. $users_id = empty($data['users_id']) ? null : $data['users_id'];
  9087. $id = $data['id'];
  9088. unset($data['users_id']);
  9089. unset($data['id']);
  9090. // return Result::success($data);
  9091. Db::beginTransaction();
  9092. try{
  9093. $result = ResearchTopic::where('id', $id)->update($data);
  9094. if (empty($result)) {
  9095. Db::rollBack();
  9096. return Result::error('编辑调研选题失败!');
  9097. }
  9098. if(!empty($users_id) && is_string($users_id)){
  9099. $users = json_decode($users_id ?? '[]',true);
  9100. }
  9101. // return Result::success($users);
  9102. $retopic_users = RetopicUser::where('retopic_id', $id)->pluck('user_id')->toArray();
  9103. if(!empty($retopic_users)){
  9104. $del_users = RetopicUser::where('retopic_id', $id)->delete();
  9105. if(empty($del_users)){
  9106. Db::rollBack();
  9107. return Result::error('编辑同行人员失败!');
  9108. }
  9109. }
  9110. if(!empty($users) && is_array($users)){
  9111. // 去重:确保同一 retopic_id + user_id 组合唯一
  9112. $users = array_values(array_unique($users));
  9113. // 组装关联数据
  9114. $users_topic = [];
  9115. foreach ($users as $key => $value) {
  9116. $users_topic[$key] = [
  9117. 'user_id' => $value,
  9118. 'retopic_id' => $id,
  9119. ];
  9120. }
  9121. // 使用 insertOrIgnore 忽略重复主键/唯一索引冲突
  9122. $retopic_user = RetopicUser::insert($users_topic);
  9123. if(empty($retopic_user)){
  9124. Db::rollBack();
  9125. return Result::error('编辑失败');
  9126. }
  9127. }
  9128. Db::commit();
  9129. return Result::success($result);
  9130. }catch(\Exception $e){
  9131. Db::rollBack();
  9132. return Result::error($e->getMessage());
  9133. }
  9134. }
  9135. /**
  9136. * 调研选题-删除
  9137. * @param array $data
  9138. * @return array
  9139. */
  9140. public function delResearchTopic(array $data): array
  9141. {
  9142. $user = User::where('id', $data['user_id'])->first();
  9143. if (empty($user)) {
  9144. return Result::error('用户不存在');
  9145. }
  9146. $topic = ResearchTopic::where('id', $data['id'])->first();
  9147. if (empty($topic)) {
  9148. return Result::error('此调研选题不存在');
  9149. }
  9150. Db::beginTransaction();
  9151. try{
  9152. $result = ResearchTopic::where('id', $data['id'])->delete();
  9153. if (empty($result)) {
  9154. Db::rollBack();
  9155. return Result::error('删除调研选题失败!');
  9156. }
  9157. $topic_users = RetopicUser::where('retopic_id', $data['id'])->pluck('user_id')->toArray();
  9158. if(!empty($topic_users)){
  9159. $del_topic_users = RetopicUser::where('retopic_id', $data['id'])->delete();
  9160. if(empty($del_topic_users)){
  9161. Db::rollBack();
  9162. return Result::error('删除同行人员失败!');
  9163. }
  9164. }
  9165. Db::commit();
  9166. return Result::success($result);
  9167. }catch(\Exception $e){
  9168. Db::rollBack();
  9169. return Result::error($e->getMessage());
  9170. }
  9171. }
  9172. /**
  9173. * 调研选题-列表
  9174. * @param array $data
  9175. * @return array
  9176. */
  9177. public function getResearchTopicList(array $data): array
  9178. {
  9179. $user = User::where('id', $data['user_id'])->first();
  9180. if (empty($user)) {
  9181. return Result::error('用户不存在!');
  9182. }
  9183. $where = [];
  9184. if($user->type_id != 10000){
  9185. $where['research_topic.user_id'] = $data['user_id'];
  9186. $website = Website::where('id', $data['website_id'])->first();
  9187. if (empty($website)) {
  9188. return Result::error('网站不存在!');
  9189. }
  9190. $web_column = json_decode($website->website_column_arr_id ?? '[]',true);
  9191. if(empty($web_column)){
  9192. return Result::error('网站未配置栏目!');
  9193. }
  9194. }
  9195. if($data['is_master'] != 0){
  9196. if($data['is_master'] == 3){
  9197. $where['research_topic.status'] = 0;
  9198. }else{
  9199. $where['research_topic.status'] = $data['is_master'];
  9200. }
  9201. }
  9202. if(!empty($data['title'])){
  9203. array_push($where, ['research_topic.title', 'like', '%'.$data['title'].'%']);
  9204. }
  9205. $page = $data['page'] ?? 1;
  9206. $page_size = $data['page_size'] ?? 10;
  9207. $research_topic = ResearchTopic::when($data['is_master'] == 0, function($query) use($data){
  9208. $query->whereIn('research_topic.status', [0,2]);
  9209. })
  9210. ->when(!empty($where), function($query) use($where){
  9211. $query->where($where);
  9212. })
  9213. ->with(['retopicUsers' => function ($query) {
  9214. $query->select('id', 'user_id', 'retopic_id');
  9215. }
  9216. ])
  9217. ->leftJoin('user', 'user.id', '=', 'research_topic.user_id')
  9218. ->leftJoin('user_info', 'user_info.user_id', '=', 'research_topic.user_id')
  9219. ->select('research_topic.id','research_topic.title','research_topic.updated_at','research_topic.status',
  9220. 'research_topic.due_time','user_info.real_name','research_topic.column_id','research_topic.user_id',
  9221. 'user.user_name'
  9222. )
  9223. ->orderBy('research_topic.updated_at', 'desc')
  9224. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  9225. if(empty($research_topic->items())){
  9226. return Result::error('暂无调研选题!');
  9227. }
  9228. $result = [
  9229. 'rows' => $research_topic->items(),
  9230. 'count' => $research_topic->total()
  9231. ];
  9232. foreach($result['rows'] as $key => $value){
  9233. if($user->type_id != 10000){
  9234. if(in_array($value['column_id'], $web_column)){
  9235. $result['rows'][$key]['is_update'] = 1;
  9236. }else{
  9237. $result['rows'][$key]['is_update'] = 0;
  9238. }
  9239. }else{
  9240. if($value['user_id'] == $data['user_id']){
  9241. $result['rows'][$key]['is_update'] = 1;
  9242. }else{
  9243. $result['rows'][$key]['is_update'] = 0;
  9244. }
  9245. }
  9246. if(!isset($value['real_name']) || empty($value['real_name'])){
  9247. $result['rows'][$key]['real_name'] = $value['user_name'];
  9248. }
  9249. if(!empty($value['retopicUsers'])){
  9250. $retopic_users = $value['retopicUsers'];
  9251. $retopic_user = $retopic_users->pluck('user_id')->toArray();
  9252. $result['rows'][$key]['txry_users'] = implode(',', $retopic_user);
  9253. unset($result['rows'][$key]['retopicUsers']);
  9254. }
  9255. }
  9256. return Result::success($result);
  9257. }
  9258. /**
  9259. * 调研选题-修改状态
  9260. * @param array $data
  9261. * @return array
  9262. */
  9263. public function checkResearchTopic(array $data): array
  9264. {
  9265. $user = User::where('id', $data['user_id'])->first();
  9266. if (empty($user)) {
  9267. return Result::error('用户不存在!');
  9268. }
  9269. if($user->type_id != 10000 && ($data['status'] == 1 || $data['status'] == 2)){
  9270. return Result::error('此用户暂无权限!');
  9271. }
  9272. $topic = ResearchTopic::where('id', $data['id'])->first();
  9273. if (empty($topic)) {
  9274. return Result::error('此调研选题不存在');
  9275. }
  9276. $id = $data['id'];
  9277. unset($data['id']);
  9278. unset($data['user_id']);
  9279. $result = ResearchTopic::where('id', $id)->update($data);
  9280. if (empty($result)) {
  9281. return Result::error('修改调研选题状态失败!');
  9282. }
  9283. return Result::success($result);
  9284. }
  9285. /**
  9286. * 调研选题-详情
  9287. * @param array $data
  9288. * @return array
  9289. */
  9290. public function getResearchTopicInfo(array $data): array
  9291. {
  9292. $user = User::where('id', $data['user_id'])->first();
  9293. if (empty($user)) {
  9294. return Result::error('用户不存在!');
  9295. }
  9296. $research_topic = ResearchTopic::where('research_topic.id', $data['id'])
  9297. ->with(['retopicUsers' => function ($query) {
  9298. $query->select('user_id','retopic_id');
  9299. }
  9300. ])
  9301. ->leftJoin('user', 'user.id', '=', 'research_topic.user_id')
  9302. ->leftJoin('user_info', 'user_info.user_id', '=', 'research_topic.user_id')
  9303. ->select('research_topic.*','user_info.number')
  9304. ->first();
  9305. if(empty($research_topic)){
  9306. return Result::error('获取调研选题详情失败!');
  9307. }
  9308. $retopic_user = $research_topic['retopicUsers'];
  9309. if(!empty($retopic_user)){
  9310. $retopic_user = $retopic_user->pluck('user_id')->toArray();
  9311. foreach($retopic_user as $key => $value){
  9312. $real_name = UserInfo::where('user_id', $value)->value('real_name');
  9313. $research_topic['retopicUsers'][$key]['real_name'] = $real_name;
  9314. $research_topic['retopicUsers'][$key]['user_id'] = $value;
  9315. unset($research_topic['retopicUsers'][$key]['retopic_id']);
  9316. }
  9317. }
  9318. return Result::success($research_topic);
  9319. }
  9320. /**
  9321. * 添加网站导航
  9322. * @param array $data
  9323. */
  9324. public function addWebCateinfo(array $data): array
  9325. {
  9326. $user = User::where('id', $data['user_id'])->first();
  9327. if (empty($user)) {
  9328. return Result::error('用户不存在');
  9329. }
  9330. if($user['type_id'] == 10000){
  9331. $data['status'] = 1;
  9332. }else{
  9333. $data['status'] = 0;
  9334. }
  9335. if ($data['keyword'] == '') {
  9336. //提取标题+内容中的关键词
  9337. $data['keyword'] = $data['title'];
  9338. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  9339. Jieba::init(); // 初始化 jieba-php
  9340. Finalseg::init();
  9341. $segList = Jieba::cut($data['keyword']);
  9342. $segList1 = array_slice($segList, 0, 8);
  9343. $data['keyword'] = implode(',', $segList1);
  9344. }
  9345. if ($data['description'] == '') {
  9346. //提取内容中的描述
  9347. $content = $data['content'];
  9348. // 去除 <style> 和 <script> 标签及其内容
  9349. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9350. // 去除所有 HTML 标签
  9351. $content = strip_tags($content);
  9352. // 去除 HTML 实体
  9353. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9354. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9355. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9356. // 去除多余空白
  9357. $content = preg_replace('/\s+/u', '', $content);
  9358. // 截取 100 个字符
  9359. $data['description'] = mb_substr($content, 0, 100);
  9360. }
  9361. $data['cate_name'] = empty($data['cate_name']) ? '官网导航' : $data['cate_name'];
  9362. $data['province_id'] = empty($data['province_id']) ? null : $data['province_id'];
  9363. $data['city_id'] = empty($data['city_id']) ? null : $data['city_id'];
  9364. $data['county_id'] = empty($data['county_id']) ? null : $data['county_id'];
  9365. unset($data['users_id']);
  9366. $result = WebCateinfo::insertGetId($data);
  9367. if (empty($result)) {
  9368. return Result::error('添加失败');
  9369. }
  9370. return Result::success($result);
  9371. }
  9372. /**
  9373. * 更新网站导航
  9374. * @param array $data
  9375. */
  9376. public function upWebCateinfo(array $data): array
  9377. {
  9378. $webCateinfo = WebCateinfo::where('id', $data['id'])->first();
  9379. if (empty($webCateinfo)) {
  9380. return Result::error('导航不存在');
  9381. }
  9382. $user = User::where('id', $data['user_id'])->first();
  9383. if (empty($user)) {
  9384. return Result::error('用户不存在');
  9385. }
  9386. if($user['type_id'] == 10000){
  9387. $data['status'] = 1;
  9388. }else{
  9389. $data['status'] = 0;
  9390. }
  9391. if ($data['keyword'] == '') {
  9392. //提取标题+内容中的关键词
  9393. $data['keyword'] = $data['title'];
  9394. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  9395. Jieba::init(); // 初始化 jieba-php
  9396. Finalseg::init();
  9397. $segList = Jieba::cut($data['keyword']);
  9398. $segList1 = array_slice($segList, 0, 8);
  9399. $data['keyword'] = implode(',', $segList1);
  9400. }
  9401. if ($data['description'] == '') {
  9402. //提取内容中的描述
  9403. $content = $data['content'];
  9404. // 去除 <style> 和 <script> 标签及其内容
  9405. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9406. // 去除所有 HTML 标签
  9407. $content = strip_tags($content);
  9408. // 去除 HTML 实体
  9409. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9410. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9411. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9412. // 去除多余空白
  9413. $content = preg_replace('/\s+/u', '', $content);
  9414. // 截取 100 个字符
  9415. $data['description'] = mb_substr($content, 0, 100);
  9416. }
  9417. $data['cate_name'] = empty($data['cate_name']) ? '官网导航' : $data['cate_name'];
  9418. $data['province_id'] = empty($data['province_id']) ? null : $data['province_id'];
  9419. $data['city_id'] = empty($data['city_id']) ? null : $data['city_id'];
  9420. $data['county_id'] = empty($data['county_id']) ? null : $data['county_id'];
  9421. unset($data['users_id']);
  9422. $result = WebCateinfo::where('id', $data['id'])->update($data);
  9423. if (empty($result)) {
  9424. return Result::error('更新失败');
  9425. }
  9426. return Result::success($result);
  9427. }
  9428. /**
  9429. * 获取网站导航列表
  9430. * @param array $data
  9431. * @return array
  9432. */
  9433. public function getWebCateinfoList(array $data): array
  9434. {
  9435. $user = User::where('id', $data['user_id'])->first();
  9436. if (empty($user)) {
  9437. return Result::error('用户不存在');
  9438. }
  9439. $where = [];
  9440. if($user['type_id'] != 10000){
  9441. $where['web_cateinfo.user_id'] = $data['user_id'];
  9442. }
  9443. if(!empty($data['title'])){
  9444. array_push($where, ['web_cateinfo.title', 'like', '%'.$data['title'].'%']);
  9445. }
  9446. if($data['is_master'] != 0){
  9447. if($data['is_master'] == 3){
  9448. $where['web_cateinfo.status'] = 0;
  9449. }else{
  9450. $where['web_cateinfo.status'] = $data['is_master'];
  9451. }
  9452. }
  9453. $web_cateinfo = WebCateinfo::when(!empty($data['is_master'] == 0), function ($query) use ($where) {
  9454. $query->whereIn('web_cateinfo.status', [0, 2]);
  9455. })
  9456. ->when(!empty($where), function ($query) use ($where) {
  9457. $query->where($where);
  9458. })
  9459. ->leftJoin('user', 'web_cateinfo.user_id', '=', 'user.id')
  9460. ->select(['web_cateinfo.id', 'web_cateinfo.user_id', 'user.nickname', 'web_cateinfo.title', 'web_cateinfo.cate_name', 'web_cateinfo.status','web_cateinfo.updated_at'])
  9461. ->orderBy('updated_at', 'desc')
  9462. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  9463. if(empty($web_cateinfo->items())){
  9464. return Result::error('官网导航不存在');
  9465. }
  9466. $result = [
  9467. 'rows' => $web_cateinfo->items(),
  9468. 'total' => $web_cateinfo->total(),
  9469. ];
  9470. foreach($result['rows'] as $key => $value){
  9471. if($value['user_id'] == $data['user_id']){
  9472. $result['rows'][$key]['is_update'] = 1;
  9473. }else{
  9474. $result['rows'][$key]['is_update'] = 0;
  9475. }
  9476. }
  9477. return Result::success($result);
  9478. }
  9479. /**
  9480. * 删除网站导航
  9481. * @param array $data
  9482. */
  9483. public function delWebCateinfo(array $data): array
  9484. {
  9485. $webCateinfo = WebCateinfo::where('id', $data['id'])->first();
  9486. if (empty($webCateinfo)) {
  9487. return Result::error('导航不存在');
  9488. }
  9489. $result = WebCateinfo::where('id', $data['id'])->delete();
  9490. if (empty($result)) {
  9491. return Result::error('删除失败');
  9492. }
  9493. return Result::success($result);
  9494. }
  9495. /**
  9496. * 审核网站导航
  9497. * @param array $data
  9498. */
  9499. public function checkWebCateinfo(array $data): array
  9500. {
  9501. $webCateinfo = WebCateinfo::where('id', $data['id'])->first();
  9502. if (empty($webCateinfo)) {
  9503. return Result::error('导航不存在');
  9504. }
  9505. $user = User::where('id', $data['user_id'])->first();
  9506. if (empty($user)) {
  9507. return Result::error('用户不存在');
  9508. }
  9509. if($user['type_id'] != 10000 && $data['status'] == 1){
  9510. return Result::error('非管理员不能审核');
  9511. }
  9512. $update_data['status'] = $data['status'];
  9513. if($data['status'] == 2){
  9514. $update_data['reason'] = $data['reason'];
  9515. }
  9516. $result = WebCateinfo::where('id', $data['id'])->update($update_data);
  9517. if (empty($result)) {
  9518. return Result::error('审核失败');
  9519. }
  9520. return Result::success($result);
  9521. }
  9522. /**
  9523. * 获取网站导航详情
  9524. * @param array $data
  9525. */
  9526. public function getWebCateinfoDetail(array $data): array
  9527. {
  9528. $webCateinfo = WebCateinfo::where('id', $data['id'])->first();
  9529. if (empty($webCateinfo)) {
  9530. return Result::error('导航不存在');
  9531. }
  9532. $result = $webCateinfo->toArray();
  9533. return Result::success($result);
  9534. }
  9535. /**
  9536. * 推荐单页管理
  9537. * @param array $data
  9538. */
  9539. public function getAdviceSinglePages(array $data): array
  9540. {
  9541. $user = User::where('id', $data['user_id'])->first();
  9542. if (empty($user)) {
  9543. return Result::error('用户不存在');
  9544. }
  9545. $category = WebsiteCategory::where(['website_id' => $data['website_id']])->pluck('category_id');
  9546. if(empty($category)){
  9547. return Result::error('推荐单页不存在');
  9548. }
  9549. $where = [];
  9550. if(!empty($data['title'])){
  9551. array_push($where, ['title', 'like', '%'.$data['title'].'%']);
  9552. }
  9553. $result = SinglePage::whereIn('id', $category)
  9554. ->when(!empty($where), function ($query) use ($where) {
  9555. $query->where($where);
  9556. })
  9557. ->when(!empty($data['catid']), function ($query) use ($data) {
  9558. $query->where('catid', $data['catid']);
  9559. })
  9560. ->where('status', 1)
  9561. ->select(['id', 'title', 'catid','status','website_id','updated_at'])
  9562. ->orderBy('updated_at', 'desc')
  9563. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  9564. if(empty($result->items())){
  9565. return Result::error('推荐单页不存在');
  9566. }
  9567. $result = [
  9568. 'rows' => $result->items(),
  9569. 'total' => $result->total(),
  9570. ];
  9571. return Result::success($result);
  9572. }
  9573. /**
  9574. * 添加单页
  9575. * @param array $data
  9576. */
  9577. public function addSinglePage(array $data): array
  9578. {
  9579. $user = User::where('id', $data['user_id'])->first();
  9580. if (empty($user)) {
  9581. return Result::error('用户不存在');
  9582. }
  9583. if($user['type_id'] == 10000){
  9584. $data['status'] = 1;
  9585. }else{
  9586. $data['status'] = 0;
  9587. }
  9588. if(is_array($data['cat_arr_id'])){
  9589. $data['cat_arr_id'] = array_map(function($item){
  9590. return intval($item);
  9591. }, $data['cat_arr_id']);
  9592. $data['catid'] = end($data['cat_arr_id']);
  9593. $data['cat_arr_id'] = json_encode($data['cat_arr_id'], JSON_UNESCAPED_UNICODE);
  9594. }else{
  9595. return Result::error('请选择栏目;');
  9596. }
  9597. if(!empty($data['commend_id']) && is_array($data['commend_id'])){
  9598. $data['commend_id'] = json_encode($data['commend_id'], JSON_UNESCAPED_UNICODE);
  9599. }else{
  9600. $data['commend_id'] = null;
  9601. }
  9602. if ($data['keyword'] == '') {
  9603. //提取标题+内容中的关键词
  9604. $articleData['keyword'] = $data['title'];
  9605. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  9606. Jieba::init(); // 初始化 jieba-php
  9607. Finalseg::init();
  9608. $segList = Jieba::cut($articleData['keyword']);
  9609. $segList1 = array_slice($segList, 0, 8);
  9610. $data['keyword'] = implode(',', $segList1);
  9611. }
  9612. if ($data['description'] == '') {
  9613. //提取内容中的描述
  9614. $content = $data['content'];
  9615. // 去除 <style> 和 <script> 标签及其内容
  9616. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9617. // 去除所有 HTML 标签
  9618. $content = strip_tags($content);
  9619. // 去除 HTML 实体
  9620. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9621. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9622. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9623. // 去除多余空白
  9624. $content = preg_replace('/\s+/u', '', $content);
  9625. // 截取 100 个字符
  9626. $data['description'] = mb_substr($content, 0, 100);
  9627. }
  9628. if(empty($data['publiced_at'])){
  9629. $data['publiced_at'] = null;
  9630. }
  9631. $result = SinglePage::insertGetId($data);
  9632. if (empty($result)) {
  9633. return Result::error('添加失败');
  9634. }
  9635. return Result::success($result);
  9636. }
  9637. /**
  9638. * 更新单页
  9639. * @param array $data
  9640. */
  9641. public function upSinglePage(array $data): array
  9642. {
  9643. $singlePage = SinglePage::where('id', $data['id'])->where('user_id', $data['user_id'])->first();
  9644. if (empty($singlePage)) {
  9645. return Result::error('单页不存在');
  9646. }
  9647. $user = User::where('id', $data['user_id'])->first();
  9648. if (empty($user)) {
  9649. return Result::error('用户不存在');
  9650. }
  9651. $where['id'] = $data['id'];
  9652. unset($data['id']);
  9653. if($user['type_id'] == 10000){
  9654. $data['status'] = 1;
  9655. }else{
  9656. $data['status'] = 0;
  9657. }
  9658. if(is_array($data['cat_arr_id'])){
  9659. $data['cat_arr_id'] = array_map(function($item){
  9660. return intval($item);
  9661. }, $data['cat_arr_id']);
  9662. $data['catid'] = end($data['cat_arr_id']);
  9663. $data['cat_arr_id'] = json_encode($data['cat_arr_id'], JSON_UNESCAPED_UNICODE);
  9664. }else{
  9665. return Result::error('请选择栏目;');
  9666. }
  9667. if(!empty($data['commend_id']) && is_array($data['commend_id'])){
  9668. $data['commend_id'] = json_encode($data['commend_id'], JSON_UNESCAPED_UNICODE);
  9669. }else{
  9670. $data['commend_id'] = null;
  9671. }
  9672. if ($data['keyword'] == '') {
  9673. //提取标题+内容中的关键词
  9674. $articleData['keyword'] = $data['title'];
  9675. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  9676. Jieba::init(); // 初始化 jieba-php
  9677. Finalseg::init();
  9678. $segList = Jieba::cut($articleData['keyword']);
  9679. $segList1 = array_slice($segList, 0, 8);
  9680. $data['keyword'] = implode(',', $segList1);
  9681. }
  9682. if ($data['description'] == '') {
  9683. //提取内容中的描述
  9684. $content = $data['content'];
  9685. // 去除 <style> 和 <script> 标签及其内容
  9686. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9687. // 去除所有 HTML 标签
  9688. $content = strip_tags($content);
  9689. // 去除 HTML 实体
  9690. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9691. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9692. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9693. // 去除多余空白
  9694. $content = preg_replace('/\s+/u', '', $content);
  9695. // 截取 100 个字符
  9696. $data['description'] = mb_substr($content, 0, 100);
  9697. }
  9698. if(empty($data['publiced_at'])){
  9699. $data['publiced_at'] = null;
  9700. }
  9701. $result = SinglePage::where($where)->update($data);
  9702. if (empty($result)) {
  9703. return Result::error('更新失败');
  9704. }
  9705. return Result::success($result);
  9706. }
  9707. /**
  9708. * 删除单页
  9709. * @param array $data
  9710. */
  9711. public function delSinglePage(array $data): array
  9712. {
  9713. $singlePage = SinglePage::where('id', $data['id'])->first();
  9714. if (empty($singlePage)) {
  9715. return Result::error('单页不存在');
  9716. }
  9717. $user = User::where('id', $data['user_id'])->first();
  9718. if (empty($user)) {
  9719. return Result::error('用户不存在');
  9720. }
  9721. $where['id'] = $data['id'];
  9722. $result = SinglePage::where($where)->delete();
  9723. if (empty($result)) {
  9724. return Result::error('删除失败');
  9725. }
  9726. return Result::success($result);
  9727. }
  9728. /**
  9729. * 审核单页
  9730. * @param array $data
  9731. */
  9732. public function checkSinglePage(array $data): array
  9733. {
  9734. $user = User::where('id', $data['user_id'])->first();
  9735. if (empty($user)) {
  9736. return Result::error('用户不存在');
  9737. }
  9738. if($user['type_id'] != 10000 && in_array($data['status'], [1, 2])){
  9739. return Result::error('非管理员不能审核单页');
  9740. }
  9741. if($data['status'] == 2){
  9742. $update_data['reason'] = $data['reason'] ?? '';
  9743. }
  9744. $update_data['status'] = $data['status'];
  9745. $result = SinglePage::where('id', $data['id'])->update($update_data);
  9746. if (empty($result)) {
  9747. return Result::error('更新失败');
  9748. }
  9749. return Result::success($result);
  9750. }
  9751. /**
  9752. * 更新单页状态
  9753. * @param array $data
  9754. */
  9755. public function getSinglePageList(array $data): array
  9756. {
  9757. $user = User::where('id', $data['user_id'])->first();
  9758. if (empty($user)) {
  9759. return Result::error('用户不存在');
  9760. }
  9761. $where = [];
  9762. if($user['type_id'] != 10000){
  9763. $where['single_page.user_id'] = $data['user_id'];
  9764. }
  9765. if($data['is_master'] == 3){
  9766. $where['single_page.status'] = 0;
  9767. }else if($data['is_master'] != 0){
  9768. $where['single_page.status'] = $data['is_master'];
  9769. }
  9770. if(!empty($data['title'])){
  9771. array_push($where, ['single_page.title', 'like', '%'.$data['title'].'%']);
  9772. }
  9773. $result = SinglePage::when($data['is_master'] == 0, function($query) use($data){
  9774. $query->whereIn('single_page.status', [0, 2]);
  9775. })
  9776. ->when(!empty($where), function($query) use($where){
  9777. $query->where($where);
  9778. })
  9779. ->with([
  9780. 'websiteCategory' => function ($query) {
  9781. $query->select('website_id', 'category_id', 'alias');
  9782. },
  9783. 'user' => function ($query) {
  9784. $query->select('id', 'nickname');
  9785. }
  9786. ])
  9787. ->select(['single_page.id','single_page.title','single_page.content','single_page.updated_at',
  9788. 'single_page.status','single_page.catid','single_page.website_id','single_page.user_id'])
  9789. ->orderBy('single_page.updated_at', 'desc')
  9790. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  9791. if (empty($result->items())) {
  9792. return Result::error('暂无数据');
  9793. }
  9794. $result = [
  9795. 'rows' => $result->items(),
  9796. 'total' => $result->total(),
  9797. ];
  9798. foreach($result['rows'] as $key => $value){
  9799. $result['rows'][$key]['category_alias'] = $value['websiteCategory']['alias'] ?? '';
  9800. $result['rows'][$key]['user_nickname'] = $value['user']['nickname'] ?? '';
  9801. $result['rows'][$key]['websiteCategory'] = $value['websiteCategory']['alias'] ?? '';
  9802. unset($result['rows'][$key]['user']);
  9803. unset($result['rows'][$key]['websiteCategory']);
  9804. if($user['type_id'] == 10000){
  9805. if($value['user_id'] == $data['user_id']){
  9806. $result['rows'][$key]['is_update'] = 1;
  9807. }else{
  9808. $result['rows'][$key]['is_update'] = 0;
  9809. }
  9810. }else{
  9811. if($value['website_id'] == $data['website_id']){
  9812. $result['rows'][$key]['is_update'] = 1;
  9813. }else{
  9814. $result['rows'][$key]['is_update'] = 0;
  9815. }
  9816. }
  9817. }
  9818. return Result::success($result);
  9819. }
  9820. /**
  9821. * 获取单页详情
  9822. * @param array $data
  9823. */
  9824. public function getSinglePageInfo(array $data): array
  9825. {
  9826. $singlePage = SinglePage::where('id', $data['id'])->where('user_id', $data['user_id'])->first();
  9827. if (empty($singlePage)) {
  9828. return Result::error('单页不存在');
  9829. }
  9830. $user = User::where('id', $data['user_id'])->first();
  9831. if (empty($user)) {
  9832. return Result::error('用户不存在');
  9833. }
  9834. $where['id'] = $data['id'];
  9835. $result = SinglePage::where($where)->first();
  9836. if (empty($result)) {
  9837. return Result::error('获取失败');
  9838. }
  9839. $result['cat_arr_id'] = json_decode($result['cat_arr_id'] ?? '[]' , true);
  9840. $result['commend_id'] = json_decode($result['commend_id'] ?? '[]' , true);
  9841. return Result::success($result);
  9842. }
  9843. }