NewsService.php 369 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113
  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. $where = [
  330. 'website_id' => $data['website_id'],
  331. ];
  332. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  333. var_dump($ids);
  334. if (empty($ids)) {
  335. return Result::error("没有推荐数据");
  336. }
  337. //id
  338. $whereArticle = [];
  339. if (isset($data['id'])) {
  340. $whereArticle['id'] = $data['id'];
  341. }
  342. //title like
  343. if (isset($data['title'])) {
  344. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  345. }
  346. $article = Article::whereIn('catid', values: $ids)->where('status', 1)
  347. ->where($whereArticle)
  348. ->orderBy('id', 'desc')
  349. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  350. if ($article) {
  351. $data = [
  352. 'rows' => $article->items(),
  353. 'count' => $article->total(),
  354. ];
  355. return Result::success($data);
  356. } else {
  357. return Result::error("获取失败失败");
  358. }
  359. }
  360. /**
  361. * @param array $data
  362. * @return array
  363. */
  364. public function getArticleList(array $data): array
  365. {
  366. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  367. $type_id = $data['type_id'];
  368. unset($data['type_id']);
  369. $user_id = $data['user_id'];
  370. unset($data['user_id']);
  371. $where = [];
  372. $status1 = [];
  373. if (isset($data['id']) && $data['id']) {
  374. array_push($where, ['article.id', '=', $data['id']]);
  375. }
  376. if (isset($data['title']) && $data['title']) {
  377. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  378. }
  379. if (isset($data['category_name']) && $data['category_name']) {
  380. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  381. }
  382. if (isset($data['catid']) && $data['catid']) {
  383. array_push($where, ['article.catid', '=', $data['catid']]);
  384. }
  385. if (isset($data['author']) && $data['author']) {
  386. array_push($where, ['article.author', '=', $data['author']]);
  387. }
  388. if (isset($data['islink']) && $data['islink'] !== "") {
  389. array_push($where, ['article.islink', '=', $data['islink']]);
  390. }
  391. if (isset($data['status']) && $data['status'] !== "") {
  392. array_push($where, ['article.status', '=', $data['status']]);
  393. }
  394. if (isset($data['status1'])) {
  395. $status1 = json_decode(($data['status1']));
  396. }
  397. //不是管理员展示个人数据;
  398. if ($type_id != 10000) {
  399. $where[] = ['article.admin_user_id', '=', $user_id];
  400. }
  401. $startTime = microtime(true);
  402. $rep = Article::query()
  403. // 预加载相关关联
  404. ->with([
  405. 'category' => function ($query) {
  406. $query->select('id', 'name');
  407. },
  408. 'websiteCategory' => function ($query) {
  409. $query->select('website_id', 'category_id', 'alias');
  410. },'user' => function ($query) {
  411. $query->select('id', 'nickname');
  412. }
  413. ])
  414. // 构建where条件
  415. ->when(isset($data['id']) && $data['id'], function ($query) use ($data) {
  416. $query->where('article.id', '=', $data['id']);
  417. })
  418. ->when(isset($data['title']) && $data['title'], function ($query) use ($data) {
  419. $query->where('article.title', 'like', '%' . $data['title'] . '%');
  420. })
  421. ->when(isset($data['category_name']) && $data['category_name'], function ($query) use ($data) {
  422. // 使用子查询替代左连接进行模糊搜索
  423. $query->whereHas('category', function ($subQuery) use ($data) {
  424. $subQuery->where('name', 'like', '%' . $data['category_name'] . '%');
  425. });
  426. })
  427. ->when(isset($data['catid']) && $data['catid'], function ($query) use ($data) {
  428. $query->where('article.catid', '=', $data['catid']);
  429. })
  430. ->when(isset($data['author']) && $data['author'], function ($query) use ($data) {
  431. $query->where('article.author', '=', $data['author']);
  432. })
  433. ->when(isset($data['islink']) && $data['islink'] !== "", function ($query) use ($data) {
  434. $query->where('article.islink', '=', $data['islink']);
  435. })
  436. ->when(isset($data['status']) && $data['status'] !== "", function ($query) use ($data) {
  437. $query->where('article.status', '=', $data['status']);
  438. })
  439. ->when(isset($data['status1']) && $data['status1'], function ($query) use ($data) {
  440. // 安全地处理JSON字符串
  441. $status1 = is_array($data['status1']) ? $data['status1'] : json_decode($data['status1'], true) ?? [];
  442. if (!empty($status1)) {
  443. $query->whereIn('article.status', $status1);
  444. }
  445. })
  446. ->select('article.*')
  447. // 非管理员限制
  448. ->when($type_id != 10000, function ($query) use ($user_id) {
  449. // 非管理员只能看自己的文章,同时把 article_ignore 的 c_show_time 一起查出来
  450. $query->where('article.admin_user_id', $user_id)
  451. ->leftJoin('article_ignore', function ($join) {
  452. // 关联条件:article.id = article_ignore.article_id 且 article.web_site_id = article_ignore.website_id
  453. $join->on('article_ignore.article_id', '=', 'article.id')
  454. ->whereColumn('article_ignore.website_id', 'article.web_site_id');
  455. })
  456. ->addSelect('article_ignore.article_id','article_ignore.c_show_time'); // 用 addSelect 追加字段,避免覆盖原有 select
  457. })
  458. // 基础条件
  459. ->whereNotIn('article.status', [404])
  460. // 排序和分页
  461. ->orderBy('article.updated_at', 'desc')
  462. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  463. // 获取结果并格式化
  464. $data = [
  465. 'rows' => $rep->items(),
  466. 'count' => $rep->total(),
  467. ];
  468. // 执行查询
  469. $endTime = microtime(true);
  470. $executionTime = ($endTime - $startTime) * 1000;
  471. echo "查询执行时间: {$executionTime}ms\n";
  472. return Result::success($data);
  473. }
  474. /**
  475. * @param array $data
  476. * @return array
  477. */
  478. public function addArticle(array $data): array
  479. {
  480. var_dump($data, '----------12-----------1');
  481. // ------c_show_time********add***1****
  482. $is_collect = $data['is_collect'] ?? 0;
  483. $user_type = $data['user_type'];
  484. unset($data['is_collect']);
  485. unset($data['user_type']);
  486. // ------c_show_time********add***1****
  487. unset($data['nav_add_pool_id']);
  488. // unset($data['commend_id']);
  489. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  490. Db::beginTransaction();
  491. try {
  492. //处理投票
  493. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  494. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  495. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  496. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  497. unset($data['is_survey']);
  498. unset($data['survey_name']);
  499. unset($data['suvey_array']);
  500. // unset($data['website_id']);
  501. // unset($data['web_site_id']);
  502. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  503. if ($data['hits'] == '') {
  504. $data['hits'] = 0;
  505. }
  506. if ($data['is_original'] == '') {
  507. $data['is_original'] = 0;
  508. }
  509. if ($data['status'] == '') {
  510. $data['status'] = 0;
  511. }
  512. $articleData = $data;
  513. unset($articleData['content']);
  514. //自动处理缩略图、关键字、描述
  515. if ($articleData['imgurl'] == '') {
  516. //如果没有图,设置level=0
  517. $levelArr = json_decode($articleData['level'], true);
  518. var_dump($levelArr, '----------levelArr-----------1');
  519. //content中提取图片第一个图,正则提取
  520. // -------采集器相关优化-----
  521. // 优化正则表达式,仅匹配 src 属性值,避免匹配到多余内容
  522. if ($is_collect == 1) {
  523. $reg = '/<img.*?src=[\'"]?((?!.*\.gif)[^\'" >]+)[\'"]?.*?>/i';
  524. } else {
  525. $reg = '/<img.*?src=[\'"]?([^\'" >]+)[\'"]?.*?>/i';
  526. }
  527. // -------采集器相关优化-----
  528. preg_match_all($reg, $data['content'], $matches);
  529. if (isset($matches[1][0])) {
  530. //截取varchar240
  531. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  532. //如果有图,设置level=3
  533. if (!in_array(3, $levelArr)) {
  534. $levelArr[] = 3;
  535. }
  536. $articleData['level'] = json_encode($levelArr);
  537. } else {
  538. if (!in_array(0, $levelArr)) {
  539. $levelArr[] = 0;
  540. }
  541. $articleData['level'] = json_encode($levelArr);
  542. }
  543. }
  544. var_dump($articleData['level'], '----------$articleData[level]----------1');
  545. if ($articleData['keyword'] == '') {
  546. //提取标题+内容中的关键词
  547. $articleData['keyword'] = $data['title'];
  548. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  549. Jieba::init(); // 初始化 jieba-php
  550. Finalseg::init();
  551. $segList = Jieba::cut($articleData['keyword']);
  552. $segList1 = array_slice($segList, 0, 8);
  553. $articleData['keyword'] = implode(',', $segList1);
  554. }
  555. if ($articleData['introduce'] == '') {
  556. //提取内容中的描述
  557. $content = $data['content'];
  558. // 去除 <style> 和 <script> 标签及其内容
  559. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  560. // 去除所有 HTML 标签
  561. $content = strip_tags($content);
  562. // 去除 HTML 实体
  563. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  564. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  565. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  566. // 去除多余空白
  567. $content = preg_replace('/\s+/u', '', $content);
  568. // 截取 100 个字符
  569. $articleData['introduce'] = mb_substr($content, 0, 100);
  570. }
  571. if ($articleData['status'] == 0) {
  572. $this->sendMessage([
  573. 'talk_type' => 100,
  574. 'title' => $articleData['title'],
  575. 'content' => '提交了审核',
  576. 'messageType' => 2,
  577. ]);
  578. }
  579. if(!empty($data['fujian'])){
  580. $articleData['fujian'] = $data['fujian'];
  581. }
  582. $id = Article::insertGetId($articleData);
  583. if (!$id) {
  584. throw new \Exception('文章插入失败');
  585. }
  586. $articleDataContent = [
  587. 'article_id' => $id,
  588. 'content' => $data['content'],
  589. ];
  590. // 采集器中的文章内容,在添加时,去掉div标签
  591. if ($is_collect == 1) {
  592. // 采集来的文章,content中可能包含div标签,需要先移除
  593. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  594. $article_data = preg_replace($pattern, '', $data['content']);
  595. $$articleDataContent['content'] = $article_data;
  596. }
  597. $contentInsertId = ArticleData::insertGetId($articleDataContent);
  598. if (!$contentInsertId) {
  599. throw new \Exception('文章内容插入失败');
  600. }
  601. // ------c_show_time********add***2****
  602. // 直接使用当前系统时间,不再强制添加8小时
  603. $now = date('Y-m-d H:i:s');
  604. if ($user_type == 10000 || $is_collect == 1) {
  605. // 管理员添加文章时,核心站c端显示时间就是创建时间;非核心站c端显示时间就是此创建时间往后推二十分钟;
  606. // 非管理员添加文章时,不做操作只有在审核通过时获取c端显示时间
  607. if (!isset($data['catid'])) {
  608. throw new \Exception('缺少必要字段:catid');
  609. }
  610. $column_arr = WebsiteColumn::where('column_name','官网')->pluck('id')->toArray();
  611. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  612. $web = WebsiteCategory::where('category_id', $data['catid'])
  613. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  614. ->select(
  615. 'website_id',
  616. DB::raw('
  617. CASE
  618. WHEN website.id IS NULL THEN 2
  619. WHEN website.website_column_id IN ('.implode(',', $column_arr).') THEN 1
  620. ELSE 0
  621. END as is_core
  622. ')
  623. )
  624. ->get();
  625. // $id = 225; -----测试开启
  626. // 采集来的文章,错开时间在两小时之内发布
  627. if ($user_type == 10000 && $is_collect == 1) {
  628. $web_num = $web->where('is_core', '!=', 2)->count();
  629. $waiting_interval = 10;
  630. if ($web_num > 12) {
  631. // 若网站数量大于12个,则每个网站间隔时间取均值
  632. // 防止除数为 0,虽然这里 $web_num 是 count 结果不会为 0,但做健壮性检查
  633. $waiting_interval = 120 / max(1, $web_num);
  634. }
  635. $time = 0;
  636. } else {
  637. // 非核心站与核心站----显示时间-----间隔
  638. $time = 20;
  639. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  640. $waiting_interval = 5;
  641. }
  642. // 将 Hyperf\Database\Model\Collection 转换为数组
  643. $webArray = $web->toArray();
  644. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $id, $waiting_interval, $is_collect) {
  645. // 检查 $item 对象是否有 is_core 属性
  646. if (!isset($item['is_core'])) {
  647. throw new \Exception('$item 对象缺少 is_core 属性');
  648. }
  649. // 当 is_core 为 2 时,则表示此网站不存在
  650. if ($item['is_core'] == 2) {
  651. return null;
  652. }
  653. if ($is_collect == 1) {
  654. // 采集来的文章,错开时间在两小时之内发布
  655. // $time = 0;
  656. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  657. $time += $waiting_interval;
  658. } else if ($item['is_core'] == 1) {
  659. // 当 is_core 为 1 时,则表示此网站是核心站
  660. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  661. } else {
  662. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  663. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  664. if ($item['is_core'] == 0) {
  665. $time += $waiting_interval;
  666. }
  667. }
  668. return [
  669. 'article_id' => $id,
  670. 'website_id' => $item['website_id'],
  671. 'c_show_time' => $c_show_time,
  672. // 'is_core' => $item['is_core'],
  673. // 'time' => $time
  674. ];
  675. }, array_keys($webArray), $webArray)));
  676. // Db::commit();
  677. // return Result::success($article_ignore);
  678. if (!empty($article_ignore)) {
  679. $article_ignores = ArticleIgnore::insert($article_ignore);
  680. if (!$article_ignores) {
  681. throw new \Exception('c端展示时间插入失败');
  682. }
  683. }
  684. }
  685. // ------c_show_time********add***2****
  686. //处理投票
  687. if ($is_survey == 1) {
  688. //生成年月日时分秒+8位随机数
  689. $uuid = date('YmdHis') . rand(10000000, 99999999);
  690. var_dump($suvey_array, 'suvey_array________');
  691. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  692. var_dump($suveys_array, '---------------------1');
  693. var_dump($suvey_array, '---------------------2');
  694. $suvey_data = [];
  695. foreach ($suveys_array as $key => $value) {
  696. if ($value == '') {
  697. continue;
  698. }
  699. if (is_array($value)) {
  700. $suvey_data[] = [
  701. 'sur_id' => $uuid,
  702. 'art_id' => $id,
  703. 'website_id' => $website_id ?? 2,
  704. 'survey_name' => $survey_name,
  705. 'choice_name' => $value[1],
  706. 'is_other' => 1,
  707. 'other_id' => 0,
  708. 'results' => 0,
  709. ];
  710. } else {
  711. $suvey_data[] = [
  712. 'sur_id' => $uuid,
  713. 'art_id' => $id,
  714. 'website_id' => $website_id ?? 2,
  715. 'survey_name' => $survey_name,
  716. 'choice_name' => $value,
  717. 'is_other' => 0,
  718. 'other_id' => 0,
  719. 'results' => 0,
  720. ];
  721. }
  722. if (empty($suvey_data)) {
  723. throw new \Exception("投票数据为空");
  724. }
  725. }
  726. $result = ArticleSurvey::insert($suvey_data);
  727. if (!$result) {
  728. throw new \Exception("投票失败,ArticleSurvey插入失败");
  729. }
  730. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  731. if (!$result) {
  732. throw new \Exception("投票失败,更新主表失败");
  733. }
  734. }
  735. Db::commit();
  736. return Result::success(['id' => $id]);
  737. } catch (\Throwable $ex) {
  738. Db::rollBack();
  739. var_dump($ex->getMessage());
  740. return Result::error("创建失败", 0);
  741. }
  742. }
  743. /**
  744. * @param array $data
  745. * @return array
  746. */
  747. public function delArticle(array $data): array
  748. {
  749. // ------c_show_time********del*******
  750. Db::beginTransaction();
  751. try {
  752. $article = Article::where(['id' => $data['id']])->delete();
  753. // 若文章删除失败,抛出异常,后续 SQL 语句不会执行
  754. if (!$article) {
  755. throw new \Exception("删除失败,文章删除失败");
  756. }
  757. //survey投票删除
  758. ArticleSurvey::where(['art_id' => $data['id']])->delete(); // 修正类名大小写
  759. $articleIgnore = ArticleIgnore::where(['article_id' => $data['id']])->delete();
  760. $article_data = ArticleData::where(['article_id' => $data['id']])->delete();
  761. // 若文章详情删除失败,抛出异常
  762. if (!$article_data) {
  763. throw new \Exception("删除失败,文章详情删除失败");
  764. }
  765. Db::commit(); // 所有操作成功,提交事务
  766. } catch (\Throwable $ex) {
  767. Db::rollBack();
  768. var_dump($ex->getMessage());
  769. return Result::error("删除失败: " . $ex->getMessage(), 0);
  770. }
  771. // ------c_show_time********del*******
  772. if (!$article) {
  773. return Result::error("删除失败");
  774. }
  775. return Result::success($article);
  776. }
  777. /**
  778. * @param array $data
  779. * @return array
  780. */
  781. public function updateArticle(array $data): array
  782. {
  783. var_dump($data, '----------12-----------1');
  784. Db::beginTransaction();
  785. // ------c_show_time********up*******
  786. $user_type = isset($data['user_type']) ? $data['user_type'] : 0;
  787. // 无论是否改变了c端显示时间或者栏目,都需要将未屏蔽的网站显示时间删除记录
  788. // 若是存在交集,则进行修改,若无,则合并(此表中的记录应该包含被屏蔽网站及涉及所有网站的展示时间)
  789. $web = WebsiteCategory::where('category_id', $data['catid'])
  790. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  791. ->select(
  792. 'website_id',
  793. 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')
  794. )
  795. ->get();
  796. // 根据错误信息,问题在于 $web 可能是一个包含对象的集合,不能直接用于 whereNotIn 方法
  797. // 先从 $web 集合中提取 website_id 字段的值,再进行删除操作
  798. $websiteIds = $web->pluck('website_id')->toArray();
  799. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  800. if ($user_type == 0) {
  801. throw new \Exception("用户类型不能为空");
  802. }
  803. if ($user_type == 10000) {
  804. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  805. $web = WebsiteCategory::where('category_id', $data['catid'])
  806. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  807. ->select(
  808. 'website_id',
  809. 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')
  810. )
  811. ->get();
  812. // 非核心站与核心站----显示时间-----间隔
  813. $time = 20;
  814. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  815. $waiting_interval = 5;
  816. $webArray = $web->toArray();
  817. if (empty($webArray)) {
  818. throw new \Exception('网站分类不存在');
  819. }
  820. // 直接使用当前系统时间,不再强制添加8小时
  821. $now = date('Y-m-d H:i:s');
  822. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  823. // 检查 $item 对象是否有 is_core 属性
  824. if (!isset($item['is_core'])) {
  825. throw new \Exception('$item 对象缺少 is_core 属性');
  826. }
  827. // 当 is_core 为 2 时,则表示此网站不存在
  828. if ($item['is_core'] == 2) {
  829. return null;
  830. } else if ($item['is_core'] == 1) {
  831. // 当 is_core 为 1 时,则表示此网站是核心站
  832. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  833. } else {
  834. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  835. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  836. if ($item['is_core'] == 0) {
  837. $time += $waiting_interval;
  838. }
  839. }
  840. return [
  841. 'article_id' => $data['id'],
  842. 'website_id' => $item['website_id'],
  843. 'c_show_time' => $c_show_time,
  844. ];
  845. }, array_keys($webArray), $webArray)));
  846. if (!empty($article_ignore)) {
  847. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  848. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  849. $article_ignores = ArticleIgnore::upsert(
  850. $article_ignore,
  851. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  852. ['c_show_time'] // 需要更新的字段
  853. );
  854. if (!$article_ignores) {
  855. throw new \Exception('c端展示时间插入失败');
  856. }
  857. }
  858. // Db::commit();
  859. // return Result::success($article_ignore);
  860. }
  861. // ------c_show_time********up*******
  862. unset($data['user_type']);
  863. // unset($data['web_site_id']);
  864. unset($data['nav_add_pool_id']);
  865. try {
  866. //处理投票
  867. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  868. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  869. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  870. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  871. unset($data['is_survey']);
  872. unset($data['survey_name']);
  873. unset($data['suvey_array']);
  874. unset($data['website_id']);
  875. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  876. if ($data['hits'] == '') {
  877. $data['hits'] = 0;
  878. }
  879. if ($data['is_original'] == '') {
  880. $data['is_original'] = 0;
  881. }
  882. if ($data['status'] == '') {
  883. $data['status'] = 0;
  884. }
  885. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  886. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  887. $articleData = $data;
  888. unset($articleData['content']);
  889. unset($articleData['status_name']);
  890. unset($articleData['name']);
  891. unset($articleData['content']);
  892. unset($articleData['pid_arr']);
  893. unset($articleData['pid']);
  894. //自动处理缩略图、关键字、描述
  895. if ($articleData['imgurl'] == '') {
  896. //如果没有图,设置level=0
  897. $levelArr = json_decode($articleData['level'], true);
  898. var_dump($levelArr, '----------levelArr-----------1');
  899. //content中提取图片第一个图,正则提取
  900. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  901. preg_match_all($reg, $data['content'], $matches);
  902. if (isset($matches[1][0])) {
  903. //截取varchar240
  904. // 截取到第一个<
  905. $articleData['imgurl'] = $matches[1][0];
  906. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  907. $pos = strpos($articleData['imgurl'], '"');
  908. if ($pos !== false) {
  909. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  910. }
  911. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  912. //如果有图,设置level=3
  913. if (!in_array(3, $levelArr)) {
  914. $levelArr[] = 3;
  915. }
  916. $articleData['level'] = json_encode($levelArr);
  917. } else {
  918. if (!in_array(0, $levelArr)) {
  919. $levelArr[] = 0;
  920. }
  921. $articleData['level'] = json_encode($levelArr);
  922. }
  923. }
  924. var_dump($articleData['level'], '----------$articleData[level]----------1');
  925. if ($articleData['keyword'] == '') {
  926. //提取标题+内容中的关键词
  927. $articleData['keyword'] = $data['title'];
  928. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  929. Jieba::init(); // 初始化 jieba-php
  930. Finalseg::init();
  931. $segList = Jieba::cut($articleData['keyword']);
  932. $segList1 = array_slice($segList, 0, 8);
  933. $articleData['keyword'] = implode(',', $segList1);
  934. }
  935. if ($articleData['introduce'] == '') {
  936. //提取内容中的描述
  937. $content = $data['content'];
  938. // 去除 <style> 和 <script> 标签及其内容
  939. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  940. // 去除所有 HTML 标签
  941. $content = strip_tags($content);
  942. // 去除 HTML 实体
  943. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  944. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  945. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  946. // 去除多余空白
  947. $content = preg_replace('/\s+/u', '', $content);
  948. // 截取 100 个字符
  949. $articleData['introduce'] = mb_substr($content, 0, 100);
  950. }
  951. if ($articleData['status'] == 0) {
  952. $this->sendMessage([
  953. 'talk_type' => 100,
  954. 'title' => $articleData['title'],
  955. 'content' => '提交了审核',
  956. 'messageType' => 2,
  957. ]);
  958. }
  959. if(!empty($data['fujian'])){
  960. $articleData['fujian'] = $data['fujian'];
  961. }
  962. $id = Article::where(['id' => $data['id']])->update($articleData);
  963. // $articleDataContent = [
  964. // 'content' => $data['content'],
  965. // ];
  966. // 采集来的文章,content中可能包含div标签,需要先移除
  967. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  968. $article_data = preg_replace($pattern, '', $data['content']);
  969. $articleDataContent['content'] = $article_data;
  970. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  971. //处理投票
  972. $id = $data['id'];
  973. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  974. var_dump($suvey_array, 'suvey_array________delete');
  975. //处理投票
  976. if ($is_survey == 1) {
  977. //生成年月日时分秒+8位随机数
  978. $uuid = date('YmdHis') . rand(10000000, 99999999);
  979. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  980. var_dump($suveys_array, '---------------------1');
  981. $suvey_data = [];
  982. if (is_array($suveys_array)) {
  983. foreach ($suveys_array as $key => $value) {
  984. if ($value == '') {
  985. continue;
  986. }
  987. if (is_array($value)) {
  988. $suvey_data[] = [
  989. 'sur_id' => $uuid,
  990. 'art_id' => $id,
  991. 'website_id' => $website_id ?? 2,
  992. 'survey_name' => $survey_name,
  993. 'choice_name' => $value[1],
  994. 'is_other' => 1,
  995. 'other_id' => 0,
  996. 'results' => 0,
  997. ];
  998. } else {
  999. $suvey_data[] = [
  1000. 'sur_id' => $uuid,
  1001. 'art_id' => $id,
  1002. 'website_id' => $website_id ?? 2,
  1003. 'survey_name' => $survey_name,
  1004. 'choice_name' => $value,
  1005. 'is_other' => 0,
  1006. 'other_id' => 0,
  1007. 'results' => 0,
  1008. ];
  1009. }
  1010. if (empty($suvey_data)) {
  1011. throw new \Exception("投票数据为空");
  1012. }
  1013. }
  1014. }
  1015. $result = ArticleSurvey::insert($suvey_data);
  1016. if (!$result) {
  1017. throw new \Exception("投票失败");
  1018. }
  1019. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  1020. if (!$result) {
  1021. throw new \Exception("投票失败");
  1022. }
  1023. } else {
  1024. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  1025. }
  1026. Db::commit();
  1027. return Result::success([]);
  1028. } catch (\Throwable $ex) {
  1029. Db::rollBack();
  1030. var_dump($ex->getMessage());
  1031. return Result::error("更新失败" . $ex->getMessage(), 0);
  1032. }
  1033. }
  1034. /**
  1035. * 更新资讯状态
  1036. * @param array $data
  1037. * @return array
  1038. */
  1039. public function upArticleStatus(array $data): array
  1040. {
  1041. $articleData = Article::where(['id' => $data['id']])->first();
  1042. //发送10次
  1043. // for ($i = 0; $i < 10; $i++) {
  1044. // $this->sendMessage([
  1045. // 'talk_type' => 100,
  1046. // 'title' => $i . $articleData['title'],
  1047. // 'content' => '审核通过',
  1048. // 'messageType' => 2,
  1049. // 'user_id' => $articleData['admin_user_id'],
  1050. // ]);
  1051. // }
  1052. // var_dump($data['status'], 'status');
  1053. // return Result::success();
  1054. if ($data['status'] == 1) {
  1055. $this->sendMessage([
  1056. 'talk_type' => 101,
  1057. 'title' => $articleData['title'],
  1058. 'content' => '审核通过',
  1059. 'messageType' => 2,
  1060. 'user_id' => $articleData['admin_user_id'],
  1061. ]);
  1062. }
  1063. if ($data['status'] == 2) {
  1064. $this->sendMessage([
  1065. 'talk_type' => 101,
  1066. 'title' => $articleData['title'],
  1067. 'content' => '审核拒绝',
  1068. 'messageType' => 2,
  1069. 'user_id' => $articleData['admin_user_id'],
  1070. ]);
  1071. }
  1072. if ($data['status'] == 0) {
  1073. $this->sendMessage([
  1074. 'talk_type' => 100,
  1075. 'title' => $articleData['title'],
  1076. 'content' => '提交了审核',
  1077. 'messageType' => 2,
  1078. ]);
  1079. }
  1080. $result = Article::where(['id' => $data['id']])->update($data);
  1081. // ------c_show_time********up_status*******
  1082. // 若是审核通过 则更新c_show_time
  1083. if ($data['status'] == 1) {
  1084. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  1085. $column_arr = WebsiteColumn::where('column_name','官网')->pluck('id')->toArray();
  1086. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  1087. $web = WebsiteCategory::where('category_id', $data['catid'])
  1088. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  1089. ->select(
  1090. 'website_id',
  1091. DB::raw('
  1092. CASE
  1093. WHEN website.id IS NULL THEN 2
  1094. WHEN website.website_column_id IN ('.implode(',', $column_arr).') THEN 1
  1095. ELSE 0
  1096. END as is_core
  1097. ')
  1098. )
  1099. ->get();
  1100. // 非核心站与核心站----显示时间-----间隔
  1101. $time = 20;
  1102. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  1103. $waiting_interval = 5;
  1104. $webArray = $web->toArray();
  1105. if (empty($webArray)) {
  1106. throw new \Exception('网站分类不存在');
  1107. }
  1108. // 直接使用当前系统时间,不再强制添加8小时
  1109. $now = date('Y-m-d H:i:s');
  1110. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  1111. if (isset($data['ignore_ids'])) {
  1112. $ignore_website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  1113. if (in_array($item['website_id'], $ignore_website_ids)) {
  1114. $is_ignore = 1;
  1115. } else {
  1116. $is_ignore = 0;
  1117. }
  1118. return [
  1119. 'article_id' => $data['id'],
  1120. 'website_id' => $item['website_id'],
  1121. 'is_ignore' => $is_ignore,
  1122. ];
  1123. } else {
  1124. // 检查 $item 对象是否有 is_core 属性
  1125. if (!isset($item['is_core'])) {
  1126. throw new \Exception('$item 对象缺少 is_core 属性');
  1127. }
  1128. // 当 is_core 为 2 时,则表示此网站不存在
  1129. if ($item['is_core'] == 2) {
  1130. return null;
  1131. } else if ($item['is_core'] == 1) {
  1132. // 当 is_core 为 1 时,则表示此网站是核心站
  1133. $c_show_time = $now;
  1134. } else {
  1135. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  1136. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  1137. if ($item['is_core'] == 0) {
  1138. $time += $waiting_interval;
  1139. }
  1140. }
  1141. return [
  1142. 'article_id' => $data['id'],
  1143. 'website_id' => $item['website_id'],
  1144. 'c_show_time' => $c_show_time,
  1145. ];
  1146. }
  1147. }, array_keys($webArray), $webArray)));
  1148. if (!empty($article_ignore) && !isset($data['ignore_ids'])) {
  1149. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  1150. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  1151. $websiteIds = $web->pluck('website_id')->toArray();
  1152. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  1153. $article_ignores = ArticleIgnore::upsert(
  1154. $article_ignore,
  1155. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1156. ['c_show_time'] // 需要更新的字段
  1157. );
  1158. if (!$article_ignores) {
  1159. throw new \Exception('c端展示时间插入失败');
  1160. }
  1161. }
  1162. if (!empty($data['ignore_ids'])) {
  1163. // return Result::success($article_ignore);
  1164. // 从数据库中删除 article_id 为 $data['id'] 且 website_id 在 $website_ids 中的记录
  1165. if (!empty($article_ignore)) {
  1166. $article_ignores = ArticleIgnore::upsert(
  1167. $article_ignore,
  1168. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1169. ['is_ignore'] // 需要更新的字段
  1170. );
  1171. // if(!$article_ignores){
  1172. // throw new \Exception('屏蔽网站更新失败');
  1173. // }
  1174. }
  1175. }
  1176. }
  1177. // ------c_show_time********up_status*******
  1178. if ($result) {
  1179. return Result::success();
  1180. } else {
  1181. return Result::error("更新状态失败", 0);
  1182. }
  1183. }
  1184. /**
  1185. * 获取新闻详情
  1186. * @param array $data
  1187. * @return array
  1188. */
  1189. public function getArticleInfo(array $data): array
  1190. {
  1191. $where = [
  1192. 'article.id' => $data['id'],
  1193. // 'article.status' => 1,
  1194. ];
  1195. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  1196. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  1197. $info = $result;
  1198. // var_dump($info, 'info');
  1199. $info['survey_array'] = $articleSurvey;
  1200. if ($result) {
  1201. return Result::success($info);
  1202. } else {
  1203. return Result::error("查询失败", 0);
  1204. }
  1205. }
  1206. /**
  1207. * 获取头条新闻
  1208. * @param array $data
  1209. * @return array
  1210. */
  1211. public function getWebsiteArticlett(array $data): array
  1212. {
  1213. $website_id = $data['website_id'];
  1214. $website = Website::where('id', $data['website_id'])->first();
  1215. if (empty($website)) {
  1216. return Result::error("网站不存在", 0);
  1217. }
  1218. $categorys = $this->processArticlePro($website_id);
  1219. $catiall = $categorys['catiall'];
  1220. $categoryIds = $categorys['categoryIds'];
  1221. $where = [
  1222. 'status' => 1
  1223. ];
  1224. // $website_column = $website['column'];
  1225. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1226. $website_column = json_decode($website['website_column_arr_id'], true);
  1227. }
  1228. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1229. // return Result::success($diff_pid_categoryIds);
  1230. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1231. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1232. }
  1233. // $website_id = $data['website_id'];
  1234. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  1235. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  1236. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  1237. switch ($data['level']) {
  1238. case 1:
  1239. case 2:
  1240. case 3:
  1241. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  1242. $query = Article::where($where)
  1243. ->where('level', 'like', '%' . $data['level'] . '%')
  1244. ->orderBy('updated_at', 'desc');
  1245. break;
  1246. case 4: //最新资讯
  1247. $query = Article::where($where)->orderBy('updated_at', 'desc');
  1248. break;
  1249. case 5: //资讯推荐
  1250. $query = Article::where($where)
  1251. ->where('updated_at', '>', $month);
  1252. break;
  1253. case 7: //资讯分类
  1254. if (isset($data['id']) && !empty($data['id'])) {
  1255. $keyword = Article::where('id', $data['id'])->value('keyword');
  1256. $keywordArray = explode(',', $keyword);
  1257. $whereL7 = [];
  1258. foreach ($keywordArray as $k => $v) {
  1259. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1260. }
  1261. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  1262. break;
  1263. } else {
  1264. return Result::error("请输入资讯ID", 0);
  1265. break;
  1266. }
  1267. default:
  1268. break;
  1269. }
  1270. // $whereL7 = [];
  1271. // if(isset($data['id']) && !empty($data['id'])){
  1272. // $keyword = Article::where('id', $data['id'])->value('keyword');
  1273. // $keywordArray = explode(',', $keyword);
  1274. // foreach ($keywordArray as $k => $v) {
  1275. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1276. // }
  1277. // }
  1278. // $query = Article::where($where)
  1279. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  1280. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  1281. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  1282. // }
  1283. // if($data['level'] == 7){
  1284. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  1285. // }
  1286. // if($data['level'] == 4){
  1287. // $query = $query->inRandomOrder()
  1288. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  1289. // }
  1290. // if($data['level'] == 5){
  1291. // $query = $query->orderBy('updated_at','desc');
  1292. // }
  1293. // });
  1294. if ($data['textnum'] > 0) {
  1295. $query = clone $query;
  1296. $result['text'] = $query
  1297. ->whereIn('catid', $categoryIds)
  1298. ->leftJoinSub(function ($query) use ($website_id) {
  1299. $query->from('article_ignore')
  1300. ->where('website_id', $website_id);
  1301. }, 'article_ignore', function ($join) {
  1302. $join->on('article_ignore.article_id', '=', 'article.id');
  1303. })
  1304. ->where(function ($query) {
  1305. $query->whereNull('article_ignore.article_id')
  1306. ->orWhere(function ($subQuery) {
  1307. $subQuery->whereNotNull('article_ignore.article_id')
  1308. ->where('article_ignore.is_ignore', 0)
  1309. ->where(function ($subSubQuery) {
  1310. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1311. ->orWhereNull('article_ignore.c_show_time');
  1312. });
  1313. });
  1314. })
  1315. // ->where(function ($query) use ($website_id) {
  1316. // $query->whereNull('article_ignore.article_id')
  1317. // ->orWhere('article_ignore.website_id', '!=', $website_id);
  1318. // })
  1319. ->select(
  1320. 'article.id',
  1321. 'article.title',
  1322. 'article.author',
  1323. 'article.updated_at',
  1324. 'article.introduce',
  1325. 'article.islink',
  1326. 'article.linkurl',
  1327. 'article.copyfrom',
  1328. 'article.cat_arr_id',
  1329. 'article.catid',
  1330. 'article.level',
  1331. // 'article_ignore.is_ignore',
  1332. // 'article_ignore.c_show_time',
  1333. )
  1334. ->offset($data['placeid'])
  1335. ->limit($data['textnum'])
  1336. ->get()->all();
  1337. foreach ($result['text'] as $k => $v) {
  1338. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1339. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  1340. }
  1341. }
  1342. if ($data['imgnum'] > 0) {
  1343. $query = clone $query;
  1344. if ($data['textnum'] == 0) {
  1345. $query = $query->leftJoinSub(function ($query) use ($website_id) {
  1346. $query->from('article_ignore')
  1347. ->where('website_id', $website_id);
  1348. }, 'article_ignore', function ($join) {
  1349. $join->on('article_ignore.article_id', '=', 'article.id');
  1350. })
  1351. ->where(function ($query) {
  1352. $query->whereNull('article_ignore.article_id')
  1353. ->orWhere(function ($subQuery) {
  1354. $subQuery->whereNotNull('article_ignore.article_id')
  1355. ->where('article_ignore.is_ignore', 0)
  1356. ->where(function ($subSubQuery) {
  1357. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1358. ->orWhereNull('article_ignore.c_show_time');
  1359. });
  1360. });
  1361. });
  1362. }
  1363. $result['img'] = $query
  1364. ->whereIn('catid', $categoryIds)
  1365. ->where('article.imgurl', '!=', '')
  1366. ->select(
  1367. 'article.id',
  1368. 'article.title',
  1369. 'article.imgurl',
  1370. 'article.author',
  1371. 'article.updated_at',
  1372. 'article.introduce',
  1373. 'article.islink',
  1374. 'article.linkurl',
  1375. 'article.copyfrom',
  1376. 'article.cat_arr_id',
  1377. 'article.catid',
  1378. 'article.level',
  1379. // 'article_ignore.is_ignore',
  1380. // 'article_ignore.c_show_time',
  1381. )
  1382. ->offset($data['placeid'])
  1383. ->limit($data['imgnum'])
  1384. ->get()->all();
  1385. foreach ($result['img'] as $k => $v) {
  1386. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1387. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1388. }
  1389. }
  1390. if (empty($result)) {
  1391. return Result::error("暂无相关资讯", 0);
  1392. }
  1393. return Result::success($result);
  1394. }
  1395. /**
  1396. * 获取模块新闻
  1397. * @param array $data
  1398. * @return array
  1399. */
  1400. public function getWebsiteModelArticles(array $data): array
  1401. {
  1402. $catid = $data['catid'];
  1403. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1404. $category = $category->toArray();
  1405. if (!empty($category)) {
  1406. $where = [
  1407. 'status' => 1,
  1408. 'catid' => $catid,
  1409. ];
  1410. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1411. // 1:文字新闻;2:轮播图;3:图文;
  1412. // 级别:0:未分类
  1413. // 3:推荐图片
  1414. if ($data['level'] == 1) {
  1415. $data['level'] = 0;
  1416. }
  1417. $result = Article::where($where)
  1418. ->where(function ($query) use ($data) {
  1419. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1420. ->orWhereNull("level")
  1421. ->orWhereRaw("level = '[]'");
  1422. })
  1423. ->leftJoinSub(function ($query) use ($data) {
  1424. $query->from('article_ignore')
  1425. ->where('website_id', $data['website_id']);
  1426. }, 'article_ignore', function ($join) {
  1427. $join->on('article_ignore.article_id', '=', 'article.id');
  1428. })
  1429. ->where(function ($query) {
  1430. $query->whereNull('article_ignore.article_id')
  1431. ->orWhere(function ($subQuery) {
  1432. $subQuery->whereNotNull('article_ignore.article_id')
  1433. ->where('article_ignore.is_ignore', 0)
  1434. ->where(function ($subSubQuery) {
  1435. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1436. ->orWhereNull('article_ignore.c_show_time');
  1437. });
  1438. });
  1439. })
  1440. // ->where(function ($query) use ($data) {
  1441. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1442. // ->orWhereNull("ignore_ids");
  1443. // })
  1444. ->orderBy("updated_at", "desc")
  1445. ->offset($placeid)
  1446. ->limit($data['pagesize'])
  1447. ->get();
  1448. if (empty($result)) {
  1449. return Result::error("此栏目暂无相关新闻", 0);
  1450. }
  1451. } else {
  1452. return Result::error("此网站暂无此栏目", 0);
  1453. }
  1454. return Result::success($result);
  1455. }
  1456. /**
  1457. *获取新闻列表
  1458. * @param array $data
  1459. * @return array
  1460. */
  1461. public function getWebsiteArticleList(array $data): array
  1462. {
  1463. // return Result::success($data);
  1464. $where[] = ['status', '=', 1];
  1465. $website_id = $data['website_id'];
  1466. $website = Website::where('id', $data['website_id'])->first();
  1467. if (empty($website)) {
  1468. return Result::error("网站不存在", 0);
  1469. }
  1470. // $website_column = $website['column'];
  1471. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1472. $website_column = json_decode($website['website_column_arr_id'], true);
  1473. }
  1474. $categorys = $this->processArticlePro($website_id);
  1475. $cat_1st_arr = $categorys['cat_1st_arr'];
  1476. $catiall = $categorys['catiall'];
  1477. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1478. // return Result::success($diff_pid_categoryIds);
  1479. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1480. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1481. }
  1482. if (isset($data['catid']) && !empty($data['catid'])) {
  1483. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1484. if (empty($category)) {
  1485. return Result::error("此网站暂无此栏目", 0);
  1486. }
  1487. array_push($where, ['catid', '=', $data['catid']]);
  1488. }
  1489. // return Result::success($where);
  1490. $query = Article::where($where)
  1491. ->leftJoinSub(function ($query) use ($website_id) {
  1492. $query->from('article_ignore')
  1493. ->where('website_id', $website_id);
  1494. }, 'article_ignore', function ($join) {
  1495. $join->on('article_ignore.article_id', '=', 'article.id');
  1496. })
  1497. ->where(function ($query) {
  1498. $query->whereNull('article_ignore.article_id')
  1499. ->orWhere(function ($subQuery) {
  1500. $subQuery->whereNotNull('article_ignore.article_id')
  1501. ->where('article_ignore.is_ignore', 0)
  1502. ->where(function ($subSubQuery) {
  1503. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1504. ->orWhereNull('article_ignore.c_show_time');
  1505. });
  1506. });
  1507. })
  1508. ->select(
  1509. 'article.id',
  1510. 'article.title',
  1511. 'article.imgurl',
  1512. 'article.author',
  1513. 'article.updated_at',
  1514. 'article.introduce',
  1515. 'article.islink',
  1516. 'article.linkurl',
  1517. 'article.copyfrom',
  1518. 'article.cat_arr_id',
  1519. 'article.catid'
  1520. );
  1521. $count = $query->count();
  1522. $rep = $query->orderBy("updated_at", "desc")
  1523. ->offset(($data['page'] - 1) * $data['pageSize'])
  1524. ->limit($data['pageSize'])
  1525. ->get()->all();
  1526. $categorys = $this->processArticlePro($website_id);
  1527. $cat_1st_arr = $categorys['cat_1st_arr'];
  1528. $catiall = $categorys['catiall'];
  1529. // $web['website_id'] = $data['website_id'];
  1530. foreach ($rep as $k => $v) {
  1531. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1532. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1533. }
  1534. // $rep = $this->processArticles($rep,$web);
  1535. $data = [
  1536. 'rows' => $rep,
  1537. 'count' => $count,
  1538. ];
  1539. if (empty($rep)) {
  1540. return Result::error("没有信息数据");
  1541. }
  1542. return Result::success($data);
  1543. }
  1544. /**
  1545. * 前端-获取新闻详情
  1546. * @param array $data
  1547. * @return array
  1548. */
  1549. public function selectWebsiteArticleInfo(array $data): array
  1550. {
  1551. $where = [
  1552. 'article.id' => $data['id'],
  1553. 'article.status' => 1,
  1554. ];
  1555. $result = Article::where($where)
  1556. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1557. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1558. // ->where(function ($query) use ($data) {
  1559. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1560. // ->orWhereNull("ignore_ids");
  1561. // })
  1562. ->leftJoinSub(function ($query) use ($data) {
  1563. $query->from('article_ignore')
  1564. ->where('website_id', $data['website_id']);
  1565. }, 'article_ignore', function ($join) {
  1566. $join->on('article_ignore.article_id', '=', 'article.id');
  1567. })
  1568. ->where(function ($query) {
  1569. $query->whereNull('article_ignore.article_id')
  1570. ->orWhere(function ($subQuery) {
  1571. $subQuery->whereNotNull('article_ignore.article_id')
  1572. ->where('article_ignore.is_ignore', 0)
  1573. ->where(function ($subSubQuery) {
  1574. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1575. ->orWhereNull('article_ignore.c_show_time');
  1576. });
  1577. });
  1578. })
  1579. ->select(
  1580. 'article.*',
  1581. 'article_data.content',
  1582. 'article_data.article_id',
  1583. 'article_extend.website_url',
  1584. 'article_extend.email',
  1585. 'article_extend.contacts',
  1586. 'article_extend.contacts_mobile',
  1587. 'article_extend.contacts_address',
  1588. 'article_extend.zip_code',
  1589. 'article_extend.enterprise_name'
  1590. )
  1591. ->first();
  1592. if (empty($result)) {
  1593. return Result::error("暂无此新闻!", 0);
  1594. }
  1595. if (!empty($result['publiced_at'])) {
  1596. $result['updated_at'] = $result['publiced_at'];
  1597. }
  1598. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1599. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1600. ->where('website_category.website_id', $data['website_id'])
  1601. ->where(['website_category.category_id' => $result['catid']])
  1602. ->first();
  1603. if (empty($category)) {
  1604. return Result::error("查询失败", 0);
  1605. }
  1606. //手动推荐文章
  1607. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1608. if (empty($commend_ids)) {
  1609. $commendArticle = [];
  1610. } else {
  1611. //去除不存在的文章ID
  1612. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1613. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1614. ->leftJoinSub(function ($query) use ($data) {
  1615. $query->from('article_ignore')
  1616. ->where('website_id', $data['website_id']);
  1617. }, 'article_ignore', function ($join) {
  1618. $join->on('article_ignore.article_id', '=', 'article.id');
  1619. })
  1620. ->where(function ($query) {
  1621. $query->whereNull('article_ignore.article_id')
  1622. ->orWhere(function ($subQuery) {
  1623. $subQuery->whereNotNull('article_ignore.article_id')
  1624. ->where('article_ignore.is_ignore', 0)
  1625. ->where(function ($subSubQuery) {
  1626. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1627. ->orWhereNull('article_ignore.c_show_time');
  1628. });
  1629. });
  1630. })
  1631. ->where('article.status', 1)
  1632. ->where('website_category.website_id', $data['website_id'])
  1633. ->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')
  1634. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1635. // ->orderBy('article.updated_at', 'desc')
  1636. ->limit(5)
  1637. ->get();
  1638. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1639. foreach ($commendArticle as $k => $v) {
  1640. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1641. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1642. $cat_arr_id = array_unique($cat_arr_id);
  1643. // 从website_category取出alias_pinyin
  1644. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1645. ->whereIn('category_id', $cat_arr_id)
  1646. ->pluck('alias_pinyin', 'category_id')
  1647. ->toArray();
  1648. // 将cat_arr_id的json转成路径/隔开
  1649. $path_parts = [];
  1650. foreach ($cat_arr_id as $cat_id) {
  1651. if (isset($cat_arr[$cat_id])) {
  1652. $path_parts[] = $cat_arr[$cat_id];
  1653. }
  1654. }
  1655. $v->alias_pinyin = implode('/', $path_parts);
  1656. } else {
  1657. $v->alias_pinyin = '';
  1658. }
  1659. }
  1660. }
  1661. $result['category_id'] = $category['category_id'];
  1662. $result['cat_name'] = $category['alias'];
  1663. $result['website_name'] = $category['website_name'] ?? "";
  1664. $result['suffix'] = $category['suffix'] ?? "";
  1665. $result['commendArticle'] = $commendArticle;
  1666. $result['commend_ids'] = $commend_ids;
  1667. return Result::success($result);
  1668. }
  1669. /**
  1670. * 前端-获取网站调查问卷
  1671. * @param array $data
  1672. * @return array
  1673. */
  1674. public function getWebsiteSurvey(array $data): array
  1675. {
  1676. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1677. $website = Website::where('id', $data['website_id'])->first();
  1678. if (empty($website)) {
  1679. return Result::error("暂无此网站", 0);
  1680. }
  1681. }
  1682. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1683. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1684. if (empty($article)) {
  1685. return Result::error("暂无此文章", 0);
  1686. }
  1687. // return Result::error($data,0);
  1688. $where['art_id'] = $data['art_id'];
  1689. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1690. } else {
  1691. $survey = Article::where(function ($query) {
  1692. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1693. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1694. })
  1695. ->where('status', 1)
  1696. ->where('is_survey', 1)
  1697. ->select('survey_id')
  1698. ->orderBy('updated_at', 'desc')
  1699. ->first();
  1700. if (empty($survey)) {
  1701. return Result::error("暂无调查问卷", 0);
  1702. }
  1703. $where['sur_id'] = $survey['survey_id'];
  1704. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1705. }
  1706. // return Result::success($where);
  1707. $result = ArticleSurvey::where($where)
  1708. ->where(function ($query) {
  1709. $query->where('is_other', 0)
  1710. ->orWhere(function ($subQuery) {
  1711. $subQuery->where('is_other', 1)
  1712. ->where('other_id', 0);
  1713. });
  1714. })
  1715. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1716. ->select('article_survey.*', 'article.survey_type')
  1717. ->get()->all();
  1718. if (empty($result)) {
  1719. return Result::error("此文章暂无调查问卷", 0);
  1720. }
  1721. return Result::success($result);
  1722. }
  1723. /**
  1724. * 前端-添加网站调查问卷选项
  1725. * @param array $data
  1726. * @return array
  1727. */
  1728. public function addWebsiteSurveyOption(array $data): array
  1729. {
  1730. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1731. $website = Website::where('id', $data['website_id'])->first();
  1732. if (empty($website)) {
  1733. return Result::error("暂无此网站", 0);
  1734. }
  1735. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1736. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1737. if (empty($survey)) {
  1738. return Result::error("此调查问卷不可添加选项", 0);
  1739. }
  1740. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1741. $choice = [
  1742. 'art_id' => $survey['art_id'],
  1743. 'website_id' => $data['website_id'],
  1744. 'survey_name' => $survey['survey_name'],
  1745. 'choice_name' => $data['choice_name'],
  1746. 'sur_id' => $survey['sur_id'],
  1747. 'is_other' => 1,
  1748. 'other_id' => $survey['id'],
  1749. ];
  1750. $result = ArticleSurvey::insertGetId($choice);
  1751. if (empty($result)) {
  1752. return Result::error("添加失败", 0);
  1753. }
  1754. return Result::success($result);
  1755. }
  1756. }
  1757. return Result::error("添加失败", 0);
  1758. }
  1759. return Result::error("添加失败", 0);
  1760. }
  1761. /**
  1762. * 前端-调查问卷投票
  1763. * @param array $data
  1764. * @return array
  1765. */
  1766. public function addWebsiteSurveyVote(array $data): array
  1767. {
  1768. // return Result::success($data);
  1769. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1770. $website = Website::where('id', $data['website_id'])->first();
  1771. if (empty($website)) {
  1772. return Result::error("暂无此网站", 0);
  1773. }
  1774. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1775. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1776. // return Result::success($survey);
  1777. if (empty($is_survey)) {
  1778. return Result::error("此调查问卷不存在", 0);
  1779. }
  1780. // return Result::success($survey);
  1781. // 调查问卷类型
  1782. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1783. //多选 若是json型则转化成数组类型
  1784. if (strpos($data['choice_id'], '[') === 0) {
  1785. $data['choice_id'] = json_decode($data['choice_id'], true);
  1786. } else {
  1787. // 单选 也转换成数组
  1788. $data['choice_id'] = [$data['choice_id']];
  1789. }
  1790. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1791. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1792. // ->where('website_id',$data['website_id'])
  1793. ->where('is_other', 1)
  1794. ->where('other_id', 0)
  1795. ->first();
  1796. if (!empty($other)) {
  1797. return Result::error("请选择已有的选项!", 0);
  1798. }
  1799. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1800. // ->where('website_id',$data['website_id'])
  1801. ->where('is_other', 1)
  1802. ->where('other_id', '!=', 0)
  1803. ->first();
  1804. // return Result::success($choice['other']);
  1805. $choice_id = $data['choice_id'];
  1806. if (!empty($choice['other'])) {
  1807. // array_push($data['choice_id'],$choice['other']['other_id']);
  1808. if (!empty($choice_id)) {
  1809. $key = array_search($choice['other']['id'], $choice_id);
  1810. if ($key !== false) {
  1811. unset($choice_id[$key]);
  1812. $choice_id = array_values($choice_id);
  1813. }
  1814. array_push($choice_id, $choice['other']['other_id']);
  1815. } else {
  1816. $choice_id[0] = $choice['other']['other_id'];
  1817. }
  1818. array_push($data['choice_id'], $choice['other']['other_id']);
  1819. }
  1820. // return Result::success($data);
  1821. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1822. // ->where('website_id',$data['website_id'])
  1823. ->increment('results', 1);
  1824. if (empty($choice)) {
  1825. return Result::error("请选择已有的选项!", 0);
  1826. }
  1827. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1828. // ->where('website_id',$data['website_id'])
  1829. ->where('other_id', 0)
  1830. ->get();
  1831. $survey['choice'] = $choice_id;
  1832. return Result::success($survey);
  1833. }
  1834. return Result::error("参数必填!");
  1835. }
  1836. return Result::error("此调查问卷不存在", 0);
  1837. }
  1838. return Result::error("参数必填!");
  1839. }
  1840. /**
  1841. * 后端-获取网站调查问卷列表
  1842. * @param array $data
  1843. * @return array
  1844. */
  1845. public function getSurveyList(array $data): array
  1846. {
  1847. $where = [];
  1848. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1849. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1850. }
  1851. $survey_type = isset($data['survey_type']) && $data['survey_type'] !== '' ? $data['survey_type'] : null;
  1852. if (!empty($where)) {
  1853. // 修复:先关联 article 再按 survey_type 过滤,避免查不到数据
  1854. $query = ArticleSurvey::select(
  1855. 'art_id as id',
  1856. Db::raw('MAX(id) as surid'),
  1857. Db::raw('MAX(survey_name) as survey_name'),
  1858. Db::raw('MAX(sur_id) as survey_id')
  1859. )
  1860. ->groupBy('art_id')
  1861. ->where($where)
  1862. ->when(!is_null($survey_type), function ($q) use ($survey_type) {
  1863. $q->whereIn('art_id', function ($sub) use ($survey_type) {
  1864. $sub->select('id')
  1865. ->from('article')
  1866. ->where('survey_type', $survey_type);
  1867. });
  1868. })
  1869. ->with(['article' => function ($query) {
  1870. $query->select('id', 'survey_type','created_at','updated_at','created_at');
  1871. }]);
  1872. ;
  1873. }else{
  1874. $query = ArticleSurvey::select(
  1875. 'art_id as id',
  1876. Db::raw('MAX(id) as surid'),
  1877. Db::raw('MAX(survey_name) as survey_name'),
  1878. Db::raw('MAX(sur_id) as survey_id'),
  1879. )
  1880. ->groupBy('art_id')
  1881. ->when(!is_null($survey_type), function ($q) use ($survey_type) {
  1882. $q->whereIn('art_id', function ($sub) use ($survey_type) {
  1883. $sub->select('id')
  1884. ->from('article')
  1885. ->where('survey_type', $survey_type);
  1886. });
  1887. })
  1888. ->with(['article' => function ($query) {
  1889. $query->select('id', 'survey_type','created_at','updated_at','created_at');
  1890. }]);
  1891. }
  1892. $count = $query->get()->count();
  1893. // 简单写法:直接统计分组后的 art_id 数量
  1894. $survey = $query->orderBy('id', 'desc')
  1895. ->limit($data['pageSize'])
  1896. ->offset(($data['page'] - 1) * $data['pageSize'])
  1897. ->get();
  1898. if (empty($survey->toArray())) {
  1899. return Result::error("暂无调查问卷!", 0);
  1900. }
  1901. $survey = array_map(function ($item) {
  1902. if (isset($item['article'])) {
  1903. $item['survey_type'] = $item['article']['survey_type'];
  1904. $item['created_at'] = $item['article']['created_at'];
  1905. $item['updated_at'] = $item['article']['updated_at'];
  1906. } else {
  1907. // 处理article为null的情况,设置默认值
  1908. $item['survey_type'] = null;
  1909. $item['created_at'] = null;
  1910. $item['updated_at'] = null;
  1911. }
  1912. unset($item['article']);
  1913. return $item;
  1914. }, $survey->toArray());
  1915. $result = [
  1916. 'rows' => $survey,
  1917. 'count' => $count,
  1918. ];
  1919. return Result::success($result);
  1920. }
  1921. /**
  1922. * 后端-获取网站调查问卷详情
  1923. * @param array $data
  1924. * @return array
  1925. */
  1926. public function getSurveyInfo(array $data): array
  1927. {
  1928. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1929. $where = ['sur_id' => $data['sur_id']];
  1930. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1931. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1932. ->select('article_survey.*', 'article.survey_type')
  1933. ->get()->all();
  1934. if (empty($choose)) {
  1935. return Result::error("此调查问卷不存在", 0);
  1936. }
  1937. $resultsArray = array_column($choose, 'results');
  1938. $total = array_sum($resultsArray);
  1939. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1940. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1941. // $total = 0;
  1942. if (!empty($other)) {
  1943. $total = $total + $other['results'];
  1944. $other['choice_name'] = '(其他)';
  1945. if (!empty($others)) {
  1946. $other['hasChildren'] = true;
  1947. // array_push($other,['hasChildren','=',true]);
  1948. $other['children'] = $others;
  1949. $other_choices = [$other->toArray()];
  1950. $mer_choice = array_merge($choose, $other_choices);
  1951. $value_choice = array_values($mer_choice);
  1952. } else {
  1953. // return Result::error('1111');
  1954. $other_choices = [$other->toArray()];
  1955. $other_choices = array_merge($choose, $other_choices);
  1956. $value_choice = array_values($other_choices);
  1957. // return Result::success($result);
  1958. }
  1959. } else {
  1960. $value_choice = $choose;
  1961. }
  1962. $result = [
  1963. 'choose' => $value_choice,
  1964. 'total' => $total,
  1965. ];
  1966. }
  1967. return Result::success($result);
  1968. }
  1969. /**
  1970. * 前端-搜索新闻列表
  1971. * @param array $data
  1972. * @return array
  1973. */
  1974. public function selectWebsiteArticle(array $data): array
  1975. {
  1976. $website = Website::where('id', $data['website_id'])->first();
  1977. if (empty($website)) {
  1978. return Result::error("网站不存在", 0);
  1979. }
  1980. // $website_column = $website['column'];
  1981. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1982. $website_column = json_decode($website['website_column_arr_id'], true);
  1983. }
  1984. $website_id = $data['website_id'];
  1985. $categorys = $this->processArticlePro($website_id);
  1986. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1987. // return Result::success($diff_pid_categoryIds);
  1988. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1989. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1990. }
  1991. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1992. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1993. $catiall = $categorys['catiall'];
  1994. $categoryIds = $categorys['categoryIds'];
  1995. // return Result::success($categoryIds);
  1996. $query = Article::where('status', 1)
  1997. ->whereIn('catid', $categoryIds)
  1998. ->leftJoinSub(function ($query) use ($website_id) {
  1999. $query->from('article_ignore')
  2000. ->where('website_id', $website_id);
  2001. }, 'article_ignore', function ($join) {
  2002. $join->on('article_ignore.article_id', '=', 'article.id');
  2003. })
  2004. ->where(function ($query) {
  2005. $query->whereNull('article_ignore.article_id')
  2006. ->orWhere(function ($subQuery) {
  2007. $subQuery->whereNotNull('article_ignore.article_id')
  2008. ->where('article_ignore.is_ignore', 0)
  2009. ->where(function ($subSubQuery) {
  2010. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2011. ->orWhereNull('article_ignore.c_show_time');
  2012. });
  2013. });
  2014. });
  2015. // ->get()->all();
  2016. // return Result::success($query);
  2017. if (isset($data['cityid']) && !empty($data['cityid'])) {
  2018. $query->whereRaw("JSON_CONTAINS(article.city_arr_id, '" . intval($data['cityid']) . "')");
  2019. }
  2020. if (isset($data['department_id']) && !empty($data['department_id'])) {
  2021. $query->whereRaw("JSON_CONTAINS(article.department_arr_id, '" . intval($data['department_id']) . "')");
  2022. }
  2023. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2024. $query->where('article.title', 'like', '%' . $data['keyword'] . '%');
  2025. }
  2026. // 计算总数
  2027. $count = $query->count();
  2028. // return Result::success($count);
  2029. // 分页查询
  2030. $articles = $query
  2031. ->select(
  2032. 'article.id',
  2033. 'article.title',
  2034. 'article.imgurl',
  2035. 'article.author',
  2036. 'article.updated_at',
  2037. 'article.introduce',
  2038. 'article.islink',
  2039. 'article.linkurl',
  2040. 'article.copyfrom',
  2041. 'article.cat_arr_id',
  2042. 'article.catid',
  2043. 'article.department_arr_id',
  2044. 'article.city_arr_id',
  2045. // 'article_ignore.c_show_time',
  2046. // 'article_ignore.is_ignore'
  2047. )
  2048. ->orderBy("updated_at", "desc")
  2049. ->offset(($data['page'] - 1) * $data['pageSize'])
  2050. ->limit($data['pageSize'])
  2051. ->get();
  2052. // return Result::success($articles);
  2053. foreach ($articles as $k => $v) {
  2054. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  2055. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2056. }
  2057. if (empty($articles)) {
  2058. return Result::error("没有符合条件的资讯数据");
  2059. }
  2060. $result = [
  2061. 'rows' => $articles,
  2062. 'count' => $count,
  2063. ];
  2064. return Result::success($result);
  2065. }
  2066. /**
  2067. * 模块新闻加强版
  2068. * @param array $data
  2069. * @return array
  2070. */
  2071. public function getWebsiteCatidArticle(array $data): array
  2072. {
  2073. $where = [
  2074. 'website_category.category_id' => $data['catid'],
  2075. 'website_category.website_id' => $data['website_id'],
  2076. ];
  2077. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  2078. $child_catnum = $data['child_catnum'] ?? 1;
  2079. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  2080. $childCategoryIds = array_column($category['child'], 'category_id');
  2081. if (empty($childCategoryIds)) {
  2082. return Result::error("暂无子栏目", 0);
  2083. }
  2084. $imgArticles = [];
  2085. $textArticles = [];
  2086. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  2087. // 初始化子分类图片新闻和文字新闻数组
  2088. // 查询所有子级栏目的图文新闻
  2089. $imgArticles = Article::where('catid', $childCategoryIds[0])
  2090. ->where(function ($query) use ($data) {
  2091. $query->where(function ($subQuery) use ($data) {
  2092. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2093. })->orWhereNull("ignore_ids");
  2094. })
  2095. ->where('status', 1)
  2096. ->where('imgurl', '!=', '')
  2097. ->select('*')
  2098. ->orderBy('updated_at', 'desc')
  2099. ->limit($data['child_imgnum'])
  2100. ->get();
  2101. }
  2102. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  2103. // 查询所有子级栏目的文字新闻
  2104. $textArticles = Article::where('catid', $childCategoryIds[0])
  2105. ->where('status', 1)
  2106. ->where(function ($query) use ($data) {
  2107. $query->where(function ($subQuery) use ($data) {
  2108. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2109. })->orWhereNull("ignore_ids");
  2110. })
  2111. ->select('*')
  2112. ->orderBy('updated_at', 'desc')
  2113. ->limit($data['child_textnum'])
  2114. ->get();
  2115. }
  2116. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  2117. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  2118. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  2119. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  2120. return $child;
  2121. }, $category['child']);
  2122. }
  2123. // }
  2124. if (isset($data['img_num']) && !empty($data['img_num'])) {
  2125. $category['img'] = WebsiteCategory::where($where)
  2126. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2127. ->where('article.status', 1)
  2128. ->where('article.imgurl', '!=', '')
  2129. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2130. ->orderBy('article.updated_at', 'desc')
  2131. ->limit($data['img_num'])
  2132. ->get();
  2133. }
  2134. if (isset($data['text_num']) && !empty($data['text_num'])) {
  2135. $category['text'] = WebsiteCategory::where($where)
  2136. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2137. ->where('article.status', 1)
  2138. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2139. ->orderBy('article.updated_at', 'desc')
  2140. ->limit($data['text_num'])
  2141. ->get();
  2142. }
  2143. // $category = $category->get();
  2144. if (empty($category)) {
  2145. return Result::error("查询失败", 0);
  2146. }
  2147. return Result::success($category);
  2148. }
  2149. /**
  2150. * 模块新闻加强plus版
  2151. * @param array $data
  2152. * @return array
  2153. */
  2154. public function getWebsiteAllArticle(array $data): array
  2155. {
  2156. // return Result::success($data);
  2157. $time1 = microtime(true);
  2158. $wetbsite_id = $data['website_id'] ?? 2;
  2159. $data = json_decode($data['id'], true);
  2160. $website = Website::where('id', $wetbsite_id)->first();
  2161. if (empty($website)) {
  2162. return Result::error("网站不存在", 0);
  2163. }
  2164. // return Result::success($website);
  2165. $website_column = $website['website_column_arr_id'] ?? '[]';
  2166. $website_column = json_decode($website_column, true);
  2167. $categorys = $this->processArticlePro($wetbsite_id);
  2168. $cat_1st_arr = $categorys['cat_1st_arr'];
  2169. $catiall = $categorys['catiall'];
  2170. // return Result::success($catiall);
  2171. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2172. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2173. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2174. }
  2175. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  2176. // return Result::success($categorys);
  2177. $parent_category = array_column($data, 'parent');
  2178. $parent_cat = [];
  2179. $child_category = array_column($data, 'child');
  2180. if (!empty($parent_category)) {
  2181. foreach ($parent_category as $key => $value) {
  2182. $arr = array_map('intval', explode(',', $value));
  2183. $parent_cat[$key] = $arr[0] ?? 0;
  2184. $parent_category = $arr[0] ?? 0;
  2185. $article_imgnum = $arr[1] ?? 0;
  2186. $article_textnum = $arr[2] ?? 0;
  2187. if ($parent_category != 0) {
  2188. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2189. // return Result::success($category_arr);
  2190. if ($article_imgnum != 0) {
  2191. $img_article = Article::whereIn('catid', $category_arr)
  2192. ->where('status', 1)
  2193. ->where('imgurl', '!=', '')
  2194. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2195. $query->from('article_ignore')
  2196. ->where('website_id', $wetbsite_id);
  2197. }, 'article_ignore', function ($join) {
  2198. $join->on('article_ignore.article_id', '=', 'article.id');
  2199. })
  2200. ->where(function ($query) {
  2201. $query->whereNull('article_ignore.article_id')
  2202. ->orWhere(function ($subQuery) {
  2203. $subQuery->whereNotNull('article_ignore.article_id')
  2204. ->where('article_ignore.is_ignore', 0)
  2205. ->where(function ($subSubQuery) {
  2206. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2207. ->orWhereNull('article_ignore.c_show_time');
  2208. });
  2209. });
  2210. })
  2211. ->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')
  2212. ->orderBy('updated_at', 'desc')
  2213. ->limit($article_imgnum)
  2214. ->get()->all();
  2215. foreach ($img_article as $k => $v) {
  2216. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2217. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2218. }
  2219. } else {
  2220. $img_article = [];
  2221. }
  2222. if ($article_textnum != 0) {
  2223. $text_article = Article::whereIn('catid', $category_arr)
  2224. ->where('status', 1)
  2225. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2226. $query->from('article_ignore')
  2227. ->where('website_id', $wetbsite_id);
  2228. }, 'article_ignore', function ($join) {
  2229. $join->on('article_ignore.article_id', '=', 'article.id');
  2230. })
  2231. ->where(function ($query) {
  2232. $query->whereNull('article_ignore.article_id')
  2233. ->orWhere(function ($subQuery) {
  2234. $subQuery->whereNotNull('article_ignore.article_id')
  2235. ->where('article_ignore.is_ignore', 0)
  2236. ->where(function ($subSubQuery) {
  2237. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2238. ->orWhereNull('article_ignore.c_show_time');
  2239. });
  2240. });
  2241. })
  2242. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2243. ->orderBy('updated_at', 'desc')
  2244. ->limit($article_textnum)
  2245. ->get()->all();
  2246. foreach ($text_article as $k => $v) {
  2247. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2248. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2249. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2250. }
  2251. } else {
  2252. $text_article = [];
  2253. }
  2254. $catiall[$parent_category]['imgnum'] = $img_article;
  2255. $catiall[$parent_category]['textnum'] = $text_article;
  2256. $parent[$key] = $catiall[$parent_category];
  2257. } else {
  2258. $parent[$key] = '';
  2259. }
  2260. }
  2261. }
  2262. if (!empty($child_category)) {
  2263. foreach ($child_category as $key => $value) {
  2264. $arr = array_map('intval', explode(',', $value));
  2265. $parent_category = $parent_cat[$key];
  2266. $child_category = $arr[0] ?? 0;
  2267. $article_imgnum = $arr[1] ?? 0;
  2268. $article_textnum = $arr[2] ?? 0;
  2269. if ($child_category != 0) {
  2270. $all_childcat = $cat_1st_arr[$parent_category];
  2271. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  2272. // 从 $websiteInfoIndexed 中获取对应的数据
  2273. $info = $websiteInfoIndexed[$v];
  2274. // 返回一个包含所需信息的数组
  2275. return [
  2276. 'alias' => $info->alias,
  2277. 'category_id' => $info->category_id,
  2278. 'aLIas_pinyin' => $info->aLIas_pinyin,
  2279. 'pid' => $info->pid,
  2280. 'type' => $info->type,
  2281. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  2282. 'pinyin' => $info->pinyin,
  2283. ];
  2284. }, $all_childcat);
  2285. if ($article_imgnum != 0) {
  2286. $img_article = Article::where('catid', $child_category)
  2287. ->where('status', 1)
  2288. ->where('imgurl', '!=', '')
  2289. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2290. $query->from('article_ignore')
  2291. ->where('website_id', $wetbsite_id);
  2292. }, 'article_ignore', function ($join) {
  2293. $join->on('article_ignore.article_id', '=', 'article.id');
  2294. })
  2295. ->where(function ($query) {
  2296. $query->whereNull('article_ignore.article_id')
  2297. ->orWhere(function ($subQuery) {
  2298. $subQuery->whereNotNull('article_ignore.article_id')
  2299. ->where('article_ignore.is_ignore', 0)
  2300. ->where(function ($subSubQuery) {
  2301. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2302. ->orWhereNull('article_ignore.c_show_time');
  2303. });
  2304. });
  2305. })
  2306. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2307. ->orderBy('updated_at', 'desc')
  2308. ->limit($article_imgnum)
  2309. ->get()->all();
  2310. foreach ($img_article as $k => $v) {
  2311. // var_dump($v);
  2312. // var_dump($k);
  2313. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2314. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2315. }
  2316. } else {
  2317. $img_article = [];
  2318. }
  2319. if ($article_textnum != 0) {
  2320. $text_article = Article::where('catid', $child_category)
  2321. ->where('status', 1)
  2322. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2323. $query->from('article_ignore')
  2324. ->where('website_id', $wetbsite_id);
  2325. }, 'article_ignore', function ($join) {
  2326. $join->on('article_ignore.article_id', '=', 'article.id');
  2327. })
  2328. ->where(function ($query) {
  2329. $query->whereNull('article_ignore.article_id')
  2330. ->orWhere(function ($subQuery) {
  2331. $subQuery->whereNotNull('article_ignore.article_id')
  2332. ->where('article_ignore.is_ignore', 0)
  2333. ->where(function ($subSubQuery) {
  2334. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2335. ->orWhereNull('article_ignore.c_show_time');
  2336. });
  2337. });
  2338. })
  2339. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2340. ->orderBy('updated_at', 'desc')
  2341. ->limit($article_textnum)
  2342. ->get()->all();
  2343. foreach ($text_article as $k => $v) {
  2344. // var_dump($v);
  2345. // var_dump($k);
  2346. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2347. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2348. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2349. }
  2350. } else {
  2351. $text_article = [];
  2352. }
  2353. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  2354. $catiall[$child_category]['imgnum'] = $img_article;
  2355. $catiall[$child_category]['textnum'] = $text_article;
  2356. $child[$key] = $catiall[$child_category];
  2357. // var_dump($pids);
  2358. } else {
  2359. $child[$key] = '';
  2360. }
  2361. }
  2362. }
  2363. foreach ($parent as $key => $value) {
  2364. $result[$key] = $value;
  2365. if (!empty($child[$key])) {
  2366. // var_dump($child[$key]);
  2367. $result[$key]['child'] = $child[$key];
  2368. // $value[$key]['child'] = $child[$key];
  2369. } else {
  2370. $result[$key]['child'] = [
  2371. "alias" => null,
  2372. "category_id" => null,
  2373. "type" => null,
  2374. "pinyin" => null,
  2375. "all_childcat" => [],
  2376. "imgnum" => [],
  2377. "textnum" => []
  2378. ];
  2379. }
  2380. }
  2381. return Result::success($result);
  2382. }
  2383. /**
  2384. * 辅助方法:获取文章列表
  2385. */
  2386. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  2387. {
  2388. sleep(1);
  2389. $query = Article::where('article.status', 1)
  2390. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  2391. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  2392. ->where(function ($query) use ($website) {
  2393. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  2394. })
  2395. ->leftJoin('website_category', function ($join) use ($website) {
  2396. $join->on('article.catid', '=', 'website_category.category_id')
  2397. ->where('website_category.website_id', '=', $website['website_id']);
  2398. })
  2399. ->select(
  2400. 'article.id',
  2401. 'article.title',
  2402. 'article.imgurl',
  2403. 'article.author',
  2404. 'article.updated_at',
  2405. 'article.introduce',
  2406. 'article.islink',
  2407. 'article.linkurl',
  2408. 'article.copyfrom',
  2409. 'article.cat_arr_id',
  2410. 'article.catid',
  2411. 'website_category.alias as category_name'
  2412. )
  2413. ->orderBy('updated_at', 'desc')
  2414. ->limit($limit);
  2415. // 如果是图片文章,添加图片URL条件
  2416. if ($isImageArticle) {
  2417. $query->where('imgurl', '!=', '');
  2418. } else {
  2419. // 文字文章不需要imgurl字段
  2420. $query->addSelect('article.introduce');
  2421. }
  2422. $articles = $query->get();
  2423. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  2424. }
  2425. /**
  2426. * 乡村网-获取特殊新闻模块
  2427. * @param array $data
  2428. * @return array
  2429. */
  2430. public function getWebsiteArticles(array $data): array
  2431. {
  2432. $website_id = $data['website_id'];
  2433. $website = Website::where('id', $website_id)->first();
  2434. if (empty($website)) {
  2435. return Result::error("网站不存在", 0);
  2436. }
  2437. // return Result::success($website);
  2438. $website_column = $website['website_column_arr_id'] ?? '[]';
  2439. $website_column = json_decode($website_column, true);
  2440. $catids = json_decode($data['id'], true);
  2441. $parent_category = array_column($catids, 'parent');
  2442. if (!empty($parent_category) && is_array($parent_category)) {
  2443. $categorys = $this->processArticlePro($website_id);
  2444. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2445. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2446. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2447. }
  2448. $catiall = $categorys['catiall'];
  2449. $cat_1st_arr = $categorys['cat_1st_arr'];
  2450. // return Result::success($categorys);
  2451. foreach ($parent_category as $key => $value) {
  2452. $arr = array_map('intval', explode(',', $value));
  2453. $parent_category = $arr[0] ?? 0;
  2454. $article_imgnum = $arr[1] ?? 0;
  2455. $article_textnum = $arr[2] ?? 0;
  2456. if ($parent_category != 0) {
  2457. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2458. // return Result::success($category_arr);
  2459. if ($article_imgnum != 0) {
  2460. $img_article = Article::whereIn('article.catid', $category_arr)
  2461. ->where('article.status', 1)
  2462. ->where('article.imgurl', '!=', '')
  2463. ->leftJoinSub(function ($query) use ($website_id) {
  2464. $query->from('article_ignore')
  2465. ->where('website_id', $website_id);
  2466. }, 'article_ignore', function ($join) {
  2467. $join->on('article_ignore.article_id', '=', 'article.id');
  2468. })
  2469. ->where(function ($query) {
  2470. $query->whereNull('article_ignore.article_id')
  2471. ->orWhere(function ($subQuery) {
  2472. $subQuery->whereNotNull('article_ignore.article_id')
  2473. ->where('article_ignore.is_ignore', 0)
  2474. ->where(function ($subSubQuery) {
  2475. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2476. ->orWhereNull('article_ignore.c_show_time');
  2477. });
  2478. });
  2479. })
  2480. ->select(
  2481. 'article.id',
  2482. 'article.title',
  2483. 'article.imgurl',
  2484. 'article.author',
  2485. 'article.updated_at',
  2486. 'article.introduce',
  2487. 'article.islink',
  2488. 'article.linkurl',
  2489. 'article.copyfrom',
  2490. 'article.cat_arr_id',
  2491. 'article.catid as category_id'
  2492. )
  2493. ->orderBy('updated_at', 'desc')
  2494. ->limit($article_imgnum)
  2495. ->get()->all();
  2496. foreach ($img_article as $k => $v) {
  2497. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2498. // return Result::success($v);
  2499. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2500. }
  2501. } else {
  2502. $img_article = [];
  2503. }
  2504. if ($article_textnum != 0) {
  2505. $text_article = Article::whereIn('article.catid', $category_arr)
  2506. ->where('article.status', 1)
  2507. ->leftJoinSub(function ($query) use ($website_id) {
  2508. $query->from('article_ignore')
  2509. ->where('website_id', $website_id);
  2510. }, 'article_ignore', function ($join) {
  2511. $join->on('article_ignore.article_id', '=', 'article.id');
  2512. })
  2513. ->where(function ($query) {
  2514. $query->whereNull('article_ignore.article_id')
  2515. ->orWhere(function ($subQuery) {
  2516. $subQuery->whereNotNull('article_ignore.article_id')
  2517. ->where('article_ignore.is_ignore', 0)
  2518. ->where(function ($subSubQuery) {
  2519. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2520. ->orWhereNull('article_ignore.c_show_time');
  2521. });
  2522. });
  2523. })
  2524. ->select(
  2525. 'article.id',
  2526. 'article.title',
  2527. 'article.author',
  2528. 'article.updated_at',
  2529. 'article.introduce',
  2530. 'article.islink',
  2531. 'article.linkurl',
  2532. 'article.copyfrom',
  2533. 'article.cat_arr_id',
  2534. 'article.catid as category_id'
  2535. )
  2536. ->orderBy('updated_at', 'desc')
  2537. ->limit($article_textnum)
  2538. ->get()->all();
  2539. foreach ($text_article as $k => $v) {
  2540. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2541. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2542. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2543. }
  2544. } else {
  2545. $text_article = [];
  2546. }
  2547. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2548. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2549. $parent[$key] = $catiall[$parent_category];
  2550. } else {
  2551. $parent[$key] = [];
  2552. }
  2553. }
  2554. }
  2555. return Result::success($parent);
  2556. }
  2557. // 封装处理商品的路由问题
  2558. function processGoods($goods, $data)
  2559. {
  2560. return $goods->map(function ($good) use ($data) {
  2561. $catid = $good->catid ?? 0;
  2562. // $pinyin = '';
  2563. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2564. if (!empty($category->pid) && $category->pid != 0) {
  2565. $level = json_decode($category->category_arr_id, true);
  2566. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2567. ->whereIn('category_id', $level)
  2568. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2569. ->get(['aLIas_pinyin'])
  2570. ->pluck('aLIas_pinyin')
  2571. ->implode('/');
  2572. } else {
  2573. $pinyin = $category->aLIas_pinyin ?? '';
  2574. }
  2575. if (isset($good->city_id) && !empty($good->city_id)) {
  2576. $city = District::where('id', $good->city_id)->first(['name']);
  2577. $good->city_name = $city->name ?? '';
  2578. }
  2579. // 解析imgurl JSON并取第一条数据
  2580. $imgUrls = json_decode($good->imgurl, true);
  2581. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2582. $good->pinyin = $pinyin;
  2583. return $good;
  2584. });
  2585. }
  2586. /**
  2587. * 获取商城首页-根据栏目id
  2588. * @param array $data
  2589. * @return array
  2590. * */
  2591. function getWebsiteCatidshop(array $data): array
  2592. {
  2593. $input['catid'] = $data['catid'];
  2594. $input['website_id'] = $data['website_id'];
  2595. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2596. $result = array_map(function ($item) use ($input) {
  2597. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2598. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2599. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2600. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2601. if (empty($category) || $category->type != 2) {
  2602. return Result::error("暂无此栏目", 0);
  2603. } else {
  2604. $website['website_id'] = $input['website_id'];
  2605. $goods = Good::where('good.status', 2)
  2606. ->where('good.website_id', $website['website_id'])
  2607. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2608. ->select(
  2609. 'good.id',
  2610. 'good.name',
  2611. 'good.imgurl',
  2612. 'good.description',
  2613. 'good.updated_at',
  2614. 'good.catid',
  2615. 'good.type_id',
  2616. 'good.price',
  2617. 'good.com',
  2618. 'good.level',
  2619. 'good.unit'
  2620. )
  2621. ->orderBy('updated_at', 'desc')
  2622. ->offset($goodStart)
  2623. ->limit($goodNum);
  2624. $all_goods = $goods->get();
  2625. $all_goods = $this->processGoods($all_goods, $website);
  2626. }
  2627. return $all_goods ?? [];
  2628. }
  2629. }, $data);
  2630. return Result::success($result);
  2631. }
  2632. /**
  2633. * 获取商品模块
  2634. * @param array $data
  2635. * @return array
  2636. * */
  2637. public function getWebsiteshop(array $data): array
  2638. {
  2639. $input['id'] = $data['id'];
  2640. $input['website_id'] = $data['website_id'];
  2641. $catid = $data['catid'];
  2642. $data = json_decode($input['id'] ?? '', true) ?? [];
  2643. $result['goods'] = array_map(function ($item) use ($input) {
  2644. // 检查parent元素是否存在且不是undefined
  2645. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2646. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2647. $website = $input['website_id'];
  2648. $query = Good::where('good.status', 2)
  2649. ->where('good.website_id', $website);
  2650. switch ($Levelid) {
  2651. case 1:
  2652. case 2:
  2653. case 3:
  2654. $goods = $query->where(function ($q) use ($Levelid) {
  2655. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2656. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2657. });
  2658. break;
  2659. case 4:
  2660. $goods = $query;
  2661. break;
  2662. case 5:
  2663. $goods = $query->where('type_id', 1);
  2664. break;
  2665. case 6:
  2666. $goods = $query->where('type_id', 2);
  2667. break;
  2668. default:
  2669. return [];
  2670. }
  2671. $all_goods = $goods
  2672. ->select(
  2673. 'good.id',
  2674. 'good.name',
  2675. 'good.imgurl',
  2676. 'good.description',
  2677. 'good.updated_at',
  2678. 'good.catid',
  2679. 'good.type_id',
  2680. 'good.price',
  2681. 'good.level',
  2682. 'good.website_id'
  2683. )
  2684. ->orderBy('updated_at', 'desc')
  2685. ->offset($goodStart)
  2686. ->limit($goodNum)
  2687. ->get();
  2688. $web['website_id'] = $website;
  2689. $all_goods = $this->processGoods($all_goods, $web);
  2690. }
  2691. return $all_goods;
  2692. }, $data);
  2693. $website = $input['website_id'];
  2694. $result['article'] = Article::where(function ($query) use ($website) {
  2695. $query->where(function ($subQuery) use ($website) {
  2696. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2697. })->orWhereNull("ignore_ids");
  2698. })
  2699. ->where('catid', $catid)
  2700. ->where('article.status', 1)
  2701. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2702. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2703. ->orderBy('article.updated_at', 'desc')
  2704. ->first();
  2705. return Result::success($result);
  2706. }
  2707. /**
  2708. * 获取商品分类
  2709. * @param array $data
  2710. * @return array
  2711. * */
  2712. public function getWebsiteshopCat(array $data): array
  2713. {
  2714. $website = $data['website_id'];
  2715. $category = WebsiteCategory::where('website_id', $website)
  2716. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2717. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2718. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2719. ->orderBy('sort')
  2720. ->get();
  2721. $cat = $category->map(function ($item) use ($website) {
  2722. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2723. $pid = $item->pid ?? 0;
  2724. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2725. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2726. ->where('website_id', $website)
  2727. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2728. ->get(['aLIas_pinyin'])
  2729. ->pluck('aLIas_pinyin')
  2730. ->implode('/');
  2731. } else {
  2732. $pinyin = $item->aLIas_pinyin ?? '';
  2733. }
  2734. $item->pinyin = $pinyin;
  2735. });
  2736. if (empty($category)) {
  2737. return Result::error("栏目查询失败", 0);
  2738. }
  2739. $cat_tree = Result::buildMenuTree($category);
  2740. $web['website_id'] = $website;
  2741. $goods = Good::where('website_id', $website)
  2742. ->where('status', 2)
  2743. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2744. ->latest('updated_at')
  2745. ->offset(($data['page'] - 1) * $data['pageSize'])
  2746. ->limit($data['pageSize'])
  2747. ->get();
  2748. if (!empty($goods)) {
  2749. if ($goods->count() > 1 && !empty($goods)) {
  2750. $goods = $this->processGoods($goods, $web);
  2751. }
  2752. } else {
  2753. $goods = [];
  2754. }
  2755. $result = [
  2756. 'category' => $cat_tree,
  2757. 'goods' => $goods,
  2758. ];
  2759. // $resul['goods'] = $goods;
  2760. if (empty($result)) {
  2761. return Result::error("查询失败", 0);
  2762. }
  2763. return Result::success($result);
  2764. }
  2765. /*
  2766. * 获取商品列表
  2767. * @param array $data
  2768. * @return array
  2769. * */
  2770. public function getWebsiteshopList(array $data): array
  2771. {
  2772. // return Result::success($data);
  2773. $where = [
  2774. 'status' => 2,
  2775. 'website_id' => $data['website_id'],
  2776. ];
  2777. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2778. // return Result::error("查询失败", 0);
  2779. // }
  2780. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2781. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2782. $data['catid'] = $category->category_id ?? 0;
  2783. }
  2784. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2785. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2786. }
  2787. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2788. array_push($where, ['type_id', $data['type_id']]);
  2789. }
  2790. $query = Good::where($where)
  2791. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2792. $query->where(function ($q) use ($data) {
  2793. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2794. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2795. });
  2796. })
  2797. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2798. $query->where(function ($q) use ($data) {
  2799. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2800. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2801. });
  2802. })
  2803. ->select(
  2804. 'good.id',
  2805. 'good.name',
  2806. 'good.imgurl',
  2807. 'good.description',
  2808. 'good.updated_at',
  2809. 'good.com',
  2810. 'good.catid',
  2811. 'good.type_id',
  2812. 'good.website_id',
  2813. 'good.cat_arr_id',
  2814. 'good.created_at',
  2815. 'good.city_id'
  2816. )
  2817. ->latest('updated_at');
  2818. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2819. $result['count'] = $query->clone()->count();
  2820. $result['goods'] = $this->processGoods(
  2821. $query->clone()
  2822. ->offset(($data['page'] - 1) * $data['pageSize'])
  2823. ->limit($data['pageSize'])
  2824. ->get(),
  2825. $data
  2826. );
  2827. } else {
  2828. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2829. // 获取 type_id 为 1 的数据
  2830. $result['type1'] = $this->processGoods(
  2831. $query->clone()
  2832. ->where('type_id', 1)
  2833. ->offset(($data['page'] - 1) * $data['pageSize'])
  2834. ->limit($data['pageSize'])
  2835. ->get(),
  2836. $data
  2837. );
  2838. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2839. // 获取 type_id 为 2 的数据
  2840. $result['type2'] = $this->processGoods(
  2841. $query->clone()
  2842. ->where('type_id', 2)
  2843. ->offset(($data['page'] - 1) * $data['pageSize'])
  2844. ->limit($data['pageSize'])
  2845. ->get(),
  2846. $data
  2847. );
  2848. }
  2849. if (empty($result)) {
  2850. return Result::error("查询失败", 0);
  2851. }
  2852. return Result::success($result);
  2853. }
  2854. /**
  2855. * 获取商品详情
  2856. * @param array $data
  2857. * @return array
  2858. * */
  2859. public function getWebsiteshopInfo(array $data): array
  2860. {
  2861. $where = [
  2862. 'good.status' => 2,
  2863. 'good.website_id' => $data['website_id'],
  2864. 'good.id' => $data['id'],
  2865. ];
  2866. $goods = Good::where($where)
  2867. ->where('good.id', $data['id'])
  2868. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2869. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2870. ->first();
  2871. if (empty($goods)) {
  2872. return Result::error("查询失败", 0);
  2873. }
  2874. $goods->imgurl = json_decode($goods->imgurl, true);
  2875. return Result::success($goods);
  2876. }
  2877. /**
  2878. * plus pro 处理文章路由问题
  2879. */
  2880. function processArticlePro($website_id)
  2881. {
  2882. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2883. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2884. // // 取出category_id 对应的aLIas_pinyin
  2885. // $categoryIds = array_column($categorys, 'category_id');
  2886. // $categoryPIds = array_column($categorys, 'pid');
  2887. // $aliasPinyins = array_column($categorys, 'path');
  2888. // $alias = array_column($categorys, 'alias');
  2889. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2890. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2891. // // return Result::success($cat_arr);
  2892. // // $catiall = [];
  2893. // //一级所有子级的记录
  2894. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2895. // return [
  2896. // 'cat_1st_arr' => $cat_alias_arr,
  2897. // 'catiall' => $cat_arr,
  2898. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2899. // 'categoryIds' => $categoryIds,
  2900. // ];
  2901. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2902. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2903. // 取出category_id 对应的aLIas_pinyin
  2904. $categoryIds = array_column($categorys, 'category_id');
  2905. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
  2906. return $pid != 0;
  2907. })));
  2908. $category_path = array_column($categorys, 'path');
  2909. $cat_arr = array_combine($categoryIds, $category_path);
  2910. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2911. $catiall = [];
  2912. //一级所有子级的记录
  2913. $cat_1st_arr = [];
  2914. foreach ($categorys as $key => $value) {
  2915. // $category_arr_id = json_decode($value->category_arr_id);
  2916. // $pinyin_str = '';
  2917. // // 算出一级 并且算出子级
  2918. if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
  2919. $cat_1st_arr[$value->pid][] = $value->category_id;
  2920. }
  2921. // foreach ($category_arr_id as $k => $v) {
  2922. // $pinyin_str .= $cat_arr[$v] . '/';
  2923. // }
  2924. // $pinyin_str = rtrim($pinyin_str, '/');
  2925. $catiall[$value->category_id]['alias'] = $value->alias;
  2926. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2927. $catiall[$value->category_id]['type'] = $value->type;
  2928. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2929. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2930. }
  2931. return [
  2932. 'cat_1st_arr' => $cat_1st_arr,
  2933. 'catiall' => $catiall,
  2934. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2935. 'categoryIds' => $categoryIds,
  2936. 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
  2937. 'categoryPIds' => $categoryPIds,
  2938. ];
  2939. }
  2940. /**
  2941. * 封装处理文章的路由问题
  2942. * */
  2943. function processArticles($articles, $data)
  2944. {
  2945. // 检查 $articles 是否为数组或可迭代对象
  2946. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2947. return $articles->map(function ($article) use ($data) {
  2948. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2949. $catid = $article->cat_arr_id ?? '';
  2950. }
  2951. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2952. $catid = $article->category_arr_id ?? '';
  2953. }
  2954. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2955. $level = json_decode($catid, true);
  2956. if (!is_array($level)) {
  2957. return $article;
  2958. } else {
  2959. $level = array_map('intval', $level);
  2960. }
  2961. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2962. ->where($data)
  2963. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2964. ->pluck('aLIas_pinyin')
  2965. ->implode('/');
  2966. $article->pinyin = $pinyin ?? '';
  2967. return $article;
  2968. });
  2969. } else {
  2970. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2971. $catid = $articles->cat_arr_id ?? '';
  2972. $level = json_decode($catid, true);
  2973. if (!is_array($level)) {
  2974. return $articles;
  2975. } else {
  2976. $level = array_map('intval', $level);
  2977. }
  2978. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2979. ->where($data)
  2980. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2981. ->pluck('aLIas_pinyin')
  2982. ->implode('/');
  2983. $articles->pinyin = $pinyin ?? '';
  2984. return $articles;
  2985. }
  2986. }
  2987. // 封装处理由问题
  2988. function processJob($job, $data)
  2989. {
  2990. return $job->map(function ($job) use ($data) {
  2991. $category = $job->cat_arr_id ?? '';
  2992. $cityid = $job->city_arr_id ?? '';
  2993. $city = json_decode($cityid, true);
  2994. $pinyin = '';
  2995. $level = json_decode($category, true);
  2996. // 路由
  2997. if (!empty($level) && is_array($level)) {
  2998. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2999. ->where('website_id', $data['website_id']) // 添加网站ID条件
  3000. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3001. ->get(['aLIas_pinyin'])
  3002. ->pluck('aLIas_pinyin')
  3003. ->implode('/');
  3004. if (empty($pinyin)) {
  3005. $pinyin = $pinyin->aLIas_pinyin ?? '';
  3006. }
  3007. $job->pinyin = $pinyin;
  3008. }
  3009. // 取职位-城市 市??省
  3010. if (!empty($city) && is_array($city)) {
  3011. if (isset($city[1]) && !empty($city[1])) {
  3012. $city = District::where('id', $city[1])->first(['name']);
  3013. $job->city_name = $city->name ?? '';
  3014. } else if (isset($city[0]) && !empty($city[0])) {
  3015. $city = District::where('id', $city[0])->first(['name']);
  3016. $job->city_name = $city->name ?? '';
  3017. } else {
  3018. $job->city_name = '全国';
  3019. }
  3020. }
  3021. // 获取简历最后一级地区
  3022. if (isset($job->city_id) && !empty($job->city_id)) {
  3023. $city = District::where('id', $job->city_id)->first(['name']);
  3024. $job->hunt_cityname = $city->name ?? '';
  3025. }
  3026. // 组合详细地址
  3027. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  3028. $address_id = json_decode($job->address_arr_id, true) ?? [];
  3029. if (is_array($address_id) && !empty($address_id)) {
  3030. $address = District::whereIn('id', $address_id)
  3031. ->orderBy('level', 'asc')
  3032. ->get(['name'])
  3033. ->pluck('name')
  3034. ->implode('');
  3035. // $job->address_name = $address ?? '';
  3036. $job->address_name = ($address ?? '') . ($job->address ?? '');
  3037. }
  3038. }
  3039. // 取行业
  3040. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  3041. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  3042. if (!empty($job->industry)) {
  3043. $query->where('hyid', $job->industry);
  3044. } else if (!empty($job->hy_id)) {
  3045. $query->where('hyid', $job->hy_id);
  3046. } else if (!empty($job->company_hy_id)) {
  3047. $query->where('hyid', $job->company_hy_id);
  3048. } else {
  3049. $query->where('hyid', $job->job_industry);
  3050. }
  3051. })->first(['hyname']);
  3052. $job->hy_name = $hy_name->hyname ?? '';
  3053. }
  3054. // 取职位类别
  3055. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  3056. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  3057. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  3058. $job->zw_name = $zw_name->zwname ?? '';
  3059. }
  3060. // 取具体职位
  3061. 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))) {
  3062. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  3063. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  3064. $job->jtzw_name = $jtzw_name->zwname ?? '';
  3065. }
  3066. // 取工作经验
  3067. if (isset($job->experience) && !empty($job->experience)) {
  3068. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  3069. $job->experience_name = $experience->ename ?? '';
  3070. }
  3071. // 取学历
  3072. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  3073. $education = $job->educational ?? $job->school_education;
  3074. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  3075. $job->education_name = $education->ename ?? '';
  3076. }
  3077. // 语言
  3078. if (isset($job->language) && !empty($job->language)) {
  3079. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  3080. $job->language_name = $language->ename ?? '';
  3081. }
  3082. // 薪资
  3083. if (isset($job->salary) && !empty($job->salary)) {
  3084. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  3085. $job->salary_name = $salary->ename ?? '';
  3086. }
  3087. // 职位性质
  3088. if (isset($job->nature_id) && !empty($job->nature_id)) {
  3089. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  3090. $job->job_nature_name = $job_nature->ename ?? '';
  3091. }
  3092. // 公司规模
  3093. if (isset($job->company_size) && !empty($job->company_size)) {
  3094. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  3095. $job->company_size_name = $company_size->ename ?? '';
  3096. }
  3097. // 公司性质
  3098. if (isset($job->company_nature) && !empty($job->company_nature)) {
  3099. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  3100. $job->company_nature_name = $company_nature->nature_name ?? '';
  3101. }
  3102. // $job->pinyin = $pinyin;
  3103. return $job;
  3104. });
  3105. }
  3106. /**
  3107. * 获取书籍模块
  3108. * @param array $data
  3109. * @return array
  3110. * */
  3111. public function getWebsiteBook(array $data): array
  3112. {
  3113. $input['id'] = $data['id'];
  3114. $input['website_id'] = $data['website_id'];
  3115. // 将 JSON 字符串转换为 PHP 数组
  3116. $data = json_decode($input['id'], true);
  3117. // 使用 array_map 处理每个元素
  3118. $result = array_map(function ($item) use ($input) {
  3119. // 检查parent元素是否存在且不是undefined
  3120. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  3121. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3122. $website = [
  3123. 'website_id' => $input['website_id'],
  3124. ];
  3125. // 查询栏目名称
  3126. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3127. if (empty($category)) {
  3128. $parent_alias = '';
  3129. $parent_pinyin = null;
  3130. $imgBooks = [];
  3131. $textBooks = [];
  3132. } else {
  3133. $parent_alias = $category->alias ?? '';
  3134. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  3135. // 查找子分类ID数组
  3136. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  3137. array_push($childCategoryIds, $parentCatId);
  3138. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  3139. if ($parentImgNum != 0) {
  3140. // 查询图片新闻
  3141. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  3142. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3143. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3144. })
  3145. ->where('book.status', 2)
  3146. ->where('book.img_url', '!=', '')
  3147. ->where('book.website_id', $website['website_id'])
  3148. ->leftJoin('website_category', function ($join) use ($website) {
  3149. $join->on('book.cat_id', '=', 'website_category.category_id')
  3150. ->where('website_category.website_id', '=', $website['website_id']);
  3151. })
  3152. ->select(
  3153. 'book.id',
  3154. 'book.title',
  3155. 'book.img_url',
  3156. 'book.price',
  3157. 'book.market_price',
  3158. 'book.description',
  3159. 'book.cat_id',
  3160. 'book.description',
  3161. 'book.updated_at',
  3162. 'website_category.alias as category_name',
  3163. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3164. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3165. )
  3166. ->orderBy('updated_at', 'desc')
  3167. ->limit($parentImgNum)
  3168. ->get()->all();
  3169. // 查询文字新闻
  3170. }
  3171. if ($parentTextNum != 0) {
  3172. $textBooks = [];
  3173. $textBooks = Book::where(function ($query) use ($parentCatId) {
  3174. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3175. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3176. })
  3177. ->where('book.status', 2)
  3178. ->where('book.website_id', $website['website_id'])
  3179. ->leftJoin('website_category', function ($join) use ($website) {
  3180. $join->on('book.cat_id', '=', 'website_category.category_id')
  3181. ->where('website_category.website_id', '=', $website['website_id']);
  3182. })
  3183. ->select(
  3184. 'book.id',
  3185. 'book.title',
  3186. 'book.img_url',
  3187. 'book.price',
  3188. 'book.market_price',
  3189. 'book.description',
  3190. 'book.cat_id',
  3191. 'book.description',
  3192. 'book.updated_at',
  3193. 'website_category.alias as category_name',
  3194. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3195. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3196. )
  3197. ->orderBy('updated_at', 'desc')
  3198. ->limit($parentTextNum)
  3199. ->get()->all();
  3200. }
  3201. }
  3202. }
  3203. $resultItem = [
  3204. 'alias' => $parent_alias ?? '',
  3205. 'category_id' => $parentCatId ?? 0,
  3206. 'pinyin' => $parent_pinyin ?? null,
  3207. 'imgnum' => $imgBooks ?? [],
  3208. 'textnum' => $textBooks ?? [],
  3209. ];
  3210. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  3211. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  3212. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  3213. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3214. ->get()->all();
  3215. if (!empty($childCategory)) {
  3216. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  3217. // 查询子栏目名称
  3218. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  3219. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3220. ->first();
  3221. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  3222. $childImgArticles = [];
  3223. $childTextArticles = [];
  3224. $resultItem['child'] = [];
  3225. } else {
  3226. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  3227. // 查询子栏目图片新闻
  3228. $childImgArticles = Book::where('cat_id', $childCatId)
  3229. ->where('status', 2)
  3230. ->where('img_url', '!=', '')
  3231. ->where('book.website_id', $website['website_id'])
  3232. ->leftJoin('website_category', function ($join) use ($website) {
  3233. $join->on('book.cat_id', '=', 'website_category.category_id')
  3234. ->where('website_category.website_id', '=', $website['website_id']);
  3235. })
  3236. ->select(
  3237. 'book.id',
  3238. 'book.title',
  3239. 'book.img_url',
  3240. 'book.price',
  3241. 'book.market_price',
  3242. 'book.description',
  3243. 'book.cat_id',
  3244. 'book.description',
  3245. 'book.updated_at',
  3246. DB::raw("'$child_pinyin' as pinyin")
  3247. )
  3248. ->orderBy('updated_at', 'desc')
  3249. ->limit($childImgNum)
  3250. ->get()->all();
  3251. // 查询子栏目文字新闻
  3252. $childTextArticles = Book::where('cat_id', $childCatId)
  3253. ->where('status', 2)
  3254. ->where('book.website_id', $website['website_id'])
  3255. ->leftJoin('website_category', function ($join) use ($website) {
  3256. $join->on('book.cat_id', '=', 'website_category.category_id')
  3257. ->where('website_category.website_id', '=', $website['website_id']);
  3258. })
  3259. ->select(
  3260. 'book.id',
  3261. 'book.title',
  3262. 'book.img_url',
  3263. 'book.price',
  3264. 'book.market_price',
  3265. 'book.description',
  3266. 'book.cat_id',
  3267. 'book.description',
  3268. 'book.updated_at',
  3269. DB::raw("'$child_pinyin' as pinyin")
  3270. )
  3271. ->orderBy('updated_at', 'desc')
  3272. ->limit($childTextNum)
  3273. ->get()->all();
  3274. $resultItem['child'] = [
  3275. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  3276. 'category_id' => $childCatId,
  3277. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  3278. 'all_childcat' => $childCategory,
  3279. 'imgnum' => $childImgArticles,
  3280. 'textnum' => $childTextArticles,
  3281. ];
  3282. }
  3283. }
  3284. } else {
  3285. $resultItem['child'] = [];
  3286. }
  3287. return $resultItem;
  3288. }, $data);
  3289. return Result::success($result);
  3290. }
  3291. /**
  3292. * 获取书刊列表
  3293. * @param array $data
  3294. * @return array
  3295. * */
  3296. public function getWebsiteBookList(array $data): array
  3297. {
  3298. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3299. if (empty($web)) {
  3300. return Result::error("查询失败", 0);
  3301. }
  3302. $catid = $data['id'];
  3303. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  3304. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  3305. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  3306. $category_pinyin = $category ? $category->aLias_pinyin : '';
  3307. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  3308. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  3309. ->where('pid', $category['pid'])
  3310. ->select(
  3311. 'category_id',
  3312. 'alias',
  3313. 'aLIas_pinyin',
  3314. 'pid',
  3315. 'sort',
  3316. 'is_url',
  3317. 'web_url',
  3318. 'seo_title',
  3319. 'seo_keywords',
  3320. 'seo_description',
  3321. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  3322. )
  3323. ->orderBy('sort')
  3324. ->get()->all();
  3325. if (empty($category)) {
  3326. return Result::error("查询失败", 0);
  3327. }
  3328. $query = Book::where('book.status', 2)
  3329. ->where('book.website_id', $data['website_id'])
  3330. ->where('book.cat_id', $catid)
  3331. ->select(
  3332. 'book.id',
  3333. 'book.title',
  3334. 'book.img_url',
  3335. 'book.description',
  3336. 'book.updated_at',
  3337. 'book.cat_id',
  3338. DB::raw("'$pinyin' as pinyin")
  3339. )
  3340. ->orderBy('book.updated_at', 'desc');
  3341. $count = $query->count();
  3342. $query = clone $query;
  3343. $Book = $query
  3344. ->limit($data['pageSize'])
  3345. ->offset(($data['page'] - 1) * $data['pageSize'])
  3346. ->get()->all();
  3347. $result = [
  3348. 'category' => $categorys,
  3349. 'books' => $Book,
  3350. 'count' => $count,
  3351. ];
  3352. // if(empty($result)){
  3353. // return Result::error("查询失败", 0);
  3354. // }
  3355. return Result::success($result);
  3356. }
  3357. /**
  3358. * 获取书刊详情
  3359. * @param array $data
  3360. * @return array
  3361. * */
  3362. public function getWebsiteBookInfo(array $data): array
  3363. {
  3364. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3365. if (empty($web)) {
  3366. return Result::error("查询失败", 0);
  3367. }
  3368. $book = Book::where('status', 2)
  3369. ->where('website_id', $data['website_id'])
  3370. ->where('id', $data['id'])
  3371. ->select(
  3372. 'book.*',
  3373. )
  3374. ->orderBy('updated_at', 'desc')
  3375. ->first();
  3376. if (empty($book)) {
  3377. return Result::error("查询失败", 0);
  3378. }
  3379. // 先查询当前分类的 pid
  3380. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  3381. ->where('category_id', $book['cat_id'])
  3382. ->first(['pid', 'category_id']);
  3383. $query = WebsiteCategory::where('website_id', $data['website_id']);
  3384. if (!empty($carpid)) {
  3385. if ($carpid->pid != 0) {
  3386. $pid = $carpid['pid'];
  3387. // $parent_pinyin = '';
  3388. } else {
  3389. $pid = $carpid['category_id'];
  3390. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  3391. }
  3392. }
  3393. $categorys = $query->where('pid', $pid)
  3394. ->select(
  3395. 'category_id',
  3396. 'alias',
  3397. 'aLIas_pinyin',
  3398. 'pid',
  3399. 'sort',
  3400. 'is_url',
  3401. 'web_url',
  3402. 'category_arr_id as cat_arr_id',
  3403. )
  3404. ->orderBy('sort')
  3405. ->get();
  3406. $category = $this->processArticle($categorys, $data);
  3407. $result = [
  3408. 'category' => $category,
  3409. 'books' => $book,
  3410. ];
  3411. return Result::success($result);
  3412. }
  3413. /**
  3414. * 尝试
  3415. * @param array $data
  3416. * @return array
  3417. * */
  3418. public function test(array $data): array
  3419. {
  3420. $input['id'] = $data['id'];
  3421. $input['website_id'] = $data['website_id'];
  3422. // 将 JSON 字符串转换为 PHP 数组
  3423. $data = json_decode($input['id'], true);
  3424. $result = [];
  3425. $article = $data;
  3426. $result = array_map(function ($item) use ($input) {
  3427. $website = [
  3428. 'website_id' => $input['website_id'],
  3429. ];
  3430. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3431. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3432. $parent = [
  3433. 0 => $category['category_id'] ?? [],
  3434. 1 => $parentImgNum ?? [],
  3435. 2 => $parentTextNum ?? [],
  3436. ];
  3437. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  3438. $child = [];
  3439. $resultItem = [
  3440. // 'alias' => $parent_alias ?? '',
  3441. 'category_id' => $parentCatId ?? 0,
  3442. 'pinyin' => $parentImgNum ?? null,
  3443. 'imgnum' => $parentTextNum ?? [],
  3444. // 'textnum' => $textArticles ?? [],
  3445. ];
  3446. return $parent;
  3447. }, $data);
  3448. return Result::success($result);
  3449. // });
  3450. }
  3451. /**
  3452. * 封装处理文章的路由问题
  3453. * */
  3454. function processArticle($article, $data)
  3455. {
  3456. return $article->map(function ($article) use ($data) {
  3457. $catid = $article->cat_arr_id ?? '';
  3458. $level = json_decode($catid, true);
  3459. $pinyin = '';
  3460. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  3461. if (!empty($level) && is_array($level)) {
  3462. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  3463. ->where('website_id', $data['website_id'])
  3464. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3465. ->get(['aLIas_pinyin'])
  3466. ->pluck('aLIas_pinyin')
  3467. ->implode('/');
  3468. } else {
  3469. $pinyin = '';
  3470. }
  3471. $article->pinyin = $pinyin;
  3472. return $article;
  3473. });
  3474. }
  3475. /**
  3476. * c端-获取招工招聘下拉选框
  3477. * @param array $data
  3478. * @return array
  3479. * */
  3480. public function getWebsiteJobSelect(array $data): array
  3481. {
  3482. $web = Website::where('id', $data['website_id'])->first();
  3483. if (empty($web)) {
  3484. return Result::error("该网站不存在", 0);
  3485. }
  3486. $hy = JobIndustry::get()->all();
  3487. $zw = JobPosition::where('zwpid', 0)->get()->all();
  3488. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  3489. $result = [
  3490. 'hy' => $hy,
  3491. 'zw' => $zw,
  3492. 'jtzw' => $jtzw,
  3493. ];
  3494. if (empty($result)) {
  3495. return Result::error("查询失败", 0);
  3496. }
  3497. return Result::success($result);
  3498. }
  3499. /**
  3500. * c端-获取招工招聘
  3501. * @param array $data
  3502. * @return array
  3503. * */
  3504. public function getWebsiteJob(array $data): array
  3505. {
  3506. $web = Website::where('id', $data['website_id'])->first();
  3507. if (empty($web)) {
  3508. return Result::error("该网站不存在", 0);
  3509. }
  3510. $job_hunting = JobHunting::where('job_hunting.status', 2)
  3511. ->where('job_hunting.website_id', $data['website_id'])
  3512. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3513. $query->where(function ($q) use ($data) {
  3514. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3515. });
  3516. })
  3517. ->select(
  3518. 'job_hunting.id',
  3519. 'job_hunting.catid',
  3520. 'job_hunting.cat_arr_id',
  3521. 'job_hunting.job_name_get',
  3522. 'job_hunting.industry',
  3523. 'job_hunting.name',
  3524. 'job_hunting.sexy',
  3525. 'job_hunting.origin',
  3526. 'job_hunting.city_arr_id',
  3527. 'job_hunting.experience',
  3528. 'job_hunting.updated_at',
  3529. 'job_hunting.salary',
  3530. 'job_hunting.skillList',
  3531. 'job_hunting.slelf_evaluation',
  3532. )
  3533. ->orderBy('updated_at', 'desc')
  3534. ->limit($data['job1_num'])
  3535. ->get();
  3536. $web['website_id'] = $data['website_id'];
  3537. if (empty($job_hunting)) {
  3538. $job_huntings = "未查询到相关简历信息";
  3539. } else {
  3540. $job_huntings = $this->processJob($job_hunting, $web);
  3541. }
  3542. // 0:待审核 1:已通过 2:已拒绝
  3543. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3544. ->where('job_recruiting.website_id', $data['website_id'])
  3545. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3546. $query->where(function ($q) use ($data) {
  3547. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3548. });
  3549. })
  3550. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3551. ->select(
  3552. 'job_recruiting.id',
  3553. 'job_recruiting.catid',
  3554. 'job_recruiting.cat_arr_id',
  3555. 'job_recruiting.title',
  3556. 'job_recruiting.jtzw_id',
  3557. 'job_recruiting.hy_id',
  3558. 'job_recruiting.city_arr_id',
  3559. 'job_recruiting.due_data',
  3560. 'job_recruiting.updated_at',
  3561. 'job_recruiting.experience',
  3562. 'job_recruiting.educational',
  3563. 'job_recruiting.salary',
  3564. 'job_recruiting.zw_id',
  3565. 'job_company.business_name',
  3566. 'job_recruiting.keyword',
  3567. 'job_recruiting.description',
  3568. )
  3569. ->orderBy('updated_at', 'desc')
  3570. ->limit($data['job2_num'])
  3571. ->get();
  3572. if (empty($job_recruiting->toArray())) {
  3573. $job_recruitings = "未查询到相关职位信息";
  3574. } else {
  3575. $job_recruitings = $this->processJob($job_recruiting, $web);
  3576. }
  3577. $result = [
  3578. 'job_hunting' => $job_huntings,
  3579. 'job_recuiting' => $job_recruitings,
  3580. ];
  3581. return Result::success($result);
  3582. }
  3583. /**
  3584. * c端-获取招工招聘列表
  3585. * @param array $data
  3586. * @return array
  3587. * */
  3588. public function getWebsiteJobList(array $data): array
  3589. {
  3590. $recruit_where = [];
  3591. $hunt_where = [];
  3592. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3593. if (empty($web)) {
  3594. return Result::error("此网站不存在", 0);
  3595. }
  3596. $website_id['website_id'] = $data['website_id'];
  3597. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3598. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3599. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3600. }
  3601. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3602. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3603. }
  3604. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3605. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3606. }
  3607. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3608. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3609. }
  3610. $query = JobRecruiting::where('job_recruiting.status', 1)
  3611. ->where('job_recruiting.website_id', $data['website_id'])
  3612. ->where($recruit_where)
  3613. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3614. $query->where(function ($q) use ($data) {
  3615. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3616. });
  3617. })
  3618. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3619. $query->where(function ($q) use ($data) {
  3620. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3621. });
  3622. })
  3623. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3624. ->select(
  3625. 'job_recruiting.id',
  3626. 'job_recruiting.catid',
  3627. 'job_recruiting.hy_id',
  3628. 'job_recruiting.title',
  3629. 'job_recruiting.zw_id',
  3630. 'job_recruiting.educational',
  3631. 'job_recruiting.jtzw_id',
  3632. 'job_recruiting.city_arr_id',
  3633. 'job_recruiting.due_data',
  3634. 'job_recruiting.experience',
  3635. 'job_recruiting.cat_arr_id',
  3636. 'job_recruiting.updated_at',
  3637. 'job_company.business_name',
  3638. 'job_recruiting.keyword',
  3639. 'job_recruiting.description',
  3640. )
  3641. ->orderBy('job_recruiting.updated_at', 'desc');
  3642. $recruit_count = $query->count();
  3643. $query = clone $query;
  3644. $JobRecruiting = $query
  3645. ->offset(($data['page'] - 1) * $data['pageSize'])
  3646. ->limit($data['pageSize'])
  3647. ->get();
  3648. if (empty($JobRecruiting)) {
  3649. $JobRecruiting = "暂无相关职位信息";
  3650. } else {
  3651. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3652. }
  3653. }
  3654. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3655. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3656. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3657. }
  3658. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3659. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3660. }
  3661. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3662. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3663. }
  3664. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3665. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3666. }
  3667. $query = JobHunting::where('job_hunting.status', 2)
  3668. ->where('job_hunting.website_id', $data['website_id'])
  3669. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3670. ->where($hunt_where)
  3671. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3672. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3673. // })
  3674. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3675. $query->where(function ($q) use ($data) {
  3676. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3677. });
  3678. })
  3679. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3680. $query->where(function ($q) use ($data) {
  3681. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3682. });
  3683. })
  3684. ->select(
  3685. 'job_hunting.id',
  3686. 'job_hunting.catid',
  3687. 'job_hunting.sexy',
  3688. 'job_hunting.experience',
  3689. 'job_hunting.origin',
  3690. 'job_hunting.industry',
  3691. 'job_hunting.name',
  3692. 'job_hunting.job',
  3693. 'job_hunting.job_name_get',
  3694. 'job_hunting.city_arr_id',
  3695. 'job_hunting.cat_arr_id',
  3696. 'job_hunting.created_at',
  3697. 'job_hunting.updated_at',
  3698. 'job_position.zwname as job_name',
  3699. 'job_hunting.skillList',
  3700. 'job_hunting.slelf_evaluation',
  3701. )
  3702. ->orderBy('job_hunting.updated_at', 'desc');
  3703. $hunt_count = $query->count();
  3704. $query = clone $query;
  3705. $JobHunting = $query
  3706. ->offset(($data['page'] - 1) * $data['pageSize'])
  3707. ->limit($data['pageSize'])
  3708. ->get();
  3709. if (empty($JobHunting)) {
  3710. $JobRecruiting = "暂无相关简历信息";
  3711. } else {
  3712. $JobHunting = $this->processJob($JobHunting, $website_id);
  3713. }
  3714. }
  3715. $result = [
  3716. 'JobRecruiting' => $JobRecruiting ?? [],
  3717. 'recruit_count' => $recruit_count ?? 0,
  3718. 'JobHunting' => $JobHunting ?? [],
  3719. 'hunt_count' => $hunt_count ?? 0,
  3720. ];
  3721. return Result::success($result);
  3722. }
  3723. /**
  3724. * c端-获取招工招聘详情
  3725. * @param array $data
  3726. * @return array
  3727. * */
  3728. public function getWebsiteJobInfo(array $data): array
  3729. {
  3730. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3731. if (empty($web)) {
  3732. return Result::error("该网站不存在", 0);
  3733. }
  3734. $webid = [
  3735. 'website_id' => $data['website_id'],
  3736. ];
  3737. // 职位相关信息
  3738. if ($data['type'] == 1) {
  3739. $query = JobRecruiting::where('status', 1)
  3740. ->where('website_id', $data['website_id'])
  3741. ->select('*');
  3742. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3743. $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();
  3744. if (!empty($company)) {
  3745. $result['company'] = $this->processJob($company, $webid);
  3746. }
  3747. $other_job = JobRecruiting::where('status', 1)
  3748. ->where('website_id', $data['website_id'])
  3749. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3750. ->where('id', '!=', $data['id'])
  3751. ->where('user_id', '=', $job[0]['user_id'])
  3752. ->limit($data['pageSize'])
  3753. ->get();
  3754. if (!empty($other_job)) {
  3755. $result['other_job'] = $this->processJob($other_job, $webid);
  3756. }
  3757. } else {
  3758. // 简历相关信息
  3759. $job = JobHunting::where('job_hunting.status', 2)
  3760. ->where('job_hunting.website_id', $data['website_id'])
  3761. ->where('job_hunting.id', $data['id'])
  3762. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3763. ->select('job_hunting.*', 'user_name')
  3764. ->get();
  3765. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3766. if (!empty($resume->toArray())) {
  3767. $result['resume'] = 1;
  3768. } else {
  3769. $result['resume'] = 0;
  3770. }
  3771. }
  3772. if (empty($job->toArray())) {
  3773. return Result::error("id参数错误", 0);
  3774. }
  3775. if (!empty($job[0]['job_experience'])) {
  3776. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3777. if (!empty($job_experience)) {
  3778. // $hy = [];
  3779. foreach ($job_experience as $key => $value) {
  3780. // $id = $value['id'];
  3781. $hy[$key] = $value['job_industry'];
  3782. $zw_id[$key] = $value['job_typename'];
  3783. $jtzw_id[$key] = $value['job_name'];
  3784. }
  3785. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3786. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3787. // 先将关联表转换为索引数组,提高查找效率
  3788. $hyLookup = [];
  3789. foreach ($hy_table as $item) {
  3790. $hyLookup[$item['hyid']] = $item['hyname'];
  3791. }
  3792. $zwLookup = [];
  3793. foreach ($zw_table as $item) {
  3794. $zwLookup[$item['zwid']] = $item['zwname'];
  3795. }
  3796. foreach ($job_experience as $key => &$value) {
  3797. // 处理行业名称
  3798. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3799. $value['hy_name'] = $hyLookup[$hy[$key]];
  3800. }
  3801. // 处理职位名称
  3802. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3803. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3804. }
  3805. // 处理具体职位名称
  3806. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3807. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3808. }
  3809. }
  3810. // 释放引用,防止意外修改后续代码
  3811. unset($value);
  3812. }
  3813. $result['job_experience'] = $job_experience ?? [];
  3814. }
  3815. if (!empty($job[0]['education_experience'])) {
  3816. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3817. if (!empty($education_experience)) {
  3818. foreach ($education_experience as $key => $value) {
  3819. // $id = $value['id'];
  3820. $education[$key] = $value['school_education'];
  3821. }
  3822. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3823. // // 先将关联表转换为索引数组,提高查找效率
  3824. $educationLookup = [];
  3825. foreach ($education_table as $item) {
  3826. $educationLookup[$item['evalue']] = $item['ename'];
  3827. }
  3828. foreach ($education_experience as $key => &$value) {
  3829. // 处理学历名称
  3830. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3831. $value['education_name'] = $educationLookup[$education[$key]];
  3832. }
  3833. }
  3834. }
  3835. $result['education_experience'] = $job_experience ?? [];
  3836. }
  3837. $result['job'] = $this->processJob($job, $webid);
  3838. // // 返现对应的栏目
  3839. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3840. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3841. ->whereIn('category_id', $catid)
  3842. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3843. ->orderBy('pid')->get()->all();
  3844. if (!empty($category)) {
  3845. $result['category'] = $category;
  3846. }
  3847. $result['job'] = $job;
  3848. $result['job_experience'] = $job_experience ?? [];
  3849. $result['education_experience'] = $education_experience ?? [];
  3850. if (empty($result)) {
  3851. return Result::error("参数错误", 0);
  3852. }
  3853. return Result::success($result);
  3854. }
  3855. /**
  3856. * c端-申请职位
  3857. * @param array $data
  3858. * @return array
  3859. * */
  3860. public function getWebsiteJobApply(array $data): array
  3861. {
  3862. // 首先验证网站是否存在
  3863. // return Result::success($data);
  3864. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3865. if (empty($web)) {
  3866. return Result::error("该网站不存在", 0);
  3867. }
  3868. // 验证用户是否存在且为个人会员/管理员
  3869. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3870. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3871. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3872. return Result::error("用户不存在", 0);
  3873. }
  3874. // 去除重复元素和空元素,并保持原始顺序
  3875. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3876. return !empty($value);
  3877. }));
  3878. // 验证职位是否存在 1:审核通过
  3879. $recruiting = JobRecruiting::where('status', 1)
  3880. ->where('website_id', $data['website_id'])
  3881. ->whereIn('id', $data['recruit_id'])
  3882. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3883. if (empty($recruiting)) {
  3884. return Result::error("该职位不存在", 0);
  3885. }
  3886. // 简历是否存在
  3887. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3888. if (empty($hunt_id)) {
  3889. return Result::error("该简历不存在", 0);
  3890. }
  3891. $data['hunt_id'] = $hunt_id['hunt_id'];
  3892. // // 验证是否已投递过该职位
  3893. $apply = JobApply::where('user_id', $data['user_id'])
  3894. ->where('hunt_id', $data['hunt_id'])
  3895. ->where('website_id', $data['website_id'])
  3896. ->whereIn('recruit_id', $data['recruit_id'])
  3897. ->get(['recruit_id']);
  3898. if (!empty($apply->toArray())) {
  3899. return Result::error("您已投递过该职位!");
  3900. }
  3901. $insertData = array_map(function ($recruiting) use ($data) {
  3902. return [
  3903. 'user_id' => $data['user_id'],
  3904. 'hunt_id' => $data['hunt_id'],
  3905. 'website_id' => $data['website_id'],
  3906. 'recruit_id' => $recruiting['recruit_id'],
  3907. 'receiver_id' => $recruiting['receiver_id'],
  3908. 'status' => 1,
  3909. ];
  3910. }, $recruiting);
  3911. // 批量插入数据
  3912. $result = JobApply::insert($insertData);
  3913. if (empty($result)) {
  3914. return Result::error("投递失败", 0);
  3915. }
  3916. return Result::success($result);
  3917. }
  3918. /**
  3919. * 招工招聘-沟通简历
  3920. * @param array $data
  3921. * @return array
  3922. * */
  3923. public function getWebsiteJobResume(array $data): array
  3924. {
  3925. // 首先验证网站是否存在
  3926. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3927. if (empty($web)) {
  3928. return Result::error("该网站不存在", 0);
  3929. }
  3930. // return Result::success($data);
  3931. // 验证用户是否存在且为企业会员/管理员
  3932. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3933. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3934. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3935. return Result::error("用户不存在", 0);
  3936. }
  3937. // 去除重复元素和空元素,并保持原始顺序
  3938. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3939. return !empty($value);
  3940. }));
  3941. // 验证简历是否存在
  3942. $hunting = JobHunting::where('status', 2)
  3943. ->where('website_id', $data['website_id'])
  3944. ->whereIn('id', $data['hunt_id'])
  3945. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3946. if (empty($hunting)) {
  3947. return Result::error("该简历不存在", 0);
  3948. }
  3949. // 验证是否已沟通过该简历
  3950. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3951. ->where('recruit_id', $data['recruit_id'])
  3952. ->where('website_id', $data['website_id'])
  3953. ->whereIn('hunt_id', $data['hunt_id'])
  3954. ->get(['hunt_id']);
  3955. if (!empty($remuse->toArray())) {
  3956. return Result::error("您已沟通过该简历!");
  3957. }
  3958. // 准备要插入的数据数组
  3959. $insertData = array_map(function ($hunting) use ($data) {
  3960. return [
  3961. 'user_id' => $data['user_id'],
  3962. 'recruit_id' => $data['recruit_id'],
  3963. 'website_id' => $data['website_id'],
  3964. 'hunt_id' => $hunting['hunt_id'],
  3965. 'receiver_id' => $hunting['receiver_id'],
  3966. 'status' => 1,
  3967. ];
  3968. }, $hunting);
  3969. // 批量插入数据
  3970. $result = JobRemuse::insert($insertData);
  3971. if (empty($result)) {
  3972. return Result::error("沟通失败", 0);
  3973. }
  3974. return Result::success($result);
  3975. }
  3976. /**
  3977. * 招工招聘 -我的职位(企业会员)
  3978. * @param array $data
  3979. * @return array
  3980. */
  3981. public function getWebsiteJobRecruiting(array $data): array
  3982. {
  3983. $web = Website::where('id', $data['website_id'])->first('id');
  3984. if (empty($web)) {
  3985. return Result::error("该网站不存在", 0);
  3986. }
  3987. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3988. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3989. return Result::error("用户暂无权限!", 0);
  3990. }
  3991. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3992. $result = JobRecruiting::where('website_id', $data['website_id'])
  3993. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3994. $query->where('user_id', $user['id']);
  3995. })
  3996. ->where('status', 1)
  3997. ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
  3998. ->orderBy('updated_at', 'desc')
  3999. ->limit($data['pageSize'])
  4000. ->get();
  4001. if (empty($result)) {
  4002. return Result::error("暂无相关职位信息", 0);
  4003. }
  4004. return Result::success($result);
  4005. }
  4006. /**
  4007. * c端 - 验证路由
  4008. * @param array $data
  4009. * @return array
  4010. */
  4011. /**
  4012. * c端 - 验证路由
  4013. * @param array $data
  4014. * @return array
  4015. */
  4016. public function checkWebsiteRoute(array $data): array
  4017. {
  4018. // 测试001111111222
  4019. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  4020. if (empty($web)) {
  4021. return Result::error("该网站不存在", 0);
  4022. } elseif ($web['status'] != 1) {
  4023. return Result::error("网站已经关闭", 0);
  4024. }
  4025. if (isset($data['other_route']) && !empty($data['other_route'])) {
  4026. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  4027. // 验证路由是否存在
  4028. if (empty($whiteRouterInfo)) {
  4029. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  4030. }
  4031. if (!empty($whiteRouterInfo)) {
  4032. return Result::success($whiteRouterInfo->toArray());
  4033. }
  4034. }
  4035. // 验证栏目路由
  4036. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  4037. ->where('path', $data['all_route'])
  4038. ->get()->all();
  4039. if (count($last_category) == 0) {
  4040. return Result::error("该栏目不存在", 0);
  4041. }
  4042. if (count($last_category) > 1) {
  4043. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  4044. }
  4045. if (count($last_category) == 1) {
  4046. $last_category = $last_category[0];
  4047. }
  4048. // return Result::success($last_category);
  4049. if (isset($data['id']) && !empty($data['id'])) {
  4050. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  4051. switch ($last_category['type']) {
  4052. case 1:
  4053. // 文章
  4054. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  4055. $article = Article::where('status', 1)
  4056. ->where('id', $data['id'])
  4057. ->where(function ($query) use ($data) {
  4058. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  4059. ->orWhereNull("ignore_ids");
  4060. })
  4061. ->first(['catid']);
  4062. if (empty($article)) {
  4063. return Result::error("该文章不存在", 0);
  4064. }
  4065. // return Result::success($article);
  4066. break;
  4067. case 2:
  4068. // 商品
  4069. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4070. $article = Good::where('website_id', $data['website_id'])
  4071. ->where('status', 2)
  4072. ->where('id', $data['id'])
  4073. ->first(['cat_arr_id']);
  4074. if (empty($article)) {
  4075. return Result::error("该商品不存在", 0);
  4076. }
  4077. break;
  4078. case 3:
  4079. // 书刊信息
  4080. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4081. $article = Book::where('website_id', $data['website_id'])
  4082. ->where('status', 2)
  4083. ->where('id', $data['id'])
  4084. ->first(['id', 'cat_arr_id']);
  4085. if (empty($article)) {
  4086. return Result::error("该书刊不存在", 0);
  4087. }
  4088. break;
  4089. case 4:
  4090. // 招聘
  4091. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  4092. $article = JobRecruiting::where('website_id', $data['website_id'])
  4093. ->where('status', 1)
  4094. ->where('id', $data['id'])
  4095. ->first(['cat_arr_id']);
  4096. if (empty($article)) {
  4097. return Result::error("该招聘不存在", 0);
  4098. }
  4099. break;
  4100. case 5:
  4101. // 求职
  4102. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4103. $article = JobHunting::where('website_id', $data['website_id'])
  4104. ->where('status', 2)
  4105. ->where('id', $data['id'])
  4106. ->first(['cat_arr_id']);
  4107. if (empty($article)) {
  4108. return Result::error("该求职不存在", 0);
  4109. }
  4110. break;
  4111. case 6:
  4112. // 企业
  4113. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4114. $article = Company::
  4115. // where('website_id', $data['website_id'])
  4116. // ->
  4117. where('status', 1)
  4118. ->where('id', $data['id'])
  4119. ->first(['cat_arr_id']);
  4120. if (empty($article)) {
  4121. return Result::error("该企业不存在", 0);
  4122. }
  4123. break;
  4124. case 7:
  4125. // 项目
  4126. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4127. $article = Project::where('website_id', $data['website_id'])
  4128. ->where('status', 1)
  4129. ->where('id', $data['id'])
  4130. ->first(['cat_arr_id']);
  4131. if (empty($article)) {
  4132. return Result::error("该项目不存在", 0);
  4133. }
  4134. break;
  4135. default:
  4136. return Result::error("该数据不存在", 0);
  4137. break;
  4138. }
  4139. // return Result::success($article);
  4140. // $catid =0 ;
  4141. if (!isset($article['cat_arr_id'])) {
  4142. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  4143. } else {
  4144. $catidArray = json_decode($article['cat_arr_id'], true);
  4145. $catid = !empty($catidArray) ? end($catidArray) : null;
  4146. }
  4147. // return Result::success($catid);
  4148. // // return Result::success($article['cat_arr_id']);
  4149. if (empty($catid)) {
  4150. return Result::error("该栏目路径不存在", 0);
  4151. }
  4152. $path = WebsiteCategory::where('website_id', $data['website_id'])
  4153. ->where('category_id', $catid)
  4154. ->first('path');
  4155. }
  4156. // else{
  4157. // // if ($last_category['pid'] != 0) {
  4158. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  4159. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  4160. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  4161. // ->where('category_id',$catid)
  4162. // ->where('path',$data['all_route'])
  4163. // ->first('path');
  4164. // // } else {
  4165. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  4166. // // }
  4167. // }
  4168. // return Result::success($path);
  4169. if (!empty($path) && $path['path'] != $data['all_route']) {
  4170. return Result::error('非法路径!');
  4171. } else {
  4172. return Result::success($last_category['path']);
  4173. }
  4174. }
  4175. /**
  4176. * 招工招聘 - 获取推荐职位
  4177. * @param array $data
  4178. * @return array
  4179. */
  4180. public function getWebsiteLevelJob(array $data): array
  4181. {
  4182. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  4183. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  4184. ->where('job_recruiting.status', 1)
  4185. ->where('job_level', $data['job_level'])
  4186. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4187. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  4188. ->orderBy('job_recruiting.updated_at', 'desc')
  4189. ->limit($data['pageSize'])
  4190. ->get();
  4191. $web = ['website_id' => $data['website_id']];
  4192. if (!empty($job)) {
  4193. $result = $this->processJob($job, $web);
  4194. }
  4195. if (empty($result)) {
  4196. return Result::error("暂无相关职位信息", 0);
  4197. }
  4198. return Result::success($result);
  4199. }
  4200. /**
  4201. * 验证导航名称是否重复
  4202. * @return void
  4203. */
  4204. //20250226 产品列表
  4205. public function getGoodList(array $data): array
  4206. {
  4207. var_dump($data, '---------1-2--');
  4208. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  4209. unset($data['user_type_id']);
  4210. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4211. $where = [];
  4212. if ($type_id != '10000') {
  4213. $where = [
  4214. 'good.user_id' => $user_id,
  4215. ];
  4216. }
  4217. //类型
  4218. if (isset($data['type_id']) && $data['type_id']) {
  4219. $where['good.type_id'] = $data['type_id'];
  4220. }
  4221. //名称
  4222. if (isset($data['name']) && $data['name']) {
  4223. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  4224. }
  4225. //status
  4226. if (isset($data['status']) && $data['status'] != '') {
  4227. $where['good.status'] = $data['status'];
  4228. }
  4229. //status1
  4230. // if (isset($data['status1']) && $data['status1'] == 1) {
  4231. // $status1 = 1;
  4232. // }
  4233. $where1 = [];
  4234. //website_id
  4235. // if (isset($data['website_id']) && $data['website_id']) {
  4236. // $where1 = [
  4237. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  4238. // ];
  4239. // }
  4240. // website_name
  4241. if (isset($data['website_name']) && $data['website_name']) {
  4242. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  4243. }
  4244. // catid
  4245. if (isset($data['category_name']) && $data['category_name']) {
  4246. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  4247. }
  4248. // $result = Good::where($where)
  4249. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  4250. var_dump($where, '---------1---');
  4251. $result = Good::where($where)
  4252. ->when(!empty($where1), function ($query) use ($where1) {
  4253. return $query->where($where1);
  4254. })
  4255. //status 1待审核2已审核3已拒绝
  4256. ->when(isset($data['status1']), function ($query) {
  4257. return $query->whereIn('good.status', [1, 3]);
  4258. })
  4259. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4260. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4261. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4262. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4263. ->orderBy("updated_at", "desc")
  4264. ->limit($data['page_size'])
  4265. ->offset(($data['page'] - 1) * $data['page_size'])
  4266. ->get();
  4267. $count = Good::where($where)
  4268. ->when(!empty($where1), function ($query) use ($where1) {
  4269. return $query->where($where1);
  4270. })
  4271. //status 1待审核2已审核3已拒绝
  4272. ->when(isset($data['status1']), function ($query) {
  4273. return $query->whereIn('good.status', [1, 3]);
  4274. })
  4275. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4276. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4277. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4278. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4279. ->orderBy("updated_at", "desc")->count();
  4280. $data = [
  4281. 'rows' => $result->toArray(),
  4282. 'count' => $count,
  4283. ];
  4284. if (empty($result)) {
  4285. return Result::error("此栏目暂无相关产品", 0);
  4286. }
  4287. return Result::success($data);
  4288. }
  4289. public function getGoodInfo(array $data): array
  4290. {
  4291. $result = Good::where('id', $data['id'])->first();
  4292. if (empty($result)) {
  4293. return Result::error("此产品不存在", 0);
  4294. }
  4295. return Result::success($result);
  4296. }
  4297. public function addGood(array $data): array
  4298. {
  4299. // unset($data['city_arr_id']);
  4300. // unset($data['cat_arr_id']);
  4301. $data['city_id'] = end($data['city_arr_id']);
  4302. $data['catid'] = end($data['cat_arr_id']);
  4303. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4304. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4305. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4306. unset($data['imgUrl']); //大小写
  4307. if (isset($data['price']) && $data['price'] == '') {
  4308. $data['price'] = 0;
  4309. }
  4310. if ($data['imgurl'] == '') {
  4311. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4312. preg_match_all($reg, $data['detail'], $matches);
  4313. if (isset($matches[1][0])) {
  4314. //截取varchar240
  4315. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4316. }
  4317. }
  4318. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4319. //提取标题+内容中的关键词
  4320. $data['keyword'] = $data['name'];
  4321. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4322. Jieba::init(); // 初始化 jieba-php
  4323. Finalseg::init();
  4324. $segList = Jieba::cut($data['keyword']);
  4325. $segList1 = array_slice($segList, 0, 8);
  4326. $data['keyword'] = implode(',', $segList1);
  4327. }
  4328. if ($data['description'] == '') {
  4329. //提取内容中的描述
  4330. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4331. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4332. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4333. }
  4334. if ($data['status'] == 1) {
  4335. $this->sendMessage([
  4336. 'talk_type' => 200,
  4337. 'title' => $data['name'],
  4338. 'content' => '提交了审核',
  4339. 'messageType' => 3,
  4340. ]);
  4341. }
  4342. $result = Good::insert($data);
  4343. if (empty($result)) {
  4344. return Result::error("添加失败", 0);
  4345. }
  4346. return Result::success($result);
  4347. }
  4348. public function updateGood(array $data): array
  4349. {
  4350. $data['city_id'] = end($data['city_arr_id']);
  4351. $data['catid'] = end($data['cat_arr_id']);
  4352. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4353. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4354. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4355. //设置东八区
  4356. date_default_timezone_set('Asia/Shanghai');
  4357. $data['updated_at'] = date('Y-m-d H:i:s');
  4358. if (isset($data['price']) && $data['price'] == '') {
  4359. $data['price'] = 0;
  4360. }
  4361. if ($data['imgurl'] == '') {
  4362. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4363. preg_match_all($reg, $data['detail'], $matches);
  4364. if (isset($matches[1][0])) {
  4365. //截取varchar240
  4366. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4367. }
  4368. }
  4369. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4370. //提取标题+内容中的关键词
  4371. $data['keyword'] = $data['name'];
  4372. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4373. Jieba::init(); // 初始化 jieba-php
  4374. Finalseg::init();
  4375. $segList = Jieba::cut($data['keyword']);
  4376. $segList1 = array_slice($segList, 0, 8);
  4377. $data['keyword'] = implode(',', $segList1);
  4378. }
  4379. if ($data['description'] == '') {
  4380. //提取内容中的描述
  4381. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4382. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4383. }
  4384. if ($data['status'] == 1) {
  4385. $this->sendMessage([
  4386. 'talk_type' => 200,
  4387. 'title' => $data['name'],
  4388. 'content' => '提交了审核',
  4389. 'messageType' => 3,
  4390. ]);
  4391. }
  4392. $result = Good::where('id', $data['id'])->update($data);
  4393. if (empty($result)) {
  4394. return Result::error("更新失败", 0);
  4395. }
  4396. return Result::success($result);
  4397. }
  4398. public function delGood(array $data): array
  4399. {
  4400. $result = Good::where('id', $data['id'])->delete();
  4401. if (empty($result)) {
  4402. return Result::error("删除失败", 0);
  4403. }
  4404. return Result::success($result);
  4405. }
  4406. //20250226 产品列表
  4407. //20250306 求职信息
  4408. public function getJobHuntingList(array $data): array
  4409. {
  4410. $where = [];
  4411. if (isset($data['username']) && !empty($data['username'])) {
  4412. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4413. }
  4414. //status 1待审核2已审核3已拒绝
  4415. if (isset($data['status']) && $data['status'] != '') {
  4416. $where = [
  4417. 'job_hunting.status' => $data['status'],
  4418. ];
  4419. }
  4420. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4421. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4422. unset($data['type_id']);
  4423. if ($type_id != '10000') {
  4424. $where[] = ['job_hunting.user_id', '=', $user_id];
  4425. }
  4426. $result = JobHunting::where($where)
  4427. ->when(!empty($data['status1']), function ($query) use ($data) {
  4428. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4429. })
  4430. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4431. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4432. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  4433. ->orderBy("updated_at", "desc")
  4434. ->limit($data['page_size'])
  4435. ->offset(($data['page'] - 1) * $data['page_size'])
  4436. ->get();
  4437. if (empty($result)) {
  4438. return Result::error("查询失败", 0);
  4439. }
  4440. $count = 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. ->count();
  4447. $data = [
  4448. 'rows' => $result->toArray(),
  4449. 'count' => $count,
  4450. ];
  4451. return Result::success($data);
  4452. }
  4453. public function getJobHuntingApply(array $data): array
  4454. {
  4455. var_dump($data, '-----------------test--------1-');
  4456. $where = [];
  4457. if (isset($data['username']) && !empty($data['username'])) {
  4458. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4459. }
  4460. if (isset($data['salary']) && !empty($data['salary'])) {
  4461. $where[] = [
  4462. 'job_hunting.salary',
  4463. '=',
  4464. $data['salary'],
  4465. ];
  4466. }
  4467. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4468. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4469. unset($data['type_id']);
  4470. if ($type_id != '10000') {
  4471. $where[] = ['job_apply.receiver_id', '=', $user_id];
  4472. }
  4473. var_dump($where, '-----------------test---------');
  4474. $result = jobApply::where($where)
  4475. // ->when(!empty($data['status1']), function ($query) use ($data) {
  4476. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4477. // })
  4478. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  4479. ->where('job_enum.egroup', '=', 'income')
  4480. ->where('job_hunting.status', 2) //已审核
  4481. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4482. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4483. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4484. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4485. //职位----是申请职位
  4486. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4487. ->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')
  4488. ->orderBy("job_hunting.updated_at", "desc")
  4489. ->limit($data['page_size'])
  4490. ->offset(($data['page'] - 1) * $data['page_size'])
  4491. ->get();
  4492. if (empty($result)) {
  4493. return Result::error("查询失败", 0);
  4494. }
  4495. $count = jobApply::where($where)
  4496. ->where('job_enum.egroup', '=', 'income')
  4497. ->where('job_hunting.status', 2) //已审核
  4498. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4499. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4500. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4501. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4502. //职位----是申请职位
  4503. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4504. ->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')
  4505. ->count();
  4506. $data = [
  4507. 'rows' => $result->toArray(),
  4508. 'count' => $count,
  4509. ];
  4510. return Result::success($data);
  4511. }
  4512. public function addJobHunting(array $data): array
  4513. {
  4514. date_default_timezone_set('Asia/Shanghai');
  4515. unset($data['company_name']);
  4516. unset($data['job_industry']);
  4517. unset($data['job_name']);
  4518. unset($data['department']);
  4519. unset($data['job_timeList']);
  4520. unset($data['job_content']);
  4521. unset($data['job_typename']); //不知道这是啥,
  4522. $data['created_at'] = date('Y-m-d H:i:s');
  4523. $data['updated_at'] = date('Y-m-d H:i:s');
  4524. //根据用户 user_id 只能添加一次
  4525. $result = JobHunting::where('user_id', $data['user_id'])->first();
  4526. if (!empty($result)) {
  4527. return Result::error("您已添加过求职信息", 0);
  4528. }
  4529. var_dump($result, '-----------------test---------');
  4530. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  4531. if (is_string($data['city_arr_id'])) {
  4532. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4533. $cityArr = json_decode($data['city_arr_id'], true);
  4534. // 确保 $cityArr 是数组
  4535. if (is_array($cityArr)) {
  4536. $data['city_id'] = end($cityArr);
  4537. }
  4538. } else {
  4539. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4540. if (is_array($data['city_arr_id'])) {
  4541. $data['city_id'] = end($data['city_arr_id']);
  4542. }
  4543. }
  4544. }
  4545. // 处理求职所绑定栏目
  4546. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4547. if (is_string($data['cat_arr_id'])) {
  4548. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4549. // 先清理可能存在的无效 JSON 字符
  4550. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4551. $catArr = json_decode($cleanedCatArrStr, true);
  4552. // 检查 JSON 解码是否成功且结果是数组
  4553. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4554. $data['catid'] = end($catArr);
  4555. }
  4556. } else {
  4557. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4558. if (is_array($data['cat_arr_id'])) {
  4559. $data['catid'] = end($data['cat_arr_id']);
  4560. }
  4561. }
  4562. }
  4563. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4564. $this->sendMessage([
  4565. 'talk_type' => 600,
  4566. 'title' => $data['name'],
  4567. 'content' => '提交了审核',
  4568. 'messageType' => 11,
  4569. ]);
  4570. }
  4571. $result = JobHunting::create($data);
  4572. if (empty($result)) {
  4573. return Result::error("添加失败", 0);
  4574. }
  4575. return Result::success($result);
  4576. }
  4577. public function delJobHunting(array $data): array
  4578. {
  4579. $result = JobHunting::where('id', $data['id'])->delete();
  4580. if (empty($result)) {
  4581. return Result::error("删除失败", 0);
  4582. }
  4583. return Result::success($result);
  4584. }
  4585. public function updateJobHunting(array $data): array
  4586. {
  4587. //设置东八区
  4588. date_default_timezone_set('Asia/Shanghai');
  4589. unset($data['company_name']);
  4590. unset($data['job_industry']);
  4591. unset($data['job_name']);
  4592. unset($data['department']);
  4593. unset($data['job_timeList']);
  4594. unset($data['job_content']);
  4595. unset($data['job_typename']); //不知道这是啥,
  4596. $data['created_at'] = date('Y-m-d H:i:s');
  4597. $data['updated_at'] = date('Y-m-d H:i:s');
  4598. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4599. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4600. $cityArr = json_decode($data['city_arr_id'], true);
  4601. $data['city_id'] = end($cityArr);
  4602. } else {
  4603. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4604. $data['city_id'] = end($data['city_arr_id']);
  4605. }
  4606. // 处理求职所绑定栏目
  4607. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4608. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4609. $catArr = json_decode($data['cat_arr_id'], true);
  4610. $data['catid'] = end($catArr);
  4611. } else {
  4612. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4613. $data['catid'] = end($data['cat_arr_id']);
  4614. }
  4615. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4616. $this->sendMessage([
  4617. 'talk_type' => 600,
  4618. 'title' => $data['name'],
  4619. 'content' => '提交了审核',
  4620. 'messageType' => 11,
  4621. ]);
  4622. }
  4623. $result = JobHunting::where('id', $data['id'])->update($data);
  4624. if (empty($result)) {
  4625. return Result::error("更新失败", 0);
  4626. }
  4627. return Result::success($result);
  4628. }
  4629. public function getJobHuntingInfo(array $data): array
  4630. {
  4631. $result = JobHunting::where('id', $data['id'])->first();
  4632. if (empty($result)) {
  4633. return Result::error("查询失败", 0);
  4634. }
  4635. return Result::success($result);
  4636. }
  4637. public function getJobHuntingData(array $data): array
  4638. {
  4639. $jobEnum = JobEnum::get();
  4640. $jobIndustry = JobIndustry::get();
  4641. $jobNature = JobNature::get();
  4642. $jobPosition = JobPosition::get();
  4643. $data = [
  4644. 'jobEnum' => $jobEnum,
  4645. 'jobIndustry' => $jobIndustry,
  4646. 'jobNature' => $jobNature,
  4647. 'jobPosition' => $jobPosition,
  4648. ];
  4649. return Result::success($data);
  4650. }
  4651. public function delJobHuntingInfo(array $data): array
  4652. {
  4653. $result = JobHunting::where('id', $data['id'])->delete();
  4654. return Result::success();
  4655. }
  4656. //20250324 通知,公告,消息
  4657. public function delNotice(array $data): array
  4658. {
  4659. $result = Notice::where('id', $data['id'])->delete();
  4660. if ($result) {
  4661. return Result::success();
  4662. } else {
  4663. return Result::error("删除失败", 0);
  4664. }
  4665. }
  4666. public function getNoticeInfo(array $data): array
  4667. {
  4668. $result = Notice::where('id', $data['id'])->first();
  4669. // var_dump($result['re_user_ids'], '--------------------');
  4670. if (empty($result)) {
  4671. return Result::error("查询失败", 0);
  4672. }
  4673. return Result::success($result);
  4674. }
  4675. public function readNotice(array $data): array
  4676. {
  4677. $result = Notice::where('id', $data['id'])->first();
  4678. // var_dump($result['re_user_ids'], '--------------------');
  4679. if (empty($result)) {
  4680. return Result::error("查询失败", 0);
  4681. }
  4682. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4683. $re_user_ids = json_decode($result['re_user_ids'], true);
  4684. var_dump($re_user_ids, '--------------1---test---------');
  4685. var_dump($data, '--------------1---test---------');
  4686. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4687. //如果已经存在,就不再添加
  4688. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4689. $read_id = json_decode($result['read_id'], true);
  4690. if (!is_array($read_id)) {
  4691. $read_id = [];
  4692. }
  4693. if (!in_array($data['user_id'], $read_id)) {
  4694. $read_id[] = $data['user_id'];
  4695. $result['read_id'] = json_encode($read_id);
  4696. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4697. }
  4698. } else {
  4699. //如果不存在,就添加
  4700. $result['read_id'] = json_encode([$data['user_id']]);
  4701. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4702. }
  4703. }
  4704. return Result::success($result);
  4705. }
  4706. public function addNotice(array $data): array
  4707. {
  4708. date_default_timezone_set('Asia/Shanghai');
  4709. $data['created_at'] = date('Y-m-d H:i:s');
  4710. $data['updated_at'] = date('Y-m-d H:i:s');
  4711. // $data['level'] = "1,2,3,4,5";
  4712. $level = json_decode($data['level'], true);
  4713. $user_id = UserInfo::
  4714. //city_id不是null
  4715. whereNotNull('city_id')
  4716. ->whereNotNull('department_id')
  4717. ->where(function ($query) use ($data) {
  4718. $query->where(function ($subQuery) use ($data) {
  4719. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4720. });
  4721. })
  4722. ->where(function ($query) use ($data) {
  4723. $query->where(function ($subQuery) use ($data) {
  4724. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4725. });
  4726. })
  4727. ->when(isset($level) && is_array($level), function ($query) use ($level) {
  4728. $query->whereIn('level', $level);
  4729. })
  4730. ->pluck('user_id')->toArray();
  4731. $user_id = array_unique($user_id);
  4732. $chat_ids = $user_id;
  4733. $user_id = json_encode($user_id);
  4734. $data['re_user_ids'] = $user_id;
  4735. $this->sendMessage([
  4736. 'talk_type' => 700,
  4737. 'title' => $data['title'],
  4738. 'content' => '提交了审核',
  4739. 'messageType' => 5,
  4740. ]);
  4741. $result = Notice::insertGetId($data);
  4742. if (empty($result)) {
  4743. return Result::error("添加失败", 0);
  4744. }
  4745. return Result::success($result);
  4746. }
  4747. public function updateNotice(array $data): array
  4748. {
  4749. date_default_timezone_set('Asia/Shanghai');
  4750. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4751. $user_id = UserInfo::
  4752. //city_id不是null
  4753. whereNotNull('city_id')
  4754. ->whereNotNull('department_id')
  4755. ->where(function ($query) use ($data) {
  4756. $query->where(function ($subQuery) use ($data) {
  4757. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4758. });
  4759. })
  4760. ->where(function ($query) use ($data) {
  4761. $query->where(function ($subQuery) use ($data) {
  4762. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4763. });
  4764. })
  4765. ->pluck('user_id')->toArray();
  4766. $user_id = array_unique($user_id);
  4767. $user_id = json_encode($user_id);
  4768. $data['re_user_ids'] = $user_id;
  4769. $data['updated_at'] = date('Y-m-d H:i:s');
  4770. $this->sendMessage([
  4771. 'talk_type' => 700,
  4772. 'title' => $data['title'],
  4773. 'content' => '提交了审核',
  4774. 'messageType' => 5,
  4775. ]);
  4776. $result = Notice::where('id', $data['id'])->update($data);
  4777. return Result::success($result);
  4778. }
  4779. public function getNoticeList(array $data): array
  4780. {
  4781. $where = [];
  4782. //title
  4783. if (isset($data['title']) && !empty($data['title'])) {
  4784. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4785. }
  4786. //level
  4787. if (isset($data['level']) && !empty($data['level'])) {
  4788. $where[] = ['notice.level', '=', $data['level']];
  4789. }
  4790. //status
  4791. if (isset($data['status']) && !empty($data['status'])) {
  4792. $where[] = ['notice.status', '=', $data['status']];
  4793. }
  4794. //type
  4795. if (isset($data['type']) && !empty($data['type'])) {
  4796. $where[] = ['notice.type', '=', $data['type']];
  4797. }
  4798. var_dump($data, '------------11111-2----test---------');
  4799. if ($data['type_id'] == 10000) {
  4800. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4801. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4802. })
  4803. ->where($where)
  4804. ->orderBy('updated_at', 'desc')
  4805. ->limit($data['page_size'])
  4806. ->offset(($data['page'] - 1) * $data['page_size'])
  4807. ->get();
  4808. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4809. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4810. })
  4811. ->where($where)
  4812. ->orderBy('updated_at', 'desc')
  4813. ->count();
  4814. } else {
  4815. $result = Notice::where($where)
  4816. // ->where('user_id', $data['user_id'])
  4817. ->Where(function ($query) use ($data) {
  4818. $query->Where(function ($q) use ($data) {
  4819. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4820. ->orWhere('notice.user_id', $data['user_id']);
  4821. });
  4822. })
  4823. ->when(!empty($data['status1']), function ($query) use ($data) {
  4824. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4825. })
  4826. ->orderBy('updated_at', 'desc')
  4827. ->limit($data['page_size'])
  4828. ->offset(($data['page'] - 1) * $data['page_size'])
  4829. ->get();
  4830. $total = Notice::where($where)
  4831. ->when(!empty($data['status1']), function ($query) use ($data) {
  4832. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4833. })
  4834. // ->where('user_id', $data['user_id'])
  4835. ->Where(function ($query) use ($data) {
  4836. $query->Where(function ($q) use ($data) {
  4837. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4838. ->orWhere('notice.user_id', $data['user_id']);
  4839. });
  4840. })
  4841. ->count();
  4842. }
  4843. if (empty($result)) {
  4844. return Result::error("查询失败", 0);
  4845. }
  4846. $data = [
  4847. 'rows' => $result,
  4848. 'count' => $total,
  4849. ];
  4850. return Result::success($data);
  4851. }
  4852. public function noticeList(array $data): array
  4853. {
  4854. $where = [];
  4855. //title
  4856. if (isset($data['title']) && !empty($data['title'])) {
  4857. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4858. }
  4859. //level
  4860. if (isset($data['level']) && !empty($data['level'])) {
  4861. $where[] = ['notice.level', '=', $data['level']];
  4862. }
  4863. //status
  4864. if (isset($data['status']) && !empty($data['status'])) {
  4865. $where[] = ['notice.status', '=', $data['status']];
  4866. }
  4867. //type
  4868. if (isset($data['type']) && !empty($data['type'])) {
  4869. $where[] = ['notice.type', '=', $data['type']];
  4870. }
  4871. var_dump($data, '------------11111-2----test---------');
  4872. if ($data['type_id'] == 10000) {
  4873. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4874. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4875. })
  4876. ->where($where)
  4877. ->orderBy('updated_at', 'desc')
  4878. ->limit($data['page_size'])
  4879. ->offset(($data['page'] - 1) * $data['page_size'])
  4880. ->get();
  4881. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4882. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4883. })
  4884. ->where($where)
  4885. ->orderBy('updated_at', 'desc')
  4886. ->count();
  4887. } else {
  4888. $result = Notice::where($where)
  4889. // ->where('user_id', $data['user_id'])
  4890. ->Where(function ($query) use ($data) {
  4891. $query->Where(function ($q) use ($data) {
  4892. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4893. ->orWhere('notice.user_id', $data['user_id']);
  4894. });
  4895. })
  4896. ->when(!empty($data['status1']), function ($query) use ($data) {
  4897. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4898. })
  4899. ->orderBy('updated_at', 'desc')
  4900. ->limit($data['page_size'])
  4901. ->offset(($data['page'] - 1) * $data['page_size'])
  4902. ->get();
  4903. $total = Notice::where($where)
  4904. ->when(!empty($data['status1']), function ($query) use ($data) {
  4905. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4906. })
  4907. // ->where('user_id', $data['user_id'])
  4908. ->Where(function ($query) use ($data) {
  4909. $query->Where(function ($q) use ($data) {
  4910. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4911. ->orWhere('notice.user_id', $data['user_id']);
  4912. });
  4913. })
  4914. ->count();
  4915. }
  4916. if (empty($result)) {
  4917. return Result::error("查询失败", 0);
  4918. }
  4919. $data = [
  4920. 'rows' => $result,
  4921. 'count' => $total,
  4922. ];
  4923. return Result::success($data);
  4924. }
  4925. public function getNoticeDetail(array $data): array
  4926. {
  4927. $result = Notice::where('id', $data['id'])->first();
  4928. if (empty($result)) {
  4929. return Result::error("查询失败", 0);
  4930. }
  4931. return Result::success($result);
  4932. }
  4933. public function deleteNotice(array $data): array
  4934. {
  4935. $notice = Notice::where('id', $data['id'])->first();
  4936. if (empty($notice)) {
  4937. return Result::error("删除失败", 0);
  4938. }
  4939. $chat_group_id = $notice->group_id;
  4940. if ($chat_group_id) {
  4941. //删除群聊
  4942. ChatGroups::where('id', $chat_group_id)->delete();
  4943. //删除群成员
  4944. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4945. //删除群聊记录
  4946. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4947. }
  4948. $result = Notice::where('id', $data['id'])->delete();
  4949. return Result::success($result);
  4950. }
  4951. public function complaintList(array $data): array
  4952. {
  4953. var_dump($data, '---------1---------');
  4954. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4955. unset($data['type_id']);
  4956. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4957. $where = [];
  4958. if ($type_id != 10000 && empty($data['deal_user'])) {
  4959. // $where['complaint.user_id'] = $user_id;
  4960. }
  4961. if (!empty($data['title'])) {
  4962. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4963. }
  4964. if (!empty($data['department_id'])) {
  4965. $where['complaint.department_id'] = $data['department_id'];
  4966. }
  4967. if (!empty($data['deal'])) {
  4968. $where['complaint.deal'] = $data['deal'];
  4969. }
  4970. if (!empty($data['status'])) {
  4971. $where['complaint.status'] = $data['status'];
  4972. }
  4973. var_dump(!empty($data['deal_user']), '----------1');
  4974. var_dump($where, '----------2');
  4975. $result = Complaint::where($where)
  4976. ->when(!empty($data['status1']), function ($query) use ($data) {
  4977. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4978. })
  4979. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4980. //json re_user_ids data[user_id]是不是在里面
  4981. $query->Where(function ($q) use ($data) {
  4982. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4983. ->where('complaint.status', 2);
  4984. });
  4985. })
  4986. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4987. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4988. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4989. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4990. ->orderBy('updated_at', 'desc')
  4991. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4992. //sql输出
  4993. if (empty($result)) {
  4994. return Result::error("暂无投诉信息", 0);
  4995. }
  4996. // 取出数据
  4997. $rows = $result->items();
  4998. $count = $result->total();
  4999. $responseData = [
  5000. 'rows' => $rows,
  5001. 'count' => $count,
  5002. ];
  5003. return Result::success($responseData);
  5004. }
  5005. public function getComplaintList(array $data): array
  5006. {
  5007. var_dump($data, '00000001000000000000');
  5008. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  5009. unset($data['type_id']);
  5010. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  5011. $where = [];
  5012. if ($type_id != 10000 && empty($data['deal_user'])) {
  5013. $where['complaint.user_id'] = $user_id;
  5014. }
  5015. if (!empty($data['title'])) {
  5016. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  5017. }
  5018. if (!empty($data['department_id'])) {
  5019. $where['complaint.department_id'] = $data['department_id'];
  5020. }
  5021. if (!empty($data['deal'])) {
  5022. $where['complaint.deal'] = $data['deal'];
  5023. }
  5024. if (!empty($data['status'])) {
  5025. $where['complaint.status'] = $data['status'];
  5026. }
  5027. var_dump(!empty($data['deal_user']), '----------1');
  5028. var_dump($where, '----------2');
  5029. $result = Complaint::where($where)
  5030. ->when(!empty($data['status1']), function ($query) use ($data) {
  5031. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  5032. })
  5033. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  5034. // //json re_user_ids data[user_id]是不是在里面
  5035. // $query->Where(function ($q) use ($data) {
  5036. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  5037. // ->where('complaint.status', 2);
  5038. // });
  5039. // })
  5040. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  5041. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  5042. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  5043. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  5044. ->orderBy('updated_at', 'desc')
  5045. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5046. //sql输出
  5047. if (empty($result)) {
  5048. return Result::error("暂无投诉信息", 0);
  5049. }
  5050. // 取出数据
  5051. $rows = $result->items();
  5052. $count = $result->total();
  5053. $responseData = [
  5054. 'rows' => $rows,
  5055. 'count' => $count,
  5056. ];
  5057. return Result::success($responseData);
  5058. }
  5059. public function getComplaintInfo(array $data): array
  5060. {
  5061. $result = Complaint::where('id', $data['id'])->first();
  5062. if (empty($result)) {
  5063. return Result::error("查询失败", 0);
  5064. }
  5065. return Result::success($result);
  5066. }
  5067. public function readComplaint(array $data): array
  5068. {
  5069. $result = Complaint::where('id', $data['id'])->first();
  5070. if (empty($result)) {
  5071. return Result::error("查询失败", 0);
  5072. }
  5073. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  5074. $re_user_ids = json_decode($result['re_user_ids'], true);
  5075. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  5076. //如果已经存在,就不再添加
  5077. if (isset($result['read_id']) && !empty($result['read_id'])) {
  5078. $read_id = json_decode($result['read_id'], true);
  5079. if (!is_array($read_id)) {
  5080. $read_id = [];
  5081. }
  5082. if (!in_array($data['user_id'], $read_id)) {
  5083. $read_id[] = $data['user_id'];
  5084. $result['read_id'] = json_encode($read_id);
  5085. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  5086. }
  5087. } else {
  5088. //如果不存在,就添加
  5089. $result['read_id'] = json_encode([$data['user_id']]);
  5090. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  5091. }
  5092. }
  5093. return Result::success($result);
  5094. }
  5095. public function addComplaint(array $data): array
  5096. {
  5097. date_default_timezone_set('Asia/Shanghai');
  5098. $data['created_at'] = date('Y-m-d H:i:s');
  5099. $data['updated_at'] = date('Y-m-d H:i:s');
  5100. $this->sendMessage([
  5101. 'talk_type' => 800,
  5102. 'title' => $data['title'],
  5103. 'content' => '提交了审核',
  5104. 'messageType' => 6,
  5105. ]);
  5106. $result = Complaint::create($data);
  5107. return Result::success($result);
  5108. }
  5109. public function updateComplaint(array $data): array
  5110. {
  5111. date_default_timezone_set('Asia/Shanghai');
  5112. $data['updated_at'] = date('Y-m-d H:i:s');
  5113. $user_id = $data['user_id'] ?? 0;
  5114. $type_id = $data['type_id'] ?? 0;
  5115. unset($data['user_id']);
  5116. unset($data['type_id']);
  5117. $this->sendMessage([
  5118. 'talk_type' => 800,
  5119. 'title' => $data['title'],
  5120. 'content' => '提交了审核',
  5121. 'messageType' => 6,
  5122. ]);
  5123. $result = Complaint::where('id', $data['id'])->update($data);
  5124. return Result::success($result);
  5125. }
  5126. public function deleteComplaint(array $data): array
  5127. {
  5128. $result = Complaint::where('id', $data['id'])->delete();
  5129. return Result::success($result);
  5130. }
  5131. public function getComplainInfo(array $data): array
  5132. {
  5133. $result = Complaint::where('id', $data['id'])->first();
  5134. if (empty($result)) {
  5135. return Result::error("查询失败", 0);
  5136. }
  5137. return Result::success($result);
  5138. }
  5139. public function updateComplaintStatus(array $data): array
  5140. {
  5141. date_default_timezone_set('Asia/Shanghai');
  5142. $data['updated_at'] = date('Y-m-d H:i:s');
  5143. $user_id = $data['user_id'] ?? 0;
  5144. $type_id = $data['type_id'] ?? 0;
  5145. unset($data['user_id']);
  5146. unset($data['type_id']);
  5147. //处理, 写入处理人
  5148. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  5149. $data['real_deal_user'] = $user_id;
  5150. }
  5151. //如果是deal 23,则判断是不是处理人
  5152. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  5153. $complaintInof = Complaint::where('id', $data['id'])
  5154. ->where('real_deal_user', $user_id)
  5155. ->first();
  5156. if (empty($complaintInof)) {
  5157. return Result::error("处理人错误", 0);
  5158. }
  5159. }
  5160. $complaintInfo = Complaint::where('id', $data['id'])->first();
  5161. if ($data['status'] == 1) {
  5162. $this->sendMessage([
  5163. 'talk_type' => 800,
  5164. 'title' => $complaintInfo['title'],
  5165. 'content' => '提交了审核',
  5166. 'messageType' => 6,
  5167. ]);
  5168. }
  5169. if ($data['status'] == 2 && !isset($data['deal'])) {
  5170. $this->sendMessage([
  5171. 'talk_type' => 801,
  5172. 'title' => $complaintInfo['title'],
  5173. 'content' => '审核通过',
  5174. 'messageType' => 6,
  5175. 'user_id' => $complaintInfo['user_id'],
  5176. ]);
  5177. $this->sendMessage([
  5178. 'talk_type' => 802,
  5179. 'title' => $complaintInfo['title'],
  5180. 'content' => '待处理',
  5181. 'messageType' => 6,
  5182. 'user_id' => $complaintInfo['re_user_ids'],
  5183. ]);
  5184. }
  5185. if ($data['status'] == 3 && !isset($data['deal'])) {
  5186. $this->sendMessage([
  5187. 'talk_type' => 801,
  5188. 'title' => $complaintInfo['title'],
  5189. 'content' => '审核拒绝',
  5190. 'messageType' => 6,
  5191. 'user_id' => $complaintInfo['user_id'],
  5192. ]);
  5193. }
  5194. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  5195. $this->sendMessage([
  5196. 'talk_type' => 802,
  5197. 'title' => $complaintInfo['title'],
  5198. 'content' => '处理中',
  5199. 'messageType' => 6,
  5200. 'user_id' => $complaintInfo['re_user_ids'],
  5201. ]);
  5202. }
  5203. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  5204. $this->sendMessage([
  5205. 'talk_type' => 802,
  5206. 'title' => $complaintInfo['title'],
  5207. 'content' => '不予处理',
  5208. 'messageType' => 6,
  5209. 'user_id' => $complaintInfo['re_user_ids'],
  5210. ]);
  5211. }
  5212. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  5213. $this->sendMessage([
  5214. 'talk_type' => 802,
  5215. 'title' => $complaintInfo['title'],
  5216. 'content' => '已完结',
  5217. 'messageType' => 6,
  5218. 'user_id' => $complaintInfo['re_user_ids'],
  5219. ]);
  5220. }
  5221. $result = complaint::where('id', $data['id'])->update($data);
  5222. return Result::success($result);
  5223. }
  5224. public function updateGoodStatus(array $data): array
  5225. {
  5226. $user_id = $data['user_id'] ?? 0;
  5227. $type_id = $data['type_id'] ?? 0;
  5228. unset($data['user_id']);
  5229. unset($data['type_id']);
  5230. $goodInfo = Good::where('id', $data['id'])->first();
  5231. if ($data['status'] == 2) {
  5232. $this->sendMessage([
  5233. 'talk_type' => 201,
  5234. 'title' => $goodInfo['name'],
  5235. 'content' => '审核通过',
  5236. 'messageType' => 3,
  5237. 'user_id' => $goodInfo['user_id'],
  5238. ]);
  5239. }
  5240. if ($data['status'] == 3) {
  5241. $this->sendMessage([
  5242. 'talk_type' => 201,
  5243. 'title' => $goodInfo['name'],
  5244. 'content' => '审核拒绝',
  5245. 'messageType' => 3,
  5246. 'user_id' => $goodInfo['user_id'],
  5247. ]);
  5248. }
  5249. if ($data['status'] == 1) {
  5250. $this->sendMessage([
  5251. 'talk_type' => 200,
  5252. 'title' => $goodInfo['name'],
  5253. 'content' => '提交了审核',
  5254. 'messageType' => 3,
  5255. ]);
  5256. }
  5257. $result = Good::where('id', $data['id'])->update($data);
  5258. return Result::success($result);
  5259. }
  5260. public function updateJobHuntingStatus(array $data): array
  5261. {
  5262. $user_id = $data['user_id'] ?? 0;
  5263. $type_id = $data['type_id'] ?? 0;
  5264. unset($data['user_id']);
  5265. unset($data['type_id']);
  5266. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  5267. if ($data['status'] == 2) {
  5268. $this->sendMessage([
  5269. 'talk_type' => 601,
  5270. 'title' => $jogHuntingInfo['name'],
  5271. 'content' => '审核通过',
  5272. 'messageType' => 11,
  5273. 'user_id' => $jogHuntingInfo['user_id'],
  5274. ]);
  5275. }
  5276. if ($data['status'] == 3) {
  5277. $this->sendMessage([
  5278. 'talk_type' => 601,
  5279. 'title' => $jogHuntingInfo['name'],
  5280. 'content' => '审核拒绝',
  5281. 'messageType' => 11,
  5282. 'user_id' => $jogHuntingInfo['user_id'],
  5283. ]);
  5284. }
  5285. if ($data['status'] == 1) {
  5286. $this->sendMessage([
  5287. 'talk_type' => 600,
  5288. 'title' => $jogHuntingInfo['name'],
  5289. 'content' => '提交了审核',
  5290. 'messageType' => 11,
  5291. ]);
  5292. }
  5293. $result = JobHunting::where('id', $data['id'])->update($data);
  5294. return Result::success($result);
  5295. }
  5296. public function updateNoticeStatus(array $data): array
  5297. {
  5298. $user_id = $data['user_id'] ?? 0;
  5299. $type_id = $data['type_id'] ?? 0;
  5300. unset($data['user_id']);
  5301. unset($data['type_id']);
  5302. //查询公告
  5303. $notice = Notice::where('id', $data['id'])->first();
  5304. if (empty($notice)) {
  5305. return Result::error("公告不存在", 0);
  5306. }
  5307. //$chat_ids 去除掉$data['user_id']
  5308. $chat_ids = json_decode($notice['re_user_ids'], true);
  5309. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  5310. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  5311. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  5312. //chat_group
  5313. $group_id = PublicData::uuid();
  5314. $groupData = [
  5315. 'id' => $group_id,
  5316. 'creator_id' => $notice['user_id'],
  5317. 'group_name' => $notice['group_name'] ?? '',
  5318. 'profile' => $notice['profile'] ?? 0,
  5319. ];
  5320. var_dump($groupData, '-----------------groupData-------');
  5321. $groupResult = ChatGroups::insertGetId($groupData);
  5322. var_dump($groupResult, '-----------------groupid-------');
  5323. $groupMemberData = [
  5324. 'id' => PublicData::uuid(),
  5325. 'user_id' => $notice['user_id'],
  5326. 'group_id' => $group_id,
  5327. 'leader' => 2,
  5328. ];
  5329. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  5330. //插入群成员表
  5331. $groupMemberDataUser = [];
  5332. $chatData = [];
  5333. foreach ($chat_ids as $key => $value) {
  5334. $groupMemberDataUser[] = [
  5335. 'id' => PublicData::uuid(),
  5336. 'user_id' => $value,
  5337. 'group_id' => $group_id,
  5338. 'leader' => 1,
  5339. ];
  5340. $chatData[] = [
  5341. 'user_id' => $value,
  5342. 'msg_type' => 1,
  5343. 'receiver_id' => $group_id,
  5344. 'content' => '通过通知创建群聊',
  5345. 'group_receiver_id' => $notice['user_id'],
  5346. 'action' => 'recieved',
  5347. 'created_at' => date('Y-m-d H:i:s'),
  5348. ];
  5349. }
  5350. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  5351. ChatGroupsMember::insert($groupMemberDataUser);
  5352. //插入一条管理员聊天记录
  5353. $chatData[] = [
  5354. 'user_id' => $notice['user_id'],
  5355. 'msg_type' => 1,
  5356. 'receiver_id' => $group_id,
  5357. 'content' => '通过通知创建群聊',
  5358. 'group_receiver_id' => $notice['user_id'],
  5359. 'action' => 'said',
  5360. 'created_at' => date('Y-m-d H:i:s'),
  5361. ];
  5362. var_dump($chatData, '-----------------chatData-------');
  5363. $chatResult = ChatRecords::insert($chatData);
  5364. //处理imp
  5365. $group = [
  5366. 'type' => 1,
  5367. 'name' => $notice['group_name'] ?? '',
  5368. 'profile' => '',
  5369. 'avatar' => '',
  5370. 'creator_id' => $notice['user_id'],
  5371. ];
  5372. $groupResult = GroupImp::insertGetId($group);
  5373. var_dump($groupResult, '获取imp group_id');
  5374. $groupMember = [
  5375. 'user_id' => $notice['user_id'],
  5376. 'group_id' => $groupResult,
  5377. 'leader' => 1,
  5378. 'join_time' => Date('Y-m-d H:i:s')
  5379. ];
  5380. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  5381. $talk_session = [
  5382. 'user_id' => $notice['user_id'],
  5383. 'to_from_id' => $groupResult,
  5384. 'talk_mode' => 2,
  5385. 'created_at' => Date('Y-m-d H:i:s'),
  5386. 'updated_at' => Date('Y-m-d H:i:s'),
  5387. ];
  5388. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  5389. //被通知人员处理
  5390. foreach ($chat_ids as $key => $value) {
  5391. $groupMemberdata[] = [
  5392. 'user_id' => $value,
  5393. 'group_id' => $groupResult,
  5394. 'leader' => 3,
  5395. 'join_time' => Date('Y-m-d H:i:s')
  5396. ];
  5397. $talk_sessionData[] = [
  5398. 'user_id' => $value,
  5399. 'to_from_id' => $groupResult,
  5400. 'talk_mode' => 2,
  5401. 'created_at' => Date('Y-m-d H:i:s'),
  5402. 'updated_at' => Date('Y-m-d H:i:s'),
  5403. ];
  5404. }
  5405. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  5406. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  5407. $group_id = $groupResult;
  5408. //更新result的 group_id
  5409. $data['group_id'] = $group_id;
  5410. Notice::where(['id' => $data['id']])->update($data);
  5411. }
  5412. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  5413. //删除掉信息
  5414. GroupImp::where('id', $notice['group_id'])->delete();
  5415. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  5416. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  5417. foreach ($chat_ids as $key => $value) {
  5418. }
  5419. //聊天记录删除
  5420. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  5421. $data['group_id'] = null;
  5422. Notice::where(['id' => $data['id']])->update($data);
  5423. }
  5424. $result = Notice::where('id', $data['id'])->update($data);
  5425. $noticeInfo = Notice::where('id', $data['id'])->first();
  5426. if ($data['status'] == 2) {
  5427. $this->sendMessage([
  5428. 'talk_type' => 701,
  5429. 'title' => $noticeInfo['title'],
  5430. 'content' => '审核通过',
  5431. 'messageType' => 3,
  5432. 'user_id' => $noticeInfo['user_id'],
  5433. ]);
  5434. }
  5435. if ($data['status'] == 3) {
  5436. $this->sendMessage([
  5437. 'talk_type' => 701,
  5438. 'title' => $noticeInfo['title'],
  5439. 'content' => '审核拒绝',
  5440. 'messageType' => 3,
  5441. 'user_id' => $noticeInfo['user_id'],
  5442. ]);
  5443. }
  5444. if ($data['status'] == 1) {
  5445. $this->sendMessage([
  5446. 'talk_type' => 700,
  5447. 'title' => $noticeInfo['title'],
  5448. 'content' => '提交了审核',
  5449. 'messageType' => 3,
  5450. ]);
  5451. }
  5452. return Result::success($result);
  5453. }
  5454. public function getDUser(array $data): array
  5455. {
  5456. if (!empty($data['ids'])) {
  5457. $user = User::whereIn('id', $data['ids'])->getall();
  5458. if (empty($user)) {
  5459. return Result::error('无数据', 0);
  5460. }
  5461. return Result::success($user);
  5462. }
  5463. $where = [];
  5464. if (!empty($data['department_id'])) {
  5465. $where['department_id'] = $data['department_id'];
  5466. }
  5467. if (!empty($data['city_id'])) {
  5468. $where['city_id'] = $data['city_id'];
  5469. }
  5470. $result = User::where('type_id', 2)
  5471. ->where('status', 1)
  5472. ->where($where)
  5473. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  5474. ->get();
  5475. if (empty($result)) {
  5476. return Result::error("查询失败", 0);
  5477. }
  5478. return Result::success($result);
  5479. }
  5480. /**
  5481. * 验证导航名称是否重复
  5482. * @return void
  5483. */
  5484. public function checkCategoryName(array $data): array
  5485. {
  5486. $result = Category::when($data, function ($query) use ($data) {
  5487. if (isset($data['name']) && $data['name']) {
  5488. $query->where("name", $data['name']);
  5489. }
  5490. if (isset($data['id']) && $data['id']) {
  5491. $query->where("id", "!=", $data['id']);
  5492. }
  5493. })->first();
  5494. if ($result) {
  5495. return Result::error("已存在");
  5496. } else {
  5497. return Result::success();
  5498. }
  5499. }
  5500. //20250226 产品列表
  5501. // 20250306 -------招聘--------fr
  5502. /*
  5503. * 招聘列表
  5504. * */
  5505. public function getJobRecruitingList(array $data): array
  5506. {
  5507. $where = [];
  5508. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  5509. if ($data['checkout'] == 0) {
  5510. $job_status = [0, 2];
  5511. } else {
  5512. $job_status = [1];
  5513. }
  5514. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5515. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  5516. }
  5517. $user = User::where('id', $data['user_id'])->first();
  5518. if (empty($user)) {
  5519. return Result::error("用户不存在", 0);
  5520. }
  5521. // 3:企业会员
  5522. if ($user['type_id'] == 3) {
  5523. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  5524. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  5525. }
  5526. // 如果 $where 为空,则不添加 where 条件
  5527. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5528. return $query->where($where);
  5529. })
  5530. ->whereIn('job_recruiting.status', $job_status)
  5531. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5532. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  5533. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  5534. ->orderBy("updated_at", "desc")
  5535. ->offset(($data['page'] - 1) * $data['page_size'])
  5536. ->limit($data['page_size'])
  5537. ->get()
  5538. ->all();
  5539. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5540. return $query->where($where);
  5541. })
  5542. ->whereIn('job_recruiting.status', $job_status)
  5543. ->count();
  5544. if (empty($result)) {
  5545. return Result::error("暂无招聘信息", 0);
  5546. }
  5547. return Result::success($result);
  5548. }
  5549. /*
  5550. * 招聘信息添加
  5551. * */
  5552. public function addJobRecruiting(array $data): array
  5553. {
  5554. // var_dump('添加招聘进入news------data',$data);
  5555. // return Result::success($data);
  5556. $user = User::where('user.id', $data['user_id'])
  5557. ->where('user.status', 1)
  5558. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5559. ->select(
  5560. 'user.type_id',
  5561. 'user.mobile',
  5562. 'user.email',
  5563. 'user_info.business_name',
  5564. 'user_info.company_hy_id',
  5565. 'user_info.company_nature',
  5566. 'user_info.company_size',
  5567. 'user_info.introduction',
  5568. 'user_info.real_name',
  5569. 'user_info.company_url',
  5570. 'user_info.address_arr_id',
  5571. 'user_info.address'
  5572. )
  5573. ->first();
  5574. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5575. return Result::error("用户不存在", 0);
  5576. }
  5577. $web = Website::where('id', $data['website_id'])->first();
  5578. if (empty($web)) {
  5579. return Result::error("网站不存在", 0);
  5580. }
  5581. // var_dump('添加招聘进入news---user---user',$user);
  5582. // 处理招聘关键词
  5583. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5584. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5585. } else {
  5586. Jieba::init(); // 初始化 jieba-php
  5587. Finalseg::init();
  5588. $segList = Jieba::cut($data['title']);
  5589. $segList1 = array_slice($segList, 0, 8);
  5590. $data['keyword'] = implode(',', $segList1);
  5591. }
  5592. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5593. $content = $data['description'];
  5594. // 去除 <style> 和 <script> 标签及其内容
  5595. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5596. // 去除所有 HTML 标签
  5597. $content = strip_tags($content);
  5598. // 去除 HTML 实体
  5599. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5600. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5601. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5602. // 去除多余空白
  5603. $content = preg_replace('/\s+/u', '', $content);
  5604. // 截取 100 个字符
  5605. $data['seo_description'] = mb_substr($content, 0, 100);
  5606. }
  5607. // return Result::success($user);
  5608. $data['action_id'] = $data['user_id'] ?? null;
  5609. $data['user_type'] = $user['type_id'] ?? null;
  5610. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5611. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5612. $data['catid'] = end($data['cat_arr_id']);
  5613. } else {
  5614. $data['catid'] = 0;
  5615. }
  5616. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5617. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5618. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5619. // 公司地址 管理员必填
  5620. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5621. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5622. // 管理员-企业相关信息
  5623. $company = [
  5624. // 'user_id' => $data['user_id']?? null,
  5625. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5626. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5627. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5628. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5629. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5630. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5631. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5632. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5633. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5634. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5635. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5636. ];
  5637. //去掉相关企业信息
  5638. $job = array_diff_key($data, array_flip(array_keys($company)));
  5639. // var_dump('添加招聘进入news---job---user',$job);
  5640. Db::beginTransaction();
  5641. try {
  5642. // // 先添加职位相关信息
  5643. if ($user['type_id'] == 10000) {
  5644. $job['status'] = 1;
  5645. }
  5646. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5647. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5648. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5649. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5650. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5651. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5652. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5653. // return Result::success($job);
  5654. $jobId = JobRecruiting::insertGetId($job);
  5655. if (empty($jobId)) {
  5656. Db::rollBack();
  5657. return Result::error("添加失败");
  5658. }
  5659. // 添加公司信息
  5660. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5661. $company['job_id'] = $jobId;
  5662. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5663. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5664. if ($user['type_id'] == 10000) {
  5665. // 管理员添加企业信息
  5666. $companyId = JobCompany::insertGetId($company);
  5667. if (empty($companyId)) {
  5668. Db::rollBack();
  5669. return Result::error("添加失败");
  5670. }
  5671. } else {
  5672. // 企业会员添加企业信息
  5673. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5674. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5675. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5676. $company['job_id'] = $jobId;
  5677. $companyId = JobCompany::insertGetId($company);
  5678. if (empty($companyId)) {
  5679. Db::rollBack();
  5680. return Result::error("添加失败");
  5681. }
  5682. }
  5683. Db::commit();
  5684. $result = [
  5685. 'job_id' => $jobId,
  5686. 'company_id' => $companyId,
  5687. ];
  5688. return Result::success($result);
  5689. } catch (\Exception $e) {
  5690. Db::rollBack();
  5691. return Result::error($e->getMessage(), 0);
  5692. }
  5693. // return Result::success($result);
  5694. }
  5695. /*
  5696. * 获取招聘信息详情
  5697. * */
  5698. public function getJobRecruitingInfo(array $data): array
  5699. {
  5700. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5701. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5702. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5703. ->select(
  5704. 'job_recruiting.*',
  5705. 'website.website_name as website_name',
  5706. 'job_company.business_name',
  5707. 'job_company.company_hy_id',
  5708. 'job_company.company_size',
  5709. 'job_company.company_nature',
  5710. 'job_company.introduction',
  5711. 'job_company.real_name',
  5712. 'job_company.mobile',
  5713. 'job_company.company_url',
  5714. 'job_company.address_arr_id',
  5715. 'job_company.address',
  5716. 'job_company.email'
  5717. )
  5718. ->first();
  5719. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5720. if (!empty($cityId)) {
  5721. if (isset($cityId[1]) && $cityId[1] != null) {
  5722. $city = District::where('id', $cityId[1])->first(['name']);
  5723. } else {
  5724. $city = District::where('id', $cityId[0])->first(['name']);
  5725. }
  5726. $result['city'] = $city['name'] ?? '';
  5727. }
  5728. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5729. if (is_array($addressId) && !empty($addressId)) {
  5730. $address = District::whereIn('id', $addressId)
  5731. ->orderBy('level', 'asc')
  5732. ->get(['name'])
  5733. ->pluck('name')
  5734. ->implode('');
  5735. // $job->address_name = $address ?? '';
  5736. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5737. }
  5738. if (empty($result)) {
  5739. return Result::error("招聘信息不存在", 0);
  5740. }
  5741. // return Result::success($job);
  5742. return Result::success($result);
  5743. }
  5744. /*
  5745. * 修改招聘信息
  5746. * */
  5747. public function upJobRecruiting(array $data): array
  5748. {
  5749. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5750. // return Result::success($job);
  5751. if (empty($job)) {
  5752. return Result::error("招聘信息不存在", 0);
  5753. }
  5754. $user = User::where('id', $data['user_id'])->first();
  5755. // return Result::success($user);
  5756. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5757. return Result::error("用户不存在", 0);
  5758. }
  5759. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5760. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5761. }
  5762. // 处理招聘关键词
  5763. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5764. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5765. } else {
  5766. Jieba::init(); // 初始化 jieba-php
  5767. Finalseg::init();
  5768. $segList = Jieba::cut($data['title']);
  5769. $segList1 = array_slice($segList, 0, 8);
  5770. $data['keyword'] = implode(',', $segList1);
  5771. }
  5772. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5773. $content = $data['description'];
  5774. // 去除 <style> 和 <script> 标签及其内容
  5775. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5776. // 去除所有 HTML 标签
  5777. $content = strip_tags($content);
  5778. // 去除 HTML 实体
  5779. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5780. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5781. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5782. // 去除多余空白
  5783. $content = preg_replace('/\s+/u', '', $content);
  5784. // 截取 100 个字符
  5785. $data['seo_description'] = mb_substr($content, 0, 100);
  5786. }
  5787. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5788. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5789. $data['catid'] = end($data['cat_arr_id']);
  5790. } else {
  5791. }
  5792. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5793. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5794. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5795. // 公司地址 管理员必填
  5796. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5797. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5798. // 管理员-企业相关信息
  5799. $company = [
  5800. // 'user_id' => $data['user_id']?? null,
  5801. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5802. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5803. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5804. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5805. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5806. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5807. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5808. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5809. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5810. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5811. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5812. ];
  5813. //去掉相关企业信息
  5814. $data = array_diff_key($data, array_flip(array_keys($company)));
  5815. $jobId = $data['id'];
  5816. $web = $data['website_id'];
  5817. $data['action_id'] = $data['user_id'];
  5818. unset($data['user_id']);
  5819. unset($data['user_type']);
  5820. unset($data['id']);
  5821. unset($data['website_id']);
  5822. // return Result::success($data);
  5823. Db::beginTransaction();
  5824. try {
  5825. // 管理员修改招聘信息
  5826. if ($user['type_id'] == 10000) {
  5827. $data['website_id'] = $web;
  5828. $company['website_id'] = $data['website_id'];
  5829. $data['status'] = 1;
  5830. } else {
  5831. $data['status'] = 0;
  5832. }
  5833. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5834. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5835. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5836. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5837. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5838. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5839. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5840. // return Result::success($job);
  5841. // Db::rollBack();
  5842. // return Result::success($company);
  5843. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5844. $this->sendMessage([
  5845. 'talk_type' => 500,
  5846. 'title' => $data['title'],
  5847. 'content' => '提交了审核',
  5848. 'messageType' => 10,
  5849. ]);
  5850. }
  5851. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5852. if (empty($result['job'])) {
  5853. Db::rollBack();
  5854. return Result::error("修改招聘信息失败");
  5855. }
  5856. // 管理员修改企业相关信息
  5857. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5858. if (empty($result['company'])) {
  5859. Db::rollBack();
  5860. return Result::error("修改企业相关信息失败");
  5861. }
  5862. Db::commit();
  5863. // return Result::success($result);
  5864. } catch (\Exception $e) {
  5865. Db::rollBack();
  5866. return Result::error($e->getMessage(), 0);
  5867. }
  5868. return Result::success($result);
  5869. }
  5870. /*
  5871. * 招聘信息删除
  5872. * */
  5873. public function delJobRecruiting(array $data): array
  5874. {
  5875. $user = User::where('id', $data['user_id'])->first();
  5876. if (empty($user)) {
  5877. return Result::error("用户不存在", 0);
  5878. }
  5879. $job = JobRecruiting::where('id', $data['id'])->first();
  5880. if (empty($job)) {
  5881. return Result::error("招聘信息不存在", 0);
  5882. }
  5883. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5884. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5885. }
  5886. Db::beginTransaction();
  5887. try {
  5888. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5889. if (empty($result['job'])) {
  5890. Db::rollBack();
  5891. return Result::error("删除招聘信息失败");
  5892. }
  5893. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5894. if (empty($result['company'])) {
  5895. Db::rollBack();
  5896. return Result::error("删除企业相关信息失败");
  5897. }
  5898. Db::commit();
  5899. } catch (\Exception $e) {
  5900. Db::rollBack();
  5901. return Result::error($e->getMessage(), 0);
  5902. }
  5903. return Result::success($result);
  5904. }
  5905. /*
  5906. * 获取公司信息
  5907. * */
  5908. public function getJobCompany(array $data): array
  5909. {
  5910. $user = User::where('user.id', $data['user_id'])
  5911. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5912. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5913. ->first();
  5914. // return Result::success($user);
  5915. if (empty($user)) {
  5916. return Result::error("用户不存在", 0);
  5917. }
  5918. if ($user['type_id'] == 3) {
  5919. $result = [
  5920. // 'id' => 0,
  5921. 'user_id' => $data['user_id'],
  5922. 'website_id' => $data['website_id'],
  5923. 'business_name' => $user['business_name'], // 企业名称
  5924. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5925. 'company_nature' => $user['company_nature'], // 公司性质
  5926. 'company_size' => $user['company_size'], // 公司规模
  5927. 'introduction' => $user['introduction'], // 公司简介
  5928. 'real_name' => $user['real_name'], // 企业联系人
  5929. 'mobile' => $user['mobile'], // 企业联系电话
  5930. 'company_url' => $user['company_url'], // 企业网址
  5931. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5932. 'address' => $user['address'], // 企业地址
  5933. 'email' => $user['email'], // 企业邮箱
  5934. ];
  5935. } else {
  5936. return Result::error("用户类型错误", 0);
  5937. }
  5938. if (empty($result)) {
  5939. return Result::error("公司信息不存在", 0);
  5940. }
  5941. return Result::success($result);
  5942. }
  5943. /*
  5944. * 修改公司信息
  5945. * */
  5946. public function upJobCompany(array $data): array
  5947. {
  5948. // return Result::success($data);
  5949. $user = User::where('user.id', $data['user_id'])
  5950. ->where('user.status', 1)
  5951. ->select('user.user_name', 'user.type_id')
  5952. ->first();
  5953. if (empty($user)) {
  5954. return Result::error("用户不存在", 0);
  5955. }
  5956. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5957. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5958. $company = [
  5959. 'business_name' => $data['business_name'], // 企业名称
  5960. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5961. 'company_nature' => $data['company_nature'], // 公司性质
  5962. 'company_size' => $data['company_size'], // 公司规模
  5963. 'introduction' => $data['introduction'], // 公司简介
  5964. // 'real_name' => $data['real_name'], // 企业联系人
  5965. 'company_url' => $data['company_url'], // 企业网址
  5966. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5967. 'address' => $data['address'], // 企业详细地址
  5968. // 'email' => $data['email'], // 企业邮箱
  5969. ];
  5970. if ($user['type_id'] == 3) {
  5971. Db::beginTransaction();
  5972. try {
  5973. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5974. 'business_name' => $data['business_name'], // 企业名称
  5975. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5976. 'company_nature' => $data['company_nature'], // 公司性质
  5977. 'company_size' => $data['company_size'], // 公司规模
  5978. 'introduction' => $data['introduction'], // 公司简介
  5979. // 'real_name' => $data['real_name'], // 企业联系人
  5980. 'company_url' => $data['company_url'], // 企业网址
  5981. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5982. 'address' => $data['address'], // 企业详细地址
  5983. ]);
  5984. if (empty($result['userinfo'])) {
  5985. Db::rollBack();
  5986. return Result::error('修改企业会员信息失败!');
  5987. }
  5988. $result['user'] = User::where('id', $data['user_id'])->update([
  5989. 'email' => $data['email'], // 企业邮箱
  5990. ]);
  5991. if (empty($result['user'])) {
  5992. Db::rollBack();
  5993. return Result::error('修改个人中心信息失败!');
  5994. }
  5995. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5996. if (!empty($job_company)) {
  5997. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5998. if (empty($result['job_company'])) {
  5999. Db::rollBack();
  6000. return Result::error('修改企业会员信息失败!');
  6001. }
  6002. }
  6003. Db::commit();
  6004. return Result::success($result);
  6005. } catch (\Exception $e) {
  6006. Db::rollBack();
  6007. return Result::error($e->getMessage(), 0);
  6008. }
  6009. } else {
  6010. return Result::error("用户类型错误", 0);
  6011. }
  6012. }
  6013. /*
  6014. * 获取省-市
  6015. * */
  6016. public function getJobRecruitingArea(array $data): array
  6017. {
  6018. if (isset($data['pid']) && $data['pid'] != null) {
  6019. $result = District::where('pid', $data['pid'])->get()->all();
  6020. } else {
  6021. $result = District::where('level', 1)->get()->all();
  6022. }
  6023. if (empty($result)) {
  6024. return Result::error("暂无此省市", 0);
  6025. }
  6026. return Result::success($result);
  6027. }
  6028. /*
  6029. * 获取行业分类
  6030. * */
  6031. public function getIndustry(array $data): array
  6032. {
  6033. $result = JobIndustry::get()->all();
  6034. if (empty($result)) {
  6035. return Result::error("暂无行业分类", 0);
  6036. }
  6037. return Result::success($result);
  6038. }
  6039. /*
  6040. * 获取职位
  6041. * */
  6042. public function getPositionList(array $data): array
  6043. {
  6044. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  6045. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  6046. } else {
  6047. $result = JobPosition::where('zwpid', 0)->get()->all();
  6048. }
  6049. if (empty($result)) {
  6050. return Result::error("暂无此职位", 0);
  6051. }
  6052. return Result::success($result);
  6053. }
  6054. /*
  6055. * 获取工作性质-菜单
  6056. * */
  6057. public function getJobNature(array $data): array
  6058. {
  6059. $result = JobEnum::where('egroup', 'nature')->get()->all();
  6060. if (empty($result)) {
  6061. return Result::error("暂无工作性质", 0);
  6062. }
  6063. return Result::success($result);
  6064. }
  6065. /*
  6066. * 获取工作经验-菜单
  6067. * */
  6068. public function getExperience(array $data): array
  6069. {
  6070. $result = JobEnum::where('egroup', 'years')->get()->all();
  6071. if (empty($result)) {
  6072. return Result::error("暂无工作经验", 0);
  6073. }
  6074. return Result::success($result);
  6075. }
  6076. /*
  6077. * 获取学历-菜单
  6078. * */
  6079. public function getEducation(array $data): array
  6080. {
  6081. $result = JobEnum::where('egroup', 'education')->get()->all();
  6082. if (empty($result)) {
  6083. return Result::error("暂无学历", 0);
  6084. }
  6085. return Result::success($result);
  6086. }
  6087. /*
  6088. * 获取薪资-菜单
  6089. * */
  6090. public function getSalary(array $data): array
  6091. {
  6092. $result = JobEnum::where('egroup', 'income')->get()->all();
  6093. if (empty($result)) {
  6094. return Result::error("暂无薪资", 0);
  6095. }
  6096. return Result::success($result);
  6097. }
  6098. /*
  6099. * 获取语言-菜单
  6100. * */
  6101. public function getLanguage(array $data): array
  6102. {
  6103. $result = JobEnum::where('egroup', 'language')->get()->all();
  6104. if (empty($result)) {
  6105. return Result::error("暂无语言", 0);
  6106. }
  6107. return Result::success($result);
  6108. }
  6109. /*
  6110. * 获取掌握程度-菜单
  6111. * */
  6112. public function getLevel(array $data): array
  6113. {
  6114. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  6115. if (empty($result)) {
  6116. return Result::error("暂无工作性质", 0);
  6117. }
  6118. return Result::success($result);
  6119. }
  6120. // 公司信息
  6121. /*
  6122. * 获取公司性质-菜单
  6123. * */
  6124. public function getCompanyNature(array $data): array
  6125. {
  6126. $result = JobNature::get()->all();
  6127. if (empty($result)) {
  6128. return Result::error("暂无公司性质", 0);
  6129. }
  6130. return Result::success($result);
  6131. }
  6132. /*
  6133. * 获取公司规模-菜单
  6134. * */
  6135. public function getCompanySize(array $data): array
  6136. {
  6137. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  6138. if (empty($result)) {
  6139. return Result::error("暂无公司规模", 0);
  6140. }
  6141. return Result::success($result);
  6142. }
  6143. /*
  6144. * 招聘信息审核
  6145. * */
  6146. public function checkJobRecruiting(array $data): array
  6147. {
  6148. $user = User::where('id', $data['user_id'])->first();
  6149. if (empty($user)) {
  6150. return Result::error("用户不存在", 0);
  6151. }
  6152. $job = JobRecruiting::where('id', $data['id'])->first();
  6153. if (empty($job)) {
  6154. return Result::error("招聘信息不存在", 0);
  6155. }
  6156. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  6157. if ($user['type_id'] != 10000) {
  6158. return Result::error("用户暂无权限审核此招聘信息!", 0);
  6159. }
  6160. // 驳回原因
  6161. if ($data['status'] == 2) {
  6162. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  6163. }
  6164. $data['action_id'] = $data['user_id'];
  6165. unset($data['user_id']);
  6166. if ($data['status'] == 1) {
  6167. $this->sendMessage([
  6168. 'talk_type' => 501,
  6169. 'title' => $job['title'],
  6170. 'content' => '审核通过',
  6171. 'messageType' => 10,
  6172. 'user_id' => $job['user_id'],
  6173. ]);
  6174. }
  6175. if ($data['status'] == 2) {
  6176. $this->sendMessage([
  6177. 'talk_type' => 501,
  6178. 'title' => $job['title'],
  6179. 'content' => '审核拒绝',
  6180. 'messageType' => 10,
  6181. 'user_id' => $job['user_id'],
  6182. ]);
  6183. }
  6184. if ($data['status'] == 0) {
  6185. $this->sendMessage([
  6186. 'talk_type' => 500,
  6187. 'title' => $job['title'],
  6188. 'content' => '提交了审核',
  6189. 'messageType' => 10,
  6190. ]);
  6191. }
  6192. $result = JobRecruiting::where('id', $data['id'])->update($data);
  6193. if (empty($result)) {
  6194. return Result::error("审核失败", 0);
  6195. }
  6196. return Result::success($result);
  6197. }
  6198. public function myApplyList(array $data): array
  6199. {
  6200. var_dump($data, '------参数');
  6201. $user = User::where('id', $data['user_id'])->first();
  6202. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6203. return Result::error("用户不存在", 0);
  6204. }
  6205. // 1:个人会员 职场机会
  6206. if ($user['type_id'] == 1) {
  6207. $where['user_id'] = $user['id'];
  6208. }
  6209. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  6210. $query->where('user_id', $user['id']);
  6211. })
  6212. ->pluck('recruit_id');
  6213. $where = [];
  6214. if (isset($data['salary']) && $data['salary'] != null) {
  6215. $where['job_recruiting.salary'] = $data['salary'];
  6216. }
  6217. if (isset($data['experience']) && $data['experience'] != null) {
  6218. $where['job_recruiting.experience'] = $data['experience'];
  6219. }
  6220. if (isset($data['business_name']) && $data['business_name'] != null) {
  6221. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6222. }
  6223. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6224. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6225. ->where($where);
  6226. // ->count();
  6227. $count = $query->count();
  6228. $query = clone $query;
  6229. $job = $query
  6230. ->leftJoin('job_enum as income_enum', function ($join) {
  6231. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6232. ->where('income_enum.egroup', 'income');
  6233. })
  6234. ->leftJoin('job_enum as years_enum', function ($join) {
  6235. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6236. ->where('years_enum.egroup', 'years');
  6237. })
  6238. // ->where($where)
  6239. ->orderBy('job_recruiting.updated_at', 'desc')
  6240. ->select(
  6241. 'job_recruiting.id',
  6242. 'job_recruiting.title',
  6243. 'job_company.business_name',
  6244. 'income_enum.evalue as salary_evalue',
  6245. 'income_enum.ename as salary_ename',
  6246. 'years_enum.evalue as experience_evalue',
  6247. 'years_enum.ename as experience_ename',
  6248. 'job_recruiting.updated_at'
  6249. )
  6250. ->offset(($data['page'] - 1) * $data['pageSize'])
  6251. ->limit($data['pageSize'])
  6252. ->get()
  6253. ->all();
  6254. if (empty($job)) {
  6255. return Result::error("暂无招聘信息", 0);
  6256. }
  6257. $result = [
  6258. 'row' => $job,
  6259. 'count' => $count,
  6260. ];
  6261. return Result::success($result);
  6262. }
  6263. public function readJobApply(array $data): array
  6264. {
  6265. $result = JobApply::where('id', $data['id'])->first();
  6266. if (empty($result)) {
  6267. return Result::error("查询失败", 0);
  6268. }
  6269. $result = JobApply::where('id', $data['id'])->update([
  6270. 'status' => 2,
  6271. ]);
  6272. return Result::success($result);
  6273. }
  6274. /*
  6275. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  6276. * */
  6277. public function getRecruitingList(array $data): array
  6278. {
  6279. $user = User::where('id', $data['user_id'])->first();
  6280. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6281. return Result::error("用户不存在", 0);
  6282. }
  6283. // 1:个人会员 职场机会
  6284. if ($user['type_id'] == 1) {
  6285. $where['user_id'] = $user['id'];
  6286. }
  6287. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  6288. $query->where('receiver_id', $user['id']);
  6289. })
  6290. ->pluck('recruit_id');
  6291. // return Result::success($recruitingId);
  6292. $where = [];
  6293. if (isset($data['salary']) && $data['salary'] != null) {
  6294. $where['job_recruiting.salary'] = $data['salary'];
  6295. }
  6296. if (isset($data['experience']) && $data['experience'] != null) {
  6297. $where['job_recruiting.experience'] = $data['experience'];
  6298. }
  6299. if (isset($data['business_name']) && $data['business_name'] != null) {
  6300. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6301. }
  6302. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6303. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6304. ->where($where);
  6305. // ->count();
  6306. $count = $query->count();
  6307. $query = clone $query;
  6308. $job = $query
  6309. ->leftJoin('job_enum as income_enum', function ($join) {
  6310. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6311. ->where('income_enum.egroup', 'income');
  6312. })
  6313. ->leftJoin('job_enum as years_enum', function ($join) {
  6314. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6315. ->where('years_enum.egroup', 'years');
  6316. })
  6317. // ->where($where)
  6318. ->orderBy('job_recruiting.updated_at', 'desc')
  6319. ->select(
  6320. 'job_recruiting.id',
  6321. 'job_recruiting.title',
  6322. 'job_company.business_name',
  6323. 'income_enum.evalue as salary_evalue',
  6324. 'income_enum.ename as salary_ename',
  6325. 'years_enum.evalue as experience_evalue',
  6326. 'years_enum.ename as experience_ename',
  6327. 'job_recruiting.updated_at'
  6328. )
  6329. ->offset(($data['page'] - 1) * $data['pageSize'])
  6330. ->limit($data['pageSize'])
  6331. ->get()
  6332. ->all();
  6333. if (empty($job)) {
  6334. return Result::error("暂无招聘信息", 0);
  6335. }
  6336. $result = [
  6337. 'row' => $job,
  6338. 'count' => $count,
  6339. ];
  6340. return Result::success($result);
  6341. }
  6342. /*
  6343. * 获取企业会员-招聘信息列表
  6344. * */
  6345. public function getRecruitingInfo(array $data): array
  6346. {
  6347. $user = User::where('id', $data['user_id'])->first();
  6348. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6349. return Result::error("用户不存在", 0);
  6350. }
  6351. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  6352. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6353. ->select(
  6354. 'job_recruiting.*',
  6355. 'job_company.business_name',
  6356. 'job_company.company_hy_id',
  6357. 'job_company.company_size',
  6358. 'job_company.company_nature',
  6359. 'job_company.introduction',
  6360. 'job_company.real_name',
  6361. 'job_company.mobile',
  6362. 'job_company.company_url',
  6363. 'job_company.address_arr_id',
  6364. 'job_company.address',
  6365. 'job_company.email'
  6366. )
  6367. ->get();
  6368. if (empty($recruiting)) {
  6369. return Result::error("暂无招聘信息", 0);
  6370. }
  6371. return Result::success($recruiting);
  6372. }
  6373. /*
  6374. * 获取企业会员-我的沟通
  6375. * */
  6376. public function getJobResumeList(array $data): array
  6377. {
  6378. $user = User::where('id', $data['user_id'])->first();
  6379. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  6380. return Result::error("用户不存在", 0);
  6381. }
  6382. $where = [];
  6383. if (isset($data['salary']) && $data['salary'] != null) {
  6384. $where['job_hunting.salary'] = $data['salary'];
  6385. }
  6386. if (isset($data['user_name']) && $data['user_name'] != null) {
  6387. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  6388. }
  6389. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  6390. $query->where('job_resume.user_id', $user['id']);
  6391. })
  6392. ->when(!empty($where), function ($query) use ($where) {
  6393. $query->where($where);
  6394. })
  6395. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  6396. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  6397. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  6398. ->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');
  6399. $count = $job->count();
  6400. if ($count == 0) {
  6401. return Result::error("暂无沟通记录", 0);
  6402. }
  6403. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  6404. ->offset(($data['page'] - 1) * $data['pageSize'])
  6405. ->limit($data['pageSize'])
  6406. ->get();
  6407. if (empty($jobs)) {
  6408. return Result::error("暂无沟通记录", 0);
  6409. }
  6410. $result['row'] = $this->processJob($jobs, '');
  6411. $result['count'] = $count;
  6412. return Result::success($result);
  6413. }
  6414. public function readJobResume(array $data): array
  6415. {
  6416. $result = JobResume::where('id', $data['id'])->first();
  6417. if (empty($result)) {
  6418. return Result::error("查询失败", 0);
  6419. }
  6420. $result = JobResume::where('id', $data['id'])->update([
  6421. 'status' => 2,
  6422. ]);
  6423. return Result::success($result);
  6424. }
  6425. // 20250306 招聘
  6426. //20250422 书刊音像
  6427. public function addBook(array $data): array
  6428. {
  6429. $user_id = $data['user_id'] ?? 0;
  6430. $type_id = $data['type_id'] ?? 0;
  6431. // $website_id = $data['website_id'] ?? 0;
  6432. // unset($data['user_id']);
  6433. unset($data['type_id']);
  6434. // unset($data['website_id']);
  6435. //处理数组
  6436. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6437. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6438. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6439. if ($data['img_url'] == '') {
  6440. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6441. preg_match_all($reg, $data['detail'], $matches);
  6442. if (isset($matches[1][0])) {
  6443. //截取varchar240
  6444. $data['img_url'] = substr($matches[1][0], 0, 240);
  6445. }
  6446. }
  6447. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  6448. //提取标题+内容中的关键词
  6449. $data['keyword'] = $data['title'];
  6450. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6451. Jieba::init(); // 初始化 jieba-php
  6452. Finalseg::init();
  6453. $segList = Jieba::cut($data['keyword']);
  6454. $segList1 = array_slice($segList, 0, 8);
  6455. $data['keyword'] = implode(',', $segList1);
  6456. }
  6457. if ($data['description'] == '') {
  6458. //提取内容中的描述
  6459. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6460. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6461. }
  6462. var_dump($data, '--');
  6463. if ($data['status'] == 1) {
  6464. $this->sendMessage([
  6465. 'talk_type' => 400,
  6466. 'title' => $data['title'],
  6467. 'content' => '提交了审核',
  6468. 'messageType' => 7,
  6469. ]);
  6470. }
  6471. $result = Book::insertGetId($data);
  6472. if (empty($result)) {
  6473. return Result::error("添加失败", 0);
  6474. }
  6475. return Result::success($result);
  6476. }
  6477. public function getBookList(array $data): array
  6478. {
  6479. $where = [];
  6480. if (!empty($data["title"])) {
  6481. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  6482. }
  6483. if (!empty($data['website_name'])) {
  6484. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  6485. }
  6486. if (!empty($data['status'])) {
  6487. $where[] = ['book.status', '=', $data['status']];
  6488. }
  6489. $user_id = $data['user_id'];
  6490. $type_id = $data['type_id'];
  6491. // $type_id = 4;
  6492. var_dump($type_id, '------1--------');
  6493. if ($type_id != 10000) {
  6494. $where[] = ['book.user_id', '=', $user_id];
  6495. }
  6496. var_dump(!empty($data['status1']), '=-===1');
  6497. $result = Book::where($where)
  6498. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  6499. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  6500. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  6501. ->when(isset($data['status1']), function ($query) use ($data) {
  6502. $query->whereIn('book.status', [1, 3]);
  6503. })
  6504. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  6505. ->orderBy("updated_at", "desc")
  6506. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  6507. if (empty($result)) {
  6508. return Result::error("暂无数据", 0);
  6509. }
  6510. // 取出数据
  6511. $rows = $result->items();
  6512. $count = $result->total();
  6513. $responseData = [
  6514. 'rows' => $rows,
  6515. 'count' => $count,
  6516. ];
  6517. return Result::success($responseData);
  6518. }
  6519. public function deleteBook(array $data): array
  6520. {
  6521. $result = Book::where('id', $data['id'])->delete();
  6522. if (empty($result)) {
  6523. return Result::error("删除失败", 0);
  6524. }
  6525. return Result::success($result);
  6526. }
  6527. public function updateBook(array $data): array
  6528. {
  6529. // $user_id = $data['user_id'] ?? 0;
  6530. $type_id = $data['type_id'] ?? 0;
  6531. // $website_id = $data['website_id'] ?? 0;
  6532. unset($data['user_id']);
  6533. unset($data['type_id']);
  6534. // unset($data['website_id']);
  6535. //处理数组
  6536. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6537. if ($data['img_url'] == '') {
  6538. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6539. preg_match_all($reg, $data['detail'], $matches);
  6540. if (isset($matches[1][0])) {
  6541. //截取varchar240
  6542. $data['img_url'] = substr($matches[1][0], 0, 240);
  6543. }
  6544. }
  6545. if ($data['keyword'] == '') {
  6546. //提取标题+内容中的关键词
  6547. $data['keyword'] = $data['title'];
  6548. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6549. Jieba::init(); // 初始化 jieba-php
  6550. Finalseg::init();
  6551. $segList = Jieba::cut($data['keyword']);
  6552. $segList1 = array_slice($segList, 0, 8);
  6553. $data['keyword'] = implode(',', $segList1);
  6554. }
  6555. if ($data['description'] == '') {
  6556. //提取内容中的描述
  6557. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6558. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6559. }
  6560. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6561. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6562. if ($data['status'] == 1) {
  6563. $this->sendMessage([
  6564. 'talk_type' => 400,
  6565. 'title' => $data['title'],
  6566. 'content' => '提交了审核',
  6567. 'messageType' => 7,
  6568. ]);
  6569. }
  6570. $result = Book::where("id", $data["id"])->update($data);
  6571. if (empty($result)) {
  6572. return Result::error("更新失败", 0);
  6573. }
  6574. return Result::success($result);
  6575. }
  6576. public function getBookInfo(array $data): array
  6577. {
  6578. $result = Book::where("id", $data["id"])->first();
  6579. if (empty($result)) {
  6580. return Result::error("获取失败", 0);
  6581. }
  6582. return Result::success($result);
  6583. }
  6584. public function updateBookStatus(array $data): array
  6585. {
  6586. //审核
  6587. unset($data['user_id']);
  6588. $bookInfo = Book::where("id", $data["id"])->first();
  6589. var_dump($bookInfo, '----');
  6590. if ($data['status'] == 2) {
  6591. $this->sendMessage([
  6592. 'talk_type' => 401,
  6593. 'title' => $bookInfo['title'],
  6594. 'content' => '审核通过',
  6595. 'messageType' => 7,
  6596. 'user_id' => $bookInfo['user_id'],
  6597. ]);
  6598. }
  6599. if ($data['status'] == 3) {
  6600. $this->sendMessage([
  6601. 'talk_type' => 401,
  6602. 'title' => $bookInfo['title'],
  6603. 'content' => '审核拒绝',
  6604. 'messageType' => 7,
  6605. 'user_id' => $bookInfo['user_id'],
  6606. ]);
  6607. }
  6608. if ($data['status'] == 1) {
  6609. $this->sendMessage([
  6610. 'talk_type' => 400,
  6611. 'title' => $bookInfo['title'],
  6612. 'content' => '提交了审核',
  6613. 'messageType' => 7,
  6614. // 'user_id'=>$bookInfo['user_id'],
  6615. ]);
  6616. }
  6617. $result = Book::where("id", $data["id"])->update($data);
  6618. if (empty($result)) {
  6619. return Result::error("更新失败", 0);
  6620. }
  6621. return Result::success($result);
  6622. }
  6623. //20250422 书刊音像
  6624. /**
  6625. * 贴身宝贝
  6626. * @param array $data
  6627. * @return array
  6628. */
  6629. public function getWebsiteTsbb(array $data): array
  6630. {
  6631. $month = $data['month'] ?? date('m');
  6632. $day = $data['day'] ?? date('d');
  6633. // 使用缓存键
  6634. $cacheKey = "tsbb_data_{$month}_{$day}";
  6635. // 尝试从缓存获取数据
  6636. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6637. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6638. if ($cachedData = $cache->get($cacheKey)) {
  6639. return Result::success(unserialize($cachedData));
  6640. }
  6641. //查询老黄历
  6642. try {
  6643. $date = date('Y-m-d');
  6644. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6645. // 使用 curl 替代 file_get_contents
  6646. $ch = curl_init();
  6647. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6648. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6649. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6650. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6651. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6652. 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');
  6653. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6654. 'Accept: application/json',
  6655. 'Content-Type: application/json',
  6656. 'Referer: https://www.36jxs.com/'
  6657. ]);
  6658. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6659. curl_setopt($ch, CURLOPT_ENCODING, '');
  6660. $almanacResponse = curl_exec($ch);
  6661. var_dump("====:", $almanacResponse);
  6662. if (curl_errno($ch)) {
  6663. var_dump('Curl error:', curl_error($ch));
  6664. throw new \Exception('Curl error: ' . curl_error($ch));
  6665. }
  6666. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6667. curl_close($ch);
  6668. if ($almanacResponse === false) {
  6669. throw new \Exception('Failed to fetch almanac data');
  6670. }
  6671. $almanacData = json_decode($almanacResponse, true);
  6672. if (json_last_error() !== JSON_ERROR_NONE) {
  6673. throw new \Exception('Failed to parse almanac data');
  6674. }
  6675. $almanacInfo = $almanacData['data'] ?? [];
  6676. } catch (\Exception $e) {
  6677. var_dump('Exception:', $e->getMessage());
  6678. $almanacInfo = [];
  6679. }
  6680. // 获取历史上的今天数据
  6681. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6682. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6683. ->orderBy('year', 'asc')
  6684. ->select("title", "id", "year", DB::raw('1 as type'))
  6685. ->limit(16)
  6686. ->get();
  6687. // 获取节日数据 - 从今天开始获取未来4条
  6688. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6689. ->orderBy('showtime', 'asc')
  6690. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6691. ->limit(16)
  6692. ->get();
  6693. //说文解字
  6694. $chartacterList = Character::orderBy('updated_at', 'desc')
  6695. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6696. ->limit(6)
  6697. ->get();
  6698. //谜语沙龙
  6699. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6700. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6701. ->limit(4)
  6702. ->get();
  6703. //成语欣赏
  6704. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6705. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6706. ->limit(32)
  6707. ->get();
  6708. //名联赏析
  6709. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6710. ->select("id", "first", "second", DB::raw('6 as type'))
  6711. ->limit(6)
  6712. ->get();
  6713. // 获取分类文章数据
  6714. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6715. ->pluck('category_id')
  6716. ->toArray();
  6717. $articlesList = [];
  6718. foreach ($categoryIds as $catid) {
  6719. // 先查有图片的
  6720. $withImg = DB::table('article')
  6721. ->where('status', 1)
  6722. ->where('catid', $catid)
  6723. ->whereNotNull('imgurl')
  6724. ->where('imgurl', '!=', '')
  6725. ->orderBy('updated_at', 'desc')
  6726. ->limit(6)
  6727. ->get();
  6728. $count = $withImg->count();
  6729. if ($count < 6) {
  6730. // 不足6条再查无图片的补足
  6731. $withoutImg = DB::table('article')
  6732. ->where('status', 1)
  6733. ->where('catid', $catid)
  6734. ->where(function ($q) {
  6735. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6736. })
  6737. ->orderBy('updated_at', 'desc')
  6738. ->limit(6 - $count)
  6739. ->get();
  6740. $articles = $withImg->concat($withoutImg);
  6741. } else {
  6742. $articles = $withImg;
  6743. }
  6744. // 组装
  6745. $category = \App\Model\Category::find($catid);
  6746. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6747. $articlesList[] = [
  6748. 'category_name' => $category ? $category->name : '',
  6749. 'catid' => $catid,
  6750. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6751. 'type' => 100,
  6752. 'list' => $articles->map(function ($item) {
  6753. return [
  6754. 'id' => $item->id,
  6755. 'title' => $item->title,
  6756. 'imgurl' => $item->imgurl,
  6757. 'created_at' => $item->created_at
  6758. ];
  6759. })->values()
  6760. ];
  6761. }
  6762. $result = [
  6763. 'almanac' => $almanacInfo,
  6764. 'historyTodayList' => [
  6765. 'category_name' => '历史上的今天',
  6766. 'list' => $historyTodayList,
  6767. 'type' => 1
  6768. ],
  6769. 'festivalList' => [
  6770. 'category_name' => '节日预告',
  6771. 'list' => $festivalList,
  6772. 'type' => 2
  6773. ],
  6774. 'chartacterList' => [
  6775. 'category_name' => '说文解字',
  6776. 'list' => $chartacterList,
  6777. 'type' => 3
  6778. ],
  6779. 'coupletList' => [
  6780. 'category_name' => '名联赏析',
  6781. 'list' => $coupletList,
  6782. 'type' => 6
  6783. ],
  6784. 'riddletList' => [
  6785. 'category_name' => '谜语沙龙',
  6786. 'list' => $riddletList,
  6787. 'type' => 4
  6788. ],
  6789. 'idiomList' => [
  6790. 'category_name' => '成语欣赏',
  6791. 'list' => $idiomList,
  6792. 'type' => 5
  6793. ],
  6794. 'articlesList' => $articlesList
  6795. ];
  6796. // 缓存结果,设置1小时过期
  6797. $cache->set($cacheKey, serialize($result), 3600);
  6798. return Result::success($result);
  6799. }
  6800. /**
  6801. * 获取资讯列表
  6802. */
  6803. public function getWebsiteTsbbList(array $data): array
  6804. {
  6805. $page = $data['page'] ?? 1;
  6806. $pageSize = $data['pageSize'] ?? 10;
  6807. // 如果没有传入月份和日期,则使用今天的日期
  6808. $month = $data['month'] ?? date('m');
  6809. $day = $data['day'] ?? date('d');
  6810. $total = 0;
  6811. $result = [];
  6812. $data['type'] = intval($data['type']);
  6813. var_dump("接收参数:", $data);
  6814. switch ($data['type']) {
  6815. case 1:
  6816. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6817. // 当前月份之后的数据
  6818. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6819. // 或者当前月份且日期大于等于当前日期的数据
  6820. ->orWhere(function ($q) use ($month, $day) {
  6821. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6822. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6823. });
  6824. })
  6825. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6826. $total = $query->count();
  6827. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6828. ->offset(($page - 1) * $pageSize)
  6829. ->limit($pageSize)
  6830. ->get();
  6831. break;
  6832. case 2:
  6833. $query = Festival::where(function ($q) use ($month, $day) {
  6834. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6835. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6836. ->orWhere(function ($q) use ($month, $day) {
  6837. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6838. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6839. });
  6840. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6841. $total = $query->count();
  6842. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6843. ->offset(($page - 1) * $pageSize)
  6844. ->limit($pageSize)
  6845. ->get();
  6846. break;
  6847. case 3:
  6848. $query = Character::orderBy("updated_at", "desc");
  6849. $total = $query->count();
  6850. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6851. ->offset(($page - 1) * $pageSize)
  6852. ->limit($pageSize)
  6853. ->get();
  6854. break;
  6855. case 4:
  6856. $query = Riddle::orderBy("updated_at", "desc");
  6857. $total = $query->count();
  6858. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6859. ->offset(($page - 1) * $pageSize)
  6860. ->limit($pageSize)
  6861. ->get();
  6862. break;
  6863. case 5:
  6864. $query = Idiom::orderBy("updated_at", "desc");
  6865. $total = $query->count();
  6866. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6867. ->offset(($page - 1) * $pageSize)
  6868. ->limit($pageSize)
  6869. ->get();
  6870. break;
  6871. case 6:
  6872. $query = Couplet::orderBy("updated_at", "desc");
  6873. $total = $query->count();
  6874. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6875. ->offset(($page - 1) * $pageSize)
  6876. ->limit($pageSize)
  6877. ->get();
  6878. break;
  6879. default:
  6880. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6881. $total = $query->count();
  6882. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6883. ->offset(($page - 1) * $pageSize)
  6884. ->limit($pageSize)
  6885. ->get();
  6886. }
  6887. return Result::success([
  6888. 'list' => $result,
  6889. 'total' => $total,
  6890. 'page' => (int)$page,
  6891. 'pageSize' => (int)$pageSize,
  6892. 'month' => $month,
  6893. 'day' => $day
  6894. ]);
  6895. }
  6896. /**
  6897. * 1:历史上的今天
  6898. * 2:节日
  6899. * 3:文章
  6900. *
  6901. * 资讯详情信息
  6902. */
  6903. public function getWebsiteTsbbDetail(array $data): array
  6904. {
  6905. $data['type'] = intval($data['type']);
  6906. switch ($data['type']) {
  6907. case 1:
  6908. $result = HistoryToday::where("id", $data['id'])->first();
  6909. break;
  6910. case 2:
  6911. $result = Festival::where("id", $data['id'])->first();
  6912. break;
  6913. case 3:
  6914. $result = Character::where("id", $data['id'])->first();
  6915. break;
  6916. case 4:
  6917. $result = Riddle::where("id", $data['id'])->first();
  6918. break;
  6919. case 5:
  6920. $result = Idiom::where("id", $data['id'])->first();
  6921. break;
  6922. case 6:
  6923. $result = Couplet::where("id", $data['id'])->first();
  6924. break;
  6925. default:
  6926. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6927. break;
  6928. }
  6929. return Result::success($result);
  6930. }
  6931. /**
  6932. * 农网导航首页数据
  6933. */
  6934. public function getWebsiteNwHomeList(array $data): array
  6935. {
  6936. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6937. ->pluck('category_id')
  6938. ->toArray();
  6939. // 使用子查询优化
  6940. $articlesList = DB::table('article')
  6941. ->select([
  6942. 'article.id',
  6943. 'article.title',
  6944. 'article.imgurl',
  6945. 'article.created_at',
  6946. 'category.name as category_name',
  6947. 'category.id as category_id',
  6948. 'website_category.aLIas_pinyin as pinyin',
  6949. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6950. DB::raw('100 as type')
  6951. ])
  6952. ->join('category', 'article.catid', '=', 'category.id')
  6953. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6954. ->leftJoin('website_category as parent_wc', function ($join) {
  6955. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6956. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6957. })
  6958. ->where('website_category.website_id', $data['website_id'])
  6959. ->where('article.status', 1)
  6960. ->whereIn('category.id', $categoryIds)
  6961. ->orderBy('article.created_at', 'desc')
  6962. ->get()
  6963. ->groupBy('category_id')
  6964. ->map(function ($group) {
  6965. // 确保第一条数据有图片
  6966. $firstWithImage = $group->first(function ($item) {
  6967. return !empty($item->imgurl);
  6968. });
  6969. if ($firstWithImage) {
  6970. // 如果有带图片的文章,将其放在第一位
  6971. $group = $group->filter(function ($item) use ($firstWithImage) {
  6972. return $item->id !== $firstWithImage->id;
  6973. })->prepend($firstWithImage);
  6974. }
  6975. return [
  6976. 'category_name' => $group->first()->category_name,
  6977. 'catid' => $group->first()->category_id,
  6978. 'pinyin' => $group->first()->pinyin,
  6979. 'parent_pinyin' => $group->first()->parent_pinyin,
  6980. 'list' => $group->take(4)->map(function ($item) {
  6981. return [
  6982. 'id' => $item->id,
  6983. 'title' => $item->title,
  6984. ];
  6985. })->values()
  6986. ];
  6987. })
  6988. ->values()
  6989. ->toArray();
  6990. return Result::success($articlesList);
  6991. }
  6992. /**
  6993. * 企业管理
  6994. * @param array $data
  6995. * @return array
  6996. */
  6997. public function getCompanyList(array $data): array
  6998. {
  6999. // return Result::success($data);
  7000. $where = [];
  7001. $user = User::where('id', $data['user_id'])->first();
  7002. if (empty($user)) {
  7003. return Result::error('用户不存在!');
  7004. }
  7005. if ($user['type_id'] != 10000) {
  7006. $where['user_id'] = $data['user_id'];
  7007. }
  7008. if (isset($data['title']) && !empty($data['title'])) {
  7009. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  7010. }
  7011. if (isset($data['website_id']) && !empty($data['website_id'])) {
  7012. array_push($where, ['website.id', $data['website_id']]);
  7013. }
  7014. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  7015. if ($data['ischeck'] == 1) {
  7016. if (isset($data['status']) && $data['status'] != '') {
  7017. array_push($where, ['company.status', $data['status']]);
  7018. $query = Company::where($where);
  7019. } else {
  7020. $query = Company::whereIn('company.status', [0, 2]);
  7021. }
  7022. } else {
  7023. $query = Company::where('company.status', 1);
  7024. }
  7025. }
  7026. $result = $query->where($where)
  7027. ->leftJoin('website_category', function ($query) {
  7028. $query->on('website_category.category_id', '=', 'company.category_id')
  7029. ->on('website_category.website_id', '=', 'company.website_id');
  7030. })
  7031. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  7032. ->select(
  7033. 'company.id',
  7034. 'company.title',
  7035. 'company.website_id',
  7036. 'company.category_id',
  7037. 'website.website_name',
  7038. 'website_category.alias as category_name',
  7039. 'company.status',
  7040. 'company.updated_at',
  7041. 'company.user_id'
  7042. )
  7043. ->orderBy('company.updated_at', 'desc')
  7044. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7045. if ($result->isEmpty()) {
  7046. return Result::error("暂无企业", 0);
  7047. }
  7048. return Result::success($result);
  7049. }
  7050. /**
  7051. * 添加企业
  7052. * @param array $data
  7053. * @return array
  7054. */
  7055. public function addCompany(array $data): array
  7056. {
  7057. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  7058. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  7059. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  7060. $data['cat_arr_id'] = json_encode($car_arr_id);
  7061. } else {
  7062. $data['cat_arr_id'] = '';
  7063. }
  7064. if ($data['imgurl'] == '') {
  7065. //content中提取图片第一个图,正则提取
  7066. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7067. preg_match_all($reg, $data['content'], $matches);
  7068. if (isset($matches[1][0])) {
  7069. //截取varchar240
  7070. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7071. }
  7072. }
  7073. if ($data['keyword'] == '') {
  7074. //提取标题+内容中的关键词
  7075. $data['keyword'] = $data['title'];
  7076. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7077. Jieba::init(); // 初始化 jieba-php
  7078. Finalseg::init();
  7079. $segList = Jieba::cut($data['keyword']);
  7080. $segList1 = array_slice($segList, 0, 8);
  7081. $data['keyword'] = implode(',', $segList1);
  7082. }
  7083. if ($data['introduce'] == '' || empty($data['introduce'])) {
  7084. //提取内容中的描述
  7085. $content = $data['content'];
  7086. // 去除 <style> 和 <script> 标签及其内容
  7087. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7088. // 去除所有 HTML 标签
  7089. $content = strip_tags($content);
  7090. // 去除 HTML 实体
  7091. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7092. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7093. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7094. // 去除多余空白
  7095. $content = preg_replace('/\s+/u', '', $content);
  7096. // 截取 100 个字符
  7097. $data['introduce'] = mb_substr($content, 0, 100);
  7098. }
  7099. $user = User::where('id', $data['user_id'])->first();
  7100. if (empty($user)) {
  7101. return Result::error('用户不存在!');
  7102. }
  7103. if ($user['type_id'] == 10000) {
  7104. $data['status'] = 1;
  7105. }
  7106. if (isset($data['level']) && $data['level'] != null) {
  7107. $data['level'] = intval($data['level']);
  7108. } else {
  7109. $data['level'] = null;
  7110. }
  7111. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7112. $this->sendMessage([
  7113. 'talk_type' => 900,
  7114. 'title' => $data['title'],
  7115. 'content' => '提交了审核',
  7116. 'messageType' => 8,
  7117. ]);
  7118. }
  7119. $result = Company::insertGetId($data);
  7120. if ($result) {
  7121. return Result::success($result);
  7122. } else {
  7123. return Result::error('添加失败');
  7124. }
  7125. }
  7126. /**
  7127. * 更新企业
  7128. * @param array $data
  7129. * @return array
  7130. */
  7131. public function upCompany(array $data): array
  7132. {
  7133. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  7134. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  7135. $data['cat_arr_id'] = json_encode($car_arr_id);
  7136. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  7137. } else {
  7138. $data['cat_arr_id'] = '';
  7139. }
  7140. if ($data['imgurl'] == '') {
  7141. //content中提取图片第一个图,正则提取
  7142. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7143. preg_match_all($reg, $data['content'], $matches);
  7144. if (isset($matches[1][0])) {
  7145. //截取varchar
  7146. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7147. }
  7148. }
  7149. if ($data['keyword'] == '') {
  7150. //提取标题+内容中的关键词
  7151. $data['keyword'] = $data['title'];
  7152. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7153. Jieba::init(); // 初始化 jieba-php
  7154. Finalseg::init();
  7155. $segList = Jieba::cut($data['keyword']);
  7156. $segList1 = array_slice($segList, 0, 8);
  7157. $data['keyword'] = implode(',', $segList1);
  7158. }
  7159. if ($data['introduce'] == '') {
  7160. //提取内容中的描述
  7161. $content = $data['content'];
  7162. // 去除 <style> 和 <script> 标签及其内容
  7163. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7164. // 去除所有 HTML 标签
  7165. $content = strip_tags($content);
  7166. // 去除 HTML 实体
  7167. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7168. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7169. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7170. // 去除多余空白
  7171. $content = preg_replace('/\s+/u', '', $content);
  7172. // 截取 100 个字符
  7173. $data['introduce'] = mb_substr($content, 0, 100);
  7174. }
  7175. if (isset($data['level']) && $data['level'] != null) {
  7176. $data['level'] = intval($data['level']);
  7177. } else {
  7178. $data['level'] = null;
  7179. }
  7180. $user = User::where('id', $data['user_id'])->first();
  7181. if (empty($user)) {
  7182. return Result::error('用户不存在!');
  7183. }
  7184. if ($user['type_id'] == 10000) {
  7185. $data['status'] = 1;
  7186. } else {
  7187. $data['status'] = 0;
  7188. }
  7189. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7190. $this->sendMessage([
  7191. 'talk_type' => 900,
  7192. 'title' => $data['title'],
  7193. 'content' => '提交了审核',
  7194. 'messageType' => 8,
  7195. ]);
  7196. }
  7197. $result = Company::where('id', $data['id'])->update($data);
  7198. if ($result) {
  7199. return Result::success($result);
  7200. } else {
  7201. return Result::error('修改失败');
  7202. }
  7203. }
  7204. /**
  7205. * 删除企业
  7206. * @param array $data
  7207. * @return array
  7208. */
  7209. public function delCompany(array $data): array
  7210. {
  7211. $result = Company::where('id', $data['id'])->delete();
  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 checkCompany(array $data): array
  7224. {
  7225. $user = User::where('id', $data['user_id'])->first();
  7226. if (empty($user)) {
  7227. return Result::error('用户不存在!');
  7228. }
  7229. $company = Company::where('id', $data['id'])->first();
  7230. if (empty($company)) {
  7231. return Result::error('企业不存在!');
  7232. }
  7233. // 状态:0:未审核 1:已审核 2:已拒绝
  7234. if ($data['status'] == 2 || $data['status'] == '2') {
  7235. $this->sendMessage([
  7236. 'talk_type' => 901,
  7237. 'title' => $company['title'],
  7238. 'content' => '审核拒绝',
  7239. 'messageType' => 8,
  7240. 'user_id' => $company['user_id'],
  7241. ]);
  7242. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  7243. } else {
  7244. if ($data['status'] == 1) {
  7245. $this->sendMessage([
  7246. 'talk_type' => 901,
  7247. 'title' => $company['title'],
  7248. 'content' => '审核通过',
  7249. 'messageType' => 8,
  7250. 'user_id' => $company['user_id'],
  7251. ]);
  7252. } else if ($data['status'] == 0) {
  7253. $this->sendMessage([
  7254. 'talk_type' => 900,
  7255. 'title' => $company['title'],
  7256. 'content' => '提交了审核',
  7257. 'messageType' => 8,
  7258. ]);
  7259. }
  7260. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  7261. }
  7262. if (empty($result)) {
  7263. return Result::error('审核失败!');
  7264. } else {
  7265. return Result::success($result);
  7266. }
  7267. }
  7268. /**
  7269. * 获取企业信息
  7270. * @param array $data
  7271. * @return array
  7272. */
  7273. public function getCompanyInfo(array $data): array
  7274. {
  7275. $result = Company::where('id', $data['id'])->first();
  7276. $city_arr = json_decode($result['city_arr_id']);
  7277. $result['city_name'] = District::whereIn('id', $city_arr)
  7278. ->pluck('name')
  7279. ->implode('-');
  7280. if (empty($result)) {
  7281. return Result::error('企业不存在!');
  7282. } else {
  7283. return Result::success($result);
  7284. }
  7285. }
  7286. /**
  7287. * @param array $data
  7288. * @return array
  7289. */
  7290. public function getWebsiteCompany(array $data): array
  7291. {
  7292. $categorys = json_decode($data['id'], true);
  7293. $category_arr = $this->processArticlePro($data['website_id']);
  7294. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7295. $catiall = $category_arr['catiall'];
  7296. $categoryIds = $category_arr['categoryIds'];
  7297. // return Result::success($category_arr);
  7298. foreach ($categorys as $key => $value) {
  7299. if (array_key_exists('level', $value)) {
  7300. $parts = explode(',', $value['level']);
  7301. $level = $parts[0] ?? null;
  7302. $imgnum = $parts[1] ?? null;
  7303. $textnum = $parts[2] ?? null;
  7304. if (!empty($textnum) && $textnum > 0) {
  7305. $text_num = Company::where('level', $level)
  7306. ->whereIn('category_id', $categoryIds)
  7307. ->where('status', 1)
  7308. ->select(
  7309. 'company.id',
  7310. 'company.title',
  7311. 'company.description',
  7312. 'company.updated_at',
  7313. 'company.category_id',
  7314. 'company.cat_arr_id'
  7315. )
  7316. ->orderBy('updated_at', 'desc')
  7317. ->limit($textnum)
  7318. ->get()->all();
  7319. }
  7320. if (!empty($imgnum) && $imgnum > 0) {
  7321. $img_num = Company::where('level', $level)
  7322. ->whereIn('category_id', $categoryIds)
  7323. ->where('status', 1)
  7324. ->where('imgurl', '!=', '')
  7325. ->whereNotNull('imgurl')
  7326. ->select(
  7327. 'company.id',
  7328. 'company.title',
  7329. 'company.description',
  7330. 'company.updated_at',
  7331. 'company.imgurl as imgs',
  7332. 'company.category_id',
  7333. 'company.cat_arr_id'
  7334. )
  7335. ->orderBy('updated_at', 'desc')
  7336. ->limit($imgnum)
  7337. ->get()->all();
  7338. }
  7339. }
  7340. if (array_key_exists('id', $value)) {
  7341. $parts = explode(',', $value['id']);
  7342. $category_id = $parts[0] ?? null;
  7343. $imgnum = $parts[1] ?? null;
  7344. $textnum = $parts[2] ?? null;
  7345. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  7346. if (!empty($textnum) && $textnum > 0) {
  7347. $text_num = Company::whereIn('category_id', $category_arr)
  7348. // ->where('website_id', $data['website_id'])
  7349. ->where('status', 1)
  7350. ->select(
  7351. 'company.id',
  7352. 'company.title',
  7353. 'company.description',
  7354. 'company.updated_at',
  7355. 'company.category_id',
  7356. 'company.cat_arr_id'
  7357. )
  7358. ->orderBy('updated_at', 'desc')
  7359. ->limit($textnum)
  7360. ->get()->all();
  7361. }
  7362. if (!empty($imgnum) && $imgnum > 0) {
  7363. $img_num = Company::whereIn('category_id', $category_arr)
  7364. // ->where('website_id', $data['website_id'])
  7365. ->where('status', 1)
  7366. ->where('imgurl', '!=', '')
  7367. ->whereNotNull('imgurl')
  7368. ->select(
  7369. 'company.id',
  7370. 'company.title',
  7371. 'company.description',
  7372. 'company.updated_at',
  7373. 'company.imgurl as imgs',
  7374. 'company.category_id',
  7375. 'company.cat_arr_id'
  7376. )
  7377. ->orderBy('updated_at', 'desc')
  7378. ->limit($imgnum)
  7379. ->get()->all();
  7380. }
  7381. }
  7382. if (!empty($text_num)) {
  7383. foreach ($text_num as $k => $v) {
  7384. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7385. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7386. }
  7387. }
  7388. if (!empty($img_num)) {
  7389. foreach ($img_num as $k => $v) {
  7390. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7391. $imgurl = json_decode($v['imgs'], true);
  7392. if (!empty($imgurl)) {
  7393. $img_num[$k]->imgurl = $imgurl[0];
  7394. }
  7395. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7396. }
  7397. }
  7398. $company[$key]['img_num'] = $img_num ?? [];
  7399. $company[$key]['text_num'] = $text_num ?? [];
  7400. }
  7401. if (empty($company)) {
  7402. return Result::error("暂无相关企业信息", 0);
  7403. }
  7404. return Result::success($company);
  7405. }
  7406. /**
  7407. * @param array $data
  7408. * @return array
  7409. */
  7410. public function getWebsiteCompanyList(array $data): array
  7411. {
  7412. $where['website_id'] = $data['website_id'];
  7413. $where['status'] = 1;
  7414. $categoryIds = [];
  7415. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7416. $category_id = $data['category_id'];
  7417. }
  7418. $category_arr = $this->processArticlePro($data['website_id']);
  7419. $categoryIds = $category_arr['categoryIds'];
  7420. // return Result::success($cat_1st_arr);
  7421. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  7422. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  7423. })
  7424. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  7425. $query->whereIn('category_id', $categoryIds);
  7426. })
  7427. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  7428. $query->where('category_id', $category_id);
  7429. })
  7430. ->where('status',1)
  7431. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  7432. ->orderBy('updated_at', 'desc')
  7433. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7434. if (empty($company)) {
  7435. return Result::error("暂无相关公司信息", 0);
  7436. }
  7437. $result = [
  7438. 'count' => $company->total(),
  7439. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  7440. ];
  7441. return Result::success($result);
  7442. }
  7443. /**
  7444. * 获取项目列表
  7445. * @param array $data
  7446. * @return array
  7447. */
  7448. public function getProjectList(array $data): array
  7449. {
  7450. $where = [];
  7451. $user = User::where('id', $data['user_id'])->first();
  7452. if (empty($user)) {
  7453. return Result::error('用户不存在!');
  7454. }
  7455. if ($user->type_id != 10000) {
  7456. array_push($where, ['project.user_id', $data['user_id']]);
  7457. }
  7458. $query = Project::query();
  7459. if (isset($data['website_id']) && !empty($data['website_id'])) {
  7460. array_push($where, ['project.website_id', $data['website_id']]);
  7461. }
  7462. if (isset($data['title']) && !empty($data['title'])) {
  7463. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  7464. }
  7465. if ($data['status'] != 3) {
  7466. array_push($where, ['project.status', $data['status']]);
  7467. }
  7468. $query = Project::where($where)
  7469. ->when($data['status'] == 3, function ($query) {
  7470. $query->whereIn('project.status', [0, 2]);
  7471. });
  7472. $count = $query->clone()
  7473. ->count();
  7474. $rows = $query->clone()
  7475. ->leftJoin('website', 'project.website_id', 'website.id')
  7476. ->leftJoin('website_category', function ($join) {
  7477. $join->on('project.website_id', '=', 'website_category.website_id')
  7478. ->on('project.category_id', '=', 'website_category.category_id');
  7479. })
  7480. ->select(
  7481. 'project.id',
  7482. 'project.title',
  7483. 'project.updated_at',
  7484. 'project.status',
  7485. 'website.website_name',
  7486. 'website_category.alias as category_name',
  7487. 'project.website_id',
  7488. 'project.user_id'
  7489. )
  7490. ->orderBy('project.updated_at', 'desc')
  7491. ->offset(($data['page'] - 1) * $data['pageSize'])
  7492. ->limit($data['pageSize'])
  7493. ->get();
  7494. if ($rows->isEmpty()) {
  7495. return Result::error("暂无相关项目信息", 0);
  7496. }
  7497. $result = [
  7498. 'count' => $count,
  7499. 'rows' => $rows,
  7500. ];
  7501. return Result::success($result);
  7502. }
  7503. /**
  7504. * 添加项目
  7505. * @param array $data
  7506. * @return array
  7507. */
  7508. public function addProject(array $data): array
  7509. {
  7510. $user = User::where('id', $data['user_id'])->first();
  7511. if (empty($user)) {
  7512. return Result::error("暂无相关用户信息", 0);
  7513. }
  7514. if ($user->type_id == 10000) {
  7515. $data['status'] = 1;
  7516. } else {
  7517. $data['status'] = 0;
  7518. }
  7519. if ($data['keyword'] == '') {
  7520. //提取标题+内容中的关键词
  7521. $data['keyword'] = $data['title'];
  7522. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7523. Jieba::init(); // 初始化 jieba-php
  7524. Finalseg::init();
  7525. $segList = Jieba::cut($data['keyword']);
  7526. $segList1 = array_slice($segList, 0, 8);
  7527. $data['keyword'] = implode(',', $segList1);
  7528. }
  7529. if ($data['description'] == '') {
  7530. //提取内容中的描述
  7531. // var_dump(11111);
  7532. //提取内容中的描述
  7533. $content = $data['introduce'];
  7534. // 去除 <style> 和 <script> 标签及其内容
  7535. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7536. // 去除所有 HTML 标签
  7537. $content = strip_tags($content);
  7538. // 去除 HTML 实体
  7539. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7540. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7541. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7542. // 去除多余空白
  7543. $content = preg_replace('/\s+/u', '', $content);
  7544. // 截取 100 个字符
  7545. $data['description'] = mb_substr($content, 0, 100);
  7546. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7547. }
  7548. if ($data['status'] == 0) {
  7549. $this->sendMessage([
  7550. 'talk_type' => 1000,
  7551. 'title' => $data['title'],
  7552. 'content' => '提交了审核',
  7553. 'messageType' => 9,
  7554. ]);
  7555. }
  7556. $project = Project::insertGetId($data);
  7557. if (empty($project)) {
  7558. return Result::error("暂无相关项目信息", 0);
  7559. }
  7560. return Result::success($project);
  7561. }
  7562. /**
  7563. * 更新项目
  7564. * @param array $data
  7565. * @return array
  7566. */
  7567. public function upProject(array $data): array
  7568. {
  7569. $project = Project::where('id', $data['id'])->first();
  7570. if (empty($project)) {
  7571. return Result::error("暂无相关项目信息", 0);
  7572. }
  7573. $id = $data['id'];
  7574. unset($data['id']);
  7575. $user = User::where('id', $data['user_id'])->first();
  7576. if (empty($user)) {
  7577. return Result::error("暂无相关用户信息", 0);
  7578. }
  7579. if ($user->type_id == 10000) {
  7580. $data['status'] = 1;
  7581. } else {
  7582. $data['status'] = 0;
  7583. }
  7584. unset($data['user_id']);
  7585. if ($data['keyword'] == '') {
  7586. //提取标题+内容中的关键词
  7587. $data['keyword'] = $data['title'];
  7588. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7589. Jieba::init(); // 初始化 jieba-php
  7590. Finalseg::init();
  7591. $segList = Jieba::cut($data['keyword']);
  7592. $segList1 = array_slice($segList, 0, 8);
  7593. $data['keyword'] = implode(',', $segList1);
  7594. }
  7595. if ($data['description'] == '') {
  7596. //提取内容中的描述
  7597. // var_dump(11111);
  7598. //提取内容中的描述
  7599. $content = $data['introduce'];
  7600. // 去除 <style> 和 <script> 标签及其内容
  7601. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7602. // 去除所有 HTML 标签
  7603. $content = strip_tags($content);
  7604. // 去除 HTML 实体
  7605. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7606. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7607. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7608. // 去除多余空白
  7609. $content = preg_replace('/\s+/u', '', $content);
  7610. // 截取 100 个字符
  7611. $data['description'] = mb_substr($content, 0, 100);
  7612. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7613. }
  7614. if ($data['status'] == 0) {
  7615. $this->sendMessage([
  7616. 'talk_type' => 1000,
  7617. 'title' => $data['title'],
  7618. 'content' => '提交了审核',
  7619. 'messageType' => 9,
  7620. ]);
  7621. }
  7622. $result = Project::where('id', $id)->update($data);
  7623. if (empty($result)) {
  7624. return Result::error("更新失败", 0);
  7625. }
  7626. return Result::success($result);
  7627. }
  7628. /**
  7629. * 删除项目
  7630. * @param array $data
  7631. * @return array
  7632. */
  7633. public function delProject(array $data): array
  7634. {
  7635. $user = User::where('id', $data['user_id'])->first();
  7636. if (empty($user)) {
  7637. return Result::error("暂无相关用户信息", 0);
  7638. }
  7639. $project = Project::where('id', $data['id'])->first();
  7640. if (empty($project)) {
  7641. return Result::error("暂无相关项目信息", 0);
  7642. }
  7643. $result = Project::where('id', $data['id'])->delete();
  7644. if (empty($result)) {
  7645. return Result::error("删除失败", 0);
  7646. }
  7647. return Result::success($result);
  7648. }
  7649. /**
  7650. * 审核项目
  7651. * @param array $data
  7652. * @return array
  7653. */
  7654. public function checkProject(array $data): array
  7655. {
  7656. $user = User::where('id', $data['user_id'])->first();
  7657. if (empty($user)) {
  7658. return Result::error("暂无相关用户信息", 0);
  7659. }
  7660. // 0:未审核; 1:已审核; 2:已拒绝;
  7661. if ($user->type_id != 10000) {
  7662. if ($data['status'] == 1 || $data['status'] == 2) {
  7663. return Result::error("此用户权限不足", 0);
  7664. }
  7665. }
  7666. $project = Project::where('id', $data['id'])->first();
  7667. if (empty($project)) {
  7668. return Result::error("暂无相关项目信息", 0);
  7669. }
  7670. if ($data['status'] == 2) {
  7671. $this->sendMessage([
  7672. 'talk_type' => 1001,
  7673. 'title' => $project['title'],
  7674. 'content' => '审核拒绝',
  7675. 'messageType' => 9,
  7676. 'user_id' => $project['user_id'],
  7677. ]);
  7678. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7679. } else {
  7680. if ($data['status'] == 1) {
  7681. $this->sendMessage([
  7682. 'talk_type' => 1001,
  7683. 'title' => $project['title'],
  7684. 'content' => '审核通过',
  7685. 'messageType' => 9,
  7686. 'user_id' => $project['user_id'],
  7687. ]);
  7688. } else if ($data['status'] == 0) {
  7689. $this->sendMessage([
  7690. 'talk_type' => 1000,
  7691. 'title' => $project['title'],
  7692. 'content' => '提交了审核',
  7693. 'messageType' => 9,
  7694. ]);
  7695. }
  7696. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7697. }
  7698. if (empty($result)) {
  7699. return Result::error("审核失败", 0);
  7700. }
  7701. return Result::success($result);
  7702. }
  7703. /**
  7704. * 获取项目详情
  7705. * @param array $data
  7706. * @return array
  7707. */
  7708. public function getProjectInfo(array $data): array
  7709. {
  7710. $project = Project::where('id', $data['id'])->first();
  7711. if (empty($project)) {
  7712. return Result::error("暂无相关项目信息", 0);
  7713. }
  7714. return Result::success($project);
  7715. }
  7716. public function getWebsiteCompanyInfo(array $data): array
  7717. {
  7718. $company = Company::where('id', $data['id'])
  7719. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7720. ->where('status', 1)
  7721. // ->where('website_id', $data['website_id'])
  7722. ->select('company.*', 'job_industry.hyname as hy_name')
  7723. ->first();
  7724. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7725. $jobnature_id = $company['jobnature_id'] ?? null;
  7726. if ($jobnature_id !== null) {
  7727. switch ($jobnature_id) {
  7728. case 0:
  7729. $company->jobnature_name = '市场监督';
  7730. break;
  7731. case 1:
  7732. $company->jobnature_name = '信访纪检';
  7733. break;
  7734. case 2:
  7735. $company->jobnature_name = '公检法司';
  7736. break;
  7737. case 3:
  7738. $company->jobnature_name = '高关注机构';
  7739. break;
  7740. default:
  7741. $company->jobnature_name = '';
  7742. break;
  7743. }
  7744. } else {
  7745. $company->jobnature_name = '';
  7746. }
  7747. $city_arr = $company->city_arr_id;
  7748. if (!empty($city_arr)) {
  7749. $city_arr = json_decode($city_arr, true);
  7750. $cityNames = District::whereIn('id', $city_arr)
  7751. ->pluck('name')
  7752. ->implode('-');
  7753. $company->city_name = $cityNames;
  7754. } else {
  7755. $company->city_name = '';
  7756. }
  7757. if (empty($company)) {
  7758. return Result::error("暂无相关公司信息", 0);
  7759. }
  7760. return Result::success($company);
  7761. }
  7762. public function getMSG(array $data): array
  7763. {
  7764. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7765. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7766. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7767. $result = [];
  7768. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7769. //最近的5篇已审的文章
  7770. $apply_articale = Article::where('status', 1)
  7771. ->where('admin_user_id', $user_id)
  7772. ->orderBy('updated_at', 'desc')
  7773. // ->limit(5)
  7774. ->get();
  7775. //获取5条用户的已审核商品
  7776. $good = Good::where('status', 2)
  7777. ->where('user_id', $user_id)
  7778. ->orderBy('updated_at', 'desc')
  7779. // ->limit(5)
  7780. ->get();
  7781. //获取5条用户待审核的公告
  7782. $notice = Notice::where('status', 2)
  7783. ->where('user_id', $user_id)
  7784. ->orderBy('updated_at', 'desc')
  7785. ->limit(5)->get();
  7786. //获取5条用户的待审核投诉
  7787. $complaint = Complaint::where('status', 2)
  7788. ->where('user_id', $user_id)
  7789. ->orderBy('updated_at', 'desc')
  7790. // ->limit(5)
  7791. ->get();
  7792. //获取5条用户的book
  7793. $book = Book::where('status', 2)
  7794. ->where('user_id', $user_id)
  7795. ->orderBy('updated_at', 'desc')
  7796. // ->limit(5)
  7797. ->get();
  7798. //获取5条用户的求职
  7799. //获取5条用户的求职 1
  7800. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7801. ->where('job_hunting.user_id', $user_id)
  7802. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7803. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7804. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7805. ->orderBy('updated_at', 'desc')
  7806. // ->limit(5)
  7807. ->get();
  7808. //获取5条用户的求职 2
  7809. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7810. ->where('job_recruiting.user_id', $user_id)
  7811. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7812. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7813. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7814. ->orderBy('updated_at', 'desc')
  7815. // ->limit(5)
  7816. ->get();
  7817. //人才库 1
  7818. $job_apply = JobApply::where('job_apply.status', 1)
  7819. ->where('job_apply.receiver_id', $user_id)
  7820. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7821. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7822. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7823. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7824. ->select('job_recruiting', 'job_recruiting.', '', '')
  7825. ->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')
  7826. ->orderBy('updated_at', 'desc')
  7827. // ->limit(5)
  7828. ->get();
  7829. // 职场机会 2
  7830. $job_resume = JobResume::where('job_resume.status', 1)
  7831. ->where('job_resume.receiver_id', $user_id)
  7832. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7833. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7834. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7835. ->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')
  7836. ->orderBy('updated_at', 'desc')
  7837. // ->limit(5)
  7838. ->get();
  7839. //获取5条用户待处理的投诉
  7840. $complaint_deal = Complaint::where('status', 2)
  7841. ->where('deal', 1)
  7842. ->whereJsonContains('re_user_ids', $user_id)
  7843. ->orderBy('updated_at', 'desc')
  7844. // ->limit(5)
  7845. ->get();
  7846. //获取 被通知者未读信息
  7847. $notice_unread = Notice::where('status', 2)
  7848. ->whereJsonContains('re_user_ids', $user_id)
  7849. //未读消息
  7850. ->where(function ($query) use ($user_id) {
  7851. $query->whereJsonDoesntContain('read_id', $user_id)
  7852. ->orWhereNull('read_id');
  7853. })
  7854. ->orderBy('updated_at', 'desc')
  7855. ->get();
  7856. $complaint_unread = Complaint::where('status', 2)
  7857. ->whereJsonContains('re_user_ids', $user_id)
  7858. //未读消息
  7859. ->where(function ($query) use ($user_id) {
  7860. $query->whereJsonDoesntContain('read_id', $user_id)
  7861. ->orWhereNull('read_id');
  7862. })
  7863. ->orderBy('updated_at', 'desc')
  7864. ->get();
  7865. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7866. $complany = Company::where('status', 1)
  7867. ->where('user_id', $user_id)
  7868. ->orderBy('updated_at', 'desc')
  7869. // ->limit(5)
  7870. ->get();
  7871. //获取5条单聊未读聊天消息
  7872. // $chat = ChatRecords::where('is_read', 0)
  7873. // ->where('user_id', $user_id)
  7874. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7875. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7876. // ->where('action', 'recieved')
  7877. // ->where('talk_type', 1)
  7878. // ->orderBy('created_at', 'desc')
  7879. // // ->limit(5)
  7880. // ->get();
  7881. //获取5条未读群聊信息
  7882. // $chat_group = ChatRecords::where('is_read', 0)
  7883. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7884. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7885. // ->where('user_id', $user_id)
  7886. // ->where('talk_type', 2)
  7887. // ->orderBy('created_at', 'desc')
  7888. // // ->limit(5)
  7889. // ->get();
  7890. //获取5条用户的待审核项目
  7891. $project = Project::where('status', 1)
  7892. ->where('user_id', $user_id)
  7893. ->orderBy('updated_at', 'desc')
  7894. // ->limit(5)
  7895. ->get();
  7896. // count($chat) + count($chat_group) +
  7897. $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)
  7898. + count($complany)
  7899. + count($project)
  7900. + count($notice_unread)
  7901. + count($complaint_unread)
  7902. // + count($chat) + count($chat_group)
  7903. ;
  7904. $result = [
  7905. 'apply_articale' => $apply_articale,
  7906. // 'chat' => $chat,
  7907. // 'chat_group' => $chat_group,
  7908. 'good' => $good,
  7909. 'notice' => $notice,
  7910. 'complaint' => $complaint,
  7911. 'book' => $book,
  7912. 'job_hunting' => $job_hunting,
  7913. 'job_recruiting' => $job_recruiting,
  7914. 'job_apply' => $job_apply,
  7915. 'job_resume' => $job_resume,
  7916. 'complaint_deal' => $complaint_deal,
  7917. 'complany' => $complany,
  7918. 'project' => $project,
  7919. 'notice_unread' => $notice_unread,
  7920. 'complaint_unread' => $complaint_unread,
  7921. 'count' => $count,
  7922. ];
  7923. } elseif ($type_id == 12) {
  7924. //最近的5篇已审的文章
  7925. $apply_articale = Article::where('status', 1)
  7926. ->where('admin_user_id', $user_id)
  7927. ->limit(5)->get();
  7928. //获取5条单聊未读聊天消息
  7929. $chat = ChatRecords::where('is_read', 0)
  7930. ->where('user_id', $user_id)
  7931. ->where('talk_type', 1)
  7932. ->orderBy('created_at', 'desc')
  7933. ->limit(5)->get();
  7934. //获取5条未读群聊信息
  7935. $chat_group = ChatRecords::where('is_read', 0)
  7936. ->where('user_id', $user_id)
  7937. ->where('talk_type', 2)
  7938. ->orderBy('created_at', 'desc')
  7939. ->limit(5)->get();
  7940. //获取5条用户的已审核商品
  7941. $good = Good::where('status', 2)
  7942. ->where('user_id', $user_id)
  7943. ->orderBy('updated_at', 'desc')
  7944. ->limit(5)->get();
  7945. //获取5条用户的book
  7946. $book = Book::where('status', 2)
  7947. ->where('user_id', $user_id)
  7948. ->orderBy('updated_at', 'desc')
  7949. ->limit(5)->get();
  7950. //获取5条用户的求职
  7951. //获取5条用户的求职 1
  7952. //count($chat) + count($chat_group)
  7953. $count = count($apply_articale) + count($good);
  7954. $result = [
  7955. 'apply_articale' => $apply_articale,
  7956. 'chat' => $chat,
  7957. 'chat_group' => $chat_group,
  7958. 'good' => $good,
  7959. 'book' => $book,
  7960. 'count' => $count,
  7961. ];
  7962. } elseif ($type_id == 13) {
  7963. //最近的5篇已审的文章
  7964. $apply_articale = Article::where('status', 1)
  7965. ->where('admin_user_id', $user_id)
  7966. ->limit(5)->get();
  7967. //获取5条单聊未读聊天消息
  7968. $chat = ChatRecords::where('is_read', 0)
  7969. ->where('user_id', $user_id)
  7970. ->where('talk_type', 1)
  7971. ->orderBy('created_at', 'desc')
  7972. ->limit(5)->get();
  7973. //获取5条未读群聊信息
  7974. $chat_group = ChatRecords::where('is_read', 0)
  7975. ->where('user_id', $user_id)
  7976. ->where('talk_type', 2)
  7977. ->orderBy('created_at', 'desc')
  7978. ->limit(5)->get();
  7979. //获取5条用户的已审核商品
  7980. $good = Good::where('status', 2)
  7981. ->where('user_id', $user_id)
  7982. ->orderBy('updated_at', 'desc')
  7983. ->limit(5)->get();
  7984. //count($chat) + count($chat_group) +
  7985. $count = count($apply_articale) + count($good);
  7986. $result = [
  7987. 'apply_articale' => $apply_articale,
  7988. 'chat' => $chat,
  7989. 'chat_group' => $chat_group,
  7990. 'good' => $good,
  7991. 'count' => $count,
  7992. ];
  7993. } elseif ($type_id == 14) {
  7994. //最近的5篇已审的文章
  7995. $apply_articale = Article::where('status', 1)
  7996. ->where('admin_user_id', $user_id)
  7997. // ->limit(5)
  7998. ->get();
  7999. //获取5条用户的已审核商品
  8000. $good = Good::where('status', 2)
  8001. ->where('user_id', $user_id)
  8002. ->orderBy('updated_at', 'desc')
  8003. // ->limit(5)
  8004. ->get();
  8005. $count = count($apply_articale) + count($good);
  8006. $result = [
  8007. 'apply_articale' => $apply_articale,
  8008. 'chat' => '',
  8009. 'chat_group' => '',
  8010. 'good' => $good,
  8011. 'count' => $count,
  8012. ];
  8013. } elseif ($type_id == 10000) {
  8014. //获取未审核的5篇文章
  8015. $apply_articale = Article::where('status', 0)
  8016. ->orderBy('updated_at', 'desc')
  8017. // ->limit(5)
  8018. ->get();
  8019. //获取5条单聊未读聊天消息
  8020. //获取5条单聊未读聊天消息
  8021. // $chat = ChatRecords::where('is_read', 0)
  8022. // ->where('user_id', $user_id)
  8023. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  8024. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  8025. // ->where('action', 'recieved')
  8026. // ->where('talk_type', 1)
  8027. // ->orderBy('created_at', 'desc')
  8028. // // ->limit(5)
  8029. // ->get();
  8030. // //获取5条未读群聊信息
  8031. // $chat_group = ChatRecords::where('is_read', 0)
  8032. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  8033. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  8034. // ->where('user_id', $user_id)
  8035. // ->where('talk_type', 2)
  8036. // ->orderBy('created_at', 'desc')
  8037. // // ->limit(5)
  8038. // ->get();
  8039. //获取5条用户的已审核商品
  8040. $good = Good::where('status', 1)
  8041. // ->where('user_id', $user_id)
  8042. ->orderBy('updated_at', 'desc')
  8043. // ->limit(5)
  8044. ->get();
  8045. //获取5条用户待审核的公告
  8046. $notice = Notice::where('status', 1)
  8047. ->orderBy('updated_at', 'desc')
  8048. // ->limit(5)
  8049. ->get();
  8050. //获取5条用户的待审核投诉
  8051. $complaint = Complaint::where('status', 1)
  8052. ->orderBy('updated_at', 'desc')
  8053. // ->limit(5)
  8054. ->get();
  8055. //获取5条用户的book
  8056. $book = Book::where('status', 1)
  8057. ->orderBy('updated_at', 'desc')
  8058. // ->limit(5)
  8059. ->get();
  8060. //获取5条用户的求职 1
  8061. $job_hunting = JobHunting::where('job_hunting.status', 1)
  8062. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  8063. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  8064. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  8065. ->orderBy('updated_at', 'desc')
  8066. // ->limit(5)
  8067. ->get();
  8068. //获取5条用户的求职 2
  8069. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  8070. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  8071. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  8072. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  8073. ->orderBy('updated_at', 'desc')
  8074. // ->limit(5)
  8075. ->get();
  8076. //人才库 1
  8077. $job_apply = JobApply::where('job_apply.status', 1)
  8078. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  8079. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  8080. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  8081. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  8082. ->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')
  8083. ->orderBy('updated_at', 'desc')
  8084. // ->limit(5)
  8085. ->get();
  8086. // 职场机会 2
  8087. $job_resume = JobResume::where('job_resume.status', 1)
  8088. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  8089. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  8090. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  8091. ->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')
  8092. ->orderBy('updated_at', 'desc')
  8093. // ->limit(5)
  8094. ->get();
  8095. //待审核数据com pro
  8096. $complany = Company::where('status', 0)
  8097. ->orderBy('updated_at', 'desc')
  8098. // ->limit(5)
  8099. ->get();
  8100. $project = Project::where('status', 0)
  8101. ->orderBy('updated_at', 'desc')
  8102. // ->limit(5)
  8103. ->get();
  8104. $count =
  8105. // count($chat) +
  8106. // count($chat_group) +
  8107. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  8108. // + count($job_apply)
  8109. // + count($job_resume)
  8110. + count($complany)
  8111. + count($project);
  8112. $result = [
  8113. 'apply_articale' => $apply_articale,
  8114. // 'chat' => $chat,
  8115. // 'chat_group' => $chat_group,
  8116. 'good' => $good,
  8117. 'notice' => $notice,
  8118. 'complaint' => $complaint,
  8119. 'book' => $book,
  8120. 'job_hunting' => $job_hunting,
  8121. 'job_recruiting' => $job_recruiting,
  8122. // 'job_apply' => $job_apply,
  8123. // 'job_resume' => $job_resume,
  8124. 'complany' => $complany,
  8125. 'project' => $project,
  8126. 'count' => $count,
  8127. ];
  8128. } elseif ($type_id == 20000) {
  8129. }
  8130. var_dump($type_id, '-----------------test---------');
  8131. return Result::success($result);
  8132. }
  8133. /**
  8134. * @param array $data
  8135. * @return array
  8136. */
  8137. public function getWebsiteProject(array $data): array
  8138. {
  8139. $categorys = json_decode($data['id'], true);
  8140. if (!empty($categorys)) {
  8141. $category_arr = $this->processArticlePro($data['website_id']);
  8142. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8143. $catiall = $category_arr['catiall'];
  8144. // return Result::success($catiall);
  8145. foreach ($categorys as $key => $val) {
  8146. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  8147. $level = explode(',', $val['level'])[0];
  8148. $imgnum = explode(',', $val['level'])[1] ?? null;
  8149. $textnum = explode(',', $val['level'])[2] ?? null;
  8150. if ($level == 1) {
  8151. if (!empty($textnum) && $textnum > 0) {
  8152. $text_num = Project::where('level', $level)
  8153. ->where('website_id', $data['website_id'])
  8154. ->where('status', 1)
  8155. ->select(
  8156. 'project.id',
  8157. 'project.title',
  8158. 'project.description',
  8159. 'project.updated_at',
  8160. 'project.category_id',
  8161. 'project.cat_arr_id'
  8162. )
  8163. ->orderBy('updated_at', 'desc')
  8164. ->limit($textnum)
  8165. ->get()->all();
  8166. }
  8167. if (!empty($imgnum) && $imgnum > 0) {
  8168. $img_num = Project::where('level', $level)
  8169. ->where('website_id', $data['website_id'])
  8170. ->where('status', 1)
  8171. ->where('imgurl', '!=', '')
  8172. ->whereNotNull('imgurl')
  8173. ->select(
  8174. 'project.id',
  8175. 'project.title',
  8176. 'project.description',
  8177. 'project.updated_at',
  8178. 'project.imgurl as imgs',
  8179. 'project.category_id',
  8180. 'project.cat_arr_id'
  8181. )
  8182. ->orderBy('updated_at', 'desc')
  8183. ->limit($imgnum)
  8184. ->get()->all();
  8185. }
  8186. } else {
  8187. if (!empty($textnum) && $textnum > 0) {
  8188. $text_num = Project::where('website_id', $data['website_id'])
  8189. ->where('status', 1)
  8190. ->select(
  8191. 'project.id',
  8192. 'project.title',
  8193. 'project.description',
  8194. 'project.updated_at',
  8195. 'project.category_id',
  8196. 'project.cat_arr_id',
  8197. 'project.website_id',
  8198. 'project.updated_at',
  8199. 'project.created_at'
  8200. )
  8201. ->orderBy('updated_at', 'desc')
  8202. ->limit($textnum)
  8203. ->get()->all();
  8204. }
  8205. if (!empty($imgnum) && $imgnum > 0) {
  8206. $img_num = Project::where('website_id', $data['website_id'])
  8207. ->where('status', 1)
  8208. ->where('imgurl', '!=', '')
  8209. ->whereNotNull('imgurl')
  8210. ->select(
  8211. 'project.id',
  8212. 'project.title',
  8213. 'project.description',
  8214. 'project.updated_at',
  8215. 'project.imgurl as imgs',
  8216. 'project.category_id',
  8217. 'project.cat_arr_id'
  8218. )
  8219. ->orderBy('updated_at', 'desc')
  8220. ->limit($imgnum)
  8221. ->get()->all();
  8222. }
  8223. }
  8224. }
  8225. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  8226. $category_ids = explode(',', $val['id'])[0];
  8227. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  8228. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  8229. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  8230. if (!empty($cat_textnum) && $cat_textnum > 0) {
  8231. $text_num = Project::whereIn('category_id', $category_arr)
  8232. ->where('website_id', $data['website_id'])
  8233. ->where('status', 1)
  8234. ->select(
  8235. 'project.id',
  8236. 'project.title',
  8237. 'project.description',
  8238. 'project.updated_at',
  8239. 'project.category_id',
  8240. 'project.cat_arr_id'
  8241. )
  8242. ->orderBy('updated_at', 'desc')
  8243. ->limit($cat_textnum)
  8244. ->get()->all();
  8245. }
  8246. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  8247. $img_num = Project::whereIn('category_id', $category_arr)
  8248. ->where('website_id', $data['website_id'])
  8249. ->where('status', 1)
  8250. ->where('imgurl', '!=', '')
  8251. ->whereNotNull('imgurl')
  8252. ->select(
  8253. 'project.id',
  8254. 'project.title',
  8255. 'project.description',
  8256. 'project.updated_at',
  8257. 'project.imgurl as imgs',
  8258. 'project.category_id',
  8259. 'project.cat_arr_id'
  8260. )
  8261. ->orderBy('updated_at', 'desc')
  8262. ->limit($cat_imgnum)
  8263. ->get()->all();
  8264. }
  8265. }
  8266. if (!empty($img_num)) {
  8267. foreach ($img_num as $k => $v) {
  8268. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8269. $imgurl = json_decode($v['imgs'], true);
  8270. if (!empty($imgurl)) {
  8271. $img_num[$k]->imgurl = $imgurl[0];
  8272. }
  8273. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8274. }
  8275. }
  8276. if (!empty($text_num)) {
  8277. foreach ($text_num as $k => $v) {
  8278. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8279. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8280. }
  8281. }
  8282. $project[$key]['img_num'] = $img_num ?? [];
  8283. $project[$key]['text_num'] = $text_num ?? [];
  8284. }
  8285. }
  8286. if (empty($project)) {
  8287. return Result::error("暂无相关项目信息", 0);
  8288. }
  8289. return Result::success($project);
  8290. }
  8291. /**
  8292. * @param array $data
  8293. * @return array
  8294. */
  8295. public function getWebsiteProjectInfo(array $data): array
  8296. {
  8297. $project = Project::where('id', $data['id'])
  8298. ->where('status', 1)
  8299. ->where('website_id', $data['website_id'])
  8300. ->select('project.*')
  8301. ->first();
  8302. if (empty($project)) {
  8303. return Result::error("暂无相关项目信息", 0);
  8304. }
  8305. return Result::success($project);
  8306. }
  8307. /**
  8308. * @param array $data
  8309. * @return array
  8310. */
  8311. public function getWebsiteProjectList(array $data): array
  8312. {
  8313. $where = [];
  8314. if (isset($data['category_id']) && !empty($data['category_id'])) {
  8315. $where['category_id'] = $data['category_id'];
  8316. }
  8317. if (isset($data['keyword']) && !empty($data['keyword'])) {
  8318. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  8319. }
  8320. $query = Project::where($where)
  8321. ->where('status', 1)
  8322. ->where('website_id', $data['website_id'])
  8323. ->select(
  8324. 'project.id',
  8325. 'project.title',
  8326. 'project.description',
  8327. 'project.imgurl as imgs',
  8328. 'project.category_id',
  8329. 'project.cat_arr_id'
  8330. )
  8331. ->orderBy('updated_at', 'desc');
  8332. $count = $query->count();
  8333. $project = $query->clone()
  8334. ->offset(($data['page'] - 1) * $data['pageSize'])
  8335. ->limit($data['pageSize'])
  8336. ->get()->all();
  8337. if (empty($project)) {
  8338. return Result::error("暂无相关项目信息", 0);
  8339. }
  8340. $categorys = $this->processArticlePro($data['website_id']);
  8341. $catiall = $categorys['catiall'];
  8342. foreach ($project as $key => $val) {
  8343. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  8344. if (!empty($val['imgs'])) {
  8345. $imgurl = json_decode($val['imgs'], true);
  8346. if (!empty($imgurl)) {
  8347. $project[$key]->imgurl = $imgurl[0];
  8348. }
  8349. } else {
  8350. $project[$key]->imgurl = '';
  8351. }
  8352. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  8353. }
  8354. $result = [
  8355. 'rows' => $project,
  8356. 'count' => $count,
  8357. ];
  8358. return Result::success($result);
  8359. }
  8360. /**
  8361. * @param array $data
  8362. * @return array
  8363. */
  8364. public function getWebsiteCategoryJob(array $data): array
  8365. {
  8366. $categorys = json_decode($data['id'], true);
  8367. if (!empty($categorys)) {
  8368. $category_arr = $this->processArticlePro($data['website_id']);
  8369. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8370. $catiall = $category_arr['catiall'];
  8371. foreach ($categorys as $key => $val) {
  8372. if (isset($val['id']) && !empty($val['id'])) {
  8373. $catid = explode(',', $val['id'])[0] ?? null;
  8374. $type = explode(',', $val['id'])[1] ?? null;
  8375. $textnum = explode(',', $val['id'])[2] ?? null;
  8376. }
  8377. // 4:招聘;5:求职;
  8378. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  8379. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  8380. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  8381. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  8382. ->where('job_recruiting.status', 1)
  8383. ->where('job_recruiting.website_id', $data['website_id'])
  8384. ->select(
  8385. 'job_recruiting.id',
  8386. 'job_recruiting.title',
  8387. 'job_company.business_name',
  8388. 'job_recruiting.updated_at',
  8389. 'job_recruiting.cat_arr_id',
  8390. 'job_recruiting.keyword',
  8391. 'job_recruiting.description'
  8392. )
  8393. ->orderBy('job_recruiting.updated_at', 'desc')
  8394. ->limit($textnum)
  8395. ->get()->all();
  8396. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  8397. // 状态 审核状态,1待审核2已审核3已拒绝
  8398. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  8399. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  8400. ->where('job_hunting.status', 2)
  8401. ->where('job_hunting.website_id', $data['website_id'])
  8402. ->select(
  8403. 'job_hunting.id',
  8404. 'job_hunting.name',
  8405. 'job_hunting.cat_arr_id',
  8406. 'job_position.zwname as job_name',
  8407. 'job_hunting.updated_at',
  8408. // 'job_hunting.keyword',
  8409. 'job_hunting.slelf_evaluation'
  8410. )
  8411. ->orderBy('updated_at', 'desc')
  8412. ->limit($textnum)
  8413. ->get()->all();
  8414. } else {
  8415. $job = [];
  8416. }
  8417. // var_dump($catid.'222uuuuuuu'.$key);
  8418. if (!empty($job)) {
  8419. foreach ($job as $k => $value) {
  8420. if (isset($value->cat_arr_id)) {
  8421. $catArr = json_decode($value->cat_arr_id, true);
  8422. $catId = end($catArr);
  8423. } else {
  8424. continue;
  8425. }
  8426. if (isset($catiall[$catId])) {
  8427. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  8428. }
  8429. }
  8430. }
  8431. // var_dump($catid.'xxxxx'.$key);
  8432. $result[$key] = $job ?? [];
  8433. }
  8434. }
  8435. if (empty($result)) {
  8436. return Result::error("暂无相关分类信息", 0);
  8437. }
  8438. return Result::success($result);
  8439. }
  8440. /**
  8441. * 发送消息
  8442. * @param array $messageData
  8443. * @return void
  8444. */
  8445. public function sendMessage($messageData)
  8446. {
  8447. $msg = [
  8448. 'talk_type' => $messageData['talk_type'],
  8449. 'title' => $messageData['title'],
  8450. 'content' => $messageData['content'],
  8451. 'messageType' => $messageData['messageType'],
  8452. 'user_id' => $messageData['user_id'] ?? '',
  8453. 'time' => microtime(),
  8454. ];
  8455. $message = new MqProducer($msg);
  8456. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  8457. $producer->produce($message);
  8458. }
  8459. /**
  8460. * 行业分类管理 ------1121
  8461. * @param array $data
  8462. * @return array
  8463. */
  8464. public function getJobIndustryList(array $data): array
  8465. {
  8466. $page = $data['page'] ?? 1;
  8467. $page_size = $data['page_size'] ?? 10;
  8468. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8469. $where = ['hyname', 'like', '%' . $data['hyname'] . '%'];
  8470. } else {
  8471. $where = [];
  8472. }
  8473. $rs_query = JobIndustry::when(!empty($where), function ($query) use ($where) {
  8474. $query->where([$where]); // 修复:将条件包装成二维数组
  8475. })
  8476. ->orderBy('updated_at', 'desc');
  8477. $count = $rs_query->count();
  8478. $hy = $rs_query->offset(($page - 1) * $page_size)->limit($page_size)->get()->all();
  8479. $result = [
  8480. 'count' => $count,
  8481. 'list' => $hy,
  8482. ];
  8483. if (empty($hy)) {
  8484. return Result::success('暂无数据');
  8485. }
  8486. return Result::success($result);
  8487. }
  8488. /**
  8489. * 添加行业分类
  8490. * @param array $data
  8491. * @return array
  8492. */
  8493. public function addJobIndustry(array $data): array
  8494. {
  8495. $hy_name = JobIndustry::where('hyname', $data['hyname'])->first(['hyid']);
  8496. if (!empty($hy_name)) {
  8497. return Result::error('行业分类已存在');
  8498. }
  8499. $hy = JobIndustry::insertGetId($data);
  8500. if (empty($hy)) {
  8501. return Result::error('添加失败');
  8502. }
  8503. return Result::success($hy);
  8504. }
  8505. /**
  8506. * 更新行业分类
  8507. * @param array $data
  8508. * @return array
  8509. */
  8510. public function upJobIndustry(array $data): array
  8511. {
  8512. $hy_query = JobIndustry::get();
  8513. $hy_ids = $hy_query->pluck('hyid')->toArray();
  8514. $hy_names = $hy_query->pluck('hyname')->toArray();
  8515. if (!in_array($data['hyid'], $hy_ids)) {
  8516. return Result::error('行业分类不存在');
  8517. }
  8518. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8519. $other_key_hy = array_search($data['hyid'], $hy_ids);
  8520. // return Result::success($other_key_hy);
  8521. unset($hy_names[$other_key_hy]);
  8522. if (in_array($data['hyname'], $hy_names)) {
  8523. return Result::error('行业分类名称已存在');
  8524. }
  8525. }
  8526. $hy = JobIndustry::where('hyid', $data['hyid'])->update($data);
  8527. if (empty($hy)) {
  8528. return Result::error('更新失败');
  8529. }
  8530. return Result::success($hy);
  8531. }
  8532. /**
  8533. * 删除行业分类
  8534. * @param array $data
  8535. * @return array
  8536. */
  8537. public function delJobIndustry(array $data): array
  8538. {
  8539. $hy_id = JobIndustry::where('hyid', $data['hyid'])->first(['hyid']);
  8540. if (empty($hy_id)) {
  8541. return Result::error('行业分类不存在');
  8542. }
  8543. $hy = JobIndustry::where('hyid', $data['hyid'])->delete();
  8544. if (empty($hy)) {
  8545. return Result::error('删除失败');
  8546. }
  8547. return Result::success($hy);
  8548. }
  8549. /**
  8550. * 职位分类-列表
  8551. * @param array $data
  8552. * @return array
  8553. */
  8554. public function getJobPositionList(array $data): array
  8555. {
  8556. $page = $data['page'] ?? 1;
  8557. $page_size = $data['page_size'] ?? 10;
  8558. $where = [];
  8559. if (isset($data['zwname']) && !empty($data['zwname'])) {
  8560. $zwids = JobPosition::where('zwpid', 0)
  8561. ->when(!empty($data['zwname']), function ($query) use ($data) {
  8562. $query->where('zwname', 'like', '%' . $data['zwname'] . '%');
  8563. })
  8564. ->orderBy('updated_at', 'desc')
  8565. ->pluck('zwid')
  8566. // ->get()
  8567. ->toArray();
  8568. }
  8569. if (isset($data['childname']) && !empty($data['childname'])) {
  8570. $child_zwids = JobPosition::where('zwpid', '!=', 0)
  8571. ->when(!empty($data['childname']), function ($query) use ($data) {
  8572. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8573. })
  8574. ->orderBy('updated_at', 'desc')
  8575. ->pluck('zwpid')
  8576. // ->get()
  8577. ->toArray();
  8578. if (isset($zwids) && is_array($zwids) && is_array($child_zwids)) {
  8579. $child_zwids = array_intersect($zwids, $child_zwids);
  8580. }
  8581. $zwids = array_values(array_unique($child_zwids));
  8582. }
  8583. $zwids = $zwids ?? null;
  8584. $count = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8585. $query->whereIn('zwid', $zwids);
  8586. })
  8587. ->where('zwpid', 0)
  8588. ->count();
  8589. $position = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8590. $query->whereIn('zwid', $zwids);
  8591. })
  8592. ->where('zwpid', 0)
  8593. ->orderBy('updated_at', 'desc')
  8594. ->offset(($page - 1) * $page_size)
  8595. ->limit($page_size)->get()
  8596. ->map(function ($item) use ($data) {
  8597. $item->children = $item->where('zwpid', $item->zwid)
  8598. ->when(!empty($data['childname']), function ($query) use ($data) {
  8599. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8600. })
  8601. ->orderBy('updated_at', 'desc')
  8602. ->get();
  8603. return $item;
  8604. })
  8605. ->all();
  8606. $result = [
  8607. 'count' => $count,
  8608. 'list' => $position,
  8609. ];
  8610. if (empty($result)) {
  8611. return Result::success('暂无数据');
  8612. }
  8613. return Result::success($result);
  8614. }
  8615. /**
  8616. * 职位分类-添加
  8617. * @param array $data
  8618. * @return array
  8619. */
  8620. public function addJobPosition(array $data): array
  8621. {
  8622. $zw_name = JobPosition::where('zwpid', $data['zwpid'])
  8623. ->where('zwname', $data['zwname'])->first(['zwid']);
  8624. if (!empty($zw_name)) {
  8625. return Result::error('职位分类已存在');
  8626. }
  8627. $zw = JobPosition::insertGetId($data);
  8628. if(empty($zw)){
  8629. return Result::error('添加失败');
  8630. }
  8631. return Result::success($zw);
  8632. }
  8633. /**
  8634. * 更新职位分类
  8635. * @param array $data
  8636. * @return array
  8637. */
  8638. public function upJobPosition(array $data): array
  8639. {
  8640. $zw_position = JobPosition::get();
  8641. if (!in_array($data['zwid'], $zw_position->pluck('zwid')->toArray())) {
  8642. return Result::error('职位分类不存在');
  8643. }
  8644. $zw_name = $zw_position->where('zwid', '!=', $data['zwid'])
  8645. ->where('zwpid', $data['zwpid'])
  8646. ->where('zwname', $data['zwname'])->first();
  8647. if (!empty($zw_name)) {
  8648. return Result::error('职位分类已存在');
  8649. }
  8650. $result = JobPosition::where('zwid', $data['zwid'])->update($data);
  8651. if (empty($result)) {
  8652. return Result::error('更新失败');
  8653. }
  8654. return Result::success($result);
  8655. }
  8656. /**
  8657. * 删除职位分类
  8658. * @param array $data
  8659. * @return array
  8660. */
  8661. public function delJobPosition(array $data): array
  8662. {
  8663. $zw_jobposition = JobPosition::get();
  8664. $zw_id = $zw_jobposition->where('zwid', $data['zwid'])->first();
  8665. if (empty($zw_id)) {
  8666. return Result::error('职位分类不存在');
  8667. }
  8668. if($zw_id->zwpid == 0){
  8669. $zw_job = JobPosition::where('zwpid', $zw_id->zwid)->first();
  8670. if(!empty($zw_job)){
  8671. return Result::error('请先删除子分类');
  8672. }
  8673. }
  8674. $result = JobPosition::where('zwid', $data['zwid'])->delete();
  8675. if (empty($result)) {
  8676. return Result::error('删除失败');
  8677. }
  8678. return Result::success($result);
  8679. }
  8680. /**
  8681. * 网民留言-添加
  8682. * @param array $data
  8683. * @return array
  8684. */
  8685. public function addMessage(array $data): array
  8686. {
  8687. $user = User::where('id', $data['user_id'])->first();
  8688. if (empty($user)) {
  8689. return Result::error('用户不存在');
  8690. }
  8691. if($user['type_id'] == 10000){
  8692. $data['status'] = 1;
  8693. }else{
  8694. $data['status'] = 0;
  8695. }
  8696. if ($data['keyword'] == '') {
  8697. //提取标题+内容中的关键词
  8698. $data['keyword'] = $data['title'];
  8699. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  8700. Jieba::init(); // 初始化 jieba-php
  8701. Finalseg::init();
  8702. $segList = Jieba::cut($data['keyword']);
  8703. $segList1 = array_slice($segList, 0, 8);
  8704. $data['keyword'] = implode(',', $segList1);
  8705. }
  8706. if ($data['description'] == '') {
  8707. //提取内容中的描述
  8708. $content = $data['content'];
  8709. // 去除 <style> 和 <script> 标签及其内容
  8710. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  8711. // 去除所有 HTML 标签
  8712. $content = strip_tags($content);
  8713. // 去除 HTML 实体
  8714. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  8715. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  8716. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  8717. // 去除多余空白
  8718. $content = preg_replace('/\s+/u', '', $content);
  8719. // 截取 100 个字符
  8720. $data['description'] = mb_substr($content, 0, 100);
  8721. }
  8722. if(!empty($data['reply'])){
  8723. $data['reply_userid'] = $data['user_id'];
  8724. }
  8725. $result = Message::insertGetId($data);
  8726. if(empty($result)){
  8727. return Result::error('添加失败');
  8728. }
  8729. return Result::success($result);
  8730. }
  8731. /**
  8732. * 网民留言-更新
  8733. * @param array $data
  8734. * @return array
  8735. */
  8736. public function upMessage(array $data): array
  8737. {
  8738. $user = User::where('id', $data['user_id'])->first();
  8739. if (empty($user)) {
  8740. return Result::error('用户不存在');
  8741. }
  8742. if($user['type_id'] == 10000){
  8743. $data['status'] = 1;
  8744. }else{
  8745. $data['status'] = 0;
  8746. }
  8747. $message = Message::where('id', $data['id'])->first();
  8748. if (empty($message)) {
  8749. return Result::error('留言不存在');
  8750. }
  8751. if($data['user_id'] != $message['user_id'] && $user['type_id'] != 10000){
  8752. return Result::error('非留言人不能更新');
  8753. }
  8754. if ($data['keyword'] == '') {
  8755. //提取标题+内容中的关键词
  8756. $data['keyword'] = $data['title'];
  8757. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  8758. Jieba::init(); // 初始化 jieba-php
  8759. Finalseg::init();
  8760. $segList = Jieba::cut($data['keyword']);
  8761. $segList1 = array_slice($segList, 0, 8);
  8762. $data['keyword'] = implode(',', $segList1);
  8763. }
  8764. if ($data['description'] == '') {
  8765. //提取内容中的描述
  8766. $content = $data['content'];
  8767. // 去除 <style> 和 <script> 标签及其内容
  8768. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  8769. // 去除所有 HTML 标签
  8770. $content = strip_tags($content);
  8771. // 去除 HTML 实体
  8772. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  8773. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  8774. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  8775. // 去除多余空白
  8776. $content = preg_replace('/\s+/u', '', $content);
  8777. // 截取 100 个字符
  8778. $data['description'] = mb_substr($content, 0, 100);
  8779. }
  8780. unset($data['id']);
  8781. if(!empty($data['reply'])){
  8782. $data['reply_userid'] = $data['user_id'];
  8783. unset($data['user_id']);
  8784. }
  8785. $result = Message::where('id', $message['id'])->update($data);
  8786. if (empty($result)) {
  8787. return Result::error('更新失败');
  8788. }
  8789. return Result::success($result);
  8790. }
  8791. /**
  8792. * 网民留言-删除
  8793. * @param array $data
  8794. * @return array
  8795. */
  8796. public function delMessage(array $data): array
  8797. {
  8798. $result = Message::where('id', $data['id'])->delete();
  8799. if (empty($result)) {
  8800. return Result::error('删除失败');
  8801. }
  8802. return Result::success($result);
  8803. }
  8804. /**
  8805. * 网民留言-更新状态
  8806. * @param array $data
  8807. * @return array
  8808. */
  8809. public function upMessageStatus(array $data): array
  8810. {
  8811. $message = Message::where('id', $data['id'])->first();
  8812. if (empty($message)) {
  8813. return Result::error('留言不存在!');
  8814. }
  8815. unset($data['id']);
  8816. unset($data['user_id']);
  8817. if($data['status'] != 2){
  8818. $data['reason'] = null;
  8819. }
  8820. $result = Message::where('id', $message['id'])->update($data);
  8821. if (empty($result)) {
  8822. return Result::error('留言更新失败!');
  8823. }
  8824. return Result::success($result);
  8825. }
  8826. /**
  8827. * 网民留言-获取详情
  8828. * @param array $data
  8829. * @return array
  8830. */
  8831. public function getMessageInfo(array $data): array
  8832. {
  8833. $result = Message::where('message.id', $data['id'])
  8834. ->leftJoin('website_column', 'message.column_id', '=', 'website_column.id')
  8835. ->select('message.*', 'website_column.column_arr_id')
  8836. ->first();
  8837. if (empty($result)) {
  8838. return Result::error('留言不存在!');
  8839. }
  8840. $result['column_arr_id'] = json_decode($result['column_arr_id'] ?? [], true);
  8841. return Result::success($result);
  8842. }
  8843. /**
  8844. * 网民留言-获取列表
  8845. * @param array $data
  8846. * @return array
  8847. */
  8848. public function getMessageList(array $data): array
  8849. {
  8850. $where = [];
  8851. if($data['is_master'] == 1){
  8852. $where['message.status'] = 1;
  8853. }else if($data['is_master'] == 2){
  8854. $where['message.status'] = 2;
  8855. }else if($data['is_master'] == 3){
  8856. $where['message.status'] = 0;
  8857. }
  8858. $user = User::where('id', $data['user_id'])->first();
  8859. if (empty($user)) {
  8860. return Result::error('用户不存在');
  8861. }
  8862. $column_arr_id = [];
  8863. if($user['type_id'] != 10000 && !empty($data['website_id'])){
  8864. $where['message.user_id'] = $data['user_id'];
  8865. $web = Website::where('id',$data['website_id'])->first('website_column_arr_id');
  8866. if(empty($web)){
  8867. return Result::error('此网站未关联任何网站属性!');
  8868. }
  8869. $column_arr_id = json_decode($web['website_column_arr_id'],true);
  8870. }
  8871. if(!empty($data['title'])){
  8872. array_push($where, ['message.title', 'like', '%'.$data['title'].'%']);
  8873. }
  8874. $result = Message::when($data['is_master'] == 0, function ($query) {
  8875. $query->whereIn('message.status', [0, 2]);
  8876. })
  8877. ->when(!empty($where), function ($query) use ($where) {
  8878. $query->where($where);
  8879. })
  8880. ->leftJoin('user', 'message.user_id', '=', 'user.id')
  8881. ->select('message.*', 'user.nickname')
  8882. ->orderBy('message.updated_at', 'desc')
  8883. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  8884. if(empty($result->items())) {
  8885. return Result::error('留言不存在!');
  8886. }
  8887. $result = [
  8888. 'data' => $result->items(),
  8889. 'count' => $result->total(),
  8890. ];
  8891. if(!empty($column_arr_id) && $user['type_id'] != 10000){
  8892. foreach($result['data'] as $key => $value){
  8893. if(in_array($value['column_id'], $column_arr_id)){
  8894. $result['data'][$key]['is_update'] = 1;
  8895. }else{
  8896. $result['data'][$key]['is_update'] = 0;
  8897. }
  8898. }
  8899. }
  8900. return Result::success($result);
  8901. }
  8902. /**
  8903. * 网民留言-检查是否可编辑
  8904. * @param array $data
  8905. * @return array
  8906. */
  8907. public function checkMessageEdit(array $data): array
  8908. {
  8909. $message = Message::where('id', $data['id'])->first();
  8910. if (empty($message)) {
  8911. return Result::error('留言不存在!');
  8912. }
  8913. $web = Website::where('id', $data['website_id'])->first();
  8914. if (empty($web)) {
  8915. return Result::error('网站不存在!');
  8916. }
  8917. $column_arr = json_decode($web['website_column_arr_id'] ?? [], true);
  8918. if(empty($column_arr)){
  8919. return Result::error('该网站未关联任何属性!');
  8920. }
  8921. if(!in_array($message['column_id'], $column_arr)){
  8922. return Result::error('不可编辑');
  8923. }
  8924. return Result::success('可编辑');
  8925. }
  8926. /**
  8927. * 调研选题-获取所有Researchers
  8928. * @param array $data
  8929. * @return array
  8930. */
  8931. public function getAllResearcher(array $data): array
  8932. {
  8933. $where['role_user.role_id'] = 21;
  8934. if(!empty($data['id'])){
  8935. $where['user.id'] = $data['id'];
  8936. }
  8937. if(!empty($data['real_name'])){
  8938. array_push($where, ['user_info.real_name', 'like', '%'.$data['real_name'].'%']);
  8939. }
  8940. $users = User::leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  8941. ->leftJoin('role_user', 'user.id', '=', 'role_user.user_id')
  8942. ->where($where)
  8943. ->select('user.id', 'user_info.real_name','user_info.number')
  8944. ->get()->toArray();
  8945. if (empty($users)) {
  8946. return Result::error('此调研员不存在!');
  8947. }
  8948. $user_number = array_search($data['user_id'], array_column($users, 'id'));
  8949. if($user_number == false){
  8950. $result['number'] = null;
  8951. }else{
  8952. $result['number'] = $users[$user_number]['number'];
  8953. }
  8954. $result['users'] = $users;
  8955. $result['user_id'] = $data['user_id'];
  8956. return Result::success($result);
  8957. }
  8958. /**
  8959. * 调研选题-添加
  8960. * @param array $data
  8961. * @return array
  8962. */
  8963. public function addResearchTopic(array $data): array
  8964. {
  8965. $user = User::where('id', $data['user_id'])->first();
  8966. if (empty($user)) {
  8967. return Result::error('用户不存在');
  8968. }
  8969. if($user['type_id'] == 10000){
  8970. $data['status'] = 1;
  8971. }else{
  8972. $data['status'] = 0;
  8973. }
  8974. if ($data['keyword'] == '') {
  8975. //提取标题+内容中的关键词
  8976. $data['keyword'] = $data['title'];
  8977. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  8978. Jieba::init(); // 初始化 jieba-php
  8979. Finalseg::init();
  8980. $segList = Jieba::cut($data['keyword']);
  8981. $segList1 = array_slice($segList, 0, 8);
  8982. $data['keyword'] = implode(',', $segList1);
  8983. }
  8984. if ($data['description'] == '') {
  8985. //提取内容中的描述
  8986. $content = $data['content'];
  8987. // 去除 <style> 和 <script> 标签及其内容
  8988. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  8989. // 去除所有 HTML 标签
  8990. $content = strip_tags($content);
  8991. // 去除 HTML 实体
  8992. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  8993. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  8994. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  8995. // 去除多余空白
  8996. $content = preg_replace('/\s+/u', '', $content);
  8997. // 截取 100 个字符
  8998. $data['description'] = mb_substr($content, 0, 100);
  8999. }
  9000. $data['level'] = empty($data['level']) ? null : $data['level'];
  9001. $data['province_id'] = empty($data['province_id']) ? null : $data['province_id'];
  9002. $data['city_id'] = empty($data['city_id']) ? null : $data['city_id'];
  9003. $data['county_id'] = empty($data['county_id']) ? null : $data['county_id'];
  9004. $data['due_time'] = empty($data['due_time']) ? null : $data['due_time'];
  9005. $users_id = empty($data['users_id']) ? null : $data['users_id'];
  9006. unset($data['users_id']);
  9007. // return Result::success($data);
  9008. Db::beginTransaction();
  9009. try{
  9010. $result = ResearchTopic::insertGetId($data);
  9011. if (empty($result)) {
  9012. Db::rollBack();
  9013. return Result::error('添加失败');
  9014. }
  9015. if(!empty($users_id) && is_string($users_id)){
  9016. $users = json_decode($users_id ?? '[]',true);
  9017. }
  9018. $users_type4 = User::where('type_id', 4)->pluck('id');
  9019. $type4_num = array_intersect($users, $users_type4->toArray());
  9020. if(count($users) != count($type4_num)){
  9021. Db::rollBack();
  9022. return Result::error('请选择调研员!');
  9023. }
  9024. // return Result::success($users);
  9025. if(!empty($users) && is_array($users)){
  9026. // 去重:确保同一 retopic_id + user_id 组合唯一
  9027. $users = array_values(array_unique($users));
  9028. // 组装关联数据
  9029. $users_topic = [];
  9030. foreach ($users as $key => $value) {
  9031. $users_topic[$key] = [
  9032. 'user_id' => $value,
  9033. 'retopic_id' => $result,
  9034. ];
  9035. }
  9036. // 使用 insertOrIgnore 忽略重复主键/唯一索引冲突
  9037. $retopic_user = RetopicUser::insert($users_topic);
  9038. if(empty($retopic_user)){
  9039. Db::rollBack();
  9040. return Result::error('添加失败');
  9041. }
  9042. }
  9043. Db::commit();
  9044. return Result::success($result);
  9045. }catch(\Exception $e){
  9046. Db::rollBack();
  9047. return Result::error($e->getMessage());
  9048. }
  9049. }
  9050. /**
  9051. * 调研选题-编辑
  9052. * @param array $data
  9053. * @return array
  9054. */
  9055. public function upResearchTopic(array $data): array
  9056. {
  9057. $user = User::where('id', $data['user_id'])->first();
  9058. if (empty($user)) {
  9059. return Result::error('用户不存在');
  9060. }
  9061. if($user['type_id'] == 10000){
  9062. $data['status'] = 1;
  9063. }else{
  9064. $data['status'] = 0;
  9065. }
  9066. $topic = ResearchTopic::where('id', $data['id'])->first();
  9067. if (empty($topic)) {
  9068. return Result::error('此调研选题不存在');
  9069. }
  9070. if ($data['keyword'] == '') {
  9071. //提取标题+内容中的关键词
  9072. $data['keyword'] = $data['title'];
  9073. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  9074. Jieba::init(); // 初始化 jieba-php
  9075. Finalseg::init();
  9076. $segList = Jieba::cut($data['keyword']);
  9077. $segList1 = array_slice($segList, 0, 8);
  9078. $data['keyword'] = implode(',', $segList1);
  9079. }
  9080. if ($data['description'] == '') {
  9081. //提取内容中的描述
  9082. $content = $data['content'];
  9083. // 去除 <style> 和 <script> 标签及其内容
  9084. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9085. // 去除所有 HTML 标签
  9086. $content = strip_tags($content);
  9087. // 去除 HTML 实体
  9088. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9089. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9090. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9091. // 去除多余空白
  9092. $content = preg_replace('/\s+/u', '', $content);
  9093. // 截取 100 个字符
  9094. $data['description'] = mb_substr($content, 0, 100);
  9095. }
  9096. $data['level'] = empty($data['level']) ? null : $data['level'];
  9097. $data['province_id'] = empty($data['province_id']) ? null : $data['province_id'];
  9098. $data['city_id'] = empty($data['city_id']) ? null : $data['city_id'];
  9099. $data['county_id'] = empty($data['county_id']) ? null : $data['county_id'];
  9100. $data['due_time'] = empty($data['due_time']) ? null : $data['due_time'];
  9101. $users_id = empty($data['users_id']) ? null : $data['users_id'];
  9102. $id = $data['id'];
  9103. unset($data['users_id']);
  9104. unset($data['id']);
  9105. // return Result::success($data);
  9106. Db::beginTransaction();
  9107. try{
  9108. $result = ResearchTopic::where('id', $id)->update($data);
  9109. if (empty($result)) {
  9110. Db::rollBack();
  9111. return Result::error('编辑调研选题失败!');
  9112. }
  9113. if(!empty($users_id) && is_string($users_id)){
  9114. $users = json_decode($users_id ?? '[]',true);
  9115. }
  9116. // return Result::success($users);
  9117. $retopic_users = RetopicUser::where('retopic_id', $id)->pluck('user_id')->toArray();
  9118. if(!empty($retopic_users)){
  9119. $del_users = RetopicUser::where('retopic_id', $id)->delete();
  9120. if(empty($del_users)){
  9121. Db::rollBack();
  9122. return Result::error('编辑同行人员失败!');
  9123. }
  9124. }
  9125. if(!empty($users) && is_array($users)){
  9126. // 去重:确保同一 retopic_id + user_id 组合唯一
  9127. $users = array_values(array_unique($users));
  9128. // 组装关联数据
  9129. $users_topic = [];
  9130. foreach ($users as $key => $value) {
  9131. $users_topic[$key] = [
  9132. 'user_id' => $value,
  9133. 'retopic_id' => $id,
  9134. ];
  9135. }
  9136. // 使用 insertOrIgnore 忽略重复主键/唯一索引冲突
  9137. $retopic_user = RetopicUser::insert($users_topic);
  9138. if(empty($retopic_user)){
  9139. Db::rollBack();
  9140. return Result::error('编辑失败');
  9141. }
  9142. }
  9143. Db::commit();
  9144. return Result::success($result);
  9145. }catch(\Exception $e){
  9146. Db::rollBack();
  9147. return Result::error($e->getMessage());
  9148. }
  9149. }
  9150. /**
  9151. * 调研选题-删除
  9152. * @param array $data
  9153. * @return array
  9154. */
  9155. public function delResearchTopic(array $data): array
  9156. {
  9157. $user = User::where('id', $data['user_id'])->first();
  9158. if (empty($user)) {
  9159. return Result::error('用户不存在');
  9160. }
  9161. $topic = ResearchTopic::where('id', $data['id'])->first();
  9162. if (empty($topic)) {
  9163. return Result::error('此调研选题不存在');
  9164. }
  9165. Db::beginTransaction();
  9166. try{
  9167. $result = ResearchTopic::where('id', $data['id'])->delete();
  9168. if (empty($result)) {
  9169. Db::rollBack();
  9170. return Result::error('删除调研选题失败!');
  9171. }
  9172. $topic_users = RetopicUser::where('retopic_id', $data['id'])->pluck('user_id')->toArray();
  9173. if(!empty($topic_users)){
  9174. $del_topic_users = RetopicUser::where('retopic_id', $data['id'])->delete();
  9175. if(empty($del_topic_users)){
  9176. Db::rollBack();
  9177. return Result::error('删除同行人员失败!');
  9178. }
  9179. }
  9180. Db::commit();
  9181. return Result::success($result);
  9182. }catch(\Exception $e){
  9183. Db::rollBack();
  9184. return Result::error($e->getMessage());
  9185. }
  9186. }
  9187. /**
  9188. * 调研选题-列表
  9189. * @param array $data
  9190. * @return array
  9191. */
  9192. public function getResearchTopicList(array $data): array
  9193. {
  9194. $user = User::where('id', $data['user_id'])->first();
  9195. if (empty($user)) {
  9196. return Result::error('用户不存在!');
  9197. }
  9198. $where = [];
  9199. if($user->type_id != 10000){
  9200. $where['research_topic.user_id'] = $data['user_id'];
  9201. $website = Website::where('id', $data['website_id'])->first();
  9202. if (empty($website)) {
  9203. return Result::error('网站不存在!');
  9204. }
  9205. $web_column = json_decode($website->website_column_arr_id ?? '[]',true);
  9206. if(empty($web_column)){
  9207. return Result::error('网站未配置栏目!');
  9208. }
  9209. }
  9210. if($data['is_master'] != 0){
  9211. if($data['is_master'] == 3){
  9212. $where['research_topic.status'] = 0;
  9213. }else{
  9214. $where['research_topic.status'] = $data['is_master'];
  9215. }
  9216. }
  9217. if(!empty($data['title'])){
  9218. array_push($where, ['research_topic.title', 'like', '%'.$data['title'].'%']);
  9219. }
  9220. $page = $data['page'] ?? 1;
  9221. $page_size = $data['page_size'] ?? 10;
  9222. $research_topic = ResearchTopic::when($data['is_master'] == 0, function($query) use($data){
  9223. $query->whereIn('research_topic.status', [0,2]);
  9224. })
  9225. ->when(!empty($where), function($query) use($where){
  9226. $query->where($where);
  9227. })
  9228. ->with(['retopicUsers' => function ($query) {
  9229. $query->select('id', 'user_id', 'retopic_id');
  9230. }
  9231. ])
  9232. ->leftJoin('user', 'user.id', '=', 'research_topic.user_id')
  9233. ->leftJoin('user_info', 'user_info.user_id', '=', 'research_topic.user_id')
  9234. ->select('research_topic.id','research_topic.title','research_topic.updated_at','research_topic.status',
  9235. 'research_topic.due_time','user_info.real_name','research_topic.column_id','research_topic.user_id',
  9236. 'user.user_name'
  9237. )
  9238. ->orderBy('research_topic.updated_at', 'desc')
  9239. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  9240. if(empty($research_topic->items())){
  9241. return Result::error('暂无调研选题!');
  9242. }
  9243. $result = [
  9244. 'rows' => $research_topic->items(),
  9245. 'count' => $research_topic->total()
  9246. ];
  9247. foreach($result['rows'] as $key => $value){
  9248. if($user->type_id != 10000){
  9249. if(in_array($value['column_id'], $web_column)){
  9250. $result['rows'][$key]['is_update'] = 1;
  9251. }else{
  9252. $result['rows'][$key]['is_update'] = 0;
  9253. }
  9254. }else{
  9255. if($value['user_id'] == $data['user_id']){
  9256. $result['rows'][$key]['is_update'] = 1;
  9257. }else{
  9258. $result['rows'][$key]['is_update'] = 0;
  9259. }
  9260. }
  9261. if(!isset($value['real_name']) || empty($value['real_name'])){
  9262. $result['rows'][$key]['real_name'] = $value['user_name'];
  9263. }
  9264. if(!empty($value['retopicUsers'])){
  9265. $retopic_users = $value['retopicUsers'];
  9266. $retopic_user = $retopic_users->pluck('user_id')->toArray();
  9267. $result['rows'][$key]['txry_users'] = implode(',', $retopic_user);
  9268. unset($result['rows'][$key]['retopicUsers']);
  9269. }
  9270. }
  9271. return Result::success($result);
  9272. }
  9273. /**
  9274. * 调研选题-修改状态
  9275. * @param array $data
  9276. * @return array
  9277. */
  9278. public function checkResearchTopic(array $data): array
  9279. {
  9280. $user = User::where('id', $data['user_id'])->first();
  9281. if (empty($user)) {
  9282. return Result::error('用户不存在!');
  9283. }
  9284. if($user->type_id != 10000 && ($data['status'] == 1 || $data['status'] == 2)){
  9285. return Result::error('此用户暂无权限!');
  9286. }
  9287. $topic = ResearchTopic::where('id', $data['id'])->first();
  9288. if (empty($topic)) {
  9289. return Result::error('此调研选题不存在');
  9290. }
  9291. $id = $data['id'];
  9292. unset($data['id']);
  9293. unset($data['user_id']);
  9294. $result = ResearchTopic::where('id', $id)->update($data);
  9295. if (empty($result)) {
  9296. return Result::error('修改调研选题状态失败!');
  9297. }
  9298. return Result::success($result);
  9299. }
  9300. /**
  9301. * 调研选题-详情
  9302. * @param array $data
  9303. * @return array
  9304. */
  9305. public function getResearchTopicInfo(array $data): array
  9306. {
  9307. $user = User::where('id', $data['user_id'])->first();
  9308. if (empty($user)) {
  9309. return Result::error('用户不存在!');
  9310. }
  9311. $research_topic = ResearchTopic::where('research_topic.id', $data['id'])
  9312. ->with(['retopicUsers' => function ($query) {
  9313. $query->select('user_id','retopic_id');
  9314. }
  9315. ])
  9316. ->leftJoin('user', 'user.id', '=', 'research_topic.user_id')
  9317. ->leftJoin('user_info', 'user_info.user_id', '=', 'research_topic.user_id')
  9318. ->select('research_topic.*','user_info.number')
  9319. ->first();
  9320. if(empty($research_topic)){
  9321. return Result::error('获取调研选题详情失败!');
  9322. }
  9323. $retopic_user = $research_topic['retopicUsers'];
  9324. if(!empty($retopic_user)){
  9325. $retopic_user = $retopic_user->pluck('user_id')->toArray();
  9326. foreach($retopic_user as $key => $value){
  9327. $real_name = UserInfo::where('user_id', $value)->value('real_name');
  9328. $research_topic['retopicUsers'][$key]['real_name'] = $real_name;
  9329. $research_topic['retopicUsers'][$key]['user_id'] = $value;
  9330. unset($research_topic['retopicUsers'][$key]['retopic_id']);
  9331. }
  9332. }
  9333. return Result::success($research_topic);
  9334. }
  9335. /**
  9336. * 添加网站导航
  9337. * @param array $data
  9338. */
  9339. public function addWebCateinfo(array $data): array
  9340. {
  9341. $user = User::where('id', $data['user_id'])->first();
  9342. if (empty($user)) {
  9343. return Result::error('用户不存在');
  9344. }
  9345. if($user['type_id'] == 10000){
  9346. $data['status'] = 1;
  9347. }else{
  9348. $data['status'] = 0;
  9349. }
  9350. if ($data['keyword'] == '') {
  9351. //提取标题+内容中的关键词
  9352. $data['keyword'] = $data['title'];
  9353. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  9354. Jieba::init(); // 初始化 jieba-php
  9355. Finalseg::init();
  9356. $segList = Jieba::cut($data['keyword']);
  9357. $segList1 = array_slice($segList, 0, 8);
  9358. $data['keyword'] = implode(',', $segList1);
  9359. }
  9360. if ($data['description'] == '') {
  9361. //提取内容中的描述
  9362. $content = $data['content'];
  9363. // 去除 <style> 和 <script> 标签及其内容
  9364. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9365. // 去除所有 HTML 标签
  9366. $content = strip_tags($content);
  9367. // 去除 HTML 实体
  9368. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9369. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9370. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9371. // 去除多余空白
  9372. $content = preg_replace('/\s+/u', '', $content);
  9373. // 截取 100 个字符
  9374. $data['description'] = mb_substr($content, 0, 100);
  9375. }
  9376. $data['cate_name'] = empty($data['cate_name']) ? '官网导航' : $data['cate_name'];
  9377. $data['province_id'] = empty($data['province_id']) ? null : $data['province_id'];
  9378. $data['city_id'] = empty($data['city_id']) ? null : $data['city_id'];
  9379. $data['county_id'] = empty($data['county_id']) ? null : $data['county_id'];
  9380. unset($data['users_id']);
  9381. $result = WebCateinfo::insertGetId($data);
  9382. if (empty($result)) {
  9383. return Result::error('添加失败');
  9384. }
  9385. return Result::success($result);
  9386. }
  9387. /**
  9388. * 更新网站导航
  9389. * @param array $data
  9390. */
  9391. public function upWebCateinfo(array $data): array
  9392. {
  9393. $webCateinfo = WebCateinfo::where('id', $data['id'])->first();
  9394. if (empty($webCateinfo)) {
  9395. return Result::error('导航不存在');
  9396. }
  9397. $user = User::where('id', $data['user_id'])->first();
  9398. if (empty($user)) {
  9399. return Result::error('用户不存在');
  9400. }
  9401. if($user['type_id'] == 10000){
  9402. $data['status'] = 1;
  9403. }else{
  9404. $data['status'] = 0;
  9405. }
  9406. if ($data['keyword'] == '') {
  9407. //提取标题+内容中的关键词
  9408. $data['keyword'] = $data['title'];
  9409. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  9410. Jieba::init(); // 初始化 jieba-php
  9411. Finalseg::init();
  9412. $segList = Jieba::cut($data['keyword']);
  9413. $segList1 = array_slice($segList, 0, 8);
  9414. $data['keyword'] = implode(',', $segList1);
  9415. }
  9416. if ($data['description'] == '') {
  9417. //提取内容中的描述
  9418. $content = $data['content'];
  9419. // 去除 <style> 和 <script> 标签及其内容
  9420. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9421. // 去除所有 HTML 标签
  9422. $content = strip_tags($content);
  9423. // 去除 HTML 实体
  9424. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9425. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9426. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9427. // 去除多余空白
  9428. $content = preg_replace('/\s+/u', '', $content);
  9429. // 截取 100 个字符
  9430. $data['description'] = mb_substr($content, 0, 100);
  9431. }
  9432. $data['cate_name'] = empty($data['cate_name']) ? '官网导航' : $data['cate_name'];
  9433. $data['province_id'] = empty($data['province_id']) ? null : $data['province_id'];
  9434. $data['city_id'] = empty($data['city_id']) ? null : $data['city_id'];
  9435. $data['county_id'] = empty($data['county_id']) ? null : $data['county_id'];
  9436. unset($data['users_id']);
  9437. $result = WebCateinfo::where('id', $data['id'])->update($data);
  9438. if (empty($result)) {
  9439. return Result::error('更新失败');
  9440. }
  9441. return Result::success($result);
  9442. }
  9443. /**
  9444. * 获取网站导航列表
  9445. * @param array $data
  9446. * @return array
  9447. */
  9448. public function getWebCateinfoList(array $data): array
  9449. {
  9450. $user = User::where('id', $data['user_id'])->first();
  9451. if (empty($user)) {
  9452. return Result::error('用户不存在');
  9453. }
  9454. $where = [];
  9455. if($user['type_id'] != 10000){
  9456. $where['web_cateinfo.user_id'] = $data['user_id'];
  9457. }
  9458. if(!empty($data['title'])){
  9459. array_push($where, ['web_cateinfo.title', 'like', '%'.$data['title'].'%']);
  9460. }
  9461. if($data['is_master'] != 0){
  9462. if($data['is_master'] == 3){
  9463. $where['web_cateinfo.status'] = 0;
  9464. }else{
  9465. $where['web_cateinfo.status'] = $data['is_master'];
  9466. }
  9467. }
  9468. $web_cateinfo = WebCateinfo::when(!empty($data['is_master'] == 0), function ($query) use ($where) {
  9469. $query->whereIn('web_cateinfo.status', [0, 2]);
  9470. })
  9471. ->when(!empty($where), function ($query) use ($where) {
  9472. $query->where($where);
  9473. })
  9474. ->leftJoin('user', 'web_cateinfo.user_id', '=', 'user.id')
  9475. ->select(['web_cateinfo.id', 'web_cateinfo.user_id', 'user.nickname', 'web_cateinfo.title', 'web_cateinfo.cate_name', 'web_cateinfo.status','web_cateinfo.updated_at'])
  9476. ->orderBy('updated_at', 'desc')
  9477. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  9478. if(empty($web_cateinfo->items())){
  9479. return Result::error('官网导航不存在');
  9480. }
  9481. $result = [
  9482. 'rows' => $web_cateinfo->items(),
  9483. 'total' => $web_cateinfo->total(),
  9484. ];
  9485. foreach($result['rows'] as $key => $value){
  9486. if($value['user_id'] == $data['user_id']){
  9487. $result['rows'][$key]['is_update'] = 1;
  9488. }else{
  9489. $result['rows'][$key]['is_update'] = 0;
  9490. }
  9491. }
  9492. return Result::success($result);
  9493. }
  9494. /**
  9495. * 删除网站导航
  9496. * @param array $data
  9497. */
  9498. public function delWebCateinfo(array $data): array
  9499. {
  9500. $webCateinfo = WebCateinfo::where('id', $data['id'])->first();
  9501. if (empty($webCateinfo)) {
  9502. return Result::error('导航不存在');
  9503. }
  9504. $result = WebCateinfo::where('id', $data['id'])->delete();
  9505. if (empty($result)) {
  9506. return Result::error('删除失败');
  9507. }
  9508. return Result::success($result);
  9509. }
  9510. /**
  9511. * 审核网站导航
  9512. * @param array $data
  9513. */
  9514. public function checkWebCateinfo(array $data): array
  9515. {
  9516. $webCateinfo = WebCateinfo::where('id', $data['id'])->first();
  9517. if (empty($webCateinfo)) {
  9518. return Result::error('导航不存在');
  9519. }
  9520. $user = User::where('id', $data['user_id'])->first();
  9521. if (empty($user)) {
  9522. return Result::error('用户不存在');
  9523. }
  9524. if($user['type_id'] != 10000 && $data['status'] == 1){
  9525. return Result::error('非管理员不能审核');
  9526. }
  9527. $update_data['status'] = $data['status'];
  9528. if($data['status'] == 2){
  9529. $update_data['reason'] = $data['reason'];
  9530. }
  9531. $result = WebCateinfo::where('id', $data['id'])->update($update_data);
  9532. if (empty($result)) {
  9533. return Result::error('审核失败');
  9534. }
  9535. return Result::success($result);
  9536. }
  9537. /**
  9538. * 获取网站导航详情
  9539. * @param array $data
  9540. */
  9541. public function getWebCateinfoDetail(array $data): array
  9542. {
  9543. $webCateinfo = WebCateinfo::where('id', $data['id'])->first();
  9544. if (empty($webCateinfo)) {
  9545. return Result::error('导航不存在');
  9546. }
  9547. $result = $webCateinfo->toArray();
  9548. return Result::success($result);
  9549. }
  9550. /**
  9551. * 推荐单页管理
  9552. * @param array $data
  9553. */
  9554. public function getAdviceSinglePages(array $data): array
  9555. {
  9556. $user = User::where('id', $data['user_id'])->first();
  9557. if (empty($user)) {
  9558. return Result::error('用户不存在');
  9559. }
  9560. $category = WebsiteCategory::where(['website_id' => $data['website_id']])->pluck('category_id');
  9561. if(empty($category)){
  9562. return Result::error('推荐单页不存在');
  9563. }
  9564. $where = [];
  9565. if(!empty($data['title'])){
  9566. array_push($where, ['title', 'like', '%'.$data['title'].'%']);
  9567. }
  9568. $result = SinglePage::whereIn('id', $category)
  9569. ->when(!empty($where), function ($query) use ($where) {
  9570. $query->where($where);
  9571. })
  9572. // ->when(!isset($data['catid']), function ($query) use ($data) {
  9573. // $query->where('catid', $data['catid']);
  9574. // })
  9575. ->where('status', 1)
  9576. ->select(['id', 'title', 'catid','status','website_id','updated_at'])
  9577. ->orderBy('updated_at', 'desc')
  9578. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  9579. if(empty($result->items())){
  9580. return Result::error('推荐单页不存在');
  9581. }
  9582. $result = [
  9583. 'rows' => $result->items(),
  9584. 'total' => $result->total(),
  9585. ];
  9586. return Result::success($result);
  9587. }
  9588. /**
  9589. * 添加单页
  9590. * @param array $data
  9591. */
  9592. public function addSinglePage(array $data): array
  9593. {
  9594. $user = User::where('id', $data['user_id'])->first();
  9595. if (empty($user)) {
  9596. return Result::error('用户不存在');
  9597. }
  9598. if($user['type_id'] == 10000){
  9599. $data['status'] = 1;
  9600. }else{
  9601. $data['status'] = 0;
  9602. }
  9603. if(is_array($data['cat_arr_id'])){
  9604. $data['cat_arr_id'] = array_map(function($item){
  9605. return intval($item);
  9606. }, $data['cat_arr_id']);
  9607. $data['catid'] = end($data['cat_arr_id']);
  9608. $data['cat_arr_id'] = json_encode($data['cat_arr_id'], JSON_UNESCAPED_UNICODE);
  9609. }else{
  9610. return Result::error('请选择栏目;');
  9611. }
  9612. if(!empty($data['commend_id']) && is_array($data['commend_id'])){
  9613. $data['commend_id'] = json_encode($data['commend_id'], JSON_UNESCAPED_UNICODE);
  9614. }else{
  9615. $data['commend_id'] = null;
  9616. }
  9617. if ($data['keyword'] == '') {
  9618. //提取标题+内容中的关键词
  9619. $articleData['keyword'] = $data['title'];
  9620. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  9621. Jieba::init(); // 初始化 jieba-php
  9622. Finalseg::init();
  9623. $segList = Jieba::cut($articleData['keyword']);
  9624. $segList1 = array_slice($segList, 0, 8);
  9625. $data['keyword'] = implode(',', $segList1);
  9626. }
  9627. if ($data['description'] == '') {
  9628. //提取内容中的描述
  9629. $content = $data['content'];
  9630. // 去除 <style> 和 <script> 标签及其内容
  9631. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9632. // 去除所有 HTML 标签
  9633. $content = strip_tags($content);
  9634. // 去除 HTML 实体
  9635. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9636. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9637. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9638. // 去除多余空白
  9639. $content = preg_replace('/\s+/u', '', $content);
  9640. // 截取 100 个字符
  9641. $data['description'] = mb_substr($content, 0, 100);
  9642. }
  9643. if(empty($data['publiced_at'])){
  9644. $data['publiced_at'] = null;
  9645. }
  9646. $result = SinglePage::insertGetId($data);
  9647. if (empty($result)) {
  9648. return Result::error('添加失败');
  9649. }
  9650. return Result::success($result);
  9651. }
  9652. /**
  9653. * 更新单页
  9654. * @param array $data
  9655. */
  9656. public function upSinglePage(array $data): array
  9657. {
  9658. $singlePage = SinglePage::where('id', $data['id'])->where('user_id', $data['user_id'])->first();
  9659. if (empty($singlePage)) {
  9660. return Result::error('单页不存在');
  9661. }
  9662. $user = User::where('id', $data['user_id'])->first();
  9663. if (empty($user)) {
  9664. return Result::error('用户不存在');
  9665. }
  9666. $where['id'] = $data['id'];
  9667. unset($data['id']);
  9668. if($user['type_id'] == 10000){
  9669. $data['status'] = 1;
  9670. }else{
  9671. $data['status'] = 0;
  9672. }
  9673. if(is_array($data['cat_arr_id'])){
  9674. $data['cat_arr_id'] = array_map(function($item){
  9675. return intval($item);
  9676. }, $data['cat_arr_id']);
  9677. $data['catid'] = end($data['cat_arr_id']);
  9678. $data['cat_arr_id'] = json_encode($data['cat_arr_id'], JSON_UNESCAPED_UNICODE);
  9679. }else{
  9680. return Result::error('请选择栏目;');
  9681. }
  9682. if(!empty($data['commend_id']) && is_array($data['commend_id'])){
  9683. $data['commend_id'] = json_encode($data['commend_id'], JSON_UNESCAPED_UNICODE);
  9684. }else{
  9685. $data['commend_id'] = null;
  9686. }
  9687. if ($data['keyword'] == '') {
  9688. //提取标题+内容中的关键词
  9689. $articleData['keyword'] = $data['title'];
  9690. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  9691. Jieba::init(); // 初始化 jieba-php
  9692. Finalseg::init();
  9693. $segList = Jieba::cut($articleData['keyword']);
  9694. $segList1 = array_slice($segList, 0, 8);
  9695. $data['keyword'] = implode(',', $segList1);
  9696. }
  9697. if ($data['description'] == '') {
  9698. //提取内容中的描述
  9699. $content = $data['content'];
  9700. // 去除 <style> 和 <script> 标签及其内容
  9701. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9702. // 去除所有 HTML 标签
  9703. $content = strip_tags($content);
  9704. // 去除 HTML 实体
  9705. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9706. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9707. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9708. // 去除多余空白
  9709. $content = preg_replace('/\s+/u', '', $content);
  9710. // 截取 100 个字符
  9711. $data['description'] = mb_substr($content, 0, 100);
  9712. }
  9713. if(empty($data['publiced_at'])){
  9714. $data['publiced_at'] = null;
  9715. }
  9716. $result = SinglePage::where($where)->update($data);
  9717. if (empty($result)) {
  9718. return Result::error('更新失败');
  9719. }
  9720. return Result::success($result);
  9721. }
  9722. /**
  9723. * 删除单页
  9724. * @param array $data
  9725. */
  9726. public function delSinglePage(array $data): array
  9727. {
  9728. $singlePage = SinglePage::where('id', $data['id'])->first();
  9729. if (empty($singlePage)) {
  9730. return Result::error('单页不存在');
  9731. }
  9732. $user = User::where('id', $data['user_id'])->first();
  9733. if (empty($user)) {
  9734. return Result::error('用户不存在');
  9735. }
  9736. $where['id'] = $data['id'];
  9737. $result = SinglePage::where($where)->delete();
  9738. if (empty($result)) {
  9739. return Result::error('删除失败');
  9740. }
  9741. return Result::success($result);
  9742. }
  9743. /**
  9744. * 审核单页
  9745. * @param array $data
  9746. */
  9747. public function checkSinglePage(array $data): array
  9748. {
  9749. $user = User::where('id', $data['user_id'])->first();
  9750. if (empty($user)) {
  9751. return Result::error('用户不存在');
  9752. }
  9753. if($user['type_id'] != 10000 && in_array($data['status'], [1, 2])){
  9754. return Result::error('非管理员不能审核单页');
  9755. }
  9756. if($data['status'] == 2){
  9757. $update_data['reason'] = $data['reason'] ?? '';
  9758. }
  9759. $update_data['status'] = $data['status'];
  9760. $result = SinglePage::where('id', $data['id'])->update($update_data);
  9761. if (empty($result)) {
  9762. return Result::error('更新失败');
  9763. }
  9764. return Result::success($result);
  9765. }
  9766. /**
  9767. * 更新单页状态
  9768. * @param array $data
  9769. */
  9770. public function getSinglePageList(array $data): array
  9771. {
  9772. $user = User::where('id', $data['user_id'])->first();
  9773. if (empty($user)) {
  9774. return Result::error('用户不存在');
  9775. }
  9776. $where = [];
  9777. if($user['type_id'] != 10000){
  9778. $where['single_page.user_id'] = $data['user_id'];
  9779. }
  9780. if($data['is_master'] == 3){
  9781. $where['single_page.status'] = 0;
  9782. }else if($data['is_master'] != 0){
  9783. $where['single_page.status'] = $data['is_master'];
  9784. }
  9785. if(!empty($data['title'])){
  9786. array_push($where, ['single_page.title', 'like', '%'.$data['title'].'%']);
  9787. }
  9788. $result = SinglePage::when($data['is_master'] == 0, function($query) use($data){
  9789. $query->whereIn('single_page.status', [0, 2]);
  9790. })
  9791. ->when(!empty($where), function($query) use($where){
  9792. $query->where($where);
  9793. })
  9794. ->with([
  9795. 'websiteCategory' => function ($query) {
  9796. $query->select('website_id', 'category_id', 'alias');
  9797. },
  9798. 'user' => function ($query) {
  9799. $query->select('id', 'nickname');
  9800. }
  9801. ])
  9802. ->select(['single_page.id','single_page.title','single_page.content','single_page.updated_at',
  9803. 'single_page.status','single_page.catid','single_page.website_id','single_page.user_id'])
  9804. ->orderBy('single_page.updated_at', 'desc')
  9805. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  9806. if (empty($result->items())) {
  9807. return Result::error('暂无数据');
  9808. }
  9809. $result = [
  9810. 'rows' => $result->items(),
  9811. 'total' => $result->total(),
  9812. ];
  9813. foreach($result['rows'] as $key => $value){
  9814. $result['rows'][$key]['category_alias'] = $value['websiteCategory']['alias'] ?? '';
  9815. $result['rows'][$key]['user_nickname'] = $value['user']['nickname'] ?? '';
  9816. $result['rows'][$key]['websiteCategory'] = $value['websiteCategory']['alias'] ?? '';
  9817. unset($result['rows'][$key]['user']);
  9818. unset($result['rows'][$key]['websiteCategory']);
  9819. if($user['type_id'] == 10000){
  9820. if($value['user_id'] == $data['user_id']){
  9821. $result['rows'][$key]['is_update'] = 1;
  9822. }else{
  9823. $result['rows'][$key]['is_update'] = 0;
  9824. }
  9825. }else{
  9826. if($value['website_id'] == $data['website_id']){
  9827. $result['rows'][$key]['is_update'] = 1;
  9828. }else{
  9829. $result['rows'][$key]['is_update'] = 0;
  9830. }
  9831. }
  9832. }
  9833. return Result::success($result);
  9834. }
  9835. /**
  9836. * 获取单页详情
  9837. * @param array $data
  9838. */
  9839. public function getSinglePageInfo(array $data): array
  9840. {
  9841. $singlePage = SinglePage::where('id', $data['id'])->where('user_id', $data['user_id'])->first();
  9842. if (empty($singlePage)) {
  9843. return Result::error('单页不存在');
  9844. }
  9845. $user = User::where('id', $data['user_id'])->first();
  9846. if (empty($user)) {
  9847. return Result::error('用户不存在');
  9848. }
  9849. $where['id'] = $data['id'];
  9850. $result = SinglePage::where($where)->first();
  9851. if (empty($result)) {
  9852. return Result::error('获取失败');
  9853. }
  9854. $result['cat_arr_id'] = json_decode($result['cat_arr_id'] ?? '[]' , true);
  9855. $result['commend_id'] = json_decode($result['commend_id'] ?? '[]' , true);
  9856. return Result::success($result);
  9857. }
  9858. }