NewsService.php 370 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137
  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. use App\Model\WebsiteColumn;
  75. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  76. class NewsService implements NewsServiceInterface
  77. {
  78. #[Inject]
  79. protected Redis $redis;
  80. /**
  81. * 获取导航池列表
  82. * @param array $data
  83. * @return array
  84. */
  85. public function getCategoryList(array $data): array
  86. {
  87. $search = $data['name'] ?? '';
  88. $page = (int)($data['page'] ?? 1);
  89. $perPage = (int)($data['pageSize'] ?? 10);
  90. // 1. 查出所有匹配的分类id
  91. if ($search) {
  92. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  93. if (empty($matchedIds)) {
  94. return Result::success(['rows' => [], 'total' => 0]);
  95. }
  96. // 2. 递归查所有父级,直到一级分类
  97. $idsStr = implode(',', $matchedIds);
  98. $sql = "
  99. WITH RECURSIVE parents AS (
  100. SELECT * FROM category WHERE id IN ($idsStr)
  101. UNION ALL
  102. SELECT c.* FROM category c
  103. INNER JOIN parents p ON c.id = p.pid
  104. )
  105. SELECT * FROM parents
  106. ";
  107. $parents = Db::select($sql);
  108. $parentIds = [];
  109. foreach ($parents as $row) {
  110. if ($row->pid == 0) {
  111. $parentIds[] = $row->id;
  112. }
  113. }
  114. $parentIds = array_unique($parentIds);
  115. } else {
  116. // 没有搜索,一级分类就是根
  117. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  118. }
  119. // 3. 一级分类分页
  120. $total = count($parentIds);
  121. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  122. if (empty($parentIds)) {
  123. return Result::success(['rows' => [], 'total' => $total]);
  124. }
  125. // 4. 递归查所有子孙
  126. $idsStr = implode(',', $parentIds);
  127. $sql = "
  128. WITH RECURSIVE subcategories AS (
  129. SELECT * FROM category WHERE id IN ($idsStr)
  130. UNION ALL
  131. SELECT c.* FROM category c
  132. INNER JOIN subcategories s ON c.pid = s.id
  133. )
  134. SELECT * FROM subcategories ORDER BY updated_at DESC
  135. ";
  136. $allCategories = Db::select($sql);
  137. // 5. 组装树结构
  138. $categoryMap = [];
  139. foreach ($allCategories as $cat) {
  140. $cat = (array)$cat;
  141. $cat['children'] = [];
  142. $categoryMap[$cat['id']] = $cat;
  143. }
  144. foreach ($categoryMap as $id => &$cat) {
  145. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  146. $categoryMap[$cat['pid']]['children'][] = &$cat;
  147. }
  148. }
  149. unset($cat);
  150. $categoryTree = [];
  151. foreach ($parentIds as $id) {
  152. if (isset($categoryMap[$id])) {
  153. $categoryTree[] = $categoryMap[$id];
  154. }
  155. }
  156. return Result::success([
  157. 'rows' => $categoryTree,
  158. 'total' => $total,
  159. ]);
  160. }
  161. private function findMatchedCategories($search)
  162. {
  163. if ($search) {
  164. return Category::where('name', 'like', "%{$search}%")
  165. ->orderBy('updated_at', 'desc')
  166. ->get();
  167. }
  168. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  169. ->get();
  170. }
  171. private function findAllParents($categories)
  172. {
  173. $allCategories = [];
  174. foreach ($categories as $category) {
  175. $parentId = $category->pid;
  176. while ($parentId > 0) {
  177. $parent = Category::find($parentId);
  178. if ($parent) {
  179. $allCategories[$parent->id] = $parent;
  180. $parentId = $parent->pid;
  181. } else {
  182. break;
  183. }
  184. }
  185. $allCategories[$category->id] = $category;
  186. }
  187. return array_values($allCategories);
  188. }
  189. private function buildCategoryTree($category, $allRequiredCategories)
  190. {
  191. $categoryData = $category->toArray();
  192. $children = [];
  193. foreach ($allRequiredCategories as $c) {
  194. if ($c->pid === $category->id) {
  195. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  196. }
  197. }
  198. if (!empty($children)) {
  199. $categoryData['children'] = $children;
  200. }
  201. return $categoryData;
  202. }
  203. public function myCategoryList(array $data): array
  204. {
  205. $sszq = $data['sszq'] ?? '';
  206. unset($data['sszq']);
  207. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  208. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  209. $where[] = [
  210. 'pid',
  211. '=',
  212. $data['pid'],
  213. ];
  214. if (isset($data['name'])) {
  215. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  216. }
  217. var_dump($where);
  218. //根据分类id,从category表中取出分类信息
  219. $result = Category::where($where)
  220. ->whereIn('category.id', $catorytids)
  221. ->select('category.*', 'category.id as category_id')->get();
  222. if (empty($result)) {
  223. return Result::error("没有栏目数据");
  224. }
  225. return Result::success($result);
  226. }
  227. /**
  228. * @param array $data
  229. * @return array
  230. */
  231. public function categoryList(array $data): array
  232. {
  233. $where[] = [
  234. 'pid',
  235. '=',
  236. $data['pid']
  237. ];
  238. if (isset($data['name'])) {
  239. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  240. }
  241. var_dump($where);
  242. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  243. if (empty($result)) {
  244. return Result::error("没有栏目数据");
  245. }
  246. return Result::success($result);
  247. }
  248. /**
  249. * @param array $data
  250. * @return array
  251. */
  252. public function addCategory(array $data): array
  253. {
  254. if (isset($data['id'])) {
  255. unset($data['id']);
  256. }
  257. $id = Category::insertGetId($data);
  258. if (empty($id)) {
  259. return Result::error("添加失败");
  260. }
  261. return Result::success(['id' => $id]);
  262. }
  263. /**
  264. * @param array $data
  265. * @return array
  266. */
  267. public function delCategory(array $data): array
  268. {
  269. Db::beginTransaction();
  270. try {
  271. $categoryList = Category::where(['pid' => $data['id']])->get();
  272. if ($categoryList->toArray()) {
  273. Db::rollBack();
  274. return Result::error("分类下面有子分类不能删除");
  275. }
  276. $articleList = Article::where(['catid' => $data['id']])->get();
  277. if ($articleList->toArray()) {
  278. Db::rollBack();
  279. return Result::error("分类下面有资讯不能删除");
  280. }
  281. $result = Category::where($data)->delete();
  282. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  283. if (!$result) {
  284. Db::rollBack();
  285. return Result::error("删除失败");
  286. }
  287. Db::commit();
  288. return Result::success($result);
  289. } catch (\Exception $e) {
  290. Db::rollBack();
  291. return Result::error("删除失败" . $e->getMessage());
  292. }
  293. }
  294. /**
  295. * @param array $data
  296. * @return array
  297. */
  298. public function updateCategory(array $data): array
  299. {
  300. $where = [
  301. 'id' => $data['id'],
  302. ];
  303. $result = Category::where($where)->update($data);
  304. if ($result) {
  305. return Result::success($result);
  306. } else {
  307. return Result::error("更新失败");
  308. }
  309. }
  310. /**
  311. * 获取导航池信息
  312. * @param array $data
  313. * @return array
  314. */
  315. public function getCategoryInfo(array $data): array
  316. {
  317. $where = [
  318. 'id' => $data['id'],
  319. ];
  320. $result = Category::where($where)->first();
  321. if ($result) {
  322. return Result::success($result);
  323. } else {
  324. return Result::error("更新失败");
  325. }
  326. }
  327. public function getArticleCommend(array $data): array
  328. {
  329. $user = User::where('id',$data['user_id'])->first();
  330. if(empty($user)){
  331. return Result::error('用户不存在!');
  332. }
  333. $ids = [];
  334. if(empty($data['website_id']) && $user['type_id'] == 10000){
  335. $ids = [];
  336. }else{
  337. $where = [
  338. 'website_id' => $data['website_id'] ?? $data['web_id'],
  339. ];
  340. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  341. // var_dump($ids);
  342. if (empty($ids)) {
  343. return Result::error("没有推荐数据");
  344. }
  345. }
  346. $whereArticle = [];
  347. if (isset($data['id']) && !empty($data['id'])) {
  348. $whereArticle['id'] = $data['id'];
  349. }
  350. //title like
  351. if (isset($data['title']) && !empty($data['id'])) {
  352. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  353. }
  354. // 若存在过滤用的分类 id 数组,则加入 whereIn 条件,否则直接跳过
  355. $article = Article::when(!empty($ids) && is_array($ids), function ($query) use ($ids) {
  356. $query->whereIn('catid', $ids);
  357. })
  358. ->where('status', 1)
  359. ->when(!empty($whereArticle) , function ($query) use ($whereArticle){
  360. $query->where($whereArticle);
  361. })
  362. ->orderBy('updated_at', 'desc')
  363. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  364. if ($article) {
  365. $data = [
  366. 'rows' => $article->items(),
  367. 'count' => $article->total(),
  368. ];
  369. return Result::success($data);
  370. } else {
  371. return Result::error("获取失败失败");
  372. }
  373. }
  374. /**
  375. * @param array $data
  376. * @return array
  377. */
  378. public function getArticleList(array $data): array
  379. {
  380. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  381. $type_id = $data['type_id'];
  382. unset($data['type_id']);
  383. $user_id = $data['user_id'];
  384. unset($data['user_id']);
  385. $where = [];
  386. $status1 = [];
  387. if (isset($data['id']) && $data['id']) {
  388. array_push($where, ['article.id', '=', $data['id']]);
  389. }
  390. if (isset($data['title']) && $data['title']) {
  391. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  392. }
  393. if (isset($data['category_name']) && $data['category_name']) {
  394. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  395. }
  396. if (isset($data['catid']) && $data['catid']) {
  397. array_push($where, ['article.catid', '=', $data['catid']]);
  398. }
  399. if (isset($data['author']) && $data['author']) {
  400. array_push($where, ['article.author', '=', $data['author']]);
  401. }
  402. if (isset($data['islink']) && $data['islink'] !== "") {
  403. array_push($where, ['article.islink', '=', $data['islink']]);
  404. }
  405. if (isset($data['status']) && $data['status'] !== "") {
  406. array_push($where, ['article.status', '=', $data['status']]);
  407. }
  408. if (isset($data['status1'])) {
  409. $status1 = json_decode(($data['status1']));
  410. }
  411. //不是管理员展示个人数据;
  412. if ($type_id != 10000) {
  413. $where[] = ['article.admin_user_id', '=', $user_id];
  414. }
  415. $startTime = microtime(true);
  416. $rep = Article::query()
  417. // 预加载相关关联
  418. ->with([
  419. 'category' => function ($query) {
  420. $query->select('id', 'name');
  421. },
  422. 'websiteCategory' => function ($query) {
  423. $query->select('website_id', 'category_id', 'alias');
  424. },'user' => function ($query) {
  425. $query->select('id', 'nickname');
  426. }
  427. ])
  428. // 构建where条件
  429. ->when(isset($data['id']) && $data['id'], function ($query) use ($data) {
  430. $query->where('article.id', '=', $data['id']);
  431. })
  432. ->when(isset($data['title']) && $data['title'], function ($query) use ($data) {
  433. $query->where('article.title', 'like', '%' . $data['title'] . '%');
  434. })
  435. ->when(isset($data['category_name']) && $data['category_name'], function ($query) use ($data) {
  436. // 使用子查询替代左连接进行模糊搜索
  437. $query->whereHas('category', function ($subQuery) use ($data) {
  438. $subQuery->where('name', 'like', '%' . $data['category_name'] . '%');
  439. });
  440. })
  441. ->when(isset($data['catid']) && $data['catid'], function ($query) use ($data) {
  442. $query->where('article.catid', '=', $data['catid']);
  443. })
  444. ->when(isset($data['author']) && $data['author'], function ($query) use ($data) {
  445. $query->where('article.author', '=', $data['author']);
  446. })
  447. ->when(isset($data['islink']) && $data['islink'] !== "", function ($query) use ($data) {
  448. $query->where('article.islink', '=', $data['islink']);
  449. })
  450. ->when(isset($data['status']) && $data['status'] !== "", function ($query) use ($data) {
  451. $query->where('article.status', '=', $data['status']);
  452. })
  453. ->when(isset($data['status1']) && $data['status1'], function ($query) use ($data) {
  454. // 安全地处理JSON字符串
  455. $status1 = is_array($data['status1']) ? $data['status1'] : json_decode($data['status1'], true) ?? [];
  456. if (!empty($status1)) {
  457. $query->whereIn('article.status', $status1);
  458. }
  459. })
  460. ->select('article.*')
  461. // 非管理员限制
  462. ->when($type_id != 10000, function ($query) use ($user_id) {
  463. // 非管理员只能看自己的文章,同时把 article_ignore 的 c_show_time 一起查出来
  464. $query->where('article.admin_user_id', $user_id)
  465. ->leftJoin('article_ignore', function ($join) {
  466. // 关联条件:article.id = article_ignore.article_id 且 article.web_site_id = article_ignore.website_id
  467. $join->on('article_ignore.article_id', '=', 'article.id')
  468. ->whereColumn('article_ignore.website_id', 'article.web_site_id');
  469. })
  470. ->addSelect('article_ignore.article_id','article_ignore.c_show_time'); // 用 addSelect 追加字段,避免覆盖原有 select
  471. })
  472. // 基础条件
  473. ->whereNotIn('article.status', [404])
  474. // 排序和分页
  475. ->orderBy('article.updated_at', 'desc')
  476. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  477. // 获取结果并格式化
  478. $data = [
  479. 'rows' => $rep->items(),
  480. 'count' => $rep->total(),
  481. ];
  482. // 执行查询
  483. $endTime = microtime(true);
  484. $executionTime = ($endTime - $startTime) * 1000;
  485. echo "查询执行时间: {$executionTime}ms\n";
  486. return Result::success($data);
  487. }
  488. /**
  489. * @param array $data
  490. * @return array
  491. */
  492. public function addArticle(array $data): array
  493. {
  494. var_dump($data, '----------12-----------1');
  495. // ------c_show_time********add***1****
  496. $is_collect = $data['is_collect'] ?? 0;
  497. $user_type = $data['user_type'];
  498. unset($data['is_collect']);
  499. unset($data['user_type']);
  500. // ------c_show_time********add***1****
  501. unset($data['nav_add_pool_id']);
  502. // unset($data['commend_id']);
  503. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  504. Db::beginTransaction();
  505. try {
  506. //处理投票
  507. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  508. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  509. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  510. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  511. unset($data['is_survey']);
  512. unset($data['survey_name']);
  513. unset($data['suvey_array']);
  514. // unset($data['website_id']);
  515. // unset($data['web_site_id']);
  516. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  517. if ($data['hits'] == '') {
  518. $data['hits'] = 0;
  519. }
  520. if ($data['is_original'] == '') {
  521. $data['is_original'] = 0;
  522. }
  523. if ($data['status'] == '') {
  524. $data['status'] = 0;
  525. }
  526. $articleData = $data;
  527. unset($articleData['content']);
  528. //自动处理缩略图、关键字、描述
  529. if ($articleData['imgurl'] == '') {
  530. //如果没有图,设置level=0
  531. $levelArr = json_decode($articleData['level'], true);
  532. var_dump($levelArr, '----------levelArr-----------1');
  533. //content中提取图片第一个图,正则提取
  534. // -------采集器相关优化-----
  535. // 优化正则表达式,仅匹配 src 属性值,避免匹配到多余内容
  536. if ($is_collect == 1) {
  537. $reg = '/<img.*?src=[\'"]?((?!.*\.gif)[^\'" >]+)[\'"]?.*?>/i';
  538. } else {
  539. $reg = '/<img.*?src=[\'"]?([^\'" >]+)[\'"]?.*?>/i';
  540. }
  541. // -------采集器相关优化-----
  542. preg_match_all($reg, $data['content'], $matches);
  543. if (isset($matches[1][0])) {
  544. //截取varchar240
  545. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  546. //如果有图,设置level=3
  547. if (!in_array(3, $levelArr)) {
  548. $levelArr[] = 3;
  549. }
  550. $articleData['level'] = json_encode($levelArr);
  551. } else {
  552. if (!in_array(0, $levelArr)) {
  553. $levelArr[] = 0;
  554. }
  555. $articleData['level'] = json_encode($levelArr);
  556. }
  557. }
  558. var_dump($articleData['level'], '----------$articleData[level]----------1');
  559. if ($articleData['keyword'] == '') {
  560. //提取标题+内容中的关键词
  561. $articleData['keyword'] = $data['title'];
  562. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  563. Jieba::init(); // 初始化 jieba-php
  564. Finalseg::init();
  565. $segList = Jieba::cut($articleData['keyword']);
  566. $segList1 = array_slice($segList, 0, 8);
  567. $articleData['keyword'] = implode(',', $segList1);
  568. }
  569. if ($articleData['introduce'] == '') {
  570. //提取内容中的描述
  571. $content = $data['content'];
  572. // 去除 <style> 和 <script> 标签及其内容
  573. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  574. // 去除所有 HTML 标签
  575. $content = strip_tags($content);
  576. // 去除 HTML 实体
  577. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  578. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  579. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  580. // 去除多余空白
  581. $content = preg_replace('/\s+/u', '', $content);
  582. // 截取 100 个字符
  583. $articleData['introduce'] = mb_substr($content, 0, 100);
  584. }
  585. if ($articleData['status'] == 0) {
  586. $this->sendMessage([
  587. 'talk_type' => 100,
  588. 'title' => $articleData['title'],
  589. 'content' => '提交了审核',
  590. 'messageType' => 2,
  591. ]);
  592. }
  593. if(!empty($data['fujian'])){
  594. $articleData['fujian'] = $data['fujian'];
  595. }
  596. $id = Article::insertGetId($articleData);
  597. if (!$id) {
  598. throw new \Exception('文章插入失败');
  599. }
  600. $articleDataContent = [
  601. 'article_id' => $id,
  602. 'content' => $data['content'],
  603. ];
  604. // 采集器中的文章内容,在添加时,去掉div标签
  605. if ($is_collect == 1) {
  606. // 采集来的文章,content中可能包含div标签,需要先移除
  607. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  608. $article_data = preg_replace($pattern, '', $data['content']);
  609. $$articleDataContent['content'] = $article_data;
  610. }
  611. $contentInsertId = ArticleData::insertGetId($articleDataContent);
  612. if (!$contentInsertId) {
  613. throw new \Exception('文章内容插入失败');
  614. }
  615. // ------c_show_time********add***2****
  616. // 直接使用当前系统时间,不再强制添加8小时
  617. $now = date('Y-m-d H:i:s');
  618. if ($user_type == 10000 || $is_collect == 1) {
  619. // 管理员添加文章时,核心站c端显示时间就是创建时间;非核心站c端显示时间就是此创建时间往后推二十分钟;
  620. // 非管理员添加文章时,不做操作只有在审核通过时获取c端显示时间
  621. if (!isset($data['catid'])) {
  622. throw new \Exception('缺少必要字段:catid');
  623. }
  624. $column_arr = WebsiteColumn::where('column_name','官网')->pluck('id')->toArray();
  625. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  626. $web = WebsiteCategory::where('category_id', $data['catid'])
  627. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  628. ->select(
  629. 'website_id',
  630. DB::raw('
  631. CASE
  632. WHEN website.id IS NULL THEN 2
  633. WHEN website.website_column_id IN ('.implode(',', $column_arr).') THEN 1
  634. ELSE 0
  635. END as is_core
  636. ')
  637. )
  638. ->get();
  639. // $id = 225; -----测试开启
  640. // 采集来的文章,错开时间在两小时之内发布
  641. if ($user_type == 10000 && $is_collect == 1) {
  642. $web_num = $web->where('is_core', '!=', 2)->count();
  643. $waiting_interval = 10;
  644. if ($web_num > 12) {
  645. // 若网站数量大于12个,则每个网站间隔时间取均值
  646. // 防止除数为 0,虽然这里 $web_num 是 count 结果不会为 0,但做健壮性检查
  647. $waiting_interval = 120 / max(1, $web_num);
  648. }
  649. $time = 0;
  650. } else {
  651. // 非核心站与核心站----显示时间-----间隔
  652. $time = 20;
  653. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  654. $waiting_interval = 5;
  655. }
  656. // 将 Hyperf\Database\Model\Collection 转换为数组
  657. $webArray = $web->toArray();
  658. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $id, $waiting_interval, $is_collect) {
  659. // 检查 $item 对象是否有 is_core 属性
  660. if (!isset($item['is_core'])) {
  661. throw new \Exception('$item 对象缺少 is_core 属性');
  662. }
  663. // 当 is_core 为 2 时,则表示此网站不存在
  664. if ($item['is_core'] == 2) {
  665. return null;
  666. }
  667. if ($is_collect == 1) {
  668. // 采集来的文章,错开时间在两小时之内发布
  669. // $time = 0;
  670. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  671. $time += $waiting_interval;
  672. } else if ($item['is_core'] == 1) {
  673. // 当 is_core 为 1 时,则表示此网站是核心站
  674. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  675. } else {
  676. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  677. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  678. if ($item['is_core'] == 0) {
  679. $time += $waiting_interval;
  680. }
  681. }
  682. return [
  683. 'article_id' => $id,
  684. 'website_id' => $item['website_id'],
  685. 'c_show_time' => $c_show_time,
  686. // 'is_core' => $item['is_core'],
  687. // 'time' => $time
  688. ];
  689. }, array_keys($webArray), $webArray)));
  690. // Db::commit();
  691. // return Result::success($article_ignore);
  692. if (!empty($article_ignore)) {
  693. $article_ignores = ArticleIgnore::insert($article_ignore);
  694. if (!$article_ignores) {
  695. throw new \Exception('c端展示时间插入失败');
  696. }
  697. }
  698. }
  699. // ------c_show_time********add***2****
  700. //处理投票
  701. if ($is_survey == 1) {
  702. //生成年月日时分秒+8位随机数
  703. $uuid = date('YmdHis') . rand(10000000, 99999999);
  704. var_dump($suvey_array, 'suvey_array________');
  705. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  706. var_dump($suveys_array, '---------------------1');
  707. var_dump($suvey_array, '---------------------2');
  708. $suvey_data = [];
  709. foreach ($suveys_array as $key => $value) {
  710. if ($value == '') {
  711. continue;
  712. }
  713. if (is_array($value)) {
  714. $suvey_data[] = [
  715. 'sur_id' => $uuid,
  716. 'art_id' => $id,
  717. 'website_id' => $website_id ?? 2,
  718. 'survey_name' => $survey_name,
  719. 'choice_name' => $value[1],
  720. 'is_other' => 1,
  721. 'other_id' => 0,
  722. 'results' => 0,
  723. ];
  724. } else {
  725. $suvey_data[] = [
  726. 'sur_id' => $uuid,
  727. 'art_id' => $id,
  728. 'website_id' => $website_id ?? 2,
  729. 'survey_name' => $survey_name,
  730. 'choice_name' => $value,
  731. 'is_other' => 0,
  732. 'other_id' => 0,
  733. 'results' => 0,
  734. ];
  735. }
  736. if (empty($suvey_data)) {
  737. throw new \Exception("投票数据为空");
  738. }
  739. }
  740. $result = ArticleSurvey::insert($suvey_data);
  741. if (!$result) {
  742. throw new \Exception("投票失败,ArticleSurvey插入失败");
  743. }
  744. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  745. if (!$result) {
  746. throw new \Exception("投票失败,更新主表失败");
  747. }
  748. }
  749. Db::commit();
  750. return Result::success(['id' => $id]);
  751. } catch (\Throwable $ex) {
  752. Db::rollBack();
  753. var_dump($ex->getMessage());
  754. return Result::error("创建失败", 0);
  755. }
  756. }
  757. /**
  758. * @param array $data
  759. * @return array
  760. */
  761. public function delArticle(array $data): array
  762. {
  763. // ------c_show_time********del*******
  764. Db::beginTransaction();
  765. try {
  766. $article = Article::where(['id' => $data['id']])->delete();
  767. // 若文章删除失败,抛出异常,后续 SQL 语句不会执行
  768. if (!$article) {
  769. throw new \Exception("删除失败,文章删除失败");
  770. }
  771. //survey投票删除
  772. ArticleSurvey::where(['art_id' => $data['id']])->delete(); // 修正类名大小写
  773. $articleIgnore = ArticleIgnore::where(['article_id' => $data['id']])->delete();
  774. $article_data = ArticleData::where(['article_id' => $data['id']])->delete();
  775. // 若文章详情删除失败,抛出异常
  776. if (!$article_data) {
  777. throw new \Exception("删除失败,文章详情删除失败");
  778. }
  779. Db::commit(); // 所有操作成功,提交事务
  780. } catch (\Throwable $ex) {
  781. Db::rollBack();
  782. var_dump($ex->getMessage());
  783. return Result::error("删除失败: " . $ex->getMessage(), 0);
  784. }
  785. // ------c_show_time********del*******
  786. if (!$article) {
  787. return Result::error("删除失败");
  788. }
  789. return Result::success($article);
  790. }
  791. /**
  792. * @param array $data
  793. * @return array
  794. */
  795. public function updateArticle(array $data): array
  796. {
  797. var_dump($data, '----------12-----------1');
  798. Db::beginTransaction();
  799. // ------c_show_time********up*******
  800. $user_type = isset($data['user_type']) ? $data['user_type'] : 0;
  801. // 无论是否改变了c端显示时间或者栏目,都需要将未屏蔽的网站显示时间删除记录
  802. // 若是存在交集,则进行修改,若无,则合并(此表中的记录应该包含被屏蔽网站及涉及所有网站的展示时间)
  803. $web = WebsiteCategory::where('category_id', $data['catid'])
  804. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  805. ->select(
  806. 'website_id',
  807. 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')
  808. )
  809. ->get();
  810. // 根据错误信息,问题在于 $web 可能是一个包含对象的集合,不能直接用于 whereNotIn 方法
  811. // 先从 $web 集合中提取 website_id 字段的值,再进行删除操作
  812. $websiteIds = $web->pluck('website_id')->toArray();
  813. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  814. if ($user_type == 0) {
  815. throw new \Exception("用户类型不能为空");
  816. }
  817. if ($user_type == 10000) {
  818. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  819. $web = WebsiteCategory::where('category_id', $data['catid'])
  820. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  821. ->select(
  822. 'website_id',
  823. 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')
  824. )
  825. ->get();
  826. // 非核心站与核心站----显示时间-----间隔
  827. $time = 20;
  828. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  829. $waiting_interval = 5;
  830. $webArray = $web->toArray();
  831. if (empty($webArray)) {
  832. throw new \Exception('网站分类不存在');
  833. }
  834. // 直接使用当前系统时间,不再强制添加8小时
  835. $now = date('Y-m-d H:i:s');
  836. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  837. // 检查 $item 对象是否有 is_core 属性
  838. if (!isset($item['is_core'])) {
  839. throw new \Exception('$item 对象缺少 is_core 属性');
  840. }
  841. // 当 is_core 为 2 时,则表示此网站不存在
  842. if ($item['is_core'] == 2) {
  843. return null;
  844. } else if ($item['is_core'] == 1) {
  845. // 当 is_core 为 1 时,则表示此网站是核心站
  846. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  847. } else {
  848. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  849. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  850. if ($item['is_core'] == 0) {
  851. $time += $waiting_interval;
  852. }
  853. }
  854. return [
  855. 'article_id' => $data['id'],
  856. 'website_id' => $item['website_id'],
  857. 'c_show_time' => $c_show_time,
  858. ];
  859. }, array_keys($webArray), $webArray)));
  860. if (!empty($article_ignore)) {
  861. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  862. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  863. $article_ignores = ArticleIgnore::upsert(
  864. $article_ignore,
  865. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  866. ['c_show_time'] // 需要更新的字段
  867. );
  868. if (!$article_ignores) {
  869. throw new \Exception('c端展示时间插入失败');
  870. }
  871. }
  872. // Db::commit();
  873. // return Result::success($article_ignore);
  874. }
  875. // ------c_show_time********up*******
  876. unset($data['user_type']);
  877. // unset($data['web_site_id']);
  878. unset($data['nav_add_pool_id']);
  879. try {
  880. //处理投票
  881. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  882. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  883. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  884. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  885. unset($data['is_survey']);
  886. unset($data['survey_name']);
  887. unset($data['suvey_array']);
  888. unset($data['website_id']);
  889. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  890. if ($data['hits'] == '') {
  891. $data['hits'] = 0;
  892. }
  893. if ($data['is_original'] == '') {
  894. $data['is_original'] = 0;
  895. }
  896. if ($data['status'] == '') {
  897. $data['status'] = 0;
  898. }
  899. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  900. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  901. $articleData = $data;
  902. unset($articleData['content']);
  903. unset($articleData['status_name']);
  904. unset($articleData['name']);
  905. unset($articleData['content']);
  906. unset($articleData['pid_arr']);
  907. unset($articleData['pid']);
  908. //自动处理缩略图、关键字、描述
  909. if ($articleData['imgurl'] == '') {
  910. //如果没有图,设置level=0
  911. $levelArr = json_decode($articleData['level'], true);
  912. var_dump($levelArr, '----------levelArr-----------1');
  913. //content中提取图片第一个图,正则提取
  914. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  915. preg_match_all($reg, $data['content'], $matches);
  916. if (isset($matches[1][0])) {
  917. //截取varchar240
  918. // 截取到第一个<
  919. $articleData['imgurl'] = $matches[1][0];
  920. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  921. $pos = strpos($articleData['imgurl'], '"');
  922. if ($pos !== false) {
  923. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  924. }
  925. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  926. //如果有图,设置level=3
  927. if (!in_array(3, $levelArr)) {
  928. $levelArr[] = 3;
  929. }
  930. $articleData['level'] = json_encode($levelArr);
  931. } else {
  932. if (!in_array(0, $levelArr)) {
  933. $levelArr[] = 0;
  934. }
  935. $articleData['level'] = json_encode($levelArr);
  936. }
  937. }
  938. var_dump($articleData['level'], '----------$articleData[level]----------1');
  939. if ($articleData['keyword'] == '') {
  940. //提取标题+内容中的关键词
  941. $articleData['keyword'] = $data['title'];
  942. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  943. Jieba::init(); // 初始化 jieba-php
  944. Finalseg::init();
  945. $segList = Jieba::cut($articleData['keyword']);
  946. $segList1 = array_slice($segList, 0, 8);
  947. $articleData['keyword'] = implode(',', $segList1);
  948. }
  949. if ($articleData['introduce'] == '') {
  950. //提取内容中的描述
  951. $content = $data['content'];
  952. // 去除 <style> 和 <script> 标签及其内容
  953. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  954. // 去除所有 HTML 标签
  955. $content = strip_tags($content);
  956. // 去除 HTML 实体
  957. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  958. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  959. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  960. // 去除多余空白
  961. $content = preg_replace('/\s+/u', '', $content);
  962. // 截取 100 个字符
  963. $articleData['introduce'] = mb_substr($content, 0, 100);
  964. }
  965. if ($articleData['status'] == 0) {
  966. $this->sendMessage([
  967. 'talk_type' => 100,
  968. 'title' => $articleData['title'],
  969. 'content' => '提交了审核',
  970. 'messageType' => 2,
  971. ]);
  972. }
  973. if(!empty($data['fujian'])){
  974. $articleData['fujian'] = $data['fujian'];
  975. }
  976. $id = Article::where(['id' => $data['id']])->update($articleData);
  977. // $articleDataContent = [
  978. // 'content' => $data['content'],
  979. // ];
  980. // 采集来的文章,content中可能包含div标签,需要先移除
  981. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  982. $article_data = preg_replace($pattern, '', $data['content']);
  983. $articleDataContent['content'] = $article_data;
  984. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  985. //处理投票
  986. $id = $data['id'];
  987. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  988. var_dump($suvey_array, 'suvey_array________delete');
  989. //处理投票
  990. if ($is_survey == 1) {
  991. //生成年月日时分秒+8位随机数
  992. $uuid = date('YmdHis') . rand(10000000, 99999999);
  993. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  994. var_dump($suveys_array, '---------------------1');
  995. $suvey_data = [];
  996. if (is_array($suveys_array)) {
  997. foreach ($suveys_array as $key => $value) {
  998. if ($value == '') {
  999. continue;
  1000. }
  1001. if (is_array($value)) {
  1002. $suvey_data[] = [
  1003. 'sur_id' => $uuid,
  1004. 'art_id' => $id,
  1005. 'website_id' => $website_id ?? 2,
  1006. 'survey_name' => $survey_name,
  1007. 'choice_name' => $value[1],
  1008. 'is_other' => 1,
  1009. 'other_id' => 0,
  1010. 'results' => 0,
  1011. ];
  1012. } else {
  1013. $suvey_data[] = [
  1014. 'sur_id' => $uuid,
  1015. 'art_id' => $id,
  1016. 'website_id' => $website_id ?? 2,
  1017. 'survey_name' => $survey_name,
  1018. 'choice_name' => $value,
  1019. 'is_other' => 0,
  1020. 'other_id' => 0,
  1021. 'results' => 0,
  1022. ];
  1023. }
  1024. if (empty($suvey_data)) {
  1025. throw new \Exception("投票数据为空");
  1026. }
  1027. }
  1028. }
  1029. $result = ArticleSurvey::insert($suvey_data);
  1030. if (!$result) {
  1031. throw new \Exception("投票失败");
  1032. }
  1033. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  1034. if (!$result) {
  1035. throw new \Exception("投票失败");
  1036. }
  1037. } else {
  1038. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  1039. }
  1040. Db::commit();
  1041. return Result::success([]);
  1042. } catch (\Throwable $ex) {
  1043. Db::rollBack();
  1044. var_dump($ex->getMessage());
  1045. return Result::error("更新失败" . $ex->getMessage(), 0);
  1046. }
  1047. }
  1048. /**
  1049. * 更新资讯状态
  1050. * @param array $data
  1051. * @return array
  1052. */
  1053. public function upArticleStatus(array $data): array
  1054. {
  1055. $articleData = Article::where(['id' => $data['id']])->first();
  1056. //发送10次
  1057. // for ($i = 0; $i < 10; $i++) {
  1058. // $this->sendMessage([
  1059. // 'talk_type' => 100,
  1060. // 'title' => $i . $articleData['title'],
  1061. // 'content' => '审核通过',
  1062. // 'messageType' => 2,
  1063. // 'user_id' => $articleData['admin_user_id'],
  1064. // ]);
  1065. // }
  1066. // var_dump($data['status'], 'status');
  1067. // return Result::success();
  1068. if ($data['status'] == 1) {
  1069. $this->sendMessage([
  1070. 'talk_type' => 101,
  1071. 'title' => $articleData['title'],
  1072. 'content' => '审核通过',
  1073. 'messageType' => 2,
  1074. 'user_id' => $articleData['admin_user_id'],
  1075. ]);
  1076. }
  1077. if ($data['status'] == 2) {
  1078. $this->sendMessage([
  1079. 'talk_type' => 101,
  1080. 'title' => $articleData['title'],
  1081. 'content' => '审核拒绝',
  1082. 'messageType' => 2,
  1083. 'user_id' => $articleData['admin_user_id'],
  1084. ]);
  1085. }
  1086. if ($data['status'] == 0) {
  1087. $this->sendMessage([
  1088. 'talk_type' => 100,
  1089. 'title' => $articleData['title'],
  1090. 'content' => '提交了审核',
  1091. 'messageType' => 2,
  1092. ]);
  1093. }
  1094. $result = Article::where(['id' => $data['id']])->update($data);
  1095. // ------c_show_time********up_status*******
  1096. // 若是审核通过 则更新c_show_time
  1097. if ($data['status'] == 1) {
  1098. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  1099. $column_arr = WebsiteColumn::where('column_name','官网')->pluck('id')->toArray();
  1100. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  1101. $web = WebsiteCategory::where('category_id', $data['catid'])
  1102. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  1103. ->select(
  1104. 'website_id',
  1105. DB::raw('
  1106. CASE
  1107. WHEN website.id IS NULL THEN 2
  1108. WHEN website.website_column_id IN ('.implode(',', $column_arr).') THEN 1
  1109. ELSE 0
  1110. END as is_core
  1111. ')
  1112. )
  1113. ->get();
  1114. // 非核心站与核心站----显示时间-----间隔
  1115. $time = 20;
  1116. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  1117. $waiting_interval = 5;
  1118. $webArray = $web->toArray();
  1119. if (empty($webArray)) {
  1120. throw new \Exception('网站分类不存在');
  1121. }
  1122. // 直接使用当前系统时间,不再强制添加8小时
  1123. $now = date('Y-m-d H:i:s');
  1124. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  1125. if (isset($data['ignore_ids'])) {
  1126. $ignore_website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  1127. if (in_array($item['website_id'], $ignore_website_ids)) {
  1128. $is_ignore = 1;
  1129. } else {
  1130. $is_ignore = 0;
  1131. }
  1132. return [
  1133. 'article_id' => $data['id'],
  1134. 'website_id' => $item['website_id'],
  1135. 'is_ignore' => $is_ignore,
  1136. ];
  1137. } else {
  1138. // 检查 $item 对象是否有 is_core 属性
  1139. if (!isset($item['is_core'])) {
  1140. throw new \Exception('$item 对象缺少 is_core 属性');
  1141. }
  1142. // 当 is_core 为 2 时,则表示此网站不存在
  1143. if ($item['is_core'] == 2) {
  1144. return null;
  1145. } else if ($item['is_core'] == 1) {
  1146. // 当 is_core 为 1 时,则表示此网站是核心站
  1147. $c_show_time = $now;
  1148. } else {
  1149. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  1150. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  1151. if ($item['is_core'] == 0) {
  1152. $time += $waiting_interval;
  1153. }
  1154. }
  1155. return [
  1156. 'article_id' => $data['id'],
  1157. 'website_id' => $item['website_id'],
  1158. 'c_show_time' => $c_show_time,
  1159. ];
  1160. }
  1161. }, array_keys($webArray), $webArray)));
  1162. if (!empty($article_ignore) && !isset($data['ignore_ids'])) {
  1163. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  1164. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  1165. $websiteIds = $web->pluck('website_id')->toArray();
  1166. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  1167. $article_ignores = ArticleIgnore::upsert(
  1168. $article_ignore,
  1169. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1170. ['c_show_time'] // 需要更新的字段
  1171. );
  1172. if (!$article_ignores) {
  1173. throw new \Exception('c端展示时间插入失败');
  1174. }
  1175. }
  1176. if (!empty($data['ignore_ids'])) {
  1177. // return Result::success($article_ignore);
  1178. // 从数据库中删除 article_id 为 $data['id'] 且 website_id 在 $website_ids 中的记录
  1179. if (!empty($article_ignore)) {
  1180. $article_ignores = ArticleIgnore::upsert(
  1181. $article_ignore,
  1182. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1183. ['is_ignore'] // 需要更新的字段
  1184. );
  1185. // if(!$article_ignores){
  1186. // throw new \Exception('屏蔽网站更新失败');
  1187. // }
  1188. }
  1189. }
  1190. }
  1191. // ------c_show_time********up_status*******
  1192. if ($result) {
  1193. return Result::success();
  1194. } else {
  1195. return Result::error("更新状态失败", 0);
  1196. }
  1197. }
  1198. /**
  1199. * 获取新闻详情
  1200. * @param array $data
  1201. * @return array
  1202. */
  1203. public function getArticleInfo(array $data): array
  1204. {
  1205. $where = [
  1206. 'article.id' => $data['id'],
  1207. // 'article.status' => 1,
  1208. ];
  1209. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  1210. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  1211. $info = $result;
  1212. // var_dump($info, 'info');
  1213. $info['survey_array'] = $articleSurvey;
  1214. if ($result) {
  1215. return Result::success($info);
  1216. } else {
  1217. return Result::error("查询失败", 0);
  1218. }
  1219. }
  1220. /**
  1221. * 获取头条新闻
  1222. * @param array $data
  1223. * @return array
  1224. */
  1225. public function getWebsiteArticlett(array $data): array
  1226. {
  1227. $website_id = $data['website_id'];
  1228. $website = Website::where('id', $data['website_id'])->first();
  1229. if (empty($website)) {
  1230. return Result::error("网站不存在", 0);
  1231. }
  1232. $categorys = $this->processArticlePro($website_id);
  1233. $catiall = $categorys['catiall'];
  1234. $categoryIds = $categorys['categoryIds'];
  1235. $where = [
  1236. 'status' => 1
  1237. ];
  1238. // $website_column = $website['column'];
  1239. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1240. $website_column = json_decode($website['website_column_arr_id'], true);
  1241. }
  1242. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1243. // return Result::success($diff_pid_categoryIds);
  1244. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1245. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1246. }
  1247. // $website_id = $data['website_id'];
  1248. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  1249. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  1250. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  1251. switch ($data['level']) {
  1252. case 1:
  1253. case 2:
  1254. case 3:
  1255. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  1256. $query = Article::where($where)
  1257. ->where('level', 'like', '%' . $data['level'] . '%')
  1258. ->orderBy('updated_at', 'desc');
  1259. break;
  1260. case 4: //最新资讯
  1261. $query = Article::where($where)->orderBy('updated_at', 'desc');
  1262. break;
  1263. case 5: //资讯推荐
  1264. $query = Article::where($where)
  1265. ->where('updated_at', '>', $month);
  1266. break;
  1267. case 7: //资讯分类
  1268. if (isset($data['id']) && !empty($data['id'])) {
  1269. $keyword = Article::where('id', $data['id'])->value('keyword');
  1270. $keywordArray = explode(',', $keyword);
  1271. $whereL7 = [];
  1272. foreach ($keywordArray as $k => $v) {
  1273. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1274. }
  1275. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  1276. break;
  1277. } else {
  1278. return Result::error("请输入资讯ID", 0);
  1279. break;
  1280. }
  1281. default:
  1282. break;
  1283. }
  1284. // $whereL7 = [];
  1285. // if(isset($data['id']) && !empty($data['id'])){
  1286. // $keyword = Article::where('id', $data['id'])->value('keyword');
  1287. // $keywordArray = explode(',', $keyword);
  1288. // foreach ($keywordArray as $k => $v) {
  1289. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1290. // }
  1291. // }
  1292. // $query = Article::where($where)
  1293. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  1294. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  1295. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  1296. // }
  1297. // if($data['level'] == 7){
  1298. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  1299. // }
  1300. // if($data['level'] == 4){
  1301. // $query = $query->inRandomOrder()
  1302. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  1303. // }
  1304. // if($data['level'] == 5){
  1305. // $query = $query->orderBy('updated_at','desc');
  1306. // }
  1307. // });
  1308. if ($data['textnum'] > 0) {
  1309. $query = clone $query;
  1310. $result['text'] = $query
  1311. ->whereIn('catid', $categoryIds)
  1312. ->leftJoinSub(function ($query) use ($website_id) {
  1313. $query->from('article_ignore')
  1314. ->where('website_id', $website_id);
  1315. }, 'article_ignore', function ($join) {
  1316. $join->on('article_ignore.article_id', '=', 'article.id');
  1317. })
  1318. ->where(function ($query) {
  1319. $query->whereNull('article_ignore.article_id')
  1320. ->orWhere(function ($subQuery) {
  1321. $subQuery->whereNotNull('article_ignore.article_id')
  1322. ->where('article_ignore.is_ignore', 0)
  1323. ->where(function ($subSubQuery) {
  1324. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1325. ->orWhereNull('article_ignore.c_show_time');
  1326. });
  1327. });
  1328. })
  1329. // ->where(function ($query) use ($website_id) {
  1330. // $query->whereNull('article_ignore.article_id')
  1331. // ->orWhere('article_ignore.website_id', '!=', $website_id);
  1332. // })
  1333. ->select(
  1334. 'article.id',
  1335. 'article.title',
  1336. 'article.author',
  1337. 'article.updated_at',
  1338. 'article.introduce',
  1339. 'article.islink',
  1340. 'article.linkurl',
  1341. 'article.copyfrom',
  1342. 'article.cat_arr_id',
  1343. 'article.catid',
  1344. 'article.level',
  1345. // 'article_ignore.is_ignore',
  1346. // 'article_ignore.c_show_time',
  1347. )
  1348. ->offset($data['placeid'])
  1349. ->limit($data['textnum'])
  1350. ->get()->all();
  1351. foreach ($result['text'] as $k => $v) {
  1352. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1353. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  1354. }
  1355. }
  1356. if ($data['imgnum'] > 0) {
  1357. $query = clone $query;
  1358. if ($data['textnum'] == 0) {
  1359. $query = $query->leftJoinSub(function ($query) use ($website_id) {
  1360. $query->from('article_ignore')
  1361. ->where('website_id', $website_id);
  1362. }, 'article_ignore', function ($join) {
  1363. $join->on('article_ignore.article_id', '=', 'article.id');
  1364. })
  1365. ->where(function ($query) {
  1366. $query->whereNull('article_ignore.article_id')
  1367. ->orWhere(function ($subQuery) {
  1368. $subQuery->whereNotNull('article_ignore.article_id')
  1369. ->where('article_ignore.is_ignore', 0)
  1370. ->where(function ($subSubQuery) {
  1371. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1372. ->orWhereNull('article_ignore.c_show_time');
  1373. });
  1374. });
  1375. });
  1376. }
  1377. $result['img'] = $query
  1378. ->whereIn('catid', $categoryIds)
  1379. ->where('article.imgurl', '!=', '')
  1380. ->select(
  1381. 'article.id',
  1382. 'article.title',
  1383. 'article.imgurl',
  1384. 'article.author',
  1385. 'article.updated_at',
  1386. 'article.introduce',
  1387. 'article.islink',
  1388. 'article.linkurl',
  1389. 'article.copyfrom',
  1390. 'article.cat_arr_id',
  1391. 'article.catid',
  1392. 'article.level',
  1393. // 'article_ignore.is_ignore',
  1394. // 'article_ignore.c_show_time',
  1395. )
  1396. ->offset($data['placeid'])
  1397. ->limit($data['imgnum'])
  1398. ->get()->all();
  1399. foreach ($result['img'] as $k => $v) {
  1400. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1401. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1402. }
  1403. }
  1404. if (empty($result)) {
  1405. return Result::error("暂无相关资讯", 0);
  1406. }
  1407. return Result::success($result);
  1408. }
  1409. /**
  1410. * 获取模块新闻
  1411. * @param array $data
  1412. * @return array
  1413. */
  1414. public function getWebsiteModelArticles(array $data): array
  1415. {
  1416. $catid = $data['catid'];
  1417. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1418. $category = $category->toArray();
  1419. if (!empty($category)) {
  1420. $where = [
  1421. 'status' => 1,
  1422. 'catid' => $catid,
  1423. ];
  1424. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1425. // 1:文字新闻;2:轮播图;3:图文;
  1426. // 级别:0:未分类
  1427. // 3:推荐图片
  1428. if ($data['level'] == 1) {
  1429. $data['level'] = 0;
  1430. }
  1431. $result = Article::where($where)
  1432. ->where(function ($query) use ($data) {
  1433. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1434. ->orWhereNull("level")
  1435. ->orWhereRaw("level = '[]'");
  1436. })
  1437. ->leftJoinSub(function ($query) use ($data) {
  1438. $query->from('article_ignore')
  1439. ->where('website_id', $data['website_id']);
  1440. }, 'article_ignore', function ($join) {
  1441. $join->on('article_ignore.article_id', '=', 'article.id');
  1442. })
  1443. ->where(function ($query) {
  1444. $query->whereNull('article_ignore.article_id')
  1445. ->orWhere(function ($subQuery) {
  1446. $subQuery->whereNotNull('article_ignore.article_id')
  1447. ->where('article_ignore.is_ignore', 0)
  1448. ->where(function ($subSubQuery) {
  1449. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1450. ->orWhereNull('article_ignore.c_show_time');
  1451. });
  1452. });
  1453. })
  1454. // ->where(function ($query) use ($data) {
  1455. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1456. // ->orWhereNull("ignore_ids");
  1457. // })
  1458. ->orderBy("updated_at", "desc")
  1459. ->offset($placeid)
  1460. ->limit($data['pagesize'])
  1461. ->get();
  1462. if (empty($result)) {
  1463. return Result::error("此栏目暂无相关新闻", 0);
  1464. }
  1465. } else {
  1466. return Result::error("此网站暂无此栏目", 0);
  1467. }
  1468. return Result::success($result);
  1469. }
  1470. /**
  1471. *获取新闻列表
  1472. * @param array $data
  1473. * @return array
  1474. */
  1475. public function getWebsiteArticleList(array $data): array
  1476. {
  1477. // return Result::success($data);
  1478. $where[] = ['status', '=', 1];
  1479. $website_id = $data['website_id'];
  1480. $website = Website::where('id', $data['website_id'])->first();
  1481. if (empty($website)) {
  1482. return Result::error("网站不存在", 0);
  1483. }
  1484. // $website_column = $website['column'];
  1485. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1486. $website_column = json_decode($website['website_column_arr_id'], true);
  1487. }
  1488. $categorys = $this->processArticlePro($website_id);
  1489. $cat_1st_arr = $categorys['cat_1st_arr'];
  1490. $catiall = $categorys['catiall'];
  1491. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1492. // return Result::success($diff_pid_categoryIds);
  1493. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1494. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1495. }
  1496. if (isset($data['catid']) && !empty($data['catid'])) {
  1497. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1498. if (empty($category)) {
  1499. return Result::error("此网站暂无此栏目", 0);
  1500. }
  1501. array_push($where, ['catid', '=', $data['catid']]);
  1502. }
  1503. // return Result::success($where);
  1504. $query = Article::where($where)
  1505. ->leftJoinSub(function ($query) use ($website_id) {
  1506. $query->from('article_ignore')
  1507. ->where('website_id', $website_id);
  1508. }, 'article_ignore', function ($join) {
  1509. $join->on('article_ignore.article_id', '=', 'article.id');
  1510. })
  1511. ->where(function ($query) {
  1512. $query->whereNull('article_ignore.article_id')
  1513. ->orWhere(function ($subQuery) {
  1514. $subQuery->whereNotNull('article_ignore.article_id')
  1515. ->where('article_ignore.is_ignore', 0)
  1516. ->where(function ($subSubQuery) {
  1517. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1518. ->orWhereNull('article_ignore.c_show_time');
  1519. });
  1520. });
  1521. })
  1522. ->select(
  1523. 'article.id',
  1524. 'article.title',
  1525. 'article.imgurl',
  1526. 'article.author',
  1527. 'article.updated_at',
  1528. 'article.introduce',
  1529. 'article.islink',
  1530. 'article.linkurl',
  1531. 'article.copyfrom',
  1532. 'article.cat_arr_id',
  1533. 'article.catid'
  1534. );
  1535. $count = $query->count();
  1536. $rep = $query->orderBy("updated_at", "desc")
  1537. ->offset(($data['page'] - 1) * $data['pageSize'])
  1538. ->limit($data['pageSize'])
  1539. ->get()->all();
  1540. $categorys = $this->processArticlePro($website_id);
  1541. $cat_1st_arr = $categorys['cat_1st_arr'];
  1542. $catiall = $categorys['catiall'];
  1543. // $web['website_id'] = $data['website_id'];
  1544. foreach ($rep as $k => $v) {
  1545. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1546. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1547. }
  1548. // $rep = $this->processArticles($rep,$web);
  1549. $data = [
  1550. 'rows' => $rep,
  1551. 'count' => $count,
  1552. ];
  1553. if (empty($rep)) {
  1554. return Result::error("没有信息数据");
  1555. }
  1556. return Result::success($data);
  1557. }
  1558. /**
  1559. * 前端-获取新闻详情
  1560. * @param array $data
  1561. * @return array
  1562. */
  1563. public function selectWebsiteArticleInfo(array $data): array
  1564. {
  1565. $where = [
  1566. 'article.id' => $data['id'],
  1567. 'article.status' => 1,
  1568. ];
  1569. $result = Article::where($where)
  1570. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1571. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1572. // ->where(function ($query) use ($data) {
  1573. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1574. // ->orWhereNull("ignore_ids");
  1575. // })
  1576. ->leftJoinSub(function ($query) use ($data) {
  1577. $query->from('article_ignore')
  1578. ->where('website_id', $data['website_id']);
  1579. }, 'article_ignore', function ($join) {
  1580. $join->on('article_ignore.article_id', '=', 'article.id');
  1581. })
  1582. ->where(function ($query) {
  1583. $query->whereNull('article_ignore.article_id')
  1584. ->orWhere(function ($subQuery) {
  1585. $subQuery->whereNotNull('article_ignore.article_id')
  1586. ->where('article_ignore.is_ignore', 0)
  1587. ->where(function ($subSubQuery) {
  1588. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1589. ->orWhereNull('article_ignore.c_show_time');
  1590. });
  1591. });
  1592. })
  1593. ->select(
  1594. 'article.*',
  1595. 'article_data.content',
  1596. 'article_data.article_id',
  1597. 'article_extend.website_url',
  1598. 'article_extend.email',
  1599. 'article_extend.contacts',
  1600. 'article_extend.contacts_mobile',
  1601. 'article_extend.contacts_address',
  1602. 'article_extend.zip_code',
  1603. 'article_extend.enterprise_name'
  1604. )
  1605. ->first();
  1606. if (empty($result)) {
  1607. return Result::error("暂无此新闻!", 0);
  1608. }
  1609. if (!empty($result['publiced_at'])) {
  1610. $result['updated_at'] = $result['publiced_at'];
  1611. }
  1612. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1613. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1614. ->where('website_category.website_id', $data['website_id'])
  1615. ->where(['website_category.category_id' => $result['catid']])
  1616. ->first();
  1617. if (empty($category)) {
  1618. return Result::error("查询失败", 0);
  1619. }
  1620. //手动推荐文章
  1621. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1622. if (empty($commend_ids)) {
  1623. $commendArticle = [];
  1624. } else {
  1625. //去除不存在的文章ID
  1626. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1627. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1628. ->leftJoinSub(function ($query) use ($data) {
  1629. $query->from('article_ignore')
  1630. ->where('website_id', $data['website_id']);
  1631. }, 'article_ignore', function ($join) {
  1632. $join->on('article_ignore.article_id', '=', 'article.id');
  1633. })
  1634. ->where(function ($query) {
  1635. $query->whereNull('article_ignore.article_id')
  1636. ->orWhere(function ($subQuery) {
  1637. $subQuery->whereNotNull('article_ignore.article_id')
  1638. ->where('article_ignore.is_ignore', 0)
  1639. ->where(function ($subSubQuery) {
  1640. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1641. ->orWhereNull('article_ignore.c_show_time');
  1642. });
  1643. });
  1644. })
  1645. ->where('article.status', 1)
  1646. ->where('website_category.website_id', $data['website_id'])
  1647. ->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')
  1648. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1649. // ->orderBy('article.updated_at', 'desc')
  1650. ->limit(5)
  1651. ->get();
  1652. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1653. foreach ($commendArticle as $k => $v) {
  1654. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1655. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1656. $cat_arr_id = array_unique($cat_arr_id);
  1657. // 从website_category取出alias_pinyin
  1658. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1659. ->whereIn('category_id', $cat_arr_id)
  1660. ->pluck('alias_pinyin', 'category_id')
  1661. ->toArray();
  1662. // 将cat_arr_id的json转成路径/隔开
  1663. $path_parts = [];
  1664. foreach ($cat_arr_id as $cat_id) {
  1665. if (isset($cat_arr[$cat_id])) {
  1666. $path_parts[] = $cat_arr[$cat_id];
  1667. }
  1668. }
  1669. $v->alias_pinyin = implode('/', $path_parts);
  1670. } else {
  1671. $v->alias_pinyin = '';
  1672. }
  1673. }
  1674. }
  1675. $result['category_id'] = $category['category_id'];
  1676. $result['cat_name'] = $category['alias'];
  1677. $result['website_name'] = $category['website_name'] ?? "";
  1678. $result['suffix'] = $category['suffix'] ?? "";
  1679. $result['commendArticle'] = $commendArticle;
  1680. $result['commend_ids'] = $commend_ids;
  1681. return Result::success($result);
  1682. }
  1683. /**
  1684. * 前端-获取网站调查问卷
  1685. * @param array $data
  1686. * @return array
  1687. */
  1688. public function getWebsiteSurvey(array $data): array
  1689. {
  1690. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1691. $website = Website::where('id', $data['website_id'])->first();
  1692. if (empty($website)) {
  1693. return Result::error("暂无此网站", 0);
  1694. }
  1695. }
  1696. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1697. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1698. if (empty($article)) {
  1699. return Result::error("暂无此文章", 0);
  1700. }
  1701. // return Result::error($data,0);
  1702. $where['art_id'] = $data['art_id'];
  1703. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1704. } else {
  1705. $survey = Article::where(function ($query) {
  1706. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1707. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1708. })
  1709. ->where('status', 1)
  1710. ->where('is_survey', 1)
  1711. ->select('survey_id')
  1712. ->orderBy('updated_at', 'desc')
  1713. ->first();
  1714. if (empty($survey)) {
  1715. return Result::error("暂无调查问卷", 0);
  1716. }
  1717. $where['sur_id'] = $survey['survey_id'];
  1718. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1719. }
  1720. // return Result::success($where);
  1721. $result = ArticleSurvey::where($where)
  1722. ->where(function ($query) {
  1723. $query->where('is_other', 0)
  1724. ->orWhere(function ($subQuery) {
  1725. $subQuery->where('is_other', 1)
  1726. ->where('other_id', 0);
  1727. });
  1728. })
  1729. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1730. ->select('article_survey.*', 'article.survey_type')
  1731. ->get()->all();
  1732. if (empty($result)) {
  1733. return Result::error("此文章暂无调查问卷", 0);
  1734. }
  1735. return Result::success($result);
  1736. }
  1737. /**
  1738. * 前端-添加网站调查问卷选项
  1739. * @param array $data
  1740. * @return array
  1741. */
  1742. public function addWebsiteSurveyOption(array $data): array
  1743. {
  1744. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1745. $website = Website::where('id', $data['website_id'])->first();
  1746. if (empty($website)) {
  1747. return Result::error("暂无此网站", 0);
  1748. }
  1749. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1750. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1751. if (empty($survey)) {
  1752. return Result::error("此调查问卷不可添加选项", 0);
  1753. }
  1754. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1755. $choice = [
  1756. 'art_id' => $survey['art_id'],
  1757. 'website_id' => $data['website_id'],
  1758. 'survey_name' => $survey['survey_name'],
  1759. 'choice_name' => $data['choice_name'],
  1760. 'sur_id' => $survey['sur_id'],
  1761. 'is_other' => 1,
  1762. 'other_id' => $survey['id'],
  1763. ];
  1764. $result = ArticleSurvey::insertGetId($choice);
  1765. if (empty($result)) {
  1766. return Result::error("添加失败", 0);
  1767. }
  1768. return Result::success($result);
  1769. }
  1770. }
  1771. return Result::error("添加失败", 0);
  1772. }
  1773. return Result::error("添加失败", 0);
  1774. }
  1775. /**
  1776. * 前端-调查问卷投票
  1777. * @param array $data
  1778. * @return array
  1779. */
  1780. public function addWebsiteSurveyVote(array $data): array
  1781. {
  1782. // return Result::success($data);
  1783. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1784. $website = Website::where('id', $data['website_id'])->first();
  1785. if (empty($website)) {
  1786. return Result::error("暂无此网站", 0);
  1787. }
  1788. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1789. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1790. // return Result::success($survey);
  1791. if (empty($is_survey)) {
  1792. return Result::error("此调查问卷不存在", 0);
  1793. }
  1794. // return Result::success($survey);
  1795. // 调查问卷类型
  1796. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1797. //多选 若是json型则转化成数组类型
  1798. if (strpos($data['choice_id'], '[') === 0) {
  1799. $data['choice_id'] = json_decode($data['choice_id'], true);
  1800. } else {
  1801. // 单选 也转换成数组
  1802. $data['choice_id'] = [$data['choice_id']];
  1803. }
  1804. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1805. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1806. // ->where('website_id',$data['website_id'])
  1807. ->where('is_other', 1)
  1808. ->where('other_id', 0)
  1809. ->first();
  1810. if (!empty($other)) {
  1811. return Result::error("请选择已有的选项!", 0);
  1812. }
  1813. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1814. // ->where('website_id',$data['website_id'])
  1815. ->where('is_other', 1)
  1816. ->where('other_id', '!=', 0)
  1817. ->first();
  1818. // return Result::success($choice['other']);
  1819. $choice_id = $data['choice_id'];
  1820. if (!empty($choice['other'])) {
  1821. // array_push($data['choice_id'],$choice['other']['other_id']);
  1822. if (!empty($choice_id)) {
  1823. $key = array_search($choice['other']['id'], $choice_id);
  1824. if ($key !== false) {
  1825. unset($choice_id[$key]);
  1826. $choice_id = array_values($choice_id);
  1827. }
  1828. array_push($choice_id, $choice['other']['other_id']);
  1829. } else {
  1830. $choice_id[0] = $choice['other']['other_id'];
  1831. }
  1832. array_push($data['choice_id'], $choice['other']['other_id']);
  1833. }
  1834. // return Result::success($data);
  1835. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1836. // ->where('website_id',$data['website_id'])
  1837. ->increment('results', 1);
  1838. if (empty($choice)) {
  1839. return Result::error("请选择已有的选项!", 0);
  1840. }
  1841. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1842. // ->where('website_id',$data['website_id'])
  1843. ->where('other_id', 0)
  1844. ->get();
  1845. $survey['choice'] = $choice_id;
  1846. return Result::success($survey);
  1847. }
  1848. return Result::error("参数必填!");
  1849. }
  1850. return Result::error("此调查问卷不存在", 0);
  1851. }
  1852. return Result::error("参数必填!");
  1853. }
  1854. /**
  1855. * 后端-获取网站调查问卷列表
  1856. * @param array $data
  1857. * @return array
  1858. */
  1859. public function getSurveyList(array $data): array
  1860. {
  1861. $where = [];
  1862. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1863. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1864. }
  1865. $survey_type = isset($data['survey_type']) && $data['survey_type'] !== '' ? $data['survey_type'] : null;
  1866. if (!empty($where)) {
  1867. // 修复:先关联 article 再按 survey_type 过滤,避免查不到数据
  1868. $query = ArticleSurvey::select(
  1869. 'art_id as id',
  1870. Db::raw('MAX(id) as surid'),
  1871. Db::raw('MAX(survey_name) as survey_name'),
  1872. Db::raw('MAX(sur_id) as survey_id')
  1873. )
  1874. ->groupBy('art_id')
  1875. ->where($where)
  1876. ->when(!is_null($survey_type), function ($q) use ($survey_type) {
  1877. $q->whereIn('art_id', function ($sub) use ($survey_type) {
  1878. $sub->select('id')
  1879. ->from('article')
  1880. ->where('survey_type', $survey_type);
  1881. });
  1882. })
  1883. ->with(['article' => function ($query) {
  1884. $query->select('id', 'survey_type','created_at','updated_at','created_at');
  1885. }]);
  1886. ;
  1887. }else{
  1888. $query = ArticleSurvey::select(
  1889. 'art_id as id',
  1890. Db::raw('MAX(id) as surid'),
  1891. Db::raw('MAX(survey_name) as survey_name'),
  1892. Db::raw('MAX(sur_id) as survey_id'),
  1893. )
  1894. ->groupBy('art_id')
  1895. ->when(!is_null($survey_type), function ($q) use ($survey_type) {
  1896. $q->whereIn('art_id', function ($sub) use ($survey_type) {
  1897. $sub->select('id')
  1898. ->from('article')
  1899. ->where('survey_type', $survey_type);
  1900. });
  1901. })
  1902. ->with(['article' => function ($query) {
  1903. $query->select('id', 'survey_type','created_at','updated_at','created_at');
  1904. }]);
  1905. }
  1906. $count = $query->get()->count();
  1907. // 简单写法:直接统计分组后的 art_id 数量
  1908. $survey = $query->orderBy('id', 'desc')
  1909. ->limit($data['pageSize'])
  1910. ->offset(($data['page'] - 1) * $data['pageSize'])
  1911. ->get();
  1912. if (empty($survey->toArray())) {
  1913. return Result::error("暂无调查问卷!", 0);
  1914. }
  1915. $survey = array_map(function ($item) {
  1916. if (isset($item['article'])) {
  1917. $item['survey_type'] = $item['article']['survey_type'];
  1918. $item['created_at'] = $item['article']['created_at'];
  1919. $item['updated_at'] = $item['article']['updated_at'];
  1920. } else {
  1921. // 处理article为null的情况,设置默认值
  1922. $item['survey_type'] = null;
  1923. $item['created_at'] = null;
  1924. $item['updated_at'] = null;
  1925. }
  1926. unset($item['article']);
  1927. return $item;
  1928. }, $survey->toArray());
  1929. $result = [
  1930. 'rows' => $survey,
  1931. 'count' => $count,
  1932. ];
  1933. return Result::success($result);
  1934. }
  1935. /**
  1936. * 后端-获取网站调查问卷详情
  1937. * @param array $data
  1938. * @return array
  1939. */
  1940. public function getSurveyInfo(array $data): array
  1941. {
  1942. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1943. $where = ['sur_id' => $data['sur_id']];
  1944. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1945. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1946. ->select('article_survey.*', 'article.survey_type')
  1947. ->get()->all();
  1948. if (empty($choose)) {
  1949. return Result::error("此调查问卷不存在", 0);
  1950. }
  1951. $resultsArray = array_column($choose, 'results');
  1952. $total = array_sum($resultsArray);
  1953. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1954. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1955. // $total = 0;
  1956. if (!empty($other)) {
  1957. $total = $total + $other['results'];
  1958. $other['choice_name'] = '(其他)';
  1959. if (!empty($others)) {
  1960. $other['hasChildren'] = true;
  1961. // array_push($other,['hasChildren','=',true]);
  1962. $other['children'] = $others;
  1963. $other_choices = [$other->toArray()];
  1964. $mer_choice = array_merge($choose, $other_choices);
  1965. $value_choice = array_values($mer_choice);
  1966. } else {
  1967. // return Result::error('1111');
  1968. $other_choices = [$other->toArray()];
  1969. $other_choices = array_merge($choose, $other_choices);
  1970. $value_choice = array_values($other_choices);
  1971. // return Result::success($result);
  1972. }
  1973. } else {
  1974. $value_choice = $choose;
  1975. }
  1976. $result = [
  1977. 'choose' => $value_choice,
  1978. 'total' => $total,
  1979. ];
  1980. }
  1981. return Result::success($result);
  1982. }
  1983. /**
  1984. * 前端-搜索新闻列表
  1985. * @param array $data
  1986. * @return array
  1987. */
  1988. public function selectWebsiteArticle(array $data): array
  1989. {
  1990. $website = Website::where('id', $data['website_id'])->first();
  1991. if (empty($website)) {
  1992. return Result::error("网站不存在", 0);
  1993. }
  1994. // $website_column = $website['column'];
  1995. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1996. $website_column = json_decode($website['website_column_arr_id'], true);
  1997. }
  1998. $website_id = $data['website_id'];
  1999. $categorys = $this->processArticlePro($website_id);
  2000. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  2001. // return Result::success($diff_pid_categoryIds);
  2002. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2003. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2004. }
  2005. // return Result::success(reset($diff_pid_categoryIds) == 0);
  2006. // $cat_1st_arr = $categorys['cat_1st_arr'];
  2007. $catiall = $categorys['catiall'];
  2008. $categoryIds = $categorys['categoryIds'];
  2009. // return Result::success($categoryIds);
  2010. $query = Article::where('status', 1)
  2011. ->whereIn('catid', $categoryIds)
  2012. ->leftJoinSub(function ($query) use ($website_id) {
  2013. $query->from('article_ignore')
  2014. ->where('website_id', $website_id);
  2015. }, 'article_ignore', function ($join) {
  2016. $join->on('article_ignore.article_id', '=', 'article.id');
  2017. })
  2018. ->where(function ($query) {
  2019. $query->whereNull('article_ignore.article_id')
  2020. ->orWhere(function ($subQuery) {
  2021. $subQuery->whereNotNull('article_ignore.article_id')
  2022. ->where('article_ignore.is_ignore', 0)
  2023. ->where(function ($subSubQuery) {
  2024. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2025. ->orWhereNull('article_ignore.c_show_time');
  2026. });
  2027. });
  2028. });
  2029. // ->get()->all();
  2030. // return Result::success($query);
  2031. if (isset($data['cityid']) && !empty($data['cityid'])) {
  2032. $query->whereRaw("JSON_CONTAINS(article.city_arr_id, '" . intval($data['cityid']) . "')");
  2033. }
  2034. if (isset($data['department_id']) && !empty($data['department_id'])) {
  2035. $query->whereRaw("JSON_CONTAINS(article.department_arr_id, '" . intval($data['department_id']) . "')");
  2036. }
  2037. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2038. $query->where('article.title', 'like', '%' . $data['keyword'] . '%');
  2039. }
  2040. // 计算总数
  2041. $count = $query->count();
  2042. // return Result::success($count);
  2043. // 分页查询
  2044. $articles = $query
  2045. ->select(
  2046. 'article.id',
  2047. 'article.title',
  2048. 'article.imgurl',
  2049. 'article.author',
  2050. 'article.updated_at',
  2051. 'article.introduce',
  2052. 'article.islink',
  2053. 'article.linkurl',
  2054. 'article.copyfrom',
  2055. 'article.cat_arr_id',
  2056. 'article.catid',
  2057. 'article.department_arr_id',
  2058. 'article.city_arr_id',
  2059. // 'article_ignore.c_show_time',
  2060. // 'article_ignore.is_ignore'
  2061. )
  2062. ->orderBy("updated_at", "desc")
  2063. ->offset(($data['page'] - 1) * $data['pageSize'])
  2064. ->limit($data['pageSize'])
  2065. ->get();
  2066. // return Result::success($articles);
  2067. foreach ($articles as $k => $v) {
  2068. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  2069. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2070. }
  2071. if (empty($articles)) {
  2072. return Result::error("没有符合条件的资讯数据");
  2073. }
  2074. $result = [
  2075. 'rows' => $articles,
  2076. 'count' => $count,
  2077. ];
  2078. return Result::success($result);
  2079. }
  2080. /**
  2081. * 模块新闻加强版
  2082. * @param array $data
  2083. * @return array
  2084. */
  2085. public function getWebsiteCatidArticle(array $data): array
  2086. {
  2087. $where = [
  2088. 'website_category.category_id' => $data['catid'],
  2089. 'website_category.website_id' => $data['website_id'],
  2090. ];
  2091. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  2092. $child_catnum = $data['child_catnum'] ?? 1;
  2093. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  2094. $childCategoryIds = array_column($category['child'], 'category_id');
  2095. if (empty($childCategoryIds)) {
  2096. return Result::error("暂无子栏目", 0);
  2097. }
  2098. $imgArticles = [];
  2099. $textArticles = [];
  2100. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  2101. // 初始化子分类图片新闻和文字新闻数组
  2102. // 查询所有子级栏目的图文新闻
  2103. $imgArticles = Article::where('catid', $childCategoryIds[0])
  2104. ->where(function ($query) use ($data) {
  2105. $query->where(function ($subQuery) use ($data) {
  2106. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2107. })->orWhereNull("ignore_ids");
  2108. })
  2109. ->where('status', 1)
  2110. ->where('imgurl', '!=', '')
  2111. ->select('*')
  2112. ->orderBy('updated_at', 'desc')
  2113. ->limit($data['child_imgnum'])
  2114. ->get();
  2115. }
  2116. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  2117. // 查询所有子级栏目的文字新闻
  2118. $textArticles = Article::where('catid', $childCategoryIds[0])
  2119. ->where('status', 1)
  2120. ->where(function ($query) use ($data) {
  2121. $query->where(function ($subQuery) use ($data) {
  2122. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2123. })->orWhereNull("ignore_ids");
  2124. })
  2125. ->select('*')
  2126. ->orderBy('updated_at', 'desc')
  2127. ->limit($data['child_textnum'])
  2128. ->get();
  2129. }
  2130. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  2131. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  2132. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  2133. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  2134. return $child;
  2135. }, $category['child']);
  2136. }
  2137. // }
  2138. if (isset($data['img_num']) && !empty($data['img_num'])) {
  2139. $category['img'] = WebsiteCategory::where($where)
  2140. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2141. ->where('article.status', 1)
  2142. ->where('article.imgurl', '!=', '')
  2143. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2144. ->orderBy('article.updated_at', 'desc')
  2145. ->limit($data['img_num'])
  2146. ->get();
  2147. }
  2148. if (isset($data['text_num']) && !empty($data['text_num'])) {
  2149. $category['text'] = WebsiteCategory::where($where)
  2150. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2151. ->where('article.status', 1)
  2152. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2153. ->orderBy('article.updated_at', 'desc')
  2154. ->limit($data['text_num'])
  2155. ->get();
  2156. }
  2157. // $category = $category->get();
  2158. if (empty($category)) {
  2159. return Result::error("查询失败", 0);
  2160. }
  2161. return Result::success($category);
  2162. }
  2163. /**
  2164. * 模块新闻加强plus版
  2165. * @param array $data
  2166. * @return array
  2167. */
  2168. public function getWebsiteAllArticle(array $data): array
  2169. {
  2170. // return Result::success($data);
  2171. $time1 = microtime(true);
  2172. $wetbsite_id = $data['website_id'] ?? 2;
  2173. $data = json_decode($data['id'], true);
  2174. $website = Website::where('id', $wetbsite_id)->first();
  2175. if (empty($website)) {
  2176. return Result::error("网站不存在", 0);
  2177. }
  2178. // return Result::success($website);
  2179. $website_column = $website['website_column_arr_id'] ?? '[]';
  2180. $website_column = json_decode($website_column, true);
  2181. $categorys = $this->processArticlePro($wetbsite_id);
  2182. $cat_1st_arr = $categorys['cat_1st_arr'];
  2183. $catiall = $categorys['catiall'];
  2184. // return Result::success($catiall);
  2185. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2186. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2187. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2188. }
  2189. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  2190. // return Result::success($categorys);
  2191. $parent_category = array_column($data, 'parent');
  2192. $parent_cat = [];
  2193. $child_category = array_column($data, 'child');
  2194. if (!empty($parent_category)) {
  2195. foreach ($parent_category as $key => $value) {
  2196. $arr = array_map('intval', explode(',', $value));
  2197. $parent_cat[$key] = $arr[0] ?? 0;
  2198. $parent_category = $arr[0] ?? 0;
  2199. $article_imgnum = $arr[1] ?? 0;
  2200. $article_textnum = $arr[2] ?? 0;
  2201. if ($parent_category != 0) {
  2202. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2203. // return Result::success($category_arr);
  2204. if ($article_imgnum != 0) {
  2205. $img_article = Article::whereIn('catid', $category_arr)
  2206. ->where('status', 1)
  2207. ->where('imgurl', '!=', '')
  2208. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2209. $query->from('article_ignore')
  2210. ->where('website_id', $wetbsite_id);
  2211. }, 'article_ignore', function ($join) {
  2212. $join->on('article_ignore.article_id', '=', 'article.id');
  2213. })
  2214. ->where(function ($query) {
  2215. $query->whereNull('article_ignore.article_id')
  2216. ->orWhere(function ($subQuery) {
  2217. $subQuery->whereNotNull('article_ignore.article_id')
  2218. ->where('article_ignore.is_ignore', 0)
  2219. ->where(function ($subSubQuery) {
  2220. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2221. ->orWhereNull('article_ignore.c_show_time');
  2222. });
  2223. });
  2224. })
  2225. ->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')
  2226. ->orderBy('updated_at', 'desc')
  2227. ->limit($article_imgnum)
  2228. ->get()->all();
  2229. foreach ($img_article as $k => $v) {
  2230. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2231. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2232. }
  2233. } else {
  2234. $img_article = [];
  2235. }
  2236. if ($article_textnum != 0) {
  2237. $text_article = Article::whereIn('catid', $category_arr)
  2238. ->where('status', 1)
  2239. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2240. $query->from('article_ignore')
  2241. ->where('website_id', $wetbsite_id);
  2242. }, 'article_ignore', function ($join) {
  2243. $join->on('article_ignore.article_id', '=', 'article.id');
  2244. })
  2245. ->where(function ($query) {
  2246. $query->whereNull('article_ignore.article_id')
  2247. ->orWhere(function ($subQuery) {
  2248. $subQuery->whereNotNull('article_ignore.article_id')
  2249. ->where('article_ignore.is_ignore', 0)
  2250. ->where(function ($subSubQuery) {
  2251. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2252. ->orWhereNull('article_ignore.c_show_time');
  2253. });
  2254. });
  2255. })
  2256. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2257. ->orderBy('updated_at', 'desc')
  2258. ->limit($article_textnum)
  2259. ->get()->all();
  2260. foreach ($text_article as $k => $v) {
  2261. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2262. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2263. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2264. }
  2265. } else {
  2266. $text_article = [];
  2267. }
  2268. $catiall[$parent_category]['imgnum'] = $img_article;
  2269. $catiall[$parent_category]['textnum'] = $text_article;
  2270. $parent[$key] = $catiall[$parent_category];
  2271. } else {
  2272. $parent[$key] = '';
  2273. }
  2274. }
  2275. }
  2276. if (!empty($child_category)) {
  2277. foreach ($child_category as $key => $value) {
  2278. $arr = array_map('intval', explode(',', $value));
  2279. $parent_category = $parent_cat[$key];
  2280. $child_category = $arr[0] ?? 0;
  2281. $article_imgnum = $arr[1] ?? 0;
  2282. $article_textnum = $arr[2] ?? 0;
  2283. if ($child_category != 0) {
  2284. $all_childcat = $cat_1st_arr[$parent_category];
  2285. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  2286. // 从 $websiteInfoIndexed 中获取对应的数据
  2287. $info = $websiteInfoIndexed[$v];
  2288. // 返回一个包含所需信息的数组
  2289. return [
  2290. 'alias' => $info->alias,
  2291. 'category_id' => $info->category_id,
  2292. 'aLIas_pinyin' => $info->aLIas_pinyin,
  2293. 'pid' => $info->pid,
  2294. 'type' => $info->type,
  2295. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  2296. 'pinyin' => $info->pinyin,
  2297. ];
  2298. }, $all_childcat);
  2299. if ($article_imgnum != 0) {
  2300. $img_article = Article::where('catid', $child_category)
  2301. ->where('status', 1)
  2302. ->where('imgurl', '!=', '')
  2303. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2304. $query->from('article_ignore')
  2305. ->where('website_id', $wetbsite_id);
  2306. }, 'article_ignore', function ($join) {
  2307. $join->on('article_ignore.article_id', '=', 'article.id');
  2308. })
  2309. ->where(function ($query) {
  2310. $query->whereNull('article_ignore.article_id')
  2311. ->orWhere(function ($subQuery) {
  2312. $subQuery->whereNotNull('article_ignore.article_id')
  2313. ->where('article_ignore.is_ignore', 0)
  2314. ->where(function ($subSubQuery) {
  2315. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2316. ->orWhereNull('article_ignore.c_show_time');
  2317. });
  2318. });
  2319. })
  2320. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2321. ->orderBy('updated_at', 'desc')
  2322. ->limit($article_imgnum)
  2323. ->get()->all();
  2324. foreach ($img_article as $k => $v) {
  2325. // var_dump($v);
  2326. // var_dump($k);
  2327. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2328. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2329. }
  2330. } else {
  2331. $img_article = [];
  2332. }
  2333. if ($article_textnum != 0) {
  2334. $text_article = Article::where('catid', $child_category)
  2335. ->where('status', 1)
  2336. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2337. $query->from('article_ignore')
  2338. ->where('website_id', $wetbsite_id);
  2339. }, 'article_ignore', function ($join) {
  2340. $join->on('article_ignore.article_id', '=', 'article.id');
  2341. })
  2342. ->where(function ($query) {
  2343. $query->whereNull('article_ignore.article_id')
  2344. ->orWhere(function ($subQuery) {
  2345. $subQuery->whereNotNull('article_ignore.article_id')
  2346. ->where('article_ignore.is_ignore', 0)
  2347. ->where(function ($subSubQuery) {
  2348. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2349. ->orWhereNull('article_ignore.c_show_time');
  2350. });
  2351. });
  2352. })
  2353. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2354. ->orderBy('updated_at', 'desc')
  2355. ->limit($article_textnum)
  2356. ->get()->all();
  2357. foreach ($text_article as $k => $v) {
  2358. // var_dump($v);
  2359. // var_dump($k);
  2360. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2361. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2362. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2363. }
  2364. } else {
  2365. $text_article = [];
  2366. }
  2367. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  2368. $catiall[$child_category]['imgnum'] = $img_article;
  2369. $catiall[$child_category]['textnum'] = $text_article;
  2370. $child[$key] = $catiall[$child_category];
  2371. // var_dump($pids);
  2372. } else {
  2373. $child[$key] = '';
  2374. }
  2375. }
  2376. }
  2377. foreach ($parent as $key => $value) {
  2378. $result[$key] = $value;
  2379. if (!empty($child[$key])) {
  2380. // var_dump($child[$key]);
  2381. $result[$key]['child'] = $child[$key];
  2382. // $value[$key]['child'] = $child[$key];
  2383. } else {
  2384. $result[$key]['child'] = [
  2385. "alias" => null,
  2386. "category_id" => null,
  2387. "type" => null,
  2388. "pinyin" => null,
  2389. "all_childcat" => [],
  2390. "imgnum" => [],
  2391. "textnum" => []
  2392. ];
  2393. }
  2394. }
  2395. return Result::success($result);
  2396. }
  2397. /**
  2398. * 辅助方法:获取文章列表
  2399. */
  2400. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  2401. {
  2402. sleep(1);
  2403. $query = Article::where('article.status', 1)
  2404. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  2405. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  2406. ->where(function ($query) use ($website) {
  2407. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  2408. })
  2409. ->leftJoin('website_category', function ($join) use ($website) {
  2410. $join->on('article.catid', '=', 'website_category.category_id')
  2411. ->where('website_category.website_id', '=', $website['website_id']);
  2412. })
  2413. ->select(
  2414. 'article.id',
  2415. 'article.title',
  2416. 'article.imgurl',
  2417. 'article.author',
  2418. 'article.updated_at',
  2419. 'article.introduce',
  2420. 'article.islink',
  2421. 'article.linkurl',
  2422. 'article.copyfrom',
  2423. 'article.cat_arr_id',
  2424. 'article.catid',
  2425. 'website_category.alias as category_name'
  2426. )
  2427. ->orderBy('updated_at', 'desc')
  2428. ->limit($limit);
  2429. // 如果是图片文章,添加图片URL条件
  2430. if ($isImageArticle) {
  2431. $query->where('imgurl', '!=', '');
  2432. } else {
  2433. // 文字文章不需要imgurl字段
  2434. $query->addSelect('article.introduce');
  2435. }
  2436. $articles = $query->get();
  2437. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  2438. }
  2439. /**
  2440. * 乡村网-获取特殊新闻模块
  2441. * @param array $data
  2442. * @return array
  2443. */
  2444. public function getWebsiteArticles(array $data): array
  2445. {
  2446. $website_id = $data['website_id'];
  2447. $website = Website::where('id', $website_id)->first();
  2448. if (empty($website)) {
  2449. return Result::error("网站不存在", 0);
  2450. }
  2451. // return Result::success($website);
  2452. $website_column = $website['website_column_arr_id'] ?? '[]';
  2453. $website_column = json_decode($website_column, true);
  2454. $catids = json_decode($data['id'], true);
  2455. $parent_category = array_column($catids, 'parent');
  2456. if (!empty($parent_category) && is_array($parent_category)) {
  2457. $categorys = $this->processArticlePro($website_id);
  2458. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2459. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2460. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2461. }
  2462. $catiall = $categorys['catiall'];
  2463. $cat_1st_arr = $categorys['cat_1st_arr'];
  2464. // return Result::success($categorys);
  2465. foreach ($parent_category as $key => $value) {
  2466. $arr = array_map('intval', explode(',', $value));
  2467. $parent_category = $arr[0] ?? 0;
  2468. $article_imgnum = $arr[1] ?? 0;
  2469. $article_textnum = $arr[2] ?? 0;
  2470. if ($parent_category != 0) {
  2471. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2472. // return Result::success($category_arr);
  2473. if ($article_imgnum != 0) {
  2474. $img_article = Article::whereIn('article.catid', $category_arr)
  2475. ->where('article.status', 1)
  2476. ->where('article.imgurl', '!=', '')
  2477. ->leftJoinSub(function ($query) use ($website_id) {
  2478. $query->from('article_ignore')
  2479. ->where('website_id', $website_id);
  2480. }, 'article_ignore', function ($join) {
  2481. $join->on('article_ignore.article_id', '=', 'article.id');
  2482. })
  2483. ->where(function ($query) {
  2484. $query->whereNull('article_ignore.article_id')
  2485. ->orWhere(function ($subQuery) {
  2486. $subQuery->whereNotNull('article_ignore.article_id')
  2487. ->where('article_ignore.is_ignore', 0)
  2488. ->where(function ($subSubQuery) {
  2489. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2490. ->orWhereNull('article_ignore.c_show_time');
  2491. });
  2492. });
  2493. })
  2494. ->select(
  2495. 'article.id',
  2496. 'article.title',
  2497. 'article.imgurl',
  2498. 'article.author',
  2499. 'article.updated_at',
  2500. 'article.introduce',
  2501. 'article.islink',
  2502. 'article.linkurl',
  2503. 'article.copyfrom',
  2504. 'article.cat_arr_id',
  2505. 'article.catid as category_id'
  2506. )
  2507. ->orderBy('updated_at', 'desc')
  2508. ->limit($article_imgnum)
  2509. ->get()->all();
  2510. foreach ($img_article as $k => $v) {
  2511. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2512. // return Result::success($v);
  2513. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2514. }
  2515. } else {
  2516. $img_article = [];
  2517. }
  2518. if ($article_textnum != 0) {
  2519. $text_article = Article::whereIn('article.catid', $category_arr)
  2520. ->where('article.status', 1)
  2521. ->leftJoinSub(function ($query) use ($website_id) {
  2522. $query->from('article_ignore')
  2523. ->where('website_id', $website_id);
  2524. }, 'article_ignore', function ($join) {
  2525. $join->on('article_ignore.article_id', '=', 'article.id');
  2526. })
  2527. ->where(function ($query) {
  2528. $query->whereNull('article_ignore.article_id')
  2529. ->orWhere(function ($subQuery) {
  2530. $subQuery->whereNotNull('article_ignore.article_id')
  2531. ->where('article_ignore.is_ignore', 0)
  2532. ->where(function ($subSubQuery) {
  2533. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2534. ->orWhereNull('article_ignore.c_show_time');
  2535. });
  2536. });
  2537. })
  2538. ->select(
  2539. 'article.id',
  2540. 'article.title',
  2541. 'article.author',
  2542. 'article.updated_at',
  2543. 'article.introduce',
  2544. 'article.islink',
  2545. 'article.linkurl',
  2546. 'article.copyfrom',
  2547. 'article.cat_arr_id',
  2548. 'article.catid as category_id'
  2549. )
  2550. ->orderBy('updated_at', 'desc')
  2551. ->limit($article_textnum)
  2552. ->get()->all();
  2553. foreach ($text_article as $k => $v) {
  2554. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2555. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2556. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2557. }
  2558. } else {
  2559. $text_article = [];
  2560. }
  2561. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2562. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2563. $parent[$key] = $catiall[$parent_category];
  2564. } else {
  2565. $parent[$key] = [];
  2566. }
  2567. }
  2568. }
  2569. return Result::success($parent);
  2570. }
  2571. // 封装处理商品的路由问题
  2572. function processGoods($goods, $data)
  2573. {
  2574. return $goods->map(function ($good) use ($data) {
  2575. $catid = $good->catid ?? 0;
  2576. // $pinyin = '';
  2577. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2578. if (!empty($category->pid) && $category->pid != 0) {
  2579. $level = json_decode($category->category_arr_id, true);
  2580. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2581. ->whereIn('category_id', $level)
  2582. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2583. ->get(['aLIas_pinyin'])
  2584. ->pluck('aLIas_pinyin')
  2585. ->implode('/');
  2586. } else {
  2587. $pinyin = $category->aLIas_pinyin ?? '';
  2588. }
  2589. if (isset($good->city_id) && !empty($good->city_id)) {
  2590. $city = District::where('id', $good->city_id)->first(['name']);
  2591. $good->city_name = $city->name ?? '';
  2592. }
  2593. // 解析imgurl JSON并取第一条数据
  2594. $imgUrls = json_decode($good->imgurl, true);
  2595. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2596. $good->pinyin = $pinyin;
  2597. return $good;
  2598. });
  2599. }
  2600. /**
  2601. * 获取商城首页-根据栏目id
  2602. * @param array $data
  2603. * @return array
  2604. * */
  2605. function getWebsiteCatidshop(array $data): array
  2606. {
  2607. $input['catid'] = $data['catid'];
  2608. $input['website_id'] = $data['website_id'];
  2609. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2610. $result = array_map(function ($item) use ($input) {
  2611. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2612. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2613. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2614. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2615. if (empty($category) || $category->type != 2) {
  2616. return Result::error("暂无此栏目", 0);
  2617. } else {
  2618. $website['website_id'] = $input['website_id'];
  2619. $goods = Good::where('good.status', 2)
  2620. ->where('good.website_id', $website['website_id'])
  2621. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2622. ->select(
  2623. 'good.id',
  2624. 'good.name',
  2625. 'good.imgurl',
  2626. 'good.description',
  2627. 'good.updated_at',
  2628. 'good.catid',
  2629. 'good.type_id',
  2630. 'good.price',
  2631. 'good.com',
  2632. 'good.level',
  2633. 'good.unit'
  2634. )
  2635. ->orderBy('updated_at', 'desc')
  2636. ->offset($goodStart)
  2637. ->limit($goodNum);
  2638. $all_goods = $goods->get();
  2639. $all_goods = $this->processGoods($all_goods, $website);
  2640. }
  2641. return $all_goods ?? [];
  2642. }
  2643. }, $data);
  2644. return Result::success($result);
  2645. }
  2646. /**
  2647. * 获取商品模块
  2648. * @param array $data
  2649. * @return array
  2650. * */
  2651. public function getWebsiteshop(array $data): array
  2652. {
  2653. $input['id'] = $data['id'];
  2654. $input['website_id'] = $data['website_id'];
  2655. $catid = $data['catid'];
  2656. $data = json_decode($input['id'] ?? '', true) ?? [];
  2657. $result['goods'] = array_map(function ($item) use ($input) {
  2658. // 检查parent元素是否存在且不是undefined
  2659. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2660. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2661. $website = $input['website_id'];
  2662. $query = Good::where('good.status', 2)
  2663. ->where('good.website_id', $website);
  2664. switch ($Levelid) {
  2665. case 1:
  2666. case 2:
  2667. case 3:
  2668. $goods = $query->where(function ($q) use ($Levelid) {
  2669. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2670. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2671. });
  2672. break;
  2673. case 4:
  2674. $goods = $query;
  2675. break;
  2676. case 5:
  2677. $goods = $query->where('type_id', 1);
  2678. break;
  2679. case 6:
  2680. $goods = $query->where('type_id', 2);
  2681. break;
  2682. default:
  2683. return [];
  2684. }
  2685. $all_goods = $goods
  2686. ->select(
  2687. 'good.id',
  2688. 'good.name',
  2689. 'good.imgurl',
  2690. 'good.description',
  2691. 'good.updated_at',
  2692. 'good.catid',
  2693. 'good.type_id',
  2694. 'good.price',
  2695. 'good.level',
  2696. 'good.website_id'
  2697. )
  2698. ->orderBy('updated_at', 'desc')
  2699. ->offset($goodStart)
  2700. ->limit($goodNum)
  2701. ->get();
  2702. $web['website_id'] = $website;
  2703. $all_goods = $this->processGoods($all_goods, $web);
  2704. }
  2705. return $all_goods;
  2706. }, $data);
  2707. $website = $input['website_id'];
  2708. $result['article'] = Article::where(function ($query) use ($website) {
  2709. $query->where(function ($subQuery) use ($website) {
  2710. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2711. })->orWhereNull("ignore_ids");
  2712. })
  2713. ->where('catid', $catid)
  2714. ->where('article.status', 1)
  2715. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2716. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2717. ->orderBy('article.updated_at', 'desc')
  2718. ->first();
  2719. return Result::success($result);
  2720. }
  2721. /**
  2722. * 获取商品分类
  2723. * @param array $data
  2724. * @return array
  2725. * */
  2726. public function getWebsiteshopCat(array $data): array
  2727. {
  2728. $website = $data['website_id'];
  2729. $category = WebsiteCategory::where('website_id', $website)
  2730. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2731. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2732. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2733. ->orderBy('sort')
  2734. ->get();
  2735. $cat = $category->map(function ($item) use ($website) {
  2736. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2737. $pid = $item->pid ?? 0;
  2738. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2739. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2740. ->where('website_id', $website)
  2741. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2742. ->get(['aLIas_pinyin'])
  2743. ->pluck('aLIas_pinyin')
  2744. ->implode('/');
  2745. } else {
  2746. $pinyin = $item->aLIas_pinyin ?? '';
  2747. }
  2748. $item->pinyin = $pinyin;
  2749. });
  2750. if (empty($category)) {
  2751. return Result::error("栏目查询失败", 0);
  2752. }
  2753. $cat_tree = Result::buildMenuTree($category);
  2754. $web['website_id'] = $website;
  2755. $goods = Good::where('website_id', $website)
  2756. ->where('status', 2)
  2757. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2758. ->latest('updated_at')
  2759. ->offset(($data['page'] - 1) * $data['pageSize'])
  2760. ->limit($data['pageSize'])
  2761. ->get();
  2762. if (!empty($goods)) {
  2763. if ($goods->count() > 1 && !empty($goods)) {
  2764. $goods = $this->processGoods($goods, $web);
  2765. }
  2766. } else {
  2767. $goods = [];
  2768. }
  2769. $result = [
  2770. 'category' => $cat_tree,
  2771. 'goods' => $goods,
  2772. ];
  2773. // $resul['goods'] = $goods;
  2774. if (empty($result)) {
  2775. return Result::error("查询失败", 0);
  2776. }
  2777. return Result::success($result);
  2778. }
  2779. /*
  2780. * 获取商品列表
  2781. * @param array $data
  2782. * @return array
  2783. * */
  2784. public function getWebsiteshopList(array $data): array
  2785. {
  2786. // return Result::success($data);
  2787. $where = [
  2788. 'status' => 2,
  2789. 'website_id' => $data['website_id'],
  2790. ];
  2791. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2792. // return Result::error("查询失败", 0);
  2793. // }
  2794. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2795. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2796. $data['catid'] = $category->category_id ?? 0;
  2797. }
  2798. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2799. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2800. }
  2801. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2802. array_push($where, ['type_id', $data['type_id']]);
  2803. }
  2804. $query = Good::where($where)
  2805. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2806. $query->where(function ($q) use ($data) {
  2807. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2808. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2809. });
  2810. })
  2811. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2812. $query->where(function ($q) use ($data) {
  2813. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2814. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2815. });
  2816. })
  2817. ->select(
  2818. 'good.id',
  2819. 'good.name',
  2820. 'good.imgurl',
  2821. 'good.description',
  2822. 'good.updated_at',
  2823. 'good.com',
  2824. 'good.catid',
  2825. 'good.type_id',
  2826. 'good.website_id',
  2827. 'good.cat_arr_id',
  2828. 'good.created_at',
  2829. 'good.city_id'
  2830. )
  2831. ->latest('updated_at');
  2832. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2833. $result['count'] = $query->clone()->count();
  2834. $result['goods'] = $this->processGoods(
  2835. $query->clone()
  2836. ->offset(($data['page'] - 1) * $data['pageSize'])
  2837. ->limit($data['pageSize'])
  2838. ->get(),
  2839. $data
  2840. );
  2841. } else {
  2842. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2843. // 获取 type_id 为 1 的数据
  2844. $result['type1'] = $this->processGoods(
  2845. $query->clone()
  2846. ->where('type_id', 1)
  2847. ->offset(($data['page'] - 1) * $data['pageSize'])
  2848. ->limit($data['pageSize'])
  2849. ->get(),
  2850. $data
  2851. );
  2852. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2853. // 获取 type_id 为 2 的数据
  2854. $result['type2'] = $this->processGoods(
  2855. $query->clone()
  2856. ->where('type_id', 2)
  2857. ->offset(($data['page'] - 1) * $data['pageSize'])
  2858. ->limit($data['pageSize'])
  2859. ->get(),
  2860. $data
  2861. );
  2862. }
  2863. if (empty($result)) {
  2864. return Result::error("查询失败", 0);
  2865. }
  2866. return Result::success($result);
  2867. }
  2868. /**
  2869. * 获取商品详情
  2870. * @param array $data
  2871. * @return array
  2872. * */
  2873. public function getWebsiteshopInfo(array $data): array
  2874. {
  2875. $where = [
  2876. 'good.status' => 2,
  2877. 'good.website_id' => $data['website_id'],
  2878. 'good.id' => $data['id'],
  2879. ];
  2880. $goods = Good::where($where)
  2881. ->where('good.id', $data['id'])
  2882. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2883. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2884. ->first();
  2885. if (empty($goods)) {
  2886. return Result::error("查询失败", 0);
  2887. }
  2888. $goods->imgurl = json_decode($goods->imgurl, true);
  2889. return Result::success($goods);
  2890. }
  2891. /**
  2892. * plus pro 处理文章路由问题
  2893. */
  2894. function processArticlePro($website_id)
  2895. {
  2896. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2897. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2898. // // 取出category_id 对应的aLIas_pinyin
  2899. // $categoryIds = array_column($categorys, 'category_id');
  2900. // $categoryPIds = array_column($categorys, 'pid');
  2901. // $aliasPinyins = array_column($categorys, 'path');
  2902. // $alias = array_column($categorys, 'alias');
  2903. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2904. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2905. // // return Result::success($cat_arr);
  2906. // // $catiall = [];
  2907. // //一级所有子级的记录
  2908. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2909. // return [
  2910. // 'cat_1st_arr' => $cat_alias_arr,
  2911. // 'catiall' => $cat_arr,
  2912. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2913. // 'categoryIds' => $categoryIds,
  2914. // ];
  2915. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2916. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2917. // 取出category_id 对应的aLIas_pinyin
  2918. $categoryIds = array_column($categorys, 'category_id');
  2919. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
  2920. return $pid != 0;
  2921. })));
  2922. $category_path = array_column($categorys, 'path');
  2923. $cat_arr = array_combine($categoryIds, $category_path);
  2924. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2925. $catiall = [];
  2926. //一级所有子级的记录
  2927. $cat_1st_arr = [];
  2928. foreach ($categorys as $key => $value) {
  2929. // $category_arr_id = json_decode($value->category_arr_id);
  2930. // $pinyin_str = '';
  2931. // // 算出一级 并且算出子级
  2932. if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
  2933. $cat_1st_arr[$value->pid][] = $value->category_id;
  2934. }
  2935. // foreach ($category_arr_id as $k => $v) {
  2936. // $pinyin_str .= $cat_arr[$v] . '/';
  2937. // }
  2938. // $pinyin_str = rtrim($pinyin_str, '/');
  2939. $catiall[$value->category_id]['alias'] = $value->alias;
  2940. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2941. $catiall[$value->category_id]['type'] = $value->type;
  2942. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2943. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2944. }
  2945. return [
  2946. 'cat_1st_arr' => $cat_1st_arr,
  2947. 'catiall' => $catiall,
  2948. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2949. 'categoryIds' => $categoryIds,
  2950. 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
  2951. 'categoryPIds' => $categoryPIds,
  2952. ];
  2953. }
  2954. /**
  2955. * 封装处理文章的路由问题
  2956. * */
  2957. function processArticles($articles, $data)
  2958. {
  2959. // 检查 $articles 是否为数组或可迭代对象
  2960. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2961. return $articles->map(function ($article) use ($data) {
  2962. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2963. $catid = $article->cat_arr_id ?? '';
  2964. }
  2965. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2966. $catid = $article->category_arr_id ?? '';
  2967. }
  2968. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2969. $level = json_decode($catid, true);
  2970. if (!is_array($level)) {
  2971. return $article;
  2972. } else {
  2973. $level = array_map('intval', $level);
  2974. }
  2975. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2976. ->where($data)
  2977. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2978. ->pluck('aLIas_pinyin')
  2979. ->implode('/');
  2980. $article->pinyin = $pinyin ?? '';
  2981. return $article;
  2982. });
  2983. } else {
  2984. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2985. $catid = $articles->cat_arr_id ?? '';
  2986. $level = json_decode($catid, true);
  2987. if (!is_array($level)) {
  2988. return $articles;
  2989. } else {
  2990. $level = array_map('intval', $level);
  2991. }
  2992. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2993. ->where($data)
  2994. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2995. ->pluck('aLIas_pinyin')
  2996. ->implode('/');
  2997. $articles->pinyin = $pinyin ?? '';
  2998. return $articles;
  2999. }
  3000. }
  3001. // 封装处理由问题
  3002. function processJob($job, $data)
  3003. {
  3004. return $job->map(function ($job) use ($data) {
  3005. $category = $job->cat_arr_id ?? '';
  3006. $cityid = $job->city_arr_id ?? '';
  3007. $city = json_decode($cityid, true);
  3008. $pinyin = '';
  3009. $level = json_decode($category, true);
  3010. // 路由
  3011. if (!empty($level) && is_array($level)) {
  3012. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  3013. ->where('website_id', $data['website_id']) // 添加网站ID条件
  3014. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3015. ->get(['aLIas_pinyin'])
  3016. ->pluck('aLIas_pinyin')
  3017. ->implode('/');
  3018. if (empty($pinyin)) {
  3019. $pinyin = $pinyin->aLIas_pinyin ?? '';
  3020. }
  3021. $job->pinyin = $pinyin;
  3022. }
  3023. // 取职位-城市 市??省
  3024. if (!empty($city) && is_array($city)) {
  3025. if (isset($city[1]) && !empty($city[1])) {
  3026. $city = District::where('id', $city[1])->first(['name']);
  3027. $job->city_name = $city->name ?? '';
  3028. } else if (isset($city[0]) && !empty($city[0])) {
  3029. $city = District::where('id', $city[0])->first(['name']);
  3030. $job->city_name = $city->name ?? '';
  3031. } else {
  3032. $job->city_name = '全国';
  3033. }
  3034. }
  3035. // 获取简历最后一级地区
  3036. if (isset($job->city_id) && !empty($job->city_id)) {
  3037. $city = District::where('id', $job->city_id)->first(['name']);
  3038. $job->hunt_cityname = $city->name ?? '';
  3039. }
  3040. // 组合详细地址
  3041. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  3042. $address_id = json_decode($job->address_arr_id, true) ?? [];
  3043. if (is_array($address_id) && !empty($address_id)) {
  3044. $address = District::whereIn('id', $address_id)
  3045. ->orderBy('level', 'asc')
  3046. ->get(['name'])
  3047. ->pluck('name')
  3048. ->implode('');
  3049. // $job->address_name = $address ?? '';
  3050. $job->address_name = ($address ?? '') . ($job->address ?? '');
  3051. }
  3052. }
  3053. // 取行业
  3054. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  3055. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  3056. if (!empty($job->industry)) {
  3057. $query->where('hyid', $job->industry);
  3058. } else if (!empty($job->hy_id)) {
  3059. $query->where('hyid', $job->hy_id);
  3060. } else if (!empty($job->company_hy_id)) {
  3061. $query->where('hyid', $job->company_hy_id);
  3062. } else {
  3063. $query->where('hyid', $job->job_industry);
  3064. }
  3065. })->first(['hyname']);
  3066. $job->hy_name = $hy_name->hyname ?? '';
  3067. }
  3068. // 取职位类别
  3069. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  3070. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  3071. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  3072. $job->zw_name = $zw_name->zwname ?? '';
  3073. }
  3074. // 取具体职位
  3075. 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))) {
  3076. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  3077. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  3078. $job->jtzw_name = $jtzw_name->zwname ?? '';
  3079. }
  3080. // 取工作经验
  3081. if (isset($job->experience) && !empty($job->experience)) {
  3082. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  3083. $job->experience_name = $experience->ename ?? '';
  3084. }
  3085. // 取学历
  3086. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  3087. $education = $job->educational ?? $job->school_education;
  3088. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  3089. $job->education_name = $education->ename ?? '';
  3090. }
  3091. // 语言
  3092. if (isset($job->language) && !empty($job->language)) {
  3093. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  3094. $job->language_name = $language->ename ?? '';
  3095. }
  3096. // 薪资
  3097. if (isset($job->salary) && !empty($job->salary)) {
  3098. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  3099. $job->salary_name = $salary->ename ?? '';
  3100. }
  3101. // 职位性质
  3102. if (isset($job->nature_id) && !empty($job->nature_id)) {
  3103. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  3104. $job->job_nature_name = $job_nature->ename ?? '';
  3105. }
  3106. // 公司规模
  3107. if (isset($job->company_size) && !empty($job->company_size)) {
  3108. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  3109. $job->company_size_name = $company_size->ename ?? '';
  3110. }
  3111. // 公司性质
  3112. if (isset($job->company_nature) && !empty($job->company_nature)) {
  3113. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  3114. $job->company_nature_name = $company_nature->nature_name ?? '';
  3115. }
  3116. // $job->pinyin = $pinyin;
  3117. return $job;
  3118. });
  3119. }
  3120. /**
  3121. * 获取书籍模块
  3122. * @param array $data
  3123. * @return array
  3124. * */
  3125. public function getWebsiteBook(array $data): array
  3126. {
  3127. $input['id'] = $data['id'];
  3128. $input['website_id'] = $data['website_id'];
  3129. // 将 JSON 字符串转换为 PHP 数组
  3130. $data = json_decode($input['id'], true);
  3131. // 使用 array_map 处理每个元素
  3132. $result = array_map(function ($item) use ($input) {
  3133. // 检查parent元素是否存在且不是undefined
  3134. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  3135. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3136. $website = [
  3137. 'website_id' => $input['website_id'],
  3138. ];
  3139. // 查询栏目名称
  3140. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3141. if (empty($category)) {
  3142. $parent_alias = '';
  3143. $parent_pinyin = null;
  3144. $imgBooks = [];
  3145. $textBooks = [];
  3146. } else {
  3147. $parent_alias = $category->alias ?? '';
  3148. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  3149. // 查找子分类ID数组
  3150. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  3151. array_push($childCategoryIds, $parentCatId);
  3152. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  3153. if ($parentImgNum != 0) {
  3154. // 查询图片新闻
  3155. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  3156. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3157. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3158. })
  3159. ->where('book.status', 2)
  3160. ->where('book.img_url', '!=', '')
  3161. ->where('book.website_id', $website['website_id'])
  3162. ->leftJoin('website_category', function ($join) use ($website) {
  3163. $join->on('book.cat_id', '=', 'website_category.category_id')
  3164. ->where('website_category.website_id', '=', $website['website_id']);
  3165. })
  3166. ->select(
  3167. 'book.id',
  3168. 'book.title',
  3169. 'book.img_url',
  3170. 'book.price',
  3171. 'book.market_price',
  3172. 'book.description',
  3173. 'book.cat_id',
  3174. 'book.description',
  3175. 'book.updated_at',
  3176. 'website_category.alias as category_name',
  3177. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3178. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3179. )
  3180. ->orderBy('updated_at', 'desc')
  3181. ->limit($parentImgNum)
  3182. ->get()->all();
  3183. // 查询文字新闻
  3184. }
  3185. if ($parentTextNum != 0) {
  3186. $textBooks = [];
  3187. $textBooks = Book::where(function ($query) use ($parentCatId) {
  3188. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3189. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3190. })
  3191. ->where('book.status', 2)
  3192. ->where('book.website_id', $website['website_id'])
  3193. ->leftJoin('website_category', function ($join) use ($website) {
  3194. $join->on('book.cat_id', '=', 'website_category.category_id')
  3195. ->where('website_category.website_id', '=', $website['website_id']);
  3196. })
  3197. ->select(
  3198. 'book.id',
  3199. 'book.title',
  3200. 'book.img_url',
  3201. 'book.price',
  3202. 'book.market_price',
  3203. 'book.description',
  3204. 'book.cat_id',
  3205. 'book.description',
  3206. 'book.updated_at',
  3207. 'website_category.alias as category_name',
  3208. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3209. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3210. )
  3211. ->orderBy('updated_at', 'desc')
  3212. ->limit($parentTextNum)
  3213. ->get()->all();
  3214. }
  3215. }
  3216. }
  3217. $resultItem = [
  3218. 'alias' => $parent_alias ?? '',
  3219. 'category_id' => $parentCatId ?? 0,
  3220. 'pinyin' => $parent_pinyin ?? null,
  3221. 'imgnum' => $imgBooks ?? [],
  3222. 'textnum' => $textBooks ?? [],
  3223. ];
  3224. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  3225. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  3226. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  3227. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3228. ->get()->all();
  3229. if (!empty($childCategory)) {
  3230. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  3231. // 查询子栏目名称
  3232. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  3233. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3234. ->first();
  3235. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  3236. $childImgArticles = [];
  3237. $childTextArticles = [];
  3238. $resultItem['child'] = [];
  3239. } else {
  3240. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  3241. // 查询子栏目图片新闻
  3242. $childImgArticles = Book::where('cat_id', $childCatId)
  3243. ->where('status', 2)
  3244. ->where('img_url', '!=', '')
  3245. ->where('book.website_id', $website['website_id'])
  3246. ->leftJoin('website_category', function ($join) use ($website) {
  3247. $join->on('book.cat_id', '=', 'website_category.category_id')
  3248. ->where('website_category.website_id', '=', $website['website_id']);
  3249. })
  3250. ->select(
  3251. 'book.id',
  3252. 'book.title',
  3253. 'book.img_url',
  3254. 'book.price',
  3255. 'book.market_price',
  3256. 'book.description',
  3257. 'book.cat_id',
  3258. 'book.description',
  3259. 'book.updated_at',
  3260. DB::raw("'$child_pinyin' as pinyin")
  3261. )
  3262. ->orderBy('updated_at', 'desc')
  3263. ->limit($childImgNum)
  3264. ->get()->all();
  3265. // 查询子栏目文字新闻
  3266. $childTextArticles = Book::where('cat_id', $childCatId)
  3267. ->where('status', 2)
  3268. ->where('book.website_id', $website['website_id'])
  3269. ->leftJoin('website_category', function ($join) use ($website) {
  3270. $join->on('book.cat_id', '=', 'website_category.category_id')
  3271. ->where('website_category.website_id', '=', $website['website_id']);
  3272. })
  3273. ->select(
  3274. 'book.id',
  3275. 'book.title',
  3276. 'book.img_url',
  3277. 'book.price',
  3278. 'book.market_price',
  3279. 'book.description',
  3280. 'book.cat_id',
  3281. 'book.description',
  3282. 'book.updated_at',
  3283. DB::raw("'$child_pinyin' as pinyin")
  3284. )
  3285. ->orderBy('updated_at', 'desc')
  3286. ->limit($childTextNum)
  3287. ->get()->all();
  3288. $resultItem['child'] = [
  3289. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  3290. 'category_id' => $childCatId,
  3291. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  3292. 'all_childcat' => $childCategory,
  3293. 'imgnum' => $childImgArticles,
  3294. 'textnum' => $childTextArticles,
  3295. ];
  3296. }
  3297. }
  3298. } else {
  3299. $resultItem['child'] = [];
  3300. }
  3301. return $resultItem;
  3302. }, $data);
  3303. return Result::success($result);
  3304. }
  3305. /**
  3306. * 获取书刊列表
  3307. * @param array $data
  3308. * @return array
  3309. * */
  3310. public function getWebsiteBookList(array $data): array
  3311. {
  3312. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3313. if (empty($web)) {
  3314. return Result::error("查询失败", 0);
  3315. }
  3316. $catid = $data['id'];
  3317. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  3318. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  3319. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  3320. $category_pinyin = $category ? $category->aLias_pinyin : '';
  3321. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  3322. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  3323. ->where('pid', $category['pid'])
  3324. ->select(
  3325. 'category_id',
  3326. 'alias',
  3327. 'aLIas_pinyin',
  3328. 'pid',
  3329. 'sort',
  3330. 'is_url',
  3331. 'web_url',
  3332. 'seo_title',
  3333. 'seo_keywords',
  3334. 'seo_description',
  3335. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  3336. )
  3337. ->orderBy('sort')
  3338. ->get()->all();
  3339. if (empty($category)) {
  3340. return Result::error("查询失败", 0);
  3341. }
  3342. $query = Book::where('book.status', 2)
  3343. ->where('book.website_id', $data['website_id'])
  3344. ->where('book.cat_id', $catid)
  3345. ->select(
  3346. 'book.id',
  3347. 'book.title',
  3348. 'book.img_url',
  3349. 'book.description',
  3350. 'book.updated_at',
  3351. 'book.cat_id',
  3352. DB::raw("'$pinyin' as pinyin")
  3353. )
  3354. ->orderBy('book.updated_at', 'desc');
  3355. $count = $query->count();
  3356. $query = clone $query;
  3357. $Book = $query
  3358. ->limit($data['pageSize'])
  3359. ->offset(($data['page'] - 1) * $data['pageSize'])
  3360. ->get()->all();
  3361. $result = [
  3362. 'category' => $categorys,
  3363. 'books' => $Book,
  3364. 'count' => $count,
  3365. ];
  3366. // if(empty($result)){
  3367. // return Result::error("查询失败", 0);
  3368. // }
  3369. return Result::success($result);
  3370. }
  3371. /**
  3372. * 获取书刊详情
  3373. * @param array $data
  3374. * @return array
  3375. * */
  3376. public function getWebsiteBookInfo(array $data): array
  3377. {
  3378. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3379. if (empty($web)) {
  3380. return Result::error("查询失败", 0);
  3381. }
  3382. $book = Book::where('status', 2)
  3383. ->where('website_id', $data['website_id'])
  3384. ->where('id', $data['id'])
  3385. ->select(
  3386. 'book.*',
  3387. )
  3388. ->orderBy('updated_at', 'desc')
  3389. ->first();
  3390. if (empty($book)) {
  3391. return Result::error("查询失败", 0);
  3392. }
  3393. // 先查询当前分类的 pid
  3394. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  3395. ->where('category_id', $book['cat_id'])
  3396. ->first(['pid', 'category_id']);
  3397. $query = WebsiteCategory::where('website_id', $data['website_id']);
  3398. if (!empty($carpid)) {
  3399. if ($carpid->pid != 0) {
  3400. $pid = $carpid['pid'];
  3401. // $parent_pinyin = '';
  3402. } else {
  3403. $pid = $carpid['category_id'];
  3404. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  3405. }
  3406. }
  3407. $categorys = $query->where('pid', $pid)
  3408. ->select(
  3409. 'category_id',
  3410. 'alias',
  3411. 'aLIas_pinyin',
  3412. 'pid',
  3413. 'sort',
  3414. 'is_url',
  3415. 'web_url',
  3416. 'category_arr_id as cat_arr_id',
  3417. )
  3418. ->orderBy('sort')
  3419. ->get();
  3420. $category = $this->processArticle($categorys, $data);
  3421. $result = [
  3422. 'category' => $category,
  3423. 'books' => $book,
  3424. ];
  3425. return Result::success($result);
  3426. }
  3427. /**
  3428. * 尝试
  3429. * @param array $data
  3430. * @return array
  3431. * */
  3432. public function test(array $data): array
  3433. {
  3434. $input['id'] = $data['id'];
  3435. $input['website_id'] = $data['website_id'];
  3436. // 将 JSON 字符串转换为 PHP 数组
  3437. $data = json_decode($input['id'], true);
  3438. $result = [];
  3439. $article = $data;
  3440. $result = array_map(function ($item) use ($input) {
  3441. $website = [
  3442. 'website_id' => $input['website_id'],
  3443. ];
  3444. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3445. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3446. $parent = [
  3447. 0 => $category['category_id'] ?? [],
  3448. 1 => $parentImgNum ?? [],
  3449. 2 => $parentTextNum ?? [],
  3450. ];
  3451. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  3452. $child = [];
  3453. $resultItem = [
  3454. // 'alias' => $parent_alias ?? '',
  3455. 'category_id' => $parentCatId ?? 0,
  3456. 'pinyin' => $parentImgNum ?? null,
  3457. 'imgnum' => $parentTextNum ?? [],
  3458. // 'textnum' => $textArticles ?? [],
  3459. ];
  3460. return $parent;
  3461. }, $data);
  3462. return Result::success($result);
  3463. // });
  3464. }
  3465. /**
  3466. * 封装处理文章的路由问题
  3467. * */
  3468. function processArticle($article, $data)
  3469. {
  3470. return $article->map(function ($article) use ($data) {
  3471. $catid = $article->cat_arr_id ?? '';
  3472. $level = json_decode($catid, true);
  3473. $pinyin = '';
  3474. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  3475. if (!empty($level) && is_array($level)) {
  3476. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  3477. ->where('website_id', $data['website_id'])
  3478. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3479. ->get(['aLIas_pinyin'])
  3480. ->pluck('aLIas_pinyin')
  3481. ->implode('/');
  3482. } else {
  3483. $pinyin = '';
  3484. }
  3485. $article->pinyin = $pinyin;
  3486. return $article;
  3487. });
  3488. }
  3489. /**
  3490. * c端-获取招工招聘下拉选框
  3491. * @param array $data
  3492. * @return array
  3493. * */
  3494. public function getWebsiteJobSelect(array $data): array
  3495. {
  3496. $web = Website::where('id', $data['website_id'])->first();
  3497. if (empty($web)) {
  3498. return Result::error("该网站不存在", 0);
  3499. }
  3500. $hy = JobIndustry::get()->all();
  3501. $zw = JobPosition::where('zwpid', 0)->get()->all();
  3502. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  3503. $result = [
  3504. 'hy' => $hy,
  3505. 'zw' => $zw,
  3506. 'jtzw' => $jtzw,
  3507. ];
  3508. if (empty($result)) {
  3509. return Result::error("查询失败", 0);
  3510. }
  3511. return Result::success($result);
  3512. }
  3513. /**
  3514. * c端-获取招工招聘
  3515. * @param array $data
  3516. * @return array
  3517. * */
  3518. public function getWebsiteJob(array $data): array
  3519. {
  3520. $web = Website::where('id', $data['website_id'])->first();
  3521. if (empty($web)) {
  3522. return Result::error("该网站不存在", 0);
  3523. }
  3524. $job_hunting = JobHunting::where('job_hunting.status', 2)
  3525. ->where('job_hunting.website_id', $data['website_id'])
  3526. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3527. $query->where(function ($q) use ($data) {
  3528. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3529. });
  3530. })
  3531. ->select(
  3532. 'job_hunting.id',
  3533. 'job_hunting.catid',
  3534. 'job_hunting.cat_arr_id',
  3535. 'job_hunting.job_name_get',
  3536. 'job_hunting.industry',
  3537. 'job_hunting.name',
  3538. 'job_hunting.sexy',
  3539. 'job_hunting.origin',
  3540. 'job_hunting.city_arr_id',
  3541. 'job_hunting.experience',
  3542. 'job_hunting.updated_at',
  3543. 'job_hunting.salary',
  3544. 'job_hunting.skillList',
  3545. 'job_hunting.slelf_evaluation',
  3546. )
  3547. ->orderBy('updated_at', 'desc')
  3548. ->limit($data['job1_num'])
  3549. ->get();
  3550. $web['website_id'] = $data['website_id'];
  3551. if (empty($job_hunting)) {
  3552. $job_huntings = "未查询到相关简历信息";
  3553. } else {
  3554. $job_huntings = $this->processJob($job_hunting, $web);
  3555. }
  3556. // 0:待审核 1:已通过 2:已拒绝
  3557. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3558. ->where('job_recruiting.website_id', $data['website_id'])
  3559. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3560. $query->where(function ($q) use ($data) {
  3561. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3562. });
  3563. })
  3564. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3565. ->select(
  3566. 'job_recruiting.id',
  3567. 'job_recruiting.catid',
  3568. 'job_recruiting.cat_arr_id',
  3569. 'job_recruiting.title',
  3570. 'job_recruiting.jtzw_id',
  3571. 'job_recruiting.hy_id',
  3572. 'job_recruiting.city_arr_id',
  3573. 'job_recruiting.due_data',
  3574. 'job_recruiting.updated_at',
  3575. 'job_recruiting.experience',
  3576. 'job_recruiting.educational',
  3577. 'job_recruiting.salary',
  3578. 'job_recruiting.zw_id',
  3579. 'job_company.business_name',
  3580. 'job_recruiting.keyword',
  3581. 'job_recruiting.description',
  3582. )
  3583. ->orderBy('updated_at', 'desc')
  3584. ->limit($data['job2_num'])
  3585. ->get();
  3586. if (empty($job_recruiting->toArray())) {
  3587. $job_recruitings = "未查询到相关职位信息";
  3588. } else {
  3589. $job_recruitings = $this->processJob($job_recruiting, $web);
  3590. }
  3591. $result = [
  3592. 'job_hunting' => $job_huntings,
  3593. 'job_recuiting' => $job_recruitings,
  3594. ];
  3595. return Result::success($result);
  3596. }
  3597. /**
  3598. * c端-获取招工招聘列表
  3599. * @param array $data
  3600. * @return array
  3601. * */
  3602. public function getWebsiteJobList(array $data): array
  3603. {
  3604. $recruit_where = [];
  3605. $hunt_where = [];
  3606. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3607. if (empty($web)) {
  3608. return Result::error("此网站不存在", 0);
  3609. }
  3610. $website_id['website_id'] = $data['website_id'];
  3611. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3612. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3613. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3614. }
  3615. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3616. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3617. }
  3618. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3619. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3620. }
  3621. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3622. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3623. }
  3624. $query = JobRecruiting::where('job_recruiting.status', 1)
  3625. ->where('job_recruiting.website_id', $data['website_id'])
  3626. ->where($recruit_where)
  3627. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3628. $query->where(function ($q) use ($data) {
  3629. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3630. });
  3631. })
  3632. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3633. $query->where(function ($q) use ($data) {
  3634. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3635. });
  3636. })
  3637. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3638. ->select(
  3639. 'job_recruiting.id',
  3640. 'job_recruiting.catid',
  3641. 'job_recruiting.hy_id',
  3642. 'job_recruiting.title',
  3643. 'job_recruiting.zw_id',
  3644. 'job_recruiting.educational',
  3645. 'job_recruiting.jtzw_id',
  3646. 'job_recruiting.city_arr_id',
  3647. 'job_recruiting.due_data',
  3648. 'job_recruiting.experience',
  3649. 'job_recruiting.cat_arr_id',
  3650. 'job_recruiting.updated_at',
  3651. 'job_company.business_name',
  3652. 'job_recruiting.keyword',
  3653. 'job_recruiting.description',
  3654. )
  3655. ->orderBy('job_recruiting.updated_at', 'desc');
  3656. $recruit_count = $query->count();
  3657. $query = clone $query;
  3658. $JobRecruiting = $query
  3659. ->offset(($data['page'] - 1) * $data['pageSize'])
  3660. ->limit($data['pageSize'])
  3661. ->get();
  3662. if (empty($JobRecruiting)) {
  3663. $JobRecruiting = "暂无相关职位信息";
  3664. } else {
  3665. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3666. }
  3667. }
  3668. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3669. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3670. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3671. }
  3672. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3673. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3674. }
  3675. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3676. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3677. }
  3678. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3679. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3680. }
  3681. $query = JobHunting::where('job_hunting.status', 2)
  3682. ->where('job_hunting.website_id', $data['website_id'])
  3683. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3684. ->where($hunt_where)
  3685. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3686. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3687. // })
  3688. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3689. $query->where(function ($q) use ($data) {
  3690. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3691. });
  3692. })
  3693. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3694. $query->where(function ($q) use ($data) {
  3695. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3696. });
  3697. })
  3698. ->select(
  3699. 'job_hunting.id',
  3700. 'job_hunting.catid',
  3701. 'job_hunting.sexy',
  3702. 'job_hunting.experience',
  3703. 'job_hunting.origin',
  3704. 'job_hunting.industry',
  3705. 'job_hunting.name',
  3706. 'job_hunting.job',
  3707. 'job_hunting.job_name_get',
  3708. 'job_hunting.city_arr_id',
  3709. 'job_hunting.cat_arr_id',
  3710. 'job_hunting.created_at',
  3711. 'job_hunting.updated_at',
  3712. 'job_position.zwname as job_name',
  3713. 'job_hunting.skillList',
  3714. 'job_hunting.slelf_evaluation',
  3715. )
  3716. ->orderBy('job_hunting.updated_at', 'desc');
  3717. $hunt_count = $query->count();
  3718. $query = clone $query;
  3719. $JobHunting = $query
  3720. ->offset(($data['page'] - 1) * $data['pageSize'])
  3721. ->limit($data['pageSize'])
  3722. ->get();
  3723. if (empty($JobHunting)) {
  3724. $JobRecruiting = "暂无相关简历信息";
  3725. } else {
  3726. $JobHunting = $this->processJob($JobHunting, $website_id);
  3727. }
  3728. }
  3729. $result = [
  3730. 'JobRecruiting' => $JobRecruiting ?? [],
  3731. 'recruit_count' => $recruit_count ?? 0,
  3732. 'JobHunting' => $JobHunting ?? [],
  3733. 'hunt_count' => $hunt_count ?? 0,
  3734. ];
  3735. return Result::success($result);
  3736. }
  3737. /**
  3738. * c端-获取招工招聘详情
  3739. * @param array $data
  3740. * @return array
  3741. * */
  3742. public function getWebsiteJobInfo(array $data): array
  3743. {
  3744. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3745. if (empty($web)) {
  3746. return Result::error("该网站不存在", 0);
  3747. }
  3748. $webid = [
  3749. 'website_id' => $data['website_id'],
  3750. ];
  3751. // 职位相关信息
  3752. if ($data['type'] == 1) {
  3753. $query = JobRecruiting::where('status', 1)
  3754. ->where('website_id', $data['website_id'])
  3755. ->select('*');
  3756. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3757. $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();
  3758. if (!empty($company)) {
  3759. $result['company'] = $this->processJob($company, $webid);
  3760. }
  3761. $other_job = JobRecruiting::where('status', 1)
  3762. ->where('website_id', $data['website_id'])
  3763. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3764. ->where('id', '!=', $data['id'])
  3765. ->where('user_id', '=', $job[0]['user_id'])
  3766. ->limit($data['pageSize'])
  3767. ->get();
  3768. if (!empty($other_job)) {
  3769. $result['other_job'] = $this->processJob($other_job, $webid);
  3770. }
  3771. } else {
  3772. // 简历相关信息
  3773. $job = JobHunting::where('job_hunting.status', 2)
  3774. ->where('job_hunting.website_id', $data['website_id'])
  3775. ->where('job_hunting.id', $data['id'])
  3776. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3777. ->select('job_hunting.*', 'user_name')
  3778. ->get();
  3779. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3780. if (!empty($resume->toArray())) {
  3781. $result['resume'] = 1;
  3782. } else {
  3783. $result['resume'] = 0;
  3784. }
  3785. }
  3786. if (empty($job->toArray())) {
  3787. return Result::error("id参数错误", 0);
  3788. }
  3789. if (!empty($job[0]['job_experience'])) {
  3790. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3791. if (!empty($job_experience)) {
  3792. // $hy = [];
  3793. foreach ($job_experience as $key => $value) {
  3794. // $id = $value['id'];
  3795. $hy[$key] = $value['job_industry'];
  3796. $zw_id[$key] = $value['job_typename'];
  3797. $jtzw_id[$key] = $value['job_name'];
  3798. }
  3799. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3800. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3801. // 先将关联表转换为索引数组,提高查找效率
  3802. $hyLookup = [];
  3803. foreach ($hy_table as $item) {
  3804. $hyLookup[$item['hyid']] = $item['hyname'];
  3805. }
  3806. $zwLookup = [];
  3807. foreach ($zw_table as $item) {
  3808. $zwLookup[$item['zwid']] = $item['zwname'];
  3809. }
  3810. foreach ($job_experience as $key => &$value) {
  3811. // 处理行业名称
  3812. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3813. $value['hy_name'] = $hyLookup[$hy[$key]];
  3814. }
  3815. // 处理职位名称
  3816. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3817. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3818. }
  3819. // 处理具体职位名称
  3820. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3821. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3822. }
  3823. }
  3824. // 释放引用,防止意外修改后续代码
  3825. unset($value);
  3826. }
  3827. $result['job_experience'] = $job_experience ?? [];
  3828. }
  3829. if (!empty($job[0]['education_experience'])) {
  3830. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3831. if (!empty($education_experience)) {
  3832. foreach ($education_experience as $key => $value) {
  3833. // $id = $value['id'];
  3834. $education[$key] = $value['school_education'];
  3835. }
  3836. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3837. // // 先将关联表转换为索引数组,提高查找效率
  3838. $educationLookup = [];
  3839. foreach ($education_table as $item) {
  3840. $educationLookup[$item['evalue']] = $item['ename'];
  3841. }
  3842. foreach ($education_experience as $key => &$value) {
  3843. // 处理学历名称
  3844. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3845. $value['education_name'] = $educationLookup[$education[$key]];
  3846. }
  3847. }
  3848. }
  3849. $result['education_experience'] = $job_experience ?? [];
  3850. }
  3851. $result['job'] = $this->processJob($job, $webid);
  3852. // // 返现对应的栏目
  3853. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3854. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3855. ->whereIn('category_id', $catid)
  3856. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3857. ->orderBy('pid')->get()->all();
  3858. if (!empty($category)) {
  3859. $result['category'] = $category;
  3860. }
  3861. $result['job'] = $job;
  3862. $result['job_experience'] = $job_experience ?? [];
  3863. $result['education_experience'] = $education_experience ?? [];
  3864. if (empty($result)) {
  3865. return Result::error("参数错误", 0);
  3866. }
  3867. return Result::success($result);
  3868. }
  3869. /**
  3870. * c端-申请职位
  3871. * @param array $data
  3872. * @return array
  3873. * */
  3874. public function getWebsiteJobApply(array $data): array
  3875. {
  3876. // 首先验证网站是否存在
  3877. // return Result::success($data);
  3878. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3879. if (empty($web)) {
  3880. return Result::error("该网站不存在", 0);
  3881. }
  3882. // 验证用户是否存在且为个人会员/管理员
  3883. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3884. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3885. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3886. return Result::error("用户不存在", 0);
  3887. }
  3888. // 去除重复元素和空元素,并保持原始顺序
  3889. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3890. return !empty($value);
  3891. }));
  3892. // 验证职位是否存在 1:审核通过
  3893. $recruiting = JobRecruiting::where('status', 1)
  3894. ->where('website_id', $data['website_id'])
  3895. ->whereIn('id', $data['recruit_id'])
  3896. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3897. if (empty($recruiting)) {
  3898. return Result::error("该职位不存在", 0);
  3899. }
  3900. // 简历是否存在
  3901. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3902. if (empty($hunt_id)) {
  3903. return Result::error("该简历不存在", 0);
  3904. }
  3905. $data['hunt_id'] = $hunt_id['hunt_id'];
  3906. // // 验证是否已投递过该职位
  3907. $apply = JobApply::where('user_id', $data['user_id'])
  3908. ->where('hunt_id', $data['hunt_id'])
  3909. ->where('website_id', $data['website_id'])
  3910. ->whereIn('recruit_id', $data['recruit_id'])
  3911. ->get(['recruit_id']);
  3912. if (!empty($apply->toArray())) {
  3913. return Result::error("您已投递过该职位!");
  3914. }
  3915. $insertData = array_map(function ($recruiting) use ($data) {
  3916. return [
  3917. 'user_id' => $data['user_id'],
  3918. 'hunt_id' => $data['hunt_id'],
  3919. 'website_id' => $data['website_id'],
  3920. 'recruit_id' => $recruiting['recruit_id'],
  3921. 'receiver_id' => $recruiting['receiver_id'],
  3922. 'status' => 1,
  3923. ];
  3924. }, $recruiting);
  3925. // 批量插入数据
  3926. $result = JobApply::insert($insertData);
  3927. if (empty($result)) {
  3928. return Result::error("投递失败", 0);
  3929. }
  3930. return Result::success($result);
  3931. }
  3932. /**
  3933. * 招工招聘-沟通简历
  3934. * @param array $data
  3935. * @return array
  3936. * */
  3937. public function getWebsiteJobResume(array $data): array
  3938. {
  3939. // 首先验证网站是否存在
  3940. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3941. if (empty($web)) {
  3942. return Result::error("该网站不存在", 0);
  3943. }
  3944. // return Result::success($data);
  3945. // 验证用户是否存在且为企业会员/管理员
  3946. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3947. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3948. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3949. return Result::error("用户不存在", 0);
  3950. }
  3951. // 去除重复元素和空元素,并保持原始顺序
  3952. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3953. return !empty($value);
  3954. }));
  3955. // 验证简历是否存在
  3956. $hunting = JobHunting::where('status', 2)
  3957. ->where('website_id', $data['website_id'])
  3958. ->whereIn('id', $data['hunt_id'])
  3959. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3960. if (empty($hunting)) {
  3961. return Result::error("该简历不存在", 0);
  3962. }
  3963. // 验证是否已沟通过该简历
  3964. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3965. ->where('recruit_id', $data['recruit_id'])
  3966. ->where('website_id', $data['website_id'])
  3967. ->whereIn('hunt_id', $data['hunt_id'])
  3968. ->get(['hunt_id']);
  3969. if (!empty($remuse->toArray())) {
  3970. return Result::error("您已沟通过该简历!");
  3971. }
  3972. // 准备要插入的数据数组
  3973. $insertData = array_map(function ($hunting) use ($data) {
  3974. return [
  3975. 'user_id' => $data['user_id'],
  3976. 'recruit_id' => $data['recruit_id'],
  3977. 'website_id' => $data['website_id'],
  3978. 'hunt_id' => $hunting['hunt_id'],
  3979. 'receiver_id' => $hunting['receiver_id'],
  3980. 'status' => 1,
  3981. ];
  3982. }, $hunting);
  3983. // 批量插入数据
  3984. $result = JobRemuse::insert($insertData);
  3985. if (empty($result)) {
  3986. return Result::error("沟通失败", 0);
  3987. }
  3988. return Result::success($result);
  3989. }
  3990. /**
  3991. * 招工招聘 -我的职位(企业会员)
  3992. * @param array $data
  3993. * @return array
  3994. */
  3995. public function getWebsiteJobRecruiting(array $data): array
  3996. {
  3997. $web = Website::where('id', $data['website_id'])->first('id');
  3998. if (empty($web)) {
  3999. return Result::error("该网站不存在", 0);
  4000. }
  4001. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  4002. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  4003. return Result::error("用户暂无权限!", 0);
  4004. }
  4005. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  4006. $result = JobRecruiting::where('website_id', $data['website_id'])
  4007. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  4008. $query->where('user_id', $user['id']);
  4009. })
  4010. ->where('status', 1)
  4011. ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
  4012. ->orderBy('updated_at', 'desc')
  4013. ->limit($data['pageSize'])
  4014. ->get();
  4015. if (empty($result)) {
  4016. return Result::error("暂无相关职位信息", 0);
  4017. }
  4018. return Result::success($result);
  4019. }
  4020. /**
  4021. * c端 - 验证路由
  4022. * @param array $data
  4023. * @return array
  4024. */
  4025. /**
  4026. * c端 - 验证路由
  4027. * @param array $data
  4028. * @return array
  4029. */
  4030. public function checkWebsiteRoute(array $data): array
  4031. {
  4032. // 测试001111111222
  4033. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  4034. if (empty($web)) {
  4035. return Result::error("该网站不存在", 0);
  4036. } elseif ($web['status'] != 1) {
  4037. return Result::error("网站已经关闭", 0);
  4038. }
  4039. if (isset($data['other_route']) && !empty($data['other_route'])) {
  4040. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  4041. // 验证路由是否存在
  4042. if (empty($whiteRouterInfo)) {
  4043. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  4044. }
  4045. if (!empty($whiteRouterInfo)) {
  4046. return Result::success($whiteRouterInfo->toArray());
  4047. }
  4048. }
  4049. // 验证栏目路由
  4050. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  4051. ->where('path', $data['all_route'])
  4052. ->get()->all();
  4053. if (count($last_category) == 0) {
  4054. return Result::error("该栏目不存在", 0);
  4055. }
  4056. if (count($last_category) > 1) {
  4057. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  4058. }
  4059. if (count($last_category) == 1) {
  4060. $last_category = $last_category[0];
  4061. }
  4062. // return Result::success($last_category);
  4063. if (isset($data['id']) && !empty($data['id'])) {
  4064. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  4065. switch ($last_category['type']) {
  4066. case 1:
  4067. // 文章
  4068. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  4069. $article = Article::where('status', 1)
  4070. ->where('id', $data['id'])
  4071. ->where(function ($query) use ($data) {
  4072. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  4073. ->orWhereNull("ignore_ids");
  4074. })
  4075. ->first(['catid']);
  4076. if (empty($article)) {
  4077. return Result::error("该文章不存在", 0);
  4078. }
  4079. // return Result::success($article);
  4080. break;
  4081. case 2:
  4082. // 商品
  4083. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4084. $article = Good::where('website_id', $data['website_id'])
  4085. ->where('status', 2)
  4086. ->where('id', $data['id'])
  4087. ->first(['cat_arr_id']);
  4088. if (empty($article)) {
  4089. return Result::error("该商品不存在", 0);
  4090. }
  4091. break;
  4092. case 3:
  4093. // 书刊信息
  4094. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4095. $article = Book::where('website_id', $data['website_id'])
  4096. ->where('status', 2)
  4097. ->where('id', $data['id'])
  4098. ->first(['id', 'cat_arr_id']);
  4099. if (empty($article)) {
  4100. return Result::error("该书刊不存在", 0);
  4101. }
  4102. break;
  4103. case 4:
  4104. // 招聘
  4105. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  4106. $article = JobRecruiting::where('website_id', $data['website_id'])
  4107. ->where('status', 1)
  4108. ->where('id', $data['id'])
  4109. ->first(['cat_arr_id']);
  4110. if (empty($article)) {
  4111. return Result::error("该招聘不存在", 0);
  4112. }
  4113. break;
  4114. case 5:
  4115. // 求职
  4116. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4117. $article = JobHunting::where('website_id', $data['website_id'])
  4118. ->where('status', 2)
  4119. ->where('id', $data['id'])
  4120. ->first(['cat_arr_id']);
  4121. if (empty($article)) {
  4122. return Result::error("该求职不存在", 0);
  4123. }
  4124. break;
  4125. case 6:
  4126. // 企业
  4127. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4128. $article = Company::
  4129. // where('website_id', $data['website_id'])
  4130. // ->
  4131. where('status', 1)
  4132. ->where('id', $data['id'])
  4133. ->first(['cat_arr_id']);
  4134. if (empty($article)) {
  4135. return Result::error("该企业不存在", 0);
  4136. }
  4137. break;
  4138. case 7:
  4139. // 项目
  4140. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4141. $article = Project::where('website_id', $data['website_id'])
  4142. ->where('status', 1)
  4143. ->where('id', $data['id'])
  4144. ->first(['cat_arr_id']);
  4145. if (empty($article)) {
  4146. return Result::error("该项目不存在", 0);
  4147. }
  4148. break;
  4149. default:
  4150. return Result::error("该数据不存在", 0);
  4151. break;
  4152. }
  4153. // return Result::success($article);
  4154. // $catid =0 ;
  4155. if (!isset($article['cat_arr_id'])) {
  4156. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  4157. } else {
  4158. $catidArray = json_decode($article['cat_arr_id'], true);
  4159. $catid = !empty($catidArray) ? end($catidArray) : null;
  4160. }
  4161. // return Result::success($catid);
  4162. // // return Result::success($article['cat_arr_id']);
  4163. if (empty($catid)) {
  4164. return Result::error("该栏目路径不存在", 0);
  4165. }
  4166. $path = WebsiteCategory::where('website_id', $data['website_id'])
  4167. ->where('category_id', $catid)
  4168. ->first('path');
  4169. }
  4170. // else{
  4171. // // if ($last_category['pid'] != 0) {
  4172. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  4173. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  4174. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  4175. // ->where('category_id',$catid)
  4176. // ->where('path',$data['all_route'])
  4177. // ->first('path');
  4178. // // } else {
  4179. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  4180. // // }
  4181. // }
  4182. // return Result::success($path);
  4183. if (!empty($path) && $path['path'] != $data['all_route']) {
  4184. return Result::error('非法路径!');
  4185. } else {
  4186. return Result::success($last_category['path']);
  4187. }
  4188. }
  4189. /**
  4190. * 招工招聘 - 获取推荐职位
  4191. * @param array $data
  4192. * @return array
  4193. */
  4194. public function getWebsiteLevelJob(array $data): array
  4195. {
  4196. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  4197. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  4198. ->where('job_recruiting.status', 1)
  4199. ->where('job_level', $data['job_level'])
  4200. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4201. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  4202. ->orderBy('job_recruiting.updated_at', 'desc')
  4203. ->limit($data['pageSize'])
  4204. ->get();
  4205. $web = ['website_id' => $data['website_id']];
  4206. if (!empty($job)) {
  4207. $result = $this->processJob($job, $web);
  4208. }
  4209. if (empty($result)) {
  4210. return Result::error("暂无相关职位信息", 0);
  4211. }
  4212. return Result::success($result);
  4213. }
  4214. /**
  4215. * 验证导航名称是否重复
  4216. * @return void
  4217. */
  4218. //20250226 产品列表
  4219. public function getGoodList(array $data): array
  4220. {
  4221. var_dump($data, '---------1-2--');
  4222. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  4223. unset($data['user_type_id']);
  4224. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4225. $where = [];
  4226. if ($type_id != '10000') {
  4227. $where = [
  4228. 'good.user_id' => $user_id,
  4229. ];
  4230. }
  4231. //类型
  4232. if (isset($data['type_id']) && $data['type_id']) {
  4233. $where['good.type_id'] = $data['type_id'];
  4234. }
  4235. //名称
  4236. if (isset($data['name']) && $data['name']) {
  4237. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  4238. }
  4239. //status
  4240. if (isset($data['status']) && $data['status'] != '') {
  4241. $where['good.status'] = $data['status'];
  4242. }
  4243. //status1
  4244. // if (isset($data['status1']) && $data['status1'] == 1) {
  4245. // $status1 = 1;
  4246. // }
  4247. $where1 = [];
  4248. //website_id
  4249. // if (isset($data['website_id']) && $data['website_id']) {
  4250. // $where1 = [
  4251. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  4252. // ];
  4253. // }
  4254. // website_name
  4255. if (isset($data['website_name']) && $data['website_name']) {
  4256. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  4257. }
  4258. // catid
  4259. if (isset($data['category_name']) && $data['category_name']) {
  4260. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  4261. }
  4262. // $result = Good::where($where)
  4263. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  4264. var_dump($where, '---------1---');
  4265. $result = Good::where($where)
  4266. ->when(!empty($where1), function ($query) use ($where1) {
  4267. return $query->where($where1);
  4268. })
  4269. //status 1待审核2已审核3已拒绝
  4270. ->when(isset($data['status1']), function ($query) {
  4271. return $query->whereIn('good.status', [1, 3]);
  4272. })
  4273. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4274. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4275. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4276. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4277. ->orderBy("updated_at", "desc")
  4278. ->limit($data['page_size'])
  4279. ->offset(($data['page'] - 1) * $data['page_size'])
  4280. ->get();
  4281. $count = Good::where($where)
  4282. ->when(!empty($where1), function ($query) use ($where1) {
  4283. return $query->where($where1);
  4284. })
  4285. //status 1待审核2已审核3已拒绝
  4286. ->when(isset($data['status1']), function ($query) {
  4287. return $query->whereIn('good.status', [1, 3]);
  4288. })
  4289. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4290. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4291. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4292. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4293. ->orderBy("updated_at", "desc")->count();
  4294. $data = [
  4295. 'rows' => $result->toArray(),
  4296. 'count' => $count,
  4297. ];
  4298. if (empty($result)) {
  4299. return Result::error("此栏目暂无相关产品", 0);
  4300. }
  4301. return Result::success($data);
  4302. }
  4303. public function getGoodInfo(array $data): array
  4304. {
  4305. $result = Good::where('id', $data['id'])->first();
  4306. if (empty($result)) {
  4307. return Result::error("此产品不存在", 0);
  4308. }
  4309. return Result::success($result);
  4310. }
  4311. public function addGood(array $data): array
  4312. {
  4313. // unset($data['city_arr_id']);
  4314. // unset($data['cat_arr_id']);
  4315. $data['city_id'] = end($data['city_arr_id']);
  4316. $data['catid'] = end($data['cat_arr_id']);
  4317. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4318. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4319. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4320. unset($data['imgUrl']); //大小写
  4321. if (isset($data['price']) && $data['price'] == '') {
  4322. $data['price'] = 0;
  4323. }
  4324. if ($data['imgurl'] == '') {
  4325. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4326. preg_match_all($reg, $data['detail'], $matches);
  4327. if (isset($matches[1][0])) {
  4328. //截取varchar240
  4329. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4330. }
  4331. }
  4332. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4333. //提取标题+内容中的关键词
  4334. $data['keyword'] = $data['name'];
  4335. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4336. Jieba::init(); // 初始化 jieba-php
  4337. Finalseg::init();
  4338. $segList = Jieba::cut($data['keyword']);
  4339. $segList1 = array_slice($segList, 0, 8);
  4340. $data['keyword'] = implode(',', $segList1);
  4341. }
  4342. if ($data['description'] == '') {
  4343. //提取内容中的描述
  4344. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4345. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4346. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4347. }
  4348. if ($data['status'] == 1) {
  4349. $this->sendMessage([
  4350. 'talk_type' => 200,
  4351. 'title' => $data['name'],
  4352. 'content' => '提交了审核',
  4353. 'messageType' => 3,
  4354. ]);
  4355. }
  4356. $result = Good::insert($data);
  4357. if (empty($result)) {
  4358. return Result::error("添加失败", 0);
  4359. }
  4360. return Result::success($result);
  4361. }
  4362. public function updateGood(array $data): array
  4363. {
  4364. $data['city_id'] = end($data['city_arr_id']);
  4365. $data['catid'] = end($data['cat_arr_id']);
  4366. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4367. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4368. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4369. //设置东八区
  4370. date_default_timezone_set('Asia/Shanghai');
  4371. $data['updated_at'] = date('Y-m-d H:i:s');
  4372. if (isset($data['price']) && $data['price'] == '') {
  4373. $data['price'] = 0;
  4374. }
  4375. if ($data['imgurl'] == '') {
  4376. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4377. preg_match_all($reg, $data['detail'], $matches);
  4378. if (isset($matches[1][0])) {
  4379. //截取varchar240
  4380. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4381. }
  4382. }
  4383. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4384. //提取标题+内容中的关键词
  4385. $data['keyword'] = $data['name'];
  4386. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4387. Jieba::init(); // 初始化 jieba-php
  4388. Finalseg::init();
  4389. $segList = Jieba::cut($data['keyword']);
  4390. $segList1 = array_slice($segList, 0, 8);
  4391. $data['keyword'] = implode(',', $segList1);
  4392. }
  4393. if ($data['description'] == '') {
  4394. //提取内容中的描述
  4395. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4396. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4397. }
  4398. if ($data['status'] == 1) {
  4399. $this->sendMessage([
  4400. 'talk_type' => 200,
  4401. 'title' => $data['name'],
  4402. 'content' => '提交了审核',
  4403. 'messageType' => 3,
  4404. ]);
  4405. }
  4406. $result = Good::where('id', $data['id'])->update($data);
  4407. if (empty($result)) {
  4408. return Result::error("更新失败", 0);
  4409. }
  4410. return Result::success($result);
  4411. }
  4412. public function delGood(array $data): array
  4413. {
  4414. $result = Good::where('id', $data['id'])->delete();
  4415. if (empty($result)) {
  4416. return Result::error("删除失败", 0);
  4417. }
  4418. return Result::success($result);
  4419. }
  4420. //20250226 产品列表
  4421. //20250306 求职信息
  4422. public function getJobHuntingList(array $data): array
  4423. {
  4424. $where = [];
  4425. if (isset($data['username']) && !empty($data['username'])) {
  4426. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4427. }
  4428. //status 1待审核2已审核3已拒绝
  4429. if (isset($data['status']) && $data['status'] != '') {
  4430. $where = [
  4431. 'job_hunting.status' => $data['status'],
  4432. ];
  4433. }
  4434. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4435. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4436. unset($data['type_id']);
  4437. if ($type_id != '10000') {
  4438. $where[] = ['job_hunting.user_id', '=', $user_id];
  4439. }
  4440. $result = JobHunting::where($where)
  4441. ->when(!empty($data['status1']), function ($query) use ($data) {
  4442. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4443. })
  4444. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4445. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4446. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  4447. ->orderBy("updated_at", "desc")
  4448. ->limit($data['page_size'])
  4449. ->offset(($data['page'] - 1) * $data['page_size'])
  4450. ->get();
  4451. if (empty($result)) {
  4452. return Result::error("查询失败", 0);
  4453. }
  4454. $count = JobHunting::where($where)
  4455. ->when(!empty($data['status1']), function ($query) use ($data) {
  4456. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4457. })
  4458. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4459. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4460. ->count();
  4461. $data = [
  4462. 'rows' => $result->toArray(),
  4463. 'count' => $count,
  4464. ];
  4465. return Result::success($data);
  4466. }
  4467. public function getJobHuntingApply(array $data): array
  4468. {
  4469. var_dump($data, '-----------------test--------1-');
  4470. $where = [];
  4471. if (isset($data['username']) && !empty($data['username'])) {
  4472. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4473. }
  4474. if (isset($data['salary']) && !empty($data['salary'])) {
  4475. $where[] = [
  4476. 'job_hunting.salary',
  4477. '=',
  4478. $data['salary'],
  4479. ];
  4480. }
  4481. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4482. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4483. unset($data['type_id']);
  4484. if ($type_id != '10000') {
  4485. $where[] = ['job_apply.receiver_id', '=', $user_id];
  4486. }
  4487. var_dump($where, '-----------------test---------');
  4488. $result = jobApply::where($where)
  4489. // ->when(!empty($data['status1']), function ($query) use ($data) {
  4490. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4491. // })
  4492. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  4493. ->where('job_enum.egroup', '=', 'income')
  4494. ->where('job_hunting.status', 2) //已审核
  4495. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4496. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4497. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4498. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4499. //职位----是申请职位
  4500. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4501. ->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')
  4502. ->orderBy("job_hunting.updated_at", "desc")
  4503. ->limit($data['page_size'])
  4504. ->offset(($data['page'] - 1) * $data['page_size'])
  4505. ->get();
  4506. if (empty($result)) {
  4507. return Result::error("查询失败", 0);
  4508. }
  4509. $count = jobApply::where($where)
  4510. ->where('job_enum.egroup', '=', 'income')
  4511. ->where('job_hunting.status', 2) //已审核
  4512. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4513. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4514. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4515. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4516. //职位----是申请职位
  4517. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4518. ->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')
  4519. ->count();
  4520. $data = [
  4521. 'rows' => $result->toArray(),
  4522. 'count' => $count,
  4523. ];
  4524. return Result::success($data);
  4525. }
  4526. public function addJobHunting(array $data): array
  4527. {
  4528. date_default_timezone_set('Asia/Shanghai');
  4529. unset($data['company_name']);
  4530. unset($data['job_industry']);
  4531. unset($data['job_name']);
  4532. unset($data['department']);
  4533. unset($data['job_timeList']);
  4534. unset($data['job_content']);
  4535. unset($data['job_typename']); //不知道这是啥,
  4536. $data['created_at'] = date('Y-m-d H:i:s');
  4537. $data['updated_at'] = date('Y-m-d H:i:s');
  4538. //根据用户 user_id 只能添加一次
  4539. $result = JobHunting::where('user_id', $data['user_id'])->first();
  4540. if (!empty($result)) {
  4541. return Result::error("您已添加过求职信息", 0);
  4542. }
  4543. var_dump($result, '-----------------test---------');
  4544. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  4545. if (is_string($data['city_arr_id'])) {
  4546. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4547. $cityArr = json_decode($data['city_arr_id'], true);
  4548. // 确保 $cityArr 是数组
  4549. if (is_array($cityArr)) {
  4550. $data['city_id'] = end($cityArr);
  4551. }
  4552. } else {
  4553. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4554. if (is_array($data['city_arr_id'])) {
  4555. $data['city_id'] = end($data['city_arr_id']);
  4556. }
  4557. }
  4558. }
  4559. // 处理求职所绑定栏目
  4560. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4561. if (is_string($data['cat_arr_id'])) {
  4562. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4563. // 先清理可能存在的无效 JSON 字符
  4564. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4565. $catArr = json_decode($cleanedCatArrStr, true);
  4566. // 检查 JSON 解码是否成功且结果是数组
  4567. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4568. $data['catid'] = end($catArr);
  4569. }
  4570. } else {
  4571. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4572. if (is_array($data['cat_arr_id'])) {
  4573. $data['catid'] = end($data['cat_arr_id']);
  4574. }
  4575. }
  4576. }
  4577. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4578. $this->sendMessage([
  4579. 'talk_type' => 600,
  4580. 'title' => $data['name'],
  4581. 'content' => '提交了审核',
  4582. 'messageType' => 11,
  4583. ]);
  4584. }
  4585. $result = JobHunting::create($data);
  4586. if (empty($result)) {
  4587. return Result::error("添加失败", 0);
  4588. }
  4589. return Result::success($result);
  4590. }
  4591. public function delJobHunting(array $data): array
  4592. {
  4593. $result = JobHunting::where('id', $data['id'])->delete();
  4594. if (empty($result)) {
  4595. return Result::error("删除失败", 0);
  4596. }
  4597. return Result::success($result);
  4598. }
  4599. public function updateJobHunting(array $data): array
  4600. {
  4601. //设置东八区
  4602. date_default_timezone_set('Asia/Shanghai');
  4603. unset($data['company_name']);
  4604. unset($data['job_industry']);
  4605. unset($data['job_name']);
  4606. unset($data['department']);
  4607. unset($data['job_timeList']);
  4608. unset($data['job_content']);
  4609. unset($data['job_typename']); //不知道这是啥,
  4610. $data['created_at'] = date('Y-m-d H:i:s');
  4611. $data['updated_at'] = date('Y-m-d H:i:s');
  4612. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4613. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4614. $cityArr = json_decode($data['city_arr_id'], true);
  4615. $data['city_id'] = end($cityArr);
  4616. } else {
  4617. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4618. $data['city_id'] = end($data['city_arr_id']);
  4619. }
  4620. // 处理求职所绑定栏目
  4621. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4622. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4623. $catArr = json_decode($data['cat_arr_id'], true);
  4624. $data['catid'] = end($catArr);
  4625. } else {
  4626. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4627. $data['catid'] = end($data['cat_arr_id']);
  4628. }
  4629. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4630. $this->sendMessage([
  4631. 'talk_type' => 600,
  4632. 'title' => $data['name'],
  4633. 'content' => '提交了审核',
  4634. 'messageType' => 11,
  4635. ]);
  4636. }
  4637. $result = JobHunting::where('id', $data['id'])->update($data);
  4638. if (empty($result)) {
  4639. return Result::error("更新失败", 0);
  4640. }
  4641. return Result::success($result);
  4642. }
  4643. public function getJobHuntingInfo(array $data): array
  4644. {
  4645. $result = JobHunting::where('id', $data['id'])->first();
  4646. if (empty($result)) {
  4647. return Result::error("查询失败", 0);
  4648. }
  4649. return Result::success($result);
  4650. }
  4651. public function getJobHuntingData(array $data): array
  4652. {
  4653. $jobEnum = JobEnum::get();
  4654. $jobIndustry = JobIndustry::get();
  4655. $jobNature = JobNature::get();
  4656. $jobPosition = JobPosition::get();
  4657. $data = [
  4658. 'jobEnum' => $jobEnum,
  4659. 'jobIndustry' => $jobIndustry,
  4660. 'jobNature' => $jobNature,
  4661. 'jobPosition' => $jobPosition,
  4662. ];
  4663. return Result::success($data);
  4664. }
  4665. public function delJobHuntingInfo(array $data): array
  4666. {
  4667. $result = JobHunting::where('id', $data['id'])->delete();
  4668. return Result::success();
  4669. }
  4670. //20250324 通知,公告,消息
  4671. public function delNotice(array $data): array
  4672. {
  4673. $result = Notice::where('id', $data['id'])->delete();
  4674. if ($result) {
  4675. return Result::success();
  4676. } else {
  4677. return Result::error("删除失败", 0);
  4678. }
  4679. }
  4680. public function getNoticeInfo(array $data): array
  4681. {
  4682. $result = Notice::where('id', $data['id'])->first();
  4683. // var_dump($result['re_user_ids'], '--------------------');
  4684. if (empty($result)) {
  4685. return Result::error("查询失败", 0);
  4686. }
  4687. return Result::success($result);
  4688. }
  4689. public function readNotice(array $data): array
  4690. {
  4691. $result = Notice::where('id', $data['id'])->first();
  4692. // var_dump($result['re_user_ids'], '--------------------');
  4693. if (empty($result)) {
  4694. return Result::error("查询失败", 0);
  4695. }
  4696. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4697. $re_user_ids = json_decode($result['re_user_ids'], true);
  4698. var_dump($re_user_ids, '--------------1---test---------');
  4699. var_dump($data, '--------------1---test---------');
  4700. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4701. //如果已经存在,就不再添加
  4702. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4703. $read_id = json_decode($result['read_id'], true);
  4704. if (!is_array($read_id)) {
  4705. $read_id = [];
  4706. }
  4707. if (!in_array($data['user_id'], $read_id)) {
  4708. $read_id[] = $data['user_id'];
  4709. $result['read_id'] = json_encode($read_id);
  4710. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4711. }
  4712. } else {
  4713. //如果不存在,就添加
  4714. $result['read_id'] = json_encode([$data['user_id']]);
  4715. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4716. }
  4717. }
  4718. return Result::success($result);
  4719. }
  4720. public function addNotice(array $data): array
  4721. {
  4722. date_default_timezone_set('Asia/Shanghai');
  4723. $data['created_at'] = date('Y-m-d H:i:s');
  4724. $data['updated_at'] = date('Y-m-d H:i:s');
  4725. // $data['level'] = "1,2,3,4,5";
  4726. $level = json_decode($data['level'], true);
  4727. $user_id = UserInfo::
  4728. //city_id不是null
  4729. whereNotNull('city_id')
  4730. ->whereNotNull('department_id')
  4731. ->where(function ($query) use ($data) {
  4732. $query->where(function ($subQuery) use ($data) {
  4733. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4734. });
  4735. })
  4736. ->where(function ($query) use ($data) {
  4737. $query->where(function ($subQuery) use ($data) {
  4738. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4739. });
  4740. })
  4741. ->when(isset($level) && is_array($level), function ($query) use ($level) {
  4742. $query->whereIn('level', $level);
  4743. })
  4744. ->pluck('user_id')->toArray();
  4745. $user_id = array_unique($user_id);
  4746. $chat_ids = $user_id;
  4747. $user_id = json_encode($user_id);
  4748. $data['re_user_ids'] = $user_id;
  4749. $this->sendMessage([
  4750. 'talk_type' => 700,
  4751. 'title' => $data['title'],
  4752. 'content' => '提交了审核',
  4753. 'messageType' => 5,
  4754. ]);
  4755. $result = Notice::insertGetId($data);
  4756. if (empty($result)) {
  4757. return Result::error("添加失败", 0);
  4758. }
  4759. return Result::success($result);
  4760. }
  4761. public function updateNotice(array $data): array
  4762. {
  4763. date_default_timezone_set('Asia/Shanghai');
  4764. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4765. $user_id = UserInfo::
  4766. //city_id不是null
  4767. whereNotNull('city_id')
  4768. ->whereNotNull('department_id')
  4769. ->where(function ($query) use ($data) {
  4770. $query->where(function ($subQuery) use ($data) {
  4771. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4772. });
  4773. })
  4774. ->where(function ($query) use ($data) {
  4775. $query->where(function ($subQuery) use ($data) {
  4776. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4777. });
  4778. })
  4779. ->pluck('user_id')->toArray();
  4780. $user_id = array_unique($user_id);
  4781. $user_id = json_encode($user_id);
  4782. $data['re_user_ids'] = $user_id;
  4783. $data['updated_at'] = date('Y-m-d H:i:s');
  4784. $this->sendMessage([
  4785. 'talk_type' => 700,
  4786. 'title' => $data['title'],
  4787. 'content' => '提交了审核',
  4788. 'messageType' => 5,
  4789. ]);
  4790. $result = Notice::where('id', $data['id'])->update($data);
  4791. return Result::success($result);
  4792. }
  4793. public function getNoticeList(array $data): array
  4794. {
  4795. $where = [];
  4796. //title
  4797. if (isset($data['title']) && !empty($data['title'])) {
  4798. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4799. }
  4800. //level
  4801. if (isset($data['level']) && !empty($data['level'])) {
  4802. $where[] = ['notice.level', '=', $data['level']];
  4803. }
  4804. //status
  4805. if (isset($data['status']) && !empty($data['status'])) {
  4806. $where[] = ['notice.status', '=', $data['status']];
  4807. }
  4808. //type
  4809. if (isset($data['type']) && !empty($data['type'])) {
  4810. $where[] = ['notice.type', '=', $data['type']];
  4811. }
  4812. var_dump($data, '------------11111-2----test---------');
  4813. if ($data['type_id'] == 10000) {
  4814. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4815. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4816. })
  4817. ->where($where)
  4818. ->orderBy('updated_at', 'desc')
  4819. ->limit($data['page_size'])
  4820. ->offset(($data['page'] - 1) * $data['page_size'])
  4821. ->get();
  4822. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4823. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4824. })
  4825. ->where($where)
  4826. ->orderBy('updated_at', 'desc')
  4827. ->count();
  4828. } else {
  4829. $result = Notice::where($where)
  4830. // ->where('user_id', $data['user_id'])
  4831. ->Where(function ($query) use ($data) {
  4832. $query->Where(function ($q) use ($data) {
  4833. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4834. ->orWhere('notice.user_id', $data['user_id']);
  4835. });
  4836. })
  4837. ->when(!empty($data['status1']), function ($query) use ($data) {
  4838. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4839. })
  4840. ->orderBy('updated_at', 'desc')
  4841. ->limit($data['page_size'])
  4842. ->offset(($data['page'] - 1) * $data['page_size'])
  4843. ->get();
  4844. $total = Notice::where($where)
  4845. ->when(!empty($data['status1']), function ($query) use ($data) {
  4846. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4847. })
  4848. // ->where('user_id', $data['user_id'])
  4849. ->Where(function ($query) use ($data) {
  4850. $query->Where(function ($q) use ($data) {
  4851. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4852. ->orWhere('notice.user_id', $data['user_id']);
  4853. });
  4854. })
  4855. ->count();
  4856. }
  4857. if (empty($result)) {
  4858. return Result::error("查询失败", 0);
  4859. }
  4860. $data = [
  4861. 'rows' => $result,
  4862. 'count' => $total,
  4863. ];
  4864. return Result::success($data);
  4865. }
  4866. public function noticeList(array $data): array
  4867. {
  4868. $where = [];
  4869. //title
  4870. if (isset($data['title']) && !empty($data['title'])) {
  4871. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4872. }
  4873. //level
  4874. if (isset($data['level']) && !empty($data['level'])) {
  4875. $where[] = ['notice.level', '=', $data['level']];
  4876. }
  4877. //status
  4878. if (isset($data['status']) && !empty($data['status'])) {
  4879. $where[] = ['notice.status', '=', $data['status']];
  4880. }
  4881. //type
  4882. if (isset($data['type']) && !empty($data['type'])) {
  4883. $where[] = ['notice.type', '=', $data['type']];
  4884. }
  4885. var_dump($data, '------------11111-2----test---------');
  4886. if ($data['type_id'] == 10000) {
  4887. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4888. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4889. })
  4890. ->where($where)
  4891. ->orderBy('updated_at', 'desc')
  4892. ->limit($data['page_size'])
  4893. ->offset(($data['page'] - 1) * $data['page_size'])
  4894. ->get();
  4895. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4896. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4897. })
  4898. ->where($where)
  4899. ->orderBy('updated_at', 'desc')
  4900. ->count();
  4901. } else {
  4902. $result = Notice::where($where)
  4903. // ->where('user_id', $data['user_id'])
  4904. ->Where(function ($query) use ($data) {
  4905. $query->Where(function ($q) use ($data) {
  4906. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4907. ->orWhere('notice.user_id', $data['user_id']);
  4908. });
  4909. })
  4910. ->when(!empty($data['status1']), function ($query) use ($data) {
  4911. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4912. })
  4913. ->orderBy('updated_at', 'desc')
  4914. ->limit($data['page_size'])
  4915. ->offset(($data['page'] - 1) * $data['page_size'])
  4916. ->get();
  4917. $total = Notice::where($where)
  4918. ->when(!empty($data['status1']), function ($query) use ($data) {
  4919. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4920. })
  4921. // ->where('user_id', $data['user_id'])
  4922. ->Where(function ($query) use ($data) {
  4923. $query->Where(function ($q) use ($data) {
  4924. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4925. ->orWhere('notice.user_id', $data['user_id']);
  4926. });
  4927. })
  4928. ->count();
  4929. }
  4930. if (empty($result)) {
  4931. return Result::error("查询失败", 0);
  4932. }
  4933. $data = [
  4934. 'rows' => $result,
  4935. 'count' => $total,
  4936. ];
  4937. return Result::success($data);
  4938. }
  4939. public function getNoticeDetail(array $data): array
  4940. {
  4941. $result = Notice::where('id', $data['id'])->first();
  4942. if (empty($result)) {
  4943. return Result::error("查询失败", 0);
  4944. }
  4945. return Result::success($result);
  4946. }
  4947. public function deleteNotice(array $data): array
  4948. {
  4949. $notice = Notice::where('id', $data['id'])->first();
  4950. if (empty($notice)) {
  4951. return Result::error("删除失败", 0);
  4952. }
  4953. $chat_group_id = $notice->group_id;
  4954. if ($chat_group_id) {
  4955. //删除群聊
  4956. ChatGroups::where('id', $chat_group_id)->delete();
  4957. //删除群成员
  4958. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4959. //删除群聊记录
  4960. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4961. }
  4962. $result = Notice::where('id', $data['id'])->delete();
  4963. return Result::success($result);
  4964. }
  4965. public function complaintList(array $data): array
  4966. {
  4967. var_dump($data, '---------1---------');
  4968. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4969. unset($data['type_id']);
  4970. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4971. $where = [];
  4972. if ($type_id != 10000 && empty($data['deal_user'])) {
  4973. // $where['complaint.user_id'] = $user_id;
  4974. }
  4975. if (!empty($data['title'])) {
  4976. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4977. }
  4978. if (!empty($data['department_id'])) {
  4979. $where['complaint.department_id'] = $data['department_id'];
  4980. }
  4981. if (!empty($data['deal'])) {
  4982. $where['complaint.deal'] = $data['deal'];
  4983. }
  4984. if (!empty($data['status'])) {
  4985. $where['complaint.status'] = $data['status'];
  4986. }
  4987. var_dump(!empty($data['deal_user']), '----------1');
  4988. var_dump($where, '----------2');
  4989. $result = Complaint::where($where)
  4990. ->when(!empty($data['status1']), function ($query) use ($data) {
  4991. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4992. })
  4993. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4994. //json re_user_ids data[user_id]是不是在里面
  4995. $query->Where(function ($q) use ($data) {
  4996. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4997. ->where('complaint.status', 2);
  4998. });
  4999. })
  5000. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  5001. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  5002. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  5003. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  5004. ->orderBy('updated_at', 'desc')
  5005. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5006. //sql输出
  5007. if (empty($result)) {
  5008. return Result::error("暂无投诉信息", 0);
  5009. }
  5010. // 取出数据
  5011. $rows = $result->items();
  5012. $count = $result->total();
  5013. $responseData = [
  5014. 'rows' => $rows,
  5015. 'count' => $count,
  5016. ];
  5017. return Result::success($responseData);
  5018. }
  5019. public function getComplaintList(array $data): array
  5020. {
  5021. var_dump($data, '00000001000000000000');
  5022. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  5023. unset($data['type_id']);
  5024. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  5025. $where = [];
  5026. if ($type_id != 10000 && empty($data['deal_user'])) {
  5027. $where['complaint.user_id'] = $user_id;
  5028. }
  5029. if (!empty($data['title'])) {
  5030. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  5031. }
  5032. if (!empty($data['department_id'])) {
  5033. $where['complaint.department_id'] = $data['department_id'];
  5034. }
  5035. if (!empty($data['deal'])) {
  5036. $where['complaint.deal'] = $data['deal'];
  5037. }
  5038. if (!empty($data['status'])) {
  5039. $where['complaint.status'] = $data['status'];
  5040. }
  5041. var_dump(!empty($data['deal_user']), '----------1');
  5042. var_dump($where, '----------2');
  5043. $result = Complaint::where($where)
  5044. ->when(!empty($data['status1']), function ($query) use ($data) {
  5045. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  5046. })
  5047. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  5048. // //json re_user_ids data[user_id]是不是在里面
  5049. // $query->Where(function ($q) use ($data) {
  5050. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  5051. // ->where('complaint.status', 2);
  5052. // });
  5053. // })
  5054. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  5055. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  5056. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  5057. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  5058. ->orderBy('updated_at', 'desc')
  5059. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5060. //sql输出
  5061. if (empty($result)) {
  5062. return Result::error("暂无投诉信息", 0);
  5063. }
  5064. // 取出数据
  5065. $rows = $result->items();
  5066. $count = $result->total();
  5067. $responseData = [
  5068. 'rows' => $rows,
  5069. 'count' => $count,
  5070. ];
  5071. return Result::success($responseData);
  5072. }
  5073. public function getComplaintInfo(array $data): array
  5074. {
  5075. $result = Complaint::where('id', $data['id'])->first();
  5076. if (empty($result)) {
  5077. return Result::error("查询失败", 0);
  5078. }
  5079. return Result::success($result);
  5080. }
  5081. public function readComplaint(array $data): array
  5082. {
  5083. $result = Complaint::where('id', $data['id'])->first();
  5084. if (empty($result)) {
  5085. return Result::error("查询失败", 0);
  5086. }
  5087. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  5088. $re_user_ids = json_decode($result['re_user_ids'], true);
  5089. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  5090. //如果已经存在,就不再添加
  5091. if (isset($result['read_id']) && !empty($result['read_id'])) {
  5092. $read_id = json_decode($result['read_id'], true);
  5093. if (!is_array($read_id)) {
  5094. $read_id = [];
  5095. }
  5096. if (!in_array($data['user_id'], $read_id)) {
  5097. $read_id[] = $data['user_id'];
  5098. $result['read_id'] = json_encode($read_id);
  5099. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  5100. }
  5101. } else {
  5102. //如果不存在,就添加
  5103. $result['read_id'] = json_encode([$data['user_id']]);
  5104. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  5105. }
  5106. }
  5107. return Result::success($result);
  5108. }
  5109. public function addComplaint(array $data): array
  5110. {
  5111. date_default_timezone_set('Asia/Shanghai');
  5112. $data['created_at'] = date('Y-m-d H:i:s');
  5113. $data['updated_at'] = date('Y-m-d H:i:s');
  5114. $this->sendMessage([
  5115. 'talk_type' => 800,
  5116. 'title' => $data['title'],
  5117. 'content' => '提交了审核',
  5118. 'messageType' => 6,
  5119. ]);
  5120. $result = Complaint::create($data);
  5121. return Result::success($result);
  5122. }
  5123. public function updateComplaint(array $data): array
  5124. {
  5125. date_default_timezone_set('Asia/Shanghai');
  5126. $data['updated_at'] = date('Y-m-d H:i:s');
  5127. $user_id = $data['user_id'] ?? 0;
  5128. $type_id = $data['type_id'] ?? 0;
  5129. unset($data['user_id']);
  5130. unset($data['type_id']);
  5131. $this->sendMessage([
  5132. 'talk_type' => 800,
  5133. 'title' => $data['title'],
  5134. 'content' => '提交了审核',
  5135. 'messageType' => 6,
  5136. ]);
  5137. $result = Complaint::where('id', $data['id'])->update($data);
  5138. return Result::success($result);
  5139. }
  5140. public function deleteComplaint(array $data): array
  5141. {
  5142. $result = Complaint::where('id', $data['id'])->delete();
  5143. return Result::success($result);
  5144. }
  5145. public function getComplainInfo(array $data): array
  5146. {
  5147. $result = Complaint::where('id', $data['id'])->first();
  5148. if (empty($result)) {
  5149. return Result::error("查询失败", 0);
  5150. }
  5151. return Result::success($result);
  5152. }
  5153. public function updateComplaintStatus(array $data): array
  5154. {
  5155. date_default_timezone_set('Asia/Shanghai');
  5156. $data['updated_at'] = date('Y-m-d H:i:s');
  5157. $user_id = $data['user_id'] ?? 0;
  5158. $type_id = $data['type_id'] ?? 0;
  5159. unset($data['user_id']);
  5160. unset($data['type_id']);
  5161. //处理, 写入处理人
  5162. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  5163. $data['real_deal_user'] = $user_id;
  5164. }
  5165. //如果是deal 23,则判断是不是处理人
  5166. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  5167. $complaintInof = Complaint::where('id', $data['id'])
  5168. ->where('real_deal_user', $user_id)
  5169. ->first();
  5170. if (empty($complaintInof)) {
  5171. return Result::error("处理人错误", 0);
  5172. }
  5173. }
  5174. $complaintInfo = Complaint::where('id', $data['id'])->first();
  5175. if ($data['status'] == 1) {
  5176. $this->sendMessage([
  5177. 'talk_type' => 800,
  5178. 'title' => $complaintInfo['title'],
  5179. 'content' => '提交了审核',
  5180. 'messageType' => 6,
  5181. ]);
  5182. }
  5183. if ($data['status'] == 2 && !isset($data['deal'])) {
  5184. $this->sendMessage([
  5185. 'talk_type' => 801,
  5186. 'title' => $complaintInfo['title'],
  5187. 'content' => '审核通过',
  5188. 'messageType' => 6,
  5189. 'user_id' => $complaintInfo['user_id'],
  5190. ]);
  5191. $this->sendMessage([
  5192. 'talk_type' => 802,
  5193. 'title' => $complaintInfo['title'],
  5194. 'content' => '待处理',
  5195. 'messageType' => 6,
  5196. 'user_id' => $complaintInfo['re_user_ids'],
  5197. ]);
  5198. }
  5199. if ($data['status'] == 3 && !isset($data['deal'])) {
  5200. $this->sendMessage([
  5201. 'talk_type' => 801,
  5202. 'title' => $complaintInfo['title'],
  5203. 'content' => '审核拒绝',
  5204. 'messageType' => 6,
  5205. 'user_id' => $complaintInfo['user_id'],
  5206. ]);
  5207. }
  5208. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  5209. $this->sendMessage([
  5210. 'talk_type' => 802,
  5211. 'title' => $complaintInfo['title'],
  5212. 'content' => '处理中',
  5213. 'messageType' => 6,
  5214. 'user_id' => $complaintInfo['re_user_ids'],
  5215. ]);
  5216. }
  5217. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  5218. $this->sendMessage([
  5219. 'talk_type' => 802,
  5220. 'title' => $complaintInfo['title'],
  5221. 'content' => '不予处理',
  5222. 'messageType' => 6,
  5223. 'user_id' => $complaintInfo['re_user_ids'],
  5224. ]);
  5225. }
  5226. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  5227. $this->sendMessage([
  5228. 'talk_type' => 802,
  5229. 'title' => $complaintInfo['title'],
  5230. 'content' => '已完结',
  5231. 'messageType' => 6,
  5232. 'user_id' => $complaintInfo['re_user_ids'],
  5233. ]);
  5234. }
  5235. $result = complaint::where('id', $data['id'])->update($data);
  5236. return Result::success($result);
  5237. }
  5238. public function updateGoodStatus(array $data): array
  5239. {
  5240. $user_id = $data['user_id'] ?? 0;
  5241. $type_id = $data['type_id'] ?? 0;
  5242. unset($data['user_id']);
  5243. unset($data['type_id']);
  5244. $goodInfo = Good::where('id', $data['id'])->first();
  5245. if ($data['status'] == 2) {
  5246. $this->sendMessage([
  5247. 'talk_type' => 201,
  5248. 'title' => $goodInfo['name'],
  5249. 'content' => '审核通过',
  5250. 'messageType' => 3,
  5251. 'user_id' => $goodInfo['user_id'],
  5252. ]);
  5253. }
  5254. if ($data['status'] == 3) {
  5255. $this->sendMessage([
  5256. 'talk_type' => 201,
  5257. 'title' => $goodInfo['name'],
  5258. 'content' => '审核拒绝',
  5259. 'messageType' => 3,
  5260. 'user_id' => $goodInfo['user_id'],
  5261. ]);
  5262. }
  5263. if ($data['status'] == 1) {
  5264. $this->sendMessage([
  5265. 'talk_type' => 200,
  5266. 'title' => $goodInfo['name'],
  5267. 'content' => '提交了审核',
  5268. 'messageType' => 3,
  5269. ]);
  5270. }
  5271. $result = Good::where('id', $data['id'])->update($data);
  5272. return Result::success($result);
  5273. }
  5274. public function updateJobHuntingStatus(array $data): array
  5275. {
  5276. $user_id = $data['user_id'] ?? 0;
  5277. $type_id = $data['type_id'] ?? 0;
  5278. unset($data['user_id']);
  5279. unset($data['type_id']);
  5280. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  5281. if ($data['status'] == 2) {
  5282. $this->sendMessage([
  5283. 'talk_type' => 601,
  5284. 'title' => $jogHuntingInfo['name'],
  5285. 'content' => '审核通过',
  5286. 'messageType' => 11,
  5287. 'user_id' => $jogHuntingInfo['user_id'],
  5288. ]);
  5289. }
  5290. if ($data['status'] == 3) {
  5291. $this->sendMessage([
  5292. 'talk_type' => 601,
  5293. 'title' => $jogHuntingInfo['name'],
  5294. 'content' => '审核拒绝',
  5295. 'messageType' => 11,
  5296. 'user_id' => $jogHuntingInfo['user_id'],
  5297. ]);
  5298. }
  5299. if ($data['status'] == 1) {
  5300. $this->sendMessage([
  5301. 'talk_type' => 600,
  5302. 'title' => $jogHuntingInfo['name'],
  5303. 'content' => '提交了审核',
  5304. 'messageType' => 11,
  5305. ]);
  5306. }
  5307. $result = JobHunting::where('id', $data['id'])->update($data);
  5308. return Result::success($result);
  5309. }
  5310. public function updateNoticeStatus(array $data): array
  5311. {
  5312. $user_id = $data['user_id'] ?? 0;
  5313. $type_id = $data['type_id'] ?? 0;
  5314. unset($data['user_id']);
  5315. unset($data['type_id']);
  5316. //查询公告
  5317. $notice = Notice::where('id', $data['id'])->first();
  5318. if (empty($notice)) {
  5319. return Result::error("公告不存在", 0);
  5320. }
  5321. //$chat_ids 去除掉$data['user_id']
  5322. $chat_ids = json_decode($notice['re_user_ids'], true);
  5323. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  5324. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  5325. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  5326. //chat_group
  5327. $group_id = PublicData::uuid();
  5328. $groupData = [
  5329. 'id' => $group_id,
  5330. 'creator_id' => $notice['user_id'],
  5331. 'group_name' => $notice['group_name'] ?? '',
  5332. 'profile' => $notice['profile'] ?? 0,
  5333. ];
  5334. var_dump($groupData, '-----------------groupData-------');
  5335. $groupResult = ChatGroups::insertGetId($groupData);
  5336. var_dump($groupResult, '-----------------groupid-------');
  5337. $groupMemberData = [
  5338. 'id' => PublicData::uuid(),
  5339. 'user_id' => $notice['user_id'],
  5340. 'group_id' => $group_id,
  5341. 'leader' => 2,
  5342. ];
  5343. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  5344. //插入群成员表
  5345. $groupMemberDataUser = [];
  5346. $chatData = [];
  5347. foreach ($chat_ids as $key => $value) {
  5348. $groupMemberDataUser[] = [
  5349. 'id' => PublicData::uuid(),
  5350. 'user_id' => $value,
  5351. 'group_id' => $group_id,
  5352. 'leader' => 1,
  5353. ];
  5354. $chatData[] = [
  5355. 'user_id' => $value,
  5356. 'msg_type' => 1,
  5357. 'receiver_id' => $group_id,
  5358. 'content' => '通过通知创建群聊',
  5359. 'group_receiver_id' => $notice['user_id'],
  5360. 'action' => 'recieved',
  5361. 'created_at' => date('Y-m-d H:i:s'),
  5362. ];
  5363. }
  5364. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  5365. ChatGroupsMember::insert($groupMemberDataUser);
  5366. //插入一条管理员聊天记录
  5367. $chatData[] = [
  5368. 'user_id' => $notice['user_id'],
  5369. 'msg_type' => 1,
  5370. 'receiver_id' => $group_id,
  5371. 'content' => '通过通知创建群聊',
  5372. 'group_receiver_id' => $notice['user_id'],
  5373. 'action' => 'said',
  5374. 'created_at' => date('Y-m-d H:i:s'),
  5375. ];
  5376. var_dump($chatData, '-----------------chatData-------');
  5377. $chatResult = ChatRecords::insert($chatData);
  5378. //处理imp
  5379. $group = [
  5380. 'type' => 1,
  5381. 'name' => $notice['group_name'] ?? '',
  5382. 'profile' => '',
  5383. 'avatar' => '',
  5384. 'creator_id' => $notice['user_id'],
  5385. ];
  5386. $groupResult = GroupImp::insertGetId($group);
  5387. var_dump($groupResult, '获取imp group_id');
  5388. $groupMember = [
  5389. 'user_id' => $notice['user_id'],
  5390. 'group_id' => $groupResult,
  5391. 'leader' => 1,
  5392. 'join_time' => Date('Y-m-d H:i:s')
  5393. ];
  5394. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  5395. $talk_session = [
  5396. 'user_id' => $notice['user_id'],
  5397. 'to_from_id' => $groupResult,
  5398. 'talk_mode' => 2,
  5399. 'created_at' => Date('Y-m-d H:i:s'),
  5400. 'updated_at' => Date('Y-m-d H:i:s'),
  5401. ];
  5402. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  5403. //被通知人员处理
  5404. foreach ($chat_ids as $key => $value) {
  5405. $groupMemberdata[] = [
  5406. 'user_id' => $value,
  5407. 'group_id' => $groupResult,
  5408. 'leader' => 3,
  5409. 'join_time' => Date('Y-m-d H:i:s')
  5410. ];
  5411. $talk_sessionData[] = [
  5412. 'user_id' => $value,
  5413. 'to_from_id' => $groupResult,
  5414. 'talk_mode' => 2,
  5415. 'created_at' => Date('Y-m-d H:i:s'),
  5416. 'updated_at' => Date('Y-m-d H:i:s'),
  5417. ];
  5418. }
  5419. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  5420. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  5421. $group_id = $groupResult;
  5422. //更新result的 group_id
  5423. $data['group_id'] = $group_id;
  5424. Notice::where(['id' => $data['id']])->update($data);
  5425. }
  5426. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  5427. //删除掉信息
  5428. GroupImp::where('id', $notice['group_id'])->delete();
  5429. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  5430. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  5431. foreach ($chat_ids as $key => $value) {
  5432. }
  5433. //聊天记录删除
  5434. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  5435. $data['group_id'] = null;
  5436. Notice::where(['id' => $data['id']])->update($data);
  5437. }
  5438. $result = Notice::where('id', $data['id'])->update($data);
  5439. $noticeInfo = Notice::where('id', $data['id'])->first();
  5440. if ($data['status'] == 2) {
  5441. $this->sendMessage([
  5442. 'talk_type' => 701,
  5443. 'title' => $noticeInfo['title'],
  5444. 'content' => '审核通过',
  5445. 'messageType' => 3,
  5446. 'user_id' => $noticeInfo['user_id'],
  5447. ]);
  5448. }
  5449. if ($data['status'] == 3) {
  5450. $this->sendMessage([
  5451. 'talk_type' => 701,
  5452. 'title' => $noticeInfo['title'],
  5453. 'content' => '审核拒绝',
  5454. 'messageType' => 3,
  5455. 'user_id' => $noticeInfo['user_id'],
  5456. ]);
  5457. }
  5458. if ($data['status'] == 1) {
  5459. $this->sendMessage([
  5460. 'talk_type' => 700,
  5461. 'title' => $noticeInfo['title'],
  5462. 'content' => '提交了审核',
  5463. 'messageType' => 3,
  5464. ]);
  5465. }
  5466. return Result::success($result);
  5467. }
  5468. public function getDUser(array $data): array
  5469. {
  5470. if (!empty($data['ids'])) {
  5471. $user = User::whereIn('id', $data['ids'])->getall();
  5472. if (empty($user)) {
  5473. return Result::error('无数据', 0);
  5474. }
  5475. return Result::success($user);
  5476. }
  5477. $where = [];
  5478. if (!empty($data['department_id'])) {
  5479. $where['department_id'] = $data['department_id'];
  5480. }
  5481. if (!empty($data['city_id'])) {
  5482. $where['city_id'] = $data['city_id'];
  5483. }
  5484. $result = User::where('type_id', 2)
  5485. ->where('status', 1)
  5486. ->where($where)
  5487. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  5488. ->get();
  5489. if (empty($result)) {
  5490. return Result::error("查询失败", 0);
  5491. }
  5492. return Result::success($result);
  5493. }
  5494. /**
  5495. * 验证导航名称是否重复
  5496. * @return void
  5497. */
  5498. public function checkCategoryName(array $data): array
  5499. {
  5500. $result = Category::when($data, function ($query) use ($data) {
  5501. if (isset($data['name']) && $data['name']) {
  5502. $query->where("name", $data['name']);
  5503. }
  5504. if (isset($data['id']) && $data['id']) {
  5505. $query->where("id", "!=", $data['id']);
  5506. }
  5507. })->first();
  5508. if ($result) {
  5509. return Result::error("已存在");
  5510. } else {
  5511. return Result::success();
  5512. }
  5513. }
  5514. //20250226 产品列表
  5515. // 20250306 -------招聘--------fr
  5516. /*
  5517. * 招聘列表
  5518. * */
  5519. public function getJobRecruitingList(array $data): array
  5520. {
  5521. $where = [];
  5522. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  5523. if ($data['checkout'] == 0) {
  5524. $job_status = [0, 2];
  5525. } else {
  5526. $job_status = [1];
  5527. }
  5528. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5529. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  5530. }
  5531. $user = User::where('id', $data['user_id'])->first();
  5532. if (empty($user)) {
  5533. return Result::error("用户不存在", 0);
  5534. }
  5535. // 3:企业会员
  5536. if ($user['type_id'] == 3) {
  5537. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  5538. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  5539. }
  5540. // 如果 $where 为空,则不添加 where 条件
  5541. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5542. return $query->where($where);
  5543. })
  5544. ->whereIn('job_recruiting.status', $job_status)
  5545. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5546. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  5547. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  5548. ->orderBy("updated_at", "desc")
  5549. ->offset(($data['page'] - 1) * $data['page_size'])
  5550. ->limit($data['page_size'])
  5551. ->get()
  5552. ->all();
  5553. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5554. return $query->where($where);
  5555. })
  5556. ->whereIn('job_recruiting.status', $job_status)
  5557. ->count();
  5558. if (empty($result)) {
  5559. return Result::error("暂无招聘信息", 0);
  5560. }
  5561. return Result::success($result);
  5562. }
  5563. /*
  5564. * 招聘信息添加
  5565. * */
  5566. public function addJobRecruiting(array $data): array
  5567. {
  5568. // var_dump('添加招聘进入news------data',$data);
  5569. // return Result::success($data);
  5570. $user = User::where('user.id', $data['user_id'])
  5571. ->where('user.status', 1)
  5572. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5573. ->select(
  5574. 'user.type_id',
  5575. 'user.mobile',
  5576. 'user.email',
  5577. 'user_info.business_name',
  5578. 'user_info.company_hy_id',
  5579. 'user_info.company_nature',
  5580. 'user_info.company_size',
  5581. 'user_info.introduction',
  5582. 'user_info.real_name',
  5583. 'user_info.company_url',
  5584. 'user_info.address_arr_id',
  5585. 'user_info.address'
  5586. )
  5587. ->first();
  5588. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5589. return Result::error("用户不存在", 0);
  5590. }
  5591. $web = Website::where('id', $data['website_id'])->first();
  5592. if (empty($web)) {
  5593. return Result::error("网站不存在", 0);
  5594. }
  5595. // var_dump('添加招聘进入news---user---user',$user);
  5596. // 处理招聘关键词
  5597. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5598. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5599. } else {
  5600. Jieba::init(); // 初始化 jieba-php
  5601. Finalseg::init();
  5602. $segList = Jieba::cut($data['title']);
  5603. $segList1 = array_slice($segList, 0, 8);
  5604. $data['keyword'] = implode(',', $segList1);
  5605. }
  5606. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5607. $content = $data['description'];
  5608. // 去除 <style> 和 <script> 标签及其内容
  5609. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5610. // 去除所有 HTML 标签
  5611. $content = strip_tags($content);
  5612. // 去除 HTML 实体
  5613. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5614. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5615. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5616. // 去除多余空白
  5617. $content = preg_replace('/\s+/u', '', $content);
  5618. // 截取 100 个字符
  5619. $data['seo_description'] = mb_substr($content, 0, 100);
  5620. }
  5621. // return Result::success($user);
  5622. $data['action_id'] = $data['user_id'] ?? null;
  5623. $data['user_type'] = $user['type_id'] ?? null;
  5624. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5625. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5626. $data['catid'] = end($data['cat_arr_id']);
  5627. } else {
  5628. $data['catid'] = 0;
  5629. }
  5630. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5631. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5632. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5633. // 公司地址 管理员必填
  5634. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5635. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5636. // 管理员-企业相关信息
  5637. $company = [
  5638. // 'user_id' => $data['user_id']?? null,
  5639. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5640. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5641. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5642. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5643. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5644. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5645. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5646. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5647. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5648. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5649. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5650. ];
  5651. //去掉相关企业信息
  5652. $job = array_diff_key($data, array_flip(array_keys($company)));
  5653. // var_dump('添加招聘进入news---job---user',$job);
  5654. Db::beginTransaction();
  5655. try {
  5656. // // 先添加职位相关信息
  5657. if ($user['type_id'] == 10000) {
  5658. $job['status'] = 1;
  5659. }
  5660. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5661. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5662. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5663. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5664. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5665. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5666. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5667. // return Result::success($job);
  5668. $jobId = JobRecruiting::insertGetId($job);
  5669. if (empty($jobId)) {
  5670. Db::rollBack();
  5671. return Result::error("添加失败");
  5672. }
  5673. // 添加公司信息
  5674. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5675. $company['job_id'] = $jobId;
  5676. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5677. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5678. if ($user['type_id'] == 10000) {
  5679. // 管理员添加企业信息
  5680. $companyId = JobCompany::insertGetId($company);
  5681. if (empty($companyId)) {
  5682. Db::rollBack();
  5683. return Result::error("添加失败");
  5684. }
  5685. } else {
  5686. // 企业会员添加企业信息
  5687. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5688. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5689. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5690. $company['job_id'] = $jobId;
  5691. $companyId = JobCompany::insertGetId($company);
  5692. if (empty($companyId)) {
  5693. Db::rollBack();
  5694. return Result::error("添加失败");
  5695. }
  5696. }
  5697. Db::commit();
  5698. $result = [
  5699. 'job_id' => $jobId,
  5700. 'company_id' => $companyId,
  5701. ];
  5702. return Result::success($result);
  5703. } catch (\Exception $e) {
  5704. Db::rollBack();
  5705. return Result::error($e->getMessage(), 0);
  5706. }
  5707. // return Result::success($result);
  5708. }
  5709. /*
  5710. * 获取招聘信息详情
  5711. * */
  5712. public function getJobRecruitingInfo(array $data): array
  5713. {
  5714. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5715. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5716. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5717. ->select(
  5718. 'job_recruiting.*',
  5719. 'website.website_name as website_name',
  5720. 'job_company.business_name',
  5721. 'job_company.company_hy_id',
  5722. 'job_company.company_size',
  5723. 'job_company.company_nature',
  5724. 'job_company.introduction',
  5725. 'job_company.real_name',
  5726. 'job_company.mobile',
  5727. 'job_company.company_url',
  5728. 'job_company.address_arr_id',
  5729. 'job_company.address',
  5730. 'job_company.email'
  5731. )
  5732. ->first();
  5733. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5734. if (!empty($cityId)) {
  5735. if (isset($cityId[1]) && $cityId[1] != null) {
  5736. $city = District::where('id', $cityId[1])->first(['name']);
  5737. } else {
  5738. $city = District::where('id', $cityId[0])->first(['name']);
  5739. }
  5740. $result['city'] = $city['name'] ?? '';
  5741. }
  5742. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5743. if (is_array($addressId) && !empty($addressId)) {
  5744. $address = District::whereIn('id', $addressId)
  5745. ->orderBy('level', 'asc')
  5746. ->get(['name'])
  5747. ->pluck('name')
  5748. ->implode('');
  5749. // $job->address_name = $address ?? '';
  5750. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5751. }
  5752. if (empty($result)) {
  5753. return Result::error("招聘信息不存在", 0);
  5754. }
  5755. // return Result::success($job);
  5756. return Result::success($result);
  5757. }
  5758. /*
  5759. * 修改招聘信息
  5760. * */
  5761. public function upJobRecruiting(array $data): array
  5762. {
  5763. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5764. // return Result::success($job);
  5765. if (empty($job)) {
  5766. return Result::error("招聘信息不存在", 0);
  5767. }
  5768. $user = User::where('id', $data['user_id'])->first();
  5769. // return Result::success($user);
  5770. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5771. return Result::error("用户不存在", 0);
  5772. }
  5773. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5774. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5775. }
  5776. // 处理招聘关键词
  5777. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5778. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5779. } else {
  5780. Jieba::init(); // 初始化 jieba-php
  5781. Finalseg::init();
  5782. $segList = Jieba::cut($data['title']);
  5783. $segList1 = array_slice($segList, 0, 8);
  5784. $data['keyword'] = implode(',', $segList1);
  5785. }
  5786. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5787. $content = $data['description'];
  5788. // 去除 <style> 和 <script> 标签及其内容
  5789. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5790. // 去除所有 HTML 标签
  5791. $content = strip_tags($content);
  5792. // 去除 HTML 实体
  5793. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5794. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5795. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5796. // 去除多余空白
  5797. $content = preg_replace('/\s+/u', '', $content);
  5798. // 截取 100 个字符
  5799. $data['seo_description'] = mb_substr($content, 0, 100);
  5800. }
  5801. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5802. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5803. $data['catid'] = end($data['cat_arr_id']);
  5804. } else {
  5805. }
  5806. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5807. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5808. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5809. // 公司地址 管理员必填
  5810. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5811. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5812. // 管理员-企业相关信息
  5813. $company = [
  5814. // 'user_id' => $data['user_id']?? null,
  5815. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5816. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5817. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5818. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5819. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5820. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5821. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5822. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5823. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5824. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5825. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5826. ];
  5827. //去掉相关企业信息
  5828. $data = array_diff_key($data, array_flip(array_keys($company)));
  5829. $jobId = $data['id'];
  5830. $web = $data['website_id'];
  5831. $data['action_id'] = $data['user_id'];
  5832. unset($data['user_id']);
  5833. unset($data['user_type']);
  5834. unset($data['id']);
  5835. unset($data['website_id']);
  5836. // return Result::success($data);
  5837. Db::beginTransaction();
  5838. try {
  5839. // 管理员修改招聘信息
  5840. if ($user['type_id'] == 10000) {
  5841. $data['website_id'] = $web;
  5842. $company['website_id'] = $data['website_id'];
  5843. $data['status'] = 1;
  5844. } else {
  5845. $data['status'] = 0;
  5846. }
  5847. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5848. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5849. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5850. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5851. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5852. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5853. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5854. // return Result::success($job);
  5855. // Db::rollBack();
  5856. // return Result::success($company);
  5857. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5858. $this->sendMessage([
  5859. 'talk_type' => 500,
  5860. 'title' => $data['title'],
  5861. 'content' => '提交了审核',
  5862. 'messageType' => 10,
  5863. ]);
  5864. }
  5865. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5866. if (empty($result['job'])) {
  5867. Db::rollBack();
  5868. return Result::error("修改招聘信息失败");
  5869. }
  5870. // 管理员修改企业相关信息
  5871. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5872. if (empty($result['company'])) {
  5873. Db::rollBack();
  5874. return Result::error("修改企业相关信息失败");
  5875. }
  5876. Db::commit();
  5877. // return Result::success($result);
  5878. } catch (\Exception $e) {
  5879. Db::rollBack();
  5880. return Result::error($e->getMessage(), 0);
  5881. }
  5882. return Result::success($result);
  5883. }
  5884. /*
  5885. * 招聘信息删除
  5886. * */
  5887. public function delJobRecruiting(array $data): array
  5888. {
  5889. $user = User::where('id', $data['user_id'])->first();
  5890. if (empty($user)) {
  5891. return Result::error("用户不存在", 0);
  5892. }
  5893. $job = JobRecruiting::where('id', $data['id'])->first();
  5894. if (empty($job)) {
  5895. return Result::error("招聘信息不存在", 0);
  5896. }
  5897. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5898. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5899. }
  5900. Db::beginTransaction();
  5901. try {
  5902. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5903. if (empty($result['job'])) {
  5904. Db::rollBack();
  5905. return Result::error("删除招聘信息失败");
  5906. }
  5907. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5908. if (empty($result['company'])) {
  5909. Db::rollBack();
  5910. return Result::error("删除企业相关信息失败");
  5911. }
  5912. Db::commit();
  5913. } catch (\Exception $e) {
  5914. Db::rollBack();
  5915. return Result::error($e->getMessage(), 0);
  5916. }
  5917. return Result::success($result);
  5918. }
  5919. /*
  5920. * 获取公司信息
  5921. * */
  5922. public function getJobCompany(array $data): array
  5923. {
  5924. $user = User::where('user.id', $data['user_id'])
  5925. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5926. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5927. ->first();
  5928. // return Result::success($user);
  5929. if (empty($user)) {
  5930. return Result::error("用户不存在", 0);
  5931. }
  5932. if ($user['type_id'] == 3) {
  5933. $result = [
  5934. // 'id' => 0,
  5935. 'user_id' => $data['user_id'],
  5936. 'website_id' => $data['website_id'],
  5937. 'business_name' => $user['business_name'], // 企业名称
  5938. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5939. 'company_nature' => $user['company_nature'], // 公司性质
  5940. 'company_size' => $user['company_size'], // 公司规模
  5941. 'introduction' => $user['introduction'], // 公司简介
  5942. 'real_name' => $user['real_name'], // 企业联系人
  5943. 'mobile' => $user['mobile'], // 企业联系电话
  5944. 'company_url' => $user['company_url'], // 企业网址
  5945. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5946. 'address' => $user['address'], // 企业地址
  5947. 'email' => $user['email'], // 企业邮箱
  5948. ];
  5949. } else {
  5950. return Result::error("用户类型错误", 0);
  5951. }
  5952. if (empty($result)) {
  5953. return Result::error("公司信息不存在", 0);
  5954. }
  5955. return Result::success($result);
  5956. }
  5957. /*
  5958. * 修改公司信息
  5959. * */
  5960. public function upJobCompany(array $data): array
  5961. {
  5962. // return Result::success($data);
  5963. $user = User::where('user.id', $data['user_id'])
  5964. ->where('user.status', 1)
  5965. ->select('user.user_name', 'user.type_id')
  5966. ->first();
  5967. if (empty($user)) {
  5968. return Result::error("用户不存在", 0);
  5969. }
  5970. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5971. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5972. $company = [
  5973. 'business_name' => $data['business_name'], // 企业名称
  5974. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5975. 'company_nature' => $data['company_nature'], // 公司性质
  5976. 'company_size' => $data['company_size'], // 公司规模
  5977. 'introduction' => $data['introduction'], // 公司简介
  5978. // 'real_name' => $data['real_name'], // 企业联系人
  5979. 'company_url' => $data['company_url'], // 企业网址
  5980. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5981. 'address' => $data['address'], // 企业详细地址
  5982. // 'email' => $data['email'], // 企业邮箱
  5983. ];
  5984. if ($user['type_id'] == 3) {
  5985. Db::beginTransaction();
  5986. try {
  5987. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5988. 'business_name' => $data['business_name'], // 企业名称
  5989. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5990. 'company_nature' => $data['company_nature'], // 公司性质
  5991. 'company_size' => $data['company_size'], // 公司规模
  5992. 'introduction' => $data['introduction'], // 公司简介
  5993. // 'real_name' => $data['real_name'], // 企业联系人
  5994. 'company_url' => $data['company_url'], // 企业网址
  5995. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5996. 'address' => $data['address'], // 企业详细地址
  5997. ]);
  5998. if (empty($result['userinfo'])) {
  5999. Db::rollBack();
  6000. return Result::error('修改企业会员信息失败!');
  6001. }
  6002. $result['user'] = User::where('id', $data['user_id'])->update([
  6003. 'email' => $data['email'], // 企业邮箱
  6004. ]);
  6005. if (empty($result['user'])) {
  6006. Db::rollBack();
  6007. return Result::error('修改个人中心信息失败!');
  6008. }
  6009. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  6010. if (!empty($job_company)) {
  6011. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  6012. if (empty($result['job_company'])) {
  6013. Db::rollBack();
  6014. return Result::error('修改企业会员信息失败!');
  6015. }
  6016. }
  6017. Db::commit();
  6018. return Result::success($result);
  6019. } catch (\Exception $e) {
  6020. Db::rollBack();
  6021. return Result::error($e->getMessage(), 0);
  6022. }
  6023. } else {
  6024. return Result::error("用户类型错误", 0);
  6025. }
  6026. }
  6027. /*
  6028. * 获取省-市
  6029. * */
  6030. public function getJobRecruitingArea(array $data): array
  6031. {
  6032. if (isset($data['pid']) && $data['pid'] != null) {
  6033. $result = District::where('pid', $data['pid'])->get()->all();
  6034. } else {
  6035. $result = District::where('level', 1)->get()->all();
  6036. }
  6037. if (empty($result)) {
  6038. return Result::error("暂无此省市", 0);
  6039. }
  6040. return Result::success($result);
  6041. }
  6042. /*
  6043. * 获取行业分类
  6044. * */
  6045. public function getIndustry(array $data): array
  6046. {
  6047. $result = JobIndustry::get()->all();
  6048. if (empty($result)) {
  6049. return Result::error("暂无行业分类", 0);
  6050. }
  6051. return Result::success($result);
  6052. }
  6053. /*
  6054. * 获取职位
  6055. * */
  6056. public function getPositionList(array $data): array
  6057. {
  6058. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  6059. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  6060. } else {
  6061. $result = JobPosition::where('zwpid', 0)->get()->all();
  6062. }
  6063. if (empty($result)) {
  6064. return Result::error("暂无此职位", 0);
  6065. }
  6066. return Result::success($result);
  6067. }
  6068. /*
  6069. * 获取工作性质-菜单
  6070. * */
  6071. public function getJobNature(array $data): array
  6072. {
  6073. $result = JobEnum::where('egroup', 'nature')->get()->all();
  6074. if (empty($result)) {
  6075. return Result::error("暂无工作性质", 0);
  6076. }
  6077. return Result::success($result);
  6078. }
  6079. /*
  6080. * 获取工作经验-菜单
  6081. * */
  6082. public function getExperience(array $data): array
  6083. {
  6084. $result = JobEnum::where('egroup', 'years')->get()->all();
  6085. if (empty($result)) {
  6086. return Result::error("暂无工作经验", 0);
  6087. }
  6088. return Result::success($result);
  6089. }
  6090. /*
  6091. * 获取学历-菜单
  6092. * */
  6093. public function getEducation(array $data): array
  6094. {
  6095. $result = JobEnum::where('egroup', 'education')->get()->all();
  6096. if (empty($result)) {
  6097. return Result::error("暂无学历", 0);
  6098. }
  6099. return Result::success($result);
  6100. }
  6101. /*
  6102. * 获取薪资-菜单
  6103. * */
  6104. public function getSalary(array $data): array
  6105. {
  6106. $result = JobEnum::where('egroup', 'income')->get()->all();
  6107. if (empty($result)) {
  6108. return Result::error("暂无薪资", 0);
  6109. }
  6110. return Result::success($result);
  6111. }
  6112. /*
  6113. * 获取语言-菜单
  6114. * */
  6115. public function getLanguage(array $data): array
  6116. {
  6117. $result = JobEnum::where('egroup', 'language')->get()->all();
  6118. if (empty($result)) {
  6119. return Result::error("暂无语言", 0);
  6120. }
  6121. return Result::success($result);
  6122. }
  6123. /*
  6124. * 获取掌握程度-菜单
  6125. * */
  6126. public function getLevel(array $data): array
  6127. {
  6128. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  6129. if (empty($result)) {
  6130. return Result::error("暂无工作性质", 0);
  6131. }
  6132. return Result::success($result);
  6133. }
  6134. // 公司信息
  6135. /*
  6136. * 获取公司性质-菜单
  6137. * */
  6138. public function getCompanyNature(array $data): array
  6139. {
  6140. $result = JobNature::get()->all();
  6141. if (empty($result)) {
  6142. return Result::error("暂无公司性质", 0);
  6143. }
  6144. return Result::success($result);
  6145. }
  6146. /*
  6147. * 获取公司规模-菜单
  6148. * */
  6149. public function getCompanySize(array $data): array
  6150. {
  6151. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  6152. if (empty($result)) {
  6153. return Result::error("暂无公司规模", 0);
  6154. }
  6155. return Result::success($result);
  6156. }
  6157. /*
  6158. * 招聘信息审核
  6159. * */
  6160. public function checkJobRecruiting(array $data): array
  6161. {
  6162. $user = User::where('id', $data['user_id'])->first();
  6163. if (empty($user)) {
  6164. return Result::error("用户不存在", 0);
  6165. }
  6166. $job = JobRecruiting::where('id', $data['id'])->first();
  6167. if (empty($job)) {
  6168. return Result::error("招聘信息不存在", 0);
  6169. }
  6170. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  6171. if ($user['type_id'] != 10000) {
  6172. return Result::error("用户暂无权限审核此招聘信息!", 0);
  6173. }
  6174. // 驳回原因
  6175. if ($data['status'] == 2) {
  6176. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  6177. }
  6178. $data['action_id'] = $data['user_id'];
  6179. unset($data['user_id']);
  6180. if ($data['status'] == 1) {
  6181. $this->sendMessage([
  6182. 'talk_type' => 501,
  6183. 'title' => $job['title'],
  6184. 'content' => '审核通过',
  6185. 'messageType' => 10,
  6186. 'user_id' => $job['user_id'],
  6187. ]);
  6188. }
  6189. if ($data['status'] == 2) {
  6190. $this->sendMessage([
  6191. 'talk_type' => 501,
  6192. 'title' => $job['title'],
  6193. 'content' => '审核拒绝',
  6194. 'messageType' => 10,
  6195. 'user_id' => $job['user_id'],
  6196. ]);
  6197. }
  6198. if ($data['status'] == 0) {
  6199. $this->sendMessage([
  6200. 'talk_type' => 500,
  6201. 'title' => $job['title'],
  6202. 'content' => '提交了审核',
  6203. 'messageType' => 10,
  6204. ]);
  6205. }
  6206. $result = JobRecruiting::where('id', $data['id'])->update($data);
  6207. if (empty($result)) {
  6208. return Result::error("审核失败", 0);
  6209. }
  6210. return Result::success($result);
  6211. }
  6212. public function myApplyList(array $data): array
  6213. {
  6214. var_dump($data, '------参数');
  6215. $user = User::where('id', $data['user_id'])->first();
  6216. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6217. return Result::error("用户不存在", 0);
  6218. }
  6219. // 1:个人会员 职场机会
  6220. if ($user['type_id'] == 1) {
  6221. $where['user_id'] = $user['id'];
  6222. }
  6223. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  6224. $query->where('user_id', $user['id']);
  6225. })
  6226. ->pluck('recruit_id');
  6227. $where = [];
  6228. if (isset($data['salary']) && $data['salary'] != null) {
  6229. $where['job_recruiting.salary'] = $data['salary'];
  6230. }
  6231. if (isset($data['experience']) && $data['experience'] != null) {
  6232. $where['job_recruiting.experience'] = $data['experience'];
  6233. }
  6234. if (isset($data['business_name']) && $data['business_name'] != null) {
  6235. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6236. }
  6237. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6238. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6239. ->where($where);
  6240. // ->count();
  6241. $count = $query->count();
  6242. $query = clone $query;
  6243. $job = $query
  6244. ->leftJoin('job_enum as income_enum', function ($join) {
  6245. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6246. ->where('income_enum.egroup', 'income');
  6247. })
  6248. ->leftJoin('job_enum as years_enum', function ($join) {
  6249. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6250. ->where('years_enum.egroup', 'years');
  6251. })
  6252. // ->where($where)
  6253. ->orderBy('job_recruiting.updated_at', 'desc')
  6254. ->select(
  6255. 'job_recruiting.id',
  6256. 'job_recruiting.title',
  6257. 'job_company.business_name',
  6258. 'income_enum.evalue as salary_evalue',
  6259. 'income_enum.ename as salary_ename',
  6260. 'years_enum.evalue as experience_evalue',
  6261. 'years_enum.ename as experience_ename',
  6262. 'job_recruiting.updated_at'
  6263. )
  6264. ->offset(($data['page'] - 1) * $data['pageSize'])
  6265. ->limit($data['pageSize'])
  6266. ->get()
  6267. ->all();
  6268. if (empty($job)) {
  6269. return Result::error("暂无招聘信息", 0);
  6270. }
  6271. $result = [
  6272. 'row' => $job,
  6273. 'count' => $count,
  6274. ];
  6275. return Result::success($result);
  6276. }
  6277. public function readJobApply(array $data): array
  6278. {
  6279. $result = JobApply::where('id', $data['id'])->first();
  6280. if (empty($result)) {
  6281. return Result::error("查询失败", 0);
  6282. }
  6283. $result = JobApply::where('id', $data['id'])->update([
  6284. 'status' => 2,
  6285. ]);
  6286. return Result::success($result);
  6287. }
  6288. /*
  6289. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  6290. * */
  6291. public function getRecruitingList(array $data): array
  6292. {
  6293. $user = User::where('id', $data['user_id'])->first();
  6294. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6295. return Result::error("用户不存在", 0);
  6296. }
  6297. // 1:个人会员 职场机会
  6298. if ($user['type_id'] == 1) {
  6299. $where['user_id'] = $user['id'];
  6300. }
  6301. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  6302. $query->where('receiver_id', $user['id']);
  6303. })
  6304. ->pluck('recruit_id');
  6305. // return Result::success($recruitingId);
  6306. $where = [];
  6307. if (isset($data['salary']) && $data['salary'] != null) {
  6308. $where['job_recruiting.salary'] = $data['salary'];
  6309. }
  6310. if (isset($data['experience']) && $data['experience'] != null) {
  6311. $where['job_recruiting.experience'] = $data['experience'];
  6312. }
  6313. if (isset($data['business_name']) && $data['business_name'] != null) {
  6314. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6315. }
  6316. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6317. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6318. ->where($where);
  6319. // ->count();
  6320. $count = $query->count();
  6321. $query = clone $query;
  6322. $job = $query
  6323. ->leftJoin('job_enum as income_enum', function ($join) {
  6324. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6325. ->where('income_enum.egroup', 'income');
  6326. })
  6327. ->leftJoin('job_enum as years_enum', function ($join) {
  6328. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6329. ->where('years_enum.egroup', 'years');
  6330. })
  6331. // ->where($where)
  6332. ->orderBy('job_recruiting.updated_at', 'desc')
  6333. ->select(
  6334. 'job_recruiting.id',
  6335. 'job_recruiting.title',
  6336. 'job_company.business_name',
  6337. 'income_enum.evalue as salary_evalue',
  6338. 'income_enum.ename as salary_ename',
  6339. 'years_enum.evalue as experience_evalue',
  6340. 'years_enum.ename as experience_ename',
  6341. 'job_recruiting.updated_at'
  6342. )
  6343. ->offset(($data['page'] - 1) * $data['pageSize'])
  6344. ->limit($data['pageSize'])
  6345. ->get()
  6346. ->all();
  6347. if (empty($job)) {
  6348. return Result::error("暂无招聘信息", 0);
  6349. }
  6350. $result = [
  6351. 'row' => $job,
  6352. 'count' => $count,
  6353. ];
  6354. return Result::success($result);
  6355. }
  6356. /*
  6357. * 获取企业会员-招聘信息列表
  6358. * */
  6359. public function getRecruitingInfo(array $data): array
  6360. {
  6361. $user = User::where('id', $data['user_id'])->first();
  6362. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6363. return Result::error("用户不存在", 0);
  6364. }
  6365. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  6366. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6367. ->select(
  6368. 'job_recruiting.*',
  6369. 'job_company.business_name',
  6370. 'job_company.company_hy_id',
  6371. 'job_company.company_size',
  6372. 'job_company.company_nature',
  6373. 'job_company.introduction',
  6374. 'job_company.real_name',
  6375. 'job_company.mobile',
  6376. 'job_company.company_url',
  6377. 'job_company.address_arr_id',
  6378. 'job_company.address',
  6379. 'job_company.email'
  6380. )
  6381. ->get();
  6382. if (empty($recruiting)) {
  6383. return Result::error("暂无招聘信息", 0);
  6384. }
  6385. return Result::success($recruiting);
  6386. }
  6387. /*
  6388. * 获取企业会员-我的沟通
  6389. * */
  6390. public function getJobResumeList(array $data): array
  6391. {
  6392. $user = User::where('id', $data['user_id'])->first();
  6393. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  6394. return Result::error("用户不存在", 0);
  6395. }
  6396. $where = [];
  6397. if (isset($data['salary']) && $data['salary'] != null) {
  6398. $where['job_hunting.salary'] = $data['salary'];
  6399. }
  6400. if (isset($data['user_name']) && $data['user_name'] != null) {
  6401. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  6402. }
  6403. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  6404. $query->where('job_resume.user_id', $user['id']);
  6405. })
  6406. ->when(!empty($where), function ($query) use ($where) {
  6407. $query->where($where);
  6408. })
  6409. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  6410. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  6411. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  6412. ->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');
  6413. $count = $job->count();
  6414. if ($count == 0) {
  6415. return Result::error("暂无沟通记录", 0);
  6416. }
  6417. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  6418. ->offset(($data['page'] - 1) * $data['pageSize'])
  6419. ->limit($data['pageSize'])
  6420. ->get();
  6421. if (empty($jobs)) {
  6422. return Result::error("暂无沟通记录", 0);
  6423. }
  6424. $result['row'] = $this->processJob($jobs, '');
  6425. $result['count'] = $count;
  6426. return Result::success($result);
  6427. }
  6428. public function readJobResume(array $data): array
  6429. {
  6430. $result = JobResume::where('id', $data['id'])->first();
  6431. if (empty($result)) {
  6432. return Result::error("查询失败", 0);
  6433. }
  6434. $result = JobResume::where('id', $data['id'])->update([
  6435. 'status' => 2,
  6436. ]);
  6437. return Result::success($result);
  6438. }
  6439. // 20250306 招聘
  6440. //20250422 书刊音像
  6441. public function addBook(array $data): array
  6442. {
  6443. $user_id = $data['user_id'] ?? 0;
  6444. $type_id = $data['type_id'] ?? 0;
  6445. // $website_id = $data['website_id'] ?? 0;
  6446. // unset($data['user_id']);
  6447. unset($data['type_id']);
  6448. // unset($data['website_id']);
  6449. //处理数组
  6450. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6451. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6452. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6453. if ($data['img_url'] == '') {
  6454. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6455. preg_match_all($reg, $data['detail'], $matches);
  6456. if (isset($matches[1][0])) {
  6457. //截取varchar240
  6458. $data['img_url'] = substr($matches[1][0], 0, 240);
  6459. }
  6460. }
  6461. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  6462. //提取标题+内容中的关键词
  6463. $data['keyword'] = $data['title'];
  6464. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6465. Jieba::init(); // 初始化 jieba-php
  6466. Finalseg::init();
  6467. $segList = Jieba::cut($data['keyword']);
  6468. $segList1 = array_slice($segList, 0, 8);
  6469. $data['keyword'] = implode(',', $segList1);
  6470. }
  6471. if ($data['description'] == '') {
  6472. //提取内容中的描述
  6473. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6474. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6475. }
  6476. var_dump($data, '--');
  6477. if ($data['status'] == 1) {
  6478. $this->sendMessage([
  6479. 'talk_type' => 400,
  6480. 'title' => $data['title'],
  6481. 'content' => '提交了审核',
  6482. 'messageType' => 7,
  6483. ]);
  6484. }
  6485. $result = Book::insertGetId($data);
  6486. if (empty($result)) {
  6487. return Result::error("添加失败", 0);
  6488. }
  6489. return Result::success($result);
  6490. }
  6491. public function getBookList(array $data): array
  6492. {
  6493. $where = [];
  6494. if (!empty($data["title"])) {
  6495. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  6496. }
  6497. if (!empty($data['website_name'])) {
  6498. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  6499. }
  6500. if (!empty($data['status'])) {
  6501. $where[] = ['book.status', '=', $data['status']];
  6502. }
  6503. $user_id = $data['user_id'];
  6504. $type_id = $data['type_id'];
  6505. // $type_id = 4;
  6506. var_dump($type_id, '------1--------');
  6507. if ($type_id != 10000) {
  6508. $where[] = ['book.user_id', '=', $user_id];
  6509. }
  6510. var_dump(!empty($data['status1']), '=-===1');
  6511. $result = Book::where($where)
  6512. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  6513. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  6514. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  6515. ->when(isset($data['status1']), function ($query) use ($data) {
  6516. $query->whereIn('book.status', [1, 3]);
  6517. })
  6518. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  6519. ->orderBy("updated_at", "desc")
  6520. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  6521. if (empty($result)) {
  6522. return Result::error("暂无数据", 0);
  6523. }
  6524. // 取出数据
  6525. $rows = $result->items();
  6526. $count = $result->total();
  6527. $responseData = [
  6528. 'rows' => $rows,
  6529. 'count' => $count,
  6530. ];
  6531. return Result::success($responseData);
  6532. }
  6533. public function deleteBook(array $data): array
  6534. {
  6535. $result = Book::where('id', $data['id'])->delete();
  6536. if (empty($result)) {
  6537. return Result::error("删除失败", 0);
  6538. }
  6539. return Result::success($result);
  6540. }
  6541. public function updateBook(array $data): array
  6542. {
  6543. // $user_id = $data['user_id'] ?? 0;
  6544. $type_id = $data['type_id'] ?? 0;
  6545. // $website_id = $data['website_id'] ?? 0;
  6546. unset($data['user_id']);
  6547. unset($data['type_id']);
  6548. // unset($data['website_id']);
  6549. //处理数组
  6550. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6551. if ($data['img_url'] == '') {
  6552. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6553. preg_match_all($reg, $data['detail'], $matches);
  6554. if (isset($matches[1][0])) {
  6555. //截取varchar240
  6556. $data['img_url'] = substr($matches[1][0], 0, 240);
  6557. }
  6558. }
  6559. if ($data['keyword'] == '') {
  6560. //提取标题+内容中的关键词
  6561. $data['keyword'] = $data['title'];
  6562. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6563. Jieba::init(); // 初始化 jieba-php
  6564. Finalseg::init();
  6565. $segList = Jieba::cut($data['keyword']);
  6566. $segList1 = array_slice($segList, 0, 8);
  6567. $data['keyword'] = implode(',', $segList1);
  6568. }
  6569. if ($data['description'] == '') {
  6570. //提取内容中的描述
  6571. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6572. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6573. }
  6574. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6575. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6576. if ($data['status'] == 1) {
  6577. $this->sendMessage([
  6578. 'talk_type' => 400,
  6579. 'title' => $data['title'],
  6580. 'content' => '提交了审核',
  6581. 'messageType' => 7,
  6582. ]);
  6583. }
  6584. $result = Book::where("id", $data["id"])->update($data);
  6585. if (empty($result)) {
  6586. return Result::error("更新失败", 0);
  6587. }
  6588. return Result::success($result);
  6589. }
  6590. public function getBookInfo(array $data): array
  6591. {
  6592. $result = Book::where("id", $data["id"])->first();
  6593. if (empty($result)) {
  6594. return Result::error("获取失败", 0);
  6595. }
  6596. return Result::success($result);
  6597. }
  6598. public function updateBookStatus(array $data): array
  6599. {
  6600. //审核
  6601. unset($data['user_id']);
  6602. $bookInfo = Book::where("id", $data["id"])->first();
  6603. var_dump($bookInfo, '----');
  6604. if ($data['status'] == 2) {
  6605. $this->sendMessage([
  6606. 'talk_type' => 401,
  6607. 'title' => $bookInfo['title'],
  6608. 'content' => '审核通过',
  6609. 'messageType' => 7,
  6610. 'user_id' => $bookInfo['user_id'],
  6611. ]);
  6612. }
  6613. if ($data['status'] == 3) {
  6614. $this->sendMessage([
  6615. 'talk_type' => 401,
  6616. 'title' => $bookInfo['title'],
  6617. 'content' => '审核拒绝',
  6618. 'messageType' => 7,
  6619. 'user_id' => $bookInfo['user_id'],
  6620. ]);
  6621. }
  6622. if ($data['status'] == 1) {
  6623. $this->sendMessage([
  6624. 'talk_type' => 400,
  6625. 'title' => $bookInfo['title'],
  6626. 'content' => '提交了审核',
  6627. 'messageType' => 7,
  6628. // 'user_id'=>$bookInfo['user_id'],
  6629. ]);
  6630. }
  6631. $result = Book::where("id", $data["id"])->update($data);
  6632. if (empty($result)) {
  6633. return Result::error("更新失败", 0);
  6634. }
  6635. return Result::success($result);
  6636. }
  6637. //20250422 书刊音像
  6638. /**
  6639. * 贴身宝贝
  6640. * @param array $data
  6641. * @return array
  6642. */
  6643. public function getWebsiteTsbb(array $data): array
  6644. {
  6645. $month = $data['month'] ?? date('m');
  6646. $day = $data['day'] ?? date('d');
  6647. // 使用缓存键
  6648. $cacheKey = "tsbb_data_{$month}_{$day}";
  6649. // 尝试从缓存获取数据
  6650. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6651. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6652. if ($cachedData = $cache->get($cacheKey)) {
  6653. return Result::success(unserialize($cachedData));
  6654. }
  6655. //查询老黄历
  6656. try {
  6657. $date = date('Y-m-d');
  6658. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6659. // 使用 curl 替代 file_get_contents
  6660. $ch = curl_init();
  6661. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6662. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6663. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6664. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6665. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6666. 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');
  6667. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6668. 'Accept: application/json',
  6669. 'Content-Type: application/json',
  6670. 'Referer: https://www.36jxs.com/'
  6671. ]);
  6672. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6673. curl_setopt($ch, CURLOPT_ENCODING, '');
  6674. $almanacResponse = curl_exec($ch);
  6675. var_dump("====:", $almanacResponse);
  6676. if (curl_errno($ch)) {
  6677. var_dump('Curl error:', curl_error($ch));
  6678. throw new \Exception('Curl error: ' . curl_error($ch));
  6679. }
  6680. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6681. curl_close($ch);
  6682. if ($almanacResponse === false) {
  6683. throw new \Exception('Failed to fetch almanac data');
  6684. }
  6685. $almanacData = json_decode($almanacResponse, true);
  6686. if (json_last_error() !== JSON_ERROR_NONE) {
  6687. throw new \Exception('Failed to parse almanac data');
  6688. }
  6689. $almanacInfo = $almanacData['data'] ?? [];
  6690. } catch (\Exception $e) {
  6691. var_dump('Exception:', $e->getMessage());
  6692. $almanacInfo = [];
  6693. }
  6694. // 获取历史上的今天数据
  6695. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6696. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6697. ->orderBy('year', 'asc')
  6698. ->select("title", "id", "year", DB::raw('1 as type'))
  6699. ->limit(16)
  6700. ->get();
  6701. // 获取节日数据 - 从今天开始获取未来4条
  6702. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6703. ->orderBy('showtime', 'asc')
  6704. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6705. ->limit(16)
  6706. ->get();
  6707. //说文解字
  6708. $chartacterList = Character::orderBy('updated_at', 'desc')
  6709. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6710. ->limit(6)
  6711. ->get();
  6712. //谜语沙龙
  6713. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6714. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6715. ->limit(4)
  6716. ->get();
  6717. //成语欣赏
  6718. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6719. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6720. ->limit(32)
  6721. ->get();
  6722. //名联赏析
  6723. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6724. ->select("id", "first", "second", DB::raw('6 as type'))
  6725. ->limit(6)
  6726. ->get();
  6727. // 获取分类文章数据
  6728. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6729. ->pluck('category_id')
  6730. ->toArray();
  6731. $articlesList = [];
  6732. foreach ($categoryIds as $catid) {
  6733. // 先查有图片的
  6734. $withImg = DB::table('article')
  6735. ->where('status', 1)
  6736. ->where('catid', $catid)
  6737. ->whereNotNull('imgurl')
  6738. ->where('imgurl', '!=', '')
  6739. ->orderBy('updated_at', 'desc')
  6740. ->limit(6)
  6741. ->get();
  6742. $count = $withImg->count();
  6743. if ($count < 6) {
  6744. // 不足6条再查无图片的补足
  6745. $withoutImg = DB::table('article')
  6746. ->where('status', 1)
  6747. ->where('catid', $catid)
  6748. ->where(function ($q) {
  6749. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6750. })
  6751. ->orderBy('updated_at', 'desc')
  6752. ->limit(6 - $count)
  6753. ->get();
  6754. $articles = $withImg->concat($withoutImg);
  6755. } else {
  6756. $articles = $withImg;
  6757. }
  6758. // 组装
  6759. $category = \App\Model\Category::find($catid);
  6760. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6761. $articlesList[] = [
  6762. 'category_name' => $category ? $category->name : '',
  6763. 'catid' => $catid,
  6764. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6765. 'type' => 100,
  6766. 'list' => $articles->map(function ($item) {
  6767. return [
  6768. 'id' => $item->id,
  6769. 'title' => $item->title,
  6770. 'imgurl' => $item->imgurl,
  6771. 'created_at' => $item->created_at
  6772. ];
  6773. })->values()
  6774. ];
  6775. }
  6776. $result = [
  6777. 'almanac' => $almanacInfo,
  6778. 'historyTodayList' => [
  6779. 'category_name' => '历史上的今天',
  6780. 'list' => $historyTodayList,
  6781. 'type' => 1
  6782. ],
  6783. 'festivalList' => [
  6784. 'category_name' => '节日预告',
  6785. 'list' => $festivalList,
  6786. 'type' => 2
  6787. ],
  6788. 'chartacterList' => [
  6789. 'category_name' => '说文解字',
  6790. 'list' => $chartacterList,
  6791. 'type' => 3
  6792. ],
  6793. 'coupletList' => [
  6794. 'category_name' => '名联赏析',
  6795. 'list' => $coupletList,
  6796. 'type' => 6
  6797. ],
  6798. 'riddletList' => [
  6799. 'category_name' => '谜语沙龙',
  6800. 'list' => $riddletList,
  6801. 'type' => 4
  6802. ],
  6803. 'idiomList' => [
  6804. 'category_name' => '成语欣赏',
  6805. 'list' => $idiomList,
  6806. 'type' => 5
  6807. ],
  6808. 'articlesList' => $articlesList
  6809. ];
  6810. // 缓存结果,设置1小时过期
  6811. $cache->set($cacheKey, serialize($result), 3600);
  6812. return Result::success($result);
  6813. }
  6814. /**
  6815. * 获取资讯列表
  6816. */
  6817. public function getWebsiteTsbbList(array $data): array
  6818. {
  6819. $page = $data['page'] ?? 1;
  6820. $pageSize = $data['pageSize'] ?? 10;
  6821. // 如果没有传入月份和日期,则使用今天的日期
  6822. $month = $data['month'] ?? date('m');
  6823. $day = $data['day'] ?? date('d');
  6824. $total = 0;
  6825. $result = [];
  6826. $data['type'] = intval($data['type']);
  6827. var_dump("接收参数:", $data);
  6828. switch ($data['type']) {
  6829. case 1:
  6830. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6831. // 当前月份之后的数据
  6832. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6833. // 或者当前月份且日期大于等于当前日期的数据
  6834. ->orWhere(function ($q) use ($month, $day) {
  6835. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6836. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6837. });
  6838. })
  6839. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6840. $total = $query->count();
  6841. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6842. ->offset(($page - 1) * $pageSize)
  6843. ->limit($pageSize)
  6844. ->get();
  6845. break;
  6846. case 2:
  6847. $query = Festival::where(function ($q) use ($month, $day) {
  6848. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6849. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6850. ->orWhere(function ($q) use ($month, $day) {
  6851. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6852. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6853. });
  6854. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6855. $total = $query->count();
  6856. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6857. ->offset(($page - 1) * $pageSize)
  6858. ->limit($pageSize)
  6859. ->get();
  6860. break;
  6861. case 3:
  6862. $query = Character::orderBy("updated_at", "desc");
  6863. $total = $query->count();
  6864. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6865. ->offset(($page - 1) * $pageSize)
  6866. ->limit($pageSize)
  6867. ->get();
  6868. break;
  6869. case 4:
  6870. $query = Riddle::orderBy("updated_at", "desc");
  6871. $total = $query->count();
  6872. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6873. ->offset(($page - 1) * $pageSize)
  6874. ->limit($pageSize)
  6875. ->get();
  6876. break;
  6877. case 5:
  6878. $query = Idiom::orderBy("updated_at", "desc");
  6879. $total = $query->count();
  6880. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6881. ->offset(($page - 1) * $pageSize)
  6882. ->limit($pageSize)
  6883. ->get();
  6884. break;
  6885. case 6:
  6886. $query = Couplet::orderBy("updated_at", "desc");
  6887. $total = $query->count();
  6888. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6889. ->offset(($page - 1) * $pageSize)
  6890. ->limit($pageSize)
  6891. ->get();
  6892. break;
  6893. default:
  6894. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6895. $total = $query->count();
  6896. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6897. ->offset(($page - 1) * $pageSize)
  6898. ->limit($pageSize)
  6899. ->get();
  6900. }
  6901. return Result::success([
  6902. 'list' => $result,
  6903. 'total' => $total,
  6904. 'page' => (int)$page,
  6905. 'pageSize' => (int)$pageSize,
  6906. 'month' => $month,
  6907. 'day' => $day
  6908. ]);
  6909. }
  6910. /**
  6911. * 1:历史上的今天
  6912. * 2:节日
  6913. * 3:文章
  6914. *
  6915. * 资讯详情信息
  6916. */
  6917. public function getWebsiteTsbbDetail(array $data): array
  6918. {
  6919. $data['type'] = intval($data['type']);
  6920. switch ($data['type']) {
  6921. case 1:
  6922. $result = HistoryToday::where("id", $data['id'])->first();
  6923. break;
  6924. case 2:
  6925. $result = Festival::where("id", $data['id'])->first();
  6926. break;
  6927. case 3:
  6928. $result = Character::where("id", $data['id'])->first();
  6929. break;
  6930. case 4:
  6931. $result = Riddle::where("id", $data['id'])->first();
  6932. break;
  6933. case 5:
  6934. $result = Idiom::where("id", $data['id'])->first();
  6935. break;
  6936. case 6:
  6937. $result = Couplet::where("id", $data['id'])->first();
  6938. break;
  6939. default:
  6940. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6941. break;
  6942. }
  6943. return Result::success($result);
  6944. }
  6945. /**
  6946. * 农网导航首页数据
  6947. */
  6948. public function getWebsiteNwHomeList(array $data): array
  6949. {
  6950. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6951. ->pluck('category_id')
  6952. ->toArray();
  6953. // 使用子查询优化
  6954. $articlesList = DB::table('article')
  6955. ->select([
  6956. 'article.id',
  6957. 'article.title',
  6958. 'article.imgurl',
  6959. 'article.created_at',
  6960. 'category.name as category_name',
  6961. 'category.id as category_id',
  6962. 'website_category.aLIas_pinyin as pinyin',
  6963. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6964. DB::raw('100 as type')
  6965. ])
  6966. ->join('category', 'article.catid', '=', 'category.id')
  6967. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6968. ->leftJoin('website_category as parent_wc', function ($join) {
  6969. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6970. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6971. })
  6972. ->where('website_category.website_id', $data['website_id'])
  6973. ->where('article.status', 1)
  6974. ->whereIn('category.id', $categoryIds)
  6975. ->orderBy('article.created_at', 'desc')
  6976. ->get()
  6977. ->groupBy('category_id')
  6978. ->map(function ($group) {
  6979. // 确保第一条数据有图片
  6980. $firstWithImage = $group->first(function ($item) {
  6981. return !empty($item->imgurl);
  6982. });
  6983. if ($firstWithImage) {
  6984. // 如果有带图片的文章,将其放在第一位
  6985. $group = $group->filter(function ($item) use ($firstWithImage) {
  6986. return $item->id !== $firstWithImage->id;
  6987. })->prepend($firstWithImage);
  6988. }
  6989. return [
  6990. 'category_name' => $group->first()->category_name,
  6991. 'catid' => $group->first()->category_id,
  6992. 'pinyin' => $group->first()->pinyin,
  6993. 'parent_pinyin' => $group->first()->parent_pinyin,
  6994. 'list' => $group->take(4)->map(function ($item) {
  6995. return [
  6996. 'id' => $item->id,
  6997. 'title' => $item->title,
  6998. ];
  6999. })->values()
  7000. ];
  7001. })
  7002. ->values()
  7003. ->toArray();
  7004. return Result::success($articlesList);
  7005. }
  7006. /**
  7007. * 企业管理
  7008. * @param array $data
  7009. * @return array
  7010. */
  7011. public function getCompanyList(array $data): array
  7012. {
  7013. // return Result::success($data);
  7014. $where = [];
  7015. $user = User::where('id', $data['user_id'])->first();
  7016. if (empty($user)) {
  7017. return Result::error('用户不存在!');
  7018. }
  7019. if ($user['type_id'] != 10000) {
  7020. $where['user_id'] = $data['user_id'];
  7021. }
  7022. if (isset($data['title']) && !empty($data['title'])) {
  7023. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  7024. }
  7025. if (isset($data['website_id']) && !empty($data['website_id'])) {
  7026. array_push($where, ['website.id', $data['website_id']]);
  7027. }
  7028. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  7029. if ($data['ischeck'] == 1) {
  7030. if (isset($data['status']) && $data['status'] != '') {
  7031. array_push($where, ['company.status', $data['status']]);
  7032. $query = Company::where($where);
  7033. } else {
  7034. $query = Company::whereIn('company.status', [0, 2]);
  7035. }
  7036. } else {
  7037. $query = Company::where('company.status', 1);
  7038. }
  7039. }
  7040. $result = $query->where($where)
  7041. ->leftJoin('website_category', function ($query) {
  7042. $query->on('website_category.category_id', '=', 'company.category_id')
  7043. ->on('website_category.website_id', '=', 'company.website_id');
  7044. })
  7045. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  7046. ->select(
  7047. 'company.id',
  7048. 'company.title',
  7049. 'company.website_id',
  7050. 'company.category_id',
  7051. 'website.website_name',
  7052. 'website_category.alias as category_name',
  7053. 'company.status',
  7054. 'company.updated_at',
  7055. 'company.user_id'
  7056. )
  7057. ->orderBy('company.updated_at', 'desc')
  7058. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7059. if ($result->isEmpty()) {
  7060. return Result::error("暂无企业", 0);
  7061. }
  7062. return Result::success($result);
  7063. }
  7064. /**
  7065. * 添加企业
  7066. * @param array $data
  7067. * @return array
  7068. */
  7069. public function addCompany(array $data): array
  7070. {
  7071. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  7072. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  7073. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  7074. $data['cat_arr_id'] = json_encode($car_arr_id);
  7075. } else {
  7076. $data['cat_arr_id'] = '';
  7077. }
  7078. if ($data['imgurl'] == '') {
  7079. //content中提取图片第一个图,正则提取
  7080. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7081. preg_match_all($reg, $data['content'], $matches);
  7082. if (isset($matches[1][0])) {
  7083. //截取varchar240
  7084. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7085. }
  7086. }
  7087. if ($data['keyword'] == '') {
  7088. //提取标题+内容中的关键词
  7089. $data['keyword'] = $data['title'];
  7090. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7091. Jieba::init(); // 初始化 jieba-php
  7092. Finalseg::init();
  7093. $segList = Jieba::cut($data['keyword']);
  7094. $segList1 = array_slice($segList, 0, 8);
  7095. $data['keyword'] = implode(',', $segList1);
  7096. }
  7097. if ($data['introduce'] == '' || empty($data['introduce'])) {
  7098. //提取内容中的描述
  7099. $content = $data['content'];
  7100. // 去除 <style> 和 <script> 标签及其内容
  7101. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7102. // 去除所有 HTML 标签
  7103. $content = strip_tags($content);
  7104. // 去除 HTML 实体
  7105. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7106. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7107. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7108. // 去除多余空白
  7109. $content = preg_replace('/\s+/u', '', $content);
  7110. // 截取 100 个字符
  7111. $data['introduce'] = mb_substr($content, 0, 100);
  7112. }
  7113. $user = User::where('id', $data['user_id'])->first();
  7114. if (empty($user)) {
  7115. return Result::error('用户不存在!');
  7116. }
  7117. if ($user['type_id'] == 10000) {
  7118. $data['status'] = 1;
  7119. }
  7120. if (isset($data['level']) && $data['level'] != null) {
  7121. $data['level'] = intval($data['level']);
  7122. } else {
  7123. $data['level'] = null;
  7124. }
  7125. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7126. $this->sendMessage([
  7127. 'talk_type' => 900,
  7128. 'title' => $data['title'],
  7129. 'content' => '提交了审核',
  7130. 'messageType' => 8,
  7131. ]);
  7132. }
  7133. $result = Company::insertGetId($data);
  7134. if ($result) {
  7135. return Result::success($result);
  7136. } else {
  7137. return Result::error('添加失败');
  7138. }
  7139. }
  7140. /**
  7141. * 更新企业
  7142. * @param array $data
  7143. * @return array
  7144. */
  7145. public function upCompany(array $data): array
  7146. {
  7147. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  7148. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  7149. $data['cat_arr_id'] = json_encode($car_arr_id);
  7150. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  7151. } else {
  7152. $data['cat_arr_id'] = '';
  7153. }
  7154. if ($data['imgurl'] == '') {
  7155. //content中提取图片第一个图,正则提取
  7156. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7157. preg_match_all($reg, $data['content'], $matches);
  7158. if (isset($matches[1][0])) {
  7159. //截取varchar
  7160. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7161. }
  7162. }
  7163. if ($data['keyword'] == '') {
  7164. //提取标题+内容中的关键词
  7165. $data['keyword'] = $data['title'];
  7166. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7167. Jieba::init(); // 初始化 jieba-php
  7168. Finalseg::init();
  7169. $segList = Jieba::cut($data['keyword']);
  7170. $segList1 = array_slice($segList, 0, 8);
  7171. $data['keyword'] = implode(',', $segList1);
  7172. }
  7173. if ($data['introduce'] == '') {
  7174. //提取内容中的描述
  7175. $content = $data['content'];
  7176. // 去除 <style> 和 <script> 标签及其内容
  7177. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7178. // 去除所有 HTML 标签
  7179. $content = strip_tags($content);
  7180. // 去除 HTML 实体
  7181. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7182. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7183. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7184. // 去除多余空白
  7185. $content = preg_replace('/\s+/u', '', $content);
  7186. // 截取 100 个字符
  7187. $data['introduce'] = mb_substr($content, 0, 100);
  7188. }
  7189. if (isset($data['level']) && $data['level'] != null) {
  7190. $data['level'] = intval($data['level']);
  7191. } else {
  7192. $data['level'] = null;
  7193. }
  7194. $user = User::where('id', $data['user_id'])->first();
  7195. if (empty($user)) {
  7196. return Result::error('用户不存在!');
  7197. }
  7198. if ($user['type_id'] == 10000) {
  7199. $data['status'] = 1;
  7200. } else {
  7201. $data['status'] = 0;
  7202. }
  7203. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7204. $this->sendMessage([
  7205. 'talk_type' => 900,
  7206. 'title' => $data['title'],
  7207. 'content' => '提交了审核',
  7208. 'messageType' => 8,
  7209. ]);
  7210. }
  7211. $result = Company::where('id', $data['id'])->update($data);
  7212. if ($result) {
  7213. return Result::success($result);
  7214. } else {
  7215. return Result::error('修改失败');
  7216. }
  7217. }
  7218. /**
  7219. * 删除企业
  7220. * @param array $data
  7221. * @return array
  7222. */
  7223. public function delCompany(array $data): array
  7224. {
  7225. $result = Company::where('id', $data['id'])->delete();
  7226. if ($result) {
  7227. return Result::success($result);
  7228. } else {
  7229. return Result::error('删除失败');
  7230. }
  7231. }
  7232. /**
  7233. * 审核企业
  7234. * @param array $data
  7235. * @return array
  7236. */
  7237. public function checkCompany(array $data): array
  7238. {
  7239. $user = User::where('id', $data['user_id'])->first();
  7240. if (empty($user)) {
  7241. return Result::error('用户不存在!');
  7242. }
  7243. $company = Company::where('id', $data['id'])->first();
  7244. if (empty($company)) {
  7245. return Result::error('企业不存在!');
  7246. }
  7247. // 状态:0:未审核 1:已审核 2:已拒绝
  7248. if ($data['status'] == 2 || $data['status'] == '2') {
  7249. $this->sendMessage([
  7250. 'talk_type' => 901,
  7251. 'title' => $company['title'],
  7252. 'content' => '审核拒绝',
  7253. 'messageType' => 8,
  7254. 'user_id' => $company['user_id'],
  7255. ]);
  7256. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  7257. } else {
  7258. if ($data['status'] == 1) {
  7259. $this->sendMessage([
  7260. 'talk_type' => 901,
  7261. 'title' => $company['title'],
  7262. 'content' => '审核通过',
  7263. 'messageType' => 8,
  7264. 'user_id' => $company['user_id'],
  7265. ]);
  7266. } else if ($data['status'] == 0) {
  7267. $this->sendMessage([
  7268. 'talk_type' => 900,
  7269. 'title' => $company['title'],
  7270. 'content' => '提交了审核',
  7271. 'messageType' => 8,
  7272. ]);
  7273. }
  7274. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  7275. }
  7276. if (empty($result)) {
  7277. return Result::error('审核失败!');
  7278. } else {
  7279. return Result::success($result);
  7280. }
  7281. }
  7282. /**
  7283. * 获取企业信息
  7284. * @param array $data
  7285. * @return array
  7286. */
  7287. public function getCompanyInfo(array $data): array
  7288. {
  7289. $result = Company::where('id', $data['id'])->first();
  7290. $city_arr = json_decode($result['city_arr_id']);
  7291. $result['city_name'] = District::whereIn('id', $city_arr)
  7292. ->pluck('name')
  7293. ->implode('-');
  7294. if (empty($result)) {
  7295. return Result::error('企业不存在!');
  7296. } else {
  7297. return Result::success($result);
  7298. }
  7299. }
  7300. /**
  7301. * @param array $data
  7302. * @return array
  7303. */
  7304. public function getWebsiteCompany(array $data): array
  7305. {
  7306. $categorys = json_decode($data['id'], true);
  7307. $category_arr = $this->processArticlePro($data['website_id']);
  7308. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7309. $catiall = $category_arr['catiall'];
  7310. $categoryIds = $category_arr['categoryIds'];
  7311. // return Result::success($category_arr);
  7312. foreach ($categorys as $key => $value) {
  7313. if (array_key_exists('level', $value)) {
  7314. $parts = explode(',', $value['level']);
  7315. $level = $parts[0] ?? null;
  7316. $imgnum = $parts[1] ?? null;
  7317. $textnum = $parts[2] ?? null;
  7318. if (!empty($textnum) && $textnum > 0) {
  7319. $text_num = Company::where('level', $level)
  7320. ->whereIn('category_id', $categoryIds)
  7321. ->where('status', 1)
  7322. ->select(
  7323. 'company.id',
  7324. 'company.title',
  7325. 'company.description',
  7326. 'company.updated_at',
  7327. 'company.category_id',
  7328. 'company.cat_arr_id'
  7329. )
  7330. ->orderBy('updated_at', 'desc')
  7331. ->limit($textnum)
  7332. ->get()->all();
  7333. }
  7334. if (!empty($imgnum) && $imgnum > 0) {
  7335. $img_num = Company::where('level', $level)
  7336. ->whereIn('category_id', $categoryIds)
  7337. ->where('status', 1)
  7338. ->where('imgurl', '!=', '')
  7339. ->whereNotNull('imgurl')
  7340. ->select(
  7341. 'company.id',
  7342. 'company.title',
  7343. 'company.description',
  7344. 'company.updated_at',
  7345. 'company.imgurl as imgs',
  7346. 'company.category_id',
  7347. 'company.cat_arr_id'
  7348. )
  7349. ->orderBy('updated_at', 'desc')
  7350. ->limit($imgnum)
  7351. ->get()->all();
  7352. }
  7353. }
  7354. if (array_key_exists('id', $value)) {
  7355. $parts = explode(',', $value['id']);
  7356. $category_id = $parts[0] ?? null;
  7357. $imgnum = $parts[1] ?? null;
  7358. $textnum = $parts[2] ?? null;
  7359. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  7360. if (!empty($textnum) && $textnum > 0) {
  7361. $text_num = Company::whereIn('category_id', $category_arr)
  7362. // ->where('website_id', $data['website_id'])
  7363. ->where('status', 1)
  7364. ->select(
  7365. 'company.id',
  7366. 'company.title',
  7367. 'company.description',
  7368. 'company.updated_at',
  7369. 'company.category_id',
  7370. 'company.cat_arr_id'
  7371. )
  7372. ->orderBy('updated_at', 'desc')
  7373. ->limit($textnum)
  7374. ->get()->all();
  7375. }
  7376. if (!empty($imgnum) && $imgnum > 0) {
  7377. $img_num = Company::whereIn('category_id', $category_arr)
  7378. // ->where('website_id', $data['website_id'])
  7379. ->where('status', 1)
  7380. ->where('imgurl', '!=', '')
  7381. ->whereNotNull('imgurl')
  7382. ->select(
  7383. 'company.id',
  7384. 'company.title',
  7385. 'company.description',
  7386. 'company.updated_at',
  7387. 'company.imgurl as imgs',
  7388. 'company.category_id',
  7389. 'company.cat_arr_id'
  7390. )
  7391. ->orderBy('updated_at', 'desc')
  7392. ->limit($imgnum)
  7393. ->get()->all();
  7394. }
  7395. }
  7396. if (!empty($text_num)) {
  7397. foreach ($text_num as $k => $v) {
  7398. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7399. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7400. }
  7401. }
  7402. if (!empty($img_num)) {
  7403. foreach ($img_num as $k => $v) {
  7404. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7405. $imgurl = json_decode($v['imgs'], true);
  7406. if (!empty($imgurl)) {
  7407. $img_num[$k]->imgurl = $imgurl[0];
  7408. }
  7409. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7410. }
  7411. }
  7412. $company[$key]['img_num'] = $img_num ?? [];
  7413. $company[$key]['text_num'] = $text_num ?? [];
  7414. }
  7415. if (empty($company)) {
  7416. return Result::error("暂无相关企业信息", 0);
  7417. }
  7418. return Result::success($company);
  7419. }
  7420. /**
  7421. * @param array $data
  7422. * @return array
  7423. */
  7424. public function getWebsiteCompanyList(array $data): array
  7425. {
  7426. $where['website_id'] = $data['website_id'];
  7427. $where['status'] = 1;
  7428. $categoryIds = [];
  7429. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7430. $category_id = $data['category_id'];
  7431. }
  7432. $category_arr = $this->processArticlePro($data['website_id']);
  7433. $categoryIds = $category_arr['categoryIds'];
  7434. // return Result::success($cat_1st_arr);
  7435. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  7436. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  7437. })
  7438. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  7439. $query->whereIn('category_id', $categoryIds);
  7440. })
  7441. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  7442. $query->where('category_id', $category_id);
  7443. })
  7444. ->where('status',1)
  7445. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  7446. ->orderBy('updated_at', 'desc')
  7447. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7448. if (empty($company)) {
  7449. return Result::error("暂无相关公司信息", 0);
  7450. }
  7451. $result = [
  7452. 'count' => $company->total(),
  7453. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  7454. ];
  7455. return Result::success($result);
  7456. }
  7457. /**
  7458. * 获取项目列表
  7459. * @param array $data
  7460. * @return array
  7461. */
  7462. public function getProjectList(array $data): array
  7463. {
  7464. $where = [];
  7465. $user = User::where('id', $data['user_id'])->first();
  7466. if (empty($user)) {
  7467. return Result::error('用户不存在!');
  7468. }
  7469. if ($user->type_id != 10000) {
  7470. array_push($where, ['project.user_id', $data['user_id']]);
  7471. }
  7472. $query = Project::query();
  7473. if (isset($data['website_id']) && !empty($data['website_id'])) {
  7474. array_push($where, ['project.website_id', $data['website_id']]);
  7475. }
  7476. if (isset($data['title']) && !empty($data['title'])) {
  7477. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  7478. }
  7479. if ($data['status'] != 3) {
  7480. array_push($where, ['project.status', $data['status']]);
  7481. }
  7482. $query = Project::where($where)
  7483. ->when($data['status'] == 3, function ($query) {
  7484. $query->whereIn('project.status', [0, 2]);
  7485. });
  7486. $count = $query->clone()
  7487. ->count();
  7488. $rows = $query->clone()
  7489. ->leftJoin('website', 'project.website_id', 'website.id')
  7490. ->leftJoin('website_category', function ($join) {
  7491. $join->on('project.website_id', '=', 'website_category.website_id')
  7492. ->on('project.category_id', '=', 'website_category.category_id');
  7493. })
  7494. ->select(
  7495. 'project.id',
  7496. 'project.title',
  7497. 'project.updated_at',
  7498. 'project.status',
  7499. 'website.website_name',
  7500. 'website_category.alias as category_name',
  7501. 'project.website_id',
  7502. 'project.user_id'
  7503. )
  7504. ->orderBy('project.updated_at', 'desc')
  7505. ->offset(($data['page'] - 1) * $data['pageSize'])
  7506. ->limit($data['pageSize'])
  7507. ->get();
  7508. if ($rows->isEmpty()) {
  7509. return Result::error("暂无相关项目信息", 0);
  7510. }
  7511. $result = [
  7512. 'count' => $count,
  7513. 'rows' => $rows,
  7514. ];
  7515. return Result::success($result);
  7516. }
  7517. /**
  7518. * 添加项目
  7519. * @param array $data
  7520. * @return array
  7521. */
  7522. public function addProject(array $data): array
  7523. {
  7524. $user = User::where('id', $data['user_id'])->first();
  7525. if (empty($user)) {
  7526. return Result::error("暂无相关用户信息", 0);
  7527. }
  7528. if ($user->type_id == 10000) {
  7529. $data['status'] = 1;
  7530. } else {
  7531. $data['status'] = 0;
  7532. }
  7533. if ($data['keyword'] == '') {
  7534. //提取标题+内容中的关键词
  7535. $data['keyword'] = $data['title'];
  7536. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7537. Jieba::init(); // 初始化 jieba-php
  7538. Finalseg::init();
  7539. $segList = Jieba::cut($data['keyword']);
  7540. $segList1 = array_slice($segList, 0, 8);
  7541. $data['keyword'] = implode(',', $segList1);
  7542. }
  7543. if ($data['description'] == '') {
  7544. //提取内容中的描述
  7545. // var_dump(11111);
  7546. //提取内容中的描述
  7547. $content = $data['introduce'];
  7548. // 去除 <style> 和 <script> 标签及其内容
  7549. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7550. // 去除所有 HTML 标签
  7551. $content = strip_tags($content);
  7552. // 去除 HTML 实体
  7553. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7554. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7555. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7556. // 去除多余空白
  7557. $content = preg_replace('/\s+/u', '', $content);
  7558. // 截取 100 个字符
  7559. $data['description'] = mb_substr($content, 0, 100);
  7560. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7561. }
  7562. if ($data['status'] == 0) {
  7563. $this->sendMessage([
  7564. 'talk_type' => 1000,
  7565. 'title' => $data['title'],
  7566. 'content' => '提交了审核',
  7567. 'messageType' => 9,
  7568. ]);
  7569. }
  7570. $project = Project::insertGetId($data);
  7571. if (empty($project)) {
  7572. return Result::error("暂无相关项目信息", 0);
  7573. }
  7574. return Result::success($project);
  7575. }
  7576. /**
  7577. * 更新项目
  7578. * @param array $data
  7579. * @return array
  7580. */
  7581. public function upProject(array $data): array
  7582. {
  7583. $project = Project::where('id', $data['id'])->first();
  7584. if (empty($project)) {
  7585. return Result::error("暂无相关项目信息", 0);
  7586. }
  7587. $id = $data['id'];
  7588. unset($data['id']);
  7589. $user = User::where('id', $data['user_id'])->first();
  7590. if (empty($user)) {
  7591. return Result::error("暂无相关用户信息", 0);
  7592. }
  7593. if ($user->type_id == 10000) {
  7594. $data['status'] = 1;
  7595. } else {
  7596. $data['status'] = 0;
  7597. }
  7598. unset($data['user_id']);
  7599. if ($data['keyword'] == '') {
  7600. //提取标题+内容中的关键词
  7601. $data['keyword'] = $data['title'];
  7602. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7603. Jieba::init(); // 初始化 jieba-php
  7604. Finalseg::init();
  7605. $segList = Jieba::cut($data['keyword']);
  7606. $segList1 = array_slice($segList, 0, 8);
  7607. $data['keyword'] = implode(',', $segList1);
  7608. }
  7609. if ($data['description'] == '') {
  7610. //提取内容中的描述
  7611. // var_dump(11111);
  7612. //提取内容中的描述
  7613. $content = $data['introduce'];
  7614. // 去除 <style> 和 <script> 标签及其内容
  7615. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7616. // 去除所有 HTML 标签
  7617. $content = strip_tags($content);
  7618. // 去除 HTML 实体
  7619. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7620. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7621. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7622. // 去除多余空白
  7623. $content = preg_replace('/\s+/u', '', $content);
  7624. // 截取 100 个字符
  7625. $data['description'] = mb_substr($content, 0, 100);
  7626. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7627. }
  7628. if ($data['status'] == 0) {
  7629. $this->sendMessage([
  7630. 'talk_type' => 1000,
  7631. 'title' => $data['title'],
  7632. 'content' => '提交了审核',
  7633. 'messageType' => 9,
  7634. ]);
  7635. }
  7636. $result = Project::where('id', $id)->update($data);
  7637. if (empty($result)) {
  7638. return Result::error("更新失败", 0);
  7639. }
  7640. return Result::success($result);
  7641. }
  7642. /**
  7643. * 删除项目
  7644. * @param array $data
  7645. * @return array
  7646. */
  7647. public function delProject(array $data): array
  7648. {
  7649. $user = User::where('id', $data['user_id'])->first();
  7650. if (empty($user)) {
  7651. return Result::error("暂无相关用户信息", 0);
  7652. }
  7653. $project = Project::where('id', $data['id'])->first();
  7654. if (empty($project)) {
  7655. return Result::error("暂无相关项目信息", 0);
  7656. }
  7657. $result = Project::where('id', $data['id'])->delete();
  7658. if (empty($result)) {
  7659. return Result::error("删除失败", 0);
  7660. }
  7661. return Result::success($result);
  7662. }
  7663. /**
  7664. * 审核项目
  7665. * @param array $data
  7666. * @return array
  7667. */
  7668. public function checkProject(array $data): array
  7669. {
  7670. $user = User::where('id', $data['user_id'])->first();
  7671. if (empty($user)) {
  7672. return Result::error("暂无相关用户信息", 0);
  7673. }
  7674. // 0:未审核; 1:已审核; 2:已拒绝;
  7675. if ($user->type_id != 10000) {
  7676. if ($data['status'] == 1 || $data['status'] == 2) {
  7677. return Result::error("此用户权限不足", 0);
  7678. }
  7679. }
  7680. $project = Project::where('id', $data['id'])->first();
  7681. if (empty($project)) {
  7682. return Result::error("暂无相关项目信息", 0);
  7683. }
  7684. if ($data['status'] == 2) {
  7685. $this->sendMessage([
  7686. 'talk_type' => 1001,
  7687. 'title' => $project['title'],
  7688. 'content' => '审核拒绝',
  7689. 'messageType' => 9,
  7690. 'user_id' => $project['user_id'],
  7691. ]);
  7692. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7693. } else {
  7694. if ($data['status'] == 1) {
  7695. $this->sendMessage([
  7696. 'talk_type' => 1001,
  7697. 'title' => $project['title'],
  7698. 'content' => '审核通过',
  7699. 'messageType' => 9,
  7700. 'user_id' => $project['user_id'],
  7701. ]);
  7702. } else if ($data['status'] == 0) {
  7703. $this->sendMessage([
  7704. 'talk_type' => 1000,
  7705. 'title' => $project['title'],
  7706. 'content' => '提交了审核',
  7707. 'messageType' => 9,
  7708. ]);
  7709. }
  7710. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7711. }
  7712. if (empty($result)) {
  7713. return Result::error("审核失败", 0);
  7714. }
  7715. return Result::success($result);
  7716. }
  7717. /**
  7718. * 获取项目详情
  7719. * @param array $data
  7720. * @return array
  7721. */
  7722. public function getProjectInfo(array $data): array
  7723. {
  7724. $project = Project::where('id', $data['id'])->first();
  7725. if (empty($project)) {
  7726. return Result::error("暂无相关项目信息", 0);
  7727. }
  7728. return Result::success($project);
  7729. }
  7730. public function getWebsiteCompanyInfo(array $data): array
  7731. {
  7732. $company = Company::where('id', $data['id'])
  7733. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7734. ->where('status', 1)
  7735. // ->where('website_id', $data['website_id'])
  7736. ->select('company.*', 'job_industry.hyname as hy_name')
  7737. ->first();
  7738. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7739. $jobnature_id = $company['jobnature_id'] ?? null;
  7740. if ($jobnature_id !== null) {
  7741. switch ($jobnature_id) {
  7742. case 0:
  7743. $company->jobnature_name = '市场监督';
  7744. break;
  7745. case 1:
  7746. $company->jobnature_name = '信访纪检';
  7747. break;
  7748. case 2:
  7749. $company->jobnature_name = '公检法司';
  7750. break;
  7751. case 3:
  7752. $company->jobnature_name = '高关注机构';
  7753. break;
  7754. default:
  7755. $company->jobnature_name = '';
  7756. break;
  7757. }
  7758. } else {
  7759. $company->jobnature_name = '';
  7760. }
  7761. $city_arr = $company->city_arr_id;
  7762. if (!empty($city_arr)) {
  7763. $city_arr = json_decode($city_arr, true);
  7764. $cityNames = District::whereIn('id', $city_arr)
  7765. ->pluck('name')
  7766. ->implode('-');
  7767. $company->city_name = $cityNames;
  7768. } else {
  7769. $company->city_name = '';
  7770. }
  7771. if (empty($company)) {
  7772. return Result::error("暂无相关公司信息", 0);
  7773. }
  7774. return Result::success($company);
  7775. }
  7776. public function getMSG(array $data): array
  7777. {
  7778. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7779. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7780. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7781. $result = [];
  7782. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7783. //最近的5篇已审的文章
  7784. $apply_articale = Article::where('status', 1)
  7785. ->where('admin_user_id', $user_id)
  7786. ->orderBy('updated_at', 'desc')
  7787. // ->limit(5)
  7788. ->get();
  7789. //获取5条用户的已审核商品
  7790. $good = Good::where('status', 2)
  7791. ->where('user_id', $user_id)
  7792. ->orderBy('updated_at', 'desc')
  7793. // ->limit(5)
  7794. ->get();
  7795. //获取5条用户待审核的公告
  7796. $notice = Notice::where('status', 2)
  7797. ->where('user_id', $user_id)
  7798. ->orderBy('updated_at', 'desc')
  7799. ->limit(5)->get();
  7800. //获取5条用户的待审核投诉
  7801. $complaint = Complaint::where('status', 2)
  7802. ->where('user_id', $user_id)
  7803. ->orderBy('updated_at', 'desc')
  7804. // ->limit(5)
  7805. ->get();
  7806. //获取5条用户的book
  7807. $book = Book::where('status', 2)
  7808. ->where('user_id', $user_id)
  7809. ->orderBy('updated_at', 'desc')
  7810. // ->limit(5)
  7811. ->get();
  7812. //获取5条用户的求职
  7813. //获取5条用户的求职 1
  7814. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7815. ->where('job_hunting.user_id', $user_id)
  7816. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7817. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7818. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7819. ->orderBy('updated_at', 'desc')
  7820. // ->limit(5)
  7821. ->get();
  7822. //获取5条用户的求职 2
  7823. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7824. ->where('job_recruiting.user_id', $user_id)
  7825. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7826. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7827. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7828. ->orderBy('updated_at', 'desc')
  7829. // ->limit(5)
  7830. ->get();
  7831. //人才库 1
  7832. $job_apply = JobApply::where('job_apply.status', 1)
  7833. ->where('job_apply.receiver_id', $user_id)
  7834. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7835. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7836. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7837. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7838. ->select('job_recruiting', 'job_recruiting.', '', '')
  7839. ->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')
  7840. ->orderBy('updated_at', 'desc')
  7841. // ->limit(5)
  7842. ->get();
  7843. // 职场机会 2
  7844. $job_resume = JobResume::where('job_resume.status', 1)
  7845. ->where('job_resume.receiver_id', $user_id)
  7846. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7847. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7848. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7849. ->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')
  7850. ->orderBy('updated_at', 'desc')
  7851. // ->limit(5)
  7852. ->get();
  7853. //获取5条用户待处理的投诉
  7854. $complaint_deal = Complaint::where('status', 2)
  7855. ->where('deal', 1)
  7856. ->whereJsonContains('re_user_ids', $user_id)
  7857. ->orderBy('updated_at', 'desc')
  7858. // ->limit(5)
  7859. ->get();
  7860. //获取 被通知者未读信息
  7861. $notice_unread = Notice::where('status', 2)
  7862. ->whereJsonContains('re_user_ids', $user_id)
  7863. //未读消息
  7864. ->where(function ($query) use ($user_id) {
  7865. $query->whereJsonDoesntContain('read_id', $user_id)
  7866. ->orWhereNull('read_id');
  7867. })
  7868. ->orderBy('updated_at', 'desc')
  7869. ->get();
  7870. $complaint_unread = Complaint::where('status', 2)
  7871. ->whereJsonContains('re_user_ids', $user_id)
  7872. //未读消息
  7873. ->where(function ($query) use ($user_id) {
  7874. $query->whereJsonDoesntContain('read_id', $user_id)
  7875. ->orWhereNull('read_id');
  7876. })
  7877. ->orderBy('updated_at', 'desc')
  7878. ->get();
  7879. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7880. $complany = Company::where('status', 1)
  7881. ->where('user_id', $user_id)
  7882. ->orderBy('updated_at', 'desc')
  7883. // ->limit(5)
  7884. ->get();
  7885. //获取5条单聊未读聊天消息
  7886. // $chat = ChatRecords::where('is_read', 0)
  7887. // ->where('user_id', $user_id)
  7888. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7889. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7890. // ->where('action', 'recieved')
  7891. // ->where('talk_type', 1)
  7892. // ->orderBy('created_at', 'desc')
  7893. // // ->limit(5)
  7894. // ->get();
  7895. //获取5条未读群聊信息
  7896. // $chat_group = ChatRecords::where('is_read', 0)
  7897. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7898. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7899. // ->where('user_id', $user_id)
  7900. // ->where('talk_type', 2)
  7901. // ->orderBy('created_at', 'desc')
  7902. // // ->limit(5)
  7903. // ->get();
  7904. //获取5条用户的待审核项目
  7905. $project = Project::where('status', 1)
  7906. ->where('user_id', $user_id)
  7907. ->orderBy('updated_at', 'desc')
  7908. // ->limit(5)
  7909. ->get();
  7910. // count($chat) + count($chat_group) +
  7911. $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)
  7912. + count($complany)
  7913. + count($project)
  7914. + count($notice_unread)
  7915. + count($complaint_unread)
  7916. // + count($chat) + count($chat_group)
  7917. ;
  7918. $result = [
  7919. 'apply_articale' => $apply_articale,
  7920. // 'chat' => $chat,
  7921. // 'chat_group' => $chat_group,
  7922. 'good' => $good,
  7923. 'notice' => $notice,
  7924. 'complaint' => $complaint,
  7925. 'book' => $book,
  7926. 'job_hunting' => $job_hunting,
  7927. 'job_recruiting' => $job_recruiting,
  7928. 'job_apply' => $job_apply,
  7929. 'job_resume' => $job_resume,
  7930. 'complaint_deal' => $complaint_deal,
  7931. 'complany' => $complany,
  7932. 'project' => $project,
  7933. 'notice_unread' => $notice_unread,
  7934. 'complaint_unread' => $complaint_unread,
  7935. 'count' => $count,
  7936. ];
  7937. } elseif ($type_id == 12) {
  7938. //最近的5篇已审的文章
  7939. $apply_articale = Article::where('status', 1)
  7940. ->where('admin_user_id', $user_id)
  7941. ->limit(5)->get();
  7942. //获取5条单聊未读聊天消息
  7943. $chat = ChatRecords::where('is_read', 0)
  7944. ->where('user_id', $user_id)
  7945. ->where('talk_type', 1)
  7946. ->orderBy('created_at', 'desc')
  7947. ->limit(5)->get();
  7948. //获取5条未读群聊信息
  7949. $chat_group = ChatRecords::where('is_read', 0)
  7950. ->where('user_id', $user_id)
  7951. ->where('talk_type', 2)
  7952. ->orderBy('created_at', 'desc')
  7953. ->limit(5)->get();
  7954. //获取5条用户的已审核商品
  7955. $good = Good::where('status', 2)
  7956. ->where('user_id', $user_id)
  7957. ->orderBy('updated_at', 'desc')
  7958. ->limit(5)->get();
  7959. //获取5条用户的book
  7960. $book = Book::where('status', 2)
  7961. ->where('user_id', $user_id)
  7962. ->orderBy('updated_at', 'desc')
  7963. ->limit(5)->get();
  7964. //获取5条用户的求职
  7965. //获取5条用户的求职 1
  7966. //count($chat) + count($chat_group)
  7967. $count = count($apply_articale) + count($good);
  7968. $result = [
  7969. 'apply_articale' => $apply_articale,
  7970. 'chat' => $chat,
  7971. 'chat_group' => $chat_group,
  7972. 'good' => $good,
  7973. 'book' => $book,
  7974. 'count' => $count,
  7975. ];
  7976. } elseif ($type_id == 13) {
  7977. //最近的5篇已审的文章
  7978. $apply_articale = Article::where('status', 1)
  7979. ->where('admin_user_id', $user_id)
  7980. ->limit(5)->get();
  7981. //获取5条单聊未读聊天消息
  7982. $chat = ChatRecords::where('is_read', 0)
  7983. ->where('user_id', $user_id)
  7984. ->where('talk_type', 1)
  7985. ->orderBy('created_at', 'desc')
  7986. ->limit(5)->get();
  7987. //获取5条未读群聊信息
  7988. $chat_group = ChatRecords::where('is_read', 0)
  7989. ->where('user_id', $user_id)
  7990. ->where('talk_type', 2)
  7991. ->orderBy('created_at', 'desc')
  7992. ->limit(5)->get();
  7993. //获取5条用户的已审核商品
  7994. $good = Good::where('status', 2)
  7995. ->where('user_id', $user_id)
  7996. ->orderBy('updated_at', 'desc')
  7997. ->limit(5)->get();
  7998. //count($chat) + count($chat_group) +
  7999. $count = count($apply_articale) + count($good);
  8000. $result = [
  8001. 'apply_articale' => $apply_articale,
  8002. 'chat' => $chat,
  8003. 'chat_group' => $chat_group,
  8004. 'good' => $good,
  8005. 'count' => $count,
  8006. ];
  8007. } elseif ($type_id == 14) {
  8008. //最近的5篇已审的文章
  8009. $apply_articale = Article::where('status', 1)
  8010. ->where('admin_user_id', $user_id)
  8011. // ->limit(5)
  8012. ->get();
  8013. //获取5条用户的已审核商品
  8014. $good = Good::where('status', 2)
  8015. ->where('user_id', $user_id)
  8016. ->orderBy('updated_at', 'desc')
  8017. // ->limit(5)
  8018. ->get();
  8019. $count = count($apply_articale) + count($good);
  8020. $result = [
  8021. 'apply_articale' => $apply_articale,
  8022. 'chat' => '',
  8023. 'chat_group' => '',
  8024. 'good' => $good,
  8025. 'count' => $count,
  8026. ];
  8027. } elseif ($type_id == 10000) {
  8028. //获取未审核的5篇文章
  8029. $apply_articale = Article::where('status', 0)
  8030. ->orderBy('updated_at', 'desc')
  8031. // ->limit(5)
  8032. ->get();
  8033. //获取5条单聊未读聊天消息
  8034. //获取5条单聊未读聊天消息
  8035. // $chat = ChatRecords::where('is_read', 0)
  8036. // ->where('user_id', $user_id)
  8037. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  8038. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  8039. // ->where('action', 'recieved')
  8040. // ->where('talk_type', 1)
  8041. // ->orderBy('created_at', 'desc')
  8042. // // ->limit(5)
  8043. // ->get();
  8044. // //获取5条未读群聊信息
  8045. // $chat_group = ChatRecords::where('is_read', 0)
  8046. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  8047. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  8048. // ->where('user_id', $user_id)
  8049. // ->where('talk_type', 2)
  8050. // ->orderBy('created_at', 'desc')
  8051. // // ->limit(5)
  8052. // ->get();
  8053. //获取5条用户的已审核商品
  8054. $good = Good::where('status', 1)
  8055. // ->where('user_id', $user_id)
  8056. ->orderBy('updated_at', 'desc')
  8057. // ->limit(5)
  8058. ->get();
  8059. //获取5条用户待审核的公告
  8060. $notice = Notice::where('status', 1)
  8061. ->orderBy('updated_at', 'desc')
  8062. // ->limit(5)
  8063. ->get();
  8064. //获取5条用户的待审核投诉
  8065. $complaint = Complaint::where('status', 1)
  8066. ->orderBy('updated_at', 'desc')
  8067. // ->limit(5)
  8068. ->get();
  8069. //获取5条用户的book
  8070. $book = Book::where('status', 1)
  8071. ->orderBy('updated_at', 'desc')
  8072. // ->limit(5)
  8073. ->get();
  8074. //获取5条用户的求职 1
  8075. $job_hunting = JobHunting::where('job_hunting.status', 1)
  8076. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  8077. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  8078. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  8079. ->orderBy('updated_at', 'desc')
  8080. // ->limit(5)
  8081. ->get();
  8082. //获取5条用户的求职 2
  8083. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  8084. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  8085. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  8086. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  8087. ->orderBy('updated_at', 'desc')
  8088. // ->limit(5)
  8089. ->get();
  8090. //人才库 1
  8091. $job_apply = JobApply::where('job_apply.status', 1)
  8092. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  8093. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  8094. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  8095. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  8096. ->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')
  8097. ->orderBy('updated_at', 'desc')
  8098. // ->limit(5)
  8099. ->get();
  8100. // 职场机会 2
  8101. $job_resume = JobResume::where('job_resume.status', 1)
  8102. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  8103. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  8104. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  8105. ->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')
  8106. ->orderBy('updated_at', 'desc')
  8107. // ->limit(5)
  8108. ->get();
  8109. //待审核数据com pro
  8110. $complany = Company::where('status', 0)
  8111. ->orderBy('updated_at', 'desc')
  8112. // ->limit(5)
  8113. ->get();
  8114. $project = Project::where('status', 0)
  8115. ->orderBy('updated_at', 'desc')
  8116. // ->limit(5)
  8117. ->get();
  8118. $count =
  8119. // count($chat) +
  8120. // count($chat_group) +
  8121. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  8122. // + count($job_apply)
  8123. // + count($job_resume)
  8124. + count($complany)
  8125. + count($project);
  8126. $result = [
  8127. 'apply_articale' => $apply_articale,
  8128. // 'chat' => $chat,
  8129. // 'chat_group' => $chat_group,
  8130. 'good' => $good,
  8131. 'notice' => $notice,
  8132. 'complaint' => $complaint,
  8133. 'book' => $book,
  8134. 'job_hunting' => $job_hunting,
  8135. 'job_recruiting' => $job_recruiting,
  8136. // 'job_apply' => $job_apply,
  8137. // 'job_resume' => $job_resume,
  8138. 'complany' => $complany,
  8139. 'project' => $project,
  8140. 'count' => $count,
  8141. ];
  8142. } elseif ($type_id == 20000) {
  8143. }
  8144. var_dump($type_id, '-----------------test---------');
  8145. return Result::success($result);
  8146. }
  8147. /**
  8148. * @param array $data
  8149. * @return array
  8150. */
  8151. public function getWebsiteProject(array $data): array
  8152. {
  8153. $categorys = json_decode($data['id'], true);
  8154. if (!empty($categorys)) {
  8155. $category_arr = $this->processArticlePro($data['website_id']);
  8156. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8157. $catiall = $category_arr['catiall'];
  8158. // return Result::success($catiall);
  8159. foreach ($categorys as $key => $val) {
  8160. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  8161. $level = explode(',', $val['level'])[0];
  8162. $imgnum = explode(',', $val['level'])[1] ?? null;
  8163. $textnum = explode(',', $val['level'])[2] ?? null;
  8164. if ($level == 1) {
  8165. if (!empty($textnum) && $textnum > 0) {
  8166. $text_num = Project::where('level', $level)
  8167. ->where('website_id', $data['website_id'])
  8168. ->where('status', 1)
  8169. ->select(
  8170. 'project.id',
  8171. 'project.title',
  8172. 'project.description',
  8173. 'project.updated_at',
  8174. 'project.category_id',
  8175. 'project.cat_arr_id'
  8176. )
  8177. ->orderBy('updated_at', 'desc')
  8178. ->limit($textnum)
  8179. ->get()->all();
  8180. }
  8181. if (!empty($imgnum) && $imgnum > 0) {
  8182. $img_num = Project::where('level', $level)
  8183. ->where('website_id', $data['website_id'])
  8184. ->where('status', 1)
  8185. ->where('imgurl', '!=', '')
  8186. ->whereNotNull('imgurl')
  8187. ->select(
  8188. 'project.id',
  8189. 'project.title',
  8190. 'project.description',
  8191. 'project.updated_at',
  8192. 'project.imgurl as imgs',
  8193. 'project.category_id',
  8194. 'project.cat_arr_id'
  8195. )
  8196. ->orderBy('updated_at', 'desc')
  8197. ->limit($imgnum)
  8198. ->get()->all();
  8199. }
  8200. } else {
  8201. if (!empty($textnum) && $textnum > 0) {
  8202. $text_num = Project::where('website_id', $data['website_id'])
  8203. ->where('status', 1)
  8204. ->select(
  8205. 'project.id',
  8206. 'project.title',
  8207. 'project.description',
  8208. 'project.updated_at',
  8209. 'project.category_id',
  8210. 'project.cat_arr_id',
  8211. 'project.website_id',
  8212. 'project.updated_at',
  8213. 'project.created_at'
  8214. )
  8215. ->orderBy('updated_at', 'desc')
  8216. ->limit($textnum)
  8217. ->get()->all();
  8218. }
  8219. if (!empty($imgnum) && $imgnum > 0) {
  8220. $img_num = Project::where('website_id', $data['website_id'])
  8221. ->where('status', 1)
  8222. ->where('imgurl', '!=', '')
  8223. ->whereNotNull('imgurl')
  8224. ->select(
  8225. 'project.id',
  8226. 'project.title',
  8227. 'project.description',
  8228. 'project.updated_at',
  8229. 'project.imgurl as imgs',
  8230. 'project.category_id',
  8231. 'project.cat_arr_id'
  8232. )
  8233. ->orderBy('updated_at', 'desc')
  8234. ->limit($imgnum)
  8235. ->get()->all();
  8236. }
  8237. }
  8238. }
  8239. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  8240. $category_ids = explode(',', $val['id'])[0];
  8241. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  8242. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  8243. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  8244. if (!empty($cat_textnum) && $cat_textnum > 0) {
  8245. $text_num = Project::whereIn('category_id', $category_arr)
  8246. ->where('website_id', $data['website_id'])
  8247. ->where('status', 1)
  8248. ->select(
  8249. 'project.id',
  8250. 'project.title',
  8251. 'project.description',
  8252. 'project.updated_at',
  8253. 'project.category_id',
  8254. 'project.cat_arr_id'
  8255. )
  8256. ->orderBy('updated_at', 'desc')
  8257. ->limit($cat_textnum)
  8258. ->get()->all();
  8259. }
  8260. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  8261. $img_num = Project::whereIn('category_id', $category_arr)
  8262. ->where('website_id', $data['website_id'])
  8263. ->where('status', 1)
  8264. ->where('imgurl', '!=', '')
  8265. ->whereNotNull('imgurl')
  8266. ->select(
  8267. 'project.id',
  8268. 'project.title',
  8269. 'project.description',
  8270. 'project.updated_at',
  8271. 'project.imgurl as imgs',
  8272. 'project.category_id',
  8273. 'project.cat_arr_id'
  8274. )
  8275. ->orderBy('updated_at', 'desc')
  8276. ->limit($cat_imgnum)
  8277. ->get()->all();
  8278. }
  8279. }
  8280. if (!empty($img_num)) {
  8281. foreach ($img_num as $k => $v) {
  8282. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8283. $imgurl = json_decode($v['imgs'], true);
  8284. if (!empty($imgurl)) {
  8285. $img_num[$k]->imgurl = $imgurl[0];
  8286. }
  8287. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8288. }
  8289. }
  8290. if (!empty($text_num)) {
  8291. foreach ($text_num as $k => $v) {
  8292. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8293. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8294. }
  8295. }
  8296. $project[$key]['img_num'] = $img_num ?? [];
  8297. $project[$key]['text_num'] = $text_num ?? [];
  8298. }
  8299. }
  8300. if (empty($project)) {
  8301. return Result::error("暂无相关项目信息", 0);
  8302. }
  8303. return Result::success($project);
  8304. }
  8305. /**
  8306. * @param array $data
  8307. * @return array
  8308. */
  8309. public function getWebsiteProjectInfo(array $data): array
  8310. {
  8311. $project = Project::where('id', $data['id'])
  8312. ->where('status', 1)
  8313. ->where('website_id', $data['website_id'])
  8314. ->select('project.*')
  8315. ->first();
  8316. if (empty($project)) {
  8317. return Result::error("暂无相关项目信息", 0);
  8318. }
  8319. return Result::success($project);
  8320. }
  8321. /**
  8322. * @param array $data
  8323. * @return array
  8324. */
  8325. public function getWebsiteProjectList(array $data): array
  8326. {
  8327. $where = [];
  8328. if (isset($data['category_id']) && !empty($data['category_id'])) {
  8329. $where['category_id'] = $data['category_id'];
  8330. }
  8331. if (isset($data['keyword']) && !empty($data['keyword'])) {
  8332. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  8333. }
  8334. $query = Project::where($where)
  8335. ->where('status', 1)
  8336. ->where('website_id', $data['website_id'])
  8337. ->select(
  8338. 'project.id',
  8339. 'project.title',
  8340. 'project.description',
  8341. 'project.imgurl as imgs',
  8342. 'project.category_id',
  8343. 'project.cat_arr_id'
  8344. )
  8345. ->orderBy('updated_at', 'desc');
  8346. $count = $query->count();
  8347. $project = $query->clone()
  8348. ->offset(($data['page'] - 1) * $data['pageSize'])
  8349. ->limit($data['pageSize'])
  8350. ->get()->all();
  8351. if (empty($project)) {
  8352. return Result::error("暂无相关项目信息", 0);
  8353. }
  8354. $categorys = $this->processArticlePro($data['website_id']);
  8355. $catiall = $categorys['catiall'];
  8356. foreach ($project as $key => $val) {
  8357. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  8358. if (!empty($val['imgs'])) {
  8359. $imgurl = json_decode($val['imgs'], true);
  8360. if (!empty($imgurl)) {
  8361. $project[$key]->imgurl = $imgurl[0];
  8362. }
  8363. } else {
  8364. $project[$key]->imgurl = '';
  8365. }
  8366. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  8367. }
  8368. $result = [
  8369. 'rows' => $project,
  8370. 'count' => $count,
  8371. ];
  8372. return Result::success($result);
  8373. }
  8374. /**
  8375. * @param array $data
  8376. * @return array
  8377. */
  8378. public function getWebsiteCategoryJob(array $data): array
  8379. {
  8380. $categorys = json_decode($data['id'], true);
  8381. if (!empty($categorys)) {
  8382. $category_arr = $this->processArticlePro($data['website_id']);
  8383. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8384. $catiall = $category_arr['catiall'];
  8385. foreach ($categorys as $key => $val) {
  8386. if (isset($val['id']) && !empty($val['id'])) {
  8387. $catid = explode(',', $val['id'])[0] ?? null;
  8388. $type = explode(',', $val['id'])[1] ?? null;
  8389. $textnum = explode(',', $val['id'])[2] ?? null;
  8390. }
  8391. // 4:招聘;5:求职;
  8392. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  8393. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  8394. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  8395. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  8396. ->where('job_recruiting.status', 1)
  8397. ->where('job_recruiting.website_id', $data['website_id'])
  8398. ->select(
  8399. 'job_recruiting.id',
  8400. 'job_recruiting.title',
  8401. 'job_company.business_name',
  8402. 'job_recruiting.updated_at',
  8403. 'job_recruiting.cat_arr_id',
  8404. 'job_recruiting.keyword',
  8405. 'job_recruiting.description'
  8406. )
  8407. ->orderBy('job_recruiting.updated_at', 'desc')
  8408. ->limit($textnum)
  8409. ->get()->all();
  8410. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  8411. // 状态 审核状态,1待审核2已审核3已拒绝
  8412. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  8413. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  8414. ->where('job_hunting.status', 2)
  8415. ->where('job_hunting.website_id', $data['website_id'])
  8416. ->select(
  8417. 'job_hunting.id',
  8418. 'job_hunting.name',
  8419. 'job_hunting.cat_arr_id',
  8420. 'job_position.zwname as job_name',
  8421. 'job_hunting.updated_at',
  8422. // 'job_hunting.keyword',
  8423. 'job_hunting.slelf_evaluation'
  8424. )
  8425. ->orderBy('updated_at', 'desc')
  8426. ->limit($textnum)
  8427. ->get()->all();
  8428. } else {
  8429. $job = [];
  8430. }
  8431. // var_dump($catid.'222uuuuuuu'.$key);
  8432. if (!empty($job)) {
  8433. foreach ($job as $k => $value) {
  8434. if (isset($value->cat_arr_id)) {
  8435. $catArr = json_decode($value->cat_arr_id, true);
  8436. $catId = end($catArr);
  8437. } else {
  8438. continue;
  8439. }
  8440. if (isset($catiall[$catId])) {
  8441. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  8442. }
  8443. }
  8444. }
  8445. // var_dump($catid.'xxxxx'.$key);
  8446. $result[$key] = $job ?? [];
  8447. }
  8448. }
  8449. if (empty($result)) {
  8450. return Result::error("暂无相关分类信息", 0);
  8451. }
  8452. return Result::success($result);
  8453. }
  8454. /**
  8455. * 发送消息
  8456. * @param array $messageData
  8457. * @return void
  8458. */
  8459. public function sendMessage($messageData)
  8460. {
  8461. $msg = [
  8462. 'talk_type' => $messageData['talk_type'],
  8463. 'title' => $messageData['title'],
  8464. 'content' => $messageData['content'],
  8465. 'messageType' => $messageData['messageType'],
  8466. 'user_id' => $messageData['user_id'] ?? '',
  8467. 'time' => microtime(),
  8468. ];
  8469. $message = new MqProducer($msg);
  8470. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  8471. $producer->produce($message);
  8472. }
  8473. /**
  8474. * 行业分类管理 ------1121
  8475. * @param array $data
  8476. * @return array
  8477. */
  8478. public function getJobIndustryList(array $data): array
  8479. {
  8480. $page = $data['page'] ?? 1;
  8481. $page_size = $data['page_size'] ?? 10;
  8482. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8483. $where = ['hyname', 'like', '%' . $data['hyname'] . '%'];
  8484. } else {
  8485. $where = [];
  8486. }
  8487. $rs_query = JobIndustry::when(!empty($where), function ($query) use ($where) {
  8488. $query->where([$where]); // 修复:将条件包装成二维数组
  8489. })
  8490. ->orderBy('updated_at', 'desc');
  8491. $count = $rs_query->count();
  8492. $hy = $rs_query->offset(($page - 1) * $page_size)->limit($page_size)->get()->all();
  8493. $result = [
  8494. 'count' => $count,
  8495. 'list' => $hy,
  8496. ];
  8497. if (empty($hy)) {
  8498. return Result::success('暂无数据');
  8499. }
  8500. return Result::success($result);
  8501. }
  8502. /**
  8503. * 添加行业分类
  8504. * @param array $data
  8505. * @return array
  8506. */
  8507. public function addJobIndustry(array $data): array
  8508. {
  8509. $hy_name = JobIndustry::where('hyname', $data['hyname'])->first(['hyid']);
  8510. if (!empty($hy_name)) {
  8511. return Result::error('行业分类已存在');
  8512. }
  8513. $hy = JobIndustry::insertGetId($data);
  8514. if (empty($hy)) {
  8515. return Result::error('添加失败');
  8516. }
  8517. return Result::success($hy);
  8518. }
  8519. /**
  8520. * 更新行业分类
  8521. * @param array $data
  8522. * @return array
  8523. */
  8524. public function upJobIndustry(array $data): array
  8525. {
  8526. $hy_query = JobIndustry::get();
  8527. $hy_ids = $hy_query->pluck('hyid')->toArray();
  8528. $hy_names = $hy_query->pluck('hyname')->toArray();
  8529. if (!in_array($data['hyid'], $hy_ids)) {
  8530. return Result::error('行业分类不存在');
  8531. }
  8532. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8533. $other_key_hy = array_search($data['hyid'], $hy_ids);
  8534. // return Result::success($other_key_hy);
  8535. unset($hy_names[$other_key_hy]);
  8536. if (in_array($data['hyname'], $hy_names)) {
  8537. return Result::error('行业分类名称已存在');
  8538. }
  8539. }
  8540. $hy = JobIndustry::where('hyid', $data['hyid'])->update($data);
  8541. if (empty($hy)) {
  8542. return Result::error('更新失败');
  8543. }
  8544. return Result::success($hy);
  8545. }
  8546. /**
  8547. * 删除行业分类
  8548. * @param array $data
  8549. * @return array
  8550. */
  8551. public function delJobIndustry(array $data): array
  8552. {
  8553. $hy_id = JobIndustry::where('hyid', $data['hyid'])->first(['hyid']);
  8554. if (empty($hy_id)) {
  8555. return Result::error('行业分类不存在');
  8556. }
  8557. $hy = JobIndustry::where('hyid', $data['hyid'])->delete();
  8558. if (empty($hy)) {
  8559. return Result::error('删除失败');
  8560. }
  8561. return Result::success($hy);
  8562. }
  8563. /**
  8564. * 职位分类-列表
  8565. * @param array $data
  8566. * @return array
  8567. */
  8568. public function getJobPositionList(array $data): array
  8569. {
  8570. $page = $data['page'] ?? 1;
  8571. $page_size = $data['page_size'] ?? 10;
  8572. $where = [];
  8573. if (isset($data['zwname']) && !empty($data['zwname'])) {
  8574. $zwids = JobPosition::where('zwpid', 0)
  8575. ->when(!empty($data['zwname']), function ($query) use ($data) {
  8576. $query->where('zwname', 'like', '%' . $data['zwname'] . '%');
  8577. })
  8578. ->orderBy('updated_at', 'desc')
  8579. ->pluck('zwid')
  8580. // ->get()
  8581. ->toArray();
  8582. }
  8583. if (isset($data['childname']) && !empty($data['childname'])) {
  8584. $child_zwids = JobPosition::where('zwpid', '!=', 0)
  8585. ->when(!empty($data['childname']), function ($query) use ($data) {
  8586. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8587. })
  8588. ->orderBy('updated_at', 'desc')
  8589. ->pluck('zwpid')
  8590. // ->get()
  8591. ->toArray();
  8592. if (isset($zwids) && is_array($zwids) && is_array($child_zwids)) {
  8593. $child_zwids = array_intersect($zwids, $child_zwids);
  8594. }
  8595. $zwids = array_values(array_unique($child_zwids));
  8596. }
  8597. $zwids = $zwids ?? null;
  8598. $count = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8599. $query->whereIn('zwid', $zwids);
  8600. })
  8601. ->where('zwpid', 0)
  8602. ->count();
  8603. $position = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8604. $query->whereIn('zwid', $zwids);
  8605. })
  8606. ->where('zwpid', 0)
  8607. ->orderBy('updated_at', 'desc')
  8608. ->offset(($page - 1) * $page_size)
  8609. ->limit($page_size)->get()
  8610. ->map(function ($item) use ($data) {
  8611. $item->children = $item->where('zwpid', $item->zwid)
  8612. ->when(!empty($data['childname']), function ($query) use ($data) {
  8613. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8614. })
  8615. ->orderBy('updated_at', 'desc')
  8616. ->get();
  8617. return $item;
  8618. })
  8619. ->all();
  8620. $result = [
  8621. 'count' => $count,
  8622. 'list' => $position,
  8623. ];
  8624. if (empty($result)) {
  8625. return Result::success('暂无数据');
  8626. }
  8627. return Result::success($result);
  8628. }
  8629. /**
  8630. * 职位分类-添加
  8631. * @param array $data
  8632. * @return array
  8633. */
  8634. public function addJobPosition(array $data): array
  8635. {
  8636. $zw_name = JobPosition::where('zwpid', $data['zwpid'])
  8637. ->where('zwname', $data['zwname'])->first(['zwid']);
  8638. if (!empty($zw_name)) {
  8639. return Result::error('职位分类已存在');
  8640. }
  8641. $zw = JobPosition::insertGetId($data);
  8642. if(empty($zw)){
  8643. return Result::error('添加失败');
  8644. }
  8645. return Result::success($zw);
  8646. }
  8647. /**
  8648. * 更新职位分类
  8649. * @param array $data
  8650. * @return array
  8651. */
  8652. public function upJobPosition(array $data): array
  8653. {
  8654. $zw_position = JobPosition::get();
  8655. if (!in_array($data['zwid'], $zw_position->pluck('zwid')->toArray())) {
  8656. return Result::error('职位分类不存在');
  8657. }
  8658. $zw_name = $zw_position->where('zwid', '!=', $data['zwid'])
  8659. ->where('zwpid', $data['zwpid'])
  8660. ->where('zwname', $data['zwname'])->first();
  8661. if (!empty($zw_name)) {
  8662. return Result::error('职位分类已存在');
  8663. }
  8664. $result = JobPosition::where('zwid', $data['zwid'])->update($data);
  8665. if (empty($result)) {
  8666. return Result::error('更新失败');
  8667. }
  8668. return Result::success($result);
  8669. }
  8670. /**
  8671. * 删除职位分类
  8672. * @param array $data
  8673. * @return array
  8674. */
  8675. public function delJobPosition(array $data): array
  8676. {
  8677. $zw_jobposition = JobPosition::get();
  8678. $zw_id = $zw_jobposition->where('zwid', $data['zwid'])->first();
  8679. if (empty($zw_id)) {
  8680. return Result::error('职位分类不存在');
  8681. }
  8682. if($zw_id->zwpid == 0){
  8683. $zw_job = JobPosition::where('zwpid', $zw_id->zwid)->first();
  8684. if(!empty($zw_job)){
  8685. return Result::error('请先删除子分类');
  8686. }
  8687. }
  8688. $result = JobPosition::where('zwid', $data['zwid'])->delete();
  8689. if (empty($result)) {
  8690. return Result::error('删除失败');
  8691. }
  8692. return Result::success($result);
  8693. }
  8694. /**
  8695. * 网民留言-添加
  8696. * @param array $data
  8697. * @return array
  8698. */
  8699. public function addMessage(array $data): array
  8700. {
  8701. $user = User::where('id', $data['user_id'])->first();
  8702. if (empty($user)) {
  8703. return Result::error('用户不存在');
  8704. }
  8705. if($user['type_id'] == 10000){
  8706. $data['status'] = 1;
  8707. }else{
  8708. $data['status'] = 0;
  8709. }
  8710. if ($data['keyword'] == '') {
  8711. //提取标题+内容中的关键词
  8712. $data['keyword'] = $data['title'];
  8713. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  8714. Jieba::init(); // 初始化 jieba-php
  8715. Finalseg::init();
  8716. $segList = Jieba::cut($data['keyword']);
  8717. $segList1 = array_slice($segList, 0, 8);
  8718. $data['keyword'] = implode(',', $segList1);
  8719. }
  8720. if ($data['description'] == '') {
  8721. //提取内容中的描述
  8722. $content = $data['content'];
  8723. // 去除 <style> 和 <script> 标签及其内容
  8724. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  8725. // 去除所有 HTML 标签
  8726. $content = strip_tags($content);
  8727. // 去除 HTML 实体
  8728. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  8729. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  8730. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  8731. // 去除多余空白
  8732. $content = preg_replace('/\s+/u', '', $content);
  8733. // 截取 100 个字符
  8734. $data['description'] = mb_substr($content, 0, 100);
  8735. }
  8736. if(!empty($data['reply'])){
  8737. $data['reply_userid'] = $data['user_id'];
  8738. }
  8739. $result = Message::insertGetId($data);
  8740. if(empty($result)){
  8741. return Result::error('添加失败');
  8742. }
  8743. return Result::success($result);
  8744. }
  8745. /**
  8746. * 网民留言-更新
  8747. * @param array $data
  8748. * @return array
  8749. */
  8750. public function upMessage(array $data): array
  8751. {
  8752. $user = User::where('id', $data['user_id'])->first();
  8753. if (empty($user)) {
  8754. return Result::error('用户不存在');
  8755. }
  8756. if($user['type_id'] == 10000){
  8757. $data['status'] = 1;
  8758. }else{
  8759. $data['status'] = 0;
  8760. }
  8761. $message = Message::where('id', $data['id'])->first();
  8762. if (empty($message)) {
  8763. return Result::error('留言不存在');
  8764. }
  8765. if($data['user_id'] != $message['user_id'] && $user['type_id'] != 10000){
  8766. return Result::error('非留言人不能更新');
  8767. }
  8768. if ($data['keyword'] == '') {
  8769. //提取标题+内容中的关键词
  8770. $data['keyword'] = $data['title'];
  8771. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  8772. Jieba::init(); // 初始化 jieba-php
  8773. Finalseg::init();
  8774. $segList = Jieba::cut($data['keyword']);
  8775. $segList1 = array_slice($segList, 0, 8);
  8776. $data['keyword'] = implode(',', $segList1);
  8777. }
  8778. if ($data['description'] == '') {
  8779. //提取内容中的描述
  8780. $content = $data['content'];
  8781. // 去除 <style> 和 <script> 标签及其内容
  8782. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  8783. // 去除所有 HTML 标签
  8784. $content = strip_tags($content);
  8785. // 去除 HTML 实体
  8786. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  8787. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  8788. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  8789. // 去除多余空白
  8790. $content = preg_replace('/\s+/u', '', $content);
  8791. // 截取 100 个字符
  8792. $data['description'] = mb_substr($content, 0, 100);
  8793. }
  8794. unset($data['id']);
  8795. if(!empty($data['reply'])){
  8796. $data['reply_userid'] = $data['user_id'];
  8797. unset($data['user_id']);
  8798. }
  8799. $result = Message::where('id', $message['id'])->update($data);
  8800. if (empty($result)) {
  8801. return Result::error('更新失败');
  8802. }
  8803. return Result::success($result);
  8804. }
  8805. /**
  8806. * 网民留言-删除
  8807. * @param array $data
  8808. * @return array
  8809. */
  8810. public function delMessage(array $data): array
  8811. {
  8812. $result = Message::where('id', $data['id'])->delete();
  8813. if (empty($result)) {
  8814. return Result::error('删除失败');
  8815. }
  8816. return Result::success($result);
  8817. }
  8818. /**
  8819. * 网民留言-更新状态
  8820. * @param array $data
  8821. * @return array
  8822. */
  8823. public function upMessageStatus(array $data): array
  8824. {
  8825. $message = Message::where('id', $data['id'])->first();
  8826. if (empty($message)) {
  8827. return Result::error('留言不存在!');
  8828. }
  8829. unset($data['id']);
  8830. unset($data['user_id']);
  8831. if($data['status'] != 2){
  8832. $data['reason'] = null;
  8833. }
  8834. $result = Message::where('id', $message['id'])->update($data);
  8835. if (empty($result)) {
  8836. return Result::error('留言更新失败!');
  8837. }
  8838. return Result::success($result);
  8839. }
  8840. /**
  8841. * 网民留言-获取详情
  8842. * @param array $data
  8843. * @return array
  8844. */
  8845. public function getMessageInfo(array $data): array
  8846. {
  8847. $result = Message::where('message.id', $data['id'])
  8848. ->leftJoin('website_column', 'message.column_id', '=', 'website_column.id')
  8849. ->select('message.*', 'website_column.column_arr_id')
  8850. ->first();
  8851. if (empty($result)) {
  8852. return Result::error('留言不存在!');
  8853. }
  8854. $result['column_arr_id'] = json_decode($result['column_arr_id'] ?? [], true);
  8855. return Result::success($result);
  8856. }
  8857. /**
  8858. * 网民留言-获取列表
  8859. * @param array $data
  8860. * @return array
  8861. */
  8862. public function getMessageList(array $data): array
  8863. {
  8864. $where = [];
  8865. if($data['is_master'] == 1){
  8866. $where['message.status'] = 1;
  8867. }else if($data['is_master'] == 2){
  8868. $where['message.status'] = 2;
  8869. }else if($data['is_master'] == 3){
  8870. $where['message.status'] = 0;
  8871. }
  8872. $user = User::where('id', $data['user_id'])->first();
  8873. if (empty($user)) {
  8874. return Result::error('用户不存在');
  8875. }
  8876. $column_arr_id = [];
  8877. if($user['type_id'] != 10000 && !empty($data['website_id'])){
  8878. $where['message.user_id'] = $data['user_id'];
  8879. $web = Website::where('id',$data['website_id'])->first('website_column_arr_id');
  8880. if(empty($web)){
  8881. return Result::error('此网站未关联任何网站属性!');
  8882. }
  8883. $column_arr_id = json_decode($web['website_column_arr_id'],true);
  8884. }
  8885. if(!empty($data['title'])){
  8886. array_push($where, ['message.title', 'like', '%'.$data['title'].'%']);
  8887. }
  8888. $result = Message::when($data['is_master'] == 0, function ($query) {
  8889. $query->whereIn('message.status', [0, 2]);
  8890. })
  8891. ->when(!empty($where), function ($query) use ($where) {
  8892. $query->where($where);
  8893. })
  8894. ->leftJoin('user', 'message.user_id', '=', 'user.id')
  8895. ->select('message.*', 'user.nickname')
  8896. ->orderBy('message.updated_at', 'desc')
  8897. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  8898. if(empty($result->items())) {
  8899. return Result::error('留言不存在!');
  8900. }
  8901. $result = [
  8902. 'data' => $result->items(),
  8903. 'count' => $result->total(),
  8904. ];
  8905. if(!empty($column_arr_id) && $user['type_id'] != 10000){
  8906. foreach($result['data'] as $key => $value){
  8907. if(in_array($value['column_id'], $column_arr_id)){
  8908. $result['data'][$key]['is_update'] = 1;
  8909. }else{
  8910. $result['data'][$key]['is_update'] = 0;
  8911. }
  8912. }
  8913. }
  8914. return Result::success($result);
  8915. }
  8916. /**
  8917. * 网民留言-检查是否可编辑
  8918. * @param array $data
  8919. * @return array
  8920. */
  8921. public function checkMessageEdit(array $data): array
  8922. {
  8923. $message = Message::where('id', $data['id'])->first();
  8924. if (empty($message)) {
  8925. return Result::error('留言不存在!');
  8926. }
  8927. $web = Website::where('id', $data['website_id'])->first();
  8928. if (empty($web)) {
  8929. return Result::error('网站不存在!');
  8930. }
  8931. $column_arr = json_decode($web['website_column_arr_id'] ?? [], true);
  8932. if(empty($column_arr)){
  8933. return Result::error('该网站未关联任何属性!');
  8934. }
  8935. if(!in_array($message['column_id'], $column_arr)){
  8936. return Result::error('不可编辑');
  8937. }
  8938. return Result::success('可编辑');
  8939. }
  8940. /**
  8941. * 调研选题-获取所有Researchers
  8942. * @param array $data
  8943. * @return array
  8944. */
  8945. public function getAllResearcher(array $data): array
  8946. {
  8947. $where['role_user.role_id'] = 21;
  8948. if(!empty($data['id'])){
  8949. $where['user.id'] = $data['id'];
  8950. }
  8951. if(!empty($data['real_name'])){
  8952. array_push($where, ['user_info.real_name', 'like', '%'.$data['real_name'].'%']);
  8953. }
  8954. $users = User::leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  8955. ->leftJoin('role_user', 'user.id', '=', 'role_user.user_id')
  8956. ->where($where)
  8957. ->select('user.id', 'user_info.real_name','user_info.number')
  8958. ->get()->toArray();
  8959. if (empty($users)) {
  8960. return Result::error('此调研员不存在!');
  8961. }
  8962. $user_number = array_search($data['user_id'], array_column($users, 'id'));
  8963. if($user_number == false){
  8964. $result['number'] = null;
  8965. }else{
  8966. $result['number'] = $users[$user_number]['number'];
  8967. }
  8968. $result['users'] = $users;
  8969. $result['user_id'] = $data['user_id'];
  8970. return Result::success($result);
  8971. }
  8972. /**
  8973. * 调研选题-添加
  8974. * @param array $data
  8975. * @return array
  8976. */
  8977. public function addResearchTopic(array $data): array
  8978. {
  8979. $user = User::where('id', $data['user_id'])->first();
  8980. if (empty($user)) {
  8981. return Result::error('用户不存在');
  8982. }
  8983. if($user['type_id'] == 10000){
  8984. $data['status'] = 1;
  8985. }else{
  8986. $data['status'] = 0;
  8987. }
  8988. if ($data['keyword'] == '') {
  8989. //提取标题+内容中的关键词
  8990. $data['keyword'] = $data['title'];
  8991. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  8992. Jieba::init(); // 初始化 jieba-php
  8993. Finalseg::init();
  8994. $segList = Jieba::cut($data['keyword']);
  8995. $segList1 = array_slice($segList, 0, 8);
  8996. $data['keyword'] = implode(',', $segList1);
  8997. }
  8998. if ($data['description'] == '') {
  8999. //提取内容中的描述
  9000. $content = $data['content'];
  9001. // 去除 <style> 和 <script> 标签及其内容
  9002. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9003. // 去除所有 HTML 标签
  9004. $content = strip_tags($content);
  9005. // 去除 HTML 实体
  9006. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9007. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9008. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9009. // 去除多余空白
  9010. $content = preg_replace('/\s+/u', '', $content);
  9011. // 截取 100 个字符
  9012. $data['description'] = mb_substr($content, 0, 100);
  9013. }
  9014. $data['level'] = empty($data['level']) ? null : $data['level'];
  9015. $data['province_id'] = empty($data['province_id']) ? null : $data['province_id'];
  9016. $data['city_id'] = empty($data['city_id']) ? null : $data['city_id'];
  9017. $data['county_id'] = empty($data['county_id']) ? null : $data['county_id'];
  9018. $data['due_time'] = empty($data['due_time']) ? null : $data['due_time'];
  9019. $users_id = empty($data['users_id']) ? null : $data['users_id'];
  9020. unset($data['users_id']);
  9021. // return Result::success($data);
  9022. Db::beginTransaction();
  9023. try{
  9024. $result = ResearchTopic::insertGetId($data);
  9025. if (empty($result)) {
  9026. Db::rollBack();
  9027. return Result::error('添加失败');
  9028. }
  9029. if(!empty($users_id) && is_string($users_id)){
  9030. $users = json_decode($users_id ?? '[]',true);
  9031. }
  9032. $users_type4 = User::where('type_id', 4)->pluck('id');
  9033. $type4_num = array_intersect($users, $users_type4->toArray());
  9034. if(count($users) != count($type4_num)){
  9035. Db::rollBack();
  9036. return Result::error('请选择调研员!');
  9037. }
  9038. // return Result::success($users);
  9039. if(!empty($users) && is_array($users)){
  9040. // 去重:确保同一 retopic_id + user_id 组合唯一
  9041. $users = array_values(array_unique($users));
  9042. // 组装关联数据
  9043. $users_topic = [];
  9044. foreach ($users as $key => $value) {
  9045. $users_topic[$key] = [
  9046. 'user_id' => $value,
  9047. 'retopic_id' => $result,
  9048. ];
  9049. }
  9050. // 使用 insertOrIgnore 忽略重复主键/唯一索引冲突
  9051. $retopic_user = RetopicUser::insert($users_topic);
  9052. if(empty($retopic_user)){
  9053. Db::rollBack();
  9054. return Result::error('添加失败');
  9055. }
  9056. }
  9057. Db::commit();
  9058. return Result::success($result);
  9059. }catch(\Exception $e){
  9060. Db::rollBack();
  9061. return Result::error($e->getMessage());
  9062. }
  9063. }
  9064. /**
  9065. * 调研选题-编辑
  9066. * @param array $data
  9067. * @return array
  9068. */
  9069. public function upResearchTopic(array $data): array
  9070. {
  9071. $user = User::where('id', $data['user_id'])->first();
  9072. if (empty($user)) {
  9073. return Result::error('用户不存在');
  9074. }
  9075. if($user['type_id'] == 10000){
  9076. $data['status'] = 1;
  9077. }else{
  9078. $data['status'] = 0;
  9079. }
  9080. $topic = ResearchTopic::where('id', $data['id'])->first();
  9081. if (empty($topic)) {
  9082. return Result::error('此调研选题不存在');
  9083. }
  9084. if ($data['keyword'] == '') {
  9085. //提取标题+内容中的关键词
  9086. $data['keyword'] = $data['title'];
  9087. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  9088. Jieba::init(); // 初始化 jieba-php
  9089. Finalseg::init();
  9090. $segList = Jieba::cut($data['keyword']);
  9091. $segList1 = array_slice($segList, 0, 8);
  9092. $data['keyword'] = implode(',', $segList1);
  9093. }
  9094. if ($data['description'] == '') {
  9095. //提取内容中的描述
  9096. $content = $data['content'];
  9097. // 去除 <style> 和 <script> 标签及其内容
  9098. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9099. // 去除所有 HTML 标签
  9100. $content = strip_tags($content);
  9101. // 去除 HTML 实体
  9102. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9103. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9104. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9105. // 去除多余空白
  9106. $content = preg_replace('/\s+/u', '', $content);
  9107. // 截取 100 个字符
  9108. $data['description'] = mb_substr($content, 0, 100);
  9109. }
  9110. $data['level'] = empty($data['level']) ? null : $data['level'];
  9111. $data['province_id'] = empty($data['province_id']) ? null : $data['province_id'];
  9112. $data['city_id'] = empty($data['city_id']) ? null : $data['city_id'];
  9113. $data['county_id'] = empty($data['county_id']) ? null : $data['county_id'];
  9114. $data['due_time'] = empty($data['due_time']) ? null : $data['due_time'];
  9115. $users_id = empty($data['users_id']) ? null : $data['users_id'];
  9116. $id = $data['id'];
  9117. unset($data['users_id']);
  9118. unset($data['id']);
  9119. // return Result::success($data);
  9120. Db::beginTransaction();
  9121. try{
  9122. $result = ResearchTopic::where('id', $id)->update($data);
  9123. if (empty($result)) {
  9124. Db::rollBack();
  9125. return Result::error('编辑调研选题失败!');
  9126. }
  9127. if(!empty($users_id) && is_string($users_id)){
  9128. $users = json_decode($users_id ?? '[]',true);
  9129. }
  9130. // return Result::success($users);
  9131. $retopic_users = RetopicUser::where('retopic_id', $id)->pluck('user_id')->toArray();
  9132. if(!empty($retopic_users)){
  9133. $del_users = RetopicUser::where('retopic_id', $id)->delete();
  9134. if(empty($del_users)){
  9135. Db::rollBack();
  9136. return Result::error('编辑同行人员失败!');
  9137. }
  9138. }
  9139. if(!empty($users) && is_array($users)){
  9140. // 去重:确保同一 retopic_id + user_id 组合唯一
  9141. $users = array_values(array_unique($users));
  9142. // 组装关联数据
  9143. $users_topic = [];
  9144. foreach ($users as $key => $value) {
  9145. $users_topic[$key] = [
  9146. 'user_id' => $value,
  9147. 'retopic_id' => $id,
  9148. ];
  9149. }
  9150. // 使用 insertOrIgnore 忽略重复主键/唯一索引冲突
  9151. $retopic_user = RetopicUser::insert($users_topic);
  9152. if(empty($retopic_user)){
  9153. Db::rollBack();
  9154. return Result::error('编辑失败');
  9155. }
  9156. }
  9157. Db::commit();
  9158. return Result::success($result);
  9159. }catch(\Exception $e){
  9160. Db::rollBack();
  9161. return Result::error($e->getMessage());
  9162. }
  9163. }
  9164. /**
  9165. * 调研选题-删除
  9166. * @param array $data
  9167. * @return array
  9168. */
  9169. public function delResearchTopic(array $data): array
  9170. {
  9171. $user = User::where('id', $data['user_id'])->first();
  9172. if (empty($user)) {
  9173. return Result::error('用户不存在');
  9174. }
  9175. $topic = ResearchTopic::where('id', $data['id'])->first();
  9176. if (empty($topic)) {
  9177. return Result::error('此调研选题不存在');
  9178. }
  9179. Db::beginTransaction();
  9180. try{
  9181. $result = ResearchTopic::where('id', $data['id'])->delete();
  9182. if (empty($result)) {
  9183. Db::rollBack();
  9184. return Result::error('删除调研选题失败!');
  9185. }
  9186. $topic_users = RetopicUser::where('retopic_id', $data['id'])->pluck('user_id')->toArray();
  9187. if(!empty($topic_users)){
  9188. $del_topic_users = RetopicUser::where('retopic_id', $data['id'])->delete();
  9189. if(empty($del_topic_users)){
  9190. Db::rollBack();
  9191. return Result::error('删除同行人员失败!');
  9192. }
  9193. }
  9194. Db::commit();
  9195. return Result::success($result);
  9196. }catch(\Exception $e){
  9197. Db::rollBack();
  9198. return Result::error($e->getMessage());
  9199. }
  9200. }
  9201. /**
  9202. * 调研选题-列表
  9203. * @param array $data
  9204. * @return array
  9205. */
  9206. public function getResearchTopicList(array $data): array
  9207. {
  9208. $user = User::where('id', $data['user_id'])->first();
  9209. if (empty($user)) {
  9210. return Result::error('用户不存在!');
  9211. }
  9212. $where = [];
  9213. if($user->type_id != 10000){
  9214. $where['research_topic.user_id'] = $data['user_id'];
  9215. $website = Website::where('id', $data['website_id'])->first();
  9216. if (empty($website)) {
  9217. return Result::error('网站不存在!');
  9218. }
  9219. $web_column = json_decode($website->website_column_arr_id ?? '[]',true);
  9220. if(empty($web_column)){
  9221. return Result::error('网站未配置栏目!');
  9222. }
  9223. }
  9224. if($data['is_master'] != 0){
  9225. if($data['is_master'] == 3){
  9226. $where['research_topic.status'] = 0;
  9227. }else{
  9228. $where['research_topic.status'] = $data['is_master'];
  9229. }
  9230. }
  9231. if(!empty($data['title'])){
  9232. array_push($where, ['research_topic.title', 'like', '%'.$data['title'].'%']);
  9233. }
  9234. $page = $data['page'] ?? 1;
  9235. $page_size = $data['page_size'] ?? 10;
  9236. $research_topic = ResearchTopic::when($data['is_master'] == 0, function($query) use($data){
  9237. $query->whereIn('research_topic.status', [0,2]);
  9238. })
  9239. ->when(!empty($where), function($query) use($where){
  9240. $query->where($where);
  9241. })
  9242. ->with(['retopicUsers' => function ($query) {
  9243. $query->select('id', 'user_id', 'retopic_id');
  9244. }
  9245. ])
  9246. ->leftJoin('user', 'user.id', '=', 'research_topic.user_id')
  9247. ->leftJoin('user_info', 'user_info.user_id', '=', 'research_topic.user_id')
  9248. ->select('research_topic.id','research_topic.title','research_topic.updated_at','research_topic.status',
  9249. 'research_topic.due_time','user_info.real_name','research_topic.column_id','research_topic.user_id',
  9250. 'user.user_name'
  9251. )
  9252. ->orderBy('research_topic.updated_at', 'desc')
  9253. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  9254. if(empty($research_topic->items())){
  9255. return Result::error('暂无调研选题!');
  9256. }
  9257. $result = [
  9258. 'rows' => $research_topic->items(),
  9259. 'count' => $research_topic->total()
  9260. ];
  9261. foreach($result['rows'] as $key => $value){
  9262. if($user->type_id != 10000){
  9263. if(in_array($value['column_id'], $web_column)){
  9264. $result['rows'][$key]['is_update'] = 1;
  9265. }else{
  9266. $result['rows'][$key]['is_update'] = 0;
  9267. }
  9268. }else{
  9269. if($value['user_id'] == $data['user_id']){
  9270. $result['rows'][$key]['is_update'] = 1;
  9271. }else{
  9272. $result['rows'][$key]['is_update'] = 0;
  9273. }
  9274. }
  9275. if(!isset($value['real_name']) || empty($value['real_name'])){
  9276. $result['rows'][$key]['real_name'] = $value['user_name'];
  9277. }
  9278. if(!empty($value['retopicUsers'])){
  9279. $retopic_users = $value['retopicUsers'];
  9280. $retopic_user = $retopic_users->pluck('user_id')->toArray();
  9281. $result['rows'][$key]['txry_users'] = implode(',', $retopic_user);
  9282. unset($result['rows'][$key]['retopicUsers']);
  9283. }
  9284. }
  9285. return Result::success($result);
  9286. }
  9287. /**
  9288. * 调研选题-修改状态
  9289. * @param array $data
  9290. * @return array
  9291. */
  9292. public function checkResearchTopic(array $data): array
  9293. {
  9294. $user = User::where('id', $data['user_id'])->first();
  9295. if (empty($user)) {
  9296. return Result::error('用户不存在!');
  9297. }
  9298. if($user->type_id != 10000 && ($data['status'] == 1 || $data['status'] == 2)){
  9299. return Result::error('此用户暂无权限!');
  9300. }
  9301. $topic = ResearchTopic::where('id', $data['id'])->first();
  9302. if (empty($topic)) {
  9303. return Result::error('此调研选题不存在');
  9304. }
  9305. $id = $data['id'];
  9306. unset($data['id']);
  9307. unset($data['user_id']);
  9308. $result = ResearchTopic::where('id', $id)->update($data);
  9309. if (empty($result)) {
  9310. return Result::error('修改调研选题状态失败!');
  9311. }
  9312. return Result::success($result);
  9313. }
  9314. /**
  9315. * 调研选题-详情
  9316. * @param array $data
  9317. * @return array
  9318. */
  9319. public function getResearchTopicInfo(array $data): array
  9320. {
  9321. $user = User::where('id', $data['user_id'])->first();
  9322. if (empty($user)) {
  9323. return Result::error('用户不存在!');
  9324. }
  9325. $research_topic = ResearchTopic::where('research_topic.id', $data['id'])
  9326. ->with(['retopicUsers' => function ($query) {
  9327. $query->select('user_id','retopic_id');
  9328. }
  9329. ])
  9330. ->leftJoin('user', 'user.id', '=', 'research_topic.user_id')
  9331. ->leftJoin('user_info', 'user_info.user_id', '=', 'research_topic.user_id')
  9332. ->select('research_topic.*','user_info.number')
  9333. ->first();
  9334. if(empty($research_topic)){
  9335. return Result::error('获取调研选题详情失败!');
  9336. }
  9337. $retopic_user = $research_topic['retopicUsers'];
  9338. if(!empty($retopic_user)){
  9339. $retopic_user = $retopic_user->pluck('user_id')->toArray();
  9340. foreach($retopic_user as $key => $value){
  9341. $real_name = UserInfo::where('user_id', $value)->value('real_name');
  9342. $research_topic['retopicUsers'][$key]['real_name'] = $real_name;
  9343. $research_topic['retopicUsers'][$key]['user_id'] = $value;
  9344. unset($research_topic['retopicUsers'][$key]['retopic_id']);
  9345. }
  9346. }
  9347. return Result::success($research_topic);
  9348. }
  9349. /**
  9350. * 添加网站导航
  9351. * @param array $data
  9352. */
  9353. public function addWebCateinfo(array $data): array
  9354. {
  9355. $user = User::where('id', $data['user_id'])->first();
  9356. if (empty($user)) {
  9357. return Result::error('用户不存在');
  9358. }
  9359. if($user['type_id'] == 10000){
  9360. $data['status'] = 1;
  9361. }else{
  9362. $data['status'] = 0;
  9363. }
  9364. if ($data['keyword'] == '') {
  9365. //提取标题+内容中的关键词
  9366. $data['keyword'] = $data['title'];
  9367. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  9368. Jieba::init(); // 初始化 jieba-php
  9369. Finalseg::init();
  9370. $segList = Jieba::cut($data['keyword']);
  9371. $segList1 = array_slice($segList, 0, 8);
  9372. $data['keyword'] = implode(',', $segList1);
  9373. }
  9374. if ($data['description'] == '') {
  9375. //提取内容中的描述
  9376. $content = $data['content'];
  9377. // 去除 <style> 和 <script> 标签及其内容
  9378. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9379. // 去除所有 HTML 标签
  9380. $content = strip_tags($content);
  9381. // 去除 HTML 实体
  9382. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9383. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9384. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9385. // 去除多余空白
  9386. $content = preg_replace('/\s+/u', '', $content);
  9387. // 截取 100 个字符
  9388. $data['description'] = mb_substr($content, 0, 100);
  9389. }
  9390. $data['cate_name'] = empty($data['cate_name']) ? '官网导航' : $data['cate_name'];
  9391. $data['province_id'] = empty($data['province_id']) ? null : $data['province_id'];
  9392. $data['city_id'] = empty($data['city_id']) ? null : $data['city_id'];
  9393. $data['county_id'] = empty($data['county_id']) ? null : $data['county_id'];
  9394. unset($data['users_id']);
  9395. $result = WebCateinfo::insertGetId($data);
  9396. if (empty($result)) {
  9397. return Result::error('添加失败');
  9398. }
  9399. return Result::success($result);
  9400. }
  9401. /**
  9402. * 更新网站导航
  9403. * @param array $data
  9404. */
  9405. public function upWebCateinfo(array $data): array
  9406. {
  9407. $webCateinfo = WebCateinfo::where('id', $data['id'])->first();
  9408. if (empty($webCateinfo)) {
  9409. return Result::error('导航不存在');
  9410. }
  9411. $user = User::where('id', $data['user_id'])->first();
  9412. if (empty($user)) {
  9413. return Result::error('用户不存在');
  9414. }
  9415. if($user['type_id'] == 10000){
  9416. $data['status'] = 1;
  9417. }else{
  9418. $data['status'] = 0;
  9419. }
  9420. if ($data['keyword'] == '') {
  9421. //提取标题+内容中的关键词
  9422. $data['keyword'] = $data['title'];
  9423. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  9424. Jieba::init(); // 初始化 jieba-php
  9425. Finalseg::init();
  9426. $segList = Jieba::cut($data['keyword']);
  9427. $segList1 = array_slice($segList, 0, 8);
  9428. $data['keyword'] = implode(',', $segList1);
  9429. }
  9430. if ($data['description'] == '') {
  9431. //提取内容中的描述
  9432. $content = $data['content'];
  9433. // 去除 <style> 和 <script> 标签及其内容
  9434. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9435. // 去除所有 HTML 标签
  9436. $content = strip_tags($content);
  9437. // 去除 HTML 实体
  9438. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9439. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9440. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9441. // 去除多余空白
  9442. $content = preg_replace('/\s+/u', '', $content);
  9443. // 截取 100 个字符
  9444. $data['description'] = mb_substr($content, 0, 100);
  9445. }
  9446. $data['cate_name'] = empty($data['cate_name']) ? '官网导航' : $data['cate_name'];
  9447. $data['province_id'] = empty($data['province_id']) ? null : $data['province_id'];
  9448. $data['city_id'] = empty($data['city_id']) ? null : $data['city_id'];
  9449. $data['county_id'] = empty($data['county_id']) ? null : $data['county_id'];
  9450. unset($data['users_id']);
  9451. $result = WebCateinfo::where('id', $data['id'])->update($data);
  9452. if (empty($result)) {
  9453. return Result::error('更新失败');
  9454. }
  9455. return Result::success($result);
  9456. }
  9457. /**
  9458. * 获取网站导航列表
  9459. * @param array $data
  9460. * @return array
  9461. */
  9462. public function getWebCateinfoList(array $data): array
  9463. {
  9464. $user = User::where('id', $data['user_id'])->first();
  9465. if (empty($user)) {
  9466. return Result::error('用户不存在');
  9467. }
  9468. $where = [];
  9469. if($user['type_id'] != 10000){
  9470. $where['web_cateinfo.user_id'] = $data['user_id'];
  9471. }
  9472. if(!empty($data['title'])){
  9473. array_push($where, ['web_cateinfo.title', 'like', '%'.$data['title'].'%']);
  9474. }
  9475. if($data['is_master'] != 0){
  9476. if($data['is_master'] == 3){
  9477. $where['web_cateinfo.status'] = 0;
  9478. }else{
  9479. $where['web_cateinfo.status'] = $data['is_master'];
  9480. }
  9481. }
  9482. $web_cateinfo = WebCateinfo::when(!empty($data['is_master'] == 0), function ($query) use ($where) {
  9483. $query->whereIn('web_cateinfo.status', [0, 2]);
  9484. })
  9485. ->when(!empty($where), function ($query) use ($where) {
  9486. $query->where($where);
  9487. })
  9488. ->leftJoin('user', 'web_cateinfo.user_id', '=', 'user.id')
  9489. ->select(['web_cateinfo.id', 'web_cateinfo.user_id', 'user.nickname', 'web_cateinfo.title', 'web_cateinfo.cate_name', 'web_cateinfo.status','web_cateinfo.updated_at'])
  9490. ->orderBy('updated_at', 'desc')
  9491. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  9492. if(empty($web_cateinfo->items())){
  9493. return Result::error('官网导航不存在');
  9494. }
  9495. $result = [
  9496. 'rows' => $web_cateinfo->items(),
  9497. 'total' => $web_cateinfo->total(),
  9498. ];
  9499. foreach($result['rows'] as $key => $value){
  9500. if($value['user_id'] == $data['user_id']){
  9501. $result['rows'][$key]['is_update'] = 1;
  9502. }else{
  9503. $result['rows'][$key]['is_update'] = 0;
  9504. }
  9505. }
  9506. return Result::success($result);
  9507. }
  9508. /**
  9509. * 删除网站导航
  9510. * @param array $data
  9511. */
  9512. public function delWebCateinfo(array $data): array
  9513. {
  9514. $webCateinfo = WebCateinfo::where('id', $data['id'])->first();
  9515. if (empty($webCateinfo)) {
  9516. return Result::error('导航不存在');
  9517. }
  9518. $result = WebCateinfo::where('id', $data['id'])->delete();
  9519. if (empty($result)) {
  9520. return Result::error('删除失败');
  9521. }
  9522. return Result::success($result);
  9523. }
  9524. /**
  9525. * 审核网站导航
  9526. * @param array $data
  9527. */
  9528. public function checkWebCateinfo(array $data): array
  9529. {
  9530. $webCateinfo = WebCateinfo::where('id', $data['id'])->first();
  9531. if (empty($webCateinfo)) {
  9532. return Result::error('导航不存在');
  9533. }
  9534. $user = User::where('id', $data['user_id'])->first();
  9535. if (empty($user)) {
  9536. return Result::error('用户不存在');
  9537. }
  9538. if($user['type_id'] != 10000 && $data['status'] == 1){
  9539. return Result::error('非管理员不能审核');
  9540. }
  9541. $update_data['status'] = $data['status'];
  9542. if($data['status'] == 2){
  9543. $update_data['reason'] = $data['reason'];
  9544. }
  9545. $result = WebCateinfo::where('id', $data['id'])->update($update_data);
  9546. if (empty($result)) {
  9547. return Result::error('审核失败');
  9548. }
  9549. return Result::success($result);
  9550. }
  9551. /**
  9552. * 获取网站导航详情
  9553. * @param array $data
  9554. */
  9555. public function getWebCateinfoDetail(array $data): array
  9556. {
  9557. $webCateinfo = WebCateinfo::where('id', $data['id'])->first();
  9558. if (empty($webCateinfo)) {
  9559. return Result::error('导航不存在');
  9560. }
  9561. $result = $webCateinfo->toArray();
  9562. return Result::success($result);
  9563. }
  9564. /**
  9565. * 推荐单页管理
  9566. * @param array $data
  9567. */
  9568. public function getAdviceSinglePages(array $data): array
  9569. {
  9570. $user = User::where('id', $data['user_id'])->first();
  9571. if (empty($user)) {
  9572. return Result::error('用户不存在');
  9573. }
  9574. if(empty($data['website_id']) && $user['type_id'] == 10000){
  9575. $category = [];
  9576. }else{
  9577. $where = [
  9578. 'website_id' => $data['website_id'] ?? $data['web_id'],
  9579. ];
  9580. $category = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  9581. // var_dump($ids);
  9582. if (empty($ids)) {
  9583. return Result::error("推荐单页不存在");
  9584. }
  9585. }
  9586. $where = [];
  9587. if(!empty($data['title'])){
  9588. array_push($where, ['title', 'like', '%'.$data['title'].'%']);
  9589. }
  9590. $result = SinglePage::when(!empty($category) ,function ($query) use ($category){
  9591. $query->whereIn('id', $category);
  9592. })
  9593. ->when(!empty($where), function ($query) use ($where) {
  9594. $query->where($where);
  9595. })
  9596. // ->when(!isset($data['catid']), function ($query) use ($data) {
  9597. // $query->where('catid', $data['catid']);
  9598. // })
  9599. ->where('status', 1)
  9600. ->select(['id', 'title', 'catid','status','website_id','updated_at'])
  9601. ->orderBy('updated_at', 'desc')
  9602. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  9603. if(empty($result->items())){
  9604. return Result::error('推荐单页不存在');
  9605. }
  9606. $result = [
  9607. 'rows' => $result->items(),
  9608. 'total' => $result->total(),
  9609. ];
  9610. return Result::success($result);
  9611. }
  9612. /**
  9613. * 添加单页
  9614. * @param array $data
  9615. */
  9616. public function addSinglePage(array $data): array
  9617. {
  9618. $user = User::where('id', $data['user_id'])->first();
  9619. if (empty($user)) {
  9620. return Result::error('用户不存在');
  9621. }
  9622. if($user['type_id'] == 10000){
  9623. $data['status'] = 1;
  9624. }else{
  9625. $data['status'] = 0;
  9626. }
  9627. if(is_array($data['cat_arr_id'])){
  9628. $data['cat_arr_id'] = array_map(function($item){
  9629. return intval($item);
  9630. }, $data['cat_arr_id']);
  9631. $data['catid'] = end($data['cat_arr_id']);
  9632. $data['cat_arr_id'] = json_encode($data['cat_arr_id'], JSON_UNESCAPED_UNICODE);
  9633. }else{
  9634. return Result::error('请选择栏目;');
  9635. }
  9636. if(!empty($data['commend_id']) && is_array($data['commend_id'])){
  9637. $data['commend_id'] = json_encode($data['commend_id'], JSON_UNESCAPED_UNICODE);
  9638. }else{
  9639. $data['commend_id'] = null;
  9640. }
  9641. if ($data['keyword'] == '') {
  9642. //提取标题+内容中的关键词
  9643. $articleData['keyword'] = $data['title'];
  9644. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  9645. Jieba::init(); // 初始化 jieba-php
  9646. Finalseg::init();
  9647. $segList = Jieba::cut($articleData['keyword']);
  9648. $segList1 = array_slice($segList, 0, 8);
  9649. $data['keyword'] = implode(',', $segList1);
  9650. }
  9651. if ($data['description'] == '') {
  9652. //提取内容中的描述
  9653. $content = $data['content'];
  9654. // 去除 <style> 和 <script> 标签及其内容
  9655. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9656. // 去除所有 HTML 标签
  9657. $content = strip_tags($content);
  9658. // 去除 HTML 实体
  9659. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9660. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9661. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9662. // 去除多余空白
  9663. $content = preg_replace('/\s+/u', '', $content);
  9664. // 截取 100 个字符
  9665. $data['description'] = mb_substr($content, 0, 100);
  9666. }
  9667. if(empty($data['publiced_at'])){
  9668. $data['publiced_at'] = null;
  9669. }
  9670. $result = SinglePage::insertGetId($data);
  9671. if (empty($result)) {
  9672. return Result::error('添加失败');
  9673. }
  9674. return Result::success($result);
  9675. }
  9676. /**
  9677. * 更新单页
  9678. * @param array $data
  9679. */
  9680. public function upSinglePage(array $data): array
  9681. {
  9682. $singlePage = SinglePage::where('id', $data['id'])->where('user_id', $data['user_id'])->first();
  9683. if (empty($singlePage)) {
  9684. return Result::error('单页不存在');
  9685. }
  9686. $user = User::where('id', $data['user_id'])->first();
  9687. if (empty($user)) {
  9688. return Result::error('用户不存在');
  9689. }
  9690. $where['id'] = $data['id'];
  9691. unset($data['id']);
  9692. if($user['type_id'] == 10000){
  9693. $data['status'] = 1;
  9694. }else{
  9695. $data['status'] = 0;
  9696. }
  9697. if(is_array($data['cat_arr_id'])){
  9698. $data['cat_arr_id'] = array_map(function($item){
  9699. return intval($item);
  9700. }, $data['cat_arr_id']);
  9701. $data['catid'] = end($data['cat_arr_id']);
  9702. $data['cat_arr_id'] = json_encode($data['cat_arr_id'], JSON_UNESCAPED_UNICODE);
  9703. }else{
  9704. return Result::error('请选择栏目;');
  9705. }
  9706. if(!empty($data['commend_id']) && is_array($data['commend_id'])){
  9707. $data['commend_id'] = json_encode($data['commend_id'], JSON_UNESCAPED_UNICODE);
  9708. }else{
  9709. $data['commend_id'] = null;
  9710. }
  9711. if ($data['keyword'] == '') {
  9712. //提取标题+内容中的关键词
  9713. $articleData['keyword'] = $data['title'];
  9714. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  9715. Jieba::init(); // 初始化 jieba-php
  9716. Finalseg::init();
  9717. $segList = Jieba::cut($articleData['keyword']);
  9718. $segList1 = array_slice($segList, 0, 8);
  9719. $data['keyword'] = implode(',', $segList1);
  9720. }
  9721. if ($data['description'] == '') {
  9722. //提取内容中的描述
  9723. $content = $data['content'];
  9724. // 去除 <style> 和 <script> 标签及其内容
  9725. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9726. // 去除所有 HTML 标签
  9727. $content = strip_tags($content);
  9728. // 去除 HTML 实体
  9729. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9730. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9731. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9732. // 去除多余空白
  9733. $content = preg_replace('/\s+/u', '', $content);
  9734. // 截取 100 个字符
  9735. $data['description'] = mb_substr($content, 0, 100);
  9736. }
  9737. if(empty($data['publiced_at'])){
  9738. $data['publiced_at'] = null;
  9739. }
  9740. $result = SinglePage::where($where)->update($data);
  9741. if (empty($result)) {
  9742. return Result::error('更新失败');
  9743. }
  9744. return Result::success($result);
  9745. }
  9746. /**
  9747. * 删除单页
  9748. * @param array $data
  9749. */
  9750. public function delSinglePage(array $data): array
  9751. {
  9752. $singlePage = SinglePage::where('id', $data['id'])->first();
  9753. if (empty($singlePage)) {
  9754. return Result::error('单页不存在');
  9755. }
  9756. $user = User::where('id', $data['user_id'])->first();
  9757. if (empty($user)) {
  9758. return Result::error('用户不存在');
  9759. }
  9760. $where['id'] = $data['id'];
  9761. $result = SinglePage::where($where)->delete();
  9762. if (empty($result)) {
  9763. return Result::error('删除失败');
  9764. }
  9765. return Result::success($result);
  9766. }
  9767. /**
  9768. * 审核单页
  9769. * @param array $data
  9770. */
  9771. public function checkSinglePage(array $data): array
  9772. {
  9773. $user = User::where('id', $data['user_id'])->first();
  9774. if (empty($user)) {
  9775. return Result::error('用户不存在');
  9776. }
  9777. if($user['type_id'] != 10000 && in_array($data['status'], [1, 2])){
  9778. return Result::error('非管理员不能审核单页');
  9779. }
  9780. if($data['status'] == 2){
  9781. $update_data['reason'] = $data['reason'] ?? '';
  9782. }
  9783. $update_data['status'] = $data['status'];
  9784. $result = SinglePage::where('id', $data['id'])->update($update_data);
  9785. if (empty($result)) {
  9786. return Result::error('更新失败');
  9787. }
  9788. return Result::success($result);
  9789. }
  9790. /**
  9791. * 更新单页状态
  9792. * @param array $data
  9793. */
  9794. public function getSinglePageList(array $data): array
  9795. {
  9796. $user = User::where('id', $data['user_id'])->first();
  9797. if (empty($user)) {
  9798. return Result::error('用户不存在');
  9799. }
  9800. $where = [];
  9801. if($user['type_id'] != 10000){
  9802. $where['single_page.user_id'] = $data['user_id'];
  9803. }
  9804. if($data['is_master'] == 3){
  9805. $where['single_page.status'] = 0;
  9806. }else if($data['is_master'] != 0){
  9807. $where['single_page.status'] = $data['is_master'];
  9808. }
  9809. if(!empty($data['title'])){
  9810. array_push($where, ['single_page.title', 'like', '%'.$data['title'].'%']);
  9811. }
  9812. $result = SinglePage::when($data['is_master'] == 0, function($query) use($data){
  9813. $query->whereIn('single_page.status', [0, 2]);
  9814. })
  9815. ->when(!empty($where), function($query) use($where){
  9816. $query->where($where);
  9817. })
  9818. ->with([
  9819. 'websiteCategory' => function ($query) {
  9820. $query->select('website_id', 'category_id', 'alias');
  9821. },
  9822. 'user' => function ($query) {
  9823. $query->select('id', 'nickname');
  9824. }
  9825. ])
  9826. ->select(['single_page.id','single_page.title','single_page.content','single_page.updated_at',
  9827. 'single_page.status','single_page.catid','single_page.website_id','single_page.user_id'])
  9828. ->orderBy('single_page.updated_at', 'desc')
  9829. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  9830. if (empty($result->items())) {
  9831. return Result::error('暂无数据');
  9832. }
  9833. $result = [
  9834. 'rows' => $result->items(),
  9835. 'total' => $result->total(),
  9836. ];
  9837. foreach($result['rows'] as $key => $value){
  9838. $result['rows'][$key]['category_alias'] = $value['websiteCategory']['alias'] ?? '';
  9839. $result['rows'][$key]['user_nickname'] = $value['user']['nickname'] ?? '';
  9840. $result['rows'][$key]['websiteCategory'] = $value['websiteCategory']['alias'] ?? '';
  9841. unset($result['rows'][$key]['user']);
  9842. unset($result['rows'][$key]['websiteCategory']);
  9843. if($user['type_id'] == 10000){
  9844. if($value['user_id'] == $data['user_id']){
  9845. $result['rows'][$key]['is_update'] = 1;
  9846. }else{
  9847. $result['rows'][$key]['is_update'] = 0;
  9848. }
  9849. }else{
  9850. if($value['website_id'] == $data['website_id']){
  9851. $result['rows'][$key]['is_update'] = 1;
  9852. }else{
  9853. $result['rows'][$key]['is_update'] = 0;
  9854. }
  9855. }
  9856. }
  9857. return Result::success($result);
  9858. }
  9859. /**
  9860. * 获取单页详情
  9861. * @param array $data
  9862. */
  9863. public function getSinglePageInfo(array $data): array
  9864. {
  9865. $singlePage = SinglePage::where('id', $data['id'])->first();
  9866. if (empty($singlePage)) {
  9867. return Result::error('单页不存在');
  9868. }
  9869. $user = User::where('id', $data['user_id'])->first();
  9870. if (empty($user)) {
  9871. return Result::error('用户不存在');
  9872. }
  9873. $where['id'] = $data['id'];
  9874. $result = SinglePage::where($where)->first();
  9875. if (empty($result)) {
  9876. return Result::error('获取失败');
  9877. }
  9878. $result['cat_arr_id'] = json_decode($result['cat_arr_id'] ?? '[]' , true);
  9879. $result['commend_id'] = json_decode($result['commend_id'] ?? '[]' , true);
  9880. return Result::success($result);
  9881. }
  9882. }