NewsService.php 312 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508
  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. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  70. class NewsService implements NewsServiceInterface
  71. {
  72. #[Inject]
  73. protected Redis $redis;
  74. /**
  75. * 获取导航池列表
  76. * @param array $data
  77. * @return array
  78. */
  79. public function getCategoryList(array $data): array
  80. {
  81. $search = $data['name'] ?? '';
  82. $page = (int)($data['page'] ?? 1);
  83. $perPage = (int)($data['pageSize'] ?? 10);
  84. // 1. 查出所有匹配的分类id
  85. if ($search) {
  86. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  87. if (empty($matchedIds)) {
  88. return Result::success(['rows' => [], 'total' => 0]);
  89. }
  90. // 2. 递归查所有父级,直到一级分类
  91. $idsStr = implode(',', $matchedIds);
  92. $sql = "
  93. WITH RECURSIVE parents AS (
  94. SELECT * FROM category WHERE id IN ($idsStr)
  95. UNION ALL
  96. SELECT c.* FROM category c
  97. INNER JOIN parents p ON c.id = p.pid
  98. )
  99. SELECT * FROM parents
  100. ";
  101. $parents = Db::select($sql);
  102. $parentIds = [];
  103. foreach ($parents as $row) {
  104. if ($row->pid == 0) {
  105. $parentIds[] = $row->id;
  106. }
  107. }
  108. $parentIds = array_unique($parentIds);
  109. } else {
  110. // 没有搜索,一级分类就是根
  111. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  112. }
  113. // 3. 一级分类分页
  114. $total = count($parentIds);
  115. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  116. if (empty($parentIds)) {
  117. return Result::success(['rows' => [], 'total' => $total]);
  118. }
  119. // 4. 递归查所有子孙
  120. $idsStr = implode(',', $parentIds);
  121. $sql = "
  122. WITH RECURSIVE subcategories AS (
  123. SELECT * FROM category WHERE id IN ($idsStr)
  124. UNION ALL
  125. SELECT c.* FROM category c
  126. INNER JOIN subcategories s ON c.pid = s.id
  127. )
  128. SELECT * FROM subcategories ORDER BY updated_at DESC
  129. ";
  130. $allCategories = Db::select($sql);
  131. // 5. 组装树结构
  132. $categoryMap = [];
  133. foreach ($allCategories as $cat) {
  134. $cat = (array)$cat;
  135. $cat['children'] = [];
  136. $categoryMap[$cat['id']] = $cat;
  137. }
  138. foreach ($categoryMap as $id => &$cat) {
  139. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  140. $categoryMap[$cat['pid']]['children'][] = &$cat;
  141. }
  142. }
  143. unset($cat);
  144. $categoryTree = [];
  145. foreach ($parentIds as $id) {
  146. if (isset($categoryMap[$id])) {
  147. $categoryTree[] = $categoryMap[$id];
  148. }
  149. }
  150. return Result::success([
  151. 'rows' => $categoryTree,
  152. 'total' => $total,
  153. ]);
  154. }
  155. private function findMatchedCategories($search)
  156. {
  157. if ($search) {
  158. return Category::where('name', 'like', "%{$search}%")
  159. ->orderBy('updated_at', 'desc')
  160. ->get();
  161. }
  162. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  163. ->get();
  164. }
  165. private function findAllParents($categories)
  166. {
  167. $allCategories = [];
  168. foreach ($categories as $category) {
  169. $parentId = $category->pid;
  170. while ($parentId > 0) {
  171. $parent = Category::find($parentId);
  172. if ($parent) {
  173. $allCategories[$parent->id] = $parent;
  174. $parentId = $parent->pid;
  175. } else {
  176. break;
  177. }
  178. }
  179. $allCategories[$category->id] = $category;
  180. }
  181. return array_values($allCategories);
  182. }
  183. private function buildCategoryTree($category, $allRequiredCategories)
  184. {
  185. $categoryData = $category->toArray();
  186. $children = [];
  187. foreach ($allRequiredCategories as $c) {
  188. if ($c->pid === $category->id) {
  189. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  190. }
  191. }
  192. if (!empty($children)) {
  193. $categoryData['children'] = $children;
  194. }
  195. return $categoryData;
  196. }
  197. public function myCategoryList(array $data): array
  198. {
  199. $sszq = $data['sszq'] ?? '';
  200. unset($data['sszq']);
  201. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  202. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  203. $where[] = [
  204. 'pid',
  205. '=',
  206. $data['pid'],
  207. ];
  208. if (isset($data['name'])) {
  209. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  210. }
  211. var_dump($where);
  212. //根据分类id,从category表中取出分类信息
  213. $result = Category::where($where)
  214. ->whereIn('category.id', $catorytids)
  215. ->select('category.*', 'category.id as category_id')->get();
  216. if (empty($result)) {
  217. return Result::error("没有栏目数据");
  218. }
  219. return Result::success($result);
  220. }
  221. /**
  222. * @param array $data
  223. * @return array
  224. */
  225. public function categoryList(array $data): array
  226. {
  227. $where[] = [
  228. 'pid',
  229. '=',
  230. $data['pid']
  231. ];
  232. if (isset($data['name'])) {
  233. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  234. }
  235. var_dump($where);
  236. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  237. if (empty($result)) {
  238. return Result::error("没有栏目数据");
  239. }
  240. return Result::success($result);
  241. }
  242. /**
  243. * @param array $data
  244. * @return array
  245. */
  246. public function addCategory(array $data): array
  247. {
  248. if (isset($data['id'])) {
  249. unset($data['id']);
  250. }
  251. $id = Category::insertGetId($data);
  252. if (empty($id)) {
  253. return Result::error("添加失败");
  254. }
  255. return Result::success(['id' => $id]);
  256. }
  257. /**
  258. * @param array $data
  259. * @return array
  260. */
  261. public function delCategory(array $data): array
  262. {
  263. Db::beginTransaction();
  264. try {
  265. $categoryList = Category::where(['pid' => $data['id']])->get();
  266. if ($categoryList->toArray()) {
  267. Db::rollBack();
  268. return Result::error("分类下面有子分类不能删除");
  269. }
  270. $articleList = Article::where(['catid' => $data['id']])->get();
  271. if ($articleList->toArray()) {
  272. Db::rollBack();
  273. return Result::error("分类下面有资讯不能删除");
  274. }
  275. $result = Category::where($data)->delete();
  276. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  277. if (!$result) {
  278. Db::rollBack();
  279. return Result::error("删除失败");
  280. }
  281. Db::commit();
  282. return Result::success($result);
  283. } catch (\Exception $e) {
  284. Db::rollBack();
  285. return Result::error("删除失败" . $e->getMessage());
  286. }
  287. }
  288. /**
  289. * @param array $data
  290. * @return array
  291. */
  292. public function updateCategory(array $data): array
  293. {
  294. $where = [
  295. 'id' => $data['id'],
  296. ];
  297. $result = Category::where($where)->update($data);
  298. if ($result) {
  299. return Result::success($result);
  300. } else {
  301. return Result::error("更新失败");
  302. }
  303. }
  304. /**
  305. * 获取导航池信息
  306. * @param array $data
  307. * @return array
  308. */
  309. public function getCategoryInfo(array $data): array
  310. {
  311. $where = [
  312. 'id' => $data['id'],
  313. ];
  314. $result = Category::where($where)->first();
  315. if ($result) {
  316. return Result::success($result);
  317. } else {
  318. return Result::error("更新失败");
  319. }
  320. }
  321. public function getArticleCommend(array $data): array
  322. {
  323. $where = [
  324. 'website_id' => $data['website_id'],
  325. ];
  326. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  327. var_dump($ids);
  328. if (empty($ids)) {
  329. return Result::error("没有推荐数据");
  330. }
  331. //id
  332. $whereArticle = [];
  333. if (isset($data['id'])) {
  334. $whereArticle['id'] = $data['id'];
  335. }
  336. //title like
  337. if (isset($data['title'])) {
  338. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  339. }
  340. $article = Article::whereIn('catid', values: $ids)->where('status', 1)
  341. ->where($whereArticle)
  342. ->orderBy('id', 'desc')
  343. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  344. if ($article) {
  345. $data = [
  346. 'rows' => $article->items(),
  347. 'count' => $article->total(),
  348. ];
  349. return Result::success($data);
  350. } else {
  351. return Result::error("获取失败失败");
  352. }
  353. }
  354. /**
  355. * @param array $data
  356. * @return array
  357. */
  358. public function getArticleList(array $data): array
  359. {
  360. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  361. $type_id = $data['type_id'];
  362. unset($data['type_id']);
  363. $user_id = $data['user_id'];
  364. unset($data['user_id']);
  365. $where = [];
  366. $status1 = [];
  367. if (isset($data['id']) && $data['id']) {
  368. array_push($where, ['article.id', '=', $data['id']]);
  369. }
  370. if (isset($data['title']) && $data['title']) {
  371. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  372. }
  373. if (isset($data['category_name']) && $data['category_name']) {
  374. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  375. }
  376. if (isset($data['catid']) && $data['catid']) {
  377. array_push($where, ['article.catid', '=', $data['catid']]);
  378. }
  379. if (isset($data['author']) && $data['author']) {
  380. array_push($where, ['article.author', '=', $data['author']]);
  381. }
  382. if (isset($data['islink']) && $data['islink'] !== "") {
  383. array_push($where, ['article.islink', '=', $data['islink']]);
  384. }
  385. if (isset($data['status']) && $data['status'] !== "") {
  386. array_push($where, ['article.status', '=', $data['status']]);
  387. }
  388. if (isset($data['status1'])) {
  389. $status1 = json_decode(($data['status1']));
  390. }
  391. //不是管理员展示个人数据;
  392. if ($type_id != 10000) {
  393. $where[] = ['article.admin_user_id', '=', $user_id];
  394. }
  395. // $rep = Article::where($where)
  396. // ->whereNotIn('article.status', [404])
  397. // ->when($status1, function ($query) use ($status1) {
  398. // if (isset($status1) && $status1) {
  399. // $query->whereIn('article.status', $status1);
  400. // }
  401. // })
  402. // ->leftJoin('category', 'article.catid', 'category.id')
  403. // ->leftJoin('website_category', function ($join) {
  404. // $join->on('article.web_site_id', '=', 'website_category.website_id')
  405. // ->on('article.catid', '=', 'website_category.category_id');
  406. // })
  407. // ->when($type_id != 10000 && !empty($data['website_id']), function ($query) use ($data) {
  408. // $query->leftJoin('article_ignore', function ($join) use ($data) {
  409. // $join->on('article.id', '=', 'article_ignore.article_id')
  410. // ->where('article_ignore.website_id', $data['website_id']);
  411. // });
  412. // })
  413. // ->select("article.*", "category.name as category_name", "website_category.alias",
  414. // Db::raw('IFNULL(article_ignore.c_show_time, "") as c_show_time'))
  415. // ->orderBy("article.updated_at", "desc")
  416. // ->limit($data['pageSize'])
  417. // ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  418. //
  419. $query = Article::where($where)
  420. ->whereNotIn('article.status', [404])
  421. ->when($status1, function ($query) use ($status1) {
  422. if (isset($status1) && $status1) {
  423. $query->whereIn('article.status', $status1);
  424. }
  425. })
  426. ->leftJoin('category', 'article.catid', 'category.id')
  427. ->leftJoin('website_category', function ($join) {
  428. $join->on('article.web_site_id', '=', 'website_category.website_id')
  429. ->on('article.catid', '=', 'website_category.category_id');
  430. });
  431. if ($type_id != 10000 && !empty($data['website_id'])) {
  432. $query = $query
  433. ->leftJoin('article_ignore', function ($join) use ($data) {
  434. $join->on('article.id', '=', 'article_ignore.article_id')
  435. ->where('article_ignore.website_id', $data['website_id']);
  436. })
  437. ->select("article.*", "category.name as category_name", "website_category.alias",'article_ignore.c_show_time');
  438. } else {
  439. $query = $query
  440. ->select("article.*", "category.name as category_name", "website_category.alias");
  441. }
  442. $rep = $query
  443. ->orderBy("article.updated_at", "desc")
  444. ->limit($data['pageSize'])
  445. ->offset(($data['page'] - 1) * $data['pageSize'])
  446. ->get();
  447. $count = $query->count();
  448. $data = [
  449. 'rows' => $rep->toArray(),
  450. 'count' => $count,
  451. ];
  452. if (empty($rep)) {
  453. return Result::error("没有信息数据");
  454. }
  455. return Result::success($data);
  456. }
  457. /**
  458. * @param array $data
  459. * @return array
  460. */
  461. public function addArticle(array $data): array
  462. {
  463. var_dump($data, '----------12-----------1');
  464. // ------c_show_time********add***1****
  465. $is_collect = $data['is_collect'] ?? 0;
  466. $user_type = $data['user_type'];
  467. unset($data['is_collect']);
  468. unset($data['user_type']);
  469. // ------c_show_time********add***1****
  470. unset($data['nav_add_pool_id']);
  471. // unset($data['commend_id']);
  472. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  473. Db::beginTransaction();
  474. try {
  475. //处理投票
  476. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  477. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  478. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  479. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  480. unset($data['is_survey']);
  481. unset($data['survey_name']);
  482. unset($data['suvey_array']);
  483. unset($data['website_id']);
  484. unset($data['web_site_id']);
  485. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  486. if ($data['hits'] == '') {
  487. $data['hits'] = 0;
  488. }
  489. if ($data['is_original'] == '') {
  490. $data['is_original'] = 0;
  491. }
  492. if ($data['status'] == '') {
  493. $data['status'] = 0;
  494. }
  495. $articleData = $data;
  496. unset($articleData['content']);
  497. //自动处理缩略图、关键字、描述
  498. if ($articleData['imgurl'] == '') {
  499. //如果没有图,设置level=0
  500. $levelArr = json_decode($articleData['level'], true);
  501. var_dump($levelArr, '----------levelArr-----------1');
  502. //content中提取图片第一个图,正则提取
  503. // -------采集器相关优化-----
  504. // 优化正则表达式,仅匹配 src 属性值,避免匹配到多余内容
  505. if($is_collect == 1){
  506. $reg = '/<img.*?src=[\'"]?((?!.*\.gif)[^\'" >]+)[\'"]?.*?>/i';
  507. }else{
  508. $reg = '/<img.*?src=[\'"]?([^\'" >]+)[\'"]?.*?>/i';
  509. }
  510. // -------采集器相关优化-----
  511. preg_match_all($reg, $data['content'], $matches);
  512. if (isset($matches[1][0])) {
  513. //截取varchar240
  514. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  515. //如果有图,设置level=3
  516. if (!in_array(3, $levelArr)) {
  517. $levelArr[] = 3;
  518. }
  519. $articleData['level'] = json_encode($levelArr);
  520. } else {
  521. if (!in_array(0, $levelArr)) {
  522. $levelArr[] = 0;
  523. }
  524. $articleData['level'] = json_encode($levelArr);
  525. }
  526. }
  527. var_dump($articleData['level'], '----------$articleData[level]----------1');
  528. if ($articleData['keyword'] == '') {
  529. //提取标题+内容中的关键词
  530. $articleData['keyword'] = $data['title'];
  531. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  532. Jieba::init(); // 初始化 jieba-php
  533. Finalseg::init();
  534. $segList = Jieba::cut($articleData['keyword']);
  535. $segList1 = array_slice($segList, 0, 8);
  536. $articleData['keyword'] = implode(',', $segList1);
  537. }
  538. if ($articleData['introduce'] == '') {
  539. //提取内容中的描述
  540. $content = $data['content'];
  541. // 去除 <style> 和 <script> 标签及其内容
  542. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  543. // 去除所有 HTML 标签
  544. $content = strip_tags($content);
  545. // 去除 HTML 实体
  546. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  547. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  548. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  549. // 去除多余空白
  550. $content = preg_replace('/\s+/u', '', $content);
  551. // 截取 100 个字符
  552. $articleData['introduce'] = mb_substr($content, 0, 100);
  553. }
  554. if ($articleData['status'] == 0) {
  555. $this->sendMessage([
  556. 'talk_type' => 100,
  557. 'title' => $articleData['title'],
  558. 'content' => '提交了审核',
  559. 'messageType' => 2,
  560. ]);
  561. }
  562. $id = Article::insertGetId($articleData);
  563. if (!$id) {
  564. throw new \Exception('文章插入失败');
  565. }
  566. $articleDataContent = [
  567. 'article_id' => $id,
  568. 'content' => $data['content'],
  569. ];
  570. $contentInsertId = ArticleData::insertGetId($articleDataContent);
  571. if (!$contentInsertId) {
  572. throw new \Exception('文章内容插入失败');
  573. }
  574. // ------c_show_time********add***2****
  575. // 直接使用当前系统时间,不再强制添加8小时
  576. $now = date('Y-m-d H:i:s');
  577. if($user_type == 10000 || $is_collect == 1){
  578. // 管理员添加文章时,核心站c端显示时间就是创建时间;非核心站c端显示时间就是此创建时间往后推二十分钟;
  579. // 非管理员添加文章时,不做操作只有在审核通过时获取c端显示时间
  580. if (!isset($data['catid'])) {
  581. throw new \Exception('缺少必要字段:catid');
  582. }
  583. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  584. $web = WebsiteCategory::where('category_id', $data['catid'])
  585. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  586. ->select('website_id',
  587. 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'))
  588. ->get();
  589. // $id = 225; -----测试开启
  590. // 采集来的文章,错开时间在两小时之内发布
  591. if($user_type == 10000 && $is_collect == 1){
  592. $web_num = $web->where('is_core', '!=', 2)->count();
  593. $waiting_interval = 10;
  594. if($web_num > 12){
  595. // 若网站数量大于12个,则每个网站间隔时间取均值
  596. // 防止除数为 0,虽然这里 $web_num 是 count 结果不会为 0,但做健壮性检查
  597. $waiting_interval = 120 / max(1, $web_num);
  598. }
  599. $time = 0;
  600. }else{
  601. // 非核心站与核心站----显示时间-----间隔
  602. $time = 20;
  603. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  604. $waiting_interval = 5;
  605. }
  606. // 将 Hyperf\Database\Model\Collection 转换为数组
  607. $webArray = $web->toArray();
  608. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $id, $waiting_interval, $is_collect) {
  609. // 检查 $item 对象是否有 is_core 属性
  610. if (!isset($item['is_core'])) {
  611. throw new \Exception('$item 对象缺少 is_core 属性');
  612. }
  613. // 当 is_core 为 2 时,则表示此网站不存在
  614. if ($item['is_core'] == 2) {
  615. return null;
  616. }
  617. if($is_collect == 1){
  618. // 采集来的文章,错开时间在两小时之内发布
  619. // $time = 0;
  620. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  621. $time += $waiting_interval;
  622. }else if($item['is_core'] == 1){
  623. // 当 is_core 为 1 时,则表示此网站是核心站
  624. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  625. }else{
  626. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  627. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  628. if ($item['is_core'] == 0) {
  629. $time += $waiting_interval;
  630. }
  631. }
  632. return [
  633. 'article_id' => $id,
  634. 'website_id' => $item['website_id'],
  635. 'c_show_time' => $c_show_time,
  636. // 'is_core' => $item['is_core'],
  637. // 'time' => $time
  638. ];
  639. }, array_keys($webArray), $webArray)));
  640. // Db::commit();
  641. // return Result::success($article_ignore);
  642. if(!empty($article_ignore)){
  643. $article_ignores = ArticleIgnore::insert($article_ignore);
  644. if(!$article_ignores){
  645. throw new \Exception('c端展示时间插入失败');
  646. }
  647. }
  648. }
  649. // ------c_show_time********add***2****
  650. //处理投票
  651. if ($is_survey == 1) {
  652. //生成年月日时分秒+8位随机数
  653. $uuid = date('YmdHis') . rand(10000000, 99999999);
  654. var_dump($suvey_array, 'suvey_array________');
  655. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  656. var_dump($suveys_array, '---------------------1');
  657. var_dump($suvey_array, '---------------------2');
  658. $suvey_data = [];
  659. foreach ($suveys_array as $key => $value) {
  660. if ($value == '') {
  661. continue;
  662. }
  663. if (is_array($value)) {
  664. $suvey_data[] = [
  665. 'sur_id' => $uuid,
  666. 'art_id' => $id,
  667. 'website_id' => $website_id ?? 2,
  668. 'survey_name' => $survey_name,
  669. 'choice_name' => $value[1],
  670. 'is_other' => 1,
  671. 'other_id' => 0,
  672. 'results' => 0,
  673. ];
  674. } else {
  675. $suvey_data[] = [
  676. 'sur_id' => $uuid,
  677. 'art_id' => $id,
  678. 'website_id' => $website_id ?? 2,
  679. 'survey_name' => $survey_name,
  680. 'choice_name' => $value,
  681. 'is_other' => 0,
  682. 'other_id' => 0,
  683. 'results' => 0,
  684. ];
  685. }
  686. if (empty($suvey_data)) {
  687. throw new \Exception("投票数据为空");
  688. }
  689. }
  690. $result = ArticleSurvey::insert($suvey_data);
  691. if (!$result) {
  692. throw new \Exception("投票失败,ArticleSurvey插入失败");
  693. }
  694. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  695. if (!$result) {
  696. throw new \Exception("投票失败,更新主表失败");
  697. }
  698. }
  699. Db::commit();
  700. return Result::success(['id' => $id]);
  701. } catch (\Throwable $ex) {
  702. Db::rollBack();
  703. var_dump($ex->getMessage());
  704. return Result::error("创建失败", 0);
  705. }
  706. }
  707. /**
  708. * @param array $data
  709. * @return array
  710. */
  711. public function delArticle(array $data): array
  712. {
  713. // ------c_show_time********del*******
  714. Db::beginTransaction();
  715. try{
  716. $article = Article::where(['id' => $data['id']])->delete();
  717. // 若文章删除失败,抛出异常,后续 SQL 语句不会执行
  718. if (!$article) {
  719. throw new \Exception("删除失败,文章删除失败");
  720. }
  721. //survey投票删除
  722. ArticleSurvey::where(['art_id' => $data['id']])->delete(); // 修正类名大小写
  723. $articleIgnore = ArticleIgnore::where(['article_id' => $data['id']])->delete();
  724. $article_data = ArticleData::where(['article_id' => $data['id']])->delete();
  725. // 若文章详情删除失败,抛出异常
  726. if (!$article_data) {
  727. throw new \Exception("删除失败,文章详情删除失败");
  728. }
  729. Db::commit(); // 所有操作成功,提交事务
  730. }catch (\Throwable $ex) {
  731. Db::rollBack();
  732. var_dump($ex->getMessage());
  733. return Result::error("删除失败: " . $ex->getMessage(), 0);
  734. }
  735. // ------c_show_time********del*******
  736. if (!$article) {
  737. return Result::error("删除失败");
  738. }
  739. return Result::success($article);
  740. }
  741. /**
  742. * @param array $data
  743. * @return array
  744. */
  745. public function updateArticle(array $data): array
  746. {
  747. var_dump($data, '----------12-----------1');
  748. Db::beginTransaction();
  749. // ------c_show_time********up*******
  750. $user_type = isset($data['user_type']) ? $data['user_type'] : 0;
  751. // 无论是否改变了c端显示时间或者栏目,都需要将未屏蔽的网站显示时间删除记录
  752. // 若是存在交集,则进行修改,若无,则合并(此表中的记录应该包含被屏蔽网站及涉及所有网站的展示时间)
  753. $web = WebsiteCategory::where('category_id', $data['catid'])
  754. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  755. ->select('website_id',
  756. 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'))
  757. ->get();
  758. // 根据错误信息,问题在于 $web 可能是一个包含对象的集合,不能直接用于 whereNotIn 方法
  759. // 先从 $web 集合中提取 website_id 字段的值,再进行删除操作
  760. $websiteIds = $web->pluck('website_id')->toArray();
  761. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  762. if($user_type == 0){
  763. throw new \Exception("用户类型不能为空");
  764. }
  765. if($user_type == 10000 ){
  766. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  767. $web = WebsiteCategory::where('category_id', $data['catid'])
  768. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  769. ->select('website_id',
  770. 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'))
  771. ->get();
  772. // 非核心站与核心站----显示时间-----间隔
  773. $time = 20;
  774. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  775. $waiting_interval = 5;
  776. $webArray = $web->toArray();
  777. if(empty($webArray)){
  778. throw new \Exception('网站分类不存在');
  779. }
  780. // 直接使用当前系统时间,不再强制添加8小时
  781. $now = date('Y-m-d H:i:s');
  782. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  783. // 检查 $item 对象是否有 is_core 属性
  784. if (!isset($item['is_core'])) {
  785. throw new \Exception('$item 对象缺少 is_core 属性');
  786. }
  787. // 当 is_core 为 2 时,则表示此网站不存在
  788. if ($item['is_core'] == 2) {
  789. return null;
  790. }else if($item['is_core'] == 1){
  791. // 当 is_core 为 1 时,则表示此网站是核心站
  792. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  793. }else{
  794. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  795. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  796. if ($item['is_core'] == 0) {
  797. $time += $waiting_interval;
  798. }
  799. }
  800. return [
  801. 'article_id' => $data['id'],
  802. 'website_id' => $item['website_id'],
  803. 'c_show_time' => $c_show_time,
  804. ];
  805. }, array_keys($webArray), $webArray)));
  806. if(!empty($article_ignore)){
  807. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  808. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  809. $article_ignores = ArticleIgnore::upsert(
  810. $article_ignore,
  811. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  812. ['c_show_time'] // 需要更新的字段
  813. );
  814. if(!$article_ignores){
  815. throw new \Exception('c端展示时间插入失败');
  816. }
  817. }
  818. // Db::commit();
  819. // return Result::success($article_ignore);
  820. }
  821. // ------c_show_time********up*******
  822. unset($data['user_type']);
  823. // unset($data['web_site_id']);
  824. unset($data['nav_add_pool_id']);
  825. try {
  826. //处理投票
  827. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  828. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  829. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  830. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  831. unset($data['is_survey']);
  832. unset($data['survey_name']);
  833. unset($data['suvey_array']);
  834. unset($data['website_id']);
  835. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  836. if ($data['hits'] == '') {
  837. $data['hits'] = 0;
  838. }
  839. if ($data['is_original'] == '') {
  840. $data['is_original'] = 0;
  841. }
  842. if ($data['status'] == '') {
  843. $data['status'] = 0;
  844. }
  845. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  846. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  847. $articleData = $data;
  848. unset($articleData['content']);
  849. unset($articleData['status_name']);
  850. unset($articleData['name']);
  851. unset($articleData['content']);
  852. unset($articleData['pid_arr']);
  853. unset($articleData['pid']);
  854. //自动处理缩略图、关键字、描述
  855. if ($articleData['imgurl'] == '') {
  856. //如果没有图,设置level=0
  857. $levelArr = json_decode($articleData['level'], true);
  858. var_dump($levelArr, '----------levelArr-----------1');
  859. //content中提取图片第一个图,正则提取
  860. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  861. preg_match_all($reg, $data['content'], $matches);
  862. if (isset($matches[1][0])) {
  863. //截取varchar240
  864. // 截取到第一个<
  865. $articleData['imgurl'] = $matches[1][0];
  866. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  867. $pos = strpos($articleData['imgurl'], '"');
  868. if ($pos !== false) {
  869. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  870. }
  871. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  872. //如果有图,设置level=3
  873. if (!in_array(3, $levelArr)) {
  874. $levelArr[] = 3;
  875. }
  876. $articleData['level'] = json_encode($levelArr);
  877. } else {
  878. if (!in_array(0, $levelArr)) {
  879. $levelArr[] = 0;
  880. }
  881. $articleData['level'] = json_encode($levelArr);
  882. }
  883. }
  884. var_dump($articleData['level'], '----------$articleData[level]----------1');
  885. if ($articleData['keyword'] == '') {
  886. //提取标题+内容中的关键词
  887. $articleData['keyword'] = $data['title'];
  888. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  889. Jieba::init(); // 初始化 jieba-php
  890. Finalseg::init();
  891. $segList = Jieba::cut($articleData['keyword']);
  892. $segList1 = array_slice($segList, 0, 8);
  893. $articleData['keyword'] = implode(',', $segList1);
  894. }
  895. if ($articleData['introduce'] == '') {
  896. //提取内容中的描述
  897. $content = $data['content'];
  898. // 去除 <style> 和 <script> 标签及其内容
  899. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  900. // 去除所有 HTML 标签
  901. $content = strip_tags($content);
  902. // 去除 HTML 实体
  903. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  904. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  905. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  906. // 去除多余空白
  907. $content = preg_replace('/\s+/u', '', $content);
  908. // 截取 100 个字符
  909. $articleData['introduce'] = mb_substr($content, 0, 100);
  910. }
  911. if ($articleData['status'] == 0) {
  912. $this->sendMessage([
  913. 'talk_type' => 100,
  914. 'title' => $articleData['title'],
  915. 'content' => '提交了审核',
  916. 'messageType' => 2,
  917. ]);
  918. }
  919. $id = Article::where(['id' => $data['id']])->update($articleData);
  920. $articleDataContent = [
  921. 'content' => $data['content'],
  922. ];
  923. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  924. //处理投票
  925. $id = $data['id'];
  926. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  927. var_dump($suvey_array, 'suvey_array________delete');
  928. //处理投票
  929. if ($is_survey == 1) {
  930. //生成年月日时分秒+8位随机数
  931. $uuid = date('YmdHis') . rand(10000000, 99999999);
  932. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  933. var_dump($suveys_array, '---------------------1');
  934. $suvey_data = [];
  935. if (is_array($suveys_array)) {
  936. foreach ($suveys_array as $key => $value) {
  937. if ($value == '') {
  938. continue;
  939. }
  940. if (is_array($value)) {
  941. $suvey_data[] = [
  942. 'sur_id' => $uuid,
  943. 'art_id' => $id,
  944. 'website_id' => $website_id ?? 2,
  945. 'survey_name' => $survey_name,
  946. 'choice_name' => $value[1],
  947. 'is_other' => 1,
  948. 'other_id' => 0,
  949. 'results' => 0,
  950. ];
  951. } else {
  952. $suvey_data[] = [
  953. 'sur_id' => $uuid,
  954. 'art_id' => $id,
  955. 'website_id' => $website_id ?? 2,
  956. 'survey_name' => $survey_name,
  957. 'choice_name' => $value,
  958. 'is_other' => 0,
  959. 'other_id' => 0,
  960. 'results' => 0,
  961. ];
  962. }
  963. if (empty($suvey_data)) {
  964. throw new \Exception("投票数据为空");
  965. }
  966. }
  967. }
  968. $result = ArticleSurvey::insert($suvey_data);
  969. if (!$result) {
  970. throw new \Exception("投票失败");
  971. }
  972. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  973. if (!$result) {
  974. throw new \Exception("投票失败");
  975. }
  976. } else {
  977. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  978. }
  979. Db::commit();
  980. return Result::success([]);
  981. } catch (\Throwable $ex) {
  982. Db::rollBack();
  983. var_dump($ex->getMessage());
  984. return Result::error("更新失败" . $ex->getMessage(), 0);
  985. }
  986. }
  987. /**
  988. * 更新资讯状态
  989. * @param array $data
  990. * @return array
  991. */
  992. public function upArticleStatus(array $data): array
  993. {
  994. $articleData = Article::where(['id' => $data['id']])->first();
  995. //发送10次
  996. // for ($i = 0; $i < 10; $i++) {
  997. // $this->sendMessage([
  998. // 'talk_type' => 100,
  999. // 'title' => $i . $articleData['title'],
  1000. // 'content' => '审核通过',
  1001. // 'messageType' => 2,
  1002. // 'user_id' => $articleData['admin_user_id'],
  1003. // ]);
  1004. // }
  1005. // var_dump($data['status'], 'status');
  1006. // return Result::success();
  1007. if ($data['status'] == 1) {
  1008. $this->sendMessage([
  1009. 'talk_type' => 101,
  1010. 'title' => $articleData['title'],
  1011. 'content' => '审核通过',
  1012. 'messageType' => 2,
  1013. 'user_id' => $articleData['admin_user_id'],
  1014. ]);
  1015. }
  1016. if ($data['status'] == 2) {
  1017. $this->sendMessage([
  1018. 'talk_type' => 101,
  1019. 'title' => $articleData['title'],
  1020. 'content' => '审核拒绝',
  1021. 'messageType' => 2,
  1022. 'user_id' => $articleData['admin_user_id'],
  1023. ]);
  1024. }
  1025. if ($data['status'] == 0) {
  1026. $this->sendMessage([
  1027. 'talk_type' => 100,
  1028. 'title' => $articleData['title'],
  1029. 'content' => '提交了审核',
  1030. 'messageType' => 2,
  1031. ]);
  1032. }
  1033. $result = Article::where(['id' => $data['id']])->update($data);
  1034. if (isset($data['ignore_ids']) && !empty($data['ignore_ids'])) {
  1035. //article_ignore 表插入数据 db操作
  1036. //转成数组
  1037. //删掉数据重新写入
  1038. // DB::table('article_ignore')->where('article_id', $data['id'])->delete();
  1039. $website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  1040. // $insert_data = [];
  1041. // foreach ($website_ids as $key => $value) {
  1042. // $insert_data[] = [
  1043. // 'article_id' => $data['id'],
  1044. // 'website_id' => $value,
  1045. // 'is_ignore' => 1
  1046. // ];
  1047. // }
  1048. DB::table('article_ignore')->where('article_id', $data['id'])->whereIn('website_id',$website_ids)->update(['is_ignore' => 1]);
  1049. }else{
  1050. // ------c_show_time********up_status*******
  1051. // 若是审核通过 则更新c_show_time
  1052. if($data['status'] == 1){
  1053. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  1054. $web = Article::where('article.id',$data['id'])
  1055. ->leftJoin('website_category','article.catid','website_category.category_id')
  1056. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  1057. ->select('website_id',
  1058. 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'))
  1059. ->get();
  1060. // 非核心站与核心站----显示时间-----间隔
  1061. $time = 20;
  1062. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  1063. $waiting_interval = 5;
  1064. $webArray = $web->toArray();
  1065. if(empty($webArray)){
  1066. throw new \Exception('网站分类不存在');
  1067. }
  1068. // 直接使用当前系统时间,不再强制添加8小时
  1069. $now = date('Y-m-d H:i:s');
  1070. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  1071. // 检查 $item 对象是否有 is_core 属性
  1072. if (!isset($item['is_core'])) {
  1073. throw new \Exception('$item 对象缺少 is_core 属性');
  1074. }
  1075. // 当 is_core 为 2 时,则表示此网站不存在
  1076. if ($item['is_core'] == 2) {
  1077. return null;
  1078. }else if($item['is_core'] == 1){
  1079. // 当 is_core 为 1 时,则表示此网站是核心站
  1080. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  1081. }else{
  1082. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  1083. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  1084. if ($item['is_core'] == 0) {
  1085. $time += $waiting_interval;
  1086. }
  1087. }
  1088. return [
  1089. 'article_id' => $data['id'],
  1090. 'website_id' => $item['website_id'],
  1091. 'c_show_time' => $c_show_time,
  1092. ];
  1093. }, array_keys($webArray), $webArray)));
  1094. if(!empty($article_ignore)){
  1095. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  1096. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  1097. $article_ignores = ArticleIgnore::upsert(
  1098. $article_ignore,
  1099. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1100. ['c_show_time'] // 需要更新的字段
  1101. );
  1102. if(!$article_ignores){
  1103. throw new \Exception('c端展示时间插入失败');
  1104. }
  1105. }
  1106. }
  1107. // ------c_show_time********up_status*******
  1108. }
  1109. if ($result) {
  1110. return Result::success();
  1111. } else {
  1112. return Result::error("更新状态失败", 0);
  1113. }
  1114. }
  1115. /**
  1116. * 获取新闻详情
  1117. * @param array $data
  1118. * @return array
  1119. */
  1120. public function getArticleInfo(array $data): array
  1121. {
  1122. $where = [
  1123. 'article.id' => $data['id'],
  1124. // 'article.status' => 1,
  1125. ];
  1126. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  1127. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  1128. $info = $result;
  1129. // var_dump($info, 'info');
  1130. $info['survey_array'] = $articleSurvey;
  1131. if ($result) {
  1132. return Result::success($info);
  1133. } else {
  1134. return Result::error("查询失败", 0);
  1135. }
  1136. }
  1137. /**
  1138. * 获取头条新闻
  1139. * @param array $data
  1140. * @return array
  1141. */
  1142. public function getWebsiteArticlett(array $data): array
  1143. {
  1144. $website_id = $data['website_id'];
  1145. $website = Website::where('id', $data['website_id'])->first();
  1146. if (empty($website)) {
  1147. return Result::error("网站不存在", 0);
  1148. }
  1149. $categorys = $this->processArticlePro($website_id);
  1150. $catiall = $categorys['catiall'];
  1151. $categoryIds = $categorys['categoryIds'];
  1152. $where = [
  1153. 'status' => 1
  1154. ];
  1155. // $website_column = $website['column'];
  1156. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1157. $website_column = json_decode($website['website_column_arr_id'], true);
  1158. }
  1159. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1160. // return Result::success($diff_pid_categoryIds);
  1161. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1162. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1163. }
  1164. // $website_id = $data['website_id'];
  1165. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  1166. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  1167. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  1168. switch ($data['level']) {
  1169. case 1:
  1170. case 2:
  1171. case 3:
  1172. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  1173. $query = Article::where($where)
  1174. ->where('level', 'like', '%' . $data['level'] . '%')
  1175. ->orderBy('updated_at', 'desc');
  1176. break;
  1177. case 4: //最新资讯
  1178. $query = Article::where($where)->orderBy('updated_at', 'desc');
  1179. break;
  1180. case 5: //资讯推荐
  1181. $query = Article::where($where)
  1182. ->where('updated_at', '>', $month);
  1183. break;
  1184. case 7: //资讯分类
  1185. if (isset($data['id']) && !empty($data['id'])) {
  1186. $keyword = Article::where('id', $data['id'])->value('keyword');
  1187. $keywordArray = explode(',', $keyword);
  1188. $whereL7 = [];
  1189. foreach ($keywordArray as $k => $v) {
  1190. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1191. }
  1192. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  1193. break;
  1194. } else {
  1195. return Result::error("请输入资讯ID", 0);
  1196. break;
  1197. }
  1198. default:
  1199. break;
  1200. }
  1201. // $whereL7 = [];
  1202. // if(isset($data['id']) && !empty($data['id'])){
  1203. // $keyword = Article::where('id', $data['id'])->value('keyword');
  1204. // $keywordArray = explode(',', $keyword);
  1205. // foreach ($keywordArray as $k => $v) {
  1206. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1207. // }
  1208. // }
  1209. // $query = Article::where($where)
  1210. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  1211. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  1212. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  1213. // }
  1214. // if($data['level'] == 7){
  1215. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  1216. // }
  1217. // if($data['level'] == 4){
  1218. // $query = $query->inRandomOrder()
  1219. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  1220. // }
  1221. // if($data['level'] == 5){
  1222. // $query = $query->orderBy('updated_at','desc');
  1223. // }
  1224. // });
  1225. if ($data['textnum'] > 0) {
  1226. $query = clone $query;
  1227. $result['text'] = $query
  1228. ->whereIn('catid', $categoryIds)
  1229. ->leftJoinSub(function ($query) use ($website_id) {
  1230. $query->from('article_ignore')
  1231. ->where('website_id', $website_id);
  1232. }, 'article_ignore', function ($join) {
  1233. $join->on('article_ignore.article_id', '=', 'article.id');
  1234. })
  1235. ->where(function ($query) {
  1236. $query->whereNull('article_ignore.article_id')
  1237. ->orWhere(function ($subQuery) {
  1238. $subQuery->whereNotNull('article_ignore.article_id')
  1239. ->where('article_ignore.is_ignore', 0)
  1240. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1241. });
  1242. })
  1243. // ->where(function ($query) use ($website_id) {
  1244. // $query->whereNull('article_ignore.article_id')
  1245. // ->orWhere('article_ignore.website_id', '!=', $website_id);
  1246. // })
  1247. ->select(
  1248. 'article.id',
  1249. 'article.title',
  1250. 'article.author',
  1251. 'article.updated_at',
  1252. 'article.introduce',
  1253. 'article.islink',
  1254. 'article.linkurl',
  1255. 'article.copyfrom',
  1256. 'article.cat_arr_id',
  1257. 'article.catid',
  1258. 'article.level',
  1259. // 'article_ignore.is_ignore',
  1260. // 'article_ignore.c_show_time',
  1261. )
  1262. ->offset($data['placeid'])
  1263. ->limit($data['textnum'])
  1264. ->get()->all();
  1265. foreach ($result['text'] as $k => $v) {
  1266. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1267. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  1268. }
  1269. }
  1270. if ($data['imgnum'] > 0) {
  1271. $query = clone $query;
  1272. $result['img'] = $query
  1273. ->whereIn('catid', $categoryIds)
  1274. ->where('article.imgurl', '!=', '')
  1275. ->select(
  1276. 'article.id',
  1277. 'article.title',
  1278. 'article.imgurl',
  1279. 'article.author',
  1280. 'article.updated_at',
  1281. 'article.introduce',
  1282. 'article.islink',
  1283. 'article.linkurl',
  1284. 'article.copyfrom',
  1285. 'article.cat_arr_id',
  1286. 'article.catid',
  1287. 'article.level',
  1288. // 'article_ignore.is_ignore',
  1289. // 'article_ignore.c_show_time',
  1290. )
  1291. ->offset($data['placeid'])
  1292. ->limit($data['imgnum'])
  1293. ->get()->all();
  1294. foreach ($result['img'] as $k => $v) {
  1295. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1296. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1297. }
  1298. }
  1299. if (empty($result)) {
  1300. return Result::error("暂无相关资讯", 0);
  1301. }
  1302. return Result::success($result);
  1303. }
  1304. /**
  1305. * 获取模块新闻
  1306. * @param array $data
  1307. * @return array
  1308. */
  1309. public function getWebsiteModelArticles(array $data): array
  1310. {
  1311. $catid = $data['catid'];
  1312. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1313. $category = $category->toArray();
  1314. if (!empty($category)) {
  1315. $where = [
  1316. 'status' => 1,
  1317. 'catid' => $catid,
  1318. ];
  1319. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1320. // 1:文字新闻;2:轮播图;3:图文;
  1321. // 级别:0:未分类
  1322. // 3:推荐图片
  1323. if ($data['level'] == 1) {
  1324. $data['level'] = 0;
  1325. }
  1326. $result = Article::where($where)
  1327. ->where(function ($query) use ($data) {
  1328. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1329. ->orWhereNull("level")
  1330. ->orWhereRaw("level = '[]'");
  1331. })
  1332. ->leftJoinSub(function ($query) use ($data) {
  1333. $query->from('article_ignore')
  1334. ->where('website_id', $data['website_id']);
  1335. }, 'article_ignore', function ($join) {
  1336. $join->on('article_ignore.article_id', '=', 'article.id');
  1337. })
  1338. ->where(function ($query) {
  1339. $query->whereNull('article_ignore.article_id')
  1340. ->orWhere(function ($subQuery) {
  1341. $subQuery->whereNotNull('article_ignore.article_id')
  1342. ->where('article_ignore.is_ignore', 0)
  1343. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1344. });
  1345. })
  1346. // ->where(function ($query) use ($data) {
  1347. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1348. // ->orWhereNull("ignore_ids");
  1349. // })
  1350. ->orderBy("updated_at", "desc")
  1351. ->offset($placeid)
  1352. ->limit($data['pagesize'])
  1353. ->get();
  1354. if (empty($result)) {
  1355. return Result::error("此栏目暂无相关新闻", 0);
  1356. }
  1357. } else {
  1358. return Result::error("此网站暂无此栏目", 0);
  1359. }
  1360. return Result::success($result);
  1361. }
  1362. /**
  1363. *获取新闻列表
  1364. * @param array $data
  1365. * @return array
  1366. */
  1367. public function getWebsiteArticleList(array $data): array
  1368. {
  1369. // return Result::success($data);
  1370. $where[] = ['status', '=', 1];
  1371. $website_id = $data['website_id'];
  1372. $website = Website::where('id', $data['website_id'])->first();
  1373. if (empty($website)) {
  1374. return Result::error("网站不存在", 0);
  1375. }
  1376. // $website_column = $website['column'];
  1377. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1378. $website_column = json_decode($website['website_column_arr_id'], true);
  1379. }
  1380. $categorys = $this->processArticlePro($website_id);
  1381. $cat_1st_arr = $categorys['cat_1st_arr'];
  1382. $catiall = $categorys['catiall'];
  1383. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1384. // return Result::success($diff_pid_categoryIds);
  1385. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1386. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1387. }
  1388. if (isset($data['catid']) && !empty($data['catid'])) {
  1389. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1390. if (empty($category)) {
  1391. return Result::error("此网站暂无此栏目", 0);
  1392. }
  1393. array_push($where, ['catid', '=', $data['catid']]);
  1394. }
  1395. // return Result::success($where);
  1396. $query = Article::where($where)
  1397. ->leftJoinSub(function ($query) use ($website_id) {
  1398. $query->from('article_ignore')
  1399. ->where('website_id', $website_id);
  1400. }, 'article_ignore', function ($join) {
  1401. $join->on('article_ignore.article_id', '=', 'article.id');
  1402. })
  1403. ->where(function ($query) {
  1404. $query->whereNull('article_ignore.article_id')
  1405. ->orWhere(function ($subQuery) {
  1406. $subQuery->whereNotNull('article_ignore.article_id')
  1407. ->where('article_ignore.is_ignore', 0)
  1408. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1409. });
  1410. })
  1411. ->select(
  1412. 'article.id',
  1413. 'article.title',
  1414. 'article.imgurl',
  1415. 'article.author',
  1416. 'article.updated_at',
  1417. 'article.introduce',
  1418. 'article.islink',
  1419. 'article.linkurl',
  1420. 'article.copyfrom',
  1421. 'article.cat_arr_id',
  1422. 'article.catid'
  1423. );
  1424. $count = $query->count();
  1425. $rep = $query->orderBy("updated_at", "desc")
  1426. ->offset(($data['page'] - 1) * $data['pageSize'])
  1427. ->limit($data['pageSize'])
  1428. ->get()->all();
  1429. $categorys = $this->processArticlePro($website_id);
  1430. $cat_1st_arr = $categorys['cat_1st_arr'];
  1431. $catiall = $categorys['catiall'];
  1432. // $web['website_id'] = $data['website_id'];
  1433. foreach ($rep as $k => $v) {
  1434. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1435. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1436. }
  1437. // $rep = $this->processArticles($rep,$web);
  1438. $data = [
  1439. 'rows' => $rep,
  1440. 'count' => $count,
  1441. ];
  1442. if (empty($rep)) {
  1443. return Result::error("没有信息数据");
  1444. }
  1445. return Result::success($data);
  1446. }
  1447. /**
  1448. * 前端-获取新闻详情
  1449. * @param array $data
  1450. * @return array
  1451. */
  1452. public function selectWebsiteArticleInfo(array $data): array
  1453. {
  1454. $where = [
  1455. 'article.id' => $data['id'],
  1456. 'article.status' => 1,
  1457. ];
  1458. $result = Article::where($where)
  1459. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1460. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1461. ->where(function ($query) use ($data) {
  1462. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1463. ->orWhereNull("ignore_ids");
  1464. })
  1465. ->select(
  1466. 'article.*',
  1467. 'article_data.content',
  1468. 'article_data.article_id',
  1469. 'article_extend.website_url',
  1470. 'article_extend.email',
  1471. 'article_extend.contacts',
  1472. 'article_extend.contacts_mobile',
  1473. 'article_extend.contacts_address',
  1474. 'article_extend.zip_code',
  1475. 'article_extend.enterprise_name'
  1476. )
  1477. ->first();
  1478. if (empty($result)) {
  1479. return Result::error("暂无此新闻!", 0);
  1480. }
  1481. if (!empty($result['publiced_at'])) {
  1482. $result['updated_at'] = $result['publiced_at'];
  1483. }
  1484. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1485. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1486. ->where('website_category.website_id', $data['website_id'])
  1487. ->where(['website_category.category_id' => $result['catid']])
  1488. ->first();
  1489. if (empty($category)) {
  1490. return Result::error("查询失败", 0);
  1491. }
  1492. //手动推荐文章
  1493. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1494. if (empty($commend_ids)) {
  1495. $commendArticle = [];
  1496. } else {
  1497. //去除不存在的文章ID
  1498. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1499. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1500. ->where('article.status', 1)
  1501. ->where('website_category.website_id', $data['website_id'])
  1502. ->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')
  1503. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1504. // ->orderBy('article.updated_at', 'desc')
  1505. ->limit(5)
  1506. ->get();
  1507. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1508. foreach ($commendArticle as $k => $v) {
  1509. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1510. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1511. $cat_arr_id = array_unique($cat_arr_id);
  1512. // 从website_category取出alias_pinyin
  1513. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1514. ->whereIn('category_id', $cat_arr_id)
  1515. ->pluck('alias_pinyin', 'category_id')
  1516. ->toArray();
  1517. // 将cat_arr_id的json转成路径/隔开
  1518. $path_parts = [];
  1519. foreach ($cat_arr_id as $cat_id) {
  1520. if (isset($cat_arr[$cat_id])) {
  1521. $path_parts[] = $cat_arr[$cat_id];
  1522. }
  1523. }
  1524. $v->alias_pinyin = implode('/', $path_parts);
  1525. } else {
  1526. $v->alias_pinyin = '';
  1527. }
  1528. }
  1529. }
  1530. $result['category_id'] = $category['category_id'];
  1531. $result['cat_name'] = $category['alias'];
  1532. $result['website_name'] = $category['website_name'] ?? "";
  1533. $result['suffix'] = $category['suffix'] ?? "";
  1534. $result['commendArticle'] = $commendArticle;
  1535. $result['commend_ids'] = $commend_ids;
  1536. return Result::success($result);
  1537. }
  1538. /**
  1539. * 前端-获取网站调查问卷
  1540. * @param array $data
  1541. * @return array
  1542. */
  1543. public function getWebsiteSurvey(array $data): array
  1544. {
  1545. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1546. $website = Website::where('id', $data['website_id'])->first();
  1547. if (empty($website)) {
  1548. return Result::error("暂无此网站", 0);
  1549. }
  1550. }
  1551. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1552. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1553. if (empty($article)) {
  1554. return Result::error("暂无此文章", 0);
  1555. }
  1556. // return Result::error($data,0);
  1557. $where['art_id'] = $data['art_id'];
  1558. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1559. } else {
  1560. $survey = Article::where(function ($query) {
  1561. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1562. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1563. })
  1564. ->where('status', 1)
  1565. ->where('is_survey', 1)
  1566. ->select('survey_id')
  1567. ->orderBy('updated_at', 'desc')
  1568. ->first();
  1569. if (empty($survey)) {
  1570. return Result::error("暂无调查问卷", 0);
  1571. }
  1572. $where['sur_id'] = $survey['survey_id'];
  1573. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1574. }
  1575. // return Result::success($where);
  1576. $result = ArticleSurvey::where($where)
  1577. ->where(function ($query) {
  1578. $query->where('is_other', 0)
  1579. ->orWhere(function ($subQuery) {
  1580. $subQuery->where('is_other', 1)
  1581. ->where('other_id', 0);
  1582. });
  1583. })
  1584. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1585. ->select('article_survey.*', 'article.survey_type')
  1586. ->get()->all();
  1587. if (empty($result)) {
  1588. return Result::error("此文章暂无调查问卷", 0);
  1589. }
  1590. return Result::success($result);
  1591. }
  1592. /**
  1593. * 前端-添加网站调查问卷选项
  1594. * @param array $data
  1595. * @return array
  1596. */
  1597. public function addWebsiteSurveyOption(array $data): array
  1598. {
  1599. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1600. $website = Website::where('id', $data['website_id'])->first();
  1601. if (empty($website)) {
  1602. return Result::error("暂无此网站", 0);
  1603. }
  1604. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1605. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1606. if (empty($survey)) {
  1607. return Result::error("此调查问卷不可添加选项", 0);
  1608. }
  1609. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1610. $choice = [
  1611. 'art_id' => $survey['art_id'],
  1612. 'website_id' => $data['website_id'],
  1613. 'survey_name' => $survey['survey_name'],
  1614. 'choice_name' => $data['choice_name'],
  1615. 'sur_id' => $survey['sur_id'],
  1616. 'is_other' => 1,
  1617. 'other_id' => $survey['id'],
  1618. ];
  1619. $result = ArticleSurvey::insertGetId($choice);
  1620. if (empty($result)) {
  1621. return Result::error("添加失败", 0);
  1622. }
  1623. return Result::success($result);
  1624. }
  1625. }
  1626. return Result::error("添加失败", 0);
  1627. }
  1628. return Result::error("添加失败", 0);
  1629. }
  1630. /**
  1631. * 前端-调查问卷投票
  1632. * @param array $data
  1633. * @return array
  1634. */
  1635. public function addWebsiteSurveyVote(array $data): array
  1636. {
  1637. // return Result::success($data);
  1638. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1639. $website = Website::where('id', $data['website_id'])->first();
  1640. if (empty($website)) {
  1641. return Result::error("暂无此网站", 0);
  1642. }
  1643. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1644. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1645. // return Result::success($survey);
  1646. if (empty($is_survey)) {
  1647. return Result::error("此调查问卷不存在", 0);
  1648. }
  1649. // return Result::success($survey);
  1650. // 调查问卷类型
  1651. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1652. //多选 若是json型则转化成数组类型
  1653. if (strpos($data['choice_id'], '[') === 0) {
  1654. $data['choice_id'] = json_decode($data['choice_id'], true);
  1655. } else {
  1656. // 单选 也转换成数组
  1657. $data['choice_id'] = [$data['choice_id']];
  1658. }
  1659. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1660. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1661. // ->where('website_id',$data['website_id'])
  1662. ->where('is_other', 1)
  1663. ->where('other_id', 0)
  1664. ->first();
  1665. if (!empty($other)) {
  1666. return Result::error("请选择已有的选项!", 0);
  1667. }
  1668. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1669. // ->where('website_id',$data['website_id'])
  1670. ->where('is_other', 1)
  1671. ->where('other_id', '!=', 0)
  1672. ->first();
  1673. // return Result::success($choice['other']);
  1674. $choice_id = $data['choice_id'];
  1675. if (!empty($choice['other'])) {
  1676. // array_push($data['choice_id'],$choice['other']['other_id']);
  1677. if (!empty($choice_id)) {
  1678. $key = array_search($choice['other']['id'], $choice_id);
  1679. if ($key !== false) {
  1680. unset($choice_id[$key]);
  1681. $choice_id = array_values($choice_id);
  1682. }
  1683. array_push($choice_id, $choice['other']['other_id']);
  1684. } else {
  1685. $choice_id[0] = $choice['other']['other_id'];
  1686. }
  1687. array_push($data['choice_id'], $choice['other']['other_id']);
  1688. }
  1689. // return Result::success($data);
  1690. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1691. // ->where('website_id',$data['website_id'])
  1692. ->increment('results', 1);
  1693. if (empty($choice)) {
  1694. return Result::error("请选择已有的选项!", 0);
  1695. }
  1696. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1697. // ->where('website_id',$data['website_id'])
  1698. ->where('other_id', 0)
  1699. ->get();
  1700. $survey['choice'] = $choice_id;
  1701. return Result::success($survey);
  1702. }
  1703. return Result::error("参数必填!");
  1704. }
  1705. return Result::error("此调查问卷不存在", 0);
  1706. }
  1707. return Result::error("参数必填!");
  1708. }
  1709. /**
  1710. * 后端-获取网站调查问卷列表
  1711. * @param array $data
  1712. * @return array
  1713. */
  1714. public function getSurveyList(array $data): array
  1715. {
  1716. $where = [];
  1717. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1718. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1719. }
  1720. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1721. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1722. }
  1723. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1724. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1725. }
  1726. // return Result::success($where);
  1727. if (!empty($where)) {
  1728. $query = Article::where($where)->where(function ($q) {
  1729. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1730. });
  1731. } else {
  1732. $query = Article::where(function ($q) {
  1733. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1734. });
  1735. }
  1736. $count = $query->count();
  1737. $survey = $query->orderByDesc('id')
  1738. ->limit($data['pageSize'])
  1739. ->offset(($data['page'] - 1) * $data['pageSize'])
  1740. ->get();
  1741. if (empty($survey->toArray())) {
  1742. return Result::error("暂无调查问卷!", 0);
  1743. }
  1744. $result = [
  1745. 'rows' => $survey,
  1746. 'count' => $count,
  1747. ];
  1748. return Result::success($result);
  1749. }
  1750. /**
  1751. * 后端-获取网站调查问卷详情
  1752. * @param array $data
  1753. * @return array
  1754. */
  1755. public function getSurveyInfo(array $data): array
  1756. {
  1757. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1758. $where = ['sur_id' => $data['sur_id']];
  1759. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1760. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1761. ->select('article_survey.*', 'article.survey_type')
  1762. ->get()->all();
  1763. if (empty($choose)) {
  1764. return Result::error("此调查问卷不存在", 0);
  1765. }
  1766. $resultsArray = array_column($choose, 'results');
  1767. $total = array_sum($resultsArray);
  1768. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1769. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1770. // $total = 0;
  1771. if (!empty($other)) {
  1772. $total = $total + $other['results'];
  1773. $other['choice_name'] = '(其他)';
  1774. if (!empty($others)) {
  1775. $other['hasChildren'] = true;
  1776. // array_push($other,['hasChildren','=',true]);
  1777. $other['children'] = $others;
  1778. $other_choices = [$other->toArray()];
  1779. $mer_choice = array_merge($choose, $other_choices);
  1780. $value_choice = array_values($mer_choice);
  1781. } else {
  1782. // return Result::error('1111');
  1783. $other_choices = [$other->toArray()];
  1784. $other_choices = array_merge($choose, $other_choices);
  1785. $value_choice = array_values($other_choices);
  1786. // return Result::success($result);
  1787. }
  1788. } else {
  1789. $value_choice = $choose;
  1790. }
  1791. $result = [
  1792. 'choose' => $value_choice,
  1793. 'total' => $total,
  1794. ];
  1795. }
  1796. return Result::success($result);
  1797. }
  1798. /**
  1799. * 前端-搜索新闻列表
  1800. * @param array $data
  1801. * @return array
  1802. */
  1803. public function selectWebsiteArticle(array $data): array
  1804. {
  1805. $website = Website::where('id', $data['website_id'])->first();
  1806. if (empty($website)) {
  1807. return Result::error("网站不存在", 0);
  1808. }
  1809. // $website_column = $website['column'];
  1810. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1811. $website_column = json_decode($website['website_column_arr_id'], true);
  1812. }
  1813. $website_id = $data['website_id'];
  1814. $categorys = $this->processArticlePro($website_id);
  1815. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1816. // return Result::success($diff_pid_categoryIds);
  1817. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1818. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1819. }
  1820. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1821. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1822. $catiall = $categorys['catiall'];
  1823. $categoryIds = $categorys['categoryIds'];
  1824. // return Result::success($categoryIds);
  1825. $query = Article::where('status', 1)
  1826. ->whereIn('catid', $categoryIds)
  1827. ->leftJoinSub(function ($query) use ($website_id) {
  1828. $query->from('article_ignore')
  1829. ->where('website_id', $website_id);
  1830. }, 'article_ignore', function ($join) {
  1831. $join->on('article_ignore.article_id', '=', 'article.id');
  1832. })
  1833. ->where(function ($query) {
  1834. $query->whereNull('article_ignore.article_id')
  1835. ->orWhere(function ($subQuery) {
  1836. $subQuery->whereNotNull('article_ignore.article_id')
  1837. ->where('article_ignore.is_ignore', 0)
  1838. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1839. });
  1840. });
  1841. // ->get()->all();
  1842. // return Result::success($query);
  1843. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1844. $query->whereRaw("JSON_CONTAINS(article.city_arr_id, '" . intval($data['cityid']) . "')");
  1845. }
  1846. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1847. $query->whereRaw("JSON_CONTAINS(article.department_arr_id, '" . intval($data['department_id']) . "')");
  1848. }
  1849. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1850. $query->where('article.title', 'like', '%' . $data['keyword'] . '%');
  1851. }
  1852. // 计算总数
  1853. $count = $query->count();
  1854. // return Result::success($count);
  1855. // 分页查询
  1856. $articles = $query
  1857. ->select(
  1858. 'article.id',
  1859. 'article.title',
  1860. 'article.imgurl',
  1861. 'article.author',
  1862. 'article.updated_at',
  1863. 'article.introduce',
  1864. 'article.islink',
  1865. 'article.linkurl',
  1866. 'article.copyfrom',
  1867. 'article.cat_arr_id',
  1868. 'article.catid',
  1869. 'article.department_arr_id',
  1870. 'article.city_arr_id',
  1871. // 'article_ignore.c_show_time',
  1872. // 'article_ignore.is_ignore'
  1873. )
  1874. ->orderBy("updated_at", "desc")
  1875. ->offset(($data['page'] - 1) * $data['pageSize'])
  1876. ->limit($data['pageSize'])
  1877. ->get();
  1878. // return Result::success($articles);
  1879. foreach ($articles as $k => $v) {
  1880. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1881. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1882. }
  1883. if (empty($articles)) {
  1884. return Result::error("没有符合条件的资讯数据");
  1885. }
  1886. $result = [
  1887. 'rows' => $articles,
  1888. 'count' => $count,
  1889. ];
  1890. return Result::success($result);
  1891. }
  1892. /**
  1893. * 模块新闻加强版
  1894. * @param array $data
  1895. * @return array
  1896. */
  1897. public function getWebsiteCatidArticle(array $data): array
  1898. {
  1899. $where = [
  1900. 'website_category.category_id' => $data['catid'],
  1901. 'website_category.website_id' => $data['website_id'],
  1902. ];
  1903. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1904. $child_catnum = $data['child_catnum'] ?? 1;
  1905. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1906. $childCategoryIds = array_column($category['child'], 'category_id');
  1907. if (empty($childCategoryIds)) {
  1908. return Result::error("暂无子栏目", 0);
  1909. }
  1910. $imgArticles = [];
  1911. $textArticles = [];
  1912. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1913. // 初始化子分类图片新闻和文字新闻数组
  1914. // 查询所有子级栏目的图文新闻
  1915. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1916. ->where(function ($query) use ($data) {
  1917. $query->where(function ($subQuery) use ($data) {
  1918. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1919. })->orWhereNull("ignore_ids");
  1920. })
  1921. ->where('status', 1)
  1922. ->where('imgurl', '!=', '')
  1923. ->select('*')
  1924. ->orderBy('updated_at', 'desc')
  1925. ->limit($data['child_imgnum'])
  1926. ->get();
  1927. }
  1928. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1929. // 查询所有子级栏目的文字新闻
  1930. $textArticles = Article::where('catid', $childCategoryIds[0])
  1931. ->where('status', 1)
  1932. ->where(function ($query) use ($data) {
  1933. $query->where(function ($subQuery) use ($data) {
  1934. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1935. })->orWhereNull("ignore_ids");
  1936. })
  1937. ->select('*')
  1938. ->orderBy('updated_at', 'desc')
  1939. ->limit($data['child_textnum'])
  1940. ->get();
  1941. }
  1942. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1943. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1944. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1945. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1946. return $child;
  1947. }, $category['child']);
  1948. }
  1949. // }
  1950. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1951. $category['img'] = WebsiteCategory::where($where)
  1952. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1953. ->where('article.status', 1)
  1954. ->where('article.imgurl', '!=', '')
  1955. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1956. ->orderBy('article.updated_at', 'desc')
  1957. ->limit($data['img_num'])
  1958. ->get();
  1959. }
  1960. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1961. $category['text'] = WebsiteCategory::where($where)
  1962. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1963. ->where('article.status', 1)
  1964. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1965. ->orderBy('article.updated_at', 'desc')
  1966. ->limit($data['text_num'])
  1967. ->get();
  1968. }
  1969. // $category = $category->get();
  1970. if (empty($category)) {
  1971. return Result::error("查询失败", 0);
  1972. }
  1973. return Result::success($category);
  1974. }
  1975. /**
  1976. * 模块新闻加强plus版
  1977. * @param array $data
  1978. * @return array
  1979. */
  1980. public function getWebsiteAllArticle(array $data): array
  1981. {
  1982. // return Result::success($data);
  1983. $time1 = microtime(true);
  1984. $wetbsite_id = $data['website_id'] ?? 2;
  1985. $data = json_decode($data['id'], true);
  1986. $website = Website::where('id', $wetbsite_id)->first();
  1987. if (empty($website)) {
  1988. return Result::error("网站不存在", 0);
  1989. }
  1990. // return Result::success($website);
  1991. $website_column = $website['website_column_arr_id'] ?? '[]';
  1992. $website_column = json_decode($website_column, true);
  1993. $categorys = $this->processArticlePro($wetbsite_id);
  1994. $cat_1st_arr = $categorys['cat_1st_arr'];
  1995. $catiall = $categorys['catiall'];
  1996. // return Result::success($catiall);
  1997. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  1998. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1999. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2000. }
  2001. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  2002. // return Result::success($categorys);
  2003. $parent_category = array_column($data, 'parent');
  2004. $parent_cat = [];
  2005. $child_category = array_column($data, 'child');
  2006. if (!empty($parent_category)) {
  2007. foreach ($parent_category as $key => $value) {
  2008. $arr = array_map('intval', explode(',', $value));
  2009. $parent_cat[$key] = $arr[0] ?? 0;
  2010. $parent_category = $arr[0] ?? 0;
  2011. $article_imgnum = $arr[1] ?? 0;
  2012. $article_textnum = $arr[2] ?? 0;
  2013. if ($parent_category != 0) {
  2014. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2015. // return Result::success($category_arr);
  2016. if ($article_imgnum != 0) {
  2017. $img_article = Article::whereIn('catid', $category_arr)
  2018. ->where('status', 1)
  2019. ->where('imgurl', '!=', '')
  2020. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2021. $query->from('article_ignore')
  2022. ->where('website_id', $wetbsite_id);
  2023. }, 'article_ignore', function ($join) {
  2024. $join->on('article_ignore.article_id', '=', 'article.id');
  2025. })
  2026. ->where(function ($query) {
  2027. $query->whereNull('article_ignore.article_id')
  2028. ->orWhere(function ($subQuery) {
  2029. $subQuery->whereNotNull('article_ignore.article_id')
  2030. ->where('article_ignore.is_ignore', 0)
  2031. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2032. });
  2033. })
  2034. ->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')
  2035. ->orderBy('updated_at', 'desc')
  2036. ->limit($article_imgnum)
  2037. ->get()->all();
  2038. foreach ($img_article as $k => $v) {
  2039. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2040. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2041. }
  2042. } else {
  2043. $img_article = [];
  2044. }
  2045. if ($article_textnum != 0) {
  2046. $text_article = Article::whereIn('catid', $category_arr)
  2047. ->where('status', 1)
  2048. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2049. $query->from('article_ignore')
  2050. ->where('website_id', $wetbsite_id);
  2051. }, 'article_ignore', function ($join) {
  2052. $join->on('article_ignore.article_id', '=', 'article.id');
  2053. })
  2054. ->where(function ($query) {
  2055. $query->whereNull('article_ignore.article_id')
  2056. ->orWhere(function ($subQuery) {
  2057. $subQuery->whereNotNull('article_ignore.article_id')
  2058. ->where('article_ignore.is_ignore', 0)
  2059. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2060. });
  2061. })
  2062. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2063. ->orderBy('updated_at', 'desc')
  2064. ->limit($article_textnum)
  2065. ->get()->all();
  2066. foreach ($text_article as $k => $v) {
  2067. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2068. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2069. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2070. }
  2071. } else {
  2072. $text_article = [];
  2073. }
  2074. $catiall[$parent_category]['imgnum'] = $img_article;
  2075. $catiall[$parent_category]['textnum'] = $text_article;
  2076. $parent[$key] = $catiall[$parent_category];
  2077. } else {
  2078. $parent[$key] = '';
  2079. }
  2080. }
  2081. }
  2082. if (!empty($child_category)) {
  2083. foreach ($child_category as $key => $value) {
  2084. $arr = array_map('intval', explode(',', $value));
  2085. $parent_category = $parent_cat[$key];
  2086. $child_category = $arr[0] ?? 0;
  2087. $article_imgnum = $arr[1] ?? 0;
  2088. $article_textnum = $arr[2] ?? 0;
  2089. if ($child_category != 0) {
  2090. $all_childcat = $cat_1st_arr[$parent_category];
  2091. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  2092. // 从 $websiteInfoIndexed 中获取对应的数据
  2093. $info = $websiteInfoIndexed[$v];
  2094. // 返回一个包含所需信息的数组
  2095. return [
  2096. 'alias' => $info->alias,
  2097. 'category_id' => $info->category_id,
  2098. 'aLIas_pinyin' => $info->aLIas_pinyin,
  2099. 'pid' => $info->pid,
  2100. 'type' => $info->type,
  2101. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  2102. 'pinyin' => $info->pinyin,
  2103. ];
  2104. }, $all_childcat);
  2105. if ($article_imgnum != 0) {
  2106. $img_article = Article::where('catid', $child_category)
  2107. ->where('status', 1)
  2108. ->where('imgurl', '!=', '')
  2109. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2110. $query->from('article_ignore')
  2111. ->where('website_id', $wetbsite_id);
  2112. }, 'article_ignore', function ($join) {
  2113. $join->on('article_ignore.article_id', '=', 'article.id');
  2114. })
  2115. ->where(function ($query) {
  2116. $query->whereNull('article_ignore.article_id')
  2117. ->orWhere(function ($subQuery) {
  2118. $subQuery->whereNotNull('article_ignore.article_id')
  2119. ->where('article_ignore.is_ignore', 0)
  2120. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2121. });
  2122. })
  2123. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2124. ->orderBy('updated_at', 'desc')
  2125. ->limit($article_imgnum)
  2126. ->get()->all();
  2127. foreach ($img_article as $k => $v) {
  2128. // var_dump($v);
  2129. // var_dump($k);
  2130. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2131. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2132. }
  2133. } else {
  2134. $img_article = [];
  2135. }
  2136. if ($article_textnum != 0) {
  2137. $text_article = Article::where('catid', $child_category)
  2138. ->where('status', 1)
  2139. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2140. $query->from('article_ignore')
  2141. ->where('website_id', $wetbsite_id);
  2142. }, 'article_ignore', function ($join) {
  2143. $join->on('article_ignore.article_id', '=', 'article.id');
  2144. })
  2145. ->where(function ($query) {
  2146. $query->whereNull('article_ignore.article_id')
  2147. ->orWhere(function ($subQuery) {
  2148. $subQuery->whereNotNull('article_ignore.article_id')
  2149. ->where('article_ignore.is_ignore', 0)
  2150. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2151. });
  2152. })
  2153. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2154. ->orderBy('updated_at', 'desc')
  2155. ->limit($article_textnum)
  2156. ->get()->all();
  2157. foreach ($text_article as $k => $v) {
  2158. // var_dump($v);
  2159. // var_dump($k);
  2160. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2161. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2162. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2163. }
  2164. } else {
  2165. $text_article = [];
  2166. }
  2167. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  2168. $catiall[$child_category]['imgnum'] = $img_article;
  2169. $catiall[$child_category]['textnum'] = $text_article;
  2170. $child[$key] = $catiall[$child_category];
  2171. // var_dump($pids);
  2172. } else {
  2173. $child[$key] = '';
  2174. }
  2175. }
  2176. }
  2177. foreach ($parent as $key => $value) {
  2178. $result[$key] = $value;
  2179. if (!empty($child[$key])) {
  2180. // var_dump($child[$key]);
  2181. $result[$key]['child'] = $child[$key];
  2182. // $value[$key]['child'] = $child[$key];
  2183. } else {
  2184. $result[$key]['child'] = [
  2185. "alias" => null,
  2186. "category_id" => null,
  2187. "type" => null,
  2188. "pinyin" => null,
  2189. "all_childcat" => [],
  2190. "imgnum" => [],
  2191. "textnum" => []
  2192. ];
  2193. }
  2194. }
  2195. return Result::success($result);
  2196. }
  2197. /**
  2198. * 辅助方法:获取文章列表
  2199. */
  2200. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  2201. {
  2202. sleep(1);
  2203. $query = Article::where('article.status', 1)
  2204. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  2205. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  2206. ->where(function ($query) use ($website) {
  2207. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  2208. })
  2209. ->leftJoin('website_category', function ($join) use ($website) {
  2210. $join->on('article.catid', '=', 'website_category.category_id')
  2211. ->where('website_category.website_id', '=', $website['website_id']);
  2212. })
  2213. ->select(
  2214. 'article.id',
  2215. 'article.title',
  2216. 'article.imgurl',
  2217. 'article.author',
  2218. 'article.updated_at',
  2219. 'article.introduce',
  2220. 'article.islink',
  2221. 'article.linkurl',
  2222. 'article.copyfrom',
  2223. 'article.cat_arr_id',
  2224. 'article.catid',
  2225. 'website_category.alias as category_name'
  2226. )
  2227. ->orderBy('updated_at', 'desc')
  2228. ->limit($limit);
  2229. // 如果是图片文章,添加图片URL条件
  2230. if ($isImageArticle) {
  2231. $query->where('imgurl', '!=', '');
  2232. } else {
  2233. // 文字文章不需要imgurl字段
  2234. $query->addSelect('article.introduce');
  2235. }
  2236. $articles = $query->get();
  2237. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  2238. }
  2239. /**
  2240. * 乡村网-获取特殊新闻模块
  2241. * @param array $data
  2242. * @return array
  2243. */
  2244. public function getWebsiteArticles(array $data): array
  2245. {
  2246. $website_id = $data['website_id'];
  2247. $website = Website::where('id', $website_id)->first();
  2248. if (empty($website)) {
  2249. return Result::error("网站不存在", 0);
  2250. }
  2251. // return Result::success($website);
  2252. $website_column = $website['website_column_arr_id'] ?? '[]';
  2253. $website_column = json_decode($website_column, true);
  2254. $catids = json_decode($data['id'], true);
  2255. $parent_category = array_column($catids, 'parent');
  2256. if (!empty($parent_category) && is_array($parent_category)) {
  2257. $categorys = $this->processArticlePro($website_id);
  2258. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2259. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2260. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2261. }
  2262. $catiall = $categorys['catiall'];
  2263. $cat_1st_arr = $categorys['cat_1st_arr'];
  2264. // return Result::success($categorys);
  2265. foreach ($parent_category as $key => $value) {
  2266. $arr = array_map('intval', explode(',', $value));
  2267. $parent_category = $arr[0] ?? 0;
  2268. $article_imgnum = $arr[1] ?? 0;
  2269. $article_textnum = $arr[2] ?? 0;
  2270. if ($parent_category != 0) {
  2271. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2272. // return Result::success($category_arr);
  2273. if ($article_imgnum != 0) {
  2274. $img_article = Article::whereIn('article.catid', $category_arr)
  2275. ->where('article.status', 1)
  2276. ->where('article.imgurl', '!=', '')
  2277. ->leftJoinSub(function ($query) use ($website_id) {
  2278. $query->from('article_ignore')
  2279. ->where('website_id', $website_id);
  2280. }, 'article_ignore', function ($join) {
  2281. $join->on('article_ignore.article_id', '=', 'article.id');
  2282. })
  2283. ->where(function ($query) {
  2284. $query->whereNull('article_ignore.article_id')
  2285. ->orWhere(function ($subQuery) {
  2286. $subQuery->whereNotNull('article_ignore.article_id')
  2287. ->where('article_ignore.is_ignore', 0)
  2288. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2289. });
  2290. })
  2291. ->select(
  2292. 'article.id',
  2293. 'article.title',
  2294. 'article.imgurl',
  2295. 'article.author',
  2296. 'article.updated_at',
  2297. 'article.introduce',
  2298. 'article.islink',
  2299. 'article.linkurl',
  2300. 'article.copyfrom',
  2301. 'article.cat_arr_id',
  2302. 'article.catid as category_id'
  2303. )
  2304. ->orderBy('updated_at', 'desc')
  2305. ->limit($article_imgnum)
  2306. ->get()->all();
  2307. foreach ($img_article as $k => $v) {
  2308. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2309. // return Result::success($v);
  2310. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2311. }
  2312. } else {
  2313. $img_article = [];
  2314. }
  2315. if ($article_textnum != 0) {
  2316. $text_article = Article::whereIn('article.catid', $category_arr)
  2317. ->where('article.status', 1)
  2318. ->leftJoinSub(function ($query) use ($website_id) {
  2319. $query->from('article_ignore')
  2320. ->where('website_id', $website_id);
  2321. }, 'article_ignore', function ($join) {
  2322. $join->on('article_ignore.article_id', '=', 'article.id');
  2323. })
  2324. ->where(function ($query) {
  2325. $query->whereNull('article_ignore.article_id')
  2326. ->orWhere(function ($subQuery) {
  2327. $subQuery->whereNotNull('article_ignore.article_id')
  2328. ->where('article_ignore.is_ignore', 0)
  2329. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2330. });
  2331. })
  2332. ->select(
  2333. 'article.id',
  2334. 'article.title',
  2335. 'article.author',
  2336. 'article.updated_at',
  2337. 'article.introduce',
  2338. 'article.islink',
  2339. 'article.linkurl',
  2340. 'article.copyfrom',
  2341. 'article.cat_arr_id',
  2342. 'article.catid as category_id'
  2343. )
  2344. ->orderBy('updated_at', 'desc')
  2345. ->limit($article_textnum)
  2346. ->get()->all();
  2347. foreach ($text_article as $k => $v) {
  2348. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2349. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2350. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2351. }
  2352. } else {
  2353. $text_article = [];
  2354. }
  2355. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2356. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2357. $parent[$key] = $catiall[$parent_category];
  2358. } else {
  2359. $parent[$key] = [];
  2360. }
  2361. }
  2362. }
  2363. return Result::success($parent);
  2364. }
  2365. // 封装处理商品的路由问题
  2366. function processGoods($goods, $data)
  2367. {
  2368. return $goods->map(function ($good) use ($data) {
  2369. $catid = $good->catid ?? 0;
  2370. // $pinyin = '';
  2371. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2372. if (!empty($category->pid) && $category->pid != 0) {
  2373. $level = json_decode($category->category_arr_id, true);
  2374. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2375. ->whereIn('category_id', $level)
  2376. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2377. ->get(['aLIas_pinyin'])
  2378. ->pluck('aLIas_pinyin')
  2379. ->implode('/');
  2380. } else {
  2381. $pinyin = $category->aLIas_pinyin ?? '';
  2382. }
  2383. if (isset($good->city_id) && !empty($good->city_id)) {
  2384. $city = District::where('id', $good->city_id)->first(['name']);
  2385. $good->city_name = $city->name ?? '';
  2386. }
  2387. // 解析imgurl JSON并取第一条数据
  2388. $imgUrls = json_decode($good->imgurl, true);
  2389. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2390. $good->pinyin = $pinyin;
  2391. return $good;
  2392. });
  2393. }
  2394. /**
  2395. * 获取商城首页-根据栏目id
  2396. * @param array $data
  2397. * @return array
  2398. * */
  2399. function getWebsiteCatidshop(array $data): array
  2400. {
  2401. $input['catid'] = $data['catid'];
  2402. $input['website_id'] = $data['website_id'];
  2403. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2404. $result = array_map(function ($item) use ($input) {
  2405. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2406. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2407. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2408. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2409. if (empty($category) || $category->type != 2) {
  2410. return Result::error("暂无此栏目", 0);
  2411. } else {
  2412. $website['website_id'] = $input['website_id'];
  2413. $goods = Good::where('good.status', 2)
  2414. ->where('good.website_id', $website['website_id'])
  2415. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2416. ->select(
  2417. 'good.id',
  2418. 'good.name',
  2419. 'good.imgurl',
  2420. 'good.description',
  2421. 'good.updated_at',
  2422. 'good.catid',
  2423. 'good.type_id',
  2424. 'good.price',
  2425. 'good.com',
  2426. 'good.level',
  2427. 'good.unit'
  2428. )
  2429. ->orderBy('updated_at', 'desc')
  2430. ->offset($goodStart)
  2431. ->limit($goodNum);
  2432. $all_goods = $goods->get();
  2433. $all_goods = $this->processGoods($all_goods, $website);
  2434. }
  2435. return $all_goods ?? [];
  2436. }
  2437. }, $data);
  2438. return Result::success($result);
  2439. }
  2440. /**
  2441. * 获取商品模块
  2442. * @param array $data
  2443. * @return array
  2444. * */
  2445. public function getWebsiteshop(array $data): array
  2446. {
  2447. $input['id'] = $data['id'];
  2448. $input['website_id'] = $data['website_id'];
  2449. $catid = $data['catid'];
  2450. $data = json_decode($input['id'] ?? '', true) ?? [];
  2451. $result['goods'] = array_map(function ($item) use ($input) {
  2452. // 检查parent元素是否存在且不是undefined
  2453. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2454. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2455. $website = $input['website_id'];
  2456. $query = Good::where('good.status', 2)
  2457. ->where('good.website_id', $website);
  2458. switch ($Levelid) {
  2459. case 1:
  2460. case 2:
  2461. case 3:
  2462. $goods = $query->where(function ($q) use ($Levelid) {
  2463. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2464. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2465. });
  2466. break;
  2467. case 4:
  2468. $goods = $query;
  2469. break;
  2470. case 5:
  2471. $goods = $query->where('type_id', 1);
  2472. break;
  2473. case 6:
  2474. $goods = $query->where('type_id', 2);
  2475. break;
  2476. default:
  2477. return [];
  2478. }
  2479. $all_goods = $goods
  2480. ->select(
  2481. 'good.id',
  2482. 'good.name',
  2483. 'good.imgurl',
  2484. 'good.description',
  2485. 'good.updated_at',
  2486. 'good.catid',
  2487. 'good.type_id',
  2488. 'good.price',
  2489. 'good.level',
  2490. 'good.website_id'
  2491. )
  2492. ->orderBy('updated_at', 'desc')
  2493. ->offset($goodStart)
  2494. ->limit($goodNum)
  2495. ->get();
  2496. $web['website_id'] = $website;
  2497. $all_goods = $this->processGoods($all_goods, $web);
  2498. }
  2499. return $all_goods;
  2500. }, $data);
  2501. $website = $input['website_id'];
  2502. $result['article'] = Article::where(function ($query) use ($website) {
  2503. $query->where(function ($subQuery) use ($website) {
  2504. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2505. })->orWhereNull("ignore_ids");
  2506. })
  2507. ->where('catid', $catid)
  2508. ->where('article.status', 1)
  2509. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2510. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2511. ->orderBy('article.updated_at', 'desc')
  2512. ->first();
  2513. return Result::success($result);
  2514. }
  2515. /**
  2516. * 获取商品分类
  2517. * @param array $data
  2518. * @return array
  2519. * */
  2520. public function getWebsiteshopCat(array $data): array
  2521. {
  2522. $website = $data['website_id'];
  2523. $category = WebsiteCategory::where('website_id', $website)
  2524. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2525. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2526. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2527. ->orderBy('sort')
  2528. ->get();
  2529. $cat = $category->map(function ($item) use ($website) {
  2530. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2531. $pid = $item->pid ?? 0;
  2532. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2533. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2534. ->where('website_id', $website)
  2535. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2536. ->get(['aLIas_pinyin'])
  2537. ->pluck('aLIas_pinyin')
  2538. ->implode('/');
  2539. } else {
  2540. $pinyin = $item->aLIas_pinyin ?? '';
  2541. }
  2542. $item->pinyin = $pinyin;
  2543. });
  2544. if (empty($category)) {
  2545. return Result::error("栏目查询失败", 0);
  2546. }
  2547. $cat_tree = Result::buildMenuTree($category);
  2548. $web['website_id'] = $website;
  2549. $goods = Good::where('website_id', $website)
  2550. ->where('status', 2)
  2551. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2552. ->latest('updated_at')
  2553. ->offset(($data['page'] - 1) * $data['pageSize'])
  2554. ->limit($data['pageSize'])
  2555. ->get();
  2556. if (!empty($goods)) {
  2557. if ($goods->count() > 1 && !empty($goods)) {
  2558. $goods = $this->processGoods($goods, $web);
  2559. }
  2560. } else {
  2561. $goods = [];
  2562. }
  2563. $result = [
  2564. 'category' => $cat_tree,
  2565. 'goods' => $goods,
  2566. ];
  2567. // $resul['goods'] = $goods;
  2568. if (empty($result)) {
  2569. return Result::error("查询失败", 0);
  2570. }
  2571. return Result::success($result);
  2572. }
  2573. /*
  2574. * 获取商品列表
  2575. * @param array $data
  2576. * @return array
  2577. * */
  2578. public function getWebsiteshopList(array $data): array
  2579. {
  2580. // return Result::success($data);
  2581. $where = [
  2582. 'status' => 2,
  2583. 'website_id' => $data['website_id'],
  2584. ];
  2585. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2586. // return Result::error("查询失败", 0);
  2587. // }
  2588. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2589. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2590. $data['catid'] = $category->category_id ?? 0;
  2591. }
  2592. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2593. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2594. }
  2595. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2596. array_push($where, ['type_id', $data['type_id']]);
  2597. }
  2598. $query = Good::where($where)
  2599. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2600. $query->where(function ($q) use ($data) {
  2601. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2602. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2603. });
  2604. })
  2605. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2606. $query->where(function ($q) use ($data) {
  2607. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2608. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2609. });
  2610. })
  2611. ->select(
  2612. 'good.id',
  2613. 'good.name',
  2614. 'good.imgurl',
  2615. 'good.description',
  2616. 'good.updated_at',
  2617. 'good.com',
  2618. 'good.catid',
  2619. 'good.type_id',
  2620. 'good.website_id',
  2621. 'good.cat_arr_id',
  2622. 'good.created_at',
  2623. 'good.city_id'
  2624. )
  2625. ->latest('updated_at');
  2626. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2627. $result['count'] = $query->clone()->count();
  2628. $result['goods'] = $this->processGoods(
  2629. $query->clone()
  2630. ->offset(($data['page'] - 1) * $data['pageSize'])
  2631. ->limit($data['pageSize'])
  2632. ->get(),
  2633. $data
  2634. );
  2635. } else {
  2636. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2637. // 获取 type_id 为 1 的数据
  2638. $result['type1'] = $this->processGoods(
  2639. $query->clone()
  2640. ->where('type_id', 1)
  2641. ->offset(($data['page'] - 1) * $data['pageSize'])
  2642. ->limit($data['pageSize'])
  2643. ->get(),
  2644. $data
  2645. );
  2646. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2647. // 获取 type_id 为 2 的数据
  2648. $result['type2'] = $this->processGoods(
  2649. $query->clone()
  2650. ->where('type_id', 2)
  2651. ->offset(($data['page'] - 1) * $data['pageSize'])
  2652. ->limit($data['pageSize'])
  2653. ->get(),
  2654. $data
  2655. );
  2656. }
  2657. if (empty($result)) {
  2658. return Result::error("查询失败", 0);
  2659. }
  2660. return Result::success($result);
  2661. }
  2662. /**
  2663. * 获取商品详情
  2664. * @param array $data
  2665. * @return array
  2666. * */
  2667. public function getWebsiteshopInfo(array $data): array
  2668. {
  2669. $where = [
  2670. 'good.status' => 2,
  2671. 'good.website_id' => $data['website_id'],
  2672. 'good.id' => $data['id'],
  2673. ];
  2674. $goods = Good::where($where)
  2675. ->where('good.id', $data['id'])
  2676. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2677. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2678. ->first();
  2679. if (empty($goods)) {
  2680. return Result::error("查询失败", 0);
  2681. }
  2682. $goods->imgurl = json_decode($goods->imgurl, true);
  2683. return Result::success($goods);
  2684. }
  2685. /**
  2686. * plus pro 处理文章路由问题
  2687. */
  2688. function processArticlePro($website_id)
  2689. {
  2690. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2691. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2692. // // 取出category_id 对应的aLIas_pinyin
  2693. // $categoryIds = array_column($categorys, 'category_id');
  2694. // $categoryPIds = array_column($categorys, 'pid');
  2695. // $aliasPinyins = array_column($categorys, 'path');
  2696. // $alias = array_column($categorys, 'alias');
  2697. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2698. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2699. // // return Result::success($cat_arr);
  2700. // // $catiall = [];
  2701. // //一级所有子级的记录
  2702. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2703. // return [
  2704. // 'cat_1st_arr' => $cat_alias_arr,
  2705. // 'catiall' => $cat_arr,
  2706. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2707. // 'categoryIds' => $categoryIds,
  2708. // ];
  2709. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2710. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2711. // 取出category_id 对应的aLIas_pinyin
  2712. $categoryIds = array_column($categorys, 'category_id');
  2713. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
  2714. return $pid != 0;
  2715. })));
  2716. $category_path = array_column($categorys, 'path');
  2717. $cat_arr = array_combine($categoryIds, $category_path);
  2718. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2719. $catiall = [];
  2720. //一级所有子级的记录
  2721. $cat_1st_arr = [];
  2722. foreach ($categorys as $key => $value) {
  2723. // $category_arr_id = json_decode($value->category_arr_id);
  2724. // $pinyin_str = '';
  2725. // // 算出一级 并且算出子级
  2726. if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
  2727. $cat_1st_arr[$value->pid][] = $value->category_id;
  2728. }
  2729. // foreach ($category_arr_id as $k => $v) {
  2730. // $pinyin_str .= $cat_arr[$v] . '/';
  2731. // }
  2732. // $pinyin_str = rtrim($pinyin_str, '/');
  2733. $catiall[$value->category_id]['alias'] = $value->alias;
  2734. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2735. $catiall[$value->category_id]['type'] = $value->type;
  2736. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2737. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2738. }
  2739. return [
  2740. 'cat_1st_arr' => $cat_1st_arr,
  2741. 'catiall' => $catiall,
  2742. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2743. 'categoryIds' => $categoryIds,
  2744. 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
  2745. 'categoryPIds' => $categoryPIds,
  2746. ];
  2747. }
  2748. /**
  2749. * 封装处理文章的路由问题
  2750. * */
  2751. function processArticles($articles, $data)
  2752. {
  2753. // 检查 $articles 是否为数组或可迭代对象
  2754. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2755. return $articles->map(function ($article) use ($data) {
  2756. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2757. $catid = $article->cat_arr_id ?? '';
  2758. }
  2759. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2760. $catid = $article->category_arr_id ?? '';
  2761. }
  2762. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2763. $level = json_decode($catid, true);
  2764. if (!is_array($level)) {
  2765. return $article;
  2766. } else {
  2767. $level = array_map('intval', $level);
  2768. }
  2769. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2770. ->where($data)
  2771. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2772. ->pluck('aLIas_pinyin')
  2773. ->implode('/');
  2774. $article->pinyin = $pinyin ?? '';
  2775. return $article;
  2776. });
  2777. } else {
  2778. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2779. $catid = $articles->cat_arr_id ?? '';
  2780. $level = json_decode($catid, true);
  2781. if (!is_array($level)) {
  2782. return $articles;
  2783. } else {
  2784. $level = array_map('intval', $level);
  2785. }
  2786. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2787. ->where($data)
  2788. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2789. ->pluck('aLIas_pinyin')
  2790. ->implode('/');
  2791. $articles->pinyin = $pinyin ?? '';
  2792. return $articles;
  2793. }
  2794. }
  2795. // 封装处理由问题
  2796. function processJob($job, $data)
  2797. {
  2798. return $job->map(function ($job) use ($data) {
  2799. $category = $job->cat_arr_id ?? '';
  2800. $cityid = $job->city_arr_id ?? '';
  2801. $city = json_decode($cityid, true);
  2802. $pinyin = '';
  2803. $level = json_decode($category, true);
  2804. // 路由
  2805. if (!empty($level) && is_array($level)) {
  2806. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2807. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2808. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2809. ->get(['aLIas_pinyin'])
  2810. ->pluck('aLIas_pinyin')
  2811. ->implode('/');
  2812. if (empty($pinyin)) {
  2813. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2814. }
  2815. $job->pinyin = $pinyin;
  2816. }
  2817. // 取职位-城市 市??省
  2818. if (!empty($city) && is_array($city)) {
  2819. if (isset($city[1]) && !empty($city[1])) {
  2820. $city = District::where('id', $city[1])->first(['name']);
  2821. $job->city_name = $city->name ?? '';
  2822. } else if (isset($city[0]) && !empty($city[0])) {
  2823. $city = District::where('id', $city[0])->first(['name']);
  2824. $job->city_name = $city->name ?? '';
  2825. } else {
  2826. $job->city_name = '全国';
  2827. }
  2828. }
  2829. // 获取简历最后一级地区
  2830. if (isset($job->city_id) && !empty($job->city_id)) {
  2831. $city = District::where('id', $job->city_id)->first(['name']);
  2832. $job->hunt_cityname = $city->name ?? '';
  2833. }
  2834. // 组合详细地址
  2835. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2836. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2837. if (is_array($address_id) && !empty($address_id)) {
  2838. $address = District::whereIn('id', $address_id)
  2839. ->orderBy('level', 'asc')
  2840. ->get(['name'])
  2841. ->pluck('name')
  2842. ->implode('');
  2843. // $job->address_name = $address ?? '';
  2844. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2845. }
  2846. }
  2847. // 取行业
  2848. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2849. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2850. if (!empty($job->industry)) {
  2851. $query->where('hyid', $job->industry);
  2852. } else if (!empty($job->hy_id)) {
  2853. $query->where('hyid', $job->hy_id);
  2854. } else if (!empty($job->company_hy_id)) {
  2855. $query->where('hyid', $job->company_hy_id);
  2856. } else {
  2857. $query->where('hyid', $job->job_industry);
  2858. }
  2859. })->first(['hyname']);
  2860. $job->hy_name = $hy_name->hyname ?? '';
  2861. }
  2862. // 取职位类别
  2863. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2864. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2865. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2866. $job->zw_name = $zw_name->zwname ?? '';
  2867. }
  2868. // 取具体职位
  2869. 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))) {
  2870. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2871. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2872. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2873. }
  2874. // 取工作经验
  2875. if (isset($job->experience) && !empty($job->experience)) {
  2876. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2877. $job->experience_name = $experience->ename ?? '';
  2878. }
  2879. // 取学历
  2880. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2881. $education = $job->educational ?? $job->school_education;
  2882. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2883. $job->education_name = $education->ename ?? '';
  2884. }
  2885. // 语言
  2886. if (isset($job->language) && !empty($job->language)) {
  2887. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2888. $job->language_name = $language->ename ?? '';
  2889. }
  2890. // 薪资
  2891. if (isset($job->salary) && !empty($job->salary)) {
  2892. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2893. $job->salary_name = $salary->ename ?? '';
  2894. }
  2895. // 职位性质
  2896. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2897. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2898. $job->job_nature_name = $job_nature->ename ?? '';
  2899. }
  2900. // 公司规模
  2901. if (isset($job->company_size) && !empty($job->company_size)) {
  2902. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2903. $job->company_size_name = $company_size->ename ?? '';
  2904. }
  2905. // 公司性质
  2906. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2907. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2908. $job->company_nature_name = $company_nature->nature_name ?? '';
  2909. }
  2910. // $job->pinyin = $pinyin;
  2911. return $job;
  2912. });
  2913. }
  2914. /**
  2915. * 获取书籍模块
  2916. * @param array $data
  2917. * @return array
  2918. * */
  2919. public function getWebsiteBook(array $data): array
  2920. {
  2921. $input['id'] = $data['id'];
  2922. $input['website_id'] = $data['website_id'];
  2923. // 将 JSON 字符串转换为 PHP 数组
  2924. $data = json_decode($input['id'], true);
  2925. // 使用 array_map 处理每个元素
  2926. $result = array_map(function ($item) use ($input) {
  2927. // 检查parent元素是否存在且不是undefined
  2928. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2929. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2930. $website = [
  2931. 'website_id' => $input['website_id'],
  2932. ];
  2933. // 查询栏目名称
  2934. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2935. if (empty($category)) {
  2936. $parent_alias = '';
  2937. $parent_pinyin = null;
  2938. $imgBooks = [];
  2939. $textBooks = [];
  2940. } else {
  2941. $parent_alias = $category->alias ?? '';
  2942. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2943. // 查找子分类ID数组
  2944. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2945. array_push($childCategoryIds, $parentCatId);
  2946. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2947. if ($parentImgNum != 0) {
  2948. // 查询图片新闻
  2949. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2950. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2951. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2952. })
  2953. ->where('book.status', 2)
  2954. ->where('book.img_url', '!=', '')
  2955. ->where('book.website_id', $website['website_id'])
  2956. ->leftJoin('website_category', function ($join) use ($website) {
  2957. $join->on('book.cat_id', '=', 'website_category.category_id')
  2958. ->where('website_category.website_id', '=', $website['website_id']);
  2959. })
  2960. ->select(
  2961. 'book.id',
  2962. 'book.title',
  2963. 'book.img_url',
  2964. 'book.price',
  2965. 'book.market_price',
  2966. 'book.description',
  2967. 'book.cat_id',
  2968. 'book.description',
  2969. 'book.updated_at',
  2970. 'website_category.alias as category_name',
  2971. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2972. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2973. )
  2974. ->orderBy('updated_at', 'desc')
  2975. ->limit($parentImgNum)
  2976. ->get()->all();
  2977. // 查询文字新闻
  2978. }
  2979. if ($parentTextNum != 0) {
  2980. $textBooks = [];
  2981. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2982. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2983. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2984. })
  2985. ->where('book.status', 2)
  2986. ->where('book.website_id', $website['website_id'])
  2987. ->leftJoin('website_category', function ($join) use ($website) {
  2988. $join->on('book.cat_id', '=', 'website_category.category_id')
  2989. ->where('website_category.website_id', '=', $website['website_id']);
  2990. })
  2991. ->select(
  2992. 'book.id',
  2993. 'book.title',
  2994. 'book.img_url',
  2995. 'book.price',
  2996. 'book.market_price',
  2997. 'book.description',
  2998. 'book.cat_id',
  2999. 'book.description',
  3000. 'book.updated_at',
  3001. 'website_category.alias as category_name',
  3002. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3003. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3004. )
  3005. ->orderBy('updated_at', 'desc')
  3006. ->limit($parentTextNum)
  3007. ->get()->all();
  3008. }
  3009. }
  3010. }
  3011. $resultItem = [
  3012. 'alias' => $parent_alias ?? '',
  3013. 'category_id' => $parentCatId ?? 0,
  3014. 'pinyin' => $parent_pinyin ?? null,
  3015. 'imgnum' => $imgBooks ?? [],
  3016. 'textnum' => $textBooks ?? [],
  3017. ];
  3018. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  3019. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  3020. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  3021. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3022. ->get()->all();
  3023. if (!empty($childCategory)) {
  3024. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  3025. // 查询子栏目名称
  3026. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  3027. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3028. ->first();
  3029. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  3030. $childImgArticles = [];
  3031. $childTextArticles = [];
  3032. $resultItem['child'] = [];
  3033. } else {
  3034. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  3035. // 查询子栏目图片新闻
  3036. $childImgArticles = Book::where('cat_id', $childCatId)
  3037. ->where('status', 2)
  3038. ->where('img_url', '!=', '')
  3039. ->where('book.website_id', $website['website_id'])
  3040. ->leftJoin('website_category', function ($join) use ($website) {
  3041. $join->on('book.cat_id', '=', 'website_category.category_id')
  3042. ->where('website_category.website_id', '=', $website['website_id']);
  3043. })
  3044. ->select(
  3045. 'book.id',
  3046. 'book.title',
  3047. 'book.img_url',
  3048. 'book.price',
  3049. 'book.market_price',
  3050. 'book.description',
  3051. 'book.cat_id',
  3052. 'book.description',
  3053. 'book.updated_at',
  3054. DB::raw("'$child_pinyin' as pinyin")
  3055. )
  3056. ->orderBy('updated_at', 'desc')
  3057. ->limit($childImgNum)
  3058. ->get()->all();
  3059. // 查询子栏目文字新闻
  3060. $childTextArticles = Book::where('cat_id', $childCatId)
  3061. ->where('status', 2)
  3062. ->where('book.website_id', $website['website_id'])
  3063. ->leftJoin('website_category', function ($join) use ($website) {
  3064. $join->on('book.cat_id', '=', 'website_category.category_id')
  3065. ->where('website_category.website_id', '=', $website['website_id']);
  3066. })
  3067. ->select(
  3068. 'book.id',
  3069. 'book.title',
  3070. 'book.img_url',
  3071. 'book.price',
  3072. 'book.market_price',
  3073. 'book.description',
  3074. 'book.cat_id',
  3075. 'book.description',
  3076. 'book.updated_at',
  3077. DB::raw("'$child_pinyin' as pinyin")
  3078. )
  3079. ->orderBy('updated_at', 'desc')
  3080. ->limit($childTextNum)
  3081. ->get()->all();
  3082. $resultItem['child'] = [
  3083. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  3084. 'category_id' => $childCatId,
  3085. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  3086. 'all_childcat' => $childCategory,
  3087. 'imgnum' => $childImgArticles,
  3088. 'textnum' => $childTextArticles,
  3089. ];
  3090. }
  3091. }
  3092. } else {
  3093. $resultItem['child'] = [];
  3094. }
  3095. return $resultItem;
  3096. }, $data);
  3097. return Result::success($result);
  3098. }
  3099. /**
  3100. * 获取书刊列表
  3101. * @param array $data
  3102. * @return array
  3103. * */
  3104. public function getWebsiteBookList(array $data): array
  3105. {
  3106. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3107. if (empty($web)) {
  3108. return Result::error("查询失败", 0);
  3109. }
  3110. $catid = $data['id'];
  3111. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  3112. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  3113. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  3114. $category_pinyin = $category ? $category->aLias_pinyin : '';
  3115. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  3116. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  3117. ->where('pid', $category['pid'])
  3118. ->select(
  3119. 'category_id',
  3120. 'alias',
  3121. 'aLIas_pinyin',
  3122. 'pid',
  3123. 'sort',
  3124. 'is_url',
  3125. 'web_url',
  3126. 'seo_title',
  3127. 'seo_keywords',
  3128. 'seo_description',
  3129. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  3130. )
  3131. ->orderBy('sort')
  3132. ->get()->all();
  3133. if (empty($category)) {
  3134. return Result::error("查询失败", 0);
  3135. }
  3136. $query = Book::where('book.status', 2)
  3137. ->where('book.website_id', $data['website_id'])
  3138. ->where('book.cat_id', $catid)
  3139. ->select(
  3140. 'book.id',
  3141. 'book.title',
  3142. 'book.img_url',
  3143. 'book.description',
  3144. 'book.updated_at',
  3145. 'book.cat_id',
  3146. DB::raw("'$pinyin' as pinyin")
  3147. )
  3148. ->orderBy('book.updated_at', 'desc');
  3149. $count = $query->count();
  3150. $query = clone $query;
  3151. $Book = $query
  3152. ->limit($data['pageSize'])
  3153. ->offset(($data['page'] - 1) * $data['pageSize'])
  3154. ->get()->all();
  3155. $result = [
  3156. 'category' => $categorys,
  3157. 'books' => $Book,
  3158. 'count' => $count,
  3159. ];
  3160. // if(empty($result)){
  3161. // return Result::error("查询失败", 0);
  3162. // }
  3163. return Result::success($result);
  3164. }
  3165. /**
  3166. * 获取书刊详情
  3167. * @param array $data
  3168. * @return array
  3169. * */
  3170. public function getWebsiteBookInfo(array $data): array
  3171. {
  3172. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3173. if (empty($web)) {
  3174. return Result::error("查询失败", 0);
  3175. }
  3176. $book = Book::where('status', 2)
  3177. ->where('website_id', $data['website_id'])
  3178. ->where('id', $data['id'])
  3179. ->select(
  3180. 'book.*',
  3181. )
  3182. ->orderBy('updated_at', 'desc')
  3183. ->first();
  3184. if (empty($book)) {
  3185. return Result::error("查询失败", 0);
  3186. }
  3187. // 先查询当前分类的 pid
  3188. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  3189. ->where('category_id', $book['cat_id'])
  3190. ->first(['pid', 'category_id']);
  3191. $query = WebsiteCategory::where('website_id', $data['website_id']);
  3192. if (!empty($carpid)) {
  3193. if ($carpid->pid != 0) {
  3194. $pid = $carpid['pid'];
  3195. // $parent_pinyin = '';
  3196. } else {
  3197. $pid = $carpid['category_id'];
  3198. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  3199. }
  3200. }
  3201. $categorys = $query->where('pid', $pid)
  3202. ->select(
  3203. 'category_id',
  3204. 'alias',
  3205. 'aLIas_pinyin',
  3206. 'pid',
  3207. 'sort',
  3208. 'is_url',
  3209. 'web_url',
  3210. 'category_arr_id as cat_arr_id',
  3211. )
  3212. ->orderBy('sort')
  3213. ->get();
  3214. $category = $this->processArticle($categorys, $data);
  3215. $result = [
  3216. 'category' => $category,
  3217. 'books' => $book,
  3218. ];
  3219. return Result::success($result);
  3220. }
  3221. /**
  3222. * 尝试
  3223. * @param array $data
  3224. * @return array
  3225. * */
  3226. public function test(array $data): array
  3227. {
  3228. $input['id'] = $data['id'];
  3229. $input['website_id'] = $data['website_id'];
  3230. // 将 JSON 字符串转换为 PHP 数组
  3231. $data = json_decode($input['id'], true);
  3232. $result = [];
  3233. $article = $data;
  3234. $result = array_map(function ($item) use ($input) {
  3235. $website = [
  3236. 'website_id' => $input['website_id'],
  3237. ];
  3238. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3239. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3240. $parent = [
  3241. 0 => $category['category_id'] ?? [],
  3242. 1 => $parentImgNum ?? [],
  3243. 2 => $parentTextNum ?? [],
  3244. ];
  3245. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  3246. $child = [];
  3247. $resultItem = [
  3248. // 'alias' => $parent_alias ?? '',
  3249. 'category_id' => $parentCatId ?? 0,
  3250. 'pinyin' => $parentImgNum ?? null,
  3251. 'imgnum' => $parentTextNum ?? [],
  3252. // 'textnum' => $textArticles ?? [],
  3253. ];
  3254. return $parent;
  3255. }, $data);
  3256. return Result::success($result);
  3257. // });
  3258. }
  3259. /**
  3260. * 封装处理文章的路由问题
  3261. * */
  3262. function processArticle($article, $data)
  3263. {
  3264. return $article->map(function ($article) use ($data) {
  3265. $catid = $article->cat_arr_id ?? '';
  3266. $level = json_decode($catid, true);
  3267. $pinyin = '';
  3268. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  3269. if (!empty($level) && is_array($level)) {
  3270. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  3271. ->where('website_id', $data['website_id'])
  3272. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3273. ->get(['aLIas_pinyin'])
  3274. ->pluck('aLIas_pinyin')
  3275. ->implode('/');
  3276. } else {
  3277. $pinyin = '';
  3278. }
  3279. $article->pinyin = $pinyin;
  3280. return $article;
  3281. });
  3282. }
  3283. /**
  3284. * c端-获取招工招聘下拉选框
  3285. * @param array $data
  3286. * @return array
  3287. * */
  3288. public function getWebsiteJobSelect(array $data): array
  3289. {
  3290. $web = Website::where('id', $data['website_id'])->first();
  3291. if (empty($web)) {
  3292. return Result::error("该网站不存在", 0);
  3293. }
  3294. $hy = JobIndustry::get()->all();
  3295. $zw = JobPosition::where('zwpid', 0)->get()->all();
  3296. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  3297. $result = [
  3298. 'hy' => $hy,
  3299. 'zw' => $zw,
  3300. 'jtzw' => $jtzw,
  3301. ];
  3302. if (empty($result)) {
  3303. return Result::error("查询失败", 0);
  3304. }
  3305. return Result::success($result);
  3306. }
  3307. /**
  3308. * c端-获取招工招聘
  3309. * @param array $data
  3310. * @return array
  3311. * */
  3312. public function getWebsiteJob(array $data): array
  3313. {
  3314. $web = Website::where('id', $data['website_id'])->first();
  3315. if (empty($web)) {
  3316. return Result::error("该网站不存在", 0);
  3317. }
  3318. $job_hunting = JobHunting::where('job_hunting.status', 2)
  3319. ->where('job_hunting.website_id', $data['website_id'])
  3320. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3321. $query->where(function ($q) use ($data) {
  3322. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3323. });
  3324. })
  3325. ->select(
  3326. 'job_hunting.id',
  3327. 'job_hunting.catid',
  3328. 'job_hunting.cat_arr_id',
  3329. 'job_hunting.job_name_get',
  3330. 'job_hunting.industry',
  3331. 'job_hunting.name',
  3332. 'job_hunting.sexy',
  3333. 'job_hunting.origin',
  3334. 'job_hunting.city_arr_id',
  3335. 'job_hunting.experience',
  3336. 'job_hunting.updated_at',
  3337. 'job_hunting.salary',
  3338. 'job_hunting.skillList',
  3339. 'job_hunting.slelf_evaluation',
  3340. )
  3341. ->orderBy('updated_at', 'desc')
  3342. ->limit($data['job1_num'])
  3343. ->get();
  3344. $web['website_id'] = $data['website_id'];
  3345. if (empty($job_hunting)) {
  3346. $job_huntings = "未查询到相关简历信息";
  3347. } else {
  3348. $job_huntings = $this->processJob($job_hunting, $web);
  3349. }
  3350. // 0:待审核 1:已通过 2:已拒绝
  3351. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3352. ->where('job_recruiting.website_id', $data['website_id'])
  3353. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3354. $query->where(function ($q) use ($data) {
  3355. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3356. });
  3357. })
  3358. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3359. ->select(
  3360. 'job_recruiting.id',
  3361. 'job_recruiting.catid',
  3362. 'job_recruiting.cat_arr_id',
  3363. 'job_recruiting.title',
  3364. 'job_recruiting.jtzw_id',
  3365. 'job_recruiting.hy_id',
  3366. 'job_recruiting.city_arr_id',
  3367. 'job_recruiting.due_data',
  3368. 'job_recruiting.updated_at',
  3369. 'job_recruiting.experience',
  3370. 'job_recruiting.educational',
  3371. 'job_recruiting.salary',
  3372. 'job_recruiting.zw_id',
  3373. 'job_company.business_name',
  3374. 'job_recruiting.keyword',
  3375. 'job_recruiting.description',
  3376. )
  3377. ->orderBy('updated_at', 'desc')
  3378. ->limit($data['job2_num'])
  3379. ->get();
  3380. if (empty($job_recruiting->toArray())) {
  3381. $job_recruitings = "未查询到相关职位信息";
  3382. } else {
  3383. $job_recruitings = $this->processJob($job_recruiting, $web);
  3384. }
  3385. $result = [
  3386. 'job_hunting' => $job_huntings,
  3387. 'job_recuiting' => $job_recruitings,
  3388. ];
  3389. return Result::success($result);
  3390. }
  3391. /**
  3392. * c端-获取招工招聘列表
  3393. * @param array $data
  3394. * @return array
  3395. * */
  3396. public function getWebsiteJobList(array $data): array
  3397. {
  3398. $recruit_where = [];
  3399. $hunt_where = [];
  3400. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3401. if (empty($web)) {
  3402. return Result::error("此网站不存在", 0);
  3403. }
  3404. $website_id['website_id'] = $data['website_id'];
  3405. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3406. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3407. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3408. }
  3409. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3410. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3411. }
  3412. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3413. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3414. }
  3415. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3416. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3417. }
  3418. $query = JobRecruiting::where('job_recruiting.status', 1)
  3419. ->where('job_recruiting.website_id', $data['website_id'])
  3420. ->where($recruit_where)
  3421. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3422. $query->where(function ($q) use ($data) {
  3423. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3424. });
  3425. })
  3426. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3427. $query->where(function ($q) use ($data) {
  3428. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3429. });
  3430. })
  3431. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3432. ->select(
  3433. 'job_recruiting.id',
  3434. 'job_recruiting.catid',
  3435. 'job_recruiting.hy_id',
  3436. 'job_recruiting.title',
  3437. 'job_recruiting.zw_id',
  3438. 'job_recruiting.educational',
  3439. 'job_recruiting.jtzw_id',
  3440. 'job_recruiting.city_arr_id',
  3441. 'job_recruiting.due_data',
  3442. 'job_recruiting.experience',
  3443. 'job_recruiting.cat_arr_id',
  3444. 'job_recruiting.updated_at',
  3445. 'job_company.business_name',
  3446. 'job_recruiting.keyword',
  3447. 'job_recruiting.description',
  3448. )
  3449. ->orderBy('job_recruiting.updated_at', 'desc');
  3450. $recruit_count = $query->count();
  3451. $query = clone $query;
  3452. $JobRecruiting = $query
  3453. ->offset(($data['page'] - 1) * $data['pageSize'])
  3454. ->limit($data['pageSize'])
  3455. ->get();
  3456. if (empty($JobRecruiting)) {
  3457. $JobRecruiting = "暂无相关职位信息";
  3458. } else {
  3459. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3460. }
  3461. }
  3462. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3463. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3464. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3465. }
  3466. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3467. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3468. }
  3469. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3470. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3471. }
  3472. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3473. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3474. }
  3475. $query = JobHunting::where('job_hunting.status', 2)
  3476. ->where('job_hunting.website_id', $data['website_id'])
  3477. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3478. ->where($hunt_where)
  3479. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3480. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3481. // })
  3482. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3483. $query->where(function ($q) use ($data) {
  3484. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3485. });
  3486. })
  3487. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3488. $query->where(function ($q) use ($data) {
  3489. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3490. });
  3491. })
  3492. ->select(
  3493. 'job_hunting.id',
  3494. 'job_hunting.catid',
  3495. 'job_hunting.sexy',
  3496. 'job_hunting.experience',
  3497. 'job_hunting.origin',
  3498. 'job_hunting.industry',
  3499. 'job_hunting.name',
  3500. 'job_hunting.job',
  3501. 'job_hunting.job_name_get',
  3502. 'job_hunting.city_arr_id',
  3503. 'job_hunting.cat_arr_id',
  3504. 'job_hunting.created_at',
  3505. 'job_hunting.updated_at',
  3506. 'job_position.zwname as job_name',
  3507. 'job_hunting.skillList',
  3508. 'job_hunting.slelf_evaluation',
  3509. )
  3510. ->orderBy('job_hunting.updated_at', 'desc');
  3511. $hunt_count = $query->count();
  3512. $query = clone $query;
  3513. $JobHunting = $query
  3514. ->offset(($data['page'] - 1) * $data['pageSize'])
  3515. ->limit($data['pageSize'])
  3516. ->get();
  3517. if (empty($JobHunting)) {
  3518. $JobRecruiting = "暂无相关简历信息";
  3519. } else {
  3520. $JobHunting = $this->processJob($JobHunting, $website_id);
  3521. }
  3522. }
  3523. $result = [
  3524. 'JobRecruiting' => $JobRecruiting ?? [],
  3525. 'recruit_count' => $recruit_count ?? 0,
  3526. 'JobHunting' => $JobHunting ?? [],
  3527. 'hunt_count' => $hunt_count ?? 0,
  3528. ];
  3529. return Result::success($result);
  3530. }
  3531. /**
  3532. * c端-获取招工招聘详情
  3533. * @param array $data
  3534. * @return array
  3535. * */
  3536. public function getWebsiteJobInfo(array $data): array
  3537. {
  3538. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3539. if (empty($web)) {
  3540. return Result::error("该网站不存在", 0);
  3541. }
  3542. $webid = [
  3543. 'website_id' => $data['website_id'],
  3544. ];
  3545. // 职位相关信息
  3546. if ($data['type'] == 1) {
  3547. $query = JobRecruiting::where('status', 1)
  3548. ->where('website_id', $data['website_id'])
  3549. ->select('*');
  3550. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3551. $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();
  3552. if (!empty($company)) {
  3553. $result['company'] = $this->processJob($company, $webid);
  3554. }
  3555. $other_job = JobRecruiting::where('status', 1)
  3556. ->where('website_id', $data['website_id'])
  3557. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3558. ->where('id', '!=', $data['id'])
  3559. ->where('user_id', '=', $job[0]['user_id'])
  3560. ->limit($data['pageSize'])
  3561. ->get();
  3562. if (!empty($other_job)) {
  3563. $result['other_job'] = $this->processJob($other_job, $webid);
  3564. }
  3565. } else {
  3566. // 简历相关信息
  3567. $job = JobHunting::where('job_hunting.status', 2)
  3568. ->where('job_hunting.website_id', $data['website_id'])
  3569. ->where('job_hunting.id', $data['id'])
  3570. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3571. ->select('job_hunting.*', 'user_name')
  3572. ->get();
  3573. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3574. if (!empty($resume->toArray())) {
  3575. $result['resume'] = 1;
  3576. } else {
  3577. $result['resume'] = 0;
  3578. }
  3579. }
  3580. if (empty($job->toArray())) {
  3581. return Result::error("id参数错误", 0);
  3582. }
  3583. if (!empty($job[0]['job_experience'])) {
  3584. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3585. if (!empty($job_experience)) {
  3586. // $hy = [];
  3587. foreach ($job_experience as $key => $value) {
  3588. // $id = $value['id'];
  3589. $hy[$key] = $value['job_industry'];
  3590. $zw_id[$key] = $value['job_typename'];
  3591. $jtzw_id[$key] = $value['job_name'];
  3592. }
  3593. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3594. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3595. // 先将关联表转换为索引数组,提高查找效率
  3596. $hyLookup = [];
  3597. foreach ($hy_table as $item) {
  3598. $hyLookup[$item['hyid']] = $item['hyname'];
  3599. }
  3600. $zwLookup = [];
  3601. foreach ($zw_table as $item) {
  3602. $zwLookup[$item['zwid']] = $item['zwname'];
  3603. }
  3604. foreach ($job_experience as $key => &$value) {
  3605. // 处理行业名称
  3606. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3607. $value['hy_name'] = $hyLookup[$hy[$key]];
  3608. }
  3609. // 处理职位名称
  3610. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3611. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3612. }
  3613. // 处理具体职位名称
  3614. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3615. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3616. }
  3617. }
  3618. // 释放引用,防止意外修改后续代码
  3619. unset($value);
  3620. }
  3621. $result['job_experience'] = $job_experience ?? [];
  3622. }
  3623. if (!empty($job[0]['education_experience'])) {
  3624. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3625. if (!empty($education_experience)) {
  3626. foreach ($education_experience as $key => $value) {
  3627. // $id = $value['id'];
  3628. $education[$key] = $value['school_education'];
  3629. }
  3630. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3631. // // 先将关联表转换为索引数组,提高查找效率
  3632. $educationLookup = [];
  3633. foreach ($education_table as $item) {
  3634. $educationLookup[$item['evalue']] = $item['ename'];
  3635. }
  3636. foreach ($education_experience as $key => &$value) {
  3637. // 处理学历名称
  3638. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3639. $value['education_name'] = $educationLookup[$education[$key]];
  3640. }
  3641. }
  3642. }
  3643. $result['education_experience'] = $job_experience ?? [];
  3644. }
  3645. $result['job'] = $this->processJob($job, $webid);
  3646. // // 返现对应的栏目
  3647. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3648. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3649. ->whereIn('category_id', $catid)
  3650. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3651. ->orderBy('pid')->get()->all();
  3652. if (!empty($category)) {
  3653. $result['category'] = $category;
  3654. }
  3655. $result['job'] = $job;
  3656. $result['job_experience'] = $job_experience ?? [];
  3657. $result['education_experience'] = $education_experience ?? [];
  3658. if (empty($result)) {
  3659. return Result::error("参数错误", 0);
  3660. }
  3661. return Result::success($result);
  3662. }
  3663. /**
  3664. * c端-申请职位
  3665. * @param array $data
  3666. * @return array
  3667. * */
  3668. public function getWebsiteJobApply(array $data): array
  3669. {
  3670. // 首先验证网站是否存在
  3671. // return Result::success($data);
  3672. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3673. if (empty($web)) {
  3674. return Result::error("该网站不存在", 0);
  3675. }
  3676. // 验证用户是否存在且为个人会员/管理员
  3677. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3678. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3679. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3680. return Result::error("用户不存在", 0);
  3681. }
  3682. // 去除重复元素和空元素,并保持原始顺序
  3683. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3684. return !empty($value);
  3685. }));
  3686. // 验证职位是否存在 1:审核通过
  3687. $recruiting = JobRecruiting::where('status', 1)
  3688. ->where('website_id', $data['website_id'])
  3689. ->whereIn('id', $data['recruit_id'])
  3690. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3691. if (empty($recruiting)) {
  3692. return Result::error("该职位不存在", 0);
  3693. }
  3694. // 简历是否存在
  3695. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3696. if (empty($hunt_id)) {
  3697. return Result::error("该简历不存在", 0);
  3698. }
  3699. $data['hunt_id'] = $hunt_id['hunt_id'];
  3700. // // 验证是否已投递过该职位
  3701. $apply = JobApply::where('user_id', $data['user_id'])
  3702. ->where('hunt_id', $data['hunt_id'])
  3703. ->where('website_id', $data['website_id'])
  3704. ->whereIn('recruit_id', $data['recruit_id'])
  3705. ->get(['recruit_id']);
  3706. if (!empty($apply->toArray())) {
  3707. return Result::error("您已投递过该职位!");
  3708. }
  3709. $insertData = array_map(function ($recruiting) use ($data) {
  3710. return [
  3711. 'user_id' => $data['user_id'],
  3712. 'hunt_id' => $data['hunt_id'],
  3713. 'website_id' => $data['website_id'],
  3714. 'recruit_id' => $recruiting['recruit_id'],
  3715. 'receiver_id' => $recruiting['receiver_id'],
  3716. 'status' => 1,
  3717. ];
  3718. }, $recruiting);
  3719. // 批量插入数据
  3720. $result = JobApply::insert($insertData);
  3721. if (empty($result)) {
  3722. return Result::error("投递失败", 0);
  3723. }
  3724. return Result::success($result);
  3725. }
  3726. /**
  3727. * 招工招聘-沟通简历
  3728. * @param array $data
  3729. * @return array
  3730. * */
  3731. public function getWebsiteJobResume(array $data): array
  3732. {
  3733. // 首先验证网站是否存在
  3734. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3735. if (empty($web)) {
  3736. return Result::error("该网站不存在", 0);
  3737. }
  3738. // return Result::success($data);
  3739. // 验证用户是否存在且为企业会员/管理员
  3740. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3741. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3742. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3743. return Result::error("用户不存在", 0);
  3744. }
  3745. // 去除重复元素和空元素,并保持原始顺序
  3746. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3747. return !empty($value);
  3748. }));
  3749. // 验证简历是否存在
  3750. $hunting = JobHunting::where('status', 2)
  3751. ->where('website_id', $data['website_id'])
  3752. ->whereIn('id', $data['hunt_id'])
  3753. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3754. if (empty($hunting)) {
  3755. return Result::error("该简历不存在", 0);
  3756. }
  3757. // 验证是否已沟通过该简历
  3758. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3759. ->where('recruit_id', $data['recruit_id'])
  3760. ->where('website_id', $data['website_id'])
  3761. ->whereIn('hunt_id', $data['hunt_id'])
  3762. ->get(['hunt_id']);
  3763. if (!empty($remuse->toArray())) {
  3764. return Result::error("您已沟通过该简历!");
  3765. }
  3766. // 准备要插入的数据数组
  3767. $insertData = array_map(function ($hunting) use ($data) {
  3768. return [
  3769. 'user_id' => $data['user_id'],
  3770. 'recruit_id' => $data['recruit_id'],
  3771. 'website_id' => $data['website_id'],
  3772. 'hunt_id' => $hunting['hunt_id'],
  3773. 'receiver_id' => $hunting['receiver_id'],
  3774. 'status' => 1,
  3775. ];
  3776. }, $hunting);
  3777. // 批量插入数据
  3778. $result = JobRemuse::insert($insertData);
  3779. if (empty($result)) {
  3780. return Result::error("沟通失败", 0);
  3781. }
  3782. return Result::success($result);
  3783. }
  3784. /**
  3785. * 招工招聘 -我的职位(企业会员)
  3786. * @param array $data
  3787. * @return array
  3788. */
  3789. public function getWebsiteJobRecruiting(array $data): array
  3790. {
  3791. $web = Website::where('id', $data['website_id'])->first('id');
  3792. if (empty($web)) {
  3793. return Result::error("该网站不存在", 0);
  3794. }
  3795. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3796. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3797. return Result::error("用户暂无权限!", 0);
  3798. }
  3799. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3800. $result = JobRecruiting::where('website_id', $data['website_id'])
  3801. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3802. $query->where('user_id', $user['id']);
  3803. })
  3804. ->where('status', 1)
  3805. ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
  3806. ->orderBy('updated_at', 'desc')
  3807. ->limit($data['pageSize'])
  3808. ->get();
  3809. if (empty($result)) {
  3810. return Result::error("暂无相关职位信息", 0);
  3811. }
  3812. return Result::success($result);
  3813. }
  3814. /**
  3815. * c端 - 验证路由
  3816. * @param array $data
  3817. * @return array
  3818. */
  3819. /**
  3820. * c端 - 验证路由
  3821. * @param array $data
  3822. * @return array
  3823. */
  3824. public function checkWebsiteRoute(array $data): array
  3825. {
  3826. // 测试001111111222
  3827. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3828. if (empty($web)) {
  3829. return Result::error("该网站不存在", 0);
  3830. } elseif ($web['status'] != 1) {
  3831. return Result::error("网站已经关闭", 0);
  3832. }
  3833. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3834. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3835. // 验证路由是否存在
  3836. if (empty($whiteRouterInfo)) {
  3837. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  3838. }
  3839. if (!empty($whiteRouterInfo)) {
  3840. return Result::success($whiteRouterInfo->toArray());
  3841. }
  3842. }
  3843. // 验证栏目路由
  3844. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3845. ->where('path', $data['all_route'])
  3846. ->get()->all();
  3847. if (count($last_category) == 0) {
  3848. return Result::error("该栏目不存在", 0);
  3849. }
  3850. if (count($last_category) > 1) {
  3851. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  3852. }
  3853. if (count($last_category) == 1) {
  3854. $last_category = $last_category[0];
  3855. }
  3856. // return Result::success($last_category);
  3857. if (isset($data['id']) && !empty($data['id'])) {
  3858. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3859. switch ($last_category['type']) {
  3860. case 1:
  3861. // 文章
  3862. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3863. $article = Article::where('status', 1)
  3864. ->where('id', $data['id'])
  3865. ->where(function ($query) use ($data) {
  3866. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3867. ->orWhereNull("ignore_ids");
  3868. })
  3869. ->first(['catid']);
  3870. if (empty($article)) {
  3871. return Result::error("该文章不存在", 0);
  3872. }
  3873. // return Result::success($article);
  3874. break;
  3875. case 2:
  3876. // 商品
  3877. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3878. $article = Good::where('website_id', $data['website_id'])
  3879. ->where('status', 2)
  3880. ->where('id', $data['id'])
  3881. ->first(['cat_arr_id']);
  3882. if (empty($article)) {
  3883. return Result::error("该商品不存在", 0);
  3884. }
  3885. break;
  3886. case 3:
  3887. // 书刊信息
  3888. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3889. $article = Book::where('website_id', $data['website_id'])
  3890. ->where('status', 2)
  3891. ->where('id', $data['id'])
  3892. ->first(['id', 'cat_arr_id']);
  3893. if (empty($article)) {
  3894. return Result::error("该书刊不存在", 0);
  3895. }
  3896. break;
  3897. case 4:
  3898. // 招聘
  3899. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  3900. $article = JobRecruiting::where('website_id', $data['website_id'])
  3901. ->where('status', 1)
  3902. ->where('id', $data['id'])
  3903. ->first(['cat_arr_id']);
  3904. if (empty($article)) {
  3905. return Result::error("该招聘不存在", 0);
  3906. }
  3907. break;
  3908. case 5:
  3909. // 求职
  3910. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3911. $article = JobHunting::where('website_id', $data['website_id'])
  3912. ->where('status', 2)
  3913. ->where('id', $data['id'])
  3914. ->first(['cat_arr_id']);
  3915. if (empty($article)) {
  3916. return Result::error("该求职不存在", 0);
  3917. }
  3918. break;
  3919. case 6:
  3920. // 企业
  3921. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3922. $article = Company::
  3923. // where('website_id', $data['website_id'])
  3924. // ->
  3925. where('status', 1)
  3926. ->where('id', $data['id'])
  3927. ->first(['cat_arr_id']);
  3928. if (empty($article)) {
  3929. return Result::error("该企业不存在", 0);
  3930. }
  3931. break;
  3932. case 7:
  3933. // 项目
  3934. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3935. $article = Project::where('website_id', $data['website_id'])
  3936. ->where('status', 1)
  3937. ->where('id', $data['id'])
  3938. ->first(['cat_arr_id']);
  3939. if (empty($article)) {
  3940. return Result::error("该项目不存在", 0);
  3941. }
  3942. break;
  3943. default:
  3944. return Result::error("该数据不存在", 0);
  3945. break;
  3946. }
  3947. // return Result::success($article);
  3948. // $catid =0 ;
  3949. if (!isset($article['cat_arr_id'])) {
  3950. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  3951. } else {
  3952. $catidArray = json_decode($article['cat_arr_id'], true);
  3953. $catid = !empty($catidArray) ? end($catidArray) : null;
  3954. }
  3955. // return Result::success($catid);
  3956. // // return Result::success($article['cat_arr_id']);
  3957. if (empty($catid)) {
  3958. return Result::error("该栏目路径不存在", 0);
  3959. }
  3960. $path = WebsiteCategory::where('website_id', $data['website_id'])
  3961. ->where('category_id', $catid)
  3962. ->first('path');
  3963. }
  3964. // else{
  3965. // // if ($last_category['pid'] != 0) {
  3966. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  3967. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  3968. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3969. // ->where('category_id',$catid)
  3970. // ->where('path',$data['all_route'])
  3971. // ->first('path');
  3972. // // } else {
  3973. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  3974. // // }
  3975. // }
  3976. // return Result::success($path);
  3977. if (!empty($path) && $path['path'] != $data['all_route']) {
  3978. return Result::error('非法路径!');
  3979. } else {
  3980. return Result::success($last_category['path']);
  3981. }
  3982. }
  3983. /**
  3984. * 招工招聘 - 获取推荐职位
  3985. * @param array $data
  3986. * @return array
  3987. */
  3988. public function getWebsiteLevelJob(array $data): array
  3989. {
  3990. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3991. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  3992. ->where('job_recruiting.status', 1)
  3993. ->where('job_level', $data['job_level'])
  3994. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3995. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  3996. ->orderBy('job_recruiting.updated_at', 'desc')
  3997. ->limit($data['pageSize'])
  3998. ->get();
  3999. $web = ['website_id' => $data['website_id']];
  4000. if (!empty($job)) {
  4001. $result = $this->processJob($job, $web);
  4002. }
  4003. if (empty($result)) {
  4004. return Result::error("暂无相关职位信息", 0);
  4005. }
  4006. return Result::success($result);
  4007. }
  4008. /**
  4009. * 验证导航名称是否重复
  4010. * @return void
  4011. */
  4012. //20250226 产品列表
  4013. public function getGoodList(array $data): array
  4014. {
  4015. var_dump($data, '---------1-2--');
  4016. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  4017. unset($data['user_type_id']);
  4018. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4019. $where = [];
  4020. if ($type_id != '10000') {
  4021. $where = [
  4022. 'good.user_id' => $user_id,
  4023. ];
  4024. }
  4025. //类型
  4026. if (isset($data['type_id']) && $data['type_id']) {
  4027. $where['good.type_id'] = $data['type_id'];
  4028. }
  4029. //名称
  4030. if (isset($data['name']) && $data['name']) {
  4031. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  4032. }
  4033. //status
  4034. if (isset($data['status']) && $data['status'] != '') {
  4035. $where['good.status'] = $data['status'];
  4036. }
  4037. //status1
  4038. // if (isset($data['status1']) && $data['status1'] == 1) {
  4039. // $status1 = 1;
  4040. // }
  4041. $where1 = [];
  4042. //website_id
  4043. // if (isset($data['website_id']) && $data['website_id']) {
  4044. // $where1 = [
  4045. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  4046. // ];
  4047. // }
  4048. // website_name
  4049. if (isset($data['website_name']) && $data['website_name']) {
  4050. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  4051. }
  4052. // catid
  4053. if (isset($data['category_name']) && $data['category_name']) {
  4054. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  4055. }
  4056. // $result = Good::where($where)
  4057. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  4058. var_dump($where, '---------1---');
  4059. $result = Good::where($where)
  4060. ->when(!empty($where1), function ($query) use ($where1) {
  4061. return $query->where($where1);
  4062. })
  4063. //status 1待审核2已审核3已拒绝
  4064. ->when(isset($data['status1']), function ($query) {
  4065. return $query->whereIn('good.status', [1, 3]);
  4066. })
  4067. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4068. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4069. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4070. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4071. ->orderBy("updated_at", "desc")
  4072. ->limit($data['page_size'])
  4073. ->offset(($data['page'] - 1) * $data['page_size'])
  4074. ->get();
  4075. $count = Good::where($where)
  4076. ->when(!empty($where1), function ($query) use ($where1) {
  4077. return $query->where($where1);
  4078. })
  4079. //status 1待审核2已审核3已拒绝
  4080. ->when(isset($data['status1']), function ($query) {
  4081. return $query->whereIn('good.status', [1, 3]);
  4082. })
  4083. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4084. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4085. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4086. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4087. ->orderBy("updated_at", "desc")->count();
  4088. $data = [
  4089. 'rows' => $result->toArray(),
  4090. 'count' => $count,
  4091. ];
  4092. if (empty($result)) {
  4093. return Result::error("此栏目暂无相关产品", 0);
  4094. }
  4095. return Result::success($data);
  4096. }
  4097. public function getGoodInfo(array $data): array
  4098. {
  4099. $result = Good::where('id', $data['id'])->first();
  4100. if (empty($result)) {
  4101. return Result::error("此产品不存在", 0);
  4102. }
  4103. return Result::success($result);
  4104. }
  4105. public function addGood(array $data): array
  4106. {
  4107. // unset($data['city_arr_id']);
  4108. // unset($data['cat_arr_id']);
  4109. $data['city_id'] = end($data['city_arr_id']);
  4110. $data['catid'] = end($data['cat_arr_id']);
  4111. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4112. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4113. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4114. unset($data['imgUrl']); //大小写
  4115. if (isset($data['price']) && $data['price'] == '') {
  4116. $data['price'] = 0;
  4117. }
  4118. if ($data['imgurl'] == '') {
  4119. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4120. preg_match_all($reg, $data['detail'], $matches);
  4121. if (isset($matches[1][0])) {
  4122. //截取varchar240
  4123. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4124. }
  4125. }
  4126. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4127. //提取标题+内容中的关键词
  4128. $data['keyword'] = $data['name'];
  4129. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4130. Jieba::init(); // 初始化 jieba-php
  4131. Finalseg::init();
  4132. $segList = Jieba::cut($data['keyword']);
  4133. $segList1 = array_slice($segList, 0, 8);
  4134. $data['keyword'] = implode(',', $segList1);
  4135. }
  4136. if ($data['description'] == '') {
  4137. //提取内容中的描述
  4138. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4139. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4140. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4141. }
  4142. if ($data['status'] == 1) {
  4143. $this->sendMessage([
  4144. 'talk_type' => 200,
  4145. 'title' => $data['name'],
  4146. 'content' => '提交了审核',
  4147. 'messageType' => 3,
  4148. ]);
  4149. }
  4150. $result = Good::insert($data);
  4151. if (empty($result)) {
  4152. return Result::error("添加失败", 0);
  4153. }
  4154. return Result::success($result);
  4155. }
  4156. public function updateGood(array $data): array
  4157. {
  4158. $data['city_id'] = end($data['city_arr_id']);
  4159. $data['catid'] = end($data['cat_arr_id']);
  4160. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4161. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4162. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4163. //设置东八区
  4164. date_default_timezone_set('Asia/Shanghai');
  4165. $data['updated_at'] = date('Y-m-d H:i:s');
  4166. if (isset($data['price']) && $data['price'] == '') {
  4167. $data['price'] = 0;
  4168. }
  4169. if ($data['imgurl'] == '') {
  4170. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4171. preg_match_all($reg, $data['detail'], $matches);
  4172. if (isset($matches[1][0])) {
  4173. //截取varchar240
  4174. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4175. }
  4176. }
  4177. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4178. //提取标题+内容中的关键词
  4179. $data['keyword'] = $data['name'];
  4180. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4181. Jieba::init(); // 初始化 jieba-php
  4182. Finalseg::init();
  4183. $segList = Jieba::cut($data['keyword']);
  4184. $segList1 = array_slice($segList, 0, 8);
  4185. $data['keyword'] = implode(',', $segList1);
  4186. }
  4187. if ($data['description'] == '') {
  4188. //提取内容中的描述
  4189. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4190. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4191. }
  4192. if ($data['status'] == 1) {
  4193. $this->sendMessage([
  4194. 'talk_type' => 200,
  4195. 'title' => $data['name'],
  4196. 'content' => '提交了审核',
  4197. 'messageType' => 3,
  4198. ]);
  4199. }
  4200. $result = Good::where('id', $data['id'])->update($data);
  4201. if (empty($result)) {
  4202. return Result::error("更新失败", 0);
  4203. }
  4204. return Result::success($result);
  4205. }
  4206. public function delGood(array $data): array
  4207. {
  4208. $result = Good::where('id', $data['id'])->delete();
  4209. if (empty($result)) {
  4210. return Result::error("删除失败", 0);
  4211. }
  4212. return Result::success($result);
  4213. }
  4214. //20250226 产品列表
  4215. //20250306 求职信息
  4216. public function getJobHuntingList(array $data): array
  4217. {
  4218. $where = [];
  4219. if (isset($data['username']) && !empty($data['username'])) {
  4220. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4221. }
  4222. //status 1待审核2已审核3已拒绝
  4223. if (isset($data['status']) && $data['status'] != '') {
  4224. $where = [
  4225. 'job_hunting.status' => $data['status'],
  4226. ];
  4227. }
  4228. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4229. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4230. unset($data['type_id']);
  4231. if ($type_id != '10000') {
  4232. $where[] = ['job_hunting.user_id', '=', $user_id];
  4233. }
  4234. $result = JobHunting::where($where)
  4235. ->when(!empty($data['status1']), function ($query) use ($data) {
  4236. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4237. })
  4238. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4239. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4240. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  4241. ->orderBy("updated_at", "desc")
  4242. ->limit($data['page_size'])
  4243. ->offset(($data['page'] - 1) * $data['page_size'])
  4244. ->get();
  4245. if (empty($result)) {
  4246. return Result::error("查询失败", 0);
  4247. }
  4248. $count = JobHunting::where($where)
  4249. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4250. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4251. ->count();
  4252. $data = [
  4253. 'rows' => $result->toArray(),
  4254. 'count' => $count,
  4255. ];
  4256. return Result::success($data);
  4257. }
  4258. public function getJobHuntingApply(array $data): array
  4259. {
  4260. var_dump($data, '-----------------test--------1-');
  4261. $where = [];
  4262. if (isset($data['username']) && !empty($data['username'])) {
  4263. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4264. }
  4265. if (isset($data['salary']) && !empty($data['salary'])) {
  4266. $where[] = [
  4267. 'job_hunting.salary',
  4268. '=',
  4269. $data['salary'],
  4270. ];
  4271. }
  4272. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4273. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4274. unset($data['type_id']);
  4275. if ($type_id != '10000') {
  4276. $where[] = ['job_apply.receiver_id', '=', $user_id];
  4277. }
  4278. var_dump($where, '-----------------test---------');
  4279. $result = jobApply::where($where)
  4280. // ->when(!empty($data['status1']), function ($query) use ($data) {
  4281. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4282. // })
  4283. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  4284. ->where('job_enum.egroup', '=', 'income')
  4285. ->where('job_hunting.status', 2) //已审核
  4286. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4287. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4288. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4289. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4290. //职位----是申请职位
  4291. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4292. ->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')
  4293. ->orderBy("job_hunting.updated_at", "desc")
  4294. ->limit($data['page_size'])
  4295. ->offset(($data['page'] - 1) * $data['page_size'])
  4296. ->get();
  4297. if (empty($result)) {
  4298. return Result::error("查询失败", 0);
  4299. }
  4300. $count = jobApply::where($where)
  4301. ->where('job_enum.egroup', '=', 'income')
  4302. ->where('job_hunting.status', 2) //已审核
  4303. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4304. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4305. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4306. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4307. //职位----是申请职位
  4308. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4309. ->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')
  4310. ->count();
  4311. $data = [
  4312. 'rows' => $result->toArray(),
  4313. 'count' => $count,
  4314. ];
  4315. return Result::success($data);
  4316. }
  4317. public function addJobHunting(array $data): array
  4318. {
  4319. date_default_timezone_set('Asia/Shanghai');
  4320. unset($data['company_name']);
  4321. unset($data['job_industry']);
  4322. unset($data['job_name']);
  4323. unset($data['department']);
  4324. unset($data['job_timeList']);
  4325. unset($data['job_content']);
  4326. unset($data['job_typename']); //不知道这是啥,
  4327. $data['created_at'] = date('Y-m-d H:i:s');
  4328. $data['updated_at'] = date('Y-m-d H:i:s');
  4329. //根据用户 user_id 只能添加一次
  4330. $result = JobHunting::where('user_id', $data['user_id'])->first();
  4331. if (!empty($result)) {
  4332. return Result::error("您已添加过求职信息", 0);
  4333. }
  4334. var_dump($result, '-----------------test---------');
  4335. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  4336. if (is_string($data['city_arr_id'])) {
  4337. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4338. $cityArr = json_decode($data['city_arr_id'], true);
  4339. // 确保 $cityArr 是数组
  4340. if (is_array($cityArr)) {
  4341. $data['city_id'] = end($cityArr);
  4342. }
  4343. } else {
  4344. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4345. if (is_array($data['city_arr_id'])) {
  4346. $data['city_id'] = end($data['city_arr_id']);
  4347. }
  4348. }
  4349. }
  4350. // 处理求职所绑定栏目
  4351. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4352. if (is_string($data['cat_arr_id'])) {
  4353. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4354. // 先清理可能存在的无效 JSON 字符
  4355. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4356. $catArr = json_decode($cleanedCatArrStr, true);
  4357. // 检查 JSON 解码是否成功且结果是数组
  4358. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4359. $data['catid'] = end($catArr);
  4360. }
  4361. } else {
  4362. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4363. if (is_array($data['cat_arr_id'])) {
  4364. $data['catid'] = end($data['cat_arr_id']);
  4365. }
  4366. }
  4367. }
  4368. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4369. $this->sendMessage([
  4370. 'talk_type' => 600,
  4371. 'title' => $data['name'],
  4372. 'content' => '提交了审核',
  4373. 'messageType' => 11,
  4374. ]);
  4375. }
  4376. $result = JobHunting::create($data);
  4377. if (empty($result)) {
  4378. return Result::error("添加失败", 0);
  4379. }
  4380. return Result::success($result);
  4381. }
  4382. public function delJobHunting(array $data): array
  4383. {
  4384. $result = JobHunting::where('id', $data['id'])->delete();
  4385. if (empty($result)) {
  4386. return Result::error("删除失败", 0);
  4387. }
  4388. return Result::success($result);
  4389. }
  4390. public function updateJobHunting(array $data): array
  4391. {
  4392. //设置东八区
  4393. date_default_timezone_set('Asia/Shanghai');
  4394. unset($data['company_name']);
  4395. unset($data['job_industry']);
  4396. unset($data['job_name']);
  4397. unset($data['department']);
  4398. unset($data['job_timeList']);
  4399. unset($data['job_content']);
  4400. unset($data['job_typename']); //不知道这是啥,
  4401. $data['created_at'] = date('Y-m-d H:i:s');
  4402. $data['updated_at'] = date('Y-m-d H:i:s');
  4403. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4404. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4405. $cityArr = json_decode($data['city_arr_id'], true);
  4406. $data['city_id'] = end($cityArr);
  4407. } else {
  4408. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4409. $data['city_id'] = end($data['city_arr_id']);
  4410. }
  4411. // 处理求职所绑定栏目
  4412. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4413. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4414. $catArr = json_decode($data['cat_arr_id'], true);
  4415. $data['catid'] = end($catArr);
  4416. } else {
  4417. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4418. $data['catid'] = end($data['cat_arr_id']);
  4419. }
  4420. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4421. $this->sendMessage([
  4422. 'talk_type' => 600,
  4423. 'title' => $data['name'],
  4424. 'content' => '提交了审核',
  4425. 'messageType' => 11,
  4426. ]);
  4427. }
  4428. $result = JobHunting::where('id', $data['id'])->update($data);
  4429. if (empty($result)) {
  4430. return Result::error("更新失败", 0);
  4431. }
  4432. return Result::success($result);
  4433. }
  4434. public function getJobHuntingInfo(array $data): array
  4435. {
  4436. $result = JobHunting::where('id', $data['id'])->first();
  4437. if (empty($result)) {
  4438. return Result::error("查询失败", 0);
  4439. }
  4440. return Result::success($result);
  4441. }
  4442. public function getJobHuntingData(array $data): array
  4443. {
  4444. $jobEnum = JobEnum::get();
  4445. $jobIndustry = JobIndustry::get();
  4446. $jobNature = JobNature::get();
  4447. $jobPosition = JobPosition::get();
  4448. $data = [
  4449. 'jobEnum' => $jobEnum,
  4450. 'jobIndustry' => $jobIndustry,
  4451. 'jobNature' => $jobNature,
  4452. 'jobPosition' => $jobPosition,
  4453. ];
  4454. return Result::success($data);
  4455. }
  4456. public function delJobHuntingInfo(array $data): array
  4457. {
  4458. $result = JobHunting::where('id', $data['id'])->delete();
  4459. return Result::success();
  4460. }
  4461. //20250324 通知,公告,消息
  4462. public function delNotice(array $data): array
  4463. {
  4464. $result = Notice::where('id', $data['id'])->delete();
  4465. if ($result) {
  4466. return Result::success();
  4467. } else {
  4468. return Result::error("删除失败", 0);
  4469. }
  4470. }
  4471. public function getNoticeInfo(array $data): array
  4472. {
  4473. $result = Notice::where('id', $data['id'])->first();
  4474. // var_dump($result['re_user_ids'], '--------------------');
  4475. if (empty($result)) {
  4476. return Result::error("查询失败", 0);
  4477. }
  4478. return Result::success($result);
  4479. }
  4480. public function readNotice(array $data): array
  4481. {
  4482. $result = Notice::where('id', $data['id'])->first();
  4483. // var_dump($result['re_user_ids'], '--------------------');
  4484. if (empty($result)) {
  4485. return Result::error("查询失败", 0);
  4486. }
  4487. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4488. $re_user_ids = json_decode($result['re_user_ids'], true);
  4489. var_dump($re_user_ids, '--------------1---test---------');
  4490. var_dump($data, '--------------1---test---------');
  4491. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4492. //如果已经存在,就不再添加
  4493. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4494. $read_id = json_decode($result['read_id'], true);
  4495. if (!is_array($read_id)) {
  4496. $read_id = [];
  4497. }
  4498. if (!in_array($data['user_id'], $read_id)) {
  4499. $read_id[] = $data['user_id'];
  4500. $result['read_id'] = json_encode($read_id);
  4501. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4502. }
  4503. } else {
  4504. //如果不存在,就添加
  4505. $result['read_id'] = json_encode([$data['user_id']]);
  4506. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4507. }
  4508. }
  4509. return Result::success($result);
  4510. }
  4511. public function addNotice(array $data): array
  4512. {
  4513. date_default_timezone_set('Asia/Shanghai');
  4514. $data['created_at'] = date('Y-m-d H:i:s');
  4515. $data['updated_at'] = date('Y-m-d H:i:s');
  4516. $user_id = UserInfo::
  4517. //city_id不是null
  4518. whereNotNull('city_id')
  4519. ->whereNotNull('department_id')
  4520. ->where(function ($query) use ($data) {
  4521. $query->where(function ($subQuery) use ($data) {
  4522. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4523. });
  4524. })
  4525. ->where(function ($query) use ($data) {
  4526. $query->where(function ($subQuery) use ($data) {
  4527. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4528. });
  4529. })
  4530. ->pluck('user_id')->toArray();
  4531. $user_id = array_unique($user_id);
  4532. $chat_ids = $user_id;
  4533. $user_id = json_encode($user_id);
  4534. $data['re_user_ids'] = $user_id;
  4535. $this->sendMessage([
  4536. 'talk_type' => 700,
  4537. 'title' => $data['title'],
  4538. 'content' => '提交了审核',
  4539. 'messageType' => 5,
  4540. ]);
  4541. $result = Notice::insertGetId($data);
  4542. if (empty($result)) {
  4543. return Result::error("添加失败", 0);
  4544. }
  4545. return Result::success($result);
  4546. }
  4547. public function updateNotice(array $data): array
  4548. {
  4549. date_default_timezone_set('Asia/Shanghai');
  4550. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4551. $user_id = UserInfo::
  4552. //city_id不是null
  4553. whereNotNull('city_id')
  4554. ->whereNotNull('department_id')
  4555. ->where(function ($query) use ($data) {
  4556. $query->where(function ($subQuery) use ($data) {
  4557. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4558. });
  4559. })
  4560. ->where(function ($query) use ($data) {
  4561. $query->where(function ($subQuery) use ($data) {
  4562. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4563. });
  4564. })
  4565. ->pluck('user_id')->toArray();
  4566. $user_id = array_unique($user_id);
  4567. $user_id = json_encode($user_id);
  4568. $data['re_user_ids'] = $user_id;
  4569. $data['updated_at'] = date('Y-m-d H:i:s');
  4570. $this->sendMessage([
  4571. 'talk_type' => 700,
  4572. 'title' => $data['title'],
  4573. 'content' => '提交了审核',
  4574. 'messageType' => 5,
  4575. ]);
  4576. $result = Notice::where('id', $data['id'])->update($data);
  4577. return Result::success($result);
  4578. }
  4579. public function getNoticeList(array $data): array
  4580. {
  4581. $where = [];
  4582. //title
  4583. if (isset($data['title']) && !empty($data['title'])) {
  4584. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4585. }
  4586. //level
  4587. if (isset($data['level']) && !empty($data['level'])) {
  4588. $where[] = ['notice.level', '=', $data['level']];
  4589. }
  4590. //status
  4591. if (isset($data['status']) && !empty($data['status'])) {
  4592. $where[] = ['notice.status', '=', $data['status']];
  4593. }
  4594. //type
  4595. if (isset($data['type']) && !empty($data['type'])) {
  4596. $where[] = ['notice.type', '=', $data['type']];
  4597. }
  4598. var_dump($data, '------------11111-2----test---------');
  4599. if ($data['type_id'] == 10000) {
  4600. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4601. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4602. })
  4603. ->where($where)
  4604. ->orderBy('updated_at', 'desc')
  4605. ->limit($data['page_size'])
  4606. ->offset(($data['page'] - 1) * $data['page_size'])
  4607. ->get();
  4608. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4609. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4610. })
  4611. ->where($where)
  4612. ->orderBy('updated_at', 'desc')
  4613. ->count();
  4614. } else {
  4615. $result = Notice::where($where)
  4616. // ->where('user_id', $data['user_id'])
  4617. ->Where(function ($query) use ($data) {
  4618. $query->Where(function ($q) use ($data) {
  4619. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4620. ->orWhere('notice.user_id', $data['user_id']);
  4621. });
  4622. })
  4623. ->when(!empty($data['status1']), function ($query) use ($data) {
  4624. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4625. })
  4626. ->orderBy('updated_at', 'desc')
  4627. ->limit($data['page_size'])
  4628. ->offset(($data['page'] - 1) * $data['page_size'])
  4629. ->get();
  4630. $total = Notice::where($where)
  4631. ->when(!empty($data['status1']), function ($query) use ($data) {
  4632. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4633. })
  4634. // ->where('user_id', $data['user_id'])
  4635. ->Where(function ($query) use ($data) {
  4636. $query->Where(function ($q) use ($data) {
  4637. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4638. ->orWhere('notice.user_id', $data['user_id']);
  4639. });
  4640. })
  4641. ->count();
  4642. }
  4643. if (empty($result)) {
  4644. return Result::error("查询失败", 0);
  4645. }
  4646. $data = [
  4647. 'rows' => $result,
  4648. 'count' => $total,
  4649. ];
  4650. return Result::success($data);
  4651. }
  4652. public function noticeList(array $data): array
  4653. {
  4654. $where = [];
  4655. //title
  4656. if (isset($data['title']) && !empty($data['title'])) {
  4657. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4658. }
  4659. //level
  4660. if (isset($data['level']) && !empty($data['level'])) {
  4661. $where[] = ['notice.level', '=', $data['level']];
  4662. }
  4663. //status
  4664. if (isset($data['status']) && !empty($data['status'])) {
  4665. $where[] = ['notice.status', '=', $data['status']];
  4666. }
  4667. //type
  4668. if (isset($data['type']) && !empty($data['type'])) {
  4669. $where[] = ['notice.type', '=', $data['type']];
  4670. }
  4671. var_dump($data, '------------11111-2----test---------');
  4672. if ($data['type_id'] == 10000) {
  4673. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4674. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4675. })
  4676. ->where($where)
  4677. ->orderBy('updated_at', 'desc')
  4678. ->limit($data['page_size'])
  4679. ->offset(($data['page'] - 1) * $data['page_size'])
  4680. ->get();
  4681. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4682. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4683. })
  4684. ->where($where)
  4685. ->orderBy('updated_at', 'desc')
  4686. ->count();
  4687. } else {
  4688. $result = Notice::where($where)
  4689. // ->where('user_id', $data['user_id'])
  4690. ->Where(function ($query) use ($data) {
  4691. $query->Where(function ($q) use ($data) {
  4692. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4693. ->orWhere('notice.user_id', $data['user_id']);
  4694. });
  4695. })
  4696. ->when(!empty($data['status1']), function ($query) use ($data) {
  4697. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4698. })
  4699. ->orderBy('updated_at', 'desc')
  4700. ->limit($data['page_size'])
  4701. ->offset(($data['page'] - 1) * $data['page_size'])
  4702. ->get();
  4703. $total = Notice::where($where)
  4704. ->when(!empty($data['status1']), function ($query) use ($data) {
  4705. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4706. })
  4707. // ->where('user_id', $data['user_id'])
  4708. ->Where(function ($query) use ($data) {
  4709. $query->Where(function ($q) use ($data) {
  4710. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4711. ->orWhere('notice.user_id', $data['user_id']);
  4712. });
  4713. })
  4714. ->count();
  4715. }
  4716. if (empty($result)) {
  4717. return Result::error("查询失败", 0);
  4718. }
  4719. $data = [
  4720. 'rows' => $result,
  4721. 'count' => $total,
  4722. ];
  4723. return Result::success($data);
  4724. }
  4725. public function getNoticeDetail(array $data): array
  4726. {
  4727. $result = Notice::where('id', $data['id'])->first();
  4728. if (empty($result)) {
  4729. return Result::error("查询失败", 0);
  4730. }
  4731. return Result::success($result);
  4732. }
  4733. public function deleteNotice(array $data): array
  4734. {
  4735. $notice = Notice::where('id', $data['id'])->first();
  4736. if (empty($notice)) {
  4737. return Result::error("删除失败", 0);
  4738. }
  4739. $chat_group_id = $notice->group_id;
  4740. if ($chat_group_id) {
  4741. //删除群聊
  4742. ChatGroups::where('id', $chat_group_id)->delete();
  4743. //删除群成员
  4744. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4745. //删除群聊记录
  4746. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4747. }
  4748. $result = Notice::where('id', $data['id'])->delete();
  4749. return Result::success($result);
  4750. }
  4751. public function complaintList(array $data): array
  4752. {
  4753. var_dump($data, '---------1---------');
  4754. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4755. unset($data['type_id']);
  4756. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4757. $where = [];
  4758. if ($type_id != 10000 && empty($data['deal_user'])) {
  4759. // $where['complaint.user_id'] = $user_id;
  4760. }
  4761. if (!empty($data['title'])) {
  4762. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4763. }
  4764. if (!empty($data['department_id'])) {
  4765. $where['complaint.department_id'] = $data['department_id'];
  4766. }
  4767. if (!empty($data['deal'])) {
  4768. $where['complaint.deal'] = $data['deal'];
  4769. }
  4770. if (!empty($data['status'])) {
  4771. $where['complaint.status'] = $data['status'];
  4772. }
  4773. var_dump(!empty($data['deal_user']), '----------1');
  4774. var_dump($where, '----------2');
  4775. $result = Complaint::where($where)
  4776. ->when(!empty($data['status1']), function ($query) use ($data) {
  4777. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4778. })
  4779. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4780. //json re_user_ids data[user_id]是不是在里面
  4781. $query->Where(function ($q) use ($data) {
  4782. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4783. ->where('complaint.status', 2);
  4784. });
  4785. })
  4786. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4787. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4788. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4789. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4790. ->orderBy('updated_at', 'desc')
  4791. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4792. //sql输出
  4793. if (empty($result)) {
  4794. return Result::error("暂无投诉信息", 0);
  4795. }
  4796. // 取出数据
  4797. $rows = $result->items();
  4798. $count = $result->total();
  4799. $responseData = [
  4800. 'rows' => $rows,
  4801. 'count' => $count,
  4802. ];
  4803. return Result::success($responseData);
  4804. }
  4805. public function getComplaintList(array $data): array
  4806. {
  4807. var_dump($data, '00000001000000000000');
  4808. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4809. unset($data['type_id']);
  4810. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4811. $where = [];
  4812. if ($type_id != 10000 && empty($data['deal_user'])) {
  4813. $where['complaint.user_id'] = $user_id;
  4814. }
  4815. if (!empty($data['title'])) {
  4816. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4817. }
  4818. if (!empty($data['department_id'])) {
  4819. $where['complaint.department_id'] = $data['department_id'];
  4820. }
  4821. if (!empty($data['deal'])) {
  4822. $where['complaint.deal'] = $data['deal'];
  4823. }
  4824. if (!empty($data['status'])) {
  4825. $where['complaint.status'] = $data['status'];
  4826. }
  4827. var_dump(!empty($data['deal_user']), '----------1');
  4828. var_dump($where, '----------2');
  4829. $result = Complaint::where($where)
  4830. ->when(!empty($data['status1']), function ($query) use ($data) {
  4831. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4832. })
  4833. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4834. // //json re_user_ids data[user_id]是不是在里面
  4835. // $query->Where(function ($q) use ($data) {
  4836. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4837. // ->where('complaint.status', 2);
  4838. // });
  4839. // })
  4840. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4841. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4842. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4843. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4844. ->orderBy('updated_at', 'desc')
  4845. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4846. //sql输出
  4847. if (empty($result)) {
  4848. return Result::error("暂无投诉信息", 0);
  4849. }
  4850. // 取出数据
  4851. $rows = $result->items();
  4852. $count = $result->total();
  4853. $responseData = [
  4854. 'rows' => $rows,
  4855. 'count' => $count,
  4856. ];
  4857. return Result::success($responseData);
  4858. }
  4859. public function getComplaintInfo(array $data): array
  4860. {
  4861. $result = Complaint::where('id', $data['id'])->first();
  4862. if (empty($result)) {
  4863. return Result::error("查询失败", 0);
  4864. }
  4865. return Result::success($result);
  4866. }
  4867. public function readComplaint(array $data): array
  4868. {
  4869. $result = Complaint::where('id', $data['id'])->first();
  4870. if (empty($result)) {
  4871. return Result::error("查询失败", 0);
  4872. }
  4873. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4874. $re_user_ids = json_decode($result['re_user_ids'], true);
  4875. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4876. //如果已经存在,就不再添加
  4877. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4878. $read_id = json_decode($result['read_id'], true);
  4879. if (!is_array($read_id)) {
  4880. $read_id = [];
  4881. }
  4882. if (!in_array($data['user_id'], $read_id)) {
  4883. $read_id[] = $data['user_id'];
  4884. $result['read_id'] = json_encode($read_id);
  4885. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4886. }
  4887. } else {
  4888. //如果不存在,就添加
  4889. $result['read_id'] = json_encode([$data['user_id']]);
  4890. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4891. }
  4892. }
  4893. return Result::success($result);
  4894. }
  4895. public function addComplaint(array $data): array
  4896. {
  4897. date_default_timezone_set('Asia/Shanghai');
  4898. $data['created_at'] = date('Y-m-d H:i:s');
  4899. $data['updated_at'] = date('Y-m-d H:i:s');
  4900. $this->sendMessage([
  4901. 'talk_type' => 800,
  4902. 'title' => $data['title'],
  4903. 'content' => '提交了审核',
  4904. 'messageType' => 6,
  4905. ]);
  4906. $result = Complaint::create($data);
  4907. return Result::success($result);
  4908. }
  4909. public function updateComplaint(array $data): array
  4910. {
  4911. date_default_timezone_set('Asia/Shanghai');
  4912. $data['updated_at'] = date('Y-m-d H:i:s');
  4913. $user_id = $data['user_id'] ?? 0;
  4914. $type_id = $data['type_id'] ?? 0;
  4915. unset($data['user_id']);
  4916. unset($data['type_id']);
  4917. $this->sendMessage([
  4918. 'talk_type' => 800,
  4919. 'title' => $data['title'],
  4920. 'content' => '提交了审核',
  4921. 'messageType' => 6,
  4922. ]);
  4923. $result = Complaint::where('id', $data['id'])->update($data);
  4924. return Result::success($result);
  4925. }
  4926. public function deleteComplaint(array $data): array
  4927. {
  4928. $result = Complaint::where('id', $data['id'])->delete();
  4929. return Result::success($result);
  4930. }
  4931. public function getComplainInfo(array $data): array
  4932. {
  4933. $result = Complaint::where('id', $data['id'])->first();
  4934. if (empty($result)) {
  4935. return Result::error("查询失败", 0);
  4936. }
  4937. return Result::success($result);
  4938. }
  4939. public function updateComplaintStatus(array $data): array
  4940. {
  4941. date_default_timezone_set('Asia/Shanghai');
  4942. $data['updated_at'] = date('Y-m-d H:i:s');
  4943. $user_id = $data['user_id'] ?? 0;
  4944. $type_id = $data['type_id'] ?? 0;
  4945. unset($data['user_id']);
  4946. unset($data['type_id']);
  4947. //处理, 写入处理人
  4948. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4949. $data['real_deal_user'] = $user_id;
  4950. }
  4951. //如果是deal 23,则判断是不是处理人
  4952. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4953. $complaintInof = Complaint::where('id', $data['id'])
  4954. ->where('real_deal_user', $user_id)
  4955. ->first();
  4956. if (empty($complaintInof)) {
  4957. return Result::error("处理人错误", 0);
  4958. }
  4959. }
  4960. $complaintInfo = Complaint::where('id', $data['id'])->first();
  4961. if ($data['status'] == 1) {
  4962. $this->sendMessage([
  4963. 'talk_type' => 800,
  4964. 'title' => $complaintInfo['title'],
  4965. 'content' => '提交了审核',
  4966. 'messageType' => 6,
  4967. ]);
  4968. }
  4969. if ($data['status'] == 2 && !isset($data['deal'])) {
  4970. $this->sendMessage([
  4971. 'talk_type' => 801,
  4972. 'title' => $complaintInfo['title'],
  4973. 'content' => '审核通过',
  4974. 'messageType' => 6,
  4975. 'user_id' => $complaintInfo['user_id'],
  4976. ]);
  4977. $this->sendMessage([
  4978. 'talk_type' => 802,
  4979. 'title' => $complaintInfo['title'],
  4980. 'content' => '待处理',
  4981. 'messageType' => 6,
  4982. 'user_id' => $complaintInfo['re_user_ids'],
  4983. ]);
  4984. }
  4985. if ($data['status'] == 3 && !isset($data['deal'])) {
  4986. $this->sendMessage([
  4987. 'talk_type' => 801,
  4988. 'title' => $complaintInfo['title'],
  4989. 'content' => '审核拒绝',
  4990. 'messageType' => 6,
  4991. 'user_id' => $complaintInfo['user_id'],
  4992. ]);
  4993. }
  4994. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  4995. $this->sendMessage([
  4996. 'talk_type' => 802,
  4997. 'title' => $complaintInfo['title'],
  4998. 'content' => '处理中',
  4999. 'messageType' => 6,
  5000. 'user_id' => $complaintInfo['re_user_ids'],
  5001. ]);
  5002. }
  5003. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  5004. $this->sendMessage([
  5005. 'talk_type' => 802,
  5006. 'title' => $complaintInfo['title'],
  5007. 'content' => '不予处理',
  5008. 'messageType' => 6,
  5009. 'user_id' => $complaintInfo['re_user_ids'],
  5010. ]);
  5011. }
  5012. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  5013. $this->sendMessage([
  5014. 'talk_type' => 802,
  5015. 'title' => $complaintInfo['title'],
  5016. 'content' => '已完结',
  5017. 'messageType' => 6,
  5018. 'user_id' => $complaintInfo['re_user_ids'],
  5019. ]);
  5020. }
  5021. $result = complaint::where('id', $data['id'])->update($data);
  5022. return Result::success($result);
  5023. }
  5024. public function updateGoodStatus(array $data): array
  5025. {
  5026. $user_id = $data['user_id'] ?? 0;
  5027. $type_id = $data['type_id'] ?? 0;
  5028. unset($data['user_id']);
  5029. unset($data['type_id']);
  5030. $goodInfo = Good::where('id', $data['id'])->first();
  5031. if ($data['status'] == 2) {
  5032. $this->sendMessage([
  5033. 'talk_type' => 201,
  5034. 'title' => $goodInfo['name'],
  5035. 'content' => '审核通过',
  5036. 'messageType' => 3,
  5037. 'user_id' => $goodInfo['user_id'],
  5038. ]);
  5039. }
  5040. if ($data['status'] == 3) {
  5041. $this->sendMessage([
  5042. 'talk_type' => 201,
  5043. 'title' => $goodInfo['name'],
  5044. 'content' => '审核拒绝',
  5045. 'messageType' => 3,
  5046. 'user_id' => $goodInfo['user_id'],
  5047. ]);
  5048. }
  5049. if ($data['status'] == 1) {
  5050. $this->sendMessage([
  5051. 'talk_type' => 200,
  5052. 'title' => $goodInfo['name'],
  5053. 'content' => '提交了审核',
  5054. 'messageType' => 3,
  5055. ]);
  5056. }
  5057. $result = Good::where('id', $data['id'])->update($data);
  5058. return Result::success($result);
  5059. }
  5060. public function updateJobHuntingStatus(array $data): array
  5061. {
  5062. $user_id = $data['user_id'] ?? 0;
  5063. $type_id = $data['type_id'] ?? 0;
  5064. unset($data['user_id']);
  5065. unset($data['type_id']);
  5066. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  5067. if ($data['status'] == 2) {
  5068. $this->sendMessage([
  5069. 'talk_type' => 601,
  5070. 'title' => $jogHuntingInfo['name'],
  5071. 'content' => '审核通过',
  5072. 'messageType' => 11,
  5073. 'user_id' => $jogHuntingInfo['user_id'],
  5074. ]);
  5075. }
  5076. if ($data['status'] == 3) {
  5077. $this->sendMessage([
  5078. 'talk_type' => 601,
  5079. 'title' => $jogHuntingInfo['name'],
  5080. 'content' => '审核拒绝',
  5081. 'messageType' => 11,
  5082. 'user_id' => $jogHuntingInfo['user_id'],
  5083. ]);
  5084. }
  5085. if ($data['status'] == 1) {
  5086. $this->sendMessage([
  5087. 'talk_type' => 600,
  5088. 'title' => $jogHuntingInfo['name'],
  5089. 'content' => '提交了审核',
  5090. 'messageType' => 11,
  5091. ]);
  5092. }
  5093. $result = JobHunting::where('id', $data['id'])->update($data);
  5094. return Result::success($result);
  5095. }
  5096. public function updateNoticeStatus(array $data): array
  5097. {
  5098. $user_id = $data['user_id'] ?? 0;
  5099. $type_id = $data['type_id'] ?? 0;
  5100. unset($data['user_id']);
  5101. unset($data['type_id']);
  5102. //查询公告
  5103. $notice = Notice::where('id', $data['id'])->first();
  5104. if (empty($notice)) {
  5105. return Result::error("公告不存在", 0);
  5106. }
  5107. //$chat_ids 去除掉$data['user_id']
  5108. $chat_ids = json_decode($notice['re_user_ids'], true);
  5109. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  5110. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  5111. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  5112. //chat_group
  5113. $group_id = PublicData::uuid();
  5114. $groupData = [
  5115. 'id' => $group_id,
  5116. 'creator_id' => $notice['user_id'],
  5117. 'group_name' => $notice['group_name'] ?? '',
  5118. 'profile' => $notice['profile'] ?? 0,
  5119. ];
  5120. var_dump($groupData, '-----------------groupData-------');
  5121. $groupResult = ChatGroups::insertGetId($groupData);
  5122. var_dump($groupResult, '-----------------groupid-------');
  5123. $groupMemberData = [
  5124. 'id' => PublicData::uuid(),
  5125. 'user_id' => $notice['user_id'],
  5126. 'group_id' => $group_id,
  5127. 'leader' => 2,
  5128. ];
  5129. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  5130. //插入群成员表
  5131. $groupMemberDataUser = [];
  5132. $chatData = [];
  5133. foreach ($chat_ids as $key => $value) {
  5134. $groupMemberDataUser[] = [
  5135. 'id' => PublicData::uuid(),
  5136. 'user_id' => $value,
  5137. 'group_id' => $group_id,
  5138. 'leader' => 1,
  5139. ];
  5140. $chatData[] = [
  5141. 'user_id' => $value,
  5142. 'msg_type' => 1,
  5143. 'receiver_id' => $group_id,
  5144. 'content' => '通过通知创建群聊',
  5145. 'group_receiver_id' => $notice['user_id'],
  5146. 'action' => 'recieved',
  5147. 'created_at' => date('Y-m-d H:i:s'),
  5148. ];
  5149. }
  5150. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  5151. ChatGroupsMember::insert($groupMemberDataUser);
  5152. //插入一条管理员聊天记录
  5153. $chatData[] = [
  5154. 'user_id' => $notice['user_id'],
  5155. 'msg_type' => 1,
  5156. 'receiver_id' => $group_id,
  5157. 'content' => '通过通知创建群聊',
  5158. 'group_receiver_id' => $notice['user_id'],
  5159. 'action' => 'said',
  5160. 'created_at' => date('Y-m-d H:i:s'),
  5161. ];
  5162. var_dump($chatData, '-----------------chatData-------');
  5163. $chatResult = ChatRecords::insert($chatData);
  5164. //处理imp
  5165. $group = [
  5166. 'type' => 1,
  5167. 'name' => $notice['group_name'] ?? '',
  5168. 'profile' => '',
  5169. 'avatar' => '',
  5170. 'creator_id' => $notice['user_id'],
  5171. ];
  5172. $groupResult = GroupImp::insertGetId($group);
  5173. var_dump($groupResult, '获取imp group_id');
  5174. $groupMember = [
  5175. 'user_id' => $notice['user_id'],
  5176. 'group_id' => $groupResult,
  5177. 'leader' => 1,
  5178. 'join_time' => Date('Y-m-d H:i:s')
  5179. ];
  5180. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  5181. $talk_session = [
  5182. 'user_id' => $notice['user_id'],
  5183. 'to_from_id' => $groupResult,
  5184. 'talk_mode' => 2,
  5185. 'created_at' => Date('Y-m-d H:i:s'),
  5186. 'updated_at' => Date('Y-m-d H:i:s'),
  5187. ];
  5188. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  5189. //被通知人员处理
  5190. foreach ($chat_ids as $key => $value) {
  5191. $groupMemberdata[] = [
  5192. 'user_id' => $value,
  5193. 'group_id' => $groupResult,
  5194. 'leader' => 3,
  5195. 'join_time' => Date('Y-m-d H:i:s')
  5196. ];
  5197. $talk_sessionData[] = [
  5198. 'user_id' => $value,
  5199. 'to_from_id' => $groupResult,
  5200. 'talk_mode' => 2,
  5201. 'created_at' => Date('Y-m-d H:i:s'),
  5202. 'updated_at' => Date('Y-m-d H:i:s'),
  5203. ];
  5204. }
  5205. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  5206. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  5207. $group_id = $groupResult;
  5208. //更新result的 group_id
  5209. $data['group_id'] = $group_id;
  5210. Notice::where(['id' => $data['id']])->update($data);
  5211. }
  5212. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  5213. //删除掉信息
  5214. GroupImp::where('id', $notice['group_id'])->delete();
  5215. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  5216. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  5217. foreach ($chat_ids as $key => $value) {
  5218. }
  5219. //聊天记录删除
  5220. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  5221. $data['group_id'] = null;
  5222. Notice::where(['id' => $data['id']])->update($data);
  5223. }
  5224. $result = Notice::where('id', $data['id'])->update($data);
  5225. $noticeInfo = Notice::where('id', $data['id'])->first();
  5226. if ($data['status'] == 2) {
  5227. $this->sendMessage([
  5228. 'talk_type' => 701,
  5229. 'title' => $noticeInfo['title'],
  5230. 'content' => '审核通过',
  5231. 'messageType' => 3,
  5232. 'user_id' => $noticeInfo['user_id'],
  5233. ]);
  5234. }
  5235. if ($data['status'] == 3) {
  5236. $this->sendMessage([
  5237. 'talk_type' => 701,
  5238. 'title' => $noticeInfo['title'],
  5239. 'content' => '审核拒绝',
  5240. 'messageType' => 3,
  5241. 'user_id' => $noticeInfo['user_id'],
  5242. ]);
  5243. }
  5244. if ($data['status'] == 1) {
  5245. $this->sendMessage([
  5246. 'talk_type' => 700,
  5247. 'title' => $noticeInfo['title'],
  5248. 'content' => '提交了审核',
  5249. 'messageType' => 3,
  5250. ]);
  5251. }
  5252. return Result::success($result);
  5253. }
  5254. public function getDUser(array $data): array
  5255. {
  5256. if (!empty($data['ids'])) {
  5257. $user = User::whereIn('id', $data['ids'])->getall();
  5258. if (empty($user)) {
  5259. return Result::error('无数据', 0);
  5260. }
  5261. return Result::success($user);
  5262. }
  5263. $where = [];
  5264. if (!empty($data['department_id'])) {
  5265. $where['department_id'] = $data['department_id'];
  5266. }
  5267. if (!empty($data['city_id'])) {
  5268. $where['city_id'] = $data['city_id'];
  5269. }
  5270. $result = User::where('type_id', 2)
  5271. ->where('status', 1)
  5272. ->where($where)
  5273. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  5274. ->get();
  5275. if (empty($result)) {
  5276. return Result::error("查询失败", 0);
  5277. }
  5278. return Result::success($result);
  5279. }
  5280. /**
  5281. * 验证导航名称是否重复
  5282. * @return void
  5283. */
  5284. public function checkCategoryName(array $data): array
  5285. {
  5286. $result = Category::when($data, function ($query) use ($data) {
  5287. if (isset($data['name']) && $data['name']) {
  5288. $query->where("name", $data['name']);
  5289. }
  5290. if (isset($data['id']) && $data['id']) {
  5291. $query->where("id", "!=", $data['id']);
  5292. }
  5293. })->first();
  5294. if ($result) {
  5295. return Result::error("已存在");
  5296. } else {
  5297. return Result::success();
  5298. }
  5299. }
  5300. //20250226 产品列表
  5301. // 20250306 -------招聘--------fr
  5302. /*
  5303. * 招聘列表
  5304. * */
  5305. public function getJobRecruitingList(array $data): array
  5306. {
  5307. $where = [];
  5308. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  5309. if ($data['checkout'] == 0) {
  5310. $job_status = [0, 2];
  5311. } else {
  5312. $job_status = [1];
  5313. }
  5314. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5315. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  5316. }
  5317. $user = User::where('id', $data['user_id'])->first();
  5318. if (empty($user)) {
  5319. return Result::error("用户不存在", 0);
  5320. }
  5321. // 3:企业会员
  5322. if ($user['type_id'] == 3) {
  5323. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  5324. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  5325. }
  5326. // 如果 $where 为空,则不添加 where 条件
  5327. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5328. return $query->where($where);
  5329. })
  5330. ->whereIn('job_recruiting.status', $job_status)
  5331. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5332. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  5333. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  5334. ->orderBy("updated_at", "desc")
  5335. ->offset(($data['page'] - 1) * $data['page_size'])
  5336. ->limit($data['page_size'])
  5337. ->get()
  5338. ->all();
  5339. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5340. return $query->where($where);
  5341. })
  5342. ->whereIn('job_recruiting.status', $job_status)
  5343. ->count();
  5344. if (empty($result)) {
  5345. return Result::error("暂无招聘信息", 0);
  5346. }
  5347. return Result::success($result);
  5348. }
  5349. /*
  5350. * 招聘信息添加
  5351. * */
  5352. public function addJobRecruiting(array $data): array
  5353. {
  5354. // var_dump('添加招聘进入news------data',$data);
  5355. // return Result::success($data);
  5356. $user = User::where('user.id', $data['user_id'])
  5357. ->where('user.status', 1)
  5358. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5359. ->select(
  5360. 'user.type_id',
  5361. 'user.mobile',
  5362. 'user.email',
  5363. 'user_info.business_name',
  5364. 'user_info.company_hy_id',
  5365. 'user_info.company_nature',
  5366. 'user_info.company_size',
  5367. 'user_info.introduction',
  5368. 'user_info.real_name',
  5369. 'user_info.company_url',
  5370. 'user_info.address_arr_id',
  5371. 'user_info.address'
  5372. )
  5373. ->first();
  5374. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5375. return Result::error("用户不存在", 0);
  5376. }
  5377. $web = Website::where('id', $data['website_id'])->first();
  5378. if (empty($web)) {
  5379. return Result::error("网站不存在", 0);
  5380. }
  5381. // var_dump('添加招聘进入news---user---user',$user);
  5382. // 处理招聘关键词
  5383. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5384. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5385. } else {
  5386. Jieba::init(); // 初始化 jieba-php
  5387. Finalseg::init();
  5388. $segList = Jieba::cut($data['title']);
  5389. $segList1 = array_slice($segList, 0, 8);
  5390. $data['keyword'] = implode(',', $segList1);
  5391. }
  5392. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5393. $content = $data['description'];
  5394. // 去除 <style> 和 <script> 标签及其内容
  5395. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5396. // 去除所有 HTML 标签
  5397. $content = strip_tags($content);
  5398. // 去除 HTML 实体
  5399. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5400. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5401. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5402. // 去除多余空白
  5403. $content = preg_replace('/\s+/u', '', $content);
  5404. // 截取 100 个字符
  5405. $data['seo_description'] = mb_substr($content, 0, 100);
  5406. }
  5407. // return Result::success($user);
  5408. $data['action_id'] = $data['user_id'] ?? null;
  5409. $data['user_type'] = $user['type_id'] ?? null;
  5410. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5411. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5412. $data['catid'] = end($data['cat_arr_id']);
  5413. } else {
  5414. $data['catid'] = 0;
  5415. }
  5416. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5417. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5418. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5419. // 公司地址 管理员必填
  5420. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5421. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5422. // 管理员-企业相关信息
  5423. $company = [
  5424. // 'user_id' => $data['user_id']?? null,
  5425. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5426. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5427. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5428. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5429. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5430. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5431. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5432. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5433. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5434. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5435. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5436. ];
  5437. //去掉相关企业信息
  5438. $job = array_diff_key($data, array_flip(array_keys($company)));
  5439. // var_dump('添加招聘进入news---job---user',$job);
  5440. Db::beginTransaction();
  5441. try {
  5442. // // 先添加职位相关信息
  5443. if ($user['type_id'] == 10000) {
  5444. $job['status'] = 1;
  5445. }
  5446. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5447. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5448. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5449. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5450. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5451. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5452. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5453. // return Result::success($job);
  5454. $jobId = JobRecruiting::insertGetId($job);
  5455. if (empty($jobId)) {
  5456. Db::rollBack();
  5457. return Result::error("添加失败");
  5458. }
  5459. // 添加公司信息
  5460. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5461. $company['job_id'] = $jobId;
  5462. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5463. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5464. if ($user['type_id'] == 10000) {
  5465. // 管理员添加企业信息
  5466. $companyId = JobCompany::insertGetId($company);
  5467. if (empty($companyId)) {
  5468. Db::rollBack();
  5469. return Result::error("添加失败");
  5470. }
  5471. } else {
  5472. // 企业会员添加企业信息
  5473. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5474. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5475. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5476. $company['job_id'] = $jobId;
  5477. $companyId = JobCompany::insertGetId($company);
  5478. if (empty($companyId)) {
  5479. Db::rollBack();
  5480. return Result::error("添加失败");
  5481. }
  5482. }
  5483. Db::commit();
  5484. $result = [
  5485. 'job_id' => $jobId,
  5486. 'company_id' => $companyId,
  5487. ];
  5488. return Result::success($result);
  5489. } catch (\Exception $e) {
  5490. Db::rollBack();
  5491. return Result::error($e->getMessage(), 0);
  5492. }
  5493. // return Result::success($result);
  5494. }
  5495. /*
  5496. * 获取招聘信息详情
  5497. * */
  5498. public function getJobRecruitingInfo(array $data): array
  5499. {
  5500. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5501. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5502. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5503. ->select(
  5504. 'job_recruiting.*',
  5505. 'website.website_name as website_name',
  5506. 'job_company.business_name',
  5507. 'job_company.company_hy_id',
  5508. 'job_company.company_size',
  5509. 'job_company.company_nature',
  5510. 'job_company.introduction',
  5511. 'job_company.real_name',
  5512. 'job_company.mobile',
  5513. 'job_company.company_url',
  5514. 'job_company.address_arr_id',
  5515. 'job_company.address',
  5516. 'job_company.email'
  5517. )
  5518. ->first();
  5519. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5520. if (!empty($cityId)) {
  5521. if (isset($cityId[1]) && $cityId[1] != null) {
  5522. $city = District::where('id', $cityId[1])->first(['name']);
  5523. } else {
  5524. $city = District::where('id', $cityId[0])->first(['name']);
  5525. }
  5526. $result['city'] = $city['name'] ?? '';
  5527. }
  5528. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5529. if (is_array($addressId) && !empty($addressId)) {
  5530. $address = District::whereIn('id', $addressId)
  5531. ->orderBy('level', 'asc')
  5532. ->get(['name'])
  5533. ->pluck('name')
  5534. ->implode('');
  5535. // $job->address_name = $address ?? '';
  5536. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5537. }
  5538. if (empty($result)) {
  5539. return Result::error("招聘信息不存在", 0);
  5540. }
  5541. // return Result::success($job);
  5542. return Result::success($result);
  5543. }
  5544. /*
  5545. * 修改招聘信息
  5546. * */
  5547. public function upJobRecruiting(array $data): array
  5548. {
  5549. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5550. // return Result::success($job);
  5551. if (empty($job)) {
  5552. return Result::error("招聘信息不存在", 0);
  5553. }
  5554. $user = User::where('id', $data['user_id'])->first();
  5555. // return Result::success($user);
  5556. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5557. return Result::error("用户不存在", 0);
  5558. }
  5559. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5560. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5561. }
  5562. // 处理招聘关键词
  5563. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5564. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5565. } else {
  5566. Jieba::init(); // 初始化 jieba-php
  5567. Finalseg::init();
  5568. $segList = Jieba::cut($data['title']);
  5569. $segList1 = array_slice($segList, 0, 8);
  5570. $data['keyword'] = implode(',', $segList1);
  5571. }
  5572. if(!isset($data['seo_description']) || empty($data['seo_description'])){
  5573. $content = $data['description'];
  5574. // 去除 <style> 和 <script> 标签及其内容
  5575. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5576. // 去除所有 HTML 标签
  5577. $content = strip_tags($content);
  5578. // 去除 HTML 实体
  5579. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5580. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5581. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5582. // 去除多余空白
  5583. $content = preg_replace('/\s+/u', '', $content);
  5584. // 截取 100 个字符
  5585. $data['seo_description'] = mb_substr($content, 0, 100);
  5586. }
  5587. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5588. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5589. $data['catid'] = end($data['cat_arr_id']);
  5590. } else {
  5591. }
  5592. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5593. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5594. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5595. // 公司地址 管理员必填
  5596. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5597. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5598. // 管理员-企业相关信息
  5599. $company = [
  5600. // 'user_id' => $data['user_id']?? null,
  5601. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5602. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5603. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5604. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5605. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5606. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5607. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5608. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5609. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5610. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5611. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5612. ];
  5613. //去掉相关企业信息
  5614. $data = array_diff_key($data, array_flip(array_keys($company)));
  5615. $jobId = $data['id'];
  5616. $web = $data['website_id'];
  5617. $data['action_id'] = $data['user_id'];
  5618. unset($data['user_id']);
  5619. unset($data['user_type']);
  5620. unset($data['id']);
  5621. unset($data['website_id']);
  5622. // return Result::success($data);
  5623. Db::beginTransaction();
  5624. try {
  5625. // 管理员修改招聘信息
  5626. if ($user['type_id'] == 10000) {
  5627. $data['website_id'] = $web;
  5628. $company['website_id'] = $data['website_id'];
  5629. $data['status'] = 1;
  5630. } else {
  5631. $data['status'] = 0;
  5632. }
  5633. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5634. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5635. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5636. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5637. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5638. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5639. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5640. // return Result::success($job);
  5641. // Db::rollBack();
  5642. // return Result::success($company);
  5643. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5644. $this->sendMessage([
  5645. 'talk_type' => 500,
  5646. 'title' => $data['title'],
  5647. 'content' => '提交了审核',
  5648. 'messageType' => 10,
  5649. ]);
  5650. }
  5651. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5652. if (empty($result['job'])) {
  5653. Db::rollBack();
  5654. return Result::error("修改招聘信息失败");
  5655. }
  5656. // 管理员修改企业相关信息
  5657. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5658. if (empty($result['company'])) {
  5659. Db::rollBack();
  5660. return Result::error("修改企业相关信息失败");
  5661. }
  5662. Db::commit();
  5663. // return Result::success($result);
  5664. } catch (\Exception $e) {
  5665. Db::rollBack();
  5666. return Result::error($e->getMessage(), 0);
  5667. }
  5668. return Result::success($result);
  5669. }
  5670. /*
  5671. * 招聘信息删除
  5672. * */
  5673. public function delJobRecruiting(array $data): array
  5674. {
  5675. $user = User::where('id', $data['user_id'])->first();
  5676. if (empty($user)) {
  5677. return Result::error("用户不存在", 0);
  5678. }
  5679. $job = JobRecruiting::where('id', $data['id'])->first();
  5680. if (empty($job)) {
  5681. return Result::error("招聘信息不存在", 0);
  5682. }
  5683. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5684. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5685. }
  5686. Db::beginTransaction();
  5687. try {
  5688. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5689. if (empty($result['job'])) {
  5690. Db::rollBack();
  5691. return Result::error("删除招聘信息失败");
  5692. }
  5693. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5694. if (empty($result['company'])) {
  5695. Db::rollBack();
  5696. return Result::error("删除企业相关信息失败");
  5697. }
  5698. Db::commit();
  5699. } catch (\Exception $e) {
  5700. Db::rollBack();
  5701. return Result::error($e->getMessage(), 0);
  5702. }
  5703. return Result::success($result);
  5704. }
  5705. /*
  5706. * 获取公司信息
  5707. * */
  5708. public function getJobCompany(array $data): array
  5709. {
  5710. $user = User::where('user.id', $data['user_id'])
  5711. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5712. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5713. ->first();
  5714. // return Result::success($user);
  5715. if (empty($user)) {
  5716. return Result::error("用户不存在", 0);
  5717. }
  5718. if ($user['type_id'] == 3) {
  5719. $result = [
  5720. // 'id' => 0,
  5721. 'user_id' => $data['user_id'],
  5722. 'website_id' => $data['website_id'],
  5723. 'business_name' => $user['business_name'], // 企业名称
  5724. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5725. 'company_nature' => $user['company_nature'], // 公司性质
  5726. 'company_size' => $user['company_size'], // 公司规模
  5727. 'introduction' => $user['introduction'], // 公司简介
  5728. 'real_name' => $user['real_name'], // 企业联系人
  5729. 'mobile' => $user['mobile'], // 企业联系电话
  5730. 'company_url' => $user['company_url'], // 企业网址
  5731. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5732. 'address' => $user['address'], // 企业地址
  5733. 'email' => $user['email'], // 企业邮箱
  5734. ];
  5735. } else {
  5736. return Result::error("用户类型错误", 0);
  5737. }
  5738. if (empty($result)) {
  5739. return Result::error("公司信息不存在", 0);
  5740. }
  5741. return Result::success($result);
  5742. }
  5743. /*
  5744. * 修改公司信息
  5745. * */
  5746. public function upJobCompany(array $data): array
  5747. {
  5748. // return Result::success($data);
  5749. $user = User::where('user.id', $data['user_id'])
  5750. ->where('user.status', 1)
  5751. ->select('user.user_name', 'user.type_id')
  5752. ->first();
  5753. if (empty($user)) {
  5754. return Result::error("用户不存在", 0);
  5755. }
  5756. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5757. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5758. $company = [
  5759. 'business_name' => $data['business_name'], // 企业名称
  5760. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5761. 'company_nature' => $data['company_nature'], // 公司性质
  5762. 'company_size' => $data['company_size'], // 公司规模
  5763. 'introduction' => $data['introduction'], // 公司简介
  5764. // 'real_name' => $data['real_name'], // 企业联系人
  5765. 'company_url' => $data['company_url'], // 企业网址
  5766. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5767. 'address' => $data['address'], // 企业详细地址
  5768. // 'email' => $data['email'], // 企业邮箱
  5769. ];
  5770. if ($user['type_id'] == 3) {
  5771. Db::beginTransaction();
  5772. try {
  5773. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5774. 'business_name' => $data['business_name'], // 企业名称
  5775. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5776. 'company_nature' => $data['company_nature'], // 公司性质
  5777. 'company_size' => $data['company_size'], // 公司规模
  5778. 'introduction' => $data['introduction'], // 公司简介
  5779. // 'real_name' => $data['real_name'], // 企业联系人
  5780. 'company_url' => $data['company_url'], // 企业网址
  5781. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5782. 'address' => $data['address'], // 企业详细地址
  5783. ]);
  5784. if (empty($result['userinfo'])) {
  5785. Db::rollBack();
  5786. return Result::error('修改企业会员信息失败!');
  5787. }
  5788. $result['user'] = User::where('id', $data['user_id'])->update([
  5789. 'email' => $data['email'], // 企业邮箱
  5790. ]);
  5791. if (empty($result['user'])) {
  5792. Db::rollBack();
  5793. return Result::error('修改个人中心信息失败!');
  5794. }
  5795. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5796. if (!empty($job_company)) {
  5797. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5798. if (empty($result['job_company'])) {
  5799. Db::rollBack();
  5800. return Result::error('修改企业会员信息失败!');
  5801. }
  5802. }
  5803. Db::commit();
  5804. return Result::success($result);
  5805. } catch (\Exception $e) {
  5806. Db::rollBack();
  5807. return Result::error($e->getMessage(), 0);
  5808. }
  5809. } else {
  5810. return Result::error("用户类型错误", 0);
  5811. }
  5812. }
  5813. /*
  5814. * 获取省-市
  5815. * */
  5816. public function getJobRecruitingArea(array $data): array
  5817. {
  5818. if (isset($data['pid']) && $data['pid'] != null) {
  5819. $result = District::where('pid', $data['pid'])->get()->all();
  5820. } else {
  5821. $result = District::where('level', 1)->get()->all();
  5822. }
  5823. if (empty($result)) {
  5824. return Result::error("暂无此省市", 0);
  5825. }
  5826. return Result::success($result);
  5827. }
  5828. /*
  5829. * 获取行业分类
  5830. * */
  5831. public function getIndustry(array $data): array
  5832. {
  5833. $result = JobIndustry::get()->all();
  5834. if (empty($result)) {
  5835. return Result::error("暂无行业分类", 0);
  5836. }
  5837. return Result::success($result);
  5838. }
  5839. /*
  5840. * 获取职位
  5841. * */
  5842. public function getPositionList(array $data): array
  5843. {
  5844. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5845. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5846. } else {
  5847. $result = JobPosition::where('zwpid', 0)->get()->all();
  5848. }
  5849. if (empty($result)) {
  5850. return Result::error("暂无此职位", 0);
  5851. }
  5852. return Result::success($result);
  5853. }
  5854. /*
  5855. * 获取工作性质-菜单
  5856. * */
  5857. public function getJobNature(array $data): array
  5858. {
  5859. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5860. if (empty($result)) {
  5861. return Result::error("暂无工作性质", 0);
  5862. }
  5863. return Result::success($result);
  5864. }
  5865. /*
  5866. * 获取工作经验-菜单
  5867. * */
  5868. public function getExperience(array $data): array
  5869. {
  5870. $result = JobEnum::where('egroup', 'years')->get()->all();
  5871. if (empty($result)) {
  5872. return Result::error("暂无工作经验", 0);
  5873. }
  5874. return Result::success($result);
  5875. }
  5876. /*
  5877. * 获取学历-菜单
  5878. * */
  5879. public function getEducation(array $data): array
  5880. {
  5881. $result = JobEnum::where('egroup', 'education')->get()->all();
  5882. if (empty($result)) {
  5883. return Result::error("暂无学历", 0);
  5884. }
  5885. return Result::success($result);
  5886. }
  5887. /*
  5888. * 获取薪资-菜单
  5889. * */
  5890. public function getSalary(array $data): array
  5891. {
  5892. $result = JobEnum::where('egroup', 'income')->get()->all();
  5893. if (empty($result)) {
  5894. return Result::error("暂无薪资", 0);
  5895. }
  5896. return Result::success($result);
  5897. }
  5898. /*
  5899. * 获取语言-菜单
  5900. * */
  5901. public function getLanguage(array $data): array
  5902. {
  5903. $result = JobEnum::where('egroup', 'language')->get()->all();
  5904. if (empty($result)) {
  5905. return Result::error("暂无语言", 0);
  5906. }
  5907. return Result::success($result);
  5908. }
  5909. /*
  5910. * 获取掌握程度-菜单
  5911. * */
  5912. public function getLevel(array $data): array
  5913. {
  5914. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  5915. if (empty($result)) {
  5916. return Result::error("暂无工作性质", 0);
  5917. }
  5918. return Result::success($result);
  5919. }
  5920. // 公司信息
  5921. /*
  5922. * 获取公司性质-菜单
  5923. * */
  5924. public function getCompanyNature(array $data): array
  5925. {
  5926. $result = JobNature::get()->all();
  5927. if (empty($result)) {
  5928. return Result::error("暂无公司性质", 0);
  5929. }
  5930. return Result::success($result);
  5931. }
  5932. /*
  5933. * 获取公司规模-菜单
  5934. * */
  5935. public function getCompanySize(array $data): array
  5936. {
  5937. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  5938. if (empty($result)) {
  5939. return Result::error("暂无公司规模", 0);
  5940. }
  5941. return Result::success($result);
  5942. }
  5943. /*
  5944. * 招聘信息审核
  5945. * */
  5946. public function checkJobRecruiting(array $data): array
  5947. {
  5948. $user = User::where('id', $data['user_id'])->first();
  5949. if (empty($user)) {
  5950. return Result::error("用户不存在", 0);
  5951. }
  5952. $job = JobRecruiting::where('id', $data['id'])->first();
  5953. if (empty($job)) {
  5954. return Result::error("招聘信息不存在", 0);
  5955. }
  5956. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  5957. if ($user['type_id'] != 10000) {
  5958. return Result::error("用户暂无权限审核此招聘信息!", 0);
  5959. }
  5960. // 驳回原因
  5961. if ($data['status'] == 2) {
  5962. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  5963. }
  5964. $data['action_id'] = $data['user_id'];
  5965. unset($data['user_id']);
  5966. if ($data['status'] == 1) {
  5967. $this->sendMessage([
  5968. 'talk_type' => 501,
  5969. 'title' => $job['title'],
  5970. 'content' => '审核通过',
  5971. 'messageType' => 10,
  5972. 'user_id' => $job['user_id'],
  5973. ]);
  5974. }
  5975. if ($data['status'] == 2) {
  5976. $this->sendMessage([
  5977. 'talk_type' => 501,
  5978. 'title' => $job['title'],
  5979. 'content' => '审核拒绝',
  5980. 'messageType' => 10,
  5981. 'user_id' => $job['user_id'],
  5982. ]);
  5983. }
  5984. if ($data['status'] == 0) {
  5985. $this->sendMessage([
  5986. 'talk_type' => 500,
  5987. 'title' => $job['title'],
  5988. 'content' => '提交了审核',
  5989. 'messageType' => 10,
  5990. ]);
  5991. }
  5992. $result = JobRecruiting::where('id', $data['id'])->update($data);
  5993. if (empty($result)) {
  5994. return Result::error("审核失败", 0);
  5995. }
  5996. return Result::success($result);
  5997. }
  5998. public function myApplyList(array $data): array
  5999. {
  6000. var_dump($data, '------参数');
  6001. $user = User::where('id', $data['user_id'])->first();
  6002. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6003. return Result::error("用户不存在", 0);
  6004. }
  6005. // 1:个人会员 职场机会
  6006. if ($user['type_id'] == 1) {
  6007. $where['user_id'] = $user['id'];
  6008. }
  6009. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  6010. $query->where('user_id', $user['id']);
  6011. })
  6012. ->pluck('recruit_id');
  6013. $where = [];
  6014. if (isset($data['salary']) && $data['salary'] != null) {
  6015. $where['job_recruiting.salary'] = $data['salary'];
  6016. }
  6017. if (isset($data['experience']) && $data['experience'] != null) {
  6018. $where['job_recruiting.experience'] = $data['experience'];
  6019. }
  6020. if (isset($data['business_name']) && $data['business_name'] != null) {
  6021. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6022. }
  6023. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6024. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6025. ->where($where);
  6026. // ->count();
  6027. $count = $query->count();
  6028. $query = clone $query;
  6029. $job = $query
  6030. ->leftJoin('job_enum as income_enum', function ($join) {
  6031. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6032. ->where('income_enum.egroup', 'income');
  6033. })
  6034. ->leftJoin('job_enum as years_enum', function ($join) {
  6035. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6036. ->where('years_enum.egroup', 'years');
  6037. })
  6038. // ->where($where)
  6039. ->orderBy('job_recruiting.updated_at', 'desc')
  6040. ->select(
  6041. 'job_recruiting.id',
  6042. 'job_recruiting.title',
  6043. 'job_company.business_name',
  6044. 'income_enum.evalue as salary_evalue',
  6045. 'income_enum.ename as salary_ename',
  6046. 'years_enum.evalue as experience_evalue',
  6047. 'years_enum.ename as experience_ename',
  6048. 'job_recruiting.updated_at'
  6049. )
  6050. ->offset(($data['page'] - 1) * $data['pageSize'])
  6051. ->limit($data['pageSize'])
  6052. ->get()
  6053. ->all();
  6054. if (empty($job)) {
  6055. return Result::error("暂无招聘信息", 0);
  6056. }
  6057. $result = [
  6058. 'row' => $job,
  6059. 'count' => $count,
  6060. ];
  6061. return Result::success($result);
  6062. }
  6063. public function readJobApply(array $data): array
  6064. {
  6065. $result = JobApply::where('id', $data['id'])->first();
  6066. if (empty($result)) {
  6067. return Result::error("查询失败", 0);
  6068. }
  6069. $result = JobApply::where('id', $data['id'])->update([
  6070. 'status' => 2,
  6071. ]);
  6072. return Result::success($result);
  6073. }
  6074. /*
  6075. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  6076. * */
  6077. public function getRecruitingList(array $data): array
  6078. {
  6079. $user = User::where('id', $data['user_id'])->first();
  6080. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6081. return Result::error("用户不存在", 0);
  6082. }
  6083. // 1:个人会员 职场机会
  6084. if ($user['type_id'] == 1) {
  6085. $where['user_id'] = $user['id'];
  6086. }
  6087. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  6088. $query->where('receiver_id', $user['id']);
  6089. })
  6090. ->pluck('recruit_id');
  6091. // return Result::success($recruitingId);
  6092. $where = [];
  6093. if (isset($data['salary']) && $data['salary'] != null) {
  6094. $where['job_recruiting.salary'] = $data['salary'];
  6095. }
  6096. if (isset($data['experience']) && $data['experience'] != null) {
  6097. $where['job_recruiting.experience'] = $data['experience'];
  6098. }
  6099. if (isset($data['business_name']) && $data['business_name'] != null) {
  6100. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6101. }
  6102. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6103. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6104. ->where($where);
  6105. // ->count();
  6106. $count = $query->count();
  6107. $query = clone $query;
  6108. $job = $query
  6109. ->leftJoin('job_enum as income_enum', function ($join) {
  6110. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6111. ->where('income_enum.egroup', 'income');
  6112. })
  6113. ->leftJoin('job_enum as years_enum', function ($join) {
  6114. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6115. ->where('years_enum.egroup', 'years');
  6116. })
  6117. // ->where($where)
  6118. ->orderBy('job_recruiting.updated_at', 'desc')
  6119. ->select(
  6120. 'job_recruiting.id',
  6121. 'job_recruiting.title',
  6122. 'job_company.business_name',
  6123. 'income_enum.evalue as salary_evalue',
  6124. 'income_enum.ename as salary_ename',
  6125. 'years_enum.evalue as experience_evalue',
  6126. 'years_enum.ename as experience_ename',
  6127. 'job_recruiting.updated_at'
  6128. )
  6129. ->offset(($data['page'] - 1) * $data['pageSize'])
  6130. ->limit($data['pageSize'])
  6131. ->get()
  6132. ->all();
  6133. if (empty($job)) {
  6134. return Result::error("暂无招聘信息", 0);
  6135. }
  6136. $result = [
  6137. 'row' => $job,
  6138. 'count' => $count,
  6139. ];
  6140. return Result::success($result);
  6141. }
  6142. /*
  6143. * 获取企业会员-招聘信息列表
  6144. * */
  6145. public function getRecruitingInfo(array $data): array
  6146. {
  6147. $user = User::where('id', $data['user_id'])->first();
  6148. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6149. return Result::error("用户不存在", 0);
  6150. }
  6151. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  6152. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6153. ->select(
  6154. 'job_recruiting.*',
  6155. 'job_company.business_name',
  6156. 'job_company.company_hy_id',
  6157. 'job_company.company_size',
  6158. 'job_company.company_nature',
  6159. 'job_company.introduction',
  6160. 'job_company.real_name',
  6161. 'job_company.mobile',
  6162. 'job_company.company_url',
  6163. 'job_company.address_arr_id',
  6164. 'job_company.address',
  6165. 'job_company.email'
  6166. )
  6167. ->get();
  6168. if (empty($recruiting)) {
  6169. return Result::error("暂无招聘信息", 0);
  6170. }
  6171. return Result::success($recruiting);
  6172. }
  6173. /*
  6174. * 获取企业会员-我的沟通
  6175. * */
  6176. public function getJobResumeList(array $data): array
  6177. {
  6178. $user = User::where('id', $data['user_id'])->first();
  6179. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  6180. return Result::error("用户不存在", 0);
  6181. }
  6182. $where = [];
  6183. if (isset($data['salary']) && $data['salary'] != null) {
  6184. $where['job_hunting.salary'] = $data['salary'];
  6185. }
  6186. if (isset($data['user_name']) && $data['user_name'] != null) {
  6187. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  6188. }
  6189. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  6190. $query->where('job_resume.user_id', $user['id']);
  6191. })
  6192. ->when(!empty($where), function ($query) use ($where) {
  6193. $query->where($where);
  6194. })
  6195. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  6196. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  6197. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  6198. ->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');
  6199. $count = $job->count();
  6200. if ($count == 0) {
  6201. return Result::error("暂无沟通记录", 0);
  6202. }
  6203. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  6204. ->offset(($data['page'] - 1) * $data['pageSize'])
  6205. ->limit($data['pageSize'])
  6206. ->get();
  6207. if (empty($jobs)) {
  6208. return Result::error("暂无沟通记录", 0);
  6209. }
  6210. $result['row'] = $this->processJob($jobs, '');
  6211. $result['count'] = $count;
  6212. return Result::success($result);
  6213. }
  6214. public function readJobResume(array $data): array
  6215. {
  6216. $result = JobResume::where('id', $data['id'])->first();
  6217. if (empty($result)) {
  6218. return Result::error("查询失败", 0);
  6219. }
  6220. $result = JobResume::where('id', $data['id'])->update([
  6221. 'status' => 2,
  6222. ]);
  6223. return Result::success($result);
  6224. }
  6225. // 20250306 招聘
  6226. //20250422 书刊音像
  6227. public function addBook(array $data): array
  6228. {
  6229. $user_id = $data['user_id'] ?? 0;
  6230. $type_id = $data['type_id'] ?? 0;
  6231. // $website_id = $data['website_id'] ?? 0;
  6232. // unset($data['user_id']);
  6233. unset($data['type_id']);
  6234. // unset($data['website_id']);
  6235. //处理数组
  6236. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6237. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6238. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6239. if ($data['img_url'] == '') {
  6240. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6241. preg_match_all($reg, $data['detail'], $matches);
  6242. if (isset($matches[1][0])) {
  6243. //截取varchar240
  6244. $data['img_url'] = substr($matches[1][0], 0, 240);
  6245. }
  6246. }
  6247. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  6248. //提取标题+内容中的关键词
  6249. $data['keyword'] = $data['title'];
  6250. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6251. Jieba::init(); // 初始化 jieba-php
  6252. Finalseg::init();
  6253. $segList = Jieba::cut($data['keyword']);
  6254. $segList1 = array_slice($segList, 0, 8);
  6255. $data['keyword'] = implode(',', $segList1);
  6256. }
  6257. if ($data['description'] == '') {
  6258. //提取内容中的描述
  6259. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6260. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6261. }
  6262. var_dump($data, '--');
  6263. if ($data['status'] == 1) {
  6264. $this->sendMessage([
  6265. 'talk_type' => 400,
  6266. 'title' => $data['title'],
  6267. 'content' => '提交了审核',
  6268. 'messageType' => 7,
  6269. ]);
  6270. }
  6271. $result = Book::insertGetId($data);
  6272. if (empty($result)) {
  6273. return Result::error("添加失败", 0);
  6274. }
  6275. return Result::success($result);
  6276. }
  6277. public function getBookList(array $data): array
  6278. {
  6279. $where = [];
  6280. if (!empty($data["title"])) {
  6281. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  6282. }
  6283. if (!empty($data['website_name'])) {
  6284. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  6285. }
  6286. if (!empty($data['status'])) {
  6287. $where[] = ['book.status', '=', $data['status']];
  6288. }
  6289. $user_id = $data['user_id'];
  6290. $type_id = $data['type_id'];
  6291. // $type_id = 4;
  6292. var_dump($type_id, '------1--------');
  6293. if ($type_id != 10000) {
  6294. $where[] = ['book.user_id', '=', $user_id];
  6295. }
  6296. var_dump(!empty($data['status1']), '=-===1');
  6297. $result = Book::where($where)
  6298. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  6299. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  6300. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  6301. ->when(isset($data['status1']), function ($query) use ($data) {
  6302. $query->whereIn('book.status', [1, 3]);
  6303. })
  6304. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  6305. ->orderBy("updated_at", "desc")
  6306. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  6307. if (empty($result)) {
  6308. return Result::error("暂无数据", 0);
  6309. }
  6310. // 取出数据
  6311. $rows = $result->items();
  6312. $count = $result->total();
  6313. $responseData = [
  6314. 'rows' => $rows,
  6315. 'count' => $count,
  6316. ];
  6317. return Result::success($responseData);
  6318. }
  6319. public function deleteBook(array $data): array
  6320. {
  6321. $result = Book::where('id', $data['id'])->delete();
  6322. if (empty($result)) {
  6323. return Result::error("删除失败", 0);
  6324. }
  6325. return Result::success($result);
  6326. }
  6327. public function updateBook(array $data): array
  6328. {
  6329. // $user_id = $data['user_id'] ?? 0;
  6330. $type_id = $data['type_id'] ?? 0;
  6331. // $website_id = $data['website_id'] ?? 0;
  6332. unset($data['user_id']);
  6333. unset($data['type_id']);
  6334. // unset($data['website_id']);
  6335. //处理数组
  6336. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6337. if ($data['img_url'] == '') {
  6338. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6339. preg_match_all($reg, $data['detail'], $matches);
  6340. if (isset($matches[1][0])) {
  6341. //截取varchar240
  6342. $data['img_url'] = substr($matches[1][0], 0, 240);
  6343. }
  6344. }
  6345. if ($data['keyword'] == '') {
  6346. //提取标题+内容中的关键词
  6347. $data['keyword'] = $data['title'];
  6348. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6349. Jieba::init(); // 初始化 jieba-php
  6350. Finalseg::init();
  6351. $segList = Jieba::cut($data['keyword']);
  6352. $segList1 = array_slice($segList, 0, 8);
  6353. $data['keyword'] = implode(',', $segList1);
  6354. }
  6355. if ($data['description'] == '') {
  6356. //提取内容中的描述
  6357. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6358. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6359. }
  6360. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6361. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6362. if ($data['status'] == 1) {
  6363. $this->sendMessage([
  6364. 'talk_type' => 400,
  6365. 'title' => $data['title'],
  6366. 'content' => '提交了审核',
  6367. 'messageType' => 7,
  6368. ]);
  6369. }
  6370. $result = Book::where("id", $data["id"])->update($data);
  6371. if (empty($result)) {
  6372. return Result::error("更新失败", 0);
  6373. }
  6374. return Result::success($result);
  6375. }
  6376. public function getBookInfo(array $data): array
  6377. {
  6378. $result = Book::where("id", $data["id"])->first();
  6379. if (empty($result)) {
  6380. return Result::error("获取失败", 0);
  6381. }
  6382. return Result::success($result);
  6383. }
  6384. public function updateBookStatus(array $data): array
  6385. {
  6386. //审核
  6387. unset($data['user_id']);
  6388. $bookInfo = Book::where("id", $data["id"])->first();
  6389. var_dump($bookInfo, '----');
  6390. if ($data['status'] == 2) {
  6391. $this->sendMessage([
  6392. 'talk_type' => 401,
  6393. 'title' => $bookInfo['title'],
  6394. 'content' => '审核通过',
  6395. 'messageType' => 7,
  6396. 'user_id' => $bookInfo['user_id'],
  6397. ]);
  6398. }
  6399. if ($data['status'] == 3) {
  6400. $this->sendMessage([
  6401. 'talk_type' => 401,
  6402. 'title' => $bookInfo['title'],
  6403. 'content' => '审核拒绝',
  6404. 'messageType' => 7,
  6405. 'user_id' => $bookInfo['user_id'],
  6406. ]);
  6407. }
  6408. if ($data['status'] == 1) {
  6409. $this->sendMessage([
  6410. 'talk_type' => 400,
  6411. 'title' => $bookInfo['title'],
  6412. 'content' => '提交了审核',
  6413. 'messageType' => 7,
  6414. // 'user_id'=>$bookInfo['user_id'],
  6415. ]);
  6416. }
  6417. $result = Book::where("id", $data["id"])->update($data);
  6418. if (empty($result)) {
  6419. return Result::error("更新失败", 0);
  6420. }
  6421. return Result::success($result);
  6422. }
  6423. //20250422 书刊音像
  6424. /**
  6425. * 贴身宝贝
  6426. * @param array $data
  6427. * @return array
  6428. */
  6429. public function getWebsiteTsbb(array $data): array
  6430. {
  6431. $month = $data['month'] ?? date('m');
  6432. $day = $data['day'] ?? date('d');
  6433. // 使用缓存键
  6434. $cacheKey = "tsbb_data_{$month}_{$day}";
  6435. // 尝试从缓存获取数据
  6436. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6437. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6438. if ($cachedData = $cache->get($cacheKey)) {
  6439. return Result::success(unserialize($cachedData));
  6440. }
  6441. //查询老黄历
  6442. try {
  6443. $date = date('Y-m-d');
  6444. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6445. // 使用 curl 替代 file_get_contents
  6446. $ch = curl_init();
  6447. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6448. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6449. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6450. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6451. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6452. 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');
  6453. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6454. 'Accept: application/json',
  6455. 'Content-Type: application/json',
  6456. 'Referer: https://www.36jxs.com/'
  6457. ]);
  6458. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6459. curl_setopt($ch, CURLOPT_ENCODING, '');
  6460. $almanacResponse = curl_exec($ch);
  6461. var_dump("====:", $almanacResponse);
  6462. if (curl_errno($ch)) {
  6463. var_dump('Curl error:', curl_error($ch));
  6464. throw new \Exception('Curl error: ' . curl_error($ch));
  6465. }
  6466. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6467. curl_close($ch);
  6468. if ($almanacResponse === false) {
  6469. throw new \Exception('Failed to fetch almanac data');
  6470. }
  6471. $almanacData = json_decode($almanacResponse, true);
  6472. if (json_last_error() !== JSON_ERROR_NONE) {
  6473. throw new \Exception('Failed to parse almanac data');
  6474. }
  6475. $almanacInfo = $almanacData['data'] ?? [];
  6476. } catch (\Exception $e) {
  6477. var_dump('Exception:', $e->getMessage());
  6478. $almanacInfo = [];
  6479. }
  6480. // 获取历史上的今天数据
  6481. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6482. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6483. ->orderBy('year', 'asc')
  6484. ->select("title", "id", "year", DB::raw('1 as type'))
  6485. ->limit(16)
  6486. ->get();
  6487. // 获取节日数据 - 从今天开始获取未来4条
  6488. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6489. ->orderBy('showtime', 'asc')
  6490. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6491. ->limit(16)
  6492. ->get();
  6493. //说文解字
  6494. $chartacterList = Character::orderBy('updated_at', 'desc')
  6495. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6496. ->limit(6)
  6497. ->get();
  6498. //谜语沙龙
  6499. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6500. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6501. ->limit(4)
  6502. ->get();
  6503. //成语欣赏
  6504. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6505. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6506. ->limit(32)
  6507. ->get();
  6508. //名联赏析
  6509. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6510. ->select("id", "first", "second", DB::raw('6 as type'))
  6511. ->limit(6)
  6512. ->get();
  6513. // 获取分类文章数据
  6514. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6515. ->pluck('category_id')
  6516. ->toArray();
  6517. $articlesList = [];
  6518. foreach ($categoryIds as $catid) {
  6519. // 先查有图片的
  6520. $withImg = DB::table('article')
  6521. ->where('status', 1)
  6522. ->where('catid', $catid)
  6523. ->whereNotNull('imgurl')
  6524. ->where('imgurl', '!=', '')
  6525. ->orderBy('updated_at', 'desc')
  6526. ->limit(6)
  6527. ->get();
  6528. $count = $withImg->count();
  6529. if ($count < 6) {
  6530. // 不足6条再查无图片的补足
  6531. $withoutImg = DB::table('article')
  6532. ->where('status', 1)
  6533. ->where('catid', $catid)
  6534. ->where(function ($q) {
  6535. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6536. })
  6537. ->orderBy('updated_at', 'desc')
  6538. ->limit(6 - $count)
  6539. ->get();
  6540. $articles = $withImg->concat($withoutImg);
  6541. } else {
  6542. $articles = $withImg;
  6543. }
  6544. // 组装
  6545. $category = \App\Model\Category::find($catid);
  6546. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6547. $articlesList[] = [
  6548. 'category_name' => $category ? $category->name : '',
  6549. 'catid' => $catid,
  6550. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6551. 'type' => 100,
  6552. 'list' => $articles->map(function ($item) {
  6553. return [
  6554. 'id' => $item->id,
  6555. 'title' => $item->title,
  6556. 'imgurl' => $item->imgurl,
  6557. 'created_at' => $item->created_at
  6558. ];
  6559. })->values()
  6560. ];
  6561. }
  6562. $result = [
  6563. 'almanac' => $almanacInfo,
  6564. 'historyTodayList' => [
  6565. 'category_name' => '历史上的今天',
  6566. 'list' => $historyTodayList,
  6567. 'type' => 1
  6568. ],
  6569. 'festivalList' => [
  6570. 'category_name' => '节日预告',
  6571. 'list' => $festivalList,
  6572. 'type' => 2
  6573. ],
  6574. 'chartacterList' => [
  6575. 'category_name' => '说文解字',
  6576. 'list' => $chartacterList,
  6577. 'type' => 3
  6578. ],
  6579. 'coupletList' => [
  6580. 'category_name' => '名联赏析',
  6581. 'list' => $coupletList,
  6582. 'type' => 6
  6583. ],
  6584. 'riddletList' => [
  6585. 'category_name' => '谜语沙龙',
  6586. 'list' => $riddletList,
  6587. 'type' => 4
  6588. ],
  6589. 'idiomList' => [
  6590. 'category_name' => '成语欣赏',
  6591. 'list' => $idiomList,
  6592. 'type' => 5
  6593. ],
  6594. 'articlesList' => $articlesList
  6595. ];
  6596. // 缓存结果,设置1小时过期
  6597. $cache->set($cacheKey, serialize($result), 3600);
  6598. return Result::success($result);
  6599. }
  6600. /**
  6601. * 获取资讯列表
  6602. */
  6603. public function getWebsiteTsbbList(array $data): array
  6604. {
  6605. $page = $data['page'] ?? 1;
  6606. $pageSize = $data['pageSize'] ?? 10;
  6607. // 如果没有传入月份和日期,则使用今天的日期
  6608. $month = $data['month'] ?? date('m');
  6609. $day = $data['day'] ?? date('d');
  6610. $total = 0;
  6611. $result = [];
  6612. $data['type'] = intval($data['type']);
  6613. var_dump("接收参数:", $data);
  6614. switch ($data['type']) {
  6615. case 1:
  6616. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6617. // 当前月份之后的数据
  6618. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6619. // 或者当前月份且日期大于等于当前日期的数据
  6620. ->orWhere(function ($q) use ($month, $day) {
  6621. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6622. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6623. });
  6624. })
  6625. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6626. $total = $query->count();
  6627. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6628. ->offset(($page - 1) * $pageSize)
  6629. ->limit($pageSize)
  6630. ->get();
  6631. break;
  6632. case 2:
  6633. $query = Festival::where(function ($q) use ($month, $day) {
  6634. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6635. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6636. ->orWhere(function ($q) use ($month, $day) {
  6637. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6638. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6639. });
  6640. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6641. $total = $query->count();
  6642. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6643. ->offset(($page - 1) * $pageSize)
  6644. ->limit($pageSize)
  6645. ->get();
  6646. break;
  6647. case 3:
  6648. $query = Character::orderBy("updated_at", "desc");
  6649. $total = $query->count();
  6650. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6651. ->offset(($page - 1) * $pageSize)
  6652. ->limit($pageSize)
  6653. ->get();
  6654. break;
  6655. case 4:
  6656. $query = Riddle::orderBy("updated_at", "desc");
  6657. $total = $query->count();
  6658. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6659. ->offset(($page - 1) * $pageSize)
  6660. ->limit($pageSize)
  6661. ->get();
  6662. break;
  6663. case 5:
  6664. $query = Idiom::orderBy("updated_at", "desc");
  6665. $total = $query->count();
  6666. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6667. ->offset(($page - 1) * $pageSize)
  6668. ->limit($pageSize)
  6669. ->get();
  6670. break;
  6671. case 6:
  6672. $query = Couplet::orderBy("updated_at", "desc");
  6673. $total = $query->count();
  6674. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6675. ->offset(($page - 1) * $pageSize)
  6676. ->limit($pageSize)
  6677. ->get();
  6678. break;
  6679. default:
  6680. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6681. $total = $query->count();
  6682. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6683. ->offset(($page - 1) * $pageSize)
  6684. ->limit($pageSize)
  6685. ->get();
  6686. }
  6687. return Result::success([
  6688. 'list' => $result,
  6689. 'total' => $total,
  6690. 'page' => (int)$page,
  6691. 'pageSize' => (int)$pageSize,
  6692. 'month' => $month,
  6693. 'day' => $day
  6694. ]);
  6695. }
  6696. /**
  6697. * 1:历史上的今天
  6698. * 2:节日
  6699. * 3:文章
  6700. *
  6701. * 资讯详情信息
  6702. */
  6703. public function getWebsiteTsbbDetail(array $data): array
  6704. {
  6705. $data['type'] = intval($data['type']);
  6706. switch ($data['type']) {
  6707. case 1:
  6708. $result = HistoryToday::where("id", $data['id'])->first();
  6709. break;
  6710. case 2:
  6711. $result = Festival::where("id", $data['id'])->first();
  6712. break;
  6713. case 3:
  6714. $result = Character::where("id", $data['id'])->first();
  6715. break;
  6716. case 4:
  6717. $result = Riddle::where("id", $data['id'])->first();
  6718. break;
  6719. case 5:
  6720. $result = Idiom::where("id", $data['id'])->first();
  6721. break;
  6722. case 6:
  6723. $result = Couplet::where("id", $data['id'])->first();
  6724. break;
  6725. default:
  6726. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6727. break;
  6728. }
  6729. return Result::success($result);
  6730. }
  6731. /**
  6732. * 农网导航首页数据
  6733. */
  6734. public function getWebsiteNwHomeList(array $data): array
  6735. {
  6736. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6737. ->pluck('category_id')
  6738. ->toArray();
  6739. // 使用子查询优化
  6740. $articlesList = DB::table('article')
  6741. ->select([
  6742. 'article.id',
  6743. 'article.title',
  6744. 'article.imgurl',
  6745. 'article.created_at',
  6746. 'category.name as category_name',
  6747. 'category.id as category_id',
  6748. 'website_category.aLIas_pinyin as pinyin',
  6749. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6750. DB::raw('100 as type')
  6751. ])
  6752. ->join('category', 'article.catid', '=', 'category.id')
  6753. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6754. ->leftJoin('website_category as parent_wc', function ($join) {
  6755. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6756. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6757. })
  6758. ->where('website_category.website_id', $data['website_id'])
  6759. ->where('article.status', 1)
  6760. ->whereIn('category.id', $categoryIds)
  6761. ->orderBy('article.created_at', 'desc')
  6762. ->get()
  6763. ->groupBy('category_id')
  6764. ->map(function ($group) {
  6765. // 确保第一条数据有图片
  6766. $firstWithImage = $group->first(function ($item) {
  6767. return !empty($item->imgurl);
  6768. });
  6769. if ($firstWithImage) {
  6770. // 如果有带图片的文章,将其放在第一位
  6771. $group = $group->filter(function ($item) use ($firstWithImage) {
  6772. return $item->id !== $firstWithImage->id;
  6773. })->prepend($firstWithImage);
  6774. }
  6775. return [
  6776. 'category_name' => $group->first()->category_name,
  6777. 'catid' => $group->first()->category_id,
  6778. 'pinyin' => $group->first()->pinyin,
  6779. 'parent_pinyin' => $group->first()->parent_pinyin,
  6780. 'list' => $group->take(4)->map(function ($item) {
  6781. return [
  6782. 'id' => $item->id,
  6783. 'title' => $item->title,
  6784. ];
  6785. })->values()
  6786. ];
  6787. })
  6788. ->values()
  6789. ->toArray();
  6790. return Result::success($articlesList);
  6791. }
  6792. /**
  6793. * 企业管理
  6794. * @param array $data
  6795. * @return array
  6796. */
  6797. public function getCompanyList(array $data): array
  6798. {
  6799. // return Result::success($data);
  6800. $where = [];
  6801. $user = User::where('id', $data['user_id'])->first();
  6802. if (empty($user)) {
  6803. return Result::error('用户不存在!');
  6804. }
  6805. if ($user['type_id'] != 10000) {
  6806. $where['user_id'] = $data['user_id'];
  6807. }
  6808. if (isset($data['title']) && !empty($data['title'])) {
  6809. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6810. }
  6811. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6812. array_push($where, ['website.id', $data['website_id']]);
  6813. }
  6814. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6815. if ($data['ischeck'] == 1) {
  6816. if (isset($data['status']) && $data['status'] != '') {
  6817. array_push($where, ['company.status', $data['status']]);
  6818. $query = Company::where($where);
  6819. } else {
  6820. $query = Company::whereIn('company.status', [0, 2]);
  6821. }
  6822. } else {
  6823. $query = Company::where('company.status', 1);
  6824. }
  6825. }
  6826. $result = $query->where($where)
  6827. ->leftJoin('website_category', function ($query) {
  6828. $query->on('website_category.category_id', '=', 'company.category_id')
  6829. ->on('website_category.website_id', '=', 'company.website_id');
  6830. })
  6831. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6832. ->select(
  6833. 'company.id',
  6834. 'company.title',
  6835. 'company.website_id',
  6836. 'company.category_id',
  6837. 'website.website_name',
  6838. 'website_category.alias as category_name',
  6839. 'company.status',
  6840. 'company.updated_at',
  6841. 'company.user_id'
  6842. )
  6843. ->orderBy('company.updated_at', 'desc')
  6844. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6845. if ($result->isEmpty()) {
  6846. return Result::error("暂无企业", 0);
  6847. }
  6848. return Result::success($result);
  6849. }
  6850. /**
  6851. * 添加企业
  6852. * @param array $data
  6853. * @return array
  6854. */
  6855. public function addCompany(array $data): array
  6856. {
  6857. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  6858. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6859. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6860. $data['cat_arr_id'] = json_encode($car_arr_id);
  6861. } else {
  6862. $data['cat_arr_id'] = '';
  6863. }
  6864. if ($data['imgurl'] == '') {
  6865. //content中提取图片第一个图,正则提取
  6866. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6867. preg_match_all($reg, $data['content'], $matches);
  6868. if (isset($matches[1][0])) {
  6869. //截取varchar240
  6870. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6871. }
  6872. }
  6873. if ($data['keyword'] == '') {
  6874. //提取标题+内容中的关键词
  6875. $data['keyword'] = $data['title'];
  6876. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6877. Jieba::init(); // 初始化 jieba-php
  6878. Finalseg::init();
  6879. $segList = Jieba::cut($data['keyword']);
  6880. $segList1 = array_slice($segList, 0, 8);
  6881. $data['keyword'] = implode(',', $segList1);
  6882. }
  6883. if ($data['introduce'] == '' || empty($data['introduce'])) {
  6884. //提取内容中的描述
  6885. $content = $data['content'];
  6886. // 去除 <style> 和 <script> 标签及其内容
  6887. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6888. // 去除所有 HTML 标签
  6889. $content = strip_tags($content);
  6890. // 去除 HTML 实体
  6891. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6892. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6893. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6894. // 去除多余空白
  6895. $content = preg_replace('/\s+/u', '', $content);
  6896. // 截取 100 个字符
  6897. $data['introduce'] = mb_substr($content, 0, 100);
  6898. }
  6899. $user = User::where('id', $data['user_id'])->first();
  6900. if (empty($user)) {
  6901. return Result::error('用户不存在!');
  6902. }
  6903. if ($user['type_id'] == 10000) {
  6904. $data['status'] = 1;
  6905. }
  6906. if (isset($data['level']) && $data['level'] != null) {
  6907. $data['level'] = intval($data['level']);
  6908. } else {
  6909. $data['level'] = null;
  6910. }
  6911. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6912. $this->sendMessage([
  6913. 'talk_type' => 900,
  6914. 'title' => $data['title'],
  6915. 'content' => '提交了审核',
  6916. 'messageType' => 8,
  6917. ]);
  6918. }
  6919. $result = Company::insertGetId($data);
  6920. if ($result) {
  6921. return Result::success($result);
  6922. } else {
  6923. return Result::error('添加失败');
  6924. }
  6925. }
  6926. /**
  6927. * 更新企业
  6928. * @param array $data
  6929. * @return array
  6930. */
  6931. public function upCompany(array $data): array
  6932. {
  6933. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6934. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6935. $data['cat_arr_id'] = json_encode($car_arr_id);
  6936. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  6937. } else {
  6938. $data['cat_arr_id'] = '';
  6939. }
  6940. if ($data['imgurl'] == '') {
  6941. //content中提取图片第一个图,正则提取
  6942. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6943. preg_match_all($reg, $data['content'], $matches);
  6944. if (isset($matches[1][0])) {
  6945. //截取varchar
  6946. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6947. }
  6948. }
  6949. if ($data['keyword'] == '') {
  6950. //提取标题+内容中的关键词
  6951. $data['keyword'] = $data['title'];
  6952. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6953. Jieba::init(); // 初始化 jieba-php
  6954. Finalseg::init();
  6955. $segList = Jieba::cut($data['keyword']);
  6956. $segList1 = array_slice($segList, 0, 8);
  6957. $data['keyword'] = implode(',', $segList1);
  6958. }
  6959. if ($data['introduce'] == '') {
  6960. //提取内容中的描述
  6961. $content = $data['content'];
  6962. // 去除 <style> 和 <script> 标签及其内容
  6963. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6964. // 去除所有 HTML 标签
  6965. $content = strip_tags($content);
  6966. // 去除 HTML 实体
  6967. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6968. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6969. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6970. // 去除多余空白
  6971. $content = preg_replace('/\s+/u', '', $content);
  6972. // 截取 100 个字符
  6973. $data['introduce'] = mb_substr($content, 0, 100);
  6974. }
  6975. if (isset($data['level']) && $data['level'] != null) {
  6976. $data['level'] = intval($data['level']);
  6977. } else {
  6978. $data['level'] = null;
  6979. }
  6980. $user = User::where('id', $data['user_id'])->first();
  6981. if (empty($user)) {
  6982. return Result::error('用户不存在!');
  6983. }
  6984. if ($user['type_id'] == 10000) {
  6985. $data['status'] = 1;
  6986. } else {
  6987. $data['status'] = 0;
  6988. }
  6989. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6990. $this->sendMessage([
  6991. 'talk_type' => 900,
  6992. 'title' => $data['title'],
  6993. 'content' => '提交了审核',
  6994. 'messageType' => 8,
  6995. ]);
  6996. }
  6997. $result = Company::where('id', $data['id'])->update($data);
  6998. if ($result) {
  6999. return Result::success($result);
  7000. } else {
  7001. return Result::error('修改失败');
  7002. }
  7003. }
  7004. /**
  7005. * 删除企业
  7006. * @param array $data
  7007. * @return array
  7008. */
  7009. public function delCompany(array $data): array
  7010. {
  7011. $result = Company::where('id', $data['id'])->delete();
  7012. if ($result) {
  7013. return Result::success($result);
  7014. } else {
  7015. return Result::error('删除失败');
  7016. }
  7017. }
  7018. /**
  7019. * 审核企业
  7020. * @param array $data
  7021. * @return array
  7022. */
  7023. public function checkCompany(array $data): array
  7024. {
  7025. $user = User::where('id', $data['user_id'])->first();
  7026. if (empty($user)) {
  7027. return Result::error('用户不存在!');
  7028. }
  7029. $company = Company::where('id', $data['id'])->first();
  7030. if (empty($company)) {
  7031. return Result::error('企业不存在!');
  7032. }
  7033. // 状态:0:未审核 1:已审核 2:已拒绝
  7034. if ($data['status'] == 2 || $data['status'] == '2') {
  7035. $this->sendMessage([
  7036. 'talk_type' => 901,
  7037. 'title' => $company['title'],
  7038. 'content' => '审核拒绝',
  7039. 'messageType' => 8,
  7040. 'user_id' => $company['user_id'],
  7041. ]);
  7042. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  7043. } else {
  7044. if ($data['status'] == 1) {
  7045. $this->sendMessage([
  7046. 'talk_type' => 901,
  7047. 'title' => $company['title'],
  7048. 'content' => '审核通过',
  7049. 'messageType' => 8,
  7050. 'user_id' => $company['user_id'],
  7051. ]);
  7052. } else if ($data['status'] == 0) {
  7053. $this->sendMessage([
  7054. 'talk_type' => 900,
  7055. 'title' => $company['title'],
  7056. 'content' => '提交了审核',
  7057. 'messageType' => 8,
  7058. ]);
  7059. }
  7060. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  7061. }
  7062. if (empty($result)) {
  7063. return Result::error('审核失败!');
  7064. } else {
  7065. return Result::success($result);
  7066. }
  7067. }
  7068. /**
  7069. * 获取企业信息
  7070. * @param array $data
  7071. * @return array
  7072. */
  7073. public function getCompanyInfo(array $data): array
  7074. {
  7075. $result = Company::where('id', $data['id'])->first();
  7076. $city_arr = json_decode($result['city_arr_id']);
  7077. $result['city_name'] = District::whereIn('id', $city_arr)
  7078. ->pluck('name')
  7079. ->implode('-');
  7080. if (empty($result)) {
  7081. return Result::error('企业不存在!');
  7082. } else {
  7083. return Result::success($result);
  7084. }
  7085. }
  7086. /**
  7087. * @param array $data
  7088. * @return array
  7089. */
  7090. public function getWebsiteCompany(array $data): array
  7091. {
  7092. $categorys = json_decode($data['id'], true);
  7093. $category_arr = $this->processArticlePro($data['website_id']);
  7094. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7095. $catiall = $category_arr['catiall'];
  7096. $categoryIds = $category_arr['categoryIds'];
  7097. // return Result::success($category_arr);
  7098. foreach ($categorys as $key => $value) {
  7099. if (array_key_exists('level', $value)) {
  7100. $parts = explode(',', $value['level']);
  7101. $level = $parts[0] ?? null;
  7102. $imgnum = $parts[1] ?? null;
  7103. $textnum = $parts[2] ?? null;
  7104. if (!empty($textnum) && $textnum > 0) {
  7105. $text_num = Company::where('level', $level)
  7106. ->whereIn('category_id', $categoryIds)
  7107. ->where('status', 1)
  7108. ->select(
  7109. 'company.id',
  7110. 'company.title',
  7111. 'company.description',
  7112. 'company.updated_at',
  7113. 'company.category_id',
  7114. 'company.cat_arr_id'
  7115. )
  7116. ->orderBy('updated_at', 'desc')
  7117. ->limit($textnum)
  7118. ->get()->all();
  7119. }
  7120. if (!empty($imgnum) && $imgnum > 0) {
  7121. $img_num = Company::where('level', $level)
  7122. ->whereIn('category_id', $categoryIds)
  7123. ->where('status', 1)
  7124. ->where('imgurl', '!=', '')
  7125. ->whereNotNull('imgurl')
  7126. ->select(
  7127. 'company.id',
  7128. 'company.title',
  7129. 'company.description',
  7130. 'company.updated_at',
  7131. 'company.imgurl as imgs',
  7132. 'company.category_id',
  7133. 'company.cat_arr_id'
  7134. )
  7135. ->orderBy('updated_at', 'desc')
  7136. ->limit($imgnum)
  7137. ->get()->all();
  7138. }
  7139. }
  7140. if (array_key_exists('id', $value)) {
  7141. $parts = explode(',', $value['id']);
  7142. $category_id = $parts[0] ?? null;
  7143. $imgnum = $parts[1] ?? null;
  7144. $textnum = $parts[2] ?? null;
  7145. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  7146. if (!empty($textnum) && $textnum > 0) {
  7147. $text_num = Company::whereIn('category_id', $category_arr)
  7148. // ->where('website_id', $data['website_id'])
  7149. ->where('status', 1)
  7150. ->select(
  7151. 'company.id',
  7152. 'company.title',
  7153. 'company.description',
  7154. 'company.updated_at',
  7155. 'company.category_id',
  7156. 'company.cat_arr_id'
  7157. )
  7158. ->orderBy('updated_at', 'desc')
  7159. ->limit($textnum)
  7160. ->get()->all();
  7161. }
  7162. if (!empty($imgnum) && $imgnum > 0) {
  7163. $img_num = Company::whereIn('category_id', $category_arr)
  7164. // ->where('website_id', $data['website_id'])
  7165. ->where('status', 1)
  7166. ->where('imgurl', '!=', '')
  7167. ->whereNotNull('imgurl')
  7168. ->select(
  7169. 'company.id',
  7170. 'company.title',
  7171. 'company.description',
  7172. 'company.updated_at',
  7173. 'company.imgurl as imgs',
  7174. 'company.category_id',
  7175. 'company.cat_arr_id'
  7176. )
  7177. ->orderBy('updated_at', 'desc')
  7178. ->limit($imgnum)
  7179. ->get()->all();
  7180. }
  7181. }
  7182. if (!empty($text_num)) {
  7183. foreach ($text_num as $k => $v) {
  7184. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7185. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7186. }
  7187. }
  7188. if (!empty($img_num)) {
  7189. foreach ($img_num as $k => $v) {
  7190. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7191. $imgurl = json_decode($v['imgs'], true);
  7192. if (!empty($imgurl)) {
  7193. $img_num[$k]->imgurl = $imgurl[0];
  7194. }
  7195. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7196. }
  7197. }
  7198. $company[$key]['img_num'] = $img_num ?? [];
  7199. $company[$key]['text_num'] = $text_num ?? [];
  7200. }
  7201. if (empty($company)) {
  7202. return Result::error("暂无相关企业信息", 0);
  7203. }
  7204. return Result::success($company);
  7205. }
  7206. /**
  7207. * @param array $data
  7208. * @return array
  7209. */
  7210. public function getWebsiteCompanyList(array $data): array
  7211. {
  7212. $where['website_id'] = $data['website_id'];
  7213. $where['status'] = 1;
  7214. $categoryIds = [];
  7215. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7216. $category_id = $data['category_id'];
  7217. }
  7218. $category_arr = $this->processArticlePro($data['website_id']);
  7219. $categoryIds = $category_arr['categoryIds'];
  7220. // return Result::success($cat_1st_arr);
  7221. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  7222. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  7223. })
  7224. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  7225. $query->whereIn('category_id', $categoryIds);
  7226. })
  7227. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  7228. $query->where('category_id', $category_id);
  7229. })
  7230. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  7231. ->orderBy('updated_at', 'desc')
  7232. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7233. if (empty($company)) {
  7234. return Result::error("暂无相关公司信息", 0);
  7235. }
  7236. $result = [
  7237. 'count' => $company->total(),
  7238. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  7239. ];
  7240. return Result::success($result);
  7241. }
  7242. /**
  7243. * 获取项目列表
  7244. * @param array $data
  7245. * @return array
  7246. */
  7247. public function getProjectList(array $data): array
  7248. {
  7249. $where = [];
  7250. $user = User::where('id', $data['user_id'])->first();
  7251. if (empty($user)) {
  7252. return Result::error('用户不存在!');
  7253. }
  7254. if ($user->type_id != 10000) {
  7255. array_push($where, ['project.user_id', $data['user_id']]);
  7256. }
  7257. $query = Project::query();
  7258. if (isset($data['website_id']) && !empty($data['website_id'])) {
  7259. array_push($where, ['project.website_id', $data['website_id']]);
  7260. }
  7261. if (isset($data['title']) && !empty($data['title'])) {
  7262. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  7263. }
  7264. if ($data['status'] != 3) {
  7265. array_push($where, ['project.status', $data['status']]);
  7266. }
  7267. $query = Project::where($where)
  7268. ->when($data['status'] == 3, function ($query) {
  7269. $query->whereIn('project.status', [0, 2]);
  7270. });
  7271. $count = $query->clone()
  7272. ->count();
  7273. $rows = $query->clone()
  7274. ->leftJoin('website', 'project.website_id', 'website.id')
  7275. ->leftJoin('website_category', function ($join) {
  7276. $join->on('project.website_id', '=', 'website_category.website_id')
  7277. ->on('project.category_id', '=', 'website_category.category_id');
  7278. })
  7279. ->select(
  7280. 'project.id',
  7281. 'project.title',
  7282. 'project.updated_at',
  7283. 'project.status',
  7284. 'website.website_name',
  7285. 'website_category.alias as category_name',
  7286. 'project.website_id',
  7287. 'project.user_id'
  7288. )
  7289. ->orderBy('project.updated_at', 'desc')
  7290. ->offset(($data['page'] - 1) * $data['pageSize'])
  7291. ->limit($data['pageSize'])
  7292. ->get();
  7293. if ($rows->isEmpty()) {
  7294. return Result::error("暂无相关项目信息", 0);
  7295. }
  7296. $result = [
  7297. 'count' => $count,
  7298. 'rows' => $rows,
  7299. ];
  7300. return Result::success($result);
  7301. }
  7302. /**
  7303. * 添加项目
  7304. * @param array $data
  7305. * @return array
  7306. */
  7307. public function addProject(array $data): array
  7308. {
  7309. $user = User::where('id', $data['user_id'])->first();
  7310. if (empty($user)) {
  7311. return Result::error("暂无相关用户信息", 0);
  7312. }
  7313. if ($user->type_id == 10000) {
  7314. $data['status'] = 1;
  7315. } else {
  7316. $data['status'] = 0;
  7317. }
  7318. if ($data['keyword'] == '') {
  7319. //提取标题+内容中的关键词
  7320. $data['keyword'] = $data['title'];
  7321. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7322. Jieba::init(); // 初始化 jieba-php
  7323. Finalseg::init();
  7324. $segList = Jieba::cut($data['keyword']);
  7325. $segList1 = array_slice($segList, 0, 8);
  7326. $data['keyword'] = implode(',', $segList1);
  7327. }
  7328. if ($data['description'] == '') {
  7329. //提取内容中的描述
  7330. // var_dump(11111);
  7331. //提取内容中的描述
  7332. $content = $data['introduce'];
  7333. // 去除 <style> 和 <script> 标签及其内容
  7334. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7335. // 去除所有 HTML 标签
  7336. $content = strip_tags($content);
  7337. // 去除 HTML 实体
  7338. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7339. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7340. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7341. // 去除多余空白
  7342. $content = preg_replace('/\s+/u', '', $content);
  7343. // 截取 100 个字符
  7344. $data['description'] = mb_substr($content, 0, 100);
  7345. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7346. }
  7347. if ($data['status'] == 0) {
  7348. $this->sendMessage([
  7349. 'talk_type' => 1000,
  7350. 'title' => $data['title'],
  7351. 'content' => '提交了审核',
  7352. 'messageType' => 9,
  7353. ]);
  7354. }
  7355. $project = Project::insertGetId($data);
  7356. if (empty($project)) {
  7357. return Result::error("暂无相关项目信息", 0);
  7358. }
  7359. return Result::success($project);
  7360. }
  7361. /**
  7362. * 更新项目
  7363. * @param array $data
  7364. * @return array
  7365. */
  7366. public function upProject(array $data): array
  7367. {
  7368. $project = Project::where('id', $data['id'])->first();
  7369. if (empty($project)) {
  7370. return Result::error("暂无相关项目信息", 0);
  7371. }
  7372. $id = $data['id'];
  7373. unset($data['id']);
  7374. $user = User::where('id', $data['user_id'])->first();
  7375. if (empty($user)) {
  7376. return Result::error("暂无相关用户信息", 0);
  7377. }
  7378. if ($user->type_id == 10000) {
  7379. $data['status'] = 1;
  7380. } else {
  7381. $data['status'] = 0;
  7382. }
  7383. unset($data['user_id']);
  7384. if ($data['keyword'] == '') {
  7385. //提取标题+内容中的关键词
  7386. $data['keyword'] = $data['title'];
  7387. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7388. Jieba::init(); // 初始化 jieba-php
  7389. Finalseg::init();
  7390. $segList = Jieba::cut($data['keyword']);
  7391. $segList1 = array_slice($segList, 0, 8);
  7392. $data['keyword'] = implode(',', $segList1);
  7393. }
  7394. if ($data['description'] == '') {
  7395. //提取内容中的描述
  7396. // var_dump(11111);
  7397. //提取内容中的描述
  7398. $content = $data['introduce'];
  7399. // 去除 <style> 和 <script> 标签及其内容
  7400. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7401. // 去除所有 HTML 标签
  7402. $content = strip_tags($content);
  7403. // 去除 HTML 实体
  7404. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7405. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7406. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7407. // 去除多余空白
  7408. $content = preg_replace('/\s+/u', '', $content);
  7409. // 截取 100 个字符
  7410. $data['description'] = mb_substr($content, 0, 100);
  7411. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7412. }
  7413. if ($data['status'] == 0) {
  7414. $this->sendMessage([
  7415. 'talk_type' => 1000,
  7416. 'title' => $data['title'],
  7417. 'content' => '提交了审核',
  7418. 'messageType' => 9,
  7419. ]);
  7420. }
  7421. $result = Project::where('id', $id)->update($data);
  7422. if (empty($result)) {
  7423. return Result::error("更新失败", 0);
  7424. }
  7425. return Result::success($result);
  7426. }
  7427. /**
  7428. * 删除项目
  7429. * @param array $data
  7430. * @return array
  7431. */
  7432. public function delProject(array $data): array
  7433. {
  7434. $user = User::where('id', $data['user_id'])->first();
  7435. if (empty($user)) {
  7436. return Result::error("暂无相关用户信息", 0);
  7437. }
  7438. $project = Project::where('id', $data['id'])->first();
  7439. if (empty($project)) {
  7440. return Result::error("暂无相关项目信息", 0);
  7441. }
  7442. $result = Project::where('id', $data['id'])->delete();
  7443. if (empty($result)) {
  7444. return Result::error("删除失败", 0);
  7445. }
  7446. return Result::success($result);
  7447. }
  7448. /**
  7449. * 审核项目
  7450. * @param array $data
  7451. * @return array
  7452. */
  7453. public function checkProject(array $data): array
  7454. {
  7455. $user = User::where('id', $data['user_id'])->first();
  7456. if (empty($user)) {
  7457. return Result::error("暂无相关用户信息", 0);
  7458. }
  7459. // 0:未审核; 1:已审核; 2:已拒绝;
  7460. if ($user->type_id != 10000) {
  7461. if ($data['status'] == 1 || $data['status'] == 2) {
  7462. return Result::error("此用户权限不足", 0);
  7463. }
  7464. }
  7465. $project = Project::where('id', $data['id'])->first();
  7466. if (empty($project)) {
  7467. return Result::error("暂无相关项目信息", 0);
  7468. }
  7469. if ($data['status'] == 2) {
  7470. $this->sendMessage([
  7471. 'talk_type' => 1001,
  7472. 'title' => $project['title'],
  7473. 'content' => '审核拒绝',
  7474. 'messageType' => 9,
  7475. 'user_id' => $project['user_id'],
  7476. ]);
  7477. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7478. } else {
  7479. if ($data['status'] == 1) {
  7480. $this->sendMessage([
  7481. 'talk_type' => 1001,
  7482. 'title' => $project['title'],
  7483. 'content' => '审核通过',
  7484. 'messageType' => 9,
  7485. 'user_id' => $project['user_id'],
  7486. ]);
  7487. } else if ($data['status'] == 0) {
  7488. $this->sendMessage([
  7489. 'talk_type' => 1000,
  7490. 'title' => $project['title'],
  7491. 'content' => '提交了审核',
  7492. 'messageType' => 9,
  7493. ]);
  7494. }
  7495. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7496. }
  7497. if (empty($result)) {
  7498. return Result::error("审核失败", 0);
  7499. }
  7500. return Result::success($result);
  7501. }
  7502. /**
  7503. * 获取项目详情
  7504. * @param array $data
  7505. * @return array
  7506. */
  7507. public function getProjectInfo(array $data): array
  7508. {
  7509. $project = Project::where('id', $data['id'])->first();
  7510. if (empty($project)) {
  7511. return Result::error("暂无相关项目信息", 0);
  7512. }
  7513. return Result::success($project);
  7514. }
  7515. public function getWebsiteCompanyInfo(array $data): array
  7516. {
  7517. $company = Company::where('id', $data['id'])
  7518. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7519. ->where('status', 1)
  7520. // ->where('website_id', $data['website_id'])
  7521. ->select('company.*', 'job_industry.hyname as hy_name')
  7522. ->first();
  7523. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7524. switch ($company->jobnature_id) {
  7525. case null:
  7526. $company->jobnature_name = '';
  7527. break;
  7528. case 0:
  7529. $company->jobnature_name = '市场监督';
  7530. break;
  7531. case 1:
  7532. $company->jobnature_name = '信访纪检';
  7533. break;
  7534. case 2:
  7535. $company->jobnature_name = '公检法司';
  7536. break;
  7537. case 3:
  7538. $company->jobnature_name = '高关注机构';
  7539. break;
  7540. default:
  7541. $company->jobnature_name = '';
  7542. break;
  7543. }
  7544. $city_arr = $company->city_arr_id;
  7545. if (!empty($city_arr)) {
  7546. $city_arr = json_decode($city_arr, true);
  7547. $cityNames = District::whereIn('id', $city_arr)
  7548. ->pluck('name')
  7549. ->implode('-');
  7550. $company->city_name = $cityNames;
  7551. } else {
  7552. $company->city_name = '';
  7553. }
  7554. if (empty($company)) {
  7555. return Result::error("暂无相关公司信息", 0);
  7556. }
  7557. return Result::success($company);
  7558. }
  7559. public function getMSG(array $data): array
  7560. {
  7561. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7562. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7563. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7564. $result = [];
  7565. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7566. //最近的5篇已审的文章
  7567. $apply_articale = Article::where('status', 1)
  7568. ->where('admin_user_id', $user_id)
  7569. ->orderBy('updated_at', 'desc')
  7570. // ->limit(5)
  7571. ->get();
  7572. //获取5条用户的已审核商品
  7573. $good = Good::where('status', 2)
  7574. ->where('user_id', $user_id)
  7575. ->orderBy('updated_at', 'desc')
  7576. // ->limit(5)
  7577. ->get();
  7578. //获取5条用户待审核的公告
  7579. $notice = Notice::where('status', 2)
  7580. ->where('user_id', $user_id)
  7581. ->orderBy('updated_at', 'desc')
  7582. ->limit(5)->get();
  7583. //获取5条用户的待审核投诉
  7584. $complaint = Complaint::where('status', 2)
  7585. ->where('user_id', $user_id)
  7586. ->orderBy('updated_at', 'desc')
  7587. // ->limit(5)
  7588. ->get();
  7589. //获取5条用户的book
  7590. $book = Book::where('status', 2)
  7591. ->where('user_id', $user_id)
  7592. ->orderBy('updated_at', 'desc')
  7593. // ->limit(5)
  7594. ->get();
  7595. //获取5条用户的求职
  7596. //获取5条用户的求职 1
  7597. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7598. ->where('job_hunting.user_id', $user_id)
  7599. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7600. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7601. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7602. ->orderBy('updated_at', 'desc')
  7603. // ->limit(5)
  7604. ->get();
  7605. //获取5条用户的求职 2
  7606. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7607. ->where('job_recruiting.user_id', $user_id)
  7608. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7609. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7610. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7611. ->orderBy('updated_at', 'desc')
  7612. // ->limit(5)
  7613. ->get();
  7614. //人才库 1
  7615. $job_apply = JobApply::where('job_apply.status', 1)
  7616. ->where('job_apply.receiver_id', $user_id)
  7617. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7618. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7619. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7620. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7621. ->select('job_recruiting', 'job_recruiting.', '', '')
  7622. ->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')
  7623. ->orderBy('updated_at', 'desc')
  7624. // ->limit(5)
  7625. ->get();
  7626. // 职场机会 2
  7627. $job_resume = JobResume::where('job_resume.status', 1)
  7628. ->where('job_resume.receiver_id', $user_id)
  7629. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7630. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7631. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7632. ->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')
  7633. ->orderBy('updated_at', 'desc')
  7634. // ->limit(5)
  7635. ->get();
  7636. //获取5条用户待处理的投诉
  7637. $complaint_deal = Complaint::where('status', 2)
  7638. ->where('deal', 1)
  7639. ->whereJsonContains('re_user_ids', $user_id)
  7640. ->orderBy('updated_at', 'desc')
  7641. // ->limit(5)
  7642. ->get();
  7643. //获取 被通知者未读信息
  7644. $notice_unread = Notice::where('status', 2)
  7645. ->whereJsonContains('re_user_ids', $user_id)
  7646. //未读消息
  7647. ->where(function ($query) use ($user_id) {
  7648. $query->whereJsonDoesntContain('read_id', $user_id)
  7649. ->orWhereNull('read_id');
  7650. })
  7651. ->orderBy('updated_at', 'desc')
  7652. ->get();
  7653. $complaint_unread = Complaint::where('status', 2)
  7654. ->whereJsonContains('re_user_ids', $user_id)
  7655. //未读消息
  7656. ->where(function ($query) use ($user_id) {
  7657. $query->whereJsonDoesntContain('read_id', $user_id)
  7658. ->orWhereNull('read_id');
  7659. })
  7660. ->orderBy('updated_at', 'desc')
  7661. ->get();
  7662. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7663. $complany = Company::where('status', 1)
  7664. ->where('user_id', $user_id)
  7665. ->orderBy('updated_at', 'desc')
  7666. // ->limit(5)
  7667. ->get();
  7668. //获取5条单聊未读聊天消息
  7669. // $chat = ChatRecords::where('is_read', 0)
  7670. // ->where('user_id', $user_id)
  7671. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7672. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7673. // ->where('action', 'recieved')
  7674. // ->where('talk_type', 1)
  7675. // ->orderBy('created_at', 'desc')
  7676. // // ->limit(5)
  7677. // ->get();
  7678. //获取5条未读群聊信息
  7679. // $chat_group = ChatRecords::where('is_read', 0)
  7680. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7681. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7682. // ->where('user_id', $user_id)
  7683. // ->where('talk_type', 2)
  7684. // ->orderBy('created_at', 'desc')
  7685. // // ->limit(5)
  7686. // ->get();
  7687. //获取5条用户的待审核项目
  7688. $project = Project::where('status', 1)
  7689. ->where('user_id', $user_id)
  7690. ->orderBy('updated_at', 'desc')
  7691. // ->limit(5)
  7692. ->get();
  7693. // count($chat) + count($chat_group) +
  7694. $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)
  7695. + count($complany)
  7696. + count($project)
  7697. + count($notice_unread)
  7698. + count($complaint_unread)
  7699. // + count($chat) + count($chat_group)
  7700. ;
  7701. $result = [
  7702. 'apply_articale' => $apply_articale,
  7703. // 'chat' => $chat,
  7704. // 'chat_group' => $chat_group,
  7705. 'good' => $good,
  7706. 'notice' => $notice,
  7707. 'complaint' => $complaint,
  7708. 'book' => $book,
  7709. 'job_hunting' => $job_hunting,
  7710. 'job_recruiting' => $job_recruiting,
  7711. 'job_apply' => $job_apply,
  7712. 'job_resume' => $job_resume,
  7713. 'complaint_deal' => $complaint_deal,
  7714. 'complany' => $complany,
  7715. 'project' => $project,
  7716. 'notice_unread' => $notice_unread,
  7717. 'complaint_unread' => $complaint_unread,
  7718. 'count' => $count,
  7719. ];
  7720. } elseif ($type_id == 12) {
  7721. //最近的5篇已审的文章
  7722. $apply_articale = Article::where('status', 1)
  7723. ->where('admin_user_id', $user_id)
  7724. ->limit(5)->get();
  7725. //获取5条单聊未读聊天消息
  7726. $chat = ChatRecords::where('is_read', 0)
  7727. ->where('user_id', $user_id)
  7728. ->where('talk_type', 1)
  7729. ->orderBy('created_at', 'desc')
  7730. ->limit(5)->get();
  7731. //获取5条未读群聊信息
  7732. $chat_group = ChatRecords::where('is_read', 0)
  7733. ->where('user_id', $user_id)
  7734. ->where('talk_type', 2)
  7735. ->orderBy('created_at', 'desc')
  7736. ->limit(5)->get();
  7737. //获取5条用户的已审核商品
  7738. $good = Good::where('status', 2)
  7739. ->where('user_id', $user_id)
  7740. ->orderBy('updated_at', 'desc')
  7741. ->limit(5)->get();
  7742. //获取5条用户的book
  7743. $book = Book::where('status', 2)
  7744. ->where('user_id', $user_id)
  7745. ->orderBy('updated_at', 'desc')
  7746. ->limit(5)->get();
  7747. //获取5条用户的求职
  7748. //获取5条用户的求职 1
  7749. //count($chat) + count($chat_group)
  7750. $count = count($apply_articale) + count($good);
  7751. $result = [
  7752. 'apply_articale' => $apply_articale,
  7753. 'chat' => $chat,
  7754. 'chat_group' => $chat_group,
  7755. 'good' => $good,
  7756. 'book' => $book,
  7757. 'count' => $count,
  7758. ];
  7759. } elseif ($type_id == 13) {
  7760. //最近的5篇已审的文章
  7761. $apply_articale = Article::where('status', 1)
  7762. ->where('admin_user_id', $user_id)
  7763. ->limit(5)->get();
  7764. //获取5条单聊未读聊天消息
  7765. $chat = ChatRecords::where('is_read', 0)
  7766. ->where('user_id', $user_id)
  7767. ->where('talk_type', 1)
  7768. ->orderBy('created_at', 'desc')
  7769. ->limit(5)->get();
  7770. //获取5条未读群聊信息
  7771. $chat_group = ChatRecords::where('is_read', 0)
  7772. ->where('user_id', $user_id)
  7773. ->where('talk_type', 2)
  7774. ->orderBy('created_at', 'desc')
  7775. ->limit(5)->get();
  7776. //获取5条用户的已审核商品
  7777. $good = Good::where('status', 2)
  7778. ->where('user_id', $user_id)
  7779. ->orderBy('updated_at', 'desc')
  7780. ->limit(5)->get();
  7781. //count($chat) + count($chat_group) +
  7782. $count = count($apply_articale) + count($good);
  7783. $result = [
  7784. 'apply_articale' => $apply_articale,
  7785. 'chat' => $chat,
  7786. 'chat_group' => $chat_group,
  7787. 'good' => $good,
  7788. 'count' => $count,
  7789. ];
  7790. } elseif ($type_id == 14) {
  7791. //最近的5篇已审的文章
  7792. $apply_articale = Article::where('status', 1)
  7793. ->where('admin_user_id', $user_id)
  7794. // ->limit(5)
  7795. ->get();
  7796. //获取5条用户的已审核商品
  7797. $good = Good::where('status', 2)
  7798. ->where('user_id', $user_id)
  7799. ->orderBy('updated_at', 'desc')
  7800. // ->limit(5)
  7801. ->get();
  7802. $count = count($apply_articale) + count($good);
  7803. $result = [
  7804. 'apply_articale' => $apply_articale,
  7805. 'chat' => '',
  7806. 'chat_group' => '',
  7807. 'good' => $good,
  7808. 'count' => $count,
  7809. ];
  7810. } elseif ($type_id == 10000) {
  7811. //获取未审核的5篇文章
  7812. $apply_articale = Article::where('status', 0)
  7813. ->orderBy('updated_at', 'desc')
  7814. // ->limit(5)
  7815. ->get();
  7816. //获取5条单聊未读聊天消息
  7817. //获取5条单聊未读聊天消息
  7818. // $chat = ChatRecords::where('is_read', 0)
  7819. // ->where('user_id', $user_id)
  7820. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7821. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7822. // ->where('action', 'recieved')
  7823. // ->where('talk_type', 1)
  7824. // ->orderBy('created_at', 'desc')
  7825. // // ->limit(5)
  7826. // ->get();
  7827. // //获取5条未读群聊信息
  7828. // $chat_group = ChatRecords::where('is_read', 0)
  7829. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7830. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7831. // ->where('user_id', $user_id)
  7832. // ->where('talk_type', 2)
  7833. // ->orderBy('created_at', 'desc')
  7834. // // ->limit(5)
  7835. // ->get();
  7836. //获取5条用户的已审核商品
  7837. $good = Good::where('status', 1)
  7838. // ->where('user_id', $user_id)
  7839. ->orderBy('updated_at', 'desc')
  7840. // ->limit(5)
  7841. ->get();
  7842. //获取5条用户待审核的公告
  7843. $notice = Notice::where('status', 1)
  7844. ->orderBy('updated_at', 'desc')
  7845. // ->limit(5)
  7846. ->get();
  7847. //获取5条用户的待审核投诉
  7848. $complaint = Complaint::where('status', 1)
  7849. ->orderBy('updated_at', 'desc')
  7850. // ->limit(5)
  7851. ->get();
  7852. //获取5条用户的book
  7853. $book = Book::where('status', 1)
  7854. ->orderBy('updated_at', 'desc')
  7855. // ->limit(5)
  7856. ->get();
  7857. //获取5条用户的求职 1
  7858. $job_hunting = JobHunting::where('job_hunting.status', 1)
  7859. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7860. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7861. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7862. ->orderBy('updated_at', 'desc')
  7863. // ->limit(5)
  7864. ->get();
  7865. //获取5条用户的求职 2
  7866. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  7867. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7868. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7869. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7870. ->orderBy('updated_at', 'desc')
  7871. // ->limit(5)
  7872. ->get();
  7873. //人才库 1
  7874. $job_apply = JobApply::where('job_apply.status', 1)
  7875. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7876. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7877. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7878. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7879. ->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')
  7880. ->orderBy('updated_at', 'desc')
  7881. // ->limit(5)
  7882. ->get();
  7883. // 职场机会 2
  7884. $job_resume = JobResume::where('job_resume.status', 1)
  7885. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7886. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7887. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7888. ->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')
  7889. ->orderBy('updated_at', 'desc')
  7890. // ->limit(5)
  7891. ->get();
  7892. //待审核数据com pro
  7893. $complany = Company::where('status', 0)
  7894. ->orderBy('updated_at', 'desc')
  7895. // ->limit(5)
  7896. ->get();
  7897. $project = Project::where('status', 0)
  7898. ->orderBy('updated_at', 'desc')
  7899. // ->limit(5)
  7900. ->get();
  7901. $count =
  7902. // count($chat) +
  7903. // count($chat_group) +
  7904. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  7905. // + count($job_apply)
  7906. // + count($job_resume)
  7907. + count($complany)
  7908. + count($project);
  7909. $result = [
  7910. 'apply_articale' => $apply_articale,
  7911. // 'chat' => $chat,
  7912. // 'chat_group' => $chat_group,
  7913. 'good' => $good,
  7914. 'notice' => $notice,
  7915. 'complaint' => $complaint,
  7916. 'book' => $book,
  7917. 'job_hunting' => $job_hunting,
  7918. 'job_recruiting' => $job_recruiting,
  7919. // 'job_apply' => $job_apply,
  7920. // 'job_resume' => $job_resume,
  7921. 'complany' => $complany,
  7922. 'project' => $project,
  7923. 'count' => $count,
  7924. ];
  7925. } elseif ($type_id == 20000) {
  7926. }
  7927. var_dump($type_id, '-----------------test---------');
  7928. return Result::success($result);
  7929. }
  7930. /**
  7931. * @param array $data
  7932. * @return array
  7933. */
  7934. public function getWebsiteProject(array $data): array
  7935. {
  7936. $categorys = json_decode($data['id'], true);
  7937. if (!empty($categorys)) {
  7938. $category_arr = $this->processArticlePro($data['website_id']);
  7939. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7940. $catiall = $category_arr['catiall'];
  7941. // return Result::success($catiall);
  7942. foreach ($categorys as $key => $val) {
  7943. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  7944. $level = explode(',', $val['level'])[0];
  7945. $imgnum = explode(',', $val['level'])[1] ?? null;
  7946. $textnum = explode(',', $val['level'])[2] ?? null;
  7947. if ($level == 1) {
  7948. if (!empty($textnum) && $textnum > 0) {
  7949. $text_num = Project::where('level', $level)
  7950. ->where('website_id', $data['website_id'])
  7951. ->where('status', 1)
  7952. ->select(
  7953. 'project.id',
  7954. 'project.title',
  7955. 'project.description',
  7956. 'project.updated_at',
  7957. 'project.category_id',
  7958. 'project.cat_arr_id'
  7959. )
  7960. ->orderBy('updated_at', 'desc')
  7961. ->limit($textnum)
  7962. ->get()->all();
  7963. }
  7964. if (!empty($imgnum) && $imgnum > 0) {
  7965. $img_num = Project::where('level', $level)
  7966. ->where('website_id', $data['website_id'])
  7967. ->where('status', 1)
  7968. ->where('imgurl', '!=', '')
  7969. ->whereNotNull('imgurl')
  7970. ->select(
  7971. 'project.id',
  7972. 'project.title',
  7973. 'project.description',
  7974. 'project.updated_at',
  7975. 'project.imgurl as imgs',
  7976. 'project.category_id',
  7977. 'project.cat_arr_id'
  7978. )
  7979. ->orderBy('updated_at', 'desc')
  7980. ->limit($imgnum)
  7981. ->get()->all();
  7982. }
  7983. } else {
  7984. if (!empty($textnum) && $textnum > 0) {
  7985. $text_num = Project::where('website_id', $data['website_id'])
  7986. ->where('status', 1)
  7987. ->select(
  7988. 'project.id',
  7989. 'project.title',
  7990. 'project.description',
  7991. 'project.updated_at',
  7992. 'project.category_id',
  7993. 'project.cat_arr_id',
  7994. 'project.website_id',
  7995. 'project.updated_at',
  7996. 'project.created_at'
  7997. )
  7998. ->orderBy('updated_at', 'desc')
  7999. ->limit($textnum)
  8000. ->get()->all();
  8001. }
  8002. if (!empty($imgnum) && $imgnum > 0) {
  8003. $img_num = Project::where('website_id', $data['website_id'])
  8004. ->where('status', 1)
  8005. ->where('imgurl', '!=', '')
  8006. ->whereNotNull('imgurl')
  8007. ->select(
  8008. 'project.id',
  8009. 'project.title',
  8010. 'project.description',
  8011. 'project.updated_at',
  8012. 'project.imgurl as imgs',
  8013. 'project.category_id',
  8014. 'project.cat_arr_id'
  8015. )
  8016. ->orderBy('updated_at', 'desc')
  8017. ->limit($imgnum)
  8018. ->get()->all();
  8019. }
  8020. }
  8021. }
  8022. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  8023. $category_ids = explode(',', $val['id'])[0];
  8024. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  8025. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  8026. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  8027. if (!empty($cat_textnum) && $cat_textnum > 0) {
  8028. $text_num = Project::whereIn('category_id', $category_arr)
  8029. ->where('website_id', $data['website_id'])
  8030. ->where('status', 1)
  8031. ->select(
  8032. 'project.id',
  8033. 'project.title',
  8034. 'project.description',
  8035. 'project.updated_at',
  8036. 'project.category_id',
  8037. 'project.cat_arr_id'
  8038. )
  8039. ->orderBy('updated_at', 'desc')
  8040. ->limit($cat_textnum)
  8041. ->get()->all();
  8042. }
  8043. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  8044. $img_num = Project::whereIn('category_id', $category_arr)
  8045. ->where('website_id', $data['website_id'])
  8046. ->where('status', 1)
  8047. ->where('imgurl', '!=', '')
  8048. ->whereNotNull('imgurl')
  8049. ->select(
  8050. 'project.id',
  8051. 'project.title',
  8052. 'project.description',
  8053. 'project.updated_at',
  8054. 'project.imgurl as imgs',
  8055. 'project.category_id',
  8056. 'project.cat_arr_id'
  8057. )
  8058. ->orderBy('updated_at', 'desc')
  8059. ->limit($cat_imgnum)
  8060. ->get()->all();
  8061. }
  8062. }
  8063. if (!empty($img_num)) {
  8064. foreach ($img_num as $k => $v) {
  8065. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8066. $imgurl = json_decode($v['imgs'], true);
  8067. if (!empty($imgurl)) {
  8068. $img_num[$k]->imgurl = $imgurl[0];
  8069. }
  8070. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8071. }
  8072. }
  8073. if (!empty($text_num)) {
  8074. foreach ($text_num as $k => $v) {
  8075. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8076. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8077. }
  8078. }
  8079. $project[$key]['img_num'] = $img_num ?? [];
  8080. $project[$key]['text_num'] = $text_num ?? [];
  8081. }
  8082. }
  8083. if (empty($project)) {
  8084. return Result::error("暂无相关项目信息", 0);
  8085. }
  8086. return Result::success($project);
  8087. }
  8088. /**
  8089. * @param array $data
  8090. * @return array
  8091. */
  8092. public function getWebsiteProjectInfo(array $data): array
  8093. {
  8094. $project = Project::where('id', $data['id'])
  8095. ->where('status', 1)
  8096. ->where('website_id', $data['website_id'])
  8097. ->select('project.*')
  8098. ->first();
  8099. if (empty($project)) {
  8100. return Result::error("暂无相关项目信息", 0);
  8101. }
  8102. return Result::success($project);
  8103. }
  8104. /**
  8105. * @param array $data
  8106. * @return array
  8107. */
  8108. public function getWebsiteProjectList(array $data): array
  8109. {
  8110. $where = [];
  8111. if (isset($data['category_id']) && !empty($data['category_id'])) {
  8112. $where['category_id'] = $data['category_id'];
  8113. }
  8114. if (isset($data['keyword']) && !empty($data['keyword'])) {
  8115. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  8116. }
  8117. $query = Project::where($where)
  8118. ->where('status', 1)
  8119. ->where('website_id', $data['website_id'])
  8120. ->select(
  8121. 'project.id',
  8122. 'project.title',
  8123. 'project.description',
  8124. 'project.imgurl as imgs',
  8125. 'project.category_id',
  8126. 'project.cat_arr_id'
  8127. )
  8128. ->orderBy('updated_at', 'desc');
  8129. $count = $query->count();
  8130. $project = $query->clone()
  8131. ->offset(($data['page'] - 1) * $data['pageSize'])
  8132. ->limit($data['pageSize'])
  8133. ->get()->all();
  8134. if (empty($project)) {
  8135. return Result::error("暂无相关项目信息", 0);
  8136. }
  8137. $categorys = $this->processArticlePro($data['website_id']);
  8138. $catiall = $categorys['catiall'];
  8139. foreach ($project as $key => $val) {
  8140. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  8141. if (!empty($val['imgs'])) {
  8142. $imgurl = json_decode($val['imgs'], true);
  8143. if (!empty($imgurl)) {
  8144. $project[$key]->imgurl = $imgurl[0];
  8145. }
  8146. } else {
  8147. $project[$key]->imgurl = '';
  8148. }
  8149. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  8150. }
  8151. $result = [
  8152. 'rows' => $project,
  8153. 'count' => $count,
  8154. ];
  8155. return Result::success($result);
  8156. }
  8157. /**
  8158. * @param array $data
  8159. * @return array
  8160. */
  8161. public function getWebsiteCategoryJob(array $data): array
  8162. {
  8163. $categorys = json_decode($data['id'], true);
  8164. if (!empty($categorys)) {
  8165. $category_arr = $this->processArticlePro($data['website_id']);
  8166. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8167. $catiall = $category_arr['catiall'];
  8168. foreach ($categorys as $key => $val) {
  8169. if (isset($val['id']) && !empty($val['id'])) {
  8170. $catid = explode(',', $val['id'])[0] ?? null;
  8171. $type = explode(',', $val['id'])[1] ?? null;
  8172. $textnum = explode(',', $val['id'])[2] ?? null;
  8173. }
  8174. // 4:招聘;5:求职;
  8175. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  8176. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  8177. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  8178. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  8179. ->where('job_recruiting.status', 1)
  8180. ->where('job_recruiting.website_id', $data['website_id'])
  8181. ->select(
  8182. 'job_recruiting.id',
  8183. 'job_recruiting.title',
  8184. 'job_company.business_name',
  8185. 'job_recruiting.updated_at',
  8186. 'job_recruiting.cat_arr_id',
  8187. 'job_recruiting.keyword',
  8188. 'job_recruiting.description'
  8189. )
  8190. ->orderBy('job_recruiting.updated_at', 'desc')
  8191. ->limit($textnum)
  8192. ->get()->all();
  8193. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  8194. // 状态 审核状态,1待审核2已审核3已拒绝
  8195. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  8196. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  8197. ->where('job_hunting.status', 2)
  8198. ->where('job_hunting.website_id', $data['website_id'])
  8199. ->select(
  8200. 'job_hunting.id',
  8201. 'job_hunting.name',
  8202. 'job_hunting.cat_arr_id',
  8203. 'job_position.zwname as job_name',
  8204. 'job_hunting.updated_at',
  8205. 'job_hunting.keyword',
  8206. 'job_hunting.slelf_evaluation'
  8207. )
  8208. ->orderBy('updated_at', 'desc')
  8209. ->limit($textnum)
  8210. ->get()->all();
  8211. } else {
  8212. $job = [];
  8213. }
  8214. // var_dump($catid.'222uuuuuuu'.$key);
  8215. if (!empty($job)) {
  8216. foreach ($job as $k => $value) {
  8217. if (isset($value->cat_arr_id)) {
  8218. $catArr = json_decode($value->cat_arr_id, true);
  8219. $catId = end($catArr);
  8220. } else {
  8221. continue;
  8222. }
  8223. if (isset($catiall[$catId])) {
  8224. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  8225. }
  8226. }
  8227. }
  8228. // var_dump($catid.'xxxxx'.$key);
  8229. $result[$key] = $job ?? [];
  8230. }
  8231. }
  8232. if (empty($result)) {
  8233. return Result::error("暂无相关分类信息", 0);
  8234. }
  8235. return Result::success($result);
  8236. }
  8237. /**
  8238. * 发送消息
  8239. * @param array $messageData
  8240. * @return void
  8241. */
  8242. public function sendMessage($messageData)
  8243. {
  8244. $msg = [
  8245. 'talk_type' => $messageData['talk_type'],
  8246. 'title' => $messageData['title'],
  8247. 'content' => $messageData['content'],
  8248. 'messageType' => $messageData['messageType'],
  8249. 'user_id' => $messageData['user_id'] ?? '',
  8250. 'time' => microtime(),
  8251. ];
  8252. $message = new MqProducer($msg);
  8253. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  8254. $producer->produce($message);
  8255. }
  8256. }