NewsService.php 294 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127
  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. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  69. class NewsService implements NewsServiceInterface
  70. {
  71. #[Inject]
  72. protected Redis $redis;
  73. /**
  74. * 获取导航池列表
  75. * @param array $data
  76. * @return array
  77. */
  78. public function getCategoryList(array $data): array
  79. {
  80. $search = $data['name'] ?? '';
  81. $page = (int)($data['page'] ?? 1);
  82. $perPage = (int)($data['pageSize'] ?? 10);
  83. // 1. 查出所有匹配的分类id
  84. if ($search) {
  85. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  86. if (empty($matchedIds)) {
  87. return Result::success(['rows' => [], 'total' => 0]);
  88. }
  89. // 2. 递归查所有父级,直到一级分类
  90. $idsStr = implode(',', $matchedIds);
  91. $sql = "
  92. WITH RECURSIVE parents AS (
  93. SELECT * FROM category WHERE id IN ($idsStr)
  94. UNION ALL
  95. SELECT c.* FROM category c
  96. INNER JOIN parents p ON c.id = p.pid
  97. )
  98. SELECT * FROM parents
  99. ";
  100. $parents = Db::select($sql);
  101. $parentIds = [];
  102. foreach ($parents as $row) {
  103. if ($row->pid == 0) {
  104. $parentIds[] = $row->id;
  105. }
  106. }
  107. $parentIds = array_unique($parentIds);
  108. } else {
  109. // 没有搜索,一级分类就是根
  110. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  111. }
  112. // 3. 一级分类分页
  113. $total = count($parentIds);
  114. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  115. if (empty($parentIds)) {
  116. return Result::success(['rows' => [], 'total' => $total]);
  117. }
  118. // 4. 递归查所有子孙
  119. $idsStr = implode(',', $parentIds);
  120. $sql = "
  121. WITH RECURSIVE subcategories AS (
  122. SELECT * FROM category WHERE id IN ($idsStr)
  123. UNION ALL
  124. SELECT c.* FROM category c
  125. INNER JOIN subcategories s ON c.pid = s.id
  126. )
  127. SELECT * FROM subcategories ORDER BY updated_at DESC
  128. ";
  129. $allCategories = Db::select($sql);
  130. // 5. 组装树结构
  131. $categoryMap = [];
  132. foreach ($allCategories as $cat) {
  133. $cat = (array)$cat;
  134. $cat['children'] = [];
  135. $categoryMap[$cat['id']] = $cat;
  136. }
  137. foreach ($categoryMap as $id => &$cat) {
  138. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  139. $categoryMap[$cat['pid']]['children'][] = &$cat;
  140. }
  141. }
  142. unset($cat);
  143. $categoryTree = [];
  144. foreach ($parentIds as $id) {
  145. if (isset($categoryMap[$id])) {
  146. $categoryTree[] = $categoryMap[$id];
  147. }
  148. }
  149. return Result::success([
  150. 'rows' => $categoryTree,
  151. 'total' => $total,
  152. ]);
  153. }
  154. private function findMatchedCategories($search)
  155. {
  156. if ($search) {
  157. return Category::where('name', 'like', "%{$search}%")
  158. ->orderBy('updated_at', 'desc')
  159. ->get();
  160. }
  161. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  162. ->get();
  163. }
  164. private function findAllParents($categories)
  165. {
  166. $allCategories = [];
  167. foreach ($categories as $category) {
  168. $parentId = $category->pid;
  169. while ($parentId > 0) {
  170. $parent = Category::find($parentId);
  171. if ($parent) {
  172. $allCategories[$parent->id] = $parent;
  173. $parentId = $parent->pid;
  174. } else {
  175. break;
  176. }
  177. }
  178. $allCategories[$category->id] = $category;
  179. }
  180. return array_values($allCategories);
  181. }
  182. private function buildCategoryTree($category, $allRequiredCategories)
  183. {
  184. $categoryData = $category->toArray();
  185. $children = [];
  186. foreach ($allRequiredCategories as $c) {
  187. if ($c->pid === $category->id) {
  188. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  189. }
  190. }
  191. if (!empty($children)) {
  192. $categoryData['children'] = $children;
  193. }
  194. return $categoryData;
  195. }
  196. public function myCategoryList(array $data): array
  197. {
  198. $sszq = $data['sszq'] ?? '';
  199. unset($data['sszq']);
  200. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  201. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  202. $where[] = [
  203. 'pid',
  204. '=',
  205. $data['pid'],
  206. ];
  207. if (isset($data['name'])) {
  208. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  209. }
  210. var_dump($where);
  211. //根据分类id,从category表中取出分类信息
  212. $result = Category::where($where)
  213. ->whereIn('category.id', $catorytids)
  214. ->select('category.*', 'category.id as category_id')->get();
  215. if (empty($result)) {
  216. return Result::error("没有栏目数据");
  217. }
  218. return Result::success($result);
  219. }
  220. /**
  221. * @param array $data
  222. * @return array
  223. */
  224. public function categoryList(array $data): array
  225. {
  226. $where[] = [
  227. 'pid',
  228. '=',
  229. $data['pid']
  230. ];
  231. if (isset($data['name'])) {
  232. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  233. }
  234. var_dump($where);
  235. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  236. if (empty($result)) {
  237. return Result::error("没有栏目数据");
  238. }
  239. return Result::success($result);
  240. }
  241. /**
  242. * @param array $data
  243. * @return array
  244. */
  245. public function addCategory(array $data): array
  246. {
  247. if (isset($data['id'])) {
  248. unset($data['id']);
  249. }
  250. $id = Category::insertGetId($data);
  251. if (empty($id)) {
  252. return Result::error("添加失败");
  253. }
  254. return Result::success(['id' => $id]);
  255. }
  256. /**
  257. * @param array $data
  258. * @return array
  259. */
  260. public function delCategory(array $data): array
  261. {
  262. Db::beginTransaction();
  263. try {
  264. $categoryList = Category::where(['pid' => $data['id']])->get();
  265. if ($categoryList->toArray()) {
  266. Db::rollBack();
  267. return Result::error("分类下面有子分类不能删除");
  268. }
  269. $articleList = Article::where(['catid' => $data['id']])->get();
  270. if ($articleList->toArray()) {
  271. Db::rollBack();
  272. return Result::error("分类下面有资讯不能删除");
  273. }
  274. $result = Category::where($data)->delete();
  275. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  276. if (!$result) {
  277. Db::rollBack();
  278. return Result::error("删除失败");
  279. }
  280. Db::commit();
  281. return Result::success($result);
  282. } catch (\Exception $e) {
  283. Db::rollBack();
  284. return Result::error("删除失败" . $e->getMessage());
  285. }
  286. }
  287. /**
  288. * @param array $data
  289. * @return array
  290. */
  291. public function updateCategory(array $data): array
  292. {
  293. $where = [
  294. 'id' => $data['id'],
  295. ];
  296. $result = Category::where($where)->update($data);
  297. if ($result) {
  298. return Result::success($result);
  299. } else {
  300. return Result::error("更新失败");
  301. }
  302. }
  303. /**
  304. * 获取导航池信息
  305. * @param array $data
  306. * @return array
  307. */
  308. public function getCategoryInfo(array $data): array
  309. {
  310. $where = [
  311. 'id' => $data['id'],
  312. ];
  313. $result = Category::where($where)->first();
  314. if ($result) {
  315. return Result::success($result);
  316. } else {
  317. return Result::error("更新失败");
  318. }
  319. }
  320. public function getArticleCommend(array $data): array
  321. {
  322. $where = [
  323. 'website_id' => $data['website_id'],
  324. ];
  325. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  326. var_dump($ids);
  327. if (empty($ids)) {
  328. return Result::error("没有推荐数据");
  329. }
  330. //id
  331. $whereArticle = [];
  332. if (isset($data['id'])) {
  333. $whereArticle['id'] = $data['id'];
  334. }
  335. //title like
  336. if (isset($data['title'])) {
  337. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  338. }
  339. $article = Article::whereIn('catid', values: $ids)->where('status', 1)
  340. ->where($whereArticle)
  341. ->orderBy('id', 'desc')
  342. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  343. if ($article) {
  344. $data = [
  345. 'rows' => $article->items(),
  346. 'count' => $article->total(),
  347. ];
  348. return Result::success($data);
  349. } else {
  350. return Result::error("获取失败失败");
  351. }
  352. }
  353. /**
  354. * @param array $data
  355. * @return array
  356. */
  357. public function getArticleList(array $data): array
  358. {
  359. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  360. $type_id = $data['type_id'];
  361. unset($data['type_id']);
  362. $user_id = $data['user_id'];
  363. unset($data['user_id']);
  364. $where = [];
  365. $status1 = [];
  366. if (isset($data['id']) && $data['id']) {
  367. array_push($where, ['article.id', '=', $data['id']]);
  368. }
  369. if (isset($data['title']) && $data['title']) {
  370. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  371. }
  372. if (isset($data['category_name']) && $data['category_name']) {
  373. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  374. }
  375. if (isset($data['catid']) && $data['catid']) {
  376. array_push($where, ['article.catid', '=', $data['catid']]);
  377. }
  378. if (isset($data['author']) && $data['author']) {
  379. array_push($where, ['article.author', '=', $data['author']]);
  380. }
  381. if (isset($data['islink']) && $data['islink'] !== "") {
  382. array_push($where, ['article.islink', '=', $data['islink']]);
  383. }
  384. if (isset($data['status']) && $data['status'] !== "") {
  385. array_push($where, ['article.status', '=', $data['status']]);
  386. }
  387. if (isset($data['status1'])) {
  388. $status1 = json_decode(($data['status1']));
  389. }
  390. //不是管理员展示个人数据;
  391. if ($type_id != 10000) {
  392. $where[] = ['article.admin_user_id', '=', $user_id];
  393. }
  394. $rep = Article::where($where)
  395. ->whereNotIn('article.status', [404])
  396. ->when($status1, function ($query) use ($status1) {
  397. if (isset($status1) && $status1) {
  398. $query->whereIn('article.status', $status1);
  399. }
  400. })
  401. ->leftJoin('category', 'article.catid', 'category.id')
  402. ->leftJoin('website_category', function ($join) {
  403. $join->on('article.web_site_id', '=', 'website_category.website_id')
  404. ->on('article.catid', '=', 'website_category.category_id');
  405. })
  406. ->select("article.*", "category.name as category_name", "website_category.alias")
  407. ->orderBy("article.updated_at", "desc")
  408. ->limit($data['pageSize'])
  409. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  410. $count = Article::where($where)->whereNotIn('article.status', [404])
  411. ->when($status1, function ($query) use ($status1) {
  412. if (isset($status1) && $status1) {
  413. $query->whereIn('article.status', $status1);
  414. }
  415. })
  416. ->leftJoin('category', 'article.catid', 'category.id')->count();
  417. $data = [
  418. 'rows' => $rep->toArray(),
  419. 'count' => $count,
  420. ];
  421. if (empty($rep)) {
  422. return Result::error("没有信息数据");
  423. }
  424. return Result::success($data);
  425. }
  426. /**
  427. * @param array $data
  428. * @return array
  429. */
  430. public function addArticle(array $data): array
  431. {
  432. var_dump($data, '----------12-----------1');
  433. unset($data['user_type']);
  434. unset($data['nav_add_pool_id']);
  435. // unset($data['commend_id']);
  436. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  437. Db::beginTransaction();
  438. try {
  439. //处理投票
  440. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  441. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  442. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  443. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  444. unset($data['is_survey']);
  445. unset($data['survey_name']);
  446. unset($data['suvey_array']);
  447. // unset($data['website_id']);
  448. // unset($data['web_site_id']);
  449. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  450. if ($data['hits'] == '') {
  451. $data['hits'] = 0;
  452. }
  453. if ($data['is_original'] == '') {
  454. $data['is_original'] = 0;
  455. }
  456. if ($data['status'] == '') {
  457. $data['status'] = 0;
  458. }
  459. $articleData = $data;
  460. unset($articleData['content']);
  461. //自动处理缩略图、关键字、描述
  462. if ($articleData['imgurl'] == '') {
  463. //如果没有图,设置level=0
  464. $levelArr = json_decode($articleData['level'], true);
  465. var_dump($levelArr, '----------levelArr-----------1');
  466. //content中提取图片第一个图,正则提取
  467. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  468. preg_match_all($reg, $data['content'], $matches);
  469. if (isset($matches[1][0])) {
  470. //截取varchar240
  471. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  472. //如果有图,设置level=3
  473. if (!in_array(3, $levelArr)) {
  474. $levelArr[] = 3;
  475. }
  476. $articleData['level'] = json_encode($levelArr);
  477. } else {
  478. if (!in_array(0, $levelArr)) {
  479. $levelArr[] = 0;
  480. }
  481. $articleData['level'] = json_encode($levelArr);
  482. }
  483. }
  484. var_dump($articleData['level'], '----------$articleData[level]----------1');
  485. if ($articleData['keyword'] == '') {
  486. //提取标题+内容中的关键词
  487. $articleData['keyword'] = $data['title'];
  488. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  489. Jieba::init(); // 初始化 jieba-php
  490. Finalseg::init();
  491. $segList = Jieba::cut($articleData['keyword']);
  492. $segList1 = array_slice($segList, 0, 8);
  493. $articleData['keyword'] = implode(',', $segList1);
  494. }
  495. if ($articleData['introduce'] == '') {
  496. //提取内容中的描述
  497. $content = $data['content'];
  498. // 去除 <style> 和 <script> 标签及其内容
  499. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  500. // 去除所有 HTML 标签
  501. $content = strip_tags($content);
  502. // 去除 HTML 实体
  503. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  504. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  505. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  506. // 去除多余空白
  507. $content = preg_replace('/\s+/u', '', $content);
  508. // 截取 100 个字符
  509. $articleData['introduce'] = mb_substr($content, 0, 100);
  510. }
  511. if ($articleData['status'] == 0) {
  512. $this->sendMessage([
  513. 'talk_type' => 100,
  514. 'title' => $articleData['title'],
  515. 'content' => '提交了审核',
  516. 'messageType' => 2,
  517. ]);
  518. }
  519. $id = Article::insertGetId($articleData);
  520. $articleDataContent = [
  521. 'article_id' => $id,
  522. 'content' => $data['content'],
  523. ];
  524. ArticleData::insertGetId($articleDataContent);
  525. //处理投票
  526. if ($is_survey == 1) {
  527. //生成年月日时分秒+8位随机数
  528. $uuid = date('YmdHis') . rand(10000000, 99999999);
  529. var_dump($suvey_array, 'suvey_array________');
  530. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  531. var_dump($suveys_array, '---------------------1');
  532. var_dump($suvey_array, '---------------------2');
  533. $suvey_data = [];
  534. foreach ($suveys_array as $key => $value) {
  535. if ($value == '') {
  536. continue;
  537. }
  538. if (is_array($value)) {
  539. $suvey_data[] = [
  540. 'sur_id' => $uuid,
  541. 'art_id' => $id,
  542. 'website_id' => $website_id ?? 2,
  543. 'survey_name' => $survey_name,
  544. 'choice_name' => $value[1],
  545. 'is_other' => 1,
  546. 'other_id' => 0,
  547. 'results' => 0,
  548. ];
  549. } else {
  550. $suvey_data[] = [
  551. 'sur_id' => $uuid,
  552. 'art_id' => $id,
  553. 'website_id' => $website_id ?? 2,
  554. 'survey_name' => $survey_name,
  555. 'choice_name' => $value,
  556. 'is_other' => 0,
  557. 'other_id' => 0,
  558. 'results' => 0,
  559. ];
  560. }
  561. if (empty($suvey_data)) {
  562. throw new \Exception("投票数据为空");
  563. }
  564. }
  565. $result = ArticleSurvey::insert($suvey_data);
  566. if (!$result) {
  567. throw new \Exception("投票失败,ArticleSurvey插入失败");
  568. }
  569. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  570. if (!$result) {
  571. throw new \Exception("投票失败,更新主表失败");
  572. }
  573. }
  574. Db::commit();
  575. return Result::success(['id' => $id]);
  576. } catch (\Throwable $ex) {
  577. Db::rollBack();
  578. var_dump($ex->getMessage());
  579. return Result::error("创建失败", 0);
  580. }
  581. }
  582. /**
  583. * @param array $data
  584. * @return array
  585. */
  586. public function delArticle(array $data): array
  587. {
  588. $result = Article::where($data)->delete();
  589. //survey投票删除
  590. articleSurvey::where(['art_id' => $data['id']])->delete();
  591. if (!$result) {
  592. return Result::error("删除失败");
  593. }
  594. return Result::success($result);
  595. }
  596. /**
  597. * @param array $data
  598. * @return array
  599. */
  600. public function updateArticle(array $data): array
  601. {
  602. var_dump($data, '----------12-----------1');
  603. Db::beginTransaction();
  604. unset($data['user_type']);
  605. // unset($data['web_site_id']);
  606. unset($data['nav_add_pool_id']);
  607. try {
  608. //处理投票
  609. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  610. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  611. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  612. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  613. unset($data['is_survey']);
  614. unset($data['survey_name']);
  615. unset($data['suvey_array']);
  616. unset($data['website_id']);
  617. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  618. if ($data['hits'] == '') {
  619. $data['hits'] = 0;
  620. }
  621. if ($data['is_original'] == '') {
  622. $data['is_original'] = 0;
  623. }
  624. if ($data['status'] == '') {
  625. $data['status'] = 0;
  626. }
  627. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  628. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  629. $articleData = $data;
  630. unset($articleData['content']);
  631. unset($articleData['status_name']);
  632. unset($articleData['name']);
  633. unset($articleData['content']);
  634. unset($articleData['pid_arr']);
  635. unset($articleData['pid']);
  636. //自动处理缩略图、关键字、描述
  637. if ($articleData['imgurl'] == '') {
  638. //如果没有图,设置level=0
  639. $levelArr = json_decode($articleData['level'], true);
  640. var_dump($levelArr, '----------levelArr-----------1');
  641. //content中提取图片第一个图,正则提取
  642. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  643. preg_match_all($reg, $data['content'], $matches);
  644. if (isset($matches[1][0])) {
  645. //截取varchar240
  646. // 截取到第一个<
  647. $articleData['imgurl'] = $matches[1][0];
  648. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  649. $pos = strpos($articleData['imgurl'], '"');
  650. if ($pos !== false) {
  651. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  652. }
  653. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  654. //如果有图,设置level=3
  655. if (!in_array(3, $levelArr)) {
  656. $levelArr[] = 3;
  657. }
  658. $articleData['level'] = json_encode($levelArr);
  659. } else {
  660. if (!in_array(0, $levelArr)) {
  661. $levelArr[] = 0;
  662. }
  663. $articleData['level'] = json_encode($levelArr);
  664. }
  665. }
  666. var_dump($articleData['level'], '----------$articleData[level]----------1');
  667. if ($articleData['keyword'] == '') {
  668. //提取标题+内容中的关键词
  669. $articleData['keyword'] = $data['title'];
  670. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  671. Jieba::init(); // 初始化 jieba-php
  672. Finalseg::init();
  673. $segList = Jieba::cut($articleData['keyword']);
  674. $segList1 = array_slice($segList, 0, 8);
  675. $articleData['keyword'] = implode(',', $segList1);
  676. }
  677. if ($articleData['introduce'] == '') {
  678. //提取内容中的描述
  679. $content = $data['content'];
  680. // 去除 <style> 和 <script> 标签及其内容
  681. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  682. // 去除所有 HTML 标签
  683. $content = strip_tags($content);
  684. // 去除 HTML 实体
  685. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  686. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  687. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  688. // 去除多余空白
  689. $content = preg_replace('/\s+/u', '', $content);
  690. // 截取 100 个字符
  691. $articleData['introduce'] = mb_substr($content, 0, 100);
  692. }
  693. if ($articleData['status'] == 0) {
  694. $this->sendMessage([
  695. 'talk_type' => 100,
  696. 'title' => $articleData['title'],
  697. 'content' => '提交了审核',
  698. 'messageType' => 2,
  699. ]);
  700. }
  701. $id = Article::where(['id' => $data['id']])->update($articleData);
  702. $articleDataContent = [
  703. 'content' => $data['content'],
  704. ];
  705. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  706. //处理投票
  707. $id = $data['id'];
  708. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  709. var_dump($suvey_array, 'suvey_array________delete');
  710. //处理投票
  711. if ($is_survey == 1) {
  712. //生成年月日时分秒+8位随机数
  713. $uuid = date('YmdHis') . rand(10000000, 99999999);
  714. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  715. var_dump($suveys_array, '---------------------1');
  716. $suvey_data = [];
  717. if (is_array($suveys_array)) {
  718. foreach ($suveys_array as $key => $value) {
  719. if ($value == '') {
  720. continue;
  721. }
  722. if (is_array($value)) {
  723. $suvey_data[] = [
  724. 'sur_id' => $uuid,
  725. 'art_id' => $id,
  726. 'website_id' => $website_id ?? 2,
  727. 'survey_name' => $survey_name,
  728. 'choice_name' => $value[1],
  729. 'is_other' => 1,
  730. 'other_id' => 0,
  731. 'results' => 0,
  732. ];
  733. } else {
  734. $suvey_data[] = [
  735. 'sur_id' => $uuid,
  736. 'art_id' => $id,
  737. 'website_id' => $website_id ?? 2,
  738. 'survey_name' => $survey_name,
  739. 'choice_name' => $value,
  740. 'is_other' => 0,
  741. 'other_id' => 0,
  742. 'results' => 0,
  743. ];
  744. }
  745. if (empty($suvey_data)) {
  746. throw new \Exception("投票数据为空");
  747. }
  748. }
  749. }
  750. $result = ArticleSurvey::insert($suvey_data);
  751. if (!$result) {
  752. throw new \Exception("投票失败");
  753. }
  754. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  755. if (!$result) {
  756. throw new \Exception("投票失败");
  757. }
  758. } else {
  759. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  760. }
  761. Db::commit();
  762. return Result::success([]);
  763. } catch (\Throwable $ex) {
  764. Db::rollBack();
  765. var_dump($ex->getMessage());
  766. return Result::error("更新失败" . $ex->getMessage(), 0);
  767. }
  768. }
  769. /**
  770. * 更新资讯状态
  771. * @param array $data
  772. * @return array
  773. */
  774. public function upArticleStatus(array $data): array
  775. {
  776. $articleData = Article::where(['id' => $data['id']])->first();
  777. //发送10次
  778. // for ($i = 0; $i < 10; $i++) {
  779. // $this->sendMessage([
  780. // 'talk_type' => 100,
  781. // 'title' => $i . $articleData['title'],
  782. // 'content' => '审核通过',
  783. // 'messageType' => 2,
  784. // 'user_id' => $articleData['admin_user_id'],
  785. // ]);
  786. // }
  787. // var_dump($data['status'], 'status');
  788. // return Result::success();
  789. if ($data['status'] == 1) {
  790. $this->sendMessage([
  791. 'talk_type' => 101,
  792. 'title' => $articleData['title'],
  793. 'content' => '审核通过',
  794. 'messageType' => 2,
  795. 'user_id' => $articleData['admin_user_id'],
  796. ]);
  797. }
  798. if ($data['status'] == 2) {
  799. $this->sendMessage([
  800. 'talk_type' => 101,
  801. 'title' => $articleData['title'],
  802. 'content' => '审核拒绝',
  803. 'messageType' => 2,
  804. 'user_id' => $articleData['admin_user_id'],
  805. ]);
  806. }
  807. if ($data['status'] == 0) {
  808. $this->sendMessage([
  809. 'talk_type' => 100,
  810. 'title' => $articleData['title'],
  811. 'content' => '提交了审核',
  812. 'messageType' => 2,
  813. ]);
  814. }
  815. $result = Article::where(['id' => $data['id']])->update($data);
  816. if (isset($data['ignore_ids']) && !empty($data['ignore_ids'])) {
  817. //article_ignore 表插入数据 db操作
  818. //转成数组
  819. //删掉数据重新写入
  820. DB::table('article_ignore')->where('article_id', $data['id'])->delete();
  821. $website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  822. $insert_data = [];
  823. foreach ($website_ids as $key => $value) {
  824. $insert_data[] = [
  825. 'article_id' => $data['id'],
  826. 'website_id' => $value,
  827. ];
  828. }
  829. DB::table('article_ignore')->insert($insert_data);
  830. }
  831. if ($result) {
  832. return Result::success();
  833. } else {
  834. return Result::error("更新状态失败", 0);
  835. }
  836. }
  837. /**
  838. * 获取新闻详情
  839. * @param array $data
  840. * @return array
  841. */
  842. public function getArticleInfo(array $data): array
  843. {
  844. $where = [
  845. 'article.id' => $data['id'],
  846. // 'article.status' => 1,
  847. ];
  848. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  849. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  850. $info = $result;
  851. // var_dump($info, 'info');
  852. $info['survey_array'] = $articleSurvey;
  853. if ($result) {
  854. return Result::success($info);
  855. } else {
  856. return Result::error("查询失败", 0);
  857. }
  858. }
  859. /**
  860. * 获取头条新闻
  861. * @param array $data
  862. * @return array
  863. */
  864. public function getWebsiteArticlett(array $data): array
  865. {
  866. $website_id = $data['website_id'];
  867. $website = Website::where('id', $data['website_id'])->first();
  868. if (empty($website)) {
  869. return Result::error("网站不存在", 0);
  870. }
  871. $categorys = $this->processArticlePro($website_id);
  872. $catiall = $categorys['catiall'];
  873. $categoryIds = $categorys['categoryIds'];
  874. $where = [
  875. 'status' => 1
  876. ];
  877. // $website_column = $website['column'];
  878. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  879. $website_column = json_decode($website['website_column_arr_id'], true);
  880. }
  881. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  882. // return Result::success($diff_pid_categoryIds);
  883. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  884. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  885. }
  886. // $website_id = $data['website_id'];
  887. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  888. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  889. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  890. switch ($data['level']) {
  891. case 1:
  892. case 2:
  893. case 3:
  894. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  895. $query = Article::where($where)
  896. ->where('level', 'like', '%' . $data['level'] . '%')
  897. ->orderBy('updated_at', 'desc');
  898. break;
  899. case 4: //最新资讯
  900. $query = Article::where($where)->orderBy('updated_at', 'desc');
  901. break;
  902. case 5: //资讯推荐
  903. $query = Article::where($where)
  904. ->where('updated_at', '>', $month);
  905. break;
  906. case 7: //资讯分类
  907. if (isset($data['id']) && !empty($data['id'])) {
  908. $keyword = Article::where('id', $data['id'])->value('keyword');
  909. $keywordArray = explode(',', $keyword);
  910. $whereL7 = [];
  911. foreach ($keywordArray as $k => $v) {
  912. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  913. }
  914. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  915. break;
  916. } else {
  917. return Result::error("请输入资讯ID", 0);
  918. break;
  919. }
  920. default:
  921. break;
  922. }
  923. // $whereL7 = [];
  924. // if(isset($data['id']) && !empty($data['id'])){
  925. // $keyword = Article::where('id', $data['id'])->value('keyword');
  926. // $keywordArray = explode(',', $keyword);
  927. // foreach ($keywordArray as $k => $v) {
  928. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  929. // }
  930. // }
  931. // $query = Article::where($where)
  932. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  933. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  934. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  935. // }
  936. // if($data['level'] == 7){
  937. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  938. // }
  939. // if($data['level'] == 4){
  940. // $query = $query->inRandomOrder()
  941. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  942. // }
  943. // if($data['level'] == 5){
  944. // $query = $query->orderBy('updated_at','desc');
  945. // }
  946. // });
  947. if ($data['textnum'] > 0) {
  948. $query = clone $query;
  949. $result['text'] = $query
  950. ->whereIn('catid', $categoryIds)
  951. ->leftJoinSub(function ($query) use ($website_id) {
  952. $query->from('article_ignore')
  953. ->where('website_id', $website_id);
  954. }, 'article_ignore', function ($join) {
  955. $join->on('article_ignore.article_id', '=', 'article.id');
  956. })
  957. ->where(function ($query) use ($website_id) {
  958. $query->whereNull('article_ignore.article_id')
  959. ->orWhere('article_ignore.website_id', '!=', $website_id);
  960. })
  961. ->select(
  962. 'article.id',
  963. 'article.title',
  964. 'article.author',
  965. 'article.updated_at',
  966. 'article.introduce',
  967. 'article.islink',
  968. 'article.linkurl',
  969. 'article.copyfrom',
  970. 'article.cat_arr_id',
  971. 'article.catid',
  972. 'article.level'
  973. )
  974. ->offset($data['placeid'])
  975. ->limit($data['textnum'])
  976. ->get()->all();
  977. foreach ($result['text'] as $k => $v) {
  978. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  979. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  980. }
  981. }
  982. if ($data['imgnum'] > 0) {
  983. $query = clone $query;
  984. $result['img'] = $query
  985. ->whereIn('catid', $categoryIds)
  986. ->where('article.imgurl', '!=', '')
  987. ->select(
  988. 'article.id',
  989. 'article.title',
  990. 'article.imgurl',
  991. 'article.author',
  992. 'article.updated_at',
  993. 'article.introduce',
  994. 'article.islink',
  995. 'article.linkurl',
  996. 'article.copyfrom',
  997. 'article.cat_arr_id',
  998. 'article.catid',
  999. 'article.level'
  1000. )
  1001. ->offset($data['placeid'])
  1002. ->limit($data['imgnum'])
  1003. ->get()->all();
  1004. foreach ($result['img'] as $k => $v) {
  1005. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1006. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1007. }
  1008. }
  1009. if (empty($result)) {
  1010. return Result::error("暂无相关资讯", 0);
  1011. }
  1012. return Result::success($result);
  1013. }
  1014. /**
  1015. * 获取模块新闻
  1016. * @param array $data
  1017. * @return array
  1018. */
  1019. public function getWebsiteModelArticles(array $data): array
  1020. {
  1021. $catid = $data['catid'];
  1022. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1023. $category = $category->toArray();
  1024. if (!empty($category)) {
  1025. $where = [
  1026. 'status' => 1,
  1027. 'catid' => $catid,
  1028. ];
  1029. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1030. // 1:文字新闻;2:轮播图;3:图文;
  1031. // 级别:0:未分类
  1032. // 3:推荐图片
  1033. if ($data['level'] == 1) {
  1034. $data['level'] = 0;
  1035. }
  1036. $result = Article::where($where)
  1037. ->where(function ($query) use ($data) {
  1038. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1039. ->orWhereNull("level")
  1040. ->orWhereRaw("level = '[]'");
  1041. })
  1042. ->where(function ($query) use ($data) {
  1043. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1044. ->orWhereNull("ignore_ids");
  1045. })
  1046. ->orderBy("updated_at", "desc")
  1047. ->offset($placeid)
  1048. ->limit($data['pagesize'])
  1049. ->get();
  1050. if (empty($result)) {
  1051. return Result::error("此栏目暂无相关新闻", 0);
  1052. }
  1053. } else {
  1054. return Result::error("此网站暂无此栏目", 0);
  1055. }
  1056. return Result::success($result);
  1057. }
  1058. /**
  1059. *获取新闻列表
  1060. * @param array $data
  1061. * @return array
  1062. */
  1063. public function getWebsiteArticleList(array $data): array
  1064. {
  1065. // return Result::success($data);
  1066. $where[] = ['status', '=', 1];
  1067. $website_id = $data['website_id'];
  1068. $website = Website::where('id', $data['website_id'])->first();
  1069. if (empty($website)) {
  1070. return Result::error("网站不存在", 0);
  1071. }
  1072. // $website_column = $website['column'];
  1073. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1074. $website_column = json_decode($website['website_column_arr_id'], true);
  1075. }
  1076. $categorys = $this->processArticlePro($website_id);
  1077. $cat_1st_arr = $categorys['cat_1st_arr'];
  1078. $catiall = $categorys['catiall'];
  1079. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1080. // return Result::success($diff_pid_categoryIds);
  1081. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1082. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1083. }
  1084. if (isset($data['catid']) && !empty($data['catid'])) {
  1085. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1086. if (empty($category)) {
  1087. return Result::error("此网站暂无此栏目", 0);
  1088. }
  1089. array_push($where, ['catid', '=', $data['catid']]);
  1090. }
  1091. // return Result::success($where);
  1092. $query = Article::where($where)
  1093. ->leftJoinSub(function ($query) use ($website_id) {
  1094. $query->from('article_ignore')
  1095. ->where('website_id', $website_id);
  1096. }, 'article_ignore', function ($join) {
  1097. $join->on('article_ignore.article_id', '=', 'article.id');
  1098. })
  1099. ->where(function ($query) use ($website_id) {
  1100. $query->whereNull('article_ignore.article_id')
  1101. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1102. })
  1103. ->select(
  1104. 'article.id',
  1105. 'article.title',
  1106. 'article.imgurl',
  1107. 'article.author',
  1108. 'article.updated_at',
  1109. 'article.introduce',
  1110. 'article.islink',
  1111. 'article.linkurl',
  1112. 'article.copyfrom',
  1113. 'article.cat_arr_id',
  1114. 'article.catid'
  1115. );
  1116. $count = $query->count();
  1117. $rep = $query->orderBy("updated_at", "desc")
  1118. ->offset(($data['page'] - 1) * $data['pageSize'])
  1119. ->limit($data['pageSize'])
  1120. ->get()->all();
  1121. $categorys = $this->processArticlePro($website_id);
  1122. $cat_1st_arr = $categorys['cat_1st_arr'];
  1123. $catiall = $categorys['catiall'];
  1124. // $web['website_id'] = $data['website_id'];
  1125. foreach ($rep as $k => $v) {
  1126. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1127. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1128. }
  1129. // $rep = $this->processArticles($rep,$web);
  1130. $data = [
  1131. 'rows' => $rep,
  1132. 'count' => $count,
  1133. ];
  1134. if (empty($rep)) {
  1135. return Result::error("没有信息数据");
  1136. }
  1137. return Result::success($data);
  1138. }
  1139. /**
  1140. * 前端-获取新闻详情
  1141. * @param array $data
  1142. * @return array
  1143. */
  1144. public function selectWebsiteArticleInfo(array $data): array
  1145. {
  1146. $where = [
  1147. 'article.id' => $data['id'],
  1148. 'article.status' => 1,
  1149. ];
  1150. $result = Article::where($where)
  1151. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1152. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1153. ->where(function ($query) use ($data) {
  1154. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1155. ->orWhereNull("ignore_ids");
  1156. })
  1157. ->select(
  1158. 'article.*',
  1159. 'article_data.content',
  1160. 'article_data.article_id',
  1161. 'article_extend.website_url',
  1162. 'article_extend.email',
  1163. 'article_extend.contacts',
  1164. 'article_extend.contacts_mobile',
  1165. 'article_extend.contacts_address',
  1166. 'article_extend.zip_code',
  1167. 'article_extend.enterprise_name'
  1168. )
  1169. ->first();
  1170. if (empty($result)) {
  1171. return Result::error("暂无此新闻!", 0);
  1172. }
  1173. if (!empty($result['publiced_at'])) {
  1174. $result['updated_at'] = $result['publiced_at'];
  1175. }
  1176. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1177. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1178. ->where('website_category.website_id', $data['website_id'])
  1179. ->where(['website_category.category_id' => $result['catid']])
  1180. ->first();
  1181. if (empty($category)) {
  1182. return Result::error("查询失败", 0);
  1183. }
  1184. //手动推荐文章
  1185. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1186. if (empty($commend_ids)) {
  1187. $commendArticle = [];
  1188. } else {
  1189. //去除不存在的文章ID
  1190. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1191. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1192. ->where('article.status', 1)
  1193. ->where('website_category.website_id', $data['website_id'])
  1194. ->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')
  1195. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1196. // ->orderBy('article.updated_at', 'desc')
  1197. ->limit(5)
  1198. ->get();
  1199. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1200. foreach ($commendArticle as $k => $v) {
  1201. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1202. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1203. $cat_arr_id = array_unique($cat_arr_id);
  1204. // 从website_category取出alias_pinyin
  1205. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1206. ->whereIn('category_id', $cat_arr_id)
  1207. ->pluck('alias_pinyin', 'category_id')
  1208. ->toArray();
  1209. // 将cat_arr_id的json转成路径/隔开
  1210. $path_parts = [];
  1211. foreach ($cat_arr_id as $cat_id) {
  1212. if (isset($cat_arr[$cat_id])) {
  1213. $path_parts[] = $cat_arr[$cat_id];
  1214. }
  1215. }
  1216. $v->alias_pinyin = implode('/', $path_parts);
  1217. } else {
  1218. $v->alias_pinyin = '';
  1219. }
  1220. }
  1221. }
  1222. $result['category_id'] = $category['category_id'];
  1223. $result['cat_name'] = $category['alias'];
  1224. $result['website_name'] = $category['website_name'] ?? "";
  1225. $result['suffix'] = $category['suffix'] ?? "";
  1226. $result['commendArticle'] = $commendArticle;
  1227. $result['commend_ids'] = $commend_ids;
  1228. return Result::success($result);
  1229. }
  1230. /**
  1231. * 前端-获取网站调查问卷
  1232. * @param array $data
  1233. * @return array
  1234. */
  1235. public function getWebsiteSurvey(array $data): array
  1236. {
  1237. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1238. $website = Website::where('id', $data['website_id'])->first();
  1239. if (empty($website)) {
  1240. return Result::error("暂无此网站", 0);
  1241. }
  1242. }
  1243. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1244. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1245. if (empty($article)) {
  1246. return Result::error("暂无此文章", 0);
  1247. }
  1248. // return Result::error($data,0);
  1249. $where['art_id'] = $data['art_id'];
  1250. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1251. } else {
  1252. $survey = Article::where(function ($query) {
  1253. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1254. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1255. })
  1256. ->where('status', 1)
  1257. ->where('is_survey', 1)
  1258. ->select('survey_id')
  1259. ->orderBy('updated_at', 'desc')
  1260. ->first();
  1261. if (empty($survey)) {
  1262. return Result::error("暂无调查问卷", 0);
  1263. }
  1264. $where['sur_id'] = $survey['survey_id'];
  1265. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1266. }
  1267. // return Result::success($where);
  1268. $result = ArticleSurvey::where($where)
  1269. ->where(function ($query) {
  1270. $query->where('is_other', 0)
  1271. ->orWhere(function ($subQuery) {
  1272. $subQuery->where('is_other', 1)
  1273. ->where('other_id', 0);
  1274. });
  1275. })
  1276. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1277. ->select('article_survey.*', 'article.survey_type')
  1278. ->get()->all();
  1279. if (empty($result)) {
  1280. return Result::error("此文章暂无调查问卷", 0);
  1281. }
  1282. return Result::success($result);
  1283. }
  1284. /**
  1285. * 前端-添加网站调查问卷选项
  1286. * @param array $data
  1287. * @return array
  1288. */
  1289. public function addWebsiteSurveyOption(array $data): array
  1290. {
  1291. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1292. $website = Website::where('id', $data['website_id'])->first();
  1293. if (empty($website)) {
  1294. return Result::error("暂无此网站", 0);
  1295. }
  1296. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1297. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1298. if (empty($survey)) {
  1299. return Result::error("此调查问卷不可添加选项", 0);
  1300. }
  1301. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1302. $choice = [
  1303. 'art_id' => $survey['art_id'],
  1304. 'website_id' => $data['website_id'],
  1305. 'survey_name' => $survey['survey_name'],
  1306. 'choice_name' => $data['choice_name'],
  1307. 'sur_id' => $survey['sur_id'],
  1308. 'is_other' => 1,
  1309. 'other_id' => $survey['id'],
  1310. ];
  1311. $result = ArticleSurvey::insertGetId($choice);
  1312. if (empty($result)) {
  1313. return Result::error("添加失败", 0);
  1314. }
  1315. return Result::success($result);
  1316. }
  1317. }
  1318. return Result::error("添加失败", 0);
  1319. }
  1320. return Result::error("添加失败", 0);
  1321. }
  1322. /**
  1323. * 前端-调查问卷投票
  1324. * @param array $data
  1325. * @return array
  1326. */
  1327. public function addWebsiteSurveyVote(array $data): array
  1328. {
  1329. // return Result::success($data);
  1330. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1331. $website = Website::where('id', $data['website_id'])->first();
  1332. if (empty($website)) {
  1333. return Result::error("暂无此网站", 0);
  1334. }
  1335. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1336. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1337. // return Result::success($survey);
  1338. if (empty($is_survey)) {
  1339. return Result::error("此调查问卷不存在", 0);
  1340. }
  1341. // return Result::success($survey);
  1342. // 调查问卷类型
  1343. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1344. //多选 若是json型则转化成数组类型
  1345. if (strpos($data['choice_id'], '[') === 0) {
  1346. $data['choice_id'] = json_decode($data['choice_id'], true);
  1347. } else {
  1348. // 单选 也转换成数组
  1349. $data['choice_id'] = [$data['choice_id']];
  1350. }
  1351. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1352. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1353. // ->where('website_id',$data['website_id'])
  1354. ->where('is_other', 1)
  1355. ->where('other_id', 0)
  1356. ->first();
  1357. if (!empty($other)) {
  1358. return Result::error("请选择已有的选项!", 0);
  1359. }
  1360. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1361. // ->where('website_id',$data['website_id'])
  1362. ->where('is_other', 1)
  1363. ->where('other_id', '!=', 0)
  1364. ->first();
  1365. // return Result::success($choice['other']);
  1366. $choice_id = $data['choice_id'];
  1367. if (!empty($choice['other'])) {
  1368. // array_push($data['choice_id'],$choice['other']['other_id']);
  1369. if (!empty($choice_id)) {
  1370. $key = array_search($choice['other']['id'], $choice_id);
  1371. if ($key !== false) {
  1372. unset($choice_id[$key]);
  1373. $choice_id = array_values($choice_id);
  1374. }
  1375. array_push($choice_id, $choice['other']['other_id']);
  1376. } else {
  1377. $choice_id[0] = $choice['other']['other_id'];
  1378. }
  1379. array_push($data['choice_id'], $choice['other']['other_id']);
  1380. }
  1381. // return Result::success($data);
  1382. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1383. // ->where('website_id',$data['website_id'])
  1384. ->increment('results', 1);
  1385. if (empty($choice)) {
  1386. return Result::error("请选择已有的选项!", 0);
  1387. }
  1388. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1389. // ->where('website_id',$data['website_id'])
  1390. ->where('other_id', 0)
  1391. ->get();
  1392. $survey['choice'] = $choice_id;
  1393. return Result::success($survey);
  1394. }
  1395. return Result::error("参数必填!");
  1396. }
  1397. return Result::error("此调查问卷不存在", 0);
  1398. }
  1399. return Result::error("参数必填!");
  1400. }
  1401. /**
  1402. * 后端-获取网站调查问卷列表
  1403. * @param array $data
  1404. * @return array
  1405. */
  1406. public function getSurveyList(array $data): array
  1407. {
  1408. $where = [];
  1409. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1410. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1411. }
  1412. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1413. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1414. }
  1415. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1416. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1417. }
  1418. // return Result::success($where);
  1419. if (!empty($where)) {
  1420. $query = Article::where($where)->where(function ($q) {
  1421. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1422. });
  1423. } else {
  1424. $query = Article::where(function ($q) {
  1425. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1426. });
  1427. }
  1428. $count = $query->count();
  1429. $survey = $query->orderByDesc('id')
  1430. ->limit($data['pageSize'])
  1431. ->offset(($data['page'] - 1) * $data['pageSize'])
  1432. ->get();
  1433. if (empty($survey->toArray())) {
  1434. return Result::error("暂无调查问卷!", 0);
  1435. }
  1436. $result = [
  1437. 'rows' => $survey,
  1438. 'count' => $count,
  1439. ];
  1440. return Result::success($result);
  1441. }
  1442. /**
  1443. * 后端-获取网站调查问卷详情
  1444. * @param array $data
  1445. * @return array
  1446. */
  1447. public function getSurveyInfo(array $data): array
  1448. {
  1449. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1450. $where = ['sur_id' => $data['sur_id']];
  1451. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1452. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1453. ->select('article_survey.*', 'article.survey_type')
  1454. ->get()->all();
  1455. if (empty($choose)) {
  1456. return Result::error("此调查问卷不存在", 0);
  1457. }
  1458. $resultsArray = array_column($choose, 'results');
  1459. $total = array_sum($resultsArray);
  1460. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1461. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1462. // $total = 0;
  1463. if (!empty($other)) {
  1464. $total = $total + $other['results'];
  1465. $other['choice_name'] = '(其他)';
  1466. if (!empty($others)) {
  1467. $other['hasChildren'] = true;
  1468. // array_push($other,['hasChildren','=',true]);
  1469. $other['children'] = $others;
  1470. $other_choices = [$other->toArray()];
  1471. $mer_choice = array_merge($choose, $other_choices);
  1472. $value_choice = array_values($mer_choice);
  1473. } else {
  1474. // return Result::error('1111');
  1475. $other_choices = [$other->toArray()];
  1476. $other_choices = array_merge($choose, $other_choices);
  1477. $value_choice = array_values($other_choices);
  1478. // return Result::success($result);
  1479. }
  1480. } else {
  1481. $value_choice = $choose;
  1482. }
  1483. $result = [
  1484. 'choose' => $value_choice,
  1485. 'total' => $total,
  1486. ];
  1487. }
  1488. return Result::success($result);
  1489. }
  1490. /**
  1491. * 前端-搜索新闻列表
  1492. * @param array $data
  1493. * @return array
  1494. */
  1495. public function selectWebsiteArticle(array $data): array
  1496. {
  1497. $website = Website::where('id', $data['website_id'])->first();
  1498. if (empty($website)) {
  1499. return Result::error("网站不存在", 0);
  1500. }
  1501. // $website_column = $website['column'];
  1502. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1503. $website_column = json_decode($website['website_column_arr_id'], true);
  1504. }
  1505. $website_id = $data['website_id'];
  1506. $categorys = $this->processArticlePro($website_id);
  1507. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1508. // return Result::success($diff_pid_categoryIds);
  1509. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1510. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1511. }
  1512. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1513. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1514. $catiall = $categorys['catiall'];
  1515. $categoryIds = $categorys['categoryIds'];
  1516. // return Result::success($categoryIds);
  1517. $query = Article::where('status', 1)
  1518. ->whereIn('catid', $categoryIds)
  1519. ->leftJoinSub(function ($query) use ($website_id) {
  1520. $query->from('article_ignore')
  1521. ->where('website_id', $website_id);
  1522. }, 'article_ignore', function ($join) {
  1523. $join->on('article_ignore.article_id', '=', 'article.id');
  1524. })
  1525. ->where(function ($query) use ($website_id) {
  1526. $query->whereNull('article_ignore.article_id')
  1527. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1528. });
  1529. // ->get()->all();
  1530. // return Result::success($query);
  1531. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1532. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1533. }
  1534. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1535. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1536. }
  1537. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1538. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1539. }
  1540. // 计算总数
  1541. $count = $query->count();
  1542. // return Result::success($count);
  1543. // 分页查询
  1544. $articles = $query
  1545. ->select(
  1546. 'article.id',
  1547. 'article.title',
  1548. 'article.imgurl',
  1549. 'article.author',
  1550. 'article.updated_at',
  1551. 'article.introduce',
  1552. 'article.islink',
  1553. 'article.linkurl',
  1554. 'article.copyfrom',
  1555. 'article.cat_arr_id',
  1556. 'article.catid',
  1557. 'article.department_arr_id',
  1558. 'article.city_arr_id',
  1559. )
  1560. ->orderBy("updated_at", "desc")
  1561. ->offset(($data['page'] - 1) * $data['pageSize'])
  1562. ->limit($data['pageSize'])
  1563. ->get();
  1564. // return Result::success($articles);
  1565. foreach ($articles as $k => $v) {
  1566. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1567. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1568. }
  1569. if (empty($articles)) {
  1570. return Result::error("没有符合条件的资讯数据");
  1571. }
  1572. $result = [
  1573. 'rows' => $articles,
  1574. 'count' => $count,
  1575. ];
  1576. return Result::success($result);
  1577. }
  1578. /**
  1579. * 模块新闻加强版
  1580. * @param array $data
  1581. * @return array
  1582. */
  1583. public function getWebsiteCatidArticle(array $data): array
  1584. {
  1585. $where = [
  1586. 'website_category.category_id' => $data['catid'],
  1587. 'website_category.website_id' => $data['website_id'],
  1588. ];
  1589. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1590. $child_catnum = $data['child_catnum'] ?? 1;
  1591. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1592. $childCategoryIds = array_column($category['child'], 'category_id');
  1593. if (empty($childCategoryIds)) {
  1594. return Result::error("暂无子栏目", 0);
  1595. }
  1596. $imgArticles = [];
  1597. $textArticles = [];
  1598. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1599. // 初始化子分类图片新闻和文字新闻数组
  1600. // 查询所有子级栏目的图文新闻
  1601. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1602. ->where(function ($query) use ($data) {
  1603. $query->where(function ($subQuery) use ($data) {
  1604. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1605. })->orWhereNull("ignore_ids");
  1606. })
  1607. ->where('status', 1)
  1608. ->where('imgurl', '!=', '')
  1609. ->select('*')
  1610. ->orderBy('updated_at', 'desc')
  1611. ->limit($data['child_imgnum'])
  1612. ->get();
  1613. }
  1614. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1615. // 查询所有子级栏目的文字新闻
  1616. $textArticles = Article::where('catid', $childCategoryIds[0])
  1617. ->where('status', 1)
  1618. ->where(function ($query) use ($data) {
  1619. $query->where(function ($subQuery) use ($data) {
  1620. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1621. })->orWhereNull("ignore_ids");
  1622. })
  1623. ->select('*')
  1624. ->orderBy('updated_at', 'desc')
  1625. ->limit($data['child_textnum'])
  1626. ->get();
  1627. }
  1628. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1629. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1630. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1631. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1632. return $child;
  1633. }, $category['child']);
  1634. }
  1635. // }
  1636. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1637. $category['img'] = WebsiteCategory::where($where)
  1638. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1639. ->where('article.status', 1)
  1640. ->where('article.imgurl', '!=', '')
  1641. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1642. ->orderBy('article.updated_at', 'desc')
  1643. ->limit($data['img_num'])
  1644. ->get();
  1645. }
  1646. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1647. $category['text'] = WebsiteCategory::where($where)
  1648. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1649. ->where('article.status', 1)
  1650. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1651. ->orderBy('article.updated_at', 'desc')
  1652. ->limit($data['text_num'])
  1653. ->get();
  1654. }
  1655. // $category = $category->get();
  1656. if (empty($category)) {
  1657. return Result::error("查询失败", 0);
  1658. }
  1659. return Result::success($category);
  1660. }
  1661. /**
  1662. * 模块新闻加强plus版
  1663. * @param array $data
  1664. * @return array
  1665. */
  1666. public function getWebsiteAllArticle(array $data): array
  1667. {
  1668. // return Result::success($data);
  1669. $time1 = microtime(true);
  1670. $wetbsite_id = $data['website_id'] ?? 2;
  1671. $data = json_decode($data['id'], true);
  1672. $website = Website::where('id', $wetbsite_id)->first();
  1673. if (empty($website)) {
  1674. return Result::error("网站不存在", 0);
  1675. }
  1676. // return Result::success($website);
  1677. $website_column = $website['website_column_arr_id'] ?? '[]';
  1678. $website_column = json_decode($website_column, true);
  1679. $categorys = $this->processArticlePro($wetbsite_id);
  1680. $cat_1st_arr = $categorys['cat_1st_arr'];
  1681. $catiall = $categorys['catiall'];
  1682. // return Result::success($catiall);
  1683. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  1684. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1685. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1686. }
  1687. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  1688. // return Result::success($categorys);
  1689. $parent_category = array_column($data, 'parent');
  1690. $parent_cat = [];
  1691. $child_category = array_column($data, 'child');
  1692. if (!empty($parent_category)) {
  1693. foreach ($parent_category as $key => $value) {
  1694. $arr = array_map('intval', explode(',', $value));
  1695. $parent_cat[$key] = $arr[0] ?? 0;
  1696. $parent_category = $arr[0] ?? 0;
  1697. $article_imgnum = $arr[1] ?? 0;
  1698. $article_textnum = $arr[2] ?? 0;
  1699. if ($parent_category != 0) {
  1700. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1701. // return Result::success($category_arr);
  1702. if ($article_imgnum != 0) {
  1703. $img_article = Article::whereIn('catid', $category_arr)
  1704. ->where('status', 1)
  1705. ->where('imgurl', '!=', '')
  1706. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1707. $query->from('article_ignore')
  1708. ->where('website_id', $wetbsite_id);
  1709. }, 'article_ignore', function ($join) {
  1710. $join->on('article_ignore.article_id', '=', 'article.id');
  1711. })
  1712. ->where(function ($query) use ($wetbsite_id) {
  1713. $query->whereNull('article_ignore.article_id')
  1714. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1715. })
  1716. ->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')
  1717. ->orderBy('updated_at', 'desc')
  1718. ->limit($article_imgnum)
  1719. ->get()->all();
  1720. foreach ($img_article as $k => $v) {
  1721. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1722. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1723. }
  1724. } else {
  1725. $img_article = [];
  1726. }
  1727. if ($article_textnum != 0) {
  1728. $text_article = Article::whereIn('catid', $category_arr)
  1729. ->where('status', 1)
  1730. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1731. $query->from('article_ignore')
  1732. ->where('website_id', $wetbsite_id);
  1733. }, 'article_ignore', function ($join) {
  1734. $join->on('article_ignore.article_id', '=', 'article.id');
  1735. })
  1736. ->where(function ($query) use ($wetbsite_id) {
  1737. $query->whereNull('article_ignore.article_id')
  1738. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1739. })
  1740. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1741. ->orderBy('updated_at', 'desc')
  1742. ->limit($article_textnum)
  1743. ->get()->all();
  1744. foreach ($text_article as $k => $v) {
  1745. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1746. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1747. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1748. }
  1749. } else {
  1750. $text_article = [];
  1751. }
  1752. $catiall[$parent_category]['imgnum'] = $img_article;
  1753. $catiall[$parent_category]['textnum'] = $text_article;
  1754. $parent[$key] = $catiall[$parent_category];
  1755. } else {
  1756. $parent[$key] = '';
  1757. }
  1758. }
  1759. }
  1760. if (!empty($child_category)) {
  1761. foreach ($child_category as $key => $value) {
  1762. $arr = array_map('intval', explode(',', $value));
  1763. $parent_category = $parent_cat[$key];
  1764. $child_category = $arr[0] ?? 0;
  1765. $article_imgnum = $arr[1] ?? 0;
  1766. $article_textnum = $arr[2] ?? 0;
  1767. if ($child_category != 0) {
  1768. $all_childcat = $cat_1st_arr[$parent_category];
  1769. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  1770. // 从 $websiteInfoIndexed 中获取对应的数据
  1771. $info = $websiteInfoIndexed[$v];
  1772. // 返回一个包含所需信息的数组
  1773. return [
  1774. 'alias' => $info->alias,
  1775. 'category_id' => $info->category_id,
  1776. 'aLIas_pinyin' => $info->aLIas_pinyin,
  1777. 'pid' => $info->pid,
  1778. 'type' => $info->type,
  1779. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  1780. 'pinyin' => $info->pinyin,
  1781. ];
  1782. }, $all_childcat);
  1783. if ($article_imgnum != 0) {
  1784. $img_article = Article::where('catid', $child_category)
  1785. ->where('status', 1)
  1786. ->where('imgurl', '!=', '')
  1787. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1788. $query->from('article_ignore')
  1789. ->where('website_id', $wetbsite_id);
  1790. }, 'article_ignore', function ($join) {
  1791. $join->on('article_ignore.article_id', '=', 'article.id');
  1792. })
  1793. ->where(function ($query) use ($wetbsite_id) {
  1794. $query->whereNull('article_ignore.article_id')
  1795. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1796. })
  1797. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1798. ->orderBy('updated_at', 'desc')
  1799. ->limit($article_imgnum)
  1800. ->get()->all();
  1801. foreach ($img_article as $k => $v) {
  1802. // var_dump($v);
  1803. // var_dump($k);
  1804. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1805. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1806. }
  1807. } else {
  1808. $img_article = [];
  1809. }
  1810. if ($article_textnum != 0) {
  1811. $text_article = Article::where('catid', $child_category)
  1812. ->where('status', 1)
  1813. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1814. $query->from('article_ignore')
  1815. ->where('website_id', $wetbsite_id);
  1816. }, 'article_ignore', function ($join) {
  1817. $join->on('article_ignore.article_id', '=', 'article.id');
  1818. })
  1819. ->where(function ($query) use ($wetbsite_id) {
  1820. $query->whereNull('article_ignore.article_id')
  1821. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1822. })
  1823. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1824. ->orderBy('updated_at', 'desc')
  1825. ->limit($article_textnum)
  1826. ->get()->all();
  1827. foreach ($text_article as $k => $v) {
  1828. // var_dump($v);
  1829. // var_dump($k);
  1830. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1831. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1832. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1833. }
  1834. } else {
  1835. $text_article = [];
  1836. }
  1837. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  1838. $catiall[$child_category]['imgnum'] = $img_article;
  1839. $catiall[$child_category]['textnum'] = $text_article;
  1840. $child[$key] = $catiall[$child_category];
  1841. // var_dump($pids);
  1842. } else {
  1843. $child[$key] = '';
  1844. }
  1845. }
  1846. }
  1847. foreach ($parent as $key => $value) {
  1848. $result[$key] = $value;
  1849. if (!empty($child[$key])) {
  1850. // var_dump($child[$key]);
  1851. $result[$key]['child'] = $child[$key];
  1852. // $value[$key]['child'] = $child[$key];
  1853. } else {
  1854. $result[$key]['child'] = [
  1855. "alias" => null,
  1856. "category_id" => null,
  1857. "type" => null,
  1858. "pinyin" => null,
  1859. "all_childcat" => [],
  1860. "imgnum" => [],
  1861. "textnum" => []
  1862. ];
  1863. }
  1864. }
  1865. return Result::success($result);
  1866. }
  1867. /**
  1868. * 辅助方法:获取文章列表
  1869. */
  1870. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  1871. {
  1872. sleep(1);
  1873. $query = Article::where('article.status', 1)
  1874. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  1875. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  1876. ->where(function ($query) use ($website) {
  1877. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  1878. })
  1879. ->leftJoin('website_category', function ($join) use ($website) {
  1880. $join->on('article.catid', '=', 'website_category.category_id')
  1881. ->where('website_category.website_id', '=', $website['website_id']);
  1882. })
  1883. ->select(
  1884. 'article.id',
  1885. 'article.title',
  1886. 'article.imgurl',
  1887. 'article.author',
  1888. 'article.updated_at',
  1889. 'article.introduce',
  1890. 'article.islink',
  1891. 'article.linkurl',
  1892. 'article.copyfrom',
  1893. 'article.cat_arr_id',
  1894. 'article.catid',
  1895. 'website_category.alias as category_name'
  1896. )
  1897. ->orderBy('updated_at', 'desc')
  1898. ->limit($limit);
  1899. // 如果是图片文章,添加图片URL条件
  1900. if ($isImageArticle) {
  1901. $query->where('imgurl', '!=', '');
  1902. } else {
  1903. // 文字文章不需要imgurl字段
  1904. $query->addSelect('article.introduce');
  1905. }
  1906. $articles = $query->get();
  1907. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  1908. }
  1909. /**
  1910. * 乡村网-获取特殊新闻模块
  1911. * @param array $data
  1912. * @return array
  1913. */
  1914. public function getWebsiteArticles(array $data): array
  1915. {
  1916. $website_id = $data['website_id'];
  1917. $website = Website::where('id', $website_id)->first();
  1918. if (empty($website)) {
  1919. return Result::error("网站不存在", 0);
  1920. }
  1921. // return Result::success($website);
  1922. $website_column = $website['website_column_arr_id'] ?? '[]';
  1923. $website_column = json_decode($website_column, true);
  1924. $catids = json_decode($data['id'], true);
  1925. $parent_category = array_column($catids, 'parent');
  1926. if (!empty($parent_category) && is_array($parent_category)) {
  1927. $categorys = $this->processArticlePro($website_id);
  1928. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  1929. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1930. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1931. }
  1932. $catiall = $categorys['catiall'];
  1933. $cat_1st_arr = $categorys['cat_1st_arr'];
  1934. // return Result::success($categorys);
  1935. foreach ($parent_category as $key => $value) {
  1936. $arr = array_map('intval', explode(',', $value));
  1937. $parent_category = $arr[0] ?? 0;
  1938. $article_imgnum = $arr[1] ?? 0;
  1939. $article_textnum = $arr[2] ?? 0;
  1940. if ($parent_category != 0) {
  1941. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1942. // return Result::success($category_arr);
  1943. if ($article_imgnum != 0) {
  1944. $img_article = Article::whereIn('catid', $category_arr)
  1945. ->where('status', 1)
  1946. ->where('imgurl', '!=', '')
  1947. ->leftJoinSub(function ($query) use ($website_id) {
  1948. $query->from('article_ignore')
  1949. ->where('website_id', $website_id);
  1950. }, 'article_ignore', function ($join) {
  1951. $join->on('article_ignore.article_id', '=', 'article.id');
  1952. })
  1953. ->where(function ($query) use ($website_id) {
  1954. $query->whereNull('article_ignore.article_id')
  1955. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1956. })
  1957. ->select(
  1958. 'id',
  1959. 'title',
  1960. 'imgurl',
  1961. 'author',
  1962. 'updated_at',
  1963. 'introduce',
  1964. 'islink',
  1965. 'linkurl',
  1966. 'copyfrom',
  1967. 'cat_arr_id',
  1968. 'catid as category_id'
  1969. )
  1970. ->orderBy('updated_at', 'desc')
  1971. ->limit($article_imgnum)
  1972. ->get()->all();
  1973. foreach ($img_article as $k => $v) {
  1974. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  1975. // return Result::success($v);
  1976. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  1977. }
  1978. } else {
  1979. $img_article = [];
  1980. }
  1981. if ($article_textnum != 0) {
  1982. $text_article = Article::whereIn('catid', $category_arr)
  1983. ->where('status', 1)
  1984. ->leftJoinSub(function ($query) use ($website_id) {
  1985. $query->from('article_ignore')
  1986. ->where('website_id', $website_id);
  1987. }, 'article_ignore', function ($join) {
  1988. $join->on('article_ignore.article_id', '=', 'article.id');
  1989. })
  1990. ->where(function ($query) use ($website_id) {
  1991. $query->whereNull('article_ignore.article_id')
  1992. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1993. })
  1994. ->select(
  1995. 'id',
  1996. 'title',
  1997. 'author',
  1998. 'updated_at',
  1999. 'introduce',
  2000. 'islink',
  2001. 'linkurl',
  2002. 'copyfrom',
  2003. 'cat_arr_id',
  2004. 'catid as category_id'
  2005. )
  2006. ->orderBy('updated_at', 'desc')
  2007. ->limit($article_textnum)
  2008. ->get()->all();
  2009. foreach ($text_article as $k => $v) {
  2010. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2011. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2012. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2013. }
  2014. } else {
  2015. $text_article = [];
  2016. }
  2017. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2018. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2019. $parent[$key] = $catiall[$parent_category];
  2020. } else {
  2021. $parent[$key] = [];
  2022. }
  2023. }
  2024. }
  2025. return Result::success($parent);
  2026. }
  2027. // 封装处理商品的路由问题
  2028. function processGoods($goods, $data)
  2029. {
  2030. return $goods->map(function ($good) use ($data) {
  2031. $catid = $good->catid ?? 0;
  2032. // $pinyin = '';
  2033. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2034. if (!empty($category->pid) && $category->pid != 0) {
  2035. $level = json_decode($category->category_arr_id, true);
  2036. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2037. ->whereIn('category_id', $level)
  2038. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2039. ->get(['aLIas_pinyin'])
  2040. ->pluck('aLIas_pinyin')
  2041. ->implode('/');
  2042. } else {
  2043. $pinyin = $category->aLIas_pinyin ?? '';
  2044. }
  2045. if (isset($good->city_id) && !empty($good->city_id)) {
  2046. $city = District::where('id', $good->city_id)->first(['name']);
  2047. $good->city_name = $city->name ?? '';
  2048. }
  2049. // 解析imgurl JSON并取第一条数据
  2050. $imgUrls = json_decode($good->imgurl, true);
  2051. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2052. $good->pinyin = $pinyin;
  2053. return $good;
  2054. });
  2055. }
  2056. /**
  2057. * 获取商城首页-根据栏目id
  2058. * @param array $data
  2059. * @return array
  2060. * */
  2061. function getWebsiteCatidshop(array $data): array
  2062. {
  2063. $input['catid'] = $data['catid'];
  2064. $input['website_id'] = $data['website_id'];
  2065. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2066. $result = array_map(function ($item) use ($input) {
  2067. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2068. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2069. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2070. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2071. if (empty($category) || $category->type != 2) {
  2072. return Result::error("暂无此栏目", 0);
  2073. } else {
  2074. $website['website_id'] = $input['website_id'];
  2075. $goods = Good::where('good.status', 2)
  2076. ->where('good.website_id', $website['website_id'])
  2077. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2078. ->select(
  2079. 'good.id',
  2080. 'good.name',
  2081. 'good.imgurl',
  2082. 'good.description',
  2083. 'good.updated_at',
  2084. 'good.catid',
  2085. 'good.type_id',
  2086. 'good.price',
  2087. 'good.com',
  2088. 'good.level',
  2089. 'good.unit'
  2090. )
  2091. ->orderBy('updated_at', 'desc')
  2092. ->offset($goodStart)
  2093. ->limit($goodNum);
  2094. $all_goods = $goods->get();
  2095. $all_goods = $this->processGoods($all_goods, $website);
  2096. }
  2097. return $all_goods ?? [];
  2098. }
  2099. }, $data);
  2100. return Result::success($result);
  2101. }
  2102. /**
  2103. * 获取商品模块
  2104. * @param array $data
  2105. * @return array
  2106. * */
  2107. public function getWebsiteshop(array $data): array
  2108. {
  2109. $input['id'] = $data['id'];
  2110. $input['website_id'] = $data['website_id'];
  2111. $catid = $data['catid'];
  2112. $data = json_decode($input['id'] ?? '', true) ?? [];
  2113. $result['goods'] = array_map(function ($item) use ($input) {
  2114. // 检查parent元素是否存在且不是undefined
  2115. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2116. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2117. $website = $input['website_id'];
  2118. $query = Good::where('good.status', 2)
  2119. ->where('good.website_id', $website);
  2120. switch ($Levelid) {
  2121. case 1:
  2122. case 2:
  2123. case 3:
  2124. $goods = $query->where(function ($q) use ($Levelid) {
  2125. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2126. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2127. });
  2128. break;
  2129. case 4:
  2130. $goods = $query;
  2131. break;
  2132. case 5:
  2133. $goods = $query->where('type_id', 1);
  2134. break;
  2135. case 6:
  2136. $goods = $query->where('type_id', 2);
  2137. break;
  2138. default:
  2139. return [];
  2140. }
  2141. $all_goods = $goods
  2142. ->select(
  2143. 'good.id',
  2144. 'good.name',
  2145. 'good.imgurl',
  2146. 'good.description',
  2147. 'good.updated_at',
  2148. 'good.catid',
  2149. 'good.type_id',
  2150. 'good.price',
  2151. 'good.level',
  2152. 'good.website_id'
  2153. )
  2154. ->orderBy('updated_at', 'desc')
  2155. ->offset($goodStart)
  2156. ->limit($goodNum)
  2157. ->get();
  2158. $web['website_id'] = $website;
  2159. $all_goods = $this->processGoods($all_goods, $web);
  2160. }
  2161. return $all_goods;
  2162. }, $data);
  2163. $website = $input['website_id'];
  2164. $result['article'] = Article::where(function ($query) use ($website) {
  2165. $query->where(function ($subQuery) use ($website) {
  2166. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2167. })->orWhereNull("ignore_ids");
  2168. })
  2169. ->where('catid', $catid)
  2170. ->where('article.status', 1)
  2171. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2172. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2173. ->orderBy('article.updated_at', 'desc')
  2174. ->first();
  2175. return Result::success($result);
  2176. }
  2177. /**
  2178. * 获取商品分类
  2179. * @param array $data
  2180. * @return array
  2181. * */
  2182. public function getWebsiteshopCat(array $data): array
  2183. {
  2184. $website = $data['website_id'];
  2185. $category = WebsiteCategory::where('website_id', $website)
  2186. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2187. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2188. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2189. ->orderBy('sort')
  2190. ->get();
  2191. $cat = $category->map(function ($item) use ($website) {
  2192. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2193. $pid = $item->pid ?? 0;
  2194. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2195. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2196. ->where('website_id', $website)
  2197. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2198. ->get(['aLIas_pinyin'])
  2199. ->pluck('aLIas_pinyin')
  2200. ->implode('/');
  2201. } else {
  2202. $pinyin = $item->aLIas_pinyin ?? '';
  2203. }
  2204. $item->pinyin = $pinyin;
  2205. });
  2206. if (empty($category)) {
  2207. return Result::error("栏目查询失败", 0);
  2208. }
  2209. $cat_tree = Result::buildMenuTree($category);
  2210. $web['website_id'] = $website;
  2211. $goods = Good::where('website_id', $website)
  2212. ->where('status', 2)
  2213. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2214. ->latest('updated_at')
  2215. ->offset(($data['page'] - 1) * $data['pageSize'])
  2216. ->limit($data['pageSize'])
  2217. ->get();
  2218. if (!empty($goods)) {
  2219. if ($goods->count() > 1 && !empty($goods)) {
  2220. $goods = $this->processGoods($goods, $web);
  2221. }
  2222. } else {
  2223. $goods = [];
  2224. }
  2225. $result = [
  2226. 'category' => $cat_tree,
  2227. 'goods' => $goods,
  2228. ];
  2229. // $resul['goods'] = $goods;
  2230. if (empty($result)) {
  2231. return Result::error("查询失败", 0);
  2232. }
  2233. return Result::success($result);
  2234. }
  2235. /*
  2236. * 获取商品列表
  2237. * @param array $data
  2238. * @return array
  2239. * */
  2240. public function getWebsiteshopList(array $data): array
  2241. {
  2242. // return Result::success($data);
  2243. $where = [
  2244. 'status' => 2,
  2245. 'website_id' => $data['website_id'],
  2246. ];
  2247. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2248. // return Result::error("查询失败", 0);
  2249. // }
  2250. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2251. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2252. $data['catid'] = $category->category_id ?? 0;
  2253. }
  2254. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2255. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2256. }
  2257. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2258. array_push($where, ['type_id', $data['type_id']]);
  2259. }
  2260. $query = Good::where($where)
  2261. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2262. $query->where(function ($q) use ($data) {
  2263. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2264. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2265. });
  2266. })
  2267. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2268. $query->where(function ($q) use ($data) {
  2269. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2270. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2271. });
  2272. })
  2273. ->select(
  2274. 'good.id',
  2275. 'good.name',
  2276. 'good.imgurl',
  2277. 'good.description',
  2278. 'good.updated_at',
  2279. 'good.com',
  2280. 'good.catid',
  2281. 'good.type_id',
  2282. 'good.website_id',
  2283. 'good.cat_arr_id',
  2284. 'good.created_at',
  2285. 'good.city_id'
  2286. )
  2287. ->latest('updated_at');
  2288. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2289. $result['count'] = $query->clone()->count();
  2290. $result['goods'] = $this->processGoods(
  2291. $query->clone()
  2292. ->offset(($data['page'] - 1) * $data['pageSize'])
  2293. ->limit($data['pageSize'])
  2294. ->get(),
  2295. $data
  2296. );
  2297. } else {
  2298. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2299. // 获取 type_id 为 1 的数据
  2300. $result['type1'] = $this->processGoods(
  2301. $query->clone()
  2302. ->where('type_id', 1)
  2303. ->offset(($data['page'] - 1) * $data['pageSize'])
  2304. ->limit($data['pageSize'])
  2305. ->get(),
  2306. $data
  2307. );
  2308. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2309. // 获取 type_id 为 2 的数据
  2310. $result['type2'] = $this->processGoods(
  2311. $query->clone()
  2312. ->where('type_id', 2)
  2313. ->offset(($data['page'] - 1) * $data['pageSize'])
  2314. ->limit($data['pageSize'])
  2315. ->get(),
  2316. $data
  2317. );
  2318. }
  2319. if (empty($result)) {
  2320. return Result::error("查询失败", 0);
  2321. }
  2322. return Result::success($result);
  2323. }
  2324. /**
  2325. * 获取商品详情
  2326. * @param array $data
  2327. * @return array
  2328. * */
  2329. public function getWebsiteshopInfo(array $data): array
  2330. {
  2331. $where = [
  2332. 'good.status' => 2,
  2333. 'good.website_id' => $data['website_id'],
  2334. 'good.id' => $data['id'],
  2335. ];
  2336. $goods = Good::where($where)
  2337. ->where('good.id', $data['id'])
  2338. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2339. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2340. ->first();
  2341. if (empty($goods)) {
  2342. return Result::error("查询失败", 0);
  2343. }
  2344. $goods->imgurl = json_decode($goods->imgurl, true);
  2345. return Result::success($goods);
  2346. }
  2347. /**
  2348. * plus pro 处理文章路由问题
  2349. */
  2350. function processArticlePro($website_id)
  2351. {
  2352. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2353. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2354. // // 取出category_id 对应的aLIas_pinyin
  2355. // $categoryIds = array_column($categorys, 'category_id');
  2356. // $categoryPIds = array_column($categorys, 'pid');
  2357. // $aliasPinyins = array_column($categorys, 'path');
  2358. // $alias = array_column($categorys, 'alias');
  2359. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2360. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2361. // // return Result::success($cat_arr);
  2362. // // $catiall = [];
  2363. // //一级所有子级的记录
  2364. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2365. // return [
  2366. // 'cat_1st_arr' => $cat_alias_arr,
  2367. // 'catiall' => $cat_arr,
  2368. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2369. // 'categoryIds' => $categoryIds,
  2370. // ];
  2371. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2372. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2373. // 取出category_id 对应的aLIas_pinyin
  2374. $categoryIds = array_column($categorys, 'category_id');
  2375. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
  2376. return $pid != 0;
  2377. })));
  2378. $category_path = array_column($categorys, 'path');
  2379. $cat_arr = array_combine($categoryIds, $category_path);
  2380. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2381. $catiall = [];
  2382. //一级所有子级的记录
  2383. $cat_1st_arr = [];
  2384. foreach ($categorys as $key => $value) {
  2385. // $category_arr_id = json_decode($value->category_arr_id);
  2386. // $pinyin_str = '';
  2387. // // 算出一级 并且算出子级
  2388. if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
  2389. $cat_1st_arr[$value->pid][] = $value->category_id;
  2390. }
  2391. // foreach ($category_arr_id as $k => $v) {
  2392. // $pinyin_str .= $cat_arr[$v] . '/';
  2393. // }
  2394. // $pinyin_str = rtrim($pinyin_str, '/');
  2395. $catiall[$value->category_id]['alias'] = $value->alias;
  2396. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2397. $catiall[$value->category_id]['type'] = $value->type;
  2398. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2399. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2400. }
  2401. return [
  2402. 'cat_1st_arr' => $cat_1st_arr,
  2403. 'catiall' => $catiall,
  2404. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2405. 'categoryIds' => $categoryIds,
  2406. 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
  2407. 'categoryPIds' => $categoryPIds,
  2408. ];
  2409. }
  2410. /**
  2411. * 封装处理文章的路由问题
  2412. * */
  2413. function processArticles($articles, $data)
  2414. {
  2415. // 检查 $articles 是否为数组或可迭代对象
  2416. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2417. return $articles->map(function ($article) use ($data) {
  2418. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2419. $catid = $article->cat_arr_id ?? '';
  2420. }
  2421. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2422. $catid = $article->category_arr_id ?? '';
  2423. }
  2424. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2425. $level = json_decode($catid, true);
  2426. if (!is_array($level)) {
  2427. return $article;
  2428. } else {
  2429. $level = array_map('intval', $level);
  2430. }
  2431. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2432. ->where($data)
  2433. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2434. ->pluck('aLIas_pinyin')
  2435. ->implode('/');
  2436. $article->pinyin = $pinyin ?? '';
  2437. return $article;
  2438. });
  2439. } else {
  2440. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2441. $catid = $articles->cat_arr_id ?? '';
  2442. $level = json_decode($catid, true);
  2443. if (!is_array($level)) {
  2444. return $articles;
  2445. } else {
  2446. $level = array_map('intval', $level);
  2447. }
  2448. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2449. ->where($data)
  2450. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2451. ->pluck('aLIas_pinyin')
  2452. ->implode('/');
  2453. $articles->pinyin = $pinyin ?? '';
  2454. return $articles;
  2455. }
  2456. }
  2457. // 封装处理由问题
  2458. function processJob($job, $data)
  2459. {
  2460. return $job->map(function ($job) use ($data) {
  2461. $category = $job->cat_arr_id ?? '';
  2462. $cityid = $job->city_arr_id ?? '';
  2463. $city = json_decode($cityid, true);
  2464. $pinyin = '';
  2465. $level = json_decode($category, true);
  2466. // 路由
  2467. if (!empty($level) && is_array($level)) {
  2468. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2469. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2470. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2471. ->get(['aLIas_pinyin'])
  2472. ->pluck('aLIas_pinyin')
  2473. ->implode('/');
  2474. if (empty($pinyin)) {
  2475. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2476. }
  2477. $job->pinyin = $pinyin;
  2478. }
  2479. // 取职位-城市 市??省
  2480. if (!empty($city) && is_array($city)) {
  2481. if (isset($city[1]) && !empty($city[1])) {
  2482. $city = District::where('id', $city[1])->first(['name']);
  2483. $job->city_name = $city->name ?? '';
  2484. } else if (isset($city[0]) && !empty($city[0])) {
  2485. $city = District::where('id', $city[0])->first(['name']);
  2486. $job->city_name = $city->name ?? '';
  2487. } else {
  2488. $job->city_name = '全国';
  2489. }
  2490. }
  2491. // 获取简历最后一级地区
  2492. if (isset($job->city_id) && !empty($job->city_id)) {
  2493. $city = District::where('id', $job->city_id)->first(['name']);
  2494. $job->hunt_cityname = $city->name ?? '';
  2495. }
  2496. // 组合详细地址
  2497. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2498. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2499. if (is_array($address_id) && !empty($address_id)) {
  2500. $address = District::whereIn('id', $address_id)
  2501. ->orderBy('level', 'asc')
  2502. ->get(['name'])
  2503. ->pluck('name')
  2504. ->implode('');
  2505. // $job->address_name = $address ?? '';
  2506. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2507. }
  2508. }
  2509. // 取行业
  2510. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2511. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2512. if (!empty($job->industry)) {
  2513. $query->where('hyid', $job->industry);
  2514. } else if (!empty($job->hy_id)) {
  2515. $query->where('hyid', $job->hy_id);
  2516. } else if (!empty($job->company_hy_id)) {
  2517. $query->where('hyid', $job->company_hy_id);
  2518. } else {
  2519. $query->where('hyid', $job->job_industry);
  2520. }
  2521. })->first(['hyname']);
  2522. $job->hy_name = $hy_name->hyname ?? '';
  2523. }
  2524. // 取职位类别
  2525. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2526. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2527. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2528. $job->zw_name = $zw_name->zwname ?? '';
  2529. }
  2530. // 取具体职位
  2531. 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))) {
  2532. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2533. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2534. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2535. }
  2536. // 取工作经验
  2537. if (isset($job->experience) && !empty($job->experience)) {
  2538. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2539. $job->experience_name = $experience->ename ?? '';
  2540. }
  2541. // 取学历
  2542. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2543. $education = $job->educational ?? $job->school_education;
  2544. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2545. $job->education_name = $education->ename ?? '';
  2546. }
  2547. // 语言
  2548. if (isset($job->language) && !empty($job->language)) {
  2549. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2550. $job->language_name = $language->ename ?? '';
  2551. }
  2552. // 薪资
  2553. if (isset($job->salary) && !empty($job->salary)) {
  2554. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2555. $job->salary_name = $salary->ename ?? '';
  2556. }
  2557. // 职位性质
  2558. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2559. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2560. $job->job_nature_name = $job_nature->ename ?? '';
  2561. }
  2562. // 公司规模
  2563. if (isset($job->company_size) && !empty($job->company_size)) {
  2564. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2565. $job->company_size_name = $company_size->ename ?? '';
  2566. }
  2567. // 公司性质
  2568. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2569. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2570. $job->company_nature_name = $company_nature->nature_name ?? '';
  2571. }
  2572. // $job->pinyin = $pinyin;
  2573. return $job;
  2574. });
  2575. }
  2576. /**
  2577. * 获取书籍模块
  2578. * @param array $data
  2579. * @return array
  2580. * */
  2581. public function getWebsiteBook(array $data): array
  2582. {
  2583. $input['id'] = $data['id'];
  2584. $input['website_id'] = $data['website_id'];
  2585. // 将 JSON 字符串转换为 PHP 数组
  2586. $data = json_decode($input['id'], true);
  2587. // 使用 array_map 处理每个元素
  2588. $result = array_map(function ($item) use ($input) {
  2589. // 检查parent元素是否存在且不是undefined
  2590. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2591. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2592. $website = [
  2593. 'website_id' => $input['website_id'],
  2594. ];
  2595. // 查询栏目名称
  2596. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2597. if (empty($category)) {
  2598. $parent_alias = '';
  2599. $parent_pinyin = null;
  2600. $imgBooks = [];
  2601. $textBooks = [];
  2602. } else {
  2603. $parent_alias = $category->alias ?? '';
  2604. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2605. // 查找子分类ID数组
  2606. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2607. array_push($childCategoryIds, $parentCatId);
  2608. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2609. if ($parentImgNum != 0) {
  2610. // 查询图片新闻
  2611. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2612. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2613. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2614. })
  2615. ->where('book.status', 2)
  2616. ->where('book.img_url', '!=', '')
  2617. ->where('book.website_id', $website['website_id'])
  2618. ->leftJoin('website_category', function ($join) use ($website) {
  2619. $join->on('book.cat_id', '=', 'website_category.category_id')
  2620. ->where('website_category.website_id', '=', $website['website_id']);
  2621. })
  2622. ->select(
  2623. 'book.id',
  2624. 'book.title',
  2625. 'book.img_url',
  2626. 'book.price',
  2627. 'book.market_price',
  2628. 'book.description',
  2629. 'book.cat_id',
  2630. 'book.description',
  2631. 'book.updated_at',
  2632. 'website_category.alias as category_name',
  2633. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2634. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2635. )
  2636. ->orderBy('updated_at', 'desc')
  2637. ->limit($parentImgNum)
  2638. ->get()->all();
  2639. // 查询文字新闻
  2640. }
  2641. if ($parentTextNum != 0) {
  2642. $textBooks = [];
  2643. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2644. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2645. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2646. })
  2647. ->where('book.status', 2)
  2648. ->where('book.website_id', $website['website_id'])
  2649. ->leftJoin('website_category', function ($join) use ($website) {
  2650. $join->on('book.cat_id', '=', 'website_category.category_id')
  2651. ->where('website_category.website_id', '=', $website['website_id']);
  2652. })
  2653. ->select(
  2654. 'book.id',
  2655. 'book.title',
  2656. 'book.img_url',
  2657. 'book.price',
  2658. 'book.market_price',
  2659. 'book.description',
  2660. 'book.cat_id',
  2661. 'book.description',
  2662. 'book.updated_at',
  2663. 'website_category.alias as category_name',
  2664. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2665. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2666. )
  2667. ->orderBy('updated_at', 'desc')
  2668. ->limit($parentTextNum)
  2669. ->get()->all();
  2670. }
  2671. }
  2672. }
  2673. $resultItem = [
  2674. 'alias' => $parent_alias ?? '',
  2675. 'category_id' => $parentCatId ?? 0,
  2676. 'pinyin' => $parent_pinyin ?? null,
  2677. 'imgnum' => $imgBooks ?? [],
  2678. 'textnum' => $textBooks ?? [],
  2679. ];
  2680. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  2681. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  2682. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  2683. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2684. ->get()->all();
  2685. if (!empty($childCategory)) {
  2686. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  2687. // 查询子栏目名称
  2688. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  2689. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2690. ->first();
  2691. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  2692. $childImgArticles = [];
  2693. $childTextArticles = [];
  2694. $resultItem['child'] = [];
  2695. } else {
  2696. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  2697. // 查询子栏目图片新闻
  2698. $childImgArticles = Book::where('cat_id', $childCatId)
  2699. ->where('status', 2)
  2700. ->where('img_url', '!=', '')
  2701. ->leftJoin('website_category', function ($join) use ($website) {
  2702. $join->on('book.cat_id', '=', 'website_category.category_id')
  2703. ->where('website_category.website_id', '=', $website['website_id']);
  2704. })
  2705. ->select(
  2706. 'book.id',
  2707. 'book.title',
  2708. 'book.img_url',
  2709. 'book.price',
  2710. 'book.market_price',
  2711. 'book.description',
  2712. 'book.cat_id',
  2713. 'book.description',
  2714. 'book.updated_at',
  2715. DB::raw("'$child_pinyin' as pinyin")
  2716. )
  2717. ->orderBy('updated_at', 'desc')
  2718. ->limit($childImgNum)
  2719. ->get()->all();
  2720. // 查询子栏目文字新闻
  2721. $childTextArticles = Book::where('cat_id', $childCatId)
  2722. ->where('status', 2)
  2723. ->leftJoin('website_category', function ($join) use ($website) {
  2724. $join->on('book.cat_id', '=', 'website_category.category_id')
  2725. ->where('website_category.website_id', '=', $website['website_id']);
  2726. })
  2727. ->select(
  2728. 'book.id',
  2729. 'book.title',
  2730. 'book.img_url',
  2731. 'book.price',
  2732. 'book.market_price',
  2733. 'book.description',
  2734. 'book.cat_id',
  2735. 'book.description',
  2736. 'book.updated_at',
  2737. DB::raw("'$child_pinyin' as pinyin")
  2738. )
  2739. ->orderBy('updated_at', 'desc')
  2740. ->limit($childTextNum)
  2741. ->get()->all();
  2742. $resultItem['child'] = [
  2743. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  2744. 'category_id' => $childCatId,
  2745. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  2746. 'all_childcat' => $childCategory,
  2747. 'imgnum' => $childImgArticles,
  2748. 'textnum' => $childTextArticles,
  2749. ];
  2750. }
  2751. }
  2752. } else {
  2753. $resultItem['child'] = [];
  2754. }
  2755. return $resultItem;
  2756. }, $data);
  2757. return Result::success($result);
  2758. }
  2759. /**
  2760. * 获取书刊列表
  2761. * @param array $data
  2762. * @return array
  2763. * */
  2764. public function getWebsiteBookList(array $data): array
  2765. {
  2766. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2767. if (empty($web)) {
  2768. return Result::error("查询失败", 0);
  2769. }
  2770. $catid = $data['id'];
  2771. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  2772. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  2773. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  2774. $category_pinyin = $category ? $category->aLias_pinyin : '';
  2775. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  2776. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  2777. ->where('pid', $category['pid'])
  2778. ->select(
  2779. 'category_id',
  2780. 'alias',
  2781. 'aLIas_pinyin',
  2782. 'pid',
  2783. 'sort',
  2784. 'is_url',
  2785. 'web_url',
  2786. 'seo_title',
  2787. 'seo_keywords',
  2788. 'seo_description',
  2789. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  2790. )
  2791. ->orderBy('sort')
  2792. ->get()->all();
  2793. if (empty($category)) {
  2794. return Result::error("查询失败", 0);
  2795. }
  2796. $query = Book::where('book.status', 2)
  2797. ->where('book.website_id', $data['website_id'])
  2798. ->where('book.cat_id', $catid)
  2799. ->select(
  2800. 'book.id',
  2801. 'book.title',
  2802. 'book.img_url',
  2803. 'book.description',
  2804. 'book.updated_at',
  2805. 'book.cat_id',
  2806. DB::raw("'$pinyin' as pinyin")
  2807. )
  2808. ->orderBy('book.updated_at', 'desc');
  2809. $count = $query->count();
  2810. $query = clone $query;
  2811. $Book = $query
  2812. ->limit($data['pageSize'])
  2813. ->offset(($data['page'] - 1) * $data['pageSize'])
  2814. ->get()->all();
  2815. $result = [
  2816. 'category' => $categorys,
  2817. 'books' => $Book,
  2818. 'count' => $count,
  2819. ];
  2820. // if(empty($result)){
  2821. // return Result::error("查询失败", 0);
  2822. // }
  2823. return Result::success($result);
  2824. }
  2825. /**
  2826. * 获取书刊详情
  2827. * @param array $data
  2828. * @return array
  2829. * */
  2830. public function getWebsiteBookInfo(array $data): array
  2831. {
  2832. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2833. if (empty($web)) {
  2834. return Result::error("查询失败", 0);
  2835. }
  2836. $book = Book::where('status', 2)
  2837. ->where('website_id', $data['website_id'])
  2838. ->where('id', $data['id'])
  2839. ->select(
  2840. 'book.*',
  2841. )
  2842. ->orderBy('updated_at', 'desc')
  2843. ->first();
  2844. if (empty($book)) {
  2845. return Result::error("查询失败", 0);
  2846. }
  2847. // 先查询当前分类的 pid
  2848. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  2849. ->where('category_id', $book['cat_id'])
  2850. ->first(['pid', 'category_id']);
  2851. $query = WebsiteCategory::where('website_id', $data['website_id']);
  2852. if (!empty($carpid)) {
  2853. if ($carpid->pid != 0) {
  2854. $pid = $carpid['pid'];
  2855. // $parent_pinyin = '';
  2856. } else {
  2857. $pid = $carpid['category_id'];
  2858. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  2859. }
  2860. }
  2861. $categorys = $query->where('pid', $pid)
  2862. ->select(
  2863. 'category_id',
  2864. 'alias',
  2865. 'aLIas_pinyin',
  2866. 'pid',
  2867. 'sort',
  2868. 'is_url',
  2869. 'web_url',
  2870. 'category_arr_id as cat_arr_id',
  2871. )
  2872. ->orderBy('sort')
  2873. ->get();
  2874. $category = $this->processArticle($categorys, $data);
  2875. $result = [
  2876. 'category' => $category,
  2877. 'books' => $book,
  2878. ];
  2879. return Result::success($result);
  2880. }
  2881. /**
  2882. * 尝试
  2883. * @param array $data
  2884. * @return array
  2885. * */
  2886. public function test(array $data): array
  2887. {
  2888. $input['id'] = $data['id'];
  2889. $input['website_id'] = $data['website_id'];
  2890. // 将 JSON 字符串转换为 PHP 数组
  2891. $data = json_decode($input['id'], true);
  2892. $result = [];
  2893. $article = $data;
  2894. $result = array_map(function ($item) use ($input) {
  2895. $website = [
  2896. 'website_id' => $input['website_id'],
  2897. ];
  2898. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2899. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2900. $parent = [
  2901. 0 => $category['category_id'] ?? [],
  2902. 1 => $parentImgNum ?? [],
  2903. 2 => $parentTextNum ?? [],
  2904. ];
  2905. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  2906. $child = [];
  2907. $resultItem = [
  2908. // 'alias' => $parent_alias ?? '',
  2909. 'category_id' => $parentCatId ?? 0,
  2910. 'pinyin' => $parentImgNum ?? null,
  2911. 'imgnum' => $parentTextNum ?? [],
  2912. // 'textnum' => $textArticles ?? [],
  2913. ];
  2914. return $parent;
  2915. }, $data);
  2916. return Result::success($result);
  2917. // });
  2918. }
  2919. /**
  2920. * 封装处理文章的路由问题
  2921. * */
  2922. function processArticle($article, $data)
  2923. {
  2924. return $article->map(function ($article) use ($data) {
  2925. $catid = $article->cat_arr_id ?? '';
  2926. $level = json_decode($catid, true);
  2927. $pinyin = '';
  2928. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2929. if (!empty($level) && is_array($level)) {
  2930. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2931. ->where('website_id', $data['website_id'])
  2932. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2933. ->get(['aLIas_pinyin'])
  2934. ->pluck('aLIas_pinyin')
  2935. ->implode('/');
  2936. } else {
  2937. $pinyin = '';
  2938. }
  2939. $article->pinyin = $pinyin;
  2940. return $article;
  2941. });
  2942. }
  2943. /**
  2944. * c端-获取招工招聘下拉选框
  2945. * @param array $data
  2946. * @return array
  2947. * */
  2948. public function getWebsiteJobSelect(array $data): array
  2949. {
  2950. $web = Website::where('id', $data['website_id'])->first();
  2951. if (empty($web)) {
  2952. return Result::error("该网站不存在", 0);
  2953. }
  2954. $hy = JobIndustry::get()->all();
  2955. $zw = JobPosition::where('zwpid', 0)->get()->all();
  2956. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  2957. $result = [
  2958. 'hy' => $hy,
  2959. 'zw' => $zw,
  2960. 'jtzw' => $jtzw,
  2961. ];
  2962. if (empty($result)) {
  2963. return Result::error("查询失败", 0);
  2964. }
  2965. return Result::success($result);
  2966. }
  2967. /**
  2968. * c端-获取招工招聘
  2969. * @param array $data
  2970. * @return array
  2971. * */
  2972. public function getWebsiteJob(array $data): array
  2973. {
  2974. $web = Website::where('id', $data['website_id'])->first();
  2975. if (empty($web)) {
  2976. return Result::error("该网站不存在", 0);
  2977. }
  2978. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2979. ->where('job_hunting.website_id', $data['website_id'])
  2980. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2981. $query->where(function ($q) use ($data) {
  2982. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2983. });
  2984. })
  2985. ->select(
  2986. 'job_hunting.id',
  2987. 'job_hunting.catid',
  2988. 'job_hunting.cat_arr_id',
  2989. 'job_hunting.job_name_get',
  2990. 'job_hunting.industry',
  2991. 'job_hunting.name',
  2992. 'job_hunting.sexy',
  2993. 'job_hunting.origin',
  2994. 'job_hunting.city_arr_id',
  2995. 'job_hunting.experience',
  2996. 'job_hunting.updated_at',
  2997. 'job_hunting.salary',
  2998. 'job_hunting.skillList',
  2999. 'job_hunting.slelf_evaluation',
  3000. )
  3001. ->orderBy('updated_at', 'desc')
  3002. ->limit($data['job1_num'])
  3003. ->get();
  3004. $web['website_id'] = $data['website_id'];
  3005. if (empty($job_hunting)) {
  3006. $job_huntings = "未查询到相关简历信息";
  3007. } else {
  3008. $job_huntings = $this->processJob($job_hunting, $web);
  3009. }
  3010. // 0:待审核 1:已通过 2:已拒绝
  3011. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3012. ->where('job_recruiting.website_id', $data['website_id'])
  3013. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3014. $query->where(function ($q) use ($data) {
  3015. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3016. });
  3017. })
  3018. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3019. ->select(
  3020. 'job_recruiting.id',
  3021. 'job_recruiting.catid',
  3022. 'job_recruiting.cat_arr_id',
  3023. 'job_recruiting.title',
  3024. 'job_recruiting.jtzw_id',
  3025. 'job_recruiting.hy_id',
  3026. 'job_recruiting.city_arr_id',
  3027. 'job_recruiting.due_data',
  3028. 'job_recruiting.updated_at',
  3029. 'job_recruiting.experience',
  3030. 'job_recruiting.educational',
  3031. 'job_recruiting.salary',
  3032. 'job_recruiting.zw_id',
  3033. 'job_company.business_name',
  3034. 'job_recruiting.keyword',
  3035. 'job_recruiting.description',
  3036. )
  3037. ->orderBy('updated_at', 'desc')
  3038. ->limit($data['job2_num'])
  3039. ->get();
  3040. if (empty($job_recruiting->toArray())) {
  3041. $job_recruitings = "未查询到相关职位信息";
  3042. } else {
  3043. $job_recruitings = $this->processJob($job_recruiting, $web);
  3044. }
  3045. $result = [
  3046. 'job_hunting' => $job_huntings,
  3047. 'job_recuiting' => $job_recruitings,
  3048. ];
  3049. return Result::success($result);
  3050. }
  3051. /**
  3052. * c端-获取招工招聘列表
  3053. * @param array $data
  3054. * @return array
  3055. * */
  3056. public function getWebsiteJobList(array $data): array
  3057. {
  3058. $recruit_where = [];
  3059. $hunt_where = [];
  3060. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3061. if (empty($web)) {
  3062. return Result::error("此网站不存在", 0);
  3063. }
  3064. $website_id['website_id'] = $data['website_id'];
  3065. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3066. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3067. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3068. }
  3069. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3070. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3071. }
  3072. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3073. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3074. }
  3075. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3076. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3077. }
  3078. $query = JobRecruiting::where('job_recruiting.status', 1)
  3079. ->where('job_recruiting.website_id', $data['website_id'])
  3080. ->where($recruit_where)
  3081. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3082. $query->where(function ($q) use ($data) {
  3083. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3084. });
  3085. })
  3086. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3087. $query->where(function ($q) use ($data) {
  3088. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3089. });
  3090. })
  3091. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3092. ->select(
  3093. 'job_recruiting.id',
  3094. 'job_recruiting.catid',
  3095. 'job_recruiting.hy_id',
  3096. 'job_recruiting.title',
  3097. 'job_recruiting.zw_id',
  3098. 'job_recruiting.educational',
  3099. 'job_recruiting.jtzw_id',
  3100. 'job_recruiting.city_arr_id',
  3101. 'job_recruiting.due_data',
  3102. 'job_recruiting.experience',
  3103. 'job_recruiting.cat_arr_id',
  3104. 'job_recruiting.updated_at',
  3105. 'job_company.business_name',
  3106. 'job_recruiting.keyword',
  3107. 'job_recruiting.description',
  3108. )
  3109. ->orderBy('job_recruiting.updated_at', 'desc');
  3110. $recruit_count = $query->count();
  3111. $query = clone $query;
  3112. $JobRecruiting = $query
  3113. ->offset(($data['page'] - 1) * $data['pageSize'])
  3114. ->limit($data['pageSize'])
  3115. ->get();
  3116. if (empty($JobRecruiting)) {
  3117. $JobRecruiting = "暂无相关职位信息";
  3118. } else {
  3119. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3120. }
  3121. }
  3122. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3123. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3124. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3125. }
  3126. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3127. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3128. }
  3129. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3130. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3131. }
  3132. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3133. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3134. }
  3135. $query = JobHunting::where('job_hunting.status', 2)
  3136. ->where('job_hunting.website_id', $data['website_id'])
  3137. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3138. ->where($hunt_where)
  3139. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3140. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3141. // })
  3142. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3143. $query->where(function ($q) use ($data) {
  3144. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3145. });
  3146. })
  3147. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3148. $query->where(function ($q) use ($data) {
  3149. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3150. });
  3151. })
  3152. ->select(
  3153. 'job_hunting.id',
  3154. 'job_hunting.catid',
  3155. 'job_hunting.sexy',
  3156. 'job_hunting.experience',
  3157. 'job_hunting.origin',
  3158. 'job_hunting.industry',
  3159. 'job_hunting.name',
  3160. 'job_hunting.job',
  3161. 'job_hunting.job_name_get',
  3162. 'job_hunting.city_arr_id',
  3163. 'job_hunting.cat_arr_id',
  3164. 'job_hunting.created_at',
  3165. 'job_hunting.updated_at',
  3166. 'job_position.zwname as job_name',
  3167. 'job_hunting.skillList',
  3168. 'job_hunting.slelf_evaluation',
  3169. )
  3170. ->orderBy('job_hunting.updated_at', 'desc');
  3171. $hunt_count = $query->count();
  3172. $query = clone $query;
  3173. $JobHunting = $query
  3174. ->offset(($data['page'] - 1) * $data['pageSize'])
  3175. ->limit($data['pageSize'])
  3176. ->get();
  3177. if (empty($JobHunting)) {
  3178. $JobRecruiting = "暂无相关简历信息";
  3179. } else {
  3180. $JobHunting = $this->processJob($JobHunting, $website_id);
  3181. }
  3182. }
  3183. $result = [
  3184. 'JobRecruiting' => $JobRecruiting ?? [],
  3185. 'recruit_count' => $recruit_count ?? 0,
  3186. 'JobHunting' => $JobHunting ?? [],
  3187. 'hunt_count' => $hunt_count ?? 0,
  3188. ];
  3189. return Result::success($result);
  3190. }
  3191. /**
  3192. * c端-获取招工招聘详情
  3193. * @param array $data
  3194. * @return array
  3195. * */
  3196. public function getWebsiteJobInfo(array $data): array
  3197. {
  3198. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3199. if (empty($web)) {
  3200. return Result::error("该网站不存在", 0);
  3201. }
  3202. $webid = [
  3203. 'website_id' => $data['website_id'],
  3204. ];
  3205. // 职位相关信息
  3206. if ($data['type'] == 1) {
  3207. $query = JobRecruiting::where('status', 1)
  3208. ->where('website_id', $data['website_id'])
  3209. ->select('*');
  3210. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3211. $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();
  3212. if (!empty($company)) {
  3213. $result['company'] = $this->processJob($company, $webid);
  3214. }
  3215. $other_job = JobRecruiting::where('status', 1)
  3216. ->where('website_id', $data['website_id'])
  3217. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3218. ->where('id', '!=', $data['id'])
  3219. ->where('user_id', '=', $job[0]['user_id'])
  3220. ->limit($data['pageSize'])
  3221. ->get();
  3222. if (!empty($other_job)) {
  3223. $result['other_job'] = $this->processJob($other_job, $webid);
  3224. }
  3225. } else {
  3226. // 简历相关信息
  3227. $job = JobHunting::where('job_hunting.status', 2)
  3228. ->where('job_hunting.website_id', $data['website_id'])
  3229. ->where('job_hunting.id', $data['id'])
  3230. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3231. ->select('job_hunting.*', 'user_name')
  3232. ->get();
  3233. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3234. if (!empty($resume->toArray())) {
  3235. $result['resume'] = 1;
  3236. } else {
  3237. $result['resume'] = 0;
  3238. }
  3239. }
  3240. if (empty($job->toArray())) {
  3241. return Result::error("id参数错误", 0);
  3242. }
  3243. if (!empty($job[0]['job_experience'])) {
  3244. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3245. if (!empty($job_experience)) {
  3246. // $hy = [];
  3247. foreach ($job_experience as $key => $value) {
  3248. // $id = $value['id'];
  3249. $hy[$key] = $value['job_industry'];
  3250. $zw_id[$key] = $value['job_typename'];
  3251. $jtzw_id[$key] = $value['job_name'];
  3252. }
  3253. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3254. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3255. // 先将关联表转换为索引数组,提高查找效率
  3256. $hyLookup = [];
  3257. foreach ($hy_table as $item) {
  3258. $hyLookup[$item['hyid']] = $item['hyname'];
  3259. }
  3260. $zwLookup = [];
  3261. foreach ($zw_table as $item) {
  3262. $zwLookup[$item['zwid']] = $item['zwname'];
  3263. }
  3264. foreach ($job_experience as $key => &$value) {
  3265. // 处理行业名称
  3266. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3267. $value['hy_name'] = $hyLookup[$hy[$key]];
  3268. }
  3269. // 处理职位名称
  3270. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3271. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3272. }
  3273. // 处理具体职位名称
  3274. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3275. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3276. }
  3277. }
  3278. // 释放引用,防止意外修改后续代码
  3279. unset($value);
  3280. }
  3281. $result['job_experience'] = $job_experience ?? [];
  3282. }
  3283. if (!empty($job[0]['education_experience'])) {
  3284. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3285. if (!empty($education_experience)) {
  3286. foreach ($education_experience as $key => $value) {
  3287. // $id = $value['id'];
  3288. $education[$key] = $value['school_education'];
  3289. }
  3290. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3291. // // 先将关联表转换为索引数组,提高查找效率
  3292. $educationLookup = [];
  3293. foreach ($education_table as $item) {
  3294. $educationLookup[$item['evalue']] = $item['ename'];
  3295. }
  3296. foreach ($education_experience as $key => &$value) {
  3297. // 处理学历名称
  3298. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3299. $value['education_name'] = $educationLookup[$education[$key]];
  3300. }
  3301. }
  3302. }
  3303. $result['education_experience'] = $job_experience ?? [];
  3304. }
  3305. $result['job'] = $this->processJob($job, $webid);
  3306. // // 返现对应的栏目
  3307. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3308. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3309. ->whereIn('category_id', $catid)
  3310. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3311. ->orderBy('pid')->get()->all();
  3312. if (!empty($category)) {
  3313. $result['category'] = $category;
  3314. }
  3315. $result['job'] = $job;
  3316. $result['job_experience'] = $job_experience ?? [];
  3317. $result['education_experience'] = $education_experience ?? [];
  3318. if (empty($result)) {
  3319. return Result::error("参数错误", 0);
  3320. }
  3321. return Result::success($result);
  3322. }
  3323. /**
  3324. * c端-申请职位
  3325. * @param array $data
  3326. * @return array
  3327. * */
  3328. public function getWebsiteJobApply(array $data): array
  3329. {
  3330. // 首先验证网站是否存在
  3331. // return Result::success($data);
  3332. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3333. if (empty($web)) {
  3334. return Result::error("该网站不存在", 0);
  3335. }
  3336. // 验证用户是否存在且为个人会员/管理员
  3337. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3338. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3339. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3340. return Result::error("用户不存在", 0);
  3341. }
  3342. // 去除重复元素和空元素,并保持原始顺序
  3343. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3344. return !empty($value);
  3345. }));
  3346. // 验证职位是否存在 1:审核通过
  3347. $recruiting = JobRecruiting::where('status', 1)
  3348. ->where('website_id', $data['website_id'])
  3349. ->whereIn('id', $data['recruit_id'])
  3350. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3351. if (empty($recruiting)) {
  3352. return Result::error("该职位不存在", 0);
  3353. }
  3354. // 简历是否存在
  3355. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3356. if (empty($hunt_id)) {
  3357. return Result::error("该简历不存在", 0);
  3358. }
  3359. $data['hunt_id'] = $hunt_id['hunt_id'];
  3360. // // 验证是否已投递过该职位
  3361. $apply = JobApply::where('user_id', $data['user_id'])
  3362. ->where('hunt_id', $data['hunt_id'])
  3363. ->where('website_id', $data['website_id'])
  3364. ->whereIn('recruit_id', $data['recruit_id'])
  3365. ->get(['recruit_id']);
  3366. if (!empty($apply->toArray())) {
  3367. return Result::error("您已投递过该职位!");
  3368. }
  3369. $insertData = array_map(function ($recruiting) use ($data) {
  3370. return [
  3371. 'user_id' => $data['user_id'],
  3372. 'hunt_id' => $data['hunt_id'],
  3373. 'website_id' => $data['website_id'],
  3374. 'recruit_id' => $recruiting['recruit_id'],
  3375. 'receiver_id' => $recruiting['receiver_id'],
  3376. 'status' => 1,
  3377. ];
  3378. }, $recruiting);
  3379. // 批量插入数据
  3380. $result = JobApply::insert($insertData);
  3381. if (empty($result)) {
  3382. return Result::error("投递失败", 0);
  3383. }
  3384. return Result::success($result);
  3385. }
  3386. /**
  3387. * 招工招聘-沟通简历
  3388. * @param array $data
  3389. * @return array
  3390. * */
  3391. public function getWebsiteJobResume(array $data): array
  3392. {
  3393. // 首先验证网站是否存在
  3394. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3395. if (empty($web)) {
  3396. return Result::error("该网站不存在", 0);
  3397. }
  3398. // return Result::success($data);
  3399. // 验证用户是否存在且为企业会员/管理员
  3400. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3401. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3402. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3403. return Result::error("用户不存在", 0);
  3404. }
  3405. // 去除重复元素和空元素,并保持原始顺序
  3406. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3407. return !empty($value);
  3408. }));
  3409. // 验证简历是否存在
  3410. $hunting = JobHunting::where('status', 2)
  3411. ->where('website_id', $data['website_id'])
  3412. ->whereIn('id', $data['hunt_id'])
  3413. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3414. if (empty($hunting)) {
  3415. return Result::error("该简历不存在", 0);
  3416. }
  3417. // 验证是否已沟通过该简历
  3418. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3419. ->where('recruit_id', $data['recruit_id'])
  3420. ->where('website_id', $data['website_id'])
  3421. ->whereIn('hunt_id', $data['hunt_id'])
  3422. ->get(['hunt_id']);
  3423. if (!empty($remuse->toArray())) {
  3424. return Result::error("您已沟通过该简历!");
  3425. }
  3426. // 准备要插入的数据数组
  3427. $insertData = array_map(function ($hunting) use ($data) {
  3428. return [
  3429. 'user_id' => $data['user_id'],
  3430. 'recruit_id' => $data['recruit_id'],
  3431. 'website_id' => $data['website_id'],
  3432. 'hunt_id' => $hunting['hunt_id'],
  3433. 'receiver_id' => $hunting['receiver_id'],
  3434. 'status' => 1,
  3435. ];
  3436. }, $hunting);
  3437. // 批量插入数据
  3438. $result = JobRemuse::insert($insertData);
  3439. if (empty($result)) {
  3440. return Result::error("沟通失败", 0);
  3441. }
  3442. return Result::success($result);
  3443. }
  3444. /**
  3445. * 招工招聘 -我的职位(企业会员)
  3446. * @param array $data
  3447. * @return array
  3448. */
  3449. public function getWebsiteJobRecruiting(array $data): array
  3450. {
  3451. $web = Website::where('id', $data['website_id'])->first('id');
  3452. if (empty($web)) {
  3453. return Result::error("该网站不存在", 0);
  3454. }
  3455. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3456. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3457. return Result::error("用户暂无权限!", 0);
  3458. }
  3459. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3460. $result = JobRecruiting::where('website_id', $data['website_id'])
  3461. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3462. $query->where('user_id', $user['id']);
  3463. })
  3464. ->where('status', 1)
  3465. ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
  3466. ->orderBy('updated_at', 'desc')
  3467. ->limit($data['pageSize'])
  3468. ->get();
  3469. if (empty($result)) {
  3470. return Result::error("暂无相关职位信息", 0);
  3471. }
  3472. return Result::success($result);
  3473. }
  3474. /**
  3475. * c端 - 验证路由
  3476. * @param array $data
  3477. * @return array
  3478. */
  3479. /**
  3480. * c端 - 验证路由
  3481. * @param array $data
  3482. * @return array
  3483. */
  3484. public function checkWebsiteRoute(array $data): array
  3485. {
  3486. // 测试001111111222
  3487. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3488. if (empty($web)) {
  3489. return Result::error("该网站不存在", 0);
  3490. } elseif ($web['status'] != 1) {
  3491. return Result::error("网站已经关闭", 0);
  3492. }
  3493. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3494. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3495. // 验证路由是否存在
  3496. if (empty($whiteRouterInfo)) {
  3497. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  3498. }
  3499. if (!empty($whiteRouterInfo)) {
  3500. return Result::success($whiteRouterInfo->toArray());
  3501. }
  3502. }
  3503. // 验证栏目路由
  3504. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3505. ->where('path', $data['all_route'])
  3506. ->get()->all();
  3507. if (count($last_category) == 0) {
  3508. return Result::error("该栏目不存在", 0);
  3509. }
  3510. if (count($last_category) > 1) {
  3511. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  3512. }
  3513. if (count($last_category) == 1) {
  3514. $last_category = $last_category[0];
  3515. }
  3516. // return Result::success($last_category);
  3517. if (isset($data['id']) && !empty($data['id'])) {
  3518. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3519. switch ($last_category['type']) {
  3520. case 1:
  3521. // 文章
  3522. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3523. $article = Article::where('status', 1)
  3524. ->where('id', $data['id'])
  3525. ->where(function ($query) use ($data) {
  3526. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3527. ->orWhereNull("ignore_ids");
  3528. })
  3529. ->first(['catid']);
  3530. if (empty($article)) {
  3531. return Result::error("该文章不存在", 0);
  3532. }
  3533. // return Result::success($article);
  3534. break;
  3535. case 2:
  3536. // 商品
  3537. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3538. $article = Good::where('website_id', $data['website_id'])
  3539. ->where('status', 2)
  3540. ->where('id', $data['id'])
  3541. ->first(['cat_arr_id']);
  3542. if (empty($article)) {
  3543. return Result::error("该商品不存在", 0);
  3544. }
  3545. break;
  3546. case 3:
  3547. // 书刊信息
  3548. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3549. $article = Book::where('website_id', $data['website_id'])
  3550. ->where('status', 2)
  3551. ->where('id', $data['id'])
  3552. ->first(['id', 'cat_arr_id']);
  3553. if (empty($article)) {
  3554. return Result::error("该书刊不存在", 0);
  3555. }
  3556. break;
  3557. case 4:
  3558. // 招聘
  3559. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  3560. $article = JobRecruiting::where('website_id', $data['website_id'])
  3561. ->where('status', 1)
  3562. ->where('id', $data['id'])
  3563. ->first(['cat_arr_id']);
  3564. if (empty($article)) {
  3565. return Result::error("该招聘不存在", 0);
  3566. }
  3567. break;
  3568. case 5:
  3569. // 求职
  3570. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3571. $article = JobHunting::where('website_id', $data['website_id'])
  3572. ->where('status', 2)
  3573. ->where('id', $data['id'])
  3574. ->first(['cat_arr_id']);
  3575. if (empty($article)) {
  3576. return Result::error("该求职不存在", 0);
  3577. }
  3578. break;
  3579. case 6:
  3580. // 企业
  3581. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3582. $article = Company::
  3583. // where('website_id', $data['website_id'])
  3584. // ->
  3585. where('status', 1)
  3586. ->where('id', $data['id'])
  3587. ->first(['cat_arr_id']);
  3588. if (empty($article)) {
  3589. return Result::error("该企业不存在", 0);
  3590. }
  3591. break;
  3592. case 7:
  3593. // 项目
  3594. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3595. $article = Project::where('website_id', $data['website_id'])
  3596. ->where('status', 1)
  3597. ->where('id', $data['id'])
  3598. ->first(['cat_arr_id']);
  3599. if (empty($article)) {
  3600. return Result::error("该项目不存在", 0);
  3601. }
  3602. break;
  3603. default:
  3604. return Result::error("该数据不存在", 0);
  3605. break;
  3606. }
  3607. // return Result::success($article);
  3608. // $catid =0 ;
  3609. if (!isset($article['cat_arr_id'])) {
  3610. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  3611. } else {
  3612. $catidArray = json_decode($article['cat_arr_id'], true);
  3613. $catid = !empty($catidArray) ? end($catidArray) : null;
  3614. }
  3615. // return Result::success($catid);
  3616. // // return Result::success($article['cat_arr_id']);
  3617. if (empty($catid)) {
  3618. return Result::error("该栏目路径不存在", 0);
  3619. }
  3620. $path = WebsiteCategory::where('website_id', $data['website_id'])
  3621. ->where('category_id', $catid)
  3622. ->first('path');
  3623. }
  3624. // else{
  3625. // // if ($last_category['pid'] != 0) {
  3626. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  3627. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  3628. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3629. // ->where('category_id',$catid)
  3630. // ->where('path',$data['all_route'])
  3631. // ->first('path');
  3632. // // } else {
  3633. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  3634. // // }
  3635. // }
  3636. // return Result::success($path);
  3637. if (!empty($path) && $path['path'] != $data['all_route']) {
  3638. return Result::error('非法路径!');
  3639. } else {
  3640. return Result::success($last_category['path']);
  3641. }
  3642. }
  3643. /**
  3644. * 招工招聘 - 获取推荐职位
  3645. * @param array $data
  3646. * @return array
  3647. */
  3648. public function getWebsiteLevelJob(array $data): array
  3649. {
  3650. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3651. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  3652. ->where('job_recruiting.status', 1)
  3653. ->where('job_level', $data['job_level'])
  3654. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3655. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  3656. ->orderBy('job_recruiting.updated_at', 'desc')
  3657. ->limit($data['pageSize'])
  3658. ->get();
  3659. $web = ['website_id' => $data['website_id']];
  3660. if (!empty($job)) {
  3661. $result = $this->processJob($job, $web);
  3662. }
  3663. if (empty($result)) {
  3664. return Result::error("暂无相关职位信息", 0);
  3665. }
  3666. return Result::success($result);
  3667. }
  3668. /**
  3669. * 验证导航名称是否重复
  3670. * @return void
  3671. */
  3672. //20250226 产品列表
  3673. public function getGoodList(array $data): array
  3674. {
  3675. var_dump($data, '---------1-2--');
  3676. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  3677. unset($data['user_type_id']);
  3678. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3679. $where = [];
  3680. if ($type_id != '10000') {
  3681. $where = [
  3682. 'good.user_id' => $user_id,
  3683. ];
  3684. }
  3685. //类型
  3686. if (isset($data['type_id']) && $data['type_id']) {
  3687. $where['good.type_id'] = $data['type_id'];
  3688. }
  3689. //名称
  3690. if (isset($data['name']) && $data['name']) {
  3691. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  3692. }
  3693. //status
  3694. if (isset($data['status']) && $data['status'] != '') {
  3695. $where['good.status'] = $data['status'];
  3696. }
  3697. //status1
  3698. // if (isset($data['status1']) && $data['status1'] == 1) {
  3699. // $status1 = 1;
  3700. // }
  3701. $where1 = [];
  3702. //website_id
  3703. // if (isset($data['website_id']) && $data['website_id']) {
  3704. // $where1 = [
  3705. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  3706. // ];
  3707. // }
  3708. // website_name
  3709. if (isset($data['website_name']) && $data['website_name']) {
  3710. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  3711. }
  3712. // catid
  3713. if (isset($data['category_name']) && $data['category_name']) {
  3714. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  3715. }
  3716. // $result = Good::where($where)
  3717. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  3718. var_dump($where, '---------1---');
  3719. $result = Good::where($where)
  3720. ->when(!empty($where1), function ($query) use ($where1) {
  3721. return $query->where($where1);
  3722. })
  3723. //status 1待审核2已审核3已拒绝
  3724. ->when(isset($data['status1']), function ($query) {
  3725. return $query->whereIn('good.status', [1, 3]);
  3726. })
  3727. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3728. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3729. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3730. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3731. ->orderBy("updated_at", "desc")
  3732. ->limit($data['page_size'])
  3733. ->offset(($data['page'] - 1) * $data['page_size'])
  3734. ->get();
  3735. $count = Good::where($where)
  3736. ->when(!empty($where1), function ($query) use ($where1) {
  3737. return $query->where($where1);
  3738. })
  3739. //status 1待审核2已审核3已拒绝
  3740. ->when(isset($data['status1']), function ($query) {
  3741. return $query->whereIn('good.status', [1, 3]);
  3742. })
  3743. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3744. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3745. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3746. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3747. ->orderBy("updated_at", "desc")->count();
  3748. $data = [
  3749. 'rows' => $result->toArray(),
  3750. 'count' => $count,
  3751. ];
  3752. if (empty($result)) {
  3753. return Result::error("此栏目暂无相关产品", 0);
  3754. }
  3755. return Result::success($data);
  3756. }
  3757. public function getGoodInfo(array $data): array
  3758. {
  3759. $result = Good::where('id', $data['id'])->first();
  3760. if (empty($result)) {
  3761. return Result::error("此产品不存在", 0);
  3762. }
  3763. return Result::success($result);
  3764. }
  3765. public function addGood(array $data): array
  3766. {
  3767. // unset($data['city_arr_id']);
  3768. // unset($data['cat_arr_id']);
  3769. $data['city_id'] = end($data['city_arr_id']);
  3770. $data['catid'] = end($data['cat_arr_id']);
  3771. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3772. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3773. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3774. unset($data['imgUrl']); //大小写
  3775. if (isset($data['price']) && $data['price'] == '') {
  3776. $data['price'] = 0;
  3777. }
  3778. if ($data['imgurl'] == '') {
  3779. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3780. preg_match_all($reg, $data['detail'], $matches);
  3781. if (isset($matches[1][0])) {
  3782. //截取varchar240
  3783. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3784. }
  3785. }
  3786. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3787. //提取标题+内容中的关键词
  3788. $data['keyword'] = $data['name'];
  3789. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3790. Jieba::init(); // 初始化 jieba-php
  3791. Finalseg::init();
  3792. $segList = Jieba::cut($data['keyword']);
  3793. $segList1 = array_slice($segList, 0, 8);
  3794. $data['keyword'] = implode(',', $segList1);
  3795. }
  3796. if ($data['description'] == '') {
  3797. //提取内容中的描述
  3798. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3799. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3800. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  3801. }
  3802. if ($data['status'] == 1) {
  3803. $this->sendMessage([
  3804. 'talk_type' => 200,
  3805. 'title' => $data['name'],
  3806. 'content' => '提交了审核',
  3807. 'messageType' => 3,
  3808. ]);
  3809. }
  3810. $result = Good::insert($data);
  3811. if (empty($result)) {
  3812. return Result::error("添加失败", 0);
  3813. }
  3814. return Result::success($result);
  3815. }
  3816. public function updateGood(array $data): array
  3817. {
  3818. $data['city_id'] = end($data['city_arr_id']);
  3819. $data['catid'] = end($data['cat_arr_id']);
  3820. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3821. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3822. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3823. //设置东八区
  3824. date_default_timezone_set('Asia/Shanghai');
  3825. $data['updated_at'] = date('Y-m-d H:i:s');
  3826. if (isset($data['price']) && $data['price'] == '') {
  3827. $data['price'] = 0;
  3828. }
  3829. if ($data['imgurl'] == '') {
  3830. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3831. preg_match_all($reg, $data['detail'], $matches);
  3832. if (isset($matches[1][0])) {
  3833. //截取varchar240
  3834. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3835. }
  3836. }
  3837. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3838. //提取标题+内容中的关键词
  3839. $data['keyword'] = $data['name'];
  3840. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3841. Jieba::init(); // 初始化 jieba-php
  3842. Finalseg::init();
  3843. $segList = Jieba::cut($data['keyword']);
  3844. $segList1 = array_slice($segList, 0, 8);
  3845. $data['keyword'] = implode(',', $segList1);
  3846. }
  3847. if ($data['description'] == '') {
  3848. //提取内容中的描述
  3849. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3850. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3851. }
  3852. if ($data['status'] == 1) {
  3853. $this->sendMessage([
  3854. 'talk_type' => 200,
  3855. 'title' => $data['name'],
  3856. 'content' => '提交了审核',
  3857. 'messageType' => 3,
  3858. ]);
  3859. }
  3860. $result = Good::where('id', $data['id'])->update($data);
  3861. if (empty($result)) {
  3862. return Result::error("更新失败", 0);
  3863. }
  3864. return Result::success($result);
  3865. }
  3866. public function delGood(array $data): array
  3867. {
  3868. $result = Good::where('id', $data['id'])->delete();
  3869. if (empty($result)) {
  3870. return Result::error("删除失败", 0);
  3871. }
  3872. return Result::success($result);
  3873. }
  3874. //20250226 产品列表
  3875. //20250306 求职信息
  3876. public function getJobHuntingList(array $data): array
  3877. {
  3878. $where = [];
  3879. if (isset($data['username']) && !empty($data['username'])) {
  3880. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3881. }
  3882. //status 1待审核2已审核3已拒绝
  3883. if (isset($data['status']) && $data['status'] != '') {
  3884. $where = [
  3885. 'job_hunting.status' => $data['status'],
  3886. ];
  3887. }
  3888. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3889. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3890. unset($data['type_id']);
  3891. if ($type_id != '10000') {
  3892. $where[] = ['job_hunting.user_id', '=', $user_id];
  3893. }
  3894. $result = JobHunting::where($where)
  3895. ->when(!empty($data['status1']), function ($query) use ($data) {
  3896. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3897. })
  3898. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3899. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3900. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  3901. ->orderBy("updated_at", "desc")
  3902. ->limit($data['page_size'])
  3903. ->offset(($data['page'] - 1) * $data['page_size'])
  3904. ->get();
  3905. if (empty($result)) {
  3906. return Result::error("查询失败", 0);
  3907. }
  3908. $count = JobHunting::where($where)
  3909. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3910. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3911. ->count();
  3912. $data = [
  3913. 'rows' => $result->toArray(),
  3914. 'count' => $count,
  3915. ];
  3916. return Result::success($data);
  3917. }
  3918. public function getJobHuntingApply(array $data): array
  3919. {
  3920. var_dump($data, '-----------------test--------1-');
  3921. $where = [];
  3922. if (isset($data['username']) && !empty($data['username'])) {
  3923. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3924. }
  3925. if (isset($data['salary']) && !empty($data['salary'])) {
  3926. $where[] = [
  3927. 'job_hunting.salary',
  3928. '=',
  3929. $data['salary'],
  3930. ];
  3931. }
  3932. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3933. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3934. unset($data['type_id']);
  3935. if ($type_id != '10000') {
  3936. $where[] = ['job_apply.receiver_id', '=', $user_id];
  3937. }
  3938. var_dump($where, '-----------------test---------');
  3939. $result = jobApply::where($where)
  3940. // ->when(!empty($data['status1']), function ($query) use ($data) {
  3941. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3942. // })
  3943. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  3944. ->where('job_enum.egroup', '=', 'income')
  3945. ->where('job_hunting.status', 2) //已审核
  3946. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3947. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3948. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3949. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3950. //职位----是申请职位
  3951. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3952. ->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')
  3953. ->orderBy("job_hunting.updated_at", "desc")
  3954. ->limit($data['page_size'])
  3955. ->offset(($data['page'] - 1) * $data['page_size'])
  3956. ->get();
  3957. if (empty($result)) {
  3958. return Result::error("查询失败", 0);
  3959. }
  3960. $count = jobApply::where($where)
  3961. ->where('job_enum.egroup', '=', 'income')
  3962. ->where('job_hunting.status', 2) //已审核
  3963. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3964. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3965. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3966. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3967. //职位----是申请职位
  3968. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3969. ->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')
  3970. ->count();
  3971. $data = [
  3972. 'rows' => $result->toArray(),
  3973. 'count' => $count,
  3974. ];
  3975. return Result::success($data);
  3976. }
  3977. public function addJobHunting(array $data): array
  3978. {
  3979. date_default_timezone_set('Asia/Shanghai');
  3980. unset($data['company_name']);
  3981. unset($data['job_industry']);
  3982. unset($data['job_name']);
  3983. unset($data['department']);
  3984. unset($data['job_timeList']);
  3985. unset($data['job_content']);
  3986. unset($data['job_typename']); //不知道这是啥,
  3987. $data['created_at'] = date('Y-m-d H:i:s');
  3988. $data['updated_at'] = date('Y-m-d H:i:s');
  3989. //根据用户 user_id 只能添加一次
  3990. $result = JobHunting::where('user_id', $data['user_id'])->first();
  3991. if (!empty($result)) {
  3992. return Result::error("您已添加过求职信息", 0);
  3993. }
  3994. var_dump($result, '-----------------test---------');
  3995. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  3996. if (is_string($data['city_arr_id'])) {
  3997. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3998. $cityArr = json_decode($data['city_arr_id'], true);
  3999. // 确保 $cityArr 是数组
  4000. if (is_array($cityArr)) {
  4001. $data['city_id'] = end($cityArr);
  4002. }
  4003. } else {
  4004. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4005. if (is_array($data['city_arr_id'])) {
  4006. $data['city_id'] = end($data['city_arr_id']);
  4007. }
  4008. }
  4009. }
  4010. // 处理求职所绑定栏目
  4011. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4012. if (is_string($data['cat_arr_id'])) {
  4013. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4014. // 先清理可能存在的无效 JSON 字符
  4015. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4016. $catArr = json_decode($cleanedCatArrStr, true);
  4017. // 检查 JSON 解码是否成功且结果是数组
  4018. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4019. $data['catid'] = end($catArr);
  4020. }
  4021. } else {
  4022. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4023. if (is_array($data['cat_arr_id'])) {
  4024. $data['catid'] = end($data['cat_arr_id']);
  4025. }
  4026. }
  4027. }
  4028. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4029. $this->sendMessage([
  4030. 'talk_type' => 600,
  4031. 'title' => $data['name'],
  4032. 'content' => '提交了审核',
  4033. 'messageType' => 11,
  4034. ]);
  4035. }
  4036. $result = JobHunting::create($data);
  4037. if (empty($result)) {
  4038. return Result::error("添加失败", 0);
  4039. }
  4040. return Result::success($result);
  4041. }
  4042. public function delJobHunting(array $data): array
  4043. {
  4044. $result = JobHunting::where('id', $data['id'])->delete();
  4045. if (empty($result)) {
  4046. return Result::error("删除失败", 0);
  4047. }
  4048. return Result::success($result);
  4049. }
  4050. public function updateJobHunting(array $data): array
  4051. {
  4052. //设置东八区
  4053. date_default_timezone_set('Asia/Shanghai');
  4054. unset($data['company_name']);
  4055. unset($data['job_industry']);
  4056. unset($data['job_name']);
  4057. unset($data['department']);
  4058. unset($data['job_timeList']);
  4059. unset($data['job_content']);
  4060. unset($data['job_typename']); //不知道这是啥,
  4061. $data['created_at'] = date('Y-m-d H:i:s');
  4062. $data['updated_at'] = date('Y-m-d H:i:s');
  4063. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4064. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4065. $cityArr = json_decode($data['city_arr_id'], true);
  4066. $data['city_id'] = end($cityArr);
  4067. } else {
  4068. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4069. $data['city_id'] = end($data['city_arr_id']);
  4070. }
  4071. // 处理求职所绑定栏目
  4072. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4073. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4074. $catArr = json_decode($data['cat_arr_id'], true);
  4075. $data['catid'] = end($catArr);
  4076. } else {
  4077. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4078. $data['catid'] = end($data['cat_arr_id']);
  4079. }
  4080. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4081. $this->sendMessage([
  4082. 'talk_type' => 600,
  4083. 'title' => $data['name'],
  4084. 'content' => '提交了审核',
  4085. 'messageType' => 11,
  4086. ]);
  4087. }
  4088. $result = JobHunting::where('id', $data['id'])->update($data);
  4089. if (empty($result)) {
  4090. return Result::error("更新失败", 0);
  4091. }
  4092. return Result::success($result);
  4093. }
  4094. public function getJobHuntingInfo(array $data): array
  4095. {
  4096. $result = JobHunting::where('id', $data['id'])->first();
  4097. if (empty($result)) {
  4098. return Result::error("查询失败", 0);
  4099. }
  4100. return Result::success($result);
  4101. }
  4102. public function getJobHuntingData(array $data): array
  4103. {
  4104. $jobEnum = JobEnum::get();
  4105. $jobIndustry = JobIndustry::get();
  4106. $jobNature = JobNature::get();
  4107. $jobPosition = JobPosition::get();
  4108. $data = [
  4109. 'jobEnum' => $jobEnum,
  4110. 'jobIndustry' => $jobIndustry,
  4111. 'jobNature' => $jobNature,
  4112. 'jobPosition' => $jobPosition,
  4113. ];
  4114. return Result::success($data);
  4115. }
  4116. public function delJobHuntingInfo(array $data): array
  4117. {
  4118. $result = JobHunting::where('id', $data['id'])->delete();
  4119. return Result::success();
  4120. }
  4121. //20250324 通知,公告,消息
  4122. public function delNotice(array $data): array
  4123. {
  4124. $result = Notice::where('id', $data['id'])->delete();
  4125. if ($result) {
  4126. return Result::success();
  4127. } else {
  4128. return Result::error("删除失败", 0);
  4129. }
  4130. }
  4131. public function getNoticeInfo(array $data): array
  4132. {
  4133. $result = Notice::where('id', $data['id'])->first();
  4134. // var_dump($result['re_user_ids'], '--------------------');
  4135. if (empty($result)) {
  4136. return Result::error("查询失败", 0);
  4137. }
  4138. return Result::success($result);
  4139. }
  4140. public function readNotice(array $data): array
  4141. {
  4142. $result = Notice::where('id', $data['id'])->first();
  4143. // var_dump($result['re_user_ids'], '--------------------');
  4144. if (empty($result)) {
  4145. return Result::error("查询失败", 0);
  4146. }
  4147. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4148. $re_user_ids = json_decode($result['re_user_ids'], true);
  4149. var_dump($re_user_ids, '--------------1---test---------');
  4150. var_dump($data, '--------------1---test---------');
  4151. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4152. //如果已经存在,就不再添加
  4153. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4154. $read_id = json_decode($result['read_id'], true);
  4155. if (!is_array($read_id)) {
  4156. $read_id = [];
  4157. }
  4158. if (!in_array($data['user_id'], $read_id)) {
  4159. $read_id[] = $data['user_id'];
  4160. $result['read_id'] = json_encode($read_id);
  4161. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4162. }
  4163. } else {
  4164. //如果不存在,就添加
  4165. $result['read_id'] = json_encode([$data['user_id']]);
  4166. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4167. }
  4168. }
  4169. return Result::success($result);
  4170. }
  4171. public function addNotice(array $data): array
  4172. {
  4173. date_default_timezone_set('Asia/Shanghai');
  4174. $data['created_at'] = date('Y-m-d H:i:s');
  4175. $data['updated_at'] = date('Y-m-d H:i:s');
  4176. $user_id = UserInfo::
  4177. //city_id不是null
  4178. whereNotNull('city_id')
  4179. ->whereNotNull('department_id')
  4180. ->where(function ($query) use ($data) {
  4181. $query->where(function ($subQuery) use ($data) {
  4182. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4183. });
  4184. })
  4185. ->where(function ($query) use ($data) {
  4186. $query->where(function ($subQuery) use ($data) {
  4187. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4188. });
  4189. })
  4190. ->pluck('user_id')->toArray();
  4191. $user_id = array_unique($user_id);
  4192. $chat_ids = $user_id;
  4193. $user_id = json_encode($user_id);
  4194. $data['re_user_ids'] = $user_id;
  4195. $this->sendMessage([
  4196. 'talk_type' => 700,
  4197. 'title' => $data['title'],
  4198. 'content' => '提交了审核',
  4199. 'messageType' => 5,
  4200. ]);
  4201. $result = Notice::insertGetId($data);
  4202. if (empty($result)) {
  4203. return Result::error("添加失败", 0);
  4204. }
  4205. return Result::success($result);
  4206. }
  4207. public function updateNotice(array $data): array
  4208. {
  4209. date_default_timezone_set('Asia/Shanghai');
  4210. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4211. $user_id = UserInfo::
  4212. //city_id不是null
  4213. whereNotNull('city_id')
  4214. ->whereNotNull('department_id')
  4215. ->where(function ($query) use ($data) {
  4216. $query->where(function ($subQuery) use ($data) {
  4217. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4218. });
  4219. })
  4220. ->where(function ($query) use ($data) {
  4221. $query->where(function ($subQuery) use ($data) {
  4222. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4223. });
  4224. })
  4225. ->pluck('user_id')->toArray();
  4226. $user_id = array_unique($user_id);
  4227. $user_id = json_encode($user_id);
  4228. $data['re_user_ids'] = $user_id;
  4229. $data['updated_at'] = date('Y-m-d H:i:s');
  4230. $this->sendMessage([
  4231. 'talk_type' => 700,
  4232. 'title' => $data['title'],
  4233. 'content' => '提交了审核',
  4234. 'messageType' => 5,
  4235. ]);
  4236. $result = Notice::where('id', $data['id'])->update($data);
  4237. return Result::success($result);
  4238. }
  4239. public function getNoticeList(array $data): array
  4240. {
  4241. $where = [];
  4242. //title
  4243. if (isset($data['title']) && !empty($data['title'])) {
  4244. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4245. }
  4246. //level
  4247. if (isset($data['level']) && !empty($data['level'])) {
  4248. $where[] = ['notice.level', '=', $data['level']];
  4249. }
  4250. //status
  4251. if (isset($data['status']) && !empty($data['status'])) {
  4252. $where[] = ['notice.status', '=', $data['status']];
  4253. }
  4254. //type
  4255. if (isset($data['type']) && !empty($data['type'])) {
  4256. $where[] = ['notice.type', '=', $data['type']];
  4257. }
  4258. var_dump($data, '------------11111-2----test---------');
  4259. if ($data['type_id'] == 10000) {
  4260. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4261. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4262. })
  4263. ->where($where)
  4264. ->orderBy('updated_at', 'desc')
  4265. ->limit($data['page_size'])
  4266. ->offset(($data['page'] - 1) * $data['page_size'])
  4267. ->get();
  4268. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4269. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4270. })
  4271. ->where($where)
  4272. ->orderBy('updated_at', 'desc')
  4273. ->count();
  4274. } else {
  4275. $result = Notice::where($where)
  4276. // ->where('user_id', $data['user_id'])
  4277. ->Where(function ($query) use ($data) {
  4278. $query->Where(function ($q) use ($data) {
  4279. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4280. ->orWhere('notice.user_id', $data['user_id']);
  4281. });
  4282. })
  4283. ->when(!empty($data['status1']), function ($query) use ($data) {
  4284. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4285. })
  4286. ->orderBy('updated_at', 'desc')
  4287. ->limit($data['page_size'])
  4288. ->offset(($data['page'] - 1) * $data['page_size'])
  4289. ->get();
  4290. $total = Notice::where($where)
  4291. ->when(!empty($data['status1']), function ($query) use ($data) {
  4292. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4293. })
  4294. // ->where('user_id', $data['user_id'])
  4295. ->Where(function ($query) use ($data) {
  4296. $query->Where(function ($q) use ($data) {
  4297. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4298. ->orWhere('notice.user_id', $data['user_id']);
  4299. });
  4300. })
  4301. ->count();
  4302. }
  4303. if (empty($result)) {
  4304. return Result::error("查询失败", 0);
  4305. }
  4306. $data = [
  4307. 'rows' => $result,
  4308. 'count' => $total,
  4309. ];
  4310. return Result::success($data);
  4311. }
  4312. public function noticeList(array $data): array
  4313. {
  4314. $where = [];
  4315. //title
  4316. if (isset($data['title']) && !empty($data['title'])) {
  4317. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4318. }
  4319. //level
  4320. if (isset($data['level']) && !empty($data['level'])) {
  4321. $where[] = ['notice.level', '=', $data['level']];
  4322. }
  4323. //status
  4324. if (isset($data['status']) && !empty($data['status'])) {
  4325. $where[] = ['notice.status', '=', $data['status']];
  4326. }
  4327. //type
  4328. if (isset($data['type']) && !empty($data['type'])) {
  4329. $where[] = ['notice.type', '=', $data['type']];
  4330. }
  4331. var_dump($data, '------------11111-2----test---------');
  4332. if ($data['type_id'] == 10000) {
  4333. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4334. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4335. })
  4336. ->where($where)
  4337. ->orderBy('updated_at', 'desc')
  4338. ->limit($data['page_size'])
  4339. ->offset(($data['page'] - 1) * $data['page_size'])
  4340. ->get();
  4341. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4342. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4343. })
  4344. ->where($where)
  4345. ->orderBy('updated_at', 'desc')
  4346. ->count();
  4347. } else {
  4348. $result = Notice::where($where)
  4349. // ->where('user_id', $data['user_id'])
  4350. ->Where(function ($query) use ($data) {
  4351. $query->Where(function ($q) use ($data) {
  4352. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4353. ->orWhere('notice.user_id', $data['user_id']);
  4354. });
  4355. })
  4356. ->when(!empty($data['status1']), function ($query) use ($data) {
  4357. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4358. })
  4359. ->orderBy('updated_at', 'desc')
  4360. ->limit($data['page_size'])
  4361. ->offset(($data['page'] - 1) * $data['page_size'])
  4362. ->get();
  4363. $total = Notice::where($where)
  4364. ->when(!empty($data['status1']), function ($query) use ($data) {
  4365. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4366. })
  4367. // ->where('user_id', $data['user_id'])
  4368. ->Where(function ($query) use ($data) {
  4369. $query->Where(function ($q) use ($data) {
  4370. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4371. ->orWhere('notice.user_id', $data['user_id']);
  4372. });
  4373. })
  4374. ->count();
  4375. }
  4376. if (empty($result)) {
  4377. return Result::error("查询失败", 0);
  4378. }
  4379. $data = [
  4380. 'rows' => $result,
  4381. 'count' => $total,
  4382. ];
  4383. return Result::success($data);
  4384. }
  4385. public function getNoticeDetail(array $data): array
  4386. {
  4387. $result = Notice::where('id', $data['id'])->first();
  4388. if (empty($result)) {
  4389. return Result::error("查询失败", 0);
  4390. }
  4391. return Result::success($result);
  4392. }
  4393. public function deleteNotice(array $data): array
  4394. {
  4395. $notice = Notice::where('id', $data['id'])->first();
  4396. if (empty($notice)) {
  4397. return Result::error("删除失败", 0);
  4398. }
  4399. $chat_group_id = $notice->group_id;
  4400. if ($chat_group_id) {
  4401. //删除群聊
  4402. ChatGroups::where('id', $chat_group_id)->delete();
  4403. //删除群成员
  4404. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4405. //删除群聊记录
  4406. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4407. }
  4408. $result = Notice::where('id', $data['id'])->delete();
  4409. return Result::success($result);
  4410. }
  4411. public function complaintList(array $data): array
  4412. {
  4413. var_dump($data, '---------1---------');
  4414. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4415. unset($data['type_id']);
  4416. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4417. $where = [];
  4418. if ($type_id != 10000 && empty($data['deal_user'])) {
  4419. // $where['complaint.user_id'] = $user_id;
  4420. }
  4421. if (!empty($data['title'])) {
  4422. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4423. }
  4424. if (!empty($data['department_id'])) {
  4425. $where['complaint.department_id'] = $data['department_id'];
  4426. }
  4427. if (!empty($data['deal'])) {
  4428. $where['complaint.deal'] = $data['deal'];
  4429. }
  4430. if (!empty($data['status'])) {
  4431. $where['complaint.status'] = $data['status'];
  4432. }
  4433. var_dump(!empty($data['deal_user']), '----------1');
  4434. var_dump($where, '----------2');
  4435. $result = Complaint::where($where)
  4436. ->when(!empty($data['status1']), function ($query) use ($data) {
  4437. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4438. })
  4439. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4440. //json re_user_ids data[user_id]是不是在里面
  4441. $query->Where(function ($q) use ($data) {
  4442. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4443. ->where('complaint.status', 2);
  4444. });
  4445. })
  4446. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4447. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4448. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4449. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4450. ->orderBy('updated_at', 'desc')
  4451. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4452. //sql输出
  4453. if (empty($result)) {
  4454. return Result::error("暂无投诉信息", 0);
  4455. }
  4456. // 取出数据
  4457. $rows = $result->items();
  4458. $count = $result->total();
  4459. $responseData = [
  4460. 'rows' => $rows,
  4461. 'count' => $count,
  4462. ];
  4463. return Result::success($responseData);
  4464. }
  4465. public function getComplaintList(array $data): array
  4466. {
  4467. var_dump($data, '00000001000000000000');
  4468. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4469. unset($data['type_id']);
  4470. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4471. $where = [];
  4472. if ($type_id != 10000 && empty($data['deal_user'])) {
  4473. $where['complaint.user_id'] = $user_id;
  4474. }
  4475. if (!empty($data['title'])) {
  4476. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4477. }
  4478. if (!empty($data['department_id'])) {
  4479. $where['complaint.department_id'] = $data['department_id'];
  4480. }
  4481. if (!empty($data['deal'])) {
  4482. $where['complaint.deal'] = $data['deal'];
  4483. }
  4484. if (!empty($data['status'])) {
  4485. $where['complaint.status'] = $data['status'];
  4486. }
  4487. var_dump(!empty($data['deal_user']), '----------1');
  4488. var_dump($where, '----------2');
  4489. $result = Complaint::where($where)
  4490. ->when(!empty($data['status1']), function ($query) use ($data) {
  4491. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4492. })
  4493. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4494. // //json re_user_ids data[user_id]是不是在里面
  4495. // $query->Where(function ($q) use ($data) {
  4496. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4497. // ->where('complaint.status', 2);
  4498. // });
  4499. // })
  4500. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4501. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4502. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4503. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4504. ->orderBy('updated_at', 'desc')
  4505. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4506. //sql输出
  4507. if (empty($result)) {
  4508. return Result::error("暂无投诉信息", 0);
  4509. }
  4510. // 取出数据
  4511. $rows = $result->items();
  4512. $count = $result->total();
  4513. $responseData = [
  4514. 'rows' => $rows,
  4515. 'count' => $count,
  4516. ];
  4517. return Result::success($responseData);
  4518. }
  4519. public function getComplaintInfo(array $data): array
  4520. {
  4521. $result = Complaint::where('id', $data['id'])->first();
  4522. if (empty($result)) {
  4523. return Result::error("查询失败", 0);
  4524. }
  4525. return Result::success($result);
  4526. }
  4527. public function readComplaint(array $data): array
  4528. {
  4529. $result = Complaint::where('id', $data['id'])->first();
  4530. if (empty($result)) {
  4531. return Result::error("查询失败", 0);
  4532. }
  4533. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4534. $re_user_ids = json_decode($result['re_user_ids'], true);
  4535. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4536. //如果已经存在,就不再添加
  4537. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4538. $read_id = json_decode($result['read_id'], true);
  4539. if (!is_array($read_id)) {
  4540. $read_id = [];
  4541. }
  4542. if (!in_array($data['user_id'], $read_id)) {
  4543. $read_id[] = $data['user_id'];
  4544. $result['read_id'] = json_encode($read_id);
  4545. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4546. }
  4547. } else {
  4548. //如果不存在,就添加
  4549. $result['read_id'] = json_encode([$data['user_id']]);
  4550. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4551. }
  4552. }
  4553. return Result::success($result);
  4554. }
  4555. public function addComplaint(array $data): array
  4556. {
  4557. date_default_timezone_set('Asia/Shanghai');
  4558. $data['created_at'] = date('Y-m-d H:i:s');
  4559. $data['updated_at'] = date('Y-m-d H:i:s');
  4560. $this->sendMessage([
  4561. 'talk_type' => 800,
  4562. 'title' => $data['title'],
  4563. 'content' => '提交了审核',
  4564. 'messageType' => 6,
  4565. ]);
  4566. $result = Complaint::create($data);
  4567. return Result::success($result);
  4568. }
  4569. public function updateComplaint(array $data): array
  4570. {
  4571. date_default_timezone_set('Asia/Shanghai');
  4572. $data['updated_at'] = date('Y-m-d H:i:s');
  4573. $user_id = $data['user_id'] ?? 0;
  4574. $type_id = $data['type_id'] ?? 0;
  4575. unset($data['user_id']);
  4576. unset($data['type_id']);
  4577. $this->sendMessage([
  4578. 'talk_type' => 800,
  4579. 'title' => $data['title'],
  4580. 'content' => '提交了审核',
  4581. 'messageType' => 6,
  4582. ]);
  4583. $result = Complaint::where('id', $data['id'])->update($data);
  4584. return Result::success($result);
  4585. }
  4586. public function deleteComplaint(array $data): array
  4587. {
  4588. $result = Complaint::where('id', $data['id'])->delete();
  4589. return Result::success($result);
  4590. }
  4591. public function getComplainInfo(array $data): array
  4592. {
  4593. $result = Complaint::where('id', $data['id'])->first();
  4594. if (empty($result)) {
  4595. return Result::error("查询失败", 0);
  4596. }
  4597. return Result::success($result);
  4598. }
  4599. public function updateComplaintStatus(array $data): array
  4600. {
  4601. date_default_timezone_set('Asia/Shanghai');
  4602. $data['updated_at'] = date('Y-m-d H:i:s');
  4603. $user_id = $data['user_id'] ?? 0;
  4604. $type_id = $data['type_id'] ?? 0;
  4605. unset($data['user_id']);
  4606. unset($data['type_id']);
  4607. //处理, 写入处理人
  4608. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4609. $data['real_deal_user'] = $user_id;
  4610. }
  4611. //如果是deal 23,则判断是不是处理人
  4612. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4613. $complaintInof = Complaint::where('id', $data['id'])
  4614. ->where('real_deal_user', $user_id)
  4615. ->first();
  4616. if (empty($complaintInof)) {
  4617. return Result::error("处理人错误", 0);
  4618. }
  4619. }
  4620. $complaintInfo = Complaint::where('id', $data['id'])->first();
  4621. if ($data['status'] == 1) {
  4622. $this->sendMessage([
  4623. 'talk_type' => 800,
  4624. 'title' => $complaintInfo['title'],
  4625. 'content' => '提交了审核',
  4626. 'messageType' => 6,
  4627. ]);
  4628. }
  4629. if ($data['status'] == 2 && !isset($data['deal'])) {
  4630. $this->sendMessage([
  4631. 'talk_type' => 801,
  4632. 'title' => $complaintInfo['title'],
  4633. 'content' => '审核通过',
  4634. 'messageType' => 6,
  4635. 'user_id' => $complaintInfo['user_id'],
  4636. ]);
  4637. $this->sendMessage([
  4638. 'talk_type' => 802,
  4639. 'title' => $complaintInfo['title'],
  4640. 'content' => '待处理',
  4641. 'messageType' => 6,
  4642. 'user_id' => $complaintInfo['re_user_ids'],
  4643. ]);
  4644. }
  4645. if ($data['status'] == 3 && !isset($data['deal'])) {
  4646. $this->sendMessage([
  4647. 'talk_type' => 801,
  4648. 'title' => $complaintInfo['title'],
  4649. 'content' => '审核拒绝',
  4650. 'messageType' => 6,
  4651. 'user_id' => $complaintInfo['user_id'],
  4652. ]);
  4653. }
  4654. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  4655. $this->sendMessage([
  4656. 'talk_type' => 802,
  4657. 'title' => $complaintInfo['title'],
  4658. 'content' => '处理中',
  4659. 'messageType' => 6,
  4660. 'user_id' => $complaintInfo['re_user_ids'],
  4661. ]);
  4662. }
  4663. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  4664. $this->sendMessage([
  4665. 'talk_type' => 802,
  4666. 'title' => $complaintInfo['title'],
  4667. 'content' => '不予处理',
  4668. 'messageType' => 6,
  4669. 'user_id' => $complaintInfo['re_user_ids'],
  4670. ]);
  4671. }
  4672. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  4673. $this->sendMessage([
  4674. 'talk_type' => 802,
  4675. 'title' => $complaintInfo['title'],
  4676. 'content' => '已完结',
  4677. 'messageType' => 6,
  4678. 'user_id' => $complaintInfo['re_user_ids'],
  4679. ]);
  4680. }
  4681. $result = complaint::where('id', $data['id'])->update($data);
  4682. return Result::success($result);
  4683. }
  4684. public function updateGoodStatus(array $data): array
  4685. {
  4686. $user_id = $data['user_id'] ?? 0;
  4687. $type_id = $data['type_id'] ?? 0;
  4688. unset($data['user_id']);
  4689. unset($data['type_id']);
  4690. $goodInfo = Good::where('id', $data['id'])->first();
  4691. if ($data['status'] == 2) {
  4692. $this->sendMessage([
  4693. 'talk_type' => 201,
  4694. 'title' => $goodInfo['name'],
  4695. 'content' => '审核通过',
  4696. 'messageType' => 3,
  4697. 'user_id' => $goodInfo['user_id'],
  4698. ]);
  4699. }
  4700. if ($data['status'] == 3) {
  4701. $this->sendMessage([
  4702. 'talk_type' => 201,
  4703. 'title' => $goodInfo['name'],
  4704. 'content' => '审核拒绝',
  4705. 'messageType' => 3,
  4706. 'user_id' => $goodInfo['user_id'],
  4707. ]);
  4708. }
  4709. if ($data['status'] == 1) {
  4710. $this->sendMessage([
  4711. 'talk_type' => 200,
  4712. 'title' => $goodInfo['name'],
  4713. 'content' => '提交了审核',
  4714. 'messageType' => 3,
  4715. ]);
  4716. }
  4717. $result = Good::where('id', $data['id'])->update($data);
  4718. return Result::success($result);
  4719. }
  4720. public function updateJobHuntingStatus(array $data): array
  4721. {
  4722. $user_id = $data['user_id'] ?? 0;
  4723. $type_id = $data['type_id'] ?? 0;
  4724. unset($data['user_id']);
  4725. unset($data['type_id']);
  4726. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  4727. if ($data['status'] == 2) {
  4728. $this->sendMessage([
  4729. 'talk_type' => 601,
  4730. 'title' => $jogHuntingInfo['name'],
  4731. 'content' => '审核通过',
  4732. 'messageType' => 11,
  4733. 'user_id' => $jogHuntingInfo['user_id'],
  4734. ]);
  4735. }
  4736. if ($data['status'] == 3) {
  4737. $this->sendMessage([
  4738. 'talk_type' => 601,
  4739. 'title' => $jogHuntingInfo['name'],
  4740. 'content' => '审核拒绝',
  4741. 'messageType' => 11,
  4742. 'user_id' => $jogHuntingInfo['user_id'],
  4743. ]);
  4744. }
  4745. if ($data['status'] == 1) {
  4746. $this->sendMessage([
  4747. 'talk_type' => 600,
  4748. 'title' => $jogHuntingInfo['name'],
  4749. 'content' => '提交了审核',
  4750. 'messageType' => 11,
  4751. ]);
  4752. }
  4753. $result = JobHunting::where('id', $data['id'])->update($data);
  4754. return Result::success($result);
  4755. }
  4756. public function updateNoticeStatus(array $data): array
  4757. {
  4758. $user_id = $data['user_id'] ?? 0;
  4759. $type_id = $data['type_id'] ?? 0;
  4760. unset($data['user_id']);
  4761. unset($data['type_id']);
  4762. //查询公告
  4763. $notice = Notice::where('id', $data['id'])->first();
  4764. if (empty($notice)) {
  4765. return Result::error("公告不存在", 0);
  4766. }
  4767. //$chat_ids 去除掉$data['user_id']
  4768. $chat_ids = json_decode($notice['re_user_ids'], true);
  4769. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  4770. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  4771. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  4772. //chat_group
  4773. $group_id = PublicData::uuid();
  4774. $groupData = [
  4775. 'id' => $group_id,
  4776. 'creator_id' => $notice['user_id'],
  4777. 'group_name' => $notice['group_name'] ?? '',
  4778. 'profile' => $notice['profile'] ?? 0,
  4779. ];
  4780. var_dump($groupData, '-----------------groupData-------');
  4781. $groupResult = ChatGroups::insertGetId($groupData);
  4782. var_dump($groupResult, '-----------------groupid-------');
  4783. $groupMemberData = [
  4784. 'id' => PublicData::uuid(),
  4785. 'user_id' => $notice['user_id'],
  4786. 'group_id' => $group_id,
  4787. 'leader' => 2,
  4788. ];
  4789. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  4790. //插入群成员表
  4791. $groupMemberDataUser = [];
  4792. $chatData = [];
  4793. foreach ($chat_ids as $key => $value) {
  4794. $groupMemberDataUser[] = [
  4795. 'id' => PublicData::uuid(),
  4796. 'user_id' => $value,
  4797. 'group_id' => $group_id,
  4798. 'leader' => 1,
  4799. ];
  4800. $chatData[] = [
  4801. 'user_id' => $value,
  4802. 'msg_type' => 1,
  4803. 'receiver_id' => $group_id,
  4804. 'content' => '通过通知创建群聊',
  4805. 'group_receiver_id' => $notice['user_id'],
  4806. 'action' => 'recieved',
  4807. 'created_at' => date('Y-m-d H:i:s'),
  4808. ];
  4809. }
  4810. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  4811. ChatGroupsMember::insert($groupMemberDataUser);
  4812. //插入一条管理员聊天记录
  4813. $chatData[] = [
  4814. 'user_id' => $notice['user_id'],
  4815. 'msg_type' => 1,
  4816. 'receiver_id' => $group_id,
  4817. 'content' => '通过通知创建群聊',
  4818. 'group_receiver_id' => $notice['user_id'],
  4819. 'action' => 'said',
  4820. 'created_at' => date('Y-m-d H:i:s'),
  4821. ];
  4822. var_dump($chatData, '-----------------chatData-------');
  4823. $chatResult = ChatRecords::insert($chatData);
  4824. //处理imp
  4825. $group = [
  4826. 'type' => 1,
  4827. 'name' => $notice['group_name'] ?? '',
  4828. 'profile' => '',
  4829. 'avatar' => '',
  4830. 'creator_id' => $notice['user_id'],
  4831. ];
  4832. $groupResult = GroupImp::insertGetId($group);
  4833. var_dump($groupResult, '获取imp group_id');
  4834. $groupMember = [
  4835. 'user_id' => $notice['user_id'],
  4836. 'group_id' => $groupResult,
  4837. 'leader' => 1,
  4838. 'join_time' => Date('Y-m-d H:i:s')
  4839. ];
  4840. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  4841. $talk_session = [
  4842. 'user_id' => $notice['user_id'],
  4843. 'to_from_id' => $groupResult,
  4844. 'talk_mode' => 2,
  4845. 'created_at' => Date('Y-m-d H:i:s'),
  4846. 'updated_at' => Date('Y-m-d H:i:s'),
  4847. ];
  4848. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  4849. //被通知人员处理
  4850. foreach ($chat_ids as $key => $value) {
  4851. $groupMemberdata[] = [
  4852. 'user_id' => $value,
  4853. 'group_id' => $groupResult,
  4854. 'leader' => 3,
  4855. 'join_time' => Date('Y-m-d H:i:s')
  4856. ];
  4857. $talk_sessionData[] = [
  4858. 'user_id' => $value,
  4859. 'to_from_id' => $groupResult,
  4860. 'talk_mode' => 2,
  4861. 'created_at' => Date('Y-m-d H:i:s'),
  4862. 'updated_at' => Date('Y-m-d H:i:s'),
  4863. ];
  4864. }
  4865. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  4866. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  4867. $group_id = $groupResult;
  4868. //更新result的 group_id
  4869. $data['group_id'] = $group_id;
  4870. Notice::where(['id' => $data['id']])->update($data);
  4871. }
  4872. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  4873. //删除掉信息
  4874. GroupImp::where('id', $notice['group_id'])->delete();
  4875. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  4876. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  4877. foreach ($chat_ids as $key => $value) {
  4878. }
  4879. //聊天记录删除
  4880. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  4881. $data['group_id'] = null;
  4882. Notice::where(['id' => $data['id']])->update($data);
  4883. }
  4884. $result = Notice::where('id', $data['id'])->update($data);
  4885. $noticeInfo = Notice::where('id', $data['id'])->first();
  4886. if ($data['status'] == 2) {
  4887. $this->sendMessage([
  4888. 'talk_type' => 701,
  4889. 'title' => $noticeInfo['title'],
  4890. 'content' => '审核通过',
  4891. 'messageType' => 3,
  4892. 'user_id' => $noticeInfo['user_id'],
  4893. ]);
  4894. }
  4895. if ($data['status'] == 3) {
  4896. $this->sendMessage([
  4897. 'talk_type' => 701,
  4898. 'title' => $noticeInfo['title'],
  4899. 'content' => '审核拒绝',
  4900. 'messageType' => 3,
  4901. 'user_id' => $noticeInfo['user_id'],
  4902. ]);
  4903. }
  4904. if ($data['status'] == 1) {
  4905. $this->sendMessage([
  4906. 'talk_type' => 700,
  4907. 'title' => $noticeInfo['title'],
  4908. 'content' => '提交了审核',
  4909. 'messageType' => 3,
  4910. ]);
  4911. }
  4912. return Result::success($result);
  4913. }
  4914. public function getDUser(array $data): array
  4915. {
  4916. if (!empty($data['ids'])) {
  4917. $user = User::whereIn('id', $data['ids'])->getall();
  4918. if (empty($user)) {
  4919. return Result::error('无数据', 0);
  4920. }
  4921. return Result::success($user);
  4922. }
  4923. $where = [];
  4924. if (!empty($data['department_id'])) {
  4925. $where['department_id'] = $data['department_id'];
  4926. }
  4927. if (!empty($data['city_id'])) {
  4928. $where['city_id'] = $data['city_id'];
  4929. }
  4930. $result = User::where('type_id', 2)
  4931. ->where('status', 1)
  4932. ->where($where)
  4933. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  4934. ->get();
  4935. if (empty($result)) {
  4936. return Result::error("查询失败", 0);
  4937. }
  4938. return Result::success($result);
  4939. }
  4940. /**
  4941. * 验证导航名称是否重复
  4942. * @return void
  4943. */
  4944. public function checkCategoryName(array $data): array
  4945. {
  4946. $result = Category::when($data, function ($query) use ($data) {
  4947. if (isset($data['name']) && $data['name']) {
  4948. $query->where("name", $data['name']);
  4949. }
  4950. if (isset($data['id']) && $data['id']) {
  4951. $query->where("id", "!=", $data['id']);
  4952. }
  4953. })->first();
  4954. if ($result) {
  4955. return Result::error("已存在");
  4956. } else {
  4957. return Result::success();
  4958. }
  4959. }
  4960. //20250226 产品列表
  4961. // 20250306 -------招聘--------fr
  4962. /*
  4963. * 招聘列表
  4964. * */
  4965. public function getJobRecruitingList(array $data): array
  4966. {
  4967. $where = [];
  4968. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  4969. if ($data['checkout'] == 0) {
  4970. $job_status = [0, 2];
  4971. } else {
  4972. $job_status = [1];
  4973. }
  4974. if (isset($data['keyword']) && !empty($data['keyword'])) {
  4975. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  4976. }
  4977. $user = User::where('id', $data['user_id'])->first();
  4978. if (empty($user)) {
  4979. return Result::error("用户不存在", 0);
  4980. }
  4981. // 3:企业会员
  4982. if ($user['type_id'] == 3) {
  4983. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  4984. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  4985. }
  4986. // 如果 $where 为空,则不添加 where 条件
  4987. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4988. return $query->where($where);
  4989. })
  4990. ->whereIn('job_recruiting.status', $job_status)
  4991. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4992. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4993. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  4994. ->orderBy("updated_at", "desc")
  4995. ->offset(($data['page'] - 1) * $data['page_size'])
  4996. ->limit($data['page_size'])
  4997. ->get()
  4998. ->all();
  4999. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5000. return $query->where($where);
  5001. })
  5002. ->whereIn('job_recruiting.status', $job_status)
  5003. ->count();
  5004. if (empty($result)) {
  5005. return Result::error("暂无招聘信息", 0);
  5006. }
  5007. return Result::success($result);
  5008. }
  5009. /*
  5010. * 招聘信息添加
  5011. * */
  5012. public function addJobRecruiting(array $data): array
  5013. {
  5014. // var_dump('添加招聘进入news------data',$data);
  5015. // return Result::success($data);
  5016. $user = User::where('user.id', $data['user_id'])
  5017. ->where('user.status', 1)
  5018. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5019. ->select(
  5020. 'user.type_id',
  5021. 'user.mobile',
  5022. 'user.email',
  5023. 'user_info.business_name',
  5024. 'user_info.company_hy_id',
  5025. 'user_info.company_nature',
  5026. 'user_info.company_size',
  5027. 'user_info.introduction',
  5028. 'user_info.real_name',
  5029. 'user_info.company_url',
  5030. 'user_info.address_arr_id',
  5031. 'user_info.address'
  5032. )
  5033. ->first();
  5034. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5035. return Result::error("用户不存在", 0);
  5036. }
  5037. $web = Website::where('id', $data['website_id'])->first();
  5038. if (empty($web)) {
  5039. return Result::error("网站不存在", 0);
  5040. }
  5041. // var_dump('添加招聘进入news---user---user',$user);
  5042. // 处理招聘关键词
  5043. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5044. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5045. } else {
  5046. Jieba::init(); // 初始化 jieba-php
  5047. Finalseg::init();
  5048. $segList = Jieba::cut($data['title']);
  5049. $segList1 = array_slice($segList, 0, 8);
  5050. $data['keyword'] = implode(',', $segList1);
  5051. }
  5052. // return Result::success($user);
  5053. $data['action_id'] = $data['user_id'] ?? null;
  5054. $data['user_type'] = $user['type_id'] ?? null;
  5055. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5056. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5057. $data['catid'] = end($data['cat_arr_id']);
  5058. } else {
  5059. $data['catid'] = 0;
  5060. }
  5061. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5062. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5063. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5064. // 公司地址 管理员必填
  5065. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5066. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5067. // 管理员-企业相关信息
  5068. $company = [
  5069. // 'user_id' => $data['user_id']?? null,
  5070. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5071. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5072. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5073. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5074. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5075. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5076. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5077. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5078. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5079. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5080. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5081. ];
  5082. //去掉相关企业信息
  5083. $job = array_diff_key($data, array_flip(array_keys($company)));
  5084. // var_dump('添加招聘进入news---job---user',$job);
  5085. Db::beginTransaction();
  5086. try {
  5087. // // 先添加职位相关信息
  5088. if ($user['type_id'] == 10000) {
  5089. $job['status'] = 1;
  5090. }
  5091. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5092. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5093. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5094. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5095. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5096. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5097. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5098. // return Result::success($job);
  5099. $jobId = JobRecruiting::insertGetId($job);
  5100. if (empty($jobId)) {
  5101. Db::rollBack();
  5102. return Result::error("添加失败");
  5103. }
  5104. // 添加公司信息
  5105. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5106. $company['job_id'] = $jobId;
  5107. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5108. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5109. if ($user['type_id'] == 10000) {
  5110. // 管理员添加企业信息
  5111. $companyId = JobCompany::insertGetId($company);
  5112. if (empty($companyId)) {
  5113. Db::rollBack();
  5114. return Result::error("添加失败");
  5115. }
  5116. } else {
  5117. // 企业会员添加企业信息
  5118. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5119. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5120. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5121. $company['job_id'] = $jobId;
  5122. $companyId = JobCompany::insertGetId($company);
  5123. if (empty($companyId)) {
  5124. Db::rollBack();
  5125. return Result::error("添加失败");
  5126. }
  5127. }
  5128. Db::commit();
  5129. $result = [
  5130. 'job_id' => $jobId,
  5131. 'company_id' => $companyId,
  5132. ];
  5133. return Result::success($result);
  5134. } catch (\Exception $e) {
  5135. Db::rollBack();
  5136. return Result::error($e->getMessage(), 0);
  5137. }
  5138. // return Result::success($result);
  5139. }
  5140. /*
  5141. * 获取招聘信息详情
  5142. * */
  5143. public function getJobRecruitingInfo(array $data): array
  5144. {
  5145. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5146. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5147. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5148. ->select(
  5149. 'job_recruiting.*',
  5150. 'website.website_name as website_name',
  5151. 'job_company.business_name',
  5152. 'job_company.company_hy_id',
  5153. 'job_company.company_size',
  5154. 'job_company.company_nature',
  5155. 'job_company.introduction',
  5156. 'job_company.real_name',
  5157. 'job_company.mobile',
  5158. 'job_company.company_url',
  5159. 'job_company.address_arr_id',
  5160. 'job_company.address',
  5161. 'job_company.email'
  5162. )
  5163. ->first();
  5164. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5165. if (!empty($cityId)) {
  5166. if (isset($cityId[1]) && $cityId[1] != null) {
  5167. $city = District::where('id', $cityId[1])->first(['name']);
  5168. } else {
  5169. $city = District::where('id', $cityId[0])->first(['name']);
  5170. }
  5171. $result['city'] = $city['name'] ?? '';
  5172. }
  5173. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5174. if (is_array($addressId) && !empty($addressId)) {
  5175. $address = District::whereIn('id', $addressId)
  5176. ->orderBy('level', 'asc')
  5177. ->get(['name'])
  5178. ->pluck('name')
  5179. ->implode('');
  5180. // $job->address_name = $address ?? '';
  5181. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5182. }
  5183. if (empty($result)) {
  5184. return Result::error("招聘信息不存在", 0);
  5185. }
  5186. // return Result::success($job);
  5187. return Result::success($result);
  5188. }
  5189. /*
  5190. * 修改招聘信息
  5191. * */
  5192. public function upJobRecruiting(array $data): array
  5193. {
  5194. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5195. // return Result::success($job);
  5196. if (empty($job)) {
  5197. return Result::error("招聘信息不存在", 0);
  5198. }
  5199. $user = User::where('id', $data['user_id'])->first();
  5200. // return Result::success($user);
  5201. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5202. return Result::error("用户不存在", 0);
  5203. }
  5204. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5205. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5206. }
  5207. // 处理招聘关键词
  5208. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5209. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5210. } else {
  5211. Jieba::init(); // 初始化 jieba-php
  5212. Finalseg::init();
  5213. $segList = Jieba::cut($data['title']);
  5214. $segList1 = array_slice($segList, 0, 8);
  5215. $data['keyword'] = implode(',', $segList1);
  5216. }
  5217. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5218. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5219. $data['catid'] = end($data['cat_arr_id']);
  5220. } else {
  5221. }
  5222. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5223. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5224. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5225. // 公司地址 管理员必填
  5226. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5227. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5228. // 管理员-企业相关信息
  5229. $company = [
  5230. // 'user_id' => $data['user_id']?? null,
  5231. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5232. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5233. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5234. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5235. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5236. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5237. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5238. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5239. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5240. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5241. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5242. ];
  5243. //去掉相关企业信息
  5244. $data = array_diff_key($data, array_flip(array_keys($company)));
  5245. $jobId = $data['id'];
  5246. $web = $data['website_id'];
  5247. $data['action_id'] = $data['user_id'];
  5248. unset($data['user_id']);
  5249. unset($data['user_type']);
  5250. unset($data['id']);
  5251. unset($data['website_id']);
  5252. // return Result::success($data);
  5253. Db::beginTransaction();
  5254. try {
  5255. // 管理员修改招聘信息
  5256. if ($user['type_id'] == 10000) {
  5257. $data['website_id'] = $web;
  5258. $company['website_id'] = $data['website_id'];
  5259. $data['status'] = 1;
  5260. } else {
  5261. $data['status'] = 0;
  5262. }
  5263. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5264. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5265. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5266. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5267. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5268. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5269. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5270. // return Result::success($job);
  5271. // Db::rollBack();
  5272. // return Result::success($company);
  5273. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5274. $this->sendMessage([
  5275. 'talk_type' => 500,
  5276. 'title' => $data['title'],
  5277. 'content' => '提交了审核',
  5278. 'messageType' => 10,
  5279. ]);
  5280. }
  5281. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5282. if (empty($result['job'])) {
  5283. Db::rollBack();
  5284. return Result::error("修改招聘信息失败");
  5285. }
  5286. // 管理员修改企业相关信息
  5287. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5288. if (empty($result['company'])) {
  5289. Db::rollBack();
  5290. return Result::error("修改企业相关信息失败");
  5291. }
  5292. Db::commit();
  5293. // return Result::success($result);
  5294. } catch (\Exception $e) {
  5295. Db::rollBack();
  5296. return Result::error($e->getMessage(), 0);
  5297. }
  5298. return Result::success($result);
  5299. }
  5300. /*
  5301. * 招聘信息删除
  5302. * */
  5303. public function delJobRecruiting(array $data): array
  5304. {
  5305. $user = User::where('id', $data['user_id'])->first();
  5306. if (empty($user)) {
  5307. return Result::error("用户不存在", 0);
  5308. }
  5309. $job = JobRecruiting::where('id', $data['id'])->first();
  5310. if (empty($job)) {
  5311. return Result::error("招聘信息不存在", 0);
  5312. }
  5313. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5314. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5315. }
  5316. Db::beginTransaction();
  5317. try {
  5318. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5319. if (empty($result['job'])) {
  5320. Db::rollBack();
  5321. return Result::error("删除招聘信息失败");
  5322. }
  5323. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5324. if (empty($result['company'])) {
  5325. Db::rollBack();
  5326. return Result::error("删除企业相关信息失败");
  5327. }
  5328. Db::commit();
  5329. } catch (\Exception $e) {
  5330. Db::rollBack();
  5331. return Result::error($e->getMessage(), 0);
  5332. }
  5333. return Result::success($result);
  5334. }
  5335. /*
  5336. * 获取公司信息
  5337. * */
  5338. public function getJobCompany(array $data): array
  5339. {
  5340. $user = User::where('user.id', $data['user_id'])
  5341. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5342. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5343. ->first();
  5344. // return Result::success($user);
  5345. if (empty($user)) {
  5346. return Result::error("用户不存在", 0);
  5347. }
  5348. if ($user['type_id'] == 3) {
  5349. $result = [
  5350. // 'id' => 0,
  5351. 'user_id' => $data['user_id'],
  5352. 'website_id' => $data['website_id'],
  5353. 'business_name' => $user['business_name'], // 企业名称
  5354. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5355. 'company_nature' => $user['company_nature'], // 公司性质
  5356. 'company_size' => $user['company_size'], // 公司规模
  5357. 'introduction' => $user['introduction'], // 公司简介
  5358. 'real_name' => $user['real_name'], // 企业联系人
  5359. 'mobile' => $user['mobile'], // 企业联系电话
  5360. 'company_url' => $user['company_url'], // 企业网址
  5361. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5362. 'address' => $user['address'], // 企业地址
  5363. 'email' => $user['email'], // 企业邮箱
  5364. ];
  5365. } else {
  5366. return Result::error("用户类型错误", 0);
  5367. }
  5368. if (empty($result)) {
  5369. return Result::error("公司信息不存在", 0);
  5370. }
  5371. return Result::success($result);
  5372. }
  5373. /*
  5374. * 修改公司信息
  5375. * */
  5376. public function upJobCompany(array $data): array
  5377. {
  5378. // return Result::success($data);
  5379. $user = User::where('user.id', $data['user_id'])
  5380. ->where('user.status', 1)
  5381. ->select('user.user_name', 'user.type_id')
  5382. ->first();
  5383. if (empty($user)) {
  5384. return Result::error("用户不存在", 0);
  5385. }
  5386. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5387. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5388. $company = [
  5389. 'business_name' => $data['business_name'], // 企业名称
  5390. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5391. 'company_nature' => $data['company_nature'], // 公司性质
  5392. 'company_size' => $data['company_size'], // 公司规模
  5393. 'introduction' => $data['introduction'], // 公司简介
  5394. // 'real_name' => $data['real_name'], // 企业联系人
  5395. 'company_url' => $data['company_url'], // 企业网址
  5396. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5397. 'address' => $data['address'], // 企业详细地址
  5398. // 'email' => $data['email'], // 企业邮箱
  5399. ];
  5400. if ($user['type_id'] == 3) {
  5401. Db::beginTransaction();
  5402. try {
  5403. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5404. 'business_name' => $data['business_name'], // 企业名称
  5405. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5406. 'company_nature' => $data['company_nature'], // 公司性质
  5407. 'company_size' => $data['company_size'], // 公司规模
  5408. 'introduction' => $data['introduction'], // 公司简介
  5409. // 'real_name' => $data['real_name'], // 企业联系人
  5410. 'company_url' => $data['company_url'], // 企业网址
  5411. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5412. 'address' => $data['address'], // 企业详细地址
  5413. ]);
  5414. if (empty($result['userinfo'])) {
  5415. Db::rollBack();
  5416. return Result::error('修改企业会员信息失败!');
  5417. }
  5418. $result['user'] = User::where('id', $data['user_id'])->update([
  5419. 'email' => $data['email'], // 企业邮箱
  5420. ]);
  5421. if (empty($result['user'])) {
  5422. Db::rollBack();
  5423. return Result::error('修改个人中心信息失败!');
  5424. }
  5425. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5426. if (!empty($job_company)) {
  5427. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5428. if (empty($result['job_company'])) {
  5429. Db::rollBack();
  5430. return Result::error('修改企业会员信息失败!');
  5431. }
  5432. }
  5433. Db::commit();
  5434. return Result::success($result);
  5435. } catch (\Exception $e) {
  5436. Db::rollBack();
  5437. return Result::error($e->getMessage(), 0);
  5438. }
  5439. } else {
  5440. return Result::error("用户类型错误", 0);
  5441. }
  5442. }
  5443. /*
  5444. * 获取省-市
  5445. * */
  5446. public function getJobRecruitingArea(array $data): array
  5447. {
  5448. if (isset($data['pid']) && $data['pid'] != null) {
  5449. $result = District::where('pid', $data['pid'])->get()->all();
  5450. } else {
  5451. $result = District::where('level', 1)->get()->all();
  5452. }
  5453. if (empty($result)) {
  5454. return Result::error("暂无此省市", 0);
  5455. }
  5456. return Result::success($result);
  5457. }
  5458. /*
  5459. * 获取行业分类
  5460. * */
  5461. public function getIndustry(array $data): array
  5462. {
  5463. $result = JobIndustry::get()->all();
  5464. if (empty($result)) {
  5465. return Result::error("暂无行业分类", 0);
  5466. }
  5467. return Result::success($result);
  5468. }
  5469. /*
  5470. * 获取职位
  5471. * */
  5472. public function getPositionList(array $data): array
  5473. {
  5474. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5475. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5476. } else {
  5477. $result = JobPosition::where('zwpid', 0)->get()->all();
  5478. }
  5479. if (empty($result)) {
  5480. return Result::error("暂无此职位", 0);
  5481. }
  5482. return Result::success($result);
  5483. }
  5484. /*
  5485. * 获取工作性质-菜单
  5486. * */
  5487. public function getJobNature(array $data): array
  5488. {
  5489. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5490. if (empty($result)) {
  5491. return Result::error("暂无工作性质", 0);
  5492. }
  5493. return Result::success($result);
  5494. }
  5495. /*
  5496. * 获取工作经验-菜单
  5497. * */
  5498. public function getExperience(array $data): array
  5499. {
  5500. $result = JobEnum::where('egroup', 'years')->get()->all();
  5501. if (empty($result)) {
  5502. return Result::error("暂无工作经验", 0);
  5503. }
  5504. return Result::success($result);
  5505. }
  5506. /*
  5507. * 获取学历-菜单
  5508. * */
  5509. public function getEducation(array $data): array
  5510. {
  5511. $result = JobEnum::where('egroup', 'education')->get()->all();
  5512. if (empty($result)) {
  5513. return Result::error("暂无学历", 0);
  5514. }
  5515. return Result::success($result);
  5516. }
  5517. /*
  5518. * 获取薪资-菜单
  5519. * */
  5520. public function getSalary(array $data): array
  5521. {
  5522. $result = JobEnum::where('egroup', 'income')->get()->all();
  5523. if (empty($result)) {
  5524. return Result::error("暂无薪资", 0);
  5525. }
  5526. return Result::success($result);
  5527. }
  5528. /*
  5529. * 获取语言-菜单
  5530. * */
  5531. public function getLanguage(array $data): array
  5532. {
  5533. $result = JobEnum::where('egroup', 'language')->get()->all();
  5534. if (empty($result)) {
  5535. return Result::error("暂无语言", 0);
  5536. }
  5537. return Result::success($result);
  5538. }
  5539. /*
  5540. * 获取掌握程度-菜单
  5541. * */
  5542. public function getLevel(array $data): array
  5543. {
  5544. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  5545. if (empty($result)) {
  5546. return Result::error("暂无工作性质", 0);
  5547. }
  5548. return Result::success($result);
  5549. }
  5550. // 公司信息
  5551. /*
  5552. * 获取公司性质-菜单
  5553. * */
  5554. public function getCompanyNature(array $data): array
  5555. {
  5556. $result = JobNature::get()->all();
  5557. if (empty($result)) {
  5558. return Result::error("暂无公司性质", 0);
  5559. }
  5560. return Result::success($result);
  5561. }
  5562. /*
  5563. * 获取公司规模-菜单
  5564. * */
  5565. public function getCompanySize(array $data): array
  5566. {
  5567. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  5568. if (empty($result)) {
  5569. return Result::error("暂无公司规模", 0);
  5570. }
  5571. return Result::success($result);
  5572. }
  5573. /*
  5574. * 招聘信息审核
  5575. * */
  5576. public function checkJobRecruiting(array $data): array
  5577. {
  5578. $user = User::where('id', $data['user_id'])->first();
  5579. if (empty($user)) {
  5580. return Result::error("用户不存在", 0);
  5581. }
  5582. $job = JobRecruiting::where('id', $data['id'])->first();
  5583. if (empty($job)) {
  5584. return Result::error("招聘信息不存在", 0);
  5585. }
  5586. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  5587. if ($user['type_id'] != 10000) {
  5588. return Result::error("用户暂无权限审核此招聘信息!", 0);
  5589. }
  5590. // 驳回原因
  5591. if ($data['status'] == 2) {
  5592. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  5593. }
  5594. $data['action_id'] = $data['user_id'];
  5595. unset($data['user_id']);
  5596. if ($data['status'] == 1) {
  5597. $this->sendMessage([
  5598. 'talk_type' => 501,
  5599. 'title' => $job['title'],
  5600. 'content' => '审核通过',
  5601. 'messageType' => 10,
  5602. 'user_id' => $job['user_id'],
  5603. ]);
  5604. }
  5605. if ($data['status'] == 2) {
  5606. $this->sendMessage([
  5607. 'talk_type' => 501,
  5608. 'title' => $job['title'],
  5609. 'content' => '审核拒绝',
  5610. 'messageType' => 10,
  5611. 'user_id' => $job['user_id'],
  5612. ]);
  5613. }
  5614. if ($data['status'] == 0) {
  5615. $this->sendMessage([
  5616. 'talk_type' => 500,
  5617. 'title' => $job['title'],
  5618. 'content' => '提交了审核',
  5619. 'messageType' => 10,
  5620. ]);
  5621. }
  5622. $result = JobRecruiting::where('id', $data['id'])->update($data);
  5623. if (empty($result)) {
  5624. return Result::error("审核失败", 0);
  5625. }
  5626. return Result::success($result);
  5627. }
  5628. public function myApplyList(array $data): array
  5629. {
  5630. var_dump($data, '------参数');
  5631. $user = User::where('id', $data['user_id'])->first();
  5632. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5633. return Result::error("用户不存在", 0);
  5634. }
  5635. // 1:个人会员 职场机会
  5636. if ($user['type_id'] == 1) {
  5637. $where['user_id'] = $user['id'];
  5638. }
  5639. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  5640. $query->where('user_id', $user['id']);
  5641. })
  5642. ->pluck('recruit_id');
  5643. $where = [];
  5644. if (isset($data['salary']) && $data['salary'] != null) {
  5645. $where['job_recruiting.salary'] = $data['salary'];
  5646. }
  5647. if (isset($data['experience']) && $data['experience'] != null) {
  5648. $where['job_recruiting.experience'] = $data['experience'];
  5649. }
  5650. if (isset($data['business_name']) && $data['business_name'] != null) {
  5651. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5652. }
  5653. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5654. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5655. ->where($where);
  5656. // ->count();
  5657. $count = $query->count();
  5658. $query = clone $query;
  5659. $job = $query
  5660. ->leftJoin('job_enum as income_enum', function ($join) {
  5661. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5662. ->where('income_enum.egroup', 'income');
  5663. })
  5664. ->leftJoin('job_enum as years_enum', function ($join) {
  5665. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5666. ->where('years_enum.egroup', 'years');
  5667. })
  5668. // ->where($where)
  5669. ->orderBy('job_recruiting.updated_at', 'desc')
  5670. ->select(
  5671. 'job_recruiting.id',
  5672. 'job_recruiting.title',
  5673. 'job_company.business_name',
  5674. 'income_enum.evalue as salary_evalue',
  5675. 'income_enum.ename as salary_ename',
  5676. 'years_enum.evalue as experience_evalue',
  5677. 'years_enum.ename as experience_ename',
  5678. 'job_recruiting.updated_at'
  5679. )
  5680. ->offset(($data['page'] - 1) * $data['pageSize'])
  5681. ->limit($data['pageSize'])
  5682. ->get()
  5683. ->all();
  5684. if (empty($job)) {
  5685. return Result::error("暂无招聘信息", 0);
  5686. }
  5687. $result = [
  5688. 'row' => $job,
  5689. 'count' => $count,
  5690. ];
  5691. return Result::success($result);
  5692. }
  5693. public function readJobApply(array $data): array
  5694. {
  5695. $result = JobApply::where('id', $data['id'])->first();
  5696. if (empty($result)) {
  5697. return Result::error("查询失败", 0);
  5698. }
  5699. $result = JobApply::where('id', $data['id'])->update([
  5700. 'status' => 2,
  5701. ]);
  5702. return Result::success($result);
  5703. }
  5704. /*
  5705. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  5706. * */
  5707. public function getRecruitingList(array $data): array
  5708. {
  5709. $user = User::where('id', $data['user_id'])->first();
  5710. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5711. return Result::error("用户不存在", 0);
  5712. }
  5713. // 1:个人会员 职场机会
  5714. if ($user['type_id'] == 1) {
  5715. $where['user_id'] = $user['id'];
  5716. }
  5717. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  5718. $query->where('receiver_id', $user['id']);
  5719. })
  5720. ->pluck('recruit_id');
  5721. // return Result::success($recruitingId);
  5722. $where = [];
  5723. if (isset($data['salary']) && $data['salary'] != null) {
  5724. $where['job_recruiting.salary'] = $data['salary'];
  5725. }
  5726. if (isset($data['experience']) && $data['experience'] != null) {
  5727. $where['job_recruiting.experience'] = $data['experience'];
  5728. }
  5729. if (isset($data['business_name']) && $data['business_name'] != null) {
  5730. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5731. }
  5732. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5733. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5734. ->where($where);
  5735. // ->count();
  5736. $count = $query->count();
  5737. $query = clone $query;
  5738. $job = $query
  5739. ->leftJoin('job_enum as income_enum', function ($join) {
  5740. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5741. ->where('income_enum.egroup', 'income');
  5742. })
  5743. ->leftJoin('job_enum as years_enum', function ($join) {
  5744. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5745. ->where('years_enum.egroup', 'years');
  5746. })
  5747. // ->where($where)
  5748. ->orderBy('job_recruiting.updated_at', 'desc')
  5749. ->select(
  5750. 'job_recruiting.id',
  5751. 'job_recruiting.title',
  5752. 'job_company.business_name',
  5753. 'income_enum.evalue as salary_evalue',
  5754. 'income_enum.ename as salary_ename',
  5755. 'years_enum.evalue as experience_evalue',
  5756. 'years_enum.ename as experience_ename',
  5757. 'job_recruiting.updated_at'
  5758. )
  5759. ->offset(($data['page'] - 1) * $data['pageSize'])
  5760. ->limit($data['pageSize'])
  5761. ->get()
  5762. ->all();
  5763. if (empty($job)) {
  5764. return Result::error("暂无招聘信息", 0);
  5765. }
  5766. $result = [
  5767. 'row' => $job,
  5768. 'count' => $count,
  5769. ];
  5770. return Result::success($result);
  5771. }
  5772. /*
  5773. * 获取企业会员-招聘信息列表
  5774. * */
  5775. public function getRecruitingInfo(array $data): array
  5776. {
  5777. $user = User::where('id', $data['user_id'])->first();
  5778. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5779. return Result::error("用户不存在", 0);
  5780. }
  5781. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  5782. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5783. ->select(
  5784. 'job_recruiting.*',
  5785. 'job_company.business_name',
  5786. 'job_company.company_hy_id',
  5787. 'job_company.company_size',
  5788. 'job_company.company_nature',
  5789. 'job_company.introduction',
  5790. 'job_company.real_name',
  5791. 'job_company.mobile',
  5792. 'job_company.company_url',
  5793. 'job_company.address_arr_id',
  5794. 'job_company.address',
  5795. 'job_company.email'
  5796. )
  5797. ->get();
  5798. if (empty($recruiting)) {
  5799. return Result::error("暂无招聘信息", 0);
  5800. }
  5801. return Result::success($recruiting);
  5802. }
  5803. /*
  5804. * 获取企业会员-我的沟通
  5805. * */
  5806. public function getJobResumeList(array $data): array
  5807. {
  5808. $user = User::where('id', $data['user_id'])->first();
  5809. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  5810. return Result::error("用户不存在", 0);
  5811. }
  5812. $where = [];
  5813. if (isset($data['salary']) && $data['salary'] != null) {
  5814. $where['job_hunting.salary'] = $data['salary'];
  5815. }
  5816. if (isset($data['user_name']) && $data['user_name'] != null) {
  5817. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  5818. }
  5819. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  5820. $query->where('job_resume.user_id', $user['id']);
  5821. })
  5822. ->when(!empty($where), function ($query) use ($where) {
  5823. $query->where($where);
  5824. })
  5825. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  5826. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  5827. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  5828. ->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');
  5829. $count = $job->count();
  5830. if ($count == 0) {
  5831. return Result::error("暂无沟通记录", 0);
  5832. }
  5833. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  5834. ->offset(($data['page'] - 1) * $data['pageSize'])
  5835. ->limit($data['pageSize'])
  5836. ->get();
  5837. if (empty($jobs)) {
  5838. return Result::error("暂无沟通记录", 0);
  5839. }
  5840. $result['row'] = $this->processJob($jobs, '');
  5841. $result['count'] = $count;
  5842. return Result::success($result);
  5843. }
  5844. public function readJobResume(array $data): array
  5845. {
  5846. $result = JobResume::where('id', $data['id'])->first();
  5847. if (empty($result)) {
  5848. return Result::error("查询失败", 0);
  5849. }
  5850. $result = JobResume::where('id', $data['id'])->update([
  5851. 'status' => 2,
  5852. ]);
  5853. return Result::success($result);
  5854. }
  5855. // 20250306 招聘
  5856. //20250422 书刊音像
  5857. public function addBook(array $data): array
  5858. {
  5859. $user_id = $data['user_id'] ?? 0;
  5860. $type_id = $data['type_id'] ?? 0;
  5861. // $website_id = $data['website_id'] ?? 0;
  5862. // unset($data['user_id']);
  5863. unset($data['type_id']);
  5864. // unset($data['website_id']);
  5865. //处理数组
  5866. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5867. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5868. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5869. if ($data['img_url'] == '') {
  5870. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5871. preg_match_all($reg, $data['detail'], $matches);
  5872. if (isset($matches[1][0])) {
  5873. //截取varchar240
  5874. $data['img_url'] = substr($matches[1][0], 0, 240);
  5875. }
  5876. }
  5877. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  5878. //提取标题+内容中的关键词
  5879. $data['keyword'] = $data['title'];
  5880. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5881. Jieba::init(); // 初始化 jieba-php
  5882. Finalseg::init();
  5883. $segList = Jieba::cut($data['keyword']);
  5884. $segList1 = array_slice($segList, 0, 8);
  5885. $data['keyword'] = implode(',', $segList1);
  5886. }
  5887. if ($data['description'] == '') {
  5888. //提取内容中的描述
  5889. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5890. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5891. }
  5892. var_dump($data, '--');
  5893. if ($data['status'] == 1) {
  5894. $this->sendMessage([
  5895. 'talk_type' => 400,
  5896. 'title' => $data['title'],
  5897. 'content' => '提交了审核',
  5898. 'messageType' => 7,
  5899. ]);
  5900. }
  5901. $result = Book::insertGetId($data);
  5902. if (empty($result)) {
  5903. return Result::error("添加失败", 0);
  5904. }
  5905. return Result::success($result);
  5906. }
  5907. public function getBookList(array $data): array
  5908. {
  5909. $where = [];
  5910. if (!empty($data["title"])) {
  5911. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  5912. }
  5913. if (!empty($data['website_name'])) {
  5914. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  5915. }
  5916. if (!empty($data['status'])) {
  5917. $where[] = ['book.status', '=', $data['status']];
  5918. }
  5919. $user_id = $data['user_id'];
  5920. $type_id = $data['type_id'];
  5921. // $type_id = 4;
  5922. var_dump($type_id, '------1--------');
  5923. if ($type_id != 10000) {
  5924. $where[] = ['book.user_id', '=', $user_id];
  5925. }
  5926. var_dump(!empty($data['status1']), '=-===1');
  5927. $result = Book::where($where)
  5928. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  5929. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  5930. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  5931. ->when(isset($data['status1']), function ($query) use ($data) {
  5932. $query->whereIn('book.status', [1, 3]);
  5933. })
  5934. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  5935. ->orderBy("updated_at", "desc")
  5936. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5937. if (empty($result)) {
  5938. return Result::error("暂无数据", 0);
  5939. }
  5940. // 取出数据
  5941. $rows = $result->items();
  5942. $count = $result->total();
  5943. $responseData = [
  5944. 'rows' => $rows,
  5945. 'count' => $count,
  5946. ];
  5947. return Result::success($responseData);
  5948. }
  5949. public function deleteBook(array $data): array
  5950. {
  5951. $result = Book::where('id', $data['id'])->delete();
  5952. if (empty($result)) {
  5953. return Result::error("删除失败", 0);
  5954. }
  5955. return Result::success($result);
  5956. }
  5957. public function updateBook(array $data): array
  5958. {
  5959. // $user_id = $data['user_id'] ?? 0;
  5960. $type_id = $data['type_id'] ?? 0;
  5961. // $website_id = $data['website_id'] ?? 0;
  5962. unset($data['user_id']);
  5963. unset($data['type_id']);
  5964. // unset($data['website_id']);
  5965. //处理数组
  5966. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5967. if ($data['img_url'] == '') {
  5968. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5969. preg_match_all($reg, $data['detail'], $matches);
  5970. if (isset($matches[1][0])) {
  5971. //截取varchar240
  5972. $data['img_url'] = substr($matches[1][0], 0, 240);
  5973. }
  5974. }
  5975. if ($data['keyword'] == '') {
  5976. //提取标题+内容中的关键词
  5977. $data['keyword'] = $data['title'];
  5978. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5979. Jieba::init(); // 初始化 jieba-php
  5980. Finalseg::init();
  5981. $segList = Jieba::cut($data['keyword']);
  5982. $segList1 = array_slice($segList, 0, 8);
  5983. $data['keyword'] = implode(',', $segList1);
  5984. }
  5985. if ($data['description'] == '') {
  5986. //提取内容中的描述
  5987. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5988. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5989. }
  5990. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5991. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5992. if ($data['status'] == 1) {
  5993. $this->sendMessage([
  5994. 'talk_type' => 400,
  5995. 'title' => $data['title'],
  5996. 'content' => '提交了审核',
  5997. 'messageType' => 7,
  5998. ]);
  5999. }
  6000. $result = Book::where("id", $data["id"])->update($data);
  6001. if (empty($result)) {
  6002. return Result::error("更新失败", 0);
  6003. }
  6004. return Result::success($result);
  6005. }
  6006. public function getBookInfo(array $data): array
  6007. {
  6008. $result = Book::where("id", $data["id"])->first();
  6009. if (empty($result)) {
  6010. return Result::error("获取失败", 0);
  6011. }
  6012. return Result::success($result);
  6013. }
  6014. public function updateBookStatus(array $data): array
  6015. {
  6016. //审核
  6017. unset($data['user_id']);
  6018. $bookInfo = Book::where("id", $data["id"])->first();
  6019. var_dump($bookInfo, '----');
  6020. if ($data['status'] == 2) {
  6021. $this->sendMessage([
  6022. 'talk_type' => 401,
  6023. 'title' => $bookInfo['title'],
  6024. 'content' => '审核通过',
  6025. 'messageType' => 7,
  6026. 'user_id' => $bookInfo['user_id'],
  6027. ]);
  6028. }
  6029. if ($data['status'] == 3) {
  6030. $this->sendMessage([
  6031. 'talk_type' => 401,
  6032. 'title' => $bookInfo['title'],
  6033. 'content' => '审核拒绝',
  6034. 'messageType' => 7,
  6035. 'user_id' => $bookInfo['user_id'],
  6036. ]);
  6037. }
  6038. if ($data['status'] == 1) {
  6039. $this->sendMessage([
  6040. 'talk_type' => 400,
  6041. 'title' => $bookInfo['title'],
  6042. 'content' => '提交了审核',
  6043. 'messageType' => 7,
  6044. // 'user_id'=>$bookInfo['user_id'],
  6045. ]);
  6046. }
  6047. $result = Book::where("id", $data["id"])->update($data);
  6048. if (empty($result)) {
  6049. return Result::error("更新失败", 0);
  6050. }
  6051. return Result::success($result);
  6052. }
  6053. //20250422 书刊音像
  6054. /**
  6055. * 贴身宝贝
  6056. * @param array $data
  6057. * @return array
  6058. */
  6059. public function getWebsiteTsbb(array $data): array
  6060. {
  6061. $month = $data['month'] ?? date('m');
  6062. $day = $data['day'] ?? date('d');
  6063. // 使用缓存键
  6064. $cacheKey = "tsbb_data_{$month}_{$day}";
  6065. // 尝试从缓存获取数据
  6066. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6067. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6068. if ($cachedData = $cache->get($cacheKey)) {
  6069. return Result::success(unserialize($cachedData));
  6070. }
  6071. //查询老黄历
  6072. try {
  6073. $date = date('Y-m-d');
  6074. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6075. // 使用 curl 替代 file_get_contents
  6076. $ch = curl_init();
  6077. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6078. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6079. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6080. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6081. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6082. 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');
  6083. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6084. 'Accept: application/json',
  6085. 'Content-Type: application/json',
  6086. 'Referer: https://www.36jxs.com/'
  6087. ]);
  6088. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6089. curl_setopt($ch, CURLOPT_ENCODING, '');
  6090. $almanacResponse = curl_exec($ch);
  6091. var_dump("====:", $almanacResponse);
  6092. if (curl_errno($ch)) {
  6093. var_dump('Curl error:', curl_error($ch));
  6094. throw new \Exception('Curl error: ' . curl_error($ch));
  6095. }
  6096. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6097. curl_close($ch);
  6098. if ($almanacResponse === false) {
  6099. throw new \Exception('Failed to fetch almanac data');
  6100. }
  6101. $almanacData = json_decode($almanacResponse, true);
  6102. if (json_last_error() !== JSON_ERROR_NONE) {
  6103. throw new \Exception('Failed to parse almanac data');
  6104. }
  6105. $almanacInfo = $almanacData['data'] ?? [];
  6106. } catch (\Exception $e) {
  6107. var_dump('Exception:', $e->getMessage());
  6108. $almanacInfo = [];
  6109. }
  6110. // 获取历史上的今天数据
  6111. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6112. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6113. ->orderBy('year', 'asc')
  6114. ->select("title", "id", "year", DB::raw('1 as type'))
  6115. ->limit(16)
  6116. ->get();
  6117. // 获取节日数据 - 从今天开始获取未来4条
  6118. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6119. ->orderBy('showtime', 'asc')
  6120. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6121. ->limit(16)
  6122. ->get();
  6123. //说文解字
  6124. $chartacterList = Character::orderBy('updated_at', 'desc')
  6125. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6126. ->limit(6)
  6127. ->get();
  6128. //谜语沙龙
  6129. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6130. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6131. ->limit(4)
  6132. ->get();
  6133. //成语欣赏
  6134. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6135. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6136. ->limit(32)
  6137. ->get();
  6138. //名联赏析
  6139. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6140. ->select("id", "first", "second", DB::raw('6 as type'))
  6141. ->limit(6)
  6142. ->get();
  6143. // 获取分类文章数据
  6144. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6145. ->pluck('category_id')
  6146. ->toArray();
  6147. $articlesList = [];
  6148. foreach ($categoryIds as $catid) {
  6149. // 先查有图片的
  6150. $withImg = DB::table('article')
  6151. ->where('status', 1)
  6152. ->where('catid', $catid)
  6153. ->whereNotNull('imgurl')
  6154. ->where('imgurl', '!=', '')
  6155. ->orderBy('updated_at', 'desc')
  6156. ->limit(6)
  6157. ->get();
  6158. $count = $withImg->count();
  6159. if ($count < 6) {
  6160. // 不足6条再查无图片的补足
  6161. $withoutImg = DB::table('article')
  6162. ->where('status', 1)
  6163. ->where('catid', $catid)
  6164. ->where(function ($q) {
  6165. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6166. })
  6167. ->orderBy('updated_at', 'desc')
  6168. ->limit(6 - $count)
  6169. ->get();
  6170. $articles = $withImg->concat($withoutImg);
  6171. } else {
  6172. $articles = $withImg;
  6173. }
  6174. // 组装
  6175. $category = \App\Model\Category::find($catid);
  6176. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6177. $articlesList[] = [
  6178. 'category_name' => $category ? $category->name : '',
  6179. 'catid' => $catid,
  6180. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6181. 'type' => 100,
  6182. 'list' => $articles->map(function ($item) {
  6183. return [
  6184. 'id' => $item->id,
  6185. 'title' => $item->title,
  6186. 'imgurl' => $item->imgurl,
  6187. 'created_at' => $item->created_at
  6188. ];
  6189. })->values()
  6190. ];
  6191. }
  6192. $result = [
  6193. 'almanac' => $almanacInfo,
  6194. 'historyTodayList' => [
  6195. 'category_name' => '历史上的今天',
  6196. 'list' => $historyTodayList,
  6197. 'type' => 1
  6198. ],
  6199. 'festivalList' => [
  6200. 'category_name' => '节日预告',
  6201. 'list' => $festivalList,
  6202. 'type' => 2
  6203. ],
  6204. 'chartacterList' => [
  6205. 'category_name' => '说文解字',
  6206. 'list' => $chartacterList,
  6207. 'type' => 3
  6208. ],
  6209. 'coupletList' => [
  6210. 'category_name' => '名联赏析',
  6211. 'list' => $coupletList,
  6212. 'type' => 6
  6213. ],
  6214. 'riddletList' => [
  6215. 'category_name' => '谜语沙龙',
  6216. 'list' => $riddletList,
  6217. 'type' => 4
  6218. ],
  6219. 'idiomList' => [
  6220. 'category_name' => '成语欣赏',
  6221. 'list' => $idiomList,
  6222. 'type' => 5
  6223. ],
  6224. 'articlesList' => $articlesList
  6225. ];
  6226. // 缓存结果,设置1小时过期
  6227. $cache->set($cacheKey, serialize($result), 3600);
  6228. return Result::success($result);
  6229. }
  6230. /**
  6231. * 获取资讯列表
  6232. */
  6233. public function getWebsiteTsbbList(array $data): array
  6234. {
  6235. $page = $data['page'] ?? 1;
  6236. $pageSize = $data['pageSize'] ?? 10;
  6237. // 如果没有传入月份和日期,则使用今天的日期
  6238. $month = $data['month'] ?? date('m');
  6239. $day = $data['day'] ?? date('d');
  6240. $total = 0;
  6241. $result = [];
  6242. $data['type'] = intval($data['type']);
  6243. var_dump("接收参数:", $data);
  6244. switch ($data['type']) {
  6245. case 1:
  6246. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6247. // 当前月份之后的数据
  6248. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6249. // 或者当前月份且日期大于等于当前日期的数据
  6250. ->orWhere(function ($q) use ($month, $day) {
  6251. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6252. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6253. });
  6254. })
  6255. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6256. $total = $query->count();
  6257. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6258. ->offset(($page - 1) * $pageSize)
  6259. ->limit($pageSize)
  6260. ->get();
  6261. break;
  6262. case 2:
  6263. $query = Festival::where(function ($q) use ($month, $day) {
  6264. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6265. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6266. ->orWhere(function ($q) use ($month, $day) {
  6267. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6268. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6269. });
  6270. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6271. $total = $query->count();
  6272. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6273. ->offset(($page - 1) * $pageSize)
  6274. ->limit($pageSize)
  6275. ->get();
  6276. break;
  6277. case 3:
  6278. $query = Character::orderBy("updated_at", "desc");
  6279. $total = $query->count();
  6280. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6281. ->offset(($page - 1) * $pageSize)
  6282. ->limit($pageSize)
  6283. ->get();
  6284. break;
  6285. case 4:
  6286. $query = Riddle::orderBy("updated_at", "desc");
  6287. $total = $query->count();
  6288. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6289. ->offset(($page - 1) * $pageSize)
  6290. ->limit($pageSize)
  6291. ->get();
  6292. break;
  6293. case 5:
  6294. $query = Idiom::orderBy("updated_at", "desc");
  6295. $total = $query->count();
  6296. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6297. ->offset(($page - 1) * $pageSize)
  6298. ->limit($pageSize)
  6299. ->get();
  6300. break;
  6301. case 6:
  6302. $query = Couplet::orderBy("updated_at", "desc");
  6303. $total = $query->count();
  6304. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6305. ->offset(($page - 1) * $pageSize)
  6306. ->limit($pageSize)
  6307. ->get();
  6308. break;
  6309. default:
  6310. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6311. $total = $query->count();
  6312. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6313. ->offset(($page - 1) * $pageSize)
  6314. ->limit($pageSize)
  6315. ->get();
  6316. }
  6317. return Result::success([
  6318. 'list' => $result,
  6319. 'total' => $total,
  6320. 'page' => (int)$page,
  6321. 'pageSize' => (int)$pageSize,
  6322. 'month' => $month,
  6323. 'day' => $day
  6324. ]);
  6325. }
  6326. /**
  6327. * 1:历史上的今天
  6328. * 2:节日
  6329. * 3:文章
  6330. *
  6331. * 资讯详情信息
  6332. */
  6333. public function getWebsiteTsbbDetail(array $data): array
  6334. {
  6335. $data['type'] = intval($data['type']);
  6336. switch ($data['type']) {
  6337. case 1:
  6338. $result = HistoryToday::where("id", $data['id'])->first();
  6339. break;
  6340. case 2:
  6341. $result = Festival::where("id", $data['id'])->first();
  6342. break;
  6343. case 3:
  6344. $result = Character::where("id", $data['id'])->first();
  6345. break;
  6346. case 4:
  6347. $result = Riddle::where("id", $data['id'])->first();
  6348. break;
  6349. case 5:
  6350. $result = Idiom::where("id", $data['id'])->first();
  6351. break;
  6352. case 6:
  6353. $result = Couplet::where("id", $data['id'])->first();
  6354. break;
  6355. default:
  6356. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6357. break;
  6358. }
  6359. return Result::success($result);
  6360. }
  6361. /**
  6362. * 农网导航首页数据
  6363. */
  6364. public function getWebsiteNwHomeList(array $data): array
  6365. {
  6366. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6367. ->pluck('category_id')
  6368. ->toArray();
  6369. // 使用子查询优化
  6370. $articlesList = DB::table('article')
  6371. ->select([
  6372. 'article.id',
  6373. 'article.title',
  6374. 'article.imgurl',
  6375. 'article.created_at',
  6376. 'category.name as category_name',
  6377. 'category.id as category_id',
  6378. 'website_category.aLIas_pinyin as pinyin',
  6379. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6380. DB::raw('100 as type')
  6381. ])
  6382. ->join('category', 'article.catid', '=', 'category.id')
  6383. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6384. ->leftJoin('website_category as parent_wc', function ($join) {
  6385. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6386. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6387. })
  6388. ->where('website_category.website_id', $data['website_id'])
  6389. ->where('article.status', 1)
  6390. ->whereIn('category.id', $categoryIds)
  6391. ->orderBy('article.created_at', 'desc')
  6392. ->get()
  6393. ->groupBy('category_id')
  6394. ->map(function ($group) {
  6395. // 确保第一条数据有图片
  6396. $firstWithImage = $group->first(function ($item) {
  6397. return !empty($item->imgurl);
  6398. });
  6399. if ($firstWithImage) {
  6400. // 如果有带图片的文章,将其放在第一位
  6401. $group = $group->filter(function ($item) use ($firstWithImage) {
  6402. return $item->id !== $firstWithImage->id;
  6403. })->prepend($firstWithImage);
  6404. }
  6405. return [
  6406. 'category_name' => $group->first()->category_name,
  6407. 'catid' => $group->first()->category_id,
  6408. 'pinyin' => $group->first()->pinyin,
  6409. 'parent_pinyin' => $group->first()->parent_pinyin,
  6410. 'list' => $group->take(4)->map(function ($item) {
  6411. return [
  6412. 'id' => $item->id,
  6413. 'title' => $item->title,
  6414. ];
  6415. })->values()
  6416. ];
  6417. })
  6418. ->values()
  6419. ->toArray();
  6420. return Result::success($articlesList);
  6421. }
  6422. /**
  6423. * 企业管理
  6424. * @param array $data
  6425. * @return array
  6426. */
  6427. public function getCompanyList(array $data): array
  6428. {
  6429. // return Result::success($data);
  6430. $where = [];
  6431. $user = User::where('id', $data['user_id'])->first();
  6432. if (empty($user)) {
  6433. return Result::error('用户不存在!');
  6434. }
  6435. if ($user['type_id'] != 10000) {
  6436. $where['user_id'] = $data['user_id'];
  6437. }
  6438. if (isset($data['title']) && !empty($data['title'])) {
  6439. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6440. }
  6441. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6442. array_push($where, ['website.id', $data['website_id']]);
  6443. }
  6444. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6445. if ($data['ischeck'] == 1) {
  6446. if (isset($data['status']) && $data['status'] != '') {
  6447. array_push($where, ['company.status', $data['status']]);
  6448. $query = Company::where($where);
  6449. } else {
  6450. $query = Company::whereIn('company.status', [0, 2]);
  6451. }
  6452. } else {
  6453. $query = Company::where('company.status', 1);
  6454. }
  6455. }
  6456. $result = $query->where($where)
  6457. ->leftJoin('website_category', function ($query) {
  6458. $query->on('website_category.category_id', '=', 'company.category_id')
  6459. ->on('website_category.website_id', '=', 'company.website_id');
  6460. })
  6461. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6462. ->select(
  6463. 'company.id',
  6464. 'company.title',
  6465. 'company.website_id',
  6466. 'company.category_id',
  6467. 'website.website_name',
  6468. 'website_category.alias as category_name',
  6469. 'company.status',
  6470. 'company.updated_at',
  6471. 'company.user_id'
  6472. )
  6473. ->orderBy('company.updated_at', 'desc')
  6474. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6475. if ($result->isEmpty()) {
  6476. return Result::error("暂无企业", 0);
  6477. }
  6478. return Result::success($result);
  6479. }
  6480. /**
  6481. * 添加企业
  6482. * @param array $data
  6483. * @return array
  6484. */
  6485. public function addCompany(array $data): array
  6486. {
  6487. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  6488. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6489. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6490. $data['cat_arr_id'] = json_encode($car_arr_id);
  6491. } else {
  6492. $data['cat_arr_id'] = '';
  6493. }
  6494. if ($data['imgurl'] == '') {
  6495. //content中提取图片第一个图,正则提取
  6496. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6497. preg_match_all($reg, $data['content'], $matches);
  6498. if (isset($matches[1][0])) {
  6499. //截取varchar240
  6500. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6501. }
  6502. }
  6503. if ($data['keyword'] == '') {
  6504. //提取标题+内容中的关键词
  6505. $data['keyword'] = $data['title'];
  6506. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6507. Jieba::init(); // 初始化 jieba-php
  6508. Finalseg::init();
  6509. $segList = Jieba::cut($data['keyword']);
  6510. $segList1 = array_slice($segList, 0, 8);
  6511. $data['keyword'] = implode(',', $segList1);
  6512. }
  6513. if ($data['introduce'] == '' || empty($data['introduce'])) {
  6514. //提取内容中的描述
  6515. $content = $data['content'];
  6516. // 去除 <style> 和 <script> 标签及其内容
  6517. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6518. // 去除所有 HTML 标签
  6519. $content = strip_tags($content);
  6520. // 去除 HTML 实体
  6521. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6522. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6523. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6524. // 去除多余空白
  6525. $content = preg_replace('/\s+/u', '', $content);
  6526. // 截取 100 个字符
  6527. $data['introduce'] = mb_substr($content, 0, 100);
  6528. }
  6529. $user = User::where('id', $data['user_id'])->first();
  6530. if (empty($user)) {
  6531. return Result::error('用户不存在!');
  6532. }
  6533. if ($user['type_id'] == 10000) {
  6534. $data['status'] = 1;
  6535. }
  6536. if (isset($data['level']) && $data['level'] != null) {
  6537. $data['level'] = intval($data['level']);
  6538. } else {
  6539. $data['level'] = null;
  6540. }
  6541. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6542. $this->sendMessage([
  6543. 'talk_type' => 900,
  6544. 'title' => $data['title'],
  6545. 'content' => '提交了审核',
  6546. 'messageType' => 8,
  6547. ]);
  6548. }
  6549. $result = Company::insertGetId($data);
  6550. if ($result) {
  6551. return Result::success($result);
  6552. } else {
  6553. return Result::error('添加失败');
  6554. }
  6555. }
  6556. /**
  6557. * 更新企业
  6558. * @param array $data
  6559. * @return array
  6560. */
  6561. public function upCompany(array $data): array
  6562. {
  6563. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6564. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6565. $data['cat_arr_id'] = json_encode($car_arr_id);
  6566. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  6567. } else {
  6568. $data['cat_arr_id'] = '';
  6569. }
  6570. if ($data['imgurl'] == '') {
  6571. //content中提取图片第一个图,正则提取
  6572. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6573. preg_match_all($reg, $data['content'], $matches);
  6574. if (isset($matches[1][0])) {
  6575. //截取varchar
  6576. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6577. }
  6578. }
  6579. if ($data['keyword'] == '') {
  6580. //提取标题+内容中的关键词
  6581. $data['keyword'] = $data['title'];
  6582. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6583. Jieba::init(); // 初始化 jieba-php
  6584. Finalseg::init();
  6585. $segList = Jieba::cut($data['keyword']);
  6586. $segList1 = array_slice($segList, 0, 8);
  6587. $data['keyword'] = implode(',', $segList1);
  6588. }
  6589. if ($data['introduce'] == '') {
  6590. //提取内容中的描述
  6591. $content = $data['content'];
  6592. // 去除 <style> 和 <script> 标签及其内容
  6593. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6594. // 去除所有 HTML 标签
  6595. $content = strip_tags($content);
  6596. // 去除 HTML 实体
  6597. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6598. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6599. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6600. // 去除多余空白
  6601. $content = preg_replace('/\s+/u', '', $content);
  6602. // 截取 100 个字符
  6603. $data['introduce'] = mb_substr($content, 0, 100);
  6604. }
  6605. if (isset($data['level']) && $data['level'] != null) {
  6606. $data['level'] = intval($data['level']);
  6607. } else {
  6608. $data['level'] = null;
  6609. }
  6610. $user = User::where('id', $data['user_id'])->first();
  6611. if (empty($user)) {
  6612. return Result::error('用户不存在!');
  6613. }
  6614. if ($user['type_id'] == 10000) {
  6615. $data['status'] = 1;
  6616. } else {
  6617. $data['status'] = 0;
  6618. }
  6619. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6620. $this->sendMessage([
  6621. 'talk_type' => 900,
  6622. 'title' => $data['title'],
  6623. 'content' => '提交了审核',
  6624. 'messageType' => 8,
  6625. ]);
  6626. }
  6627. $result = Company::where('id', $data['id'])->update($data);
  6628. if ($result) {
  6629. return Result::success($result);
  6630. } else {
  6631. return Result::error('修改失败');
  6632. }
  6633. }
  6634. /**
  6635. * 删除企业
  6636. * @param array $data
  6637. * @return array
  6638. */
  6639. public function delCompany(array $data): array
  6640. {
  6641. $result = Company::where('id', $data['id'])->delete();
  6642. if ($result) {
  6643. return Result::success($result);
  6644. } else {
  6645. return Result::error('删除失败');
  6646. }
  6647. }
  6648. /**
  6649. * 审核企业
  6650. * @param array $data
  6651. * @return array
  6652. */
  6653. public function checkCompany(array $data): array
  6654. {
  6655. $user = User::where('id', $data['user_id'])->first();
  6656. if (empty($user)) {
  6657. return Result::error('用户不存在!');
  6658. }
  6659. $company = Company::where('id', $data['id'])->first();
  6660. if (empty($company)) {
  6661. return Result::error('企业不存在!');
  6662. }
  6663. // 状态:0:未审核 1:已审核 2:已拒绝
  6664. if ($data['status'] == 2 || $data['status'] == '2') {
  6665. $this->sendMessage([
  6666. 'talk_type' => 901,
  6667. 'title' => $company['title'],
  6668. 'content' => '审核拒绝',
  6669. 'messageType' => 8,
  6670. 'user_id' => $company['user_id'],
  6671. ]);
  6672. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  6673. } else {
  6674. if ($data['status'] == 1) {
  6675. $this->sendMessage([
  6676. 'talk_type' => 901,
  6677. 'title' => $company['title'],
  6678. 'content' => '审核通过',
  6679. 'messageType' => 8,
  6680. 'user_id' => $company['user_id'],
  6681. ]);
  6682. } else if ($data['status'] == 0) {
  6683. $this->sendMessage([
  6684. 'talk_type' => 900,
  6685. 'title' => $company['title'],
  6686. 'content' => '提交了审核',
  6687. 'messageType' => 8,
  6688. ]);
  6689. }
  6690. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  6691. }
  6692. if (empty($result)) {
  6693. return Result::error('审核失败!');
  6694. } else {
  6695. return Result::success($result);
  6696. }
  6697. }
  6698. /**
  6699. * 获取企业信息
  6700. * @param array $data
  6701. * @return array
  6702. */
  6703. public function getCompanyInfo(array $data): array
  6704. {
  6705. $result = Company::where('id', $data['id'])->first();
  6706. $city_arr = json_decode($result['city_arr_id']);
  6707. $result['city_name'] = District::whereIn('id', $city_arr)
  6708. ->pluck('name')
  6709. ->implode('-');
  6710. if (empty($result)) {
  6711. return Result::error('企业不存在!');
  6712. } else {
  6713. return Result::success($result);
  6714. }
  6715. }
  6716. /**
  6717. * @param array $data
  6718. * @return array
  6719. */
  6720. public function getWebsiteCompany(array $data): array
  6721. {
  6722. $categorys = json_decode($data['id'], true);
  6723. $category_arr = $this->processArticlePro($data['website_id']);
  6724. $cat_1st_arr = $category_arr['cat_1st_arr'];
  6725. $catiall = $category_arr['catiall'];
  6726. $categoryIds = $category_arr['categoryIds'];
  6727. // return Result::success($category_arr);
  6728. foreach ($categorys as $key => $value) {
  6729. if (array_key_exists('level', $value)) {
  6730. $parts = explode(',', $value['level']);
  6731. $level = $parts[0] ?? null;
  6732. $imgnum = $parts[1] ?? null;
  6733. $textnum = $parts[2] ?? null;
  6734. if (!empty($textnum) && $textnum > 0) {
  6735. $text_num = Company::where('level', $level)
  6736. ->whereIn('category_id', $categoryIds)
  6737. ->where('status', 1)
  6738. ->select(
  6739. 'company.id',
  6740. 'company.title',
  6741. 'company.description',
  6742. 'company.updated_at',
  6743. 'company.category_id',
  6744. 'company.cat_arr_id'
  6745. )
  6746. ->orderBy('updated_at', 'desc')
  6747. ->limit($textnum)
  6748. ->get()->all();
  6749. }
  6750. if (!empty($imgnum) && $imgnum > 0) {
  6751. $img_num = Company::where('level', $level)
  6752. ->whereIn('category_id', $categoryIds)
  6753. ->where('status', 1)
  6754. ->where('imgurl', '!=', '')
  6755. ->whereNotNull('imgurl')
  6756. ->select(
  6757. 'company.id',
  6758. 'company.title',
  6759. 'company.description',
  6760. 'company.updated_at',
  6761. 'company.imgurl as imgs',
  6762. 'company.category_id',
  6763. 'company.cat_arr_id'
  6764. )
  6765. ->orderBy('updated_at', 'desc')
  6766. ->limit($imgnum)
  6767. ->get()->all();
  6768. }
  6769. }
  6770. if (array_key_exists('id', $value)) {
  6771. $parts = explode(',', $value['id']);
  6772. $category_id = $parts[0] ?? null;
  6773. $imgnum = $parts[1] ?? null;
  6774. $textnum = $parts[2] ?? null;
  6775. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  6776. if (!empty($textnum) && $textnum > 0) {
  6777. $text_num = Company::whereIn('category_id', $category_arr)
  6778. // ->where('website_id', $data['website_id'])
  6779. ->where('status', 1)
  6780. ->select(
  6781. 'company.id',
  6782. 'company.title',
  6783. 'company.description',
  6784. 'company.updated_at',
  6785. 'company.category_id',
  6786. 'company.cat_arr_id'
  6787. )
  6788. ->orderBy('updated_at', 'desc')
  6789. ->limit($textnum)
  6790. ->get()->all();
  6791. }
  6792. if (!empty($imgnum) && $imgnum > 0) {
  6793. $img_num = Company::whereIn('category_id', $category_arr)
  6794. // ->where('website_id', $data['website_id'])
  6795. ->where('status', 1)
  6796. ->where('imgurl', '!=', '')
  6797. ->whereNotNull('imgurl')
  6798. ->select(
  6799. 'company.id',
  6800. 'company.title',
  6801. 'company.description',
  6802. 'company.updated_at',
  6803. 'company.imgurl as imgs',
  6804. 'company.category_id',
  6805. 'company.cat_arr_id'
  6806. )
  6807. ->orderBy('updated_at', 'desc')
  6808. ->limit($imgnum)
  6809. ->get()->all();
  6810. }
  6811. }
  6812. if (!empty($text_num)) {
  6813. foreach ($text_num as $k => $v) {
  6814. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6815. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6816. }
  6817. }
  6818. if (!empty($img_num)) {
  6819. foreach ($img_num as $k => $v) {
  6820. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6821. $imgurl = json_decode($v['imgs'], true);
  6822. if (!empty($imgurl)) {
  6823. $img_num[$k]->imgurl = $imgurl[0];
  6824. }
  6825. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6826. }
  6827. }
  6828. $company[$key]['img_num'] = $img_num ?? [];
  6829. $company[$key]['text_num'] = $text_num ?? [];
  6830. }
  6831. if (empty($company)) {
  6832. return Result::error("暂无相关企业信息", 0);
  6833. }
  6834. return Result::success($company);
  6835. }
  6836. /**
  6837. * @param array $data
  6838. * @return array
  6839. */
  6840. public function getWebsiteCompanyList(array $data): array
  6841. {
  6842. $where['website_id'] = $data['website_id'];
  6843. $where['status'] = 1;
  6844. $categoryIds = [];
  6845. if (isset($data['category_id']) && !empty($data['category_id'])) {
  6846. $category_id = $data['category_id'];
  6847. }
  6848. $category_arr = $this->processArticlePro($data['website_id']);
  6849. $categoryIds = $category_arr['categoryIds'];
  6850. // return Result::success($cat_1st_arr);
  6851. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  6852. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  6853. })
  6854. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  6855. $query->whereIn('category_id', $categoryIds);
  6856. })
  6857. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  6858. $query->where('category_id', $category_id);
  6859. })
  6860. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  6861. ->orderBy('updated_at', 'desc')
  6862. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6863. if (empty($company)) {
  6864. return Result::error("暂无相关公司信息", 0);
  6865. }
  6866. $result = [
  6867. 'count' => $company->total(),
  6868. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  6869. ];
  6870. return Result::success($result);
  6871. }
  6872. /**
  6873. * 获取项目列表
  6874. * @param array $data
  6875. * @return array
  6876. */
  6877. public function getProjectList(array $data): array
  6878. {
  6879. $where = [];
  6880. $user = User::where('id', $data['user_id'])->first();
  6881. if (empty($user)) {
  6882. return Result::error('用户不存在!');
  6883. }
  6884. if ($user->type_id != 10000) {
  6885. array_push($where, ['project.user_id', $data['user_id']]);
  6886. }
  6887. $query = Project::query();
  6888. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6889. array_push($where, ['project.website_id', $data['website_id']]);
  6890. }
  6891. if (isset($data['title']) && !empty($data['title'])) {
  6892. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  6893. }
  6894. if ($data['status'] != 3) {
  6895. array_push($where, ['project.status', $data['status']]);
  6896. }
  6897. $query = Project::where($where)
  6898. ->when($data['status'] == 3, function ($query) {
  6899. $query->whereIn('project.status', [0, 2]);
  6900. });
  6901. $count = $query->clone()
  6902. ->count();
  6903. $rows = $query->clone()
  6904. ->leftJoin('website', 'project.website_id', 'website.id')
  6905. ->leftJoin('website_category', function ($join) {
  6906. $join->on('project.website_id', '=', 'website_category.website_id')
  6907. ->on('project.category_id', '=', 'website_category.category_id');
  6908. })
  6909. ->select(
  6910. 'project.id',
  6911. 'project.title',
  6912. 'project.updated_at',
  6913. 'project.status',
  6914. 'website.website_name',
  6915. 'website_category.alias as category_name',
  6916. 'project.website_id',
  6917. 'project.user_id'
  6918. )
  6919. ->orderBy('project.updated_at', 'desc')
  6920. ->offset(($data['page'] - 1) * $data['pageSize'])
  6921. ->limit($data['pageSize'])
  6922. ->get();
  6923. if ($rows->isEmpty()) {
  6924. return Result::error("暂无相关项目信息", 0);
  6925. }
  6926. $result = [
  6927. 'count' => $count,
  6928. 'rows' => $rows,
  6929. ];
  6930. return Result::success($result);
  6931. }
  6932. /**
  6933. * 添加项目
  6934. * @param array $data
  6935. * @return array
  6936. */
  6937. public function addProject(array $data): array
  6938. {
  6939. $user = User::where('id', $data['user_id'])->first();
  6940. if (empty($user)) {
  6941. return Result::error("暂无相关用户信息", 0);
  6942. }
  6943. if ($user->type_id == 10000) {
  6944. $data['status'] = 1;
  6945. } else {
  6946. $data['status'] = 0;
  6947. }
  6948. if ($data['keyword'] == '') {
  6949. //提取标题+内容中的关键词
  6950. $data['keyword'] = $data['title'];
  6951. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6952. Jieba::init(); // 初始化 jieba-php
  6953. Finalseg::init();
  6954. $segList = Jieba::cut($data['keyword']);
  6955. $segList1 = array_slice($segList, 0, 8);
  6956. $data['keyword'] = implode(',', $segList1);
  6957. }
  6958. if ($data['description'] == '') {
  6959. //提取内容中的描述
  6960. // var_dump(11111);
  6961. //提取内容中的描述
  6962. $content = $data['introduce'];
  6963. // 去除 <style> 和 <script> 标签及其内容
  6964. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6965. // 去除所有 HTML 标签
  6966. $content = strip_tags($content);
  6967. // 去除 HTML 实体
  6968. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6969. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6970. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6971. // 去除多余空白
  6972. $content = preg_replace('/\s+/u', '', $content);
  6973. // 截取 100 个字符
  6974. $data['description'] = mb_substr($content, 0, 100);
  6975. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  6976. }
  6977. if ($data['status'] == 0) {
  6978. $this->sendMessage([
  6979. 'talk_type' => 1000,
  6980. 'title' => $data['title'],
  6981. 'content' => '提交了审核',
  6982. 'messageType' => 9,
  6983. ]);
  6984. }
  6985. $project = Project::insertGetId($data);
  6986. if (empty($project)) {
  6987. return Result::error("暂无相关项目信息", 0);
  6988. }
  6989. return Result::success($project);
  6990. }
  6991. /**
  6992. * 更新项目
  6993. * @param array $data
  6994. * @return array
  6995. */
  6996. public function upProject(array $data): array
  6997. {
  6998. $project = Project::where('id', $data['id'])->first();
  6999. if (empty($project)) {
  7000. return Result::error("暂无相关项目信息", 0);
  7001. }
  7002. $id = $data['id'];
  7003. unset($data['id']);
  7004. $user = User::where('id', $data['user_id'])->first();
  7005. if (empty($user)) {
  7006. return Result::error("暂无相关用户信息", 0);
  7007. }
  7008. if ($user->type_id == 10000) {
  7009. $data['status'] = 1;
  7010. } else {
  7011. $data['status'] = 0;
  7012. }
  7013. unset($data['user_id']);
  7014. if ($data['keyword'] == '') {
  7015. //提取标题+内容中的关键词
  7016. $data['keyword'] = $data['title'];
  7017. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7018. Jieba::init(); // 初始化 jieba-php
  7019. Finalseg::init();
  7020. $segList = Jieba::cut($data['keyword']);
  7021. $segList1 = array_slice($segList, 0, 8);
  7022. $data['keyword'] = implode(',', $segList1);
  7023. }
  7024. if ($data['description'] == '') {
  7025. //提取内容中的描述
  7026. // var_dump(11111);
  7027. //提取内容中的描述
  7028. $content = $data['introduce'];
  7029. // 去除 <style> 和 <script> 标签及其内容
  7030. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7031. // 去除所有 HTML 标签
  7032. $content = strip_tags($content);
  7033. // 去除 HTML 实体
  7034. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7035. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7036. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7037. // 去除多余空白
  7038. $content = preg_replace('/\s+/u', '', $content);
  7039. // 截取 100 个字符
  7040. $data['description'] = mb_substr($content, 0, 100);
  7041. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7042. }
  7043. if ($data['status'] == 0) {
  7044. $this->sendMessage([
  7045. 'talk_type' => 1000,
  7046. 'title' => $data['title'],
  7047. 'content' => '提交了审核',
  7048. 'messageType' => 9,
  7049. ]);
  7050. }
  7051. $result = Project::where('id', $id)->update($data);
  7052. if (empty($result)) {
  7053. return Result::error("更新失败", 0);
  7054. }
  7055. return Result::success($result);
  7056. }
  7057. /**
  7058. * 删除项目
  7059. * @param array $data
  7060. * @return array
  7061. */
  7062. public function delProject(array $data): array
  7063. {
  7064. $user = User::where('id', $data['user_id'])->first();
  7065. if (empty($user)) {
  7066. return Result::error("暂无相关用户信息", 0);
  7067. }
  7068. $project = Project::where('id', $data['id'])->first();
  7069. if (empty($project)) {
  7070. return Result::error("暂无相关项目信息", 0);
  7071. }
  7072. $result = Project::where('id', $data['id'])->delete();
  7073. if (empty($result)) {
  7074. return Result::error("删除失败", 0);
  7075. }
  7076. return Result::success($result);
  7077. }
  7078. /**
  7079. * 审核项目
  7080. * @param array $data
  7081. * @return array
  7082. */
  7083. public function checkProject(array $data): array
  7084. {
  7085. $user = User::where('id', $data['user_id'])->first();
  7086. if (empty($user)) {
  7087. return Result::error("暂无相关用户信息", 0);
  7088. }
  7089. // 0:未审核; 1:已审核; 2:已拒绝;
  7090. if ($user->type_id != 10000) {
  7091. if ($data['status'] == 1 || $data['status'] == 2) {
  7092. return Result::error("此用户权限不足", 0);
  7093. }
  7094. }
  7095. $project = Project::where('id', $data['id'])->first();
  7096. if (empty($project)) {
  7097. return Result::error("暂无相关项目信息", 0);
  7098. }
  7099. if ($data['status'] == 2) {
  7100. $this->sendMessage([
  7101. 'talk_type' => 1001,
  7102. 'title' => $project['title'],
  7103. 'content' => '审核拒绝',
  7104. 'messageType' => 9,
  7105. 'user_id' => $project['user_id'],
  7106. ]);
  7107. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7108. } else {
  7109. if ($data['status'] == 1) {
  7110. $this->sendMessage([
  7111. 'talk_type' => 1001,
  7112. 'title' => $project['title'],
  7113. 'content' => '审核通过',
  7114. 'messageType' => 9,
  7115. 'user_id' => $project['user_id'],
  7116. ]);
  7117. } else if ($data['status'] == 0) {
  7118. $this->sendMessage([
  7119. 'talk_type' => 1000,
  7120. 'title' => $project['title'],
  7121. 'content' => '提交了审核',
  7122. 'messageType' => 9,
  7123. ]);
  7124. }
  7125. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7126. }
  7127. if (empty($result)) {
  7128. return Result::error("审核失败", 0);
  7129. }
  7130. return Result::success($result);
  7131. }
  7132. /**
  7133. * 获取项目详情
  7134. * @param array $data
  7135. * @return array
  7136. */
  7137. public function getProjectInfo(array $data): array
  7138. {
  7139. $project = Project::where('id', $data['id'])->first();
  7140. if (empty($project)) {
  7141. return Result::error("暂无相关项目信息", 0);
  7142. }
  7143. return Result::success($project);
  7144. }
  7145. public function getWebsiteCompanyInfo(array $data): array
  7146. {
  7147. $company = Company::where('id', $data['id'])
  7148. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7149. ->where('status', 1)
  7150. // ->where('website_id', $data['website_id'])
  7151. ->select('company.*', 'job_industry.hyname as hy_name')
  7152. ->first();
  7153. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7154. switch ($company->jobnature_id) {
  7155. case null:
  7156. $company->jobnature_name = '';
  7157. break;
  7158. case 0:
  7159. $company->jobnature_name = '市场监督';
  7160. break;
  7161. case 1:
  7162. $company->jobnature_name = '信访纪检';
  7163. break;
  7164. case 2:
  7165. $company->jobnature_name = '公检法司';
  7166. break;
  7167. case 3:
  7168. $company->jobnature_name = '高关注机构';
  7169. break;
  7170. default:
  7171. $company->jobnature_name = '';
  7172. break;
  7173. }
  7174. $city_arr = $company->city_arr_id;
  7175. if (!empty($city_arr)) {
  7176. $city_arr = json_decode($city_arr, true);
  7177. $cityNames = District::whereIn('id', $city_arr)
  7178. ->pluck('name')
  7179. ->implode('-');
  7180. $company->city_name = $cityNames;
  7181. } else {
  7182. $company->city_name = '';
  7183. }
  7184. if (empty($company)) {
  7185. return Result::error("暂无相关公司信息", 0);
  7186. }
  7187. return Result::success($company);
  7188. }
  7189. public function getMSG(array $data): array
  7190. {
  7191. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7192. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7193. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7194. $result = [];
  7195. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7196. //最近的5篇已审的文章
  7197. $apply_articale = Article::where('status', 1)
  7198. ->where('admin_user_id', $user_id)
  7199. ->orderBy('updated_at', 'desc')
  7200. // ->limit(5)
  7201. ->get();
  7202. //获取5条用户的已审核商品
  7203. $good = Good::where('status', 2)
  7204. ->where('user_id', $user_id)
  7205. ->orderBy('updated_at', 'desc')
  7206. // ->limit(5)
  7207. ->get();
  7208. //获取5条用户待审核的公告
  7209. $notice = Notice::where('status', 2)
  7210. ->where('user_id', $user_id)
  7211. ->orderBy('updated_at', 'desc')
  7212. ->limit(5)->get();
  7213. //获取5条用户的待审核投诉
  7214. $complaint = Complaint::where('status', 2)
  7215. ->where('user_id', $user_id)
  7216. ->orderBy('updated_at', 'desc')
  7217. // ->limit(5)
  7218. ->get();
  7219. //获取5条用户的book
  7220. $book = Book::where('status', 2)
  7221. ->where('user_id', $user_id)
  7222. ->orderBy('updated_at', 'desc')
  7223. // ->limit(5)
  7224. ->get();
  7225. //获取5条用户的求职
  7226. //获取5条用户的求职 1
  7227. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7228. ->where('job_hunting.user_id', $user_id)
  7229. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7230. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7231. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7232. ->orderBy('updated_at', 'desc')
  7233. // ->limit(5)
  7234. ->get();
  7235. //获取5条用户的求职 2
  7236. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7237. ->where('job_recruiting.user_id', $user_id)
  7238. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7239. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7240. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7241. ->orderBy('updated_at', 'desc')
  7242. // ->limit(5)
  7243. ->get();
  7244. //人才库 1
  7245. $job_apply = JobApply::where('job_apply.status', 1)
  7246. ->where('job_apply.receiver_id', $user_id)
  7247. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7248. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7249. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7250. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7251. ->select('job_recruiting', 'job_recruiting.', '', '')
  7252. ->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')
  7253. ->orderBy('updated_at', 'desc')
  7254. // ->limit(5)
  7255. ->get();
  7256. // 职场机会 2
  7257. $job_resume = JobResume::where('job_resume.status', 1)
  7258. ->where('job_resume.receiver_id', $user_id)
  7259. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7260. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7261. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7262. ->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')
  7263. ->orderBy('updated_at', 'desc')
  7264. // ->limit(5)
  7265. ->get();
  7266. //获取5条用户待处理的投诉
  7267. $complaint_deal = Complaint::where('status', 2)
  7268. ->where('deal', 1)
  7269. ->whereJsonContains('re_user_ids', $user_id)
  7270. ->orderBy('updated_at', 'desc')
  7271. // ->limit(5)
  7272. ->get();
  7273. //获取 被通知者未读信息
  7274. $notice_unread = Notice::where('status', 2)
  7275. ->whereJsonContains('re_user_ids', $user_id)
  7276. //未读消息
  7277. ->where(function ($query) use ($user_id) {
  7278. $query->whereJsonDoesntContain('read_id', $user_id)
  7279. ->orWhereNull('read_id');
  7280. })
  7281. ->orderBy('updated_at', 'desc')
  7282. ->get();
  7283. $complaint_unread = Complaint::where('status', 2)
  7284. ->whereJsonContains('re_user_ids', $user_id)
  7285. //未读消息
  7286. ->where(function ($query) use ($user_id) {
  7287. $query->whereJsonDoesntContain('read_id', $user_id)
  7288. ->orWhereNull('read_id');
  7289. })
  7290. ->orderBy('updated_at', 'desc')
  7291. ->get();
  7292. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7293. $complany = Company::where('status', 1)
  7294. ->where('user_id', $user_id)
  7295. ->orderBy('updated_at', 'desc')
  7296. // ->limit(5)
  7297. ->get();
  7298. //获取5条单聊未读聊天消息
  7299. // $chat = ChatRecords::where('is_read', 0)
  7300. // ->where('user_id', $user_id)
  7301. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7302. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7303. // ->where('action', 'recieved')
  7304. // ->where('talk_type', 1)
  7305. // ->orderBy('created_at', 'desc')
  7306. // // ->limit(5)
  7307. // ->get();
  7308. //获取5条未读群聊信息
  7309. // $chat_group = ChatRecords::where('is_read', 0)
  7310. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7311. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7312. // ->where('user_id', $user_id)
  7313. // ->where('talk_type', 2)
  7314. // ->orderBy('created_at', 'desc')
  7315. // // ->limit(5)
  7316. // ->get();
  7317. //获取5条用户的待审核项目
  7318. $project = Project::where('status', 1)
  7319. ->where('user_id', $user_id)
  7320. ->orderBy('updated_at', 'desc')
  7321. // ->limit(5)
  7322. ->get();
  7323. // count($chat) + count($chat_group) +
  7324. $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)
  7325. + count($complany)
  7326. + count($project)
  7327. + count($notice_unread)
  7328. + count($complaint_unread)
  7329. // + count($chat) + count($chat_group)
  7330. ;
  7331. $result = [
  7332. 'apply_articale' => $apply_articale,
  7333. // 'chat' => $chat,
  7334. // 'chat_group' => $chat_group,
  7335. 'good' => $good,
  7336. 'notice' => $notice,
  7337. 'complaint' => $complaint,
  7338. 'book' => $book,
  7339. 'job_hunting' => $job_hunting,
  7340. 'job_recruiting' => $job_recruiting,
  7341. 'job_apply' => $job_apply,
  7342. 'job_resume' => $job_resume,
  7343. 'complaint_deal' => $complaint_deal,
  7344. 'complany' => $complany,
  7345. 'project' => $project,
  7346. 'notice_unread' => $notice_unread,
  7347. 'complaint_unread' => $complaint_unread,
  7348. 'count' => $count,
  7349. ];
  7350. } elseif ($type_id == 12) {
  7351. //最近的5篇已审的文章
  7352. $apply_articale = Article::where('status', 1)
  7353. ->where('admin_user_id', $user_id)
  7354. ->limit(5)->get();
  7355. //获取5条单聊未读聊天消息
  7356. $chat = ChatRecords::where('is_read', 0)
  7357. ->where('user_id', $user_id)
  7358. ->where('talk_type', 1)
  7359. ->orderBy('created_at', 'desc')
  7360. ->limit(5)->get();
  7361. //获取5条未读群聊信息
  7362. $chat_group = ChatRecords::where('is_read', 0)
  7363. ->where('user_id', $user_id)
  7364. ->where('talk_type', 2)
  7365. ->orderBy('created_at', 'desc')
  7366. ->limit(5)->get();
  7367. //获取5条用户的已审核商品
  7368. $good = Good::where('status', 2)
  7369. ->where('user_id', $user_id)
  7370. ->orderBy('updated_at', 'desc')
  7371. ->limit(5)->get();
  7372. //获取5条用户的book
  7373. $book = Book::where('status', 2)
  7374. ->where('user_id', $user_id)
  7375. ->orderBy('updated_at', 'desc')
  7376. ->limit(5)->get();
  7377. //获取5条用户的求职
  7378. //获取5条用户的求职 1
  7379. //count($chat) + count($chat_group)
  7380. $count = count($apply_articale) + count($good);
  7381. $result = [
  7382. 'apply_articale' => $apply_articale,
  7383. 'chat' => $chat,
  7384. 'chat_group' => $chat_group,
  7385. 'good' => $good,
  7386. 'book' => $book,
  7387. 'count' => $count,
  7388. ];
  7389. } elseif ($type_id == 13) {
  7390. //最近的5篇已审的文章
  7391. $apply_articale = Article::where('status', 1)
  7392. ->where('admin_user_id', $user_id)
  7393. ->limit(5)->get();
  7394. //获取5条单聊未读聊天消息
  7395. $chat = ChatRecords::where('is_read', 0)
  7396. ->where('user_id', $user_id)
  7397. ->where('talk_type', 1)
  7398. ->orderBy('created_at', 'desc')
  7399. ->limit(5)->get();
  7400. //获取5条未读群聊信息
  7401. $chat_group = ChatRecords::where('is_read', 0)
  7402. ->where('user_id', $user_id)
  7403. ->where('talk_type', 2)
  7404. ->orderBy('created_at', 'desc')
  7405. ->limit(5)->get();
  7406. //获取5条用户的已审核商品
  7407. $good = Good::where('status', 2)
  7408. ->where('user_id', $user_id)
  7409. ->orderBy('updated_at', 'desc')
  7410. ->limit(5)->get();
  7411. //count($chat) + count($chat_group) +
  7412. $count = count($apply_articale) + count($good);
  7413. $result = [
  7414. 'apply_articale' => $apply_articale,
  7415. 'chat' => $chat,
  7416. 'chat_group' => $chat_group,
  7417. 'good' => $good,
  7418. 'count' => $count,
  7419. ];
  7420. } elseif ($type_id == 14) {
  7421. //最近的5篇已审的文章
  7422. $apply_articale = Article::where('status', 1)
  7423. ->where('admin_user_id', $user_id)
  7424. // ->limit(5)
  7425. ->get();
  7426. //获取5条用户的已审核商品
  7427. $good = Good::where('status', 2)
  7428. ->where('user_id', $user_id)
  7429. ->orderBy('updated_at', 'desc')
  7430. // ->limit(5)
  7431. ->get();
  7432. $count = count($apply_articale) + count($good);
  7433. $result = [
  7434. 'apply_articale' => $apply_articale,
  7435. 'chat' => '',
  7436. 'chat_group' => '',
  7437. 'good' => $good,
  7438. 'count' => $count,
  7439. ];
  7440. } elseif ($type_id == 10000) {
  7441. //获取未审核的5篇文章
  7442. $apply_articale = Article::where('status', 0)
  7443. ->orderBy('updated_at', 'desc')
  7444. // ->limit(5)
  7445. ->get();
  7446. //获取5条单聊未读聊天消息
  7447. //获取5条单聊未读聊天消息
  7448. // $chat = ChatRecords::where('is_read', 0)
  7449. // ->where('user_id', $user_id)
  7450. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7451. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7452. // ->where('action', 'recieved')
  7453. // ->where('talk_type', 1)
  7454. // ->orderBy('created_at', 'desc')
  7455. // // ->limit(5)
  7456. // ->get();
  7457. // //获取5条未读群聊信息
  7458. // $chat_group = ChatRecords::where('is_read', 0)
  7459. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7460. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7461. // ->where('user_id', $user_id)
  7462. // ->where('talk_type', 2)
  7463. // ->orderBy('created_at', 'desc')
  7464. // // ->limit(5)
  7465. // ->get();
  7466. //获取5条用户的已审核商品
  7467. $good = Good::where('status', 1)
  7468. // ->where('user_id', $user_id)
  7469. ->orderBy('updated_at', 'desc')
  7470. // ->limit(5)
  7471. ->get();
  7472. //获取5条用户待审核的公告
  7473. $notice = Notice::where('status', 1)
  7474. ->orderBy('updated_at', 'desc')
  7475. // ->limit(5)
  7476. ->get();
  7477. //获取5条用户的待审核投诉
  7478. $complaint = Complaint::where('status', 1)
  7479. ->orderBy('updated_at', 'desc')
  7480. // ->limit(5)
  7481. ->get();
  7482. //获取5条用户的book
  7483. $book = Book::where('status', 1)
  7484. ->orderBy('updated_at', 'desc')
  7485. // ->limit(5)
  7486. ->get();
  7487. //获取5条用户的求职 1
  7488. $job_hunting = JobHunting::where('job_hunting.status', 1)
  7489. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7490. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7491. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7492. ->orderBy('updated_at', 'desc')
  7493. // ->limit(5)
  7494. ->get();
  7495. //获取5条用户的求职 2
  7496. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  7497. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7498. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7499. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7500. ->orderBy('updated_at', 'desc')
  7501. // ->limit(5)
  7502. ->get();
  7503. //人才库 1
  7504. $job_apply = JobApply::where('job_apply.status', 1)
  7505. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7506. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7507. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7508. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7509. ->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')
  7510. ->orderBy('updated_at', 'desc')
  7511. // ->limit(5)
  7512. ->get();
  7513. // 职场机会 2
  7514. $job_resume = JobResume::where('job_resume.status', 1)
  7515. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7516. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7517. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7518. ->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')
  7519. ->orderBy('updated_at', 'desc')
  7520. // ->limit(5)
  7521. ->get();
  7522. //待审核数据com pro
  7523. $complany = Company::where('status', 0)
  7524. ->orderBy('updated_at', 'desc')
  7525. // ->limit(5)
  7526. ->get();
  7527. $project = Project::where('status', 0)
  7528. ->orderBy('updated_at', 'desc')
  7529. // ->limit(5)
  7530. ->get();
  7531. $count =
  7532. // count($chat) +
  7533. // count($chat_group) +
  7534. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  7535. // + count($job_apply)
  7536. // + count($job_resume)
  7537. + count($complany)
  7538. + count($project);
  7539. $result = [
  7540. 'apply_articale' => $apply_articale,
  7541. // 'chat' => $chat,
  7542. // 'chat_group' => $chat_group,
  7543. 'good' => $good,
  7544. 'notice' => $notice,
  7545. 'complaint' => $complaint,
  7546. 'book' => $book,
  7547. 'job_hunting' => $job_hunting,
  7548. 'job_recruiting' => $job_recruiting,
  7549. // 'job_apply' => $job_apply,
  7550. // 'job_resume' => $job_resume,
  7551. 'complany' => $complany,
  7552. 'project' => $project,
  7553. 'count' => $count,
  7554. ];
  7555. } elseif ($type_id == 20000) {
  7556. }
  7557. var_dump($type_id, '-----------------test---------');
  7558. return Result::success($result);
  7559. }
  7560. /**
  7561. * @param array $data
  7562. * @return array
  7563. */
  7564. public function getWebsiteProject(array $data): array
  7565. {
  7566. $categorys = json_decode($data['id'], true);
  7567. if (!empty($categorys)) {
  7568. $category_arr = $this->processArticlePro($data['website_id']);
  7569. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7570. $catiall = $category_arr['catiall'];
  7571. // return Result::success($catiall);
  7572. foreach ($categorys as $key => $val) {
  7573. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  7574. $level = explode(',', $val['level'])[0];
  7575. $imgnum = explode(',', $val['level'])[1] ?? null;
  7576. $textnum = explode(',', $val['level'])[2] ?? null;
  7577. if ($level == 1) {
  7578. if (!empty($textnum) && $textnum > 0) {
  7579. $text_num = Project::where('level', $level)
  7580. ->where('website_id', $data['website_id'])
  7581. ->where('status', 1)
  7582. ->select(
  7583. 'project.id',
  7584. 'project.title',
  7585. 'project.description',
  7586. 'project.updated_at',
  7587. 'project.category_id',
  7588. 'project.cat_arr_id'
  7589. )
  7590. ->orderBy('updated_at', 'desc')
  7591. ->limit($textnum)
  7592. ->get()->all();
  7593. }
  7594. if (!empty($imgnum) && $imgnum > 0) {
  7595. $img_num = Project::where('level', $level)
  7596. ->where('website_id', $data['website_id'])
  7597. ->where('status', 1)
  7598. ->where('imgurl', '!=', '')
  7599. ->whereNotNull('imgurl')
  7600. ->select(
  7601. 'project.id',
  7602. 'project.title',
  7603. 'project.description',
  7604. 'project.updated_at',
  7605. 'project.imgurl as imgs',
  7606. 'project.category_id',
  7607. 'project.cat_arr_id'
  7608. )
  7609. ->orderBy('updated_at', 'desc')
  7610. ->limit($imgnum)
  7611. ->get()->all();
  7612. }
  7613. } else {
  7614. if (!empty($textnum) && $textnum > 0) {
  7615. $text_num = Project::where('website_id', $data['website_id'])
  7616. ->where('status', 1)
  7617. ->select(
  7618. 'project.id',
  7619. 'project.title',
  7620. 'project.description',
  7621. 'project.updated_at',
  7622. 'project.category_id',
  7623. 'project.cat_arr_id',
  7624. 'project.website_id',
  7625. 'project.updated_at',
  7626. 'project.created_at'
  7627. )
  7628. ->orderBy('updated_at', 'desc')
  7629. ->limit($textnum)
  7630. ->get()->all();
  7631. }
  7632. if (!empty($imgnum) && $imgnum > 0) {
  7633. $img_num = Project::where('website_id', $data['website_id'])
  7634. ->where('status', 1)
  7635. ->where('imgurl', '!=', '')
  7636. ->whereNotNull('imgurl')
  7637. ->select(
  7638. 'project.id',
  7639. 'project.title',
  7640. 'project.description',
  7641. 'project.updated_at',
  7642. 'project.imgurl as imgs',
  7643. 'project.category_id',
  7644. 'project.cat_arr_id'
  7645. )
  7646. ->orderBy('updated_at', 'desc')
  7647. ->limit($imgnum)
  7648. ->get()->all();
  7649. }
  7650. }
  7651. }
  7652. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  7653. $category_ids = explode(',', $val['id'])[0];
  7654. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  7655. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  7656. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  7657. if (!empty($cat_textnum) && $cat_textnum > 0) {
  7658. $text_num = Project::whereIn('category_id', $category_arr)
  7659. ->where('website_id', $data['website_id'])
  7660. ->where('status', 1)
  7661. ->select(
  7662. 'project.id',
  7663. 'project.title',
  7664. 'project.description',
  7665. 'project.updated_at',
  7666. 'project.category_id',
  7667. 'project.cat_arr_id'
  7668. )
  7669. ->orderBy('updated_at', 'desc')
  7670. ->limit($cat_textnum)
  7671. ->get()->all();
  7672. }
  7673. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  7674. $img_num = Project::whereIn('category_id', $category_arr)
  7675. ->where('website_id', $data['website_id'])
  7676. ->where('status', 1)
  7677. ->where('imgurl', '!=', '')
  7678. ->whereNotNull('imgurl')
  7679. ->select(
  7680. 'project.id',
  7681. 'project.title',
  7682. 'project.description',
  7683. 'project.updated_at',
  7684. 'project.imgurl as imgs',
  7685. 'project.category_id',
  7686. 'project.cat_arr_id'
  7687. )
  7688. ->orderBy('updated_at', 'desc')
  7689. ->limit($cat_imgnum)
  7690. ->get()->all();
  7691. }
  7692. }
  7693. if (!empty($img_num)) {
  7694. foreach ($img_num as $k => $v) {
  7695. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7696. $imgurl = json_decode($v['imgs'], true);
  7697. if (!empty($imgurl)) {
  7698. $img_num[$k]->imgurl = $imgurl[0];
  7699. }
  7700. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7701. }
  7702. }
  7703. if (!empty($text_num)) {
  7704. foreach ($text_num as $k => $v) {
  7705. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7706. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7707. }
  7708. }
  7709. $project[$key]['img_num'] = $img_num ?? [];
  7710. $project[$key]['text_num'] = $text_num ?? [];
  7711. }
  7712. }
  7713. if (empty($project)) {
  7714. return Result::error("暂无相关项目信息", 0);
  7715. }
  7716. return Result::success($project);
  7717. }
  7718. /**
  7719. * @param array $data
  7720. * @return array
  7721. */
  7722. public function getWebsiteProjectInfo(array $data): array
  7723. {
  7724. $project = Project::where('id', $data['id'])
  7725. ->where('status', 1)
  7726. ->where('website_id', $data['website_id'])
  7727. ->select('project.*')
  7728. ->first();
  7729. if (empty($project)) {
  7730. return Result::error("暂无相关项目信息", 0);
  7731. }
  7732. return Result::success($project);
  7733. }
  7734. /**
  7735. * @param array $data
  7736. * @return array
  7737. */
  7738. public function getWebsiteProjectList(array $data): array
  7739. {
  7740. $where = [];
  7741. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7742. $where['category_id'] = $data['category_id'];
  7743. }
  7744. if (isset($data['keyword']) && !empty($data['keyword'])) {
  7745. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  7746. }
  7747. $query = Project::where($where)
  7748. ->where('status', 1)
  7749. ->where('website_id', $data['website_id'])
  7750. ->select(
  7751. 'project.id',
  7752. 'project.title',
  7753. 'project.description',
  7754. 'project.imgurl as imgs',
  7755. 'project.category_id',
  7756. 'project.cat_arr_id'
  7757. )
  7758. ->orderBy('updated_at', 'desc');
  7759. $count = $query->count();
  7760. $project = $query->clone()
  7761. ->offset(($data['page'] - 1) * $data['pageSize'])
  7762. ->limit($data['pageSize'])
  7763. ->get()->all();
  7764. if (empty($project)) {
  7765. return Result::error("暂无相关项目信息", 0);
  7766. }
  7767. $categorys = $this->processArticlePro($data['website_id']);
  7768. $catiall = $categorys['catiall'];
  7769. foreach ($project as $key => $val) {
  7770. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  7771. if (!empty($val['imgs'])) {
  7772. $imgurl = json_decode($val['imgs'], true);
  7773. if (!empty($imgurl)) {
  7774. $project[$key]->imgurl = $imgurl[0];
  7775. }
  7776. } else {
  7777. $project[$key]->imgurl = '';
  7778. }
  7779. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  7780. }
  7781. $result = [
  7782. 'rows' => $project,
  7783. 'count' => $count,
  7784. ];
  7785. return Result::success($result);
  7786. }
  7787. /**
  7788. * @param array $data
  7789. * @return array
  7790. */
  7791. public function getWebsiteCategoryJob(array $data): array
  7792. {
  7793. $categorys = json_decode($data['id'], true);
  7794. if (!empty($categorys)) {
  7795. $category_arr = $this->processArticlePro($data['website_id']);
  7796. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7797. $catiall = $category_arr['catiall'];
  7798. foreach ($categorys as $key => $val) {
  7799. if (isset($val['id']) && !empty($val['id'])) {
  7800. $catid = explode(',', $val['id'])[0] ?? null;
  7801. $type = explode(',', $val['id'])[1] ?? null;
  7802. $textnum = explode(',', $val['id'])[2] ?? null;
  7803. }
  7804. // 4:招聘;5:求职;
  7805. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  7806. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  7807. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  7808. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  7809. ->where('job_recruiting.status', 1)
  7810. ->where('job_recruiting.website_id', $data['website_id'])
  7811. ->select(
  7812. 'job_recruiting.id',
  7813. 'job_recruiting.title',
  7814. 'job_company.business_name',
  7815. 'job_recruiting.updated_at',
  7816. 'job_recruiting.cat_arr_id',
  7817. 'job_recruiting.keyword',
  7818. 'job_recruiting.description'
  7819. )
  7820. ->orderBy('job_recruiting.updated_at', 'desc')
  7821. ->limit($textnum)
  7822. ->get()->all();
  7823. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  7824. // 状态 审核状态,1待审核2已审核3已拒绝
  7825. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  7826. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  7827. ->where('job_hunting.status', 2)
  7828. ->where('job_hunting.website_id', $data['website_id'])
  7829. ->select(
  7830. 'job_hunting.id',
  7831. 'job_hunting.name',
  7832. 'job_hunting.cat_arr_id',
  7833. 'job_position.zwname as job_name',
  7834. 'job_hunting.updated_at',
  7835. 'job_hunting.keyword',
  7836. 'job_hunting.slelf_evaluation'
  7837. )
  7838. ->orderBy('updated_at', 'desc')
  7839. ->limit($textnum)
  7840. ->get()->all();
  7841. } else {
  7842. $job = [];
  7843. }
  7844. // var_dump($catid.'222uuuuuuu'.$key);
  7845. if (!empty($job)) {
  7846. foreach ($job as $k => $value) {
  7847. if (isset($value->cat_arr_id)) {
  7848. $catArr = json_decode($value->cat_arr_id, true);
  7849. $catId = end($catArr);
  7850. } else {
  7851. continue;
  7852. }
  7853. if (isset($catiall[$catId])) {
  7854. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  7855. }
  7856. }
  7857. }
  7858. // var_dump($catid.'xxxxx'.$key);
  7859. $result[$key] = $job ?? [];
  7860. }
  7861. }
  7862. if (empty($result)) {
  7863. return Result::error("暂无相关分类信息", 0);
  7864. }
  7865. return Result::success($result);
  7866. }
  7867. /**
  7868. * 发送消息
  7869. * @param array $messageData
  7870. * @return void
  7871. */
  7872. public function sendMessage($messageData)
  7873. {
  7874. $msg = [
  7875. 'talk_type' => $messageData['talk_type'],
  7876. 'title' => $messageData['title'],
  7877. 'content' => $messageData['content'],
  7878. 'messageType' => $messageData['messageType'],
  7879. 'user_id' => $messageData['user_id'] ?? '',
  7880. 'time' => microtime(),
  7881. ];
  7882. $message = new MqProducer($msg);
  7883. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  7884. $producer->produce($message);
  7885. }
  7886. }