NewsService.php 349 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546
  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. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  73. class NewsService implements NewsServiceInterface
  74. {
  75. #[Inject]
  76. protected Redis $redis;
  77. /**
  78. * 获取导航池列表
  79. * @param array $data
  80. * @return array
  81. */
  82. public function getCategoryList(array $data): array
  83. {
  84. $search = $data['name'] ?? '';
  85. $page = (int)($data['page'] ?? 1);
  86. $perPage = (int)($data['pageSize'] ?? 10);
  87. // 1. 查出所有匹配的分类id
  88. if ($search) {
  89. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  90. if (empty($matchedIds)) {
  91. return Result::success(['rows' => [], 'total' => 0]);
  92. }
  93. // 2. 递归查所有父级,直到一级分类
  94. $idsStr = implode(',', $matchedIds);
  95. $sql = "
  96. WITH RECURSIVE parents AS (
  97. SELECT * FROM category WHERE id IN ($idsStr)
  98. UNION ALL
  99. SELECT c.* FROM category c
  100. INNER JOIN parents p ON c.id = p.pid
  101. )
  102. SELECT * FROM parents
  103. ";
  104. $parents = Db::select($sql);
  105. $parentIds = [];
  106. foreach ($parents as $row) {
  107. if ($row->pid == 0) {
  108. $parentIds[] = $row->id;
  109. }
  110. }
  111. $parentIds = array_unique($parentIds);
  112. } else {
  113. // 没有搜索,一级分类就是根
  114. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  115. }
  116. // 3. 一级分类分页
  117. $total = count($parentIds);
  118. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  119. if (empty($parentIds)) {
  120. return Result::success(['rows' => [], 'total' => $total]);
  121. }
  122. // 4. 递归查所有子孙
  123. $idsStr = implode(',', $parentIds);
  124. $sql = "
  125. WITH RECURSIVE subcategories AS (
  126. SELECT * FROM category WHERE id IN ($idsStr)
  127. UNION ALL
  128. SELECT c.* FROM category c
  129. INNER JOIN subcategories s ON c.pid = s.id
  130. )
  131. SELECT * FROM subcategories ORDER BY updated_at DESC
  132. ";
  133. $allCategories = Db::select($sql);
  134. // 5. 组装树结构
  135. $categoryMap = [];
  136. foreach ($allCategories as $cat) {
  137. $cat = (array)$cat;
  138. $cat['children'] = [];
  139. $categoryMap[$cat['id']] = $cat;
  140. }
  141. foreach ($categoryMap as $id => &$cat) {
  142. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  143. $categoryMap[$cat['pid']]['children'][] = &$cat;
  144. }
  145. }
  146. unset($cat);
  147. $categoryTree = [];
  148. foreach ($parentIds as $id) {
  149. if (isset($categoryMap[$id])) {
  150. $categoryTree[] = $categoryMap[$id];
  151. }
  152. }
  153. return Result::success([
  154. 'rows' => $categoryTree,
  155. 'total' => $total,
  156. ]);
  157. }
  158. private function findMatchedCategories($search)
  159. {
  160. if ($search) {
  161. return Category::where('name', 'like', "%{$search}%")
  162. ->orderBy('updated_at', 'desc')
  163. ->get();
  164. }
  165. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  166. ->get();
  167. }
  168. private function findAllParents($categories)
  169. {
  170. $allCategories = [];
  171. foreach ($categories as $category) {
  172. $parentId = $category->pid;
  173. while ($parentId > 0) {
  174. $parent = Category::find($parentId);
  175. if ($parent) {
  176. $allCategories[$parent->id] = $parent;
  177. $parentId = $parent->pid;
  178. } else {
  179. break;
  180. }
  181. }
  182. $allCategories[$category->id] = $category;
  183. }
  184. return array_values($allCategories);
  185. }
  186. private function buildCategoryTree($category, $allRequiredCategories)
  187. {
  188. $categoryData = $category->toArray();
  189. $children = [];
  190. foreach ($allRequiredCategories as $c) {
  191. if ($c->pid === $category->id) {
  192. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  193. }
  194. }
  195. if (!empty($children)) {
  196. $categoryData['children'] = $children;
  197. }
  198. return $categoryData;
  199. }
  200. public function myCategoryList(array $data): array
  201. {
  202. $sszq = $data['sszq'] ?? '';
  203. unset($data['sszq']);
  204. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  205. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  206. $where[] = [
  207. 'pid',
  208. '=',
  209. $data['pid'],
  210. ];
  211. if (isset($data['name'])) {
  212. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  213. }
  214. var_dump($where);
  215. //根据分类id,从category表中取出分类信息
  216. $result = Category::where($where)
  217. ->whereIn('category.id', $catorytids)
  218. ->select('category.*', 'category.id as category_id')->get();
  219. if (empty($result)) {
  220. return Result::error("没有栏目数据");
  221. }
  222. return Result::success($result);
  223. }
  224. /**
  225. * @param array $data
  226. * @return array
  227. */
  228. public function categoryList(array $data): array
  229. {
  230. $where[] = [
  231. 'pid',
  232. '=',
  233. $data['pid']
  234. ];
  235. if (isset($data['name'])) {
  236. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  237. }
  238. var_dump($where);
  239. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  240. if (empty($result)) {
  241. return Result::error("没有栏目数据");
  242. }
  243. return Result::success($result);
  244. }
  245. /**
  246. * @param array $data
  247. * @return array
  248. */
  249. public function addCategory(array $data): array
  250. {
  251. if (isset($data['id'])) {
  252. unset($data['id']);
  253. }
  254. $id = Category::insertGetId($data);
  255. if (empty($id)) {
  256. return Result::error("添加失败");
  257. }
  258. return Result::success(['id' => $id]);
  259. }
  260. /**
  261. * @param array $data
  262. * @return array
  263. */
  264. public function delCategory(array $data): array
  265. {
  266. Db::beginTransaction();
  267. try {
  268. $categoryList = Category::where(['pid' => $data['id']])->get();
  269. if ($categoryList->toArray()) {
  270. Db::rollBack();
  271. return Result::error("分类下面有子分类不能删除");
  272. }
  273. $articleList = Article::where(['catid' => $data['id']])->get();
  274. if ($articleList->toArray()) {
  275. Db::rollBack();
  276. return Result::error("分类下面有资讯不能删除");
  277. }
  278. $result = Category::where($data)->delete();
  279. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  280. if (!$result) {
  281. Db::rollBack();
  282. return Result::error("删除失败");
  283. }
  284. Db::commit();
  285. return Result::success($result);
  286. } catch (\Exception $e) {
  287. Db::rollBack();
  288. return Result::error("删除失败" . $e->getMessage());
  289. }
  290. }
  291. /**
  292. * @param array $data
  293. * @return array
  294. */
  295. public function updateCategory(array $data): array
  296. {
  297. $where = [
  298. 'id' => $data['id'],
  299. ];
  300. $result = Category::where($where)->update($data);
  301. if ($result) {
  302. return Result::success($result);
  303. } else {
  304. return Result::error("更新失败");
  305. }
  306. }
  307. /**
  308. * 获取导航池信息
  309. * @param array $data
  310. * @return array
  311. */
  312. public function getCategoryInfo(array $data): array
  313. {
  314. $where = [
  315. 'id' => $data['id'],
  316. ];
  317. $result = Category::where($where)->first();
  318. if ($result) {
  319. return Result::success($result);
  320. } else {
  321. return Result::error("更新失败");
  322. }
  323. }
  324. public function getArticleCommend(array $data): array
  325. {
  326. $where = [
  327. 'website_id' => $data['website_id'],
  328. ];
  329. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  330. var_dump($ids);
  331. if (empty($ids)) {
  332. return Result::error("没有推荐数据");
  333. }
  334. //id
  335. $whereArticle = [];
  336. if (isset($data['id'])) {
  337. $whereArticle['id'] = $data['id'];
  338. }
  339. //title like
  340. if (isset($data['title'])) {
  341. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  342. }
  343. $article = Article::whereIn('catid', values: $ids)->where('status', 1)
  344. ->where($whereArticle)
  345. ->orderBy('id', 'desc')
  346. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  347. if ($article) {
  348. $data = [
  349. 'rows' => $article->items(),
  350. 'count' => $article->total(),
  351. ];
  352. return Result::success($data);
  353. } else {
  354. return Result::error("获取失败失败");
  355. }
  356. }
  357. /**
  358. * @param array $data
  359. * @return array
  360. */
  361. public function getArticleList(array $data): array
  362. {
  363. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  364. $type_id = $data['type_id'];
  365. unset($data['type_id']);
  366. $user_id = $data['user_id'];
  367. unset($data['user_id']);
  368. $where = [];
  369. $status1 = [];
  370. if (isset($data['id']) && $data['id']) {
  371. array_push($where, ['article.id', '=', $data['id']]);
  372. }
  373. if (isset($data['title']) && $data['title']) {
  374. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  375. }
  376. if (isset($data['category_name']) && $data['category_name']) {
  377. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  378. }
  379. if (isset($data['catid']) && $data['catid']) {
  380. array_push($where, ['article.catid', '=', $data['catid']]);
  381. }
  382. if (isset($data['author']) && $data['author']) {
  383. array_push($where, ['article.author', '=', $data['author']]);
  384. }
  385. if (isset($data['islink']) && $data['islink'] !== "") {
  386. array_push($where, ['article.islink', '=', $data['islink']]);
  387. }
  388. if (isset($data['status']) && $data['status'] !== "") {
  389. array_push($where, ['article.status', '=', $data['status']]);
  390. }
  391. if (isset($data['status1'])) {
  392. $status1 = json_decode(($data['status1']));
  393. }
  394. //不是管理员展示个人数据;
  395. if ($type_id != 10000) {
  396. $where[] = ['article.admin_user_id', '=', $user_id];
  397. }
  398. $startTime = microtime(true);
  399. $rep = Article::query()
  400. // 预加载相关关联
  401. ->with([
  402. 'category' => function ($query) {
  403. $query->select('id', 'name');
  404. },
  405. 'websiteCategory' => function ($query) {
  406. $query->select('website_id', 'category_id', 'alias');
  407. },'user' => function ($query) {
  408. $query->select('id', 'nickname');
  409. }
  410. ])
  411. // 构建where条件
  412. ->when(isset($data['id']) && $data['id'], function ($query) use ($data) {
  413. $query->where('article.id', '=', $data['id']);
  414. })
  415. ->when(isset($data['title']) && $data['title'], function ($query) use ($data) {
  416. $query->where('article.title', 'like', '%' . $data['title'] . '%');
  417. })
  418. ->when(isset($data['category_name']) && $data['category_name'], function ($query) use ($data) {
  419. // 使用子查询替代左连接进行模糊搜索
  420. $query->whereHas('category', function ($subQuery) use ($data) {
  421. $subQuery->where('name', 'like', '%' . $data['category_name'] . '%');
  422. });
  423. })
  424. ->when(isset($data['catid']) && $data['catid'], function ($query) use ($data) {
  425. $query->where('article.catid', '=', $data['catid']);
  426. })
  427. ->when(isset($data['author']) && $data['author'], function ($query) use ($data) {
  428. $query->where('article.author', '=', $data['author']);
  429. })
  430. ->when(isset($data['islink']) && $data['islink'] !== "", function ($query) use ($data) {
  431. $query->where('article.islink', '=', $data['islink']);
  432. })
  433. ->when(isset($data['status']) && $data['status'] !== "", function ($query) use ($data) {
  434. $query->where('article.status', '=', $data['status']);
  435. })
  436. ->when(isset($data['status1']) && $data['status1'], function ($query) use ($data) {
  437. // 安全地处理JSON字符串
  438. $status1 = is_array($data['status1']) ? $data['status1'] : json_decode($data['status1'], true) ?? [];
  439. if (!empty($status1)) {
  440. $query->whereIn('article.status', $status1);
  441. }
  442. })
  443. ->select('article.*')
  444. // 非管理员限制
  445. ->when($type_id != 10000, function ($query) use ($user_id) {
  446. // 非管理员只能看自己的文章,同时把 article_ignore 的 c_show_time 一起查出来
  447. $query->where('article.admin_user_id', $user_id)
  448. ->leftJoin('article_ignore', function ($join) {
  449. // 关联条件:article.id = article_ignore.article_id 且 article.web_site_id = article_ignore.website_id
  450. $join->on('article_ignore.article_id', '=', 'article.id')
  451. ->whereColumn('article_ignore.website_id', 'article.web_site_id');
  452. })
  453. ->addSelect('article_ignore.article_id','article_ignore.c_show_time'); // 用 addSelect 追加字段,避免覆盖原有 select
  454. })
  455. // 基础条件
  456. ->whereNotIn('article.status', [404])
  457. // 排序和分页
  458. ->orderBy('article.updated_at', 'desc')
  459. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  460. // 获取结果并格式化
  461. $data = [
  462. 'rows' => $rep->items(),
  463. 'count' => $rep->total(),
  464. ];
  465. // 执行查询
  466. $endTime = microtime(true);
  467. $executionTime = ($endTime - $startTime) * 1000;
  468. echo "查询执行时间: {$executionTime}ms\n";
  469. return Result::success($data);
  470. }
  471. /**
  472. * @param array $data
  473. * @return array
  474. */
  475. public function addArticle(array $data): array
  476. {
  477. var_dump($data, '----------12-----------1');
  478. // ------c_show_time********add***1****
  479. $is_collect = $data['is_collect'] ?? 0;
  480. $user_type = $data['user_type'];
  481. unset($data['is_collect']);
  482. unset($data['user_type']);
  483. // ------c_show_time********add***1****
  484. unset($data['nav_add_pool_id']);
  485. // unset($data['commend_id']);
  486. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  487. Db::beginTransaction();
  488. try {
  489. //处理投票
  490. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  491. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  492. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  493. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  494. unset($data['is_survey']);
  495. unset($data['survey_name']);
  496. unset($data['suvey_array']);
  497. // unset($data['website_id']);
  498. // unset($data['web_site_id']);
  499. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  500. if ($data['hits'] == '') {
  501. $data['hits'] = 0;
  502. }
  503. if ($data['is_original'] == '') {
  504. $data['is_original'] = 0;
  505. }
  506. if ($data['status'] == '') {
  507. $data['status'] = 0;
  508. }
  509. $articleData = $data;
  510. unset($articleData['content']);
  511. //自动处理缩略图、关键字、描述
  512. if ($articleData['imgurl'] == '') {
  513. //如果没有图,设置level=0
  514. $levelArr = json_decode($articleData['level'], true);
  515. var_dump($levelArr, '----------levelArr-----------1');
  516. //content中提取图片第一个图,正则提取
  517. // -------采集器相关优化-----
  518. // 优化正则表达式,仅匹配 src 属性值,避免匹配到多余内容
  519. if ($is_collect == 1) {
  520. $reg = '/<img.*?src=[\'"]?((?!.*\.gif)[^\'" >]+)[\'"]?.*?>/i';
  521. } else {
  522. $reg = '/<img.*?src=[\'"]?([^\'" >]+)[\'"]?.*?>/i';
  523. }
  524. // -------采集器相关优化-----
  525. preg_match_all($reg, $data['content'], $matches);
  526. if (isset($matches[1][0])) {
  527. //截取varchar240
  528. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  529. //如果有图,设置level=3
  530. if (!in_array(3, $levelArr)) {
  531. $levelArr[] = 3;
  532. }
  533. $articleData['level'] = json_encode($levelArr);
  534. } else {
  535. if (!in_array(0, $levelArr)) {
  536. $levelArr[] = 0;
  537. }
  538. $articleData['level'] = json_encode($levelArr);
  539. }
  540. }
  541. var_dump($articleData['level'], '----------$articleData[level]----------1');
  542. if ($articleData['keyword'] == '') {
  543. //提取标题+内容中的关键词
  544. $articleData['keyword'] = $data['title'];
  545. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  546. Jieba::init(); // 初始化 jieba-php
  547. Finalseg::init();
  548. $segList = Jieba::cut($articleData['keyword']);
  549. $segList1 = array_slice($segList, 0, 8);
  550. $articleData['keyword'] = implode(',', $segList1);
  551. }
  552. if ($articleData['introduce'] == '') {
  553. //提取内容中的描述
  554. $content = $data['content'];
  555. // 去除 <style> 和 <script> 标签及其内容
  556. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  557. // 去除所有 HTML 标签
  558. $content = strip_tags($content);
  559. // 去除 HTML 实体
  560. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  561. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  562. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  563. // 去除多余空白
  564. $content = preg_replace('/\s+/u', '', $content);
  565. // 截取 100 个字符
  566. $articleData['introduce'] = mb_substr($content, 0, 100);
  567. }
  568. if ($articleData['status'] == 0) {
  569. $this->sendMessage([
  570. 'talk_type' => 100,
  571. 'title' => $articleData['title'],
  572. 'content' => '提交了审核',
  573. 'messageType' => 2,
  574. ]);
  575. }
  576. if(!empty($data['fujian'])){
  577. $articleData['fujian'] = $data['fujian'];
  578. }
  579. $id = Article::insertGetId($articleData);
  580. if (!$id) {
  581. throw new \Exception('文章插入失败');
  582. }
  583. $articleDataContent = [
  584. 'article_id' => $id,
  585. 'content' => $data['content'],
  586. ];
  587. // 采集器中的文章内容,在添加时,去掉div标签
  588. if ($is_collect == 1) {
  589. // 采集来的文章,content中可能包含div标签,需要先移除
  590. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  591. $article_data = preg_replace($pattern, '', $data['content']);
  592. $$articleDataContent['content'] = $article_data;
  593. }
  594. $contentInsertId = ArticleData::insertGetId($articleDataContent);
  595. if (!$contentInsertId) {
  596. throw new \Exception('文章内容插入失败');
  597. }
  598. // ------c_show_time********add***2****
  599. // 直接使用当前系统时间,不再强制添加8小时
  600. $now = date('Y-m-d H:i:s');
  601. if ($user_type == 10000 || $is_collect == 1) {
  602. // 管理员添加文章时,核心站c端显示时间就是创建时间;非核心站c端显示时间就是此创建时间往后推二十分钟;
  603. // 非管理员添加文章时,不做操作只有在审核通过时获取c端显示时间
  604. if (!isset($data['catid'])) {
  605. throw new \Exception('缺少必要字段:catid');
  606. }
  607. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  608. $web = WebsiteCategory::where('category_id', $data['catid'])
  609. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  610. ->select(
  611. 'website_id',
  612. 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')
  613. )
  614. ->get();
  615. // $id = 225; -----测试开启
  616. // 采集来的文章,错开时间在两小时之内发布
  617. if ($user_type == 10000 && $is_collect == 1) {
  618. $web_num = $web->where('is_core', '!=', 2)->count();
  619. $waiting_interval = 10;
  620. if ($web_num > 12) {
  621. // 若网站数量大于12个,则每个网站间隔时间取均值
  622. // 防止除数为 0,虽然这里 $web_num 是 count 结果不会为 0,但做健壮性检查
  623. $waiting_interval = 120 / max(1, $web_num);
  624. }
  625. $time = 0;
  626. } else {
  627. // 非核心站与核心站----显示时间-----间隔
  628. $time = 20;
  629. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  630. $waiting_interval = 5;
  631. }
  632. // 将 Hyperf\Database\Model\Collection 转换为数组
  633. $webArray = $web->toArray();
  634. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $id, $waiting_interval, $is_collect) {
  635. // 检查 $item 对象是否有 is_core 属性
  636. if (!isset($item['is_core'])) {
  637. throw new \Exception('$item 对象缺少 is_core 属性');
  638. }
  639. // 当 is_core 为 2 时,则表示此网站不存在
  640. if ($item['is_core'] == 2) {
  641. return null;
  642. }
  643. if ($is_collect == 1) {
  644. // 采集来的文章,错开时间在两小时之内发布
  645. // $time = 0;
  646. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  647. $time += $waiting_interval;
  648. } else if ($item['is_core'] == 1) {
  649. // 当 is_core 为 1 时,则表示此网站是核心站
  650. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  651. } else {
  652. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  653. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  654. if ($item['is_core'] == 0) {
  655. $time += $waiting_interval;
  656. }
  657. }
  658. return [
  659. 'article_id' => $id,
  660. 'website_id' => $item['website_id'],
  661. 'c_show_time' => $c_show_time,
  662. // 'is_core' => $item['is_core'],
  663. // 'time' => $time
  664. ];
  665. }, array_keys($webArray), $webArray)));
  666. // Db::commit();
  667. // return Result::success($article_ignore);
  668. if (!empty($article_ignore)) {
  669. $article_ignores = ArticleIgnore::insert($article_ignore);
  670. if (!$article_ignores) {
  671. throw new \Exception('c端展示时间插入失败');
  672. }
  673. }
  674. }
  675. // ------c_show_time********add***2****
  676. //处理投票
  677. if ($is_survey == 1) {
  678. //生成年月日时分秒+8位随机数
  679. $uuid = date('YmdHis') . rand(10000000, 99999999);
  680. var_dump($suvey_array, 'suvey_array________');
  681. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  682. var_dump($suveys_array, '---------------------1');
  683. var_dump($suvey_array, '---------------------2');
  684. $suvey_data = [];
  685. foreach ($suveys_array as $key => $value) {
  686. if ($value == '') {
  687. continue;
  688. }
  689. if (is_array($value)) {
  690. $suvey_data[] = [
  691. 'sur_id' => $uuid,
  692. 'art_id' => $id,
  693. 'website_id' => $website_id ?? 2,
  694. 'survey_name' => $survey_name,
  695. 'choice_name' => $value[1],
  696. 'is_other' => 1,
  697. 'other_id' => 0,
  698. 'results' => 0,
  699. ];
  700. } else {
  701. $suvey_data[] = [
  702. 'sur_id' => $uuid,
  703. 'art_id' => $id,
  704. 'website_id' => $website_id ?? 2,
  705. 'survey_name' => $survey_name,
  706. 'choice_name' => $value,
  707. 'is_other' => 0,
  708. 'other_id' => 0,
  709. 'results' => 0,
  710. ];
  711. }
  712. if (empty($suvey_data)) {
  713. throw new \Exception("投票数据为空");
  714. }
  715. }
  716. $result = ArticleSurvey::insert($suvey_data);
  717. if (!$result) {
  718. throw new \Exception("投票失败,ArticleSurvey插入失败");
  719. }
  720. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  721. if (!$result) {
  722. throw new \Exception("投票失败,更新主表失败");
  723. }
  724. }
  725. Db::commit();
  726. return Result::success(['id' => $id]);
  727. } catch (\Throwable $ex) {
  728. Db::rollBack();
  729. var_dump($ex->getMessage());
  730. return Result::error("创建失败", 0);
  731. }
  732. }
  733. /**
  734. * @param array $data
  735. * @return array
  736. */
  737. public function delArticle(array $data): array
  738. {
  739. // ------c_show_time********del*******
  740. Db::beginTransaction();
  741. try {
  742. $article = Article::where(['id' => $data['id']])->delete();
  743. // 若文章删除失败,抛出异常,后续 SQL 语句不会执行
  744. if (!$article) {
  745. throw new \Exception("删除失败,文章删除失败");
  746. }
  747. //survey投票删除
  748. ArticleSurvey::where(['art_id' => $data['id']])->delete(); // 修正类名大小写
  749. $articleIgnore = ArticleIgnore::where(['article_id' => $data['id']])->delete();
  750. $article_data = ArticleData::where(['article_id' => $data['id']])->delete();
  751. // 若文章详情删除失败,抛出异常
  752. if (!$article_data) {
  753. throw new \Exception("删除失败,文章详情删除失败");
  754. }
  755. Db::commit(); // 所有操作成功,提交事务
  756. } catch (\Throwable $ex) {
  757. Db::rollBack();
  758. var_dump($ex->getMessage());
  759. return Result::error("删除失败: " . $ex->getMessage(), 0);
  760. }
  761. // ------c_show_time********del*******
  762. if (!$article) {
  763. return Result::error("删除失败");
  764. }
  765. return Result::success($article);
  766. }
  767. /**
  768. * @param array $data
  769. * @return array
  770. */
  771. public function updateArticle(array $data): array
  772. {
  773. var_dump($data, '----------12-----------1');
  774. Db::beginTransaction();
  775. // ------c_show_time********up*******
  776. $user_type = isset($data['user_type']) ? $data['user_type'] : 0;
  777. // 无论是否改变了c端显示时间或者栏目,都需要将未屏蔽的网站显示时间删除记录
  778. // 若是存在交集,则进行修改,若无,则合并(此表中的记录应该包含被屏蔽网站及涉及所有网站的展示时间)
  779. $web = WebsiteCategory::where('category_id', $data['catid'])
  780. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  781. ->select(
  782. 'website_id',
  783. 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')
  784. )
  785. ->get();
  786. // 根据错误信息,问题在于 $web 可能是一个包含对象的集合,不能直接用于 whereNotIn 方法
  787. // 先从 $web 集合中提取 website_id 字段的值,再进行删除操作
  788. $websiteIds = $web->pluck('website_id')->toArray();
  789. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  790. if ($user_type == 0) {
  791. throw new \Exception("用户类型不能为空");
  792. }
  793. if ($user_type == 10000) {
  794. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  795. $web = WebsiteCategory::where('category_id', $data['catid'])
  796. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  797. ->select(
  798. 'website_id',
  799. 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')
  800. )
  801. ->get();
  802. // 非核心站与核心站----显示时间-----间隔
  803. $time = 20;
  804. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  805. $waiting_interval = 5;
  806. $webArray = $web->toArray();
  807. if (empty($webArray)) {
  808. throw new \Exception('网站分类不存在');
  809. }
  810. // 直接使用当前系统时间,不再强制添加8小时
  811. $now = date('Y-m-d H:i:s');
  812. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  813. // 检查 $item 对象是否有 is_core 属性
  814. if (!isset($item['is_core'])) {
  815. throw new \Exception('$item 对象缺少 is_core 属性');
  816. }
  817. // 当 is_core 为 2 时,则表示此网站不存在
  818. if ($item['is_core'] == 2) {
  819. return null;
  820. } else if ($item['is_core'] == 1) {
  821. // 当 is_core 为 1 时,则表示此网站是核心站
  822. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  823. } else {
  824. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  825. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  826. if ($item['is_core'] == 0) {
  827. $time += $waiting_interval;
  828. }
  829. }
  830. return [
  831. 'article_id' => $data['id'],
  832. 'website_id' => $item['website_id'],
  833. 'c_show_time' => $c_show_time,
  834. ];
  835. }, array_keys($webArray), $webArray)));
  836. if (!empty($article_ignore)) {
  837. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  838. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  839. $article_ignores = ArticleIgnore::upsert(
  840. $article_ignore,
  841. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  842. ['c_show_time'] // 需要更新的字段
  843. );
  844. if (!$article_ignores) {
  845. throw new \Exception('c端展示时间插入失败');
  846. }
  847. }
  848. // Db::commit();
  849. // return Result::success($article_ignore);
  850. }
  851. // ------c_show_time********up*******
  852. unset($data['user_type']);
  853. // unset($data['web_site_id']);
  854. unset($data['nav_add_pool_id']);
  855. try {
  856. //处理投票
  857. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  858. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  859. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  860. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  861. unset($data['is_survey']);
  862. unset($data['survey_name']);
  863. unset($data['suvey_array']);
  864. unset($data['website_id']);
  865. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  866. if ($data['hits'] == '') {
  867. $data['hits'] = 0;
  868. }
  869. if ($data['is_original'] == '') {
  870. $data['is_original'] = 0;
  871. }
  872. if ($data['status'] == '') {
  873. $data['status'] = 0;
  874. }
  875. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  876. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  877. $articleData = $data;
  878. unset($articleData['content']);
  879. unset($articleData['status_name']);
  880. unset($articleData['name']);
  881. unset($articleData['content']);
  882. unset($articleData['pid_arr']);
  883. unset($articleData['pid']);
  884. //自动处理缩略图、关键字、描述
  885. if ($articleData['imgurl'] == '') {
  886. //如果没有图,设置level=0
  887. $levelArr = json_decode($articleData['level'], true);
  888. var_dump($levelArr, '----------levelArr-----------1');
  889. //content中提取图片第一个图,正则提取
  890. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  891. preg_match_all($reg, $data['content'], $matches);
  892. if (isset($matches[1][0])) {
  893. //截取varchar240
  894. // 截取到第一个<
  895. $articleData['imgurl'] = $matches[1][0];
  896. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  897. $pos = strpos($articleData['imgurl'], '"');
  898. if ($pos !== false) {
  899. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  900. }
  901. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  902. //如果有图,设置level=3
  903. if (!in_array(3, $levelArr)) {
  904. $levelArr[] = 3;
  905. }
  906. $articleData['level'] = json_encode($levelArr);
  907. } else {
  908. if (!in_array(0, $levelArr)) {
  909. $levelArr[] = 0;
  910. }
  911. $articleData['level'] = json_encode($levelArr);
  912. }
  913. }
  914. var_dump($articleData['level'], '----------$articleData[level]----------1');
  915. if ($articleData['keyword'] == '') {
  916. //提取标题+内容中的关键词
  917. $articleData['keyword'] = $data['title'];
  918. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  919. Jieba::init(); // 初始化 jieba-php
  920. Finalseg::init();
  921. $segList = Jieba::cut($articleData['keyword']);
  922. $segList1 = array_slice($segList, 0, 8);
  923. $articleData['keyword'] = implode(',', $segList1);
  924. }
  925. if ($articleData['introduce'] == '') {
  926. //提取内容中的描述
  927. $content = $data['content'];
  928. // 去除 <style> 和 <script> 标签及其内容
  929. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  930. // 去除所有 HTML 标签
  931. $content = strip_tags($content);
  932. // 去除 HTML 实体
  933. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  934. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  935. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  936. // 去除多余空白
  937. $content = preg_replace('/\s+/u', '', $content);
  938. // 截取 100 个字符
  939. $articleData['introduce'] = mb_substr($content, 0, 100);
  940. }
  941. if ($articleData['status'] == 0) {
  942. $this->sendMessage([
  943. 'talk_type' => 100,
  944. 'title' => $articleData['title'],
  945. 'content' => '提交了审核',
  946. 'messageType' => 2,
  947. ]);
  948. }
  949. if(!empty($data['fujian'])){
  950. $articleData['fujian'] = $data['fujian'];
  951. }
  952. $id = Article::where(['id' => $data['id']])->update($articleData);
  953. // $articleDataContent = [
  954. // 'content' => $data['content'],
  955. // ];
  956. // 采集来的文章,content中可能包含div标签,需要先移除
  957. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  958. $article_data = preg_replace($pattern, '', $data['content']);
  959. $articleDataContent['content'] = $article_data;
  960. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  961. //处理投票
  962. $id = $data['id'];
  963. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  964. var_dump($suvey_array, 'suvey_array________delete');
  965. //处理投票
  966. if ($is_survey == 1) {
  967. //生成年月日时分秒+8位随机数
  968. $uuid = date('YmdHis') . rand(10000000, 99999999);
  969. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  970. var_dump($suveys_array, '---------------------1');
  971. $suvey_data = [];
  972. if (is_array($suveys_array)) {
  973. foreach ($suveys_array as $key => $value) {
  974. if ($value == '') {
  975. continue;
  976. }
  977. if (is_array($value)) {
  978. $suvey_data[] = [
  979. 'sur_id' => $uuid,
  980. 'art_id' => $id,
  981. 'website_id' => $website_id ?? 2,
  982. 'survey_name' => $survey_name,
  983. 'choice_name' => $value[1],
  984. 'is_other' => 1,
  985. 'other_id' => 0,
  986. 'results' => 0,
  987. ];
  988. } else {
  989. $suvey_data[] = [
  990. 'sur_id' => $uuid,
  991. 'art_id' => $id,
  992. 'website_id' => $website_id ?? 2,
  993. 'survey_name' => $survey_name,
  994. 'choice_name' => $value,
  995. 'is_other' => 0,
  996. 'other_id' => 0,
  997. 'results' => 0,
  998. ];
  999. }
  1000. if (empty($suvey_data)) {
  1001. throw new \Exception("投票数据为空");
  1002. }
  1003. }
  1004. }
  1005. $result = ArticleSurvey::insert($suvey_data);
  1006. if (!$result) {
  1007. throw new \Exception("投票失败");
  1008. }
  1009. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  1010. if (!$result) {
  1011. throw new \Exception("投票失败");
  1012. }
  1013. } else {
  1014. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  1015. }
  1016. Db::commit();
  1017. return Result::success([]);
  1018. } catch (\Throwable $ex) {
  1019. Db::rollBack();
  1020. var_dump($ex->getMessage());
  1021. return Result::error("更新失败" . $ex->getMessage(), 0);
  1022. }
  1023. }
  1024. /**
  1025. * 更新资讯状态
  1026. * @param array $data
  1027. * @return array
  1028. */
  1029. public function upArticleStatus(array $data): array
  1030. {
  1031. $articleData = Article::where(['id' => $data['id']])->first();
  1032. //发送10次
  1033. // for ($i = 0; $i < 10; $i++) {
  1034. // $this->sendMessage([
  1035. // 'talk_type' => 100,
  1036. // 'title' => $i . $articleData['title'],
  1037. // 'content' => '审核通过',
  1038. // 'messageType' => 2,
  1039. // 'user_id' => $articleData['admin_user_id'],
  1040. // ]);
  1041. // }
  1042. // var_dump($data['status'], 'status');
  1043. // return Result::success();
  1044. if ($data['status'] == 1) {
  1045. $this->sendMessage([
  1046. 'talk_type' => 101,
  1047. 'title' => $articleData['title'],
  1048. 'content' => '审核通过',
  1049. 'messageType' => 2,
  1050. 'user_id' => $articleData['admin_user_id'],
  1051. ]);
  1052. }
  1053. if ($data['status'] == 2) {
  1054. $this->sendMessage([
  1055. 'talk_type' => 101,
  1056. 'title' => $articleData['title'],
  1057. 'content' => '审核拒绝',
  1058. 'messageType' => 2,
  1059. 'user_id' => $articleData['admin_user_id'],
  1060. ]);
  1061. }
  1062. if ($data['status'] == 0) {
  1063. $this->sendMessage([
  1064. 'talk_type' => 100,
  1065. 'title' => $articleData['title'],
  1066. 'content' => '提交了审核',
  1067. 'messageType' => 2,
  1068. ]);
  1069. }
  1070. $result = Article::where(['id' => $data['id']])->update($data);
  1071. // ------c_show_time********up_status*******
  1072. // 若是审核通过 则更新c_show_time
  1073. if ($data['status'] == 1) {
  1074. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  1075. $web = Article::where('article.id', $data['id'])
  1076. ->leftJoin('website_category', 'article.catid', 'website_category.category_id')
  1077. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  1078. ->select(
  1079. 'website_id',
  1080. 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')
  1081. )
  1082. ->get();
  1083. // 非核心站与核心站----显示时间-----间隔
  1084. $time = 20;
  1085. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  1086. $waiting_interval = 5;
  1087. $webArray = $web->toArray();
  1088. if (empty($webArray)) {
  1089. throw new \Exception('网站分类不存在');
  1090. }
  1091. // 直接使用当前系统时间,不再强制添加8小时
  1092. $now = date('Y-m-d H:i:s');
  1093. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  1094. if (isset($data['ignore_ids'])) {
  1095. $ignore_website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  1096. if (in_array($item['website_id'], $ignore_website_ids)) {
  1097. $is_ignore = 1;
  1098. } else {
  1099. $is_ignore = 0;
  1100. }
  1101. return [
  1102. 'article_id' => $data['id'],
  1103. 'website_id' => $item['website_id'],
  1104. 'is_ignore' => $is_ignore,
  1105. ];
  1106. } else {
  1107. // 检查 $item 对象是否有 is_core 属性
  1108. if (!isset($item['is_core'])) {
  1109. throw new \Exception('$item 对象缺少 is_core 属性');
  1110. }
  1111. // 当 is_core 为 2 时,则表示此网站不存在
  1112. if ($item['is_core'] == 2) {
  1113. return null;
  1114. } else if ($item['is_core'] == 1) {
  1115. // 当 is_core 为 1 时,则表示此网站是核心站
  1116. $c_show_time = $now;
  1117. } else {
  1118. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  1119. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  1120. if ($item['is_core'] == 0) {
  1121. $time += $waiting_interval;
  1122. }
  1123. }
  1124. return [
  1125. 'article_id' => $data['id'],
  1126. 'website_id' => $item['website_id'],
  1127. 'c_show_time' => $c_show_time,
  1128. ];
  1129. }
  1130. }, array_keys($webArray), $webArray)));
  1131. if (!empty($article_ignore) && !isset($data['ignore_ids'])) {
  1132. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  1133. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  1134. $websiteIds = $web->pluck('website_id')->toArray();
  1135. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  1136. $article_ignores = ArticleIgnore::upsert(
  1137. $article_ignore,
  1138. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1139. ['c_show_time'] // 需要更新的字段
  1140. );
  1141. if (!$article_ignores) {
  1142. throw new \Exception('c端展示时间插入失败');
  1143. }
  1144. }
  1145. if (!empty($data['ignore_ids'])) {
  1146. // return Result::success($article_ignore);
  1147. // 从数据库中删除 article_id 为 $data['id'] 且 website_id 在 $website_ids 中的记录
  1148. if (!empty($article_ignore)) {
  1149. $article_ignores = ArticleIgnore::upsert(
  1150. $article_ignore,
  1151. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1152. ['is_ignore'] // 需要更新的字段
  1153. );
  1154. // if(!$article_ignores){
  1155. // throw new \Exception('屏蔽网站更新失败');
  1156. // }
  1157. }
  1158. }
  1159. }
  1160. // ------c_show_time********up_status*******
  1161. if ($result) {
  1162. return Result::success();
  1163. } else {
  1164. return Result::error("更新状态失败", 0);
  1165. }
  1166. }
  1167. /**
  1168. * 获取新闻详情
  1169. * @param array $data
  1170. * @return array
  1171. */
  1172. public function getArticleInfo(array $data): array
  1173. {
  1174. $where = [
  1175. 'article.id' => $data['id'],
  1176. // 'article.status' => 1,
  1177. ];
  1178. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  1179. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  1180. $info = $result;
  1181. // var_dump($info, 'info');
  1182. $info['survey_array'] = $articleSurvey;
  1183. if ($result) {
  1184. return Result::success($info);
  1185. } else {
  1186. return Result::error("查询失败", 0);
  1187. }
  1188. }
  1189. /**
  1190. * 获取头条新闻
  1191. * @param array $data
  1192. * @return array
  1193. */
  1194. public function getWebsiteArticlett(array $data): array
  1195. {
  1196. $website_id = $data['website_id'];
  1197. $website = Website::where('id', $data['website_id'])->first();
  1198. if (empty($website)) {
  1199. return Result::error("网站不存在", 0);
  1200. }
  1201. $categorys = $this->processArticlePro($website_id);
  1202. $catiall = $categorys['catiall'];
  1203. $categoryIds = $categorys['categoryIds'];
  1204. $where = [
  1205. 'status' => 1
  1206. ];
  1207. // $website_column = $website['column'];
  1208. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1209. $website_column = json_decode($website['website_column_arr_id'], true);
  1210. }
  1211. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1212. // return Result::success($diff_pid_categoryIds);
  1213. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1214. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1215. }
  1216. // $website_id = $data['website_id'];
  1217. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  1218. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  1219. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  1220. switch ($data['level']) {
  1221. case 1:
  1222. case 2:
  1223. case 3:
  1224. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  1225. $query = Article::where($where)
  1226. ->where('level', 'like', '%' . $data['level'] . '%')
  1227. ->orderBy('updated_at', 'desc');
  1228. break;
  1229. case 4: //最新资讯
  1230. $query = Article::where($where)->orderBy('updated_at', 'desc');
  1231. break;
  1232. case 5: //资讯推荐
  1233. $query = Article::where($where)
  1234. ->where('updated_at', '>', $month);
  1235. break;
  1236. case 7: //资讯分类
  1237. if (isset($data['id']) && !empty($data['id'])) {
  1238. $keyword = Article::where('id', $data['id'])->value('keyword');
  1239. $keywordArray = explode(',', $keyword);
  1240. $whereL7 = [];
  1241. foreach ($keywordArray as $k => $v) {
  1242. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1243. }
  1244. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  1245. break;
  1246. } else {
  1247. return Result::error("请输入资讯ID", 0);
  1248. break;
  1249. }
  1250. default:
  1251. break;
  1252. }
  1253. // $whereL7 = [];
  1254. // if(isset($data['id']) && !empty($data['id'])){
  1255. // $keyword = Article::where('id', $data['id'])->value('keyword');
  1256. // $keywordArray = explode(',', $keyword);
  1257. // foreach ($keywordArray as $k => $v) {
  1258. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1259. // }
  1260. // }
  1261. // $query = Article::where($where)
  1262. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  1263. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  1264. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  1265. // }
  1266. // if($data['level'] == 7){
  1267. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  1268. // }
  1269. // if($data['level'] == 4){
  1270. // $query = $query->inRandomOrder()
  1271. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  1272. // }
  1273. // if($data['level'] == 5){
  1274. // $query = $query->orderBy('updated_at','desc');
  1275. // }
  1276. // });
  1277. if ($data['textnum'] > 0) {
  1278. $query = clone $query;
  1279. $result['text'] = $query
  1280. ->whereIn('catid', $categoryIds)
  1281. ->leftJoinSub(function ($query) use ($website_id) {
  1282. $query->from('article_ignore')
  1283. ->where('website_id', $website_id);
  1284. }, 'article_ignore', function ($join) {
  1285. $join->on('article_ignore.article_id', '=', 'article.id');
  1286. })
  1287. ->where(function ($query) {
  1288. $query->whereNull('article_ignore.article_id')
  1289. ->orWhere(function ($subQuery) {
  1290. $subQuery->whereNotNull('article_ignore.article_id')
  1291. ->where('article_ignore.is_ignore', 0)
  1292. ->where(function ($subSubQuery) {
  1293. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1294. ->orWhereNull('article_ignore.c_show_time');
  1295. });
  1296. });
  1297. })
  1298. // ->where(function ($query) use ($website_id) {
  1299. // $query->whereNull('article_ignore.article_id')
  1300. // ->orWhere('article_ignore.website_id', '!=', $website_id);
  1301. // })
  1302. ->select(
  1303. 'article.id',
  1304. 'article.title',
  1305. 'article.author',
  1306. 'article.updated_at',
  1307. 'article.introduce',
  1308. 'article.islink',
  1309. 'article.linkurl',
  1310. 'article.copyfrom',
  1311. 'article.cat_arr_id',
  1312. 'article.catid',
  1313. 'article.level',
  1314. // 'article_ignore.is_ignore',
  1315. // 'article_ignore.c_show_time',
  1316. )
  1317. ->offset($data['placeid'])
  1318. ->limit($data['textnum'])
  1319. ->get()->all();
  1320. foreach ($result['text'] as $k => $v) {
  1321. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1322. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  1323. }
  1324. }
  1325. if ($data['imgnum'] > 0) {
  1326. $query = clone $query;
  1327. if ($data['textnum'] == 0) {
  1328. $query = $query->leftJoinSub(function ($query) use ($website_id) {
  1329. $query->from('article_ignore')
  1330. ->where('website_id', $website_id);
  1331. }, 'article_ignore', function ($join) {
  1332. $join->on('article_ignore.article_id', '=', 'article.id');
  1333. })
  1334. ->where(function ($query) {
  1335. $query->whereNull('article_ignore.article_id')
  1336. ->orWhere(function ($subQuery) {
  1337. $subQuery->whereNotNull('article_ignore.article_id')
  1338. ->where('article_ignore.is_ignore', 0)
  1339. ->where(function ($subSubQuery) {
  1340. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1341. ->orWhereNull('article_ignore.c_show_time');
  1342. });
  1343. });
  1344. });
  1345. }
  1346. $result['img'] = $query
  1347. ->whereIn('catid', $categoryIds)
  1348. ->where('article.imgurl', '!=', '')
  1349. ->select(
  1350. 'article.id',
  1351. 'article.title',
  1352. 'article.imgurl',
  1353. 'article.author',
  1354. 'article.updated_at',
  1355. 'article.introduce',
  1356. 'article.islink',
  1357. 'article.linkurl',
  1358. 'article.copyfrom',
  1359. 'article.cat_arr_id',
  1360. 'article.catid',
  1361. 'article.level',
  1362. // 'article_ignore.is_ignore',
  1363. // 'article_ignore.c_show_time',
  1364. )
  1365. ->offset($data['placeid'])
  1366. ->limit($data['imgnum'])
  1367. ->get()->all();
  1368. foreach ($result['img'] as $k => $v) {
  1369. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1370. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1371. }
  1372. }
  1373. if (empty($result)) {
  1374. return Result::error("暂无相关资讯", 0);
  1375. }
  1376. return Result::success($result);
  1377. }
  1378. /**
  1379. * 获取模块新闻
  1380. * @param array $data
  1381. * @return array
  1382. */
  1383. public function getWebsiteModelArticles(array $data): array
  1384. {
  1385. $catid = $data['catid'];
  1386. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1387. $category = $category->toArray();
  1388. if (!empty($category)) {
  1389. $where = [
  1390. 'status' => 1,
  1391. 'catid' => $catid,
  1392. ];
  1393. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1394. // 1:文字新闻;2:轮播图;3:图文;
  1395. // 级别:0:未分类
  1396. // 3:推荐图片
  1397. if ($data['level'] == 1) {
  1398. $data['level'] = 0;
  1399. }
  1400. $result = Article::where($where)
  1401. ->where(function ($query) use ($data) {
  1402. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1403. ->orWhereNull("level")
  1404. ->orWhereRaw("level = '[]'");
  1405. })
  1406. ->leftJoinSub(function ($query) use ($data) {
  1407. $query->from('article_ignore')
  1408. ->where('website_id', $data['website_id']);
  1409. }, 'article_ignore', function ($join) {
  1410. $join->on('article_ignore.article_id', '=', 'article.id');
  1411. })
  1412. ->where(function ($query) {
  1413. $query->whereNull('article_ignore.article_id')
  1414. ->orWhere(function ($subQuery) {
  1415. $subQuery->whereNotNull('article_ignore.article_id')
  1416. ->where('article_ignore.is_ignore', 0)
  1417. ->where(function ($subSubQuery) {
  1418. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1419. ->orWhereNull('article_ignore.c_show_time');
  1420. });
  1421. });
  1422. })
  1423. // ->where(function ($query) use ($data) {
  1424. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1425. // ->orWhereNull("ignore_ids");
  1426. // })
  1427. ->orderBy("updated_at", "desc")
  1428. ->offset($placeid)
  1429. ->limit($data['pagesize'])
  1430. ->get();
  1431. if (empty($result)) {
  1432. return Result::error("此栏目暂无相关新闻", 0);
  1433. }
  1434. } else {
  1435. return Result::error("此网站暂无此栏目", 0);
  1436. }
  1437. return Result::success($result);
  1438. }
  1439. /**
  1440. *获取新闻列表
  1441. * @param array $data
  1442. * @return array
  1443. */
  1444. public function getWebsiteArticleList(array $data): array
  1445. {
  1446. // return Result::success($data);
  1447. $where[] = ['status', '=', 1];
  1448. $website_id = $data['website_id'];
  1449. $website = Website::where('id', $data['website_id'])->first();
  1450. if (empty($website)) {
  1451. return Result::error("网站不存在", 0);
  1452. }
  1453. // $website_column = $website['column'];
  1454. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1455. $website_column = json_decode($website['website_column_arr_id'], true);
  1456. }
  1457. $categorys = $this->processArticlePro($website_id);
  1458. $cat_1st_arr = $categorys['cat_1st_arr'];
  1459. $catiall = $categorys['catiall'];
  1460. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1461. // return Result::success($diff_pid_categoryIds);
  1462. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1463. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1464. }
  1465. if (isset($data['catid']) && !empty($data['catid'])) {
  1466. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1467. if (empty($category)) {
  1468. return Result::error("此网站暂无此栏目", 0);
  1469. }
  1470. array_push($where, ['catid', '=', $data['catid']]);
  1471. }
  1472. // return Result::success($where);
  1473. $query = Article::where($where)
  1474. ->leftJoinSub(function ($query) use ($website_id) {
  1475. $query->from('article_ignore')
  1476. ->where('website_id', $website_id);
  1477. }, 'article_ignore', function ($join) {
  1478. $join->on('article_ignore.article_id', '=', 'article.id');
  1479. })
  1480. ->where(function ($query) {
  1481. $query->whereNull('article_ignore.article_id')
  1482. ->orWhere(function ($subQuery) {
  1483. $subQuery->whereNotNull('article_ignore.article_id')
  1484. ->where('article_ignore.is_ignore', 0)
  1485. ->where(function ($subSubQuery) {
  1486. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1487. ->orWhereNull('article_ignore.c_show_time');
  1488. });
  1489. });
  1490. })
  1491. ->select(
  1492. 'article.id',
  1493. 'article.title',
  1494. 'article.imgurl',
  1495. 'article.author',
  1496. 'article.updated_at',
  1497. 'article.introduce',
  1498. 'article.islink',
  1499. 'article.linkurl',
  1500. 'article.copyfrom',
  1501. 'article.cat_arr_id',
  1502. 'article.catid'
  1503. );
  1504. $count = $query->count();
  1505. $rep = $query->orderBy("updated_at", "desc")
  1506. ->offset(($data['page'] - 1) * $data['pageSize'])
  1507. ->limit($data['pageSize'])
  1508. ->get()->all();
  1509. $categorys = $this->processArticlePro($website_id);
  1510. $cat_1st_arr = $categorys['cat_1st_arr'];
  1511. $catiall = $categorys['catiall'];
  1512. // $web['website_id'] = $data['website_id'];
  1513. foreach ($rep as $k => $v) {
  1514. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1515. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1516. }
  1517. // $rep = $this->processArticles($rep,$web);
  1518. $data = [
  1519. 'rows' => $rep,
  1520. 'count' => $count,
  1521. ];
  1522. if (empty($rep)) {
  1523. return Result::error("没有信息数据");
  1524. }
  1525. return Result::success($data);
  1526. }
  1527. /**
  1528. * 前端-获取新闻详情
  1529. * @param array $data
  1530. * @return array
  1531. */
  1532. public function selectWebsiteArticleInfo(array $data): array
  1533. {
  1534. $where = [
  1535. 'article.id' => $data['id'],
  1536. 'article.status' => 1,
  1537. ];
  1538. $result = Article::where($where)
  1539. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1540. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1541. // ->where(function ($query) use ($data) {
  1542. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1543. // ->orWhereNull("ignore_ids");
  1544. // })
  1545. ->leftJoinSub(function ($query) use ($data) {
  1546. $query->from('article_ignore')
  1547. ->where('website_id', $data['website_id']);
  1548. }, 'article_ignore', function ($join) {
  1549. $join->on('article_ignore.article_id', '=', 'article.id');
  1550. })
  1551. ->where(function ($query) {
  1552. $query->whereNull('article_ignore.article_id')
  1553. ->orWhere(function ($subQuery) {
  1554. $subQuery->whereNotNull('article_ignore.article_id')
  1555. ->where('article_ignore.is_ignore', 0)
  1556. ->where(function ($subSubQuery) {
  1557. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1558. ->orWhereNull('article_ignore.c_show_time');
  1559. });
  1560. });
  1561. })
  1562. ->select(
  1563. 'article.*',
  1564. 'article_data.content',
  1565. 'article_data.article_id',
  1566. 'article_extend.website_url',
  1567. 'article_extend.email',
  1568. 'article_extend.contacts',
  1569. 'article_extend.contacts_mobile',
  1570. 'article_extend.contacts_address',
  1571. 'article_extend.zip_code',
  1572. 'article_extend.enterprise_name'
  1573. )
  1574. ->first();
  1575. if (empty($result)) {
  1576. return Result::error("暂无此新闻!", 0);
  1577. }
  1578. if (!empty($result['publiced_at'])) {
  1579. $result['updated_at'] = $result['publiced_at'];
  1580. }
  1581. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1582. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1583. ->where('website_category.website_id', $data['website_id'])
  1584. ->where(['website_category.category_id' => $result['catid']])
  1585. ->first();
  1586. if (empty($category)) {
  1587. return Result::error("查询失败", 0);
  1588. }
  1589. //手动推荐文章
  1590. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1591. if (empty($commend_ids)) {
  1592. $commendArticle = [];
  1593. } else {
  1594. //去除不存在的文章ID
  1595. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1596. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1597. ->leftJoinSub(function ($query) use ($data) {
  1598. $query->from('article_ignore')
  1599. ->where('website_id', $data['website_id']);
  1600. }, 'article_ignore', function ($join) {
  1601. $join->on('article_ignore.article_id', '=', 'article.id');
  1602. })
  1603. ->where(function ($query) {
  1604. $query->whereNull('article_ignore.article_id')
  1605. ->orWhere(function ($subQuery) {
  1606. $subQuery->whereNotNull('article_ignore.article_id')
  1607. ->where('article_ignore.is_ignore', 0)
  1608. ->where(function ($subSubQuery) {
  1609. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1610. ->orWhereNull('article_ignore.c_show_time');
  1611. });
  1612. });
  1613. })
  1614. ->where('article.status', 1)
  1615. ->where('website_category.website_id', $data['website_id'])
  1616. ->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')
  1617. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1618. // ->orderBy('article.updated_at', 'desc')
  1619. ->limit(5)
  1620. ->get();
  1621. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1622. foreach ($commendArticle as $k => $v) {
  1623. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1624. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1625. $cat_arr_id = array_unique($cat_arr_id);
  1626. // 从website_category取出alias_pinyin
  1627. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1628. ->whereIn('category_id', $cat_arr_id)
  1629. ->pluck('alias_pinyin', 'category_id')
  1630. ->toArray();
  1631. // 将cat_arr_id的json转成路径/隔开
  1632. $path_parts = [];
  1633. foreach ($cat_arr_id as $cat_id) {
  1634. if (isset($cat_arr[$cat_id])) {
  1635. $path_parts[] = $cat_arr[$cat_id];
  1636. }
  1637. }
  1638. $v->alias_pinyin = implode('/', $path_parts);
  1639. } else {
  1640. $v->alias_pinyin = '';
  1641. }
  1642. }
  1643. }
  1644. $result['category_id'] = $category['category_id'];
  1645. $result['cat_name'] = $category['alias'];
  1646. $result['website_name'] = $category['website_name'] ?? "";
  1647. $result['suffix'] = $category['suffix'] ?? "";
  1648. $result['commendArticle'] = $commendArticle;
  1649. $result['commend_ids'] = $commend_ids;
  1650. return Result::success($result);
  1651. }
  1652. /**
  1653. * 前端-获取网站调查问卷
  1654. * @param array $data
  1655. * @return array
  1656. */
  1657. public function getWebsiteSurvey(array $data): array
  1658. {
  1659. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1660. $website = Website::where('id', $data['website_id'])->first();
  1661. if (empty($website)) {
  1662. return Result::error("暂无此网站", 0);
  1663. }
  1664. }
  1665. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1666. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1667. if (empty($article)) {
  1668. return Result::error("暂无此文章", 0);
  1669. }
  1670. // return Result::error($data,0);
  1671. $where['art_id'] = $data['art_id'];
  1672. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1673. } else {
  1674. $survey = Article::where(function ($query) {
  1675. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1676. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1677. })
  1678. ->where('status', 1)
  1679. ->where('is_survey', 1)
  1680. ->select('survey_id')
  1681. ->orderBy('updated_at', 'desc')
  1682. ->first();
  1683. if (empty($survey)) {
  1684. return Result::error("暂无调查问卷", 0);
  1685. }
  1686. $where['sur_id'] = $survey['survey_id'];
  1687. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1688. }
  1689. // return Result::success($where);
  1690. $result = ArticleSurvey::where($where)
  1691. ->where(function ($query) {
  1692. $query->where('is_other', 0)
  1693. ->orWhere(function ($subQuery) {
  1694. $subQuery->where('is_other', 1)
  1695. ->where('other_id', 0);
  1696. });
  1697. })
  1698. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1699. ->select('article_survey.*', 'article.survey_type')
  1700. ->get()->all();
  1701. if (empty($result)) {
  1702. return Result::error("此文章暂无调查问卷", 0);
  1703. }
  1704. return Result::success($result);
  1705. }
  1706. /**
  1707. * 前端-添加网站调查问卷选项
  1708. * @param array $data
  1709. * @return array
  1710. */
  1711. public function addWebsiteSurveyOption(array $data): array
  1712. {
  1713. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1714. $website = Website::where('id', $data['website_id'])->first();
  1715. if (empty($website)) {
  1716. return Result::error("暂无此网站", 0);
  1717. }
  1718. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1719. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1720. if (empty($survey)) {
  1721. return Result::error("此调查问卷不可添加选项", 0);
  1722. }
  1723. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1724. $choice = [
  1725. 'art_id' => $survey['art_id'],
  1726. 'website_id' => $data['website_id'],
  1727. 'survey_name' => $survey['survey_name'],
  1728. 'choice_name' => $data['choice_name'],
  1729. 'sur_id' => $survey['sur_id'],
  1730. 'is_other' => 1,
  1731. 'other_id' => $survey['id'],
  1732. ];
  1733. $result = ArticleSurvey::insertGetId($choice);
  1734. if (empty($result)) {
  1735. return Result::error("添加失败", 0);
  1736. }
  1737. return Result::success($result);
  1738. }
  1739. }
  1740. return Result::error("添加失败", 0);
  1741. }
  1742. return Result::error("添加失败", 0);
  1743. }
  1744. /**
  1745. * 前端-调查问卷投票
  1746. * @param array $data
  1747. * @return array
  1748. */
  1749. public function addWebsiteSurveyVote(array $data): array
  1750. {
  1751. // return Result::success($data);
  1752. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1753. $website = Website::where('id', $data['website_id'])->first();
  1754. if (empty($website)) {
  1755. return Result::error("暂无此网站", 0);
  1756. }
  1757. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1758. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1759. // return Result::success($survey);
  1760. if (empty($is_survey)) {
  1761. return Result::error("此调查问卷不存在", 0);
  1762. }
  1763. // return Result::success($survey);
  1764. // 调查问卷类型
  1765. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1766. //多选 若是json型则转化成数组类型
  1767. if (strpos($data['choice_id'], '[') === 0) {
  1768. $data['choice_id'] = json_decode($data['choice_id'], true);
  1769. } else {
  1770. // 单选 也转换成数组
  1771. $data['choice_id'] = [$data['choice_id']];
  1772. }
  1773. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1774. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1775. // ->where('website_id',$data['website_id'])
  1776. ->where('is_other', 1)
  1777. ->where('other_id', 0)
  1778. ->first();
  1779. if (!empty($other)) {
  1780. return Result::error("请选择已有的选项!", 0);
  1781. }
  1782. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1783. // ->where('website_id',$data['website_id'])
  1784. ->where('is_other', 1)
  1785. ->where('other_id', '!=', 0)
  1786. ->first();
  1787. // return Result::success($choice['other']);
  1788. $choice_id = $data['choice_id'];
  1789. if (!empty($choice['other'])) {
  1790. // array_push($data['choice_id'],$choice['other']['other_id']);
  1791. if (!empty($choice_id)) {
  1792. $key = array_search($choice['other']['id'], $choice_id);
  1793. if ($key !== false) {
  1794. unset($choice_id[$key]);
  1795. $choice_id = array_values($choice_id);
  1796. }
  1797. array_push($choice_id, $choice['other']['other_id']);
  1798. } else {
  1799. $choice_id[0] = $choice['other']['other_id'];
  1800. }
  1801. array_push($data['choice_id'], $choice['other']['other_id']);
  1802. }
  1803. // return Result::success($data);
  1804. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1805. // ->where('website_id',$data['website_id'])
  1806. ->increment('results', 1);
  1807. if (empty($choice)) {
  1808. return Result::error("请选择已有的选项!", 0);
  1809. }
  1810. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1811. // ->where('website_id',$data['website_id'])
  1812. ->where('other_id', 0)
  1813. ->get();
  1814. $survey['choice'] = $choice_id;
  1815. return Result::success($survey);
  1816. }
  1817. return Result::error("参数必填!");
  1818. }
  1819. return Result::error("此调查问卷不存在", 0);
  1820. }
  1821. return Result::error("参数必填!");
  1822. }
  1823. /**
  1824. * 后端-获取网站调查问卷列表
  1825. * @param array $data
  1826. * @return array
  1827. */
  1828. public function getSurveyList(array $data): array
  1829. {
  1830. $where = [];
  1831. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1832. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1833. }
  1834. $survey_type = isset($data['survey_type']) && $data['survey_type'] !== '' ? $data['survey_type'] : null;
  1835. if (!empty($where)) {
  1836. // 修复:先关联 article 再按 survey_type 过滤,避免查不到数据
  1837. $query = ArticleSurvey::select(
  1838. 'art_id as id',
  1839. Db::raw('MAX(id) as surid'),
  1840. Db::raw('MAX(survey_name) as survey_name'),
  1841. Db::raw('MAX(sur_id) as survey_id')
  1842. )
  1843. ->groupBy('art_id')
  1844. ->where($where)
  1845. ->when(!is_null($survey_type), function ($q) use ($survey_type) {
  1846. $q->whereIn('art_id', function ($sub) use ($survey_type) {
  1847. $sub->select('id')
  1848. ->from('article')
  1849. ->where('survey_type', $survey_type);
  1850. });
  1851. })
  1852. ->with(['article' => function ($query) {
  1853. $query->select('id', 'survey_type','created_at','updated_at','created_at');
  1854. }]);
  1855. ;
  1856. }else{
  1857. $query = ArticleSurvey::select(
  1858. 'art_id as id',
  1859. Db::raw('MAX(id) as surid'),
  1860. Db::raw('MAX(survey_name) as survey_name'),
  1861. Db::raw('MAX(sur_id) as survey_id'),
  1862. )
  1863. ->groupBy('art_id')
  1864. ->when(!is_null($survey_type), function ($q) use ($survey_type) {
  1865. $q->whereIn('art_id', function ($sub) use ($survey_type) {
  1866. $sub->select('id')
  1867. ->from('article')
  1868. ->where('survey_type', $survey_type);
  1869. });
  1870. })
  1871. ->with(['article' => function ($query) {
  1872. $query->select('id', 'survey_type','created_at','updated_at','created_at');
  1873. }]);
  1874. }
  1875. $count = $query->get()->count();
  1876. // 简单写法:直接统计分组后的 art_id 数量
  1877. $survey = $query->orderBy('id', 'desc')
  1878. ->limit($data['pageSize'])
  1879. ->offset(($data['page'] - 1) * $data['pageSize'])
  1880. ->get();
  1881. if (empty($survey->toArray())) {
  1882. return Result::error("暂无调查问卷!", 0);
  1883. }
  1884. $survey = array_map(function ($item) {
  1885. if (isset($item['article'])) {
  1886. $item['survey_type'] = $item['article']['survey_type'];
  1887. $item['created_at'] = $item['article']['created_at'];
  1888. $item['updated_at'] = $item['article']['updated_at'];
  1889. } else {
  1890. // 处理article为null的情况,设置默认值
  1891. $item['survey_type'] = null;
  1892. $item['created_at'] = null;
  1893. $item['updated_at'] = null;
  1894. }
  1895. unset($item['article']);
  1896. return $item;
  1897. }, $survey->toArray());
  1898. $result = [
  1899. 'rows' => $survey,
  1900. 'count' => $count,
  1901. ];
  1902. return Result::success($result);
  1903. }
  1904. /**
  1905. * 后端-获取网站调查问卷详情
  1906. * @param array $data
  1907. * @return array
  1908. */
  1909. public function getSurveyInfo(array $data): array
  1910. {
  1911. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1912. $where = ['sur_id' => $data['sur_id']];
  1913. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1914. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1915. ->select('article_survey.*', 'article.survey_type')
  1916. ->get()->all();
  1917. if (empty($choose)) {
  1918. return Result::error("此调查问卷不存在", 0);
  1919. }
  1920. $resultsArray = array_column($choose, 'results');
  1921. $total = array_sum($resultsArray);
  1922. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1923. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1924. // $total = 0;
  1925. if (!empty($other)) {
  1926. $total = $total + $other['results'];
  1927. $other['choice_name'] = '(其他)';
  1928. if (!empty($others)) {
  1929. $other['hasChildren'] = true;
  1930. // array_push($other,['hasChildren','=',true]);
  1931. $other['children'] = $others;
  1932. $other_choices = [$other->toArray()];
  1933. $mer_choice = array_merge($choose, $other_choices);
  1934. $value_choice = array_values($mer_choice);
  1935. } else {
  1936. // return Result::error('1111');
  1937. $other_choices = [$other->toArray()];
  1938. $other_choices = array_merge($choose, $other_choices);
  1939. $value_choice = array_values($other_choices);
  1940. // return Result::success($result);
  1941. }
  1942. } else {
  1943. $value_choice = $choose;
  1944. }
  1945. $result = [
  1946. 'choose' => $value_choice,
  1947. 'total' => $total,
  1948. ];
  1949. }
  1950. return Result::success($result);
  1951. }
  1952. /**
  1953. * 前端-搜索新闻列表
  1954. * @param array $data
  1955. * @return array
  1956. */
  1957. public function selectWebsiteArticle(array $data): array
  1958. {
  1959. $website = Website::where('id', $data['website_id'])->first();
  1960. if (empty($website)) {
  1961. return Result::error("网站不存在", 0);
  1962. }
  1963. // $website_column = $website['column'];
  1964. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1965. $website_column = json_decode($website['website_column_arr_id'], true);
  1966. }
  1967. $website_id = $data['website_id'];
  1968. $categorys = $this->processArticlePro($website_id);
  1969. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1970. // return Result::success($diff_pid_categoryIds);
  1971. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1972. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1973. }
  1974. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1975. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1976. $catiall = $categorys['catiall'];
  1977. $categoryIds = $categorys['categoryIds'];
  1978. // return Result::success($categoryIds);
  1979. $query = Article::where('status', 1)
  1980. ->whereIn('catid', $categoryIds)
  1981. ->leftJoinSub(function ($query) use ($website_id) {
  1982. $query->from('article_ignore')
  1983. ->where('website_id', $website_id);
  1984. }, 'article_ignore', function ($join) {
  1985. $join->on('article_ignore.article_id', '=', 'article.id');
  1986. })
  1987. ->where(function ($query) {
  1988. $query->whereNull('article_ignore.article_id')
  1989. ->orWhere(function ($subQuery) {
  1990. $subQuery->whereNotNull('article_ignore.article_id')
  1991. ->where('article_ignore.is_ignore', 0)
  1992. ->where(function ($subSubQuery) {
  1993. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1994. ->orWhereNull('article_ignore.c_show_time');
  1995. });
  1996. });
  1997. });
  1998. // ->get()->all();
  1999. // return Result::success($query);
  2000. if (isset($data['cityid']) && !empty($data['cityid'])) {
  2001. $query->whereRaw("JSON_CONTAINS(article.city_arr_id, '" . intval($data['cityid']) . "')");
  2002. }
  2003. if (isset($data['department_id']) && !empty($data['department_id'])) {
  2004. $query->whereRaw("JSON_CONTAINS(article.department_arr_id, '" . intval($data['department_id']) . "')");
  2005. }
  2006. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2007. $query->where('article.title', 'like', '%' . $data['keyword'] . '%');
  2008. }
  2009. // 计算总数
  2010. $count = $query->count();
  2011. // return Result::success($count);
  2012. // 分页查询
  2013. $articles = $query
  2014. ->select(
  2015. 'article.id',
  2016. 'article.title',
  2017. 'article.imgurl',
  2018. 'article.author',
  2019. 'article.updated_at',
  2020. 'article.introduce',
  2021. 'article.islink',
  2022. 'article.linkurl',
  2023. 'article.copyfrom',
  2024. 'article.cat_arr_id',
  2025. 'article.catid',
  2026. 'article.department_arr_id',
  2027. 'article.city_arr_id',
  2028. // 'article_ignore.c_show_time',
  2029. // 'article_ignore.is_ignore'
  2030. )
  2031. ->orderBy("updated_at", "desc")
  2032. ->offset(($data['page'] - 1) * $data['pageSize'])
  2033. ->limit($data['pageSize'])
  2034. ->get();
  2035. // return Result::success($articles);
  2036. foreach ($articles as $k => $v) {
  2037. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  2038. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2039. }
  2040. if (empty($articles)) {
  2041. return Result::error("没有符合条件的资讯数据");
  2042. }
  2043. $result = [
  2044. 'rows' => $articles,
  2045. 'count' => $count,
  2046. ];
  2047. return Result::success($result);
  2048. }
  2049. /**
  2050. * 模块新闻加强版
  2051. * @param array $data
  2052. * @return array
  2053. */
  2054. public function getWebsiteCatidArticle(array $data): array
  2055. {
  2056. $where = [
  2057. 'website_category.category_id' => $data['catid'],
  2058. 'website_category.website_id' => $data['website_id'],
  2059. ];
  2060. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  2061. $child_catnum = $data['child_catnum'] ?? 1;
  2062. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  2063. $childCategoryIds = array_column($category['child'], 'category_id');
  2064. if (empty($childCategoryIds)) {
  2065. return Result::error("暂无子栏目", 0);
  2066. }
  2067. $imgArticles = [];
  2068. $textArticles = [];
  2069. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  2070. // 初始化子分类图片新闻和文字新闻数组
  2071. // 查询所有子级栏目的图文新闻
  2072. $imgArticles = Article::where('catid', $childCategoryIds[0])
  2073. ->where(function ($query) use ($data) {
  2074. $query->where(function ($subQuery) use ($data) {
  2075. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2076. })->orWhereNull("ignore_ids");
  2077. })
  2078. ->where('status', 1)
  2079. ->where('imgurl', '!=', '')
  2080. ->select('*')
  2081. ->orderBy('updated_at', 'desc')
  2082. ->limit($data['child_imgnum'])
  2083. ->get();
  2084. }
  2085. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  2086. // 查询所有子级栏目的文字新闻
  2087. $textArticles = Article::where('catid', $childCategoryIds[0])
  2088. ->where('status', 1)
  2089. ->where(function ($query) use ($data) {
  2090. $query->where(function ($subQuery) use ($data) {
  2091. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2092. })->orWhereNull("ignore_ids");
  2093. })
  2094. ->select('*')
  2095. ->orderBy('updated_at', 'desc')
  2096. ->limit($data['child_textnum'])
  2097. ->get();
  2098. }
  2099. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  2100. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  2101. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  2102. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  2103. return $child;
  2104. }, $category['child']);
  2105. }
  2106. // }
  2107. if (isset($data['img_num']) && !empty($data['img_num'])) {
  2108. $category['img'] = WebsiteCategory::where($where)
  2109. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2110. ->where('article.status', 1)
  2111. ->where('article.imgurl', '!=', '')
  2112. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2113. ->orderBy('article.updated_at', 'desc')
  2114. ->limit($data['img_num'])
  2115. ->get();
  2116. }
  2117. if (isset($data['text_num']) && !empty($data['text_num'])) {
  2118. $category['text'] = WebsiteCategory::where($where)
  2119. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2120. ->where('article.status', 1)
  2121. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2122. ->orderBy('article.updated_at', 'desc')
  2123. ->limit($data['text_num'])
  2124. ->get();
  2125. }
  2126. // $category = $category->get();
  2127. if (empty($category)) {
  2128. return Result::error("查询失败", 0);
  2129. }
  2130. return Result::success($category);
  2131. }
  2132. /**
  2133. * 模块新闻加强plus版
  2134. * @param array $data
  2135. * @return array
  2136. */
  2137. public function getWebsiteAllArticle(array $data): array
  2138. {
  2139. // return Result::success($data);
  2140. $time1 = microtime(true);
  2141. $wetbsite_id = $data['website_id'] ?? 2;
  2142. $data = json_decode($data['id'], true);
  2143. $website = Website::where('id', $wetbsite_id)->first();
  2144. if (empty($website)) {
  2145. return Result::error("网站不存在", 0);
  2146. }
  2147. // return Result::success($website);
  2148. $website_column = $website['website_column_arr_id'] ?? '[]';
  2149. $website_column = json_decode($website_column, true);
  2150. $categorys = $this->processArticlePro($wetbsite_id);
  2151. $cat_1st_arr = $categorys['cat_1st_arr'];
  2152. $catiall = $categorys['catiall'];
  2153. // return Result::success($catiall);
  2154. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2155. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2156. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2157. }
  2158. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  2159. // return Result::success($categorys);
  2160. $parent_category = array_column($data, 'parent');
  2161. $parent_cat = [];
  2162. $child_category = array_column($data, 'child');
  2163. if (!empty($parent_category)) {
  2164. foreach ($parent_category as $key => $value) {
  2165. $arr = array_map('intval', explode(',', $value));
  2166. $parent_cat[$key] = $arr[0] ?? 0;
  2167. $parent_category = $arr[0] ?? 0;
  2168. $article_imgnum = $arr[1] ?? 0;
  2169. $article_textnum = $arr[2] ?? 0;
  2170. if ($parent_category != 0) {
  2171. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2172. // return Result::success($category_arr);
  2173. if ($article_imgnum != 0) {
  2174. $img_article = Article::whereIn('catid', $category_arr)
  2175. ->where('status', 1)
  2176. ->where('imgurl', '!=', '')
  2177. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2178. $query->from('article_ignore')
  2179. ->where('website_id', $wetbsite_id);
  2180. }, 'article_ignore', function ($join) {
  2181. $join->on('article_ignore.article_id', '=', 'article.id');
  2182. })
  2183. ->where(function ($query) {
  2184. $query->whereNull('article_ignore.article_id')
  2185. ->orWhere(function ($subQuery) {
  2186. $subQuery->whereNotNull('article_ignore.article_id')
  2187. ->where('article_ignore.is_ignore', 0)
  2188. ->where(function ($subSubQuery) {
  2189. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2190. ->orWhereNull('article_ignore.c_show_time');
  2191. });
  2192. });
  2193. })
  2194. ->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')
  2195. ->orderBy('updated_at', 'desc')
  2196. ->limit($article_imgnum)
  2197. ->get()->all();
  2198. foreach ($img_article as $k => $v) {
  2199. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2200. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2201. }
  2202. } else {
  2203. $img_article = [];
  2204. }
  2205. if ($article_textnum != 0) {
  2206. $text_article = Article::whereIn('catid', $category_arr)
  2207. ->where('status', 1)
  2208. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2209. $query->from('article_ignore')
  2210. ->where('website_id', $wetbsite_id);
  2211. }, 'article_ignore', function ($join) {
  2212. $join->on('article_ignore.article_id', '=', 'article.id');
  2213. })
  2214. ->where(function ($query) {
  2215. $query->whereNull('article_ignore.article_id')
  2216. ->orWhere(function ($subQuery) {
  2217. $subQuery->whereNotNull('article_ignore.article_id')
  2218. ->where('article_ignore.is_ignore', 0)
  2219. ->where(function ($subSubQuery) {
  2220. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2221. ->orWhereNull('article_ignore.c_show_time');
  2222. });
  2223. });
  2224. })
  2225. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2226. ->orderBy('updated_at', 'desc')
  2227. ->limit($article_textnum)
  2228. ->get()->all();
  2229. foreach ($text_article as $k => $v) {
  2230. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2231. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2232. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2233. }
  2234. } else {
  2235. $text_article = [];
  2236. }
  2237. $catiall[$parent_category]['imgnum'] = $img_article;
  2238. $catiall[$parent_category]['textnum'] = $text_article;
  2239. $parent[$key] = $catiall[$parent_category];
  2240. } else {
  2241. $parent[$key] = '';
  2242. }
  2243. }
  2244. }
  2245. if (!empty($child_category)) {
  2246. foreach ($child_category as $key => $value) {
  2247. $arr = array_map('intval', explode(',', $value));
  2248. $parent_category = $parent_cat[$key];
  2249. $child_category = $arr[0] ?? 0;
  2250. $article_imgnum = $arr[1] ?? 0;
  2251. $article_textnum = $arr[2] ?? 0;
  2252. if ($child_category != 0) {
  2253. $all_childcat = $cat_1st_arr[$parent_category];
  2254. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  2255. // 从 $websiteInfoIndexed 中获取对应的数据
  2256. $info = $websiteInfoIndexed[$v];
  2257. // 返回一个包含所需信息的数组
  2258. return [
  2259. 'alias' => $info->alias,
  2260. 'category_id' => $info->category_id,
  2261. 'aLIas_pinyin' => $info->aLIas_pinyin,
  2262. 'pid' => $info->pid,
  2263. 'type' => $info->type,
  2264. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  2265. 'pinyin' => $info->pinyin,
  2266. ];
  2267. }, $all_childcat);
  2268. if ($article_imgnum != 0) {
  2269. $img_article = Article::where('catid', $child_category)
  2270. ->where('status', 1)
  2271. ->where('imgurl', '!=', '')
  2272. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2273. $query->from('article_ignore')
  2274. ->where('website_id', $wetbsite_id);
  2275. }, 'article_ignore', function ($join) {
  2276. $join->on('article_ignore.article_id', '=', 'article.id');
  2277. })
  2278. ->where(function ($query) {
  2279. $query->whereNull('article_ignore.article_id')
  2280. ->orWhere(function ($subQuery) {
  2281. $subQuery->whereNotNull('article_ignore.article_id')
  2282. ->where('article_ignore.is_ignore', 0)
  2283. ->where(function ($subSubQuery) {
  2284. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2285. ->orWhereNull('article_ignore.c_show_time');
  2286. });
  2287. });
  2288. })
  2289. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2290. ->orderBy('updated_at', 'desc')
  2291. ->limit($article_imgnum)
  2292. ->get()->all();
  2293. foreach ($img_article as $k => $v) {
  2294. // var_dump($v);
  2295. // var_dump($k);
  2296. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2297. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2298. }
  2299. } else {
  2300. $img_article = [];
  2301. }
  2302. if ($article_textnum != 0) {
  2303. $text_article = Article::where('catid', $child_category)
  2304. ->where('status', 1)
  2305. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2306. $query->from('article_ignore')
  2307. ->where('website_id', $wetbsite_id);
  2308. }, 'article_ignore', function ($join) {
  2309. $join->on('article_ignore.article_id', '=', 'article.id');
  2310. })
  2311. ->where(function ($query) {
  2312. $query->whereNull('article_ignore.article_id')
  2313. ->orWhere(function ($subQuery) {
  2314. $subQuery->whereNotNull('article_ignore.article_id')
  2315. ->where('article_ignore.is_ignore', 0)
  2316. ->where(function ($subSubQuery) {
  2317. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2318. ->orWhereNull('article_ignore.c_show_time');
  2319. });
  2320. });
  2321. })
  2322. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2323. ->orderBy('updated_at', 'desc')
  2324. ->limit($article_textnum)
  2325. ->get()->all();
  2326. foreach ($text_article as $k => $v) {
  2327. // var_dump($v);
  2328. // var_dump($k);
  2329. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2330. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2331. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2332. }
  2333. } else {
  2334. $text_article = [];
  2335. }
  2336. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  2337. $catiall[$child_category]['imgnum'] = $img_article;
  2338. $catiall[$child_category]['textnum'] = $text_article;
  2339. $child[$key] = $catiall[$child_category];
  2340. // var_dump($pids);
  2341. } else {
  2342. $child[$key] = '';
  2343. }
  2344. }
  2345. }
  2346. foreach ($parent as $key => $value) {
  2347. $result[$key] = $value;
  2348. if (!empty($child[$key])) {
  2349. // var_dump($child[$key]);
  2350. $result[$key]['child'] = $child[$key];
  2351. // $value[$key]['child'] = $child[$key];
  2352. } else {
  2353. $result[$key]['child'] = [
  2354. "alias" => null,
  2355. "category_id" => null,
  2356. "type" => null,
  2357. "pinyin" => null,
  2358. "all_childcat" => [],
  2359. "imgnum" => [],
  2360. "textnum" => []
  2361. ];
  2362. }
  2363. }
  2364. return Result::success($result);
  2365. }
  2366. /**
  2367. * 辅助方法:获取文章列表
  2368. */
  2369. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  2370. {
  2371. sleep(1);
  2372. $query = Article::where('article.status', 1)
  2373. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  2374. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  2375. ->where(function ($query) use ($website) {
  2376. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  2377. })
  2378. ->leftJoin('website_category', function ($join) use ($website) {
  2379. $join->on('article.catid', '=', 'website_category.category_id')
  2380. ->where('website_category.website_id', '=', $website['website_id']);
  2381. })
  2382. ->select(
  2383. 'article.id',
  2384. 'article.title',
  2385. 'article.imgurl',
  2386. 'article.author',
  2387. 'article.updated_at',
  2388. 'article.introduce',
  2389. 'article.islink',
  2390. 'article.linkurl',
  2391. 'article.copyfrom',
  2392. 'article.cat_arr_id',
  2393. 'article.catid',
  2394. 'website_category.alias as category_name'
  2395. )
  2396. ->orderBy('updated_at', 'desc')
  2397. ->limit($limit);
  2398. // 如果是图片文章,添加图片URL条件
  2399. if ($isImageArticle) {
  2400. $query->where('imgurl', '!=', '');
  2401. } else {
  2402. // 文字文章不需要imgurl字段
  2403. $query->addSelect('article.introduce');
  2404. }
  2405. $articles = $query->get();
  2406. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  2407. }
  2408. /**
  2409. * 乡村网-获取特殊新闻模块
  2410. * @param array $data
  2411. * @return array
  2412. */
  2413. public function getWebsiteArticles(array $data): array
  2414. {
  2415. $website_id = $data['website_id'];
  2416. $website = Website::where('id', $website_id)->first();
  2417. if (empty($website)) {
  2418. return Result::error("网站不存在", 0);
  2419. }
  2420. // return Result::success($website);
  2421. $website_column = $website['website_column_arr_id'] ?? '[]';
  2422. $website_column = json_decode($website_column, true);
  2423. $catids = json_decode($data['id'], true);
  2424. $parent_category = array_column($catids, 'parent');
  2425. if (!empty($parent_category) && is_array($parent_category)) {
  2426. $categorys = $this->processArticlePro($website_id);
  2427. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2428. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2429. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2430. }
  2431. $catiall = $categorys['catiall'];
  2432. $cat_1st_arr = $categorys['cat_1st_arr'];
  2433. // return Result::success($categorys);
  2434. foreach ($parent_category as $key => $value) {
  2435. $arr = array_map('intval', explode(',', $value));
  2436. $parent_category = $arr[0] ?? 0;
  2437. $article_imgnum = $arr[1] ?? 0;
  2438. $article_textnum = $arr[2] ?? 0;
  2439. if ($parent_category != 0) {
  2440. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2441. // return Result::success($category_arr);
  2442. if ($article_imgnum != 0) {
  2443. $img_article = Article::whereIn('article.catid', $category_arr)
  2444. ->where('article.status', 1)
  2445. ->where('article.imgurl', '!=', '')
  2446. ->leftJoinSub(function ($query) use ($website_id) {
  2447. $query->from('article_ignore')
  2448. ->where('website_id', $website_id);
  2449. }, 'article_ignore', function ($join) {
  2450. $join->on('article_ignore.article_id', '=', 'article.id');
  2451. })
  2452. ->where(function ($query) {
  2453. $query->whereNull('article_ignore.article_id')
  2454. ->orWhere(function ($subQuery) {
  2455. $subQuery->whereNotNull('article_ignore.article_id')
  2456. ->where('article_ignore.is_ignore', 0)
  2457. ->where(function ($subSubQuery) {
  2458. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2459. ->orWhereNull('article_ignore.c_show_time');
  2460. });
  2461. });
  2462. })
  2463. ->select(
  2464. 'article.id',
  2465. 'article.title',
  2466. 'article.imgurl',
  2467. 'article.author',
  2468. 'article.updated_at',
  2469. 'article.introduce',
  2470. 'article.islink',
  2471. 'article.linkurl',
  2472. 'article.copyfrom',
  2473. 'article.cat_arr_id',
  2474. 'article.catid as category_id'
  2475. )
  2476. ->orderBy('updated_at', 'desc')
  2477. ->limit($article_imgnum)
  2478. ->get()->all();
  2479. foreach ($img_article as $k => $v) {
  2480. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2481. // return Result::success($v);
  2482. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2483. }
  2484. } else {
  2485. $img_article = [];
  2486. }
  2487. if ($article_textnum != 0) {
  2488. $text_article = Article::whereIn('article.catid', $category_arr)
  2489. ->where('article.status', 1)
  2490. ->leftJoinSub(function ($query) use ($website_id) {
  2491. $query->from('article_ignore')
  2492. ->where('website_id', $website_id);
  2493. }, 'article_ignore', function ($join) {
  2494. $join->on('article_ignore.article_id', '=', 'article.id');
  2495. })
  2496. ->where(function ($query) {
  2497. $query->whereNull('article_ignore.article_id')
  2498. ->orWhere(function ($subQuery) {
  2499. $subQuery->whereNotNull('article_ignore.article_id')
  2500. ->where('article_ignore.is_ignore', 0)
  2501. ->where(function ($subSubQuery) {
  2502. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2503. ->orWhereNull('article_ignore.c_show_time');
  2504. });
  2505. });
  2506. })
  2507. ->select(
  2508. 'article.id',
  2509. 'article.title',
  2510. 'article.author',
  2511. 'article.updated_at',
  2512. 'article.introduce',
  2513. 'article.islink',
  2514. 'article.linkurl',
  2515. 'article.copyfrom',
  2516. 'article.cat_arr_id',
  2517. 'article.catid as category_id'
  2518. )
  2519. ->orderBy('updated_at', 'desc')
  2520. ->limit($article_textnum)
  2521. ->get()->all();
  2522. foreach ($text_article as $k => $v) {
  2523. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2524. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2525. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2526. }
  2527. } else {
  2528. $text_article = [];
  2529. }
  2530. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2531. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2532. $parent[$key] = $catiall[$parent_category];
  2533. } else {
  2534. $parent[$key] = [];
  2535. }
  2536. }
  2537. }
  2538. return Result::success($parent);
  2539. }
  2540. // 封装处理商品的路由问题
  2541. function processGoods($goods, $data)
  2542. {
  2543. return $goods->map(function ($good) use ($data) {
  2544. $catid = $good->catid ?? 0;
  2545. // $pinyin = '';
  2546. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2547. if (!empty($category->pid) && $category->pid != 0) {
  2548. $level = json_decode($category->category_arr_id, true);
  2549. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2550. ->whereIn('category_id', $level)
  2551. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2552. ->get(['aLIas_pinyin'])
  2553. ->pluck('aLIas_pinyin')
  2554. ->implode('/');
  2555. } else {
  2556. $pinyin = $category->aLIas_pinyin ?? '';
  2557. }
  2558. if (isset($good->city_id) && !empty($good->city_id)) {
  2559. $city = District::where('id', $good->city_id)->first(['name']);
  2560. $good->city_name = $city->name ?? '';
  2561. }
  2562. // 解析imgurl JSON并取第一条数据
  2563. $imgUrls = json_decode($good->imgurl, true);
  2564. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2565. $good->pinyin = $pinyin;
  2566. return $good;
  2567. });
  2568. }
  2569. /**
  2570. * 获取商城首页-根据栏目id
  2571. * @param array $data
  2572. * @return array
  2573. * */
  2574. function getWebsiteCatidshop(array $data): array
  2575. {
  2576. $input['catid'] = $data['catid'];
  2577. $input['website_id'] = $data['website_id'];
  2578. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2579. $result = array_map(function ($item) use ($input) {
  2580. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2581. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2582. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2583. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2584. if (empty($category) || $category->type != 2) {
  2585. return Result::error("暂无此栏目", 0);
  2586. } else {
  2587. $website['website_id'] = $input['website_id'];
  2588. $goods = Good::where('good.status', 2)
  2589. ->where('good.website_id', $website['website_id'])
  2590. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2591. ->select(
  2592. 'good.id',
  2593. 'good.name',
  2594. 'good.imgurl',
  2595. 'good.description',
  2596. 'good.updated_at',
  2597. 'good.catid',
  2598. 'good.type_id',
  2599. 'good.price',
  2600. 'good.com',
  2601. 'good.level',
  2602. 'good.unit'
  2603. )
  2604. ->orderBy('updated_at', 'desc')
  2605. ->offset($goodStart)
  2606. ->limit($goodNum);
  2607. $all_goods = $goods->get();
  2608. $all_goods = $this->processGoods($all_goods, $website);
  2609. }
  2610. return $all_goods ?? [];
  2611. }
  2612. }, $data);
  2613. return Result::success($result);
  2614. }
  2615. /**
  2616. * 获取商品模块
  2617. * @param array $data
  2618. * @return array
  2619. * */
  2620. public function getWebsiteshop(array $data): array
  2621. {
  2622. $input['id'] = $data['id'];
  2623. $input['website_id'] = $data['website_id'];
  2624. $catid = $data['catid'];
  2625. $data = json_decode($input['id'] ?? '', true) ?? [];
  2626. $result['goods'] = array_map(function ($item) use ($input) {
  2627. // 检查parent元素是否存在且不是undefined
  2628. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2629. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2630. $website = $input['website_id'];
  2631. $query = Good::where('good.status', 2)
  2632. ->where('good.website_id', $website);
  2633. switch ($Levelid) {
  2634. case 1:
  2635. case 2:
  2636. case 3:
  2637. $goods = $query->where(function ($q) use ($Levelid) {
  2638. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2639. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2640. });
  2641. break;
  2642. case 4:
  2643. $goods = $query;
  2644. break;
  2645. case 5:
  2646. $goods = $query->where('type_id', 1);
  2647. break;
  2648. case 6:
  2649. $goods = $query->where('type_id', 2);
  2650. break;
  2651. default:
  2652. return [];
  2653. }
  2654. $all_goods = $goods
  2655. ->select(
  2656. 'good.id',
  2657. 'good.name',
  2658. 'good.imgurl',
  2659. 'good.description',
  2660. 'good.updated_at',
  2661. 'good.catid',
  2662. 'good.type_id',
  2663. 'good.price',
  2664. 'good.level',
  2665. 'good.website_id'
  2666. )
  2667. ->orderBy('updated_at', 'desc')
  2668. ->offset($goodStart)
  2669. ->limit($goodNum)
  2670. ->get();
  2671. $web['website_id'] = $website;
  2672. $all_goods = $this->processGoods($all_goods, $web);
  2673. }
  2674. return $all_goods;
  2675. }, $data);
  2676. $website = $input['website_id'];
  2677. $result['article'] = Article::where(function ($query) use ($website) {
  2678. $query->where(function ($subQuery) use ($website) {
  2679. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2680. })->orWhereNull("ignore_ids");
  2681. })
  2682. ->where('catid', $catid)
  2683. ->where('article.status', 1)
  2684. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2685. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2686. ->orderBy('article.updated_at', 'desc')
  2687. ->first();
  2688. return Result::success($result);
  2689. }
  2690. /**
  2691. * 获取商品分类
  2692. * @param array $data
  2693. * @return array
  2694. * */
  2695. public function getWebsiteshopCat(array $data): array
  2696. {
  2697. $website = $data['website_id'];
  2698. $category = WebsiteCategory::where('website_id', $website)
  2699. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2700. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2701. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2702. ->orderBy('sort')
  2703. ->get();
  2704. $cat = $category->map(function ($item) use ($website) {
  2705. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2706. $pid = $item->pid ?? 0;
  2707. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2708. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2709. ->where('website_id', $website)
  2710. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2711. ->get(['aLIas_pinyin'])
  2712. ->pluck('aLIas_pinyin')
  2713. ->implode('/');
  2714. } else {
  2715. $pinyin = $item->aLIas_pinyin ?? '';
  2716. }
  2717. $item->pinyin = $pinyin;
  2718. });
  2719. if (empty($category)) {
  2720. return Result::error("栏目查询失败", 0);
  2721. }
  2722. $cat_tree = Result::buildMenuTree($category);
  2723. $web['website_id'] = $website;
  2724. $goods = Good::where('website_id', $website)
  2725. ->where('status', 2)
  2726. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2727. ->latest('updated_at')
  2728. ->offset(($data['page'] - 1) * $data['pageSize'])
  2729. ->limit($data['pageSize'])
  2730. ->get();
  2731. if (!empty($goods)) {
  2732. if ($goods->count() > 1 && !empty($goods)) {
  2733. $goods = $this->processGoods($goods, $web);
  2734. }
  2735. } else {
  2736. $goods = [];
  2737. }
  2738. $result = [
  2739. 'category' => $cat_tree,
  2740. 'goods' => $goods,
  2741. ];
  2742. // $resul['goods'] = $goods;
  2743. if (empty($result)) {
  2744. return Result::error("查询失败", 0);
  2745. }
  2746. return Result::success($result);
  2747. }
  2748. /*
  2749. * 获取商品列表
  2750. * @param array $data
  2751. * @return array
  2752. * */
  2753. public function getWebsiteshopList(array $data): array
  2754. {
  2755. // return Result::success($data);
  2756. $where = [
  2757. 'status' => 2,
  2758. 'website_id' => $data['website_id'],
  2759. ];
  2760. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2761. // return Result::error("查询失败", 0);
  2762. // }
  2763. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2764. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2765. $data['catid'] = $category->category_id ?? 0;
  2766. }
  2767. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2768. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2769. }
  2770. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2771. array_push($where, ['type_id', $data['type_id']]);
  2772. }
  2773. $query = Good::where($where)
  2774. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2775. $query->where(function ($q) use ($data) {
  2776. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2777. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2778. });
  2779. })
  2780. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2781. $query->where(function ($q) use ($data) {
  2782. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2783. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2784. });
  2785. })
  2786. ->select(
  2787. 'good.id',
  2788. 'good.name',
  2789. 'good.imgurl',
  2790. 'good.description',
  2791. 'good.updated_at',
  2792. 'good.com',
  2793. 'good.catid',
  2794. 'good.type_id',
  2795. 'good.website_id',
  2796. 'good.cat_arr_id',
  2797. 'good.created_at',
  2798. 'good.city_id'
  2799. )
  2800. ->latest('updated_at');
  2801. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2802. $result['count'] = $query->clone()->count();
  2803. $result['goods'] = $this->processGoods(
  2804. $query->clone()
  2805. ->offset(($data['page'] - 1) * $data['pageSize'])
  2806. ->limit($data['pageSize'])
  2807. ->get(),
  2808. $data
  2809. );
  2810. } else {
  2811. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2812. // 获取 type_id 为 1 的数据
  2813. $result['type1'] = $this->processGoods(
  2814. $query->clone()
  2815. ->where('type_id', 1)
  2816. ->offset(($data['page'] - 1) * $data['pageSize'])
  2817. ->limit($data['pageSize'])
  2818. ->get(),
  2819. $data
  2820. );
  2821. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2822. // 获取 type_id 为 2 的数据
  2823. $result['type2'] = $this->processGoods(
  2824. $query->clone()
  2825. ->where('type_id', 2)
  2826. ->offset(($data['page'] - 1) * $data['pageSize'])
  2827. ->limit($data['pageSize'])
  2828. ->get(),
  2829. $data
  2830. );
  2831. }
  2832. if (empty($result)) {
  2833. return Result::error("查询失败", 0);
  2834. }
  2835. return Result::success($result);
  2836. }
  2837. /**
  2838. * 获取商品详情
  2839. * @param array $data
  2840. * @return array
  2841. * */
  2842. public function getWebsiteshopInfo(array $data): array
  2843. {
  2844. $where = [
  2845. 'good.status' => 2,
  2846. 'good.website_id' => $data['website_id'],
  2847. 'good.id' => $data['id'],
  2848. ];
  2849. $goods = Good::where($where)
  2850. ->where('good.id', $data['id'])
  2851. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2852. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2853. ->first();
  2854. if (empty($goods)) {
  2855. return Result::error("查询失败", 0);
  2856. }
  2857. $goods->imgurl = json_decode($goods->imgurl, true);
  2858. return Result::success($goods);
  2859. }
  2860. /**
  2861. * plus pro 处理文章路由问题
  2862. */
  2863. function processArticlePro($website_id)
  2864. {
  2865. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2866. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2867. // // 取出category_id 对应的aLIas_pinyin
  2868. // $categoryIds = array_column($categorys, 'category_id');
  2869. // $categoryPIds = array_column($categorys, 'pid');
  2870. // $aliasPinyins = array_column($categorys, 'path');
  2871. // $alias = array_column($categorys, 'alias');
  2872. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2873. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2874. // // return Result::success($cat_arr);
  2875. // // $catiall = [];
  2876. // //一级所有子级的记录
  2877. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2878. // return [
  2879. // 'cat_1st_arr' => $cat_alias_arr,
  2880. // 'catiall' => $cat_arr,
  2881. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2882. // 'categoryIds' => $categoryIds,
  2883. // ];
  2884. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2885. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2886. // 取出category_id 对应的aLIas_pinyin
  2887. $categoryIds = array_column($categorys, 'category_id');
  2888. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
  2889. return $pid != 0;
  2890. })));
  2891. $category_path = array_column($categorys, 'path');
  2892. $cat_arr = array_combine($categoryIds, $category_path);
  2893. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2894. $catiall = [];
  2895. //一级所有子级的记录
  2896. $cat_1st_arr = [];
  2897. foreach ($categorys as $key => $value) {
  2898. // $category_arr_id = json_decode($value->category_arr_id);
  2899. // $pinyin_str = '';
  2900. // // 算出一级 并且算出子级
  2901. if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
  2902. $cat_1st_arr[$value->pid][] = $value->category_id;
  2903. }
  2904. // foreach ($category_arr_id as $k => $v) {
  2905. // $pinyin_str .= $cat_arr[$v] . '/';
  2906. // }
  2907. // $pinyin_str = rtrim($pinyin_str, '/');
  2908. $catiall[$value->category_id]['alias'] = $value->alias;
  2909. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2910. $catiall[$value->category_id]['type'] = $value->type;
  2911. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2912. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2913. }
  2914. return [
  2915. 'cat_1st_arr' => $cat_1st_arr,
  2916. 'catiall' => $catiall,
  2917. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2918. 'categoryIds' => $categoryIds,
  2919. 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
  2920. 'categoryPIds' => $categoryPIds,
  2921. ];
  2922. }
  2923. /**
  2924. * 封装处理文章的路由问题
  2925. * */
  2926. function processArticles($articles, $data)
  2927. {
  2928. // 检查 $articles 是否为数组或可迭代对象
  2929. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2930. return $articles->map(function ($article) use ($data) {
  2931. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2932. $catid = $article->cat_arr_id ?? '';
  2933. }
  2934. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2935. $catid = $article->category_arr_id ?? '';
  2936. }
  2937. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2938. $level = json_decode($catid, true);
  2939. if (!is_array($level)) {
  2940. return $article;
  2941. } else {
  2942. $level = array_map('intval', $level);
  2943. }
  2944. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2945. ->where($data)
  2946. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2947. ->pluck('aLIas_pinyin')
  2948. ->implode('/');
  2949. $article->pinyin = $pinyin ?? '';
  2950. return $article;
  2951. });
  2952. } else {
  2953. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2954. $catid = $articles->cat_arr_id ?? '';
  2955. $level = json_decode($catid, true);
  2956. if (!is_array($level)) {
  2957. return $articles;
  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. $articles->pinyin = $pinyin ?? '';
  2967. return $articles;
  2968. }
  2969. }
  2970. // 封装处理由问题
  2971. function processJob($job, $data)
  2972. {
  2973. return $job->map(function ($job) use ($data) {
  2974. $category = $job->cat_arr_id ?? '';
  2975. $cityid = $job->city_arr_id ?? '';
  2976. $city = json_decode($cityid, true);
  2977. $pinyin = '';
  2978. $level = json_decode($category, true);
  2979. // 路由
  2980. if (!empty($level) && is_array($level)) {
  2981. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2982. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2983. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2984. ->get(['aLIas_pinyin'])
  2985. ->pluck('aLIas_pinyin')
  2986. ->implode('/');
  2987. if (empty($pinyin)) {
  2988. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2989. }
  2990. $job->pinyin = $pinyin;
  2991. }
  2992. // 取职位-城市 市??省
  2993. if (!empty($city) && is_array($city)) {
  2994. if (isset($city[1]) && !empty($city[1])) {
  2995. $city = District::where('id', $city[1])->first(['name']);
  2996. $job->city_name = $city->name ?? '';
  2997. } else if (isset($city[0]) && !empty($city[0])) {
  2998. $city = District::where('id', $city[0])->first(['name']);
  2999. $job->city_name = $city->name ?? '';
  3000. } else {
  3001. $job->city_name = '全国';
  3002. }
  3003. }
  3004. // 获取简历最后一级地区
  3005. if (isset($job->city_id) && !empty($job->city_id)) {
  3006. $city = District::where('id', $job->city_id)->first(['name']);
  3007. $job->hunt_cityname = $city->name ?? '';
  3008. }
  3009. // 组合详细地址
  3010. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  3011. $address_id = json_decode($job->address_arr_id, true) ?? [];
  3012. if (is_array($address_id) && !empty($address_id)) {
  3013. $address = District::whereIn('id', $address_id)
  3014. ->orderBy('level', 'asc')
  3015. ->get(['name'])
  3016. ->pluck('name')
  3017. ->implode('');
  3018. // $job->address_name = $address ?? '';
  3019. $job->address_name = ($address ?? '') . ($job->address ?? '');
  3020. }
  3021. }
  3022. // 取行业
  3023. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  3024. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  3025. if (!empty($job->industry)) {
  3026. $query->where('hyid', $job->industry);
  3027. } else if (!empty($job->hy_id)) {
  3028. $query->where('hyid', $job->hy_id);
  3029. } else if (!empty($job->company_hy_id)) {
  3030. $query->where('hyid', $job->company_hy_id);
  3031. } else {
  3032. $query->where('hyid', $job->job_industry);
  3033. }
  3034. })->first(['hyname']);
  3035. $job->hy_name = $hy_name->hyname ?? '';
  3036. }
  3037. // 取职位类别
  3038. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  3039. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  3040. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  3041. $job->zw_name = $zw_name->zwname ?? '';
  3042. }
  3043. // 取具体职位
  3044. 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))) {
  3045. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  3046. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  3047. $job->jtzw_name = $jtzw_name->zwname ?? '';
  3048. }
  3049. // 取工作经验
  3050. if (isset($job->experience) && !empty($job->experience)) {
  3051. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  3052. $job->experience_name = $experience->ename ?? '';
  3053. }
  3054. // 取学历
  3055. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  3056. $education = $job->educational ?? $job->school_education;
  3057. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  3058. $job->education_name = $education->ename ?? '';
  3059. }
  3060. // 语言
  3061. if (isset($job->language) && !empty($job->language)) {
  3062. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  3063. $job->language_name = $language->ename ?? '';
  3064. }
  3065. // 薪资
  3066. if (isset($job->salary) && !empty($job->salary)) {
  3067. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  3068. $job->salary_name = $salary->ename ?? '';
  3069. }
  3070. // 职位性质
  3071. if (isset($job->nature_id) && !empty($job->nature_id)) {
  3072. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  3073. $job->job_nature_name = $job_nature->ename ?? '';
  3074. }
  3075. // 公司规模
  3076. if (isset($job->company_size) && !empty($job->company_size)) {
  3077. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  3078. $job->company_size_name = $company_size->ename ?? '';
  3079. }
  3080. // 公司性质
  3081. if (isset($job->company_nature) && !empty($job->company_nature)) {
  3082. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  3083. $job->company_nature_name = $company_nature->nature_name ?? '';
  3084. }
  3085. // $job->pinyin = $pinyin;
  3086. return $job;
  3087. });
  3088. }
  3089. /**
  3090. * 获取书籍模块
  3091. * @param array $data
  3092. * @return array
  3093. * */
  3094. public function getWebsiteBook(array $data): array
  3095. {
  3096. $input['id'] = $data['id'];
  3097. $input['website_id'] = $data['website_id'];
  3098. // 将 JSON 字符串转换为 PHP 数组
  3099. $data = json_decode($input['id'], true);
  3100. // 使用 array_map 处理每个元素
  3101. $result = array_map(function ($item) use ($input) {
  3102. // 检查parent元素是否存在且不是undefined
  3103. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  3104. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3105. $website = [
  3106. 'website_id' => $input['website_id'],
  3107. ];
  3108. // 查询栏目名称
  3109. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3110. if (empty($category)) {
  3111. $parent_alias = '';
  3112. $parent_pinyin = null;
  3113. $imgBooks = [];
  3114. $textBooks = [];
  3115. } else {
  3116. $parent_alias = $category->alias ?? '';
  3117. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  3118. // 查找子分类ID数组
  3119. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  3120. array_push($childCategoryIds, $parentCatId);
  3121. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  3122. if ($parentImgNum != 0) {
  3123. // 查询图片新闻
  3124. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  3125. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3126. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3127. })
  3128. ->where('book.status', 2)
  3129. ->where('book.img_url', '!=', '')
  3130. ->where('book.website_id', $website['website_id'])
  3131. ->leftJoin('website_category', function ($join) use ($website) {
  3132. $join->on('book.cat_id', '=', 'website_category.category_id')
  3133. ->where('website_category.website_id', '=', $website['website_id']);
  3134. })
  3135. ->select(
  3136. 'book.id',
  3137. 'book.title',
  3138. 'book.img_url',
  3139. 'book.price',
  3140. 'book.market_price',
  3141. 'book.description',
  3142. 'book.cat_id',
  3143. 'book.description',
  3144. 'book.updated_at',
  3145. 'website_category.alias as category_name',
  3146. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3147. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3148. )
  3149. ->orderBy('updated_at', 'desc')
  3150. ->limit($parentImgNum)
  3151. ->get()->all();
  3152. // 查询文字新闻
  3153. }
  3154. if ($parentTextNum != 0) {
  3155. $textBooks = [];
  3156. $textBooks = Book::where(function ($query) use ($parentCatId) {
  3157. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3158. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3159. })
  3160. ->where('book.status', 2)
  3161. ->where('book.website_id', $website['website_id'])
  3162. ->leftJoin('website_category', function ($join) use ($website) {
  3163. $join->on('book.cat_id', '=', 'website_category.category_id')
  3164. ->where('website_category.website_id', '=', $website['website_id']);
  3165. })
  3166. ->select(
  3167. 'book.id',
  3168. 'book.title',
  3169. 'book.img_url',
  3170. 'book.price',
  3171. 'book.market_price',
  3172. 'book.description',
  3173. 'book.cat_id',
  3174. 'book.description',
  3175. 'book.updated_at',
  3176. 'website_category.alias as category_name',
  3177. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3178. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3179. )
  3180. ->orderBy('updated_at', 'desc')
  3181. ->limit($parentTextNum)
  3182. ->get()->all();
  3183. }
  3184. }
  3185. }
  3186. $resultItem = [
  3187. 'alias' => $parent_alias ?? '',
  3188. 'category_id' => $parentCatId ?? 0,
  3189. 'pinyin' => $parent_pinyin ?? null,
  3190. 'imgnum' => $imgBooks ?? [],
  3191. 'textnum' => $textBooks ?? [],
  3192. ];
  3193. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  3194. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  3195. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  3196. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3197. ->get()->all();
  3198. if (!empty($childCategory)) {
  3199. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  3200. // 查询子栏目名称
  3201. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  3202. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3203. ->first();
  3204. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  3205. $childImgArticles = [];
  3206. $childTextArticles = [];
  3207. $resultItem['child'] = [];
  3208. } else {
  3209. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  3210. // 查询子栏目图片新闻
  3211. $childImgArticles = Book::where('cat_id', $childCatId)
  3212. ->where('status', 2)
  3213. ->where('img_url', '!=', '')
  3214. ->where('book.website_id', $website['website_id'])
  3215. ->leftJoin('website_category', function ($join) use ($website) {
  3216. $join->on('book.cat_id', '=', 'website_category.category_id')
  3217. ->where('website_category.website_id', '=', $website['website_id']);
  3218. })
  3219. ->select(
  3220. 'book.id',
  3221. 'book.title',
  3222. 'book.img_url',
  3223. 'book.price',
  3224. 'book.market_price',
  3225. 'book.description',
  3226. 'book.cat_id',
  3227. 'book.description',
  3228. 'book.updated_at',
  3229. DB::raw("'$child_pinyin' as pinyin")
  3230. )
  3231. ->orderBy('updated_at', 'desc')
  3232. ->limit($childImgNum)
  3233. ->get()->all();
  3234. // 查询子栏目文字新闻
  3235. $childTextArticles = Book::where('cat_id', $childCatId)
  3236. ->where('status', 2)
  3237. ->where('book.website_id', $website['website_id'])
  3238. ->leftJoin('website_category', function ($join) use ($website) {
  3239. $join->on('book.cat_id', '=', 'website_category.category_id')
  3240. ->where('website_category.website_id', '=', $website['website_id']);
  3241. })
  3242. ->select(
  3243. 'book.id',
  3244. 'book.title',
  3245. 'book.img_url',
  3246. 'book.price',
  3247. 'book.market_price',
  3248. 'book.description',
  3249. 'book.cat_id',
  3250. 'book.description',
  3251. 'book.updated_at',
  3252. DB::raw("'$child_pinyin' as pinyin")
  3253. )
  3254. ->orderBy('updated_at', 'desc')
  3255. ->limit($childTextNum)
  3256. ->get()->all();
  3257. $resultItem['child'] = [
  3258. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  3259. 'category_id' => $childCatId,
  3260. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  3261. 'all_childcat' => $childCategory,
  3262. 'imgnum' => $childImgArticles,
  3263. 'textnum' => $childTextArticles,
  3264. ];
  3265. }
  3266. }
  3267. } else {
  3268. $resultItem['child'] = [];
  3269. }
  3270. return $resultItem;
  3271. }, $data);
  3272. return Result::success($result);
  3273. }
  3274. /**
  3275. * 获取书刊列表
  3276. * @param array $data
  3277. * @return array
  3278. * */
  3279. public function getWebsiteBookList(array $data): array
  3280. {
  3281. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3282. if (empty($web)) {
  3283. return Result::error("查询失败", 0);
  3284. }
  3285. $catid = $data['id'];
  3286. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  3287. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  3288. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  3289. $category_pinyin = $category ? $category->aLias_pinyin : '';
  3290. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  3291. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  3292. ->where('pid', $category['pid'])
  3293. ->select(
  3294. 'category_id',
  3295. 'alias',
  3296. 'aLIas_pinyin',
  3297. 'pid',
  3298. 'sort',
  3299. 'is_url',
  3300. 'web_url',
  3301. 'seo_title',
  3302. 'seo_keywords',
  3303. 'seo_description',
  3304. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  3305. )
  3306. ->orderBy('sort')
  3307. ->get()->all();
  3308. if (empty($category)) {
  3309. return Result::error("查询失败", 0);
  3310. }
  3311. $query = Book::where('book.status', 2)
  3312. ->where('book.website_id', $data['website_id'])
  3313. ->where('book.cat_id', $catid)
  3314. ->select(
  3315. 'book.id',
  3316. 'book.title',
  3317. 'book.img_url',
  3318. 'book.description',
  3319. 'book.updated_at',
  3320. 'book.cat_id',
  3321. DB::raw("'$pinyin' as pinyin")
  3322. )
  3323. ->orderBy('book.updated_at', 'desc');
  3324. $count = $query->count();
  3325. $query = clone $query;
  3326. $Book = $query
  3327. ->limit($data['pageSize'])
  3328. ->offset(($data['page'] - 1) * $data['pageSize'])
  3329. ->get()->all();
  3330. $result = [
  3331. 'category' => $categorys,
  3332. 'books' => $Book,
  3333. 'count' => $count,
  3334. ];
  3335. // if(empty($result)){
  3336. // return Result::error("查询失败", 0);
  3337. // }
  3338. return Result::success($result);
  3339. }
  3340. /**
  3341. * 获取书刊详情
  3342. * @param array $data
  3343. * @return array
  3344. * */
  3345. public function getWebsiteBookInfo(array $data): array
  3346. {
  3347. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3348. if (empty($web)) {
  3349. return Result::error("查询失败", 0);
  3350. }
  3351. $book = Book::where('status', 2)
  3352. ->where('website_id', $data['website_id'])
  3353. ->where('id', $data['id'])
  3354. ->select(
  3355. 'book.*',
  3356. )
  3357. ->orderBy('updated_at', 'desc')
  3358. ->first();
  3359. if (empty($book)) {
  3360. return Result::error("查询失败", 0);
  3361. }
  3362. // 先查询当前分类的 pid
  3363. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  3364. ->where('category_id', $book['cat_id'])
  3365. ->first(['pid', 'category_id']);
  3366. $query = WebsiteCategory::where('website_id', $data['website_id']);
  3367. if (!empty($carpid)) {
  3368. if ($carpid->pid != 0) {
  3369. $pid = $carpid['pid'];
  3370. // $parent_pinyin = '';
  3371. } else {
  3372. $pid = $carpid['category_id'];
  3373. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  3374. }
  3375. }
  3376. $categorys = $query->where('pid', $pid)
  3377. ->select(
  3378. 'category_id',
  3379. 'alias',
  3380. 'aLIas_pinyin',
  3381. 'pid',
  3382. 'sort',
  3383. 'is_url',
  3384. 'web_url',
  3385. 'category_arr_id as cat_arr_id',
  3386. )
  3387. ->orderBy('sort')
  3388. ->get();
  3389. $category = $this->processArticle($categorys, $data);
  3390. $result = [
  3391. 'category' => $category,
  3392. 'books' => $book,
  3393. ];
  3394. return Result::success($result);
  3395. }
  3396. /**
  3397. * 尝试
  3398. * @param array $data
  3399. * @return array
  3400. * */
  3401. public function test(array $data): array
  3402. {
  3403. $input['id'] = $data['id'];
  3404. $input['website_id'] = $data['website_id'];
  3405. // 将 JSON 字符串转换为 PHP 数组
  3406. $data = json_decode($input['id'], true);
  3407. $result = [];
  3408. $article = $data;
  3409. $result = array_map(function ($item) use ($input) {
  3410. $website = [
  3411. 'website_id' => $input['website_id'],
  3412. ];
  3413. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3414. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3415. $parent = [
  3416. 0 => $category['category_id'] ?? [],
  3417. 1 => $parentImgNum ?? [],
  3418. 2 => $parentTextNum ?? [],
  3419. ];
  3420. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  3421. $child = [];
  3422. $resultItem = [
  3423. // 'alias' => $parent_alias ?? '',
  3424. 'category_id' => $parentCatId ?? 0,
  3425. 'pinyin' => $parentImgNum ?? null,
  3426. 'imgnum' => $parentTextNum ?? [],
  3427. // 'textnum' => $textArticles ?? [],
  3428. ];
  3429. return $parent;
  3430. }, $data);
  3431. return Result::success($result);
  3432. // });
  3433. }
  3434. /**
  3435. * 封装处理文章的路由问题
  3436. * */
  3437. function processArticle($article, $data)
  3438. {
  3439. return $article->map(function ($article) use ($data) {
  3440. $catid = $article->cat_arr_id ?? '';
  3441. $level = json_decode($catid, true);
  3442. $pinyin = '';
  3443. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  3444. if (!empty($level) && is_array($level)) {
  3445. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  3446. ->where('website_id', $data['website_id'])
  3447. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3448. ->get(['aLIas_pinyin'])
  3449. ->pluck('aLIas_pinyin')
  3450. ->implode('/');
  3451. } else {
  3452. $pinyin = '';
  3453. }
  3454. $article->pinyin = $pinyin;
  3455. return $article;
  3456. });
  3457. }
  3458. /**
  3459. * c端-获取招工招聘下拉选框
  3460. * @param array $data
  3461. * @return array
  3462. * */
  3463. public function getWebsiteJobSelect(array $data): array
  3464. {
  3465. $web = Website::where('id', $data['website_id'])->first();
  3466. if (empty($web)) {
  3467. return Result::error("该网站不存在", 0);
  3468. }
  3469. $hy = JobIndustry::get()->all();
  3470. $zw = JobPosition::where('zwpid', 0)->get()->all();
  3471. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  3472. $result = [
  3473. 'hy' => $hy,
  3474. 'zw' => $zw,
  3475. 'jtzw' => $jtzw,
  3476. ];
  3477. if (empty($result)) {
  3478. return Result::error("查询失败", 0);
  3479. }
  3480. return Result::success($result);
  3481. }
  3482. /**
  3483. * c端-获取招工招聘
  3484. * @param array $data
  3485. * @return array
  3486. * */
  3487. public function getWebsiteJob(array $data): array
  3488. {
  3489. $web = Website::where('id', $data['website_id'])->first();
  3490. if (empty($web)) {
  3491. return Result::error("该网站不存在", 0);
  3492. }
  3493. $job_hunting = JobHunting::where('job_hunting.status', 2)
  3494. ->where('job_hunting.website_id', $data['website_id'])
  3495. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3496. $query->where(function ($q) use ($data) {
  3497. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3498. });
  3499. })
  3500. ->select(
  3501. 'job_hunting.id',
  3502. 'job_hunting.catid',
  3503. 'job_hunting.cat_arr_id',
  3504. 'job_hunting.job_name_get',
  3505. 'job_hunting.industry',
  3506. 'job_hunting.name',
  3507. 'job_hunting.sexy',
  3508. 'job_hunting.origin',
  3509. 'job_hunting.city_arr_id',
  3510. 'job_hunting.experience',
  3511. 'job_hunting.updated_at',
  3512. 'job_hunting.salary',
  3513. 'job_hunting.skillList',
  3514. 'job_hunting.slelf_evaluation',
  3515. )
  3516. ->orderBy('updated_at', 'desc')
  3517. ->limit($data['job1_num'])
  3518. ->get();
  3519. $web['website_id'] = $data['website_id'];
  3520. if (empty($job_hunting)) {
  3521. $job_huntings = "未查询到相关简历信息";
  3522. } else {
  3523. $job_huntings = $this->processJob($job_hunting, $web);
  3524. }
  3525. // 0:待审核 1:已通过 2:已拒绝
  3526. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3527. ->where('job_recruiting.website_id', $data['website_id'])
  3528. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3529. $query->where(function ($q) use ($data) {
  3530. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3531. });
  3532. })
  3533. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3534. ->select(
  3535. 'job_recruiting.id',
  3536. 'job_recruiting.catid',
  3537. 'job_recruiting.cat_arr_id',
  3538. 'job_recruiting.title',
  3539. 'job_recruiting.jtzw_id',
  3540. 'job_recruiting.hy_id',
  3541. 'job_recruiting.city_arr_id',
  3542. 'job_recruiting.due_data',
  3543. 'job_recruiting.updated_at',
  3544. 'job_recruiting.experience',
  3545. 'job_recruiting.educational',
  3546. 'job_recruiting.salary',
  3547. 'job_recruiting.zw_id',
  3548. 'job_company.business_name',
  3549. 'job_recruiting.keyword',
  3550. 'job_recruiting.description',
  3551. )
  3552. ->orderBy('updated_at', 'desc')
  3553. ->limit($data['job2_num'])
  3554. ->get();
  3555. if (empty($job_recruiting->toArray())) {
  3556. $job_recruitings = "未查询到相关职位信息";
  3557. } else {
  3558. $job_recruitings = $this->processJob($job_recruiting, $web);
  3559. }
  3560. $result = [
  3561. 'job_hunting' => $job_huntings,
  3562. 'job_recuiting' => $job_recruitings,
  3563. ];
  3564. return Result::success($result);
  3565. }
  3566. /**
  3567. * c端-获取招工招聘列表
  3568. * @param array $data
  3569. * @return array
  3570. * */
  3571. public function getWebsiteJobList(array $data): array
  3572. {
  3573. $recruit_where = [];
  3574. $hunt_where = [];
  3575. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3576. if (empty($web)) {
  3577. return Result::error("此网站不存在", 0);
  3578. }
  3579. $website_id['website_id'] = $data['website_id'];
  3580. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3581. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3582. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3583. }
  3584. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3585. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3586. }
  3587. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3588. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3589. }
  3590. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3591. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3592. }
  3593. $query = JobRecruiting::where('job_recruiting.status', 1)
  3594. ->where('job_recruiting.website_id', $data['website_id'])
  3595. ->where($recruit_where)
  3596. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3597. $query->where(function ($q) use ($data) {
  3598. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3599. });
  3600. })
  3601. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3602. $query->where(function ($q) use ($data) {
  3603. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3604. });
  3605. })
  3606. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3607. ->select(
  3608. 'job_recruiting.id',
  3609. 'job_recruiting.catid',
  3610. 'job_recruiting.hy_id',
  3611. 'job_recruiting.title',
  3612. 'job_recruiting.zw_id',
  3613. 'job_recruiting.educational',
  3614. 'job_recruiting.jtzw_id',
  3615. 'job_recruiting.city_arr_id',
  3616. 'job_recruiting.due_data',
  3617. 'job_recruiting.experience',
  3618. 'job_recruiting.cat_arr_id',
  3619. 'job_recruiting.updated_at',
  3620. 'job_company.business_name',
  3621. 'job_recruiting.keyword',
  3622. 'job_recruiting.description',
  3623. )
  3624. ->orderBy('job_recruiting.updated_at', 'desc');
  3625. $recruit_count = $query->count();
  3626. $query = clone $query;
  3627. $JobRecruiting = $query
  3628. ->offset(($data['page'] - 1) * $data['pageSize'])
  3629. ->limit($data['pageSize'])
  3630. ->get();
  3631. if (empty($JobRecruiting)) {
  3632. $JobRecruiting = "暂无相关职位信息";
  3633. } else {
  3634. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3635. }
  3636. }
  3637. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3638. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3639. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3640. }
  3641. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3642. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3643. }
  3644. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3645. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3646. }
  3647. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3648. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3649. }
  3650. $query = JobHunting::where('job_hunting.status', 2)
  3651. ->where('job_hunting.website_id', $data['website_id'])
  3652. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3653. ->where($hunt_where)
  3654. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3655. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3656. // })
  3657. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3658. $query->where(function ($q) use ($data) {
  3659. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3660. });
  3661. })
  3662. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3663. $query->where(function ($q) use ($data) {
  3664. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3665. });
  3666. })
  3667. ->select(
  3668. 'job_hunting.id',
  3669. 'job_hunting.catid',
  3670. 'job_hunting.sexy',
  3671. 'job_hunting.experience',
  3672. 'job_hunting.origin',
  3673. 'job_hunting.industry',
  3674. 'job_hunting.name',
  3675. 'job_hunting.job',
  3676. 'job_hunting.job_name_get',
  3677. 'job_hunting.city_arr_id',
  3678. 'job_hunting.cat_arr_id',
  3679. 'job_hunting.created_at',
  3680. 'job_hunting.updated_at',
  3681. 'job_position.zwname as job_name',
  3682. 'job_hunting.skillList',
  3683. 'job_hunting.slelf_evaluation',
  3684. )
  3685. ->orderBy('job_hunting.updated_at', 'desc');
  3686. $hunt_count = $query->count();
  3687. $query = clone $query;
  3688. $JobHunting = $query
  3689. ->offset(($data['page'] - 1) * $data['pageSize'])
  3690. ->limit($data['pageSize'])
  3691. ->get();
  3692. if (empty($JobHunting)) {
  3693. $JobRecruiting = "暂无相关简历信息";
  3694. } else {
  3695. $JobHunting = $this->processJob($JobHunting, $website_id);
  3696. }
  3697. }
  3698. $result = [
  3699. 'JobRecruiting' => $JobRecruiting ?? [],
  3700. 'recruit_count' => $recruit_count ?? 0,
  3701. 'JobHunting' => $JobHunting ?? [],
  3702. 'hunt_count' => $hunt_count ?? 0,
  3703. ];
  3704. return Result::success($result);
  3705. }
  3706. /**
  3707. * c端-获取招工招聘详情
  3708. * @param array $data
  3709. * @return array
  3710. * */
  3711. public function getWebsiteJobInfo(array $data): array
  3712. {
  3713. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3714. if (empty($web)) {
  3715. return Result::error("该网站不存在", 0);
  3716. }
  3717. $webid = [
  3718. 'website_id' => $data['website_id'],
  3719. ];
  3720. // 职位相关信息
  3721. if ($data['type'] == 1) {
  3722. $query = JobRecruiting::where('status', 1)
  3723. ->where('website_id', $data['website_id'])
  3724. ->select('*');
  3725. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3726. $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();
  3727. if (!empty($company)) {
  3728. $result['company'] = $this->processJob($company, $webid);
  3729. }
  3730. $other_job = JobRecruiting::where('status', 1)
  3731. ->where('website_id', $data['website_id'])
  3732. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3733. ->where('id', '!=', $data['id'])
  3734. ->where('user_id', '=', $job[0]['user_id'])
  3735. ->limit($data['pageSize'])
  3736. ->get();
  3737. if (!empty($other_job)) {
  3738. $result['other_job'] = $this->processJob($other_job, $webid);
  3739. }
  3740. } else {
  3741. // 简历相关信息
  3742. $job = JobHunting::where('job_hunting.status', 2)
  3743. ->where('job_hunting.website_id', $data['website_id'])
  3744. ->where('job_hunting.id', $data['id'])
  3745. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3746. ->select('job_hunting.*', 'user_name')
  3747. ->get();
  3748. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3749. if (!empty($resume->toArray())) {
  3750. $result['resume'] = 1;
  3751. } else {
  3752. $result['resume'] = 0;
  3753. }
  3754. }
  3755. if (empty($job->toArray())) {
  3756. return Result::error("id参数错误", 0);
  3757. }
  3758. if (!empty($job[0]['job_experience'])) {
  3759. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3760. if (!empty($job_experience)) {
  3761. // $hy = [];
  3762. foreach ($job_experience as $key => $value) {
  3763. // $id = $value['id'];
  3764. $hy[$key] = $value['job_industry'];
  3765. $zw_id[$key] = $value['job_typename'];
  3766. $jtzw_id[$key] = $value['job_name'];
  3767. }
  3768. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3769. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3770. // 先将关联表转换为索引数组,提高查找效率
  3771. $hyLookup = [];
  3772. foreach ($hy_table as $item) {
  3773. $hyLookup[$item['hyid']] = $item['hyname'];
  3774. }
  3775. $zwLookup = [];
  3776. foreach ($zw_table as $item) {
  3777. $zwLookup[$item['zwid']] = $item['zwname'];
  3778. }
  3779. foreach ($job_experience as $key => &$value) {
  3780. // 处理行业名称
  3781. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3782. $value['hy_name'] = $hyLookup[$hy[$key]];
  3783. }
  3784. // 处理职位名称
  3785. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3786. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3787. }
  3788. // 处理具体职位名称
  3789. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3790. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3791. }
  3792. }
  3793. // 释放引用,防止意外修改后续代码
  3794. unset($value);
  3795. }
  3796. $result['job_experience'] = $job_experience ?? [];
  3797. }
  3798. if (!empty($job[0]['education_experience'])) {
  3799. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3800. if (!empty($education_experience)) {
  3801. foreach ($education_experience as $key => $value) {
  3802. // $id = $value['id'];
  3803. $education[$key] = $value['school_education'];
  3804. }
  3805. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3806. // // 先将关联表转换为索引数组,提高查找效率
  3807. $educationLookup = [];
  3808. foreach ($education_table as $item) {
  3809. $educationLookup[$item['evalue']] = $item['ename'];
  3810. }
  3811. foreach ($education_experience as $key => &$value) {
  3812. // 处理学历名称
  3813. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3814. $value['education_name'] = $educationLookup[$education[$key]];
  3815. }
  3816. }
  3817. }
  3818. $result['education_experience'] = $job_experience ?? [];
  3819. }
  3820. $result['job'] = $this->processJob($job, $webid);
  3821. // // 返现对应的栏目
  3822. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3823. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3824. ->whereIn('category_id', $catid)
  3825. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3826. ->orderBy('pid')->get()->all();
  3827. if (!empty($category)) {
  3828. $result['category'] = $category;
  3829. }
  3830. $result['job'] = $job;
  3831. $result['job_experience'] = $job_experience ?? [];
  3832. $result['education_experience'] = $education_experience ?? [];
  3833. if (empty($result)) {
  3834. return Result::error("参数错误", 0);
  3835. }
  3836. return Result::success($result);
  3837. }
  3838. /**
  3839. * c端-申请职位
  3840. * @param array $data
  3841. * @return array
  3842. * */
  3843. public function getWebsiteJobApply(array $data): array
  3844. {
  3845. // 首先验证网站是否存在
  3846. // return Result::success($data);
  3847. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3848. if (empty($web)) {
  3849. return Result::error("该网站不存在", 0);
  3850. }
  3851. // 验证用户是否存在且为个人会员/管理员
  3852. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3853. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3854. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3855. return Result::error("用户不存在", 0);
  3856. }
  3857. // 去除重复元素和空元素,并保持原始顺序
  3858. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3859. return !empty($value);
  3860. }));
  3861. // 验证职位是否存在 1:审核通过
  3862. $recruiting = JobRecruiting::where('status', 1)
  3863. ->where('website_id', $data['website_id'])
  3864. ->whereIn('id', $data['recruit_id'])
  3865. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3866. if (empty($recruiting)) {
  3867. return Result::error("该职位不存在", 0);
  3868. }
  3869. // 简历是否存在
  3870. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3871. if (empty($hunt_id)) {
  3872. return Result::error("该简历不存在", 0);
  3873. }
  3874. $data['hunt_id'] = $hunt_id['hunt_id'];
  3875. // // 验证是否已投递过该职位
  3876. $apply = JobApply::where('user_id', $data['user_id'])
  3877. ->where('hunt_id', $data['hunt_id'])
  3878. ->where('website_id', $data['website_id'])
  3879. ->whereIn('recruit_id', $data['recruit_id'])
  3880. ->get(['recruit_id']);
  3881. if (!empty($apply->toArray())) {
  3882. return Result::error("您已投递过该职位!");
  3883. }
  3884. $insertData = array_map(function ($recruiting) use ($data) {
  3885. return [
  3886. 'user_id' => $data['user_id'],
  3887. 'hunt_id' => $data['hunt_id'],
  3888. 'website_id' => $data['website_id'],
  3889. 'recruit_id' => $recruiting['recruit_id'],
  3890. 'receiver_id' => $recruiting['receiver_id'],
  3891. 'status' => 1,
  3892. ];
  3893. }, $recruiting);
  3894. // 批量插入数据
  3895. $result = JobApply::insert($insertData);
  3896. if (empty($result)) {
  3897. return Result::error("投递失败", 0);
  3898. }
  3899. return Result::success($result);
  3900. }
  3901. /**
  3902. * 招工招聘-沟通简历
  3903. * @param array $data
  3904. * @return array
  3905. * */
  3906. public function getWebsiteJobResume(array $data): array
  3907. {
  3908. // 首先验证网站是否存在
  3909. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3910. if (empty($web)) {
  3911. return Result::error("该网站不存在", 0);
  3912. }
  3913. // return Result::success($data);
  3914. // 验证用户是否存在且为企业会员/管理员
  3915. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3916. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3917. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3918. return Result::error("用户不存在", 0);
  3919. }
  3920. // 去除重复元素和空元素,并保持原始顺序
  3921. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3922. return !empty($value);
  3923. }));
  3924. // 验证简历是否存在
  3925. $hunting = JobHunting::where('status', 2)
  3926. ->where('website_id', $data['website_id'])
  3927. ->whereIn('id', $data['hunt_id'])
  3928. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3929. if (empty($hunting)) {
  3930. return Result::error("该简历不存在", 0);
  3931. }
  3932. // 验证是否已沟通过该简历
  3933. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3934. ->where('recruit_id', $data['recruit_id'])
  3935. ->where('website_id', $data['website_id'])
  3936. ->whereIn('hunt_id', $data['hunt_id'])
  3937. ->get(['hunt_id']);
  3938. if (!empty($remuse->toArray())) {
  3939. return Result::error("您已沟通过该简历!");
  3940. }
  3941. // 准备要插入的数据数组
  3942. $insertData = array_map(function ($hunting) use ($data) {
  3943. return [
  3944. 'user_id' => $data['user_id'],
  3945. 'recruit_id' => $data['recruit_id'],
  3946. 'website_id' => $data['website_id'],
  3947. 'hunt_id' => $hunting['hunt_id'],
  3948. 'receiver_id' => $hunting['receiver_id'],
  3949. 'status' => 1,
  3950. ];
  3951. }, $hunting);
  3952. // 批量插入数据
  3953. $result = JobRemuse::insert($insertData);
  3954. if (empty($result)) {
  3955. return Result::error("沟通失败", 0);
  3956. }
  3957. return Result::success($result);
  3958. }
  3959. /**
  3960. * 招工招聘 -我的职位(企业会员)
  3961. * @param array $data
  3962. * @return array
  3963. */
  3964. public function getWebsiteJobRecruiting(array $data): array
  3965. {
  3966. $web = Website::where('id', $data['website_id'])->first('id');
  3967. if (empty($web)) {
  3968. return Result::error("该网站不存在", 0);
  3969. }
  3970. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3971. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3972. return Result::error("用户暂无权限!", 0);
  3973. }
  3974. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3975. $result = JobRecruiting::where('website_id', $data['website_id'])
  3976. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3977. $query->where('user_id', $user['id']);
  3978. })
  3979. ->where('status', 1)
  3980. ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
  3981. ->orderBy('updated_at', 'desc')
  3982. ->limit($data['pageSize'])
  3983. ->get();
  3984. if (empty($result)) {
  3985. return Result::error("暂无相关职位信息", 0);
  3986. }
  3987. return Result::success($result);
  3988. }
  3989. /**
  3990. * c端 - 验证路由
  3991. * @param array $data
  3992. * @return array
  3993. */
  3994. /**
  3995. * c端 - 验证路由
  3996. * @param array $data
  3997. * @return array
  3998. */
  3999. public function checkWebsiteRoute(array $data): array
  4000. {
  4001. // 测试001111111222
  4002. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  4003. if (empty($web)) {
  4004. return Result::error("该网站不存在", 0);
  4005. } elseif ($web['status'] != 1) {
  4006. return Result::error("网站已经关闭", 0);
  4007. }
  4008. if (isset($data['other_route']) && !empty($data['other_route'])) {
  4009. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  4010. // 验证路由是否存在
  4011. if (empty($whiteRouterInfo)) {
  4012. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  4013. }
  4014. if (!empty($whiteRouterInfo)) {
  4015. return Result::success($whiteRouterInfo->toArray());
  4016. }
  4017. }
  4018. // 验证栏目路由
  4019. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  4020. ->where('path', $data['all_route'])
  4021. ->get()->all();
  4022. if (count($last_category) == 0) {
  4023. return Result::error("该栏目不存在", 0);
  4024. }
  4025. if (count($last_category) > 1) {
  4026. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  4027. }
  4028. if (count($last_category) == 1) {
  4029. $last_category = $last_category[0];
  4030. }
  4031. // return Result::success($last_category);
  4032. if (isset($data['id']) && !empty($data['id'])) {
  4033. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  4034. switch ($last_category['type']) {
  4035. case 1:
  4036. // 文章
  4037. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  4038. $article = Article::where('status', 1)
  4039. ->where('id', $data['id'])
  4040. ->where(function ($query) use ($data) {
  4041. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  4042. ->orWhereNull("ignore_ids");
  4043. })
  4044. ->first(['catid']);
  4045. if (empty($article)) {
  4046. return Result::error("该文章不存在", 0);
  4047. }
  4048. // return Result::success($article);
  4049. break;
  4050. case 2:
  4051. // 商品
  4052. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4053. $article = Good::where('website_id', $data['website_id'])
  4054. ->where('status', 2)
  4055. ->where('id', $data['id'])
  4056. ->first(['cat_arr_id']);
  4057. if (empty($article)) {
  4058. return Result::error("该商品不存在", 0);
  4059. }
  4060. break;
  4061. case 3:
  4062. // 书刊信息
  4063. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4064. $article = Book::where('website_id', $data['website_id'])
  4065. ->where('status', 2)
  4066. ->where('id', $data['id'])
  4067. ->first(['id', 'cat_arr_id']);
  4068. if (empty($article)) {
  4069. return Result::error("该书刊不存在", 0);
  4070. }
  4071. break;
  4072. case 4:
  4073. // 招聘
  4074. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  4075. $article = JobRecruiting::where('website_id', $data['website_id'])
  4076. ->where('status', 1)
  4077. ->where('id', $data['id'])
  4078. ->first(['cat_arr_id']);
  4079. if (empty($article)) {
  4080. return Result::error("该招聘不存在", 0);
  4081. }
  4082. break;
  4083. case 5:
  4084. // 求职
  4085. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4086. $article = JobHunting::where('website_id', $data['website_id'])
  4087. ->where('status', 2)
  4088. ->where('id', $data['id'])
  4089. ->first(['cat_arr_id']);
  4090. if (empty($article)) {
  4091. return Result::error("该求职不存在", 0);
  4092. }
  4093. break;
  4094. case 6:
  4095. // 企业
  4096. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4097. $article = Company::
  4098. // where('website_id', $data['website_id'])
  4099. // ->
  4100. where('status', 1)
  4101. ->where('id', $data['id'])
  4102. ->first(['cat_arr_id']);
  4103. if (empty($article)) {
  4104. return Result::error("该企业不存在", 0);
  4105. }
  4106. break;
  4107. case 7:
  4108. // 项目
  4109. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4110. $article = Project::where('website_id', $data['website_id'])
  4111. ->where('status', 1)
  4112. ->where('id', $data['id'])
  4113. ->first(['cat_arr_id']);
  4114. if (empty($article)) {
  4115. return Result::error("该项目不存在", 0);
  4116. }
  4117. break;
  4118. default:
  4119. return Result::error("该数据不存在", 0);
  4120. break;
  4121. }
  4122. // return Result::success($article);
  4123. // $catid =0 ;
  4124. if (!isset($article['cat_arr_id'])) {
  4125. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  4126. } else {
  4127. $catidArray = json_decode($article['cat_arr_id'], true);
  4128. $catid = !empty($catidArray) ? end($catidArray) : null;
  4129. }
  4130. // return Result::success($catid);
  4131. // // return Result::success($article['cat_arr_id']);
  4132. if (empty($catid)) {
  4133. return Result::error("该栏目路径不存在", 0);
  4134. }
  4135. $path = WebsiteCategory::where('website_id', $data['website_id'])
  4136. ->where('category_id', $catid)
  4137. ->first('path');
  4138. }
  4139. // else{
  4140. // // if ($last_category['pid'] != 0) {
  4141. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  4142. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  4143. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  4144. // ->where('category_id',$catid)
  4145. // ->where('path',$data['all_route'])
  4146. // ->first('path');
  4147. // // } else {
  4148. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  4149. // // }
  4150. // }
  4151. // return Result::success($path);
  4152. if (!empty($path) && $path['path'] != $data['all_route']) {
  4153. return Result::error('非法路径!');
  4154. } else {
  4155. return Result::success($last_category['path']);
  4156. }
  4157. }
  4158. /**
  4159. * 招工招聘 - 获取推荐职位
  4160. * @param array $data
  4161. * @return array
  4162. */
  4163. public function getWebsiteLevelJob(array $data): array
  4164. {
  4165. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  4166. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  4167. ->where('job_recruiting.status', 1)
  4168. ->where('job_level', $data['job_level'])
  4169. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4170. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  4171. ->orderBy('job_recruiting.updated_at', 'desc')
  4172. ->limit($data['pageSize'])
  4173. ->get();
  4174. $web = ['website_id' => $data['website_id']];
  4175. if (!empty($job)) {
  4176. $result = $this->processJob($job, $web);
  4177. }
  4178. if (empty($result)) {
  4179. return Result::error("暂无相关职位信息", 0);
  4180. }
  4181. return Result::success($result);
  4182. }
  4183. /**
  4184. * 验证导航名称是否重复
  4185. * @return void
  4186. */
  4187. //20250226 产品列表
  4188. public function getGoodList(array $data): array
  4189. {
  4190. var_dump($data, '---------1-2--');
  4191. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  4192. unset($data['user_type_id']);
  4193. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4194. $where = [];
  4195. if ($type_id != '10000') {
  4196. $where = [
  4197. 'good.user_id' => $user_id,
  4198. ];
  4199. }
  4200. //类型
  4201. if (isset($data['type_id']) && $data['type_id']) {
  4202. $where['good.type_id'] = $data['type_id'];
  4203. }
  4204. //名称
  4205. if (isset($data['name']) && $data['name']) {
  4206. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  4207. }
  4208. //status
  4209. if (isset($data['status']) && $data['status'] != '') {
  4210. $where['good.status'] = $data['status'];
  4211. }
  4212. //status1
  4213. // if (isset($data['status1']) && $data['status1'] == 1) {
  4214. // $status1 = 1;
  4215. // }
  4216. $where1 = [];
  4217. //website_id
  4218. // if (isset($data['website_id']) && $data['website_id']) {
  4219. // $where1 = [
  4220. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  4221. // ];
  4222. // }
  4223. // website_name
  4224. if (isset($data['website_name']) && $data['website_name']) {
  4225. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  4226. }
  4227. // catid
  4228. if (isset($data['category_name']) && $data['category_name']) {
  4229. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  4230. }
  4231. // $result = Good::where($where)
  4232. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  4233. var_dump($where, '---------1---');
  4234. $result = Good::where($where)
  4235. ->when(!empty($where1), function ($query) use ($where1) {
  4236. return $query->where($where1);
  4237. })
  4238. //status 1待审核2已审核3已拒绝
  4239. ->when(isset($data['status1']), function ($query) {
  4240. return $query->whereIn('good.status', [1, 3]);
  4241. })
  4242. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4243. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4244. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4245. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4246. ->orderBy("updated_at", "desc")
  4247. ->limit($data['page_size'])
  4248. ->offset(($data['page'] - 1) * $data['page_size'])
  4249. ->get();
  4250. $count = Good::where($where)
  4251. ->when(!empty($where1), function ($query) use ($where1) {
  4252. return $query->where($where1);
  4253. })
  4254. //status 1待审核2已审核3已拒绝
  4255. ->when(isset($data['status1']), function ($query) {
  4256. return $query->whereIn('good.status', [1, 3]);
  4257. })
  4258. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4259. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4260. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4261. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4262. ->orderBy("updated_at", "desc")->count();
  4263. $data = [
  4264. 'rows' => $result->toArray(),
  4265. 'count' => $count,
  4266. ];
  4267. if (empty($result)) {
  4268. return Result::error("此栏目暂无相关产品", 0);
  4269. }
  4270. return Result::success($data);
  4271. }
  4272. public function getGoodInfo(array $data): array
  4273. {
  4274. $result = Good::where('id', $data['id'])->first();
  4275. if (empty($result)) {
  4276. return Result::error("此产品不存在", 0);
  4277. }
  4278. return Result::success($result);
  4279. }
  4280. public function addGood(array $data): array
  4281. {
  4282. // unset($data['city_arr_id']);
  4283. // unset($data['cat_arr_id']);
  4284. $data['city_id'] = end($data['city_arr_id']);
  4285. $data['catid'] = end($data['cat_arr_id']);
  4286. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4287. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4288. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4289. unset($data['imgUrl']); //大小写
  4290. if (isset($data['price']) && $data['price'] == '') {
  4291. $data['price'] = 0;
  4292. }
  4293. if ($data['imgurl'] == '') {
  4294. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4295. preg_match_all($reg, $data['detail'], $matches);
  4296. if (isset($matches[1][0])) {
  4297. //截取varchar240
  4298. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4299. }
  4300. }
  4301. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4302. //提取标题+内容中的关键词
  4303. $data['keyword'] = $data['name'];
  4304. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4305. Jieba::init(); // 初始化 jieba-php
  4306. Finalseg::init();
  4307. $segList = Jieba::cut($data['keyword']);
  4308. $segList1 = array_slice($segList, 0, 8);
  4309. $data['keyword'] = implode(',', $segList1);
  4310. }
  4311. if ($data['description'] == '') {
  4312. //提取内容中的描述
  4313. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4314. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4315. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4316. }
  4317. if ($data['status'] == 1) {
  4318. $this->sendMessage([
  4319. 'talk_type' => 200,
  4320. 'title' => $data['name'],
  4321. 'content' => '提交了审核',
  4322. 'messageType' => 3,
  4323. ]);
  4324. }
  4325. $result = Good::insert($data);
  4326. if (empty($result)) {
  4327. return Result::error("添加失败", 0);
  4328. }
  4329. return Result::success($result);
  4330. }
  4331. public function updateGood(array $data): array
  4332. {
  4333. $data['city_id'] = end($data['city_arr_id']);
  4334. $data['catid'] = end($data['cat_arr_id']);
  4335. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4336. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4337. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4338. //设置东八区
  4339. date_default_timezone_set('Asia/Shanghai');
  4340. $data['updated_at'] = date('Y-m-d H:i:s');
  4341. if (isset($data['price']) && $data['price'] == '') {
  4342. $data['price'] = 0;
  4343. }
  4344. if ($data['imgurl'] == '') {
  4345. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4346. preg_match_all($reg, $data['detail'], $matches);
  4347. if (isset($matches[1][0])) {
  4348. //截取varchar240
  4349. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4350. }
  4351. }
  4352. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4353. //提取标题+内容中的关键词
  4354. $data['keyword'] = $data['name'];
  4355. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4356. Jieba::init(); // 初始化 jieba-php
  4357. Finalseg::init();
  4358. $segList = Jieba::cut($data['keyword']);
  4359. $segList1 = array_slice($segList, 0, 8);
  4360. $data['keyword'] = implode(',', $segList1);
  4361. }
  4362. if ($data['description'] == '') {
  4363. //提取内容中的描述
  4364. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4365. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4366. }
  4367. if ($data['status'] == 1) {
  4368. $this->sendMessage([
  4369. 'talk_type' => 200,
  4370. 'title' => $data['name'],
  4371. 'content' => '提交了审核',
  4372. 'messageType' => 3,
  4373. ]);
  4374. }
  4375. $result = Good::where('id', $data['id'])->update($data);
  4376. if (empty($result)) {
  4377. return Result::error("更新失败", 0);
  4378. }
  4379. return Result::success($result);
  4380. }
  4381. public function delGood(array $data): array
  4382. {
  4383. $result = Good::where('id', $data['id'])->delete();
  4384. if (empty($result)) {
  4385. return Result::error("删除失败", 0);
  4386. }
  4387. return Result::success($result);
  4388. }
  4389. //20250226 产品列表
  4390. //20250306 求职信息
  4391. public function getJobHuntingList(array $data): array
  4392. {
  4393. $where = [];
  4394. if (isset($data['username']) && !empty($data['username'])) {
  4395. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4396. }
  4397. //status 1待审核2已审核3已拒绝
  4398. if (isset($data['status']) && $data['status'] != '') {
  4399. $where = [
  4400. 'job_hunting.status' => $data['status'],
  4401. ];
  4402. }
  4403. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4404. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4405. unset($data['type_id']);
  4406. if ($type_id != '10000') {
  4407. $where[] = ['job_hunting.user_id', '=', $user_id];
  4408. }
  4409. $result = JobHunting::where($where)
  4410. ->when(!empty($data['status1']), function ($query) use ($data) {
  4411. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4412. })
  4413. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4414. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4415. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  4416. ->orderBy("updated_at", "desc")
  4417. ->limit($data['page_size'])
  4418. ->offset(($data['page'] - 1) * $data['page_size'])
  4419. ->get();
  4420. if (empty($result)) {
  4421. return Result::error("查询失败", 0);
  4422. }
  4423. $count = JobHunting::where($where)
  4424. ->when(!empty($data['status1']), function ($query) use ($data) {
  4425. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4426. })
  4427. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4428. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4429. ->count();
  4430. $data = [
  4431. 'rows' => $result->toArray(),
  4432. 'count' => $count,
  4433. ];
  4434. return Result::success($data);
  4435. }
  4436. public function getJobHuntingApply(array $data): array
  4437. {
  4438. var_dump($data, '-----------------test--------1-');
  4439. $where = [];
  4440. if (isset($data['username']) && !empty($data['username'])) {
  4441. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4442. }
  4443. if (isset($data['salary']) && !empty($data['salary'])) {
  4444. $where[] = [
  4445. 'job_hunting.salary',
  4446. '=',
  4447. $data['salary'],
  4448. ];
  4449. }
  4450. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4451. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4452. unset($data['type_id']);
  4453. if ($type_id != '10000') {
  4454. $where[] = ['job_apply.receiver_id', '=', $user_id];
  4455. }
  4456. var_dump($where, '-----------------test---------');
  4457. $result = jobApply::where($where)
  4458. // ->when(!empty($data['status1']), function ($query) use ($data) {
  4459. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4460. // })
  4461. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  4462. ->where('job_enum.egroup', '=', 'income')
  4463. ->where('job_hunting.status', 2) //已审核
  4464. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4465. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4466. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4467. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4468. //职位----是申请职位
  4469. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4470. ->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')
  4471. ->orderBy("job_hunting.updated_at", "desc")
  4472. ->limit($data['page_size'])
  4473. ->offset(($data['page'] - 1) * $data['page_size'])
  4474. ->get();
  4475. if (empty($result)) {
  4476. return Result::error("查询失败", 0);
  4477. }
  4478. $count = jobApply::where($where)
  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. ->count();
  4489. $data = [
  4490. 'rows' => $result->toArray(),
  4491. 'count' => $count,
  4492. ];
  4493. return Result::success($data);
  4494. }
  4495. public function addJobHunting(array $data): array
  4496. {
  4497. date_default_timezone_set('Asia/Shanghai');
  4498. unset($data['company_name']);
  4499. unset($data['job_industry']);
  4500. unset($data['job_name']);
  4501. unset($data['department']);
  4502. unset($data['job_timeList']);
  4503. unset($data['job_content']);
  4504. unset($data['job_typename']); //不知道这是啥,
  4505. $data['created_at'] = date('Y-m-d H:i:s');
  4506. $data['updated_at'] = date('Y-m-d H:i:s');
  4507. //根据用户 user_id 只能添加一次
  4508. $result = JobHunting::where('user_id', $data['user_id'])->first();
  4509. if (!empty($result)) {
  4510. return Result::error("您已添加过求职信息", 0);
  4511. }
  4512. var_dump($result, '-----------------test---------');
  4513. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  4514. if (is_string($data['city_arr_id'])) {
  4515. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4516. $cityArr = json_decode($data['city_arr_id'], true);
  4517. // 确保 $cityArr 是数组
  4518. if (is_array($cityArr)) {
  4519. $data['city_id'] = end($cityArr);
  4520. }
  4521. } else {
  4522. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4523. if (is_array($data['city_arr_id'])) {
  4524. $data['city_id'] = end($data['city_arr_id']);
  4525. }
  4526. }
  4527. }
  4528. // 处理求职所绑定栏目
  4529. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4530. if (is_string($data['cat_arr_id'])) {
  4531. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4532. // 先清理可能存在的无效 JSON 字符
  4533. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4534. $catArr = json_decode($cleanedCatArrStr, true);
  4535. // 检查 JSON 解码是否成功且结果是数组
  4536. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4537. $data['catid'] = end($catArr);
  4538. }
  4539. } else {
  4540. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4541. if (is_array($data['cat_arr_id'])) {
  4542. $data['catid'] = end($data['cat_arr_id']);
  4543. }
  4544. }
  4545. }
  4546. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4547. $this->sendMessage([
  4548. 'talk_type' => 600,
  4549. 'title' => $data['name'],
  4550. 'content' => '提交了审核',
  4551. 'messageType' => 11,
  4552. ]);
  4553. }
  4554. $result = JobHunting::create($data);
  4555. if (empty($result)) {
  4556. return Result::error("添加失败", 0);
  4557. }
  4558. return Result::success($result);
  4559. }
  4560. public function delJobHunting(array $data): array
  4561. {
  4562. $result = JobHunting::where('id', $data['id'])->delete();
  4563. if (empty($result)) {
  4564. return Result::error("删除失败", 0);
  4565. }
  4566. return Result::success($result);
  4567. }
  4568. public function updateJobHunting(array $data): array
  4569. {
  4570. //设置东八区
  4571. date_default_timezone_set('Asia/Shanghai');
  4572. unset($data['company_name']);
  4573. unset($data['job_industry']);
  4574. unset($data['job_name']);
  4575. unset($data['department']);
  4576. unset($data['job_timeList']);
  4577. unset($data['job_content']);
  4578. unset($data['job_typename']); //不知道这是啥,
  4579. $data['created_at'] = date('Y-m-d H:i:s');
  4580. $data['updated_at'] = date('Y-m-d H:i:s');
  4581. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4582. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4583. $cityArr = json_decode($data['city_arr_id'], true);
  4584. $data['city_id'] = end($cityArr);
  4585. } else {
  4586. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4587. $data['city_id'] = end($data['city_arr_id']);
  4588. }
  4589. // 处理求职所绑定栏目
  4590. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4591. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4592. $catArr = json_decode($data['cat_arr_id'], true);
  4593. $data['catid'] = end($catArr);
  4594. } else {
  4595. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4596. $data['catid'] = end($data['cat_arr_id']);
  4597. }
  4598. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4599. $this->sendMessage([
  4600. 'talk_type' => 600,
  4601. 'title' => $data['name'],
  4602. 'content' => '提交了审核',
  4603. 'messageType' => 11,
  4604. ]);
  4605. }
  4606. $result = JobHunting::where('id', $data['id'])->update($data);
  4607. if (empty($result)) {
  4608. return Result::error("更新失败", 0);
  4609. }
  4610. return Result::success($result);
  4611. }
  4612. public function getJobHuntingInfo(array $data): array
  4613. {
  4614. $result = JobHunting::where('id', $data['id'])->first();
  4615. if (empty($result)) {
  4616. return Result::error("查询失败", 0);
  4617. }
  4618. return Result::success($result);
  4619. }
  4620. public function getJobHuntingData(array $data): array
  4621. {
  4622. $jobEnum = JobEnum::get();
  4623. $jobIndustry = JobIndustry::get();
  4624. $jobNature = JobNature::get();
  4625. $jobPosition = JobPosition::get();
  4626. $data = [
  4627. 'jobEnum' => $jobEnum,
  4628. 'jobIndustry' => $jobIndustry,
  4629. 'jobNature' => $jobNature,
  4630. 'jobPosition' => $jobPosition,
  4631. ];
  4632. return Result::success($data);
  4633. }
  4634. public function delJobHuntingInfo(array $data): array
  4635. {
  4636. $result = JobHunting::where('id', $data['id'])->delete();
  4637. return Result::success();
  4638. }
  4639. //20250324 通知,公告,消息
  4640. public function delNotice(array $data): array
  4641. {
  4642. $result = Notice::where('id', $data['id'])->delete();
  4643. if ($result) {
  4644. return Result::success();
  4645. } else {
  4646. return Result::error("删除失败", 0);
  4647. }
  4648. }
  4649. public function getNoticeInfo(array $data): array
  4650. {
  4651. $result = Notice::where('id', $data['id'])->first();
  4652. // var_dump($result['re_user_ids'], '--------------------');
  4653. if (empty($result)) {
  4654. return Result::error("查询失败", 0);
  4655. }
  4656. return Result::success($result);
  4657. }
  4658. public function readNotice(array $data): array
  4659. {
  4660. $result = Notice::where('id', $data['id'])->first();
  4661. // var_dump($result['re_user_ids'], '--------------------');
  4662. if (empty($result)) {
  4663. return Result::error("查询失败", 0);
  4664. }
  4665. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4666. $re_user_ids = json_decode($result['re_user_ids'], true);
  4667. var_dump($re_user_ids, '--------------1---test---------');
  4668. var_dump($data, '--------------1---test---------');
  4669. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4670. //如果已经存在,就不再添加
  4671. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4672. $read_id = json_decode($result['read_id'], true);
  4673. if (!is_array($read_id)) {
  4674. $read_id = [];
  4675. }
  4676. if (!in_array($data['user_id'], $read_id)) {
  4677. $read_id[] = $data['user_id'];
  4678. $result['read_id'] = json_encode($read_id);
  4679. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4680. }
  4681. } else {
  4682. //如果不存在,就添加
  4683. $result['read_id'] = json_encode([$data['user_id']]);
  4684. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4685. }
  4686. }
  4687. return Result::success($result);
  4688. }
  4689. public function addNotice(array $data): array
  4690. {
  4691. date_default_timezone_set('Asia/Shanghai');
  4692. $data['created_at'] = date('Y-m-d H:i:s');
  4693. $data['updated_at'] = date('Y-m-d H:i:s');
  4694. // $data['level'] = "1,2,3,4,5";
  4695. $level = json_decode($data['level'], true);
  4696. $user_id = UserInfo::
  4697. //city_id不是null
  4698. whereNotNull('city_id')
  4699. ->whereNotNull('department_id')
  4700. ->where(function ($query) use ($data) {
  4701. $query->where(function ($subQuery) use ($data) {
  4702. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4703. });
  4704. })
  4705. ->where(function ($query) use ($data) {
  4706. $query->where(function ($subQuery) use ($data) {
  4707. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4708. });
  4709. })
  4710. ->when(isset($level) && is_array($level), function ($query) use ($level) {
  4711. $query->whereIn('level', $level);
  4712. })
  4713. ->pluck('user_id')->toArray();
  4714. $user_id = array_unique($user_id);
  4715. $chat_ids = $user_id;
  4716. $user_id = json_encode($user_id);
  4717. $data['re_user_ids'] = $user_id;
  4718. $this->sendMessage([
  4719. 'talk_type' => 700,
  4720. 'title' => $data['title'],
  4721. 'content' => '提交了审核',
  4722. 'messageType' => 5,
  4723. ]);
  4724. $result = Notice::insertGetId($data);
  4725. if (empty($result)) {
  4726. return Result::error("添加失败", 0);
  4727. }
  4728. return Result::success($result);
  4729. }
  4730. public function updateNotice(array $data): array
  4731. {
  4732. date_default_timezone_set('Asia/Shanghai');
  4733. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4734. $user_id = UserInfo::
  4735. //city_id不是null
  4736. whereNotNull('city_id')
  4737. ->whereNotNull('department_id')
  4738. ->where(function ($query) use ($data) {
  4739. $query->where(function ($subQuery) use ($data) {
  4740. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4741. });
  4742. })
  4743. ->where(function ($query) use ($data) {
  4744. $query->where(function ($subQuery) use ($data) {
  4745. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4746. });
  4747. })
  4748. ->pluck('user_id')->toArray();
  4749. $user_id = array_unique($user_id);
  4750. $user_id = json_encode($user_id);
  4751. $data['re_user_ids'] = $user_id;
  4752. $data['updated_at'] = date('Y-m-d H:i:s');
  4753. $this->sendMessage([
  4754. 'talk_type' => 700,
  4755. 'title' => $data['title'],
  4756. 'content' => '提交了审核',
  4757. 'messageType' => 5,
  4758. ]);
  4759. $result = Notice::where('id', $data['id'])->update($data);
  4760. return Result::success($result);
  4761. }
  4762. public function getNoticeList(array $data): array
  4763. {
  4764. $where = [];
  4765. //title
  4766. if (isset($data['title']) && !empty($data['title'])) {
  4767. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4768. }
  4769. //level
  4770. if (isset($data['level']) && !empty($data['level'])) {
  4771. $where[] = ['notice.level', '=', $data['level']];
  4772. }
  4773. //status
  4774. if (isset($data['status']) && !empty($data['status'])) {
  4775. $where[] = ['notice.status', '=', $data['status']];
  4776. }
  4777. //type
  4778. if (isset($data['type']) && !empty($data['type'])) {
  4779. $where[] = ['notice.type', '=', $data['type']];
  4780. }
  4781. var_dump($data, '------------11111-2----test---------');
  4782. if ($data['type_id'] == 10000) {
  4783. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4784. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4785. })
  4786. ->where($where)
  4787. ->orderBy('updated_at', 'desc')
  4788. ->limit($data['page_size'])
  4789. ->offset(($data['page'] - 1) * $data['page_size'])
  4790. ->get();
  4791. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4792. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4793. })
  4794. ->where($where)
  4795. ->orderBy('updated_at', 'desc')
  4796. ->count();
  4797. } else {
  4798. $result = Notice::where($where)
  4799. // ->where('user_id', $data['user_id'])
  4800. ->Where(function ($query) use ($data) {
  4801. $query->Where(function ($q) use ($data) {
  4802. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4803. ->orWhere('notice.user_id', $data['user_id']);
  4804. });
  4805. })
  4806. ->when(!empty($data['status1']), function ($query) use ($data) {
  4807. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4808. })
  4809. ->orderBy('updated_at', 'desc')
  4810. ->limit($data['page_size'])
  4811. ->offset(($data['page'] - 1) * $data['page_size'])
  4812. ->get();
  4813. $total = Notice::where($where)
  4814. ->when(!empty($data['status1']), function ($query) use ($data) {
  4815. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4816. })
  4817. // ->where('user_id', $data['user_id'])
  4818. ->Where(function ($query) use ($data) {
  4819. $query->Where(function ($q) use ($data) {
  4820. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4821. ->orWhere('notice.user_id', $data['user_id']);
  4822. });
  4823. })
  4824. ->count();
  4825. }
  4826. if (empty($result)) {
  4827. return Result::error("查询失败", 0);
  4828. }
  4829. $data = [
  4830. 'rows' => $result,
  4831. 'count' => $total,
  4832. ];
  4833. return Result::success($data);
  4834. }
  4835. public function noticeList(array $data): array
  4836. {
  4837. $where = [];
  4838. //title
  4839. if (isset($data['title']) && !empty($data['title'])) {
  4840. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4841. }
  4842. //level
  4843. if (isset($data['level']) && !empty($data['level'])) {
  4844. $where[] = ['notice.level', '=', $data['level']];
  4845. }
  4846. //status
  4847. if (isset($data['status']) && !empty($data['status'])) {
  4848. $where[] = ['notice.status', '=', $data['status']];
  4849. }
  4850. //type
  4851. if (isset($data['type']) && !empty($data['type'])) {
  4852. $where[] = ['notice.type', '=', $data['type']];
  4853. }
  4854. var_dump($data, '------------11111-2----test---------');
  4855. if ($data['type_id'] == 10000) {
  4856. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4857. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4858. })
  4859. ->where($where)
  4860. ->orderBy('updated_at', 'desc')
  4861. ->limit($data['page_size'])
  4862. ->offset(($data['page'] - 1) * $data['page_size'])
  4863. ->get();
  4864. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4865. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4866. })
  4867. ->where($where)
  4868. ->orderBy('updated_at', 'desc')
  4869. ->count();
  4870. } else {
  4871. $result = Notice::where($where)
  4872. // ->where('user_id', $data['user_id'])
  4873. ->Where(function ($query) use ($data) {
  4874. $query->Where(function ($q) use ($data) {
  4875. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4876. ->orWhere('notice.user_id', $data['user_id']);
  4877. });
  4878. })
  4879. ->when(!empty($data['status1']), function ($query) use ($data) {
  4880. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4881. })
  4882. ->orderBy('updated_at', 'desc')
  4883. ->limit($data['page_size'])
  4884. ->offset(($data['page'] - 1) * $data['page_size'])
  4885. ->get();
  4886. $total = Notice::where($where)
  4887. ->when(!empty($data['status1']), function ($query) use ($data) {
  4888. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4889. })
  4890. // ->where('user_id', $data['user_id'])
  4891. ->Where(function ($query) use ($data) {
  4892. $query->Where(function ($q) use ($data) {
  4893. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4894. ->orWhere('notice.user_id', $data['user_id']);
  4895. });
  4896. })
  4897. ->count();
  4898. }
  4899. if (empty($result)) {
  4900. return Result::error("查询失败", 0);
  4901. }
  4902. $data = [
  4903. 'rows' => $result,
  4904. 'count' => $total,
  4905. ];
  4906. return Result::success($data);
  4907. }
  4908. public function getNoticeDetail(array $data): array
  4909. {
  4910. $result = Notice::where('id', $data['id'])->first();
  4911. if (empty($result)) {
  4912. return Result::error("查询失败", 0);
  4913. }
  4914. return Result::success($result);
  4915. }
  4916. public function deleteNotice(array $data): array
  4917. {
  4918. $notice = Notice::where('id', $data['id'])->first();
  4919. if (empty($notice)) {
  4920. return Result::error("删除失败", 0);
  4921. }
  4922. $chat_group_id = $notice->group_id;
  4923. if ($chat_group_id) {
  4924. //删除群聊
  4925. ChatGroups::where('id', $chat_group_id)->delete();
  4926. //删除群成员
  4927. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4928. //删除群聊记录
  4929. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4930. }
  4931. $result = Notice::where('id', $data['id'])->delete();
  4932. return Result::success($result);
  4933. }
  4934. public function complaintList(array $data): array
  4935. {
  4936. var_dump($data, '---------1---------');
  4937. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4938. unset($data['type_id']);
  4939. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4940. $where = [];
  4941. if ($type_id != 10000 && empty($data['deal_user'])) {
  4942. // $where['complaint.user_id'] = $user_id;
  4943. }
  4944. if (!empty($data['title'])) {
  4945. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4946. }
  4947. if (!empty($data['department_id'])) {
  4948. $where['complaint.department_id'] = $data['department_id'];
  4949. }
  4950. if (!empty($data['deal'])) {
  4951. $where['complaint.deal'] = $data['deal'];
  4952. }
  4953. if (!empty($data['status'])) {
  4954. $where['complaint.status'] = $data['status'];
  4955. }
  4956. var_dump(!empty($data['deal_user']), '----------1');
  4957. var_dump($where, '----------2');
  4958. $result = Complaint::where($where)
  4959. ->when(!empty($data['status1']), function ($query) use ($data) {
  4960. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4961. })
  4962. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4963. //json re_user_ids data[user_id]是不是在里面
  4964. $query->Where(function ($q) use ($data) {
  4965. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4966. ->where('complaint.status', 2);
  4967. });
  4968. })
  4969. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4970. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4971. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4972. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4973. ->orderBy('updated_at', 'desc')
  4974. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4975. //sql输出
  4976. if (empty($result)) {
  4977. return Result::error("暂无投诉信息", 0);
  4978. }
  4979. // 取出数据
  4980. $rows = $result->items();
  4981. $count = $result->total();
  4982. $responseData = [
  4983. 'rows' => $rows,
  4984. 'count' => $count,
  4985. ];
  4986. return Result::success($responseData);
  4987. }
  4988. public function getComplaintList(array $data): array
  4989. {
  4990. var_dump($data, '00000001000000000000');
  4991. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4992. unset($data['type_id']);
  4993. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4994. $where = [];
  4995. if ($type_id != 10000 && empty($data['deal_user'])) {
  4996. $where['complaint.user_id'] = $user_id;
  4997. }
  4998. if (!empty($data['title'])) {
  4999. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  5000. }
  5001. if (!empty($data['department_id'])) {
  5002. $where['complaint.department_id'] = $data['department_id'];
  5003. }
  5004. if (!empty($data['deal'])) {
  5005. $where['complaint.deal'] = $data['deal'];
  5006. }
  5007. if (!empty($data['status'])) {
  5008. $where['complaint.status'] = $data['status'];
  5009. }
  5010. var_dump(!empty($data['deal_user']), '----------1');
  5011. var_dump($where, '----------2');
  5012. $result = Complaint::where($where)
  5013. ->when(!empty($data['status1']), function ($query) use ($data) {
  5014. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  5015. })
  5016. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  5017. // //json re_user_ids data[user_id]是不是在里面
  5018. // $query->Where(function ($q) use ($data) {
  5019. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  5020. // ->where('complaint.status', 2);
  5021. // });
  5022. // })
  5023. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  5024. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  5025. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  5026. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  5027. ->orderBy('updated_at', 'desc')
  5028. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5029. //sql输出
  5030. if (empty($result)) {
  5031. return Result::error("暂无投诉信息", 0);
  5032. }
  5033. // 取出数据
  5034. $rows = $result->items();
  5035. $count = $result->total();
  5036. $responseData = [
  5037. 'rows' => $rows,
  5038. 'count' => $count,
  5039. ];
  5040. return Result::success($responseData);
  5041. }
  5042. public function getComplaintInfo(array $data): array
  5043. {
  5044. $result = Complaint::where('id', $data['id'])->first();
  5045. if (empty($result)) {
  5046. return Result::error("查询失败", 0);
  5047. }
  5048. return Result::success($result);
  5049. }
  5050. public function readComplaint(array $data): array
  5051. {
  5052. $result = Complaint::where('id', $data['id'])->first();
  5053. if (empty($result)) {
  5054. return Result::error("查询失败", 0);
  5055. }
  5056. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  5057. $re_user_ids = json_decode($result['re_user_ids'], true);
  5058. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  5059. //如果已经存在,就不再添加
  5060. if (isset($result['read_id']) && !empty($result['read_id'])) {
  5061. $read_id = json_decode($result['read_id'], true);
  5062. if (!is_array($read_id)) {
  5063. $read_id = [];
  5064. }
  5065. if (!in_array($data['user_id'], $read_id)) {
  5066. $read_id[] = $data['user_id'];
  5067. $result['read_id'] = json_encode($read_id);
  5068. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  5069. }
  5070. } else {
  5071. //如果不存在,就添加
  5072. $result['read_id'] = json_encode([$data['user_id']]);
  5073. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  5074. }
  5075. }
  5076. return Result::success($result);
  5077. }
  5078. public function addComplaint(array $data): array
  5079. {
  5080. date_default_timezone_set('Asia/Shanghai');
  5081. $data['created_at'] = date('Y-m-d H:i:s');
  5082. $data['updated_at'] = date('Y-m-d H:i:s');
  5083. $this->sendMessage([
  5084. 'talk_type' => 800,
  5085. 'title' => $data['title'],
  5086. 'content' => '提交了审核',
  5087. 'messageType' => 6,
  5088. ]);
  5089. $result = Complaint::create($data);
  5090. return Result::success($result);
  5091. }
  5092. public function updateComplaint(array $data): array
  5093. {
  5094. date_default_timezone_set('Asia/Shanghai');
  5095. $data['updated_at'] = date('Y-m-d H:i:s');
  5096. $user_id = $data['user_id'] ?? 0;
  5097. $type_id = $data['type_id'] ?? 0;
  5098. unset($data['user_id']);
  5099. unset($data['type_id']);
  5100. $this->sendMessage([
  5101. 'talk_type' => 800,
  5102. 'title' => $data['title'],
  5103. 'content' => '提交了审核',
  5104. 'messageType' => 6,
  5105. ]);
  5106. $result = Complaint::where('id', $data['id'])->update($data);
  5107. return Result::success($result);
  5108. }
  5109. public function deleteComplaint(array $data): array
  5110. {
  5111. $result = Complaint::where('id', $data['id'])->delete();
  5112. return Result::success($result);
  5113. }
  5114. public function getComplainInfo(array $data): array
  5115. {
  5116. $result = Complaint::where('id', $data['id'])->first();
  5117. if (empty($result)) {
  5118. return Result::error("查询失败", 0);
  5119. }
  5120. return Result::success($result);
  5121. }
  5122. public function updateComplaintStatus(array $data): array
  5123. {
  5124. date_default_timezone_set('Asia/Shanghai');
  5125. $data['updated_at'] = date('Y-m-d H:i:s');
  5126. $user_id = $data['user_id'] ?? 0;
  5127. $type_id = $data['type_id'] ?? 0;
  5128. unset($data['user_id']);
  5129. unset($data['type_id']);
  5130. //处理, 写入处理人
  5131. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  5132. $data['real_deal_user'] = $user_id;
  5133. }
  5134. //如果是deal 23,则判断是不是处理人
  5135. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  5136. $complaintInof = Complaint::where('id', $data['id'])
  5137. ->where('real_deal_user', $user_id)
  5138. ->first();
  5139. if (empty($complaintInof)) {
  5140. return Result::error("处理人错误", 0);
  5141. }
  5142. }
  5143. $complaintInfo = Complaint::where('id', $data['id'])->first();
  5144. if ($data['status'] == 1) {
  5145. $this->sendMessage([
  5146. 'talk_type' => 800,
  5147. 'title' => $complaintInfo['title'],
  5148. 'content' => '提交了审核',
  5149. 'messageType' => 6,
  5150. ]);
  5151. }
  5152. if ($data['status'] == 2 && !isset($data['deal'])) {
  5153. $this->sendMessage([
  5154. 'talk_type' => 801,
  5155. 'title' => $complaintInfo['title'],
  5156. 'content' => '审核通过',
  5157. 'messageType' => 6,
  5158. 'user_id' => $complaintInfo['user_id'],
  5159. ]);
  5160. $this->sendMessage([
  5161. 'talk_type' => 802,
  5162. 'title' => $complaintInfo['title'],
  5163. 'content' => '待处理',
  5164. 'messageType' => 6,
  5165. 'user_id' => $complaintInfo['re_user_ids'],
  5166. ]);
  5167. }
  5168. if ($data['status'] == 3 && !isset($data['deal'])) {
  5169. $this->sendMessage([
  5170. 'talk_type' => 801,
  5171. 'title' => $complaintInfo['title'],
  5172. 'content' => '审核拒绝',
  5173. 'messageType' => 6,
  5174. 'user_id' => $complaintInfo['user_id'],
  5175. ]);
  5176. }
  5177. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  5178. $this->sendMessage([
  5179. 'talk_type' => 802,
  5180. 'title' => $complaintInfo['title'],
  5181. 'content' => '处理中',
  5182. 'messageType' => 6,
  5183. 'user_id' => $complaintInfo['re_user_ids'],
  5184. ]);
  5185. }
  5186. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  5187. $this->sendMessage([
  5188. 'talk_type' => 802,
  5189. 'title' => $complaintInfo['title'],
  5190. 'content' => '不予处理',
  5191. 'messageType' => 6,
  5192. 'user_id' => $complaintInfo['re_user_ids'],
  5193. ]);
  5194. }
  5195. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  5196. $this->sendMessage([
  5197. 'talk_type' => 802,
  5198. 'title' => $complaintInfo['title'],
  5199. 'content' => '已完结',
  5200. 'messageType' => 6,
  5201. 'user_id' => $complaintInfo['re_user_ids'],
  5202. ]);
  5203. }
  5204. $result = complaint::where('id', $data['id'])->update($data);
  5205. return Result::success($result);
  5206. }
  5207. public function updateGoodStatus(array $data): array
  5208. {
  5209. $user_id = $data['user_id'] ?? 0;
  5210. $type_id = $data['type_id'] ?? 0;
  5211. unset($data['user_id']);
  5212. unset($data['type_id']);
  5213. $goodInfo = Good::where('id', $data['id'])->first();
  5214. if ($data['status'] == 2) {
  5215. $this->sendMessage([
  5216. 'talk_type' => 201,
  5217. 'title' => $goodInfo['name'],
  5218. 'content' => '审核通过',
  5219. 'messageType' => 3,
  5220. 'user_id' => $goodInfo['user_id'],
  5221. ]);
  5222. }
  5223. if ($data['status'] == 3) {
  5224. $this->sendMessage([
  5225. 'talk_type' => 201,
  5226. 'title' => $goodInfo['name'],
  5227. 'content' => '审核拒绝',
  5228. 'messageType' => 3,
  5229. 'user_id' => $goodInfo['user_id'],
  5230. ]);
  5231. }
  5232. if ($data['status'] == 1) {
  5233. $this->sendMessage([
  5234. 'talk_type' => 200,
  5235. 'title' => $goodInfo['name'],
  5236. 'content' => '提交了审核',
  5237. 'messageType' => 3,
  5238. ]);
  5239. }
  5240. $result = Good::where('id', $data['id'])->update($data);
  5241. return Result::success($result);
  5242. }
  5243. public function updateJobHuntingStatus(array $data): array
  5244. {
  5245. $user_id = $data['user_id'] ?? 0;
  5246. $type_id = $data['type_id'] ?? 0;
  5247. unset($data['user_id']);
  5248. unset($data['type_id']);
  5249. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  5250. if ($data['status'] == 2) {
  5251. $this->sendMessage([
  5252. 'talk_type' => 601,
  5253. 'title' => $jogHuntingInfo['name'],
  5254. 'content' => '审核通过',
  5255. 'messageType' => 11,
  5256. 'user_id' => $jogHuntingInfo['user_id'],
  5257. ]);
  5258. }
  5259. if ($data['status'] == 3) {
  5260. $this->sendMessage([
  5261. 'talk_type' => 601,
  5262. 'title' => $jogHuntingInfo['name'],
  5263. 'content' => '审核拒绝',
  5264. 'messageType' => 11,
  5265. 'user_id' => $jogHuntingInfo['user_id'],
  5266. ]);
  5267. }
  5268. if ($data['status'] == 1) {
  5269. $this->sendMessage([
  5270. 'talk_type' => 600,
  5271. 'title' => $jogHuntingInfo['name'],
  5272. 'content' => '提交了审核',
  5273. 'messageType' => 11,
  5274. ]);
  5275. }
  5276. $result = JobHunting::where('id', $data['id'])->update($data);
  5277. return Result::success($result);
  5278. }
  5279. public function updateNoticeStatus(array $data): array
  5280. {
  5281. $user_id = $data['user_id'] ?? 0;
  5282. $type_id = $data['type_id'] ?? 0;
  5283. unset($data['user_id']);
  5284. unset($data['type_id']);
  5285. //查询公告
  5286. $notice = Notice::where('id', $data['id'])->first();
  5287. if (empty($notice)) {
  5288. return Result::error("公告不存在", 0);
  5289. }
  5290. //$chat_ids 去除掉$data['user_id']
  5291. $chat_ids = json_decode($notice['re_user_ids'], true);
  5292. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  5293. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  5294. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  5295. //chat_group
  5296. $group_id = PublicData::uuid();
  5297. $groupData = [
  5298. 'id' => $group_id,
  5299. 'creator_id' => $notice['user_id'],
  5300. 'group_name' => $notice['group_name'] ?? '',
  5301. 'profile' => $notice['profile'] ?? 0,
  5302. ];
  5303. var_dump($groupData, '-----------------groupData-------');
  5304. $groupResult = ChatGroups::insertGetId($groupData);
  5305. var_dump($groupResult, '-----------------groupid-------');
  5306. $groupMemberData = [
  5307. 'id' => PublicData::uuid(),
  5308. 'user_id' => $notice['user_id'],
  5309. 'group_id' => $group_id,
  5310. 'leader' => 2,
  5311. ];
  5312. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  5313. //插入群成员表
  5314. $groupMemberDataUser = [];
  5315. $chatData = [];
  5316. foreach ($chat_ids as $key => $value) {
  5317. $groupMemberDataUser[] = [
  5318. 'id' => PublicData::uuid(),
  5319. 'user_id' => $value,
  5320. 'group_id' => $group_id,
  5321. 'leader' => 1,
  5322. ];
  5323. $chatData[] = [
  5324. 'user_id' => $value,
  5325. 'msg_type' => 1,
  5326. 'receiver_id' => $group_id,
  5327. 'content' => '通过通知创建群聊',
  5328. 'group_receiver_id' => $notice['user_id'],
  5329. 'action' => 'recieved',
  5330. 'created_at' => date('Y-m-d H:i:s'),
  5331. ];
  5332. }
  5333. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  5334. ChatGroupsMember::insert($groupMemberDataUser);
  5335. //插入一条管理员聊天记录
  5336. $chatData[] = [
  5337. 'user_id' => $notice['user_id'],
  5338. 'msg_type' => 1,
  5339. 'receiver_id' => $group_id,
  5340. 'content' => '通过通知创建群聊',
  5341. 'group_receiver_id' => $notice['user_id'],
  5342. 'action' => 'said',
  5343. 'created_at' => date('Y-m-d H:i:s'),
  5344. ];
  5345. var_dump($chatData, '-----------------chatData-------');
  5346. $chatResult = ChatRecords::insert($chatData);
  5347. //处理imp
  5348. $group = [
  5349. 'type' => 1,
  5350. 'name' => $notice['group_name'] ?? '',
  5351. 'profile' => '',
  5352. 'avatar' => '',
  5353. 'creator_id' => $notice['user_id'],
  5354. ];
  5355. $groupResult = GroupImp::insertGetId($group);
  5356. var_dump($groupResult, '获取imp group_id');
  5357. $groupMember = [
  5358. 'user_id' => $notice['user_id'],
  5359. 'group_id' => $groupResult,
  5360. 'leader' => 1,
  5361. 'join_time' => Date('Y-m-d H:i:s')
  5362. ];
  5363. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  5364. $talk_session = [
  5365. 'user_id' => $notice['user_id'],
  5366. 'to_from_id' => $groupResult,
  5367. 'talk_mode' => 2,
  5368. 'created_at' => Date('Y-m-d H:i:s'),
  5369. 'updated_at' => Date('Y-m-d H:i:s'),
  5370. ];
  5371. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  5372. //被通知人员处理
  5373. foreach ($chat_ids as $key => $value) {
  5374. $groupMemberdata[] = [
  5375. 'user_id' => $value,
  5376. 'group_id' => $groupResult,
  5377. 'leader' => 3,
  5378. 'join_time' => Date('Y-m-d H:i:s')
  5379. ];
  5380. $talk_sessionData[] = [
  5381. 'user_id' => $value,
  5382. 'to_from_id' => $groupResult,
  5383. 'talk_mode' => 2,
  5384. 'created_at' => Date('Y-m-d H:i:s'),
  5385. 'updated_at' => Date('Y-m-d H:i:s'),
  5386. ];
  5387. }
  5388. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  5389. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  5390. $group_id = $groupResult;
  5391. //更新result的 group_id
  5392. $data['group_id'] = $group_id;
  5393. Notice::where(['id' => $data['id']])->update($data);
  5394. }
  5395. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  5396. //删除掉信息
  5397. GroupImp::where('id', $notice['group_id'])->delete();
  5398. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  5399. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  5400. foreach ($chat_ids as $key => $value) {
  5401. }
  5402. //聊天记录删除
  5403. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  5404. $data['group_id'] = null;
  5405. Notice::where(['id' => $data['id']])->update($data);
  5406. }
  5407. $result = Notice::where('id', $data['id'])->update($data);
  5408. $noticeInfo = Notice::where('id', $data['id'])->first();
  5409. if ($data['status'] == 2) {
  5410. $this->sendMessage([
  5411. 'talk_type' => 701,
  5412. 'title' => $noticeInfo['title'],
  5413. 'content' => '审核通过',
  5414. 'messageType' => 3,
  5415. 'user_id' => $noticeInfo['user_id'],
  5416. ]);
  5417. }
  5418. if ($data['status'] == 3) {
  5419. $this->sendMessage([
  5420. 'talk_type' => 701,
  5421. 'title' => $noticeInfo['title'],
  5422. 'content' => '审核拒绝',
  5423. 'messageType' => 3,
  5424. 'user_id' => $noticeInfo['user_id'],
  5425. ]);
  5426. }
  5427. if ($data['status'] == 1) {
  5428. $this->sendMessage([
  5429. 'talk_type' => 700,
  5430. 'title' => $noticeInfo['title'],
  5431. 'content' => '提交了审核',
  5432. 'messageType' => 3,
  5433. ]);
  5434. }
  5435. return Result::success($result);
  5436. }
  5437. public function getDUser(array $data): array
  5438. {
  5439. if (!empty($data['ids'])) {
  5440. $user = User::whereIn('id', $data['ids'])->getall();
  5441. if (empty($user)) {
  5442. return Result::error('无数据', 0);
  5443. }
  5444. return Result::success($user);
  5445. }
  5446. $where = [];
  5447. if (!empty($data['department_id'])) {
  5448. $where['department_id'] = $data['department_id'];
  5449. }
  5450. if (!empty($data['city_id'])) {
  5451. $where['city_id'] = $data['city_id'];
  5452. }
  5453. $result = User::where('type_id', 2)
  5454. ->where('status', 1)
  5455. ->where($where)
  5456. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  5457. ->get();
  5458. if (empty($result)) {
  5459. return Result::error("查询失败", 0);
  5460. }
  5461. return Result::success($result);
  5462. }
  5463. /**
  5464. * 验证导航名称是否重复
  5465. * @return void
  5466. */
  5467. public function checkCategoryName(array $data): array
  5468. {
  5469. $result = Category::when($data, function ($query) use ($data) {
  5470. if (isset($data['name']) && $data['name']) {
  5471. $query->where("name", $data['name']);
  5472. }
  5473. if (isset($data['id']) && $data['id']) {
  5474. $query->where("id", "!=", $data['id']);
  5475. }
  5476. })->first();
  5477. if ($result) {
  5478. return Result::error("已存在");
  5479. } else {
  5480. return Result::success();
  5481. }
  5482. }
  5483. //20250226 产品列表
  5484. // 20250306 -------招聘--------fr
  5485. /*
  5486. * 招聘列表
  5487. * */
  5488. public function getJobRecruitingList(array $data): array
  5489. {
  5490. $where = [];
  5491. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  5492. if ($data['checkout'] == 0) {
  5493. $job_status = [0, 2];
  5494. } else {
  5495. $job_status = [1];
  5496. }
  5497. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5498. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  5499. }
  5500. $user = User::where('id', $data['user_id'])->first();
  5501. if (empty($user)) {
  5502. return Result::error("用户不存在", 0);
  5503. }
  5504. // 3:企业会员
  5505. if ($user['type_id'] == 3) {
  5506. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  5507. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  5508. }
  5509. // 如果 $where 为空,则不添加 where 条件
  5510. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5511. return $query->where($where);
  5512. })
  5513. ->whereIn('job_recruiting.status', $job_status)
  5514. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5515. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  5516. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  5517. ->orderBy("updated_at", "desc")
  5518. ->offset(($data['page'] - 1) * $data['page_size'])
  5519. ->limit($data['page_size'])
  5520. ->get()
  5521. ->all();
  5522. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5523. return $query->where($where);
  5524. })
  5525. ->whereIn('job_recruiting.status', $job_status)
  5526. ->count();
  5527. if (empty($result)) {
  5528. return Result::error("暂无招聘信息", 0);
  5529. }
  5530. return Result::success($result);
  5531. }
  5532. /*
  5533. * 招聘信息添加
  5534. * */
  5535. public function addJobRecruiting(array $data): array
  5536. {
  5537. // var_dump('添加招聘进入news------data',$data);
  5538. // return Result::success($data);
  5539. $user = User::where('user.id', $data['user_id'])
  5540. ->where('user.status', 1)
  5541. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5542. ->select(
  5543. 'user.type_id',
  5544. 'user.mobile',
  5545. 'user.email',
  5546. 'user_info.business_name',
  5547. 'user_info.company_hy_id',
  5548. 'user_info.company_nature',
  5549. 'user_info.company_size',
  5550. 'user_info.introduction',
  5551. 'user_info.real_name',
  5552. 'user_info.company_url',
  5553. 'user_info.address_arr_id',
  5554. 'user_info.address'
  5555. )
  5556. ->first();
  5557. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5558. return Result::error("用户不存在", 0);
  5559. }
  5560. $web = Website::where('id', $data['website_id'])->first();
  5561. if (empty($web)) {
  5562. return Result::error("网站不存在", 0);
  5563. }
  5564. // var_dump('添加招聘进入news---user---user',$user);
  5565. // 处理招聘关键词
  5566. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5567. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5568. } else {
  5569. Jieba::init(); // 初始化 jieba-php
  5570. Finalseg::init();
  5571. $segList = Jieba::cut($data['title']);
  5572. $segList1 = array_slice($segList, 0, 8);
  5573. $data['keyword'] = implode(',', $segList1);
  5574. }
  5575. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5576. $content = $data['description'];
  5577. // 去除 <style> 和 <script> 标签及其内容
  5578. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5579. // 去除所有 HTML 标签
  5580. $content = strip_tags($content);
  5581. // 去除 HTML 实体
  5582. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5583. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5584. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5585. // 去除多余空白
  5586. $content = preg_replace('/\s+/u', '', $content);
  5587. // 截取 100 个字符
  5588. $data['seo_description'] = mb_substr($content, 0, 100);
  5589. }
  5590. // return Result::success($user);
  5591. $data['action_id'] = $data['user_id'] ?? null;
  5592. $data['user_type'] = $user['type_id'] ?? null;
  5593. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5594. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5595. $data['catid'] = end($data['cat_arr_id']);
  5596. } else {
  5597. $data['catid'] = 0;
  5598. }
  5599. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5600. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5601. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5602. // 公司地址 管理员必填
  5603. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5604. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5605. // 管理员-企业相关信息
  5606. $company = [
  5607. // 'user_id' => $data['user_id']?? null,
  5608. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5609. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5610. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5611. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5612. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5613. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5614. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5615. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5616. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5617. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5618. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5619. ];
  5620. //去掉相关企业信息
  5621. $job = array_diff_key($data, array_flip(array_keys($company)));
  5622. // var_dump('添加招聘进入news---job---user',$job);
  5623. Db::beginTransaction();
  5624. try {
  5625. // // 先添加职位相关信息
  5626. if ($user['type_id'] == 10000) {
  5627. $job['status'] = 1;
  5628. }
  5629. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5630. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5631. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5632. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5633. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5634. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5635. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5636. // return Result::success($job);
  5637. $jobId = JobRecruiting::insertGetId($job);
  5638. if (empty($jobId)) {
  5639. Db::rollBack();
  5640. return Result::error("添加失败");
  5641. }
  5642. // 添加公司信息
  5643. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5644. $company['job_id'] = $jobId;
  5645. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5646. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5647. if ($user['type_id'] == 10000) {
  5648. // 管理员添加企业信息
  5649. $companyId = JobCompany::insertGetId($company);
  5650. if (empty($companyId)) {
  5651. Db::rollBack();
  5652. return Result::error("添加失败");
  5653. }
  5654. } else {
  5655. // 企业会员添加企业信息
  5656. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5657. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5658. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5659. $company['job_id'] = $jobId;
  5660. $companyId = JobCompany::insertGetId($company);
  5661. if (empty($companyId)) {
  5662. Db::rollBack();
  5663. return Result::error("添加失败");
  5664. }
  5665. }
  5666. Db::commit();
  5667. $result = [
  5668. 'job_id' => $jobId,
  5669. 'company_id' => $companyId,
  5670. ];
  5671. return Result::success($result);
  5672. } catch (\Exception $e) {
  5673. Db::rollBack();
  5674. return Result::error($e->getMessage(), 0);
  5675. }
  5676. // return Result::success($result);
  5677. }
  5678. /*
  5679. * 获取招聘信息详情
  5680. * */
  5681. public function getJobRecruitingInfo(array $data): array
  5682. {
  5683. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5684. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5685. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5686. ->select(
  5687. 'job_recruiting.*',
  5688. 'website.website_name as website_name',
  5689. 'job_company.business_name',
  5690. 'job_company.company_hy_id',
  5691. 'job_company.company_size',
  5692. 'job_company.company_nature',
  5693. 'job_company.introduction',
  5694. 'job_company.real_name',
  5695. 'job_company.mobile',
  5696. 'job_company.company_url',
  5697. 'job_company.address_arr_id',
  5698. 'job_company.address',
  5699. 'job_company.email'
  5700. )
  5701. ->first();
  5702. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5703. if (!empty($cityId)) {
  5704. if (isset($cityId[1]) && $cityId[1] != null) {
  5705. $city = District::where('id', $cityId[1])->first(['name']);
  5706. } else {
  5707. $city = District::where('id', $cityId[0])->first(['name']);
  5708. }
  5709. $result['city'] = $city['name'] ?? '';
  5710. }
  5711. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5712. if (is_array($addressId) && !empty($addressId)) {
  5713. $address = District::whereIn('id', $addressId)
  5714. ->orderBy('level', 'asc')
  5715. ->get(['name'])
  5716. ->pluck('name')
  5717. ->implode('');
  5718. // $job->address_name = $address ?? '';
  5719. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5720. }
  5721. if (empty($result)) {
  5722. return Result::error("招聘信息不存在", 0);
  5723. }
  5724. // return Result::success($job);
  5725. return Result::success($result);
  5726. }
  5727. /*
  5728. * 修改招聘信息
  5729. * */
  5730. public function upJobRecruiting(array $data): array
  5731. {
  5732. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5733. // return Result::success($job);
  5734. if (empty($job)) {
  5735. return Result::error("招聘信息不存在", 0);
  5736. }
  5737. $user = User::where('id', $data['user_id'])->first();
  5738. // return Result::success($user);
  5739. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5740. return Result::error("用户不存在", 0);
  5741. }
  5742. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5743. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5744. }
  5745. // 处理招聘关键词
  5746. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5747. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5748. } else {
  5749. Jieba::init(); // 初始化 jieba-php
  5750. Finalseg::init();
  5751. $segList = Jieba::cut($data['title']);
  5752. $segList1 = array_slice($segList, 0, 8);
  5753. $data['keyword'] = implode(',', $segList1);
  5754. }
  5755. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5756. $content = $data['description'];
  5757. // 去除 <style> 和 <script> 标签及其内容
  5758. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5759. // 去除所有 HTML 标签
  5760. $content = strip_tags($content);
  5761. // 去除 HTML 实体
  5762. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5763. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5764. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5765. // 去除多余空白
  5766. $content = preg_replace('/\s+/u', '', $content);
  5767. // 截取 100 个字符
  5768. $data['seo_description'] = mb_substr($content, 0, 100);
  5769. }
  5770. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5771. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5772. $data['catid'] = end($data['cat_arr_id']);
  5773. } else {
  5774. }
  5775. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5776. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5777. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5778. // 公司地址 管理员必填
  5779. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5780. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5781. // 管理员-企业相关信息
  5782. $company = [
  5783. // 'user_id' => $data['user_id']?? null,
  5784. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5785. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5786. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5787. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5788. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5789. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5790. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5791. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5792. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5793. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5794. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5795. ];
  5796. //去掉相关企业信息
  5797. $data = array_diff_key($data, array_flip(array_keys($company)));
  5798. $jobId = $data['id'];
  5799. $web = $data['website_id'];
  5800. $data['action_id'] = $data['user_id'];
  5801. unset($data['user_id']);
  5802. unset($data['user_type']);
  5803. unset($data['id']);
  5804. unset($data['website_id']);
  5805. // return Result::success($data);
  5806. Db::beginTransaction();
  5807. try {
  5808. // 管理员修改招聘信息
  5809. if ($user['type_id'] == 10000) {
  5810. $data['website_id'] = $web;
  5811. $company['website_id'] = $data['website_id'];
  5812. $data['status'] = 1;
  5813. } else {
  5814. $data['status'] = 0;
  5815. }
  5816. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5817. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5818. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5819. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5820. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5821. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5822. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5823. // return Result::success($job);
  5824. // Db::rollBack();
  5825. // return Result::success($company);
  5826. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5827. $this->sendMessage([
  5828. 'talk_type' => 500,
  5829. 'title' => $data['title'],
  5830. 'content' => '提交了审核',
  5831. 'messageType' => 10,
  5832. ]);
  5833. }
  5834. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5835. if (empty($result['job'])) {
  5836. Db::rollBack();
  5837. return Result::error("修改招聘信息失败");
  5838. }
  5839. // 管理员修改企业相关信息
  5840. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5841. if (empty($result['company'])) {
  5842. Db::rollBack();
  5843. return Result::error("修改企业相关信息失败");
  5844. }
  5845. Db::commit();
  5846. // return Result::success($result);
  5847. } catch (\Exception $e) {
  5848. Db::rollBack();
  5849. return Result::error($e->getMessage(), 0);
  5850. }
  5851. return Result::success($result);
  5852. }
  5853. /*
  5854. * 招聘信息删除
  5855. * */
  5856. public function delJobRecruiting(array $data): array
  5857. {
  5858. $user = User::where('id', $data['user_id'])->first();
  5859. if (empty($user)) {
  5860. return Result::error("用户不存在", 0);
  5861. }
  5862. $job = JobRecruiting::where('id', $data['id'])->first();
  5863. if (empty($job)) {
  5864. return Result::error("招聘信息不存在", 0);
  5865. }
  5866. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5867. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5868. }
  5869. Db::beginTransaction();
  5870. try {
  5871. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5872. if (empty($result['job'])) {
  5873. Db::rollBack();
  5874. return Result::error("删除招聘信息失败");
  5875. }
  5876. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5877. if (empty($result['company'])) {
  5878. Db::rollBack();
  5879. return Result::error("删除企业相关信息失败");
  5880. }
  5881. Db::commit();
  5882. } catch (\Exception $e) {
  5883. Db::rollBack();
  5884. return Result::error($e->getMessage(), 0);
  5885. }
  5886. return Result::success($result);
  5887. }
  5888. /*
  5889. * 获取公司信息
  5890. * */
  5891. public function getJobCompany(array $data): array
  5892. {
  5893. $user = User::where('user.id', $data['user_id'])
  5894. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5895. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5896. ->first();
  5897. // return Result::success($user);
  5898. if (empty($user)) {
  5899. return Result::error("用户不存在", 0);
  5900. }
  5901. if ($user['type_id'] == 3) {
  5902. $result = [
  5903. // 'id' => 0,
  5904. 'user_id' => $data['user_id'],
  5905. 'website_id' => $data['website_id'],
  5906. 'business_name' => $user['business_name'], // 企业名称
  5907. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5908. 'company_nature' => $user['company_nature'], // 公司性质
  5909. 'company_size' => $user['company_size'], // 公司规模
  5910. 'introduction' => $user['introduction'], // 公司简介
  5911. 'real_name' => $user['real_name'], // 企业联系人
  5912. 'mobile' => $user['mobile'], // 企业联系电话
  5913. 'company_url' => $user['company_url'], // 企业网址
  5914. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5915. 'address' => $user['address'], // 企业地址
  5916. 'email' => $user['email'], // 企业邮箱
  5917. ];
  5918. } else {
  5919. return Result::error("用户类型错误", 0);
  5920. }
  5921. if (empty($result)) {
  5922. return Result::error("公司信息不存在", 0);
  5923. }
  5924. return Result::success($result);
  5925. }
  5926. /*
  5927. * 修改公司信息
  5928. * */
  5929. public function upJobCompany(array $data): array
  5930. {
  5931. // return Result::success($data);
  5932. $user = User::where('user.id', $data['user_id'])
  5933. ->where('user.status', 1)
  5934. ->select('user.user_name', 'user.type_id')
  5935. ->first();
  5936. if (empty($user)) {
  5937. return Result::error("用户不存在", 0);
  5938. }
  5939. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5940. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5941. $company = [
  5942. 'business_name' => $data['business_name'], // 企业名称
  5943. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5944. 'company_nature' => $data['company_nature'], // 公司性质
  5945. 'company_size' => $data['company_size'], // 公司规模
  5946. 'introduction' => $data['introduction'], // 公司简介
  5947. // 'real_name' => $data['real_name'], // 企业联系人
  5948. 'company_url' => $data['company_url'], // 企业网址
  5949. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5950. 'address' => $data['address'], // 企业详细地址
  5951. // 'email' => $data['email'], // 企业邮箱
  5952. ];
  5953. if ($user['type_id'] == 3) {
  5954. Db::beginTransaction();
  5955. try {
  5956. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5957. 'business_name' => $data['business_name'], // 企业名称
  5958. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5959. 'company_nature' => $data['company_nature'], // 公司性质
  5960. 'company_size' => $data['company_size'], // 公司规模
  5961. 'introduction' => $data['introduction'], // 公司简介
  5962. // 'real_name' => $data['real_name'], // 企业联系人
  5963. 'company_url' => $data['company_url'], // 企业网址
  5964. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5965. 'address' => $data['address'], // 企业详细地址
  5966. ]);
  5967. if (empty($result['userinfo'])) {
  5968. Db::rollBack();
  5969. return Result::error('修改企业会员信息失败!');
  5970. }
  5971. $result['user'] = User::where('id', $data['user_id'])->update([
  5972. 'email' => $data['email'], // 企业邮箱
  5973. ]);
  5974. if (empty($result['user'])) {
  5975. Db::rollBack();
  5976. return Result::error('修改个人中心信息失败!');
  5977. }
  5978. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5979. if (!empty($job_company)) {
  5980. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5981. if (empty($result['job_company'])) {
  5982. Db::rollBack();
  5983. return Result::error('修改企业会员信息失败!');
  5984. }
  5985. }
  5986. Db::commit();
  5987. return Result::success($result);
  5988. } catch (\Exception $e) {
  5989. Db::rollBack();
  5990. return Result::error($e->getMessage(), 0);
  5991. }
  5992. } else {
  5993. return Result::error("用户类型错误", 0);
  5994. }
  5995. }
  5996. /*
  5997. * 获取省-市
  5998. * */
  5999. public function getJobRecruitingArea(array $data): array
  6000. {
  6001. if (isset($data['pid']) && $data['pid'] != null) {
  6002. $result = District::where('pid', $data['pid'])->get()->all();
  6003. } else {
  6004. $result = District::where('level', 1)->get()->all();
  6005. }
  6006. if (empty($result)) {
  6007. return Result::error("暂无此省市", 0);
  6008. }
  6009. return Result::success($result);
  6010. }
  6011. /*
  6012. * 获取行业分类
  6013. * */
  6014. public function getIndustry(array $data): array
  6015. {
  6016. $result = JobIndustry::get()->all();
  6017. if (empty($result)) {
  6018. return Result::error("暂无行业分类", 0);
  6019. }
  6020. return Result::success($result);
  6021. }
  6022. /*
  6023. * 获取职位
  6024. * */
  6025. public function getPositionList(array $data): array
  6026. {
  6027. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  6028. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  6029. } else {
  6030. $result = JobPosition::where('zwpid', 0)->get()->all();
  6031. }
  6032. if (empty($result)) {
  6033. return Result::error("暂无此职位", 0);
  6034. }
  6035. return Result::success($result);
  6036. }
  6037. /*
  6038. * 获取工作性质-菜单
  6039. * */
  6040. public function getJobNature(array $data): array
  6041. {
  6042. $result = JobEnum::where('egroup', 'nature')->get()->all();
  6043. if (empty($result)) {
  6044. return Result::error("暂无工作性质", 0);
  6045. }
  6046. return Result::success($result);
  6047. }
  6048. /*
  6049. * 获取工作经验-菜单
  6050. * */
  6051. public function getExperience(array $data): array
  6052. {
  6053. $result = JobEnum::where('egroup', 'years')->get()->all();
  6054. if (empty($result)) {
  6055. return Result::error("暂无工作经验", 0);
  6056. }
  6057. return Result::success($result);
  6058. }
  6059. /*
  6060. * 获取学历-菜单
  6061. * */
  6062. public function getEducation(array $data): array
  6063. {
  6064. $result = JobEnum::where('egroup', 'education')->get()->all();
  6065. if (empty($result)) {
  6066. return Result::error("暂无学历", 0);
  6067. }
  6068. return Result::success($result);
  6069. }
  6070. /*
  6071. * 获取薪资-菜单
  6072. * */
  6073. public function getSalary(array $data): array
  6074. {
  6075. $result = JobEnum::where('egroup', 'income')->get()->all();
  6076. if (empty($result)) {
  6077. return Result::error("暂无薪资", 0);
  6078. }
  6079. return Result::success($result);
  6080. }
  6081. /*
  6082. * 获取语言-菜单
  6083. * */
  6084. public function getLanguage(array $data): array
  6085. {
  6086. $result = JobEnum::where('egroup', 'language')->get()->all();
  6087. if (empty($result)) {
  6088. return Result::error("暂无语言", 0);
  6089. }
  6090. return Result::success($result);
  6091. }
  6092. /*
  6093. * 获取掌握程度-菜单
  6094. * */
  6095. public function getLevel(array $data): array
  6096. {
  6097. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  6098. if (empty($result)) {
  6099. return Result::error("暂无工作性质", 0);
  6100. }
  6101. return Result::success($result);
  6102. }
  6103. // 公司信息
  6104. /*
  6105. * 获取公司性质-菜单
  6106. * */
  6107. public function getCompanyNature(array $data): array
  6108. {
  6109. $result = JobNature::get()->all();
  6110. if (empty($result)) {
  6111. return Result::error("暂无公司性质", 0);
  6112. }
  6113. return Result::success($result);
  6114. }
  6115. /*
  6116. * 获取公司规模-菜单
  6117. * */
  6118. public function getCompanySize(array $data): array
  6119. {
  6120. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  6121. if (empty($result)) {
  6122. return Result::error("暂无公司规模", 0);
  6123. }
  6124. return Result::success($result);
  6125. }
  6126. /*
  6127. * 招聘信息审核
  6128. * */
  6129. public function checkJobRecruiting(array $data): array
  6130. {
  6131. $user = User::where('id', $data['user_id'])->first();
  6132. if (empty($user)) {
  6133. return Result::error("用户不存在", 0);
  6134. }
  6135. $job = JobRecruiting::where('id', $data['id'])->first();
  6136. if (empty($job)) {
  6137. return Result::error("招聘信息不存在", 0);
  6138. }
  6139. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  6140. if ($user['type_id'] != 10000) {
  6141. return Result::error("用户暂无权限审核此招聘信息!", 0);
  6142. }
  6143. // 驳回原因
  6144. if ($data['status'] == 2) {
  6145. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  6146. }
  6147. $data['action_id'] = $data['user_id'];
  6148. unset($data['user_id']);
  6149. if ($data['status'] == 1) {
  6150. $this->sendMessage([
  6151. 'talk_type' => 501,
  6152. 'title' => $job['title'],
  6153. 'content' => '审核通过',
  6154. 'messageType' => 10,
  6155. 'user_id' => $job['user_id'],
  6156. ]);
  6157. }
  6158. if ($data['status'] == 2) {
  6159. $this->sendMessage([
  6160. 'talk_type' => 501,
  6161. 'title' => $job['title'],
  6162. 'content' => '审核拒绝',
  6163. 'messageType' => 10,
  6164. 'user_id' => $job['user_id'],
  6165. ]);
  6166. }
  6167. if ($data['status'] == 0) {
  6168. $this->sendMessage([
  6169. 'talk_type' => 500,
  6170. 'title' => $job['title'],
  6171. 'content' => '提交了审核',
  6172. 'messageType' => 10,
  6173. ]);
  6174. }
  6175. $result = JobRecruiting::where('id', $data['id'])->update($data);
  6176. if (empty($result)) {
  6177. return Result::error("审核失败", 0);
  6178. }
  6179. return Result::success($result);
  6180. }
  6181. public function myApplyList(array $data): array
  6182. {
  6183. var_dump($data, '------参数');
  6184. $user = User::where('id', $data['user_id'])->first();
  6185. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6186. return Result::error("用户不存在", 0);
  6187. }
  6188. // 1:个人会员 职场机会
  6189. if ($user['type_id'] == 1) {
  6190. $where['user_id'] = $user['id'];
  6191. }
  6192. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  6193. $query->where('user_id', $user['id']);
  6194. })
  6195. ->pluck('recruit_id');
  6196. $where = [];
  6197. if (isset($data['salary']) && $data['salary'] != null) {
  6198. $where['job_recruiting.salary'] = $data['salary'];
  6199. }
  6200. if (isset($data['experience']) && $data['experience'] != null) {
  6201. $where['job_recruiting.experience'] = $data['experience'];
  6202. }
  6203. if (isset($data['business_name']) && $data['business_name'] != null) {
  6204. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6205. }
  6206. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6207. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6208. ->where($where);
  6209. // ->count();
  6210. $count = $query->count();
  6211. $query = clone $query;
  6212. $job = $query
  6213. ->leftJoin('job_enum as income_enum', function ($join) {
  6214. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6215. ->where('income_enum.egroup', 'income');
  6216. })
  6217. ->leftJoin('job_enum as years_enum', function ($join) {
  6218. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6219. ->where('years_enum.egroup', 'years');
  6220. })
  6221. // ->where($where)
  6222. ->orderBy('job_recruiting.updated_at', 'desc')
  6223. ->select(
  6224. 'job_recruiting.id',
  6225. 'job_recruiting.title',
  6226. 'job_company.business_name',
  6227. 'income_enum.evalue as salary_evalue',
  6228. 'income_enum.ename as salary_ename',
  6229. 'years_enum.evalue as experience_evalue',
  6230. 'years_enum.ename as experience_ename',
  6231. 'job_recruiting.updated_at'
  6232. )
  6233. ->offset(($data['page'] - 1) * $data['pageSize'])
  6234. ->limit($data['pageSize'])
  6235. ->get()
  6236. ->all();
  6237. if (empty($job)) {
  6238. return Result::error("暂无招聘信息", 0);
  6239. }
  6240. $result = [
  6241. 'row' => $job,
  6242. 'count' => $count,
  6243. ];
  6244. return Result::success($result);
  6245. }
  6246. public function readJobApply(array $data): array
  6247. {
  6248. $result = JobApply::where('id', $data['id'])->first();
  6249. if (empty($result)) {
  6250. return Result::error("查询失败", 0);
  6251. }
  6252. $result = JobApply::where('id', $data['id'])->update([
  6253. 'status' => 2,
  6254. ]);
  6255. return Result::success($result);
  6256. }
  6257. /*
  6258. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  6259. * */
  6260. public function getRecruitingList(array $data): array
  6261. {
  6262. $user = User::where('id', $data['user_id'])->first();
  6263. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6264. return Result::error("用户不存在", 0);
  6265. }
  6266. // 1:个人会员 职场机会
  6267. if ($user['type_id'] == 1) {
  6268. $where['user_id'] = $user['id'];
  6269. }
  6270. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  6271. $query->where('receiver_id', $user['id']);
  6272. })
  6273. ->pluck('recruit_id');
  6274. // return Result::success($recruitingId);
  6275. $where = [];
  6276. if (isset($data['salary']) && $data['salary'] != null) {
  6277. $where['job_recruiting.salary'] = $data['salary'];
  6278. }
  6279. if (isset($data['experience']) && $data['experience'] != null) {
  6280. $where['job_recruiting.experience'] = $data['experience'];
  6281. }
  6282. if (isset($data['business_name']) && $data['business_name'] != null) {
  6283. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6284. }
  6285. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6286. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6287. ->where($where);
  6288. // ->count();
  6289. $count = $query->count();
  6290. $query = clone $query;
  6291. $job = $query
  6292. ->leftJoin('job_enum as income_enum', function ($join) {
  6293. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6294. ->where('income_enum.egroup', 'income');
  6295. })
  6296. ->leftJoin('job_enum as years_enum', function ($join) {
  6297. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6298. ->where('years_enum.egroup', 'years');
  6299. })
  6300. // ->where($where)
  6301. ->orderBy('job_recruiting.updated_at', 'desc')
  6302. ->select(
  6303. 'job_recruiting.id',
  6304. 'job_recruiting.title',
  6305. 'job_company.business_name',
  6306. 'income_enum.evalue as salary_evalue',
  6307. 'income_enum.ename as salary_ename',
  6308. 'years_enum.evalue as experience_evalue',
  6309. 'years_enum.ename as experience_ename',
  6310. 'job_recruiting.updated_at'
  6311. )
  6312. ->offset(($data['page'] - 1) * $data['pageSize'])
  6313. ->limit($data['pageSize'])
  6314. ->get()
  6315. ->all();
  6316. if (empty($job)) {
  6317. return Result::error("暂无招聘信息", 0);
  6318. }
  6319. $result = [
  6320. 'row' => $job,
  6321. 'count' => $count,
  6322. ];
  6323. return Result::success($result);
  6324. }
  6325. /*
  6326. * 获取企业会员-招聘信息列表
  6327. * */
  6328. public function getRecruitingInfo(array $data): array
  6329. {
  6330. $user = User::where('id', $data['user_id'])->first();
  6331. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6332. return Result::error("用户不存在", 0);
  6333. }
  6334. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  6335. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6336. ->select(
  6337. 'job_recruiting.*',
  6338. 'job_company.business_name',
  6339. 'job_company.company_hy_id',
  6340. 'job_company.company_size',
  6341. 'job_company.company_nature',
  6342. 'job_company.introduction',
  6343. 'job_company.real_name',
  6344. 'job_company.mobile',
  6345. 'job_company.company_url',
  6346. 'job_company.address_arr_id',
  6347. 'job_company.address',
  6348. 'job_company.email'
  6349. )
  6350. ->get();
  6351. if (empty($recruiting)) {
  6352. return Result::error("暂无招聘信息", 0);
  6353. }
  6354. return Result::success($recruiting);
  6355. }
  6356. /*
  6357. * 获取企业会员-我的沟通
  6358. * */
  6359. public function getJobResumeList(array $data): array
  6360. {
  6361. $user = User::where('id', $data['user_id'])->first();
  6362. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  6363. return Result::error("用户不存在", 0);
  6364. }
  6365. $where = [];
  6366. if (isset($data['salary']) && $data['salary'] != null) {
  6367. $where['job_hunting.salary'] = $data['salary'];
  6368. }
  6369. if (isset($data['user_name']) && $data['user_name'] != null) {
  6370. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  6371. }
  6372. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  6373. $query->where('job_resume.user_id', $user['id']);
  6374. })
  6375. ->when(!empty($where), function ($query) use ($where) {
  6376. $query->where($where);
  6377. })
  6378. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  6379. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  6380. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  6381. ->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');
  6382. $count = $job->count();
  6383. if ($count == 0) {
  6384. return Result::error("暂无沟通记录", 0);
  6385. }
  6386. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  6387. ->offset(($data['page'] - 1) * $data['pageSize'])
  6388. ->limit($data['pageSize'])
  6389. ->get();
  6390. if (empty($jobs)) {
  6391. return Result::error("暂无沟通记录", 0);
  6392. }
  6393. $result['row'] = $this->processJob($jobs, '');
  6394. $result['count'] = $count;
  6395. return Result::success($result);
  6396. }
  6397. public function readJobResume(array $data): array
  6398. {
  6399. $result = JobResume::where('id', $data['id'])->first();
  6400. if (empty($result)) {
  6401. return Result::error("查询失败", 0);
  6402. }
  6403. $result = JobResume::where('id', $data['id'])->update([
  6404. 'status' => 2,
  6405. ]);
  6406. return Result::success($result);
  6407. }
  6408. // 20250306 招聘
  6409. //20250422 书刊音像
  6410. public function addBook(array $data): array
  6411. {
  6412. $user_id = $data['user_id'] ?? 0;
  6413. $type_id = $data['type_id'] ?? 0;
  6414. // $website_id = $data['website_id'] ?? 0;
  6415. // unset($data['user_id']);
  6416. unset($data['type_id']);
  6417. // unset($data['website_id']);
  6418. //处理数组
  6419. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6420. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6421. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6422. if ($data['img_url'] == '') {
  6423. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6424. preg_match_all($reg, $data['detail'], $matches);
  6425. if (isset($matches[1][0])) {
  6426. //截取varchar240
  6427. $data['img_url'] = substr($matches[1][0], 0, 240);
  6428. }
  6429. }
  6430. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  6431. //提取标题+内容中的关键词
  6432. $data['keyword'] = $data['title'];
  6433. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6434. Jieba::init(); // 初始化 jieba-php
  6435. Finalseg::init();
  6436. $segList = Jieba::cut($data['keyword']);
  6437. $segList1 = array_slice($segList, 0, 8);
  6438. $data['keyword'] = implode(',', $segList1);
  6439. }
  6440. if ($data['description'] == '') {
  6441. //提取内容中的描述
  6442. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6443. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6444. }
  6445. var_dump($data, '--');
  6446. if ($data['status'] == 1) {
  6447. $this->sendMessage([
  6448. 'talk_type' => 400,
  6449. 'title' => $data['title'],
  6450. 'content' => '提交了审核',
  6451. 'messageType' => 7,
  6452. ]);
  6453. }
  6454. $result = Book::insertGetId($data);
  6455. if (empty($result)) {
  6456. return Result::error("添加失败", 0);
  6457. }
  6458. return Result::success($result);
  6459. }
  6460. public function getBookList(array $data): array
  6461. {
  6462. $where = [];
  6463. if (!empty($data["title"])) {
  6464. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  6465. }
  6466. if (!empty($data['website_name'])) {
  6467. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  6468. }
  6469. if (!empty($data['status'])) {
  6470. $where[] = ['book.status', '=', $data['status']];
  6471. }
  6472. $user_id = $data['user_id'];
  6473. $type_id = $data['type_id'];
  6474. // $type_id = 4;
  6475. var_dump($type_id, '------1--------');
  6476. if ($type_id != 10000) {
  6477. $where[] = ['book.user_id', '=', $user_id];
  6478. }
  6479. var_dump(!empty($data['status1']), '=-===1');
  6480. $result = Book::where($where)
  6481. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  6482. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  6483. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  6484. ->when(isset($data['status1']), function ($query) use ($data) {
  6485. $query->whereIn('book.status', [1, 3]);
  6486. })
  6487. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  6488. ->orderBy("updated_at", "desc")
  6489. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  6490. if (empty($result)) {
  6491. return Result::error("暂无数据", 0);
  6492. }
  6493. // 取出数据
  6494. $rows = $result->items();
  6495. $count = $result->total();
  6496. $responseData = [
  6497. 'rows' => $rows,
  6498. 'count' => $count,
  6499. ];
  6500. return Result::success($responseData);
  6501. }
  6502. public function deleteBook(array $data): array
  6503. {
  6504. $result = Book::where('id', $data['id'])->delete();
  6505. if (empty($result)) {
  6506. return Result::error("删除失败", 0);
  6507. }
  6508. return Result::success($result);
  6509. }
  6510. public function updateBook(array $data): array
  6511. {
  6512. // $user_id = $data['user_id'] ?? 0;
  6513. $type_id = $data['type_id'] ?? 0;
  6514. // $website_id = $data['website_id'] ?? 0;
  6515. unset($data['user_id']);
  6516. unset($data['type_id']);
  6517. // unset($data['website_id']);
  6518. //处理数组
  6519. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6520. if ($data['img_url'] == '') {
  6521. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6522. preg_match_all($reg, $data['detail'], $matches);
  6523. if (isset($matches[1][0])) {
  6524. //截取varchar240
  6525. $data['img_url'] = substr($matches[1][0], 0, 240);
  6526. }
  6527. }
  6528. if ($data['keyword'] == '') {
  6529. //提取标题+内容中的关键词
  6530. $data['keyword'] = $data['title'];
  6531. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6532. Jieba::init(); // 初始化 jieba-php
  6533. Finalseg::init();
  6534. $segList = Jieba::cut($data['keyword']);
  6535. $segList1 = array_slice($segList, 0, 8);
  6536. $data['keyword'] = implode(',', $segList1);
  6537. }
  6538. if ($data['description'] == '') {
  6539. //提取内容中的描述
  6540. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6541. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6542. }
  6543. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6544. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6545. if ($data['status'] == 1) {
  6546. $this->sendMessage([
  6547. 'talk_type' => 400,
  6548. 'title' => $data['title'],
  6549. 'content' => '提交了审核',
  6550. 'messageType' => 7,
  6551. ]);
  6552. }
  6553. $result = Book::where("id", $data["id"])->update($data);
  6554. if (empty($result)) {
  6555. return Result::error("更新失败", 0);
  6556. }
  6557. return Result::success($result);
  6558. }
  6559. public function getBookInfo(array $data): array
  6560. {
  6561. $result = Book::where("id", $data["id"])->first();
  6562. if (empty($result)) {
  6563. return Result::error("获取失败", 0);
  6564. }
  6565. return Result::success($result);
  6566. }
  6567. public function updateBookStatus(array $data): array
  6568. {
  6569. //审核
  6570. unset($data['user_id']);
  6571. $bookInfo = Book::where("id", $data["id"])->first();
  6572. var_dump($bookInfo, '----');
  6573. if ($data['status'] == 2) {
  6574. $this->sendMessage([
  6575. 'talk_type' => 401,
  6576. 'title' => $bookInfo['title'],
  6577. 'content' => '审核通过',
  6578. 'messageType' => 7,
  6579. 'user_id' => $bookInfo['user_id'],
  6580. ]);
  6581. }
  6582. if ($data['status'] == 3) {
  6583. $this->sendMessage([
  6584. 'talk_type' => 401,
  6585. 'title' => $bookInfo['title'],
  6586. 'content' => '审核拒绝',
  6587. 'messageType' => 7,
  6588. 'user_id' => $bookInfo['user_id'],
  6589. ]);
  6590. }
  6591. if ($data['status'] == 1) {
  6592. $this->sendMessage([
  6593. 'talk_type' => 400,
  6594. 'title' => $bookInfo['title'],
  6595. 'content' => '提交了审核',
  6596. 'messageType' => 7,
  6597. // 'user_id'=>$bookInfo['user_id'],
  6598. ]);
  6599. }
  6600. $result = Book::where("id", $data["id"])->update($data);
  6601. if (empty($result)) {
  6602. return Result::error("更新失败", 0);
  6603. }
  6604. return Result::success($result);
  6605. }
  6606. //20250422 书刊音像
  6607. /**
  6608. * 贴身宝贝
  6609. * @param array $data
  6610. * @return array
  6611. */
  6612. public function getWebsiteTsbb(array $data): array
  6613. {
  6614. $month = $data['month'] ?? date('m');
  6615. $day = $data['day'] ?? date('d');
  6616. // 使用缓存键
  6617. $cacheKey = "tsbb_data_{$month}_{$day}";
  6618. // 尝试从缓存获取数据
  6619. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6620. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6621. if ($cachedData = $cache->get($cacheKey)) {
  6622. return Result::success(unserialize($cachedData));
  6623. }
  6624. //查询老黄历
  6625. try {
  6626. $date = date('Y-m-d');
  6627. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6628. // 使用 curl 替代 file_get_contents
  6629. $ch = curl_init();
  6630. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6631. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6632. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6633. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6634. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6635. 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');
  6636. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6637. 'Accept: application/json',
  6638. 'Content-Type: application/json',
  6639. 'Referer: https://www.36jxs.com/'
  6640. ]);
  6641. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6642. curl_setopt($ch, CURLOPT_ENCODING, '');
  6643. $almanacResponse = curl_exec($ch);
  6644. var_dump("====:", $almanacResponse);
  6645. if (curl_errno($ch)) {
  6646. var_dump('Curl error:', curl_error($ch));
  6647. throw new \Exception('Curl error: ' . curl_error($ch));
  6648. }
  6649. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6650. curl_close($ch);
  6651. if ($almanacResponse === false) {
  6652. throw new \Exception('Failed to fetch almanac data');
  6653. }
  6654. $almanacData = json_decode($almanacResponse, true);
  6655. if (json_last_error() !== JSON_ERROR_NONE) {
  6656. throw new \Exception('Failed to parse almanac data');
  6657. }
  6658. $almanacInfo = $almanacData['data'] ?? [];
  6659. } catch (\Exception $e) {
  6660. var_dump('Exception:', $e->getMessage());
  6661. $almanacInfo = [];
  6662. }
  6663. // 获取历史上的今天数据
  6664. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6665. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6666. ->orderBy('year', 'asc')
  6667. ->select("title", "id", "year", DB::raw('1 as type'))
  6668. ->limit(16)
  6669. ->get();
  6670. // 获取节日数据 - 从今天开始获取未来4条
  6671. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6672. ->orderBy('showtime', 'asc')
  6673. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6674. ->limit(16)
  6675. ->get();
  6676. //说文解字
  6677. $chartacterList = Character::orderBy('updated_at', 'desc')
  6678. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6679. ->limit(6)
  6680. ->get();
  6681. //谜语沙龙
  6682. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6683. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6684. ->limit(4)
  6685. ->get();
  6686. //成语欣赏
  6687. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6688. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6689. ->limit(32)
  6690. ->get();
  6691. //名联赏析
  6692. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6693. ->select("id", "first", "second", DB::raw('6 as type'))
  6694. ->limit(6)
  6695. ->get();
  6696. // 获取分类文章数据
  6697. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6698. ->pluck('category_id')
  6699. ->toArray();
  6700. $articlesList = [];
  6701. foreach ($categoryIds as $catid) {
  6702. // 先查有图片的
  6703. $withImg = DB::table('article')
  6704. ->where('status', 1)
  6705. ->where('catid', $catid)
  6706. ->whereNotNull('imgurl')
  6707. ->where('imgurl', '!=', '')
  6708. ->orderBy('updated_at', 'desc')
  6709. ->limit(6)
  6710. ->get();
  6711. $count = $withImg->count();
  6712. if ($count < 6) {
  6713. // 不足6条再查无图片的补足
  6714. $withoutImg = DB::table('article')
  6715. ->where('status', 1)
  6716. ->where('catid', $catid)
  6717. ->where(function ($q) {
  6718. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6719. })
  6720. ->orderBy('updated_at', 'desc')
  6721. ->limit(6 - $count)
  6722. ->get();
  6723. $articles = $withImg->concat($withoutImg);
  6724. } else {
  6725. $articles = $withImg;
  6726. }
  6727. // 组装
  6728. $category = \App\Model\Category::find($catid);
  6729. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6730. $articlesList[] = [
  6731. 'category_name' => $category ? $category->name : '',
  6732. 'catid' => $catid,
  6733. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6734. 'type' => 100,
  6735. 'list' => $articles->map(function ($item) {
  6736. return [
  6737. 'id' => $item->id,
  6738. 'title' => $item->title,
  6739. 'imgurl' => $item->imgurl,
  6740. 'created_at' => $item->created_at
  6741. ];
  6742. })->values()
  6743. ];
  6744. }
  6745. $result = [
  6746. 'almanac' => $almanacInfo,
  6747. 'historyTodayList' => [
  6748. 'category_name' => '历史上的今天',
  6749. 'list' => $historyTodayList,
  6750. 'type' => 1
  6751. ],
  6752. 'festivalList' => [
  6753. 'category_name' => '节日预告',
  6754. 'list' => $festivalList,
  6755. 'type' => 2
  6756. ],
  6757. 'chartacterList' => [
  6758. 'category_name' => '说文解字',
  6759. 'list' => $chartacterList,
  6760. 'type' => 3
  6761. ],
  6762. 'coupletList' => [
  6763. 'category_name' => '名联赏析',
  6764. 'list' => $coupletList,
  6765. 'type' => 6
  6766. ],
  6767. 'riddletList' => [
  6768. 'category_name' => '谜语沙龙',
  6769. 'list' => $riddletList,
  6770. 'type' => 4
  6771. ],
  6772. 'idiomList' => [
  6773. 'category_name' => '成语欣赏',
  6774. 'list' => $idiomList,
  6775. 'type' => 5
  6776. ],
  6777. 'articlesList' => $articlesList
  6778. ];
  6779. // 缓存结果,设置1小时过期
  6780. $cache->set($cacheKey, serialize($result), 3600);
  6781. return Result::success($result);
  6782. }
  6783. /**
  6784. * 获取资讯列表
  6785. */
  6786. public function getWebsiteTsbbList(array $data): array
  6787. {
  6788. $page = $data['page'] ?? 1;
  6789. $pageSize = $data['pageSize'] ?? 10;
  6790. // 如果没有传入月份和日期,则使用今天的日期
  6791. $month = $data['month'] ?? date('m');
  6792. $day = $data['day'] ?? date('d');
  6793. $total = 0;
  6794. $result = [];
  6795. $data['type'] = intval($data['type']);
  6796. var_dump("接收参数:", $data);
  6797. switch ($data['type']) {
  6798. case 1:
  6799. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6800. // 当前月份之后的数据
  6801. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6802. // 或者当前月份且日期大于等于当前日期的数据
  6803. ->orWhere(function ($q) use ($month, $day) {
  6804. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6805. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6806. });
  6807. })
  6808. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6809. $total = $query->count();
  6810. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6811. ->offset(($page - 1) * $pageSize)
  6812. ->limit($pageSize)
  6813. ->get();
  6814. break;
  6815. case 2:
  6816. $query = Festival::where(function ($q) use ($month, $day) {
  6817. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6818. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6819. ->orWhere(function ($q) use ($month, $day) {
  6820. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6821. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6822. });
  6823. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6824. $total = $query->count();
  6825. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6826. ->offset(($page - 1) * $pageSize)
  6827. ->limit($pageSize)
  6828. ->get();
  6829. break;
  6830. case 3:
  6831. $query = Character::orderBy("updated_at", "desc");
  6832. $total = $query->count();
  6833. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6834. ->offset(($page - 1) * $pageSize)
  6835. ->limit($pageSize)
  6836. ->get();
  6837. break;
  6838. case 4:
  6839. $query = Riddle::orderBy("updated_at", "desc");
  6840. $total = $query->count();
  6841. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6842. ->offset(($page - 1) * $pageSize)
  6843. ->limit($pageSize)
  6844. ->get();
  6845. break;
  6846. case 5:
  6847. $query = Idiom::orderBy("updated_at", "desc");
  6848. $total = $query->count();
  6849. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6850. ->offset(($page - 1) * $pageSize)
  6851. ->limit($pageSize)
  6852. ->get();
  6853. break;
  6854. case 6:
  6855. $query = Couplet::orderBy("updated_at", "desc");
  6856. $total = $query->count();
  6857. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6858. ->offset(($page - 1) * $pageSize)
  6859. ->limit($pageSize)
  6860. ->get();
  6861. break;
  6862. default:
  6863. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6864. $total = $query->count();
  6865. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6866. ->offset(($page - 1) * $pageSize)
  6867. ->limit($pageSize)
  6868. ->get();
  6869. }
  6870. return Result::success([
  6871. 'list' => $result,
  6872. 'total' => $total,
  6873. 'page' => (int)$page,
  6874. 'pageSize' => (int)$pageSize,
  6875. 'month' => $month,
  6876. 'day' => $day
  6877. ]);
  6878. }
  6879. /**
  6880. * 1:历史上的今天
  6881. * 2:节日
  6882. * 3:文章
  6883. *
  6884. * 资讯详情信息
  6885. */
  6886. public function getWebsiteTsbbDetail(array $data): array
  6887. {
  6888. $data['type'] = intval($data['type']);
  6889. switch ($data['type']) {
  6890. case 1:
  6891. $result = HistoryToday::where("id", $data['id'])->first();
  6892. break;
  6893. case 2:
  6894. $result = Festival::where("id", $data['id'])->first();
  6895. break;
  6896. case 3:
  6897. $result = Character::where("id", $data['id'])->first();
  6898. break;
  6899. case 4:
  6900. $result = Riddle::where("id", $data['id'])->first();
  6901. break;
  6902. case 5:
  6903. $result = Idiom::where("id", $data['id'])->first();
  6904. break;
  6905. case 6:
  6906. $result = Couplet::where("id", $data['id'])->first();
  6907. break;
  6908. default:
  6909. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6910. break;
  6911. }
  6912. return Result::success($result);
  6913. }
  6914. /**
  6915. * 农网导航首页数据
  6916. */
  6917. public function getWebsiteNwHomeList(array $data): array
  6918. {
  6919. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6920. ->pluck('category_id')
  6921. ->toArray();
  6922. // 使用子查询优化
  6923. $articlesList = DB::table('article')
  6924. ->select([
  6925. 'article.id',
  6926. 'article.title',
  6927. 'article.imgurl',
  6928. 'article.created_at',
  6929. 'category.name as category_name',
  6930. 'category.id as category_id',
  6931. 'website_category.aLIas_pinyin as pinyin',
  6932. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6933. DB::raw('100 as type')
  6934. ])
  6935. ->join('category', 'article.catid', '=', 'category.id')
  6936. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6937. ->leftJoin('website_category as parent_wc', function ($join) {
  6938. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6939. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6940. })
  6941. ->where('website_category.website_id', $data['website_id'])
  6942. ->where('article.status', 1)
  6943. ->whereIn('category.id', $categoryIds)
  6944. ->orderBy('article.created_at', 'desc')
  6945. ->get()
  6946. ->groupBy('category_id')
  6947. ->map(function ($group) {
  6948. // 确保第一条数据有图片
  6949. $firstWithImage = $group->first(function ($item) {
  6950. return !empty($item->imgurl);
  6951. });
  6952. if ($firstWithImage) {
  6953. // 如果有带图片的文章,将其放在第一位
  6954. $group = $group->filter(function ($item) use ($firstWithImage) {
  6955. return $item->id !== $firstWithImage->id;
  6956. })->prepend($firstWithImage);
  6957. }
  6958. return [
  6959. 'category_name' => $group->first()->category_name,
  6960. 'catid' => $group->first()->category_id,
  6961. 'pinyin' => $group->first()->pinyin,
  6962. 'parent_pinyin' => $group->first()->parent_pinyin,
  6963. 'list' => $group->take(4)->map(function ($item) {
  6964. return [
  6965. 'id' => $item->id,
  6966. 'title' => $item->title,
  6967. ];
  6968. })->values()
  6969. ];
  6970. })
  6971. ->values()
  6972. ->toArray();
  6973. return Result::success($articlesList);
  6974. }
  6975. /**
  6976. * 企业管理
  6977. * @param array $data
  6978. * @return array
  6979. */
  6980. public function getCompanyList(array $data): array
  6981. {
  6982. // return Result::success($data);
  6983. $where = [];
  6984. $user = User::where('id', $data['user_id'])->first();
  6985. if (empty($user)) {
  6986. return Result::error('用户不存在!');
  6987. }
  6988. if ($user['type_id'] != 10000) {
  6989. $where['user_id'] = $data['user_id'];
  6990. }
  6991. if (isset($data['title']) && !empty($data['title'])) {
  6992. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6993. }
  6994. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6995. array_push($where, ['website.id', $data['website_id']]);
  6996. }
  6997. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6998. if ($data['ischeck'] == 1) {
  6999. if (isset($data['status']) && $data['status'] != '') {
  7000. array_push($where, ['company.status', $data['status']]);
  7001. $query = Company::where($where);
  7002. } else {
  7003. $query = Company::whereIn('company.status', [0, 2]);
  7004. }
  7005. } else {
  7006. $query = Company::where('company.status', 1);
  7007. }
  7008. }
  7009. $result = $query->where($where)
  7010. ->leftJoin('website_category', function ($query) {
  7011. $query->on('website_category.category_id', '=', 'company.category_id')
  7012. ->on('website_category.website_id', '=', 'company.website_id');
  7013. })
  7014. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  7015. ->select(
  7016. 'company.id',
  7017. 'company.title',
  7018. 'company.website_id',
  7019. 'company.category_id',
  7020. 'website.website_name',
  7021. 'website_category.alias as category_name',
  7022. 'company.status',
  7023. 'company.updated_at',
  7024. 'company.user_id'
  7025. )
  7026. ->orderBy('company.updated_at', 'desc')
  7027. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7028. if ($result->isEmpty()) {
  7029. return Result::error("暂无企业", 0);
  7030. }
  7031. return Result::success($result);
  7032. }
  7033. /**
  7034. * 添加企业
  7035. * @param array $data
  7036. * @return array
  7037. */
  7038. public function addCompany(array $data): array
  7039. {
  7040. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  7041. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  7042. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  7043. $data['cat_arr_id'] = json_encode($car_arr_id);
  7044. } else {
  7045. $data['cat_arr_id'] = '';
  7046. }
  7047. if ($data['imgurl'] == '') {
  7048. //content中提取图片第一个图,正则提取
  7049. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7050. preg_match_all($reg, $data['content'], $matches);
  7051. if (isset($matches[1][0])) {
  7052. //截取varchar240
  7053. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7054. }
  7055. }
  7056. if ($data['keyword'] == '') {
  7057. //提取标题+内容中的关键词
  7058. $data['keyword'] = $data['title'];
  7059. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7060. Jieba::init(); // 初始化 jieba-php
  7061. Finalseg::init();
  7062. $segList = Jieba::cut($data['keyword']);
  7063. $segList1 = array_slice($segList, 0, 8);
  7064. $data['keyword'] = implode(',', $segList1);
  7065. }
  7066. if ($data['introduce'] == '' || empty($data['introduce'])) {
  7067. //提取内容中的描述
  7068. $content = $data['content'];
  7069. // 去除 <style> 和 <script> 标签及其内容
  7070. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7071. // 去除所有 HTML 标签
  7072. $content = strip_tags($content);
  7073. // 去除 HTML 实体
  7074. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7075. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7076. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7077. // 去除多余空白
  7078. $content = preg_replace('/\s+/u', '', $content);
  7079. // 截取 100 个字符
  7080. $data['introduce'] = mb_substr($content, 0, 100);
  7081. }
  7082. $user = User::where('id', $data['user_id'])->first();
  7083. if (empty($user)) {
  7084. return Result::error('用户不存在!');
  7085. }
  7086. if ($user['type_id'] == 10000) {
  7087. $data['status'] = 1;
  7088. }
  7089. if (isset($data['level']) && $data['level'] != null) {
  7090. $data['level'] = intval($data['level']);
  7091. } else {
  7092. $data['level'] = null;
  7093. }
  7094. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7095. $this->sendMessage([
  7096. 'talk_type' => 900,
  7097. 'title' => $data['title'],
  7098. 'content' => '提交了审核',
  7099. 'messageType' => 8,
  7100. ]);
  7101. }
  7102. $result = Company::insertGetId($data);
  7103. if ($result) {
  7104. return Result::success($result);
  7105. } else {
  7106. return Result::error('添加失败');
  7107. }
  7108. }
  7109. /**
  7110. * 更新企业
  7111. * @param array $data
  7112. * @return array
  7113. */
  7114. public function upCompany(array $data): array
  7115. {
  7116. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  7117. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  7118. $data['cat_arr_id'] = json_encode($car_arr_id);
  7119. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  7120. } else {
  7121. $data['cat_arr_id'] = '';
  7122. }
  7123. if ($data['imgurl'] == '') {
  7124. //content中提取图片第一个图,正则提取
  7125. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7126. preg_match_all($reg, $data['content'], $matches);
  7127. if (isset($matches[1][0])) {
  7128. //截取varchar
  7129. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7130. }
  7131. }
  7132. if ($data['keyword'] == '') {
  7133. //提取标题+内容中的关键词
  7134. $data['keyword'] = $data['title'];
  7135. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7136. Jieba::init(); // 初始化 jieba-php
  7137. Finalseg::init();
  7138. $segList = Jieba::cut($data['keyword']);
  7139. $segList1 = array_slice($segList, 0, 8);
  7140. $data['keyword'] = implode(',', $segList1);
  7141. }
  7142. if ($data['introduce'] == '') {
  7143. //提取内容中的描述
  7144. $content = $data['content'];
  7145. // 去除 <style> 和 <script> 标签及其内容
  7146. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7147. // 去除所有 HTML 标签
  7148. $content = strip_tags($content);
  7149. // 去除 HTML 实体
  7150. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7151. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7152. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7153. // 去除多余空白
  7154. $content = preg_replace('/\s+/u', '', $content);
  7155. // 截取 100 个字符
  7156. $data['introduce'] = mb_substr($content, 0, 100);
  7157. }
  7158. if (isset($data['level']) && $data['level'] != null) {
  7159. $data['level'] = intval($data['level']);
  7160. } else {
  7161. $data['level'] = null;
  7162. }
  7163. $user = User::where('id', $data['user_id'])->first();
  7164. if (empty($user)) {
  7165. return Result::error('用户不存在!');
  7166. }
  7167. if ($user['type_id'] == 10000) {
  7168. $data['status'] = 1;
  7169. } else {
  7170. $data['status'] = 0;
  7171. }
  7172. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7173. $this->sendMessage([
  7174. 'talk_type' => 900,
  7175. 'title' => $data['title'],
  7176. 'content' => '提交了审核',
  7177. 'messageType' => 8,
  7178. ]);
  7179. }
  7180. $result = Company::where('id', $data['id'])->update($data);
  7181. if ($result) {
  7182. return Result::success($result);
  7183. } else {
  7184. return Result::error('修改失败');
  7185. }
  7186. }
  7187. /**
  7188. * 删除企业
  7189. * @param array $data
  7190. * @return array
  7191. */
  7192. public function delCompany(array $data): array
  7193. {
  7194. $result = Company::where('id', $data['id'])->delete();
  7195. if ($result) {
  7196. return Result::success($result);
  7197. } else {
  7198. return Result::error('删除失败');
  7199. }
  7200. }
  7201. /**
  7202. * 审核企业
  7203. * @param array $data
  7204. * @return array
  7205. */
  7206. public function checkCompany(array $data): array
  7207. {
  7208. $user = User::where('id', $data['user_id'])->first();
  7209. if (empty($user)) {
  7210. return Result::error('用户不存在!');
  7211. }
  7212. $company = Company::where('id', $data['id'])->first();
  7213. if (empty($company)) {
  7214. return Result::error('企业不存在!');
  7215. }
  7216. // 状态:0:未审核 1:已审核 2:已拒绝
  7217. if ($data['status'] == 2 || $data['status'] == '2') {
  7218. $this->sendMessage([
  7219. 'talk_type' => 901,
  7220. 'title' => $company['title'],
  7221. 'content' => '审核拒绝',
  7222. 'messageType' => 8,
  7223. 'user_id' => $company['user_id'],
  7224. ]);
  7225. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  7226. } else {
  7227. if ($data['status'] == 1) {
  7228. $this->sendMessage([
  7229. 'talk_type' => 901,
  7230. 'title' => $company['title'],
  7231. 'content' => '审核通过',
  7232. 'messageType' => 8,
  7233. 'user_id' => $company['user_id'],
  7234. ]);
  7235. } else if ($data['status'] == 0) {
  7236. $this->sendMessage([
  7237. 'talk_type' => 900,
  7238. 'title' => $company['title'],
  7239. 'content' => '提交了审核',
  7240. 'messageType' => 8,
  7241. ]);
  7242. }
  7243. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  7244. }
  7245. if (empty($result)) {
  7246. return Result::error('审核失败!');
  7247. } else {
  7248. return Result::success($result);
  7249. }
  7250. }
  7251. /**
  7252. * 获取企业信息
  7253. * @param array $data
  7254. * @return array
  7255. */
  7256. public function getCompanyInfo(array $data): array
  7257. {
  7258. $result = Company::where('id', $data['id'])->first();
  7259. $city_arr = json_decode($result['city_arr_id']);
  7260. $result['city_name'] = District::whereIn('id', $city_arr)
  7261. ->pluck('name')
  7262. ->implode('-');
  7263. if (empty($result)) {
  7264. return Result::error('企业不存在!');
  7265. } else {
  7266. return Result::success($result);
  7267. }
  7268. }
  7269. /**
  7270. * @param array $data
  7271. * @return array
  7272. */
  7273. public function getWebsiteCompany(array $data): array
  7274. {
  7275. $categorys = json_decode($data['id'], true);
  7276. $category_arr = $this->processArticlePro($data['website_id']);
  7277. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7278. $catiall = $category_arr['catiall'];
  7279. $categoryIds = $category_arr['categoryIds'];
  7280. // return Result::success($category_arr);
  7281. foreach ($categorys as $key => $value) {
  7282. if (array_key_exists('level', $value)) {
  7283. $parts = explode(',', $value['level']);
  7284. $level = $parts[0] ?? null;
  7285. $imgnum = $parts[1] ?? null;
  7286. $textnum = $parts[2] ?? null;
  7287. if (!empty($textnum) && $textnum > 0) {
  7288. $text_num = Company::where('level', $level)
  7289. ->whereIn('category_id', $categoryIds)
  7290. ->where('status', 1)
  7291. ->select(
  7292. 'company.id',
  7293. 'company.title',
  7294. 'company.description',
  7295. 'company.updated_at',
  7296. 'company.category_id',
  7297. 'company.cat_arr_id'
  7298. )
  7299. ->orderBy('updated_at', 'desc')
  7300. ->limit($textnum)
  7301. ->get()->all();
  7302. }
  7303. if (!empty($imgnum) && $imgnum > 0) {
  7304. $img_num = Company::where('level', $level)
  7305. ->whereIn('category_id', $categoryIds)
  7306. ->where('status', 1)
  7307. ->where('imgurl', '!=', '')
  7308. ->whereNotNull('imgurl')
  7309. ->select(
  7310. 'company.id',
  7311. 'company.title',
  7312. 'company.description',
  7313. 'company.updated_at',
  7314. 'company.imgurl as imgs',
  7315. 'company.category_id',
  7316. 'company.cat_arr_id'
  7317. )
  7318. ->orderBy('updated_at', 'desc')
  7319. ->limit($imgnum)
  7320. ->get()->all();
  7321. }
  7322. }
  7323. if (array_key_exists('id', $value)) {
  7324. $parts = explode(',', $value['id']);
  7325. $category_id = $parts[0] ?? null;
  7326. $imgnum = $parts[1] ?? null;
  7327. $textnum = $parts[2] ?? null;
  7328. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  7329. if (!empty($textnum) && $textnum > 0) {
  7330. $text_num = Company::whereIn('category_id', $category_arr)
  7331. // ->where('website_id', $data['website_id'])
  7332. ->where('status', 1)
  7333. ->select(
  7334. 'company.id',
  7335. 'company.title',
  7336. 'company.description',
  7337. 'company.updated_at',
  7338. 'company.category_id',
  7339. 'company.cat_arr_id'
  7340. )
  7341. ->orderBy('updated_at', 'desc')
  7342. ->limit($textnum)
  7343. ->get()->all();
  7344. }
  7345. if (!empty($imgnum) && $imgnum > 0) {
  7346. $img_num = Company::whereIn('category_id', $category_arr)
  7347. // ->where('website_id', $data['website_id'])
  7348. ->where('status', 1)
  7349. ->where('imgurl', '!=', '')
  7350. ->whereNotNull('imgurl')
  7351. ->select(
  7352. 'company.id',
  7353. 'company.title',
  7354. 'company.description',
  7355. 'company.updated_at',
  7356. 'company.imgurl as imgs',
  7357. 'company.category_id',
  7358. 'company.cat_arr_id'
  7359. )
  7360. ->orderBy('updated_at', 'desc')
  7361. ->limit($imgnum)
  7362. ->get()->all();
  7363. }
  7364. }
  7365. if (!empty($text_num)) {
  7366. foreach ($text_num as $k => $v) {
  7367. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7368. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7369. }
  7370. }
  7371. if (!empty($img_num)) {
  7372. foreach ($img_num as $k => $v) {
  7373. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7374. $imgurl = json_decode($v['imgs'], true);
  7375. if (!empty($imgurl)) {
  7376. $img_num[$k]->imgurl = $imgurl[0];
  7377. }
  7378. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7379. }
  7380. }
  7381. $company[$key]['img_num'] = $img_num ?? [];
  7382. $company[$key]['text_num'] = $text_num ?? [];
  7383. }
  7384. if (empty($company)) {
  7385. return Result::error("暂无相关企业信息", 0);
  7386. }
  7387. return Result::success($company);
  7388. }
  7389. /**
  7390. * @param array $data
  7391. * @return array
  7392. */
  7393. public function getWebsiteCompanyList(array $data): array
  7394. {
  7395. $where['website_id'] = $data['website_id'];
  7396. $where['status'] = 1;
  7397. $categoryIds = [];
  7398. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7399. $category_id = $data['category_id'];
  7400. }
  7401. $category_arr = $this->processArticlePro($data['website_id']);
  7402. $categoryIds = $category_arr['categoryIds'];
  7403. // return Result::success($cat_1st_arr);
  7404. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  7405. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  7406. })
  7407. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  7408. $query->whereIn('category_id', $categoryIds);
  7409. })
  7410. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  7411. $query->where('category_id', $category_id);
  7412. })
  7413. ->where('status',1)
  7414. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  7415. ->orderBy('updated_at', 'desc')
  7416. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7417. if (empty($company)) {
  7418. return Result::error("暂无相关公司信息", 0);
  7419. }
  7420. $result = [
  7421. 'count' => $company->total(),
  7422. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  7423. ];
  7424. return Result::success($result);
  7425. }
  7426. /**
  7427. * 获取项目列表
  7428. * @param array $data
  7429. * @return array
  7430. */
  7431. public function getProjectList(array $data): array
  7432. {
  7433. $where = [];
  7434. $user = User::where('id', $data['user_id'])->first();
  7435. if (empty($user)) {
  7436. return Result::error('用户不存在!');
  7437. }
  7438. if ($user->type_id != 10000) {
  7439. array_push($where, ['project.user_id', $data['user_id']]);
  7440. }
  7441. $query = Project::query();
  7442. if (isset($data['website_id']) && !empty($data['website_id'])) {
  7443. array_push($where, ['project.website_id', $data['website_id']]);
  7444. }
  7445. if (isset($data['title']) && !empty($data['title'])) {
  7446. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  7447. }
  7448. if ($data['status'] != 3) {
  7449. array_push($where, ['project.status', $data['status']]);
  7450. }
  7451. $query = Project::where($where)
  7452. ->when($data['status'] == 3, function ($query) {
  7453. $query->whereIn('project.status', [0, 2]);
  7454. });
  7455. $count = $query->clone()
  7456. ->count();
  7457. $rows = $query->clone()
  7458. ->leftJoin('website', 'project.website_id', 'website.id')
  7459. ->leftJoin('website_category', function ($join) {
  7460. $join->on('project.website_id', '=', 'website_category.website_id')
  7461. ->on('project.category_id', '=', 'website_category.category_id');
  7462. })
  7463. ->select(
  7464. 'project.id',
  7465. 'project.title',
  7466. 'project.updated_at',
  7467. 'project.status',
  7468. 'website.website_name',
  7469. 'website_category.alias as category_name',
  7470. 'project.website_id',
  7471. 'project.user_id'
  7472. )
  7473. ->orderBy('project.updated_at', 'desc')
  7474. ->offset(($data['page'] - 1) * $data['pageSize'])
  7475. ->limit($data['pageSize'])
  7476. ->get();
  7477. if ($rows->isEmpty()) {
  7478. return Result::error("暂无相关项目信息", 0);
  7479. }
  7480. $result = [
  7481. 'count' => $count,
  7482. 'rows' => $rows,
  7483. ];
  7484. return Result::success($result);
  7485. }
  7486. /**
  7487. * 添加项目
  7488. * @param array $data
  7489. * @return array
  7490. */
  7491. public function addProject(array $data): array
  7492. {
  7493. $user = User::where('id', $data['user_id'])->first();
  7494. if (empty($user)) {
  7495. return Result::error("暂无相关用户信息", 0);
  7496. }
  7497. if ($user->type_id == 10000) {
  7498. $data['status'] = 1;
  7499. } else {
  7500. $data['status'] = 0;
  7501. }
  7502. if ($data['keyword'] == '') {
  7503. //提取标题+内容中的关键词
  7504. $data['keyword'] = $data['title'];
  7505. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7506. Jieba::init(); // 初始化 jieba-php
  7507. Finalseg::init();
  7508. $segList = Jieba::cut($data['keyword']);
  7509. $segList1 = array_slice($segList, 0, 8);
  7510. $data['keyword'] = implode(',', $segList1);
  7511. }
  7512. if ($data['description'] == '') {
  7513. //提取内容中的描述
  7514. // var_dump(11111);
  7515. //提取内容中的描述
  7516. $content = $data['introduce'];
  7517. // 去除 <style> 和 <script> 标签及其内容
  7518. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7519. // 去除所有 HTML 标签
  7520. $content = strip_tags($content);
  7521. // 去除 HTML 实体
  7522. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7523. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7524. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7525. // 去除多余空白
  7526. $content = preg_replace('/\s+/u', '', $content);
  7527. // 截取 100 个字符
  7528. $data['description'] = mb_substr($content, 0, 100);
  7529. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7530. }
  7531. if ($data['status'] == 0) {
  7532. $this->sendMessage([
  7533. 'talk_type' => 1000,
  7534. 'title' => $data['title'],
  7535. 'content' => '提交了审核',
  7536. 'messageType' => 9,
  7537. ]);
  7538. }
  7539. $project = Project::insertGetId($data);
  7540. if (empty($project)) {
  7541. return Result::error("暂无相关项目信息", 0);
  7542. }
  7543. return Result::success($project);
  7544. }
  7545. /**
  7546. * 更新项目
  7547. * @param array $data
  7548. * @return array
  7549. */
  7550. public function upProject(array $data): array
  7551. {
  7552. $project = Project::where('id', $data['id'])->first();
  7553. if (empty($project)) {
  7554. return Result::error("暂无相关项目信息", 0);
  7555. }
  7556. $id = $data['id'];
  7557. unset($data['id']);
  7558. $user = User::where('id', $data['user_id'])->first();
  7559. if (empty($user)) {
  7560. return Result::error("暂无相关用户信息", 0);
  7561. }
  7562. if ($user->type_id == 10000) {
  7563. $data['status'] = 1;
  7564. } else {
  7565. $data['status'] = 0;
  7566. }
  7567. unset($data['user_id']);
  7568. if ($data['keyword'] == '') {
  7569. //提取标题+内容中的关键词
  7570. $data['keyword'] = $data['title'];
  7571. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7572. Jieba::init(); // 初始化 jieba-php
  7573. Finalseg::init();
  7574. $segList = Jieba::cut($data['keyword']);
  7575. $segList1 = array_slice($segList, 0, 8);
  7576. $data['keyword'] = implode(',', $segList1);
  7577. }
  7578. if ($data['description'] == '') {
  7579. //提取内容中的描述
  7580. // var_dump(11111);
  7581. //提取内容中的描述
  7582. $content = $data['introduce'];
  7583. // 去除 <style> 和 <script> 标签及其内容
  7584. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7585. // 去除所有 HTML 标签
  7586. $content = strip_tags($content);
  7587. // 去除 HTML 实体
  7588. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7589. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7590. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7591. // 去除多余空白
  7592. $content = preg_replace('/\s+/u', '', $content);
  7593. // 截取 100 个字符
  7594. $data['description'] = mb_substr($content, 0, 100);
  7595. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7596. }
  7597. if ($data['status'] == 0) {
  7598. $this->sendMessage([
  7599. 'talk_type' => 1000,
  7600. 'title' => $data['title'],
  7601. 'content' => '提交了审核',
  7602. 'messageType' => 9,
  7603. ]);
  7604. }
  7605. $result = Project::where('id', $id)->update($data);
  7606. if (empty($result)) {
  7607. return Result::error("更新失败", 0);
  7608. }
  7609. return Result::success($result);
  7610. }
  7611. /**
  7612. * 删除项目
  7613. * @param array $data
  7614. * @return array
  7615. */
  7616. public function delProject(array $data): array
  7617. {
  7618. $user = User::where('id', $data['user_id'])->first();
  7619. if (empty($user)) {
  7620. return Result::error("暂无相关用户信息", 0);
  7621. }
  7622. $project = Project::where('id', $data['id'])->first();
  7623. if (empty($project)) {
  7624. return Result::error("暂无相关项目信息", 0);
  7625. }
  7626. $result = Project::where('id', $data['id'])->delete();
  7627. if (empty($result)) {
  7628. return Result::error("删除失败", 0);
  7629. }
  7630. return Result::success($result);
  7631. }
  7632. /**
  7633. * 审核项目
  7634. * @param array $data
  7635. * @return array
  7636. */
  7637. public function checkProject(array $data): array
  7638. {
  7639. $user = User::where('id', $data['user_id'])->first();
  7640. if (empty($user)) {
  7641. return Result::error("暂无相关用户信息", 0);
  7642. }
  7643. // 0:未审核; 1:已审核; 2:已拒绝;
  7644. if ($user->type_id != 10000) {
  7645. if ($data['status'] == 1 || $data['status'] == 2) {
  7646. return Result::error("此用户权限不足", 0);
  7647. }
  7648. }
  7649. $project = Project::where('id', $data['id'])->first();
  7650. if (empty($project)) {
  7651. return Result::error("暂无相关项目信息", 0);
  7652. }
  7653. if ($data['status'] == 2) {
  7654. $this->sendMessage([
  7655. 'talk_type' => 1001,
  7656. 'title' => $project['title'],
  7657. 'content' => '审核拒绝',
  7658. 'messageType' => 9,
  7659. 'user_id' => $project['user_id'],
  7660. ]);
  7661. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7662. } else {
  7663. if ($data['status'] == 1) {
  7664. $this->sendMessage([
  7665. 'talk_type' => 1001,
  7666. 'title' => $project['title'],
  7667. 'content' => '审核通过',
  7668. 'messageType' => 9,
  7669. 'user_id' => $project['user_id'],
  7670. ]);
  7671. } else if ($data['status'] == 0) {
  7672. $this->sendMessage([
  7673. 'talk_type' => 1000,
  7674. 'title' => $project['title'],
  7675. 'content' => '提交了审核',
  7676. 'messageType' => 9,
  7677. ]);
  7678. }
  7679. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7680. }
  7681. if (empty($result)) {
  7682. return Result::error("审核失败", 0);
  7683. }
  7684. return Result::success($result);
  7685. }
  7686. /**
  7687. * 获取项目详情
  7688. * @param array $data
  7689. * @return array
  7690. */
  7691. public function getProjectInfo(array $data): array
  7692. {
  7693. $project = Project::where('id', $data['id'])->first();
  7694. if (empty($project)) {
  7695. return Result::error("暂无相关项目信息", 0);
  7696. }
  7697. return Result::success($project);
  7698. }
  7699. public function getWebsiteCompanyInfo(array $data): array
  7700. {
  7701. $company = Company::where('id', $data['id'])
  7702. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7703. ->where('status', 1)
  7704. // ->where('website_id', $data['website_id'])
  7705. ->select('company.*', 'job_industry.hyname as hy_name')
  7706. ->first();
  7707. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7708. $jobnature_id = $company['jobnature_id'] ?? null;
  7709. if ($jobnature_id !== null) {
  7710. switch ($jobnature_id) {
  7711. case 0:
  7712. $company->jobnature_name = '市场监督';
  7713. break;
  7714. case 1:
  7715. $company->jobnature_name = '信访纪检';
  7716. break;
  7717. case 2:
  7718. $company->jobnature_name = '公检法司';
  7719. break;
  7720. case 3:
  7721. $company->jobnature_name = '高关注机构';
  7722. break;
  7723. default:
  7724. $company->jobnature_name = '';
  7725. break;
  7726. }
  7727. } else {
  7728. $company->jobnature_name = '';
  7729. }
  7730. $city_arr = $company->city_arr_id;
  7731. if (!empty($city_arr)) {
  7732. $city_arr = json_decode($city_arr, true);
  7733. $cityNames = District::whereIn('id', $city_arr)
  7734. ->pluck('name')
  7735. ->implode('-');
  7736. $company->city_name = $cityNames;
  7737. } else {
  7738. $company->city_name = '';
  7739. }
  7740. if (empty($company)) {
  7741. return Result::error("暂无相关公司信息", 0);
  7742. }
  7743. return Result::success($company);
  7744. }
  7745. public function getMSG(array $data): array
  7746. {
  7747. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7748. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7749. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7750. $result = [];
  7751. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7752. //最近的5篇已审的文章
  7753. $apply_articale = Article::where('status', 1)
  7754. ->where('admin_user_id', $user_id)
  7755. ->orderBy('updated_at', 'desc')
  7756. // ->limit(5)
  7757. ->get();
  7758. //获取5条用户的已审核商品
  7759. $good = Good::where('status', 2)
  7760. ->where('user_id', $user_id)
  7761. ->orderBy('updated_at', 'desc')
  7762. // ->limit(5)
  7763. ->get();
  7764. //获取5条用户待审核的公告
  7765. $notice = Notice::where('status', 2)
  7766. ->where('user_id', $user_id)
  7767. ->orderBy('updated_at', 'desc')
  7768. ->limit(5)->get();
  7769. //获取5条用户的待审核投诉
  7770. $complaint = Complaint::where('status', 2)
  7771. ->where('user_id', $user_id)
  7772. ->orderBy('updated_at', 'desc')
  7773. // ->limit(5)
  7774. ->get();
  7775. //获取5条用户的book
  7776. $book = Book::where('status', 2)
  7777. ->where('user_id', $user_id)
  7778. ->orderBy('updated_at', 'desc')
  7779. // ->limit(5)
  7780. ->get();
  7781. //获取5条用户的求职
  7782. //获取5条用户的求职 1
  7783. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7784. ->where('job_hunting.user_id', $user_id)
  7785. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7786. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7787. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7788. ->orderBy('updated_at', 'desc')
  7789. // ->limit(5)
  7790. ->get();
  7791. //获取5条用户的求职 2
  7792. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7793. ->where('job_recruiting.user_id', $user_id)
  7794. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7795. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7796. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7797. ->orderBy('updated_at', 'desc')
  7798. // ->limit(5)
  7799. ->get();
  7800. //人才库 1
  7801. $job_apply = JobApply::where('job_apply.status', 1)
  7802. ->where('job_apply.receiver_id', $user_id)
  7803. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7804. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7805. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7806. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7807. ->select('job_recruiting', 'job_recruiting.', '', '')
  7808. ->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')
  7809. ->orderBy('updated_at', 'desc')
  7810. // ->limit(5)
  7811. ->get();
  7812. // 职场机会 2
  7813. $job_resume = JobResume::where('job_resume.status', 1)
  7814. ->where('job_resume.receiver_id', $user_id)
  7815. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7816. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7817. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7818. ->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')
  7819. ->orderBy('updated_at', 'desc')
  7820. // ->limit(5)
  7821. ->get();
  7822. //获取5条用户待处理的投诉
  7823. $complaint_deal = Complaint::where('status', 2)
  7824. ->where('deal', 1)
  7825. ->whereJsonContains('re_user_ids', $user_id)
  7826. ->orderBy('updated_at', 'desc')
  7827. // ->limit(5)
  7828. ->get();
  7829. //获取 被通知者未读信息
  7830. $notice_unread = Notice::where('status', 2)
  7831. ->whereJsonContains('re_user_ids', $user_id)
  7832. //未读消息
  7833. ->where(function ($query) use ($user_id) {
  7834. $query->whereJsonDoesntContain('read_id', $user_id)
  7835. ->orWhereNull('read_id');
  7836. })
  7837. ->orderBy('updated_at', 'desc')
  7838. ->get();
  7839. $complaint_unread = Complaint::where('status', 2)
  7840. ->whereJsonContains('re_user_ids', $user_id)
  7841. //未读消息
  7842. ->where(function ($query) use ($user_id) {
  7843. $query->whereJsonDoesntContain('read_id', $user_id)
  7844. ->orWhereNull('read_id');
  7845. })
  7846. ->orderBy('updated_at', 'desc')
  7847. ->get();
  7848. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7849. $complany = Company::where('status', 1)
  7850. ->where('user_id', $user_id)
  7851. ->orderBy('updated_at', 'desc')
  7852. // ->limit(5)
  7853. ->get();
  7854. //获取5条单聊未读聊天消息
  7855. // $chat = ChatRecords::where('is_read', 0)
  7856. // ->where('user_id', $user_id)
  7857. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7858. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7859. // ->where('action', 'recieved')
  7860. // ->where('talk_type', 1)
  7861. // ->orderBy('created_at', 'desc')
  7862. // // ->limit(5)
  7863. // ->get();
  7864. //获取5条未读群聊信息
  7865. // $chat_group = ChatRecords::where('is_read', 0)
  7866. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7867. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7868. // ->where('user_id', $user_id)
  7869. // ->where('talk_type', 2)
  7870. // ->orderBy('created_at', 'desc')
  7871. // // ->limit(5)
  7872. // ->get();
  7873. //获取5条用户的待审核项目
  7874. $project = Project::where('status', 1)
  7875. ->where('user_id', $user_id)
  7876. ->orderBy('updated_at', 'desc')
  7877. // ->limit(5)
  7878. ->get();
  7879. // count($chat) + count($chat_group) +
  7880. $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)
  7881. + count($complany)
  7882. + count($project)
  7883. + count($notice_unread)
  7884. + count($complaint_unread)
  7885. // + count($chat) + count($chat_group)
  7886. ;
  7887. $result = [
  7888. 'apply_articale' => $apply_articale,
  7889. // 'chat' => $chat,
  7890. // 'chat_group' => $chat_group,
  7891. 'good' => $good,
  7892. 'notice' => $notice,
  7893. 'complaint' => $complaint,
  7894. 'book' => $book,
  7895. 'job_hunting' => $job_hunting,
  7896. 'job_recruiting' => $job_recruiting,
  7897. 'job_apply' => $job_apply,
  7898. 'job_resume' => $job_resume,
  7899. 'complaint_deal' => $complaint_deal,
  7900. 'complany' => $complany,
  7901. 'project' => $project,
  7902. 'notice_unread' => $notice_unread,
  7903. 'complaint_unread' => $complaint_unread,
  7904. 'count' => $count,
  7905. ];
  7906. } elseif ($type_id == 12) {
  7907. //最近的5篇已审的文章
  7908. $apply_articale = Article::where('status', 1)
  7909. ->where('admin_user_id', $user_id)
  7910. ->limit(5)->get();
  7911. //获取5条单聊未读聊天消息
  7912. $chat = ChatRecords::where('is_read', 0)
  7913. ->where('user_id', $user_id)
  7914. ->where('talk_type', 1)
  7915. ->orderBy('created_at', 'desc')
  7916. ->limit(5)->get();
  7917. //获取5条未读群聊信息
  7918. $chat_group = ChatRecords::where('is_read', 0)
  7919. ->where('user_id', $user_id)
  7920. ->where('talk_type', 2)
  7921. ->orderBy('created_at', 'desc')
  7922. ->limit(5)->get();
  7923. //获取5条用户的已审核商品
  7924. $good = Good::where('status', 2)
  7925. ->where('user_id', $user_id)
  7926. ->orderBy('updated_at', 'desc')
  7927. ->limit(5)->get();
  7928. //获取5条用户的book
  7929. $book = Book::where('status', 2)
  7930. ->where('user_id', $user_id)
  7931. ->orderBy('updated_at', 'desc')
  7932. ->limit(5)->get();
  7933. //获取5条用户的求职
  7934. //获取5条用户的求职 1
  7935. //count($chat) + count($chat_group)
  7936. $count = count($apply_articale) + count($good);
  7937. $result = [
  7938. 'apply_articale' => $apply_articale,
  7939. 'chat' => $chat,
  7940. 'chat_group' => $chat_group,
  7941. 'good' => $good,
  7942. 'book' => $book,
  7943. 'count' => $count,
  7944. ];
  7945. } elseif ($type_id == 13) {
  7946. //最近的5篇已审的文章
  7947. $apply_articale = Article::where('status', 1)
  7948. ->where('admin_user_id', $user_id)
  7949. ->limit(5)->get();
  7950. //获取5条单聊未读聊天消息
  7951. $chat = ChatRecords::where('is_read', 0)
  7952. ->where('user_id', $user_id)
  7953. ->where('talk_type', 1)
  7954. ->orderBy('created_at', 'desc')
  7955. ->limit(5)->get();
  7956. //获取5条未读群聊信息
  7957. $chat_group = ChatRecords::where('is_read', 0)
  7958. ->where('user_id', $user_id)
  7959. ->where('talk_type', 2)
  7960. ->orderBy('created_at', 'desc')
  7961. ->limit(5)->get();
  7962. //获取5条用户的已审核商品
  7963. $good = Good::where('status', 2)
  7964. ->where('user_id', $user_id)
  7965. ->orderBy('updated_at', 'desc')
  7966. ->limit(5)->get();
  7967. //count($chat) + count($chat_group) +
  7968. $count = count($apply_articale) + count($good);
  7969. $result = [
  7970. 'apply_articale' => $apply_articale,
  7971. 'chat' => $chat,
  7972. 'chat_group' => $chat_group,
  7973. 'good' => $good,
  7974. 'count' => $count,
  7975. ];
  7976. } elseif ($type_id == 14) {
  7977. //最近的5篇已审的文章
  7978. $apply_articale = Article::where('status', 1)
  7979. ->where('admin_user_id', $user_id)
  7980. // ->limit(5)
  7981. ->get();
  7982. //获取5条用户的已审核商品
  7983. $good = Good::where('status', 2)
  7984. ->where('user_id', $user_id)
  7985. ->orderBy('updated_at', 'desc')
  7986. // ->limit(5)
  7987. ->get();
  7988. $count = count($apply_articale) + count($good);
  7989. $result = [
  7990. 'apply_articale' => $apply_articale,
  7991. 'chat' => '',
  7992. 'chat_group' => '',
  7993. 'good' => $good,
  7994. 'count' => $count,
  7995. ];
  7996. } elseif ($type_id == 10000) {
  7997. //获取未审核的5篇文章
  7998. $apply_articale = Article::where('status', 0)
  7999. ->orderBy('updated_at', 'desc')
  8000. // ->limit(5)
  8001. ->get();
  8002. //获取5条单聊未读聊天消息
  8003. //获取5条单聊未读聊天消息
  8004. // $chat = ChatRecords::where('is_read', 0)
  8005. // ->where('user_id', $user_id)
  8006. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  8007. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  8008. // ->where('action', 'recieved')
  8009. // ->where('talk_type', 1)
  8010. // ->orderBy('created_at', 'desc')
  8011. // // ->limit(5)
  8012. // ->get();
  8013. // //获取5条未读群聊信息
  8014. // $chat_group = ChatRecords::where('is_read', 0)
  8015. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  8016. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  8017. // ->where('user_id', $user_id)
  8018. // ->where('talk_type', 2)
  8019. // ->orderBy('created_at', 'desc')
  8020. // // ->limit(5)
  8021. // ->get();
  8022. //获取5条用户的已审核商品
  8023. $good = Good::where('status', 1)
  8024. // ->where('user_id', $user_id)
  8025. ->orderBy('updated_at', 'desc')
  8026. // ->limit(5)
  8027. ->get();
  8028. //获取5条用户待审核的公告
  8029. $notice = Notice::where('status', 1)
  8030. ->orderBy('updated_at', 'desc')
  8031. // ->limit(5)
  8032. ->get();
  8033. //获取5条用户的待审核投诉
  8034. $complaint = Complaint::where('status', 1)
  8035. ->orderBy('updated_at', 'desc')
  8036. // ->limit(5)
  8037. ->get();
  8038. //获取5条用户的book
  8039. $book = Book::where('status', 1)
  8040. ->orderBy('updated_at', 'desc')
  8041. // ->limit(5)
  8042. ->get();
  8043. //获取5条用户的求职 1
  8044. $job_hunting = JobHunting::where('job_hunting.status', 1)
  8045. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  8046. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  8047. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  8048. ->orderBy('updated_at', 'desc')
  8049. // ->limit(5)
  8050. ->get();
  8051. //获取5条用户的求职 2
  8052. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  8053. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  8054. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  8055. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  8056. ->orderBy('updated_at', 'desc')
  8057. // ->limit(5)
  8058. ->get();
  8059. //人才库 1
  8060. $job_apply = JobApply::where('job_apply.status', 1)
  8061. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  8062. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  8063. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  8064. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  8065. ->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')
  8066. ->orderBy('updated_at', 'desc')
  8067. // ->limit(5)
  8068. ->get();
  8069. // 职场机会 2
  8070. $job_resume = JobResume::where('job_resume.status', 1)
  8071. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  8072. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  8073. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  8074. ->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')
  8075. ->orderBy('updated_at', 'desc')
  8076. // ->limit(5)
  8077. ->get();
  8078. //待审核数据com pro
  8079. $complany = Company::where('status', 0)
  8080. ->orderBy('updated_at', 'desc')
  8081. // ->limit(5)
  8082. ->get();
  8083. $project = Project::where('status', 0)
  8084. ->orderBy('updated_at', 'desc')
  8085. // ->limit(5)
  8086. ->get();
  8087. $count =
  8088. // count($chat) +
  8089. // count($chat_group) +
  8090. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  8091. // + count($job_apply)
  8092. // + count($job_resume)
  8093. + count($complany)
  8094. + count($project);
  8095. $result = [
  8096. 'apply_articale' => $apply_articale,
  8097. // 'chat' => $chat,
  8098. // 'chat_group' => $chat_group,
  8099. 'good' => $good,
  8100. 'notice' => $notice,
  8101. 'complaint' => $complaint,
  8102. 'book' => $book,
  8103. 'job_hunting' => $job_hunting,
  8104. 'job_recruiting' => $job_recruiting,
  8105. // 'job_apply' => $job_apply,
  8106. // 'job_resume' => $job_resume,
  8107. 'complany' => $complany,
  8108. 'project' => $project,
  8109. 'count' => $count,
  8110. ];
  8111. } elseif ($type_id == 20000) {
  8112. }
  8113. var_dump($type_id, '-----------------test---------');
  8114. return Result::success($result);
  8115. }
  8116. /**
  8117. * @param array $data
  8118. * @return array
  8119. */
  8120. public function getWebsiteProject(array $data): array
  8121. {
  8122. $categorys = json_decode($data['id'], true);
  8123. if (!empty($categorys)) {
  8124. $category_arr = $this->processArticlePro($data['website_id']);
  8125. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8126. $catiall = $category_arr['catiall'];
  8127. // return Result::success($catiall);
  8128. foreach ($categorys as $key => $val) {
  8129. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  8130. $level = explode(',', $val['level'])[0];
  8131. $imgnum = explode(',', $val['level'])[1] ?? null;
  8132. $textnum = explode(',', $val['level'])[2] ?? null;
  8133. if ($level == 1) {
  8134. if (!empty($textnum) && $textnum > 0) {
  8135. $text_num = Project::where('level', $level)
  8136. ->where('website_id', $data['website_id'])
  8137. ->where('status', 1)
  8138. ->select(
  8139. 'project.id',
  8140. 'project.title',
  8141. 'project.description',
  8142. 'project.updated_at',
  8143. 'project.category_id',
  8144. 'project.cat_arr_id'
  8145. )
  8146. ->orderBy('updated_at', 'desc')
  8147. ->limit($textnum)
  8148. ->get()->all();
  8149. }
  8150. if (!empty($imgnum) && $imgnum > 0) {
  8151. $img_num = Project::where('level', $level)
  8152. ->where('website_id', $data['website_id'])
  8153. ->where('status', 1)
  8154. ->where('imgurl', '!=', '')
  8155. ->whereNotNull('imgurl')
  8156. ->select(
  8157. 'project.id',
  8158. 'project.title',
  8159. 'project.description',
  8160. 'project.updated_at',
  8161. 'project.imgurl as imgs',
  8162. 'project.category_id',
  8163. 'project.cat_arr_id'
  8164. )
  8165. ->orderBy('updated_at', 'desc')
  8166. ->limit($imgnum)
  8167. ->get()->all();
  8168. }
  8169. } else {
  8170. if (!empty($textnum) && $textnum > 0) {
  8171. $text_num = Project::where('website_id', $data['website_id'])
  8172. ->where('status', 1)
  8173. ->select(
  8174. 'project.id',
  8175. 'project.title',
  8176. 'project.description',
  8177. 'project.updated_at',
  8178. 'project.category_id',
  8179. 'project.cat_arr_id',
  8180. 'project.website_id',
  8181. 'project.updated_at',
  8182. 'project.created_at'
  8183. )
  8184. ->orderBy('updated_at', 'desc')
  8185. ->limit($textnum)
  8186. ->get()->all();
  8187. }
  8188. if (!empty($imgnum) && $imgnum > 0) {
  8189. $img_num = Project::where('website_id', $data['website_id'])
  8190. ->where('status', 1)
  8191. ->where('imgurl', '!=', '')
  8192. ->whereNotNull('imgurl')
  8193. ->select(
  8194. 'project.id',
  8195. 'project.title',
  8196. 'project.description',
  8197. 'project.updated_at',
  8198. 'project.imgurl as imgs',
  8199. 'project.category_id',
  8200. 'project.cat_arr_id'
  8201. )
  8202. ->orderBy('updated_at', 'desc')
  8203. ->limit($imgnum)
  8204. ->get()->all();
  8205. }
  8206. }
  8207. }
  8208. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  8209. $category_ids = explode(',', $val['id'])[0];
  8210. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  8211. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  8212. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  8213. if (!empty($cat_textnum) && $cat_textnum > 0) {
  8214. $text_num = Project::whereIn('category_id', $category_arr)
  8215. ->where('website_id', $data['website_id'])
  8216. ->where('status', 1)
  8217. ->select(
  8218. 'project.id',
  8219. 'project.title',
  8220. 'project.description',
  8221. 'project.updated_at',
  8222. 'project.category_id',
  8223. 'project.cat_arr_id'
  8224. )
  8225. ->orderBy('updated_at', 'desc')
  8226. ->limit($cat_textnum)
  8227. ->get()->all();
  8228. }
  8229. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  8230. $img_num = Project::whereIn('category_id', $category_arr)
  8231. ->where('website_id', $data['website_id'])
  8232. ->where('status', 1)
  8233. ->where('imgurl', '!=', '')
  8234. ->whereNotNull('imgurl')
  8235. ->select(
  8236. 'project.id',
  8237. 'project.title',
  8238. 'project.description',
  8239. 'project.updated_at',
  8240. 'project.imgurl as imgs',
  8241. 'project.category_id',
  8242. 'project.cat_arr_id'
  8243. )
  8244. ->orderBy('updated_at', 'desc')
  8245. ->limit($cat_imgnum)
  8246. ->get()->all();
  8247. }
  8248. }
  8249. if (!empty($img_num)) {
  8250. foreach ($img_num as $k => $v) {
  8251. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8252. $imgurl = json_decode($v['imgs'], true);
  8253. if (!empty($imgurl)) {
  8254. $img_num[$k]->imgurl = $imgurl[0];
  8255. }
  8256. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8257. }
  8258. }
  8259. if (!empty($text_num)) {
  8260. foreach ($text_num as $k => $v) {
  8261. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8262. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8263. }
  8264. }
  8265. $project[$key]['img_num'] = $img_num ?? [];
  8266. $project[$key]['text_num'] = $text_num ?? [];
  8267. }
  8268. }
  8269. if (empty($project)) {
  8270. return Result::error("暂无相关项目信息", 0);
  8271. }
  8272. return Result::success($project);
  8273. }
  8274. /**
  8275. * @param array $data
  8276. * @return array
  8277. */
  8278. public function getWebsiteProjectInfo(array $data): array
  8279. {
  8280. $project = Project::where('id', $data['id'])
  8281. ->where('status', 1)
  8282. ->where('website_id', $data['website_id'])
  8283. ->select('project.*')
  8284. ->first();
  8285. if (empty($project)) {
  8286. return Result::error("暂无相关项目信息", 0);
  8287. }
  8288. return Result::success($project);
  8289. }
  8290. /**
  8291. * @param array $data
  8292. * @return array
  8293. */
  8294. public function getWebsiteProjectList(array $data): array
  8295. {
  8296. $where = [];
  8297. if (isset($data['category_id']) && !empty($data['category_id'])) {
  8298. $where['category_id'] = $data['category_id'];
  8299. }
  8300. if (isset($data['keyword']) && !empty($data['keyword'])) {
  8301. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  8302. }
  8303. $query = Project::where($where)
  8304. ->where('status', 1)
  8305. ->where('website_id', $data['website_id'])
  8306. ->select(
  8307. 'project.id',
  8308. 'project.title',
  8309. 'project.description',
  8310. 'project.imgurl as imgs',
  8311. 'project.category_id',
  8312. 'project.cat_arr_id'
  8313. )
  8314. ->orderBy('updated_at', 'desc');
  8315. $count = $query->count();
  8316. $project = $query->clone()
  8317. ->offset(($data['page'] - 1) * $data['pageSize'])
  8318. ->limit($data['pageSize'])
  8319. ->get()->all();
  8320. if (empty($project)) {
  8321. return Result::error("暂无相关项目信息", 0);
  8322. }
  8323. $categorys = $this->processArticlePro($data['website_id']);
  8324. $catiall = $categorys['catiall'];
  8325. foreach ($project as $key => $val) {
  8326. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  8327. if (!empty($val['imgs'])) {
  8328. $imgurl = json_decode($val['imgs'], true);
  8329. if (!empty($imgurl)) {
  8330. $project[$key]->imgurl = $imgurl[0];
  8331. }
  8332. } else {
  8333. $project[$key]->imgurl = '';
  8334. }
  8335. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  8336. }
  8337. $result = [
  8338. 'rows' => $project,
  8339. 'count' => $count,
  8340. ];
  8341. return Result::success($result);
  8342. }
  8343. /**
  8344. * @param array $data
  8345. * @return array
  8346. */
  8347. public function getWebsiteCategoryJob(array $data): array
  8348. {
  8349. $categorys = json_decode($data['id'], true);
  8350. if (!empty($categorys)) {
  8351. $category_arr = $this->processArticlePro($data['website_id']);
  8352. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8353. $catiall = $category_arr['catiall'];
  8354. foreach ($categorys as $key => $val) {
  8355. if (isset($val['id']) && !empty($val['id'])) {
  8356. $catid = explode(',', $val['id'])[0] ?? null;
  8357. $type = explode(',', $val['id'])[1] ?? null;
  8358. $textnum = explode(',', $val['id'])[2] ?? null;
  8359. }
  8360. // 4:招聘;5:求职;
  8361. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  8362. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  8363. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  8364. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  8365. ->where('job_recruiting.status', 1)
  8366. ->where('job_recruiting.website_id', $data['website_id'])
  8367. ->select(
  8368. 'job_recruiting.id',
  8369. 'job_recruiting.title',
  8370. 'job_company.business_name',
  8371. 'job_recruiting.updated_at',
  8372. 'job_recruiting.cat_arr_id',
  8373. 'job_recruiting.keyword',
  8374. 'job_recruiting.description'
  8375. )
  8376. ->orderBy('job_recruiting.updated_at', 'desc')
  8377. ->limit($textnum)
  8378. ->get()->all();
  8379. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  8380. // 状态 审核状态,1待审核2已审核3已拒绝
  8381. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  8382. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  8383. ->where('job_hunting.status', 2)
  8384. ->where('job_hunting.website_id', $data['website_id'])
  8385. ->select(
  8386. 'job_hunting.id',
  8387. 'job_hunting.name',
  8388. 'job_hunting.cat_arr_id',
  8389. 'job_position.zwname as job_name',
  8390. 'job_hunting.updated_at',
  8391. // 'job_hunting.keyword',
  8392. 'job_hunting.slelf_evaluation'
  8393. )
  8394. ->orderBy('updated_at', 'desc')
  8395. ->limit($textnum)
  8396. ->get()->all();
  8397. } else {
  8398. $job = [];
  8399. }
  8400. // var_dump($catid.'222uuuuuuu'.$key);
  8401. if (!empty($job)) {
  8402. foreach ($job as $k => $value) {
  8403. if (isset($value->cat_arr_id)) {
  8404. $catArr = json_decode($value->cat_arr_id, true);
  8405. $catId = end($catArr);
  8406. } else {
  8407. continue;
  8408. }
  8409. if (isset($catiall[$catId])) {
  8410. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  8411. }
  8412. }
  8413. }
  8414. // var_dump($catid.'xxxxx'.$key);
  8415. $result[$key] = $job ?? [];
  8416. }
  8417. }
  8418. if (empty($result)) {
  8419. return Result::error("暂无相关分类信息", 0);
  8420. }
  8421. return Result::success($result);
  8422. }
  8423. /**
  8424. * 发送消息
  8425. * @param array $messageData
  8426. * @return void
  8427. */
  8428. public function sendMessage($messageData)
  8429. {
  8430. $msg = [
  8431. 'talk_type' => $messageData['talk_type'],
  8432. 'title' => $messageData['title'],
  8433. 'content' => $messageData['content'],
  8434. 'messageType' => $messageData['messageType'],
  8435. 'user_id' => $messageData['user_id'] ?? '',
  8436. 'time' => microtime(),
  8437. ];
  8438. $message = new MqProducer($msg);
  8439. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  8440. $producer->produce($message);
  8441. }
  8442. /**
  8443. * 行业分类管理 ------1121
  8444. * @param array $data
  8445. * @return array
  8446. */
  8447. public function getJobIndustryList(array $data): array
  8448. {
  8449. $page = $data['page'] ?? 1;
  8450. $page_size = $data['page_size'] ?? 10;
  8451. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8452. $where = ['hyname', 'like', '%' . $data['hyname'] . '%'];
  8453. } else {
  8454. $where = [];
  8455. }
  8456. $rs_query = JobIndustry::when(!empty($where), function ($query) use ($where) {
  8457. $query->where([$where]); // 修复:将条件包装成二维数组
  8458. })
  8459. ->orderBy('updated_at', 'desc');
  8460. $count = $rs_query->count();
  8461. $hy = $rs_query->offset(($page - 1) * $page_size)->limit($page_size)->get()->all();
  8462. $result = [
  8463. 'count' => $count,
  8464. 'list' => $hy,
  8465. ];
  8466. if (empty($hy)) {
  8467. return Result::success('暂无数据');
  8468. }
  8469. return Result::success($result);
  8470. }
  8471. /**
  8472. * 添加行业分类
  8473. * @param array $data
  8474. * @return array
  8475. */
  8476. public function addJobIndustry(array $data): array
  8477. {
  8478. $hy_name = JobIndustry::where('hyname', $data['hyname'])->first(['hyid']);
  8479. if (!empty($hy_name)) {
  8480. return Result::error('行业分类已存在');
  8481. }
  8482. $hy = JobIndustry::insertGetId($data);
  8483. if (empty($hy)) {
  8484. return Result::error('添加失败');
  8485. }
  8486. return Result::success($hy);
  8487. }
  8488. /**
  8489. * 更新行业分类
  8490. * @param array $data
  8491. * @return array
  8492. */
  8493. public function upJobIndustry(array $data): array
  8494. {
  8495. $hy_query = JobIndustry::get();
  8496. $hy_ids = $hy_query->pluck('hyid')->toArray();
  8497. $hy_names = $hy_query->pluck('hyname')->toArray();
  8498. if (!in_array($data['hyid'], $hy_ids)) {
  8499. return Result::error('行业分类不存在');
  8500. }
  8501. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8502. $other_key_hy = array_search($data['hyid'], $hy_ids);
  8503. // return Result::success($other_key_hy);
  8504. unset($hy_names[$other_key_hy]);
  8505. if (in_array($data['hyname'], $hy_names)) {
  8506. return Result::error('行业分类名称已存在');
  8507. }
  8508. }
  8509. $hy = JobIndustry::where('hyid', $data['hyid'])->update($data);
  8510. if (empty($hy)) {
  8511. return Result::error('更新失败');
  8512. }
  8513. return Result::success($hy);
  8514. }
  8515. /**
  8516. * 删除行业分类
  8517. * @param array $data
  8518. * @return array
  8519. */
  8520. public function delJobIndustry(array $data): array
  8521. {
  8522. $hy_id = JobIndustry::where('hyid', $data['hyid'])->first(['hyid']);
  8523. if (empty($hy_id)) {
  8524. return Result::error('行业分类不存在');
  8525. }
  8526. $hy = JobIndustry::where('hyid', $data['hyid'])->delete();
  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 getJobPositionList(array $data): array
  8538. {
  8539. $page = $data['page'] ?? 1;
  8540. $page_size = $data['page_size'] ?? 10;
  8541. $where = [];
  8542. if (isset($data['zwname']) && !empty($data['zwname'])) {
  8543. $zwids = JobPosition::where('zwpid', 0)
  8544. ->when(!empty($data['zwname']), function ($query) use ($data) {
  8545. $query->where('zwname', 'like', '%' . $data['zwname'] . '%');
  8546. })
  8547. ->orderBy('updated_at', 'desc')
  8548. ->pluck('zwid')
  8549. // ->get()
  8550. ->toArray();
  8551. }
  8552. if (isset($data['childname']) && !empty($data['childname'])) {
  8553. $child_zwids = JobPosition::where('zwpid', '!=', 0)
  8554. ->when(!empty($data['childname']), function ($query) use ($data) {
  8555. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8556. })
  8557. ->orderBy('updated_at', 'desc')
  8558. ->pluck('zwpid')
  8559. // ->get()
  8560. ->toArray();
  8561. if (isset($zwids) && is_array($zwids) && is_array($child_zwids)) {
  8562. $child_zwids = array_intersect($zwids, $child_zwids);
  8563. }
  8564. $zwids = array_values(array_unique($child_zwids));
  8565. }
  8566. $zwids = $zwids ?? null;
  8567. $count = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8568. $query->whereIn('zwid', $zwids);
  8569. })
  8570. ->where('zwpid', 0)
  8571. ->count();
  8572. $position = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8573. $query->whereIn('zwid', $zwids);
  8574. })
  8575. ->where('zwpid', 0)
  8576. ->orderBy('updated_at', 'desc')
  8577. ->offset(($page - 1) * $page_size)
  8578. ->limit($page_size)->get()
  8579. ->map(function ($item) use ($data) {
  8580. $item->children = $item->where('zwpid', $item->zwid)
  8581. ->when(!empty($data['childname']), function ($query) use ($data) {
  8582. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8583. })
  8584. ->orderBy('updated_at', 'desc')
  8585. ->get();
  8586. return $item;
  8587. })
  8588. ->all();
  8589. $result = [
  8590. 'count' => $count,
  8591. 'list' => $position,
  8592. ];
  8593. if (empty($result)) {
  8594. return Result::success('暂无数据');
  8595. }
  8596. return Result::success($result);
  8597. }
  8598. /**
  8599. * 职位分类-添加
  8600. * @param array $data
  8601. * @return array
  8602. */
  8603. public function addJobPosition(array $data): array
  8604. {
  8605. $zw_name = JobPosition::where('zwpid', $data['zwpid'])
  8606. ->where('zwname', $data['zwname'])->first(['zwid']);
  8607. if (!empty($zw_name)) {
  8608. return Result::error('职位分类已存在');
  8609. }
  8610. $zw = JobPosition::insertGetId($data);
  8611. if(empty($zw)){
  8612. return Result::error('添加失败');
  8613. }
  8614. return Result::success($zw);
  8615. }
  8616. /**
  8617. * 更新职位分类
  8618. * @param array $data
  8619. * @return array
  8620. */
  8621. public function upJobPosition(array $data): array
  8622. {
  8623. $zw_position = JobPosition::get();
  8624. if (!in_array($data['zwid'], $zw_position->pluck('zwid')->toArray())) {
  8625. return Result::error('职位分类不存在');
  8626. }
  8627. $zw_name = $zw_position->where('zwid', '!=', $data['zwid'])
  8628. ->where('zwpid', $data['zwpid'])
  8629. ->where('zwname', $data['zwname'])->first();
  8630. if (!empty($zw_name)) {
  8631. return Result::error('职位分类已存在');
  8632. }
  8633. $result = JobPosition::where('zwid', $data['zwid'])->update($data);
  8634. if (empty($result)) {
  8635. return Result::error('更新失败');
  8636. }
  8637. return Result::success($result);
  8638. }
  8639. /**
  8640. * 删除职位分类
  8641. * @param array $data
  8642. * @return array
  8643. */
  8644. public function delJobPosition(array $data): array
  8645. {
  8646. $zw_jobposition = JobPosition::get();
  8647. $zw_id = $zw_jobposition->where('zwid', $data['zwid'])->first();
  8648. if (empty($zw_id)) {
  8649. return Result::error('职位分类不存在');
  8650. }
  8651. if($zw_id->zwpid == 0){
  8652. $zw_job = JobPosition::where('zwpid', $zw_id->zwid)->first();
  8653. if(!empty($zw_job)){
  8654. return Result::error('请先删除子分类');
  8655. }
  8656. }
  8657. $result = JobPosition::where('zwid', $data['zwid'])->delete();
  8658. if (empty($result)) {
  8659. return Result::error('删除失败');
  8660. }
  8661. return Result::success($result);
  8662. }
  8663. /**
  8664. * 网民留言-添加
  8665. * @param array $data
  8666. * @return array
  8667. */
  8668. public function addMessage(array $data): array
  8669. {
  8670. $user = User::where('id', $data['user_id'])->first();
  8671. if (empty($user)) {
  8672. return Result::error('用户不存在');
  8673. }
  8674. if($user['type_id'] == 10000){
  8675. $data['status'] = 1;
  8676. }else{
  8677. $data['status'] = 0;
  8678. }
  8679. if ($data['keyword'] == '') {
  8680. //提取标题+内容中的关键词
  8681. $data['keyword'] = $data['title'];
  8682. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  8683. Jieba::init(); // 初始化 jieba-php
  8684. Finalseg::init();
  8685. $segList = Jieba::cut($data['keyword']);
  8686. $segList1 = array_slice($segList, 0, 8);
  8687. $data['keyword'] = implode(',', $segList1);
  8688. }
  8689. if ($data['description'] == '') {
  8690. //提取内容中的描述
  8691. $content = $data['content'];
  8692. // 去除 <style> 和 <script> 标签及其内容
  8693. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  8694. // 去除所有 HTML 标签
  8695. $content = strip_tags($content);
  8696. // 去除 HTML 实体
  8697. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  8698. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  8699. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  8700. // 去除多余空白
  8701. $content = preg_replace('/\s+/u', '', $content);
  8702. // 截取 100 个字符
  8703. $data['description'] = mb_substr($content, 0, 100);
  8704. }
  8705. if(!empty($data['reply'])){
  8706. $data['reply_userid'] = $data['user_id'];
  8707. }
  8708. $result = Message::insertGetId($data);
  8709. if(empty($result)){
  8710. return Result::error('添加失败');
  8711. }
  8712. return Result::success($result);
  8713. }
  8714. /**
  8715. * 网民留言-更新
  8716. * @param array $data
  8717. * @return array
  8718. */
  8719. public function upMessage(array $data): array
  8720. {
  8721. $user = User::where('id', $data['user_id'])->first();
  8722. if (empty($user)) {
  8723. return Result::error('用户不存在');
  8724. }
  8725. if($user['type_id'] == 10000){
  8726. $data['status'] = 1;
  8727. }else{
  8728. $data['status'] = 0;
  8729. }
  8730. $message = Message::where('id', $data['id'])->first();
  8731. if (empty($message)) {
  8732. return Result::error('留言不存在');
  8733. }
  8734. if($data['user_id'] != $message['user_id'] && $user['type_id'] != 10000){
  8735. return Result::error('非留言人不能更新');
  8736. }
  8737. if ($data['keyword'] == '') {
  8738. //提取标题+内容中的关键词
  8739. $data['keyword'] = $data['title'];
  8740. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  8741. Jieba::init(); // 初始化 jieba-php
  8742. Finalseg::init();
  8743. $segList = Jieba::cut($data['keyword']);
  8744. $segList1 = array_slice($segList, 0, 8);
  8745. $data['keyword'] = implode(',', $segList1);
  8746. }
  8747. if ($data['description'] == '') {
  8748. //提取内容中的描述
  8749. $content = $data['content'];
  8750. // 去除 <style> 和 <script> 标签及其内容
  8751. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  8752. // 去除所有 HTML 标签
  8753. $content = strip_tags($content);
  8754. // 去除 HTML 实体
  8755. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  8756. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  8757. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  8758. // 去除多余空白
  8759. $content = preg_replace('/\s+/u', '', $content);
  8760. // 截取 100 个字符
  8761. $data['description'] = mb_substr($content, 0, 100);
  8762. }
  8763. unset($data['id']);
  8764. if(!empty($data['reply'])){
  8765. $data['reply_userid'] = $data['user_id'];
  8766. unset($data['user_id']);
  8767. }
  8768. $result = Message::where('id', $message['id'])->update($data);
  8769. if (empty($result)) {
  8770. return Result::error('更新失败');
  8771. }
  8772. return Result::success($result);
  8773. }
  8774. /**
  8775. * 网民留言-删除
  8776. * @param array $data
  8777. * @return array
  8778. */
  8779. public function delMessage(array $data): array
  8780. {
  8781. $result = Message::where('id', $data['id'])->delete();
  8782. if (empty($result)) {
  8783. return Result::error('删除失败');
  8784. }
  8785. return Result::success($result);
  8786. }
  8787. /**
  8788. * 网民留言-更新状态
  8789. * @param array $data
  8790. * @return array
  8791. */
  8792. public function upMessageStatus(array $data): array
  8793. {
  8794. $message = Message::where('id', $data['id'])->first();
  8795. if (empty($message)) {
  8796. return Result::error('留言不存在!');
  8797. }
  8798. unset($data['id']);
  8799. unset($data['user_id']);
  8800. if($data['status'] != 2){
  8801. $data['reason'] = null;
  8802. }
  8803. $result = Message::where('id', $message['id'])->update($data);
  8804. if (empty($result)) {
  8805. return Result::error('留言更新失败!');
  8806. }
  8807. return Result::success($result);
  8808. }
  8809. /**
  8810. * 网民留言-获取详情
  8811. * @param array $data
  8812. * @return array
  8813. */
  8814. public function getMessageInfo(array $data): array
  8815. {
  8816. $result = Message::where('message.id', $data['id'])
  8817. ->leftJoin('website_column', 'message.column_id', '=', 'website_column.id')
  8818. ->select('message.*', 'website_column.column_arr_id')
  8819. ->first();
  8820. if (empty($result)) {
  8821. return Result::error('留言不存在!');
  8822. }
  8823. $result['column_arr_id'] = json_decode($result['column_arr_id'] ?? [], true);
  8824. return Result::success($result);
  8825. }
  8826. /**
  8827. * 网民留言-获取列表
  8828. * @param array $data
  8829. * @return array
  8830. */
  8831. public function getMessageList(array $data): array
  8832. {
  8833. $where = [];
  8834. if($data['is_master'] == 1){
  8835. $where['message.status'] = 1;
  8836. }else if($data['is_master'] == 2){
  8837. $where['message.status'] = 2;
  8838. }else if($data['is_master'] == 3){
  8839. $where['message.status'] = 0;
  8840. }
  8841. $user = User::where('id', $data['user_id'])->first();
  8842. if (empty($user)) {
  8843. return Result::error('用户不存在');
  8844. }
  8845. $column_arr_id = [];
  8846. if($user['type_id'] != 10000 && !empty($data['website_id'])){
  8847. $where['message.user_id'] = $data['user_id'];
  8848. $web = Website::where('id',$data['website_id'])->first('website_column_arr_id');
  8849. if(empty($web)){
  8850. return Result::error('此网站未关联任何网站属性!');
  8851. }
  8852. $column_arr_id = json_decode($web['website_column_arr_id'],true);
  8853. }
  8854. if(!empty($data['title'])){
  8855. array_push($where, ['message.title', 'like', '%'.$data['title'].'%']);
  8856. }
  8857. $result = Message::when($data['is_master'] == 0, function ($query) {
  8858. $query->whereIn('message.status', [0, 2]);
  8859. })
  8860. ->when(!empty($where), function ($query) use ($where) {
  8861. $query->where($where);
  8862. })
  8863. ->leftJoin('user', 'message.user_id', '=', 'user.id')
  8864. ->select('message.*', 'user.nickname')
  8865. ->orderBy('message.updated_at', 'desc')
  8866. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  8867. if(empty($result->items())) {
  8868. return Result::error('留言不存在!');
  8869. }
  8870. $result = [
  8871. 'data' => $result->items(),
  8872. 'count' => $result->total(),
  8873. ];
  8874. if(!empty($column_arr_id) && $user['type_id'] != 10000){
  8875. foreach($result['data'] as $key => $value){
  8876. if(in_array($value['column_id'], $column_arr_id)){
  8877. $result['data'][$key]['is_update'] = 1;
  8878. }else{
  8879. $result['data'][$key]['is_update'] = 0;
  8880. }
  8881. }
  8882. }
  8883. return Result::success($result);
  8884. }
  8885. /**
  8886. * 网民留言-检查是否可编辑
  8887. * @param array $data
  8888. * @return array
  8889. */
  8890. public function checkMessageEdit(array $data): array
  8891. {
  8892. $message = Message::where('id', $data['id'])->first();
  8893. if (empty($message)) {
  8894. return Result::error('留言不存在!');
  8895. }
  8896. $web = Website::where('id', $data['website_id'])->first();
  8897. if (empty($web)) {
  8898. return Result::error('网站不存在!');
  8899. }
  8900. $column_arr = json_decode($web['website_column_arr_id'] ?? [], true);
  8901. if(empty($column_arr)){
  8902. return Result::error('该网站未关联任何属性!');
  8903. }
  8904. if(!in_array($message['column_id'], $column_arr)){
  8905. return Result::error('不可编辑');
  8906. }
  8907. return Result::success('可编辑');
  8908. }
  8909. /**
  8910. * 调研选题-获取所有Researchers
  8911. * @param array $data
  8912. * @return array
  8913. */
  8914. public function getAllResearcher(array $data): array
  8915. {
  8916. $where['user.type_id'] = 4;
  8917. if(!empty($data['id'])){
  8918. $where['user.id'] = $data['id'];
  8919. }
  8920. if(!empty($data['real_name'])){
  8921. array_push($where, ['user_info.real_name', 'like', '%'.$data['real_name'].'%']);
  8922. }
  8923. $users = User::leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  8924. ->where($where)
  8925. ->select('user.id', 'user_info.real_name')
  8926. ->get()->toArray();
  8927. if (empty($users)) {
  8928. return Result::error('此调研员不存在!');
  8929. }
  8930. $result['users'] = $users;
  8931. $result['user_id'] = $data['user_id'];
  8932. return Result::success($result);
  8933. }
  8934. /**
  8935. * 调研选题-添加
  8936. * @param array $data
  8937. * @return array
  8938. */
  8939. public function addResearchTopic(array $data): array
  8940. {
  8941. $user = User::where('id', $data['user_id'])->first();
  8942. if (empty($user)) {
  8943. return Result::error('用户不存在');
  8944. }
  8945. if($user['type_id'] == 10000){
  8946. $data['status'] = 1;
  8947. }else{
  8948. $data['status'] = 0;
  8949. }
  8950. if ($data['keyword'] == '') {
  8951. //提取标题+内容中的关键词
  8952. $data['keyword'] = $data['title'];
  8953. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  8954. Jieba::init(); // 初始化 jieba-php
  8955. Finalseg::init();
  8956. $segList = Jieba::cut($data['keyword']);
  8957. $segList1 = array_slice($segList, 0, 8);
  8958. $data['keyword'] = implode(',', $segList1);
  8959. }
  8960. if ($data['description'] == '') {
  8961. //提取内容中的描述
  8962. $content = $data['content'];
  8963. // 去除 <style> 和 <script> 标签及其内容
  8964. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  8965. // 去除所有 HTML 标签
  8966. $content = strip_tags($content);
  8967. // 去除 HTML 实体
  8968. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  8969. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  8970. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  8971. // 去除多余空白
  8972. $content = preg_replace('/\s+/u', '', $content);
  8973. // 截取 100 个字符
  8974. $data['description'] = mb_substr($content, 0, 100);
  8975. }
  8976. $data['level'] = empty($data['level']) ? null : $data['level'];
  8977. $data['province_id'] = empty($data['province_id']) ? null : $data['province_id'];
  8978. $data['city_id'] = empty($data['city_id']) ? null : $data['city_id'];
  8979. $data['due_time'] = empty($data['due_time']) ? null : $data['due_time'];
  8980. $users_id = empty($data['users_id']) ? null : $data['users_id'];
  8981. unset($data['users_id']);
  8982. // return Result::success($data);
  8983. Db::beginTransaction();
  8984. try{
  8985. $result = ResearchTopic::insertGetId($data);
  8986. if (empty($result)) {
  8987. Db::rollBack();
  8988. return Result::error('添加失败');
  8989. }
  8990. $users = json_decode($users_id ?? '[]',true);
  8991. $users_type4 = User::where('type_id', 4)->pluck('id');
  8992. $type4_num = array_intersect($users, $users_type4->toArray());
  8993. if(count($users) != count($type4_num)){
  8994. Db::rollBack();
  8995. return Result::error('请选择调研员!');
  8996. }
  8997. // return Result::success($users);
  8998. if(!empty($users)){
  8999. // 去重:确保同一 retopic_id + user_id 组合唯一
  9000. $users = array_values(array_unique($users));
  9001. // 组装关联数据
  9002. $users_topic = [];
  9003. foreach ($users as $key => $value) {
  9004. $users_topic[$key] = [
  9005. 'user_id' => $value,
  9006. 'retopic_id' => $result,
  9007. ];
  9008. }
  9009. // 使用 insertOrIgnore 忽略重复主键/唯一索引冲突
  9010. $retopic_user = RetopicUser::insert($users_topic);
  9011. if(empty($retopic_user)){
  9012. Db::rollBack();
  9013. return Result::error('添加失败');
  9014. }
  9015. }
  9016. Db::commit();
  9017. return Result::success($result);
  9018. }catch(\Exception $e){
  9019. Db::rollBack();
  9020. return Result::error($e->getMessage());
  9021. }
  9022. }
  9023. /**
  9024. * 调研选题-编辑
  9025. * @param array $data
  9026. * @return array
  9027. */
  9028. public function upResearchTopic(array $data): array
  9029. {
  9030. $user = User::where('id', $data['user_id'])->first();
  9031. if (empty($user)) {
  9032. return Result::error('用户不存在');
  9033. }
  9034. if($user['type_id'] == 10000){
  9035. $data['status'] = 1;
  9036. }else{
  9037. $data['status'] = 0;
  9038. }
  9039. $topic = ResearchTopic::where('id', $data['id'])->first();
  9040. if (empty($topic)) {
  9041. return Result::error('此调研选题不存在');
  9042. }
  9043. if ($data['keyword'] == '') {
  9044. //提取标题+内容中的关键词
  9045. $data['keyword'] = $data['title'];
  9046. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  9047. Jieba::init(); // 初始化 jieba-php
  9048. Finalseg::init();
  9049. $segList = Jieba::cut($data['keyword']);
  9050. $segList1 = array_slice($segList, 0, 8);
  9051. $data['keyword'] = implode(',', $segList1);
  9052. }
  9053. if ($data['description'] == '') {
  9054. //提取内容中的描述
  9055. $content = $data['content'];
  9056. // 去除 <style> 和 <script> 标签及其内容
  9057. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9058. // 去除所有 HTML 标签
  9059. $content = strip_tags($content);
  9060. // 去除 HTML 实体
  9061. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9062. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9063. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9064. // 去除多余空白
  9065. $content = preg_replace('/\s+/u', '', $content);
  9066. // 截取 100 个字符
  9067. $data['description'] = mb_substr($content, 0, 100);
  9068. }
  9069. $data['level'] = empty($data['level']) ? null : $data['level'];
  9070. $data['province_id'] = empty($data['province_id']) ? null : $data['province_id'];
  9071. $data['city_id'] = empty($data['city_id']) ? null : $data['city_id'];
  9072. $data['due_time'] = empty($data['due_time']) ? null : $data['due_time'];
  9073. $users_id = empty($data['users_id']) ? null : $data['users_id'];
  9074. $id = $data['id'];
  9075. unset($data['users_id']);
  9076. unset($data['id']);
  9077. // return Result::success($data);
  9078. Db::beginTransaction();
  9079. try{
  9080. $result = ResearchTopic::where('id', $id)->update($data);
  9081. if (empty($result)) {
  9082. Db::rollBack();
  9083. return Result::error('编辑调研选题失败!');
  9084. }
  9085. $users = json_decode($users_id ?? '[]',true);
  9086. // return Result::success($users);
  9087. $retopic_users = RetopicUser::where('retopic_id', $id)->pluck('user_id')->toArray();
  9088. if(!empty($retopic_users)){
  9089. $del_users = RetopicUser::where('retopic_id', $id)->delete();
  9090. if(empty($del_users)){
  9091. Db::rollBack();
  9092. return Result::error('编辑同行人员失败!');
  9093. }
  9094. }
  9095. if(!empty($users)){
  9096. // 去重:确保同一 retopic_id + user_id 组合唯一
  9097. $users = array_values(array_unique($users));
  9098. // 组装关联数据
  9099. $users_topic = [];
  9100. foreach ($users as $key => $value) {
  9101. $users_topic[$key] = [
  9102. 'user_id' => $value,
  9103. 'retopic_id' => $id,
  9104. ];
  9105. }
  9106. // 使用 insertOrIgnore 忽略重复主键/唯一索引冲突
  9107. $retopic_user = RetopicUser::insert($users_topic);
  9108. if(empty($retopic_user)){
  9109. Db::rollBack();
  9110. return Result::error('编辑失败');
  9111. }
  9112. }
  9113. Db::commit();
  9114. return Result::success($result);
  9115. }catch(\Exception $e){
  9116. Db::rollBack();
  9117. return Result::error($e->getMessage());
  9118. }
  9119. }
  9120. /**
  9121. * 调研选题-删除
  9122. * @param array $data
  9123. * @return array
  9124. */
  9125. public function delResearchTopic(array $data): array
  9126. {
  9127. $user = User::where('id', $data['user_id'])->first();
  9128. if (empty($user)) {
  9129. return Result::error('用户不存在');
  9130. }
  9131. $topic = ResearchTopic::where('id', $data['id'])->first();
  9132. if (empty($topic)) {
  9133. return Result::error('此调研选题不存在');
  9134. }
  9135. Db::beginTransaction();
  9136. try{
  9137. $result = ResearchTopic::where('id', $data['id'])->delete();
  9138. if (empty($result)) {
  9139. Db::rollBack();
  9140. return Result::error('删除调研选题失败!');
  9141. }
  9142. $topic_users = RetopicUser::where('retopic_id', $data['id'])->pluck('user_id')->toArray();
  9143. if(!empty($topic_users)){
  9144. $del_topic_users = RetopicUser::where('retopic_id', $data['id'])->delete();
  9145. if(empty($del_topic_users)){
  9146. Db::rollBack();
  9147. return Result::error('删除同行人员失败!');
  9148. }
  9149. }
  9150. Db::commit();
  9151. return Result::success($result);
  9152. }catch(\Exception $e){
  9153. Db::rollBack();
  9154. return Result::error($e->getMessage());
  9155. }
  9156. }
  9157. /**
  9158. * 调研选题-列表
  9159. * @param array $data
  9160. * @return array
  9161. */
  9162. public function getResearchTopicList(array $data): array
  9163. {
  9164. $user = User::where('id', $data['user_id'])->first();
  9165. if (empty($user)) {
  9166. return Result::error('用户不存在!');
  9167. }
  9168. $where = [];
  9169. if($user->type_id != 10000){
  9170. $where['research_topic.user_id'] = $data['user_id'];
  9171. $website = Website::where('id', $data['website_id'])->first();
  9172. if (empty($website)) {
  9173. return Result::error('网站不存在!');
  9174. }
  9175. $web_column = json_decode($website->website_column_arr_id ?? '[]',true);
  9176. if(empty($web_column)){
  9177. return Result::error('网站未配置栏目!');
  9178. }
  9179. }
  9180. if($data['is_master'] != 0){
  9181. if($data['is_master'] == 3){
  9182. $where['research_topic.status'] = 0;
  9183. }else{
  9184. $where['research_topic.status'] = $data['is_master'];
  9185. }
  9186. }
  9187. if(!empty($data['title'])){
  9188. array_push($where, ['research_topic.title', 'like', '%'.$data['title'].'%']);
  9189. }
  9190. $page = $data['page'] ?? 1;
  9191. $page_size = $data['page_size'] ?? 10;
  9192. $research_topic = ResearchTopic::when($data['is_master'] == 0, function($query) use($data){
  9193. $query->whereIn('research_topic.status', [0,2]);
  9194. })
  9195. ->when(!empty($where), function($query) use($where){
  9196. $query->where($where);
  9197. })
  9198. ->with(['retopicUsers' => function ($query) {
  9199. $query->select('id', 'user_id', 'retopic_id');
  9200. }
  9201. ])
  9202. ->leftJoin('user', 'user.id', '=', 'research_topic.user_id')
  9203. ->select('research_topic.id','research_topic.title','research_topic.updated_at','research_topic.status',
  9204. 'research_topic.due_time','user.nickname')
  9205. ->orderBy('research_topic.updated_at', 'desc')
  9206. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  9207. if(empty($research_topic->items())){
  9208. return Result::error('暂无调研选题!');
  9209. }
  9210. $result = [
  9211. 'rows' => $research_topic->items(),
  9212. 'count' => $research_topic->total()
  9213. ];
  9214. foreach($result['rows'] as $key => $value){
  9215. if($user->type_id != 10000){
  9216. if(in_array($value['column_id'], $web_column)){
  9217. $result['rows'][$key]['is_update'] = 1;
  9218. }else{
  9219. $result['rows'][$key]['is_update'] = 0;
  9220. }
  9221. }
  9222. if(!empty($value['retopicUsers'])){
  9223. $retopic_users = $value['retopicUsers'];
  9224. $retopic_user = $retopic_users->pluck('user_id')->toArray();
  9225. $result['rows'][$key]['txry_users'] = implode(',', $retopic_user);
  9226. unset($result['rows'][$key]['retopicUsers']);
  9227. }
  9228. }
  9229. return Result::success($result);
  9230. }
  9231. /**
  9232. * 调研选题-修改状态
  9233. * @param array $data
  9234. * @return array
  9235. */
  9236. public function checkResearchTopic(array $data): array
  9237. {
  9238. $user = User::where('id', $data['user_id'])->first();
  9239. if (empty($user)) {
  9240. return Result::error('用户不存在!');
  9241. }
  9242. if($user->type_id != 10000 && ($data['status'] == 1 || $data['status'] == 2)){
  9243. return Result::error('此用户暂无权限!');
  9244. }
  9245. $topic = ResearchTopic::where('id', $data['id'])->first();
  9246. if (empty($topic)) {
  9247. return Result::error('此调研选题不存在');
  9248. }
  9249. $id = $data['id'];
  9250. unset($data['id']);
  9251. unset($data['user_id']);
  9252. $result = ResearchTopic::where('id', $id)->update($data);
  9253. if (empty($result)) {
  9254. return Result::error('修改调研选题状态失败!');
  9255. }
  9256. return Result::success($result);
  9257. }
  9258. /**
  9259. * 调研选题-详情
  9260. * @param array $data
  9261. * @return array
  9262. */
  9263. public function getResearchTopicInfo(array $data): array
  9264. {
  9265. $user = User::where('id', $data['user_id'])->first();
  9266. if (empty($user)) {
  9267. return Result::error('用户不存在!');
  9268. }
  9269. $research_topic = ResearchTopic::where('research_topic.id', $data['id'])
  9270. ->with(['retopicUsers' => function ($query) {
  9271. $query->select('user_id','retopic_id');
  9272. }
  9273. ])
  9274. ->leftJoin('user', 'user.id', '=', 'research_topic.user_id')
  9275. ->leftJoin('user_info', 'user_info.user_id', '=', 'research_topic.user_id')
  9276. ->select('research_topic.*','user_info.number')
  9277. ->first();
  9278. if(empty($research_topic)){
  9279. return Result::error('获取调研选题详情失败!');
  9280. }
  9281. $retopic_user = $research_topic['retopicUsers'];
  9282. if(!empty($retopic_user)){
  9283. $retopic_user = $retopic_user->pluck('user_id')->toArray();
  9284. foreach($retopic_user as $key => $value){
  9285. $real_name = UserInfo::where('user_id', $value)->value('real_name');
  9286. $research_topic['retopicUsers'][$key]['real_name'] = $real_name;
  9287. $research_topic['retopicUsers'][$key]['user_id'] = $value;
  9288. unset($research_topic['retopicUsers'][$key]['retopic_id']);
  9289. }
  9290. }
  9291. return Result::success($research_topic);
  9292. }
  9293. }